[PATCH] D55820: [AST] Unify the code paths of traversing lambda expressions.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 18 07:32:34 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC349494: [AST] Unify the code paths of traversing lambda expressions. (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55820?vs=178667&id=178674#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55820/new/

https://reviews.llvm.org/D55820

Files:
  include/clang/AST/RecursiveASTVisitor.h
  test/Index/cxx11-lambdas.cpp
  tools/libclang/CIndex.cpp


Index: include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -2414,27 +2414,20 @@
   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;
Index: test/Index/cxx11-lambdas.cpp
===================================================================
--- test/Index/cxx11-lambdas.cpp
+++ test/Index/cxx11-lambdas.cpp
@@ -14,9 +14,9 @@
 // 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]
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3135,25 +3135,19 @@
             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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55820.178674.patch
Type: text/x-patch
Size: 4295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181218/f493698a/attachment.bin>


More information about the cfe-commits mailing list