[cfe-dev] RecursiveAstVisitor: How to find the open brace of the corresponding function declaration within a VisitCallExpr?

Marcel Schaible via cfe-dev cfe-dev at lists.llvm.org
Wed Aug 16 07:51:28 PDT 2017


Hi,

I want to retrieve in my RecursiveAstVisitor inside a VisitCallExpr 
method the open brace of the corresponding function declaration.

The code below does not find anything..

Any idea what I am doing wrong and is there a more elegant way to 
generate a variable declaration with a Rewriter?

Thanx

Marcel

bool VisitCallExpr(CallExpr *CallExpression) {
...
         if (CallExpression != NULL) {
             const auto& parents = TheContext->getParents(CallExpression);

             if (parents.empty()) {
                 llvm::errs() << "**** Can not find parent\n";
                 return false;
             }

             auto parent = parents[0].get<DeclStmt>();

             if (parent != NULL) {
                 llvm::errs() << "**** FOUND DECL STATEMENT ****\n";
                 SourceLocation l1 = parent->getLocStart();
                 TheRewriter.InsertText(l1, "/** found decl**/");
             }
             else
                 llvm::errs() << "**** DECL STATEMENT NOT FOUND ****\n";

...

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170816/a4dfcdf7/attachment.html>


More information about the cfe-dev mailing list