blob: 513db44a847e818ea418890a90f930b8d42330b3 [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 Vasko72c6d642024-02-27 14:59:01 +0100177ypr_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 +0200178{
179 const char *s, *t;
Michal Vasko72c6d642024-02-27 14:59:01 +0100180 char quot;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200181
Michal Vasko72c6d642024-02-27 14:59:01 +0100182 if (flags & LYS_YPR_TEXT_SINGLEQUOTED) {
183 quot = '\'';
184 } else {
185 quot = '\"';
186 }
187
188 if (flags & LYS_YPR_TEXT_SINGLELINE) {
189 ly_print_(pctx->out, "%*s%s %c", INDENT, name, quot);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200190 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100191 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192 LEVEL++;
193
Michal Vasko72c6d642024-02-27 14:59:01 +0100194 ly_print_(pctx->out, "%*s%c", INDENT, quot);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200195 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100196
Radek Krejcid3ca0632019-04-16 16:54:54 +0200197 t = text;
198 while ((s = strchr(t, '\n'))) {
Michal Vasko72c6d642024-02-27 14:59:01 +0100199 if (flags & LYS_YPR_TEXT_SINGLEQUOTED) {
200 ly_print_(pctx->out, "%.*s", (int)(s - t), t);
201 } else {
202 ypr_encode(pctx->out, t, s - t);
203 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100204 ly_print_(pctx->out, "\n");
Michal Vasko72c6d642024-02-27 14:59:01 +0100205
Radek Krejcid3ca0632019-04-16 16:54:54 +0200206 t = s + 1;
207 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100208 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200209 }
210 }
211
Michal Vasko72c6d642024-02-27 14:59:01 +0100212 if (flags & LYS_YPR_TEXT_SINGLEQUOTED) {
213 ly_print_(pctx->out, "%s", t);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200214 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +0100215 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200216 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100217 ly_print_(pctx->out, "%c", quot);
218 if (!(flags & LYS_YPR_TEXT_SINGLELINE)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200219 LEVEL--;
220 }
221}
222
223static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100224yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200225{
226 struct lysp_stmt *childstmt;
Michal Vasko72c6d642024-02-27 14:59:01 +0100227 uint16_t tflags = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200228
229 if (stmt->arg) {
230 if (stmt->flags) {
Michal Vasko72c6d642024-02-27 14:59:01 +0100231 if (stmt->flags & LYS_SINGLEQUOTED) {
232 tflags |= LYS_YPR_TEXT_SINGLEQUOTED;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200233 }
Michal Vasko72c6d642024-02-27 14:59:01 +0100234 ypr_text(pctx, stmt->stmt, stmt->arg, tflags);
235 ly_print_(pctx->out, "%s", stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100237 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200238 }
239 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100240 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200241 }
242
243 if (stmt->child) {
244 LEVEL++;
245 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100246 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200247 }
248 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100249 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200250 }
251}
252
Radek Krejcid3ca0632019-04-16 16:54:54 +0200253static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200254yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
255 struct lysp_ext_instance *ext, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200256{
Radek Krejcid3ca0632019-04-16 16:54:54 +0200257 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200258 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200259
Michal Vaskob26d09d2022-08-22 09:52:19 +0200260 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
261 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200262 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100263
Michal Vaskob26d09d2022-08-22 09:52:19 +0200264 ypr_open(pctx->out, flag);
265
Michal Vasko193dacd2022-10-13 08:43:05 +0200266 if (ext->def->argname) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200267 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200268 ypr_encode(pctx->out, ext->argument, -1);
269 ly_print_(pctx->out, "\"");
270 } else {
271 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
272 }
273
274 child_presence = 0;
275 LEVEL++;
276 LY_LIST_FOR(ext->child, stmt) {
277 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200278 continue;
279 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200280 if (!child_presence) {
281 ly_print_(pctx->out, " {\n");
282 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200283 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200284 yprp_stmt(pctx, stmt);
285 }
286 LEVEL--;
287 if (child_presence) {
288 ly_print_(pctx->out, "%*s}\n", INDENT);
289 } else {
290 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200291 }
292}
293
Radek Krejci693262f2019-04-29 15:23:20 +0200294static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200295yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
296 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200297{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200298 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200299
300 LY_ARRAY_FOR(exts, u) {
aPiecek6cf1d162023-11-08 16:07:00 +0100301 if (exts[u].flags & LYS_INTERNAL) {
302 continue;
303 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200304 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
305 }
306}
307
aPiecek6cf1d162023-11-08 16:07:00 +0100308static ly_bool
309yprp_extension_has_printable_instances(struct lysp_ext_instance *exts)
310{
311 LY_ARRAY_COUNT_TYPE u;
312
313 LY_ARRAY_FOR(exts, u) {
314 if (!(exts[u].flags & LYS_INTERNAL)) {
315 return 1;
316 }
317 }
318
319 return 0;
320}
321
Michal Vaskob26d09d2022-08-22 09:52:19 +0200322static void
323yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
324 struct lysc_ext_instance *exts, ly_bool *flag)
325{
326 LY_ARRAY_COUNT_TYPE u;
327 ly_bool inner_flag;
328
329 LY_ARRAY_FOR(exts, u) {
330 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
331 return;
332 }
333
334 ypr_open(pctx->out, flag);
335 if (exts[u].argument) {
336 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
337 ypr_encode(pctx->out, exts[u].argument, -1);
338 ly_print_(pctx->out, "\"");
339 } else {
340 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
341 }
342
343 LEVEL++;
344 inner_flag = 0;
345 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
346
Michal Vasko941e0562022-10-18 10:35:00 +0200347 if (exts[u].def->plugin && exts[u].def->plugin->printer_info) {
348 exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200349 }
350
351 LEVEL--;
352 ypr_close(pctx, inner_flag);
353 }
354}
355
356static void
Michal Vasko72c6d642024-02-27 14:59:01 +0100357ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text,
358 ly_bool singlequoted, void *exts)
Michal Vaskob26d09d2022-08-22 09:52:19 +0200359{
Radek Krejci857189e2020-09-01 13:26:36 +0200360 ly_bool extflag = 0;
Michal Vasko72c6d642024-02-27 14:59:01 +0100361 uint16_t flags = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200362
363 if (!text) {
364 /* nothing to print */
365 return;
366 }
367
Michal Vaskob872d0f2022-12-08 09:36:54 +0100368 if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) {
369 ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200370 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +0100371 if (!(lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN)) {
372 flags |= LYS_YPR_TEXT_SINGLELINE;
373 }
374 if (singlequoted) {
375 flags |= LYS_YPR_TEXT_SINGLEQUOTED;
376 }
377 ypr_text(pctx, lys_stmt_str(substmt), text, flags);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378 }
379
380 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200381 if (pctx->schema == LYS_YPR_PARSED) {
382 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
383 } else {
384 yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200385 }
386 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100387 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200388}
389
390static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100391ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
Michal Vasko2bf4af42023-01-04 12:08:38 +0100392 unsigned long attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393{
394 char *str;
395
Radek Krejci1deb5be2020-08-26 16:43:36 +0200396 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398 return;
399 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100400 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100401 ypr_substmt(pctx, substmt, substmt_index, str, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200402 free(str);
403}
404
405static void
Michal Vasko2bf4af42023-01-04 12:08:38 +0100406ypr_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 +0100407 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200408{
409 char *str;
410
Radek Krejci1deb5be2020-08-26 16:43:36 +0200411 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100412 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200413 return;
414 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100415 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100416 ypr_substmt(pctx, substmt, substmt_index, str, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200417 free(str);
418}
419
420static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100421yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422{
423 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100424 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200425 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200426 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +0100427 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, 0, rev->exts);
428 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, 0, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100430 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200431 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100432 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433 }
434}
435
436static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100437ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200438{
439 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100440 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100441 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200442 }
443}
444
445static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100446ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447{
448 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100449 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100450 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200451 }
452}
453
454static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100455ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200456{
457 const char *status = NULL;
458
459 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100460 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 status = "current";
462 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100463 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464 status = "deprecated";
465 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100466 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200467 status = "obsolete";
468 }
Radek Krejci693262f2019-04-29 15:23:20 +0200469
Michal Vasko72c6d642024-02-27 14:59:01 +0100470 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471}
472
473static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100474ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200475{
476 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100477 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100478 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200479 }
480}
481
482static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100483ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200484{
485 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100486 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100487 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, 0, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200488 }
489}
490
491static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100492yprp_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 +0200493{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200494 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200495 ly_bool extflag;
Michal Vasko72c6d642024-02-27 14:59:01 +0100496 uint16_t flags;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200497
Michal Vasko7f45cf22020-10-01 12:49:44 +0200498 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100499 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200500 extflag = 0;
501
Michal Vasko659f8fa2024-02-27 15:20:34 +0100502 flags = LYS_YPR_TEXT_SINGLELINE | ((iffs[u].flags & LYS_SINGLEQUOTED) ? LYS_YPR_TEXT_SINGLEQUOTED : 0);
Michal Vasko72c6d642024-02-27 14:59:01 +0100503 ypr_text(pctx, "if-feature", iffs[u].str, flags);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200504
505 /* extensions */
506 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200507 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100509 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200510 }
511}
512
513static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100514yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200515{
Radek Krejci857189e2020-09-01 13:26:36 +0200516 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200517 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200518
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100519 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200520 LEVEL++;
521
Michal Vaskob26d09d2022-08-22 09:52:19 +0200522 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200523
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100524 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100525 ypr_open(pctx->out, &flag);
526 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200527 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200528 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200529 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100530 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 +0200531 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200532 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533 }
534 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100535 (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 +0100536 ypr_open(pctx->out, &flag2);
Michal Vasko72c6d642024-02-27 14:59:01 +0100537 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 +0200538 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200539 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100540 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200541 }
542
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100543 ypr_status(pctx, ext->flags, ext->exts, &flag);
544 ypr_description(pctx, ext->dsc, ext->exts, &flag);
545 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200546
547 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100548 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200549}
550
551static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100552yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553{
Radek Krejci857189e2020-09-01 13:26:36 +0200554 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200555
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100556 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200557 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200558 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100559 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
560 ypr_status(pctx, feat->flags, feat->exts, &flag);
561 ypr_description(pctx, feat->dsc, feat->exts, &flag);
562 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100564 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200565}
566
567static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100568yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200569{
Radek Krejci857189e2020-09-01 13:26:36 +0200570 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200571 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200572
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100573 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200574 LEVEL++;
575
Michal Vaskob26d09d2022-08-22 09:52:19 +0200576 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100577 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200578
579 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100580 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100581 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], 0, ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200582 }
583
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100584 ypr_status(pctx, ident->flags, ident->exts, &flag);
585 ypr_description(pctx, ident->dsc, ident->exts, &flag);
586 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200587
588 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100589 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200590}
591
592static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100593yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200594{
Radek Krejci857189e2020-09-01 13:26:36 +0200595 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200596 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200597
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100598 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200599 LEVEL++;
600
Michal Vaskob26d09d2022-08-22 09:52:19 +0200601 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200602
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100603 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200604 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100605 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200606 }
607
Radek Krejci693262f2019-04-29 15:23:20 +0200608 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100609 if (pctx->module != ident->derived[u]->module) {
610 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 +0200611 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100612 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200613 }
614 }
615
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100616 ypr_status(pctx, ident->flags, ident->exts, &flag);
617 ypr_description(pctx, ident->dsc, ident->exts, &flag);
618 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200619
620 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100621 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200622}
623
624static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100625yprp_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 +0200626{
Michal Vasko72c6d642024-02-27 14:59:01 +0100627 ly_bool inner_flag = 0;
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100628 const char *text;
Michal Vasko72c6d642024-02-27 14:59:01 +0100629 uint16_t flags = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200630
631 if (!restr) {
632 return;
633 }
634
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100635 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100636 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
637 restr->arg.str : restr->arg.str + 1;
Michal Vasko72c6d642024-02-27 14:59:01 +0100638 if (!strchr(text, '\n')) {
639 flags |= LYS_YPR_TEXT_SINGLELINE;
640 }
641 if (restr->arg.flags & LYS_SINGLEQUOTED) {
642 flags |= LYS_YPR_TEXT_SINGLEQUOTED;
643 }
644 ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, flags);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200645
646 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200647 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100648 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200649 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100650 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100651 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200652 }
653 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100654 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100655 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, 0, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200656 }
657 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100658 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100659 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, 0, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200660 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100661 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
662 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200663
Radek Krejcid3ca0632019-04-16 16:54:54 +0200664 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100665 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200666}
667
668static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100669yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200670{
Radek Krejci857189e2020-09-01 13:26:36 +0200671 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200672
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100673 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100674 ypr_text(pctx, "must", must->cond->expr, LYS_YPR_TEXT_SINGLELINE);
Radek Krejci693262f2019-04-29 15:23:20 +0200675
676 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200677 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200678 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100679 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100680 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, 0, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200681 }
682 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100683 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100684 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, 0, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200685 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100686 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
687 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200688
689 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100690 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200691}
692
693static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100694yprc_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 +0200695{
Radek Krejci857189e2020-09-01 13:26:36 +0200696 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200697 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200698
Radek Krejci334ccc72019-06-12 13:49:29 +0200699 if (!range) {
700 return;
701 }
702
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100703 ypr_open(pctx->out, flag);
704 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200705 LY_ARRAY_FOR(range->parts, u) {
706 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100707 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200708 }
709 if (range->parts[u].max_64 == range->parts[u].min_64) {
710 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100711 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200712 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100713 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200714 }
715 } else {
716 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100717 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200718 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100719 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200720 }
721 }
722 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100723 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200724
725 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200726 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200727 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100728 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100729 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, 0, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200730 }
731 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100732 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100733 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, 0, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200734 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100735 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
736 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200737
738 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100739 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200740}
741
742static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100743yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200744{
Radek Krejci857189e2020-09-01 13:26:36 +0200745 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200746
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100747 ypr_open(pctx->out, flag);
748 ly_print_(pctx->out, "%*spattern \"", INDENT);
749 ypr_encode(pctx->out, pattern->expr, -1);
750 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200751
752 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200753 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200754 if (pattern->inverted) {
755 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100756 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100757 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200758 }
759 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100760 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100761 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, 0, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200762 }
763 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100764 ypr_open(pctx->out, &inner_flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100765 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, 0, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200766 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100767 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
768 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200769
770 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100771 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200772}
773
774static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200775yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag)
776{
777 LY_ARRAY_COUNT_TYPE u;
778 const struct lysc_type_bitenum_item *item;
779 ly_bool inner_flag;
780
781 assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM));
782
783 LY_ARRAY_FOR(items, u) {
784 item = &items[u];
785 inner_flag = 0;
786
787 ypr_open(pctx->out, flag);
788 ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum");
789 ypr_encode(pctx->out, item->name, -1);
790 ly_print_(pctx->out, "\"");
791 LEVEL++;
792 if (basetype == LY_TYPE_BITS) {
793 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
794 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
795 } else { /* LY_TYPE_ENUM */
796 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
797 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
798 }
799 ypr_status(pctx, item->flags, item->exts, &inner_flag);
800 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
801 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
802 LEVEL--;
803 ypr_close(pctx, inner_flag);
804 }
805}
806
807static void
808yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200809{
Radek Krejci857189e2020-09-01 13:26:36 +0200810 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200811
812 if (!when) {
813 return;
814 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100815 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200816
Michal Vasko72c6d642024-02-27 14:59:01 +0100817 ypr_text(pctx, "when", when->cond, LYS_YPR_TEXT_SINGLELINE);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200818
819 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200820 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100821 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
822 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200823 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100824 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200825}
826
827static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200828yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200829{
Radek Krejci857189e2020-09-01 13:26:36 +0200830 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200831
832 if (!when) {
833 return;
834 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100835 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200836
Michal Vasko72c6d642024-02-27 14:59:01 +0100837 ypr_text(pctx, "when", when->cond->expr, LYS_YPR_TEXT_SINGLELINE);
Radek Krejci693262f2019-04-29 15:23:20 +0200838
839 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200840 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100841 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
842 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200843 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100844 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200845}
846
847static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200848yprp_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 +0200849{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200850 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200851 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200852
853 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100854 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200855 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100856 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200857 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100858 ly_print_(pctx->out, "%*senum \"", INDENT);
859 ypr_encode(pctx->out, items[u].name, -1);
860 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200861 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200862 inner_flag = 0;
863 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200864 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100865 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200866 if (items[u].flags & LYS_SET_VALUE) {
867 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100868 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200869 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100870 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200871 }
872 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100873 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
874 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
875 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200876 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100877 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200878 }
879}
880
881static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100882yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200883{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200884 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200885 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200886
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100887 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200888 LEVEL++;
889
Michal Vaskob26d09d2022-08-22 09:52:19 +0200890 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200891
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100892 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
893 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200894 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100895 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200896 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200897 yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
898 yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200899
900 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100901 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100902 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, 0, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200903 }
904 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100905 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100906 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", 0, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200907 }
908 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100909 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200910 }
911 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100912 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +0100913 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], 0, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200914 }
915 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100916 ypr_open(pctx->out, &flag);
917 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200918 }
919
920 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100921 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200922}
923
924static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100925yprc_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 +0200926 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200927{
Radek Krejci857189e2020-09-01 13:26:36 +0200928 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200929 const char *str;
930
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100931 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +0100932 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, 0, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200933 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200934 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200935 }
936}
937
938static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100939yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200940{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200941 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200942 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200943
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100944 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200945 LEVEL++;
946
Michal Vaskob26d09d2022-08-22 09:52:19 +0200947 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200948
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200949 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200950 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200951 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200952
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100953 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200954 break;
955 }
956 case LY_TYPE_UINT8:
957 case LY_TYPE_UINT16:
958 case LY_TYPE_UINT32:
959 case LY_TYPE_UINT64:
960 case LY_TYPE_INT8:
961 case LY_TYPE_INT16:
962 case LY_TYPE_INT32:
963 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200964 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200965
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100966 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200967 break;
968 }
969 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200970 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200971
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100972 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200973 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100974 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200975 }
976 break;
977 }
978 case LY_TYPE_BITS:
979 case LY_TYPE_ENUM: {
980 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200981 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200982
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200983 yprc_bits_enum(pctx, bits->bits, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200984 break;
985 }
986 case LY_TYPE_BOOL:
987 case LY_TYPE_EMPTY:
988 /* nothing to do */
989 break;
990 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200991 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200992
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100993 ypr_open(pctx->out, &flag);
994 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
995 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200996 break;
997 }
998 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200999 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001000
Radek Krejci693262f2019-04-29 15:23:20 +02001001 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001002 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001003 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, 0, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001004 }
1005 break;
1006 }
1007 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001008 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001009
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001010 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001011 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", 0, inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001012 break;
1013 }
1014 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001015 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001016
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001017 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001018 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, 0, lr->exts);
1019 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", 0, lr->exts);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001020 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +02001021 break;
1022 }
1023 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001024 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +02001025
Radek Krejci693262f2019-04-29 15:23:20 +02001026 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001027 ypr_open(pctx->out, &flag);
1028 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02001029 }
1030 break;
1031 }
1032 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001033 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +02001034 }
1035
1036 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001037 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001038}
1039
1040static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001041yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001042{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001043 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044 LEVEL++;
1045
Michal Vaskob26d09d2022-08-22 09:52:19 +02001046 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001047
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001048 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049
1050 if (tpdf->units) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001051 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, 0, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001052 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001053 if (tpdf->dflt.str) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001054 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 +02001055 }
1056
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001057 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1058 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1059 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001060
1061 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001062 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001063}
1064
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001065static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1066static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1067static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1068static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001069
1070static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001071yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001073 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001074 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001076 struct lysp_node_action *action;
1077 struct lysp_node_notif *notif;
1078 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001079
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001080 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081 LEVEL++;
1082
Michal Vaskob26d09d2022-08-22 09:52:19 +02001083 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001084 ypr_status(pctx, grp->flags, grp->exts, &flag);
1085 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1086 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001087
1088 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001089 ypr_open(pctx->out, &flag);
1090 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091 }
1092
Radek Krejci2a9fc652021-01-22 17:44:34 +01001093 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001094 ypr_open(pctx->out, &flag);
1095 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001096 }
1097
Radek Krejci01180ac2021-01-27 08:48:22 +01001098 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001099 ypr_open(pctx->out, &flag);
1100 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001101 }
1102
Radek Krejci2a9fc652021-01-22 17:44:34 +01001103 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001104 ypr_open(pctx->out, &flag);
1105 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001106 }
1107
1108 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001109 ypr_open(pctx->out, &flag);
1110 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001111 }
1112
1113 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001114 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001115}
1116
1117static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001118yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001119{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001120 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001121 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001122 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001123
Radek Krejci01180ac2021-01-27 08:48:22 +01001124 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001125 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001126 return;
1127 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001128 ypr_open(pctx->out, flag);
1129 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001130
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001131 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001132 LEVEL++;
1133
Michal Vaskob26d09d2022-08-22 09:52:19 +02001134 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001135 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001136 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001137 }
1138 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001139 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001140 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001141 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001142 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001143 }
1144
Radek Krejci01180ac2021-01-27 08:48:22 +01001145 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001146 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147 }
1148
1149 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001150 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001151}
1152
1153static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001154yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001155{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001156 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001157 struct lysc_node *data;
1158
Radek Krejci01180ac2021-01-27 08:48:22 +01001159 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001160 /* input/output is empty */
1161 return;
1162 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001163 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001164
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001165 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001166 LEVEL++;
1167
Michal Vasko193dacd2022-10-13 08:43:05 +02001168 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001169 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001170 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001171 }
1172
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001173 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001174 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001175 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001176 }
Radek Krejci693262f2019-04-29 15:23:20 +02001177 }
1178
1179 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001180 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001181}
1182
1183static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001184yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001185{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001186 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001187 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001188 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001189 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001190
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001191 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001192
1193 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001194 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001195 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001196
1197 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001198 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001199 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001200 ypr_status(pctx, notif->flags, notif->exts, &flag);
1201 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1202 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203
1204 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001205 ypr_open(pctx->out, &flag);
1206 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001207 }
1208
Radek Krejci2a9fc652021-01-22 17:44:34 +01001209 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001210 ypr_open(pctx->out, &flag);
1211 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001212 }
1213
Radek Krejci01180ac2021-01-27 08:48:22 +01001214 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001215 ypr_open(pctx->out, &flag);
1216 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001217 }
1218
1219 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001220 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001221}
1222
1223static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001224yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001225{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001226 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001227 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001228 struct lysc_node *data;
1229
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001230 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001231
1232 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001233 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001234
1235 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001236 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001237 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001238 ypr_status(pctx, notif->flags, notif->exts, &flag);
1239 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1240 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001241
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001242 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001243 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001244 ypr_open(pctx->out, &flag);
1245 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001246 }
Radek Krejci693262f2019-04-29 15:23:20 +02001247 }
1248
1249 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001250 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001251}
1252
1253static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001254yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001255{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001256 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001257 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001258 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001259
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001260 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001261
1262 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001263 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001264 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1265 ypr_status(pctx, action->flags, action->exts, &flag);
1266 ypr_description(pctx, action->dsc, action->exts, &flag);
1267 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001268
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001269 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001270
Radek Krejcid3ca0632019-04-16 16:54:54 +02001271 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001272 ypr_open(pctx->out, &flag);
1273 YPR_EXTRA_LINE_PRINT(pctx);
1274 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275 }
1276
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001277 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001278
Radek Krejci2a9fc652021-01-22 17:44:34 +01001279 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001280 ypr_open(pctx->out, &flag);
1281 YPR_EXTRA_LINE_PRINT(pctx);
1282 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001283 }
1284
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001285 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001286
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001287 yprp_inout(pctx, &action->input, &flag);
1288 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001289
1290 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001291 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292}
1293
1294static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001295yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001296{
Radek Krejci857189e2020-09-01 13:26:36 +02001297 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001298
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001299 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001300
1301 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001302 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001303 ypr_status(pctx, action->flags, action->exts, &flag);
1304 ypr_description(pctx, action->dsc, action->exts, &flag);
1305 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001306
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001307 yprc_inout(pctx, &action->input, &flag);
1308 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001309
1310 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001311 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001312}
1313
1314static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001315yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001316{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001317 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001318 LEVEL++;
1319
Michal Vasko193dacd2022-10-13 08:43:05 +02001320 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001321 yprp_when(pctx, lysp_node_when(node), flag);
1322 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001323}
1324
1325static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001326yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001327{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001328 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001329 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001330
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001331 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001332 LEVEL++;
1333
Michal Vasko193dacd2022-10-13 08:43:05 +02001334 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001335
1336 when = lysc_node_when(node);
1337 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001338 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001339 }
Radek Krejci693262f2019-04-29 15:23:20 +02001340}
1341
Michal Vaskob26d09d2022-08-22 09:52:19 +02001342/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001343#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001344 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001345 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001346 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001347 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001348 ypr_status(pctx, node->flags, node->exts, flag); \
1349 ypr_description(pctx, node->dsc, node->exts, flag); \
1350 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001351
1352static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001353yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001354{
1355 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001356}
1357
1358static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001359yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001360{
1361 YPR_NODE_COMMON2;
1362}
1363
1364#undef YPR_NODE_COMMON2
1365
1366static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001367yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001368{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001369 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001370 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001371 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001372 struct lysp_node_action *action;
1373 struct lysp_node_notif *notif;
1374 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001375 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1376
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001377 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001378
1379 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001380 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001381 }
1382 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001383 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001384 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, 0, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001385 }
1386
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001387 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001388
1389 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001390 ypr_open(pctx->out, &flag);
1391 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001392 }
1393
Radek Krejci2a9fc652021-01-22 17:44:34 +01001394 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001395 ypr_open(pctx->out, &flag);
1396 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001397 }
1398
1399 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001400 ypr_open(pctx->out, &flag);
1401 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001402 }
1403
Radek Krejci2a9fc652021-01-22 17:44:34 +01001404 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001405 ypr_open(pctx->out, &flag);
1406 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001407 }
1408
Radek Krejci2a9fc652021-01-22 17:44:34 +01001409 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001410 ypr_open(pctx->out, &flag);
1411 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001412 }
1413
1414 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001415 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001416}
1417
1418static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001419yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001420{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001421 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001422 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001423 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001424 struct lysc_node_action *action;
1425 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001426 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1427
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001428 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001429
1430 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001431 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001432 }
1433 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001434 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001435 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", 0, cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001436 }
1437
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001438 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001439
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001440 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001441 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001442 ypr_open(pctx->out, &flag);
1443 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001444 }
Radek Krejci693262f2019-04-29 15:23:20 +02001445
Radek Krejci2a9fc652021-01-22 17:44:34 +01001446 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001447 ypr_open(pctx->out, &flag);
1448 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001449 }
Radek Krejci693262f2019-04-29 15:23:20 +02001450
Radek Krejci2a9fc652021-01-22 17:44:34 +01001451 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001452 ypr_open(pctx->out, &flag);
1453 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001454 }
Radek Krejci693262f2019-04-29 15:23:20 +02001455 }
1456
1457 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001458 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001459}
1460
1461static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001462yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001463{
Radek Krejci857189e2020-09-01 13:26:36 +02001464 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001465 struct lysp_node *child;
1466 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1467
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001468 yprp_node_common1(pctx, node, &flag);
1469 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001470
1471 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001472 ypr_open(pctx->out, &flag);
1473 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001474 }
1475
1476 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001477 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001478}
1479
1480static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001481yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001482{
Radek Krejci857189e2020-09-01 13:26:36 +02001483 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001484 struct lysc_node *child;
1485
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001486 yprc_node_common1(pctx, &cs->node, &flag);
1487 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001488
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001489 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001490 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001491 ypr_open(pctx->out, &flag);
1492 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001493 }
Radek Krejci693262f2019-04-29 15:23:20 +02001494 }
1495
1496 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001497 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001498}
1499
1500static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001501yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001502{
Radek Krejci857189e2020-09-01 13:26:36 +02001503 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001504 struct lysp_node *child;
1505 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1506
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001507 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001508
Michal Vasko7f45cf22020-10-01 12:49:44 +02001509 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001510 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001511 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 +02001512 }
1513
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001514 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515
1516 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001517 ypr_open(pctx->out, &flag);
1518 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001519 }
1520
1521 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001522 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001523}
1524
1525static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001526yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001527{
Radek Krejci857189e2020-09-01 13:26:36 +02001528 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001529 struct lysc_node_case *cs;
1530 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1531
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001532 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001533
1534 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001535 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001536 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, 0, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001537 }
1538
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001539 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001540
Michal Vasko22df3f02020-08-24 13:29:22 +02001541 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001542 ypr_open(pctx->out, &flag);
1543 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001544 }
1545
1546 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001547 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001548}
1549
1550static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001551yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001552{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001553 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1555
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001556 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001557
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001558 yprp_type(pctx, &leaf->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001559 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001560 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001561 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562 }
Michal Vasko72c6d642024-02-27 14:59:01 +01001563 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 +02001564
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001565 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001566
1567 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001568 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001569}
1570
1571static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001572yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001573{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001574 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001575 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1576
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001577 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001578
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001579 yprc_type(pctx, leaf->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001580 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001581 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001582 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001583 }
Radek Krejcia1911222019-07-22 17:24:50 +02001584
1585 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001586 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001587 }
Radek Krejci693262f2019-04-29 15:23:20 +02001588
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001589 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001590
1591 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001592 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001593}
1594
1595static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001596yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001597{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001598 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001599 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1600
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001601 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001602
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001603 yprp_type(pctx, &llist->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001604 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001605 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001606 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001607 }
1608 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001609 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(llist->dflts[u].flags),
1610 llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001611 }
1612
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001613 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001614
1615 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001616 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001617 }
1618 if (llist->flags & LYS_SET_MAX) {
1619 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001620 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001621 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001622 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001623 }
1624 }
1625
1626 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko72c6d642024-02-27 14:59:01 +01001627 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 +02001628 }
1629
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001630 ypr_status(pctx, node->flags, node->exts, NULL);
1631 ypr_description(pctx, node->dsc, node->exts, NULL);
1632 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633
1634 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001635 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001636}
1637
1638static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001639yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001640{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001641 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001642 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1643
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001644 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001645
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001646 yprc_type(pctx, llist->type);
Michal Vasko72c6d642024-02-27 14:59:01 +01001647 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001648 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001649 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001650 }
1651 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001652 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001653 }
1654
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001655 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001656
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001657 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001658 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001659 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001660 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001661 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001662 }
1663
Michal Vasko72c6d642024-02-27 14:59:01 +01001664 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 +02001665
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001666 ypr_status(pctx, node->flags, node->exts, NULL);
1667 ypr_description(pctx, node->dsc, node->exts, NULL);
1668 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001669
1670 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001671 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001672}
1673
1674static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001675yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001676{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001677 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001678 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001679 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001680 struct lysp_node_action *action;
1681 struct lysp_node_notif *notif;
1682 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001683 struct lysp_node_list *list = (struct lysp_node_list *)node;
1684
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001685 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001686
1687 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001688 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001689 }
1690 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001691 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001692 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, 0, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001693 }
1694 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001695 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001696 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(list->uniques[u].flags),
1697 list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001698 }
1699
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001700 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001701
1702 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001703 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001704 }
1705 if (list->flags & LYS_SET_MAX) {
1706 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001707 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001708 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001709 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001710 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001711 }
1712 }
1713
1714 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001715 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001716 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 +02001717 }
1718
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001719 ypr_status(pctx, node->flags, node->exts, &flag);
1720 ypr_description(pctx, node->dsc, node->exts, &flag);
1721 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001722
1723 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001724 ypr_open(pctx->out, &flag);
1725 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001726 }
1727
Radek Krejci2a9fc652021-01-22 17:44:34 +01001728 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001729 ypr_open(pctx->out, &flag);
1730 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001731 }
1732
1733 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001734 ypr_open(pctx->out, &flag);
1735 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001736 }
1737
Radek Krejci2a9fc652021-01-22 17:44:34 +01001738 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001739 ypr_open(pctx->out, &flag);
1740 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001741 }
1742
Radek Krejci2a9fc652021-01-22 17:44:34 +01001743 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001744 ypr_open(pctx->out, &flag);
1745 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001746 }
1747
1748 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001749 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001750}
1751
1752static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001753yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001754{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001755 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001756 struct lysc_node_list *list = (struct lysc_node_list *)node;
1757
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001758 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001759
1760 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001761 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001762 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001763 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001764 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001765 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 +01001766 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001767 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001768 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001769 }
1770 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001771 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001772 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001773 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001774 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001775 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001776 }
1777
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001778 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001779
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001780 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001781 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001782 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001783 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001784 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001785 }
1786
Michal Vasko72c6d642024-02-27 14:59:01 +01001787 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 +02001788
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001789 ypr_status(pctx, node->flags, node->exts, NULL);
1790 ypr_description(pctx, node->dsc, node->exts, NULL);
1791 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001792
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001793 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001794 struct lysc_node *child;
1795 struct lysc_node_action *action;
1796 struct lysc_node_notif *notif;
1797
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001798 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001799 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001800 }
Radek Krejci693262f2019-04-29 15:23:20 +02001801
Radek Krejci2a9fc652021-01-22 17:44:34 +01001802 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001803 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001804 }
Radek Krejci693262f2019-04-29 15:23:20 +02001805
Radek Krejci2a9fc652021-01-22 17:44:34 +01001806 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001807 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001808 }
Radek Krejci693262f2019-04-29 15:23:20 +02001809 }
1810
1811 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001812 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001813}
1814
1815static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001816yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001818 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001819 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001821 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001822 LEVEL++;
1823
Michal Vaskob26d09d2022-08-22 09:52:19 +02001824 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001825 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826
1827 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001828 ypr_open(pctx->out, &flag);
1829 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 }
1831
1832 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001833 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001834 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, 0, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001835 }
1836
1837 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001838 ypr_open(pctx->out, &flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01001839 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(refine->dflts[u].flags),
1840 refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841 }
1842
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001843 ypr_config(pctx, refine->flags, refine->exts, &flag);
1844 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845
1846 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001847 ypr_open(pctx->out, &flag);
1848 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 }
1850 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001851 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001852 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001853 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001854 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01001855 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856 }
1857 }
1858
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001859 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1860 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861
1862 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001863 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864}
1865
1866static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001867yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001868{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001869 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001870 struct lysp_node_action *action;
1871 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001873 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001874 LEVEL++;
1875
Michal Vaskob26d09d2022-08-22 09:52:19 +02001876 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001877 yprp_when(pctx, aug->when, NULL);
1878 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1879 ypr_status(pctx, aug->flags, aug->exts, NULL);
1880 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1881 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001882
1883 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001884 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 }
1886
Radek Krejci2a9fc652021-01-22 17:44:34 +01001887 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001888 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889 }
1890
Radek Krejci2a9fc652021-01-22 17:44:34 +01001891 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001892 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893 }
1894
1895 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001896 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897}
1898
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001900yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001902 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001903 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001905 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001907 yprp_node_common1(pctx, node, &flag);
1908 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001909
1910 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001911 ypr_open(pctx->out, &flag);
1912 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001913 }
1914
Radek Krejci2a9fc652021-01-22 17:44:34 +01001915 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001916 ypr_open(pctx->out, &flag);
1917 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 }
1919
1920 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001921 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922}
1923
1924static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001925yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001926{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001927 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001928 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001929 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1930
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001931 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001932
1933 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001934 ypr_open(pctx->out, &flag);
1935 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 }
1937
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001938 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939
1940 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001941 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942}
1943
1944static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001945yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001946{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001947 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001948 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001949 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001950
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001951 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001952
Radek Krejci693262f2019-04-29 15:23:20 +02001953 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001954 ypr_open(pctx->out, &flag);
1955 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001956 }
1957
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001958 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001959
Radek Krejcid3ca0632019-04-16 16:54:54 +02001960 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001961 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001962}
1963
1964static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001965yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001966{
1967 switch (node->nodetype) {
1968 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001969 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970 break;
1971 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001972 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001973 break;
1974 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001975 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976 break;
1977 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001978 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 break;
1980 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001981 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982 break;
1983 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001984 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001985 break;
1986 case LYS_ANYXML:
1987 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001988 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989 break;
1990 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001991 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001992 break;
1993 default:
1994 break;
1995 }
1996}
1997
1998static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001999yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02002000{
2001 switch (node->nodetype) {
2002 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002003 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002004 break;
2005 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002007 break;
2008 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002009 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002010 break;
2011 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002012 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002013 break;
2014 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002015 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002016 break;
2017 case LYS_ANYXML:
2018 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002019 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02002020 break;
2021 default:
2022 break;
2023 }
2024}
2025
2026static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002027yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002029 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 struct lysp_deviate_add *add;
2031 struct lysp_deviate_rpl *rpl;
2032 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08002033 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002035 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002036 LEVEL++;
2037
Michal Vaskob26d09d2022-08-22 09:52:19 +02002038 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002039 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
2040 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041
fredgan2b11ddb2019-10-21 11:03:39 +08002042 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002043 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08002044 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
2045 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002046 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047 LEVEL++;
2048
Michal Vaskob26d09d2022-08-22 09:52:19 +02002049 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002050 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002051 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002052 continue;
2053 }
fredgan2b11ddb2019-10-21 11:03:39 +08002054 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002055 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002056 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 LEVEL++;
2058
Michal Vaskob26d09d2022-08-22 09:52:19 +02002059 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002060 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, 0, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002061 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002062 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002064 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002065 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(add->uniques[u].flags),
2066 add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002067 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002068 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002069 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(add->dflts[u].flags),
2070 add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002071 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002072 ypr_config(pctx, add->flags, add->exts, NULL);
2073 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002075 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002076 }
2077 if (add->flags & LYS_SET_MAX) {
2078 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002079 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002080 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01002081 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002082 }
2083 }
fredgan2b11ddb2019-10-21 11:03:39 +08002084 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002085 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002086 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002087 LEVEL++;
2088
Michal Vaskob26d09d2022-08-22 09:52:19 +02002089 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002090 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002091 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002092 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002093 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, 0, rpl->exts);
2094 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 +01002095 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2096 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002097 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002098 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002099 }
2100 if (rpl->flags & LYS_SET_MAX) {
2101 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002102 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002103 } else {
Michal Vasko72c6d642024-02-27 14:59:01 +01002104 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002105 }
2106 }
fredgan2b11ddb2019-10-21 11:03:39 +08002107 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002108 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002109 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002110 LEVEL++;
2111
Michal Vaskob26d09d2022-08-22 09:52:19 +02002112 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002113 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, 0, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002114 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002115 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002116 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002117 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002118 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(del->uniques[u].flags),
2119 del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002120 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002121 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002122 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(del->dflts[u].flags),
2123 del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002124 }
2125 }
2126
2127 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002128 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002129 }
2130
2131 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002132 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002133}
2134
Michal Vasko7c8439f2020-08-05 13:25:19 +02002135static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002136yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002137{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002138 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139
Radek Krejcid3ca0632019-04-16 16:54:54 +02002140 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002141 if (modp->imports[u].flags & LYS_INTERNAL) {
2142 continue;
2143 }
2144
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002145 YPR_EXTRA_LINE_PRINT(pctx);
2146 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002148 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002149 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, 0, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002150 if (modp->imports[u].rev[0]) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002151 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, 0, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002152 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002153 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, 0, modp->imports[u].exts);
2154 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, 0, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002156 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002157 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002158 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002159
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002161 if (modp->includes[u].injected) {
2162 /* do not print the includes injected from submodules */
2163 continue;
2164 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002165 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002166 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 +01002167 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002169 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002170 if (modp->includes[u].rev[0]) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002171 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, 0, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002173 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, 0, modp->includes[u].exts);
2174 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, 0, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002175 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002176 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002177 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002178 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002179 }
2180 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002181 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002182}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002183
Michal Vasko7c8439f2020-08-05 13:25:19 +02002184static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002185yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002186{
2187 LY_ARRAY_COUNT_TYPE u;
2188 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002189 struct lysp_node_action *action;
2190 struct lysp_node_notif *notif;
2191 struct lysp_node_grp *grp;
2192 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002193
Radek Krejcid3ca0632019-04-16 16:54:54 +02002194 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002195 YPR_EXTRA_LINE_PRINT(pctx);
2196 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002197 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002198
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002199 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002200
aPiecek6cf1d162023-11-08 16:07:00 +01002201 if (yprp_extension_has_printable_instances(modp->exts)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002202 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002203 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002204 }
2205
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002206 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002207
Radek Krejcid3ca0632019-04-16 16:54:54 +02002208 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002209 YPR_EXTRA_LINE_PRINT(pctx);
2210 yprp_feature(pctx, &modp->features[u]);
2211 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002212 }
2213
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002214 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002215
Radek Krejcid3ca0632019-04-16 16:54:54 +02002216 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002217 YPR_EXTRA_LINE_PRINT(pctx);
2218 yprp_identity(pctx, &modp->identities[u]);
2219 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002220 }
2221
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002222 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002223
Radek Krejcid3ca0632019-04-16 16:54:54 +02002224 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002225 YPR_EXTRA_LINE_PRINT(pctx);
2226 yprp_typedef(pctx, &modp->typedefs[u]);
2227 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002228 }
2229
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002230 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002231
Radek Krejci2a9fc652021-01-22 17:44:34 +01002232 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 YPR_EXTRA_LINE_PRINT(pctx);
2234 yprp_grouping(pctx, grp);
2235 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002236 }
2237
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002238 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002239
Radek Krejcid3ca0632019-04-16 16:54:54 +02002240 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002241 YPR_EXTRA_LINE_PRINT(pctx);
2242 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002243 }
2244
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002245 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002246
Radek Krejci2a9fc652021-01-22 17:44:34 +01002247 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002248 YPR_EXTRA_LINE_PRINT(pctx);
2249 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002250 }
2251
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002252 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002253
Radek Krejci2a9fc652021-01-22 17:44:34 +01002254 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002255 YPR_EXTRA_LINE_PRINT(pctx);
2256 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002257 }
2258
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002259 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002260
Radek Krejci2a9fc652021-01-22 17:44:34 +01002261 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002262 YPR_EXTRA_LINE_PRINT(pctx);
2263 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002264 }
2265
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002266 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002267
Radek Krejcid3ca0632019-04-16 16:54:54 +02002268 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002269 YPR_EXTRA_LINE_PRINT(pctx);
2270 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002271 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002272
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002273 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002274}
2275
2276LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002277yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002278{
2279 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002280 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002281 struct lys_ypr_ctx pctx_ = {
2282 .out = out,
2283 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002284 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002285 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002286 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002287 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002288
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002289 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002290 LEVEL++;
2291
2292 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002293 if (modp->version) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002294 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 +02002295 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002296 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modp->exts);
2297 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002298
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002299 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002300
Michal Vasko7c8439f2020-08-05 13:25:19 +02002301 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002302 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002303
2304 /* meta-stmts */
2305 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002306 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002307 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002308 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modp->exts);
2309 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modp->exts);
2310 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modp->exts);
2311 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002312
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002313 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002314
Michal Vasko7c8439f2020-08-05 13:25:19 +02002315 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002316 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002317 YPR_EXTRA_LINE_PRINT(pctx);
2318 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002319 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002320
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002321 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002322
Michal Vasko7c8439f2020-08-05 13:25:19 +02002323 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002324 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002325
2326 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002327 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002328 ly_print_flush(out);
2329
2330 return LY_SUCCESS;
2331}
2332
2333static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002334yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002335{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002336 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002337 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002338 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko72c6d642024-02-27 14:59:01 +01002339 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, 0, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002340 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002341 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002342}
2343
2344LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002345yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002346{
2347 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002348 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002349 .out = out,
2350 .level = 0,
2351 .options = options,
2352 .module = submodp->mod,
2353 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002354 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002355
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002356 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002357 LEVEL++;
2358
2359 /* submodule-header-stmts */
2360 if (submodp->version) {
Michal Vasko72c6d642024-02-27 14:59:01 +01002361 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 +02002362 }
2363
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002364 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002365
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002366 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002367
Michal Vasko7c8439f2020-08-05 13:25:19 +02002368 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002369 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002370
2371 /* meta-stmts */
2372 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002373 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002374 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002375 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, 0, submodp->exts);
2376 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, 0, submodp->exts);
2377 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, 0, submodp->exts);
2378 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, 0, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002379
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002380 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002381
Michal Vasko7c8439f2020-08-05 13:25:19 +02002382 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002383 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002384 YPR_EXTRA_LINE_PRINT(pctx);
2385 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002386 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002387
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002388 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002389
Michal Vasko7c8439f2020-08-05 13:25:19 +02002390 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002391 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002392
2393 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002394 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002395 ly_print_flush(out);
2396
2397 return LY_SUCCESS;
2398}
2399
2400LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002401yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002402{
Michal Vasko331303f2022-08-22 09:51:57 +02002403 struct lys_ypr_ctx pctx_ = {
2404 .out = out,
2405 .level = 0,
2406 .options = options,
2407 .module = node->module,
2408 .schema = LYS_YPR_COMPILED
2409 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002410
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002411 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002412
2413 ly_print_flush(out);
2414 return LY_SUCCESS;
2415}
2416
2417LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002418yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002419{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002420 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002421 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002422 struct lys_ypr_ctx pctx_ = {
2423 .out = out,
2424 .level = 0,
2425 .options = options,
2426 .module = module,
2427 .schema = LYS_YPR_COMPILED
2428 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002429
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002430 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002431 LEVEL++;
2432
Radek Krejci693262f2019-04-29 15:23:20 +02002433 /* module-header-stmts */
Michal Vasko72c6d642024-02-27 14:59:01 +01002434 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modc->exts);
2435 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002436
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002437 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002438
Michal Vasko7c8439f2020-08-05 13:25:19 +02002439 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002440
2441 /* meta-stmts */
2442 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002443 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002444 }
Michal Vasko72c6d642024-02-27 14:59:01 +01002445 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modc->exts);
2446 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modc->exts);
2447 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modc->exts);
2448 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002449
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002450 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002451
Radek Krejci693262f2019-04-29 15:23:20 +02002452 /* revision-stmts */
2453 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002454 YPR_EXTRA_LINE_PRINT(pctx);
2455 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2456 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002457 }
2458
2459 /* body-stmts */
2460 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002461 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002462 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002463 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002464 }
2465
Radek Krejci80d281e2020-09-14 17:42:54 +02002466 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002467 YPR_EXTRA_LINE_PRINT(pctx);
2468 yprc_identity(pctx, &module->identities[u]);
2469 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002470 }
2471
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002472 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002473 struct lysc_node *data;
2474 struct lysc_node_action *rpc;
2475 struct lysc_node_notif *notif;
2476
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002477 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002478 YPR_EXTRA_LINE_PRINT(pctx);
2479 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002480 }
Radek Krejci693262f2019-04-29 15:23:20 +02002481
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002482 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002483
Radek Krejci2a9fc652021-01-22 17:44:34 +01002484 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002485 YPR_EXTRA_LINE_PRINT(pctx);
2486 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002487 }
Radek Krejci693262f2019-04-29 15:23:20 +02002488
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002489 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002490
Radek Krejci2a9fc652021-01-22 17:44:34 +01002491 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002492 YPR_EXTRA_LINE_PRINT(pctx);
2493 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002494 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002495
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002496 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002497 }
2498
2499 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002500 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002501 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002502
2503 return LY_SUCCESS;
2504}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002505
Michal Vaskocc28b152022-08-23 14:44:54 +02002506LIBYANG_API_DEF void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002507lyplg_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 +01002508{
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002509 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002510 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002511 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002512
2513 LY_ARRAY_FOR(ext->substmts, u) {
2514 switch (ext->substmts[u].stmt) {
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002515 case LY_STMT_NOTIFICATION:
2516 case LY_STMT_INPUT:
2517 case LY_STMT_OUTPUT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002518 case LY_STMT_ACTION:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002519 case LY_STMT_RPC:
2520 case LY_STMT_ANYDATA:
2521 case LY_STMT_ANYXML:
2522 case LY_STMT_CASE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002523 case LY_STMT_CHOICE:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002524 case LY_STMT_CONTAINER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002525 case LY_STMT_LEAF:
2526 case LY_STMT_LEAF_LIST:
2527 case LY_STMT_LIST:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002528 case LY_STMT_USES: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002529 const struct lysc_node *node;
2530
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002531 if (data_printed) {
2532 break;
2533 }
2534
Radek Krejciadcf63d2021-02-09 10:21:18 +01002535 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002536 ypr_open(pctx->out, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002537 if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002538 yprc_notification(pctx, (struct lysc_node_notif *)node);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002539 } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) {
2540 yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag);
2541 } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) {
2542 yprc_action(pctx, (struct lysc_node_action *)node);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002543 } else {
2544 yprc_node(pctx, node);
2545 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002546 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002547
2548 /* all data nodes are stored in a linked list so all were printed */
2549 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002550 break;
2551 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002552 case LY_STMT_ARGUMENT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002553 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002554 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002555 case LY_STMT_ERROR_APP_TAG:
2556 case LY_STMT_ERROR_MESSAGE:
2557 case LY_STMT_KEY:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002558 case LY_STMT_MODIFIER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002559 case LY_STMT_NAMESPACE:
2560 case LY_STMT_ORGANIZATION:
2561 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002562 case LY_STMT_REFERENCE:
2563 case LY_STMT_UNITS:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002564 if (*(const char **)ext->substmts[u].storage) {
2565 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01002566 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, 0, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002567 }
2568 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002569 case LY_STMT_BIT:
2570 case LY_STMT_ENUM: {
2571 const struct lysc_type_bitenum_item *items = *(struct lysc_type_bitenum_item **)ext->substmts[u].storage;
2572
2573 yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag);
2574 break;
2575 }
2576 case LY_STMT_CONFIG:
2577 ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2578 break;
2579 case LY_STMT_EXTENSION_INSTANCE:
2580 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0,
2581 *(struct lysc_ext_instance **)ext->substmts[u].storage, flag);
2582 break;
2583 case LY_STMT_FRACTION_DIGITS:
2584 if (*(uint8_t *)ext->substmts[u].storage) {
2585 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, *(uint8_t *)ext->substmts[u].storage, flag);
2586 }
2587 break;
2588 case LY_STMT_IDENTITY: {
2589 const struct lysc_ident *idents = *(struct lysc_ident **)ext->substmts[u].storage;
2590
2591 LY_ARRAY_FOR(idents, v) {
2592 yprc_identity(pctx, &idents[v]);
2593 }
2594 break;
2595 }
2596 case LY_STMT_LENGTH:
2597 if (*(struct lysc_range **)ext->substmts[u].storage) {
2598 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_STRING, flag);
2599 }
2600 break;
2601 case LY_STMT_MANDATORY:
2602 ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2603 break;
2604 case LY_STMT_MAX_ELEMENTS: {
2605 uint32_t max = *(uint32_t *)ext->substmts[u].storage;
2606
2607 if (max) {
2608 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag);
2609 } else {
2610 ypr_open(pctx->out, flag);
Michal Vasko72c6d642024-02-27 14:59:01 +01002611 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, ext->exts);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002612 }
2613 break;
2614 }
2615 case LY_STMT_MIN_ELEMENTS:
2616 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage, flag);
2617 break;
2618 case LY_STMT_ORDERED_BY:
2619 ypr_open(pctx->out, flag);
2620 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0,
Michal Vasko72c6d642024-02-27 14:59:01 +01002621 (*(uint16_t *)ext->substmts[u].storage & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002622 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002623 case LY_STMT_MUST: {
2624 const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
2625
2626 LY_ARRAY_FOR(musts, v) {
2627 yprc_must(pctx, &musts[v], flag);
2628 }
2629 break;
2630 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002631 case LY_STMT_PATTERN: {
2632 const struct lysc_pattern *patterns = *(struct lysc_pattern **)ext->substmts[u].storage;
2633
2634 LY_ARRAY_FOR(patterns, v) {
2635 yprc_pattern(pctx, &patterns[v], flag);
2636 }
2637 break;
2638 }
2639 case LY_STMT_POSITION:
2640 if (*(int64_t *)ext->substmts[u].storage) {
2641 ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2642 }
2643 break;
2644 case LY_STMT_VALUE:
2645 if (*(int64_t *)ext->substmts[u].storage) {
2646 ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2647 }
2648 break;
2649 case LY_STMT_RANGE:
2650 if (*(struct lysc_range **)ext->substmts[u].storage) {
2651 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_UINT64, flag);
2652 }
2653 break;
2654 case LY_STMT_REQUIRE_INSTANCE:
2655 ypr_open(pctx->out, flag);
2656 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage ? "true" : "false",
Michal Vasko72c6d642024-02-27 14:59:01 +01002657 0, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002658 break;
2659 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002660 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002661 break;
2662 case LY_STMT_TYPE:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002663 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2664 ypr_open(pctx->out, flag);
2665 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002666 }
2667 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002668 case LY_STMT_WHEN:
2669 yprc_when(pctx, *(struct lysc_when **)ext->substmts[u].storage, flag);
2670 break;
2671 case LY_STMT_AUGMENT:
2672 case LY_STMT_BASE:
2673 case LY_STMT_BELONGS_TO:
2674 case LY_STMT_DEFAULT:
2675 case LY_STMT_DEVIATE:
2676 case LY_STMT_DEVIATION:
2677 case LY_STMT_EXTENSION:
2678 case LY_STMT_FEATURE:
2679 case LY_STMT_GROUPING:
2680 case LY_STMT_IF_FEATURE:
2681 case LY_STMT_IMPORT:
2682 case LY_STMT_INCLUDE:
2683 case LY_STMT_MODULE:
2684 case LY_STMT_PATH:
2685 case LY_STMT_PREFIX:
2686 case LY_STMT_REFINE:
2687 case LY_STMT_REVISION:
2688 case LY_STMT_REVISION_DATE:
2689 case LY_STMT_SUBMODULE:
2690 case LY_STMT_TYPEDEF:
2691 case LY_STMT_UNIQUE:
2692 case LY_STMT_YANG_VERSION:
2693 case LY_STMT_YIN_ELEMENT:
2694 /* nothing to do */
2695 break;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002696 default:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002697 LOGINT(pctx->module->ctx);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002698 break;
2699 }
2700 }
2701}