r187810 - ObjectiveC migration: tweak setting of lifetime attribute
Fariborz Jahanian
fjahanian at apple.com
Tue Aug 6 11:06:24 PDT 2013
Author: fjahanian
Date: Tue Aug 6 13:06:23 2013
New Revision: 187810
URL: http://llvm.org/viewvc/llvm-project?rev=187810&view=rev
Log:
ObjectiveC migration: tweak setting of lifetime attribute
on @property migration. Don't set unsafe_unretained
on non-object properties. Set 'retain' on strong
properties. Makecertain properties with specific
names unsafe_unretained as well.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-property.m
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=187810&r1=187809&r2=187810&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Aug 6 13:06:23 2013
@@ -211,26 +211,37 @@ static bool rewriteToObjCProperty(const
const NSAPI &NS, edit::Commit &commit) {
ASTContext &Context = NS.getASTContext();
std::string PropertyString = "@property";
- const ParmVarDecl *argDecl = *Setter->param_begin();
- QualType ArgType = Context.getCanonicalType(argDecl->getType());
- Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
- if (ArgType->isObjCRetainableType() &&
- propertyLifetime == Qualifiers::OCL_Strong) {
- if (const ObjCObjectPointerType *ObjPtrTy =
- ArgType->getAs<ObjCObjectPointerType>()) {
- ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
- if (IDecl &&
- IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
- PropertyString += "(copy)";
- }
- }
- else if (propertyLifetime == Qualifiers::OCL_Weak)
- // TODO. More precise determination of 'weak' attribute requires
- // looking into setter's implementation for backing weak ivar.
- PropertyString += "(weak)";
- else
+ std::string PropertyNameString = Getter->getNameAsString();
+ StringRef PropertyName(PropertyNameString);
+ // Short circuit properties that contain the name "delegate" or "dataSource",
+ // or have exact name "target" to have unsafe_unretained attribute.
+ if (PropertyName.equals("target") ||
+ (PropertyName.find("delegate") != StringRef::npos) ||
+ (PropertyName.find("dataSource") != StringRef::npos))
PropertyString += "(unsafe_unretained)";
+ else {
+ 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")))
+ PropertyString += "(copy)";
+ else
+ PropertyString += "(retain)";
+ }
+ } else if (propertyLifetime == Qualifiers::OCL_Weak)
+ // TODO. More precise determination of 'weak' attribute requires
+ // looking into setter's implementation for backing weak ivar.
+ PropertyString += "(weak)";
+ else if (RetainableObject)
+ PropertyString += "(retain)";
+ }
// strip off any ARC lifetime qualifier.
QualType CanResultTy = Context.getCanonicalType(Getter->getResultType());
@@ -242,7 +253,7 @@ static bool rewriteToObjCProperty(const
PropertyString += " ";
PropertyString += CanResultTy.getAsString(Context.getPrintingPolicy());
PropertyString += " ";
- PropertyString += Getter->getNameAsString();
+ PropertyString += PropertyNameString;
commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),
Getter->getDeclaratorEndLoc()),
PropertyString);
Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=187810&r1=187809&r2=187810&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Tue Aug 6 13:06:23 2013
@@ -55,3 +55,26 @@
- (__strong NSArray *)names4;
- (NSArray *) names1;
@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;
+ at end
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=187810&r1=187809&r2=187810&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Tue Aug 6 13:06:23 2013
@@ -18,7 +18,7 @@
@property(weak) NSString * WeakProp;
- at property NSString * StrongProp;
+ at property(retain) NSString * StrongProp;
- (NSString *) UnavailProp __attribute__((unavailable));
@@ -50,8 +50,31 @@
- at property NSArray * names2;
- at property NSArray * names3;
- at property NSArray * names4;
- at property NSArray * names1;
+ at property(retain) NSArray * names2;
+ at property(retain) NSArray * names3;
+ at property(retain) NSArray * names4;
+ at property(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(unsafe_unretained) id target;
+
+
+ at property(unsafe_unretained) id dataSource;
+
+ at property(unsafe_unretained) id xxxdelegateYYY;
+
+
+
+
+ at property(retain) id MYtarget;
+
+
+ at property(retain) id targetX;
+
+
+ at property int value;
+
@end
More information about the cfe-commits
mailing list