Introduce the Redeclarable template class, which serves as a base type defining the common interface for Decls that can be redeclared.
Make FunctionDecl and VarDecl use it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76297 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 23782d6..e59d632 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -362,29 +362,8 @@
return 0;
}
-void VarDecl::setPreviousDeclaration(VarDecl *PrevDecl) {
- if (PrevDecl) {
- // Point to previous.
- PreviousDeclaration.setPointer(PrevDecl);
- PreviousDeclaration.setInt(0);
-
- // First one will point to this one as latest.
- // getCanonicalDecl returns the first one.
- VarDecl *First = PrevDecl->getCanonicalDecl();
- assert(First->PreviousDeclaration.getInt() == 1 && "Expected first");
- First->PreviousDeclaration.setPointer(this);
- } else {
- // This is first.
- PreviousDeclaration.setPointer(this);
- PreviousDeclaration.setInt(1);
- }
-}
-
VarDecl *VarDecl::getCanonicalDecl() {
- VarDecl *Var = this;
- while (Var->getPreviousDeclaration())
- Var = Var->getPreviousDeclaration();
- return Var;
+ return getFirstDeclaration();
}
//===----------------------------------------------------------------------===//
@@ -586,22 +565,8 @@
void
FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
- if (PrevDecl) {
- // Point to previous.
- PreviousDeclaration.setPointer(PrevDecl);
- PreviousDeclaration.setInt(0);
-
- // First one will point to this one as latest.
- // getCanonicalDecl returns the first one.
- FunctionDecl *First = PrevDecl->getCanonicalDecl();
- assert(First->PreviousDeclaration.getInt() == 1 && "Expected first");
- First->PreviousDeclaration.setPointer(this);
- } else {
- // This is first.
- PreviousDeclaration.setPointer(this);
- PreviousDeclaration.setInt(1);
- }
-
+ Redeclarable<FunctionDecl>::setPreviousDeclaration(PrevDecl);
+
if (FunctionTemplateDecl *FunTmpl = getDescribedFunctionTemplate()) {
FunctionTemplateDecl *PrevFunTmpl
= PrevDecl? PrevDecl->getDescribedFunctionTemplate() : 0;
@@ -611,10 +576,7 @@
}
FunctionDecl *FunctionDecl::getCanonicalDecl() {
- FunctionDecl *FD = this;
- while (FD->getPreviousDeclaration())
- FD = FD->getPreviousDeclaration();
- return FD;
+ return getFirstDeclaration();
}
/// getOverloadedOperator - Which C++ overloaded operator this