parser FEATURE set of currently parsed modules
... instead of only the last one. It is used
to handle cyclic includes.
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index 84492c8..9625ea9 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -75,19 +75,23 @@
static int
setup(void **state)
{
+ struct lysp_module *pmod;
+
UTEST_SETUP;
/* allocate parser context */
YCTX = calloc(1, sizeof(*YCTX));
YCTX->format = LYS_IN_YANG;
+ ly_set_new(&YCTX->parsed_mods);
/* allocate new parsed module */
- YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
+ pmod = calloc(1, sizeof *pmod);
+ ly_set_add(YCTX->parsed_mods, pmod, 1, NULL);
/* allocate new module */
- YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
- YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
- YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
+ pmod->mod = calloc(1, sizeof *pmod->mod);
+ pmod->mod->ctx = UTEST_LYCTX;
+ pmod->mod->parsed = pmod;
/* initilize and use the global easily available and customizable input handler */
in.line = 1;
@@ -100,9 +104,10 @@
static int
teardown(void **state)
{
- lys_module_free(YCTX->parsed_mod->mod);
+ lys_module_free(PARSER_CUR_PMOD(YCTX)->mod);
LOG_LOCBACK(0, 0, 0, 1);
+ ly_set_free(YCTX->parsed_mods, NULL);
free(YCTX);
YCTX = NULL;
@@ -477,7 +482,7 @@
uint32_t value = 0;
struct lysp_ext_instance *ext = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
in.current = " 1invalid; ...";
assert_int_equal(LY_EVALID, parse_minelements(YCTX, &value, &flags, &ext));
@@ -500,7 +505,7 @@
flags = value = 0;
TEST_MINMAX_SUCCESS(" 1 {m:ext;} ...", YCTX, LYS_SET_MIN, 1);
assert_non_null(ext);
- FREE_ARRAY(YCTX->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
+ FREE_ARRAY(PARSER_CUR_PMOD(YCTX)->mod->ctx, ext, lysp_ext_instance_free);
ext = NULL;
flags = value = 0;
@@ -532,7 +537,7 @@
flags = value = 0;
TEST_MINMAX_SUCCESS(" 1 {m:ext;} ...", YCTX, LYS_SET_MAX, 1);
assert_non_null(ext);
- FREE_ARRAY(YCTX->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
+ FREE_ARRAY(PARSER_CUR_PMOD(YCTX)->mod->ctx, ext, lysp_ext_instance_free);
ext = NULL;
flags = value = 0;
@@ -544,32 +549,36 @@
static struct lysp_module *
mod_renew(struct lys_yang_parser_ctx *ctx)
{
- struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
+ struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
+ struct lysp_module *pmod;
- lys_module_free(ctx->parsed_mod->mod);
- ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod);
- ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
- ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
- ctx->parsed_mod->mod->ctx = ly_ctx;
+ lys_module_free(PARSER_CUR_PMOD(ctx)->mod);
+ pmod = calloc(1, sizeof *pmod);
+ ctx->parsed_mods->objs[0] = pmod;
+ pmod->mod = calloc(1, sizeof *pmod->mod);
+ pmod->mod->parsed = pmod;
+ pmod->mod->ctx = ly_ctx;
ctx->in->line = 1;
- return ctx->parsed_mod;
+ return pmod;
}
static struct lysp_submodule *
submod_renew(struct lys_yang_parser_ctx *ctx)
{
- struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
+ struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
+ struct lysp_submodule *submod;
- lys_module_free(ctx->parsed_mod->mod);
- ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule));
- ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
- lydict_insert(ly_ctx, "name", 0, &ctx->parsed_mod->mod->name);
- ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
- ctx->parsed_mod->mod->ctx = ly_ctx;
+ lys_module_free(PARSER_CUR_PMOD(ctx)->mod);
+ submod = calloc(1, sizeof *submod);
+ ctx->parsed_mods->objs[0] = submod;
+ submod->mod = calloc(1, sizeof *submod->mod);
+ lydict_insert(ly_ctx, "name", 0, &submod->mod->name);
+ submod->mod->parsed = (struct lysp_module *)submod;
+ submod->mod->ctx = ly_ctx;
- return (struct lysp_submodule *)ctx->parsed_mod;
+ return submod;
}
static LY_ERR
@@ -677,7 +686,7 @@
TEST_GENERIC("identity test;}", mod->identities,
assert_string_equal("test", mod->identities[0].name));
/* import */
- ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
+ ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
TEST_GENERIC("import zzz {prefix z;}}", mod->imports,
assert_string_equal("zzz", mod->imports[0].name));
@@ -695,21 +704,21 @@
LOG_LOCBACK(0, 0, 0, 1);
in.current = "module name10 {yang-version 1.1;namespace urn:x;prefix \"x\";import zzz {prefix y;}import zzz {prefix z;}}";
- assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
+ assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
CHECK_LOG_CTX("Single revision of the module \"zzz\" imported twice.", NULL);
/* include */
- ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
+ ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
in.current = "module" SCHEMA_BEGINNING "include xxx;}";
- assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
+ assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
CHECK_LOG_CTX("Parsing module \"name\" failed.", NULL, "Including \"xxx\" submodule into \"name\" failed.", NULL);
- ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
+ ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
in.current = "module" SCHEMA_BEGINNING "include xxx;}";
- assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
+ assert_int_equal(lys_parse_mem(PARSER_CUR_PMOD(YCTX)->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
CHECK_LOG_CTX("Parsing module \"name\" failed.", NULL, "Including \"xxx\" submodule into \"name\" failed.", NULL);
- ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
+ ly_ctx_set_module_imp_clb(PARSER_CUR_PMOD(YCTX)->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
TEST_GENERIC("include xxx;}", mod->includes,
assert_string_equal("xxx", mod->includes[0].name));
@@ -759,7 +768,7 @@
in.current = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
m = calloc(1, sizeof *m);
- m->ctx = YCTX->parsed_mod->mod->ctx;
+ m->ctx = PARSER_CUR_PMOD(YCTX)->mod->ctx;
assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after module, expected end-of-input.", "Line number 1.");
yang_parser_ctx_free(ctx_p);
@@ -767,7 +776,7 @@
in.current = "prefix " SCHEMA_BEGINNING "}";
m = calloc(1, sizeof *m);
- m->ctx = YCTX->parsed_mod->mod->ctx;
+ m->ctx = PARSER_CUR_PMOD(YCTX)->mod->ctx;
assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
@@ -775,7 +784,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;
+ m->ctx = PARSER_CUR_PMOD(YCTX)->mod->ctx;
assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m));
CHECK_LOG_CTX("Invalid keyword \"position\" as a child of \"enum\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
@@ -828,12 +837,12 @@
submod = submod_renew(YCTX);
in.current = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
- assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, YCTX->parsed_mod->mod->ctx, (struct lys_parser_ctx *)YCTX, YCTX->in, &submod));
+ assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lys_parser_ctx *)YCTX, YCTX->in, &submod));
CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after submodule, expected end-of-input.", "Line number 1.");
yang_parser_ctx_free(ctx_p);
in.current = "prefix " SCHEMA_BEGINNING "}";
- assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, YCTX->parsed_mod->mod->ctx, (struct lys_parser_ctx *)YCTX, YCTX->in, &submod));
+ assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lys_parser_ctx *)YCTX, YCTX->in, &submod));
CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
yang_parser_ctx_free(ctx_p);
submod = submod_renew(YCTX);
@@ -852,7 +861,7 @@
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \
- &d, "1", FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free); d = NULL)
+ &d, "1", FREE_ARRAY(PARSER_CUR_PMOD(YCTX)->mod->ctx, d, lysp_deviation_free); d = NULL)
TEST_DUP("description", "a", "b");
TEST_DUP("reference", "a", "b");
@@ -862,21 +871,21 @@
assert_int_equal(LY_SUCCESS, parse_deviation(YCTX, &d));
assert_non_null(d);
assert_string_equal(" ...", in.current);
- FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
+ FREE_ARRAY(PARSER_CUR_PMOD(YCTX)->mod->ctx, d, lysp_deviation_free);
d = NULL;
/* missing mandatory substatement */
in.current = " test {description text;}";
assert_int_equal(LY_EVALID, parse_deviation(YCTX, &d));
CHECK_LOG_CTX("Missing mandatory keyword \"deviate\" as a child of \"deviation\".", "Line number 1.");
- FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
+ FREE_ARRAY(PARSER_CUR_PMOD(YCTX)->mod->ctx, d, lysp_deviation_free);
d = NULL;
/* invalid substatement */
in.current = " test {deviate not-supported; status obsolete;}";
assert_int_equal(LY_EVALID, parse_deviation(YCTX, &d));
CHECK_LOG_CTX("Invalid keyword \"status\" as a child of \"deviation\".", "Line number 1.");
- FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
+ FREE_ARRAY(PARSER_CUR_PMOD(YCTX)->mod->ctx, d, lysp_deviation_free);
d = NULL;
#undef TEST_DUP
}
@@ -886,7 +895,7 @@
assert_int_equal(LY_SUCCESS, parse_deviate(YCTX, &d));\
assert_non_null(d);\
assert_string_equal(REMAIN_TEXT, in.current);\
- lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL
+ lysp_deviate_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, d); free(d); d = NULL
static void
test_deviate(void **state)
@@ -896,7 +905,7 @@
/* invalid cardinality */
#define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \
TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \
- &d, "1", lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL)
+ &d, "1", lysp_deviate_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, d); free(d); d = NULL)
TEST_DUP("add", "config", "true", "false");
#if 0
@@ -923,7 +932,7 @@
in.current = " "DEV" {"STMT" "VALUE";}..."; \
assert_int_equal(LY_EVALID, parse_deviate(YCTX, &d)); \
CHECK_LOG_CTX("Deviate \""DEV"\" does not support keyword \""STMT"\".", "Line number 1.");\
- lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL
+ lysp_deviate_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, d); free(d); d = NULL
TEST_NOT_SUP("not-supported", "units", "meters");
TEST_NOT_SUP("not-supported", "must", "1");
@@ -956,7 +965,7 @@
{
struct lysp_node_container *c = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
/* invalid cardinality */
@@ -964,7 +973,7 @@
in.current = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node**)&c)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)c); c = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)c); c = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -988,24 +997,24 @@
assert_non_null(c->typedefs);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
/* invalid */
in.current = " cont {augment /root;} ...";
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node **)&c));
CHECK_LOG_CTX("Invalid keyword \"augment\" as a child of \"container\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
in.current = " cont {nonsence true;} ...";
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node **)&c));
CHECK_LOG_CTX("Invalid character sequence \"nonsence\", expected a keyword.", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
- YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
+ PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 */
in.current = " cont {action x;} ...";
assert_int_equal(LY_EVALID, parse_container(YCTX, NULL, (struct lysp_node **)&c));
CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - "
"the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c); c = NULL;
}
static void
@@ -1018,7 +1027,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node**)&l)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)l); l = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("default", "x", "y");
@@ -1040,25 +1049,25 @@
assert_string_equal("yyy", l->units);
assert_string_equal("string", l->type.name);
assert_non_null(l->musts);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
/* full content - now with mandatory */
in.current = "l {mandatory true; type string;} ...";
assert_int_equal(LY_SUCCESS, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LYSP_NODE(l, NULL, 0, LYS_MAND_TRUE, 0, "l", 0, LYS_LEAF, 0, NULL, 0);
assert_string_equal("string", l->type.name);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
/* invalid */
in.current = " l {description \"missing type\";} ...";
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
in.current = "l { type iid { path qpud wrong {";
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Invalid character sequence \"wrong\", expected a keyword.", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
}
static void
@@ -1066,14 +1075,14 @@
{
struct lysp_node_leaflist *ll = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
in.current = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_leaflist(YCTX, NULL, (struct lysp_node**)&ll)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)ll); ll = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)ll); ll = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1103,7 +1112,7 @@
assert_string_equal("string", ll->type.name);
assert_non_null(ll->musts);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
/* full content - now with min-elements */
in.current = "ll {min-elements 10; type string;} ...";
@@ -1113,19 +1122,19 @@
assert_int_equal(0, ll->max);
assert_int_equal(10, ll->min);
assert_int_equal(LYS_SET_MIN, ll->flags);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
/* invalid */
in.current = " ll {description \"missing type\";} ...";
assert_int_equal(LY_EVALID, parse_leaflist(YCTX, NULL, (struct lysp_node **)&ll));
CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf-list\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
- YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
+ PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
in.current = " ll {default xx; type string;} ...";
assert_int_equal(LY_EVALID, parse_leaflist(YCTX, NULL, (struct lysp_node **)&ll));
CHECK_LOG_CTX("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ll); ll = NULL;
}
static void
@@ -1133,7 +1142,7 @@
{
struct lysp_node_list *l = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
/* invalid cardinality */
@@ -1141,7 +1150,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_list(YCTX, NULL, (struct lysp_node**)&l)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)l); l = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1171,14 +1180,14 @@
assert_non_null(l->musts);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
/* invalid content */
- YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
+ PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 */
in.current = "l {action x;} ...";
assert_int_equal(LY_EVALID, parse_list(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)l); l = NULL;
}
static void
@@ -1186,14 +1195,14 @@
{
struct lysp_node_choice *ch = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
in.current = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_choice(YCTX, NULL, (struct lysp_node**)&ch)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)ch); ch = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)ch); ch = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("default", "a", "b");
@@ -1209,14 +1218,14 @@
"leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
assert_int_equal(LY_SUCCESS, parse_choice(YCTX, NULL, (struct lysp_node **)&ch));
CHECK_LYSP_NODE(ch, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "ch", 0, LYS_CHOICE, 0, "test", 1);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ch); ch = NULL;
/* full content - the default missing from the previous node */
in.current = "ch {default c;case c;} ...";
assert_int_equal(LY_SUCCESS, parse_choice(YCTX, NULL, (struct lysp_node **)&ch));
CHECK_LYSP_NODE(ch, NULL, 0, 0, 0, "ch", 0, LYS_CHOICE, 0, NULL, 0);
assert_string_equal("c", ch->dflt.str);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)ch); ch = NULL;
}
static void
@@ -1224,14 +1233,14 @@
{
struct lysp_node_case *cs = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
in.current = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_case(YCTX, NULL, (struct lysp_node**)&cs)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)cs); cs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)cs); cs = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1244,13 +1253,13 @@
"leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
assert_int_equal(LY_SUCCESS, parse_case(YCTX, NULL, (struct lysp_node **)&cs));
CHECK_LYSP_NODE(cs, "test", 1, LYS_STATUS_CURR, 1, "cs", 0, LYS_CASE, 0, "test", 1);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)cs); cs = NULL;
/* invalid content */
in.current = "cs {config true} ...";
assert_int_equal(LY_EVALID, parse_case(YCTX, NULL, (struct lysp_node **)&cs));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"case\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)cs); cs = NULL;
}
static void
@@ -1259,9 +1268,9 @@
struct lysp_node_anydata *any = NULL;
if (kw == LY_STMT_ANYDATA) {
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
} else {
- YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
+ PARSER_CUR_PMOD(YCTX)->version = 1; /* simulate YANG 1.0 */
}
/* invalid cardinality */
@@ -1269,7 +1278,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_any(YCTX, kw, NULL, (struct lysp_node**)&any)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)any); any = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)any); any = NULL;
TEST_DUP("config", "true", "false");
TEST_DUP("description", "text1", "text2");
@@ -1286,7 +1295,7 @@
uint16_t node_type = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML;
CHECK_LYSP_NODE(any, "test", 1, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "any", 0, node_type, 0, "test", 1);
assert_non_null(any->musts);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)any); any = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)any); any = NULL;
}
static void
@@ -1306,7 +1315,7 @@
{
struct lysp_node_grp *grp = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
/* invalid cardinality */
@@ -1314,7 +1323,7 @@
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_grouping(YCTX, NULL, &grp)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, &grp->node); grp = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node); grp = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1335,20 +1344,20 @@
assert_int_equal(LYS_STATUS_CURR, grp->flags);
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, &grp->node);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node);
grp = NULL;
/* invalid content */
in.current = "grp {config true} ...";
assert_int_equal(LY_EVALID, parse_grouping(YCTX, NULL, &grp));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"grouping\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, &grp->node);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node);
grp = NULL;
in.current = "grp {must 'expr'} ...";
assert_int_equal(LY_EVALID, parse_grouping(YCTX, NULL, &grp));
CHECK_LOG_CTX("Invalid keyword \"must\" as a child of \"grouping\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, &grp->node);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, &grp->node);
grp = NULL;
}
@@ -1358,7 +1367,7 @@
struct lysp_node_action *rpcs = NULL;
struct lysp_node_container *c = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
/* invalid cardinality */
@@ -1366,7 +1375,7 @@
in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_action(YCTX, NULL, &rpcs)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)rpcs); rpcs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)rpcs); rpcs = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("input", "{leaf l1 {type empty;}} description a", "{leaf l2 {type empty;}} description a");
@@ -1411,15 +1420,15 @@
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)rpcs); rpcs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)rpcs); rpcs = NULL;
/* invalid content */
in.current = "func {config true} ...";
assert_int_equal(LY_EVALID, parse_action(YCTX, NULL, &rpcs));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"rpc\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)rpcs); rpcs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)rpcs); rpcs = NULL;
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c);
}
static void
@@ -1428,7 +1437,7 @@
struct lysp_node_notif *notifs = NULL;
struct lysp_node_container *c = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
YCTX->main_ctx = (struct lys_parser_ctx *)YCTX;
/* invalid cardinality */
@@ -1436,7 +1445,7 @@
in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_notif(YCTX, NULL, ¬ifs)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)notifs); notifs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)notifs); notifs = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1464,15 +1473,15 @@
ly_set_erase(&YCTX->tpdfs_nodes, NULL);
ly_set_erase(&YCTX->grps_nodes, NULL);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)notifs); notifs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)notifs); notifs = NULL;
/* invalid content */
in.current = "ntf {config true} ...";
assert_int_equal(LY_EVALID, parse_notif(YCTX, NULL, ¬ifs));
CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"notification\".", "Line number 1.");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)notifs); notifs = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)notifs); notifs = NULL;
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)c);
}
static void
@@ -1480,14 +1489,14 @@
{
struct lysp_node_uses *u = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_uses(YCTX, NULL, (struct lysp_node**)&u)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)u); u = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node*)u); u = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1501,7 +1510,7 @@
CHECK_LYSP_NODE(u, "test", 1, LYS_STATUS_CURR, 1, "grpref", 0, LYS_USES, 0, "test", 1);
assert_non_null(u->augments);
assert_non_null(u->refines);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)u); u = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)u); u = NULL;
}
static void
@@ -1509,14 +1518,14 @@
{
struct lysp_node_augment *a = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_augment(YCTX, NULL, &a)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)a); a = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)a); a = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1538,7 +1547,7 @@
assert_non_null(a->when);
assert_null(a->parent);
assert_int_equal(LYS_STATUS_CURR, a->flags);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)a); a = NULL;
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)a); a = NULL;
}
static void
@@ -1546,14 +1555,14 @@
{
struct lysp_when *w = NULL;
- YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
+ PARSER_CUR_PMOD(YCTX)->version = 2; /* simulate YANG 1.1 */
/* invalid cardinality */
#define TEST_DUP(MEMBER, VALUE1, VALUE2) \
in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
assert_int_equal(LY_EVALID, parse_when(YCTX, &w)); \
CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
- FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+ FREE_MEMBER(PARSER_CUR_PMOD(YCTX)->mod->ctx, w, lysp_when_free); w = NULL;
TEST_DUP("description", "text1", "text2");
TEST_DUP("reference", "1", "2");
@@ -1567,7 +1576,7 @@
assert_string_equal("test", w->dsc);
assert_string_equal("test", w->ref);
assert_non_null(w->exts);
- FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+ FREE_MEMBER(PARSER_CUR_PMOD(YCTX)->mod->ctx, w, lysp_when_free); w = NULL;
/* empty condition */
in.current = "\"\";";
@@ -1575,7 +1584,7 @@
CHECK_LOG_CTX("Empty argument of when statement does not make sense.", NULL);
assert_non_null(w);
assert_string_equal("", w->cond);
- FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+ FREE_MEMBER(PARSER_CUR_PMOD(YCTX)->mod->ctx, w, lysp_when_free); w = NULL;
}
static void
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index b8ac15a..59353a4 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -130,17 +130,21 @@
static int
setup_ctx(void **state)
{
+ struct lysp_module *pmod;
+
/* allocate parser context */
YCTX = calloc(1, sizeof(*YCTX));
YCTX->format = LYS_IN_YIN;
+ ly_set_new(&YCTX->parsed_mods);
/* allocate new parsed module */
- YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
+ pmod = calloc(1, sizeof *pmod);
+ ly_set_add(YCTX->parsed_mods, pmod, 1, NULL);
/* allocate new module */
- YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
- YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
- YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
+ pmod->mod = calloc(1, sizeof *pmod->mod);
+ pmod->mod->ctx = UTEST_LYCTX;
+ pmod->mod->parsed = pmod;
return 0;
}
@@ -158,7 +162,7 @@
static int
teardown_ctx(void **UNUSED(state))
{
- lys_module_free(YCTX->parsed_mod->mod);
+ lys_module_free(PARSER_CUR_PMOD(YCTX)->mod);
yin_parser_ctx_free(YCTX);
YCTX = NULL;
@@ -1216,7 +1220,7 @@
struct lysp_submodule submod;
struct lysp_ext_instance *exts = NULL;
- lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name);
+ lydict_insert(UTEST_LYCTX, "module-name", 0, &PARSER_CUR_PMOD(YCTX)->mod->name);
data = ELEMENT_WRAPPER_START
"<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
@@ -2451,7 +2455,7 @@
struct include_meta inc_meta = {"module-name", &includes};
/* max subelems */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<include module=\"mod\">\n"
" <description><text>desc</text></description>\n"
@@ -2477,7 +2481,7 @@
includes = NULL;
/* invalid combinations */
- YCTX->parsed_mod->version = LYS_VERSION_1_0;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_0;
data = ELEMENT_WRAPPER_START
"<include module=\"mod\">\n"
" <description><text>desc</text></description>\n"
@@ -2490,7 +2494,7 @@
FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
includes = NULL;
- YCTX->parsed_mod->version = LYS_VERSION_1_0;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_0;
data = ELEMENT_WRAPPER_START
"<include module=\"mod\">\n"
" <reference><text>ref</text></reference>\n"
@@ -2598,7 +2602,7 @@
struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)¬ifs};
/* max subelems */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<notification name=\"notif-name\">\n"
" <anydata name=\"anyd\"/>\n"
@@ -2730,7 +2734,7 @@
struct lysp_node_container *parsed = NULL;
/* max subelems */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<container name=\"cont-name\">\n"
" <anydata name=\"anyd\"/>\n"
@@ -2812,7 +2816,7 @@
struct lysp_node_case *parsed = NULL;
/* max subelems */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<case name=\"case-name\">\n"
" <anydata name=\"anyd\"/>\n"
@@ -2879,7 +2883,7 @@
struct lysp_node_choice *parsed = NULL;
/* max subelems */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<choice name=\"choice-name\">\n"
" <anydata name=\"anyd\"/>\n"
@@ -2949,7 +2953,7 @@
struct inout_meta inout_meta = {NULL, &inout};
/* max subelements */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<input>\n"
" <anydata name=\"anyd\"/>\n"
@@ -2993,7 +2997,7 @@
memset(&inout, 0, sizeof inout);
/* max subelements */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<output>\n"
" <anydata name=\"anyd\"/>\n"
@@ -3064,7 +3068,7 @@
uint16_t flags;
/* max subelems */
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<action name=\"act\">\n"
" <description><text>desc</text></description>\n"
@@ -3100,7 +3104,7 @@
lysp_node_free(UTEST_LYCTX, (struct lysp_node *)actions);
actions = NULL;
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<rpc name=\"act\">\n"
" <description><text>desc</text></description>\n"
@@ -3148,7 +3152,7 @@
struct lysp_node_augment *augments = NULL;
struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
- YCTX->parsed_mod->version = LYS_VERSION_1_1;
+ PARSER_CUR_PMOD(YCTX)->version = LYS_VERSION_1_1;
data = ELEMENT_WRAPPER_START
"<augment target-node=\"target\">\n"
" <action name=\"action\"/>\n"
@@ -3201,13 +3205,13 @@
assert_string_equal(augments->actions->name, "action");
assert_string_equal(augments->notifs->name, "notif");
TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]), LY_STMT_AUGMENT);
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)augments);
augments = NULL;
data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
assert_string_equal(augments->nodeid, "target");
- lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)augments);
+ lysp_node_free(PARSER_CUR_PMOD(YCTX)->mod->ctx, (struct lysp_node *)augments);
augments = NULL;
}
@@ -3421,15 +3425,17 @@
static struct lysp_module *
mod_renew(struct lys_yin_parser_ctx *ctx)
{
- struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
+ struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
+ struct lysp_module *pmod;
- lys_module_free(ctx->parsed_mod->mod);
- ctx->parsed_mod = calloc(1, sizeof *ctx->parsed_mod);
- ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
- ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
- ctx->parsed_mod->mod->ctx = ly_ctx;
+ lys_module_free(PARSER_CUR_PMOD(ctx)->mod);
+ pmod = calloc(1, sizeof *pmod);
+ ctx->parsed_mods->objs[0] = pmod;
+ pmod->mod = calloc(1, sizeof *pmod->mod);
+ pmod->mod->parsed = pmod;
+ pmod->mod->ctx = ly_ctx;
- return ctx->parsed_mod;
+ return pmod;
}
static void
@@ -3549,16 +3555,18 @@
static struct lysp_submodule *
submod_renew(struct lys_yin_parser_ctx *ctx, const char *belongs_to)
{
- struct ly_ctx *ly_ctx = ctx->parsed_mod->mod->ctx;
+ struct ly_ctx *ly_ctx = PARSER_CUR_PMOD(ctx)->mod->ctx;
+ struct lysp_submodule *submod;
- lys_module_free(ctx->parsed_mod->mod);
- ctx->parsed_mod = calloc(1, sizeof(struct lysp_submodule));
- ctx->parsed_mod->mod = calloc(1, sizeof *ctx->parsed_mod->mod);
- lydict_insert(ly_ctx, belongs_to, 0, &ctx->parsed_mod->mod->name);
- ctx->parsed_mod->mod->parsed = ctx->parsed_mod;
- ctx->parsed_mod->mod->ctx = ly_ctx;
+ lys_module_free(PARSER_CUR_PMOD(ctx)->mod);
+ submod = calloc(1, sizeof *submod);
+ ctx->parsed_mods->objs[0] = submod;
+ submod->mod = calloc(1, sizeof *submod->mod);
+ lydict_insert(ly_ctx, belongs_to, 0, &submod->mod->name);
+ submod->mod->parsed = (struct lysp_module *)submod;
+ submod->mod->ctx = ly_ctx;
- return (struct lysp_submodule *)ctx->parsed_mod;
+ return submod;
}
static void
@@ -3805,7 +3813,7 @@
struct lysp_submodule *submod = NULL;
struct ly_in *in;
- lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name);
+ lydict_insert(UTEST_LYCTX, "a", 0, &PARSER_CUR_PMOD(YCTX)->mod->name);
data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<submodule name=\"asub\""
diff --git a/tests/utests/schema/test_schema_common.c b/tests/utests/schema/test_schema_common.c
index 3c78d0d..ab0d81b 100644
--- a/tests/utests/schema/test_schema_common.c
+++ b/tests/utests/schema/test_schema_common.c
@@ -976,7 +976,7 @@
struct module_clb_list list[] = {
{"main_c", "module main_c { yang-version 1.1; namespace urn:test:main_c; prefix mc; include sub_c_one; include sub_c_two;}"},
{"sub_c_one", "submodule sub_c_one { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_two;}"},
- {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } }"},
+ {"sub_c_two", "submodule sub_c_two { yang-version 1.1; belongs-to main_c { prefix mc; } include sub_c_one;}"},
{NULL, NULL}
};
ly_ctx_set_module_imp_clb(UTEST_LYCTX, module_clb, list);
@@ -985,7 +985,7 @@
assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->includes));
assert_false(mod->parsed->includes[1].injected);
/* result is ok, but log includes the warning */
- CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_one) are not necessary.", NULL);
+ CHECK_LOG_CTX("YANG version 1.1 expects all includes in main module, includes in submodules (sub_c_two) are not necessary.", NULL);
}
}