blob: 4ed2127be76542fa15b0832754cb43231838a965 [file] [log] [blame]
Just van Rossum79e71f72001-12-13 13:17:20 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4import os
Jack Jansenaaebdd62002-08-05 15:39:30 +00005from bgenlocations import TOOLBOXDIR, BGENDIR
Just van Rossum79e71f72001-12-13 13:17:20 +00006sys.path.append(BGENDIR)
7from scantools import Scanner_OSX
Just van Rossum79e71f72001-12-13 13:17:20 +00008
9LONG = "CoreGraphics"
10SHORT = "cg"
11OBJECTS = ("CGContextRef",
12 )
13# ADD object typenames here
14
15def main():
16 input = [
17 "CGContext.h",
18 ]
19 output = SHORT + "gen.py"
20 defsoutput = TOOLBOXDIR + LONG + ".py"
21 scanner = MyScanner(input, output, defsoutput)
22 scanner.scan()
23 scanner.gentypetest(SHORT+"typetest.py")
24 scanner.close()
25 print "=== Done scanning and generating, now importing the generated code... ==="
26 exec "import " + SHORT + "support"
27 print "=== Done. It's up to you to compile it now! ==="
28
29class MyScanner(Scanner_OSX):
30
31 def destination(self, type, name, arglist):
32 classname = "Function"
33 listname = "functions"
34 if arglist:
35 t, n, m = arglist[0]
36 if t in OBJECTS and m == "InMode":
37 classname = "Method"
38 listname = t + "_methods"
39 # Special case for the silly first AllocatorRef argument
40 if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
41 t, n, m = arglist[1]
42 if t in OBJECTS and m == "InMode":
43 classname = "MethodSkipArg1"
44 listname = t + "_methods"
45 return classname, listname
46
47 def writeinitialdefs(self):
48 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
49
50 def makeblacklistnames(self):
51 return [
52 "CGContextRetain",
53 "CGContextRelease",
54 ]
55
56 def makegreylist(self):
57 return []
58
59 def makeblacklisttypes(self):
60 return [
61 "float_ptr",
62 "CGRect_ptr",
63 "CGPoint_ptr",
64 "CGColorSpaceRef",
65 "CGColorRenderingIntent",
66 "CGFontRef",
67# "char_ptr",
68 "CGGlyph_ptr",
69 "CGImageRef",
70 "CGPDFDocumentRef",
71 ]
72
73 def makerepairinstructions(self):
74 return [
75 ([("char_ptr", "cstring", "InMode"), ("size_t", "length", "InMode")],
76 [("InBuffer", "*", "*")]),
77# ([("char_ptr", "name", "InMode"),],
78# [("CCCCC", "*", "*")]),
79 ]
80
81if __name__ == "__main__":
82 main()