@@ -59,8 +59,6 @@ void inspect_statement(AstNode *node)
case STMT_ITERATOR:
ast_append_child(node, "break:", stmt->iterator_break, inspect_symbol);
ast_append_child(node, "continue:", stmt->iterator_continue, inspect_symbol);
- ast_append_child(node, "pre_statement:", stmt->iterator_pre_statement,
- inspect_statement);
ast_append_child(node, "statement:", stmt->iterator_statement,
inspect_statement);
ast_append_child(node, "post_statement:", stmt->iterator_post_statement,
@@ -1913,7 +1913,6 @@ static int loopstk_continue(void)
static void emit_loop(struct statement *stmt)
{
- struct statement *pre_statement = stmt->iterator_pre_statement;
struct expression *pre_condition = stmt->iterator_pre_condition;
struct statement *statement = stmt->iterator_statement;
struct statement *post_statement = stmt->iterator_post_statement;
@@ -1926,7 +1925,6 @@ static void emit_loop(struct statement *stmt)
loop_continue = new_label();
loopstk_push(loop_continue, loop_bottom);
- x86_statement(pre_statement);
if (!post_condition || post_condition->type != EXPR_VALUE || post_condition->value) {
loop_top = new_label();
emit_label(loop_top, "loop top");
@@ -494,7 +494,6 @@ static struct symbol *do_statement(usage_t mode, struct statement *stmt)
}
break; case STMT_ITERATOR:
- do_statement(U_VOID, stmt->iterator_pre_statement);
do_expression(U_R_VAL, stmt->iterator_pre_condition);
do_statement(U_VOID, stmt->iterator_post_statement);
do_statement(U_VOID, stmt->iterator_statement);
@@ -3281,7 +3281,6 @@ static void evaluate_iterator(struct statement *stmt)
{
evaluate_conditional(stmt->iterator_pre_condition, 1);
evaluate_conditional(stmt->iterator_post_condition,1);
- evaluate_statement(stmt->iterator_pre_statement);
evaluate_statement(stmt->iterator_statement);
evaluate_statement(stmt->iterator_post_statement);
}
@@ -1180,7 +1180,6 @@ static int expand_statement(struct statement *stmt)
case STMT_ITERATOR:
expand_expression(stmt->iterator_pre_condition);
expand_expression(stmt->iterator_post_condition);
- expand_statement(stmt->iterator_pre_statement);
expand_statement(stmt->iterator_statement);
expand_statement(stmt->iterator_post_statement);
return SIDE_EFFECTS;
@@ -421,7 +421,6 @@ static struct statement *copy_one_statement(struct statement *stmt)
stmt = dup_statement(stmt);
stmt->iterator_break = copy_symbol(stmt->pos, stmt->iterator_break);
stmt->iterator_continue = copy_symbol(stmt->pos, stmt->iterator_continue);
- stmt->iterator_pre_statement = copy_one_statement(stmt->iterator_pre_statement);
stmt->iterator_pre_condition = copy_expression(stmt->iterator_pre_condition);
stmt->iterator_statement = copy_one_statement(stmt->iterator_statement);
@@ -1994,13 +1994,11 @@ static pseudo_t linearize_switch(struct entrypoint *ep, struct statement *stmt)
static pseudo_t linearize_iterator(struct entrypoint *ep, struct statement *stmt)
{
- struct statement *pre_statement = stmt->iterator_pre_statement;
struct expression *pre_condition = stmt->iterator_pre_condition;
struct statement *statement = stmt->iterator_statement;
struct statement *post_statement = stmt->iterator_post_statement;
struct expression *post_condition = stmt->iterator_post_condition;
struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end;
- linearize_statement(ep, pre_statement);
loop_body = loop_top = alloc_basic_block(ep, stmt->pos);
loop_continue = alloc_basic_block(ep, stmt->pos);
@@ -2284,6 +2284,7 @@ static struct token *parse_for_statement(struct token *token, struct statement *
{
struct expression *e2, *e3;
struct statement *iterator;
+ struct statement *compound;
struct statement *pre = NULL;
token = expect(token->next, '(', "after 'for'");
@@ -2303,6 +2304,14 @@ static struct token *parse_for_statement(struct token *token, struct statement *
pre = make_statement(e1);
}
+ if (pre) {
+ compound = stmt;
+ compound->type = STMT_COMPOUND;
+ stmt = alloc_statement(token->pos, STMT_ITERATOR);
+ add_statement(&compound->stmts, pre);
+ add_statement(&compound->stmts, stmt);
+ }
+
start_iterator(stmt);
token = parse_expression(token, &e2);
token = expect(token, ';', "in 'for'");
@@ -2310,7 +2319,6 @@ static struct token *parse_for_statement(struct token *token, struct statement *
token = expect(token, ')', "in 'for'");
token = statement(token, &iterator);
- stmt->iterator_pre_statement = pre;
stmt->iterator_pre_condition = e2;
stmt->iterator_post_statement = make_statement(e3);
stmt->iterator_post_condition = NULL;
@@ -88,7 +88,6 @@ struct statement {
struct /* iterator_struct */ {
struct symbol *iterator_break;
struct symbol *iterator_continue;
- struct statement *iterator_pre_statement;
struct expression *iterator_pre_condition;
struct statement *iterator_statement;
@@ -626,14 +626,12 @@ int show_statement(struct statement *stmt)
break;
case STMT_ITERATOR: {
- struct statement *pre_statement = stmt->iterator_pre_statement;
struct expression *pre_condition = stmt->iterator_pre_condition;
struct statement *statement = stmt->iterator_statement;
struct statement *post_statement = stmt->iterator_post_statement;
struct expression *post_condition = stmt->iterator_post_condition;
int val, loop_top = 0, loop_bottom = 0;
- show_statement(pre_statement);
if (pre_condition) {
if (pre_condition->type == EXPR_VALUE) {
if (!pre_condition->value) {
The for-statement needs a lot of fields in struct statement, much more than any other statement. This is due to the complexity of the for-statement. However part of this complexity can be removed by processing the 'pre-' statement separately from the loop. This is equivalent to transform a single-statement for-loop like: for (pre; cond; post) body into a compound statement like: pre; for (;cond; post) body; Note: The motivation for this change is to make struct statement smaller. The change also make further processing slightly simpler since we don't have to process the 'pre-' statement separately. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- ast-inspect.c | 2 -- compile-i386.c | 2 -- dissect.c | 1 - evaluate.c | 1 - expand.c | 1 - inline.c | 1 - linearize.c | 2 -- parse.c | 10 +++++++++- parse.h | 1 - show-parse.c | 2 -- 10 files changed, 9 insertions(+), 14 deletions(-)