Skip to content

Commit 101658e

Browse files
committed
libyang CHANGE refactor flag names and attributes holding them
1 parent eecc6a4 commit 101658e

File tree

11 files changed

+38
-36
lines changed

11 files changed

+38
-36
lines changed

src/parser.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
14881488
/* fully clear the value */
14891489
if (store) {
14901490
lyd_free_value(*val, *val_type, *val_flags, type);
1491-
*val_flags &= ~LYTYPE_UNRES;
1491+
*val_flags &= ~LY_VALUE_UNRES;
14921492
}
14931493

14941494
switch (type->base) {
@@ -1902,7 +1902,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
19021902
/* note that the data node is an unresolved instance-identifier */
19031903
val->instance = NULL;
19041904
*val_type = LY_TYPE_INST;
1905-
*val_flags |= LYTYPE_UNRES;
1905+
*val_flags |= LY_VALUE_UNRES;
19061906
}
19071907

19081908
if (!ly_strequal(value, *value_, 1)) {
@@ -1942,7 +1942,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
19421942

19431943
if (store) {
19441944
/* make the note that the data node is an unresolved leafref (value union was already filled) */
1945-
*val_flags |= LYTYPE_UNRES;
1945+
*val_flags |= LY_VALUE_UNRES;
19461946
}
19471947

19481948
type = t;
@@ -2182,7 +2182,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
21822182
if (c == -1) {
21832183
return NULL;
21842184
} else if (!c) {
2185-
*val_flags |= LYTYPE_USER;
2185+
*val_flags |= LY_VALUE_USER;
21862186
}
21872187
}
21882188

src/parser_yang.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_
673673
lydict_remove(ctx, module_name);
674674
lydict_remove(ctx, value);
675675

676-
if (type->flags & LYTYPE_GRP) {
676+
if (type->value_flags & LY_VALUE_UNRESGRP) {
677677
/* resolved type in grouping, decrease the grouping's nacm number to indicate that one less
678678
* unresolved item left inside the grouping, LYTYPE_GRP used as a flag for types inside a grouping. */
679679
for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter));
@@ -684,7 +684,7 @@ yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_
684684
LOGINT(ctx);
685685
goto error;
686686
}
687-
type->flags &= ~LYTYPE_GRP;
687+
type->value_flags &= ~LY_VALUE_UNRESGRP;
688688
}
689689

690690
/* check status */

src/parser_yin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_e
584584
lydict_remove(ctx, module_name);
585585
lydict_remove(ctx, value);
586586

587-
if (type->flags & LYTYPE_GRP) {
587+
if (type->value_flags & LY_VALUE_UNRESGRP) {
588588
/* resolved type in grouping, decrease the grouping's nacm number to indicate that one less
589589
* unresolved item left inside the grouping, LYTYPE_GRP used as a flag for types inside a grouping. */
590590
for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter));
@@ -595,7 +595,7 @@ fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_e
595595
LOGINT(ctx);
596596
goto error;
597597
}
598-
type->flags &= ~LYTYPE_GRP;
598+
type->value_flags &= ~LY_VALUE_UNRESGRP;
599599
}
600600
type->base = type->der->type.base;
601601

src/resolve.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6841,7 +6841,7 @@ resolve_unres_schema_item(struct lys_module *mod, void *item, enum UNRES_ITEM ty
68416841
return -1;
68426842
}
68436843
}
6844-
} else if (rc == EXIT_FAILURE && !(stype->flags & LYTYPE_GRP)) {
6844+
} else if (rc == EXIT_FAILURE && !(stype->value_flags & LY_VALUE_UNRESGRP)) {
68456845
/* forward reference - in case the type is in grouping, we have to make the grouping unusable
68466846
* by uses statement until the type is resolved. We do that the same way as uses statements inside
68476847
* grouping. The grouping cannot be used unless the unres counter is 0.
@@ -6853,7 +6853,7 @@ resolve_unres_schema_item(struct lys_module *mod, void *item, enum UNRES_ITEM ty
68536853
LOGERR(ctx, LY_EINT, "Too many unresolved items (type) inside a grouping.");
68546854
return -1;
68556855
}
6856-
stype->flags |= LYTYPE_GRP;
6856+
stype->value_flags |= LY_VALUE_UNRESGRP;
68576857
}
68586858
}
68596859
break;
@@ -7864,7 +7864,7 @@ resolve_union(struct lyd_node_leaf_list *leaf, struct lys_type *type, int store,
78647864

78657865
assert(type->base == LY_TYPE_UNION);
78667866

7867-
if ((leaf->value_type == LY_TYPE_UNION) || ((leaf->value_type == LY_TYPE_INST) && (leaf->value_flags & LYTYPE_UNRES))) {
7867+
if ((leaf->value_type == LY_TYPE_UNION) || ((leaf->value_type == LY_TYPE_INST) && (leaf->value_flags & LY_VALUE_UNRES))) {
78687868
/* either NULL or instid previously converted to JSON */
78697869
json_val = lydict_insert(ctx, leaf->value.string, 0);
78707870
}
@@ -7939,7 +7939,7 @@ resolve_union(struct lyd_node_leaf_list *leaf, struct lys_type *type, int store,
79397939
leaf->value.instance = NULL;
79407940
}
79417941
leaf->value_type = LY_TYPE_INST;
7942-
leaf->value_flags |= LYTYPE_UNRES;
7942+
leaf->value_flags |= LY_VALUE_UNRES;
79437943
}
79447944
}
79457945

