| 1 | n/a | # Scan an Apple header file, generating a Python file of generator calls. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | import sys |
|---|
| 4 | n/a | from bgenlocations import TOOLBOXDIR, BGENDIR |
|---|
| 5 | n/a | sys.path.append(BGENDIR) |
|---|
| 6 | n/a | from scantools import Scanner_OSX |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | LONG = "CoreFoundation" |
|---|
| 9 | n/a | SHORT = "cf" |
|---|
| 10 | n/a | OBJECTS = ("CFTypeRef", |
|---|
| 11 | n/a | "CFArrayRef", "CFMutableArrayRef", |
|---|
| 12 | n/a | "CFDataRef", "CFMutableDataRef", |
|---|
| 13 | n/a | "CFDictionaryRef", "CFMutableDictionaryRef", |
|---|
| 14 | n/a | "CFStringRef", "CFMutableStringRef", |
|---|
| 15 | n/a | "CFURLRef", |
|---|
| 16 | n/a | ## "CFPropertyListRef", |
|---|
| 17 | n/a | ) |
|---|
| 18 | n/a | # ADD object typenames here |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | def main(): |
|---|
| 21 | n/a | input = [ |
|---|
| 22 | n/a | "CFBase.h", |
|---|
| 23 | n/a | "CFArray.h", |
|---|
| 24 | n/a | ## "CFBag.h", |
|---|
| 25 | n/a | ## "CFBundle.h", |
|---|
| 26 | n/a | ## "CFCharacterSet.h", |
|---|
| 27 | n/a | "CFData.h", |
|---|
| 28 | n/a | ## "CFDate.h", |
|---|
| 29 | n/a | "CFDictionary.h", |
|---|
| 30 | n/a | ## "CFNumber.h", |
|---|
| 31 | n/a | ## "CFPlugIn.h", |
|---|
| 32 | n/a | "CFPreferences.h", |
|---|
| 33 | n/a | "CFPropertyList.h", |
|---|
| 34 | n/a | ## "CFSet.h", |
|---|
| 35 | n/a | "CFString.h", |
|---|
| 36 | n/a | ## "CFStringEncodingExt.h", |
|---|
| 37 | n/a | ## "CFTimeZone.h", |
|---|
| 38 | n/a | "CFURL.h", |
|---|
| 39 | n/a | ] |
|---|
| 40 | n/a | output = SHORT + "gen.py" |
|---|
| 41 | n/a | defsoutput = TOOLBOXDIR + LONG + ".py" |
|---|
| 42 | n/a | scanner = MyScanner(input, output, defsoutput) |
|---|
| 43 | n/a | scanner.scan() |
|---|
| 44 | n/a | scanner.gentypetest(SHORT+"typetest.py") |
|---|
| 45 | n/a | scanner.close() |
|---|
| 46 | n/a | print "=== Testing definitions output code ===" |
|---|
| 47 | n/a | execfile(defsoutput, {}, {}) |
|---|
| 48 | n/a | print "=== Done scanning and generating, now importing the generated code... ===" |
|---|
| 49 | n/a | exec "import " + SHORT + "support" |
|---|
| 50 | n/a | print "=== Done. It's up to you to compile it now! ===" |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | class MyScanner(Scanner_OSX): |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | def destination(self, type, name, arglist): |
|---|
| 55 | n/a | classname = "Function" |
|---|
| 56 | n/a | listname = "functions" |
|---|
| 57 | n/a | if arglist and name[:13] != 'CFPreferences': |
|---|
| 58 | n/a | t, n, m = arglist[0] |
|---|
| 59 | n/a | if t in OBJECTS and m == "InMode": |
|---|
| 60 | n/a | classname = "Method" |
|---|
| 61 | n/a | listname = t + "_methods" |
|---|
| 62 | n/a | # Special case for the silly first AllocatorRef argument |
|---|
| 63 | n/a | if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1: |
|---|
| 64 | n/a | t, n, m = arglist[1] |
|---|
| 65 | n/a | if t in OBJECTS and m == "InMode": |
|---|
| 66 | n/a | classname = "MethodSkipArg1" |
|---|
| 67 | n/a | listname = t + "_methods" |
|---|
| 68 | n/a | return classname, listname |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | def writeinitialdefs(self): |
|---|
| 71 | n/a | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | def makeblacklistnames(self): |
|---|
| 74 | n/a | return [ |
|---|
| 75 | n/a | # Memory allocator functions |
|---|
| 76 | n/a | "CFAllocatorGetDefault", |
|---|
| 77 | n/a | "CFAllocatorSetDefault", |
|---|
| 78 | n/a | "CFAllocatorAllocate", |
|---|
| 79 | n/a | "CFAllocatorReallocate", |
|---|
| 80 | n/a | "CFAllocatorDeallocate", |
|---|
| 81 | n/a | "CFGetAllocator", |
|---|
| 82 | n/a | # Array functions we skip for now. |
|---|
| 83 | n/a | "CFArrayGetValueAtIndex", |
|---|
| 84 | n/a | # Data pointer functions. Skip for now. |
|---|
| 85 | n/a | "CFDataGetBytePtr", |
|---|
| 86 | n/a | "CFDataGetMutableBytePtr", |
|---|
| 87 | n/a | "CFDataGetBytes", # XXXX Should support this one |
|---|
| 88 | n/a | # String functions |
|---|
| 89 | n/a | "CFStringGetPascalString", # Use the C-string methods. |
|---|
| 90 | n/a | "CFStringGetPascalStringPtr", # TBD automatically |
|---|
| 91 | n/a | "CFStringGetCStringPtr", |
|---|
| 92 | n/a | "CFStringGetCharactersPtr", |
|---|
| 93 | n/a | "CFStringGetCString", |
|---|
| 94 | n/a | "CFStringGetCharacters", |
|---|
| 95 | n/a | "CFURLCreateStringWithFileSystemPath", # Gone in later releases |
|---|
| 96 | n/a | "CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue... |
|---|
| 97 | n/a | "CFStringSetExternalCharactersNoCopy", |
|---|
| 98 | n/a | "CFStringGetCharacterAtIndex", # No format for single unichars yet. |
|---|
| 99 | n/a | "kCFStringEncodingInvalidId", # incompatible constant declaration |
|---|
| 100 | n/a | "CFPropertyListCreateFromXMLData", # Manually generated |
|---|
| 101 | n/a | ] |
|---|
| 102 | n/a | |
|---|
| 103 | n/a | def makegreylist(self): |
|---|
| 104 | n/a | return [] |
|---|
| 105 | n/a | |
|---|
| 106 | n/a | def makeblacklisttypes(self): |
|---|
| 107 | n/a | return [ |
|---|
| 108 | n/a | "CFComparatorFunction", # Callback function pointer |
|---|
| 109 | n/a | "CFAllocatorContext", # Not interested in providing our own allocator |
|---|
| 110 | n/a | "void_ptr_ptr", # Tricky. This is the initializer for arrays... |
|---|
| 111 | n/a | "void_ptr", # Ditto for various array lookup methods |
|---|
| 112 | n/a | "CFArrayApplierFunction", # Callback function pointer |
|---|
| 113 | n/a | "CFDictionaryApplierFunction", # Callback function pointer |
|---|
| 114 | n/a | "va_list", # For printf-to-a-cfstring. Use Python. |
|---|
| 115 | n/a | "const_CFStringEncoding_ptr", # To be done, I guess |
|---|
| 116 | n/a | ] |
|---|
| 117 | n/a | |
|---|
| 118 | n/a | def makerepairinstructions(self): |
|---|
| 119 | n/a | return [ |
|---|
| 120 | n/a | # Buffers in CF seem to be passed as UInt8 * normally. |
|---|
| 121 | n/a | ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], |
|---|
| 122 | n/a | [("UcharInBuffer", "*", "*")]), |
|---|
| 123 | n/a | |
|---|
| 124 | n/a | ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], |
|---|
| 125 | n/a | [("UnicodeInBuffer", "*", "*")]), |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | # Some functions return a const char *. Don't worry, we won't modify it. |
|---|
| 128 | n/a | ([("const_char_ptr", "*", "ReturnMode")], |
|---|
| 129 | n/a | [("return_stringptr", "*", "*")]), |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | # base URLs are optional (pass None for NULL) |
|---|
| 132 | n/a | ([("CFURLRef", "baseURL", "InMode")], |
|---|
| 133 | n/a | [("OptionalCFURLRef", "*", "*")]), |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | # We handle CFPropertyListRef objects as plain CFTypeRef |
|---|
| 136 | n/a | ([("CFPropertyListRef", "*", "*")], |
|---|
| 137 | n/a | [("CFTypeRef", "*", "*")]), |
|---|
| 138 | n/a | ] |
|---|
| 139 | n/a | |
|---|
| 140 | n/a | if __name__ == "__main__": |
|---|
| 141 | n/a | main() |
|---|