diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-17 15:38:19 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-17 15:38:19 +0000 |
commit | c834c70986b01f5086d72bc5c5e564d7d0ebbc74 (patch) | |
tree | be37cc901d894de56cdbaade23f87fee5e26c352 /clang/lib/Format | |
parent | 21b3da0f939c699e671dd8df460fce7079361123 (diff) | |
download | bcm5719-llvm-c834c70986b01f5086d72bc5c5e564d7d0ebbc74.tar.gz bcm5719-llvm-c834c70986b01f5086d72bc5c5e564d7d0ebbc74.zip |
Improve line breaking before multi-line strings.
The AlwaysBreakBeforeMultilineStrings rule does not really make sense
if it does not a column gain.
Before (in Google style):
f(
"aaaa"
"bbbb");
After:
f("aaaa"
"bbbb");
llvm-svn: 186515
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 12 |
2 files changed, 11 insertions, 9 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 125283a0c6d..a4495ba62ee 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1177,6 +1177,14 @@ private: !Current.isTrailingComment() && !Current.isOneOf(tok::r_paren, tok::r_brace)) return true; + if (Style.AlwaysBreakBeforeMultilineStrings && + State.Column > State.Stack.back().Indent && + Current.is(tok::string_literal) && Previous.isNot(tok::lessless) && + Previous.Type != TT_InlineASMColon && + ((Current.getNextNonComment() && + Current.getNextNonComment()->is(tok::string_literal)) || + (Current.TokenText.find("\\\n") != StringRef::npos))) + return true; // If we need to break somewhere inside the LHS of a binary expression, we // should also break after the operator. Otherwise, the formatting would diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 67a0fa892d5..021fd2488bb 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -963,18 +963,12 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { } else if (Current->Previous->ClosesTemplateDeclaration && Style.AlwaysBreakTemplateDeclarations) { Current->MustBreakBefore = true; - } else if (Style.AlwaysBreakBeforeMultilineStrings && - Current->is(tok::string_literal) && - Current->Previous->isNot(tok::lessless) && - Current->Previous->Type != TT_InlineASMColon && - ((Current->getNextNonComment() && - Current->getNextNonComment()->is(tok::string_literal)) || - (Current->TokenText.find("\\\n") != StringRef::npos))) { - Current->MustBreakBefore = true; } Current->CanBreakBefore = Current->MustBreakBefore || canBreakBefore(Line, *Current); - if (Current->MustBreakBefore) + if (Current->MustBreakBefore || + (Current->is(tok::string_literal) && + Current->TokenText.find("\\\n") != StringRef::npos)) Current->TotalLength = Current->Previous->TotalLength + Style.ColumnLimit; else Current->TotalLength = Current->Previous->TotalLength + |