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" |
| 12 | OBJECTS = ("CFTypeRef", "CFStringRef") |
| 13 | |
| 14 | def main(): |
| 15 | input = [ |
| 16 | "CFBase.h", |
| 17 | ### "CFArray.h", |
| 18 | ## "CFBag.h", |
| 19 | ## "CFBundle.h", |
| 20 | ## "CFCharacterSet.h", |
| 21 | ### "CFData.h", |
| 22 | ## "CFDate.h", |
| 23 | ### "CFDictionary.h", |
| 24 | ## "CFNumber.h", |
| 25 | ## "CFPlugIn.h", |
| 26 | ## "CFPreferences.h", |
| 27 | ## "CFPropertyList.h", |
| 28 | ## "CFSet.h", |
| 29 | ### "CFString.h", |
| 30 | ## "CFStringEncodingExt.h", |
| 31 | ## "CFTimeZone.h", |
| 32 | ## "CFURL.h", |
| 33 | ] |
| 34 | output = SHORT + "gen.py" |
| 35 | defsoutput = TOOLBOXDIR + LONG + ".py" |
| 36 | scanner = MyScanner(input, output, defsoutput) |
| 37 | scanner.scan() |
| 38 | scanner.gentypetest(SHORT+"typetest.py") |
| 39 | scanner.close() |
| 40 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 41 | exec "import " + SHORT + "support" |
| 42 | print "=== Done. It's up to you to compile it now! ===" |
| 43 | |
| 44 | class MyScanner(Scanner_OSX): |
| 45 | |
| 46 | def destination(self, type, name, arglist): |
| 47 | classname = "Function" |
| 48 | listname = "functions" |
| 49 | if arglist: |
| 50 | t, n, m = arglist[0] |
| 51 | if t in OBJECTS and m == "InMode": |
| 52 | classname = "Method" |
| 53 | listname = t + "_methods" |
| 54 | return classname, listname |
| 55 | |
| 56 | def writeinitialdefs(self): |
| 57 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 58 | |
| 59 | def makeblacklistnames(self): |
| 60 | return [ |
| 61 | # Memory allocator functions |
| 62 | "CFAllocatorGetDefault", |
| 63 | "CFAllocatorSetDefault", |
| 64 | "CFAllocatorAllocate", |
| 65 | "CFAllocatorReallocate", |
| 66 | "CFAllocatorDeallocate", |
| 67 | "CFGetAllocator", |
| 68 | ] |
| 69 | |
| 70 | def makegreylist(self): |
| 71 | return [] |
| 72 | |
| 73 | def makeblacklisttypes(self): |
| 74 | return [ |
| 75 | "CFAllocatorContext", |
| 76 | ] |
| 77 | |
| 78 | def makerepairinstructions(self): |
| 79 | return [ |
| 80 | ] |
| 81 | |
| 82 | if __name__ == "__main__": |
| 83 | main() |