Getting access to two different AST's

Hi all,

I’m new to clang and having a little trouble. Would be happy to get some help.

I’m trying to build a tool that (among other things) combines two code parts: The first one is a c file that is given by the user and the second is a fixed c function.

I want to have access to the AST nodes of both code parts, extract the relevant stmts from each, and build from them a new compoundStmt node (initiated with a vector<Stmt*>), which will be transformed back to c code.

I’m having trouble with getting access to both AST’s simultaneously.

I tried to access the input code with libTooling by running the following command from main:

Hi all,

I’m new to clang and having a little trouble. Would be happy to get some help.

I’m trying to build a tool that (among other things) combines two code parts: The first one is a c file that is given by the user and the second is a fixed c function.

I want to have access to the AST nodes of both code parts, extract the relevant stmts from each, and build from them a new compoundStmt node (initiated with a vector<Stmt*>), which will be transformed back to c code.

I’m having trouble with getting access to both AST’s simultaneously.

I tried to access the input code with libTooling by running the following command from main:

Tool.run(newFrontendActionFactoryclang::MyAction().get());

And access to the fixed code using runToolOnCode and then pass the compoundStmt pointer of the function body to the main:

clang::tooling::runToolOnCode(new MyOtherAction, MyFixedText);

but it seems like both tools are running independently with no ability to pass information from one to the other.

Can anyone give me a hint on this or give me a link to a code that does something similar?

Can you read the file from disk, attach your function at the end (textually), and parse the result with runToolOnCode?