Add missing permission notice in each source file
[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 106 break;
48a01768
MD
107 case UNARY_NESTED:
108 print_tabs(fd, depth);
4759bcf5 109 fprintf(fd, "<unary_expression_nested>\n");
48a01768
MD
110 ret = ctf_visitor_print_unary_expression(fd, depth + 1,
111 node->u.unary_expression.u.nested_exp);
112 if (ret)
113 return ret;
114 print_tabs(fd, depth);
4759bcf5 115 fprintf(fd, "</unary_expression_nested>\n");
48a01768 116 break;
7de8808c
MD
117
118 case UNARY_UNKNOWN:
119 default:
120 fprintf(stderr, "[error] %s: unknown expression type %d\n", __func__,
121 (int) node->u.unary_expression.type);
122 return -EINVAL;
123 }
7de8808c
MD
124 return 0;
125}
126
3e11b713
MD
127static
128int ctf_visitor_print_type_specifier_list(FILE *fd, int depth, struct ctf_node *node)
129{
130 struct ctf_node *iter;
131 int ret;
132
133 print_tabs(fd, depth);
134 fprintf(fd, "<type_specifier_list>\n");
3122e6f0 135 bt_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
3e11b713
MD
136 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
137 if (ret)
138 return ret;
139 }
140 print_tabs(fd, depth);
141 fprintf(fd, "</type_specifier_list>\n");
142 return 0;
143}
144
67905e42 145static
7de8808c
MD
146int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
147{
a10a7e5b 148 int ret;
7de8808c 149 print_tabs(fd, depth);
3e11b713
MD
150
151 switch (node->u.type_specifier.type) {
152 case TYPESPEC_VOID:
153 case TYPESPEC_CHAR:
154 case TYPESPEC_SHORT:
155 case TYPESPEC_INT:
156 case TYPESPEC_LONG:
157 case TYPESPEC_FLOAT:
158 case TYPESPEC_DOUBLE:
159 case TYPESPEC_SIGNED:
160 case TYPESPEC_UNSIGNED:
161 case TYPESPEC_BOOL:
162 case TYPESPEC_COMPLEX:
163 case TYPESPEC_IMAGINARY:
164 case TYPESPEC_CONST:
165 case TYPESPEC_ID_TYPE:
a10a7e5b 166 fprintf(fd, "<type_specifier type=\"");
3e11b713
MD
167 break;
168 case TYPESPEC_FLOATING_POINT:
169 case TYPESPEC_INTEGER:
170 case TYPESPEC_STRING:
171 case TYPESPEC_STRUCT:
172 case TYPESPEC_VARIANT:
173 case TYPESPEC_ENUM:
174 fprintf(fd, "<type_specifier>\n");
175 depth++;
176 break;
177 case TYPESPEC_UNKNOWN:
178 default:
179 fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
180 (int) node->u.type_specifier.type);
181 return -EINVAL;
182 }
7de8808c
MD
183
184 switch (node->u.type_specifier.type) {
185 case TYPESPEC_VOID:
186 fprintf(fd, "void");
187 break;
188 case TYPESPEC_CHAR:
189 fprintf(fd, "char");
190 break;
191 case TYPESPEC_SHORT:
192 fprintf(fd, "short");
193 break;
194 case TYPESPEC_INT:
195 fprintf(fd, "int");
196 break;
197 case TYPESPEC_LONG:
198 fprintf(fd, "long");
199 break;
200 case TYPESPEC_FLOAT:
201 fprintf(fd, "float");
202 break;
203 case TYPESPEC_DOUBLE:
204 fprintf(fd, "double");
205 break;
206 case TYPESPEC_SIGNED:
207 fprintf(fd, "signed");
208 break;
209 case TYPESPEC_UNSIGNED:
210 fprintf(fd, "unsigned");
211 break;
212 case TYPESPEC_BOOL:
213 fprintf(fd, "bool");
214 break;
215 case TYPESPEC_COMPLEX:
3888a159
MD
216 fprintf(fd, "_Complex");
217 break;
218 case TYPESPEC_IMAGINARY:
219 fprintf(fd, "_Imaginary");
7de8808c
MD
220 break;
221 case TYPESPEC_CONST:
222 fprintf(fd, "const");
223 break;
224 case TYPESPEC_ID_TYPE:
225 fprintf(fd, "%s", node->u.type_specifier.id_type);
226 break;
3e11b713
MD
227 case TYPESPEC_FLOATING_POINT:
228 case TYPESPEC_INTEGER:
229 case TYPESPEC_STRING:
230 case TYPESPEC_STRUCT:
231 case TYPESPEC_VARIANT:
232 case TYPESPEC_ENUM:
a10a7e5b
SM
233 ret = ctf_visitor_print_xml(fd, depth, node->u.type_specifier.node);
234 if (ret)
235 return ret;
236 break;
3e11b713
MD
237 case TYPESPEC_UNKNOWN:
238 default:
239 fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
240 (int) node->u.type_specifier.type);
241 return -EINVAL;
242 }
7de8808c 243
3e11b713
MD
244 switch (node->u.type_specifier.type) {
245 case TYPESPEC_VOID:
246 case TYPESPEC_CHAR:
247 case TYPESPEC_SHORT:
248 case TYPESPEC_INT:
249 case TYPESPEC_LONG:
250 case TYPESPEC_FLOAT:
251 case TYPESPEC_DOUBLE:
252 case TYPESPEC_SIGNED:
253 case TYPESPEC_UNSIGNED:
254 case TYPESPEC_BOOL:
255 case TYPESPEC_COMPLEX:
256 case TYPESPEC_IMAGINARY:
257 case TYPESPEC_CONST:
258 case TYPESPEC_ID_TYPE:
259 fprintf(fd, "\"/>\n");
260 break;
261 case TYPESPEC_FLOATING_POINT:
262 case TYPESPEC_INTEGER:
263 case TYPESPEC_STRING:
264 case TYPESPEC_STRUCT:
265 case TYPESPEC_VARIANT:
266 case TYPESPEC_ENUM:
a10a7e5b 267 depth--;
3e11b713
MD
268 print_tabs(fd, depth);
269 fprintf(fd, "</type_specifier>\n");
3e11b713 270 break;
7de8808c
MD
271 case TYPESPEC_UNKNOWN:
272 default:
273 fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
274 (int) node->u.type_specifier.type);
275 return -EINVAL;
276 }
3e11b713 277
7de8808c
MD
278 return 0;
279}
280
67905e42 281static
7de8808c
MD
282int ctf_visitor_print_type_declarator(FILE *fd, int depth, struct ctf_node *node)
283{
284 int ret = 0;
285 struct ctf_node *iter;
286
287 print_tabs(fd, depth);
288 fprintf(fd, "<type_declarator>\n");
289 depth++;
290
3122e6f0 291 if (!bt_list_empty(&node->u.type_declarator.pointers)) {
48a01768
MD
292 print_tabs(fd, depth);
293 fprintf(fd, "<pointers>\n");
3122e6f0 294 bt_list_for_each_entry(iter, &node->u.type_declarator.pointers,
48a01768
MD
295 siblings) {
296 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
297 if (ret)
298 return ret;
299 }
300 print_tabs(fd, depth);
301 fprintf(fd, "</pointers>\n");
7de8808c 302 }
7de8808c
MD
303
304 switch (node->u.type_declarator.type) {
305 case TYPEDEC_ID:
0009a725
MD
306 if (node->u.type_declarator.u.id) {
307 print_tabs(fd, depth);
a10a7e5b 308 fprintf(fd, "<id name=\"");
0009a725
MD
309 fprintf(fd, "%s", node->u.type_declarator.u.id);
310 fprintf(fd, "\" />\n");
311 }
7de8808c
MD
312 break;
313 case TYPEDEC_NESTED:
314 if (node->u.type_declarator.u.nested.type_declarator) {
315 print_tabs(fd, depth);
316 fprintf(fd, "<type_declarator>\n");
317 ret = ctf_visitor_print_xml(fd, depth + 1,
318 node->u.type_declarator.u.nested.type_declarator);
319 if (ret)
320 return ret;
321 print_tabs(fd, depth);
322 fprintf(fd, "</type_declarator>\n");
323 }
7c7835b0
MD
324 if (node->u.type_declarator.u.nested.abstract_array) {
325 print_tabs(fd, depth);
326 fprintf(fd, "<length>\n");
327 print_tabs(fd, depth);
328 fprintf(fd, "</length>\n");
3122e6f0 329 } else if (!bt_list_empty(&node->u.type_declarator.u.nested.length)) {
7de8808c
MD
330 print_tabs(fd, depth);
331 fprintf(fd, "<length>\n");
3122e6f0 332 bt_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
98df1c9f
MD
333 siblings) {
334 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
335 if (ret)
336 return ret;
337 }
7de8808c
MD
338 print_tabs(fd, depth);
339 fprintf(fd, "</length>\n");
340 }
7de8808c
MD
341 if (node->u.type_declarator.bitfield_len) {
342 print_tabs(fd, depth);
343 fprintf(fd, "<bitfield_len>\n");
344 ret = ctf_visitor_print_xml(fd, depth + 1,
345 node->u.type_declarator.bitfield_len);
346 if (ret)
347 return ret;
348 print_tabs(fd, depth);
349 fprintf(fd, "</bitfield_len>\n");
350 }
351 break;
352 case TYPEDEC_UNKNOWN:
353 default:
354 fprintf(stderr, "[error] %s: unknown type declarator %d\n", __func__,
355 (int) node->u.type_declarator.type);
356 return -EINVAL;
357 }
358
359 depth--;
360 print_tabs(fd, depth);
361 fprintf(fd, "</type_declarator>\n");
362 return 0;
363}
364
365int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
366{
367 int ret = 0;
368 struct ctf_node *iter;
369
370 switch (node->type) {
371 case NODE_ROOT:
372 print_tabs(fd, depth);
373 fprintf(fd, "<root>\n");
3122e6f0 374 bt_list_for_each_entry(iter, &node->u.root.declaration_list,
7de8808c
MD
375 siblings) {
376 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
377 if (ret)
378 return ret;
379 }
3122e6f0 380 bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
7de8808c
MD
381 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
382 if (ret)
383 return ret;
384 }
3122e6f0 385 bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
7de8808c
MD
386 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
387 if (ret)
388 return ret;
389 }
3122e6f0 390 bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
7de8808c
MD
391 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
392 if (ret)
393 return ret;
394 }
395 print_tabs(fd, depth);
396 fprintf(fd, "</root>\n");
397 break;
398
399 case NODE_EVENT:
400 print_tabs(fd, depth);
401 fprintf(fd, "<event>\n");
3122e6f0 402 bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
7de8808c
MD
403 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
404 if (ret)
405 return ret;
406 }
407 print_tabs(fd, depth);
408 fprintf(fd, "</event>\n");
409 break;
410 case NODE_STREAM:
411 print_tabs(fd, depth);
412 fprintf(fd, "<stream>\n");
3122e6f0 413 bt_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
7de8808c
MD
414 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
415 if (ret)
416 return ret;
417 }
418 print_tabs(fd, depth);
419 fprintf(fd, "</stream>\n");
420 break;
e2c76a4d
MD
421 case NODE_ENV:
422 print_tabs(fd, depth);
423 fprintf(fd, "<env>\n");
3122e6f0 424 bt_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) {
e2c76a4d
MD
425 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
426 if (ret)
427 return ret;
428 }
429 print_tabs(fd, depth);
430 fprintf(fd, "</env>\n");
431 break;
7de8808c
MD
432 case NODE_TRACE:
433 print_tabs(fd, depth);
434 fprintf(fd, "<trace>\n");
3122e6f0 435 bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
7de8808c
MD
436 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
437 if (ret)
438 return ret;
439 }
440 print_tabs(fd, depth);
441 fprintf(fd, "</trace>\n");
442 break;
e2c76a4d
MD
443 case NODE_CLOCK:
444 print_tabs(fd, depth);
445 fprintf(fd, "<clock>\n");
3122e6f0 446 bt_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
e2c76a4d
MD
447 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
448 if (ret)
449 return ret;
450 }
451 print_tabs(fd, depth);
452 fprintf(fd, "</clock>\n");
453 break;
f133896d
MD
454 case NODE_CALLSITE:
455 print_tabs(fd, depth);
456 fprintf(fd, "<callsite>\n");
457 bt_list_for_each_entry(iter, &node->u.callsite.declaration_list, siblings) {
458 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
459 if (ret)
460 return ret;
461 }
462 print_tabs(fd, depth);
463 fprintf(fd, "</callsite>\n");
464 break;
e2c76a4d 465
7de8808c
MD
466
467 case NODE_CTF_EXPRESSION:
468 print_tabs(fd, depth);
469 fprintf(fd, "<ctf_expression>\n");
470 depth++;
471 print_tabs(fd, depth);
472 fprintf(fd, "<left>\n");
3122e6f0 473 bt_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) {
48a01768
MD
474 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
475 if (ret)
476 return ret;
477 }
478
7de8808c
MD
479 print_tabs(fd, depth);
480 fprintf(fd, "</left>\n");
481
482 print_tabs(fd, depth);
483 fprintf(fd, "<right>\n");
3122e6f0 484 bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
48a01768
MD
485 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
486 if (ret)
487 return ret;
488 }
7de8808c
MD
489 print_tabs(fd, depth);
490 fprintf(fd, "</right>\n");
491 depth--;
492 print_tabs(fd, depth);
493 fprintf(fd, "</ctf_expression>\n");
494 break;
495 case NODE_UNARY_EXPRESSION:
496 return ctf_visitor_print_unary_expression(fd, depth, node);
497
498 case NODE_TYPEDEF:
499 print_tabs(fd, depth);
500 fprintf(fd, "<typedef>\n");
501 depth++;
3e11b713
MD
502 ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list);
503 if (ret)
504 return ret;
7de8808c
MD
505
506 print_tabs(fd, depth);
3e11b713 507 fprintf(fd, "<type_declarator_list>\n");
3122e6f0 508 bt_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
7de8808c
MD
509 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
510 if (ret)
511 return ret;
512 }
513 print_tabs(fd, depth);
3e11b713 514 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
515 depth--;
516 print_tabs(fd, depth);
517 fprintf(fd, "</typedef>\n");
518 break;
519 case NODE_TYPEALIAS_TARGET:
520 print_tabs(fd, depth);
521 fprintf(fd, "<target>\n");
522 depth++;
523
3e11b713
MD
524 ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list);
525 if (ret)
526 return ret;
7de8808c
MD
527
528 print_tabs(fd, depth);
3e11b713 529 fprintf(fd, "<type_declarator_list>\n");
3122e6f0 530 bt_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
7de8808c
MD
531 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
532 if (ret)
533 return ret;
534 }
535 print_tabs(fd, depth);
3e11b713 536 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
537
538 depth--;
539 print_tabs(fd, depth);
540 fprintf(fd, "</target>\n");
541 break;
542 case NODE_TYPEALIAS_ALIAS:
543 print_tabs(fd, depth);
544 fprintf(fd, "<alias>\n");
545 depth++;
546
3e11b713
MD
547 ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list);
548 if (ret)
549 return ret;
7de8808c
MD
550
551 print_tabs(fd, depth);
3e11b713 552 fprintf(fd, "<type_declarator_list>\n");
3122e6f0 553 bt_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
7de8808c
MD
554 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
555 if (ret)
556 return ret;
557 }
558 print_tabs(fd, depth);
3e11b713 559 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
560
561 depth--;
562 print_tabs(fd, depth);
563 fprintf(fd, "</alias>\n");
564 break;
565 case NODE_TYPEALIAS:
566 print_tabs(fd, depth);
567 fprintf(fd, "<typealias>\n");
568 ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.target);
569 if (ret)
570 return ret;
571 ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.alias);
572 if (ret)
573 return ret;
574 print_tabs(fd, depth);
575 fprintf(fd, "</typealias>\n");
576 break;
577
3e11b713
MD
578 case NODE_TYPE_SPECIFIER_LIST:
579 ret = ctf_visitor_print_type_specifier_list(fd, depth, node);
580 if (ret)
581 return ret;
582 break;
583
7de8808c
MD
584 case NODE_TYPE_SPECIFIER:
585 ret = ctf_visitor_print_type_specifier(fd, depth, node);
586 if (ret)
587 return ret;
588 break;
589 case NODE_POINTER:
590 print_tabs(fd, depth);
591 if (node->u.pointer.const_qualifier)
592 fprintf(fd, "<const_pointer />\n");
593 else
594 fprintf(fd, "<pointer />\n");
595 break;
596 case NODE_TYPE_DECLARATOR:
597 ret = ctf_visitor_print_type_declarator(fd, depth, node);
598 if (ret)
599 return ret;
600 break;
601
602 case NODE_FLOATING_POINT:
603 print_tabs(fd, depth);
604 fprintf(fd, "<floating_point>\n");
3122e6f0 605 bt_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) {
7de8808c
MD
606 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
607 if (ret)
608 return ret;
609 }
610 print_tabs(fd, depth);
611 fprintf(fd, "</floating_point>\n");
612 break;
613 case NODE_INTEGER:
614 print_tabs(fd, depth);
615 fprintf(fd, "<integer>\n");
3122e6f0 616 bt_list_for_each_entry(iter, &node->u.integer.expressions, siblings) {
7de8808c
MD
617 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
618 if (ret)
619 return ret;
620 }
621 print_tabs(fd, depth);
622 fprintf(fd, "</integer>\n");
623 break;
624 case NODE_STRING:
625 print_tabs(fd, depth);
626 fprintf(fd, "<string>\n");
3122e6f0 627 bt_list_for_each_entry(iter, &node->u.string.expressions, siblings) {
7de8808c
MD
628 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
629 if (ret)
630 return ret;
631 }
632 print_tabs(fd, depth);
633 fprintf(fd, "</string>\n");
634 break;
635 case NODE_ENUMERATOR:
636 print_tabs(fd, depth);
637 fprintf(fd, "<enumerator");
638 if (node->u.enumerator.id)
639 fprintf(fd, " id=\"%s\"", node->u.enumerator.id);
640 fprintf(fd, ">\n");
3122e6f0 641 bt_list_for_each_entry(iter, &node->u.enumerator.values, siblings) {
48a01768 642 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
7de8808c
MD
643 if (ret)
644 return ret;
645 }
646 print_tabs(fd, depth);
48a01768 647 fprintf(fd, "</enumerator>\n");
7de8808c
MD
648 break;
649 case NODE_ENUM:
650 print_tabs(fd, depth);
651 if (node->u._struct.name)
652 fprintf(fd, "<enum name=\"%s\">\n",
653 node->u._enum.enum_id);
654 else
655 fprintf(fd, "<enum >\n");
656 depth++;
657
3e11b713 658 if (node->u._enum.container_type) {
7de8808c 659 print_tabs(fd, depth);
48a01768 660 fprintf(fd, "<container_type>\n");
6743829a
MD
661 ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type);
662 if (ret)
663 return ret;
7de8808c 664 print_tabs(fd, depth);
48a01768 665 fprintf(fd, "</container_type>\n");
7de8808c
MD
666 }
667
668 print_tabs(fd, depth);
48a01768 669 fprintf(fd, "<enumerator_list>\n");
3122e6f0 670 bt_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
7de8808c
MD
671 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
672 if (ret)
673 return ret;
674 }
675 print_tabs(fd, depth);
48a01768 676 fprintf(fd, "</enumerator_list>\n");
7de8808c
MD
677
678 depth--;
679 print_tabs(fd, depth);
680 fprintf(fd, "</enum>\n");
681 break;
682 case NODE_STRUCT_OR_VARIANT_DECLARATION:
3e11b713
MD
683 ret = ctf_visitor_print_xml(fd, depth,
684 node->u.struct_or_variant_declaration.type_specifier_list);
685 if (ret)
686 return ret;
7de8808c
MD
687
688 print_tabs(fd, depth);
3e11b713 689 fprintf(fd, "<type_declarator_list>\n");
3122e6f0 690 bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
7de8808c
MD
691 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
692 if (ret)
693 return ret;
694 }
695 print_tabs(fd, depth);
3e11b713 696 fprintf(fd, "</type_declarator_list>\n");
7de8808c
MD
697 break;
698 case NODE_VARIANT:
699 print_tabs(fd, depth);
700 fprintf(fd, "<variant");
701 if (node->u.variant.name)
702 fprintf(fd, " name=\"%s\"", node->u.variant.name);
703 if (node->u.variant.choice)
704 fprintf(fd, " choice=\"%s\"", node->u.variant.choice);
705 fprintf(fd, ">\n");
3122e6f0 706 bt_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
7de8808c
MD
707 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
708 if (ret)
709 return ret;
710 }
711 print_tabs(fd, depth);
712 fprintf(fd, "</variant>\n");
713 break;
714 case NODE_STRUCT:
715 print_tabs(fd, depth);
716 if (node->u._struct.name)
717 fprintf(fd, "<struct name=\"%s\">\n",
718 node->u._struct.name);
719 else
720 fprintf(fd, "<struct>\n");
3122e6f0 721 bt_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) {
7de8808c
MD
722 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
723 if (ret)
724 return ret;
725 }
726 print_tabs(fd, depth);
727 fprintf(fd, "</struct>\n");
3122e6f0 728 if (!bt_list_empty(&node->u._struct.min_align)) {
b7e35bad
MD
729 print_tabs(fd, depth);
730 fprintf(fd, "<align>\n");
3122e6f0 731 bt_list_for_each_entry(iter, &node->u._struct.min_align, siblings) {
b7e35bad
MD
732 ret = ctf_visitor_print_xml(fd, depth + 1, iter);
733 if (ret)
734 return ret;
735 }
736 print_tabs(fd, depth);
737 fprintf(fd, "</align>\n");
738 }
7de8808c
MD
739 break;
740
741 case NODE_UNKNOWN:
742 default:
743 fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
744 (int) node->type);
745 return -EINVAL;
746 }
747 return ret;
748}
This page took 0.095327 seconds and 4 git commands to generate.