static void elab_context_walk_fn(ident_t name, int kind, void *context) { if (kind == T_PACKAGE) { const elab_ctx_t *ctx = (elab_ctx_t *)context; if (!elab_have_context(ctx->out, name)) { tree_t c = tree_new(T_USE); tree_set_ident(c, name); tree_set_ident2(c, all_i); elab_add_context(c, ctx); } } }
static void elab_use_clause(tree_t use, const elab_ctx_t *ctx) { tree_set_ident2(use, all_i); ident_t name = tree_ident(use); ident_t lname = ident_until(name, '.'); elab_ctx_t new_ctx = *ctx; new_ctx.library = elab_find_lib(lname, ctx); if (name == lname) lib_walk_index(new_ctx.library, elab_context_walk_fn, &new_ctx); else if (!elab_have_context(ctx->out, name)) elab_add_context(use, &new_ctx); }
static void elab_copy_context(tree_t src, const elab_ctx_t *ctx) { const int nsrc = tree_contexts(src); for (int i = 0; i < nsrc; i++) { tree_t c = tree_context(src, i); if (tree_kind(c) != T_USE) continue; tree_set_ident2(c, all_i); ident_t name = tree_ident(c); ident_t lname = ident_until(name, '.'); elab_ctx_t new_ctx = *ctx; new_ctx.library = elab_find_lib(lname, ctx); if (name == lname) lib_walk_index(new_ctx.library, elab_context_walk_fn, &new_ctx); else if (!elab_have_context(ctx->out, name)) elab_add_context(c, &new_ctx); } }