const char *getStrData() const { return StrData; }
unsigned getByteLength() const { return ByteLength; }
bool isWide() const { return IsWide; }
-
+ bool containsNonAscii() const {
+ for (unsigned i = 0; i < getByteLength(); ++i)
+ if (!isascii(getStrData()[i]))
+ return true;
+ return false;
+ }
/// getNumConcatenated - Get the number of string literal tokens that were
/// concatenated in translation phase #6 to form this string literal.
unsigned getNumConcatenated() const { return NumConcatenated; }
return CGM.GetAddrOfConstantStringFromObjCEncode(cast<ObjCEncodeExpr>(E));
case Expr::ObjCStringLiteralClass: {
ObjCStringLiteral* SL = cast<ObjCStringLiteral>(E);
- std::string S(SL->getString()->getStrData(),
- SL->getString()->getByteLength());
- llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(S);
+ llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(SL);
return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType()));
}
case Expr::PredefinedExprClass: {
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);
}
case Expr::BlockExprClass: {
/// Emits an instance of NSConstantString representing the object.
llvm::Value *CodeGenFunction::EmitObjCStringLiteral(const ObjCStringLiteral *E)
{
- std::string String(E->getString()->getStrData(),
- E->getString()->getByteLength());
- llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(String);
+ llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(E);
// FIXME: This bitcast should just be made an invariant on the Runtime.
return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType()));
}
std::vector<llvm::Constant*> &V, const std::string &Name="");
public:
CGObjCGNU(CodeGen::CodeGenModule &cgm);
- virtual llvm::Constant *GenerateConstantString(const std::string &String);
+ virtual llvm::Constant *GenerateConstantString(const ObjCStringLiteral *);
virtual CodeGen::RValue
GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
QualType ResultType,
//TODO: In case there are any crazy people still using the GNU runtime without
//an OpenStep implementation, this should let them select their own class for
//constant strings.
-llvm::Constant *CGObjCGNU::GenerateConstantString(const std::string &Str) {
+llvm::Constant *CGObjCGNU::GenerateConstantString(const ObjCStringLiteral *SL) {
+ std::string Str(SL->getString()->getStrData(),
+ SL->getString()->getByteLength());
std::vector<llvm::Constant*> Ivars;
Ivars.push_back(NULLPtr);
Ivars.push_back(MakeConstantString(Str));
CGObjCCommonMac(CodeGen::CodeGenModule &cgm) : CGM(cgm)
{ }
- virtual llvm::Constant *GenerateConstantString(const std::string &String);
+ virtual llvm::Constant *GenerateConstantString(const ObjCStringLiteral *SL);
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
const ObjCContainerDecl *CD=0);
*/
llvm::Constant *CGObjCCommonMac::GenerateConstantString(
- const std::string &String) {
- return CGM.GetAddrOfConstantCFString(String);
+ 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);
}
/// Generates a message send where the super is the receiver. This is
class ObjCProtocolDecl;
class Selector;
class ObjCIvarDecl;
+ class ObjCStringLiteral;
namespace CodeGen {
class CodeGenModule;
Selector Sel) = 0;
/// Generate a constant string object.
- virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
+ virtual llvm::Constant *GenerateConstantString(const ObjCStringLiteral *) = 0;
/// Generate a category. A category contains a list of methods (and
/// accompanying metadata) and a list of protocols.