[PATCH] [clang-format] AllowSimpleBracedStatements

Daniel Jasper djasper at google.com
Wed May 14 02:01:18 PDT 2014


On Wed, May 14, 2014 at 9:38 AM, Gonzalo BG <gonzalobg88 at gmail.com> wrote:

> It looks like you might have attached the wrong diff. It contains nothing
>> but formatting changes as far as I can tell.
>
>
>
>  Indeed. Sorry about that. Here is the whole patch. It is however
> unformatted.
>
> Bests,
> Gonzalo
>
> P.S: I tried to find how to format the diff with clang-format. The only
> way I found was:
>
> "svn diff | tools/clang-format/clang-format-diff.py > ~/patch.diff".
>

clang-format-diff takes a unified diff as input, determines which lines are
changed and reformats those lines in the original files. For SVN, you
should be able to do:

svn diff --diff-cmd=diff -x-u0 | tools/clang-format/clang-format-diff.py

Which will show you the differences or use "-i" to change the files in
place.

OR, just integrate clang-format into your editor :-).

However, clang-format-diff swallows almost the whole patch..
>
> I tried setting up "git clang-format" but it seems to be non trivial and
> there seem to be no docs about it.
>

If you could point me to the documentation about how to set up git
> clang-format and use it to format the patch I can try again.
>

Well, you need to use git instead of svn as version control system and you
should not make that switch for clang-format. Once you use git, it should
be a simple matter of putting git-clang-format on your path.

In the interest of getting this submitted quickly, I'll patch it in, do a
bit of cleanup and submit.
Thanks for working on this!

Cheers,
Daniel

On Wed, May 14, 2014 at 7:49 AM, Daniel Jasper <djasper at google.com> wrote:
>
>>  It looks like you might have attached the wrong diff. It contains
>> nothing but formatting changes as far as I can tell.
>>
>>  Cheers,
>> Daniel
>>
>>
>> On Mon, May 12, 2014 at 8:19 PM, Gonzalo BG <gonzalobg88 at gmail.com>wrote:
>>
>>> This patch adds a new option "AllowSimpleBracedStatements" that allows
>>> braced statements to be considered as "simple". That is, if
>>> AllowShortIfStatementsOnASingleLine and AllowShortLoopStatementsOnASingle
>>> line are enabled, code like:
>>>
>>>  if (true) {
>>>   f();
>>> }
>>>
>>>  can be wrapped into a single line as:
>>>
>>>  if (true) { f(); }
>>>
>>>  AllowSimpleBracedStatements defaults to false, meaning that the above
>>> transformation will not happen since braced block are considered "complex"
>>> and thus are not allowed to be put on a single line.
>>>
>>>  This is a fix for http://llvm.org/bugs/show_bug.cgi?id=19193 . There,
>>> the following remarks were made:
>>>
>>>  Things to do before this can get accepted:
>>>> - You clang-format in LLVM style to format the changes (or e.g.
>>>> git-clang-format).
>>>> - Add tests, i.e. your test program should be put as unit tests into
>>>> unittests/Format/FormatTest.cpp
>>>
>>>
>>>  These issues have been addressed (hopefully!) in the attached patch
>>> and adding the tests has made the patch better (so thanks for the
>>> feedback!).
>>>
>>>  Some newbie impressions on the clang-format code for those interested:
>>>
>>>  I have almost no experience with clang-format but after hacking on it
>>> a bit I feel that in the future there should be a way to format blocks
>>> independently of them being braced or not, belonging to a function, a
>>> control statements, a loop, ... Right now there are multiple functions
>>> dealing with the formatting of blocks and it felt a bit messy.
>>>
>>>  It also took me a bit to figure out how to add a new test, and how to
>>> launch clang-format tests only (independently of all others llvm tests) but
>>> this could probably fixed with a small paragraph in the docs.
>>>
>>>  Otherwise the code is self explanatory and well documented, and for
>>> someone like me who has no idea what he is doing (and what clang-format is
>>> doing) it was really easy to get clang-format to do what I wanted.
>>>
>>>  Bests,
>>> Gonzalo BG
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140514/7aa2e2db/attachment.html>


More information about the cfe-commits mailing list