1 #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 #include "lib/assert-pre.h"
28 #include <babeltrace2/trace-ir/clock-class.h>
29 #include <babeltrace2/trace-ir/field-class.h>
30 #include "common/macros.h"
31 #include "common/common.h"
32 #include "lib/object.h"
33 #include <babeltrace2/types.h>
37 #define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc) \
38 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
39 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
40 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
41 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
43 #define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name) \
44 _name " is not an integer field class: %![fc-]+F"
46 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc) \
47 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
48 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION)
50 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name) \
51 _name " is not an unsigned integer field class: %![fc-]+F"
54 #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc) \
55 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
56 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
58 #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name) \
59 _name " is not a signed integer field class: %![fc-]+F"
61 #define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc) \
62 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
63 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
65 #define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name) \
66 _name " is not an enumeration field class: %![fc-]+F"
68 #define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc) \
69 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
70 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || \
71 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD)
73 #define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name) \
74 _name " is not an array field class: %![fc-]+F"
76 #define _BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc) \
77 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD || \
78 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
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_FMT(_name) \
83 _name " is not an option field class: %![fc-]+F"
85 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc) \
86 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
87 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
88 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
90 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name) \
91 _name " is not an option field class with a selector: %![fc-]+F"
93 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc) \
94 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
95 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
97 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name) \
98 _name " is not an option field class with an integer selector: %![fc-]+F"
100 #define _BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc) \
101 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD || \
102 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
103 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
105 #define _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name) \
106 _name " is not a variant field class: %![fc-]+F"
108 #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc) \
109 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
110 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
112 #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name) \
113 _name " is not a variant field class with a selector: %![fc-]+F"
115 #define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type) \
116 (((const struct bt_field_class *) (_fc))->type == (_type))
118 #define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name) \
119 _name " has the wrong type: expected-type=%s, %![fc-]+F"
121 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
122 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
123 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
125 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
126 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
127 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
129 #define BT_ASSERT_PRE_FC_IS_SIGNED_INT(_fc, _name) \
130 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \
131 _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
133 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
134 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
135 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
137 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
138 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
139 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
141 #define BT_ASSERT_PRE_FC_IS_OPTION(_fc, _name) \
142 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \
143 _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
145 #define BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(_fc, _name) \
146 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
147 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
149 #define BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \
150 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
151 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
153 #define BT_ASSERT_PRE_FC_IS_VARIANT(_fc, _name) \
154 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \
155 _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
157 #define BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL(_fc, _name) \
158 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
159 _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
161 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
162 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
163 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
164 bt_common_field_class_type_string(_type), (_fc))
166 #define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name) \
167 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
168 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
170 #define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name) \
171 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
172 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
174 #define BT_ASSERT_PRE_DEV_FC_IS_SIGNED_INT(_fc, _name) \
175 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \
176 _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
178 #define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name) \
179 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
180 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
182 #define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name) \
183 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
184 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
186 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION(_fc, _name) \
187 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \
188 _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
190 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_SEL(_fc, _name) \
191 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
192 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
194 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \
195 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
196 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
198 #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT(_fc, _name) \
199 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \
200 _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
202 #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(_fc, _name) \
203 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
204 _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
206 #define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name) \
207 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
208 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
209 bt_common_field_class_type_string(_type), (_fc))
211 #define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name) \
212 BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc), \
213 (_name), ": %!+F", (_fc))
215 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
216 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
217 struct bt_field_class_enumeration_mapping, (_index)))
219 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
220 (&g_array_index((_mapping)->ranges, \
221 struct bt_field_class_enumeration_mapping_range, (_index)))
224 struct bt_field_class
;
226 struct bt_field_class
{
227 struct bt_object base
;
228 enum bt_field_class_type type
;
232 struct bt_value
*user_attributes
;
235 * This flag indicates whether or not this field class is part
238 bool part_of_trace_class
;
241 struct bt_field_class_bool
{
242 struct bt_field_class common
;
245 struct bt_field_class_bit_array
{
246 struct bt_field_class common
;
250 struct bt_field_class_integer
{
251 struct bt_field_class common
;
254 * Value range of fields built from this integer field class:
255 * this is an equivalent integer size in bits. More formally,
258 * Unsigned range: [0, 2^n - 1]
259 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
263 enum bt_field_class_integer_preferred_display_base base
;
266 struct bt_field_class_enumeration_mapping
{
270 const struct bt_integer_range_set
*range_set
;
273 struct bt_field_class_enumeration_unsigned_mapping
;
274 struct bt_field_class_enumeration_signed_mapping
;
276 struct bt_field_class_enumeration
{
277 struct bt_field_class_integer common
;
279 /* Array of `struct bt_field_class_enumeration_mapping *` */
283 * This is an array of `const char *` which acts as a temporary
284 * (potentially growing) buffer for
285 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
287 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
289 * The actual strings are owned by the mappings above.
291 GPtrArray
*label_buf
;
294 struct bt_field_class_real
{
295 struct bt_field_class common
;
298 struct bt_field_class_string
{
299 struct bt_field_class common
;
302 /* A named field class is a (name, field class) pair */
303 struct bt_named_field_class
{
307 struct bt_value
*user_attributes
;
310 struct bt_field_class
*fc
;
315 struct bt_field_class_structure_member
;
316 struct bt_field_class_variant_option
;
317 struct bt_field_class_variant_with_selector_field_integer_unsigned_option
;
318 struct bt_field_class_variant_with_selector_field_integer_signed_option
;
320 struct bt_field_class_named_field_class_container
{
321 struct bt_field_class common
;
324 * Key: `const char *`, not owned by this (owned by named field
325 * class objects contained in `named_fcs` below).
327 GHashTable
*name_to_index
;
329 /* Array of `struct bt_named_field_class *` */
330 GPtrArray
*named_fcs
;
333 struct bt_field_class_structure
{
334 struct bt_field_class_named_field_class_container common
;
337 struct bt_field_class_array
{
338 struct bt_field_class common
;
341 struct bt_field_class
*element_fc
;
344 struct bt_field_class_array_static
{
345 struct bt_field_class_array common
;
349 struct bt_field_class_array_dynamic
{
350 struct bt_field_class_array common
;
353 struct bt_field_class
*length_fc
;
356 struct bt_field_path
*length_field_path
;
359 struct bt_field_class_option
{
360 struct bt_field_class common
;
363 struct bt_field_class
*content_fc
;
366 struct bt_field_class_option_with_selector_field
{
367 struct bt_field_class_option common
;
370 struct bt_field_class
*selector_fc
;
373 struct bt_field_path
*selector_field_path
;
376 struct bt_field_class_option_with_selector_field_bool
{
377 struct bt_field_class_option_with_selector_field common
;
380 bool sel_is_reversed
;
383 struct bt_field_class_option_with_selector_field_integer
{
384 struct bt_field_class_option_with_selector_field common
;
387 const struct bt_integer_range_set
*range_set
;
390 /* Variant FC (with selector) option: named field class + range set */
391 struct bt_field_class_variant_with_selector_field_option
{
392 struct bt_named_field_class common
;
395 const struct bt_integer_range_set
*range_set
;
398 struct bt_field_class_variant
{
400 * Depending on the variant field class type, the contained
401 * named field classes are of type
402 * `struct bt_named_field_class *` if the variant field class
403 * doesn't have a selector, or
404 * `struct bt_field_class_variant_with_selector_field_option *`
407 struct bt_field_class_named_field_class_container common
;
410 struct bt_field_class_variant_with_selector_field
{
411 struct bt_field_class_variant common
;
414 * Owned by this, but never dereferenced: only use to find it
417 const struct bt_field_class
*selector_fc
;
420 struct bt_field_path
*selector_field_path
;
424 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
427 # define bt_field_class_freeze _bt_field_class_freeze
429 # define bt_field_class_freeze(_fc) ((void) _fc)
433 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
436 # define bt_named_field_class_freeze _bt_named_field_class_freeze
438 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
442 * This function recursively marks `field_class` and its children as
443 * being part of a trace. This is used to validate that all field classes
444 * are used at a single location within trace objects even if they are
445 * shared objects for other purposes.
448 void bt_field_class_make_part_of_trace_class(
449 const struct bt_field_class
*field_class
);
451 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */