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