Fix XML output in ctf-parser-test
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-xml.c
CommitLineData
7de8808c
MD
1/*
2 * ctf-visitor-xml.c
3 *
4 * Common Trace Format Metadata Visitor (XML dump).
5 *
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19#include <stdio.h>
20#include <unistd.h>
21#include <string.h>
22#include <stdlib.h>
23#include <assert.h>
7de8808c 24#include <glib.h>
380d60b1 25#include <inttypes.h>
7de8808c 26#include <errno.h>
c8b219a3 27#include <babeltrace/babeltrace.h>
fe41395a 28#include <babeltrace/list.h>
7de8808c
MD
29#include "ctf-scanner.h"
30#include "ctf-parser.h"
31#include "ctf-ast.h"
32
34f7b02c 33#define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
7de8808c 34
67905e42
MD
35static
36void print_tabs(FILE *fd, int depth)
7de8808c
MD
37{
38 int i;
39
40 for (i = 0; i < depth; i++)
41 fprintf(fd, "\t");
42}
43
67905e42 44static
7de8808c
MD
45int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *node)
46{
47 int ret = 0;
48
48a01768
MD
49 switch (node->u.unary_expression.link) {
50 case UNARY_LINK_UNKNOWN:
51 break;
52 case UNARY_DOTLINK:
53 print_tabs(fd, depth);
54 fprintf(fd, "<dotlink/>\n");
55 break;
56 case UNARY_ARROWLINK:
57 print_tabs(fd, depth);
58 fprintf(fd, "<arrowlink/>\n");
59 break;
60 case UNARY_DOTDOTDOT:
61 print_tabs(fd, depth);
62 fprintf(fd, "<dotdotdot/>\n");
63 break;
64 default:
65 fprintf(stderr, "[error] %s: unknown expression link type %d\n", __func__,
66 (int) node->u.unary_expression.link);
67 return -EINVAL;
68 }
69
7de8808c
MD
70 switch (node->u.unary_expression.type) {
71 case UNARY_STRING:
72 print_tabs(fd, depth);
73 fprintf(fd, "<unary_expression value=");
74 fprintf(fd, "\"%s\"", node->u.unary_expression.u.string);
48a01768 75 fprintf(fd, " />\n");
7de8808c
MD
76 break;
77 case UNARY_SIGNED_CONSTANT:
78 print_tabs(fd, depth);
a10a7e5b 79 fprintf(fd, "<unary_expression value=\"");
380d60b1 80 fprintf(fd, "%" PRId64, node->u.unary_expression.u.signed_constant);
a10a7e5b 81 fprintf(fd, "\" />\n");
7de8808c
MD
82 break;
83 case UNARY_UNSIGNED_CONSTANT:
84 print_tabs(fd, depth);
a10a7e5b 85 fprintf(fd, "<unary_expression value=\"");
380d60b1 86 fprintf(fd, "%" PRIu64, node->u.unary_expression.u.signed_constant);
a10a7e5b 87 fprintf(fd, "\" />\n");
7de8808c
MD
88 break;
89 case UNARY_SBRAC:
90 print_tabs(fd, depth);
4759bcf5 91 fprintf(fd, "<unary_expression_sbrac>\n");
7de8808c
MD
92 ret = ctf_visitor_print_unary_expression(fd, depth + 1,
93 node->u.unary_expression.u.sbrac_exp);
94 if (ret)
95 return ret;
96 print_tabs(fd, depth);
4759bcf5 97 fprintf(fd, "</unary_expression_sbrac>\n");
7de8808c 98 break;
48a01768
MD
99 case UNARY_NESTED:
100 print_tabs(fd, depth);
4759bcf5 101 fprintf(fd, "<unary_expression_nested>\n");
48a01768
MD
102 ret = ctf_visitor_print_unary_expression(fd, depth + 1,
103 node->u.unary_expression.u.nested_exp);
104 if (ret)
105 return ret;
106 print_tabs(fd, depth);
4759bcf5 107 fprintf(fd, "</unary_expression_nested>\n");
48a01768 108 break;
7de8808c
MD
109
110 case UNARY_UNKNOWN:
111 default:
112 fprintf(stderr, "[error] %s: unknown expression type %d\n", __func__,
113 (int) node->u.unary_expression.type);
114 return -EINVAL;
115 }
7de8808c
MD
116 return 0;
117}
118
3e11b713
MD
119static
120int ctf_visitor_print_type_specifier_list(FILE *fd, int depth, struct ctf_node *node)
121{
122 struct ctf_node *iter;
123 int ret;
124
125 print_tabs(fd, depth);
126 fprintf(fd, "<type_specifier_list>\n");
127 cds_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
128 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
129 if (ret)
130 return ret;
131 }
132 print_tabs(fd, depth);
133 fprintf(fd, "</type_specifier_list>\n");
134 return 0;
135}
136
67905e42 137static
7de8808c
MD
138int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
139{
a10a7e5b 140 int ret;
7de8808c 141 print_tabs(fd, depth);
3e11b713
MD
142
143 switch (node->u.type_specifier.type) {
144 case TYPESPEC_VOID:
145 case TYPESPEC_CHAR:
146 case TYPESPEC_SHORT:
147 case TYPESPEC_INT:
148 case TYPESPEC_LONG:
149 case TYPESPEC_FLOAT:
150 case TYPESPEC_DOUBLE:
151 case TYPESPEC_SIGNED:
152 case TYPESPEC_UNSIGNED:
153 case TYPESPEC_BOOL:
154 case TYPESPEC_COMPLEX:
155 case TYPESPEC_IMAGINARY:
156 case TYPESPEC_CONST:
157 case TYPESPEC_ID_TYPE:
a10a7e5b 158 fprintf(fd, "<type_specifier type=\"");
3e11b713
MD
159 break;
160 case TYPESPEC_FLOATING_POINT:
161 case TYPESPEC_INTEGER:
162 case TYPESPEC_STRING:
163 case TYPESPEC_STRUCT:
164 case TYPESPEC_VARIANT:
165 case TYPESPEC_ENUM:
166 fprintf(fd, "<type_specifier>\n");
167 depth++;
168 break;
169 case TYPESPEC_UNKNOWN:
170 default:
171 fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
172 (int) node->u.type_specifier.type);
173 return -EINVAL;
174 }
7de8808c
MD
175
176 switch (node->u.type_specifier.type) {
177 case TYPESPEC_VOID:
178 fprintf(fd, "void");
179 break;
180 case TYPESPEC_CHAR:
181 fprintf(fd, "char");
182 break;
183 case TYPESPEC_SHORT:
184 fprintf(fd, "short");
185 break;
186 case TYPESPEC_INT:
187 fprintf(fd, "int");
188 break;
189 case TYPESPEC_LONG:
190 fprintf(fd, "long");
191 break;
192 case TYPESPEC_FLOAT:
193 fprintf(fd, "float");
194 break;
195 case TYPESPEC_DOUBLE:
196 fprintf(fd, "double");
197 break;
198 case TYPESPEC_SIGNED:
199 fprintf(fd, "signed");
200 break;
201 case TYPESPEC_UNSIGNED:
202 fprintf(fd, "unsigned");
203 break;
204 case TYPESPEC_BOOL:
205 fprintf(fd, "bool");
206 break;
207 case TYPESPEC_COMPLEX:
3888a159
MD
208 fprintf(fd, "_Complex");
209 break;
210 case TYPESPEC_IMAGINARY:
211 fprintf(fd, "_Imaginary");
7de8808c
MD
212 break;
213 case TYPESPEC_CONST:
214 fprintf(fd, "const");
215 break;
216 case TYPESPEC_ID_TYPE:
217 fprintf(fd, "%s", node->u.type_specifier.id_type);
218 break;
3e11b713
MD
219 case TYPESPEC_FLOATING_POINT:
220 case TYPESPEC_INTEGER:
221 case TYPESPEC_STRING:
222 case TYPESPEC_STRUCT:
223 case TYPESPEC_VARIANT:
224 case TYPESPEC_ENUM:
a10a7e5b
SM
225 ret = ctf_visitor_print_xml(fd, depth, node->u.type_specifier.node);
226 if (ret)
227 return ret;
228 break;
3e11b713
MD
229 case TYPESPEC_UNKNOWN:
230 default:
231 fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
232 (int) node->u.type_specifier.type);
233 return -EINVAL;
234 }
7de8808c 235
3e11b713
MD
236 switch (node->u.type_specifier.type) {
237 case TYPESPEC_VOID:
238 case TYPESPEC_CHAR:
239 case TYPESPEC_SHORT:
240 case TYPESPEC_INT:
241 case TYPESPEC_LONG:
242 case TYPESPEC_FLOAT:
243 case TYPESPEC_DOUBLE:
244 case TYPESPEC_SIGNED:
245 case TYPESPEC_UNSIGNED:
246 case TYPESPEC_BOOL:
247 case TYPESPEC_COMPLEX:
248 case TYPESPEC_IMAGINARY:
249 case TYPESPEC_CONST:
250 case TYPESPEC_ID_TYPE:
251 fprintf(fd, "\"/>\n");
252 break;
253 case TYPESPEC_FLOATING_POINT:
254 case TYPESPEC_INTEGER:
255 case TYPESPEC_STRING:
256 case TYPESPEC_STRUCT:
257 case TYPESPEC_VARIANT:
258 case TYPESPEC_ENUM:
a10a7e5b 259 depth--;
3e11b713
MD
260 print_tabs(fd, depth);
261 fprintf(fd, "</type_specifier>\n");
3e11b713 262 break;
7de8808c
MD
263 case TYPESPEC_UNKNOWN:
264 default:
265 fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
266 (int) node->u.type_specifier.type);
267 return -EINVAL;
268 }
3e11b713 269
7de8808c
MD
270 return 0;
271}
272
67905e42 273static
7de8808c
MD
274int ctf_visitor_print_type_declarator(FILE *fd, int depth, struct ctf_node *node)
275{
276 int ret = 0;
277 struct ctf_node *iter;
278
279 print_tabs(fd, depth);
280 fprintf(fd, "<type_declarator>\n");
281 depth++;
282
48a01768
MD
283 if (!cds_list_empty(&node->u.type_declarator.pointers)) {
284 print_tabs(fd, depth);
285 fprintf(fd, "<pointers>\n");
286 cds_list_for_each_entry(iter, &node->u.type_declarator.pointers,
287 siblings) {
288 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
289 if (ret)
290 return ret;
291 }
292 print_tabs(fd, depth);
293 fprintf(fd, "</pointers>\n");
7de8808c 294 }
7de8808c
MD
295
296 switch (node->u.type_declarator.type) {
297 case TYPEDEC_ID:
0009a725
MD
298 if (node->u.type_declarator.u.id) {
299 print_tabs(fd, depth);
a10a7e5b 300 fprintf(fd, "<id name=\"");
0009a725
MD
301 fprintf(fd, "%s", node->u.type_declarator.u.id);
302 fprintf(fd, "\" />\n");
303 }
7de8808c
MD
304 break;
305 case TYPEDEC_NESTED:
306 if (node->u.type_declarator.u.nested.type_declarator) {
307 print_tabs(fd, depth);
308 fprintf(fd, "<type_declarator>\n");
309 ret = ctf_visitor_print_xml(fd, depth + 1,
310 node->u.type_declarator.u.nested.type_declarator);
311 if (ret)
312 return ret;
313 print_tabs(fd, depth);
314 fprintf(fd, "</type_declarator>\n");
315 }
98df1c9f 316 if (!cds_list_empty(&node->u.type_declarator.u.nested.length)) {
7de8808c
MD
317 print_tabs(fd, depth);
318 fprintf(fd, "<length>\n");
98df1c9f
MD
319 cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
320 siblings) {
321 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
322 if (ret)
323 return ret;
324 }
7de8808c
MD
325 print_tabs(fd, depth);
326 fprintf(fd, "</length>\n");
327 }
328 if (node->u.type_declarator.u.nested.abstract_array) {
329 print_tabs(fd, depth);
330 fprintf(fd, "<length>\n");
331 print_tabs(fd, depth);
332 fprintf(fd, "</length>\n");
333 }
334 if (node->u.type_declarator.bitfield_len) {
335 print_tabs(fd, depth);
336 fprintf(fd, "<bitfield_len>\n");
337 ret = ctf_visitor_print_xml(fd, depth + 1,
338 node->u.type_declarator.bitfield_len);
339 if (ret)
340 return ret;
341 print_tabs(fd, depth);
342 fprintf(fd, "</bitfield_len>\n");
343 }
344 break;
345 case TYPEDEC_UNKNOWN:
346 default:
347 fprintf(stderr, "[error] %s: unknown type declarator %d\n", __func__,
348 (int) node->u.type_declarator.type);
349 return -EINVAL;
350 }
351
352 depth--;
353 print_tabs(fd, depth);
354 fprintf(fd, "</type_declarator>\n");
355 return 0;
356}
357
358int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
359{
360 int ret = 0;
361 struct ctf_node *iter;
362
363 switch (node->type) {
364 case NODE_ROOT:
365 print_tabs(fd, depth);
366 fprintf(fd, "<root>\n");
3e11b713 367 cds_list_for_each_entry(iter, &node->u.root.declaration_list,
7de8808c
MD
368 siblings) {
369 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
370 if (ret)
371 return ret;
372 }
7de8808c
MD
373 cds_list_for_each_entry(iter, &node->u.root.trace, siblings) {
374 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
375 if (ret)
376 return ret;
377 }
378 cds_list_for_each_entry(iter, &node->u.root.stream, siblings) {
379 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
380 if (ret)
381 return ret;
382 }
383 cds_list_for_each_entry(iter, &node->u.root.event, siblings) {
384 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
385 if (ret)
386 return ret;
387 }
388 print_tabs(fd, depth);
389 fprintf(fd, "</root>\n");
390 break;
391
392 case NODE_EVENT:
393 print_tabs(fd, depth);
394 fprintf(fd, "<event>\n");
395 cds_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
396 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
397 if (ret)
398 return ret;
399 }
400 print_tabs(fd, depth);
401 fprintf(fd, "</event>\n");
402 break;
403 case NODE_STREAM:
404 print_tabs(fd, depth);
405 fprintf(fd, "<stream>\n");
406 cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
407 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
408 if (ret)
409 return ret;
410 }
411 print_tabs(fd, depth);
412 fprintf(fd, "</stream>\n");
413 break;
414 case NODE_TRACE:
415 print_tabs(fd, depth);
416 fprintf(fd, "<trace>\n");
417 cds_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
418 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
419 if (ret)
420 return ret;
421 }
422 print_tabs(fd, depth);
423 fprintf(fd, "</trace>\n");
424 break;
425
426 case NODE_CTF_EXPRESSION:
427 print_tabs(fd, depth);
428 fprintf(fd, "<ctf_expression>\n");
429 depth++;
430 print_tabs(fd, depth);
431 fprintf(fd, "<left>\n");
48a01768
MD
432 cds_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) {
433 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
434 if (ret)
435 return ret;
436 }
437
7de8808c
MD
438 print_tabs(fd, depth);
439 fprintf(fd, "</left>\n");
440
441 print_tabs(fd, depth);
442 fprintf(fd, "<right>\n");
48a01768
MD
443 cds_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
444 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
445 if (ret)
446 return ret;
447 }
7de8808c
MD
448 print_tabs(fd, depth);
449 fprintf(fd, "</right>\n");
450 depth--;
451 print_tabs(fd, depth);
452 fprintf(fd, "</ctf_expression>\n");
453 break;
454 case NODE_UNARY_EXPRESSION:
455 return ctf_visitor_print_unary_expression(fd, depth, node);
456
457 case NODE_TYPEDEF:
458 print_tabs(fd, depth);
459 fprintf(fd, "<typedef>\n");
460 depth++;
3e11b713
MD
461 ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list);
462 if (ret)
463 return ret;
7de8808c
MD
464
465 print_tabs(fd, depth);
3e11b713 466 fprintf(fd, "<type_declarator_list>\n");
7de8808c
MD
467 cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
468 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
469 if (ret)
470 return ret;
471 }
472 print_tabs(fd, depth);
3e11b713 473 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
474 depth--;
475 print_tabs(fd, depth);
476 fprintf(fd, "</typedef>\n");
477 break;
478 case NODE_TYPEALIAS_TARGET:
479 print_tabs(fd, depth);
480 fprintf(fd, "<target>\n");
481 depth++;
482
3e11b713
MD
483 ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list);
484 if (ret)
485 return ret;
7de8808c
MD
486
487 print_tabs(fd, depth);
3e11b713 488 fprintf(fd, "<type_declarator_list>\n");
7de8808c
MD
489 cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
490 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
491 if (ret)
492 return ret;
493 }
494 print_tabs(fd, depth);
3e11b713 495 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
496
497 depth--;
498 print_tabs(fd, depth);
499 fprintf(fd, "</target>\n");
500 break;
501 case NODE_TYPEALIAS_ALIAS:
502 print_tabs(fd, depth);
503 fprintf(fd, "<alias>\n");
504 depth++;
505
3e11b713
MD
506 ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list);
507 if (ret)
508 return ret;
7de8808c
MD
509
510 print_tabs(fd, depth);
3e11b713 511 fprintf(fd, "<type_declarator_list>\n");
7de8808c
MD
512 cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
513 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
514 if (ret)
515 return ret;
516 }
517 print_tabs(fd, depth);
3e11b713 518 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
519
520 depth--;
521 print_tabs(fd, depth);
522 fprintf(fd, "</alias>\n");
523 break;
524 case NODE_TYPEALIAS:
525 print_tabs(fd, depth);
526 fprintf(fd, "<typealias>\n");
527 ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.target);
528 if (ret)
529 return ret;
530 ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.alias);
531 if (ret)
532 return ret;
533 print_tabs(fd, depth);
534 fprintf(fd, "</typealias>\n");
535 break;
536
3e11b713
MD
537 case NODE_TYPE_SPECIFIER_LIST:
538 ret = ctf_visitor_print_type_specifier_list(fd, depth, node);
539 if (ret)
540 return ret;
541 break;
542
7de8808c
MD
543 case NODE_TYPE_SPECIFIER:
544 ret = ctf_visitor_print_type_specifier(fd, depth, node);
545 if (ret)
546 return ret;
547 break;
548 case NODE_POINTER:
549 print_tabs(fd, depth);
550 if (node->u.pointer.const_qualifier)
551 fprintf(fd, "<const_pointer />\n");
552 else
553 fprintf(fd, "<pointer />\n");
554 break;
555 case NODE_TYPE_DECLARATOR:
556 ret = ctf_visitor_print_type_declarator(fd, depth, node);
557 if (ret)
558 return ret;
559 break;
560
561 case NODE_FLOATING_POINT:
562 print_tabs(fd, depth);
563 fprintf(fd, "<floating_point>\n");
564 cds_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) {
565 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
566 if (ret)
567 return ret;
568 }
569 print_tabs(fd, depth);
570 fprintf(fd, "</floating_point>\n");
571 break;
572 case NODE_INTEGER:
573 print_tabs(fd, depth);
574 fprintf(fd, "<integer>\n");
575 cds_list_for_each_entry(iter, &node->u.integer.expressions, siblings) {
576 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
577 if (ret)
578 return ret;
579 }
580 print_tabs(fd, depth);
581 fprintf(fd, "</integer>\n");
582 break;
583 case NODE_STRING:
584 print_tabs(fd, depth);
585 fprintf(fd, "<string>\n");
586 cds_list_for_each_entry(iter, &node->u.string.expressions, siblings) {
587 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
588 if (ret)
589 return ret;
590 }
591 print_tabs(fd, depth);
592 fprintf(fd, "</string>\n");
593 break;
594 case NODE_ENUMERATOR:
595 print_tabs(fd, depth);
596 fprintf(fd, "<enumerator");
597 if (node->u.enumerator.id)
598 fprintf(fd, " id=\"%s\"", node->u.enumerator.id);
599 fprintf(fd, ">\n");
48a01768
MD
600 cds_list_for_each_entry(iter, &node->u.enumerator.values, siblings) {
601 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
7de8808c
MD
602 if (ret)
603 return ret;
604 }
605 print_tabs(fd, depth);
48a01768 606 fprintf(fd, "</enumerator>\n");
7de8808c
MD
607 break;
608 case NODE_ENUM:
609 print_tabs(fd, depth);
610 if (node->u._struct.name)
611 fprintf(fd, "<enum name=\"%s\">\n",
612 node->u._enum.enum_id);
613 else
614 fprintf(fd, "<enum >\n");
615 depth++;
616
3e11b713 617 if (node->u._enum.container_type) {
7de8808c 618 print_tabs(fd, depth);
48a01768 619 fprintf(fd, "<container_type>\n");
6743829a
MD
620 ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type);
621 if (ret)
622 return ret;
7de8808c 623 print_tabs(fd, depth);
48a01768 624 fprintf(fd, "</container_type>\n");
7de8808c
MD
625 }
626
627 print_tabs(fd, depth);
48a01768 628 fprintf(fd, "<enumerator_list>\n");
7de8808c
MD
629 cds_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
630 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
631 if (ret)
632 return ret;
633 }
634 print_tabs(fd, depth);
48a01768 635 fprintf(fd, "</enumerator_list>\n");
7de8808c
MD
636
637 depth--;
638 print_tabs(fd, depth);
639 fprintf(fd, "</enum>\n");
640 break;
641 case NODE_STRUCT_OR_VARIANT_DECLARATION:
3e11b713
MD
642 ret = ctf_visitor_print_xml(fd, depth,
643 node->u.struct_or_variant_declaration.type_specifier_list);
644 if (ret)
645 return ret;
7de8808c
MD
646
647 print_tabs(fd, depth);
3e11b713 648 fprintf(fd, "<type_declarator_list>\n");
7de8808c
MD
649 cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
650 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
651 if (ret)
652 return ret;
653 }
654 print_tabs(fd, depth);
3e11b713 655 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
656 break;
657 case NODE_VARIANT:
658 print_tabs(fd, depth);
659 fprintf(fd, "<variant");
660 if (node->u.variant.name)
661 fprintf(fd, " name=\"%s\"", node->u.variant.name);
662 if (node->u.variant.choice)
663 fprintf(fd, " choice=\"%s\"", node->u.variant.choice);
664 fprintf(fd, ">\n");
665 cds_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
666 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
667 if (ret)
668 return ret;
669 }
670 print_tabs(fd, depth);
671 fprintf(fd, "</variant>\n");
672 break;
673 case NODE_STRUCT:
674 print_tabs(fd, depth);
675 if (node->u._struct.name)
676 fprintf(fd, "<struct name=\"%s\">\n",
677 node->u._struct.name);
678 else
679 fprintf(fd, "<struct>\n");
680 cds_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) {
681 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
682 if (ret)
683 return ret;
684 }
685 print_tabs(fd, depth);
686 fprintf(fd, "</struct>\n");
b7e35bad
MD
687 if (!cds_list_empty(&node->u._struct.min_align)) {
688 print_tabs(fd, depth);
689 fprintf(fd, "<align>\n");
690 cds_list_for_each_entry(iter, &node->u._struct.min_align, siblings) {
691 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
692 if (ret)
693 return ret;
694 }
695 print_tabs(fd, depth);
696 fprintf(fd, "</align>\n");
697 }
7de8808c
MD
698 break;
699
700 case NODE_UNKNOWN:
701 default:
702 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
703 (int) node->type);
704 return -EINVAL;
705 }
706 return ret;
707}
This page took 0.052246 seconds and 4 git commands to generate.