Skip to content

Commit

Permalink
👕 More clean
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Jul 23, 2019
1 parent 3dc4a8a commit 38ae1e2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/parse/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/parse/scan0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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)) {
Expand Down
11 changes: 6 additions & 5 deletions src/parse/scan1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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"))
Expand All @@ -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;
}

Expand Down
9 changes: 2 additions & 7 deletions src/parse/scan2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
13 changes: 8 additions & 5 deletions src/parse/traverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ 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);
}

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);
}

Expand All @@ -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);
}

0 comments on commit 38ae1e2

Please sign in to comment.