[cfe-commits] r44964 - in /cfe/trunk: Parse/ParseObjc.cpp Sema/SemaExpr.cpp test/Sema/objc-string-concat-1.m
Fariborz Jahanian
fjahanian at apple.com
Wed Dec 12 15:55:49 PST 2007
Author: fjahanian
Date: Wed Dec 12 17:55:49 2007
New Revision: 44964
URL: http://llvm.org/viewvc/llvm-project?rev=44964&view=rev
Log:
Concatenation of objc strings.
Added:
cfe/trunk/test/Sema/objc-string-concat-1.m
Modified:
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/SemaExpr.cpp
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=44964&r1=44963&r2=44964&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Wed Dec 12 17:55:49 2007
@@ -1397,7 +1397,7 @@
AtStrings.push_back(Res.Val);
}
-
+
return Actions.ParseObjCStringLiteral(&AtLocs[0], &AtStrings[0],
AtStrings.size());
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44964&r1=44963&r2=44964&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Dec 12 17:55:49 2007
@@ -2049,11 +2049,30 @@
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<StringLiteral *>(Strings[0]);
+ if (NumStrings > 1) {
+ // Concatenate objc strings.
+ StringLiteral* ES = static_cast<StringLiteral *>(Strings[NumStrings-1]);
+ SourceLocation EndLoc = ES->getSourceRange().getEnd();
+ unsigned Length = 0;
+ for (unsigned i = 0; i < NumStrings; i++)
+ Length += static_cast<StringLiteral *>(Strings[i])->getByteLength();
+ 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;
+ 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;
Added: cfe/trunk/test/Sema/objc-string-concat-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-string-concat-1.m?rev=44964&view=auto
==============================================================================
--- cfe/trunk/test/Sema/objc-string-concat-1.m (added)
+++ cfe/trunk/test/Sema/objc-string-concat-1.m Wed Dec 12 17:55:49 2007
@@ -0,0 +1,14 @@
+// RUN: clang -rewrite-test %s
+
+ at class NSString;
+
+ at interface NSConstantString;
+ at end
+
+
+
+NSConstantString *t0 = @"123";
+NSConstantString *t = @"123" @"4567"; // concat
+NSConstantString *t1 = @"123" @"4567" /* COMMENT */ @"89"; // concat
+NSConstantString *t2 = @"123" @/* COMMENT */ "4567"; // concat
+
More information about the cfe-commits
mailing list