Trying to add C++ header generation to dmd

Gregor Mückl gregormueckl at gmx.de
Tue Mar 19 20:55:34 UTC 2019


Hi!

I tried to hack a bit on dmd to have it generate a C++ header for 
a D module. I've copied the visitor in hdrgen.d and did truly 
terrible things to it, to the point where I don't feel confident 
that I want to show that code to anyone.

So now I get something almost resembling C++ code for a few 
really trivial definitions in the input D module. But that is for 
all definitions, not just the ones marked external(C++).

This is the point where I'm actually stumped now. The 
PrettyPrintVisitor, which I used as a template, does not really 
make it easy to discover the context of a visited AST node. In 
particular, I don't know how to determine if one of the parent 
nodes possess the required extern(C++) linkage specification to 
be considered for exporting.

If there was a way for the visitor to know when the subtree below 
a certain node has been visited completely, it could then 
trivially track linkage as a kind of a contextual information.

So to anyone who knows dmd better than me: how would you go about 
implementing the visitor in such a way that it only exports the 
correct AST subtrees?

Gregor


More information about the Digitalmars-d mailing list