+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;
+}
+
+/*
+ * Note: This algorithm is O(n^2) vs number of enumeration mappings.
+ * Only used when freezing an enumeration.
+ */
+static
+void set_enumeration_range_overlap(
+ struct bt_ctf_field_type *type)
+{
+ int i, j, len;
+ struct bt_ctf_field_type *container_type;
+ struct bt_ctf_field_type_enumeration *enumeration_type;
+ int is_signed;
+
+ enumeration_type = container_of(type,
+ struct bt_ctf_field_type_enumeration, parent);
+
+ len = enumeration_type->entries->len;
+ container_type = enumeration_type->container;
+ is_signed = bt_ctf_field_type_integer_get_signed(container_type);
+
+ 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;
+ }
+ }
+ }
+ }
+}
+