[PATCH] C Block Formatting in clang-format

Daniel Jasper djasper at google.com
Sun Apr 5 10:44:46 PDT 2015


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/4e127dc1/attachment.html>


More information about the llvm-commits mailing list