Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file schema_compile.h |
| 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 Header for schema compilation. |
| 6 | * |
Michal Vasko | 19a0902 | 2021-06-15 11:54:08 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2021 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 | #ifndef LY_SCHEMA_COMPILE_H_ |
| 17 | #define LY_SCHEMA_COMPILE_H_ |
| 18 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 19 | #include <stddef.h> |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include "common.h" |
| 23 | #include "dict.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 24 | #include "log.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 25 | #include "set.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 26 | #include "tree.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 27 | #include "tree_edit.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 28 | #include "tree_schema.h" |
| 29 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 30 | struct lyxp_expr; |
| 31 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 32 | /** |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 33 | * @brief YANG schema compilation context. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 34 | */ |
| 35 | struct lysc_ctx { |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 36 | struct ly_ctx *ctx; /**< libyang context */ |
Michal Vasko | b8df576 | 2021-01-12 15:15:53 +0100 | [diff] [blame] | 37 | struct lys_module *cur_mod; /**< module currently being compiled, |
| 38 | - identifier/path - used as the current module for unprefixed nodes |
| 39 | - augment - module where the augment is defined |
| 40 | - deviation - module where the deviation is defined |
| 41 | - uses - module where the uses is defined */ |
| 42 | struct lysp_module *pmod; /**< parsed module being processed, |
| 43 | - identifier/path - used for searching imports to resolve prefixed nodes |
| 44 | - augment - module where the augment is defined |
| 45 | - deviation - module where the deviation is defined |
| 46 | - uses - module where the grouping is defined */ |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 47 | struct lysc_ext_instance *ext; /**< extension instance being processed and serving as a source for its substatements |
| 48 | instead of the module itself */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 49 | struct ly_set groupings; /**< stack for groupings circular check */ |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 50 | struct ly_set tpdf_chain; /**< stack for typedefs circular check */ |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 51 | struct ly_set augs; /**< set of compiled non-applied top-level augments (stored ::lysc_augment *) */ |
| 52 | struct ly_set devs; /**< set of compiled non-applied deviations (stored ::lysc_deviation *) */ |
| 53 | struct ly_set uses_augs; /**< set of compiled non-applied uses augments (stored ::lysc_augment *) */ |
| 54 | struct ly_set uses_rfns; /**< set of compiled non-applied uses refines (stored ::lysc_refine *) */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 55 | struct lys_depset_unres *unres; /**< dependency set unres sets */ |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 56 | uint32_t path_len; /**< number of path bytes used */ |
Michal Vasko | 7c56592 | 2021-06-10 14:58:27 +0200 | [diff] [blame] | 57 | uint32_t compile_opts; /**< various @ref scflags. */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 58 | #define LYSC_CTX_BUFSIZE 4078 |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 59 | char path[LYSC_CTX_BUFSIZE];/**< Path identifying the schema node currently being processed */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /** |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 63 | * @brief Structure for unresolved items that may depend on any implemented module data in the dependency set |
| 64 | * so their resolution can only be performed after the whole dep set compilation is done. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 65 | */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 66 | struct lys_depset_unres { |
aPiecek | c6526b4 | 2021-07-12 15:21:39 +0200 | [diff] [blame] | 67 | struct ly_set xpath; /**< when/must to check */ |
| 68 | struct ly_set leafrefs; /**< to validate target of leafrefs */ |
| 69 | struct ly_set dflts; /**< set of incomplete default values */ |
| 70 | struct ly_set disabled; /**< set of compiled nodes whose if-feature(s) was not satisfied (stored ::lysc_node *) */ |
| 71 | struct ly_set disabled_leafrefs; /**< subset of the lys_depset_unres.disabled to validate target of disabled leafrefs */ |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | /** |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 75 | * @brief Unres structure global for compilation. |
| 76 | */ |
| 77 | struct lys_glob_unres { |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 78 | struct ly_set dep_sets; /**< set of dependency sets of modules, see ::lys_compile_dep_set_r() */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 79 | struct ly_set implementing; /**< set of YANG schemas being atomically implemented (compiled); the first added |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 80 | module is always the explicitly implemented module, the other ones are dependencies */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 81 | struct ly_set creating; /**< set of YANG schemas being atomically created (parsed); it is a subset of implemented |
| 82 | and all these modules are freed if any error occurs */ |
| 83 | struct lys_depset_unres ds_unres; /**< unres specific for the current dependency set */ |
| 84 | }; |
| 85 | |
| 86 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 87 | * @brief Structure for remembering default values of leaves and leaf-lists. They are resolved at schema compilation |
| 88 | * end when the whole schema tree is available. |
| 89 | */ |
| 90 | struct lysc_unres_dflt { |
| 91 | union { |
| 92 | struct lysc_node_leaf *leaf; |
| 93 | struct lysc_node_leaflist *llist; |
| 94 | }; |
| 95 | struct lysp_qname *dflt; |
| 96 | struct lysp_qname *dflts; /**< this is a sized array */ |
| 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * @brief Duplicate string into dictionary |
| 101 | * @param[in] CTX libyang context of the dictionary. |
| 102 | * @param[in] ORIG String to duplicate. |
| 103 | * @param[out] DUP Where to store the result. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 104 | * @param[out] RET Where to store the return code. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 105 | */ |
| 106 | #define DUP_STRING(CTX, ORIG, DUP, RET) if (ORIG) {RET = lydict_insert(CTX, ORIG, 0, &DUP);} |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 107 | #define DUP_STRING_RET(CTX, ORIG, DUP) if (ORIG) {LY_ERR __ret = lydict_insert(CTX, ORIG, 0, &DUP); LY_CHECK_RET(__ret);} |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 108 | #define DUP_STRING_GOTO(CTX, ORIG, DUP, RET, GOTO) if (ORIG) {LY_CHECK_GOTO(RET = lydict_insert(CTX, ORIG, 0, &DUP), GOTO);} |
| 109 | |
| 110 | #define DUP_ARRAY(CTX, ORIG_ARRAY, NEW_ARRAY, DUP_FUNC) \ |
| 111 | if (ORIG_ARRAY) { \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 112 | LY_ARRAY_COUNT_TYPE __u; \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 113 | LY_ARRAY_CREATE_RET(CTX, NEW_ARRAY, LY_ARRAY_COUNT(ORIG_ARRAY), LY_EMEM); \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 114 | LY_ARRAY_FOR(ORIG_ARRAY, __u) { \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 115 | LY_ARRAY_INCREMENT(NEW_ARRAY); \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 116 | LY_CHECK_RET(DUP_FUNC(CTX, &(NEW_ARRAY)[__u], &(ORIG_ARRAY)[__u])); \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 117 | } \ |
| 118 | } |
| 119 | |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 120 | #define COMPILE_OP_ARRAY_GOTO(CTX, ARRAY_P, ARRAY_C, PARENT, FUNC, USES_STATUS, RET, GOTO) \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 121 | if (ARRAY_P) { \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 122 | LY_ARRAY_COUNT_TYPE __u = (ARRAY_C) ? LY_ARRAY_COUNT(ARRAY_C) : 0; \ |
| 123 | LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, __u + LY_ARRAY_COUNT(ARRAY_P), RET, GOTO); \ |
| 124 | LY_ARRAY_FOR(ARRAY_P, __u) { \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 125 | LY_ARRAY_INCREMENT(ARRAY_C); \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 126 | RET = FUNC(CTX, &(ARRAY_P)[__u], PARENT, &(ARRAY_C)[LY_ARRAY_COUNT(ARRAY_C) - 1], USES_STATUS); \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 127 | if (RET == LY_EDENIED) { \ |
| 128 | LY_ARRAY_DECREMENT(ARRAY_C); \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 129 | RET = LY_SUCCESS; \ |
| 130 | } else if (RET) { \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 131 | goto GOTO; \ |
| 132 | } \ |
| 133 | } \ |
| 134 | } |
| 135 | |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 136 | #define COMPILE_ARRAY_GOTO(CTX, ARRAY_P, ARRAY_C, FUNC, RET, GOTO) \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 137 | if (ARRAY_P) { \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 138 | LY_ARRAY_COUNT_TYPE __u = (ARRAY_C) ? LY_ARRAY_COUNT(ARRAY_C) : 0; \ |
| 139 | LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, __u + LY_ARRAY_COUNT(ARRAY_P), RET, GOTO); \ |
| 140 | LY_ARRAY_FOR(ARRAY_P, __u) { \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 141 | LY_ARRAY_INCREMENT(ARRAY_C); \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 142 | RET = FUNC(CTX, &(ARRAY_P)[__u], &(ARRAY_C)[LY_ARRAY_COUNT(ARRAY_C) - 1]); \ |
| 143 | LY_CHECK_GOTO(RET, GOTO); \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 144 | } \ |
| 145 | } |
| 146 | |
Radek Krejci | ab43086 | 2021-03-02 20:13:40 +0100 | [diff] [blame] | 147 | #define COMPILE_EXTS_GOTO(CTX, EXTS_P, EXT_C, PARENT, RET, GOTO) \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 148 | if (EXTS_P) { \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 149 | LY_ARRAY_COUNT_TYPE __u = (EXT_C) ? LY_ARRAY_COUNT(EXT_C) : 0; \ |
| 150 | LY_ARRAY_CREATE_GOTO((CTX)->ctx, EXT_C, __u + LY_ARRAY_COUNT(EXTS_P), RET, GOTO); \ |
| 151 | LY_ARRAY_FOR(EXTS_P, __u) { \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 152 | LY_ARRAY_INCREMENT(EXT_C); \ |
Radek Krejci | ab43086 | 2021-03-02 20:13:40 +0100 | [diff] [blame] | 153 | RET = lys_compile_ext(CTX, &(EXTS_P)[__u], &(EXT_C)[LY_ARRAY_COUNT(EXT_C) - 1], PARENT, NULL); \ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 154 | if (RET == LY_ENOT) { \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 155 | LY_ARRAY_DECREMENT(EXT_C); \ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 156 | RET = LY_SUCCESS; \ |
Michal Vasko | 5347e3a | 2020-11-03 17:14:57 +0100 | [diff] [blame] | 157 | } else if (RET) { \ |
| 158 | goto GOTO; \ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 159 | } \ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 160 | } \ |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @brief Fill in the prepared compiled extension instance structure according to the parsed extension instance. |
| 165 | * |
| 166 | * @param[in] ctx Compilation context. |
| 167 | * @param[in] ext_p Parsed extension instance. |
| 168 | * @param[in,out] ext Prepared compiled extension instance. |
| 169 | * @param[in] parent Extension instance parent. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 170 | * @param[in] ext_mod Optional module with the extension instance extension definition, set only for internal annotations. |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 171 | * @return LY_SUCCESS on success. |
| 172 | * @return LY_ENOT if the extension is disabled and should be ignored. |
| 173 | * @return LY_ERR on error. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 174 | */ |
| 175 | LY_ERR lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *ext_p, struct lysc_ext_instance *ext, void *parent, |
Radek Krejci | ab43086 | 2021-03-02 20:13:40 +0100 | [diff] [blame] | 176 | const struct lys_module *ext_mod); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 177 | |
| 178 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 179 | * @brief Compile information from the identity statement |
| 180 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 181 | * The backlinks to the identities derived from this one are supposed to be filled later via ::lys_compile_identity_bases(). |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 182 | * |
| 183 | * @param[in] ctx_sc Compile context - alternative to the combination of @p ctx and @p parsed_mod. |
| 184 | * @param[in] ctx libyang context. |
| 185 | * @param[in] parsed_mod Module with the identities. |
| 186 | * @param[in] identities_p Array of the parsed identity definitions to precompile. |
| 187 | * @param[in,out] identities Pointer to the storage of the (pre)compiled identities array where the new identities are |
| 188 | * supposed to be added. The storage is supposed to be initiated to NULL when the first parsed identities are going |
| 189 | * to be processed. |
| 190 | * @return LY_ERR value. |
| 191 | */ |
| 192 | LY_ERR lys_identity_precompile(struct lysc_ctx *ctx_sc, struct ly_ctx *ctx, struct lysp_module *parsed_mod, |
| 193 | struct lysp_ident *identities_p, struct lysc_ident **identities); |
| 194 | |
| 195 | /** |
| 196 | * @brief Find and process the referenced base identities from another identity or identityref |
| 197 | * |
| 198 | * For bases in identity set backlinks to them from the base identities. For identityref, store |
| 199 | * the array of pointers to the base identities. So one of the ident or bases parameter must be set |
| 200 | * to distinguish these two use cases. |
| 201 | * |
| 202 | * @param[in] ctx Compile context, not only for logging but also to get the current module to resolve prefixes. |
| 203 | * @param[in] base_pmod Module where to resolve @p bases_p prefixes. |
| 204 | * @param[in] bases_p Array of names (including prefix if necessary) of base identities. |
| 205 | * @param[in] ident Referencing identity to work with, NULL for identityref. |
| 206 | * @param[in] bases Array of bases of identityref to fill in. |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 207 | * @param[in] enabled Whether the base is disabled, must be set if @p ident is set. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 208 | * @return LY_ERR value. |
| 209 | */ |
| 210 | LY_ERR lys_compile_identity_bases(struct lysc_ctx *ctx, const struct lysp_module *base_pmod, const char **bases_p, |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 211 | struct lysc_ident *ident, struct lysc_ident ***bases, ly_bool *enabled); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 212 | |
| 213 | /** |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 214 | * @brief Compile schema into a validated schema linking all the references. Must have been implemented before. |
| 215 | * |
| 216 | * @param[in] mod Pointer to the schema structure holding pointers to both schema structure types. The ::lys_module#parsed |
| 217 | * member is used as input and ::lys_module#compiled is used to hold the result of the compilation. |
| 218 | * @param[in,out] unres Dep set unres structure to add to. |
| 219 | * @return LY_SUCCESS on success. |
| 220 | * @return LY_ERR on error. |
| 221 | */ |
| 222 | LY_ERR lys_compile(struct lys_module *mod, struct lys_depset_unres *unres); |
| 223 | |
| 224 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 225 | * @brief Check statement's status for invalid combination. |
| 226 | * |
| 227 | * The modX parameters are used just to determine if both flags are in the same module, |
| 228 | * so any of the schema module structure can be used, but both modules must be provided |
| 229 | * in the same type. |
| 230 | * |
| 231 | * @param[in] ctx Compile context for logging. |
| 232 | * @param[in] flags1 Flags of the referencing node. |
| 233 | * @param[in] mod1 Module of the referencing node, |
| 234 | * @param[in] name1 Schema node name of the referencing node. |
| 235 | * @param[in] flags2 Flags of the referenced node. |
| 236 | * @param[in] mod2 Module of the referenced node, |
| 237 | * @param[in] name2 Schema node name of the referenced node. |
| 238 | * @return LY_ERR value |
| 239 | */ |
| 240 | LY_ERR lysc_check_status(struct lysc_ctx *ctx, uint16_t flags1, void *mod1, const char *name1, uint16_t flags2, |
| 241 | void *mod2, const char *name2); |
| 242 | |
| 243 | /** |
Michal Vasko | 25d6ad0 | 2020-10-22 12:20:22 +0200 | [diff] [blame] | 244 | * @brief Check parsed expression for any prefixes of unimplemented modules. |
| 245 | * |
| 246 | * @param[in] ctx libyang context. |
| 247 | * @param[in] expr Parsed expression. |
| 248 | * @param[in] format Prefix format. |
| 249 | * @param[in] prefix_data Format-specific data (see ::ly_resolve_prefix()). |
| 250 | * @param[in] implement Whether all the non-implemented modules should are implemented or the first |
| 251 | * non-implemented module, if any, returned in @p mod_p. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 252 | * @param[in,out] unres Global unres structure of newly implemented modules. |
Michal Vasko | 25d6ad0 | 2020-10-22 12:20:22 +0200 | [diff] [blame] | 253 | * @param[out] mod_p Module that is not implemented. |
| 254 | * @return LY_SUCCESS on success. |
Michal Vasko | 40c158c | 2021-04-28 17:01:03 +0200 | [diff] [blame] | 255 | * @return LY_ERECOMPILE if @p implement is set. |
Michal Vasko | 25d6ad0 | 2020-10-22 12:20:22 +0200 | [diff] [blame] | 256 | * @return LY_ERR on error. |
| 257 | */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 258 | LY_ERR lys_compile_expr_implement(const struct ly_ctx *ctx, const struct lyxp_expr *expr, LY_VALUE_FORMAT format, |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 259 | void *prefix_data, ly_bool implement, struct lys_glob_unres *unres, const struct lys_module **mod_p); |
| 260 | |
| 261 | /** |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 262 | * @brief Compile all flagged modules in a dependency set, recursively if recompilation is needed. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 263 | * |
Michal Vasko | 50bc09a | 2021-06-17 17:31:56 +0200 | [diff] [blame] | 264 | * Steps taken when adding a new module (::ly_ctx_load_module(), ::lys_parse()): |
| 265 | * |
| 266 | * 1) parse module and add it into context with all imports and includes also parsed and in context |
Michal Vasko | 6598824 | 2021-07-15 09:19:16 +0200 | [diff] [blame] | 267 | * (::lys_parse_load(), ::lys_parse_in(), lys_parse_localfile() - static) |
Michal Vasko | 50bc09a | 2021-06-17 17:31:56 +0200 | [diff] [blame] | 268 | * 2) implement it (perform one-time compilation tasks - compile identities and add reference to augment/deviation |
| 269 | * target modules, implement those as well, ::_lys_set_implemented()) |
| 270 | * 3) create dep set of the module (::lys_unres_dep_sets_create()) |
| 271 | * 4) (re)compile all the modules in the dep set and collect unres (::lys_compile_dep_set_r()) |
Michal Vasko | 6598824 | 2021-07-15 09:19:16 +0200 | [diff] [blame] | 272 | * 5) resolve unres (lys_compile_unres_depset() - static), new modules may be implemented like in 2) and if |
| 273 | * require recompilation, free all compiled modules and do 4) |
Michal Vasko | 50bc09a | 2021-06-17 17:31:56 +0200 | [diff] [blame] | 274 | * 6) all modules that needed to be (re)compiled are now, with all their dependencies |
| 275 | * |
| 276 | * What can cause new modules to be implemented when resolving unres in 5): |
| 277 | * - leafref |
| 278 | * - when, must |
Michal Vasko | 41369bd | 2021-06-23 12:03:23 +0200 | [diff] [blame] | 279 | * - identityref, instance-identifier default value |
Michal Vasko | 50bc09a | 2021-06-17 17:31:56 +0200 | [diff] [blame] | 280 | * - new implemented module augments, deviations |
| 281 | * |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 282 | * @param[in] ctx libyang context. |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 283 | * @param[in] dep_set Dependency set to compile. |
| 284 | * @param[in,out] unres Global unres to use. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 285 | * @return LY_ERR value. |
| 286 | */ |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 287 | LY_ERR lys_compile_dep_set_r(struct ly_ctx *ctx, struct ly_set *dep_set, struct lys_glob_unres *unres); |
Michal Vasko | 916aefb | 2020-11-02 15:43:16 +0100 | [diff] [blame] | 288 | |
| 289 | /** |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 290 | * @brief Implement a single module. Does not actually compile, only marks to_compile! |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 291 | * |
| 292 | * @param[in] mod Module to implement. |
| 293 | * @param[in] features Features to set, see ::lys_set_features(). |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 294 | * @param[in,out] unres Global unres to use. |
| 295 | * @return LY_ERR value. |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 296 | */ |
| 297 | LY_ERR lys_implement(struct lys_module *mod, const char **features, struct lys_glob_unres *unres); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 298 | |
| 299 | #endif /* LY_SCHEMA_COMPILE_H_ */ |