/Mac/Modules/scrap/scrapscan.py

http://unladen-swallow.googlecode.com/ · Python · 60 lines · 45 code · 9 blank · 6 comment · 4 complexity · 28e08ff0e680899ff815b3f2ecfa8146 MD5 · raw file

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2. #
  3. # Note that the scrap-manager include file is so weird that this
  4. # generates a boilerplate to be edited by hand.
  5. import sys
  6. from bgenlocations import TOOLBOXDIR, BGENDIR
  7. sys.path.append(BGENDIR)
  8. from scantools import Scanner
  9. LONG = "Scrap"
  10. SHORT = "scrap"
  11. def main():
  12. input = "Scrap.h"
  13. output = SHORT + "gen.py"
  14. defsoutput = "@Scrap.py"
  15. scanner = MyScanner(input, output, defsoutput)
  16. scanner.scan()
  17. scanner.close()
  18. ## print "=== Testing definitions output code ==="
  19. ## execfile(defsoutput, {}, {})
  20. print "=== Done scanning and generating, now importing the generated code... ==="
  21. exec "import " + SHORT + "support"
  22. print "=== Done. It's up to you to compile it now! ==="
  23. class MyScanner(Scanner):
  24. def destination(self, type, name, arglist):
  25. classname = "Function"
  26. listname = "functions"
  27. if arglist:
  28. t, n, m = arglist[0]
  29. if t == 'ScrapRef' and m == "InMode":
  30. classname = "Method"
  31. listname = "methods"
  32. return classname, listname
  33. def makeblacklistnames(self):
  34. return [
  35. "GetScrapFlavorInfoList",
  36. 'InfoScrap',
  37. 'GetScrap',
  38. 'ZeroScrap',
  39. 'PutScrap',
  40. ]
  41. def makeblacklisttypes(self):
  42. return [
  43. 'ScrapPromiseKeeperUPP',
  44. ]
  45. def makerepairinstructions(self):
  46. return [
  47. ([('void', '*', 'OutMode')], [('putscrapbuffer', '*', 'InMode')]),
  48. ([('void_ptr', '*', 'InMode')], [('putscrapbuffer', '*', 'InMode')]),
  49. ]
  50. if __name__ == "__main__":
  51. main()