Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit bcbb92d

Browse files
committed
[C++11] Replacing CompoundStmt iterators body_begin() and body_end() with iterator_range body(). Updating all of the usages of the iterators with range-based for loops.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204040 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e5e230f commit bcbb92d

File tree

12 files changed

+39
-47
lines changed

12 files changed

+39
-47
lines changed

Diff for: include/clang/AST/Stmt.h

+8
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ class CompoundStmt : public Stmt {
571571
unsigned size() const { return CompoundStmtBits.NumStmts; }
572572

573573
typedef Stmt** body_iterator;
574+
typedef llvm::iterator_range<body_iterator> body_range;
575+
576+
body_range body() { return body_range(body_begin(), body_end()); }
574577
body_iterator body_begin() { return Body; }
575578
body_iterator body_end() { return Body + size(); }
576579
Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
@@ -581,6 +584,11 @@ class CompoundStmt : public Stmt {
581584
}
582585

583586
typedef Stmt* const * const_body_iterator;
587+
typedef llvm::iterator_range<const_body_iterator> body_const_range;
588+
589+
body_const_range body() const {
590+
return body_const_range(body_begin(), body_end());
591+
}
584592
const_body_iterator body_begin() const { return Body; }
585593
const_body_iterator body_end() const { return Body + size(); }
586594
const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }

Diff for: lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ class EmptyChecker : public StmtVisitor<EmptyChecker, bool> {
8989
bool VisitCompoundStmt(CompoundStmt *S) {
9090
if (S->body_empty())
9191
return false; // was already empty, not because of transformations.
92-
for (CompoundStmt::body_iterator
93-
I = S->body_begin(), E = S->body_end(); I != E; ++I)
94-
if (!Visit(*I))
92+
for (auto *I : S->body())
93+
if (!Visit(I))
9594
return false;
9695
return true;
9796
}
@@ -167,9 +166,8 @@ class EmptyStatementsRemover :
167166
}
168167

169168
bool VisitCompoundStmt(CompoundStmt *S) {
170-
for (CompoundStmt::body_iterator
171-
I = S->body_begin(), E = S->body_end(); I != E; ++I)
172-
check(*I);
169+
for (auto *I : S->body())
170+
check(I);
173171
return true;
174172
}
175173

@@ -189,9 +187,8 @@ class EmptyStatementsRemover :
189187

