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 | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame^] | 8 | from bgenlocations import TOOLBOXDIR, BGENDIR |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 9 | sys.path.append(BGENDIR) |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 10 | from scantools import Scanner |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 11 | |
| 12 | LONG = "Scrap" |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 13 | SHORT = "scrap" |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 14 | |
| 15 | def main(): |
| 16 | input = "Scrap.h" |
| 17 | output = SHORT + "gen.py" |
| 18 | defsoutput = "@Scrap.py" |
| 19 | scanner = MyScanner(input, output, defsoutput) |
| 20 | scanner.scan() |
| 21 | scanner.close() |
| 22 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 23 | exec "import " + SHORT + "support" |
| 24 | print "=== Done. It's up to you to compile it now! ===" |
| 25 | |
| 26 | class MyScanner(Scanner): |
| 27 | |
| 28 | def destination(self, type, name, arglist): |
| 29 | classname = "Function" |
| 30 | listname = "functions" |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 31 | if arglist: |
| 32 | t, n, m = arglist[0] |
| 33 | if t == 'ScrapRef' and m == "InMode": |
| 34 | classname = "Method" |
| 35 | listname = "methods" |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 36 | return classname, listname |
| 37 | |
| 38 | def makeblacklistnames(self): |
| 39 | return [ |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 40 | "GetScrapFlavorInfoList", |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 41 | ] |
| 42 | |
Jack Jansen | 7b3cc1f | 2001-01-24 16:04:01 +0000 | [diff] [blame] | 43 | def makegreylist(self): |
| 44 | return [ |
| 45 | ('#if !TARGET_API_MAC_CARBON', [ |
| 46 | 'InfoScrap', |
| 47 | 'GetScrap', |
| 48 | 'ZeroScrap', |
| 49 | 'PutScrap', |
| 50 | ]), |
| 51 | ('#if TARGET_API_MAC_CARBON', [ |
| 52 | 'CallInScrapPromises', |
| 53 | 'ClearCurrentScrap', |
| 54 | ])] |
| 55 | |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 56 | def makeblacklisttypes(self): |
| 57 | return [ |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 58 | 'ScrapPromiseKeeperUPP', |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 59 | ] |
| 60 | |
| 61 | def makerepairinstructions(self): |
| 62 | return [ |
| 63 | ([('void', '*', 'OutMode')], [('putscrapbuffer', '*', 'InMode')]), |
Jack Jansen | 7b3cc1f | 2001-01-24 16:04:01 +0000 | [diff] [blame] | 64 | ([('void_ptr', '*', 'InMode')], [('putscrapbuffer', '*', 'InMode')]), |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 65 | ] |
| 66 | |
| 67 | if __name__ == "__main__": |
| 68 | main() |