[PATCH] D85503: [clangd] Have template template arguments target their referenced template decl
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 10:27:58 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG70d583ad1287: [clangd] Have template template arguments target their referenced template decl (authored by nridge).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85503/new/
https://reviews.llvm.org/D85503
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -407,8 +407,16 @@
s2[[-^>]]f();
}
)cpp",
- "DeclRefExpr"} // DeclRefExpr to the "operator->" method.
- };
+ "DeclRefExpr"}, // DeclRefExpr to the "operator->" method.
+
+ // Template template argument.
+ {R"cpp(
+ template <typename> class Vector {};
+ template <template <typename> class Container> class A {};
+ A<[[V^ector]]> a;
+ )cpp",
+ "TemplateArgumentLoc"}};
+
for (const Case &C : Cases) {
trace::TestTracer Tracer;
Annotations Test(C.Code);
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -376,6 +376,15 @@
{"template<> class Foo<int *>", Rel::TemplateInstantiation},
{"template <typename T> class Foo<T *>", Rel::TemplatePattern});
+ Code = R"cpp(
+ // Template template argument.
+ template<typename T> struct Vector {};
+ template <template <typename> class Container>
+ struct A {};
+ A<[[Vector]]> a;
+ )cpp";
+ EXPECT_DECLS("TemplateArgumentLoc", {"template <typename T> struct Vector"});
+
Flags.push_back("-std=c++17"); // for CTAD tests
Code = R"cpp(
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -479,6 +479,10 @@
bool TraverseTypeLoc(TypeLoc X) {
return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
}
+ bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &X) {
+ return traverseNode(&X,
+ [&] { return Base::TraverseTemplateArgumentLoc(X); });
+ }
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
return traverseNode(
&X, [&] { return Base::TraverseNestedNameSpecifierLoc(X); });
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -596,6 +596,19 @@
add(CCI->getAnyMember(), Flags);
// Constructor calls contain a TypeLoc node, so we don't handle them here.
}
+
+ void add(const TemplateArgument &Arg, RelSet Flags) {
+ // Only used for template template arguments.
+ // For type and non-type template arguments, SelectionTree
+ // will hit a more specific node (e.g. a TypeLoc or a
+ // DeclRefExpr).
+ if (Arg.getKind() == TemplateArgument::Template ||
+ Arg.getKind() == TemplateArgument::TemplateExpansion) {
+ if (TemplateDecl *TD = Arg.getAsTemplate().getAsTemplateDecl()) {
+ report(TD, Flags);
+ }
+ }
+ }
};
} // namespace
@@ -619,6 +632,8 @@
Finder.add(*QT, Flags);
else if (const CXXCtorInitializer *CCI = N.get<CXXCtorInitializer>())
Finder.add(CCI, Flags);
+ else if (const TemplateArgumentLoc *TAL = N.get<TemplateArgumentLoc>())
+ Finder.add(TAL->getArgument(), Flags);
return Finder.takeDecls();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85503.284430.patch
Type: text/x-patch
Size: 3432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200810/0f7e0e8f/attachment.bin>
More information about the cfe-commits
mailing list