From 36c49e3f258dced101949edabd72e9bc3f1dedc4 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 17 Sep 2010 15:54:40 +0000 Subject: Vendor import of clang r114020 (from the release_28 branch): http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020 Approved by: rpaulo (mentor) --- lib/AST/DeclTemplate.cpp | 174 +++++++++++++++++++++++++++-------------------- 1 file changed, 99 insertions(+), 75 deletions(-) (limited to 'lib/AST/DeclTemplate.cpp') diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 9e1d79d..e69338a 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -84,10 +84,59 @@ unsigned TemplateParameterList::getDepth() const { } //===----------------------------------------------------------------------===// -// TemplateDecl Implementation +// RedeclarableTemplateDecl Implementation //===----------------------------------------------------------------------===// -TemplateDecl::~TemplateDecl() { +RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() { + // Find the first declaration of this function template. + RedeclarableTemplateDecl *First = getCanonicalDecl(); + + if (First->CommonOrPrev.isNull()) { + CommonBase *CommonPtr = First->newCommon(); + First->CommonOrPrev = CommonPtr; + CommonPtr->Latest = First; + } + return First->CommonOrPrev.get(); +} + + +RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() { + RedeclarableTemplateDecl *Tmpl = this; + while (Tmpl->getPreviousDeclaration()) + Tmpl = Tmpl->getPreviousDeclaration(); + return Tmpl; +} + +void RedeclarableTemplateDecl::setPreviousDeclarationImpl( + RedeclarableTemplateDecl *Prev) { + if (Prev) { + CommonBase *Common = Prev->getCommonPtr(); + Prev = Common->Latest; + Common->Latest = this; + CommonOrPrev = Prev; + } else { + assert(CommonOrPrev.is() && "Cannot reset TemplateDecl Prev"); + } +} + +RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() { + if (CommonOrPrev.is()) + return CommonOrPrev.get(); + CommonBase *Common = CommonOrPrev.get(); + 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; } //===----------------------------------------------------------------------===// @@ -107,37 +156,16 @@ FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl); } -void FunctionTemplateDecl::Destroy(ASTContext &C) { - if (Common *CommonPtr = CommonOrPrev.dyn_cast()) { - for (llvm::FoldingSet::iterator - Spec = CommonPtr->Specializations.begin(), - SpecEnd = CommonPtr->Specializations.end(); - Spec != SpecEnd; ++Spec) - C.Deallocate(&*Spec); - } - - Decl::Destroy(C); +RedeclarableTemplateDecl::CommonBase *FunctionTemplateDecl::newCommon() { + Common *CommonPtr = new (getASTContext()) Common; + getASTContext().AddDeallocation(DeallocateCommon, CommonPtr); + return CommonPtr; } -FunctionTemplateDecl *FunctionTemplateDecl::getCanonicalDecl() { - FunctionTemplateDecl *FunTmpl = this; - while (FunTmpl->getPreviousDeclaration()) - FunTmpl = FunTmpl->getPreviousDeclaration(); - return FunTmpl; -} - -FunctionTemplateDecl::Common *FunctionTemplateDecl::getCommonPtr() { - // Find the first declaration of this function template. - FunctionTemplateDecl *First = this; - while (First->getPreviousDeclaration()) - First = First->getPreviousDeclaration(); - - if (First->CommonOrPrev.isNull()) { - Common *CommonPtr = new (getASTContext()) Common; - getASTContext().AddDeallocation(DeallocateCommon, CommonPtr); - First->CommonOrPrev = CommonPtr; - } - return First->CommonOrPrev.get(); +FunctionDecl * +FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args, + unsigned NumArgs, void *&InsertPos) { + return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); } //===----------------------------------------------------------------------===// @@ -148,13 +176,6 @@ void ClassTemplateDecl::DeallocateCommon(void *Ptr) { static_cast(Ptr)->~Common(); } -ClassTemplateDecl *ClassTemplateDecl::getCanonicalDecl() { - ClassTemplateDecl *Template = this; - while (Template->getPreviousDeclaration()) - Template = Template->getPreviousDeclaration(); - return Template; -} - ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, @@ -167,8 +188,24 @@ ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, return New; } -void ClassTemplateDecl::Destroy(ASTContext& C) { - Decl::Destroy(C); +RedeclarableTemplateDecl::CommonBase *ClassTemplateDecl::newCommon() { + Common *CommonPtr = new (getASTContext()) Common; + getASTContext().AddDeallocation(DeallocateCommon, CommonPtr); + return CommonPtr; +} + +ClassTemplateSpecializationDecl * +ClassTemplateDecl::findSpecialization(const TemplateArgument *Args, + unsigned NumArgs, void *&InsertPos) { + return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos); +} + +ClassTemplatePartialSpecializationDecl * +ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args, + unsigned NumArgs, + void *&InsertPos) { + return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs, + InsertPos); } void ClassTemplateDecl::getPartialSpecializations( @@ -181,7 +218,7 @@ void ClassTemplateDecl::getPartialSpecializations( P = PartialSpecs.begin(), PEnd = PartialSpecs.end(); P != PEnd; ++P) { assert(!PS[P->getSequenceNumber()]); - PS[P->getSequenceNumber()] = &*P; + PS[P->getSequenceNumber()] = P->getMostRecentDeclaration(); } } @@ -194,7 +231,22 @@ ClassTemplateDecl::findPartialSpecialization(QualType T) { PEnd = getPartialSpecializations().end(); P != PEnd; ++P) { if (Context.hasSameType(P->getInjectedSpecializationType(), T)) - return &*P; + return P->getMostRecentDeclaration(); + } + + return 0; +} + +ClassTemplatePartialSpecializationDecl * +ClassTemplateDecl::findPartialSpecInstantiatedFromMember( + ClassTemplatePartialSpecializationDecl *D) { + Decl *DCanon = D->getCanonicalDecl(); + for (llvm::FoldingSet::iterator + P = getPartialSpecializations().begin(), + PEnd = getPartialSpecializations().end(); + P != PEnd; ++P) { + if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) + return P->getMostRecentDeclaration(); } return 0; @@ -239,20 +291,6 @@ ClassTemplateDecl::getInjectedClassNameSpecialization() { return CommonPtr->InjectedClassNameType; } -ClassTemplateDecl::Common *ClassTemplateDecl::getCommonPtr() { - // Find the first declaration of this function template. - ClassTemplateDecl *First = this; - while (First->getPreviousDeclaration()) - First = First->getPreviousDeclaration(); - - if (First->CommonOrPrev.isNull()) { - Common *CommonPtr = new (getASTContext()) Common; - getASTContext().AddDeallocation(DeallocateCommon, CommonPtr); - First->CommonOrPrev = CommonPtr; - } - return First->CommonOrPrev.get(); -} - //===----------------------------------------------------------------------===// // TemplateTypeParm Allocation/Deallocation Method Implementations //===----------------------------------------------------------------------===// @@ -431,15 +469,6 @@ StructuredArguments.setPointer(NewArgs); StructuredArguments.setInt(0); // Doesn't own the pointer. } -void TemplateArgumentList::Destroy(ASTContext &C) { - if (FlatArguments.getInt()) - C.Deallocate((void*)FlatArguments.getPointer()); - if (StructuredArguments.getInt()) - C.Deallocate((void*)StructuredArguments.getPointer()); -} - -TemplateArgumentList::~TemplateArgumentList() {} - //===----------------------------------------------------------------------===// // ClassTemplateSpecializationDecl Implementation //===----------------------------------------------------------------------===// @@ -487,16 +516,6 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) { new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization); } -void ClassTemplateSpecializationDecl::Destroy(ASTContext &C) { - delete ExplicitInfo; - - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) - C.Deallocate(PartialSpec); - - CXXRecordDecl::Destroy(C); -} - void ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S, const PrintingPolicy &Policy, @@ -584,3 +603,8 @@ FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc); return Result; } + +FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context, + EmptyShell Empty) { + return new (Context) FriendTemplateDecl(Empty); +} -- cgit v1.1