Rewrite users of Stmt::child_begin/end into for-range loops.

No functionality change intended.

llvm-svn: 241355
This commit is contained in:
Benjamin Kramer 2015-07-03 15:12:24 +00:00
parent e9da9aa4f3
commit 973431b22f
16 changed files with 61 additions and 84 deletions

View File

@ -322,11 +322,10 @@ void TransferFunctions::Visit(Stmt *S) {
return;
}
}
for (Stmt::child_iterator it = S->child_begin(), ei = S->child_end();
it != ei; ++it) {
if (Stmt *child = *it)
AddLiveStmt(val.liveStmts, LV.SSetFact, child);
for (Stmt *Child : S->children()) {
if (Child)
AddLiveStmt(val.liveStmts, LV.SSetFact, Child);
}
}

View File

@ -168,10 +168,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
void WalkAST::VisitChildren(Stmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I != E;
++I)
if (Stmt *child = *I)
Visit(child);
for (Stmt *Child : S->children())
if (Child)
Visit(Child);
}
namespace {

View File

@ -69,8 +69,8 @@ static bool scan_ivar_release(Stmt *S, ObjCIvarDecl *ID,
}
// Recurse to children.
for (Stmt::child_iterator I = S->child_begin(), E= S->child_end(); I!=E; ++I)
if (*I && scan_ivar_release(*I, ID, PD, Release, SelfII, Ctx))
for (Stmt *SubStmt : S->children())
if (SubStmt && scan_ivar_release(SubStmt, ID, PD, Release, SelfII, Ctx))
return true;
return false;

View File

@ -109,9 +109,9 @@ public:
//===----------------------------------------------------------------------===//
void WalkAST::VisitChildren(Stmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
if (Stmt *child = *I)
Visit(child);
for (Stmt *Child : S->children())
if (Child)
Visit(Child);
}
void WalkAST::VisitCallExpr(CallExpr *CE) {
@ -162,11 +162,11 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
void WalkAST::VisitCompoundStmt(CompoundStmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
if (Stmt *child = *I) {
if (CallExpr *CE = dyn_cast<CallExpr>(child))
for (Stmt *Child : S->children())
if (Child) {
if (CallExpr *CE = dyn_cast<CallExpr>(Child))
checkUncheckedReturnValue(CE);
Visit(child);
Visit(Child);
}
}

View File

@ -37,9 +37,9 @@ public:
}
void WalkAST::VisitChildren(Stmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
if (Stmt *child = *I)
Visit(child);
for (Stmt *Child : S->children())
if (Child)
Visit(Child);
}
// CWE-467: Use of sizeof() on a Pointer Type

View File

@ -124,10 +124,9 @@ public:
const CheckerBase *checker)
: DeclWithIssue(declWithIssue), BR(br), Checker(checker) {}
void VisitChildren(Stmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end() ;
I != E; ++I)
if (Stmt *child = *I)
Visit(child);
for (Stmt *Child : S->children())
if (Child)
Visit(Child);
}
void VisitStmt(Stmt *S) { VisitChildren(S); }
void VisitDeclStmt(DeclStmt *DS);

View File

