]> granicus.if.org Git - clang/commitdiff
Align a multiline string literal with the first part.
authorDaniel Jasper <djasper@google.com>
Mon, 13 May 2013 20:50:15 +0000 (20:50 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 May 2013 20:50:15 +0000 (20:50 +0000)
Before:
  #define A(X)          \
    "aaaaa" #X "bbbbbb" \
               "ccccc"

After:
  #define A(X)          \
    "aaaaa" #X "bbbbbb" \
    "ccccc"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181732 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 384c4628bf4d55d0661453497dcfeba471a2a054..50567a6f84b7e9122ecb1f93555ed667f21e40e8 100644 (file)
@@ -738,10 +738,10 @@ private:
       State.Stack.back().VariablePos = VariablePos;
     }
 
-    if (Current.is(tok::string_literal)) {
+    if (Current.is(tok::string_literal) && State.StartOfStringLiteral == 0) {
       State.StartOfStringLiteral = State.Column;
-    } else if (Current.isNot(tok::comment)) {
-      State.StartOfStringLiteral = 0;
+    } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash,
+                                tok::string_literal)) {
     }
 
     State.Column += Current.FormatTok.TokenLength;
index 9624ac92240a445355268d975068e8409cb39c69..697cc538205c79e760a7b86095177e9ad1756322 100644 (file)
@@ -2231,6 +2231,14 @@ TEST_F(FormatTest, AlignsStringLiterals) {
       "#define LL_FORMAT \"ll\"\n"
       "printf(\"aaaaa: %d, bbbbbb: %\" LL_FORMAT \"d, cccccccc: %\" LL_FORMAT\n"
       "       \"d, ddddddddd: %\" LL_FORMAT \"d\");");
+
+  verifyFormat("#define A(X)          \\\n"
+               "  \"aaaaa\" #X \"bbbbbb\" \\\n"
+               "  \"ccccc\"",
+               getLLVMStyleWithColumns(23));
+  verifyFormat("#define A \"def\"\n"
+               "f(\"abc\" A \"ghi\"\n"
+               "  \"jkl\");");
 }
 
 TEST_F(FormatTest, AlignsPipes) {