blob: c08394ee2d22b9392f5c674c44ddd9478e41ab3c [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
Jack Jansenaaebdd62002-08-05 15:39:30 +00004from bgenlocations import TOOLBOXDIR, BGENDIR
Just van Rossum79e71f72001-12-13 13:17:20 +00005sys.path.append(BGENDIR)
6from scantools import Scanner_OSX
Just van Rossum79e71f72001-12-13 13:17:20 +00007
8LONG = "CoreGraphics"
9SHORT = "cg"
Tim Peters182b5ac2004-07-18 06:16:08 +000010OBJECTS = ("CGContextRef",
11 )
Just van Rossum79e71f72001-12-13 13:17:20 +000012# ADD object typenames here
13
14def main():
Tim Peters182b5ac2004-07-18 06:16:08 +000015 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! ==="
Just van Rossum79e71f72001-12-13 13:17:20 +000029
30class MyScanner(Scanner_OSX):
31
Tim Peters182b5ac2004-07-18 06:16:08 +000032 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
Just van Rossum79e71f72001-12-13 13:17:20 +000047
Tim Peters182b5ac2004-07-18 06:16:08 +000048 def writeinitialdefs(self):
49 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
Just van Rossum79e71f72001-12-13 13:17:20 +000050
Tim Peters182b5ac2004-07-18 06:16:08 +000051 def makeblacklistnames(self):
52 return [
53 "CGContextRetain",
54 "CGContextRelease",
55 ]
Just van Rossum79e71f72001-12-13 13:17:20 +000056
Tim Peters182b5ac2004-07-18 06:16:08 +000057 def makegreylist(self):
58 return []
Just van Rossum79e71f72001-12-13 13:17:20 +000059
Tim Peters182b5ac2004-07-18 06:16:08 +000060 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 ]
Just van Rossum79e71f72001-12-13 13:17:20 +000073
Tim Peters182b5ac2004-07-18 06:16:08 +000074 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
Just van Rossum79e71f72001-12-13 13:17:20 +000082if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +000083 main()