1 # Scan an Apple header file, generating a Python file of generator calls.
5 from bgenlocations
import TOOLBOXDIR
, BGENDIR
6 sys
.path
.append(BGENDIR
)
7 from scantools
import Scanner_OSX
9 LONG
= "CoreFoundation"
11 OBJECTS
= ("CFTypeRef",
12 "CFArrayRef", "CFMutableArrayRef",
13 "CFDataRef", "CFMutableDataRef",
14 "CFDictionaryRef", "CFMutableDictionaryRef",
15 "CFStringRef", "CFMutableStringRef",
17 ## "CFPropertyListRef",
19 # ADD object typenames here
27 ## "CFCharacterSet.h",
37 ## "CFStringEncodingExt.h",
41 output
= SHORT
+ "gen.py"
42 defsoutput
= TOOLBOXDIR
+ LONG
+ ".py"
43 scanner
= MyScanner(input, output
, defsoutput
)
45 scanner
.gentypetest(SHORT
+"typetest.py")
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! ==="
53 class MyScanner(Scanner_OSX
):
55 def destination(self
, type, name
, arglist
):
56 classname
= "Function"
57 listname
= "functions"
58 if arglist
and name
[:13] != 'CFPreferences':
60 if t
in OBJECTS
and m
== "InMode":
62 listname
= t
+ "_methods"
63 # Special case for the silly first AllocatorRef argument
64 if t
== 'CFAllocatorRef' and m
== 'InMode' and len(arglist
) > 1:
66 if t
in OBJECTS
and m
== "InMode":
67 classname
= "MethodSkipArg1"
68 listname
= t
+ "_methods"
69 return classname
, listname
71 def writeinitialdefs(self
):
72 self
.defsfile
.write("def FOUR_CHAR_CODE(x): return x\n")
74 def makeblacklistnames(self
):
76 # Memory allocator functions
77 "CFAllocatorGetDefault",
78 "CFAllocatorSetDefault",
79 "CFAllocatorAllocate",
80 "CFAllocatorReallocate",
81 "CFAllocatorDeallocate",
83 # Array functions we skip for now.
84 "CFArrayGetValueAtIndex",
85 # Data pointer functions. Skip for now.
87 "CFDataGetMutableBytePtr",
88 "CFDataGetBytes", # XXXX Should support this one
90 "CFStringGetPascalString", # Use the C-string methods.
91 "CFStringGetPascalStringPtr", # TBD automatically
92 "CFStringGetCStringPtr",
93 "CFStringGetCharactersPtr",
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
104 def makegreylist(self
):
107 def makeblacklisttypes(self
):
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
119 def makerepairinstructions(self
):
121 # Buffers in CF seem to be passed as UInt8 * normally.
122 ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
123 [("UcharInBuffer", "*", "*")]),
125 ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
126 [("UnicodeInBuffer", "*", "*")]),
128 # Some functions return a const char *. Don't worry, we won't modify it.
129 ([("const_char_ptr", "*", "ReturnMode")],
130 [("return_stringptr", "*", "*")]),
132 # base URLs are optional (pass None for NULL)
133 ([("CFURLRef", "baseURL", "InMode")],
134 [("OptionalCFURLRef", "*", "*")]),
136 # We handle CFPropertyListRef objects as plain CFTypeRef
137 ([("CFPropertyListRef", "*", "*")],
138 [("CFTypeRef", "*", "*")]),
141 if __name__
== "__main__":