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