]> granicus.if.org Git - clang/commitdiff
ObjectiveC migration. Better handle migration to conforming
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 22 Jul 2013 23:50:04 +0000 (23:50 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 22 Jul 2013 23:50:04 +0000 (23:50 +0000)
protocols by ignoring cases where all protocol properties
and methods are optional.

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

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

index 1bc0b8c891c70f7aff2216b6d77ed25346d454b4..153ebbcca16dfde9e7d0084d859d330fee32f81f 100644 (file)
@@ -293,12 +293,14 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
   // 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(ASTContext &Ctx,
       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(ASTContext &Ctx,
         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(ASTContext &Ctx,
         return false;
     }
   }
-
-  return true;
+  if (HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod)
+    return true;
+  return false;
 }
 
 static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl,
index 2b9c93f3fced27da0b62dd8f35a0daefa1658705..849343d3bdc982146db79efea5ca38bd7e8a378d 100644 (file)
 @implementation Test6 
 @end
 
+@class UIDynamicAnimator, UIWindow;
+@interface UIResponder : NSObject
+@end
+
+@protocol EmptyProtocol
+@end
+
+@protocol OptionalMethodsOnly
+@optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+@end
+
+@protocol OptionalPropertiesOnly
+@optional
+@property (strong, nonatomic) id OptionalProperty;
+@end
+
+@protocol OptionalEvrything
+@optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+@property (strong, nonatomic) id OptionalProperty;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+@end
+
+@protocol UIApplicationDelegate
+@end
+
+@interface Test7 : UIResponder <UIApplicationDelegate>
+@property (strong, nonatomic) UIWindow *window;
+@end
+
+@implementation Test7
+@end
+
index ba3264588018799bcfbbc79622480df2d3f8cfd0..4f1ee771d2b29193a9c104ba6e516cd3245cb7cf 100644 (file)
 @implementation Test6 
 @end
 
+@class UIDynamicAnimator, UIWindow;
+@interface UIResponder : NSObject
+@end
+
+@protocol EmptyProtocol
+@end
+
+@protocol OptionalMethodsOnly
+@optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+@end
+
+@protocol OptionalPropertiesOnly
+@optional
+@property (strong, nonatomic) id OptionalProperty;
+@end
+
+@protocol OptionalEvrything
+@optional
+- (void)dynamicAnimatorWillResume:(UIDynamicAnimator*)animator;
+@property (strong, nonatomic) id OptionalProperty;
+- (void)dynamicAnimatorDidPause:(UIDynamicAnimator*)animator;
+@end
+
+@protocol UIApplicationDelegate
+@end
+
+@interface Test7 : UIResponder <UIApplicationDelegate>
+@property (strong, nonatomic) UIWindow *window;
+@end
+
+@implementation Test7
+@end
+