|
1 # Scan an Apple header file, generating a Python file of generator calls. |
|
2 import sys |
|
3 from bgenlocations import TOOLBOXDIR, BGENDIR |
|
4 sys.path.append(BGENDIR) |
|
5 |
|
6 from scantools import Scanner |
|
7 |
|
8 def main(): |
|
9 input = "QDOffscreen.h" |
|
10 output = "qdoffsgen.py" |
|
11 defsoutput = TOOLBOXDIR + "QDOffscreen.py" |
|
12 scanner = MyScanner(input, output, defsoutput) |
|
13 scanner.scan() |
|
14 scanner.close() |
|
15 print "=== Testing definitions output code ===" |
|
16 execfile(defsoutput, {}, {}) |
|
17 print "=== Done scanning and generating, now importing the generated code... ===" |
|
18 import qdoffssupport |
|
19 print "=== Done. It's up to you to compile it now! ===" |
|
20 |
|
21 class MyScanner(Scanner): |
|
22 |
|
23 def destination(self, type, name, arglist): |
|
24 classname = "Function" |
|
25 listname = "functions" |
|
26 if arglist: |
|
27 t, n, m = arglist[0] |
|
28 if t == "GWorldPtr" and m in ("InMode", "InOutMode"): |
|
29 classname = "Method" |
|
30 listname = "methods" |
|
31 return classname, listname |
|
32 |
|
33 def writeinitialdefs(self): |
|
34 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
|
35 |
|
36 def makeblacklistnames(self): |
|
37 return [ |
|
38 'DisposeGWorld', # Implied when the object is deleted |
|
39 'NewGWorldFromHBITMAP', # Don't know what the args do |
|
40 'GetGDeviceAttributes', # Windows-only |
|
41 ] |
|
42 |
|
43 def makeblacklisttypes(self): |
|
44 return [ |
|
45 "void_ptr", # GetGDeviceSurface, blacklisted for now |
|
46 "Ptr", # Again, for now (array is probably ok here) |
|
47 ] |
|
48 |
|
49 def makerepairinstructions(self): |
|
50 return [ |
|
51 |
|
52 ## ("UpdateGWorld", |
|
53 ## [("GWorldPtr", "*", "OutMode")], |
|
54 ## [("*", "*", "InOutMode")]), |
|
55 |
|
56 # This one is incorrect: we say that all input gdevices are |
|
57 # optional, but some are not. Most are, however, so users passing |
|
58 # None for non-optional gdevices will get a qd error, I guess, in |
|
59 # stead of a python argument error. |
|
60 ([("GDHandle", "*", "InMode")], |
|
61 [("OptGDHandle", "*", "InMode")]), |
|
62 ] |
|
63 |
|
64 if __name__ == "__main__": |
|
65 main() |