From: Fariborz Jahanian Date: Wed, 12 Dec 2007 23:55:49 +0000 (+0000) Subject: Concatenation of objc strings. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79a99f2c063ce7cd9b18852a39bf4c937fc1faf8;p=clang Concatenation of objc strings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44964 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index e3230c4892..48b9feb47e 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1397,7 +1397,7 @@ Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { AtStrings.push_back(Res.Val); } - + return Actions.ParseObjCStringLiteral(&AtLocs[0], &AtStrings[0], AtStrings.size()); } diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 98ede439f6..c6260344f1 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -2049,11 +2049,30 @@ Sema::ExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc, Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, ExprTy **Strings, unsigned NumStrings) { - - // FIXME: This is passed in an ARRAY of strings which need to be concatenated. - // Handle this case here. For now we just ignore all but the first one. SourceLocation AtLoc = AtLocs[0]; StringLiteral* S = static_cast(Strings[0]); + if (NumStrings > 1) { + // Concatenate objc strings. + StringLiteral* ES = static_cast(Strings[NumStrings-1]); + SourceLocation EndLoc = ES->getSourceRange().getEnd(); + unsigned Length = 0; + for (unsigned i = 0; i < NumStrings; i++) + Length += static_cast(Strings[i])->getByteLength(); + 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; + memcpy(p, S->getStrData(), S->getByteLength()); + p += S->getByteLength(); + delete S; + } + S = new StringLiteral(strBuf, Length, + isWide, Context.getPointerType(Context.CharTy), + AtLoc, EndLoc); + } if (CheckBuiltinCFStringArgument(S)) return true; diff --git a/test/Sema/objc-string-concat-1.m b/test/Sema/objc-string-concat-1.m new file mode 100644 index 0000000000..63b8d1d1c3 --- /dev/null +++ b/test/Sema/objc-string-concat-1.m @@ -0,0 +1,14 @@ +// RUN: clang -rewrite-test %s + +@class NSString; + +@interface NSConstantString; +@end + + + +NSConstantString *t0 = @"123"; +NSConstantString *t = @"123" @"4567"; // concat +NSConstantString *t1 = @"123" @"4567" /* COMMENT */ @"89"; // concat +NSConstantString *t2 = @"123" @/* COMMENT */ "4567"; // concat +