From: fennecdjay Date: Tue, 1 Oct 2019 23:12:21 +0000 (+0200) Subject: :art: Improve check_subscript X-Git-Tag: nightly~2198^2~186 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=9c6b56e9c40e0730134c4d94497252b5376c9d2c;p=gwion.git :art: Improve check_subscript --- diff --git a/include/parse.h b/include/parse.h index a3da97f2..8b41eed8 100644 --- a/include/parse.h +++ b/include/parse.h @@ -90,4 +90,5 @@ xxx_cdef(traverse) __attribute__((returns_nonnull)) ANN Type get_type(const Type t); +ANN m_bool check_subscripts(const Env, const Array_Sub); #endif diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index c3060eea..db560281 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -90,7 +90,6 @@ OP_CHECK(opck_post) { return post->exp->type; } -ANN m_bool check_exp_array_subscripts(const Env env, const Exp exp); OP_CHECK(opck_new) { const Exp_Unary* unary = (Exp_Unary*)data; SET_FLAG(unary->td, ref); @@ -101,7 +100,7 @@ OP_CHECK(opck_new) { ERR_N(td_pos(unary->td), _("can't use 'new' on ref type '%s'\n"), t->name) UNSET_FLAG(unary->td, ref); if(unary->td->array) - CHECK_BO(check_exp_array_subscripts(env, unary->td->array->exp)) + CHECK_BO(check_subscripts(env, unary->td->array)) return t; } diff --git a/src/parse/check.c b/src/parse/check.c index eecbe7c2..a517c114 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -54,11 +54,12 @@ ANN static inline m_bool check_implicit(const Env env, const Exp e, const Type t } -ANN m_bool check_exp_array_subscripts(Env env, Exp exp) { - CHECK_OB(check_exp(env, exp)) - do if(isa(exp->type, env->gwion->type[et_int]) < 0) - ERR_B(exp->pos, _("incompatible array subscript type '%s' ..."), exp->type->name) - while((exp = exp->next)); +ANN m_bool check_subscripts(Env env, const Array_Sub array) { + CHECK_OB(check_exp(env, array->exp)) + Exp e = array->exp; + do if(isa(e->type, env->gwion->type[et_int]) < 0) + ERR_B(e->pos, _("incompatible array subscript type '%s' ..."), e->type->name) + while((e = e->next)); return GW_OK; } @@ -164,7 +165,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { if(env->class_def && !env->scope->depth && env->class_def->e->parent) CHECK_BO(check_exp_decl_parent(env, var)) if(var->array && var->array->exp) - CHECK_BO(check_exp_array_subscripts(env, var->array->exp)) + CHECK_BO(check_subscripts(env, var->array)) if(env->class_def) { if(GET_FLAG(decl->td, member)) { decl_member(env, v); @@ -1397,7 +1398,7 @@ ANN static m_bool check_class_parent(const Env env, const Class_Def cdef) { const Type parent = cdef->base.type->e->parent; const Type_Decl *td = cdef->base.ext; if(td->array) - CHECK_BB(check_exp_array_subscripts(env, td->array->exp)) + CHECK_BB(check_subscripts(env, td->array)) if(parent->e->def && !GET_FLAG(parent, check)) CHECK_BB(scanx_parent(parent, traverse_cdef, env)) if(GET_FLAG(parent, typedef))