]> granicus.if.org Git - clang/commitdiff
Better fix for r177725.
authorDaniel Jasper <djasper@google.com>
Fri, 22 Mar 2013 16:55:40 +0000 (16:55 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 22 Mar 2013 16:55:40 +0000 (16:55 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177740 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 7e3ef75d3dc107ca9dde705fe13f10aa899fe0ce..25670d4f6882a0ed393b0a7748a95056acf72c23 100644 (file)
@@ -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:
index a01344c03e6998c8b3cb1e61f3dd059635a7270f..8408ce3a0d8f64fee7a8e6733ac0c24f5a181be7 100644 (file)
@@ -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);
index 084030275426d150295f8f884821af2da75e6eb1..5988a905965f00c08919ed350f817f954f7c2a81 100644 (file)
@@ -2815,6 +2815,7 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) {
 
   // 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;");
 }