Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file schema_compile.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | 19a0902 | 2021-06-15 11:54:08 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 5 | * @brief Schema compilation. |
| 6 | * |
Michal Vasko | 35274cf | 2024-07-04 12:01:00 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2024 CESNET, z.s.p.o. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
| 16 | #define _GNU_SOURCE |
| 17 | |
| 18 | #include "schema_compile.h" |
| 19 | |
| 20 | #include <assert.h> |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 21 | #include <stddef.h> |
| 22 | #include <stdint.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 27 | #include "compat.h" |
| 28 | #include "context.h" |
| 29 | #include "dict.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 30 | #include "in.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 31 | #include "log.h" |
Michal Vasko | 8f702ee | 2024-02-20 15:44:24 +0100 | [diff] [blame] | 32 | #include "ly_common.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 33 | #include "parser_schema.h" |
| 34 | #include "path.h" |
Radek Krejci | 0aa1f70 | 2021-04-01 16:16:19 +0200 | [diff] [blame] | 35 | #include "plugins.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 36 | #include "plugins_exts.h" |
Radek Krejci | 3e6632f | 2021-03-22 22:08:21 +0100 | [diff] [blame] | 37 | #include "plugins_internal.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 38 | #include "plugins_types.h" |
| 39 | #include "schema_compile_amend.h" |
| 40 | #include "schema_compile_node.h" |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 41 | #include "schema_features.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 42 | #include "set.h" |
| 43 | #include "tree.h" |
| 44 | #include "tree_data.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 45 | #include "tree_schema.h" |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 46 | #include "tree_schema_free.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 47 | #include "tree_schema_internal.h" |
| 48 | #include "xpath.h" |
| 49 | |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 50 | void |
| 51 | lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, const char *name) |
| 52 | { |
| 53 | int len; |
| 54 | uint8_t nextlevel = 0; /* 0 - no starttag, 1 - '/' starttag, 2 - '=' starttag + '}' endtag */ |
| 55 | |
| 56 | if (!name) { |
| 57 | /* removing last path segment */ |
| 58 | if (ctx->path[ctx->path_len - 1] == '}') { |
| 59 | for ( ; ctx->path[ctx->path_len] != '=' && ctx->path[ctx->path_len] != '{'; --ctx->path_len) {} |
| 60 | if (ctx->path[ctx->path_len] == '=') { |
| 61 | ctx->path[ctx->path_len++] = '}'; |
| 62 | } else { |
| 63 | /* not a top-level special tag, remove also preceiding '/' */ |
| 64 | goto remove_nodelevel; |
| 65 | } |
| 66 | } else { |
| 67 | remove_nodelevel: |
| 68 | for ( ; ctx->path[ctx->path_len] != '/'; --ctx->path_len) {} |
| 69 | if (ctx->path_len == 0) { |
| 70 | /* top-level (last segment) */ |
| 71 | ctx->path_len = 1; |
| 72 | } |
| 73 | } |
| 74 | /* set new terminating NULL-byte */ |
| 75 | ctx->path[ctx->path_len] = '\0'; |
| 76 | } else { |
| 77 | if (ctx->path_len > 1) { |
| 78 | if (!parent_module && (ctx->path[ctx->path_len - 1] == '}') && (ctx->path[ctx->path_len - 2] != '\'')) { |
| 79 | /* extension of the special tag */ |
| 80 | nextlevel = 2; |
| 81 | --ctx->path_len; |
| 82 | } else { |
| 83 | /* there is already some path, so add next level */ |
| 84 | nextlevel = 1; |
| 85 | } |
| 86 | } /* else the path is just initiated with '/', so do not add additional slash in case of top-level nodes */ |
| 87 | |
| 88 | if (nextlevel != 2) { |
| 89 | if ((parent_module && (parent_module == ctx->cur_mod)) || (!parent_module && (ctx->path_len > 1) && (name[0] == '{'))) { |
| 90 | /* module not changed, print the name unprefixed */ |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 91 | len = snprintf(&ctx->path[ctx->path_len], LYSC_CTX_BUFSIZE - ctx->path_len, "%s%s", |
| 92 | nextlevel ? "/" : "", name); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 93 | } else { |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 94 | len = snprintf(&ctx->path[ctx->path_len], LYSC_CTX_BUFSIZE - ctx->path_len, "%s%s:%s", |
| 95 | nextlevel ? "/" : "", ctx->cur_mod->name, name); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 96 | } |
| 97 | } else { |
| 98 | len = snprintf(&ctx->path[ctx->path_len], LYSC_CTX_BUFSIZE - ctx->path_len, "='%s'}", name); |
| 99 | } |
| 100 | if (len >= LYSC_CTX_BUFSIZE - (int)ctx->path_len) { |
| 101 | /* output truncated */ |
| 102 | ctx->path_len = LYSC_CTX_BUFSIZE - 1; |
| 103 | } else { |
| 104 | ctx->path_len += len; |
| 105 | } |
| 106 | } |
| 107 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 108 | ly_log_location_revert(0, 0, 1, 0); |
| 109 | ly_log_location(NULL, NULL, ctx->path, NULL); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 112 | /** |
| 113 | * @brief Fill in the prepared compiled extensions definition structure according to the parsed extension definition. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 114 | * |
| 115 | * @param[in] ctx Compile context. |
| 116 | * @param[in] extp Parsed extension instance. |
| 117 | * @param[out] ext Compiled extension definition. |
| 118 | * @return LY_ERR value. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 119 | */ |
| 120 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 121 | lys_compile_extension(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lysc_ext **ext) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 122 | { |
| 123 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 124 | struct lysp_ext *ep = extp->def; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 125 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 126 | if (!ep->compiled) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 127 | lysc_update_path(ctx, NULL, "{extension}"); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 128 | lysc_update_path(ctx, NULL, ep->name); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 129 | |
| 130 | /* compile the extension definition */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 131 | *ext = ep->compiled = calloc(1, sizeof **ext); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 132 | DUP_STRING_GOTO(ctx->ctx, ep->name, (*ext)->name, ret, cleanup); |
| 133 | DUP_STRING_GOTO(ctx->ctx, ep->argname, (*ext)->argname, ret, cleanup); |
| 134 | LY_CHECK_GOTO(ret = lysp_ext_find_definition(ctx->ctx, extp, (const struct lys_module **)&(*ext)->module, NULL), |
| 135 | cleanup); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 136 | |
| 137 | /* compile nested extensions */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 138 | COMPILE_EXTS_GOTO(ctx, ep->exts, (*ext)->exts, *ext, ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 139 | |
| 140 | lysc_update_path(ctx, NULL, NULL); |
| 141 | lysc_update_path(ctx, NULL, NULL); |
| 142 | |
| 143 | /* find extension definition plugin */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 144 | (*ext)->plugin = extp->record ? (struct lyplg_ext *)&extp->record->plugin : NULL; |
Michal Vasko | 54b1195 | 2022-06-08 12:29:39 +0200 | [diff] [blame] | 145 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 146 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 147 | *ext = ep->compiled; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 148 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 149 | cleanup: |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 150 | if (ret) { |
| 151 | lysc_update_path(ctx, NULL, NULL); |
| 152 | lysc_update_path(ctx, NULL, NULL); |
| 153 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 158 | lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lysc_ext_instance *ext, void *parent) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 159 | { |
Radek Krejci | 85ac831 | 2021-03-03 20:21:33 +0100 | [diff] [blame] | 160 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 161 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 162 | DUP_STRING_GOTO(ctx->ctx, extp->argument, ext->argument, ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 163 | ext->module = ctx->cur_mod; |
| 164 | ext->parent = parent; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 165 | ext->parent_stmt = extp->parent_stmt; |
| 166 | ext->parent_stmt_index = extp->parent_stmt_index; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 167 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 168 | lysc_update_path(ctx, (ext->parent_stmt & LY_STMT_NODE_MASK) ? ((struct lysc_node *)ext->parent)->module : NULL, |
| 169 | "{extension}"); |
| 170 | lysc_update_path(ctx, NULL, extp->name); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 171 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 172 | /* compile extension if not already */ |
| 173 | LY_CHECK_GOTO(ret = lys_compile_extension(ctx, extp, &ext->def), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 174 | |
Michal Vasko | 35274cf | 2024-07-04 12:01:00 +0200 | [diff] [blame] | 175 | /* compile nested extensions */ |
| 176 | COMPILE_EXTS_GOTO(ctx, extp->exts, ext->exts, ext, ret, cleanup); |
| 177 | |
| 178 | /* compile this extension */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 179 | if (ext->def->plugin && ext->def->plugin->compile) { |
| 180 | if (ext->argument) { |
Radek Krejci | a601699 | 2021-03-03 10:13:41 +0100 | [diff] [blame] | 181 | lysc_update_path(ctx, ext->module, ext->argument); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 182 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 183 | ret = ext->def->plugin->compile(ctx, extp, ext); |
Radek Krejci | cc21a4f | 2021-02-09 15:23:31 +0100 | [diff] [blame] | 184 | if (ret == LY_ENOT) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 185 | lysc_ext_instance_free(&ctx->free_ctx, ext); |
Radek Krejci | cc21a4f | 2021-02-09 15:23:31 +0100 | [diff] [blame] | 186 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 187 | if (ext->argument) { |
| 188 | lysc_update_path(ctx, NULL, NULL); |
| 189 | } |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 190 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 191 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 192 | |
| 193 | cleanup: |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 194 | lysc_update_path(ctx, NULL, NULL); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 195 | lysc_update_path(ctx, NULL, NULL); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 196 | return ret; |
| 197 | } |
| 198 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 199 | static void |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 200 | lysc_unres_must_free(struct lysc_unres_must *m) |
| 201 | { |
| 202 | LY_ARRAY_FREE(m->local_mods); |
| 203 | free(m); |
| 204 | } |
| 205 | |
| 206 | static void |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 207 | lysc_unres_dflt_free(const struct ly_ctx *ctx, struct lysc_unres_dflt *r) |
| 208 | { |
| 209 | assert(!r->dflt || !r->dflts); |
| 210 | if (r->dflt) { |
| 211 | lysp_qname_free((struct ly_ctx *)ctx, r->dflt); |
| 212 | free(r->dflt); |
| 213 | } else { |
| 214 | FREE_ARRAY((struct ly_ctx *)ctx, r->dflts, lysp_qname_free); |
| 215 | } |
| 216 | free(r); |
| 217 | } |
| 218 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 219 | LY_ERR |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 220 | lys_identity_precompile(struct lysc_ctx *ctx_sc, struct ly_ctx *ctx, struct lysp_module *parsed_mod, |
Michal Vasko | 9b23208 | 2022-06-07 10:59:31 +0200 | [diff] [blame] | 221 | const struct lysp_ident *identities_p, struct lysc_ident **identities) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 222 | { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 223 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 0c9a1d3 | 2024-09-11 13:53:39 +0200 | [diff] [blame] | 224 | struct lysc_ctx cctx = {0}; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 225 | struct lysc_ident *ident; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 226 | LY_ERR ret = LY_SUCCESS; |
| 227 | |
| 228 | assert(ctx_sc || ctx); |
| 229 | |
| 230 | if (!ctx_sc) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 231 | if (parsed_mod) { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 232 | LYSC_CTX_INIT_PMOD(cctx, parsed_mod, NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 233 | } else { |
| 234 | LYSC_CTX_INIT_CTX(cctx, ctx); |
| 235 | } |
| 236 | ctx_sc = &cctx; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | if (!identities_p) { |
| 240 | return LY_SUCCESS; |
| 241 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 242 | |
| 243 | lysc_update_path(ctx_sc, NULL, "{identity}"); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 244 | LY_ARRAY_FOR(identities_p, u) { |
| 245 | lysc_update_path(ctx_sc, NULL, identities_p[u].name); |
| 246 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 247 | /* add new compiled identity */ |
Michal Vasko | 9b23208 | 2022-06-07 10:59:31 +0200 | [diff] [blame] | 248 | LY_ARRAY_NEW_GOTO(ctx_sc->ctx, *identities, ident, ret, done); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 249 | |
| 250 | DUP_STRING_GOTO(ctx_sc->ctx, identities_p[u].name, ident->name, ret, done); |
| 251 | DUP_STRING_GOTO(ctx_sc->ctx, identities_p[u].dsc, ident->dsc, ret, done); |
| 252 | DUP_STRING_GOTO(ctx_sc->ctx, identities_p[u].ref, ident->ref, ret, done); |
| 253 | ident->module = ctx_sc->cur_mod; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 254 | /* backlinks (derived) can be added no sooner than when all the identities in the current module are present */ |
Radek Krejci | ab43086 | 2021-03-02 20:13:40 +0100 | [diff] [blame] | 255 | COMPILE_EXTS_GOTO(ctx_sc, identities_p[u].exts, ident->exts, ident, ret, done); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 256 | ident->flags = identities_p[u].flags; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 257 | |
| 258 | lysc_update_path(ctx_sc, NULL, NULL); |
| 259 | } |
| 260 | lysc_update_path(ctx_sc, NULL, NULL); |
Michal Vasko | 9b23208 | 2022-06-07 10:59:31 +0200 | [diff] [blame] | 261 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 262 | done: |
Michal Vasko | 9b23208 | 2022-06-07 10:59:31 +0200 | [diff] [blame] | 263 | if (ret) { |
| 264 | lysc_update_path(ctx_sc, NULL, NULL); |
| 265 | lysc_update_path(ctx_sc, NULL, NULL); |
| 266 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 267 | return ret; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * @brief Check circular dependency of identities - identity MUST NOT reference itself (via their base statement). |
| 272 | * |
| 273 | * The function works in the same way as lys_compile_feature_circular_check() with different structures and error messages. |
| 274 | * |
| 275 | * @param[in] ctx Compile context for logging. |
| 276 | * @param[in] ident The base identity (its derived list is being extended by the identity being currently processed). |
| 277 | * @param[in] derived The list of derived identities of the identity being currently processed (not the one provided as @p ident) |
| 278 | * @return LY_SUCCESS if everything is ok. |
| 279 | * @return LY_EVALID if the identity is derived from itself. |
| 280 | */ |
| 281 | static LY_ERR |
| 282 | lys_compile_identity_circular_check(struct lysc_ctx *ctx, struct lysc_ident *ident, struct lysc_ident **derived) |
| 283 | { |
| 284 | LY_ERR ret = LY_SUCCESS; |
| 285 | LY_ARRAY_COUNT_TYPE u, v; |
| 286 | struct ly_set recursion = {0}; |
| 287 | struct lysc_ident *drv; |
| 288 | |
| 289 | if (!derived) { |
| 290 | return LY_SUCCESS; |
| 291 | } |
| 292 | |
| 293 | for (u = 0; u < LY_ARRAY_COUNT(derived); ++u) { |
| 294 | if (ident == derived[u]) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 295 | LOGVAL(ctx->ctx, LYVE_REFERENCE, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 296 | "Identity \"%s\" is indirectly derived from itself.", ident->name); |
| 297 | ret = LY_EVALID; |
| 298 | goto cleanup; |
| 299 | } |
| 300 | ret = ly_set_add(&recursion, derived[u], 0, NULL); |
| 301 | LY_CHECK_GOTO(ret, cleanup); |
| 302 | } |
| 303 | |
| 304 | for (v = 0; v < recursion.count; ++v) { |
| 305 | drv = recursion.objs[v]; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 306 | for (u = 0; u < LY_ARRAY_COUNT(drv->derived); ++u) { |
| 307 | if (ident == drv->derived[u]) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 308 | LOGVAL(ctx->ctx, LYVE_REFERENCE, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 309 | "Identity \"%s\" is indirectly derived from itself.", ident->name); |
| 310 | ret = LY_EVALID; |
| 311 | goto cleanup; |
| 312 | } |
| 313 | ret = ly_set_add(&recursion, drv->derived[u], 0, NULL); |
| 314 | LY_CHECK_GOTO(ret, cleanup); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | cleanup: |
| 319 | ly_set_erase(&recursion, NULL); |
| 320 | return ret; |
| 321 | } |
| 322 | |
| 323 | LY_ERR |
| 324 | lys_compile_identity_bases(struct lysc_ctx *ctx, const struct lysp_module *base_pmod, const char **bases_p, |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 325 | struct lysc_ident *ident, struct lysc_ident ***bases) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 326 | { |
| 327 | LY_ARRAY_COUNT_TYPE u, v; |
| 328 | const char *s, *name; |
| 329 | const struct lys_module *mod; |
| 330 | struct lysc_ident **idref; |
| 331 | |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 332 | assert(ident || bases); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 333 | |
| 334 | if ((LY_ARRAY_COUNT(bases_p) > 1) && (ctx->pmod->version < LYS_VERSION_1_1)) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 335 | LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 336 | "Multiple bases in %s are allowed only in YANG 1.1 modules.", ident ? "identity" : "identityref type"); |
| 337 | return LY_EVALID; |
| 338 | } |
| 339 | |
| 340 | LY_ARRAY_FOR(bases_p, u) { |
| 341 | s = strchr(bases_p[u], ':'); |
| 342 | if (s) { |
| 343 | /* prefixed identity */ |
| 344 | name = &s[1]; |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 345 | mod = ly_resolve_prefix(ctx->ctx, bases_p[u], s - bases_p[u], LY_VALUE_SCHEMA, (void *)base_pmod); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 346 | } else { |
| 347 | name = bases_p[u]; |
| 348 | mod = base_pmod->mod; |
| 349 | } |
| 350 | if (!mod) { |
| 351 | if (ident) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 352 | LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 353 | "Invalid prefix used for base (%s) of identity \"%s\".", bases_p[u], ident->name); |
| 354 | } else { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 355 | LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 356 | "Invalid prefix used for base (%s) of identityref.", bases_p[u]); |
| 357 | } |
| 358 | return LY_EVALID; |
| 359 | } |
| 360 | |
| 361 | idref = NULL; |
| 362 | LY_ARRAY_FOR(mod->identities, v) { |
| 363 | if (!strcmp(name, mod->identities[v].name)) { |
| 364 | if (ident) { |
| 365 | if (ident == &mod->identities[v]) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 366 | LOGVAL(ctx->ctx, LYVE_REFERENCE, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 367 | "Identity \"%s\" is derived from itself.", ident->name); |
| 368 | return LY_EVALID; |
| 369 | } |
| 370 | LY_CHECK_RET(lys_compile_identity_circular_check(ctx, &mod->identities[v], ident->derived)); |
| 371 | /* we have match! store the backlink */ |
| 372 | LY_ARRAY_NEW_RET(ctx->ctx, mod->identities[v].derived, idref, LY_EMEM); |
| 373 | *idref = ident; |
| 374 | } else { |
| 375 | /* we have match! store the found identity */ |
| 376 | LY_ARRAY_NEW_RET(ctx->ctx, *bases, idref, LY_EMEM); |
| 377 | *idref = &mod->identities[v]; |
| 378 | } |
| 379 | break; |
| 380 | } |
| 381 | } |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 382 | if (!idref) { |
Radek Krejci | 10443f4 | 2021-03-28 17:40:35 +0200 | [diff] [blame] | 383 | if (ident) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 384 | LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 385 | "Unable to find base (%s) of identity \"%s\".", bases_p[u], ident->name); |
| 386 | } else { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 387 | LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 388 | "Unable to find base (%s) of identityref.", bases_p[u]); |
| 389 | } |
| 390 | return LY_EVALID; |
| 391 | } |
| 392 | } |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 393 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 394 | return LY_SUCCESS; |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * @brief For the given array of identities, set the backlinks from all their base identities. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 399 | * |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 400 | * @param[in] ctx Compile context, not only for logging but also to get the current module to resolve prefixes. |
| 401 | * @param[in] idents_p Array of identities definitions from the parsed schema structure. |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 402 | * @param[in,out] idents Array of referencing identities to which the backlinks are supposed to be set. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 403 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 404 | */ |
| 405 | static LY_ERR |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 406 | lys_compile_identities_derived(struct lysc_ctx *ctx, struct lysp_ident *idents_p, struct lysc_ident **idents) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 407 | { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 408 | LY_ARRAY_COUNT_TYPE u, v; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 409 | |
| 410 | lysc_update_path(ctx, NULL, "{identity}"); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 411 | |
aPiecek | f3e2db8 | 2021-08-05 10:18:43 +0200 | [diff] [blame] | 412 | for (u = 0; u < LY_ARRAY_COUNT(*idents); ++u) { |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 413 | /* find matching parsed identity */ |
aPiecek | f3e2db8 | 2021-08-05 10:18:43 +0200 | [diff] [blame] | 414 | for (v = 0; v < LY_ARRAY_COUNT(idents_p); ++v) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 415 | if (idents_p[v].name == (*idents)[u].name) { |
| 416 | break; |
| 417 | } |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 418 | } |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 419 | |
Michal Vasko | dc6f84c | 2021-06-15 14:50:27 +0200 | [diff] [blame] | 420 | if ((v == LY_ARRAY_COUNT(idents_p)) || !idents_p[v].bases) { |
| 421 | /* identity not found (it may be from a submodule) or identity without bases */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 422 | continue; |
| 423 | } |
Michal Vasko | dc6f84c | 2021-06-15 14:50:27 +0200 | [diff] [blame] | 424 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 425 | lysc_update_path(ctx, NULL, (*idents)[u].name); |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 426 | LY_CHECK_RET(lys_compile_identity_bases(ctx, ctx->pmod, idents_p[v].bases, &(*idents)[u], NULL)); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 427 | lysc_update_path(ctx, NULL, NULL); |
| 428 | } |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 429 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 430 | lysc_update_path(ctx, NULL, NULL); |
| 431 | return LY_SUCCESS; |
| 432 | } |
| 433 | |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 434 | LY_ERR |
| 435 | lys_compile_expr_implement(const struct ly_ctx *ctx, const struct lyxp_expr *expr, LY_VALUE_FORMAT format, |
| 436 | void *prefix_data, ly_bool implement, struct lys_glob_unres *unres, const struct lys_module **mod_p) |
| 437 | { |
| 438 | uint32_t i; |
| 439 | const char *ptr, *start, **imp_f, *all_f[] = {"*", NULL}; |
| 440 | const struct lys_module *mod; |
| 441 | |
| 442 | assert(implement || mod_p); |
| 443 | |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 444 | if (mod_p) { |
| 445 | *mod_p = NULL; |
| 446 | } |
| 447 | |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 448 | for (i = 0; i < expr->used; ++i) { |
| 449 | if ((expr->tokens[i] != LYXP_TOKEN_NAMETEST) && (expr->tokens[i] != LYXP_TOKEN_LITERAL)) { |
| 450 | /* token cannot have a prefix */ |
| 451 | continue; |
| 452 | } |
| 453 | |
| 454 | start = expr->expr + expr->tok_pos[i]; |
| 455 | if (!(ptr = ly_strnchr(start, ':', expr->tok_len[i]))) { |
| 456 | /* token without a prefix */ |
| 457 | continue; |
| 458 | } |
| 459 | |
| 460 | if (!(mod = ly_resolve_prefix(ctx, start, ptr - start, format, prefix_data))) { |
| 461 | /* unknown prefix, do not care right now */ |
| 462 | continue; |
| 463 | } |
| 464 | |
| 465 | /* unimplemented module found */ |
| 466 | if (!mod->implemented && !implement) { |
| 467 | /* should not be implemented now */ |
| 468 | *mod_p = mod; |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | if (!mod->implemented) { |
| 473 | /* implement if not implemented */ |
| 474 | imp_f = (ctx->flags & LY_CTX_ENABLE_IMP_FEATURES) ? all_f : NULL; |
| 475 | LY_CHECK_RET(lys_implement((struct lys_module *)mod, imp_f, unres)); |
| 476 | } |
| 477 | if (!mod->compiled) { |
| 478 | /* compile if not implemented before or only marked for compilation */ |
| 479 | LY_CHECK_RET(lys_compile((struct lys_module *)mod, &unres->ds_unres)); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | return LY_SUCCESS; |
| 484 | } |
| 485 | |
| 486 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 487 | * @brief Check when for cyclic dependencies. |
| 488 | * |
| 489 | * @param[in] set Set with all the referenced nodes. |
| 490 | * @param[in] node Node whose "when" referenced nodes are in @p set. |
| 491 | * @return LY_ERR value |
| 492 | */ |
| 493 | static LY_ERR |
| 494 | lys_compile_unres_when_cyclic(struct lyxp_set *set, const struct lysc_node *node) |
| 495 | { |
| 496 | struct lyxp_set tmp_set; |
| 497 | struct lyxp_set_scnode *xp_scnode; |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 498 | uint32_t i, j, idx; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 499 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 500 | LY_ERR ret = LY_SUCCESS; |
| 501 | |
| 502 | memset(&tmp_set, 0, sizeof tmp_set); |
| 503 | |
| 504 | /* prepare in_ctx of the set */ |
| 505 | for (i = 0; i < set->used; ++i) { |
| 506 | xp_scnode = &set->val.scnodes[i]; |
| 507 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 508 | if (xp_scnode->in_ctx != LYXP_SET_SCNODE_START_USED) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 509 | /* check node when, skip the context node (it was just checked) */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 510 | xp_scnode->in_ctx = LYXP_SET_SCNODE_ATOM_CTX; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
| 514 | for (i = 0; i < set->used; ++i) { |
| 515 | xp_scnode = &set->val.scnodes[i]; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 516 | if (xp_scnode->in_ctx != LYXP_SET_SCNODE_ATOM_CTX) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 517 | /* already checked */ |
| 518 | continue; |
| 519 | } |
| 520 | |
Michal Vasko | 1a09b21 | 2021-05-06 13:00:10 +0200 | [diff] [blame] | 521 | if ((xp_scnode->type != LYXP_NODE_ELEM) || !lysc_node_when(xp_scnode->scnode)) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 522 | /* no when to check */ |
Michal Vasko | 1a09b21 | 2021-05-06 13:00:10 +0200 | [diff] [blame] | 523 | xp_scnode->in_ctx = LYXP_SET_SCNODE_ATOM_NODE; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 524 | continue; |
| 525 | } |
| 526 | |
| 527 | node = xp_scnode->scnode; |
| 528 | do { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 529 | struct lysc_when **when_list, *when; |
| 530 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 531 | LOG_LOCSET(node, NULL); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 532 | when_list = lysc_node_when(node); |
| 533 | LY_ARRAY_FOR(when_list, u) { |
| 534 | when = when_list[u]; |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 535 | ret = lyxp_atomize(set->ctx, when->cond, node->module, LY_VALUE_SCHEMA_RESOLVED, when->prefixes, |
Michal Vasko | a3e92bc | 2022-07-29 14:56:23 +0200 | [diff] [blame] | 536 | when->context, when->context, &tmp_set, LYXP_SCNODE_SCHEMA); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 537 | if (ret != LY_SUCCESS) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 538 | LOGVAL(set->ctx, LYVE_SEMANTICS, "Invalid when condition \"%s\".", when->cond->expr); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 539 | LOG_LOCBACK(1, 0); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 540 | goto cleanup; |
| 541 | } |
| 542 | |
| 543 | for (j = 0; j < tmp_set.used; ++j) { |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 544 | if (tmp_set.val.scnodes[j].type != LYXP_NODE_ELEM) { |
| 545 | /* skip roots'n'stuff, no when, nothing to check */ |
Michal Vasko | 1a09b21 | 2021-05-06 13:00:10 +0200 | [diff] [blame] | 546 | tmp_set.val.scnodes[j].in_ctx = LYXP_SET_SCNODE_ATOM_NODE; |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 547 | continue; |
| 548 | } |
| 549 | |
| 550 | /* try to find this node in our set */ |
| 551 | if (lyxp_set_scnode_contains(set, tmp_set.val.scnodes[j].scnode, LYXP_NODE_ELEM, -1, &idx) && |
| 552 | (set->val.scnodes[idx].in_ctx == LYXP_SET_SCNODE_START_USED)) { |
| 553 | LOGVAL(set->ctx, LYVE_SEMANTICS, "When condition cyclic dependency on the node \"%s\".", |
| 554 | tmp_set.val.scnodes[j].scnode->name); |
| 555 | ret = LY_EVALID; |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 556 | LOG_LOCBACK(1, 0); |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 557 | goto cleanup; |
| 558 | } |
| 559 | |
| 560 | /* needs to be checked, if in both sets, will be ignored */ |
| 561 | tmp_set.val.scnodes[j].in_ctx = LYXP_SET_SCNODE_ATOM_CTX; |
| 562 | } |
| 563 | |
| 564 | if (when->context != node) { |
| 565 | /* node actually depends on this "when", not the context node */ |
| 566 | assert(tmp_set.val.scnodes[0].scnode == when->context); |
| 567 | if (tmp_set.val.scnodes[0].in_ctx == LYXP_SET_SCNODE_START_USED) { |
| 568 | /* replace the non-traversed context node with the dependent node */ |
| 569 | tmp_set.val.scnodes[0].scnode = (struct lysc_node *)node; |
| 570 | } else { |
| 571 | /* context node was traversed, so just add the dependent node */ |
| 572 | ret = lyxp_set_scnode_insert_node(&tmp_set, node, LYXP_SET_SCNODE_START_USED, LYXP_AXIS_CHILD, NULL); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 573 | LY_CHECK_ERR_GOTO(ret, LOG_LOCBACK(1, 0), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | /* merge this set into the global when set */ |
| 578 | lyxp_set_scnode_merge(set, &tmp_set); |
| 579 | } |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 580 | LOG_LOCBACK(1, 0); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 581 | |
| 582 | /* check when of non-data parents as well */ |
| 583 | node = node->parent; |
| 584 | } while (node && (node->nodetype & (LYS_CASE | LYS_CHOICE))); |
| 585 | |
| 586 | /* this node when was checked (xp_scnode could have been reallocd) */ |
Michal Vasko | 60edc2f | 2021-07-20 09:18:02 +0200 | [diff] [blame] | 587 | set->val.scnodes[i].in_ctx = LYXP_SET_SCNODE_ATOM_NODE; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | cleanup: |
| 591 | lyxp_set_free_content(&tmp_set); |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | LY_ERR |
| 596 | lysc_check_status(struct lysc_ctx *ctx, uint16_t flags1, void *mod1, const char *name1, uint16_t flags2, void *mod2, |
| 597 | const char *name2) |
| 598 | { |
| 599 | uint16_t flg1, flg2; |
| 600 | |
| 601 | flg1 = (flags1 & LYS_STATUS_MASK) ? (flags1 & LYS_STATUS_MASK) : LYS_STATUS_CURR; |
| 602 | flg2 = (flags2 & LYS_STATUS_MASK) ? (flags2 & LYS_STATUS_MASK) : LYS_STATUS_CURR; |
| 603 | |
| 604 | if ((flg1 < flg2) && (mod1 == mod2)) { |
| 605 | if (ctx) { |
Michal Vasko | 23864e0 | 2021-06-24 09:23:58 +0200 | [diff] [blame] | 606 | LOGVAL(ctx->ctx, LYVE_REFERENCE, "A %s definition \"%s\" is not allowed to reference %s definition \"%s\".", |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 607 | flg1 == LYS_STATUS_CURR ? "current" : "deprecated", name1, |
| 608 | flg2 == LYS_STATUS_OBSLT ? "obsolete" : "deprecated", name2); |
| 609 | } |
| 610 | return LY_EVALID; |
| 611 | } |
| 612 | |
| 613 | return LY_SUCCESS; |
| 614 | } |
| 615 | |
Michal Vasko | cfaff23 | 2020-10-20 09:35:14 +0200 | [diff] [blame] | 616 | /** |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 617 | * @brief Check when expressions of a node on a complete compiled schema tree. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 618 | * |
| 619 | * @param[in] ctx Compile context. |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 620 | * @param[in] when When to check. |
| 621 | * @param[in] node Node with @p when. |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 622 | * @return LY_ERR value. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 623 | */ |
| 624 | static LY_ERR |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 625 | lys_compile_unres_when(struct lysc_ctx *ctx, const struct lysc_when *when, const struct lysc_node *node) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 626 | { |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 627 | struct lyxp_set tmp_set = {0}; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 628 | uint32_t i, opts; |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 629 | struct lysc_node *schema; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 630 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 631 | |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 632 | opts = LYXP_SCNODE_SCHEMA | ((node->flags & LYS_IS_OUTPUT) ? LYXP_SCNODE_OUTPUT : 0); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 633 | |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 634 | /* check "when" */ |
| 635 | ret = lyxp_atomize(ctx->ctx, when->cond, node->module, LY_VALUE_SCHEMA_RESOLVED, when->prefixes, when->context, |
| 636 | when->context, &tmp_set, opts); |
| 637 | if (ret) { |
| 638 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Invalid when condition \"%s\".", when->cond->expr); |
| 639 | goto cleanup; |
| 640 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 641 | |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 642 | ctx->path[0] = '\0'; |
| 643 | lysc_path(node, LYSC_PATH_LOG, ctx->path, LYSC_CTX_BUFSIZE); |
| 644 | for (i = 0; i < tmp_set.used; ++i) { |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 645 | if (tmp_set.val.scnodes[i].type != LYXP_NODE_ELEM) { |
| 646 | /* skip roots'n'stuff */ |
| 647 | continue; |
| 648 | } else if (tmp_set.val.scnodes[i].in_ctx == LYXP_SET_SCNODE_START_USED) { |
| 649 | /* context node not actually traversed */ |
| 650 | continue; |
| 651 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 652 | |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 653 | schema = tmp_set.val.scnodes[i].scnode; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 654 | |
Michal Vasko | e4a6d01 | 2023-05-22 14:34:52 +0200 | [diff] [blame] | 655 | /* XPath expression cannot reference "lower" status than the node that has the definition */ |
| 656 | if (lysc_check_status(NULL, when->flags, node->module, node->name, schema->flags, schema->module, |
| 657 | schema->name)) { |
| 658 | LOGWRN(ctx->ctx, "When condition \"%s\" may be referencing %s node \"%s\".", when->cond->expr, |
| 659 | (schema->flags == LYS_STATUS_OBSLT) ? "obsolete" : "deprecated", schema->name); |
| 660 | } |
| 661 | |
| 662 | /* check dummy node children/value accessing */ |
| 663 | if (lysc_data_parent(schema) == node) { |
| 664 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "When condition is accessing its own conditional node children."); |
| 665 | ret = LY_EVALID; |
| 666 | goto cleanup; |
| 667 | } else if ((schema == node) && (tmp_set.val.scnodes[i].in_ctx == LYXP_SET_SCNODE_ATOM_VAL)) { |
| 668 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "When condition is accessing its own conditional node value."); |
| 669 | ret = LY_EVALID; |
| 670 | goto cleanup; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | if (when->context != node) { |
| 675 | /* node actually depends on this "when", not the context node */ |
| 676 | assert(tmp_set.val.scnodes[0].scnode == when->context); |
| 677 | if (tmp_set.val.scnodes[0].in_ctx == LYXP_SET_SCNODE_START_USED) { |
| 678 | /* replace the non-traversed context node with the dependent node */ |
| 679 | tmp_set.val.scnodes[0].scnode = (struct lysc_node *)node; |
| 680 | } else { |
| 681 | /* context node was traversed, so just add the dependent node */ |
| 682 | ret = lyxp_set_scnode_insert_node(&tmp_set, node, LYXP_SET_SCNODE_START_USED, LYXP_AXIS_CHILD, NULL); |
| 683 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 684 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 687 | /* check cyclic dependencies */ |
| 688 | ret = lys_compile_unres_when_cyclic(&tmp_set, node); |
| 689 | LY_CHECK_GOTO(ret, cleanup); |
| 690 | |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 691 | cleanup: |
| 692 | lyxp_set_free_content(&tmp_set); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 693 | return ret; |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * @brief Check must expressions of a node on a complete compiled schema tree. |
| 698 | * |
| 699 | * @param[in] ctx Compile context. |
| 700 | * @param[in] node Node to check. |
| 701 | * @param[in] local_mods Sized array of local modules for musts of @p node at the same index. |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 702 | * @return LY_ERR value. |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 703 | */ |
| 704 | static LY_ERR |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 705 | lys_compile_unres_must(struct lysc_ctx *ctx, const struct lysc_node *node, const struct lysp_module **local_mods) |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 706 | { |
| 707 | struct lyxp_set tmp_set; |
| 708 | uint32_t i, opts; |
| 709 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 710 | struct lysc_must *musts; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 711 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 712 | uint16_t flg; |
| 713 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 714 | LOG_LOCSET(node, NULL); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 715 | |
| 716 | memset(&tmp_set, 0, sizeof tmp_set); |
| 717 | opts = LYXP_SCNODE_SCHEMA | ((node->flags & LYS_IS_OUTPUT) ? LYXP_SCNODE_OUTPUT : 0); |
| 718 | |
| 719 | musts = lysc_node_musts(node); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 720 | LY_ARRAY_FOR(musts, u) { |
Michal Vasko | cfaff23 | 2020-10-20 09:35:14 +0200 | [diff] [blame] | 721 | /* check "must" */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 722 | ret = lyxp_atomize(ctx->ctx, musts[u].cond, node->module, LY_VALUE_SCHEMA_RESOLVED, musts[u].prefixes, node, |
Michal Vasko | a3e92bc | 2022-07-29 14:56:23 +0200 | [diff] [blame] | 723 | node, &tmp_set, opts); |
Michal Vasko | 25d6ad0 | 2020-10-22 12:20:22 +0200 | [diff] [blame] | 724 | if (ret) { |
Michal Vasko | 7c3134d | 2022-07-14 10:57:59 +0200 | [diff] [blame] | 725 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Invalid must condition \"%s\".", musts[u].cond->expr); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 726 | goto cleanup; |
| 727 | } |
| 728 | |
| 729 | ctx->path[0] = '\0'; |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 730 | lysc_path(node, LYSC_PATH_LOG, ctx->path, LYSC_CTX_BUFSIZE); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 731 | for (i = 0; i < tmp_set.used; ++i) { |
| 732 | /* skip roots'n'stuff */ |
| 733 | if (tmp_set.val.scnodes[i].type == LYXP_NODE_ELEM) { |
Michal Vasko | 7c3134d | 2022-07-14 10:57:59 +0200 | [diff] [blame] | 734 | struct lysc_node *schema = tmp_set.val.scnodes[i].scnode; |
| 735 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 736 | /* XPath expression cannot reference "lower" status than the node that has the definition */ |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 737 | if (local_mods[u]->mod == node->module) { |
| 738 | /* use flags of the context node since the definition is local */ |
| 739 | flg = node->flags; |
| 740 | } else { |
| 741 | /* definition is foreign (deviation, refine), always current */ |
| 742 | flg = LYS_STATUS_CURR; |
| 743 | } |
Michal Vasko | 7c3134d | 2022-07-14 10:57:59 +0200 | [diff] [blame] | 744 | if (lysc_check_status(NULL, flg, local_mods[u]->mod, node->name, schema->flags, schema->module, |
| 745 | schema->name)) { |
| 746 | LOGWRN(ctx->ctx, "Must condition \"%s\" may be referencing %s node \"%s\".", musts[u].cond->expr, |
| 747 | (schema->flags == LYS_STATUS_OBSLT) ? "obsolete" : "deprecated", schema->name); |
| 748 | break; |
| 749 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
| 753 | lyxp_set_free_content(&tmp_set); |
| 754 | } |
| 755 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 756 | cleanup: |
| 757 | lyxp_set_free_content(&tmp_set); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 758 | LOG_LOCBACK(1, 0); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 759 | return ret; |
| 760 | } |
| 761 | |
| 762 | /** |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 763 | * @brief Remove all disabled bits/enums from a sized array. |
| 764 | * |
| 765 | * @param[in] ctx Context with the dictionary. |
| 766 | * @param[in] items Sized array of bits/enums. |
| 767 | */ |
| 768 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 769 | lys_compile_unres_disabled_bitenum_remove(struct lysf_ctx *ctx, struct lysc_type_bitenum_item *items) |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 770 | { |
| 771 | LY_ARRAY_COUNT_TYPE u = 0, last_u; |
| 772 | |
| 773 | while (u < LY_ARRAY_COUNT(items)) { |
| 774 | if (items[u].flags & LYS_DISABLED) { |
| 775 | /* free the disabled item */ |
| 776 | lysc_enum_item_free(ctx, &items[u]); |
| 777 | |
| 778 | /* replace it with the following items */ |
| 779 | last_u = LY_ARRAY_COUNT(items) - 1; |
| 780 | if (u < last_u) { |
| 781 | memmove(items + u, items + u + 1, (last_u - u) * sizeof *items); |
| 782 | } |
| 783 | |
| 784 | /* one item less */ |
| 785 | LY_ARRAY_DECREMENT(items); |
| 786 | continue; |
| 787 | } |
| 788 | |
| 789 | ++u; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * @brief Find and remove all disabled bits/enums in a leaf/leaf-list type. |
| 795 | * |
| 796 | * @param[in] ctx Compile context. |
| 797 | * @param[in] leaf Leaf/leaf-list to check. |
| 798 | * @return LY_ERR value |
| 799 | */ |
| 800 | static LY_ERR |
| 801 | lys_compile_unres_disabled_bitenum(struct lysc_ctx *ctx, struct lysc_node_leaf *leaf) |
| 802 | { |
| 803 | struct lysc_type **t; |
| 804 | LY_ARRAY_COUNT_TYPE u, count; |
| 805 | struct lysc_type_enum *ent; |
Michal Vasko | 28864d5 | 2023-03-23 08:07:46 +0100 | [diff] [blame] | 806 | ly_bool has_value = 0; |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 807 | |
| 808 | if (leaf->type->basetype == LY_TYPE_UNION) { |
| 809 | t = ((struct lysc_type_union *)leaf->type)->types; |
| 810 | count = LY_ARRAY_COUNT(t); |
| 811 | } else { |
| 812 | t = &leaf->type; |
| 813 | count = 1; |
| 814 | } |
| 815 | for (u = 0; u < count; ++u) { |
| 816 | if ((t[u]->basetype == LY_TYPE_BITS) || (t[u]->basetype == LY_TYPE_ENUM)) { |
| 817 | /* remove all disabled items */ |
| 818 | ent = (struct lysc_type_enum *)(t[u]); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 819 | lys_compile_unres_disabled_bitenum_remove(&ctx->free_ctx, ent->enums); |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 820 | |
Michal Vasko | 28864d5 | 2023-03-23 08:07:46 +0100 | [diff] [blame] | 821 | if (LY_ARRAY_COUNT(ent->enums)) { |
| 822 | has_value = 1; |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 823 | } |
Michal Vasko | 28864d5 | 2023-03-23 08:07:46 +0100 | [diff] [blame] | 824 | } else { |
| 825 | has_value = 1; |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Michal Vasko | 28864d5 | 2023-03-23 08:07:46 +0100 | [diff] [blame] | 829 | if (!has_value) { |
| 830 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Node \"%s\" without any (or all disabled) valid values.", leaf->name); |
| 831 | return LY_EVALID; |
| 832 | } |
| 833 | |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 834 | return LY_SUCCESS; |
| 835 | } |
| 836 | |
| 837 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 838 | * @brief Check leafref for its target existence on a complete compiled schema tree. |
| 839 | * |
| 840 | * @param[in] ctx Compile context. |
| 841 | * @param[in] node Context node for the leafref. |
| 842 | * @param[in] lref Leafref to check/resolve. |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 843 | * @param[in] local_mod Local module for the leafref type. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 844 | * @return LY_ERR value. |
| 845 | */ |
| 846 | static LY_ERR |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 847 | lys_compile_unres_leafref(struct lysc_ctx *ctx, const struct lysc_node *node, struct lysc_type_leafref *lref, |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 848 | const struct lysp_module *local_mod) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 849 | { |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 850 | const struct lysc_node *target = NULL; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 851 | struct ly_path *p; |
| 852 | struct lysc_type *type; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 853 | uint16_t flg; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 854 | |
| 855 | assert(node->nodetype & (LYS_LEAF | LYS_LEAFLIST)); |
| 856 | |
Michal Vasko | f2a793b | 2023-03-13 11:56:50 +0100 | [diff] [blame] | 857 | if (lref->realtype) { |
| 858 | /* already resolved, may happen (shared union typedef with a leafref) */ |
| 859 | return LY_SUCCESS; |
| 860 | } |
| 861 | |
Michal Vasko | ed725d7 | 2021-06-23 12:03:45 +0200 | [diff] [blame] | 862 | /* try to find the target, current module is that of the context node (RFC 7950 6.4.1 second bullet) */ |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 863 | LY_CHECK_RET(ly_path_compile_leafref(ctx->ctx, node, ctx->ext, lref->path, |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 864 | (node->flags & LYS_IS_OUTPUT) ? LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, |
Michal Vasko | 24fc4d1 | 2021-07-12 14:41:20 +0200 | [diff] [blame] | 865 | LY_VALUE_SCHEMA_RESOLVED, lref->prefixes, &p)); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 866 | |
| 867 | /* get the target node */ |
| 868 | target = p[LY_ARRAY_COUNT(p) - 1].node; |
Michal Vasko | 68b9634 | 2024-09-09 15:24:18 +0200 | [diff] [blame] | 869 | ly_path_free(p); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 870 | |
| 871 | if (!(target->nodetype & (LYS_LEAF | LYS_LEAFLIST))) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 872 | LOGVAL(ctx->ctx, LYVE_REFERENCE, "Invalid leafref path \"%s\" - target node is %s instead of leaf or leaf-list.", |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 873 | lref->path->expr, lys_nodetype2str(target->nodetype)); |
| 874 | return LY_EVALID; |
| 875 | } |
| 876 | |
| 877 | /* check status */ |
| 878 | ctx->path[0] = '\0'; |
| 879 | lysc_path(node, LYSC_PATH_LOG, ctx->path, LYSC_CTX_BUFSIZE); |
| 880 | ctx->path_len = strlen(ctx->path); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 881 | if (node->module == local_mod->mod) { |
| 882 | /* use flags of the context node since the definition is local */ |
| 883 | flg = node->flags; |
| 884 | } else { |
| 885 | /* definition is foreign (deviation), always current */ |
| 886 | flg = LYS_STATUS_CURR; |
| 887 | } |
| 888 | if (lysc_check_status(ctx, flg, local_mod->mod, node->name, target->flags, target->module, target->name)) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 889 | return LY_EVALID; |
| 890 | } |
| 891 | ctx->path_len = 1; |
| 892 | ctx->path[1] = '\0'; |
| 893 | |
| 894 | /* check config */ |
| 895 | if (lref->require_instance) { |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 896 | if ((node->flags & LYS_CONFIG_W) && (target->flags & LYS_CONFIG_R)) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 897 | LOGVAL(ctx->ctx, LYVE_REFERENCE, "Invalid leafref path \"%s\" - target is supposed" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 898 | " to represent configuration data (as the leafref does), but it does not.", lref->path->expr); |
| 899 | return LY_EVALID; |
| 900 | } |
| 901 | } |
| 902 | |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 903 | /* check for circular chain of leafrefs */ |
| 904 | for (type = ((struct lysc_node_leaf *)target)->type; |
| 905 | type && (type->basetype == LY_TYPE_LEAFREF); |
| 906 | type = ((struct lysc_type_leafref *)type)->realtype) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 907 | if (type == (struct lysc_type *)lref) { |
| 908 | /* circular chain detected */ |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 909 | LOGVAL(ctx->ctx, LYVE_REFERENCE, "Invalid leafref path \"%s\" - circular chain of leafrefs detected.", |
| 910 | lref->path->expr); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 911 | return LY_EVALID; |
| 912 | } |
| 913 | } |
| 914 | |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 915 | /* store the type */ |
| 916 | lref->realtype = ((struct lysc_node_leaf *)target)->type; |
| 917 | ++lref->realtype->refcount; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 918 | return LY_SUCCESS; |
| 919 | } |
| 920 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 921 | /** |
| 922 | * @brief Compile default value(s) for leaf or leaf-list expecting a complete compiled schema tree. |
| 923 | * |
| 924 | * @param[in] ctx Compile context. |
| 925 | * @param[in] node Leaf or leaf-list to compile the default value(s) for. |
| 926 | * @param[in] type Type of the default value. |
| 927 | * @param[in] dflt Default value. |
| 928 | * @param[in] dflt_pmod Parsed module of the @p dflt to resolve possible prefixes. |
| 929 | * @param[in,out] storage Storage for the compiled default value. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 930 | * @param[in,out] unres Global unres structure for newly implemented modules. |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 931 | * @return LY_ERECOMPILE if the whole dep set needs to be recompiled for the value to be checked. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 932 | * @return LY_ERR value. |
| 933 | */ |
| 934 | static LY_ERR |
| 935 | lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc_type *type, const char *dflt, |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 936 | const struct lysp_module *dflt_pmod, struct lyd_value *storage, struct lys_glob_unres *unres) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 937 | { |
| 938 | LY_ERR ret; |
Michal Vasko | 25d6ad0 | 2020-10-22 12:20:22 +0200 | [diff] [blame] | 939 | uint32_t options; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 940 | struct ly_err_item *err = NULL; |
| 941 | |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 942 | options = (ctx->ctx->flags & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0; |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 943 | ret = type->plugin->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod, |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 944 | LYD_HINT_SCHEMA, node, storage, unres, &err); |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 945 | if (ret == LY_ERECOMPILE) { |
| 946 | /* fine, but we need to recompile */ |
| 947 | return LY_ERECOMPILE; |
| 948 | } else if (ret == LY_EINCOMPLETE) { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 949 | /* we have no data so we will not be resolving it */ |
| 950 | ret = LY_SUCCESS; |
| 951 | } |
| 952 | |
| 953 | if (ret) { |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 954 | LOG_LOCSET(node, NULL); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 955 | if (err) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 956 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Invalid default - value does not fit the type (%s).", err->msg); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 957 | ly_err_free(err); |
| 958 | } else { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 959 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Invalid default - value does not fit the type."); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 960 | } |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 961 | LOG_LOCBACK(1, 0); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 962 | return ret; |
| 963 | } |
| 964 | |
Michal Vasko | 04338d9 | 2021-09-01 07:58:14 +0200 | [diff] [blame] | 965 | LY_ATOMIC_INC_BARRIER(((struct lysc_type *)storage->realtype)->refcount); |
Michal Vasko | 311fe05 | 2024-09-09 15:24:51 +0200 | [diff] [blame] | 966 | if (storage->realtype->basetype == LY_TYPE_INST) { |
| 967 | /* ly_path includes references to other nodes, in case they are in foreign modules, the context would |
| 968 | * need to be freed in specific order to avoid accessing freed memory, so just avoid storing it */ |
| 969 | ly_path_free(storage->target); |
| 970 | storage->target = NULL; |
| 971 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 972 | return LY_SUCCESS; |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * @brief Compile default value of a leaf expecting a complete compiled schema tree. |
| 977 | * |
| 978 | * @param[in] ctx Compile context. |
| 979 | * @param[in] leaf Leaf that the default value is for. |
| 980 | * @param[in] dflt Default value to compile. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 981 | * @param[in,out] unres Global unres structure for newly implemented modules. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 982 | * @return LY_ERR value. |
| 983 | */ |
| 984 | static LY_ERR |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 985 | lys_compile_unres_leaf_dlft(struct lysc_ctx *ctx, struct lysc_node_leaf *leaf, struct lysp_qname *dflt, |
| 986 | struct lys_glob_unres *unres) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 987 | { |
| 988 | LY_ERR ret; |
| 989 | |
| 990 | assert(!leaf->dflt); |
| 991 | |
| 992 | if (leaf->flags & (LYS_MAND_TRUE | LYS_KEY)) { |
| 993 | /* ignore default values for keys and mandatory leaves */ |
| 994 | return LY_SUCCESS; |
| 995 | } |
| 996 | |
| 997 | /* allocate the default value */ |
| 998 | leaf->dflt = calloc(1, sizeof *leaf->dflt); |
| 999 | LY_CHECK_ERR_RET(!leaf->dflt, LOGMEM(ctx->ctx), LY_EMEM); |
| 1000 | |
| 1001 | /* store the default value */ |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 1002 | ret = lys_compile_unres_dflt(ctx, &leaf->node, leaf->type, dflt->str, dflt->mod, leaf->dflt, unres); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1003 | if (ret) { |
| 1004 | free(leaf->dflt); |
| 1005 | leaf->dflt = NULL; |
| 1006 | } |
| 1007 | |
| 1008 | return ret; |
| 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * @brief Compile default values of a leaf-list expecting a complete compiled schema tree. |
| 1013 | * |
| 1014 | * @param[in] ctx Compile context. |
| 1015 | * @param[in] llist Leaf-list that the default value(s) are for. |
| 1016 | * @param[in] dflt Default value to compile, in case of a single value. |
| 1017 | * @param[in] dflts Sized array of default values, in case of more values. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1018 | * @param[in,out] unres Global unres structure for newly implemented modules. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1019 | * @return LY_ERR value. |
| 1020 | */ |
| 1021 | static LY_ERR |
| 1022 | lys_compile_unres_llist_dflts(struct lysc_ctx *ctx, struct lysc_node_leaflist *llist, struct lysp_qname *dflt, |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1023 | struct lysp_qname *dflts, struct lys_glob_unres *unres) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1024 | { |
| 1025 | LY_ERR ret; |
| 1026 | LY_ARRAY_COUNT_TYPE orig_count, u, v; |
| 1027 | |
| 1028 | assert(dflt || dflts); |
| 1029 | |
Radek Krejci | c7d13e3 | 2020-12-09 12:32:24 +0100 | [diff] [blame] | 1030 | /* in case there were already some defaults and we are adding new by deviations */ |
| 1031 | orig_count = LY_ARRAY_COUNT(llist->dflts); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1032 | |
| 1033 | /* allocate new items */ |
Radek Krejci | c7d13e3 | 2020-12-09 12:32:24 +0100 | [diff] [blame] | 1034 | LY_ARRAY_CREATE_RET(ctx->ctx, llist->dflts, orig_count + (dflts ? LY_ARRAY_COUNT(dflts) : 1), LY_EMEM); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1035 | |
| 1036 | /* fill each new default value */ |
| 1037 | if (dflts) { |
| 1038 | LY_ARRAY_FOR(dflts, u) { |
| 1039 | llist->dflts[orig_count + u] = calloc(1, sizeof **llist->dflts); |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 1040 | ret = lys_compile_unres_dflt(ctx, &llist->node, llist->type, dflts[u].str, dflts[u].mod, |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1041 | llist->dflts[orig_count + u], unres); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1042 | LY_CHECK_ERR_RET(ret, free(llist->dflts[orig_count + u]), ret); |
| 1043 | LY_ARRAY_INCREMENT(llist->dflts); |
| 1044 | } |
| 1045 | } else { |
| 1046 | llist->dflts[orig_count] = calloc(1, sizeof **llist->dflts); |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 1047 | ret = lys_compile_unres_dflt(ctx, &llist->node, llist->type, dflt->str, dflt->mod, |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1048 | llist->dflts[orig_count], unres); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1049 | LY_CHECK_ERR_RET(ret, free(llist->dflts[orig_count]), ret); |
| 1050 | LY_ARRAY_INCREMENT(llist->dflts); |
| 1051 | } |
| 1052 | |
| 1053 | /* check default value uniqueness */ |
| 1054 | if (llist->flags & LYS_CONFIG_W) { |
| 1055 | /* configuration data values must be unique - so check the default values */ |
| 1056 | for (u = orig_count; u < LY_ARRAY_COUNT(llist->dflts); ++u) { |
| 1057 | for (v = 0; v < u; ++v) { |
aPiecek | 0a6705b | 2023-11-14 14:20:58 +0100 | [diff] [blame] | 1058 | if (!llist->dflts[u]->realtype->plugin->compare(ctx->ctx, llist->dflts[u], llist->dflts[v])) { |
Radek Krejci | a601699 | 2021-03-03 10:13:41 +0100 | [diff] [blame] | 1059 | lysc_update_path(ctx, llist->parent ? llist->parent->module : NULL, llist->name); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1060 | LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Configuration leaf-list has multiple defaults of the same value \"%s\".", |
Michal Vasko | 7b3a00e | 2023-08-09 11:58:03 +0200 | [diff] [blame] | 1061 | (char *)llist->dflts[u]->realtype->plugin->print(ctx->ctx, llist->dflts[u], LY_VALUE_CANON, |
| 1062 | NULL, NULL, NULL)); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1063 | lysc_update_path(ctx, NULL, NULL); |
| 1064 | return LY_EVALID; |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | return LY_SUCCESS; |
| 1071 | } |
| 1072 | |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1073 | /** |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1074 | * @brief Iteratively get all leafrefs from @p node |
| 1075 | * if the node is of type union, otherwise just return the leafref. |
| 1076 | * |
| 1077 | * @param[in] node Node that may contain the leafref. |
| 1078 | * @param[in,out] index Value that is passed between function calls. |
| 1079 | * For each new node, initialize value of the @p index to 0, otherwise |
| 1080 | * do not modify the value between calls. |
| 1081 | * @return Pointer to the leafref or next leafref, otherwise NULL. |
| 1082 | */ |
| 1083 | static struct lysc_type_leafref * |
Michal Vasko | 350e8dd | 2024-04-16 09:27:19 +0200 | [diff] [blame] | 1084 | lys_type_leafref_next(const struct lysc_node *node, LY_ARRAY_COUNT_TYPE *index) |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1085 | { |
| 1086 | struct lysc_type_leafref *ret = NULL; |
| 1087 | struct lysc_type_union *uni; |
| 1088 | struct lysc_type *leaf_type; |
| 1089 | |
| 1090 | assert(node->nodetype & LYD_NODE_TERM); |
| 1091 | |
| 1092 | leaf_type = ((struct lysc_node_leaf *)node)->type; |
| 1093 | if (leaf_type->basetype == LY_TYPE_UNION) { |
| 1094 | uni = (struct lysc_type_union *)leaf_type; |
| 1095 | |
| 1096 | /* find next union leafref */ |
| 1097 | while (*index < LY_ARRAY_COUNT(uni->types)) { |
| 1098 | if (uni->types[*index]->basetype == LY_TYPE_LEAFREF) { |
| 1099 | ret = (struct lysc_type_leafref *)uni->types[*index]; |
| 1100 | ++(*index); |
| 1101 | break; |
| 1102 | } |
| 1103 | |
| 1104 | ++(*index); |
| 1105 | } |
| 1106 | } else { |
| 1107 | /* return just the single leafref */ |
| 1108 | if (*index == 0) { |
| 1109 | ++(*index); |
| 1110 | assert(leaf_type->basetype == LY_TYPE_LEAFREF); |
| 1111 | ret = (struct lysc_type_leafref *)leaf_type; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | return ret; |
| 1116 | } |
| 1117 | |
| 1118 | /** |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1119 | * @brief Implement all referenced modules by leafrefs, when and must conditions. |
| 1120 | * |
| 1121 | * @param[in] ctx libyang context. |
| 1122 | * @param[in] unres Global unres structure with the sets to resolve. |
| 1123 | * @return LY_SUCCESS on success. |
| 1124 | * @return LY_ERECOMPILE if the whole dep set needs to be recompiled with the new implemented modules. |
| 1125 | * @return LY_ERR value on error. |
| 1126 | */ |
| 1127 | static LY_ERR |
| 1128 | lys_compile_unres_depset_implement(struct ly_ctx *ctx, struct lys_glob_unres *unres) |
| 1129 | { |
| 1130 | struct lys_depset_unres *ds_unres = &unres->ds_unres; |
| 1131 | struct lysc_type_leafref *lref; |
| 1132 | const struct lys_module *mod; |
| 1133 | LY_ARRAY_COUNT_TYPE u; |
| 1134 | struct lysc_unres_leafref *l; |
| 1135 | struct lysc_unres_when *w; |
| 1136 | struct lysc_unres_must *m; |
| 1137 | struct lysc_must *musts; |
| 1138 | ly_bool not_implemented; |
| 1139 | uint32_t di = 0, li = 0, wi = 0, mi = 0; |
| 1140 | |
| 1141 | implement_all: |
| 1142 | /* disabled leafrefs - even those because we need to check their target exists */ |
| 1143 | while (di < ds_unres->disabled_leafrefs.count) { |
| 1144 | l = ds_unres->disabled_leafrefs.objs[di]; |
| 1145 | |
| 1146 | u = 0; |
| 1147 | while ((lref = lys_type_leafref_next(l->node, &u))) { |
| 1148 | LY_CHECK_RET(lys_compile_expr_implement(ctx, lref->path, LY_VALUE_SCHEMA_RESOLVED, lref->prefixes, 1, unres, NULL)); |
| 1149 | } |
| 1150 | |
| 1151 | ++di; |
| 1152 | } |
| 1153 | |
| 1154 | /* leafrefs */ |
| 1155 | while (li < ds_unres->leafrefs.count) { |
| 1156 | l = ds_unres->leafrefs.objs[li]; |
| 1157 | |
| 1158 | u = 0; |
| 1159 | while ((lref = lys_type_leafref_next(l->node, &u))) { |
| 1160 | LY_CHECK_RET(lys_compile_expr_implement(ctx, lref->path, LY_VALUE_SCHEMA_RESOLVED, lref->prefixes, 1, unres, NULL)); |
| 1161 | } |
| 1162 | |
| 1163 | ++li; |
| 1164 | } |
| 1165 | |
| 1166 | /* when conditions */ |
| 1167 | while (wi < ds_unres->whens.count) { |
| 1168 | w = ds_unres->whens.objs[wi]; |
| 1169 | |
| 1170 | LY_CHECK_RET(lys_compile_expr_implement(ctx, w->when->cond, LY_VALUE_SCHEMA_RESOLVED, w->when->prefixes, |
| 1171 | ctx->flags & LY_CTX_REF_IMPLEMENTED, unres, &mod)); |
| 1172 | if (mod) { |
| 1173 | LOGWRN(ctx, "When condition \"%s\" check skipped because referenced module \"%s\" is not implemented.", |
| 1174 | w->when->cond->expr, mod->name); |
| 1175 | |
| 1176 | /* remove from the set to skip the check */ |
| 1177 | ly_set_rm_index(&ds_unres->whens, wi, free); |
| 1178 | continue; |
| 1179 | } |
| 1180 | |
| 1181 | ++wi; |
| 1182 | } |
| 1183 | |
| 1184 | /* must conditions */ |
| 1185 | while (mi < ds_unres->musts.count) { |
| 1186 | m = ds_unres->musts.objs[mi]; |
| 1187 | |
| 1188 | not_implemented = 0; |
| 1189 | musts = lysc_node_musts(m->node); |
| 1190 | LY_ARRAY_FOR(musts, u) { |
| 1191 | LY_CHECK_RET(lys_compile_expr_implement(ctx, musts[u].cond, LY_VALUE_SCHEMA_RESOLVED, musts[u].prefixes, |
| 1192 | ctx->flags & LY_CTX_REF_IMPLEMENTED, unres, &mod)); |
| 1193 | if (mod) { |
| 1194 | LOGWRN(ctx, "Must condition \"%s\" check skipped because referenced module \"%s\" is not implemented.", |
| 1195 | musts[u].cond->expr, mod->name); |
| 1196 | |
| 1197 | /* need to implement modules from all the expressions */ |
| 1198 | not_implemented = 1; |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if (not_implemented) { |
| 1203 | /* remove from the set to skip the check */ |
| 1204 | lysc_unres_must_free(m); |
| 1205 | ly_set_rm_index(&ds_unres->musts, mi, NULL); |
| 1206 | continue; |
| 1207 | } |
| 1208 | |
| 1209 | ++mi; |
| 1210 | } |
| 1211 | |
| 1212 | if ((di < ds_unres->disabled_leafrefs.count) || (li < ds_unres->leafrefs.count) || (wi < ds_unres->whens.count)) { |
| 1213 | /* new items in the sets */ |
| 1214 | goto implement_all; |
| 1215 | } |
| 1216 | |
| 1217 | return LY_SUCCESS; |
| 1218 | } |
| 1219 | |
| 1220 | /** |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1221 | * @brief Check that a disabled node (to be freed) can be freed and is not referenced. |
| 1222 | * |
| 1223 | * @param[in] node Disabled node to check. |
| 1224 | * @return LY_ERR value. |
| 1225 | */ |
| 1226 | static LY_ERR |
| 1227 | lys_compile_unres_check_disabled(const struct lysc_node *node) |
| 1228 | { |
| 1229 | const struct lysc_node *parent; |
Michal Vasko | 99bfd40 | 2024-04-05 10:20:36 +0200 | [diff] [blame] | 1230 | struct lysc_node_list *slist; |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1231 | LY_ARRAY_COUNT_TYPE u, v; |
Michal Vasko | 99bfd40 | 2024-04-05 10:20:36 +0200 | [diff] [blame] | 1232 | int found; |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1233 | |
| 1234 | if (node->flags & LYS_KEY) { |
| 1235 | LOG_LOCSET(node, NULL); |
| 1236 | LOGVAL(node->module->ctx, LYVE_REFERENCE, "Key \"%s\" is disabled.", node->name); |
| 1237 | LOG_LOCBACK(1, 0); |
| 1238 | return LY_EVALID; |
| 1239 | } |
| 1240 | |
| 1241 | for (parent = node->parent; parent; parent = parent->parent) { |
| 1242 | if (parent->nodetype != LYS_LIST) { |
| 1243 | continue; |
| 1244 | } |
| 1245 | |
Michal Vasko | 99bfd40 | 2024-04-05 10:20:36 +0200 | [diff] [blame] | 1246 | /* check and fix list uniques */ |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1247 | slist = (struct lysc_node_list *)parent; |
Michal Vasko | 99bfd40 | 2024-04-05 10:20:36 +0200 | [diff] [blame] | 1248 | found = 0; |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1249 | LY_ARRAY_FOR(slist->uniques, u) { |
| 1250 | LY_ARRAY_FOR(slist->uniques[u], v) { |
| 1251 | if (slist->uniques[u][v] == (struct lysc_node_leaf *)node) { |
Michal Vasko | 99bfd40 | 2024-04-05 10:20:36 +0200 | [diff] [blame] | 1252 | found = 1; |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | if (found) { |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | if (found) { |
| 1263 | if (LY_ARRAY_COUNT(slist->uniques[u]) > 1) { |
| 1264 | /* remove the item */ |
| 1265 | if (v < LY_ARRAY_COUNT(slist->uniques[u]) - 1) { |
| 1266 | memmove(&slist->uniques[u][v], &slist->uniques[u][v + 1], |
| 1267 | (LY_ARRAY_COUNT(slist->uniques[u]) - v - 1) * sizeof slist->uniques[u][v]); |
| 1268 | } |
| 1269 | LY_ARRAY_DECREMENT(slist->uniques[u]); |
| 1270 | } else { |
| 1271 | /* remove the whole unique array */ |
| 1272 | LY_ARRAY_FREE(slist->uniques[u]); |
| 1273 | if (LY_ARRAY_COUNT(slist->uniques) > 1) { |
| 1274 | if (u < LY_ARRAY_COUNT(slist->uniques) - 1) { |
| 1275 | memmove(&slist->uniques[u], &slist->uniques[u + 1], |
| 1276 | (LY_ARRAY_COUNT(slist->uniques) - u - 1) * sizeof slist->uniques[u]); |
| 1277 | } |
| 1278 | LY_ARRAY_DECREMENT(slist->uniques); |
| 1279 | } else { |
| 1280 | LY_ARRAY_FREE(slist->uniques); |
| 1281 | slist->uniques = NULL; |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | return LY_SUCCESS; |
| 1288 | } |
| 1289 | |
| 1290 | /** |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1291 | * @brief Finish dependency set compilation by resolving all the unres sets. |
| 1292 | * |
| 1293 | * @param[in] ctx libyang context. |
| 1294 | * @param[in] unres Global unres structure with the sets to resolve. |
| 1295 | * @return LY_SUCCESS on success. |
| 1296 | * @return LY_ERECOMPILE if the dep set needs to be recompiled. |
| 1297 | * @return LY_ERR value on error. |
| 1298 | */ |
| 1299 | static LY_ERR |
| 1300 | lys_compile_unres_depset(struct ly_ctx *ctx, struct lys_glob_unres *unres) |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1301 | { |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1302 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1303 | struct lysc_node *node; |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1304 | struct lysc_type *typeiter; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1305 | struct lysc_type_leafref *lref; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1306 | struct lysc_ctx cctx = {0}; |
| 1307 | struct lys_depset_unres *ds_unres = &unres->ds_unres; |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1308 | struct ly_path *path; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1309 | LY_ARRAY_COUNT_TYPE v; |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1310 | struct lysc_unres_leafref *l; |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 1311 | struct lysc_unres_when *w; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1312 | struct lysc_unres_must *m; |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1313 | struct lysc_unres_dflt *d; |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1314 | uint32_t i, processed_leafrefs = 0; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1315 | |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1316 | resolve_all: |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1317 | /* implement all referenced modules to get final ds_unres set */ |
| 1318 | if ((ret = lys_compile_unres_depset_implement(ctx, unres))) { |
| 1319 | goto cleanup; |
| 1320 | } |
| 1321 | |
| 1322 | /* check disabled leafrefs */ |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 1323 | while (ds_unres->disabled_leafrefs.count) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1324 | /* remember index, it can change before we get to free this item */ |
| 1325 | i = ds_unres->disabled_leafrefs.count - 1; |
| 1326 | l = ds_unres->disabled_leafrefs.objs[i]; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1327 | LYSC_CTX_INIT_PMOD(cctx, l->node->module->parsed, l->ext); |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 1328 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1329 | LOG_LOCSET(l->node, NULL); |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 1330 | v = 0; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1331 | while ((ret == LY_SUCCESS) && (lref = lys_type_leafref_next(l->node, &v))) { |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1332 | ret = lys_compile_unres_leafref(&cctx, l->node, lref, l->local_mod); |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 1333 | } |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1334 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1335 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1336 | |
| 1337 | ly_set_rm_index(&ds_unres->disabled_leafrefs, i, free); |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 1338 | } |
Michal Vasko | a23e1d9 | 2021-07-13 12:04:16 +0200 | [diff] [blame] | 1339 | |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 1340 | /* for leafref, we need 2 rounds - first detects circular chain by storing the first referred type (which |
| 1341 | * can be also leafref, in case it is already resolved, go through the chain and check that it does not |
| 1342 | * point to the starting leafref type). The second round stores the first non-leafref type for later data validation. |
| 1343 | * Also do the same check for set of the disabled leafrefs, but without the second round. */ |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1344 | for (i = processed_leafrefs; i < ds_unres->leafrefs.count; ++i) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1345 | l = ds_unres->leafrefs.objs[i]; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1346 | LYSC_CTX_INIT_PMOD(cctx, l->node->module->parsed, l->ext); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1347 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1348 | LOG_LOCSET(l->node, NULL); |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1349 | v = 0; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1350 | while ((ret == LY_SUCCESS) && (lref = lys_type_leafref_next(l->node, &v))) { |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1351 | ret = lys_compile_unres_leafref(&cctx, l->node, lref, l->local_mod); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1352 | } |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1353 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1354 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1355 | } |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1356 | for (i = processed_leafrefs; i < ds_unres->leafrefs.count; ++i) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1357 | l = ds_unres->leafrefs.objs[i]; |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1358 | |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1359 | /* store pointer to the real type */ |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1360 | v = 0; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1361 | while ((lref = lys_type_leafref_next(l->node, &v))) { |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1362 | for (typeiter = lref->realtype; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1363 | typeiter->basetype == LY_TYPE_LEAFREF; |
| 1364 | typeiter = ((struct lysc_type_leafref *)typeiter)->realtype) {} |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 1365 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1366 | lysc_type_free(&cctx.free_ctx, lref->realtype); |
aPiecek | 732cd14 | 2021-07-07 16:29:59 +0200 | [diff] [blame] | 1367 | lref->realtype = typeiter; |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 1368 | ++lref->realtype->refcount; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1371 | /* if 'goto' will be used on the 'resolve_all' label, then the current leafref will not be processed again */ |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1372 | processed_leafrefs++; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1375 | /* check when, the referenced modules must be implemented now */ |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1376 | while (ds_unres->whens.count) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1377 | i = ds_unres->whens.count - 1; |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 1378 | w = ds_unres->whens.objs[i]; |
| 1379 | LYSC_CTX_INIT_PMOD(cctx, w->node->module->parsed, NULL); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1380 | |
Michal Vasko | e6943a0 | 2024-02-27 09:04:07 +0100 | [diff] [blame] | 1381 | LOG_LOCSET(w->node, NULL); |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1382 | ret = lys_compile_unres_when(&cctx, w->when, w->node); |
Michal Vasko | e6943a0 | 2024-02-27 09:04:07 +0100 | [diff] [blame] | 1383 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1384 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1385 | |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 1386 | free(w); |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1387 | ly_set_rm_index(&ds_unres->whens, i, NULL); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /* check must */ |
| 1391 | while (ds_unres->musts.count) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1392 | i = ds_unres->musts.count - 1; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1393 | m = ds_unres->musts.objs[i]; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1394 | LYSC_CTX_INIT_PMOD(cctx, m->node->module->parsed, m->ext); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1395 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1396 | LOG_LOCSET(m->node, NULL); |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1397 | ret = lys_compile_unres_must(&cctx, m->node, m->local_mods); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1398 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1399 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1400 | |
| 1401 | lysc_unres_must_free(m); |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1402 | ly_set_rm_index(&ds_unres->musts, i, NULL); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1403 | } |
| 1404 | |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 1405 | /* remove disabled enums/bits */ |
Michal Vasko | 5eaf732 | 2021-11-22 15:58:26 +0100 | [diff] [blame] | 1406 | while (ds_unres->disabled_bitenums.count) { |
| 1407 | i = ds_unres->disabled_bitenums.count - 1; |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 1408 | node = ds_unres->disabled_bitenums.objs[i]; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1409 | LYSC_CTX_INIT_PMOD(cctx, node->module->parsed, NULL); |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 1410 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1411 | LOG_LOCSET(node, NULL); |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 1412 | ret = lys_compile_unres_disabled_bitenum(&cctx, (struct lysc_node_leaf *)node); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1413 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1414 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 1415 | |
| 1416 | ly_set_rm_index(&ds_unres->disabled_bitenums, i, NULL); |
| 1417 | } |
| 1418 | |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1419 | /* finish incomplete default values compilation */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1420 | while (ds_unres->dflts.count) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1421 | i = ds_unres->dflts.count - 1; |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1422 | d = ds_unres->dflts.objs[i]; |
| 1423 | LYSC_CTX_INIT_PMOD(cctx, d->leaf->module->parsed, NULL); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1424 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1425 | LOG_LOCSET(&d->leaf->node, NULL); |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1426 | if (d->leaf->nodetype == LYS_LEAF) { |
| 1427 | ret = lys_compile_unres_leaf_dlft(&cctx, d->leaf, d->dflt, unres); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1428 | } else { |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1429 | ret = lys_compile_unres_llist_dflts(&cctx, d->llist, d->dflt, d->dflts, unres); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1430 | } |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1431 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1432 | LY_CHECK_GOTO(ret, cleanup); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1433 | |
Michal Vasko | e20599c | 2022-12-02 10:45:01 +0100 | [diff] [blame] | 1434 | lysc_unres_dflt_free(ctx, d); |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1435 | ly_set_rm_index(&ds_unres->dflts, i, NULL); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1436 | } |
| 1437 | |
Michal Vasko | aa54894 | 2023-06-08 12:23:14 +0200 | [diff] [blame] | 1438 | /* some unres items may have been added by the default values */ |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 1439 | if ((processed_leafrefs != ds_unres->leafrefs.count) || ds_unres->disabled_leafrefs.count || |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1440 | ds_unres->whens.count || ds_unres->musts.count || ds_unres->dflts.count) { |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1441 | goto resolve_all; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
Michal Vasko | 30ab8e7 | 2021-04-19 12:47:52 +0200 | [diff] [blame] | 1444 | /* finally, remove all disabled nodes */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1445 | for (i = 0; i < ds_unres->disabled.count; ++i) { |
| 1446 | node = ds_unres->disabled.snodes[i]; |
Michal Vasko | 93b9b24 | 2024-03-19 09:14:30 +0100 | [diff] [blame] | 1447 | ret = lys_compile_unres_check_disabled(node); |
| 1448 | LY_CHECK_GOTO(ret, cleanup); |
| 1449 | |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1450 | LYSC_CTX_INIT_PMOD(cctx, node->module->parsed, NULL); |
Michal Vasko | 30ab8e7 | 2021-04-19 12:47:52 +0200 | [diff] [blame] | 1451 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1452 | lysc_node_free(&cctx.free_ctx, node, 1); |
Michal Vasko | 30ab8e7 | 2021-04-19 12:47:52 +0200 | [diff] [blame] | 1453 | } |
| 1454 | |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1455 | /* also check if the leafref target has not been disabled */ |
| 1456 | for (i = 0; i < ds_unres->leafrefs.count; ++i) { |
Michal Vasko | a91d87e | 2021-10-19 11:58:57 +0200 | [diff] [blame] | 1457 | l = ds_unres->leafrefs.objs[i]; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1458 | LYSC_CTX_INIT_PMOD(cctx, l->node->module->parsed, l->ext); |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1459 | |
| 1460 | v = 0; |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1461 | while ((lref = lys_type_leafref_next(l->node, &v))) { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1462 | ret = ly_path_compile_leafref(cctx.ctx, l->node, cctx.ext, lref->path, |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1463 | (l->node->flags & LYS_IS_OUTPUT) ? LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1464 | LY_VALUE_SCHEMA_RESOLVED, lref->prefixes, &path); |
Michal Vasko | 68b9634 | 2024-09-09 15:24:18 +0200 | [diff] [blame] | 1465 | ly_path_free(path); |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1466 | |
| 1467 | assert(ret != LY_ERECOMPILE); |
| 1468 | if (ret) { |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1469 | LOG_LOCSET(l->node, NULL); |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1470 | LOGVAL(ctx, LYVE_REFERENCE, "Target of leafref \"%s\" cannot be referenced because it is disabled.", |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1471 | l->node->name); |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1472 | LOG_LOCBACK(1, 0); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1473 | ret = LY_EVALID; |
| 1474 | goto cleanup; |
aPiecek | d7bd52d | 2021-07-08 08:59:59 +0200 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1479 | cleanup: |
Michal Vasko | 0c9a1d3 | 2024-09-11 13:53:39 +0200 | [diff] [blame] | 1480 | assert(!cctx.free_ctx.ext_set.count); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1481 | return ret; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1484 | /** |
| 1485 | * @brief Erase dep set unres. |
| 1486 | * |
| 1487 | * @param[in] ctx libyang context. |
| 1488 | * @param[in] unres Global unres structure with the sets to resolve. |
| 1489 | */ |
| 1490 | static void |
| 1491 | lys_compile_unres_depset_erase(const struct ly_ctx *ctx, struct lys_glob_unres *unres) |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1492 | { |
| 1493 | uint32_t i; |
| 1494 | |
Michal Vasko | 4ed3bd5 | 2022-12-02 10:28:04 +0100 | [diff] [blame] | 1495 | ly_set_erase(&unres->ds_unres.whens, free); |
Michal Vasko | c130e16 | 2021-10-19 11:30:00 +0200 | [diff] [blame] | 1496 | for (i = 0; i < unres->ds_unres.musts.count; ++i) { |
| 1497 | lysc_unres_must_free(unres->ds_unres.musts.objs[i]); |
| 1498 | } |
| 1499 | ly_set_erase(&unres->ds_unres.musts, NULL); |
| 1500 | ly_set_erase(&unres->ds_unres.leafrefs, free); |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1501 | for (i = 0; i < unres->ds_unres.dflts.count; ++i) { |
| 1502 | lysc_unres_dflt_free(ctx, unres->ds_unres.dflts.objs[i]); |
Michal Vasko | df6319c | 2021-06-10 14:41:05 +0200 | [diff] [blame] | 1503 | } |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1504 | ly_set_erase(&unres->ds_unres.dflts, NULL); |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1505 | ly_set_erase(&unres->ds_unres.disabled, NULL); |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 1506 | ly_set_erase(&unres->ds_unres.disabled_leafrefs, free); |
| 1507 | ly_set_erase(&unres->ds_unres.disabled_bitenums, NULL); |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
Michal Vasko | 709f9a5 | 2021-07-21 10:51:59 +0200 | [diff] [blame] | 1510 | /** |
| 1511 | * @brief Compile all flagged modules in a dependency set, recursively if recompilation is needed. |
| 1512 | * |
| 1513 | * @param[in] ctx libyang context. |
| 1514 | * @param[in] dep_set Dependency set to compile. |
| 1515 | * @param[in,out] unres Global unres to use. |
| 1516 | * @return LY_ERR value. |
| 1517 | */ |
| 1518 | static LY_ERR |
| 1519 | lys_compile_depset_r(struct ly_ctx *ctx, struct ly_set *dep_set, struct lys_glob_unres *unres) |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1520 | { |
| 1521 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1522 | struct lysf_ctx fctx = {.ctx = ctx}; |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1523 | struct lys_module *mod; |
| 1524 | uint32_t i; |
| 1525 | |
| 1526 | for (i = 0; i < dep_set->count; ++i) { |
| 1527 | mod = dep_set->objs[i]; |
| 1528 | if (!mod->to_compile) { |
| 1529 | /* skip */ |
| 1530 | continue; |
| 1531 | } |
| 1532 | assert(mod->implemented); |
| 1533 | |
| 1534 | /* free the compiled module, if any */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1535 | lysc_module_free(&fctx, mod->compiled); |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1536 | mod->compiled = NULL; |
| 1537 | |
| 1538 | /* (re)compile the module */ |
| 1539 | LY_CHECK_GOTO(ret = lys_compile(mod, &unres->ds_unres), cleanup); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1540 | } |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1541 | |
| 1542 | /* resolve dep set unres */ |
| 1543 | ret = lys_compile_unres_depset(ctx, unres); |
| 1544 | if (ret == LY_ERECOMPILE) { |
| 1545 | /* new module is implemented, discard current dep set unres and recompile the whole dep set */ |
| 1546 | lys_compile_unres_depset_erase(ctx, unres); |
Michal Vasko | 709f9a5 | 2021-07-21 10:51:59 +0200 | [diff] [blame] | 1547 | return lys_compile_depset_r(ctx, dep_set, unres); |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1548 | } else if (ret) { |
| 1549 | /* error */ |
| 1550 | goto cleanup; |
| 1551 | } |
| 1552 | |
| 1553 | /* success, unset the flags of all the modules in the dep set */ |
| 1554 | for (i = 0; i < dep_set->count; ++i) { |
| 1555 | mod = dep_set->objs[i]; |
| 1556 | mod->to_compile = 0; |
| 1557 | } |
| 1558 | |
| 1559 | cleanup: |
Michal Vasko | 0c9a1d3 | 2024-09-11 13:53:39 +0200 | [diff] [blame] | 1560 | assert(!fctx.ext_set.count); |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1561 | lys_compile_unres_depset_erase(ctx, unres); |
| 1562 | return ret; |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
Michal Vasko | 6a4ef77 | 2022-02-08 15:07:44 +0100 | [diff] [blame] | 1565 | /** |
| 1566 | * @brief Check if-feature of all features of all modules in a dep set. |
| 1567 | * |
| 1568 | * @param[in] dep_set Dep set to check. |
| 1569 | * @return LY_ERR value. |
| 1570 | */ |
| 1571 | static LY_ERR |
| 1572 | lys_compile_depset_check_features(struct ly_set *dep_set) |
| 1573 | { |
| 1574 | struct lys_module *mod; |
| 1575 | uint32_t i; |
| 1576 | |
| 1577 | for (i = 0; i < dep_set->count; ++i) { |
| 1578 | mod = dep_set->objs[i]; |
| 1579 | if (!mod->to_compile) { |
| 1580 | /* skip */ |
| 1581 | continue; |
| 1582 | } |
| 1583 | |
| 1584 | /* check features of this module */ |
| 1585 | LY_CHECK_RET(lys_check_features(mod->parsed)); |
| 1586 | } |
| 1587 | |
| 1588 | return LY_SUCCESS; |
| 1589 | } |
| 1590 | |
Michal Vasko | 709f9a5 | 2021-07-21 10:51:59 +0200 | [diff] [blame] | 1591 | LY_ERR |
| 1592 | lys_compile_depset_all(struct ly_ctx *ctx, struct lys_glob_unres *unres) |
| 1593 | { |
| 1594 | uint32_t i; |
| 1595 | |
| 1596 | for (i = 0; i < unres->dep_sets.count; ++i) { |
Michal Vasko | 6a4ef77 | 2022-02-08 15:07:44 +0100 | [diff] [blame] | 1597 | LY_CHECK_RET(lys_compile_depset_check_features(unres->dep_sets.objs[i])); |
Michal Vasko | 709f9a5 | 2021-07-21 10:51:59 +0200 | [diff] [blame] | 1598 | LY_CHECK_RET(lys_compile_depset_r(ctx, unres->dep_sets.objs[i], unres)); |
| 1599 | } |
| 1600 | |
| 1601 | return LY_SUCCESS; |
| 1602 | } |
| 1603 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1604 | /** |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1605 | * @brief Finish compilation of all the module unres sets in a compile context. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1606 | * |
| 1607 | * @param[in] ctx Compile context with unres sets. |
| 1608 | * @return LY_ERR value. |
| 1609 | */ |
| 1610 | static LY_ERR |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1611 | lys_compile_unres_mod(struct lysc_ctx *ctx) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1612 | { |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1613 | struct lysc_augment *aug; |
| 1614 | struct lysc_deviation *dev; |
Michal Vasko | 1ade6f1 | 2021-04-19 11:32:45 +0200 | [diff] [blame] | 1615 | struct lys_module *orig_mod = ctx->cur_mod; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1616 | uint32_t i; |
| 1617 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1618 | /* check that all augments were applied */ |
| 1619 | for (i = 0; i < ctx->augs.count; ++i) { |
| 1620 | aug = ctx->augs.objs[i]; |
Michal Vasko | 1ade6f1 | 2021-04-19 11:32:45 +0200 | [diff] [blame] | 1621 | ctx->cur_mod = aug->aug_pmod->mod; |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 1622 | if (aug->ext) { |
| 1623 | lysc_update_path(ctx, NULL, "{extension}"); |
| 1624 | lysc_update_path(ctx, NULL, aug->ext->name); |
| 1625 | } |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1626 | lysc_update_path(ctx, NULL, "{augment}"); |
Michal Vasko | 8824a6e | 2024-01-19 12:42:21 +0100 | [diff] [blame] | 1627 | lysc_update_path(ctx, NULL, aug->nodeid->str); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 1628 | LOGVAL(ctx->ctx, LYVE_REFERENCE, "Augment%s target node \"%s\" from module \"%s\" was not found.", |
Michal Vasko | 8824a6e | 2024-01-19 12:42:21 +0100 | [diff] [blame] | 1629 | aug->ext ? " extension" : "", aug->nodeid->str, LYSP_MODULE_NAME(aug->aug_pmod)); |
Michal Vasko | 1ade6f1 | 2021-04-19 11:32:45 +0200 | [diff] [blame] | 1630 | ctx->cur_mod = orig_mod; |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1631 | lysc_update_path(ctx, NULL, NULL); |
| 1632 | lysc_update_path(ctx, NULL, NULL); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 1633 | if (aug->ext) { |
| 1634 | lysc_update_path(ctx, NULL, NULL); |
| 1635 | lysc_update_path(ctx, NULL, NULL); |
| 1636 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1637 | } |
| 1638 | if (ctx->augs.count) { |
| 1639 | return LY_ENOTFOUND; |
| 1640 | } |
| 1641 | |
| 1642 | /* check that all deviations were applied */ |
| 1643 | for (i = 0; i < ctx->devs.count; ++i) { |
| 1644 | dev = ctx->devs.objs[i]; |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1645 | lysc_update_path(ctx, NULL, "{deviation}"); |
Michal Vasko | 8824a6e | 2024-01-19 12:42:21 +0100 | [diff] [blame] | 1646 | lysc_update_path(ctx, NULL, dev->nodeid->str); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1647 | LOGVAL(ctx->ctx, LYVE_REFERENCE, "Deviation(s) target node \"%s\" from module \"%s\" was not found.", |
Michal Vasko | 8824a6e | 2024-01-19 12:42:21 +0100 | [diff] [blame] | 1648 | dev->nodeid->str, LYSP_MODULE_NAME(dev->dev_pmods[0])); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1649 | lysc_update_path(ctx, NULL, NULL); |
| 1650 | lysc_update_path(ctx, NULL, NULL); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1651 | } |
| 1652 | if (ctx->devs.count) { |
| 1653 | return LY_ENOTFOUND; |
| 1654 | } |
| 1655 | |
| 1656 | return LY_SUCCESS; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /** |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1660 | * @brief Erase all the module unres sets in a compile context. |
| 1661 | * |
| 1662 | * @param[in] ctx Compile context with unres sets. |
| 1663 | * @param[in] error Whether the compilation finished with an error or not. |
| 1664 | */ |
| 1665 | static void |
| 1666 | lys_compile_unres_mod_erase(struct lysc_ctx *ctx, ly_bool error) |
| 1667 | { |
| 1668 | uint32_t i; |
| 1669 | |
| 1670 | ly_set_erase(&ctx->groupings, NULL); |
| 1671 | ly_set_erase(&ctx->tpdf_chain, NULL); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1672 | |
| 1673 | if (!error) { |
| 1674 | /* there can be no leftover deviations or augments */ |
| 1675 | LY_CHECK_ERR_RET(ctx->augs.count, LOGINT(ctx->ctx), ); |
| 1676 | LY_CHECK_ERR_RET(ctx->devs.count, LOGINT(ctx->ctx), ); |
| 1677 | |
| 1678 | ly_set_erase(&ctx->augs, NULL); |
| 1679 | ly_set_erase(&ctx->devs, NULL); |
| 1680 | ly_set_erase(&ctx->uses_augs, NULL); |
| 1681 | ly_set_erase(&ctx->uses_rfns, NULL); |
| 1682 | } else { |
| 1683 | for (i = 0; i < ctx->augs.count; ++i) { |
| 1684 | lysc_augment_free(ctx->ctx, ctx->augs.objs[i]); |
| 1685 | } |
| 1686 | ly_set_erase(&ctx->augs, NULL); |
| 1687 | for (i = 0; i < ctx->devs.count; ++i) { |
| 1688 | lysc_deviation_free(ctx->ctx, ctx->devs.objs[i]); |
| 1689 | } |
| 1690 | ly_set_erase(&ctx->devs, NULL); |
| 1691 | for (i = 0; i < ctx->uses_augs.count; ++i) { |
| 1692 | lysc_augment_free(ctx->ctx, ctx->uses_augs.objs[i]); |
| 1693 | } |
| 1694 | ly_set_erase(&ctx->uses_augs, NULL); |
| 1695 | for (i = 0; i < ctx->uses_rfns.count; ++i) { |
| 1696 | lysc_refine_free(ctx->ctx, ctx->uses_rfns.objs[i]); |
| 1697 | } |
| 1698 | ly_set_erase(&ctx->uses_rfns, NULL); |
| 1699 | } |
| 1700 | } |
| 1701 | |
Michal Vasko | 30712a2 | 2024-09-10 15:06:55 +0200 | [diff] [blame^] | 1702 | /** |
| 1703 | * @brief Compile (copy) all enabled features of a parsed module. |
| 1704 | * |
| 1705 | * @param[in] mod Module with the parsed and compiled module. |
| 1706 | * @return LY_ERR value. |
| 1707 | */ |
| 1708 | static LY_ERR |
| 1709 | lys_compile_enabled_features(struct lys_module *mod) |
| 1710 | { |
| 1711 | LY_ERR rc = LY_SUCCESS; |
| 1712 | struct lysp_feature *f = NULL; |
| 1713 | uint32_t idx = 0; |
| 1714 | const char **feat_p; |
| 1715 | |
| 1716 | /* copy enabled features */ |
| 1717 | while ((f = lysp_feature_next(f, mod->parsed, &idx))) { |
| 1718 | if (f->flags & LYS_FENABLED) { |
| 1719 | LY_ARRAY_NEW_GOTO(mod->ctx, mod->compiled->features, feat_p, rc, cleanup); |
| 1720 | LY_CHECK_GOTO(rc = lydict_dup(mod->ctx, f->name, feat_p), cleanup); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | cleanup: |
| 1725 | return rc; |
| 1726 | } |
| 1727 | |
Michal Vasko | d39bea4 | 2021-06-14 10:42:49 +0200 | [diff] [blame] | 1728 | LY_ERR |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1729 | lys_compile(struct lys_module *mod, struct lys_depset_unres *unres) |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1730 | { |
Michal Vasko | 0c9a1d3 | 2024-09-11 13:53:39 +0200 | [diff] [blame] | 1731 | struct lysc_ctx ctx = {0}; |
Michal Vasko | 0b395e1 | 2021-04-23 13:43:07 +0200 | [diff] [blame] | 1732 | struct lysc_module *mod_c = NULL; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1733 | struct lysp_module *sp; |
| 1734 | struct lysp_submodule *submod; |
| 1735 | struct lysp_node *pnode; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1736 | struct lysp_node_grp *grp; |
| 1737 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1738 | LY_ERR ret = LY_SUCCESS; |
| 1739 | |
| 1740 | LY_CHECK_ARG_RET(NULL, mod, mod->parsed, !mod->compiled, mod->ctx, LY_EINVAL); |
| 1741 | |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1742 | assert(mod->implemented && mod->to_compile); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1743 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1744 | sp = mod->parsed; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1745 | LYSC_CTX_INIT_PMOD(ctx, sp, NULL); |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1746 | ctx.unres = unres; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1747 | |
Michal Vasko | 0b395e1 | 2021-04-23 13:43:07 +0200 | [diff] [blame] | 1748 | ++mod->ctx->change_count; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1749 | mod->compiled = mod_c = calloc(1, sizeof *mod_c); |
| 1750 | LY_CHECK_ERR_RET(!mod_c, LOGMEM(mod->ctx), LY_EMEM); |
| 1751 | mod_c->mod = mod; |
| 1752 | |
Michal Vasko | 30712a2 | 2024-09-10 15:06:55 +0200 | [diff] [blame^] | 1753 | /* copy the enabled features */ |
| 1754 | LY_CHECK_GOTO(ret = lys_compile_enabled_features(mod), cleanup); |
| 1755 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1756 | /* compile augments and deviations of our module from other modules so they can be applied during compilation */ |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1757 | LY_CHECK_GOTO(ret = lys_precompile_own_augments(&ctx), cleanup); |
| 1758 | LY_CHECK_GOTO(ret = lys_precompile_own_deviations(&ctx), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1759 | |
| 1760 | /* data nodes */ |
| 1761 | LY_LIST_FOR(sp->data, pnode) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1762 | LY_CHECK_GOTO(ret = lys_compile_node(&ctx, pnode, NULL, 0, NULL), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1763 | } |
| 1764 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1765 | /* top-level RPCs */ |
| 1766 | LY_LIST_FOR((struct lysp_node *)sp->rpcs, pnode) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1767 | LY_CHECK_GOTO(ret = lys_compile_node(&ctx, pnode, NULL, 0, NULL), cleanup); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | /* top-level notifications */ |
| 1771 | LY_LIST_FOR((struct lysp_node *)sp->notifs, pnode) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1772 | LY_CHECK_GOTO(ret = lys_compile_node(&ctx, pnode, NULL, 0, NULL), cleanup); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1773 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1774 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1775 | /* module extension instances */ |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1776 | COMPILE_EXTS_GOTO(&ctx, sp->exts, mod_c->exts, mod_c, ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1777 | |
| 1778 | /* the same for submodules */ |
| 1779 | LY_ARRAY_FOR(sp->includes, u) { |
| 1780 | submod = sp->includes[u].submodule; |
| 1781 | ctx.pmod = (struct lysp_module *)submod; |
| 1782 | |
| 1783 | LY_LIST_FOR(submod->data, pnode) { |
| 1784 | ret = lys_compile_node(&ctx, pnode, NULL, 0, NULL); |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1785 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1786 | } |
| 1787 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1788 | LY_LIST_FOR((struct lysp_node *)submod->rpcs, pnode) { |
| 1789 | ret = lys_compile_node(&ctx, pnode, NULL, 0, NULL); |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1790 | LY_CHECK_GOTO(ret, cleanup); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | LY_LIST_FOR((struct lysp_node *)submod->notifs, pnode) { |
| 1794 | ret = lys_compile_node(&ctx, pnode, NULL, 0, NULL); |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1795 | LY_CHECK_GOTO(ret, cleanup); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1796 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1797 | |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1798 | COMPILE_EXTS_GOTO(&ctx, submod->exts, mod_c->exts, mod_c, ret, cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1799 | } |
Michal Vasko | 12606ee | 2020-11-25 17:05:11 +0100 | [diff] [blame] | 1800 | ctx.pmod = sp; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1801 | |
| 1802 | /* validate non-instantiated groupings from the parsed schema, |
| 1803 | * without it we would accept even the schemas with invalid grouping specification */ |
Michal Vasko | 7c56592 | 2021-06-10 14:58:27 +0200 | [diff] [blame] | 1804 | ctx.compile_opts |= LYS_COMPILE_GROUPING; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1805 | LY_LIST_FOR(sp->groupings, grp) { |
| 1806 | if (!(grp->flags & LYS_USED_GRP)) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1807 | LY_CHECK_GOTO(ret = lys_compile_grouping(&ctx, NULL, grp), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | LY_LIST_FOR(sp->data, pnode) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1811 | LY_LIST_FOR((struct lysp_node_grp *)lysp_node_groupings(pnode), grp) { |
| 1812 | if (!(grp->flags & LYS_USED_GRP)) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1813 | LY_CHECK_GOTO(ret = lys_compile_grouping(&ctx, pnode, grp), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | LY_ARRAY_FOR(sp->includes, u) { |
| 1818 | submod = sp->includes[u].submodule; |
| 1819 | ctx.pmod = (struct lysp_module *)submod; |
| 1820 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1821 | LY_LIST_FOR(submod->groupings, grp) { |
| 1822 | if (!(grp->flags & LYS_USED_GRP)) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1823 | LY_CHECK_GOTO(ret = lys_compile_grouping(&ctx, NULL, grp), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1824 | } |
| 1825 | } |
| 1826 | LY_LIST_FOR(submod->data, pnode) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1827 | LY_LIST_FOR((struct lysp_node_grp *)lysp_node_groupings(pnode), grp) { |
| 1828 | if (!(grp->flags & LYS_USED_GRP)) { |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1829 | LY_CHECK_GOTO(ret = lys_compile_grouping(&ctx, pnode, grp), cleanup); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | } |
| 1834 | ctx.pmod = sp; |
| 1835 | |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1836 | ly_log_location_revert(0, 0, 1, 0); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 1837 | |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 1838 | /* finish compilation for all unresolved module items in the context */ |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1839 | LY_CHECK_GOTO(ret = lys_compile_unres_mod(&ctx), cleanup); |
Michal Vasko | 12606ee | 2020-11-25 17:05:11 +0100 | [diff] [blame] | 1840 | |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1841 | cleanup: |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1842 | ly_log_location_revert(0, 0, 1, 0); |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1843 | lys_compile_unres_mod_erase(&ctx, ret); |
| 1844 | if (ret) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1845 | lysc_module_free(&ctx.free_ctx, mod_c); |
Michal Vasko | 1ccbf54 | 2021-04-19 11:35:00 +0200 | [diff] [blame] | 1846 | mod->compiled = NULL; |
| 1847 | } |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1848 | return ret; |
| 1849 | } |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1850 | |
aPiecek | 6b3d542 | 2021-07-30 15:55:43 +0200 | [diff] [blame] | 1851 | LY_ERR |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1852 | lys_compile_identities(struct lys_module *mod) |
| 1853 | { |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1854 | LY_ERR rc = LY_SUCCESS; |
Michal Vasko | 0c9a1d3 | 2024-09-11 13:53:39 +0200 | [diff] [blame] | 1855 | struct lysc_ctx ctx = {0}; |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1856 | struct lysp_submodule *submod; |
| 1857 | LY_ARRAY_COUNT_TYPE u; |
| 1858 | |
aPiecek | 6b3d542 | 2021-07-30 15:55:43 +0200 | [diff] [blame] | 1859 | /* pre-compile identities of the module and any submodules */ |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1860 | rc = lys_identity_precompile(NULL, mod->ctx, mod->parsed, mod->parsed->identities, &mod->identities); |
| 1861 | LY_CHECK_GOTO(rc, cleanup); |
aPiecek | 6b3d542 | 2021-07-30 15:55:43 +0200 | [diff] [blame] | 1862 | LY_ARRAY_FOR(mod->parsed->includes, u) { |
| 1863 | submod = mod->parsed->includes[u].submodule; |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1864 | rc = lys_identity_precompile(NULL, mod->ctx, (struct lysp_module *)submod, submod->identities, &mod->identities); |
| 1865 | LY_CHECK_GOTO(rc, cleanup); |
aPiecek | 6b3d542 | 2021-07-30 15:55:43 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1868 | /* prepare context */ |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1869 | LYSC_CTX_INIT_PMOD(ctx, mod->parsed, NULL); |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1870 | |
| 1871 | if (mod->parsed->identities) { |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1872 | rc = lys_compile_identities_derived(&ctx, mod->parsed->identities, &mod->identities); |
| 1873 | LY_CHECK_GOTO(rc, cleanup); |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1874 | } |
| 1875 | lysc_update_path(&ctx, NULL, "{submodule}"); |
| 1876 | LY_ARRAY_FOR(mod->parsed->includes, u) { |
| 1877 | submod = mod->parsed->includes[u].submodule; |
| 1878 | if (submod->identities) { |
| 1879 | ctx.pmod = (struct lysp_module *)submod; |
| 1880 | lysc_update_path(&ctx, NULL, submod->name); |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1881 | rc = lys_compile_identities_derived(&ctx, submod->identities, &mod->identities); |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1882 | lysc_update_path(&ctx, NULL, NULL); |
| 1883 | } |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1884 | |
| 1885 | if (rc) { |
| 1886 | break; |
| 1887 | } |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1888 | } |
| 1889 | lysc_update_path(&ctx, NULL, NULL); |
| 1890 | |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1891 | cleanup: |
| 1892 | /* always needed when using lysc_update_path() */ |
Michal Vasko | 7a26677 | 2024-01-23 11:02:38 +0100 | [diff] [blame] | 1893 | ly_log_location_revert(0, 0, 1, 0); |
Michal Vasko | 776ae74 | 2022-08-04 11:08:21 +0200 | [diff] [blame] | 1894 | return rc; |
Michal Vasko | fa5a7d7 | 2021-06-15 11:41:20 +0200 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | /** |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1898 | * @brief Check whether a module does not have any (recursive) compiled import. |
| 1899 | * |
| 1900 | * @param[in] mod Module to examine. |
| 1901 | * @return LY_SUCCESS on success. |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1902 | * @return LY_ERECOMPILE on required recompilation of the dep set. |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1903 | * @return LY_ERR on error. |
| 1904 | */ |
| 1905 | static LY_ERR |
| 1906 | lys_has_compiled_import_r(struct lys_module *mod) |
| 1907 | { |
| 1908 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | e792712 | 2021-06-15 12:00:04 +0200 | [diff] [blame] | 1909 | struct lys_module *m; |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1910 | |
| 1911 | LY_ARRAY_FOR(mod->parsed->imports, u) { |
Michal Vasko | e792712 | 2021-06-15 12:00:04 +0200 | [diff] [blame] | 1912 | m = mod->parsed->imports[u].module; |
| 1913 | if (!m->implemented) { |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1914 | continue; |
| 1915 | } |
| 1916 | |
Michal Vasko | e792712 | 2021-06-15 12:00:04 +0200 | [diff] [blame] | 1917 | if (!m->to_compile) { |
Michal Vasko | d39bea4 | 2021-06-14 10:42:49 +0200 | [diff] [blame] | 1918 | /* module was not/will not be compiled in this compilation (so disabled nodes are not present) */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 1919 | m->to_compile = 1; |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1920 | return LY_ERECOMPILE; |
| 1921 | } |
| 1922 | |
| 1923 | /* recursive */ |
Michal Vasko | e792712 | 2021-06-15 12:00:04 +0200 | [diff] [blame] | 1924 | LY_CHECK_RET(lys_has_compiled_import_r(m)); |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | return LY_SUCCESS; |
| 1928 | } |
| 1929 | |
| 1930 | LY_ERR |
| 1931 | lys_implement(struct lys_module *mod, const char **features, struct lys_glob_unres *unres) |
| 1932 | { |
Michal Vasko | dc668d2 | 2023-02-13 10:23:13 +0100 | [diff] [blame] | 1933 | LY_ERR r; |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1934 | struct lys_module *m; |
| 1935 | |
| 1936 | assert(!mod->implemented); |
| 1937 | |
Michal Vasko | 978532b | 2022-01-21 14:13:40 +0100 | [diff] [blame] | 1938 | /* check collision with other implemented revision */ |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1939 | m = ly_ctx_get_module_implemented(mod->ctx, mod->name); |
| 1940 | if (m) { |
| 1941 | assert(m != mod); |
Michal Vasko | dc668d2 | 2023-02-13 10:23:13 +0100 | [diff] [blame] | 1942 | LOGERR(mod->ctx, LY_EDENIED, "Module \"%s@%s\" is already implemented in revision \"%s\".", |
| 1943 | mod->name, mod->revision ? mod->revision : "<none>", m->revision ? m->revision : "<none>"); |
| 1944 | return LY_EDENIED; |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | /* set features */ |
Michal Vasko | dc668d2 | 2023-02-13 10:23:13 +0100 | [diff] [blame] | 1948 | r = lys_set_features(mod->parsed, features); |
| 1949 | if (r && (r != LY_EEXIST)) { |
| 1950 | return r; |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1951 | } |
| 1952 | |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1953 | /* |
| 1954 | * mark the module implemented, which means |
| 1955 | * 1) to (re)compile it only ::lys_compile() call is needed |
| 1956 | * 2) its compilation will never cause new modules to be implemented (::lys_compile() does not return ::LY_ERECOMPILE) |
| 1957 | * but there can be some unres items added that do |
| 1958 | */ |
| 1959 | mod->implemented = 1; |
| 1960 | |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 1961 | /* this module is compiled in this compilation */ |
| 1962 | mod->to_compile = 1; |
| 1963 | |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1964 | /* add the module into newly implemented module set */ |
| 1965 | LY_CHECK_RET(ly_set_add(&unres->implementing, mod, 1, NULL)); |
| 1966 | |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 1967 | /* mark target modules with our augments and deviations */ |
| 1968 | LY_CHECK_RET(lys_precompile_augments_deviations(mod, unres)); |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1969 | |
Michal Vasko | d39bea4 | 2021-06-14 10:42:49 +0200 | [diff] [blame] | 1970 | /* check whether this module may reference any modules compiled previously */ |
| 1971 | LY_CHECK_RET(lys_has_compiled_import_r(mod)); |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1972 | |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 1973 | return LY_SUCCESS; |
| 1974 | } |