schema CHANGE move when statement from common schema node structure

The when statement is not present in many of the lysc_node* and
lysp_node* structures. It is actually similar to the must statement
which is placed in the specific schema node structures, so it make sense
to move the when statement to the same place.

Some helpers functions to access the musts and whens were added.
diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c
index c491f32..240804c 100644
--- a/src/schema_compile_amend.c
+++ b/src/schema_compile_amend.c
@@ -386,19 +386,19 @@
     DUP_STRING(ctx, orig->name, node->name, ret);
     DUP_STRING(ctx, orig->dsc, node->dsc, ret);
     DUP_STRING(ctx, orig->ref, node->ref, ret);
-
-    if (orig->when) {
-        node->when = calloc(1, sizeof *node->when);
-        LY_CHECK_ERR_RET(!node->when, LOGMEM(ctx), LY_EMEM);
-        LY_CHECK_RET(lysp_when_dup(ctx, node->when, orig->when));
-    }
-
     DUP_ARRAY(ctx, orig->iffeatures, node->iffeatures, lysp_qname_dup);
     DUP_ARRAY(ctx, orig->exts, node->exts, lysp_ext_dup);
 
     return ret;
 }
 
+#define DUP_PWHEN(CTX, ORIG, NEW) \
+    if (ORIG) { \
+        NEW = calloc(1, sizeof *NEW); \
+        LY_CHECK_ERR_RET(!NEW, LOGMEM(CTX), LY_EMEM); \
+        LY_CHECK_RET(lysp_when_dup(CTX, NEW, ORIG)); \
+    }
+
 static LY_ERR
 lysp_node_dup(const struct ly_ctx *ctx, struct lysp_node *node, const struct lysp_node *orig)
 {
@@ -436,6 +436,7 @@
         cont = (struct lysp_node_container *)node;
         orig_cont = (const struct lysp_node_container *)orig;
 
+        DUP_PWHEN(ctx, orig_cont->when, cont->when);
         DUP_ARRAY(ctx, orig_cont->musts, cont->musts, lysp_restr_dup);
         DUP_STRING(ctx, orig_cont->presence, cont->presence, ret);
         /* we do not need the rest */
@@ -444,6 +445,7 @@
         leaf = (struct lysp_node_leaf *)node;
         orig_leaf = (const struct lysp_node_leaf *)orig;
 
+        DUP_PWHEN(ctx, orig_leaf->when, leaf->when);
         DUP_ARRAY(ctx, orig_leaf->musts, leaf->musts, lysp_restr_dup);
         LY_CHECK_RET(lysp_type_dup(ctx, &leaf->type, &orig_leaf->type));
         DUP_STRING(ctx, orig_leaf->units, leaf->units, ret);
@@ -453,6 +455,7 @@
         llist = (struct lysp_node_leaflist *)node;
         orig_llist = (const struct lysp_node_leaflist *)orig;
 
+        DUP_PWHEN(ctx, orig_llist->when, llist->when);
         DUP_ARRAY(ctx, orig_llist->musts, llist->musts, lysp_restr_dup);
         LY_CHECK_RET(lysp_type_dup(ctx, &llist->type, &orig_llist->type));
         DUP_STRING(ctx, orig_llist->units, llist->units, ret);
@@ -464,6 +467,7 @@
         list = (struct lysp_node_list *)node;
         orig_list = (const struct lysp_node_list *)orig;
 
+        DUP_PWHEN(ctx, orig_list->when, list->when);
         DUP_ARRAY(ctx, orig_list->musts, list->musts, lysp_restr_dup);
         DUP_STRING(ctx, orig_list->key, list->key, ret);
         /* we do not need these arrays */
@@ -475,6 +479,7 @@
         choice = (struct lysp_node_choice *)node;
         orig_choice = (const struct lysp_node_choice *)orig;
 
+        DUP_PWHEN(ctx, orig_choice->when, choice->when);
         /* we do not need children */
         LY_CHECK_RET(lysp_qname_dup(ctx, &choice->dflt, &orig_choice->dflt));
         break;
@@ -482,15 +487,15 @@
         cas = (struct lysp_node_case *)node;
         orig_cas = (const struct lysp_node_case *)orig;
 
+        DUP_PWHEN(ctx, orig_cas->when, cas->when);
         /* we do not need children */
-        (void)cas;
-        (void)orig_cas;
         break;
     case LYS_ANYDATA:
     case LYS_ANYXML:
         any = (struct lysp_node_anydata *)node;
         orig_any = (const struct lysp_node_anydata *)orig;
 
+        DUP_PWHEN(ctx, orig_any->when, any->when);
         DUP_ARRAY(ctx, orig_any->musts, any->musts, lysp_restr_dup);
         break;
     case LYS_RPC:
@@ -855,23 +860,8 @@
 
     /* *must-stmt */
     if (d->musts) {
-        switch (target->nodetype) {
-        case LYS_CONTAINER:
-        case LYS_LIST:
-        case LYS_LEAF:
-        case LYS_LEAFLIST:
-        case LYS_ANYDATA:
-        case LYS_ANYXML:
-            musts = &((struct lysp_node_container *)target)->musts;
-            break;
-        case LYS_NOTIF:
-            musts = &((struct lysp_node_notif *)target)->musts;
-            break;
-        case LYS_INPUT:
-        case LYS_OUTPUT:
-            musts = &((struct lysp_node_action_inout *)target)->musts;
-            break;
-        default:
+        musts = lysp_node_musts_p(target);
+        if (!musts) {
             AMEND_WRONG_NODETYPE("deviation", "add", "must");
         }
 
@@ -1098,23 +1088,8 @@
 
     /* *must-stmt */
     if (d->musts) {
-        switch (target->nodetype) {
-        case LYS_CONTAINER:
-        case LYS_LIST:
-        case LYS_LEAF:
-        case LYS_LEAFLIST:
-        case LYS_ANYDATA:
-        case LYS_ANYXML:
-            musts = &((struct lysp_node_container *)target)->musts;
-            break;
-        case LYS_NOTIF:
-            musts = &((struct lysp_node_notif *)target)->musts;
-            break;
-        case LYS_INPUT:
-        case LYS_OUTPUT:
-            musts = &((struct lysp_node_action_inout *)target)->musts;
-            break;
-        default:
+        musts = lysp_node_musts_p(target);
+        if (!musts) {
             AMEND_WRONG_NODETYPE("deviation", "delete", "must");
         }
 
@@ -1375,42 +1350,6 @@
 }
 
 /**
- * @brief Check whether a parsed node matches a single schema nodeid name test.
- *
- * @param[in] pnode Parsed node to consider.
- * @param[in] pnode_mod Compiled @p pnode to-be module.
- * @param[in] mod Expected module.
- * @param[in] name Expected name.
- * @param[in] name_len Length of @p name.
- * @return Whether it is a match or not.
- */
-static ly_bool
-lysp_schema_nodeid_match_pnode(const struct lysp_node *pnode, const struct lys_module *pnode_mod,
-        const struct lys_module *mod, const char *name, size_t name_len)
-{
-    const char *pname;
-
-    /* compare with the module of the node */
-    if (pnode_mod != mod) {
-        return 0;
-    }
-
-    /* compare names */
-    if (pnode->nodetype & (LYS_ACTION | LYS_RPC)) {
-        pname = ((struct lysp_node_action *)pnode)->name;
-    } else if (pnode->nodetype & (LYS_INPUT | LYS_OUTPUT)) {
-        pname = (pnode->nodetype & LYS_INPUT) ? "input" : "output";
-    } else {
-        pname = pnode->name;
-    }
-    if (ly_strncmp(pname, name, name_len)) {
-        return 0;
-    }
-
-    return 1;
-}
-
-/**
  * @brief Check whether a compiled node matches a single schema nodeid name test.
  *
  * @param[in,out] node Compiled node to consider. On a match it is moved to its parent.
@@ -1477,7 +1416,7 @@
 
     if (pnode) {
         /* compare on the last parsed-only node */
-        if (!lysp_schema_nodeid_match_pnode(pnode, pnode_mod, mod, name, name_len)) {
+        if (pnode_mod != mod || ly_strncmp(pnode->name, name, name_len)) {
             return 0;
         }
     } else {