diff options
| author | gingerBill <bill@gingerbill.org> | 2018-09-11 12:10:32 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-09-11 12:10:32 +0100 |
| commit | f1e1814ff91ab0753891536442797ff8544e6b6c (patch) | |
| tree | 52572629c86ee40763f3eb7346a478f5bacad31d /src/check_type.cpp | |
| parent | b468cf141bdec09369ff8d2c28097ec7ead3c2f6 (diff) | |
Syntactic sugar for anonymous enum within a bit set
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 33b90288f..993db6ff1 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -931,7 +931,7 @@ bool is_type_valid_bit_set_range(Type *t) { return false; } -void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) { +void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *node) { ast_node(bs, BitSetType, node); GB_ASSERT(type->kind == Type_BitSet); @@ -1045,6 +1045,24 @@ void check_bit_set_type(CheckerContext *c, Type *type, Ast *node) { } else { Type *elem = check_type_expr(c, bs->elem, nullptr); + #if 1 + if (named_type != nullptr && named_type->kind == Type_Named && + elem->kind == Type_Enum) { + // NOTE(bill): Anonymous enumeration + + String prefix = named_type->Named.name; + String enum_name = concatenate_strings(heap_allocator(), prefix, str_lit(".enum")); + + Token token = make_token_ident(enum_name); + + Entity *e = alloc_entity_type_name(nullptr, token, nullptr, EntityState_Resolved); + Type *named = alloc_type_named(enum_name, elem, e); + e->type = named; + e->TypeName.is_type_alias = true; + elem = named; + } + #endif + type->BitSet.elem = elem; if (!is_type_valid_bit_set_elem(elem)) { error(bs->elem, "Expected an enum type for a bit_set"); @@ -2436,7 +2454,7 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t case_ast_node(bs, BitSetType, e); *type = alloc_type_bit_set(); set_base_type(named_type, *type); - check_bit_set_type(ctx, *type, e); + check_bit_set_type(ctx, *type, named_type, e); return true; case_end; |