From a2a1fef4c970a1f5b24b5c6e0375646865751b53 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 13 Mar 2014 20:55:22 +0000 Subject: [PATCH] [C++11] Replacing ObjCInterfaceDecl iterators all_referenced_protocol_begin() and all_referenced_protocol_end() with iterator_range all_referenced_protocols(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203848 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 5 ++++ lib/AST/ASTContext.cpp | 4 +--- lib/AST/DeclObjC.cpp | 43 ++++++++++++----------------------- lib/CodeGen/CGObjCMac.cpp | 7 ++---- lib/Sema/SemaCodeComplete.cpp | 6 ++--- lib/Sema/SemaDeclObjC.cpp | 25 +++++++------------- lib/Sema/SemaLookup.cpp | 6 ++--- lib/Sema/SemaObjCProperty.cpp | 31 ++++++++----------------- 8 files changed, 43 insertions(+), 84 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index c1a419817e..22977cbd47 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -878,7 +878,12 @@ public: } typedef ObjCList::iterator all_protocol_iterator; + typedef llvm::iterator_range all_protocol_range; + all_protocol_range all_referenced_protocols() const { + return all_protocol_range(all_referenced_protocol_begin(), + all_referenced_protocol_end()); + } all_protocol_iterator all_referenced_protocol_begin() const { // FIXME: Should make sure no callers ever do this. if (!hasDefinition()) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 43040b45e9..7d48365f1b 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1813,9 +1813,7 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl, if (const ObjCInterfaceDecl *OI = dyn_cast(CDecl)) { // We can use protocol_iterator here instead of // all_referenced_protocol_iterator since we are walking all categories. - for (ObjCInterfaceDecl::all_protocol_iterator P = OI->all_referenced_protocol_begin(), - PE = OI->all_referenced_protocol_end(); P != PE; ++P) { - ObjCProtocolDecl *Proto = (*P); + 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) { diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 4fd152e090..4b60a9eff1 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -134,13 +134,10 @@ ObjCContainerDecl::HasUserDeclaredSetterMethod(const ObjCPropertyDecl *Property) } // Also look into protocols, for a user declared instance method. - for (ObjCInterfaceDecl::all_protocol_iterator P = - ID->all_referenced_protocol_begin(), - PE = ID->all_referenced_protocol_end(); P != PE; ++P) { - ObjCProtocolDecl *Proto = (*P); + for (const auto *Proto : ID->all_referenced_protocols()) if (Proto->HasUserDeclaredSetterMethod(Property)) return true; - } + // And in its super class. ObjCInterfaceDecl *OSC = ID->getSuperClass(); while (OSC) { @@ -227,10 +224,8 @@ ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { } // Look through protocols. - for (ObjCInterfaceDecl::all_protocol_iterator - I = OID->all_referenced_protocol_begin(), - E = OID->all_referenced_protocol_end(); I != E; ++I) - if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) + for (const auto *I : OID->all_referenced_protocols()) + if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) return P; // Finally, check the super class. @@ -274,10 +269,8 @@ ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( return PD; // Look through protocols. - for (ObjCInterfaceDecl::all_protocol_iterator - I = all_referenced_protocol_begin(), - E = all_referenced_protocol_end(); I != E; ++I) - if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId)) + for (const auto *I : all_referenced_protocols()) + if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId)) return P; return 0; @@ -289,10 +282,8 @@ void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM, PM[Prop->getIdentifier()] = Prop; PO.push_back(Prop); } - for (ObjCInterfaceDecl::all_protocol_iterator - PI = all_referenced_protocol_begin(), - E = all_referenced_protocol_end(); PI != E; ++PI) - (*PI)->collectPropertiesToImplement(PM, PO); + for (const auto *PI : all_referenced_protocols()) + PI->collectPropertiesToImplement(PM, PO); // Note, the properties declared only in class extensions are still copied // into the main @interface's property list, and therefore we don't // explicitly, have to search class extension properties. @@ -338,10 +329,7 @@ void ObjCInterfaceDecl::mergeClassExtensionProtocolList( for (unsigned i = 0; i < ExtNum; i++) { bool protocolExists = false; ObjCProtocolDecl *ProtoInExtension = ExtList[i]; - for (all_protocol_iterator - p = all_referenced_protocol_begin(), - e = all_referenced_protocol_end(); p != e; ++p) { - ObjCProtocolDecl *Proto = (*p); + for (auto *Proto : all_referenced_protocols()) { if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) { protocolExists = true; break; @@ -357,9 +345,8 @@ void ObjCInterfaceDecl::mergeClassExtensionProtocolList( return; // Merge ProtocolRefs into class's protocol list; - for (all_protocol_iterator p = all_referenced_protocol_begin(), - e = all_referenced_protocol_end(); p != e; ++p) { - ProtocolRefs.push_back(*p); + for (auto *P : all_referenced_protocols()) { + ProtocolRefs.push_back(P); } data().AllReferencedProtocols.set(ProtocolRefs.data(), ProtocolRefs.size(),C); @@ -521,11 +508,9 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass( ObjCProtocolDecl * ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) { - for (ObjCInterfaceDecl::all_protocol_iterator P = - all_referenced_protocol_begin(), PE = all_referenced_protocol_end(); - P != PE; ++P) - if ((*P)->lookupProtocolNamed(Name)) - return (*P); + for (auto *P : all_referenced_protocols()) + if (P->lookupProtocolNamed(Name)) + return P; ObjCInterfaceDecl *SuperClass = getSuperClass(); return SuperClass ? SuperClass->lookupNestedProtocol(Name) : NULL; } diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 98bdb16889..e62eddd695 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2813,11 +2813,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name, Prop)); } if (const ObjCInterfaceDecl *OID = dyn_cast(OCD)) { - for (ObjCInterfaceDecl::all_protocol_iterator - P = OID->all_referenced_protocol_begin(), - E = OID->all_referenced_protocol_end(); P != E; ++P) - PushProtocolProperties(PropertySet, Properties, Container, (*P), - ObjCTypes); + for (const auto *P : OID->all_referenced_protocols()) + PushProtocolProperties(PropertySet, Properties, Container, P, ObjCTypes); } else if (const ObjCCategoryDecl *CD = dyn_cast(OCD)) { for (ObjCCategoryDecl::protocol_iterator P = CD->protocol_begin(), diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 0c02e52e67..87a2b4cf0e 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -3504,10 +3504,8 @@ static void AddObjCProperties(ObjCContainerDecl *Container, } // Look through protocols. - for (ObjCInterfaceDecl::all_protocol_iterator - I = IFace->all_referenced_protocol_begin(), - E = IFace->all_referenced_protocol_end(); I != E; ++I) - AddObjCProperties(*I, AllowCategories, AllowNullaryMethods, CurContext, + for (auto *I : IFace->all_referenced_protocols()) + AddObjCProperties(I, AllowCategories, AllowNullaryMethods, CurContext, AddedProperties, Results); // Look in the superclass. diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 1b8a466644..eabd98d7b7 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1666,11 +1666,8 @@ static void findProtocolsWithExplicitImpls(const ObjCInterfaceDecl *Super, if (!Super) return; - for (ObjCInterfaceDecl::all_protocol_iterator - I = Super->all_referenced_protocol_begin(), - E = Super->all_referenced_protocol_end(); I != E; ++I) { - findProtocolsWithExplicitImpls(*I, PNS); - } + for (const auto *I : Super->all_referenced_protocols()) + findProtocolsWithExplicitImpls(I, PNS); findProtocolsWithExplicitImpls(Super->getSuperClass(), PNS); } @@ -1907,14 +1904,11 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap, } // Check for any implementation of a methods declared in protocol. - for (ObjCInterfaceDecl::all_protocol_iterator - PI = I->all_referenced_protocol_begin(), - E = I->all_referenced_protocol_end(); PI != E; ++PI) + for (auto *PI : I->all_referenced_protocols()) MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, - IMPDecl, - (*PI), IncompleteImpl, false, + IMPDecl, PI, IncompleteImpl, false, WarnCategoryMethodImpl); - + // FIXME. For now, we are not checking for extact match of methods // in category implementation and its primary class's super class. if (!WarnCategoryMethodImpl && I->getSuperClass()) @@ -2010,12 +2004,9 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, LazyProtocolNameSet ExplicitImplProtocols; if (ObjCInterfaceDecl *I = dyn_cast (CDecl)) { - for (ObjCInterfaceDecl::all_protocol_iterator - PI = I->all_referenced_protocol_begin(), - E = I->all_referenced_protocol_end(); PI != E; ++PI) - CheckProtocolMethodDefs(*this, IMPDecl->getLocation(), *PI, - IncompleteImpl, InsMap, ClsMap, I, - ExplicitImplProtocols); + for (auto *PI : I->all_referenced_protocols()) + CheckProtocolMethodDefs(*this, IMPDecl->getLocation(), PI, IncompleteImpl, + InsMap, ClsMap, I, ExplicitImplProtocols); // Check class extensions (unnamed categories) for (ObjCInterfaceDecl::visible_extensions_iterator Ext = I->visible_extensions_begin(), diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 0e31606aaf..d98b7f8505 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3143,11 +3143,9 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, } // Traverse protocols. - for (ObjCInterfaceDecl::all_protocol_iterator - I = IFace->all_referenced_protocol_begin(), - E = IFace->all_referenced_protocol_end(); I != E; ++I) { + for (auto *I : IFace->all_referenced_protocols()) { ShadowContextRAII Shadow(Visited); - LookupVisibleDecls(*I, Result, QualifiedNameLookup, false, Consumer, + LookupVisibleDecls(I, Result, QualifiedNameLookup, false, Consumer, Visited); } diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index d918aeca15..a10e3d8370 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -227,11 +227,8 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, } } else { // Slower path: look in all protocols we referenced. - for (ObjCInterfaceDecl::all_protocol_iterator - P = IFace->all_referenced_protocol_begin(), - PEnd = IFace->all_referenced_protocol_end(); - P != PEnd; ++P) { - CheckPropertyAgainstProtocol(*this, Res, *P, KnownProtos); + for (auto *P : IFace->all_referenced_protocols()) { + CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos); } } } else if (ObjCCategoryDecl *Cat = dyn_cast(ClassDecl)) { @@ -763,18 +760,14 @@ DiagnosePropertyMismatchDeclInProtocols(Sema &S, SourceLocation AtLoc, ObjCInterfaceDecl *ClassDecl, ObjCPropertyDecl *Property) { ObjCInterfaceDecl::ProtocolPropertyMap PropMap; - for (ObjCInterfaceDecl::all_protocol_iterator - PI = ClassDecl->all_referenced_protocol_begin(), - E = ClassDecl->all_referenced_protocol_end(); PI != E; ++PI) { - if (const ObjCProtocolDecl *PDecl = (*PI)->getDefinition()) + for (const auto *PI : ClassDecl->all_referenced_protocols()) { + if (const ObjCProtocolDecl *PDecl = PI->getDefinition()) PDecl->collectInheritedProtocolProperties(Property, PropMap); } if (ObjCInterfaceDecl *SDecl = ClassDecl->getSuperClass()) while (SDecl) { - for (ObjCInterfaceDecl::all_protocol_iterator - PI = SDecl->all_referenced_protocol_begin(), - E = SDecl->all_referenced_protocol_end(); PI != E; ++PI) { - if (const ObjCProtocolDecl *PDecl = (*PI)->getDefinition()) + for (const auto *PI : SDecl->all_referenced_protocols()) { + if (const ObjCProtocolDecl *PDecl = PI->getDefinition()) PDecl->collectInheritedProtocolProperties(Property, PropMap); } SDecl = SDecl->getSuperClass(); @@ -1447,10 +1440,8 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl, PropMap[Prop->getIdentifier()] = Prop; if (IncludeProtocols) { // Scan through class's protocols. - for (ObjCInterfaceDecl::all_protocol_iterator - PI = IDecl->all_referenced_protocol_begin(), - E = IDecl->all_referenced_protocol_end(); PI != E; ++PI) - CollectImmediateProperties((*PI), PropMap, SuperPropMap); + for (auto *PI : IDecl->all_referenced_protocols()) + CollectImmediateProperties(PI, PropMap, SuperPropMap); } } if (ObjCCategoryDecl *CATDecl = dyn_cast(CDecl)) { @@ -1698,11 +1689,7 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, if (IDecl) { std::unique_ptr LazyMap; - for (ObjCInterfaceDecl::all_protocol_iterator - PI = IDecl->all_referenced_protocol_begin(), - PE = IDecl->all_referenced_protocol_end(); - PI != PE; ++PI) { - ObjCProtocolDecl *PDecl = *PI; + for (auto *PDecl : IDecl->all_referenced_protocols()) { if (!PDecl->hasAttr()) continue; // Lazily construct a set of all the properties in the @interface -- 2.40.0