blob: b2e79461953be45f64787a9e53376bd2b88649df [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"
Tim Peters182b5ac2004-07-18 06:16:08 +000011OBJECTS = ("CGContextRef",
12 )
Just van Rossum79e71f72001-12-13 13:17:20 +000013# ADD object typenames here
14
15def main():
Tim Peters182b5ac2004-07-18 06:16:08 +000016 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 "=== Testing definitions output code ==="
26 execfile(defsoutput, {}, {})
27 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! ==="
Just van Rossum79e71f72001-12-13 13:17:20 +000030
31class MyScanner(Scanner_OSX):
32
Tim Peters182b5ac2004-07-18 06:16:08 +000033 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
Just van Rossum79e71f72001-12-13 13:17:20 +000048
Tim Peters182b5ac2004-07-18 06:16:08 +000049 def writeinitialdefs(self):
50 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
Just van Rossum79e71f72001-12-13 13:17:20 +000051
Tim Peters182b5ac2004-07-18 06:16:08 +000052 def makeblacklistnames(self):
53 return [
54 "CGContextRetain",
55 "CGContextRelease",
56 ]
Just van Rossum79e71f72001-12-13 13:17:20 +000057
Tim Peters182b5ac2004-07-18 06:16:08 +000058 def makegreylist(self):
59 return []
Just van Rossum79e71f72001-12-13 13:17:20 +000060
Tim Peters182b5ac2004-07-18 06:16:08 +000061 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 ]
Just van Rossum79e71f72001-12-13 13:17:20 +000074
Tim Peters182b5ac2004-07-18 06:16:08 +000075 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
Just van Rossum79e71f72001-12-13 13:17:20 +000083if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +000084 main()