r216405 - Objective-C modernization. Convert -initWithUTF8String messaging
Fariborz Jahanian
fjahanian at apple.com
Mon Aug 25 13:22:25 PDT 2014
Author: fjahanian
Date: Mon Aug 25 15:22:25 2014
New Revision: 216405
URL: http://llvm.org/viewvc/llvm-project?rev=216405&view=rev
Log:
Objective-C modernization. Convert -initWithUTF8String messaging
with auto-boxing syntax for literals. rdar://18080352
Modified:
cfe/trunk/include/clang/AST/NSAPI.h
cfe/trunk/lib/AST/NSAPI.cpp
cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
cfe/trunk/test/ARCMT/objcmt-boxing.m
cfe/trunk/test/ARCMT/objcmt-boxing.m.result
Modified: cfe/trunk/include/clang/AST/NSAPI.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/NSAPI.h?rev=216405&r1=216404&r2=216405&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/NSAPI.h (original)
+++ cfe/trunk/include/clang/AST/NSAPI.h Mon Aug 25 15:22:25 2014
@@ -42,7 +42,8 @@ public:
NSStr_stringWithUTF8String,
NSStr_stringWithCStringEncoding,
NSStr_stringWithCString,
- NSStr_initWithString
+ NSStr_initWithString,
+ NSStr_initWithUTF8String
};
static const unsigned NumNSStringMethods = 5;
Modified: cfe/trunk/lib/AST/NSAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/NSAPI.cpp?rev=216405&r1=216404&r2=216405&view=diff
==============================================================================
--- cfe/trunk/lib/AST/NSAPI.cpp (original)
+++ cfe/trunk/lib/AST/NSAPI.cpp Mon Aug 25 15:22:25 2014
@@ -46,6 +46,10 @@ Selector NSAPI::getNSStringSelector(NSSt
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"),
Modified: cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp?rev=216405&r1=216404&r2=216405&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp (original)
+++ cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp Mon Aug 25 15:22:25 2014
@@ -1149,7 +1149,8 @@ static bool rewriteToStringBoxedExpressi
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);
Modified: cfe/trunk/test/ARCMT/objcmt-boxing.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-boxing.m?rev=216405&r1=216404&r2=216405&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-boxing.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-boxing.m Mon Aug 25 15:22:25 2014
@@ -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];
}
Modified: cfe/trunk/test/ARCMT/objcmt-boxing.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-boxing.m.result?rev=216405&r1=216404&r2=216405&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-boxing.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-boxing.m.result Mon Aug 25 15:22:25 2014
@@ -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);
}
More information about the cfe-commits
mailing list