This commit was manufactured by cvs2svn to create tag 'r221c2'.
[python/dscho.git] / Mac / Modules / cg / cgscan.py
blobf67647008d195cf923f91059833914e42c36efb0
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 import os
5 BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6 sys.path.append(BGENDIR)
7 from scantools import Scanner_OSX
8 from bgenlocations import TOOLBOXDIR
10 LONG = "CoreGraphics"
11 SHORT = "cg"
12 OBJECTS = ("CGContextRef",
14 # ADD object typenames here
16 def main():
17 input = [
18 "CGContext.h",
20 output = SHORT + "gen.py"
21 defsoutput = TOOLBOXDIR + LONG + ".py"
22 scanner = MyScanner(input, output, defsoutput)
23 scanner.scan()
24 scanner.gentypetest(SHORT+"typetest.py")
25 scanner.close()
26 print "=== Done scanning and generating, now importing the generated code... ==="
27 exec "import " + SHORT + "support"
28 print "=== Done. It's up to you to compile it now! ==="
30 class MyScanner(Scanner_OSX):
32 def destination(self, type, name, arglist):
33 classname = "Function"
34 listname = "functions"
35 if arglist:
36 t, n, m = arglist[0]
37 if t in OBJECTS and m == "InMode":
38 classname = "Method"
39 listname = t + "_methods"
40 # Special case for the silly first AllocatorRef argument
41 if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
42 t, n, m = arglist[1]
43 if t in OBJECTS and m == "InMode":
44 classname = "MethodSkipArg1"
45 listname = t + "_methods"
46 return classname, listname
48 def writeinitialdefs(self):
49 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
51 def makeblacklistnames(self):
52 return [
53 "CGContextRetain",
54 "CGContextRelease",
57 def makegreylist(self):
58 return []
60 def makeblacklisttypes(self):
61 return [
62 "float_ptr",
63 "CGRect_ptr",
64 "CGPoint_ptr",
65 "CGColorSpaceRef",
66 "CGColorRenderingIntent",
67 "CGFontRef",
68 # "char_ptr",
69 "CGGlyph_ptr",
70 "CGImageRef",
71 "CGPDFDocumentRef",
74 def makerepairinstructions(self):
75 return [
76 ([("char_ptr", "cstring", "InMode"), ("size_t", "length", "InMode")],
77 [("InBuffer", "*", "*")]),
78 # ([("char_ptr", "name", "InMode"),],
79 # [("CCCCC", "*", "*")]),
82 if __name__ == "__main__":
83 main()