[C++11] Replacing ObjCProtocolDecl iterators protocol_begin() and protocol_end() with iterator_range protocols(). Updating all of the usages of the iterators with range-based for loops.

llvm-svn: 203863
This commit is contained in:
Aaron Ballman 2014-03-13 22:58:06 +00:00
parent 9b8f9c3d95
commit 0f6e64d505
13 changed files with 61 additions and 94 deletions

View File

@ -1553,6 +1553,11 @@ public:
return data().ReferencedProtocols;
}
typedef ObjCProtocolList::iterator protocol_iterator;
typedef llvm::iterator_range<protocol_iterator> protocol_range;
protocol_range protocols() const {
return protocol_range(protocol_begin(), protocol_end());
}
protocol_iterator protocol_begin() const {
if (!hasDefinition())
return protocol_iterator();

View File

@ -1811,10 +1811,9 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl,
// all_referenced_protocol_iterator since we are walking all categories.
for (auto *Proto : OI->all_referenced_protocols()) {
Protocols.insert(Proto->getCanonicalDecl());
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
PE = Proto->protocol_end(); P != PE; ++P) {
Protocols.insert((*P)->getCanonicalDecl());
CollectInheritedProtocols(*P, Protocols);
for (auto *P : Proto->protocols()) {
Protocols.insert(P->getCanonicalDecl());
CollectInheritedProtocols(P, Protocols);
}
}
@ -1832,18 +1831,14 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl,
PE = OC->protocol_end(); P != PE; ++P) {
ObjCProtocolDecl *Proto = (*P);
Protocols.insert(Proto->getCanonicalDecl());
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
PE = Proto->protocol_end(); P != PE; ++P)
CollectInheritedProtocols(*P, Protocols);
for (const auto *P : Proto->protocols())
CollectInheritedProtocols(P, Protocols);
}
} else if (const ObjCProtocolDecl *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) {
for (ObjCProtocolDecl::protocol_iterator P = OP->protocol_begin(),
PE = OP->protocol_end(); P != PE; ++P) {
ObjCProtocolDecl *Proto = (*P);
for (auto *Proto : OP->protocols()) {
Protocols.insert(Proto->getCanonicalDecl());
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
PE = Proto->protocol_end(); P != PE; ++P)
CollectInheritedProtocols(*P, Protocols);
for (const auto *P : Proto->protocols())
CollectInheritedProtocols(P, Protocols);
}
}
}
@ -6386,9 +6381,8 @@ ASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
ObjCProtocolDecl *rProto) const {
if (declaresSameEntity(lProto, rProto))
return true;
for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(),
E = rProto->protocol_end(); PI != E; ++PI)
if (ProtocolCompatibleWithProtocol(lProto, *PI))
for (auto *PI : rProto->protocols())
if (ProtocolCompatibleWithProtocol(lProto, PI))
return true;
return false;
}

View File

@ -143,11 +143,9 @@ ObjCContainerDecl::HasUserDeclaredSetterMethod(const ObjCPropertyDecl *Property)
}
}
if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(this))
for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(),
E = PD->protocol_end(); PI != E; ++PI) {
if ((*PI)->HasUserDeclaredSetterMethod(Property))
for (const auto *PI : PD->protocols())
if (PI->HasUserDeclaredSetterMethod(Property))
return true;
}
return false;
}
@ -201,9 +199,8 @@ ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
break;
case Decl::ObjCProtocol: {
const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
E = PID->protocol_end(); I != E; ++I)
if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
for (const auto *I : PID->protocols())
if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId))
return P;
break;
}
@ -966,10 +963,8 @@ static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
}
if (const ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)){
for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
PEnd = Protocol->protocol_end();
P != PEnd; ++P)
CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper);
for (const auto *P : Protocol->protocols())
CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
}
if (const ObjCInterfaceDecl *
@ -1496,8 +1491,8 @@ ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
if (Name == getIdentifier())
return PDecl;
for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
if ((PDecl = (*I)->lookupProtocolNamed(Name)))
for (auto *I : protocols())
if ((PDecl = I->lookupProtocolNamed(Name)))
return PDecl;
return NULL;
@ -1518,8 +1513,8 @@ ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
if ((MethodDecl = getMethod(Sel, isInstance)))
return MethodDecl;
for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
for (const auto *I : protocols())
if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
return MethodDecl;
return NULL;
}
@ -1548,9 +1543,8 @@ void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
PO.push_back(Prop);
}
// Scan through protocol's protocols.
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
E = PDecl->protocol_end(); PI != E; ++PI)
(*PI)->collectPropertiesToImplement(PM, PO);
for (const auto *PI : PDecl->protocols())
PI->collectPropertiesToImplement(PM, PO);
}
}
@ -1571,9 +1565,8 @@ void ObjCProtocolDecl::collectInheritedProtocolProperties(
}
// Scan through protocol's protocols which did not have a matching property.
if (!MatchFound)
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
E = PDecl->protocol_end(); PI != E; ++PI)
(*PI)->collectInheritedProtocolProperties(Property, PM);
for (const auto *PI : PDecl->protocols())
PI->collectInheritedProtocolProperties(Property, PM);
}
}

