Skip to content

Commit 668cbd8

Browse files
[Frontend] Use range-based for loops (NFC) (#107757)
1 parent 0078d4b commit 668cbd8

File tree

1 file changed

+48
-60
lines changed

1 file changed

+48
-60
lines changed

clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,19 +4080,17 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
40804080

40814081
// Create local declarations to avoid rewriting all closure decl ref exprs.
40824082
// First, emit a declaration for all "by ref" decls.
4083-
for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
4084-
++I) {
4083+
for (ValueDecl *VD : BlockByRefDecls) {
40854084
S += " ";
4086-
std::string Name = (*I)->getNameAsString();
4085+
std::string Name = VD->getNameAsString();
40874086
std::string TypeString;
4088-
RewriteByRefString(TypeString, Name, (*I));
4087+
RewriteByRefString(TypeString, Name, VD);
40894088
TypeString += " *";
40904089
Name = TypeString + Name;
4091-
S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n";
4090+
S += Name + " = __cself->" + VD->getNameAsString() + "; // bound by ref\n";
40924091
}
40934092
// Next, emit a declaration for all "by copy" declarations.
4094-
for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
4095-
++I) {
4093+
for (ValueDecl *VD : BlockByCopyDecls) {
40964094
S += " ";
40974095
// Handle nested closure invocation. For example:
40984096
//
@@ -4104,21 +4102,20 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
41044102
// myImportedClosure(); // import and invoke the closure
41054103
// };
41064104
//
4107-
if (isTopLevelBlockPointerType((*I)->getType())) {
4108-
RewriteBlockPointerTypeVariable(S, (*I));
4105+
if (isTopLevelBlockPointerType(VD->getType())) {
4106+
RewriteBlockPointerTypeVariable(S, VD);
41094107
S += " = (";
4110-
RewriteBlockPointerType(S, (*I)->getType());
4108+
RewriteBlockPointerType(S, VD->getType());
41114109
S += ")";
4112-
S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n";
4113-
}
4114-
else {
4115-
std::string Name = (*I)->getNameAsString();
4116-
QualType QT = (*I)->getType();
4117-
if (HasLocalVariableExternalStorage(*I))
4110+
S += "__cself->" + VD->getNameAsString() + "; // bound by copy\n";
4111+
} else {
4112+
std::string Name = VD->getNameAsString();
4113+
QualType QT = VD->getType();
4114+
if (HasLocalVariableExternalStorage(VD))
41184115
QT = Context->getPointerType(QT);
41194116
QT.getAsStringInternal(Name, Context->getPrintingPolicy());
4120-
S += Name + " = __cself->" +
4121-
(*I)->getNameAsString() + "; // bound by copy\n";
4117+
S += Name + " = __cself->" + VD->getNameAsString() +
4118+
"; // bound by copy\n";
41224119
}
41234120
}
41244121
std::string RewrittenStr = RewrittenBlockExprs[CE];
@@ -4188,10 +4185,9 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
41884185

41894186
if (BlockDeclRefs.size()) {
41904187
// Output all "by copy" declarations.
4191-
for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
4192-
++I) {
4188+
for (ValueDecl *VD : BlockByCopyDecls) {
41934189
S += " ";
4194-
std::string FieldName = (*I)->getNameAsString();
4190+
std::string FieldName = VD->getNameAsString();
41954191
std::string ArgName = "_" + FieldName;
41964192
// Handle nested closure invocation. For example:
41974193
//
@@ -4203,12 +4199,12 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
42034199
// myImportedBlock(); // import and invoke the closure
42044200
// };
42054201
//
4206-
if (isTopLevelBlockPointerType((*I)->getType())) {
4202+
if (isTopLevelBlockPointerType(VD->getType())) {
42074203
S += "struct __block_impl *";
42084204
Constructor += ", void *" + ArgName;
42094205
} else {
4210-
QualType QT = (*I)->getType();
4211-
if (HasLocalVariableExternalStorage(*I))
4206+
QualType QT = VD->getType();
4207+
if (HasLocalVariableExternalStorage(VD))
42124208
QT = Context->getPointerType(QT);
42134209
QT.getAsStringInternal(FieldName, Context->getPrintingPolicy());
42144210
QT.getAsStringInternal(ArgName, Context->getPrintingPolicy());
@@ -4217,14 +4213,13 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
42174213
S += FieldName + ";\n";
42184214
}
42194215
// Output all "by ref" declarations.
4220-
for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
4221-
++I) {
4216+
for (ValueDecl *VD : BlockByRefDecls) {
42224217
S += " ";
4223-
std::string FieldName = (*I)->getNameAsString();
4218+
std::string FieldName = VD->getNameAsString();
42244219
std::string ArgName = "_" + FieldName;
42254220
{
42264221
std::string TypeString;
4227-
RewriteByRefString(TypeString, FieldName, (*I));
4222+
RewriteByRefString(TypeString, FieldName, VD);
42284223
TypeString += " *";
42294224
FieldName = TypeString + FieldName;
42304225
ArgName = TypeString + ArgName;
@@ -4236,24 +4231,21 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
42364231
Constructor += ", int flags=0)";
42374232
// Initialize all "by copy" arguments.
42384233
bool firsTime = true;
4239-
for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
4240-
++I) {
4241-
std::string Name = (*I)->getNameAsString();
4242-
if (firsTime) {
4243-
Constructor += " : ";
4244-
firsTime = false;
4245-
}
4246-
else
4247-
Constructor += ", ";
4248-
if (isTopLevelBlockPointerType((*I)->getType()))
4249-
Constructor += Name + "((struct __block_impl *)_" + Name + ")";
4250-
else
4251-
Constructor += Name + "(_" + Name + ")";
4234+
for (const ValueDecl *VD : BlockByCopyDecls) {
4235+
std::string Name = VD->getNameAsString();
4236+
if (firsTime) {
4237+
Constructor += " : ";
4238+
firsTime = false;
4239+
} else
4240+
Constructor += ", ";
4241+
if (isTopLevelBlockPointerType(VD->getType()))
4242+
Constructor += Name + "((struct __block_impl *)_" + Name + ")";
4243+
else
4244+
Constructor += Name + "(_" + Name + ")";
42524245
}
42534246
// Initialize all "by ref" arguments.
4254-
for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
4255-
++I) {
4256-
std::string Name = (*I)->getNameAsString();
4247+
for (const ValueDecl *VD : BlockByRefDecls) {
4248+
std::string Name = VD->getNameAsString();
42574249
if (firsTime) {
42584250
Constructor += " : ";
42594251
firsTime = false;
@@ -5277,47 +5269,43 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
52775269
if (BlockDeclRefs.size()) {
52785270
Expr *Exp;
52795271
// Output all "by copy" declarations.
5280-
for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E;
5281-
++I) {
5282-
if (isObjCType((*I)->getType())) {
5272+
for (ValueDecl *VD : BlockByCopyDecls) {
5273+
if (isObjCType(VD->getType())) {
52835274
// FIXME: Conform to ABI ([[obj retain] autorelease]).
5284-
FD = SynthBlockInitFunctionDecl((*I)->getName());
5275+
FD = SynthBlockInitFunctionDecl(VD->getName());
52855276
Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
52865277
VK_LValue, SourceLocation());
5287-
if (HasLocalVariableExternalStorage(*I)) {
5288-
QualType QT = (*I)->getType();
5278+
if (HasLocalVariableExternalStorage(VD)) {
5279+
QualType QT = VD->getType();
52895280
QT = Context->getPointerType(QT);
52905281
Exp = UnaryOperator::Create(const_cast<ASTContext &>(*Context), Exp,
52915282
UO_AddrOf, QT, VK_PRValue, OK_Ordinary,
52925283
SourceLocation(), false,
52935284
FPOptionsOverride());
52945285
}
5295-
} else if (isTopLevelBlockPointerType((*I)->getType())) {
5296-
FD = SynthBlockInitFunctionDecl((*I)->getName());
5286+
} else if (isTopLevelBlockPointerType(VD->getType())) {
5287+
FD = SynthBlockInitFunctionDecl(VD->getName());
52975288
Arg = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
52985289
VK_LValue, SourceLocation());
52995290
Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy,
53005291
CK_BitCast, Arg);
53015292
} else {
5302-
FD = SynthBlockInitFunctionDecl((*I)->getName());
5293+
FD = SynthBlockInitFunctionDecl(VD->getName());
53035294
Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
53045295
VK_LValue, SourceLocation());
5305-
if (HasLocalVariableExternalStorage(*I)) {
5306-
QualType QT = (*I)->getType();
5296+
if (HasLocalVariableExternalStorage(VD)) {
5297+
QualType QT = VD->getType();
53075298
QT = Context->getPointerType(QT);
53085299
Exp = UnaryOperator::Create(const_cast<ASTContext &>(*Context), Exp,
53095300
UO_AddrOf, QT, VK_PRValue, OK_Ordinary,
53105301
SourceLocation(), false,
53115302
FPOptionsOverride());
53125303
}
5313-
53145304
}
53155305
InitExprs.push_back(Exp);
53165306
}
53175307
// Output all "by ref" declarations.
5318-
for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E;
5319-
++I) {
5320-
ValueDecl *ND = (*I);
5308+
for (ValueDecl *ND : BlockByRefDecls) {
53215309
std::string Name(ND->getNameAsString());
53225310
std::string RecName;
53235311
RewriteByRefString(RecName, Name, ND, true);
@@ -5329,7 +5317,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
53295317
assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl");
53305318
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
53315319

5332-
FD = SynthBlockInitFunctionDecl((*I)->getName());
5320+
FD = SynthBlockInitFunctionDecl(ND->getName());
53335321
Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(),
53345322
VK_LValue, SourceLocation());
53355323
bool isNestedCapturedVar = false;

0 commit comments

Comments
 (0)