r223846 - Objective-C SDK modernizer. Modernize to use

Fariborz Jahanian fjahanian at apple.com
Tue Dec 9 14:36:47 PST 2014


Author: fjahanian
Date: Tue Dec  9 16:36:47 2014
New Revision: 223846

URL: http://llvm.org/viewvc/llvm-project?rev=223846&view=rev
Log:
Objective-C SDK modernizer. Modernize to use 
property-dot-syntax when receiver is 'super'. 
rdar://19140267

Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m
    cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=223846&r1=223845&r2=223846&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Dec  9 16:36:47 2014
@@ -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);

Modified: cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m?rev=223846&r1=223845&r2=223846&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m Tue Dec  9 16:36:47 2014
@@ -37,3 +37,25 @@ P* fun();
 
 - (P*) MethodReturnsPObj { return 0; }
 @end
+
+// rdar://19140267
+ at interface Sub : P
+ at end
+
+ at 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];
+}
+ at end

Modified: cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result?rev=223846&r1=223845&r2=223846&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result Tue Dec  9 16:36:47 2014
@@ -37,3 +37,25 @@ P* fun();
 
 - (P*) MethodReturnsPObj { return 0; }
 @end
+
+// rdar://19140267
+ at interface Sub : P
+ at end
+
+ at 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;
+}
+ at end





More information about the cfe-commits mailing list