blob: 9fe5c65c4ffa1c6949444a0d1637fe02de1615d7 [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;
Michal Vasko65333882021-06-10 14:12:16 +020026struct lys_glob_unres;
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020027struct lys_module;
28
29/**
30 * @brief Compiled parsed augment structure. Just a temporary storage for applying the augment to data.
31 */
32struct lysc_augment {
33 struct lyxp_expr *nodeid; /**< augment target */
Michal Vasko28fe5f62021-03-03 16:37:39 +010034 const struct lysp_module *aug_pmod; /**< module where the augment is defined, for top-level augments
35 used to resolve prefixes, for uses augments used as the context pmod */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020036 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */
37
Michal Vasko28fe5f62021-03-03 16:37:39 +010038 struct lysp_node_augment *aug_p; /**< pointer to the parsed augment to apply */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020039};
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 */
Michal Vaskod8655722021-01-12 15:20:36 +010062 struct lysp_node_uses *uses_p; /**< parsed uses node of the refine, for tracking recursive refines */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020063
64 struct lysp_refine **rfns; /**< sized array of parsed refines to apply */
65};
66
67/**
68 * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation.
69 *
70 * @param[in] ctx Compile context.
71 * @param[in] uses_p Parsed uses structure with augments and refines.
aPiecekb0445f22021-06-24 11:34:07 +020072 * @param[in] ctx_node Context node of @p uses_p meaning its first data definition parent.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020073 * @return LY_ERR value.
74 */
75LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p,
76 const struct lysc_node *ctx_node);
77
78/**
79 * @brief Duplicate qname structure.
80 *
81 * @param[in] ctx libyang context.
82 * @param[in,out] qname Structure to fill.
83 * @param[in] orig_qname Structure to read from.
84 * @return LY_ERR value.
85 */
86LY_ERR lysp_qname_dup(const struct ly_ctx *ctx, struct lysp_qname *qname, const struct lysp_qname *orig_qname);
87
88/**
89 * @brief Free a compiled augment temporary structure.
90 *
91 * @param[in] ctx libyang context.
92 * @param[in] aug Structure to free.
93 */
94void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug);
95
96/**
97 * @brief Free a compiled deviation temporary structure.
98 *
99 * @param[in] ctx libyang context.
100 * @param[in] dev Structure to free.
101 */
102void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev);
103
104/**
105 * @brief Free a compiled refine temporary structure.
106 *
107 * @param[in] ctx libyang context.
108 * @param[in] rfn Structure to free.
109 */
110void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn);
111
112/**
113 * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines().
114 *
115 * @param[in] ctx libyang context.
116 * @param[in] dev_pnode Parsed node to free.
117 */
118void lysp_dev_node_free(const struct ly_ctx *ctx, struct lysp_node *dev_pnode);
119
120/**
aPiecekb0445f22021-06-24 11:34:07 +0200121 * @brief Compile and apply any precompiled deviations and refines targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200122 *
123 * @param[in] ctx Compile context.
124 * @param[in] pnode Parsed node to consider.
125 * @param[in] parent First compiled parent of @p pnode.
126 * @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 +0200127 * @param[out] not_supported Whether a not-supported deviation is defined for the node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200128 * @return LY_ERR value.
129 */
130LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode,
131 const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported);
132
133/**
aPiecekb0445f22021-06-24 11:34:07 +0200134 * @brief Compile and apply any precompiled top-level or uses augments targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200135 *
136 * @param[in] ctx Compile context.
137 * @param[in] node Compiled node to consider.
138 * @return LY_ERR value.
139 */
140LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node);
141
142/**
143 * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation.
144 *
145 * @param[in] ctx Compile context.
146 * @return LY_ERR value.
147 */
148LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx);
149
150/**
151 * @brief Prepare all deviations for the current module to be applied during data nodes compilation.
152 *
153 * @param[in] ctx Compile context.
154 * @return LY_ERR value.
155 */
156LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx);
157
158/**
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200159 * @brief Add references to target modules of top-level augments and deviations in a module and all its submodules.
160 * Adds the module reference to the target modules and if not implemented, implement them (but not compile).
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200161 *
Michal Vasko65333882021-06-10 14:12:16 +0200162 * @param[in] mod Module to process.
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200163 * @param[in,out] unres Global unres to use.
Michal Vasko65333882021-06-10 14:12:16 +0200164 * @return LY_SUCCESS on success.
Michal Vaskof4258e12021-06-15 12:11:42 +0200165 * @return LY_ERECOMPILE on required recompilation of the dep set.
Michal Vasko65333882021-06-10 14:12:16 +0200166 * @return LY_ERR on error.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200167 */
Michal Vasko65333882021-06-10 14:12:16 +0200168LY_ERR lys_precompile_augments_deviations(struct lys_module *mod, struct lys_glob_unres *unres);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200169
170/**
171 * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from
172 * all the target modules.
173 *
174 * @param[in] ctx libyang context.
175 * @param[in] mod Mod whose precompilation to revert.
176 */
177void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod);
178
179#endif /* LY_SCHEMA_COMPILE_AMEND_H_ */