lib: create_packet_message(): make assertion message less convoluted
[babeltrace.git] / include / babeltrace / trace-ir / field-class-internal.h
1 #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
3
4 /*
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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
24 * SOFTWARE.
25 */
26
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>
33 #include <stdint.h>
34 #include <glib.h>
35
36 #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
37 BT_ASSERT_PRE( \
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))
43
44 #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
45 BT_ASSERT_PRE( \
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))
49
50 #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
51 BT_ASSERT_PRE( \
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))
55
56 #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
57 BT_ASSERT_PRE( \
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))
61
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))
66
67 #define BT_ASSERT_PRE_FC_HOT(_fc, _name) \
68 BT_ASSERT_PRE_HOT((const struct bt_field_class *) (_fc), \
69 (_name), ": %!+F", (_fc))
70
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)))
74
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)))
78
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)))
82
83 struct bt_field;
84 struct bt_field_class;
85
86 struct bt_field_class {
87 struct bt_object base;
88 enum bt_field_class_type type;
89 bool frozen;
90
91 /*
92 * Only used in developer mode, this flag indicates whether or
93 * not this field class is part of a trace class.
94 */
95 bool part_of_trace_class;
96 };
97
98 struct bt_field_class_integer {
99 struct bt_field_class common;
100
101 /*
102 * Value range of fields built from this integer field class:
103 * this is an equivalent integer size in bits. More formally,
104 * `range` is `n` in:
105 *
106 * Unsigned range: [0, 2^n - 1]
107 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
108 */
109 uint64_t range;
110
111 enum bt_field_class_integer_preferred_display_base base;
112 };
113
114 struct bt_field_class_enumeration_mapping_range {
115 union {
116 uint64_t u;
117 int64_t i;
118 } lower;
119
120 union {
121 uint64_t u;
122 int64_t i;
123 } upper;
124 };
125
126 struct bt_field_class_enumeration_mapping {
127 GString *label;
128
129 /* Array of `struct bt_field_class_enumeration_mapping_range` */
130 GArray *ranges;
131 };
132
133 struct bt_field_class_unsigned_enumeration_mapping;
134 struct bt_field_class_signed_enumeration_mapping;
135
136 struct bt_field_class_enumeration {
137 struct bt_field_class_integer common;
138
139 /* Array of `struct bt_field_class_enumeration_mapping *` */
140 GArray *mappings;
141
142 /*
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()
146 * and
147 * bt_field_class_signed_enumeration_get_mapping_labels_by_value().
148 *
149 * The actual strings are owned by the mappings above.
150 */
151 GPtrArray *label_buf;
152 };
153
154 struct bt_field_class_real {
155 struct bt_field_class common;
156 bool is_single_precision;
157 };
158
159 struct bt_field_class_string {
160 struct bt_field_class common;
161 };
162
163 /* A named field class is a (name, field class) pair */
164 struct bt_named_field_class {
165 GString *name;
166
167 /* Owned by this */
168 struct bt_field_class *fc;
169
170 bool frozen;
171 };
172
173 struct bt_field_class_structure_member;
174 struct bt_field_class_variant_option;
175
176 /*
177 * This is the base field class for a container of named field classes.
178 * Structure and variant field classes inherit this.
179 */
180 struct bt_field_class_named_field_class_container {
181 struct bt_field_class common;
182
183 /*
184 * Key: `const char *`, not owned by this (owned by named field
185 * type objects contained in `named_fcs` below).
186 */
187 GHashTable *name_to_index;
188
189 /* Array of `struct bt_named_field_class` */
190 GArray *named_fcs;
191 };
192
193 struct bt_field_class_structure {
194 struct bt_field_class_named_field_class_container common;
195 };
196
197 struct bt_field_class_array {
198 struct bt_field_class common;
199
200 /* Owned by this */
201 struct bt_field_class *element_fc;
202 };
203
204 struct bt_field_class_static_array {
205 struct bt_field_class_array common;
206 uint64_t length;
207 };
208
209 struct bt_field_class_dynamic_array {
210 struct bt_field_class_array common;
211
212 /* Weak: never dereferenced, only use to find it elsewhere */
213 struct bt_field_class *length_fc;
214
215 /* Owned by this */
216 struct bt_field_path *length_field_path;
217 };
218
219 struct bt_field_class_variant {
220 struct bt_field_class_named_field_class_container common;
221
222 /* Weak: never dereferenced, only use to find it elsewhere */
223 struct bt_field_class *selector_fc;
224
225 /* Owned by this */
226 struct bt_field_path *selector_field_path;
227 };
228
229 static inline
230 bool bt_field_class_has_known_type(const struct bt_field_class *fc)
231 {
232 return fc->type >= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER &&
233 fc->type <= BT_FIELD_CLASS_TYPE_VARIANT;
234 }
235
236 BT_HIDDEN
237 void _bt_field_class_freeze(const struct bt_field_class *field_class);
238
239 #ifdef BT_DEV_MODE
240 # define bt_field_class_freeze _bt_field_class_freeze
241 #else
242 # define bt_field_class_freeze(_fc) ((void) _fc)
243 #endif
244
245 BT_HIDDEN
246 void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc);
247
248 #ifdef BT_DEV_MODE
249 # define bt_named_field_class_freeze _bt_named_field_class_freeze
250 #else
251 # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
252 #endif
253
254 /*
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.
259 */
260 BT_HIDDEN
261 void _bt_field_class_make_part_of_trace_class(
262 const struct bt_field_class *field_class);
263
264 #ifdef BT_DEV_MODE
265 # define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class
266 #else
267 # define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc)
268 #endif
269
270 #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */
This page took 0.03639 seconds and 4 git commands to generate.