Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/parser_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -1937,9 +1937,17 @@ parse_type_enum(struct lysp_yang_ctx *ctx, enum ly_stmt enum_kw, struct lysp_typ
size_t word_len;
enum ly_stmt kw;
struct lysp_type_enum *enm;
LY_ARRAY_COUNT_TYPE u, v;

LY_ARRAY_NEW_RET(PARSER_CTX(ctx), *enums, enm, LY_EMEM);

/* revalidate the backward parent pointers from extensions */
LY_ARRAY_FOR(*enums, u) {
LY_ARRAY_FOR((*enums)[u].exts, v) {
(*enums)[u].exts[v].parent = &(*enums)[u];
}
}

/* get value */
LY_CHECK_RET(get_argument(ctx, enum_kw == LY_STMT_ENUM ? Y_STR_ARG : Y_IDENTIF_ARG, NULL, &word, &buf, &word_len));
if (enum_kw == LY_STMT_ENUM) {
Expand Down Expand Up @@ -2246,6 +2254,7 @@ parse_type(struct lysp_yang_ctx *ctx, struct lysp_type *type)
size_t word_len;
enum ly_stmt kw;
struct lysp_type *nest_type;
LY_ARRAY_COUNT_TYPE u, v;

if (type->name) {
LOGVAL_PARSER(ctx, LY_VCODE_DUPSTMT, "type");
Expand Down Expand Up @@ -2329,6 +2338,12 @@ parse_type(struct lysp_yang_ctx *ctx, struct lysp_type *type)
break;
case LY_STMT_TYPE:
LY_ARRAY_NEW_RET(PARSER_CTX(ctx), type->types, nest_type, LY_EMEM);
/* revalidate the backward parent pointers from extensions */
LY_ARRAY_FOR(type->types, u) {
LY_ARRAY_FOR((type->types)[u].exts, v) {
(type->types)[u].exts[v].parent = &(type->types)[u];
}
}
LY_CHECK_RET(parse_type(ctx, nest_type));
type->flags |= LYS_SET_TYPE;
break;
Expand Down Expand Up @@ -2809,6 +2824,9 @@ parse_typedef(struct lysp_yang_ctx *ctx, struct lysp_node *parent, struct lysp_t
LY_ARRAY_FOR((*typedefs)[u].exts, v) {
(*typedefs)[u].exts[v].parent = &(*typedefs)[u];
}
LY_ARRAY_FOR((*typedefs)[u].type.exts, v) {
(*typedefs)[u].type.exts[v].parent = &(*typedefs)[u].type;
}
}

/* get value */
Expand Down
24 changes: 22 additions & 2 deletions tests/utests/basic/test_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@ const char *simple = "module libyang-plugins-simple {"
" type s:note {length 255;}"
" s:hint \"some hint here\";"
" }"
" leaf enum1 {"
" type enumeration {"
" enum val1 {s:rt;}"
" enum val2 {s:rt;}"
" }"
" }"
" leaf u1 {"
" type union {"
" type string {s:rt;}"
" type int8 {s:rt;}"
" }"
" }"
" grouping grp1 {"
" list l1 {key v; leaf v {type string;} leaf k {type string;}}"
" list l2 {key v; leaf v {type string;} leaf k {type string;}}"
" typedef t1 {"
" type string;"
" type string {s:rt;}"
" s:rt;"
" }"
" typedef t2 {"
" type string;"
" type string {s:rt;}"
" s:rt;"
" }"
" }"
Expand Down Expand Up @@ -132,6 +144,8 @@ parse_clb2(struct lysp_ctx *UNUSED(pctx), struct lysp_ext_instance *ext)
{
struct lysp_refine *refine;
struct lysp_tpdf *tpdf;
struct lysp_type_enum *en;
struct lysp_type *type;
LY_ARRAY_COUNT_TYPE count = 0;

if (ext->parent_stmt == LY_STMT_REFINE) {
Expand All @@ -140,6 +154,12 @@ parse_clb2(struct lysp_ctx *UNUSED(pctx), struct lysp_ext_instance *ext)
} else if (ext->parent_stmt == LY_STMT_TYPEDEF) {
tpdf = (struct lysp_tpdf *)ext->parent;
count = LY_ARRAY_COUNT(tpdf->exts);
} else if (ext->parent_stmt == LY_STMT_ENUM) {
en = (struct lysp_type_enum *)ext->parent;
count = LY_ARRAY_COUNT(en->exts);
} else if (ext->parent_stmt == LY_STMT_TYPE) {
type = (struct lysp_type *)ext->parent;
count = LY_ARRAY_COUNT(type->exts);
} else {
return LY_SUCCESS;
}
Expand Down