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