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

Commit 262bc18

Browse files
committed
Remove the ref/value inconsistency in filter_decl_iterator.
filter_decl_iterator had a weird mismatch where both op* and op-> returned T* making it difficult to generalize this filtering behavior into a reusable library of any kind. This change errs on the side of value, making op-> return T* and op* return T&. (reviewed by Richard Smith) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155808 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2980383 commit 262bc18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+306
-297
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,8 @@ class DeclContext {
12371237
}
12381238

12391239
public:
1240-
typedef SpecificDecl* value_type;
1241-
typedef SpecificDecl* reference;
1240+
typedef SpecificDecl value_type;
1241+
typedef SpecificDecl& reference;
12421242
typedef SpecificDecl* pointer;
12431243
typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
12441244
difference_type;
@@ -1258,8 +1258,8 @@ class DeclContext {
12581258
SkipToNextDecl();
12591259
}
12601260

1261-
reference operator*() const { return cast<SpecificDecl>(*Current); }
1262-
pointer operator->() const { return cast<SpecificDecl>(*Current); }
1261+
reference operator*() const { return *cast<SpecificDecl>(*Current); }
1262+
pointer operator->() const { return &**this; }
12631263

12641264
specific_decl_iterator& operator++() {
12651265
++Current;

Diff for: lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ static void cleanupDeallocOrFinalize(MigrationPass &pass) {
210210
ObjCMethodDecl *DeallocM = 0;
211211
ObjCMethodDecl *FinalizeM = 0;
212212
for (ObjCImplementationDecl::instmeth_iterator
213-
MI = (*I)->instmeth_begin(),
214-
ME = (*I)->instmeth_end(); MI != ME; ++MI) {
213+
MI = I->instmeth_begin(),
214+
ME = I->instmeth_end(); MI != ME; ++MI) {
215215
ObjCMethodDecl *MD = *MI;
216216
if (!MD->hasBody())
217217
continue;

Diff for: lib/ARCMigrate/TransGCAttrs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class GCAttrsCollector : public RecursiveASTVisitor<GCAttrsCollector> {
136136
if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
137137
for (CXXRecordDecl::method_iterator
138138
MI = RD->method_begin(), ME = RD->method_end(); MI != ME; ++MI) {
139-
if ((*MI)->isOutOfLine())
139+
if (MI->isOutOfLine())
140140
return true;
141141
}
142142
return false;

Diff for: lib/ARCMigrate/TransProperties.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class PropertiesRewriter {
8585
if (PrevAtProps->find(RawLoc) != PrevAtProps->end())
8686
continue;
8787
PropsTy &props = AtProps[RawLoc];
88-
props.push_back(*propI);
88+
props.push_back(&*propI);
8989
}
9090
}
9191

@@ -102,7 +102,7 @@ class PropertiesRewriter {
102102
for (prop_impl_iterator
103103
I = prop_impl_iterator(D->decls_begin()),
104104
E = prop_impl_iterator(D->decls_end()); I != E; ++I) {
105-
ObjCPropertyImplDecl *implD = *I;
105+
ObjCPropertyImplDecl *implD = &*I;
106106
if (implD->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
107107
continue;
108108
ObjCPropertyDecl *propD = implD->getPropertyDecl();

Diff for: lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ZeroOutInDeallocRemover :
114114
// this class implementation.
115115
for (ObjCImplDecl::propimpl_iterator
116116
I = IMD->propimpl_begin(), EI = IMD->propimpl_end(); I != EI; ++I) {
117-
ObjCPropertyImplDecl *PID = *I;
117+
ObjCPropertyImplDecl *PID = &*I;
118118
if (PID->getPropertyImplementation() ==
119119
ObjCPropertyImplDecl::Synthesize) {
120120
ObjCPropertyDecl *PD = PID->getPropertyDecl();

Diff for: lib/ARCMigrate/Transforms.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ static void GCRewriteFinalize(MigrationPass &pass) {
472472
for (impl_iterator I = impl_iterator(DC->decls_begin()),
473473
E = impl_iterator(DC->decls_end()); I != E; ++I) {
474474
for (ObjCImplementationDecl::instmeth_iterator
475-
MI = (*I)->instmeth_begin(),
476-
ME = (*I)->instmeth_end(); MI != ME; ++MI) {
475+
MI = I->instmeth_begin(),
476+
ME = I->instmeth_end(); MI != ME; ++MI) {
477477
ObjCMethodDecl *MD = *MI;
478478
if (!MD->hasBody())
479479
continue;

Diff for: lib/AST/APValue.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ void APValue::printPretty(raw_ostream &Out, ASTContext &Ctx, QualType Ty) const{
467467
FI != RD->field_end(); ++FI) {
468468
if (!First)
469469
Out << ", ";
470-
if ((*FI)->isUnnamedBitfield()) continue;
471-
getStructField((*FI)->getFieldIndex()).
472-
printPretty(Out, Ctx, (*FI)->getType());
470+
if (FI->isUnnamedBitfield()) continue;
471+
getStructField(FI->getFieldIndex()).
472+
printPretty(Out, Ctx, FI->getType());
473473
First = false;
474474
}
475475
Out << '}';

Diff for: lib/AST/ASTContext.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ void ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI,
11871187
if (!leafClass) {
11881188
for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
11891189
E = OI->ivar_end(); I != E; ++I)
1190-
Ivars.push_back(*I);
1190+
Ivars.push_back(&*I);
11911191
} else {
11921192
ObjCInterfaceDecl *IDecl = const_cast<ObjCInterfaceDecl *>(OI);
11931193
for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv;
@@ -4227,7 +4227,7 @@ void ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
42274227
for (ObjCCategoryImplDecl::propimpl_iterator
42284228
i = CID->propimpl_begin(), e = CID->propimpl_end();
42294229
i != e; ++i) {
4230-
ObjCPropertyImplDecl *PID = *i;
4230+
ObjCPropertyImplDecl *PID = &*i;
42314231
if (PID->getPropertyDecl() == PD) {
42324232
if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) {
42334233
Dynamic = true;
@@ -4241,7 +4241,7 @@ void ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
42414241
for (ObjCCategoryImplDecl::propimpl_iterator
42424242
i = OID->propimpl_begin(), e = OID->propimpl_end();
42434243
i != e; ++i) {
4244-
ObjCPropertyImplDecl *PID = *i;
4244+
ObjCPropertyImplDecl *PID = &*i;
42454245
if (PID->getPropertyDecl() == PD) {
42464246
if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) {
42474247
Dynamic = true;
@@ -4563,7 +4563,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
45634563
// Special case bit-fields.
45644564
if (Field->isBitField()) {
45654565
getObjCEncodingForTypeImpl(Field->getType(), S, false, true,
4566-
(*Field));
4566+
&*Field);
45674567
} else {
45684568
QualType qt = Field->getType();
45694569
getLegacyIntegralTypeEncoding(qt);
@@ -4759,7 +4759,7 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
47594759
Field != FieldEnd; ++Field, ++i) {
47604760
uint64_t offs = layout.getFieldOffset(i);
47614761
FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
4762-
std::make_pair(offs, *Field));
4762+
std::make_pair(offs, &*Field));
47634763
}
47644764

47654765
if (CXXRec && includeVBases) {

Diff for: lib/AST/ASTImporter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
10171017
return false;
10181018
}
10191019

1020-
if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
1020+
if (!IsStructurallyEquivalent(Context, &*Field1, &*Field2))
10211021
return false;
10221022
}
10231023

Diff for: lib/AST/Decl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2463,15 +2463,15 @@ unsigned FieldDecl::getFieldIndex() const {
24632463

24642464
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
24652465
I != E; ++I, ++Index) {
2466-
(*I)->CachedFieldIndex = Index + 1;
2466+
I->CachedFieldIndex = Index + 1;
24672467

24682468
if (IsMsStruct) {
24692469
// Zero-length bitfields following non-bitfield members are ignored.
2470-
if (getASTContext().ZeroBitfieldFollowsNonBitfield((*I), LastFD)) {
2470+
if (getASTContext().ZeroBitfieldFollowsNonBitfield(&*I, LastFD)) {
24712471
--Index;
24722472
continue;
24732473
}
2474-
LastFD = (*I);
2474+
LastFD = &*I;
24752475
}
24762476
}
24772477

Diff for: lib/AST/DeclCXX.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(unsigned TypeQuals) const{
400400
CXXConstructorDecl *CXXRecordDecl::getMoveConstructor() const {
401401
for (ctor_iterator I = ctor_begin(), E = ctor_end(); I != E; ++I)
402402
if (I->isMoveConstructor())
403-
return *I;
403+
return &*I;
404404

405405
return 0;
406406
}
@@ -458,7 +458,7 @@ CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const {
458458
CXXMethodDecl *CXXRecordDecl::getMoveAssignmentOperator() const {
459459
for (method_iterator I = method_begin(), E = method_end(); I != E; ++I)
460460
if (I->isMoveAssignmentOperator())
461-
return *I;
461+
return &*I;
462462

463463
return 0;
464464
}
@@ -996,11 +996,11 @@ void CXXRecordDecl::getCaptureFields(
996996
for (LambdaExpr::Capture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures;
997997
C != CEnd; ++C, ++Field) {
998998
if (C->capturesThis()) {
999-
ThisCapture = *Field;
999+
ThisCapture = &*Field;
10001000
continue;
10011001
}
10021002

1003-
Captures[C->getCapturedVar()] = *Field;
1003+
Captures[C->getCapturedVar()] = &*Field;
10041004
}
10051005
}
10061006

Diff for: lib/AST/DeclObjC.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,9 @@ ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
767767
ObjCIvarDecl *curIvar = 0;
768768
if (!ivar_empty()) {
769769
ObjCInterfaceDecl::ivar_iterator I = ivar_begin(), E = ivar_end();
770-
data().IvarList = (*I); ++I;
771-
for (curIvar = data().IvarList; I != E; curIvar = *I, ++I)
772-
curIvar->setNextIvar(*I);
770+
data().IvarList = &*I; ++I;
771+
for (curIvar = data().IvarList; I != E; curIvar = &*I, ++I)
772+
curIvar->setNextIvar(&*I);
773773
}
774774

775775
for (const ObjCCategoryDecl *CDecl = getFirstClassExtension(); CDecl;
@@ -778,11 +778,11 @@ ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
778778
ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
779779
E = CDecl->ivar_end();
780780
if (!data().IvarList) {
781-
data().IvarList = (*I); ++I;
781+
data().IvarList = &*I; ++I;
782782
curIvar = data().IvarList;
783783
}
784-
for ( ;I != E; curIvar = *I, ++I)
785-
curIvar->setNextIvar(*I);
784+
for ( ;I != E; curIvar = &*I, ++I)
785+
curIvar->setNextIvar(&*I);
786786
}
787787
}
788788

@@ -791,11 +791,11 @@ ObjCIvarDecl *ObjCInterfaceDecl::all_declared_ivar_begin() {
791791
ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
792792
E = ImplDecl->ivar_end();
793793
if (!data().IvarList) {
794-
data().IvarList = (*I); ++I;
794+
data().IvarList = &*I; ++I;
795795
curIvar = data().IvarList;
796796
}
797-
for ( ;I != E; curIvar = *I, ++I)
798-
curIvar->setNextIvar(*I);
797+
for ( ;I != E; curIvar = &*I, ++I)
798+
curIvar->setNextIvar(&*I);
799799
}
800800
}
801801
return data().IvarList;
@@ -1175,7 +1175,7 @@ void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
11751175
ObjCPropertyImplDecl *ObjCImplDecl::
11761176
FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
11771177
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
1178-
ObjCPropertyImplDecl *PID = *i;
1178+
ObjCPropertyImplDecl *PID = &*i;
11791179
if (PID->getPropertyIvarDecl() &&
11801180
PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
11811181
return PID;
@@ -1190,7 +1190,7 @@ FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
11901190
ObjCPropertyImplDecl *ObjCImplDecl::
11911191
FindPropertyImplDecl(IdentifierInfo *Id) const {
11921192
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
1193-
ObjCPropertyImplDecl *PID = *i;
1193+
ObjCPropertyImplDecl *PID = &*i;
11941194
if (PID->getPropertyDecl()->getIdentifier() == Id)
11951195
return PID;
11961196
}

Diff for: lib/AST/DeclPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
923923
Indentation += Policy.Indentation;
924924
for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
925925
E = OID->ivar_end(); I != E; ++I) {
926-
Indent() << (*I)->getType().getAsString(Policy) << ' ' << **I << ";\n";
926+
Indent() << I->getType().getAsString(Policy) << ' ' << *I << ";\n";
927927
}
928928
Indentation -= Policy.Indentation;
929929
Out << "}\n";

Diff for: lib/AST/ExprConstant.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,8 @@ static bool CheckConstantExpression(EvalInfo &Info, SourceLocation DiagLoc,
10721072
}
10731073
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
10741074
I != E; ++I) {
1075-
if (!CheckConstantExpression(Info, DiagLoc, (*I)->getType(),
1076-
Value.getStructField((*I)->getFieldIndex())))
1075+
if (!CheckConstantExpression(Info, DiagLoc, I->getType(),
1076+
Value.getStructField(I->getFieldIndex())))
10771077
return false;
10781078
}
10791079
}
@@ -3391,15 +3391,15 @@ static bool HandleClassZeroInitialization(EvalInfo &Info, const Expr *E,
33913391
for (RecordDecl::field_iterator I = RD->field_begin(), End = RD->field_end();
33923392
I != End; ++I) {
33933393
// -- if T is a reference type, no initialization is performed.
3394-
if ((*I)->getType()->isReferenceType())
3394+
if (I->getType()->isReferenceType())
33953395
continue;
33963396

33973397
LValue Subobject = This;
3398-
HandleLValueMember(Info, E, Subobject, *I, &Layout);
3398+
HandleLValueMember(Info, E, Subobject, &*I, &Layout);
33993399

3400-
ImplicitValueInitExpr VIE((*I)->getType());
3400+
ImplicitValueInitExpr VIE(I->getType());
34013401
if (!EvaluateInPlace(
3402-
Result.getStructField((*I)->getFieldIndex()), Info, Subobject, &VIE))
3402+
Result.getStructField(I->getFieldIndex()), Info, Subobject, &VIE))
34033403
return false;
34043404
}
34053405

@@ -3419,9 +3419,9 @@ bool RecordExprEvaluator::ZeroInitialization(const Expr *E) {
34193419
}
34203420

34213421
LValue Subobject = This;
3422-
HandleLValueMember(Info, E, Subobject, *I);
3423-
Result = APValue(*I);
3424-
ImplicitValueInitExpr VIE((*I)->getType());
3422+
HandleLValueMember(Info, E, Subobject, &*I);
3423+
Result = APValue(&*I);
3424+
ImplicitValueInitExpr VIE(I->getType());
34253425
return EvaluateInPlace(Result.getUnionValue(), Info, Subobject, &VIE);
34263426
}
34273427

@@ -3511,14 +3511,14 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
35113511
// FIXME: Diagnostics here should point to the end of the initializer
35123512
// list, not the start.
35133513
HandleLValueMember(Info, HaveInit ? E->getInit(ElementNo) : E, Subobject,
3514-
*Field, &Layout);
3514+
&*Field, &Layout);
35153515

35163516
// Perform an implicit value-initialization for members beyond the end of
35173517
// the initializer list.
35183518
ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy : Field->getType());
35193519

35203520
if (!EvaluateInPlace(
3521-
Result.getStructField((*Field)->getFieldIndex()),
3521+
Result.getStructField(Field->getFieldIndex()),
35223522
Info, Subobject, HaveInit ? E->getInit(ElementNo++) : &VIE)) {
35233523
if (!Info.keepEvaluatingAfterFailure())
35243524
return false;

Diff for: lib/AST/ItaniumMangle.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ static const FieldDecl *FindFirstNamedDataMember(const RecordDecl *RD) {
10321032

10331033
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
10341034
I != E; ++I) {
1035-
const FieldDecl *FD = *I;
1035+
const FieldDecl *FD = &*I;
10361036

10371037
if (FD->getIdentifier())
10381038
return FD;

0 commit comments

Comments
 (0)