[PATCH] C Block Formatting in clang-format

Brian King brianaking at gmail.com
Sun Apr 5 15:51:32 PDT 2015


Will do! Also, looks like I was a bit pessimistic about the behavior and
optimistic about my fix. It looks like the block formatting does work when
a column width is set, and not when it's set to 0, like we have. Also, my
fix is breaking the ability to have 1 line blocks. I thought I had ran the
unit tests, but once you pointed me to that, I realized I missed them. I'll
look into it more as I have time and get a new patch in.

Thanks for the feedback tho!

Brian

On Sun, Apr 5, 2015 at 1:44 PM, Daniel Jasper <djasper at google.com> wrote:

> Hi Brian,
>
> thanks for working on this. Could you provide an example or two of what
> behavior is changing exactly? Also add tests in
> unittests/Format/FormatTest.cpp. There are certainly tests there that test
> multiline behavior and it should be obvious how to add additional ones.
> Somewhat next to other ObjC tests would probably be good, e.g. close to
> "TEST_F(FormatTest, FormatsBlocks) {".
>
> Also, generally prefer using our code review system on
> http://reviews.llvm.org.
>
> Cheers,
> Daniel
>
> On Sun, Apr 5, 2015 at 6:56 PM, Brian King <brianaking at gmail.com> wrote:
>
>> The current version of clang-format does not apply formatting rules
>> inside of c blocks. This significantly reduces the usefulness of
>> clang-format in Obj-C projects.
>>
>> When I turned on debug, I noticed that all the lines were being added as
>> child-lines in the UnwrappedLineParser, which apparently causes Format to
>> not suggest replacements.
>>
>> parseStructuralElement had some code to parse C Blocks and handed them
>> off to parseChildBlock. I changed that to use parseLevel  so that the
>> blocks would be handled like other types of blocks. I found 3 different
>> places that blocks can be encountered, a variable
>> declaration(parseStructuralElement), an objective-c
>> invocation(parseSquare), and a C method invocation(parseParens). This patch
>> should pass the tokens through a new method parseCBlock when a carat is
>> encountered in those methods.
>>
>> All of the tests continue to pass. I did not see any clang-format tests
>> that tested any multi-line behavior and it wasn't too clear how to add
>> them. I did run this on a lot of different styles of block behavior, and it
>> works as expected.
>>
>> Thanks for the awesome project, if there's anything I can do to help this
>> get accepted, I'll gladly keep working on it.
>>
>>
>> Brian King
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150405/7191abe7/attachment.html>


More information about the llvm-commits mailing list