blob: 01ffa34c9d542f44315948e2cfb534f75b47d06f [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
Radek Krejci693262f2019-04-29 15:23:20 +020018#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020019#include <stdint.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010023#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020024
Radek Krejci535ea9f2020-05-29 16:01:05 +020025#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020026#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020027#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010028#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020029#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010030#include "plugins_exts.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010031#include "plugins_exts_print.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;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200249 struct lysp_ext *ext_def;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200250
Michal Vaskob26d09d2022-08-22 09:52:19 +0200251 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
252 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200253 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100254
Michal Vaskob26d09d2022-08-22 09:52:19 +0200255 lysp_ext_find_definition(pctx->module->ctx, ext, NULL, &ext_def);
256 if (!ext_def) {
257 return;
258 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200259
Michal Vaskob26d09d2022-08-22 09:52:19 +0200260 ypr_open(pctx->out, flag);
261
262 if (ext_def->argname) {
263 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
264 lysp_ext_instance_resolve_argument(pctx->module->ctx, ext, ext_def);
265 ypr_encode(pctx->out, ext->argument, -1);
266 ly_print_(pctx->out, "\"");
267 } else {
268 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
269 }
270
271 child_presence = 0;
272 LEVEL++;
273 LY_LIST_FOR(ext->child, stmt) {
274 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200275 continue;
276 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200277 if (!child_presence) {
278 ly_print_(pctx->out, " {\n");
279 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200280 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200281 yprp_stmt(pctx, stmt);
282 }
283 LEVEL--;
284 if (child_presence) {
285 ly_print_(pctx->out, "%*s}\n", INDENT);
286 } else {
287 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200288 }
289}
290
Radek Krejci693262f2019-04-29 15:23:20 +0200291static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200292yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
293 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200294{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200295 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200296
297 LY_ARRAY_FOR(exts, u) {
298 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
299 }
300}
301
302static void
303yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
304 struct lysc_ext_instance *exts, ly_bool *flag)
305{
306 LY_ARRAY_COUNT_TYPE u;
307 ly_bool inner_flag;
308
309 LY_ARRAY_FOR(exts, u) {
310 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
311 return;
312 }
313
314 ypr_open(pctx->out, flag);
315 if (exts[u].argument) {
316 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
317 ypr_encode(pctx->out, exts[u].argument, -1);
318 ly_print_(pctx->out, "\"");
319 } else {
320 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
321 }
322
323 LEVEL++;
324 inner_flag = 0;
325 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
326
327 if (exts[u].def->plugin && exts[u].def->plugin->sprinter) {
328 exts[u].def->plugin->sprinter(&pctx->printer_ctx, &exts[u], &inner_flag);
329 }
330
331 LEVEL--;
332 ypr_close(pctx, inner_flag);
333 }
334}
335
336static void
337ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts)
338{
Radek Krejci857189e2020-09-01 13:26:36 +0200339 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340
341 if (!text) {
342 /* nothing to print */
343 return;
344 }
345
Radek Krejcieccf6602021-02-05 19:42:54 +0100346 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100347 ly_print_(pctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200348 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100349 ypr_text(pctx, stmt_attr_info[substmt].name, text,
Radek Krejcieccf6602021-02-05 19:42:54 +0100350 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200351 }
352
353 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200354 if (pctx->schema == LYS_YPR_PARSED) {
355 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
356 } else {
357 yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200358 }
359 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100360 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200361}
362
363static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100364ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
365 unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200366{
367 char *str;
368
Radek Krejci1deb5be2020-08-26 16:43:36 +0200369 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100370 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200371 return;
372 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100373 ypr_open(pctx->out, flag);
374 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200375 free(str);
376}
377
378static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100379ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value,
380 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200381{
382 char *str;
383
Radek Krejci1deb5be2020-08-26 16:43:36 +0200384 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100385 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200386 return;
387 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100388 ypr_open(pctx->out, flag);
389 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200390 free(str);
391}
392
393static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100394yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200395{
396 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200399 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100400 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
401 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200402 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100403 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200404 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100405 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200406 }
407}
408
409static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100410ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200411{
412 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100413 ypr_open(pctx->out, flag);
414 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200415 }
416}
417
418static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100419ypr_config(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_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100422 ypr_open(pctx->out, flag);
423 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200424 }
425}
426
427static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429{
430 const char *status = NULL;
431
432 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100433 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200434 status = "current";
435 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100436 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200437 status = "deprecated";
438 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100439 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200440 status = "obsolete";
441 }
Radek Krejci693262f2019-04-29 15:23:20 +0200442
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100443 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444}
445
446static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100447ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200448{
449 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100450 ypr_open(pctx->out, flag);
451 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200452 }
453}
454
455static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100456ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200457{
458 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100459 ypr_open(pctx->out, flag);
460 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 }
462}
463
464static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100465yprp_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 +0200466{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200467 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200468 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200469
Michal Vasko7f45cf22020-10-01 12:49:44 +0200470 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100471 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200472 extflag = 0;
473
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100474 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200475
476 /* extensions */
477 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200478 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200479 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100480 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481 }
482}
483
484static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100485yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486{
Radek Krejci857189e2020-09-01 13:26:36 +0200487 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200488 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200489
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100490 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 LEVEL++;
492
Michal Vaskob26d09d2022-08-22 09:52:19 +0200493 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200494
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100495 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100496 ypr_open(pctx->out, &flag);
497 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200498 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200499 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200500 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100501 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 +0200502 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200503 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200504 }
505 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100506 (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 +0100507 ypr_open(pctx->out, &flag2);
508 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200509 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200510 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100511 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200512 }
513
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100514 ypr_status(pctx, ext->flags, ext->exts, &flag);
515 ypr_description(pctx, ext->dsc, ext->exts, &flag);
516 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200517
518 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100519 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200520}
521
522static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100523yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200524{
Radek Krejci857189e2020-09-01 13:26:36 +0200525 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200526
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100527 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200528 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200529 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100530 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
531 ypr_status(pctx, feat->flags, feat->exts, &flag);
532 ypr_description(pctx, feat->dsc, feat->exts, &flag);
533 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200534 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100535 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200536}
537
538static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100539yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200540{
Radek Krejci857189e2020-09-01 13:26:36 +0200541 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200542 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200543
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100544 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200545 LEVEL++;
546
Michal Vaskob26d09d2022-08-22 09:52:19 +0200547 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100548 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200549
550 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100551 ypr_open(pctx->out, &flag);
552 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553 }
554
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100555 ypr_status(pctx, ident->flags, ident->exts, &flag);
556 ypr_description(pctx, ident->dsc, ident->exts, &flag);
557 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200558
559 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100560 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200561}
562
563static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100564yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200565{
Radek Krejci857189e2020-09-01 13:26:36 +0200566 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200567 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200568
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100569 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200570 LEVEL++;
571
Michal Vaskob26d09d2022-08-22 09:52:19 +0200572 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200573
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100574 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200575 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100576 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200577 }
578
Radek Krejci693262f2019-04-29 15:23:20 +0200579 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100580 if (pctx->module != ident->derived[u]->module) {
581 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 +0200582 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100583 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200584 }
585 }
586
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100587 ypr_status(pctx, ident->flags, ident->exts, &flag);
588 ypr_description(pctx, ident->dsc, ident->exts, &flag);
589 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200590
591 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100592 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200593}
594
595static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100596yprp_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 +0200597{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100598 ly_bool inner_flag = 0, singleline;
599 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200600
601 if (!restr) {
602 return;
603 }
604
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100605 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100606 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
607 restr->arg.str : restr->arg.str + 1;
608 singleline = strchr(text, '\n') ? 0 : 1;
609 ypr_text(pctx, ly_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200610
611 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200612 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100613 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200614 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100615 ypr_open(pctx->out, &inner_flag);
616 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200617 }
618 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100619 ypr_open(pctx->out, &inner_flag);
620 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200621 }
622 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100623 ypr_open(pctx->out, &inner_flag);
624 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200625 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100626 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
627 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200628
Radek Krejcid3ca0632019-04-16 16:54:54 +0200629 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100630 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200631}
632
633static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100634yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200635{
Radek Krejci857189e2020-09-01 13:26:36 +0200636 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200637
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100638 ypr_open(pctx->out, flag);
639 ly_print_(pctx->out, "%*smust \"", INDENT);
640 ypr_encode(pctx->out, must->cond->expr, -1);
641 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200642
643 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200644 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200645 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100646 ypr_open(pctx->out, &inner_flag);
647 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200648 }
649 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100650 ypr_open(pctx->out, &inner_flag);
651 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200652 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100653 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
654 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200655
656 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100657 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200658}
659
660static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100661yprc_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 +0200662{
Radek Krejci857189e2020-09-01 13:26:36 +0200663 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200664 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200665
Radek Krejci334ccc72019-06-12 13:49:29 +0200666 if (!range) {
667 return;
668 }
669
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100670 ypr_open(pctx->out, flag);
671 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200672 LY_ARRAY_FOR(range->parts, u) {
673 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100674 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200675 }
676 if (range->parts[u].max_64 == range->parts[u].min_64) {
677 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100678 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200679 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100680 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200681 }
682 } else {
683 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100684 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200685 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100686 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200687 }
688 }
689 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100690 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200691
692 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200693 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200694 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100695 ypr_open(pctx->out, &inner_flag);
696 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200697 }
698 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100699 ypr_open(pctx->out, &inner_flag);
700 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200701 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100702 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
703 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200704
705 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100706 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200707}
708
709static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100710yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200711{
Radek Krejci857189e2020-09-01 13:26:36 +0200712 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200713
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100714 ypr_open(pctx->out, flag);
715 ly_print_(pctx->out, "%*spattern \"", INDENT);
716 ypr_encode(pctx->out, pattern->expr, -1);
717 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200718
719 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200720 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200721 if (pattern->inverted) {
722 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100723 ypr_open(pctx->out, &inner_flag);
724 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200725 }
726 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100727 ypr_open(pctx->out, &inner_flag);
728 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200729 }
730 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100731 ypr_open(pctx->out, &inner_flag);
732 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200733 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100734 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
735 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200736
737 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100738 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200739}
740
741static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100742yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200743{
Radek Krejci857189e2020-09-01 13:26:36 +0200744 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200745
746 if (!when) {
747 return;
748 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100749 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200750
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100751 ly_print_(pctx->out, "%*swhen \"", INDENT);
752 ypr_encode(pctx->out, when->cond, -1);
753 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200754
755 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200756 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100757 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
758 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200759 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100760 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200761}
762
763static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100764yprc_when(struct lys_ypr_ctx *pctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200765{
Radek Krejci857189e2020-09-01 13:26:36 +0200766 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200767
768 if (!when) {
769 return;
770 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100771 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200772
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100773 ly_print_(pctx->out, "%*swhen \"", INDENT);
774 ypr_encode(pctx->out, when->cond->expr, -1);
775 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200776
777 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200778 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100779 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
780 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200781 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100782 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200783}
784
785static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100786yprp_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 +0200787{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200788 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200789 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200790
791 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100792 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200793 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100794 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200795 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100796 ly_print_(pctx->out, "%*senum \"", INDENT);
797 ypr_encode(pctx->out, items[u].name, -1);
798 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200799 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200800 inner_flag = 0;
801 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200802 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100803 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200804 if (items[u].flags & LYS_SET_VALUE) {
805 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100806 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200807 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100808 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200809 }
810 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100811 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
812 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
813 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200814 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100815 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200816 }
817}
818
819static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100820yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200821{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200822 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200823 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200824
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100825 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200826 LEVEL++;
827
Michal Vaskob26d09d2022-08-22 09:52:19 +0200828 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200829
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100830 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
831 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200832 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100833 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100835 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
836 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200837
838 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100839 ypr_open(pctx->out, &flag);
840 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200841 }
842 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100843 ypr_open(pctx->out, &flag);
844 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200845 }
846 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100847 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200848 }
849 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100850 ypr_open(pctx->out, &flag);
851 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200852 }
853 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100854 ypr_open(pctx->out, &flag);
855 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200856 }
857
858 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100859 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200860}
861
862static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100863yprc_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 +0200864 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200865{
Radek Krejci857189e2020-09-01 13:26:36 +0200866 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200867 const char *str;
868
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100869 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
870 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200871 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200872 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200873 }
874}
875
876static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100877yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200878{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200879 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200880 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200881
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100882 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200883 LEVEL++;
884
Michal Vaskob26d09d2022-08-22 09:52:19 +0200885 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200886
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200887 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200888 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200889 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200890
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100891 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200892 break;
893 }
894 case LY_TYPE_UINT8:
895 case LY_TYPE_UINT16:
896 case LY_TYPE_UINT32:
897 case LY_TYPE_UINT64:
898 case LY_TYPE_INT8:
899 case LY_TYPE_INT16:
900 case LY_TYPE_INT32:
901 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200902 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200903
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100904 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200905 break;
906 }
907 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200908 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200909
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100910 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200911 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100912 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200913 }
914 break;
915 }
916 case LY_TYPE_BITS:
917 case LY_TYPE_ENUM: {
918 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200919 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200920
Radek Krejci693262f2019-04-29 15:23:20 +0200921 LY_ARRAY_FOR(bits->bits, u) {
922 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200923 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200924
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100925 ypr_open(pctx->out, &flag);
926 ly_print_(pctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
927 ypr_encode(pctx->out, item->name, -1);
928 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200929 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200930 if (type->basetype == LY_TYPE_BITS) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200931 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100932 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200933 } else { /* LY_TYPE_ENUM */
Michal Vaskob26d09d2022-08-22 09:52:19 +0200934 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100935 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200936 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100937 ypr_status(pctx, item->flags, item->exts, &inner_flag);
938 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
939 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200940 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100941 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200942 }
943 break;
944 }
945 case LY_TYPE_BOOL:
946 case LY_TYPE_EMPTY:
947 /* nothing to do */
948 break;
949 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200950 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200951
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100952 ypr_open(pctx->out, &flag);
953 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
954 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200955 break;
956 }
957 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200958 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200959
Radek Krejci693262f2019-04-29 15:23:20 +0200960 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100961 ypr_open(pctx->out, &flag);
962 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200963 }
964 break;
965 }
966 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200967 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200968
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100969 ypr_open(pctx->out, &flag);
970 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200971 break;
972 }
973 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200974 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200975
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100976 ypr_open(pctx->out, &flag);
977 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
978 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
979 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200980 break;
981 }
982 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200983 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200984
Radek Krejci693262f2019-04-29 15:23:20 +0200985 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100986 ypr_open(pctx->out, &flag);
987 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200988 }
989 break;
990 }
991 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100992 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200993 }
994
995 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100996 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200997}
998
999static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001000yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001001{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001002 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001003 LEVEL++;
1004
Michal Vaskob26d09d2022-08-22 09:52:19 +02001005 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001006
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001007 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001008
1009 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001010 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001011 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001012 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001013 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001014 }
1015
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001016 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1017 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1018 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001019
1020 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001021 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001022}
1023
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001024static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1025static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1026static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1027static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001028
1029static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001030yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001031{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001032 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001033 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001034 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001035 struct lysp_node_action *action;
1036 struct lysp_node_notif *notif;
1037 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001038
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001039 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001040 LEVEL++;
1041
Michal Vaskob26d09d2022-08-22 09:52:19 +02001042 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001043 ypr_status(pctx, grp->flags, grp->exts, &flag);
1044 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1045 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001046
1047 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001048 ypr_open(pctx->out, &flag);
1049 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001050 }
1051
Radek Krejci2a9fc652021-01-22 17:44:34 +01001052 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001053 ypr_open(pctx->out, &flag);
1054 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001055 }
1056
Radek Krejci01180ac2021-01-27 08:48:22 +01001057 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001058 ypr_open(pctx->out, &flag);
1059 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001060 }
1061
Radek Krejci2a9fc652021-01-22 17:44:34 +01001062 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001063 ypr_open(pctx->out, &flag);
1064 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001065 }
1066
1067 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001068 ypr_open(pctx->out, &flag);
1069 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070 }
1071
1072 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001073 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001074}
1075
1076static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001077yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001079 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001081 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001082
Radek Krejci01180ac2021-01-27 08:48:22 +01001083 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001084 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001085 return;
1086 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001087 ypr_open(pctx->out, flag);
1088 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001089
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001090 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091 LEVEL++;
1092
Michal Vaskob26d09d2022-08-22 09:52:19 +02001093 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001095 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001096 }
1097 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001098 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001099 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001100 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001101 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001102 }
1103
Radek Krejci01180ac2021-01-27 08:48:22 +01001104 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001105 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106 }
1107
1108 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001109 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110}
1111
1112static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001113yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001114{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001115 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001116 struct lysc_node *data;
1117
Radek Krejci01180ac2021-01-27 08:48:22 +01001118 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001119 /* input/output is empty */
1120 return;
1121 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001122 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001123
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001124 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001125 LEVEL++;
1126
Michal Vaskob26d09d2022-08-22 09:52:19 +02001127 yprc_extension_instances(pctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001128 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001129 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001130 }
1131
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001132 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001133 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001134 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001135 }
Radek Krejci693262f2019-04-29 15:23:20 +02001136 }
1137
1138 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001139 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001140}
1141
1142static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001143yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001144{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001145 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001146 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001148 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001149
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001150 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001151
1152 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001153 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001154 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001155
1156 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001157 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001158 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001159 ypr_status(pctx, notif->flags, notif->exts, &flag);
1160 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1161 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001162
1163 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001164 ypr_open(pctx->out, &flag);
1165 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001166 }
1167
Radek Krejci2a9fc652021-01-22 17:44:34 +01001168 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001169 ypr_open(pctx->out, &flag);
1170 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001171 }
1172
Radek Krejci01180ac2021-01-27 08:48:22 +01001173 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001174 ypr_open(pctx->out, &flag);
1175 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001176 }
1177
1178 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001179 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001180}
1181
1182static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001183yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001184{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001185 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001186 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001187 struct lysc_node *data;
1188
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001189 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001190
1191 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001192 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001193
1194 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001195 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001196 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001197 ypr_status(pctx, notif->flags, notif->exts, &flag);
1198 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1199 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001200
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001202 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001203 ypr_open(pctx->out, &flag);
1204 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001205 }
Radek Krejci693262f2019-04-29 15:23:20 +02001206 }
1207
1208 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001209 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001210}
1211
1212static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001213yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001214{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001215 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001216 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001217 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001218
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001219 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001220
1221 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001222 yprp_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001223 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1224 ypr_status(pctx, action->flags, action->exts, &flag);
1225 ypr_description(pctx, action->dsc, action->exts, &flag);
1226 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001227
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001228 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001229
Radek Krejcid3ca0632019-04-16 16:54:54 +02001230 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001231 ypr_open(pctx->out, &flag);
1232 YPR_EXTRA_LINE_PRINT(pctx);
1233 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234 }
1235
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001236 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001237
Radek Krejci2a9fc652021-01-22 17:44:34 +01001238 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001239 ypr_open(pctx->out, &flag);
1240 YPR_EXTRA_LINE_PRINT(pctx);
1241 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001242 }
1243
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001244 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001245
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001246 yprp_inout(pctx, &action->input, &flag);
1247 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248
1249 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001250 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001251}
1252
1253static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001254yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001255{
Radek Krejci857189e2020-09-01 13:26:36 +02001256 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001257
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001258 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001259
1260 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001261 yprc_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001262 ypr_status(pctx, action->flags, action->exts, &flag);
1263 ypr_description(pctx, action->dsc, action->exts, &flag);
1264 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001265
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001266 yprc_inout(pctx, &action->input, &flag);
1267 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001268
1269 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001270 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001271}
1272
1273static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001274yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001276 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001277 LEVEL++;
1278
Michal Vaskob26d09d2022-08-22 09:52:19 +02001279 yprp_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001280 yprp_when(pctx, lysp_node_when(node), flag);
1281 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001282}
1283
1284static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001285yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001287 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001288 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001289
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001290 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001291 LEVEL++;
1292
Michal Vaskob26d09d2022-08-22 09:52:19 +02001293 yprc_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001294
1295 when = lysc_node_when(node);
1296 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001297 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001298 }
Radek Krejci693262f2019-04-29 15:23:20 +02001299}
1300
Michal Vaskob26d09d2022-08-22 09:52:19 +02001301/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001302#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001303 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001304 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001305 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001306 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001307 ypr_status(pctx, node->flags, node->exts, flag); \
1308 ypr_description(pctx, node->dsc, node->exts, flag); \
1309 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001310
1311static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001312yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001313{
1314 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001315}
1316
1317static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001318yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001319{
1320 YPR_NODE_COMMON2;
1321}
1322
1323#undef YPR_NODE_COMMON2
1324
1325static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001326yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001327{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001328 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001329 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001330 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001331 struct lysp_node_action *action;
1332 struct lysp_node_notif *notif;
1333 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001334 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1335
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001336 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001337
1338 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001339 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001340 }
1341 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001342 ypr_open(pctx->out, &flag);
1343 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001344 }
1345
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001346 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001347
1348 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001349 ypr_open(pctx->out, &flag);
1350 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001351 }
1352
Radek Krejci2a9fc652021-01-22 17:44:34 +01001353 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001354 ypr_open(pctx->out, &flag);
1355 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001356 }
1357
1358 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001359 ypr_open(pctx->out, &flag);
1360 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001361 }
1362
Radek Krejci2a9fc652021-01-22 17:44:34 +01001363 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001364 ypr_open(pctx->out, &flag);
1365 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001366 }
1367
Radek Krejci2a9fc652021-01-22 17:44:34 +01001368 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001369 ypr_open(pctx->out, &flag);
1370 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001371 }
1372
1373 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001374 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001375}
1376
1377static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001378yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001379{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001380 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001381 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001382 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001383 struct lysc_node_action *action;
1384 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001385 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1386
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001387 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001388
1389 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001390 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001391 }
1392 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001393 ypr_open(pctx->out, &flag);
1394 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001395 }
1396
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001397 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001398
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001399 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001400 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001401 ypr_open(pctx->out, &flag);
1402 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001403 }
Radek Krejci693262f2019-04-29 15:23:20 +02001404
Radek Krejci2a9fc652021-01-22 17:44:34 +01001405 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001406 ypr_open(pctx->out, &flag);
1407 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001408 }
Radek Krejci693262f2019-04-29 15:23:20 +02001409
Radek Krejci2a9fc652021-01-22 17:44:34 +01001410 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001411 ypr_open(pctx->out, &flag);
1412 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001413 }
Radek Krejci693262f2019-04-29 15:23:20 +02001414 }
1415
1416 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001417 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001418}
1419
1420static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001421yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001422{
Radek Krejci857189e2020-09-01 13:26:36 +02001423 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001424 struct lysp_node *child;
1425 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1426
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001427 yprp_node_common1(pctx, node, &flag);
1428 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001429
1430 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001431 ypr_open(pctx->out, &flag);
1432 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001433 }
1434
1435 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001436 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001437}
1438
1439static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001440yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001441{
Radek Krejci857189e2020-09-01 13:26:36 +02001442 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001443 struct lysc_node *child;
1444
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001445 yprc_node_common1(pctx, &cs->node, &flag);
1446 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001447
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001448 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001449 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001450 ypr_open(pctx->out, &flag);
1451 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001452 }
Radek Krejci693262f2019-04-29 15:23:20 +02001453 }
1454
1455 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001456 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001457}
1458
1459static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001460yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001461{
Radek Krejci857189e2020-09-01 13:26:36 +02001462 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001463 struct lysp_node *child;
1464 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1465
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001466 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001467
Michal Vasko7f45cf22020-10-01 12:49:44 +02001468 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001469 ypr_open(pctx->out, &flag);
1470 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001471 }
1472
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001473 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001474
1475 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001476 ypr_open(pctx->out, &flag);
1477 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478 }
1479
1480 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001481 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001482}
1483
1484static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001485yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001486{
Radek Krejci857189e2020-09-01 13:26:36 +02001487 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001488 struct lysc_node_case *cs;
1489 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1490
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001491 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001492
1493 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001494 ypr_open(pctx->out, &flag);
1495 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001496 }
1497
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001498 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001499
Michal Vasko22df3f02020-08-24 13:29:22 +02001500 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001501 ypr_open(pctx->out, &flag);
1502 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001503 }
1504
1505 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001506 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001507}
1508
1509static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001510yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001512 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001513 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1514
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001515 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001516
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001517 yprp_type(pctx, &leaf->type);
1518 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001519 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001520 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001521 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001522 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001523
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001524 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001525
1526 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001527 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001528}
1529
1530static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001531yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001532{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001533 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001534 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1535
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001536 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001537
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001538 yprc_type(pctx, leaf->type);
1539 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001540 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001541 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001542 }
Radek Krejcia1911222019-07-22 17:24:50 +02001543
1544 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001545 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001546 }
Radek Krejci693262f2019-04-29 15:23:20 +02001547
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001548 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001549
1550 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001551 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001552}
1553
1554static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001555yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001556{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001557 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001558 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1559
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001560 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001562 yprp_type(pctx, &llist->type);
1563 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001564 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001565 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001566 }
1567 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001568 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001569 }
1570
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001571 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001572
1573 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001574 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575 }
1576 if (llist->flags & LYS_SET_MAX) {
1577 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001578 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001580 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001581 }
1582 }
1583
1584 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001585 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001586 }
1587
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001588 ypr_status(pctx, node->flags, node->exts, NULL);
1589 ypr_description(pctx, node->dsc, node->exts, NULL);
1590 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001591
1592 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001593 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001594}
1595
1596static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001597yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001598{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001599 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001600 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1601
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001602 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001603
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001604 yprc_type(pctx, llist->type);
1605 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001606 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001607 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001608 }
1609 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001610 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001611 }
1612
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001613 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001614
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001615 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001616 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001617 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001618 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001619 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001620 }
1621
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001622 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001623
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001624 ypr_status(pctx, node->flags, node->exts, NULL);
1625 ypr_description(pctx, node->dsc, node->exts, NULL);
1626 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001627
1628 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001629 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001630}
1631
1632static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001633yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001634{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001635 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001636 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001637 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001638 struct lysp_node_action *action;
1639 struct lysp_node_notif *notif;
1640 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001641 struct lysp_node_list *list = (struct lysp_node_list *)node;
1642
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001643 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001644
1645 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001646 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647 }
1648 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001649 ypr_open(pctx->out, &flag);
1650 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001651 }
1652 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001653 ypr_open(pctx->out, &flag);
1654 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001655 }
1656
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001657 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001658
1659 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001660 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001661 }
1662 if (list->flags & LYS_SET_MAX) {
1663 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001664 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001665 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001666 ypr_open(pctx->out, &flag);
1667 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001668 }
1669 }
1670
1671 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001672 ypr_open(pctx->out, &flag);
1673 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001674 }
1675
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001676 ypr_status(pctx, node->flags, node->exts, &flag);
1677 ypr_description(pctx, node->dsc, node->exts, &flag);
1678 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001679
1680 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001681 ypr_open(pctx->out, &flag);
1682 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001683 }
1684
Radek Krejci2a9fc652021-01-22 17:44:34 +01001685 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001686 ypr_open(pctx->out, &flag);
1687 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001688 }
1689
1690 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001691 ypr_open(pctx->out, &flag);
1692 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001693 }
1694
Radek Krejci2a9fc652021-01-22 17:44:34 +01001695 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001696 ypr_open(pctx->out, &flag);
1697 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001698 }
1699
Radek Krejci2a9fc652021-01-22 17:44:34 +01001700 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001701 ypr_open(pctx->out, &flag);
1702 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001703 }
1704
1705 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001706 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001707}
1708
1709static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001710yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001711{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001712 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001713 struct lysc_node_list *list = (struct lysc_node_list *)node;
1714
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001715 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001716
1717 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001718 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001719 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001720 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001721 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001722 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 +01001723 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001724 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001725 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001726 }
1727 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001728 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001729 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001730 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001731 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001732 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001733 }
1734
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001735 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001736
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001737 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001738 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001739 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001740 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001741 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001742 }
1743
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001744 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001745
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001746 ypr_status(pctx, node->flags, node->exts, NULL);
1747 ypr_description(pctx, node->dsc, node->exts, NULL);
1748 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001749
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001750 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001751 struct lysc_node *child;
1752 struct lysc_node_action *action;
1753 struct lysc_node_notif *notif;
1754
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001755 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001756 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001757 }
Radek Krejci693262f2019-04-29 15:23:20 +02001758
Radek Krejci2a9fc652021-01-22 17:44:34 +01001759 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001760 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001761 }
Radek Krejci693262f2019-04-29 15:23:20 +02001762
Radek Krejci2a9fc652021-01-22 17:44:34 +01001763 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001764 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001765 }
Radek Krejci693262f2019-04-29 15:23:20 +02001766 }
1767
1768 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001769 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001770}
1771
1772static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001773yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001775 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001776 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001777
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001778 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779 LEVEL++;
1780
Michal Vaskob26d09d2022-08-22 09:52:19 +02001781 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001782 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783
1784 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001785 ypr_open(pctx->out, &flag);
1786 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787 }
1788
1789 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001790 ypr_open(pctx->out, &flag);
1791 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001792 }
1793
1794 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001795 ypr_open(pctx->out, &flag);
1796 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001797 }
1798
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001799 ypr_config(pctx, refine->flags, refine->exts, &flag);
1800 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801
1802 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001803 ypr_open(pctx->out, &flag);
1804 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001805 }
1806 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001807 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001808 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001809 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001811 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812 }
1813 }
1814
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001815 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1816 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817
1818 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001819 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820}
1821
1822static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001823yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001824{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001826 struct lysp_node_action *action;
1827 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001829 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 LEVEL++;
1831
Michal Vaskob26d09d2022-08-22 09:52:19 +02001832 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001833 yprp_when(pctx, aug->when, NULL);
1834 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1835 ypr_status(pctx, aug->flags, aug->exts, NULL);
1836 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1837 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001838
1839 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001840 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841 }
1842
Radek Krejci2a9fc652021-01-22 17:44:34 +01001843 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001844 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845 }
1846
Radek Krejci2a9fc652021-01-22 17:44:34 +01001847 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001848 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 }
1850
1851 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001852 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853}
1854
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001856yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001857{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001858 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001859 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001861 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001862
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001863 yprp_node_common1(pctx, node, &flag);
1864 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001865
1866 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001867 ypr_open(pctx->out, &flag);
1868 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001869 }
1870
Radek Krejci2a9fc652021-01-22 17:44:34 +01001871 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001872 ypr_open(pctx->out, &flag);
1873 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001874 }
1875
1876 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001877 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001878}
1879
1880static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001881yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001882{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001883 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001884 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1886
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001887 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001888
1889 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001890 ypr_open(pctx->out, &flag);
1891 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001892 }
1893
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001894 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001895
1896 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001897 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001898}
1899
1900static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001901yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001902{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001903 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001904 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001905 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001907 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001908
Radek Krejci693262f2019-04-29 15:23:20 +02001909 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001910 ypr_open(pctx->out, &flag);
1911 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912 }
1913
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001914 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001915
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001917 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918}
1919
1920static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001921yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922{
1923 switch (node->nodetype) {
1924 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001925 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001926 break;
1927 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001928 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001929 break;
1930 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001931 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001932 break;
1933 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001934 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001935 break;
1936 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001937 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001938 break;
1939 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001940 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001941 break;
1942 case LYS_ANYXML:
1943 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001944 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001945 break;
1946 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001947 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001948 break;
1949 default:
1950 break;
1951 }
1952}
1953
1954static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001955yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001956{
1957 switch (node->nodetype) {
1958 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001959 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001960 break;
1961 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001962 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001963 break;
1964 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001965 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001966 break;
1967 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001968 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001969 break;
1970 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001971 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001972 break;
1973 case LYS_ANYXML:
1974 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001975 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001976 break;
1977 default:
1978 break;
1979 }
1980}
1981
1982static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001983yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001984{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001985 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001986 struct lysp_deviate_add *add;
1987 struct lysp_deviate_rpl *rpl;
1988 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001989 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001991 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001992 LEVEL++;
1993
Michal Vaskob26d09d2022-08-22 09:52:19 +02001994 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001995 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1996 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001997
fredgan2b11ddb2019-10-21 11:03:39 +08001998 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001999 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08002000 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
2001 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002002 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003 LEVEL++;
2004
Michal Vaskob26d09d2022-08-22 09:52:19 +02002005 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002007 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002008 continue;
2009 }
fredgan2b11ddb2019-10-21 11:03:39 +08002010 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002011 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002012 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002013 LEVEL++;
2014
Michal Vaskob26d09d2022-08-22 09:52:19 +02002015 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002016 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002017 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002018 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002019 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002020 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002021 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002023 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002024 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002025 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002026 ypr_config(pctx, add->flags, add->exts, NULL);
2027 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002029 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 }
2031 if (add->flags & LYS_SET_MAX) {
2032 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002033 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002035 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002036 }
2037 }
fredgan2b11ddb2019-10-21 11:03:39 +08002038 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002039 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002040 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 LEVEL++;
2042
Michal Vaskob26d09d2022-08-22 09:52:19 +02002043 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002045 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002046 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002047 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2048 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2049 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2050 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002052 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002053 }
2054 if (rpl->flags & LYS_SET_MAX) {
2055 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002056 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002058 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002059 }
2060 }
fredgan2b11ddb2019-10-21 11:03:39 +08002061 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002062 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002063 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002064 LEVEL++;
2065
Michal Vaskob26d09d2022-08-22 09:52:19 +02002066 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002067 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002068 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002069 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002071 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002072 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002073 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002074 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002075 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002076 }
2077 }
2078
2079 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002080 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002081 }
2082
2083 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002084 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085}
2086
Michal Vasko7c8439f2020-08-05 13:25:19 +02002087static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002088yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002090 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091
Radek Krejcid3ca0632019-04-16 16:54:54 +02002092 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002093 if (modp->imports[u].flags & LYS_INTERNAL) {
2094 continue;
2095 }
2096
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002097 YPR_EXTRA_LINE_PRINT(pctx);
2098 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002099 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002100 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002101 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002103 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002104 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002105 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2106 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002107 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002108 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002109 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002110 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002111
Radek Krejcid3ca0632019-04-16 16:54:54 +02002112 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002113 if (modp->includes[u].injected) {
2114 /* do not print the includes injected from submodules */
2115 continue;
2116 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002117 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002118 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 +01002119 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002120 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002121 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002123 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002124 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002125 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2126 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002128 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002129 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002130 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002131 }
2132 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002133 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002134}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135
Michal Vasko7c8439f2020-08-05 13:25:19 +02002136static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002137yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002138{
2139 LY_ARRAY_COUNT_TYPE u;
2140 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002141 struct lysp_node_action *action;
2142 struct lysp_node_notif *notif;
2143 struct lysp_node_grp *grp;
2144 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002145
Radek Krejcid3ca0632019-04-16 16:54:54 +02002146 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002147 YPR_EXTRA_LINE_PRINT(pctx);
2148 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002149 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002150
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002151 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002152
Radek Krejcid3ca0632019-04-16 16:54:54 +02002153 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002154 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002155 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002156 }
2157
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002158 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002159
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002161 YPR_EXTRA_LINE_PRINT(pctx);
2162 yprp_feature(pctx, &modp->features[u]);
2163 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 }
2165
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002166 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002167
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002169 YPR_EXTRA_LINE_PRINT(pctx);
2170 yprp_identity(pctx, &modp->identities[u]);
2171 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172 }
2173
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002174 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002175
Radek Krejcid3ca0632019-04-16 16:54:54 +02002176 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002177 YPR_EXTRA_LINE_PRINT(pctx);
2178 yprp_typedef(pctx, &modp->typedefs[u]);
2179 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 }
2181
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002182 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002183
Radek Krejci2a9fc652021-01-22 17:44:34 +01002184 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002185 YPR_EXTRA_LINE_PRINT(pctx);
2186 yprp_grouping(pctx, grp);
2187 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002188 }
2189
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002190 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002191
Radek Krejcid3ca0632019-04-16 16:54:54 +02002192 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002193 YPR_EXTRA_LINE_PRINT(pctx);
2194 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002195 }
2196
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002197 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002198
Radek Krejci2a9fc652021-01-22 17:44:34 +01002199 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002200 YPR_EXTRA_LINE_PRINT(pctx);
2201 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002202 }
2203
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002204 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002205
Radek Krejci2a9fc652021-01-22 17:44:34 +01002206 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002207 YPR_EXTRA_LINE_PRINT(pctx);
2208 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002209 }
2210
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002211 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002212
Radek Krejci2a9fc652021-01-22 17:44:34 +01002213 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002214 YPR_EXTRA_LINE_PRINT(pctx);
2215 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002216 }
2217
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002218 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002219
Radek Krejcid3ca0632019-04-16 16:54:54 +02002220 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002221 YPR_EXTRA_LINE_PRINT(pctx);
2222 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002223 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002224
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002225 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002226}
2227
2228LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002229yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002230{
2231 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002232 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 struct lys_ypr_ctx pctx_ = {
2234 .out = out,
2235 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002236 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002237 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002238 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002239 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002240
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002241 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002242 LEVEL++;
2243
2244 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002245 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002246 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 +02002247 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002248 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2249 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002250
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002251 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002252
Michal Vasko7c8439f2020-08-05 13:25:19 +02002253 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002254 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002255
2256 /* meta-stmts */
2257 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002258 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002259 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002260 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2261 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2262 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2263 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002264
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002265 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002266
Michal Vasko7c8439f2020-08-05 13:25:19 +02002267 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002268 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002269 YPR_EXTRA_LINE_PRINT(pctx);
2270 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002271 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002272
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002273 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002274
Michal Vasko7c8439f2020-08-05 13:25:19 +02002275 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002276 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002277
2278 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002279 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002280 ly_print_flush(out);
2281
2282 return LY_SUCCESS;
2283}
2284
2285static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002286yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002287{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002288 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002289 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002290 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002291 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002292 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002293 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002294}
2295
2296LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002297yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002298{
2299 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002300 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002301 .out = out,
2302 .level = 0,
2303 .options = options,
2304 .module = submodp->mod,
2305 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002306 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002307
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002308 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002309 LEVEL++;
2310
2311 /* submodule-header-stmts */
2312 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002313 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 +02002314 }
2315
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002316 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002317
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002318 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002319
Michal Vasko7c8439f2020-08-05 13:25:19 +02002320 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002321 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002322
2323 /* meta-stmts */
2324 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002325 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002326 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002327 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2328 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2329 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2330 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002331
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002332 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002333
Michal Vasko7c8439f2020-08-05 13:25:19 +02002334 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002335 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002336 YPR_EXTRA_LINE_PRINT(pctx);
2337 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002338 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002339
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002340 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002341
Michal Vasko7c8439f2020-08-05 13:25:19 +02002342 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002343 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002344
2345 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002346 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002347 ly_print_flush(out);
2348
2349 return LY_SUCCESS;
2350}
2351
2352LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002353yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002354{
Michal Vasko331303f2022-08-22 09:51:57 +02002355 struct lys_ypr_ctx pctx_ = {
2356 .out = out,
2357 .level = 0,
2358 .options = options,
2359 .module = node->module,
2360 .schema = LYS_YPR_COMPILED
2361 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002362
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002363 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002364
2365 ly_print_flush(out);
2366 return LY_SUCCESS;
2367}
2368
2369LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002370yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002371{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002372 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002373 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002374 struct lys_ypr_ctx pctx_ = {
2375 .out = out,
2376 .level = 0,
2377 .options = options,
2378 .module = module,
2379 .schema = LYS_YPR_COMPILED
2380 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002381
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002382 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002383 LEVEL++;
2384
Radek Krejci693262f2019-04-29 15:23:20 +02002385 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002386 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2387 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002388
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002389 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002390
Michal Vasko7c8439f2020-08-05 13:25:19 +02002391 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002392
2393 /* meta-stmts */
2394 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002395 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002396 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002397 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2398 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2399 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2400 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002401
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002402 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002403
Radek Krejci693262f2019-04-29 15:23:20 +02002404 /* revision-stmts */
2405 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002406 YPR_EXTRA_LINE_PRINT(pctx);
2407 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2408 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002409 }
2410
2411 /* body-stmts */
2412 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002413 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002414 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002415 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002416 }
2417
Radek Krejci80d281e2020-09-14 17:42:54 +02002418 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002419 YPR_EXTRA_LINE_PRINT(pctx);
2420 yprc_identity(pctx, &module->identities[u]);
2421 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002422 }
2423
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002424 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002425 struct lysc_node *data;
2426 struct lysc_node_action *rpc;
2427 struct lysc_node_notif *notif;
2428
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002429 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002430 YPR_EXTRA_LINE_PRINT(pctx);
2431 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002432 }
Radek Krejci693262f2019-04-29 15:23:20 +02002433
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002434 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002435
Radek Krejci2a9fc652021-01-22 17:44:34 +01002436 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002437 YPR_EXTRA_LINE_PRINT(pctx);
2438 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002439 }
Radek Krejci693262f2019-04-29 15:23:20 +02002440
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002441 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002442
Radek Krejci2a9fc652021-01-22 17:44:34 +01002443 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002444 YPR_EXTRA_LINE_PRINT(pctx);
2445 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002446 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002447
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002448 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002449 }
2450
2451 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002452 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002453 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002454
2455 return LY_SUCCESS;
2456}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002457
Michal Vaskocc28b152022-08-23 14:44:54 +02002458LIBYANG_API_DEF void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002459lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002460{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002461 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002462 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002463 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002464
2465 LY_ARRAY_FOR(ext->substmts, u) {
2466 switch (ext->substmts[u].stmt) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002467 case LY_STMT_ACTION:
2468 case LY_STMT_CONTAINER:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002469 case LY_STMT_CHOICE:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002470 case LY_STMT_LEAF:
2471 case LY_STMT_LEAF_LIST:
2472 case LY_STMT_LIST:
2473 case LY_STMT_NOTIFICATION:
2474 case LY_STMT_RPC:
2475 case LY_STMT_ANYXML:
2476 case LY_STMT_ANYDATA: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002477 const struct lysc_node *node;
2478
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002479 if (data_printed) {
2480 break;
2481 }
2482
Radek Krejciadcf63d2021-02-09 10:21:18 +01002483 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002484 ypr_open(pctx->out, flag);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002485 if ((ext->substmts[u].stmt == LY_STMT_ACTION) || (ext->substmts[u].stmt == LY_STMT_RPC)) {
2486 yprc_action(pctx, (struct lysc_node_action *)node);
2487 } else if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
2488 yprc_notification(pctx, (struct lysc_node_notif *)node);
2489 } else {
2490 yprc_node(pctx, node);
2491 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002492 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002493
2494 /* all data nodes are stored in a linked list so all were printed */
2495 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002496 break;
2497 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002498 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002499 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002500 case LY_STMT_ERROR_APP_TAG:
2501 case LY_STMT_ERROR_MESSAGE:
2502 case LY_STMT_KEY:
2503 case LY_STMT_NAMESPACE:
2504 case LY_STMT_ORGANIZATION:
2505 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002506 case LY_STMT_REFERENCE:
2507 case LY_STMT_UNITS:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002508 if (*(const char **)ext->substmts[u].storage) {
2509 ypr_open(pctx->out, flag);
2510 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002511 }
2512 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002513 case LY_STMT_MUST: {
2514 const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
2515
2516 LY_ARRAY_FOR(musts, v) {
2517 yprc_must(pctx, &musts[v], flag);
2518 }
2519 break;
2520 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002521 case LY_STMT_IF_FEATURE:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002522 case LY_STMT_USES:
2523 case LY_STMT_GROUPING:
2524 case LY_STMT_TYPEDEF:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002525 /* nothing to do */
2526 break;
2527 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002528 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002529 break;
2530 case LY_STMT_TYPE:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002531 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2532 ypr_open(pctx->out, flag);
2533 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002534 }
2535 break;
2536 /* TODO support other substatements */
2537 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002538 LOGWRN(pctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
Radek Krejciadcf63d2021-02-09 10:21:18 +01002539 ly_stmt2str(ext->substmts[u].stmt));
2540 break;
2541 }
2542 }
2543}