r192834 - ObjectiveC migrator. 'atomic' is the default attribute.
Fariborz Jahanian
fjahanian at apple.com
Wed Oct 16 12:48:23 PDT 2013
Author: fjahanian
Date: Wed Oct 16 14:48:23 2013
New Revision: 192834
URL: http://llvm.org/viewvc/llvm-project?rev=192834&view=rev
Log:
ObjectiveC migrator. 'atomic' is the default attribute.
Don't add it to inferred property. // rdar://14988132
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=192834&r1=192833&r2=192834&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Oct 16 14:48:23 2013
@@ -229,8 +229,14 @@ void ObjCMigrateASTConsumer::migrateDecl
BodyMigrator(*this).TraverseDecl(D);
}
-static void append_attr(std::string &PropertyString, const char *attr) {
- PropertyString += ", ";
+static void append_attr(std::string &PropertyString, const char *attr,
+ bool &LParenAdded) {
+ if (!LParenAdded) {
+ PropertyString += "(";
+ LParenAdded = true;
+ }
+ else
+ PropertyString += ", ";
PropertyString += attr;
}
@@ -273,24 +279,40 @@ static bool rewriteToObjCProperty(const
unsigned LengthOfPrefix,
bool Atomic) {
ASTContext &Context = NS.getASTContext();
- std::string PropertyString = "@property (";
- PropertyString += (Atomic ? "atomic" : "nonatomic");
+ bool LParenAdded = false;
+ std::string PropertyString = "@property ";
+ if (!Atomic) {
+ PropertyString += "(nonatomic";
+ LParenAdded = true;
+ }
+
std::string PropertyNameString = Getter->getNameAsString();
StringRef PropertyName(PropertyNameString);
if (LengthOfPrefix > 0) {
- PropertyString += ", getter=";
+ if (!LParenAdded) {
+ PropertyString += "(getter=";
+ LParenAdded = true;
+ }
+ else
+ PropertyString += ", getter=";
PropertyString += PropertyNameString;
}
// Property with no setter may be suggested as a 'readonly' property.
- if (!Setter)
- append_attr(PropertyString, "readonly");
+ if (!Setter) {
+ if (!LParenAdded) {
+ PropertyString += "(readonly";
+ LParenAdded = true;
+ }
+ else
+ append_attr(PropertyString, "readonly", LParenAdded);
+ }
// Short circuit 'delegate' properties that contain the name "delegate" or
// "dataSource", or have exact name "target" to have 'assign' attribute.
if (PropertyName.equals("target") ||
(PropertyName.find("delegate") != StringRef::npos) ||
(PropertyName.find("dataSource") != StringRef::npos))
- append_attr(PropertyString, "assign");
+ append_attr(PropertyString, "assign", LParenAdded);
else if (Setter) {
const ParmVarDecl *argDecl = *Setter->param_begin();
QualType ArgType = Context.getCanonicalType(argDecl->getType());
@@ -302,21 +324,22 @@ static bool rewriteToObjCProperty(const
ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
if (IDecl &&
IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
- append_attr(PropertyString, "copy");
+ append_attr(PropertyString, "copy", LParenAdded);
else
- append_attr(PropertyString, "retain");
+ append_attr(PropertyString, "retain", LParenAdded);
}
else if (ArgType->isBlockPointerType())
- append_attr(PropertyString, "copy");
+ 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");
+ append_attr(PropertyString, "weak", LParenAdded);
else if (RetainableObject)
append_attr(PropertyString,
- ArgType->isBlockPointerType() ? "copy" : "retain");
+ ArgType->isBlockPointerType() ? "copy" : "retain", LParenAdded);
}
- PropertyString += ')';
+ if (LParenAdded)
+ PropertyString += ')';
QualType RT = Getter->getResultType();
if (!isa<TypedefType>(RT)) {
// strip off any ARC lifetime qualifier.
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=192834&r1=192833&r2=192834&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-atomic-property.m.result Wed Oct 16 14:48:23 2013
@@ -22,21 +22,21 @@ typedef char BOOL;
int ivarVal;
}
- at property (atomic, weak) NSString *WeakProp;
+ at property (weak) NSString *WeakProp;
- at property (atomic, retain) NSString *StrongProp;
+ at property (retain) NSString *StrongProp;
- (NSString *) UnavailProp __attribute__((unavailable));
- (void) setUnavailProp : (NSString *)Val;
- at property (atomic, retain) NSString *UnavailProp1 __attribute__((unavailable));
+ at property (retain) NSString *UnavailProp1 __attribute__((unavailable));
- (NSString *) UnavailProp2;
- (void) setUnavailProp2 : (NSString *)Val __attribute__((unavailable));
- at property (atomic, copy) NSDictionary *undoAction;
+ at property (copy) NSDictionary *undoAction;
@end
@@ -56,108 +56,108 @@ typedef char BOOL;
- at property (atomic, retain) NSArray *names2;
- at property (atomic, retain) NSArray *names3;
- at property (atomic, retain) NSArray *names4;
- at property (atomic, retain) NSArray *names1;
+ at property (retain) NSArray *names2;
+ at property (retain) NSArray *names3;
+ at property (retain) NSArray *names4;
+ at property (retain) NSArray *names1;
@end
// Properties that contain the name "delegate" or "dataSource",
// or have exact name "target" have unsafe_unretained attribute.
@interface NSInvocation
- at property (atomic, assign) id target;
+ at property (assign) id target;
- at property (atomic, assign) id dataSource;
+ at property (assign) id dataSource;
- at property (atomic, assign) id xxxdelegateYYY;
+ at property (assign) id xxxdelegateYYY;
- at property (atomic, retain) id MYtarget;
+ at property (retain) id MYtarget;
- at property (atomic, retain) id targetX;
+ at property (retain) id targetX;
- at property (atomic) int value;
+ at property int value;
- at property (atomic, getter=isContinuous) BOOL continuous;
+ at property (getter=isContinuous) BOOL continuous;
- (id) isAnObject;
- (void)setAnObject : (id) object;
- at property (atomic, getter=isinValid, readonly) BOOL inValid;
+ at property (getter=isinValid, readonly) BOOL inValid;
- (void) setInValid : (BOOL) arg;
- (void) Nothing;
- at property (atomic, readonly) int Length;
- at property (atomic, readonly) id object;
+ at property (readonly) int Length;
+ at property (readonly) id object;
+ (double) D;
- at property (atomic, readonly) void *JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
- at property (atomic, getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
+ at property (readonly) void *JSObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER);
+ at property (getter=isIgnoringInteractionEvents, readonly) BOOL ignoringInteractionEvents;
- at property (atomic, getter=getStringValue, retain) NSString *stringValue;
- at property (atomic, getter=getCounterValue, readonly) BOOL counterValue;
+ at property (getter=getStringValue, retain) NSString *stringValue;
+ at property (getter=getCounterValue, readonly) BOOL counterValue;
- at property (atomic, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
+ at property (getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary;
- (BOOL)is3bar; // watch out
- (NSString *)get3foo; // watch out
- at property (atomic, getter=getM, readonly) BOOL m;
- at property (atomic, getter=getMA, readonly) BOOL MA;
- at property (atomic, getter=getALL, readonly) BOOL ALL;
- at property (atomic, getter=getMANY, readonly) BOOL MANY;
- at property (atomic, getter=getSome, readonly) BOOL some;
+ at property (getter=getM, readonly) BOOL m;
+ at property (getter=getMA, readonly) BOOL MA;
+ at property (getter=getALL, readonly) BOOL ALL;
+ at property (getter=getMANY, readonly) BOOL MANY;
+ at property (getter=getSome, readonly) BOOL some;
@end
@interface NSInvocation(CAT)
- at property (atomic, assign) id target;
+ at property (assign) id target;
- at property (atomic, assign) id dataSource;
+ at property (assign) id dataSource;
- at property (atomic, assign) id xxxdelegateYYY;
+ at property (assign) id xxxdelegateYYY;
- at property (atomic, retain) id MYtarget;
+ at property (retain) id MYtarget;
- at property (atomic, retain) id targetX;
+ at property (retain) id targetX;
- at property (atomic) int value;
+ at property int value;
- at property (atomic, getter=isContinuous) BOOL continuous;
+ at property (getter=isContinuous) BOOL continuous;
- (id) isAnObject;
- (void)setAnObject : (id) object;
- at property (atomic, getter=isinValid, readonly) BOOL inValid;
+ at property (getter=isinValid, readonly) BOOL inValid;
- (void) setInValid : (BOOL) arg;
- (void) Nothing;
- at property (atomic, readonly) int Length;
- at property (atomic, readonly) id object;
+ at property (readonly) int Length;
+ at property (readonly) id object;
+ (double) D;
- (BOOL)is3bar; // watch out
- (NSString *)get3foo; // watch out
- at property (atomic, getter=getM, readonly) BOOL m;
- at property (atomic, getter=getMA, readonly) BOOL MA;
- at property (atomic, getter=getALL, readonly) BOOL ALL;
- at property (atomic, getter=getMANY, readonly) BOOL MANY;
- at property (atomic, getter=getSome, readonly) BOOL some;
+ at property (getter=getM, readonly) BOOL m;
+ at property (getter=getMA, readonly) BOOL MA;
+ at property (getter=getALL, readonly) BOOL ALL;
+ at property (getter=getMANY, readonly) BOOL MANY;
+ at property (getter=getSome, readonly) BOOL some;
@end
DEPRECATED
@@ -187,14 +187,14 @@ DEPRECATED
- (NSURL *)appStoreReceiptURL NS_AVAILABLE;
- (void) setAppStoreReceiptURL : (NSURL *)object;
- at property (atomic, retain) NSURL *appStoreReceiptURLX NS_AVAILABLE;
+ at property (retain) NSURL *appStoreReceiptURLX NS_AVAILABLE;
// Do not infer a property.
- (NSURL *)appStoreReceiptURLY ;
- (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE;
- at property (atomic, readonly) id OkToInfer NS_AVAILABLE;
+ at property (readonly) id OkToInfer NS_AVAILABLE;
// Do not infer a property.
- (NSURL *)appStoreReceiptURLZ ;
@@ -204,14 +204,14 @@ DEPRECATED
- (id) t1 NORETURN NS_AVAILABLE;
- (void) setT1 : (id) arg NS_AVAILABLE;
- at property (atomic, retain) id method1 ALIGNED NS_AVAILABLE;
+ at property (retain) id method1 ALIGNED NS_AVAILABLE;
- (NSURL *)init; // No Change
+ (id)alloc; // No Change
- (BOOL)is1stClass; // Not a valid property
- at property (atomic, getter=isClass, readonly) BOOL class; // This is a valid property 'class' is not a keyword in ObjC
+ at property (getter=isClass, readonly) BOOL class; // This is a valid property 'class' is not a keyword in ObjC
- (BOOL)isDouble; // Not a valid property
@end
@@ -220,10 +220,10 @@ DEPRECATED
@class NSMutableDictionary;
@interface NSArray
- at property (atomic, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
- at property (atomic, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *);
+ at property (copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *);
- at property (atomic, readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *);
- at property (atomic) id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *);
+ at property (readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *);
+ at property id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *);
@end
More information about the cfe-commits
mailing list