r177725 - More precisely recognize ObjC method declarations.

Jordan Rose jordan_rose at apple.com
Fri Mar 22 09:16:58 PDT 2013


These are valid Objective-C method declarations.

- methodReturningID;
+ methodWithArgument:first context:second;

The types are assumed to be 'id', just like C90 return types are assumed to be 'int'.

Most people don't write code like this today, but it is legal. It makes sense for clang-format to not handle these well in macros, though.


On Mar 22, 2013, at 3:44 , Daniel Jasper <djasper at google.com> wrote:

> Author: djasper
> Date: Fri Mar 22 05:44:43 2013
> New Revision: 177725
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=177725&view=rev
> Log:
> More precisely recognize ObjC method declarations.
> 
> Otherwise, +/- and the beginning of constants can be recognized
> incorrectly.
> 
> Before:  #define A - 1
> After:   #define A -1
> 
> Modified:
>    cfe/trunk/lib/Format/TokenAnnotator.cpp
>    cfe/trunk/unittests/Format/FormatTest.cpp
> 
> Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=177725&r1=177724&r2=177725&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
> +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Mar 22 05:44:43 2013
> @@ -313,9 +313,11 @@ private:
>     switch (Tok->FormatTok.Tok.getKind()) {
>     case tok::plus:
>     case tok::minus:
> -      // At the start of the line, +/- specific ObjectiveC method
> -      // declarations.
> -      if (Tok->Parent == NULL)
> +      // At the start of the line, +/- specify ObjectiveC method declarations.
> +      if (Tok->Children.empty() || Tok->Children[0].Children.empty())
> +        break; // Can't be an ObjectiveC method declaration.
> +      if (Tok->Parent == NULL && (Tok->Children[0].is(tok::l_paren) ||
> +                                  Tok->Children[0].Children[0].is(tok::colon)))
>         Tok->Type = TT_ObjCMethodSpecifier;
>       break;
>     case tok::colon:
> 
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177725&r1=177724&r2=177725&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Mar 22 05:44:43 2013
> @@ -2067,6 +2067,8 @@ TEST_F(FormatTest, UnderstandsUnaryOpera
>                "case -1:\n"
>                "  break;\n"
>                "}");
> +  verifyFormat("#define X -1");
> +  verifyFormat("#define X -kConstant");
> 
>   verifyFormat("const NSPoint kBrowserFrameViewPatternOffset = { -5, +3 };");
>   verifyFormat("const NSPoint kBrowserFrameViewPatternOffset = { +5, -3 };");
> 
> 
> _______________________________________________
> 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