blob: 808e64f5eb321f300c8a578bb50720fb0fbf03aa [file] [log] [blame]
Michal Vasko1a7a7bd2020-10-16 14:39:15 +02001/**
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 Krejci47fab892020-11-05 17:02:41 +010020struct ly_ctx;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020021struct lysp_qname;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020022struct lysp_node;
23struct lysc_node;
24struct lysc_ctx;
25struct lysp_node_uses;
26struct lys_module;
27
28/**
29 * @brief Compiled parsed augment structure. Just a temporary storage for applying the augment to data.
30 */
31struct lysc_augment {
32 struct lyxp_expr *nodeid; /**< augment target */
33 const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */
34 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */
35
Radek Krejci2a9fc652021-01-22 17:44:34 +010036 struct lysp_node_augment *aug_p; /**< pointer to the parsed augment to apply */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020037};
38
39/**
40 * @brief Compiled parsed deviation structure. Just a temporary storage for applying the deviation to data.
41 */
42struct lysc_deviation {
43 struct lyxp_expr *nodeid; /**< deviation target, taken from the first deviation in
44 ::lysc_deviation.dev_pmods array, this module is used for resolving
45 prefixes used in the nodeid. */
46
47 struct lysp_deviation **devs; /**< sized array of all the parsed deviations for one target node */
48 const struct lysp_module **dev_pmods; /**< sized array of parsed modules of @p devs (where the specific deviations
49 are defined). */
50 ly_bool not_supported; /**< whether this is a not-supported deviation */
51};
52
53/**
54 * @brief Compiled parsed refine structure. Just a temporary storage for applying the refine to data.
55 */
56struct lysc_refine {
57 struct lyxp_expr *nodeid; /**< refine target */
58 const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */
59 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node */
Michal Vaskod8655722021-01-12 15:20:36 +010060 struct lysp_node_uses *uses_p; /**< parsed uses node of the refine, for tracking recursive refines */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020061
62 struct lysp_refine **rfns; /**< sized array of parsed refines to apply */
63};
64
65/**
66 * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation.
67 *
68 * @param[in] ctx Compile context.
69 * @param[in] uses_p Parsed uses structure with augments and refines.
70 * @param[in] ctx_node Context node of @p uses_p meaning its first data definiition parent.
71 * @return LY_ERR value.
72 */
73LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p,
74 const struct lysc_node *ctx_node);
75
76/**
77 * @brief Duplicate qname structure.
78 *
79 * @param[in] ctx libyang context.
80 * @param[in,out] qname Structure to fill.
81 * @param[in] orig_qname Structure to read from.
82 * @return LY_ERR value.
83 */
84LY_ERR lysp_qname_dup(const struct ly_ctx *ctx, struct lysp_qname *qname, const struct lysp_qname *orig_qname);
85
86/**
87 * @brief Free a compiled augment temporary structure.
88 *
89 * @param[in] ctx libyang context.
90 * @param[in] aug Structure to free.
91 */
92void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug);
93
94/**
95 * @brief Free a compiled deviation temporary structure.
96 *
97 * @param[in] ctx libyang context.
98 * @param[in] dev Structure to free.
99 */
100void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev);
101
102/**
103 * @brief Free a compiled refine temporary structure.
104 *
105 * @param[in] ctx libyang context.
106 * @param[in] rfn Structure to free.
107 */
108void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn);
109
110/**
111 * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines().
112 *
113 * @param[in] ctx libyang context.
114 * @param[in] dev_pnode Parsed node to free.
115 */
116void lysp_dev_node_free(const struct ly_ctx *ctx, struct lysp_node *dev_pnode);
117
118/**
119 * @brief Compile and apply any precompiled deviations and refines targetting a node.
120 *
121 * @param[in] ctx Compile context.
122 * @param[in] pnode Parsed node to consider.
123 * @param[in] parent First compiled parent of @p pnode.
124 * @param[out] dev_pnode Copy of parsed node @p pnode with deviations and refines, if any. NULL if there are none.
125 * @param[out] no_supported Whether a not-supported deviation is defined for the node.
126 * @return LY_ERR value.
127 */
128LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode,
129 const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported);
130
131/**
132 * @brief Compile and apply any precompiled top-level or uses augments targetting a node.
133 *
134 * @param[in] ctx Compile context.
135 * @param[in] node Compiled node to consider.
136 * @return LY_ERR value.
137 */
138LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node);
139
140/**
141 * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation.
142 *
143 * @param[in] ctx Compile context.
144 * @return LY_ERR value.
145 */
146LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx);
147
148/**
149 * @brief Prepare all deviations for the current module to be applied during data nodes compilation.
150 *
151 * @param[in] ctx Compile context.
152 * @return LY_ERR value.
153 */
154LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx);
155
156/**
157 * @brief Compile top-level augments and deviations defined in the current module.
158 * Generally, just add the module refence to the target modules. But in case
159 * of foreign augments, they are directly applied.
160 *
161 * @param[in] ctx Compile context.
162 * @return LY_ERR value.
163 */
164LY_ERR lys_precompile_augments_deviations(struct lysc_ctx *ctx);
165
166/**
167 * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from
168 * all the target modules.
169 *
170 * @param[in] ctx libyang context.
171 * @param[in] mod Mod whose precompilation to revert.
172 */
173void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod);
174
175#endif /* LY_SCHEMA_COMPILE_AMEND_H_ */