[cfe-commits] r43156 - in /cfe/trunk: AST/Expr.cpp AST/ExprCXX.cpp AST/Stmt.cpp AST/StmtIterator.cpp include/clang/AST/StmtGraphTraits.h include/clang/AST/StmtIterator.h

Ted Kremenek kremenek at apple.com
Thu Oct 18 16:28:49 PDT 2007


Author: kremenek
Date: Thu Oct 18 18:28:49 2007
New Revision: 43156

URL: http://llvm.org/viewvc/llvm-project?rev=43156&view=rev
Log:
Fixed DeclStmt::child_begin() to actually create an iterator that
visits its decls, rather than just creating an "end()" iterator.

Fixed child_end() for statements and expressions to use
child_iterator() to create the end() iterator, rather than just
returning NULL.

Fixed bug in StmtIterator where we did not correctly detect if we had
marched off the end of the ScopedDecls.

Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/AST/ExprCXX.cpp
    cfe/trunk/AST/Stmt.cpp
    cfe/trunk/AST/StmtIterator.cpp
    cfe/trunk/include/clang/AST/StmtGraphTraits.h
    cfe/trunk/include/clang/AST/StmtIterator.h

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=43156&r1=43155&r2=43156&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Thu Oct 18 18:28:49 2007
@@ -899,24 +899,24 @@
 //===----------------------------------------------------------------------===//
 
 // DeclRefExpr
-Stmt::child_iterator DeclRefExpr::child_begin() { return NULL; }
-Stmt::child_iterator DeclRefExpr::child_end() { return NULL; }
+Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
+Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
 
 // PreDefinedExpr
-Stmt::child_iterator PreDefinedExpr::child_begin() { return NULL; }
-Stmt::child_iterator PreDefinedExpr::child_end() { return NULL; }
+Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); }
+Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); }
 
 // IntegerLiteral
-Stmt::child_iterator IntegerLiteral::child_begin() { return NULL; }
-Stmt::child_iterator IntegerLiteral::child_end() { return NULL; }
+Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
+Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
 
 // CharacterLiteral
-Stmt::child_iterator CharacterLiteral::child_begin() { return NULL; }
-Stmt::child_iterator CharacterLiteral::child_end() { return NULL; }
+Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); }
+Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
 
 // FloatingLiteral
-Stmt::child_iterator FloatingLiteral::child_begin() { return NULL; }
-Stmt::child_iterator FloatingLiteral::child_end() { return NULL; }
+Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
+Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
 
 // ImaginaryLiteral
 Stmt::child_iterator ImaginaryLiteral::child_begin() {
@@ -927,8 +927,8 @@
 }
 
 // StringLiteral
-Stmt::child_iterator StringLiteral::child_begin() { return NULL; }
-Stmt::child_iterator StringLiteral::child_end() { return NULL; }
+Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
+Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
 
 // ParenExpr
 Stmt::child_iterator ParenExpr::child_begin() {
@@ -947,8 +947,12 @@
 }
 
 // SizeOfAlignOfTypeExpr
-Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() { return NULL; }
-Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() { return NULL; }
+Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() { 
+  return child_iterator(); 
+}
+Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
+  return child_iterator();
+}
 
 // ArraySubscriptExpr
 Stmt::child_iterator ArraySubscriptExpr::child_begin() {
@@ -1023,8 +1027,8 @@
 }
 
 // AddrLabelExpr
-Stmt::child_iterator AddrLabelExpr::child_begin() { return NULL; }
-Stmt::child_iterator AddrLabelExpr::child_end() { return NULL; }
+Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
+Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
 
 // StmtExpr
 Stmt::child_iterator StmtExpr::child_begin() {
@@ -1035,8 +1039,13 @@
 }
 
 // TypesCompatibleExpr
