- variant->scope = new_definition_scope(parent_scope);
- 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->definition =
- type_field->type->definition_new(type_field->type,
- variant->scope);
+ /*
+ * Use INT_MAX order to ensure that all fields of the parent
+ * scope are seen as being prior to this scope.
+ */
+ variant->p.index = root_name ? INT_MAX : index;
+ variant->p.name = field_name;
+ variant->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+ variant->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+
+ ret = bt_register_field_definition(field_name, &variant->p,
+ parent_scope);
+ assert(!ret);
+
+ variant->enum_tag = bt_lookup_path_definition(variant->p.scope->scope_path,
+ variant_declaration->tag_name,
+ parent_scope);
+
+ if (!variant->enum_tag)
+ goto error;
+ bt_definition_ref(variant->enum_tag);
+ variant->fields = g_ptr_array_sized_new(variant_declaration->untagged_variant->fields->len);
+ g_ptr_array_set_size(variant->fields, variant_declaration->untagged_variant->fields->len);
+ for (i = 0; i < variant_declaration->untagged_variant->fields->len; i++) {
+ struct declaration_field *declaration_field =
+ &g_array_index(variant_declaration->untagged_variant->fields,
+ struct declaration_field, i);
+ struct bt_definition **field =
+ (struct bt_definition **) &g_ptr_array_index(variant->fields, i);
+
+ /*
+ * All child definition are at index 0, because they are
+ * various choices of the same field.
+ */
+ *field = declaration_field->declaration->definition_new(declaration_field->declaration,
+ variant->p.scope,
+ declaration_field->name, 0, NULL);
+ if (!*field)
+ goto error;