[C++11] Replacing ObjCContainerDecl iterators prop_begin() and prop_end() with iterator_range props(). Updating all of the usages of the iterators with range-based for loops.

llvm-svn: 203830
This commit is contained in:
Aaron Ballman 2014-03-13 18:47:37 +00:00
parent 8d62008ecb
commit dc4bea4676
13 changed files with 61 additions and 130 deletions

View File

@ -521,6 +521,10 @@ public:
// Iterator access to properties.
typedef specific_decl_iterator<ObjCPropertyDecl> prop_iterator;
typedef llvm::iterator_range<specific_decl_iterator<ObjCPropertyDecl>>
prop_range;
prop_range props() const { return prop_range(prop_begin(), prop_end()); }
prop_iterator prop_begin() const {
return prop_iterator(decls_begin());
}

View File

@ -488,9 +488,7 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx,
if (!(ASTMigrateActions & FrontendOptions::ObjCMT_ReturnsInnerPointerProperty))
return;
for (ObjCContainerDecl::prop_iterator P = D->prop_begin(),
E = D->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : D->props()) {
if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) &&
!Prop->isDeprecated())
migratePropertyNsReturnsInnerPointer(Ctx, Prop);
@ -507,9 +505,7 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
// in class interface.
bool HasAtleastOneRequiredProperty = false;
if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition())
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Property = *P;
for (const auto *Property : PDecl->props()) {
if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
continue;
HasAtleastOneRequiredProperty = true;

View File

@ -75,17 +75,15 @@ public:
static void collectProperties(ObjCContainerDecl *D, AtPropDeclsTy &AtProps,
AtPropDeclsTy *PrevAtProps = 0) {
for (ObjCInterfaceDecl::prop_iterator
propI = D->prop_begin(),
propE = D->prop_end(); propI != propE; ++propI) {
if (propI->getAtLoc().isInvalid())
for (auto *Prop : D->props()) {
if (Prop->getAtLoc().isInvalid())
continue;
unsigned RawLoc = propI->getAtLoc().getRawEncoding();
unsigned RawLoc = Prop->getAtLoc().getRawEncoding();
if (PrevAtProps)
if (PrevAtProps->find(RawLoc) != PrevAtProps->end())
continue;
PropsTy &props = AtProps[RawLoc];
props.push_back(*propI);
props.push_back(Prop);
}
}

View File

@ -125,8 +125,7 @@ ObjCContainerDecl::HasUserDeclaredSetterMethod(const ObjCPropertyDecl *Property)
// Also search through the categories looking for a 'readwrite' declaration
// of this property. If one found, presumably a setter will be provided
// (properties declared in categories will not get auto-synthesized).
for (ObjCContainerDecl::prop_iterator P = Cat->prop_begin(),
E = Cat->prop_end(); P != E; ++P)
for (const auto *P : Cat->props())
if (P->getIdentifier() == Property->getIdentifier()) {
if (P->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite)
return true;
@ -286,9 +285,7 @@ ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
void ObjCInterfaceDecl::collectPropertiesToImplement(PropertyMap &PM,
PropertyDeclOrder &PO) const {
for (ObjCContainerDecl::prop_iterator P = prop_begin(),
E = prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : props()) {
PM[Prop->getIdentifier()] = Prop;
PO.push_back(Prop);
}
@ -1114,13 +1111,11 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
bool IsGetter = (NumArgs == 0);
for (ObjCContainerDecl::prop_iterator I = Container->prop_begin(),
E = Container->prop_end();
I != E; ++I) {
Selector NextSel = IsGetter ? (*I)->getGetterName()
: (*I)->getSetterName();
for (const auto *I : Container->props()) {
Selector NextSel = IsGetter ? I->getGetterName()
: I->getSetterName();
if (NextSel == Sel)
return *I;
return I;
}
llvm_unreachable("Marked as a property accessor but no property found!");
@ -1606,9 +1601,7 @@ void ObjCProtocolDecl::collectPropertiesToImplement(PropertyMap &PM,
PropertyDeclOrder &PO) const {
if (const ObjCProtocolDecl *PDecl = getDefinition()) {
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : PDecl->props()) {
// Insert into PM if not there already.
PM.insert(std::make_pair(Prop->getIdentifier(), Prop));
PO.push_back(Prop);
@ -1626,9 +1619,7 @@ void ObjCProtocolDecl::collectInheritedProtocolProperties(
ProtocolPropertyMap &PM) const {
if (const ObjCProtocolDecl *PDecl = getDefinition()) {
bool MatchFound = false;
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : PDecl->props()) {
if (Prop == Property)
continue;
if (Prop->getIdentifier() == Property->getIdentifier()) {

View File

@ -1668,9 +1668,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
}
// Create entries for all of the properties.
for (ObjCContainerDecl::prop_iterator I = ID->prop_begin(),
E = ID->prop_end(); I != E; ++I) {
const ObjCPropertyDecl *PD = *I;
for (const auto *PD : ID->props()) {
SourceLocation Loc = PD->getLocation();
llvm::DIFile PUnit = getOrCreateFile(Loc);
unsigned PLine = getLineNumber(Loc);

View File

@ -1822,11 +1822,8 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
// Add all of the property methods need adding to the method list and to the
// property metadata list.
for (ObjCContainerDecl::prop_iterator
iter = PD->prop_begin(), endIter = PD->prop_end();
iter != endIter ; iter++) {
for (auto *property : PD->props()) {
std::vector<llvm::Constant*> Fields;
ObjCPropertyDecl *property = *iter;
Fields.push_back(MakePropertyEncodingString(property, 0));
PushPropertyAttributes(Fields, property);

View File

@ -999,7 +999,7 @@ protected:
llvm::SmallPtrSet<const IdentifierInfo*, 16> &PropertySet,
SmallVectorImpl<llvm::Constant*> &Properties,
const Decl *Container,
const ObjCProtocolDecl *PROTO,
const ObjCProtocolDecl *Proto,
const ObjCCommonTypesHelper &ObjCTypes);
/// GetProtocolRef - Return a reference to the internal protocol
@ -2773,14 +2773,12 @@ void CGObjCCommonMac::
PushProtocolProperties(llvm::SmallPtrSet<const IdentifierInfo*,16> &PropertySet,
SmallVectorImpl<llvm::Constant *> &Properties,
const Decl *Container,
const ObjCProtocolDecl *PROTO,
const ObjCProtocolDecl *Proto,
const ObjCCommonTypesHelper &ObjCTypes) {
for (ObjCProtocolDecl::protocol_iterator P = PROTO->protocol_begin(),
E = PROTO->protocol_end(); P != E; ++P)
for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(),
E = Proto->protocol_end(); P != E; ++P)
PushProtocolProperties(PropertySet, Properties, Container, (*P), ObjCTypes);
for (ObjCContainerDecl::prop_iterator I = PROTO->prop_begin(),
E = PROTO->prop_end(); I != E; ++I) {
const ObjCPropertyDecl *PD = *I;
for (const auto *PD : Proto->props()) {
if (!PropertySet.insert(PD->getIdentifier()))
continue;
llvm::Constant *Prop[] = {
@ -2809,9 +2807,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
const ObjCCommonTypesHelper &ObjCTypes) {
SmallVector<llvm::Constant *, 16> Properties;
llvm::SmallPtrSet<const IdentifierInfo*, 16> PropertySet;
for (ObjCContainerDecl::prop_iterator I = OCD->prop_begin(),
E = OCD->prop_end(); I != E; ++I) {
const ObjCPropertyDecl *PD = *I;
for (const auto *PD : OCD->props()) {
PropertySet.insert(PD->getIdentifier());
llvm::Constant *Prop[] = {
GetPropertyName(PD->getIdentifier()),

View File

@ -1160,9 +1160,8 @@ void RewriteModernObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
ReplaceText(LocStart, 0, "// ");
}
for (ObjCCategoryDecl::prop_iterator I = CatDecl->prop_begin(),
E = CatDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
for (auto *I : CatDecl->props())
RewriteProperty(I);
for (ObjCCategoryDecl::instmeth_iterator
I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end();
@ -1194,9 +1193,8 @@ void RewriteModernObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
I != E; ++I)
RewriteMethodDeclaration(*I);
for (ObjCInterfaceDecl::prop_iterator I = PDecl->prop_begin(),
E = PDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
for (auto *I : PDecl->props())
RewriteProperty(I);
// Lastly, comment out the @end.
SourceLocation LocEnd = PDecl->getAtEndRange().getBegin();
@ -1453,9 +1451,8 @@ void RewriteModernObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) {
// Mark this typedef as having been written into its c++ equivalent.
ObjCWrittenInterfaces.insert(ClassDecl->getCanonicalDecl());
for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(),
E = ClassDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
for (auto *I : ClassDecl->props())
RewriteProperty(I);
for (ObjCInterfaceDecl::instmeth_iterator
I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end();
I != E; ++I)
@ -7089,11 +7086,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl,
PDecl->getNameAsString(), false);
// Protocol's property metadata.
std::vector<ObjCPropertyDecl *> ProtocolProperties;
for (ObjCContainerDecl::prop_iterator I = PDecl->prop_begin(),
E = PDecl->prop_end(); I != E; ++I)
ProtocolProperties.push_back(*I);
SmallVector<ObjCPropertyDecl *, 8> ProtocolProperties(PDecl->props());
Write_prop_list_t_initializer(*this, Context, Result, ProtocolProperties,
/* Container */0,
"_OBJC_PROTOCOL_PROPERTIES_",
@ -7310,11 +7303,7 @@ void RewriteModernObjC::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl,
IDecl->getNameAsString());
// Protocol's property metadata.
std::vector<ObjCPropertyDecl *> ClassProperties;
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
E = CDecl->prop_end(); I != E; ++I)
ClassProperties.push_back(*I);
SmallVector<ObjCPropertyDecl *, 8> ClassProperties(CDecl->props());
Write_prop_list_t_initializer(*this, Context, Result, ClassProperties,
/* Container */IDecl,
"_OBJC_$_PROP_LIST_",
@ -7569,11 +7558,7 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl,
FullCategoryName);
// Protocol's property metadata.
std::vector<ObjCPropertyDecl *> ClassProperties;
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
E = CDecl->prop_end(); I != E; ++I)
ClassProperties.push_back(*I);
SmallVector<ObjCPropertyDecl *, 8> ClassProperties(CDecl->props());
Write_prop_list_t_initializer(*this, Context, Result, ClassProperties,
/* Container */IDecl,
"_OBJC_$_PROP_LIST_",

View File

@ -980,9 +980,8 @@ void RewriteObjC::RewriteCategoryDecl(ObjCCategoryDecl *CatDecl) {
// FIXME: handle category headers that are declared across multiple lines.
ReplaceText(LocStart, 0, "// ");
for (ObjCCategoryDecl::prop_iterator I = CatDecl->prop_begin(),
E = CatDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
for (auto *I : CatDecl->props())
RewriteProperty(I);
for (ObjCCategoryDecl::instmeth_iterator
I = CatDecl->instmeth_begin(), E = CatDecl->instmeth_end();
@ -1014,9 +1013,8 @@ void RewriteObjC::RewriteProtocolDecl(ObjCProtocolDecl *PDecl) {
I != E; ++I)
RewriteMethodDeclaration(*I);
for (ObjCInterfaceDecl::prop_iterator I = PDecl->prop_begin(),
E = PDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
for (auto *I : PDecl->props())
RewriteProperty(I);
// Lastly, comment out the @end.
SourceLocation LocEnd = PDecl->getAtEndRange().getBegin();
@ -1245,9 +1243,8 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) {
}
RewriteObjCInternalStruct(ClassDecl, ResultStr);
for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(),
E = ClassDecl->prop_end(); I != E; ++I)
RewriteProperty(*I);
for (auto *I : ClassDecl->props())
RewriteProperty(I);
for (ObjCInterfaceDecl::instmeth_iterator
I = ClassDecl->instmeth_begin(), E = ClassDecl->instmeth_end();
I != E; ++I)

View File

@ -3458,14 +3458,10 @@ static void AddObjCProperties(ObjCContainerDecl *Container,
Container = getContainerDef(Container);
// Add properties in this container.
for (ObjCContainerDecl::prop_iterator P = Container->prop_begin(),
PEnd = Container->prop_end();
P != PEnd;
++P) {
for (const auto *P : Container->props())
if (AddedProperties.insert(P->getIdentifier()))
Results.MaybeAddResult(Result(*P, Results.getBasePriority(*P), 0),
Results.MaybeAddResult(Result(P, Results.getBasePriority(P), 0),
CurContext);
}
// Add nullary methods
if (AllowNullaryMethods) {
@ -6981,14 +6977,10 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S,
}
}
for (unsigned I = 0, N = Containers.size(); I != N; ++I) {
for (ObjCContainerDecl::prop_iterator P = Containers[I]->prop_begin(),
PEnd = Containers[I]->prop_end();
P != PEnd; ++P) {
AddObjCKeyValueCompletions(*P, IsInstanceMethod, ReturnType, Context,
for (unsigned I = 0, N = Containers.size(); I != N; ++I)
for (auto *P : Containers[I]->props())
AddObjCKeyValueCompletions(P, IsInstanceMethod, ReturnType, Context,
KnownSelectors, Results);
}
}
}
Results.ExitScope();

View File

@ -2680,10 +2680,8 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef<Decl *> allMethods,
// ProcessPropertyDecl is responsible for diagnosing conflicts with any
// user-defined setter/getter. It also synthesizes setter/getter methods
// and adds them to the DeclContext and global method pools.
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
E = CDecl->prop_end();
I != E; ++I)
ProcessPropertyDecl(*I, CDecl);
for (auto *I : CDecl->props())
ProcessPropertyDecl(I, CDecl);
CDecl->setAtEndRange(AtEnd);
}
if (ObjCImplementationDecl *IC=dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
@ -2698,9 +2696,7 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef<Decl *> allMethods,
Ext = IDecl->visible_extensions_begin(),
ExtEnd = IDecl->visible_extensions_end();
Ext != ExtEnd; ++Ext) {
for (ObjCContainerDecl::prop_iterator I = Ext->prop_begin(),
E = Ext->prop_end(); I != E; ++I) {
ObjCPropertyDecl *Property = *I;
for (const auto *Property : Ext->props()) {
// Skip over properties declared @dynamic
if (const ObjCPropertyImplDecl *PIDecl
= IC->FindPropertyImplDecl(Property->getIdentifier()))

View File

@ -1446,11 +1446,8 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl,
bool IncludeProtocols = true) {
if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(),
E = IDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : IDecl->props())
PropMap[Prop->getIdentifier()] = Prop;
}
if (IncludeProtocols) {
// Scan through class's protocols.
for (ObjCInterfaceDecl::all_protocol_iterator
@ -1461,11 +1458,8 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl,
}
if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) {
if (!CATDecl->IsClassExtension())
for (ObjCContainerDecl::prop_iterator P = CATDecl->prop_begin(),
E = CATDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : CATDecl->props())
PropMap[Prop->getIdentifier()] = Prop;
}
if (IncludeProtocols) {
// Scan through class's protocols.
for (ObjCCategoryDecl::protocol_iterator PI = CATDecl->protocol_begin(),
@ -1474,9 +1468,7 @@ static void CollectImmediateProperties(ObjCContainerDecl *CDecl,
}
}
else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) {
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Prop = *P;
for (auto *Prop : PDecl->props()) {
ObjCPropertyDecl *PropertyFromSuper = SuperPropMap[Prop->getIdentifier()];
// Exclude property for protocols which conform to class's super-class,
// as super-class has to implement the property.
@ -1523,12 +1515,10 @@ Sema::IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
// look up a property declaration whose one of its accessors is implemented
// by this method.
for (ObjCContainerDecl::prop_iterator P = IFace->prop_begin(),
E = IFace->prop_end(); P != E; ++P) {
ObjCPropertyDecl *property = *P;
if ((property->getGetterName() == IMD->getSelector() ||
property->getSetterName() == IMD->getSelector()) &&
(property->getPropertyIvarDecl() == IV))
for (const auto *Property : IFace->props()) {
if ((Property->getGetterName() == IMD->getSelector() ||
Property->getSetterName() == IMD->getSelector()) &&
(Property->getPropertyIvarDecl() == IV))
return true;
}
return false;
@ -1733,13 +1723,10 @@ void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
}
// Add the properties of 'PDecl' to the list of properties that
// need to be implemented.
for (ObjCProtocolDecl::prop_iterator
PRI = PDecl->prop_begin(), PRE = PDecl->prop_end();
PRI != PRE; ++PRI) {
ObjCPropertyDecl *PropDecl = *PRI;
if ((*LazyMap)[PRI->getIdentifier()])
for (auto *PropDecl : PDecl->props()) {
if ((*LazyMap)[PropDecl->getIdentifier()])
continue;
PropMap[PRI->getIdentifier()] = PropDecl;
PropMap[PropDecl->getIdentifier()] = PropDecl;
}
}
}
@ -1799,10 +1786,7 @@ Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl,
// Rules apply in non-GC mode only
if (getLangOpts().getGC() != LangOptions::NonGC)
return;
for (ObjCContainerDecl::prop_iterator I = IDecl->prop_begin(),
E = IDecl->prop_end();
I != E; ++I) {
ObjCPropertyDecl *Property = *I;
for (const auto *Property : IDecl->props()) {
ObjCMethodDecl *GetterMethod = 0;
ObjCMethodDecl *SetterMethod = 0;
bool LookedUpGetterSetter = false;

View File

@ -124,10 +124,7 @@ void DirectIvarAssignment::checkASTDecl(const ObjCImplementationDecl *D,
IvarToPropertyMapTy IvarToPropMap;
// Find all properties for this class.
for (ObjCInterfaceDecl::prop_iterator I = InterD->prop_begin(),
E = InterD->prop_end(); I != E; ++I) {
ObjCPropertyDecl *PD = *I;
for (const auto *PD : InterD->props()) {
// Find the corresponding IVar.
const ObjCIvarDecl *ID = findPropertyBackingIvar(PD, InterD,
Mgr.getASTContext());