]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: until we have beter understanding of
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Aug 2013 18:49:03 +0000 (18:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Aug 2013 18:49:03 +0000 (18:49 +0000)
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
test/ARCMT/objcmt-property.m.result

index 37e2214233e0e7bebf6de14d68bce248f5da0278..6ad861531f2866b91bf8a8d937767d38c230fc12 100644 (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)) {
index dcdf0da773c4f99145150cc68b02782acd728cae..5fa9063327787f90b62095da8fe6282f6d2ee4e4 100644 (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;