blob: 9dd95a8be85c11f083bc0d3d1eab5e704e0b0ed0 [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
Radek Krejciaa14a0c2020-09-04 11:16:47 +020049#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
50
Michal Vasko61ad1ff2022-02-10 15:48:39 +010051#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
52#define YPR_EXTRA_LINE_PRINT(PCTX) \
53 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
54 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020055 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010056 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020057 } \
58 }
59
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010060/**
61 * @brief Compiled YANG printer context
62 *
63 * Note that the YANG extensions API provides getter to the members for the extension plugins.
64 */
65struct lys_ypr_ctx {
66 union {
67 struct {
68 struct ly_out *out; /**< output specification */
69 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020070 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010071 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
72 const struct lys_module *module; /**< schema to print */
73 };
74 struct lyspr_ctx printer_ctx;
75 };
76
77 /* YANG printer specific members */
78 enum lys_ypr_schema_type schema; /**< type of the schema to print */
79};
80
81/**
Radek Krejcie7b95092019-05-15 11:03:07 +020082 * @brief Print the given text as content of a double quoted YANG string,
83 * including encoding characters that have special meanings. The quotation marks
84 * are not printed.
85 *
86 * Follows RFC 7950, section 6.1.3.
87 *
88 * @param[in] out Output specification.
89 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020090 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020091 * the @p text is printed completely as a NULL-terminated string.
92 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020093static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020094ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020095{
Radek Krejci1deb5be2020-08-26 16:43:36 +020096 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020097 const char *start;
98 char special = 0;
99
100 if (!len) {
101 return;
102 }
103
104 if (len < 0) {
105 len = strlen(text);
106 }
107
108 start = text;
109 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200110 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200111 switch (text[i]) {
112 case '\n':
113 case '\t':
114 case '\"':
115 case '\\':
116 special = text[i];
117 break;
118 default:
119 ++start_len;
120 break;
121 }
122
123 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200124 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200125 switch (special) {
126 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200127 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200128 break;
129 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200130 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200131 break;
132 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200133 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200134 break;
135 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200136 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200137 break;
138 }
139
140 start += start_len + 1;
141 start_len = 0;
142
143 special = 0;
144 }
145 }
146
Michal Vasko5233e962020-08-14 14:26:20 +0200147 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200148}
149
150static void
Radek Krejci857189e2020-09-01 13:26:36 +0200151ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200152{
153 if (flag && !*flag) {
154 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200155 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200156 }
157}
158
159static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100160ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200161{
162 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100163 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200164 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100165 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200166 }
167}
168
169static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100170ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, ly_bool singleline, ly_bool closed)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200171{
172 const char *s, *t;
173
174 if (singleline) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100175 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200176 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100177 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200178 LEVEL++;
179
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100180 ly_print_(pctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200181 }
182 t = text;
183 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100184 ypr_encode(pctx->out, t, s - t);
185 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200186 t = s + 1;
187 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100188 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200189 }
190 }
191
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100192 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200193 if (closed) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100194 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200195 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100196 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200197 }
198 if (!singleline) {
199 LEVEL--;
200 }
201}
202
203static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100204yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200205{
206 struct lysp_stmt *childstmt;
207 const char *s, *t;
208
209 if (stmt->arg) {
210 if (stmt->flags) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100211 ly_print_(pctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200212 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100213 ly_print_(pctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200214 t = stmt->arg;
215 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100216 ypr_encode(pctx->out, t, s - t);
217 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200218 t = s + 1;
219 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100220 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200221 }
222 }
223 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100224 ypr_encode(pctx->out, t, strlen(t));
225 ly_print_(pctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200226 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100227 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200228 }
229 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100230 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200231 }
232
233 if (stmt->child) {
234 LEVEL++;
235 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100236 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200237 }
238 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100239 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200240 }
241}
242
Radek Krejcid3ca0632019-04-16 16:54:54 +0200243static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200244yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
245 struct lysp_ext_instance *ext, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200246{
Radek Krejcid3ca0632019-04-16 16:54:54 +0200247 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200248 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200249
Michal Vaskob26d09d2022-08-22 09:52:19 +0200250 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
251 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200252 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100253
Michal Vaskob26d09d2022-08-22 09:52:19 +0200254 ypr_open(pctx->out, flag);
255
Michal Vasko193dacd2022-10-13 08:43:05 +0200256 if (ext->def->argname) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200257 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200258 ypr_encode(pctx->out, ext->argument, -1);
259 ly_print_(pctx->out, "\"");
260 } else {
261 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
262 }
263
264 child_presence = 0;
265 LEVEL++;
266 LY_LIST_FOR(ext->child, stmt) {
267 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200268 continue;
269 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200270 if (!child_presence) {
271 ly_print_(pctx->out, " {\n");
272 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200273 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200274 yprp_stmt(pctx, stmt);
275 }
276 LEVEL--;
277 if (child_presence) {
278 ly_print_(pctx->out, "%*s}\n", INDENT);
279 } else {
280 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 }
282}
283
Radek Krejci693262f2019-04-29 15:23:20 +0200284static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200285yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
286 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200287{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200288 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200289
290 LY_ARRAY_FOR(exts, u) {
aPiecek6cf1d162023-11-08 16:07:00 +0100291 if (exts[u].flags & LYS_INTERNAL) {
292 continue;
293 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200294 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
295 }
296}
297
aPiecek6cf1d162023-11-08 16:07:00 +0100298static ly_bool
299yprp_extension_has_printable_instances(struct lysp_ext_instance *exts)
300{
301 LY_ARRAY_COUNT_TYPE u;
302
303 LY_ARRAY_FOR(exts, u) {
304 if (!(exts[u].flags & LYS_INTERNAL)) {
305 return 1;
306 }
307 }
308
309 return 0;
310}
311
Michal Vaskob26d09d2022-08-22 09:52:19 +0200312static void
313yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
314 struct lysc_ext_instance *exts, ly_bool *flag)
315{
316 LY_ARRAY_COUNT_TYPE u;
317 ly_bool inner_flag;
318
319 LY_ARRAY_FOR(exts, u) {
320 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
321 return;
322 }
323
324 ypr_open(pctx->out, flag);
325 if (exts[u].argument) {
326 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
327 ypr_encode(pctx->out, exts[u].argument, -1);
328 ly_print_(pctx->out, "\"");
329 } else {
330 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
331 }
332
333 LEVEL++;
334 inner_flag = 0;
335 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
336
Michal Vasko941e0562022-10-18 10:35:00 +0200337 if (exts[u].def->plugin && exts[u].def->plugin->printer_info) {
338 exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200339 }
340
341 LEVEL--;
342 ypr_close(pctx, inner_flag);
343 }
344}
345
346static void
347ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts)
348{
Radek Krejci857189e2020-09-01 13:26:36 +0200349 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200350
351 if (!text) {
352 /* nothing to print */
353 return;
354 }
355
Michal Vaskob872d0f2022-12-08 09:36:54 +0100356 if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) {
357 ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200358 } else {
Michal Vaskob872d0f2022-12-08 09:36:54 +0100359 ypr_text(pctx, lys_stmt_str(substmt), text, (lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200360 }
361
362 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200363 if (pctx->schema == LYS_YPR_PARSED) {
364 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
365 } else {
366 yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200367 }
368 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100369 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200370}
371
372static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100373ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
Michal Vasko2bf4af42023-01-04 12:08:38 +0100374 unsigned long attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200375{
376 char *str;
377
Radek Krejci1deb5be2020-08-26 16:43:36 +0200378 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100379 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380 return;
381 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100382 ypr_open(pctx->out, flag);
383 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384 free(str);
385}
386
387static void
Michal Vasko2bf4af42023-01-04 12:08:38 +0100388ypr_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 +0100389 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200390{
391 char *str;
392
Radek Krejci1deb5be2020-08-26 16:43:36 +0200393 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100394 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200395 return;
396 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397 ypr_open(pctx->out, flag);
398 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200399 free(str);
400}
401
402static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100403yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200404{
405 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100406 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200408 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100409 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
410 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200411 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100412 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200413 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200415 }
416}
417
418static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100419ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200420{
421 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100422 ypr_open(pctx->out, flag);
423 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200424 }
425}
426
427static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429{
430 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100431 ypr_open(pctx->out, flag);
432 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433 }
434}
435
436static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100437ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200438{
439 const char *status = NULL;
440
441 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100442 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200443 status = "current";
444 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100445 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200446 status = "deprecated";
447 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100448 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449 status = "obsolete";
450 }
Radek Krejci693262f2019-04-29 15:23:20 +0200451
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100452 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453}
454
455static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100456ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200457{
458 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100459 ypr_open(pctx->out, flag);
460 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 }
462}
463
464static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100465ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200466{
467 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100468 ypr_open(pctx->out, flag);
469 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200470 }
471}
472
473static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100474yprp_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 +0200475{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200476 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200477 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478
Michal Vasko7f45cf22020-10-01 12:49:44 +0200479 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100480 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481 extflag = 0;
482
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100483 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200484
485 /* extensions */
486 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200487 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200488 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100489 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200490 }
491}
492
493static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100494yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200495{
Radek Krejci857189e2020-09-01 13:26:36 +0200496 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200497 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200498
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100499 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200500 LEVEL++;
501
Michal Vaskob26d09d2022-08-22 09:52:19 +0200502 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200503
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100504 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100505 ypr_open(pctx->out, &flag);
506 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200507 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200509 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100510 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 +0200511 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200512 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200513 }
514 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100515 (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 +0100516 ypr_open(pctx->out, &flag2);
517 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200518 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200519 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100520 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200521 }
522
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100523 ypr_status(pctx, ext->flags, ext->exts, &flag);
524 ypr_description(pctx, ext->dsc, ext->exts, &flag);
525 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200526
527 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100528 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200529}
530
531static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100532yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533{
Radek Krejci857189e2020-09-01 13:26:36 +0200534 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100536 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200537 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200538 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100539 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
540 ypr_status(pctx, feat->flags, feat->exts, &flag);
541 ypr_description(pctx, feat->dsc, feat->exts, &flag);
542 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200543 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100544 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200545}
546
547static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100548yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200549{
Radek Krejci857189e2020-09-01 13:26:36 +0200550 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200551 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200552
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100553 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200554 LEVEL++;
555
Michal Vaskob26d09d2022-08-22 09:52:19 +0200556 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100557 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200558
559 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100560 ypr_open(pctx->out, &flag);
561 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200562 }
563
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100564 ypr_status(pctx, ident->flags, ident->exts, &flag);
565 ypr_description(pctx, ident->dsc, ident->exts, &flag);
566 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200567
568 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100569 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200570}
571
572static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100573yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200574{
Radek Krejci857189e2020-09-01 13:26:36 +0200575 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200576 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200577
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100578 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200579 LEVEL++;
580
Michal Vaskob26d09d2022-08-22 09:52:19 +0200581 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200582
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100583 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200584 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100585 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200586 }
587
Radek Krejci693262f2019-04-29 15:23:20 +0200588 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100589 if (pctx->module != ident->derived[u]->module) {
590 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 +0200591 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100592 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200593 }
594 }
595
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100596 ypr_status(pctx, ident->flags, ident->exts, &flag);
597 ypr_description(pctx, ident->dsc, ident->exts, &flag);
598 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200599
600 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100601 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200602}
603
604static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100605yprp_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 +0200606{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100607 ly_bool inner_flag = 0, singleline;
608 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200609
610 if (!restr) {
611 return;
612 }
613
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100614 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100615 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
616 restr->arg.str : restr->arg.str + 1;
617 singleline = strchr(text, '\n') ? 0 : 1;
Michal Vasko193dacd2022-10-13 08:43:05 +0200618 ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200619
620 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200621 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100622 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200623 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100624 ypr_open(pctx->out, &inner_flag);
625 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200626 }
627 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100628 ypr_open(pctx->out, &inner_flag);
629 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200630 }
631 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100632 ypr_open(pctx->out, &inner_flag);
633 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200634 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100635 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
636 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200637
Radek Krejcid3ca0632019-04-16 16:54:54 +0200638 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100639 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200640}
641
642static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100643yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200644{
Radek Krejci857189e2020-09-01 13:26:36 +0200645 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200646
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100647 ypr_open(pctx->out, flag);
Michal Vasko2e3af132023-08-11 11:29:26 +0200648 ypr_text(pctx, "must", must->cond->expr, 1, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200649
650 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200651 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200652 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100653 ypr_open(pctx->out, &inner_flag);
654 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200655 }
656 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100657 ypr_open(pctx->out, &inner_flag);
658 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200659 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
661 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200662
663 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100664 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200665}
666
667static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100668yprc_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 +0200669{
Radek Krejci857189e2020-09-01 13:26:36 +0200670 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200671 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200672
Radek Krejci334ccc72019-06-12 13:49:29 +0200673 if (!range) {
674 return;
675 }
676
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100677 ypr_open(pctx->out, flag);
678 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200679 LY_ARRAY_FOR(range->parts, u) {
680 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100681 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200682 }
683 if (range->parts[u].max_64 == range->parts[u].min_64) {
684 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100685 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200686 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100687 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200688 }
689 } else {
690 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100691 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200692 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100693 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200694 }
695 }
696 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100697 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200698
699 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200700 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200701 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100702 ypr_open(pctx->out, &inner_flag);
703 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200704 }
705 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100706 ypr_open(pctx->out, &inner_flag);
707 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200708 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100709 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
710 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200711
712 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100713 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200714}
715
716static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100717yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200718{
Radek Krejci857189e2020-09-01 13:26:36 +0200719 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200720
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100721 ypr_open(pctx->out, flag);
722 ly_print_(pctx->out, "%*spattern \"", INDENT);
723 ypr_encode(pctx->out, pattern->expr, -1);
724 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200725
726 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200727 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200728 if (pattern->inverted) {
729 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100730 ypr_open(pctx->out, &inner_flag);
731 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200732 }
733 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100734 ypr_open(pctx->out, &inner_flag);
735 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200736 }
737 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100738 ypr_open(pctx->out, &inner_flag);
739 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200740 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100741 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
742 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200743
744 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100745 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200746}
747
748static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200749yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag)
750{
751 LY_ARRAY_COUNT_TYPE u;
752 const struct lysc_type_bitenum_item *item;
753 ly_bool inner_flag;
754
755 assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM));
756
757 LY_ARRAY_FOR(items, u) {
758 item = &items[u];
759 inner_flag = 0;
760
761 ypr_open(pctx->out, flag);
762 ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum");
763 ypr_encode(pctx->out, item->name, -1);
764 ly_print_(pctx->out, "\"");
765 LEVEL++;
766 if (basetype == LY_TYPE_BITS) {
767 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
768 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
769 } else { /* LY_TYPE_ENUM */
770 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
771 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
772 }
773 ypr_status(pctx, item->flags, item->exts, &inner_flag);
774 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
775 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
776 LEVEL--;
777 ypr_close(pctx, inner_flag);
778 }
779}
780
781static void
782yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200783{
Radek Krejci857189e2020-09-01 13:26:36 +0200784 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200785
786 if (!when) {
787 return;
788 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100789 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200790
Michal Vasko2e3af132023-08-11 11:29:26 +0200791 ypr_text(pctx, "when", when->cond, 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200792
793 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200794 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100795 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
796 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200797 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100798 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200799}
800
801static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200802yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200803{
Radek Krejci857189e2020-09-01 13:26:36 +0200804 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200805
806 if (!when) {
807 return;
808 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100809 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200810
Michal Vasko2e3af132023-08-11 11:29:26 +0200811 ypr_text(pctx, "when", when->cond->expr, 1, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200812
813 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200814 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100815 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
816 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200817 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100818 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200819}
820
821static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200822yprp_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 +0200823{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200824 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200825 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200826
827 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100828 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200829 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100830 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200831 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100832 ly_print_(pctx->out, "%*senum \"", INDENT);
833 ypr_encode(pctx->out, items[u].name, -1);
834 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200835 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200836 inner_flag = 0;
837 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200838 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100839 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840 if (items[u].flags & LYS_SET_VALUE) {
841 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100842 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200843 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100844 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200845 }
846 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100847 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
848 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
849 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200850 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100851 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200852 }
853}
854
855static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100856yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200857{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200858 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200859 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200860
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100861 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200862 LEVEL++;
863
Michal Vaskob26d09d2022-08-22 09:52:19 +0200864 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200865
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100866 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
867 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200868 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100869 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200870 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200871 yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
872 yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200873
874 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100875 ypr_open(pctx->out, &flag);
876 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200877 }
878 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100879 ypr_open(pctx->out, &flag);
880 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200881 }
882 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100883 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200884 }
885 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100886 ypr_open(pctx->out, &flag);
887 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200888 }
889 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100890 ypr_open(pctx->out, &flag);
891 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200892 }
893
894 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100895 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200896}
897
898static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100899yprc_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 +0200900 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200901{
Radek Krejci857189e2020-09-01 13:26:36 +0200902 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200903 const char *str;
904
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100905 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
906 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200907 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200908 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200909 }
910}
911
912static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100913yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200914{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200915 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200916 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200917
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100918 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200919 LEVEL++;
920
Michal Vaskob26d09d2022-08-22 09:52:19 +0200921 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200922
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200923 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200924 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200925 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200926
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100927 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200928 break;
929 }
930 case LY_TYPE_UINT8:
931 case LY_TYPE_UINT16:
932 case LY_TYPE_UINT32:
933 case LY_TYPE_UINT64:
934 case LY_TYPE_INT8:
935 case LY_TYPE_INT16:
936 case LY_TYPE_INT32:
937 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200938 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200939
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100940 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200941 break;
942 }
943 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200944 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200945
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100946 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200947 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100948 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200949 }
950 break;
951 }
952 case LY_TYPE_BITS:
953 case LY_TYPE_ENUM: {
954 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200955 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200956
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200957 yprc_bits_enum(pctx, bits->bits, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200958 break;
959 }
960 case LY_TYPE_BOOL:
961 case LY_TYPE_EMPTY:
962 /* nothing to do */
963 break;
964 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200965 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200966
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100967 ypr_open(pctx->out, &flag);
968 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
969 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200970 break;
971 }
972 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200973 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200974
Radek Krejci693262f2019-04-29 15:23:20 +0200975 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100976 ypr_open(pctx->out, &flag);
977 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200978 }
979 break;
980 }
981 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200982 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200983
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100984 ypr_open(pctx->out, &flag);
985 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200986 break;
987 }
988 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200989 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200990
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100991 ypr_open(pctx->out, &flag);
992 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
993 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
994 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200995 break;
996 }
997 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200998 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200999
Radek Krejci693262f2019-04-29 15:23:20 +02001000 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001001 ypr_open(pctx->out, &flag);
1002 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02001003 }
1004 break;
1005 }
1006 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001007 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +02001008 }
1009
1010 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001011 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001012}
1013
1014static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001015yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001016{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001017 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001018 LEVEL++;
1019
Michal Vaskob26d09d2022-08-22 09:52:19 +02001020 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001021
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001022 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001023
1024 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001025 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001027 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001028 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001029 }
1030
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001031 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1032 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1033 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001034
1035 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001036 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001037}
1038
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001039static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1040static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1041static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1042static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001043
1044static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001045yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001046{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001047 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001048 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001050 struct lysp_node_action *action;
1051 struct lysp_node_notif *notif;
1052 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001053
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001054 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001055 LEVEL++;
1056
Michal Vaskob26d09d2022-08-22 09:52:19 +02001057 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001058 ypr_status(pctx, grp->flags, grp->exts, &flag);
1059 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1060 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001061
1062 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001063 ypr_open(pctx->out, &flag);
1064 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001065 }
1066
Radek Krejci2a9fc652021-01-22 17:44:34 +01001067 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001068 ypr_open(pctx->out, &flag);
1069 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070 }
1071
Radek Krejci01180ac2021-01-27 08:48:22 +01001072 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001073 ypr_open(pctx->out, &flag);
1074 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 }
1076
Radek Krejci2a9fc652021-01-22 17:44:34 +01001077 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001078 ypr_open(pctx->out, &flag);
1079 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001080 }
1081
1082 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001083 ypr_open(pctx->out, &flag);
1084 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001085 }
1086
1087 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001088 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001089}
1090
1091static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001092yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001093{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001094 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001095 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001096 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001097
Radek Krejci01180ac2021-01-27 08:48:22 +01001098 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001099 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100 return;
1101 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001102 ypr_open(pctx->out, flag);
1103 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001104
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001105 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106 LEVEL++;
1107
Michal Vaskob26d09d2022-08-22 09:52:19 +02001108 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001109 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001110 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001111 }
1112 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001113 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001114 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001115 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001116 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001117 }
1118
Radek Krejci01180ac2021-01-27 08:48:22 +01001119 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001120 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001121 }
1122
1123 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001124 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001125}
1126
1127static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001128yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001129{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001130 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001131 struct lysc_node *data;
1132
Radek Krejci01180ac2021-01-27 08:48:22 +01001133 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001134 /* input/output is empty */
1135 return;
1136 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001137 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001138
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001139 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001140 LEVEL++;
1141
Michal Vasko193dacd2022-10-13 08:43:05 +02001142 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001143 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001144 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001145 }
1146
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001147 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001148 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001149 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001150 }
Radek Krejci693262f2019-04-29 15:23:20 +02001151 }
1152
1153 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001154 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001155}
1156
1157static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001158yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001159{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001160 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001161 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001162 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001163 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001164
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001165 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001166
1167 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001168 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001169 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001170
1171 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001172 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001173 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001174 ypr_status(pctx, notif->flags, notif->exts, &flag);
1175 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1176 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001177
1178 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001179 ypr_open(pctx->out, &flag);
1180 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001181 }
1182
Radek Krejci2a9fc652021-01-22 17:44:34 +01001183 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001184 ypr_open(pctx->out, &flag);
1185 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001186 }
1187
Radek Krejci01180ac2021-01-27 08:48:22 +01001188 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001189 ypr_open(pctx->out, &flag);
1190 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001191 }
1192
1193 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001194 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001195}
1196
1197static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001198yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001199{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001200 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001201 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001202 struct lysc_node *data;
1203
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001204 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001205
1206 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001207 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001208
1209 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001210 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001211 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001212 ypr_status(pctx, notif->flags, notif->exts, &flag);
1213 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1214 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001215
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001216 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001217 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001218 ypr_open(pctx->out, &flag);
1219 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001220 }
Radek Krejci693262f2019-04-29 15:23:20 +02001221 }
1222
1223 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001224 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001225}
1226
1227static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001228yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001229{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001230 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001231 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001232 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001233
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001234 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001235
1236 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001237 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001238 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1239 ypr_status(pctx, action->flags, action->exts, &flag);
1240 ypr_description(pctx, action->dsc, action->exts, &flag);
1241 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001242
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001243 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001244
Radek Krejcid3ca0632019-04-16 16:54:54 +02001245 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001246 ypr_open(pctx->out, &flag);
1247 YPR_EXTRA_LINE_PRINT(pctx);
1248 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001249 }
1250
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001251 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001252
Radek Krejci2a9fc652021-01-22 17:44:34 +01001253 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001254 ypr_open(pctx->out, &flag);
1255 YPR_EXTRA_LINE_PRINT(pctx);
1256 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001257 }
1258
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001259 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001260
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001261 yprp_inout(pctx, &action->input, &flag);
1262 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001263
1264 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001265 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001266}
1267
1268static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001269yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001270{
Radek Krejci857189e2020-09-01 13:26:36 +02001271 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001272
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001273 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001274
1275 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001276 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001277 ypr_status(pctx, action->flags, action->exts, &flag);
1278 ypr_description(pctx, action->dsc, action->exts, &flag);
1279 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001280
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001281 yprc_inout(pctx, &action->input, &flag);
1282 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001283
1284 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001285 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001286}
1287
1288static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001289yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001290{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001291 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292 LEVEL++;
1293
Michal Vasko193dacd2022-10-13 08:43:05 +02001294 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001295 yprp_when(pctx, lysp_node_when(node), flag);
1296 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001297}
1298
1299static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001300yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001301{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001302 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001303 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001304
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001305 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001306 LEVEL++;
1307
Michal Vasko193dacd2022-10-13 08:43:05 +02001308 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001309
1310 when = lysc_node_when(node);
1311 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001312 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001313 }
Radek Krejci693262f2019-04-29 15:23:20 +02001314}
1315
Michal Vaskob26d09d2022-08-22 09:52:19 +02001316/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001317#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001318 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001319 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001320 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001321 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001322 ypr_status(pctx, node->flags, node->exts, flag); \
1323 ypr_description(pctx, node->dsc, node->exts, flag); \
1324 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001325
1326static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001327yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001328{
1329 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001330}
1331
1332static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001333yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001334{
1335 YPR_NODE_COMMON2;
1336}
1337
1338#undef YPR_NODE_COMMON2
1339
1340static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001341yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001342{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001343 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001344 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001345 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001346 struct lysp_node_action *action;
1347 struct lysp_node_notif *notif;
1348 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001349 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1350
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001351 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001352
1353 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001354 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001355 }
1356 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001357 ypr_open(pctx->out, &flag);
1358 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001359 }
1360
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001361 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001362
1363 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001364 ypr_open(pctx->out, &flag);
1365 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001366 }
1367
Radek Krejci2a9fc652021-01-22 17:44:34 +01001368 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001369 ypr_open(pctx->out, &flag);
1370 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001371 }
1372
1373 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001374 ypr_open(pctx->out, &flag);
1375 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001376 }
1377
Radek Krejci2a9fc652021-01-22 17:44:34 +01001378 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001379 ypr_open(pctx->out, &flag);
1380 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001381 }
1382
Radek Krejci2a9fc652021-01-22 17:44:34 +01001383 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001384 ypr_open(pctx->out, &flag);
1385 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001386 }
1387
1388 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001389 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001390}
1391
1392static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001393yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001394{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001395 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001396 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001397 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001398 struct lysc_node_action *action;
1399 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001400 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1401
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001402 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001403
1404 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001405 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001406 }
1407 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001408 ypr_open(pctx->out, &flag);
1409 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001410 }
1411
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001412 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001413
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001414 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001415 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001416 ypr_open(pctx->out, &flag);
1417 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001418 }
Radek Krejci693262f2019-04-29 15:23:20 +02001419
Radek Krejci2a9fc652021-01-22 17:44:34 +01001420 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001421 ypr_open(pctx->out, &flag);
1422 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001423 }
Radek Krejci693262f2019-04-29 15:23:20 +02001424
Radek Krejci2a9fc652021-01-22 17:44:34 +01001425 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001426 ypr_open(pctx->out, &flag);
1427 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001428 }
Radek Krejci693262f2019-04-29 15:23:20 +02001429 }
1430
1431 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001432 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001433}
1434
1435static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001436yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001437{
Radek Krejci857189e2020-09-01 13:26:36 +02001438 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001439 struct lysp_node *child;
1440 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1441
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001442 yprp_node_common1(pctx, node, &flag);
1443 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001444
1445 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001446 ypr_open(pctx->out, &flag);
1447 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001448 }
1449
1450 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001451 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001452}
1453
1454static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001455yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001456{
Radek Krejci857189e2020-09-01 13:26:36 +02001457 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001458 struct lysc_node *child;
1459
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001460 yprc_node_common1(pctx, &cs->node, &flag);
1461 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001462
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001463 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001464 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001465 ypr_open(pctx->out, &flag);
1466 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001467 }
Radek Krejci693262f2019-04-29 15:23:20 +02001468 }
1469
1470 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001471 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001472}
1473
1474static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001475yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001476{
Radek Krejci857189e2020-09-01 13:26:36 +02001477 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478 struct lysp_node *child;
1479 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1480
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001481 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001482
Michal Vasko7f45cf22020-10-01 12:49:44 +02001483 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001484 ypr_open(pctx->out, &flag);
1485 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001486 }
1487
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001488 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001489
1490 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001491 ypr_open(pctx->out, &flag);
1492 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001493 }
1494
1495 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001496 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001497}
1498
1499static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001500yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001501{
Radek Krejci857189e2020-09-01 13:26:36 +02001502 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001503 struct lysc_node_case *cs;
1504 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1505
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001506 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001507
1508 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001509 ypr_open(pctx->out, &flag);
1510 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001511 }
1512
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001513 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001514
Michal Vasko22df3f02020-08-24 13:29:22 +02001515 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001516 ypr_open(pctx->out, &flag);
1517 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001518 }
1519
1520 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001521 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001522}
1523
1524static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001525yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001526{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001527 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001528 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1529
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001530 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001531
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001532 yprp_type(pctx, &leaf->type);
1533 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001534 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001535 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001536 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001537 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001538
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001539 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001540
1541 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001542 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001543}
1544
1545static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001546yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001547{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001548 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001549 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1550
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001551 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001552
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001553 yprc_type(pctx, leaf->type);
1554 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001555 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001556 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001557 }
Radek Krejcia1911222019-07-22 17:24:50 +02001558
1559 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001560 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001561 }
Radek Krejci693262f2019-04-29 15:23:20 +02001562
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001563 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001564
1565 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001566 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001567}
1568
1569static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001570yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001571{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001572 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1574
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001575 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001576
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001577 yprp_type(pctx, &llist->type);
1578 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001580 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001581 }
1582 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001583 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001584 }
1585
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001586 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001587
1588 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001589 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001590 }
1591 if (llist->flags & LYS_SET_MAX) {
1592 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001593 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001594 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001595 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001596 }
1597 }
1598
1599 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001600 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001601 }
1602
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001603 ypr_status(pctx, node->flags, node->exts, NULL);
1604 ypr_description(pctx, node->dsc, node->exts, NULL);
1605 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001606
1607 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001608 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001609}
1610
1611static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001612yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001613{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001614 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001615 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1616
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001617 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001618
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001619 yprc_type(pctx, llist->type);
1620 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001621 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001622 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001623 }
1624 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001625 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001626 }
1627
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001628 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001629
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001630 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001631 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001632 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001633 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001634 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001635 }
1636
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001637 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001638
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001639 ypr_status(pctx, node->flags, node->exts, NULL);
1640 ypr_description(pctx, node->dsc, node->exts, NULL);
1641 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001642
1643 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001644 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001645}
1646
1647static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001648yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001649{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001650 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001651 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001653 struct lysp_node_action *action;
1654 struct lysp_node_notif *notif;
1655 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001656 struct lysp_node_list *list = (struct lysp_node_list *)node;
1657
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001658 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659
1660 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001661 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001662 }
1663 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001664 ypr_open(pctx->out, &flag);
1665 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001666 }
1667 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001668 ypr_open(pctx->out, &flag);
1669 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001670 }
1671
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001672 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001673
1674 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001675 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001676 }
1677 if (list->flags & LYS_SET_MAX) {
1678 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001679 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001680 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001681 ypr_open(pctx->out, &flag);
1682 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001683 }
1684 }
1685
1686 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001687 ypr_open(pctx->out, &flag);
1688 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001689 }
1690
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001691 ypr_status(pctx, node->flags, node->exts, &flag);
1692 ypr_description(pctx, node->dsc, node->exts, &flag);
1693 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001694
1695 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001696 ypr_open(pctx->out, &flag);
1697 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001698 }
1699
Radek Krejci2a9fc652021-01-22 17:44:34 +01001700 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001701 ypr_open(pctx->out, &flag);
1702 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001703 }
1704
1705 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001706 ypr_open(pctx->out, &flag);
1707 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001708 }
1709
Radek Krejci2a9fc652021-01-22 17:44:34 +01001710 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001711 ypr_open(pctx->out, &flag);
1712 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001713 }
1714
Radek Krejci2a9fc652021-01-22 17:44:34 +01001715 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001716 ypr_open(pctx->out, &flag);
1717 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001718 }
1719
1720 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001721 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001722}
1723
1724static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001725yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001726{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001727 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001728 struct lysc_node_list *list = (struct lysc_node_list *)node;
1729
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001730 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001731
1732 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001733 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001734 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001735 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001736 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001737 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 +01001738 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001739 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001740 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001741 }
1742 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001743 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001744 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001745 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001746 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001747 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001748 }
1749
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001750 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001751
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001752 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001753 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001754 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001755 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001756 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001757 }
1758
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001759 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001760
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001761 ypr_status(pctx, node->flags, node->exts, NULL);
1762 ypr_description(pctx, node->dsc, node->exts, NULL);
1763 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001764
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001765 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001766 struct lysc_node *child;
1767 struct lysc_node_action *action;
1768 struct lysc_node_notif *notif;
1769
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001770 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001771 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001772 }
Radek Krejci693262f2019-04-29 15:23:20 +02001773
Radek Krejci2a9fc652021-01-22 17:44:34 +01001774 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001775 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001776 }
Radek Krejci693262f2019-04-29 15:23:20 +02001777
Radek Krejci2a9fc652021-01-22 17:44:34 +01001778 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001779 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001780 }
Radek Krejci693262f2019-04-29 15:23:20 +02001781 }
1782
1783 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001784 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001785}
1786
1787static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001788yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001789{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001790 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001791 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001792
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001793 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001794 LEVEL++;
1795
Michal Vaskob26d09d2022-08-22 09:52:19 +02001796 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001797 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001798
1799 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001800 ypr_open(pctx->out, &flag);
1801 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802 }
1803
1804 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001805 ypr_open(pctx->out, &flag);
1806 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001807 }
1808
1809 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001810 ypr_open(pctx->out, &flag);
1811 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812 }
1813
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001814 ypr_config(pctx, refine->flags, refine->exts, &flag);
1815 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816
1817 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001818 ypr_open(pctx->out, &flag);
1819 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820 }
1821 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001822 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001824 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001826 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827 }
1828 }
1829
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001830 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1831 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001832
1833 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001834 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001835}
1836
1837static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001838yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001839{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001840 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001841 struct lysp_node_action *action;
1842 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001843
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001844 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845 LEVEL++;
1846
Michal Vaskob26d09d2022-08-22 09:52:19 +02001847 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001848 yprp_when(pctx, aug->when, NULL);
1849 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1850 ypr_status(pctx, aug->flags, aug->exts, NULL);
1851 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1852 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853
1854 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001855 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856 }
1857
Radek Krejci2a9fc652021-01-22 17:44:34 +01001858 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001859 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860 }
1861
Radek Krejci2a9fc652021-01-22 17:44:34 +01001862 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001863 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864 }
1865
1866 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001867 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001868}
1869
Radek Krejcid3ca0632019-04-16 16:54:54 +02001870static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001871yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001873 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001874 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001875 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001876 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001878 yprp_node_common1(pctx, node, &flag);
1879 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880
1881 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001882 ypr_open(pctx->out, &flag);
1883 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884 }
1885
Radek Krejci2a9fc652021-01-22 17:44:34 +01001886 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001887 ypr_open(pctx->out, &flag);
1888 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889 }
1890
1891 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001892 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893}
1894
1895static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001896yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001898 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001899 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1901
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001902 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903
1904 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001905 ypr_open(pctx->out, &flag);
1906 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001907 }
1908
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001909 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910
1911 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001912 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001913}
1914
1915static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001916yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001917{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001918 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001919 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001920 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001922 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001923
Radek Krejci693262f2019-04-29 15:23:20 +02001924 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001925 ypr_open(pctx->out, &flag);
1926 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001927 }
1928
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001929 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001930
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001932 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001933}
1934
1935static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001936yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937{
1938 switch (node->nodetype) {
1939 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001940 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001941 break;
1942 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001943 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001944 break;
1945 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001946 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001947 break;
1948 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001949 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001950 break;
1951 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001952 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001953 break;
1954 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001955 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001956 break;
1957 case LYS_ANYXML:
1958 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001959 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001960 break;
1961 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001962 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963 break;
1964 default:
1965 break;
1966 }
1967}
1968
1969static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001970yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001971{
1972 switch (node->nodetype) {
1973 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001974 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001975 break;
1976 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001977 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001978 break;
1979 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001980 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001981 break;
1982 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001983 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001984 break;
1985 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001986 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001987 break;
1988 case LYS_ANYXML:
1989 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001990 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001991 break;
1992 default:
1993 break;
1994 }
1995}
1996
1997static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001998yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001999{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002000 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 struct lysp_deviate_add *add;
2002 struct lysp_deviate_rpl *rpl;
2003 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08002004 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 LEVEL++;
2008
Michal Vaskob26d09d2022-08-22 09:52:19 +02002009 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002010 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
2011 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012
fredgan2b11ddb2019-10-21 11:03:39 +08002013 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002014 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08002015 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
2016 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002017 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 LEVEL++;
2019
Michal Vaskob26d09d2022-08-22 09:52:19 +02002020 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002021 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002022 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 continue;
2024 }
fredgan2b11ddb2019-10-21 11:03:39 +08002025 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002026 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002027 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 LEVEL++;
2029
Michal Vaskob26d09d2022-08-22 09:52:19 +02002030 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002031 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002032 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002033 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002035 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002036 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002038 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002039 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002040 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002041 ypr_config(pctx, add->flags, add->exts, NULL);
2042 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002044 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 }
2046 if (add->flags & LYS_SET_MAX) {
2047 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002048 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002049 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002050 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 }
2052 }
fredgan2b11ddb2019-10-21 11:03:39 +08002053 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002054 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002055 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002056 LEVEL++;
2057
Michal Vaskob26d09d2022-08-22 09:52:19 +02002058 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002059 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002060 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002061 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002062 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2063 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2064 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2065 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002066 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002067 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 }
2069 if (rpl->flags & LYS_SET_MAX) {
2070 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002071 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002072 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002073 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 }
2075 }
fredgan2b11ddb2019-10-21 11:03:39 +08002076 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002077 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002078 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002079 LEVEL++;
2080
Michal Vaskob26d09d2022-08-22 09:52:19 +02002081 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002082 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002083 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002084 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002086 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002087 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002088 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002089 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002090 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 }
2092 }
2093
2094 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002095 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002096 }
2097
2098 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002099 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002100}
2101
Michal Vasko7c8439f2020-08-05 13:25:19 +02002102static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002103yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002104{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002105 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106
Radek Krejcid3ca0632019-04-16 16:54:54 +02002107 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002108 if (modp->imports[u].flags & LYS_INTERNAL) {
2109 continue;
2110 }
2111
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002112 YPR_EXTRA_LINE_PRINT(pctx);
2113 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002114 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002115 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002116 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002118 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002119 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002120 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2121 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002123 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002124 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002125 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002126
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002128 if (modp->includes[u].injected) {
2129 /* do not print the includes injected from submodules */
2130 continue;
2131 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002132 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002133 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 +01002134 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002136 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002137 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002138 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002140 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2141 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002142 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002143 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002144 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002145 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002146 }
2147 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002148 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002149}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002150
Michal Vasko7c8439f2020-08-05 13:25:19 +02002151static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002152yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002153{
2154 LY_ARRAY_COUNT_TYPE u;
2155 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002156 struct lysp_node_action *action;
2157 struct lysp_node_notif *notif;
2158 struct lysp_node_grp *grp;
2159 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160
Radek Krejcid3ca0632019-04-16 16:54:54 +02002161 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002162 YPR_EXTRA_LINE_PRINT(pctx);
2163 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002165
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002166 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002167
aPiecek6cf1d162023-11-08 16:07:00 +01002168 if (yprp_extension_has_printable_instances(modp->exts)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002169 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002170 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002171 }
2172
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002173 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002174
Radek Krejcid3ca0632019-04-16 16:54:54 +02002175 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002176 YPR_EXTRA_LINE_PRINT(pctx);
2177 yprp_feature(pctx, &modp->features[u]);
2178 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002179 }
2180
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002181 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002182
Radek Krejcid3ca0632019-04-16 16:54:54 +02002183 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002184 YPR_EXTRA_LINE_PRINT(pctx);
2185 yprp_identity(pctx, &modp->identities[u]);
2186 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002187 }
2188
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002190
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002192 YPR_EXTRA_LINE_PRINT(pctx);
2193 yprp_typedef(pctx, &modp->typedefs[u]);
2194 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002195 }
2196
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002197 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002198
Radek Krejci2a9fc652021-01-22 17:44:34 +01002199 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002200 YPR_EXTRA_LINE_PRINT(pctx);
2201 yprp_grouping(pctx, grp);
2202 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002203 }
2204
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002205 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002206
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002208 YPR_EXTRA_LINE_PRINT(pctx);
2209 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002210 }
2211
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002212 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002213
Radek Krejci2a9fc652021-01-22 17:44:34 +01002214 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002215 YPR_EXTRA_LINE_PRINT(pctx);
2216 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002217 }
2218
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002219 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002220
Radek Krejci2a9fc652021-01-22 17:44:34 +01002221 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002222 YPR_EXTRA_LINE_PRINT(pctx);
2223 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002224 }
2225
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002226 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002227
Radek Krejci2a9fc652021-01-22 17:44:34 +01002228 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002229 YPR_EXTRA_LINE_PRINT(pctx);
2230 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002231 }
2232
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002234
Radek Krejcid3ca0632019-04-16 16:54:54 +02002235 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002236 YPR_EXTRA_LINE_PRINT(pctx);
2237 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002238 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002239
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002240 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002241}
2242
2243LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002244yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002245{
2246 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002247 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002248 struct lys_ypr_ctx pctx_ = {
2249 .out = out,
2250 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002251 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002252 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002253 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002254 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002255
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002256 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002257 LEVEL++;
2258
2259 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002260 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002261 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002262 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002263 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2264 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002265
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002266 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002267
Michal Vasko7c8439f2020-08-05 13:25:19 +02002268 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002269 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002270
2271 /* meta-stmts */
2272 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002273 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002274 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002275 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2276 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2277 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2278 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002279
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002280 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002281
Michal Vasko7c8439f2020-08-05 13:25:19 +02002282 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002283 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002284 YPR_EXTRA_LINE_PRINT(pctx);
2285 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002286 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002287
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002288 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002289
Michal Vasko7c8439f2020-08-05 13:25:19 +02002290 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002291 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002292
2293 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002294 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002295 ly_print_flush(out);
2296
2297 return LY_SUCCESS;
2298}
2299
2300static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002301yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002302{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002303 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002304 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002305 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002306 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002307 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002308 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002309}
2310
2311LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002312yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002313{
2314 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002315 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002316 .out = out,
2317 .level = 0,
2318 .options = options,
2319 .module = submodp->mod,
2320 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002321 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002322
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002323 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002324 LEVEL++;
2325
2326 /* submodule-header-stmts */
2327 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002328 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002329 }
2330
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002331 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002332
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002333 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002334
Michal Vasko7c8439f2020-08-05 13:25:19 +02002335 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002336 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002337
2338 /* meta-stmts */
2339 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002340 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002341 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002342 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2343 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2344 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2345 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002346
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002347 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002348
Michal Vasko7c8439f2020-08-05 13:25:19 +02002349 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002350 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002351 YPR_EXTRA_LINE_PRINT(pctx);
2352 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002353 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002354
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002355 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002356
Michal Vasko7c8439f2020-08-05 13:25:19 +02002357 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002358 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002359
2360 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002361 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002362 ly_print_flush(out);
2363
2364 return LY_SUCCESS;
2365}
2366
2367LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002368yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002369{
Michal Vasko331303f2022-08-22 09:51:57 +02002370 struct lys_ypr_ctx pctx_ = {
2371 .out = out,
2372 .level = 0,
2373 .options = options,
2374 .module = node->module,
2375 .schema = LYS_YPR_COMPILED
2376 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002377
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002378 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002379
2380 ly_print_flush(out);
2381 return LY_SUCCESS;
2382}
2383
2384LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002385yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002386{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002387 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002388 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002389 struct lys_ypr_ctx pctx_ = {
2390 .out = out,
2391 .level = 0,
2392 .options = options,
2393 .module = module,
2394 .schema = LYS_YPR_COMPILED
2395 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002396
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002397 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002398 LEVEL++;
2399
Radek Krejci693262f2019-04-29 15:23:20 +02002400 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002401 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2402 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002403
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002404 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002405
Michal Vasko7c8439f2020-08-05 13:25:19 +02002406 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002407
2408 /* meta-stmts */
2409 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002410 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002411 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002412 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2413 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2414 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2415 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002416
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002417 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002418
Radek Krejci693262f2019-04-29 15:23:20 +02002419 /* revision-stmts */
2420 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002421 YPR_EXTRA_LINE_PRINT(pctx);
2422 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2423 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002424 }
2425
2426 /* body-stmts */
2427 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002428 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002429 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002430 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002431 }
2432
Radek Krejci80d281e2020-09-14 17:42:54 +02002433 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002434 YPR_EXTRA_LINE_PRINT(pctx);
2435 yprc_identity(pctx, &module->identities[u]);
2436 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002437 }
2438
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002439 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002440 struct lysc_node *data;
2441 struct lysc_node_action *rpc;
2442 struct lysc_node_notif *notif;
2443
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002444 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002445 YPR_EXTRA_LINE_PRINT(pctx);
2446 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002447 }
Radek Krejci693262f2019-04-29 15:23:20 +02002448
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002449 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002450
Radek Krejci2a9fc652021-01-22 17:44:34 +01002451 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002452 YPR_EXTRA_LINE_PRINT(pctx);
2453 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002454 }
Radek Krejci693262f2019-04-29 15:23:20 +02002455
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002456 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002457
Radek Krejci2a9fc652021-01-22 17:44:34 +01002458 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002459 YPR_EXTRA_LINE_PRINT(pctx);
2460 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002461 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002462
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002463 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002464 }
2465
2466 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002467 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002468 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002469
2470 return LY_SUCCESS;
2471}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002472
Michal Vaskocc28b152022-08-23 14:44:54 +02002473LIBYANG_API_DEF void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002474lyplg_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 +01002475{
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002476 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002477 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002478 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002479
2480 LY_ARRAY_FOR(ext->substmts, u) {
2481 switch (ext->substmts[u].stmt) {
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002482 case LY_STMT_NOTIFICATION:
2483 case LY_STMT_INPUT:
2484 case LY_STMT_OUTPUT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002485 case LY_STMT_ACTION:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002486 case LY_STMT_RPC:
2487 case LY_STMT_ANYDATA:
2488 case LY_STMT_ANYXML:
2489 case LY_STMT_CASE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002490 case LY_STMT_CHOICE:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002491 case LY_STMT_CONTAINER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002492 case LY_STMT_LEAF:
2493 case LY_STMT_LEAF_LIST:
2494 case LY_STMT_LIST:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002495 case LY_STMT_USES: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002496 const struct lysc_node *node;
2497
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002498 if (data_printed) {
2499 break;
2500 }
2501
Radek Krejciadcf63d2021-02-09 10:21:18 +01002502 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002503 ypr_open(pctx->out, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002504 if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002505 yprc_notification(pctx, (struct lysc_node_notif *)node);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002506 } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) {
2507 yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag);
2508 } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) {
2509 yprc_action(pctx, (struct lysc_node_action *)node);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002510 } else {
2511 yprc_node(pctx, node);
2512 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002513 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002514
2515 /* all data nodes are stored in a linked list so all were printed */
2516 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002517 break;
2518 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002519 case LY_STMT_ARGUMENT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002520 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002521 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002522 case LY_STMT_ERROR_APP_TAG:
2523 case LY_STMT_ERROR_MESSAGE:
2524 case LY_STMT_KEY:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002525 case LY_STMT_MODIFIER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002526 case LY_STMT_NAMESPACE:
2527 case LY_STMT_ORGANIZATION:
2528 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002529 case LY_STMT_REFERENCE:
2530 case LY_STMT_UNITS:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002531 if (*(const char **)ext->substmts[u].storage) {
2532 ypr_open(pctx->out, flag);
2533 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002534 }
2535 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002536 case LY_STMT_BIT:
2537 case LY_STMT_ENUM: {
2538 const struct lysc_type_bitenum_item *items = *(struct lysc_type_bitenum_item **)ext->substmts[u].storage;
2539
2540 yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag);
2541 break;
2542 }
2543 case LY_STMT_CONFIG:
2544 ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2545 break;
2546 case LY_STMT_EXTENSION_INSTANCE:
2547 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0,
2548 *(struct lysc_ext_instance **)ext->substmts[u].storage, flag);
2549 break;
2550 case LY_STMT_FRACTION_DIGITS:
2551 if (*(uint8_t *)ext->substmts[u].storage) {
2552 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, *(uint8_t *)ext->substmts[u].storage, flag);
2553 }
2554 break;
2555 case LY_STMT_IDENTITY: {
2556 const struct lysc_ident *idents = *(struct lysc_ident **)ext->substmts[u].storage;
2557
2558 LY_ARRAY_FOR(idents, v) {
2559 yprc_identity(pctx, &idents[v]);
2560 }
2561 break;
2562 }
2563 case LY_STMT_LENGTH:
2564 if (*(struct lysc_range **)ext->substmts[u].storage) {
2565 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_STRING, flag);
2566 }
2567 break;
2568 case LY_STMT_MANDATORY:
2569 ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2570 break;
2571 case LY_STMT_MAX_ELEMENTS: {
2572 uint32_t max = *(uint32_t *)ext->substmts[u].storage;
2573
2574 if (max) {
2575 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag);
2576 } else {
2577 ypr_open(pctx->out, flag);
2578 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", ext->exts);
2579 }
2580 break;
2581 }
2582 case LY_STMT_MIN_ELEMENTS:
2583 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage, flag);
2584 break;
2585 case LY_STMT_ORDERED_BY:
2586 ypr_open(pctx->out, flag);
2587 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0,
2588 (*(uint16_t *)ext->substmts[u].storage & LYS_ORDBY_USER) ? "user" : "system", ext->exts);
2589 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002590 case LY_STMT_MUST: {
2591 const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
2592
2593 LY_ARRAY_FOR(musts, v) {
2594 yprc_must(pctx, &musts[v], flag);
2595 }
2596 break;
2597 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002598 case LY_STMT_PATTERN: {
2599 const struct lysc_pattern *patterns = *(struct lysc_pattern **)ext->substmts[u].storage;
2600
2601 LY_ARRAY_FOR(patterns, v) {
2602 yprc_pattern(pctx, &patterns[v], flag);
2603 }
2604 break;
2605 }
2606 case LY_STMT_POSITION:
2607 if (*(int64_t *)ext->substmts[u].storage) {
2608 ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2609 }
2610 break;
2611 case LY_STMT_VALUE:
2612 if (*(int64_t *)ext->substmts[u].storage) {
2613 ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2614 }
2615 break;
2616 case LY_STMT_RANGE:
2617 if (*(struct lysc_range **)ext->substmts[u].storage) {
2618 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_UINT64, flag);
2619 }
2620 break;
2621 case LY_STMT_REQUIRE_INSTANCE:
2622 ypr_open(pctx->out, flag);
2623 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage ? "true" : "false",
2624 ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002625 break;
2626 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002627 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002628 break;
2629 case LY_STMT_TYPE:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002630 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2631 ypr_open(pctx->out, flag);
2632 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002633 }
2634 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002635 case LY_STMT_WHEN:
2636 yprc_when(pctx, *(struct lysc_when **)ext->substmts[u].storage, flag);
2637 break;
2638 case LY_STMT_AUGMENT:
2639 case LY_STMT_BASE:
2640 case LY_STMT_BELONGS_TO:
2641 case LY_STMT_DEFAULT:
2642 case LY_STMT_DEVIATE:
2643 case LY_STMT_DEVIATION:
2644 case LY_STMT_EXTENSION:
2645 case LY_STMT_FEATURE:
2646 case LY_STMT_GROUPING:
2647 case LY_STMT_IF_FEATURE:
2648 case LY_STMT_IMPORT:
2649 case LY_STMT_INCLUDE:
2650 case LY_STMT_MODULE:
2651 case LY_STMT_PATH:
2652 case LY_STMT_PREFIX:
2653 case LY_STMT_REFINE:
2654 case LY_STMT_REVISION:
2655 case LY_STMT_REVISION_DATE:
2656 case LY_STMT_SUBMODULE:
2657 case LY_STMT_TYPEDEF:
2658 case LY_STMT_UNIQUE:
2659 case LY_STMT_YANG_VERSION:
2660 case LY_STMT_YIN_ELEMENT:
2661 /* nothing to do */
2662 break;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002663 default:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002664 LOGINT(pctx->module->ctx);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002665 break;
2666 }
2667 }
2668}