]> git.saurik.com Git - wxWidgets.git/commitdiff
Adding preliminary code for C bindings, thanks to Luke A. Guest.
authorKevin Ollivier <kevino@theolliviers.com>
Fri, 17 Jul 2009 18:39:26 +0000 (18:39 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Fri, 17 Jul 2009 18:39:26 +0000 (18:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/doxygen/scripts/c_tools.py [new file with mode: 0644]
docs/doxygen/scripts/make_bindings.py

diff --git a/docs/doxygen/scripts/c_tools.py b/docs/doxygen/scripts/c_tools.py
new file mode 100644 (file)
index 0000000..6df0d9b
--- /dev/null
@@ -0,0 +1,73 @@
+"""\r
+C bindings generator\r
+Author: Luke A. Guest\r
+"""\r
+\r
+import os\r
+\r
+from common import *\r
+\r
+class CBuilder:\r
+    def __init__(self, doxyparse, outputdir):\r
+        self.doxyparser = doxyparse\r
+        self.output_dir = outputdir\r
+\r
+    def make_bindings(self):\r
+        output_dir = os.path.abspath(os.path.join(self.output_dir, "c"))\r
+        if not os.path.exists(output_dir):\r
+            os.makedirs(output_dir)\r
+    \r
+        for aclass in self.doxyparser.classes:\r
+            # This bit doesn't work, because the aclass.name is not the same as\r
+            # those listed in common\r
+            if aclass.name in excluded_classes:\r
+                #print "Skipping %s" % aclass.name\r
+                continue\r
+                \r
+            self.make_c_header(output_dir, aclass)\r
+\r
+\r
+    def make_c_header(self, output_dir, aclass):\r
+            filename = os.path.join(output_dir, aclass.name[2:].lower() + ".hh")\r
+            enums_text = make_enums(aclass)\r
+            method_text = self.make_c_methods(aclass)\r
+            class_name = aclass.name[2:].capitalize()\r
+            text = """\r
+// Enums\r
+%s\r
+\r
+%s\r
+""" % (enums_text, method_text)\r
+\r
+            afile = open(filename, "wb")\r
+            afile.write(text)\r
+            afile.close()\r
+\r
+\r
+    def make_c_methods(self, aclass):\r
+        retval = ""\r
+        \r
+        wxc_classname = 'wxC' + aclass.name[2:].capitalize()\r
+\r
+        for amethod in aclass.constructors:\r
+            if amethod.name.startswith('m_'):\r
+                # for some reason, public members are listed as methods\r
+                continue\r
+            retval += """\r
+// %s\r
+%s%s;\n\n\r
+""" % (amethod.brief_description, wxc_classname + '* ' + wxc_classname + '_' + amethod.name, amethod.argsstring)\r
+\r
+        for amethod in aclass.methods:\r
+            args = '(' + wxc_classname + '* obj'\r
+            if amethod.argsstring.find('()') != -1:\r
+                args += ')'\r
+            else: \r
+                args += ', ' + amethod.argsstring[1:].strip()\r
+            \r
+            retval += """\r
+// %s\r
+%s %s%s;\n\r
+""" % (amethod.detailed_description, amethod.return_type, wxc_classname + '_' + amethod.name, args)\r
+\r
+        return retval\r
index e3e83047c1a1c805944d09763aa60d42617c7399..5411d07b566ac9fd50d8a2e1fe204255cb4c3ab2 100644 (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]
+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."),
+                
+    }
     
-    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()
+    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__":
     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()