summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@l3000.localdomain>2011-03-24 21:01:57 -0400
committerSøren Sandmann Pedersen <ssp@l3000.localdomain>2011-03-24 21:01:57 -0400
commitf7b84bdea5ff350b776c7f800297931610ae29bf (patch)
tree0dc9719e839fcb4e3e926186933fa5e754ea6197 /ast.c
parentd9bdad74e2f8404785568f9dd511701abfb71292 (diff)
Consolidate the three loop types into one ast node.
This required the ability to jump into the middle of a loop - otherwise "do/while" couldn't be expressed as a regular while loop.
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c64
1 files changed, 13 insertions, 51 deletions
diff --git a/ast.c b/ast.c
index 7218577..2d57f9f 100644
--- a/ast.c
+++ b/ast.c
@@ -42,41 +42,17 @@ statement_new (ast_statement_type_t statement_type)
}
ast_statement_t *
-ast_statement_new_while (ast_expression_t *condition,
- ast_statement_t *body)
+ast_statement_new_loop (ast_statement_t *init,
+ ast_expression_t *condition,
+ ast_statement_t *body,
+ ast_statement_t *increment)
{
- ast_statement_t *statement = statement_new (AST_WHILE_STATEMENT);
+ ast_statement_t *statement = statement_new (AST_LOOP_STATEMENT);
- statement->while_.condition = condition;
- statement->while_.body = body;
-
- return statement;
-}
-
-ast_statement_t *
-ast_statement_new_for (ast_expression_t *first,
- ast_expression_t *second,
- ast_expression_t *third,
- ast_statement_t *body)
-{
- ast_statement_t *statement = statement_new (AST_FOR_STATEMENT);
-
- statement->for_.first = first;
- statement->for_.second = second;
- statement->for_.third = third;
- statement->for_.body = body;
-
- return statement;
-}
-
-ast_statement_t *
-ast_statement_new_do (ast_statement_t *body,
- ast_expression_t *condition)
-{
- ast_statement_t *statement = statement_new (AST_DO_STATEMENT);
-
- statement->do_.body = body;
- statement->do_.condition = condition;
+ statement->loop.init = init;
+ statement->loop.condition = condition;
+ statement->loop.body = body;
+ statement->loop.increment = increment;
return statement;
}
@@ -726,25 +702,11 @@ ast_enclosing_class (ast_t *ast)
ast, AST_DEFINITION, AST_CLASS_DEFINITION);
}
-ast_while_statement_t *
-ast_enclosing_while (ast_t *ast)
-{
- return (ast_while_statement_t *)enclosing (
- ast, AST_STATEMENT, AST_WHILE_STATEMENT);
-}
-
-ast_for_statement_t *
-ast_enclosing_for (ast_t *ast)
-{
- return (ast_for_statement_t *)enclosing (
- ast, AST_STATEMENT, AST_FOR_STATEMENT);
-}
-
-ast_do_statement_t *
-ast_enclosing_do (ast_t *ast)
+ast_loop_statement_t *
+ast_enclosing_loop (ast_t *ast)
{
- return (ast_do_statement_t *)enclosing (
- ast, AST_STATEMENT, AST_DO_STATEMENT);
+ return (ast_loop_statement_t *)enclosing (
+ ast, AST_STATEMENT, AST_LOOP_STATEMENT);
}
ast_switch_statement_t *