blob: 0ab98a86a047eca2044c4ec41ed8c3f276793537 [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
36 struct lysp_augment *aug_p; /**< pointer to the parsed augment to apply */
37};
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 */
60
61 struct lysp_refine **rfns; /**< sized array of parsed refines to apply */
62};
63
64/**
65 * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation.
66 *
67 * @param[in] ctx Compile context.
68 * @param[in] uses_p Parsed uses structure with augments and refines.
69 * @param[in] ctx_node Context node of @p uses_p meaning its first data definiition parent.
70 * @return LY_ERR value.
71 */
72LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p,
73 const struct lysc_node *ctx_node);
74
75/**
76 * @brief Duplicate qname structure.
77 *
78 * @param[in] ctx libyang context.
79 * @param[in,out] qname Structure to fill.
80 * @param[in] orig_qname Structure to read from.
81 * @return LY_ERR value.
82 */
83LY_ERR lysp_qname_dup(const struct ly_ctx *ctx, struct lysp_qname *qname, const struct lysp_qname *orig_qname);
84
85/**
86 * @brief Free a compiled augment temporary structure.
87 *
88 * @param[in] ctx libyang context.
89 * @param[in] aug Structure to free.
90 */
91void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug);
92
93/**
94 * @brief Free a compiled deviation temporary structure.
95 *
96 * @param[in] ctx libyang context.
97 * @param[in] dev Structure to free.
98 */
99void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev);
100
101/**
102 * @brief Free a compiled refine temporary structure.
103 *
104 * @param[in] ctx libyang context.
105 * @param[in] rfn Structure to free.
106 */
107void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn);
108
109/**
110 * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines().
111 *
112 * @param[in] ctx libyang context.
113 * @param[in] dev_pnode Parsed node to free.
114 */
115void lysp_dev_node_free(const struct ly_ctx *ctx, struct lysp_node *dev_pnode);
116
117/**
118 * @brief Compile and apply any precompiled deviations and refines targetting a node.
119 *
120 * @param[in] ctx Compile context.
121 * @param[in] pnode Parsed node to consider.
122 * @param[in] parent First compiled parent of @p pnode.
123 * @param[out] dev_pnode Copy of parsed node @p pnode with deviations and refines, if any. NULL if there are none.
124 * @param[out] no_supported Whether a not-supported deviation is defined for the node.
125 * @return LY_ERR value.
126 */
127LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode,
128 const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported);
129
130/**
131 * @brief Compile and apply any precompiled top-level or uses augments targetting a node.
132 *
133 * @param[in] ctx Compile context.
134 * @param[in] node Compiled node to consider.
135 * @return LY_ERR value.
136 */
137LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node);
138
139/**
140 * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation.
141 *
142 * @param[in] ctx Compile context.
143 * @return LY_ERR value.
144 */
145LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx);
146
147/**
148 * @brief Prepare all deviations for the current module to be applied during data nodes compilation.
149 *
150 * @param[in] ctx Compile context.
151 * @return LY_ERR value.
152 */
153LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx);
154
155/**
156 * @brief Compile top-level augments and deviations defined in the current module.
157 * Generally, just add the module refence to the target modules. But in case
158 * of foreign augments, they are directly applied.
159 *
160 * @param[in] ctx Compile context.
161 * @return LY_ERR value.
162 */
163LY_ERR lys_precompile_augments_deviations(struct lysc_ctx *ctx);
164
165/**
166 * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from
167 * all the target modules.
168 *
169 * @param[in] ctx libyang context.
170 * @param[in] mod Mod whose precompilation to revert.
171 */
172void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod);
173
174#endif /* LY_SCHEMA_COMPILE_AMEND_H_ */