c_tools.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. C bindings generator
  3. Author: Luke A. Guest
  4. """
  5. import os
  6. from common import *
  7. class CBuilder:
  8. def __init__(self, doxyparse, outputdir):
  9. self.doxyparser = doxyparse
  10. self.output_dir = outputdir
  11. def make_bindings(self):
  12. output_dir = os.path.abspath(os.path.join(self.output_dir, "c"))
  13. if not os.path.exists(output_dir):
  14. os.makedirs(output_dir)
  15. for aclass in self.doxyparser.classes:
  16. # This bit doesn't work, because the aclass.name is not the same as
  17. # those listed in common
  18. if aclass.name in excluded_classes:
  19. #print "Skipping %s" % aclass.name
  20. continue
  21. self.make_c_header(output_dir, aclass)
  22. def make_c_header(self, output_dir, aclass):
  23. filename = os.path.join(output_dir, aclass.name[2:].lower() + ".hh")
  24. enums_text = make_enums(aclass)
  25. method_text = self.make_c_methods(aclass)
  26. class_name = aclass.name[2:].capitalize()
  27. text = """
  28. // Enums
  29. %s
  30. %s
  31. """ % (enums_text, method_text)
  32. afile = open(filename, "wb")
  33. afile.write(text)
  34. afile.close()
  35. def make_c_methods(self, aclass):
  36. retval = ""
  37. wxc_classname = 'wxC' + aclass.name[2:].capitalize()
  38. for amethod in aclass.constructors:
  39. retval += """
  40. // %s
  41. %s%s;\n\n
  42. """ % (amethod.brief_description, wxc_classname + '* ' + wxc_classname + '_' + amethod.name, amethod.argsstring)
  43. for amethod in aclass.methods:
  44. if amethod.name.startswith('m_'):
  45. # for some reason, public members are listed as methods
  46. continue
  47. args = '(' + wxc_classname + '* obj'
  48. if amethod.argsstring.find('()') != -1:
  49. args += ')'
  50. else:
  51. args += ', ' + amethod.argsstring[1:].strip()
  52. retval += """
  53. // %s
  54. %s %s%s;\n
  55. """ % (amethod.detailed_description, amethod.return_type, wxc_classname + '_' + amethod.name, args)
  56. return retval