Jack Jansen | d0e59fb | 2002-11-22 15:53:32 +0000 | [diff] [blame^] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | from bgenlocations import TOOLBOXDIR, BGENDIR |
| 6 | sys.path.append(BGENDIR) |
| 7 | from scantools import Scanner_OSX |
| 8 | |
| 9 | LONG = "Aliases" |
| 10 | SHORT = "alias" |
| 11 | OBJECT = "AliasHandle" |
| 12 | |
| 13 | def main(): |
| 14 | input = LONG + ".h" |
| 15 | output = SHORT + "gen.py" |
| 16 | defsoutput = TOOLBOXDIR + LONG + ".py" |
| 17 | scanner = MyScanner(input, output, defsoutput) |
| 18 | scanner.scan() |
| 19 | scanner.close() |
| 20 | scanner.gentypetest(SHORT+"typetest.py") |
| 21 | print "=== Testing definitions output code ===" |
| 22 | execfile(defsoutput, {}, {}) |
| 23 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 24 | exec "import " + SHORT + "support" |
| 25 | print "=== Done. It's up to you to compile it now! ===" |
| 26 | |
| 27 | class MyScanner(Scanner_OSX): |
| 28 | |
| 29 | def destination(self, type, name, arglist): |
| 30 | classname = "Function" |
| 31 | listname = "functions" |
| 32 | if arglist: |
| 33 | t, n, m = arglist[0] |
| 34 | # This is non-functional today |
| 35 | if t == OBJECT and m == "InMode": |
| 36 | classname = "Method" |
| 37 | listname = "methods" |
| 38 | return classname, listname |
| 39 | |
| 40 | def makeblacklistnames(self): |
| 41 | return [ |
| 42 | # Constants with incompatible definitions |
| 43 | |
| 44 | ] |
| 45 | |
| 46 | def makeblacklisttypes(self): |
| 47 | return [ |
| 48 | "AliasFilterProcPtr", |
| 49 | "AliasFilterUPP", |
| 50 | "CInfoPBPtr", |
| 51 | ] |
| 52 | |
| 53 | def makerepairinstructions(self): |
| 54 | return [ |
| 55 | ([('Str63', 'theString', 'InMode')], |
| 56 | [('Str63', 'theString', 'OutMode')]), |
| 57 | |
| 58 | ([('short', 'fullPathLength', 'InMode'), |
| 59 | ('void_ptr', 'fullPath', 'InMode')], |
| 60 | [('FullPathName', 'fullPath', 'InMode')]), |
| 61 | |
| 62 | ] |
| 63 | |
| 64 | |
| 65 | def writeinitialdefs(self): |
| 66 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 67 | self.defsfile.write("true = True\n") |
| 68 | self.defsfile.write("false = False\n") |
| 69 | |
| 70 | if __name__ == "__main__": |
| 71 | main() |