View File

@ -1755,9 +1755,8 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
PD = Def;
SmallVector<std::string, 16> Protocols;
for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(),
E = PD->protocol_end(); PI != E; ++PI)
Protocols.push_back((*PI)->getNameAsString());
for (const auto *PI : PD->protocols())
Protocols.push_back(PI->getNameAsString());
SmallVector<llvm::Constant*, 16> InstanceMethodNames;
SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
SmallVector<llvm::Constant*, 16> OptionalInstanceMethodNames;

View File

@ -2771,9 +2771,8 @@ PushProtocolProperties(llvm::SmallPtrSet<const IdentifierInfo*,16> &PropertySet,
const Decl *Container,
const ObjCProtocolDecl *Proto,
const ObjCCommonTypesHelper &ObjCTypes) {
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
E = Proto->protocol_end(); P != E; ++P)
PushProtocolProperties(PropertySet, Properties, Container, (*P), ObjCTypes);
for (const auto *P : Proto->protocols())
PushProtocolProperties(PropertySet, Properties, Container, P, ObjCTypes);
for (const auto *PD : Proto->properties()) {
if (!PropertySet.insert(PD->getIdentifier()))
continue;

View File

@ -6996,9 +6996,8 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl,
PDecl = Def;
// Must write out all protocol definitions in current qualifier list,
// and in their nested qualifiers before writing out current definition.
for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(),
E = PDecl->protocol_end(); I != E; ++I)
RewriteObjCProtocolMetaData(*I, Result);
for (auto *I : PDecl->protocols())
RewriteObjCProtocolMetaData(I, Result);
// Construct method lists.
std::vector<ObjCMethodDecl *> InstanceMethods, ClassMethods;
@ -7033,11 +7032,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl,
"_OBJC_PROTOCOL_METHOD_TYPES_",
PDecl->getNameAsString());
// Protocol's super protocol list
std::vector<ObjCProtocolDecl *> SuperProtocols;
for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(),
E = PDecl->protocol_end(); I != E; ++I)
SuperProtocols.push_back(*I);
SmallVector<ObjCProtocolDecl *, 8> SuperProtocols(PDecl->protocols());
Write_protocol_list_initializer(Context, Result, SuperProtocols,
"_OBJC_PROTOCOL_REFS_",
PDecl->getNameAsString());

View File

@ -3487,10 +3487,8 @@ static void AddObjCProperties(ObjCContainerDecl *Container,
// Add properties in referenced protocols.
if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
PEnd = Protocol->protocol_end();
P != PEnd; ++P)
AddObjCProperties(*P, AllowCategories, AllowNullaryMethods, CurContext,
for (auto *P : Protocol->protocols())
AddObjCProperties(P, AllowCategories, AllowNullaryMethods, CurContext,
AddedProperties, Results);
} else if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container)){
if (AllowCategories) {

View File

@ -767,10 +767,9 @@ static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
return true;
}
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
E = PDecl->protocol_end(); PI != E; ++PI)
if (NestedProtocolHasNoDefinition((*PI), UndefinedProtocol)) {
UndefinedProtocol = (*PI);
for (auto *PI : PDecl->protocols())
if (NestedProtocolHasNoDefinition(PI, UndefinedProtocol)) {
UndefinedProtocol = PI;
return true;
}
return false;
@ -1649,9 +1648,8 @@ static void findProtocolsWithExplicitImpls(const ObjCProtocolDecl *PDecl,
ProtocolNameSet &PNS) {
if (PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
PNS.insert(PDecl->getIdentifier());
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
PE = PDecl->protocol_end(); PI != PE; ++PI)
findProtocolsWithExplicitImpls(*PI, PNS);
for (const auto *PI : PDecl->protocols())
findProtocolsWithExplicitImpls(PI, PNS);
}
/// Recursively populates a set with all conformed protocols in a class
@ -1796,9 +1794,8 @@ static void CheckProtocolMethodDefs(Sema &S,
}
}
// Check on this protocols's referenced protocols, recursively.
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
E = PDecl->protocol_end(); PI != E; ++PI)
CheckProtocolMethodDefs(S, ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap,
for (auto *PI : PDecl->protocols())
CheckProtocolMethodDefs(S, ImpLoc, PI, IncompleteImpl, InsMap, ClsMap,
CDecl, ProtocolsExplictImpl);
}
@ -1867,10 +1864,9 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap,
if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl> (CDecl)) {
// Also, check for methods declared in protocols inherited by
// this protocol.
for (ObjCProtocolDecl::protocol_iterator
PI = PD->protocol_begin(), E = PD->protocol_end(); PI != E; ++PI)
for (auto *PI : PD->protocols())
MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
IMPDecl, (*PI), IncompleteImpl, false,
IMPDecl, PI, IncompleteImpl, false,
WarnCategoryMethodImpl);
}

