blob: 0bcf914842e7c8d20200e69a749215370e5978fb [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
Jack Jansenaaebdd62002-08-05 15:39:30 +00005from bgenlocations import TOOLBOXDIR, BGENDIR
Jack Jansen686f9c32001-06-26 21:51:18 +00006sys.path.append(BGENDIR)
7from scantools import Scanner_OSX
Jack Jansen686f9c32001-06-26 21:51:18 +00008
9LONG = "CoreFoundation"
10SHORT = "cf"
Jack Jansenbc7c8962001-06-27 22:00:55 +000011OBJECTS = ("CFTypeRef",
12 "CFArrayRef", "CFMutableArrayRef",
13 "CFDataRef", "CFMutableDataRef",
14 "CFDictionaryRef", "CFMutableDictionaryRef",
Jack Jansen7becc912001-06-28 22:08:26 +000015 "CFStringRef", "CFMutableStringRef",
16 "CFURLRef",
Jack Jansen6d207c02002-05-10 22:51:58 +000017## "CFPropertyListRef",
Jack Jansenbc7c8962001-06-27 22:00:55 +000018 )
19# ADD object typenames here
Jack Jansen686f9c32001-06-26 21:51:18 +000020
21def main():
22 input = [
23 "CFBase.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000024 "CFArray.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000025## "CFBag.h",
26## "CFBundle.h",
27## "CFCharacterSet.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000028 "CFData.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000029## "CFDate.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000030 "CFDictionary.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000031## "CFNumber.h",
32## "CFPlugIn.h",
Jack Jansen23be1ce2002-05-13 21:21:49 +000033 "CFPreferences.h",
Jack Jansen6d207c02002-05-10 22:51:58 +000034 "CFPropertyList.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000035## "CFSet.h",
Jack Jansenbc7c8962001-06-27 22:00:55 +000036 "CFString.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000037## "CFStringEncodingExt.h",
38## "CFTimeZone.h",
Jack Jansen7becc912001-06-28 22:08:26 +000039 "CFURL.h",
Jack Jansen686f9c32001-06-26 21:51:18 +000040 ]
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! ==="
50
51class MyScanner(Scanner_OSX):
52
53 def destination(self, type, name, arglist):
54 classname = "Function"
55 listname = "functions"
Jack Jansen23be1ce2002-05-13 21:21:49 +000056 if arglist and name[:13] != 'CFPreferences':
Jack Jansen686f9c32001-06-26 21:51:18 +000057 t, n, m = arglist[0]
58 if t in OBJECTS and m == "InMode":
59 classname = "Method"
60 listname = t + "_methods"
Jack Jansen6f70d622001-07-17 20:47:13 +000061 # 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"
Jack Jansen686f9c32001-06-26 21:51:18 +000067 return classname, listname
68
69 def writeinitialdefs(self):
70 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
71
72 def makeblacklistnames(self):
73 return [
74 # Memory allocator functions
75 "CFAllocatorGetDefault",
76 "CFAllocatorSetDefault",
77 "CFAllocatorAllocate",
78 "CFAllocatorReallocate",
79 "CFAllocatorDeallocate",
80 "CFGetAllocator",
Jack Jansenbc7c8962001-06-27 22:00:55 +000081 # 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",
Jack Jansen7becc912001-06-28 22:08:26 +000091 "CFStringGetCharactersPtr",
Jack Jansen340d98f2001-07-01 22:04:02 +000092 "CFStringGetCString",
93 "CFStringGetCharacters",
Jack Jansen6f70d622001-07-17 20:47:13 +000094 "CFURLCreateStringWithFileSystemPath", # Gone in later releases
Jack Jansen69ac3612002-01-01 22:43:13 +000095 "CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue...
96 "CFStringSetExternalCharactersNoCopy",
97 "CFStringGetCharacterAtIndex", # No format for single unichars yet.
Jack Jansen9d799902002-03-24 23:04:18 +000098 "kCFStringEncodingInvalidId", # incompatible constant declaration
Jack Jansen79066342002-05-12 22:04:14 +000099 "CFPropertyListCreateFromXMLData", # Manually generated
Jack Jansen686f9c32001-06-26 21:51:18 +0000100 ]
101
102 def makegreylist(self):
103 return []
104
105 def makeblacklisttypes(self):
106 return [
Jack Jansenbc7c8962001-06-27 22:00:55 +0000107 "CFComparatorFunction", # Callback function pointer
108 "CFAllocatorContext", # Not interested in providing our own allocator
109 "void_ptr_ptr", # Tricky. This is the initializer for arrays...
110 "void_ptr", # Ditto for various array lookup methods
111 "CFArrayApplierFunction", # Callback function pointer
112 "CFDictionaryApplierFunction", # Callback function pointer
Jack Jansenbc7c8962001-06-27 22:00:55 +0000113 "va_list", # For printf-to-a-cfstring. Use Python.
114 "const_CFStringEncoding_ptr", # To be done, I guess
Jack Jansen686f9c32001-06-26 21:51:18 +0000115 ]
116
117 def makerepairinstructions(self):
118 return [
Jack Jansen7becc912001-06-28 22:08:26 +0000119 # Buffers in CF seem to be passed as UInt8 * normally.
Jack Jansenbc7c8962001-06-27 22:00:55 +0000120 ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
121 [("UcharInBuffer", "*", "*")]),
Jack Jansen7becc912001-06-28 22:08:26 +0000122
Jack Jansen69ac3612002-01-01 22:43:13 +0000123 ([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
124 [("UnicodeInBuffer", "*", "*")]),
125
Jack Jansen7becc912001-06-28 22:08:26 +0000126 # Some functions return a const char *. Don't worry, we won't modify it.
Jack Jansenbc7c8962001-06-27 22:00:55 +0000127 ([("const_char_ptr", "*", "ReturnMode")],
128 [("return_stringptr", "*", "*")]),
Jack Jansen7becc912001-06-28 22:08:26 +0000129
130 # base URLs are optional (pass None for NULL)
131 ([("CFURLRef", "baseURL", "InMode")],
132 [("OptionalCFURLRef", "*", "*")]),
133
Jack Jansen6d207c02002-05-10 22:51:58 +0000134 # We handle CFPropertyListRef objects as plain CFTypeRef
135 ([("CFPropertyListRef", "*", "*")],
136 [("CFTypeRef", "*", "*")]),
Jack Jansen686f9c32001-06-26 21:51:18 +0000137 ]
138
139if __name__ == "__main__":
140 main()