This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Mac / Modules / cf / cfscan.py
blobbe11dba7ea721f04df8bce245c56729aeaba56eb
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 import os
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"
11 SHORT = "cf"
12 OBJECTS = ("CFTypeRef",
13 "CFArrayRef", "CFMutableArrayRef",
14 "CFDataRef", "CFMutableDataRef",
15 "CFDictionaryRef", "CFMutableDictionaryRef",
16 "CFStringRef", "CFMutableStringRef",
17 "CFURLRef",
19 # ADD object typenames here
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",
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 "=== 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"
56 if arglist:
57 t, n, m = arglist[0]
58 if t in OBJECTS and m == "InMode":
59 classname = "Method"
60 listname = t + "_methods"
61 # Special case for the silly first AllocatorRef argument
62 if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
63 t, n, m = arglist[1]
64 if t in OBJECTS and m == "InMode":
65 classname = "MethodSkipArg1"
66 listname = t + "_methods"
67 return classname, listname
69 def writeinitialdefs(self):
70 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
72 def makeblacklistnames(self):
73 return [
74 # Memory allocator functions
75 "CFAllocatorGetDefault",
76 "CFAllocatorSetDefault",
77 "CFAllocatorAllocate",
78 "CFAllocatorReallocate",
79 "CFAllocatorDeallocate",
80 "CFGetAllocator",
81 # Array functions we skip for now.
82 "CFArrayGetValueAtIndex",
83 # Data pointer functions. Skip for now.
84 "CFDataGetBytePtr",
85 "CFDataGetMutableBytePtr",
86 "CFDataGetBytes", # XXXX Should support this one
87 # String functions
88 "CFStringGetPascalString", # Use the C-string methods.
89 "CFStringGetPascalStringPtr", # TBD automatically
90 "CFStringGetCStringPtr",
91 "CFStringGetCharactersPtr",
92 "CFStringGetCString",
93 "CFStringGetCharacters",
94 "CFURLCreateStringWithFileSystemPath", # Gone in later releases
95 "CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue...
96 "CFStringSetExternalCharactersNoCopy",
97 "CFStringGetCharacterAtIndex", # No format for single unichars yet.
98 "kCFStringEncodingInvalidId", # incompatible constant declaration
101 def makegreylist(self):
102 return []
104 def makeblacklisttypes(self):
105 return [
106 "CFComparatorFunction", # Callback function pointer
107 "CFAllocatorContext", # Not interested in providing our own allocator
108 "void_ptr_ptr", # Tricky. This is the initializer for arrays...
109 "void_ptr", # Ditto for various array lookup methods
110 "CFArrayApplierFunction", # Callback function pointer
111 "CFDictionaryApplierFunction", # Callback function pointer
112 "va_list", # For printf-to-a-cfstring. Use Python.
113 "const_CFStringEncoding_ptr", # To be done, I guess
116 def makerepairinstructions(self):
117 return [
118 # Buffers in CF seem to be passed as UInt8 * normally.
119 ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
120 [("UcharInBuffer", "*", "*")]),
122 ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
123 [("UnicodeInBuffer", "*", "*")]),
125 # Some functions return a const char *. Don't worry, we won't modify it.
126 ([("const_char_ptr", "*", "ReturnMode")],
127 [("return_stringptr", "*", "*")]),
129 # base URLs are optional (pass None for NULL)
130 ([("CFURLRef", "baseURL", "InMode")],
131 [("OptionalCFURLRef", "*", "*")]),
135 if __name__ == "__main__":
136 main()