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(_fc, _name) \
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, \
42 _name " is not an integer field class: %![fc-]+F", (_fc))
44 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
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, \
48 _name " is not an unsigned integer field class: %![fc-]+F", (_fc))
50 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
52 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
53 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
54 _name " is not an enumeration field class: %![fc-]+F", (_fc))
56 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
58 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
59 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
60 _name " is not an array field class: %![fc-]+F", (_fc))
62 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
63 BT_ASSERT_PRE(((const struct bt_field_class *) (_fc))->type == (_type), \
64 _name " has the wrong type: expected-type=%s, " \
65 "%![fc-]+F", bt_common_field_class_type_string(_type), (_fc))
67 #define BT_ASSERT_PRE_FC_HOT(_fc, _name) \
68 BT_ASSERT_PRE_HOT((const struct bt_field_class *) (_fc), \
69 (_name), ": %!+F", (_fc))
71 #define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \
72 (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \
73 struct bt_named_field_class, (_index)))
75 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
76 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
77 struct bt_field_class_enumeration_mapping, (_index)))
79 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
80 (&g_array_index((_mapping)->ranges, \
81 struct bt_field_class_enumeration_mapping_range, (_index)))
84 struct bt_field_class
;
86 struct bt_field_class
{
87 struct bt_object base
;
88 enum bt_field_class_type type
;
92 * Only used in developer mode, this flag indicates whether or
93 * not this field class is part of a trace class.
95 bool part_of_trace_class
;
98 struct bt_field_class_integer
{
99 struct bt_field_class common
;
102 * Value range of fields built from this integer field class:
103 * this is an equivalent integer size in bits. More formally,
106 * Unsigned range: [0, 2^n - 1]
107 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
111 enum bt_field_class_integer_preferred_display_base base
;
114 struct bt_field_class_enumeration_mapping_range
{
126 struct bt_field_class_enumeration_mapping
{
129 /* Array of `struct bt_field_class_enumeration_mapping_range` */
133 struct bt_field_class_unsigned_enumeration_mapping
;
134 struct bt_field_class_signed_enumeration_mapping
;
136 struct bt_field_class_enumeration
{
137 struct bt_field_class_integer common
;
139 /* Array of `struct bt_field_class_enumeration_mapping *` */
143 * This is an array of `const char *` which acts as a temporary
144 * (potentially growing) buffer for
145 * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value()
147 * bt_field_class_signed_enumeration_get_mapping_labels_by_value().
149 * The actual strings are owned by the mappings above.
151 GPtrArray
*label_buf
;
154 struct bt_field_class_real
{
155 struct bt_field_class common
;
156 bool is_single_precision
;
159 struct bt_field_class_string
{
160 struct bt_field_class common
;
163 /* A named field class is a (name, field class) pair */
164 struct bt_named_field_class
{
168 struct bt_field_class
*fc
;
173 struct bt_field_class_structure_member
;
174 struct bt_field_class_variant_option
;
177 * This is the base field class for a container of named field classes.
178 * Structure and variant field classes inherit this.
180 struct bt_field_class_named_field_class_container
{
181 struct bt_field_class common
;
184 * Key: `const char *`, not owned by this (owned by named field
185 * type objects contained in `named_fcs` below).
187 GHashTable
*name_to_index
;
189 /* Array of `struct bt_named_field_class` */
193 struct bt_field_class_structure
{
194 struct bt_field_class_named_field_class_container common
;
197 struct bt_field_class_array
{
198 struct bt_field_class common
;
201 struct bt_field_class
*element_fc
;
204 struct bt_field_class_static_array
{
205 struct bt_field_class_array common
;
209 struct bt_field_class_dynamic_array
{
210 struct bt_field_class_array common
;
212 /* Weak: never dereferenced, only use to find it elsewhere */
213 struct bt_field_class
*length_fc
;
216 struct bt_field_path
*length_field_path
;
219 struct bt_field_class_variant
{
220 struct bt_field_class_named_field_class_container common
;
222 /* Weak: never dereferenced, only use to find it elsewhere */
223 struct bt_field_class
*selector_fc
;
226 struct bt_field_path
*selector_field_path
;
230 bool bt_field_class_has_known_type(const struct bt_field_class
*fc
)
232 return fc
->type
>= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
&&
233 fc
->type
<= BT_FIELD_CLASS_TYPE_VARIANT
;
237 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
240 # define bt_field_class_freeze _bt_field_class_freeze
242 # define bt_field_class_freeze(_fc) ((void) _fc)
246 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
);
249 # define bt_named_field_class_freeze _bt_named_field_class_freeze
251 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
255 * This function recursively marks `field_class` and its children as
256 * being part of a trace. This is used to validate that all field classes
257 * are used at a single location within trace objects even if they are
258 * shared objects for other purposes.
261 void _bt_field_class_make_part_of_trace_class(
262 const struct bt_field_class
*field_class
);
265 # define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class
267 # define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc)
270 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */