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>
38 #define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc) \
39 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
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_UNSIGNED_ENUMERATION || \
42 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
44 #define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name) \
45 _name " is not an integer field class: %![fc-]+F"
47 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc) \
48 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
49 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION)
51 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name) \
52 _name " is not an unsigned integer field class: %![fc-]+F"
55 #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc) \
56 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
57 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
59 #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name) \
60 _name " is not a signed integer field class: %![fc-]+F"
62 #define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc) \
63 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
64 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
66 #define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name) \
67 _name " is not an enumeration field class: %![fc-]+F"
69 #define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc) \
70 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
71 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || \
72 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD)
74 #define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name) \
75 _name " is not an array field class: %![fc-]+F"
77 #define _BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc) \
78 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD || \
79 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
80 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
81 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
83 #define _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name) \
84 _name " is not an option field class: %![fc-]+F"
86 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc) \
87 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD || \
88 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
89 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
91 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name) \
92 _name " is not an option field class with a selector: %![fc-]+F"
94 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc) \
95 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
96 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
98 #define _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name) \
99 _name " is not an option field class with an integer selector: %![fc-]+F"
101 #define _BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc) \
102 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD || \
103 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
104 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
106 #define _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name) \
107 _name " is not a variant field class: %![fc-]+F"
109 #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc) \
110 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD || \
111 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD)
113 #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name) \
114 _name " is not a variant field class with a selector: %![fc-]+F"
116 #define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type) \
117 (((const struct bt_field_class *) (_fc))->type == (_type))
119 #define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name) \
120 _name " has the wrong type: expected-type=%s, %![fc-]+F"
122 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
123 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
124 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
126 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
127 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
128 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
130 #define BT_ASSERT_PRE_FC_IS_SIGNED_INT(_fc, _name) \
131 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \
132 _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
134 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
135 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
136 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
138 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
139 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
140 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
142 #define BT_ASSERT_PRE_FC_IS_OPTION(_fc, _name) \
143 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \
144 _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
146 #define BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(_fc, _name) \
147 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
148 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
150 #define BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \
151 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
152 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
154 #define BT_ASSERT_PRE_FC_IS_VARIANT(_fc, _name) \
155 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \
156 _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
158 #define BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL(_fc, _name) \
159 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
160 _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
162 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
163 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
164 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
165 bt_common_field_class_type_string(_type), (_fc))
167 #define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name) \
168 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
169 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
171 #define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name) \
172 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
173 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
175 #define BT_ASSERT_PRE_DEV_FC_IS_SIGNED_INT(_fc, _name) \
176 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \
177 _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc))
179 #define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name) \
180 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
181 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
183 #define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name) \
184 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
185 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
187 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION(_fc, _name) \
188 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_COND(_fc), \
189 _BT_ASSERT_PRE_FC_IS_OPTION_FMT(_name), (_fc))
191 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_SEL(_fc, _name) \
192 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_COND(_fc), \
193 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL_FMT(_name), (_fc))
195 #define BT_ASSERT_PRE_DEV_FC_IS_OPTION_WITH_INT_SEL(_fc, _name) \
196 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_COND(_fc), \
197 _BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL_FMT(_name), (_fc))
199 #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT(_fc, _name) \
200 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \
201 _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc))
203 #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(_fc, _name) \
204 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \
205 _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
207 #define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name) \
208 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
209 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
210 bt_common_field_class_type_string(_type), (_fc))
212 #define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name) \
213 BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc), \
214 (_name), ": %!+F", (_fc))
216 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
217 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
218 struct bt_field_class_enumeration_mapping, (_index)))
220 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
221 (&g_array_index((_mapping)->ranges, \
222 struct bt_field_class_enumeration_mapping_range, (_index)))
225 struct bt_field_class
;
227 struct bt_field_class
{
228 struct bt_object base
;
229 enum bt_field_class_type type
;
233 struct bt_value
*user_attributes
;
236 * This flag indicates whether or not this field class is part
239 bool part_of_trace_class
;
242 struct bt_field_class_bool
{
243 struct bt_field_class common
;
246 struct bt_field_class_bit_array
{
247 struct bt_field_class common
;
251 struct bt_field_class_integer
{
252 struct bt_field_class common
;
255 * Value range of fields built from this integer field class:
256 * this is an equivalent integer size in bits. More formally,
259 * Unsigned range: [0, 2^n - 1]
260 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
264 enum bt_field_class_integer_preferred_display_base base
;
267 struct bt_field_class_enumeration_mapping
{
271 const struct bt_integer_range_set
*range_set
;
274 struct bt_field_class_enumeration_unsigned_mapping
;
275 struct bt_field_class_enumeration_signed_mapping
;
277 struct bt_field_class_enumeration
{
278 struct bt_field_class_integer common
;
280 /* Array of `struct bt_field_class_enumeration_mapping *` */
284 * This is an array of `const char *` which acts as a temporary
285 * (potentially growing) buffer for
286 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
288 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
290 * The actual strings are owned by the mappings above.
292 GPtrArray
*label_buf
;
295 struct bt_field_class_real
{
296 struct bt_field_class common
;
299 struct bt_field_class_string
{
300 struct bt_field_class common
;
303 /* A named field class is a (name, field class) pair */
304 struct bt_named_field_class
{
308 struct bt_value
*user_attributes
;
311 struct bt_field_class
*fc
;
316 struct bt_field_class_structure_member
;
317 struct bt_field_class_variant_option
;
318 struct bt_field_class_variant_with_selector_field_integer_unsigned_option
;
319 struct bt_field_class_variant_with_selector_field_integer_signed_option
;
321 struct bt_field_class_named_field_class_container
{
322 struct bt_field_class common
;
325 * Key: `const char *`, not owned by this (owned by named field
326 * class objects contained in `named_fcs` below).
328 GHashTable
*name_to_index
;
330 /* Array of `struct bt_named_field_class *` */
331 GPtrArray
*named_fcs
;
334 struct bt_field_class_structure
{
335 struct bt_field_class_named_field_class_container common
;
338 struct bt_field_class_array
{
339 struct bt_field_class common
;
342 struct bt_field_class
*element_fc
;
345 struct bt_field_class_array_static
{
346 struct bt_field_class_array common
;
350 struct bt_field_class_array_dynamic
{
351 struct bt_field_class_array common
;
354 struct bt_field_class
*length_fc
;
357 struct bt_field_path
*length_field_path
;
360 struct bt_field_class_option
{
361 struct bt_field_class common
;
364 struct bt_field_class
*content_fc
;
367 struct bt_field_class_option_with_selector_field
{
368 struct bt_field_class_option common
;
371 struct bt_field_class
*selector_fc
;
374 struct bt_field_path
*selector_field_path
;
377 struct bt_field_class_option_with_selector_field_bool
{
378 struct bt_field_class_option_with_selector_field common
;
381 bool sel_is_reversed
;
384 struct bt_field_class_option_with_selector_field_integer
{
385 struct bt_field_class_option_with_selector_field common
;
388 const struct bt_integer_range_set
*range_set
;
391 /* Variant FC (with selector) option: named field class + range set */
392 struct bt_field_class_variant_with_selector_field_option
{
393 struct bt_named_field_class common
;
396 const struct bt_integer_range_set
*range_set
;
399 struct bt_field_class_variant
{
401 * Depending on the variant field class type, the contained
402 * named field classes are of type
403 * `struct bt_named_field_class *` if the variant field class
404 * doesn't have a selector, or
405 * `struct bt_field_class_variant_with_selector_field_option *`
408 struct bt_field_class_named_field_class_container common
;
411 struct bt_field_class_variant_with_selector_field
{
412 struct bt_field_class_variant common
;
415 * Owned by this, but never dereferenced: only use to find it
418 const struct bt_field_class
*selector_fc
;
421 struct bt_field_path
*selector_field_path
;
425 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
428 # define bt_field_class_freeze _bt_field_class_freeze
430 # define bt_field_class_freeze(_fc) ((void) _fc)
434 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
437 # define bt_named_field_class_freeze _bt_named_field_class_freeze
439 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
443 * This function recursively marks `field_class` and its children as
444 * being part of a trace. This is used to validate that all field classes
445 * are used at a single location within trace objects even if they are
446 * shared objects for other purposes.
449 void bt_field_class_make_part_of_trace_class(
450 const struct bt_field_class
*field_class
);
452 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */