2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #include <babeltrace2/babeltrace.h>
8 #include "common/macros.h"
9 #include "common/assert.h"
15 #include "ctf-meta-visitors.hpp"
18 int update_field_class_stored_value_index(struct ctf_field_class
*fc
,
19 struct ctf_trace_class
*tc
,
20 struct ctf_stream_class
*sc
,
21 struct ctf_event_class
*ec
)
25 struct ctf_field_path
*field_path
= NULL
;
26 struct ctf_field_class_int
*tgt_fc
= NULL
;
27 uint64_t *stored_value_index
= NULL
;
34 case CTF_FIELD_CLASS_TYPE_VARIANT
:
36 ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
38 field_path
= &var_fc
->tag_path
;
39 stored_value_index
= &var_fc
->stored_tag_index
;
40 tgt_fc
= &var_fc
->tag_fc
->base
;
43 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
45 struct ctf_field_class_sequence
*seq_fc
= ctf_field_class_as_sequence(fc
);
47 field_path
= &seq_fc
->length_path
;
48 stored_value_index
= &seq_fc
->stored_length_index
;
49 tgt_fc
= seq_fc
->length_fc
;
58 BT_ASSERT(tgt_fc
->base
.base
.type
== CTF_FIELD_CLASS_TYPE_INT
||
59 tgt_fc
->base
.base
.type
== CTF_FIELD_CLASS_TYPE_ENUM
);
60 if (tgt_fc
->storing_index
>= 0) {
61 /* Already storing its value */
62 *stored_value_index
= (uint64_t) tgt_fc
->storing_index
;
64 /* Not storing its value: allocate new index */
65 tgt_fc
->storing_index
= tc
->stored_value_count
;
66 *stored_value_index
= (uint64_t) tgt_fc
->storing_index
;
67 tc
->stored_value_count
++;
72 case CTF_FIELD_CLASS_TYPE_STRUCT
:
74 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
76 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
77 struct ctf_named_field_class
*named_fc
=
78 ctf_field_class_struct_borrow_member_by_index(
81 ret
= update_field_class_stored_value_index(named_fc
->fc
,
90 case CTF_FIELD_CLASS_TYPE_VARIANT
:
92 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
94 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
95 struct ctf_named_field_class
*named_fc
=
96 ctf_field_class_variant_borrow_option_by_index(
99 ret
= update_field_class_stored_value_index(named_fc
->fc
,
108 case CTF_FIELD_CLASS_TYPE_ARRAY
:
109 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
111 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
113 ret
= update_field_class_stored_value_index(array_fc
->elem_fc
,
130 int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class
*ctf_tc
)
134 if (!ctf_tc
->is_translated
) {
135 update_field_class_stored_value_index(
136 ctf_tc
->packet_header_fc
, ctf_tc
, NULL
, NULL
);
139 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
141 ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
143 if (!sc
->is_translated
) {
144 update_field_class_stored_value_index(sc
->packet_context_fc
,
146 update_field_class_stored_value_index(sc
->event_header_fc
,
148 update_field_class_stored_value_index(
149 sc
->event_common_context_fc
, ctf_tc
, sc
, NULL
);
152 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
153 struct ctf_event_class
*ec
=
154 (ctf_event_class
*) sc
->event_classes
->pdata
[j
];
156 if (!ec
->is_translated
) {
157 update_field_class_stored_value_index(
158 ec
->spec_context_fc
, ctf_tc
, sc
, ec
);
159 update_field_class_stored_value_index(
160 ec
->payload_fc
, ctf_tc
, sc
, ec
);