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