#include "common/assert.h"
#include <babeltrace2/trace-ir/field-path-const.h>
#include <limits.h>
+#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include <glib.h>
goto end;
}
- switch (fc->type) {
- case BT_FIELD_CLASS_TYPE_STRUCTURE:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
- {
+ if (bt_field_class_type_is(fc->type, BT_FIELD_CLASS_TYPE_OPTION)) {
+ struct bt_field_class_option *opt_fc = (void *) fc;
+ struct bt_field_path_item item = {
+ .type = BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT,
+ .index = UINT64_C(-1),
+ };
+
+ bt_field_path_append_item(field_path, &item);
+ found = find_field_class_recursive(opt_fc->content_fc,
+ tgt_fc, field_path);
+ if (found) {
+ goto end;
+ }
+
+ bt_field_path_remove_last_item(field_path);
+ } else if (fc->type == BT_FIELD_CLASS_TYPE_STRUCTURE ||
+ bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_VARIANT)) {
struct bt_field_class_named_field_class_container *container_fc =
(void *) fc;
uint64_t i;
bt_field_path_remove_last_item(field_path);
}
-
- break;
- }
- case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
- case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
- {
+ } else if (bt_field_class_type_is(fc->type, BT_FIELD_CLASS_TYPE_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,
}
bt_field_path_remove_last_item(field_path);
- break;
- }
- default:
- break;
}
end:
static
int find_field_class(struct bt_field_class *root_fc,
- enum bt_scope root_scope, struct bt_field_class *tgt_fc,
+ enum bt_field_path_scope root_scope, struct bt_field_class *tgt_fc,
struct bt_field_path **ret_field_path)
{
int ret = 0;
struct bt_field_path *field_path = NULL;
int ret;
- ret = find_field_class(ctx->packet_context, BT_SCOPE_PACKET_CONTEXT,
+ ret = find_field_class(ctx->packet_context, BT_FIELD_PATH_SCOPE_PACKET_CONTEXT,
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);
+ BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT, fc, &field_path);
if (ret || field_path) {
goto end;
}
ret = find_field_class(ctx->event_specific_context,
- BT_SCOPE_EVENT_SPECIFIC_CONTEXT, fc, &field_path);
+ BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT, fc, &field_path);
if (ret || field_path) {
goto end;
}
- ret = find_field_class(ctx->event_payload, BT_SCOPE_EVENT_PAYLOAD,
+ ret = find_field_class(ctx->event_payload, BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD,
fc, &field_path);
if (ret || field_path) {
goto end;
BT_ASSERT_PRE_DEV_FUNC
static inline
struct bt_field_class *borrow_root_field_class(
- struct bt_resolve_field_path_context *ctx, enum bt_scope scope)
+ struct bt_resolve_field_path_context *ctx, enum bt_field_path_scope scope)
{
switch (scope) {
- case BT_SCOPE_PACKET_CONTEXT:
+ case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT:
return ctx->packet_context;
- case BT_SCOPE_EVENT_COMMON_CONTEXT:
+ case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT:
return ctx->event_common_context;
- case BT_SCOPE_EVENT_SPECIFIC_CONTEXT:
+ case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT:
return ctx->event_specific_context;
- case BT_SCOPE_EVENT_PAYLOAD:
+ case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD:
return ctx->event_payload;
default:
- abort();
+ bt_common_abort();
}
return NULL;
{
struct bt_field_class *child_fc = NULL;
- switch (parent_fc->type) {
- case BT_FIELD_CLASS_TYPE_STRUCTURE:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
- {
+ if (bt_field_class_type_is(parent_fc->type,
+ BT_FIELD_CLASS_TYPE_OPTION)) {
+ struct bt_field_class_option *opt_fc = (void *) parent_fc;
+
+ BT_ASSERT(fp_item->type ==
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT);
+ child_fc = opt_fc->content_fc;
+ } else if (parent_fc->type == BT_FIELD_CLASS_TYPE_STRUCTURE ||
+ bt_field_class_type_is(parent_fc->type,
+ BT_FIELD_CLASS_TYPE_VARIANT)) {
struct bt_field_class_named_field_class_container *container_fc =
(void *) parent_fc;
struct bt_named_field_class *named_fc;
BT_ASSERT(fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX);
named_fc = container_fc->named_fcs->pdata[fp_item->index];
child_fc = named_fc->fc;
- break;
- }
- case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
- case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
- {
+ } else if (bt_field_class_type_is(parent_fc->type,
+ BT_FIELD_CLASS_TYPE_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;
- break;
- }
- default:
- break;
}
return child_fc;
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 ||
- fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR ||
- fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
- fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
+ if (bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_ARRAY) ||
+ bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_OPTION) ||
+ bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_VARIANT)) {
is_valid = false;
goto end;
}
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_WITHOUT_SELECTOR ||
- tgt_fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
- tgt_fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
+ if (bt_field_class_type_is(tgt_fc->type,
+ BT_FIELD_CLASS_TYPE_ARRAY) ||
+ bt_field_class_type_is(tgt_fc->type,
+ BT_FIELD_CLASS_TYPE_OPTION) ||
+ bt_field_class_type_is(tgt_fc->type,
+ BT_FIELD_CLASS_TYPE_VARIANT)) {
is_valid = false;
goto end;
}
BT_ASSERT(fc);
/* Resolving part for dynamic array and variant field classes */
- switch (fc->type) {
- case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
- {
- struct bt_field_class_dynamic_array *dyn_array_fc = (void *) fc;
-
- if (dyn_array_fc->length_fc) {
- BT_ASSERT(!dyn_array_fc->length_field_path);
- dyn_array_fc->length_field_path = resolve_field_path(
- fc, dyn_array_fc->length_fc, ctx);
- if (!dyn_array_fc->length_field_path) {
- ret = -1;
- goto end;
- }
+ if (bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD)) {
+ struct bt_field_class_option_with_selector_field *opt_fc = (void *) fc;
+
+ BT_ASSERT(opt_fc->selector_fc);
+ BT_ASSERT(!opt_fc->selector_field_path);
+ opt_fc->selector_field_path = resolve_field_path(
+ fc, opt_fc->selector_fc, ctx);
+ if (!opt_fc->selector_field_path) {
+ ret = -1;
+ goto end;
}
-
- break;
- }
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
- {
- struct bt_field_class_variant_with_selector *var_fc =
+ } else if (fc->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) {
+ struct bt_field_class_array_dynamic *dyn_array_fc = (void *) fc;
+
+ BT_ASSERT(dyn_array_fc->length_fc);
+ BT_ASSERT(!dyn_array_fc->length_field_path);
+ dyn_array_fc->length_field_path = resolve_field_path(
+ fc, dyn_array_fc->length_fc, ctx);
+ if (!dyn_array_fc->length_field_path) {
+ ret = -1;
+ goto end;
+ }
+ } else if (bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD)) {
+ struct bt_field_class_variant_with_selector_field *var_fc =
(void *) fc;
if (var_fc->selector_fc) {
}
}
}
- default:
- break;
- }
/* Recursive part */
- switch (fc->type) {
- case BT_FIELD_CLASS_TYPE_STRUCTURE:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
- case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
- {
+ if (bt_field_class_type_is(fc->type, BT_FIELD_CLASS_TYPE_OPTION)) {
+ struct bt_field_class_option *opt_fc = (void *) fc;
+
+ ret = bt_resolve_field_paths(opt_fc->content_fc, ctx);
+ } else if (fc->type == BT_FIELD_CLASS_TYPE_STRUCTURE ||
+ bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_VARIANT)) {
struct bt_field_class_named_field_class_container *container_fc =
(void *) fc;
uint64_t i;
goto end;
}
}
-
- break;
- }
- case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
- case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
- {
+ } else if (bt_field_class_type_is(fc->type,
+ BT_FIELD_CLASS_TYPE_ARRAY)) {
struct bt_field_class_array *array_fc = (void *) fc;
ret = bt_resolve_field_paths(array_fc->element_fc, ctx);
- break;
- }
- default:
- break;
}
end: