1 #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/trace-ir/clock-class.h>
30 #include <babeltrace/trace-ir/field-classes.h>
31 #include <babeltrace/babeltrace-internal.h>
32 #include <babeltrace/object-internal.h>
33 #include <babeltrace/types.h>
37 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
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, \
43 _name " is not an integer field class: %![fc-]+F", (_fc))
45 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
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, \
49 _name " is not an unsigned integer field class: %![fc-]+F", (_fc))
51 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
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, \
55 _name " is not an enumeration field class: %![fc-]+F", (_fc))
57 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
59 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
60 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
61 _name " is not an array field class: %![fc-]+F", (_fc))
63 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
64 BT_ASSERT_PRE(((const struct bt_field_class *) (_fc))->type == (_type), \
65 _name " has the wrong type: expected-type=%s, " \
66 "%![fc-]+F", bt_common_field_class_type_string(_type), (_fc))
68 #define BT_ASSERT_PRE_FC_HOT(_fc, _name) \
69 BT_ASSERT_PRE_HOT((const struct bt_field_class *) (_fc), \
70 (_name), ": %!+F", (_fc))
72 #define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \
73 (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \
74 struct bt_named_field_class, (_index)))
76 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
77 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
78 struct bt_field_class_enumeration_mapping, (_index)))
80 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
81 (&g_array_index((_mapping)->ranges, \
82 struct bt_field_class_enumeration_mapping_range, (_index)))
85 struct bt_field_class
;
87 struct bt_field_class
{
88 struct bt_object base
;
89 enum bt_field_class_type type
;
93 * Only used in developer mode, this flag indicates whether or
94 * not this field class is part of a trace class.
96 bool part_of_trace_class
;
99 struct bt_field_class_integer
{
100 struct bt_field_class common
;
103 * Value range of fields built from this integer field class:
104 * this is an equivalent integer size in bits. More formally,
107 * Unsigned range: [0, 2^n - 1]
108 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
112 enum bt_field_class_integer_preferred_display_base base
;
115 struct bt_field_class_enumeration_mapping_range
{
127 struct bt_field_class_enumeration_mapping
{
130 /* Array of `struct bt_field_class_enumeration_mapping_range` */
134 struct bt_field_class_enumeration
{
135 struct bt_field_class_integer common
;
137 /* Array of `struct bt_field_class_enumeration_mapping *` */
141 * This is an array of `const char *` which acts as a temporary
142 * (potentially growing) buffer for
143 * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value()
145 * bt_field_class_signed_enumeration_get_mapping_labels_by_value().
147 * The actual strings are owned by the mappings above.
149 GPtrArray
*label_buf
;
152 struct bt_field_class_real
{
153 struct bt_field_class common
;
154 bool is_single_precision
;
157 struct bt_field_class_string
{
158 struct bt_field_class common
;
161 /* A named field class is a (name, field class) pair */
162 struct bt_named_field_class
{
166 struct bt_field_class
*fc
;
170 * This is the base field class for a container of named field classes.
171 * Structure and variant field classes inherit this.
173 struct bt_field_class_named_field_class_container
{
174 struct bt_field_class common
;
177 * Key: `const char *`, not owned by this (owned by named field
178 * type objects contained in `named_fcs` below).
180 GHashTable
*name_to_index
;
182 /* Array of `struct bt_named_field_class` */
186 struct bt_field_class_structure
{
187 struct bt_field_class_named_field_class_container common
;
190 struct bt_field_class_array
{
191 struct bt_field_class common
;
194 struct bt_field_class
*element_fc
;
197 struct bt_field_class_static_array
{
198 struct bt_field_class_array common
;
202 struct bt_field_class_dynamic_array
{
203 struct bt_field_class_array common
;
205 /* Weak: never dereferenced, only use to find it elsewhere */
206 struct bt_field_class
*length_fc
;
209 struct bt_field_path
*length_field_path
;
212 struct bt_field_class_variant
{
213 struct bt_field_class_named_field_class_container common
;
215 /* Weak: never dereferenced, only use to find it elsewhere */
216 struct bt_field_class
*selector_fc
;
219 struct bt_field_path
*selector_field_path
;
223 bool bt_field_class_has_known_type(const struct bt_field_class
*fc
)
225 return fc
->type
>= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
&&
226 fc
->type
<= BT_FIELD_CLASS_TYPE_VARIANT
;
230 void _bt_field_class_freeze(const struct bt_field_class
*field_class
);
233 # define bt_field_class_freeze _bt_field_class_freeze
235 # define bt_field_class_freeze(_fc)
239 * This function recursively marks `field_class` and its children as
240 * being part of a trace. This is used to validate that all field classes
241 * are used at a single location within trace objects even if they are
242 * shared objects for other purposes.
245 void _bt_field_class_make_part_of_trace_class(
246 const struct bt_field_class
*field_class
);
249 # define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class
251 # define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc)
254 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */