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 | ||
44c440bc PP |
39 | #define BT_ASSERT_PRE_FT_IS_INT(_ft, _name) \ |
40 | BT_ASSERT_PRE( \ | |
41 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_INTEGER || \ | |
42 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_INTEGER || \ | |
43 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION || \ | |
44 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_ENUMERATION, \ | |
45 | _name " is not an integer field type: %![ft-]+F", (_ft)) | |
46 | ||
47 | #define BT_ASSERT_PRE_FT_IS_UNSIGNED_INT(_ft, _name) \ | |
48 | BT_ASSERT_PRE( \ | |
49 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_INTEGER || \ | |
50 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION, \ | |
51 | _name " is not an unsigned integer field type: %![ft-]+F", (_ft)) | |
52 | ||
53 | #define BT_ASSERT_PRE_FT_IS_ENUM(_ft, _name) \ | |
54 | BT_ASSERT_PRE( \ | |
55 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_UNSIGNED_ENUMERATION || \ | |
56 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_SIGNED_ENUMERATION, \ | |
57 | _name " is not an enumeration field type: %![ft-]+F", (_ft)) | |
58 | ||
59 | #define BT_ASSERT_PRE_FT_IS_ARRAY(_ft, _name) \ | |
60 | BT_ASSERT_PRE( \ | |
61 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_STATIC_ARRAY || \ | |
62 | ((struct bt_field_type *) (_ft))->id == BT_FIELD_TYPE_ID_DYNAMIC_ARRAY, \ | |
63 | _name " is not an array field type: %![ft-]+F", (_ft)) | |
64 | ||
65 | #define BT_ASSERT_PRE_FT_HAS_ID(_ft, _id, _name) \ | |
66 | BT_ASSERT_PRE(((struct bt_field_type *) (_ft))->id == (_id), \ | |
67 | _name " has the wrong ID: expected-id=%s, " \ | |
68 | "%![ft-]+F", bt_common_field_type_id_string(_id), (_ft)) | |
3dca2276 PP |
69 | |
70 | #define BT_ASSERT_PRE_FT_HOT(_ft, _name) \ | |
44c440bc PP |
71 | BT_ASSERT_PRE_HOT((struct bt_field_type *) (_ft), \ |
72 | (_name), ": %!+F", (_ft)) | |
3dca2276 | 73 | |
44c440bc PP |
74 | #define BT_FIELD_TYPE_NAMED_FT_AT_INDEX(_ft, _index) \ |
75 | (&g_array_index(((struct bt_field_type_named_field_types_container *) (_ft))->named_fts, \ | |
76 | struct bt_named_field_type, (_index))) | |
312c056a | 77 | |
44c440bc PP |
78 | #define BT_FIELD_TYPE_ENUM_MAPPING_AT_INDEX(_ft, _index) \ |
79 | (&g_array_index(((struct bt_field_type_enumeration *) (_ft))->mappings, \ | |
80 | struct bt_field_type_enumeration_mapping, (_index))) | |
81 | ||
82 | #define BT_FIELD_TYPE_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ | |
83 | (&g_array_index((_mapping)->ranges, \ | |
84 | struct bt_field_type_enumeration_mapping_range, (_index))) | |
312c056a | 85 | |
cb6f1f7d | 86 | struct bt_field; |
3dca2276 PP |
87 | struct bt_field_type; |
88 | ||
cb6f1f7d | 89 | struct bt_field_type { |
83509119 | 90 | struct bt_object base; |
50842bdc | 91 | enum bt_field_type_id id; |
44c440bc | 92 | bool frozen; |
81e36fac PP |
93 | |
94 | /* | |
44c440bc PP |
95 | * Only used in developer mode, this flag indicates whether or |
96 | * not this field type is part of a trace. | |
81e36fac | 97 | */ |
44c440bc | 98 | bool part_of_trace; |
273b65be JG |
99 | }; |
100 | ||
cb6f1f7d PP |
101 | struct bt_field_type_integer { |
102 | struct bt_field_type common; | |
312c056a | 103 | |
44c440bc PP |
104 | /* |
105 | * Value range of fields built from this integer field type: | |
106 | * this is an equivalent integer size in bits. More formally, | |
107 | * `range` is `n` in: | |
108 | * | |
109 | * Unsigned range: [0, 2^n - 1] | |
110 | * Signed range: [-2^(n - 1), 2^(n - 1) - 1] | |
111 | */ | |
112 | uint64_t range; | |
312c056a | 113 | |
44c440bc | 114 | enum bt_field_type_integer_preferred_display_base base; |
273b65be JG |
115 | }; |
116 | ||
44c440bc | 117 | struct bt_field_type_enumeration_mapping_range { |
b92ddaaa | 118 | union { |
44c440bc PP |
119 | uint64_t u; |
120 | int64_t i; | |
121 | } lower; | |
122 | ||
b92ddaaa | 123 | union { |
44c440bc PP |
124 | uint64_t u; |
125 | int64_t i; | |
126 | } upper; | |
273b65be JG |
127 | }; |
128 | ||
44c440bc PP |
129 | struct bt_field_type_enumeration_mapping { |
130 | GString *label; | |
312c056a | 131 | |
44c440bc PP |
132 | /* Array of `struct bt_field_type_enumeration_mapping_range` */ |
133 | GArray *ranges; | |
96e8f959 MD |
134 | }; |
135 | ||
44c440bc PP |
136 | struct bt_field_type_enumeration { |
137 | struct bt_field_type_integer common; | |
96e8f959 | 138 | |
44c440bc PP |
139 | /* Array of `struct bt_field_type_enumeration_mapping *` */ |
140 | GArray *mappings; | |
312c056a | 141 | |
44c440bc PP |
142 | /* |
143 | * This is an array of `const char *` which acts as a temporary | |
144 | * (potentially growing) buffer for | |
145 | * bt_field_type_unsigned_enumeration_get_mapping_labels_by_value() | |
146 | * and | |
147 | * bt_field_type_signed_enumeration_get_mapping_labels_by_value(). | |
148 | * | |
149 | * The actual strings are owned by the mappings above. | |
150 | */ | |
151 | GPtrArray *label_buf; | |
152 | }; | |
312c056a | 153 | |
44c440bc PP |
154 | struct bt_field_type_real { |
155 | struct bt_field_type common; | |
156 | bool is_single_precision; | |
273b65be JG |
157 | }; |
158 | ||
44c440bc | 159 | struct bt_field_type_string { |
cb6f1f7d | 160 | struct bt_field_type common; |
273b65be JG |
161 | }; |
162 | ||
44c440bc PP |
163 | /* A named field type is a (name, field type) pair */ |
164 | struct bt_named_field_type { | |
165 | GString *name; | |
312c056a PP |
166 | |
167 | /* Owned by this */ | |
44c440bc | 168 | struct bt_field_type *ft; |
273b65be JG |
169 | }; |
170 | ||
44c440bc PP |
171 | /* |
172 | * This is the base field type for a container of named field types. | |
173 | * Structure and variant field types inherit this. | |
174 | */ | |
175 | struct bt_field_type_named_field_types_container { | |
cb6f1f7d | 176 | struct bt_field_type common; |
312c056a PP |
177 | |
178 | /* | |
44c440bc PP |
179 | * Key: `const char *`, not owned by this (owned by named field |
180 | * type objects contained in `named_fts` below). | |
312c056a | 181 | */ |
44c440bc | 182 | GHashTable *name_to_index; |
312c056a | 183 | |
44c440bc PP |
184 | /* Array of `struct bt_named_field_type` */ |
185 | GArray *named_fts; | |
312c056a PP |
186 | }; |
187 | ||
44c440bc PP |
188 | struct bt_field_type_structure { |
189 | struct bt_field_type_named_field_types_container common; | |
273b65be JG |
190 | }; |
191 | ||
cb6f1f7d PP |
192 | struct bt_field_type_array { |
193 | struct bt_field_type common; | |
312c056a PP |
194 | |
195 | /* Owned by this */ | |
cb6f1f7d | 196 | struct bt_field_type *element_ft; |
44c440bc | 197 | }; |
312c056a | 198 | |
44c440bc PP |
199 | struct bt_field_type_static_array { |
200 | struct bt_field_type_array common; | |
201 | uint64_t length; | |
273b65be JG |
202 | }; |
203 | ||
44c440bc PP |
204 | struct bt_field_type_dynamic_array { |
205 | struct bt_field_type_array common; | |
312c056a | 206 | |
44c440bc PP |
207 | /* Weak: never dereferenced, only use to find it elsewhere */ |
208 | struct bt_field_type *length_ft; | |
312c056a PP |
209 | |
210 | /* Owned by this */ | |
50842bdc | 211 | struct bt_field_path *length_field_path; |
273b65be JG |
212 | }; |
213 | ||
44c440bc PP |
214 | struct bt_field_type_variant { |
215 | struct bt_field_type_named_field_types_container common; | |
216 | ||
217 | /* Weak: never dereferenced, only use to find it elsewhere */ | |
218 | struct bt_field_type *selector_ft; | |
273b65be | 219 | |
44c440bc PP |
220 | /* Owned by this */ |
221 | struct bt_field_path *selector_field_path; | |
222 | }; | |
3dca2276 | 223 | |
44c440bc PP |
224 | static inline |
225 | bool bt_field_type_has_known_id(struct bt_field_type *ft) | |
cb6f1f7d | 226 | { |
44c440bc PP |
227 | return ft->id >= BT_FIELD_TYPE_ID_UNSIGNED_INTEGER && |
228 | ft->id <= BT_FIELD_TYPE_ID_VARIANT; | |
cb6f1f7d | 229 | } |
3dca2276 PP |
230 | |
231 | BT_HIDDEN | |
44c440bc | 232 | void _bt_field_type_freeze(struct bt_field_type *field_type); |
3dca2276 | 233 | |
44c440bc PP |
234 | #ifdef BT_DEV_MODE |
235 | # define bt_field_type_freeze _bt_field_type_freeze | |
236 | #else | |
237 | # define bt_field_type_freeze(_ft) | |
238 | #endif | |
3dca2276 | 239 | |
44c440bc PP |
240 | /* |
241 | * This function recursively marks `field_type` and its children as | |
242 | * being part of a trace. This is used to validate that all field types | |
243 | * are used at a single location within trace objects even if they are | |
244 | * shared objects for other purposes. | |
245 | */ | |
3dca2276 | 246 | BT_HIDDEN |
44c440bc | 247 | void _bt_field_type_make_part_of_trace(struct bt_field_type *field_type); |
4e8304f7 | 248 | |
44c440bc PP |
249 | #ifdef BT_DEV_MODE |
250 | # define bt_field_type_make_part_of_trace _bt_field_type_make_part_of_trace | |
251 | #else | |
252 | # define bt_field_type_make_part_of_trace(_ft) ((void) _ft) | |
253 | #endif | |
312c056a | 254 | |
2e33ac5a | 255 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */ |