[cfe-commits] r125751 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclTemplate.h lib/AST/Decl.cpp lib/AST/DeclTemplate.cpp

Douglas Gregor dgregor at apple.com
Thu Feb 17 09:23:19 PST 2011


Author: dgregor
Date: Thu Feb 17 11:23:19 2011
New Revision: 125751

URL: http://llvm.org/viewvc/llvm-project?rev=125751&view=rev
Log:
Devirtualize NamedDecl::getNameForDiagnostic().

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/DeclTemplate.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=125751&r1=125750&r2=125751&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Feb 17 11:23:19 2011
@@ -158,14 +158,9 @@
   /// 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 @@
     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
   }
 
-  virtual void getNameForDiagnostic(std::string &S,
-                                    const PrintingPolicy &Policy,
-                                    bool Qualified) const;
-
   SourceRange getSourceRange() const {
     return SourceRange(getOuterLocStart(), EndRangeLoc);
   }

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=125751&r1=125750&r2=125751&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Feb 17 11:23:19 2011
@@ -1318,10 +1318,6 @@
   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());

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=125751&r1=125750&r2=125751&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Feb 17 11:23:19 2011
@@ -601,6 +601,30 @@
   }
 }
 
+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 @@
 // 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();

Modified: cfe/trunk/lib/AST/DeclTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=125751&r1=125750&r2=125751&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Thu Feb 17 11:23:19 2011
@@ -551,19 +551,6 @@
     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





More information about the cfe-commits mailing list