From: Jérémie Astor Date: Wed, 16 Dec 2020 01:09:55 +0000 (+0100) Subject: :art: Improve xxx2xxx consistency X-Git-Tag: nightly~1105^2~3 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=718c53c2ca1a4c6dca74e8fe754af2d5828d86c5;p=gwion.git :art: Improve xxx2xxx consistency --- diff --git a/include/env/env.h b/include/env/env.h index 67c26ddc..9d73be48 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -35,11 +35,6 @@ ANN void env_pop(const Env, const m_uint); ANN Map env_label(const Env); ANN Type scan_type(const Env, const Type, Type_Decl*); ANN Value mk_class(const Env env, const Type base); - -// those functions return a mp_alloced string -ANEW ANN m_str tl2str(const Env, const Type_List); // in type_decl.c -ANEW ANN m_str type2str(const Env env, const Type t); - ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def); ANN Type known_type(const Env env, Type_Decl*); ANN Type prim_ref(const Env env, const Type t, const Type_Decl* td); diff --git a/include/import/checker.h b/include/import/checker.h index 3b81b40c..0e02d006 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -47,14 +47,19 @@ typedef struct OperCK { // name_checker ? ANN void func_checker_clean(const Gwi gwi, struct ImportCK *ck); ANN m_bool check_typename_def(const Gwi gwi, struct ImportCK *ck); -ANN Symbol str2sym(const Gwion gwi, const m_str path, const loc_t pos); -ANN ID_List str2symlist(const Gwion gwi, const m_str path, const loc_t); +ANN Symbol str2sym(const Gwion, const m_str, const loc_t); +ANN ID_List str2symlist(const Gwion, const m_str, const loc_t); ANN Var_Decl str2var(const Gwion, const m_str, const loc_t); ANN Var_Decl_List str2varlist(const Gwion, const m_str, const loc_t); ANN Type_Decl* str2td(const Gwion, const m_str, const loc_t); ANN Type str2type(const Gwion, const m_str, const loc_t); + +// those functions return a mp_alloced string +ANEW ANN m_str tl2str(const Gwion, const Type_List, const loc_t); +ANEW ANN m_str type2str(const Gwion, const Type, const loc_t); + ANN static inline Type_Decl* type2td(const Gwion gwion, const Type t, const loc_t pos) { - const m_str str = type2str(gwion->env, t); + const m_str str = type2str(gwion, t, pos); Type_Decl *td = str2td(gwion, str, pos); free_mstr(gwion->mp, str); return td; diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 9fea976f..dfdd6456 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -218,6 +218,45 @@ ANN Type str2type(const Gwion gwion, const m_str str, const loc_t pos) { return t; } +struct td_info { + Type_List tl; + GwText text; +}; + +ANN static void td_fullname(const Env env, GwText *text, const Type t) { + const Type owner = t->info->owner_class; + if(owner) { + td_fullname(env, text, owner); + text_add(text, "."); + } + text_add(text, t->name); +} + +ANN static m_bool td_info_run(const Env env, struct td_info* info) { + Type_List tl = info->tl; + do { + DECL_OB(const Type, t, = known_type(env, tl->td)) + td_fullname(env, &info->text, t); + if(tl->next) + text_add(&info->text, ","); + } while((tl = tl->next)); + return GW_OK; +} + +ANEW ANN m_str type2str(const Gwion gwion, const Type t, const loc_t pos NUSED) { + GwText text = { .mp=gwion->mp }; + if(t->info->owner_class) + td_fullname(gwion->env, &text, t->info->owner_class); + text_add(&text, t->name); + return text.str; +} + +ANEW ANN m_str tl2str(const Gwion gwion, const Type_List tl, const loc_t pos NUSED) { + struct td_info info = { .tl=tl, { .mp=gwion->mp} }; + CHECK_BO(td_info_run(gwion->env, &info)) + return info.text.str; +} + ANN static inline m_bool ac_finish(const Gwion gwion, const struct AC *ac) { if(*ac->str == ']') return GW_OK; diff --git a/src/lib/instr.c b/src/lib/instr.c index 0fe1eb3b..c80153a8 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -58,7 +58,8 @@ INSTR(GTmpl) { const m_str name = f->name; const Emitter emit = shred->info->vm->gwion->emit; emit->env->name = "runtime"; - m_str tmpl_name = tl2str(emit->env, dt->tl); + struct loc_t_ pos = {}; + m_str tmpl_name = tl2str(emit->gwion, dt->tl, &pos); for(m_uint i = 0 ; i <= f->value_ref->from->offset; ++i) { const Symbol sym = func_symbol(emit->env, f->value_ref->from->owner->name, name, tmpl_name, i); diff --git a/src/lib/tmpl_info.c b/src/lib/tmpl_info.c index 535d462d..43d0f4cc 100644 --- a/src/lib/tmpl_info.c +++ b/src/lib/tmpl_info.c @@ -7,6 +7,9 @@ #include "operator.h" #include "traverse.h" #include "parse.h" +#include "object.h" +#include "instr.h" +#include "import.h" #include "tmpl_info.h" ANN static inline m_str tmpl_get(struct tmpl_info* info, m_str str) { @@ -39,9 +42,9 @@ ANN static inline size_t tmpl_set(struct tmpl_info* info, const m_str str) { } ANN static ssize_t template_size(const Env env, struct tmpl_info* info) { - DECL_OB(const m_str, str, = tl2str(env, info->td->types)) + DECL_OB(const m_str, str, = tl2str(env->gwion, info->td->types, info->td->pos)) const size_t tmpl_sz = tmpl_set(info, str); - const m_str base = type2str(env, info->base); + const m_str base = type2str(env->gwion, info->base, info->td->pos); return tmpl_sz + tmpl_set(info, base) + 4; } diff --git a/src/parse/check.c b/src/parse/check.c index e1e5a103..f25ddaf0 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -772,7 +772,7 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix* post) { } ANN static m_bool predefined_call(const Env env, const Type t, const loc_t pos) { - const m_str str = tl2str(env, t->info->func->def->base->tmpl->call); + const m_str str = tl2str(env->gwion, t->info->func->def->base->tmpl->call, pos); env_err(env, pos, _("Type '%s' has '%s' as pre-defined types."), t->name, str); free_mstr(env->gwion->mp, str); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 1d4bf397..ecddf952 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -126,7 +126,7 @@ ANN static Func find_tmpl(const Env env, const Value v, const Exp_Call* exp, con } ANN static Func _find_template_match(const Env env, const Value v, const Exp_Call* exp) { - DECL_OO(const m_str, tmpl_name, = tl2str(env, exp->tmpl->call)) + DECL_OO(const m_str, tmpl_name, = tl2str(env->gwion, exp->tmpl->call, exp->func->pos)) const Func f = find_tmpl(env, v, exp, tmpl_name); free_mstr(env->gwion->mp, tmpl_name); return f; diff --git a/src/parse/template.c b/src/parse/template.c index 3d71630b..45dbeced 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -8,6 +8,9 @@ #include "parse.h" #include "gwion.h" #include "operator.h" +#include "instr.h" +#include "object.h" +#include "import.h" ANN static m_bool push_types(const Env env, const Tmpl *tmpl) { ID_List list = tmpl->list; @@ -51,7 +54,7 @@ ANN Tmpl* mk_tmpl(const Env env, const Tmpl *tm, const Type_List types) { } static ANN Type scan_func(const Env env, const Type t, const Type_Decl* td) { - DECL_OO(const m_str, tl_name, = tl2str(env, td->types)) + DECL_OO(const m_str, tl_name, = tl2str(env->gwion, td->types, td->pos)) const Symbol sym = func_symbol(env, t->info->owner->name, t->info->func->name, tl_name, 0); free_mstr(env->gwion->mp, tl_name); const Type base_type = nspc_lookup_type1(t->info->owner, sym); diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index a024e196..14da7e1b 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -28,45 +28,6 @@ ANN static Type resolve(const Env env, Type_Decl* td) { return !td->array ? ret : array_type(env, ret, td->array->depth); } -struct td_info { - Type_List tl; - GwText text; -}; - -ANN static void td_fullname(const Env env, GwText *text, const Type t) { - const Type owner = t->info->owner_class; - if(owner) { - td_fullname(env, text, owner); - text_add(text, "."); - } - text_add(text, t->name); -} - -ANN static m_bool td_info_run(const Env env, struct td_info* info) { - Type_List tl = info->tl; - do { - DECL_OB(const Type, t, = known_type(env, tl->td)) - td_fullname(env, &info->text, t); - if(tl->next) - text_add(&info->text, ","); - } while((tl = tl->next)); - return GW_OK; -} - -ANEW ANN m_str type2str(const Env env, const Type t) { - GwText text = { .mp=env->gwion->mp }; - if(t->info->owner_class) - td_fullname(env, &text, t->info->owner_class); - text_add(&text, t->name); - return text.str; -} - -ANEW ANN m_str tl2str(const Env env, Type_List tl) { - struct td_info info = { .tl=tl, { .mp=env->gwion->mp} }; - CHECK_BO(td_info_run(env, &info)) - return info.text.str; -} - ANN static inline void* type_unknown(const Env env, const Type_Decl* td) { env_err(env, td->pos, _("unknown type '%s'"), s_name(td->xid)); return NULL;