From b498ed6e0b06d41de2d53fb988d3897a52111d78 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 30 Jul 2010 17:09:04 +0000 Subject: [PATCH] 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. llvm-svn: 109869 --- clang/include/clang/AST/DeclTemplate.h | 5 ++++ clang/lib/AST/DeclTemplate.cpp | 33 +++++++++++++------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 341c802f507d..0f255476759b 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -512,6 +512,11 @@ protected: } }; + template typename SpecEntryTraits::DeclType* + findSpecializationImpl(llvm::FoldingSet &Specs, + const TemplateArgument *Args, unsigned NumArgs, + void *&InsertPos); + struct CommonBase { CommonBase() : InstantiatedFromMember(0, false) { } diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 25df086e73cf..e69338a7730d 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -126,6 +126,19 @@ RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() { return Common ? Common->Latest : this; } +template +typename RedeclarableTemplateDecl::SpecEntryTraits::DeclType* +RedeclarableTemplateDecl::findSpecializationImpl( + llvm::FoldingSet &Specs, + const TemplateArgument *Args, unsigned NumArgs, + void *&InsertPos) { + typedef SpecEntryTraits 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(