From 0a863bf803aca3f74d1f000bf799e3944ef6a87a Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Fri, 19 Sep 2008 04:56:20 +0000 Subject: [PATCH] Resolve off-by-one (and off-by-two) errors in the source position of statements. [r22112] --- parser.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/parser.c b/parser.c index 3b841bb..a167ab3 100644 --- a/parser.c +++ b/parser.c @@ -8705,11 +8705,11 @@ static asm_clobber_t *parse_asm_clobbers(void) */ static statement_t *parse_asm_statement(void) { - eat(T_asm); - statement_t *statement = allocate_statement_zero(STATEMENT_ASM); asm_statement_t *asm_statement = &statement->asms; + eat(T_asm); + if (token.type == T_volatile) { next_token(); asm_statement->is_volatile = true; @@ -8764,11 +8764,11 @@ end_error: */ static statement_t *parse_case_statement(void) { - eat(T_case); - statement_t *const statement = allocate_statement_zero(STATEMENT_CASE_LABEL); source_position_t *const pos = &statement->base.source_position; + eat(T_case); + expression_t *const expression = parse_expression(); statement->case_label.expression = expression; if (!is_constant_expression(expression)) { @@ -8859,10 +8859,10 @@ end_error: */ static statement_t *parse_default_statement(void) { - eat(T_default); - statement_t *statement = allocate_statement_zero(STATEMENT_CASE_LABEL); + eat(T_default); + PUSH_PARENT(statement); expect(':'); @@ -8906,14 +8906,14 @@ end_error: static statement_t *parse_label_statement(void) { assert(token.type == T_IDENTIFIER); - symbol_t *symbol = token.v.symbol; - next_token(); - - declaration_t *label = get_label(symbol); + symbol_t *symbol = token.v.symbol; + declaration_t *label = get_label(symbol); statement_t *const statement = allocate_statement_zero(STATEMENT_LABEL); statement->label.label = label; + next_token(); + PUSH_PARENT(statement); /* if statement is already set then the label is defined twice, @@ -8968,10 +8968,10 @@ static statement_t *parse_label_statement(void) */ static statement_t *parse_if(void) { - eat(T_if); - statement_t *statement = allocate_statement_zero(STATEMENT_IF); + eat(T_if); + PUSH_PARENT(statement); expect('('); @@ -9041,10 +9041,10 @@ static void check_enum_cases(const switch_statement_t *statement) { */ static statement_t *parse_switch(void) { - eat(T_switch); - statement_t *statement = allocate_statement_zero(STATEMENT_SWITCH); + eat(T_switch); + PUSH_PARENT(statement); expect('('); @@ -9104,10 +9104,10 @@ static statement_t *parse_loop_body(statement_t *const loop) */ static statement_t *parse_while(void) { - eat(T_while); - statement_t *statement = allocate_statement_zero(STATEMENT_WHILE); + eat(T_while); + PUSH_PARENT(statement); expect('('); @@ -9130,10 +9130,10 @@ end_error: */ static statement_t *parse_do(void) { - eat(T_do); - statement_t *statement = allocate_statement_zero(STATEMENT_DO_WHILE); + eat(T_do); + PUSH_PARENT(statement) add_anchor_token(T_while); @@ -9160,10 +9160,10 @@ end_error: */ static statement_t *parse_for(void) { - eat(T_for); - statement_t *statement = allocate_statement_zero(STATEMENT_FOR); + eat(T_for); + PUSH_PARENT(statement); size_t const top = environment_top(); @@ -9405,10 +9405,10 @@ declaration_t *expr_is_variable(const expression_t *expression) */ static statement_t *parse_return(void) { - statement_t *statement = allocate_statement_zero(STATEMENT_RETURN); - eat(T_return); + statement_t *statement = allocate_statement_zero(STATEMENT_RETURN); + expression_t *return_value = NULL; if (token.type != ';') { return_value = parse_expression(); @@ -9896,10 +9896,11 @@ static void check_unused_globals(void) static void parse_global_asm(void) { + statement_t *statement = allocate_statement_zero(STATEMENT_ASM); + eat(T_asm); expect('('); - statement_t *statement = allocate_statement_zero(STATEMENT_ASM); statement->asms.asm_text = parse_string_literals(); statement->base.next = unit->global_asm; unit->global_asm = statement; -- 2.20.1