Improve error recovery in parse_for() and do not return an error statement.
authorChristoph Mallon <christoph.mallon@gmx.de>
Thu, 26 Apr 2012 10:41:04 +0000 (12:41 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 26 Apr 2012 13:19:17 +0000 (15:19 +0200)
parser.c

index 59417dd..0f7f557 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -9507,12 +9507,12 @@ static statement_t *parse_for(void)
 
        eat(T_for);
 
-       expect('(', end_error1);
-       add_anchor_token(')');
-
        PUSH_PARENT(statement);
        PUSH_SCOPE(&statement->fors.scope);
 
+       expect('(', end_error1);
+       add_anchor_token(')');
+
        PUSH_EXTENSION();
 
        if (next_if(';')) {
@@ -9544,6 +9544,7 @@ end_error3:;
                rem_anchor_token(';');
        }
        expect(';', end_error2);
+end_error2:
        if (token.kind != ')') {
                expression_t *const step = parse_expression();
                statement->fors.step = step;
@@ -9552,22 +9553,14 @@ end_error3:;
                        warningf(WARN_UNUSED_VALUE, &step->base.source_position, "step of 'for'-statement has no effect");
                }
        }
-       expect(')', end_error2);
        rem_anchor_token(')');
+       expect(')', end_error1);
+end_error1:
        statement->fors.body = parse_loop_body(statement);
 
        POP_SCOPE();
        POP_PARENT();
        return statement;
-
-end_error2:
-       POP_PARENT();
-       rem_anchor_token(')');
-       POP_SCOPE();
-       /* fallthrough */
-
-end_error1:
-       return create_error_statement();
 }
 
 /**