From 9ac5928abeb3a47592201e1c30fe2930c20a507e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 18 Oct 2007 23:28:49 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43156 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/Expr.cpp | 73 +++++++++++++++++++---------- AST/ExprCXX.cpp | 8 +++- AST/Stmt.cpp | 24 +++++----- AST/StmtIterator.cpp | 2 + include/clang/AST/StmtGraphTraits.h | 8 ++-- include/clang/AST/StmtIterator.h | 7 ++- 6 files changed, 77 insertions(+), 45 deletions(-) diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 49dbfe4798..d6960d35e2 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -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() { diff --git a/AST/ExprCXX.cpp b/AST/ExprCXX.cpp index 31e1e1db91..ea5939caab 100644 --- a/AST/ExprCXX.cpp +++ b/AST/ExprCXX.cpp @@ -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(); +} diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp index c9a86ed28b..96acbd15ba 100644 --- a/AST/Stmt.cpp +++ b/AST/Stmt.cpp @@ -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(&RetExpr); - else return NULL; + else return child_iterator(); } Stmt::child_iterator ReturnStmt::child_end() { if (RetExpr) return reinterpret_cast(&RetExpr)+1; - else return NULL; + else return child_iterator(); } diff --git a/AST/StmtIterator.cpp b/AST/StmtIterator.cpp index d618db8147..b7a03bbb2c 100644 --- a/AST/StmtIterator.cpp +++ b/AST/StmtIterator.cpp @@ -22,6 +22,8 @@ void StmtIteratorBase::NextDecl() { do Ptr.D = Ptr.D->getNextDeclarator(); while (Ptr.D != NULL && !isa(Ptr.D)); + + if (Ptr.D == NULL) FirstDecl = NULL; } StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) { diff --git a/include/clang/AST/StmtGraphTraits.h b/include/clang/AST/StmtGraphTraits.h index 80abc80866..5518199d0d 100644 --- a/include/clang/AST/StmtGraphTraits.h +++ b/include/clang/AST/StmtGraphTraits.h @@ -33,12 +33,12 @@ template <> struct GraphTraits { 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 { 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) { diff --git a/include/clang/AST/StmtIterator.h b/include/clang/AST/StmtIterator.h index 33b26eac81..f347636fae 100644 --- a/include/clang/AST/StmtIterator.h +++ b/include/clang/AST/StmtIterator.h @@ -91,11 +91,16 @@ public: }; struct StmtIterator : public StmtIteratorImpl { + explicit StmtIterator() : StmtIteratorImpl() {} StmtIterator(Stmt** S) : StmtIteratorImpl(S) {} + StmtIterator(ScopedDecl* D) : StmtIteratorImpl(D) {} }; struct ConstStmtIterator : public StmtIteratorImpl { + const Stmt*> { + explicit ConstStmtIterator() : + StmtIteratorImpl() {} + ConstStmtIterator(const StmtIterator& RHS) : StmtIteratorImpl(RHS) {} }; -- 2.50.1