X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Fresolve-field-path.c;h=1f7b5cd240858296459cb0f17a17b65ddab82697;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=1b690be76a790e5dfa9bb1d906f6462e7232671a;hpb=e5be10efe4d5543ba697c7e607ca0a5c33fa3ccb;p=babeltrace.git diff --git a/lib/trace-ir/resolve-field-path.c b/lib/trace-ir/resolve-field-path.c index 1b690be7..1f7b5cd2 100644 --- a/lib/trace-ir/resolve-field-path.c +++ b/lib/trace-ir/resolve-field-path.c @@ -21,15 +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 #include @@ -58,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; @@ -76,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: @@ -125,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) { @@ -184,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++; @@ -210,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: @@ -231,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; @@ -240,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: @@ -252,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: @@ -280,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 || @@ -292,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: @@ -324,20 +325,21 @@ 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; } @@ -350,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: @@ -389,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 || @@ -428,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: @@ -452,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; @@ -467,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; @@ -480,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; @@ -503,8 +484,8 @@ 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; @@ -522,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); }