[PATCH] C Block Formatting in clang-format

Brian King brianaking at gmail.com
Sun Apr 5 09:56:10 PDT 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150405/fed4fc10/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c-block-format.patch
Type: application/octet-stream
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150405/fed4fc10/attachment.obj>


More information about the llvm-commits mailing list