diff options
| author | Krasimir Georgiev <krasimir@google.com> | 2018-02-08 10:47:12 +0000 | 
|---|---|---|
| committer | Krasimir Georgiev <krasimir@google.com> | 2018-02-08 10:47:12 +0000 | 
| commit | 374e6de8e0378c96fc7d1ea1d58433c81cf34cbe (patch) | |
| tree | c89c4da120faee4c732bfd7f86fef600be9e4364 /clang/lib/Format | |
| parent | 014e4654d496a7c6dfeb28903079bd324c16fc2b (diff) | |
| download | bcm5719-llvm-374e6de8e0378c96fc7d1ea1d58433c81cf34cbe.tar.gz bcm5719-llvm-374e6de8e0378c96fc7d1ea1d58433c81cf34cbe.zip | |
[clang-format] Do not break before long string literals in protos
Summary:
This patch is a follow-up to r323319 (which disables string literal breaking for
text protos) and it disables breaking before long string literals.
For example this:
```
keyyyyy: "long string literal"
```
used to get broken into:
```
keyyyyy:
    "long string literal"
```
While at it, I also enabled it for LK_Proto and fixed a bug in the mustBreak code.
Reviewers: djasper, sammccall
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D42957
llvm-svn: 324591
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Format/Format.cpp | 11 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 | 
3 files changed, 14 insertions, 7 deletions
| diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 96281db9540..6ee299566e4 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1992,7 +1992,7 @@ bool ContinuationIndenter::nextIsMultilineString(const LineState &State) {    if (Current.getNextNonComment() &&        Current.getNextNonComment()->isStringLiteral())      return true; // Implicit concatenation. -  if (Style.ColumnLimit != 0 && +  if (Style.ColumnLimit != 0 && Style.BreakStringLiterals &&        State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >            Style.ColumnLimit)      return true; // String will be split. diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5fb775a0d33..ff437f119e9 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -686,11 +686,6 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {      FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto);      GoogleStyle.Language = FormatStyle::LK_TextProto; -    // Text protos are currently mostly formatted inside C++ raw string literals -    // and often the current breaking behavior of string literals is not -    // beneficial there. Investigate turning this on once proper string reflow -    // has been implemented. -    GoogleStyle.BreakStringLiterals = false;      return GoogleStyle;    } @@ -762,6 +757,12 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {      GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;      GoogleStyle.SpacesInContainerLiterals = false;      GoogleStyle.Cpp11BracedListStyle = false; +    // This affects protocol buffer options specifications and text protos. +    // Text protos are currently mostly formatted inside C++ raw string literals +    // and often the current breaking behavior of string literals is not +    // beneficial there. Investigate turning this on once proper string reflow +    // has been implemented. +    GoogleStyle.BreakStringLiterals = false;    } else if (Language == FormatStyle::LK_ObjC) {      GoogleStyle.ColumnLimit = 100;    } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 993c937a771..d8c3366941c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2830,11 +2830,17 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,    if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&        Left.isNot(TT_SelectorName))      return true; +    if (Right.is(tok::colon) &&        !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))      return false; -  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) +  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) { +    if ((Style.Language == FormatStyle::LK_Proto || +         Style.Language == FormatStyle::LK_TextProto) && +        Right.isStringLiteral()) +      return false;      return true; +  }    if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&                                      Right.Next->is(TT_ObjCMethodExpr)))      return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls. | 

