Skip to content

Commit f47f357

Browse files
committed
schema compile UPDATE identityref derived type without bases
Some refactoring included.
1 parent d605c1d commit f47f357

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/schema_compile_node.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,9 +1814,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
18141814

18151815
LY_CHECK_GOTO(rc = lys_compile_type_enums(ctx, base_type_p->bits, basetype, NULL,
18161816
(struct lysc_type_bitenum_item **)&bits->bits), cleanup);
1817-
} /* else error */
1818-
1819-
if (!base && !type_p->flags) {
1817+
} else {
18201818
/* type derived from bits built-in type must contain at least one bit */
18211819
if (tpdfname) {
18221820
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "bit", "bits type ", tpdfname);
@@ -1914,9 +1912,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
19141912
assert(base_type_p);
19151913

19161914
LY_CHECK_GOTO(rc = lys_compile_type_enums(ctx, base_type_p->enums, basetype, NULL, &enumeration->enums), cleanup);
1917-
} /* else error */
1918-
1919-
if (!base && !type_p->flags) {
1915+
} else {
19201916
/* type derived from enumerations built-in type must contain at least one enum */
19211917
if (tpdfname) {
19221918
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "enum", "enumeration type ", tpdfname);
@@ -1965,9 +1961,17 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
19651961
goto cleanup;
19661962
}
19671963
LY_CHECK_GOTO(rc = lys_compile_identity_bases(ctx, type_p->pmod, type_p->bases, NULL, &idref->bases), cleanup);
1968-
}
1964+
} else if (base) {
1965+
/* copy all the bases */
1966+
const struct lysc_type_identityref *idref_base = (struct lysc_type_identityref *)base;
1967+
LY_ARRAY_COUNT_TYPE u;
19691968

1970-
if (!base && !type_p->flags) {
1969+
LY_ARRAY_CREATE_GOTO(ctx->ctx, idref->bases, LY_ARRAY_COUNT(idref_base->bases), rc, cleanup);
1970+
LY_ARRAY_FOR(idref_base->bases, u) {
1971+
idref->bases[u] = idref_base->bases[u];
1972+
LY_ARRAY_INCREMENT(idref->bases);
1973+
}
1974+
} else {
19711975
/* type derived from identityref built-in type must contain at least one base */
19721976
if (tpdfname) {
19731977
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "base", "identityref type ", tpdfname);
@@ -2012,12 +2016,13 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
20122016
LY_CHECK_GOTO(rc = lyxp_expr_dup(ctx->ctx, ((struct lysc_type_leafref *)base)->path, 0, 0, &lref->path), cleanup);
20132017
LY_CHECK_GOTO(rc = lyplg_type_prefix_data_dup(ctx->ctx, LY_VALUE_SCHEMA_RESOLVED,
20142018
((struct lysc_type_leafref *)base)->prefixes, (void **)&lref->prefixes), cleanup);
2015-
} else if (tpdfname) {
2016-
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "path", "leafref type ", tpdfname);
2017-
rc = LY_EVALID;
2018-
goto cleanup;
20192019
} else {
2020-
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "path", "leafref type", "");
2020+
/* type derived from leafref built-in type must contain path */
2021+
if (tpdfname) {
2022+
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "path", "leafref type ", tpdfname);
2023+
} else {
2024+
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "path", "leafref type", "");
2025+
}
20212026
rc = LY_EVALID;
20222027
goto cleanup;
20232028
}
@@ -2063,9 +2068,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
20632068
LY_ATOMIC_INC_BARRIER(un->types[u]->refcount);
20642069
LY_ARRAY_INCREMENT(un->types);
20652070
}
2066-
}
2067-
2068-
if (!base && !type_p->flags) {
2071+
} else {
20692072
/* type derived from union built-in type must contain at least one type */
20702073
if (tpdfname) {
20712074
LOGVAL(ctx->ctx, LY_VCODE_MISSCHILDSTMT, "type", "union type ", tpdfname);

0 commit comments

Comments
 (0)