2 * ctf-visitor-generate-io-struct.c
4 * Common Trace Format Metadata Visitor (generate I/O structures).
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
28 #include <babeltrace/list.h>
29 #include <babeltrace/types.h>
30 #include <babeltrace/ctf/metadata.h>
31 #include <uuid/uuid.h>
32 #include "ctf-scanner.h"
33 #include "ctf-parser.h"
36 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
38 #define _cds_list_first_entry(ptr, type, member) \
39 cds_list_entry((ptr)->next, type, member)
42 struct declaration
*ctf_declaration_specifier_visit(FILE *fd
,
43 int depth
, struct cds_list_head
*head
,
44 struct declaration_scope
*declaration_scope
,
45 struct ctf_trace
*trace
);
48 * String returned must be freed by the caller using g_free.
51 char *concatenate_unary_strings(struct cds_list_head
*head
)
53 struct ctf_node
*node
;
57 str
= g_string_new("");
58 cds_list_for_each_entry(node
, head
, siblings
) {
61 assert(node
->type
== NODE_UNARY_EXPRESSION
);
62 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
63 assert((node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
)
65 switch (node
->u
.unary_expression
.link
) {
67 g_string_append(str
, ".");
70 g_string_append(str
, "->");
73 g_string_append(str
, "...");
78 src_string
= node
->u
.unary_expression
.u
.string
;
79 g_string_append(str
, src_string
);
82 return g_string_free(str
, FALSE
);
86 int get_unary_unsigned(struct cds_list_head
*head
, uint64_t *value
)
88 struct ctf_node
*node
;
91 cds_list_for_each_entry(node
, head
, siblings
) {
92 assert(node
->type
== NODE_UNARY_EXPRESSION
);
93 assert(node
->u
.unary_expression
.type
== UNARY_UNSIGNED_CONSTANT
);
94 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
96 *value
= node
->u
.unary_expression
.u
.unsigned_constant
;
103 int get_unary_uuid(struct cds_list_head
*head
, uuid_t
*uuid
)
105 struct ctf_node
*node
;
109 cds_list_for_each_entry(node
, head
, siblings
) {
110 const char *src_string
;
112 assert(node
->type
== NODE_UNARY_EXPRESSION
);
113 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
114 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
116 src_string
= node
->u
.unary_expression
.u
.string
;
117 ret
= uuid_parse(node
->u
.unary_expression
.u
.string
, *uuid
);
123 struct ctf_stream
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
125 if (trace
->streams
->len
<= stream_id
)
127 return g_ptr_array_index(trace
->streams
, stream_id
);
131 int visit_declaration_specifier(struct cds_list_head
*declaration_specifier
, GString
*str
)
133 struct ctf_node
*iter
;
134 int alias_item_nr
= 0;
137 cds_list_for_each_entry(iter
, declaration_specifier
, siblings
) {
138 if (alias_item_nr
!= 0)
139 g_string_append(str
, " ");
142 switch (iter
->type
) {
143 case NODE_TYPE_SPECIFIER
:
144 switch (iter
->u
.type_specifier
.type
) {
146 g_string_append(str
, "void");
149 g_string_append(str
, "char");
152 g_string_append(str
, "short");
155 g_string_append(str
, "int");
158 g_string_append(str
, "long");
161 g_string_append(str
, "float");
163 case TYPESPEC_DOUBLE
:
164 g_string_append(str
, "double");
166 case TYPESPEC_SIGNED
:
167 g_string_append(str
, "signed");
169 case TYPESPEC_UNSIGNED
:
170 g_string_append(str
, "unsigned");
173 g_string_append(str
, "bool");
175 case TYPESPEC_COMPLEX
:
176 g_string_append(str
, "_Complex");
178 case TYPESPEC_IMAGINARY
:
179 g_string_append(str
, "_Imaginary");
182 g_string_append(str
, "const");
184 case TYPESPEC_ID_TYPE
:
185 if (iter
->u
.type_specifier
.id_type
)
186 g_string_append(str
, iter
->u
.type_specifier
.id_type
);
189 fprintf(stderr
, "[error] %s: unknown specifier\n", __func__
);
195 if (!iter
->u
._enum
.enum_id
) {
196 fprintf(stderr
, "[error] %s: unexpected empty enum ID\n", __func__
);
200 g_string_append(str
, "enum ");
201 g_string_append(str
, iter
->u
._enum
.enum_id
);
204 if (!iter
->u
.variant
.name
) {
205 fprintf(stderr
, "[error] %s: unexpected empty variant name\n", __func__
);
209 g_string_append(str
, "variant ");
210 g_string_append(str
, iter
->u
.variant
.name
);
213 if (!iter
->u
._struct
.name
) {
214 fprintf(stderr
, "[error] %s: unexpected empty variant name\n", __func__
);
218 g_string_append(str
, "struct ");
219 g_string_append(str
, iter
->u
._struct
.name
);
222 fprintf(stderr
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
233 GQuark
create_typealias_identifier(FILE *fd
, int depth
,
234 struct cds_list_head
*declaration_specifier
,
235 struct ctf_node
*node_type_declarator
)
237 struct ctf_node
*iter
;
243 str
= g_string_new("");
244 ret
= visit_declaration_specifier(declaration_specifier
, str
);
246 g_string_free(str
, TRUE
);
249 cds_list_for_each_entry(iter
, &node_type_declarator
->u
.type_declarator
.pointers
, siblings
) {
250 g_string_append(str
, " *");
251 if (iter
->u
.pointer
.const_qualifier
)
252 g_string_append(str
, " const");
254 str_c
= g_string_free(str
, FALSE
);
255 alias_q
= g_quark_from_string(str_c
);
261 struct declaration
*ctf_type_declarator_visit(FILE *fd
, int depth
,
262 struct cds_list_head
*declaration_specifier
,
264 struct ctf_node
*node_type_declarator
,
265 struct declaration_scope
*declaration_scope
,
266 struct declaration
*nested_declaration
,
267 struct ctf_trace
*trace
)
270 * Visit type declarator by first taking care of sequence/array
271 * (recursively). Then, when we get to the identifier, take care
275 if (node_type_declarator
) {
276 assert(node_type_declarator
->u
.type_declarator
.type
!= TYPEDEC_UNKNOWN
);
278 /* TODO: gcc bitfields not supported yet. */
279 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!= NULL
) {
280 fprintf(stderr
, "[error] %s: gcc bitfields are not supported yet.\n", __func__
);
285 if (!nested_declaration
) {
286 if (node_type_declarator
&& !cds_list_empty(&node_type_declarator
->u
.type_declarator
.pointers
)) {
290 * If we have a pointer declarator, it _has_ to be present in
291 * the typealiases (else fail).
293 alias_q
= create_typealias_identifier(fd
, depth
,
294 declaration_specifier
, node_type_declarator
);
295 nested_declaration
= lookup_declaration(alias_q
, declaration_scope
);
296 if (!nested_declaration
) {
297 fprintf(stderr
, "[error] %s: cannot find typealias \"%s\".\n", __func__
, g_quark_to_string(alias_q
));
301 nested_declaration
= ctf_declaration_specifier_visit(fd
, depth
,
302 declaration_specifier
, declaration_scope
, trace
);
306 if (!node_type_declarator
)
307 return nested_declaration
;
309 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
310 if (node_type_declarator
->u
.type_declarator
.u
.id
)
311 *field_name
= g_quark_from_string(node_type_declarator
->u
.type_declarator
.u
.id
);
314 return nested_declaration
;
316 struct declaration
*declaration
;
317 struct cds_list_head
*length
;
318 struct ctf_node
*first
;
322 /* create array/sequence, pass nested_declaration as child. */
323 length
= &node_type_declarator
->u
.type_declarator
.u
.nested
.length
;
324 if (cds_list_empty(length
)) {
325 fprintf(stderr
, "[error] %s: expecting length type or value.\n", __func__
);
328 first
= _cds_list_first_entry(length
, struct ctf_node
, siblings
);
329 switch (first
->type
) {
330 case NODE_UNARY_EXPRESSION
:
332 struct declaration_array
*array_declaration
;
335 if (first
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
336 fprintf(stderr
, "[error] %s: array: unexpected unary expression.\n", __func__
);
339 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
340 array_declaration
= array_declaration_new(len
, nested_declaration
,
342 declaration
= &array_declaration
->p
;
346 case NODE_TYPE_SPECIFIER
:
348 struct declaration_sequence
*sequence_declaration
;
349 struct declaration_integer
*integer_declaration
;
352 declaration
= ctf_type_declarator_visit(fd
, depth
,
357 assert(declaration
->id
== CTF_TYPE_INTEGER
);
358 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
359 sequence_declaration
= sequence_declaration_new(integer_declaration
,
360 nested_declaration
, declaration_scope
);
361 declaration
= &sequence_declaration
->p
;
368 /* Pass it as content of outer container */
369 declaration
= ctf_type_declarator_visit(fd
, depth
,
370 declaration_specifier
, field_name
,
371 node_type_declarator
->u
.type_declarator
.u
.nested
.type_declarator
,
372 declaration_scope
, declaration
, trace
);
378 int ctf_struct_type_declarators_visit(FILE *fd
, int depth
,
379 struct declaration_struct
*struct_declaration
,
380 struct cds_list_head
*declaration_specifier
,
381 struct cds_list_head
*type_declarators
,
382 struct declaration_scope
*declaration_scope
,
383 struct ctf_trace
*trace
)
385 struct ctf_node
*iter
;
388 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
389 struct declaration
*field_declaration
;
391 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
392 declaration_specifier
,
394 struct_declaration
->scope
,
396 struct_declaration_add_field(struct_declaration
,
397 g_quark_to_string(field_name
),
404 int ctf_variant_type_declarators_visit(FILE *fd
, int depth
,
405 struct declaration_untagged_variant
*untagged_variant_declaration
,
406 struct cds_list_head
*declaration_specifier
,
407 struct cds_list_head
*type_declarators
,
408 struct declaration_scope
*declaration_scope
,
409 struct ctf_trace
*trace
)
411 struct ctf_node
*iter
;
414 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
415 struct declaration
*field_declaration
;
417 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
418 declaration_specifier
,
420 untagged_variant_declaration
->scope
,
422 untagged_variant_declaration_add_field(untagged_variant_declaration
,
423 g_quark_to_string(field_name
),
430 int ctf_typedef_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
431 struct cds_list_head
*declaration_specifier
,
432 struct cds_list_head
*type_declarators
,
433 struct ctf_trace
*trace
)
435 struct ctf_node
*iter
;
438 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
439 struct declaration
*type_declaration
;
442 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
443 declaration_specifier
,
446 ret
= register_declaration(identifier
, type_declaration
, scope
);
448 type_declaration
->declaration_free(type_declaration
);
456 int ctf_typealias_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
457 struct ctf_node
*target
, struct ctf_node
*alias
,
458 struct ctf_trace
*trace
)
460 struct declaration
*type_declaration
;
461 struct ctf_node
*node
;
466 /* See ctf_visitor_type_declarator() in the semantic validator. */
469 * Create target type declaration.
472 if (cds_list_empty(&alias
->u
.typealias_target
.type_declarators
))
475 node
= _cds_list_first_entry(&alias
->u
.typealias_target
.type_declarators
,
476 struct ctf_node
, siblings
);
477 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
478 &target
->u
.typealias_target
.declaration_specifier
,
481 if (!type_declaration
) {
482 fprintf(stderr
, "[error] %s: problem creating type declaration\n", __func__
);
487 * The semantic validator does not check whether the target is
488 * abstract or not (if it has an identifier). Check it here.
491 fprintf(stderr
, "[error] %s: expecting empty identifier\n", __func__
);
496 * Create alias identifier.
499 node
= _cds_list_first_entry(&alias
->u
.typealias_alias
.type_declarators
,
500 struct ctf_node
, siblings
);
501 alias_q
= create_typealias_identifier(fd
, depth
,
502 &alias
->u
.typealias_alias
.declaration_specifier
, node
);
503 err
= register_declaration(alias_q
, type_declaration
, scope
);
509 type_declaration
->declaration_free(type_declaration
);
514 int ctf_struct_declaration_list_visit(FILE *fd
, int depth
,
515 struct ctf_node
*iter
, struct declaration_struct
*struct_declaration
,
516 struct ctf_trace
*trace
)
520 switch (iter
->type
) {
522 /* For each declarator, declare type and add type to struct declaration scope */
523 ret
= ctf_typedef_visit(fd
, depth
,
524 struct_declaration
->scope
,
525 &iter
->u
._typedef
.declaration_specifier
,
526 &iter
->u
._typedef
.type_declarators
, trace
);
531 /* Declare type with declarator and add type to struct declaration scope */
532 ret
= ctf_typealias_visit(fd
, depth
,
533 struct_declaration
->scope
,
534 iter
->u
.typealias
.target
,
535 iter
->u
.typealias
.alias
, trace
);
539 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
540 /* Add field to structure declaration */
541 ret
= ctf_struct_type_declarators_visit(fd
, depth
,
543 &iter
->u
.struct_or_variant_declaration
.declaration_specifier
,
544 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
545 struct_declaration
->scope
, trace
);
550 fprintf(stderr
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
557 int ctf_variant_declaration_list_visit(FILE *fd
, int depth
,
558 struct ctf_node
*iter
,
559 struct declaration_untagged_variant
*untagged_variant_declaration
,
560 struct ctf_trace
*trace
)
564 switch (iter
->type
) {
566 /* For each declarator, declare type and add type to variant declaration scope */
567 ret
= ctf_typedef_visit(fd
, depth
,
568 untagged_variant_declaration
->scope
,
569 &iter
->u
._typedef
.declaration_specifier
,
570 &iter
->u
._typedef
.type_declarators
, trace
);
575 /* Declare type with declarator and add type to variant declaration scope */
576 ret
= ctf_typealias_visit(fd
, depth
,
577 untagged_variant_declaration
->scope
,
578 iter
->u
.typealias
.target
,
579 iter
->u
.typealias
.alias
, trace
);
583 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
584 /* Add field to structure declaration */
585 ret
= ctf_variant_type_declarators_visit(fd
, depth
,
586 untagged_variant_declaration
,
587 &iter
->u
.struct_or_variant_declaration
.declaration_specifier
,
588 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
589 untagged_variant_declaration
->scope
, trace
);
594 fprintf(stderr
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
601 struct declaration
*ctf_declaration_struct_visit(FILE *fd
,
602 int depth
, const char *name
, struct cds_list_head
*declaration_list
,
603 int has_body
, struct declaration_scope
*declaration_scope
,
604 struct ctf_trace
*trace
)
606 struct declaration_struct
*struct_declaration
;
607 struct ctf_node
*iter
;
611 * For named struct (without body), lookup in
612 * declaration scope. Don't take reference on struct
613 * declaration: ref is only taken upon definition.
618 lookup_struct_declaration(g_quark_from_string(name
),
620 return &struct_declaration
->p
;
622 /* For unnamed struct, create type */
623 /* For named struct (with body), create type and add to declaration scope */
625 if (lookup_struct_declaration(g_quark_from_string(name
),
626 declaration_scope
)) {
628 fprintf(stderr
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
632 struct_declaration
= struct_declaration_new(declaration_scope
);
633 cds_list_for_each_entry(iter
, declaration_list
, siblings
) {
634 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
635 struct_declaration
, trace
);
640 ret
= register_struct_declaration(g_quark_from_string(name
),
645 return &struct_declaration
->p
;
648 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
653 struct declaration
*ctf_declaration_variant_visit(FILE *fd
,
654 int depth
, const char *name
, const char *choice
,
655 struct cds_list_head
*declaration_list
,
656 int has_body
, struct declaration_scope
*declaration_scope
,
657 struct ctf_trace
*trace
)
659 struct declaration_untagged_variant
*untagged_variant_declaration
;
660 struct declaration_variant
*variant_declaration
;
661 struct ctf_node
*iter
;
665 * For named variant (without body), lookup in
666 * declaration scope. Don't take reference on variant
667 * declaration: ref is only taken upon definition.
671 untagged_variant_declaration
=
672 lookup_variant_declaration(g_quark_from_string(name
),
675 /* For unnamed variant, create type */
676 /* For named variant (with body), create type and add to declaration scope */
678 if (lookup_variant_declaration(g_quark_from_string(name
),
679 declaration_scope
)) {
681 fprintf(stderr
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
685 untagged_variant_declaration
= untagged_variant_declaration_new(declaration_scope
);
686 cds_list_for_each_entry(iter
, declaration_list
, siblings
) {
687 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
688 untagged_variant_declaration
, trace
);
693 ret
= register_variant_declaration(g_quark_from_string(name
),
694 untagged_variant_declaration
,
700 * if tagged, create tagged variant and return. else return
704 return &untagged_variant_declaration
->p
;
706 variant_declaration
= variant_declaration_new(untagged_variant_declaration
, choice
);
707 if (!variant_declaration
)
709 declaration_unref(&untagged_variant_declaration
->p
);
710 return &variant_declaration
->p
;
713 untagged_variant_declaration
->p
.declaration_free(&variant_declaration
->p
);
718 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
719 struct ctf_node
*enumerator
,
720 struct declaration_enum
*enum_declaration
)
723 struct ctf_node
*iter
;
725 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
726 if (enum_declaration
->integer_declaration
->signedness
) {
730 cds_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
733 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
739 switch (iter
->u
.unary_expression
.type
) {
740 case UNARY_SIGNED_CONSTANT
:
741 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
743 case UNARY_UNSIGNED_CONSTANT
:
744 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
747 fprintf(stderr
, "[error] %s: invalid enumerator\n", __func__
);
751 fprintf(stderr
, "[error] %s: invalid enumerator\n", __func__
);
758 enum_signed_insert(enum_declaration
, start
, end
, q
);
763 cds_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
766 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
772 switch (iter
->u
.unary_expression
.type
) {
773 case UNARY_UNSIGNED_CONSTANT
:
774 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
776 case UNARY_SIGNED_CONSTANT
:
778 * We don't accept signed constants for enums with unsigned
781 fprintf(stderr
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
784 fprintf(stderr
, "[error] %s: invalid enumerator\n", __func__
);
788 fprintf(stderr
, "[error] %s: invalid enumerator\n", __func__
);
795 enum_unsigned_insert(enum_declaration
, start
, end
, q
);
801 struct declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
803 struct cds_list_head
*container_type
,
804 struct cds_list_head
*enumerator_list
,
806 struct declaration_scope
*declaration_scope
,
807 struct ctf_trace
*trace
)
809 struct declaration
*declaration
;
810 struct declaration_enum
*enum_declaration
;
811 struct declaration_integer
*integer_declaration
;
812 struct ctf_node
*iter
, *first
;
817 * For named enum (without body), lookup in
818 * declaration scope. Don't take reference on enum
819 * declaration: ref is only taken upon definition.
824 lookup_enum_declaration(g_quark_from_string(name
),
826 return &enum_declaration
->p
;
828 /* For unnamed enum, create type */
829 /* For named enum (with body), create type and add to declaration scope */
831 if (lookup_enum_declaration(g_quark_from_string(name
),
832 declaration_scope
)) {
834 fprintf(stderr
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
838 if (cds_list_empty(container_type
)) {
839 fprintf(stderr
, "[error] %s: missing container type for enumeration\n", __func__
);
843 first
= _cds_list_first_entry(container_type
, struct ctf_node
, siblings
);
844 switch (first
->type
) {
846 case NODE_TYPE_SPECIFIER
:
847 declaration
= ctf_type_declarator_visit(fd
, depth
,
852 assert(declaration
->id
== CTF_TYPE_INTEGER
);
853 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
858 enum_declaration
= enum_declaration_new(integer_declaration
);
859 declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
860 cds_list_for_each_entry(iter
, enumerator_list
, siblings
) {
861 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
);
866 ret
= register_enum_declaration(g_quark_from_string(name
),
871 return &enum_declaration
->p
;
874 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
879 struct declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
880 struct cds_list_head
*declaration_specifier
,
881 struct declaration_scope
*declaration_scope
)
884 struct declaration
*declaration
;
889 str
= g_string_new("");
890 ret
= visit_declaration_specifier(declaration_specifier
, str
);
893 str_c
= g_string_free(str
, FALSE
);
894 id_q
= g_quark_from_string(str_c
);
896 declaration
= lookup_declaration(id_q
, declaration_scope
);
901 * Returns 0/1 boolean, or < 0 on error.
904 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
906 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
907 fprintf(stderr
, "[error] %s: expecting unary expression\n",
911 switch (unary_expression
->u
.unary_expression
.type
) {
912 case UNARY_UNSIGNED_CONSTANT
:
913 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
917 case UNARY_SIGNED_CONSTANT
:
918 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
923 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
925 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
927 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
929 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
932 fprintf(stderr
, "[error] %s: unexpected string \"%s\"\n",
933 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
938 fprintf(stderr
, "[error] %s: unexpected unary expression type\n",
946 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
947 struct ctf_trace
*trace
)
951 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
952 fprintf(stderr
, "[error] %s: byte_order: expecting string\n",
956 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
957 byte_order
= trace
->byte_order
;
958 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
959 byte_order
= BIG_ENDIAN
;
960 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
961 byte_order
= BIG_ENDIAN
;
962 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
963 byte_order
= LITTLE_ENDIAN
;
965 fprintf(stderr
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
966 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
973 struct declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
974 struct cds_list_head
*expressions
,
975 struct ctf_trace
*trace
)
977 struct ctf_node
*expression
;
978 uint64_t alignment
, size
;
979 int byte_order
= trace
->byte_order
;
981 int has_alignment
= 0, has_size
= 0;
982 struct declaration_integer
*integer_declaration
;
984 cds_list_for_each_entry(expression
, expressions
, siblings
) {
985 struct ctf_node
*left
, *right
;
987 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
988 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
989 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
990 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
991 signedness
= get_boolean(fd
, depth
, right
);
994 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
995 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
998 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
999 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1000 fprintf(stderr
, "[error] %s: size: expecting unsigned constant\n",
1004 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1006 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1007 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1008 fprintf(stderr
, "[error] %s: align: expecting unsigned constant\n",
1012 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1015 fprintf(stderr
, "[error] %s: unknown attribute name %s\n",
1016 __func__
, left
->u
.unary_expression
.u
.string
);
1021 fprintf(stderr
, "[error] %s: missing size attribute\n", __func__
);
1024 if (!has_alignment
) {
1025 if (size
% CHAR_BIT
) {
1026 /* bit-packed alignment */
1029 /* byte-packed alignment */
1030 alignment
= CHAR_BIT
;
1033 integer_declaration
= integer_declaration_new(size
,
1034 byte_order
, signedness
, alignment
);
1035 return &integer_declaration
->p
;
1039 struct declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1040 struct cds_list_head
*expressions
,
1041 struct ctf_trace
*trace
)
1043 struct ctf_node
*expression
;
1044 uint64_t alignment
, exp_dig
, mant_dig
, byte_order
= trace
->byte_order
;
1045 int has_alignment
= 0, has_exp_dig
= 0, has_mant_dig
= 0;
1046 struct declaration_float
*float_declaration
;
1048 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1049 struct ctf_node
*left
, *right
;
1051 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1052 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1053 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1054 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1055 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1058 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1059 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1060 fprintf(stderr
, "[error] %s: exp_dig: expecting unsigned constant\n",
1064 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1066 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1067 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1068 fprintf(stderr
, "[error] %s: mant_dig: expecting unsigned constant\n",
1072 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1074 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1075 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1076 fprintf(stderr
, "[error] %s: align: expecting unsigned constant\n",
1080 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1083 fprintf(stderr
, "[error] %s: unknown attribute name %s\n",
1084 __func__
, left
->u
.unary_expression
.u
.string
);
1088 if (!has_mant_dig
) {
1089 fprintf(stderr
, "[error] %s: missing mant_dig attribute\n", __func__
);
1093 fprintf(stderr
, "[error] %s: missing exp_dig attribute\n", __func__
);
1096 if (!has_alignment
) {
1097 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1098 /* bit-packed alignment */
1101 /* byte-packed alignment */
1102 alignment
= CHAR_BIT
;
1105 float_declaration
= float_declaration_new(mant_dig
, exp_dig
,
1106 byte_order
, alignment
);
1107 return &float_declaration
->p
;
1111 struct declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1112 struct cds_list_head
*expressions
,
1113 struct ctf_trace
*trace
)
1115 struct ctf_node
*expression
;
1116 const char *encoding_c
= NULL
;
1117 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1118 struct declaration_string
*string_declaration
;
1120 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1121 struct ctf_node
*left
, *right
;
1123 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1124 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1125 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1126 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1127 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1128 fprintf(stderr
, "[error] %s: encoding: expecting string\n",
1132 encoding_c
= right
->u
.unary_expression
.u
.string
;
1134 fprintf(stderr
, "[error] %s: unknown attribute name %s\n",
1135 __func__
, left
->u
.unary_expression
.u
.string
);
1139 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1140 encoding
= CTF_STRING_ASCII
;
1141 string_declaration
= string_declaration_new(encoding
);
1142 return &string_declaration
->p
;
1147 * Also add named variant, struct or enum to the current declaration scope.
1148 * FIXME: we are only taking the first one. check for root declaration specifiers list.
1151 struct declaration
*ctf_declaration_specifier_visit(FILE *fd
,
1152 int depth
, struct cds_list_head
*head
,
1153 struct declaration_scope
*declaration_scope
,
1154 struct ctf_trace
*trace
)
1156 struct ctf_node
*first
;
1158 first
= _cds_list_first_entry(head
, struct ctf_node
, siblings
);
1160 switch (first
->type
) {
1162 return ctf_declaration_struct_visit(fd
, depth
,
1163 first
->u
._struct
.name
,
1164 &first
->u
._struct
.declaration_list
,
1165 first
->u
._struct
.has_body
,
1169 return ctf_declaration_variant_visit(fd
, depth
,
1170 first
->u
.variant
.name
,
1171 first
->u
.variant
.choice
,
1172 &first
->u
.variant
.declaration_list
,
1173 first
->u
.variant
.has_body
,
1177 return ctf_declaration_enum_visit(fd
, depth
,
1178 first
->u
._enum
.enum_id
,
1179 &first
->u
._enum
.container_type
,
1180 &first
->u
._enum
.enumerator_list
,
1181 first
->u
._enum
.has_body
,
1185 return ctf_declaration_integer_visit(fd
, depth
,
1186 &first
->u
.integer
.expressions
, trace
);
1187 case NODE_FLOATING_POINT
:
1188 return ctf_declaration_floating_point_visit(fd
, depth
,
1189 &first
->u
.floating_point
.expressions
, trace
);
1191 return ctf_declaration_string_visit(fd
, depth
,
1192 &first
->u
.string
.expressions
, trace
);
1193 case NODE_TYPE_SPECIFIER
:
1194 return ctf_declaration_type_specifier_visit(fd
, depth
,
1195 head
, declaration_scope
);
1197 fprintf(stderr
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->type
);
1203 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event
*event
, struct ctf_trace
*trace
)
1207 switch (node
->type
) {
1209 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1210 event
->declaration_scope
,
1211 &node
->u
._typedef
.declaration_specifier
,
1212 &node
->u
._typedef
.type_declarators
,
1217 case NODE_TYPEALIAS
:
1218 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1219 event
->declaration_scope
,
1220 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1225 case NODE_CTF_EXPRESSION
:
1229 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1230 if (!strcmp(left
, "name")) {
1233 if (CTF_EVENT_FIELD_IS_SET(event
, name
))
1235 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1237 fprintf(stderr
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1240 event
->name
= g_quark_from_string(right
);
1242 CTF_EVENT_SET_FIELD(event
, name
);
1243 } else if (!strcmp(left
, "id")) {
1244 if (CTF_EVENT_FIELD_IS_SET(event
, id
))
1246 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1248 fprintf(stderr
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1251 CTF_EVENT_SET_FIELD(event
, id
);
1252 } else if (!strcmp(left
, "stream_id")) {
1253 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
1255 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1257 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1260 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1261 if (!event
->stream
) {
1262 fprintf(stderr
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1265 CTF_EVENT_SET_FIELD(event
, stream_id
);
1266 } else if (!strcmp(left
, "context")) {
1267 struct declaration
*declaration
;
1269 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
1270 &node
->u
.ctf_expression
.right
,
1271 event
->declaration_scope
, trace
);
1274 if (declaration
->id
!= CTF_TYPE_STRUCT
)
1276 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1277 } else if (!strcmp(left
, "fields")) {
1278 struct declaration
*declaration
;
1280 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
1281 &node
->u
.ctf_expression
.right
,
1282 event
->declaration_scope
, trace
);
1285 if (declaration
->id
!= CTF_TYPE_STRUCT
)
1287 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1294 /* TODO: declaration specifier should be added. */
1301 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1302 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1305 struct ctf_node
*iter
;
1306 struct ctf_event
*event
;
1307 struct definition_scope
*parent_def_scope
;
1309 event
= g_new0(struct ctf_event
, 1);
1310 event
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
1311 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1312 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1316 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1320 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1324 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1328 if (event
->stream
->events_by_id
->len
<= event
->id
)
1329 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1330 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1331 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1332 (gpointer
)(unsigned long) event
->name
,
1334 parent_def_scope
= event
->stream
->definition_scope
;
1335 if (event
->context_decl
) {
1338 event
->context_decl
->p
.definition_new(&event
->context_decl
->p
,
1339 parent_def_scope
, 0, 0),
1340 struct definition_struct
, p
);
1341 set_dynamic_definition_scope(&event
->context
->p
,
1342 event
->context
->scope
,
1344 parent_def_scope
= event
->context
->scope
;
1345 declaration_unref(&event
->context_decl
->p
);
1347 if (event
->fields_decl
) {
1350 event
->fields_decl
->p
.definition_new(&event
->fields_decl
->p
,
1351 parent_def_scope
, 0, 0),
1352 struct definition_struct
, p
);
1353 set_dynamic_definition_scope(&event
->fields
->p
,
1354 event
->fields
->scope
,
1356 parent_def_scope
= event
->fields
->scope
;
1357 declaration_unref(&event
->fields_decl
->p
);
1362 declaration_unref(&event
->fields_decl
->p
);
1363 declaration_unref(&event
->context_decl
->p
);
1364 free_declaration_scope(event
->declaration_scope
);
1371 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream
*stream
, struct ctf_trace
*trace
)
1375 switch (node
->type
) {
1377 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1378 stream
->declaration_scope
,
1379 &node
->u
._typedef
.declaration_specifier
,
1380 &node
->u
._typedef
.type_declarators
,
1385 case NODE_TYPEALIAS
:
1386 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1387 stream
->declaration_scope
,
1388 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1393 case NODE_CTF_EXPRESSION
:
1397 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1398 if (!strcmp(left
, "stream_id")) {
1399 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
))
1401 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1403 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1406 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1407 } else if (!strcmp(left
, "event.header")) {
1408 struct declaration
*declaration
;
1410 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
1411 &node
->u
.ctf_expression
.right
,
1412 stream
->declaration_scope
, trace
);
1415 if (declaration
->id
!= CTF_TYPE_STRUCT
)
1417 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1418 } else if (!strcmp(left
, "event.context")) {
1419 struct declaration
*declaration
;
1421 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
1422 &node
->u
.ctf_expression
.right
,
1423 stream
->declaration_scope
, trace
);
1426 if (declaration
->id
!= CTF_TYPE_STRUCT
)
1428 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1429 } else if (!strcmp(left
, "packet.context")) {
1430 struct declaration
*declaration
;
1432 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
1433 &node
->u
.ctf_expression
.right
,
1434 stream
->declaration_scope
, trace
);
1437 if (declaration
->id
!= CTF_TYPE_STRUCT
)
1439 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1446 /* TODO: declaration specifier should be added. */
1453 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1454 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1457 struct ctf_node
*iter
;
1458 struct ctf_stream
*stream
;
1459 struct definition_scope
*parent_def_scope
;
1461 stream
= g_new0(struct ctf_stream
, 1);
1462 stream
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
1463 stream
->events_by_id
= g_ptr_array_new();
1464 stream
->event_quark_to_id
= g_hash_table_new(g_int_hash
, g_int_equal
);
1465 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
1466 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
1470 if (!CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1474 if (trace
->streams
->len
<= stream
->stream_id
)
1475 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
1476 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
1478 parent_def_scope
= NULL
;
1479 if (stream
->packet_context_decl
) {
1480 stream
->packet_context
=
1482 stream
->packet_context_decl
->p
.definition_new(&stream
->packet_context_decl
->p
,
1483 parent_def_scope
, 0, 0),
1484 struct definition_struct
, p
);
1485 set_dynamic_definition_scope(&stream
->packet_context
->p
,
1486 stream
->packet_context
->scope
,
1487 "stream.packet.context");
1488 parent_def_scope
= stream
->packet_context
->scope
;
1489 declaration_unref(&stream
->packet_context_decl
->p
);
1491 if (stream
->event_header_decl
) {
1492 stream
->event_header
=
1494 stream
->event_header_decl
->p
.definition_new(&stream
->event_header_decl
->p
,
1495 parent_def_scope
, 0, 0),
1496 struct definition_struct
, p
);
1497 set_dynamic_definition_scope(&stream
->event_header
->p
,
1498 stream
->event_header
->scope
,
1499 "stream.event.header");
1500 parent_def_scope
= stream
->event_header
->scope
;
1501 declaration_unref(&stream
->event_header_decl
->p
);
1503 if (stream
->event_context_decl
) {
1504 stream
->event_context
=
1506 stream
->event_context_decl
->p
.definition_new(&stream
->event_context_decl
->p
,
1507 parent_def_scope
, 0, 0),
1508 struct definition_struct
, p
);
1509 set_dynamic_definition_scope(&stream
->event_context
->p
,
1510 stream
->event_context
->scope
,
1511 "stream.event.context");
1512 parent_def_scope
= stream
->event_context
->scope
;
1513 declaration_unref(&stream
->event_context_decl
->p
);
1515 stream
->definition_scope
= parent_def_scope
;
1520 declaration_unref(&stream
->event_header_decl
->p
);
1521 declaration_unref(&stream
->event_context_decl
->p
);
1522 declaration_unref(&stream
->packet_context_decl
->p
);
1523 g_ptr_array_free(stream
->events_by_id
, TRUE
);
1524 g_hash_table_destroy(stream
->event_quark_to_id
);
1525 free_declaration_scope(stream
->declaration_scope
);
1531 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
1535 switch (node
->type
) {
1537 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1538 trace
->declaration_scope
,
1539 &node
->u
._typedef
.declaration_specifier
,
1540 &node
->u
._typedef
.type_declarators
,
1545 case NODE_TYPEALIAS
:
1546 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1547 trace
->declaration_scope
,
1548 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1553 case NODE_CTF_EXPRESSION
:
1557 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1558 if (!strcmp(left
, "major")) {
1559 if (CTF_TRACE_FIELD_IS_SET(trace
, major
))
1561 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
1563 fprintf(stderr
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
1566 CTF_TRACE_SET_FIELD(trace
, major
);
1567 } else if (!strcmp(left
, "minor")) {
1568 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
))
1570 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
1572 fprintf(stderr
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
1575 CTF_TRACE_SET_FIELD(trace
, minor
);
1576 } else if (!strcmp(left
, "word_size")) {
1577 if (CTF_TRACE_FIELD_IS_SET(trace
, word_size
))
1579 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->word_size
);
1581 fprintf(stderr
, "[error] %s: unexpected unary expression for trace word_size\n", __func__
);
1584 CTF_TRACE_SET_FIELD(trace
, word_size
);
1585 } else if (!strcmp(left
, "uuid")) {
1586 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
))
1588 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &trace
->uuid
);
1590 fprintf(stderr
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
1593 CTF_TRACE_SET_FIELD(trace
, uuid
);
1600 /* TODO: declaration specifier should be added. */
1607 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
1610 struct ctf_node
*iter
;
1612 if (trace
->declaration_scope
)
1614 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
1615 trace
->streams
= g_ptr_array_new();
1616 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
1617 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
1621 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
1625 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
1629 if (!CTF_TRACE_FIELD_IS_SET(trace
, uuid
)) {
1633 if (!CTF_TRACE_FIELD_IS_SET(trace
, word_size
)) {
1640 g_ptr_array_free(trace
->streams
, TRUE
);
1641 free_declaration_scope(trace
->declaration_scope
);
1645 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
1646 struct ctf_trace
*trace
, int byte_order
)
1649 struct ctf_node
*iter
;
1651 trace
->byte_order
= byte_order
;
1653 switch (node
->type
) {
1655 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
1657 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1658 trace
->root_declaration_scope
,
1659 &iter
->u
._typedef
.declaration_specifier
,
1660 &iter
->u
._typedef
.type_declarators
,
1665 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
1667 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1668 trace
->root_declaration_scope
,
1669 iter
->u
.typealias
.target
, iter
->u
.typealias
.alias
,
1674 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
1675 ret
= ctf_declaration_specifier_visit(fd
, depth
, iter
,
1676 trace
->root_declaration_scope
, trace
);
1680 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
1681 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
1685 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
1686 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
1687 trace
->root_declaration_scope
, trace
);
1691 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
1692 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
1693 trace
->root_declaration_scope
, trace
);
1700 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,