X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fvariant.c;h=ea20808b7205f1e31ea1fee4dce603e5584359bf;hp=91b323ffa70cc6f47f0f02e794abfdf28665d245;hb=05628561ca57ff5d269571a72a12cb86854c5f70;hpb=6ee5115efee00adab0c8f384bc9c0f38fed8a84e diff --git a/types/variant.c b/types/variant.c index 91b323ff..ea20808b 100644 --- a/types/variant.c +++ b/types/variant.c @@ -54,6 +54,7 @@ void _variant_type_free(struct type *type) 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++) { @@ -66,7 +67,8 @@ void _variant_type_free(struct type *type) 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; @@ -78,6 +80,8 @@ struct type_variant *variant_type_new(const char *name) 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; @@ -96,6 +100,7 @@ struct declaration * 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); @@ -106,6 +111,19 @@ struct declaration * 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; } @@ -117,6 +135,7 @@ void _variant_declaration_free(struct declaration *declaration) 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);