From 5ec8dd166a9baab230c235e9f24684197efb5a86 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 27 Dec 2019 16:55:32 +0000 Subject: Add #partial tag for enumerated arrays to prevent common errors using non-contiguous enumerations --- src/parser.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/parser.cpp') 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; -- cgit v1.2.3