- return &g_array_index(variant_class->fields, struct type_class_field, index);
-}
-
-/*
- * tag_instance is assumed to be an enumeration.
- */
-int variant_type_set_tag(struct type_variant *variant,
- struct type *enum_tag_instance)
-{
- struct type_enum *_enum =
- container_of(struct type_enum, variant->enum_tag, p);
- struct type_class_enum *enum_class = _enum->_class;
- int missing_field = 0;
- unsigned long i;
-
- /*
- * Strictly speaking, each enumerator must map to a field of the
- * variant. However, we are even stricter here by requiring that each
- * variant choice map to an enumerator too. We then validate that the
- * number of enumerators equals the number of variant choices.
- */
- if (variant->_class->fields->len != enum_get_nr_enumerators(enum_class))
- return -EPERM;
-
- for (i = 0; i < variant->_class->fields->len; i++) {
- struct type_class_field *field_class =
- &g_array_index(variant->_class->fields,
- struct type_class_field, i);
- if (!enum_quark_to_range_set(enum_class, field_class->name)) {
- missing_field = 1;
- break;
- }
- }
- if (missing_field)
- return -EPERM;
-
- /*
- * Check the enumeration: it must map each value to one and only one
- * enumerator tag.
- * TODO: we should also check that each range map to one and only one
- * tag. For the moment, we will simply check this dynamically in
- * variant_type_get_current_field().
- */
-
- /* Set the enum tag field */
- variant->enum_tag = enum_tag_instance;
- return 0;