Commit | Line | Data |
---|---|---|
d79865b9 MD |
1 | #ifndef _BABELTRACE_TYPES_H |
2 | #define _BABELTRACE_TYPES_H | |
3 | ||
4 | /* | |
5 | * BabelTrace | |
6 | * | |
fc93b2bd | 7 | * Type Header |
d79865b9 | 8 | * |
64fa3fec MD |
9 | * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation |
10 | * | |
11 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
d79865b9 | 12 | * |
ccd7e1c8 MD |
13 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
14 | * of this software and associated documentation files (the "Software"), to deal | |
15 | * in the Software without restriction, including without limitation the rights | |
16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
17 | * copies of the Software, and to permit persons to whom the Software is | |
18 | * furnished to do so, subject to the following conditions: | |
d79865b9 | 19 | * |
ccd7e1c8 MD |
20 | * The above copyright notice and this permission notice shall be included in |
21 | * all copies or substantial portions of the Software. | |
d79865b9 MD |
22 | */ |
23 | ||
bed864a7 | 24 | #include <babeltrace/align.h> |
d65d8abb | 25 | #include <babeltrace/list.h> |
9843982d | 26 | #include <babeltrace/ctf/events.h> |
4c8bfb7e MD |
27 | #include <stdbool.h> |
28 | #include <stdint.h> | |
29 | #include <limits.h> | |
bed864a7 | 30 | #include <string.h> |
4c8bfb7e | 31 | #include <glib.h> |
8eab883c | 32 | #include <assert.h> |
bed864a7 | 33 | |
11796b96 MD |
34 | /* Preallocate this many fields for structures */ |
35 | #define DEFAULT_NR_STRUCT_FIELDS 8 | |
36 | ||
9e88d150 | 37 | struct ctf_stream_definition; |
dd2544fd | 38 | struct stream_pos; |
4c8bfb7e | 39 | struct format; |
e1151715 | 40 | struct definition; |
56e60373 | 41 | struct ctf_clock; |
4c8bfb7e | 42 | |
64893f33 | 43 | /* type scope */ |
f6625916 | 44 | struct declaration_scope { |
c13cbf74 | 45 | /* Hash table mapping type name GQuark to "struct declaration" */ |
1ee8e81d | 46 | /* Used for both typedef and typealias. */ |
f6625916 MD |
47 | GHashTable *typedef_declarations; |
48 | /* Hash table mapping struct name GQuark to "struct declaration_struct" */ | |
49 | GHashTable *struct_declarations; | |
50 | /* Hash table mapping variant name GQuark to "struct declaration_variant" */ | |
51 | GHashTable *variant_declarations; | |
c13cbf74 | 52 | /* Hash table mapping enum name GQuark to "struct type_enum" */ |
f6625916 MD |
53 | GHashTable *enum_declarations; |
54 | struct declaration_scope *parent_scope; | |
64893f33 MD |
55 | }; |
56 | ||
e1151715 MD |
57 | /* definition scope */ |
58 | struct definition_scope { | |
59 | /* Hash table mapping field name GQuark to "struct definition" */ | |
60 | GHashTable *definitions; | |
61 | struct definition_scope *parent_scope; | |
05c749e5 MD |
62 | /* |
63 | * Complete "path" leading to this definition scope. | |
9e29e16e | 64 | * Includes dynamic scope name '.' field name '.' field name '.' .... |
05c749e5 | 65 | * Array of GQuark elements (which are each separated by dots). |
9e29e16e MD |
66 | * The dynamic scope name can contain dots, and is encoded into |
67 | * a single GQuark. Thus, scope_path[0] returns the GQuark | |
68 | * identifying the dynamic scope. | |
05c749e5 MD |
69 | */ |
70 | GArray *scope_path; /* array of GQuark */ | |
6b71274a MD |
71 | }; |
72 | ||
f6625916 | 73 | struct declaration { |
05628561 | 74 | enum ctf_type_id id; |
fc93b2bd | 75 | size_t alignment; /* type alignment, in bits */ |
e19c3d69 | 76 | int ref; /* number of references to the type */ |
c054553d | 77 | /* |
f6625916 | 78 | * declaration_free called with declaration ref is decremented to 0. |
c054553d | 79 | */ |
f6625916 | 80 | void (*declaration_free)(struct declaration *declaration); |
e1151715 | 81 | struct definition * |
f6625916 | 82 | (*definition_new)(struct declaration *declaration, |
05c749e5 | 83 | struct definition_scope *parent_scope, |
98df1c9f MD |
84 | GQuark field_name, int index, |
85 | const char *root_name); | |
c054553d | 86 | /* |
e1151715 | 87 | * definition_free called with definition ref is decremented to 0. |
e19c3d69 | 88 | */ |
e1151715 | 89 | void (*definition_free)(struct definition *definition); |
c054553d MD |
90 | }; |
91 | ||
e1151715 | 92 | struct definition { |
f6625916 | 93 | struct declaration *declaration; |
05c749e5 | 94 | int index; /* Position of the definition in its container */ |
b1a2f580 | 95 | GQuark name; /* Field name in its container (or 0 if unset) */ |
e1151715 | 96 | int ref; /* number of references to the definition */ |
31262354 | 97 | GQuark path; |
a35173fe | 98 | struct definition_scope *scope; |
fc93b2bd MD |
99 | }; |
100 | ||
c5e74408 MD |
101 | typedef int (*rw_dispatch)(struct stream_pos *pos, |
102 | struct definition *definition); | |
d11e9c49 MD |
103 | |
104 | /* Parent of per-plugin positions */ | |
105 | struct stream_pos { | |
106 | /* read/write dispatch table. Specific to plugin used for stream. */ | |
107 | rw_dispatch *rw_table; /* rw dispatch table */ | |
31262354 | 108 | int (*event_cb)(struct stream_pos *pos, |
9e88d150 | 109 | struct ctf_stream_definition *stream); |
d11e9c49 MD |
110 | }; |
111 | ||
112 | static inline | |
c5e74408 | 113 | int generic_rw(struct stream_pos *pos, struct definition *definition) |
d11e9c49 MD |
114 | { |
115 | enum ctf_type_id dispatch_id = definition->declaration->id; | |
116 | rw_dispatch call; | |
117 | ||
118 | assert(pos->rw_table[dispatch_id] != NULL); | |
119 | call = pos->rw_table[dispatch_id]; | |
c5e74408 | 120 | return call(pos, definition); |
d11e9c49 MD |
121 | } |
122 | ||
bed864a7 MD |
123 | /* |
124 | * Because we address in bits, bitfields end up being exactly the same as | |
125 | * integers, except that their read/write functions must be able to deal with | |
126 | * read/write non aligned on CHAR_BIT. | |
127 | */ | |
f6625916 MD |
128 | struct declaration_integer { |
129 | struct declaration p; | |
7fe00194 MD |
130 | size_t len; /* length, in bits. */ |
131 | int byte_order; /* byte order */ | |
132 | int signedness; | |
164078da | 133 | int base; /* Base for pretty-printing: 2, 8, 10, 16 */ |
81dee1bb | 134 | enum ctf_string_encoding encoding; |
56e60373 | 135 | struct ctf_clock *clock; |
fc93b2bd MD |
136 | }; |
137 | ||
e1151715 MD |
138 | struct definition_integer { |
139 | struct definition p; | |
f6625916 | 140 | struct declaration_integer *declaration; |
c054553d MD |
141 | /* Last values read */ |
142 | union { | |
143 | uint64_t _unsigned; | |
144 | int64_t _signed; | |
145 | } value; | |
146 | }; | |
147 | ||
f6625916 MD |
148 | struct declaration_float { |
149 | struct declaration p; | |
150 | struct declaration_integer *sign; | |
151 | struct declaration_integer *mantissa; | |
152 | struct declaration_integer *exp; | |
fc93b2bd | 153 | int byte_order; |
0a46062b | 154 | /* TODO: we might want to express more info about NaN, +inf and -inf */ |
fc93b2bd MD |
155 | }; |
156 | ||
e1151715 MD |
157 | struct definition_float { |
158 | struct definition p; | |
f6625916 | 159 | struct declaration_float *declaration; |
d11e9c49 MD |
160 | struct definition_integer *sign; |
161 | struct definition_integer *mantissa; | |
162 | struct definition_integer *exp; | |
c054553d | 163 | /* Last values read */ |
f72803ca | 164 | double value; |
c054553d MD |
165 | }; |
166 | ||
d65d8abb MD |
167 | /* |
168 | * enum_val_equal assumes that signed and unsigned memory layout overlap. | |
169 | */ | |
170 | struct enum_range { | |
171 | union { | |
172 | int64_t _signed; | |
173 | uint64_t _unsigned; | |
174 | } start; /* lowest range value */ | |
175 | union { | |
176 | int64_t _signed; | |
177 | uint64_t _unsigned; | |
178 | } end; /* highest range value */ | |
179 | }; | |
180 | ||
181 | struct enum_range_to_quark { | |
3122e6f0 | 182 | struct bt_list_head node; |
d65d8abb MD |
183 | struct enum_range range; |
184 | GQuark quark; | |
185 | }; | |
186 | ||
187 | /* | |
188 | * We optimize the common case (range of size 1: single value) by creating a | |
189 | * hash table mapping values to quark sets. We then lookup the ranges to | |
190 | * complete the quark set. | |
191 | * | |
192 | * TODO: The proper structure to hold the range to quark set mapping would be an | |
193 | * interval tree, with O(n) size, O(n*log(n)) build time and O(log(n)) query | |
194 | * time. Using a simple O(n) list search for now for implementation speed and | |
195 | * given that we can expect to have a _relatively_ small number of enumeration | |
196 | * ranges. This might become untrue if we are fed with symbol tables often | |
197 | * required to lookup function names from instruction pointer value. | |
198 | */ | |
448d3cc7 | 199 | struct enum_table { |
d65d8abb | 200 | GHashTable *value_to_quark_set; /* (value, GQuark GArray) */ |
3122e6f0 | 201 | struct bt_list_head range_to_quark; /* (range, GQuark) */ |
d65d8abb | 202 | GHashTable *quark_to_range_set; /* (GQuark, range GArray) */ |
448d3cc7 MD |
203 | }; |
204 | ||
f6625916 MD |
205 | struct declaration_enum { |
206 | struct declaration p; | |
207 | struct declaration_integer *integer_declaration; | |
448d3cc7 | 208 | struct enum_table table; |
fc93b2bd MD |
209 | }; |
210 | ||
e1151715 MD |
211 | struct definition_enum { |
212 | struct definition p; | |
213 | struct definition_integer *integer; | |
f6625916 | 214 | struct declaration_enum *declaration; |
c054553d MD |
215 | /* Last GQuark values read. Keeping a reference on the GQuark array. */ |
216 | GArray *value; | |
217 | }; | |
218 | ||
f6625916 MD |
219 | struct declaration_string { |
220 | struct declaration p; | |
ab4cf058 | 221 | enum ctf_string_encoding encoding; |
c054553d MD |
222 | }; |
223 | ||
e1151715 MD |
224 | struct definition_string { |
225 | struct definition p; | |
f6625916 | 226 | struct declaration_string *declaration; |
e1151715 | 227 | char *value; /* freed at definition_string teardown */ |
d11e9c49 | 228 | size_t len, alloc_len; |
11796b96 MD |
229 | }; |
230 | ||
f6625916 | 231 | struct declaration_field { |
e19c3d69 | 232 | GQuark name; |
f6625916 | 233 | struct declaration *declaration; |
c054553d MD |
234 | }; |
235 | ||
f6625916 MD |
236 | struct declaration_struct { |
237 | struct declaration p; | |
e19c3d69 | 238 | GHashTable *fields_by_name; /* Tuples (field name, field index) */ |
f6625916 MD |
239 | struct declaration_scope *scope; |
240 | GArray *fields; /* Array of declaration_field */ | |
e19c3d69 MD |
241 | }; |
242 | ||
e1151715 MD |
243 | struct definition_struct { |
244 | struct definition p; | |
f6625916 | 245 | struct declaration_struct *declaration; |
b1a2f580 | 246 | GPtrArray *fields; /* Array of pointers to struct definition */ |
c054553d MD |
247 | }; |
248 | ||
d60cb676 | 249 | struct declaration_untagged_variant { |
f6625916 | 250 | struct declaration p; |
c054553d | 251 | GHashTable *fields_by_tag; /* Tuples (field tag, field index) */ |
f6625916 MD |
252 | struct declaration_scope *scope; |
253 | GArray *fields; /* Array of declaration_field */ | |
c054553d MD |
254 | }; |
255 | ||
d60cb676 MD |
256 | struct declaration_variant { |
257 | struct declaration p; | |
258 | struct declaration_untagged_variant *untagged_variant; | |
259 | GArray *tag_name; /* Array of GQuark */ | |
260 | }; | |
261 | ||
262 | /* A variant needs to be tagged to be defined. */ | |
e1151715 MD |
263 | struct definition_variant { |
264 | struct definition p; | |
f6625916 | 265 | struct declaration_variant *declaration; |
e1151715 | 266 | struct definition *enum_tag; |
b1a2f580 MD |
267 | GPtrArray *fields; /* Array of pointers to struct definition */ |
268 | struct definition *current_field; /* Last field read */ | |
11796b96 MD |
269 | }; |
270 | ||
f6625916 MD |
271 | struct declaration_array { |
272 | struct declaration p; | |
11796b96 | 273 | size_t len; |
f6625916 MD |
274 | struct declaration *elem; |
275 | struct declaration_scope *scope; | |
11796b96 MD |
276 | }; |
277 | ||
e1151715 MD |
278 | struct definition_array { |
279 | struct definition p; | |
f6625916 | 280 | struct declaration_array *declaration; |
b1a2f580 | 281 | GPtrArray *elems; /* Array of pointers to struct definition */ |
81dee1bb | 282 | GString *string; /* String for encoded integer children */ |
c054553d MD |
283 | }; |
284 | ||
f6625916 MD |
285 | struct declaration_sequence { |
286 | struct declaration p; | |
98df1c9f | 287 | GArray *length_name; /* Array of GQuark */ |
f6625916 MD |
288 | struct declaration *elem; |
289 | struct declaration_scope *scope; | |
e19c3d69 MD |
290 | }; |
291 | ||
e1151715 MD |
292 | struct definition_sequence { |
293 | struct definition p; | |
f6625916 | 294 | struct declaration_sequence *declaration; |
98df1c9f | 295 | struct definition_integer *length; |
b1a2f580 | 296 | GPtrArray *elems; /* Array of pointers to struct definition */ |
81dee1bb | 297 | GString *string; /* String for encoded integer children */ |
c054553d MD |
298 | }; |
299 | ||
f6625916 MD |
300 | int register_declaration(GQuark declaration_name, |
301 | struct declaration *declaration, | |
302 | struct declaration_scope *scope); | |
303 | struct declaration *lookup_declaration(GQuark declaration_name, | |
78af2bcd | 304 | struct declaration_scope *scope); |
c13cbf74 MD |
305 | |
306 | /* | |
307 | * Type scopes also contain a separate registry for struct, variant and | |
e1151715 | 308 | * enum types. Those register types rather than type definitions, so |
c13cbf74 MD |
309 | * that a named variant can be declared without specifying its target |
310 | * "choice" tag field immediately. | |
311 | */ | |
f6625916 MD |
312 | int register_struct_declaration(GQuark struct_name, |
313 | struct declaration_struct *struct_declaration, | |
314 | struct declaration_scope *scope); | |
315 | struct declaration_struct * | |
316 | lookup_struct_declaration(GQuark struct_name, | |
317 | struct declaration_scope *scope); | |
318 | int register_variant_declaration(GQuark variant_name, | |
a0720417 | 319 | struct declaration_untagged_variant *untagged_variant_declaration, |
f6625916 | 320 | struct declaration_scope *scope); |
a0720417 | 321 | struct declaration_untagged_variant *lookup_variant_declaration(GQuark variant_name, |
f6625916 MD |
322 | struct declaration_scope *scope); |
323 | int register_enum_declaration(GQuark enum_name, | |
324 | struct declaration_enum *enum_declaration, | |
325 | struct declaration_scope *scope); | |
326 | struct declaration_enum * | |
327 | lookup_enum_declaration(GQuark enum_name, | |
328 | struct declaration_scope *scope); | |
329 | ||
330 | struct declaration_scope * | |
331 | new_declaration_scope(struct declaration_scope *parent_scope); | |
332 | void free_declaration_scope(struct declaration_scope *scope); | |
c054553d | 333 | |
c13cbf74 | 334 | /* |
e1151715 MD |
335 | * field_definition is for field definitions. They are registered into |
336 | * definition scopes. | |
c13cbf74 | 337 | */ |
e1151715 | 338 | struct definition * |
a35173fe MD |
339 | lookup_path_definition(GArray *cur_path, /* array of GQuark */ |
340 | GArray *lookup_path, /* array of GQuark */ | |
341 | struct definition_scope *scope); | |
e1151715 MD |
342 | int register_field_definition(GQuark field_name, |
343 | struct definition *definition, | |
344 | struct definition_scope *scope); | |
345 | struct definition_scope * | |
05c749e5 | 346 | new_definition_scope(struct definition_scope *parent_scope, |
98df1c9f | 347 | GQuark field_name, const char *root_name); |
e1151715 | 348 | void free_definition_scope(struct definition_scope *scope); |
4c8bfb7e | 349 | |
98df1c9f MD |
350 | GQuark new_definition_path(struct definition_scope *parent_scope, |
351 | GQuark field_name, const char *root_name); | |
31262354 MD |
352 | |
353 | static inline | |
354 | int compare_definition_path(struct definition *definition, GQuark path) | |
355 | { | |
356 | return definition->path == path; | |
357 | } | |
358 | ||
f6625916 MD |
359 | void declaration_ref(struct declaration *declaration); |
360 | void declaration_unref(struct declaration *declaration); | |
64893f33 | 361 | |
e1151715 MD |
362 | void definition_ref(struct definition *definition); |
363 | void definition_unref(struct definition *definition); | |
698f0fe4 | 364 | |
add40b62 | 365 | struct declaration_integer *integer_declaration_new(size_t len, int byte_order, |
164078da | 366 | int signedness, size_t alignment, |
56e60373 MD |
367 | int base, enum ctf_string_encoding encoding, |
368 | struct ctf_clock *clock); | |
da320b83 JD |
369 | uint64_t get_unsigned_int(const struct definition *field); |
370 | int64_t get_signed_int(const struct definition *field); | |
8673030f JD |
371 | int get_int_signedness(const struct definition *field); |
372 | int get_int_byte_order(const struct definition *field); | |
373 | int get_int_base(const struct definition *field); | |
fef0e521 | 374 | size_t get_int_len(const struct definition *field); /* in bits */ |
8673030f | 375 | enum ctf_string_encoding get_int_encoding(const struct definition *field); |
0a46062b | 376 | |
11d43b90 MD |
377 | /* |
378 | * mantissa_len is the length of the number of bytes represented by the mantissa | |
379 | * (e.g. result of DBL_MANT_DIG). It includes the leading 1. | |
380 | */ | |
add40b62 | 381 | struct declaration_float *float_declaration_new(size_t mantissa_len, |
e19c3d69 MD |
382 | size_t exp_len, int byte_order, |
383 | size_t alignment); | |
0a46062b | 384 | |
448d3cc7 MD |
385 | /* |
386 | * A GQuark can be translated to/from strings with g_quark_from_string() and | |
387 | * g_quark_to_string(). | |
388 | */ | |
47e0f2e2 MD |
389 | |
390 | /* | |
391 | * Returns a GArray of GQuark or NULL. | |
392 | * Caller must release the GArray with g_array_unref(). | |
393 | */ | |
f6625916 MD |
394 | GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration, |
395 | uint64_t v); | |
d65d8abb MD |
396 | |
397 | /* | |
47e0f2e2 | 398 | * Returns a GArray of GQuark or NULL. |
d65d8abb MD |
399 | * Caller must release the GArray with g_array_unref(). |
400 | */ | |
f6625916 | 401 | GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration, |
bcdf4cf2 | 402 | int64_t v); |
47e0f2e2 MD |
403 | |
404 | /* | |
405 | * Returns a GArray of struct enum_range or NULL. | |
fdacfb73 MD |
406 | * Callers do _not_ own the returned GArray (and therefore _don't_ need to |
407 | * release it). | |
47e0f2e2 | 408 | */ |
f6625916 MD |
409 | GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration, |
410 | GQuark q); | |
411 | void enum_signed_insert(struct declaration_enum *enum_declaration, | |
d65d8abb | 412 | int64_t start, int64_t end, GQuark q); |
f6625916 | 413 | void enum_unsigned_insert(struct declaration_enum *enum_declaration, |
d65d8abb | 414 | uint64_t start, uint64_t end, GQuark q); |
f6625916 MD |
415 | size_t enum_get_nr_enumerators(struct declaration_enum *enum_declaration); |
416 | ||
417 | struct declaration_enum * | |
ab4cf058 | 418 | enum_declaration_new(struct declaration_integer *integer_declaration); |
f6625916 | 419 | |
e397791f MD |
420 | struct declaration_string * |
421 | string_declaration_new(enum ctf_string_encoding encoding); | |
da320b83 | 422 | char *get_string(const struct definition *field); |
8673030f | 423 | enum ctf_string_encoding get_string_encoding(const struct definition *field); |
e397791f | 424 | |
f6625916 | 425 | struct declaration_struct * |
b7e35bad MD |
426 | struct_declaration_new(struct declaration_scope *parent_scope, |
427 | uint64_t min_align); | |
f6625916 MD |
428 | void struct_declaration_add_field(struct declaration_struct *struct_declaration, |
429 | const char *field_name, | |
430 | struct declaration *field_declaration); | |
11796b96 MD |
431 | /* |
432 | * Returns the index of a field within a structure. | |
433 | */ | |
0f980a35 | 434 | int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration, |
f6625916 | 435 | GQuark field_name); |
11796b96 MD |
436 | /* |
437 | * field returned only valid as long as the field structure is not appended to. | |
438 | */ | |
f6625916 MD |
439 | struct declaration_field * |
440 | struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration, | |
0f980a35 | 441 | int index); |
b1a2f580 | 442 | struct definition * |
0f980a35 MD |
443 | struct_definition_get_field_from_index(struct definition_struct *struct_definition, |
444 | int index); | |
c5e74408 | 445 | int struct_rw(struct stream_pos *pos, struct definition *definition); |
fd3382e8 | 446 | uint64_t struct_declaration_len(struct declaration_struct *struct_declaration); |
11796b96 | 447 | |
c054553d MD |
448 | /* |
449 | * The tag enumeration is validated to ensure that it contains only mappings | |
450 | * from numeric values to a single tag. Overlapping tag value ranges are | |
451 | * therefore forbidden. | |
452 | */ | |
ab4cf058 | 453 | struct declaration_untagged_variant *untagged_variant_declaration_new( |
1934b94f | 454 | struct declaration_scope *parent_scope); |
d60cb676 MD |
455 | struct declaration_variant *variant_declaration_new(struct declaration_untagged_variant *untagged_variant, |
456 | const char *tag); | |
457 | ||
458 | void untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration, | |
459 | const char *field_name, | |
460 | struct declaration *field_declaration); | |
f6625916 | 461 | struct declaration_field * |
d60cb676 | 462 | untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, |
1934b94f | 463 | GQuark tag); |
c054553d MD |
464 | /* |
465 | * Returns 0 on success, -EPERM on error. | |
466 | */ | |
e1151715 MD |
467 | int variant_definition_set_tag(struct definition_variant *variant, |
468 | struct definition *enum_tag); | |
c054553d MD |
469 | /* |
470 | * Returns the field selected by the current tag value. | |
471 | * field returned only valid as long as the variant structure is not appended | |
472 | * to. | |
473 | */ | |
b1a2f580 | 474 | struct definition *variant_get_current_field(struct definition_variant *variant); |
c5e74408 | 475 | int variant_rw(struct stream_pos *pos, struct definition *definition); |
c054553d | 476 | |
d06d03db | 477 | /* |
f6625916 MD |
478 | * elem_declaration passed as parameter now belongs to the array. No |
479 | * need to free it explicitly. "len" is the number of elements in the | |
480 | * array. | |
d06d03db | 481 | */ |
f6625916 | 482 | struct declaration_array * |
ab4cf058 | 483 | array_declaration_new(size_t len, struct declaration *elem_declaration, |
1934b94f | 484 | struct declaration_scope *parent_scope); |
3838df27 | 485 | uint64_t array_len(struct definition_array *array); |
0f980a35 | 486 | struct definition *array_index(struct definition_array *array, uint64_t i); |
c5e74408 | 487 | int array_rw(struct stream_pos *pos, struct definition *definition); |
da320b83 | 488 | GString *get_char_array(const struct definition *field); |
8673030f | 489 | int get_array_len(const struct definition *field); |
11796b96 | 490 | |
d06d03db | 491 | /* |
f6625916 MD |
492 | * int_declaration and elem_declaration passed as parameter now belong |
493 | * to the sequence. No need to free them explicitly. | |
d06d03db | 494 | */ |
f6625916 | 495 | struct declaration_sequence * |
98df1c9f | 496 | sequence_declaration_new(const char *length_name, |
1934b94f MD |
497 | struct declaration *elem_declaration, |
498 | struct declaration_scope *parent_scope); | |
3838df27 | 499 | uint64_t sequence_len(struct definition_sequence *sequence); |
0f980a35 | 500 | struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i); |
c5e74408 | 501 | int sequence_rw(struct stream_pos *pos, struct definition *definition); |
11796b96 | 502 | |
d60cb676 MD |
503 | /* |
504 | * in: path (dot separated), out: q (GArray of GQuark) | |
505 | */ | |
506 | void append_scope_path(const char *path, GArray *q); | |
507 | ||
a35173fe MD |
508 | /* |
509 | * Lookup helpers. | |
510 | */ | |
04ae3991 | 511 | struct definition *lookup_definition(const struct definition *definition, |
620961f6 | 512 | const char *field_name); |
04ae3991 | 513 | struct definition_integer *lookup_integer(const struct definition *definition, |
a35173fe MD |
514 | const char *field_name, |
515 | int signedness); | |
04ae3991 | 516 | struct definition_enum *lookup_enum(const struct definition *definition, |
a35173fe MD |
517 | const char *field_name, |
518 | int signedness); | |
04ae3991 | 519 | struct definition *lookup_variant(const struct definition *definition, |
a35173fe MD |
520 | const char *field_name); |
521 | ||
300d317a JD |
522 | static inline |
523 | const char *rem_(const char *str) | |
524 | { | |
525 | if (str[0] == '_') | |
526 | return &str[1]; | |
527 | else | |
528 | return str; | |
529 | } | |
530 | ||
31262354 | 531 | #endif /* _BABELTRACE_TYPES_H */ |