Always evaluate BT_ASSERT(); add BT_ASSERT_DBG() for debug mode only
[babeltrace.git] / src / plugins / ctf / fs-sink / fs-sink-ctf-meta.h
index 19912afb7b5aa2ad1bbdfb6026c01e0fe787fa0a..063fb03a66c73a0f7758931e275e90e6adfa5782 100644 (file)
 #include <ctype.h>
 
 enum fs_sink_ctf_field_class_type {
+       FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL,
+       FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY,
        FS_SINK_CTF_FIELD_CLASS_TYPE_INT,
        FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
        FS_SINK_CTF_FIELD_CLASS_TYPE_STRING,
        FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT,
        FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY,
        FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE,
+       FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION,
        FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT,
 };
 
@@ -52,6 +55,10 @@ struct fs_sink_ctf_field_class_bit_array {
        unsigned int size;
 };
 
+struct fs_sink_ctf_field_class_bool {
+       struct fs_sink_ctf_field_class_bit_array base;
+};
+
 struct fs_sink_ctf_field_class_int {
        struct fs_sink_ctf_field_class_bit_array base;
        bool is_signed;
@@ -79,6 +86,12 @@ struct fs_sink_ctf_field_class_struct {
        GArray *members;
 };
 
+struct fs_sink_ctf_field_class_option {
+       struct fs_sink_ctf_field_class base;
+       struct fs_sink_ctf_field_class *content_fc;
+       GString *tag_ref;
+};
+
 struct fs_sink_ctf_field_class_variant {
        struct fs_sink_ctf_field_class base;
        GString *tag_ref;
@@ -208,8 +221,8 @@ void _fs_sink_ctf_field_class_int_init(struct fs_sink_ctf_field_class_int *fc,
                (unsigned int) bt_field_class_integer_get_field_value_range(
                        ir_fc),
                index_in_parent);
-       fc->is_signed = (ir_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
-               ir_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
+       fc->is_signed = bt_field_class_type_is(ir_fc_type,
+               BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
 }
 
 static inline
@@ -236,6 +249,41 @@ void _fs_sink_ctf_named_field_class_fini(
        named_fc->fc = NULL;
 }
 
+static inline
+struct fs_sink_ctf_field_class_bit_array *
+fs_sink_ctf_field_class_bit_array_create(
+               const bt_field_class *ir_fc, uint64_t index_in_parent)
+{
+       struct fs_sink_ctf_field_class_bit_array *fc =
+               g_new0(struct fs_sink_ctf_field_class_bit_array, 1);
+
+       BT_ASSERT(fc);
+       _fs_sink_ctf_field_class_bit_array_init((void *) fc,
+               FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY, ir_fc,
+               (unsigned int) bt_field_class_bit_array_get_length(ir_fc),
+               index_in_parent);
+       return fc;
+}
+
+static inline
+struct fs_sink_ctf_field_class_bool *fs_sink_ctf_field_class_bool_create(
+               const bt_field_class *ir_fc, uint64_t index_in_parent)
+{
+       struct fs_sink_ctf_field_class_bool *fc =
+               g_new0(struct fs_sink_ctf_field_class_bool, 1);
+
+       BT_ASSERT(fc);
+
+       /*
+        * CTF 1.8 has no boolean field class type, so this component
+        * translates it to an 8-bit unsigned integer field class.
+        */
+       _fs_sink_ctf_field_class_bit_array_init((void *) fc,
+               FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL, ir_fc,
+               8, index_in_parent);
+       return fc;
+}
+
 static inline
 struct fs_sink_ctf_field_class_int *fs_sink_ctf_field_class_int_create(
                const bt_field_class *ir_fc, uint64_t index_in_parent)
@@ -259,7 +307,9 @@ struct fs_sink_ctf_field_class_float *fs_sink_ctf_field_class_float_create(
        BT_ASSERT(fc);
        _fs_sink_ctf_field_class_bit_array_init((void *) fc,
                FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
-               ir_fc, bt_field_class_real_is_single_precision(ir_fc) ? 32 : 64,
+               ir_fc,
+               bt_field_class_get_type(ir_fc) ==
+                       BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
                index_in_parent);
        return fc;
 }
@@ -294,6 +344,22 @@ struct fs_sink_ctf_field_class_struct *fs_sink_ctf_field_class_struct_create_emp
        return fc;
 }
 
+static inline
+struct fs_sink_ctf_field_class_option *fs_sink_ctf_field_class_option_create_empty(
+               const bt_field_class *ir_fc, uint64_t index_in_parent)
+{
+       struct fs_sink_ctf_field_class_option *fc =
+               g_new0(struct fs_sink_ctf_field_class_option, 1);
+
+       BT_ASSERT(fc);
+       _fs_sink_ctf_field_class_init((void *) fc,
+               FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION, ir_fc,
+               1, index_in_parent);
+       fc->tag_ref = g_string_new(NULL);
+       BT_ASSERT(fc->tag_ref);
+       return fc;
+}
+
 static inline
 struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_empty(
                const bt_field_class *ir_fc, uint64_t index_in_parent)
@@ -312,7 +378,7 @@ struct fs_sink_ctf_field_class_variant *fs_sink_ctf_field_class_variant_create_e
        BT_ASSERT(fc->tag_ref);
        fc->tag_is_before =
                bt_field_class_get_type(fc->base.ir_fc) ==
-               BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR;
+               BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD;
        return fc;
 }
 
@@ -327,7 +393,7 @@ struct fs_sink_ctf_field_class_array *fs_sink_ctf_field_class_array_create_empty
        _fs_sink_ctf_field_class_init((void *) fc,
                FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY, ir_fc,
                1, index_in_parent);
-       fc->length = bt_field_class_static_array_get_length(ir_fc);
+       fc->length = bt_field_class_array_static_get_length(ir_fc);
        return fc;
 }
 
