-Subproject commit 5d8450be617d21ac1aca168dd9c5cf267bebd8f1
+Subproject commit f4fae7438c14986d17dd28220b78869021a3e718
#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##_stmt_list, (_exp_func)prefix##_func_def, (_exp_func)prefix##_class_def, \
+ (_exp_func)prefix##_enum_def \
}; \
ANN static inline m_bool prefix##_section(const void* a, /* const */ Section* section) { GWDEBUG_EXE \
void* d = §ion->d.stmt_list; \
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_stmt_enum(const Env, const Stmt_Enum);
+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);
ANN m_bool traverse_decl(const Env, const Exp_Decl*);
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_stmt_enum(const Env, const Stmt_Enum);
-ANN m_bool scan1_stmt_enum(const Env, const Stmt_Enum);
-//ANN m_bool scan2_stmt_enum(const Env, const Stmt_Enum);
-ANN m_bool check_stmt_enum(const Env, const Stmt_Enum);
+ANN m_bool scan0_enum_def(const Env, const Enum_Def);
+ANN m_bool scan1_enum_def(const Env, const Enum_Def);
+//ANN m_bool scan2_enum_def(const Env, const Enum_Def);
+ANN m_bool check_enum_def(const Env, const Enum_Def);
ANN m_bool scan0_stmt_type(const Env, const Stmt_Type);
ANN m_bool scan1_stmt_type(const Env, const Stmt_Type);
return stmt->type->e->def ? emit_class_def(emit, stmt->type->e->def) : 1;
}
-ANN static m_bool emit_stmt_enum(const Emitter emit, const Stmt_Enum stmt) {
+ANN static m_bool emit_enum_def(const Emitter emit, const Enum_Def edef) {
LOOP_OPTIM
- for(m_uint i = 0; i < vector_size(&stmt->values); ++i) {
- const Value v = (Value)vector_at(&stmt->values, i);
+ for(m_uint i = 0; i < vector_size(&edef->values); ++i) {
+ const Value v = (Value)vector_at(&edef->values, i);
if(!emit->env->class_def) {
ALLOC_PTR(emit->gwion->mp, addr, m_uint, i);
v->offset = emit_local(emit, SZ_INT, 0);
(_exp_func)emit_stmt_for, (_exp_func)emit_stmt_auto, (_exp_func)emit_stmt_loop,
(_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)emit_stmt_enum,
+ (_exp_func)emit_stmt_case, (_exp_func)emit_stmt_jump,
(_exp_func)dummy_func, (_exp_func)emit_stmt_type, (_exp_func)emit_stmt_union,
};
ANN Type gwi_enum_end(const Gwi gwi) {
DL_Enum* d = &gwi->enum_data;
- const Stmt stmt = new_stmt_enum(gwi->gwion->mp, d->base, d->t ? insert_symbol(gwi->gwion->st, d->t) : NULL);
- if(traverse_stmt_enum(gwi->gwion->env, &stmt->d.stmt_enum) < 0) {
+ const Enum_Def edef = new_enum_def(gwi->gwion->mp, d->base, d->t ? insert_symbol(gwi->gwion->st, d->t) : NULL,
+ loc_cpy(gwi->gwion->mp, gwi->loc));
+ if(traverse_enum_def(gwi->gwion->env, edef) < 0) {
free_id_list(gwi->gwion->mp, d->base);
return NULL;
}
- import_enum_end(gwi, &stmt->d.stmt_enum.values);
- const Type t = stmt->d.stmt_enum.t;
- free_stmt(gwi->gwion->mp, stmt);
+ import_enum_end(gwi, &edef->values);
+ const Type t =edef->t;
+ free_enum_def(gwi->gwion->mp, edef);
return t;
}
return exp->type;
}
-ANN m_bool check_stmt_enum(const Env env, const Stmt_Enum stmt) {
+ANN m_bool check_enum_def(const Env env, const Enum_Def edef) {
if(env->class_def) {
- ID_List list = stmt->list;
+ ID_List list = edef->list;
do decl_static(env->curr, nspc_lookup_value0(env->curr, list->xid));
while((list = list->next));
}
(_exp_func)check_stmt_for, (_exp_func)check_stmt_auto, (_exp_func)check_stmt_loop,
(_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)check_stmt_enum,
+ (_exp_func)check_stmt_case, (_exp_func)check_stmt_jump,
(_exp_func)dummy_func, (_exp_func)check_stmt_type, (_exp_func)check_stmt_union,
};
a->stmt = cpy_stmt(p, src->stmt);
}
-ANN static void cpy_stmt_enum(MemPool p, Stmt_Enum a, const Stmt_Enum src) {
+ANN static Enum_Def cpy_enum_def(MemPool p, const Enum_Def src) {
+ Enum_Def a = mp_calloc(p, Func_Base);
a->list = cpy_id_list(p, src->list);
a->xid = src->xid;
a->flag = src->flag;
+ return a;
}
ANN Func_Base* cpy_func_base(MemPool p, const Func_Base* src) {
case ae_stmt_switch:
cpy_stmt_switch(p, &a->d.stmt_switch, &src->d.stmt_switch);
break;
- case ae_stmt_enum:
- cpy_stmt_enum(p, &a->d.stmt_enum, &src->d.stmt_enum);
- break;
case ae_stmt_fptr:
cpy_stmt_fptr(p, &a->d.stmt_fptr, &src->d.stmt_fptr);
break;
case ae_section_func:
a->d.func_def = cpy_func_def(p, src->d.func_def);
break;
+ case ae_section_enum:
+ a->d.enum_def = cpy_enum_def(p, src->d.enum_def);
+ break;
}
a->section_type = src->section_type;
return a;
a->pos = loc_cpy(p, src->pos);
return a;
}
-
+/*
ANN static Ast cpy_ast(MemPool p, const Ast src) {
Ast a = mp_calloc(p, Ast);
a->section = cpy_section(p, src->section);
a->next = cpy_ast(p, src->next);
return a;
}
-
+*/
return GW_OK;
}
-ANN m_bool scan0_stmt_enum(const Env env, const Stmt_Enum stmt) {
- CHECK_BB(env_storage(env, stmt->flag, stmt_self(stmt)->pos))
- if(stmt->xid) {
- const Value v = nspc_lookup_value1(env->curr, stmt->xid);
+ANN m_bool scan0_enum_def(const Env env, const Enum_Def edef) {
+ CHECK_BB(env_storage(env, edef->flag, edef->pos))
+ if(edef->xid) {
+ const Value v = nspc_lookup_value1(env->curr, edef->xid);
if(v)
- ERR_B(stmt_self(stmt)->pos, _("'%s' already declared as variable of type '%s'."),
- s_name(stmt->xid), v->type->name)
- CHECK_BB(scan0_defined(env, stmt->xid, stmt_self(stmt)->pos))
+ ERR_B(edef->pos, _("'%s' already declared as variable of type '%s'."),
+ s_name(edef->xid), v->type->name)
+ CHECK_BB(scan0_defined(env, edef->xid, edef->pos))
}
const Type t = type_copy(env->gwion->mp, t_int);
t->xid = ++env->scope->type_xid;
- t->name = stmt->xid ? s_name(stmt->xid) : "int";
+ t->name = edef->xid ? s_name(edef->xid) : "int";
t->e->parent = t_int;
- const Nspc nspc = GET_FLAG(stmt, global) ? env->global_nspc : env->curr;
+ const Nspc nspc = GET_FLAG(edef, global) ? env->global_nspc : env->curr;
t->e->owner = nspc;
- stmt->t = t;
- if(stmt->xid) {
+ edef->t = t;
+ if(edef->xid) {
add_type(env, nspc, t);
mk_class(env, t);
}
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_enum)
- return scan0_stmt_enum(env, &stmt->d.stmt_enum);
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_class_def(env, section->d.class_def);
if(section->section_type == ae_section_func)
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);
return GW_OK;
}
return scan1_exp(env, stmt->val);
}
-ANN m_bool scan1_stmt_enum(const Env env, const Stmt_Enum stmt) {
- if(!stmt->t)
- CHECK_BB(scan0_stmt_enum(env, stmt))
- ID_List list = stmt->list;
+ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) {
+ ID_List list = edef->list;
do {
- CHECK_BB(already_defined(env, list->xid, stmt_self(stmt)->pos))
- const Value v = new_value(env->gwion->mp, stmt->t, s_name(list->xid));
+ CHECK_BB(already_defined(env, list->xid, edef->pos))
+ const Value v = new_value(env->gwion->mp, edef->t, s_name(list->xid));
if(env->class_def) {
v->owner_class = env->class_def;
SET_FLAG(v, static);
- SET_ACCESS(stmt, v)
+ SET_ACCESS(edef, v)
}
v->owner = env->curr;
SET_FLAG(v, const | ae_flag_enum | ae_flag_checked);
- nspc_add_value(stmt->t->e->owner, list->xid, v);
- vector_add(&stmt->values, (vtype)v);
+ nspc_add_value(edef->t->e->owner, list->xid, v);
+ vector_add(&edef->values, (vtype)v);
} while((list = list->next));
return GW_OK;
}
(_exp_func)scan1_stmt_for, (_exp_func)scan1_stmt_auto, (_exp_func)scan1_stmt_loop,
(_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_enum,
+ (_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)scan2_stmt_for, (_exp_func)scan2_stmt_auto, (_exp_func)scan2_stmt_loop,
(_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)dummy_func,
+ (_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,
};
return ret;
}
+#define scan2_enum_def dummy_func
DECL_SECTION_FUNC(scan2)
ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) {
return check_stmt_union(env, def);
}
-ANN m_bool traverse_stmt_enum(const Env env, const Stmt_Enum def) {
- CHECK_BB(scan0_stmt_enum(env, def))
- CHECK_BB(scan1_stmt_enum(env, def))
-// CHECK_BBscan2_stmt_enum(env, def))
- return check_stmt_enum(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))
+ return check_enum_def(env, def);
}
ANN m_bool traverse_stmt_fptr(const Env env, const Stmt_Fptr def) {