@ -65,10 +65,9 @@ public:
}
void VisitChildren(const Stmt *S) {
for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
I!=E; ++I)
if (const Stmt *child = *I)
VisitChild(S, child);
for (const Stmt *Child : S->children())
if (Child)
VisitChild(S, Child);
}
TypeCallPair VisitCastExpr(const CastExpr *E) {

View File

@ -153,9 +153,9 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
}
void WalkAST::VisitChildren(Stmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
if (Stmt *child = *I)
Visit(child);
for (Stmt *Child : S->children())
if (Child)
Visit(Child);
}
namespace {

View File

@ -57,8 +57,8 @@ static void Scan(IvarUsageMap& M, const Stmt *S) {
Scan(M, sub);
}
for (Stmt::const_child_iterator I=S->child_begin(),E=S->child_end(); I!=E;++I)
Scan(M, *I);
for (const Stmt *SubStmt : S->children())
Scan(M, SubStmt);
}
static void Scan(IvarUsageMap& M, const ObjCPropertyImplDecl *D) {

View File

@ -2182,9 +2182,8 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N,
// Add the range by scanning the children of the statement for any bindings
// to Sym.
for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
I!=E; ++I)
if (const Expr *Exp = dyn_cast_or_null<Expr>(*I))
for (const Stmt *Child : S->children())
if (const Expr *Exp = dyn_cast_or_null<Expr>(Child))
if (CurrSt->getSValAsScalarOrLoc(Exp, LCtx).getAsLocSymbol() == Sym) {
P->addRange(Exp->getSourceRange());
break;
@ -2779,16 +2778,14 @@ void RetainCountChecker::processObjCLiterals(CheckerContext &C,
const Expr *Ex) const {
ProgramStateRef state = C.getState();
const ExplodedNode *pred = C.getPredecessor();
for (Stmt::const_child_iterator it = Ex->child_begin(), et = Ex->child_end() ;
it != et ; ++it) {
const Stmt *child = *it;
SVal V = state->getSVal(child, pred->getLocationContext());
for (const Stmt *Child : Ex->children()) {
SVal V = state->getSVal(Child, pred->getLocationContext());
if (SymbolRef sym = V.getAsSymbol())
if (const RefVal* T = getRefBinding(state, sym)) {
RefVal::Kind hasErr = (RefVal::Kind) 0;
state = updateSymbol(state, sym, *T, MayEscape, hasErr, C);
if (hasErr) {
processNonLeakError(state, child->getSourceRange(), hasErr, sym, C);
processNonLeakError(state, Child->getSourceRange(), hasErr, sym, C);
return;
}
}

View File

@ -37,12 +37,10 @@ class UndefBranchChecker : public Checker<check::BranchCondition> {
if (!MatchesCriteria(Ex))
return nullptr;
for (Stmt::const_child_iterator I = Ex->child_begin(),
E = Ex->child_end();I!=E;++I)
if (const Expr *ExI = dyn_cast_or_null<Expr>(*I)) {
const Expr *E2 = FindExpr(ExI);
if (E2) return E2;
}
for (const Stmt *SubStmt : Ex->children())
if (const Expr *ExI = dyn_cast_or_null<Expr>(SubStmt))
if (const Expr *E2 = FindExpr(ExI))
return E2;
return Ex;
}

View File

@ -40,13 +40,10 @@ static const DeclRefExpr *FindBlockDeclRefExpr(const Stmt *S,
if (BR->getDecl() == VD)
return BR;
for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end();
I!=E; ++I)
if (const Stmt *child = *I) {
const DeclRefExpr *BR = FindBlockDeclRefExpr(child, VD);
if (BR)
for (const Stmt *Child : S->children())
if (Child)
if (const DeclRefExpr *BR = FindBlockDeclRefExpr(Child, VD))
return BR;
}
return nullptr;
}

View File

@ -125,9 +125,9 @@ public:
//===----------------------------------------------------------------------===//
void WalkAST::VisitChildren(Stmt *S) {
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I)
if (Stmt *child = *I)
Visit(child);
for (Stmt *Child : S->children())
if (Child)
Visit(Child);
}
void WalkAST::VisitCallExpr(CallExpr *CE) {

View File

@ -1250,10 +1250,8 @@ static void reversePropagateIntererstingSymbols(BugReport &R,
// Fall through.
case Stmt::BinaryOperatorClass:
case Stmt::UnaryOperatorClass: {
for (Stmt::const_child_iterator CI = Ex->child_begin(),
CE = Ex->child_end();
CI != CE; ++CI) {
if (const Expr *child = dyn_cast_or_null<Expr>(*CI)) {
for (const Stmt *SubStmt : Ex->children()) {
if (const Expr *child = dyn_cast_or_null<Expr>(SubStmt)) {
IE.insert(child);
SVal ChildV = State->getSVal(child, LCtx);
R.markInteresting(ChildV);

View File

@ -1130,9 +1130,8 @@ void FindLastStoreBRVisitor::registerStatementVarDecls(BugReport &BR,
}
}
for (Stmt::const_child_iterator I = Head->child_begin();
I != Head->child_end(); ++I)
WorkList.push_back(*I);
for (const Stmt *SubStmt : Head->children())
WorkList.push_back(SubStmt);
}
}

View File

@ -22,11 +22,9 @@ bool clang::ento::containsMacro(const Stmt *S) {
if (S->getLocEnd().isMacroID())
return true;
for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
++I)
if (const Stmt *child = *I)
if (containsMacro(child))
return true;
for (const Stmt *Child : S->children())
if (Child && containsMacro(Child))
return true;
return false;
}
@ -38,11 +36,9 @@ bool clang::ento::containsEnum(const Stmt *S) {
if (DR && isa<EnumConstantDecl>(DR->getDecl()))
return true;
for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
++I)
if (const Stmt *child = *I)
if (containsEnum(child))
return true;
for (const Stmt *Child : S->children())
if (Child && containsEnum(Child))
return true;
return false;
}
@ -56,11 +52,9 @@ bool clang::ento::containsStaticLocal(const Stmt *S) {
if (VD->isStaticLocal())
return true;
for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
++I)
if (const Stmt *child = *I)
if (containsStaticLocal(child))
return true;
for (const Stmt *Child : S->children())
if (Child && containsStaticLocal(Child))
return true;
return false;
}
@ -70,11 +64,9 @@ bool clang::ento::containsBuiltinOffsetOf(const Stmt *S) {
if (isa<OffsetOfExpr>(S))
return true;
for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
++I)
if (const Stmt *child = *I)
if (containsBuiltinOffsetOf(child))
return true;
for (const Stmt *Child : S->children())
if (Child && containsBuiltinOffsetOf(Child))
return true;
return false;
}