r194503 - ObjectiveC migrator. Another alternative to

Fariborz Jahanian fjahanian at apple.com
Tue Nov 12 11:25:50 PST 2013


Author: fjahanian
Date: Tue Nov 12 13:25:50 2013
New Revision: 194503

URL: http://llvm.org/viewvc/llvm-project?rev=194503&view=rev
Log:
ObjectiveC migrator. Another alternative to
 "atomic" or "nonatomic" for properties is
NS_NONATOMIC_IOSONLY. Use it if available.
// rdar://15442742

Added:
    cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m
    cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result
Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=194503&r1=194502&r2=194503&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Nov 12 13:25:50 2013
@@ -282,7 +282,10 @@ static void rewriteToObjCProperty(const
   ASTContext &Context = NS.getASTContext();
   bool LParenAdded = false;
   std::string PropertyString = "@property ";
-  if (!Atomic) {
+  if (Context.Idents.get("NS_NONATOMIC_IOSONLY").hasMacroDefinition()) {
+    PropertyString += "(NS_NONATOMIC_IOSONLY";
+    LParenAdded = true;
+  } else if (!Atomic) {
     PropertyString += "(nonatomic";
     LParenAdded = true;
   }

Added: cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m?rev=194503&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m Tue Nov 12 13:25:50 2013
@@ -0,0 +1,236 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -objcmt-atomic-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
+
+#define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
+#define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable))
+#define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#define DEPRECATED  __attribute__((deprecated)) 
+
+// rdar://15442742
+#if TARGET_OS_IPHONE
+  #define NS_NONATOMIC_IOSONLY nonatomic
+#else
+  #define NS_NONATOMIC_IOSONLY atomic
+#endif
+
+typedef char BOOL;
+ at class NSString;
+ at protocol NSCopying @end
+
+ at interface NSObject <NSCopying>
+ at end
+
+ at interface NSDictionary : NSObject
+ at end
+
+ at interface I : NSObject {
+  int ivarVal;
+}
+- (void) setWeakProp : (NSString *__weak)Val;
+- (NSString *__weak) WeakProp;
+
+- (NSString *) StrongProp;
+- (void) setStrongProp : (NSString *)Val;
+
+- (NSString *) UnavailProp  __attribute__((unavailable));
+- (void) setUnavailProp  : (NSString *)Val;
+
+- (NSString *) UnavailProp1  __attribute__((unavailable));
+- (void) setUnavailProp1  : (NSString *)Val  __attribute__((unavailable));
+
+- (NSString *) UnavailProp2;
+- (void) setUnavailProp2  : (NSString *)Val  __attribute__((unavailable));
+
+- (NSDictionary*) undoAction;
+- (void) setUndoAction: (NSDictionary*)Arg;
+ at end
+
+ at implementation I
+ at end
+
+ at class NSArray;
+
+ at interface MyClass2  {
+ at private
+    NSArray *_names1;
+    NSArray *_names2;
+    NSArray *_names3;
+    NSArray *_names4;
+}
+- (void)setNames1:(NSArray *)names;
+- (void)setNames4:(__strong NSArray *)names;
+- (void)setNames3:(__strong NSArray *)names;
+- (void)setNames2:(NSArray *)names;
+- (NSArray *) names2;
+- (NSArray *)names3;
+- (__strong NSArray *)names4;
+- (NSArray *) names1;
+ at end
+
+// Properties that contain the name "delegate" or "dataSource",
+// or have exact name "target" have unsafe_unretained attribute.
+ at interface NSInvocation 
+- (id)target;
+- (void)setTarget:(id)target;
+
+- (id) dataSource;
+
+- (id)xxxdelegateYYY;
+- (void)setXxxdelegateYYY:(id)delegate;
+
+- (void)setDataSource:(id)source;
+
+- (id)MYtarget;
+- (void)setMYtarget: (id)target;
+
+- (id)targetX;
+- (void)setTargetX: (id)t;
+ 
+- (int)value;
+- (void)setValue: (int)val;
+
+-(BOOL) isContinuous;
+-(void) setContinuous:(BOOL)value;
+
+- (id) isAnObject;
+- (void)setAnObject : (id) object;
+
+- (BOOL) isinValid;
+- (void) setInValid : (BOOL) arg;
+
+- (void) Nothing;
+- (int) Length;
+- (id) object;
++ (double) D;
+- (void *)JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
+- (BOOL)isIgnoringInteractionEvents;
+
+- (NSString *)getStringValue;
+- (BOOL)getCounterValue;
+- (void)setStringValue:(NSString *)stringValue AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
+- (NSDictionary *)getns_dixtionary;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
+
+- (BOOL) getM;
+- (BOOL) getMA;
+- (BOOL) getALL;
+- (BOOL) getMANY;
+- (BOOL) getSome;
+ at end
+
+
+ at interface NSInvocation(CAT)
+- (id)target;
+- (void)setTarget:(id)target;
+
+- (id) dataSource;
+
+- (id)xxxdelegateYYY;
+- (void)setXxxdelegateYYY:(id)delegate;
+
+- (void)setDataSource:(id)source;
+
+- (id)MYtarget;
+- (void)setMYtarget: (id)target;
+
+- (id)targetX;
+- (void)setTargetX: (id)t;
+
+- (int)value;
+- (void)setValue: (int)val;
+
+-(BOOL) isContinuous;
+-(void) setContinuous:(BOOL)value;
+
+- (id) isAnObject;
+- (void)setAnObject : (id) object;
+
+- (BOOL) isinValid;
+- (void) setInValid : (BOOL) arg;
+
+- (void) Nothing;
+- (int) Length;
+- (id) object;
++ (double) D;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
+
+- (BOOL) getM;
+- (BOOL) getMA;
+- (BOOL) getALL;
+- (BOOL) getMANY;
+- (BOOL) getSome;
+ at end
+
+DEPRECATED
+ at interface I_DEP
+- (BOOL) isinValid;
+- (void) setInValid : (BOOL) arg;
+ at end
+
+ at interface AnotherOne
+- (BOOL) isinValid DEPRECATED;
+- (void) setInValid : (BOOL) arg;
+- (id)MYtarget;
+- (void)setMYtarget: (id)target DEPRECATED;
+- (BOOL) getM DEPRECATED;
+
+- (id)xxxdelegateYYY DEPRECATED;
+- (void)setXxxdelegateYYY:(id)delegate DEPRECATED;
+ at end
+
+// rdar://14987909
+#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0)))
+#define NORETURN __attribute__((noreturn))
+#define ALIGNED __attribute__((aligned(16)))
+
+ at interface NSURL
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURL NS_AVAILABLE;
+- (void) setAppStoreReceiptURL : (NSURL *)object;
+
+- (NSURL *)appStoreReceiptURLX NS_AVAILABLE;
+- (void) setAppStoreReceiptURLX : (NSURL *)object NS_AVAILABLE;
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLY ;
+- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
+
+- (id)OkToInfer NS_AVAILABLE;
+
+// Do not infer a property.
+- (NSURL *)appStoreReceiptURLZ ;
+- (void) setAppStoreReceiptURLZ : (NSURL *)object NS_AVAILABLE;
+
+// Do not infer a property.
+- (id) t1 NORETURN NS_AVAILABLE;
+- (void) setT1 : (id) arg NS_AVAILABLE;
+
+- (id)method1 ALIGNED NS_AVAILABLE;
+- (void) setMethod1 : (id) object NS_AVAILABLE ALIGNED;
+
+- (NSURL *)init;  // No Change
++ (id)alloc;      // No Change
+
+- (BOOL)is1stClass; // Not a valid property
+- (BOOL)isClass;    // This is a valid property 'class' is not a keyword in ObjC
+- (BOOL)isDouble; // Not a valid property
+
+ at end
+
+// rdar://15082818
+ at class NSMutableDictionary;
+
+ at interface NSArray
+- (id (^)(id, NSArray *, NSMutableDictionary *)) expressionBlock;
+- (id (^)(id, NSArray *, NSMutableDictionary *)) MyBlock;
+- (void) setMyBlock : (id (^)(id, NSArray *, NSMutableDictionary *)) bl;
+- (id (*)(id, NSArray *, NSMutableDictionary *)) expressionFuncptr;
+- (id (*)(id, NSArray *, NSMutableDictionary *)) MyFuncptr;
+- (void) setMyFuncptr : (id (*)(id, NSArray *, NSMutableDictionary *)) bl;
+ at end

Added: cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result?rev=194503&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result (added)
+++ cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result Tue Nov 12 13:25:50 2013
@@ -0,0 +1,209 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -objcmt-atomic-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
+
+#define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
+#define WEAK_IMPORT_ATTRIBUTE __attribute__((objc_arc_weak_reference_unavailable))
+#define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#define DEPRECATED  __attribute__((deprecated)) 
+
+// rdar://15442742
+#if TARGET_OS_IPHONE
+  #define NS_NONATOMIC_IOSONLY nonatomic
+#else
+  #define NS_NONATOMIC_IOSONLY atomic
+#endif
+
+typedef char BOOL;
+ at class NSString;
+ at protocol NSCopying @end
+
+ at interface NSObject <NSCopying>
+ at end
+
+ at interface NSDictionary : NSObject
+ at end
+
+ at interface I : NSObject {
+  int ivarVal;
+}
+ at property (NS_NONATOMIC_IOSONLY, weak) NSString *WeakProp;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) NSString *StrongProp;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) NSString *UnavailProp  __attribute__((unavailable));
+- (void) setUnavailProp  : (NSString *)Val;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) NSString *UnavailProp1  __attribute__((unavailable));
+
+ at property (NS_NONATOMIC_IOSONLY, retain) NSString *UnavailProp2;
+- (void) setUnavailProp2  : (NSString *)Val  __attribute__((unavailable));
+
+ at property (NS_NONATOMIC_IOSONLY, copy) NSDictionary *undoAction;
+ at end
+
+ at implementation I
+ at end
+
+ at class NSArray;
+
+ at interface MyClass2  {
+ at private
+    NSArray *_names1;
+    NSArray *_names2;
+    NSArray *_names3;
+    NSArray *_names4;
+}
+ at property (NS_NONATOMIC_IOSONLY, retain) NSArray *names2;
+ at property (NS_NONATOMIC_IOSONLY, retain) NSArray *names3;
+ at property (NS_NONATOMIC_IOSONLY, retain) NSArray *names4;
+ at property (NS_NONATOMIC_IOSONLY, retain) NSArray *names1;
+ at end
+
+// Properties that contain the name "delegate" or "dataSource",
+// or have exact name "target" have unsafe_unretained attribute.
+ at interface NSInvocation 
+ at property (NS_NONATOMIC_IOSONLY, assign) id target;
+
+ at property (NS_NONATOMIC_IOSONLY, assign) id dataSource;
+
+ at property (NS_NONATOMIC_IOSONLY, assign) id xxxdelegateYYY;
+
+
+ at property (NS_NONATOMIC_IOSONLY, retain) id MYtarget;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) id targetX;
+ 
+ at property (NS_NONATOMIC_IOSONLY) int value;
+
+ at property (NS_NONATOMIC_IOSONLY, getter=isContinuous) BOOL continuous;
+
+- (id) isAnObject;
+- (void)setAnObject : (id) object;
+
+ at property (NS_NONATOMIC_IOSONLY, getter=isinValid, readonly) BOOL inValid;
+- (void) setInValid : (BOOL) arg;
+
+- (void) Nothing;
+ at property (NS_NONATOMIC_IOSONLY, readonly) int Length;
+ at property (NS_NONATOMIC_IOSONLY, readonly) id object;
++ (double) D;
+ at property (NS_NONATOMIC_IOSONLY, readonly) void *JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
+ at property (NS_NONATOMIC_IOSONLY, getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
+
+ at property (NS_NONATOMIC_IOSONLY, getter=getStringValue, retain) NSString *stringValue;
+ at property (NS_NONATOMIC_IOSONLY, getter=getCounterValue, readonly) BOOL counterValue;
+ at property (NS_NONATOMIC_IOSONLY, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
+
+ at property (NS_NONATOMIC_IOSONLY, getter=getM, readonly) BOOL m;
+ at property (NS_NONATOMIC_IOSONLY, getter=getMA, readonly) BOOL MA;
+ at property (NS_NONATOMIC_IOSONLY, getter=getALL, readonly) BOOL ALL;
+ at property (NS_NONATOMIC_IOSONLY, getter=getMANY, readonly) BOOL MANY;
+ at property (NS_NONATOMIC_IOSONLY, getter=getSome, readonly) BOOL some;
+ at end
+
+
+ at interface NSInvocation(CAT)
+ at property (NS_NONATOMIC_IOSONLY, assign) id target;
+
+ at property (NS_NONATOMIC_IOSONLY, assign) id dataSource;
+
+ at property (NS_NONATOMIC_IOSONLY, assign) id xxxdelegateYYY;
+
+
+ at property (NS_NONATOMIC_IOSONLY, retain) id MYtarget;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) id targetX;
+
+ at property (NS_NONATOMIC_IOSONLY) int value;
+
+ at property (NS_NONATOMIC_IOSONLY, getter=isContinuous) BOOL continuous;
+
+- (id) isAnObject;
+- (void)setAnObject : (id) object;
+
+ at property (NS_NONATOMIC_IOSONLY, getter=isinValid, readonly) BOOL inValid;
+- (void) setInValid : (BOOL) arg;
+
+- (void) Nothing;
+ at property (NS_NONATOMIC_IOSONLY, readonly) int Length;
+ at property (NS_NONATOMIC_IOSONLY, readonly) id object;
++ (double) D;
+
+- (BOOL)is3bar; // watch out
+- (NSString *)get3foo; // watch out
+
+ at property (NS_NONATOMIC_IOSONLY, getter=getM, readonly) BOOL m;
+ at property (NS_NONATOMIC_IOSONLY, getter=getMA, readonly) BOOL MA;
+ at property (NS_NONATOMIC_IOSONLY, getter=getALL, readonly) BOOL ALL;
+ at property (NS_NONATOMIC_IOSONLY, getter=getMANY, readonly) BOOL MANY;
+ at property (NS_NONATOMIC_IOSONLY, getter=getSome, readonly) BOOL some;
+ at end
+
+DEPRECATED
+ at interface I_DEP
+- (BOOL) isinValid;
+- (void) setInValid : (BOOL) arg;
+ at end
+
+ at interface AnotherOne
+- (BOOL) isinValid DEPRECATED;
+- (void) setInValid : (BOOL) arg;
+- (id)MYtarget;
+- (void)setMYtarget: (id)target DEPRECATED;
+- (BOOL) getM DEPRECATED;
+
+- (id)xxxdelegateYYY DEPRECATED;
+- (void)setXxxdelegateYYY:(id)delegate DEPRECATED;
+ at end
+
+// rdar://14987909
+#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0)))
+#define NORETURN __attribute__((noreturn))
+#define ALIGNED __attribute__((aligned(16)))
+
+ at interface NSURL
+// Do not infer a property.
+ at property (NS_NONATOMIC_IOSONLY, retain) NSURL *appStoreReceiptURL NS_AVAILABLE;
+- (void) setAppStoreReceiptURL : (NSURL *)object;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) NSURL *appStoreReceiptURLX NS_AVAILABLE;
+
+// Do not infer a property.
+ at property (NS_NONATOMIC_IOSONLY, retain) NSURL *appStoreReceiptURLY ;
+- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
+
+ at property (NS_NONATOMIC_IOSONLY, readonly) id OkToInfer NS_AVAILABLE;
+
+// Do not infer a property.
+ at property (NS_NONATOMIC_IOSONLY, retain) NSURL *appStoreReceiptURLZ ;
+- (void) setAppStoreReceiptURLZ : (NSURL *)object NS_AVAILABLE;
+
+// Do not infer a property.
+- (id) t1 NORETURN NS_AVAILABLE;
+- (void) setT1 : (id) arg NS_AVAILABLE;
+
+ at property (NS_NONATOMIC_IOSONLY, retain) id method1 ALIGNED NS_AVAILABLE;
+
+- (NSURL *)init;  // No Change
++ (id)alloc;      // No Change
+
+- (BOOL)is1stClass; // Not a valid property
+ at property (NS_NONATOMIC_IOSONLY, getter=isClass, readonly) BOOL class;    // This is a valid property 'class' is not a keyword in ObjC
+- (BOOL)isDouble; // Not a valid property
+
+ at end
+
+// rdar://15082818
+ at class NSMutableDictionary;
+
+ at interface NSArray
+ at property (NS_NONATOMIC_IOSONLY, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (NS_NONATOMIC_IOSONLY, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (NS_NONATOMIC_IOSONLY, readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *);
+ at property (NS_NONATOMIC_IOSONLY) id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *);
+ at end





More information about the cfe-commits mailing list