Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file schema_compile_amend.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | 0b50f6b | 2022-10-05 15:07:55 +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 of augments, deviations, and refines. |
| 6 | * |
Michal Vasko | 0b50f6b | 2022-10-05 15:07:55 +0200 | [diff] [blame^] | 7 | * Copyright (c) 2015 - 2022 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_AMEND_H_ |
| 17 | #define LY_SCHEMA_COMPILE_AMEND_H_ |
| 18 | |
Michal Vasko | 0b50f6b | 2022-10-05 15:07:55 +0200 | [diff] [blame^] | 19 | #include <stddef.h> |
| 20 | |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 21 | #include "log.h" |
| 22 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 23 | struct ly_ctx; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 24 | struct lysp_qname; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 25 | struct lysp_node; |
| 26 | struct lysc_node; |
| 27 | struct lysc_ctx; |
| 28 | struct lysp_node_uses; |
Michal Vasko | 0b50f6b | 2022-10-05 15:07:55 +0200 | [diff] [blame^] | 29 | struct lysp_when; |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 30 | struct lys_glob_unres; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 31 | struct lys_module; |
| 32 | |
| 33 | /** |
| 34 | * @brief Compiled parsed augment structure. Just a temporary storage for applying the augment to data. |
| 35 | */ |
| 36 | struct lysc_augment { |
| 37 | struct lyxp_expr *nodeid; /**< augment target */ |
Michal Vasko | 28fe5f6 | 2021-03-03 16:37:39 +0100 | [diff] [blame] | 38 | const struct lysp_module *aug_pmod; /**< module where the augment is defined, for top-level augments |
| 39 | used to resolve prefixes, for uses augments used as the context pmod */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 40 | const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */ |
| 41 | |
Michal Vasko | 28fe5f6 | 2021-03-03 16:37:39 +0100 | [diff] [blame] | 42 | struct lysp_node_augment *aug_p; /**< pointer to the parsed augment to apply */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * @brief Compiled parsed deviation structure. Just a temporary storage for applying the deviation to data. |
| 47 | */ |
| 48 | struct lysc_deviation { |
| 49 | struct lyxp_expr *nodeid; /**< deviation target, taken from the first deviation in |
| 50 | ::lysc_deviation.dev_pmods array, this module is used for resolving |
| 51 | prefixes used in the nodeid. */ |
| 52 | |
| 53 | struct lysp_deviation **devs; /**< sized array of all the parsed deviations for one target node */ |
| 54 | const struct lysp_module **dev_pmods; /**< sized array of parsed modules of @p devs (where the specific deviations |
| 55 | are defined). */ |
| 56 | ly_bool not_supported; /**< whether this is a not-supported deviation */ |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * @brief Compiled parsed refine structure. Just a temporary storage for applying the refine to data. |
| 61 | */ |
| 62 | struct lysc_refine { |
| 63 | struct lyxp_expr *nodeid; /**< refine target */ |
| 64 | const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */ |
| 65 | const struct lysc_node *nodeid_ctx_node; /**< nodeid context node */ |
Michal Vasko | d865572 | 2021-01-12 15:20:36 +0100 | [diff] [blame] | 66 | struct lysp_node_uses *uses_p; /**< parsed uses node of the refine, for tracking recursive refines */ |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 67 | |
| 68 | struct lysp_refine **rfns; /**< sized array of parsed refines to apply */ |
| 69 | }; |
| 70 | |
| 71 | /** |
| 72 | * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation. |
| 73 | * |
| 74 | * @param[in] ctx Compile context. |
| 75 | * @param[in] uses_p Parsed uses structure with augments and refines. |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 76 | * @param[in] ctx_node Context node of @p uses_p meaning its first data definition parent. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 77 | * @return LY_ERR value. |
| 78 | */ |
| 79 | LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p, |
| 80 | const struct lysc_node *ctx_node); |
| 81 | |
| 82 | /** |
| 83 | * @brief Duplicate qname structure. |
| 84 | * |
| 85 | * @param[in] ctx libyang context. |
| 86 | * @param[in,out] qname Structure to fill. |
| 87 | * @param[in] orig_qname Structure to read from. |
| 88 | * @return LY_ERR value. |
| 89 | */ |
| 90 | LY_ERR lysp_qname_dup(const struct ly_ctx *ctx, struct lysp_qname *qname, const struct lysp_qname *orig_qname); |
| 91 | |
| 92 | /** |
| 93 | * @brief Free a compiled augment temporary structure. |
| 94 | * |
| 95 | * @param[in] ctx libyang context. |
| 96 | * @param[in] aug Structure to free. |
| 97 | */ |
| 98 | void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug); |
| 99 | |
| 100 | /** |
| 101 | * @brief Free a compiled deviation temporary structure. |
| 102 | * |
| 103 | * @param[in] ctx libyang context. |
| 104 | * @param[in] dev Structure to free. |
| 105 | */ |
| 106 | void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev); |
| 107 | |
| 108 | /** |
| 109 | * @brief Free a compiled refine temporary structure. |
| 110 | * |
| 111 | * @param[in] ctx libyang context. |
| 112 | * @param[in] rfn Structure to free. |
| 113 | */ |
| 114 | void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn); |
| 115 | |
| 116 | /** |
| 117 | * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines(). |
| 118 | * |
| 119 | * @param[in] ctx libyang context. |
| 120 | * @param[in] dev_pnode Parsed node to free. |
| 121 | */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 122 | void lysp_dev_node_free(struct lysc_ctx *cctx, struct lysp_node *dev_pnode); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 123 | |
| 124 | /** |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 125 | * @brief Compile and apply any precompiled deviations and refines targeting a node. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 126 | * |
| 127 | * @param[in] ctx Compile context. |
| 128 | * @param[in] pnode Parsed node to consider. |
| 129 | * @param[in] parent First compiled parent of @p pnode. |
| 130 | * @param[out] dev_pnode Copy of parsed node @p pnode with deviations and refines, if any. NULL if there are none. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 131 | * @param[out] not_supported Whether a not-supported deviation is defined for the node. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 132 | * @return LY_ERR value. |
| 133 | */ |
| 134 | LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode, |
| 135 | const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported); |
| 136 | |
| 137 | /** |
Michal Vasko | 0b50f6b | 2022-10-05 15:07:55 +0200 | [diff] [blame^] | 138 | * @brief Compile augment children. |
| 139 | * |
| 140 | * @param[in] ctx Compile context. |
| 141 | * @param[in] aug_when Parsed augment when to inherit. |
| 142 | * @param[in] aug_flags Parsed augment flags. |
| 143 | * @param[in] child First augment child to compile. |
| 144 | * @param[in] target Target node of the augment. |
| 145 | * @param[in] child_unres_disabled Whether the children are to be put into unres disabled set or not. |
| 146 | * @return LY_SUCCESS on success. |
| 147 | * @return LY_EVALID on failure. |
| 148 | */ |
| 149 | LY_ERR lys_compile_augment_children(struct lysc_ctx *ctx, struct lysp_when *aug_when, uint16_t aug_flags, |
| 150 | struct lysp_node *child, struct lysc_node *target, ly_bool child_unres_disabled); |
| 151 | |
| 152 | /** |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 153 | * @brief Compile and apply any precompiled top-level or uses augments targeting a node. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 154 | * |
| 155 | * @param[in] ctx Compile context. |
| 156 | * @param[in] node Compiled node to consider. |
| 157 | * @return LY_ERR value. |
| 158 | */ |
| 159 | LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node); |
| 160 | |
| 161 | /** |
| 162 | * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation. |
| 163 | * |
| 164 | * @param[in] ctx Compile context. |
| 165 | * @return LY_ERR value. |
| 166 | */ |
| 167 | LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx); |
| 168 | |
| 169 | /** |
| 170 | * @brief Prepare all deviations for the current module to be applied during data nodes compilation. |
| 171 | * |
| 172 | * @param[in] ctx Compile context. |
| 173 | * @return LY_ERR value. |
| 174 | */ |
| 175 | LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx); |
| 176 | |
| 177 | /** |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 178 | * @brief Add references to target modules of top-level augments and deviations in a module and all its submodules. |
| 179 | * Adds the module reference to the target modules and if not implemented, implement them (but not compile). |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 180 | * |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 181 | * @param[in] mod Module to process. |
Michal Vasko | a9f807e | 2021-06-15 12:07:16 +0200 | [diff] [blame] | 182 | * @param[in,out] unres Global unres to use. |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 183 | * @return LY_SUCCESS on success. |
Michal Vasko | f4258e1 | 2021-06-15 12:11:42 +0200 | [diff] [blame] | 184 | * @return LY_ERECOMPILE on required recompilation of the dep set. |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 185 | * @return LY_ERR on error. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 186 | */ |
Michal Vasko | 6533388 | 2021-06-10 14:12:16 +0200 | [diff] [blame] | 187 | LY_ERR lys_precompile_augments_deviations(struct lys_module *mod, struct lys_glob_unres *unres); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from |
| 191 | * all the target modules. |
| 192 | * |
| 193 | * @param[in] ctx libyang context. |
| 194 | * @param[in] mod Mod whose precompilation to revert. |
| 195 | */ |
| 196 | void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod); |
| 197 | |
| 198 | #endif /* LY_SCHEMA_COMPILE_AMEND_H_ */ |