r207527 - clang-format: Allow single-line function in WebKit style.
Nico Weber
thakis at chromium.org
Tue Apr 29 22:02:29 PDT 2014
Ah, that makes sense. Thanks :-)
On Tue, Apr 29, 2014 at 10:01 PM, Daniel Jasper <djasper at google.com> wrote:
> Not really.
>
> Before, this was horribly broken and definitely contradicted they style
> guide. Now, it is just an open question of whether you are allowed to but a
> short function onto a single line and AFAIU, there is a bit of disagreement
> on that. And (with ColumnLimit == 0) clang-format will just leave the
> authors choice. Thus, if you wrap the function on multiple lines, it will
> also put the braces on their own line. If you decide put it on a single
> line, it will leave that intact.
>
> And if one day, WebKit developers decide that this is not the way to go,
> single-line functions can be prevented by a flag flip.
>
>
> On Tue, Apr 29, 2014 at 7:44 PM, Nico Weber <thakis at chromium.org> wrote:
>>
>> 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
>>
>>
>
More information about the cfe-commits
mailing list