From: Aaron Ballman Date: Mon, 17 Mar 2014 16:14:00 +0000 (+0000) Subject: [C++11] Replacing ObjCObjectPointerType iterators qual_begin() and qual_end() with... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f8e7df26bc2fc6a5ba4873d7c5204a59ec39307;p=clang [C++11] Replacing ObjCObjectPointerType iterators qual_begin() and qual_end() with iterator_range quals(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204048 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index fa08912411..001a87ec28 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -4554,7 +4554,9 @@ public: /// for convenience. This will always iterate over the full set of /// protocols on a type, not just those provided directly. typedef ObjCObjectType::qual_iterator qual_iterator; + typedef llvm::iterator_range qual_range; + qual_range quals() const { return qual_range(qual_begin(), qual_end()); } qual_iterator qual_begin() const { return getObjectType()->qual_begin(); } diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ce12b2f4cb..c02150a6bc 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3514,9 +3514,7 @@ bool ASTContext::ObjCObjectAdoptsQTypeProtocols(QualType QT, if (const ObjCObjectPointerType *OPT = QT->getAs()) { // If both the right and left sides have qualifiers. - for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), - E = OPT->qual_end(); I != E; ++I) { - ObjCProtocolDecl *Proto = *I; + for (auto *Proto : OPT->quals()) { if (!IC->ClassImplementsProtocol(Proto, false)) return false; } @@ -3542,16 +3540,12 @@ bool ASTContext::QIdProtocolsAdoptObjCObjectProtocols(QualType QT, if (InheritedProtocols.empty()) return false; - for (llvm::SmallPtrSet::iterator PI = - InheritedProtocols.begin(), - E = InheritedProtocols.end(); PI != E; ++PI) { + for (auto *PI : InheritedProtocols) { // If both the right and left sides have qualifiers. bool Adopts = false; - for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), - E = OPT->qual_end(); I != E; ++I) { - ObjCProtocolDecl *Proto = *I; + for (auto *Proto : OPT->quals()) { // return 'true' if '*PI' is in the inheritance hierarchy of Proto - if ((Adopts = ProtocolCompatibleWithProtocol(*PI, Proto))) + if ((Adopts = ProtocolCompatibleWithProtocol(PI, Proto))) break; } if (!Adopts) @@ -5455,10 +5449,9 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, // Note that we do extended encoding of protocol qualifer list // Only when doing ivar or property encoding. S += '"'; - for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), - E = OPT->qual_end(); I != E; ++I) { + for (const auto *I : OPT->quals()) { S += '<'; - S += (*I)->getNameAsString(); + S += I->getNameAsString(); S += '>'; } S += '"'; @@ -5501,10 +5494,9 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, (FD || EncodingProperty || EncodeClassNames)) { S += '"'; S += OPT->getInterfaceDecl()->getIdentifier()->getName(); - for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), - E = OPT->qual_end(); I != E; ++I) { + for (const auto *I : OPT->quals()) { S += '<'; - S += (*I)->getNameAsString(); + S += I->getNameAsString(); S += '>'; } S += '"'; @@ -6377,13 +6369,9 @@ bool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, const ObjCObjectPointerType *rhsOPT = rhs->getAs(); assert ((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible"); - for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), - E = lhsQID->qual_end(); I != E; ++I) { + for (auto *lhsProto : lhsQID->quals()) { bool match = false; - ObjCProtocolDecl *lhsProto = *I; - for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), - E = rhsOPT->qual_end(); J != E; ++J) { - ObjCProtocolDecl *rhsProto = *J; + for (auto *rhsProto : rhsOPT->quals()) { if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) { match = true; break; @@ -6416,12 +6404,11 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, // If the RHS is a unqualified interface pointer "NSString*", // make sure we check the class hierarchy. if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { - for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), - E = lhsQID->qual_end(); I != E; ++I) { + for (auto *I : lhsQID->quals()) { // when comparing an id

on lhs with a static type on rhs, // see if static class implements all of id's protocols, directly or // through its super class and categories. - if (!rhsID->ClassImplementsProtocol(*I, true)) + if (!rhsID->ClassImplementsProtocol(I, true)) return false; } } @@ -6429,17 +6416,13 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, return true; } // Both the right and left sides have qualifiers. - for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), - E = lhsQID->qual_end(); I != E; ++I) { - ObjCProtocolDecl *lhsProto = *I; + for (auto *lhsProto : lhsQID->quals()) { bool match = false; // when comparing an id

on lhs with a static type on rhs, // see if static class implements all of id's protocols, directly or // through its super class and categories. - for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), - E = rhsOPT->qual_end(); J != E; ++J) { - ObjCProtocolDecl *rhsProto = *J; + for (auto *rhsProto : rhsOPT->quals()) { if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { match = true; @@ -6449,12 +6432,11 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, // If the RHS is a qualified interface pointer "NSString

*", // make sure we check the class hierarchy. if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { - for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), - E = lhsQID->qual_end(); I != E; ++I) { + for (auto *I : lhsQID->quals()) { // when comparing an id

on lhs with a static type on rhs, // see if static class implements all of id's protocols, directly or // through its super class and categories. - if (rhsID->ClassImplementsProtocol(*I, true)) { + if (rhsID->ClassImplementsProtocol(I, true)) { match = true; break; } @@ -6473,9 +6455,7 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, if (const ObjCObjectPointerType *lhsOPT = lhs->getAsObjCInterfacePointerType()) { // If both the right and left sides have qualifiers. - for (ObjCObjectPointerType::qual_iterator I = lhsOPT->qual_begin(), - E = lhsOPT->qual_end(); I != E; ++I) { - ObjCProtocolDecl *lhsProto = *I; + for (auto *lhsProto : lhsOPT->quals()) { bool match = false; // when comparing an id

on rhs with a static type on lhs, @@ -6483,9 +6463,7 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, // through its super class and categories. // First, lhs protocols in the qualifier list must be found, direct // or indirect in rhs's qualifier list or it is a mismatch. - for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), - E = rhsQID->qual_end(); J != E; ++J) { - ObjCProtocolDecl *rhsProto = *J; + for (auto *rhsProto : rhsQID->quals()) { if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { match = true; @@ -6506,14 +6484,9 @@ bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, // assume that it is mismatch. if (LHSInheritedProtocols.empty() && lhsOPT->qual_empty()) return false; - for (llvm::SmallPtrSet::iterator I = - LHSInheritedProtocols.begin(), - E = LHSInheritedProtocols.end(); I != E; ++I) { + for (auto *lhsProto : LHSInheritedProtocols) { bool match = false; - ObjCProtocolDecl *lhsProto = (*I); - for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), - E = rhsQID->qual_end(); J != E; ++J) { - ObjCProtocolDecl *rhsProto = *J; + for (auto *rhsProto : rhsQID->quals()) { if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { match = true; diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index b3bc7b3169..fe32382226 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -3604,10 +3604,8 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, AddedProperties, Results); // Add properties from the protocols in a qualified interface. - for (ObjCObjectPointerType::qual_iterator I = ObjCPtr->qual_begin(), - E = ObjCPtr->qual_end(); - I != E; ++I) - AddObjCProperties(*I, true, /*AllowNullaryMethods=*/true, CurContext, + for (auto *I : ObjCPtr->quals()) + AddObjCProperties(I, true, /*AllowNullaryMethods=*/true, CurContext, AddedProperties, Results); } else if ((IsArrow && BaseType->isObjCObjectPointerType()) || (!IsArrow && BaseType->isObjCObjectType())) { @@ -5530,10 +5528,8 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, else if (const ObjCObjectPointerType *QualID = ReceiverType->getAsObjCQualifiedIdType()) { // Search protocols for instance methods. - for (ObjCObjectPointerType::qual_iterator I = QualID->qual_begin(), - E = QualID->qual_end(); - I != E; ++I) - AddObjCMethods(*I, true, MK_Any, SelIdents, CurContext, + for (auto *I : QualID->quals()) + AddObjCMethods(I, true, MK_Any, SelIdents, CurContext, Selectors, AtArgumentExpression, Results); } // Handle messages to a pointer to interface type. @@ -5545,10 +5541,8 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, Results); // Search protocols for instance methods. - for (ObjCObjectPointerType::qual_iterator I = IFacePtr->qual_begin(), - E = IFacePtr->qual_end(); - I != E; ++I) - AddObjCMethods(*I, true, MK_Any, SelIdents, CurContext, + for (auto *I : IFacePtr->quals()) + AddObjCMethods(I, true, MK_Any, SelIdents, CurContext, Selectors, AtArgumentExpression, Results); } // Handle messages to "id". diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp index 4e9d250d4a..9f1ac516ea 100644 --- a/lib/Sema/SemaExprMember.cpp +++ b/lib/Sema/SemaExprMember.cpp @@ -398,25 +398,22 @@ static Decl *FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy, ASTContext &Context) { // Check protocols on qualified interfaces. Decl *GDecl = 0; - for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(), - E = QIdTy->qual_end(); I != E; ++I) { + for (const auto *I : QIdTy->quals()) { if (Member) - if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Member)) { + if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration(Member)) { GDecl = PD; break; } // Also must look for a getter or setter name which uses property syntax. - if (ObjCMethodDecl *OMD = (*I)->getInstanceMethod(Sel)) { + if (ObjCMethodDecl *OMD = I->getInstanceMethod(Sel)) { GDecl = OMD; break; } } if (!GDecl) { - for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(), - E = QIdTy->qual_end(); I != E; ++I) { + for (const auto *I : QIdTy->quals()) { // Search in the protocol-qualifier list of current protocol. - GDecl = FindGetterSetterNameDeclFromProtocolList(*I, Member, Sel, - Context); + GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, Context); if (GDecl) return GDecl; } diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 8ca446a2f3..7a3aa46ae6 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1478,9 +1478,7 @@ ObjCMethodDecl *Sema::LookupMethodInQualifiedType(Selector Sel, bool Instance) { ObjCMethodDecl *MD = 0; - for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), - E = OPT->qual_end(); I != E; ++I) { - ObjCProtocolDecl *PROTO = (*I); + for (const auto *PROTO : OPT->quals()) { if ((MD = PROTO->lookupMethod(Sel, Instance))) { return MD; } @@ -1589,9 +1587,8 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, MemberLoc, BaseExpr)); } // Check protocols on qualified interfaces. - for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), - E = OPT->qual_end(); I != E; ++I) - if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Member)) { + for (const auto *I : OPT->quals()) + if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration(Member)) { // Check whether we can reference this property. if (DiagnoseUseOfDecl(PD, MemberLoc)) return ExprError(); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 8495c97e4e..6e8de5875a 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -4072,10 +4072,8 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, // Look in qualified interfaces. if (OPT) { - for (ObjCObjectPointerType::qual_iterator - I = OPT->qual_begin(), E = OPT->qual_end(); - I != E; ++I) - LookupVisibleDecls(*I, LookupKind, Consumer); + for (auto *I : OPT->quals()) + LookupVisibleDecls(I, LookupKind, Consumer); } } else if (SS && SS->isSet()) { QualifiedDC = computeDeclContext(*SS, EnteringContext);