From 8677ccd659c5f997ae9c4758f8e9aac2ae7f4a14 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 21 Aug 2013 18:49:03 +0000 Subject: [PATCH] ObjectiveC migrator: until we have beter understanding of setter/getter implementations, migrate them to nonatomic properties. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188914 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 26 +++++++++++--------------- test/ARCMT/objcmt-property.m.result | 28 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 37e2214233..6ad861531f 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -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(RT)) { diff --git a/test/ARCMT/objcmt-property.m.result b/test/ARCMT/objcmt-property.m.result index dcdf0da773..5fa9063327 100644 --- a/test/ARCMT/objcmt-property.m.result +++ b/test/ARCMT/objcmt-property.m.result @@ -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; -- 2.40.0