Fix off-by-two-tokens error in the location of break and continue statements.
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 12 Dec 2007 08:01:49 +0000 (08:01 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 12 Dec 2007 08:01:49 +0000 (08:01 +0000)
[r18699]

parser.c

index c1c3054..2bf5cb7 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5201,18 +5201,19 @@ static statement_t *parse_goto(void)
  */
 static statement_t *parse_continue(void)
 {
-       eat(T_continue);
-       expect(';');
-
-       statement_t *statement          = allocate_ast_zero(sizeof(statement[0]));
-       statement->kind                 = STATEMENT_CONTINUE;
-       statement->base.source_position = token.source_position;
-
+       statement_t *statement;
        if (current_loop == NULL) {
                errorf(HERE, "continue statement not within loop");
-               return NULL;
+               statement = NULL;
+       } else {
+               statement                       = allocate_ast_zero(sizeof(statement[0]));
+               statement->kind                 = STATEMENT_CONTINUE;
+               statement->base.source_position = token.source_position;
        }
 
+       eat(T_continue);
+       expect(';');
+
        return statement;
 }
 
@@ -5221,17 +5222,19 @@ static statement_t *parse_continue(void)
  */
 static statement_t *parse_break(void)
 {
-       eat(T_break);
-       expect(';');
-
-       statement_t *statement          = allocate_ast_zero(sizeof(statement[0]));
-       statement->kind                 = STATEMENT_BREAK;
-       statement->base.source_position = token.source_position;
-
+       statement_t *statement;
        if (current_switch == NULL && current_loop == NULL) {
                errorf(HERE, "break statement not within loop or switch");
-               return NULL;
+               statement = NULL;
+       } else {
+               statement                       = allocate_ast_zero(sizeof(statement[0]));
+               statement->kind                 = STATEMENT_BREAK;
+               statement->base.source_position = token.source_position;
        }
+
+       eat(T_break);
+       expect(';');
+
        return statement;
 }