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 "lib/object.h"
32 #include <babeltrace2/types.h>
36 #define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc) \
37 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
38 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
39 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
40 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
42 #define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name) \
43 _name " is not an integer field class: %![fc-]+F"
45 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc) \
46 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
47 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION)
49 #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name) \
50 _name " is not an unsigned integer field class: %![fc-]+F"
52 #define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc) \
53 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
54 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION)
56 #define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name) \
57 _name " is not an enumeration field class: %![fc-]+F"
59 #define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc) \
60 (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
61 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)
63 #define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name) \
64 _name " is not an array field class: %![fc-]+F"
66 #define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type) \
67 (((const struct bt_field_class *) (_fc))->type == (_type))
69 #define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name) \
70 _name " has the wrong type: expected-type=%s, %![fc-]+F"
72 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
73 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
74 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
76 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
77 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
78 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
80 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
81 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
82 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
84 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
85 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
86 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
88 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
89 BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
90 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
91 bt_common_field_class_type_string(_type), (_fc))
93 #define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name) \
94 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \
95 _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc))
97 #define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name) \
98 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \
99 _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc))
101 #define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name) \
102 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \
103 _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc))
105 #define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name) \
106 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \
107 _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc))
109 #define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name) \
110 BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \
111 _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \
112 bt_common_field_class_type_string(_type), (_fc))
114 #define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name) \
115 BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc), \
116 (_name), ": %!+F", (_fc))
118 #define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \
119 (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \
120 struct bt_named_field_class, (_index)))
122 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
123 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
124 struct bt_field_class_enumeration_mapping, (_index)))
126 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
127 (&g_array_index((_mapping)->ranges, \
128 struct bt_field_class_enumeration_mapping_range, (_index)))
131 struct bt_field_class
;
133 struct bt_field_class
{
134 struct bt_object base
;
135 enum bt_field_class_type type
;
139 * This flag indicates whether or not this field class is part
142 bool part_of_trace_class
;
145 struct bt_field_class_integer
{
146 struct bt_field_class common
;
149 * Value range of fields built from this integer field class:
150 * this is an equivalent integer size in bits. More formally,
153 * Unsigned range: [0, 2^n - 1]
154 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
158 enum bt_field_class_integer_preferred_display_base base
;
161 struct bt_field_class_enumeration_mapping_range
{
173 struct bt_field_class_enumeration_mapping
{
176 /* Array of `struct bt_field_class_enumeration_mapping_range` */
180 struct bt_field_class_unsigned_enumeration_mapping
;
181 struct bt_field_class_signed_enumeration_mapping
;
183 struct bt_field_class_enumeration
{
184 struct bt_field_class_integer common
;
186 /* Array of `struct bt_field_class_enumeration_mapping *` */
190 * This is an array of `const char *` which acts as a temporary
191 * (potentially growing) buffer for
192 * bt_field_class_unsigned_enumeration_get_mapping_labels_for_value()
194 * bt_field_class_signed_enumeration_get_mapping_labels_for_value().
196 * The actual strings are owned by the mappings above.
198 GPtrArray
*label_buf
;
201 struct bt_field_class_real
{
202 struct bt_field_class common
;
203 bool is_single_precision
;
206 struct bt_field_class_string
{
207 struct bt_field_class common
;
210 /* A named field class is a (name, field class) pair */
211 struct bt_named_field_class
{
215 struct bt_field_class
*fc
;
220 struct bt_field_class_structure_member
;
221 struct bt_field_class_variant_option
;
224 * This is the base field class for a container of named field classes.
225 * Structure and variant field classes inherit this.
227 struct bt_field_class_named_field_class_container
{
228 struct bt_field_class common
;
231 * Key: `const char *`, not owned by this (owned by named field
232 * type objects contained in `named_fcs` below).
234 GHashTable
*name_to_index
;
236 /* Array of `struct bt_named_field_class` */
240 struct bt_field_class_structure
{
241 struct bt_field_class_named_field_class_container common
;
244 struct bt_field_class_array
{
245 struct bt_field_class common
;
248 struct bt_field_class
*element_fc
;
251 struct bt_field_class_static_array
{
252 struct bt_field_class_array common
;
256 struct bt_field_class_dynamic_array
{
257 struct bt_field_class_array common
;
259 /* Weak: never dereferenced, only use to find it elsewhere */
260 struct bt_field_class
*length_fc
;
263 struct bt_field_path
*length_field_path
;
266 struct bt_field_class_variant
{
267 struct bt_field_class_named_field_class_container common
;
269 /* Weak: never dereferenced, only use to find it elsewhere */
270 struct bt_field_class
*selector_fc
;
273 struct bt_field_path
*selector_field_path
;
277 bool bt_field_class_has_known_type(const struct bt_field_class
*fc
)
279 return fc
->type
>= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
&&
280 fc
->type
<= BT_FIELD_CLASS_TYPE_VARIANT
;
284 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
287 # define bt_field_class_freeze _bt_field_class_freeze
289 # define bt_field_class_freeze(_fc) ((void) _fc)
293 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
296 # define bt_named_field_class_freeze _bt_named_field_class_freeze
298 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
302 * This function recursively marks `field_class` and its children as
303 * being part of a trace. This is used to validate that all field classes
304 * are used at a single location within trace objects even if they are
305 * shared objects for other purposes.
308 void bt_field_class_make_part_of_trace_class(
309 const struct bt_field_class
*field_class
);
311 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */