tap-driver.sh: flush stdout after each test result
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta-update-in-ir.c
index a765b7c1b0b09244918d1b90827ec39bc2576edc..806a9197368245abde9b665ccd86033d91e75a3d 100644 (file)
 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-IN-IR"
 #include "logging.h"
 
-#include <babeltrace/babeltrace.h>
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/compat/glib-internal.h>
+#include <babeltrace2/babeltrace.h>
+#include <babeltrace2/babeltrace-internal.h>
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/compat/glib-internal.h>
 #include <glib.h>
 #include <stdint.h>
 #include <string.h>
 #include <inttypes.h>
+#include <assert.h>
 
 #include "ctf-meta-visitors.h"
 
+static
+void force_update_field_class_in_ir(struct ctf_field_class *fc, bool in_ir)
+{
+       uint64_t i;
+
+       if (!fc) {
+               goto end;
+       }
+
+       fc->in_ir = in_ir;
+
+       switch (fc->type) {
+       case CTF_FIELD_CLASS_TYPE_STRUCT:
+       {
+               struct ctf_field_class_struct *struct_fc = (void *) fc;
+
+               for (i = 0; i < struct_fc->members->len; i++) {
+                       struct ctf_named_field_class *named_fc =
+                               ctf_field_class_struct_borrow_member_by_index(
+                                       struct_fc, i);
+
+                       force_update_field_class_in_ir(named_fc->fc, in_ir);
+               }
+
+               break;
+       }
+       case CTF_FIELD_CLASS_TYPE_VARIANT:
+       {
+               struct ctf_named_field_class *named_fc;
+               struct ctf_field_class_variant *var_fc = (void *) fc;
+
+               for (i = 0; i < var_fc->options->len; i++) {
+                       named_fc =
+                               ctf_field_class_variant_borrow_option_by_index(
+                                       var_fc, i);
+
+                       force_update_field_class_in_ir(named_fc->fc, in_ir);
+               }
+
+               break;
+       }
+       case CTF_FIELD_CLASS_TYPE_ARRAY:
+       case CTF_FIELD_CLASS_TYPE_SEQUENCE:
+       {
+               struct ctf_field_class_array_base *array_fc = (void *) fc;
+
+               force_update_field_class_in_ir(array_fc->elem_fc, in_ir);
+               break;
+       }
+       default:
+               break;
+       }
+
+end:
+       return;
+}
+
 static
 void update_field_class_in_ir(struct ctf_field_class *fc,
                GHashTable *ft_dependents)
@@ -42,14 +100,16 @@ void update_field_class_in_ir(struct ctf_field_class *fc,
        {
                struct ctf_field_class_int *int_fc = (void *) fc;
 
-               if (int_fc->mapped_clock_class ||
-                               int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE ||
+               /*
+                * Conditions to be in trace IR; one of:
+                *
+                * 1. Does NOT have a mapped clock class AND does not
+                *    have a special meaning.
+                * 2. Another field class depends on it.
+                */
+               if ((!int_fc->mapped_clock_class &&
+                               int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE) ||
                                bt_g_hash_table_contains(ft_dependents, fc)) {
-                       /*
-                        * Field class does not update a clock, has no
-                        * special meaning, and no sequence/variant
-                        * field class which is part of IR depends on it.
-                        */
                        fc->in_ir = true;
                }
 
@@ -59,6 +119,14 @@ void update_field_class_in_ir(struct ctf_field_class *fc,
        {
                struct ctf_field_class_struct *struct_fc = (void *) fc;
 
+               /*
+                * Make it part of IR if it's empty because it was
+                * originally empty.
+                */
+               if (struct_fc->members->len == 0) {
+                       fc->in_ir = true;
+               }
+
                /* Reverse order */
                for (i = (int64_t) struct_fc->members->len - 1; i >= 0; i--) {
                        struct ctf_named_field_class *named_fc =
@@ -208,16 +276,16 @@ int ctf_trace_class_update_in_ir(struct ctf_trace_class *ctf_tc)
                if (!sc->is_translated) {
                        update_field_class_in_ir(sc->event_common_context_fc,
                                ft_dependents);
-                       update_field_class_in_ir(sc->event_header_fc,
-                               ft_dependents);
+                       force_update_field_class_in_ir(sc->event_header_fc,
+                               false);
                        update_field_class_in_ir(sc->packet_context_fc,
                                ft_dependents);
                }
        }
 
        if (!ctf_tc->is_translated) {
-               update_field_class_in_ir(ctf_tc->packet_header_fc,
-                       ft_dependents);
+               force_update_field_class_in_ir(ctf_tc->packet_header_fc,
+                       false);
        }
 
        g_hash_table_destroy(ft_dependents);
This page took 0.024524 seconds and 4 git commands to generate.