commit 2d9dc502568d9fd07e87713fa3c8b7d05e294e8d
parent 3a7547374cad9be722171c9f51ecf1889565559f
Author: Lou Woell <lou.woell@posteo.de>
Date:   Wed, 10 Sep 2025 18:29:35 +0200

resolve wildcard imports

Diffstat:
Mcmd/harehelper/helper.ha | 2+-
Mcmd/harehelper/resolve.ha | 27+++++++++++++++++++++------
Mcmd/harehelper/util.ha | 7+++++++
3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/cmd/harehelper/helper.ha b/cmd/harehelper/helper.ha @@ -85,7 +85,7 @@ export fn main () void = { case let c: (str, *getopt::command) => switch (c.0) { case "resolve" => - resolve(*c.1); + resolve(*c.1, &ctx); case "list" => list(*c.1, &ctx); case "list-modules" => diff --git a/cmd/harehelper/resolve.ha b/cmd/harehelper/resolve.ha @@ -18,12 +18,13 @@ use fs; use getopt; use hare::ast; use hare::lex; +use hare::module; use hare::parse; use hare::unparse; use io; use os; -fn resolve(cmd: getopt::command) void = { +fn resolve(cmd: getopt::command, ctx: *module::context) void = { if(len(cmd.args) == 0) fmt::fatal("Expected Argument"); @@ -41,7 +42,7 @@ fn resolve(cmd: getopt::command) void = { return void; }; - match (find_uid(id, file)) { + match (find_uid(ctx, id, file)) { case let id_exp: ast::ident => printident(id_exp); ast::ident_free(id_exp); @@ -65,7 +66,11 @@ fn list_imports (path: str) []ast::import = { return parse::imports(&lexer)!; }; -fn find_uid (id: ast::ident, path: str) (void | ast::ident) = { +fn find_uid ( + ctx: *module::context, + id: ast::ident, + path: str +) (void | ast::ident) = { let imports = list_imports(path); defer ast::imports_finish(imports); @@ -81,7 +86,8 @@ fn find_uid (id: ast::ident, path: str) (void | ast::ident) = { case let a: ast::import_alias => if (ns[0] == a) check = true; case let members: ast::import_members => - // if len(id) > 1 -> id is not an interned symbol. + // if len(id) > 1 -> id is not an interned + // symbol. if (len(id) > 1) continue; for (let s .. members) { check = (s == id[0]); @@ -91,8 +97,17 @@ fn find_uid (id: ast::ident, path: str) (void | ast::ident) = { }; }; case ast::import_wildcard => - // todo check all symbols; - void; + if (len(id) > 1) continue; + let list = list_symbols(ctx, ident); + defer idents_finish(list); + + for (let s .. list) { + check = ast::ident_eq(s, id); + if (check){ + interned = true; + break; + }; + }; case void => if (ast::ident_eq(ns, ident_last(ident))) check = true; diff --git a/cmd/harehelper/util.ha b/cmd/harehelper/util.ha @@ -54,3 +54,10 @@ fn scan(path: str) ([]ast::decl | parse::error) = { ast::imports_finish(su.imports); return su.decls; }; + +fn idents_finish (ids: []ast::ident) void = { + for (let s .. ids) { + ast::ident_free(s); + }; + free(ids); +};