/Mac/Modules/list/listscan.py

http://unladen-swallow.googlecode.com/ · Python · 87 lines · 66 code · 17 blank · 4 comment · 4 complexity · 5c173faedeec3944c45491a88bddc310 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
  6. LONG = "Lists"
  7. SHORT = "list"
  8. OBJECT = "ListHandle"
  9. def main():
  10. input = LONG + ".h"
  11. output = SHORT + "gen.py"
  12. defsoutput = TOOLBOXDIR + LONG + ".py"
  13. scanner = MyScanner(input, output, defsoutput)
  14. scanner.scan()
  15. scanner.close()
  16. print "=== Testing definitions output code ==="
  17. execfile(defsoutput, {}, {})
  18. print "=== Done scanning and generating, now importing the generated code... ==="
  19. exec "import " + SHORT + "support"
  20. print "=== Done. It's up to you to compile it now! ==="
  21. class MyScanner(Scanner):
  22. def destination(self, type, name, arglist):
  23. classname = "Function"
  24. listname = "functions"
  25. if arglist:
  26. t, n, m = arglist[-1]
  27. # This is non-functional today
  28. if t in ('ListHandle', 'ListRef') and m == "InMode":
  29. classname = "Method"
  30. listname = "methods"
  31. return classname, listname
  32. def makeblacklistnames(self):
  33. return [
  34. "LDispose", # Done by removing the object
  35. "LSearch", # We don't want to handle procs just yet
  36. "CreateCustomList", # done manually
  37. "SetListDefinitionProc",
  38. # These have funny argument/return values
  39. "GetListViewBounds",
  40. "GetListCellIndent",
  41. "GetListCellSize",
  42. "GetListVisibleCells",
  43. "GetListClickLocation",
  44. "GetListMouseLocation",
  45. "GetListDataBounds",
  46. "SetListLastClick",
  47. ]
  48. def makeblacklisttypes(self):
  49. return [
  50. "ListClickLoopUPP", # Too difficult for now
  51. "ListDefSpecPtr", # later
  52. ]
  53. def makerepairinstructions(self):
  54. return [
  55. ([('ListBounds_ptr', '*', 'InMode')],
  56. [('Rect_ptr', '*', 'InMode')]),
  57. ([("Cell", "theCell", "OutMode")],
  58. [("Cell", "theCell", "InOutMode")]),
  59. ([("void_ptr", "*", "InMode"), ("short", "*", "InMode")],
  60. [("InBufferShortsize", "*", "*")]),
  61. ([("void", "*", "OutMode"), ("short", "*", "OutMode")],
  62. [("VarOutBufferShortsize", "*", "InOutMode")]),
  63. # SetListCellIndent doesn't have const
  64. ([("Point", "indent", "OutMode")],
  65. [("Point_ptr", "indent", "InMode")]),
  66. ]
  67. def writeinitialdefs(self):
  68. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  69. if __name__ == "__main__":
  70. main()