- struct_class = g_new(struct type_class_struct, 1);
- type_class = &struct_class->p;
-
- struct_class->fields_by_name = g_hash_table_new(g_direct_hash,
- g_direct_equal);
- struct_class->fields = g_array_sized_new(false, false,
- sizeof(struct field),
- DEFAULT_NR_STRUCT_FIELDS);
- type_class->name = g_quark_from_string(name);
- type_class->alignment = 1;
- type_class->copy = struct_copy;
- type_class->free = _struct_type_free;
- type_class->ref = 1;
-
- if (type_class->name) {
- ret = ctf_register_type(type_class);
- if (ret)
- goto error_register;
+ _struct = g_new(struct definition_struct, 1);
+ declaration_ref(&struct_declaration->p);
+ _struct->p.declaration = declaration;
+ _struct->declaration = struct_declaration;
+ _struct->p.ref = 1;
+ /*
+ * Use INT_MAX order to ensure that all fields of the parent
+ * scope are seen as being prior to this scope.
+ */
+ _struct->p.index = root_name ? INT_MAX : index;
+ _struct->p.name = field_name;
+ _struct->p.path = new_definition_path(parent_scope, field_name, root_name);
+ _struct->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+
+ ret = register_field_definition(field_name, &_struct->p,
+ parent_scope);
+ assert(!ret || ret == -EPERM);
+
+ _struct->fields = g_ptr_array_sized_new(DEFAULT_NR_STRUCT_FIELDS);
+ g_ptr_array_set_size(_struct->fields, struct_declaration->fields->len);
+ for (i = 0; i < struct_declaration->fields->len; i++) {
+ struct declaration_field *declaration_field =
+ &g_array_index(struct_declaration->fields,
+ struct declaration_field, i);
+ struct definition **field =
+ (struct definition **) &g_ptr_array_index(_struct->fields, i);
+
+ *field = declaration_field->declaration->definition_new(declaration_field->declaration,
+ _struct->p.scope,
+ declaration_field->name, i, NULL);
+ if (!*field)
+ goto error;