summaryrefslogtreecommitdiffstats
path: root/clang/lib/Edit/RewriteObjCFoundationAPI.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-06-06 22:23:12 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-06-06 22:23:12 +0000
commit63aebfb4aee03bd72f4cace716104c83c87c32ef (patch)
tree15312a0ea0efe71f9efee66d42dc6046affcb673 /clang/lib/Edit/RewriteObjCFoundationAPI.cpp
parent9cc3c0307d741d5c4fdca2b98117fc55ca030bcf (diff)
downloadbcm5719-llvm-63aebfb4aee03bd72f4cace716104c83c87c32ef.tar.gz
bcm5719-llvm-63aebfb4aee03bd72f4cace716104c83c87c32ef.zip
[objcmt] When in ARC mode, also convert "[[.. alloc] init]" messages to literals,
since the change from +1 to +0 will be handled fine by ARC. rdar://11606358 llvm-svn: 158114
Diffstat (limited to 'clang/lib/Edit/RewriteObjCFoundationAPI.cpp')
-rw-r--r--clang/lib/Edit/RewriteObjCFoundationAPI.cpp36
1 files changed, 27 insertions, 9 deletions
diff --git a/clang/lib/Edit/RewriteObjCFoundationAPI.cpp b/clang/lib/Edit/RewriteObjCFoundationAPI.cpp
index c36793ff064..465f18051aa 100644
--- a/clang/lib/Edit/RewriteObjCFoundationAPI.cpp
+++ b/clang/lib/Edit/RewriteObjCFoundationAPI.cpp
@@ -22,7 +22,8 @@ using namespace clang;
using namespace edit;
static bool checkForLiteralCreation(const ObjCMessageExpr *Msg,
- IdentifierInfo *&ClassId) {
+ IdentifierInfo *&ClassId,
+ const LangOptions &LangOpts) {
if (!Msg || Msg->isImplicit() || !Msg->getMethodDecl())
return false;
@@ -34,6 +35,18 @@ static bool checkForLiteralCreation(const ObjCMessageExpr *Msg,
if (Msg->getReceiverKind() == ObjCMessageExpr::Class)
return true;
+ // When in ARC mode we also convert "[[.. alloc] init]" messages to literals,
+ // since the change from +1 to +0 will be handled fine by ARC.
+ if (LangOpts.ObjCAutoRefCount) {
+ if (Msg->getReceiverKind() == ObjCMessageExpr::Instance) {
+ if (const ObjCMessageExpr *Rec = dyn_cast<ObjCMessageExpr>(
+ Msg->getInstanceReceiver()->IgnoreParenImpCasts())) {
+ if (Rec->getMethodFamily() == OMF_alloc)
+ return true;
+ }
+ }
+ }
+
return false;
}
@@ -44,7 +57,7 @@ static bool checkForLiteralCreation(const ObjCMessageExpr *Msg,
bool edit::rewriteObjCRedundantCallWithLiteral(const ObjCMessageExpr *Msg,
const NSAPI &NS, Commit &commit) {
IdentifierInfo *II = 0;
- if (!checkForLiteralCreation(Msg, II))
+ if (!checkForLiteralCreation(Msg, II, NS.getASTContext().getLangOpts()))
return false;
if (Msg->getNumArgs() != 1)
return false;
@@ -54,16 +67,19 @@ bool edit::rewriteObjCRedundantCallWithLiteral(const ObjCMessageExpr *Msg,
if ((isa<ObjCStringLiteral>(Arg) &&
NS.getNSClassId(NSAPI::ClassId_NSString) == II &&
- NS.getNSStringSelector(NSAPI::NSStr_stringWithString) == Sel) ||
+ (NS.getNSStringSelector(NSAPI::NSStr_stringWithString) == Sel ||
+ NS.getNSStringSelector(NSAPI::NSStr_initWithString) == Sel)) ||
(isa<ObjCArrayLiteral>(Arg) &&
NS.getNSClassId(NSAPI::ClassId_NSArray) == II &&
- NS.getNSArraySelector(NSAPI::NSArr_arrayWithArray) == Sel) ||
+ (NS.getNSArraySelector(NSAPI::NSArr_arrayWithArray) == Sel ||
+ NS.getNSArraySelector(NSAPI::NSArr_initWithArray) == Sel)) ||
(isa<ObjCDictionaryLiteral>(Arg) &&
NS.getNSClassId(NSAPI::ClassId_NSDictionary) == II &&
- NS.getNSDictionarySelector(
- NSAPI::NSDict_dictionaryWithDictionary) == Sel)) {
+ (NS.getNSDictionarySelector(
+ NSAPI::NSDict_dictionaryWithDictionary) == Sel ||
+ NS.getNSDictionarySelector(NSAPI::NSDict_initWithDictionary) == Sel))) {
commit.replaceWithInner(Msg->getSourceRange(),
Msg->getArg(0)->getSourceRange());
@@ -246,7 +262,7 @@ static bool rewriteToStringBoxedExpression(const ObjCMessageExpr *Msg,
bool edit::rewriteToObjCLiteralSyntax(const ObjCMessageExpr *Msg,
const NSAPI &NS, Commit &commit) {
IdentifierInfo *II = 0;
- if (!checkForLiteralCreation(Msg, II))
+ if (!checkForLiteralCreation(Msg, II, NS.getASTContext().getLangOpts()))
return false;
if (II == NS.getNSClassId(NSAPI::ClassId_NSArray))
@@ -290,7 +306,8 @@ static bool rewriteToArrayLiteral(const ObjCMessageExpr *Msg,
return true;
}
- if (Sel == NS.getNSArraySelector(NSAPI::NSArr_arrayWithObjects)) {
+ if (Sel == NS.getNSArraySelector(NSAPI::NSArr_arrayWithObjects) ||
+ Sel == NS.getNSArraySelector(NSAPI::NSArr_initWithObjects)) {
if (Msg->getNumArgs() == 0)
return false;
const Expr *SentinelExpr = Msg->getArg(Msg->getNumArgs() - 1);
@@ -352,7 +369,8 @@ static bool rewriteToDictionaryLiteral(const ObjCMessageExpr *Msg,
}
if (Sel == NS.getNSDictionarySelector(
- NSAPI::NSDict_dictionaryWithObjectsAndKeys)) {
+ NSAPI::NSDict_dictionaryWithObjectsAndKeys) ||
+ Sel == NS.getNSDictionarySelector(NSAPI::NSDict_initWithObjectsAndKeys)) {
if (Msg->getNumArgs() % 2 != 1)
return false;
unsigned SentinelIdx = Msg->getNumArgs() - 1;
OpenPOWER on IntegriCloud