Move the functionality of ASTContext::getCanonicalDecl(), into a virtual method Decl::getCanonicalDecl().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76273 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 728724f..0a6f28d 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -387,8 +387,11 @@
return First;
}
-Decl *VarDecl::getPrimaryDecl() const {
- return const_cast<VarDecl *>(getFirstDeclaration());
+VarDecl *VarDecl::getCanonicalDecl() {
+ VarDecl *Var = this;
+ while (Var->getPreviousDeclaration())
+ Var = Var->getPreviousDeclaration();
+ return Var;
}
//===----------------------------------------------------------------------===//
@@ -621,8 +624,11 @@
return First;
}
-Decl *FunctionDecl::getPrimaryDecl() const {
- return const_cast<FunctionDecl *>(getFirstDeclaration());
+FunctionDecl *FunctionDecl::getCanonicalDecl() {
+ FunctionDecl *FD = this;
+ while (FD->getPreviousDeclaration())
+ FD = FD->getPreviousDeclaration();
+ return FD;
}
/// getOverloadedOperator - Which C++ overloaded operator this
@@ -703,6 +709,14 @@
return SourceRange(getLocation(), E);
}
+TagDecl* TagDecl::getCanonicalDecl() {
+ Type *T = getTypeForDecl();
+ if (T == 0)
+ T = getASTContext().getTagDeclType(this).getTypePtr();
+
+ return cast<TagDecl>(cast<TagType>(T->getCanonicalTypeInternal())->getDecl());
+}
+
void TagDecl::startDefinition() {
TagType *TagT = const_cast<TagType *>(TypeForDecl->getAsTagType());
TagT->decl.setPointer(this);