harec

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

commit 67b27b5da56cb0a30d366c375c0c0fab6d717f0b
parent 2dec667c8f427ada97856dd58e4463a0d1d6ed39
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Tue, 19 Jan 2021 11:21:09 -0500

scan: implement enum values

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

diff --git a/src/check.c b/src/check.c @@ -1406,6 +1406,44 @@ scan_type(struct context *ctx, const struct ast_type_decl *decl) struct identifier ident = {0}; mkident(ctx, &ident, &decl->ident); scope_insert(ctx->unit, O_TYPE, &ident, &decl->ident, type, NULL); + if (type->storage == TYPE_STORAGE_ENUM) { + for (struct type_enum_value *value = type->_enum.values; value; + value = value->next) { + struct ast_type atype = { + .loc = decl->type->loc, + .storage = TYPE_STORAGE_ALIAS, + .flags = 0, + .unwrap = false, + .alias = decl->ident, + }; + const struct type *alias = + type_store_lookup_atype(&ctx->store, &atype); + + struct expression *expr = + xcalloc(sizeof(struct expression), 1); + expr->type = EXPR_CONSTANT; + expr->result = alias; + if (type_is_signed(alias)) { + expr->constant.ival = value->ival; + } else { + expr->constant.uval = value->uval; + } + + struct identifier name_ns = { + .name = decl->ident.name, + .ns = decl->ident.ns, + }; + struct identifier name = { + .name = value->name, + .ns = &name_ns, + }; + struct identifier vident = { + .name = value->name, + .ns = &ident, + }; + scope_insert(ctx->unit, O_CONST, &name, &vident, alias, expr); + } + } trleave(TR_SCAN, NULL); }