Hi Eric,

On Apr 9, 2009, at 11:18 AM, Eric Kow wrote:

> On Thu, Apr 09, 2009 at 18:57:29 +0100, Eric Kow wrote:
>> This is where Kevin Ollivier of wxWidgets pointed out something
>> interesting: in the current wxWidgets trunk, it should be possible to
>> automatically generate the C bindings from the Doxygen XML output.   
>> In
>> fact, he has already done something similar for Python, metadata to
>> Python objects:
>>
>> http://trac.wxwidgets.org/browser/wxWidgets/trunk/docs/doxygen/doxymlparser.py
>
> Following up on this, I did
>
>  svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk  
> wxWidgets
>  cd wxWidgets/doc/doxygen
>  ./regen.sh
>  python doxymlparser.py --report out/xml/classwx_button.xml
>
> Attached is the XML file (input) and the output of this script.
>
> Here is a small extract of the output:
>
>  Class: wxButton
>  Bases: wxControl
>  Inlcudes: []
>  Brief Description:
>
> And...
>
>  Method: SetLabel
>  Return Type: void
>  Params: [{u'type': u'const&', u'declname': u'label'}]
>  Prototype: void wxButton::SetLabel(const wxString &label)
>  Brief Description:
>
> What can we do with this?

As a start, with a few lines of Python code after the  
doxyparser.parse(file) calls in the script, you can do something like:

# start code to autogenerate wxc.h
wxc_header = ""

for aclass in doxyparse.classes:
        for amethod in methods:
                self_ref = "TSelf"
                if amethod.name == "Create":
                        self_ref = "TClass"
                        wxc_header += "%s(%s) " % (self_ref, aclass.name)
                else:
                        wxc_header += "%s " % 
(wxc_type_for_type(amethod.return_type)

                wxc_header += "%s_%s( %s _obj" % (aclass.name, amethod.name,  
self_ref + (" + aclass.name + ")")

                for param in amethod.params:
                        wxc_header += ", %s %s" % 
(wxc_type_for_type(param["type"]), "_" +  
param["declname"])
                        # Note: uncomment this if you support adding default 
values
                        # if "defval" in param:
                        #       wxc_header += "=" + param["defval"]
                wxc_header += " );\n"

wxc_file = open("wxc.h", "wb")
wxc_file.write(wxc_header)
wxc_file.close()

# end code

This is all just pseudo-code, and methods like wxc_type_for_type would  
need implemented, and you'd also need to probably work out some  
special logic for constructors, a list of classes to exclude, etc. but  
this should give you an idea of how to start things off. Ideally you'd  
actually have your own generate_c_bindings.py file that does an  
"import doxyparser", then runs "doxyparse.parse()" itself rather than  
extending the doxymlparser.py script, but anyway, just some ideas.

Regards,

Kevin

> -- 
> Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
> PGP Key ID: 08AC04F9
> <classwx_button.xml><wx-button.out>


------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to