From 939be8330020221425364fcefb3586a2872e9403 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 3 Oct 2019 02:52:54 +0200 Subject: [PATCH] :shirt: Some clean --- include/gwion_all.h | 1 - include/optim.h | 11 ----------- src/emit/escape.c | 1 - src/parse/check.c | 1 - src/parse/scan1.c | 20 +++++++++++--------- src/parse/scan2.c | 42 +++++++++--------------------------------- src/parse/type_utils.c | 7 +------ 7 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 include/optim.h diff --git a/include/gwion_all.h b/include/gwion_all.h index 5a3ad317..21c56409 100644 --- a/include/gwion_all.h +++ b/include/gwion_all.h @@ -25,7 +25,6 @@ #include "oo.h" #include "opcode.h" #include "operator.h" -#include "optim.h" #include "parse.h" #include "plug.h" #include "shreduler_private.h" diff --git a/include/optim.h b/include/optim.h deleted file mode 100644 index f90783e4..00000000 --- a/include/optim.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __OPTIM -#define __OPTIM -#ifdef OPTIMIZE -#define OPTIMIZE_CONST(a) CHECK_BO(optimize_const(a)) -ANN m_bool optimize_const(const Env, const Exp_Binary*); -//ANN2(1) void constprop_prim(const Exp_Primary* p, m_uint* ptr); -#else -#define OPTIMIZE_CONST(a) -#endif -m_bool constant_folding(const Env, const Exp_Binary*); -#endif diff --git a/src/emit/escape.c b/src/emit/escape.c index c5493c09..e0c7ca47 100644 --- a/src/emit/escape.c +++ b/src/emit/escape.c @@ -76,4 +76,3 @@ m_bool escape_str(const Emitter emit, const m_str base, const loc_t pos) { ANN m_int str2char(const Emitter emit, const m_str c, const loc_t pos) { return c[0] != '\\' ? c[0] : get_escape(emit, c[1], pos); } - diff --git a/src/parse/check.c b/src/parse/check.c index 975a4e7c..32537ead 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -11,7 +11,6 @@ #include "object.h" #include "traverse.h" #include "template.h" -#include "optim.h" #include "gwion.h" #include "operator.h" #include "import.h" diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 0cf1cf86..a6f31899 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -42,11 +42,9 @@ ANN static m_bool type_recursive(const Env env, const Type_Decl *td, const Type ANN static Type void_type(const Env env, const Type_Decl* td) { DECL_OO(const Type, type, = known_type(env, td)) -{ const Type t = get_type(type); if(isa(t, env->gwion->type[et_object]) > 0) CHECK_BO(type_recursive(env, td, t)) -} if(type->size) return type; ERR_O(td_pos(td), _("cannot declare variables of size '0' (i.e. 'void')...")) @@ -384,7 +382,7 @@ ANN static m_bool scan_internal(const Env env, const Func_Base *base) { op == insert_symbol("@conditionnal") || op == insert_symbol("@unconditionnal")) return scan_internal_int(env, base); - return GW_ERROR; + return GW_OK; } ANN m_bool scan1_fdef(const Env env, const Func_Def fdef) { @@ -417,16 +415,20 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { DECL_SECTION_FUNC(scan1) +ANN static Type scan1_get_parent(const Env env, const Type_Def tdef) { + DECL_OO(const Type , parent, = tdef->type->e->parent = known_type(env, tdef->ext)) + Type t = parent; + do if(tdef->type == t) + ERR_O(td_pos(tdef->ext), _("recursive (%s <= %s) class declaration."), tdef->type->name, t->name) + while((t = t->e->parent)); + return parent; +} + ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { const loc_t pos = td_pos(cdef->base.ext); if(cdef->base.ext->array) CHECK_BB(scan1_exp(env, cdef->base.ext->array->exp)) - DECL_OB(const Type , parent, = cdef->base.type->e->parent = known_type(env, cdef->base.ext)) - Type t = parent; - do { - if(cdef->base.type == t) - ERR_B(pos, _("recursive (%s <= %s) class declaration."), cdef->base.type->name, t->name); - } while((t = t->e->parent)); + DECL_OB(const Type , parent, = scan1_get_parent(env, &cdef->base)) if(isa(parent, env->gwion->type[et_object]) < 0) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) if(parent->e->def && !GET_FLAG(parent, scan1)) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index b870d119..6f729a53 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -9,12 +9,10 @@ #include "func.h" #include "template.h" #include "traverse.h" -#include "optim.h" #include "parse.h" #include "nspc.h" #include "operator.h" #include "object.h" - #include "instr.h" #include "import.h" #include "tuple.h" @@ -114,19 +112,9 @@ ANN static inline Value prim_value(const Env env, const Symbol s) { } ANN static inline m_bool scan2_exp_primary(const Env env, const Exp_Primary* prim) { - if(prim->primary_type == ae_primary_hack) { + if(prim->primary_type == ae_primary_hack) CHECK_BB(scan2_exp(env, prim->d.exp)) - Exp e = prim->d.exp; - do { - if(e->exp_type == ae_exp_decl) { - Var_Decl_List l = e->d.exp_decl.list; - do { - const Value v = l->self->value; - SET_FLAG(v, used); - }while ((l = l->next)); - } - } while((e = e->next)); - } else if(prim->primary_type == ae_primary_id) { + else if(prim->primary_type == ae_primary_id) { const Value v = prim_value(env, prim->d.var); if(v) SET_FLAG(v, used); @@ -142,7 +130,6 @@ ANN static inline m_bool scan2_exp_array(const Env env, const Exp_Array* array) return scan2_exp(env, array->array->exp); } - ANN static m_bool multi_decl(const Env env, const Exp e, const Symbol op) { if(e->exp_type == ae_exp_decl) { if(e->d.exp_decl.list->next) @@ -424,9 +411,8 @@ ANN static m_bool scan2_func_def_op(const Env env, const Func_Def f) { f->base->ret_type : NULL; struct Op_Import opi = { .op=f->base->xid, .lhs=l, .rhs=r, .ret=f->base->ret_type, .pos=f->pos, .data=(uintptr_t)f->base->func }; - if(!strcmp(str, "@implicit")) { + if(!strcmp(str, "@implicit")) opi.ck = opck_usr_implicit; - } CHECK_BB(add_op(env->gwion, &opi)) operator_set_func(&opi); return GW_OK; @@ -455,7 +441,8 @@ ANN static m_str func_tmpl_name(const Env env, const Func_Def f) { vector_init(&v); do { const Type t = nspc_lookup_type0(env->curr, id->xid); - if(!t)continue; + if(!t) + continue; vector_add(&v, (vtype)t); tlen += strlen(t->name); } while((id = id->next) && ++tlen); @@ -487,25 +474,14 @@ ANN2(1,2,4) static Value func_create(const Env env, const Func_Def f, return v; } - -ANN static m_str template_helper(const Env env, const Func_Def f) { - const m_str name = f->base->func ? f->base->func->name : func_tmpl_name(env, f); - if(!name) - return(m_str)GW_ERROR; - const Func func = nspc_lookup_func0(env->curr, insert_symbol(name)); - if(func) { - f->base->ret_type = known_type(env, f->base->td); - return (m_str)(m_uint)((f->base->args && f->base->args->type) ? scan2_args(env, f) : GW_OK); - } - return name; -} - ANN2(1,2) static m_str func_name(const Env env, const Func_Def f, const Value v) { if(!f->base->tmpl) { - const Symbol sym = func_symbol(env, env->curr->name, s_name(f->base->xid), NULL, v ? ++v->from->offset : 0); + const Symbol sym = func_symbol(env, env->curr->name, + s_name(f->base->xid), NULL, v ? ++v->from->offset : 0); return s_name(sym); } - return template_helper(env, f); + const m_str name = f->base->func ? f->base->func->name : func_tmpl_name(env, f); + return name ?: (m_str)GW_ERROR; } ANN2(1,2) m_bool scan2_fdef_std(const Env env, const Func_Def f, const Value overload) { diff --git a/src/parse/type_utils.c b/src/parse/type_utils.c index 4474cf19..f9564be7 100644 --- a/src/parse/type_utils.c +++ b/src/parse/type_utils.c @@ -4,8 +4,6 @@ #include "gwion_ast.h" #include "oo.h" #include "env.h" -#include "value.h" -#include "type.h" #include "vm.h" #include "traverse.h" #include "parse.h" @@ -29,8 +27,5 @@ ANN void type_path(const m_str str, ID_List l) { const m_str name = s_name(l->xid); strcpy(s, name); s += strlen(name); - if(l->next) - strcpy(s++, "."); - } - while((l = l->next)); + } while((l = l->next) && strcpy(s++, ".")); } -- 2.43.0