+static
+void enum_val_free(void *ptr)
+{
+}
+#endif /* WORD_SIZE != 32 */
+
+/*
+ * Returns a GArray or NULL.
+ * Caller must release the GArray with g_array_unref().
+ */
+GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
+ uint64_t v)
+{
+ struct enum_range_to_quark *iter;
+ GArray *qs, *ranges = NULL;
+
+ /* Single values lookup */
+ qs = g_hash_table_lookup(enum_declaration->table.value_to_quark_set,
+ get_uint_v(&v));
+
+ /* Range lookup */
+ bt_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) {
+ if (iter->range.start._unsigned > v || iter->range.end._unsigned < v)
+ continue;
+ if (!ranges) {
+ size_t qs_len = 0;
+
+ if (qs)
+ qs_len = qs->len;
+ ranges = g_array_sized_new(FALSE, TRUE,
+ sizeof(GQuark),
+ qs_len + 1);
+ g_array_set_size(ranges, qs_len + 1);
+ if (qs)
+ memcpy(ranges->data, qs->data,
+ sizeof(GQuark) * qs_len);
+ g_array_index(ranges, GQuark, qs_len) = iter->quark;
+ } else {
+ size_t qs_len = ranges->len;
+
+ g_array_set_size(ranges, qs_len + 1);
+ g_array_index(ranges, GQuark, qs_len) = iter->quark;
+ }
+ }
+ if (!ranges) {
+ if (!qs)
+ return NULL;
+ ranges = qs;
+ g_array_ref(ranges);
+ }
+ return ranges;
+}
+
+/*
+ * Returns a GArray or NULL.
+ * Caller must release the GArray with g_array_unref().
+ */
+GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
+ int64_t v)
+{
+ struct enum_range_to_quark *iter;
+ GArray *qs, *ranges = NULL;
+
+ /* Single values lookup */
+ qs = g_hash_table_lookup(enum_declaration->table.value_to_quark_set,
+ get_int_v(&v));
+
+ /* Range lookup */
+ bt_list_for_each_entry(iter, &enum_declaration->table.range_to_quark, node) {
+ if (iter->range.start._signed > v || iter->range.end._signed < v)
+ continue;
+ if (!ranges) {
+ size_t qs_len = 0;
+
+ if (qs)
+ qs_len = qs->len;
+ ranges = g_array_sized_new(FALSE, TRUE,
+ sizeof(GQuark),
+ qs_len + 1);
+ g_array_set_size(ranges, qs_len + 1);
+ if (qs)
+ memcpy(ranges->data, qs->data,
+ sizeof(GQuark) * qs_len);
+ g_array_index(ranges, GQuark, qs_len) = iter->quark;
+ } else {
+ size_t qs_len = ranges->len;
+
+ g_array_set_size(ranges, qs_len + 1);
+ g_array_index(ranges, GQuark, qs_len) = iter->quark;
+ }
+ }
+ if (!ranges) {
+ if (!qs)
+ return NULL;
+ ranges = qs;
+ g_array_ref(ranges);
+ }
+ return ranges;