[cfe-commits] r68114 - in /cfe/trunk: include/clang/AST/Expr.h lib/CodeGen/CGExprConstant.cpp lib/CodeGen/CGObjC.cpp lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CGObjCRuntime.h
Steve Naroff
snaroff at apple.com
Tue Mar 31 09:53:37 PDT 2009
Author: snaroff
Date: Tue Mar 31 11:53:37 2009
New Revision: 68114
URL: http://llvm.org/viewvc/llvm-project?rev=68114&view=rev
Log:
Some "prep" work for handling ObjC @-string constants that contain UTF-8. No functionality change.
Changed GenerateConstantString() to take an ObjCStringLiteral (instead of a std::string). While this isn't strictly necessary, it seems cleaner and allows us to cache to "containsNonAscii" if necessary (to avoid checking in both Sema and CodeGen).
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=68114&r1=68113&r2=68114&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Mar 31 11:53:37 2009
@@ -533,7 +533,12 @@
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; }
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=68114&r1=68113&r2=68114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Mar 31 11:53:37 2009
@@ -417,9 +417,7 @@
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: {
@@ -445,6 +443,7 @@
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: {
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=68114&r1=68113&r2=68114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Mar 31 11:53:37 2009
@@ -26,9 +26,7 @@
/// 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()));
}
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=68114&r1=68113&r2=68114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue Mar 31 11:53:37 2009
@@ -94,7 +94,7 @@
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,
@@ -252,7 +252,9 @@
//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));
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=68114&r1=68113&r2=68114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Mar 31 11:53:37 2009
@@ -487,7 +487,7 @@
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);
@@ -899,8 +899,13 @@
*/
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
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=68114&r1=68113&r2=68114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Tue Mar 31 11:53:37 2009
@@ -48,6 +48,7 @@
class ObjCProtocolDecl;
class Selector;
class ObjCIvarDecl;
+ class ObjCStringLiteral;
namespace CodeGen {
class CodeGenModule;
@@ -72,7 +73,7 @@
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.
More information about the cfe-commits
mailing list