Commit | Line | Data |
---|---|---|
2e33ac5a PP |
1 | #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H |
2 | #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H | |
273b65be JG |
3 | |
4 | /* | |
2e33ac5a | 5 | * BabelTrace - CTF IR: Event field types internal |
273b65be | 6 | * |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
273b65be JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
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: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
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 | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
3dca2276 | 30 | #include <babeltrace/assert-pre-internal.h> |
ac0c6bdd | 31 | #include <babeltrace/ctf-ir/clock-class.h> |
4e8304f7 | 32 | #include <babeltrace/ctf-ir/field-types.h> |
273b65be | 33 | #include <babeltrace/babeltrace-internal.h> |
83509119 | 34 | #include <babeltrace/object-internal.h> |
c55a9f58 | 35 | #include <babeltrace/types.h> |
3dca2276 | 36 | #include <stdint.h> |
273b65be JG |
37 | #include <glib.h> |
38 | ||
cb6f1f7d PP |
39 | #define BT_ASSERT_PRE_FT_HAS_ID(_ft, _type_id, _name) \ |
40 | BT_ASSERT_PRE(((struct bt_field_type *) (_ft))->id == (_type_id), \ | |
3dca2276 | 41 | _name " has the wrong type ID: expected-type-id=%s, " \ |
cb6f1f7d | 42 | "%![ft-]+F", bt_common_field_type_id_string(_type_id), (_ft)) |
3dca2276 PP |
43 | |
44 | #define BT_ASSERT_PRE_FT_HOT(_ft, _name) \ | |
cb6f1f7d | 45 | BT_ASSERT_PRE_HOT((_ft), (_name), ": %!+F", (_ft)) |
3dca2276 | 46 | |
cb6f1f7d PP |
47 | #define BT_FIELD_TYPE_STRUCTURE_FIELD_AT_INDEX(_ft, _index) \ |
48 | (&g_array_index(((struct bt_field_type_structure *) (_ft))->fields, \ | |
49 | struct bt_field_type_structure_field, (_index))) | |
312c056a | 50 | |
cb6f1f7d PP |
51 | #define BT_FIELD_TYPE_VARIANT_CHOICE_AT_INDEX(_ft, _index) \ |
52 | (&g_array_index(((struct bt_field_type_variant *) (_ft))->choices, \ | |
53 | struct bt_field_type_variant_choice, (_index))) | |
312c056a | 54 | |
cb6f1f7d | 55 | struct bt_field; |
3dca2276 PP |
56 | struct bt_field_type; |
57 | ||
cb6f1f7d PP |
58 | typedef void (*bt_field_type_method_freeze)( |
59 | struct bt_field_type *); | |
60 | typedef int (*bt_field_type_method_validate)( | |
61 | struct bt_field_type *); | |
62 | typedef void (*bt_field_type_method_set_byte_order)( | |
63 | struct bt_field_type *, enum bt_byte_order); | |
64 | typedef struct bt_field_type *(*bt_field_type_method_copy)( | |
65 | struct bt_field_type *); | |
66 | typedef int (*bt_field_type_method_compare)( | |
67 | struct bt_field_type *, | |
68 | struct bt_field_type *); | |
69 | ||
70 | struct bt_field_type_methods { | |
71 | bt_field_type_method_freeze freeze; | |
72 | bt_field_type_method_validate validate; | |
73 | bt_field_type_method_set_byte_order set_byte_order; | |
74 | bt_field_type_method_copy copy; | |
75 | bt_field_type_method_compare compare; | |
3dca2276 | 76 | }; |
273b65be | 77 | |
cb6f1f7d | 78 | struct bt_field_type { |
83509119 | 79 | struct bt_object base; |
50842bdc | 80 | enum bt_field_type_id id; |
dc3fffef | 81 | unsigned int alignment; |
3dca2276 PP |
82 | |
83 | /* Virtual table */ | |
cb6f1f7d | 84 | struct bt_field_type_methods *methods; |
3dca2276 | 85 | |
273b65be JG |
86 | /* |
87 | * A type can't be modified once it is added to an event or after a | |
88 | * a field has been instanciated from it. | |
89 | */ | |
90 | int frozen; | |
81e36fac PP |
91 | |
92 | /* | |
93 | * This flag indicates if the field type is valid. A valid | |
94 | * field type is _always_ frozen. All the nested field types of | |
95 | * a valid field type are also valid (and thus frozen). | |
96 | */ | |
97 | int valid; | |
273b65be JG |
98 | }; |
99 | ||
cb6f1f7d PP |
100 | struct bt_field_type_integer { |
101 | struct bt_field_type common; | |
312c056a PP |
102 | |
103 | /* Owned by this */ | |
3dca2276 | 104 | struct bt_clock_class *mapped_clock_class; |
312c056a | 105 | |
50842bdc | 106 | enum bt_byte_order user_byte_order; |
c55a9f58 | 107 | bt_bool is_signed; |
dc3fffef | 108 | unsigned int size; |
50842bdc PP |
109 | enum bt_integer_base base; |
110 | enum bt_string_encoding encoding; | |
273b65be JG |
111 | }; |
112 | ||
113 | struct enumeration_mapping { | |
b92ddaaa JG |
114 | union { |
115 | uint64_t _unsigned; | |
116 | int64_t _signed; | |
117 | } range_start; | |
b92ddaaa JG |
118 | union { |
119 | uint64_t _unsigned; | |
120 | int64_t _signed; | |
121 | } range_end; | |
273b65be JG |
122 | GQuark string; |
123 | }; | |
124 | ||
cb6f1f7d PP |
125 | struct bt_field_type_enumeration { |
126 | struct bt_field_type common; | |
312c056a PP |
127 | |
128 | /* Owned by this */ | |
cb6f1f7d | 129 | struct bt_field_type_integer *container_ft; |
312c056a PP |
130 | |
131 | /* Array of `struct enumeration_mapping *`, owned by this */ | |
132 | GPtrArray *entries; | |
133 | ||
134 | /* Only set during validation */ | |
c55a9f58 | 135 | bt_bool has_overlapping_ranges; |
96e8f959 MD |
136 | }; |
137 | ||
50842bdc | 138 | enum bt_field_type_enumeration_mapping_iterator_type { |
96e8f959 MD |
139 | ITERATOR_BY_NAME, |
140 | ITERATOR_BY_SIGNED_VALUE, | |
141 | ITERATOR_BY_UNSIGNED_VALUE, | |
142 | }; | |
143 | ||
50842bdc | 144 | struct bt_field_type_enumeration_mapping_iterator { |
96e8f959 | 145 | struct bt_object base; |
312c056a PP |
146 | |
147 | /* Owned by this */ | |
cb6f1f7d | 148 | struct bt_field_type_enumeration *enumeration_ft; |
312c056a | 149 | |
50842bdc | 150 | enum bt_field_type_enumeration_mapping_iterator_type type; |
96e8f959 MD |
151 | int index; |
152 | union { | |
153 | GQuark name_quark; | |
154 | int64_t signed_value; | |
155 | uint64_t unsigned_value; | |
156 | } u; | |
273b65be JG |
157 | }; |
158 | ||
cb6f1f7d PP |
159 | struct bt_field_type_floating_point { |
160 | struct bt_field_type common; | |
50842bdc | 161 | enum bt_byte_order user_byte_order; |
dc3fffef PP |
162 | unsigned int exp_dig; |
163 | unsigned int mant_dig; | |
273b65be JG |
164 | }; |
165 | ||
cb6f1f7d | 166 | struct bt_field_type_structure_field { |
273b65be | 167 | GQuark name; |
312c056a PP |
168 | |
169 | /* Owned by this */ | |
cb6f1f7d | 170 | struct bt_field_type *type; |
273b65be JG |
171 | }; |
172 | ||
cb6f1f7d PP |
173 | struct bt_field_type_structure { |
174 | struct bt_field_type common; | |
273b65be | 175 | GHashTable *field_name_to_index; |
312c056a PP |
176 | |
177 | /* | |
cb6f1f7d | 178 | * Array of `struct bt_field_type_structure_field`, |
312c056a PP |
179 | * owned by this |
180 | */ | |
181 | GArray *fields; | |
182 | }; | |
183 | ||
cb6f1f7d | 184 | struct bt_field_type_variant_choice_range { |
312c056a PP |
185 | union { |
186 | int64_t i; | |
187 | uint64_t u; | |
188 | } lower; | |
189 | union { | |
190 | int64_t i; | |
191 | uint64_t u; | |
192 | } upper; | |
193 | }; | |
194 | ||
cb6f1f7d | 195 | struct bt_field_type_variant_choice { |
312c056a PP |
196 | GQuark name; |
197 | ||
198 | /* Owned by this */ | |
cb6f1f7d | 199 | struct bt_field_type *type; |
312c056a | 200 | |
cb6f1f7d | 201 | /* Array of `struct bt_field_type_variant_choice_range` */ |
312c056a | 202 | GArray *ranges; |
273b65be JG |
203 | }; |
204 | ||
cb6f1f7d PP |
205 | struct bt_field_type_variant { |
206 | struct bt_field_type common; | |
273b65be | 207 | GString *tag_name; |
312c056a PP |
208 | bool choices_up_to_date; |
209 | ||
210 | /* Owned by this */ | |
cb6f1f7d | 211 | struct bt_field_type_enumeration *tag_ft; |
312c056a PP |
212 | |
213 | /* Owned by this */ | |
50842bdc | 214 | struct bt_field_path *tag_field_path; |
312c056a PP |
215 | |
216 | GHashTable *choice_name_to_index; | |
217 | ||
218 | /* | |
cb6f1f7d | 219 | * Array of `struct bt_field_type_variant_choice`, |
312c056a PP |
220 | * owned by this */ |
221 | GArray *choices; | |
273b65be JG |
222 | }; |
223 | ||
cb6f1f7d PP |
224 | struct bt_field_type_array { |
225 | struct bt_field_type common; | |
312c056a PP |
226 | |
227 | /* Owned by this */ | |
cb6f1f7d | 228 | struct bt_field_type *element_ft; |
312c056a PP |
229 | |
230 | unsigned int length; | |
273b65be JG |
231 | }; |
232 | ||
cb6f1f7d PP |
233 | struct bt_field_type_sequence { |
234 | struct bt_field_type common; | |
312c056a PP |
235 | |
236 | /* Owned by this */ | |
cb6f1f7d | 237 | struct bt_field_type *element_ft; |
312c056a | 238 | |
273b65be | 239 | GString *length_field_name; |
312c056a PP |
240 | |
241 | /* Owned by this */ | |
50842bdc | 242 | struct bt_field_path *length_field_path; |
273b65be JG |
243 | }; |
244 | ||
cb6f1f7d PP |
245 | struct bt_field_type_string { |
246 | struct bt_field_type common; | |
50842bdc | 247 | enum bt_string_encoding encoding; |
273b65be JG |
248 | }; |
249 | ||
cb6f1f7d PP |
250 | typedef struct bt_field *(* bt_field_create_func)( |
251 | struct bt_field_type *); | |
3dca2276 | 252 | |
cb6f1f7d PP |
253 | BT_ASSERT_FUNC |
254 | static inline bool bt_field_type_has_known_id( | |
255 | struct bt_field_type *ft) | |
256 | { | |
257 | return (int) ft->id > BT_FIELD_TYPE_ID_UNKNOWN || | |
258 | (int) ft->id < BT_FIELD_TYPE_ID_NR; | |
259 | } | |
3dca2276 PP |
260 | |
261 | BT_HIDDEN | |
cb6f1f7d PP |
262 | int bt_field_type_variant_update_choices( |
263 | struct bt_field_type *ft); | |
3dca2276 PP |
264 | |
265 | BT_HIDDEN | |
5ea30b28 | 266 | void bt_field_type_freeze(struct bt_field_type *ft); |
3dca2276 PP |
267 | |
268 | BT_HIDDEN | |
cb6f1f7d | 269 | int bt_field_type_validate(struct bt_field_type *ft); |
3dca2276 PP |
270 | |
271 | BT_HIDDEN | |
cb6f1f7d PP |
272 | int bt_field_type_sequence_set_length_field_path( |
273 | struct bt_field_type *ft, struct bt_field_path *path); | |
3dca2276 PP |
274 | |
275 | BT_HIDDEN | |
cb6f1f7d PP |
276 | int bt_field_type_variant_set_tag_field_path( |
277 | struct bt_field_type *ft, | |
3dca2276 PP |
278 | struct bt_field_path *path); |
279 | ||
280 | BT_HIDDEN | |
cb6f1f7d PP |
281 | int bt_field_type_variant_set_tag_field_type( |
282 | struct bt_field_type *ft, | |
283 | struct bt_field_type *tag_ft); | |
3dca2276 PP |
284 | |
285 | BT_HIDDEN | |
cb6f1f7d | 286 | int64_t bt_field_type_get_field_count(struct bt_field_type *ft); |
3dca2276 PP |
287 | |
288 | BT_HIDDEN | |
cb6f1f7d PP |
289 | struct bt_field_type *bt_field_type_borrow_field_at_index( |
290 | struct bt_field_type *ft, int index); | |
3dca2276 PP |
291 | |
292 | BT_HIDDEN | |
cb6f1f7d | 293 | int bt_field_type_get_field_index(struct bt_field_type *ft, |
3dca2276 PP |
294 | const char *name); |
295 | ||
296 | BT_HIDDEN | |
cb6f1f7d PP |
297 | int bt_field_type_validate_single_clock_class( |
298 | struct bt_field_type *ft, | |
3dca2276 | 299 | struct bt_clock_class **expected_clock_class); |
4e8304f7 | 300 | |
312c056a | 301 | BT_HIDDEN |
cb6f1f7d PP |
302 | int64_t bt_field_type_variant_find_choice_index( |
303 | struct bt_field_type *ft, uint64_t uval, | |
312c056a PP |
304 | bool is_signed); |
305 | ||
2e33ac5a | 306 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */ |