]> granicus.if.org Git - clang/commitdiff
Concatenation of objc strings.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 12 Dec 2007 23:55:49 +0000 (23:55 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 12 Dec 2007 23:55:49 +0000 (23:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44964 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseObjc.cpp
Sema/SemaExpr.cpp
test/Sema/objc-string-concat-1.m [new file with mode: 0644]

index e3230c48924286801a355e3c38afbd80639ddfe8..48b9feb47e5496d2fd13c089cad52750508db8da 100644 (file)
@@ -1397,7 +1397,7 @@ Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {
 
     AtStrings.push_back(Res.Val);
   }
-
+  
   return Actions.ParseObjCStringLiteral(&AtLocs[0], &AtStrings[0],
                                         AtStrings.size());
 }
index 98ede439f682b889269a4d4f2b53258c95e871c8..c6260344f1b083e5eb47e007b472c33418d8efe6 100644 (file)
@@ -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<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;
diff --git a/test/Sema/objc-string-concat-1.m b/test/Sema/objc-string-concat-1.m
new file mode 100644 (file)
index 0000000..63b8d1d
--- /dev/null
@@ -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
+