Just van Rossum | 79e71f7 | 2001-12-13 13:17:20 +0000 | [diff] [blame^] | 1 | # Scan an Apple header file, generating a Python file of generator calls. |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') |
| 6 | sys.path.append(BGENDIR) |
| 7 | from scantools import Scanner_OSX |
| 8 | from bgenlocations import TOOLBOXDIR |
| 9 | |
| 10 | LONG = "CoreGraphics" |
| 11 | SHORT = "cg" |
| 12 | OBJECTS = ("CGContextRef", |
| 13 | ) |
| 14 | # ADD object typenames here |
| 15 | |
| 16 | def 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 | |
| 30 | class 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 | |
| 82 | if __name__ == "__main__": |
| 83 | main() |