diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-14 03:19:57 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-14 03:19:57 +0000 |
| commit | ef17c07bf6ae991360ef745a1437d97f7d8eb13b (patch) | |
| tree | c51445efe923841a285c5135f27c4c124acb5803 /clang | |
| parent | d49e8dd759859b05cde901e30d2160439c6d101f (diff) | |
| download | bcm5719-llvm-ef17c07bf6ae991360ef745a1437d97f7d8eb13b.tar.gz bcm5719-llvm-ef17c07bf6ae991360ef745a1437d97f7d8eb13b.zip | |
Introduce FunctionDecl::getFirstDeclaration() and VarDecl::getFirstDeclaration().
For multiple redeclarations they return the first one.
llvm-svn: 75602
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/Decl.h | 8 | ||||
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 28 |
2 files changed, 26 insertions, 10 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index d033c24046d..e83833f7d94 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -413,6 +413,10 @@ public: PreviousDeclaration = PrevDecl; } + /// \brief For multiple redeclarations returns the first one, otherwise + /// returns itself. + const VarDecl *getFirstDeclaration() const; + virtual Decl *getPrimaryDecl() const; /// hasLocalStorage - Returns true if a variable with function scope @@ -811,6 +815,10 @@ public: return PreviousDeclaration; } + /// \brief For multiple redeclarations returns the first one, otherwise + /// returns itself. + const FunctionDecl *getFirstDeclaration() const; + void setPreviousDeclaration(FunctionDecl * PrevDecl); virtual Decl *getPrimaryDecl() const; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index fe9885ef261..5ef0c090936 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -358,12 +358,16 @@ 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(); +const VarDecl *VarDecl::getFirstDeclaration() const { + const VarDecl *First = this; + while (First->getPreviousDeclaration()) + First = First->getPreviousDeclaration(); + + return First; +} - return const_cast<VarDecl *>(Prim); +Decl *VarDecl::getPrimaryDecl() const { + return const_cast<VarDecl *>(getFirstDeclaration()); } //===----------------------------------------------------------------------===// @@ -577,12 +581,16 @@ FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) { } } -Decl *FunctionDecl::getPrimaryDecl() const { - const FunctionDecl *Prim = this; - while (Prim->getPreviousDeclaration()) - Prim = Prim->getPreviousDeclaration(); +const FunctionDecl *FunctionDecl::getFirstDeclaration() const { + const FunctionDecl *First = this; + while (First->getPreviousDeclaration()) + First = First->getPreviousDeclaration(); + + return First; +} - return const_cast<FunctionDecl *>(Prim); +Decl *FunctionDecl::getPrimaryDecl() const { + return const_cast<FunctionDecl *>(getFirstDeclaration()); } /// getOverloadedOperator - Which C++ overloaded operator this |

