2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
9 #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
11 #include "lib/assert-pre.h"
12 #include <babeltrace2/trace-ir/clock-class.h>
13 #include <babeltrace2/trace-ir/field-class.h>
14 #include "common/macros.h"
15 #include "common/common.h"
16 #include "lib/object.h"
17 #include <babeltrace2/types.h>
22 #define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc) \
23 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
24 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
25 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
26 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
28 #define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name) \
29 _name " is not an integer field class: %![fc-]+F"
31 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc) \
32 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
33 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION)
35 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name) \
36 _name " is not an unsigned integer field class: %![fc-]+F"
39 #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc) \
40 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
41 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
43 #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name) \
44 _name " is not a signed integer field class: %![fc-]+F"
46 #define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc) \
47 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
48 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
50 #define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name) \
51 _name " is not an enumeration field class: %![fc-]+F"
53 #define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc) \
54 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
55 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || \
56 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD)
58 #define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name) \
59 _name " is not an array field class: %![fc-]+F"
61 #define _BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc) \
62 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD || \
63 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
64 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
65 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
67 #define _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name) \
68 _name " is not an option field class: %![fc-]+F"
70 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc) \
71 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
72 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
73 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
75 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name) \
76 _name " is not an option field class with a selector: %![fc-]+F"
78 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc) \
79 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
80 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
82 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name) \
83 _name " is not an option field class with an integer selector: %![fc-]+F"
85 #define _BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc) \
86 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD || \
87 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
88 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
90 #define _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name) \
91 _name " is not a variant field class: %![fc-]+F"
93 #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc) \
94 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
95 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
97 #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name) \
98 _name " is not a variant field class with a selector: %![fc-]+F"
100 #define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type) \
101 (((const struct bt_field_class *) (_fc))->type == (_type))
103 #define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name) \
104 _name " has the wrong type: expected-type=%s, %![fc-]+F"
106 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
107 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
108 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
110 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
111 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
112 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
114 #define BT_ASSERT_PRE_FC_IS_SIGNED_INT(_fc, _name) \
115 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \
116 _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
118 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
119 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
120 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
122 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
123 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
124 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
126 #define BT_ASSERT_PRE_FC_IS_OPTION(_fc, _name) \
127 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \
128 _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
130 #define BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(_fc, _name) \
131 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
132 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
134 #define BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \
135 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
136 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
138 #define BT_ASSERT_PRE_FC_IS_VARIANT(_fc, _name) \
139 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \
140 _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
142 #define BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL(_fc, _name) \
143 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
144 _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
146 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
147 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
148 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
149 bt_common_field_class_type_string(_type), (_fc))
151 #define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name) \
152 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
153 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
155 #define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name) \
156 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
157 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
159 #define BT_ASSERT_PRE_DEV_FC_IS_SIGNED_INT(_fc, _name) \
160 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \
161 _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
163 #define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name) \
164 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
165 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
167 #define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name) \
168 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
169 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
171 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION(_fc, _name) \
172 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \
173 _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
175 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_SEL(_fc, _name) \
176 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
177 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
179 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \
180 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
181 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
183 #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT(_fc, _name) \
184 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \
185 _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
187 #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(_fc, _name) \
188 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
189 _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
191 #define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name) \
192 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
193 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
194 bt_common_field_class_type_string(_type), (_fc))
196 #define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name) \
197 BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc), \
198 (_name), ": %!+F", (_fc))
200 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
201 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
202 struct bt_field_class_enumeration_mapping, (_index)))
204 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
205 (&g_array_index((_mapping)->ranges, \
206 struct bt_field_class_enumeration_mapping_range, (_index)))
209 struct bt_field_class
;
211 struct bt_field_class
{
212 struct bt_object base
;
213 enum bt_field_class_type type
;
217 struct bt_value
*user_attributes
;
220 * This flag indicates whether or not this field class is part
223 bool part_of_trace_class
;
226 struct bt_field_class_bool
{
227 struct bt_field_class common
;
230 struct bt_field_class_bit_array
{
231 struct bt_field_class common
;
235 struct bt_field_class_integer
{
236 struct bt_field_class common
;
239 * Value range of fields built from this integer field class:
240 * this is an equivalent integer size in bits. More formally,
243 * Unsigned range: [0, 2^n - 1]
244 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
248 enum bt_field_class_integer_preferred_display_base base
;
251 struct bt_field_class_enumeration_mapping
{
255 const struct bt_integer_range_set
*range_set
;
258 struct bt_field_class_enumeration_unsigned_mapping
;
259 struct bt_field_class_enumeration_signed_mapping
;
261 struct bt_field_class_enumeration
{
262 struct bt_field_class_integer common
;
264 /* Array of `struct bt_field_class_enumeration_mapping *` */
268 * This is an array of `const char *` which acts as a temporary
269 * (potentially growing) buffer for
270 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
272 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
274 * The actual strings are owned by the mappings above.
276 GPtrArray
*label_buf
;
279 struct bt_field_class_real
{
280 struct bt_field_class common
;
283 struct bt_field_class_string
{
284 struct bt_field_class common
;
287 /* A named field class is a (name, field class) pair */
288 struct bt_named_field_class
{
292 struct bt_value
*user_attributes
;
295 struct bt_field_class
*fc
;
300 struct bt_field_class_structure_member
;
301 struct bt_field_class_variant_option
;
302 struct bt_field_class_variant_with_selector_field_integer_unsigned_option
;
303 struct bt_field_class_variant_with_selector_field_integer_signed_option
;
305 struct bt_field_class_named_field_class_container
{
306 struct bt_field_class common
;
309 * Key: `const char *`, not owned by this (owned by named field
310 * class objects contained in `named_fcs` below).
312 GHashTable
*name_to_index
;
314 /* Array of `struct bt_named_field_class *` */
315 GPtrArray
*named_fcs
;
318 struct bt_field_class_structure
{
319 struct bt_field_class_named_field_class_container common
;
322 struct bt_field_class_array
{
323 struct bt_field_class common
;
326 struct bt_field_class
*element_fc
;
329 struct bt_field_class_array_static
{
330 struct bt_field_class_array common
;
334 struct bt_field_class_array_dynamic
{
335 struct bt_field_class_array common
;
338 struct bt_field_class
*length_fc
;
341 struct bt_field_path
*length_field_path
;
344 struct bt_field_class_option
{
345 struct bt_field_class common
;
348 struct bt_field_class
*content_fc
;
351 struct bt_field_class_option_with_selector_field
{
352 struct bt_field_class_option common
;
355 struct bt_field_class
*selector_fc
;
358 struct bt_field_path
*selector_field_path
;
361 struct bt_field_class_option_with_selector_field_bool
{
362 struct bt_field_class_option_with_selector_field common
;
365 bool sel_is_reversed
;
368 struct bt_field_class_option_with_selector_field_integer
{
369 struct bt_field_class_option_with_selector_field common
;
372 const struct bt_integer_range_set
*range_set
;
375 /* Variant FC (with selector) option: named field class + range set */
376 struct bt_field_class_variant_with_selector_field_option
{
377 struct bt_named_field_class common
;
380 const struct bt_integer_range_set
*range_set
;
383 struct bt_field_class_variant
{
385 * Depending on the variant field class type, the contained
386 * named field classes are of type
387 * `struct bt_named_field_class *` if the variant field class
388 * doesn't have a selector, or
389 * `struct bt_field_class_variant_with_selector_field_option *`
392 struct bt_field_class_named_field_class_container common
;
395 struct bt_field_class_variant_with_selector_field
{
396 struct bt_field_class_variant common
;
399 * Owned by this, but never dereferenced: only use to find it
402 const struct bt_field_class
*selector_fc
;
405 struct bt_field_path
*selector_field_path
;
409 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
412 # define bt_field_class_freeze _bt_field_class_freeze
414 # define bt_field_class_freeze(_fc) ((void) _fc)
418 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
421 # define bt_named_field_class_freeze _bt_named_field_class_freeze
423 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
427 * This function recursively marks `field_class` and its children as
428 * being part of a trace. This is used to validate that all field classes
429 * are used at a single location within trace objects even if they are
430 * shared objects for other purposes.
433 void bt_field_class_make_part_of_trace_class(
434 const struct bt_field_class
*field_class
);
436 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */