Commit | Line | Data |
---|---|---|
5cd6d0e5 PP |
1 | #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H |
2 | #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H | |
3 | ||
4 | /* | |
e2f7325d | 5 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5cd6d0e5 PP |
6 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
7 | * | |
5cd6d0e5 PP |
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 | ||
578e048b | 27 | #include "lib/assert-pre.h" |
3fadfbc0 MJ |
28 | #include <babeltrace2/trace-ir/clock-class.h> |
29 | #include <babeltrace2/trace-ir/field-class.h> | |
91d81473 | 30 | #include "common/macros.h" |
45c51519 | 31 | #include "common/common.h" |
578e048b | 32 | #include "lib/object.h" |
3fadfbc0 | 33 | #include <babeltrace2/types.h> |
5cd6d0e5 PP |
34 | #include <stdint.h> |
35 | #include <glib.h> | |
36 | ||
bdb288b3 PP |
37 | #define _BT_ASSERT_PRE_FC_IS_INT_COND(_fc) \ |
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 | ||
43 | #define _BT_ASSERT_PRE_FC_IS_INT_FMT(_name) \ | |
44 | _name " is not an integer field class: %![fc-]+F" | |
45 | ||
46 | #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc) \ | |
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 | ||
50 | #define _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name) \ | |
51 | _name " is not an unsigned integer field class: %![fc-]+F" | |
52 | ||
45c51519 PP |
53 | |
54 | #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc) \ | |
55 | (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \ | |
56 | ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) | |
57 | ||
58 | #define _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name) \ | |
59 | _name " is not a signed integer field class: %![fc-]+F" | |
60 | ||
bdb288b3 PP |
61 | #define _BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc) \ |
62 | (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ | |
63 | ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) | |
64 | ||
65 | #define _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name) \ | |
66 | _name " is not an enumeration field class: %![fc-]+F" | |
67 | ||
68 | #define _BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc) \ | |
69 | (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \ | |
70 | ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY) | |
71 | ||
72 | #define _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name) \ | |
73 | _name " is not an array field class: %![fc-]+F" | |
74 | ||
45c51519 PP |
75 | #define _BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc) \ |
76 | (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR || \ | |
77 | ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR || \ | |
78 | ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) | |
79 | ||
80 | #define _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name) \ | |
81 | _name " is not a variant field class: %![fc-]+F" | |
82 | ||
83 | #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc) \ | |
84 | (((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR || \ | |
85 | ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) | |
86 | ||
87 | #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name) \ | |
88 | _name " is not a variant field class with a selector: %![fc-]+F" | |
89 | ||
bdb288b3 PP |
90 | #define _BT_ASSERT_PRE_FC_HAS_ID_COND(_fc, _type) \ |
91 | (((const struct bt_field_class *) (_fc))->type == (_type)) | |
92 | ||
93 | #define _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name) \ | |
94 | _name " has the wrong type: expected-type=%s, %![fc-]+F" | |
95 | ||
5cd6d0e5 | 96 | #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \ |
bdb288b3 | 97 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \ |
45c51519 | 98 | _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc)) |
5cd6d0e5 PP |
99 | |
100 | #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \ | |
bdb288b3 | 101 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \ |
45c51519 PP |
102 | _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc)) |
103 | ||
104 | #define BT_ASSERT_PRE_FC_IS_SIGNED_INT(_fc, _name) \ | |
105 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \ | |
106 | _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc)) | |
5cd6d0e5 PP |
107 | |
108 | #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \ | |
bdb288b3 | 109 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \ |
45c51519 | 110 | _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc)) |
5cd6d0e5 PP |
111 | |
112 | #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \ | |
bdb288b3 | 113 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \ |
45c51519 PP |
114 | _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc)) |
115 | ||
116 | #define BT_ASSERT_PRE_FC_IS_VARIANT(_fc, _name) \ | |
117 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \ | |
118 | _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc)) | |
119 | ||
120 | #define BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL(_fc, _name) \ | |
121 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \ | |
122 | _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc)) | |
5cd6d0e5 | 123 | |
864cad70 | 124 | #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \ |
bdb288b3 | 125 | BT_ASSERT_PRE(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \ |
45c51519 PP |
126 | _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \ |
127 | bt_common_field_class_type_string(_type), (_fc)) | |
5cd6d0e5 | 128 | |
bdb288b3 PP |
129 | #define BT_ASSERT_PRE_DEV_FC_IS_INT(_fc, _name) \ |
130 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_INT_COND(_fc), \ | |
45c51519 | 131 | _BT_ASSERT_PRE_FC_IS_INT_FMT(_name), (_fc)) |
bdb288b3 PP |
132 | |
133 | #define BT_ASSERT_PRE_DEV_FC_IS_UNSIGNED_INT(_fc, _name) \ | |
134 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_COND(_fc), \ | |
45c51519 PP |
135 | _BT_ASSERT_PRE_FC_IS_UNSIGNED_INT_FMT(_name), (_fc)) |
136 | ||
137 | #define BT_ASSERT_PRE_DEV_FC_IS_SIGNED_INT(_fc, _name) \ | |
138 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_SIGNED_INT_COND(_fc), \ | |
139 | _BT_ASSERT_PRE_FC_IS_SIGNED_INT_FMT(_name), (_fc)) | |
bdb288b3 PP |
140 | |
141 | #define BT_ASSERT_PRE_DEV_FC_IS_ENUM(_fc, _name) \ | |
142 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ENUM_COND(_fc), \ | |
45c51519 | 143 | _BT_ASSERT_PRE_FC_IS_ENUM_FMT(_name), (_fc)) |
bdb288b3 PP |
144 | |
145 | #define BT_ASSERT_PRE_DEV_FC_IS_ARRAY(_fc, _name) \ | |
146 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_ARRAY_COND(_fc), \ | |
45c51519 PP |
147 | _BT_ASSERT_PRE_FC_IS_ARRAY_FMT(_name), (_fc)) |
148 | ||
149 | #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT(_fc, _name) \ | |
150 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_COND(_fc), \ | |
151 | _BT_ASSERT_PRE_FC_IS_VARIANT_FMT(_name), (_fc)) | |
152 | ||
153 | #define BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(_fc, _name) \ | |
154 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \ | |
155 | _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc)) | |
bdb288b3 PP |
156 | |
157 | #define BT_ASSERT_PRE_DEV_FC_HAS_ID(_fc, _type, _name) \ | |
158 | BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_FC_HAS_ID_COND((_fc), (_type)), \ | |
45c51519 PP |
159 | _BT_ASSERT_PRE_FC_HAS_ID_FMT(_name), \ |
160 | bt_common_field_class_type_string(_type), (_fc)) | |
bdb288b3 PP |
161 | |
162 | #define BT_ASSERT_PRE_DEV_FC_HOT(_fc, _name) \ | |
163 | BT_ASSERT_PRE_DEV_HOT((const struct bt_field_class *) (_fc), \ | |
5cd6d0e5 PP |
164 | (_name), ": %!+F", (_fc)) |
165 | ||
5cd6d0e5 PP |
166 | #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \ |
167 | (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ | |
168 | struct bt_field_class_enumeration_mapping, (_index))) | |
169 | ||
170 | #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ | |
171 | (&g_array_index((_mapping)->ranges, \ | |
172 | struct bt_field_class_enumeration_mapping_range, (_index))) | |
173 | ||
174 | struct bt_field; | |
175 | struct bt_field_class; | |
176 | ||
177 | struct bt_field_class { | |
178 | struct bt_object base; | |
864cad70 | 179 | enum bt_field_class_type type; |
5cd6d0e5 PP |
180 | bool frozen; |
181 | ||
182 | /* | |
bdb288b3 PP |
183 | * This flag indicates whether or not this field class is part |
184 | * of a trace class. | |
5cd6d0e5 | 185 | */ |
862ca4ed | 186 | bool part_of_trace_class; |
5cd6d0e5 PP |
187 | }; |
188 | ||
189 | struct bt_field_class_integer { | |
190 | struct bt_field_class common; | |
191 | ||
192 | /* | |
193 | * Value range of fields built from this integer field class: | |
194 | * this is an equivalent integer size in bits. More formally, | |
195 | * `range` is `n` in: | |
196 | * | |
197 | * Unsigned range: [0, 2^n - 1] | |
198 | * Signed range: [-2^(n - 1), 2^(n - 1) - 1] | |
199 | */ | |
200 | uint64_t range; | |
201 | ||
202 | enum bt_field_class_integer_preferred_display_base base; | |
203 | }; | |
204 | ||
5cd6d0e5 PP |
205 | struct bt_field_class_enumeration_mapping { |
206 | GString *label; | |
207 | ||
45c51519 PP |
208 | /* Owner by this */ |
209 | const struct bt_integer_range_set *range_set; | |
5cd6d0e5 PP |
210 | }; |
211 | ||
8f3ccfbc PP |
212 | struct bt_field_class_unsigned_enumeration_mapping; |
213 | struct bt_field_class_signed_enumeration_mapping; | |
214 | ||
5cd6d0e5 PP |
215 | struct bt_field_class_enumeration { |
216 | struct bt_field_class_integer common; | |
217 | ||
218 | /* Array of `struct bt_field_class_enumeration_mapping *` */ | |
219 | GArray *mappings; | |
220 | ||
221 | /* | |
222 | * This is an array of `const char *` which acts as a temporary | |
223 | * (potentially growing) buffer for | |
185ecf64 | 224 | * bt_field_class_unsigned_enumeration_get_mapping_labels_for_value() |
5cd6d0e5 | 225 | * and |
185ecf64 | 226 | * bt_field_class_signed_enumeration_get_mapping_labels_for_value(). |
5cd6d0e5 PP |
227 | * |
228 | * The actual strings are owned by the mappings above. | |
229 | */ | |
230 | GPtrArray *label_buf; | |
231 | }; | |
232 | ||
233 | struct bt_field_class_real { | |
234 | struct bt_field_class common; | |
235 | bool is_single_precision; | |
236 | }; | |
237 | ||
238 | struct bt_field_class_string { | |
239 | struct bt_field_class common; | |
240 | }; | |
241 | ||
242 | /* A named field class is a (name, field class) pair */ | |
243 | struct bt_named_field_class { | |
244 | GString *name; | |
245 | ||
246 | /* Owned by this */ | |
247 | struct bt_field_class *fc; | |
1e6fd1d7 PP |
248 | |
249 | bool frozen; | |
5cd6d0e5 PP |
250 | }; |
251 | ||
1e6fd1d7 PP |
252 | struct bt_field_class_structure_member; |
253 | struct bt_field_class_variant_option; | |
45c51519 PP |
254 | struct bt_field_class_variant_with_unsigned_selector_option; |
255 | struct bt_field_class_variant_with_signed_selector_option; | |
1e6fd1d7 | 256 | |
5cd6d0e5 PP |
257 | struct bt_field_class_named_field_class_container { |
258 | struct bt_field_class common; | |
259 | ||
260 | /* | |
261 | * Key: `const char *`, not owned by this (owned by named field | |
45c51519 | 262 | * class objects contained in `named_fcs` below). |
5cd6d0e5 PP |
263 | */ |
264 | GHashTable *name_to_index; | |
265 | ||
45c51519 PP |
266 | /* Array of `struct bt_named_field_class *` */ |
267 | GPtrArray *named_fcs; | |
5cd6d0e5 PP |
268 | }; |
269 | ||
270 | struct bt_field_class_structure { | |
271 | struct bt_field_class_named_field_class_container common; | |
272 | }; | |
273 | ||
274 | struct bt_field_class_array { | |
275 | struct bt_field_class common; | |
276 | ||
277 | /* Owned by this */ | |
278 | struct bt_field_class *element_fc; | |
279 | }; | |
280 | ||
281 | struct bt_field_class_static_array { | |
282 | struct bt_field_class_array common; | |
283 | uint64_t length; | |
284 | }; | |
285 | ||
286 | struct bt_field_class_dynamic_array { | |
287 | struct bt_field_class_array common; | |
288 | ||
289 | /* Weak: never dereferenced, only use to find it elsewhere */ | |
290 | struct bt_field_class *length_fc; | |
291 | ||
292 | /* Owned by this */ | |
293 | struct bt_field_path *length_field_path; | |
294 | }; | |
295 | ||
45c51519 PP |
296 | /* Variant FC (with selector) option: named field class + range set */ |
297 | struct bt_field_class_variant_with_selector_option { | |
298 | struct bt_named_field_class common; | |
299 | ||
300 | /* Owned by this */ | |
301 | const struct bt_integer_range_set *range_set; | |
302 | }; | |
303 | ||
5cd6d0e5 | 304 | struct bt_field_class_variant { |
45c51519 PP |
305 | /* |
306 | * Depending on the variant field class type, the contained | |
307 | * named field classes are of type | |
308 | * `struct bt_named_field_class *` if the variant field class | |
309 | * doesn't have a selector, or | |
310 | * `struct bt_field_class_variant_with_selector_option *` | |
311 | * if it has. | |
312 | */ | |
5cd6d0e5 | 313 | struct bt_field_class_named_field_class_container common; |
45c51519 | 314 | }; |
5cd6d0e5 | 315 | |
45c51519 PP |
316 | struct bt_field_class_variant_with_selector { |
317 | struct bt_field_class_variant common; | |
318 | ||
319 | /* | |
320 | * Owned by this, but never dereferenced: only use to find it | |
321 | * elsewhere. | |
322 | */ | |
323 | const struct bt_field_class *selector_fc; | |
5cd6d0e5 PP |
324 | |
325 | /* Owned by this */ | |
326 | struct bt_field_path *selector_field_path; | |
327 | }; | |
328 | ||
5cd6d0e5 | 329 | BT_HIDDEN |
40f4ba76 | 330 | void _bt_field_class_freeze(const struct bt_field_class *field_class); |
5cd6d0e5 PP |
331 | |
332 | #ifdef BT_DEV_MODE | |
333 | # define bt_field_class_freeze _bt_field_class_freeze | |
334 | #else | |
1d7f91d1 | 335 | # define bt_field_class_freeze(_fc) ((void) _fc) |
5cd6d0e5 PP |
336 | #endif |
337 | ||
1e6fd1d7 PP |
338 | BT_HIDDEN |
339 | void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc); | |
340 | ||
341 | #ifdef BT_DEV_MODE | |
342 | # define bt_named_field_class_freeze _bt_named_field_class_freeze | |
343 | #else | |
1d7f91d1 | 344 | # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc) |
1e6fd1d7 PP |
345 | #endif |
346 | ||
5cd6d0e5 PP |
347 | /* |
348 | * This function recursively marks `field_class` and its children as | |
349 | * being part of a trace. This is used to validate that all field classes | |
350 | * are used at a single location within trace objects even if they are | |
351 | * shared objects for other purposes. | |
352 | */ | |
353 | BT_HIDDEN | |
bdb288b3 | 354 | void bt_field_class_make_part_of_trace_class( |
862ca4ed | 355 | const struct bt_field_class *field_class); |
5cd6d0e5 | 356 | |
5cd6d0e5 | 357 | #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */ |