1 #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
5 * BabelTrace - Trace IR: Event field classes internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/trace-ir/clock-class.h>
32 #include <babeltrace/trace-ir/field-classes.h>
33 #include <babeltrace/babeltrace-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/types.h>
39 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
41 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_UNSIGNED_INTEGER || \
42 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_SIGNED_INTEGER || \
43 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_UNSIGNED_ENUMERATION || \
44 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_SIGNED_ENUMERATION, \
45 _name " is not an integer field class: %![fc-]+F", (_fc))
47 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
49 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_UNSIGNED_INTEGER || \
50 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_UNSIGNED_ENUMERATION, \
51 _name " is not an unsigned integer field class: %![fc-]+F", (_fc))
53 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
55 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_UNSIGNED_ENUMERATION || \
56 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_SIGNED_ENUMERATION, \
57 _name " is not an enumeration field class: %![fc-]+F", (_fc))
59 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
61 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_STATIC_ARRAY || \
62 ((struct bt_field_class *) (_fc))->id == BT_FIELD_CLASS_ID_DYNAMIC_ARRAY, \
63 _name " is not an array field class: %![fc-]+F", (_fc))
65 #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _id, _name) \
66 BT_ASSERT_PRE(((struct bt_field_class *) (_fc))->id == (_id), \
67 _name " has the wrong ID: expected-id=%s, " \
68 "%![fc-]+F", bt_common_field_class_id_string(_id), (_fc))
70 #define BT_ASSERT_PRE_FC_HOT(_fc, _name) \
71 BT_ASSERT_PRE_HOT((struct bt_field_class *) (_fc), \
72 (_name), ": %!+F", (_fc))
74 #define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \
75 (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \
76 struct bt_named_field_class, (_index)))
78 #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
79 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
80 struct bt_field_class_enumeration_mapping, (_index)))
82 #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
83 (&g_array_index((_mapping)->ranges, \
84 struct bt_field_class_enumeration_mapping_range, (_index)))
87 struct bt_field_class
;
89 struct bt_field_class
{
90 struct bt_object base
;
91 enum bt_field_class_id id
;
95 * Only used in developer mode, this flag indicates whether or
96 * not this field class is part of a trace.
101 struct bt_field_class_integer
{
102 struct bt_field_class common
;
105 * Value range of fields built from this integer field class:
106 * this is an equivalent integer size in bits. More formally,
109 * Unsigned range: [0, 2^n - 1]
110 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
114 enum bt_field_class_integer_preferred_display_base base
;
117 struct bt_field_class_enumeration_mapping_range
{
129 struct bt_field_class_enumeration_mapping
{
132 /* Array of `struct bt_field_class_enumeration_mapping_range` */
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
;
172 * This is the base field class for a container of named field classes.
173 * Structure and variant field classes inherit this.
175 struct bt_field_class_named_field_class_container
{
176 struct bt_field_class common
;
179 * Key: `const char *`, not owned by this (owned by named field
180 * type objects contained in `named_fcs` below).
182 GHashTable
*name_to_index
;
184 /* Array of `struct bt_named_field_class` */
188 struct bt_field_class_structure
{
189 struct bt_field_class_named_field_class_container common
;
192 struct bt_field_class_array
{
193 struct bt_field_class common
;
196 struct bt_field_class
*element_fc
;
199 struct bt_field_class_static_array
{
200 struct bt_field_class_array common
;
204 struct bt_field_class_dynamic_array
{
205 struct bt_field_class_array common
;
207 /* Weak: never dereferenced, only use to find it elsewhere */
208 struct bt_field_class
*length_fc
;
211 struct bt_field_path
*length_field_path
;
214 struct bt_field_class_variant
{
215 struct bt_field_class_named_field_class_container common
;
217 /* Weak: never dereferenced, only use to find it elsewhere */
218 struct bt_field_class
*selector_fc
;
221 struct bt_field_path
*selector_field_path
;
225 bool bt_field_class_has_known_id(struct bt_field_class
*fc
)
227 return fc
->id
>= BT_FIELD_CLASS_ID_UNSIGNED_INTEGER
&&
228 fc
->id
<= BT_FIELD_CLASS_ID_VARIANT
;
232 void _bt_field_class_freeze(struct bt_field_class
*field_class
);
235 # define bt_field_class_freeze _bt_field_class_freeze
237 # define bt_field_class_freeze(_fc)
241 * This function recursively marks `field_class` and its children as
242 * being part of a trace. This is used to validate that all field classes
243 * are used at a single location within trace objects even if they are
244 * shared objects for other purposes.
247 void _bt_field_class_make_part_of_trace(struct bt_field_class
*field_class
);
250 # define bt_field_class_make_part_of_trace _bt_field_class_make_part_of_trace
252 # define bt_field_class_make_part_of_trace(_fc) ((void) _fc)
255 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */