schema CHANGE remove context member from lysc_must
In contrast to when statement, which can appear in uses, compiled must is
always placed in its context node, so getting the context node is quite
straightforward and a separate context meber is not necessary.
The idea to inherit must from RPC's input/output to the their data nodes
(and then need the context memebr in lysc_must) is not good since there are
problematic corner cases with augmenting and deviating input/output.
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 847b8d4..8b6b9f4 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -1248,7 +1248,6 @@
struct lysc_must {
struct lys_module *module; /**< module where the must was defined */
- struct lysc_node *context; /**< context node for evaluating the expression */
struct lyxp_expr *cond; /**< XPath when condition */
const char *dsc; /**< description */
const char *ref; /**< reference */
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index e827ca3..595f637 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -84,18 +84,6 @@
} \
}
-#define COMPILE_ARRAY_MUST_GOTO(CTX, ARRAY_P, ARRAY_C, ITER, PARENT, RET, GOTO) \
- if (ARRAY_P) { \
- LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, LY_ARRAY_SIZE(ARRAY_P), RET, GOTO); \
- size_t __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
- for (ITER = 0; ITER < LY_ARRAY_SIZE(ARRAY_P); ++ITER) { \
- LY_ARRAY_INCREMENT(ARRAY_C); \
- RET = lys_compile_must(CTX, &(ARRAY_P)[ITER], &(ARRAY_C)[ITER + __array_offset]); \
- LY_CHECK_GOTO(RET != LY_SUCCESS, GOTO); \
- (ARRAY_C)[ITER + __array_offset].context = lysc_xpath_context((struct lysc_node*)PARENT); \
- } \
- }
-
#define COMPILE_MEMBER_GOTO(CTX, MEMBER_P, MEMBER_C, FUNC, RET, GOTO) \
if (MEMBER_P) { \
MEMBER_C = calloc(1, sizeof *(MEMBER_C)); \
@@ -3532,7 +3520,7 @@
/* input */
lysc_update_path(ctx, (struct lysc_node*)action, "input");
- COMPILE_ARRAY_MUST_GOTO(ctx, action_p->input.musts, action->input.musts, u, action, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, action_p->input.musts, action->input.musts, u, lys_compile_must, ret, cleanup);
COMPILE_EXTS_GOTO(ctx, action_p->input.exts, action->input_exts, &action->input, LYEXT_PAR_INPUT, ret, cleanup);
ctx->options |= LYSC_OPT_RPC_INPUT;
LY_LIST_FOR(action_p->input.data, child_p) {
@@ -3543,7 +3531,7 @@
/* output */
lysc_update_path(ctx, (struct lysc_node*)action, "output");
- COMPILE_ARRAY_MUST_GOTO(ctx, action_p->output.musts, action->output.musts, u, action, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, action_p->output.musts, action->output.musts, u, lys_compile_must, ret, cleanup);
COMPILE_EXTS_GOTO(ctx, action_p->output.exts, action->output_exts, &action->output, LYEXT_PAR_OUTPUT, ret, cleanup);
ctx->options |= LYSC_OPT_RPC_OUTPUT;
LY_LIST_FOR(action_p->output.data, child_p) {
@@ -3608,7 +3596,7 @@
DUP_STRING(ctx->ctx, notif_p->dsc, notif->dsc);
DUP_STRING(ctx->ctx, notif_p->ref, notif->ref);
COMPILE_ARRAY_GOTO(ctx, notif_p->iffeatures, notif->iffeatures, u, lys_compile_iffeature, ret, cleanup);
- COMPILE_ARRAY_MUST_GOTO(ctx, notif_p->musts, notif->musts, u, notif, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, notif_p->musts, notif->musts, u, lys_compile_must, ret, cleanup);
COMPILE_EXTS_GOTO(ctx, notif_p->exts, notif->exts, notif, LYEXT_PAR_NODE, ret, cleanup);
ctx->options |= LYSC_OPT_NOTIFICATION;
@@ -3647,7 +3635,7 @@
LY_CHECK_RET(lys_compile_node(ctx, child_p, node, 0));
}
- COMPILE_ARRAY_MUST_GOTO(ctx, cont_p->musts, cont->musts, u, node, ret, done);
+ COMPILE_ARRAY_GOTO(ctx, cont_p->musts, cont->musts, u, lys_compile_must, ret, done);
COMPILE_ARRAY1_GOTO(ctx, cont_p->actions, cont->actions, node, u, lys_compile_action, 0, ret, done);
COMPILE_ARRAY1_GOTO(ctx, cont_p->notifs, cont->notifs, node, u, lys_compile_notif, 0, ret, done);
@@ -3728,7 +3716,7 @@
unsigned int u;
LY_ERR ret = LY_SUCCESS;
- COMPILE_ARRAY_MUST_GOTO(ctx, leaf_p->musts, leaf->musts, u, node, ret, done);
+ COMPILE_ARRAY_GOTO(ctx, leaf_p->musts, leaf->musts, u, lys_compile_must, ret, done);
if (leaf_p->units) {
leaf->units = lydict_insert(ctx->ctx, leaf_p->units, 0);
leaf->flags |= LYS_SET_UNITS;
@@ -3789,7 +3777,7 @@
unsigned int u, v;
LY_ERR ret = LY_SUCCESS;
- COMPILE_ARRAY_MUST_GOTO(ctx, llist_p->musts, llist->musts, u, node, ret, done);
+ COMPILE_ARRAY_GOTO(ctx, llist_p->musts, llist->musts, u, lys_compile_must, ret, done);
if (llist_p->units) {
llist->units = lydict_insert(ctx->ctx, llist_p->units, 0);
llist->flags |= LYS_SET_UNITS;
@@ -3970,7 +3958,7 @@
LY_CHECK_RET(lys_compile_node(ctx, child_p, node, 0));
}
- COMPILE_ARRAY_MUST_GOTO(ctx, list_p->musts, list->musts, u, node, ret, done);
+ COMPILE_ARRAY_GOTO(ctx, list_p->musts, list->musts, u, lys_compile_must, ret, done);
/* keys */
if ((list->flags & LYS_CONFIG_W) && (!list_p->key || !list_p->key[0])) {
@@ -4269,7 +4257,7 @@
unsigned int u;
LY_ERR ret = LY_SUCCESS;
- COMPILE_ARRAY_MUST_GOTO(ctx, any_p->musts, any->musts, u, node, ret, done);
+ COMPILE_ARRAY_GOTO(ctx, any_p->musts, any->musts, u, lys_compile_must, ret, done);
if (any->flags & LYS_CONFIG_W) {
LOGWRN(ctx->ctx, "Use of %s to define configuration data is not recommended.",
@@ -5159,20 +5147,20 @@
if (rfn->musts) {
switch (node->nodetype) {
case LYS_LEAF:
- COMPILE_ARRAY_MUST_GOTO(ctx, rfn->musts, ((struct lysc_node_leaf*)node)->musts, u, node, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, rfn->musts, ((struct lysc_node_leaf*)node)->musts, u, lys_compile_must, ret, cleanup);
break;
case LYS_LEAFLIST:
- COMPILE_ARRAY_MUST_GOTO(ctx, rfn->musts, ((struct lysc_node_leaflist*)node)->musts, u, node, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, rfn->musts, ((struct lysc_node_leaflist*)node)->musts, u, lys_compile_must, ret, cleanup);
break;
case LYS_LIST:
- COMPILE_ARRAY_MUST_GOTO(ctx, rfn->musts, ((struct lysc_node_list*)node)->musts, u, node, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, rfn->musts, ((struct lysc_node_list*)node)->musts, u, lys_compile_must, ret, cleanup);
break;
case LYS_CONTAINER:
- COMPILE_ARRAY_MUST_GOTO(ctx, rfn->musts, ((struct lysc_node_container*)node)->musts, u, node, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, rfn->musts, ((struct lysc_node_container*)node)->musts, u, lys_compile_must, ret, cleanup);
break;
case LYS_ANYXML:
case LYS_ANYDATA:
- COMPILE_ARRAY_MUST_GOTO(ctx, rfn->musts, ((struct lysc_node_anydata*)node)->musts, u, node, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, rfn->musts, ((struct lysc_node_anydata*)node)->musts, u, lys_compile_must, ret, cleanup);
break;
default:
LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS,
@@ -5960,27 +5948,27 @@
switch (devs[u]->target->nodetype) {
case LYS_CONTAINER:
case LYS_LIST:
- COMPILE_ARRAY_MUST_GOTO(ctx, d_add->musts, ((struct lysc_node_container*)devs[u]->target)->musts,
- x, devs[u]->target, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, d_add->musts, ((struct lysc_node_container*)devs[u]->target)->musts,
+ x, lys_compile_must, ret, cleanup);
break;
case LYS_LEAF:
case LYS_LEAFLIST:
case LYS_ANYDATA:
- COMPILE_ARRAY_MUST_GOTO(ctx, d_add->musts, ((struct lysc_node_leaf*)devs[u]->target)->musts,
- x, devs[u]->target, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, d_add->musts, ((struct lysc_node_leaf*)devs[u]->target)->musts,
+ x, lys_compile_must, ret, cleanup);
break;
case LYS_NOTIF:
- COMPILE_ARRAY_MUST_GOTO(ctx, d_add->musts, ((struct lysc_notif*)devs[u]->target)->musts,
- x, devs[u]->target, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, d_add->musts, ((struct lysc_notif*)devs[u]->target)->musts,
+ x, lys_compile_must, ret, cleanup);
break;
case LYS_ACTION:
if (devs[u]->flags & LYSC_OPT_RPC_INPUT) {
- COMPILE_ARRAY_MUST_GOTO(ctx, d_add->musts, ((struct lysc_action*)devs[u]->target)->input.musts,
- x, devs[u]->target, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, d_add->musts, ((struct lysc_action*)devs[u]->target)->input.musts,
+ x, lys_compile_must, ret, cleanup);
break;
} else if (devs[u]->flags & LYSC_OPT_RPC_OUTPUT) {
- COMPILE_ARRAY_MUST_GOTO(ctx, d_add->musts, ((struct lysc_action*)devs[u]->target)->output.musts,
- x, devs[u]->target, ret, cleanup);
+ COMPILE_ARRAY_GOTO(ctx, d_add->musts, ((struct lysc_action*)devs[u]->target)->output.musts,
+ x, lys_compile_must, ret, cleanup);
break;
}
/* fall through */