r194718 - ObjectiveC migrator: This patch sets access property
Fariborz Jahanian
fjahanian at apple.com
Thu Nov 14 10:28:58 PST 2013
Author: fjahanian
Date: Thu Nov 14 12:28:58 2013
New Revision: 194718
URL: http://llvm.org/viewvc/llvm-project?rev=194718&view=rev
Log:
ObjectiveC migrator: This patch sets access property
attributes on 'readonly' properties. // rdar://15460787
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result
cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result
cfe/trunk/test/ARCMT/objcmt-property.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=194718&r1=194717&r2=194718&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Nov 14 12:28:58 2013
@@ -291,6 +291,29 @@ void MigrateBlockOrFunctionPointerTypeVa
}
}
+static const char *PropertyMemoryAttribute(ASTContext &Context, QualType ArgType) {
+ Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
+ bool RetainableObject = ArgType->isObjCRetainableType();
+ if (RetainableObject && propertyLifetime == Qualifiers::OCL_Strong) {
+ if (const ObjCObjectPointerType *ObjPtrTy =
+ ArgType->getAs<ObjCObjectPointerType>()) {
+ ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
+ if (IDecl &&
+ IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
+ return "copy";
+ else
+ return "retain";
+ }
+ else if (ArgType->isBlockPointerType())
+ return "copy";
+ } else if (propertyLifetime == Qualifiers::OCL_Weak)
+ // TODO. More precise determination of 'weak' attribute requires
+ // looking into setter's implementation for backing weak ivar.
+ return "weak";
+ else if (RetainableObject)
+ return ArgType->isBlockPointerType() ? "copy" : "retain";
+ return 0;
+}
static void rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter,
@@ -322,12 +345,10 @@ static void rewriteToObjCProperty(const
}
// Property with no setter may be suggested as a 'readonly' property.
if (!Setter) {
- if (!LParenAdded) {
- PropertyString += "(readonly";
- LParenAdded = true;
- }
- else
- append_attr(PropertyString, "readonly", LParenAdded);
+ append_attr(PropertyString, "readonly", LParenAdded);
+ QualType ResType = Context.getCanonicalType(Getter->getResultType());
+ if (const char *MemoryManagementAttr = PropertyMemoryAttribute(Context, ResType))
+ append_attr(PropertyString, MemoryManagementAttr, LParenAdded);
}
// Short circuit 'delegate' properties that contain the name "delegate" or
@@ -342,27 +363,8 @@ static void rewriteToObjCProperty(const
else if (Setter) {
const ParmVarDecl *argDecl = *Setter->param_begin();
QualType ArgType = Context.getCanonicalType(argDecl->getType());
- Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
- bool RetainableObject = ArgType->isObjCRetainableType();
- if (RetainableObject && propertyLifetime == Qualifiers::OCL_Strong) {
- if (const ObjCObjectPointerType *ObjPtrTy =
- ArgType->getAs<ObjCObjectPointerType>()) {
- ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
- if (IDecl &&
- IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
- append_attr(PropertyString, "copy", LParenAdded);
- else
- append_attr(PropertyString, "retain", LParenAdded);
- }
- else if (ArgType->isBlockPointerType())
- append_attr(PropertyString, "copy", LParenAdded);
- } else if (propertyLifetime == Qualifiers::OCL_Weak)
- // TODO. More precise determination of 'weak' attribute requires
- // looking into setter's implementation for backing weak ivar.
- append_attr(PropertyString, "weak", LParenAdded);
- else if (RetainableObject)
- append_attr(PropertyString,
- ArgType->isBlockPointerType() ? "copy" : "retain", LParenAdded);
+ if (const char *MemoryManagementAttr = PropertyMemoryAttribute(Context, ArgType))
+ append_attr(PropertyString, MemoryManagementAttr, LParenAdded);
}
if (LParenAdded)
PropertyString += ')';
Modified: cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result?rev=194718&r1=194717&r2=194718&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result Thu Nov 14 12:28:58 2013
@@ -80,14 +80,14 @@ typedef char BOOL;
- (void) Nothing;
@property (readonly) int Length;
- at property (readonly) id object;
+ at property (readonly, retain) id object;
+ (double) D;
@property (readonly) void *JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
@property (getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
@property (getter=getStringValue, retain) NSString *stringValue;
@property (getter=getCounterValue, readonly) BOOL counterValue;
- at property (getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+ at property (getter=getns_dixtionary, readonly, retain) NSDictionary *ns_dixtionary;
- (BOOL)is3bar; // watch out
- (NSString *)get3foo; // watch out
@@ -124,7 +124,7 @@ typedef char BOOL;
- (void) Nothing;
@property (readonly) int Length;
- at property (readonly) id object;
+ at property (readonly, retain) id object;
+ (double) D;
- (BOOL)is3bar; // watch out
@@ -170,7 +170,7 @@ DEPRECATED
@property (retain) NSURL *appStoreReceiptURLY ;
- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
- at property (readonly) id OkToInfer NS_AVAILABLE;
+ at property (readonly, retain) id OkToInfer NS_AVAILABLE;
// Do not infer a property.
@property (retain) NSURL *appStoreReceiptURLZ ;
@@ -195,7 +195,7 @@ DEPRECATED
@class NSMutableDictionary;
@interface NSArray
- at property (readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (readonly, copy) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
@property (copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
@property (readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *);
@property id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *);
Modified: 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=194718&r1=194717&r2=194718&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result Thu Nov 14 12:28:58 2013
@@ -87,14 +87,14 @@ typedef char BOOL;
- (void) Nothing;
@property (NS_NONATOMIC_IOSONLY, readonly) int Length;
- at property (NS_NONATOMIC_IOSONLY, readonly) id object;
+ at property (NS_NONATOMIC_IOSONLY, readonly, retain) id object;
+ (double) D;
@property (NS_NONATOMIC_IOSONLY, readonly) void *JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
@property (NS_NONATOMIC_IOSONLY, getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
@property (NS_NONATOMIC_IOSONLY, getter=getStringValue, retain) NSString *stringValue;
@property (NS_NONATOMIC_IOSONLY, getter=getCounterValue, readonly) BOOL counterValue;
- at property (NS_NONATOMIC_IOSONLY, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+ at property (NS_NONATOMIC_IOSONLY, getter=getns_dixtionary, readonly, retain) NSDictionary *ns_dixtionary;
- (BOOL)is3bar; // watch out
- (NSString *)get3foo; // watch out
@@ -131,7 +131,7 @@ typedef char BOOL;
- (void) Nothing;
@property (NS_NONATOMIC_IOSONLY, readonly) int Length;
- at property (NS_NONATOMIC_IOSONLY, readonly) id object;
+ at property (NS_NONATOMIC_IOSONLY, readonly, retain) id object;
+ (double) D;
- (BOOL)is3bar; // watch out
@@ -177,7 +177,7 @@ DEPRECATED
@property (NS_NONATOMIC_IOSONLY, retain) NSURL *appStoreReceiptURLY ;
- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
- at property (NS_NONATOMIC_IOSONLY, readonly) id OkToInfer NS_AVAILABLE;
+ at property (NS_NONATOMIC_IOSONLY, readonly, retain) id OkToInfer NS_AVAILABLE;
// Do not infer a property.
@property (NS_NONATOMIC_IOSONLY, retain) NSURL *appStoreReceiptURLZ ;
@@ -202,7 +202,7 @@ DEPRECATED
@class NSMutableDictionary;
@interface NSArray
- at property (NS_NONATOMIC_IOSONLY, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (NS_NONATOMIC_IOSONLY, readonly, copy) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
@property (NS_NONATOMIC_IOSONLY, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
@property (NS_NONATOMIC_IOSONLY, readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *);
@property (NS_NONATOMIC_IOSONLY) id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *);
Modified: cfe/trunk/test/ARCMT/objcmt-property.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m.result?rev=194718&r1=194717&r2=194718&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Thu Nov 14 12:28:58 2013
@@ -80,14 +80,14 @@ typedef char BOOL;
- (void) Nothing;
@property (nonatomic, readonly) int Length;
- at property (nonatomic, readonly) id object;
+ at property (nonatomic, readonly, retain) id object;
+ (double) D;
@property (nonatomic, readonly) void *JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
@property (nonatomic, getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
@property (nonatomic, getter=getStringValue, retain) NSString *stringValue;
@property (nonatomic, getter=getCounterValue, readonly) BOOL counterValue;
- at property (nonatomic, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+ at property (nonatomic, getter=getns_dixtionary, readonly, retain) NSDictionary *ns_dixtionary;
- (BOOL)is3bar; // watch out
- (NSString *)get3foo; // watch out
@@ -124,7 +124,7 @@ typedef char BOOL;
- (void) Nothing;
@property (nonatomic, readonly) int Length;
- at property (nonatomic, readonly) id object;
+ at property (nonatomic, readonly, retain) id object;
+ (double) D;
- (BOOL)is3bar; // watch out
@@ -170,7 +170,7 @@ DEPRECATED
@property (nonatomic, retain) NSURL *appStoreReceiptURLY ;
- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
- at property (nonatomic, readonly) id OkToInfer NS_AVAILABLE;
+ at property (nonatomic, readonly, retain) id OkToInfer NS_AVAILABLE;
// Do not infer a property.
@property (nonatomic, retain) NSURL *appStoreReceiptURLZ ;
@@ -195,7 +195,7 @@ DEPRECATED
@class NSMutableDictionary;
@interface NSArray
- at property (nonatomic, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (nonatomic, readonly, copy) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
@property (nonatomic, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
@property (nonatomic, readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *);
@property (nonatomic) id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *);
More information about the cfe-commits
mailing list