From e111f4c38e10fdaec516cc7df40b6eebf60f592a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 10 Aug 2021 12:09:36 +0200 Subject: [PATCH] :art: Introduce env_set_error --- include/env/context.h | 4 ++++ include/env/env.h | 1 + src/gwion.c | 2 +- src/lib/array.c | 6 +++--- src/lib/lib_func.c | 2 +- src/lib/object_op.c | 2 +- src/parse/check.c | 18 +++++++++--------- src/parse/check_traits.c | 2 ++ src/parse/scan0.c | 4 ++-- src/parse/scan1.c | 3 ++- 10 files changed, 26 insertions(+), 18 deletions(-) diff --git a/include/env/context.h b/include/env/context.h index 3613978a..af191283 100644 --- a/include/env/context.h +++ b/include/env/context.h @@ -15,4 +15,8 @@ REF_FUNC(Context, context) ANN2(1, 3) ANEW Context new_context(MemPool p, const Ast, const m_str); ANN void load_context(const Context, const Env); ANN void unload_context(const Context, const Env); + +ANN static inline void env_set_error(const Env env) { + if(env->context) env->context->error = true; +} #endif diff --git a/include/env/env.h b/include/env/env.h index 7ece02a5..f10594db 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -72,4 +72,5 @@ struct ScopeEffect { ANN void env_add_effect(const Env a, const Symbol effect, const loc_t pos); ANN void call_add_effect(const Env env, const Func func, const loc_t pos); ANN bool check_effect_overload(const Vector base, const Func override); + #endif diff --git a/src/gwion.c b/src/gwion.c index 8c594e19..5de60fa6 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -192,7 +192,7 @@ ANN void env_err(const Env env, const loc_t pos, const m_str fmt, ...) { env_xxx(env, pos, fmt, arg); va_end(arg); #endif - if (env->context) env->context->error = 1; + env_set_error(env); } ANN struct SpecialId_ *specialid_get(const Gwion gwion, const Symbol sym) { diff --git a/src/lib/array.c b/src/lib/array.c index c8102fd9..2f2f103c 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -639,19 +639,19 @@ static OP_CHECK(opck_array_scan) { if (base->size == 0) { gwerr_basic("Can't use type of size 0 as array base", NULL, NULL, "/dev/null", (loc_t) {}, 0); - env->context->error = true; + env_set_error(env); return env->gwion->type[et_error]; } if (!strncmp(base->name, "Ref:[", 5)) { gwerr_basic("Can't use ref types as array base", NULL, NULL, "/dev/null", (loc_t) {}, 0); - env->context->error = true; + env_set_error(env); return env->gwion->type[et_error]; } if (!strncmp(base->name, "Option:[", 5)) { gwerr_basic("Can't use option types as array base", NULL, NULL, "/dev/null", (loc_t) {}, 0); - env->context->error = true; + env_set_error(env); return env->gwion->type[et_error]; } const Symbol sym = array_sym(env, array_base(base), base->array_depth + 1); diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 8818dee4..d0a17d40 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -424,7 +424,7 @@ static void op_narg_err(const Env env, const Func_Def fdef, const loc_t loc) { _("Decayed operators take two arguments"), NULL, env->name, loc, 0); if (fdef) defined_here(fdef->base->func->value_ref); - env->context->error = true; + env_set_error(env); } } static m_bool op_call_narg(const Env env, Exp arg, const loc_t loc) { diff --git a/src/lib/object_op.c b/src/lib/object_op.c index cfff4546..ed06cac7 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -212,7 +212,7 @@ OP_CHECK(opck_object_dot) { exp_self(member)->pos, 0); env_error_footer(env); defined_here(value); - env->context->error = true; + env_set_error(env); } else if (GET_FLAG(value, protect)) exp_setprot(exp_self(member), 1); } diff --git a/src/parse/check.c b/src/parse/check.c index ac361855..08d06c42 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -199,7 +199,7 @@ ANN static inline Type prim_array_match(const Env env, Exp e) { if (prim_array_inner(env, type, e, loc) < 0) err = true; while ((e = e->next)); if (!err) return array_type(env, array_base(type), type->array_depth + 1); - env->context->error = true; + env_set_error(env); return NULL; } @@ -332,7 +332,7 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { gwerr_basic(_("Invalid variable"), _("not legit at this point."), NULL, env->name, prim_pos(data), 0); did_you_mean_nspc(v ? value_owner(env, v) : env->curr, s_name(sym)); - env->context->error = true; + env_set_error(env); return NULL; } prim_self(data)->value = v; @@ -407,7 +407,7 @@ ANN static Type check_prim_map(const Env env, const Exp *data) { prim_exp(data)->type = t; return t; } - env->context->error = true; + env_set_error(env); return NULL; } */ @@ -628,7 +628,7 @@ static void function_alternative(const Env env, const Type f, const Exp args, print_current_args(args); else gw_err(_("and not:\n {G}void{0}\n")); - if (env->context) env->context->error = true; + env_set_error(env); } ANN static m_uint get_type_number(Specialized_List list) { @@ -1039,7 +1039,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { char from[strlen(tdef->type->name) + 39]; sprintf(from, "in `{/+}%s{0}` definition", tdef->type->name); gwerr_secondary(from, env->name, tdef->pos); - if (env->context) env->context->error = true; + env_set_error(env); return GW_ERROR; } /* @@ -1193,7 +1193,7 @@ ANN static inline m_bool cond_type(const Env env, const Exp e) { gwerr_basic(_("invalid repeat condition type"), explain, _("use an integer or cast to int if possible"), env->name, e->pos, 0); - env->context->error = true; + env_set_error(env); return GW_ERROR; } return GW_OK; @@ -1723,7 +1723,7 @@ ANN m_bool check_abstract(const Env env, const Class_Def cdef) { } struct ValueFrom_ *from = f->value_ref->from; gwerr_secondary("implementation missing", from->filename, from->loc); - env->context->error = true; + env_set_error(env); } } return !err ? GW_OK : GW_ERROR; @@ -1801,7 +1801,7 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { if (value_error) { env->class_def = t; env_error_footer(env); - env->context->error = true; + env_set_error(env); return GW_ERROR; } } @@ -1819,7 +1819,7 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { env_err(env, v->from->loc, _("recursive type")); env->context->error = false; env_err(env, value->from->loc, _("recursive type")); - env->context->error = true; + env_set_error(env); type_remref(t, env->gwion); return GW_ERROR; } diff --git a/src/parse/check_traits.c b/src/parse/check_traits.c index 5f7b653b..ce467006 100644 --- a/src/parse/check_traits.c +++ b/src/parse/check_traits.c @@ -122,6 +122,7 @@ ANN bool check_trait_requests(const Env env, const Type t, const ID_List list) { const Trait trait = nspc_lookup_trait1(env->curr, list->xid); if (!trait_nodup(t, list->xid, list->next)) { gwerr_secondary("duplicated trait", trait->filename, trait->loc); + env_set_error(env); return false; } const bool value_error = trait->requested_values.ptr ? check_trait_variables(env, t, trait) : false; @@ -129,5 +130,6 @@ ANN bool check_trait_requests(const Env env, const Type t, const ID_List list) { if (!value_error && !funcs_error) return true; const Value request = (Value)vector_front(&trait->requested_values); gwerr_secondary("from trait", request->from->filename, trait->loc); + env_set_error(env); return false; } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index a72980bb..af4e7ea5 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -321,7 +321,7 @@ ANN static m_bool find_traits(const Env env, ID_List traits, const loc_t pos) { if (!nspc_lookup_trait1(env->curr, traits->xid)) { gwerr_basic(_("can't find trait"), NULL, NULL, env->name, pos, 0); did_you_mean_trait(env->curr, s_name(traits->xid)); - env->context->error = true; + env_set_error(env); return GW_ERROR; } } while ((traits = traits->next)); @@ -460,7 +460,7 @@ ANN static m_bool scan0_trait_def(const Env env, const Trait_Def pdef) { if (exists) { gwerr_basic("trait already defined", NULL, NULL, env->name, pdef->pos, 0); gwerr_secondary("defined here", env->name, exists->loc); - env->context->error = true; + env_set_error(env); return already_defined(env, s, pdef->pos); } if (pdef->traits) CHECK_BB(find_traits(env, pdef->traits, pdef->pos)); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 52ef77d3..63ce1b21 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -64,6 +64,7 @@ ANN static m_bool check_global(const Env env, const Type t, const loc_t pos) { gwerr_secondary("not declared global", from->filename, from->loc); const struct ValueFrom_ *ownerFrom = env->class_def->info->value->from; gwerr_secondary("is global", ownerFrom->filename, ownerFrom->loc); + env_set_error(env); return false; } return true; @@ -347,7 +348,7 @@ ANN static inline m_bool shadow_err(const Env env, const Value v, gwerr_basic(_("shadowing a previously defined variable"), NULL, NULL, env->name, loc, 0); defined_here(v); - env->context->error = true; + env_set_error(env); return GW_ERROR; } -- 2.43.0