diff --git a/src/parser_yang.c b/src/parser_yang.c index 7238e0762..b7e2cedda 100644 --- a/src/parser_yang.c +++ b/src/parser_yang.c @@ -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) { @@ -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"); @@ -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; @@ -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 */ diff --git a/tests/utests/basic/test_plugins.c b/tests/utests/basic/test_plugins.c index d36fa7d16..6bcf1daa2 100644 --- a/tests/utests/basic/test_plugins.c +++ b/tests/utests/basic/test_plugins.c @@ -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;" " }" " }" @@ -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) { @@ -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; }