-Stmt::child_iterator TypesCompatibleExpr::child_begin() { return NULL; }
-Stmt::child_iterator TypesCompatibleExpr::child_end() { return NULL; }
+Stmt::child_iterator TypesCompatibleExpr::child_begin() {
+  return child_iterator();
+}
+
+Stmt::child_iterator TypesCompatibleExpr::child_end() {
+  return child_iterator();
+}
 
 // ChooseExpr
 Stmt::child_iterator ChooseExpr::child_begin() {
@@ -1065,20 +1074,32 @@
 }
 
 // ObjCStringLiteral
-Stmt::child_iterator ObjCStringLiteral::child_begin() { return NULL; }
-Stmt::child_iterator ObjCStringLiteral::child_end() { return NULL; }
+Stmt::child_iterator ObjCStringLiteral::child_begin() { 
+  return child_iterator();
+}
+Stmt::child_iterator ObjCStringLiteral::child_end() {
+  return child_iterator();
+}
 
 // ObjCEncodeExpr
-Stmt::child_iterator ObjCEncodeExpr::child_begin() { return NULL; }
-Stmt::child_iterator ObjCEncodeExpr::child_end() { return NULL; }
+Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
+Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
 
 // ObjCSelectorExpr
-Stmt::child_iterator ObjCSelectorExpr::child_begin() { return NULL; }
-Stmt::child_iterator ObjCSelectorExpr::child_end() { return NULL; }
+Stmt::child_iterator ObjCSelectorExpr::child_begin() { 
+  return child_iterator();
+}
+Stmt::child_iterator ObjCSelectorExpr::child_end() {
+  return child_iterator();
+}
 
 // ObjCProtocolExpr
-Stmt::child_iterator ObjCProtocolExpr::child_begin() { return NULL; }
-Stmt::child_iterator ObjCProtocolExpr::child_end() { return NULL; }
+Stmt::child_iterator ObjCProtocolExpr::child_begin() {
+  return child_iterator();
+}
+Stmt::child_iterator ObjCProtocolExpr::child_end() {
+  return child_iterator();
+}
 
 // ObjCMessageExpr
 Stmt::child_iterator ObjCMessageExpr::child_begin() {

Modified: cfe/trunk/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ExprCXX.cpp?rev=43156&r1=43155&r2=43156&view=diff

==============================================================================
--- cfe/trunk/AST/ExprCXX.cpp (original)
+++ cfe/trunk/AST/ExprCXX.cpp Thu Oct 18 18:28:49 2007
@@ -29,5 +29,9 @@
 }
 
 // CXXBoolLiteralExpr
-Stmt::child_iterator CXXBoolLiteralExpr::child_begin() { return NULL; }
-Stmt::child_iterator CXXBoolLiteralExpr::child_end() { return NULL; }
+Stmt::child_iterator CXXBoolLiteralExpr::child_begin() { 
+  return child_iterator();
+}
+Stmt::child_iterator CXXBoolLiteralExpr::child_end() {
+  return child_iterator();
+}

Modified: cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Stmt.cpp?rev=43156&r1=43155&r2=43156&view=diff

==============================================================================
--- cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/trunk/AST/Stmt.cpp Thu Oct 18 18:28:49 2007
@@ -116,12 +116,12 @@
 //===----------------------------------------------------------------------===//
 
 // DeclStmt
-Stmt::child_iterator DeclStmt::child_begin() { return NULL; }
-Stmt::child_iterator DeclStmt::child_end() { return NULL; }
+Stmt::child_iterator DeclStmt::child_begin() { return getDecl(); }
+Stmt::child_iterator DeclStmt::child_end() { return child_iterator(); }
 
 // NullStmt
-Stmt::child_iterator NullStmt::child_begin() { return NULL; }
-Stmt::child_iterator NullStmt::child_end() { return NULL; }
+Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
+Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
 
 // CompoundStmt
 Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; }
@@ -160,8 +160,8 @@
 Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; }
 
 // GotoStmt
