X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fstruct.c;h=779cca5c504064d3c03bb4a86962ab58a1917808;hp=92ede5866d65130f90ecc50bf381374eadefb7a9;hb=c13cbf74f302eb64e051045ce31f712a5e05203c;hpb=6ee5115efee00adab0c8f384bc9c0f38fed8a84e diff --git a/types/struct.c b/types/struct.c index 92ede586..779cca5c 100644 --- a/types/struct.c +++ b/types/struct.c @@ -60,6 +60,7 @@ void _struct_type_free(struct type *type) container_of(type, struct type_struct, p); unsigned long i; + free_type_scope(struct_type->scope); g_hash_table_destroy(struct_type->fields_by_name); for (i = 0; i < struct_type->fields->len; i++) { @@ -72,7 +73,8 @@ void _struct_type_free(struct type *type) g_free(struct_type); } -struct type_struct *struct_type_new(const char *name) +struct type_struct *struct_type_new(const char *name, + struct type_scope *parent_scope) { struct type_struct *struct_type; struct type *type; @@ -84,6 +86,8 @@ struct type_struct *struct_type_new(const char *name) struct_type->fields = g_array_sized_new(FALSE, TRUE, sizeof(struct type_field), DEFAULT_NR_STRUCT_FIELDS); + struct_type->scope = new_type_scope(parent_scope); + type->id = CTF_TYPE_STRUCT; type->name = g_quark_from_string(name); type->alignment = 1; type->copy = struct_copy; @@ -102,6 +106,8 @@ struct declaration * struct type_struct *struct_type = container_of(type, struct type_struct, p); struct declaration_struct *_struct; + unsigned long i; + int ret; _struct = g_new(struct declaration_struct, 1); type_ref(&struct_type->p); @@ -112,6 +118,22 @@ struct declaration * _struct->fields = g_array_sized_new(FALSE, TRUE, sizeof(struct field), DEFAULT_NR_STRUCT_FIELDS); + g_array_set_size(_struct->fields, struct_type->fields->len); + for (i = 0; i < struct_type->fields->len; i++) { + struct type_field *type_field = + &g_array_index(struct_type->fields, + struct type_field, i); + struct field *field = &g_array_index(_struct->fields, + struct field, i); + + field->name = type_field->name; + field->declaration = + type_field->type->declaration_new(type_field->type, + _struct->scope); + ret = register_declaration(field->name, + field->declaration, _struct->scope); + assert(!ret); + } return &_struct->p; } @@ -122,6 +144,7 @@ void _struct_declaration_free(struct declaration *declaration) container_of(declaration, struct declaration_struct, p); unsigned long i; + assert(_struct->fields->len == _struct->type->fields->len); for (i = 0; i < _struct->fields->len; i++) { struct field *field = &g_array_index(_struct->fields, struct field, i);