diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-14 15:13:49 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-14 15:13:49 +0000 |
commit | 7c99bb5c4901c39460818ff8c00840218c48251f (patch) | |
tree | 9fbb09a974379415610adfcc29123dd5f8c8e47c /lib/Serialization/ASTReaderDecl.cpp | |
parent | 170fd49294b85ab10f820721d99ff9d109c7230d (diff) |
Reimplement RedeclarableTemplateDecl in terms of
Redeclarable<RedeclarableTemplateDecl>, eliminating a bunch of
redeclaration-chain logic both in RedeclarableTemplateDecl and
especially in its (de-)serialization.
As part of this, eliminate the RedeclarableTemplate<> class template,
which was an abstraction that didn't actually save anything.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148181 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTReaderDecl.cpp')
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 77 |
1 files changed, 24 insertions, 53 deletions
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 75c079fb65..21a0fb06a9 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1234,72 +1234,40 @@ void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { ASTDeclReader::RedeclarableResult ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { - // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr() - // can be used while this is still initializing. - enum RedeclKind { FirstDeclaration, FirstInFile, PointsToPrevious }; - RedeclKind Kind = (RedeclKind)Record[Idx++]; - - // Determine the first declaration ID. - DeclID FirstDeclID = 0; - switch (Kind) { - case FirstDeclaration: { - FirstDeclID = ThisDeclID; + RedeclarableResult Redecl = VisitRedeclarable(D); - // Since this is the first declaration of the template, fill in the - // information for the 'common' pointer. - if (D->CommonOrPrev.isNull()) { - RedeclarableTemplateDecl::CommonBase *Common - = D->newCommon(Reader.getContext()); - Common->Latest = D; - D->CommonOrPrev = Common; - } + // Make sure we've allocated the Common pointer first. We do this before + // VisitTemplateDecl so that getCommonPtr() can be used during initialization. + RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); + if (!CanonD->Common) { + CanonD->Common = CanonD->newCommon(Reader.getContext()); + Reader.PendingDefinitions.insert(CanonD); + } + D->Common = CanonD->Common; + // If this is the first declaration of the template, fill in the information + // for the 'common' pointer. + if (ThisDeclID == Redecl.getFirstID()) { if (RedeclarableTemplateDecl *RTD = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) { assert(RTD->getKind() == D->getKind() && "InstantiatedFromMemberTemplate kind mismatch"); - D->setInstantiatedFromMemberTemplateImpl(RTD); + D->setInstantiatedFromMemberTemplate(RTD); if (Record[Idx++]) D->setMemberSpecialization(); } - break; } - - case FirstInFile: - case PointsToPrevious: { - FirstDeclID = ReadDeclID(Record, Idx); - DeclID PrevDeclID = ReadDeclID(Record, Idx); - - RedeclarableTemplateDecl *FirstDecl - = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(FirstDeclID)); - - // We delay loading of the redeclaration chain to avoid deeply nested calls. - // We temporarily set the first (canonical) declaration as the previous one - // which is the one that matters and mark the real previous DeclID to be - // loaded and attached later on. - D->CommonOrPrev = FirstDecl; - - if (Kind == PointsToPrevious) { - // Make a note that we need to wire up this declaration to its - // previous declaration, later. We don't need to do this for the first - // declaration in any given module file, because those will be wired - // together later. - Reader.PendingPreviousDecls.push_back(std::make_pair(D, PrevDeclID)); - } - break; - } - } - + VisitTemplateDecl(D); D->IdentifierNamespace = Record[Idx++]; - return RedeclarableResult(Reader, FirstDeclID); + return Redecl; } void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { - VisitRedeclarableTemplateDecl(D); + RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); - if (D->getPreviousDeclaration() == 0) { + if (ThisDeclID == Redecl.getFirstID()) { // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of // the specializations. SmallVector<serialization::DeclID, 2> SpecIDs; @@ -1321,6 +1289,7 @@ void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { typedef serialization::DeclID DeclID; ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr(); + // FIXME: Append specializations! CommonPtr->LazySpecializations = new (Reader.getContext()) DeclID [SpecIDs.size()]; memcpy(CommonPtr->LazySpecializations, SpecIDs.data(), @@ -1415,9 +1384,9 @@ void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( } void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { - VisitRedeclarableTemplateDecl(D); + RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); - if (D->getPreviousDeclaration() == 0) { + if (ThisDeclID == Redecl.getFirstID()) { // This FunctionTemplateDecl owns a CommonPtr; read it. // Read the function specialization declarations. @@ -1808,7 +1777,7 @@ void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { ND->RedeclLink.setPointer(cast<NamespaceDecl>(previous)); } else { RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D); - TD->CommonOrPrev = cast<RedeclarableTemplateDecl>(previous); + TD->RedeclLink.setPointer(cast<RedeclarableTemplateDecl>(previous)); } } @@ -1841,7 +1810,9 @@ void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { cast<NamespaceDecl>(Latest)); } else { RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D); - TD->getCommonPtr()->Latest = cast<RedeclarableTemplateDecl>(Latest); + TD->RedeclLink + = Redeclarable<RedeclarableTemplateDecl>::LatestDeclLink( + cast<RedeclarableTemplateDecl>(Latest)); } } |