lib: have dedicated, unique unsigned and signed enum FC mapping objects
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 24 Apr 2019 05:00:45 +0000 (01:00 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 3 May 2019 22:19:40 +0000 (18:19 -0400)
This patch makes the enumeration field class mapping API aligned with
the structure field class member and variant field class option APIs. In
other words, a signed or an unsigned enumeration field class mapping is
now a dedicated type. An enumeration field class mapping object is
unique and always belongs to its parent field class.

bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const() and
bt_field_class_signed_enumeration_borrow_mapping_by_index_const() now
return borrowed enumeration field class mapping objects.

You can use
bt_field_class_unsigned_enumeration_mapping_as_mapping_const() to change
a signed or unsigned enumeration field class mapping into a generic
enumeration field class mapping. The API for a generic enumeration field
class mapping is:

    const char *bt_field_class_enumeration_mapping_get_label(
        const bt_field_class_enumeration_mapping *mapping);

    uint64_t bt_field_class_enumeration_mapping_get_range_count(
        const bt_field_class_enumeration_mapping *mapping);

You cannot create an enumeration field class mapping object: you still
map a name to a specific range with
bt_field_class_unsigned_enumeration_map_range() and
bt_field_class_signed_enumeration_map_range().

This patch also makes the `flt.lttng-utils.debug-info` and `sink.ctf.fs`
component classes use the updated API.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iba5da648ca69ec0ca0c5df09a9f383dd4b1e3972
Reviewed-on: https://review.gerrithub.io/c/eepp/babeltrace/+/451996

include/babeltrace/trace-ir/field-class-const.h
include/babeltrace/trace-ir/field-class-internal.h
include/babeltrace/types.h
lib/trace-ir/field-class.c
plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c

index 244218d887aaf694574999bbd1abe5eeb123faf1..eb9cb1508a2f1fb5767081f4df73b2a98f3f3a72 100644 (file)
  */
 
 /*
- * For bt_bool, bt_field_class bt_field_path
- * bt_field_class_signed_enumeration_mapping_ranges
- * bt_field_class_unsigned_enumeration_mapping_ranges,
+ * For bt_bool, bt_field_class, bt_field_path,
+ * bt_field_class_enumeration_mapping,
+ * bt_field_class_unsigned_enumeration_mapping,
+ * bt_field_class_signed_enumeration_mapping,
  * bt_field_class_enumeration_mapping_label_array
  */
 #include <babeltrace/types.h>
@@ -83,32 +84,44 @@ extern bt_bool bt_field_class_real_is_single_precision(
 extern uint64_t bt_field_class_enumeration_get_mapping_count(
                const bt_field_class *field_class);
 
-extern void bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
-               const bt_field_class *field_class, uint64_t index,
-               const char **label,
-               const bt_field_class_unsigned_enumeration_mapping_ranges **ranges);
+extern const bt_field_class_unsigned_enumeration_mapping *
+bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
+               const bt_field_class *field_class, uint64_t index);
+
+extern const bt_field_class_signed_enumeration_mapping *
+bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
+               const bt_field_class *field_class, uint64_t index);
 
-extern void bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
-               const bt_field_class *field_class, uint64_t index,
-               const char **label,
-               const bt_field_class_signed_enumeration_mapping_ranges **ranges);
+static inline
+const bt_field_class_enumeration_mapping *
+bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
+               const bt_field_class_unsigned_enumeration_mapping *mapping)
+{
+       return (const void *) mapping;
+}
+
+static inline
+const bt_field_class_enumeration_mapping *
+bt_field_class_signed_enumeration_mapping_as_mapping_const(
+               const bt_field_class_signed_enumeration_mapping *mapping)
+{
+       return (const void *) mapping;
+}
 
-extern uint64_t
-bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count(
-               const bt_field_class_unsigned_enumeration_mapping_ranges *ranges);
+extern const char *bt_field_class_enumeration_mapping_get_label(
+               const bt_field_class_enumeration_mapping *mapping);
 
