harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b9583a7874367b33bc260eb7dd9178851dfe3cf1
parent 0d91bf3e43fc96ca6ab1116eb4fdcb6b64976693
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 19 Feb 2021 13:06:43 -0500

type_store: enum values can refer to other values

Diffstat:
Msrc/type_store.c | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -466,6 +466,8 @@ type_init_from_atype(struct type_store *store, type->size = storage->size; type->align = storage->size; + struct scope *scope = scope_push( + &store->check_context->scope, TR_CHECK); // TODO: Check for duplicates struct ast_enum_field *avalue = atype->_enum.values; struct type_enum_value **values = &type->_enum.values; @@ -495,9 +497,23 @@ type_init_from_atype(struct type_store *store, } else { value->uval = uimplicit++; } + + struct identifier name = { + .name = value->name, + .ns = NULL, + }; + // TODO: This leaks: + struct expression *vexpr = xcalloc(1, sizeof(struct expression)); + vexpr->type = EXPR_CONSTANT; + vexpr->result = storage; + vexpr->constant.uval = value->uval; + scope_insert(scope, O_CONST, &name, &name, storage, vexpr); + values = &value->next; avalue = avalue->next; } + scope_pop(&store->check_context->scope, TR_CHECK); + scope_free(scope); break; case TYPE_STORAGE_FUNCTION: type->size = SIZE_UNDEFINED;