[cfe-commits] r136841 - /cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Aug 3 16:44:01 PDT 2011


Author: fjahanian
Date: Wed Aug  3 18:44:01 2011
New Revision: 136841

URL: http://llvm.org/viewvc/llvm-project?rev=136841&view=rev
Log:
Refactoring of my last patch.


Modified:
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=136841&r1=136840&r2=136841&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Aug  3 18:44:01 2011
@@ -1507,11 +1507,11 @@
   }
 }
 
-/// MatchMethodsInClassAndOneProtocol - This routine goes thru list of methods
+/// MatchMethodsInClassAndProtocols - This routine goes thru list of methods
 /// declared in the class, and its class extensions. For each method which is
 /// also declared in one of its qualifying protocols, they must type match or
 /// it issues a warning.
-static void MatchMethodsInClassAndOneProtocol(Sema &S, 
+static void MatchMethodsInClassAndProtocols(Sema &S, 
                                               const ObjCContainerDecl *IDecl,
                               Sema::ProtocolsMethodsMap &InstMethodsInProtocols,
                               Sema::ProtocolsMethodsMap &ClsMethodsInProtocols) {
@@ -1537,11 +1537,34 @@
   if (const ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(IDecl)) {
     for (const ObjCCategoryDecl *ClsExtDecl = I->getFirstClassExtension();
          ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension()) 
-      MatchMethodsInClassAndOneProtocol(S, ClsExtDecl, InstMethodsInProtocols,
+      MatchMethodsInClassAndProtocols(S, ClsExtDecl, InstMethodsInProtocols,
                                         ClsMethodsInProtocols);
   }
 }
 
+/// CollectMethodsInOneProtocol - This routine collects all methods declared
+/// in a given protocol.
+static void CollectMethodsInOneProtocol(const ObjCProtocolDecl *PDecl,
+                              Sema::ProtocolsMethodsMap &InstMethodsInProtocols,
+                              Sema::ProtocolsMethodsMap &ClsMethodsInProtocols) {
+  for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(),
+       E = PDecl->instmeth_end(); I != E; ++I) {
+    ObjCMethodDecl *method = *I;
+    ObjCMethodDecl *&ProtocolEntry = 
+    InstMethodsInProtocols[method->getSelector()];
+    if (!ProtocolEntry)
+      ProtocolEntry = method;
+  }
+  for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(),
+       E = PDecl->classmeth_end(); I != E; ++I) {
+    ObjCMethodDecl *method = *I;
+    ObjCMethodDecl *&ProtocolEntry = 
+    ClsMethodsInProtocols[method->getSelector()];
+    if (!ProtocolEntry)
+      ProtocolEntry = method;
+  }
+}
+
 /// CollectMethodsInProtocols - This routine collects all methods declared
 /// in class's list and nested qualified protocols. Instance methods and 
 /// class methods have separate containers as they have identical selectors.
@@ -1553,27 +1576,12 @@
          PI = CDecl->all_referenced_protocol_begin(),
          E = CDecl->all_referenced_protocol_end(); PI != E; ++PI) {
       ObjCProtocolDecl *PDecl = (*PI);
-      
-      for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(),
-           E = PDecl->instmeth_end(); I != E; ++I) {
-        ObjCMethodDecl *method = *I;
-        ObjCMethodDecl *&ProtocolEntry = 
-          InstMethodsInProtocols[method->getSelector()];
-        if (!ProtocolEntry)
-          ProtocolEntry = method;
-      }
-      for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(),
-           E = PDecl->classmeth_end(); I != E; ++I) {
-        ObjCMethodDecl *method = *I;
-        ObjCMethodDecl *&ProtocolEntry = 
-          ClsMethodsInProtocols[method->getSelector()];
-        if (!ProtocolEntry)
-          ProtocolEntry = method;
-      }
+      CollectMethodsInOneProtocol(PDecl, InstMethodsInProtocols,
+                                  ClsMethodsInProtocols);
       
       for (ObjCProtocolDecl::protocol_iterator P = PDecl->protocol_begin(),
            PE = PDecl->protocol_end(); P != PE; ++P)
-        CollectMethodsInProtocols(*P, InstMethodsInProtocols,
+        CollectMethodsInProtocols((*P), InstMethodsInProtocols,
                                   ClsMethodsInProtocols);
     }
     if (CDecl->getSuperClass())
@@ -1581,24 +1589,9 @@
                                 ClsMethodsInProtocols);
   }
   
-  if (const ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(ContDecl)) {
-    for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(),
-         E = PDecl->instmeth_end(); I != E; ++I) {
-      ObjCMethodDecl *method = *I;
-      ObjCMethodDecl *&ProtocolEntry = 
-        InstMethodsInProtocols[method->getSelector()];
-      if (!ProtocolEntry)
-        ProtocolEntry = method;
-    }
-    for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(),
-         E = PDecl->classmeth_end(); I != E; ++I) {
-      ObjCMethodDecl *method = *I;
-      ObjCMethodDecl *&ProtocolEntry = 
-        ClsMethodsInProtocols[method->getSelector()];
-      if (!ProtocolEntry)
-        ProtocolEntry = method;
-    }
-  }
+  if (const ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(ContDecl))
+    CollectMethodsInOneProtocol(PDecl, InstMethodsInProtocols,
+                                ClsMethodsInProtocols);
     
 }
 
@@ -1612,7 +1605,7 @@
   
   if (InstMethodsInProtocols.empty() && ClsMethodsInProtocols.empty())
     return;
-  MatchMethodsInClassAndOneProtocol(*this, CDecl, InstMethodsInProtocols,
+  MatchMethodsInClassAndProtocols(*this, CDecl, InstMethodsInProtocols,
                                     ClsMethodsInProtocols);
 }
 





More information about the cfe-commits mailing list