aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.c
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-01-27 17:43:42 +0000
committerGinger Bill <bill@gingerbill.org>2017-01-27 17:43:42 +0000
commit92453369c5558feaaaa116fbc54968b087e1aeab (patch)
treea00501fdc52f69c7dd7c415e103b9b13d51e6ad5 /src/check_stmt.c
parent832009f33acc573d44dd9dfb470ad8fef72216ff (diff)
Remove while loop and readd c-style for loops i.e. all loops are just `for`
Diffstat (limited to 'src/check_stmt.c')
-rw-r--r--src/check_stmt.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/check_stmt.c b/src/check_stmt.c
index fd8e22908..3a1fdf023 100644
--- a/src/check_stmt.c
+++ b/src/check_stmt.c
@@ -127,13 +127,13 @@ bool check_is_terminating(AstNode *node) {
}
case_end;
- case_ast_node(ws, WhileStmt, node);
- if (ws->cond != NULL && !check_has_break(ws->body, true)) {
- return check_is_terminating(ws->body);
+ case_ast_node(fs, ForStmt, node);
+ if (!check_has_break(fs->body, true)) {
+ return check_is_terminating(fs->body);
}
case_end;
- case_ast_node(rs, ForStmt, node);
+ case_ast_node(rs, RangeStmt, node);
if (!check_has_break(rs->body, true)) {
return check_is_terminating(rs->body);
}
@@ -566,27 +566,33 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
}
case_end;
- case_ast_node(ws, WhileStmt, node);
+ case_ast_node(fs, ForStmt, node);
u32 new_flags = mod_flags | Stmt_BreakAllowed | Stmt_ContinueAllowed;
check_open_scope(c, node);
- if (ws->init != NULL) {
- check_stmt(c, ws->init, 0);
+ if (fs->init != NULL) {
+ check_stmt(c, fs->init, 0);
}
- if (ws->cond) {
- Operand operand = {Addressing_Invalid};
- check_expr(c, &operand, ws->cond);
- if (operand.mode != Addressing_Invalid &&
- !is_type_boolean(operand.type)) {
- error_node(ws->cond, "Non-boolean condition in `while` statement");
+ if (fs->cond != NULL) {
+ Operand o = {Addressing_Invalid};
+ check_expr(c, &o, fs->cond);
+ if (o.mode != Addressing_Invalid && !is_type_boolean(o.type)) {
+ error_node(fs->cond, "Non-boolean condition in `for` statement");
+ }
+ }
+ if (fs->post != NULL) {
+ check_stmt(c, fs->post, 0);
+
+ if (fs->post->kind != AstNode_AssignStmt) {
+ error_node(fs->post, "`for` statement post statement must be an assignment");
}
}
- check_stmt(c, ws->body, new_flags);
+ check_stmt(c, fs->body, new_flags);
check_close_scope(c);
case_end;
- case_ast_node(rs, ForStmt, node);
+ case_ast_node(rs, RangeStmt, node);
u32 new_flags = mod_flags | Stmt_BreakAllowed | Stmt_ContinueAllowed;
check_open_scope(c, node);