[cfe-commits] r172361 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Mon Jan 14 02:26:04 PST 2013
Do you think we need to?
On Mon, Jan 14, 2013 at 11:25 AM, Manuel Klimek <klimek at google.com> wrote:
> On Sun, Jan 13, 2013 at 5:10 PM, Daniel Jasper <djasper at google.com> wrote:
>
>> Author: djasper
>> Date: Sun Jan 13 10:10:20 2013
>> New Revision: 172361
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=172361&view=rev
>> Log:
>> Stronger respect the input codes line breaks wrt. comments.
>>
>> clang-format should not change whether or not there is a line break
>> before a line comment as this strongly influences the percieved binding.
>>
>> User input: void f(int a,
>> // b is awesome
>> int b);
>> void g(int a, // a is awesome
>> int b);
>> Before: void f(int a, // b is awesome
>> int b);
>> void g(int a, // a is awesome
>> int b);
>> After: <unchanged from input>
>>
>> Modified:
>> cfe/trunk/lib/Format/Format.cpp
>> cfe/trunk/unittests/Format/FormatTest.cpp
>>
>> Modified: cfe/trunk/lib/Format/Format.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172361&r1=172360&r2=172361&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Format/Format.cpp (original)
>> +++ cfe/trunk/lib/Format/Format.cpp Sun Jan 13 10:10:20 2013
>> @@ -901,9 +901,12 @@
>> if (Current.FormatTok.MustBreakBefore) {
>> Current.MustBreakBefore = true;
>> } else {
>> - if (Current.Type == TT_CtorInitializerColon ||
>> Current.Parent->Type ==
>> - TT_LineComment || (Current.is(tok::string_literal) &&
>> - Current.Parent->is(tok::string_literal))) {
>> + if (Current.Type == TT_LineComment) {
>> + Current.MustBreakBefore = Current.FormatTok.NewlinesBefore > 0;
>>
>
> I assume we don't care about escaped newlines here?
>
>
>> + } else if (Current.Type == TT_CtorInitializerColon ||
>> + Current.Parent->Type == TT_LineComment ||
>> + (Current.is(tok::string_literal) &&
>> + Current.Parent->is(tok::string_literal))) {
>> Current.MustBreakBefore = true;
>> } else {
>> Current.MustBreakBefore = false;
>> @@ -1219,7 +1222,10 @@
>> return false;
>>
>> if (Right.is(tok::comment))
>> - return !Right.Children.empty();
>> + // We rely on MustBreakBefore being set correctly here as we
>> should not
>> + // change the "binding" behavior of a comment.
>> + return false;
>> +
>> if (Right.is(tok::r_paren) || Right.is(tok::l_brace) ||
>> Right.is(tok::greater))
>> return false;
>>
>> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172361&r1=172360&r2=172361&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
>> +++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Jan 13 10:10:20 2013
>> @@ -285,6 +285,14 @@
>> verifyFormat("void f() {\n"
>> " // Doesn't do anything\n"
>> "}");
>> + verifyFormat("void f(int i, // some comment (probably for i)\n"
>> + " int j, // some comment (probably for j)\n"
>> + " int k); // some comment (probably for k)");
>> + verifyFormat("void f(int i,\n"
>> + " // some comment (probably for j)\n"
>> + " int j,\n"
>> + " // some comment (probably for k)\n"
>> + " int k);");
>>
>> verifyFormat("int i // This is a fancy variable\n"
>> " = 5;");
>>
>>
>> _______________________________________________
>> 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/20130114/1a4805c0/attachment.html>
More information about the cfe-commits
mailing list