blob: f67647008d195cf923f91059833914e42c36efb0 [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
5BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6sys.path.append(BGENDIR)
7from scantools import Scanner_OSX
8from bgenlocations import TOOLBOXDIR
9
10LONG = "CoreGraphics"
11SHORT = "cg"
12OBJECTS = ("CGContextRef",
13 )
14# ADD object typenames here
15
16def main():
17 input = [
18 "CGContext.h",
19 ]
20 output = SHORT + "gen.py"
21 defsoutput = TOOLBOXDIR + LONG + ".py"
22 scanner = MyScanner(input, output, defsoutput)
23 scanner.scan()
24 scanner.gentypetest(SHORT+"typetest.py")
25 scanner.close()
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()