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)
34 #define _cds_list_first_entry(ptr, type, member) \
35 cds_list_entry((ptr)->next, type, member)
38 int ctf_visitor_print_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
40 print_tabs(fd
, depth
);
41 fprintf(fd
, "<type_specifier \"");
43 switch (node
->u
.type_specifier
.type
) {
63 fprintf(fd
, "double");
66 fprintf(fd
, "signed");
68 case TYPESPEC_UNSIGNED
:
69 fprintf(fd
, "unsigned");
74 case TYPESPEC_COMPLEX
:
75 fprintf(fd
, "complex");
80 case TYPESPEC_ID_TYPE
:
81 fprintf(fd
, "%s", node
->u
.type_specifier
.id_type
);
84 case TYPESPEC_UNKNOWN
:
86 fprintf(stderr
, "[error] %s: unknown type specifier %d\n", __func__
,
87 (int) node
->u
.type_specifier
.type
);
90 fprintf(fd
, "\"/>\n");
95 int ctf_visitor_print_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
98 struct ctf_node
*iter
;
100 print_tabs(fd
, depth
);
101 fprintf(fd
, "<type_declarator>\n");
104 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
105 print_tabs(fd
, depth
);
106 fprintf(fd
, "<pointers>\n");
107 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
109 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
113 print_tabs(fd
, depth
);
114 fprintf(fd
, "</pointers>\n");
117 switch (node
->u
.type_declarator
.type
) {
119 if (node
->u
.type_declarator
.u
.id
) {
120 print_tabs(fd
, depth
);
121 fprintf(fd
, "<id \"");
122 fprintf(fd
, "%s", node
->u
.type_declarator
.u
.id
);
123 fprintf(fd
, "\" />\n");
127 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
128 print_tabs(fd
, depth
);
129 fprintf(fd
, "<type_declarator>\n");
130 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
131 node
->u
.type_declarator
.u
.nested
.type_declarator
);
134 print_tabs(fd
, depth
);
135 fprintf(fd
, "</type_declarator>\n");
137 if (node
->u
.type_declarator
.u
.nested
.length
) {
138 print_tabs(fd
, depth
);
139 fprintf(fd
, "<length>\n");
140 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
141 node
->u
.type_declarator
.u
.nested
.length
);
144 print_tabs(fd
, depth
);
145 fprintf(fd
, "</length>\n");
147 if (node
->u
.type_declarator
.u
.nested
.abstract_array
) {
148 print_tabs(fd
, depth
);
149 fprintf(fd
, "<length>\n");
150 print_tabs(fd
, depth
);
151 fprintf(fd
, "</length>\n");
153 if (node
->u
.type_declarator
.bitfield_len
) {
154 print_tabs(fd
, depth
);
155 fprintf(fd
, "<bitfield_len>\n");
156 ret
= ctf_visitor_print_xml(fd
, depth
+ 1,
157 node
->u
.type_declarator
.bitfield_len
);
160 print_tabs(fd
, depth
);
161 fprintf(fd
, "</bitfield_len>\n");
164 case TYPEDEC_UNKNOWN
:
166 fprintf(stderr
, "[error] %s: unknown type declarator %d\n", __func__
,
167 (int) node
->u
.type_declarator
.type
);
172 print_tabs(fd
, depth
);
173 fprintf(fd
, "</type_declarator>\n");
178 * String returned must be freed by the caller.
181 char *concatenate_unary_strings(struct list_head
*head
)
187 int get_unary_unsigned(struct list_head
*head
, uint64_t *value
)
193 int get_unary_uuid(struct list_head
*head
, uuid_t
*uuid
)
199 struct ctf_stream
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
201 if (trace
->streams
->len
<= stream_id
)
203 return g_ptr_array_index(trace
->streams
, stream_id
);
207 * Also add named variant, struct or enum to the current type scope.
210 struct ctf_type
*ctf_type_specifier_visit(FILE *fd
,
211 int depth
, struct list_head
*head
,
212 struct type_scope
*type_scope
,
213 struct declaration_scope
*declaration_scope
)
215 struct ctf_type
*type
;
218 first
= _cds_list_first_entry(head
, struct node
, siblings
);
220 switch (first
->type
) {
222 /* For named struct (without body), lookup in type scope */
223 /* For named struct (with body), create type and add to type scope */
224 /* For unnamed struct, create type */
227 /* For named variant (without body), lookup in type scope */
228 /* For named variant (with body), create type and add to type scope */
229 /* For unnamed variant, create type */
232 /* For named enum (without body), lookup in type scope */
233 /* For named enum (with body), create type and add to type scope */
234 /* For unnamed enum, create type */
238 case NODE_FLOATING_POINT
:
240 case NODE_TYPE_SPECIFIER
:
247 struct ctf_declaration
*ctf_declaration_specifier_visit(FILE *fd
,
248 int depth
, struct list_head
*head
,
249 struct type_scope
*type_scope
,
250 struct declaration_scope
*declaration_scope
)
252 struct ctf_declaration
*declaration
;
253 struct ctf_type
*type
;
255 type
= ctf_type_specifier_visit(fd
, depth
, head
, type_scope
,
257 declaration
= type
->declaration_new(type
, declaration_scope
);
258 if (type
->id
== CTF_TYPE_VARIANT
) {
259 struct declaration_variant
*variant
=
260 container_of(declaration
, struct declaration_variant
, p
);
261 struct declaration
*enum_tag
=
262 lookup_field_declaration(enum_tag_name
, declaration_scope
);
264 fprintf(fd
, "[error]: expected enumeration tag field %s for variant\n",
268 /* TODO find enum tag */
269 ret
= variant_declaration_set_tag(variant
, enum_tag
);
273 declaration_unref(declaration
);
279 int ctf_typedef_declarator_visit(FILE *fd
, int depth
,
280 struct list_head
*declaration_specifier
,
281 struct node
*type_declarator
, struct type_scope
*type_scope
,
282 struct declaration_scope
*declaration_scope
)
285 * Build the type using declaration specifier (creating
286 * declaration from type_specifier), then apply type declarator,
287 * add the resulting type to the current type scope.
289 cds_list_for_each_entry(iter
, declaration_specifier
, siblings
) {
297 int ctf_typedef_visit(FILE *fd
, int depth
,
298 struct list_head
*declaration_specifier
,
299 struct list_head
*type_declarators
,
300 struct type_scope
*type_scope
,
301 struct declaration_scope
*declaration_scope
)
303 struct ctf_node
*iter
;
305 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
306 ret
= ctf_typedef_declarator_visit(fd
, depth
+ 1,
307 &node
->u
._typedef
.declaration_specifier
, iter
,
308 type_scope
, declaration_scope
);
316 int ctf_typealias_visit(FILE *fd
, int depth
, struct ctf_node
*target
,
317 struct ctf_node
*alias
, struct type_scope
*type_scope
,
318 struct declaration_scope
*declaration_scope
)
320 /* Build target type, check that it is reachable in current type scope. */
321 /* Only one type declarator is allowed */
323 /* Build alias type, add to current type scope. */
324 /* Only one type declarator is allowed */
328 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event
*event
, struct ctf_trace
*trace
)
332 switch (node
->type
) {
334 ret
= ctf_typedef_visit(fd
, depth
+ 1,
335 &node
->u
._typedef
.declaration_specifier
,
336 &node
->u
._typedef
.type_declarators
,
337 event
->type_scope
, event
->declaration_scope
);
342 ret
= ctf_typealias_visit(fd
, depth
+ 1,
343 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
344 event
->type_scope
, event
->declaration_scope
);
348 case NODE_CTF_EXPRESSION
:
352 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
353 if (!strcmp(left
, "name")) {
356 if (CTF_EVENT_FIELD_IS_SET(event
, name
))
358 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
360 fprintf(stderr
, "[error] %s: unexpected unary expression for event name\n", __func__
);
363 event
->name
= g_quark_from_string(right
);
365 CTF_EVENT_SET_FIELD(event
, name
);
366 } else if (!strcmp(left
, "id")) {
367 if (CTF_EVENT_FIELD_IS_SET(event
, id
))
369 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
371 fprintf(stderr
, "[error] %s: unexpected unary expression for event id\n", __func__
);
374 CTF_EVENT_SET_FIELD(event
, id
);
375 } else if (!strcmp(left
, "stream_id")) {
376 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
378 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
380 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
383 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
384 if (!event
->stream
) {
385 fprintf(stderr
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
388 event
->declaration_scope
= new_declaration_scope(stream
->declaration_scope
);
389 if (!event
->declaration_scope
) {
390 fprintf(stderr
, "[error] %s: Error allocating declaration scope\n", __func__
);
393 CTF_EVENT_SET_FIELD(event
, stream_id
);
394 } else if (!strcmp(left
, "context")) {
395 struct declaration
*declaration
;
397 if (!event
->declaration_scope
)
399 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
400 &node
->u
.ctf_expression
.right
,
401 event
->type_scope
, event
->declaration_scope
);
404 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
406 event
->context
= container_of(declaration
, struct declaration_struct
, p
);
407 } else if (!strcmp(left
, "fields")) {
408 struct declaration
*declaration
;
410 if (!event
->declaration_scope
)
412 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
413 &node
->u
.ctf_expression
.right
,
414 event
->type_scope
, event
->declaration_scope
);
417 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
419 event
->fields
= container_of(declaration
, struct declaration_struct
, p
);
426 /* TODO: declaration specifier should be added. */
433 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
434 struct type_scope
*parent_type_scope
, struct ctf_trace
*trace
)
437 struct ctf_node
*iter
;
438 struct ctf_event
*event
;
440 event
= g_new0(struct ctf_event
, 1);
441 event
->type_scope
= new_type_scope(parent_type_scope
);
442 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
443 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
447 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
451 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)) {
455 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
459 if (event
->stream
->events_by_id
->len
<= event
->id
)
460 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
461 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
462 g_hash_table_insert(event
->stream
->event_quark_to_id
,
463 (gpointer
)(unsigned long) event
->name
,
468 declaration_unref(event
->fields
);
469 declaration_unref(event
->context
);
470 free_declaration_scope(event
->declaration_scope
);
471 free_type_scope(event
->type_scope
);
478 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream
*stream
, struct ctf_trace
*trace
)
482 switch (node
->type
) {
484 ret
= ctf_typedef_visit(fd
, depth
+ 1,
485 &node
->u
._typedef
.declaration_specifier
,
486 &node
->u
._typedef
.type_declarators
,
487 stream
->type_scope
, stream
->declaration_scope
);
492 ret
= ctf_typealias_visit(fd
, depth
+ 1,
493 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
494 stream
->type_scope
, stream
->declaration_scope
);
498 case NODE_CTF_EXPRESSION
:
502 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
503 if (!strcmp(left
, "stream_id")) {
504 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
))
506 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
508 fprintf(stderr
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
511 CTF_EVENT_SET_FIELD(event
, stream_id
);
512 } else if (!strcmp(left
, "event_header")) {
513 struct declaration
*declaration
;
515 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
516 &node
->u
.ctf_expression
.right
,
517 stream
->type_scope
, stream
->declaration_scope
);
520 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
522 stream
->event_header
= container_of(declaration
, struct declaration_struct
, p
);
523 } else if (!strcmp(left
, "event_context")) {
524 struct declaration
*declaration
;
526 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
527 &node
->u
.ctf_expression
.right
,
528 stream
->type_scope
, stream
->declaration_scope
);
531 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
533 stream
->event_context
= container_of(declaration
, struct declaration_struct
, p
);
534 } else if (!strcmp(left
, "packet_context")) {
535 struct declaration
*declaration
;
537 declaration
= ctf_declaration_specifier_visit(fd
, depth
,
538 &node
->u
.ctf_expression
.right
,
539 stream
->type_scope
, stream
->declaration_scope
);
542 if (declaration
->type
->id
!= CTF_TYPE_STRUCT
)
544 stream
->packet_context
= container_of(declaration
, struct declaration_struct
, p
);
551 /* TODO: declaration specifier should be added. */
558 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
559 struct type_scope
*parent_type_scope
, struct ctf_trace
*trace
)
562 struct ctf_node
*iter
;
563 struct ctf_stream
*stream
;
565 stream
= g_new0(struct ctf_stream
, 1);
566 stream
->type_scope
= new_type_scope(parent_type_scope
);
567 stream
->declaration_scope
= new_declaration_scope(trace
->declaration_scope
);
568 stream
->events_by_id
= g_ptr_array_new();
569 stream
->event_quark_to_id
= g_hash_table_new(g_int_hash
, g_int_equal
);
570 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
571 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
575 if (!CTF_EVENT_FIELD_IS_SET(stream
, stream_id
)) {
579 if (trace
->streams
->len
<= stream
->stream_id
)
580 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
581 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
585 declaration_unref(stream
->event_header
);
586 declaration_unref(stream
->event_context
);
587 declaration_unref(stream
->packet_context
);
588 g_ptr_array_free(stream
->events_by_id
, TRUE
);
589 g_hash_table_free(stream
->event_quark_to_id
);
590 free_declaration_scope(stream
->declaration_scope
);
591 free_type_scope(stream
->type_scope
);
597 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
601 switch (node
->type
) {
603 ret
= ctf_typedef_visit(fd
, depth
+ 1,
604 &node
->u
._typedef
.declaration_specifier
,
605 &node
->u
._typedef
.type_declarators
,
606 trace
->type_scope
, trace
->declaration_scope
);
611 ret
= ctf_typealias_visit(fd
, depth
+ 1,
612 &node
->u
.typealias
.target
, &node
->u
.typealias
.alias
613 trace
->type_scope
, trace
->declaration_scope
);
617 case NODE_CTF_EXPRESSION
:
621 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
622 if (!strcmp(left
, "major")) {
623 if (CTF_EVENT_FIELD_IS_SET(trace
, major
))
625 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
627 fprintf(stderr
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
630 CTF_EVENT_SET_FIELD(trace
, major
);
631 } else if (!strcmp(left
, "minor")) {
632 if (CTF_EVENT_FIELD_IS_SET(trace
, minor
))
634 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
636 fprintf(stderr
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
639 CTF_EVENT_SET_FIELD(trace
, minor
);
640 } else if (!strcmp(left
, "word_size")) {
641 if (CTF_EVENT_FIELD_IS_SET(trace
, word_size
))
643 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->word_size
);
645 fprintf(stderr
, "[error] %s: unexpected unary expression for trace word_size\n", __func__
);
648 CTF_EVENT_SET_FIELD(trace
, word_size
);
649 } else if (!strcmp(left
, "uuid")) {
650 if (CTF_EVENT_FIELD_IS_SET(trace
, uuid
))
652 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &trace
->uuid
);
654 fprintf(stderr
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
657 CTF_EVENT_SET_FIELD(trace
, uuid
);
664 /* TODO: declaration specifier should be added. */
672 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
675 struct ctf_node
*iter
;
677 if (trace
->type_scope
)
679 trace
->type_scope
= new_type_scope(trace
->root_type_scope
);
680 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
681 trace
->streams
= g_ptr_array_new();
682 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
683 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
687 if (!CTF_EVENT_FIELD_IS_SET(trace
, major
)) {
691 if (!CTF_EVENT_FIELD_IS_SET(trace
, minor
)) {
695 if (!CTF_EVENT_FIELD_IS_SET(trace
, uuid
)) {
699 if (!CTF_EVENT_FIELD_IS_SET(trace
, word_size
)) {
706 g_ptr_array_free(trace
->streams
, TRUE
);
707 free_declaration_scope(stream
->declaration_scope
);
708 free_type_scope(stream
->type_scope
);
712 int _ctf_visitor(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
715 struct ctf_node
*iter
;
717 switch (node
->type
) {
719 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
721 ret
= ctf_typedef_visit(fd
, depth
+ 1,
722 &iter
->u
._typedef
.declaration_specifier
,
723 &iter
->u
._typedef
.type_declarators
,
724 trace
->type_scope
, trace
->declaration_scope
);
728 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
730 ret
= ctf_typealias_visit(fd
, depth
+ 1,
731 &iter
->u
.typealias
.target
, &iter
->u
.typealias
.alias
732 trace
->type_scope
, trace
->declaration_scope
);
736 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, siblings
) {
737 ret
= ctf_declaration_specifier_visit(fd
, depth
, iter
,
738 trace
->root_type_scope
,
739 trace
->root_declaration_scope
);
743 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
744 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
748 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
749 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
750 trace
->type_scope
, trace
);
754 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
755 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
756 trace
->type_scope
, trace
);
762 case NODE_TYPEALIAS_TARGET
:
763 print_tabs(fd
, depth
);
764 fprintf(fd
, "<target>\n");
767 print_tabs(fd
, depth
);
768 fprintf(fd
, "<declaration_specifier>\n");
769 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
770 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
774 print_tabs(fd
, depth
);
775 fprintf(fd
, "</declaration_specifier>\n");
777 print_tabs(fd
, depth
);
778 fprintf(fd
, "<type_declarators>\n");
779 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
780 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
784 print_tabs(fd
, depth
);
785 fprintf(fd
, "</type_declarators>\n");
788 print_tabs(fd
, depth
);
789 fprintf(fd
, "</target>\n");
791 case NODE_TYPEALIAS_ALIAS
:
792 print_tabs(fd
, depth
);
793 fprintf(fd
, "<alias>\n");
796 print_tabs(fd
, depth
);
797 fprintf(fd
, "<declaration_specifier>\n");
798 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
799 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
803 print_tabs(fd
, depth
);
804 fprintf(fd
, "</declaration_specifier>\n");
806 print_tabs(fd
, depth
);
807 fprintf(fd
, "<type_declarators>\n");
808 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
809 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
813 print_tabs(fd
, depth
);
814 fprintf(fd
, "</type_declarators>\n");
817 print_tabs(fd
, depth
);
818 fprintf(fd
, "</alias>\n");
821 print_tabs(fd
, depth
);
822 fprintf(fd
, "<typealias>\n");
823 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.target
);
826 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
.typealias
.alias
);
829 print_tabs(fd
, depth
);
830 fprintf(fd
, "</typealias>\n");
833 case NODE_TYPE_SPECIFIER
:
834 ret
= ctf_visitor_print_type_specifier(fd
, depth
, node
);
839 print_tabs(fd
, depth
);
840 if (node
->u
.pointer
.const_qualifier
)
841 fprintf(fd
, "<const_pointer />\n");
843 fprintf(fd
, "<pointer />\n");
845 case NODE_TYPE_DECLARATOR
:
846 ret
= ctf_visitor_print_type_declarator(fd
, depth
, node
);
851 case NODE_FLOATING_POINT
:
852 print_tabs(fd
, depth
);
853 fprintf(fd
, "<floating_point>\n");
854 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
855 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
859 print_tabs(fd
, depth
);
860 fprintf(fd
, "</floating_point>\n");
863 print_tabs(fd
, depth
);
864 fprintf(fd
, "<integer>\n");
865 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
866 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
870 print_tabs(fd
, depth
);
871 fprintf(fd
, "</integer>\n");
874 print_tabs(fd
, depth
);
875 fprintf(fd
, "<string>\n");
876 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
877 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
881 print_tabs(fd
, depth
);
882 fprintf(fd
, "</string>\n");
884 case NODE_ENUMERATOR
:
885 print_tabs(fd
, depth
);
886 fprintf(fd
, "<enumerator");
887 if (node
->u
.enumerator
.id
)
888 fprintf(fd
, " id=\"%s\"", node
->u
.enumerator
.id
);
890 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
891 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
895 print_tabs(fd
, depth
);
896 fprintf(fd
, "</enumerator>\n");
899 print_tabs(fd
, depth
);
900 if (node
->u
._struct
.name
)
901 fprintf(fd
, "<enum name=\"%s\">\n",
902 node
->u
._enum
.enum_id
);
904 fprintf(fd
, "<enum >\n");
907 if (node
->u
._enum
.container_type
) {
908 print_tabs(fd
, depth
);
909 fprintf(fd
, "<container_type>\n");
910 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, node
->u
._enum
.container_type
);
913 print_tabs(fd
, depth
);
914 fprintf(fd
, "</container_type>\n");
917 print_tabs(fd
, depth
);
918 fprintf(fd
, "<enumerator_list>\n");
919 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
920 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
924 print_tabs(fd
, depth
);
925 fprintf(fd
, "</enumerator_list>\n");
928 print_tabs(fd
, depth
);
929 fprintf(fd
, "</enum>\n");
931 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
932 print_tabs(fd
, depth
);
933 fprintf(fd
, "<declaration_specifier>\n");
934 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
935 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
939 print_tabs(fd
, depth
);
940 fprintf(fd
, "</declaration_specifier>\n");
942 print_tabs(fd
, depth
);
943 fprintf(fd
, "<type_declarators>\n");
944 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
945 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
949 print_tabs(fd
, depth
);
950 fprintf(fd
, "</type_declarators>\n");
953 print_tabs(fd
, depth
);
954 fprintf(fd
, "<variant");
955 if (node
->u
.variant
.name
)
956 fprintf(fd
, " name=\"%s\"", node
->u
.variant
.name
);
957 if (node
->u
.variant
.choice
)
958 fprintf(fd
, " choice=\"%s\"", node
->u
.variant
.choice
);
960 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
961 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
965 print_tabs(fd
, depth
);
966 fprintf(fd
, "</variant>\n");
969 print_tabs(fd
, depth
);
970 if (node
->u
._struct
.name
)
971 fprintf(fd
, "<struct name=\"%s\">\n",
972 node
->u
._struct
.name
);
974 fprintf(fd
, "<struct>\n");
975 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
976 ret
= ctf_visitor_print_xml(fd
, depth
+ 1, iter
);
980 print_tabs(fd
, depth
);
981 fprintf(fd
, "</struct>\n");
986 fprintf(stderr
, "[error] %s: unknown node type %d\n", __func__
,