From: Benjamin Kramer Date: Thu, 2 Jul 2015 21:03:14 +0000 (+0000) Subject: Switch users of the 'for (StmtRange range = stmt->children(); range; ++range)‘ patter... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=247b5bd74b436fbaa561813d730c6045a33f4eae;p=clang Switch users of the 'for (StmtRange range = stmt->children(); range; ++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241300 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index e4c3e8fb32..923d98fb16 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -1861,8 +1861,8 @@ DEF_TRAVERSE_DECL(ParmVarDecl, { TRY_TO(WalkUpFrom##STMT(S)); \ StmtQueueAction StmtQueue(*this); \ { CODE; } \ - for (Stmt::child_range range = S->children(); range; ++range) { \ - StmtQueue.queue(*range); \ + for (Stmt *SubStmt : S->children()) { \ + StmtQueue.queue(SubStmt); \ } \ return true; \ } @@ -2011,8 +2011,8 @@ bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { TRY_TO(WalkUpFromInitListExpr(S)); StmtQueueAction StmtQueue(*this); // All we need are the default actions. FIXME: use a helper function. - for (Stmt::child_range range = S->children(); range; ++range) { - StmtQueue.queue(*range); + for (Stmt *SubStmt : S->children()) { + StmtQueue.queue(SubStmt); } return true; } diff --git a/include/clang/AST/EvaluatedExprVisitor.h b/include/clang/AST/EvaluatedExprVisitor.h index 5cae5d9eca..ad5287314d 100644 --- a/include/clang/AST/EvaluatedExprVisitor.h +++ b/include/clang/AST/EvaluatedExprVisitor.h @@ -98,9 +98,9 @@ public: /// \brief The basis case walks all of the children of the statement or /// expression, assuming they are all potentially evaluated. void VisitStmt(PTR(Stmt) S) { - for (auto C = S->children(); C; ++C) - if (*C) - this->Visit(*C); + for (auto *SubStmt : S->children()) + if (SubStmt) + this->Visit(SubStmt); } #undef PTR diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index a99587b5a8..b118503b67 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -1881,8 +1881,8 @@ DEF_TRAVERSE_DECL(ParmVarDecl, { bool RecursiveASTVisitor::Traverse##STMT(STMT *S) { \ TRY_TO(WalkUpFrom##STMT(S)); \ { CODE; } \ - for (Stmt::child_range range = S->children(); range; ++range) { \ - TRY_TO(TraverseStmt(*range)); \ + for (Stmt *SubStmt : S->children()) { \ + TRY_TO(TraverseStmt(SubStmt)); \ } \ return true; \ } @@ -2038,15 +2038,15 @@ bool RecursiveASTVisitor::TraverseInitListExpr(InitListExpr *S) { if (Syn) { TRY_TO(WalkUpFromInitListExpr(Syn)); // All we need are the default actions. FIXME: use a helper function. - for (Stmt::child_range range = Syn->children(); range; ++range) { - TRY_TO(TraverseStmt(*range)); + for (Stmt *SubStmt : Syn->children()) { + TRY_TO(TraverseStmt(SubStmt)); } } InitListExpr *Sem = S->isSemanticForm() ? S : S->getSemanticForm(); if (Sem) { TRY_TO(WalkUpFromInitListExpr(Sem)); - for (Stmt::child_range range = Sem->children(); range; ++range) { - TRY_TO(TraverseStmt(*range)); + for (Stmt *SubStmt : Sem->children()) { + TRY_TO(TraverseStmt(SubStmt)); } } return true; diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h index 6a42df20d1..e7ec1f497b 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h @@ -28,10 +28,9 @@ template bool containsStmt(const Stmt *S) { if (isa(S)) return true; - for (Stmt::const_child_range I = S->children(); I; ++I) - if (const Stmt *child = *I) - if (containsStmt(child)) - return true; + for (const Stmt *Child : S->children()) + if (Child && containsStmt(Child)) + return true; return false; } diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 8c2e0f4de8..b61a421ce4 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -355,8 +355,8 @@ public: bool TraverseObjCMessageExpr(ObjCMessageExpr *E) { // Do depth first; we want to rewrite the subexpressions first so that if // we have to move expressions we will move them already rewritten. - for (Stmt::child_range range = E->children(); range; ++range) - if (!TraverseStmt(*range)) + for (Stmt *SubStmt : E->children()) + if (!TraverseStmt(SubStmt)) return false; return WalkUpFromObjCMessageExpr(E); diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 61d52f1baf..90da416719 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -1599,8 +1599,8 @@ void ASTDumper::dumpStmt(const Stmt *S) { ConstStmtVisitor::Visit(S); - for (Stmt::const_child_range CI = S->children(); CI; ++CI) - dumpStmt(*CI); + for (const Stmt *SubStmt : S->children()) + dumpStmt(SubStmt); }); } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 36f4139f83..87f9ffba78 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -3154,10 +3154,10 @@ bool Expr::HasSideEffects(const ASTContext &Ctx, } // Recurse to children. - for (const_child_range SubStmts = children(); SubStmts; ++SubStmts) - if (const Stmt *S = *SubStmts) - if (cast(S)->HasSideEffects(Ctx, IncludePossibleEffects)) - return true; + for (const Stmt *SubStmt : children()) + if (SubStmt && + cast(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects)) + return true; return false; } diff --git a/lib/AST/ParentMap.cpp b/lib/AST/ParentMap.cpp index a991302a25..d7d5f9c692 100644 --- a/lib/AST/ParentMap.cpp +++ b/lib/AST/ParentMap.cpp @@ -36,8 +36,8 @@ static void BuildParentMap(MapTy& M, Stmt* S, // If we are rebuilding the map, clear out any existing state. if (M[POE->getSyntacticForm()]) - for (Stmt::child_range I = S->children(); I; ++I) - M[*I] = nullptr; + for (Stmt *SubStmt : S->children()) + M[SubStmt] = nullptr; M[POE->getSyntacticForm()] = S; BuildParentMap(M, POE->getSyntacticForm(), OV_Transparent); @@ -82,10 +82,10 @@ static void BuildParentMap(MapTy& M, Stmt* S, break; } default: - for (Stmt::child_range I = S->children(); I; ++I) { - if (*I) { - M[*I] = S; - BuildParentMap(M, *I, OVMode); + for (Stmt *SubStmt : S->children()) { + if (SubStmt) { + M[SubStmt] = S; + BuildParentMap(M, SubStmt, OVMode); } } break; diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 63f432ca4c..da996920c4 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -69,9 +69,9 @@ namespace { void StmtProfiler::VisitStmt(const Stmt *S) { ID.AddInteger(S->getStmtClass()); - for (Stmt::const_child_range C = S->children(); C; ++C) { - if (*C) - Visit(*C); + for (const Stmt *SubStmt : S->children()) { + if (SubStmt) + Visit(SubStmt); else ID.AddInteger(0); } diff --git a/lib/Analysis/AnalysisDeclContext.cpp b/lib/Analysis/AnalysisDeclContext.cpp index 4e623c8d6c..d7fb7e95d7 100644 --- a/lib/Analysis/AnalysisDeclContext.cpp +++ b/lib/Analysis/AnalysisDeclContext.cpp @@ -472,9 +472,9 @@ public: : BEVals(bevals), BC(bc) {} void VisitStmt(Stmt *S) { - for (Stmt::child_range I = S->children(); I; ++I) - if (Stmt *child = *I) - Visit(child); + for (Stmt *Child : S->children()) + if (Child) + Visit(Child); } void VisitDeclRefExpr(DeclRefExpr *DR) { diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 19b3f5a476..54d15bd232 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -270,9 +270,8 @@ reverse_children::reverse_children(Stmt *S) { } // Default case for all other statements. - for (Stmt::child_range I = S->children(); I; ++I) { - childrenBuf.push_back(*I); - } + for (Stmt *SubStmt : S->children()) + childrenBuf.push_back(SubStmt); // This needs to be done *after* childrenBuf has been populated. children = childrenBuf; @@ -3641,11 +3640,11 @@ CFGBlock *CFGBuilder::VisitChildrenForTemporaryDtors(Stmt *E, // bottom-up, this means we visit them in their natural order, which // reverses them in the CFG. CFGBlock *B = Block; - for (Stmt::child_range I = E->children(); I; ++I) { - if (Stmt *Child = *I) + for (Stmt *Child : E->children()) + if (Child) if (CFGBlock *R = VisitForTemporaryDtors(Child, false, Context)) B = R; - } + return B; } diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index 91a8492eaa..d06603469d 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -83,9 +83,9 @@ public: } void VisitChildren(Stmt *S) { - for (Stmt::child_range I = S->children(); I; ++I) - if (*I) - static_cast(this)->Visit(*I); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + this->Visit(SubStmt); } }; diff --git a/lib/Analysis/PseudoConstantAnalysis.cpp b/lib/Analysis/PseudoConstantAnalysis.cpp index 3f96ca877f..5b917a7a27 100644 --- a/lib/Analysis/PseudoConstantAnalysis.cpp +++ b/lib/Analysis/PseudoConstantAnalysis.cpp @@ -220,8 +220,8 @@ void PseudoConstantAnalysis::RunAnalysis() { } // switch (head->getStmtClass()) // Add all substatements to the worklist - for (Stmt::const_child_range I = Head->children(); I; ++I) - if (*I) - WorkList.push_back(*I); + for (const Stmt *SubStmt : Head->children()) + if (SubStmt) + WorkList.push_back(SubStmt); } // while (!WorkList.empty()) } diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 07dbce4252..839c2e474c 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -579,9 +579,9 @@ static bool isAccessedBy(const VarDecl &var, const Stmt *s) { } } - for (Stmt::const_child_range children = s->children(); children; ++children) - // children might be null; as in missing decl or conditional of an if-stmt. - if ((*children) && isAccessedBy(var, *children)) + for (const Stmt *SubStmt : s->children()) + // SubStmt might be null; as in missing decl or conditional of an if-stmt. + if (SubStmt && isAccessedBy(var, SubStmt)) return true; return false; @@ -1074,8 +1074,8 @@ static bool isCapturedBy(const VarDecl &var, const Expr *e) { return false; } - for (Stmt::const_child_range children = e->children(); children; ++children) - if (isCapturedBy(var, cast(*children))) + for (const Stmt *SubStmt : e->children()) + if (isCapturedBy(var, cast(SubStmt))) return true; return false; diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index b297e2d10c..de86d76ba2 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -1266,12 +1266,13 @@ CodeGenFunction::EmitSections(const OMPExecutableDirective &S) { CGF.EmitLoadOfLValue(IV, S.getLocStart()).getScalarVal(), ExitBB, CS->size()); unsigned CaseNumber = 0; - for (auto C = CS->children(); C; ++C, ++CaseNumber) { + for (auto *SubStmt : CS->children()) { auto CaseBB = CGF.createBasicBlock(".omp.sections.case"); CGF.EmitBlock(CaseBB); SwitchStmt->addCase(CGF.Builder.getInt32(CaseNumber), CaseBB); - CGF.EmitStmt(*C); + CGF.EmitStmt(SubStmt); CGF.EmitBranch(ExitBB); + ++CaseNumber; } CGF.EmitBlock(ExitBB, /*IsFinished=*/true); }; diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index bece41e9ec..f1fc8c45f1 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -970,8 +970,8 @@ bool CodeGenFunction::ContainsLabel(const Stmt *S, bool IgnoreCaseStmts) { IgnoreCaseStmts = true; // Scan subexpressions for verboten labels. - for (Stmt::const_child_range I = S->children(); I; ++I) - if (ContainsLabel(*I, IgnoreCaseStmts)) + for (const Stmt *SubStmt : S->children()) + if (ContainsLabel(SubStmt, IgnoreCaseStmts)) return true; return false; @@ -994,8 +994,8 @@ bool CodeGenFunction::containsBreak(const Stmt *S) { return true; // Scan subexpressions for verboten breaks. - for (Stmt::const_child_range I = S->children(); I; ++I) - if (containsBreak(*I)) + for (const Stmt *SubStmt : S->children()) + if (containsBreak(SubStmt)) return true; return false; diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index f182a469b3..8dffefc871 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -275,10 +275,9 @@ struct ComputeRegionCounts : public ConstStmtVisitor { void VisitStmt(const Stmt *S) { RecordStmtCount(S); - for (Stmt::const_child_range I = S->children(); I; ++I) { - if (*I) - this->Visit(*I); - } + for (const Stmt *Child : S->children()) + if (Child) + this->Visit(Child); } void VisitFunctionDecl(const FunctionDecl *D) { diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index 2467143faf..eca91590e6 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -582,10 +582,9 @@ struct CounterCoverageMappingBuilder void VisitStmt(const Stmt *S) { if (!S->getLocStart().isInvalid()) extendRegion(S); - for (Stmt::const_child_range I = S->children(); I; ++I) { - if (*I) - this->Visit(*I); - } + for (const Stmt *Child : S->children()) + if (Child) + this->Visit(Child); handleFileExit(getEnd(S)); } diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index e13cdb3a3e..2902ba78c4 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -1932,9 +1932,9 @@ Stmt *RewriteModernObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) void RewriteModernObjC::WarnAboutReturnGotoStmts(Stmt *S) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) - WarnAboutReturnGotoStmts(*CI); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + WarnAboutReturnGotoStmts(SubStmt); if (isa(S) || isa(S)) { Diags.Report(Context->getFullLoc(S->getLocStart()), @@ -4549,12 +4549,12 @@ void RewriteModernObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { } void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast(*CI)) + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast(SubStmt)) GetBlockDeclRefExprs(CBE->getBody()); else - GetBlockDeclRefExprs(*CI); + GetBlockDeclRefExprs(SubStmt); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast(S)) @@ -4569,19 +4569,16 @@ void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, SmallVectorImpl &InnerBlockDeclRefs, llvm::SmallPtrSetImpl &InnerContexts) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast(*CI)) { + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast(SubStmt)) { InnerContexts.insert(cast(CBE->getBlockDecl())); GetInnerBlockDeclRefExprs(CBE->getBody(), InnerBlockDeclRefs, InnerContexts); } else - GetInnerBlockDeclRefExprs(*CI, - InnerBlockDeclRefs, - InnerContexts); - + GetInnerBlockDeclRefExprs(SubStmt, InnerBlockDeclRefs, InnerContexts); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast(S)) { @@ -5564,12 +5561,11 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { SourceRange OrigStmtRange = S->getSourceRange(); // Perform a bottom up rewrite of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - Stmt *childStmt = (*CI); + for (Stmt *&childStmt : S->children()) + if (childStmt) { Stmt *newStmt = RewriteFunctionBodyOrGlobalInitializer(childStmt); if (newStmt) { - *CI = newStmt; + childStmt = newStmt; } } diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index b2a45b407b..204820b304 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -1712,9 +1712,9 @@ Stmt *RewriteObjC::RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S) { void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) - WarnAboutReturnGotoStmts(*CI); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + WarnAboutReturnGotoStmts(SubStmt); if (isa(S) || isa(S)) { Diags.Report(Context->getFullLoc(S->getLocStart()), @@ -1726,9 +1726,9 @@ void RewriteObjC::WarnAboutReturnGotoStmts(Stmt *S) void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) - HasReturnStmts(*CI, hasReturns); + for (Stmt *SubStmt : S->children()) + if (SubStmt) + HasReturnStmts(SubStmt, hasReturns); if (isa(S)) hasReturns = true; @@ -1737,9 +1737,9 @@ void RewriteObjC::HasReturnStmts(Stmt *S, bool &hasReturns) void RewriteObjC::RewriteTryReturnStmts(Stmt *S) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - RewriteTryReturnStmts(*CI); + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + RewriteTryReturnStmts(SubStmt); } if (isa(S)) { SourceLocation startLoc = S->getLocStart(); @@ -1760,9 +1760,9 @@ void RewriteObjC::RewriteTryReturnStmts(Stmt *S) { void RewriteObjC::RewriteSyncReturnStmts(Stmt *S, std::string syncExitBuf) { // Perform a bottom up traversal of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - RewriteSyncReturnStmts(*CI, syncExitBuf); + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + RewriteSyncReturnStmts(SubStmt, syncExitBuf); } if (isa(S)) { SourceLocation startLoc = S->getLocStart(); @@ -3663,12 +3663,12 @@ void RewriteObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { } void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast(*CI)) + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast(SubStmt)) GetBlockDeclRefExprs(CBE->getBody()); else - GetBlockDeclRefExprs(*CI); + GetBlockDeclRefExprs(SubStmt); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast(S)) @@ -3683,19 +3683,16 @@ void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) { void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, SmallVectorImpl &InnerBlockDeclRefs, llvm::SmallPtrSetImpl &InnerContexts) { - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - if (BlockExpr *CBE = dyn_cast(*CI)) { + for (Stmt *SubStmt : S->children()) + if (SubStmt) { + if (BlockExpr *CBE = dyn_cast(SubStmt)) { InnerContexts.insert(cast(CBE->getBlockDecl())); GetInnerBlockDeclRefExprs(CBE->getBody(), InnerBlockDeclRefs, InnerContexts); } else - GetInnerBlockDeclRefExprs(*CI, - InnerBlockDeclRefs, - InnerContexts); - + GetInnerBlockDeclRefExprs(SubStmt, InnerBlockDeclRefs, InnerContexts); } // Handle specific things. if (DeclRefExpr *DRE = dyn_cast(S)) { @@ -4611,12 +4608,11 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { SourceRange OrigStmtRange = S->getSourceRange(); // Perform a bottom up rewrite of all children. - for (Stmt::child_range CI = S->children(); CI; ++CI) - if (*CI) { - Stmt *childStmt = (*CI); + for (Stmt *&childStmt : S->children()) + if (childStmt) { Stmt *newStmt = RewriteFunctionBodyOrGlobalInitializer(childStmt); if (newStmt) { - *CI = newStmt; + childStmt = newStmt; } } diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 36030b99a3..f2ff48ad69 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -130,11 +130,10 @@ public: return true; // Recurse to children. - for (ConstStmtRange SubStmts = E->children(); SubStmts; ++SubStmts) - if (*SubStmts) - if (const Expr *SubExpr = dyn_cast(*SubStmts)) - if (HasMacroID(SubExpr)) - return true; + for (const Stmt *SubStmt : E->children()) + if (const Expr *SubExpr = dyn_cast_or_null(SubStmt)) + if (HasMacroID(SubExpr)) + return true; return false; } diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 6b9eb2a4ed..775fe85740 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -372,13 +372,12 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned &origParentScope) break; } - for (Stmt::child_range CI = S->children(); CI; ++CI) { + for (Stmt *SubStmt : S->children()) { if (SkipFirstSubStmt) { SkipFirstSubStmt = false; continue; } - Stmt *SubStmt = *CI; if (!SubStmt) continue; // Cases, labels, and defaults aren't "scope parents". It's also diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 5737e8338f..bdfff80c7f 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -7240,8 +7240,8 @@ void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) { CC = E->getExprLoc(); BinaryOperator *BO = dyn_cast(E); bool IsLogicalAndOperator = BO && BO->getOpcode() == BO_LAnd; - for (Stmt::child_range I = E->children(); I; ++I) { - Expr *ChildExpr = dyn_cast_or_null(*I); + for (Stmt *SubStmt : E->children()) { + Expr *ChildExpr = dyn_cast_or_null(SubStmt); if (!ChildExpr) continue; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 672fc894f1..0d7cbf45e5 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -73,8 +73,8 @@ namespace { /// VisitExpr - Visit all of the children of this expression. bool CheckDefaultArgumentVisitor::VisitExpr(Expr *Node) { bool IsInvalid = false; - for (Stmt::child_range I = Node->children(); I; ++I) - IsInvalid |= Visit(*I); + for (Stmt *SubStmt : Node->children()) + IsInvalid |= Visit(SubStmt); return IsInvalid; } @@ -1091,9 +1091,9 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S, break; if (!Cxx1yLoc.isValid()) Cxx1yLoc = S->getLocStart(); - for (Stmt::child_range Children = S->children(); Children; ++Children) - if (*Children && - !CheckConstexprFunctionStmt(SemaRef, Dcl, *Children, ReturnStmts, + for (Stmt *SubStmt : S->children()) + if (SubStmt && + !CheckConstexprFunctionStmt(SemaRef, Dcl, SubStmt, ReturnStmts, Cxx1yLoc)) return false; return true; @@ -1106,9 +1106,9 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S, // mutation, we can reasonably allow them in C++11 as an extension. if (!Cxx1yLoc.isValid()) Cxx1yLoc = S->getLocStart(); - for (Stmt::child_range Children = S->children(); Children; ++Children) - if (*Children && - !CheckConstexprFunctionStmt(SemaRef, Dcl, *Children, ReturnStmts, + for (Stmt *SubStmt : S->children()) + if (SubStmt && + !CheckConstexprFunctionStmt(SemaRef, Dcl, SubStmt, ReturnStmts, Cxx1yLoc)) return false; return true; @@ -12887,8 +12887,7 @@ void Sema::SetDeclDefaulted(Decl *Dcl, SourceLocation DefaultLoc) { } static void SearchForReturnInStmt(Sema &Self, Stmt *S) { - for (Stmt::child_range CI = S->children(); CI; ++CI) { - Stmt *SubStmt = *CI; + for (Stmt *SubStmt : S->children()) { if (!SubStmt) continue; if (isa(SubStmt)) diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index f3bcf76a21..2e3e63e00a 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -837,11 +837,13 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, New->getLocation()); } -static CanThrowResult canSubExprsThrow(Sema &S, const Expr *CE) { - Expr *E = const_cast(CE); +static CanThrowResult canSubExprsThrow(Sema &S, const Expr *E) { CanThrowResult R = CT_Cannot; - for (Expr::child_range I = E->children(); I && R != CT_Can; ++I) - R = mergeCanThrow(R, S.canThrow(cast(*I))); + for (const Stmt *SubStmt : E->children()) { + R = mergeCanThrow(R, S.canThrow(cast(SubStmt))); + if (R == CT_Can) + break; + } return R; } diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 7286301fe6..867cb9f3c8 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -3344,8 +3344,7 @@ StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef Clauses, return StmtError(); // All associated statements must be '#pragma omp section' except for // the first one. - for (++S; S; ++S) { - auto SectionStmt = *S; + for (Stmt *SectionStmt : ++S) { if (!SectionStmt || !isa(SectionStmt)) { if (SectionStmt) Diag(SectionStmt->getLocStart(), @@ -3503,8 +3502,7 @@ Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef Clauses, return StmtError(); // All associated statements must be '#pragma omp section' except for // the first one. - for (++S; S; ++S) { - auto SectionStmt = *S; + for (Stmt *SectionStmt : ++S) { if (!SectionStmt || !isa(SectionStmt)) { if (SectionStmt) Diag(SectionStmt->getLocStart(), diff --git a/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp b/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp index 0bcebf6e77..a71def23c0 100644 --- a/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp +++ b/lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp @@ -78,9 +78,9 @@ class DirectIvarAssignment : void VisitBinaryOperator(const BinaryOperator *BO); void VisitChildren(const Stmt *S) { - for (Stmt::const_child_range I = S->children(); I; ++I) - if (*I) - this->Visit(*I); + for (const Stmt *Child : S->children()) + if (Child) + this->Visit(Child); } }; diff --git a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index 02c12095b5..3df5fa034a 100644 --- a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -167,9 +167,9 @@ class IvarInvalidationCheckerImpl { void VisitObjCMessageExpr(const ObjCMessageExpr *ME); void VisitChildren(const Stmt *S) { - for (Stmt::const_child_range I = S->children(); I; ++I) { - if (*I) - this->Visit(*I); + for (const Stmt *Child : S->children()) { + if (Child) + this->Visit(Child); if (CalledAnotherInvalidationMethod) return; } diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 09edc8d2e7..bf5b58253a 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1937,8 +1937,8 @@ void EnqueueVisitor::AddTypeLoc(TypeSourceInfo *TI) { } void EnqueueVisitor::EnqueueChildren(const Stmt *S) { unsigned size = WL.size(); - for (Stmt::const_child_range Child = S->children(); Child; ++Child) { - AddStmt(*Child); + for (const Stmt *SubStmt : S->children()) { + AddStmt(SubStmt); } if (size == WL.size()) return;