blob: 90b08cf3a9ce624db5737373a15b4ba752787101 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief YANG printer
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Radek Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020016
Radek Krejci693262f2019-04-29 15:23:20 +020017#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010022#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020023
Radek Krejci535ea9f2020-05-29 16:01:05 +020024#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020025#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010027#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020028#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010029#include "plugins_exts.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010030#include "plugins_exts_print.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010041 * @brief Types of the YANG printers
42 */
43enum lys_ypr_schema_type {
44 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
45 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
46};
47
Radek Krejciaa14a0c2020-09-04 11:16:47 +020048#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
49
Michal Vasko61ad1ff2022-02-10 15:48:39 +010050#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
51#define YPR_EXTRA_LINE_PRINT(PCTX) \
52 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
53 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020054 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010055 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020056 } \
57 }
58
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010059/**
60 * @brief Compiled YANG printer context
61 *
62 * Note that the YANG extensions API provides getter to the members for the extension plugins.
63 */
64struct lys_ypr_ctx {
65 union {
66 struct {
67 struct ly_out *out; /**< output specification */
68 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020069 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010070 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
71 const struct lys_module *module; /**< schema to print */
72 };
73 struct lyspr_ctx printer_ctx;
74 };
75
76 /* YANG printer specific members */
77 enum lys_ypr_schema_type schema; /**< type of the schema to print */
78};
79
80/**
Radek Krejcie7b95092019-05-15 11:03:07 +020081 * @brief Print the given text as content of a double quoted YANG string,
82 * including encoding characters that have special meanings. The quotation marks
83 * are not printed.
84 *
85 * Follows RFC 7950, section 6.1.3.
86 *
87 * @param[in] out Output specification.
88 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020089 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020090 * the @p text is printed completely as a NULL-terminated string.
91 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020092static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020093ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020094{
Radek Krejci1deb5be2020-08-26 16:43:36 +020095 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020096 const char *start;
97 char special = 0;
98
99 if (!len) {
100 return;
101 }
102
103 if (len < 0) {
104 len = strlen(text);
105 }
106
107 start = text;
108 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200109 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200110 switch (text[i]) {
111 case '\n':
112 case '\t':
113 case '\"':
114 case '\\':
115 special = text[i];
116 break;
117 default:
118 ++start_len;
119 break;
120 }
121
122 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200123 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200124 switch (special) {
125 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200126 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200127 break;
128 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200129 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200130 break;
131 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200132 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200133 break;
134 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200135 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200136 break;
137 }
138
139 start += start_len + 1;
140 start_len = 0;
141
142 special = 0;
143 }
144 }
145
Michal Vasko5233e962020-08-14 14:26:20 +0200146 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200147}
148
149static void
Radek Krejci857189e2020-09-01 13:26:36 +0200150ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151{
152 if (flag && !*flag) {
153 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200154 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200155 }
156}
157
158static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100159ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200160{
161 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100162 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100164 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200165 }
166}
167
168static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100169ypr_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 +0200170{
171 const char *s, *t;
172
173 if (singleline) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100174 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200175 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100176 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177 LEVEL++;
178
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100179 ly_print_(pctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200180 }
181 t = text;
182 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100183 ypr_encode(pctx->out, t, s - t);
184 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200185 t = s + 1;
186 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100187 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200188 }
189 }
190
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100191 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192 if (closed) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100193 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100195 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200196 }
197 if (!singleline) {
198 LEVEL--;
199 }
200}
201
202static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100203yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200204{
205 struct lysp_stmt *childstmt;
206 const char *s, *t;
207
208 if (stmt->arg) {
209 if (stmt->flags) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100210 ly_print_(pctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200211 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100212 ly_print_(pctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213 t = stmt->arg;
214 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100215 ypr_encode(pctx->out, t, s - t);
216 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200217 t = s + 1;
218 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100219 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 }
221 }
222 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100223 ypr_encode(pctx->out, t, strlen(t));
224 ly_print_(pctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200225 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100226 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200227 }
228 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100229 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200230 }
231
232 if (stmt->child) {
233 LEVEL++;
234 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100235 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236 }
237 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100238 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200239 }
240}
241
242/**
243 * @param[in] count Number of extensions to print, 0 to print them all.
244 */
245static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100246yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejci857189e2020-09-01 13:26:36 +0200247 struct lysp_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200248{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200249 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200250 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200251 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200252
253 if (!count && ext) {
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200254 count = LY_ARRAY_COUNT(ext);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200255 }
256 LY_ARRAY_FOR(ext, u) {
Radek Krejci85ac8312021-03-03 20:21:33 +0100257 struct lysp_ext *ext_def = NULL;
258
Radek Krejcid3ca0632019-04-16 16:54:54 +0200259 if (!count) {
260 break;
261 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200262
Radek Krejcid3ca0632019-04-16 16:54:54 +0200263 count--;
Radek Krejciab430862021-03-02 20:13:40 +0100264 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200265 continue;
266 }
267
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100268 lysp_ext_find_definition(pctx->module->ctx, &ext[u], NULL, &ext_def);
Radek Krejci85ac8312021-03-03 20:21:33 +0100269 if (!ext_def) {
270 continue;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200271 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100272
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100273 ypr_open(pctx->out, flag);
Radek Krejci85ac8312021-03-03 20:21:33 +0100274
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100275 if (ext_def->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100276 ly_print_(pctx->out, "%*s%s \"", INDENT, ext[u].name);
277 lysp_ext_instance_resolve_argument(pctx->module->ctx, &ext[u], ext_def);
278 ypr_encode(pctx->out, ext[u].argument, -1);
279 ly_print_(pctx->out, "\"");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200280 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100281 ly_print_(pctx->out, "%*s%s", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200282 }
283
284 child_presence = 0;
285 LEVEL++;
286 LY_LIST_FOR(ext[u].child, stmt) {
287 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
288 continue;
289 }
290 if (!child_presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100291 ly_print_(pctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200292 child_presence = 1;
293 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100294 yprp_stmt(pctx, stmt);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200295 }
296 LEVEL--;
297 if (child_presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100298 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200299 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100300 ly_print_(pctx->out, ";\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200301 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200302 }
303}
304
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100305static void yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +0100306 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count);
Radek Krejci693262f2019-04-29 15:23:20 +0200307
308static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100309ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200310{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200311 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200312 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200313
314 if (!text) {
315 /* nothing to print */
316 return;
317 }
318
Radek Krejcieccf6602021-02-05 19:42:54 +0100319 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100320 ly_print_(pctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200321 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100322 ypr_text(pctx, stmt_attr_info[substmt].name, text,
Radek Krejcieccf6602021-02-05 19:42:54 +0100323 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 }
325
326 LEVEL++;
327 LY_ARRAY_FOR(ext, u) {
Radek Krejciab430862021-03-02 20:13:40 +0100328 if ((((struct lysp_ext_instance *)ext)[u].parent_stmt != substmt) || (((struct lysp_ext_instance *)ext)[u].parent_stmt_index != substmt_index)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200329 continue;
330 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100331 if (pctx->schema == LYS_YPR_PARSED) {
332 yprp_extension_instances(pctx, substmt, substmt_index, &((struct lysp_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200333 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100334 yprc_extension_instances(pctx, substmt, substmt_index, &((struct lysc_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200335 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 }
337 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100338 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200339}
340
341static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100342ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
343 unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200344{
345 char *str;
346
Radek Krejci1deb5be2020-08-26 16:43:36 +0200347 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100348 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200349 return;
350 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100351 ypr_open(pctx->out, flag);
352 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200353 free(str);
354}
355
356static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100357ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value,
358 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200359{
360 char *str;
361
Radek Krejci1deb5be2020-08-26 16:43:36 +0200362 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100363 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200364 return;
365 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100366 ypr_open(pctx->out, flag);
367 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200368 free(str);
369}
370
371static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100372yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373{
374 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100375 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200376 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100377 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL, 0);
378 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
379 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100381 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100383 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384 }
385}
386
387static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100388ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200389{
390 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100391 ypr_open(pctx->out, flag);
392 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393 }
394}
395
396static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398{
399 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100400 ypr_open(pctx->out, flag);
401 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200402 }
403}
404
405static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100406ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407{
408 const char *status = NULL;
409
410 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100411 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200412 status = "current";
413 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200415 status = "deprecated";
416 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100417 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200418 status = "obsolete";
419 }
Radek Krejci693262f2019-04-29 15:23:20 +0200420
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100421 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422}
423
424static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100425ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200426{
427 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428 ypr_open(pctx->out, flag);
429 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200430 }
431}
432
433static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100434ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200435{
436 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100437 ypr_open(pctx->out, flag);
438 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439 }
440}
441
442static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100443yprp_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 +0200444{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200445 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200446 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447
Michal Vasko7f45cf22020-10-01 12:49:44 +0200448 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100449 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200450 extflag = 0;
451
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100452 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453
454 /* extensions */
455 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200456 LY_ARRAY_FOR(exts, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100457 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200458 }
459 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100460 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 }
462}
463
464static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100465yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200466{
Radek Krejci857189e2020-09-01 13:26:36 +0200467 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200468 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200469
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100470 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471 LEVEL++;
472
473 if (ext->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100474 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200475 }
476
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100477 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100478 ypr_open(pctx->out, &flag);
479 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200480 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200482 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100483 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100484 yprp_extension_instances(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200485 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486 }
487 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100488 (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 +0100489 ypr_open(pctx->out, &flag2);
490 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200492 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100493 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200494 }
495
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100496 ypr_status(pctx, ext->flags, ext->exts, &flag);
497 ypr_description(pctx, ext->dsc, ext->exts, &flag);
498 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200499
500 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100501 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200502}
503
504static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100505yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200506{
Radek Krejci857189e2020-09-01 13:26:36 +0200507 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100509 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200510 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100511 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag, 0);
512 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
513 ypr_status(pctx, feat->flags, feat->exts, &flag);
514 ypr_description(pctx, feat->dsc, feat->exts, &flag);
515 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200516 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100517 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200518}
519
520static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100521yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200522{
Radek Krejci857189e2020-09-01 13:26:36 +0200523 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200524 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200525
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100526 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200527 LEVEL++;
528
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100529 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
530 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531
532 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100533 ypr_open(pctx->out, &flag);
534 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535 }
536
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100537 ypr_status(pctx, ident->flags, ident->exts, &flag);
538 ypr_description(pctx, ident->dsc, ident->exts, &flag);
539 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200540
541 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100542 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200543}
544
545static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100546yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200547{
Radek Krejci857189e2020-09-01 13:26:36 +0200548 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200549 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200550
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100551 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200552 LEVEL++;
553
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100554 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200555
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100556 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200557 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100558 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200559 }
560
Radek Krejci693262f2019-04-29 15:23:20 +0200561 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100562 if (pctx->module != ident->derived[u]->module) {
563 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 +0200564 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100565 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200566 }
567 }
568
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100569 ypr_status(pctx, ident->flags, ident->exts, &flag);
570 ypr_description(pctx, ident->dsc, ident->exts, &flag);
571 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200572
573 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100574 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200575}
576
577static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100578yprp_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 +0200579{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100580 ly_bool inner_flag = 0, singleline;
581 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200582
583 if (!restr) {
584 return;
585 }
586
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100587 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100588 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
589 restr->arg.str : restr->arg.str + 1;
590 singleline = strchr(text, '\n') ? 0 : 1;
591 ypr_text(pctx, ly_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200592
593 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100594 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100595 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200596 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100597 ypr_open(pctx->out, &inner_flag);
598 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200599 }
600 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100601 ypr_open(pctx->out, &inner_flag);
602 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200603 }
604 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100605 ypr_open(pctx->out, &inner_flag);
606 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200607 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100608 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
609 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200610
Radek Krejcid3ca0632019-04-16 16:54:54 +0200611 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100612 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613}
614
615static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100616yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200617{
Radek Krejci857189e2020-09-01 13:26:36 +0200618 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200619
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100620 ypr_open(pctx->out, flag);
621 ly_print_(pctx->out, "%*smust \"", INDENT);
622 ypr_encode(pctx->out, must->cond->expr, -1);
623 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200624
625 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100626 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200627 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100628 ypr_open(pctx->out, &inner_flag);
629 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200630 }
631 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100632 ypr_open(pctx->out, &inner_flag);
633 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200634 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100635 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
636 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200637
638 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100639 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200640}
641
642static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100643yprc_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 +0200644{
Radek Krejci857189e2020-09-01 13:26:36 +0200645 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200646 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200647
Radek Krejci334ccc72019-06-12 13:49:29 +0200648 if (!range) {
649 return;
650 }
651
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100652 ypr_open(pctx->out, flag);
653 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200654 LY_ARRAY_FOR(range->parts, u) {
655 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100656 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200657 }
658 if (range->parts[u].max_64 == range->parts[u].min_64) {
659 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200661 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100662 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200663 }
664 } else {
665 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100666 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200667 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100668 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200669 }
670 }
671 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100672 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200673
674 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100675 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200676 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100677 ypr_open(pctx->out, &inner_flag);
678 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200679 }
680 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100681 ypr_open(pctx->out, &inner_flag);
682 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200683 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100684 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
685 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200686
687 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100688 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200689}
690
691static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100692yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200693{
Radek Krejci857189e2020-09-01 13:26:36 +0200694 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200695
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100696 ypr_open(pctx->out, flag);
697 ly_print_(pctx->out, "%*spattern \"", INDENT);
698 ypr_encode(pctx->out, pattern->expr, -1);
699 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200700
701 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100702 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200703 if (pattern->inverted) {
704 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100705 ypr_open(pctx->out, &inner_flag);
706 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200707 }
708 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100709 ypr_open(pctx->out, &inner_flag);
710 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200711 }
712 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100713 ypr_open(pctx->out, &inner_flag);
714 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200715 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100716 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
717 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200718
719 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100720 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200721}
722
723static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100724yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200725{
Radek Krejci857189e2020-09-01 13:26:36 +0200726 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200727
728 if (!when) {
729 return;
730 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100731 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200732
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100733 ly_print_(pctx->out, "%*swhen \"", INDENT);
734 ypr_encode(pctx->out, when->cond, -1);
735 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200736
737 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100738 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
739 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
740 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200741 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100742 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200743}
744
745static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100746yprc_when(struct lys_ypr_ctx *pctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200747{
Radek Krejci857189e2020-09-01 13:26:36 +0200748 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200749
750 if (!when) {
751 return;
752 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100753 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200754
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100755 ly_print_(pctx->out, "%*swhen \"", INDENT);
756 ypr_encode(pctx->out, when->cond->expr, -1);
757 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200758
759 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100760 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
761 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
762 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200763 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100764 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200765}
766
767static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100768yprp_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 +0200769{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200770 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200771 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200772
773 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100774 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200775 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100776 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200777 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778 ly_print_(pctx->out, "%*senum \"", INDENT);
779 ypr_encode(pctx->out, items[u].name, -1);
780 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200781 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782 inner_flag = 0;
783 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100784 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag, 0);
785 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200786 if (items[u].flags & LYS_SET_VALUE) {
787 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100788 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200789 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100790 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200791 }
792 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100793 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
794 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
795 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100797 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200798 }
799}
800
801static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100802yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200803{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200804 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200805 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200806
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100807 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200808 LEVEL++;
809
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100810 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200811
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100812 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
813 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200814 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100815 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200816 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100817 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
818 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200819
820 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100821 ypr_open(pctx->out, &flag);
822 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200823 }
824 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100825 ypr_open(pctx->out, &flag);
826 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200827 }
828 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100829 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200830 }
831 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100832 ypr_open(pctx->out, &flag);
833 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834 }
835 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100836 ypr_open(pctx->out, &flag);
837 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200838 }
839
840 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100841 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842}
843
844static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100845yprc_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 +0200846 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200847{
Radek Krejci857189e2020-09-01 13:26:36 +0200848 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200849 const char *str;
850
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100851 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
852 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200853 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200854 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200855 }
856}
857
858static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100859yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200860{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200861 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200862 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200863
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100864 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200865 LEVEL++;
866
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100867 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200868
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200869 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200870 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200871 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200872
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100873 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200874 break;
875 }
876 case LY_TYPE_UINT8:
877 case LY_TYPE_UINT16:
878 case LY_TYPE_UINT32:
879 case LY_TYPE_UINT64:
880 case LY_TYPE_INT8:
881 case LY_TYPE_INT16:
882 case LY_TYPE_INT32:
883 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200884 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200885
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100886 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200887 break;
888 }
889 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200890 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200891
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100892 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200893 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100894 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200895 }
896 break;
897 }
898 case LY_TYPE_BITS:
899 case LY_TYPE_ENUM: {
900 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200901 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200902
Radek Krejci693262f2019-04-29 15:23:20 +0200903 LY_ARRAY_FOR(bits->bits, u) {
904 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200905 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200906
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100907 ypr_open(pctx->out, &flag);
908 ly_print_(pctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
909 ypr_encode(pctx->out, item->name, -1);
910 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200911 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200912 if (type->basetype == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100913 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
914 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200915 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100916 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
917 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200918 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100919 ypr_status(pctx, item->flags, item->exts, &inner_flag);
920 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
921 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200922 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100923 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200924 }
925 break;
926 }
927 case LY_TYPE_BOOL:
928 case LY_TYPE_EMPTY:
929 /* nothing to do */
930 break;
931 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200932 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200933
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100934 ypr_open(pctx->out, &flag);
935 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
936 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200937 break;
938 }
939 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200940 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200941
Radek Krejci693262f2019-04-29 15:23:20 +0200942 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100943 ypr_open(pctx->out, &flag);
944 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200945 }
946 break;
947 }
948 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200949 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200950
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100951 ypr_open(pctx->out, &flag);
952 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200953 break;
954 }
955 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200956 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200957
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100958 ypr_open(pctx->out, &flag);
959 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
960 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
961 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200962 break;
963 }
964 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200965 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200966
Radek Krejci693262f2019-04-29 15:23:20 +0200967 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100968 ypr_open(pctx->out, &flag);
969 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200970 }
971 break;
972 }
973 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100974 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200975 }
976
977 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100978 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200979}
980
981static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100982yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200983{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100984 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200985 LEVEL++;
986
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100987 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200988
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100989 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200990
991 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100992 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200993 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200994 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100995 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200996 }
997
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100998 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
999 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1000 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001001
1002 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001003 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001004}
1005
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001006static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1007static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1008static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1009static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001010
1011static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001012yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001013{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001014 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001015 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001016 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001017 struct lysp_node_action *action;
1018 struct lysp_node_notif *notif;
1019 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001020
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001021 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001022 LEVEL++;
1023
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001024 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
1025 ypr_status(pctx, grp->flags, grp->exts, &flag);
1026 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1027 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001028
1029 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001030 ypr_open(pctx->out, &flag);
1031 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032 }
1033
Radek Krejci2a9fc652021-01-22 17:44:34 +01001034 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001035 ypr_open(pctx->out, &flag);
1036 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001037 }
1038
Radek Krejci01180ac2021-01-27 08:48:22 +01001039 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001040 ypr_open(pctx->out, &flag);
1041 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001042 }
1043
Radek Krejci2a9fc652021-01-22 17:44:34 +01001044 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001045 ypr_open(pctx->out, &flag);
1046 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001047 }
1048
1049 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001050 ypr_open(pctx->out, &flag);
1051 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001052 }
1053
1054 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001055 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001056}
1057
1058static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001059yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001060{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001061 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001063 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001064
Radek Krejci01180ac2021-01-27 08:48:22 +01001065 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001066 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067 return;
1068 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001069 ypr_open(pctx->out, flag);
1070 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001071
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001072 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073 LEVEL++;
1074
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001075 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001077 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078 }
1079 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001080 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001082 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001083 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001084 }
1085
Radek Krejci01180ac2021-01-27 08:48:22 +01001086 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001087 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001088 }
1089
1090 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001091 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001092}
1093
1094static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001095yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001096{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001097 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001098 struct lysc_node *data;
1099
Radek Krejci01180ac2021-01-27 08:48:22 +01001100 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001101 /* input/output is empty */
1102 return;
1103 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001104 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001105
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001106 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001107 LEVEL++;
1108
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001109 yprc_extension_instances(pctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001110 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001111 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001112 }
1113
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001114 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001115 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001116 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001117 }
Radek Krejci693262f2019-04-29 15:23:20 +02001118 }
1119
1120 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001121 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001122}
1123
1124static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001125yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001126{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001127 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001128 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001129 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001130 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001131
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001132 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001133
1134 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001135 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
1136 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001137
1138 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001139 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001140 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001141 ypr_status(pctx, notif->flags, notif->exts, &flag);
1142 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1143 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001144
1145 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001146 ypr_open(pctx->out, &flag);
1147 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001148 }
1149
Radek Krejci2a9fc652021-01-22 17:44:34 +01001150 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001151 ypr_open(pctx->out, &flag);
1152 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001153 }
1154
Radek Krejci01180ac2021-01-27 08:48:22 +01001155 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001156 ypr_open(pctx->out, &flag);
1157 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001158 }
1159
1160 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001161 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001162}
1163
1164static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001165yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001166{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001167 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001168 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001169 struct lysc_node *data;
1170
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001171 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001172
1173 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001174 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001175
1176 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001177 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001178 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001179 ypr_status(pctx, notif->flags, notif->exts, &flag);
1180 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1181 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001182
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001183 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001184 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001185 ypr_open(pctx->out, &flag);
1186 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001187 }
Radek Krejci693262f2019-04-29 15:23:20 +02001188 }
1189
1190 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001191 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001192}
1193
1194static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001195yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001196{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001197 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001198 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001199 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001200
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001202
1203 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001204 yprp_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
1205 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1206 ypr_status(pctx, action->flags, action->exts, &flag);
1207 ypr_description(pctx, action->dsc, action->exts, &flag);
1208 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001209
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001210 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001211
Radek Krejcid3ca0632019-04-16 16:54:54 +02001212 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001213 ypr_open(pctx->out, &flag);
1214 YPR_EXTRA_LINE_PRINT(pctx);
1215 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001216 }
1217
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001218 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001219
Radek Krejci2a9fc652021-01-22 17:44:34 +01001220 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001221 ypr_open(pctx->out, &flag);
1222 YPR_EXTRA_LINE_PRINT(pctx);
1223 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001224 }
1225
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001226 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001227
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001228 yprp_inout(pctx, &action->input, &flag);
1229 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001230
1231 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001232 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001233}
1234
1235static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001236yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001237{
Radek Krejci857189e2020-09-01 13:26:36 +02001238 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001239
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001240 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001241
1242 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001243 yprc_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
1244 ypr_status(pctx, action->flags, action->exts, &flag);
1245 ypr_description(pctx, action->dsc, action->exts, &flag);
1246 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001247
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001248 yprc_inout(pctx, &action->input, &flag);
1249 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001250
1251 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001252 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001253}
1254
1255static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001256yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001257{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001258 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001259 LEVEL++;
1260
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001261 yprp_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
1262 yprp_when(pctx, lysp_node_when(node), flag);
1263 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001264}
1265
1266static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001267yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001268{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001269 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001270 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001271
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001272 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001273 LEVEL++;
1274
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001275 yprc_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001276
1277 when = lysc_node_when(node);
1278 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001279 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001280 }
Radek Krejci693262f2019-04-29 15:23:20 +02001281}
1282
1283/* macr oto unify the code */
1284#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001285 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001286 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001287 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001288 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001289 ypr_status(pctx, node->flags, node->exts, flag); \
1290 ypr_description(pctx, node->dsc, node->exts, flag); \
1291 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001292
1293static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001294yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001295{
1296 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001297}
1298
1299static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001300yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001301{
1302 YPR_NODE_COMMON2;
1303}
1304
1305#undef YPR_NODE_COMMON2
1306
1307static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001308yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001309{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001310 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001311 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001312 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001313 struct lysp_node_action *action;
1314 struct lysp_node_notif *notif;
1315 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001316 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1317
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001318 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001319
1320 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001321 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001322 }
1323 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001324 ypr_open(pctx->out, &flag);
1325 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001326 }
1327
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001328 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001329
1330 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001331 ypr_open(pctx->out, &flag);
1332 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001333 }
1334
Radek Krejci2a9fc652021-01-22 17:44:34 +01001335 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001336 ypr_open(pctx->out, &flag);
1337 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001338 }
1339
1340 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001341 ypr_open(pctx->out, &flag);
1342 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001343 }
1344
Radek Krejci2a9fc652021-01-22 17:44:34 +01001345 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001346 ypr_open(pctx->out, &flag);
1347 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001348 }
1349
Radek Krejci2a9fc652021-01-22 17:44:34 +01001350 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001351 ypr_open(pctx->out, &flag);
1352 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001353 }
1354
1355 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001356 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001357}
1358
1359static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001360yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001361{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001362 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001363 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001364 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001365 struct lysc_node_action *action;
1366 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001367 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1368
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001369 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001370
1371 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001372 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001373 }
1374 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001375 ypr_open(pctx->out, &flag);
1376 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001377 }
1378
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001379 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001380
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001381 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001382 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001383 ypr_open(pctx->out, &flag);
1384 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001385 }
Radek Krejci693262f2019-04-29 15:23:20 +02001386
Radek Krejci2a9fc652021-01-22 17:44:34 +01001387 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001388 ypr_open(pctx->out, &flag);
1389 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001390 }
Radek Krejci693262f2019-04-29 15:23:20 +02001391
Radek Krejci2a9fc652021-01-22 17:44:34 +01001392 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001393 ypr_open(pctx->out, &flag);
1394 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001395 }
Radek Krejci693262f2019-04-29 15:23:20 +02001396 }
1397
1398 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001399 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001400}
1401
1402static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001403yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001404{
Radek Krejci857189e2020-09-01 13:26:36 +02001405 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001406 struct lysp_node *child;
1407 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1408
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001409 yprp_node_common1(pctx, node, &flag);
1410 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001411
1412 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001413 ypr_open(pctx->out, &flag);
1414 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001415 }
1416
1417 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001418 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001419}
1420
1421static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001422yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001423{
Radek Krejci857189e2020-09-01 13:26:36 +02001424 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001425 struct lysc_node *child;
1426
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001427 yprc_node_common1(pctx, &cs->node, &flag);
1428 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001429
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001430 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001431 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001432 ypr_open(pctx->out, &flag);
1433 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001434 }
Radek Krejci693262f2019-04-29 15:23:20 +02001435 }
1436
1437 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001438 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001439}
1440
1441static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001442yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001443{
Radek Krejci857189e2020-09-01 13:26:36 +02001444 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001445 struct lysp_node *child;
1446 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1447
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001448 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001449
Michal Vasko7f45cf22020-10-01 12:49:44 +02001450 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001451 ypr_open(pctx->out, &flag);
1452 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001453 }
1454
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001455 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001456
1457 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001458 ypr_open(pctx->out, &flag);
1459 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001460 }
1461
1462 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001463 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001464}
1465
1466static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001467yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001468{
Radek Krejci857189e2020-09-01 13:26:36 +02001469 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001470 struct lysc_node_case *cs;
1471 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1472
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001473 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001474
1475 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001476 ypr_open(pctx->out, &flag);
1477 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001478 }
1479
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001480 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001481
Michal Vasko22df3f02020-08-24 13:29:22 +02001482 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001483 ypr_open(pctx->out, &flag);
1484 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001485 }
1486
1487 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001488 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001489}
1490
1491static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001492yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001493{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001494 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001495 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1496
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001497 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001498
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001499 yprp_type(pctx, &leaf->type);
1500 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001501 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001502 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001503 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001504 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001505
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001506 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001507
1508 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001509 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001510}
1511
1512static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001513yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001514{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001515 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001516 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1517
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001518 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001519
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001520 yprc_type(pctx, leaf->type);
1521 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001522 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001523 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001524 }
Radek Krejcia1911222019-07-22 17:24:50 +02001525
1526 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001527 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001528 }
Radek Krejci693262f2019-04-29 15:23:20 +02001529
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001530 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001531
1532 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001533 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001534}
1535
1536static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001537yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001538{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001539 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001540 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1541
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001542 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001543
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001544 yprp_type(pctx, &llist->type);
1545 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001546 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001547 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001548 }
1549 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001550 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001551 }
1552
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001553 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554
1555 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001556 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001557 }
1558 if (llist->flags & LYS_SET_MAX) {
1559 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001560 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001562 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001563 }
1564 }
1565
1566 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001567 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001568 }
1569
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001570 ypr_status(pctx, node->flags, node->exts, NULL);
1571 ypr_description(pctx, node->dsc, node->exts, NULL);
1572 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573
1574 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001575 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001576}
1577
1578static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001579yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001580{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001581 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001582 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1583
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001584 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001585
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001586 yprc_type(pctx, llist->type);
1587 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001588 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001589 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001590 }
1591 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001592 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001593 }
1594
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001595 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001596
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001597 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001598 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001599 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001600 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001601 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001602 }
1603
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001604 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001605
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001606 ypr_status(pctx, node->flags, node->exts, NULL);
1607 ypr_description(pctx, node->dsc, node->exts, NULL);
1608 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001609
1610 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001611 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001612}
1613
1614static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001615yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001616{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001617 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001618 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001619 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001620 struct lysp_node_action *action;
1621 struct lysp_node_notif *notif;
1622 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001623 struct lysp_node_list *list = (struct lysp_node_list *)node;
1624
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001625 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001626
1627 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001628 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001629 }
1630 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001631 ypr_open(pctx->out, &flag);
1632 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633 }
1634 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001635 ypr_open(pctx->out, &flag);
1636 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001637 }
1638
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001639 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001640
1641 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001642 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001643 }
1644 if (list->flags & LYS_SET_MAX) {
1645 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001646 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001648 ypr_open(pctx->out, &flag);
1649 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001650 }
1651 }
1652
1653 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001654 ypr_open(pctx->out, &flag);
1655 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001656 }
1657
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001658 ypr_status(pctx, node->flags, node->exts, &flag);
1659 ypr_description(pctx, node->dsc, node->exts, &flag);
1660 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001661
1662 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001663 ypr_open(pctx->out, &flag);
1664 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001665 }
1666
Radek Krejci2a9fc652021-01-22 17:44:34 +01001667 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001668 ypr_open(pctx->out, &flag);
1669 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001670 }
1671
1672 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001673 ypr_open(pctx->out, &flag);
1674 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001675 }
1676
Radek Krejci2a9fc652021-01-22 17:44:34 +01001677 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001678 ypr_open(pctx->out, &flag);
1679 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001680 }
1681
Radek Krejci2a9fc652021-01-22 17:44:34 +01001682 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001683 ypr_open(pctx->out, &flag);
1684 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001685 }
1686
1687 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001688 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001689}
1690
1691static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001692yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001693{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001694 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001695 struct lysc_node_list *list = (struct lysc_node_list *)node;
1696
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001697 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001698
1699 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001700 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001701 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001702 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001703 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001704 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 +01001705 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001706 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001707 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001708 }
1709 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001710 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001711 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001712 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001713 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001714 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001715 }
1716
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001717 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001718
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001719 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001720 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001721 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001722 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001723 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001724 }
1725
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001726 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001727
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001728 ypr_status(pctx, node->flags, node->exts, NULL);
1729 ypr_description(pctx, node->dsc, node->exts, NULL);
1730 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001731
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001732 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001733 struct lysc_node *child;
1734 struct lysc_node_action *action;
1735 struct lysc_node_notif *notif;
1736
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001737 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001738 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001739 }
Radek Krejci693262f2019-04-29 15:23:20 +02001740
Radek Krejci2a9fc652021-01-22 17:44:34 +01001741 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001742 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001743 }
Radek Krejci693262f2019-04-29 15:23:20 +02001744
Radek Krejci2a9fc652021-01-22 17:44:34 +01001745 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001746 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001747 }
Radek Krejci693262f2019-04-29 15:23:20 +02001748 }
1749
1750 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001751 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001752}
1753
1754static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001755yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001756{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001757 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001758 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001759
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001760 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001761 LEVEL++;
1762
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001763 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
1764 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001765
1766 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001767 ypr_open(pctx->out, &flag);
1768 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769 }
1770
1771 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001772 ypr_open(pctx->out, &flag);
1773 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774 }
1775
1776 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001777 ypr_open(pctx->out, &flag);
1778 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779 }
1780
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001781 ypr_config(pctx, refine->flags, refine->exts, &flag);
1782 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783
1784 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001785 ypr_open(pctx->out, &flag);
1786 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787 }
1788 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001789 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001791 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001792 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001793 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001794 }
1795 }
1796
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001797 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1798 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799
1800 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001801 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802}
1803
1804static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001805yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001807 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001808 struct lysp_node_action *action;
1809 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001811 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812 LEVEL++;
1813
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001814 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
1815 yprp_when(pctx, aug->when, NULL);
1816 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1817 ypr_status(pctx, aug->flags, aug->exts, NULL);
1818 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1819 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820
1821 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001822 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823 }
1824
Radek Krejci2a9fc652021-01-22 17:44:34 +01001825 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001826 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827 }
1828
Radek Krejci2a9fc652021-01-22 17:44:34 +01001829 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001830 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001831 }
1832
1833 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001834 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001835}
1836
Radek Krejcid3ca0632019-04-16 16:54:54 +02001837static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001838yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001839{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001840 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001841 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001842 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001843 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001844
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001845 yprp_node_common1(pctx, node, &flag);
1846 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847
1848 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001849 ypr_open(pctx->out, &flag);
1850 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851 }
1852
Radek Krejci2a9fc652021-01-22 17:44:34 +01001853 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001854 ypr_open(pctx->out, &flag);
1855 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856 }
1857
1858 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001859 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860}
1861
1862static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001863yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001865 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001866 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001867 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1868
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001869 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001870
1871 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001872 ypr_open(pctx->out, &flag);
1873 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001874 }
1875
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001876 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877
1878 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001879 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880}
1881
1882static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001883yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001885 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001886 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001887 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001888
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001889 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001890
Radek Krejci693262f2019-04-29 15:23:20 +02001891 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001892 ypr_open(pctx->out, &flag);
1893 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001894 }
1895
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001896 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001897
Radek Krejcid3ca0632019-04-16 16:54:54 +02001898 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001899 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900}
1901
1902static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001903yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904{
1905 switch (node->nodetype) {
1906 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001907 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001908 break;
1909 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001910 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001911 break;
1912 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001913 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914 break;
1915 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001916 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001917 break;
1918 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001919 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 break;
1921 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001922 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001923 break;
1924 case LYS_ANYXML:
1925 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001926 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001927 break;
1928 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001929 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930 break;
1931 default:
1932 break;
1933 }
1934}
1935
1936static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001937yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001938{
1939 switch (node->nodetype) {
1940 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001941 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001942 break;
1943 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001944 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001945 break;
1946 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001947 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001948 break;
1949 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001950 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001951 break;
1952 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001953 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001954 break;
1955 case LYS_ANYXML:
1956 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001957 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001958 break;
1959 default:
1960 break;
1961 }
1962}
1963
1964static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001965yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001966{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001967 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001968 struct lysp_deviate_add *add;
1969 struct lysp_deviate_rpl *rpl;
1970 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001971 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001972
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001973 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001974 LEVEL++;
1975
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001976 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
1977 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1978 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979
fredgan2b11ddb2019-10-21 11:03:39 +08001980 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001981 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001982 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1983 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001984 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001985 LEVEL++;
1986
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001987 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001988 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001989 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 continue;
1991 }
fredgan2b11ddb2019-10-21 11:03:39 +08001992 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001993 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001994 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001995 LEVEL++;
1996
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001997 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL, 0);
1998 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001999 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002000 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002002 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002003 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002005 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002008 ypr_config(pctx, add->flags, add->exts, NULL);
2009 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002011 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 }
2013 if (add->flags & LYS_SET_MAX) {
2014 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002015 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002017 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 }
2019 }
fredgan2b11ddb2019-10-21 11:03:39 +08002020 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002021 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002022 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 LEVEL++;
2024
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002025 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002027 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002029 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2030 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2031 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2032 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002034 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 }
2036 if (rpl->flags & LYS_SET_MAX) {
2037 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002038 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002039 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002040 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 }
2042 }
fredgan2b11ddb2019-10-21 11:03:39 +08002043 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002044 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002045 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002046 LEVEL++;
2047
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002048 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
2049 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002050 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002051 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002052 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002053 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002054 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002056 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002057 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002058 }
2059 }
2060
2061 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002062 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 }
2064
2065 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002066 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002067}
2068
Michal Vasko7c8439f2020-08-05 13:25:19 +02002069static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002070yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002071{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002072 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002073
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002075 if (modp->imports[u].flags & LYS_INTERNAL) {
2076 continue;
2077 }
2078
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002079 YPR_EXTRA_LINE_PRINT(pctx);
2080 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002081 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002082 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
2083 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002084 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002085 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002086 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002087 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2088 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002090 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002092 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002093
Radek Krejcid3ca0632019-04-16 16:54:54 +02002094 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002095 if (modp->includes[u].injected) {
2096 /* do not print the includes injected from submodules */
2097 continue;
2098 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002099 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002100 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 +01002101 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002103 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002104 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002105 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002107 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2108 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002109 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002110 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002111 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002112 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002113 }
2114 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002115 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002116}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117
Michal Vasko7c8439f2020-08-05 13:25:19 +02002118static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002119yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002120{
2121 LY_ARRAY_COUNT_TYPE u;
2122 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002123 struct lysp_node_action *action;
2124 struct lysp_node_notif *notif;
2125 struct lysp_node_grp *grp;
2126 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127
Radek Krejcid3ca0632019-04-16 16:54:54 +02002128 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002129 YPR_EXTRA_LINE_PRINT(pctx);
2130 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002131 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002132
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002133 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002134
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002136 YPR_EXTRA_LINE_PRINT(pctx);
2137 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002138 }
2139
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002140 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002141
Radek Krejcid3ca0632019-04-16 16:54:54 +02002142 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002143 YPR_EXTRA_LINE_PRINT(pctx);
2144 yprp_feature(pctx, &modp->features[u]);
2145 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002146 }
2147
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002148 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002149
Radek Krejcid3ca0632019-04-16 16:54:54 +02002150 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002151 YPR_EXTRA_LINE_PRINT(pctx);
2152 yprp_identity(pctx, &modp->identities[u]);
2153 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002154 }
2155
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002156 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002157
Radek Krejcid3ca0632019-04-16 16:54:54 +02002158 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002159 YPR_EXTRA_LINE_PRINT(pctx);
2160 yprp_typedef(pctx, &modp->typedefs[u]);
2161 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002162 }
2163
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002164 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002165
Radek Krejci2a9fc652021-01-22 17:44:34 +01002166 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002167 YPR_EXTRA_LINE_PRINT(pctx);
2168 yprp_grouping(pctx, grp);
2169 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002170 }
2171
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002172 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002173
Radek Krejcid3ca0632019-04-16 16:54:54 +02002174 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002175 YPR_EXTRA_LINE_PRINT(pctx);
2176 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002177 }
2178
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002179 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002180
Radek Krejci2a9fc652021-01-22 17:44:34 +01002181 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002182 YPR_EXTRA_LINE_PRINT(pctx);
2183 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002184 }
2185
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002186 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002187
Radek Krejci2a9fc652021-01-22 17:44:34 +01002188 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE_PRINT(pctx);
2190 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 }
2192
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002193 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002194
Radek Krejci2a9fc652021-01-22 17:44:34 +01002195 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002196 YPR_EXTRA_LINE_PRINT(pctx);
2197 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002198 }
2199
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002200 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002201
Radek Krejcid3ca0632019-04-16 16:54:54 +02002202 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002203 YPR_EXTRA_LINE_PRINT(pctx);
2204 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002205 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002206
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002207 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002208}
2209
2210LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002211yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002212{
2213 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002214 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002215 struct lys_ypr_ctx pctx_ = {
2216 .out = out,
2217 .level = 0,
2218 .module = module,
2219 .schema = LYS_YPR_PARSED,
2220 .options = options
2221 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002222
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002223 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002224 LEVEL++;
2225
2226 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002227 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002228 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 +02002229 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002230 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2231 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002232
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002234
Michal Vasko7c8439f2020-08-05 13:25:19 +02002235 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002236 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002237
2238 /* meta-stmts */
2239 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002240 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002241 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002242 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2243 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2244 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2245 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002246
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002247 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002248
Michal Vasko7c8439f2020-08-05 13:25:19 +02002249 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002250 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002251 YPR_EXTRA_LINE_PRINT(pctx);
2252 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002253 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002254
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002255 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002256
Michal Vasko7c8439f2020-08-05 13:25:19 +02002257 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002258 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002259
2260 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002261 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002262 ly_print_flush(out);
2263
2264 return LY_SUCCESS;
2265}
2266
2267static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002268yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002269{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002270 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002271 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002272 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2273 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002274 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002275 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002276}
2277
2278LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002279yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002280{
2281 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002282 struct lys_ypr_ctx pctx_ = {
Radek Krejci07a55962021-03-02 20:16:43 +01002283 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2284 .options = options
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002285 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002286
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002287 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002288 LEVEL++;
2289
2290 /* submodule-header-stmts */
2291 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002292 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 +02002293 }
2294
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002295 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002296
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002297 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002298
Michal Vasko7c8439f2020-08-05 13:25:19 +02002299 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002300 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002301
2302 /* meta-stmts */
2303 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002304 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002305 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002306 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2307 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2308 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2309 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002310
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002311 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002312
Michal Vasko7c8439f2020-08-05 13:25:19 +02002313 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002314 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002315 YPR_EXTRA_LINE_PRINT(pctx);
2316 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002317 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002318
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002319 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002320
Michal Vasko7c8439f2020-08-05 13:25:19 +02002321 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002322 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002323
2324 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002325 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002326 ly_print_flush(out);
2327
2328 return LY_SUCCESS;
2329}
2330
2331LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002332yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002333{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002334 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002335
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002336 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002337
2338 ly_print_flush(out);
2339 return LY_SUCCESS;
2340}
2341
2342LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002343yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002344{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002345 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002346 struct lysc_module *modc = module->compiled;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002347 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = module, .options = options}, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002348
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002349 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002350 LEVEL++;
2351
Radek Krejci693262f2019-04-29 15:23:20 +02002352 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002353 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2354 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002355
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002356 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002357
Michal Vasko7c8439f2020-08-05 13:25:19 +02002358 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002359
2360 /* meta-stmts */
2361 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002362 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002363 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002364 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2365 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2366 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2367 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002368
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002369 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002370
Radek Krejci693262f2019-04-29 15:23:20 +02002371 /* revision-stmts */
2372 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002373 YPR_EXTRA_LINE_PRINT(pctx);
2374 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2375 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002376 }
2377
2378 /* body-stmts */
2379 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002380 YPR_EXTRA_LINE_PRINT(pctx);
2381 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
2382 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002383 }
2384
Radek Krejci80d281e2020-09-14 17:42:54 +02002385 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002386 YPR_EXTRA_LINE_PRINT(pctx);
2387 yprc_identity(pctx, &module->identities[u]);
2388 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002389 }
2390
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002391 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002392 struct lysc_node *data;
2393 struct lysc_node_action *rpc;
2394 struct lysc_node_notif *notif;
2395
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002396 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002397 YPR_EXTRA_LINE_PRINT(pctx);
2398 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002399 }
Radek Krejci693262f2019-04-29 15:23:20 +02002400
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002401 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002402
Radek Krejci2a9fc652021-01-22 17:44:34 +01002403 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002404 YPR_EXTRA_LINE_PRINT(pctx);
2405 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002406 }
Radek Krejci693262f2019-04-29 15:23:20 +02002407
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002408 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002409
Radek Krejci2a9fc652021-01-22 17:44:34 +01002410 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002411 YPR_EXTRA_LINE_PRINT(pctx);
2412 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002413 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002414
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002415 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002416 }
2417
2418 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002419 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002420 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002421
2422 return LY_SUCCESS;
2423}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002424
2425/**
2426 * @param[in] count Number of extensions to print, 0 to print them all.
2427 */
2428static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002429yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002430 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2431{
2432 LY_ARRAY_COUNT_TYPE u;
2433
2434 if (!count && ext) {
2435 count = LY_ARRAY_COUNT(ext);
2436 }
2437 LY_ARRAY_FOR(ext, u) {
2438 ly_bool inner_flag = 0;
2439
2440 if (!count) {
2441 break;
2442 }
2443
2444 count--;
Radek Krejciab430862021-03-02 20:13:40 +01002445 if ((ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002446 continue;
2447 }
2448
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002449 ypr_open(pctx->out, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002450 if (ext[u].argument) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002451 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2452 ypr_encode(pctx->out, ext[u].argument, -1);
2453 ly_print_(pctx->out, "\"");
Radek Krejciadcf63d2021-02-09 10:21:18 +01002454 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002455 ly_print_(pctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002456 }
2457
2458 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002459 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002460
Radek Krejci4a4d1e02021-04-09 14:04:40 +02002461 if (ext[u].def->plugin && ext[u].def->plugin->sprinter) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002462 ext[u].def->plugin->sprinter(&pctx->printer_ctx, &ext[u], &inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002463 }
2464
2465 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002466 ypr_close(pctx, inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002467 }
2468}
2469
2470void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002471lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002472{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002473 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002474 LY_ARRAY_COUNT_TYPE u, v;
2475
2476 LY_ARRAY_FOR(ext->substmts, u) {
2477 switch (ext->substmts[u].stmt) {
2478 case LY_STMT_CHOICE:
2479 case LY_STMT_CONTAINER: {
2480 const struct lysc_node *node;
2481
2482 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002483 ypr_open(pctx->out, flag);
2484 yprc_node(pctx, node);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002485 }
2486 break;
2487 }
2488 case LY_STMT_DESCRIPTION:
2489 case LY_STMT_REFERENCE:
2490 case LY_STMT_UNITS:
2491 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2492 if (*(const char **)ext->substmts[u].storage) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002493 ypr_open(pctx->out, flag);
2494 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002495 }
2496 } else {
2497 const char **strings = *(const char ***)ext->substmts[u].storage;
Michal Vasko26bbb272022-08-02 14:54:33 +02002498
Radek Krejciadcf63d2021-02-09 10:21:18 +01002499 LY_ARRAY_FOR(strings, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002500 ypr_open(pctx->out, flag);
2501 ypr_substmt(pctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002502 }
2503 }
2504 break;
2505 case LY_STMT_IF_FEATURE:
2506 /* nothing to do */
2507 break;
2508 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002509 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002510 break;
2511 case LY_STMT_TYPE:
2512 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2513 if (*(const struct lysc_type **)ext->substmts[u].storage) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002514 ypr_open(pctx->out, flag);
2515 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002516 }
2517 } else {
2518 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
Michal Vasko26bbb272022-08-02 14:54:33 +02002519
Radek Krejciadcf63d2021-02-09 10:21:18 +01002520 LY_ARRAY_FOR(types, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002521 ypr_open(pctx->out, flag);
2522 yprc_type(pctx, types[v]);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002523 }
2524 }
2525 break;
2526 /* TODO support other substatements */
2527 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002528 LOGWRN(pctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
Radek Krejciadcf63d2021-02-09 10:21:18 +01002529 ly_stmt2str(ext->substmts[u].stmt));
2530 break;
2531 }
2532 }
2533}