-extern uint64_t
-bt_field_class_signed_enumeration_mapping_ranges_get_range_count(
-               const bt_field_class_signed_enumeration_mapping_ranges *ranges);
+extern uint64_t bt_field_class_enumeration_mapping_get_range_count(
+               const bt_field_class_enumeration_mapping *mapping);
 
 extern void
-bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
-               const bt_field_class_unsigned_enumeration_mapping_ranges *ranges,
+bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
+               const bt_field_class_unsigned_enumeration_mapping *mapping,
                uint64_t index, uint64_t *lower, uint64_t *upper);
 
 extern void
-bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-               const bt_field_class_signed_enumeration_mapping_ranges *ranges,
+bt_field_class_signed_enumeration_mapping_get_range_by_index(
+               const bt_field_class_signed_enumeration_mapping *mapping,
                uint64_t index, int64_t *lower, int64_t *upper);
 
 extern bt_field_class_status
index 77268c5f2bad990f2465d0850caa29b087a0d1cd..7aabf62380c143f01b79d1d77b1d42b8682df388 100644 (file)
@@ -130,6 +130,9 @@ struct bt_field_class_enumeration_mapping {
        GArray *ranges;
 };
 
+struct bt_field_class_unsigned_enumeration_mapping;
+struct bt_field_class_signed_enumeration_mapping;
+
 struct bt_field_class_enumeration {
        struct bt_field_class_integer common;
 
index 72fcb9e858c44c8710fa5add66373b2ee3dcd695..9f71793a1b4b095f73f60bf2132e6a2083daec90 100644 (file)
@@ -92,8 +92,9 @@ typedef struct bt_event_class bt_event_class;
 typedef struct bt_event_header_field bt_event_header_field;
 typedef struct bt_field bt_field;
 typedef struct bt_field_class bt_field_class;
-typedef struct bt_field_class_signed_enumeration_mapping_ranges bt_field_class_signed_enumeration_mapping_ranges;
-typedef struct bt_field_class_unsigned_enumeration_mapping_ranges bt_field_class_unsigned_enumeration_mapping_ranges;
+typedef struct bt_field_class_enumeration_mapping bt_field_class_enumeration_mapping;
+typedef struct bt_field_class_signed_enumeration_mapping bt_field_class_signed_enumeration_mapping;
+typedef struct bt_field_class_unsigned_enumeration_mapping bt_field_class_unsigned_enumeration_mapping;
 typedef struct bt_field_class_structure_member bt_field_class_structure_member;
 typedef struct bt_field_class_variant_option bt_field_class_variant_option;
 typedef struct bt_field_path bt_field_path;
index dad075e80df0a582204a3fa6b69e44099038c291..b228fc0af7da9ddc992b1649aa6742af25aca15e 100644 (file)
@@ -291,64 +291,44 @@ uint64_t bt_field_class_enumeration_get_mapping_count(
        return (uint64_t) enum_fc->mappings->len;
 }
 
-void bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
-               const struct bt_field_class *fc, uint64_t index,
-               const char **name,
-               const struct bt_field_class_unsigned_enumeration_mapping_ranges **ranges)
+const struct bt_field_class_unsigned_enumeration_mapping *
+bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
+               const struct bt_field_class *fc, uint64_t index)
 {
        const struct bt_field_class_enumeration *enum_fc = (const void *) fc;
-       const struct bt_field_class_enumeration_mapping *mapping;
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name (output)");
-       BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)");
        BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len);
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION,
                "Field class");
-       mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index);
-       *name = mapping->label->str;
-       *ranges = (void *) mapping;
+       return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index);
 }
 
-void bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
-               const struct bt_field_class *fc, uint64_t index,
-               const char **name,
-               const struct bt_field_class_signed_enumeration_mapping_ranges **ranges)
+const struct bt_field_class_signed_enumeration_mapping *
+bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
+               const struct bt_field_class *fc, uint64_t index)
 {
        const struct bt_field_class_enumeration *enum_fc = (const void *) fc;
-       const struct bt_field_class_enumeration_mapping *mapping;
 
        BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name (output)");
-       BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)");
        BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len);
        BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION,
                "Field class");
