Open dobkeratops opened 9 years ago
I've thought about this before.
The C++ code maybe have lots of macro, or template meta-programming. And this is very complicated, also there are lots of black magics but useful when writing libraries.
I think we can take the advantage of these existing libraries by directly include them, but trying to convert them back just makes little sense.
True macros & elaborate TMP,sfinae subtleties etc are probably the biggest sticking points; perhaps it would be possible to assist code-cleanup by reporting where auto-translation is possible (e.g. checking the boundaries of macro invocations vs AST nodes..)
https://github.com/rose-compiler/rose - rosecompiler might prove handy for the task. There is frontends (parse to AST) for many languages (C++) included. Then there's a bunch of middleends [sic] for working on the AST's. Then there are backends - for "unparsing" [sic]. There is a complete C++ generator too. It might prove a good basis for building a SugarCpp/etc renderer from C++ AST. I've been pondering using this if I ever got the time to play around with a pet language, I guess I'll follow both yours more closely instead :)
[edited out stuff that gmail through in when replying]
are you considering auto-translation from C++ to SugarCpp (not necaserily everything);
I'm after such a tool for my experiment - I haven't started one, but have some earlier attempts at a header generator for Rust using clang. (this ran into the troubles you'd expect - Rust is not designed to represent C++ programs)
I think our languages are similar enough that the same tool could handle both with some switches. What would be really interesting is actually trying to recognise patterns in C++ and translate them into sugar.
Imagine if you could just translate back & forth, as easily as reformatting...