#include <babeltrace/ctf-ir/field-path-internal.h>
#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/ref.h>
-#include <babeltrace/ctf-ir/clock.h>
-#include <babeltrace/ctf-ir/clock-internal.h>
+#include <babeltrace/ctf-ir/clock-class.h>
+#include <babeltrace/ctf-ir/clock-class-internal.h>
#include <babeltrace/ctf-writer/writer-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/ref.h>
return ret;
}
+static
+bool bt_ctf_field_type_enumeration_has_overlapping_ranges(
+ struct bt_ctf_field_type_enumeration *enumeration_type)
+{
+ return enumeration_type->has_overlapping_ranges;
+}
+
static
int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type)
{
goto end;
}
+ if (bt_ctf_field_type_enumeration_has_overlapping_ranges(
+ variant->tag)) {
+ ret = -1;
+ goto end;
+ }
+
tag_mappings_count =
bt_ctf_field_type_enumeration_get_mapping_count(
(struct bt_ctf_field_type *) variant->tag);
for (i = 0; i < tag_mappings_count; ++i) {
const char *label;
- int64_t range_start, range_end;
struct bt_ctf_field_type *ft;
- ret = bt_ctf_field_type_enumeration_get_mapping(
+ ret = bt_ctf_field_type_enumeration_get_mapping_name(
(struct bt_ctf_field_type *) variant->tag,
- i, &label, &range_start, &range_end);
+ i, &label);
if (ret) {
goto end;
}
return ret;
}
-struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock(
+struct bt_ctf_clock_class *bt_ctf_field_type_integer_get_mapped_clock_class(
struct bt_ctf_field_type *type)
{
struct bt_ctf_field_type_integer *integer;
- struct bt_ctf_clock *clock = NULL;
+ struct bt_ctf_clock_class *clock_class = NULL;
if (!type) {
goto end;
}
integer = container_of(type, struct bt_ctf_field_type_integer, parent);
- clock = integer->mapped_clock;
- bt_get(clock);
+ clock_class = integer->mapped_clock;
+ bt_get(clock_class);
end:
- return clock;
+ return clock_class;
}
-int bt_ctf_field_type_integer_set_mapped_clock(
+int bt_ctf_field_type_integer_set_mapped_clock_class(
struct bt_ctf_field_type *type,
- struct bt_ctf_clock *clock)
+ struct bt_ctf_clock_class *clock_class)
{
struct bt_ctf_field_type_integer *integer;
int ret = 0;
- if (!type || type->frozen) {
+ if (!type || type->frozen || !bt_ctf_clock_class_is_valid(clock_class)) {
ret = -1;
goto end;
}
integer = container_of(type, struct bt_ctf_field_type_integer, parent);
bt_put(integer->mapped_clock);
- bt_get(clock);
- integer->mapped_clock = clock;
+ integer->mapped_clock = bt_get(clock_class);
end:
return ret;
}
+static
+struct enumeration_mapping *get_enumeration_mapping(
+ struct bt_ctf_field_type *type, int index)
+{
+ struct enumeration_mapping *mapping = NULL;
+ struct bt_ctf_field_type_enumeration *enumeration;
+
+ enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
+ parent);
+ if (index >= enumeration->entries->len) {
+ goto end;
+ }
+
+ mapping = g_ptr_array_index(enumeration->entries, index);
+end:
+ return mapping;
+}
+
+static void bt_ctf_field_type_enum_iter_destroy(struct bt_object *obj)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter =
+ container_of(obj,
+ struct bt_ctf_field_type_enumeration_mapping_iterator,
+ base);
+
+ bt_put(&iter->enumeration_type->parent);
+ g_free(iter);
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_next(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter)
+{
+ struct bt_ctf_field_type_enumeration *enumeration;
+ struct bt_ctf_field_type *type;
+ int i, ret = 0, len;
+
+ enumeration = iter->enumeration_type;
+ type = &enumeration->parent;
+ len = enumeration->entries->len;
+ for (i = iter->index + 1; i < len; i++) {
+ struct enumeration_mapping *mapping =
+ get_enumeration_mapping(type, i);
+
+ switch (iter->kind) {
+ case ITERATOR_BY_NAME:
+ if (mapping->string == iter->u.name_quark) {
+ iter->index = i;
+ goto end;
+ }
+ break;
+ case ITERATOR_BY_SIGNED_VALUE:
+ {
+ int64_t value = iter->u.signed_value;
+
+ if (value >= mapping->range_start._signed &&
+ value <= mapping->range_end._signed) {
+ iter->index = i;
+ goto end;
+ }
+ break;
+ }
+ case ITERATOR_BY_UNSIGNED_VALUE:
+ {
+ uint64_t value = iter->u.unsigned_value;
+
+ if (value >= mapping->range_start._unsigned &&
+ value <= mapping->range_end._unsigned) {
+ iter->index = i;
+ goto end;
+ }
+ break;
+ }
+ default:
+ abort();
+ }
+ }
+
+ ret = -1;
+end:
+ return ret;
+}
+
+static struct bt_ctf_field_type_enumeration_mapping_iterator *
+ bt_ctf_field_type_enumeration_find_mappings_kind(
+ struct bt_ctf_field_type *type,
+ enum bt_ctf_field_type_enumeration_mapping_iterator_kind kind)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter;
+ struct bt_ctf_field_type_enumeration *enumeration_type;
+
+ if (!type || (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
+ return NULL;
+ }
+ enumeration_type = container_of(type,
+ struct bt_ctf_field_type_enumeration, parent);
+ iter = g_new0(struct bt_ctf_field_type_enumeration_mapping_iterator, 1);
+ if (!iter) {
+ return NULL;
+ }
+ bt_object_init(&iter->base, bt_ctf_field_type_enum_iter_destroy);
+ bt_get(type);
+ iter->enumeration_type = enumeration_type;
+ iter->index = -1;
+ iter->kind = kind;
+ return iter;
+}
+
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+ bt_ctf_field_type_enumeration_find_mappings_by_name(
+ struct bt_ctf_field_type *type,
+ const char *name)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
+
+ iter = bt_ctf_field_type_enumeration_find_mappings_kind(
+ type, ITERATOR_BY_NAME);
+ if (!iter) {
+ goto error;
+ }
+ iter->u.name_quark = g_quark_try_string(name);
+ if (!iter->u.name_quark) {
+ goto error;
+ }
+ /* Advance iterator to first entry, or leave index at -1. */
+ if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
+ /* No entry found. */
+ goto error;
+ }
+ return iter;
+
+error:
+ bt_put(iter);
+ return NULL;
+}
+
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+ bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
+ struct bt_ctf_field_type *type,
+ int64_t value)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
+
+ iter = bt_ctf_field_type_enumeration_find_mappings_kind(
+ type, ITERATOR_BY_SIGNED_VALUE);
+ if (!iter) {
+ goto error;
+ }
+ if (bt_ctf_field_type_integer_get_signed(
+ iter->enumeration_type->container) != 1) {
+ goto error;
+ }
+ iter->u.signed_value = value;
+ /* Advance iterator to first entry, or leave index at -1. */
+ if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
+ /* No entry found. */
+ goto error;
+ }
+ return iter;
+
+error:
+ bt_put(iter);
+ return NULL;
+}
+
+struct bt_ctf_field_type_enumeration_mapping_iterator *
+ bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
+ struct bt_ctf_field_type *type,
+ uint64_t value)
+{
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter = NULL;
+
+ iter = bt_ctf_field_type_enumeration_find_mappings_kind(
+ type, ITERATOR_BY_UNSIGNED_VALUE);
+ if (!iter) {
+ goto error;
+ }
+ if (bt_ctf_field_type_integer_get_signed(
+ iter->enumeration_type->container) != 0) {
+ goto error;
+ }
+ iter->u.unsigned_value = value;
+ /* Advance iterator to first entry, or leave index at -1. */
+ if (bt_ctf_field_type_enumeration_mapping_iterator_next(iter)) {
+ /* No entry found. */
+ goto error;
+ }
+ return iter;
+
+error:
+ bt_put(iter);
+ return NULL;
+}
+
+int bt_ctf_field_type_enumeration_get_mapping_name(
+ struct bt_ctf_field_type *enum_field_type,
+ int index,
+ const char **mapping_name)
+{
+ struct enumeration_mapping *mapping;
+
+ if (!enum_field_type || index < 0) {
+ return -1;
+ }
+ mapping = get_enumeration_mapping(enum_field_type, index);
+ if (!mapping) {
+ return -1;
+ }
+ if (mapping_name) {
+ *mapping_name = g_quark_to_string(mapping->string);
+ }
+ return 0;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_get_name(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
+ const char **mapping_name)
+{
+ if (!iter) {
+ return -1;
+ }
+ return bt_ctf_field_type_enumeration_get_mapping_name(
+ &iter->enumeration_type->parent, iter->index,
+ mapping_name);
+}
+
+int bt_ctf_field_type_enumeration_get_mapping_signed(
+ struct bt_ctf_field_type *enum_field_type,
+ int index,
+ const char **mapping_name, int64_t *range_begin,
+ int64_t *range_end)
+{
+ struct enumeration_mapping *mapping;
+
+ if (!enum_field_type || index < 0) {
+ return -1;
+ }
+ mapping = get_enumeration_mapping(enum_field_type, index);
+ if (!mapping) {
+ return -1;
+ }
+ if (mapping_name) {
+ *mapping_name = g_quark_to_string(mapping->string);
+ }
+ if (range_begin) {
+ *range_begin = mapping->range_start._signed;
+ }
+ if (range_end) {
+ *range_end = mapping->range_end._signed;
+ }
+ return 0;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_get_signed(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
+ const char **mapping_name, int64_t *range_begin,
+ int64_t *range_end)
+{
+ if (!iter) {
+ return -1;
+ }
+ return bt_ctf_field_type_enumeration_get_mapping_signed(
+ &iter->enumeration_type->parent, iter->index,
+ mapping_name, range_begin, range_end);
+}
+
+int bt_ctf_field_type_enumeration_get_mapping_unsigned(
+ struct bt_ctf_field_type *enum_field_type,
+ int index,
+ const char **mapping_name, uint64_t *range_begin,
+ uint64_t *range_end)
+{
+ struct enumeration_mapping *mapping;
+
+ if (!enum_field_type || index < 0) {
+ return -1;
+ }
+ mapping = get_enumeration_mapping(enum_field_type, index);
+ if (!mapping) {
+ return -1;
+ }
+ if (mapping_name) {
+ *mapping_name = g_quark_to_string(mapping->string);
+ }
+ if (range_begin) {
+ *range_begin = mapping->range_start._unsigned;
+ }
+ if (range_end) {
+ *range_end = mapping->range_end._unsigned;
+ }
+ return 0;
+}
+
+int bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(
+ struct bt_ctf_field_type_enumeration_mapping_iterator *iter,
+ const char **mapping_name, uint64_t *range_begin,
+ uint64_t *range_end)
+{
+ if (!iter) {
+ return -1;
+ }
+ return bt_ctf_field_type_enumeration_get_mapping_unsigned(
+ &iter->enumeration_type->parent, iter->index,
+ mapping_name, range_begin, range_end);
+}
+
struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(
struct bt_ctf_field_type *integer_container_type)
{
GQuark mapping_name;
struct enumeration_mapping *mapping;
struct bt_ctf_field_type_enumeration *enumeration;
- struct range_overlap_query query;
char *escaped_string;
if (!type || (type->declaration->id != BT_CTF_TYPE_ID_ENUM) ||
goto end;
}
- mapping_name = g_quark_from_string(escaped_string);
- query = (struct range_overlap_query) {
- .range_start._signed = range_start,
- .range_end._signed = range_end,
- .mapping_name = mapping_name,
- .overlaps = 0 };
- enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
- parent);
-
- /* Check that the range does not overlap with one already present */
- g_ptr_array_foreach(enumeration->entries, check_ranges_overlap, &query);
- if (query.overlaps) {
- ret = -1;
- goto error_free;
- }
-
mapping = g_new(struct enumeration_mapping, 1);
if (!mapping) {
ret = -1;
goto error_free;
}
-
+ mapping_name = g_quark_from_string(escaped_string);
*mapping = (struct enumeration_mapping) {
.range_start._signed = range_start,
- .range_end._signed = range_end, .string = mapping_name};
+ .range_end._signed = range_end,
+ .string = mapping_name,
+ };
+ enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
+ parent);
g_ptr_array_add(enumeration->entries, mapping);
g_ptr_array_sort(enumeration->entries,
(GCompareFunc)compare_enumeration_mappings_signed);
GQuark mapping_name;
struct enumeration_mapping *mapping;
struct bt_ctf_field_type_enumeration *enumeration;
- struct range_overlap_query query;
char *escaped_string;
if (!type || (type->declaration->id != BT_CTF_TYPE_ID_ENUM) ||
goto end;
}
- mapping_name = g_quark_from_string(escaped_string);
- query = (struct range_overlap_query) {
- .range_start._unsigned = range_start,
- .range_end._unsigned = range_end,
- .mapping_name = mapping_name,
- .overlaps = 0 };
- enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
- parent);
-
- /* Check that the range does not overlap with one already present */
- g_ptr_array_foreach(enumeration->entries, check_ranges_overlap_unsigned,
- &query);
- if (query.overlaps) {
- ret = -1;
- goto error_free;
- }
-
mapping = g_new(struct enumeration_mapping, 1);
if (!mapping) {
ret = -1;
goto error_free;
}
-
+ mapping_name = g_quark_from_string(escaped_string);
*mapping = (struct enumeration_mapping) {
.range_start._unsigned = range_start,
- .range_end._unsigned = range_end, .string = mapping_name};
+ .range_end._unsigned = range_end,
+ .string = mapping_name,
+ };
+ enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
+ parent);
g_ptr_array_add(enumeration->entries, mapping);
g_ptr_array_sort(enumeration->entries,
(GCompareFunc)compare_enumeration_mappings_unsigned);
return ret;
}
-const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
- struct bt_ctf_field_type_enumeration *enumeration_type,
- uint64_t value)
-{
- const char *name = NULL;
- struct range_overlap_query query =
- (struct range_overlap_query) {
- .range_start._unsigned = value,
- .range_end._unsigned = value,
- .overlaps = 0 };
-
- g_ptr_array_foreach(enumeration_type->entries,
- check_ranges_overlap_unsigned,
- &query);
- if (!query.overlaps) {
- goto end;
- }
-
- name = g_quark_to_string(query.mapping_name);
-end:
- return name;
-}
-
-const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
- struct bt_ctf_field_type_enumeration *enumeration_type,
- int64_t value)
-{
- const char *name = NULL;
- struct range_overlap_query query =
- (struct range_overlap_query) {
- .range_start._signed = value,
- .range_end._signed = value,
- .overlaps = 0 };
-
- g_ptr_array_foreach(enumeration_type->entries, check_ranges_overlap,
- &query);
- if (!query.overlaps) {
- goto end;
- }
-
- name = g_quark_to_string(query.mapping_name);
-end:
- return name;
-}
-
int bt_ctf_field_type_enumeration_get_mapping_count(
struct bt_ctf_field_type *type)
{
return ret;
}
-static inline
-struct enumeration_mapping *get_enumeration_mapping(
- struct bt_ctf_field_type *type, int index)
-{
- struct enumeration_mapping *mapping = NULL;
- struct bt_ctf_field_type_enumeration *enumeration;
-
- enumeration = container_of(type, struct bt_ctf_field_type_enumeration,
- parent);
- if (index >= enumeration->entries->len) {
- goto end;
- }
-
- mapping = g_ptr_array_index(enumeration->entries, index);
-end:
- return mapping;
-}
-
-int bt_ctf_field_type_enumeration_get_mapping(
- struct bt_ctf_field_type *type, int index,
- const char **string, int64_t *range_start, int64_t *range_end)
-{
- struct enumeration_mapping *mapping;
- int ret = 0;
-
- if (!type || index < 0 || !string || !range_start || !range_end ||
- (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
- ret = -1;
- goto end;
- }
-
- mapping = get_enumeration_mapping(type, index);
- if (!mapping) {
- ret = -1;
- goto end;
- }
-
- *string = g_quark_to_string(mapping->string);
- *range_start = mapping->range_start._signed;
- *range_end = mapping->range_end._signed;
-end:
- return ret;
-}
-
-int bt_ctf_field_type_enumeration_get_mapping_unsigned(
- struct bt_ctf_field_type *type, int index,
- const char **string, uint64_t *range_start, uint64_t *range_end)
-{
- struct enumeration_mapping *mapping;
- int ret = 0;
-
- if (!type || index < 0 || !string || !range_start || !range_end ||
- (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
- ret = -1;
- goto end;
- }
-
- mapping = get_enumeration_mapping(type, index);
- if (!mapping) {
- ret = -1;
- goto end;
- }
-
- *string = g_quark_to_string(mapping->string);
- *range_start = mapping->range_start._unsigned;
- *range_end = mapping->range_end._unsigned;
-end:
- return ret;
-}
-
-int bt_ctf_field_type_enumeration_get_mapping_index_by_name(
- struct bt_ctf_field_type *type, const char *name)
-{
- GQuark name_quark;
- struct bt_ctf_field_type_enumeration *enumeration;
- int i, ret = 0;
-
- if (!type || !name ||
- (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
- ret = -1;
- goto end;
- }
-
- name_quark = g_quark_try_string(name);
- if (!name_quark) {
- ret = -1;
- goto end;
- }
-
- enumeration = container_of(type,
- struct bt_ctf_field_type_enumeration, parent);
- for (i = 0; i < enumeration->entries->len; i++) {
- struct enumeration_mapping *mapping =
- get_enumeration_mapping(type, i);
-
- if (mapping->string == name_quark) {
- ret = i;
- goto end;
- }
- }
-
- ret = -1;
-end:
- return ret;
-}
-
-int bt_ctf_field_type_enumeration_get_mapping_index_by_value(
- struct bt_ctf_field_type *type, int64_t value)
-{
- struct bt_ctf_field_type_enumeration *enumeration;
- int i, ret = 0;
-
- if (!type || (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
- ret = -1;
- goto end;
- }
-
- enumeration = container_of(type,
- struct bt_ctf_field_type_enumeration, parent);
- for (i = 0; i < enumeration->entries->len; i++) {
- struct enumeration_mapping *mapping =
- get_enumeration_mapping(type, i);
-
- if (value >= mapping->range_start._signed &&
- value <= mapping->range_end._signed) {
- ret = i;
- goto end;
- }
- }
-
- ret = -1;
-end:
- return ret;
-}
-
-int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(
- struct bt_ctf_field_type *type, uint64_t value)
-{
- struct bt_ctf_field_type_enumeration *enumeration;
- int i, ret = 0;
-
- if (!type || (type->declaration->id != BT_CTF_TYPE_ID_ENUM)) {
- ret = -1;
- goto end;
- }
-
- enumeration = container_of(type,
- struct bt_ctf_field_type_enumeration, parent);
- for (i = 0; i < enumeration->entries->len; i++) {
- struct enumeration_mapping *mapping =
- get_enumeration_mapping(type, i);
-
- if (value >= mapping->range_start._unsigned &&
- value <= mapping->range_end._unsigned) {
- ret = i;
- goto end;
- }
- }
-
- ret = -1;
-end:
- return ret;
-}
-
struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void)
{
struct bt_ctf_field_type_floating_point *floating_point =
int ret = 0;
struct bt_ctf_field_type_structure *structure;
+ /*
+ * TODO: check that `field_type` does not contain `type`,
+ * recursively.
+ */
if (!type || !field_type || type->frozen ||
bt_ctf_validate_identifier(field_name) ||
- (type->declaration->id != BT_CTF_TYPE_ID_STRUCT)) {
+ (type->declaration->id != BT_CTF_TYPE_ID_STRUCT) ||
+ type == field_type) {
ret = -1;
goto end;
}
struct bt_ctf_field_type_variant *variant;
GQuark field_name_quark = g_quark_from_string(field_name);
+ /*
+ * TODO: check that `field_type` does not contain `type`,
+ * recursively.
+ */
if (!type || !field_type || type->frozen ||
bt_ctf_validate_identifier(field_name) ||
- (type->declaration->id != BT_CTF_TYPE_ID_VARIANT)) {
+ (type->declaration->id != BT_CTF_TYPE_ID_VARIANT) ||
+ type == field_type) {
ret = -1;
goto end;
}
goto end;
}
- enum_value = bt_ctf_field_enumeration_get_mapping_name(tag);
+ enum_value = bt_ctf_field_enumeration_get_single_mapping_name(tag);
if (!enum_value) {
goto end;
}
ret = integer->user_byte_order;
break;
}
+ case BT_CTF_TYPE_ID_ENUM:
+ {
+ struct bt_ctf_field_type_enumeration *enum_ft = container_of(
+ type, struct bt_ctf_field_type_enumeration, parent);
+ ret = bt_ctf_field_type_get_byte_order(enum_ft->container);
+ break;
+ }
case BT_CTF_TYPE_ID_FLOAT:
{
struct bt_ctf_field_type_floating_point *floating_point =
struct range_overlap_query query = {
.range_start._signed = tag_value,
.range_end._signed = tag_value,
- .mapping_name = 0, .overlaps = 0};
+ .mapping_name = 0,
+ .overlaps = 0,
+ };
g_ptr_array_foreach(variant->tag->entries, check_ranges_overlap,
&query);
struct range_overlap_query query = {
.range_start._unsigned = tag_value,
.range_end._unsigned = tag_value,
- .mapping_name = 0, .overlaps = 0};
+ .mapping_name = 0,
+ .overlaps = 0,
+ };
g_ptr_array_foreach(variant->tag->entries,
check_ranges_overlap_unsigned,
}
}
-BT_HIDDEN
struct bt_ctf_field_type *bt_ctf_field_type_copy(struct bt_ctf_field_type *type)
{
struct bt_ctf_field_type *copy = NULL;
type, struct bt_ctf_field_type_integer, parent);
if (integer_type->mapped_clock) {
- bt_ctf_clock_freeze(integer_type->mapped_clock);
+ bt_ctf_clock_class_freeze(integer_type->mapped_clock);
}
generic_field_type_freeze(type);
}
+/*
+ * Note: This algorithm is O(n^2) vs number of enumeration mappings.
+ * Only used when freezing an enumeration.
+ */
+static
+void enumeration_range_overlap_check(struct bt_ctf_field_type *type,
+ struct bt_ctf_field_type_enumeration *enumeration_type)
+{
+ int i, j, len = enumeration_type->entries->len;
+ struct bt_ctf_field_type *container_type;
+ int is_signed;
+
+ container_type = bt_ctf_field_type_enumeration_get_container_type(type);
+ assert(container_type);
+ is_signed = bt_ctf_field_type_integer_get_signed(container_type);
+ assert(is_signed >= 0);
+
+ for (i = 0; i < len; i++) {
+ for (j = i + 1; j < len; j++) {
+ struct enumeration_mapping *mapping[2];
+
+ mapping[0] = get_enumeration_mapping(type, i);
+ mapping[1] = get_enumeration_mapping(type, j);
+ if (is_signed) {
+ if (mapping[0]->range_start._signed
+ <= mapping[1]->range_end._signed
+ && mapping[0]->range_end._signed
+ >= mapping[1]->range_start._signed) {
+ enumeration_type->has_overlapping_ranges = true;
+ return;
+ }
+ } else {
+ if (mapping[0]->range_start._unsigned
+ <= mapping[1]->range_end._unsigned
+ && mapping[0]->range_end._unsigned
+ >= mapping[1]->range_start._unsigned) {
+ enumeration_type->has_overlapping_ranges = true;
+ return;
+ }
+ }
+ }
+ }
+ assert(!enumeration_type->has_overlapping_ranges);
+}
+
static
void bt_ctf_field_type_enumeration_freeze(struct bt_ctf_field_type *type)
{
struct bt_ctf_field_type_enumeration *enumeration_type = container_of(
type, struct bt_ctf_field_type_enumeration, parent);
+ enumeration_range_overlap_check(type, enumeration_type);
generic_field_type_freeze(type);
bt_ctf_field_type_freeze(enumeration_type->container);
}
get_integer_base_string(integer->declaration.base),
get_byte_order_string(integer->declaration.byte_order));
if (integer->mapped_clock) {
- const char *clock_name = bt_ctf_clock_get_name(
+ const char *clock_name = bt_ctf_clock_class_get_name(
integer->mapped_clock);
if (!clock_name) {
for (i = 0; i < enumeration->entries->len; i++) {
struct enumeration_mapping *mapping = g_ptr_array_index(
enumeration->entries, i);
- struct enumeration_mapping* copy_mapping = g_new0(
+ struct enumeration_mapping *copy_mapping = g_new0(
struct enumeration_mapping, 1);
if (!copy_mapping) {