]> granicus.if.org Git - clang/commitdiff
Fixed DeclStmt::child_begin() to actually create an iterator that
authorTed Kremenek <kremenek@apple.com>
Thu, 18 Oct 2007 23:28:49 +0000 (23:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 18 Oct 2007 23:28:49 +0000 (23:28 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43156 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
AST/ExprCXX.cpp
AST/Stmt.cpp
AST/StmtIterator.cpp
include/clang/AST/StmtGraphTraits.h
include/clang/AST/StmtIterator.h

index 49dbfe4798b8b99e7edf25db20e13d3044d8ee19..d6960d35e275791851ee100eb56246995deb80da 100644 (file)
@@ -899,24 +899,24 @@ ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
 //===----------------------------------------------------------------------===//
 
 // 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 @@ Stmt::child_iterator ImaginaryLiteral::child_end() {
 }
 
 // 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 @@ Stmt::child_iterator UnaryOperator::child_end() {
 }
 
 // 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 @@ Stmt::child_iterator ConditionalOperator::child_end() {
 }
 
 // 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 @@ Stmt::child_iterator StmtExpr::child_end() {
 }
 
 // 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 @@ Stmt::child_iterator InitListExpr::child_end() {
 }
 
 // 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() {
index 31e1e1db91926119e62a985bb66f4102331171e5..ea5939caab408d92de91d1421201745660636961 100644 (file)
@@ -29,5 +29,9 @@ Stmt::child_iterator CXXCastExpr::child_end() {
 }
 
 // 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();
+}
index c9a86ed28bc66b1b1adace84c9cd914037e1f7a6..96acbd15ba425d382e39026459ae7167d0bb8156 100644 (file)
@@ -116,12 +116,12 @@ bool Stmt::hasImplicitControlFlow() const {
 //===----------------------------------------------------------------------===//
 
 // 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_begin() { return &SubExprs[0]; }
 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_begin() {
 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();
 }
 
index d618db8147dad51d41669ef3a4d6f9a486ad648d..b7a03bbb2c995232e0c9b9910dae2db4aaaeee0f 100644 (file)
@@ -22,6 +22,8 @@ void StmtIteratorBase::NextDecl() {
 
   do Ptr.D = Ptr.D->getNextDeclarator();
   while (Ptr.D != NULL && !isa<VarDecl>(Ptr.D));
+  
+  if (Ptr.D == NULL) FirstDecl = NULL;
 }
 
 StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) {
index 80abc80866edec87766dff396817c464a00ccce0..5518199d0d3d3b819758e702bcbffee69925ae32 100644 (file)
@@ -33,12 +33,12 @@ template <> struct GraphTraits<clang::Stmt*> {
   
   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 @@ template <> struct GraphTraits<const clang::Stmt*> {
   
   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) {
index 33b26eac81eb87a02c9a35f502e4b50be9d13e67..f347636fae6b73ff2d9c5c3301bfb2f9d8abf381 100644 (file)
@@ -91,11 +91,16 @@ public:
 };
 
 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) {}
 };