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