harec

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

commit fe1034a6e4b2cdfc00ac66a93518dbbaab6e2070
parent 576ed6c24483d8bc92564e8cdd0ec663ada38966
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 24 Jan 2021 13:14:01 -0500

typedefs: emit module dependencies

Diffstat:
Minclude/check.h | 6++++++
Msrc/check.c | 18+++++++++++++++++-
Msrc/gen.c | 2+-
Msrc/typedef.c | 7+++++++
4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/include/check.h b/include/check.h @@ -66,9 +66,15 @@ struct declarations { struct declarations *next; }; +struct imports { + struct identifier ident; + struct imports *next; +}; + struct unit { struct identifier *ns; struct declarations *declarations; + struct imports *imports; }; struct ast_expression; diff --git a/src/check.c b/src/check.c @@ -1709,7 +1709,7 @@ scan_declarations(struct context *ctx, const struct ast_decls *decls) static void load_import(struct ast_imports *import, - struct type_store *ts, struct scope *scope) + struct type_store *ts, struct scope *scope) { struct scope *mod = module_resolve(&import->ident, ts); @@ -1748,6 +1748,7 @@ check(struct type_store *ts, const struct ast_unit *aunit, struct unit *unit) struct scopes *subunit_scopes; struct scopes **next = &subunit_scopes; + struct imports **inext = &unit->imports; // First pass populates the type graph for (const struct ast_subunit *su = &aunit->subunits; @@ -1757,6 +1758,21 @@ check(struct type_store *ts, const struct ast_unit *aunit, struct unit *unit) for (struct ast_imports *imports = su->imports; imports; imports = imports->next) { load_import(imports, ts, ctx.scope); + + bool found = false; + for (struct imports *uimports = unit->imports; + uimports; uimports = uimports->next) { + if (identifier_eq(&uimports->ident, &imports->ident)) { + found = true; + break; + } + } + if (!found) { + struct imports *uimport = *inext = + xcalloc(1, sizeof(struct imports)); + identifier_dup(&uimport->ident, &imports->ident); + inext = &uimport->next; + } } ctx.store->check_context = &ctx; diff --git a/src/gen.c b/src/gen.c @@ -823,7 +823,7 @@ gen_expr_call(struct gen_context *ctx, qval_deref(&arg->value); } else { gen_temp(ctx, &arg->value, - qtype_for_type(ctx, carg->value->result, true), + qtype_for_type(ctx, carg->value->result, false), "arg.%d"); } gen_expression(ctx, carg->value, &arg->value); diff --git a/src/typedef.c b/src/typedef.c @@ -244,6 +244,13 @@ emit_decl_type(struct declaration *decl, FILE *out) void emit_typedefs(struct unit *unit, FILE *out) { + for (struct imports *imports = unit->imports; + imports; imports = imports->next) { + char *ident = identifier_unparse(&imports->ident); + fprintf(out, "use %s;\n", ident); + free(ident); + } + for (struct declarations *decls = unit->declarations; decls; decls = decls->next) { struct declaration *decl = decls->decl;