Calling a function call in c code using Clang

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

x = A() + B();

should be changed to:

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

      

I am writing it using Clang and RecursiveASTVisitor. Here is my solution. First, I have to search for all functions and declare a variable for each one in the first of my main block, which contains all the calls. Then look for binary operations that have a function call on both sides. Then, extract the function calls and use variables instead. Since I'm new to this, I don't know if there is a better way to do this or does this solution work at all?

+3


source to share





All Articles