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