[cfe-commits] r91227 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/property-list-in-class.m

Fariborz Jahanian fjahanian at apple.com
Sat Dec 12 13:26:21 PST 2009


Author: fjahanian
Date: Sat Dec 12 15:26:21 2009
New Revision: 91227

URL: http://llvm.org/viewvc/llvm-project?rev=91227&view=rev
Log:
patch to add a property from a protocol to a class that adopts the protocol.
(fixes radar 7466494).

Added:
    cfe/trunk/test/CodeGenObjC/property-list-in-class.m
Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=91227&r1=91226&r2=91227&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Dec 12 15:26:21 2009
@@ -28,6 +28,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetData.h"
 #include <cstdio>
@@ -905,6 +906,13 @@
                                    const ObjCContainerDecl *OCD,
                                    const ObjCCommonTypesHelper &ObjCTypes);
 
+  /// PushProtocolProperties - Push protocol's property on the input stack.
+  void PushProtocolProperties(llvm::SmallPtrSet<const IdentifierInfo*, 16> &PropertySet,
+                              std::vector<llvm::Constant*> &Properties,
+                                   const Decl *Container,
+                                   const ObjCProtocolDecl *PROTO,
+                                   const ObjCCommonTypesHelper &ObjCTypes);
+
   /// GetProtocolRef - Return a reference to the internal protocol
   /// description, creating an empty one if it has not been
   /// defined. The return value has type ProtocolPtrTy.
@@ -1793,6 +1801,26 @@
   return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
 }
 
+void CGObjCCommonMac::PushProtocolProperties(llvm::SmallPtrSet<const IdentifierInfo*, 16> &PropertySet,
+                                   std::vector<llvm::Constant*> &Properties,
+                                   const Decl *Container,
+                                   const ObjCProtocolDecl *PROTO,
+                                   const ObjCCommonTypesHelper &ObjCTypes) {
+  std::vector<llvm::Constant*> Prop(2);
+  for (ObjCProtocolDecl::protocol_iterator P = PROTO->protocol_begin(),
+         E = PROTO->protocol_end(); P != E; ++P) 
+    PushProtocolProperties(PropertySet, Properties, Container, (*P), ObjCTypes);
+  for (ObjCContainerDecl::prop_iterator I = PROTO->prop_begin(),
+       E = PROTO->prop_end(); I != E; ++I) {
+    const ObjCPropertyDecl *PD = *I;
+    if (!PropertySet.insert(PD->getIdentifier()))
+      continue;
+    Prop[0] = GetPropertyName(PD->getIdentifier());
+    Prop[1] = GetPropertyTypeString(PD, Container);
+    Properties.push_back(llvm::ConstantStruct::get(ObjCTypes.PropertyTy, Prop));
+  }
+}
+
 /*
   struct _objc_property {
   const char * const name;
@@ -1810,14 +1838,20 @@
                                        const ObjCContainerDecl *OCD,
                                        const ObjCCommonTypesHelper &ObjCTypes) {
   std::vector<llvm::Constant*> Properties, Prop(2);
+  llvm::SmallPtrSet<const IdentifierInfo*, 16> PropertySet;
   for (ObjCContainerDecl::prop_iterator I = OCD->prop_begin(),
          E = OCD->prop_end(); I != E; ++I) {
     const ObjCPropertyDecl *PD = *I;
+    PropertySet.insert(PD->getIdentifier());
     Prop[0] = GetPropertyName(PD->getIdentifier());
     Prop[1] = GetPropertyTypeString(PD, Container);
     Properties.push_back(llvm::ConstantStruct::get(ObjCTypes.PropertyTy,
                                                    Prop));
   }
+  if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(OCD))
+    for (ObjCInterfaceDecl::protocol_iterator P = OID->protocol_begin(),
+         E = OID->protocol_end(); P != E; ++P)
+      PushProtocolProperties(PropertySet, Properties, Container, (*P), ObjCTypes);
 
   // Return null for empty list.
   if (Properties.empty())

Added: cfe/trunk/test/CodeGenObjC/property-list-in-class.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/property-list-in-class.m?rev=91227&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/property-list-in-class.m (added)
+++ cfe/trunk/test/CodeGenObjC/property-list-in-class.m Sat Dec 12 15:26:21 2009
@@ -0,0 +1,32 @@
+// RUN: clang -m64 -fobjc-nonfragile-abi -S -emit-llvm -o %t %s
+// FIXME. Test is incomplete.
+
+ at protocol P 
+ at property int i;
+ at end
+
+ at protocol P1 
+ at property int i1;
+ at end
+
+ at protocol P2 < P1> 
+ at property int i2;
+ at end
+
+ at interface C1 { id isa; } @end
+
+ at interface C2 : C1 <P, P2> {
+    int i;
+}
+ at property int i2;
+ at end
+
+ at implementation C1
++(void)initialize { }
+ at end
+
+ at implementation C2
+ at synthesize i;
+ at synthesize i1;
+ at synthesize i2;
+ at end





More information about the cfe-commits mailing list