<div dir="ltr">Hello,<div><br></div><div>You can use the following code to walk through the parents of a stmt/expr:</div><div><br></div><div><div>const clang::Decl* get_DeclContext_from_Stmt(const clang::Stmt& stmt)</div><div>{</div><div> auto it = ASTContext->getParents(stmt).begin();</div><div><br></div><div> if(it == ASTContext->getParents(stmt).end())</div><div> return nullptr;</div><div><br></div><div> const clang::Decl *aDecl = it->get<clang::Decl>();</div><div> if(aDecl)</div><div> return aDecl;</div><div><br></div><div> const clang::Stmt *aStmt = it->get<clang::Stmt>();</div><div> if(aStmt)</div><div> return get_DeclContext_from_Stmt(*aStmt);</div><div><br></div><div> return nullptr;</div><div>}</div></div><div><br></div><div>It tries to find a declaration, but you can change it to find any stmt/expr.</div><div><br></div><div>Best regards,</div><div><br></div><div class="gmail_extra">-- <br><div class="gmail_signature"><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div>
</div></div>