r177740 - Better fix for r177725.

Jordan Rose jordan_rose at apple.com
Fri Mar 22 09:59:12 PDT 2013


Awesome. Thanks, Daniel.

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

> Author: djasper
> Date: Fri Mar 22 11:55:40 2013
> New Revision: 177740
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=177740&view=rev
> Log:
> Better fix for r177725.
> 
> It turns out that
> 
> -foo;
> 
> can be an objective C method declaration. So instead of the previous
> solution, recognize objective C methods only if we are in a declaration
> scope.
> 
> Modified:
>    cfe/trunk/lib/Format/TokenAnnotator.cpp
>    cfe/trunk/lib/Format/UnwrappedLineParser.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=177740&r1=177739&r2=177740&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
> +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Mar 22 11:55:40 2013
> @@ -313,11 +313,7 @@ private:
>     switch (Tok->FormatTok.Tok.getKind()) {
>     case tok::plus:
>     case tok::minus:
> -      // 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)))
> +      if (Tok->Parent == NULL && Line.MustBeDeclaration)
>         Tok->Type = TT_ObjCMethodSpecifier;
>       break;
>     case tok::colon:
> 
> Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=177740&r1=177739&r2=177740&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
> +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Mar 22 11:55:40 2013
> @@ -144,8 +144,9 @@ bool UnwrappedLineParser::parse() {
> }
> 
> bool UnwrappedLineParser::parseFile() {
> -  ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
> -                                          /*MustBeDeclaration=*/ true);
> +  ScopedDeclarationState DeclarationState(
> +      *Line, DeclarationScopeStack,
> +      /*MustBeDeclaration=*/ !Line->InPPDirective);
>   bool Error = parseLevel(/*HasOpeningBrace=*/ false);
>   // Make sure to format the remaining tokens.
>   flushComments(true);
> 
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177740&r1=177739&r2=177740&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Mar 22 11:55:40 2013
> @@ -2815,6 +2815,7 @@ TEST_F(FormatTest, FormatForObjectiveCMe
> 
>   // If there's no return type (very rare in practice!), LLVM and Google style
>   // agree.
> +  verifyFormat("- foo;");
>   verifyFormat("- foo:(int)f;");
>   verifyGoogleFormat("- foo:(int)foo;");
> }
> 
> 
> _______________________________________________
> 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