r186895 - ObjectiveC migration. Better handle migration to conforming
Fariborz Jahanian
fjahanian at apple.com
Mon Jul 22 16:50:05 PDT 2013
Author: fjahanian
Date: Mon Jul 22 18:50:04 2013
New Revision: 186895
URL: http://llvm.org/viewvc/llvm-project?rev=186895&view=rev
Log:
ObjectiveC migration. Better handle migration to conforming
protocols by ignoring cases where all protocol properties
and methods are optional.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m
cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=186895&r1=186894&r2=186895&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Mon Jul 22 18:50:04 2013
@@ -293,12 +293,14 @@ ClassImplementsAllMethodsAndProperties(A
// In auto-synthesis, protocol properties are not synthesized. So,
// a conforming protocol must have its required properties declared
// in class interface.
+ bool HasAtleastOneRequiredProperty = false;
if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition())
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
E = PDecl->prop_end(); P != E; ++P) {
ObjCPropertyDecl *Property = *P;
if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
continue;
+ HasAtleastOneRequiredProperty = true;
DeclContext::lookup_const_result R = IDecl->lookup(Property->getDeclName());
if (R.size() == 0) {
// Relax the rule and look into class's implementation for a synthesize
@@ -317,12 +319,14 @@ ClassImplementsAllMethodsAndProperties(A
else
return false;
}
+
// At this point, all required properties in this protocol conform to those
// declared in the class.
// Check that class implements the required methods of the protocol too.
+ bool HasAtleastOneRequiredMethod = false;
if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) {
if (PDecl->meth_begin() == PDecl->meth_end())
- return false;
+ return HasAtleastOneRequiredProperty;
for (ObjCContainerDecl::method_iterator M = PDecl->meth_begin(),
MEnd = PDecl->meth_end(); M != MEnd; ++M) {
ObjCMethodDecl *MD = (*M);
@@ -330,10 +334,11 @@ ClassImplementsAllMethodsAndProperties(A
continue;
if (MD->getImplementationControl() == ObjCMethodDecl::Optional)
continue;
- bool match = false;
DeclContext::lookup_const_result R = ImpDecl->lookup(MD->getDeclName());
if (R.size() == 0)
return false;
+ bool match = false;
+ HasAtleastOneRequiredMethod = true;
for (unsigned I = 0, N = R.size(); I != N; ++I)
if (ObjCMethodDecl *ImpMD = dyn_cast<ObjCMethodDecl>(R[0]))
if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) {
@@ -344,8 +349,9 @@ ClassImplementsAllMethodsAndProperties(A
return false;
}
}
-
- return true;
+ if (HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod)
+ return true;
+ return false;
}
static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl,
Modified: cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m?rev=186895&r1=186894&r2=186895&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m Mon Jul 22 18:50:04 2013
@@ -77,3 +77,38 @@
@implementation Test6
@end
+ at class UIDynamicAnimator, UIWindow;
+ at interface UIResponder : NSObject
+ at end
+
+ at protocol EmptyProtocol
+ at end
+
+ at protocol OptionalMethodsOnly
+ at optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+ at end
+
+ at protocol OptionalPropertiesOnly
+ at optional
+ at property (strong, nonatomic) id OptionalProperty;
+ at end
+
+ at protocol OptionalEvrything
+ at optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+ at property (strong, nonatomic) id OptionalProperty;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+ at end
+
+ at protocol UIApplicationDelegate
+ at end
+
+ at interface Test7 : UIResponder <UIApplicationDelegate>
+ at property (strong, nonatomic) UIWindow *window;
+ at end
+
+ at implementation Test7
+ at end
+
Modified: cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result?rev=186895&r1=186894&r2=186895&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-protocol-conformance.m.result Mon Jul 22 18:50:04 2013
@@ -77,3 +77,38 @@
@implementation Test6
@end
+ at class UIDynamicAnimator, UIWindow;
+ at interface UIResponder : NSObject
+ at end
+
+ at protocol EmptyProtocol
+ at end
+
+ at protocol OptionalMethodsOnly
+ at optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+ at end
+
+ at protocol OptionalPropertiesOnly
+ at optional
+ at property (strong, nonatomic) id OptionalProperty;
+ at end
+
+ at protocol OptionalEvrything
+ at optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+ at property (strong, nonatomic) id OptionalProperty;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+ at end
+
+ at protocol UIApplicationDelegate
+ at end
+
+ at interface Test7 : UIResponder <UIApplicationDelegate>
+ at property (strong, nonatomic) UIWindow *window;
+ at end
+
+ at implementation Test7
+ at end
+
More information about the cfe-commits
mailing list