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 |
Jack Jansen | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame] | 4 | from bgenlocations import TOOLBOXDIR, BGENDIR |
Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 5 | sys.path.append(BGENDIR) |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 6 | from scantools import Scanner |
| 7 | |
| 8 | LONG = "Components" |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 9 | SHORT = "cm" |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 10 | |
| 11 | def main(): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 12 | input = "Components.h" |
| 13 | output = SHORT + "gen.py" |
| 14 | defsoutput = TOOLBOXDIR + LONG + ".py" |
| 15 | scanner = MyScanner(input, output, defsoutput) |
| 16 | scanner.scan() |
| 17 | scanner.close() |
| 18 | print "=== Testing definitions output code ===" |
| 19 | execfile(defsoutput, {}, {}) |
| 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! ===" |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 23 | |
| 24 | class MyScanner(Scanner): |
| 25 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 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 |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 42 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 43 | def writeinitialdefs(self): |
| 44 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 45 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 46 | def makeblacklistnames(self): |
| 47 | return [ |
| 48 | "OpenADefaultComponent", |
| 49 | "GetComponentTypeModSeed", |
| 50 | "OpenAComponentResFile", |
| 51 | "CallComponentUnregister", |
| 52 | "CallComponentTarget", |
| 53 | "CallComponentRegister", |
| 54 | "CallComponentVersion", |
| 55 | "CallComponentCanDo", |
| 56 | "CallComponentClose", |
| 57 | "CallComponentOpen", |
| 58 | "OpenAComponent", |
| 59 | "GetComponentPublicResource", # Missing in CW Pro 6 |
| 60 | "CallComponentGetPublicResource", # Missing in CW Pro 6 |
| 61 | 'SetComponentInstanceA5', |
| 62 | 'GetComponentInstanceA5', |
| 63 | ] |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 64 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 65 | def makeblacklisttypes(self): |
| 66 | return [ |
| 67 | "ResourceSpec", |
| 68 | "ComponentResource", |
| 69 | "ComponentPlatformInfo", |
| 70 | "ComponentResourceExtension", |
| 71 | "ComponentPlatformInfoArray", |
| 72 | "ExtComponentResource", |
| 73 | "ComponentParameters", |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 74 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 75 | "ComponentRoutineUPP", |
| 76 | "ComponentMPWorkFunctionUPP", |
| 77 | "ComponentFunctionUPP", |
| 78 | "GetMissingComponentResourceUPP", |
| 79 | ] |
| 80 | |
| 81 | def makerepairinstructions(self): |
| 82 | return [ |
| 83 | ([('ComponentDescription', 'looking', 'OutMode')], |
| 84 | [('ComponentDescription', '*', 'InMode')]), |
| 85 | ] |
| 86 | |
Jack Jansen | b996856 | 1995-11-30 15:03:09 +0000 | [diff] [blame] | 87 | if __name__ == "__main__": |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 88 | main() |