ANN m_uint union_push(const Env, const Stmt_Union);
ANN void union_pop(const Env, const Stmt_Union, 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);
+static inline ANN m_bool env_body(const Env env, const Class_Def cdef, const _exp_func f) {
+ return scanx_body(env, cdef, f, env);
+}
+#define env_body(a,b,c) env_body(a,b,(_exp_func)c)
#endif
emit_class_code(emit, type->name);
if(cdef->base.ext && cdef->base.ext->array)
CHECK_BB(emit_array_extend(emit, type->e->parent, cdef->base.ext->array->exp))
- if(cdef->body) {
- const m_uint scope = env_push_type(emit->env, cdef->base.type);
- if(cdef->tmpl)
- template_push_types(emit->env, cdef->tmpl->list.list, cdef->tmpl->base);
- Class_Body body = cdef->body;
- do CHECK_BB(emit_section(emit, body->section))
- while((body = body->next));
- if(cdef->tmpl)
- nspc_pop_type(emit->env->gwion->mp, emit->env->curr);
- env_pop(emit->env, scope);
- }
+ if(cdef->body)
+ CHECK_BB(scanx_body(emit->env, cdef, (_exp_func)emit_section, emit))
emit_class_finish(emit, nspc);
SET_FLAG(cdef->base.type->nspc->pre_ctor, ctor);
emit_class_pop(emit);
return GW_OK;
}
-ANN static m_bool check_class_body(const Env env, const Class_Def cdef) {
- const m_uint scope = env_push_type(env, cdef->base.type);
- Class_Body body = cdef->body;
- if(cdef->tmpl)
- template_push_types(env, cdef->tmpl->list.list, cdef->tmpl->base);
- do CHECK_BB(check_section(env, body->section))
- while((body = body->next));
- if(cdef->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- env_pop(env, scope);
- return GW_OK;
-}
-
ANN static inline void inherit(const Type t) {
const Nspc nspc = t->nspc, parent = t->e->parent->nspc;
nspc->info->offset = parent->info->offset;
type->e->parent = t_object;
inherit(type);
if(cdef->body)
- CHECK_BB(check_class_body(env, cdef))
+ CHECK_BB(env_body(env, cdef, check_section))
SET_FLAG(type, checked | ae_flag_check);
return GW_OK;
}
ANN m_bool scan0_class_def(const Env env, const Class_Def cdef) {
CHECK_BB(scan0_class_def_pre(env, cdef))
CHECK_OB((cdef->base.type = scan0_class_def_init(env, cdef)))
- if(cdef->body) {
- Class_Body body = cdef->body;
- const m_uint scope = env_push_type(env, cdef->base.type);
- if(cdef->tmpl)
- template_push_types(env, cdef->tmpl->list.list, cdef->tmpl->base);
- do CHECK_BB(scan0_section(env, body->section))
- while((body = body->next));
- if(cdef->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- env_pop(env, scope);
- }
+ if(cdef->body)
+ CHECK_BB(env_body(env, cdef, scan0_section))
(void)mk_class(env, cdef->base.type);
if(GET_FLAG(cdef, global))
env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
return GW_OK;
}
-ANN static m_bool scan1_class_body(const Env env, const Class_Def cdef) {
- const m_uint scope = env_push_type(env, cdef->base.type);
- Class_Body body = cdef->body;
- if(cdef->tmpl)
- template_push_types(env, cdef->tmpl->list.list, cdef->tmpl->base);
- do CHECK_BB(scan1_section(env, body->section))
- while((body = body->next));
- if(cdef->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- env_pop(env, scope);
- return GW_OK;
-}
-
ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) {
if(!cdef->base.type)
CHECK_BB(scan0_class_def(env, cdef))
if(cdef->base.ext)
CHECK_BB(scan1_class_parent(env, cdef))
if(cdef->body)
- CHECK_BB(scan1_class_body(env, cdef))
+ CHECK_BB(env_body(env, cdef, scan1_section))
SET_FLAG(cdef->base.type, scan1);
return GW_OK;
}
return GW_OK;
}
-ANN static m_bool scan2_class_body(const Env env, const Class_Def cdef) {
- const m_uint scope = env_push_type(env, cdef->base.type);
- Class_Body body = cdef->body;
- if(cdef->tmpl)
- template_push_types(env, cdef->tmpl->list.list, cdef->tmpl->base);
- do CHECK_BB(scan2_section(env, body->section))
- while((body = body->next));
- if(cdef->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- env_pop(env, scope);
- return GW_OK;
-}
-
ANN m_bool scan2_class_def(const Env env, const Class_Def cdef) {
if(tmpl_class_base(cdef->tmpl))
return GW_OK;
if(cdef->base.ext)
CHECK_BB(scan2_class_parent(env, cdef))
if(cdef->body)
- CHECK_BB(scan2_class_body(env, cdef))
+ CHECK_BB(env_body(env, cdef, scan2_section))
SET_FLAG(cdef->base.type, scan2);
return GW_OK;
}
--- /dev/null
+#include <string.h>
+#include "gwion_util.h"
+#include "gwion_ast.h"
+#include "oo.h"
+#include "env.h"
+#include "type.h"
+#include "nspc.h"
+#include "vm.h"
+#include "parse.h"
+#include "template.h"
+
+ANN static inline m_bool _body(const Env e, Class_Body b, const _exp_func f) {
+ do CHECK_BB(f(e, b->section))
+ while((b = b->next));
+ return GW_OK;
+}
+
+ANN static inline m_uint _push(const Env e, const Class_Def c) {
+ const m_uint scope = env_push_type(e, c->base.type);
+ if(c->tmpl)
+ template_push_types(e, c->tmpl->list.list, c->tmpl->base);
+ return scope;
+}
+
+ANN static inline void _pop(const Env e, const Class_Def c, const m_uint s) {
+ if(c->tmpl)
+ nspc_pop_type(e->gwion->mp, e->curr);
+ env_pop(e, s);
+}
+
+ANN m_bool
+scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) {
+ const m_uint scope = _push(e, c);
+ const m_bool ret = _body(d, c->body, f);
+ _pop(e, c, scope);
+ return ret;
+}