@@ -345,8 +411,8 @@ struct fs_sink_ctf_field_class_sequence *fs_sink_ctf_field_class_sequence_create
        fc->length_ref = g_string_new(NULL);
        BT_ASSERT(fc->length_ref);
        fc->length_is_before =
-               bt_field_class_dynamic_array_borrow_length_field_path_const(ir_fc) ==
-               NULL;
+               bt_field_class_get_type(ir_fc) ==
+                       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD;
        return fc;
 }
 
@@ -366,6 +432,24 @@ void _fs_sink_ctf_field_class_fini(struct fs_sink_ctf_field_class *fc)
        BT_ASSERT(fc);
 }
 
+static inline
+void _fs_sink_ctf_field_class_bit_array_destroy(
+               struct fs_sink_ctf_field_class_int *fc)
+{
+       BT_ASSERT(fc);
+       _fs_sink_ctf_field_class_fini((void *) fc);
+       g_free(fc);
+}
+
+static inline
+void _fs_sink_ctf_field_class_bool_destroy(
+               struct fs_sink_ctf_field_class_int *fc)
+{
+       BT_ASSERT(fc);
+       _fs_sink_ctf_field_class_fini((void *) fc);
+       g_free(fc);
+}
+
 static inline
 void _fs_sink_ctf_field_class_int_destroy(
                struct fs_sink_ctf_field_class_int *fc)
@@ -452,6 +536,22 @@ void _fs_sink_ctf_field_class_sequence_destroy(
        g_free(fc);
 }
 
+static inline
+void _fs_sink_ctf_field_class_option_destroy(
+               struct fs_sink_ctf_field_class_option *fc)
+{
+       BT_ASSERT(fc);
+       _fs_sink_ctf_field_class_fini((void *) fc);
+       fs_sink_ctf_field_class_destroy(fc->content_fc);
+
+       if (fc->tag_ref) {
+               g_string_free(fc->tag_ref, TRUE);
+               fc->tag_ref = NULL;
+       }
+
+       g_free(fc);
+}
+
 static inline
 void _fs_sink_ctf_field_class_variant_destroy(
                struct fs_sink_ctf_field_class_variant *fc)
@@ -490,6 +590,12 @@ void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
        }
 
        switch (fc->type) {
+       case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL:
+               _fs_sink_ctf_field_class_bool_destroy((void *) fc);
+               break;
+       case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY:
+               _fs_sink_ctf_field_class_bit_array_destroy((void *) fc);
+               break;
        case FS_SINK_CTF_FIELD_CLASS_TYPE_INT:
                _fs_sink_ctf_field_class_int_destroy((void *) fc);
                break;
@@ -508,6 +614,9 @@ void fs_sink_ctf_field_class_destroy(struct fs_sink_ctf_field_class *fc)
        case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE:
                _fs_sink_ctf_field_class_sequence_destroy((void *) fc);
                break;
+       case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION:
+               _fs_sink_ctf_field_class_option_destroy((void *) fc);
+               break;
        case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT:
                _fs_sink_ctf_field_class_variant_destroy((void *) fc);
                break;
@@ -521,8 +630,8 @@ struct fs_sink_ctf_named_field_class *
 fs_sink_ctf_field_class_struct_borrow_member_by_index(
                struct fs_sink_ctf_field_class_struct *fc, uint64_t index)
 {
-       BT_ASSERT(fc);
-       BT_ASSERT(index < fc->members->len);
+       BT_ASSERT_DBG(fc);
+       BT_ASSERT_DBG(index < fc->members->len);
        return &g_array_index(fc->members, struct fs_sink_ctf_named_field_class,
                index);
 }
@@ -535,8 +644,8 @@ fs_sink_ctf_field_class_struct_borrow_member_by_name(
        uint64_t i;
        struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
 
-       BT_ASSERT(fc);
-       BT_ASSERT(name);
+       BT_ASSERT_DBG(fc);
+       BT_ASSERT_DBG(name);
 
        for (i = 0; i < fc->members->len; i++) {
                struct fs_sink_ctf_named_field_class *named_fc =
@@ -635,8 +744,8 @@ struct fs_sink_ctf_named_field_class *
 fs_sink_ctf_field_class_variant_borrow_option_by_index(
                struct fs_sink_ctf_field_class_variant *fc, uint64_t index)
 {
-       BT_ASSERT(fc);
-       BT_ASSERT(index < fc->options->len);
+       BT_ASSERT_DBG(fc);
+       BT_ASSERT_DBG(index < fc->options->len);
        return &g_array_index(fc->options, struct fs_sink_ctf_named_field_class,
                index);
 }
@@ -649,8 +758,8 @@ fs_sink_ctf_field_class_variant_borrow_option_by_name(
        uint64_t i;
        struct fs_sink_ctf_named_field_class *ret_named_fc = NULL;
 
-       BT_ASSERT(fc);
-       BT_ASSERT(name);
+       BT_ASSERT_DBG(fc);
+       BT_ASSERT_DBG(name);
 
        for (i = 0; i < fc->options->len; i++) {
                struct fs_sink_ctf_named_field_class *named_fc =
This page took 0.026929 seconds and 4 git commands to generate.