Help needed regarding modifying AST

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)
Can somebody tell me which Clang APIs should I use to add nodes to current AST?

Thanks in advance,
Sachin

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