r204090 - Factor out repeated code in dumping template declarations.

Richard Smith richard-llvm at metafoo.co.uk
Mon Mar 17 16:34:53 PDT 2014


Author: rsmith
Date: Mon Mar 17 18:34:53 2014
New Revision: 204090

URL: http://llvm.org/viewvc/llvm-project?rev=204090&view=rev
Log:
Factor out repeated code in dumping template declarations.

Modified:
    cfe/trunk/lib/AST/ASTDumper.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=204090&r1=204089&r2=204090&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Mar 17 18:34:53 2014
@@ -254,6 +254,8 @@ namespace  {
     void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
     void VisitCXXRecordDecl(const CXXRecordDecl *D);
     void VisitStaticAssertDecl(const StaticAssertDecl *D);
+    template<typename TemplateDecl>
+    void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
     void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
     void VisitClassTemplateDecl(const ClassTemplateDecl *D);
     void VisitClassTemplateSpecializationDecl(
@@ -1073,7 +1075,9 @@ void ASTDumper::VisitStaticAssertDecl(co
   dumpStmt(D->getMessage());
 }
 
-void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
+template<typename TemplateDecl>
+void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
+                                  bool DumpExplicitInst) {
   dumpName(D);
   dumpTemplateParameters(D->getTemplateParameters());
 
@@ -1084,9 +1088,12 @@ void ASTDumper::VisitFunctionTemplateDec
     switch (Child->getTemplateSpecializationKind()) {
     case TSK_Undeclared:
     case TSK_ImplicitInstantiation:
+      Children.dump(Child, /*Ref*/D != D->getCanonicalDecl());
+      break;
     case TSK_ExplicitInstantiationDeclaration:
     case TSK_ExplicitInstantiationDefinition:
-      Children.dump(Child, /*Ref*/D != D->getCanonicalDecl());
+      Children.dump(Child, /*Ref*/D != D->getCanonicalDecl() ||
+                                  !DumpExplicitInst);
       break;
     case TSK_ExplicitSpecialization:
       Children.dumpRef(Child);
@@ -1095,26 +1102,15 @@ void ASTDumper::VisitFunctionTemplateDec
   }
 }
 
-void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
-  dumpName(D);
-  dumpTemplateParameters(D->getTemplateParameters());
-
-  ChildDumper Children(*this);
-  Children.dump(D->getTemplatedDecl());
+void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
+  // FIXME: We don't add a declaration of a function template specialization
+  // to its context when it's explicitly instantiated, so dump explicit
+  // instantiations when we dump the template itself.
+  VisitTemplateDecl(D, true);
+}
 
-  for (auto *Child : D->specializations()) {
-    switch (Child->getTemplateSpecializationKind()) {
-    case TSK_Undeclared:
-    case TSK_ImplicitInstantiation:
-      Children.dump(Child, D != D->getCanonicalDecl());
-      break;
-    case TSK_ExplicitSpecialization:
-    case TSK_ExplicitInstantiationDeclaration:
-    case TSK_ExplicitInstantiationDefinition:
-      Children.dumpRef(Child);
-      break;
-    }
-  }
+void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
+  VisitTemplateDecl(D, false);
 }
 
 void ASTDumper::VisitClassTemplateSpecializationDecl(
@@ -1137,25 +1133,7 @@ void ASTDumper::VisitClassScopeFunctionS
 }
 
 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
-  dumpName(D);
-  dumpTemplateParameters(D->getTemplateParameters());
-
-  ChildDumper Children(*this);
-  Children.dump(D->getTemplatedDecl());
-
-  for (auto *Child : D->specializations()) {
-    switch (Child->getTemplateSpecializationKind()) {
-    case TSK_Undeclared:
-    case TSK_ImplicitInstantiation:
-      Children.dump(Child, D != D->getCanonicalDecl());
-      break;
-    case TSK_ExplicitSpecialization:
-    case TSK_ExplicitInstantiationDeclaration:
-    case TSK_ExplicitInstantiationDefinition:
-      Children.dumpRef(Child);
-      break;
-    }
-  }
+  VisitTemplateDecl(D, false);
 }
 
 void ASTDumper::VisitVarTemplateSpecializationDecl(





More information about the cfe-commits mailing list