Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer_yang.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 5 | * @brief YANG printer |
| 6 | * |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 16 | #define _GNU_SOURCE |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 17 | |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 18 | #include <assert.h> |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 19 | #include <inttypes.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 24 | #include <sys/types.h> |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 25 | |
Radek Krejci | aa45bda | 2020-07-20 07:43:38 +0200 | [diff] [blame] | 26 | #include "compat.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "log.h" |
Michal Vasko | 8f702ee | 2024-02-20 15:44:24 +0100 | [diff] [blame] | 28 | #include "ly_common.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 29 | #include "out.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 30 | #include "out_internal.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 31 | #include "plugins_exts.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 32 | #include "plugins_types.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 33 | #include "printer_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 34 | #include "printer_schema.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 35 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 36 | #include "tree_data.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 37 | #include "tree_schema.h" |
| 38 | #include "tree_schema_internal.h" |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 39 | #include "xpath.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 40 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 41 | /** |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 42 | * @brief Types of the YANG printers |
| 43 | */ |
| 44 | enum lys_ypr_schema_type { |
| 45 | LYS_YPR_PARSED, /**< YANG printer of the parsed schema */ |
| 46 | LYS_YPR_COMPILED /**< YANG printer of the compiled schema */ |
| 47 | }; |
| 48 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 49 | enum lys_ypr_text_flags { |
| 50 | LYS_YPR_TEXT_SINGLELINE = 0x01, /**< print 'text' on the same line as 'name' */ |
| 51 | LYS_YPR_TEXT_SINGLEQUOTED = 0x02 /**< do not encode 'text' and print it in single quotes */ |
| 52 | }; |
| 53 | |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 54 | #define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */ |
| 55 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 56 | #define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; } |
| 57 | #define YPR_EXTRA_LINE_PRINT(PCTX) \ |
| 58 | if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \ |
| 59 | (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 60 | if (DO_FORMAT) { \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 61 | ly_print_((PCTX)->out, "\n"); \ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 62 | } \ |
| 63 | } |
| 64 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 65 | #define YPR_IS_LYS_SINGLEQUOTED(FLAGS) (((FLAGS) & LYS_SINGLEQUOTED) ? 1 : 0) |
| 66 | |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 67 | /** |
| 68 | * @brief Compiled YANG printer context |
| 69 | * |
| 70 | * Note that the YANG extensions API provides getter to the members for the extension plugins. |
| 71 | */ |
| 72 | struct lys_ypr_ctx { |
| 73 | union { |
| 74 | struct { |
| 75 | struct ly_out *out; /**< output specification */ |
| 76 | uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 77 | uint16_t flags; /**< internal flags for use by printer */ |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 78 | uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */ |
| 79 | const struct lys_module *module; /**< schema to print */ |
| 80 | }; |
| 81 | struct lyspr_ctx printer_ctx; |
| 82 | }; |
| 83 | |
| 84 | /* YANG printer specific members */ |
| 85 | enum lys_ypr_schema_type schema; /**< type of the schema to print */ |
| 86 | }; |
| 87 | |
| 88 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 89 | * @brief Print the given text as content of a double quoted YANG string, |
| 90 | * including encoding characters that have special meanings. The quotation marks |
| 91 | * are not printed. |
| 92 | * |
| 93 | * Follows RFC 7950, section 6.1.3. |
| 94 | * |
| 95 | * @param[in] out Output specification. |
| 96 | * @param[in] text String to be printed. |
Radek Krejci | f56e2a4 | 2019-09-09 14:15:25 +0200 | [diff] [blame] | 97 | * @param[in] len Length of the string from @p text to be printed. In case of -1, |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 98 | * the @p text is printed completely as a NULL-terminated string. |
| 99 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 100 | static void |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 101 | ypr_encode(struct ly_out *out, const char *text, ssize_t len) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 102 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 103 | size_t i, start_len; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 104 | const char *start; |
| 105 | char special = 0; |
| 106 | |
| 107 | if (!len) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | if (len < 0) { |
| 112 | len = strlen(text); |
| 113 | } |
| 114 | |
| 115 | start = text; |
| 116 | start_len = 0; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 117 | for (i = 0; i < (size_t)len; ++i) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 118 | switch (text[i]) { |
| 119 | case '\n': |
| 120 | case '\t': |
| 121 | case '\"': |
| 122 | case '\\': |
| 123 | special = text[i]; |
| 124 | break; |
| 125 | default: |
| 126 | ++start_len; |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | if (special) { |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 131 | ly_write_(out, start, start_len); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 132 | switch (special) { |
| 133 | case '\n': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 134 | ly_write_(out, "\\n", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 135 | break; |
| 136 | case '\t': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 137 | ly_write_(out, "\\t", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 138 | break; |
| 139 | case '\"': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 140 | ly_write_(out, "\\\"", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 141 | break; |
| 142 | case '\\': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 143 | ly_write_(out, "\\\\", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 144 | break; |
| 145 | } |
| 146 | |
| 147 | start += start_len + 1; |
| 148 | start_len = 0; |
| 149 | |
| 150 | special = 0; |
| 151 | } |
| 152 | } |
| 153 | |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 154 | ly_write_(out, start, start_len); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static void |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 158 | ypr_open(struct ly_out *out, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 159 | { |
| 160 | if (flag && !*flag) { |
| 161 | *flag = 1; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 162 | ly_print_(out, " {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 167 | ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 168 | { |
| 169 | if (flag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 170 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 171 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 172 | ly_print_(pctx->out, ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| 176 | static void |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 177 | ypr_text_squote_line(struct lys_ypr_ctx *pctx, const char *text, int text_len) |
| 178 | { |
| 179 | const char *end = text + text_len, *squote; |
| 180 | int squote_len; |
| 181 | |
| 182 | while ((text != end) && (squote = ly_strnchr(text, '\'', end - text))) { |
| 183 | /* before squote */ |
| 184 | ly_print_(pctx->out, "%.*s", (int)(squote - text), text); |
| 185 | |
| 186 | /* specially-encoded squote(s) */ |
| 187 | squote_len = 0; |
| 188 | do { |
| 189 | ++squote_len; |
| 190 | } while ((squote + squote_len != end) && (squote[squote_len] == '\'')); |
| 191 | ly_print_(pctx->out, "' + \"%.*s\" +\n%*s'", squote_len, squote, INDENT); |
| 192 | |
| 193 | /* next iter */ |
| 194 | text = squote + squote_len; |
| 195 | } |
| 196 | |
| 197 | ly_print_(pctx->out, "%.*s", (int)(end - text), text); |
| 198 | } |
| 199 | |
| 200 | static void |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 201 | ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, enum lys_ypr_text_flags flags) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 202 | { |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 203 | const char *nl, *t; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 204 | char quot; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 205 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 206 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
| 207 | quot = '\''; |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 208 | if (strchr(text, '\'')) { |
| 209 | /* need to encode single quotes specially, split to several lines */ |
| 210 | flags &= ~LYS_YPR_TEXT_SINGLELINE; |
| 211 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 212 | } else { |
| 213 | quot = '\"'; |
| 214 | } |
| 215 | |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 216 | /* statement name and quote */ |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 217 | if (flags & LYS_YPR_TEXT_SINGLELINE) { |
| 218 | ly_print_(pctx->out, "%*s%s %c", INDENT, name, quot); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 219 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 220 | ly_print_(pctx->out, "%*s%s\n", INDENT, name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 221 | LEVEL++; |
| 222 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 223 | ly_print_(pctx->out, "%*s%c", INDENT, quot); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 224 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 225 | |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 226 | /* text with newlines */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 227 | t = text; |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 228 | while ((nl = strchr(t, '\n'))) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 229 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 230 | ypr_text_squote_line(pctx, t, nl - t); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 231 | } else { |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 232 | ypr_encode(pctx->out, t, nl - t); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 233 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 234 | ly_print_(pctx->out, "\n"); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 235 | |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 236 | t = nl + 1; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 237 | if (*t != '\n') { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 238 | ly_print_(pctx->out, "%*s ", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 242 | /* finish text and the last quote */ |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 243 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
Michal Vasko | b4b4582 | 2024-04-17 09:51:37 +0200 | [diff] [blame] | 244 | ypr_text_squote_line(pctx, t, strlen(t)); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 245 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 246 | ypr_encode(pctx->out, t, strlen(t)); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 247 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 248 | ly_print_(pctx->out, "%c", quot); |
| 249 | if (!(flags & LYS_YPR_TEXT_SINGLELINE)) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 250 | LEVEL--; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 255 | yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 256 | { |
| 257 | struct lysp_stmt *childstmt; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 258 | uint16_t tflags = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 259 | |
| 260 | if (stmt->arg) { |
| 261 | if (stmt->flags) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 262 | if (stmt->flags & LYS_SINGLEQUOTED) { |
| 263 | tflags |= LYS_YPR_TEXT_SINGLEQUOTED; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 264 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 265 | ypr_text(pctx, stmt->stmt, stmt->arg, tflags); |
| 266 | ly_print_(pctx->out, "%s", stmt->child ? " {\n" : ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 267 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 268 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 269 | } |
| 270 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 271 | ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | if (stmt->child) { |
| 275 | LEVEL++; |
| 276 | LY_LIST_FOR(stmt->child, childstmt) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 277 | yprp_stmt(pctx, childstmt); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 278 | } |
| 279 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 280 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 284 | static void |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 285 | yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 286 | struct lysp_ext_instance *ext, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 287 | { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 288 | struct lysp_stmt *stmt; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 289 | ly_bool child_presence; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 290 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 291 | if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) { |
| 292 | return; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 293 | } |
Radek Krejci | 85ac831 | 2021-03-03 20:21:33 +0100 | [diff] [blame] | 294 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 295 | ypr_open(pctx->out, flag); |
| 296 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 297 | if (ext->def->argname) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 298 | ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 299 | ypr_encode(pctx->out, ext->argument, -1); |
| 300 | ly_print_(pctx->out, "\""); |
| 301 | } else { |
| 302 | ly_print_(pctx->out, "%*s%s", INDENT, ext->name); |
| 303 | } |
| 304 | |
| 305 | child_presence = 0; |
| 306 | LEVEL++; |
| 307 | LY_LIST_FOR(ext->child, stmt) { |
| 308 | if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) { |
Radek Krejci | f56e2a4 | 2019-09-09 14:15:25 +0200 | [diff] [blame] | 309 | continue; |
| 310 | } |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 311 | if (!child_presence) { |
| 312 | ly_print_(pctx->out, " {\n"); |
| 313 | child_presence = 1; |
Radek Krejci | f56e2a4 | 2019-09-09 14:15:25 +0200 | [diff] [blame] | 314 | } |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 315 | yprp_stmt(pctx, stmt); |
| 316 | } |
| 317 | LEVEL--; |
| 318 | if (child_presence) { |
| 319 | ly_print_(pctx->out, "%*s}\n", INDENT); |
| 320 | } else { |
| 321 | ly_print_(pctx->out, ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 325 | static void |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 326 | yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 327 | struct lysp_ext_instance *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 328 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 329 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 330 | |
| 331 | LY_ARRAY_FOR(exts, u) { |
aPiecek | 6cf1d16 | 2023-11-08 16:07:00 +0100 | [diff] [blame] | 332 | if (exts[u].flags & LYS_INTERNAL) { |
| 333 | continue; |
| 334 | } |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 335 | yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag); |
| 336 | } |
| 337 | } |
| 338 | |
aPiecek | 6cf1d16 | 2023-11-08 16:07:00 +0100 | [diff] [blame] | 339 | static ly_bool |
| 340 | yprp_extension_has_printable_instances(struct lysp_ext_instance *exts) |
| 341 | { |
| 342 | LY_ARRAY_COUNT_TYPE u; |
| 343 | |
| 344 | LY_ARRAY_FOR(exts, u) { |
| 345 | if (!(exts[u].flags & LYS_INTERNAL)) { |
| 346 | return 1; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 353 | static void |
| 354 | yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 355 | struct lysc_ext_instance *exts, ly_bool *flag) |
| 356 | { |
| 357 | LY_ARRAY_COUNT_TYPE u; |
| 358 | ly_bool inner_flag; |
| 359 | |
| 360 | LY_ARRAY_FOR(exts, u) { |
| 361 | if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) { |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | ypr_open(pctx->out, flag); |
| 366 | if (exts[u].argument) { |
| 367 | ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name); |
| 368 | ypr_encode(pctx->out, exts[u].argument, -1); |
| 369 | ly_print_(pctx->out, "\""); |
| 370 | } else { |
| 371 | ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name); |
| 372 | } |
| 373 | |
| 374 | LEVEL++; |
| 375 | inner_flag = 0; |
| 376 | yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag); |
| 377 | |
Michal Vasko | 941e056 | 2022-10-18 10:35:00 +0200 | [diff] [blame] | 378 | if (exts[u].def->plugin && exts[u].def->plugin->printer_info) { |
| 379 | exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | LEVEL--; |
| 383 | ypr_close(pctx, inner_flag); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | static void |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 388 | ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, |
| 389 | ly_bool singlequoted, void *exts) |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 390 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 391 | ly_bool extflag = 0; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 392 | uint16_t flags = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 393 | |
| 394 | if (!text) { |
| 395 | /* nothing to print */ |
| 396 | return; |
| 397 | } |
| 398 | |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 399 | if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) { |
| 400 | ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 401 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 402 | if (!(lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN)) { |
| 403 | flags |= LYS_YPR_TEXT_SINGLELINE; |
| 404 | } |
| 405 | if (singlequoted) { |
| 406 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
| 407 | } |
| 408 | ypr_text(pctx, lys_stmt_str(substmt), text, flags); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 412 | if (pctx->schema == LYS_YPR_PARSED) { |
| 413 | yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
| 414 | } else { |
| 415 | yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 416 | } |
| 417 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 418 | ypr_close(pctx, extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | static void |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 422 | ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 423 | unsigned long attr_value, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 424 | { |
| 425 | char *str; |
| 426 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 427 | if (asprintf(&str, "%lu", attr_value) == -1) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 428 | LOGMEM(pctx->module->ctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 429 | return; |
| 430 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 431 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 432 | ypr_substmt(pctx, substmt, substmt_index, str, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 433 | free(str); |
| 434 | } |
| 435 | |
| 436 | static void |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 437 | ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value, |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 438 | ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 439 | { |
| 440 | char *str; |
| 441 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 442 | if (asprintf(&str, "%ld", attr_value) == -1) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 443 | LOGMEM(pctx->module->ctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 444 | return; |
| 445 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 446 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 447 | ypr_substmt(pctx, substmt, substmt_index, str, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 448 | free(str); |
| 449 | } |
| 450 | |
| 451 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 452 | yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 453 | { |
| 454 | if (rev->dsc || rev->ref || rev->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 455 | ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 456 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 457 | yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 458 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, 0, rev->exts); |
| 459 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, 0, rev->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 460 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 461 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 462 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 463 | ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 468 | ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 469 | { |
| 470 | if (flags & LYS_MAND_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 471 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 472 | ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 477 | ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 478 | { |
| 479 | if (flags & LYS_CONFIG_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 480 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 481 | ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
| 485 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 486 | ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 487 | { |
| 488 | const char *status = NULL; |
| 489 | |
| 490 | if (flags & LYS_STATUS_CURR) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 491 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 492 | status = "current"; |
| 493 | } else if (flags & LYS_STATUS_DEPRC) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 494 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 495 | status = "deprecated"; |
| 496 | } else if (flags & LYS_STATUS_OBSLT) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 497 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 498 | status = "obsolete"; |
| 499 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 500 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 501 | ypr_substmt(pctx, LY_STMT_STATUS, 0, status, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 505 | ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 506 | { |
| 507 | if (dsc) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 508 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 509 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 514 | ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 515 | { |
| 516 | if (ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 517 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 518 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 523 | yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 524 | { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 525 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 526 | ly_bool extflag; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 527 | uint16_t flags; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 528 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 529 | LY_ARRAY_FOR(iffs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 530 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 531 | extflag = 0; |
| 532 | |
Michal Vasko | 659f8fa | 2024-02-27 15:20:34 +0100 | [diff] [blame] | 533 | flags = LYS_YPR_TEXT_SINGLELINE | ((iffs[u].flags & LYS_SINGLEQUOTED) ? LYS_YPR_TEXT_SINGLEQUOTED : 0); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 534 | ypr_text(pctx, "if-feature", iffs[u].str, flags); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 535 | |
| 536 | /* extensions */ |
| 537 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 538 | yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 539 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 540 | ypr_close(pctx, extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 545 | yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 546 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 547 | ly_bool flag = 0, flag2 = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 548 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 549 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 550 | ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 551 | LEVEL++; |
| 552 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 553 | yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 554 | |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 555 | if (ext->argname) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 556 | ypr_open(pctx->out, &flag); |
| 557 | ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname); |
Radek Krejci | 38d2e9f | 2019-09-09 10:31:51 +0200 | [diff] [blame] | 558 | LEVEL++; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 559 | if (ext->exts) { |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 560 | u = -1; |
Radek Krejci | fc596f9 | 2021-02-26 22:40:26 +0100 | [diff] [blame] | 561 | while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 562 | yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 563 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 564 | } |
| 565 | if ((ext->flags & LYS_YINELEM_MASK) || |
Radek Krejci | fc596f9 | 2021-02-26 22:40:26 +0100 | [diff] [blame] | 566 | (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 567 | ypr_open(pctx->out, &flag2); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 568 | ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", 0, ext->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 569 | } |
Radek Krejci | 38d2e9f | 2019-09-09 10:31:51 +0200 | [diff] [blame] | 570 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 571 | ypr_close(pctx, flag2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 574 | ypr_status(pctx, ext->flags, ext->exts, &flag); |
| 575 | ypr_description(pctx, ext->dsc, ext->exts, &flag); |
| 576 | ypr_reference(pctx, ext->ref, ext->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 577 | |
| 578 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 579 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 583 | yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 584 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 585 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 586 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 587 | ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 588 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 589 | yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 590 | yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag); |
| 591 | ypr_status(pctx, feat->flags, feat->exts, &flag); |
| 592 | ypr_description(pctx, feat->dsc, feat->exts, &flag); |
| 593 | ypr_reference(pctx, feat->ref, feat->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 594 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 595 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 599 | yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 600 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 601 | ly_bool flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 602 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 603 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 604 | ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 605 | LEVEL++; |
| 606 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 607 | yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 608 | yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 609 | |
| 610 | LY_ARRAY_FOR(ident->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 611 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 612 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], 0, ident->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 613 | } |
| 614 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 615 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
| 616 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
| 617 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 618 | |
| 619 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 620 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 624 | yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 625 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 626 | ly_bool flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 627 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 628 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 629 | ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 630 | LEVEL++; |
| 631 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 632 | yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 633 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 634 | ypr_open(pctx->out, &flag); |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 635 | if (lys_identity_iffeature_value(ident) == LY_ENOT) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 636 | ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name); |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 637 | } |
| 638 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 639 | LY_ARRAY_FOR(ident->derived, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 640 | if (pctx->module != ident->derived[u]->module) { |
| 641 | ly_print_(pctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 642 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 643 | ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 647 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
| 648 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
| 649 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 650 | |
| 651 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 652 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 656 | yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 657 | { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 658 | ly_bool inner_flag = 0; |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 659 | const char *text; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 660 | uint16_t flags = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 661 | |
| 662 | if (!restr) { |
| 663 | return; |
| 664 | } |
| 665 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 666 | ypr_open(pctx->out, flag); |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 667 | text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ? |
| 668 | restr->arg.str : restr->arg.str + 1; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 669 | if (!strchr(text, '\n')) { |
| 670 | flags |= LYS_YPR_TEXT_SINGLELINE; |
| 671 | } |
| 672 | if (restr->arg.flags & LYS_SINGLEQUOTED) { |
| 673 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
| 674 | } |
| 675 | ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, flags); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 676 | |
| 677 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 678 | yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 679 | if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 680 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 681 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 682 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 683 | } |
| 684 | if (restr->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 685 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 686 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, 0, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 687 | } |
| 688 | if (restr->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 689 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 690 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, 0, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 691 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 692 | ypr_description(pctx, restr->dsc, restr->exts, &inner_flag); |
| 693 | ypr_reference(pctx, restr->ref, restr->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 694 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 695 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 696 | ypr_close(pctx, inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 700 | yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 701 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 702 | ly_bool inner_flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 703 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 704 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 705 | ypr_text(pctx, "must", must->cond->expr, LYS_YPR_TEXT_SINGLELINE); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 706 | |
| 707 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 708 | yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 709 | if (must->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 710 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 711 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, 0, must->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 712 | } |
| 713 | if (must->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 714 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 715 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, 0, must->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 716 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 717 | ypr_description(pctx, must->dsc, must->exts, &inner_flag); |
| 718 | ypr_reference(pctx, must->ref, must->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 719 | |
| 720 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 721 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 725 | yprc_range(struct lys_ypr_ctx *pctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 726 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 727 | ly_bool inner_flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 728 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 729 | |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame] | 730 | if (!range) { |
| 731 | return; |
| 732 | } |
| 733 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 734 | ypr_open(pctx->out, flag); |
| 735 | ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 736 | LY_ARRAY_FOR(range->parts, u) { |
| 737 | if (u > 0) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 738 | ly_print_(pctx->out, " | "); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 739 | } |
| 740 | if (range->parts[u].max_64 == range->parts[u].min_64) { |
| 741 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 742 | ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 743 | } else { /* signed values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 744 | ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 745 | } |
| 746 | } else { |
| 747 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 748 | ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 749 | } else { /* signed values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 750 | ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 754 | ly_print_(pctx->out, "\""); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 755 | |
| 756 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 757 | yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 758 | if (range->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 759 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 760 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, 0, range->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 761 | } |
| 762 | if (range->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 763 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 764 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, 0, range->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 765 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 766 | ypr_description(pctx, range->dsc, range->exts, &inner_flag); |
| 767 | ypr_reference(pctx, range->ref, range->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 768 | |
| 769 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 770 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 774 | yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 775 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 776 | ly_bool inner_flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 777 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 778 | ypr_open(pctx->out, flag); |
| 779 | ly_print_(pctx->out, "%*spattern \"", INDENT); |
| 780 | ypr_encode(pctx->out, pattern->expr, -1); |
| 781 | ly_print_(pctx->out, "\""); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 782 | |
| 783 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 784 | yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 785 | if (pattern->inverted) { |
| 786 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 787 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 788 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, pattern->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 789 | } |
| 790 | if (pattern->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 791 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 792 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, 0, pattern->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 793 | } |
| 794 | if (pattern->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 795 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 796 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, 0, pattern->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 797 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 798 | ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag); |
| 799 | ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 800 | |
| 801 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 802 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | static void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 806 | yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag) |
| 807 | { |
| 808 | LY_ARRAY_COUNT_TYPE u; |
| 809 | const struct lysc_type_bitenum_item *item; |
| 810 | ly_bool inner_flag; |
| 811 | |
| 812 | assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM)); |
| 813 | |
| 814 | LY_ARRAY_FOR(items, u) { |
| 815 | item = &items[u]; |
| 816 | inner_flag = 0; |
| 817 | |
| 818 | ypr_open(pctx->out, flag); |
| 819 | ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum"); |
| 820 | ypr_encode(pctx->out, item->name, -1); |
| 821 | ly_print_(pctx->out, "\""); |
| 822 | LEVEL++; |
| 823 | if (basetype == LY_TYPE_BITS) { |
| 824 | yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag); |
| 825 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag); |
| 826 | } else { /* LY_TYPE_ENUM */ |
| 827 | yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag); |
| 828 | ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag); |
| 829 | } |
| 830 | ypr_status(pctx, item->flags, item->exts, &inner_flag); |
| 831 | ypr_description(pctx, item->dsc, item->exts, &inner_flag); |
| 832 | ypr_reference(pctx, item->ref, item->exts, &inner_flag); |
| 833 | LEVEL--; |
| 834 | ypr_close(pctx, inner_flag); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | static void |
| 839 | yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 840 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 841 | ly_bool inner_flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 842 | |
| 843 | if (!when) { |
| 844 | return; |
| 845 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 846 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 847 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 848 | ypr_text(pctx, "when", when->cond, LYS_YPR_TEXT_SINGLELINE); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 849 | |
| 850 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 851 | yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 852 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
| 853 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 854 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 855 | ypr_close(pctx, inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | static void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 859 | yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 860 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 861 | ly_bool inner_flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 862 | |
| 863 | if (!when) { |
| 864 | return; |
| 865 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 866 | ypr_open(pctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 867 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 868 | ypr_text(pctx, "when", when->cond->expr, LYS_YPR_TEXT_SINGLELINE); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 869 | |
| 870 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 871 | yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 872 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
| 873 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 874 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 875 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 879 | yprp_bits_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 880 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 881 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 882 | ly_bool inner_flag; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 883 | |
| 884 | LY_ARRAY_FOR(items, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 885 | ypr_open(pctx->out, flag); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 886 | if (type == LY_TYPE_BITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 887 | ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 888 | } else { /* LY_TYPE_ENUM */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 889 | ly_print_(pctx->out, "%*senum \"", INDENT); |
| 890 | ypr_encode(pctx->out, items[u].name, -1); |
| 891 | ly_print_(pctx->out, "\""); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 892 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 893 | inner_flag = 0; |
| 894 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 895 | yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 896 | yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 897 | if (items[u].flags & LYS_SET_VALUE) { |
| 898 | if (type == LY_TYPE_BITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 899 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 900 | } else { /* LY_TYPE_ENUM */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 901 | ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 902 | } |
| 903 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 904 | ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag); |
| 905 | ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag); |
| 906 | ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 907 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 908 | ypr_close(pctx, inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
| 912 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 913 | yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 914 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 915 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 916 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 917 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 918 | ly_print_(pctx->out, "%*stype %s", INDENT, type->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 919 | LEVEL++; |
| 920 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 921 | yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 922 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 923 | yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag); |
| 924 | yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 925 | LY_ARRAY_FOR(type->patterns, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 926 | yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 927 | } |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 928 | yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag); |
| 929 | yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 930 | |
| 931 | if (type->path) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 932 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 933 | ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, 0, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 934 | } |
| 935 | if (type->flags & LYS_SET_REQINST) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 936 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 937 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", 0, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 938 | } |
| 939 | if (type->flags & LYS_SET_FRDIGITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 940 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 941 | } |
| 942 | LY_ARRAY_FOR(type->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 943 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 944 | ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], 0, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 945 | } |
| 946 | LY_ARRAY_FOR(type->types, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 947 | ypr_open(pctx->out, &flag); |
| 948 | yprp_type(pctx, &type->types[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 952 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 956 | yprc_dflt_value(struct lys_ypr_ctx *pctx, const struct ly_ctx *ly_pctx, const struct lyd_value *value, |
Radek Krejci | 224d4b4 | 2021-04-23 13:54:59 +0200 | [diff] [blame] | 957 | struct lysc_ext_instance *exts) |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 958 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 959 | ly_bool dynamic; |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 960 | const char *str; |
| 961 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 962 | str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 963 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, 0, exts); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 964 | if (dynamic) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 965 | free((void *)str); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
| 969 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 970 | yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 971 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 972 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 973 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 974 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 975 | ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype)); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 976 | LEVEL++; |
| 977 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 978 | yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 979 | |
Michal Vasko | 2bb55bc | 2020-08-05 13:27:04 +0200 | [diff] [blame] | 980 | switch (type->basetype) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 981 | case LY_TYPE_BINARY: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 982 | struct lysc_type_bin *bin = (struct lysc_type_bin *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 983 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 984 | yprc_range(pctx, bin->length, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 985 | break; |
| 986 | } |
| 987 | case LY_TYPE_UINT8: |
| 988 | case LY_TYPE_UINT16: |
| 989 | case LY_TYPE_UINT32: |
| 990 | case LY_TYPE_UINT64: |
| 991 | case LY_TYPE_INT8: |
| 992 | case LY_TYPE_INT16: |
| 993 | case LY_TYPE_INT32: |
| 994 | case LY_TYPE_INT64: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 995 | struct lysc_type_num *num = (struct lysc_type_num *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 996 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 997 | yprc_range(pctx, num->range, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 998 | break; |
| 999 | } |
| 1000 | case LY_TYPE_STRING: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1001 | struct lysc_type_str *str = (struct lysc_type_str *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1002 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1003 | yprc_range(pctx, str->length, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1004 | LY_ARRAY_FOR(str->patterns, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1005 | yprc_pattern(pctx, str->patterns[u], &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1006 | } |
| 1007 | break; |
| 1008 | } |
| 1009 | case LY_TYPE_BITS: |
| 1010 | case LY_TYPE_ENUM: { |
| 1011 | /* bits and enums structures are compatible */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1012 | struct lysc_type_bits *bits = (struct lysc_type_bits *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1013 | |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 1014 | yprc_bits_enum(pctx, bits->bits, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1015 | break; |
| 1016 | } |
| 1017 | case LY_TYPE_BOOL: |
| 1018 | case LY_TYPE_EMPTY: |
| 1019 | /* nothing to do */ |
| 1020 | break; |
| 1021 | case LY_TYPE_DEC64: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1022 | struct lysc_type_dec *dec = (struct lysc_type_dec *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1023 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1024 | ypr_open(pctx->out, &flag); |
| 1025 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag); |
| 1026 | yprc_range(pctx, dec->range, dec->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1027 | break; |
| 1028 | } |
| 1029 | case LY_TYPE_IDENT: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1030 | struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1031 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1032 | LY_ARRAY_FOR(ident->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1033 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1034 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, 0, type->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1035 | } |
| 1036 | break; |
| 1037 | } |
| 1038 | case LY_TYPE_INST: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1039 | struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1040 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1041 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1042 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", 0, inst->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1043 | break; |
| 1044 | } |
| 1045 | case LY_TYPE_LEAFREF: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1046 | struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1047 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1048 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1049 | ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, 0, lr->exts); |
| 1050 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", 0, lr->exts); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1051 | yprc_type(pctx, lr->realtype); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1052 | break; |
| 1053 | } |
| 1054 | case LY_TYPE_UNION: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1055 | struct lysc_type_union *un = (struct lysc_type_union *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1056 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1057 | LY_ARRAY_FOR(un->types, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1058 | ypr_open(pctx->out, &flag); |
| 1059 | yprc_type(pctx, un->types[u]); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1060 | } |
| 1061 | break; |
| 1062 | } |
| 1063 | default: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1064 | LOGINT(pctx->module->ctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1068 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1072 | yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1073 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1074 | ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1075 | LEVEL++; |
| 1076 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1077 | yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1078 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1079 | yprp_type(pctx, &tpdf->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1080 | |
| 1081 | if (tpdf->units) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1082 | ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, 0, tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1083 | } |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1084 | if (tpdf->dflt.str) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1085 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(tpdf->dflt.flags), tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1088 | ypr_status(pctx, tpdf->flags, tpdf->exts, NULL); |
| 1089 | ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL); |
| 1090 | ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1091 | |
| 1092 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1093 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1094 | } |
| 1095 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1096 | static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node); |
| 1097 | static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node); |
| 1098 | static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action); |
| 1099 | static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1100 | |
| 1101 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1102 | yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1103 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1104 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1105 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1106 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1107 | struct lysp_node_action *action; |
| 1108 | struct lysp_node_notif *notif; |
| 1109 | struct lysp_node_grp *subgrp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1110 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1111 | ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1112 | LEVEL++; |
| 1113 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1114 | yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1115 | ypr_status(pctx, grp->flags, grp->exts, &flag); |
| 1116 | ypr_description(pctx, grp->dsc, grp->exts, &flag); |
| 1117 | ypr_reference(pctx, grp->ref, grp->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1118 | |
| 1119 | LY_ARRAY_FOR(grp->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1120 | ypr_open(pctx->out, &flag); |
| 1121 | yprp_typedef(pctx, &grp->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1124 | LY_LIST_FOR(grp->groupings, subgrp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1125 | ypr_open(pctx->out, &flag); |
| 1126 | yprp_grouping(pctx, subgrp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1129 | LY_LIST_FOR(grp->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1130 | ypr_open(pctx->out, &flag); |
| 1131 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1132 | } |
| 1133 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1134 | LY_LIST_FOR(grp->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1135 | ypr_open(pctx->out, &flag); |
| 1136 | yprp_action(pctx, action); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | LY_LIST_FOR(grp->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1140 | ypr_open(pctx->out, &flag); |
| 1141 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1145 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1149 | yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1150 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1151 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1152 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1153 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1154 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1155 | if (!inout->child) { |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1156 | /* no children */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1157 | return; |
| 1158 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1159 | ypr_open(pctx->out, flag); |
| 1160 | YPR_EXTRA_LINE_PRINT(pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1161 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1162 | ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1163 | LEVEL++; |
| 1164 | |
Olivier Matz | 998e1e4 | 2024-08-05 13:35:16 +0200 | [diff] [blame] | 1165 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1166 | LY_ARRAY_FOR(inout->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1167 | yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1168 | } |
| 1169 | LY_ARRAY_FOR(inout->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1170 | yprp_typedef(pctx, &inout->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1171 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1172 | LY_LIST_FOR(inout->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1173 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1174 | } |
| 1175 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1176 | LY_LIST_FOR(inout->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1177 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1181 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1185 | yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1186 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1187 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1188 | struct lysc_node *data; |
| 1189 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1190 | if (!inout->child) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1191 | /* input/output is empty */ |
| 1192 | return; |
| 1193 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1194 | ypr_open(pctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1195 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1196 | ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1197 | LEVEL++; |
| 1198 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1199 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1200 | LY_ARRAY_FOR(inout->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1201 | yprc_must(pctx, &inout->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1202 | } |
| 1203 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1204 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1205 | LY_LIST_FOR(inout->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1206 | yprc_node(pctx, data); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1207 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1211 | ypr_close(pctx, 1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1215 | yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1216 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1217 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1218 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1219 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1220 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1221 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1222 | ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1223 | |
| 1224 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1225 | yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1226 | yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1227 | |
| 1228 | LY_ARRAY_FOR(notif->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1229 | yprp_restr(pctx, ¬if->musts[u], LY_STMT_MUST, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1230 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1231 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
| 1232 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
| 1233 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1234 | |
| 1235 | LY_ARRAY_FOR(notif->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1236 | ypr_open(pctx->out, &flag); |
| 1237 | yprp_typedef(pctx, ¬if->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1240 | LY_LIST_FOR(notif->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1241 | ypr_open(pctx->out, &flag); |
| 1242 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1243 | } |
| 1244 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1245 | LY_LIST_FOR(notif->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1246 | ypr_open(pctx->out, &flag); |
| 1247 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1251 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1255 | yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1256 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1257 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1258 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1259 | struct lysc_node *data; |
| 1260 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1261 | ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1262 | |
| 1263 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1264 | yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1265 | |
| 1266 | LY_ARRAY_FOR(notif->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1267 | yprc_must(pctx, ¬if->musts[u], &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1268 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1269 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
| 1270 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
| 1271 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1272 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1273 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1274 | LY_LIST_FOR(notif->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1275 | ypr_open(pctx->out, &flag); |
| 1276 | yprc_node(pctx, data); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1277 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1281 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1285 | yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1286 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1287 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1288 | ly_bool flag = 0; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1289 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1290 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1291 | ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1292 | |
| 1293 | LEVEL++; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1294 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1295 | yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag); |
| 1296 | ypr_status(pctx, action->flags, action->exts, &flag); |
| 1297 | ypr_description(pctx, action->dsc, action->exts, &flag); |
| 1298 | ypr_reference(pctx, action->ref, action->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1299 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1300 | YPR_EXTRA_LINE(flag, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 1301 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1302 | LY_ARRAY_FOR(action->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1303 | ypr_open(pctx->out, &flag); |
| 1304 | YPR_EXTRA_LINE_PRINT(pctx); |
| 1305 | yprp_typedef(pctx, &action->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1306 | } |
| 1307 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1308 | YPR_EXTRA_LINE(action->typedefs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 1309 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1310 | LY_LIST_FOR(action->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1311 | ypr_open(pctx->out, &flag); |
| 1312 | YPR_EXTRA_LINE_PRINT(pctx); |
| 1313 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1314 | } |
| 1315 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1316 | YPR_EXTRA_LINE(action->groupings, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 1317 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1318 | yprp_inout(pctx, &action->input, &flag); |
| 1319 | yprp_inout(pctx, &action->output, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1320 | |
| 1321 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1322 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1326 | yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1327 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1328 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1329 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1330 | ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1331 | |
| 1332 | LEVEL++; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1333 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1334 | ypr_status(pctx, action->flags, action->exts, &flag); |
| 1335 | ypr_description(pctx, action->dsc, action->exts, &flag); |
| 1336 | ypr_reference(pctx, action->ref, action->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1337 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1338 | yprc_inout(pctx, &action->input, &flag); |
| 1339 | yprc_inout(pctx, &action->output, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1340 | |
| 1341 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1342 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1346 | yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1347 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1348 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1349 | LEVEL++; |
| 1350 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1351 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1352 | yprp_when(pctx, lysp_node_when(node), flag); |
| 1353 | yprp_iffeatures(pctx, node->iffeatures, node->exts, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1357 | yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1358 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1359 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1360 | struct lysc_when **when; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1361 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1362 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1363 | LEVEL++; |
| 1364 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1365 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1366 | |
| 1367 | when = lysc_node_when(node); |
| 1368 | LY_ARRAY_FOR(when, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1369 | yprc_when(pctx, when[u], flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1370 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1373 | /* macro to unify the code */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1374 | #define YPR_NODE_COMMON2 \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1375 | ypr_config(pctx, node->flags, node->exts, flag); \ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1376 | if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1377 | ypr_mandatory(pctx, node->flags, node->exts, flag); \ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1378 | } \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1379 | ypr_status(pctx, node->flags, node->exts, flag); \ |
| 1380 | ypr_description(pctx, node->dsc, node->exts, flag); \ |
| 1381 | ypr_reference(pctx, node->ref, node->exts, flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1382 | |
| 1383 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1384 | yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1385 | { |
| 1386 | YPR_NODE_COMMON2; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1390 | yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1391 | { |
| 1392 | YPR_NODE_COMMON2; |
| 1393 | } |
| 1394 | |
| 1395 | #undef YPR_NODE_COMMON2 |
| 1396 | |
| 1397 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1398 | yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1399 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1400 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1401 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1402 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1403 | struct lysp_node_action *action; |
| 1404 | struct lysp_node_notif *notif; |
| 1405 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1406 | struct lysp_node_container *cont = (struct lysp_node_container *)node; |
| 1407 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1408 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1409 | |
| 1410 | LY_ARRAY_FOR(cont->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1411 | yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1412 | } |
| 1413 | if (cont->presence) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1414 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1415 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, 0, cont->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1416 | } |
| 1417 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1418 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1419 | |
| 1420 | LY_ARRAY_FOR(cont->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1421 | ypr_open(pctx->out, &flag); |
| 1422 | yprp_typedef(pctx, &cont->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1425 | LY_LIST_FOR(cont->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1426 | ypr_open(pctx->out, &flag); |
| 1427 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | LY_LIST_FOR(cont->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1431 | ypr_open(pctx->out, &flag); |
| 1432 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1433 | } |
| 1434 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1435 | LY_LIST_FOR(cont->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1436 | ypr_open(pctx->out, &flag); |
| 1437 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1440 | LY_LIST_FOR(cont->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1441 | ypr_open(pctx->out, &flag); |
| 1442 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1446 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1450 | yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1451 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1452 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1453 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1454 | struct lysc_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1455 | struct lysc_node_action *action; |
| 1456 | struct lysc_node_notif *notif; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1457 | struct lysc_node_container *cont = (struct lysc_node_container *)node; |
| 1458 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1459 | yprc_node_common1(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1460 | |
| 1461 | LY_ARRAY_FOR(cont->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1462 | yprc_must(pctx, &cont->musts[u], &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1463 | } |
| 1464 | if (cont->flags & LYS_PRESENCE) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1465 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1466 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", 0, cont->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1469 | yprc_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1470 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1471 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1472 | LY_LIST_FOR(cont->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1473 | ypr_open(pctx->out, &flag); |
| 1474 | yprc_node(pctx, child); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1475 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1476 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1477 | LY_LIST_FOR(cont->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1478 | ypr_open(pctx->out, &flag); |
| 1479 | yprc_action(pctx, action); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1480 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1481 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1482 | LY_LIST_FOR(cont->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1483 | ypr_open(pctx->out, &flag); |
| 1484 | yprc_notification(pctx, notif); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1485 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1489 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1493 | yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1494 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1495 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1496 | struct lysp_node *child; |
| 1497 | struct lysp_node_case *cas = (struct lysp_node_case *)node; |
| 1498 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1499 | yprp_node_common1(pctx, node, &flag); |
| 1500 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1501 | |
| 1502 | LY_LIST_FOR(cas->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1503 | ypr_open(pctx->out, &flag); |
| 1504 | yprp_node(pctx, child); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1508 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1512 | yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1513 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1514 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1515 | struct lysc_node *child; |
| 1516 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1517 | yprc_node_common1(pctx, &cs->node, &flag); |
| 1518 | yprc_node_common2(pctx, &cs->node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1519 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1520 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1521 | for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1522 | ypr_open(pctx->out, &flag); |
| 1523 | yprc_node(pctx, child); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1524 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1528 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1532 | yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1533 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1534 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1535 | struct lysp_node *child; |
| 1536 | struct lysp_node_choice *choice = (struct lysp_node_choice *)node; |
| 1537 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1538 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1539 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1540 | if (choice->dflt.str) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1541 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1542 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, YPR_IS_LYS_SINGLEQUOTED(choice->dflt.flags), choice->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1543 | } |
| 1544 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1545 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1546 | |
| 1547 | LY_LIST_FOR(choice->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1548 | ypr_open(pctx->out, &flag); |
| 1549 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1553 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1557 | yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1558 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1559 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1560 | struct lysc_node_case *cs; |
| 1561 | struct lysc_node_choice *choice = (struct lysc_node_choice *)node; |
| 1562 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1563 | yprc_node_common1(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1564 | |
| 1565 | if (choice->dflt) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1566 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1567 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, 0, choice->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1570 | yprc_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1571 | |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1572 | for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1573 | ypr_open(pctx->out, &flag); |
| 1574 | yprc_case(pctx, cs); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1578 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1582 | yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1583 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1584 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1585 | struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node; |
| 1586 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1587 | yprp_node_common1(pctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1588 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1589 | yprp_type(pctx, &leaf->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1590 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1591 | LY_ARRAY_FOR(leaf->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1592 | yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1593 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1594 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(leaf->dflt.flags), leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1595 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1596 | yprp_node_common2(pctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1597 | |
| 1598 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1599 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1603 | yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1604 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1605 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1606 | struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node; |
| 1607 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1608 | yprc_node_common1(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1609 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1610 | yprc_type(pctx, leaf->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1611 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1612 | LY_ARRAY_FOR(leaf->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1613 | yprc_must(pctx, &leaf->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1614 | } |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1615 | |
| 1616 | if (leaf->dflt) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1617 | yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1618 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1619 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1620 | yprc_node_common2(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1621 | |
| 1622 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1623 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1627 | yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1628 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1629 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1630 | struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node; |
| 1631 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1632 | yprp_node_common1(pctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1633 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1634 | yprp_type(pctx, &llist->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1635 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1636 | LY_ARRAY_FOR(llist->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1637 | yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1638 | } |
| 1639 | LY_ARRAY_FOR(llist->dflts, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1640 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(llist->dflts[u].flags), |
| 1641 | llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1642 | } |
| 1643 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1644 | ypr_config(pctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1645 | |
| 1646 | if (llist->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1647 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1648 | } |
| 1649 | if (llist->flags & LYS_SET_MAX) { |
| 1650 | if (llist->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1651 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1652 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1653 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | if (llist->flags & LYS_ORDBY_MASK) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1658 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1659 | } |
| 1660 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1661 | ypr_status(pctx, node->flags, node->exts, NULL); |
| 1662 | ypr_description(pctx, node->dsc, node->exts, NULL); |
| 1663 | ypr_reference(pctx, node->ref, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1664 | |
| 1665 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1666 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1670 | yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1671 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1672 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1673 | struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node; |
| 1674 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1675 | yprc_node_common1(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1676 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1677 | yprc_type(pctx, llist->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1678 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1679 | LY_ARRAY_FOR(llist->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1680 | yprc_must(pctx, &llist->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1681 | } |
| 1682 | LY_ARRAY_FOR(llist->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1683 | yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1684 | } |
| 1685 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1686 | ypr_config(pctx, node->flags, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1687 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1688 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1689 | if (llist->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1690 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1691 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1692 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1695 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1696 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1697 | ypr_status(pctx, node->flags, node->exts, NULL); |
| 1698 | ypr_description(pctx, node->dsc, node->exts, NULL); |
| 1699 | ypr_reference(pctx, node->ref, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1700 | |
| 1701 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1702 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1706 | yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1707 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1708 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1709 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1710 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1711 | struct lysp_node_action *action; |
| 1712 | struct lysp_node_notif *notif; |
| 1713 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1714 | struct lysp_node_list *list = (struct lysp_node_list *)node; |
| 1715 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1716 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1717 | |
| 1718 | LY_ARRAY_FOR(list->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1719 | yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1720 | } |
| 1721 | if (list->key) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1722 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1723 | ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, 0, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1724 | } |
| 1725 | LY_ARRAY_FOR(list->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1726 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1727 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(list->uniques[u].flags), |
| 1728 | list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1729 | } |
| 1730 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1731 | ypr_config(pctx, node->flags, node->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1732 | |
| 1733 | if (list->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1734 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1735 | } |
| 1736 | if (list->flags & LYS_SET_MAX) { |
| 1737 | if (list->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1738 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1739 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1740 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1741 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | if (list->flags & LYS_ORDBY_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1746 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1747 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1748 | } |
| 1749 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1750 | ypr_status(pctx, node->flags, node->exts, &flag); |
| 1751 | ypr_description(pctx, node->dsc, node->exts, &flag); |
| 1752 | ypr_reference(pctx, node->ref, node->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1753 | |
| 1754 | LY_ARRAY_FOR(list->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1755 | ypr_open(pctx->out, &flag); |
| 1756 | yprp_typedef(pctx, &list->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1757 | } |
| 1758 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1759 | LY_LIST_FOR(list->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1760 | ypr_open(pctx->out, &flag); |
| 1761 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | LY_LIST_FOR(list->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1765 | ypr_open(pctx->out, &flag); |
| 1766 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1767 | } |
| 1768 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1769 | LY_LIST_FOR(list->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1770 | ypr_open(pctx->out, &flag); |
| 1771 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1772 | } |
| 1773 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1774 | LY_LIST_FOR(list->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1775 | ypr_open(pctx->out, &flag); |
| 1776 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1780 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1784 | yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1785 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1786 | LY_ARRAY_COUNT_TYPE u, v; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1787 | struct lysc_node_list *list = (struct lysc_node_list *)node; |
| 1788 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1789 | yprc_node_common1(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1790 | |
| 1791 | LY_ARRAY_FOR(list->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1792 | yprc_must(pctx, &list->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1793 | } |
Radek Krejci | 0fe9b51 | 2019-07-26 17:51:05 +0200 | [diff] [blame] | 1794 | if (!(list->flags & LYS_KEYLESS)) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1795 | ly_print_(pctx->out, "%*skey \"", INDENT); |
Radek Krejci | 0fe9b51 | 2019-07-26 17:51:05 +0200 | [diff] [blame] | 1796 | for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1797 | ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1798 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1799 | ly_print_(pctx->out, "\";\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1800 | } |
| 1801 | LY_ARRAY_FOR(list->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1802 | ly_print_(pctx->out, "%*sunique \"", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1803 | LY_ARRAY_FOR(list->uniques[u], v) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1804 | ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1805 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1806 | ypr_close(pctx, 0); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1807 | } |
| 1808 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1809 | ypr_config(pctx, node->flags, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1810 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1811 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1812 | if (list->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1813 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1814 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1815 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1818 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1819 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1820 | ypr_status(pctx, node->flags, node->exts, NULL); |
| 1821 | ypr_description(pctx, node->dsc, node->exts, NULL); |
| 1822 | ypr_reference(pctx, node->ref, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1823 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1824 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1825 | struct lysc_node *child; |
| 1826 | struct lysc_node_action *action; |
| 1827 | struct lysc_node_notif *notif; |
| 1828 | |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1829 | LY_LIST_FOR(list->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1830 | yprc_node(pctx, child); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1831 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1832 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1833 | LY_LIST_FOR(list->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1834 | yprc_action(pctx, action); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1835 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1836 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1837 | LY_LIST_FOR(list->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1838 | yprc_notification(pctx, notif); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1839 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1843 | ypr_close(pctx, 1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1847 | yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1848 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1849 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1850 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1851 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1852 | ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1853 | LEVEL++; |
| 1854 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1855 | yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1856 | yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1857 | |
| 1858 | LY_ARRAY_FOR(refine->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1859 | ypr_open(pctx->out, &flag); |
| 1860 | yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | if (refine->presence) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1864 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1865 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, 0, refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | LY_ARRAY_FOR(refine->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1869 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1870 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(refine->dflts[u].flags), |
| 1871 | refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1872 | } |
| 1873 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1874 | ypr_config(pctx, refine->flags, refine->exts, &flag); |
| 1875 | ypr_mandatory(pctx, refine->flags, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1876 | |
| 1877 | if (refine->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1878 | ypr_open(pctx->out, &flag); |
| 1879 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1880 | } |
| 1881 | if (refine->flags & LYS_SET_MAX) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1882 | ypr_open(pctx->out, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1883 | if (refine->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1884 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1885 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1886 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1887 | } |
| 1888 | } |
| 1889 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1890 | ypr_description(pctx, refine->dsc, refine->exts, &flag); |
| 1891 | ypr_reference(pctx, refine->ref, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1892 | |
| 1893 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1894 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1898 | yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1899 | { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1900 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1901 | struct lysp_node_action *action; |
| 1902 | struct lysp_node_notif *notif; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1903 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1904 | ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1905 | LEVEL++; |
| 1906 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1907 | yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1908 | yprp_when(pctx, aug->when, NULL); |
| 1909 | yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL); |
| 1910 | ypr_status(pctx, aug->flags, aug->exts, NULL); |
| 1911 | ypr_description(pctx, aug->dsc, aug->exts, NULL); |
| 1912 | ypr_reference(pctx, aug->ref, aug->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1913 | |
| 1914 | LY_LIST_FOR(aug->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1915 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1916 | } |
| 1917 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1918 | LY_LIST_FOR(aug->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1919 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1922 | LY_LIST_FOR(aug->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1923 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1927 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1928 | } |
| 1929 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1930 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1931 | yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1932 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1933 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1934 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1935 | struct lysp_node_uses *uses = (struct lysp_node_uses *)node; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1936 | struct lysp_node_augment *aug; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1937 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1938 | yprp_node_common1(pctx, node, &flag); |
| 1939 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1940 | |
| 1941 | LY_ARRAY_FOR(uses->refines, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1942 | ypr_open(pctx->out, &flag); |
| 1943 | yprp_refine(pctx, &uses->refines[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1944 | } |
| 1945 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1946 | LY_LIST_FOR(uses->augments, aug) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1947 | ypr_open(pctx->out, &flag); |
| 1948 | yprp_augment(pctx, aug); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1952 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1956 | yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1957 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1958 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1959 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1960 | struct lysp_node_anydata *any = (struct lysp_node_anydata *)node; |
| 1961 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1962 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1963 | |
| 1964 | LY_ARRAY_FOR(any->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1965 | ypr_open(pctx->out, &flag); |
| 1966 | yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1967 | } |
| 1968 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1969 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1970 | |
| 1971 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1972 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1976 | yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1977 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1978 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1979 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1980 | struct lysc_node_anydata *any = (struct lysc_node_anydata *)node; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1981 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1982 | yprc_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1983 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1984 | LY_ARRAY_FOR(any->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1985 | ypr_open(pctx->out, &flag); |
| 1986 | yprc_must(pctx, &any->musts[u], NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1987 | } |
| 1988 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1989 | yprc_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1990 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1991 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1992 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1996 | yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1997 | { |
| 1998 | switch (node->nodetype) { |
| 1999 | case LYS_CONTAINER: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2000 | yprp_container(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2001 | break; |
| 2002 | case LYS_CHOICE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2003 | yprp_choice(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2004 | break; |
| 2005 | case LYS_LEAF: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2006 | yprp_leaf(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2007 | break; |
| 2008 | case LYS_LEAFLIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2009 | yprp_leaflist(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2010 | break; |
| 2011 | case LYS_LIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2012 | yprp_list(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2013 | break; |
| 2014 | case LYS_USES: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2015 | yprp_uses(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2016 | break; |
| 2017 | case LYS_ANYXML: |
| 2018 | case LYS_ANYDATA: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2019 | yprp_anydata(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2020 | break; |
| 2021 | case LYS_CASE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2022 | yprp_case(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2023 | break; |
| 2024 | default: |
| 2025 | break; |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2030 | yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2031 | { |
| 2032 | switch (node->nodetype) { |
| 2033 | case LYS_CONTAINER: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2034 | yprc_container(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2035 | break; |
| 2036 | case LYS_CHOICE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2037 | yprc_choice(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2038 | break; |
| 2039 | case LYS_LEAF: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2040 | yprc_leaf(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2041 | break; |
| 2042 | case LYS_LEAFLIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2043 | yprc_leaflist(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2044 | break; |
| 2045 | case LYS_LIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2046 | yprc_list(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2047 | break; |
| 2048 | case LYS_ANYXML: |
| 2049 | case LYS_ANYDATA: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2050 | yprc_anydata(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2051 | break; |
| 2052 | default: |
| 2053 | break; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2058 | yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2059 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 2060 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2061 | struct lysp_deviate_add *add; |
| 2062 | struct lysp_deviate_rpl *rpl; |
| 2063 | struct lysp_deviate_del *del; |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2064 | struct lysp_deviate *elem; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2065 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2066 | ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2067 | LEVEL++; |
| 2068 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2069 | yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2070 | ypr_description(pctx, deviation->dsc, deviation->exts, NULL); |
| 2071 | ypr_reference(pctx, deviation->ref, deviation->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2072 | |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2073 | LY_LIST_FOR(deviation->deviates, elem) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2074 | ly_print_(pctx->out, "%*sdeviate ", INDENT); |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2075 | if (elem->mod == LYS_DEV_NOT_SUPPORTED) { |
| 2076 | if (elem->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2077 | ly_print_(pctx->out, "not-supported {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2078 | LEVEL++; |
| 2079 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2080 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2081 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2082 | ly_print_(pctx->out, "not-supported;\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2083 | continue; |
| 2084 | } |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2085 | } else if (elem->mod == LYS_DEV_ADD) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2086 | add = (struct lysp_deviate_add *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2087 | ly_print_(pctx->out, "add {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2088 | LEVEL++; |
| 2089 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2090 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2091 | ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, 0, add->exts); |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2092 | LY_ARRAY_FOR(add->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2093 | yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2094 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2095 | LY_ARRAY_FOR(add->uniques, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2096 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(add->uniques[u].flags), |
| 2097 | add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2098 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2099 | LY_ARRAY_FOR(add->dflts, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2100 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(add->dflts[u].flags), |
| 2101 | add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2102 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2103 | ypr_config(pctx, add->flags, add->exts, NULL); |
| 2104 | ypr_mandatory(pctx, add->flags, add->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2105 | if (add->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2106 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2107 | } |
| 2108 | if (add->flags & LYS_SET_MAX) { |
| 2109 | if (add->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2110 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2111 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2112 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2113 | } |
| 2114 | } |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2115 | } else if (elem->mod == LYS_DEV_REPLACE) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2116 | rpl = (struct lysp_deviate_rpl *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2117 | ly_print_(pctx->out, "replace {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2118 | LEVEL++; |
| 2119 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2120 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2121 | if (rpl->type) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2122 | yprp_type(pctx, rpl->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2123 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2124 | ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, 0, rpl->exts); |
| 2125 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, YPR_IS_LYS_SINGLEQUOTED(rpl->dflt.flags), rpl->exts); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2126 | ypr_config(pctx, rpl->flags, rpl->exts, NULL); |
| 2127 | ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2128 | if (rpl->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2129 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2130 | } |
| 2131 | if (rpl->flags & LYS_SET_MAX) { |
| 2132 | if (rpl->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2133 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2134 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2135 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, rpl->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2136 | } |
| 2137 | } |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2138 | } else if (elem->mod == LYS_DEV_DELETE) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2139 | del = (struct lysp_deviate_del *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2140 | ly_print_(pctx->out, "delete {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2141 | LEVEL++; |
| 2142 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2143 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2144 | ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, 0, del->exts); |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2145 | LY_ARRAY_FOR(del->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2146 | yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2147 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2148 | LY_ARRAY_FOR(del->uniques, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2149 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(del->uniques[u].flags), |
| 2150 | del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2151 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2152 | LY_ARRAY_FOR(del->dflts, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2153 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(del->dflts[u].flags), |
| 2154 | del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2159 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2163 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2164 | } |
| 2165 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2166 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2167 | yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2168 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 2169 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2170 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2171 | LY_ARRAY_FOR(modp->imports, u) { |
Michal Vasko | 3e9bc2f | 2020-11-04 17:13:56 +0100 | [diff] [blame] | 2172 | if (modp->imports[u].flags & LYS_INTERNAL) { |
| 2173 | continue; |
| 2174 | } |
| 2175 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2176 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2177 | ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2178 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2179 | yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2180 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, 0, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2181 | if (modp->imports[u].rev[0]) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2182 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, 0, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2183 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2184 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, 0, modp->imports[u].exts); |
| 2185 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, 0, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2186 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2187 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2188 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2189 | YPR_EXTRA_LINE(modp->imports, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2190 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2191 | LY_ARRAY_FOR(modp->includes, u) { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 2192 | if (modp->includes[u].injected) { |
| 2193 | /* do not print the includes injected from submodules */ |
| 2194 | continue; |
| 2195 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2196 | YPR_EXTRA_LINE_PRINT(pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2197 | if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2198 | ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2199 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2200 | yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2201 | if (modp->includes[u].rev[0]) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2202 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, 0, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2203 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2204 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, 0, modp->includes[u].exts); |
| 2205 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, 0, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2206 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2207 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2208 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2209 | ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2210 | } |
| 2211 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2212 | YPR_EXTRA_LINE(modp->includes, pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2213 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2214 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2215 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2216 | yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2217 | { |
| 2218 | LY_ARRAY_COUNT_TYPE u; |
| 2219 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2220 | struct lysp_node_action *action; |
| 2221 | struct lysp_node_notif *notif; |
| 2222 | struct lysp_node_grp *grp; |
| 2223 | struct lysp_node_augment *aug; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2224 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2225 | LY_ARRAY_FOR(modp->extensions, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2226 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2227 | yprp_extension(pctx, &modp->extensions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2228 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2229 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2230 | YPR_EXTRA_LINE(modp->extensions, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2231 | |
aPiecek | 6cf1d16 | 2023-11-08 16:07:00 +0100 | [diff] [blame] | 2232 | if (yprp_extension_has_printable_instances(modp->exts)) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2233 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2234 | yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2237 | YPR_EXTRA_LINE(modp->exts, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2238 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2239 | LY_ARRAY_FOR(modp->features, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2240 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2241 | yprp_feature(pctx, &modp->features[u]); |
| 2242 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2243 | } |
| 2244 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2245 | YPR_EXTRA_LINE(modp->features, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2246 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2247 | LY_ARRAY_FOR(modp->identities, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2248 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2249 | yprp_identity(pctx, &modp->identities[u]); |
| 2250 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2251 | } |
| 2252 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2253 | YPR_EXTRA_LINE(modp->identities, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2254 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2255 | LY_ARRAY_FOR(modp->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2256 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2257 | yprp_typedef(pctx, &modp->typedefs[u]); |
| 2258 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2259 | } |
| 2260 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2261 | YPR_EXTRA_LINE(modp->typedefs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2262 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2263 | LY_LIST_FOR(modp->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2264 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2265 | yprp_grouping(pctx, grp); |
| 2266 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2267 | } |
| 2268 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2269 | YPR_EXTRA_LINE(modp->groupings, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2270 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2271 | LY_LIST_FOR(modp->data, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2272 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2273 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2274 | } |
| 2275 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2276 | YPR_EXTRA_LINE(modp->data, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2277 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2278 | LY_LIST_FOR(modp->augments, aug) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2279 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2280 | yprp_augment(pctx, aug); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2283 | YPR_EXTRA_LINE(modp->augments, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2284 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2285 | LY_LIST_FOR(modp->rpcs, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2286 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2287 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2288 | } |
| 2289 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2290 | YPR_EXTRA_LINE(modp->rpcs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2291 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2292 | LY_LIST_FOR(modp->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2293 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2294 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2295 | } |
| 2296 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2297 | YPR_EXTRA_LINE(modp->notifs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2298 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2299 | LY_ARRAY_FOR(modp->deviations, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2300 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2301 | yprp_deviation(pctx, &modp->deviations[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2302 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2303 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2304 | YPR_EXTRA_LINE(modp->deviations, pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | LY_ERR |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 2308 | yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2309 | { |
| 2310 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 2311 | const struct lys_module *module = modp->mod; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2312 | struct lys_ypr_ctx pctx_ = { |
| 2313 | .out = out, |
| 2314 | .level = 0, |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2315 | .options = options, |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2316 | .module = module, |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2317 | .schema = LYS_YPR_PARSED |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2318 | }, *pctx = &pctx_; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2319 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2320 | ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2321 | LEVEL++; |
| 2322 | |
| 2323 | /* module-header-stmts */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2324 | if (modp->version) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2325 | ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2326 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2327 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modp->exts); |
| 2328 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2329 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2330 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2331 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2332 | /* linkage-stmts (import/include) */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2333 | yang_print_parsed_linkage(pctx, modp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2334 | |
| 2335 | /* meta-stmts */ |
| 2336 | if (module->org || module->contact || module->dsc || module->ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2337 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2338 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2339 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modp->exts); |
| 2340 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modp->exts); |
| 2341 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modp->exts); |
| 2342 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2343 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2344 | YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2345 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2346 | /* revision-stmts */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2347 | LY_ARRAY_FOR(modp->revs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2348 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2349 | yprp_revision(pctx, &modp->revs[u]); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2350 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2351 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2352 | YPR_EXTRA_LINE(modp->revs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2353 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2354 | /* body-stmts */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2355 | yang_print_parsed_body(pctx, modp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2356 | |
| 2357 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 2358 | ly_print_(out, "%*s}\n", INDENT); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2359 | ly_print_flush(out); |
| 2360 | |
| 2361 | return LY_SUCCESS; |
| 2362 | } |
| 2363 | |
| 2364 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2365 | yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2366 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2367 | ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2368 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2369 | yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2370 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, 0, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2371 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2372 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | LY_ERR |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 2376 | yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2377 | { |
| 2378 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2379 | struct lys_ypr_ctx pctx_ = { |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2380 | .out = out, |
| 2381 | .level = 0, |
| 2382 | .options = options, |
| 2383 | .module = submodp->mod, |
| 2384 | .schema = LYS_YPR_PARSED |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2385 | }, *pctx = &pctx_; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2386 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2387 | ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2388 | LEVEL++; |
| 2389 | |
| 2390 | /* submodule-header-stmts */ |
| 2391 | if (submodp->version) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2392 | ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2393 | } |
| 2394 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2395 | yprp_belongsto(pctx, submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2396 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2397 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2398 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2399 | /* linkage-stmts (import/include) */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2400 | yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2401 | |
| 2402 | /* meta-stmts */ |
| 2403 | if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2404 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2405 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2406 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, 0, submodp->exts); |
| 2407 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, 0, submodp->exts); |
| 2408 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, 0, submodp->exts); |
| 2409 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, 0, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2410 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2411 | YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2412 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2413 | /* revision-stmts */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2414 | LY_ARRAY_FOR(submodp->revs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2415 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2416 | yprp_revision(pctx, &submodp->revs[u]); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2417 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2418 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2419 | YPR_EXTRA_LINE(submodp->revs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2420 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2421 | /* body-stmts */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2422 | yang_print_parsed_body(pctx, (struct lysp_module *)submodp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2423 | |
| 2424 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 2425 | ly_print_(out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2426 | ly_print_flush(out); |
| 2427 | |
| 2428 | return LY_SUCCESS; |
| 2429 | } |
| 2430 | |
| 2431 | LY_ERR |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 2432 | yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options) |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2433 | { |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2434 | struct lys_ypr_ctx pctx_ = { |
| 2435 | .out = out, |
| 2436 | .level = 0, |
| 2437 | .options = options, |
| 2438 | .module = node->module, |
| 2439 | .schema = LYS_YPR_COMPILED |
| 2440 | }, *pctx = &pctx_; |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2441 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2442 | yprc_node(pctx, node); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2443 | |
| 2444 | ly_print_flush(out); |
| 2445 | return LY_SUCCESS; |
| 2446 | } |
| 2447 | |
| 2448 | LY_ERR |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 2449 | yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2450 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 2451 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2452 | struct lysc_module *modc = module->compiled; |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2453 | struct lys_ypr_ctx pctx_ = { |
| 2454 | .out = out, |
| 2455 | .level = 0, |
| 2456 | .options = options, |
| 2457 | .module = module, |
| 2458 | .schema = LYS_YPR_COMPILED |
| 2459 | }, *pctx = &pctx_; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2460 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2461 | ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2462 | LEVEL++; |
| 2463 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2464 | /* module-header-stmts */ |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2465 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modc->exts); |
| 2466 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modc->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2467 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2468 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2469 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2470 | /* no linkage-stmts */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2471 | |
| 2472 | /* meta-stmts */ |
| 2473 | if (module->org || module->contact || module->dsc || module->ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2474 | YPR_EXTRA_LINE_PRINT(pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2475 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2476 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modc->exts); |
| 2477 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modc->exts); |
| 2478 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modc->exts); |
| 2479 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modc->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2480 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2481 | YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2482 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2483 | /* revision-stmts */ |
| 2484 | if (module->revision) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2485 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2486 | ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision); |
| 2487 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | /* body-stmts */ |
| 2491 | if (modc->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2492 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2493 | yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2494 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2495 | } |
| 2496 | |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 2497 | LY_ARRAY_FOR(module->identities, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2498 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2499 | yprc_identity(pctx, &module->identities[u]); |
| 2500 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2501 | } |
| 2502 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2503 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2504 | struct lysc_node *data; |
| 2505 | struct lysc_node_action *rpc; |
| 2506 | struct lysc_node_notif *notif; |
| 2507 | |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2508 | LY_LIST_FOR(modc->data, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2509 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2510 | yprc_node(pctx, data); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2511 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2512 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2513 | YPR_EXTRA_LINE(modc->data, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2514 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2515 | LY_LIST_FOR(modc->rpcs, rpc) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2516 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2517 | yprc_action(pctx, rpc); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2518 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2519 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2520 | YPR_EXTRA_LINE(modc->rpcs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2521 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2522 | LY_LIST_FOR(modc->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2523 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2524 | yprc_notification(pctx, notif); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2525 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2526 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2527 | YPR_EXTRA_LINE(modc->notifs, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 2531 | ly_print_(out, "%*s}\n", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2532 | ly_print_flush(out); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2533 | |
| 2534 | return LY_SUCCESS; |
| 2535 | } |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2536 | |
Michal Vasko | cc28b15 | 2022-08-23 14:44:54 +0200 | [diff] [blame] | 2537 | LIBYANG_API_DEF void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2538 | lyplg_ext_print_info_extension_instance(struct lyspr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag) |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2539 | { |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2540 | struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2541 | LY_ARRAY_COUNT_TYPE u, v; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2542 | ly_bool data_printed = 0; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2543 | |
| 2544 | LY_ARRAY_FOR(ext->substmts, u) { |
| 2545 | switch (ext->substmts[u].stmt) { |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2546 | case LY_STMT_NOTIFICATION: |
| 2547 | case LY_STMT_INPUT: |
| 2548 | case LY_STMT_OUTPUT: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2549 | case LY_STMT_ACTION: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2550 | case LY_STMT_RPC: |
| 2551 | case LY_STMT_ANYDATA: |
| 2552 | case LY_STMT_ANYXML: |
| 2553 | case LY_STMT_CASE: |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2554 | case LY_STMT_CHOICE: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2555 | case LY_STMT_CONTAINER: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2556 | case LY_STMT_LEAF: |
| 2557 | case LY_STMT_LEAF_LIST: |
| 2558 | case LY_STMT_LIST: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2559 | case LY_STMT_USES: { |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2560 | const struct lysc_node *node; |
| 2561 | |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2562 | if (data_printed) { |
| 2563 | break; |
| 2564 | } |
| 2565 | |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2566 | LY_LIST_FOR(*VOIDPTR2_C(ext->substmts[u].storage), node) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2567 | ypr_open(pctx->out, flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2568 | if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2569 | yprc_notification(pctx, (struct lysc_node_notif *)node); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2570 | } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) { |
| 2571 | yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag); |
| 2572 | } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) { |
| 2573 | yprc_action(pctx, (struct lysc_node_action *)node); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2574 | } else { |
| 2575 | yprc_node(pctx, node); |
| 2576 | } |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2577 | } |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2578 | |
| 2579 | /* all data nodes are stored in a linked list so all were printed */ |
| 2580 | data_printed = 1; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2581 | break; |
| 2582 | } |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2583 | case LY_STMT_ARGUMENT: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2584 | case LY_STMT_CONTACT: |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2585 | case LY_STMT_DESCRIPTION: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2586 | case LY_STMT_ERROR_APP_TAG: |
| 2587 | case LY_STMT_ERROR_MESSAGE: |
| 2588 | case LY_STMT_KEY: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2589 | case LY_STMT_MODIFIER: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2590 | case LY_STMT_NAMESPACE: |
| 2591 | case LY_STMT_ORGANIZATION: |
| 2592 | case LY_STMT_PRESENCE: |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2593 | case LY_STMT_REFERENCE: |
| 2594 | case LY_STMT_UNITS: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2595 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 2596 | ypr_open(pctx->out, flag); |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2597 | ypr_substmt(pctx, ext->substmts[u].stmt, 0, *VOIDPTR2_C(ext->substmts[u].storage), 0, ext->exts); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2598 | } |
| 2599 | break; |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2600 | case LY_STMT_BIT: |
| 2601 | case LY_STMT_ENUM: { |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2602 | const struct lysc_type_bitenum_item *items = *VOIDPTR2_C(ext->substmts[u].storage); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2603 | |
| 2604 | yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag); |
| 2605 | break; |
| 2606 | } |
| 2607 | case LY_STMT_CONFIG: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2608 | ypr_config(pctx, *(uint16_t *)VOIDPTR2_C(ext->substmts[u].storage), ext->exts, flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2609 | break; |
| 2610 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2611 | yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, *VOIDPTR2_C(ext->substmts[u].storage), flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2612 | break; |
| 2613 | case LY_STMT_FRACTION_DIGITS: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2614 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
| 2615 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, |
| 2616 | (long unsigned int)*VOIDPTR2_C(ext->substmts[u].storage), flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2617 | } |
| 2618 | break; |
| 2619 | case LY_STMT_IDENTITY: { |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2620 | const struct lysc_ident *idents = *VOIDPTR2_C(ext->substmts[u].storage); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2621 | |
| 2622 | LY_ARRAY_FOR(idents, v) { |
| 2623 | yprc_identity(pctx, &idents[v]); |
| 2624 | } |
| 2625 | break; |
| 2626 | } |
| 2627 | case LY_STMT_LENGTH: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2628 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
| 2629 | yprc_range(pctx, *VOIDPTR2_C(ext->substmts[u].storage), LY_TYPE_STRING, flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2630 | } |
| 2631 | break; |
| 2632 | case LY_STMT_MANDATORY: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2633 | ypr_mandatory(pctx, *(uint16_t *)VOIDPTR_C(ext->substmts[u].storage), ext->exts, flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2634 | break; |
| 2635 | case LY_STMT_MAX_ELEMENTS: { |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2636 | uint32_t max = *(uint32_t *)VOIDPTR_C(ext->substmts[u].storage); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2637 | |
| 2638 | if (max) { |
| 2639 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag); |
| 2640 | } else { |
| 2641 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2642 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, ext->exts); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2643 | } |
| 2644 | break; |
| 2645 | } |
| 2646 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2647 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)VOIDPTR_C(ext->substmts[u].storage), flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2648 | break; |
| 2649 | case LY_STMT_ORDERED_BY: |
| 2650 | ypr_open(pctx->out, flag); |
| 2651 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2652 | ((*(uint16_t *)VOIDPTR_C(ext->substmts[u].storage)) & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2653 | break; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2654 | case LY_STMT_MUST: { |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2655 | const struct lysc_must *musts = *VOIDPTR2_C(ext->substmts[u].storage); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2656 | |
| 2657 | LY_ARRAY_FOR(musts, v) { |
| 2658 | yprc_must(pctx, &musts[v], flag); |
| 2659 | } |
| 2660 | break; |
| 2661 | } |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2662 | case LY_STMT_PATTERN: { |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2663 | const struct lysc_pattern *patterns = *VOIDPTR2_C(ext->substmts[u].storage); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2664 | |
| 2665 | LY_ARRAY_FOR(patterns, v) { |
| 2666 | yprc_pattern(pctx, &patterns[v], flag); |
| 2667 | } |
| 2668 | break; |
| 2669 | } |
| 2670 | case LY_STMT_POSITION: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2671 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
| 2672 | ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)VOIDPTR_C(ext->substmts[u].storage), flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2673 | } |
| 2674 | break; |
| 2675 | case LY_STMT_VALUE: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2676 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
| 2677 | ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)VOIDPTR_C(ext->substmts[u].storage), flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2678 | } |
| 2679 | break; |
| 2680 | case LY_STMT_RANGE: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2681 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
| 2682 | yprc_range(pctx, *VOIDPTR2_C(ext->substmts[u].storage), LY_TYPE_UINT64, flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2683 | } |
| 2684 | break; |
| 2685 | case LY_STMT_REQUIRE_INSTANCE: |
| 2686 | ypr_open(pctx->out, flag); |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2687 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)VOIDPTR_C(ext->substmts[u].storage) ? "true" : "false", |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2688 | 0, ext->exts); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2689 | break; |
| 2690 | case LY_STMT_STATUS: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2691 | ypr_status(pctx, *(uint16_t *)VOIDPTR_C(ext->substmts[u].storage), ext->exts, flag); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2692 | break; |
| 2693 | case LY_STMT_TYPE: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2694 | if (*VOIDPTR2_C(ext->substmts[u].storage)) { |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 2695 | ypr_open(pctx->out, flag); |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2696 | yprc_type(pctx, *VOIDPTR2_C(ext->substmts[u].storage)); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2697 | } |
| 2698 | break; |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2699 | case LY_STMT_WHEN: |
Michal Vasko | 53eb6a1 | 2024-06-13 11:38:47 +0200 | [diff] [blame] | 2700 | yprc_when(pctx, *VOIDPTR2_C(ext->substmts[u].storage), flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2701 | break; |
| 2702 | case LY_STMT_AUGMENT: |
| 2703 | case LY_STMT_BASE: |
| 2704 | case LY_STMT_BELONGS_TO: |
| 2705 | case LY_STMT_DEFAULT: |
| 2706 | case LY_STMT_DEVIATE: |
| 2707 | case LY_STMT_DEVIATION: |
| 2708 | case LY_STMT_EXTENSION: |
| 2709 | case LY_STMT_FEATURE: |
| 2710 | case LY_STMT_GROUPING: |
| 2711 | case LY_STMT_IF_FEATURE: |
| 2712 | case LY_STMT_IMPORT: |
| 2713 | case LY_STMT_INCLUDE: |
| 2714 | case LY_STMT_MODULE: |
| 2715 | case LY_STMT_PATH: |
| 2716 | case LY_STMT_PREFIX: |
| 2717 | case LY_STMT_REFINE: |
| 2718 | case LY_STMT_REVISION: |
| 2719 | case LY_STMT_REVISION_DATE: |
| 2720 | case LY_STMT_SUBMODULE: |
| 2721 | case LY_STMT_TYPEDEF: |
| 2722 | case LY_STMT_UNIQUE: |
| 2723 | case LY_STMT_YANG_VERSION: |
| 2724 | case LY_STMT_YIN_ELEMENT: |
| 2725 | /* nothing to do */ |
| 2726 | break; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2727 | default: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2728 | LOGINT(pctx->module->ctx); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2729 | break; |
| 2730 | } |
| 2731 | } |
| 2732 | } |