[cfe-dev] manipulating AST with ASTConsumer

Ilya Mirsky ilya.mirsky at gmail.com
Wed Aug 11 07:17:08 PDT 2010


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 <http://clang.llvm.org/doxygen/>.

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:
1. Alter function signutures (type and params),
2. 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

-- 
Best Regards,
Ilya Mirsky
www.cs.bgu.ac.il/~mirskyil <http://www.cs.bgu.ac.il/%7Emirskyil>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100811/bfea6728/attachment.html>


More information about the cfe-dev mailing list