harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit d0afcc2a9e5eb3b122929a5fa1ff2716e3837b08
parent f828aa7072e345e6c64c4b8e6282f758fb99986f
Author: Armin Weigl <tb46305@gmail.com>
Date:   Sat,  3 Dec 2022 09:51:58 +0100

scan_const: extract from scan_decl

Signed-off-by: Armin Weigl <tb46305@gmail.com>

Diffstat:
Msrc/check.c | 35++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -3922,25 +3922,34 @@ resolve_type(struct context *ctx, struct incomplete_declaration *idecl) return ret; } +static struct incomplete_declaration * +scan_const(struct context *ctx, struct scope *imports, bool exported, + struct location loc, struct ast_global_decl *decl) +{ + + struct identifier with_ns = {0}; + mkident(ctx, &with_ns, &decl->ident, NULL); + struct incomplete_declaration *idecl = + incomplete_declaration_create(ctx, loc, + ctx->scope, &with_ns, &decl->ident); + idecl->type = IDECL_DECL; + idecl->decl = (struct ast_decl){ + .decl_type = AST_DECL_CONST, + .loc = loc, + .constant = *decl, + .exported = exported, + }; + idecl->imports = imports; + return idecl; +} + static void scan_decl(struct context *ctx, struct scope *imports, struct ast_decl *decl) { switch (decl->decl_type) { case AST_DECL_CONST: for (struct ast_global_decl *g = &decl->constant; g; g = g->next) { - struct identifier with_ns = {0}; - mkident(ctx, &with_ns, &g->ident, NULL); - struct incomplete_declaration *idecl = - incomplete_declaration_create(ctx, decl->loc, - ctx->scope, &with_ns, &g->ident); - idecl->type = IDECL_DECL; - idecl->decl = (struct ast_decl){ - .decl_type = AST_DECL_CONST, - .loc = decl->loc, - .constant = *g, - .exported = decl->exported, - }; - idecl->imports = imports; + scan_const(ctx, imports, decl->exported, decl->loc, g); } break; case AST_DECL_GLOBAL: