diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-05 22:21:56 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-05 22:21:56 +0000 |
| commit | 02dd4f9389836a2f554c6c92bc62b0122808bd6f (patch) | |
| tree | 27050135c2618b76c2e68011892c95ce594eebc9 /clang/lib/AST | |
| parent | cdfe1f210ba7e0dd51f08abc25865b4b376bf3c9 (diff) | |
| download | bcm5719-llvm-02dd4f9389836a2f554c6c92bc62b0122808bd6f.tar.gz bcm5719-llvm-02dd4f9389836a2f554c6c92bc62b0122808bd6f.zip | |
Introduce the virtual method Decl::getPrimaryDecl().
When a Decl subclass can have multiple re-declarations in the same declaration context (like FunctionDecl),
getPrimaryDecl() will return a particular Decl that all of them will point to as the "primary" declaration.
llvm-svn: 74800
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 3d02150b65b..bcbf091a195 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -358,6 +358,14 @@ const Expr *VarDecl::getDefinition(const VarDecl *&Def) const { return Def? Def->getInit() : 0; } +Decl *VarDecl::getPrimaryDecl() const { + const VarDecl *Prim = this; + while (Prim->getPreviousDeclaration()) + Prim = Prim->getPreviousDeclaration(); + + return const_cast<VarDecl *>(Prim); +} + //===----------------------------------------------------------------------===// // FunctionDecl Implementation //===----------------------------------------------------------------------===// @@ -569,6 +577,14 @@ FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) { } } +Decl *FunctionDecl::getPrimaryDecl() const { + const FunctionDecl *Prim = this; + while (Prim->getPreviousDeclaration()) + Prim = Prim->getPreviousDeclaration(); + + return const_cast<FunctionDecl *>(Prim); +} + /// getOverloadedOperator - Which C++ overloaded operator this /// function represents, if any. OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { |

