From 2bc3dda186bc645f978c78942e85a2f0ba5d3859 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 16 Jul 2013 21:59:42 +0000 Subject: [PATCH] ObjectiveC migrator. If a class implements a protocol's properties, then class conforms to that protocol. llvm-svn: 186460 --- clang/lib/ARCMigrate/ObjCMT.cpp | 25 +++++++++++-------- .../test/ARCMT/objcmt-protocol-conformance.m | 15 +++++++++++ .../objcmt-protocol-conformance.m.result | 15 +++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index dd210264582e..ab4aa0e08504 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -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(R[0])) { - if (ClassProperty->getPropertyAttributes() - != Property->getPropertyAttributes()) - return false; - if (!Ctx.hasSameType(ClassProperty->getType(), Property->getType())) - return false; - } + 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(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. diff --git a/clang/test/ARCMT/objcmt-protocol-conformance.m b/clang/test/ARCMT/objcmt-protocol-conformance.m index 2ad8a659faee..3ef2eff13f24 100644 --- a/clang/test/ARCMT/objcmt-protocol-conformance.m +++ b/clang/test/ARCMT/objcmt-protocol-conformance.m @@ -46,3 +46,18 @@ - (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 +@end + +@implementation Test5 +@synthesize Prop=_XXX; +@end diff --git a/clang/test/ARCMT/objcmt-protocol-conformance.m.result b/clang/test/ARCMT/objcmt-protocol-conformance.m.result index 71fa3b1b06d0..11bf7847280e 100644 --- a/clang/test/ARCMT/objcmt-protocol-conformance.m.result +++ b/clang/test/ARCMT/objcmt-protocol-conformance.m.result @@ -46,3 +46,18 @@ - (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 +@end + +@implementation Test5 +@synthesize Prop=_XXX; +@end