Hi all,
Not sure if it’s the right place for this kind of questions, if not- please refer me to the right place.
I want to use clang to manipulate AST of a c++ source, and write back the modified source to an output file.
I’m trying to get familiar with clang and llvm for 2 weeks now, but having problems since all tutorials I found are outdated,
and so is the API.
I’ve managed to run some tutorial which changes function names thru ASTConsumer implementation,
which calls the Visit method of DeclVisitor class, and the manipultion is done in the VisitFunctionDecl method.
Basically I’m able retrieve pretty much all I need from the AST.
My problem is modifying the AST:
- Alter function signutures (type and params),
- Adding a statement or a declaration to a block (both global and in function scope).
i.e. a function or variable declaration, a conditional statement.
I’ll be grateful if someone could give me a concrete example how to do the above operation.
Thanks in advance,
Ilya
Hi all,
Not sure if it’s the right place for this kind of questions, if not- please refer me to the right place.
I want to use clang to manipulate AST of a c++ source, and write back the modified source to an output file.
I’m trying to get familiar with clang and llvm for 2 weeks now, but having problems since all tutorials I found are outdated,
and so is the API.
The API documentation is generated nightly; it’s only out-of-date if the comments in the source are out-of-date, and if that’s the case… please tell us!
I’ve managed to run some tutorial which changes function names thru ASTConsumer implementation,
which calls the Visit method of DeclVisitor class, and the manipultion is done in the VisitFunctionDecl method.
Basically I’m able retrieve pretty much all I need from the AST.
My problem is modifying the AST:
- Alter function signutures (type and params),
- Adding a statement or a declaration to a block (both global and in function scope).
i.e. a function or variable declaration, a conditional statement.
The AST is not designed to be mutated. For source-to-source transformations, we recommend using the rewriting infrastructure to produce rewritten source for just those parts of the AST that are changing. See lib/Rewrite/RewriterObjc.cpp for an example of a non-trivial source-to-source translator.