- struct type_class_variant *variant_class;
- struct type_class *type_class;
- int ret;
-
- variant_class = g_new(struct type_class_variant, 1);
- type_class = &variant_class->p;
- variant_class->fields_by_tag = g_hash_table_new(g_direct_hash,
- g_direct_equal);
- variant_class->fields = g_array_sized_new(FALSE, TRUE,
- sizeof(struct type_class_field),
- DEFAULT_NR_STRUCT_FIELDS);
- type_class->name = g_quark_from_string(name);
- type_class->alignment = 1;
- type_class->copy = variant_copy;
- type_class->class_free = _variant_type_class_free;
- type_class->type_new = _variant_type_new;
- type_class->type_free = _variant_type_free;
- type_class->ref = 1;
-
- if (type_class->name) {
- ret = register_type(type_class);
- if (ret)
- goto error_register;
- }
- return struct_class;
-
-error_register:
- g_hash_table_destroy(variant_class->fields_by_tag);
- g_array_free(variant_class->fields, true);
- g_free(variant_class);
- return NULL;
+ struct declaration_variant *variant_declaration;
+ struct declaration *declaration;
+
+ variant_declaration = g_new(struct declaration_variant, 1);
+ declaration = &variant_declaration->p;
+ variant_declaration->fields_by_tag = g_hash_table_new(g_direct_hash,
+ g_direct_equal);
+ variant_declaration->fields = g_array_sized_new(FALSE, TRUE,
+ sizeof(struct declaration_field),
+ DEFAULT_NR_STRUCT_FIELDS);
+ variant_declaration->scope = new_declaration_scope(parent_scope);
+ declaration->id = CTF_TYPE_VARIANT;
+ declaration->name = g_quark_from_string(name);
+ declaration->alignment = 1;
+ declaration->copy = variant_copy;
+ declaration->declaration_free = _variant_declaration_free;
+ declaration->definition_new = _variant_definition_new;
+ declaration->definition_free = _variant_definition_free;
+ declaration->ref = 1;
+ return variant_declaration;