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