summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-11-14 18:28:58 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-11-14 18:28:58 +0000
commitda267d0551875e7a0f1ba69734fe5cbcda0912d3 (patch)
treede172f04b4f02464b95bd7fe3038dcec9b30b490
parent561bba2e9f3e67979b0cf6104b48067f8f7d6647 (diff)
downloadbcm5719-llvm-da267d0551875e7a0f1ba69734fe5cbcda0912d3.tar.gz
bcm5719-llvm-da267d0551875e7a0f1ba69734fe5cbcda0912d3.zip
ObjectiveC migrator: This patch sets access property
attributes on 'readonly' properties. // rdar://15460787 llvm-svn: 194718
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp56
-rw-r--r--clang/test/ARCMT/objcmt-atomic-property.m.result10
-rw-r--r--clang/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result10
-rw-r--r--clang/test/ARCMT/objcmt-property.m.result10
4 files changed, 44 insertions, 42 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index ff2ae40758f..cac0fb0aed1 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -291,6 +291,29 @@ void MigrateBlockOrFunctionPointerTypeVariable(std::string & PropertyString,
}
}
+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 ObjCMethodDecl *Getter,
}
// 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 ObjCMethodDecl *Getter,
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 += ')';
diff --git a/clang/test/ARCMT/objcmt-atomic-property.m.result b/clang/test/ARCMT/objcmt-atomic-property.m.result
index 761a208a16b..1650cd23e3b 100644
--- a/clang/test/ARCMT/objcmt-atomic-property.m.result
+++ b/clang/test/ARCMT/objcmt-atomic-property.m.result
@@ -80,14 +80,14 @@ typedef char BOOL;
- (void) Nothing;
@property (readonly) int Length;
-@property (readonly) id object;
+@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;
-@property (getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+@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;
-@property (readonly) id object;
+@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;
-@property (readonly) id OkToInfer NS_AVAILABLE;
+@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
-@property (readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+@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 *);
diff --git a/clang/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result b/clang/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result
index 3eb648b25a8..804142ee328 100644
--- a/clang/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result
+++ b/clang/test/ARCMT/objcmt-ns-nonatomic-iosonly.m.result
@@ -87,14 +87,14 @@ typedef char BOOL;
- (void) Nothing;
@property (NS_NONATOMIC_IOSONLY, readonly) int Length;
-@property (NS_NONATOMIC_IOSONLY, readonly) id object;
+@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;
-@property (NS_NONATOMIC_IOSONLY, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+@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;
-@property (NS_NONATOMIC_IOSONLY, readonly) id object;
+@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;
-@property (NS_NONATOMIC_IOSONLY, readonly) id OkToInfer NS_AVAILABLE;
+@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
-@property (NS_NONATOMIC_IOSONLY, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+@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 *);
diff --git a/clang/test/ARCMT/objcmt-property.m.result b/clang/test/ARCMT/objcmt-property.m.result
index 2d19ddb6809..c6380c80523 100644
--- a/clang/test/ARCMT/objcmt-property.m.result
+++ b/clang/test/ARCMT/objcmt-property.m.result
@@ -80,14 +80,14 @@ typedef char BOOL;
- (void) Nothing;
@property (nonatomic, readonly) int Length;
-@property (nonatomic, readonly) id object;
+@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;
-@property (nonatomic, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+@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;
-@property (nonatomic, readonly) id object;
+@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;
-@property (nonatomic, readonly) id OkToInfer NS_AVAILABLE;
+@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
-@property (nonatomic, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+@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 *);
OpenPOWER on IntegriCloud