container_of(type, struct type_variant, p);
unsigned long i;
+ free_type_scope(variant_type->scope);
g_hash_table_destroy(variant_type->fields_by_tag);
for (i = 0; i < variant_type->fields->len; i++) {
g_free(variant_type);
}
-struct type_variant *variant_type_new(const char *name)
+struct type_variant *variant_type_new(const char *name,
+ struct type_scope *parent_scope)
{
struct type_variant *variant_type;
struct type *type;
variant_type->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct type_field),
DEFAULT_NR_STRUCT_FIELDS);
+ variant_type->scope = new_type_scope(parent_scope);
+ type->id = CTF_TYPE_VARIANT;
type->name = g_quark_from_string(name);
type->alignment = 1;
type->copy = variant_copy;
struct type_variant *variant_type =
container_of(type, struct type_variant, p);
struct declaration_variant *variant;
+ unsigned long i;
variant = g_new(struct declaration_variant, 1);
type_ref(&variant_type->p);
variant->fields = g_array_sized_new(FALSE, TRUE,
sizeof(struct field),
DEFAULT_NR_STRUCT_FIELDS);
+ g_array_set_size(variant->fields, variant_type->fields->len);
+ for (i = 0; i < variant_type->fields->len; i++) {
+ struct type_field *type_field =
+ &g_array_index(variant_type->fields,
+ struct type_field, i);
+ struct field *field = &g_array_index(variant->fields,
+ struct field, i);
+
+ field->name = type_field->name;
+ field->declaration =
+ type_field->type->declaration_new(type_field->type,
+ variant->scope);
+ }
variant->current_field = NULL;
return &variant->p;
}
container_of(declaration, struct declaration_variant, p);
unsigned long i;
+ assert(variant->fields->len == variant->type->fields->len);
for (i = 0; i < variant->fields->len; i++) {
struct field *field = &g_array_index(variant->fields,
struct field, i);