@@ -8030,10 +8030,10 @@ resolve_unres_data_item(struct lyd_node *node, enum UNRES_ITEM type, int ignore_
80308030
}
80318031
leaf->value.leafref = ret;
80328032
leaf->value_type = LY_TYPE_LEAFREF;
8033-
leaf->value_flags &= ~LYTYPE_UNRES;
8033+
leaf->value_flags &= ~LY_VALUE_UNRES;
80348034
} else {
80358035
/* valid unresolved */
8036-
if (!(leaf->value_flags & LYTYPE_UNRES)) {
8036+
if (!(leaf->value_flags & LY_VALUE_UNRES)) {
80378037
if (!lyp_parse_value(&sleaf->type, &leaf->value_str, NULL, leaf, NULL, NULL, 1, 0, 0)) {
80388038
return -1;
80398039
}
@@ -8063,12 +8063,12 @@ resolve_unres_data_item(struct lyd_node *node, enum UNRES_ITEM type, int ignore_
80638063
/* valid resolved */
80648064
leaf->value.instance = ret;
80658065
leaf->value_type = LY_TYPE_INST;
8066-
leaf->value_flags &= ~LYTYPE_UNRES;
8066+
leaf->value_flags &= ~LY_VALUE_UNRES;
80678067
} else {
80688068
/* valid unresolved */
80698069
leaf->value.instance = NULL;
80708070
leaf->value_type = LY_TYPE_INST;
8071-
leaf->value_flags |= LYTYPE_UNRES;
8071+
leaf->value_flags |= LY_VALUE_UNRES;
80728072
}
80738073
} else {
80748074
return rc;

src/tree_data.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ check_leaf_list_backlinks(struct lyd_node *node, int op)
12911291
for (j = 0; j < data->number; j++) {
12921292
leaf_list = (struct lyd_node_leaf_list *)data->set.d[j];
12931293
if (((op != 0) && (leaf_list->value_type == LY_TYPE_LEAFREF) && (leaf_list->value.leafref == iter))
1294-
|| ((op != 1) && (leaf_list->value_flags & LYTYPE_UNRES))) {
1294+
|| ((op != 1) && (leaf_list->value_flags & LY_VALUE_UNRES))) {
12951295
/* invalidate the leafref, a change concerning it happened */
12961296
leaf_list->validity |= LYD_VAL_LEAFREF;
12971297
validity_changed = 1;
@@ -5354,7 +5354,7 @@ lyd_dup_to_ctx(const struct lyd_node *node, int recursive, struct ly_ctx *ctx)
53545354
if (r == -1) {
53555355
goto error;
53565356
} else if (!r) {
5357-
new_leaf->value_flags |= LYTYPE_USER;
5357+
new_leaf->value_flags |= LY_VALUE_USER;
53585358
}
53595359
}
53605360
break;
@@ -5675,7 +5675,7 @@ lyd_insert_attr(struct lyd_node *parent, const struct lys_module *mod, const cha
56755675
void
56765676
lyd_free_value(lyd_val value, LY_DATA_TYPE value_type, uint8_t value_flags, struct lys_type *type)
56775677
{
5678-
if (value_flags & LYTYPE_USER) {
5678+
if (value_flags & LY_VALUE_USER) {
56795679
assert(type->der && type->der->module);
56805680
lytype_free(type->der->module, type->der->name, value);
56815681
} else {
@@ -5686,7 +5686,7 @@ lyd_free_value(lyd_val value, LY_DATA_TYPE value_type, uint8_t value_flags, stru
56865686
}
56875687
break;
56885688
case LY_TYPE_INST:
5689-
if (!(value_flags & LYTYPE_UNRES)) {
5689+
if (!(value_flags & LY_VALUE_UNRES)) {
56905690
break;
56915691
}
56925692
/* fallthrough */

src/tree_data.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct lyd_attr {
125125
const char *value_str; /**< string representation of value (for comparison, printing,...), always corresponds to value_type */
126126
lyd_val value; /**< node's value representation, always corresponds to schema->type.base */
127127
LY_DATA_TYPE _PACKED value_type; /**< type of the value in the node, mainly for union to avoid repeating of type detection */
128-
uint8_t value_flags; /**< type flags */
128+
uint8_t value_flags; /**< value type flags */
129129
};
130130

131131
/**
@@ -227,9 +227,18 @@ struct lyd_node_leaf_list {
227227
const char *value_str; /**< string representation of value (for comparison, printing,...), always corresponds to value_type */
228228
lyd_val value; /**< node's value representation, always corresponds to schema->type.base */
229229
LY_DATA_TYPE _PACKED value_type; /**< type of the value in the node, mainly for union to avoid repeating of type detection */
230-
uint8_t value_flags; /**< type flags */
230+
uint8_t value_flags; /**< value type flags */
231231
};
232232

233+
/**
234+
* @brief Flags for values
235+
*/
236+
#define LY_VALUE_UNRES 0x01 /**< flag for unresolved leafref or instance-identifier,
237+
leafref - value union is filled as if being the target node's type,
238+
instance-identifier - value union should not be accessed */
239+
#define LY_VALUE_USER 0x02 /**< flag for a user type stored value */
240+
/* 0x80 is reserveed for internal use */
241+
233242
/**
234243
* @brief Structure for data nodes defined as #LYS_ANYDATA or #LYS_ANYXML.
235244
*

src/tree_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct lyd_node_pos {
8080
/**
8181
* @brief Type flag for an unresolved type in a grouping.
8282
*/
83-
#define LYTYPE_GRP 0x80
83+
#define LY_VALUE_UNRESGRP 0x80
8484

8585
#ifdef LY_ENABLED_CACHE
8686

src/tree_schema.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Radek Krejci <[email protected]>
44
* @brief libyang representation of data model trees.
55
*
6-
* Copyright (c) 2015 CESNET, z.s.p.o.
6+
* Copyright (c) 2015 - 2018 CESNET, z.s.p.o.
77
*
88
* This source code is licensed under BSD 3-Clause License (the "License").
99
* You may not use this file except in compliance with the License.
@@ -838,13 +838,6 @@ typedef enum {
838838
} LY_DATA_TYPE;
839839
#define LY_DATA_TYPE_COUNT 20 /**< Number of different types */
840840

841-
/* type flags */
842-
#define LYTYPE_UNRES 0x01 /**< flag for unresolved leafref or instance-identifier,
843-
leafref - value union is filled as if being the target node's type,
844-
instance-identifier - value union should not be accessed */
845-
#define LYTYPE_USER 0x02 /**< flag for a user type stored value */
846-
/* 0x80 is reserved for internal use */
847-
848841
/**
849842
*
850843
*/
@@ -1011,7 +1004,7 @@ union lys_type_info {
10111004
*/
10121005
struct lys_type {
10131006
LY_DATA_TYPE _PACKED base; /**< base type */
1014-
uint8_t flags; /**< type flags */
1007+
uint8_t value_flags; /**< value type flags */
10151008
uint8_t ext_size; /**< number of elements in #ext array */
10161009
struct lys_ext_instance **ext; /**< array of pointers to the extension instances */
10171010
struct lys_tpdf *der; /**< pointer to the superior typedef. If NULL,

src/validation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ find_orig_type(struct lys_type *par_type, LY_DATA_TYPE base_type)
446446
if (type->base == base_type) {
447447
/* we have the result */
448448
return type;
449-
} else if ((type->base == LY_TYPE_LEAFREF) && !(type->flags & LYTYPE_UNRES)) {
449+
} else if ((type->base == LY_TYPE_LEAFREF) && !(type->value_flags & LY_VALUE_UNRES)) {
450450
/* go through the leafref */
451451
assert(type->info.lref.target);
452452
return find_orig_type(&((struct lys_node_leaf *)type->info.lref.target)->type, base_type);

src/xpath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3375,7 +3375,7 @@ xpath_deref(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyd_node
33753375
sleaf = (struct lys_node_leaf *)leaf->schema;
33763376
if ((sleaf->nodetype & (LYS_LEAF | LYS_LEAFLIST))
33773377
&& ((sleaf->type.base == LY_TYPE_LEAFREF) || (sleaf->type.base == LY_TYPE_INST))) {
3378-
if (leaf->value_flags & LYTYPE_UNRES) {
3378+
if (leaf->value_flags & LY_VALUE_UNRES) {
33793379
/* this is bad */
33803380
LOGVAL(local_mod->ctx, LYE_SPEC, LY_VLOG_LYD, args[0]->val.nodes[0].node,
33813381
"Trying to dereference an unresolved leafref or instance-identifier.");

0 commit comments

Comments
 (0)