[cfe-commits] r64896 - /cfe/trunk/lib/Sema/SemaExprObjC.cpp
Chris Lattner
sabre at nondot.org
Tue Feb 17 22:13:05 PST 2009
Author: lattner
Date: Wed Feb 18 00:13:04 2009
New Revision: 64896
URL: http://llvm.org/viewvc/llvm-project?rev=64896&view=rev
Log:
add some comments describing what is happening here.
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=64896&r1=64895&r2=64896&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Feb 18 00:13:04 2009
@@ -20,9 +20,14 @@
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();
@@ -33,19 +38,22 @@
// 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.
@@ -71,7 +79,7 @@
}
}
- return new (Context) ObjCStringLiteral(S, Ty, AtLoc);
+ return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]);
}
Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
More information about the cfe-commits
mailing list