[cfe-commits] r74800 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h lib/AST/Decl.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Sun Jul 5 15:21:56 PDT 2009
Author: akirtzidis
Date: Sun Jul 5 17:21:56 2009
New Revision: 74800
URL: http://llvm.org/viewvc/llvm-project?rev=74800&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/Decl.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=74800&r1=74799&r2=74800&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun Jul 5 17:21:56 2009
@@ -413,6 +413,8 @@
PreviousDeclaration = PrevDecl;
}
+ virtual Decl *getPrimaryDecl() const;
+
/// hasLocalStorage - Returns true if a variable with function scope
/// is a non-static local variable.
bool hasLocalStorage() const {
@@ -811,6 +813,8 @@
void setPreviousDeclaration(FunctionDecl * PrevDecl);
+ virtual Decl *getPrimaryDecl() const;
+
unsigned getBuiltinID(ASTContext &Context) const;
unsigned getNumParmVarDeclsFromType() const;
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=74800&r1=74799&r2=74800&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Sun Jul 5 17:21:56 2009
@@ -311,6 +311,13 @@
// be defined inside or outside a function etc).
bool isDefinedOutsideFunctionOrMethod() const;
+ /// \brief When there are multiple re-declarations (e.g. for functions),
+ /// this will return the primary one which all of them point to.
+ virtual Decl *getPrimaryDecl() const { return const_cast<Decl*>(this); }
+
+ /// \brief Whether this particular Decl is a primary one.
+ bool isPrimaryDecl() const { return getPrimaryDecl() == this; }
+
/// getBody - If this Decl represents a declaration for a body of code,
/// such as a function or method definition, this method returns the
/// top-level Stmt* of that body. Otherwise this method returns null.
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=74800&r1=74799&r2=74800&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sun Jul 5 17:21:56 2009
@@ -358,6 +358,14 @@
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 @@
}
}
+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 {
More information about the cfe-commits
mailing list