]> granicus.if.org Git - clang/commitdiff
NeXT: Emit [meta]class protocol references.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 21 Aug 2008 21:57:41 +0000 (21:57 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 21 Aug 2008 21:57:41 +0000 (21:57 +0000)
Updated ObjCProtocolDecl::protocol_iterator to match that of
ObjCInterfaceDecl.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55143 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/CodeGen/CGObjCMac.cpp

index 688f18caf33840d18fa101485757d1e6527d5ee7..7dc874b5c6fa264f5c5290cb027f0e6ffb8d78a0 100644 (file)
@@ -596,7 +596,7 @@ public:
   const ObjCList<ObjCProtocolDecl> &getReferencedProtocols() const { 
     return ReferencedProtocols;
   }
-  typedef ObjCProtocolDecl * const * protocol_iterator;
+  typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
   protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
   protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
   
index 44f1baeb05116dab9cc200600153075d4a67298d..51558f86fa377420ecc19afd0253c660b203b7c7 100644 (file)
@@ -234,7 +234,9 @@ private:
 
   /// EmitProtocolList - Generate the list of referenced
   /// protocols. The return value has type ProtocolListPtrTy.
-  llvm::Constant *EmitProtocolList(const ObjCProtocolDecl *PD);
+  llvm::Constant *EmitProtocolList(const std::string &Name,
+                                   ObjCProtocolDecl::protocol_iterator begin,
+                                   ObjCProtocolDecl::protocol_iterator end);
 
   /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
   /// for the given selector.
@@ -459,7 +461,10 @@ void CGObjCMac::GenerateProtocol(const ObjCProtocolDecl *PD) {
   std::vector<llvm::Constant*> Values(5);
   Values[0] = EmitProtocolExtension(PD);
   Values[1] = GetClassName(PD->getIdentifier());
-  Values[2] = EmitProtocolList(PD);
+  Values[2] = 
+    EmitProtocolList(std::string("\01L_OBJC_PROTOCOL_REFS_")+PD->getName(),
+                     PD->protocol_begin(),
+                     PD->protocol_end());
   Values[3] = EmitMethodDescList(ProtocolName,
                                  true, // IsProtocol
                                  false, // ClassMethods
@@ -577,12 +582,14 @@ llvm::Constant *CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD) {
     Protocol *list[];
   };
 */
-llvm::Constant *CGObjCMac::EmitProtocolList(const ObjCProtocolDecl *PD) {
+llvm::Constant *
+CGObjCMac::EmitProtocolList(const std::string &Name,
+                            ObjCProtocolDecl::protocol_iterator begin,
+                            ObjCProtocolDecl::protocol_iterator end) {
   std::vector<llvm::Constant*> ProtocolRefs;
 
-  for (ObjCProtocolDecl::protocol_iterator i = PD->protocol_begin(), 
-         e = PD->protocol_end(); i != e; ++i)
-    ProtocolRefs.push_back(GetProtocolRef(*i));
+  for (; begin != end; ++begin)
+    ProtocolRefs.push_back(GetProtocolRef(*begin));
 
   // Just return null for empty protocol lists
   if (ProtocolRefs.empty()) 
@@ -605,8 +612,7 @@ llvm::Constant *CGObjCMac::EmitProtocolList(const ObjCProtocolDecl *PD) {
     new llvm::GlobalVariable(Init->getType(), false,
                              llvm::GlobalValue::InternalLinkage,
                              Init,
-                             (std::string("\01L_OBJC_PROTOCOL_REFS_") + 
-                              PD->getName()), 
+                             Name,
                              &CGM.getModule());
   GV->setSection("__OBJC,__cat_cls_meth,regular,no_dead_strip");
   return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
@@ -728,12 +734,13 @@ static bool IsClassHidden(const ObjCInterfaceDecl *ID) {
  */
 void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
   const char *ClassName = ID->getName();
-  // FIXME: Support protocols.
-  llvm::Constant *Protocols = 
-    llvm::Constant::getNullValue(ObjCTypes.ProtocolListPtrTy);
   // FIXME: Gross
   ObjCInterfaceDecl *Interface = 
     const_cast<ObjCInterfaceDecl*>(ID->getClassInterface());
+  llvm::Constant *Protocols = 
+    EmitProtocolList(std::string("\01L_OBJC_CLASS_PROTOCOLS_") + ID->getName(),
+                     Interface->protocol_begin(),
+                     Interface->protocol_end());
   const llvm::Type *InterfaceTy = 
    CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(Interface));
   unsigned Flags = eClassFlags_Factory;