Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 3 | import sys |
| 4 | import os |
| 5 | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') |
| 6 | sys.path.append(BGENDIR) |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 7 | from scantools import Scanner |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 8 | from bgenlocations import TOOLBOXDIR |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 9 | |
| 10 | LONG = "Components" |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 11 | SHORT = "cm" |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 12 | |
| 13 | def main(): |
| 14 | input = "Components.h" |
| 15 | output = SHORT + "gen.py" |
Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 16 | defsoutput = TOOLBOXDIR + LONG + ".py" |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 17 | scanner = MyScanner(input, output, defsoutput) |
| 18 | scanner.scan() |
| 19 | scanner.close() |
| 20 | print "=== Done scanning and generating, now importing the generated code... ===" |
| 21 | exec "import " + SHORT + "support" |
| 22 | print "=== Done. It's up to you to compile it now! ===" |
| 23 | |
| 24 | class MyScanner(Scanner): |
| 25 | |
| 26 | def destination(self, type, name, arglist): |
| 27 | classname = "Function" |
| 28 | listname = "functions" |
| 29 | if arglist: |
| 30 | t, n, m = arglist[0] |
| 31 | # |
| 32 | # FindNextComponent is a special case, since it call also be called |
| 33 | # with None as the argument. Hence, we make it a function |
| 34 | # |
| 35 | if t == "Component" and m == "InMode" and name != "FindNextComponent": |
| 36 | classname = "Method" |
| 37 | listname = "c_methods" |
| 38 | elif t == "ComponentInstance" and m == "InMode": |
| 39 | classname = "Method" |
| 40 | listname = "ci_methods" |
| 41 | return classname, listname |
| 42 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 43 | def writeinitialdefs(self): |
| 44 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
| 45 | |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 46 | def makeblacklistnames(self): |
| 47 | return [ |
Jack Jansen | 4a8c54e | 1997-02-24 13:56:59 +0000 | [diff] [blame] | 48 | "OpenADefaultComponent", |
| 49 | "GetComponentTypeModSeed", |
| 50 | "OpenAComponentResFile", |
| 51 | "CallComponentUnregister", |
| 52 | "CallComponentTarget", |
| 53 | "CallComponentRegister", |
| 54 | "CallComponentVersion", |
| 55 | "CallComponentCanDo", |
| 56 | "CallComponentClose", |
| 57 | "CallComponentOpen", |
| 58 | "OpenAComponent", |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 59 | "GetComponentPublicResource", # Missing in CW Pro 6 |
| 60 | "CallComponentGetPublicResource", # Missing in CW Pro 6 |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 61 | ] |
| 62 | |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 63 | def makegreylist(self): |
| 64 | return [ |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 65 | ('#if !TARGET_API_MAC_CARBON', [ |
Jack Jansen | 8d929ae | 2000-06-21 22:07:06 +0000 | [diff] [blame] | 66 | 'SetComponentInstanceA5', |
| 67 | 'GetComponentInstanceA5', |
| 68 | ])] |
| 69 | |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 70 | def makeblacklisttypes(self): |
| 71 | return [ |
| 72 | "ResourceSpec", |
| 73 | "ComponentResource", |
| 74 | "ComponentPlatformInfo", |
| 75 | "ComponentResourceExtension", |
| 76 | "ComponentPlatformInfoArray", |
| 77 | "ExtComponentResource", |
| 78 | "ComponentParameters", |
| 79 | |
| 80 | "ComponentRoutineUPP", |
Jack Jansen | 4a8c54e | 1997-02-24 13:56:59 +0000 | [diff] [blame] | 81 | "ComponentMPWorkFunctionUPP", |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame^] | 82 | "ComponentFunctionUPP", |
| 83 | "GetMissingComponentResourceUPP", |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 84 | ] |
| 85 | |
| 86 | def makerepairinstructions(self): |
| 87 | return [ |
| 88 | ([('ComponentDescription', 'looking', 'OutMode')], |
| 89 | [('ComponentDescription', '*', 'InMode')]), |
| 90 | ] |
| 91 | |
| 92 | if __name__ == "__main__": |
| 93 | main() |