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

Ted Kremenek kremenek at apple.com
Thu Oct 25 15:24:19 PDT 2007


Author: kremenek
Date: Thu Oct 25 17:24:19 2007
New Revision: 43366

URL: http://llvm.org/viewvc/llvm-project?rev=43366&view=rev
Log:
Modified StmtIterator to now include visiting the initialization expression for EnumConstantDecls.

Modified:
    cfe/trunk/AST/StmtIterator.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/StmtIterator.h

Modified: cfe/trunk/AST/StmtIterator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtIterator.cpp?rev=43366&r1=43365&r2=43366&view=diff

==============================================================================
--- cfe/trunk/AST/StmtIterator.cpp (original)
+++ cfe/trunk/AST/StmtIterator.cpp Thu Oct 25 17:24:19 2007
@@ -17,11 +17,23 @@
 
 using namespace clang;
 
+static inline bool declHasExpr(ScopedDecl *decl) {
+  if (VarDecl* D = dyn_cast<VarDecl>(decl))
+    if (D->getInit())
+      return true;
+  
+  if (EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(decl))
+    if (D->getInitExpr())
+      return true;
+  
+  return false;  
+}
+
 void StmtIteratorBase::NextDecl() {
   assert (FirstDecl && Ptr.D);
 
   do Ptr.D = Ptr.D->getNextDeclarator();
-  while (Ptr.D != NULL && !isa<VarDecl>(Ptr.D));
+  while (Ptr.D != NULL && !declHasExpr(Ptr.D));
   
   if (Ptr.D == NULL) FirstDecl = NULL;
 }
@@ -29,12 +41,8 @@
 StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) {
   assert (d);
   
-  while (d != NULL) {
-    if (VarDecl* V = dyn_cast<VarDecl>(d))
-      if (V->getInit()) break;
-    
+  while (d != NULL && !declHasExpr(d))
     d = d->getNextDeclarator();
-  }
   
   FirstDecl = d;
   Ptr.D = d;
@@ -61,6 +69,11 @@
   Ptr.D = lastVD;
 }
 
-Stmt*& StmtIteratorBase::GetInitializer() const {
-  return reinterpret_cast<Stmt*&>(cast<VarDecl>(Ptr.D)->Init);
+Stmt*& StmtIteratorBase::GetDeclExpr() const {
+  if (VarDecl* D = dyn_cast<VarDecl>(Ptr.D))
+    return reinterpret_cast<Stmt*&>(D->Init);
+  else {
+    EnumConstantDecl* D = cast<EnumConstantDecl>(Ptr.D);
+    return reinterpret_cast<Stmt*&>(D->Init);
+  }
 }

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=43366&r1=43365&r2=43366&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Oct 25 17:24:19 2007
@@ -430,6 +430,8 @@
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
   static bool classof(const EnumConstantDecl *D) { return true; }
+  
+  friend class StmtIteratorBase;
 };
 
 

Modified: cfe/trunk/include/clang/AST/StmtIterator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtIterator.h?rev=43366&r1=43365&r2=43366&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/StmtIterator.h (original)
+++ cfe/trunk/include/clang/AST/StmtIterator.h Thu Oct 25 17:24:19 2007
@@ -28,7 +28,7 @@
   
   void NextDecl();
   void PrevDecl();
-  Stmt*& GetInitializer() const;
+  Stmt*& GetDeclExpr() const;
 
   StmtIteratorBase(Stmt** s) : FirstDecl(NULL) { Ptr.S = s; }
   StmtIteratorBase(ScopedDecl* d);
@@ -84,7 +84,7 @@
   }
   
   REFERENCE operator*() const { 
-    return (REFERENCE) (FirstDecl ? GetInitializer() : *Ptr.S);
+    return (REFERENCE) (FirstDecl ? GetDeclExpr() : *Ptr.S);
   }
   
   REFERENCE operator->() const { return operator*(); }   





More information about the cfe-commits mailing list