]> granicus.if.org Git - clang/commitdiff
[C++11] Replacing ObjCInterfaceDecl iterators protocol_begin() and protocol_end(...
authorAaron Ballman <aaron@aaronballman.com>
Thu, 13 Mar 2014 20:29:09 +0000 (20:29 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 13 Mar 2014 20:29:09 +0000 (20:29 +0000)
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

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/CodeGen/CGObjCGNU.cpp
lib/Rewrite/Frontend/RewriteModernObjC.cpp
lib/Sema/SemaCodeComplete.cpp
lib/Sema/SemaObjCProperty.cpp
lib/Serialization/ASTWriterDecl.cpp
lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp

index 46e5d2f59f66b4f5d44544cb9967d3862395b9fc..f6b71c8f6899bdd9af61b185d7084f526f868f1c 100644 (file)
@@ -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())
index e721e1f861fcd14876f4a01028549c5e86c609f6..4fd152e0902950c0bebf7b8d09247ce4e2319b00 100644 (file)
@@ -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;
   }
 
index d64d00a153cc5ddeee2ccc391f6309febe657e44..9a5ccfa646ca3df3873ff5d413a952458b82c17c 100644 (file)
@@ -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;
index 92f747a2e1e6d899fc7137b406b8db80be419c1f..f14039272be24cd5f58f02a864958fca832d1fbe 100644 (file)
@@ -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);
index a4bac8dc66cf37b55303f0aff87f382538fab558..0c02e52e67bed3c65ead9c4a8aa2e70ede1ea454 100644 (file)
@@ -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.
index 4c203d3ece8cf1c6a94abbaa7bec54eb60f6359e..d918aeca15b636997ca04af4b58360f5fa1f2c04 100644 (file)
@@ -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.
index 18a196cf3a8a35bfde84d871962ffc097b53fae8..96cf0e1dc11b410bc0898047c73e18faafa7a0d8 100644 (file)
@@ -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)
index b11b1d9c0d6f0bd70942ca5ceb11117141956494..ed0e460b3a52d2744d5e5b67fab92ec87e0b5abf 100644 (file)
@@ -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;