I have an AST that has been parsed by Clang. How do I generate the equivalent C++ code for the AST? I would like the result as an std::string
and formatted in a readable way.
Another way of putting this question is: can I use clang-format like a library?
For example, the AST of this source code:
int main() {
int y = 4;
int x = y+ 7; return 0;}
... might become this std::string
:
int main()
{
int y = 4;
int x = y + 7;
return 0;
}
The ideal API would be something like:
std::string deparse(clang::TranslationUnitDecl* root)