From 5b6dd6edd5f1577d09e7a3cebf82f8c8135d2de6 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 4 Nov 2019 13:52:15 +0100 Subject: [PATCH] :art: coverage --- include/import/checker.h | 21 +++------------------ src/import/checker.c | 4 ++-- src/import/oper.c | 4 ++-- src/oo/env_utils.c | 8 ++++++++ tests/import/array_in_var_name.c | 2 +- tests/import/array_in_var_name_fail.c | 19 +++++++++++++++++++ tests/import/not_importing.c | 17 +++++++++++++++++ 7 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 tests/import/array_in_var_name_fail.c create mode 100644 tests/import/not_importing.c diff --git a/include/import/checker.h b/include/import/checker.h index 02ce92e4..52e8b7a3 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -15,47 +15,32 @@ typedef struct ImportCK { // name_checker ? Symbol sym; union { ID_List tmpl; - Type (*ck)(Env, void*, m_bool*); // oper Exp exp; }; union { Symbol xid;// union name - Instr (*em)(Emitter, void*); // oper f_xfun addr; }; union { Decl_List list;// union struct Vector_ v; // ID_List curr;// enum - m_str lhs;// oper }; union { Type_Decl *td; // typedef ID_List curr;// enum - m_str rhs;// oper }; ae_flag flag; // ???? enum importck_type type; } ImportCK; typedef struct OperCK { // name_checker ? - m_str name; + m_str ret; Symbol sym; Type (*ck)(Env, void*, m_bool*); // oper Instr (*em)(Emitter, void*); // oper - union { - Decl_List list;// union - struct Vector_ v; -// ID_List curr;// enum - m_str lhs;// oper - }; - union { - Type_Decl *td; // typedef - ID_List curr;// enum - m_str rhs;// oper - }; - ae_flag flag; // ???? - enum importck_type type; + m_str lhs;// oper + m_str rhs;// oper } OperCK; struct array_checker { diff --git a/src/import/checker.c b/src/import/checker.c index b713fec3..c588538e 100644 --- a/src/import/checker.c +++ b/src/import/checker.c @@ -94,7 +94,7 @@ ANN Var_Decl str2var(const Gwi gwi, const m_str path) { } ANN Var_Decl_List str2varlist(const Gwi gwi, const m_str path) { - const Var_Decl var = str2var(gwi, path); + DECL_OO(const Var_Decl, var, = str2var(gwi, path)) return new_var_decl_list(gwi->gwion->mp, var, NULL); } @@ -273,7 +273,7 @@ ANN m_bool _array_check(const Gwi gwi, struct array_checker *ck) { break; } ++ck->depth; - return is_end ? GW_OK : array_check(gwi, ck); + return is_end ? GW_OK : _array_check(gwi, ck); } if(isdigit(c)) tmp[i] = c; diff --git a/src/import/oper.c b/src/import/oper.c index 556b574d..54835564 100644 --- a/src/import/oper.c +++ b/src/import/oper.c @@ -40,7 +40,7 @@ ANN2(1,2) static int import_op(const Gwi gwi, const struct OperCK* op, const f_instr f) { const Type lhs = get_type(gwi, op->lhs), rhs = get_type(gwi, op->rhs), - ret = get_type(gwi, op->name); + ret = get_type(gwi, op->ret); const struct Op_Import opi = { lhs, rhs, ret, op->ck, op->em, (uintptr_t)f, gwi->loc, op->sym }; return add_op(gwi->gwion, &opi); @@ -49,7 +49,7 @@ ANN2(1,2) static int import_op(const Gwi gwi, const struct OperCK* op, ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const restrict m_str l, const restrict m_str r, const restrict m_str t) { - gwi->oper->name = t; + gwi->oper->ret = t; gwi->oper->rhs = r; gwi->oper->lhs = l; return GW_OK; diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index dc029ed0..caa3a4d2 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -36,6 +36,14 @@ ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos) { ANN Type find_type(const Env env, ID_List path) { Type type = nspc_lookup_type1(env->curr, path->xid); +if(!type && env->class_def) { + Type base = env->class_def->e->parent; + while(base && base->nspc) { + if((type = nspc_lookup_type1(base->nspc, path->xid))) + break; + } +} + CHECK_OO(type) Nspc nspc = type->nspc; path = path->next; diff --git a/tests/import/array_in_var_name.c b/tests/import/array_in_var_name.c index bc78e3ef..4ebb96e1 100644 --- a/tests/import/array_in_var_name.c +++ b/tests/import/array_in_var_name.c @@ -13,6 +13,6 @@ #include "gwi.h" GWION_IMPORT(checker) { - gwi_item_ini(gwi, "int", "array[]"); + gwi_item_ini(gwi, "int", "array[2][3]"); return GW_OK; } diff --git a/tests/import/array_in_var_name_fail.c b/tests/import/array_in_var_name_fail.c new file mode 100644 index 00000000..31aabf93 --- /dev/null +++ b/tests/import/array_in_var_name_fail.c @@ -0,0 +1,19 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" +#include "gwi.h" + +GWION_IMPORT(checker) { + GWI_BB(gwi_union_ini(gwi, NULL, NULL)) + GWI_BB(gwi_union_add(gwi, "int", "|array[2][3]")) + return GW_OK; +} diff --git a/tests/import/not_importing.c b/tests/import/not_importing.c new file mode 100644 index 00000000..836ab3c0 --- /dev/null +++ b/tests/import/not_importing.c @@ -0,0 +1,17 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" + +GWION_IMPORT(enum_test) { + GWI_BB(gwi_enum_add(gwi, "adc", 0)) + return GW_OK; +} -- 2.43.0