[clang-tools-extra] r373057 - [clangd] Support OverloadExpr in findExplicitReferences

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 02:39:10 PDT 2019


Author: ibiryukov
Date: Fri Sep 27 02:39:10 2019
New Revision: 373057

URL: http://llvm.org/viewvc/llvm-project?rev=373057&view=rev
Log:
[clangd] Support OverloadExpr in findExplicitReferences

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68118

Modified:
    clang-tools-extra/trunk/clangd/FindTarget.cpp
    clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp

Modified: clang-tools-extra/trunk/clangd/FindTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindTarget.cpp?rev=373057&r1=373056&r2=373057&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/FindTarget.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindTarget.cpp Fri Sep 27 02:39:10 2019
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/PrettyPrinter.h"
@@ -449,6 +450,12 @@ Optional<ReferenceLoc> refInExpr(const E
                          E->getMemberNameInfo().getLoc(),
                          {E->getFoundDecl()}};
     }
+
+    void VisitOverloadExpr(const OverloadExpr *E) {
+      Ref = ReferenceLoc{E->getQualifierLoc(), E->getNameInfo().getLoc(),
+                         llvm::SmallVector<const NamedDecl *, 1>(
+                             E->decls().begin(), E->decls().end())};
+    }
   };
 
   Visitor V;

Modified: clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp?rev=373057&r1=373056&r2=373057&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/FindTargetTests.cpp Fri Sep 27 02:39:10 2019
@@ -10,8 +10,10 @@
 #include "Selection.h"
 #include "TestTU.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
@@ -482,7 +484,11 @@ protected:
     TU.Code = Code;
 
     auto AST = TU.build();
-    auto &Func = llvm::cast<FunctionDecl>(findDecl(AST, "foo"));
+
+    auto *TestDecl = &findDecl(AST, "foo");
+    if (auto *T = llvm::dyn_cast<FunctionTemplateDecl>(TestDecl))
+      TestDecl = T->getTemplatedDecl();
+    auto &Func = llvm::cast<FunctionDecl>(*TestDecl);
 
     std::vector<ReferenceLoc> Refs;
     findExplicitReferences(Func.getBody(), [&Refs](ReferenceLoc R) {
@@ -671,6 +677,35 @@ TEST_F(FindExplicitReferencesTest, All)
         )cpp",
            "0: targets = {vector}\n"
            "1: targets = {x}\n"},
+          // Handle UnresolvedLookupExpr.
+          {R"cpp(
+            namespace ns1 { void func(char*); }
+            namespace ns2 { void func(int*); }
+            using namespace ns1;
+            using namespace ns2;
+
+            template <class T>
+            void foo(T t) {
+              $0^func($1^t);
+            }
+        )cpp",
+           "0: targets = {ns1::func, ns2::func}\n"
+           "1: targets = {t}\n"},
+          // Handle UnresolvedMemberExpr.
+          {R"cpp(
+            struct X {
+              void func(char*);
+              void func(int*);
+            };
+
+            template <class T>
+            void foo(X x, T t) {
+              $0^x.$1^func($2^t);
+            }
+        )cpp",
+           "0: targets = {x}\n"
+           "1: targets = {X::func, X::func}\n"
+           "2: targets = {t}\n"},
       };
 
   for (const auto &C : Cases) {




More information about the cfe-commits mailing list