]> granicus.if.org Git - clang/commitdiff
Refactor find*Specialization functions using SpecEntryTraits
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 30 Jul 2010 17:09:04 +0000 (17:09 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 30 Jul 2010 17:09:04 +0000 (17:09 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109869 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 341c802f507d4cae00d853e8cd5cd1c2637ea660..0f255476759bf2983e15f163cfcd30f73118b896 100644 (file)
@@ -512,6 +512,11 @@ protected:
     }
   };
 
+  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) { }
 
index 25df086e73cfaa1f769c35c2b904f0286515cd69..e69338a7730d2daca59640cfe6b8325a11835050 100644 (file)
@@ -126,6 +126,19 @@ RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() {
   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 @@ RedeclarableTemplateDecl::CommonBase *FunctionTemplateDecl::newCommon() {
 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 @@ RedeclarableTemplateDecl::CommonBase *ClassTemplateDecl::newCommon() {
 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(