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.
27 #include <babeltrace/list.h>
28 #include <uuid/uuid.h>
29 #include "ctf-scanner.h"
30 #include "ctf-parser.h"
33 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
35 #define _cds_list_first_entry(ptr, type, member) \
36 cds_list_entry((ptr)->next, type, member)
39 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
41 print_tabs(fd
, depth
);
42 fprintf(fd
, "<type_specifier \"");
44 switch (node
->u
.type_specifier
.type
) {
64 fprintf(fd
, "double");
67 fprintf(fd
, "signed");
69 case TYPESPEC_UNSIGNED
:
70 fprintf(fd
, "unsigned");
75 case TYPESPEC_COMPLEX
:
76 fprintf(fd
, "_Complex");
78 case TYPESPEC_IMAGINARY
:
79 fprintf(fd
, "_Imaginary");
84 case TYPESPEC_ID_TYPE
:
85 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
88 case TYPESPEC_UNKNOWN
:
90 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
91 (int) node
->u
.type_specifier
.type
);
94 fprintf(fd
, "\"/>\n");
99 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
102 struct ctf_node
*iter
;
104 print_tabs(fd
, depth
);
105 fprintf(fd
, "<type_declarator>\n");
108 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
109 print_tabs(fd
, depth
);
110 fprintf(fd
, "<pointers>\n");
111 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
113 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
117 print_tabs(fd
, depth
);
118 fprintf(fd
, "</pointers>\n");
121 switch (node
->u
.type_declarator
.type
) {
123 if (node
->u
.type_declarator
.u
.id
) {
124 print_tabs(fd
, depth
);
125 fprintf(fd
, "<id \"");
126 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
127 fprintf(fd
, "\" />\n");
131 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
132 print_tabs(fd
, depth
);
133 fprintf(fd
, "<type_declarator>\n");
134 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
135 node
->u
.type_declarator
.u
.nested
.type_declarator
);
138 print_tabs(fd
, depth
);
139 fprintf(fd
, "</type_declarator>\n");
141 if (node
->u
.type_declarator
.u
.nested
.length
) {
142 print_tabs(fd
, depth
);
143 fprintf(fd
, "<length>\n");
144 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
145 node
->u
.type_declarator
.u
.nested
.length
);
148 print_tabs(fd
, depth
);
149 fprintf(fd
, "</length>\n");
151 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
152 print_tabs(fd
, depth
);
153 fprintf(fd
, "<length>\n");
154 print_tabs(fd
, depth
);
155 fprintf(fd
, "</length>\n");
157 if (node
->u
.type_declarator
.bitfield_len
) {
158 print_tabs(fd
, depth
);
159 fprintf(fd
, "<bitfield_len>\n");
160 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
161 node
->u
.type_declarator
.bitfield_len
);
164 print_tabs(fd
, depth
);
165 fprintf(fd
, "</bitfield_len>\n");
168 case TYPEDEC_UNKNOWN
:
170 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
171 (int) node
->u
.type_declarator
.type
);
176 print_tabs(fd
, depth
);
177 fprintf(fd
, "</type_declarator>\n");
182 * String returned must be freed by the caller using g_free.
185 char *concatenate_unary_strings(struct list_head
*head
)
187 struct ctf_node
*node
;
191 str
= g_string_new();
192 cds_list_for_each_entry(node
, head
, siblings
) {
195 assert(node
->type
== NODE_UNARY_EXPRESSION
);
196 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
197 assert((node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
)
199 switch (node
->u
.unary_expression
.link
) {
201 g_string_append(str
, ".")
203 case UNARY_ARROWLINK
:
204 g_string_append(str
, "->")
206 case UNARY_DOTDOTDOT
:
207 g_string_append(str
, "...")
210 src_string
= u
.unary_expression
.u
.string
;
211 g_string_append(str
, src_string
);
214 return g_string_free(str
, FALSE
);
218 int get_unary_unsigned(struct list_head
*head
, uint64_t *value
)
220 struct ctf_node
*node
;
223 cds_list_for_each_entry(node
, head
, siblings
) {
224 assert(node
->type
== NODE_UNARY_EXPRESSION
);
225 assert(node
->u
.unary_expression
.type
== UNARY_UNSIGNED_CONSTANT
);
226 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
228 *value
= node
->u
.unary_expression
.unsigned_constant
235 int get_unary_uuid(struct list_head
*head
, uuid_t
*uuid
)
237 struct ctf_node
*node
;
241 cds_list_for_each_entry(node
, head
, siblings
) {
242 const char *src_string
;
244 assert(node
->type
== NODE_UNARY_EXPRESSION
);
245 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
246 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
248 src_string
= u
.unary_expression
.u
.string
;
249 ret
= uuid_parse(u
.unary_expression
.u
.string
, *uuid
);
255 struct ctf_stream
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
257 if (trace
->streams
->len
<= stream_id
)
259 return g_ptr_array_index(trace
->streams
, stream_id
);
263 * Also add named variant, struct or enum to the current declaration scope.
266 struct ctf_declaration
*ctf_declaration_specifier_visit(FILE *fd
,
267 int depth
, struct list_head
*head
,
268 struct declaration_scope
*declaration_scope
)
270 struct ctf_declaration
*declaration
;
273 first
= _cds_list_first_entry(head
, struct node
, siblings
);
275 switch (first
->type
) {
278 * For named struct (without body), lookup in
279 * declaration scope and create declaration copy.
281 /* For named struct (with body), create type and add to declaration scope */
282 /* For unnamed struct, create type */
286 * For named variant (without body), lookup in
287 * declaration scope and create declaration copy.
289 /* For named variant (with body), create type and add to declaration scope */
290 /* For unnamed variant, create type */
291 /* If variant has a tag field specifier, assign tag name. */
295 * For named enum (without body), lookup in declaration
296 * scope and create declaration copy.
298 /* For named enum (with body), create type and add to declaration scope */
299 /* For unnamed enum, create type */
300 /* Enumerations need to have their size/type specifier (< >). */
304 * Create an integer declaration.
307 case NODE_FLOATING_POINT
:
309 * Create a floating point declaration.
314 * Create a string declaration.
317 case NODE_TYPE_SPECIFIER
:
319 * Lookup named type in typedef declarations (in
320 * declaration scope). Create a copy of the declaration.
328 int ctf_typedef_declarator_visit(FILE *fd
, int depth
,
329 struct list_head
*declaration_specifier
,
330 struct node
*type_declarator
,
331 struct declaration_scope
*declaration_scope
)
334 * Build the type using declaration specifier (creating
335 * declaration from type_specifier), then apply type declarator,
336 * add the resulting type to the current declaration scope.
338 cds_list_for_each_entry(iter
, declaration_specifier
, siblings
) {
346 int ctf_typedef_visit(FILE *fd
, int depth
,
347 struct list_head
*declaration_specifier
,
348 struct list_head
*type_declarators
,
349 struct declaration_scope
*declaration_scope
)
351 struct ctf_node
*iter
;
353 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
354 ret
= ctf_typedef_declarator_visit(fd
, depth
+ 1,
355 &node
->u
._typedef
.declaration_specifier
, iter
,
364 int ctf_typealias_visit(FILE *fd
, int depth
, struct ctf_node
*target
,
365 struct ctf_node
*alias
,
366 struct declaration_scope
*declaration_scope
)
369 * Build target type, check that it is reachable in current
373 /* Only one type declarator is allowed */
375 /* Build alias type, add to current declaration scope. */
376 /* Only one type declarator is allowed */
380 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event
*event
, struct ctf_trace
*trace
)
384 switch (node
->type
) {
386 ret
= ctf_typedef_visit(fd
, depth
+ 1,
387 &node
->u
._typedef
.declaration_specifier
,
388 &node
->u
._typedef
.type_declarators
,
389 event
->declaration_scope
);
394 ret
= ctf_typealias_visit(fd
, depth
+ 1,
395 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
396 event
->declaration_scope
);
400 case NODE_CTF_EXPRESSION
:
404 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
405 if (!strcmp(left
, "name")) {
408 if (CTF_EVENT_FIELD_IS_SET(event
, name
))
410 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
412 fprintf(stderr
, "[error] %s: unexpected unary expression for event name\n", __func__
);
415 event
->name
= g_quark_from_string(right
);
417 CTF_EVENT_SET_FIELD(event
, name
);
418 } else if (!strcmp(left
, "id")) {
419 if (CTF_EVENT_FIELD_IS_SET(event
, id
))
421 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
423 fprintf(stderr
, "[error] %s: unexpected unary expression for event id\n", __func__
);
426 CTF_EVENT_SET_FIELD(event
, id
);
427 } else if (!strcmp(left
, "stream_id")) {
428 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
430 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
432 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
435 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
436 if (!event
->stream
) {
437 fprintf(stderr
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
440 CTF_EVENT_SET_FIELD(event
, stream_id
);
441 } else if (!strcmp(left
, "context")) {
442 struct declaration
*declaration
;
444 if (!event
->definition_scope
)
446 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
447 &node
->u
.ctf_expression
.right
,
448 event
->declaration_scope
);
451 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
453 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
454 } else if (!strcmp(left
, "fields")) {
455 struct declaration
*declaration
;
457 if (!event
->definition_scope
)
459 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
460 &node
->u
.ctf_expression
.right
,
461 event
->declaration_scope
);
464 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
466 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
473 /* TODO: declaration specifier should be added. */
480 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
481 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
484 struct ctf_node
*iter
;
485 struct ctf_event
*event
;
486 struct definition_scope
*parent_def_scope
;
488 event
= g_new0(struct ctf_event
, 1);
489 event
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
490 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
491 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
495 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
499 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)) {
503 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
507 if (event
->stream
->events_by_id
->len
<= event
->id
)
508 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
509 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
510 g_hash_table_insert(event
->stream
->event_quark_to_id
,
511 (gpointer
)(unsigned long) event
->name
,
513 parent_def_scope
= stream
->definition_scope
;
514 if (event
->context_decl
) {
516 event
->context_decl
->definition_new(event
->context_decl
,
517 parent_def_scope
, 0, 0);
518 set_dynamic_definition_scope(&event
->context
->p
,
519 event
->context
->scope
,
521 parent_def_scope
= event
->context
->scope
;
522 declaration_unref(event
->context_decl
);
524 if (event
->fields_decl
) {
526 event
->fields_decl
->definition_new(event
->fields_decl
,
527 parent_def_scope
, 0, 0);
528 set_dynamic_definition_scope(&event
->fields
->p
,
529 event
->fields
->scope
,
531 parent_def_scope
= event
->fields
->scope
;
532 declaration_unref(event
->fields_decl
);
537 declaration_unref(event
->fields_decl
);
538 declaration_unref(event
->context_decl
);
539 free_definition_scope(event
->definition_scope
);
540 free_declaration_scope(event
->declaration_scope
);
547 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream
*stream
, struct ctf_trace
*trace
)
551 switch (node
->type
) {
553 ret
= ctf_typedef_visit(fd
, depth
+ 1,
554 &node
->u
._typedef
.declaration_specifier
,
555 &node
->u
._typedef
.type_declarators
,
556 stream
->declaration_scope
);
561 ret
= ctf_typealias_visit(fd
, depth
+ 1,
562 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
563 stream
->declaration_scope
);
567 case NODE_CTF_EXPRESSION
:
571 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
572 if (!strcmp(left
, "stream_id")) {
573 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
575 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
577 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
580 CTF_EVENT_SET_FIELD(event
, stream_id
);
581 } else if (!strcmp(left
, "event.header")) {
582 struct declaration
*declaration
;
584 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
585 &node
->u
.ctf_expression
.right
,
586 stream
->declaration_scope
, stream
->definition_scope
);
589 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
591 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
592 } else if (!strcmp(left
, "event.context")) {
593 struct declaration
*declaration
;
595 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
596 &node
->u
.ctf_expression
.right
,
597 stream
->declaration_scope
);
600 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
602 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
603 } else if (!strcmp(left
, "packet.context")) {
604 struct declaration
*declaration
;
606 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
607 &node
->u
.ctf_expression
.right
,
608 stream
->declaration_scope
);
611 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
613 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
620 /* TODO: declaration specifier should be added. */
627 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
628 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
631 struct ctf_node
*iter
;
632 struct ctf_stream
*stream
;
633 struct definition_scope
*parent_def_scope
;
635 stream
= g_new0(struct ctf_stream
, 1);
636 stream
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
637 stream
->events_by_id
= g_ptr_array_new();
638 stream
->event_quark_to_id
= g_hash_table_new(g_int_hash
, g_int_equal
);
639 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
640 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
644 if (!CTF_EVENT_FIELD_IS_SET(stream
, stream_id
)) {
648 if (trace
->streams
->len
<= stream
->stream_id
)
649 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
650 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
652 parent_def_scope
= NULL
;
653 if (stream
->packet_context_decl
) {
654 stream
->packet_context
=
655 stream
->packet_context_decl
->definition_new(stream
->packet_context_decl
,
656 parent_def_scope
, 0, 0);
657 set_dynamic_definition_scope(&stream
->packet_context
->p
,
658 stream
->packet_context
->scope
,
659 "stream.packet.context");
660 parent_def_scope
= stream
->packet_context
->scope
;
661 declaration_unref(stream
->packet_context_decl
);
663 if (stream
->event_header_decl
) {
664 stream
->event_header
=
665 stream
->event_header_decl
->definition_new(stream
->event_header_decl
,
666 parent_def_scope
, 0, 0);
667 set_dynamic_definition_scope(&stream
->event_header
->p
,
668 stream
->event_header
->scope
,
669 "stream.event.header");
670 parent_def_scope
= stream
->event_header
->scope
;
671 declaration_unref(stream
->event_header_decl
);
673 if (stream
->event_context_decl
) {
674 stream
->event_context
=
675 stream
->event_context_decl
->definition_new(stream
->event_context_decl
,
676 parent_def_scope
, 0, 0);
677 set_dynamic_definition_scope(&stream
->event_context
->p
,
678 stream
->event_context
->scope
,
679 "stream.event.context");
680 parent_def_scope
= stream
->event_context
->scope
;
681 declaration_unref(stream
->event_context_decl
);
683 stream
->definition_scope
= parent_def_scope
;
688 declaration_unref(stream
->event_header
);
689 declaration_unref(stream
->event_context
);
690 declaration_unref(stream
->packet_context
);
691 g_ptr_array_free(stream
->events_by_id
, TRUE
);
692 g_hash_table_free(stream
->event_quark_to_id
);
693 free_definition_scope(stream
->definition_scope
);
694 free_declaration_scope(stream
->declaration_scope
);
700 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
704 switch (node
->type
) {
706 ret
= ctf_typedef_visit(fd
, depth
+ 1,
707 &node
->u
._typedef
.declaration_specifier
,
708 &node
->u
._typedef
.type_declarators
,
709 trace
->declaration_scope
);
714 ret
= ctf_typealias_visit(fd
, depth
+ 1,
715 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
716 trace
->declaration_scope
);
720 case NODE_CTF_EXPRESSION
:
724 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
725 if (!strcmp(left
, "major")) {
726 if (CTF_EVENT_FIELD_IS_SET(trace
, major
))
728 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
730 fprintf(stderr
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
733 CTF_EVENT_SET_FIELD(trace
, major
);
734 } else if (!strcmp(left
, "minor")) {
735 if (CTF_EVENT_FIELD_IS_SET(trace
, minor
))
737 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
739 fprintf(stderr
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
742 CTF_EVENT_SET_FIELD(trace
, minor
);
743 } else if (!strcmp(left
, "word_size")) {
744 if (CTF_EVENT_FIELD_IS_SET(trace
, word_size
))
746 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->word_size
);
748 fprintf(stderr
, "[error] %s: unexpected unary expression for trace word_size\n", __func__
);
751 CTF_EVENT_SET_FIELD(trace
, word_size
);
752 } else if (!strcmp(left
, "uuid")) {
753 if (CTF_EVENT_FIELD_IS_SET(trace
, uuid
))
755 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &trace
->uuid
);
757 fprintf(stderr
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
760 CTF_EVENT_SET_FIELD(trace
, uuid
);
767 /* TODO: declaration specifier should be added. */
775 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
778 struct ctf_node
*iter
;
780 if (trace
->declaration_scope
)
782 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
783 trace
->definition_scope
= new_dynamic_definition_scope(trace
->root_definition_scope
);
784 trace
->streams
= g_ptr_array_new();
785 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
786 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
790 if (!CTF_EVENT_FIELD_IS_SET(trace
, major
)) {
794 if (!CTF_EVENT_FIELD_IS_SET(trace
, minor
)) {
798 if (!CTF_EVENT_FIELD_IS_SET(trace
, uuid
)) {
802 if (!CTF_EVENT_FIELD_IS_SET(trace
, word_size
)) {
809 g_ptr_array_free(trace
->streams
, TRUE
);
810 free_definition_scope(stream
->definition_scope
);
811 free_declaration_scope(stream
->declaration_scope
);
815 int _ctf_visitor(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
818 struct ctf_node
*iter
;
820 switch (node
->type
) {
822 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
824 ret
= ctf_typedef_visit(fd
, depth
+ 1,
825 &iter
->u
._typedef
.declaration_specifier
,
826 &iter
->u
._typedef
.type_declarators
,
827 trace
->root_declaration_scope
);
831 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
833 ret
= ctf_typealias_visit(fd
, depth
+ 1,
834 &iter
->u
.typealias
.target
, &iter
->u
.typealias
.alias
835 trace
->root_declaration_scope
);
839 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
840 ret
= ctf_declaration_specifier_visit(fd
, depth
, iter
,
841 trace
->root_declaration_scope
);
845 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
846 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
850 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
851 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
852 trace
->root_declaration_scope
, trace
);
856 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
857 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
858 trace
->root_declaration_scope
, trace
);
864 case NODE_TYPEALIAS_TARGET
:
865 print_tabs(fd
, depth
);
866 fprintf(fd
, "<target>\n");
869 print_tabs(fd
, depth
);
870 fprintf(fd
, "<declaration_specifier>\n");
871 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
872 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
876 print_tabs(fd
, depth
);
877 fprintf(fd
, "</declaration_specifier>\n");
879 print_tabs(fd
, depth
);
880 fprintf(fd
, "<type_declarators>\n");
881 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
882 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
886 print_tabs(fd
, depth
);
887 fprintf(fd
, "</type_declarators>\n");
890 print_tabs(fd
, depth
);
891 fprintf(fd
, "</target>\n");
893 case NODE_TYPEALIAS_ALIAS
:
894 print_tabs(fd
, depth
);
895 fprintf(fd
, "<alias>\n");
898 print_tabs(fd
, depth
);
899 fprintf(fd
, "<declaration_specifier>\n");
900 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
901 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
905 print_tabs(fd
, depth
);
906 fprintf(fd
, "</declaration_specifier>\n");
908 print_tabs(fd
, depth
);
909 fprintf(fd
, "<type_declarators>\n");
910 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
911 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
915 print_tabs(fd
, depth
);
916 fprintf(fd
, "</type_declarators>\n");
919 print_tabs(fd
, depth
);
920 fprintf(fd
, "</alias>\n");
923 print_tabs(fd
, depth
);
924 fprintf(fd
, "<typealias>\n");
925 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
928 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
931 print_tabs(fd
, depth
);
932 fprintf(fd
, "</typealias>\n");
935 case NODE_TYPE_SPECIFIER
:
936 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
941 print_tabs(fd
, depth
);
942 if (node
->u
.pointer
.const_qualifier
)
943 fprintf(fd
, "<const_pointer />\n");
945 fprintf(fd
, "<pointer />\n");
947 case NODE_TYPE_DECLARATOR
:
948 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
953 case NODE_FLOATING_POINT
:
954 print_tabs(fd
, depth
);
955 fprintf(fd
, "<floating_point>\n");
956 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
957 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
961 print_tabs(fd
, depth
);
962 fprintf(fd
, "</floating_point>\n");
965 print_tabs(fd
, depth
);
966 fprintf(fd
, "<integer>\n");
967 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
968 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
972 print_tabs(fd
, depth
);
973 fprintf(fd
, "</integer>\n");
976 print_tabs(fd
, depth
);
977 fprintf(fd
, "<string>\n");
978 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
979 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
983 print_tabs(fd
, depth
);
984 fprintf(fd
, "</string>\n");
986 case NODE_ENUMERATOR
:
987 print_tabs(fd
, depth
);
988 fprintf(fd
, "<enumerator");
989 if (node
->u
.enumerator
.id
)
990 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
992 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
993 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
997 print_tabs(fd
, depth
);
998 fprintf(fd
, "</enumerator>\n");
1001 print_tabs(fd
, depth
);
1002 if (node
->u
._struct
.name
)
1003 fprintf(fd
, "<enum name=\"%s\">\n",
1004 node
->u
._enum
.enum_id
);
1006 fprintf(fd
, "<enum >\n");
1009 if (node
->u
._enum
.container_type
) {
1010 print_tabs(fd
, depth
);
1011 fprintf(fd
, "<container_type>\n");
1012 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
1015 print_tabs(fd
, depth
);
1016 fprintf(fd
, "</container_type>\n");
1019 print_tabs(fd
, depth
);
1020 fprintf(fd
, "<enumerator_list>\n");
1021 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
1022 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1026 print_tabs(fd
, depth
);
1027 fprintf(fd
, "</enumerator_list>\n");
1030 print_tabs(fd
, depth
);
1031 fprintf(fd
, "</enum>\n");
1033 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
1034 print_tabs(fd
, depth
);
1035 fprintf(fd
, "<declaration_specifier>\n");
1036 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
1037 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1041 print_tabs(fd
, depth
);
1042 fprintf(fd
, "</declaration_specifier>\n");
1044 print_tabs(fd
, depth
);
1045 fprintf(fd
, "<type_declarators>\n");
1046 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
1047 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1051 print_tabs(fd
, depth
);
1052 fprintf(fd
, "</type_declarators>\n");
1055 print_tabs(fd
, depth
);
1056 fprintf(fd
, "<variant");
1057 if (node
->u
.variant
.name
)
1058 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
1059 if (node
->u
.variant
.choice
)
1060 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
1062 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
1063 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1067 print_tabs(fd
, depth
);
1068 fprintf(fd
, "</variant>\n");
1071 print_tabs(fd
, depth
);
1072 if (node
->u
._struct
.name
)
1073 fprintf(fd
, "<struct name=\"%s\">\n",
1074 node
->u
._struct
.name
);
1076 fprintf(fd
, "<struct>\n");
1077 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
1078 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1082 print_tabs(fd
, depth
);
1083 fprintf(fd
, "</struct>\n");
1088 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,