Adding preliminary code for C bindings, thanks to Luke A. Guest.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2009-07-17 18:39:26 +00:00
parent edaadd8cd2
commit 1013a78945
2 changed files with 101 additions and 21 deletions

View File

@@ -0,0 +1,73 @@
"""
C bindings generator
Author: Luke A. Guest
"""
import os
from common import *
class CBuilder:
def __init__(self, doxyparse, outputdir):
self.doxyparser = doxyparse
self.output_dir = outputdir
def make_bindings(self):
output_dir = os.path.abspath(os.path.join(self.output_dir, "c"))
if not os.path.exists(output_dir):
os.makedirs(output_dir)
for aclass in self.doxyparser.classes:
# This bit doesn't work, because the aclass.name is not the same as
# those listed in common
if aclass.name in excluded_classes:
#print "Skipping %s" % aclass.name
continue
self.make_c_header(output_dir, aclass)
def make_c_header(self, output_dir, aclass):
filename = os.path.join(output_dir, aclass.name[2:].lower() + ".hh")
enums_text = make_enums(aclass)
method_text = self.make_c_methods(aclass)
class_name = aclass.name[2:].capitalize()
text = """
// Enums
%s
%s
""" % (enums_text, method_text)
afile = open(filename, "wb")
afile.write(text)
afile.close()
def make_c_methods(self, aclass):
retval = ""
wxc_classname = 'wxC' + aclass.name[2:].capitalize()
for amethod in aclass.constructors:
if amethod.name.startswith('m_'):
# for some reason, public members are listed as methods
continue
retval += """
// %s
%s%s;\n\n
""" % (amethod.brief_description, wxc_classname + '* ' + wxc_classname + '_' + amethod.name, amethod.argsstring)
for amethod in aclass.methods:
args = '(' + wxc_classname + '* obj'
if amethod.argsstring.find('()') != -1:
args += ')'
else:
args += ', ' + amethod.argsstring[1:].strip()
retval += """
// %s
%s %s%s;\n
""" % (amethod.detailed_description, amethod.return_type, wxc_classname + '_' + amethod.name, args)
return retval

View File

@@ -1,34 +1,37 @@
import doxymlparser
import optparse
import sys
import os
import string
import types
import c_tools
import doxymlparser
import sip_tools
import swig_tools
import types
from common import *
option_dict = {
"output_dir" : ("output", "Directory to output bindings to"),
"sip" : (True, "Produce SIP bindings"),
"swig" : (True, "Produce SWIG bindings."),
}
parser = optparse.OptionParser(usage="usage: %prog <doxyml files to parse>\n" , version="%prog 1.0")
for opt in option_dict:
default = option_dict[opt][0]
action = "store"
if type(default) == types.BooleanType:
action = "store_true"
parser.add_option("--" + opt, default=default, action=action, dest=opt, help=option_dict[opt][1])
options, arguments = parser.parse_args()
if __name__ == "__main__":
option_dict = {
"output_dir" : ("output", "Directory to output bindings to"),
"sip" : (True, "Produce SIP bindings"),
"swig" : (True, "Produce SWIG bindings."),
"c" : (True, "Produce C wrappers."),
}
parser = optparse.OptionParser(usage="usage: %prog <doxyml files to parse>\n" , version="%prog 1.0")
for opt in option_dict:
default = option_dict[opt][0]
action = "store"
if type(default) == types.BooleanType:
action = "store_true"
parser.add_option("--" + opt, default=default, action=action, dest=opt, help=option_dict[opt][1])
options, arguments = parser.parse_args()
if len(arguments) < 1:
parser.print_usage()
sys.exit(1)
@@ -44,3 +47,7 @@ if __name__ == "__main__":
if options.swig:
builder = swig_tools.SWIGBuilder(doxyparse, options.output_dir)
builder.make_bindings()
if options.c:
builder = c_tools.CBuilder(doxyparse, options.output_dir)
builder.make_bindings()