X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Fresolve-field-path.c;h=1f7b5cd240858296459cb0f17a17b65ddab82697;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=b86109952d06bac3494f07b381d5cf0f94909d36;hpb=5cd6d0e5fa67c2bdd21dc153313618260595d7bc;p=babeltrace.git diff --git a/lib/trace-ir/resolve-field-path.c b/lib/trace-ir/resolve-field-path.c index b8610995..1f7b5cd2 100644 --- a/lib/trace-ir/resolve-field-path.c +++ b/lib/trace-ir/resolve-field-path.c @@ -21,14 +21,14 @@ */ #define BT_LOG_TAG "RESOLVE-FIELD-PATH" -#include - -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include #include #include #include @@ -45,9 +45,9 @@ bool find_field_class_recursive(struct bt_field_class *fc, goto end; } - switch (fc->id) { - case BT_FIELD_CLASS_ID_STRUCTURE: - case BT_FIELD_CLASS_ID_VARIANT: + switch (fc->type) { + case BT_FIELD_CLASS_TYPE_STRUCTURE: + case BT_FIELD_CLASS_TYPE_VARIANT: { struct bt_field_class_named_field_class_container *container_fc = (void *) fc; @@ -57,27 +57,40 @@ bool find_field_class_recursive(struct bt_field_class *fc, struct bt_named_field_class *named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX( container_fc, i); + struct bt_field_path_item item = { + .type = BT_FIELD_PATH_ITEM_TYPE_INDEX, + .index = i, + }; - g_array_append_val(field_path->indexes, i); + bt_field_path_append_item(field_path, &item); found = find_field_class_recursive(named_fc->fc, tgt_fc, field_path); if (found) { goto end; } - g_array_set_size(field_path->indexes, - field_path->indexes->len - 1); + bt_field_path_remove_last_item(field_path); } break; } - case BT_FIELD_CLASS_ID_STATIC_ARRAY: - case BT_FIELD_CLASS_ID_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: { struct bt_field_class_array *array_fc = (void *) fc; + struct bt_field_path_item item = { + .type = BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT, + .index = UINT64_C(-1), + }; + bt_field_path_append_item(field_path, &item); found = find_field_class_recursive(array_fc->element_fc, tgt_fc, field_path); + if (found) { + goto end; + } + + bt_field_path_remove_last_item(field_path); break; } default: @@ -109,7 +122,7 @@ int find_field_class(struct bt_field_class *root_fc, field_path->root = root_scope; if (!find_field_class_recursive(root_fc, tgt_fc, field_path)) { /* Not found here */ - BT_PUT(field_path); + BT_OBJECT_PUT_REF_AND_RESET(field_path); } end: @@ -124,24 +137,12 @@ struct bt_field_path *find_field_class_in_ctx(struct bt_field_class *fc, struct bt_field_path *field_path = NULL; int ret; - ret = find_field_class(ctx->packet_header, BT_SCOPE_PACKET_HEADER, - fc, &field_path); - if (ret || field_path) { - goto end; - } - ret = find_field_class(ctx->packet_context, BT_SCOPE_PACKET_CONTEXT, fc, &field_path); if (ret || field_path) { goto end; } - ret = find_field_class(ctx->event_header, BT_SCOPE_EVENT_HEADER, - fc, &field_path); - if (ret || field_path) { - goto end; - } - ret = find_field_class(ctx->event_common_context, BT_SCOPE_EVENT_COMMON_CONTEXT, fc, &field_path); if (ret || field_path) { @@ -183,16 +184,21 @@ bool target_is_before_source(struct bt_field_path *src_field_path, BT_ASSERT(tgt_field_path->root == src_field_path->root); - while (src_i < src_field_path->indexes->len && - tgt_i < tgt_field_path->indexes->len) { - uint64_t src_index = bt_field_path_get_index_by_index_inline( - src_field_path, src_i); - uint64_t tgt_index = bt_field_path_get_index_by_index_inline( - tgt_field_path, tgt_i); - - if (tgt_index > src_index) { - is_valid = false; - goto end; + for (src_i = 0, tgt_i = 0; src_i < src_field_path->items->len && + tgt_i < tgt_field_path->items->len; src_i++, tgt_i++) { + struct bt_field_path_item *src_fp_item = + bt_field_path_borrow_item_by_index_inline( + src_field_path, src_i); + struct bt_field_path_item *tgt_fp_item = + bt_field_path_borrow_item_by_index_inline( + tgt_field_path, tgt_i); + + if (src_fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX && + tgt_fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX) { + if (tgt_fp_item->index > src_fp_item->index) { + is_valid = false; + goto end; + } } src_i++; @@ -209,12 +215,8 @@ struct bt_field_class *borrow_root_field_class( struct bt_resolve_field_path_context *ctx, enum bt_scope scope) { switch (scope) { - case BT_SCOPE_PACKET_HEADER: - return ctx->packet_header; case BT_SCOPE_PACKET_CONTEXT: return ctx->packet_context; - case BT_SCOPE_EVENT_HEADER: - return ctx->event_header; case BT_SCOPE_EVENT_COMMON_CONTEXT: return ctx->event_common_context; case BT_SCOPE_EVENT_SPECIFIC_CONTEXT: @@ -230,29 +232,32 @@ struct bt_field_class *borrow_root_field_class( BT_ASSERT_PRE_FUNC static inline -struct bt_field_class *borrow_child_field_class(struct bt_field_class *parent_fc, - uint64_t index, bool *advance) +struct bt_field_class *borrow_child_field_class( + struct bt_field_class *parent_fc, + struct bt_field_path_item *fp_item) { struct bt_field_class *child_fc = NULL; - switch (parent_fc->id) { - case BT_FIELD_CLASS_ID_STRUCTURE: - case BT_FIELD_CLASS_ID_VARIANT: + switch (parent_fc->type) { + case BT_FIELD_CLASS_TYPE_STRUCTURE: + case BT_FIELD_CLASS_TYPE_VARIANT: { - struct bt_named_field_class *named_fc = - BT_FIELD_CLASS_NAMED_FC_AT_INDEX(parent_fc, index); + struct bt_named_field_class *named_fc; + BT_ASSERT(fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX); + named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(parent_fc, + fp_item->index); child_fc = named_fc->fc; - *advance = true; break; } - case BT_FIELD_CLASS_ID_STATIC_ARRAY: - case BT_FIELD_CLASS_ID_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: { struct bt_field_class_array *array_fc = (void *) parent_fc; + BT_ASSERT(fp_item->type == + BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT); child_fc = array_fc->element_fc; - *advance = false; break; } default: @@ -279,23 +284,20 @@ bool target_field_path_in_different_scope_has_struct_fc_only( fc = borrow_root_field_class(ctx, tgt_field_path->root); - while (i < tgt_field_path->indexes->len) { - uint64_t index = bt_field_path_get_index_by_index_inline( - tgt_field_path, i); - bool advance; + for (i = 0; i < tgt_field_path->items->len; i++) { + struct bt_field_path_item *fp_item = + bt_field_path_borrow_item_by_index_inline( + tgt_field_path, i); - if (fc->id == BT_FIELD_CLASS_ID_STATIC_ARRAY || - fc->id == BT_FIELD_CLASS_ID_DYNAMIC_ARRAY || - fc->id == BT_FIELD_CLASS_ID_VARIANT) { + if (fc->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || + fc->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY || + fc->type == BT_FIELD_CLASS_TYPE_VARIANT) { is_valid = false; goto end; } - fc = borrow_child_field_class(fc, index, &advance); - - if (advance) { - i++; - } + BT_ASSERT(fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX); + fc = borrow_child_field_class(fc, fp_item); } end: @@ -323,25 +325,26 @@ bool lca_is_structure_field_class(struct bt_field_path *src_field_path, BT_ASSERT(src_fc); BT_ASSERT(tgt_fc); - while (src_i < src_field_path->indexes->len && - tgt_i < tgt_field_path->indexes->len) { - bool advance; - uint64_t src_index = bt_field_path_get_index_by_index_inline( - src_field_path, src_i); - uint64_t tgt_index = bt_field_path_get_index_by_index_inline( - tgt_field_path, tgt_i); + for (src_i = 0, tgt_i = 0; src_i < src_field_path->items->len && + tgt_i < tgt_field_path->items->len; src_i++, tgt_i++) { + struct bt_field_path_item *src_fp_item = + bt_field_path_borrow_item_by_index_inline( + src_field_path, src_i); + struct bt_field_path_item *tgt_fp_item = + bt_field_path_borrow_item_by_index_inline( + tgt_field_path, tgt_i); if (src_fc != tgt_fc) { if (!prev_fc) { /* * This is correct: the LCA is the root - * scope field classe, which must be a - * structure field classe. + * scope field class, which must be a + * structure field class. */ break; } - if (prev_fc->id != BT_FIELD_CLASS_ID_STRUCTURE) { + if (prev_fc->type != BT_FIELD_CLASS_TYPE_STRUCTURE) { is_valid = false; } @@ -349,17 +352,8 @@ bool lca_is_structure_field_class(struct bt_field_path *src_field_path, } prev_fc = src_fc; - src_fc = borrow_child_field_class(src_fc, src_index, &advance); - - if (advance) { - src_i++; - } - - tgt_fc = borrow_child_field_class(tgt_fc, tgt_index, &advance); - - if (advance) { - tgt_i++; - } + src_fc = borrow_child_field_class(src_fc, src_fp_item); + tgt_fc = borrow_child_field_class(tgt_fc, tgt_fp_item); } end: @@ -388,50 +382,38 @@ bool lca_to_target_has_struct_fc_only(struct bt_field_path *src_field_path, BT_ASSERT(src_fc == tgt_fc); /* Find LCA */ - while (src_i < src_field_path->indexes->len && - tgt_i < tgt_field_path->indexes->len) { - bool advance; - uint64_t src_index = bt_field_path_get_index_by_index_inline( - src_field_path, src_i); - uint64_t tgt_index = bt_field_path_get_index_by_index_inline( - tgt_field_path, tgt_i); + for (src_i = 0, tgt_i = 0; src_i < src_field_path->items->len && + tgt_i < tgt_field_path->items->len; src_i++, tgt_i++) { + struct bt_field_path_item *src_fp_item = + bt_field_path_borrow_item_by_index_inline( + src_field_path, src_i); + struct bt_field_path_item *tgt_fp_item = + bt_field_path_borrow_item_by_index_inline( + tgt_field_path, tgt_i); if (src_i != tgt_i) { /* Next field class is different: LCA is `tgt_fc` */ break; } - src_fc = borrow_child_field_class(src_fc, src_index, &advance); - - if (advance) { - src_i++; - } - - tgt_fc = borrow_child_field_class(tgt_fc, tgt_index, &advance); - - if (advance) { - tgt_i++; - } + src_fc = borrow_child_field_class(src_fc, src_fp_item); + tgt_fc = borrow_child_field_class(tgt_fc, tgt_fp_item); } /* Only structure field classes to the target */ - while (tgt_i < tgt_field_path->indexes->len) { - bool advance; - uint64_t tgt_index = bt_field_path_get_index_by_index_inline( - tgt_field_path, tgt_i); - - if (tgt_fc->id == BT_FIELD_CLASS_ID_STATIC_ARRAY || - tgt_fc->id == BT_FIELD_CLASS_ID_DYNAMIC_ARRAY || - tgt_fc->id == BT_FIELD_CLASS_ID_VARIANT) { + for (; tgt_i < tgt_field_path->items->len; tgt_i++) { + struct bt_field_path_item *tgt_fp_item = + bt_field_path_borrow_item_by_index_inline( + tgt_field_path, tgt_i); + + if (tgt_fc->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || + tgt_fc->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY || + tgt_fc->type == BT_FIELD_CLASS_TYPE_VARIANT) { is_valid = false; goto end; } - tgt_fc = borrow_child_field_class(tgt_fc, tgt_index, &advance); - - if (advance) { - tgt_i++; - } + tgt_fc = borrow_child_field_class(tgt_fc, tgt_fp_item); } end: @@ -451,14 +433,14 @@ bool field_path_is_valid(struct bt_field_class *src_fc, tgt_fc, ctx); if (!src_field_path) { - BT_ASSERT_PRE_MSG("Cannot find requesting field classe in " + BT_ASSERT_PRE_MSG("Cannot find requesting field class in " "resolving context: %!+F", src_fc); is_valid = false; goto end; } if (!tgt_field_path) { - BT_ASSERT_PRE_MSG("Cannot find target field classe in " + BT_ASSERT_PRE_MSG("Cannot find target field class in " "resolving context: %!+F", tgt_fc); is_valid = false; goto end; @@ -466,8 +448,8 @@ bool field_path_is_valid(struct bt_field_class *src_fc, /* Target must be before source */ if (!target_is_before_source(src_field_path, tgt_field_path)) { - BT_ASSERT_PRE_MSG("Target field classe is located after " - "requesting field classe: %![req-fc-]+F, %![tgt-fc-]+F", + BT_ASSERT_PRE_MSG("Target field class is located after " + "requesting field class: %![req-fc-]+F, %![tgt-fc-]+F", src_fc, tgt_fc); is_valid = false; goto end; @@ -479,19 +461,19 @@ bool field_path_is_valid(struct bt_field_class *src_fc, */ if (!target_field_path_in_different_scope_has_struct_fc_only( src_field_path, tgt_field_path, ctx)) { - BT_ASSERT_PRE_MSG("Target field classe is located in a " - "different scope than requesting field classe, " - "but within an array or a variant field classe: " + BT_ASSERT_PRE_MSG("Target field class is located in a " + "different scope than requesting field class, " + "but within an array or a variant field class: " "%![req-fc-]+F, %![tgt-fc-]+F", src_fc, tgt_fc); is_valid = false; goto end; } - /* Same scope: LCA must be a structure field classe */ + /* Same scope: LCA must be a structure field class */ if (!lca_is_structure_field_class(src_field_path, tgt_field_path, ctx)) { BT_ASSERT_PRE_MSG("Lowest common ancestor of target and " - "requesting field classes is not a structure field classe: " + "requesting field classes is not a structure field class: " "%![req-fc-]+F, %![tgt-fc-]+F", src_fc, tgt_fc); is_valid = false; @@ -502,16 +484,16 @@ bool field_path_is_valid(struct bt_field_class *src_fc, if (!lca_to_target_has_struct_fc_only(src_field_path, tgt_field_path, ctx)) { BT_ASSERT_PRE_MSG("Path from lowest common ancestor of target " - "and requesting field classes to target field classe " - "contains an array or a variant field classe: " + "and requesting field classes to target field class " + "contains an array or a variant field class: " "%![req-fc-]+F, %![tgt-fc-]+F", src_fc, tgt_fc); is_valid = false; goto end; } end: - bt_put(src_field_path); - bt_put(tgt_field_path); + bt_object_put_ref(src_field_path); + bt_object_put_ref(tgt_field_path); return is_valid; } @@ -521,7 +503,7 @@ struct bt_field_path *resolve_field_path(struct bt_field_class *src_fc, struct bt_resolve_field_path_context *ctx) { BT_ASSERT_PRE(field_path_is_valid(src_fc, tgt_fc, ctx), - "Invalid target field classe: %![req-fc-]+F, %![tgt-fc-]+F", + "Invalid target field class: %![req-fc-]+F, %![tgt-fc-]+F", src_fc, tgt_fc); return find_field_class_in_ctx(tgt_fc, ctx); } @@ -535,8 +517,8 @@ int bt_resolve_field_paths(struct bt_field_class *fc, BT_ASSERT(fc); /* Resolving part for dynamic array and variant field classes */ - switch (fc->id) { - case BT_FIELD_CLASS_ID_DYNAMIC_ARRAY: + switch (fc->type) { + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: { struct bt_field_class_dynamic_array *dyn_array_fc = (void *) fc; @@ -552,7 +534,7 @@ int bt_resolve_field_paths(struct bt_field_class *fc, break; } - case BT_FIELD_CLASS_ID_VARIANT: + case BT_FIELD_CLASS_TYPE_VARIANT: { struct bt_field_class_variant *var_fc = (void *) fc; @@ -572,9 +554,9 @@ int bt_resolve_field_paths(struct bt_field_class *fc, } /* Recursive part */ - switch (fc->id) { - case BT_FIELD_CLASS_ID_STRUCTURE: - case BT_FIELD_CLASS_ID_VARIANT: + switch (fc->type) { + case BT_FIELD_CLASS_TYPE_STRUCTURE: + case BT_FIELD_CLASS_TYPE_VARIANT: { struct bt_field_class_named_field_class_container *container_fc = (void *) fc; @@ -593,8 +575,8 @@ int bt_resolve_field_paths(struct bt_field_class *fc, break; } - case BT_FIELD_CLASS_ID_STATIC_ARRAY: - case BT_FIELD_CLASS_ID_DYNAMIC_ARRAY: + case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: + case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: { struct bt_field_class_array *array_fc = (void *) fc;