]> granicus.if.org Git - clang/commitdiff
In Parser::SkipUntil do not stop at '@' unconditionally.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 17 Dec 2011 04:13:22 +0000 (04:13 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 17 Dec 2011 04:13:22 +0000 (04:13 +0000)
Stopping at '@' was originally intended to avoid skipping an '@' at the @interface context
when doing parser recovery, but we should not stop at all '@' tokens because they may be part
of expressions (e.g. in @"string", @selector(), etc.), so in most cases we will want to skip them.

This commit caused 'test/Parser/method-def-in-class.m' to fail for the cases where we tried to
recover from unmatched angle bracket but IMO it is not a big deal to not have good recovery
from such broken code and the way we did recovery would not always work anyway (e.g. if there was '@'
in an expression).

The case that rdar://7029784 is about still passes.

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

lib/Parse/ParseObjc.cpp
lib/Parse/Parser.cpp
test/Parser/method-def-in-class.m

index 56d5c57c056d41baf85e4d3dadf581125a629fa2..1f20924c9b7532a5893070035e714eed647e4a29 100644 (file)
@@ -366,8 +366,12 @@ void Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey,
       allMethods.push_back(methodPrototype);
       // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for
       // method definitions.
-      ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto,
-                       "", tok::semi);
+      if (ExpectAndConsumeSemi(diag::err_expected_semi_after_method_proto)) {
+        // We didn't find a semi and we error'ed out. Skip until a ';' or '@'.
+        SkipUntil(tok::at, /*StopAtSemi=*/true, /*DontConsume=*/true);
+        if (Tok.is(tok::semi))
+          ConsumeToken();
+      }
       continue;
     }
     if (Tok.is(tok::l_paren)) {
index 95ce065ff7621d1580184755eb39ce23f2805160..c57711dbc6d041970e1dc07738747d94d8bf8cd3 100644 (file)
@@ -284,9 +284,6 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
       ConsumeStringToken();
       break;
         
-    case tok::at:
-      return false;
-      
     case tok::semi:
       if (StopAtSemi)
         return false;
index 490c0559d10832db56d0700399fff5d86fc57c2f..476ab9ba20e8ba3e4b2d63d1bde75dfb8681bba1 100644 (file)
@@ -7,19 +7,8 @@
 }
 @end
 
-@interface B
--(id) f0 { // expected-error {{expected ';' after method prototype}}
-  assert(0);
-@end
-
 @interface C
 - (id) f0 { // expected-error {{expected ';' after method prototype}}
     assert(0);
 };
 @end
-
-@interface D
-- (id) f0 { // expected-error {{expected ';' after method prototype}}
-  assert(0);
-@property int P;
-@end