bool Pascal;
const char *GetString() { return &ResultBuf[0]; }
- unsigned GetStringLength() { return ResultPtr-&ResultBuf[0]; }
-
+ unsigned GetStringLength() const { return ResultPtr-&ResultBuf[0]; }
+
+ unsigned GetNumStringChars() const {
+ if (AnyWide)
+ return GetStringLength() / wchar_tByteWidth;
+ return GetStringLength();
+ }
/// getOffsetOfStringByte - This function returns the offset of the
/// specified byte of the string data represented by Token. This handles
/// advancing over escape sequences in the string.
/// GetStringForStringLiteral - Return the appropriate bytes for a
/// string literal, properly padded to match the literal type.
std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) {
- if (E->isWide()) {
- ErrorUnsupported(E, "wide string");
- return "FIXME";
- }
-
const char *StrData = E->getStrData();
unsigned Len = E->getByteLength();
getContext().getAsConstantArrayType(E->getType());
assert(CAT && "String isn't pointer or array!");
- // Resize the string to the right size
- // FIXME: What about wchar_t strings?
+ // Resize the string to the right size.
std::string Str(StrData, StrData+Len);
uint64_t RealLen = CAT->getSize().getZExtValue();
+
+ if (E->isWide())
+ RealLen *= getContext().Target.getWCharWidth()/8;
+
Str.resize(RealLen, '\0');
return Str;
// Remember if we see any wide strings.
AnyWide |= StringToks[i].is(tok::wide_string_literal);
}
-
-
+
// Include space for the null terminator.
++SizeBound;
}
}
- // Add zero terminator.
- *ResultPtr = 0;
- if (AnyWide) {
- for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
- *ResultPtr++ = 0;
- }
-
if (Pascal) {
ResultBuf[0] = ResultPtr-&ResultBuf[0]-1;
// the nul terminator character as well as the string length for pascal
// strings.
StrTy = Context.getConstantArrayType(StrTy,
- llvm::APInt(32, Literal.GetStringLength()+1),
+ llvm::APInt(32, Literal.GetNumStringChars()+1),
ArrayType::Normal, 0);
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
int main() {
char a[10] = "abc";
+
+ void *foo = L"AB";
}
+++ /dev/null
-// RUN: clang -verify -emit-llvm -o - %s
-
-void *x = L"foo"; // expected-error {{cannot compile this wide string yet}}