]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator. If a class implements a protocol's
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 16 Jul 2013 21:59:42 +0000 (21:59 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 16 Jul 2013 21:59:42 +0000 (21:59 +0000)
properties, then class conforms to that protocol.

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

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-protocol-conformance.m
test/ARCMT/objcmt-protocol-conformance.m.result

index dd210264582e5d2b9707bbb50bcdf69ffd5a6c3f..ab4aa0e08504964ba1a0457c963d639f8cc6ef1e 100644 (file)
@@ -250,17 +250,22 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
       if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
         continue;
       DeclContext::lookup_const_result R = IDecl->lookup(Property->getDeclName());
-      if (R.size() == 0)
-        return false;
-      for (unsigned I = 0, N = R.size(); I != N; ++I) {
-        if (ObjCPropertyDecl *ClassProperty = dyn_cast<ObjCPropertyDecl>(R[0])) {
-          if (ClassProperty->getPropertyAttributes()
-              != Property->getPropertyAttributes())
-            return false;
-          if (!Ctx.hasSameType(ClassProperty->getType(), Property->getType()))
+      if (R.size() == 0) {
+        // Relax the rule and look into class's implementation for a synthesize
+        // or dynamic declaration. Class is implementing a property coming from
+        // another protocol. This still makes the target protocol as conforming.
+        if (!ImpDecl->FindPropertyImplDecl(
+                                  Property->getDeclName().getAsIdentifierInfo()))
+          return false;
+      }
+      else if (ObjCPropertyDecl *ClassProperty = dyn_cast<ObjCPropertyDecl>(R[0])) {
+          if ((ClassProperty->getPropertyAttributes()
+              != Property->getPropertyAttributes()) ||
+              !Ctx.hasSameType(ClassProperty->getType(), Property->getType()))
             return false;
-        }
       }
+      else
+        return false;
     }
   // At this point, all required properties in this protocol conform to those
   // declared in the class.
index 2ad8a659faee92133a2cc8daa16917d53614e031..3ef2eff13f24955b4728e05aa4aa4a9493812ae3 100644 (file)
 - (id) Meth1: (double) arg { return 0; }
 @end
 
+// Test5 - conforms to P3 because it implement's P3's property.
+@protocol P3
+@property (copy) id Prop;
+@end
+
+@protocol P4
+@property (copy) id Prop;
+@end
+
+@interface Test5 : NSObject<P3>
+@end
+
+@implementation Test5
+@synthesize Prop=_XXX;
+@end
index 71fa3b1b06d03ce8cbd8d89d4165a87d554e0d43..11bf7847280ec8663d0d3cc584616fd39e89263e 100644 (file)
 - (id) Meth1: (double) arg { return 0; }
 @end
 
+// Test5 - conforms to P3 because it implement's P3's property.
+@protocol P3
+@property (copy) id Prop;
+@end
+
+@protocol P4
+@property (copy) id Prop;
+@end
+
+@interface Test5 : NSObject<P3, P4>
+@end
+
+@implementation Test5
+@synthesize Prop=_XXX;
+@end