]> granicus.if.org Git - clang/commitdiff
Devirtualize NamedDecl::getNameForDiagnostic().
authorDouglas Gregor <dgregor@apple.com>
Thu, 17 Feb 2011 17:23:19 +0000 (17:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 17 Feb 2011 17:23:19 +0000 (17:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125751 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
include/clang/AST/DeclTemplate.h
lib/AST/Decl.cpp
lib/AST/DeclTemplate.cpp

index 68d20510ea9fe4ab05164237030647ade7ace778..ba7699e1a68820418ddf1d5194a8553decd66f0b 100644 (file)
@@ -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);
   }
index b3277547e3d98bd913666a0817750149acd8eca8..28a40fbbb466b4c6a01370c0d0afc1746250ddec 100644 (file)
@@ -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>(CXXRecordDecl::getMostRecentDeclaration());
index 441444da9e55d1d31de555e797591fbd43ad2a21..0b07d13cba309509b3abefb6951368677c1f13b7 100644 (file)
@@ -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<FunctionDecl>(this))
+    TemplateArgs = FD->getTemplateSpecializationArgs();
+  else if (const ClassTemplateSpecializationDecl *Spec
+                              = dyn_cast<ClassTemplateSpecializationDecl>(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<FunctionProtoType>())
     return FT->isVariadic();
index 2005ff62f6446cca8f2baab36dce3a205085e99a..2aa446bcd31cba30ba6b9dba9682503052ba109e 100644 (file)
@@ -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