Automated source translation of C++ to D
Daniel Murphy via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 22 00:48:34 PDT 2014
"Joakim" wrote in message news:ynfwlptfuzfutksbnslc at forum.dlang.org...
> Yes, I'm aware of ddmd. You've mentioned many times that it only works
> because dmd is written using a very unC++-like style, to the point where
> github's source analyzer claims that dmd is written in 66.7% C, 28.4% D
> (presumably the tests right now), 4.4% C++, and 0.5% other. :)
The style dmd is written in makes it a lot easier, but it would still be
possible with other styles. As others have said the github numbers have
nothing to do with the style of the code, only the naming of the files.
> Given tools like libclang, how hard do you think it'd be to translate most
> of actual C++ to D? If writing such a tool would mean that C++->D
> translation is the path of least effort for D users who want to integrate
> with C++, maybe that's the approach that should be taken instead.
A tool that can translate an arbitrary C++ program to D is not going to
happen.
A tool that can translate a specific C++ program to D is not particularly
difficult to produce, as I've done with dmd. eg multiple inheritance cannot
be generally mapped to D code. But in many applications, the use of
multiple inheritance _can_ be mapped because it corresponds to classes +
interfaces. This type of application-specific knowledge can significantly
reduce the complexity.
DDMD actually has a major additional complication that most translations
would not have - it is only a partial translation (glue layer stays in C++)
and therefore needs abi stability across the boundary. I initially did a
non-abi-stable translation of only the frontend, and it was rather easy in
comparison.
So no, you can't magically upgrade a project from C++ to D. But it can be
done, and is not prohibitively difficult someone experienced with C++ and D.
More information about the Digitalmars-d
mailing list