diff options
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 728724f1b3..0a6f28d3fb 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -387,8 +387,11 @@ VarDecl *VarDecl::getFirstDeclaration() { 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 @@ FunctionDecl *FunctionDecl::getFirstDeclaration() { 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 @@ SourceRange TagDecl::getSourceRange() const { 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); |