compiled schema NEW when dummy node check
Also, no need to check it in data now.
diff --git a/src/xpath.c b/src/xpath.c
index 995941c..93dd7f6 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -502,11 +502,6 @@
{
int dynamic;
- if ((set->val.nodes[0].type != LYXP_NODE_ATTR) && (set->val.nodes[0].node->flags & LYD_DUMMY)) {
- LOGVAL(set->ctx, LY_VLOG_LYD, set->val.nodes[0].node, LY_VCODE_XP_DUMMY, set->val.nodes[0].node->schema->name);
- return LY_EVALID;
- }
-
switch (set->val.nodes[0].type) {
case LYXP_NODE_ROOT:
case LYXP_NODE_ROOT_CONFIG:
@@ -924,6 +919,8 @@
for (i = 0; i < set->used; ++i) {
if (set->val.scnodes[i].in_ctx == 1) {
set->val.scnodes[i].in_ctx = 0;
+ } else if (set->val.scnodes[i].in_ctx == -2) {
+ set->val.scnodes[i].in_ctx = -1;
}
}
}
@@ -1223,10 +1220,11 @@
* @param[in] set Set to modify.
* @return New context value.
*/
-static uint32_t
+static int32_t
set_scnode_new_in_ctx(struct lyxp_set *set)
{
- uint32_t ret_ctx, i;
+ uint32_t i;
+ int32_t ret_ctx;
assert(set->type == LYXP_SET_SCNODE_SET);
@@ -4969,6 +4967,8 @@
return LY_EVALID;
}
+ set_init(&set_item, set);
+
set_item.type = LYXP_SET_NODE_SET;
set_item.val.nodes = malloc(sizeof *set_item.val.nodes);
LY_CHECK_ERR_RET(!set_item.val.nodes, LOGMEM(set->ctx), LY_EMEM);
@@ -5022,10 +5022,6 @@
for (i = 0; i < set->used;) {
switch (set->val.nodes[i].type) {
case LYXP_NODE_ELEM:
- if (set->val.nodes[i].node->flags & LYD_DUMMY) {
- LOGVAL(set->ctx, LY_VLOG_LYD, set->val.nodes[i].node, LY_VCODE_XP_DUMMY, set->val.nodes[i].node->schema->name);
- return LY_EVALID;
- }
if (set->val.nodes[i].node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
set->val.nodes[i].type = LYXP_NODE_TEXT;
++i;
@@ -5278,8 +5274,8 @@
return LY_ENOT;
}
- /* dummy and context check */
- if ((node->flags & LYD_DUMMY) || ((root_type == LYXP_NODE_ROOT_CONFIG) && (node->schema->flags & LYS_CONFIG_R))) {
+ /* context check */
+ if ((root_type == LYXP_NODE_ROOT_CONFIG) && (node->schema->flags & LYS_CONFIG_R)) {
return LY_EINVAL;
}
@@ -5389,9 +5385,8 @@
}
}
- /* skip nodes without children - leaves, leaflists, anyxmls, and dummy nodes (ouput root will eval to true) */
- } else if (!(set->val.nodes[i].node->flags & LYD_DUMMY)
- && !(set->val.nodes[i].node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) {
+ /* skip nodes without children - leaves, leaflists, anyxmls (ouput root will eval to true) */
+ } else if (!(set->val.nodes[i].node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) {
for (sub = lyd_node_children(set->val.nodes[i].node); sub; sub = sub->next) {
rc = moveto_node_check(sub, set->root_type, name_dict, moveto_mod);
@@ -5464,9 +5459,13 @@
orig_used = set->used;
for (i = 0; i < orig_used; ++i) {
if (set->val.scnodes[i].in_ctx != 1) {
- continue;
+ if (set->val.scnodes[i].in_ctx != -2) {
+ continue;
+ }
+
+ /* remember context node */
+ set->val.scnodes[i].in_ctx = -1;
}
- set->val.scnodes[i].in_ctx = 0;
start_parent = set->val.scnodes[i].scnode;
@@ -5657,9 +5656,13 @@
orig_used = set->used;
for (i = 0; i < orig_used; ++i) {
if (set->val.scnodes[i].in_ctx != 1) {
- continue;
+ if (set->val.scnodes[i].in_ctx != -2) {
+ continue;
+ }
+
+ /* remember context node */
+ set->val.scnodes[i].in_ctx = -1;
}
- set->val.scnodes[i].in_ctx = 0;
/* TREE DFS */
start = set->val.scnodes[i].scnode;
@@ -5757,7 +5760,7 @@
/* only attributes of an elem (not dummy) can be in the result, skip all the rest;
* our attributes are always qualified */
- if ((set->val.nodes[i].type == LYXP_NODE_ELEM) && !(set->val.nodes[i].node->flags & LYD_DUMMY)) {
+ if (set->val.nodes[i].type == LYXP_NODE_ELEM) {
for (sub = set->val.nodes[i].node->attr; sub; sub = sub->next) {
/* check "namespace" */
@@ -5950,7 +5953,7 @@
set_insert_node(to_set, parent, 0, LYXP_NODE_ELEM, to_set->used);
/* skip anydata/anyxml and dummy nodes */
- if (!(parent->schema->nodetype & LYS_ANYDATA) && !(parent->flags & LYD_DUMMY)) {
+ if (!(parent->schema->nodetype & LYS_ANYDATA)) {
/* also add all the children of this node, recursively */
rc = moveto_self_add_children_r(parent, 0, LYXP_NODE_ELEM, to_set, dup_check_set, options);
LY_CHECK_RET(rc);
@@ -5974,8 +5977,8 @@
if (!set_dup_node_check(dup_check_set, sub, LYXP_NODE_ELEM, -1)) {
set_insert_node(to_set, sub, 0, LYXP_NODE_ELEM, to_set->used);
- /* skip anydata/anyxml and dummy nodes */
- if ((sub->schema->nodetype & LYS_ANYDATA) || (sub->flags & LYD_DUMMY)) {
+ /* skip anydata/anyxml nodes */
+ if (sub->schema->nodetype & LYS_ANYDATA) {
continue;
}
@@ -6040,8 +6043,8 @@
continue;
}
- /* skip anydata/anyxml and dummy nodes */
- if ((set->val.nodes[i].node->schema->nodetype & LYS_ANYDATA) || (set->val.nodes[i].node->flags & LYD_DUMMY)) {
+ /* skip anydata/anyxml nodes */
+ if (set->val.nodes[i].node->schema->nodetype & LYS_ANYDATA) {
continue;
}
@@ -6095,7 +6098,12 @@
/* add all the children, they get added recursively */
for (i = 0; i < set->used; ++i) {
if (set->val.scnodes[i].in_ctx != 1) {
- continue;
+ if (set->val.scnodes[i].in_ctx != -2) {
+ continue;
+ }
+
+ /* remember context node (it was traversed again so it changes to a normal node) */
+ set->val.scnodes[i].in_ctx = 1;
}
/* add all the children */
@@ -6239,9 +6247,13 @@
orig_used = set->used;
for (i = 0; i < orig_used; ++i) {
if (set->val.scnodes[i].in_ctx != 1) {
- continue;
+ if (set->val.scnodes[i].in_ctx != -2) {
+ continue;
+ }
+
+ /* remember context node */
+ set->val.scnodes[i].in_ctx = -1;
}
- set->val.scnodes[i].in_ctx = 0;
node = set->val.scnodes[i].scnode;
@@ -6613,7 +6625,7 @@
if ((rc == LY_SUCCESS) && set && (options & LYXP_SCNODE_ALL)) {
for (i = set->used - 1; i > -1; --i) {
- if (set->val.scnodes[i].in_ctx) {
+ if (set->val.scnodes[i].in_ctx > 0) {
break;
}
}
@@ -6692,7 +6704,8 @@
{
LY_ERR rc;
uint16_t i, orig_exp;
- uint32_t orig_pos, orig_size, pred_in_ctx;
+ uint32_t orig_pos, orig_size;
+ int32_t pred_in_ctx;
struct lyxp_set set2;
struct lyd_node *orig_parent;
@@ -8307,6 +8320,7 @@
memset(set, 0, sizeof *set);
set->type = LYXP_SET_SCNODE_SET;
lyxp_set_scnode_insert_node(set, ctx_scnode, ctx_scnode_type);
+ set->val.scnodes[0].in_ctx = -2;
set->ctx = ctx;
set->ctx_scnode = ctx_scnode;
set->root_type = lyxp_get_root_type(NULL, ctx_scnode, options);