diff options
| author | Haojian Wu <hokein@google.com> | 2017-01-11 11:47:44 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2017-01-11 11:47:44 +0000 |
| commit | ffdd0728584319ad800803a3f3328838d832bdfa (patch) | |
| tree | f20f94a7d0a08d82590ebf6fc098e1609ca63354 | |
| parent | 9772eb3907a423a0a156194fac9ca37e44777246 (diff) | |
| download | bcm5719-llvm-ffdd0728584319ad800803a3f3328838d832bdfa.tar.gz bcm5719-llvm-ffdd0728584319ad800803a3f3328838d832bdfa.zip | |
[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
llvm-svn: 291669
| -rw-r--r-- | clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp | 18 | ||||
| -rw-r--r-- | clang-tools-extra/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp | 22 |
2 files changed, 36 insertions, 4 deletions
diff --git a/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp b/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp index d37918fef55..96bf992c9a5 100644 --- a/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp +++ b/clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbols.cpp @@ -32,6 +32,18 @@ AST_MATCHER(EnumConstantDecl, isInScopedEnum) { 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(MatchFinder *MatchFinder) { 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(MatchFinder *MatchFinder) { // 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. diff --git a/clang-tools-extra/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp b/clang-tools-extra/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp index baa5dca463f..852fe148de1 100644 --- a/clang-tools-extra/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp +++ b/clang-tools-extra/unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp @@ -229,6 +229,28 @@ TEST_F(FindAllSymbolsTest, CXXRecordSymbolsTemplate) { 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 { |

