blob: ebaeed886ba73e9e12b5cfeb5ab569cb302e5cb4 [file] [log] [blame]
Jack Jansen686f9c32001-06-26 21:51:18 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4import os
5BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6sys.path.append(BGENDIR)
7from scantools import Scanner_OSX
8from bgenlocations import TOOLBOXDIR
9
10LONG = "CoreFoundation"
11SHORT = "cf"
Jack Jansenbc7c8962001-06-27 22:00:55 +000012OBJECTS = ("CFTypeRef",
13 "CFArrayRef", "CFMutableArrayRef",
14 "CFDataRef", "CFMutableDataRef",
15 "CFDictionaryRef", "CFMutableDictionaryRef",
Jack Jansen7becc912001-06-28 22:08:26 +000016 "CFStringRef", "CFMutableStringRef",
17 "CFURLRef",
Jack Jansen6d207c02002-05-10 22:51:58 +000018## "CFPropertyListRef",
Jack Jansenbc7c8962001-06-27 22:00:55 +000019 )
20# ADD object typenames here
Jack Jansen686f9c32001-06-26 21:51:18 +000021
22def main():
23 input = [
24 "CFBase.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000025 "CFArray.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000026## "CFBag.h",
27## "CFBundle.h",
28## "CFCharacterSet.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000029 "CFData.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000030## "CFDate.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000031 "CFDictionary.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000032## "CFNumber.h",
33## "CFPlugIn.h",
34## "CFPreferences.h",
Jack Jansen6d207c02002-05-10 22:51:58 +000035 "CFPropertyList.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000036## "CFSet.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000037 "CFString.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000038## "CFStringEncodingExt.h",
39## "CFTimeZone.h",
Jack Jansen7becc912001-06-28 22:08:26 +000040 "CFURL.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000041 ]
42 output = SHORT + "gen.py"
43 defsoutput = TOOLBOXDIR + LONG + ".py"
44 scanner = MyScanner(input, output, defsoutput)
45 scanner.scan()
46 scanner.gentypetest(SHORT+"typetest.py")
47 scanner.close()
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! ==="
51
52class MyScanner(Scanner_OSX):
53
54 def destination(self, type, name, arglist):
55 classname = "Function"
56 listname = "functions"
57 if arglist:
58 t, n, m = arglist[0]
59 if t in OBJECTS and m == "InMode":
60 classname = "Method"
61 listname = t + "_methods"
Jack Jansen6f70d622001-07-17 20:47:13 +000062 # Special case for the silly first AllocatorRef argument
63 if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
64 t, n, m = arglist[1]
65 if t in OBJECTS and m == "InMode":
66 classname = "MethodSkipArg1"
67 listname = t + "_methods"
Jack Jansen686f9c32001-06-26 21:51:18 +000068 return classname, listname
69
70 def writeinitialdefs(self):
71 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
72
73 def makeblacklistnames(self):
74 return [
75 # Memory allocator functions
76 "CFAllocatorGetDefault",
77 "CFAllocatorSetDefault",
78 "CFAllocatorAllocate",
79 "CFAllocatorReallocate",
80 "CFAllocatorDeallocate",
81 "CFGetAllocator",
Jack Jansenbc7c8962001-06-27 22:00:55 +000082 # Array functions we skip for now.
83 "CFArrayGetValueAtIndex",
84 # Data pointer functions. Skip for now.
85 "CFDataGetBytePtr",
86 "CFDataGetMutableBytePtr",
87 "CFDataGetBytes", # XXXX Should support this one
88 # String functions
89 "CFStringGetPascalString", # Use the C-string methods.
90 "CFStringGetPascalStringPtr", # TBD automatically
91 "CFStringGetCStringPtr",
Jack Jansen7becc912001-06-28 22:08:26 +000092 "CFStringGetCharactersPtr",
Jack Jansen340d98f2001-07-01 22:04:02 +000093 "CFStringGetCString",
94 "CFStringGetCharacters",
Jack Jansen6f70d622001-07-17 20:47:13 +000095 "CFURLCreateStringWithFileSystemPath", # Gone in later releases
Jack Jansen69ac3612002-01-01 22:43:13 +000096 "CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue...
97 "CFStringSetExternalCharactersNoCopy",
98 "CFStringGetCharacterAtIndex", # No format for single unichars yet.
Jack Jansen9d799902002-03-24 23:04:18 +000099 "kCFStringEncodingInvalidId", # incompatible constant declaration
Jack Jansen79066342002-05-12 22:04:14 +0000100 "CFPropertyListCreateFromXMLData", # Manually generated
Jack Jansen686f9c32001-06-26 21:51:18 +0000101 ]
102
103 def makegreylist(self):
104 return []
105
106 def makeblacklisttypes(self):
107 return [
Jack Jansenbc7c8962001-06-27 22:00:55 +0000108 "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
Jack Jansenbc7c8962001-06-27 22:00:55 +0000114 "va_list", # For printf-to-a-cfstring. Use Python.
115 "const_CFStringEncoding_ptr", # To be done, I guess
Jack Jansen686f9c32001-06-26 21:51:18 +0000116 ]
117
118 def makerepairinstructions(self):
119 return [
Jack Jansen7becc912001-06-28 22:08:26 +0000120 # Buffers in CF seem to be passed as UInt8 * normally.
Jack Jansenbc7c8962001-06-27 22:00:55 +0000121 ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
122 [("UcharInBuffer", "*", "*")]),
Jack Jansen7becc912001-06-28 22:08:26 +0000123
Jack Jansen69ac3612002-01-01 22:43:13 +0000124 ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
125 [("UnicodeInBuffer", "*", "*")]),
126
Jack Jansen7becc912001-06-28 22:08:26 +0000127 # Some functions return a const char *. Don't worry, we won't modify it.
Jack Jansenbc7c8962001-06-27 22:00:55 +0000128 ([("const_char_ptr", "*", "ReturnMode")],
129 [("return_stringptr", "*", "*")]),
Jack Jansen7becc912001-06-28 22:08:26 +0000130
131 # base URLs are optional (pass None for NULL)
132 ([("CFURLRef", "baseURL", "InMode")],
133 [("OptionalCFURLRef", "*", "*")]),
134
Jack Jansen6d207c02002-05-10 22:51:58 +0000135 # We handle CFPropertyListRef objects as plain CFTypeRef
136 ([("CFPropertyListRef", "*", "*")],
137 [("CFTypeRef", "*", "*")]),
Jack Jansen686f9c32001-06-26 21:51:18 +0000138 ]
139
140if __name__ == "__main__":
141 main()