summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2014-03-13 20:29:09 +0000
committerAaron Ballman <aaron@aaronballman.com>2014-03-13 20:29:09 +0000
commit460fea20dc792a17cbbadfa097140551b5c28e9e (patch)
tree3e8d79d702a20b46dd1a5aa7a5c470f552a5aad9
parentccd9de1bcab5e34983d7911c05df42e254abee94 (diff)
[C++11] Replacing ObjCInterfaceDecl iterators protocol_begin() and protocol_end() with iterator_range protocols(). Updating all of the usages of the iterators with range-based for loops.
Drive-by fixing some incorrect types where a for loop would be improperly using ObjCInterfaceDecl::protocol_iterator. No functional changes in these cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203842 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclObjC.h4
-rw-r--r--lib/AST/DeclObjC.cpp19
-rw-r--r--lib/CodeGen/CGObjCGNU.cpp8
-rw-r--r--lib/Rewrite/Frontend/RewriteModernObjC.cpp4
-rw-r--r--lib/Sema/SemaCodeComplete.cpp6
-rw-r--r--lib/Sema/SemaObjCProperty.cpp7
-rw-r--r--lib/Serialization/ASTWriterDecl.cpp6
-rw-r--r--lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp13
8 files changed, 26 insertions, 41 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 46e5d2f59f..f6b71c8f68 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -823,7 +823,11 @@ public:
}
typedef ObjCProtocolList::iterator protocol_iterator;
+ typedef llvm::iterator_range<protocol_iterator> protocol_range;
+ protocol_range protocols() const {
+ return protocol_range(protocol_begin(), protocol_end());
+ }
protocol_iterator protocol_begin() const {
// FIXME: Should make sure no callers ever do this.
if (!hasDefinition())
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index e721e1f861..4fd152e090 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -555,10 +555,8 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
return MethodDecl;
// Didn't find one yet - look through protocols.
- for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(),
- E = ClassDecl->protocol_end();
- I != E; ++I)
- if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
+ for (const auto *I : ClassDecl->protocols())
+ if ((MethodDecl = I->lookupMethod(Sel, isInstance)))
return MethodDecl;
// Didn't find one yet - now look through categories.
@@ -1004,10 +1002,8 @@ static void CollectOverriddenMethodsRecurse(const ObjCContainerDecl *Container,
if (const ObjCInterfaceDecl *
Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
- for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(),
- PEnd = Interface->protocol_end();
- P != PEnd; ++P)
- CollectOverriddenMethodsRecurse(*P, Method, Methods, MovedToSuper);
+ for (const auto *P : Interface->protocols())
+ CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper);
for (ObjCInterfaceDecl::known_categories_iterator
Cat = Interface->known_categories_begin(),
@@ -1381,9 +1377,8 @@ bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
ObjCInterfaceDecl *IDecl = this;
// 1st, look up the class.
- for (ObjCInterfaceDecl::protocol_iterator
- PI = IDecl->protocol_begin(), E = IDecl->protocol_end(); PI != E; ++PI){
- if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
+ for (auto *PI : IDecl->protocols()){
+ if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI))
return true;
// This is dubious and is added to be compatible with gcc. In gcc, it is
// also allowed assigning a protocol-qualified 'id' type to a LHS object
@@ -1392,7 +1387,7 @@ bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
// FIXME: Treat this as an extension, and flag this as an error when GCC
// extensions are not enabled.
if (RHSIsQualifiedID &&
- getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
+ getASTContext().ProtocolCompatibleWithProtocol(PI, lProto))
return true;
}
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index d64d00a153..9a5ccfa646 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -2252,12 +2252,8 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
}
// Collect the names of referenced protocols
SmallVector<std::string, 16> Protocols;
- for (ObjCInterfaceDecl::protocol_iterator
- I = ClassDecl->protocol_begin(),
- E = ClassDecl->protocol_end(); I != E; ++I)
- Protocols.push_back((*I)->getNameAsString());
-
-
+ for (const auto *I : ClassDecl->protocols())
+ Protocols.push_back(I->getNameAsString());
// Get the superclass pointer.
llvm::Constant *SuperClass;
diff --git a/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/lib/Rewrite/Frontend/RewriteModernObjC.cpp
index 92f747a2e1..f14039272b 100644
--- a/lib/Rewrite/Frontend/RewriteModernObjC.cpp
+++ b/lib/Rewrite/Frontend/RewriteModernObjC.cpp
@@ -7511,8 +7511,8 @@ void RewriteModernObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl,
// Protocols referenced in class declaration?
// Protocol's super protocol list
std::vector<ObjCProtocolDecl *> RefedProtocols;
- for (ObjCInterfaceDecl::protocol_iterator I = CDecl->protocol_begin(),
- E = CDecl->protocol_end();
+ for (ObjCCategoryDecl::protocol_iterator I = CDecl->protocol_begin(),
+ E = CDecl->protocol_end();
I != E; ++I) {
RefedProtocols.push_back(*I);
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index a4bac8dc66..0c02e52e67 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -4852,10 +4852,8 @@ static void AddObjCMethods(ObjCContainerDecl *Container,
return;
// Add methods in protocols.
- for (ObjCInterfaceDecl::protocol_iterator I = IFace->protocol_begin(),
- E = IFace->protocol_end();
- I != E; ++I)
- AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents,
+ for (auto *I : IFace->protocols())
+ AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents,
CurContext, Selectors, AllowSameLength, Results, false);
// Add methods in categories.
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 4c203d3ece..d918aeca15 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -222,11 +222,8 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
if (FoundInSuper) {
// Also compare the property against a property in our protocols.
- for (ObjCInterfaceDecl::protocol_iterator
- P = CurrentInterfaceDecl->protocol_begin(),
- PEnd = CurrentInterfaceDecl->protocol_end();
- P != PEnd; ++P) {
- CheckPropertyAgainstProtocol(*this, Res, *P, KnownProtos);
+ for (auto *P : CurrentInterfaceDecl->protocols()) {
+ CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
}
} else {
// Slower path: look in all protocols we referenced.
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index 18a196cf3a..96cf0e1dc1 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -491,10 +491,8 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
// Write out the protocols that are directly referenced by the @interface.
Record.push_back(Data.ReferencedProtocols.size());
- for (ObjCInterfaceDecl::protocol_iterator P = D->protocol_begin(),
- PEnd = D->protocol_end();
- P != PEnd; ++P)
- Writer.AddDeclRef(*P, Record);
+ for (const auto *P : D->protocols())
+ Writer.AddDeclRef(P, Record);
for (ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(),
PLEnd = D->protocol_loc_end();
PL != PLEnd; ++PL)
diff --git a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
index b11b1d9c0d..ed0e460b3a 100644
--- a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -257,11 +257,8 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod(
if (const ObjCInterfaceDecl *InterfD = dyn_cast<ObjCInterfaceDecl>(D)) {
// Visit all protocols.
- for (ObjCInterfaceDecl::protocol_iterator
- I = InterfD->protocol_begin(),
- E = InterfD->protocol_end(); I != E; ++I) {
- containsInvalidationMethod((*I)->getDefinition(), OutInfo, Partial);
- }
+ for (const auto *I : InterfD->protocols())
+ containsInvalidationMethod(I->getDefinition(), OutInfo, Partial);
// Visit all categories in case the invalidation method is declared in
// a category.
@@ -278,9 +275,9 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod(
// If protocol, check all parent protocols.
if (const ObjCProtocolDecl *ProtD = dyn_cast<ObjCProtocolDecl>(D)) {
- for (ObjCInterfaceDecl::protocol_iterator
- I = ProtD->protocol_begin(),
- E = ProtD->protocol_end(); I != E; ++I) {
+ for (ObjCProtocolDecl::protocol_iterator I = ProtD->protocol_begin(),
+ E = ProtD->protocol_end();
+ I != E; ++I) {
containsInvalidationMethod((*I)->getDefinition(), OutInfo, Partial);
}
return;