return stmt;
}
+/**
+ * Parse an expression in parentheses and mark its variables as read.
+ */
+static expression_t *parse_condition(void)
+{
+ expect('(', end_error0);
+ add_anchor_token(')');
+ expression_t *const expr = parse_expression();
+ mark_vars_read(expr, NULL);
+ rem_anchor_token(')');
+ expect(')', end_error1);
+end_error1:
+ return expr;
+end_error0:
+ return create_error_expression();
+}
+
/**
* Parse an if statement.
*/
add_anchor_token('{');
- expect('(', end_error);
- add_anchor_token(')');
- expression_t *const expr = parse_expression();
+ expression_t *const expr = parse_condition();
statement->ifs.condition = expr;
/* §6.8.4.1:1 The controlling expression of an if statement shall have
* scalar type. */
semantic_condition(expr, "condition of 'if'-statment");
- mark_vars_read(expr, NULL);
- rem_anchor_token(')');
- expect(')', end_error);
-end_error:
rem_anchor_token('{');
add_anchor_token(T_else);
PUSH_PARENT(statement);
- expect('(', end_error);
- add_anchor_token(')');
- expression_t *const expr = parse_expression();
- mark_vars_read(expr, NULL);
+ expression_t *const expr = parse_condition();
type_t * type = skip_typeref(expr->base.type);
if (is_type_integer(type)) {
type = promote_integer(type);
type = type_error_type;
}
statement->switchs.expression = create_implicit_cast(expr, type);
- expect(')', end_error);
- rem_anchor_token(')');
switch_statement_t *rem = current_switch;
current_switch = &statement->switchs;
POP_PARENT();
return statement;
-end_error:
- POP_PARENT();
- return create_error_statement();
}
static statement_t *parse_loop_body(statement_t *const loop)
PUSH_PARENT(statement);
- expect('(', end_error);
- add_anchor_token(')');
- expression_t *const cond = parse_expression();
+ expression_t *const cond = parse_condition();
statement->whiles.condition = cond;
/* §6.8.5:2 The controlling expression of an iteration statement shall
* have scalar type. */
semantic_condition(cond, "condition of 'while'-statement");
- mark_vars_read(cond, NULL);
- rem_anchor_token(')');
- expect(')', end_error);
statement->whiles.body = parse_loop_body(statement);
POP_PARENT();
return statement;
-end_error:
- POP_PARENT();
- return create_error_statement();
}
/**
rem_anchor_token(T_while);
expect(T_while, end_error);
- expect('(', end_error);
- add_anchor_token(')');
- expression_t *const cond = parse_expression();
+ expression_t *const cond = parse_condition();
statement->do_while.condition = cond;
/* §6.8.5:2 The controlling expression of an iteration statement shall
* have scalar type. */
semantic_condition(cond, "condition of 'do-while'-statement");
- mark_vars_read(cond, NULL);
- rem_anchor_token(')');
- expect(')', end_error);
expect(';', end_error);
POP_PARENT();
POP_PARENT();
if (next_if(T___except)) {
- expect('(', end_error);
- add_anchor_token(')');
- expression_t *const expr = parse_expression();
- mark_vars_read(expr, NULL);
+ expression_t *const expr = parse_condition();
type_t * type = skip_typeref(expr->base.type);
if (is_type_integer(type)) {
type = promote_integer(type);
type = type_error_type;
}
statement->ms_try.except_expression = create_implicit_cast(expr, type);
- rem_anchor_token(')');
- expect(')', end_error);
- statement->ms_try.final_statement = parse_compound_statement(false);
+ statement->ms_try.final_statement = parse_compound_statement(false);
} else if (next_if(T__finally)) {
statement->ms_try.final_statement = parse_compound_statement(false);
} else {
return create_error_statement();
}
return statement;
-end_error:
- return create_error_statement();
}
static statement_t *parse_empty_statement(void)