diff options
| author | Daniel Jasper <djasper@google.com> | 2014-01-05 12:38:10 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-01-05 12:38:10 +0000 |
| commit | 9697281eecdc8204c53f4be6b778f9e5988a41c8 (patch) | |
| tree | 06b6b0d57047dc0628155422c34a4e09c4b0345c /clang/lib/Format | |
| parent | 52e4a0e109dd0428b40ae3b380616cd211b3a705 (diff) | |
| download | bcm5719-llvm-9697281eecdc8204c53f4be6b778f9e5988a41c8.tar.gz bcm5719-llvm-9697281eecdc8204c53f4be6b778f9e5988a41c8.zip | |
clang-format: Allow formatting short enums on a single line.
Before:
enum ShortEnum {
A,
B,
C
};
After:
enum ShortEnum { A, B, C };
This seems to be the predominant choice in LLVM/Clang as well as in
Google style.
llvm-svn: 198558
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 16 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 |
2 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 872545660ca..2812a405b87 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -182,10 +182,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { State.Stack.back().ObjCSelectorNameFound && State.Stack.back().BreakBeforeParameter) return true; - if (Current.Type == TT_CtorInitializerColon && - (!Style.AllowShortFunctionsOnASingleLine || - Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0)) - return true; if (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 && !Current.isTrailingComment()) return true; @@ -199,6 +195,18 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { (State.Stack.back().BreakBeforeParameter && State.Stack.back().ContainsUnwrappedBuilder))) return true; + + // The following could be precomputed as they do not depend on the state. + // However, as they should take effect only if the UnwrappedLine does not fit + // into the ColumnLimit, they are checked here in the ContinuationIndenter. + if (Previous.BlockKind == BK_Block && Previous.is(tok::l_brace) && + !Current.isOneOf(tok::r_brace, tok::comment)) + return true; + if (Current.Type == TT_CtorInitializerColon && + (!Style.AllowShortFunctionsOnASingleLine || + Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0)) + return true; + return false; } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c1760f32fc3..6b6f4edee23 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1438,9 +1438,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, Style.BreakConstructorInitializersBeforeComma && !Style.ConstructorInitializerAllOnOneLineOrOnePerLine) { return true; - } else if (Right.Previous->BlockKind == BK_Block && - Right.Previous->isNot(tok::r_brace) && Right.isNot(tok::r_brace)) { - return true; } else if (Right.is(tok::l_brace) && (Right.BlockKind == BK_Block)) { return Style.BreakBeforeBraces == FormatStyle::BS_Allman || Style.BreakBeforeBraces == FormatStyle::BS_GNU; |

