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 "ctf-scanner.h"
29 #include "ctf-parser.h"
32 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
36 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
38 print_tabs(fd
, depth
);
39 fprintf(fd
, "<type_specifier \"");
41 switch (node
->u
.type_specifier
.type
) {
61 fprintf(fd
, "double");
64 fprintf(fd
, "signed");
66 case TYPESPEC_UNSIGNED
:
67 fprintf(fd
, "unsigned");
72 case TYPESPEC_COMPLEX
:
73 fprintf(fd
, "complex");
78 case TYPESPEC_ID_TYPE
:
79 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
82 case TYPESPEC_UNKNOWN
:
84 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
85 (int) node
->u
.type_specifier
.type
);
88 fprintf(fd
, "\"/>\n");
93 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
96 struct ctf_node
*iter
;
98 print_tabs(fd
, depth
);
99 fprintf(fd
, "<type_declarator>\n");
102 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
103 print_tabs(fd
, depth
);
104 fprintf(fd
, "<pointers>\n");
105 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
107 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
111 print_tabs(fd
, depth
);
112 fprintf(fd
, "</pointers>\n");
115 switch (node
->u
.type_declarator
.type
) {
117 if (node
->u
.type_declarator
.u
.id
) {
118 print_tabs(fd
, depth
);
119 fprintf(fd
, "<id \"");
120 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
121 fprintf(fd
, "\" />\n");
125 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
126 print_tabs(fd
, depth
);
127 fprintf(fd
, "<type_declarator>\n");
128 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
129 node
->u
.type_declarator
.u
.nested
.type_declarator
);
132 print_tabs(fd
, depth
);
133 fprintf(fd
, "</type_declarator>\n");
135 if (node
->u
.type_declarator
.u
.nested
.length
) {
136 print_tabs(fd
, depth
);
137 fprintf(fd
, "<length>\n");
138 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
139 node
->u
.type_declarator
.u
.nested
.length
);
142 print_tabs(fd
, depth
);
143 fprintf(fd
, "</length>\n");
145 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
146 print_tabs(fd
, depth
);
147 fprintf(fd
, "<length>\n");
148 print_tabs(fd
, depth
);
149 fprintf(fd
, "</length>\n");
151 if (node
->u
.type_declarator
.bitfield_len
) {
152 print_tabs(fd
, depth
);
153 fprintf(fd
, "<bitfield_len>\n");
154 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
155 node
->u
.type_declarator
.bitfield_len
);
158 print_tabs(fd
, depth
);
159 fprintf(fd
, "</bitfield_len>\n");
162 case TYPEDEC_UNKNOWN
:
164 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
165 (int) node
->u
.type_declarator
.type
);
170 print_tabs(fd
, depth
);
171 fprintf(fd
, "</type_declarator>\n");
176 * String returned must be freed by the caller.
179 char *concatenate_unary_strings(struct list_head
*head
)
185 int get_unary_unsigned(struct list_head
*head
, uint64_t *value
)
191 int get_unary_uuid(struct list_head
*head
, uuid_t
*uuid
)
197 struct ctf_stream
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
199 if (trace
->streams
->len
<= stream_id
)
201 return g_ptr_array_index(trace
->streams
, stream_id
);
205 struct ctf_declaration
*ctf_declaration_specifier_visit(FILE *fd
,
206 int depth
, struct list_head
*head
,
207 struct type_scope
*type_scope
,
208 struct declaration_scope
*declaration_scope
)
214 * Use declaration specifier visitor, and add resulting variant, struct
215 * or enum to the current type scope.
218 int ctf_type_specifier_visit(FILE *fd
,
219 int depth
, struct list_head
*head
,
220 struct type_scope
*type_scope
,
221 struct declaration_scope
*declaration_scope
)
227 int ctf_typedef_declarator_visit(FILE *fd
, int depth
,
228 struct list_head
*declaration_specifier
,
229 struct node
*type_declarator
, struct type_scope
*type_scope
,
230 struct declaration_scope
*declaration_scope
)
233 * Build the type using declaration specifier, then apply type
234 * declarator, add the resulting type to the current type scope.
236 cds_list_for_each_entry(iter
, declaration_specifier
, siblings
) {
244 int ctf_typedef_visit(FILE *fd
, int depth
,
245 struct list_head
*declaration_specifier
,
246 struct list_head
*type_declarators
,
247 struct type_scope
*type_scope
,
248 struct declaration_scope
*declaration_scope
)
250 struct ctf_node
*iter
;
252 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
253 ret
= ctf_typedef_declarator_visit(fd
, depth
+ 1,
254 &node
->u
._typedef
.declaration_specifier
, iter
,
255 type_scope
, declaration_scope
);
263 int ctf_typealias_visit(FILE *fd
, int depth
, struct ctf_node
*target
,
264 struct ctf_node
*alias
, struct type_scope
*type_scope
,
265 struct declaration_scope
*declaration_scope
)
267 /* Build target type, check that it is reachable in current type scope. */
268 /* Only one type declarator is allowed */
270 /* Build alias type, add to current type scope. */
271 /* Only one type declarator is allowed */
275 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event
*event
, struct ctf_trace
*trace
)
279 switch (node
->type
) {
281 ret
= ctf_typedef_visit(fd
, depth
+ 1,
282 &node
->u
._typedef
.declaration_specifier
,
283 &node
->u
._typedef
.type_declarators
,
284 event
->type_scope
, event
->declaration_scope
);
289 ret
= ctf_typealias_visit(fd
, depth
+ 1,
290 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
291 event
->type_scope
, event
->declaration_scope
);
295 case NODE_CTF_EXPRESSION
:
299 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
300 if (!strcmp(left
, "name")) {
303 if (CTF_EVENT_FIELD_IS_SET(event
, name
))
305 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
307 fprintf(stderr
, "[error] %s: unexpected unary expression for event name\n", __func__
);
310 event
->name
= g_quark_from_string(right
);
312 CTF_EVENT_SET_FIELD(event
, name
);
313 } else if (!strcmp(left
, "id")) {
314 if (CTF_EVENT_FIELD_IS_SET(event
, id
))
316 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
318 fprintf(stderr
, "[error] %s: unexpected unary expression for event id\n", __func__
);
321 CTF_EVENT_SET_FIELD(event
, id
);
322 } else if (!strcmp(left
, "stream_id")) {
323 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
325 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
327 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
330 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
331 if (!event
->stream
) {
332 fprintf(stderr
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
335 event
->declaration_scope
= new_declaration_scope(stream
->declaration_scope
);
336 if (!event
->declaration_scope
) {
337 fprintf(stderr
, "[error] %s: Error allocating declaration scope\n", __func__
);
340 CTF_EVENT_SET_FIELD(event
, stream_id
);
341 } else if (!strcmp(left
, "context")) {
342 struct declaration
*declaration
;
344 if (!event
->declaration_scope
)
346 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
347 &node
->u
.ctf_expression
.right
,
348 event
->type_scope
, event
->declaration_scope
);
351 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
353 event
->context
= container_of(declaration
, struct declaration_struct
, p
);
354 } else if (!strcmp(left
, "fields")) {
355 struct declaration
*declaration
;
357 if (!event
->declaration_scope
)
359 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
360 &node
->u
.ctf_expression
.right
,
361 event
->type_scope
, event
->declaration_scope
);
364 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
366 event
->fields
= container_of(declaration
, struct declaration_struct
, p
);
373 /* TODO: declaration specifier should be added. */
380 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
381 struct type_scope
*parent_type_scope
, struct ctf_trace
*trace
)
384 struct ctf_node
*iter
;
385 struct ctf_event
*event
;
387 event
= g_new0(struct ctf_event
, 1);
388 event
->type_scope
= new_type_scope(parent_type_scope
);
389 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
390 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
394 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
398 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)) {
402 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
406 if (event
->stream
->events_by_id
->len
<= event
->id
)
407 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
408 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
409 g_hash_table_insert(event
->stream
->event_quark_to_id
,
410 (gpointer
)(unsigned long) event
->name
,
415 declaration_unref(event
->fields
);
416 declaration_unref(event
->context
);
417 free_declaration_scope(event
->declaration_scope
);
418 free_type_scope(event
->type_scope
);
425 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream
*stream
, struct ctf_trace
*trace
)
429 switch (node
->type
) {
431 ret
= ctf_typedef_visit(fd
, depth
+ 1,
432 &node
->u
._typedef
.declaration_specifier
,
433 &node
->u
._typedef
.type_declarators
,
434 stream
->type_scope
, stream
->declaration_scope
);
439 ret
= ctf_typealias_visit(fd
, depth
+ 1,
440 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
441 stream
->type_scope
, stream
->declaration_scope
);
445 case NODE_CTF_EXPRESSION
:
449 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
450 if (!strcmp(left
, "stream_id")) {
451 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
453 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
455 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
458 CTF_EVENT_SET_FIELD(event
, stream_id
);
459 } else if (!strcmp(left
, "event_header")) {
460 struct declaration
*declaration
;
462 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
463 &node
->u
.ctf_expression
.right
,
464 stream
->type_scope
, stream
->declaration_scope
);
467 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
469 stream
->event_header
= container_of(declaration
, struct declaration_struct
, p
);
470 } else if (!strcmp(left
, "event_context")) {
471 struct declaration
*declaration
;
473 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
474 &node
->u
.ctf_expression
.right
,
475 stream
->type_scope
, stream
->declaration_scope
);
478 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
480 stream
->event_context
= container_of(declaration
, struct declaration_struct
, p
);
481 } else if (!strcmp(left
, "packet_context")) {
482 struct declaration
*declaration
;
484 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
485 &node
->u
.ctf_expression
.right
,
486 stream
->type_scope
, stream
->declaration_scope
);
489 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
491 stream
->packet_context
= container_of(declaration
, struct declaration_struct
, p
);
498 /* TODO: declaration specifier should be added. */
505 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
506 struct type_scope
*parent_type_scope
, struct ctf_trace
*trace
)
509 struct ctf_node
*iter
;
510 struct ctf_stream
*stream
;
512 stream
= g_new0(struct ctf_stream
, 1);
513 stream
->type_scope
= new_type_scope(parent_type_scope
);
514 stream
->declaration_scope
= new_declaration_scope(trace
->declaration_scope
);
515 stream
->events_by_id
= g_ptr_array_new();
516 stream
->event_quark_to_id
= g_hash_table_new(g_int_hash
, g_int_equal
);
517 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
518 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
522 if (!CTF_EVENT_FIELD_IS_SET(stream
, stream_id
)) {
526 if (trace
->streams
->len
<= stream
->stream_id
)
527 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
528 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
532 declaration_unref(stream
->event_header
);
533 declaration_unref(stream
->event_context
);
534 declaration_unref(stream
->packet_context
);
535 g_ptr_array_free(stream
->events_by_id
, TRUE
);
536 g_hash_table_free(stream
->event_quark_to_id
);
537 free_declaration_scope(stream
->declaration_scope
);
538 free_type_scope(stream
->type_scope
);
544 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
548 switch (node
->type
) {
550 ret
= ctf_typedef_visit(fd
, depth
+ 1,
551 &node
->u
._typedef
.declaration_specifier
,
552 &node
->u
._typedef
.type_declarators
,
553 trace
->type_scope
, trace
->declaration_scope
);
558 ret
= ctf_typealias_visit(fd
, depth
+ 1,
559 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
560 trace
->type_scope
, trace
->declaration_scope
);
564 case NODE_CTF_EXPRESSION
:
568 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
569 if (!strcmp(left
, "major")) {
570 if (CTF_EVENT_FIELD_IS_SET(trace
, major
))
572 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
574 fprintf(stderr
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
577 CTF_EVENT_SET_FIELD(trace
, major
);
578 } else if (!strcmp(left
, "minor")) {
579 if (CTF_EVENT_FIELD_IS_SET(trace
, minor
))
581 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
583 fprintf(stderr
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
586 CTF_EVENT_SET_FIELD(trace
, minor
);
587 } else if (!strcmp(left
, "word_size")) {
588 if (CTF_EVENT_FIELD_IS_SET(trace
, word_size
))
590 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->word_size
);
592 fprintf(stderr
, "[error] %s: unexpected unary expression for trace word_size\n", __func__
);
595 CTF_EVENT_SET_FIELD(trace
, word_size
);
596 } else if (!strcmp(left
, "uuid")) {
597 if (CTF_EVENT_FIELD_IS_SET(trace
, uuid
))
599 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &trace
->uuid
);
601 fprintf(stderr
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
604 CTF_EVENT_SET_FIELD(trace
, uuid
);
611 /* TODO: declaration specifier should be added. */
619 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
622 struct ctf_node
*iter
;
624 if (trace
->type_scope
)
626 trace
->type_scope
= new_type_scope(trace
->root_type_scope
);
627 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
628 trace
->streams
= g_ptr_array_new();
629 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
630 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
634 if (!CTF_EVENT_FIELD_IS_SET(trace
, major
)) {
638 if (!CTF_EVENT_FIELD_IS_SET(trace
, minor
)) {
642 if (!CTF_EVENT_FIELD_IS_SET(trace
, uuid
)) {
646 if (!CTF_EVENT_FIELD_IS_SET(trace
, word_size
)) {
653 g_ptr_array_free(trace
->streams
, TRUE
);
654 free_declaration_scope(stream
->declaration_scope
);
655 free_type_scope(stream
->type_scope
);
659 int _ctf_visitor(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
662 struct ctf_node
*iter
;
664 switch (node
->type
) {
666 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
668 ret
= ctf_typedef_visit(fd
, depth
+ 1,
669 &iter
->u
._typedef
.declaration_specifier
,
670 &iter
->u
._typedef
.type_declarators
,
671 trace
->type_scope
, trace
->declaration_scope
);
675 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
677 ret
= ctf_typealias_visit(fd
, depth
+ 1,
678 &iter
->u
.typealias
.target
, &iter
->u
.typealias
.alias
679 trace
->type_scope
, trace
->declaration_scope
);
683 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
684 ret
= ctf_type_specifier_visit(fd
, depth
, iter
,
685 trace
->root_type_scope
,
686 trace
->root_declaration_scope
);
690 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
691 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
695 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
696 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
697 trace
->type_scope
, trace
);
701 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
702 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
703 trace
->type_scope
, trace
);
709 case NODE_TYPEALIAS_TARGET
:
710 print_tabs(fd
, depth
);
711 fprintf(fd
, "<target>\n");
714 print_tabs(fd
, depth
);
715 fprintf(fd
, "<declaration_specifier>\n");
716 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
717 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
721 print_tabs(fd
, depth
);
722 fprintf(fd
, "</declaration_specifier>\n");
724 print_tabs(fd
, depth
);
725 fprintf(fd
, "<type_declarators>\n");
726 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
727 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
731 print_tabs(fd
, depth
);
732 fprintf(fd
, "</type_declarators>\n");
735 print_tabs(fd
, depth
);
736 fprintf(fd
, "</target>\n");
738 case NODE_TYPEALIAS_ALIAS
:
739 print_tabs(fd
, depth
);
740 fprintf(fd
, "<alias>\n");
743 print_tabs(fd
, depth
);
744 fprintf(fd
, "<declaration_specifier>\n");
745 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
746 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
750 print_tabs(fd
, depth
);
751 fprintf(fd
, "</declaration_specifier>\n");
753 print_tabs(fd
, depth
);
754 fprintf(fd
, "<type_declarators>\n");
755 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
756 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
760 print_tabs(fd
, depth
);
761 fprintf(fd
, "</type_declarators>\n");
764 print_tabs(fd
, depth
);
765 fprintf(fd
, "</alias>\n");
768 print_tabs(fd
, depth
);
769 fprintf(fd
, "<typealias>\n");
770 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
773 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
776 print_tabs(fd
, depth
);
777 fprintf(fd
, "</typealias>\n");
780 case NODE_TYPE_SPECIFIER
:
781 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
786 print_tabs(fd
, depth
);
787 if (node
->u
.pointer
.const_qualifier
)
788 fprintf(fd
, "<const_pointer />\n");
790 fprintf(fd
, "<pointer />\n");
792 case NODE_TYPE_DECLARATOR
:
793 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
798 case NODE_FLOATING_POINT
:
799 print_tabs(fd
, depth
);
800 fprintf(fd
, "<floating_point>\n");
801 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
802 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
806 print_tabs(fd
, depth
);
807 fprintf(fd
, "</floating_point>\n");
810 print_tabs(fd
, depth
);
811 fprintf(fd
, "<integer>\n");
812 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
813 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
817 print_tabs(fd
, depth
);
818 fprintf(fd
, "</integer>\n");
821 print_tabs(fd
, depth
);
822 fprintf(fd
, "<string>\n");
823 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
824 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
828 print_tabs(fd
, depth
);
829 fprintf(fd
, "</string>\n");
831 case NODE_ENUMERATOR
:
832 print_tabs(fd
, depth
);
833 fprintf(fd
, "<enumerator");
834 if (node
->u
.enumerator
.id
)
835 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
837 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
838 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
842 print_tabs(fd
, depth
);
843 fprintf(fd
, "</enumerator>\n");
846 print_tabs(fd
, depth
);
847 if (node
->u
._struct
.name
)
848 fprintf(fd
, "<enum name=\"%s\">\n",
849 node
->u
._enum
.enum_id
);
851 fprintf(fd
, "<enum >\n");
854 if (node
->u
._enum
.container_type
) {
855 print_tabs(fd
, depth
);
856 fprintf(fd
, "<container_type>\n");
857 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
860 print_tabs(fd
, depth
);
861 fprintf(fd
, "</container_type>\n");
864 print_tabs(fd
, depth
);
865 fprintf(fd
, "<enumerator_list>\n");
866 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
867 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
871 print_tabs(fd
, depth
);
872 fprintf(fd
, "</enumerator_list>\n");
875 print_tabs(fd
, depth
);
876 fprintf(fd
, "</enum>\n");
878 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
879 print_tabs(fd
, depth
);
880 fprintf(fd
, "<declaration_specifier>\n");
881 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
882 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
886 print_tabs(fd
, depth
);
887 fprintf(fd
, "</declaration_specifier>\n");
889 print_tabs(fd
, depth
);
890 fprintf(fd
, "<type_declarators>\n");
891 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
892 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
896 print_tabs(fd
, depth
);
897 fprintf(fd
, "</type_declarators>\n");
900 print_tabs(fd
, depth
);
901 fprintf(fd
, "<variant");
902 if (node
->u
.variant
.name
)
903 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
904 if (node
->u
.variant
.choice
)
905 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
907 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
908 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
912 print_tabs(fd
, depth
);
913 fprintf(fd
, "</variant>\n");
916 print_tabs(fd
, depth
);
917 if (node
->u
._struct
.name
)
918 fprintf(fd
, "<struct name=\"%s\">\n",
919 node
->u
._struct
.name
);
921 fprintf(fd
, "<struct>\n");
922 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
923 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
927 print_tabs(fd
, depth
);
928 fprintf(fd
, "</struct>\n");
933 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,