Jack Jansen | 90ecdf4 | 1996-04-16 14:29:15 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 3 | import addpack |
| 4 | addpack.addpack(':tools:bgen:bgen') |
| 5 | from scantools import Scanner |
| 6 | from bgenlocations import TOOLBOXDIR |
| 7 | |
| 8 | WASTEDIR=":::::Waste 1.2a5:" |
| 9 | |
| 10 | OBJECT = "TEHandle" |
| 11 | SHORT = "waste" |
| 12 | OBJECT = "WEReference" |
| 13 | OBJECT2 = "WEObjectReference" |
| 14 | |
| 15 | def main(): |
| 16 | input = WASTEDIR + "WASTE C/C++ Headers:WASTE.h" |
| 17 | output = SHORT + "gen.py" |
| 18 | defsoutput = TOOLBOXDIR + "WASTEconst.py" |
| 19 | scanner = MyScanner(input, output, defsoutput) |
| 20 | scanner.scan() |
Jack Jansen | 8ae8e4f | 1996-04-23 16:17:08 +0000 | [diff] [blame] | 21 | ## scanner.gentypetest(SHORT+"typetest.py") |
Jack Jansen | 90ecdf4 | 1996-04-16 14:29:15 +0000 | [diff] [blame] | 22 | scanner.close() |
| 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): |
| 28 | |
| 29 | def initpatterns(self): |
| 30 | # Waste doesn't use 'extern': |
| 31 | Scanner.initpatterns(self) |
| 32 | self.head_pat = "^pascal[ \t]+" |
| 33 | |
| 34 | def destination(self, type, name, arglist): |
| 35 | classname = "Function" |
| 36 | listname = "functions" |
| 37 | if arglist: |
| 38 | t, n, m = arglist[-1] |
| 39 | # This is non-functional today |
| 40 | if t == OBJECT and m == "InMode": |
| 41 | classname = "Method" |
| 42 | listname = "methods" |
| 43 | else: |
| 44 | t, n, m = arglist[0] |
| 45 | if t == OBJECT2 and m == "InMode": |
| 46 | classname = "Method2" |
| 47 | listname = "methods2" |
| 48 | return classname, listname |
| 49 | |
| 50 | def makeblacklistnames(self): |
| 51 | return [ |
| 52 | "WEDispose", |
| 53 | "WESetInfo", # Argument type unknown... |
| 54 | "WEGetInfo", |
Jack Jansen | 90ecdf4 | 1996-04-16 14:29:15 +0000 | [diff] [blame] | 55 | ] |
| 56 | |
| 57 | def makeblacklisttypes(self): |
| 58 | return [ |
| 59 | "DragReference", # For now... |
| 60 | "UniversalProcPtr", |
| 61 | ] |
| 62 | |
| 63 | def makerepairinstructions(self): |
| 64 | return [ |
| 65 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], |
| 66 | [("InBuffer", "*", "*")]), |
| 67 | |
| 68 | # WEContinuousStyle |
Jack Jansen | 8ae8e4f | 1996-04-23 16:17:08 +0000 | [diff] [blame] | 69 | ([("WEStyleMode", "mode", "OutMode"), ("TextStyle", "ts", "OutMode")], |
| 70 | [("WEStyleMode", "mode", "InOutMode"), ("TextStyle", "ts", "OutMode")]), |
| 71 | |
| 72 | # WECopyRange |
| 73 | ([('Handle', 'hText', 'InMode'), ('StScrpHandle', 'hStyles', 'InMode'), |
| 74 | ('WESoupHandle', 'hSoup', 'InMode')], |
| 75 | [('OptHandle', 'hText', 'InMode'), ('OptStScrpHandle', 'hStyles', 'InMode'), |
| 76 | ('OptSoupHandle', 'hSoup', 'InMode')]), |
| 77 | |
| 78 | # WEInsert |
| 79 | ([('StScrpHandle', 'hStyles', 'InMode'), ('WESoupHandle', 'hSoup', 'InMode')], |
Jack Jansen | 756522f | 1996-05-07 15:24:01 +0000 | [diff] [blame^] | 80 | [('OptStScrpHandle', 'hStyles', 'InMode'), ('OptSoupHandle', 'hSoup', 'InMode')]), |
| 81 | |
| 82 | # WEGetObjectOwner |
| 83 | ("WEGetObjectOwner", |
| 84 | [('WEReference', '*', 'ReturnMode')], |
| 85 | [('ExistingWEReference', '*', 'ReturnMode')]) |
Jack Jansen | 8ae8e4f | 1996-04-23 16:17:08 +0000 | [diff] [blame] | 86 | |
Jack Jansen | 90ecdf4 | 1996-04-16 14:29:15 +0000 | [diff] [blame] | 87 | ] |
| 88 | |
| 89 | if __name__ == "__main__": |
| 90 | main() |