<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 15, 2015 at 12:51 PM, Deepak Rajendrakumaran <span dir="ltr"><<a href="mailto:deepak3@vt.edu" target="_blank">deepak3@vt.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div>I am new to Clang and so I am having some problem figuring out how to create AST for a program with multiple files .<div><br></div><div><br></div><div>What I am trying to do:</div><div>- In an application containing multiple .cpp/.c and .h files, parse through all the files and identify all instances of a particular function</div><div>-Move the function definition to a new file with a changed name(changed function name)</div><div>-Find all instances where the particular function is called and change the function name to the new name</div><div><br></div><div>(I am ignoring the other dependencies like nested functions/headers etc so that I can focus on my actual question. So assume this works:))<br><div><br></div><div><div>I have been reading up on Clang/libtooling inorder to figure out a way to do the same. From what I understand, the steps to do this would be</div><div>- Compile and create ASTs for the entire source code(assuming it includes multiple .cpp and .h files)</div><div>-Somehow traverse these ASTs(RecursiveASTVisitor)  to figure out where all this the particular function I am interested in exists(ASTMatchers??)</div><div>-First write the function definition to a new file </div><div>-Now use the rewriter to write the original file without the function definition and replace all the places where a call to this function exists with its new name</div><div>(I have tried to simplify the problem statement so that I can pinpoint my issue better. I'll ofcourse have to manipulate the ASTs and the source code more to get a working program )</div></div></div><div><br></div><div>First of all, I need to have ASTs of all TUs and not just one AST. Is there any way in libtooling to obtain a single AST for multiple TUs? If not is there any standard practice for the same incase anyone has faced the same problem?</div><div><br></div></div></div></blockquote><div><br></div><div>I'm not sure that I understand.  Standard practice is to process one AST per TU.  I've not found it to be a problem, but maybe it is for you for some reason -- in which case it might help to say what that reason is.  There may well be solutions.</div><div><br></div><div>-- James</div></div></div></div>