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

Nico Weber thakis at chromium.org
Tue Apr 29 10:44:22 PDT 2014


On Tue, Apr 29, 2014 at 7:05 AM, Daniel Jasper <djasper at google.com> wrote:

> 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);
>

This seems to contradict
http://www.webkit.org/coding/coding-style.html#braces-function . What's the
motivation for this change?


> +
>    // Constructor initializers are formatted one per line with the "," on
> the
>    // new line.
>    verifyFormat("Constructor()\n"
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140429/6751ce6f/attachment.html>


More information about the cfe-commits mailing list