From 8eda5772e2c4e8a806d2ceb255dbe98d70dbb015 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 11 Aug 2021 19:51:42 +0200 Subject: [PATCH] :bug: Fix array types --- include/env/type.h | 2 ++ src/emit/emit.c | 2 -- src/env/envset.c | 4 ++++ src/env/type.c | 18 ++++++++++++++++++ src/parse/check.c | 2 -- src/parse/scan1.c | 20 -------------------- src/parse/scan2.c | 2 -- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/include/env/type.h b/include/env/type.h index 288cba6e..6a68f189 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -82,6 +82,8 @@ ANN __attribute__((returns_nonnull)) static inline Type _class_base(Type t) { } ANN m_uint get_depth(const Type type); ANN void inherit(const Type); +ANN bool type_global(const Env env, Type t); +ANN bool from_global_nspc(const Env env, const Nspc nspc); __attribute__((returns_nonnull)) ANN static inline Type get_gack(Type t) { do diff --git a/src/emit/emit.c b/src/emit/emit.c index 3f590e2e..dbc95e48 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -2766,8 +2766,6 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { if (tflag(t, tflag_emit)) return GW_OK; set_tflag(t, tflag_emit); const Class_Def c = t->info->cdef; - const Type owner = t->info->value->from->owner_class; - if (owner) CHECK_BB(ensure_emit(emit, owner)); if (c->base.ext && t->info->parent->info->cdef && !tflag(t->info->parent, tflag_emit)) // ????? CHECK_BB(cdef_parent(emit, c)); diff --git a/src/env/envset.c b/src/env/envset.c index 2be348fe..6e03141b 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -43,6 +43,8 @@ ANN2(1, 3) m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) { if (t) { check(es, t); + if(es->run && type_global(es->env, t)) + env_push_global(es->env); return es->run ? push(es, t) : GW_OK; } if (nspc != es->env->curr) { @@ -66,6 +68,8 @@ ANN2(1) static void _envset_pop(struct EnvSet *es, const Type t) { ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { _envset_pop(es, t); + if(t && type_global(es->env, t)) + env_pop(es->env, es->scope); if (es->_ctx) es->env->context = es->_ctx; if (es->_filename) es->env->name = es->_filename; } diff --git a/src/env/type.c b/src/env/type.c index b5e9ff99..0d2755c7 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -157,3 +157,21 @@ ANN void inherit(const Type t) { nspc->offset = parent->offset; if (parent->vtable.ptr) vector_copy2(&parent->vtable, &nspc->vtable); } + +ANN bool from_global_nspc(const Env env, const Nspc nspc) { + Nspc global = env->global_nspc; + while(global) { + if (nspc == global) + return true; + global = global->parent; + } + return false; +} + +ANN bool type_global(const Env env, Type t) { + while(t) { + if(from_global_nspc(env, t->info->value->from->owner)) return true; + t = t->info->value->from->owner_class; + } + return false; +} diff --git a/src/parse/check.c b/src/parse/check.c index 08d06c42..c2e3e5d3 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1839,8 +1839,6 @@ ANN m_bool check_class_def(const Env env, const Class_Def cdef) { .data = (uintptr_t)c, .pos = c->pos}; CHECK_OB(op_check(env, &opi)); - if (t->info->value->from->owner_class) - CHECK_BB(ensure_check(env, t->info->value->from->owner_class)); if (tflag(t, tflag_check)) return GW_OK; set_tflag(t, tflag_check); return _check_class_def(env, c); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 63ce1b21..0a22703d 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -35,24 +35,6 @@ ANN static inline m_bool ensure_scan1(const Env env, const Type t) { return envset_run(&es, t); } -ANN static inline bool from_global_nspc(const Env env, const Nspc nspc) { - Nspc global = env->global_nspc; - while(global) { - if (nspc == global) - return true; - global = global->parent; - } - return false; -} - -ANN static bool type_global(const Env env, Type t) { - while(t) { - if(from_global_nspc(env, t->info->value->from->owner)) return true; - t = t->info->value->from->owner_class; - } - return false; -} - ANN static m_bool check_global(const Env env, const Type t, const loc_t pos) { const struct ValueFrom_ *from = t->info->value->from; if(from->owner_class && isa(from->owner_class, env->class_def) > 0) @@ -754,8 +736,6 @@ ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { const Class_Def c = t->info->cdef; if (tflag(t, tflag_scan1)) return GW_OK; set_tflag(t, tflag_scan1); - if (t->info->value->from->owner_class) - CHECK_BB(ensure_scan1(env, t->info->value->from->owner_class)); if (c->base.ext) CHECK_BB(cdef_parent(env, c)); if (c->body) CHECK_BB(env_body(env, c, scan1_section)); return GW_OK; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index b56419b2..f7f03d4d 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -610,8 +610,6 @@ ANN m_bool scan2_class_def(const Env env, const Class_Def cdef) { const Type t = cdef->base.type; const Class_Def c = t->info->cdef; if (tflag(t, tflag_scan2)) return GW_OK; - if (t->info->value->from->owner_class) - CHECK_BB(ensure_scan2(env, t->info->value->from->owner_class)); set_tflag(t, tflag_scan2); if (c->base.ext) CHECK_BB(cdef_parent(env, c)); if (c->body) CHECK_BB(env_body(env, c, scan2_section)); -- 2.43.0