r260517 - clang-format: Make indentation after "<<" more consistent.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 05:15:14 PST 2016


Author: djasper
Date: Thu Feb 11 07:15:14 2016
New Revision: 260517

URL: http://llvm.org/viewvc/llvm-project?rev=260517&view=rev
Log:
clang-format: Make indentation after "<<" more consistent.

Before:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

After:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=260517&r1=260516&r2=260517&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Feb 11 07:15:14 2016
@@ -402,9 +402,9 @@ void ContinuationIndenter::addTokenOnCur
                (Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||
                 Previous.NextOperator)) ||
               Current.StartsBinaryExpression)) {
-    // Always indent relative to the RHS of the expression unless this is a
-    // simple assignment without binary expression on the RHS. Also indent
-    // relative to unary operators and the colons of constructor initializers.
+    // Indent relative to the RHS of the expression unless this is a simple
+    // assignment without binary expression on the RHS. Also indent relative to
+    // unary operators and the colons of constructor initializers.
     State.Stack.back().LastSpace = State.Column;
   } else if (Previous.is(TT_InheritanceColon)) {
     State.Stack.back().Indent = State.Column;
@@ -531,6 +531,12 @@ unsigned ContinuationIndenter::addTokenO
 
   if (!Current.isTrailingComment())
     State.Stack.back().LastSpace = State.Column;
+  if (Current.is(tok::lessless))
+    // If we are breaking before a "<<", we always want to indent relative to
+    // RHS. This is necessary only for "<<", as we special-case it and don't
+    // always indent relative to the RHS.
+    State.Stack.back().LastSpace += 3; // 3 -> width of "<< ".
+
   State.StartOfLineLevel = Current.NestingLevel;
   State.LowestLevelOnLine = Current.NestingLevel;
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=260517&r1=260516&r2=260517&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Feb 11 07:15:14 2016
@@ -5105,6 +5105,13 @@ TEST_F(FormatTest, AlignsPipes) {
                "    << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
   verifyFormat("SemaRef.Diag(Loc, diag::note_for_range_begin_end)\n"
                "    << BEF << IsTemplate << Description << E->getType();");
+  verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)\n"
+               "    << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+  verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)\n"
+               "    << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+               "    << aaa;");
 
   verifyFormat(
       "llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"




More information about the cfe-commits mailing list