From 0bfddd62a83004ab742f26877c3af1c8b31c5f88 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 17 Mar 2014 23:34:53 +0000 Subject: [PATCH] Factor out repeated code in dumping template declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204090 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTDumper.cpp | 58 ++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 1f11f83906..67a4eaabdf 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -254,6 +254,8 @@ namespace { void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D); void VisitCXXRecordDecl(const CXXRecordDecl *D); void VisitStaticAssertDecl(const StaticAssertDecl *D); + template + 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(const StaticAssertDecl *D) { dumpStmt(D->getMessage()); } -void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { +template +void ASTDumper::VisitTemplateDecl(const TemplateDecl *D, + bool DumpExplicitInst) { dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); @@ -1084,9 +1088,12 @@ void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { 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::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { } } -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::VisitClassScopeFunctionSpecializationDecl( } 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( -- 2.40.0