schema tree REFACTOR pass only new mod set when parsing modules
Parsing and compilation being strictly separate,
pass only new mod set (creating) from unres to
parsing functions to make the distinction explicit.
diff --git a/tests/utests/basic/test_context.c b/tests/utests/basic/test_context.c
index fbd5b49..9f7961b 100644
--- a/tests/utests/basic/test_context.c
+++ b/tests/utests/basic/test_context.c
@@ -215,8 +215,8 @@
assert_int_equal(UTEST_LYCTX->change_count, ly_ctx_get_change_count(UTEST_LYCTX));
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
- assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, 4, NULL, NULL, &unres, &mod1));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, 4, NULL, NULL, &unres.creating, &mod1));
ly_in_free(in, 0);
CHECK_LOG_CTX("Invalid schema input format.", NULL);
@@ -234,26 +234,26 @@
/* name collision of module and submodule */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-30;}");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;include y;}", &in));
- assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod1));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
ly_in_free(in, 0);
CHECK_LOG_CTX("Name collision between module and submodule of name \"y\".", "Line number 1.");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", &in));
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod1));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
assert_int_equal(LY_SUCCESS, lys_implement(mod1, NULL, &unres));
assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
ly_in_free(in, 0);
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
- assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod1));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
ly_in_free(in, 0);
CHECK_LOG_CTX("Name collision between module and submodule of name \"y\".", "Line number 1.");
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule y {belongs-to b {prefix b;}}");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module b {namespace urn:b;prefix b;include y;}", &in));
- assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod1));
+ assert_int_equal(LY_EVALID, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
lys_compile_unres_glob_revert(UTEST_LYCTX, &unres);
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
ly_in_free(in, 0);
@@ -264,17 +264,16 @@
ly_ctx_reset_latests(UTEST_LYCTX);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-31;}");
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", &in));
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod2));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
ly_in_free(in, 0);
assert_string_equal("2018-10-31", mod2->parsed->includes[0].submodule->revs[0].date);
/* reloading module in case only the compiled module resists in the context */
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module w {namespace urn:w;prefix w;revision 2018-10-24;}", &in));
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod1));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod1));
ly_in_free(in, 0);
- mod1->implemented = 1;
- assert_int_equal(LY_SUCCESS, lys_compile(mod1, 0, 0, &unres));
+ assert_int_equal(LY_SUCCESS, lys_implement(mod1, NULL, &unres));
assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
assert_non_null(mod1->compiled);
@@ -295,8 +294,8 @@
assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module w {namespace urn:w;prefix w;revision 2018-10-24;}");
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod2));
- assert_int_equal(LY_SUCCESS, lys_implement(mod2, NULL, &unres));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
+ assert_int_equal(LY_SUCCESS, _lys_set_implemented(mod2, NULL, &unres));
assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
ly_in_free(in, 0);
@@ -392,23 +391,23 @@
assert_non_null(ly_ctx_get_module_ns(UTEST_LYCTX, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"));
/* select module by revision */
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres, &mod));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
assert_int_equal(LY_SUCCESS, lys_implement(mod, NULL, &unres));
assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
/* invalid attempts - implementing module of the same name and inserting the same module */
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, NULL, &unres, &mod2));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
assert_int_equal(LY_EDENIED, lys_implement(mod2, NULL, &unres));
CHECK_LOG_CTX("Module \"a@2018-10-24\" is present in the context in other implemented revision (2018-10-23).", NULL);
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
ly_in_reset(in1);
/* it is already there, fine */
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres, NULL));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres.creating, NULL));
/* insert the second module only as imported, not implemented */
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
ly_in_reset(in2);
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, NULL, &unres, &mod2));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in2, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod2));
assert_non_null(mod2);
assert_ptr_not_equal(mod, mod2);
mod = ly_ctx_get_module_latest(UTEST_LYCTX, "a");
@@ -416,15 +415,15 @@
mod2 = ly_ctx_get_module_latest_ns(UTEST_LYCTX, mod->ns);
assert_ptr_equal(mod, mod2);
/* work with module with no revision */
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in0, LYS_IN_YANG, NULL, NULL, &unres, &mod));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in0, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
assert_ptr_equal(mod, ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
assert_ptr_not_equal(mod, ly_ctx_get_module_latest(UTEST_LYCTX, "a"));
str1 = "submodule b {belongs-to a {prefix a;}}";
ly_in_free(in1, 0);
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
- assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres, &mod));
+ assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in1, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
@@ -960,11 +959,10 @@
UTEST_ADD_MODULE(schema_c, LYS_IN_YANG, NULL, NULL);
assert_int_equal(LY_SUCCESS, lys_set_implemented((struct lys_module *)mod, feats));
- /* none of the modules should be implemented */
+ /* none of the modules should be compiled */
i = 0;
while ((mod = ly_ctx_get_module_iter(UTEST_LYCTX, &i))) {
- assert_false(mod->implemented);
- assert_false(mod->compiled);
+ assert_null(mod->compiled);
}
assert_int_equal(LY_SUCCESS, ly_ctx_compile(UTEST_LYCTX));
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index d226bc3..3190d40 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -589,7 +589,7 @@
struct lysp_module *mod = NULL;
struct lysp_submodule *submod = NULL;
struct lys_module *m;
- struct lys_glob_unres unres = {0};
+ struct ly_set new_mods = {0};
struct lys_yang_parser_ctx *ctx_p;
mod = mod_renew(YCTX);
@@ -761,7 +761,7 @@
in.current = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
m = calloc(1, sizeof *m);
m->ctx = YCTX->parsed_mod->mod->ctx;
- assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
+ assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &new_mods));
CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after module, expected end-of-input.", "Line number 1.");
yang_parser_ctx_free(ctx_p);
lys_module_free(m);
@@ -769,7 +769,7 @@
in.current = "prefix " SCHEMA_BEGINNING "}";
m = calloc(1, sizeof *m);
m->ctx = YCTX->parsed_mod->mod->ctx;
- assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
+ assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &new_mods));
CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
lys_module_free(m);
@@ -777,7 +777,7 @@
in.current = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}";
m = calloc(1, sizeof *m);
m->ctx = YCTX->parsed_mod->mod->ctx;
- assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
+ assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &new_mods));
CHECK_LOG_CTX("Invalid keyword \"position\" as a child of \"enum\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
lys_module_free(m);
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index d492591..66b454d 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -3681,7 +3681,7 @@
struct lys_module *mod;
struct lys_yin_parser_ctx *yin_ctx = NULL;
struct ly_in *in = NULL;
- struct lys_glob_unres unres = {0};
+ struct ly_set new_mods = {0};
mod = calloc(1, sizeof *mod);
mod->ctx = UTEST_LYCTX;
@@ -3707,10 +3707,10 @@
" </md:annotation>\n"
"</module>\n";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
- assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
+ assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &new_mods), LY_SUCCESS);
assert_null(mod->parsed->exts->child->next->child);
assert_string_equal(mod->parsed->exts->child->next->arg, "test");
- lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ ly_set_erase(&new_mods, NULL);
lys_module_free(mod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
@@ -3748,8 +3748,8 @@
" </list>\n"
"</module>\n";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
- assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
- lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &new_mods), LY_SUCCESS);
+ ly_set_erase(&new_mods, NULL);
lys_module_free(mod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
@@ -3764,8 +3764,8 @@
" <prefix value=\"foo\"/>\n"
"</module>\n";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
- assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
- lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &new_mods), LY_SUCCESS);
+ ly_set_erase(&new_mods, NULL);
lys_module_free(mod);
yin_parser_ctx_free(yin_ctx);
ly_in_free(in, 0);
@@ -3777,7 +3777,7 @@
data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
"</submodule>\n";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
- assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EINVAL);
+ assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &new_mods), LY_EINVAL);
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
lys_module_free(mod);
yin_parser_ctx_free(yin_ctx);
@@ -3792,7 +3792,7 @@
"</module>\n"
"<module>";
assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
- assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EVALID);
+ assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &new_mods), LY_EVALID);
CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
lys_module_free(mod);
yin_parser_ctx_free(yin_ctx);
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 3ab7ccd..b8c70cc 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -76,16 +76,14 @@
str = "module test {namespace urn:test; prefix t;"
"feature f1;feature f2 {if-feature f1;}}";
- assert_int_equal(LY_EINVAL, lys_compile(NULL, 0, 0, NULL));
+ assert_int_equal(LY_EINVAL, lys_compile(NULL, 0, NULL));
CHECK_LOG("Invalid argument mod (lys_compile()).", NULL);
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod));
- assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
ly_in_free(in, 0);
assert_int_equal(0, mod->implemented);
- mod->implemented = 1;
- assert_int_equal(LY_SUCCESS, lys_compile(mod, 0, 0, &unres));
+ assert_int_equal(LY_SUCCESS, lys_implement(mod, NULL, &unres));
assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
assert_non_null(mod->compiled);
@@ -107,15 +105,15 @@
/* submodules cannot be compiled directly */
str = "submodule test {belongs-to xxx {prefix x;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, NULL));
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+ assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, NULL));
ly_in_free(in, 0);
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
/* data definition name collision in top level */
str = "module aa {namespace urn:aa;prefix aa; leaf a {type string;} container a{presence x;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres, &mod));
+ assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, NULL, &unres.creating, &mod));
assert_int_equal(LY_EEXIST, lys_implement(mod, NULL, &unres));
CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/aa:a");
lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);