Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
ExprTy **Strings,
unsigned NumStrings) {
- SourceLocation AtLoc = AtLocs[0];
- StringLiteral* S = static_cast<StringLiteral *>(Strings[0]);
- if (NumStrings > 1) {
+ // Most ObjC strings are formed out of a single piece. However, we *can*
+ // have strings formed out of multiple @ strings with multiple pptokens in
+ // each one, e.g. @"foo" "bar" @"baz" "qux" which need to be turned into one
+ // StringLiteral for ObjCStringLiteral to hold onto.
+ StringLiteral *S = static_cast<StringLiteral *>(Strings[0]);
+
+ // If we have a multi-part string, merge it all together.
+ if (NumStrings != 1) {
// Concatenate objc strings.
StringLiteral* ES = static_cast<StringLiteral *>(Strings[NumStrings-1]);
SourceLocation EndLoc = ES->getSourceRange().getEnd();
// FIXME: This should not be allocated by SEMA!
char *strBuf = new char[Length];
char *p = strBuf;
- bool isWide = false;
for (unsigned i = 0; i != NumStrings; ++i) {
S = static_cast<StringLiteral *>(Strings[i]);
- if (S->isWide())
- isWide = true;
+ if (S->isWide()) {
+ Diag(S->getLocStart(), diag::err_cfstring_literal_not_string_constant)
+ << S->getSourceRange();
+ return true;
+ }
+
memcpy(p, S->getStrData(), S->getByteLength());
p += S->getByteLength();
S->Destroy(Context);
}
// FIXME: PASS LOCATIONS PROPERLY.
- S = new (Context) StringLiteral(Context, strBuf, Length, isWide,
+ S = new (Context) StringLiteral(Context, strBuf, Length, false,
Context.getPointerType(Context.CharTy),
- AtLoc);
+ AtLocs[0]);
}
// Verify that this composite string is acceptable for ObjC strings.
}
}
- return new (Context) ObjCStringLiteral(S, Ty, AtLoc);
+ return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]);
}
Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,