blob: 97d3cd0ea164d3d9738328ff73cb1de8c868459d [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
20struct lysp_qname;
21struct lysc_augment;
22struct lysc_deviation;
23struct lysc_refine;
24struct lysp_node;
25struct lysc_node;
26struct lysc_ctx;
27struct lysp_node_uses;
28struct lys_module;
29
30/**
31 * @brief Compiled parsed augment structure. Just a temporary storage for applying the augment to data.
32 */
33struct lysc_augment {
34 struct lyxp_expr *nodeid; /**< augment target */
35 const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */
36 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */
37
38 struct lysp_augment *aug_p; /**< pointer to the parsed augment to apply */
39};
40
41/**
42 * @brief Compiled parsed deviation structure. Just a temporary storage for applying the deviation to data.
43 */
44struct 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 */
58struct 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 */
62
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_ */