1# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4from bgenlocations import TOOLBOXDIR, BGENDIR
5sys.path.append(BGENDIR)
6from scantools import Scanner_OSX
7
8LONG = "CoreGraphics"
9SHORT = "cg"
10OBJECTS = ("CGContextRef",
11                )
12# ADD object typenames here
13
14def main():
15    input = [
16            "CGContext.h",
17    ]
18    output = SHORT + "gen.py"
19    defsoutput = TOOLBOXDIR + LONG + ".py"
20    scanner = MyScanner(input, output, defsoutput)
21    scanner.scan()
22    scanner.gentypetest(SHORT+"typetest.py")
23    scanner.close()
24    print "=== Testing definitions output code ==="
25    execfile(defsoutput, {}, {})
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! ==="
29
30class MyScanner(Scanner_OSX):
31
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
47
48    def writeinitialdefs(self):
49        self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
50
51    def makeblacklistnames(self):
52        return [
53                "CGContextRetain",
54                "CGContextRelease",
55                ]
56
57    def makegreylist(self):
58        return []
59
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",
72                ]
73
74    def makerepairinstructions(self):
75        return [
76                ([("char_ptr", "cstring", "InMode"), ("size_t", "length", "InMode")],
77                 [("InBuffer", "*", "*")]),
78#                       ([("char_ptr", "name", "InMode"),],
79#                        [("CCCCC", "*", "*")]),
80                ]
81
82if __name__ == "__main__":
83    main()
84