diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-12 11:37:05 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-12 11:37:05 +0000 |
commit | 5aad4e56141d069b4298c330ff359c6d412b8585 (patch) | |
tree | 23ffa357610f2a694432aa56d5d5f5e147ff221a /clang/lib/Format/Format.cpp | |
parent | aea3bde06baf04ccb063037e083646991c96716c (diff) | |
download | bcm5719-llvm-5aad4e56141d069b4298c330ff359c6d412b8585.tar.gz bcm5719-llvm-5aad4e56141d069b4298c330ff359c6d412b8585.zip |
clang-format: Fix string literal breaking.
Before this patch, it did not cooperate with
Style::AlwaysBreakBeforeMultilineStrings. Thus, it would turn
aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa");
into:
aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa");
and only a second format step would lead to the desired (with that
option):
aaaaaaaaaaaa(aaaaaaaaaaaaa,
"aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa");
This could even lead to clang-format breaking the string at a different
character and thus leading to a completely different end result.
llvm-svn: 186154
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index b1f9f4c85b7..224f1d759fb 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -297,7 +297,7 @@ public: State.IgnoreStackForComparison = false; // The first token has already been indented and thus consumed. - moveStateToNextToken(State, /*DryRun=*/false); + moveStateToNextToken(State, /*DryRun=*/false, /*Newline=*/false); // If everything fits on a single line, just put it there. unsigned ColumnLimit = Style.ColumnLimit; @@ -729,12 +729,12 @@ private: } } - return moveStateToNextToken(State, DryRun) + ExtraPenalty; + return moveStateToNextToken(State, DryRun, Newline) + ExtraPenalty; } /// \brief Mark the next token as consumed in \p State and modify its stacks /// accordingly. - unsigned moveStateToNextToken(LineState &State, bool DryRun) { + unsigned moveStateToNextToken(LineState &State, bool DryRun, bool Newline) { const FormatToken &Current = *State.NextToken; assert(State.Stack.size()); @@ -875,6 +875,10 @@ private: State.NextToken = State.NextToken->Next; + if (!Newline && Style.AlwaysBreakBeforeMultilineStrings && + Current.is(tok::string_literal)) + return 0; + return breakProtrudingToken(Current, State, DryRun); } |