[cfe-commits] r172349 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Richard Smith richard at metafoo.co.uk
Sun Jan 13 22:07:55 PST 2013


On Sun, Jan 13, 2013 at 10:04 PM, Daniel Jasper <djasper at google.com> wrote:

> Do we have a style (guide) that says you can't put a space between ")" and
> "{"?
>

I would expect style guides to implicitly include them in whatever they say
about casts.


> On Mon, Jan 14, 2013 at 1:18 AM, Richard Smith <richard at metafoo.co.uk>wrote:
>
>> On Sun, Jan 13, 2013 at 12:01 AM, Daniel Jasper <djasper at google.com>wrote:
>>
>>> Author: djasper
>>> Date: Sun Jan 13 02:01:36 2013
>>> New Revision: 172349
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=172349&view=rev
>>> Log:
>>> Improve identification of c-style casts.
>>>
>>> A ")" before any of "=", "{" or ";" won't be a cast. This fixes issues
>>> with the formatting of unnamed parameters.
>>>
>>
>> What about C99 compound literals? e.g. (struct S){1, 2, 3}
>>
>>
>>> Before: void f(int *){}
>>> After:  void f(int *) {}
>>>
>>> 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=172349&r1=172348&r2=172349&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Format/Format.cpp (original)
>>> +++ cfe/trunk/lib/Format/Format.cpp Sun Jan 13 02:01:36 2013
>>> @@ -976,7 +976,11 @@
>>>            Current.Type = TT_BlockComment;
>>>        } else if (Current.is(tok::r_paren) &&
>>>                   (Current.Parent->Type == TT_PointerOrReference ||
>>> -                  Current.Parent->Type == TT_TemplateCloser)) {
>>> +                  Current.Parent->Type == TT_TemplateCloser) &&
>>> +                 (Current.Children.empty() ||
>>> +                  (Current.Children[0].isNot(tok::equal) &&
>>> +                   Current.Children[0].isNot(tok::semi) &&
>>> +                   Current.Children[0].isNot(tok::l_brace)))) {
>>>          // FIXME: We need to get smarter and understand more cases of
>>> casts.
>>>          Current.Type = TT_CastRParen;
>>>        } else if (Current.is(tok::at) && Current.Children.size()) {
>>>
>>> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172349&r1=172348&r2=172349&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
>>> +++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Jan 13 02:01:36 2013
>>> @@ -1045,9 +1045,6 @@
>>>    verifyFormat("A<int **> a;");
>>>    verifyFormat("A<int *, int *> a;");
>>>    verifyFormat("A<int **, int **> a;");
>>> -  verifyFormat("Type *A = static_cast<Type *>(P);");
>>> -  verifyFormat("Type *A = (Type *)P;");
>>> -  verifyFormat("Type *A = (vector<Type *, int *>)P;");
>>>
>>>    verifyFormat(
>>>        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
>>> @@ -1062,6 +1059,25 @@
>>>    verifyGoogleFormat("int a = b ? *c : *d;");
>>>  }
>>>
>>> +TEST_F(FormatTest, FormatsCasts) {
>>> +  verifyFormat("Type *A = static_cast<Type *>(P);");
>>> +  verifyFormat("Type *A = (Type *)P;");
>>> +  verifyFormat("Type *A = (vector<Type *, int *>)P;");
>>> +  verifyFormat("int a = (int)(2.0f);");
>>> +
>>> +  // FIXME: These also need to be identified.
>>> +  verifyFormat("int a = (int) 2.0f;");
>>> +  verifyFormat("int a = (int) * b;");
>>> +
>>> +  // These are not casts.
>>> +  verifyFormat("void f(int *) {}");
>>> +  verifyFormat("void f(int *);");
>>> +  verifyFormat("void f(int *) = 0;");
>>> +  verifyFormat("void f(SmallVector<int>) {}");
>>> +  verifyFormat("void f(SmallVector<int>);");
>>> +  verifyFormat("void f(SmallVector<int>) = 0;");
>>> +}
>>> +
>>>  TEST_F(FormatTest, FormatsFunctionTypes) {
>>>    // FIXME: Determine the cases that need a space after the return type
>>> and fix.
>>>    verifyFormat("A<bool()> a;");
>>>
>>>
>>> _______________________________________________
>>> 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/20130113/4c71a3a5/attachment.html>


More information about the cfe-commits mailing list