[PATCH] D68118: [clangd] Support OverloadExpr in findExplicitReferences

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 26 23:10:21 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68118

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


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -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 @@
     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 @@
         )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) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -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 @@
                          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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68118.222082.patch
Type: text/x-patch
Size: 2970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190927/3928fd59/attachment.bin>


More information about the cfe-commits mailing list