blob: 5d84500d6eb6a8ba23989fe654cbd76cde49df40 [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()
Jack Jansen87eea882002-08-15 21:48:16 +000025 print "=== Testing definitions output code ==="
26 execfile(defsoutput, {}, {})
Just van Rossum79e71f72001-12-13 13:17:20 +000027 print "=== Done scanning and generating, now importing the generated code... ==="
28 exec "import " + SHORT + "support"
29 print "=== Done. It's up to you to compile it now! ==="
30
31class MyScanner(Scanner_OSX):
32
33 def destination(self, type, name, arglist):
34 classname = "Function"
35 listname = "functions"
36 if arglist:
37 t, n, m = arglist[0]
38 if t in OBJECTS and m == "InMode":
39 classname = "Method"
40 listname = t + "_methods"
41 # Special case for the silly first AllocatorRef argument
42 if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
43 t, n, m = arglist[1]
44 if t in OBJECTS and m == "InMode":
45 classname = "MethodSkipArg1"
46 listname = t + "_methods"
47 return classname, listname
48
49 def writeinitialdefs(self):
50 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
51
52 def makeblacklistnames(self):
53 return [
54 "CGContextRetain",
55 "CGContextRelease",
56 ]
57
58 def makegreylist(self):
59 return []
60
61 def makeblacklisttypes(self):
62 return [
63 "float_ptr",
64 "CGRect_ptr",
65 "CGPoint_ptr",
66 "CGColorSpaceRef",
67 "CGColorRenderingIntent",
68 "CGFontRef",
69# "char_ptr",
70 "CGGlyph_ptr",
71 "CGImageRef",
72 "CGPDFDocumentRef",
73 ]
74
75 def makerepairinstructions(self):
76 return [
77 ([("char_ptr", "cstring", "InMode"), ("size_t", "length", "InMode")],
78 [("InBuffer", "*", "*")]),
79# ([("char_ptr", "name", "InMode"),],
80# [("CCCCC", "*", "*")]),
81 ]
82
83if __name__ == "__main__":
84 main()