View File

@ -384,9 +384,8 @@ static Decl *FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDe
if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel))
return OMD;
for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(),
E = PDecl->protocol_end(); I != E; ++I) {
if (Decl *D = FindGetterSetterNameDeclFromProtocolList(*I, Member, Sel,
for (const auto *I : PDecl->protocols()) {
if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel,
Context))
return D;
}

View File

@ -3161,10 +3161,9 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result,
QualifiedNameLookup, InBaseClass, Consumer, Visited);
}
} else if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Ctx)) {
for (ObjCProtocolDecl::protocol_iterator I = Protocol->protocol_begin(),
E = Protocol->protocol_end(); I != E; ++I) {
for (auto *I : Protocol->protocols()) {
ShadowContextRAII Shadow(Visited);
LookupVisibleDecls(*I, Result, QualifiedNameLookup, false, Consumer,
LookupVisibleDecls(I, Result, QualifiedNameLookup, false, Consumer,
Visited);
}
} else if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Ctx)) {

View File

@ -132,11 +132,8 @@ CheckPropertyAgainstProtocol(Sema &S, ObjCPropertyDecl *Prop,
}
// Check this property against any protocols we inherit.
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
PEnd = Proto->protocol_end();
P != PEnd; ++P) {
CheckPropertyAgainstProtocol(S, Prop, *P, Known);
}
for (auto *P : Proto->protocols())
CheckPropertyAgainstProtocol(S, Prop, P, Known);
}
Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
@ -239,11 +236,8 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
}
} else {
ObjCProtocolDecl *Proto = cast<ObjCProtocolDecl>(ClassDecl);
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
PEnd = Proto->protocol_end();
P != PEnd; ++P) {
CheckPropertyAgainstProtocol(*this, Res, *P, KnownProtos);
}
for (auto *P : Proto->protocols())
CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
}
ActOnDocumentableDecl(Res);
@ -1463,9 +1457,8 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl,
}
}
// scan through protocol's protocols.
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
E = PDecl->protocol_end(); PI != E; ++PI)
CollectImmediateProperties((*PI), PropMap, SuperPropMap);
for (auto *PI : PDecl->protocols())
CollectImmediateProperties(PI, PropMap, SuperPropMap);
}
}

View File

@ -545,9 +545,8 @@ void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Record.push_back(D->isThisDeclarationADefinition());
if (D->isThisDeclarationADefinition()) {
Record.push_back(D->protocol_size());
for (ObjCProtocolDecl::protocol_iterator
I = D->protocol_begin(), IEnd = D->protocol_end(); I != IEnd; ++I)
Writer.AddDeclRef(*I, Record);
for (const auto *I : D->protocols())
Writer.AddDeclRef(I, Record);
for (ObjCProtocolDecl::protocol_loc_iterator PL = D->protocol_loc_begin(),
PLEnd = D->protocol_loc_end();
PL != PLEnd; ++PL)

View File

@ -271,10 +271,8 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod(
// If protocol, check all parent protocols.
if (const ObjCProtocolDecl *ProtD = dyn_cast<ObjCProtocolDecl>(D)) {
for (ObjCProtocolDecl::protocol_iterator I = ProtD->protocol_begin(),
E = ProtD->protocol_end();
I != E; ++I) {
containsInvalidationMethod((*I)->getDefinition(), OutInfo, Partial);
for (const auto *I : ProtD->protocols()) {
containsInvalidationMethod(I->getDefinition(), OutInfo, Partial);
}
return;
}