-       mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index);
-       *name = mapping->label->str;
-       *ranges = (void *) mapping;
+       return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index);
 }
 
-static inline
-uint64_t get_enumeration_field_class_mapping_range_count(
+const char *bt_field_class_enumeration_mapping_get_label(
                const struct bt_field_class_enumeration_mapping *mapping)
 {
-       BT_ASSERT_PRE_NON_NULL(mapping, "Ranges");
-       return (uint64_t) mapping->ranges->len;
-}
-
-uint64_t bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count(
-               const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges)
-{
-       return get_enumeration_field_class_mapping_range_count(
-               (const void *) ranges);
+       BT_ASSERT_PRE_NON_NULL(mapping, "Enumeration field class mapping");
+       return mapping->label->str;
 }
 
-uint64_t bt_field_class_signed_enumeration_mapping_ranges_get_range_count(
-               const struct bt_field_class_signed_enumeration_mapping_ranges *ranges)
+uint64_t bt_field_class_enumeration_mapping_get_range_count(
+               const struct bt_field_class_enumeration_mapping *mapping)
 {
-       return get_enumeration_field_class_mapping_range_count(
-               (const void *) ranges);
+       BT_ASSERT_PRE_NON_NULL(mapping, "Enumeration field class mapping");
+       return (uint64_t) mapping->ranges->len;
 }
 
 static inline
@@ -367,16 +347,16 @@ void get_enumeration_field_class_mapping_range_at_index(
        *upper = range->upper.u;
 }
 
-void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
-               const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges,
+void bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
+               const struct bt_field_class_unsigned_enumeration_mapping *ranges,
                uint64_t index, uint64_t *lower, uint64_t *upper)
 {
        get_enumeration_field_class_mapping_range_at_index(
                (const void *) ranges, index, lower, upper);
 }
 
-void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-               const struct bt_field_class_signed_enumeration_mapping_ranges *ranges,
+void bt_field_class_signed_enumeration_mapping_get_range_by_index(
+               const struct bt_field_class_signed_enumeration_mapping *ranges,
                uint64_t index, int64_t *lower, int64_t *upper)
 {
        get_enumeration_field_class_mapping_range_at_index(
@@ -384,8 +364,6 @@ void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
                (uint64_t *) lower, (uint64_t *) upper);
 }
 
-
-
 enum bt_field_class_status
 bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
                const struct bt_field_class *fc, uint64_t value,
index fef1d040076cd33ed39eacbe7a5994ae99707c0a..efc02b305850d1a441b7f9e85feceaeb50bf804c 100644 (file)
@@ -227,23 +227,30 @@ void append_integer_field_class(struct ctx *ctx,
 
                for (i = 0; i < bt_field_class_enumeration_get_mapping_count(ir_fc); i++) {
                        const char *label;
-                       const bt_field_class_unsigned_enumeration_mapping_ranges *u_ranges;
-                       const bt_field_class_signed_enumeration_mapping_ranges *i_ranges;
+                       const bt_field_class_enumeration_mapping *mapping;
+                       const bt_field_class_unsigned_enumeration_mapping *u_mapping;
+                       const bt_field_class_signed_enumeration_mapping *i_mapping;
                        uint64_t range_count;
                        uint64_t range_i;
 
                        if (is_signed) {
-                               bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
-                                       ir_fc, i, &label, &i_ranges);
-                               range_count = bt_field_class_signed_enumeration_mapping_ranges_get_range_count(
-                                       i_ranges);
+                               i_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
+                                       ir_fc, i);
+                               mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const(
+                                       i_mapping);
                        } else {
-                               bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
-                                       ir_fc, i, &label, &u_ranges);
-                               range_count = bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count(
-                                       u_ranges);
+                               u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
+                                       ir_fc, i);
+                               mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
+                                       u_mapping);
                        }
 
