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 | 5614aef776d36e2eac36b8fef9c0ab356bb901d2 (patch) | |
| tree | 5ad25e7032de61012e2e4dfaf5375e86b36913c6 /clang/lib/AST/Decl.cpp | |
| parent | e842bd16cef2546439042cd66411c5636b1e25fb (diff) | |
| download | bcm5719-llvm-5614aef776d36e2eac36b8fef9c0ab356bb901d2.tar.gz bcm5719-llvm-5614aef776d36e2eac36b8fef9c0ab356bb901d2.zip | |
Move the functionality of ASTContext::getCanonicalDecl(), into a virtual method Decl::getCanonicalDecl().
llvm-svn: 76273
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 728724f1b3d..0a6f28d3fb7 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/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); |

