schema compile BUGFIX set context modules for uses augment/refine
Also specify what exactly they are expected to be in
which situation.
diff --git a/src/schema_compile.h b/src/schema_compile.h
index 63665fb..2dcc835 100644
--- a/src/schema_compile.h
+++ b/src/schema_compile.h
@@ -56,8 +56,16 @@
*/
struct lysc_ctx {
struct ly_ctx *ctx;
- struct lys_module *cur_mod; /**< module currently being compiled, used as the current module for unprefixed nodes */
- struct lysp_module *pmod; /**< parsed module being processed, used for searching imports to resolve prefixed nodes */
+ struct lys_module *cur_mod; /**< module currently being compiled,
+ - identifier/path - used as the current module for unprefixed nodes
+ - augment - module where the augment is defined
+ - deviation - module where the deviation is defined
+ - uses - module where the uses is defined */
+ struct lysp_module *pmod; /**< parsed module being processed,
+ - identifier/path - used for searching imports to resolve prefixed nodes
+ - augment - module where the augment is defined
+ - deviation - module where the deviation is defined
+ - uses - module where the grouping is defined */
struct ly_set groupings; /**< stack for groupings circular check */
struct ly_set tpdf_chain;
struct ly_set disabled; /**< set of compiled nodes whose if-feature(s) was not satisifed */
diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c
index 7c56022..168d87d 100644
--- a/src/schema_compile_amend.c
+++ b/src/schema_compile_amend.c
@@ -1678,11 +1678,17 @@
LY_CHECK_GOTO(ret = lysp_dup_single(ctx->ctx, pnode, 1, dev_pnode), cleanup);
}
+ /* use modules from the refine */
+ ctx->cur_mod = rfn->nodeid_pmod->mod;
+ ctx->pmod = (struct lysp_module *)rfn->nodeid_pmod;
+
/* apply all the refines by changing (the copy of) the parsed node */
LY_ARRAY_FOR(rfn->rfns, u) {
- /* apply refine, keep the current path and add to it */
+ /* keep the current path and add to it */
lysc_update_path(ctx, NULL, "{refine}");
lysc_update_path(ctx, NULL, rfn->rfns[u]->nodeid);
+
+ /* apply refine and restore the path */
ret = lys_apply_refine(ctx, rfn->rfns[u], *dev_pnode);
lysc_update_path(ctx, NULL, NULL);
lysc_update_path(ctx, NULL, NULL);
@@ -1963,9 +1969,13 @@
continue;
}
- /* apply augment, keep the current path and add to it */
+ /* use the path and modules from the augment */
lysc_update_path(ctx, NULL, "{augment}");
lysc_update_path(ctx, NULL, aug->aug_p->nodeid);
+ ctx->cur_mod = aug->nodeid_pmod->mod;
+ ctx->pmod = (struct lysp_module *)aug->nodeid_pmod;
+
+ /* apply augment, restore the path */
ret = lys_compile_augment(ctx, aug->aug_p, node);
lysc_update_path(ctx, NULL, NULL);
lysc_update_path(ctx, NULL, NULL);
@@ -1986,13 +1996,15 @@
continue;
}
- /* apply augment, use the path and modules from the augment */
+ /* use the path and modules from the augment */
strcpy(orig_path, ctx->path);
ctx->path_len = 1;
lysc_update_path(ctx, NULL, "{augment}");
lysc_update_path(ctx, NULL, aug->aug_p->nodeid);
ctx->cur_mod = aug->nodeid_pmod->mod;
ctx->pmod = (struct lysp_module *)aug->nodeid_pmod;
+
+ /* apply augment, restore the path */
ret = lys_compile_augment(ctx, aug->aug_p, node);
strcpy(ctx->path, orig_path);
ctx->path_len = strlen(ctx->path);