aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-12-27 16:55:32 +0000
committergingerBill <bill@gingerbill.org>2019-12-27 16:55:32 +0000
commit5ec8dd166a9baab230c235e9f24684197efb5a86 (patch)
tree526a7aed6ce337c5077a48e924b4eaafe7d96b33 /src/parser.cpp
parent80a32a8182545b71f184e2889414e01ed27cc9da (diff)
Add #partial tag for enumerated arrays to prevent common errors using non-contiguous enumerations
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 0e9b20e52..5ba18d4a1 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -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;