From d834002895ea2a0e9d6e1a980d89d086a229aa3c Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 23 Jul 2019 20:39:00 +0200 Subject: [PATCH] :art: define union in section --- ast | 2 +- include/parse.h | 8 ++-- include/traverse.h | 10 ++--- src/emit/emit.c | 66 ++++++++++++++++----------------- src/lib/import.c | 18 ++++----- src/oo/type.c | 8 ++-- src/parse/check.c | 28 +++++++------- src/parse/cpy_ast.c | 10 +++-- src/parse/scan0.c | 87 ++++++++++++++++++++++---------------------- src/parse/scan1.c | 28 +++++++------- src/parse/scan2.c | 12 +++--- src/parse/scanx.c | 2 +- src/parse/stage.c | 12 +++--- src/parse/template.c | 8 ++-- src/parse/traverse.c | 8 ++-- 15 files changed, 154 insertions(+), 153 deletions(-) diff --git a/ast b/ast index f4fae743..195d19f7 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit f4fae7438c14986d17dd28220b78869021a3e718 +Subproject commit 195d19f71c7a10ffb7964d0727746640e344ddba diff --git a/include/parse.h b/include/parse.h index e8e45124..800cf3e4 100644 --- a/include/parse.h +++ b/include/parse.h @@ -38,7 +38,7 @@ static const _exp_func exp_func[] = { #define DECL_SECTION_FUNC(prefix) \ static const _exp_func section_func[] = { \ (_exp_func)prefix##_stmt_list, (_exp_func)prefix##_func_def, (_exp_func)prefix##_class_def, \ - (_exp_func)prefix##_enum_def \ + (_exp_func)prefix##_enum_def, (_exp_func)prefix##_union_def \ }; \ ANN static inline m_bool prefix##_section(const void* a, /* const */ Section* section) { GWDEBUG_EXE \ void* d = §ion->d.stmt_list; \ @@ -60,8 +60,8 @@ ANN static m_bool prefix##_stmt_##name(const Env env, const type stmt) { GWDEBUG RET_NSPC(exp) \ } -ANN m_uint union_push(const Env, const Stmt_Union); -ANN void union_pop(const Env, const Stmt_Union, const m_uint); +ANN m_uint union_push(const Env, const Union_Def); +ANN void union_pop(const Env, const Union_Def, const m_uint); ANN m_bool check_stmt(const Env env, const Stmt stmt); ANN m_bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f, void* data); @@ -87,7 +87,7 @@ ANN m_bool scanx_cdef(const Env, void *,const Class_Def, #define xxx_cdef(prefix) \ static inline m_bool prefix##_cdef(const Env env, const Class_Def cdef) { \ return scanx_cdef(env, env, cdef, \ - (_exp_func)prefix##_class_def, (_exp_func)prefix##_stmt_union); \ + (_exp_func)prefix##_class_def, (_exp_func)prefix##_union_def); \ } xxx_cdef(scan1) xxx_cdef(scan2) diff --git a/include/traverse.h b/include/traverse.h index 00fa8a02..5124cbaa 100644 --- a/include/traverse.h +++ b/include/traverse.h @@ -3,7 +3,7 @@ ANN m_bool traverse_ast(const Env, const Ast); ANN m_bool traverse_class_def(const Env, const Class_Def); ANN m_bool traverse_func_def(const Env, const Func_Def); -ANN m_bool traverse_stmt_union(const Env, const Stmt_Union); +ANN m_bool traverse_union_def(const Env, const Union_Def); ANN m_bool traverse_enum_def(const Env, const Enum_Def); ANN m_bool traverse_stmt_fptr(const Env, const Stmt_Fptr ); ANN m_bool traverse_stmt_type(const Env env, const Stmt_Type def); @@ -27,10 +27,10 @@ ANN m_bool scan1_stmt_fptr(const Env, const Stmt_Fptr); ANN m_bool scan2_stmt_fptr(const Env, const Stmt_Fptr); //ANN m_bool check_stmt_fptr(const Env, const Stmt_Fptr); -ANN m_bool scan0_stmt_union(const Env, const Stmt_Union); -ANN m_bool scan1_stmt_union(const Env, const Stmt_Union); -ANN m_bool scan2_stmt_union(const Env, const Stmt_Union); -ANN m_bool check_stmt_union(const Env, const Stmt_Union); +ANN m_bool scan0_union_def(const Env, const Union_Def); +ANN m_bool scan1_union_def(const Env, const Union_Def); +ANN m_bool scan2_union_def(const Env, const Union_Def); +ANN m_bool check_union_def(const Env, const Union_Def); ANN m_bool scan0_enum_def(const Env, const Enum_Def); ANN m_bool scan1_enum_def(const Env, const Enum_Def); diff --git a/src/emit/emit.c b/src/emit/emit.c index c410d5a8..f552d238 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1364,59 +1364,59 @@ ANN void emit_union_offset(Decl_List l, const m_uint o) { } while((l = l->next)); } -ANN static inline void union_allocdata(MemPool mp, const Stmt_Union stmt) { - const Nspc nspc = (stmt->xid ? stmt->value->type : stmt->type)->nspc; +ANN static inline void union_allocdata(MemPool mp, const Union_Def udef) { + const Nspc nspc = (udef->xid ? udef->value->type : udef->type)->nspc; nspc_allocdata(mp, nspc); - nspc->info->offset = stmt->s; + nspc->info->offset = udef->s; } -ANN static m_bool emit_stmt_union(const Emitter emit, const Stmt_Union stmt) { - if(stmt->tmpl) +ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { + if(tmpl_base(udef->tmpl)) return GW_OK; - Decl_List l = stmt->l; + Decl_List l = udef->l; m_uint scope = emit->env->scope->depth; - const m_bool global = GET_FLAG(stmt, global); - if(stmt->xid) { - union_allocdata(emit->gwion->mp, stmt); + const m_bool global = GET_FLAG(udef, global); + if(udef->xid) { + union_allocdata(emit->gwion->mp, udef); Type_Decl *type_decl = new_type_decl(emit->gwion->mp, - new_id_list(emit->gwion->mp, stmt->xid, loc_cpy(emit->gwion->mp, stmt_self(stmt)->pos))); - type_decl->flag = stmt->flag; - const Var_Decl var_decl = new_var_decl(emit->gwion->mp, stmt->xid, NULL, loc_cpy(emit->gwion->mp, stmt_self(stmt)->pos)); + new_id_list(emit->gwion->mp, udef->xid, udef->pos)); + type_decl->flag = udef->flag; + const Var_Decl var_decl = new_var_decl(emit->gwion->mp, udef->xid, NULL, loc_cpy(emit->gwion->mp, udef->pos)); const Var_Decl_List var_decl_list = new_var_decl_list(emit->gwion->mp, var_decl, NULL); const Exp exp = new_exp_decl(emit->gwion->mp, type_decl, var_decl_list); - exp->d.exp_decl.type = stmt->value->type; - var_decl->value = stmt->value; + exp->d.exp_decl.type = udef->value->type; + var_decl->value = udef->value; CHECK_BB(emit_exp_decl(emit, &exp->d.exp_decl)) free_exp(emit->gwion->mp, exp); if(global) { - const M_Object o = new_object(emit->gwion->mp, NULL, stmt->value->type); - stmt->value->d.ptr = (m_uint*)o; - SET_FLAG(stmt->value, builtin); - SET_FLAG(stmt->value, global); + const M_Object o = new_object(emit->gwion->mp, NULL, udef->value->type); + udef->value->d.ptr = (m_uint*)o; + SET_FLAG(udef->value, builtin); + SET_FLAG(udef->value, global); } - scope = emit_push_type(emit, stmt->value->type); - } else if(stmt->type_xid) { - union_allocdata(emit->gwion->mp, stmt); - scope = emit_push_type(emit, stmt->type); + scope = emit_push_type(emit, udef->value->type); + } else if(udef->type_xid) { + union_allocdata(emit->gwion->mp, udef); + scope = emit_push_type(emit, udef->type); } else if(emit->env->class_def) { if(!GET_FLAG(l->self->d.exp_decl.list->self->value, member)) - stmt->o = emit_local(emit, stmt->s, 0); + udef->o = emit_local(emit, udef->s, 0); } else if(global) { - void* ptr = (void*)xcalloc(1, stmt->s); - l = stmt->l; + void* ptr = (void*)xcalloc(1, udef->s); + l = udef->l; do { Var_Decl_List list = l->self->d.exp_decl.list; list->self->value->d.ptr = ptr; SET_FLAG(list->self->value, union); } while((l = l->next)); - SET_FLAG(stmt->l->self->d.exp_decl.list->self->value, enum); + SET_FLAG(udef->l->self->d.exp_decl.list->self->value, enum); } - if(stmt->xid) - regpop(emit, !GET_FLAG(stmt, static) ? SZ_INT : SZ_INT*2); - emit_union_offset(stmt->l, stmt->o); - if(stmt->xid || stmt->type_xid || global) + if(udef->xid) + regpop(emit, !GET_FLAG(udef, static) ? SZ_INT : SZ_INT*2); + emit_union_offset(udef->l, udef->o); + if(udef->xid || udef->type_xid || global) emit_pop(emit, scope); - SET_FLAG(stmt->xid ? stmt->value->type : stmt->type, emit); + SET_FLAG(udef->xid ? udef->value->type : udef->type, emit); return GW_OK; } @@ -1430,7 +1430,7 @@ static const _exp_func stmt_func[] = { (_exp_func)emit_stmt_if, (_exp_func)emit_stmt_code, (_exp_func)emit_stmt_switch, (_exp_func)emit_stmt_break, (_exp_func)emit_stmt_continue, (_exp_func)emit_stmt_return, (_exp_func)emit_stmt_case, (_exp_func)emit_stmt_jump, - (_exp_func)dummy_func, (_exp_func)emit_stmt_type, (_exp_func)emit_stmt_union, + (_exp_func)dummy_func, (_exp_func)emit_stmt_type }; ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt, const m_bool pop) { @@ -1742,7 +1742,7 @@ ANN static m_bool emit_parent(const Emitter emit, const Class_Def cdef) { ANN static inline m_bool emit_cdef(const Emitter emit, const Class_Def cdef) { return scanx_cdef(emit->env, emit, cdef, - (_exp_func)emit_class_def, (_exp_func)emit_stmt_union); + (_exp_func)emit_class_def, (_exp_func)emit_union_def); } ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { diff --git a/src/lib/import.c b/src/lib/import.c index 80b4bbd9..0ea76367 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -599,16 +599,16 @@ ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { if(!gwi->union_data.list) GWI_ERR_O(_("union is empty")); - const Stmt stmt = new_stmt_union(gwi->gwion->mp, gwi->union_data.list, loc_cpy(gwi->gwion->mp, gwi->loc)); - stmt->d.stmt_union.flag = flag; - CHECK_BO(traverse_stmt_union(gwi->gwion->env, &stmt->d.stmt_union)) - emit_union_offset(stmt->d.stmt_union.l, stmt->d.stmt_union.o); - if(GET_FLAG((&stmt->d.stmt_union), member)) + const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->union_data.list, loc_cpy(gwi->gwion->mp, gwi->loc)); + udef->flag = flag; + CHECK_BO(traverse_union_def(gwi->gwion->env, udef)) + emit_union_offset(udef->l, udef->o); + if(GET_FLAG(udef, member)) gwi->gwion->env->class_def->nspc->info->offset = - stmt->d.stmt_union.o + stmt->d.stmt_union.s; - const Type t = stmt->d.stmt_union.xid ? stmt->d.stmt_union.value->type : - stmt->d.stmt_union.type_xid ? stmt->d.stmt_union.type : t_int; - free_stmt(gwi->gwion->mp, stmt); + udef->o + udef->s; + const Type t = udef->xid ? udef->value->type : + udef->type_xid ? udef->type : t_int; + free_union_def(gwi->gwion->mp, udef); gwi->union_data.list = NULL; gwi->union_data.xid = NULL; return t; diff --git a/src/oo/type.c b/src/oo/type.c index c9632d24..60b49054 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -13,11 +13,11 @@ ANN static void free_type(Type a, Gwion gwion) { if(GET_FLAG(a, template)) { if(GET_FLAG(a, union)) { - if(a->e->def->stmt && !GET_FLAG(a, pure)) { // <=> decl_list - UNSET_FLAG(&a->e->def->stmt->d.stmt_union, global); - free_stmt(gwion->mp, a->e->def->stmt); + if(a->e->def->union_def && !GET_FLAG(a, pure)) { // <=> decl_list + UNSET_FLAG(a->e->def->union_def, global); + free_union_def(gwion->mp, a->e->def->union_def); } - a->e->def->stmt = NULL; + a->e->def->union_def = NULL; } else free_class_def(gwion->mp, a->e->def); } diff --git a/src/parse/check.c b/src/parse/check.c index f4cb87fb..6f0810b9 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1045,36 +1045,36 @@ ANN static m_bool check_stmt_jump(const Env env, const Stmt_Jump stmt) { return GW_OK; } -ANN m_bool check_stmt_union(const Env env, const Stmt_Union stmt) { - if(stmt->tmpl && stmt->tmpl->base == -1) // there's a func for this +ANN m_bool check_union_def(const Env env, const Union_Def udef) { + if(tmpl_base(udef->tmpl)) // there's a func for this return GW_OK; - if(stmt->xid) { + if(udef->xid) { if(env->class_def) - (!GET_FLAG(stmt, static) ? decl_member : decl_static)(env->curr, stmt->value); + (!GET_FLAG(udef, static) ? decl_member : decl_static)(env->curr, udef->value); } else if(env->class_def) { - if(!GET_FLAG(stmt, static)) - stmt->o = env->class_def->nspc->info->offset; + if(!GET_FLAG(udef, static)) + udef->o = env->class_def->nspc->info->offset; else { - stmt->o = env->class_def->nspc->info->class_data_size; + udef->o = env->class_def->nspc->info->class_data_size; env->class_def->nspc->info->class_data_size += SZ_INT; } } - const m_uint scope = union_push(env, stmt); - Decl_List l = stmt->l; + const m_uint scope = union_push(env, udef); + Decl_List l = udef->l; do { CHECK_OB(check_exp(env, l->self)) if(isa(l->self->type, t_object) > 0) { - if(!GET_FLAG(l->self->d.exp_decl.td, ref) && !GET_FLAG(stmt->type, template)) + if(!GET_FLAG(l->self->d.exp_decl.td, ref) && !GET_FLAG(udef->type, template)) ERR_B(l->self->pos, _("In union, Objects must be declared as reference (use '@')")) // SET_FLAG(l->self->d.exp_decl.td, ref); Var_Decl_List list = l->self->d.exp_decl.list; do SET_FLAG(list->self->value, pure); while((list = list->next)); } - if(l->self->type->size > stmt->s) - stmt->s = l->self->type->size; + if(l->self->type->size > udef->s) + udef->s = l->self->type->size; } while((l = l->next)); - union_pop(env, stmt, scope); + union_pop(env, udef, scope); return GW_OK; } @@ -1088,7 +1088,7 @@ static const _exp_func stmt_func[] = { (_exp_func)check_stmt_if, (_exp_func)check_stmt_code, (_exp_func)check_stmt_switch, (_exp_func)check_stmt_break, (_exp_func)check_stmt_continue, (_exp_func)check_stmt_return, (_exp_func)check_stmt_case, (_exp_func)check_stmt_jump, - (_exp_func)dummy_func, (_exp_func)check_stmt_type, (_exp_func)check_stmt_union, + (_exp_func)dummy_func, (_exp_func)check_stmt_type }; ANN m_bool check_stmt(const Env env, const Stmt stmt) { diff --git a/src/parse/cpy_ast.c b/src/parse/cpy_ast.c index 86db4f46..f31e8fa2 100644 --- a/src/parse/cpy_ast.c +++ b/src/parse/cpy_ast.c @@ -345,7 +345,8 @@ ANN static void cpy_stmt_type(MemPool p, Stmt_Type a, const Stmt_Type src) { a->tmpl = cpy_tmpl(p, src->tmpl); } -ANN static void cpy_stmt_union(MemPool p, Stmt_Union a,const Stmt_Union src) { +ANN static Union_Def cpy_union_def(MemPool p, const Union_Def src) { + Union_Def a = mp_calloc(p, Union_Def); a->l = cpy_decl_list(p, src->l); // 1 if(src->xid) a->xid = src->xid; // 1 @@ -354,6 +355,7 @@ ANN static void cpy_stmt_union(MemPool p, Stmt_Union a,const Stmt_Union src) { if(src->tmpl) a->tmpl = cpy_tmpl(p, src->tmpl); // 1 a->flag = src->flag; // 1 + return a; } ANN static Stmt cpy_stmt(MemPool p, const Stmt src) { @@ -401,9 +403,6 @@ ANN static Stmt cpy_stmt(MemPool p, const Stmt src) { case ae_stmt_type: cpy_stmt_type(p, &a->d.stmt_type, &src->d.stmt_type); break; - case ae_stmt_union: - cpy_stmt_union(p, &a->d.stmt_union, &src->d.stmt_union); - break; case ae_stmt_break: case ae_stmt_continue: break; @@ -449,6 +448,9 @@ ANN static Section* cpy_section(MemPool p, const Section *src) { case ae_section_enum: a->d.enum_def = cpy_enum_def(p, src->d.enum_def); break; + case ae_section_union: + a->d.union_def = cpy_union_def(p, src->d.union_def); + break; } a->section_type = src->section_type; return a; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 0b053091..3c3caad8 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -155,61 +155,62 @@ ANN static Type union_type(const Env env, const Nspc nspc, const Symbol s, const return t; } -ANN m_bool scan0_stmt_union(const Env env, const Stmt_Union stmt) { - CHECK_BB(env_storage(env, stmt->flag, stmt_self(stmt)->pos)) - const m_uint scope = !GET_FLAG(stmt, global) ? env->scope->depth : +ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { + CHECK_BB(env_storage(env, udef->flag, udef->pos)) + const m_uint scope = !GET_FLAG(udef, global) ? env->scope->depth : env_push_global(env); - if(stmt->xid) { - CHECK_BB(scan0_defined(env, stmt->xid, stmt_self(stmt)->pos)) - const Nspc nspc = !GET_FLAG(stmt, global) ? + if(udef->xid) { + CHECK_BB(scan0_defined(env, udef->xid, udef->pos)) + const Nspc nspc = !GET_FLAG(udef, global) ? env->curr : env->global_nspc; - const Type t = union_type(env, nspc, stmt->type_xid ?: stmt->xid, - !!stmt->type_xid); - stmt->value = new_value(env->gwion->mp, t, s_name(stmt->xid)); - stmt->value->owner_class = env->class_def; - stmt->value->owner = nspc; - nspc_add_value(nspc, stmt->xid, stmt->value); + const Type t = union_type(env, nspc, udef->type_xid ?: udef->xid, + !!udef->type_xid); + udef->value = new_value(env->gwion->mp, t, s_name(udef->xid)); + udef->value->owner_class = env->class_def; + udef->value->owner = nspc; + nspc_add_value(nspc, udef->xid, udef->value); add_type(env, nspc, t); - SET_FLAG(stmt->value, checked | stmt->flag); - if(env->class_def && !GET_FLAG(stmt, static)) { - SET_FLAG(stmt->value, member); - SET_FLAG(stmt, member); + SET_FLAG(udef->value, checked | udef->flag); + if(env->class_def && !GET_FLAG(udef, static)) { + SET_FLAG(udef->value, member); + SET_FLAG(udef, member); } - } else if(stmt->type_xid) { - CHECK_BB(scan0_defined(env, stmt->type_xid, stmt_self(stmt)->pos)) - const Nspc nspc = !GET_FLAG(stmt, global) ? + } else if(udef->type_xid) { + CHECK_BB(scan0_defined(env, udef->type_xid, udef->pos)) + const Nspc nspc = !GET_FLAG(udef, global) ? env->curr : env->global_nspc; - stmt->type = union_type(env, nspc, stmt->type_xid, 1); - SET_FLAG(stmt->type, checked); + udef->type = union_type(env, nspc, udef->type_xid, 1); + SET_FLAG(udef->type, checked); } else { - const Nspc nspc = !GET_FLAG(stmt, global) ? + const Nspc nspc = !GET_FLAG(udef, global) ? env->curr : env->global_nspc; +// TODO make unique names const Type t = union_type(env, nspc, insert_symbol("union"), 1); - stmt->value = new_value(env->gwion->mp, t, "union"); - stmt->value->owner_class = env->class_def; - stmt->value->owner = nspc; - nspc_add_value(nspc, stmt->xid, stmt->value); + udef->value = new_value(env->gwion->mp, t, "union"); + udef->value->owner_class = env->class_def; + udef->value->owner = nspc; + nspc_add_value(nspc, udef->xid, udef->value); char c[16]; - sprintf(c, "%p", stmt); + sprintf(c, "%p", udef); nspc_add_type(nspc, insert_symbol(c), t); - SET_FLAG(stmt->value, checked | stmt->flag); + SET_FLAG(udef->value, checked | udef->flag); } - if(stmt->tmpl) { - if(tmpl_base(stmt->tmpl)) { - const Class_Def cdef = new_class_def(env->gwion->mp, stmt->flag, stmt->type_xid, - NULL, (Class_Body)stmt->l, loc_cpy(env->gwion->mp, stmt_self(stmt)->pos)); - stmt->type->e->def = cdef; - cdef->base.tmpl = stmt->tmpl; - cdef->base.type = stmt->type; - cdef->list = stmt->l; + if(udef->tmpl) { + if(tmpl_base(udef->tmpl)) { + const Class_Def cdef = new_class_def(env->gwion->mp, udef->flag, udef->type_xid, + NULL, (Class_Body)udef->l, loc_cpy(env->gwion->mp, udef->pos)); + udef->type->e->def = cdef; + cdef->base.tmpl = udef->tmpl; + cdef->base.type = udef->type; + cdef->list = udef->l; SET_FLAG(cdef, union); - SET_FLAG(stmt->type, pure); - SET_FLAG(stmt, template); - SET_FLAG(stmt->type, template); + SET_FLAG(udef->type, pure); + SET_FLAG(udef, template); + SET_FLAG(udef->type, template); } - SET_FLAG(stmt->type, union); + SET_FLAG(udef->type, union); } - if(GET_FLAG(stmt, global)) + if(GET_FLAG(udef, global)) env_pop(env, scope); return GW_OK; } @@ -221,8 +222,6 @@ ANN static m_bool scan0_stmt(const Env env, const Stmt stmt) { return scan0_stmt_fptr(env, &stmt->d.stmt_fptr); if(stmt->stmt_type == ae_stmt_type) return scan0_stmt_type(env, &stmt->d.stmt_type); - if(stmt->stmt_type == ae_stmt_union) - return scan0_stmt_union(env, &stmt->d.stmt_union); if(stmt->stmt_type == ae_stmt_code) return scan0_stmt_code(env, &stmt->d.stmt_code); if(stmt->stmt_type == ae_stmt_switch) @@ -286,6 +285,8 @@ ANN static m_bool scan0_section(const Env env, const Section* section) { return scan0_func_def(env, section->d.func_def); if(section->section_type == ae_section_enum) return scan0_enum_def(env, section->d.enum_def); + if(section->section_type == ae_section_union) + return scan0_union_def(env, section->d.union_def); return GW_OK; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 76845ac9..8dadc4ad 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -255,32 +255,30 @@ ANN m_bool scan1_stmt_type(const Env env, const Stmt_Type stmt) { return stmt->type->e->def ? scan1_cdef(env, stmt->type->e->def) : GW_OK; } -ANN m_bool scan1_stmt_union(const Env env, const Stmt_Union stmt) { - if(tmpl_base(stmt->tmpl)) +ANN m_bool scan1_union_def(const Env env, const Union_Def udef) { + if(tmpl_base(udef->tmpl)) return GW_OK; - if(!stmt->value) - CHECK_BB(scan0_stmt_union(env, stmt)) - Decl_List l = stmt->l; - const m_uint scope = union_push(env, stmt); - if(stmt->xid || stmt->type_xid) { - UNSET_FLAG(stmt, private); - UNSET_FLAG(stmt, protect); + Decl_List l = udef->l; + const m_uint scope = union_push(env, udef); + if(udef->xid || udef->type_xid) { + UNSET_FLAG(udef, private); + UNSET_FLAG(udef, protect); } do { const Exp_Decl decl = l->self->d.exp_decl; - SET_FLAG(decl.td, checked | stmt->flag); - const m_bool global = GET_FLAG(stmt, global); + SET_FLAG(decl.td, checked | udef->flag); + const m_bool global = GET_FLAG(udef, global); if(global) UNSET_FLAG(decl.td, global); - if(GET_FLAG(stmt, member)) + if(GET_FLAG(udef, member)) SET_FLAG(decl.td, member); - else if(GET_FLAG(stmt, static)) + else if(GET_FLAG(udef, static)) SET_FLAG(decl.td, static); CHECK_BB(scan1_exp(env, l->self)) if(global) SET_FLAG(decl.td, global); } while((l = l->next)); - union_pop(env, stmt, scope); + union_pop(env, udef, scope); return GW_OK; } @@ -290,7 +288,7 @@ static const _exp_func stmt_func[] = { (_exp_func)scan1_stmt_if, (_exp_func)scan1_stmt_code, (_exp_func)scan1_stmt_switch, (_exp_func)dummy_func, (_exp_func)dummy_func, (_exp_func)scan1_stmt_exp, (_exp_func)scan1_stmt_case, (_exp_func)dummy_func, - (_exp_func)scan1_stmt_fptr, (_exp_func)scan1_stmt_type, (_exp_func)scan1_stmt_union, + (_exp_func)scan1_stmt_fptr, (_exp_func)scan1_stmt_type, }; ANN static inline m_bool scan1_stmt(const Env env, const Stmt stmt) { diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 7993c559..a81bab45 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -270,14 +270,14 @@ ANN static m_bool scan2_stmt_jump(const Env env, const Stmt_Jump stmt) { return GW_OK; } -ANN m_bool scan2_stmt_union(const Env env, const Stmt_Union stmt) { - if(tmpl_base(stmt->tmpl)) +ANN m_bool scan2_union_def(const Env env, const Union_Def udef) { + if(tmpl_base(udef->tmpl)) return GW_OK; - const m_uint scope = union_push(env, stmt); - Decl_List l = stmt->l; + const m_uint scope = union_push(env, udef); + Decl_List l = udef->l; do CHECK_BB(scan2_exp(env, l->self)) while((l = l->next)); - union_pop(env, stmt, scope); + union_pop(env, udef, scope); return GW_OK; } @@ -287,7 +287,7 @@ static const _exp_func stmt_func[] = { (_exp_func)scan2_stmt_if, (_exp_func)scan2_stmt_code, (_exp_func)scan2_stmt_switch, (_exp_func)dummy_func, (_exp_func)dummy_func, (_exp_func)scan2_stmt_exp, (_exp_func)scan2_stmt_case, (_exp_func)scan2_stmt_jump, - (_exp_func)scan2_stmt_fptr, (_exp_func)scan2_stmt_type, (_exp_func)scan2_stmt_union, + (_exp_func)scan2_stmt_fptr, (_exp_func)scan2_stmt_type, }; ANN static m_bool scan2_stmt(const Env env, const Stmt stmt) { diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 2f9bd2fa..512eeafc 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -75,7 +75,7 @@ ANN m_bool scanx_cdef(const Env env, void* opt, const Class_Def cdef, if(cdef->base.type->e->parent != t_union) return f_cdef(opt, cdef); CHECK_BB(template_push_types(env, cdef->base.tmpl)) - const m_bool ret = f_union(opt, &cdef->stmt->d.stmt_union); + const m_bool ret = f_union(opt, cdef->union_def); nspc_pop_type(env->gwion->mp, env->curr); return ret; } diff --git a/src/parse/stage.c b/src/parse/stage.c index 72573fcf..8d582020 100644 --- a/src/parse/stage.c +++ b/src/parse/stage.c @@ -5,14 +5,14 @@ #include "value.h" #include "type.h" -ANN m_uint union_push(const Env env, const Stmt_Union stmt) { - const Type type = stmt->xid ? stmt->value->type : stmt->type_xid ? - stmt->type : NULL; - return type ? env_push_type(env, type) : GET_FLAG(stmt, global) ? +ANN m_uint union_push(const Env env, const Union_Def udef) { + const Type type = udef->xid ? udef->value->type : udef->type_xid ? + udef->type : NULL; + return type ? env_push_type(env, type) : GET_FLAG(udef, global) ? env_push_global(env) : env->scope->depth; } -ANN void union_pop(const Env env, const Stmt_Union stmt, const m_uint scope) { - if(stmt->xid || stmt->type_xid || GET_FLAG(stmt, global)) +ANN void union_pop(const Env env, const Union_Def udef, const m_uint scope) { + if(udef->xid || udef->type_xid || GET_FLAG(udef, global)) env_pop(env, scope); } diff --git a/src/parse/template.c b/src/parse/template.c index afd0bad4..d65916b5 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -180,10 +180,10 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { map_set(&t->e->owner->info->type->map, (vtype)a->base.xid, (vtype)a->base.type); map_set((Map)vector_front((Vector)&t->e->owner->info->type->ptr), (vtype)a->base.xid, (vtype)a->base.type); } else { - a->stmt = new_stmt_union(env->gwion->mp, a->list, t->e->def->pos); - a->stmt->d.stmt_union.type_xid = a->base.xid; - CHECK_BO(scan0_stmt_union(env, &a->stmt->d.stmt_union)) - a->base.type = a->stmt->d.stmt_union.type; + a->union_def = new_union_def(env->gwion->mp, a->list, t->e->def->pos); + a->union_def->type_xid = a->base.xid; + CHECK_BO(scan0_union_def(env, a->union_def)) + a->base.type = a->union_def->type; a->base.type->e->def = a; assert(GET_FLAG(a, union)); } diff --git a/src/parse/traverse.c b/src/parse/traverse.c index 4fda7c7e..2cede9be 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -26,10 +26,10 @@ ANN m_bool traverse_func_def(const Env env, const Func_Def def) { return GW_ERROR; } -ANN m_bool traverse_stmt_union(const Env env, const Stmt_Union def) { - CHECK_BB(scan1_stmt_union(env, def)) - CHECK_BB(scan2_stmt_union(env, def)) - return check_stmt_union(env, def); +ANN m_bool traverse_union_def(const Env env, const Union_Def def) { + 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) { -- 2.43.0