From 94d23bc5f456bf21b0984662e15b13fbe1407d12 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 13 Mar 2014 19:03:34 +0000 Subject: [PATCH] [C++11] Replacing ObjCContainerDecl iterators meth_begin() and meth_end() with iterator_range methods(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203832 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclObjC.h | 6 +++++ lib/ARCMigrate/ObjCMT.cpp | 19 ++++------------ lib/CodeGen/CodeGenModule.cpp | 6 ++--- lib/Sema/SemaCodeComplete.cpp | 22 +++++++------------ lib/Sema/SemaDeclObjC.cpp | 9 ++------ lib/Serialization/ASTReader.cpp | 5 ++--- .../Checkers/IvarInvalidationChecker.cpp | 12 ++++------ 7 files changed, 28 insertions(+), 51 deletions(-) diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index bf3c52c460..237aa710c5 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -534,6 +534,12 @@ public: // Iterator access to instance/class methods. typedef specific_decl_iterator method_iterator; + typedef llvm::iterator_range> + method_range; + + method_range methods() const { + return method_range(meth_begin(), meth_end()); + } method_iterator meth_begin() const { return method_iterator(decls_begin()); } diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 4453590d45..5082ea7170 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -471,9 +471,7 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, if (D->isDeprecated() || IsCategoryNameWithDeprecatedSuffix(D)) return; - for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end(); - M != MEnd; ++M) { - ObjCMethodDecl *Method = (*M); + for (auto *Method : D->methods()) { if (Method->isDeprecated()) continue; bool PropertyInferred = migrateProperty(Ctx, D, Method); @@ -535,9 +533,7 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx, if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) { if (PDecl->meth_begin() == PDecl->meth_end()) return HasAtleastOneRequiredProperty; - for (ObjCContainerDecl::method_iterator M = PDecl->meth_begin(), - MEnd = PDecl->meth_end(); M != MEnd; ++M) { - ObjCMethodDecl *MD = (*M); + for (const auto *MD : PDecl->methods()) { if (MD->isImplicit()) continue; if (MD->getImplementationControl() == ObjCMethodDecl::Optional) @@ -1160,10 +1156,7 @@ void ObjCMigrateASTConsumer::migrateAllMethodInstaceType(ASTContext &Ctx, return; // migrate methods which can have instancetype as their result type. - for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(), - MEnd = CDecl->meth_end(); - M != MEnd; ++M) { - ObjCMethodDecl *Method = (*M); + for (auto *Method : CDecl->methods()) { if (Method->isDeprecated()) continue; migrateMethodInstanceType(Ctx, CDecl, Method); @@ -1447,12 +1440,8 @@ void ObjCMigrateASTConsumer::migrateARCSafeAnnotation(ASTContext &Ctx, return; // migrate methods which can have instancetype as their result type. - for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(), - MEnd = CDecl->meth_end(); - M != MEnd; ++M) { - ObjCMethodDecl *Method = (*M); + for (const auto *Method : CDecl->methods()) migrateCFAnnotation(Ctx, Method); - } } void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx, diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index f4b47ec579..98588a4122 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2851,10 +2851,8 @@ void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) { // Meta-data for ObjC class includes references to implemented methods. // Generate class's method definitions first. if (auto *OID = dyn_cast(I)) { - for (ObjCContainerDecl::method_iterator M = OID->meth_begin(), - MEnd = OID->meth_end(); - M != MEnd; ++M) - EmitTopLevelDecl(*M); + for (auto *M : OID->methods()) + EmitTopLevelDecl(M); } EmitTopLevelDecl(I); } diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index f1da3b4ad1..b9a96478d0 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -3467,19 +3467,17 @@ static void AddObjCProperties(ObjCContainerDecl *Container, if (AllowNullaryMethods) { ASTContext &Context = Container->getASTContext(); PrintingPolicy Policy = getCompletionPrintingPolicy(Results.getSema()); - for (ObjCContainerDecl::method_iterator M = Container->meth_begin(), - MEnd = Container->meth_end(); - M != MEnd; ++M) { + for (auto *M : Container->methods()) { if (M->getSelector().isUnarySelector()) if (IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0)) if (AddedProperties.insert(Name)) { CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); - AddResultTypeChunk(Context, Policy, *M, Builder); + AddResultTypeChunk(Context, Policy, M, Builder); Builder.AddTypedTextChunk( Results.getAllocator().CopyString(Name->getName())); - Results.MaybeAddResult(Result(Builder.TakeString(), *M, + Results.MaybeAddResult(Result(Builder.TakeString(), M, CCP_MemberDeclaration + CCD_MethodAsProperty), CurContext); } @@ -4815,22 +4813,20 @@ static void AddObjCMethods(ObjCContainerDecl *Container, Container = getContainerDef(Container); ObjCInterfaceDecl *IFace = dyn_cast(Container); bool isRootClass = IFace && !IFace->getSuperClass(); - for (ObjCContainerDecl::method_iterator M = Container->meth_begin(), - MEnd = Container->meth_end(); - M != MEnd; ++M) { + for (auto *M : Container->methods()) { // The instance methods on the root class can be messaged via the // metaclass. if (M->isInstanceMethod() == WantInstanceMethods || (isRootClass && !WantInstanceMethods)) { // Check whether the selector identifiers we've been given are a // subset of the identifiers for this particular method. - if (!isAcceptableObjCMethod(*M, WantKind, SelIdents, AllowSameLength)) + if (!isAcceptableObjCMethod(M, WantKind, SelIdents, AllowSameLength)) continue; if (!Selectors.insert(M->getSelector())) continue; - Result R = Result(*M, Results.getBasePriority(*M), 0); + Result R = Result(M, Results.getBasePriority(M), 0); R.StartParameter = SelIdents.size(); R.AllParametersAreInformative = (WantKind != MK_Any); if (!InOriginalClass) @@ -6154,16 +6150,14 @@ static void FindImplementableMethods(ASTContext &Context, // Add methods in this container. This operation occurs last because // we want the methods from this container to override any methods // we've previously seen with the same selector. - for (ObjCContainerDecl::method_iterator M = Container->meth_begin(), - MEnd = Container->meth_end(); - M != MEnd; ++M) { + for (auto *M : Container->methods()) { if (M->isInstanceMethod() == WantInstanceMethods) { if (!ReturnType.isNull() && !Context.hasSameUnqualifiedType(ReturnType, M->getReturnType())) continue; KnownMethods[M->getSelector()] = - KnownMethodsMap::mapped_type(*M, InOriginalClass); + KnownMethodsMap::mapped_type(M, InOriginalClass); } } } diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index eb094b5625..efa8cbd485 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -833,17 +833,12 @@ void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, return; // Possibly due to previous error llvm::DenseMap MethodMap; - for (ObjCInterfaceDecl::method_iterator i = ID->meth_begin(), - e = ID->meth_end(); i != e; ++i) { - ObjCMethodDecl *MD = *i; + for (auto *MD : ID->methods()) MethodMap[MD->getSelector()] = MD; - } if (MethodMap.empty()) return; - for (ObjCCategoryDecl::method_iterator i = CAT->meth_begin(), - e = CAT->meth_end(); i != e; ++i) { - ObjCMethodDecl *Method = *i; + for (const auto *Method : CAT->methods()) { const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()]; if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 5d175bb720..62bc2246d2 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -6279,9 +6279,8 @@ static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, ASTConsumer *Consumer) { assert(ImplD && Consumer); - for (ObjCImplDecl::method_iterator - I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) - Consumer->HandleInterestingDecl(DeclGroupRef(*I)); + for (auto *I : ImplD->methods()) + Consumer->HandleInterestingDecl(DeclGroupRef(I)); Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); } diff --git a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index 3b794f2325..b11b1d9c0d 100644 --- a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -248,14 +248,10 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod( // TODO: Cache the results. // Check all methods. - for (ObjCContainerDecl::method_iterator - I = D->meth_begin(), - E = D->meth_end(); I != E; ++I) { - const ObjCMethodDecl *MDI = *I; - if (isInvalidationMethod(MDI, Partial)) - OutInfo.addInvalidationMethod( - cast(MDI->getCanonicalDecl())); - } + for (const auto *MDI : D->methods()) + if (isInvalidationMethod(MDI, Partial)) + OutInfo.addInvalidationMethod( + cast(MDI->getCanonicalDecl())); // If interface, check all parent protocols and super. if (const ObjCInterfaceDecl *InterfD = dyn_cast(D)) { -- 2.40.0