From 38ae1e228f3f3e5bcd774da2f54f3e8f40c3aabf Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 24 Jul 2019 01:50:38 +0200 Subject: [PATCH] :shirt: More clean --- src/parse/check.c | 4 ++-- src/parse/scan0.c | 3 +++ src/parse/scan1.c | 11 ++++++----- src/parse/scan2.c | 9 ++------- src/parse/traverse.c | 13 ++++++++----- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/parse/check.c b/src/parse/check.c index 6cfa9fe9..fa986be0 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -105,7 +105,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { if(!decl->type) ERR_O(td_pos(decl->td), _("can't infer type.")); if(GET_FLAG(decl->type , template) && !GET_FLAG(decl->type, check)) - CHECK_BO(traverse_cdef(env, decl->type->e->def)) + CHECK_BO(check_cdef(env, decl->type->e->def)) const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); do { @@ -1251,7 +1251,7 @@ ANN static m_bool check_class_parent(const Env env, const Class_Def cdef) { const Type_Decl *td = cdef->base.ext; if(td->array) CHECK_BB(check_exp_array_subscripts(env, td->array->exp)) - if(parent->e->def && (!GET_FLAG(parent, check) || GET_FLAG(parent, template))) + if(parent->e->def && !GET_FLAG(parent, check)) CHECK_BB(scanx_parent(parent, traverse_cdef, env)) if(GET_FLAG(parent, typedef)) SET_FLAG(cdef->base.type, typedef); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 4e5c95d0..4bee421d 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -192,6 +192,7 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { udef->value->owner = nspc; nspc_add_value(nspc, udef->xid, udef->value); add_type(env, nspc, t); + SET_FLAG(t, scan1); SET_FLAG(udef->value, checked | udef->flag); if(env->class_def && !GET_FLAG(udef, static)) { SET_FLAG(udef->value, member); @@ -203,6 +204,7 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { env->curr : env->global_nspc; udef->type = union_type(env, nspc, udef->type_xid, 1); SET_FLAG(udef->type, checked); + SET_FLAG(udef->type, scan1); } else { const Nspc nspc = !GET_FLAG(udef, global) ? env->curr : env->global_nspc; @@ -216,6 +218,7 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { sprintf(c, "%p", udef); nspc_add_type(nspc, insert_symbol(c), t); SET_FLAG(udef->value, checked | udef->flag); + SET_FLAG(t, scan1); } if(udef->tmpl) { if(tmpl_base(udef->tmpl)) { diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 3ef50ce0..a4827218 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -87,8 +87,7 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(isres(env, var->xid, exp_self(decl)->pos)) Type t = decl->type; const Value former = nspc_lookup_value0(env->curr, var->xid); - if(former /* && !(decl->td->exp || decl->td->xid) */&& - (!env->class_def || !(GET_FLAG(env->class_def, template) || GET_FLAG(env->class_def, scan1)))) + if(former) ERR_B(var->pos, _("variable %s has already been defined in the same scope..."), s_name(var->xid)) if(var->array) { @@ -100,14 +99,14 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { } t = array_type(env, decl->type, var->array->depth); } - const Value v = var->value = former ?: new_value(env->gwion->mp, t, s_name(var->xid)); + assert(!var->value); + const Value v = var->value = new_value(env->gwion->mp, t, s_name(var->xid)); nspc_add_value(nspc, var->xid, v); v->flag = decl->td->flag; if(var->array && !var->array->exp) SET_FLAG(v, ref); if(!env->scope->depth && !env->class_def) SET_FLAG(v, global); - v->type = t; v->d.ptr = var->addr; v->owner = !env->func ? env->curr : NULL; v->owner_class = env->scope->depth ? NULL : env->class_def; @@ -274,6 +273,7 @@ ANN m_bool scan1_union_def(const Env env, const Union_Def udef) { SET_FLAG(decl.td, global); } while((l = l->next)); union_pop(env, udef, scope); + SET_FLAG(udef, scan1); return GW_OK; } @@ -357,7 +357,7 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { } while((t = t->e->parent)); if(isa(parent, t_object) < 0) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) - if(parent->e->def && (!GET_FLAG(parent, scan1) || GET_FLAG(parent, template))) + if(parent->e->def && !GET_FLAG(parent, scan1)) CHECK_BB(scanx_parent(parent, scan1_cdef, env)) if(type_ref(parent)) ERR_B(pos, _("can't use ref type in class extend")) @@ -372,6 +372,7 @@ ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { CHECK_BB(env_ext(env, cdef, scan1_parent)) if(cdef->body) CHECK_BB(env_body(env, cdef, scan1_section)) + SET_FLAG(cdef, scan1); return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 35f9a6b3..66471747 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -17,17 +17,12 @@ ANN static m_bool scan2_stmt(const Env, const Stmt); ANN static m_bool scan2_stmt_list(const Env, Stmt_List); -ANN static m_bool scan2_exp_decl_template(const Env env, const Exp_Decl* decl) { - CHECK_BB(scan1_cdef(env, decl->type->e->def)) - return scan2_cdef(env, decl->type->e->def); -} - ANN m_bool scan2_exp_decl(const Env env, const Exp_Decl* decl) { const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); const Type type = decl->type; if(GET_FLAG(type, template) && !GET_FLAG(type, scan2)) - CHECK_BB(scan2_exp_decl_template(env, decl)) + CHECK_BB(scan2_cdef(env, decl->type->e->def)) Var_Decl_List list = decl->list; do { const Var_Decl var = list->self; @@ -522,7 +517,7 @@ DECL_SECTION_FUNC(scan2) ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) { const Type parent = cdef->base.type->e->parent; - if(parent->e->def && (!GET_FLAG(parent, scan2) || GET_FLAG(parent, template))) + if(parent->e->def && !GET_FLAG(parent, scan2)) CHECK_BB(scanx_parent(parent, scan2_cdef, env)) if(cdef->base.ext->array) CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp)) diff --git a/src/parse/traverse.c b/src/parse/traverse.c index d731bf87..4f9da80c 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -19,15 +19,17 @@ ANN m_bool traverse_decl(const Env env, const Exp_Decl* decl) { ANN m_bool traverse_func_def(const Env env, const Func_Def def) { const Func former = env->func; - if(scan1_func_def(env, def) > 0 && scan2_func_def(env, def) > 0 && - check_func_def(env, def) > 0) + if(scan1_func_def(env, def) > 0 && + scan2_func_def(env, def) > 0 && + check_func_def(env, def) > 0) return GW_OK; env->func = former; return GW_ERROR; } ANN m_bool traverse_union_def(const Env env, const Union_Def def) { - CHECK_BB(scan1_union_def(env, def)) + if(!GET_FLAG(def, scan1)) + CHECK_BB(scan1_union_def(env, def)) CHECK_BB(scan2_union_def(env, def)) return check_union_def(env, def); } @@ -35,7 +37,7 @@ ANN m_bool traverse_union_def(const Env env, const Union_Def def) { ANN m_bool traverse_enum_def(const Env env, const Enum_Def def) { CHECK_BB(scan0_enum_def(env, def)) CHECK_BB(scan1_enum_def(env, def)) -// CHECK_BBscan2_enum_def(env, def)) +// CHECK_BB(scan2_enum_def(env, def)) return check_enum_def(env, def); } @@ -54,7 +56,8 @@ ANN m_bool traverse_type_def(const Env env, const Type_Def def) { } ANN m_bool traverse_class_def(const Env env, const Class_Def def) { - CHECK_BB(scan1_class_def(env, def)) + if(!GET_FLAG(def, scan1)) + CHECK_BB(scan1_class_def(env, def)) CHECK_BB(scan2_class_def(env, def)) return check_class_def(env, def); } -- 2.43.0