From 90f0e7122a3be18f0c4995318b61e41b74dff416 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 14 Mar 2014 15:02:45 +0000 Subject: [PATCH] [C++11] Replacing ObjCCategoryDecl iterators propimpl_begin() and propimpl_end() with iterator_range property_impls(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203930 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 6 ++++ lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp | 30 +++++++++---------- lib/AST/ASTContext.cpp | 16 +++------- lib/AST/DeclObjC.cpp | 8 ++--- lib/Analysis/BodyFarm.cpp | 5 +--- lib/CodeGen/CGObjCGNU.cpp | 7 ++--- lib/CodeGen/CGObjCMac.cpp | 10 ++----- lib/CodeGen/CodeGenModule.cpp | 5 +--- lib/Rewrite/Frontend/RewriteModernObjC.cpp | 16 +++------- lib/Rewrite/Frontend/RewriteObjC.cpp | 16 +++------- lib/Sema/SemaObjCProperty.cpp | 8 ++--- .../Checkers/CheckObjCDealloc.cpp | 6 ++-- .../Checkers/ObjCUnusedIVarsChecker.cpp | 5 ++-- 13 files changed, 46 insertions(+), 92 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 2d9c5c8bb6..9527a4c62f 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1866,6 +1866,12 @@ public: // Iterator access to properties. typedef specific_decl_iterator propimpl_iterator; + typedef llvm::iterator_range> + propimpl_range; + + propimpl_range property_impls() const { + return propimpl_range(propimpl_begin(), propimpl_end()); + } propimpl_iterator propimpl_begin() const { return propimpl_iterator(decls_begin()); } diff --git a/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp b/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp index 4d088e05bf..3be9fb2f5e 100644 --- a/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp +++ b/lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp @@ -113,23 +113,21 @@ public: // For a 'dealloc' method use, find all property implementations in // this class implementation. - for (ObjCImplDecl::propimpl_iterator - I = IMD->propimpl_begin(), EI = IMD->propimpl_end(); I != EI; ++I) { - ObjCPropertyImplDecl *PID = *I; - if (PID->getPropertyImplementation() == - ObjCPropertyImplDecl::Synthesize) { - ObjCPropertyDecl *PD = PID->getPropertyDecl(); - ObjCMethodDecl *setterM = PD->getSetterMethodDecl(); - if (!(setterM && setterM->isDefined())) { - ObjCPropertyDecl::PropertyAttributeKind AttrKind = - PD->getPropertyAttributes(); - if (AttrKind & - (ObjCPropertyDecl::OBJC_PR_retain | - ObjCPropertyDecl::OBJC_PR_copy | - ObjCPropertyDecl::OBJC_PR_strong)) - SynthesizedProperties[PD] = PID; - } + for (auto *PID : IMD->property_impls()) { + if (PID->getPropertyImplementation() == + ObjCPropertyImplDecl::Synthesize) { + ObjCPropertyDecl *PD = PID->getPropertyDecl(); + ObjCMethodDecl *setterM = PD->getSetterMethodDecl(); + if (!(setterM && setterM->isDefined())) { + ObjCPropertyDecl::PropertyAttributeKind AttrKind = + PD->getPropertyAttributes(); + if (AttrKind & + (ObjCPropertyDecl::OBJC_PR_retain | + ObjCPropertyDecl::OBJC_PR_copy | + ObjCPropertyDecl::OBJC_PR_strong)) + SynthesizedProperties[PD] = PID; } + } } // Now, remove all zeroing of ivars etc. diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 1f331ce548..bc1f3a821c 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4936,22 +4936,14 @@ ASTContext::getObjCPropertyImplDeclForPropertyDecl( return 0; if (const ObjCCategoryImplDecl *CID = dyn_cast(Container)) { - for (ObjCCategoryImplDecl::propimpl_iterator - i = CID->propimpl_begin(), e = CID->propimpl_end(); - i != e; ++i) { - ObjCPropertyImplDecl *PID = *i; - if (PID->getPropertyDecl() == PD) - return PID; - } + for (auto *PID : CID->property_impls()) + if (PID->getPropertyDecl() == PD) + return PID; } else { const ObjCImplementationDecl *OID=cast(Container); - for (ObjCCategoryImplDecl::propimpl_iterator - i = OID->propimpl_begin(), e = OID->propimpl_end(); - i != e; ++i) { - ObjCPropertyImplDecl *PID = *i; + for (auto *PID : OID->property_impls()) if (PID->getPropertyDecl() == PD) return PID; - } } return 0; } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 06448f8646..6b05b7ec22 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -1674,12 +1674,10 @@ void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { /// ObjCPropertyImplDecl *ObjCImplDecl:: FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { - for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ - ObjCPropertyImplDecl *PID = *i; + for (auto *PID : property_impls()) if (PID->getPropertyIvarDecl() && PID->getPropertyIvarDecl()->getIdentifier() == ivarId) return PID; - } return 0; } @@ -1689,11 +1687,9 @@ FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const { /// ObjCPropertyImplDecl *ObjCImplDecl:: FindPropertyImplDecl(IdentifierInfo *Id) const { - for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){ - ObjCPropertyImplDecl *PID = *i; + for (auto *PID : property_impls()) if (PID->getPropertyDecl()->getIdentifier() == Id) return PID; - } return 0; } diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp index c857a0ef49..039911e3e2 100644 --- a/lib/Analysis/BodyFarm.cpp +++ b/lib/Analysis/BodyFarm.cpp @@ -404,10 +404,7 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx, const ObjCImplementationDecl *ImplDecl = IVar->getContainingInterface()->getImplementation(); if (ImplDecl) { - typedef ObjCImplementationDecl::propimpl_iterator propimpl_iterator; - for (propimpl_iterator I = ImplDecl->propimpl_begin(), - E = ImplDecl->propimpl_end(); - I != E; ++I) { + for (const auto *I : ImplDecl->property_impls()) { if (I->getPropertyDecl() != Prop) continue; diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 7a5344bd29..2689d7b459 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -2057,12 +2057,9 @@ llvm::Constant *CGObjCGNU::GeneratePropertyList(const ObjCImplementationDecl *OI // Add all of the property methods need adding to the method list and to the // property metadata list. - for (ObjCImplDecl::propimpl_iterator - iter = OID->propimpl_begin(), endIter = OID->propimpl_end(); - iter != endIter ; iter++) { + for (auto *propertyImpl : OID->property_impls()) { std::vector Fields; - ObjCPropertyDecl *property = iter->getPropertyDecl(); - ObjCPropertyImplDecl *propertyImpl = *iter; + ObjCPropertyDecl *property = propertyImpl->getPropertyDecl(); bool isSynthesized = (propertyImpl->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize); bool isDynamic = (propertyImpl->getPropertyImplementation() == diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 867ac8bf62..64b55d21c2 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -3062,10 +3062,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { // Class methods should always be defined. ClassMethods.push_back(GetMethodConstant(I)); - for (ObjCImplementationDecl::propimpl_iterator - i = ID->propimpl_begin(), e = ID->propimpl_end(); i != e; ++i) { - ObjCPropertyImplDecl *PID = *i; - + for (const auto *PID : ID->property_impls()) { if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) { ObjCPropertyDecl *PD = PID->getPropertyDecl(); @@ -5650,10 +5647,7 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer( // Instance methods should always be defined. Methods.push_back(GetMethodConstant(I)); - for (ObjCImplementationDecl::propimpl_iterator - i = ID->propimpl_begin(), e = ID->propimpl_end(); i != e; ++i) { - ObjCPropertyImplDecl *PID = *i; - + for (const auto *PID : ID->property_impls()) { if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize){ ObjCPropertyDecl *PD = PID->getPropertyDecl(); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 98588a4122..53e7d56a8d 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2752,10 +2752,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary( /// properties for an implementation. void CodeGenModule::EmitObjCPropertyImplementations(const ObjCImplementationDecl *D) { - for (ObjCImplementationDecl::propimpl_iterator - i = D->propimpl_begin(), e = D->propimpl_end(); i != e; ++i) { - ObjCPropertyImplDecl *PID = *i; - + for (const auto *PID : D->property_impls()) { // Dynamic is just for type-checking. if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) { ObjCPropertyDecl *PD = PID->getPropertyDecl(); diff --git a/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/lib/Rewrite/Frontend/RewriteModernObjC.cpp index 369383e0da..93e89a91ad 100644 --- a/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -1404,12 +1404,8 @@ void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) { const char *endBuf = SM->getCharacterData(LocEnd); ReplaceText(LocStart, endBuf-startBuf, ResultStr); } - for (ObjCCategoryImplDecl::propimpl_iterator - I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(), - E = IMD ? IMD->propimpl_end() : CID->propimpl_end(); - I != E; ++I) { - RewritePropertyImplDecl(*I, IMD, CID); - } + for (auto *I : IMD ? IMD->property_impls() : CID->property_impls()) + RewritePropertyImplDecl(I, IMD, CID); InsertText(IMD ? IMD->getLocEnd() : CID->getLocEnd(), "// "); } @@ -7220,9 +7216,7 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, // If any of our property implementations have associated getters or // setters, produce metadata for them as well. - for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(), - PropEnd = IDecl->propimpl_end(); - Prop != PropEnd; ++Prop) { + for (const auto *Prop : IDecl->property_impls()) { if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; if (!Prop->getPropertyIvarDecl()) @@ -7475,9 +7469,7 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, // If any of our property implementations have associated getters or // setters, produce metadata for them as well. - for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(), - PropEnd = IDecl->propimpl_end(); - Prop != PropEnd; ++Prop) { + for (const auto *Prop : IDecl->property_impls()) { if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; if (!Prop->getPropertyIvarDecl()) diff --git a/lib/Rewrite/Frontend/RewriteObjC.cpp b/lib/Rewrite/Frontend/RewriteObjC.cpp index 6fe2f1b897..735d1021fe 100644 --- a/lib/Rewrite/Frontend/RewriteObjC.cpp +++ b/lib/Rewrite/Frontend/RewriteObjC.cpp @@ -1197,12 +1197,8 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { const char *endBuf = SM->getCharacterData(LocEnd); ReplaceText(LocStart, endBuf-startBuf, ResultStr); } - for (ObjCCategoryImplDecl::propimpl_iterator - I = IMD ? IMD->propimpl_begin() : CID->propimpl_begin(), - E = IMD ? IMD->propimpl_end() : CID->propimpl_end(); - I != E; ++I) { - RewritePropertyImplDecl(*I, IMD, CID); - } + for (auto *I : IMD ? IMD->property_impls() : CID->property_impls()) + RewritePropertyImplDecl(I, IMD, CID); InsertText(IMD ? IMD->getLocEnd() : CID->getLocEnd(), "// "); } @@ -5429,9 +5425,7 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe // If any of our property implementations have associated getters or // setters, produce metadata for them as well. - for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(), - PropEnd = IDecl->propimpl_end(); - Prop != PropEnd; ++Prop) { + for (const auto *Prop : IDecl->property_impls()) { if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; if (!Prop->getPropertyIvarDecl()) @@ -5710,9 +5704,7 @@ void RewriteObjCFragileABI::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *ID // If any of our property implementations have associated getters or // setters, produce metadata for them as well. - for (ObjCImplDecl::propimpl_iterator Prop = IDecl->propimpl_begin(), - PropEnd = IDecl->propimpl_end(); - Prop != PropEnd; ++Prop) { + for (const auto *Prop : IDecl->property_impls()) { if (Prop->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; if (!Prop->getPropertyIvarDecl()) diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index 7e5f97e13b..3f37efa7c1 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1703,9 +1703,7 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, return; llvm::DenseSet PropImplMap; - for (ObjCImplDecl::propimpl_iterator - I = IMPDecl->propimpl_begin(), - EI = IMPDecl->propimpl_end(); I != EI; ++I) + for (const auto *I : IMPDecl->property_impls()) PropImplMap.insert(I->getPropertyDecl()); SelectorSet InsMap; @@ -1836,9 +1834,7 @@ void Sema::DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D if (getLangOpts().getGC() == LangOptions::GCOnly) return; - for (ObjCImplementationDecl::propimpl_iterator - i = D->propimpl_begin(), e = D->propimpl_end(); i != e; ++i) { - ObjCPropertyImplDecl *PID = *i; + for (const auto *PID : D->property_impls()) { const ObjCPropertyDecl *PD = PID->getPropertyDecl(); if (PD && !PD->hasAttr() && !D->getInstanceMethod(PD->getGetterName())) { diff --git a/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp b/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp index d05dd68237..827a10a746 100644 --- a/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp +++ b/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp @@ -208,9 +208,7 @@ static void checkObjCDealloc(const CheckerBase *Checker, // Scan for missing and extra releases of ivars used by implementations // of synthesized properties - for (ObjCImplementationDecl::propimpl_iterator I = D->propimpl_begin(), - E = D->propimpl_end(); I!=E; ++I) { - + for (const auto *I : D->property_impls()) { // We can only check the synthesized properties if (I->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize) continue; @@ -258,7 +256,7 @@ static void checkObjCDealloc(const CheckerBase *Checker, } PathDiagnosticLocation SDLoc = - PathDiagnosticLocation::createBegin(*I, BR.getSourceManager()); + PathDiagnosticLocation::createBegin(I, BR.getSourceManager()); BR.EmitBasicReport(MD, Checker, name, categories::CoreFoundationObjectiveC, os.str(), SDLoc); diff --git a/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp index ebfc03e0eb..d3b17534fd 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp @@ -83,9 +83,8 @@ static void Scan(IvarUsageMap& M, const ObjCContainerDecl *D) { if (const ObjCImplementationDecl *ID = dyn_cast(D)) { // Scan for @synthesized property methods that act as setters/getters // to an ivar. - for (ObjCImplementationDecl::propimpl_iterator I = ID->propimpl_begin(), - E = ID->propimpl_end(); I!=E; ++I) - Scan(M, *I); + for (const auto *I : ID->property_impls()) + Scan(M, I); // Scan the associated categories as well. for (const auto *Cat : ID->getClassInterface()->visible_categories()) { -- 2.40.0