From 0f6e64d50511aeab55ed6929d8bc1953b776bb92 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 13 Mar 2014 22:58:06 +0000 Subject: [PATCH] [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 --- clang/include/clang/AST/DeclObjC.h | 5 +++ clang/lib/AST/ASTContext.cpp | 26 ++++++-------- clang/lib/AST/DeclObjC.cpp | 35 ++++++++----------- clang/lib/CodeGen/CGObjCGNU.cpp | 5 ++- clang/lib/CodeGen/CGObjCMac.cpp | 5 ++- .../Rewrite/Frontend/RewriteModernObjC.cpp | 11 ++---- clang/lib/Sema/SemaCodeComplete.cpp | 6 ++-- clang/lib/Sema/SemaDeclObjC.cpp | 22 +++++------- clang/lib/Sema/SemaExprMember.cpp | 5 ++- clang/lib/Sema/SemaLookup.cpp | 5 ++- clang/lib/Sema/SemaObjCProperty.cpp | 19 ++++------ clang/lib/Serialization/ASTWriterDecl.cpp | 5 ++- .../Checkers/IvarInvalidationChecker.cpp | 6 ++-- 13 files changed, 61 insertions(+), 94 deletions(-) diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 17b6dbf62ae5..da4a4ee7f6ad 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -1553,6 +1553,11 @@ public: return data().ReferencedProtocols; } typedef ObjCProtocolList::iterator protocol_iterator; + typedef llvm::iterator_range protocol_range; + + protocol_range protocols() const { + return protocol_range(protocol_begin(), protocol_end()); + } protocol_iterator protocol_begin() const { if (!hasDefinition()) return protocol_iterator(); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2f8b8e66185f..514a4e15b15e 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -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(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; } diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 0844a222f8cb..dd96d39917ce 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -143,11 +143,9 @@ ObjCContainerDecl::HasUserDeclaredSetterMethod(const ObjCPropertyDecl *Property) } } if (const ObjCProtocolDecl *PD = dyn_cast(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(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(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); } } diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 9a5ccfa646ca..7a5344bd2984 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -1755,9 +1755,8 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { PD = Def; SmallVector 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 InstanceMethodNames; SmallVector InstanceMethodTypes; SmallVector OptionalInstanceMethodNames; diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index e62eddd695a3..8777549749d9 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -2771,9 +2771,8 @@ PushProtocolProperties(llvm::SmallPtrSet &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; diff --git a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp index f14039272be2..39395437b667 100644 --- a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -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 InstanceMethods, ClassMethods; @@ -7033,11 +7032,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, "_OBJC_PROTOCOL_METHOD_TYPES_", PDecl->getNameAsString()); // Protocol's super protocol list - std::vector SuperProtocols; - for (ObjCProtocolDecl::protocol_iterator I = PDecl->protocol_begin(), - E = PDecl->protocol_end(); I != E; ++I) - SuperProtocols.push_back(*I); - + SmallVector SuperProtocols(PDecl->protocols()); Write_protocol_list_initializer(Context, Result, SuperProtocols, "_OBJC_PROTOCOL_REFS_", PDecl->getNameAsString()); diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 6ef5ed8d4707..b53c48af4bc2 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -3487,10 +3487,8 @@ static void AddObjCProperties(ObjCContainerDecl *Container, // Add properties in referenced protocols. if (ObjCProtocolDecl *Protocol = dyn_cast(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(Container)){ if (AllowCategories) { diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index c3e511966cc8..3d079cfb380f 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -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()) 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 (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); } diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 9c6877e0e1bc..4e9d250d4a40 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -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; } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 4edf80954b49..8e6601c7649a 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -3161,10 +3161,9 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, QualifiedNameLookup, InBaseClass, Consumer, Visited); } } else if (ObjCProtocolDecl *Protocol = dyn_cast(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(Ctx)) { diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 4c2f889a438f..39c817286ca9 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -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(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); } } diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 9ad55f5f6343..66155b715302 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -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) diff --git a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index da458e766c1b..fdd1fdcd6eb9 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -271,10 +271,8 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod( // If protocol, check all parent protocols. if (const ObjCProtocolDecl *ProtD = dyn_cast(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; }