]> granicus.if.org Git - clang/commitdiff
clang-format: Improve stream-formatting.
authorDaniel Jasper <djasper@google.com>
Mon, 12 Aug 2013 12:58:05 +0000 (12:58 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 12 Aug 2013 12:58:05 +0000 (12:58 +0000)
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();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188175 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 322e867006817d0ccb3d3e6d6bde4e741fb6e789..6fe4d45d1d0ea0ed7eeb7c75ad3ea91689cdc5c5 100644 (file)
@@ -595,6 +595,12 @@ private:
     unsigned ContinuationIndent =
         std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) + 4;
     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;
       if (Current.is(tok::r_brace)) {
         if (Current.BlockKind == BK_BracedInit)
@@ -705,10 +711,6 @@ private:
           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 {
       if (Current.is(tok::equal) &&
           (RootToken->is(tok::kw_for) || State.ParenLevel == 0) &&
index f5e16d0e8960acf1970d8c5d72611f8b5f0daa03..ec37252947aea5b2c4a4414f658ccfef4c586e4a 100644 (file)
@@ -3188,10 +3188,12 @@ TEST_F(FormatTest, AlignsPipes) {
                "             << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
                getLLVMStyleWithColumns(70));
 
-  // But sometimes, breaking before the first "<<" is necessary.
+  // But sometimes, breaking before the first "<<" is desirable.
   verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)\n"
                "    << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
                "    << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
+  verifyFormat("SemaRef.Diag(Loc, diag::note_for_range_begin_end)\n"
+               "    << BEF << IsTemplate << Description << E->getType();");
 
   verifyFormat(
       "llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"