blob: 6cd4c050462d7d86b686d905515267a9f8142c20 [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 Vasko8824a6e2024-01-19 12:42:21 +01007 * Copyright (c) 2015 - 2024 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/**
Michal Vasko8824a6e2024-01-19 12:42:21 +010031 * @brief Compiled parsed schema-node-id.
32 */
33struct lysc_nodeid {
34 const char *str; /**< Original schema-node-id, just a pointer (do not free). */
35
36 const char **prefix; /**< Array of node prefixes in the dictionary, NULL if none. */
37 const char **name; /**< Array of node name in the dictionary. */
38 uint32_t count; /**< Number of items in @p prefix and @p name arrays */
39};
40
41/**
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020042 * @brief Compiled parsed augment structure. Just a temporary storage for applying the augment to data.
43 */
44struct lysc_augment {
Michal Vasko8824a6e2024-01-19 12:42:21 +010045 struct lysc_nodeid *nodeid; /**< augment target */
Michal Vasko28fe5f62021-03-03 16:37:39 +010046 const struct lysp_module *aug_pmod; /**< module where the augment is defined, for top-level augments
47 used to resolve prefixes, for uses augments used as the context pmod */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020048 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node for relative targets */
Michal Vaskoa0ba01e2022-10-19 13:26:57 +020049 const struct lysp_ext_instance *ext; /**< parent extension instance, in case the augment is from one */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020050
Michal Vasko28fe5f62021-03-03 16:37:39 +010051 struct lysp_node_augment *aug_p; /**< pointer to the parsed augment to apply */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020052};
53
54/**
55 * @brief Compiled parsed deviation structure. Just a temporary storage for applying the deviation to data.
56 */
57struct lysc_deviation {
Michal Vasko8824a6e2024-01-19 12:42:21 +010058 struct lysc_nodeid *nodeid; /**< deviation target, taken from the first deviation in
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020059 ::lysc_deviation.dev_pmods array, this module is used for resolving
60 prefixes used in the nodeid. */
61
62 struct lysp_deviation **devs; /**< sized array of all the parsed deviations for one target node */
63 const struct lysp_module **dev_pmods; /**< sized array of parsed modules of @p devs (where the specific deviations
64 are defined). */
65 ly_bool not_supported; /**< whether this is a not-supported deviation */
66};
67
68/**
69 * @brief Compiled parsed refine structure. Just a temporary storage for applying the refine to data.
70 */
71struct lysc_refine {
Michal Vasko8824a6e2024-01-19 12:42:21 +010072 struct lysc_nodeid *nodeid; /**< refine target */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020073 const struct lysp_module *nodeid_pmod; /**< module where the nodeid is defined, used to resolve prefixes */
74 const struct lysc_node *nodeid_ctx_node; /**< nodeid context node */
Michal Vaskod8655722021-01-12 15:20:36 +010075 struct lysp_node_uses *uses_p; /**< parsed uses node of the refine, for tracking recursive refines */
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020076
77 struct lysp_refine **rfns; /**< sized array of parsed refines to apply */
78};
79
80/**
81 * @brief Prepare any uses augments and refines in the context to be applied during uses descendant node compilation.
82 *
83 * @param[in] ctx Compile context.
84 * @param[in] uses_p Parsed uses structure with augments and refines.
aPiecekb0445f22021-06-24 11:34:07 +020085 * @param[in] ctx_node Context node of @p uses_p meaning its first data definition parent.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020086 * @return LY_ERR value.
87 */
88LY_ERR lys_precompile_uses_augments_refines(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p,
89 const struct lysc_node *ctx_node);
90
91/**
92 * @brief Duplicate qname structure.
93 *
94 * @param[in] ctx libyang context.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020095 * @param[in] orig_qname Structure to read from.
Michal Vaskoc621d862022-11-08 14:23:45 +010096 * @param[in,out] qname Structure to fill.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +020097 * @return LY_ERR value.
98 */
Michal Vaskoc621d862022-11-08 14:23:45 +010099LY_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 +0200100
101/**
102 * @brief Free a compiled augment temporary structure.
103 *
104 * @param[in] ctx libyang context.
105 * @param[in] aug Structure to free.
106 */
107void lysc_augment_free(const struct ly_ctx *ctx, struct lysc_augment *aug);
108
109/**
110 * @brief Free a compiled deviation temporary structure.
111 *
112 * @param[in] ctx libyang context.
113 * @param[in] dev Structure to free.
114 */
115void lysc_deviation_free(const struct ly_ctx *ctx, struct lysc_deviation *dev);
116
117/**
118 * @brief Free a compiled refine temporary structure.
119 *
120 * @param[in] ctx libyang context.
121 * @param[in] rfn Structure to free.
122 */
123void lysc_refine_free(const struct ly_ctx *ctx, struct lysc_refine *rfn);
124
125/**
126 * @brief Free a duplicate of parsed node. It is returned by ::lys_compile_node_deviations_refines().
127 *
128 * @param[in] ctx libyang context.
129 * @param[in] dev_pnode Parsed node to free.
130 */
Michal Vaskoc636ea42022-09-16 10:20:31 +0200131void lysp_dev_node_free(struct lysc_ctx *cctx, struct lysp_node *dev_pnode);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200132
133/**
aPiecekb0445f22021-06-24 11:34:07 +0200134 * @brief Compile and apply any precompiled deviations and refines targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200135 *
136 * @param[in] ctx Compile context.
137 * @param[in] pnode Parsed node to consider.
138 * @param[in] parent First compiled parent of @p pnode.
139 * @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 +0200140 * @param[out] not_supported Whether a not-supported deviation is defined for the node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200141 * @return LY_ERR value.
142 */
143LY_ERR lys_compile_node_deviations_refines(struct lysc_ctx *ctx, const struct lysp_node *pnode,
144 const struct lysc_node *parent, struct lysp_node **dev_pnode, ly_bool *not_supported);
145
146/**
aPiecekb0445f22021-06-24 11:34:07 +0200147 * @brief Compile and apply any precompiled top-level or uses augments targeting a node.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200148 *
149 * @param[in] ctx Compile context.
150 * @param[in] node Compiled node to consider.
151 * @return LY_ERR value.
152 */
153LY_ERR lys_compile_node_augments(struct lysc_ctx *ctx, struct lysc_node *node);
154
155/**
156 * @brief Prepare all top-level augments for the current module to be applied during data nodes compilation.
157 *
158 * @param[in] ctx Compile context.
159 * @return LY_ERR value.
160 */
161LY_ERR lys_precompile_own_augments(struct lysc_ctx *ctx);
162
163/**
164 * @brief Prepare all deviations for the current module to be applied during data nodes compilation.
165 *
166 * @param[in] ctx Compile context.
167 * @return LY_ERR value.
168 */
169LY_ERR lys_precompile_own_deviations(struct lysc_ctx *ctx);
170
171/**
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200172 * @brief Add references to target modules of top-level augments and deviations in a module and all its submodules.
173 * Adds the module reference to the target modules and if not implemented, implement them (but not compile).
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200174 *
Michal Vasko65333882021-06-10 14:12:16 +0200175 * @param[in] mod Module to process.
Michal Vaskoa9f807e2021-06-15 12:07:16 +0200176 * @param[in,out] unres Global unres to use.
Michal Vasko65333882021-06-10 14:12:16 +0200177 * @return LY_SUCCESS on success.
Michal Vaskof4258e12021-06-15 12:11:42 +0200178 * @return LY_ERECOMPILE on required recompilation of the dep set.
Michal Vasko65333882021-06-10 14:12:16 +0200179 * @return LY_ERR on error.
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200180 */
Michal Vasko65333882021-06-10 14:12:16 +0200181LY_ERR lys_precompile_augments_deviations(struct lys_module *mod, struct lys_glob_unres *unres);
Michal Vasko1a7a7bd2020-10-16 14:39:15 +0200182
183/**
184 * @brief Revert precompilation of module augments and deviations. Meaning remove its reference from
185 * all the target modules.
186 *
187 * @param[in] ctx libyang context.
188 * @param[in] mod Mod whose precompilation to revert.
189 */
190void lys_precompile_augments_deviations_revert(struct ly_ctx *ctx, const struct lys_module *mod);
191
192#endif /* LY_SCHEMA_COMPILE_AMEND_H_ */