From 2e6a16b7c3f4ea534095cfcbd574fb74e03f98f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 15 Mar 2021 13:33:37 +0100 Subject: [PATCH] :art: Update --- ast | 2 +- include/env/env.h | 4 ++-- include/env/value.h | 4 +++- src/emit/emit.c | 2 +- src/env/env.c | 4 ++-- src/env/env_utils.c | 4 ++-- src/env/value.c | 4 +++- src/gwion.c | 2 +- src/import/import_fdef.c | 4 ++-- src/import/import_type.c | 2 +- src/lib/lib_func.c | 2 +- src/parse/check.c | 12 ++++++------ src/parse/did_you_mean.c | 12 ++++-------- src/parse/scan0.c | 20 ++++++++++---------- src/parse/scan1.c | 10 +++++----- src/parse/scan2.c | 14 +++++++------- src/plug.c | 2 +- tests/error/func_code_error.gw | 6 ------ 18 files changed, 52 insertions(+), 58 deletions(-) delete mode 100644 tests/error/func_code_error.gw diff --git a/ast b/ast index 7d64efec..0e660735 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 7d64efec6200c89dd2e02dd5ee70ceacb1cea8a2 +Subproject commit 0e66073509c6e408d69c2930c9f6ddae9fd2e892 diff --git a/include/env/env.h b/include/env/env.h index ef51d6bc..63be0aab 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -33,13 +33,13 @@ ANN2(1,3) m_uint env_push(const Env, const Type, const Nspc); ANN static inline m_uint env_push_global(const Env env) { return env_push(env, NULL, env->global_nspc); } ANN void env_pop(const Env, const m_uint); ANN Type scan_type(const Env, const Type, Type_Decl*); -ANN Value mk_class(const Env env, const Type base); +ANN Value mk_class(const Env env, const Type base, const loc_t); ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def); ANN Type known_type(const Env env, Type_Decl*); ANN Type prim_ref(const Env env, const Type t, const Type_Decl* td); ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t pos); ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos); -ANN void env_add_type(const Env, const Type); +ANN void env_add_type(const Env, const Type, const loc_t); ANN Type find_type(const Env, Type_Decl*); ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos); ANN m_bool traverse_func_template(const Env, const Func_Def); diff --git a/include/env/value.h b/include/env/value.h index 066cbbd7..5796979a 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -5,6 +5,8 @@ struct ValueFrom_ { Type owner_class; struct Context_ *ctx; size_t offset; + m_str filename; + loc_t loc; }; enum vflag { @@ -41,5 +43,5 @@ REF_FUNC(Value, value) FLAG_FUNC(Value, v) ANEW ANN Value new_value(MemPool p, const Type type, const m_str name); -ANN void valuefrom(const Env, struct ValueFrom_*); +ANN void valuefrom(const Env, struct ValueFrom_*, const loc_t loc); #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 52a4cb21..10f78c68 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1141,7 +1141,7 @@ static m_bool me_cmp(MemoizeEmitter *me, const Arg_List arg) { const Symbol sym = insert_symbol("=="); struct Exp_ exp = {}; struct Op_Import opi = { .op=sym, .lhs=arg->type, .rhs=arg->type, - .pos=me->fdef->pos, .data=(uintptr_t)&exp.d }; + .pos=me->fdef->base->pos, .data=(uintptr_t)&exp.d }; CHECK_BB(op_emit(emit, &opi)) const Instr instr = emit_add_instr(emit, BranchEqInt); vector_add(&me->branch, (vtype)instr); diff --git a/src/env/env.c b/src/env/env.c index 945a0e96..947e4bb6 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -83,12 +83,12 @@ ANN void env_pop(const Env env, const m_uint scope) { env->scope->depth = scope; } -ANN void env_add_type(const Env env, const Type type) { +ANN void env_add_type(const Env env, const Type type, const loc_t loc) { type->info->owner = env->curr; type->info->owner_class = env->class_def; // t owner_class ? const Symbol sym = insert_symbol(type->name); nspc_add_type_front(env->curr, sym, type); - const Value v = mk_class(env, type); + const Value v = mk_class(env, type, loc); SET_FLAG(v, global); set_vflag(v, vflag_builtin); set_tflag(type, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit); diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 3fbb8026..2bc610ca 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -73,11 +73,11 @@ ANN static Type class_type(const Env env, const Type base) { return t; } -ANN Value mk_class(const Env env, const Type base) { +ANN Value mk_class(const Env env, const Type base, const loc_t loc) { const Type t = class_type(env, base); const Symbol sym = insert_symbol(base->name); const Value v = new_value(env->gwion->mp, t, s_name(sym)); - valuefrom(env, v->from); + valuefrom(env, v->from, loc); SET_FLAG(v, const); set_vflag(v, vflag_valid); nspc_add_value_front(base->info->owner, sym, v); diff --git a/src/env/value.c b/src/env/value.c index eb34932e..c7689f84 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -24,8 +24,10 @@ ANN Value new_value(MemPool p, const Type type, const m_str name) { return a; } -ANN void valuefrom(const Env env, struct ValueFrom_ *from) { +ANN void valuefrom(const Env env, struct ValueFrom_ *from, const loc_t loc) { from->owner = env->curr; from->owner_class = env->class_def; from->ctx = env->context; + from->filename = env->name; + from->loc = loc; } diff --git a/src/gwion.c b/src/gwion.c index f7b43923..2ae6f687 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -149,7 +149,7 @@ ANN static void env_header(const Env env) { if(env->class_def) gwerr_secondary("in class:", env->name, env->class_def->info->cdef->pos); if(env->func && env->func != (Func)1 && env->func->def) - gwerr_secondary("in function:", env->name, env->func->def->pos); + gwerr_secondary("in function:", env->name, env->func->def->base->pos); } ANN static void env_xxx(const Env env, const loc_t pos, const m_str fmt, va_list arg) { diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index 8ecb4cbe..6453b0bc 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -40,7 +40,7 @@ ANN Arg_List make_dll_arg_list(const Vector v) { ANEW ANN static Func_Base* gwi_func_base(const Gwi gwi, ImportCK *ck) { const Arg_List arg_list = make_dll_arg_list(&gwi->ck->v); - Func_Base *base = new_func_base(gwi->gwion->mp, ck->td, ck->sym, arg_list, ck->flag); + Func_Base *base = new_func_base(gwi->gwion->mp, ck->td, ck->sym, arg_list, ck->flag, gwi->loc); if(ck->variadic) base->fbflag |= fbflag_variadic; ck->td = NULL; @@ -53,7 +53,7 @@ ANEW ANN static Func_Base* gwi_func_base(const Gwi gwi, ImportCK *ck) { ANEW ANN static Func_Def import_fdef(const Gwi gwi, ImportCK *ck) { Func_Base* base = gwi_func_base(gwi, ck); - const Func_Def fdef = new_func_def(gwi->gwion->mp, base, NULL, gwi->loc); + const Func_Def fdef = new_func_def(gwi->gwion->mp, base, NULL); return fdef; } diff --git a/src/import/import_type.c b/src/import/import_type.c index f1ed62e7..bfca8fbb 100644 --- a/src/import/import_type.c +++ b/src/import/import_type.c @@ -38,7 +38,7 @@ ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, c } ANN void gwi_add_type(const Gwi gwi, const Type type) { - return env_add_type(gwi->gwion->env, type); + return env_add_type(gwi->gwion->env, type, gwi->loc); } ANN void gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) { diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 6ea745ec..5302e379 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -177,7 +177,7 @@ ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) { if(isa(info->exp->type, env->gwion->type[et_lambda]) < 0) { CHECK_BB(fptr_check(env, info)) if(!(info->exp->type = fptr_type(env, info))) - ERR_B(info->lhs->def->pos, _("no match found")) + ERR_B(info->lhs->def->base->pos, _("no match found")) return GW_OK; } Exp_Lambda *l = &info->exp->d.exp_lambda; diff --git a/src/parse/check.c b/src/parse/check.c index 213cba36..31ec343b 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -621,7 +621,7 @@ ANN static Type_List check_template_args(const Env env, Exp_Call *exp, const Tmp Exp template_arg = exp->args; while(arg && template_arg) { if(list->xid == arg->td->xid) { - tl[args_number] = mk_type_list(env, template_arg->type, fdef->pos); + tl[args_number] = mk_type_list(env, template_arg->type, fdef->base->pos); if(args_number) tl[args_number - 1]->next = tl[args_number]; ++args_number; @@ -776,7 +776,7 @@ ANN static m_bool predefined_call(const Env env, const Type t, const loc_t pos) free_mstr(env->gwion->mp, str); if(tflag(t, tflag_typedef)) { gwerr_secondary("from definition:", - env->name, t->info->func->def->pos); + env->name, t->info->func->def->base->pos); } return GW_ERROR; } @@ -859,15 +859,15 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { if(tdef->when) { const Var_Decl decl = new_var_decl(env->gwion->mp, insert_symbol("self"), NULL, tdef->when->pos); const Arg_List args = new_arg_list(env->gwion->mp, cpy_type_decl(env->gwion->mp, tdef->ext), decl, NULL); - Func_Base *fb = new_func_base(env->gwion->mp, type2td(env->gwion, tdef->type, tdef->when->pos), - insert_symbol("@implicit"), args, ae_flag_none); + Func_Base *fb = new_func_base(env->gwion->mp, type2td(env->gwion, tdef->type, tdef->pos), + insert_symbol("@implicit"), args, ae_flag_none, tdef->pos); set_fbflag(fb, fbflag_op); const Exp helper = new_prim_id(env->gwion->mp, insert_symbol("@predicate"), tdef->when->pos); tdef->when->next = helper; const Stmt stmt = new_stmt_exp(env->gwion->mp, ae_stmt_exp, cpy_exp(env->gwion->mp, tdef->when), tdef->when->pos);// copy exp const Stmt_List body = new_stmt_list(env->gwion->mp, stmt, NULL);//ret_list); const Stmt code = new_stmt_code(env->gwion->mp, body, tdef->when->pos); - const Func_Def fdef = new_func_def(env->gwion->mp, fb, code, tdef->when->pos); + const Func_Def fdef = new_func_def(env->gwion->mp, fb, code); CHECK_BB(traverse_func_def(env, fdef)) const Exp predicate = stmt->d.stmt_exp.val; if(isa(predicate->type, env->gwion->type[et_bool]) < 0) { @@ -1266,7 +1266,7 @@ ANN static m_bool check_func_def_override(const Env env, const Func_Def fdef) { if(env->class_def && env->class_def->info->parent) { const Value override = find_value(env->class_def->info->parent, fdef->base->xid); if(override && override->from->owner_class && isa(override->type, env->gwion->type[et_function]) < 0) - ERR_B(fdef->pos, + ERR_B(fdef->base->pos, _("function name '%s' conflicts with previously defined value...\n" " from super class '%s'..."), s_name(fdef->base->xid), override->from->owner_class->name) diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index 01665eb6..f2e618dc 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -38,8 +38,10 @@ ANN static void ressembles(const Vector v, const Nspc nspc, const char* name) { while(scope_iter(&iter, &value) > 0) { if(vector_find(v, (vtype)value->name) > 0 &&!strcmp(name, value->name)) continue; - if(wagner_fisher(name, value->name)) - vector_add(v, (vtype)value->name); + if(wagner_fisher(name, value->name)) { + if(!vflag(value, vflag_builtin)) + gwerr_secondary("declared here", value->from->filename, value->from->loc); + } } } @@ -54,9 +56,6 @@ ANN void did_you_mean_nspc(Nspc nspc, const char* name) { vector_init(&v); do ressembles(&v, nspc, name); while((nspc = nspc->parent)); - for(m_uint i = 0; i < vector_size(&v); ++i) - gw_err(DYM_FMT, (m_str)vector_at(&v, i)); - vector_release(&v); } #undef did_you_mean_type @@ -67,7 +66,4 @@ ANN void did_you_mean_type(Type type, const char* name) { vector_init(&v); do ressembles(&v, t->nspc, name); while((t = t->info->parent) && t->nspc); - for(m_uint i = 0; i < vector_size(&v); ++i) - gw_err(DYM_FMT, (m_str)vector_at(&v, i)); - vector_release(&v); } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 606b66c6..0d365410 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -56,7 +56,7 @@ ANN static void fptr_assign(const Env env, const Fptr_Def fptr) { static void fptr_def(const Env env, const Fptr_Def fptr) { const Func_Def def = new_func_def(env->gwion->mp, cpy_func_base(env->gwion->mp, fptr->base), - NULL, fptr->base->td->pos); + NULL); fptr->base->func = new_func(env->gwion->mp, s_name(fptr->base->xid), def); fptr->value->d.func_ref = fptr->base->func; fptr->base->func->value_ref = fptr->value; @@ -77,14 +77,14 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { t->nspc = new_nspc(env->gwion->mp, name); t->flag |= fptr->base->flag; fptr->type = t; - fptr->value = mk_class(env, t); - valuefrom(env, fptr->value->from); + fptr->value = mk_class(env, t, fptr->base->pos); + valuefrom(env, fptr->value->from, fptr->base->pos); fptr_def(env, fptr); if(env->class_def) fptr_assign(env, fptr); set_vflag(fptr->value, vflag_func); add_type(env, t->info->owner, t); - mk_class(env, t); + mk_class(env, t, fptr->base->pos); type_addref(t); return GW_OK; } @@ -146,7 +146,7 @@ ANN static void typedef_fptr(const Env env, const Type_Def tdef, const Type base tdef->type->name = s_name(tdef->xid); tdef->type->info->parent = base; add_type(env, env->curr, tdef->type); - mk_class(env, tdef->type); + mk_class(env, tdef->type, tdef->pos); if(base->info->func->def->base->tmpl) set_tflag(tdef->type, tflag_ftmpl); } @@ -189,7 +189,7 @@ ANN static Type enum_type(const Env env, const Enum_Def edef) { t->info->owner = nspc; t->info->owner_class = env->class_def; add_type(env, nspc, t); - mk_class(env, t); + mk_class(env, t, edef->pos); // scan0_implicit_similar(env, t, env->gwion->type[et_int]); return t; } @@ -211,7 +211,7 @@ ANN m_bool scan0_enum_def(const Env env, const Enum_Def edef) { return GW_OK; } -ANN static Type union_type(const Env env, const Symbol s) { +ANN static Type union_type(const Env env, const Symbol s, const loc_t loc) { const m_str name = s_name(s); const Type t = new_type(env->gwion->mp, name, env->gwion->type[et_union]); t->nspc = new_nspc(env->gwion->mp, name); @@ -219,7 +219,7 @@ ANN static Type union_type(const Env env, const Symbol s) { t->info->owner_class = env->class_def; t->info->tuple = new_tupleform(env->gwion->mp, NULL); // ??? add_type(env, env->curr, t); - mk_class(env, t); + mk_class(env, t, loc); SET_FLAG(t, final); if(strncmp(t->name, "Option", 6)) SET_FLAG(t, abstract); @@ -246,7 +246,7 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { if(GET_FLAG(udef, global)) context_global(env); CHECK_BB(scan0_defined(env, udef->xid, udef->pos)) - udef->type = union_type(env, udef->xid); + udef->type = union_type(env, udef->xid, udef->pos); Union_List l = udef->l; do udef->type->nspc->info->offset += SZ_INT; while((l = l->next)); @@ -349,7 +349,7 @@ ANN static m_bool scan0_class_def_inner(const Env env, const Class_Def cdef) { set_tflag(cdef->base.type, tflag_scan0); if(cdef->body) CHECK_BB(env_body(env, cdef, scan0_section)) - (void)mk_class(env, cdef->base.type); + (void)mk_class(env, cdef->base.type, cdef->pos); return GW_OK; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 6c209490..60441a16 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -98,7 +98,7 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { SET_FLAG(v, late); v->flag |= decl->td->flag; if(!env->scope->depth) { - valuefrom(env, v->from); + valuefrom(env, v->from, var->pos); if(env->class_def) { if(env->class_def->info->tuple) tuple_contains(env, v); @@ -323,7 +323,7 @@ ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { do { CHECK_BB(already_defined(env, list->xid, edef->pos)) const Value v = new_value(env->gwion->mp, edef->t, s_name(list->xid)); - valuefrom(env, v->from); + valuefrom(env, v->from, edef->pos); if(env->class_def) { SET_FLAG(v, static); SET_ACCESS(edef, v) @@ -415,7 +415,7 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, Union_Def ude m_uint sz = 0; const Value v = new_value(env->gwion->mp, env->gwion->type[et_int], "@index"); nspc_add_value_front(env->curr, insert_symbol("@index"), v); - valuefrom(env ,v->from); + valuefrom(env, v->from, udef->pos); do { DECL_OB(const Type, t, = known_type(env, l->td)) if(nspc_lookup_value0(env->curr, l->xid)) @@ -424,7 +424,7 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, Union_Def ude if(!tflag(t, tflag_scan1)) // ??? tuple_contains(env, v); // ??? v->from->offset = SZ_INT; - valuefrom(env ,v->from); + valuefrom(env ,v->from, udef->pos); nspc_add_value_front(env->curr, l->xid, v); if(t->size > sz) sz = t->size; @@ -570,7 +570,7 @@ ANN static inline m_bool scan1_fdef_defined(const Env env, const Func_Def fdef) if(isa(actual_type(env->gwion, v->type), env->gwion->type[et_function]) > 0) return GW_OK; if((!env->class_def || !GET_FLAG(env->class_def, final)) && !nspc_lookup_value0(env->curr, fdef->base->xid)) - ERR_B(fdef->pos, _("function '%s' has already been defined in the same scope..."), + ERR_B(fdef->base->pos, _("function '%s' has already been defined in the same scope..."), s_name(fdef->base->xid)) return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index ea0a5cc9..43b059be 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -60,7 +60,7 @@ ANN static m_bool scan2_args(const Func_Def f) { ANN static Value scan2_func_assign(const Env env, const Func_Def d, const Func f, const Value v) { - valuefrom(env, v->from); + valuefrom(env, v->from, d->base->pos); SET_FLAG(v, const); set_vflag(v, vflag_func); if(!env->class_def) { @@ -277,15 +277,15 @@ ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, const const m_bool fptr = is_fptr(env->gwion, overload->type); if(isa(overload->type, env->gwion->type[et_function]) < 0 || is_fptr(env->gwion, overload->type)) { if(!fbflag(f->base, fbflag_internal)) - ERR_B(f->pos, _("function name '%s' is already used by another value"), overload->name) + ERR_B(f->base->pos, _("function name '%s' is already used by another value"), overload->name) } const Func obase = !fptr ? overload->d.func_ref : _class_base(overload->type)->info->func; if(GET_FLAG(obase->def->base, final)) - ERR_B(f->pos, _("can't overload final function %s"), overload->name) + ERR_B(f->base->pos, _("can't overload final function %s"), overload->name) const m_bool base = tmpl_base(f->base->tmpl); const m_bool tmpl = fflag(obase, fflag_tmpl); if((!tmpl && base) || (tmpl && !base && !f->base->tmpl)) - ERR_B(f->pos, _("must overload template function with template")) + ERR_B(f->base->pos, _("must overload template function with template")) return GW_OK; } @@ -313,7 +313,7 @@ ANN2(1,2) static Value func_value(const Env env, const Func f, const Value overload) { const Type t = func_type(env, f); const Value v = new_value(env->gwion->mp, t, t->name); - valuefrom(env, v->from); + valuefrom(env, v->from, f->def->base->pos); CHECK_OO(scan2_func_assign(env, f->def, f, v)) if(!overload) { value_addref(v); @@ -351,7 +351,7 @@ ANN2(1, 2) static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, const } if(compat_func(ff->def, f) > 0) { if(ff->value_ref->from->owner == env->curr) - ERR_B(f->pos, "template function '%s' already defined with those arguments in this namespace", name) + ERR_B(f->base->pos, "template function '%s' already defined with those arguments in this namespace", name) const Symbol sym = func_symbol(env, env->curr->name, name, "template", ff->vt_index); nspc_add_value(env->curr, sym, value); @@ -380,7 +380,7 @@ ANN2(1, 2) static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, const ANN static m_bool scan2_func_def_op(const Env env, const Func_Def f) { const m_str str = s_name(f->base->xid); struct Op_Func opfunc = { .ck=strcmp(str, "@implicit") ? 0 : opck_usr_implicit }; - struct Op_Import opi = { .ret=f->base->ret_type, .pos=f->pos, + struct Op_Import opi = { .ret=f->base->ret_type, .pos=f->base->pos, .data=(uintptr_t)f->base->func, .func=&opfunc }; func_operator(f, &opi); CHECK_BB(add_op(env->gwion, &opi)) diff --git a/src/plug.c b/src/plug.c index 42800aed..5ed27f5e 100644 --- a/src/plug.c +++ b/src/plug.c @@ -50,7 +50,7 @@ ANN static void plug_get(struct PlugHandle *h, const m_str c) { Plug plug = new_plug(h->mp, dl); map_set(h->map, (vtype)strdup(name), (vtype)plug); } else - gw_err(_("error in %s."), DLERROR()); + gw_err(_("{+R}error{0} in {/+}%s{0}."), DLERROR()); } ANN static void plug_get_all(struct PlugHandle *h, const m_str name) { diff --git a/tests/error/func_code_error.gw b/tests/error/func_code_error.gw deleted file mode 100644 index 11262c4b..00000000 --- a/tests/error/func_code_error.gw +++ /dev/null @@ -1,6 +0,0 @@ -#! [contains] in function: -class C { - fun void test() { - <<< b >>>; - } -} -- 2.43.0