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

Peter Collingbourne peter at pcc.me.uk
Fri Jul 30 10:09:04 PDT 2010


Author: pcc
Date: Fri Jul 30 12:09:04 2010
New Revision: 109869

URL: http://llvm.org/viewvc/llvm-project?rev=109869&view=rev
Log:
Refactor find*Specialization functions using SpecEntryTraits

This patch reimplements the find*Specialization family of member
functions of {Class,Function}TemplateDecl in terms of a common
implementation that uses SpecEntryTraits to obtain the most recent
declaration.

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

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=109869&r1=109868&r2=109869&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Fri Jul 30 12:09:04 2010
@@ -512,6 +512,11 @@
     }
   };
 
+  template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType*
+  findSpecializationImpl(llvm::FoldingSet<EntryType> &Specs,
+                         const TemplateArgument *Args, unsigned NumArgs,
+                         void *&InsertPos);
+
   struct CommonBase {
     CommonBase() : InstantiatedFromMember(0, false) { }
 

Modified: cfe/trunk/lib/AST/DeclTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=109869&r1=109868&r2=109869&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Fri Jul 30 12:09:04 2010
@@ -126,6 +126,19 @@
   return Common ? Common->Latest : this;
 }
 
+template <class EntryType>
+typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
+RedeclarableTemplateDecl::findSpecializationImpl(
+                                 llvm::FoldingSet<EntryType> &Specs,
+                                 const TemplateArgument *Args, unsigned NumArgs,
+                                 void *&InsertPos) {
+  typedef SpecEntryTraits<EntryType> SETraits;
+  llvm::FoldingSetNodeID ID;
+  EntryType::Profile(ID,Args,NumArgs, getASTContext());
+  EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
+  return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0;
+}
+
 //===----------------------------------------------------------------------===//
 // FunctionTemplateDecl Implementation
 //===----------------------------------------------------------------------===//
@@ -152,11 +165,7 @@
 FunctionDecl *
 FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args,
                                          unsigned NumArgs, void *&InsertPos) {
-  llvm::FoldingSetNodeID ID;
-  FunctionTemplateSpecializationInfo::Profile(ID,Args,NumArgs, getASTContext());
-  FunctionTemplateSpecializationInfo *Info
-      = getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
-  return Info ? Info->Function->getMostRecentDeclaration() : 0;
+  return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
 }
 
 //===----------------------------------------------------------------------===//
@@ -188,23 +197,15 @@
 ClassTemplateSpecializationDecl *
 ClassTemplateDecl::findSpecialization(const TemplateArgument *Args,
                                       unsigned NumArgs, void *&InsertPos) {
-  llvm::FoldingSetNodeID ID;
-  ClassTemplateSpecializationDecl::Profile(ID, Args, NumArgs, getASTContext());
-  ClassTemplateSpecializationDecl *D
-      = getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
-  return D ? D->getMostRecentDeclaration() : 0;
+  return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
 }
 
 ClassTemplatePartialSpecializationDecl *
 ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
                                              unsigned NumArgs,
                                              void *&InsertPos) {
-  llvm::FoldingSetNodeID ID;
-  ClassTemplatePartialSpecializationDecl::Profile(ID, Args, NumArgs,
-                                                  getASTContext());
-  ClassTemplatePartialSpecializationDecl *D
-      = getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
-  return D ? D->getMostRecentDeclaration() : 0;
+  return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
+                                InsertPos);
 }
 
 void ClassTemplateDecl::getPartialSpecializations(





More information about the cfe-commits mailing list