aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-14 03:19:57 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-14 03:19:57 +0000
commit7bf792fdde4641d865eba4a068d862d5300bd1e4 (patch)
treea089bdc3ad9f9c1208b4c6b82219bf91a459f266
parentba4b8bd33206f695923d117f2711c486873da86d (diff)
Introduce FunctionDecl::getFirstDeclaration() and VarDecl::getFirstDeclaration().
For multiple redeclarations they return the first one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75602 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Decl.h8
-rw-r--r--lib/AST/Decl.cpp28
2 files changed, 26 insertions, 10 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index d033c24046..e83833f7d9 100644
--- a/include/clang/AST/Decl.h
+++ b/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/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index fe9885ef26..5ef0c09093 100644
--- a/lib/AST/Decl.cpp
+++ b/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