Add #partial tag for enumerated arrays to prevent common errors using non-contiguous enumerations

This commit is contained in:
gingerBill
2019-12-27 16:55:32 +00:00
parent 80a32a8182
commit 5ec8dd166a
3 changed files with 46 additions and 4 deletions

View File

@@ -1759,6 +1759,17 @@ Ast *parse_operand(AstFile *f, bool lhs) {
break;
}
return original_type;
} else if (name.string == "partial") {
Ast *tag = ast_basic_directive(f, token, name.string);
Ast *original_type = parse_type(f);
Ast *type = unparen_expr(original_type);
switch (type->kind) {
case Ast_ArrayType: type->ArrayType.tag = tag; break;
default:
syntax_error(type, "Expected an enumerated array type after #%.*s, got %.*s", LIT(name.string), LIT(ast_strings[type->kind]));
break;
}
return original_type;
} else if (name.string == "bounds_check") {
Ast *operand = parse_expr(f, lhs);
operand->state_flags |= StateFlag_bounds_check;