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 <babeltrace/assert-pre-internal.h>
28 #include <babeltrace/trace-ir/clock-class.h>
29 #include <babeltrace/trace-ir/field-class.h>
30 #include <babeltrace/babeltrace-internal.h>
31 #include <babeltrace/object-internal.h>
32 #include <babeltrace/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_enumeration
{
134 struct bt_field_class_integer common
;
136 /* Array of `struct bt_field_class_enumeration_mapping *` */
140 * This is an array of `const char *` which acts as a temporary
141 * (potentially growing) buffer for
142 * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value()
144 * bt_field_class_signed_enumeration_get_mapping_labels_by_value().
146 * The actual strings are owned by the mappings above.
148 GPtrArray
*label_buf
;
151 struct bt_field_class_real
{
152 struct bt_field_class common
;
153 bool is_single_precision
;
156 struct bt_field_class_string
{
157 struct bt_field_class common
;
160 /* A named field class is a (name, field class) pair */
161 struct bt_named_field_class
{
165 struct bt_field_class
*fc
;
169 * This is the base field class for a container of named field classes.
170 * Structure and variant field classes inherit this.
172 struct bt_field_class_named_field_class_container
{
173 struct bt_field_class common
;
176 * Key: `const char *`, not owned by this (owned by named field
177 * type objects contained in `named_fcs` below).
179 GHashTable
*name_to_index
;
181 /* Array of `struct bt_named_field_class` */
185 struct bt_field_class_structure
{
186 struct bt_field_class_named_field_class_container common
;
189 struct bt_field_class_array
{
190 struct bt_field_class common
;
193 struct bt_field_class
*element_fc
;
196 struct bt_field_class_static_array
{
197 struct bt_field_class_array common
;
201 struct bt_field_class_dynamic_array
{
202 struct bt_field_class_array common
;
204 /* Weak: never dereferenced, only use to find it elsewhere */
205 struct bt_field_class
*length_fc
;
208 struct bt_field_path
*length_field_path
;
211 struct bt_field_class_variant
{
212 struct bt_field_class_named_field_class_container common
;
214 /* Weak: never dereferenced, only use to find it elsewhere */
215 struct bt_field_class
*selector_fc
;
218 struct bt_field_path
*selector_field_path
;
222 bool bt_field_class_has_known_type(const struct bt_field_class
*fc
)
224 return fc
->type
>= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
&&
225 fc
->type
<= BT_FIELD_CLASS_TYPE_VARIANT
;
229 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
232 # define bt_field_class_freeze _bt_field_class_freeze
234 # define bt_field_class_freeze(_fc)
238 * This function recursively marks `field_class` and its children as
239 * being part of a trace. This is used to validate that all field classes
240 * are used at a single location within trace objects even if they are
241 * shared objects for other purposes.
244 void _bt_field_class_make_part_of_trace_class(
245 const struct bt_field_class
*field_class
);
248 # define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class
250 # define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc)
253 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */