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

Nico Weber thakis at chromium.org
Tue Jan 22 07:30:33 PST 2013


On Tue, Jan 22, 2013 at 3:46 AM, Daniel Jasper <djasper at google.com> wrote:
> Author: djasper
> Date: Tue Jan 22 05:46:26 2013
> New Revision: 173150
>
> URL: http://llvm.org/viewvc/llvm-project?rev=173150&view=rev
> Log:
> Fix "*" formatting when creating arrays of pointers.
>
> Before: A = new int * [10]();
> After:  A = new int *[10]();
>
> 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=173150&r1=173149&r2=173150&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/Format.cpp (original)
> +++ cfe/trunk/lib/Format/Format.cpp Tue Jan 22 05:46:26 2013
> @@ -958,6 +958,13 @@
>
>        while (CurrentToken != NULL) {
>          if (CurrentToken->is(tok::r_square)) {
> +          if (!CurrentToken->Children.empty() &&
> +              CurrentToken->Children[0].is(tok::l_paren)) {
> +            // An ObjC method call can't be followed by an open parenthesis.

I think it can, if the ObjC method returns a function pointer for example.

> +            // FIXME: Do we incorrectly label ":" with this?
> +            StartsObjCMethodExpr = false;
> +            Left->Type = TT_Unknown;
> +         }
>            if (StartsObjCMethodExpr)
>              objCSelector.markEnd(*CurrentToken);
>            Left->MatchingParen = CurrentToken;
> @@ -1325,6 +1332,9 @@
>      if (NextToken == NULL)
>        return TT_Unknown;
>
> +    if (NextToken->is(tok::l_square) && NextToken->Type != TT_ObjCMethodExpr)
> +      return TT_PointerOrReference;
> +
>      if (PrevToken->is(tok::l_paren) || PrevToken->is(tok::l_square) ||
>          PrevToken->is(tok::l_brace) || PrevToken->is(tok::comma) ||
>          PrevToken->is(tok::kw_return) || PrevToken->is(tok::colon) ||
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173150&r1=173149&r2=173150&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 22 05:46:26 2013
> @@ -1338,6 +1338,9 @@
>    verifyFormat("if (*b[i])");
>    verifyFormat("if (int *a = (&b))");
>    verifyFormat("while (int *a = &b)");
> +
> +  verifyFormat("A = new SomeType *[Length]();");
> +  verifyGoogleFormat("A = new SomeType* [Length]();");
>  }
>
>  TEST_F(FormatTest, FormatsCasts) {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list