<div dir="ltr">Hi Farzad, <div><br></div><div>If all you are looking for is finding a functionDecl wrapping a callExpr, then following is what you want. </div><div><br></div>const clang::FunctionDecl* getParentFunctionDecl(ASTContext *context,const clang::Stmt& stmt){<br>        auto it = context->getParents(stmt).begin();<br>        if(it == context->getParents(stmt).end())<br>             return nullptr;<br><br>        const clang::FunctionDecl *fDecl = it->get<clang::FunctionDecl>();<br><br>        if(fDecl)<br>              return fDecl;<br><br>        const clang::Stmt *aStmt = it->get<clang::Stmt>();<br><br>        if(aStmt)<br>             return getParentFunctionDecl(context,*aStmt);<br><br>       //nothing worked<br>       return nullptr;<br>}<div class="gmail_extra"><br clear="all"><div><div data-smartmail="gmail_signature">--<div>Himanshu</div></div></div>
<br><div class="gmail_quote">On Wed, Jul 13, 2016 at 6:34 AM, Farzad Sadeghi via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
I need to travel through all the ancestors or descendants of a matched<br>
AST node to later use that info to moodify parts of the input source<br>
code. I tried to look for ways to do that. I looked at the getParents<br>
member function of the ASTContext class. I could use that to just go<br>
up the AST hierarchy to visit all the ancestor nodes of my<br>
currently-matched node. but the problem with that is, when i get the<br>
parent node, i no longer have the context for that node to try and get<br>
its parent. I could try to rebuild the ASTContext for the new node but<br>
that seems to be another big task on its own, if possible. the lowest<br>
NodeKind (lowest in the C hierarchy) I'm looking for is a callExpr and<br>
the highest I'm looking for is a functionDecl. How can I obtain all<br>
the ancestors or descendants of a matched AST node after the match<br>
returns the control to run in MatchCallback?<br>
<span><font color="#888888"><br>
<br>
--<br>
Farzad Sadeghi<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</font></span></blockquote></div><br></div></div>