- _struct->scope = new_declaration_scope(parent_scope);
- _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);
+ /*
+ * 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 = bt_new_definition_path(parent_scope, field_name, root_name);
+ _struct->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+
+ ret = bt_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 bt_definition **field =
+ (struct bt_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;