}
ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f, const Value overload) {
- const m_str func_name = s_name(f->base->xid);
- const Func func = scan_new_func(env, f, func_name);
+ const m_str name = s_name(f->base->xid);
+ const Func func = scan_new_func(env, f, name);
const Value value = func_value(env, func, overload);
SET_FLAG(value, checked | ae_flag_template);
SET_FLAG(value->type, func); // the only types with func flag, name could be better
}
m_bool ret = compat_func(ff->def, f);
if(ret > 0) {
- const Symbol sym = func_symbol(env, env->curr->name, func_name,
+ const Symbol sym = func_symbol(env, env->curr->name, name,
"template", ff->vt_index);
nspc_add_value(env->curr, sym, value);
if(!overload) {
}
} while(type && (type = type->e->parent) && (nspc = type->nspc));
--i;
- const Symbol sym = func_symbol(env, env->curr->name, func_name, "template", i);
+ const Symbol sym = func_symbol(env, env->curr->name, name, "template", i);
nspc_add_value(env->curr, sym, value);
if(!overload) {
func->vt_index = i;
}
ANN static m_str func_tmpl_name(const Env env, const Func_Def f) {
- const m_str func_name = s_name(f->base->xid);
+ const m_str name = s_name(f->base->xid);
struct Vector_ v;
ID_List id = f->tmpl->list;
m_uint tlen = 0;
}
tmpl_name[tlen+1] = '\0';
vector_release(&v);
- const Symbol sym = func_symbol(env, env->curr->name, func_name, tmpl_name, (m_uint)f->tmpl->base);
+ const Symbol sym = func_symbol(env, env->curr->name, name, tmpl_name, (m_uint)f->tmpl->base);
return s_name(sym);
}
ANN2(1,2,4) static Value func_create(const Env env, const Func_Def f,
- const Value overload, const m_str func_name) {
- const Func func = scan_new_func(env, f, func_name);
+ const Value overload, const m_str name) {
+ const Func func = scan_new_func(env, f, name);
nspc_add_func(env->curr, insert_symbol(func->name), func);
const Value v = func_value(env, func, overload);
scan2_func_def_flag(env, f);
return v;
}
+
+ANN static m_str template_helper(const Env env, const Func_Def f) {
+ const m_str name = f->base->func ? f->base->func->name : func_tmpl_name(env, f);
+ if(!name)
+ return(m_str)GW_ERROR;
+ const Func func = nspc_lookup_func1(env->curr, insert_symbol(name));
+ if(func) {
+ if(GET_FLAG(func, member))
+ f->stack_depth += SZ_INT;
+ if(GET_FLAG(func->def, variadic))
+ f->stack_depth += SZ_INT;
+ f->base->ret_type = known_type(env, f->base->td);
+ return (m_str)(m_uint)((f->base->args && f->base->args->type) ? scan2_args(env, f) : GW_OK);
+ }
+ return name;
+}
+
+ANN2(1,2) static m_str func_name(const Env env, const Func_Def f, const Value v) {
+ if(!f->tmpl) {
+ const Symbol sym = func_symbol(env, env->curr->name, s_name(f->base->xid), NULL, v ? ++v->offset : 0);
+ return s_name(sym);
+ }
+ return template_helper(env, f);
+}
+
ANN m_bool scan2_func_def(const Env env, const Func_Def f) {
- Value value = NULL;
- f->stack_depth = 0;
- m_uint scope = env->scope->depth;
- if(GET_FLAG(f, global))
- scope = env_push_global(env);
+ const m_uint scope = !GET_FLAG(f, global) ? env->scope->depth : env_push_global(env);
const Value overload = nspc_lookup_value0(env->curr, f->base->xid);
const Value res = nspc_lookup_value1(env->global_nspc, f->base->xid);
- m_str func_name = s_name(f->base->xid);
if(res)
- ERR_B(f->pos, "'%s' already declared as type", func_name)
+ ERR_B(f->pos, "'%s' already declared as type", s_name(f->base->xid))
+ f->stack_depth = 0;
if(overload)
CHECK_BB(scan2_func_def_overload(env, f, overload))
if(tmpl_base(f->tmpl))
return scan2_func_def_template(env, f, overload);
- if(!f->tmpl) {
- const Symbol sym = func_symbol(env, env->curr->name, func_name, NULL, overload ? ++overload->offset : 0);
- func_name = s_name(sym);
- } else {
- if(f->base->func)
- func_name = f->base->func->name;
- else
- CHECK_OB((func_name = func_tmpl_name(env, f)))
- const Func func = nspc_lookup_func1(env->curr, insert_symbol(func_name));
- if(func) {
- if(GET_FLAG(func, member))
- f->stack_depth += SZ_INT;
- if(GET_FLAG(func->def, variadic))
- f->stack_depth += SZ_INT;
- f->base->ret_type = known_type(env, f->base->td);
- return (f->base->args && f->base->args->type) ? scan2_args(env, f) : GW_OK;
- }
- }
+ const m_str name = func_name(env, f, overload);
+ if((m_int)name <= GW_OK)
+ return (m_bool)(m_uint)name;
+// scan2 prelude
const Func base = get_func(env, f);
- if(!base) {
- CHECK_OB((value = func_create(env, f, overload, func_name)))
- } else {
+ if(!base)
+ CHECK_OB(func_create(env, f, overload, name))
+ else
f->base->func = base;
-}
+// body
if(f->base->args)
CHECK_BB(scan2_args(env, f))
if(!GET_FLAG(f, builtin) && f->d.code->d.stmt_code.stmt_list)
CHECK_BB(scan2_func_def_code(env, f))
+// gpop
+ if(GET_FLAG(f, global))
+ env_pop(env, scope);
+
if(!base) {
if(GET_FLAG(f, op))
CHECK_BB(scan2_func_def_op(env, f))
- SET_FLAG(value, checked);
+ SET_FLAG(f->base->func->value_ref, checked);
}
- if(GET_FLAG(f, global))
- env_pop(env, scope);
return GW_OK;
}
ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) {
const Type t = cdef->base.type->e->parent->array_depth ?
array_base(cdef->base.type->e->parent) : cdef->base.type->e->parent;
- if(!GET_FLAG(t, scan2) && GET_FLAG(cdef->base.ext, typedef)) {
+ if(!GET_FLAG(t, scan2) && GET_FLAG(cdef->base.ext, typedef))
CHECK_BB(scan2_class_def(env, t->e->def))
- }
if(cdef->base.ext->array)
CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp))
return GW_OK;