blob: 6dc06a884bcca0d004b9d14c2321267e9913b16b [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskoedb0fa52022-10-04 10:36:00 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejcid3ca0632019-04-16 16:54:54 +02005 * @brief YANG printer
6 *
Michal Vaskob26d09d2022-08-22 09:52:19 +02007 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
Radek Krejcid3ca0632019-04-16 16:54:54 +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
Radek Krejci535ea9f2020-05-29 16:01:05 +020016#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020017
Michal Vaskoa0ba01e2022-10-19 13:26:57 +020018#include <assert.h>
Radek Krejci693262f2019-04-29 15:23:20 +020019#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020020#include <stdint.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010024#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020025
Radek Krejciaa45bda2020-07-20 07:43:38 +020026#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020027#include "log.h"
Michal Vasko8f702ee2024-02-20 15:44:24 +010028#include "ly_common.h"
Radek Krejci47fab892020-11-05 17:02:41 +010029#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020030#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010031#include "plugins_exts.h"
Radek Krejci47fab892020-11-05 17:02:41 +010032#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020033#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020034#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020035#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020036#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020037#include "tree_schema.h"
38#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020039#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020040
Radek Krejcie7b95092019-05-15 11:03:07 +020041/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010042 * @brief Types of the YANG printers
43 */
44enum lys_ypr_schema_type {
45 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
46 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
47};
48
Michal Vasko72c6d642024-02-27 14:59:01 +010049enum lys_ypr_text_flags {
50 LYS_YPR_TEXT_SINGLELINE = 0x01, /**< print 'text' on the same line as 'name' */
51 LYS_YPR_TEXT_SINGLEQUOTED = 0x02 /**< do not encode 'text' and print it in single quotes */
52};
53
Radek Krejciaa14a0c2020-09-04 11:16:47 +020054#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
55
Michal Vasko61ad1ff2022-02-10 15:48:39 +010056#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
57#define YPR_EXTRA_LINE_PRINT(PCTX) \
58 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
59 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020060 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010061 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020062 } \
63 }
64
Michal Vasko72c6d642024-02-27 14:59:01 +010065#define YPR_IS_LYS_SINGLEQUOTED(FLAGS) (((FLAGS) & LYS_SINGLEQUOTED) ? 1 : 0)
66
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010067/**
68 * @brief Compiled YANG printer context
69 *
70 * Note that the YANG extensions API provides getter to the members for the extension plugins.
71 */
72struct lys_ypr_ctx {
73 union {
74 struct {
75 struct ly_out *out; /**< output specification */
76 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020077 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010078 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
79 const struct lys_module *module; /**< schema to print */
80 };
81 struct lyspr_ctx printer_ctx;
82 };
83
84 /* YANG printer specific members */
85 enum lys_ypr_schema_type schema; /**< type of the schema to print */
86};
87
88/**
Radek Krejcie7b95092019-05-15 11:03:07 +020089 * @brief Print the given text as content of a double quoted YANG string,
90 * including encoding characters that have special meanings. The quotation marks
91 * are not printed.
92 *
93 * Follows RFC 7950, section 6.1.3.
94 *
95 * @param[in] out Output specification.
96 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020097 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020098 * the @p text is printed completely as a NULL-terminated string.
99 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200100static void
Radek Krejci1deb5be2020-08-26 16:43:36 +0200101ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200102{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200103 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200104 const char *start;
105 char special = 0;
106
107 if (!len) {
108 return;
109 }
110
111 if (len < 0) {
112 len = strlen(text);
113 }
114
115 start = text;
116 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200117 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200118 switch (text[i]) {
119 case '\n':
120 case '\t':
121 case '\"':
122 case '\\':
123 special = text[i];
124 break;
125 default:
126 ++start_len;
127 break;
128 }
129
130 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200131 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200132 switch (special) {
133 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200134 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200135 break;
136 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200137 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200138 break;
139 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200140 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200141 break;
142 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200143 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200144 break;
145 }
146
147 start += start_len + 1;
148 start_len = 0;
149
150 special = 0;
151 }
152 }
153
Michal Vasko5233e962020-08-14 14:26:20 +0200154 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200155}
156
157static void
Radek Krejci857189e2020-09-01 13:26:36 +0200158ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200159{
160 if (flag && !*flag) {
161 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200162 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 }
164}
165
166static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100167ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200168{
169 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100170 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200171 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100172 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200173 }
174}
175
176static void
Michal Vaskob4b45822024-04-17 09:51:37 +0200177ypr_text_squote_line(struct lys_ypr_ctx *pctx, const char *text, int text_len)
178{
179 const char *end = text + text_len, *squote;
180 int squote_len;
181
182 while ((text != end) && (squote = ly_strnchr(text, '\'', end - text))) {
183 /* before squote */
184 ly_print_(pctx->out, "%.*s", (int)(squote - text), text);
185
186 /* specially-encoded squote(s) */
187 squote_len = 0;
188 do {
189 ++squote_len;
190 } while ((squote + squote_len != end) && (squote[squote_len] == '\''));
191 ly_print_(pctx->out, "' + \"%.*s\" +\n%*s'", squote_len, squote, INDENT);
192
193 /* next iter */
194 text = squote + squote_len;
195 }
196
197 ly_print_(pctx->out, "%.*s", (int)(end - text), text);
198}
199
200static void
Michal Vasko72c6d642024-02-27 14:59:01 +0100201ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, enum lys_ypr_text_flags flags)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200202{
Michal Vaskob4b45822024-04-17 09:51:37 +0200203 const char *nl, *t;
Michal Vasko72c6d642024-02-27 14:59:01 +0100204 char quot;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200205
Michal Vasko72c6d642024-02-27 14:59:01 +0100206 if (flags & LYS_YPR_TEXT_SINGLEQUOTED) {
207 quot = '\'';
Michal Vaskob4b45822024-04-17 09:51:37 +0200208 if (strchr(text, '\'')) {
209 /* need to encode single quotes specially, split to several lines */
210 flags &= ~LYS_YPR_TEXT_SINGLELINE;
211 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100212 } else {
213 quot = '\"';
214 }
215
Michal Vaskob4b45822024-04-17 09:51:37 +0200216 /* statement name and quote */
Michal Vasko72c6d642024-02-27 14:59:01 +0100217 if (flags & LYS_YPR_TEXT_SINGLELINE) {
218 ly_print_(pctx->out, "%*s%s %c", INDENT, name, quot);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200219 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100220 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200221 LEVEL++;
222
Michal Vasko72c6d642024-02-27 14:59:01 +0100223 ly_print_(pctx->out, "%*s%c", INDENT, quot);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200224 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100225
Michal Vaskob4b45822024-04-17 09:51:37 +0200226 /* text with newlines */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200227 t = text;
Michal Vaskob4b45822024-04-17 09:51:37 +0200228 while ((nl = strchr(t, '\n'))) {
Michal Vasko72c6d642024-02-27 14:59:01 +0100229 if (flags & LYS_YPR_TEXT_SINGLEQUOTED) {
Michal Vaskob4b45822024-04-17 09:51:37 +0200230 ypr_text_squote_line(pctx, t, nl - t);
Michal Vasko72c6d642024-02-27 14:59:01 +0100231 } else {
Michal Vaskob4b45822024-04-17 09:51:37 +0200232 ypr_encode(pctx->out, t, nl - t);
Michal Vasko72c6d642024-02-27 14:59:01 +0100233 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100234 ly_print_(pctx->out, "\n");
Michal Vasko72c6d642024-02-27 14:59:01 +0100235
Michal Vaskob4b45822024-04-17 09:51:37 +0200236 t = nl + 1;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200237 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100238 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200239 }
240 }
241
Michal Vaskob4b45822024-04-17 09:51:37 +0200242 /* finish text and the last quote */
Michal Vasko72c6d642024-02-27 14:59:01 +0100243 if (flags & LYS_YPR_TEXT_SINGLEQUOTED) {
Michal Vaskob4b45822024-04-17 09:51:37 +0200244 ypr_text_squote_line(pctx, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200245 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +0100246 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200247 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100248 ly_print_(pctx->out, "%c", quot);
249 if (!(flags & LYS_YPR_TEXT_SINGLELINE)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200250 LEVEL--;
251 }
252}
253
254static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100255yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200256{
257 struct lysp_stmt *childstmt;
Michal Vasko72c6d642024-02-27 14:59:01 +0100258 uint16_t tflags = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200259
260 if (stmt->arg) {
261 if (stmt->flags) {
Michal Vasko72c6d642024-02-27 14:59:01 +0100262 if (stmt->flags & LYS_SINGLEQUOTED) {
263 tflags |= LYS_YPR_TEXT_SINGLEQUOTED;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200264 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100265 ypr_text(pctx, stmt->stmt, stmt->arg, tflags);
266 ly_print_(pctx->out, "%s", stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200267 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100268 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200269 }
270 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100271 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200272 }
273
274 if (stmt->child) {
275 LEVEL++;
276 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100277 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200278 }
279 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100280 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 }
282}
283
Radek Krejcid3ca0632019-04-16 16:54:54 +0200284static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200285yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
286 struct lysp_ext_instance *ext, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200287{
Radek Krejcid3ca0632019-04-16 16:54:54 +0200288 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200289 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200290
Michal Vaskob26d09d2022-08-22 09:52:19 +0200291 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
292 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200293 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100294
Michal Vaskob26d09d2022-08-22 09:52:19 +0200295 ypr_open(pctx->out, flag);
296
Michal Vasko193dacd2022-10-13 08:43:05 +0200297 if (ext->def->argname) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200298 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200299 ypr_encode(pctx->out, ext->argument, -1);
300 ly_print_(pctx->out, "\"");
301 } else {
302 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
303 }
304
305 child_presence = 0;
306 LEVEL++;
307 LY_LIST_FOR(ext->child, stmt) {
308 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200309 continue;
310 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200311 if (!child_presence) {
312 ly_print_(pctx->out, " {\n");
313 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200314 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200315 yprp_stmt(pctx, stmt);
316 }
317 LEVEL--;
318 if (child_presence) {
319 ly_print_(pctx->out, "%*s}\n", INDENT);
320 } else {
321 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200322 }
323}
324
Radek Krejci693262f2019-04-29 15:23:20 +0200325static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200326yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
327 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200328{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200329 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200330
331 LY_ARRAY_FOR(exts, u) {
aPiecek6cf1d162023-11-08 16:07:00 +0100332 if (exts[u].flags & LYS_INTERNAL) {
333 continue;
334 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200335 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
336 }
337}
338
aPiecek6cf1d162023-11-08 16:07:00 +0100339static ly_bool
340yprp_extension_has_printable_instances(struct lysp_ext_instance *exts)
341{
342 LY_ARRAY_COUNT_TYPE u;
343
344 LY_ARRAY_FOR(exts, u) {
345 if (!(exts[u].flags & LYS_INTERNAL)) {
346 return 1;
347 }
348 }
349
350 return 0;
351}
352
Michal Vaskob26d09d2022-08-22 09:52:19 +0200353static void
354yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
355 struct lysc_ext_instance *exts, ly_bool *flag)
356{
357 LY_ARRAY_COUNT_TYPE u;
358 ly_bool inner_flag;
359
360 LY_ARRAY_FOR(exts, u) {
361 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
362 return;
363 }
364
365 ypr_open(pctx->out, flag);
366 if (exts[u].argument) {
367 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
368 ypr_encode(pctx->out, exts[u].argument, -1);
369 ly_print_(pctx->out, "\"");
370 } else {
371 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
372 }
373
374 LEVEL++;
375 inner_flag = 0;
376 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
377
Michal Vasko941e0562022-10-18 10:35:00 +0200378 if (exts[u].def->plugin && exts[u].def->plugin->printer_info) {
379 exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200380 }
381
382 LEVEL--;
383 ypr_close(pctx, inner_flag);
384 }
385}
386
387static void
Michal Vasko72c6d642024-02-27 14:59:01 +0100388ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text,
389 ly_bool singlequoted, void *exts)
Michal Vaskob26d09d2022-08-22 09:52:19 +0200390{
Radek Krejci857189e2020-09-01 13:26:36 +0200391 ly_bool extflag = 0;
Michal Vasko72c6d642024-02-27 14:59:01 +0100392 uint16_t flags = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393
394 if (!text) {
395 /* nothing to print */
396 return;
397 }
398
Michal Vaskob872d0f2022-12-08 09:36:54 +0100399 if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) {
400 ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200401 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +0100402 if (!(lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN)) {
403 flags |= LYS_YPR_TEXT_SINGLELINE;
404 }
405 if (singlequoted) {
406 flags |= LYS_YPR_TEXT_SINGLEQUOTED;
407 }
408 ypr_text(pctx, lys_stmt_str(substmt), text, flags);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200409 }
410
411 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200412 if (pctx->schema == LYS_YPR_PARSED) {
413 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
414 } else {
415 yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416 }
417 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100418 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200419}
420
421static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100422ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
Michal Vasko2bf4af42023-01-04 12:08:38 +0100423 unsigned long attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200424{
425 char *str;
426
Radek Krejci1deb5be2020-08-26 16:43:36 +0200427 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429 return;
430 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100431 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100432 ypr_substmt(pctx, substmt, substmt_index, str, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433 free(str);
434}
435
436static void
Michal Vasko2bf4af42023-01-04 12:08:38 +0100437ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value,
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100438 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439{
440 char *str;
441
Radek Krejci1deb5be2020-08-26 16:43:36 +0200442 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100443 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444 return;
445 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100446 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100447 ypr_substmt(pctx, substmt, substmt_index, str, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200448 free(str);
449}
450
451static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100452yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453{
454 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100455 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200456 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200457 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +0100458 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, 0, rev->exts);
459 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, 0, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200460 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100461 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200462 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100463 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464 }
465}
466
467static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100468ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200469{
470 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100471 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100472 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200473 }
474}
475
476static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100477ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478{
479 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100480 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100481 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200482 }
483}
484
485static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100486ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200487{
488 const char *status = NULL;
489
490 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100491 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200492 status = "current";
493 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100494 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200495 status = "deprecated";
496 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100497 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200498 status = "obsolete";
499 }
Radek Krejci693262f2019-04-29 15:23:20 +0200500
Michal Vasko72c6d642024-02-27 14:59:01 +0100501 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200502}
503
504static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100505ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200506{
507 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100508 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100509 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200510 }
511}
512
513static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100514ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200515{
516 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100517 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100518 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200519 }
520}
521
522static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100523yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200524{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200525 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200526 ly_bool extflag;
Michal Vasko72c6d642024-02-27 14:59:01 +0100527 uint16_t flags;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200528
Michal Vasko7f45cf22020-10-01 12:49:44 +0200529 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100530 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531 extflag = 0;
532
Michal Vasko659f8fa2024-02-27 15:20:34 +0100533 flags = LYS_YPR_TEXT_SINGLELINE | ((iffs[u].flags & LYS_SINGLEQUOTED) ? LYS_YPR_TEXT_SINGLEQUOTED : 0);
Michal Vasko72c6d642024-02-27 14:59:01 +0100534 ypr_text(pctx, "if-feature", iffs[u].str, flags);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535
536 /* extensions */
537 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200538 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200539 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100540 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200541 }
542}
543
544static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100545yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200546{
Radek Krejci857189e2020-09-01 13:26:36 +0200547 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200548 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200549
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100550 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200551 LEVEL++;
552
Michal Vaskob26d09d2022-08-22 09:52:19 +0200553 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200554
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100555 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100556 ypr_open(pctx->out, &flag);
557 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200558 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200559 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200560 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100561 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200562 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200564 }
565 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100566 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100567 ypr_open(pctx->out, &flag2);
Michal Vasko72c6d642024-02-27 14:59:01 +0100568 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", 0, ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200569 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200570 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100571 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200572 }
573
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100574 ypr_status(pctx, ext->flags, ext->exts, &flag);
575 ypr_description(pctx, ext->dsc, ext->exts, &flag);
576 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200577
578 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100579 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200580}
581
582static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100583yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200584{
Radek Krejci857189e2020-09-01 13:26:36 +0200585 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200586
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100587 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200588 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200589 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100590 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
591 ypr_status(pctx, feat->flags, feat->exts, &flag);
592 ypr_description(pctx, feat->dsc, feat->exts, &flag);
593 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200594 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100595 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200596}
597
598static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100599yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200600{
Radek Krejci857189e2020-09-01 13:26:36 +0200601 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200602 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200603
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100604 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200605 LEVEL++;
606
Michal Vaskob26d09d2022-08-22 09:52:19 +0200607 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100608 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200609
610 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100611 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100612 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], 0, ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613 }
614
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100615 ypr_status(pctx, ident->flags, ident->exts, &flag);
616 ypr_description(pctx, ident->dsc, ident->exts, &flag);
617 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200618
619 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100620 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200621}
622
623static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100624yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200625{
Radek Krejci857189e2020-09-01 13:26:36 +0200626 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200627 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200628
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100629 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200630 LEVEL++;
631
Michal Vaskob26d09d2022-08-22 09:52:19 +0200632 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200633
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100634 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200635 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100636 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200637 }
638
Radek Krejci693262f2019-04-29 15:23:20 +0200639 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100640 if (pctx->module != ident->derived[u]->module) {
641 ly_print_(pctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200642 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100643 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200644 }
645 }
646
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100647 ypr_status(pctx, ident->flags, ident->exts, &flag);
648 ypr_description(pctx, ident->dsc, ident->exts, &flag);
649 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200650
651 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100652 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200653}
654
655static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100656yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200657{
Michal Vasko72c6d642024-02-27 14:59:01 +0100658 ly_bool inner_flag = 0;
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100659 const char *text;
Michal Vasko72c6d642024-02-27 14:59:01 +0100660 uint16_t flags = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200661
662 if (!restr) {
663 return;
664 }
665
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100666 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100667 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
668 restr->arg.str : restr->arg.str + 1;
Michal Vasko72c6d642024-02-27 14:59:01 +0100669 if (!strchr(text, '\n')) {
670 flags |= LYS_YPR_TEXT_SINGLELINE;
671 }
672 if (restr->arg.flags & LYS_SINGLEQUOTED) {
673 flags |= LYS_YPR_TEXT_SINGLEQUOTED;
674 }
675 ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, flags);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200676
677 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200678 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100679 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200680 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100681 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100682 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200683 }
684 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100685 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100686 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, 0, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200687 }
688 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100689 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100690 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, 0, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200691 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100692 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
693 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200694
Radek Krejcid3ca0632019-04-16 16:54:54 +0200695 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100696 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200697}
698
699static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100700yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200701{
Radek Krejci857189e2020-09-01 13:26:36 +0200702 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200703
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100704 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100705 ypr_text(pctx, "must", must->cond->expr, LYS_YPR_TEXT_SINGLELINE);
Radek Krejci693262f2019-04-29 15:23:20 +0200706
707 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200708 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200709 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100710 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100711 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, 0, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200712 }
713 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100714 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100715 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, 0, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200716 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100717 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
718 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200719
720 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100721 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200722}
723
724static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100725yprc_range(struct lys_ypr_ctx *pctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200726{
Radek Krejci857189e2020-09-01 13:26:36 +0200727 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200728 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200729
Radek Krejci334ccc72019-06-12 13:49:29 +0200730 if (!range) {
731 return;
732 }
733
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100734 ypr_open(pctx->out, flag);
735 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200736 LY_ARRAY_FOR(range->parts, u) {
737 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100738 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200739 }
740 if (range->parts[u].max_64 == range->parts[u].min_64) {
741 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100742 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200743 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100744 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200745 }
746 } else {
747 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100748 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200749 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100750 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200751 }
752 }
753 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100754 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200755
756 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200757 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200758 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100759 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100760 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, 0, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200761 }
762 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100763 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100764 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, 0, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200765 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100766 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
767 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200768
769 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100770 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200771}
772
773static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100774yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200775{
Radek Krejci857189e2020-09-01 13:26:36 +0200776 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200777
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778 ypr_open(pctx->out, flag);
779 ly_print_(pctx->out, "%*spattern \"", INDENT);
780 ypr_encode(pctx->out, pattern->expr, -1);
781 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200782
783 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200784 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200785 if (pattern->inverted) {
786 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100787 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100788 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200789 }
790 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100791 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100792 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, 0, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200793 }
794 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100795 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100796 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, 0, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200797 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100798 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
799 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200800
801 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100802 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200803}
804
805static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200806yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag)
807{
808 LY_ARRAY_COUNT_TYPE u;
809 const struct lysc_type_bitenum_item *item;
810 ly_bool inner_flag;
811
812 assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM));
813
814 LY_ARRAY_FOR(items, u) {
815 item = &items[u];
816 inner_flag = 0;
817
818 ypr_open(pctx->out, flag);
819 ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum");
820 ypr_encode(pctx->out, item->name, -1);
821 ly_print_(pctx->out, "\"");
822 LEVEL++;
823 if (basetype == LY_TYPE_BITS) {
824 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
825 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
826 } else { /* LY_TYPE_ENUM */
827 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
828 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
829 }
830 ypr_status(pctx, item->flags, item->exts, &inner_flag);
831 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
832 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
833 LEVEL--;
834 ypr_close(pctx, inner_flag);
835 }
836}
837
838static void
839yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840{
Radek Krejci857189e2020-09-01 13:26:36 +0200841 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842
843 if (!when) {
844 return;
845 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100846 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200847
Michal Vasko72c6d642024-02-27 14:59:01 +0100848 ypr_text(pctx, "when", when->cond, LYS_YPR_TEXT_SINGLELINE);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200849
850 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200851 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100852 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
853 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200854 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100855 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200856}
857
858static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200859yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200860{
Radek Krejci857189e2020-09-01 13:26:36 +0200861 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200862
863 if (!when) {
864 return;
865 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100866 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200867
Michal Vasko72c6d642024-02-27 14:59:01 +0100868 ypr_text(pctx, "when", when->cond->expr, LYS_YPR_TEXT_SINGLELINE);
Radek Krejci693262f2019-04-29 15:23:20 +0200869
870 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200871 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100872 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
873 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200874 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100875 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200876}
877
878static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200879yprp_bits_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200880{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200881 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200882 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200883
884 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100885 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200886 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100887 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200888 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100889 ly_print_(pctx->out, "%*senum \"", INDENT);
890 ypr_encode(pctx->out, items[u].name, -1);
891 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200892 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200893 inner_flag = 0;
894 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200895 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100896 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200897 if (items[u].flags & LYS_SET_VALUE) {
898 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100899 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200900 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100901 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200902 }
903 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100904 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
905 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
906 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200907 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100908 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200909 }
910}
911
912static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100913yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200914{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200915 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200916 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200917
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100918 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200919 LEVEL++;
920
Michal Vaskob26d09d2022-08-22 09:52:19 +0200921 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200922
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100923 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
924 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200925 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100926 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200927 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200928 yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
929 yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200930
931 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100932 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100933 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, 0, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200934 }
935 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100936 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100937 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", 0, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200938 }
939 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100940 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200941 }
942 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100943 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100944 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], 0, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200945 }
946 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100947 ypr_open(pctx->out, &flag);
948 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200949 }
950
951 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100952 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200953}
954
955static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100956yprc_dflt_value(struct lys_ypr_ctx *pctx, const struct ly_ctx *ly_pctx, const struct lyd_value *value,
Radek Krejci224d4b42021-04-23 13:54:59 +0200957 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200958{
Radek Krejci857189e2020-09-01 13:26:36 +0200959 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200960 const char *str;
961
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100962 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +0100963 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, 0, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200964 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200965 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200966 }
967}
968
969static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100970yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200971{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200972 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200973 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200974
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100975 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200976 LEVEL++;
977
Michal Vaskob26d09d2022-08-22 09:52:19 +0200978 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200979
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200980 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200981 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200982 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200983
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100984 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200985 break;
986 }
987 case LY_TYPE_UINT8:
988 case LY_TYPE_UINT16:
989 case LY_TYPE_UINT32:
990 case LY_TYPE_UINT64:
991 case LY_TYPE_INT8:
992 case LY_TYPE_INT16:
993 case LY_TYPE_INT32:
994 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200995 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200996
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100997 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200998 break;
999 }
1000 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001001 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001002
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001003 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001004 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001005 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001006 }
1007 break;
1008 }
1009 case LY_TYPE_BITS:
1010 case LY_TYPE_ENUM: {
1011 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +02001012 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001013
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02001014 yprc_bits_enum(pctx, bits->bits, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001015 break;
1016 }
1017 case LY_TYPE_BOOL:
1018 case LY_TYPE_EMPTY:
1019 /* nothing to do */
1020 break;
1021 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001022 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001023
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001024 ypr_open(pctx->out, &flag);
1025 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
1026 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001027 break;
1028 }
1029 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001030 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001031
Radek Krejci693262f2019-04-29 15:23:20 +02001032 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001033 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001034 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, 0, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001035 }
1036 break;
1037 }
1038 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001039 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001040
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001041 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001042 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", 0, inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001043 break;
1044 }
1045 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001046 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001047
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001048 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001049 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, 0, lr->exts);
1050 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", 0, lr->exts);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001051 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +02001052 break;
1053 }
1054 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001055 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001056
Radek Krejci693262f2019-04-29 15:23:20 +02001057 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001058 ypr_open(pctx->out, &flag);
1059 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02001060 }
1061 break;
1062 }
1063 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001064 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +02001065 }
1066
1067 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001068 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001069}
1070
1071static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001072yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001074 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 LEVEL++;
1076
Michal Vaskob26d09d2022-08-22 09:52:19 +02001077 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001079 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080
1081 if (tpdf->units) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001082 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, 0, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001084 if (tpdf->dflt.str) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001085 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(tpdf->dflt.flags), tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001086 }
1087
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001088 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1089 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1090 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091
1092 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001093 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094}
1095
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001096static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1097static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1098static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1099static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100
1101static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001102yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001103{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001104 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001105 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001107 struct lysp_node_action *action;
1108 struct lysp_node_notif *notif;
1109 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001111 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001112 LEVEL++;
1113
Michal Vaskob26d09d2022-08-22 09:52:19 +02001114 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001115 ypr_status(pctx, grp->flags, grp->exts, &flag);
1116 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1117 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001118
1119 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001120 ypr_open(pctx->out, &flag);
1121 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001122 }
1123
Radek Krejci2a9fc652021-01-22 17:44:34 +01001124 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001125 ypr_open(pctx->out, &flag);
1126 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001127 }
1128
Radek Krejci01180ac2021-01-27 08:48:22 +01001129 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001130 ypr_open(pctx->out, &flag);
1131 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001132 }
1133
Radek Krejci2a9fc652021-01-22 17:44:34 +01001134 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001135 ypr_open(pctx->out, &flag);
1136 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001137 }
1138
1139 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001140 ypr_open(pctx->out, &flag);
1141 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001142 }
1143
1144 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001145 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001146}
1147
1148static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001149yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001150{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001151 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001152 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001153 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154
Radek Krejci01180ac2021-01-27 08:48:22 +01001155 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001156 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001157 return;
1158 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001159 ypr_open(pctx->out, flag);
1160 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001161
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001162 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001163 LEVEL++;
1164
Michal Vaskob26d09d2022-08-22 09:52:19 +02001165 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001166 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001167 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001168 }
1169 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001170 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001171 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001172 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001173 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001174 }
1175
Radek Krejci01180ac2021-01-27 08:48:22 +01001176 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001177 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001178 }
1179
1180 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001181 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001182}
1183
1184static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001185yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001186{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001187 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001188 struct lysc_node *data;
1189
Radek Krejci01180ac2021-01-27 08:48:22 +01001190 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001191 /* input/output is empty */
1192 return;
1193 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001194 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001195
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001196 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001197 LEVEL++;
1198
Michal Vasko193dacd2022-10-13 08:43:05 +02001199 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001200 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001202 }
1203
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001204 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001205 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001206 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001207 }
Radek Krejci693262f2019-04-29 15:23:20 +02001208 }
1209
1210 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001211 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001212}
1213
1214static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001215yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001216{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001217 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001218 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001219 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001220 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001221
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001222 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001223
1224 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001225 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001226 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001227
1228 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001229 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001230 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001231 ypr_status(pctx, notif->flags, notif->exts, &flag);
1232 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1233 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234
1235 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001236 ypr_open(pctx->out, &flag);
1237 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001238 }
1239
Radek Krejci2a9fc652021-01-22 17:44:34 +01001240 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001241 ypr_open(pctx->out, &flag);
1242 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001243 }
1244
Radek Krejci01180ac2021-01-27 08:48:22 +01001245 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001246 ypr_open(pctx->out, &flag);
1247 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248 }
1249
1250 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001251 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001252}
1253
1254static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001255yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001256{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001257 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001258 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001259 struct lysc_node *data;
1260
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001261 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001262
1263 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001264 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001265
1266 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001267 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001268 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001269 ypr_status(pctx, notif->flags, notif->exts, &flag);
1270 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1271 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001272
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001273 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001274 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001275 ypr_open(pctx->out, &flag);
1276 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001277 }
Radek Krejci693262f2019-04-29 15:23:20 +02001278 }
1279
1280 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001281 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001282}
1283
1284static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001285yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001287 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001288 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001289 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001290
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001291 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292
1293 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001294 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001295 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1296 ypr_status(pctx, action->flags, action->exts, &flag);
1297 ypr_description(pctx, action->dsc, action->exts, &flag);
1298 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001299
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001300 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001301
Radek Krejcid3ca0632019-04-16 16:54:54 +02001302 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001303 ypr_open(pctx->out, &flag);
1304 YPR_EXTRA_LINE_PRINT(pctx);
1305 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001306 }
1307
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001308 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001309
Radek Krejci2a9fc652021-01-22 17:44:34 +01001310 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001311 ypr_open(pctx->out, &flag);
1312 YPR_EXTRA_LINE_PRINT(pctx);
1313 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001314 }
1315
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001316 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001317
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001318 yprp_inout(pctx, &action->input, &flag);
1319 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001320
1321 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001322 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001323}
1324
1325static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001326yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001327{
Radek Krejci857189e2020-09-01 13:26:36 +02001328 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001329
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001330 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001331
1332 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001333 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001334 ypr_status(pctx, action->flags, action->exts, &flag);
1335 ypr_description(pctx, action->dsc, action->exts, &flag);
1336 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001337
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001338 yprc_inout(pctx, &action->input, &flag);
1339 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001340
1341 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001342 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001343}
1344
1345static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001346yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001347{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001348 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001349 LEVEL++;
1350
Michal Vasko193dacd2022-10-13 08:43:05 +02001351 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001352 yprp_when(pctx, lysp_node_when(node), flag);
1353 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001354}
1355
1356static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001357yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001358{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001359 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001360 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001361
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001362 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001363 LEVEL++;
1364
Michal Vasko193dacd2022-10-13 08:43:05 +02001365 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001366
1367 when = lysc_node_when(node);
1368 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001369 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001370 }
Radek Krejci693262f2019-04-29 15:23:20 +02001371}
1372
Michal Vaskob26d09d2022-08-22 09:52:19 +02001373/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001374#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001375 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001376 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001377 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001378 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001379 ypr_status(pctx, node->flags, node->exts, flag); \
1380 ypr_description(pctx, node->dsc, node->exts, flag); \
1381 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001382
1383static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001384yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001385{
1386 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001387}
1388
1389static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001390yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001391{
1392 YPR_NODE_COMMON2;
1393}
1394
1395#undef YPR_NODE_COMMON2
1396
1397static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001398yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001399{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001400 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001401 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001402 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001403 struct lysp_node_action *action;
1404 struct lysp_node_notif *notif;
1405 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001406 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1407
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001408 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001409
1410 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001411 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001412 }
1413 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001414 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001415 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, 0, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001416 }
1417
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001418 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001419
1420 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001421 ypr_open(pctx->out, &flag);
1422 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001423 }
1424
Radek Krejci2a9fc652021-01-22 17:44:34 +01001425 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001426 ypr_open(pctx->out, &flag);
1427 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001428 }
1429
1430 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001431 ypr_open(pctx->out, &flag);
1432 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001433 }
1434
Radek Krejci2a9fc652021-01-22 17:44:34 +01001435 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001436 ypr_open(pctx->out, &flag);
1437 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001438 }
1439
Radek Krejci2a9fc652021-01-22 17:44:34 +01001440 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001441 ypr_open(pctx->out, &flag);
1442 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001443 }
1444
1445 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001446 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001447}
1448
1449static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001450yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001451{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001452 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001453 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001454 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001455 struct lysc_node_action *action;
1456 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001457 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1458
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001459 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001460
1461 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001462 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001463 }
1464 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001465 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001466 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", 0, cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001467 }
1468
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001469 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001470
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001471 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001472 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001473 ypr_open(pctx->out, &flag);
1474 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001475 }
Radek Krejci693262f2019-04-29 15:23:20 +02001476
Radek Krejci2a9fc652021-01-22 17:44:34 +01001477 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001478 ypr_open(pctx->out, &flag);
1479 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001480 }
Radek Krejci693262f2019-04-29 15:23:20 +02001481
Radek Krejci2a9fc652021-01-22 17:44:34 +01001482 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001483 ypr_open(pctx->out, &flag);
1484 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001485 }
Radek Krejci693262f2019-04-29 15:23:20 +02001486 }
1487
1488 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001489 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001490}
1491
1492static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001493yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001494{
Radek Krejci857189e2020-09-01 13:26:36 +02001495 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001496 struct lysp_node *child;
1497 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1498
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001499 yprp_node_common1(pctx, node, &flag);
1500 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001501
1502 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001503 ypr_open(pctx->out, &flag);
1504 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001505 }
1506
1507 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001508 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001509}
1510
1511static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001512yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001513{
Radek Krejci857189e2020-09-01 13:26:36 +02001514 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001515 struct lysc_node *child;
1516
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001517 yprc_node_common1(pctx, &cs->node, &flag);
1518 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001519
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001520 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001521 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001522 ypr_open(pctx->out, &flag);
1523 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001524 }
Radek Krejci693262f2019-04-29 15:23:20 +02001525 }
1526
1527 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001528 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001529}
1530
1531static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001532yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001533{
Radek Krejci857189e2020-09-01 13:26:36 +02001534 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001535 struct lysp_node *child;
1536 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1537
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001538 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001539
Michal Vasko7f45cf22020-10-01 12:49:44 +02001540 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001541 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001542 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, YPR_IS_LYS_SINGLEQUOTED(choice->dflt.flags), choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001543 }
1544
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001545 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001546
1547 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001548 ypr_open(pctx->out, &flag);
1549 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001550 }
1551
1552 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001553 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554}
1555
1556static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001557yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001558{
Radek Krejci857189e2020-09-01 13:26:36 +02001559 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001560 struct lysc_node_case *cs;
1561 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1562
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001563 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001564
1565 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001566 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001567 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, 0, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001568 }
1569
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001570 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001571
Michal Vasko22df3f02020-08-24 13:29:22 +02001572 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001573 ypr_open(pctx->out, &flag);
1574 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001575 }
1576
1577 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001578 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001579}
1580
1581static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001582yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001584 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001585 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1586
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001587 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001588
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001589 yprp_type(pctx, &leaf->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001590 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001591 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001592 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001593 }
Michal Vasko72c6d642024-02-27 14:59:01 +01001594 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(leaf->dflt.flags), leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001595
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001596 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001597
1598 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001599 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600}
1601
1602static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001603yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001604{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001605 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001606 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1607
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001608 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001609
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001610 yprc_type(pctx, leaf->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001611 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001612 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001613 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001614 }
Radek Krejcia1911222019-07-22 17:24:50 +02001615
1616 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001617 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001618 }
Radek Krejci693262f2019-04-29 15:23:20 +02001619
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001620 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001621
1622 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001623 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001624}
1625
1626static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001627yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001628{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001629 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001630 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1631
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001632 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001634 yprp_type(pctx, &llist->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001635 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001636 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001637 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638 }
1639 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001640 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(llist->dflts[u].flags),
1641 llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001642 }
1643
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001644 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001645
1646 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001647 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001648 }
1649 if (llist->flags & LYS_SET_MAX) {
1650 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001651 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001653 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654 }
1655 }
1656
1657 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001658 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001661 ypr_status(pctx, node->flags, node->exts, NULL);
1662 ypr_description(pctx, node->dsc, node->exts, NULL);
1663 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001664
1665 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001666 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001667}
1668
1669static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001670yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001671{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001672 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001673 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1674
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001675 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001676
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001677 yprc_type(pctx, llist->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001678 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001679 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001680 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001681 }
1682 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001683 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001684 }
1685
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001686 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001687
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001688 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001689 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001690 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001691 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001692 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001693 }
1694
Michal Vasko72c6d642024-02-27 14:59:01 +01001695 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001696
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001697 ypr_status(pctx, node->flags, node->exts, NULL);
1698 ypr_description(pctx, node->dsc, node->exts, NULL);
1699 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001700
1701 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001702 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001703}
1704
1705static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001706yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001707{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001708 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001709 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001710 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001711 struct lysp_node_action *action;
1712 struct lysp_node_notif *notif;
1713 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001714 struct lysp_node_list *list = (struct lysp_node_list *)node;
1715
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001716 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001717
1718 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001719 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001720 }
1721 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001722 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001723 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, 0, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001724 }
1725 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001726 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001727 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(list->uniques[u].flags),
1728 list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001729 }
1730
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001731 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001732
1733 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001734 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001735 }
1736 if (list->flags & LYS_SET_MAX) {
1737 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001738 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001739 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001740 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001741 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001742 }
1743 }
1744
1745 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001746 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001747 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001748 }
1749
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001750 ypr_status(pctx, node->flags, node->exts, &flag);
1751 ypr_description(pctx, node->dsc, node->exts, &flag);
1752 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001753
1754 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001755 ypr_open(pctx->out, &flag);
1756 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001757 }
1758
Radek Krejci2a9fc652021-01-22 17:44:34 +01001759 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001760 ypr_open(pctx->out, &flag);
1761 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001762 }
1763
1764 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001765 ypr_open(pctx->out, &flag);
1766 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001767 }
1768
Radek Krejci2a9fc652021-01-22 17:44:34 +01001769 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001770 ypr_open(pctx->out, &flag);
1771 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001772 }
1773
Radek Krejci2a9fc652021-01-22 17:44:34 +01001774 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001775 ypr_open(pctx->out, &flag);
1776 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001777 }
1778
1779 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001780 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781}
1782
1783static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001784yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001785{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001786 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001787 struct lysc_node_list *list = (struct lysc_node_list *)node;
1788
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001789 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001790
1791 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001792 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001793 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001794 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001795 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001796 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001797 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001798 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001799 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001800 }
1801 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001802 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001803 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001804 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001805 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001806 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001807 }
1808
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001809 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001810
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001811 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001812 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001813 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001814 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001815 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001816 }
1817
Michal Vasko72c6d642024-02-27 14:59:01 +01001818 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001819
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001820 ypr_status(pctx, node->flags, node->exts, NULL);
1821 ypr_description(pctx, node->dsc, node->exts, NULL);
1822 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001823
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001824 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001825 struct lysc_node *child;
1826 struct lysc_node_action *action;
1827 struct lysc_node_notif *notif;
1828
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001829 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001830 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001831 }
Radek Krejci693262f2019-04-29 15:23:20 +02001832
Radek Krejci2a9fc652021-01-22 17:44:34 +01001833 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001834 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001835 }
Radek Krejci693262f2019-04-29 15:23:20 +02001836
Radek Krejci2a9fc652021-01-22 17:44:34 +01001837 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001838 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001839 }
Radek Krejci693262f2019-04-29 15:23:20 +02001840 }
1841
1842 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001843 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001844}
1845
1846static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001847yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001848{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001849 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001850 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001852 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853 LEVEL++;
1854
Michal Vaskob26d09d2022-08-22 09:52:19 +02001855 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001856 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001857
1858 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001859 ypr_open(pctx->out, &flag);
1860 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861 }
1862
1863 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001864 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001865 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, 0, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866 }
1867
1868 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001869 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001870 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(refine->dflts[u].flags),
1871 refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872 }
1873
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001874 ypr_config(pctx, refine->flags, refine->exts, &flag);
1875 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001876
1877 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001878 ypr_open(pctx->out, &flag);
1879 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880 }
1881 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001882 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001883 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001884 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001886 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887 }
1888 }
1889
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001890 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1891 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001892
1893 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001894 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001895}
1896
1897static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001898yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001901 struct lysp_node_action *action;
1902 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001904 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001905 LEVEL++;
1906
Michal Vaskob26d09d2022-08-22 09:52:19 +02001907 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001908 yprp_when(pctx, aug->when, NULL);
1909 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1910 ypr_status(pctx, aug->flags, aug->exts, NULL);
1911 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1912 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001913
1914 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001915 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 }
1917
Radek Krejci2a9fc652021-01-22 17:44:34 +01001918 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001919 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 }
1921
Radek Krejci2a9fc652021-01-22 17:44:34 +01001922 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001923 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001924 }
1925
1926 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001927 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928}
1929
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001931yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001932{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001933 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001934 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001935 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001936 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001938 yprp_node_common1(pctx, node, &flag);
1939 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001940
1941 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001942 ypr_open(pctx->out, &flag);
1943 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001944 }
1945
Radek Krejci2a9fc652021-01-22 17:44:34 +01001946 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001947 ypr_open(pctx->out, &flag);
1948 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001949 }
1950
1951 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001952 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001953}
1954
1955static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001956yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001957{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001958 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001959 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001960 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1961
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001962 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963
1964 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001965 ypr_open(pctx->out, &flag);
1966 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001967 }
1968
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001969 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970
1971 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001972 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001973}
1974
1975static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001976yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001977{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001978 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001979 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001980 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001981
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001982 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001983
Radek Krejci693262f2019-04-29 15:23:20 +02001984 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001985 ypr_open(pctx->out, &flag);
1986 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 }
1988
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001989 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001990
Radek Krejcid3ca0632019-04-16 16:54:54 +02001991 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001992 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001993}
1994
1995static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001996yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001997{
1998 switch (node->nodetype) {
1999 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002000 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 break;
2002 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002003 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004 break;
2005 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 break;
2008 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002009 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 break;
2011 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002012 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002013 break;
2014 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002015 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 break;
2017 case LYS_ANYXML:
2018 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002019 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 break;
2021 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002022 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 break;
2024 default:
2025 break;
2026 }
2027}
2028
2029static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002030yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02002031{
2032 switch (node->nodetype) {
2033 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002034 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002035 break;
2036 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002037 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002038 break;
2039 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002040 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002041 break;
2042 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002043 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002044 break;
2045 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002046 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002047 break;
2048 case LYS_ANYXML:
2049 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002050 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002051 break;
2052 default:
2053 break;
2054 }
2055}
2056
2057static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002058yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002059{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002060 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002061 struct lysp_deviate_add *add;
2062 struct lysp_deviate_rpl *rpl;
2063 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08002064 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002065
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002066 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002067 LEVEL++;
2068
Michal Vaskob26d09d2022-08-22 09:52:19 +02002069 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002070 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
2071 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002072
fredgan2b11ddb2019-10-21 11:03:39 +08002073 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002074 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08002075 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
2076 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002077 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002078 LEVEL++;
2079
Michal Vaskob26d09d2022-08-22 09:52:19 +02002080 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002081 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002082 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002083 continue;
2084 }
fredgan2b11ddb2019-10-21 11:03:39 +08002085 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002086 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002087 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002088 LEVEL++;
2089
Michal Vaskob26d09d2022-08-22 09:52:19 +02002090 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002091 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, 0, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002092 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002093 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002094 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002095 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002096 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(add->uniques[u].flags),
2097 add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002098 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002099 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002100 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(add->dflts[u].flags),
2101 add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002103 ypr_config(pctx, add->flags, add->exts, NULL);
2104 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002105 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002106 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002107 }
2108 if (add->flags & LYS_SET_MAX) {
2109 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002110 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002111 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01002112 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002113 }
2114 }
fredgan2b11ddb2019-10-21 11:03:39 +08002115 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002116 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002117 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002118 LEVEL++;
2119
Michal Vaskob26d09d2022-08-22 09:52:19 +02002120 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002121 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002122 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002123 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002124 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, 0, rpl->exts);
2125 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, YPR_IS_LYS_SINGLEQUOTED(rpl->dflt.flags), rpl->exts);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002126 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2127 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002128 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002129 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002130 }
2131 if (rpl->flags & LYS_SET_MAX) {
2132 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002133 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002134 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01002135 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002136 }
2137 }
fredgan2b11ddb2019-10-21 11:03:39 +08002138 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002139 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002140 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002141 LEVEL++;
2142
Michal Vaskob26d09d2022-08-22 09:52:19 +02002143 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002144 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, 0, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002145 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002146 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002148 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002149 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(del->uniques[u].flags),
2150 del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002151 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002152 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002153 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(del->dflts[u].flags),
2154 del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 }
2156 }
2157
2158 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002159 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 }
2161
2162 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002163 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164}
2165
Michal Vasko7c8439f2020-08-05 13:25:19 +02002166static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002167yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002169 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002170
Radek Krejcid3ca0632019-04-16 16:54:54 +02002171 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002172 if (modp->imports[u].flags & LYS_INTERNAL) {
2173 continue;
2174 }
2175
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002176 YPR_EXTRA_LINE_PRINT(pctx);
2177 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002178 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002179 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002180 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, 0, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002181 if (modp->imports[u].rev[0]) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002182 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, 0, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002183 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002184 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, 0, modp->imports[u].exts);
2185 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, 0, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002186 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002187 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002188 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002190
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002192 if (modp->includes[u].injected) {
2193 /* do not print the includes injected from submodules */
2194 continue;
2195 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002196 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002197 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002198 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002199 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002200 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002201 if (modp->includes[u].rev[0]) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002202 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, 0, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002203 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002204 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, 0, modp->includes[u].exts);
2205 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, 0, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002206 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002207 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002208 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002209 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002210 }
2211 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002212 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002213}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002214
Michal Vasko7c8439f2020-08-05 13:25:19 +02002215static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002216yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002217{
2218 LY_ARRAY_COUNT_TYPE u;
2219 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002220 struct lysp_node_action *action;
2221 struct lysp_node_notif *notif;
2222 struct lysp_node_grp *grp;
2223 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002224
Radek Krejcid3ca0632019-04-16 16:54:54 +02002225 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002226 YPR_EXTRA_LINE_PRINT(pctx);
2227 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002228 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002229
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002230 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002231
aPiecek6cf1d162023-11-08 16:07:00 +01002232 if (yprp_extension_has_printable_instances(modp->exts)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002234 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002235 }
2236
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002237 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002238
Radek Krejcid3ca0632019-04-16 16:54:54 +02002239 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002240 YPR_EXTRA_LINE_PRINT(pctx);
2241 yprp_feature(pctx, &modp->features[u]);
2242 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002243 }
2244
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002245 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002246
Radek Krejcid3ca0632019-04-16 16:54:54 +02002247 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002248 YPR_EXTRA_LINE_PRINT(pctx);
2249 yprp_identity(pctx, &modp->identities[u]);
2250 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002251 }
2252
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002253 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002254
Radek Krejcid3ca0632019-04-16 16:54:54 +02002255 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002256 YPR_EXTRA_LINE_PRINT(pctx);
2257 yprp_typedef(pctx, &modp->typedefs[u]);
2258 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002259 }
2260
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002261 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002262
Radek Krejci2a9fc652021-01-22 17:44:34 +01002263 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002264 YPR_EXTRA_LINE_PRINT(pctx);
2265 yprp_grouping(pctx, grp);
2266 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002267 }
2268
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002269 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002270
Radek Krejcid3ca0632019-04-16 16:54:54 +02002271 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002272 YPR_EXTRA_LINE_PRINT(pctx);
2273 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002274 }
2275
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002276 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002277
Radek Krejci2a9fc652021-01-22 17:44:34 +01002278 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002279 YPR_EXTRA_LINE_PRINT(pctx);
2280 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002281 }
2282
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002283 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002284
Radek Krejci2a9fc652021-01-22 17:44:34 +01002285 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002286 YPR_EXTRA_LINE_PRINT(pctx);
2287 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002288 }
2289
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002290 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002291
Radek Krejci2a9fc652021-01-22 17:44:34 +01002292 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002293 YPR_EXTRA_LINE_PRINT(pctx);
2294 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002295 }
2296
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002297 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002298
Radek Krejcid3ca0632019-04-16 16:54:54 +02002299 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002300 YPR_EXTRA_LINE_PRINT(pctx);
2301 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002302 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002303
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002304 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002305}
2306
2307LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002308yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002309{
2310 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002311 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002312 struct lys_ypr_ctx pctx_ = {
2313 .out = out,
2314 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002315 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002316 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002317 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002318 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002319
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002320 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002321 LEVEL++;
2322
2323 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002324 if (modp->version) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002325 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002326 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002327 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modp->exts);
2328 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002329
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002330 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002331
Michal Vasko7c8439f2020-08-05 13:25:19 +02002332 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002333 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002334
2335 /* meta-stmts */
2336 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002337 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002338 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002339 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modp->exts);
2340 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modp->exts);
2341 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modp->exts);
2342 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002343
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002344 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002345
Michal Vasko7c8439f2020-08-05 13:25:19 +02002346 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002347 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002348 YPR_EXTRA_LINE_PRINT(pctx);
2349 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002350 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002351
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002352 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002353
Michal Vasko7c8439f2020-08-05 13:25:19 +02002354 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002355 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002356
2357 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002358 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002359 ly_print_flush(out);
2360
2361 return LY_SUCCESS;
2362}
2363
2364static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002365yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002366{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002367 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002368 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002369 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002370 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, 0, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002371 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002372 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002373}
2374
2375LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002376yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002377{
2378 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002379 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002380 .out = out,
2381 .level = 0,
2382 .options = options,
2383 .module = submodp->mod,
2384 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002385 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002386
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002387 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002388 LEVEL++;
2389
2390 /* submodule-header-stmts */
2391 if (submodp->version) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002392 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002393 }
2394
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002395 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002396
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002397 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002398
Michal Vasko7c8439f2020-08-05 13:25:19 +02002399 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002400 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002401
2402 /* meta-stmts */
2403 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002404 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002405 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002406 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, 0, submodp->exts);
2407 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, 0, submodp->exts);
2408 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, 0, submodp->exts);
2409 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, 0, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002410
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002411 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002412
Michal Vasko7c8439f2020-08-05 13:25:19 +02002413 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002414 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002415 YPR_EXTRA_LINE_PRINT(pctx);
2416 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002417 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002418
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002419 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002420
Michal Vasko7c8439f2020-08-05 13:25:19 +02002421 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002422 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002423
2424 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002425 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002426 ly_print_flush(out);
2427
2428 return LY_SUCCESS;
2429}
2430
2431LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002432yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002433{
Michal Vasko331303f2022-08-22 09:51:57 +02002434 struct lys_ypr_ctx pctx_ = {
2435 .out = out,
2436 .level = 0,
2437 .options = options,
2438 .module = node->module,
2439 .schema = LYS_YPR_COMPILED
2440 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002441
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002442 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002443
2444 ly_print_flush(out);
2445 return LY_SUCCESS;
2446}
2447
2448LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002449yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002450{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002451 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002452 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002453 struct lys_ypr_ctx pctx_ = {
2454 .out = out,
2455 .level = 0,
2456 .options = options,
2457 .module = module,
2458 .schema = LYS_YPR_COMPILED
2459 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002460
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002461 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002462 LEVEL++;
2463
Radek Krejci693262f2019-04-29 15:23:20 +02002464 /* module-header-stmts */
Michal Vasko72c6d642024-02-27 14:59:01 +01002465 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modc->exts);
2466 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002467
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002468 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002469
Michal Vasko7c8439f2020-08-05 13:25:19 +02002470 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002471
2472 /* meta-stmts */
2473 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002474 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002475 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002476 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modc->exts);
2477 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modc->exts);
2478 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modc->exts);
2479 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002480
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002481 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002482
Radek Krejci693262f2019-04-29 15:23:20 +02002483 /* revision-stmts */
2484 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002485 YPR_EXTRA_LINE_PRINT(pctx);
2486 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2487 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002488 }
2489
2490 /* body-stmts */
2491 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002492 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002493 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002494 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002495 }
2496
Radek Krejci80d281e2020-09-14 17:42:54 +02002497 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002498 YPR_EXTRA_LINE_PRINT(pctx);
2499 yprc_identity(pctx, &module->identities[u]);
2500 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002501 }
2502
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002503 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002504 struct lysc_node *data;
2505 struct lysc_node_action *rpc;
2506 struct lysc_node_notif *notif;
2507
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002508 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002509 YPR_EXTRA_LINE_PRINT(pctx);
2510 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002511 }
Radek Krejci693262f2019-04-29 15:23:20 +02002512
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002513 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002514
Radek Krejci2a9fc652021-01-22 17:44:34 +01002515 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002516 YPR_EXTRA_LINE_PRINT(pctx);
2517 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002518 }
Radek Krejci693262f2019-04-29 15:23:20 +02002519
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002520 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002521
Radek Krejci2a9fc652021-01-22 17:44:34 +01002522 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002523 YPR_EXTRA_LINE_PRINT(pctx);
2524 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002525 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002526
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002527 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002528 }
2529
2530 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002531 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002532 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002533
2534 return LY_SUCCESS;
2535}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002536
Michal Vaskocc28b152022-08-23 14:44:54 +02002537LIBYANG_API_DEF void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002538lyplg_ext_print_info_extension_instance(struct lyspr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002539{
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002540 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002541 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002542 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002543
2544 LY_ARRAY_FOR(ext->substmts, u) {
2545 switch (ext->substmts[u].stmt) {
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002546 case LY_STMT_NOTIFICATION:
2547 case LY_STMT_INPUT:
2548 case LY_STMT_OUTPUT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002549 case LY_STMT_ACTION:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002550 case LY_STMT_RPC:
2551 case LY_STMT_ANYDATA:
2552 case LY_STMT_ANYXML:
2553 case LY_STMT_CASE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002554 case LY_STMT_CHOICE:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002555 case LY_STMT_CONTAINER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002556 case LY_STMT_LEAF:
2557 case LY_STMT_LEAF_LIST:
2558 case LY_STMT_LIST:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002559 case LY_STMT_USES: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002560 const struct lysc_node *node;
2561
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002562 if (data_printed) {
2563 break;
2564 }
2565
Michal Vasko53eb6a12024-06-13 11:38:47 +02002566 LY_LIST_FOR(*VOIDPTR2_C(ext->substmts[u].storage), node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002567 ypr_open(pctx->out, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002568 if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002569 yprc_notification(pctx, (struct lysc_node_notif *)node);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002570 } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) {
2571 yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag);
2572 } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) {
2573 yprc_action(pctx, (struct lysc_node_action *)node);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002574 } else {
2575 yprc_node(pctx, node);
2576 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002577 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002578
2579 /* all data nodes are stored in a linked list so all were printed */
2580 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002581 break;
2582 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002583 case LY_STMT_ARGUMENT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002584 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002585 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002586 case LY_STMT_ERROR_APP_TAG:
2587 case LY_STMT_ERROR_MESSAGE:
2588 case LY_STMT_KEY:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002589 case LY_STMT_MODIFIER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002590 case LY_STMT_NAMESPACE:
2591 case LY_STMT_ORGANIZATION:
2592 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002593 case LY_STMT_REFERENCE:
2594 case LY_STMT_UNITS:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002595 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
Michal Vasko9c3556a2022-10-06 16:08:47 +02002596 ypr_open(pctx->out, flag);
Michal Vasko53eb6a12024-06-13 11:38:47 +02002597 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *VOIDPTR2_C(ext->substmts[u].storage), 0, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002598 }
2599 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002600 case LY_STMT_BIT:
2601 case LY_STMT_ENUM: {
Michal Vasko53eb6a12024-06-13 11:38:47 +02002602 const struct lysc_type_bitenum_item *items = *VOIDPTR2_C(ext->substmts[u].storage);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002603
2604 yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag);
2605 break;
2606 }
2607 case LY_STMT_CONFIG:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002608 ypr_config(pctx, *(uint16_t *)VOIDPTR2_C(ext->substmts[u].storage), ext->exts, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002609 break;
2610 case LY_STMT_EXTENSION_INSTANCE:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002611 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, *VOIDPTR2_C(ext->substmts[u].storage), flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002612 break;
2613 case LY_STMT_FRACTION_DIGITS:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002614 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
2615 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts,
2616 (long unsigned int)*VOIDPTR2_C(ext->substmts[u].storage), flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002617 }
2618 break;
2619 case LY_STMT_IDENTITY: {
Michal Vasko53eb6a12024-06-13 11:38:47 +02002620 const struct lysc_ident *idents = *VOIDPTR2_C(ext->substmts[u].storage);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002621
2622 LY_ARRAY_FOR(idents, v) {
2623 yprc_identity(pctx, &idents[v]);
2624 }
2625 break;
2626 }
2627 case LY_STMT_LENGTH:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002628 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
2629 yprc_range(pctx, *VOIDPTR2_C(ext->substmts[u].storage), LY_TYPE_STRING, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002630 }
2631 break;
2632 case LY_STMT_MANDATORY:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002633 ypr_mandatory(pctx, *(uint16_t *)VOIDPTR_C(ext->substmts[u].storage), ext->exts, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002634 break;
2635 case LY_STMT_MAX_ELEMENTS: {
Michal Vasko53eb6a12024-06-13 11:38:47 +02002636 uint32_t max = *(uint32_t *)VOIDPTR_C(ext->substmts[u].storage);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002637
2638 if (max) {
2639 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag);
2640 } else {
2641 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01002642 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, ext->exts);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002643 }
2644 break;
2645 }
2646 case LY_STMT_MIN_ELEMENTS:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002647 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)VOIDPTR_C(ext->substmts[u].storage), flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002648 break;
2649 case LY_STMT_ORDERED_BY:
2650 ypr_open(pctx->out, flag);
2651 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0,
Michal Vasko53eb6a12024-06-13 11:38:47 +02002652 ((*(uint16_t *)VOIDPTR_C(ext->substmts[u].storage)) & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002653 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002654 case LY_STMT_MUST: {
Michal Vasko53eb6a12024-06-13 11:38:47 +02002655 const struct lysc_must *musts = *VOIDPTR2_C(ext->substmts[u].storage);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002656
2657 LY_ARRAY_FOR(musts, v) {
2658 yprc_must(pctx, &musts[v], flag);
2659 }
2660 break;
2661 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002662 case LY_STMT_PATTERN: {
Michal Vasko53eb6a12024-06-13 11:38:47 +02002663 const struct lysc_pattern *patterns = *VOIDPTR2_C(ext->substmts[u].storage);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002664
2665 LY_ARRAY_FOR(patterns, v) {
2666 yprc_pattern(pctx, &patterns[v], flag);
2667 }
2668 break;
2669 }
2670 case LY_STMT_POSITION:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002671 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
2672 ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)VOIDPTR_C(ext->substmts[u].storage), flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002673 }
2674 break;
2675 case LY_STMT_VALUE:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002676 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
2677 ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)VOIDPTR_C(ext->substmts[u].storage), flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002678 }
2679 break;
2680 case LY_STMT_RANGE:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002681 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
2682 yprc_range(pctx, *VOIDPTR2_C(ext->substmts[u].storage), LY_TYPE_UINT64, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002683 }
2684 break;
2685 case LY_STMT_REQUIRE_INSTANCE:
2686 ypr_open(pctx->out, flag);
Michal Vasko53eb6a12024-06-13 11:38:47 +02002687 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)VOIDPTR_C(ext->substmts[u].storage) ? "true" : "false",
Michal Vasko72c6d642024-02-27 14:59:01 +01002688 0, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002689 break;
2690 case LY_STMT_STATUS:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002691 ypr_status(pctx, *(uint16_t *)VOIDPTR_C(ext->substmts[u].storage), ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002692 break;
2693 case LY_STMT_TYPE:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002694 if (*VOIDPTR2_C(ext->substmts[u].storage)) {
Michal Vasko9c3556a2022-10-06 16:08:47 +02002695 ypr_open(pctx->out, flag);
Michal Vasko53eb6a12024-06-13 11:38:47 +02002696 yprc_type(pctx, *VOIDPTR2_C(ext->substmts[u].storage));
Radek Krejciadcf63d2021-02-09 10:21:18 +01002697 }
2698 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002699 case LY_STMT_WHEN:
Michal Vasko53eb6a12024-06-13 11:38:47 +02002700 yprc_when(pctx, *VOIDPTR2_C(ext->substmts[u].storage), flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002701 break;
2702 case LY_STMT_AUGMENT:
2703 case LY_STMT_BASE:
2704 case LY_STMT_BELONGS_TO:
2705 case LY_STMT_DEFAULT:
2706 case LY_STMT_DEVIATE:
2707 case LY_STMT_DEVIATION:
2708 case LY_STMT_EXTENSION:
2709 case LY_STMT_FEATURE:
2710 case LY_STMT_GROUPING:
2711 case LY_STMT_IF_FEATURE:
2712 case LY_STMT_IMPORT:
2713 case LY_STMT_INCLUDE:
2714 case LY_STMT_MODULE:
2715 case LY_STMT_PATH:
2716 case LY_STMT_PREFIX:
2717 case LY_STMT_REFINE:
2718 case LY_STMT_REVISION:
2719 case LY_STMT_REVISION_DATE:
2720 case LY_STMT_SUBMODULE:
2721 case LY_STMT_TYPEDEF:
2722 case LY_STMT_UNIQUE:
2723 case LY_STMT_YANG_VERSION:
2724 case LY_STMT_YIN_ELEMENT:
2725 /* nothing to do */
2726 break;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002727 default:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002728 LOGINT(pctx->module->ctx);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002729 break;
2730 }
2731 }
2732}