Implement #complete switch by default, replace with #partial switch #511

This commit is contained in:
gingerBill
2019-12-22 12:03:48 +00:00
parent 4593730632
commit d1c9fd4e01
19 changed files with 263 additions and 227 deletions

View File

@@ -766,6 +766,7 @@ Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) {
result->SwitchStmt.init = init;
result->SwitchStmt.tag = tag;
result->SwitchStmt.body = body;
result->SwitchStmt.partial = false;
return result;
}
@@ -775,6 +776,7 @@ Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) {
result->TypeSwitchStmt.token = token;
result->TypeSwitchStmt.tag = tag;
result->TypeSwitchStmt.body = body;
result->TypeSwitchStmt.partial = false;
return result;
}
@@ -4060,16 +4062,32 @@ Ast *parse_stmt(AstFile *f) {
s = parse_stmt(f);
switch (s->kind) {
case Ast_SwitchStmt:
s->SwitchStmt.complete = true;
s->SwitchStmt.partial = false;
syntax_warning(token, "#complete is now the default and has been replaced with its opposite: #partial");
break;
case Ast_TypeSwitchStmt:
s->TypeSwitchStmt.complete = true;
s->TypeSwitchStmt.partial = false;
syntax_warning(token, "#complete is now the default and has been replaced with its opposite: #partial");
break;
default:
syntax_error(token, "#complete can only be applied to a switch statement");
break;
}
return s;
} else if (tag == "partial") {
s = parse_stmt(f);
switch (s->kind) {
case Ast_SwitchStmt:
s->SwitchStmt.partial = true;
break;
case Ast_TypeSwitchStmt:
s->TypeSwitchStmt.partial = true;
break;
default:
syntax_error(token, "#partial can only be applied to a switch statement");
break;
}
return s;
} else if (tag == "assert") {
Ast *t = ast_basic_directive(f, hash_token, tag);
return ast_expr_stmt(f, parse_call_expr(f, t));