C++ Binding Generator

Jacob Carlborg doob at me.com
Sat Feb 15 03:25:08 PST 2014


On 2014-02-15 00:52, Paul O'Neil wrote:

> Also relevant is that the libclang bindings in Deimos[3] are 2 years and
> several versions old (3.1 -> 3.4 is out).  This is probably due to the
> lack of interest in libclang from D programmers (No surprise.  Who wants
> to write code in D to parse C(++)?).

I originally create those bindings to be used by DStep. But never bother 
updating them after that. DStep contains its own bindings. I haven't 
updated the bindings to anything later than 3.1 since I don't use any of 
these features yet.

> It binds to libclang's C interface  and may have been generated with DStep.

Actually, I just did some simple search-and-replace on the original C 
header. libclang is the easiest binding I've created :)

> Here's my proposed path forward:
> Write a binding generator in C++ that uses libclang to parse headers and
> auxillary XML / json / etc. files to guide the generation of D source.
> Clang provides data structures for traversing the C++ AST.  This tool
> could be used to bind Qt 5 and libclang so the conversion tool can
> eventually be migrated to D.  My hope is that using clang to avoid
> writing another C++ parser and D's similarity to C++ make this an easier
> (though still significant) undertaking than the Java bindings.

Why not contribute to DStep?

> I suspect that there are several patterns in C++ and D that are
> implemented using slightly different constructions in each of them.  For
> instance, figuring out which C++ classes should map to D structs.
> Automatically identifying these or finding a description language for
> them would be a huge benefit to automation.
>
> On the other hand, I don't yet see a way to map generic containers (such
> as QList<T>) into D yet.  But Qt Jambi found some way to solve this
> problem even when dealing with type erasure in Java.

You could hard code a couple of these containers. QList<T> could be 
converted to T[] or a linked list. I've done that with a couple of other 
types: like "BOOL" is translated to "bool" and "wchar_t" is translated 
to "wchar".

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list