<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 11, 2010, at 7:17 AM, Ilya Mirsky wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi all,<br><br>Not sure if it's the right place for this kind of questions, if not- please refer me to the right place.<br>I want to use clang to manipulate AST of a c++ source, and write back the modified source to an output file.<br>
I'm trying to get familiar with clang and llvm for 2 weeks now, but having problems since all tutorials I found are outdated,<br>and so is the <a href="http://clang.llvm.org/doxygen/">API</a>.<br></div></blockquote><div><br></div><div>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!</div><br><blockquote type="cite"><div dir="ltr">I've managed to run some tutorial which changes function names thru ASTConsumer implementation,<br>
which calls the Visit method of DeclVisitor class, and the manipultion is done in the VisitFunctionDecl method.<br>Basically I'm able retrieve pretty much all I need from the AST.<br><br>My problem is modifying the AST:<br>
1. Alter function signutures (type and params), <br>2. Adding a statement or a declaration to a block (both global and in function scope). <br>i.e. a function or variable declaration, a conditional statement.<br clear="all"></div></blockquote></div><br><div>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.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>- Doug</div></body></html>