blob: 2d11867c4e31e22fe1ab4beae3d22b7e1e501734 [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 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",
33## "CFPreferences.h",
34## "CFPropertyList.h",
35## "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"
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 return classname, listname
62
63 def writeinitialdefs(self):
64 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
65
66 def makeblacklistnames(self):
67 return [
68 # Memory allocator functions
69 "CFAllocatorGetDefault",
70 "CFAllocatorSetDefault",
71 "CFAllocatorAllocate",
72 "CFAllocatorReallocate",
73 "CFAllocatorDeallocate",
74 "CFGetAllocator",
Jack Jansenbc7c8962001-06-27 22:00:55 +000075 # Array functions we skip for now.
76 "CFArrayGetValueAtIndex",
77 # Data pointer functions. Skip for now.
78 "CFDataGetBytePtr",
79 "CFDataGetMutableBytePtr",
80 "CFDataGetBytes", # XXXX Should support this one
81 # String functions
82 "CFStringGetPascalString", # Use the C-string methods.
83 "CFStringGetPascalStringPtr", # TBD automatically
84 "CFStringGetCStringPtr",
Jack Jansen7becc912001-06-28 22:08:26 +000085 "CFStringGetCharactersPtr",
86 # OSX only, to be done
87 "CFURLCreateWithFileSystemPath",
88 "CFURLCreateStringWithFileSystemPath",
Jack Jansen686f9c32001-06-26 21:51:18 +000089 ]
90
91 def makegreylist(self):
92 return []
93
94 def makeblacklisttypes(self):
95 return [
Jack Jansenbc7c8962001-06-27 22:00:55 +000096 "CFComparatorFunction", # Callback function pointer
97 "CFAllocatorContext", # Not interested in providing our own allocator
98 "void_ptr_ptr", # Tricky. This is the initializer for arrays...
99 "void_ptr", # Ditto for various array lookup methods
100 "CFArrayApplierFunction", # Callback function pointer
101 "CFDictionaryApplierFunction", # Callback function pointer
102 "UniChar_ptr", # XXXX To be done
103 "const_UniChar_ptr", # XXXX To be done
104 "UniChar", # XXXX To be done
105 "va_list", # For printf-to-a-cfstring. Use Python.
106 "const_CFStringEncoding_ptr", # To be done, I guess
Jack Jansen686f9c32001-06-26 21:51:18 +0000107 ]
108
109 def makerepairinstructions(self):
110 return [
Jack Jansen7becc912001-06-28 22:08:26 +0000111 # Buffers in CF seem to be passed as UInt8 * normally.
Jack Jansenbc7c8962001-06-27 22:00:55 +0000112 ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
113 [("UcharInBuffer", "*", "*")]),
Jack Jansen7becc912001-06-28 22:08:26 +0000114
115 # Some functions return a const char *. Don't worry, we won't modify it.
Jack Jansenbc7c8962001-06-27 22:00:55 +0000116 ([("const_char_ptr", "*", "ReturnMode")],
117 [("return_stringptr", "*", "*")]),
Jack Jansen7becc912001-06-28 22:08:26 +0000118
119 # base URLs are optional (pass None for NULL)
120 ([("CFURLRef", "baseURL", "InMode")],
121 [("OptionalCFURLRef", "*", "*")]),
122
Jack Jansen686f9c32001-06-26 21:51:18 +0000123 ]
124
125if __name__ == "__main__":
126 main()