/Mac/Modules/cg/cgscan.py

http://unladen-swallow.googlecode.com/ · Python · 83 lines · 66 code · 11 blank · 6 comment · 9 complexity · 497741cd7c12425acab89f97a99f869b MD5 · raw file

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2. import sys
  3. from bgenlocations import TOOLBOXDIR, BGENDIR
  4. sys.path.append(BGENDIR)
  5. from scantools import Scanner_OSX
  6. LONG = "CoreGraphics"
  7. SHORT = "cg"
  8. OBJECTS = ("CGContextRef",
  9. )
  10. # ADD object typenames here
  11. def main():
  12. input = [
  13. "CGContext.h",
  14. ]
  15. output = SHORT + "gen.py"
  16. defsoutput = TOOLBOXDIR + LONG + ".py"
  17. scanner = MyScanner(input, output, defsoutput)
  18. scanner.scan()
  19. scanner.gentypetest(SHORT+"typetest.py")
  20. scanner.close()
  21. print "=== Testing definitions output code ==="
  22. execfile(defsoutput, {}, {})
  23. print "=== Done scanning and generating, now importing the generated code... ==="
  24. exec "import " + SHORT + "support"
  25. print "=== Done. It's up to you to compile it now! ==="
  26. class MyScanner(Scanner_OSX):
  27. def destination(self, type, name, arglist):
  28. classname = "Function"
  29. listname = "functions"
  30. if arglist:
  31. t, n, m = arglist[0]
  32. if t in OBJECTS and m == "InMode":
  33. classname = "Method"
  34. listname = t + "_methods"
  35. # Special case for the silly first AllocatorRef argument
  36. if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
  37. t, n, m = arglist[1]
  38. if t in OBJECTS and m == "InMode":
  39. classname = "MethodSkipArg1"
  40. listname = t + "_methods"
  41. return classname, listname
  42. def writeinitialdefs(self):
  43. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  44. def makeblacklistnames(self):
  45. return [
  46. "CGContextRetain",
  47. "CGContextRelease",
  48. ]
  49. def makegreylist(self):
  50. return []
  51. def makeblacklisttypes(self):
  52. return [
  53. "float_ptr",
  54. "CGRect_ptr",
  55. "CGPoint_ptr",
  56. "CGColorSpaceRef",
  57. "CGColorRenderingIntent",
  58. "CGFontRef",
  59. # "char_ptr",
  60. "CGGlyph_ptr",
  61. "CGImageRef",
  62. "CGPDFDocumentRef",
  63. ]
  64. def makerepairinstructions(self):
  65. return [
  66. ([("char_ptr", "cstring", "InMode"), ("size_t", "length", "InMode")],
  67. [("InBuffer", "*", "*")]),
  68. # ([("char_ptr", "name", "InMode"),],
  69. # [("CCCCC", "*", "*")]),
  70. ]
  71. if __name__ == "__main__":
  72. main()