]> granicus.if.org Git - clang/commitdiff
More "prep" work for handling UTF16 CFString.
authorSteve Naroff <snaroff@apple.com>
Wed, 1 Apr 2009 13:55:36 +0000 (13:55 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 1 Apr 2009 13:55:36 +0000 (13:55 +0000)
Patch by Jean-Daniel Dupas. Thanks!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68203 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/CodeGen/CGExprConstant.cpp
lib/CodeGen/CGObjCMac.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h

index 832f83ca73c34e83433ad5aa17f50e2c74938783..92b39632b876b8f2497a35abbcabddbb0a777ea2 100644 (file)
@@ -533,9 +533,9 @@ public:
   const char *getStrData() const { return StrData; }
   unsigned getByteLength() const { return ByteLength; }
   bool isWide() const { return IsWide; }
-  bool containsNonAscii() const {
+  bool containsNonAsciiOrNull() const {
     for (unsigned i = 0; i < getByteLength(); ++i)
-      if (!isascii(getStrData()[i]))
+      if (!isascii(getStrData()[i]) || !getStrData()[i])
         return true;
     return false;
   }
index 89b331950c1282d479ae803774e03a60c4620ae5..51ad5b67b89c72b055bc8c303c9288226cac76cd 100644 (file)
@@ -442,9 +442,8 @@ public:
         break;
       const Expr *Arg = CE->getArg(0)->IgnoreParenCasts();
       const StringLiteral *Literal = cast<StringLiteral>(Arg);
-      std::string S(Literal->getStrData(), Literal->getByteLength());
       // FIXME: need to deal with UCN conversion issues.
-      return CGM.GetAddrOfConstantCFString(S);
+      return CGM.GetAddrOfConstantCFString(Literal);
     }
     case Expr::BlockExprClass: {
       std::string FunctionName;
index 351f8e25270540992df8d4dd1c008e2a5888675d..6b3ced08bf42a5bd0a8402f2bddf97956c02cd9c 100644 (file)
@@ -900,12 +900,7 @@ llvm::Value *CGObjCMac::GetSelector(CGBuilderTy &Builder, Selector Sel) {
 
 llvm::Constant *CGObjCCommonMac::GenerateConstantString(
   const ObjCStringLiteral *SL) {
-  std::string Str(SL->getString()->getStrData(), 
-                  SL->getString()->getByteLength());
-  if (SL->getString()->containsNonAscii()) {
-    // FIXME: Convert from UTF-8 to UTF-16.
-  }
-  return CGM.GetAddrOfConstantCFString(Str);
+  return CGM.GetAddrOfConstantCFString(SL->getString());
 }
 
 /// Generates a message send where the super is the receiver.  This is
index 101b2e58b7f581f1a5a99a4c9ddf0aedbc855b15..d428c836afb57e061e7b1f27f93664e5d49b9b77 100644 (file)
@@ -1002,7 +1002,11 @@ static void appendFieldAndPadding(CodeGenModule &CGM,
 // We still need to work out the details of handling UTF-16. 
 // See: <rdr://2996215>
 llvm::Constant *CodeGenModule::
-GetAddrOfConstantCFString(const std::string &str) {
+GetAddrOfConstantCFString(const StringLiteral *Literal) {
+  //  if (Literal->containsNonAsciiOrNull()) {
+  //    // FIXME: Convert from UTF-8 to UTF-16.
+  //  }
+  std::string str(Literal->getStrData(), Literal->getByteLength());
   llvm::StringMapEntry<llvm::Constant *> &Entry = 
     CFConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
   
index 8c7571fd642ec44d8d907933c9a9c746fe3935f0..c0dbbf8267fe48c6b66456e5d98ca56e486bda4a 100644 (file)
@@ -187,7 +187,7 @@ public:
 
   /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
   /// for the given string.
-  llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
+  llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
 
   /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
   /// for the given string literal.