diff options
author | Haojian Wu <hokein@google.com> | 2018-12-18 15:29:12 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2018-12-18 15:29:12 +0000 |
commit | ef87c2679653e34ddc0c37c48048cd306202ee4a (patch) | |
tree | 815c6ce80fa074affe93767f01f3f51f9fbaabf7 | |
parent | cfa54fb456e065043acb01f883029ff68465b275 (diff) | |
download | bcm5719-llvm-ef87c2679653e34ddc0c37c48048cd306202ee4a.tar.gz bcm5719-llvm-ef87c2679653e34ddc0c37c48048cd306202ee4a.zip |
[AST] Unify the code paths of traversing lambda expressions.
Summary:
This supposes to be a non-functional change. We have two code paths when
traversing lambda expressions:
1) traverse the function proto typeloc when parameters and return type
are explicit;
2) otherwise fallback to traverse parameter decls and return type loc
individually;
This patch unifies the code path to always traverse parameters and
return type, rather than relying on traversing the full type-loc.
Reviewers: ilya-biryukov
Subscribers: arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D55820
llvm-svn: 349494
-rw-r--r-- | clang/include/clang/AST/RecursiveASTVisitor.h | 31 | ||||
-rw-r--r-- | clang/test/Index/cxx11-lambdas.cpp | 2 | ||||
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 28 |
3 files changed, 24 insertions, 37 deletions
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index eb582c7a7ae..0d88517010c 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2414,27 +2414,20 @@ DEF_TRAVERSE_STMT(LambdaExpr, { TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>(); - if (S->hasExplicitParameters() && S->hasExplicitResultType()) { - // Visit the whole type. - TRY_TO(TraverseTypeLoc(TL)); - } else { - if (S->hasExplicitParameters()) { - // Visit parameters. - for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) { - TRY_TO(TraverseDecl(Proto.getParam(I))); - } - } else if (S->hasExplicitResultType()) { - TRY_TO(TraverseTypeLoc(Proto.getReturnLoc())); - } + if (S->hasExplicitParameters()) { + // Visit parameters. + for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) + TRY_TO(TraverseDecl(Proto.getParam(I))); + } + if (S->hasExplicitResultType()) + TRY_TO(TraverseTypeLoc(Proto.getReturnLoc())); - auto *T = Proto.getTypePtr(); - for (const auto &E : T->exceptions()) { - TRY_TO(TraverseType(E)); - } + auto *T = Proto.getTypePtr(); + for (const auto &E : T->exceptions()) + TRY_TO(TraverseType(E)); - if (Expr *NE = T->getNoexceptExpr()) - TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE); - } + if (Expr *NE = T->getNoexceptExpr()) + TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE); ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue); ShouldVisitChildren = false; diff --git a/clang/test/Index/cxx11-lambdas.cpp b/clang/test/Index/cxx11-lambdas.cpp index d0ee908059f..66df09ad294 100644 --- a/clang/test/Index/cxx11-lambdas.cpp +++ b/clang/test/Index/cxx11-lambdas.cpp @@ -14,9 +14,9 @@ struct X { // CHECK-LOAD: cxx11-lambdas.cpp:7:19: LambdaExpr= Extent=[7:19 - 9:6] // CHECK-LOAD: cxx11-lambdas.cpp:7:21: VariableRef=localA:6:9 Extent=[7:21 - 7:27] // CHECK-LOAD: cxx11-lambdas.cpp:7:29: VariableRef=localB:6:17 Extent=[7:29 - 7:35] -// CHECK-LOAD: cxx11-lambdas.cpp:7:52: TypeRef=Integer:3:13 Extent=[7:52 - 7:59] // CHECK-LOAD: cxx11-lambdas.cpp:7:46: ParmDecl=x:7:46 (Definition) Extent=[7:38 - 7:47] // CHECK-LOAD: cxx11-lambdas.cpp:7:38: TypeRef=Integer:3:13 Extent=[7:38 - 7:45] +// CHECK-LOAD: cxx11-lambdas.cpp:7:52: TypeRef=Integer:3:13 Extent=[7:52 - 7:59] // CHECK-LOAD: cxx11-lambdas.cpp:7:60: CompoundStmt= Extent=[7:60 - 9:6] // CHECK-LOAD: cxx11-lambdas.cpp:8:7: ReturnStmt= Extent=[8:7 - 8:33] // CHECK-LOAD: cxx11-lambdas.cpp:8:14: DeclRefExpr=localA:6:9 Extent=[8:14 - 8:20] diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index ca8b4baf6c7..bc791954fc7 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -3135,25 +3135,19 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) { return true; } + TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); // Visit parameters and return type, if present. - if (E->hasExplicitParameters() || E->hasExplicitResultType()) { - TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); - if (E->hasExplicitParameters() && E->hasExplicitResultType()) { - // Visit the whole type. - if (Visit(TL)) - return true; - } else if (FunctionProtoTypeLoc Proto = - TL.getAs<FunctionProtoTypeLoc>()) { - if (E->hasExplicitParameters()) { - // Visit parameters. - for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) - if (Visit(MakeCXCursor(Proto.getParam(I), TU))) - return true; - } else { - // Visit result type. - if (Visit(Proto.getReturnLoc())) + if (FunctionTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) { + if (E->hasExplicitParameters()) { + // Visit parameters. + for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) + if (Visit(MakeCXCursor(Proto.getParam(I), TU))) return true; - } + } + if (E->hasExplicitResultType()) { + // Visit result type. + if (Visit(Proto.getReturnLoc())) + return true; } } break; |