+                       label = bt_field_class_enumeration_mapping_get_label(
+                               mapping);
+                       range_count =
+                               bt_field_class_enumeration_mapping_get_range_count(
+                                       mapping);
+
                        for (range_i = 0; range_i < range_count; range_i++) {
                                append_indent(ctx);
 
@@ -271,8 +278,8 @@ void append_integer_field_class(struct ctx *ctx,
                                if (is_signed) {
                                        int64_t lower, upper;
 
-                                       bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-                                               i_ranges, range_i,
+                                       bt_field_class_signed_enumeration_mapping_get_range_by_index(
+                                               i_mapping, range_i,
                                                &lower, &upper);
 
                                        if (lower == upper) {
@@ -287,8 +294,8 @@ void append_integer_field_class(struct ctx *ctx,
                                } else {
                                        uint64_t lower, upper;
 
-                                       bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
-                                               u_ranges, range_i,
+                                       bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
+                                               u_mapping, range_i,
                                                &lower, &upper);
 
                                        if (lower == upper) {
index 1434851b4dadf2106d160cef1167d3c2394f0d87..a256beda74e49c7fe9920cef05a2892ed718fb47 100644 (file)
@@ -201,15 +201,21 @@ int field_class_unsigned_enumeration_copy(
        enum_mapping_count = bt_field_class_enumeration_get_mapping_count(in_field_class);
        for (i = 0; i < enum_mapping_count; i++) {
                const char *label;
-               const bt_field_class_unsigned_enumeration_mapping_ranges *ranges;
+               const bt_field_class_unsigned_enumeration_mapping *u_mapping;
+               const bt_field_class_enumeration_mapping *mapping;
                uint64_t range_index, range_count;
 
                /* Get the ranges and the range count. */
-               bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
-                               in_field_class, i, &label, &ranges);
+               u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
+                               in_field_class, i);
+               mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
+                       u_mapping);
                range_count =
-                       bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count(
-                                       ranges);
+                       bt_field_class_enumeration_mapping_get_range_count(
+                               mapping);
+               label = bt_field_class_enumeration_mapping_get_label(
+                       mapping);
+
                /*
                 * Iterate over all the ranges to add them to copied field
                 * class.
@@ -217,8 +223,8 @@ int field_class_unsigned_enumeration_copy(
                for (range_index = 0; range_index < range_count; range_index++) {
                        uint64_t lower, upper;
                        bt_field_class_status status;
-                       bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index(
-                                       ranges, range_index, &lower, &upper);
+                       bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
+                                       u_mapping, range_index, &lower, &upper);
 
                        BT_LOGD("Copying range in enumeration field class: "
                                        "label=%s, lower=%"PRId64", upper=%"PRId64,
@@ -267,15 +273,21 @@ int field_class_signed_enumeration_copy(
                bt_field_class_enumeration_get_mapping_count(in_field_class);
        for (i = 0; i < enum_mapping_count; i++) {
                const char *label;
-               const bt_field_class_signed_enumeration_mapping_ranges *ranges;
+               const bt_field_class_signed_enumeration_mapping *i_mapping;
+               const bt_field_class_enumeration_mapping *mapping;
                uint64_t range_index, range_count;
 
                /* Get the ranges and the range count. */
-               bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
-                               in_field_class, i, &label, &ranges);
+               i_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
+                               in_field_class, i);
+               mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const(
+                       i_mapping);
                range_count =
-                       bt_field_class_signed_enumeration_mapping_ranges_get_range_count(
-                                       ranges);
+                       bt_field_class_enumeration_mapping_get_range_count(
+                               mapping);
+               label = bt_field_class_enumeration_mapping_get_label(
+                       mapping);
+
                /*
                 * Iterate over all the ranges to add them to copied field
                 * class.
@@ -283,8 +295,8 @@ int field_class_signed_enumeration_copy(
                for (range_index = 0; range_index < range_count; range_index++) {
                        int64_t lower, upper;
                        bt_field_class_status status;
-                       bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index(
-                                       ranges, range_index, &lower, &upper);
+                       bt_field_class_signed_enumeration_mapping_get_range_by_index(
+                                       i_mapping, range_index, &lower, &upper);
 
                        BT_LOGD("Copying range in enumeration field class: "
                                        "label=%s, lower=%ld, upper=%ld",
This page took 0.032149 seconds and 4 git commands to generate.