From: fennecdjay Date: Tue, 26 Jul 2022 14:40:12 +0000 (+0200) Subject: :bug: Improve scan0 X-Git-Tag: nightly~264^2~78 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7c90e78c9419fe2f881e6310d06c25fc6849a8f8;p=gwion.git :bug: Improve scan0 --- diff --git a/src/parse/scan0.c b/src/parse/scan0.c index ded15e62..88eb7ee2 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -206,9 +206,6 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { return GW_OK; } -#define scan0_nspc(env, a) \ - GET_FLAG(a, global) ? !env->class_def ? env->global_nspc : NULL : env->curr - #include "gack.h" static GACK(gack_enum) { const Map m = &t->nspc->info->value->map; @@ -323,9 +320,9 @@ ANN static Type get_parent_base(const Env env, Type_Decl *td) { } ANN static inline Type scan0_final(const Env env, Type_Decl *td) { - DECL_OO(const Type, t, = known_type(env, td)); - if (!GET_FLAG(t, final)) return t; - ERR_O(td->pos, _("can't inherit from final parent class '%s'\n."), t->name); + const Type t = find_type(env, td); + if(!t) ERR_O(td->pos, _("can't find parent class %s\n."), s_name(td->xid)); + return t; } ANN static Type cdef_parent(const Env env, const Class_Def cdef) { @@ -336,7 +333,7 @@ ANN static Type cdef_parent(const Env env, const Class_Def cdef) { if (tmpl) template_push_types(env, cdef->base.tmpl); const Type t = scan0_final(env, cdef->base.ext); if (tmpl) nspc_pop_type(env->gwion->mp, env->curr); - return t ?: (Type)GW_ERROR; + return t; } ANN static m_bool find_traits(const Env env, ID_List traits, const loc_t pos) { @@ -354,8 +351,7 @@ ANN static m_bool find_traits(const Env env, ID_List traits, const loc_t pos) { ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { CHECK_BO(scan0_defined(env, cdef->base.xid, cdef->pos)); - const Type parent = cdef_parent(env, cdef); - if (parent == (Type)GW_ERROR) return NULL; + DECL_OO(const Type, parent, = cdef_parent(env, cdef)); if(GET_FLAG(cdef, global) && isa(parent, env->gwion->type[et_closure]) < 0 && !type_global(env, parent)) { gwerr_basic(_("parent type is not global"), NULL, NULL, env->name, cdef->base.ext ? cdef->base.ext->pos : cdef->base.pos, 0); const Value v = parent->info->value; @@ -518,9 +514,8 @@ ANN static m_bool scan0_class_def_inner(const Env env, const Class_Def cdef) { return ret; } - - ANN Ast spread_class(const Env env, const Ast body); + ANN m_bool scan0_class_def(const Env env, const Class_Def c) { CHECK_BB(scan0_global(env, c->flag, c->pos)); const Ast old_extend = env->context ? env->context->extend : NULL; diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 456fdcbf..2a9698b3 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -143,8 +143,8 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { } else set_vflag(v, vflag_fglobal); // file global } else if (GET_FLAG(decl->td, global)) SET_FLAG(v, global); - else if(v->type != env->gwion->type[et_auto] && v->type != env->class_def) { - type_addref(v->type); + else if(v->type != env->gwion->type[et_auto] && v->type != env->class_def) { + type_addref(v->type); set_vflag(v, vflag_inner); // file global } ((Exp_Decl *)decl)->type = decl->vd.value->type; @@ -731,7 +731,14 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { return GW_OK; } +ANN static inline Type scan1_final(const Env env, Type_Decl *td, const bool tdef) { + DECL_OO(const Type, t, = known_type(env, td)); + if (!GET_FLAG(t, final) || tdef) return t; + ERR_O(td->pos, _("can't inherit from final parent class '%s'\n."), t->name); +} + ANN static m_bool cdef_parent(const Env env, const Class_Def cdef) { + CHECK_OB((cdef->base.type->info->parent = scan1_final(env, cdef->base.ext, tflag(cdef->base.type, tflag_typedef)))); const bool tmpl = !!cdef->base.tmpl; if (tmpl) CHECK_BB(template_push_types(env, cdef->base.tmpl)); const m_bool ret = scan1_parent(env, cdef); @@ -743,8 +750,8 @@ ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { if (tmpl_base(cdef->base.tmpl)) return GW_OK; const Type t = cdef->base.type; if (tflag(t, tflag_scan1)) return GW_OK; - const Class_Def c = t->info->cdef; set_tflag(t, tflag_scan1); + const Class_Def c = t->info->cdef; if (c->base.ext) CHECK_BB(cdef_parent(env, c)); if (c->body) CHECK_BB(env_body(env, c, scan1_section)); return GW_OK;