From ae90180e2b976006b61841c8c1140baf3556dcd7 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 26 Sep 2019 02:11:54 +0200 Subject: [PATCH] :art: Use valuefrom --- include/value.h | 1 + src/parse/did_you_mean.c | 1 + src/parse/scan0.c | 9 ++------- src/parse/scan1.c | 11 +++-------- src/parse/scan2.c | 6 ++---- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/value.h b/include/value.h index 14cf3d9d..2f592d39 100644 --- a/include/value.h +++ b/include/value.h @@ -20,4 +20,5 @@ struct Value_ { }; ANEW ANN Value new_value(MemPool p, const Type type, const m_str name); +ANN void valuefrom(const Env, struct ValueFrom_*); #endif diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index bfb959f1..d46dcd77 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -3,6 +3,7 @@ #include "gwion_util.h" #include "gwion_ast.h" #include "oo.h" +#include "env.h" #include "nspc.h" #include "value.h" #include "env.h" diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 43d8ba52..6e08e540 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -230,10 +230,7 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { const Type t = union_type(env, nspc, udef->type_xid ?: udef->xid, !!udef->type_xid); udef->value = new_value(env->gwion->mp, t, s_name(udef->xid)); -// set owner ? - udef->value->from->owner_class = env->class_def; - udef->value->from->owner = nspc; - udef->value->from->ctx = env->context; + valuefrom(env, udef->value->from); nspc_add_value(nspc, udef->xid, udef->value); add_type(env, nspc, t); SET_FLAG(t, scan1 | ae_flag_union); @@ -259,9 +256,7 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { const Symbol sym = insert_symbol(name); const Type t = union_type(env, nspc, sym, 1); udef->value = new_value(env->gwion->mp, t, s_name(sym)); - udef->value->from->owner_class = env->class_def; - udef->value->from->owner = nspc; - udef->value->from->ctx = env->context; + valuefrom(env, udef->value->from); nspc_add_value(nspc, udef->xid, udef->value); add_type(env, nspc, t); SET_FLAG(udef->value, checked | udef->flag); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 7c3672fa..092f6fb2 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -105,10 +105,8 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { if(!env->scope->depth && !env->class_def) SET_FLAG(v, global); v->d.ptr = var->addr; -// set from ? - v->from->owner = !env->func ? env->curr : NULL; - v->from->owner_class = env->scope->depth ? NULL : env->class_def; - v->from->ctx = env->context; + if(!env->scope->depth) + valuefrom(env, v->from); } while((list = list->next)); ((Exp_Decl*)decl)->type = decl->list->self->value->type; if(global) @@ -239,14 +237,11 @@ 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); if(env->class_def) { - v->from->owner_class = env->class_def; SET_FLAG(v, static); SET_ACCESS(edef, v) } -// set from ? - v->from->owner = env->curr; - v->from->ctx = env->context; SET_FLAG(v, const | ae_flag_enum | ae_flag_checked); nspc_add_value(edef->t->e->owner, list->xid, v); vector_add(&edef->values, (vtype)v); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index b3f4f81e..ca1544d8 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -70,11 +70,9 @@ ANN static m_bool scan2_args(const Env env, const Func_Def f) { ANN static Value scan2_func_assign(const Env env, const Func_Def d, const Func f, const Value v) { -// set from ? - v->from->owner = env->curr; - v->from->ctx = env->context; + valuefrom(env, v->from); SET_FLAG(v, func | ae_flag_const); - if(!(v->from->owner_class = env->class_def)) + if(!env->class_def) SET_FLAG(v, global); else { if(GET_FLAG(f, member)) -- 2.43.0