clang-format: Improve stream-formatting.

Before:
  CHECK(controller->WriteProto(FLAGS_row_key, FLAGS_proto)) << "\""
                                                            << FLAGS_proto
                                                            << "\"";

After:
  SemaRef.Diag(Loc, diag::note_for_range_begin_end)
      << BEF << IsTemplate << Description << E->getType();

llvm-svn: 188175
This commit is contained in:
Daniel Jasper 2013-08-12 12:58:05 +00:00
parent 19ae1175ae
commit 467ddb161c
2 changed files with 9 additions and 5 deletions

View File

@ -595,6 +595,12 @@ private:
unsigned ContinuationIndent = unsigned ContinuationIndent =
std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) + 4; std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) + 4;
if (Newline) { if (Newline) {
// Breaking before the first "<<" is generally not desirable if the LHS is
// short.
if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0 &&
State.Column <= Style.ColumnLimit / 2)
ExtraPenalty += Style.PenaltyBreakFirstLessLess;
State.Stack.back().ContainsLineBreak = true; State.Stack.back().ContainsLineBreak = true;
if (Current.is(tok::r_brace)) { if (Current.is(tok::r_brace)) {
if (Current.BlockKind == BK_BracedInit) if (Current.BlockKind == BK_BracedInit)
@ -705,10 +711,6 @@ private:
State.Stack.back().BreakBeforeParameter = true; State.Stack.back().BreakBeforeParameter = true;
} }
// Breaking before the first "<<" is generally not desirable.
if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0)
ExtraPenalty += Style.PenaltyBreakFirstLessLess;
} else { } else {
if (Current.is(tok::equal) && if (Current.is(tok::equal) &&
(RootToken->is(tok::kw_for) || State.ParenLevel == 0) && (RootToken->is(tok::kw_for) || State.ParenLevel == 0) &&

View File

@ -3188,10 +3188,12 @@ TEST_F(FormatTest, AlignsPipes) {
" << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;", " << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
getLLVMStyleWithColumns(70)); getLLVMStyleWithColumns(70));
// But sometimes, breaking before the first "<<" is necessary. // But sometimes, breaking before the first "<<" is desirable.
verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)\n" verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)\n"
" << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); " << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
verifyFormat("SemaRef.Diag(Loc, diag::note_for_range_begin_end)\n"
" << BEF << IsTemplate << Description << E->getType();");
verifyFormat( verifyFormat(
"llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" "llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"