-Stmt::child_iterator GotoStmt::child_begin() { return NULL; }
-Stmt::child_iterator GotoStmt::child_end() { return NULL; }
+Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); }
+Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }
 
 // IndirectGotoStmt
 Stmt::child_iterator IndirectGotoStmt::child_begin() { 
@@ -171,21 +171,21 @@
 Stmt::child_iterator IndirectGotoStmt::child_end() { return ++child_begin(); }
 
 // ContinueStmt
-Stmt::child_iterator ContinueStmt::child_begin() { return NULL; }
-Stmt::child_iterator ContinueStmt::child_end() { return NULL; }
+Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); }
+Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); }
 
 // BreakStmt
-Stmt::child_iterator BreakStmt::child_begin() { return NULL; }
-Stmt::child_iterator BreakStmt::child_end() { return NULL; }
+Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); }
+Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); }
 
 // ReturnStmt
 Stmt::child_iterator ReturnStmt::child_begin() {
   if (RetExpr) return reinterpret_cast<Stmt**>(&RetExpr);
-  else return NULL;
+  else return child_iterator();
 }
 
 Stmt::child_iterator ReturnStmt::child_end() { 
   if (RetExpr) return reinterpret_cast<Stmt**>(&RetExpr)+1;
-  else return NULL;
+  else return child_iterator();
 }
 

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

==============================================================================
--- cfe/trunk/AST/StmtIterator.cpp (original)
+++ cfe/trunk/AST/StmtIterator.cpp Thu Oct 18 18:28:49 2007
@@ -22,6 +22,8 @@
 
   do Ptr.D = Ptr.D->getNextDeclarator();
   while (Ptr.D != NULL && !isa<VarDecl>(Ptr.D));
+  
+  if (Ptr.D == NULL) FirstDecl = NULL;
 }
 
 StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) {

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

==============================================================================
--- cfe/trunk/include/clang/AST/StmtGraphTraits.h (original)
+++ cfe/trunk/include/clang/AST/StmtGraphTraits.h Thu Oct 18 18:28:49 2007
@@ -33,12 +33,12 @@
   
   static inline ChildIteratorType child_begin(NodeType* N) {
     if (N) return N->child_begin();
-    else return NULL;
+    else return ChildIteratorType();
   }
   
   static inline ChildIteratorType child_end(NodeType* N) {
     if (N) return N->child_end();
-    else return NULL;
+    else return ChildIteratorType();
   }
   
   static nodes_iterator nodes_begin(clang::Stmt* S) {
@@ -60,12 +60,12 @@
   
   static inline ChildIteratorType child_begin(NodeType* N) {
     if (N) return N->child_begin();
-    else return ChildIteratorType(NULL);    
+    else return ChildIteratorType();    
   }
   
   static inline ChildIteratorType child_end(NodeType* N) {
     if (N) return N->child_end();
-    else return ChildIteratorType(NULL);
+    else return ChildIteratorType();
   }
   
   static nodes_iterator nodes_begin(const clang::Stmt* S) {

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

==============================================================================
--- cfe/trunk/include/clang/AST/StmtIterator.h (original)
+++ cfe/trunk/include/clang/AST/StmtIterator.h Thu Oct 18 18:28:49 2007
@@ -91,11 +91,16 @@
 };
 
 struct StmtIterator : public StmtIteratorImpl<StmtIterator,Stmt*> {
+  explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*>() {}
   StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*>(S) {}
+  StmtIterator(ScopedDecl* D) : StmtIteratorImpl<StmtIterator,Stmt*>(D) {}
 };
 
 struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
-                                                   const Stmt*> {    
+                                                   const Stmt*> {
+  explicit ConstStmtIterator() : 
+    StmtIteratorImpl<ConstStmtIterator,const Stmt*>() {}
+
   ConstStmtIterator(const StmtIterator& RHS) : 
     StmtIteratorImpl<ConstStmtIterator,const Stmt*>(RHS) {}
 };





More information about the cfe-commits mailing list