- int ret = 0;
- struct fs_sink_ctf_field_class *tgt_fc = NULL;
- uint64_t i;
- int64_t si;
- const char *tgt_fc_name = NULL;
- struct field_path_elem *field_path_elem;
-
- /* Get target field class's name */
- switch (bt_field_path_get_root_scope(tgt_ir_field_path)) {
- case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT:
- BT_ASSERT(ctx->cur_sc);
- tgt_fc = ctx->cur_sc->packet_context_fc;
- break;
- case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT:
- BT_ASSERT(ctx->cur_sc);
- tgt_fc = ctx->cur_sc->event_common_context_fc;
- break;
- case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT:
- BT_ASSERT(ctx->cur_ec);
- tgt_fc = ctx->cur_ec->spec_context_fc;
- break;
- case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD:
- BT_ASSERT(ctx->cur_ec);
- tgt_fc = ctx->cur_ec->payload_fc;
- break;
- default:
- bt_common_abort();
- }
-
- i = 0;
-
- while (i < bt_field_path_get_item_count(tgt_ir_field_path)) {
- const bt_field_path_item *fp_item =
- bt_field_path_borrow_item_by_index_const(
- tgt_ir_field_path, i);
- struct fs_sink_ctf_named_field_class *named_fc = NULL;
-
- BT_ASSERT(tgt_fc);
- BT_ASSERT(fp_item);
-
- if (bt_field_path_item_get_type(fp_item) ==
- BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT) {
- /* Not supported by CTF 1.8 */
- ret = -1;
- goto end;
- }
-
- switch (tgt_fc->type) {
- case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
- BT_ASSERT(bt_field_path_item_get_type(fp_item) ==
- BT_FIELD_PATH_ITEM_TYPE_INDEX);
- named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_index(
- fs_sink_ctf_field_class_as_struct(tgt_fc),
- bt_field_path_item_index_get_index(fp_item));
- break;
- case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
- BT_ASSERT(bt_field_path_item_get_type(fp_item) ==
- BT_FIELD_PATH_ITEM_TYPE_INDEX);
- named_fc = fs_sink_ctf_field_class_variant_borrow_option_by_index(
- fs_sink_ctf_field_class_as_variant(tgt_fc),
- bt_field_path_item_index_get_index(fp_item));
- break;
- case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
- case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
- {
- struct fs_sink_ctf_field_class_array_base *array_base_fc =
- fs_sink_ctf_field_class_as_array_base(tgt_fc);
-
- BT_ASSERT(bt_field_path_item_get_type(fp_item) ==
- BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT);
- tgt_fc = array_base_fc->elem_fc;
- break;
- }
- default:
- bt_common_abort();
- }
-
- if (named_fc) {
- tgt_fc = named_fc->fc;
- tgt_fc_name = named_fc->name->str;
- i++;
- }
- }
-
- BT_ASSERT(tgt_fc);
- BT_ASSERT(tgt_fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
- BT_ASSERT(tgt_fc_name);
-
- /* Find target field class having this name in current context */
- for (si = ctx->cur_path->len - 1; si >= 0; si--) {
- struct fs_sink_ctf_field_class *fc;
- struct fs_sink_ctf_field_class_struct *struct_fc = NULL;
- struct fs_sink_ctf_field_class_variant *var_fc = NULL;
- struct fs_sink_ctf_named_field_class *named_fc;
- uint64_t len;
-
- field_path_elem = cur_path_stack_at(ctx, (uint64_t) si);
- fc = field_path_elem->parent_fc;
- if (!fc) {
- /* Reached stack's bottom */
- ret = -1;
- goto end;
- }
-
- switch (fc->type) {
- case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
- case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
- break;
- case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
- case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
- continue;
- default:
- /* Not supported by TSDL 1.8 */
- ret = -1;
- goto end;
- }
-
- if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) {
- struct_fc = fs_sink_ctf_field_class_as_struct(fc);
- len = struct_fc->members->len;
- } else {
- var_fc = fs_sink_ctf_field_class_as_variant(fc);
- len = var_fc->options->len;
- }
-
- for (i = 0; i < len; i++) {
- if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) {
- named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_index(
- struct_fc, i);
- } else {
- named_fc = fs_sink_ctf_field_class_variant_borrow_option_by_index(
- var_fc, i);
- }
-
- if (strcmp(named_fc->name->str, tgt_fc_name) == 0) {
- if (named_fc->fc == tgt_fc) {
- g_string_assign(tgt_field_ref,
- tgt_fc_name);
-
- if (user_tgt_fc) {
- *user_tgt_fc = tgt_fc;
- }
- } else {
- /*
- * Using only the target field
- * class's name, we're not
- * reaching the target field
- * class. This is not supported
- * by TSDL 1.8.
- */
- ret = -1;
- }
-
- goto end;
- }
- }
- }
+ int ret = 0;
+ struct fs_sink_ctf_field_class *tgt_fc = NULL;
+ uint64_t i;
+ int64_t si;
+ const char *tgt_fc_name = NULL;
+ struct field_path_elem *field_path_elem;
+
+ /* Get target field class's name */
+ switch (bt_field_path_get_root_scope(tgt_ir_field_path)) {
+ case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT:
+ BT_ASSERT(ctx->cur_sc);
+ tgt_fc = ctx->cur_sc->packet_context_fc;
+ break;
+ case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT:
+ BT_ASSERT(ctx->cur_sc);
+ tgt_fc = ctx->cur_sc->event_common_context_fc;
+ break;
+ case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT:
+ BT_ASSERT(ctx->cur_ec);
+ tgt_fc = ctx->cur_ec->spec_context_fc;
+ break;
+ case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD:
+ BT_ASSERT(ctx->cur_ec);
+ tgt_fc = ctx->cur_ec->payload_fc;
+ break;
+ default:
+ bt_common_abort();
+ }
+
+ i = 0;
+
+ while (i < bt_field_path_get_item_count(tgt_ir_field_path)) {
+ const bt_field_path_item *fp_item =
+ bt_field_path_borrow_item_by_index_const(tgt_ir_field_path, i);
+ struct fs_sink_ctf_named_field_class *named_fc = NULL;
+
+ BT_ASSERT(tgt_fc);
+ BT_ASSERT(fp_item);
+
+ if (bt_field_path_item_get_type(fp_item) ==
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT) {
+ /* Not supported by CTF 1.8 */
+ ret = -1;
+ goto end;
+ }
+
+ switch (tgt_fc->type) {
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
+ BT_ASSERT(bt_field_path_item_get_type(fp_item) == BT_FIELD_PATH_ITEM_TYPE_INDEX);
+ named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_index(
+ fs_sink_ctf_field_class_as_struct(tgt_fc),
+ bt_field_path_item_index_get_index(fp_item));
+ break;
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
+ BT_ASSERT(bt_field_path_item_get_type(fp_item) == BT_FIELD_PATH_ITEM_TYPE_INDEX);
+ named_fc = fs_sink_ctf_field_class_variant_borrow_option_by_index(
+ fs_sink_ctf_field_class_as_variant(tgt_fc),
+ bt_field_path_item_index_get_index(fp_item));
+ break;
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
+ {
+ struct fs_sink_ctf_field_class_array_base *array_base_fc =
+ fs_sink_ctf_field_class_as_array_base(tgt_fc);
+
+ BT_ASSERT(bt_field_path_item_get_type(fp_item) ==
+ BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT);
+ tgt_fc = array_base_fc->elem_fc;
+ break;
+ }
+ default:
+ bt_common_abort();
+ }
+
+ if (named_fc) {
+ tgt_fc = named_fc->fc;
+ tgt_fc_name = named_fc->name->str;
+ i++;
+ }
+ }
+
+ BT_ASSERT(tgt_fc);
+ BT_ASSERT(tgt_fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_INT);
+ BT_ASSERT(tgt_fc_name);
+
+ /* Find target field class having this name in current context */
+ for (si = ctx->cur_path->len - 1; si >= 0; si--) {
+ struct fs_sink_ctf_field_class *fc;
+ struct fs_sink_ctf_field_class_struct *struct_fc = NULL;
+ struct fs_sink_ctf_field_class_variant *var_fc = NULL;
+ struct fs_sink_ctf_named_field_class *named_fc;
+ uint64_t len;
+
+ field_path_elem = cur_path_stack_at(ctx, (uint64_t) si);
+ fc = field_path_elem->parent_fc;
+ if (!fc) {
+ /* Reached stack's bottom */
+ ret = -1;
+ goto end;
+ }
+
+ switch (fc->type) {
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT:
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
+ break;
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY:
+ case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
+ continue;
+ default:
+ /* Not supported by TSDL 1.8 */
+ ret = -1;
+ goto end;
+ }
+
+ if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) {
+ struct_fc = fs_sink_ctf_field_class_as_struct(fc);
+ len = struct_fc->members->len;
+ } else {
+ var_fc = fs_sink_ctf_field_class_as_variant(fc);
+ len = var_fc->options->len;
+ }
+
+ for (i = 0; i < len; i++) {
+ if (fc->type == FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT) {
+ named_fc = fs_sink_ctf_field_class_struct_borrow_member_by_index(struct_fc, i);
+ } else {
+ named_fc = fs_sink_ctf_field_class_variant_borrow_option_by_index(var_fc, i);
+ }
+
+ if (strcmp(named_fc->name->str, tgt_fc_name) == 0) {
+ if (named_fc->fc == tgt_fc) {
+ g_string_assign(tgt_field_ref, tgt_fc_name);
+
+ if (user_tgt_fc) {
+ *user_tgt_fc = tgt_fc;
+ }
+ } else {
+ /*
+ * Using only the target field
+ * class's name, we're not
+ * reaching the target field
+ * class. This is not supported
+ * by TSDL 1.8.
+ */
+ ret = -1;
+ }
+
+ goto end;
+ }
+ }
+ }