Getting access to two different AST's

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting access to two different AST's

Nat! via cfe-dev

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(newFrontendActionFactory<clang::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?

 

Thanks,

Rachel.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting access to two different AST's

Nat! via cfe-dev
On Mon, May 8, 2017 at 2:06 AM Rachel HaCohen (rahacohe) via cfe-dev <[hidden email]> wrote:

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(newFrontendActionFactory<clang::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?
 

 

Thanks,

Rachel.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev