From bc3c8e538ec3a8e4132e88683c323eaba8a6e4db Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 3 Oct 2019 00:38:58 +0200 Subject: [PATCH] :art: Clean xxx_func_def --- src/parse/check.c | 46 +++++++++++++++++++++++++++------------------- src/parse/scan1.c | 17 +++++++++++------ src/parse/scan2.c | 15 ++++++++++----- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/parse/check.c b/src/parse/check.c index f431d206..431a4acc 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1327,9 +1327,34 @@ ANN static Value set_variadic(const Env env) { return variadic; } +ANN m_bool _check_func_def(const Env env, const Func_Def fdef) { + if(fdef->base->args) + CHECK_BB(check_func_args(env, fdef->base->args)) + else + UNSET_FLAG(fdef->base->func, pure); + const Value variadic = GET_FLAG(fdef, variadic) ? set_variadic(env) : NULL; + if(!GET_FLAG(fdef, builtin)) { + if(fdef->d.code) + CHECK_BB(check_stmt_code(env, &fdef->d.code->d.stmt_code)) + } else + fdef->base->func->code->stack_depth = fdef->stack_depth; + if(variadic) + REM_REF(variadic, env->gwion) + return GW_OK; +} + +ANN m_bool _check_func_def_tmpl(const Env env, const Func_Def fdef) { + if(fdef->base->tmpl) + CHECK_BB(template_push_types(env, fdef->base->tmpl)) + const m_bool ret = _check_func_def(env, fdef); + if(fdef->base->tmpl) + nspc_pop_type(env->gwion->mp, env->curr); + return ret; +} + ANN m_bool check_func_def(const Env env, const Func_Def fdef) { const Func func = get_func(env, fdef); - m_bool ret = GW_OK; + assert(func == fdef->base->func); if(tmpl_base(fdef->base->tmpl)) return env->class_def ? check_parent_match(env, fdef) : 1; if(fdef->base->td && !fdef->base->td->xid) { // tmpl ? @@ -1344,24 +1369,7 @@ ANN m_bool check_func_def(const Env env, const Func_Def fdef) { env->func = func; ++env->scope->depth; nspc_push_value(env->gwion->mp, env->curr); - if(fdef->base->tmpl) - CHECK_BB(template_push_types(env, fdef->base->tmpl)) - if(!fdef->base->args) - UNSET_FLAG(fdef->base->func, pure); - else - ret = check_func_args(env, fdef->base->args); - if(ret > 0) { - const Value variadic = GET_FLAG(fdef, variadic) ? set_variadic(env) : NULL; - if(!GET_FLAG(fdef, builtin) && fdef->d.code && - check_stmt_code(env, &fdef->d.code->d.stmt_code) < 0) - ret = GW_ERROR; - if(variadic) - REM_REF(variadic, env->gwion) - if(GET_FLAG(fdef, builtin)) - func->code->stack_depth = fdef->stack_depth; - } - if(fdef->base->tmpl) - nspc_pop_type(env->gwion->mp, env->curr); + const m_bool ret = _check_func_def_tmpl(env, fdef); nspc_pop_value(env->gwion->mp, env->curr); --env->scope->depth; env->func = former; diff --git a/src/parse/scan1.c b/src/parse/scan1.c index e96957ff..6bf8923e 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -397,6 +397,15 @@ ANN m_bool scan1_fdef(const Env env, const Func_Def fdef) { return GW_OK; } +ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) { + if(fdef->base->tmpl) + CHECK_BB(template_push_types(env, fdef->base->tmpl)) + const m_bool ret = scan1_fdef(env, fdef); + if(fdef->base->tmpl) + nspc_pop_type(env->gwion->mp, env->curr); + return ret; +} + ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { if(fdef->base->td) CHECK_BB(env_storage(env, fdef->flag, td_pos(fdef->base->td))) @@ -405,13 +414,9 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { struct Func_ fake = { .name=s_name(fdef->base->xid) }, *const former = env->func; env->func = &fake; ++env->scope->depth; - if(fdef->base->tmpl) - CHECK_BB(template_push_types(env, fdef->base->tmpl)) - const m_bool ret = scan1_fdef(env, fdef); - if(fdef->base->tmpl) - nspc_pop_type(env->gwion->mp, env->curr); - env->func = former; + const m_bool ret = _scan1_func_def(env, fdef); --env->scope->depth; + env->func = former; return ret; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 78625b1f..9056c245 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -522,12 +522,8 @@ ANN2(1,2) m_bool scan2_fdef(const Env env, const Func_Def f, const Value overloa return GW_OK; } -ANN m_bool scan2_func_def(const Env env, const Func_Def f) { - const m_uint scope = !GET_FLAG(f, global) ? env->scope->depth : env_push_global(env); +ANN m_bool _scan2_func_def(const Env env, const Func_Def f) { const Value overload = nspc_lookup_value0(env->curr, f->base->xid); - f->stack_depth = (env->class_def && !GET_FLAG(f, static) && !GET_FLAG(f, global)) ? SZ_INT : 0; - if(GET_FLAG(f, variadic)) - f->stack_depth += SZ_INT; if(overload) CHECK_BB(scan2_func_def_overload(env, f, overload)) if(f->base->tmpl) @@ -535,6 +531,15 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { const m_bool ret = (!tmpl_base(f->base->tmpl) ? scan2_fdef : scan2_func_def_template)(env, f, overload); if(f->base->tmpl) nspc_pop_type(env->gwion->mp, env->curr); + return ret; +} + +ANN m_bool scan2_func_def(const Env env, const Func_Def f) { + const m_uint scope = !GET_FLAG(f, global) ? env->scope->depth : env_push_global(env); + f->stack_depth = (env->class_def && !GET_FLAG(f, static) && !GET_FLAG(f, global)) ? SZ_INT : 0; + if(GET_FLAG(f, variadic)) + f->stack_depth += SZ_INT; + const m_bool ret = _scan2_func_def(env, f); if(GET_FLAG(f, global)) env_pop(env, scope); return ret; -- 2.43.0