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);
-// tl2str returns a mp_alloced string
+
+// 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);
ANN static ssize_t template_size(const Env env, struct tmpl_info* info) {
DECL_OB(const m_str, str, = tl2str(env, info->td->types))
- return tmpl_set(info, str) + tmpl_set(info, info->base->name) + 4;
+ const m_str base = type2str(env, info->base);
+ return tmpl_set(info, str) + tmpl_set(info, base) + 4;
+}
+
+ANEW ANN static Symbol _template_id(const Env env, struct tmpl_info *const info, const size_t sz) {
+ char name[sz];
+ template_name(info, name);
+ return insert_symbol(name);
}
ANEW ANN static Symbol template_id(const Env env, struct tmpl_info *const info) {
vector_init(&info->type);
vector_init(&info->size);
ssize_t sz = template_size(env, info);
- char name[sz];
- if(sz > GW_ERROR)
- template_name(info, name);
+ const Symbol sym = sz > GW_ERROR ? _template_id(env, info, sz) : NULL;
+ for(m_uint i = 0; i < vector_size(&info->type); ++i)
+ mp_free2(env->gwion->mp, vector_at(&info->size, i), (m_str)vector_at(&info->type, i));
vector_release(&info->type);
vector_release(&info->size);
- return sz > GW_ERROR ? insert_symbol(name) : NULL;
+ return sym;
}
ANN static m_bool template_match(ID_List base, Type_List call) {
return NULL;
}
-ANN static Func _find_template_match(const Env env, const Value v, const Exp_Call* exp) {
+ANN static Func find_tmpl(const Env env, const Value v, const Exp_Call* exp, const m_str tmpl_name) {
const Type_List types = exp->tmpl->call;
const Func former = env->func;
- DECL_OO(const m_str, tmpl_name, = tl2str(env, types))
const m_uint scope = env->scope->depth;
struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef,
.scope=scope, .flag=tflag_check };
(void)env_push(env, v->from->owner_class, v->from->owner);
const Func m_func = !is_fptr(env->gwion, v->type) ?
func_match(env, &ra) :fptr_match(env, &ra);
- free_mstr(env->gwion->mp, tmpl_name);
if(es.run)
envset_pop(&es, v->from->owner_class);
env_pop(env, scope);
return m_func;
}
+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))
+ const Func f = find_tmpl(env, v, exp, tmpl_name);
+ free_mstr(env->gwion->mp, tmpl_name);
+ return f;
+}
+
ANN static inline m_bool check_call(const Env env, const Exp_Call* exp) {
const ae_exp_t et = exp->func->exp_type;
if(et != ae_exp_primary && et != ae_exp_dot && et != ae_exp_cast)
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))
- text_add(&info->text, t->name);
+ 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))