[cfe-commits] r75602 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Mon Jul 13 20:19:58 PDT 2009


Author: akirtzidis
Date: Mon Jul 13 22:19:57 2009
New Revision: 75602

URL: http://llvm.org/viewvc/llvm-project?rev=75602&view=rev
Log:
Introduce FunctionDecl::getFirstDeclaration() and VarDecl::getFirstDeclaration().

For multiple redeclarations they return the first one.

Modified:
    cfe/trunk/include/clang/AST/Decl.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=75602&r1=75601&r2=75602&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Jul 13 22:19:57 2009
@@ -413,6 +413,10 @@
     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 @@
     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;

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=75602&r1=75601&r2=75602&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Jul 13 22:19:57 2009
@@ -358,12 +358,16 @@
   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 @@
   }
 }
 
-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





More information about the cfe-commits mailing list