hokein updated this revision to Diff 83944.
hokein marked an inline comment as done.
hokein added a comment.

Fix code style nit.


https://reviews.llvm.org/D27920

Files:
  include-fixer/find-all-symbols/FindAllSymbols.cpp
  unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp


Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===================================================================
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -229,6 +229,28 @@
   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 {
Index: include-fixer/find-all-symbols/FindAllSymbols.cpp
===================================================================
--- include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -32,6 +32,18 @@
   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 @@
   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 @@
 
   // 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.


Index: unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
===================================================================
--- unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
+++ unittests/include-fixer/find-all-symbols/FindAllSymbolsTests.cpp
@@ -229,6 +229,28 @@
   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 {
Index: include-fixer/find-all-symbols/FindAllSymbols.cpp
===================================================================
--- include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -32,6 +32,18 @@
   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 @@
   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 @@
 
   // 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.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to