From ebe5a9bcc51bff434f38d94748b08e9160609ed9 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 17 Feb 2011 17:23:19 +0000 Subject: [PATCH] Devirtualize NamedDecl::getNameForDiagnostic(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125751 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 15 +++---------- include/clang/AST/DeclTemplate.h | 4 ---- lib/AST/Decl.cpp | 37 +++++++++++++++++++++----------- lib/AST/DeclTemplate.cpp | 13 ----------- 4 files changed, 27 insertions(+), 42 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 68d20510ea..ba7699e1a6 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -158,14 +158,9 @@ public: /// specializations are printed with their template arguments. /// /// TODO: use an API that doesn't require so many temporary strings - virtual void getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const { - if (Qualified) - S += getQualifiedNameAsString(Policy); - else - S += getNameAsString(); - } + void getNameForDiagnostic(std::string &S, + const PrintingPolicy &Policy, + bool Qualified) const; /// declarationReplaces - Determine whether this declaration, if /// known to be well-formed within its context, will replace the @@ -1349,10 +1344,6 @@ public: return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); } - virtual void getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const; - SourceRange getSourceRange() const { return SourceRange(getOuterLocStart(), EndRangeLoc); } diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index b3277547e3..28a40fbbb4 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -1318,10 +1318,6 @@ public: static ClassTemplateSpecializationDecl * Create(ASTContext &Context, EmptyShell Empty); - virtual void getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const; - ClassTemplateSpecializationDecl *getMostRecentDeclaration() { CXXRecordDecl *Recent = cast(CXXRecordDecl::getMostRecentDeclaration()); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 441444da9e..0b07d13cba 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -601,6 +601,30 @@ static void clearLinkageForClass(const CXXRecordDecl *record) { } } +void NamedDecl::getNameForDiagnostic(std::string &S, + const PrintingPolicy &Policy, + bool Qualified) const { + if (Qualified) + S += getQualifiedNameAsString(Policy); + else + S += getNameAsString(); + + const TemplateArgumentList *TemplateArgs = 0; + + if (const FunctionDecl *FD = dyn_cast(this)) + TemplateArgs = FD->getTemplateSpecializationArgs(); + else if (const ClassTemplateSpecializationDecl *Spec + = dyn_cast(this)) + TemplateArgs = &Spec->getTemplateArgs(); + + + if (TemplateArgs) + S += TemplateSpecializationType::PrintTemplateArgumentList( + TemplateArgs->data(), + TemplateArgs->size(), + Policy); +} + void NamedDecl::ClearLinkageCache() { // Note that we can't skip clearing the linkage of children just // because the parent doesn't have cached linkage: we don't cache @@ -1283,19 +1307,6 @@ bool ParmVarDecl::isParameterPack() const { // FunctionDecl Implementation //===----------------------------------------------------------------------===// -void FunctionDecl::getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const { - NamedDecl::getNameForDiagnostic(S, Policy, Qualified); - const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs(); - if (TemplateArgs) - S += TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs->data(), - TemplateArgs->size(), - Policy); - -} - bool FunctionDecl::isVariadic() const { if (const FunctionProtoType *FT = getType()->getAs()) return FT->isVariadic(); diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 2005ff62f6..2aa446bcd3 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -551,19 +551,6 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) { new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization); } -void -ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, - const PrintingPolicy &Policy, - bool Qualified) const { - NamedDecl::getNameForDiagnostic(S, Policy, Qualified); - - const TemplateArgumentList &TemplateArgs = getTemplateArgs(); - S += TemplateSpecializationType::PrintTemplateArgumentList( - TemplateArgs.data(), - TemplateArgs.size(), - Policy); -} - ClassTemplateDecl * ClassTemplateSpecializationDecl::getSpecializedTemplate() const { if (SpecializedPartialSpecialization *PartialSpec -- 2.50.1