190188
static bool isBodyEmpty(CompoundStmt *body, ASTContext &Ctx,
191189
std::vector<SourceLocation> &MacroLocs) {
192-
for (CompoundStmt::body_iterator
193-
I = body->body_begin(), E = body->body_end(); I != E; ++I)
194-
if (!EmptyChecker(Ctx, MacroLocs).Visit(*I))
190+
for (auto *I : body->body())
191+
if (!EmptyChecker(Ctx, MacroLocs).Visit(I))
195192
return false;
196193

197194
return true;

Diff for: lib/ARCMigrate/Transforms.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,8 @@ class RemovablesCollector : public RecursiveASTVisitor<RemovablesCollector> {
264264
}
265265

266266
bool VisitCompoundStmt(CompoundStmt *S) {
267-
for (CompoundStmt::body_iterator
268-
I = S->body_begin(), E = S->body_end(); I != E; ++I)
269-
mark(*I);
267+
for (auto *I : S->body())
268+
mark(I);
270269
return true;
271270
}
272271

Diff for: lib/AST/ExprConstant.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3341,9 +3341,8 @@ static EvalStmtResult EvaluateStmt(APValue &Result, EvalInfo &Info,
33413341
BlockScopeRAII Scope(Info);
33423342

33433343
const CompoundStmt *CS = cast<CompoundStmt>(S);
3344-
for (CompoundStmt::const_body_iterator BI = CS->body_begin(),
3345-
BE = CS->body_end(); BI != BE; ++BI) {
3346-
EvalStmtResult ESR = EvaluateStmt(Result, Info, *BI, Case);
3344+
for (const auto *BI : CS->body()) {
3345+
EvalStmtResult ESR = EvaluateStmt(Result, Info, BI, Case);
33473346
if (ESR == ESR_Succeeded)
33483347
Case = 0;
33493348
else if (ESR != ESR_CaseNotFound)

Diff for: lib/AST/StmtPrinter.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ namespace {
114114
/// with no newline after the }.
115115
void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) {
116116
OS << "{\n";
117-
for (CompoundStmt::body_iterator I = Node->body_begin(), E = Node->body_end();
118-
I != E; ++I)
119-
PrintStmt(*I);
117+
for (auto *I : Node->body())
118+
PrintStmt(I);
120119

121120
Indent() << "}";
122121
}

Diff for: lib/Analysis/CFG.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,8 @@ void CFGBuilder::addLocalScopeForStmt(Stmt *S) {
939939

940940
// For compound statement we will be creating explicit scope.
941941
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(S)) {
942-
for (CompoundStmt::body_iterator BI = CS->body_begin(), BE = CS->body_end()
943-
; BI != BE; ++BI) {
944-
Stmt *SI = (*BI)->stripLabelLikeStatements();
942+
for (auto *BI : CS->body()) {
943+
Stmt *SI = BI->stripLabelLikeStatements();
945944
if (DeclStmt *DS = dyn_cast<DeclStmt>(SI))
946945
Scope = addLocalScopeForDeclStmt(DS, Scope);
947946
}

Diff for: lib/CodeGen/CGClass.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,8 @@ void CodeGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
13511351
LexicalScope Scope(*this, RootCS->getSourceRange());
13521352

13531353
AssignmentMemcpyizer AM(*this, AssignOp, Args);
1354-
for (CompoundStmt::const_body_iterator I = RootCS->body_begin(),
1355-
E = RootCS->body_end();
1356-
I != E; ++I) {
1357-
AM.emitAssignment(*I);
1358-
}
1354+
for (auto *I : RootCS->body())
1355+
AM.emitAssignment(I);
13591356
AM.finish();
13601357
}
13611358

Diff for: lib/CodeGen/CGDecl.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,12 @@ static bool isCapturedBy(const VarDecl &var, const Expr *e) {
10031003

10041004
if (const StmtExpr *SE = dyn_cast<StmtExpr>(e)) {
10051005
const CompoundStmt *CS = SE->getSubStmt();
1006-
for (CompoundStmt::const_body_iterator BI = CS->body_begin(),
1007-
BE = CS->body_end(); BI != BE; ++BI)
1008-
if (Expr *E = dyn_cast<Expr>((*BI))) {
1006+
for (const auto *BI : CS->body())
1007+
if (const auto *E = dyn_cast<Expr>(BI)) {
10091008
if (isCapturedBy(var, E))
10101009
return true;
10111010
}
1012-
else if (DeclStmt *DS = dyn_cast<DeclStmt>((*BI))) {
1011+
else if (const auto *DS = dyn_cast<DeclStmt>(BI)) {
10131012
// special case declarations
10141013
for (const auto *I : DS->decls()) {
10151014
if (const auto *VD = dyn_cast<VarDecl>((I))) {

Diff for: lib/CodeGen/CGObjC.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -2834,9 +2834,8 @@ void CodeGenFunction::EmitObjCAutoreleasePoolStmt(
28342834
EHStack.pushCleanup<CallObjCMRRAutoreleasePoolObject>(NormalCleanup, token);
28352835
}
28362836

2837-
for (CompoundStmt::const_body_iterator I = S.body_begin(),
2838-
E = S.body_end(); I != E; ++I)
2839-
EmitStmt(*I);
2837+
for (const auto *I : S.body())
2838+
EmitStmt(I);
28402839

28412840
if (DI)
28422841
DI->EmitLexicalBlockEnd(Builder, S.getRBracLoc());

Diff for: lib/Sema/SemaDeclCXX.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,8 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *S,
997997
Cxx1yLoc = S->getLocStart();
998998

999999
CompoundStmt *CompStmt = cast<CompoundStmt>(S);
1000-
for (CompoundStmt::body_iterator BodyIt = CompStmt->body_begin(),
1001-
BodyEnd = CompStmt->body_end(); BodyIt != BodyEnd; ++BodyIt) {
1002-
if (!CheckConstexprFunctionStmt(SemaRef, Dcl, *BodyIt, ReturnStmts,
1000+
for (auto *BodyIt : CompStmt->body()) {
1001+
if (!CheckConstexprFunctionStmt(SemaRef, Dcl, BodyIt, ReturnStmts,
10031002
Cxx1yLoc))
10041003
return false;
10051004
}
@@ -1101,9 +1100,8 @@ bool Sema::CheckConstexprFunctionBody(const FunctionDecl *Dcl, Stmt *Body) {
11011100
// [... list of cases ...]
11021101
CompoundStmt *CompBody = cast<CompoundStmt>(Body);
11031102
SourceLocation Cxx1yLoc;
1104-
for (CompoundStmt::body_iterator BodyIt = CompBody->body_begin(),
1105-
BodyEnd = CompBody->body_end(); BodyIt != BodyEnd; ++BodyIt) {
1106-
if (!CheckConstexprFunctionStmt(*this, Dcl, *BodyIt, ReturnStmts, Cxx1yLoc))
1103+
for (auto *BodyIt : CompBody->body()) {
1104+
if (!CheckConstexprFunctionStmt(*this, Dcl, BodyIt, ReturnStmts, Cxx1yLoc))
11071105
return false;
11081106
}
11091107

Diff for: lib/Sema/TreeTransform.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -5273,21 +5273,20 @@ TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
52735273
bool SubStmtInvalid = false;
52745274
bool SubStmtChanged = false;
52755275
SmallVector<Stmt*, 8> Statements;
5276-
for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5277-
B != BEnd; ++B) {
5278-
StmtResult Result = getDerived().TransformStmt(*B);
5276+
for (auto *B : S->body()) {
5277+
StmtResult Result = getDerived().TransformStmt(B);
52795278
if (Result.isInvalid()) {
52805279
// Immediately fail if this was a DeclStmt, since it's very
52815280
// likely that this will cause problems for future statements.
5282-
if (isa<DeclStmt>(*B))
5281+
if (isa<DeclStmt>(B))
52835282
return StmtError();
52845283

52855284
// Otherwise, just keep processing substatements and fail later.
52865285
SubStmtInvalid = true;
52875286
continue;
52885287
}
52895288

5290-
SubStmtChanged = SubStmtChanged || Result.get() != *B;
5289+
SubStmtChanged = SubStmtChanged || Result.get() != B;
52915290
Statements.push_back(Result.takeAs<Stmt>());
52925291
}
52935292

Diff for: lib/Serialization/ASTWriterStmt.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ void ASTStmtWriter::VisitNullStmt(NullStmt *S) {
7171
void ASTStmtWriter::VisitCompoundStmt(CompoundStmt *S) {
7272
VisitStmt(S);
7373
Record.push_back(S->size());
74-
for (CompoundStmt::body_iterator CS = S->body_begin(), CSEnd = S->body_end();
75-
CS != CSEnd; ++CS)
76-
Writer.AddStmt(*CS);
74+
for (auto *CS : S->body())
75+
Writer.AddStmt(CS);
7776
Writer.AddSourceLocation(S->getLBracLoc(), Record);
7877
Writer.AddSourceLocation(S->getRBracLoc(), Record);
7978
Code = serialization::STMT_COMPOUND;

0 commit comments

Comments
 (0)