[cfe-dev] Help needed regarding modifying AST
Eli Friedman
eli.friedman at gmail.com
Mon Feb 2 13:10:38 PST 2009
On Sun, Feb 1, 2009 at 7:25 AM, sachin khot <sachinkhot.com at gmail.com> wrote:
> Hi,
> I am Sachin and I am trying to perform code refactoring on C code using
> Clang. I am planning to do so by modifying the clang AST and then converting
> it back to C code. (I tried to debug Clang and found that the AST is built
> by the ParseAST() function call in ParseAST.cpp)
If you're looking at code refactoring, you probably want to look at
the rewriters; there isn't anything that's doing quite what you're
trying, but RewriteBlocks.cpp might be a good place to start looking.
> Can somebody tell me which Clang APIs should I use to add nodes to current
> AST?
The API you need depends on what exactly you're trying to do... to
replace a node in the AST, you can generally use the
child_begin()/child_end() API to get a modifiable iterator. For
inserting nodes, it depends on the exact type of the node; I'd suggest
looking in Expr.h and Stmt.h. The preferred way to create a node is a
bit in flux; I'd suggest looking at SemaExpr.cpp for some examples of
how to do it.
-Eli
More information about the cfe-dev
mailing list