From c080950de05aa3e3e2adf8835387b5d0112bb868 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Thu, 26 Apr 2012 14:53:09 +0200 Subject: [PATCH] Improve error recovery in parse_compound_statement(). - Handle EOF generically with expect(). - Do not skip semantic checks, when breaking out of the parsing loop due to an error. --- parser.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/parser.c b/parser.c index b1db357..1644fa3 100644 --- a/parser.c +++ b/parser.c @@ -10158,15 +10158,10 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) statement_t **anchor = &statement->compound.statements; bool only_decls_so_far = true; - while (token.kind != '}') { - if (token.kind == T_EOF) { - errorf(&statement->base.source_position, - "EOF while parsing compound statement"); - break; - } + while (token.kind != '}' && token.kind != T_EOF) { statement_t *sub_statement = intern_parse_statement(); if (sub_statement->kind == STATEMENT_ERROR) { - goto end_error; + break; } if (sub_statement->kind != STATEMENT_DECLARATION) { @@ -10179,7 +10174,8 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) *anchor = sub_statement; anchor = &sub_statement->base.next; } - next_token(); + expect('}', end_error); +end_error: /* look over all statements again to produce no effect warnings */ if (is_warn_on(WARN_UNUSED_VALUE)) { @@ -10199,7 +10195,6 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) } } -end_error: rem_anchor_token(T_while); rem_anchor_token(T_wchar_t); rem_anchor_token(T_volatile); -- 2.20.1