blob: 1e47c615299c97956d1a8052c0cebf1f19c3b84d [file] [log] [blame]
Michal Vasko1a7a7bd2020-10-16 14:39:15 +02001/**
2 * @file schema_compile_amend.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vasko0b50f6b2022-10-05 15:07:55 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Michal Vasko1a7a7bd2020-10-16 14:39:15 +02005 * @brief Header for schema compilation of augments, deviations, and refines.
6 *
Michal Vasko0b50f6b2022-10-05 15:07:55 +02007 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +02008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
16#ifndef LY_SCHEMA_COMPILE_AMEND_H_
17#define LY_SCHEMA_COMPILE_AMEND_H_
18
Michal Vasko0b50f6b2022-10-05 15:07:55 +020019#include <stddef.h>
20
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020021#include "log.h"
22
Radek Krejci47fab892020-11-05 17:02:41 +010023struct ly_ctx;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020024struct lysp_qname;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020025struct lysp_node;
26struct lysc_node;
27struct lysc_ctx;
28struct lysp_node_uses;
Michal Vasko0b50f6b2022-10-05 15:07:55 +020029struct lysp_when;
Michal Vasko65333882021-06-10 14:12:16 +020030struct lys_glob_unres;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020031struct lys_module;
32
33/**
34 * @brief Compiled parsed augment structure. Just a temporary storage for applying the augment to data.
35 */
36struct lysc_augment {
37 struct lyxp_expr *nodeid; /**< augment target */
Michal Vasko28fe5f62021-03-03 16:37:39 +010038 const struct lysp_module *aug_pmod; /**< module where the augment is defined, for top-level augments
39 used to resolve prefixes, for uses augments used as the context pmod */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020040 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */
41
Michal Vasko28fe5f62021-03-03 16:37:39 +010042 struct lysp_node_augment *aug_p; /**< pointer to the parsed augment to apply */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020043};
44
45/**
46 * @brief Compiled parsed deviation structure. Just a temporary storage for applying the deviation to data.
47 */
48struct lysc_deviation {
49 struct lyxp_expr *nodeid; /**< deviation target, taken from the first deviation in
50 ::lysc_deviation.dev_pmods array, this module is used for resolving
51 prefixes used in the nodeid. */
52
53 struct lysp_deviation **devs; /**< sized array of all the parsed deviations for one target node */
54 const struct lysp_module **dev_pmods; /**< sized array of parsed modules of @p devs (where the specific deviations
55 are defined). */
56 ly_bool not_supported; /**< whether this is a not-supported deviation */
57};
58
59/**
60 * @brief Compiled parsed refine structure. Just a temporary storage for applying the refine to data.
61 */
62struct lysc_refine {
63 struct lyxp_expr *nodeid; /**< refine target */
64 const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */
65 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node */
Michal Vaskod8655722021-01-12 15:20:36 +010066 struct lysp_node_uses *uses_p; /**< parsed uses node of the refine, for tracking recursive refines */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020067
68 struct lysp_refine **rfns; /**< sized array of parsed refines to apply */
69};
70
71/**
72 * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation.
73 *
74 * @param[in] ctx Compile context.
75 * @param[in] uses_p Parsed uses structure with augments and refines.
aPiecekb0445f22021-06-24 11:34:07 +020076 * @param[in] ctx_node Context node of @p uses_p meaning its first data definition parent.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020077 * @return LY_ERR value.
78 */
79LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p,
80 const struct lysc_node *ctx_node);
81
82/**
83 * @brief Duplicate qname structure.
84 *
85 * @param[in] ctx libyang context.
86 * @param[in,out] qname Structure to fill.
87 * @param[in] orig_qname Structure to read from.
88 * @return LY_ERR value.
89 */
90LY_ERR lysp_qname_dup(const struct ly_ctx *ctx, struct lysp_qname *qname, const struct lysp_qname *orig_qname);
91
92/**
93 * @brief Free a compiled augment temporary structure.
94 *
95 * @param[in] ctx libyang context.
96 * @param[in] aug Structure to free.
97 */
98void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug);
99
100/**
101 * @brief Free a compiled deviation temporary structure.
102 *
103 * @param[in] ctx libyang context.
104 * @param[in] dev Structure to free.
105 */
106void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev);
107
108/**
109 * @brief Free a compiled refine temporary structure.
110 *
111 * @param[in] ctx libyang context.
112 * @param[in] rfn Structure to free.
113 */
114void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn);
115
116/**
117 * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines().
118 *
119 * @param[in] ctx libyang context.
120 * @param[in] dev_pnode Parsed node to free.
121 */
Michal Vaskoc636ea42022-09-16 10:20:31 +0200122void lysp_dev_node_free(struct lysc_ctx *cctx, struct lysp_node *dev_pnode);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200123
124/**
aPiecekb0445f22021-06-24 11:34:07 +0200125 * @brief Compile and apply any precompiled deviations and refines targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200126 *
127 * @param[in] ctx Compile context.
128 * @param[in] pnode Parsed node to consider.
129 * @param[in] parent First compiled parent of @p pnode.
130 * @param[out] dev_pnode Copy of parsed node @p pnode with deviations and refines, if any. NULL if there are none.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200131 * @param[out] not_supported Whether a not-supported deviation is defined for the node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200132 * @return LY_ERR value.
133 */
134LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode,
135 const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported);
136
137/**
Michal Vasko0b50f6b2022-10-05 15:07:55 +0200138 * @brief Compile augment children.
139 *
140 * @param[in] ctx Compile context.
141 * @param[in] aug_when Parsed augment when to inherit.
142 * @param[in] aug_flags Parsed augment flags.
143 * @param[in] child First augment child to compile.
144 * @param[in] target Target node of the augment.
145 * @param[in] child_unres_disabled Whether the children are to be put into unres disabled set or not.
146 * @return LY_SUCCESS on success.
147 * @return LY_EVALID on failure.
148 */
149LY_ERR lys_compile_augment_children(struct lysc_ctx *ctx, struct lysp_when *aug_when, uint16_t aug_flags,
150 struct lysp_node *child, struct lysc_node *target, ly_bool child_unres_disabled);
151
152/**
aPiecekb0445f22021-06-24 11:34:07 +0200153 * @brief Compile and apply any precompiled top-level or uses augments targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200154 *
155 * @param[in] ctx Compile context.
156 * @param[in] node Compiled node to consider.
157 * @return LY_ERR value.
158 */
159LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node);
160
161/**
162 * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation.
163 *
164 * @param[in] ctx Compile context.
165 * @return LY_ERR value.
166 */
167LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx);
168
169/**
170 * @brief Prepare all deviations for the current module to be applied during data nodes compilation.
171 *
172 * @param[in] ctx Compile context.
173 * @return LY_ERR value.
174 */
175LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx);
176
177/**
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200178 * @brief Add references to target modules of top-level augments and deviations in a module and all its submodules.
179 * Adds the module reference to the target modules and if not implemented, implement them (but not compile).
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200180 *
Michal Vasko65333882021-06-10 14:12:16 +0200181 * @param[in] mod Module to process.
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200182 * @param[in,out] unres Global unres to use.
Michal Vasko65333882021-06-10 14:12:16 +0200183 * @return LY_SUCCESS on success.
Michal Vaskof4258e12021-06-15 12:11:42 +0200184 * @return LY_ERECOMPILE on required recompilation of the dep set.
Michal Vasko65333882021-06-10 14:12:16 +0200185 * @return LY_ERR on error.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200186 */
Michal Vasko65333882021-06-10 14:12:16 +0200187LY_ERR lys_precompile_augments_deviations(struct lys_module *mod, struct lys_glob_unres *unres);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200188
189/**
190 * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from
191 * all the target modules.
192 *
193 * @param[in] ctx libyang context.
194 * @param[in] mod Mod whose precompilation to revert.
195 */
196void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod);
197
198#endif /* LY_SCHEMA_COMPILE_AMEND_H_ */