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