2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
10 #include "common/assert.h"
12 #include "ctf-meta-visitors.hpp"
14 static int update_field_class_stored_value_index(struct ctf_field_class
*fc
,
15 struct ctf_trace_class
*tc
,
16 struct ctf_stream_class
*sc
,
17 struct ctf_event_class
*ec
)
21 struct ctf_field_path
*field_path
= NULL
;
22 struct ctf_field_class_int
*tgt_fc
= NULL
;
23 uint64_t *stored_value_index
= NULL
;
30 case CTF_FIELD_CLASS_TYPE_VARIANT
:
32 ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
34 field_path
= &var_fc
->tag_path
;
35 stored_value_index
= &var_fc
->stored_tag_index
;
36 tgt_fc
= &var_fc
->tag_fc
->base
;
39 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
41 struct ctf_field_class_sequence
*seq_fc
= ctf_field_class_as_sequence(fc
);
43 field_path
= &seq_fc
->length_path
;
44 stored_value_index
= &seq_fc
->stored_length_index
;
45 tgt_fc
= seq_fc
->length_fc
;
54 BT_ASSERT(tgt_fc
->base
.base
.type
== CTF_FIELD_CLASS_TYPE_INT
||
55 tgt_fc
->base
.base
.type
== CTF_FIELD_CLASS_TYPE_ENUM
);
56 if (tgt_fc
->storing_index
>= 0) {
57 /* Already storing its value */
58 *stored_value_index
= (uint64_t) tgt_fc
->storing_index
;
60 /* Not storing its value: allocate new index */
61 tgt_fc
->storing_index
= tc
->stored_value_count
;
62 *stored_value_index
= (uint64_t) tgt_fc
->storing_index
;
63 tc
->stored_value_count
++;
68 case CTF_FIELD_CLASS_TYPE_STRUCT
:
70 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
72 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
73 struct ctf_named_field_class
*named_fc
=
74 ctf_field_class_struct_borrow_member_by_index(struct_fc
, i
);
76 ret
= update_field_class_stored_value_index(named_fc
->fc
, tc
, sc
, ec
);
84 case CTF_FIELD_CLASS_TYPE_VARIANT
:
86 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
88 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
89 struct ctf_named_field_class
*named_fc
=
90 ctf_field_class_variant_borrow_option_by_index(var_fc
, i
);
92 ret
= update_field_class_stored_value_index(named_fc
->fc
, tc
, sc
, ec
);
100 case CTF_FIELD_CLASS_TYPE_ARRAY
:
101 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
103 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
105 ret
= update_field_class_stored_value_index(array_fc
->elem_fc
, tc
, sc
, ec
);
120 int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class
*ctf_tc
)
124 if (!ctf_tc
->is_translated
) {
125 update_field_class_stored_value_index(ctf_tc
->packet_header_fc
, ctf_tc
, NULL
, NULL
);
128 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
130 ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
132 if (!sc
->is_translated
) {
133 update_field_class_stored_value_index(sc
->packet_context_fc
, ctf_tc
, sc
, NULL
);
134 update_field_class_stored_value_index(sc
->event_header_fc
, ctf_tc
, sc
, NULL
);
135 update_field_class_stored_value_index(sc
->event_common_context_fc
, ctf_tc
, sc
, NULL
);
138 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
139 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[j
];
141 if (!ec
->is_translated
) {
142 update_field_class_stored_value_index(ec
->spec_context_fc
, ctf_tc
, sc
, ec
);
143 update_field_class_stored_value_index(ec
->payload_fc
, ctf_tc
, sc
, ec
);