Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 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 |
| 9 | |
| 10 | LONG = "CoreFoundation" |
| 11 | SHORT = "cf" |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 12 | OBJECTS = ("CFTypeRef", |
| 13 | "CFArrayRef", "CFMutableArrayRef", |
| 14 | "CFDataRef", "CFMutableDataRef", |
| 15 | "CFDictionaryRef", "CFMutableDictionaryRef", |
| 16 | "CFStringRef", "CFMutableStringRef", |
| 17 | ) |
| 18 | # ADD object typenames here |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 19 | |
| 20 | def main(): |
| 21 | input = [ |
| 22 | "CFBase.h", |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 23 | "CFArray.h", |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 24 | ## "CFBag.h", |
| 25 | ## "CFBundle.h", |
| 26 | ## "CFCharacterSet.h", |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 27 | "CFData.h", |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 28 | ## "CFDate.h", |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 29 | "CFDictionary.h", |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 30 | ## "CFNumber.h", |
| 31 | ## "CFPlugIn.h", |
| 32 | ## "CFPreferences.h", |
| 33 | ## "CFPropertyList.h", |
| 34 | ## "CFSet.h", |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 35 | "CFString.h", |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 36 | ## "CFStringEncodingExt.h", |
| 37 | ## "CFTimeZone.h", |
| 38 | ## "CFURL.h", |
| 39 | ] |
| 40 | output = SHORT + "gen.py" |
| 41 | defsoutput = TOOLBOXDIR + LONG + ".py" |
| 42 | scanner = MyScanner(input, output, defsoutput) |
| 43 | scanner.scan() |
| 44 | scanner.gentypetest(SHORT+"typetest.py") |
| 45 | scanner.close() |
| 46 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 47 | exec "import " + SHORT + "support" |
| 48 | print "=== Done. It's up to you to compile it now! ===" |
| 49 | |
| 50 | class MyScanner(Scanner_OSX): |
| 51 | |
| 52 | def destination(self, type, name, arglist): |
| 53 | classname = "Function" |
| 54 | listname = "functions" |
| 55 | if arglist: |
| 56 | t, n, m = arglist[0] |
| 57 | if t in OBJECTS and m == "InMode": |
| 58 | classname = "Method" |
| 59 | listname = t + "_methods" |
| 60 | return classname, listname |
| 61 | |
| 62 | def writeinitialdefs(self): |
| 63 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 64 | |
| 65 | def makeblacklistnames(self): |
| 66 | return [ |
| 67 | # Memory allocator functions |
| 68 | "CFAllocatorGetDefault", |
| 69 | "CFAllocatorSetDefault", |
| 70 | "CFAllocatorAllocate", |
| 71 | "CFAllocatorReallocate", |
| 72 | "CFAllocatorDeallocate", |
| 73 | "CFGetAllocator", |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 74 | # Array functions we skip for now. |
| 75 | "CFArrayGetValueAtIndex", |
| 76 | # Data pointer functions. Skip for now. |
| 77 | "CFDataGetBytePtr", |
| 78 | "CFDataGetMutableBytePtr", |
| 79 | "CFDataGetBytes", # XXXX Should support this one |
| 80 | # String functions |
| 81 | "CFStringGetPascalString", # Use the C-string methods. |
| 82 | "CFStringGetPascalStringPtr", # TBD automatically |
| 83 | "CFStringGetCStringPtr", |
| 84 | "CFStringGetCharactersPtr", |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 85 | ] |
| 86 | |
| 87 | def makegreylist(self): |
| 88 | return [] |
| 89 | |
| 90 | def makeblacklisttypes(self): |
| 91 | return [ |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 92 | "CFComparatorFunction", # Callback function pointer |
| 93 | "CFAllocatorContext", # Not interested in providing our own allocator |
| 94 | "void_ptr_ptr", # Tricky. This is the initializer for arrays... |
| 95 | "void_ptr", # Ditto for various array lookup methods |
| 96 | "CFArrayApplierFunction", # Callback function pointer |
| 97 | "CFDictionaryApplierFunction", # Callback function pointer |
| 98 | "UniChar_ptr", # XXXX To be done |
| 99 | "const_UniChar_ptr", # XXXX To be done |
| 100 | "UniChar", # XXXX To be done |
| 101 | "va_list", # For printf-to-a-cfstring. Use Python. |
| 102 | "const_CFStringEncoding_ptr", # To be done, I guess |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 103 | ] |
| 104 | |
| 105 | def makerepairinstructions(self): |
| 106 | return [ |
Jack Jansen | bc7c896 | 2001-06-27 22:00:55 +0000 | [diff] [blame^] | 107 | ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], |
| 108 | [("UcharInBuffer", "*", "*")]), |
| 109 | ([("const_char_ptr", "*", "ReturnMode")], |
| 110 | [("return_stringptr", "*", "*")]), |
Jack Jansen | 686f9c3 | 2001-06-26 21:51:18 +0000 | [diff] [blame] | 111 | ] |
| 112 | |
| 113 | if __name__ == "__main__": |
| 114 | main() |