Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | # |
| 3 | # Note that the scrap-manager include file is so weird that this |
| 4 | # generates a boilerplate to be edited by hand. |
| 5 | |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 6 | import sys |
| 7 | import os |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 8 | if os.sep == ':': |
| 9 | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') |
| 10 | else: |
| 11 | BGENDIR="../../../Tools/bgen/bgen" |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 12 | sys.path.append(BGENDIR) |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 13 | from scantools import Scanner |
| 14 | from bgenlocations import TOOLBOXDIR |
| 15 | |
| 16 | LONG = "Scrap" |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 17 | SHORT = "scrap" |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 18 | |
| 19 | def main(): |
| 20 | input = "Scrap.h" |
| 21 | output = SHORT + "gen.py" |
| 22 | defsoutput = "@Scrap.py" |
| 23 | scanner = MyScanner(input, output, defsoutput) |
| 24 | scanner.scan() |
| 25 | scanner.close() |
| 26 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 27 | exec "import " + SHORT + "support" |
| 28 | print "=== Done. It's up to you to compile it now! ===" |
| 29 | |
| 30 | class MyScanner(Scanner): |
| 31 | |
| 32 | def destination(self, type, name, arglist): |
| 33 | classname = "Function" |
| 34 | listname = "functions" |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 35 | if arglist: |
| 36 | t, n, m = arglist[0] |
| 37 | if t == 'ScrapRef' and m == "InMode": |
| 38 | classname = "Method" |
| 39 | listname = "methods" |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 40 | return classname, listname |
| 41 | |
| 42 | def makeblacklistnames(self): |
| 43 | return [ |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 44 | "GetScrapFlavorInfoList", |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 45 | ] |
| 46 | |
Jack Jansen | 7b3cc1f | 2001-01-24 16:04:01 +0000 | [diff] [blame] | 47 | def makegreylist(self): |
| 48 | return [ |
| 49 | ('#if !TARGET_API_MAC_CARBON', [ |
| 50 | 'InfoScrap', |
| 51 | 'GetScrap', |
| 52 | 'ZeroScrap', |
| 53 | 'PutScrap', |
| 54 | ]), |
| 55 | ('#if TARGET_API_MAC_CARBON', [ |
| 56 | 'CallInScrapPromises', |
| 57 | 'ClearCurrentScrap', |
| 58 | ])] |
| 59 | |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 60 | def makeblacklisttypes(self): |
| 61 | return [ |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 62 | 'ScrapPromiseKeeperUPP', |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 63 | ] |
| 64 | |
| 65 | def makerepairinstructions(self): |
| 66 | return [ |
| 67 | ([('void', '*', 'OutMode')], [('putscrapbuffer', '*', 'InMode')]), |
Jack Jansen | 7b3cc1f | 2001-01-24 16:04:01 +0000 | [diff] [blame] | 68 | ([('void_ptr', '*', 'InMode')], [('putscrapbuffer', '*', 'InMode')]), |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 69 | ] |
| 70 | |
| 71 | if __name__ == "__main__": |
| 72 | main() |