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
->scope
,
519 g_quark_from_string("event.context"));
520 parent_def_scope
= event
->context
->scope
;
521 declaration_unref(event
->context_decl
);
523 if (event
->fields_decl
) {
525 event
->fields_decl
->definition_new(event
->fields_decl
,
526 parent_def_scope
, 0, 0);
527 set_dynamic_definition_scope(event
->fields
->scope
,
528 g_quark_from_string("event.fields"));
529 parent_def_scope
= event
->fields
->scope
;
530 declaration_unref(event
->fields_decl
);
535 declaration_unref(event
->fields_decl
);
536 declaration_unref(event
->context_decl
);
537 free_definition_scope(event
->definition_scope
);
538 free_declaration_scope(event
->declaration_scope
);
545 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream
*stream
, struct ctf_trace
*trace
)
549 switch (node
->type
) {
551 ret
= ctf_typedef_visit(fd
, depth
+ 1,
552 &node
->u
._typedef
.declaration_specifier
,
553 &node
->u
._typedef
.type_declarators
,
554 stream
->declaration_scope
);
559 ret
= ctf_typealias_visit(fd
, depth
+ 1,
560 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
561 stream
->declaration_scope
);
565 case NODE_CTF_EXPRESSION
:
569 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
570 if (!strcmp(left
, "stream_id")) {
571 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
573 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
575 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
578 CTF_EVENT_SET_FIELD(event
, stream_id
);
579 } else if (!strcmp(left
, "event.header")) {
580 struct declaration
*declaration
;
582 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
583 &node
->u
.ctf_expression
.right
,
584 stream
->declaration_scope
, stream
->definition_scope
);
587 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
589 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
590 } else if (!strcmp(left
, "event.context")) {
591 struct declaration
*declaration
;
593 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
594 &node
->u
.ctf_expression
.right
,
595 stream
->declaration_scope
);
598 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
600 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
601 } else if (!strcmp(left
, "packet.context")) {
602 struct declaration
*declaration
;
604 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
605 &node
->u
.ctf_expression
.right
,
606 stream
->declaration_scope
);
609 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
611 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
618 /* TODO: declaration specifier should be added. */
625 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
626 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
629 struct ctf_node
*iter
;
630 struct ctf_stream
*stream
;
631 struct definition_scope
*parent_def_scope
;
633 stream
= g_new0(struct ctf_stream
, 1);
634 stream
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
635 stream
->events_by_id
= g_ptr_array_new();
636 stream
->event_quark_to_id
= g_hash_table_new(g_int_hash
, g_int_equal
);
637 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
638 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
642 if (!CTF_EVENT_FIELD_IS_SET(stream
, stream_id
)) {
646 if (trace
->streams
->len
<= stream
->stream_id
)
647 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
648 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
650 parent_def_scope
= NULL
;
651 if (stream
->packet_context_decl
) {
652 stream
->packet_context
=
653 stream
->packet_context_decl
->definition_new(stream
->packet_context_decl
,
654 parent_def_scope
, 0, 0);
655 set_dynamic_definition_scope(stream
->packet_context
->scope
,
656 g_quark_from_string("stream.packet.context"));
657 parent_def_scope
= stream
->packet_context
->scope
;
658 declaration_unref(stream
->packet_context_decl
);
660 if (stream
->event_header_decl
) {
661 stream
->event_header
=
662 stream
->event_header_decl
->definition_new(stream
->event_header_decl
,
663 parent_def_scope
, 0, 0);
664 set_dynamic_definition_scope(stream
->event_header
->scope
,
665 g_quark_from_string("stream.event.header"));
666 parent_def_scope
= stream
->event_header
->scope
;
667 declaration_unref(stream
->event_header_decl
);
669 if (stream
->event_context_decl
) {
670 stream
->event_context
=
671 stream
->event_context_decl
->definition_new(stream
->event_context_decl
,
672 parent_def_scope
, 0, 0);
673 set_dynamic_definition_scope(stream
->event_context_scope
,
674 g_quark_from_string("stream.event.context"));
675 parent_def_scope
= stream
->event_context
->scope
;
676 declaration_unref(stream
->event_context_decl
);
678 stream
->definition_scope
= parent_def_scope
;
683 declaration_unref(stream
->event_header
);
684 declaration_unref(stream
->event_context
);
685 declaration_unref(stream
->packet_context
);
686 g_ptr_array_free(stream
->events_by_id
, TRUE
);
687 g_hash_table_free(stream
->event_quark_to_id
);
688 free_definition_scope(stream
->definition_scope
);
689 free_declaration_scope(stream
->declaration_scope
);
695 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
699 switch (node
->type
) {
701 ret
= ctf_typedef_visit(fd
, depth
+ 1,
702 &node
->u
._typedef
.declaration_specifier
,
703 &node
->u
._typedef
.type_declarators
,
704 trace
->declaration_scope
);
709 ret
= ctf_typealias_visit(fd
, depth
+ 1,
710 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
711 trace
->declaration_scope
);
715 case NODE_CTF_EXPRESSION
:
719 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
720 if (!strcmp(left
, "major")) {
721 if (CTF_EVENT_FIELD_IS_SET(trace
, major
))
723 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
725 fprintf(stderr
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
728 CTF_EVENT_SET_FIELD(trace
, major
);
729 } else if (!strcmp(left
, "minor")) {
730 if (CTF_EVENT_FIELD_IS_SET(trace
, minor
))
732 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
734 fprintf(stderr
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
737 CTF_EVENT_SET_FIELD(trace
, minor
);
738 } else if (!strcmp(left
, "word_size")) {
739 if (CTF_EVENT_FIELD_IS_SET(trace
, word_size
))
741 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->word_size
);
743 fprintf(stderr
, "[error] %s: unexpected unary expression for trace word_size\n", __func__
);
746 CTF_EVENT_SET_FIELD(trace
, word_size
);
747 } else if (!strcmp(left
, "uuid")) {
748 if (CTF_EVENT_FIELD_IS_SET(trace
, uuid
))
750 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &trace
->uuid
);
752 fprintf(stderr
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
755 CTF_EVENT_SET_FIELD(trace
, uuid
);
762 /* TODO: declaration specifier should be added. */
770 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
773 struct ctf_node
*iter
;
775 if (trace
->declaration_scope
)
777 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
778 trace
->definition_scope
= new_dynamic_definition_scope(trace
->root_definition_scope
);
779 trace
->streams
= g_ptr_array_new();
780 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
781 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
785 if (!CTF_EVENT_FIELD_IS_SET(trace
, major
)) {
789 if (!CTF_EVENT_FIELD_IS_SET(trace
, minor
)) {
793 if (!CTF_EVENT_FIELD_IS_SET(trace
, uuid
)) {
797 if (!CTF_EVENT_FIELD_IS_SET(trace
, word_size
)) {
804 g_ptr_array_free(trace
->streams
, TRUE
);
805 free_definition_scope(stream
->definition_scope
);
806 free_declaration_scope(stream
->declaration_scope
);
810 int _ctf_visitor(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
813 struct ctf_node
*iter
;
815 switch (node
->type
) {
817 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
819 ret
= ctf_typedef_visit(fd
, depth
+ 1,
820 &iter
->u
._typedef
.declaration_specifier
,
821 &iter
->u
._typedef
.type_declarators
,
822 trace
->declaration_scope
);
826 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
828 ret
= ctf_typealias_visit(fd
, depth
+ 1,
829 &iter
->u
.typealias
.target
, &iter
->u
.typealias
.alias
830 trace
->declaration_scope
);
834 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
835 ret
= ctf_declaration_specifier_visit(fd
, depth
, iter
,
836 trace
->root_declaration_scope
);
840 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
841 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
845 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
846 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
847 trace
->root_declaration_scope
, trace
);
851 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
852 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
853 trace
->root_declaration_scope
, trace
);
859 case NODE_TYPEALIAS_TARGET
:
860 print_tabs(fd
, depth
);
861 fprintf(fd
, "<target>\n");
864 print_tabs(fd
, depth
);
865 fprintf(fd
, "<declaration_specifier>\n");
866 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
867 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
871 print_tabs(fd
, depth
);
872 fprintf(fd
, "</declaration_specifier>\n");
874 print_tabs(fd
, depth
);
875 fprintf(fd
, "<type_declarators>\n");
876 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
877 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
881 print_tabs(fd
, depth
);
882 fprintf(fd
, "</type_declarators>\n");
885 print_tabs(fd
, depth
);
886 fprintf(fd
, "</target>\n");
888 case NODE_TYPEALIAS_ALIAS
:
889 print_tabs(fd
, depth
);
890 fprintf(fd
, "<alias>\n");
893 print_tabs(fd
, depth
);
894 fprintf(fd
, "<declaration_specifier>\n");
895 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
896 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
900 print_tabs(fd
, depth
);
901 fprintf(fd
, "</declaration_specifier>\n");
903 print_tabs(fd
, depth
);
904 fprintf(fd
, "<type_declarators>\n");
905 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
906 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
910 print_tabs(fd
, depth
);
911 fprintf(fd
, "</type_declarators>\n");
914 print_tabs(fd
, depth
);
915 fprintf(fd
, "</alias>\n");
918 print_tabs(fd
, depth
);
919 fprintf(fd
, "<typealias>\n");
920 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
923 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
926 print_tabs(fd
, depth
);
927 fprintf(fd
, "</typealias>\n");
930 case NODE_TYPE_SPECIFIER
:
931 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
936 print_tabs(fd
, depth
);
937 if (node
->u
.pointer
.const_qualifier
)
938 fprintf(fd
, "<const_pointer />\n");
940 fprintf(fd
, "<pointer />\n");
942 case NODE_TYPE_DECLARATOR
:
943 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
948 case NODE_FLOATING_POINT
:
949 print_tabs(fd
, depth
);
950 fprintf(fd
, "<floating_point>\n");
951 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
952 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
956 print_tabs(fd
, depth
);
957 fprintf(fd
, "</floating_point>\n");
960 print_tabs(fd
, depth
);
961 fprintf(fd
, "<integer>\n");
962 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
963 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
967 print_tabs(fd
, depth
);
968 fprintf(fd
, "</integer>\n");
971 print_tabs(fd
, depth
);
972 fprintf(fd
, "<string>\n");
973 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
974 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
978 print_tabs(fd
, depth
);
979 fprintf(fd
, "</string>\n");
981 case NODE_ENUMERATOR
:
982 print_tabs(fd
, depth
);
983 fprintf(fd
, "<enumerator");
984 if (node
->u
.enumerator
.id
)
985 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
987 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
988 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
992 print_tabs(fd
, depth
);
993 fprintf(fd
, "</enumerator>\n");
996 print_tabs(fd
, depth
);
997 if (node
->u
._struct
.name
)
998 fprintf(fd
, "<enum name=\"%s\">\n",
999 node
->u
._enum
.enum_id
);
1001 fprintf(fd
, "<enum >\n");
1004 if (node
->u
._enum
.container_type
) {
1005 print_tabs(fd
, depth
);
1006 fprintf(fd
, "<container_type>\n");
1007 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
1010 print_tabs(fd
, depth
);
1011 fprintf(fd
, "</container_type>\n");
1014 print_tabs(fd
, depth
);
1015 fprintf(fd
, "<enumerator_list>\n");
1016 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
1017 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1021 print_tabs(fd
, depth
);
1022 fprintf(fd
, "</enumerator_list>\n");
1025 print_tabs(fd
, depth
);
1026 fprintf(fd
, "</enum>\n");
1028 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
1029 print_tabs(fd
, depth
);
1030 fprintf(fd
, "<declaration_specifier>\n");
1031 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
1032 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1036 print_tabs(fd
, depth
);
1037 fprintf(fd
, "</declaration_specifier>\n");
1039 print_tabs(fd
, depth
);
1040 fprintf(fd
, "<type_declarators>\n");
1041 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
1042 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1046 print_tabs(fd
, depth
);
1047 fprintf(fd
, "</type_declarators>\n");
1050 print_tabs(fd
, depth
);
1051 fprintf(fd
, "<variant");
1052 if (node
->u
.variant
.name
)
1053 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
1054 if (node
->u
.variant
.choice
)
1055 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
1057 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
1058 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1062 print_tabs(fd
, depth
);
1063 fprintf(fd
, "</variant>\n");
1066 print_tabs(fd
, depth
);
1067 if (node
->u
._struct
.name
)
1068 fprintf(fd
, "<struct name=\"%s\">\n",
1069 node
->u
._struct
.name
);
1071 fprintf(fd
, "<struct>\n");
1072 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
1073 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
1077 print_tabs(fd
, depth
);
1078 fprintf(fd
, "</struct>\n");
1083 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,