introduce a new ObjCList templated class and start moving 
various objc lists over to it.  First up, the protocol list 
on ObjCInterfaceDecl.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53856 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp
index 5da762e..7b28b10 100644
--- a/lib/AST/DeclObjC.cpp
+++ b/lib/AST/DeclObjC.cpp
@@ -280,18 +280,6 @@
   return 0;
 }
 
-/// addReferencedProtocols - Set the list of protocols that this interface
-/// implements.
-void ObjCInterfaceDecl::addReferencedProtocols(ObjCProtocolDecl **OID, 
-                                               unsigned numRefProtos) {
-  assert(NumReferencedProtocols == 0 && "refproto already set!");
-  NumReferencedProtocols = numRefProtos;
-  if (numRefProtos) {
-    ReferencedProtocols = new ObjCProtocolDecl*[numRefProtos];
-    memcpy(ReferencedProtocols, OID, numRefProtos*sizeof(ObjCProtocolDecl*));
-  }
-}
-
 /// ObjCAddInstanceVariablesToClass - Inserts instance variables
 /// into ObjCInterfaceDecl's fields.
 ///
@@ -539,12 +527,13 @@
       return MethodDecl;
       
     // Didn't find one yet - look through protocols.
-    ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
-    int numProtocols = ClassDecl->getNumIntfRefProtocols();
-    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
-      if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel)))
+    const ObjCList<ObjCProtocolDecl> &Protocols =
+      ClassDecl->getReferencedProtocols();
+    for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
+         E = Protocols.end(); I != E; ++I)
+      if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
         return MethodDecl;
-    }
+    
     // Didn't find one yet - now look through categories.
     ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
     while (CatDecl) {
@@ -568,10 +557,12 @@
       return MethodDecl;
 
     // Didn't find one yet - look through protocols.
-    ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
-    int numProtocols = ClassDecl->getNumIntfRefProtocols();
-    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
-      if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel)))
+    const ObjCList<ObjCProtocolDecl> &Protocols =
+      ClassDecl->getReferencedProtocols();
+
+    for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
+         E = Protocols.end(); I != E; ++I) {
+      if ((MethodDecl = (*I)->getClassMethod(Sel)))
         return MethodDecl;
     }
     // Didn't find one yet - now look through categories.
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 20afc5e..b9c1542 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -415,9 +415,11 @@
 
   // Collect the names of referenced protocols
   llvm::SmallVector<std::string, 16> Protocols;
-  ObjCInterfaceDecl * ClassDecl = (ObjCInterfaceDecl*)OCD->getClassInterface();
-  for (unsigned i=0 ; i<ClassDecl->getNumIntfRefProtocols() ; i++)
-    Protocols.push_back(ClassDecl->getReferencedProtocols()[i]->getName());
+  const ObjCInterfaceDecl *ClassDecl = OCD->getClassInterface();
+  const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
+  for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
+       E = Protos.end(); I != E; ++I)
+    Protocols.push_back((*I)->getName());
 
   // Generate the category
   Runtime->GenerateCategory(OCD->getClassInterface()->getName(),
@@ -495,8 +497,10 @@
   }
   // Collect the names of referenced protocols
   llvm::SmallVector<std::string, 16> Protocols;
-  for (unsigned i = 0, e = ClassDecl->getNumIntfRefProtocols() ; i < e ; i++)
-    Protocols.push_back(ClassDecl->getReferencedProtocols()[i]->getName());
+  const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
+  for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
+       E = Protos.end(); I != E; ++I)
+    Protocols.push_back((*I)->getName());
 
   // Generate the category
   Runtime->GenerateClass(ClassName, SCName, instanceSize, IvarNames, IvarTypes,
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index ad40cbe..5188740 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -653,9 +653,11 @@
   
   // Check the protocol list for unimplemented methods in the @implementation
   // class.
-  ObjCProtocolDecl** protocols = IDecl->getReferencedProtocols();
-  for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++)
-    CheckProtocolMethodDefs(IMPDecl->getLocation(), protocols[i], 
+  const ObjCList<ObjCProtocolDecl> &Protocols =
+    IDecl->getReferencedProtocols();
+  for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
+       E = Protocols.end(); I != E; ++I)
+    CheckProtocolMethodDefs(IMPDecl->getLocation(), *I, 
                             IncompleteImpl, InsMap, ClsMap);
 }
 
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 56a1f81..6d19b87 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -375,9 +375,12 @@
                                     bool RHSIsQualifiedID = false) {
   
   // 1st, look up the class.
-  ObjCProtocolDecl **protoList = IDecl->getReferencedProtocols();
-  for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++) {
-    if (ProtocolCompatibleWithProtocol(lProto, protoList[i]))
+  const ObjCList<ObjCProtocolDecl> &Protocols =
+    IDecl->getReferencedProtocols();
+
+  for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
+       E = Protocols.end(); PI != E; ++PI) {
+    if (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'
@@ -385,8 +388,7 @@
     // of protocols in the rhs 'id' object. This IMO, should be a bug.
     // FIXME: Treat this as an extension, and flag this as an error when
     //  GCC extensions are not enabled.
-    else if (RHSIsQualifiedID &&
-             ProtocolCompatibleWithProtocol(protoList[i], lProto))
+    if (RHSIsQualifiedID && ProtocolCompatibleWithProtocol(*PI, lProto))
       return true;
   }
   
@@ -394,7 +396,7 @@
   if (lookupCategory)
     for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
          CDecl = CDecl->getNextClassCategory()) {
-      protoList = CDecl->getReferencedProtocols();
+      ObjCProtocolDecl **protoList = CDecl->getReferencedProtocols();
       for (unsigned i = 0; i < CDecl->getNumReferencedProtocols(); i++) {
         if (ProtocolCompatibleWithProtocol(lProto, protoList[i]))
           return true;