From: fennecdjay Date: Sat, 12 Oct 2019 14:30:51 +0000 (+0200) Subject: :art: Improve import X-Git-Tag: nightly~2159^2~4 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=885e78c08a021c04cd5c7ba1aac39e0e6fd33013;p=gwion.git :art: Improve import --- diff --git a/src/lib/import.c b/src/lib/import.c index cf6d094e..0b3fb10c 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -131,11 +131,11 @@ ANN static ID_List path_valid(const Env env, const m_str path, const loc_t pos) } else break; } - curr[i] = '\0'; + curr[i++] = '\0'; const ID_List list = new_id_list(env->gwion->mp, insert_symbol(env->gwion->st, curr), loc_cpy(env->gwion->mp, pos)); if(i < sz) - list->next = path_valid(env, path + 1 + i, pos); + list->next = path_valid(env, path + i, pos); return list; } @@ -298,9 +298,8 @@ ANN static void dl_var_release(MemPool p, const DL_Var* v) { ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) { DL_Var* v = &gwi->var; memset(v, 0, sizeof(DL_Var)); -// if(!(v->t.xid = str2list(gwi->gwion->env, type, &v->array_depth, gwi->loc))) if(!(v->td = str2decl(gwi->gwion->env, type, &v->array_depth, gwi->loc))) - GWI_ERR_B(_(" ... during var import '%s.%s'."), gwi->gwion->env->class_def->name, name) + GWI_ERR_B(_(" ... during var import '%s.%s'."), gwi->gwion->env->name, name) v->var.xid = insert_symbol(gwi->gwion->st, name); return GW_OK; } @@ -382,7 +381,7 @@ struct GetTl { #define tl_xxx(name, tgt, op) \ ANN m_bool tl_##name(struct GetTl *gtl, const m_uint i) { \ - if(!(i + 1 < gtl->sz && gtl->str[i] == tgt)) \ + if(!(i < gtl->sz && gtl->str[i] == tgt)) \ return GW_ERROR; \ op gtl->lvl; \ return GW_OK; \ @@ -393,35 +392,27 @@ tl_xxx(close, '>', --) ANN Type_List str2tl(const Env env, const m_str s, const loc_t pos) { struct GetTl gtl = { .str=s, .sz = strlen(s) }; for(m_uint i = 0; i < gtl.sz; ++i) { - if(s[i] == '<') - CHECK_BO(tl_open(>l, i)) - else if(s[i] == '~') - CHECK_BO(tl_close(>l, i)) - else if(s[i] == ',' && !gtl.lvl) - return tlnext(env, s, i, pos); + if(s[i] == '<' && !gtl.lvl) + CHECK_BO(tl_open(>l, ++i)) + if(s[i] == '~' && !gtl.lvl) + CHECK_BO(tl_close(>l, ++i)) + if(s[i] == ',' && !gtl.lvl) + return tlnext(env, s, i, pos); } return _str2tl(env, s, pos); } ANN Type_Decl* str2decl(const Env env, const m_str s, m_uint *depth, const loc_t pos) { - m_uint i = 0; - DECL_OO(m_str, type_name, = get_type_name(env, s, i++)) + DECL_OO(const m_str, type_name, = get_type_name(env, s, 0)) DECL_OO(ID_List, id, = str2list(env, type_name, depth, pos)) Type_Decl* td = new_type_decl(env->gwion->mp, id); - Type_List tmp = NULL; - while((type_name = get_type_name(env, s, i++))) { - if(!tmp) - td->types = tmp = str2tl(env, type_name, pos); - else { -//exit(3); // here here the last thing to catch - tmp->next = str2tl(env, type_name, pos); - tmp = tmp->next; + const m_str tl_name = get_type_name(env, s, 1); + if(tl_name) { + if(!(td->types = str2tl(env, type_name, pos)) || !type_decl_resolve(env, td)) { + free_type_decl(env->gwion->mp, td); + return NULL; } } - if(td->types && !type_decl_resolve(env, td)) { - free_type_decl(env->gwion->mp, td); - return NULL; - } return td; } diff --git a/tests/import/class_template.c b/tests/import/class_template.c index c8f99ce8..fa6afa67 100644 --- a/tests/import/class_template.c +++ b/tests/import/class_template.c @@ -40,6 +40,7 @@ GWION_IMPORT(class_template) { GWI_BB((o_map_value = gwi_item_end(gwi, ae_flag_member, NULL))) GWI_BB(gwi_class_end(gwi)) - GWI_BB(gwi_item_ini(gwi, "ClassTemplate<~int,int~>", "testObject")) + GWI_BB(gwi_item_ini(gwi, "ClassTemplate<~Ptr<~int~>,int~>", "testObject")) + GWI_BB(gwi_item_end(gwi, ae_flag_none, NULL)) return GW_OK; } diff --git a/tests/import/invalid_names.c b/tests/import/invalid_names.c index abb817cb..54a2f546 100644 --- a/tests/import/invalid_names.c +++ b/tests/import/invalid_names.c @@ -23,10 +23,10 @@ GWION_IMPORT(trig) { const Type t1 = gwi_mk_type(gwi, "T,", SZ_INT, NULL); gwi_add_type(gwi, t1); - const Type t2 = gwi_mk_type(gwi, "T", SZ_INT, NULL); + const Type t2 = gwi_mk_type(gwi, "T", SZ_INT, NULL); gwi_add_type(gwi, t2); - const Type t3 = gwi_mk_type(gwi, "<~a~>T", SZ_INT, NULL); + const Type t3 = gwi_mk_type(gwi, "T<~a~>", SZ_INT, NULL); gwi_add_type(gwi, t3); return GW_OK; diff --git a/tests/import/str2decl.c b/tests/import/str2decl.c index b27a4053..d3527b44 100644 --- a/tests/import/str2decl.c +++ b/tests/import/str2decl.c @@ -16,18 +16,13 @@ #include "func.h" #include "gwi.h" -ANN /*static */m_bool _path_valid(const Env env, const m_str path, const loc_t); GWION_IMPORT(str2decl) { -// const m_str list[2] = { "A", "B" }; -// gwi_tmpl_ini(gwi, 2, list); const Type t_t0 = gwi_mk_type(gwi, "Test", SZ_INT, "Object"); GWI_BB(gwi_class_ini(gwi, t_t0, NULL, NULL)) -// gwi_tmpl_end(gwi); const Type t_t2 = gwi_mk_type(gwi, "Child", SZ_INT, "Object"); GWI_BB(gwi_class_ini(gwi, t_t2, NULL, NULL)) GWI_BB(gwi_class_end(gwi)) GWI_BB(gwi_class_end(gwi)) -// const Type t_t1 = gwi_mk_type(gwi, "Test2", SZ_INT, "<~int,<~int~>Ptr~>Test.Child"); const Type t_t1 = gwi_mk_type(gwi, "Test2", SZ_INT, "Test.Child"); GWI_BB(gwi_class_ini(gwi, t_t1, NULL, NULL)) return gwi_class_end(gwi);