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/AST/DeclTemplate.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/AST/DeclTemplate.cpp')
-rw-r--r-- | lib/AST/DeclTemplate.cpp | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index f505321f03..a745526219 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -112,42 +112,30 @@ static void AdoptTemplateParameterList(TemplateParameterList *Params, //===----------------------------------------------------------------------===// RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() { - // Find the first declaration of this function template. - RedeclarableTemplateDecl *First = getCanonicalDecl(); - - if (First->CommonOrPrev.isNull()) { - CommonBase *CommonPtr = First->newCommon(getASTContext()); - First->CommonOrPrev = CommonPtr; - CommonPtr->Latest = First; - } - return First->CommonOrPrev.get<CommonBase*>(); -} - - -RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() { - RedeclarableTemplateDecl *Tmpl = this; - while (Tmpl->getPreviousDeclaration()) - Tmpl = Tmpl->getPreviousDeclaration(); - return Tmpl; -} + if (!Common) { + // Walk the previous-declaration chain until we either find a declaration + // with a common pointer or we run out of previous declarations. + llvm::SmallVector<RedeclarableTemplateDecl *, 2> PrevDecls; + for (RedeclarableTemplateDecl *Prev = getPreviousDeclaration(); Prev; + Prev = Prev->getPreviousDeclaration()) { + if (Prev->Common) { + Common = Prev->Common; + break; + } + + PrevDecls.push_back(Prev); + } -void RedeclarableTemplateDecl::setPreviousDeclarationImpl( - RedeclarableTemplateDecl *Prev) { - if (Prev) { - CommonBase *Common = Prev->getCommonPtr(); - Prev = Common->Latest; - Common->Latest = this; - CommonOrPrev = Prev; - } else { - assert(CommonOrPrev.is<CommonBase*>() && "Cannot reset TemplateDecl Prev"); + // If we never found a common pointer, allocate one now. + if (!Common) + Common = newCommon(getASTContext()); + + // Update any previous declarations we saw with the common pointer. + for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I) + PrevDecls[I]->Common = Common; } -} -RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() { - if (CommonOrPrev.is<RedeclarableTemplateDecl*>()) - return CommonOrPrev.get<RedeclarableTemplateDecl*>(); - CommonBase *Common = CommonOrPrev.get<CommonBase*>(); - return Common ? Common->Latest : this; + return Common; } template <class EntryType> |