Objective-C modernization. Convert -initWithUTF8String messaging

with auto-boxing syntax for literals. rdar://18080352

llvm-svn: 216405
This commit is contained in:
Fariborz Jahanian 2014-08-25 20:22:25 +00:00
parent a5bf76bdf3
commit be7bf7285b
5 changed files with 20 additions and 4 deletions

View File

@ -42,7 +42,8 @@ public:
NSStr_stringWithUTF8String,
NSStr_stringWithCStringEncoding,
NSStr_stringWithCString,
NSStr_initWithString
NSStr_initWithString,
NSStr_initWithUTF8String
};
static const unsigned NumNSStringMethods = 5;

View File

@ -46,6 +46,10 @@ Selector NSAPI::getNSStringSelector(NSStringMethodKind MK) const {
Sel = Ctx.Selectors.getUnarySelector(
&Ctx.Idents.get("stringWithUTF8String"));
break;
case NSStr_initWithUTF8String:
Sel = Ctx.Selectors.getUnarySelector(
&Ctx.Idents.get("initWithUTF8String"));
break;
case NSStr_stringWithCStringEncoding: {
IdentifierInfo *KeyIdents[] = {
&Ctx.Idents.get("stringWithCString"),

View File

@ -1149,7 +1149,8 @@ static bool rewriteToStringBoxedExpression(const ObjCMessageExpr *Msg,
Selector Sel = Msg->getSelector();
if (Sel == NS.getNSStringSelector(NSAPI::NSStr_stringWithUTF8String) ||
Sel == NS.getNSStringSelector(NSAPI::NSStr_stringWithCString)) {
Sel == NS.getNSStringSelector(NSAPI::NSStr_stringWithCString) ||
Sel == NS.getNSStringSelector(NSAPI::NSStr_initWithUTF8String)) {
if (Msg->getNumArgs() != 1)
return false;
return doRewriteToUTF8StringBoxedExpressionHelper(Msg, NS, commit);

View File

@ -1,5 +1,5 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify
// RUN: %clang_cc1 -fobjc-arc -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c++ %s.result
@ -68,6 +68,7 @@ typedef NSUInteger NSStringEncoding;
+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
+ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc;
+ (id)stringWithCString:(const char *)bytes;
- (instancetype)initWithUTF8String:(const char *)nullTerminatedCString;
@end
enum MyEnm {
@ -99,4 +100,8 @@ void boxString() {
static const char strarr[] = "coolbox";
s = [NSString stringWithUTF8String:strarr];
// rdar://18080352
const char *utf8Bytes = "blah";
NSString *string1 = [NSString stringWithUTF8String:utf8Bytes];
NSString *string2 = [[NSString alloc] initWithUTF8String:utf8Bytes];
}

View File

@ -1,5 +1,5 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify
// RUN: %clang_cc1 -fobjc-arc -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c++ %s.result
@ -68,6 +68,7 @@ typedef NSUInteger NSStringEncoding;
+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
+ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc;
+ (id)stringWithCString:(const char *)bytes;
- (instancetype)initWithUTF8String:(const char *)nullTerminatedCString;
@end
enum MyEnm {
@ -99,4 +100,8 @@ void boxString() {
static const char strarr[] = "coolbox";
s = @(strarr);
// rdar://18080352
const char *utf8Bytes = "blah";
NSString *string1 = @(utf8Bytes);
NSString *string2 = @(utf8Bytes);
}