diff options
author | Daniel Jasper <djasper@google.com> | 2013-05-13 20:50:15 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-05-13 20:50:15 +0000 |
commit | 27c7f54cf7d18276be2979d5c795533cc5592675 (patch) | |
tree | 8dd5b4373ba702d5804020a0a6a7e8070b1a6bd9 | |
parent | 1071b9f2d38f8177e54f20412a36450462c19186 (diff) | |
download | clang-27c7f54cf7d18276be2979d5c795533cc5592675.tar.gz clang-27c7f54cf7d18276be2979d5c795533cc5592675.tar.bz2 clang-27c7f54cf7d18276be2979d5c795533cc5592675.tar.xz |
Align a multiline string literal with the first part.
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
-rw-r--r-- | lib/Format/Format.cpp | 6 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 384c4628bf..50567a6f84 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9624ac9224..697cc53820 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { |