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.

llvm-svn: 43156
This commit is contained in:
Ted Kremenek 2007-10-18 23:28:49 +00:00
parent e183a8259d
commit 04746ce6f9
6 changed files with 77 additions and 45 deletions

View 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() {

View 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();
}

View 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();
}

View 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) {

View 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) {

View 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) {}
};