ObjectiveC migrator: until we have beter understanding of

setter/getter implementations, migrate them to
nonatomic properties.

llvm-svn: 188914
This commit is contained in:
Fariborz Jahanian 2013-08-21 18:49:03 +00:00
parent 8c407dedd3
commit 447b15ef22
2 changed files with 25 additions and 29 deletions

View File

@ -222,11 +222,9 @@ void ObjCMigrateASTConsumer::migrateDecl(Decl *D) {
BodyMigrator(*this).TraverseDecl(D);
}
static void append_attr(std::string &PropertyString, const char *attr,
bool GetterHasIsPrefix) {
PropertyString += (GetterHasIsPrefix ? ", " : "(");
static void append_attr(std::string &PropertyString, const char *attr) {
PropertyString += ", ";
PropertyString += attr;
PropertyString += ')';
}
static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
@ -234,11 +232,11 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const NSAPI &NS, edit::Commit &commit,
bool GetterHasIsPrefix) {
ASTContext &Context = NS.getASTContext();
std::string PropertyString = "@property";
std::string PropertyString = "@property(nonatomic";
std::string PropertyNameString = Getter->getNameAsString();
StringRef PropertyName(PropertyNameString);
if (GetterHasIsPrefix) {
PropertyString += "(getter=";
PropertyString += ", getter=";
PropertyString += PropertyNameString;
}
// Short circuit properties that contain the name "delegate" or "dataSource",
@ -246,7 +244,7 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
if (PropertyName.equals("target") ||
(PropertyName.find("delegate") != StringRef::npos) ||
(PropertyName.find("dataSource") != StringRef::npos))
append_attr(PropertyString, "unsafe_unretained", GetterHasIsPrefix);
append_attr(PropertyString, "unsafe_unretained");
else {
const ParmVarDecl *argDecl = *Setter->param_begin();
QualType ArgType = Context.getCanonicalType(argDecl->getType());
@ -258,20 +256,18 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter,
ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
if (IDecl &&
IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
append_attr(PropertyString, "copy", GetterHasIsPrefix);
append_attr(PropertyString, "copy");
else
append_attr(PropertyString, "retain", GetterHasIsPrefix);
} else if (GetterHasIsPrefix)
PropertyString += ')';
append_attr(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.
append_attr(PropertyString, "weak", GetterHasIsPrefix);
append_attr(PropertyString, "weak");
else if (RetainableObject)
append_attr(PropertyString, "retain", GetterHasIsPrefix);
else if (GetterHasIsPrefix)
PropertyString += ')';
append_attr(PropertyString, "retain");
}
PropertyString += ')';
QualType RT = Getter->getResultType();
if (!isa<TypedefType>(RT)) {

View File

@ -17,9 +17,9 @@ typedef char BOOL;
int ivarVal;
}
@property(weak) NSString * WeakProp;
@property(nonatomic, weak) NSString * WeakProp;
@property(retain) NSString * StrongProp;
@property(nonatomic, retain) NSString * StrongProp;
- (NSString *) UnavailProp __attribute__((unavailable));
@ -31,7 +31,7 @@ typedef char BOOL;
- (NSString *) UnavailProp2;
- (void) setUnavailProp2 : (NSString *)Val __attribute__((unavailable));
@property(copy) NSDictionary * undoAction;
@property(nonatomic, copy) NSDictionary * undoAction;
@end
@ -51,35 +51,35 @@ typedef char BOOL;
@property(retain) NSArray * names2;
@property(retain) NSArray * names3;
@property(retain) NSArray * names4;
@property(retain) NSArray * names1;
@property(nonatomic, retain) NSArray * names2;
@property(nonatomic, retain) NSArray * names3;
@property(nonatomic, retain) NSArray * names4;
@property(nonatomic, retain) NSArray * names1;
@end
// Properties that contain the name "delegate" or "dataSource",
// or have exact name "target" have unsafe_unretained attribute.
@interface NSInvocation
@property(unsafe_unretained) id target;
@property(nonatomic, unsafe_unretained) id target;
@property(unsafe_unretained) id dataSource;
@property(nonatomic, unsafe_unretained) id dataSource;
@property(unsafe_unretained) id xxxdelegateYYY;
@property(nonatomic, unsafe_unretained) id xxxdelegateYYY;
@property(retain) id MYtarget;
@property(nonatomic, retain) id MYtarget;
@property(retain) id targetX;
@property(nonatomic, retain) id targetX;
@property int value;
@property(nonatomic) int value;
@property(getter=isContinuous) BOOL continuous;
@property(nonatomic, getter=isContinuous) BOOL continuous;
- (id) isAnObject;