Patch to create protocol conforming class types.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42856 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 0eb803e..c2ac6a2 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -449,9 +449,11 @@
                                                   IdentifierInfo **IdentList,
                                                   unsigned NumElts);
   
-  virtual DeclTy **ActOnFindProtocolDeclaration(SourceLocation TypeLoc,
-                                                IdentifierInfo **ProtocolId,
-                                                unsigned NumProtocols);
+  virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
+                                       IdentifierInfo **ProtocolId,
+                                       unsigned NumProtocols,
+                                       llvm::SmallVector<DeclTy *, 8> & 
+                                       Protocols);
 
   virtual void ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *ClassDecl, 
 				         DeclTy **allMethods, unsigned allNum);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 051a4c1..406a745 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -987,20 +987,22 @@
   return PDecl;
 }
 
-/// ActOnFindProtocolDeclaration - This routine looks for a previously
-/// declared protocol and returns it. If not found, issues diagnostic.
-/// Will build a list of previously protocol declarations found in the list.
-Action::DeclTy **
-Sema::ActOnFindProtocolDeclaration(SourceLocation TypeLoc,
-                                   IdentifierInfo **ProtocolId,
-                                   unsigned NumProtocols) {
+/// FindProtocolDeclaration - This routine looks up protocols and
+/// issuer error if they are not declared. It returns list of protocol
+/// declarations in its 'Protocols' argument.
+void
+Sema::FindProtocolDeclaration(SourceLocation TypeLoc,
+                              IdentifierInfo **ProtocolId,
+                              unsigned NumProtocols,
+                              llvm::SmallVector<DeclTy *,8> &Protocols) {
   for (unsigned i = 0; i != NumProtocols; ++i) {
     ObjcProtocolDecl *PDecl = ObjcProtocols[ProtocolId[i]];
     if (!PDecl)
       Diag(TypeLoc, diag::err_undeclared_protocol, 
            ProtocolId[i]->getName());
+    else
+      Protocols.push_back(PDecl); 
   }
-  return 0;
 }
 
 /// ActOnForwardProtocolDeclaration - 
diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp
index 180e440..abf132b 100644
--- a/Sema/SemaType.cpp
+++ b/Sema/SemaType.cpp
@@ -104,8 +104,15 @@
            "Can't handle qualifiers on typedef names yet!");
     // FIXME: Adding a TST_objcInterface clause doesn't seem ideal, so
     // we have this "hack" for now... 
-    if (isa<ObjcInterfaceDecl>(D))
-      return Ctx.getObjcInterfaceType(cast<ObjcInterfaceDecl>(D));
+    if (ObjcInterfaceDecl *ObjcIntDecl = dyn_cast<ObjcInterfaceDecl>(D)) {
+      if (DS.getProtocolQualifiers() == 0)
+        return Ctx.getObjcInterfaceType(ObjcIntDecl);
+      
+      Action::DeclTy **PPDecl = &(*DS.getProtocolQualifiers())[0];
+      return Ctx.getObjcQualifiedInterfaceType(ObjcIntDecl,
+               reinterpret_cast<ObjcProtocolDecl**>(PPDecl),
+              DS.NumProtocolQualifiers());
+    }
     // TypeQuals handled by caller.
     return Ctx.getTypedefType(cast<TypedefDecl>(D));
   }