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() |
Jack Jansen | 7ca993e | 2002-08-15 22:05:58 +0000 | [diff] [blame^] | 22 | ## print "=== Testing definitions output code ===" |
| 23 | ## execfile(defsoutput, {}, {}) |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 24 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 25 | exec "import " + SHORT + "support" |
| 26 | print "=== Done. It's up to you to compile it now! ===" |
| 27 | |
| 28 | class MyScanner(Scanner): |
| 29 | |
| 30 | def destination(self, type, name, arglist): |
| 31 | classname = "Function" |
| 32 | listname = "functions" |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 33 | if arglist: |
| 34 | t, n, m = arglist[0] |
| 35 | if t == 'ScrapRef' and m == "InMode": |
| 36 | classname = "Method" |
| 37 | listname = "methods" |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 38 | return classname, listname |
| 39 | |
| 40 | def makeblacklistnames(self): |
| 41 | return [ |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 42 | "GetScrapFlavorInfoList", |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 43 | ] |
| 44 | |
Jack Jansen | 7b3cc1f | 2001-01-24 16:04:01 +0000 | [diff] [blame] | 45 | def makegreylist(self): |
| 46 | return [ |
| 47 | ('#if !TARGET_API_MAC_CARBON', [ |
| 48 | 'InfoScrap', |
| 49 | 'GetScrap', |
| 50 | 'ZeroScrap', |
| 51 | 'PutScrap', |
| 52 | ]), |
| 53 | ('#if TARGET_API_MAC_CARBON', [ |
| 54 | 'CallInScrapPromises', |
| 55 | 'ClearCurrentScrap', |
| 56 | ])] |
| 57 | |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 58 | def makeblacklisttypes(self): |
| 59 | return [ |
Jack Jansen | 420ed40 | 2001-12-31 14:52:03 +0000 | [diff] [blame] | 60 | 'ScrapPromiseKeeperUPP', |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 61 | ] |
| 62 | |
| 63 | def makerepairinstructions(self): |
| 64 | return [ |
| 65 | ([('void', '*', 'OutMode')], [('putscrapbuffer', '*', 'InMode')]), |
Jack Jansen | 7b3cc1f | 2001-01-24 16:04:01 +0000 | [diff] [blame] | 66 | ([('void_ptr', '*', 'InMode')], [('putscrapbuffer', '*', 'InMode')]), |
Jack Jansen | da6a971 | 1996-04-12 16:25:30 +0000 | [diff] [blame] | 67 | ] |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | main() |