From f4b136fb40aeedeaaa6ce7cdff22f375eb76c47b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 18 Feb 2009 06:13:04 +0000 Subject: [PATCH] add some comments describing what is happening here. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64896 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 5dba6846a3..6e40b3c4a3 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -20,9 +20,14 @@ using namespace clang; Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, ExprTy **Strings, unsigned NumStrings) { - SourceLocation AtLoc = AtLocs[0]; - StringLiteral* S = static_cast(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(Strings[0]); + + // If we have a multi-part string, merge it all together. + if (NumStrings != 1) { // Concatenate objc strings. StringLiteral* ES = static_cast(Strings[NumStrings-1]); SourceLocation EndLoc = ES->getSourceRange().getEnd(); @@ -33,19 +38,22 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, // 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(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 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, } } - return new (Context) ObjCStringLiteral(S, Ty, AtLoc); + return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]); } Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc, -- 2.40.0