1 # Scan an Apple header file, generating a Python file of generator calls.
5 BGENDIR
=os
.path
.join(sys
.prefix
, ':Tools:bgen:bgen')
6 sys
.path
.append(BGENDIR
)
7 from scantools
import Scanner_OSX
8 from bgenlocations
import TOOLBOXDIR
10 LONG
= "CoreFoundation"
12 OBJECTS
= ("CFTypeRef",
13 "CFArrayRef", "CFMutableArrayRef",
14 "CFDataRef", "CFMutableDataRef",
15 "CFDictionaryRef", "CFMutableDictionaryRef",
16 "CFStringRef", "CFMutableStringRef",
19 # ADD object typenames here
27 ## "CFCharacterSet.h",
34 ## "CFPropertyList.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 "=== Done scanning and generating, now importing the generated code... ==="
48 exec "import " + SHORT
+ "support"
49 print "=== Done. It's up to you to compile it now! ==="
51 class MyScanner(Scanner_OSX
):
53 def destination(self
, type, name
, arglist
):
54 classname
= "Function"
55 listname
= "functions"
58 if t
in OBJECTS
and m
== "InMode":
60 listname
= t
+ "_methods"
61 return classname
, listname
63 def writeinitialdefs(self
):
64 self
.defsfile
.write("def FOUR_CHAR_CODE(x): return x\n")
66 def makeblacklistnames(self
):
68 # Memory allocator functions
69 "CFAllocatorGetDefault",
70 "CFAllocatorSetDefault",
71 "CFAllocatorAllocate",
72 "CFAllocatorReallocate",
73 "CFAllocatorDeallocate",
75 # Array functions we skip for now.
76 "CFArrayGetValueAtIndex",
77 # Data pointer functions. Skip for now.
79 "CFDataGetMutableBytePtr",
80 "CFDataGetBytes", # XXXX Should support this one
82 "CFStringGetPascalString", # Use the C-string methods.
83 "CFStringGetPascalStringPtr", # TBD automatically
84 "CFStringGetCStringPtr",
85 "CFStringGetCharactersPtr",
87 "CFStringGetCharacters",
88 # OSX only, to be done
89 ## "CFURLCreateWithFileSystemPath",
90 ## "CFURLCreateStringWithFileSystemPath",
93 def makegreylist(self
):
96 def makeblacklisttypes(self
):
98 "CFComparatorFunction", # Callback function pointer
99 "CFAllocatorContext", # Not interested in providing our own allocator
100 "void_ptr_ptr", # Tricky. This is the initializer for arrays...
101 "void_ptr", # Ditto for various array lookup methods
102 "CFArrayApplierFunction", # Callback function pointer
103 "CFDictionaryApplierFunction", # Callback function pointer
104 "UniChar_ptr", # XXXX To be done
105 "const_UniChar_ptr", # XXXX To be done
106 "UniChar", # XXXX To be done
107 "va_list", # For printf-to-a-cfstring. Use Python.
108 "const_CFStringEncoding_ptr", # To be done, I guess
111 def makerepairinstructions(self
):
113 # Buffers in CF seem to be passed as UInt8 * normally.
114 ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
115 [("UcharInBuffer", "*", "*")]),
117 # Some functions return a const char *. Don't worry, we won't modify it.
118 ([("const_char_ptr", "*", "ReturnMode")],
119 [("return_stringptr", "*", "*")]),
121 # base URLs are optional (pass None for NULL)
122 ([("CFURLRef", "baseURL", "InMode")],
123 [("OptionalCFURLRef", "*", "*")]),
127 if __name__
== "__main__":