blob: 344af6548b047f6457a0a37f48acb752295df3b2 [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
19#include "log.h"
20
Radek Krejci47fab892020-11-05 17:02:41 +010021struct ly_ctx;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020022struct lysp_qname;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020023struct lysp_node;
24struct lysc_node;
25struct lysc_ctx;
26struct lysp_node_uses;
Michal Vasko65333882021-06-10 14:12:16 +020027struct lys_glob_unres;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020028struct 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 */
Michal Vasko28fe5f62021-03-03 16:37:39 +010035 const struct lysp_module *aug_pmod; /**< module where the augment is defined, for top-level augments
36 used to resolve prefixes, for uses augments used as the context pmod */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020037 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */
Michal Vaskoa0ba01e2022-10-19 13:26:57 +020038 const struct lysp_ext_instance *ext; /**< parent extension instance, in case the augment is from one */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020039
Michal Vasko28fe5f62021-03-03 16:37:39 +010040 struct lysp_node_augment *aug_p; /**< pointer to the parsed augment to apply */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020041};
42
43/**
44 * @brief Compiled parsed deviation structure. Just a temporary storage for applying the deviation to data.
45 */
46struct lysc_deviation {
47 struct lyxp_expr *nodeid; /**< deviation target, taken from the first deviation in
48 ::lysc_deviation.dev_pmods array, this module is used for resolving
49 prefixes used in the nodeid. */
50
51 struct lysp_deviation **devs; /**< sized array of all the parsed deviations for one target node */
52 const struct lysp_module **dev_pmods; /**< sized array of parsed modules of @p devs (where the specific deviations
53 are defined). */
54 ly_bool not_supported; /**< whether this is a not-supported deviation */
55};
56
57/**
58 * @brief Compiled parsed refine structure. Just a temporary storage for applying the refine to data.
59 */
60struct lysc_refine {
61 struct lyxp_expr *nodeid; /**< refine target */
62 const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */
63 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node */
Michal Vaskod8655722021-01-12 15:20:36 +010064 struct lysp_node_uses *uses_p; /**< parsed uses node of the refine, for tracking recursive refines */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020065
66 struct lysp_refine **rfns; /**< sized array of parsed refines to apply */
67};
68
69/**
70 * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation.
71 *
72 * @param[in] ctx Compile context.
73 * @param[in] uses_p Parsed uses structure with augments and refines.
aPiecekb0445f22021-06-24 11:34:07 +020074 * @param[in] ctx_node Context node of @p uses_p meaning its first data definition parent.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020075 * @return LY_ERR value.
76 */
77LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p,
78 const struct lysc_node *ctx_node);
79
80/**
81 * @brief Duplicate qname structure.
82 *
83 * @param[in] ctx libyang context.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020084 * @param[in] orig_qname Structure to read from.
Michal Vaskoc621d862022-11-08 14:23:45 +010085 * @param[in,out] qname Structure to fill.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020086 * @return LY_ERR value.
87 */
Michal Vaskoc621d862022-11-08 14:23:45 +010088LY_ERR lysp_qname_dup(const struct ly_ctx *ctx, const struct lysp_qname *orig_qname, struct lysp_qname *qname);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020089
90/**
91 * @brief Free a compiled augment temporary structure.
92 *
93 * @param[in] ctx libyang context.
94 * @param[in] aug Structure to free.
95 */
96void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug);
97
98/**
99 * @brief Free a compiled deviation temporary structure.
100 *
101 * @param[in] ctx libyang context.
102 * @param[in] dev Structure to free.
103 */
104void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev);
105
106/**
107 * @brief Free a compiled refine temporary structure.
108 *
109 * @param[in] ctx libyang context.
110 * @param[in] rfn Structure to free.
111 */
112void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn);
113
114/**
115 * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines().
116 *
117 * @param[in] ctx libyang context.
118 * @param[in] dev_pnode Parsed node to free.
119 */
Michal Vaskoc636ea42022-09-16 10:20:31 +0200120void lysp_dev_node_free(struct lysc_ctx *cctx, struct lysp_node *dev_pnode);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200121
122/**
aPiecekb0445f22021-06-24 11:34:07 +0200123 * @brief Compile and apply any precompiled deviations and refines targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200124 *
125 * @param[in] ctx Compile context.
126 * @param[in] pnode Parsed node to consider.
127 * @param[in] parent First compiled parent of @p pnode.
128 * @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 +0200129 * @param[out] not_supported Whether a not-supported deviation is defined for the node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200130 * @return LY_ERR value.
131 */
132LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode,
133 const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported);
134
135/**
aPiecekb0445f22021-06-24 11:34:07 +0200136 * @brief Compile and apply any precompiled top-level or uses augments targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200137 *
138 * @param[in] ctx Compile context.
139 * @param[in] node Compiled node to consider.
140 * @return LY_ERR value.
141 */
142LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node);
143
144/**
145 * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation.
146 *
147 * @param[in] ctx Compile context.
148 * @return LY_ERR value.
149 */
150LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx);
151
152/**
153 * @brief Prepare all deviations for the current module to be applied during data nodes compilation.
154 *
155 * @param[in] ctx Compile context.
156 * @return LY_ERR value.
157 */
158LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx);
159
160/**
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200161 * @brief Add references to target modules of top-level augments and deviations in a module and all its submodules.
162 * Adds the module reference to the target modules and if not implemented, implement them (but not compile).
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200163 *
Michal Vasko65333882021-06-10 14:12:16 +0200164 * @param[in] mod Module to process.
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200165 * @param[in,out] unres Global unres to use.
Michal Vasko65333882021-06-10 14:12:16 +0200166 * @return LY_SUCCESS on success.
Michal Vaskof4258e12021-06-15 12:11:42 +0200167 * @return LY_ERECOMPILE on required recompilation of the dep set.
Michal Vasko65333882021-06-10 14:12:16 +0200168 * @return LY_ERR on error.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200169 */
Michal Vasko65333882021-06-10 14:12:16 +0200170LY_ERR lys_precompile_augments_deviations(struct lys_module *mod, struct lys_glob_unres *unres);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200171
172/**
173 * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from
174 * all the target modules.
175 *
176 * @param[in] ctx libyang context.
177 * @param[in] mod Mod whose precompilation to revert.
178 */
179void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod);
180
181#endif /* LY_SCHEMA_COMPILE_AMEND_H_ */