- sequence->scope = new_declaration_scope(parent_scope);
- len_parent = sequence_type->len_type->p.declaration_new(&sequence_type->len_type->p,
- parent_scope);
- sequence->len =
- container_of(len_parent, struct declaration_integer, p);
- sequence->current_element.declaration =
- sequence_type->elem->declaration_new(sequence_type->elem,
- parent_scope);
+ /*
+ * 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 = bt_new_definition_path(parent_scope, field_name, root_name);
+ sequence->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+ ret = bt_register_field_definition(field_name, &sequence->p,
+ parent_scope);
+ assert(!ret);
+ len_parent = bt_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;
+ }
+ bt_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;
+ }
+ }
+ }
+
+ sequence->elems = g_ptr_array_new();