From de70d887c218335368a004b88e0fb7598a98606d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 30 Mar 2020 23:49:29 +0200 Subject: [PATCH] :art: Plug fixes --- src/import/checker.c | 17 ++++++----------- src/import/tdef.c | 8 +++++--- tests/import/invalid_names.c | 2 +- tests/import/invalid_names0.c | 18 ++++++++++++++++++ tests/import/invalid_names1.c | 18 ++++++++++++++++++ tests/import/invalid_names2.c | 18 ++++++++++++++++++ tests/import/invalid_names3.c | 18 ++++++++++++++++++ tests/sh/import.sh | 2 +- 8 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 tests/import/invalid_names0.c create mode 100644 tests/import/invalid_names1.c create mode 100644 tests/import/invalid_names2.c create mode 100644 tests/import/invalid_names3.c diff --git a/src/import/checker.c b/src/import/checker.c index 8794839c..58d8b60f 100644 --- a/src/import/checker.c +++ b/src/import/checker.c @@ -29,7 +29,6 @@ ANN static m_bool check_illegal(const char c, const m_uint i) { } /** convert a string to a symbol, with error checking **/ -//ANN Symbol str2sym(const Env env, const m_str path, const loc_t pos) { ANN Symbol str2sym(const Gwi gwi, const m_str path) { const size_t sz = strlen(path); m_uint i; @@ -56,16 +55,12 @@ ANN ID_List path_valid(const Gwi gwi, const m_str path) { const size_t sz = strlen(path); if(path[0] == '.' || path[sz] == '.') GWI_ERR_O(_("path '%s' must not ini or end with '.'."), path) -// DECL_OO(const Symbol, sym, = str2sym(gwi, path)) -// const ID_List list = new_id_list(gwi->gwion->mp, sym, loc(gwi)); - const ID_List list = str2symlist(gwi, path); + DECL_OO(const ID_List, list, = str2symlist(gwi, path)) if(strlen(s_name(list->xid)) < sz) list->next = path_valid(gwi, path + strlen(s_name(list->xid))); return list; } - -// // similar to import array_sub ? ANN Array_Sub ck_array(MemPool mp, const m_uint depth) { if(!depth) @@ -96,7 +91,6 @@ ANN Var_Decl_List str2varlist(const Gwi gwi, const m_str path) { struct tmpl_checker { const m_str str; ID_List list; -// const loc_t pos; }; ANN static m_bool tmpl_list(const Gwi gwi, struct tmpl_checker *ck) { @@ -220,9 +214,7 @@ ANN Type_Decl* str2decl(const Gwi gwi, const m_str str) { // we can do better DECL_OO(const m_str, type_name, = get_type_name(gwi->gwion->env, s, 0)) struct array_checker ck = { .str=type_name }; - const ID_List id = ck2list(gwi, &ck); - if(id == (ID_List)GW_ERROR) - return NULL; + DECL_OO(const ID_List, id, = ck2list(gwi, &ck)) Type_Decl* td = new_type_decl(gwi->gwion->mp, id); const m_str tl_name = get_type_name(gwi->gwion->env, s, 1); if(tl_name) { @@ -297,8 +289,10 @@ ANN m_bool check_typename_def(const Gwi gwi, ImportCK *ck) { str[strlen(base) - (c ? strlen(c) : 0)] = '\0'; ck->name = str; CHECK_OB((ck->sym = str2sym(gwi, str))) - if(c && (ck->tmpl = tmpl_valid(gwi, c)) == (ID_List)GW_ERROR) + ID_List tmpl = NULL; + if(c && (tmpl = tmpl_valid(gwi, c)) == (ID_List)GW_ERROR) return GW_ERROR; + ck->tmpl = tmpl; ck->name = base; return GW_OK; } @@ -338,5 +332,6 @@ NULL,// ck_clean_oper, ANN void ck_clean(const Gwi gwi) { cleaners[gwi->ck->type](gwi->gwion->mp, gwi->ck); + memset(gwi->ck, 0, sizeof(ImportCK)); } diff --git a/src/import/tdef.c b/src/import/tdef.c index d1f9a798..4fa9d050 100644 --- a/src/import/tdef.c +++ b/src/import/tdef.c @@ -19,9 +19,11 @@ ANN m_int gwi_typedef_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) { CHECK_BB(ck_ini(gwi, ck_tdef)) gwi->ck->name = name; - if(check_typename_def(gwi, gwi->ck) > 0) - return (gwi->ck->td = str2decl(gwi, type)) ? GW_OK : GW_ERROR; - return GW_ERROR; + CHECK_BB(check_typename_def(gwi, gwi->ck)) + return (gwi->ck->td = str2decl(gwi, type)) ? GW_OK : GW_ERROR; +// if(check_typename_def(gwi, gwi->ck) > 0) +// return (gwi->ck->td = str2decl(gwi, type)) ? GW_OK : GW_ERROR; +// return GW_ERROR; } ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { diff --git a/tests/import/invalid_names.c b/tests/import/invalid_names.c index 6ee7f340..66ec9711 100644 --- a/tests/import/invalid_names.c +++ b/tests/import/invalid_names.c @@ -13,7 +13,7 @@ #include "gwi.h" GWION_IMPORT(trig) { - const Type t0 = gwi_mk_type(gwi, "T~", SZ_INT, NULL); + DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T~", SZ_INT, NULL)) gwi_add_type(gwi, t0); const Type t1 = gwi_mk_type(gwi, "T,", SZ_INT, NULL); diff --git a/tests/import/invalid_names0.c b/tests/import/invalid_names0.c new file mode 100644 index 00000000..70114574 --- /dev/null +++ b/tests/import/invalid_names0.c @@ -0,0 +1,18 @@ +#include +#include +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "gwion.h" +#include "instr.h" +#include "object.h" +#include "operator.h" +#include "import.h" +#include "ugen.h" +#include "gwi.h" + +GWION_IMPORT(trig) { + DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T~", SZ_INT, NULL)) + return gwi_add_type(gwi, t0); +} diff --git a/tests/import/invalid_names1.c b/tests/import/invalid_names1.c new file mode 100644 index 00000000..874e1029 --- /dev/null +++ b/tests/import/invalid_names1.c @@ -0,0 +1,18 @@ +#include +#include +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "gwion.h" +#include "instr.h" +#include "object.h" +#include "operator.h" +#include "import.h" +#include "ugen.h" +#include "gwi.h" + +GWION_IMPORT(trig) { + DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T,", SZ_INT, NULL)) + return gwi_add_type(gwi, t0); +} diff --git a/tests/import/invalid_names2.c b/tests/import/invalid_names2.c new file mode 100644 index 00000000..f1f5fe19 --- /dev/null +++ b/tests/import/invalid_names2.c @@ -0,0 +1,18 @@ +#include +#include +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "gwion.h" +#include "instr.h" +#include "object.h" +#include "operator.h" +#include "import.h" +#include "ugen.h" +#include "gwi.h" + +GWION_IMPORT(trig) { + DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T", SZ_INT, NULL)) + return gwi_add_type(gwi, t0); +} diff --git a/tests/import/invalid_names3.c b/tests/import/invalid_names3.c new file mode 100644 index 00000000..02c7033a --- /dev/null +++ b/tests/import/invalid_names3.c @@ -0,0 +1,18 @@ +#include +#include +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "gwion.h" +#include "instr.h" +#include "object.h" +#include "operator.h" +#include "import.h" +#include "ugen.h" +#include "gwi.h" + +GWION_IMPORT(trig) { + DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T<~a~>", SZ_INT, NULL)) + return gwi_add_type(gwi, t0); +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index e4b35b68..626149e7 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #74 +# [test] #78 n=0 [ "$1" ] && n="$1" -- 2.43.0