@@ -4080,19 +4080,17 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
4080
4080
4081
4081
// Create local declarations to avoid rewriting all closure decl ref exprs.
4082
4082
// 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) {
4085
4084
S += " " ;
4086
- std::string Name = (*I) ->getNameAsString ();
4085
+ std::string Name = VD ->getNameAsString ();
4087
4086
std::string TypeString;
4088
- RewriteByRefString (TypeString, Name, (*I) );
4087
+ RewriteByRefString (TypeString, Name, VD );
4089
4088
TypeString += " *" ;
4090
4089
Name = TypeString + Name;
4091
- S += Name + " = __cself->" + (*I) ->getNameAsString () + " ; // bound by ref\n " ;
4090
+ S += Name + " = __cself->" + VD ->getNameAsString () + " ; // bound by ref\n " ;
4092
4091
}
4093
4092
// 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) {
4096
4094
S += " " ;
4097
4095
// Handle nested closure invocation. For example:
4098
4096
//
@@ -4104,21 +4102,20 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
4104
4102
// myImportedClosure(); // import and invoke the closure
4105
4103
// };
4106
4104
//
4107
- if (isTopLevelBlockPointerType ((*I) ->getType ())) {
4108
- RewriteBlockPointerTypeVariable (S, (*I) );
4105
+ if (isTopLevelBlockPointerType (VD ->getType ())) {
4106
+ RewriteBlockPointerTypeVariable (S, VD );
4109
4107
S += " = (" ;
4110
- RewriteBlockPointerType (S, (*I) ->getType ());
4108
+ RewriteBlockPointerType (S, VD ->getType ());
4111
4109
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))
4118
4115
QT = Context->getPointerType (QT);
4119
4116
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 " ;
4122
4119
}
4123
4120
}
4124
4121
std::string RewrittenStr = RewrittenBlockExprs[CE];
@@ -4188,10 +4185,9 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4188
4185
4189
4186
if (BlockDeclRefs.size ()) {
4190
4187
// Output all "by copy" declarations.
4191
- for (auto I = BlockByCopyDecls.begin (), E = BlockByCopyDecls.end (); I != E;
4192
- ++I) {
4188
+ for (ValueDecl *VD : BlockByCopyDecls) {
4193
4189
S += " " ;
4194
- std::string FieldName = (*I) ->getNameAsString ();
4190
+ std::string FieldName = VD ->getNameAsString ();
4195
4191
std::string ArgName = " _" + FieldName;
4196
4192
// Handle nested closure invocation. For example:
4197
4193
//
@@ -4203,12 +4199,12 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4203
4199
// myImportedBlock(); // import and invoke the closure
4204
4200
// };
4205
4201
//
4206
- if (isTopLevelBlockPointerType ((*I) ->getType ())) {
4202
+ if (isTopLevelBlockPointerType (VD ->getType ())) {
4207
4203
S += " struct __block_impl *" ;
4208
4204
Constructor += " , void *" + ArgName;
4209
4205
} else {
4210
- QualType QT = (*I) ->getType ();
4211
- if (HasLocalVariableExternalStorage (*I ))
4206
+ QualType QT = VD ->getType ();
4207
+ if (HasLocalVariableExternalStorage (VD ))
4212
4208
QT = Context->getPointerType (QT);
4213
4209
QT.getAsStringInternal (FieldName, Context->getPrintingPolicy ());
4214
4210
QT.getAsStringInternal (ArgName, Context->getPrintingPolicy ());
@@ -4217,14 +4213,13 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4217
4213
S += FieldName + " ;\n " ;
4218
4214
}
4219
4215
// Output all "by ref" declarations.
4220
- for (auto I = BlockByRefDecls.begin (), E = BlockByRefDecls.end (); I != E;
4221
- ++I) {
4216
+ for (ValueDecl *VD : BlockByRefDecls) {
4222
4217
S += " " ;
4223
- std::string FieldName = (*I) ->getNameAsString ();
4218
+ std::string FieldName = VD ->getNameAsString ();
4224
4219
std::string ArgName = " _" + FieldName;
4225
4220
{
4226
4221
std::string TypeString;
4227
- RewriteByRefString (TypeString, FieldName, (*I) );
4222
+ RewriteByRefString (TypeString, FieldName, VD );
4228
4223
TypeString += " *" ;
4229
4224
FieldName = TypeString + FieldName;
4230
4225
ArgName = TypeString + ArgName;
@@ -4236,24 +4231,21 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4236
4231
Constructor += " , int flags=0)" ;
4237
4232
// Initialize all "by copy" arguments.
4238
4233
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 + " )" ;
4252
4245
}
4253
4246
// 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 ();
4257
4249
if (firsTime) {
4258
4250
Constructor += " : " ;
4259
4251
firsTime = false ;
@@ -5277,47 +5269,43 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
5277
5269
if (BlockDeclRefs.size ()) {
5278
5270
Expr *Exp;
5279
5271
// 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 ())) {
5283
5274
// FIXME: Conform to ABI ([[obj retain] autorelease]).
5284
- FD = SynthBlockInitFunctionDecl ((*I) ->getName ());
5275
+ FD = SynthBlockInitFunctionDecl (VD ->getName ());
5285
5276
Exp = new (Context) DeclRefExpr (*Context, FD, false , FD->getType (),
5286
5277
VK_LValue, SourceLocation ());
5287
- if (HasLocalVariableExternalStorage (*I )) {
5288
- QualType QT = (*I) ->getType ();
5278
+ if (HasLocalVariableExternalStorage (VD )) {
5279
+ QualType QT = VD ->getType ();
5289
5280
QT = Context->getPointerType (QT);
5290
5281
Exp = UnaryOperator::Create (const_cast <ASTContext &>(*Context), Exp,
5291
5282
UO_AddrOf, QT, VK_PRValue, OK_Ordinary,
5292
5283
SourceLocation (), false ,
5293
5284
FPOptionsOverride ());
5294
5285
}
5295
- } else if (isTopLevelBlockPointerType ((*I) ->getType ())) {
5296
- FD = SynthBlockInitFunctionDecl ((*I) ->getName ());
5286
+ } else if (isTopLevelBlockPointerType (VD ->getType ())) {
5287
+ FD = SynthBlockInitFunctionDecl (VD ->getName ());
5297
5288
Arg = new (Context) DeclRefExpr (*Context, FD, false , FD->getType (),
5298
5289
VK_LValue, SourceLocation ());
5299
5290
Exp = NoTypeInfoCStyleCastExpr (Context, Context->VoidPtrTy ,
5300
5291
CK_BitCast, Arg);
5301
5292
} else {
5302
- FD = SynthBlockInitFunctionDecl ((*I) ->getName ());
5293
+ FD = SynthBlockInitFunctionDecl (VD ->getName ());
5303
5294
Exp = new (Context) DeclRefExpr (*Context, FD, false , FD->getType (),
5304
5295
VK_LValue, SourceLocation ());
5305
- if (HasLocalVariableExternalStorage (*I )) {
5306
- QualType QT = (*I) ->getType ();
5296
+ if (HasLocalVariableExternalStorage (VD )) {
5297
+ QualType QT = VD ->getType ();
5307
5298
QT = Context->getPointerType (QT);
5308
5299
Exp = UnaryOperator::Create (const_cast <ASTContext &>(*Context), Exp,
5309
5300
UO_AddrOf, QT, VK_PRValue, OK_Ordinary,
5310
5301
SourceLocation (), false ,
5311
5302
FPOptionsOverride ());
5312
5303
}
5313
-
5314
5304
}
5315
5305
InitExprs.push_back (Exp);
5316
5306
}
5317
5307
// 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) {
5321
5309
std::string Name (ND->getNameAsString ());
5322
5310
std::string RecName;
5323
5311
RewriteByRefString (RecName, Name, ND, true );
@@ -5329,7 +5317,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
5329
5317
assert (RD && " SynthBlockInitExpr(): Can't find RecordDecl" );
5330
5318
QualType castT = Context->getPointerType (Context->getTagDeclType (RD));
5331
5319
5332
- FD = SynthBlockInitFunctionDecl ((*I) ->getName ());
5320
+ FD = SynthBlockInitFunctionDecl (ND ->getName ());
5333
5321
Exp = new (Context) DeclRefExpr (*Context, FD, false , FD->getType (),
5334
5322
VK_LValue, SourceLocation ());
5335
5323
bool isNestedCapturedVar = false ;
0 commit comments