Function call extraction in a c code using Clang

369 views Asked by At

I want to write a program which decomposes expressions (in a C code) in which they have function calls and extract each function call to variable. For example:

x = A() + B();

should be changed to :

a = A();
b = B();
x = a + b;

I'm writing it using Clang and RecursiveASTVisitor. Here is my solution. At first I have to look for all the functions and declare a variable for each of them at the first of my main block which all the calls are in. Then Look for Binary Operations which has function call in either sides. Then extract function calls and use variables for instead of them. As I'm a newbie to this I don't know if there is a better of doing this or is this solution works at all?

0

There are 0 answers