[clang-tools-extra] r291669 - [find-all-symbols] Index partial template specializations.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 11 03:47:44 PST 2017
Author: hokein
Date: Wed Jan 11 05:47:44 2017
New Revision: 291669
URL: http://llvm.org/viewvc/llvm-project?rev=291669&view=rev
Log:
[find-all-symbols] Index partial template specializations.
Summary:
Fix no std::function index.
Previously, we don't index all the template specialization declarations of functions and classes (Because we assume that template functions/classes are indexed by their template declarations), but this is not always true in some cases like `std::function` which only has a partial template specialization declaration.
Reviewers: ioeric, bkramer
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D27920
Modified:
clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp?rev=291669&r1=291668&r2=291669&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/FindAllSymbols.cpp Wed Jan 11 05:47:44 2017
@@ -32,6 +32,18 @@ AST_MATCHER(EnumConstantDecl, isInScoped
return false;
}
+AST_POLYMORPHIC_MATCHER(isFullySpecialized,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl,
+ CXXRecordDecl)) {
+ if (Node.getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
+ bool IsPartialSpecialization =
+ llvm::isa<VarTemplatePartialSpecializationDecl>(Node) ||
+ llvm::isa<ClassTemplatePartialSpecializationDecl>(Node);
+ return !IsPartialSpecialization;
+ }
+ return false;
+}
+
std::vector<SymbolInfo::Context> GetContexts(const NamedDecl *ND) {
std::vector<SymbolInfo::Context> Contexts;
for (const auto *Context = ND->getDeclContext(); Context;
@@ -126,8 +138,7 @@ void FindAllSymbols::registerMatchers(Ma
auto CCMatcher =
allOf(HasNSOrTUCtxMatcher, unless(IsInSpecialization),
unless(ast_matchers::isTemplateInstantiation()),
- unless(isInstantiated()), unless(classTemplateSpecializationDecl()),
- unless(isExplicitTemplateSpecialization()));
+ unless(isInstantiated()), unless(isFullySpecialized()));
// Matchers specific to code in extern "C" {...}.
auto ExternCMatcher = hasDeclContext(linkageSpecDecl());
@@ -156,8 +167,7 @@ void FindAllSymbols::registerMatchers(Ma
// Matchers for C++ record declarations.
auto CxxRecordDecl =
- cxxRecordDecl(CommonFilter, CCMatcher, isDefinition(),
- unless(isExplicitTemplateSpecialization()));
+ cxxRecordDecl(CommonFilter, CCMatcher, isDefinition());
MatchFinder->addMatcher(CxxRecordDecl.bind("decl"), this);
// Matchers for function declarations.
Modified: clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp?rev=291669&r1=291668&r2=291669&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp Wed Jan 11 05:47:44 2017
@@ -229,6 +229,28 @@ TEST_F(FindAllSymbolsTest, CXXRecordSymb
EXPECT_TRUE(hasSymbol(Symbol));
}
+TEST_F(FindAllSymbolsTest, DontIgnoreTemplatePartialSpecialization) {
+ static const char Code[] = R"(
+ template<class> class Class; // undefined
+ template<class R, class... ArgTypes>
+ class Class<R(ArgTypes...)> {
+ };
+
+ template<class T> void f() {};
+ template<> void f<int>() {};
+ )";
+ runFindAllSymbols(Code);
+ SymbolInfo Symbol =
+ SymbolInfo("Class", SymbolInfo::SymbolKind::Class, HeaderName, 4, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+ Symbol =
+ SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, 7, {});
+ EXPECT_TRUE(hasSymbol(Symbol));
+ Symbol =
+ SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, 8, {});
+ EXPECT_FALSE(hasSymbol(Symbol));
+}
+
TEST_F(FindAllSymbolsTest, FunctionSymbols) {
static const char Code[] = R"(
namespace na {
More information about the cfe-commits
mailing list