summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2014-12-09 22:36:47 +0000
committerFariborz Jahanian <fjahanian@apple.com>2014-12-09 22:36:47 +0000
commitdf833a49186f7a7f7f632d35ca7a5ee757953f2d (patch)
treef0af1453f87d81a523a491fd3b6ef2696e39f0b8
parentb32bf14c2ae6d75d2fa5721d2819574df3a1a982 (diff)
downloadbcm5719-llvm-df833a49186f7a7f7f632d35ca7a5ee757953f2d.tar.gz
bcm5719-llvm-df833a49186f7a7f7f632d35ca7a5ee757953f2d.zip
Objective-C SDK modernizer. Modernize to use
property-dot-syntax when receiver is 'super'. rdar://19140267 llvm-svn: 223846
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp18
-rw-r--r--clang/test/ARCMT/objcmt-property-dot-syntax.m22
-rw-r--r--clang/test/ARCMT/objcmt-property-dot-syntax.m.result22
3 files changed, 56 insertions, 6 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index af9c472550e..d017acf5278 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -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);
diff --git a/clang/test/ARCMT/objcmt-property-dot-syntax.m b/clang/test/ARCMT/objcmt-property-dot-syntax.m
index 42aade5aca2..0e25abcb89e 100644
--- a/clang/test/ARCMT/objcmt-property-dot-syntax.m
+++ b/clang/test/ARCMT/objcmt-property-dot-syntax.m
@@ -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
diff --git a/clang/test/ARCMT/objcmt-property-dot-syntax.m.result b/clang/test/ARCMT/objcmt-property-dot-syntax.m.result
index 88006e9fc59..6822d44ac0a 100644
--- a/clang/test/ARCMT/objcmt-property-dot-syntax.m.result
+++ b/clang/test/ARCMT/objcmt-property-dot-syntax.m.result
@@ -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
OpenPOWER on IntegriCloud