blob: e1e4f2041433aa72adcb6bd980882669a13b3ae3 [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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100162 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100164 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200165 }
166}
167
168static void
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100174 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200175 } else {
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100187 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200188 }
189 }
190
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100191 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192 if (closed) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100193 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 } else {
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100219 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 }
221 }
222 LEVEL--;
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100235 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236 }
237 LEVEL--;
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100291 ly_print_(pctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200292 child_presence = 1;
293 }
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100298 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200299 } else {
Michal Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-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 Vaskoc08b9d22022-02-10 15:48:39 +0100338 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200339}
340
341static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100342ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200343{
344 char *str;
345
Radek Krejci1deb5be2020-08-26 16:43:36 +0200346 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100347 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200348 return;
349 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100350 ypr_open(pctx->out, flag);
351 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200352 free(str);
353}
354
355static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100356ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200357{
358 char *str;
359
Radek Krejci1deb5be2020-08-26 16:43:36 +0200360 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100361 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200362 return;
363 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100364 ypr_open(pctx->out, flag);
365 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200366 free(str);
367}
368
369static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100370yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200371{
372 if (rev->dsc || rev->ref || rev->exts) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100373 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200374 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100375 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL, 0);
376 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
377 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100379 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100381 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 }
383}
384
385static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100386ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200387{
388 if (flags & LYS_MAND_MASK) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100389 ypr_open(pctx->out, flag);
390 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200391 }
392}
393
394static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100395ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200396{
397 if (flags & LYS_CONFIG_MASK) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100398 ypr_open(pctx->out, flag);
399 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200400 }
401}
402
403static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100404ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200405{
406 const char *status = NULL;
407
408 if (flags & LYS_STATUS_CURR) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100409 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200410 status = "current";
411 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100412 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200413 status = "deprecated";
414 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100415 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416 status = "obsolete";
417 }
Radek Krejci693262f2019-04-29 15:23:20 +0200418
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100419 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200420}
421
422static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100423ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200424{
425 if (dsc) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100426 ypr_open(pctx->out, flag);
427 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200428 }
429}
430
431static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100432ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433{
434 if (ref) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100435 ypr_open(pctx->out, flag);
436 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200437 }
438}
439
440static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100441yprp_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 +0200442{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200443 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200444 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200445
Michal Vasko7f45cf22020-10-01 12:49:44 +0200446 LY_ARRAY_FOR(iffs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100447 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200448 extflag = 0;
449
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100450 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200451
452 /* extensions */
453 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200454 LY_ARRAY_FOR(exts, v) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100455 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200456 }
457 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100458 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200459 }
460}
461
462static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100463yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464{
Radek Krejci857189e2020-09-01 13:26:36 +0200465 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200466 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200467
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100468 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200469 LEVEL++;
470
471 if (ext->exts) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100472 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200473 }
474
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100475 if (ext->argname) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100476 ypr_open(pctx->out, &flag);
477 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200478 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200479 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200480 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100481 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100482 yprp_extension_instances(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200484 }
485 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100486 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100487 ypr_open(pctx->out, &flag2);
488 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200489 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200490 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100491 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200492 }
493
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100494 ypr_status(pctx, ext->flags, ext->exts, &flag);
495 ypr_description(pctx, ext->dsc, ext->exts, &flag);
496 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200497
498 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100499 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200500}
501
502static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100503yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200504{
Radek Krejci857189e2020-09-01 13:26:36 +0200505 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200506
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100507 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100509 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag, 0);
510 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
511 ypr_status(pctx, feat->flags, feat->exts, &flag);
512 ypr_description(pctx, feat->dsc, feat->exts, &flag);
513 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200514 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100515 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200516}
517
518static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100519yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200520{
Radek Krejci857189e2020-09-01 13:26:36 +0200521 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200522 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200523
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100524 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200525 LEVEL++;
526
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100527 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
528 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200529
530 LY_ARRAY_FOR(ident->bases, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100531 ypr_open(pctx->out, &flag);
532 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533 }
534
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100535 ypr_status(pctx, ident->flags, ident->exts, &flag);
536 ypr_description(pctx, ident->dsc, ident->exts, &flag);
537 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200538
539 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100540 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200541}
542
543static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100544yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200545{
Radek Krejci857189e2020-09-01 13:26:36 +0200546 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200547 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200548
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100549 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200550 LEVEL++;
551
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100552 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200553
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100554 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200555 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100556 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200557 }
558
Radek Krejci693262f2019-04-29 15:23:20 +0200559 LY_ARRAY_FOR(ident->derived, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100560 if (pctx->module != ident->derived[u]->module) {
561 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 +0200562 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100563 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200564 }
565 }
566
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100567 ypr_status(pctx, ident->flags, ident->exts, &flag);
568 ypr_description(pctx, ident->dsc, ident->exts, &flag);
569 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200570
571 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100572 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200573}
574
575static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100576yprp_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 +0200577{
Radek Krejci857189e2020-09-01 13:26:36 +0200578 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200579
580 if (!restr) {
581 return;
582 }
583
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100584 ypr_open(pctx->out, flag);
585 ly_print_(pctx->out, "%*s%s \"", INDENT, ly_stmt2str(stmt));
586 ypr_encode(pctx->out,
Radek Krejcif13b87b2020-12-01 22:02:17 +0100587 (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
588 restr->arg.str : &restr->arg.str[1], -1);
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100589 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200590
591 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100592 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100593 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200594 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100595 ypr_open(pctx->out, &inner_flag);
596 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200597 }
598 if (restr->emsg) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100599 ypr_open(pctx->out, &inner_flag);
600 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200601 }
602 if (restr->eapptag) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100603 ypr_open(pctx->out, &inner_flag);
604 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200605 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100606 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
607 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200608
Radek Krejcid3ca0632019-04-16 16:54:54 +0200609 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100610 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200611}
612
613static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100614yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200615{
Radek Krejci857189e2020-09-01 13:26:36 +0200616 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200617
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100618 ypr_open(pctx->out, flag);
619 ly_print_(pctx->out, "%*smust \"", INDENT);
620 ypr_encode(pctx->out, must->cond->expr, -1);
621 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200622
623 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100624 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200625 if (must->emsg) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100626 ypr_open(pctx->out, &inner_flag);
627 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200628 }
629 if (must->eapptag) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100630 ypr_open(pctx->out, &inner_flag);
631 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200632 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100633 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
634 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200635
636 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100637 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200638}
639
640static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100641yprc_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 +0200642{
Radek Krejci857189e2020-09-01 13:26:36 +0200643 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200644 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200645
Radek Krejci334ccc72019-06-12 13:49:29 +0200646 if (!range) {
647 return;
648 }
649
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100650 ypr_open(pctx->out, flag);
651 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200652 LY_ARRAY_FOR(range->parts, u) {
653 if (u > 0) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100654 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200655 }
656 if (range->parts[u].max_64 == range->parts[u].min_64) {
657 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100658 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200659 } else { /* signed values */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100660 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200661 }
662 } else {
663 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100664 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200665 } else { /* signed values */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100666 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200667 }
668 }
669 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100670 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200671
672 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100673 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200674 if (range->emsg) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100675 ypr_open(pctx->out, &inner_flag);
676 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200677 }
678 if (range->eapptag) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100679 ypr_open(pctx->out, &inner_flag);
680 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200681 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100682 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
683 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200684
685 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100686 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200687}
688
689static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100690yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200691{
Radek Krejci857189e2020-09-01 13:26:36 +0200692 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200693
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100694 ypr_open(pctx->out, flag);
695 ly_print_(pctx->out, "%*spattern \"", INDENT);
696 ypr_encode(pctx->out, pattern->expr, -1);
697 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200698
699 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100700 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200701 if (pattern->inverted) {
702 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100703 ypr_open(pctx->out, &inner_flag);
704 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200705 }
706 if (pattern->emsg) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100707 ypr_open(pctx->out, &inner_flag);
708 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200709 }
710 if (pattern->eapptag) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100711 ypr_open(pctx->out, &inner_flag);
712 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200713 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100714 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
715 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200716
717 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100718 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200719}
720
721static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100722yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200723{
Radek Krejci857189e2020-09-01 13:26:36 +0200724 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200725
726 if (!when) {
727 return;
728 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100729 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200730
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100731 ly_print_(pctx->out, "%*swhen \"", INDENT);
732 ypr_encode(pctx->out, when->cond, -1);
733 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200734
735 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100736 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
737 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
738 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200739 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100740 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200741}
742
743static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100744yprc_when(struct lys_ypr_ctx *pctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200745{
Radek Krejci857189e2020-09-01 13:26:36 +0200746 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200747
748 if (!when) {
749 return;
750 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100751 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200752
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100753 ly_print_(pctx->out, "%*swhen \"", INDENT);
754 ypr_encode(pctx->out, when->cond->expr, -1);
755 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200756
757 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100758 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
759 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
760 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200761 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100762 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200763}
764
765static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100766yprp_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 +0200767{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200768 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200769 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200770
771 LY_ARRAY_FOR(items, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100772 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200773 if (type == LY_TYPE_BITS) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100774 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200775 } else { /* LY_TYPE_ENUM */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100776 ly_print_(pctx->out, "%*senum \"", INDENT);
777 ypr_encode(pctx->out, items[u].name, -1);
778 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200779 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200780 inner_flag = 0;
781 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100782 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag, 0);
783 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200784 if (items[u].flags & LYS_SET_VALUE) {
785 if (type == LY_TYPE_BITS) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100786 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200787 } else { /* LY_TYPE_ENUM */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100788 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200789 }
790 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100791 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
792 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
793 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200794 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100795 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796 }
797}
798
799static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100800yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200801{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200802 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200803 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200804
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100805 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200806 LEVEL++;
807
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100808 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200809
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100810 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
811 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200812 LY_ARRAY_FOR(type->patterns, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100813 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200814 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100815 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
816 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200817
818 if (type->path) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100819 ypr_open(pctx->out, &flag);
820 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200821 }
822 if (type->flags & LYS_SET_REQINST) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100823 ypr_open(pctx->out, &flag);
824 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200825 }
826 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100827 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200828 }
829 LY_ARRAY_FOR(type->bases, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100830 ypr_open(pctx->out, &flag);
831 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200832 }
833 LY_ARRAY_FOR(type->types, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100834 ypr_open(pctx->out, &flag);
835 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200836 }
837
838 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100839 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840}
841
842static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100843yprc_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 +0200844 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200845{
Radek Krejci857189e2020-09-01 13:26:36 +0200846 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200847 const char *str;
848
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100849 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
850 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200851 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200852 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200853 }
854}
855
856static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100857yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200858{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200859 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200860 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200861
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100862 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200863 LEVEL++;
864
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100865 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200866
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200867 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200868 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200869 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100870 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200871 break;
872 }
873 case LY_TYPE_UINT8:
874 case LY_TYPE_UINT16:
875 case LY_TYPE_UINT32:
876 case LY_TYPE_UINT64:
877 case LY_TYPE_INT8:
878 case LY_TYPE_INT16:
879 case LY_TYPE_INT32:
880 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200881 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100882 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200883 break;
884 }
885 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200886 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100887 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200888 LY_ARRAY_FOR(str->patterns, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100889 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200890 }
891 break;
892 }
893 case LY_TYPE_BITS:
894 case LY_TYPE_ENUM: {
895 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200896 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200897 LY_ARRAY_FOR(bits->bits, u) {
898 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200899 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200900
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100901 ypr_open(pctx->out, &flag);
902 ly_print_(pctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
903 ypr_encode(pctx->out, item->name, -1);
904 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200905 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200906 if (type->basetype == LY_TYPE_BITS) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100907 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
908 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200909 } else { /* LY_TYPE_ENUM */
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100910 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
911 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200912 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100913 ypr_status(pctx, item->flags, item->exts, &inner_flag);
914 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
915 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200916 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100917 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200918 }
919 break;
920 }
921 case LY_TYPE_BOOL:
922 case LY_TYPE_EMPTY:
923 /* nothing to do */
924 break;
925 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200926 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100927 ypr_open(pctx->out, &flag);
928 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
929 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200930 break;
931 }
932 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200933 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200934 LY_ARRAY_FOR(ident->bases, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100935 ypr_open(pctx->out, &flag);
936 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200937 }
938 break;
939 }
940 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200941 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100942 ypr_open(pctx->out, &flag);
943 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200944 break;
945 }
946 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200947 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100948 ypr_open(pctx->out, &flag);
949 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
950 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
951 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200952 break;
953 }
954 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200955 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200956 LY_ARRAY_FOR(un->types, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100957 ypr_open(pctx->out, &flag);
958 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200959 }
960 break;
961 }
962 default:
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100963 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200964 }
965
966 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100967 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200968}
969
970static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100971yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200972{
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100973 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200974 LEVEL++;
975
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100976 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200977
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100978 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200979
980 if (tpdf->units) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100981 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200982 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200983 if (tpdf->dflt.str) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100984 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200985 }
986
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100987 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
988 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
989 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200990
991 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100992 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200993}
994
Michal Vaskoc08b9d22022-02-10 15:48:39 +0100995static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
996static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
997static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
998static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200999
1000static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001001yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001002{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001003 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001004 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001005 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001006 struct lysp_node_action *action;
1007 struct lysp_node_notif *notif;
1008 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001009
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001010 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001011 LEVEL++;
1012
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001013 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
1014 ypr_status(pctx, grp->flags, grp->exts, &flag);
1015 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1016 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001017
1018 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001019 ypr_open(pctx->out, &flag);
1020 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001021 }
1022
Radek Krejci2a9fc652021-01-22 17:44:34 +01001023 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001024 ypr_open(pctx->out, &flag);
1025 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026 }
1027
Radek Krejci01180ac2021-01-27 08:48:22 +01001028 LY_LIST_FOR(grp->child, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001029 ypr_open(pctx->out, &flag);
1030 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001031 }
1032
Radek Krejci2a9fc652021-01-22 17:44:34 +01001033 LY_LIST_FOR(grp->actions, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001034 ypr_open(pctx->out, &flag);
1035 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001036 }
1037
1038 LY_LIST_FOR(grp->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001039 ypr_open(pctx->out, &flag);
1040 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001041 }
1042
1043 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001044 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001045}
1046
1047static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001048yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001050 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001051 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001052 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001053
Radek Krejci01180ac2021-01-27 08:48:22 +01001054 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001055 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001056 return;
1057 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001058 ypr_open(pctx->out, flag);
1059 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001060
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001061 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062 LEVEL++;
1063
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001064 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001065 LY_ARRAY_FOR(inout->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001066 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067 }
1068 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001069 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001071 LY_LIST_FOR(inout->groupings, grp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001072 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073 }
1074
Radek Krejci01180ac2021-01-27 08:48:22 +01001075 LY_LIST_FOR(inout->child, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001076 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001077 }
1078
1079 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001080 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081}
1082
1083static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001084yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001085{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001086 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001087 struct lysc_node *data;
1088
Radek Krejci01180ac2021-01-27 08:48:22 +01001089 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001090 /* input/output is empty */
1091 return;
1092 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001093 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001094
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001095 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001096 LEVEL++;
1097
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001098 yprc_extension_instances(pctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001099 LY_ARRAY_FOR(inout->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001100 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001101 }
1102
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001103 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001104 LY_LIST_FOR(inout->child, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001105 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001106 }
Radek Krejci693262f2019-04-29 15:23:20 +02001107 }
1108
1109 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001110 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001111}
1112
1113static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001114yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001115{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001116 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001117 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001118 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001119 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001120
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001121 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001122
1123 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001124 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
1125 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001126
1127 LY_ARRAY_FOR(notif->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001128 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001129 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001130 ypr_status(pctx, notif->flags, notif->exts, &flag);
1131 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1132 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001133
1134 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001135 ypr_open(pctx->out, &flag);
1136 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001137 }
1138
Radek Krejci2a9fc652021-01-22 17:44:34 +01001139 LY_LIST_FOR(notif->groupings, grp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001140 ypr_open(pctx->out, &flag);
1141 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001142 }
1143
Radek Krejci01180ac2021-01-27 08:48:22 +01001144 LY_LIST_FOR(notif->child, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001145 ypr_open(pctx->out, &flag);
1146 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147 }
1148
1149 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001150 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001151}
1152
1153static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001154yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001155{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001156 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001157 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001158 struct lysc_node *data;
1159
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001160 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001161
1162 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001163 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001164
1165 LY_ARRAY_FOR(notif->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001166 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001167 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001168 ypr_status(pctx, notif->flags, notif->exts, &flag);
1169 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1170 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001171
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001172 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001173 LY_LIST_FOR(notif->child, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001174 ypr_open(pctx->out, &flag);
1175 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001176 }
Radek Krejci693262f2019-04-29 15:23:20 +02001177 }
1178
1179 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001180 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001181}
1182
1183static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001184yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001185{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001186 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001187 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001188 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001189
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001190 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001191
1192 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001193 yprp_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
1194 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1195 ypr_status(pctx, action->flags, action->exts, &flag);
1196 ypr_description(pctx, action->dsc, action->exts, &flag);
1197 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001198
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001199 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001200
Radek Krejcid3ca0632019-04-16 16:54:54 +02001201 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001202 ypr_open(pctx->out, &flag);
1203 YPR_EXTRA_LINE_PRINT(pctx);
1204 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001205 }
1206
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001207 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001208
Radek Krejci2a9fc652021-01-22 17:44:34 +01001209 LY_LIST_FOR(action->groupings, grp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001210 ypr_open(pctx->out, &flag);
1211 YPR_EXTRA_LINE_PRINT(pctx);
1212 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001213 }
1214
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001215 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001216
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001217 yprp_inout(pctx, &action->input, &flag);
1218 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001219
1220 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001221 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001222}
1223
1224static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001225yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001226{
Radek Krejci857189e2020-09-01 13:26:36 +02001227 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001228
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001229 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001230
1231 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001232 yprc_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
1233 ypr_status(pctx, action->flags, action->exts, &flag);
1234 ypr_description(pctx, action->dsc, action->exts, &flag);
1235 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001236
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001237 yprc_inout(pctx, &action->input, &flag);
1238 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001239
1240 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001241 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001242}
1243
1244static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001245yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001246{
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001247 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248 LEVEL++;
1249
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001250 yprp_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
1251 yprp_when(pctx, lysp_node_when(node), flag);
1252 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001253}
1254
1255static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001256yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001257{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001258 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001259 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001260
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001261 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001262 LEVEL++;
1263
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001264 yprc_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001265
1266 when = lysc_node_when(node);
1267 LY_ARRAY_FOR(when, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001268 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001269 }
Radek Krejci693262f2019-04-29 15:23:20 +02001270}
1271
1272/* macr oto unify the code */
1273#define YPR_NODE_COMMON2 \
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001274 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001275 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001276 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001277 } \
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001278 ypr_status(pctx, node->flags, node->exts, flag); \
1279 ypr_description(pctx, node->dsc, node->exts, flag); \
1280 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001281
1282static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001283yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001284{
1285 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286}
1287
1288static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001289yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001290{
1291 YPR_NODE_COMMON2;
1292}
1293
1294#undef YPR_NODE_COMMON2
1295
1296static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001297yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001298{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001299 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001300 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001301 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001302 struct lysp_node_action *action;
1303 struct lysp_node_notif *notif;
1304 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001305 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1306
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001307 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001308
1309 LY_ARRAY_FOR(cont->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001310 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001311 }
1312 if (cont->presence) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001313 ypr_open(pctx->out, &flag);
1314 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001315 }
1316
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001317 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001318
1319 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001320 ypr_open(pctx->out, &flag);
1321 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001322 }
1323
Radek Krejci2a9fc652021-01-22 17:44:34 +01001324 LY_LIST_FOR(cont->groupings, grp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001325 ypr_open(pctx->out, &flag);
1326 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001327 }
1328
1329 LY_LIST_FOR(cont->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001330 ypr_open(pctx->out, &flag);
1331 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001332 }
1333
Radek Krejci2a9fc652021-01-22 17:44:34 +01001334 LY_LIST_FOR(cont->actions, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001335 ypr_open(pctx->out, &flag);
1336 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001337 }
1338
Radek Krejci2a9fc652021-01-22 17:44:34 +01001339 LY_LIST_FOR(cont->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001340 ypr_open(pctx->out, &flag);
1341 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001342 }
1343
1344 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001345 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001346}
1347
1348static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001349yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001350{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001351 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001352 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001353 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001354 struct lysc_node_action *action;
1355 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001356 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1357
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001358 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001359
1360 LY_ARRAY_FOR(cont->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001361 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001362 }
1363 if (cont->flags & LYS_PRESENCE) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001364 ypr_open(pctx->out, &flag);
1365 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001366 }
1367
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001368 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001369
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001370 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001371 LY_LIST_FOR(cont->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001372 ypr_open(pctx->out, &flag);
1373 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001374 }
Radek Krejci693262f2019-04-29 15:23:20 +02001375
Radek Krejci2a9fc652021-01-22 17:44:34 +01001376 LY_LIST_FOR(cont->actions, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001377 ypr_open(pctx->out, &flag);
1378 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001379 }
Radek Krejci693262f2019-04-29 15:23:20 +02001380
Radek Krejci2a9fc652021-01-22 17:44:34 +01001381 LY_LIST_FOR(cont->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001382 ypr_open(pctx->out, &flag);
1383 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001384 }
Radek Krejci693262f2019-04-29 15:23:20 +02001385 }
1386
1387 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001388 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001389}
1390
1391static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001392yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001393{
Radek Krejci857189e2020-09-01 13:26:36 +02001394 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001395 struct lysp_node *child;
1396 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1397
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001398 yprp_node_common1(pctx, node, &flag);
1399 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001400
1401 LY_LIST_FOR(cas->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001402 ypr_open(pctx->out, &flag);
1403 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001404 }
1405
1406 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001407 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001408}
1409
1410static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001411yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001412{
Radek Krejci857189e2020-09-01 13:26:36 +02001413 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001414 struct lysc_node *child;
1415
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001416 yprc_node_common1(pctx, &cs->node, &flag);
1417 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001418
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001419 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001420 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001421 ypr_open(pctx->out, &flag);
1422 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001423 }
Radek Krejci693262f2019-04-29 15:23:20 +02001424 }
1425
1426 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001427 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001428}
1429
1430static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001431yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001432{
Radek Krejci857189e2020-09-01 13:26:36 +02001433 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001434 struct lysp_node *child;
1435 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1436
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001437 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001438
Michal Vasko7f45cf22020-10-01 12:49:44 +02001439 if (choice->dflt.str) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001440 ypr_open(pctx->out, &flag);
1441 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001442 }
1443
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001444 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001445
1446 LY_LIST_FOR(choice->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001447 ypr_open(pctx->out, &flag);
1448 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001449 }
1450
1451 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001452 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001453}
1454
1455static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001456yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001457{
Radek Krejci857189e2020-09-01 13:26:36 +02001458 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001459 struct lysc_node_case *cs;
1460 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1461
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001462 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001463
1464 if (choice->dflt) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001465 ypr_open(pctx->out, &flag);
1466 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001467 }
1468
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001469 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001470
Michal Vasko22df3f02020-08-24 13:29:22 +02001471 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001472 ypr_open(pctx->out, &flag);
1473 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001474 }
1475
1476 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001477 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001478}
1479
1480static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001481yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001482{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001483 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001484 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1485
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001486 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001487
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001488 yprp_type(pctx, &leaf->type);
1489 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001490 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001491 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001492 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001493 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001494
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001495 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001496
1497 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001498 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001499}
1500
1501static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001502yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001503{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001504 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001505 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1506
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001507 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001508
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001509 yprc_type(pctx, leaf->type);
1510 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001511 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001512 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001513 }
Radek Krejcia1911222019-07-22 17:24:50 +02001514
1515 if (leaf->dflt) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001516 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001517 }
Radek Krejci693262f2019-04-29 15:23:20 +02001518
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001519 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001520
1521 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001522 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001523}
1524
1525static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001526yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001527{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001528 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001529 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1530
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001531 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001532
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001533 yprp_type(pctx, &llist->type);
1534 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001535 LY_ARRAY_FOR(llist->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001536 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001537 }
1538 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001539 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001540 }
1541
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001542 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001543
1544 if (llist->flags & LYS_SET_MIN) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001545 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001546 }
1547 if (llist->flags & LYS_SET_MAX) {
1548 if (llist->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001549 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001550 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001551 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001552 }
1553 }
1554
1555 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001556 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001557 }
1558
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001559 ypr_status(pctx, node->flags, node->exts, NULL);
1560 ypr_description(pctx, node->dsc, node->exts, NULL);
1561 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562
1563 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001564 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565}
1566
1567static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001568yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001569{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001570 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001571 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1572
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001573 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001574
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001575 yprc_type(pctx, llist->type);
1576 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001577 LY_ARRAY_FOR(llist->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001578 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001579 }
1580 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001581 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001582 }
1583
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001584 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001585
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001586 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001587 if (llist->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001588 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001589 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001590 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001591 }
1592
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001593 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001594
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001595 ypr_status(pctx, node->flags, node->exts, NULL);
1596 ypr_description(pctx, node->dsc, node->exts, NULL);
1597 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001598
1599 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001600 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001601}
1602
1603static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001604yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001605{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001606 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001607 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001608 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001609 struct lysp_node_action *action;
1610 struct lysp_node_notif *notif;
1611 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001612 struct lysp_node_list *list = (struct lysp_node_list *)node;
1613
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001614 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001615
1616 LY_ARRAY_FOR(list->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001617 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001618 }
1619 if (list->key) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001620 ypr_open(pctx->out, &flag);
1621 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001622 }
1623 LY_ARRAY_FOR(list->uniques, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001624 ypr_open(pctx->out, &flag);
1625 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001626 }
1627
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001628 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001629
1630 if (list->flags & LYS_SET_MIN) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001631 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001632 }
1633 if (list->flags & LYS_SET_MAX) {
1634 if (list->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001635 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001636 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001637 ypr_open(pctx->out, &flag);
1638 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001639 }
1640 }
1641
1642 if (list->flags & LYS_ORDBY_MASK) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001643 ypr_open(pctx->out, &flag);
1644 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001645 }
1646
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001647 ypr_status(pctx, node->flags, node->exts, &flag);
1648 ypr_description(pctx, node->dsc, node->exts, &flag);
1649 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001650
1651 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001652 ypr_open(pctx->out, &flag);
1653 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654 }
1655
Radek Krejci2a9fc652021-01-22 17:44:34 +01001656 LY_LIST_FOR(list->groupings, grp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001657 ypr_open(pctx->out, &flag);
1658 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660
1661 LY_LIST_FOR(list->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001662 ypr_open(pctx->out, &flag);
1663 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001664 }
1665
Radek Krejci2a9fc652021-01-22 17:44:34 +01001666 LY_LIST_FOR(list->actions, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001667 ypr_open(pctx->out, &flag);
1668 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001669 }
1670
Radek Krejci2a9fc652021-01-22 17:44:34 +01001671 LY_LIST_FOR(list->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001672 ypr_open(pctx->out, &flag);
1673 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001674 }
1675
1676 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001677 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001678}
1679
1680static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001681yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001682{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001683 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001684 struct lysc_node_list *list = (struct lysc_node_list *)node;
1685
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001686 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001687
1688 LY_ARRAY_FOR(list->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001689 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001690 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001691 if (!(list->flags & LYS_KEYLESS)) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001692 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001693 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001694 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001695 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001696 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001697 }
1698 LY_ARRAY_FOR(list->uniques, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001699 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001700 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001701 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001702 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001703 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001704 }
1705
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001706 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001707
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001708 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001709 if (list->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001710 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001711 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001712 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001713 }
1714
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001715 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001716
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001717 ypr_status(pctx, node->flags, node->exts, NULL);
1718 ypr_description(pctx, node->dsc, node->exts, NULL);
1719 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001720
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001721 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001722 struct lysc_node *child;
1723 struct lysc_node_action *action;
1724 struct lysc_node_notif *notif;
1725
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001726 LY_LIST_FOR(list->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001727 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001728 }
Radek Krejci693262f2019-04-29 15:23:20 +02001729
Radek Krejci2a9fc652021-01-22 17:44:34 +01001730 LY_LIST_FOR(list->actions, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001731 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001732 }
Radek Krejci693262f2019-04-29 15:23:20 +02001733
Radek Krejci2a9fc652021-01-22 17:44:34 +01001734 LY_LIST_FOR(list->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001735 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001736 }
Radek Krejci693262f2019-04-29 15:23:20 +02001737 }
1738
1739 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001740 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001741}
1742
1743static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001744yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001745{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001746 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001747 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001748
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001749 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001750 LEVEL++;
1751
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001752 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
1753 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001754
1755 LY_ARRAY_FOR(refine->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001756 ypr_open(pctx->out, &flag);
1757 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001758 }
1759
1760 if (refine->presence) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001761 ypr_open(pctx->out, &flag);
1762 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001763 }
1764
1765 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001766 ypr_open(pctx->out, &flag);
1767 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001768 }
1769
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001770 ypr_config(pctx, refine->flags, refine->exts, &flag);
1771 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001772
1773 if (refine->flags & LYS_SET_MIN) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001774 ypr_open(pctx->out, &flag);
1775 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001776 }
1777 if (refine->flags & LYS_SET_MAX) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001778 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779 if (refine->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001780 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001782 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783 }
1784 }
1785
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001786 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1787 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001788
1789 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001790 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791}
1792
1793static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001794yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001795{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001796 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001797 struct lysp_node_action *action;
1798 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001800 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801 LEVEL++;
1802
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001803 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
1804 yprp_when(pctx, aug->when, NULL);
1805 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1806 ypr_status(pctx, aug->flags, aug->exts, NULL);
1807 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1808 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809
1810 LY_LIST_FOR(aug->child, child) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001811 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812 }
1813
Radek Krejci2a9fc652021-01-22 17:44:34 +01001814 LY_LIST_FOR(aug->actions, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001815 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816 }
1817
Radek Krejci2a9fc652021-01-22 17:44:34 +01001818 LY_LIST_FOR(aug->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001819 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820 }
1821
1822 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001823 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001824}
1825
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001827yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001829 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001830 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001831 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001832 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001834 yprp_node_common1(pctx, node, &flag);
1835 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001836
1837 LY_ARRAY_FOR(uses->refines, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001838 ypr_open(pctx->out, &flag);
1839 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001840 }
1841
Radek Krejci2a9fc652021-01-22 17:44:34 +01001842 LY_LIST_FOR(uses->augments, aug) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001843 ypr_open(pctx->out, &flag);
1844 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845 }
1846
1847 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001848 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849}
1850
1851static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001852yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001854 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001855 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1857
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001858 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859
1860 LY_ARRAY_FOR(any->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001861 ypr_open(pctx->out, &flag);
1862 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001863 }
1864
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001865 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866
1867 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001868 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001869}
1870
1871static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001872yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001874 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001875 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001876 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001878 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001879
Radek Krejci693262f2019-04-29 15:23:20 +02001880 LY_ARRAY_FOR(any->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001881 ypr_open(pctx->out, &flag);
1882 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001883 }
1884
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001885 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001886
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001888 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889}
1890
1891static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001892yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893{
1894 switch (node->nodetype) {
1895 case LYS_CONTAINER:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001896 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897 break;
1898 case LYS_CHOICE:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001899 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900 break;
1901 case LYS_LEAF:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001902 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903 break;
1904 case LYS_LEAFLIST:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001905 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906 break;
1907 case LYS_LIST:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001908 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001909 break;
1910 case LYS_USES:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001911 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912 break;
1913 case LYS_ANYXML:
1914 case LYS_ANYDATA:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001915 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 break;
1917 case LYS_CASE:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001918 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001919 break;
1920 default:
1921 break;
1922 }
1923}
1924
1925static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001926yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001927{
1928 switch (node->nodetype) {
1929 case LYS_CONTAINER:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001930 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001931 break;
1932 case LYS_CHOICE:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001933 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001934 break;
1935 case LYS_LEAF:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001936 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001937 break;
1938 case LYS_LEAFLIST:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001939 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001940 break;
1941 case LYS_LIST:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001942 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001943 break;
1944 case LYS_ANYXML:
1945 case LYS_ANYDATA:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001946 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001947 break;
1948 default:
1949 break;
1950 }
1951}
1952
1953static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001954yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001955{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001956 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001957 struct lysp_deviate_add *add;
1958 struct lysp_deviate_rpl *rpl;
1959 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001960 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001961
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001962 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963 LEVEL++;
1964
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001965 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
1966 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1967 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001968
fredgan2b11ddb2019-10-21 11:03:39 +08001969 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001970 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001971 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1972 if (elem->exts) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001973 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001974 LEVEL++;
1975
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001976 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001977 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001978 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 continue;
1980 }
fredgan2b11ddb2019-10-21 11:03:39 +08001981 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001982 add = (struct lysp_deviate_add *)elem;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001983 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001984 LEVEL++;
1985
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001986 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL, 0);
1987 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001988 LY_ARRAY_FOR(add->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001989 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001991 LY_ARRAY_FOR(add->uniques, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001992 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001993 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001994 LY_ARRAY_FOR(add->dflts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001995 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001996 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01001997 ypr_config(pctx, add->flags, add->exts, NULL);
1998 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001999 if (add->flags & LYS_SET_MIN) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002000 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 }
2002 if (add->flags & LYS_SET_MAX) {
2003 if (add->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002004 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002006 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 }
2008 }
fredgan2b11ddb2019-10-21 11:03:39 +08002009 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002010 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002011 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 LEVEL++;
2013
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002014 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002015 if (rpl->type) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002016 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002018 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2019 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2020 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2021 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 if (rpl->flags & LYS_SET_MIN) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002023 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002024 }
2025 if (rpl->flags & LYS_SET_MAX) {
2026 if (rpl->max) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002027 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002029 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 }
2031 }
fredgan2b11ddb2019-10-21 11:03:39 +08002032 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002033 del = (struct lysp_deviate_del *)elem;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002034 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 LEVEL++;
2036
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002037 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
2038 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002039 LY_ARRAY_FOR(del->musts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002040 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002042 LY_ARRAY_FOR(del->uniques, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002043 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002045 LY_ARRAY_FOR(del->dflts, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002046 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047 }
2048 }
2049
2050 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002051 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002052 }
2053
2054 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002055 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002056}
2057
Michal Vasko7c8439f2020-08-05 13:25:19 +02002058static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002059yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002060{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002061 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002064 if (modp->imports[u].flags & LYS_INTERNAL) {
2065 continue;
2066 }
2067
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002068 YPR_EXTRA_LINE_PRINT(pctx);
2069 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002071 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
2072 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002073 if (modp->imports[u].rev[0]) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002074 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002075 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002076 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2077 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002078 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002079 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002080 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002081 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002082
Radek Krejcid3ca0632019-04-16 16:54:54 +02002083 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002084 if (modp->includes[u].injected) {
2085 /* do not print the includes injected from submodules */
2086 continue;
2087 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002088 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002090 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002092 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002093 if (modp->includes[u].rev[0]) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002094 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002095 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002096 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2097 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002098 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002099 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002100 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002101 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 }
2103 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002104 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002105}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106
Michal Vasko7c8439f2020-08-05 13:25:19 +02002107static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002108yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002109{
2110 LY_ARRAY_COUNT_TYPE u;
2111 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002112 struct lysp_node_action *action;
2113 struct lysp_node_notif *notif;
2114 struct lysp_node_grp *grp;
2115 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002116
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002118 YPR_EXTRA_LINE_PRINT(pctx);
2119 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002120 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002121
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002122 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002123
Radek Krejcid3ca0632019-04-16 16:54:54 +02002124 if (modp->exts) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002125 YPR_EXTRA_LINE_PRINT(pctx);
2126 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127 }
2128
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002129 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002130
Radek Krejcid3ca0632019-04-16 16:54:54 +02002131 LY_ARRAY_FOR(modp->features, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002132 YPR_EXTRA_LINE_PRINT(pctx);
2133 yprp_feature(pctx, &modp->features[u]);
2134 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135 }
2136
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002137 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002138
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139 LY_ARRAY_FOR(modp->identities, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002140 YPR_EXTRA_LINE_PRINT(pctx);
2141 yprp_identity(pctx, &modp->identities[u]);
2142 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002143 }
2144
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002145 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002146
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002148 YPR_EXTRA_LINE_PRINT(pctx);
2149 yprp_typedef(pctx, &modp->typedefs[u]);
2150 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002151 }
2152
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002153 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002154
Radek Krejci2a9fc652021-01-22 17:44:34 +01002155 LY_LIST_FOR(modp->groupings, grp) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002156 YPR_EXTRA_LINE_PRINT(pctx);
2157 yprp_grouping(pctx, grp);
2158 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002159 }
2160
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002161 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002162
Radek Krejcid3ca0632019-04-16 16:54:54 +02002163 LY_LIST_FOR(modp->data, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002164 YPR_EXTRA_LINE_PRINT(pctx);
2165 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002166 }
2167
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002168 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002169
Radek Krejci2a9fc652021-01-22 17:44:34 +01002170 LY_LIST_FOR(modp->augments, aug) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002171 YPR_EXTRA_LINE_PRINT(pctx);
2172 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002173 }
2174
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002175 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002176
Radek Krejci2a9fc652021-01-22 17:44:34 +01002177 LY_LIST_FOR(modp->rpcs, action) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002178 YPR_EXTRA_LINE_PRINT(pctx);
2179 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 }
2181
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002182 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002183
Radek Krejci2a9fc652021-01-22 17:44:34 +01002184 LY_LIST_FOR(modp->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002185 YPR_EXTRA_LINE_PRINT(pctx);
2186 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002187 }
2188
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002190
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002192 YPR_EXTRA_LINE_PRINT(pctx);
2193 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002194 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002195
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002196 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002197}
2198
2199LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002200yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002201{
2202 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002203 const struct lys_module *module = modp->mod;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002204 struct lys_ypr_ctx pctx_ = {
2205 .out = out,
2206 .level = 0,
2207 .module = module,
2208 .schema = LYS_YPR_PARSED,
2209 .options = options
2210 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002211
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002212 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002213 LEVEL++;
2214
2215 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002216 if (modp->version) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002217 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 +02002218 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002219 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2220 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002221
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002222 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002223
Michal Vasko7c8439f2020-08-05 13:25:19 +02002224 /* linkage-stmts (import/include) */
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002225 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002226
2227 /* meta-stmts */
2228 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002229 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002230 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002231 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2232 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2233 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2234 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002235
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002236 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002237
Michal Vasko7c8439f2020-08-05 13:25:19 +02002238 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002239 LY_ARRAY_FOR(modp->revs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002240 YPR_EXTRA_LINE_PRINT(pctx);
2241 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002242 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002243
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002244 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002245
Michal Vasko7c8439f2020-08-05 13:25:19 +02002246 /* body-stmts */
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002247 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002248
2249 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002250 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002251 ly_print_flush(out);
2252
2253 return LY_SUCCESS;
2254}
2255
2256static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002257yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002258{
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002259 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002260 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002261 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2262 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002263 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002264 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002265}
2266
2267LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002268yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002269{
2270 LY_ARRAY_COUNT_TYPE u;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002271 struct lys_ypr_ctx pctx_ = {
Radek Krejci07a55962021-03-02 20:16:43 +01002272 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2273 .options = options
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002274 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002275
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002276 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002277 LEVEL++;
2278
2279 /* submodule-header-stmts */
2280 if (submodp->version) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002281 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 +02002282 }
2283
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002284 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002285
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002286 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002287
Michal Vasko7c8439f2020-08-05 13:25:19 +02002288 /* linkage-stmts (import/include) */
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002289 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002290
2291 /* meta-stmts */
2292 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002293 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002294 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002295 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2296 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2297 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2298 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002299
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002300 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002301
Michal Vasko7c8439f2020-08-05 13:25:19 +02002302 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002303 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002304 YPR_EXTRA_LINE_PRINT(pctx);
2305 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002306 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002307
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002308 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002309
Michal Vasko7c8439f2020-08-05 13:25:19 +02002310 /* body-stmts */
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002311 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002312
2313 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002314 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002315 ly_print_flush(out);
2316
2317 return LY_SUCCESS;
2318}
2319
2320LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002321yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002322{
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002323 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002324
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002325 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002326
2327 ly_print_flush(out);
2328 return LY_SUCCESS;
2329}
2330
2331LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002332yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002333{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002334 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002335 struct lysc_module *modc = module->compiled;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002336 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = module, .options = options}, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002337
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002338 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002339 LEVEL++;
2340
Radek Krejci693262f2019-04-29 15:23:20 +02002341 /* module-header-stmts */
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002342 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2343 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002344
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002345 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002346
Michal Vasko7c8439f2020-08-05 13:25:19 +02002347 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002348
2349 /* meta-stmts */
2350 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002351 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002352 }
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002353 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2354 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2355 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2356 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002357
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002358 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002359
Radek Krejci693262f2019-04-29 15:23:20 +02002360 /* revision-stmts */
2361 if (module->revision) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002362 YPR_EXTRA_LINE_PRINT(pctx);
2363 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2364 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002365 }
2366
2367 /* body-stmts */
2368 if (modc->exts) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002369 YPR_EXTRA_LINE_PRINT(pctx);
2370 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
2371 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002372 }
2373
Radek Krejci80d281e2020-09-14 17:42:54 +02002374 LY_ARRAY_FOR(module->identities, u) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002375 YPR_EXTRA_LINE_PRINT(pctx);
2376 yprc_identity(pctx, &module->identities[u]);
2377 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002378 }
2379
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002380 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002381 struct lysc_node *data;
2382 struct lysc_node_action *rpc;
2383 struct lysc_node_notif *notif;
2384
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002385 LY_LIST_FOR(modc->data, data) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002386 YPR_EXTRA_LINE_PRINT(pctx);
2387 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002388 }
Radek Krejci693262f2019-04-29 15:23:20 +02002389
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002390 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002391
Radek Krejci2a9fc652021-01-22 17:44:34 +01002392 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002393 YPR_EXTRA_LINE_PRINT(pctx);
2394 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002395 }
Radek Krejci693262f2019-04-29 15:23:20 +02002396
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002397 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002398
Radek Krejci2a9fc652021-01-22 17:44:34 +01002399 LY_LIST_FOR(modc->notifs, notif) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002400 YPR_EXTRA_LINE_PRINT(pctx);
2401 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002402 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002403
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002404 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002405 }
2406
2407 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002408 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002409 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002410
2411 return LY_SUCCESS;
2412}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002413
2414/**
2415 * @param[in] count Number of extensions to print, 0 to print them all.
2416 */
2417static void
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002418yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002419 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2420{
2421 LY_ARRAY_COUNT_TYPE u;
2422
2423 if (!count && ext) {
2424 count = LY_ARRAY_COUNT(ext);
2425 }
2426 LY_ARRAY_FOR(ext, u) {
2427 ly_bool inner_flag = 0;
2428
2429 if (!count) {
2430 break;
2431 }
2432
2433 count--;
Radek Krejciab430862021-03-02 20:13:40 +01002434 if ((ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002435 continue;
2436 }
2437
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002438 ypr_open(pctx->out, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002439 if (ext[u].argument) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002440 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2441 ypr_encode(pctx->out, ext[u].argument, -1);
2442 ly_print_(pctx->out, "\"");
Radek Krejciadcf63d2021-02-09 10:21:18 +01002443 } else {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002444 ly_print_(pctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002445 }
2446
2447 LEVEL++;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002448 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002449
Radek Krejci4a4d1e02021-04-09 14:04:40 +02002450 if (ext[u].def->plugin && ext[u].def->plugin->sprinter) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002451 ext[u].def->plugin->sprinter(&pctx->printer_ctx, &ext[u], &inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002452 }
2453
2454 LEVEL--;
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002455 ypr_close(pctx, inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002456 }
2457}
2458
2459void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002460lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002461{
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002462 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002463 LY_ARRAY_COUNT_TYPE u, v;
2464
2465 LY_ARRAY_FOR(ext->substmts, u) {
2466 switch (ext->substmts[u].stmt) {
2467 case LY_STMT_CHOICE:
2468 case LY_STMT_CONTAINER: {
2469 const struct lysc_node *node;
2470
2471 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002472 ypr_open(pctx->out, flag);
2473 yprc_node(pctx, node);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002474 }
2475 break;
2476 }
2477 case LY_STMT_DESCRIPTION:
2478 case LY_STMT_REFERENCE:
2479 case LY_STMT_UNITS:
2480 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2481 if (*(const char **)ext->substmts[u].storage) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002482 ypr_open(pctx->out, flag);
2483 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002484 }
2485 } else {
2486 const char **strings = *(const char ***)ext->substmts[u].storage;
2487 LY_ARRAY_FOR(strings, v) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002488 ypr_open(pctx->out, flag);
2489 ypr_substmt(pctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002490 }
2491 }
2492 break;
2493 case LY_STMT_IF_FEATURE:
2494 /* nothing to do */
2495 break;
2496 case LY_STMT_STATUS:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002497 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002498 break;
2499 case LY_STMT_TYPE:
2500 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2501 if (*(const struct lysc_type **)ext->substmts[u].storage) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002502 ypr_open(pctx->out, flag);
2503 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002504 }
2505 } else {
2506 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2507 LY_ARRAY_FOR(types, v) {
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002508 ypr_open(pctx->out, flag);
2509 yprc_type(pctx, types[v]);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002510 }
2511 }
2512 break;
2513 /* TODO support other substatements */
2514 default:
Michal Vaskoc08b9d22022-02-10 15:48:39 +01002515 LOGWRN(pctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
Radek Krejciadcf63d2021-02-09 10:21:18 +01002516 ly_stmt2str(ext->substmts[u].stmt));
2517 break;
2518 }
2519 }
2520}