lib: remove CTF concepts of packet and event headers
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta-translate.c
index e3da926f16f6a0c97a16f12a608d6ee3404b6601..1d318ccf0ddf85b62ef757c2e5dee7d742da6e6c 100644 (file)
 
 #include "ctf-meta-visitors.h"
 
+struct ctx {
+       bt_trace_class *ir_tc;
+       bt_stream_class *ir_sc;
+       struct ctf_trace_class *tc;
+       struct ctf_stream_class *sc;
+       struct ctf_event_class *ec;
+       enum ctf_scope scope;
+};
+
 static inline
-bt_field_class *ctf_field_class_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec);
+bt_field_class *ctf_field_class_to_ir(struct ctx *ctx,
+               struct ctf_field_class *fc);
 
 static inline
 void ctf_field_class_int_set_props(struct ctf_field_class_int *fc,
@@ -43,15 +49,15 @@ void ctf_field_class_int_set_props(struct ctf_field_class_int *fc,
 }
 
 static inline
-bt_field_class *ctf_field_class_int_to_ir(bt_trace_class *ir_tc,
+bt_field_class *ctf_field_class_int_to_ir(struct ctx *ctx,
                struct ctf_field_class_int *fc)
 {
        bt_field_class *ir_fc;
 
        if (fc->is_signed) {
-               ir_fc = bt_field_class_signed_integer_create(ir_tc);
+               ir_fc = bt_field_class_signed_integer_create(ctx->ir_tc);
        } else {
-               ir_fc = bt_field_class_unsigned_integer_create(ir_tc);
+               ir_fc = bt_field_class_unsigned_integer_create(ctx->ir_tc);
        }
 
        BT_ASSERT(ir_fc);
@@ -60,7 +66,7 @@ bt_field_class *ctf_field_class_int_to_ir(bt_trace_class *ir_tc,
 }
 
 static inline
-bt_field_class *ctf_field_class_enum_to_ir(bt_trace_class *ir_tc,
+bt_field_class *ctf_field_class_enum_to_ir(struct ctx *ctx,
                struct ctf_field_class_enum *fc)
 {
        int ret;
@@ -68,9 +74,9 @@ bt_field_class *ctf_field_class_enum_to_ir(bt_trace_class *ir_tc,
        uint64_t i;
 
        if (fc->base.is_signed) {
-               ir_fc = bt_field_class_signed_enumeration_create(ir_tc);
+               ir_fc = bt_field_class_signed_enumeration_create(ctx->ir_tc);
        } else {
-               ir_fc = bt_field_class_unsigned_enumeration_create(ir_tc);
+               ir_fc = bt_field_class_unsigned_enumeration_create(ctx->ir_tc);
        }
 
        BT_ASSERT(ir_fc);
@@ -97,12 +103,12 @@ bt_field_class *ctf_field_class_enum_to_ir(bt_trace_class *ir_tc,
 }
 
 static inline
-bt_field_class *ctf_field_class_float_to_ir(bt_trace_class *ir_tc,
+bt_field_class *ctf_field_class_float_to_ir(struct ctx *ctx,
                struct ctf_field_class_float *fc)
 {
        bt_field_class *ir_fc;
 
-       ir_fc = bt_field_class_real_create(ir_tc);
+       ir_fc = bt_field_class_real_create(ctx->ir_tc);
        BT_ASSERT(ir_fc);
 
        if (fc->base.size == 32) {
@@ -114,58 +120,61 @@ bt_field_class *ctf_field_class_float_to_ir(bt_trace_class *ir_tc,
 }
 
 static inline
-bt_field_class *ctf_field_class_string_to_ir(bt_trace_class *ir_tc,
+bt_field_class *ctf_field_class_string_to_ir(struct ctx *ctx,
                struct ctf_field_class_string *fc)
 {
-       bt_field_class *ir_fc = bt_field_class_string_create(ir_tc);
+       bt_field_class *ir_fc = bt_field_class_string_create(ctx->ir_tc);
 
        BT_ASSERT(ir_fc);
        return ir_fc;
 }
 
 static inline
-bt_field_class *ctf_field_class_struct_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class_struct *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+void translate_struct_field_class_members(struct ctx *ctx,
+               struct ctf_field_class_struct *fc, bt_field_class *ir_fc,
+               bool with_header_prefix,
+               struct ctf_field_class_struct *context_fc)
 {
-       int ret;
-       bt_field_class *ir_fc = bt_field_class_structure_create(ir_tc);
        uint64_t i;
-
-       BT_ASSERT(ir_fc);
+       int ret;
 
        for (i = 0; i < fc->members->len; i++) {
                struct ctf_named_field_class *named_fc =
                        ctf_field_class_struct_borrow_member_by_index(fc, i);
                bt_field_class *member_ir_fc;
+               const char *name = named_fc->name->str;
 
                if (!named_fc->fc->in_ir) {
                        continue;
                }
 
-               member_ir_fc = ctf_field_class_to_ir(ir_tc, named_fc->fc,
-                       tc, sc, ec);
+               member_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc);
                BT_ASSERT(member_ir_fc);
-               ret = bt_field_class_structure_append_member(
-                       ir_fc, named_fc->name->str, member_ir_fc);
+               ret = bt_field_class_structure_append_member(ir_fc, name,
+                       member_ir_fc);
                BT_ASSERT(ret == 0);
                bt_field_class_put_ref(member_ir_fc);
        }
+}
 
+static inline
+bt_field_class *ctf_field_class_struct_to_ir(struct ctx *ctx,
+               struct ctf_field_class_struct *fc)
+{
+       bt_field_class *ir_fc = bt_field_class_structure_create(ctx->ir_tc);
+
+       BT_ASSERT(ir_fc);
+       translate_struct_field_class_members(ctx, fc, ir_fc, false, NULL);
        return ir_fc;
 }
 
 static inline
-bt_field_class *borrow_ir_ft_from_field_path(struct ctf_field_path *field_path,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+bt_field_class *borrow_ir_fc_from_field_path(struct ctx *ctx,
+               struct ctf_field_path *field_path)
 {
        bt_field_class *ir_fc = NULL;
        struct ctf_field_class *fc = ctf_field_path_borrow_field_class(
-               field_path, tc, sc, ec);
+               field_path, ctx->tc, ctx->sc, ctx->ec);
 
        BT_ASSERT(fc);
 
@@ -177,20 +186,22 @@ bt_field_class *borrow_ir_ft_from_field_path(struct ctf_field_path *field_path,
 }
 
 static inline
-bt_field_class *ctf_field_class_variant_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class_variant *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+bt_field_class *ctf_field_class_variant_to_ir(struct ctx *ctx,
+               struct ctf_field_class_variant *fc)
 {
        int ret;
-       bt_field_class *ir_fc = bt_field_class_variant_create(ir_tc);
+       bt_field_class *ir_fc = bt_field_class_variant_create(ctx->ir_tc);
        uint64_t i;
 
        BT_ASSERT(ir_fc);
-       ret = bt_field_class_variant_set_selector_field_class(
-               ir_fc, borrow_ir_ft_from_field_path(&fc->tag_path, tc, sc, ec));
-       BT_ASSERT(ret == 0);
+
+       if (fc->tag_path.root != CTF_SCOPE_PACKET_HEADER &&
+                       fc->tag_path.root != CTF_SCOPE_EVENT_HEADER) {
+               ret = bt_field_class_variant_set_selector_field_class(
+                       ir_fc, borrow_ir_fc_from_field_path(ctx,
+                               &fc->tag_path));
+               BT_ASSERT(ret == 0);
+       }
 
        for (i = 0; i < fc->options->len; i++) {
                struct ctf_named_field_class *named_fc =
@@ -198,8 +209,7 @@ bt_field_class *ctf_field_class_variant_to_ir(bt_trace_class *ir_tc,
                bt_field_class *option_ir_fc;
 
                BT_ASSERT(named_fc->fc->in_ir);
-               option_ir_fc = ctf_field_class_to_ir(ir_tc, named_fc->fc,
-                       tc, sc, ec);
+               option_ir_fc = ctf_field_class_to_ir(ctx, named_fc->fc);
                BT_ASSERT(option_ir_fc);
                ret = bt_field_class_variant_append_option(
                        ir_fc, named_fc->name->str, option_ir_fc);
@@ -211,24 +221,21 @@ bt_field_class *ctf_field_class_variant_to_ir(bt_trace_class *ir_tc,
 }
 
 static inline
-bt_field_class *ctf_field_class_array_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class_array *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+bt_field_class *ctf_field_class_array_to_ir(struct ctx *ctx,
+               struct ctf_field_class_array *fc)
 {
        bt_field_class *ir_fc;
        bt_field_class *elem_ir_fc;
 
        if (fc->base.is_text) {
-               ir_fc = bt_field_class_string_create(ir_tc);
+               ir_fc = bt_field_class_string_create(ctx->ir_tc);
                BT_ASSERT(ir_fc);
                goto end;
        }
 
-       elem_ir_fc = ctf_field_class_to_ir(ir_tc, fc->base.elem_fc, tc, sc, ec);
+       elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc);
        BT_ASSERT(elem_ir_fc);
-       ir_fc = bt_field_class_static_array_create(ir_tc, elem_ir_fc,
+       ir_fc = bt_field_class_static_array_create(ctx->ir_tc, elem_ir_fc,
                fc->length);
        BT_ASSERT(ir_fc);
        bt_field_class_put_ref(elem_ir_fc);
@@ -238,43 +245,40 @@ end:
 }
 
 static inline
-bt_field_class *ctf_field_class_sequence_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class_sequence *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+bt_field_class *ctf_field_class_sequence_to_ir(struct ctx *ctx,
+               struct ctf_field_class_sequence *fc)
 {
        int ret;
        bt_field_class *ir_fc;
        bt_field_class *elem_ir_fc;
 
        if (fc->base.is_text) {
-               ir_fc = bt_field_class_string_create(ir_tc);
+               ir_fc = bt_field_class_string_create(ctx->ir_tc);
                BT_ASSERT(ir_fc);
                goto end;
        }
 
-       elem_ir_fc = ctf_field_class_to_ir(ir_tc, fc->base.elem_fc, tc, sc, ec);
+       elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc);
        BT_ASSERT(elem_ir_fc);
-       ir_fc = bt_field_class_dynamic_array_create(ir_tc, elem_ir_fc);
+       ir_fc = bt_field_class_dynamic_array_create(ctx->ir_tc, elem_ir_fc);
        BT_ASSERT(ir_fc);
        bt_field_class_put_ref(elem_ir_fc);
        BT_ASSERT(ir_fc);
-       ret = bt_field_class_dynamic_array_set_length_field_class(
-               ir_fc,
-               borrow_ir_ft_from_field_path(&fc->length_path, tc, sc, ec));
-       BT_ASSERT(ret == 0);
+
+       if (fc->length_path.root != CTF_SCOPE_PACKET_HEADER &&
+                       fc->length_path.root != CTF_SCOPE_EVENT_HEADER) {
+               ret = bt_field_class_dynamic_array_set_length_field_class(
+                       ir_fc, borrow_ir_fc_from_field_path(ctx, &fc->length_path));
+               BT_ASSERT(ret == 0);
+       }
 
 end:
        return ir_fc;
 }
 
 static inline
-bt_field_class *ctf_field_class_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+bt_field_class *ctf_field_class_to_ir(struct ctx *ctx,
+               struct ctf_field_class *fc)
 {
        bt_field_class *ir_fc = NULL;
 
@@ -283,32 +287,28 @@ bt_field_class *ctf_field_class_to_ir(bt_trace_class *ir_tc,
 
        switch (fc->type) {
        case CTF_FIELD_CLASS_TYPE_INT:
-               ir_fc = ctf_field_class_int_to_ir(ir_tc, (void *) fc);
+               ir_fc = ctf_field_class_int_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_ENUM:
-               ir_fc = ctf_field_class_enum_to_ir(ir_tc, (void *) fc);
+               ir_fc = ctf_field_class_enum_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_FLOAT:
-               ir_fc = ctf_field_class_float_to_ir(ir_tc, (void *) fc);
+               ir_fc = ctf_field_class_float_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_STRING:
-               ir_fc = ctf_field_class_string_to_ir(ir_tc, (void *) fc);
+               ir_fc = ctf_field_class_string_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_STRUCT:
-               ir_fc = ctf_field_class_struct_to_ir(ir_tc, (void *) fc,
-                       tc, sc, ec);
+               ir_fc = ctf_field_class_struct_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_ARRAY:
-               ir_fc = ctf_field_class_array_to_ir(ir_tc, (void *) fc,
-                       tc, sc, ec);
+               ir_fc = ctf_field_class_array_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_SEQUENCE:
-               ir_fc = ctf_field_class_sequence_to_ir(ir_tc, (void *) fc,
-                       tc, sc, ec);
+               ir_fc = ctf_field_class_sequence_to_ir(ctx, (void *) fc);
                break;
        case CTF_FIELD_CLASS_TYPE_VARIANT:
-               ir_fc = ctf_field_class_variant_to_ir(ir_tc, (void *) fc,
-                       tc, sc, ec);
+               ir_fc = ctf_field_class_variant_to_ir(ctx, (void *) fc);
                break;
        default:
                abort();
@@ -340,31 +340,33 @@ end:
 }
 
 static inline
-bt_field_class *scope_ctf_field_class_to_ir(bt_trace_class *ir_tc,
-               struct ctf_field_class *fc,
-               struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc,
-               struct ctf_event_class *ec)
+bt_field_class *scope_ctf_field_class_to_ir(struct ctx *ctx)
 {
        bt_field_class *ir_fc = NULL;
+       struct ctf_field_class *fc = NULL;
 
-       if (!fc) {
-               goto end;
+       switch (ctx->scope) {
+       case CTF_SCOPE_PACKET_CONTEXT:
+               fc = ctx->sc->packet_context_fc;
+               break;
+       case CTF_SCOPE_EVENT_COMMON_CONTEXT:
+               fc = ctx->sc->event_common_context_fc;
+               break;
+       case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
+               fc = ctx->ec->spec_context_fc;
+               break;
+       case CTF_SCOPE_EVENT_PAYLOAD:
+               fc = ctx->ec->payload_fc;
+               break;
+       default:
+               abort();
        }
 
-       BT_ASSERT(fc->type == CTF_FIELD_CLASS_TYPE_STRUCT);
-
-       if (!ctf_field_class_struct_has_immediate_member_in_ir((void *) fc)) {
-               /*
-                * Nothing for IR in this scope: typical for packet
-                * header, packet context, and event header.
-                */
-               goto end;
+       if (fc && ctf_field_class_struct_has_immediate_member_in_ir(
+                       (void *) fc)) {
+               ir_fc = ctf_field_class_to_ir(ctx, fc);
        }
 
-       ir_fc = ctf_field_class_to_ir(ir_tc, fc, tc, sc, ec);
-
-end:
        return ir_fc;
 }
 
@@ -396,177 +398,153 @@ end:
 }
 
 static inline
-bt_event_class *ctf_event_class_to_ir(struct ctf_event_class *ec,
-               bt_stream_class *ir_sc, struct ctf_trace_class *tc,
-               struct ctf_stream_class *sc)
+void ctf_event_class_to_ir(struct ctx *ctx)
 {
        int ret;
        bt_event_class *ir_ec = NULL;
-       bt_trace_class *ir_tc = bt_stream_class_borrow_trace_class(ir_sc);
+       bt_field_class *ir_fc;
 
-       if (ec->is_translated) {
+       BT_ASSERT(ctx->ec);
+
+       if (ctx->ec->is_translated) {
                ir_ec = bt_stream_class_borrow_event_class_by_id(
-                       ir_sc, ec->id);
+                       ctx->ir_sc, ctx->ec->id);
                BT_ASSERT(ir_ec);
                goto end;
        }
 
-       ir_ec = bt_event_class_create_with_id(ir_sc, ec->id);
+       ir_ec = bt_event_class_create_with_id(ctx->ir_sc, ctx->ec->id);
        BT_ASSERT(ir_ec);
        bt_event_class_put_ref(ir_ec);
-
-       if (ec->spec_context_fc) {
-               bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc,
-                       ec->spec_context_fc, tc, sc, ec);
-
-               if (ir_fc) {
-                       ret = bt_event_class_set_specific_context_field_class(
-                               ir_ec, ir_fc);
-                       BT_ASSERT(ret == 0);
-                       bt_field_class_put_ref(ir_fc);
-               }
+       ctx->scope = CTF_SCOPE_EVENT_SPECIFIC_CONTEXT;
+       ir_fc = scope_ctf_field_class_to_ir(ctx);
+       if (ir_fc) {
+               ret = bt_event_class_set_specific_context_field_class(
+                       ir_ec, ir_fc);
+               BT_ASSERT(ret == 0);
+               bt_field_class_put_ref(ir_fc);
        }
 
-       if (ec->payload_fc) {
-               bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc,
-                       ec->payload_fc, tc, sc, ec);
-
-               if (ir_fc) {
-                       ret = bt_event_class_set_payload_field_class(ir_ec,
-                               ir_fc);
-                       BT_ASSERT(ret == 0);
-                       bt_field_class_put_ref(ir_fc);
-               }
+       ctx->scope = CTF_SCOPE_EVENT_PAYLOAD;
+       ir_fc = scope_ctf_field_class_to_ir(ctx);
+       if (ir_fc) {
+               ret = bt_event_class_set_payload_field_class(ir_ec,
+                       ir_fc);
+               BT_ASSERT(ret == 0);
+               bt_field_class_put_ref(ir_fc);
        }
 
-       if (ec->name->len > 0) {
-               ret = bt_event_class_set_name(ir_ec, ec->name->str);
+       if (ctx->ec->name->len > 0) {
+               ret = bt_event_class_set_name(ir_ec, ctx->ec->name->str);
                BT_ASSERT(ret == 0);
        }
 
-       if (ec->emf_uri->len > 0) {
-               ret = bt_event_class_set_emf_uri(ir_ec, ec->emf_uri->str);
+       if (ctx->ec->emf_uri->len > 0) {
+               ret = bt_event_class_set_emf_uri(ir_ec, ctx->ec->emf_uri->str);
                BT_ASSERT(ret == 0);
        }
 
-       if (ec->log_level != -1) {
-               bt_event_class_set_log_level(ir_ec, ec->log_level);
+       if (ctx->ec->log_level != -1) {
+               bt_event_class_set_log_level(ir_ec, ctx->ec->log_level);
        }
 
-       ec->is_translated = true;
-       ec->ir_ec = ir_ec;
+       ctx->ec->is_translated = true;
+       ctx->ec->ir_ec = ir_ec;
 
 end:
-       return ir_ec;
+       return;
 }
 
 
 static inline
-bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
-               bt_trace_class *ir_tc, struct ctf_trace_class *tc)
+void ctf_stream_class_to_ir(struct ctx *ctx)
 {
        int ret;
-       bt_stream_class *ir_sc = NULL;
        struct ctf_field_class_int *int_fc;
+       bt_field_class *ir_fc;
 
-       if (sc->is_translated) {
-               ir_sc = bt_trace_class_borrow_stream_class_by_id(ir_tc, sc->id);
-               BT_ASSERT(ir_sc);
-               goto end;
-       }
-
-       ir_sc = bt_stream_class_create_with_id(ir_tc, sc->id);
-       BT_ASSERT(ir_sc);
-       bt_stream_class_put_ref(ir_sc);
-
-       if (sc->packet_context_fc) {
-               bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc,
-                       sc->packet_context_fc, tc, sc, NULL);
+       BT_ASSERT(ctx->sc);
 
-               if (ir_fc) {
-                       ret = bt_stream_class_set_packet_context_field_class(
-                               ir_sc, ir_fc);
-                       BT_ASSERT(ret == 0);
-                       bt_field_class_put_ref(ir_fc);
-               }
+       if (ctx->sc->is_translated) {
+               ctx->ir_sc = bt_trace_class_borrow_stream_class_by_id(
+                       ctx->ir_tc, ctx->sc->id);
+               BT_ASSERT(ctx->ir_sc);
+               goto end;
        }
 
-       if (sc->event_header_fc) {
-               bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc,
-                       sc->event_header_fc, tc, sc, NULL);
-
-               if (ir_fc) {
-                       ret = bt_stream_class_set_event_header_field_class(
-                               ir_sc, ir_fc);
-                       BT_ASSERT(ret == 0);
-                       bt_field_class_put_ref(ir_fc);
-               }
+       ctx->ir_sc = bt_stream_class_create_with_id(ctx->ir_tc, ctx->sc->id);
+       BT_ASSERT(ctx->ir_sc);
+       bt_stream_class_put_ref(ctx->ir_sc);
+       ctx->scope = CTF_SCOPE_PACKET_CONTEXT;
+       ir_fc = scope_ctf_field_class_to_ir(ctx);
+       if (ir_fc) {
+               ret = bt_stream_class_set_packet_context_field_class(
+                       ctx->ir_sc, ir_fc);
+               BT_ASSERT(ret == 0);
+               bt_field_class_put_ref(ir_fc);
        }
 
-       if (sc->event_common_context_fc) {
-               bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc,
-                       sc->event_common_context_fc, tc, sc, NULL);
-
-               if (ir_fc) {
-                       ret = bt_stream_class_set_event_common_context_field_class(
-                               ir_sc, ir_fc);
-                       BT_ASSERT(ret == 0);
-                       bt_field_class_put_ref(ir_fc);
-               }
+       ctx->scope = CTF_SCOPE_EVENT_COMMON_CONTEXT;
+       ir_fc = scope_ctf_field_class_to_ir(ctx);
+       if (ir_fc) {
+               ret = bt_stream_class_set_event_common_context_field_class(
+                       ctx->ir_sc, ir_fc);
+               BT_ASSERT(ret == 0);
+               bt_field_class_put_ref(ir_fc);
        }
 
-       bt_stream_class_set_assigns_automatic_event_class_id(ir_sc,
+       bt_stream_class_set_assigns_automatic_event_class_id(ctx->ir_sc,
                BT_FALSE);
-       bt_stream_class_set_assigns_automatic_stream_id(ir_sc, BT_FALSE);
+       bt_stream_class_set_assigns_automatic_stream_id(ctx->ir_sc, BT_FALSE);
 
-       if (sc->default_clock_class) {
-               BT_ASSERT(sc->default_clock_class->ir_cc);
-               ret = bt_stream_class_set_default_clock_class(ir_sc,
-                       sc->default_clock_class->ir_cc);
+       if (ctx->sc->default_clock_class) {
+               BT_ASSERT(ctx->sc->default_clock_class->ir_cc);
+               ret = bt_stream_class_set_default_clock_class(ctx->ir_sc,
+                       ctx->sc->default_clock_class->ir_cc);
                BT_ASSERT(ret == 0);
        }
 
-       int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
+       int_fc = borrow_named_int_field_class((void *) ctx->sc->packet_context_fc,
                "events_discarded");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT) {
                        bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
-                               ir_sc, BT_TRUE);
+                               ctx->ir_sc, BT_TRUE);
                }
        }
 
-       int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
+       int_fc = borrow_named_int_field_class((void *) ctx->sc->packet_context_fc,
                "packet_seq_num");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT) {
                        bt_stream_class_set_packets_have_packet_counter_snapshot(
-                               ir_sc, BT_TRUE);
+                               ctx->ir_sc, BT_TRUE);
                }
        }
 
-       int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
+       int_fc = borrow_named_int_field_class((void *) ctx->sc->packet_context_fc,
                "timestamp_begin");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME) {
                        bt_stream_class_set_packets_have_default_beginning_clock_snapshot(
-                               ir_sc, BT_TRUE);
+                               ctx->ir_sc, BT_TRUE);
                }
        }
 
-       int_fc = borrow_named_int_field_class((void *) sc->packet_context_fc,
+       int_fc = borrow_named_int_field_class((void *) ctx->sc->packet_context_fc,
                "timestamp_end");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_END_TIME) {
                        bt_stream_class_set_packets_have_default_end_clock_snapshot(
-                               ir_sc, BT_TRUE);
+                               ctx->ir_sc, BT_TRUE);
                }
        }
 
-       sc->is_translated = true;
-       sc->ir_sc = ir_sc;
+       ctx->sc->is_translated = true;
+       ctx->sc->ir_sc = ctx->ir_sc;
 
 end:
-       return ir_sc;
+       return;
 }
 
 static inline
@@ -596,44 +574,35 @@ void ctf_clock_class_to_ir(bt_clock_class *ir_cc, struct ctf_clock_class *cc)
 }
 
 static inline
-int ctf_trace_class_to_ir(bt_trace_class *ir_tc, struct ctf_trace_class *tc)
+int ctf_trace_class_to_ir(struct ctx *ctx)
 {
        int ret = 0;
        uint64_t i;
 
-       if (tc->is_translated) {
-               goto end;
-       }
-
-       if (tc->packet_header_fc) {
-               bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc,
-                       tc->packet_header_fc, tc, NULL, NULL);
+       BT_ASSERT(ctx->tc);
+       BT_ASSERT(ctx->ir_tc);
 
-               if (ir_fc) {
-                       ret = bt_trace_class_set_packet_header_field_class(
-                               ir_tc, ir_fc);
-                       BT_ASSERT(ret == 0);
-                       bt_field_class_put_ref(ir_fc);
-               }
+       if (ctx->tc->is_translated) {
+               goto end;
        }
 
-       if (tc->is_uuid_set) {
-               bt_trace_class_set_uuid(ir_tc, tc->uuid);
+       if (ctx->tc->is_uuid_set) {
+               bt_trace_class_set_uuid(ctx->ir_tc, ctx->tc->uuid);
        }
 
-       for (i = 0; i < tc->env_entries->len; i++) {
+       for (i = 0; i < ctx->tc->env_entries->len; i++) {
                struct ctf_trace_class_env_entry *env_entry =
-                       ctf_trace_class_borrow_env_entry_by_index(tc, i);
+                       ctf_trace_class_borrow_env_entry_by_index(ctx->tc, i);
 
                switch (env_entry->type) {
                case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT:
                        ret = bt_trace_class_set_environment_entry_integer(
-                               ir_tc, env_entry->name->str,
+                               ctx->ir_tc, env_entry->name->str,
                                env_entry->value.i);
                        break;
                case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR:
                        ret = bt_trace_class_set_environment_entry_string(
-                               ir_tc, env_entry->name->str,
+                               ctx->ir_tc, env_entry->name->str,
                                env_entry->value.str->str);
                        break;
                default:
@@ -645,17 +614,17 @@ int ctf_trace_class_to_ir(bt_trace_class *ir_tc, struct ctf_trace_class *tc)
                }
        }
 
-       for (i = 0; i < tc->clock_classes->len; i++) {
-               struct ctf_clock_class *cc = tc->clock_classes->pdata[i];
+       for (i = 0; i < ctx->tc->clock_classes->len; i++) {
+               struct ctf_clock_class *cc = ctx->tc->clock_classes->pdata[i];
 
-               cc->ir_cc = bt_clock_class_create(ir_tc);
+               cc->ir_cc = bt_clock_class_create(ctx->ir_tc);
                ctf_clock_class_to_ir(cc->ir_cc, cc);
        }
 
-       bt_trace_class_set_assigns_automatic_stream_class_id(ir_tc,
+       bt_trace_class_set_assigns_automatic_stream_class_id(ctx->ir_tc,
                BT_FALSE);
-       tc->is_translated = true;
-       tc->ir_tc = ir_tc;
+       ctx->tc->is_translated = true;
+       ctx->tc->ir_tc = ctx->ir_tc;
 
 end:
        return ret;
@@ -667,33 +636,29 @@ int ctf_trace_class_translate(bt_trace_class *ir_tc,
 {
        int ret = 0;
        uint64_t i;
+       struct ctx ctx = { 0 };
 
-       ret = ctf_trace_class_to_ir(ir_tc, tc);
+       ctx.tc = tc;
+       ctx.ir_tc = ir_tc;
+       ret = ctf_trace_class_to_ir(&ctx);
        if (ret) {
                goto end;
        }
 
        for (i = 0; i < tc->stream_classes->len; i++) {
                uint64_t j;
-               struct ctf_stream_class *sc = tc->stream_classes->pdata[i];
-               bt_stream_class *ir_sc;
+               ctx.sc = tc->stream_classes->pdata[i];
 
-               ir_sc = ctf_stream_class_to_ir(sc, ir_tc, tc);
-               if (!ir_sc) {
-                       ret = -1;
-                       goto end;
-               }
+               ctf_stream_class_to_ir(&ctx);
 
-               for (j = 0; j < sc->event_classes->len; j++) {
-                       struct ctf_event_class *ec = sc->event_classes->pdata[j];
-                       bt_event_class *ir_ec;
+               for (j = 0; j < ctx.sc->event_classes->len; j++) {
+                       ctx.ec = ctx.sc->event_classes->pdata[j];
 
-                       ir_ec = ctf_event_class_to_ir(ec, ir_sc, tc, sc);
-                       if (!ir_ec) {
-                               ret = -1;
-                               goto end;
-                       }
+                       ctf_event_class_to_ir(&ctx);
+                       ctx.ec = NULL;
                }
+
+               ctx.sc = NULL;
        }
 
 end:
This page took 0.038318 seconds and 4 git commands to generate.