diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index c97c0f1dea87..46e5d2f59f66 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -565,6 +565,11 @@ public: typedef filtered_decl_iterator classmeth_iterator; + typedef llvm::iterator_range classmeth_range; + + classmeth_range class_methods() const { + return classmeth_range(classmeth_begin(), classmeth_end()); + } classmeth_iterator classmeth_begin() const { return classmeth_iterator(decls_begin()); } diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index e55f60564171..d64d00a153cc 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -1780,18 +1780,16 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { SmallVector ClassMethodTypes; SmallVector OptionalClassMethodNames; SmallVector OptionalClassMethodTypes; - for (ObjCProtocolDecl::classmeth_iterator - iter = PD->classmeth_begin(), endIter = PD->classmeth_end(); - iter != endIter ; iter++) { + for (const auto *I : PD->class_methods()) { std::string TypeStr; - Context.getObjCEncodingForMethodDecl((*iter),TypeStr); - if ((*iter)->getImplementationControl() == ObjCMethodDecl::Optional) { + Context.getObjCEncodingForMethodDecl(I,TypeStr); + if (I->getImplementationControl() == ObjCMethodDecl::Optional) { OptionalClassMethodNames.push_back( - MakeConstantString((*iter)->getSelector().getAsString())); + MakeConstantString(I->getSelector().getAsString())); OptionalClassMethodTypes.push_back(MakeConstantString(TypeStr)); } else { ClassMethodNames.push_back( - MakeConstantString((*iter)->getSelector().getAsString())); + MakeConstantString(I->getSelector().getAsString())); ClassMethodTypes.push_back(MakeConstantString(TypeStr)); } } @@ -2013,12 +2011,10 @@ void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) { // Collect information about class methods SmallVector ClassMethodSels; SmallVector ClassMethodTypes; - for (ObjCCategoryImplDecl::classmeth_iterator - iter = OCD->classmeth_begin(), endIter = OCD->classmeth_end(); - iter != endIter ; iter++) { - ClassMethodSels.push_back((*iter)->getSelector()); + for (const auto *I : OCD->class_methods()) { + ClassMethodSels.push_back(I->getSelector()); std::string TypeStr; - CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr); + CGM.getContext().getObjCEncodingForMethodDecl(I,TypeStr); ClassMethodTypes.push_back(MakeConstantString(TypeStr)); } @@ -2248,12 +2244,10 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) { // Collect information about class methods SmallVector ClassMethodSels; SmallVector ClassMethodTypes; - for (ObjCImplementationDecl::classmeth_iterator - iter = OID->classmeth_begin(), endIter = OID->classmeth_end(); - iter != endIter ; iter++) { - ClassMethodSels.push_back((*iter)->getSelector()); + for (const auto *I : OID->class_methods()) { + ClassMethodSels.push_back(I->getSelector()); std::string TypeStr; - Context.getObjCEncodingForMethodDecl((*iter),TypeStr); + Context.getObjCEncodingForMethodDecl(I,TypeStr); ClassMethodTypes.push_back(MakeConstantString(TypeStr)); } // Collect the names of referenced protocols diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index d763c4af01e6..98bdb16889d5 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -2603,9 +2603,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) { } } - for (ObjCProtocolDecl::classmeth_iterator - i = PD->classmeth_begin(), e = PD->classmeth_end(); i != e; ++i) { - ObjCMethodDecl *MD = *i; + for (const auto *MD : PD->class_methods()) { llvm::Constant *C = GetMethodDescriptionConstant(MD); if (!C) return GetOrEmitProtocolRef(PD); @@ -2941,11 +2939,9 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { // Instance methods should always be defined. InstanceMethods.push_back(GetMethodConstant(I)); - for (ObjCCategoryImplDecl::classmeth_iterator - i = OCD->classmeth_begin(), e = OCD->classmeth_end(); i != e; ++i) { + for (const auto *I : OCD->class_methods()) // Class methods should always be defined. - ClassMethods.push_back(GetMethodConstant(*i)); - } + ClassMethods.push_back(GetMethodConstant(I)); llvm::Constant *Values[7]; Values[0] = GetClassName(OCD->getIdentifier()); @@ -3068,11 +3064,9 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { // Instance methods should always be defined. InstanceMethods.push_back(GetMethodConstant(I)); - for (ObjCImplementationDecl::classmeth_iterator - i = ID->classmeth_begin(), e = ID->classmeth_end(); i != e; ++i) { + for (const auto *I : ID->class_methods()) // Class methods should always be defined. - ClassMethods.push_back(GetMethodConstant(*i)); - } + ClassMethods.push_back(GetMethodConstant(I)); for (ObjCImplementationDecl::propimpl_iterator i = ID->propimpl_begin(), e = ID->propimpl_end(); i != e; ++i) { @@ -5653,11 +5647,9 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer( std::string MethodListName("\01l_OBJC_$_"); if (flags & NonFragileABI_Class_Meta) { MethodListName += "CLASS_METHODS_" + ID->getNameAsString(); - for (ObjCImplementationDecl::classmeth_iterator - i = ID->classmeth_begin(), e = ID->classmeth_end(); i != e; ++i) { + for (const auto *I : ID->class_methods()) // Class methods should always be defined. - Methods.push_back(GetMethodConstant(*i)); - } + Methods.push_back(GetMethodConstant(I)); } else { MethodListName += "INSTANCE_METHODS_" + ID->getNameAsString(); for (const auto *I : ID->instance_methods()) @@ -5998,11 +5990,9 @@ void CGObjCNonFragileABIMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { MethodListName += "CLASS_METHODS_" + Interface->getNameAsString() + "_$_" + OCD->getNameAsString(); Methods.clear(); - for (ObjCCategoryImplDecl::classmeth_iterator - i = OCD->classmeth_begin(), e = OCD->classmeth_end(); i != e; ++i) { + for (const auto *I : OCD->class_methods()) // Class methods should always be defined. - Methods.push_back(GetMethodConstant(*i)); - } + Methods.push_back(GetMethodConstant(I)); Values[3] = EmitMethodList(MethodListName, "__DATA, __objc_const", @@ -6289,9 +6279,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( } } - for (ObjCProtocolDecl::classmeth_iterator - i = PD->classmeth_begin(), e = PD->classmeth_end(); i != e; ++i) { - ObjCMethodDecl *MD = *i; + for (const auto *MD : PD->class_methods()) { llvm::Constant *C = GetMethodDescriptionConstant(MD); if (!C) return GetOrEmitProtocolRef(PD); diff --git a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp index 126e563ae6ae..92f747a2e1e6 100644 --- a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -1165,10 +1165,8 @@ void RewriteModernObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { for (auto *I : CatDecl->instance_methods()) RewriteMethodDeclaration(I); - for (ObjCCategoryDecl::classmeth_iterator - I = CatDecl->classmeth_begin(), E = CatDecl->classmeth_end(); - I != E; ++I) - RewriteMethodDeclaration(*I); + for (auto *I : CatDecl->class_methods()) + RewriteMethodDeclaration(I); // Lastly, comment out the @end. ReplaceText(CatDecl->getAtEndRange().getBegin(), @@ -1184,11 +1182,8 @@ void RewriteModernObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { for (auto *I : PDecl->instance_methods()) RewriteMethodDeclaration(I); - for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); - I != E; ++I) - RewriteMethodDeclaration(*I); - + for (auto *I : PDecl->class_methods()) + RewriteMethodDeclaration(I); for (auto *I : PDecl->properties()) RewriteProperty(I); @@ -1399,12 +1394,8 @@ void RewriteModernObjC::RewriteImplementationDecl(Decl *OID) { ReplaceText(LocStart, endBuf-startBuf, ResultStr); } - for (ObjCCategoryImplDecl::classmeth_iterator - I = IMD ? IMD->classmeth_begin() : CID->classmeth_begin(), - E = IMD ? IMD->classmeth_end() : CID->classmeth_end(); - I != E; ++I) { + for (auto *OMD : IMD ? IMD->class_methods() : CID->class_methods()) { std::string ResultStr; - ObjCMethodDecl *OMD = *I; RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr); SourceLocation LocStart = OMD->getLocStart(); SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart(); @@ -1447,10 +1438,8 @@ void RewriteModernObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { RewriteProperty(I); for (auto *I : ClassDecl->instance_methods()) RewriteMethodDeclaration(I); - for (ObjCInterfaceDecl::classmeth_iterator - I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); - I != E; ++I) - RewriteMethodDeclaration(*I); + for (auto *I : ClassDecl->class_methods()) + RewriteMethodDeclaration(I); // Lastly, comment out the @end. ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), @@ -7022,10 +7011,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, } } - for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); - I != E; ++I) { - ObjCMethodDecl *MD = *I; + for (auto *MD : PDecl->class_methods()) { if (MD->getImplementationControl() == ObjCMethodDecl::Optional) { OptClassMethods.push_back(MD); } else { @@ -7263,8 +7249,7 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, "_OBJC_$_INSTANCE_METHODS_", IDecl->getNameAsString(), true); - SmallVector - ClassMethods(IDecl->classmeth_begin(), IDecl->classmeth_end()); + SmallVector ClassMethods(IDecl->class_methods()); Write_method_list_t_initializer(*this, Context, Result, ClassMethods, "_OBJC_$_CLASS_METHODS_", @@ -7517,8 +7502,7 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl, "_OBJC_$_CATEGORY_INSTANCE_METHODS_", FullCategoryName, true); - SmallVector - ClassMethods(IDecl->classmeth_begin(), IDecl->classmeth_end()); + SmallVector ClassMethods(IDecl->class_methods()); Write_method_list_t_initializer(*this, Context, Result, ClassMethods, "_OBJC_$_CATEGORY_CLASS_METHODS_", diff --git a/clang/lib/Rewrite/Frontend/RewriteObjC.cpp b/clang/lib/Rewrite/Frontend/RewriteObjC.cpp index bca2099987ec..6fe2f1b897f3 100644 --- a/clang/lib/Rewrite/Frontend/RewriteObjC.cpp +++ b/clang/lib/Rewrite/Frontend/RewriteObjC.cpp @@ -981,14 +981,11 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) { ReplaceText(LocStart, 0, "// "); for (auto *I : CatDecl->properties()) - RewriteProperty(I); - + RewriteProperty(I); for (auto *I : CatDecl->instance_methods()) RewriteMethodDeclaration(I); - for (ObjCCategoryDecl::classmeth_iterator - I = CatDecl->classmeth_begin(), E = CatDecl->classmeth_end(); - I != E; ++I) - RewriteMethodDeclaration(*I); + for (auto *I : CatDecl->class_methods()) + RewriteMethodDeclaration(I); // Lastly, comment out the @end. ReplaceText(CatDecl->getAtEndRange().getBegin(), @@ -1004,11 +1001,8 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) { for (auto *I : PDecl->instance_methods()) RewriteMethodDeclaration(I); - for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); - I != E; ++I) - RewriteMethodDeclaration(*I); - + for (auto *I : PDecl->class_methods()) + RewriteMethodDeclaration(I); for (auto *I : PDecl->properties()) RewriteProperty(I); @@ -1193,12 +1187,8 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) { ReplaceText(LocStart, endBuf-startBuf, ResultStr); } - for (ObjCCategoryImplDecl::classmeth_iterator - I = IMD ? IMD->classmeth_begin() : CID->classmeth_begin(), - E = IMD ? IMD->classmeth_end() : CID->classmeth_end(); - I != E; ++I) { + for (auto *OMD : IMD ? IMD->class_methods() : CID->class_methods()) { std::string ResultStr; - ObjCMethodDecl *OMD = *I; RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr); SourceLocation LocStart = OMD->getLocStart(); SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart(); @@ -1239,10 +1229,8 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) { RewriteProperty(I); for (auto *I : ClassDecl->instance_methods()) RewriteMethodDeclaration(I); - for (ObjCInterfaceDecl::classmeth_iterator - I = ClassDecl->classmeth_begin(), E = ClassDecl->classmeth_end(); - I != E; ++I) - RewriteMethodDeclaration(*I); + for (auto *I : ClassDecl->class_methods()) + RewriteMethodDeclaration(I); // Lastly, comment out the @end. ReplaceText(ClassDecl->getAtEndRange().getBegin(), strlen("@end"), diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index f4bb2641255f..1b8a466644f0 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1780,10 +1780,7 @@ static void CheckProtocolMethodDefs(Sema &S, } } // check unimplemented class methods - for (ObjCProtocolDecl::classmeth_iterator - I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); - I != E; ++I) { - ObjCMethodDecl *method = *I; + for (auto *method : PDecl->class_methods()) { if (method->getImplementationControl() != ObjCMethodDecl::Optional && !ClsMap.count(method->getSelector()) && (!Super || !Super->lookupMethod(method->getSelector(), @@ -1853,26 +1850,23 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap, // Check and see if class methods in class interface have been // implemented in the implementation class. If so, their types match. - for (ObjCInterfaceDecl::classmeth_iterator I = CDecl->classmeth_begin(), - E = CDecl->classmeth_end(); - I != E; ++I) { - if (!ClsMapSeen.insert((*I)->getSelector())) + for (auto *I : CDecl->class_methods()) { + if (!ClsMapSeen.insert(I->getSelector())) continue; - if (!ClsMap.count((*I)->getSelector())) { + if (!ClsMap.count(I->getSelector())) { if (ImmediateClass) - WarnUndefinedMethod(*this, IMPDecl->getLocation(), *I, IncompleteImpl, + WarnUndefinedMethod(*this, IMPDecl->getLocation(), I, IncompleteImpl, diag::warn_undef_method_impl); } else { ObjCMethodDecl *ImpMethodDecl = - IMPDecl->getClassMethod((*I)->getSelector()); - assert(CDecl->getClassMethod((*I)->getSelector()) && + IMPDecl->getClassMethod(I->getSelector()); + assert(CDecl->getClassMethod(I->getSelector()) && "Expected to find the method through lookup as well"); - ObjCMethodDecl *MethodDecl = *I; if (!WarnCategoryMethodImpl) - WarnConflictingTypedMethods(ImpMethodDecl, MethodDecl, + WarnConflictingTypedMethods(ImpMethodDecl, I, isa(CDecl)); else - WarnExactTypedMethods(ImpMethodDecl, MethodDecl, + WarnExactTypedMethods(ImpMethodDecl, I, isa(CDecl)); } } @@ -1955,10 +1949,8 @@ void Sema::CheckCategoryVsClassMethodMatches( InsMap.insert(Sel); } - for (ObjCImplementationDecl::classmeth_iterator - I = CatIMPDecl->classmeth_begin(), - E = CatIMPDecl->classmeth_end(); I != E; ++I) { - Selector Sel = (*I)->getSelector(); + for (const auto *I : CatIMPDecl->class_methods()) { + Selector Sel = I->getSelector(); if (SuperIDecl && SuperIDecl->lookupMethod(Sel, false)) continue; ClsMap.insert(Sel); @@ -1994,10 +1986,8 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, } SelectorSet ClsMap; - for (ObjCImplementationDecl::classmeth_iterator - I = IMPDecl->classmeth_begin(), - E = IMPDecl->classmeth_end(); I != E; ++I) - ClsMap.insert((*I)->getSelector()); + for (const auto *I : IMPDecl->class_methods()) + ClsMap.insert(I->getSelector()); // Check for type conflict of methods declared in a class/protocol and // its implementation; if any.