lib: add option field classes with integer selectors
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-metadata-field-class-copy.c
index 2b1f4b04bc4617dfef8074e377c777bda5b0935e..c7680c8d962e24733b5d2c43ff8bd5c3affae8ed 100644 (file)
@@ -74,7 +74,10 @@ const bt_field_class *walk_field_path(struct trace_ir_metadata_maps *md_maps,
                                member);
                        break;
                }
-               case BT_FIELD_CLASS_TYPE_OPTION:
+               case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR:
+               case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+               case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+               case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
                {
                        BT_ASSERT(bt_field_path_item_get_type(fp_item) ==
                                BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT);
@@ -321,20 +324,31 @@ error:
 }
 
 static inline
-int field_class_real_copy(
+int field_class_single_precision_real_copy(
                struct trace_ir_metadata_maps *md_maps,
                const bt_field_class *in_field_class,
                bt_field_class *out_field_class)
 {
-       BT_COMP_LOGD("Copying content of real field class: "
-                       "in-fc-addr=%p, out-fc-addr=%p",
-                       in_field_class, out_field_class);
+       BT_COMP_LOGD("Copying content of single-precision real field class: "
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
 
-       bt_field_class_real_set_is_single_precision(out_field_class,
-                       bt_field_class_real_is_single_precision(in_field_class));
+       BT_COMP_LOGD("Copied content single-precision real field class:"
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
 
-       BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, "
-                       "out-fc-addr=%p", in_field_class, out_field_class);
+       return 0;
+}
+
+static inline
+int field_class_double_precision_real_copy(
+               struct trace_ir_metadata_maps *md_maps,
+               const bt_field_class *in_field_class,
+               bt_field_class *out_field_class)
+{
+       BT_COMP_LOGD("Copying content of double-precision real field class: "
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
+
+       BT_COMP_LOGD("Copied content double-precision real field class:"
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
 
        return 0;
 }
@@ -357,32 +371,33 @@ int field_class_structure_copy(
 
        /* Iterate over all the members of the struct. */
        for (i = 0; i < struct_member_count; i++) {
-               const bt_field_class_structure_member *member;
+               const bt_field_class_structure_member *in_member;
+               bt_field_class_structure_member *out_member;
                const char *member_name;
-               const bt_field_class *member_fc;
+               const bt_field_class *in_member_fc;
                bt_field_class *out_member_field_class;
 
-               member = bt_field_class_structure_borrow_member_by_index_const(
+               in_member = bt_field_class_structure_borrow_member_by_index_const(
                        in_field_class, i);
-               member_fc = bt_field_class_structure_member_borrow_field_class_const(
-                       member);
-               member_name = bt_field_class_structure_member_get_name(member);
+               in_member_fc = bt_field_class_structure_member_borrow_field_class_const(
+                       in_member);
+               member_name = bt_field_class_structure_member_get_name(in_member);
                BT_COMP_LOGD("Copying structure field class's field: "
                        "index=%" PRId64 ", "
                        "member-fc-addr=%p, field-name=\"%s\"",
-                       i, member_fc, member_name);
+                       i, in_member_fc, member_name);
 
                out_member_field_class = create_field_class_copy(md_maps,
-                               member_fc);
+                               in_member_fc);
                if (!out_member_field_class) {
                        BT_COMP_LOGE("Cannot copy structure field class's field: "
                                "index=%" PRId64 ", "
                                "field-fc-addr=%p, field-name=\"%s\"",
-                               i, member_fc, member_name);
+                               i, in_member_fc, member_name);
                        ret = -1;
                        goto error;
                }
-               ret = copy_field_class_content(md_maps, member_fc,
+               ret = copy_field_class_content(md_maps, in_member_fc,
                                out_member_field_class);
                if (ret) {
                        goto error;
@@ -394,11 +409,24 @@ int field_class_structure_copy(
                        BT_COMP_LOGE("Cannot append structure field class's field: "
                                "index=%" PRId64 ", "
                                "field-fc-addr=%p, field-name=\"%s\"",
-                               i, member_fc, member_name);
+                               i, in_member_fc, member_name);
                        BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class);
                        ret = -1;
                        goto error;
                }
+
+               out_member = bt_field_class_structure_borrow_member_by_index(
+                       out_field_class, i);
+               BT_ASSERT(out_member);
+
+               /*
+                * Safe to use the same value object because it's frozen
+                * at this point.
+                */
+               bt_field_class_structure_member_set_user_attributes(
+                       out_member,
+                       bt_field_class_structure_member_borrow_user_attributes_const(
+                               in_member));
        }
 
        BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
@@ -425,24 +453,25 @@ int field_class_variant_copy(
        variant_option_count =
                bt_field_class_variant_get_option_count(in_field_class);
        for (i = 0; i < variant_option_count; i++) {
-               const bt_field_class *option_fc;
+               const bt_field_class *in_option_fc;
                const char *option_name;
                bt_field_class *out_option_field_class;
-               const bt_field_class_variant_option *option;
+               const bt_field_class_variant_option *in_option;
+               bt_field_class_variant_option *out_option;
 
-               option = bt_field_class_variant_borrow_option_by_index_const(
+               in_option = bt_field_class_variant_borrow_option_by_index_const(
                        in_field_class, i);
-               option_fc = bt_field_class_variant_option_borrow_field_class_const(
-                       option);
-               option_name = bt_field_class_variant_option_get_name(option);
+               in_option_fc = bt_field_class_variant_option_borrow_field_class_const(
+                       in_option);
+               option_name = bt_field_class_variant_option_get_name(in_option);
                out_option_field_class = create_field_class_copy_internal(
-                               md_maps, option_fc);
+                               md_maps, in_option_fc);
                if (!out_option_field_class) {
                        BT_COMP_LOGE_STR("Cannot copy field class.");
                        ret = -1;
                        goto error;
                }
-               ret = copy_field_class_content_internal(md_maps, option_fc,
+               ret = copy_field_class_content_internal(md_maps, in_option_fc,
                                out_option_field_class);
                if (ret) {
                        BT_COMP_LOGE_STR("Error copying content of option variant "
@@ -497,6 +526,19 @@ int field_class_variant_copy(
                                goto error;
                        }
                }
+
+               out_option = bt_field_class_variant_borrow_option_by_index(
+                       out_field_class, i);
+               BT_ASSERT(out_option);
+
+               /*
+                * Safe to use the same value object because it's frozen
+                * at this point.
+                */
+               bt_field_class_variant_option_set_user_attributes(
+                       out_option,
+                       bt_field_class_variant_option_borrow_user_attributes_const(
+                               in_option));
        }
 
        BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
@@ -554,10 +596,14 @@ int field_class_option_copy(
                        "in-fc-addr=%p, out-fc-addr=%p",
                        in_field_class, out_field_class);
 
-       /*
-        * There is no content to copy. Keep this function call anyway for
-        * logging purposes.
-        */
+       if (bt_field_class_get_type(out_field_class) ==
+                       BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) {
+               bt_field_class_option_with_selector_bool_set_selector_is_reversed(
+                       out_field_class,
+                       bt_field_class_option_with_selector_bool_selector_is_reversed(
+                               in_field_class));
+       }
+
        BT_COMP_LOGD("Copied option field class: in-fc-addr=%p, "
                        "out-fc-addr=%p", in_field_class, out_field_class);
 
@@ -645,8 +691,12 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *
                out_field_class = bt_field_class_enumeration_signed_create(
                                md_maps->output_trace_class);
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               out_field_class = bt_field_class_real_create(
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               out_field_class = bt_field_class_real_single_precision_create(
+                               md_maps->output_trace_class);
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               out_field_class = bt_field_class_real_double_precision_create(
                                md_maps->output_trace_class);
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
@@ -710,14 +760,14 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *
                                out_elem_fc, out_length_fc);
                break;
        }
-       case BT_FIELD_CLASS_TYPE_OPTION:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
        {
                const bt_field_class *in_content_fc =
                        bt_field_class_option_borrow_field_class_const(
                                        in_field_class);
-               const bt_field_path *in_selector_fp =
-                       bt_field_class_option_borrow_selector_field_path_const(
-                               in_field_class);
                bt_field_class *out_selector_fc = NULL;
                bt_field_class *out_content_fc;
                int ret;
@@ -737,20 +787,56 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *
                        goto error;
                }
 
-               if (in_selector_fp) {
-                       const bt_field_class *in_selector_fc =
-                               resolve_field_path_to_field_class(
-                                       in_selector_fp, md_maps);
+               if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR) {
+                       out_field_class =
+                               bt_field_class_option_without_selector_create(
+                                       md_maps->output_trace_class,
+                                       out_content_fc);
+               } else {
+                       const bt_field_path *in_selector_fp =
+                               bt_field_class_option_with_selector_borrow_selector_field_path_const(
+                                       in_field_class);
+                       const bt_field_class *in_selector_fc;
 
+                       BT_ASSERT(in_selector_fp);
+                       in_selector_fc = resolve_field_path_to_field_class(
+                               in_selector_fp, md_maps);
                        BT_ASSERT(in_selector_fc);
                        out_selector_fc = g_hash_table_lookup(
                                md_maps->field_class_map, in_selector_fc);
                        BT_ASSERT(out_selector_fc);
+
+                       if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) {
+                               out_field_class =
+                                       bt_field_class_option_with_selector_bool_create(
+                                               md_maps->output_trace_class,
+                                               out_content_fc, out_selector_fc);
+                       } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR) {
+                               const bt_integer_range_set_unsigned *ranges =
+                                       bt_field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const(
+                                               in_field_class);
+
+                               BT_ASSERT(ranges);
+                               out_field_class =
+                                       bt_field_class_option_with_selector_integer_unsigned_create(
+                                               md_maps->output_trace_class,
+                                               out_content_fc, out_selector_fc,
+                                               ranges);
+                       } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR) {
+                               const bt_integer_range_set_signed *ranges =
+                                       bt_field_class_option_with_selector_integer_signed_borrow_selector_ranges_const(
+                                               in_field_class);
+
+                               BT_ASSERT(ranges);
+                               out_field_class =
+                                       bt_field_class_option_with_selector_integer_signed_create(
+                                               md_maps->output_trace_class,
+                                               out_content_fc, out_selector_fc,
+                                               ranges);
+                       }
                }
 
-               out_field_class = bt_field_class_option_create(
-                               md_maps->output_trace_class,
-                               out_content_fc, out_selector_fc);
+               BT_ASSERT(out_field_class);
                break;
        }
        case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
@@ -810,6 +896,14 @@ int copy_field_class_content_internal(
                bt_field_class *out_field_class)
 {
        int ret = 0;
+
+       /*
+        * Safe to use the same value object because it's frozen at this
+        * point.
+        */
+       bt_field_class_set_user_attributes(out_field_class,
+               bt_field_class_borrow_user_attributes_const(in_field_class));
+
        switch(bt_field_class_get_type(in_field_class)) {
        case BT_FIELD_CLASS_TYPE_BOOL:
                ret = field_class_bool_copy(md_maps,
@@ -835,8 +929,12 @@ int copy_field_class_content_internal(
                ret = field_class_signed_enumeration_copy(md_maps,
                                in_field_class, out_field_class);
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               ret = field_class_real_copy(md_maps,
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               ret = field_class_single_precision_real_copy(md_maps,
+                               in_field_class, out_field_class);
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               ret = field_class_double_precision_real_copy(md_maps,
                                in_field_class, out_field_class);
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
@@ -855,7 +953,10 @@ int copy_field_class_content_internal(
                ret = field_class_dynamic_array_copy(md_maps,
                                in_field_class, out_field_class);
                break;
-       case BT_FIELD_CLASS_TYPE_OPTION:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR:
                ret = field_class_option_copy(md_maps,
                                in_field_class, out_field_class);
                break;
This page took 0.030436 seconds and 4 git commands to generate.