diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-18 00:34:07 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-18 00:34:07 +0000 |
commit | b57a4fe73b8227c0dba651818b8495dfca61e530 (patch) | |
tree | 56854fb0f97e67a7dc7ef19ba5fedb56155a29a9 /lib/AST/Decl.cpp | |
parent | 0df134715d75c62422502af0f5610885a5a4f472 (diff) |
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
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); |