]> granicus.if.org Git - clang/commitdiff
Objective-C SDK modernizer. Modernize to use
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 9 Dec 2014 22:36:47 +0000 (22:36 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 9 Dec 2014 22:36:47 +0000 (22:36 +0000)
property-dot-syntax when receiver is 'super'.
rdar://19140267

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

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-property-dot-syntax.m
test/ARCMT/objcmt-property-dot-syntax.m.result

index af9c472550ed4d3d7f202b99fc14fa709099b461..d017acf527822f640ca98d7e736b19a7da44d3bf 100644 (file)
@@ -242,7 +242,8 @@ namespace {
                                   const NSAPI &NS, edit::Commit &commit,
                                   const ParentMap *PMap) {
     if (!Msg || Msg->isImplicit() ||
-        Msg->getReceiverKind() != ObjCMessageExpr::Instance)
+        (Msg->getReceiverKind() != ObjCMessageExpr::Instance &&
+         Msg->getReceiverKind() != ObjCMessageExpr::SuperInstance))
       return false;
     const ObjCMethodDecl *Method = Msg->getMethodDecl();
     if (!Method)
@@ -260,12 +261,17 @@ namespace {
       return false;
     
     SourceRange MsgRange = Msg->getSourceRange();
+    bool ReceiverIsSuper =
+      (Msg->getReceiverKind() == ObjCMessageExpr::SuperInstance);
+    // for 'super' receiver is nullptr.
     const Expr *receiver = Msg->getInstanceReceiver();
-    bool NeedsParen = subscriptOperatorNeedsParens(receiver);
+    bool NeedsParen =
+      ReceiverIsSuper ? false : subscriptOperatorNeedsParens(receiver);
     bool IsGetter = (Msg->getNumArgs() == 0);
     if (IsGetter) {
       // Find space location range between receiver expression and getter method.
-      SourceLocation BegLoc = receiver->getLocEnd();
+      SourceLocation BegLoc =
+        ReceiverIsSuper ? Msg->getSuperLoc() : receiver->getLocEnd();
       BegLoc = PP.getLocForEndOfToken(BegLoc);
       SourceLocation EndLoc = Msg->getSelectorLoc(0);
       SourceRange SpaceRange(BegLoc, EndLoc);
@@ -285,9 +291,8 @@ namespace {
       commit.replace(SourceRange(MsgRange.getBegin(), MsgRange.getBegin()), "");
       commit.replace(SourceRange(MsgRange.getEnd(), MsgRange.getEnd()), "");
     } else {
-      SourceRange ReceiverRange = receiver->getSourceRange();
       if (NeedsParen)
-        commit.insertWrap("(", ReceiverRange, ")");
+        commit.insertWrap("(", receiver->getSourceRange(), ")");
       std::string PropertyDotString = ".";
       PropertyDotString += Prop->getName();
       PropertyDotString += " =";
@@ -295,7 +300,8 @@ namespace {
       const Expr *RHS = Args[0];
       if (!RHS)
         return false;
-      SourceLocation BegLoc = ReceiverRange.getEnd();
+      SourceLocation BegLoc =
+        ReceiverIsSuper ? Msg->getSuperLoc() : receiver->getLocEnd();
       BegLoc = PP.getLocForEndOfToken(BegLoc);
       SourceLocation EndLoc = RHS->getLocStart();
       EndLoc = EndLoc.getLocWithOffset(-1);
index 42aade5aca2ede9ab8b0358da3d47533eae9aad7..0e25abcb89ecc4380ffb91487abac3e72cd77d71 100644 (file)
@@ -37,3 +37,25 @@ P* fun();
 
 - (P*) MethodReturnsPObj { return 0; }
 @end
+
+// rdar://19140267
+@interface Sub : P
+@end
+
+@implementation Sub
+- (int) Meth : (P*)array {
+  [super setCount : 100];
+
+  [super setCount : [array count]];
+
+  [[super PropertyReturnsPObj] setCount : [array count]];
+
+  [super setCount : (i1+i2*i3 - 100)];
+
+  return [super count] -
+         [(P*)0 count] + [array count] +
+         [fun() count] -
+         [[super PropertyReturnsPObj] count] +
+         [self->obj count];
+}
+@end
index 88006e9fc59ea56e975e46acc76a56898418866f..6822d44ac0a542c0b86ac2f4c8b18cbb52167c90 100644 (file)
@@ -37,3 +37,25 @@ P* fun();
 
 - (P*) MethodReturnsPObj { return 0; }
 @end
+
+// rdar://19140267
+@interface Sub : P
+@end
+
+@implementation Sub
+- (int) Meth : (P*)array {
+  super.count = 100;
+
+  super.count = array.count;
+
+  super.PropertyReturnsPObj.count = array.count;
+
+  super.count = (i1+i2*i3 - 100);
+
+  return super.count -
+         ((P*)0).count + array.count +
+         fun().count -
+         super.PropertyReturnsPObj.count +
+         self->obj.count;
+}
+@end