@@ -138,10 +138,8 @@ namespace {
138
138
SmallVector<DeclRefExpr *, 32 > BlockDeclRefs;
139
139
140
140
// Block related declarations.
141
- SmallVector<ValueDecl *, 8 > BlockByCopyDecls;
142
- llvm::SmallPtrSet<ValueDecl *, 8 > BlockByCopyDeclsPtrSet;
143
- SmallVector<ValueDecl *, 8 > BlockByRefDecls;
144
- llvm::SmallPtrSet<ValueDecl *, 8 > BlockByRefDeclsPtrSet;
141
+ llvm::SmallSetVector<ValueDecl *, 8 > BlockByCopyDecls;
142
+ llvm::SmallSetVector<ValueDecl *, 8 > BlockByRefDecls;
145
143
llvm::DenseMap<ValueDecl *, unsigned > BlockByRefDeclNo;
146
144
llvm::SmallPtrSet<ValueDecl *, 8 > ImportedBlockDecls;
147
145
llvm::SmallPtrSet<VarDecl *, 8 > ImportedLocalExternalDecls;
@@ -4082,8 +4080,8 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
4082
4080
4083
4081
// Create local declarations to avoid rewriting all closure decl ref exprs.
4084
4082
// First, emit a declaration for all "by ref" decls.
4085
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin (),
4086
- E = BlockByRefDecls. end (); I != E; ++I) {
4083
+ for (auto I = BlockByRefDecls.begin (), E = BlockByRefDecls. end (); I != E;
4084
+ ++I) {
4087
4085
S += " " ;
4088
4086
std::string Name = (*I)->getNameAsString ();
4089
4087
std::string TypeString;
@@ -4093,8 +4091,8 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i,
4093
4091
S += Name + " = __cself->" + (*I)->getNameAsString () + " ; // bound by ref\n " ;
4094
4092
}
4095
4093
// Next, emit a declaration for all "by copy" declarations.
4096
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin (),
4097
- E = BlockByCopyDecls. end (); I != E; ++I) {
4094
+ for (auto I = BlockByCopyDecls.begin (), E = BlockByCopyDecls. end (); I != E;
4095
+ ++I) {
4098
4096
S += " " ;
4099
4097
// Handle nested closure invocation. For example:
4100
4098
//
@@ -4146,7 +4144,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
4146
4144
S += VD->getNameAsString ();
4147
4145
S += " , (void*)src->" ;
4148
4146
S += VD->getNameAsString ();
4149
- if (BlockByRefDeclsPtrSet .count (VD))
4147
+ if (BlockByRefDecls .count (VD))
4150
4148
S += " , " + utostr (BLOCK_FIELD_IS_BYREF) + " /*BLOCK_FIELD_IS_BYREF*/);" ;
4151
4149
else if (VD->getType ()->isBlockPointerType ())
4152
4150
S += " , " + utostr (BLOCK_FIELD_IS_BLOCK) + " /*BLOCK_FIELD_IS_BLOCK*/);" ;
@@ -4163,7 +4161,7 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(
4163
4161
for (ValueDecl *VD : ImportedBlockDecls) {
4164
4162
S += " _Block_object_dispose((void*)src->" ;
4165
4163
S += VD->getNameAsString ();
4166
- if (BlockByRefDeclsPtrSet .count (VD))
4164
+ if (BlockByRefDecls .count (VD))
4167
4165
S += " , " + utostr (BLOCK_FIELD_IS_BYREF) + " /*BLOCK_FIELD_IS_BYREF*/);" ;
4168
4166
else if (VD->getType ()->isBlockPointerType ())
4169
4167
S += " , " + utostr (BLOCK_FIELD_IS_BLOCK) + " /*BLOCK_FIELD_IS_BLOCK*/);" ;
@@ -4190,8 +4188,8 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4190
4188
4191
4189
if (BlockDeclRefs.size ()) {
4192
4190
// Output all "by copy" declarations.
4193
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin (),
4194
- E = BlockByCopyDecls. end (); I != E; ++I) {
4191
+ for (auto I = BlockByCopyDecls.begin (), E = BlockByCopyDecls. end (); I != E;
4192
+ ++I) {
4195
4193
S += " " ;
4196
4194
std::string FieldName = (*I)->getNameAsString ();
4197
4195
std::string ArgName = " _" + FieldName;
@@ -4219,8 +4217,8 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4219
4217
S += FieldName + " ;\n " ;
4220
4218
}
4221
4219
// Output all "by ref" declarations.
4222
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin (),
4223
- E = BlockByRefDecls. end (); I != E; ++I) {
4220
+ for (auto I = BlockByRefDecls.begin (), E = BlockByRefDecls. end (); I != E;
4221
+ ++I) {
4224
4222
S += " " ;
4225
4223
std::string FieldName = (*I)->getNameAsString ();
4226
4224
std::string ArgName = " _" + FieldName;
@@ -4238,8 +4236,8 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4238
4236
Constructor += " , int flags=0)" ;
4239
4237
// Initialize all "by copy" arguments.
4240
4238
bool firsTime = true ;
4241
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin (),
4242
- E = BlockByCopyDecls. end (); I != E; ++I) {
4239
+ for (auto I = BlockByCopyDecls.begin (), E = BlockByCopyDecls. end (); I != E;
4240
+ ++I) {
4243
4241
std::string Name = (*I)->getNameAsString ();
4244
4242
if (firsTime) {
4245
4243
Constructor += " : " ;
@@ -4253,8 +4251,8 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE,
4253
4251
Constructor += Name + " (_" + Name + " )" ;
4254
4252
}
4255
4253
// Initialize all "by ref" arguments.
4256
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin (),
4257
- E = BlockByRefDecls. end (); I != E; ++I) {
4254
+ for (auto I = BlockByRefDecls.begin (), E = BlockByRefDecls. end (); I != E;
4255
+ ++I) {
4258
4256
std::string Name = (*I)->getNameAsString ();
4259
4257
if (firsTime) {
4260
4258
Constructor += " : " ;
@@ -4340,13 +4338,11 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
4340
4338
ValueDecl *VD = Exp->getDecl ();
4341
4339
BlockDeclRefs.push_back (Exp);
4342
4340
if (!VD->hasAttr <BlocksAttr>()) {
4343
- if (BlockByCopyDeclsPtrSet.insert (VD).second )
4344
- BlockByCopyDecls.push_back (VD);
4341
+ BlockByCopyDecls.insert (VD);
4345
4342
continue ;
4346
4343
}
4347
4344
4348
- if (BlockByRefDeclsPtrSet.insert (VD).second )
4349
- BlockByRefDecls.push_back (VD);
4345
+ BlockByRefDecls.insert (VD);
4350
4346
4351
4347
// imported objects in the inner blocks not used in the outer
4352
4348
// blocks must be copied/disposed in the outer block as well.
@@ -4376,9 +4372,7 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
4376
4372
4377
4373
BlockDeclRefs.clear ();
4378
4374
BlockByRefDecls.clear ();
4379
- BlockByRefDeclsPtrSet.clear ();
4380
4375
BlockByCopyDecls.clear ();
4381
- BlockByCopyDeclsPtrSet.clear ();
4382
4376
ImportedBlockDecls.clear ();
4383
4377
}
4384
4378
if (RewriteSC) {
@@ -5156,16 +5150,12 @@ void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) {
5156
5150
if (BlockDeclRefs.size ()) {
5157
5151
// Unique all "by copy" declarations.
5158
5152
for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
5159
- if (!BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>()) {
5160
- if (BlockByCopyDeclsPtrSet.insert (BlockDeclRefs[i]->getDecl ()).second )
5161
- BlockByCopyDecls.push_back (BlockDeclRefs[i]->getDecl ());
5162
- }
5153
+ if (!BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>())
5154
+ BlockByCopyDecls.insert (BlockDeclRefs[i]->getDecl ());
5163
5155
// Unique all "by ref" declarations.
5164
5156
for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
5165
- if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>()) {
5166
- if (BlockByRefDeclsPtrSet.insert (BlockDeclRefs[i]->getDecl ()).second )
5167
- BlockByRefDecls.push_back (BlockDeclRefs[i]->getDecl ());
5168
- }
5157
+ if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>())
5158
+ BlockByRefDecls.insert (BlockDeclRefs[i]->getDecl ());
5169
5159
// Find any imported blocks...they will need special attention.
5170
5160
for (unsigned i = 0 ; i < BlockDeclRefs.size (); i++)
5171
5161
if (BlockDeclRefs[i]->getDecl ()->hasAttr <BlocksAttr>() ||
@@ -5197,20 +5187,16 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
5197
5187
for (unsigned i = 0 ; i < InnerBlockDeclRefs.size (); i++) {
5198
5188
DeclRefExpr *Exp = InnerBlockDeclRefs[i];
5199
5189
ValueDecl *VD = Exp->getDecl ();
5200
- if (!VD->hasAttr <BlocksAttr>() && !BlockByCopyDeclsPtrSet. count (VD)) {
5201
- // We need to save the copied-in variables in nested
5202
- // blocks because it is needed at the end for some of the API generations.
5203
- // See SynthesizeBlockLiterals routine.
5190
+ if (!VD->hasAttr <BlocksAttr>() && BlockByCopyDecls. insert (VD)) {
5191
+ // We need to save the copied-in variables in nested
5192
+ // blocks because it is needed at the end for some of the API
5193
+ // generations. See SynthesizeBlockLiterals routine.
5204
5194
InnerDeclRefs.push_back (Exp); countOfInnerDecls++;
5205
5195
BlockDeclRefs.push_back (Exp);
5206
- BlockByCopyDeclsPtrSet.insert (VD);
5207
- BlockByCopyDecls.push_back (VD);
5208
5196
}
5209
- if (VD->hasAttr <BlocksAttr>() && !BlockByRefDeclsPtrSet. count (VD)) {
5197
+ if (VD->hasAttr <BlocksAttr>() && BlockByRefDecls. insert (VD)) {
5210
5198
InnerDeclRefs.push_back (Exp); countOfInnerDecls++;
5211
5199
BlockDeclRefs.push_back (Exp);
5212
- BlockByRefDeclsPtrSet.insert (VD);
5213
- BlockByRefDecls.push_back (VD);
5214
5200
}
5215
5201
}
5216
5202
// Find any imported blocks...they will need special attention.
@@ -5291,8 +5277,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
5291
5277
if (BlockDeclRefs.size ()) {
5292
5278
Expr *Exp;
5293
5279
// Output all "by copy" declarations.
5294
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByCopyDecls.begin (),
5295
- E = BlockByCopyDecls. end (); I != E; ++I) {
5280
+ for (auto I = BlockByCopyDecls.begin (), E = BlockByCopyDecls. end (); I != E;
5281
+ ++I) {
5296
5282
if (isObjCType ((*I)->getType ())) {
5297
5283
// FIXME: Conform to ABI ([[obj retain] autorelease]).
5298
5284
FD = SynthBlockInitFunctionDecl ((*I)->getName ());
@@ -5329,8 +5315,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
5329
5315
InitExprs.push_back (Exp);
5330
5316
}
5331
5317
// Output all "by ref" declarations.
5332
- for (SmallVectorImpl<ValueDecl *>::iterator I = BlockByRefDecls.begin (),
5333
- E = BlockByRefDecls. end (); I != E; ++I) {
5318
+ for (auto I = BlockByRefDecls.begin (), E = BlockByRefDecls. end (); I != E;
5319
+ ++I) {
5334
5320
ValueDecl *ND = (*I);
5335
5321
std::string Name (ND->getNameAsString ());
5336
5322
std::string RecName;
@@ -5398,9 +5384,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp,
5398
5384
5399
5385
BlockDeclRefs.clear ();
5400
5386
BlockByRefDecls.clear ();
5401
- BlockByRefDeclsPtrSet.clear ();
5402
5387
BlockByCopyDecls.clear ();
5403
- BlockByCopyDeclsPtrSet.clear ();
5404
5388
ImportedBlockDecls.clear ();
5405
5389
return NewRep;
5406
5390
}
0 commit comments