/Mac/Modules/cm/cmscan.py

http://unladen-swallow.googlecode.com/ · Python · 88 lines · 72 code · 11 blank · 5 comment · 7 complexity · 237cbb4bd334108e0d810d8fe704f2e7 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 = "Components"
  7. SHORT = "cm"
  8. def main():
  9. input = "Components.h"
  10. output = SHORT + "gen.py"
  11. defsoutput = TOOLBOXDIR + LONG + ".py"
  12. scanner = MyScanner(input, output, defsoutput)
  13. scanner.scan()
  14. scanner.close()
  15. print "=== Testing definitions output code ==="
  16. execfile(defsoutput, {}, {})
  17. print "=== Done scanning and generating, now importing the generated code... ==="
  18. exec "import " + SHORT + "support"
  19. print "=== Done. It's up to you to compile it now! ==="
  20. class MyScanner(Scanner):
  21. def destination(self, type, name, arglist):
  22. classname = "Function"
  23. listname = "functions"
  24. if arglist:
  25. t, n, m = arglist[0]
  26. #
  27. # FindNextComponent is a special case, since it call also be called
  28. # with None as the argument. Hence, we make it a function
  29. #
  30. if t == "Component" and m == "InMode" and name != "FindNextComponent":
  31. classname = "Method"
  32. listname = "c_methods"
  33. elif t == "ComponentInstance" and m == "InMode":
  34. classname = "Method"
  35. listname = "ci_methods"
  36. return classname, listname
  37. def writeinitialdefs(self):
  38. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  39. def makeblacklistnames(self):
  40. return [
  41. "OpenADefaultComponent",
  42. "GetComponentTypeModSeed",
  43. "OpenAComponentResFile",
  44. "CallComponentUnregister",
  45. "CallComponentTarget",
  46. "CallComponentRegister",
  47. "CallComponentVersion",
  48. "CallComponentCanDo",
  49. "CallComponentClose",
  50. "CallComponentOpen",
  51. "OpenAComponent",
  52. "GetComponentPublicResource", # Missing in CW Pro 6
  53. "CallComponentGetPublicResource", # Missing in CW Pro 6
  54. 'SetComponentInstanceA5',
  55. 'GetComponentInstanceA5',
  56. ]
  57. def makeblacklisttypes(self):
  58. return [
  59. "ResourceSpec",
  60. "ComponentResource",
  61. "ComponentPlatformInfo",
  62. "ComponentResourceExtension",
  63. "ComponentPlatformInfoArray",
  64. "ExtComponentResource",
  65. "ComponentParameters",
  66. "ComponentRoutineUPP",
  67. "ComponentMPWorkFunctionUPP",
  68. "ComponentFunctionUPP",
  69. "GetMissingComponentResourceUPP",
  70. ]
  71. def makerepairinstructions(self):
  72. return [
  73. ([('ComponentDescription', 'looking', 'OutMode')],
  74. [('ComponentDescription', '*', 'InMode')]),
  75. ]
  76. if __name__ == "__main__":
  77. main()