]> granicus.if.org Git - clang/commitdiff
[arcmt] In ARC default for properties is 'strong' so just remove a 'retain' if possible,
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 17 Oct 2011 23:14:16 +0000 (23:14 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 17 Oct 2011 23:14:16 +0000 (23:14 +0000)
instead of changing it to 'strong'. rdar://9984862.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142304 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/TransProperties.cpp
test/ARCMT/assign-prop-with-arc-runtime.m
test/ARCMT/assign-prop-with-arc-runtime.m.result
test/ARCMT/releases-driver.m.result
test/ARCMT/releases.m.result
test/ARCMT/remove-dealloc-method.m.result
test/ARCMT/remove-dealloc-zerouts.m.result
test/ARCMT/retains.m.result

index ca845b6b330d236dc7f5e27f21b67ceaabe623d5..2f5fe8be4cf2617f8eddd47b1889f55e82e16e08 100644 (file)
@@ -132,7 +132,10 @@ private:
       return;
 
     if (propAttrs & ObjCPropertyDecl::OBJC_PR_retain) {
-      rewriteAttribute("retain", "strong", atLoc);
+      if (propAttrs & ObjCPropertyDecl::OBJC_PR_readonly)
+        rewriteAttribute("retain", "strong", atLoc);
+      else
+        removeAttribute("retain", atLoc); // strong is the default.
       return;
     }
 
@@ -215,6 +218,10 @@ private:
     }
   }
 
+  bool removeAttribute(StringRef fromAttr, SourceLocation atLoc) const {
+    return rewriteAttribute(fromAttr, StringRef(), atLoc);
+  }
+
   bool rewriteAttribute(StringRef fromAttr, StringRef toAttr,
                         SourceLocation atLoc) const {
     if (atLoc.isMacroID())
@@ -248,6 +255,11 @@ private:
     lexer.LexFromRawLexer(tok);
     if (tok.isNot(tok::l_paren)) return false;
     
+    Token BeforeTok = tok;
+    Token AfterTok;
+    AfterTok.startToken();
+    SourceLocation AttrLoc;
+    
     lexer.LexFromRawLexer(tok);
     if (tok.is(tok::r_paren))
       return false;
@@ -256,18 +268,40 @@ private:
       if (tok.isNot(tok::raw_identifier)) return false;
       StringRef ident(tok.getRawIdentifierData(), tok.getLength());
       if (ident == fromAttr) {
-        Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
-        return true;
+        if (!toAttr.empty()) {
+          Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
+          return true;
+        }
+        // We want to remove the attribute.
+        AttrLoc = tok.getLocation();
       }
 
       do {
         lexer.LexFromRawLexer(tok);
+        if (AttrLoc.isValid() && AfterTok.is(tok::unknown))
+          AfterTok = tok;
       } while (tok.isNot(tok::comma) && tok.isNot(tok::r_paren));
       if (tok.is(tok::r_paren))
         break;
+      if (AttrLoc.isInvalid())
+        BeforeTok = tok;
       lexer.LexFromRawLexer(tok);
     }
 
+    if (toAttr.empty() && AttrLoc.isValid() && AfterTok.isNot(tok::unknown)) {
+      // We want to remove the attribute.
+      if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::r_paren)) {
+        Pass.TA.remove(SourceRange(BeforeTok.getLocation(),
+                                   AfterTok.getLocation()));
+      } else if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::comma)) {
+        Pass.TA.remove(SourceRange(AttrLoc, AfterTok.getLocation()));
+      } else {
+        Pass.TA.remove(SourceRange(BeforeTok.getLocation(), AttrLoc));
+      }
+
+      return true;
+    }
+    
     return false;
   }
 
index 9e10b58f621f8f976337c5926cf41462ef045512..4f50aac8eb3fe284742bb58904185e523554f787 100644 (file)
@@ -36,12 +36,18 @@ typedef _NSCachedAttributedString *BadClassForWeak;
 
 @property (assign) Foo *no_user_ivar1;
 @property (readonly) Foo *no_user_ivar2;
+
+@property (retain) id def1;
+@property (atomic,retain) id def2;
+@property (retain,atomic) id def3;
+
 @end
 
 @implementation Foo
 @synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3;
 @synthesize no_user_ivar1, no_user_ivar2;
 @synthesize assign_plus1, assign_plus2, assign_plus3;
+@synthesize def1, def2, def3;
 
 -(void)test:(Foo *)parm {
   assign_plus1 = [[Foo alloc] init];
index 8a3a0f78b6b66f33f50beec96d9f062bc0067348..796af230b4526c943b00dabe101dee690d9bcff6 100644 (file)
@@ -36,12 +36,18 @@ typedef _NSCachedAttributedString *BadClassForWeak;
 
 @property (weak) Foo *no_user_ivar1;
 @property (weak, readonly) Foo *no_user_ivar2;
+
+@property  id def1;
+@property (atomic) id def2;
+@property (atomic) id def3;
+
 @end
 
 @implementation Foo
 @synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3;
 @synthesize no_user_ivar1, no_user_ivar2;
 @synthesize assign_plus1, assign_plus2, assign_plus3;
+@synthesize def1, def2, def3;
 
 -(void)test:(Foo *)parm {
   assign_plus1 = [[Foo alloc] init];
index 70c0aecaf4755510fc40e4d5b65fa21b80b34e7f..14aecce8e9e1f29590014bf76fac41f79b8d72ce 100644 (file)
@@ -20,7 +20,7 @@ id IhaveSideEffect();
 @interface Foo : NSObject {
   id bar;
 }
-@property (strong) id bar;
+@property  id bar;
 -(void)test:(id)obj;
 @end
 
index 556610ab2a53484ece314125c2d4be5b7bd33430..2b6240b10e2ec9f70904f7f6bcb52007e22a7e3f 100644 (file)
@@ -20,7 +20,7 @@ id IhaveSideEffect();
 @interface Foo : NSObject {
   id bar;
 }
-@property (strong) id bar;
+@property  id bar;
 -(void)test:(id)obj;
 @end
 
index 47e31f9d249aed7ce2c70910bbaa8e66f5e660f0..5e1efa868774c02ddb56d24d92f9239303a2d7dd 100644 (file)
@@ -5,10 +5,10 @@
 #define nil ((void*) 0)
 
 @interface Foo 
-@property (strong) id x;
-@property (strong) id y;
-@property (strong) id w;
-@property (strong) id z;
+@property  id x;
+@property  id y;
+@property  id w;
+@property  id z;
 @end
 
 @implementation Foo 
index 9ae831abacf25c28007e4421243e30d9b5e22812..c857760bc395c954c9883b688d45146b9889a1ce 100644 (file)
@@ -3,10 +3,10 @@
 // RUN: diff %t %s.result
 
 @interface Foo 
-@property (strong) id x;
-@property (strong) id y;
-@property (strong) id w;
-@property (strong) id z;
+@property  id x;
+@property  id y;
+@property  id w;
+@property  id z;
 @property (strong) id q;
 @end
 
@@ -23,7 +23,7 @@
 @end
 
 @interface Bar
-@property (strong) Foo *a;
+@property  Foo *a;
 - (void) setA:(Foo*) val;
 - (id) a;
 @end
index 2011e506360c575526e12016d793704d4f363f41..19f8972942aaeb41b8a0020604036520669caeb5 100644 (file)
@@ -9,7 +9,7 @@ id IhaveSideEffect();
 @interface Foo : NSObject {
   id bar;
 }
-@property (strong) id bar;
+@property  id bar;
 -(id)test:(id)obj;
 -(id)something;
 @end