From: Alp Toker Date: Tue, 20 May 2014 22:03:39 +0000 (+0000) Subject: RAV reunification: merge Lambda body visitation to DRAV X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=214f0494a4f156374a313af72f52596b2b7ddd1e;p=clang RAV reunification: merge Lambda body visitation to DRAV git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209246 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 2a3e9d9b26..43fa147eea 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -240,7 +240,15 @@ public: /// \brief Recursively visit a lambda capture. /// /// \returns false if the visitation was terminated early, true otherwise. - bool TraverseLambdaCapture(LambdaCapture C); + bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C); + + /// \brief Recursively visit the body of a lambda expression. + /// + /// This provides a hook for visitors that need more context when visiting + /// \c LE->getBody(). + /// + /// \returns false if the visitation was terminated early, true otherwise. + bool TraverseLambdaBody(LambdaExpr *LE); // ---- Methods on Attrs ---- @@ -777,7 +785,18 @@ bool RecursiveASTVisitor::TraverseConstructorInitializer( } template -bool RecursiveASTVisitor::TraverseLambdaCapture(LambdaCapture C) { +bool +RecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr *LE, + const LambdaCapture *C) { + if (C->isInitCapture()) + TRY_TO(TraverseDecl(C->getCapturedVar())); + return true; +} + +template +bool RecursiveASTVisitor::TraverseLambdaBody(LambdaExpr *LE) { + StmtQueueAction StmtQueue(*this); + StmtQueue.queue(LE->getBody()); return true; } @@ -2090,7 +2109,7 @@ bool RecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), CEnd = S->explicit_capture_end(); C != CEnd; ++C) { - TRY_TO(TraverseLambdaCapture(*C)); + TRY_TO(TraverseLambdaCapture(S, C)); } if (S->hasExplicitParameters() || S->hasExplicitResultType()) { @@ -2110,8 +2129,7 @@ bool RecursiveASTVisitor::TraverseLambdaExpr(LambdaExpr *S) { } } - StmtQueueAction StmtQueue(*this); - StmtQueue.queue(S->getBody()); + TRY_TO(TraverseLambdaBody(S)); return true; } diff --git a/tools/libclang/IndexBody.cpp b/tools/libclang/IndexBody.cpp index 1cb9e078f5..fbec3d7c01 100644 --- a/tools/libclang/IndexBody.cpp +++ b/tools/libclang/IndexBody.cpp @@ -149,13 +149,13 @@ public: return true; } - bool TraverseLambdaCapture(LambdaCapture C) { - if (C.capturesThis()) + bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C) { + if (C->capturesThis()) return true; - if (C.capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols()) - IndexCtx.handleReference(C.getCapturedVar(), C.getLocation(), - Parent, ParentDC); + if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols()) + IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(), Parent, + ParentDC); // FIXME: Lambda init-captures. return true;