X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Fresolve-field-path.c;h=1f7b5cd240858296459cb0f17a17b65ddab82697;hb=3fadfbc0c91f82c46bd36e6e0657ea93570c9db1;hp=00ec6447b49fd9f00e75ac814a21bb44a6271180;hpb=c5b9b4417bedfbec9b5dd23b8395ccdd4eeffc44;p=babeltrace.git diff --git a/lib/trace-ir/resolve-field-path.c b/lib/trace-ir/resolve-field-path.c index 00ec6447..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 @@ -57,16 +57,19 @@ 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; @@ -75,9 +78,19 @@ bool find_field_class_recursive(struct bt_field_class *fc, 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: @@ -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,8 +232,9 @@ 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; @@ -239,11 +242,12 @@ struct bt_field_class *borrow_child_field_class(struct bt_field_class *parent_fc 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_TYPE_STATIC_ARRAY: @@ -251,8 +255,9 @@ struct bt_field_class *borrow_child_field_class(struct bt_field_class *parent_fc { 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,10 +284,10 @@ 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->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || fc->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY || @@ -291,11 +296,8 @@ bool target_field_path_in_different_scope_has_struct_fc_only( 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,13 +325,14 @@ 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) { @@ -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,37 +382,29 @@ 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); + 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 || @@ -427,11 +413,7 @@ bool lca_to_target_has_struct_fc_only(struct bt_field_path *src_field_path, 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: