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

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 02:39:33 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL373057: [clangd] Support OverloadExpr in findExplicitReferences (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68118?vs=222082&id=222109#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68118

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


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


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


More information about the cfe-commits mailing list