- sequence_type = g_new(struct type_sequence, 1);
- type = &sequence_type->p;
- assert(!len_type->signedness);
- type_ref(&len_type->p);
- sequence_type->len_type = len_type;
- type_ref(elem_type);
- sequence_type->elem = elem_type;
- type->name = g_quark_from_string(name);
- type->alignment = max(len_type->p.alignment, elem_type->alignment);
- type->copy = sequence_copy;
- type->type_free = _sequence_type_free;
- type->declaration_new = _sequence_declaration_new;
- type->declaration_free = _sequence_declaration_free;
- type->ref = 1;
-
- if (type->name) {
- ret = register_type(type);
- if (ret)
- goto error_register;
+ sequence = g_new(struct definition_sequence, 1);
+ declaration_ref(&sequence_declaration->p);
+ sequence->p.declaration = declaration;
+ sequence->declaration = sequence_declaration;
+ sequence->p.ref = 1;
+ /*
+ * Use INT_MAX order to ensure that all fields of the parent
+ * scope are seen as being prior to this scope.
+ */
+ sequence->p.index = root_name ? INT_MAX : index;
+ sequence->p.name = field_name;
+ sequence->p.path = new_definition_path(parent_scope, field_name, root_name);
+ sequence->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+ ret = register_field_definition(field_name, &sequence->p,
+ parent_scope);
+ assert(!ret);
+ len_parent = lookup_path_definition(sequence->p.scope->scope_path,
+ sequence_declaration->length_name,
+ parent_scope);
+ if (!len_parent) {
+ printf("[error] Lookup for sequence length field failed.\n");
+ goto error;
+ }
+ sequence->length =
+ container_of(len_parent, struct definition_integer, p);
+ if (sequence->length->declaration->signedness) {
+ printf("[error] Sequence length field should be unsigned.\n");
+ goto error;
+ }
+ definition_ref(len_parent);
+
+ sequence->string = NULL;
+ sequence->elems = NULL;
+
+ if (sequence_declaration->elem->id == CTF_TYPE_INTEGER) {
+ struct declaration_integer *integer_declaration =
+ container_of(sequence_declaration->elem, struct declaration_integer, p);
+
+ if (integer_declaration->encoding == CTF_STRING_UTF8
+ || integer_declaration->encoding == CTF_STRING_ASCII) {
+
+ sequence->string = g_string_new("");
+
+ if (integer_declaration->len == CHAR_BIT
+ && integer_declaration->p.alignment == CHAR_BIT) {
+ return &sequence->p;
+ }
+ }