*/
#define BT_LOG_TAG "RESOLVE-FIELD-PATH"
-#include <babeltrace/lib-logging-internal.h>
-
-#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/object.h>
-#include <babeltrace/trace-ir/field-classes-internal.h>
-#include <babeltrace/trace-ir/field-path-internal.h>
-#include <babeltrace/trace-ir/field-path-const.h>
-#include <babeltrace/trace-ir/resolve-field-path-internal.h>
+#include <babeltrace2/lib-logging-internal.h>
+
+#include <babeltrace2/assert-pre-internal.h>
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/trace-ir/field-class-internal.h>
+#include <babeltrace2/trace-ir/field-path-internal.h>
+#include <babeltrace2/trace-ir/field-path-const.h>
+#include <babeltrace2/trace-ir/resolve-field-path-internal.h>
#include <limits.h>
#include <stdint.h>
#include <inttypes.h>
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_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:
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) {
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++;
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:
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;
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:
{
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:
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 ||
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:
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) {
}
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:
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 ||
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: