r207527 - clang-format: Allow single-line function in WebKit style.

Daniel Jasper djasper at google.com
Tue Apr 29 07:05:20 PDT 2014


Author: djasper
Date: Tue Apr 29 09:05:20 2014
New Revision: 207527

URL: http://llvm.org/viewvc/llvm-project?rev=207527&view=rev
Log:
clang-format: Allow single-line function in WebKit style.

Before:
  void f() {
      return; }

After:
  void f() { return; }

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/lib/Format/Format.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=207527&r1=207526&r2=207527&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Apr 29 09:05:20 2014
@@ -207,8 +207,8 @@ bool ContinuationIndenter::mustBreak(con
   // 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))
+  if (Style.ColumnLimit != 0 && Previous.BlockKind == BK_Block &&
+      Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment))
     return true;
 
   return false;

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=207527&r1=207526&r2=207527&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Apr 29 09:05:20 2014
@@ -499,6 +499,8 @@ public:
       bool Newline =
           Indenter->mustBreak(State) ||
           (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);
+      llvm::errs() << State.NextToken->Tok.getName() << " "
+                   << Indenter->mustBreak(State) << "\n";
       Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
     }
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=207527&r1=207526&r2=207527&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Apr 29 09:05:20 2014
@@ -8198,6 +8198,9 @@ TEST_F(FormatTest, FormatsWithWebKitStyl
           "}",
           Style));
 
+  // Allow functions on a single line.
+  verifyFormat("void f() { return; }", Style);
+
   // Constructor initializers are formatted one per line with the "," on the
   // new line.
   verifyFormat("Constructor()\n"





More information about the cfe-commits mailing list