Commit | Line | Data |
---|---|---|
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> |
fe41395a | 27 | #include <babeltrace/list.h> |
7de8808c MD |
28 | #include "ctf-scanner.h" |
29 | #include "ctf-parser.h" | |
30 | #include "ctf-ast.h" | |
31 | ||
34f7b02c | 32 | #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args) |
7de8808c | 33 | |
67905e42 MD |
34 | static |
35 | void print_tabs(FILE *fd, int depth) | |
7de8808c MD |
36 | { |
37 | int i; | |
38 | ||
39 | for (i = 0; i < depth; i++) | |
40 | fprintf(fd, "\t"); | |
41 | } | |
42 | ||
67905e42 | 43 | static |
7de8808c MD |
44 | int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *node) |
45 | { | |
46 | int ret = 0; | |
47 | ||
48a01768 MD |
48 | switch (node->u.unary_expression.link) { |
49 | case UNARY_LINK_UNKNOWN: | |
50 | break; | |
51 | case UNARY_DOTLINK: | |
52 | print_tabs(fd, depth); | |
53 | fprintf(fd, "<dotlink/>\n"); | |
54 | break; | |
55 | case UNARY_ARROWLINK: | |
56 | print_tabs(fd, depth); | |
57 | fprintf(fd, "<arrowlink/>\n"); | |
58 | break; | |
59 | case UNARY_DOTDOTDOT: | |
60 | print_tabs(fd, depth); | |
61 | fprintf(fd, "<dotdotdot/>\n"); | |
62 | break; | |
63 | default: | |
64 | fprintf(stderr, "[error] %s: unknown expression link type %d\n", __func__, | |
65 | (int) node->u.unary_expression.link); | |
66 | return -EINVAL; | |
67 | } | |
68 | ||
7de8808c MD |
69 | switch (node->u.unary_expression.type) { |
70 | case UNARY_STRING: | |
71 | print_tabs(fd, depth); | |
72 | fprintf(fd, "<unary_expression value="); | |
73 | fprintf(fd, "\"%s\"", node->u.unary_expression.u.string); | |
48a01768 | 74 | fprintf(fd, " />\n"); |
7de8808c MD |
75 | break; |
76 | case UNARY_SIGNED_CONSTANT: | |
77 | print_tabs(fd, depth); | |
78 | fprintf(fd, "<unary_expression value="); | |
380d60b1 | 79 | fprintf(fd, "%" PRId64, node->u.unary_expression.u.signed_constant); |
48a01768 | 80 | fprintf(fd, " />\n"); |
7de8808c MD |
81 | break; |
82 | case UNARY_UNSIGNED_CONSTANT: | |
83 | print_tabs(fd, depth); | |
84 | fprintf(fd, "<unary_expression value="); | |
380d60b1 | 85 | fprintf(fd, "%" PRIu64, node->u.unary_expression.u.signed_constant); |
48a01768 | 86 | fprintf(fd, " />\n"); |
7de8808c MD |
87 | break; |
88 | case UNARY_SBRAC: | |
89 | print_tabs(fd, depth); | |
4759bcf5 | 90 | fprintf(fd, "<unary_expression_sbrac>\n"); |
7de8808c MD |
91 | ret = ctf_visitor_print_unary_expression(fd, depth + 1, |
92 | node->u.unary_expression.u.sbrac_exp); | |
93 | if (ret) | |
94 | return ret; | |
95 | print_tabs(fd, depth); | |
4759bcf5 | 96 | fprintf(fd, "</unary_expression_sbrac>\n"); |
7de8808c | 97 | break; |
48a01768 MD |
98 | case UNARY_NESTED: |
99 | print_tabs(fd, depth); | |
4759bcf5 | 100 | fprintf(fd, "<unary_expression_nested>\n"); |
48a01768 MD |
101 | ret = ctf_visitor_print_unary_expression(fd, depth + 1, |
102 | node->u.unary_expression.u.nested_exp); | |
103 | if (ret) | |
104 | return ret; | |
105 | print_tabs(fd, depth); | |
4759bcf5 | 106 | fprintf(fd, "</unary_expression_nested>\n"); |
48a01768 | 107 | break; |
7de8808c MD |
108 | |
109 | case UNARY_UNKNOWN: | |
110 | default: | |
111 | fprintf(stderr, "[error] %s: unknown expression type %d\n", __func__, | |
112 | (int) node->u.unary_expression.type); | |
113 | return -EINVAL; | |
114 | } | |
7de8808c MD |
115 | return 0; |
116 | } | |
117 | ||
3e11b713 MD |
118 | static |
119 | int ctf_visitor_print_type_specifier_list(FILE *fd, int depth, struct ctf_node *node) | |
120 | { | |
121 | struct ctf_node *iter; | |
122 | int ret; | |
123 | ||
124 | print_tabs(fd, depth); | |
125 | fprintf(fd, "<type_specifier_list>\n"); | |
126 | cds_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) { | |
127 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
128 | if (ret) | |
129 | return ret; | |
130 | } | |
131 | print_tabs(fd, depth); | |
132 | fprintf(fd, "</type_specifier_list>\n"); | |
133 | return 0; | |
134 | } | |
135 | ||
67905e42 | 136 | static |
7de8808c MD |
137 | int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node) |
138 | { | |
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: | |
156 | fprintf(fd, "<type_specifier \""); | |
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: | |
223 | return ctf_visitor_print_xml(fd, depth, node->u.type_specifier.node); | |
224 | case TYPESPEC_UNKNOWN: | |
225 | default: | |
226 | fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__, | |
227 | (int) node->u.type_specifier.type); | |
228 | return -EINVAL; | |
229 | } | |
7de8808c | 230 | |
3e11b713 MD |
231 | switch (node->u.type_specifier.type) { |
232 | case TYPESPEC_VOID: | |
233 | case TYPESPEC_CHAR: | |
234 | case TYPESPEC_SHORT: | |
235 | case TYPESPEC_INT: | |
236 | case TYPESPEC_LONG: | |
237 | case TYPESPEC_FLOAT: | |
238 | case TYPESPEC_DOUBLE: | |
239 | case TYPESPEC_SIGNED: | |
240 | case TYPESPEC_UNSIGNED: | |
241 | case TYPESPEC_BOOL: | |
242 | case TYPESPEC_COMPLEX: | |
243 | case TYPESPEC_IMAGINARY: | |
244 | case TYPESPEC_CONST: | |
245 | case TYPESPEC_ID_TYPE: | |
246 | fprintf(fd, "\"/>\n"); | |
247 | break; | |
248 | case TYPESPEC_FLOATING_POINT: | |
249 | case TYPESPEC_INTEGER: | |
250 | case TYPESPEC_STRING: | |
251 | case TYPESPEC_STRUCT: | |
252 | case TYPESPEC_VARIANT: | |
253 | case TYPESPEC_ENUM: | |
254 | print_tabs(fd, depth); | |
255 | fprintf(fd, "</type_specifier>\n"); | |
256 | depth--; | |
257 | break; | |
7de8808c MD |
258 | case TYPESPEC_UNKNOWN: |
259 | default: | |
260 | fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__, | |
261 | (int) node->u.type_specifier.type); | |
262 | return -EINVAL; | |
263 | } | |
3e11b713 | 264 | |
7de8808c MD |
265 | return 0; |
266 | } | |
267 | ||
67905e42 | 268 | static |
7de8808c MD |
269 | int ctf_visitor_print_type_declarator(FILE *fd, int depth, struct ctf_node *node) |
270 | { | |
271 | int ret = 0; | |
272 | struct ctf_node *iter; | |
273 | ||
274 | print_tabs(fd, depth); | |
275 | fprintf(fd, "<type_declarator>\n"); | |
276 | depth++; | |
277 | ||
48a01768 MD |
278 | if (!cds_list_empty(&node->u.type_declarator.pointers)) { |
279 | print_tabs(fd, depth); | |
280 | fprintf(fd, "<pointers>\n"); | |
281 | cds_list_for_each_entry(iter, &node->u.type_declarator.pointers, | |
282 | siblings) { | |
283 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
284 | if (ret) | |
285 | return ret; | |
286 | } | |
287 | print_tabs(fd, depth); | |
288 | fprintf(fd, "</pointers>\n"); | |
7de8808c | 289 | } |
7de8808c MD |
290 | |
291 | switch (node->u.type_declarator.type) { | |
292 | case TYPEDEC_ID: | |
0009a725 MD |
293 | if (node->u.type_declarator.u.id) { |
294 | print_tabs(fd, depth); | |
295 | fprintf(fd, "<id \""); | |
296 | fprintf(fd, "%s", node->u.type_declarator.u.id); | |
297 | fprintf(fd, "\" />\n"); | |
298 | } | |
7de8808c MD |
299 | break; |
300 | case TYPEDEC_NESTED: | |
301 | if (node->u.type_declarator.u.nested.type_declarator) { | |
302 | print_tabs(fd, depth); | |
303 | fprintf(fd, "<type_declarator>\n"); | |
304 | ret = ctf_visitor_print_xml(fd, depth + 1, | |
305 | node->u.type_declarator.u.nested.type_declarator); | |
306 | if (ret) | |
307 | return ret; | |
308 | print_tabs(fd, depth); | |
309 | fprintf(fd, "</type_declarator>\n"); | |
310 | } | |
3e11b713 | 311 | if (node->u.type_declarator.u.nested.length) { |
7de8808c MD |
312 | print_tabs(fd, depth); |
313 | fprintf(fd, "<length>\n"); | |
3e11b713 | 314 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u.type_declarator.u.nested.length); |
7de8808c MD |
315 | if (ret) |
316 | return ret; | |
317 | print_tabs(fd, depth); | |
318 | fprintf(fd, "</length>\n"); | |
319 | } | |
320 | if (node->u.type_declarator.u.nested.abstract_array) { | |
321 | print_tabs(fd, depth); | |
322 | fprintf(fd, "<length>\n"); | |
323 | print_tabs(fd, depth); | |
324 | fprintf(fd, "</length>\n"); | |
325 | } | |
326 | if (node->u.type_declarator.bitfield_len) { | |
327 | print_tabs(fd, depth); | |
328 | fprintf(fd, "<bitfield_len>\n"); | |
329 | ret = ctf_visitor_print_xml(fd, depth + 1, | |
330 | node->u.type_declarator.bitfield_len); | |
331 | if (ret) | |
332 | return ret; | |
333 | print_tabs(fd, depth); | |
334 | fprintf(fd, "</bitfield_len>\n"); | |
335 | } | |
336 | break; | |
337 | case TYPEDEC_UNKNOWN: | |
338 | default: | |
339 | fprintf(stderr, "[error] %s: unknown type declarator %d\n", __func__, | |
340 | (int) node->u.type_declarator.type); | |
341 | return -EINVAL; | |
342 | } | |
343 | ||
344 | depth--; | |
345 | print_tabs(fd, depth); | |
346 | fprintf(fd, "</type_declarator>\n"); | |
347 | return 0; | |
348 | } | |
349 | ||
350 | int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node) | |
351 | { | |
352 | int ret = 0; | |
353 | struct ctf_node *iter; | |
354 | ||
355 | switch (node->type) { | |
356 | case NODE_ROOT: | |
357 | print_tabs(fd, depth); | |
358 | fprintf(fd, "<root>\n"); | |
3e11b713 | 359 | cds_list_for_each_entry(iter, &node->u.root.declaration_list, |
7de8808c MD |
360 | siblings) { |
361 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
362 | if (ret) | |
363 | return ret; | |
364 | } | |
7de8808c MD |
365 | cds_list_for_each_entry(iter, &node->u.root.trace, siblings) { |
366 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
367 | if (ret) | |
368 | return ret; | |
369 | } | |
370 | cds_list_for_each_entry(iter, &node->u.root.stream, siblings) { | |
371 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
372 | if (ret) | |
373 | return ret; | |
374 | } | |
375 | cds_list_for_each_entry(iter, &node->u.root.event, siblings) { | |
376 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
377 | if (ret) | |
378 | return ret; | |
379 | } | |
380 | print_tabs(fd, depth); | |
381 | fprintf(fd, "</root>\n"); | |
382 | break; | |
383 | ||
384 | case NODE_EVENT: | |
385 | print_tabs(fd, depth); | |
386 | fprintf(fd, "<event>\n"); | |
387 | cds_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) { | |
388 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
389 | if (ret) | |
390 | return ret; | |
391 | } | |
392 | print_tabs(fd, depth); | |
393 | fprintf(fd, "</event>\n"); | |
394 | break; | |
395 | case NODE_STREAM: | |
396 | print_tabs(fd, depth); | |
397 | fprintf(fd, "<stream>\n"); | |
398 | cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) { | |
399 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
400 | if (ret) | |
401 | return ret; | |
402 | } | |
403 | print_tabs(fd, depth); | |
404 | fprintf(fd, "</stream>\n"); | |
405 | break; | |
406 | case NODE_TRACE: | |
407 | print_tabs(fd, depth); | |
408 | fprintf(fd, "<trace>\n"); | |
409 | cds_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) { | |
410 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
411 | if (ret) | |
412 | return ret; | |
413 | } | |
414 | print_tabs(fd, depth); | |
415 | fprintf(fd, "</trace>\n"); | |
416 | break; | |
417 | ||
418 | case NODE_CTF_EXPRESSION: | |
419 | print_tabs(fd, depth); | |
420 | fprintf(fd, "<ctf_expression>\n"); | |
421 | depth++; | |
422 | print_tabs(fd, depth); | |
423 | fprintf(fd, "<left>\n"); | |
48a01768 MD |
424 | cds_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) { |
425 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
426 | if (ret) | |
427 | return ret; | |
428 | } | |
429 | ||
7de8808c MD |
430 | print_tabs(fd, depth); |
431 | fprintf(fd, "</left>\n"); | |
432 | ||
433 | print_tabs(fd, depth); | |
434 | fprintf(fd, "<right>\n"); | |
48a01768 MD |
435 | cds_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) { |
436 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
437 | if (ret) | |
438 | return ret; | |
439 | } | |
7de8808c MD |
440 | print_tabs(fd, depth); |
441 | fprintf(fd, "</right>\n"); | |
442 | depth--; | |
443 | print_tabs(fd, depth); | |
444 | fprintf(fd, "</ctf_expression>\n"); | |
445 | break; | |
446 | case NODE_UNARY_EXPRESSION: | |
447 | return ctf_visitor_print_unary_expression(fd, depth, node); | |
448 | ||
449 | case NODE_TYPEDEF: | |
450 | print_tabs(fd, depth); | |
451 | fprintf(fd, "<typedef>\n"); | |
452 | depth++; | |
3e11b713 MD |
453 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list); |
454 | if (ret) | |
455 | return ret; | |
7de8808c MD |
456 | |
457 | print_tabs(fd, depth); | |
3e11b713 | 458 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
459 | cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) { |
460 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
461 | if (ret) | |
462 | return ret; | |
463 | } | |
464 | print_tabs(fd, depth); | |
3e11b713 | 465 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
466 | depth--; |
467 | print_tabs(fd, depth); | |
468 | fprintf(fd, "</typedef>\n"); | |
469 | break; | |
470 | case NODE_TYPEALIAS_TARGET: | |
471 | print_tabs(fd, depth); | |
472 | fprintf(fd, "<target>\n"); | |
473 | depth++; | |
474 | ||
3e11b713 MD |
475 | ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list); |
476 | if (ret) | |
477 | return ret; | |
7de8808c MD |
478 | |
479 | print_tabs(fd, depth); | |
3e11b713 | 480 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
481 | cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) { |
482 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
483 | if (ret) | |
484 | return ret; | |
485 | } | |
486 | print_tabs(fd, depth); | |
3e11b713 | 487 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
488 | |
489 | depth--; | |
490 | print_tabs(fd, depth); | |
491 | fprintf(fd, "</target>\n"); | |
492 | break; | |
493 | case NODE_TYPEALIAS_ALIAS: | |
494 | print_tabs(fd, depth); | |
495 | fprintf(fd, "<alias>\n"); | |
496 | depth++; | |
497 | ||
3e11b713 MD |
498 | ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list); |
499 | if (ret) | |
500 | return ret; | |
7de8808c MD |
501 | |
502 | print_tabs(fd, depth); | |
3e11b713 | 503 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
504 | cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) { |
505 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
506 | if (ret) | |
507 | return ret; | |
508 | } | |
509 | print_tabs(fd, depth); | |
3e11b713 | 510 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
511 | |
512 | depth--; | |
513 | print_tabs(fd, depth); | |
514 | fprintf(fd, "</alias>\n"); | |
515 | break; | |
516 | case NODE_TYPEALIAS: | |
517 | print_tabs(fd, depth); | |
518 | fprintf(fd, "<typealias>\n"); | |
519 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.target); | |
520 | if (ret) | |
521 | return ret; | |
522 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.alias); | |
523 | if (ret) | |
524 | return ret; | |
525 | print_tabs(fd, depth); | |
526 | fprintf(fd, "</typealias>\n"); | |
527 | break; | |
528 | ||
3e11b713 MD |
529 | case NODE_TYPE_SPECIFIER_LIST: |
530 | ret = ctf_visitor_print_type_specifier_list(fd, depth, node); | |
531 | if (ret) | |
532 | return ret; | |
533 | break; | |
534 | ||
7de8808c MD |
535 | case NODE_TYPE_SPECIFIER: |
536 | ret = ctf_visitor_print_type_specifier(fd, depth, node); | |
537 | if (ret) | |
538 | return ret; | |
539 | break; | |
540 | case NODE_POINTER: | |
541 | print_tabs(fd, depth); | |
542 | if (node->u.pointer.const_qualifier) | |
543 | fprintf(fd, "<const_pointer />\n"); | |
544 | else | |
545 | fprintf(fd, "<pointer />\n"); | |
546 | break; | |
547 | case NODE_TYPE_DECLARATOR: | |
548 | ret = ctf_visitor_print_type_declarator(fd, depth, node); | |
549 | if (ret) | |
550 | return ret; | |
551 | break; | |
552 | ||
553 | case NODE_FLOATING_POINT: | |
554 | print_tabs(fd, depth); | |
555 | fprintf(fd, "<floating_point>\n"); | |
556 | cds_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) { | |
557 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
558 | if (ret) | |
559 | return ret; | |
560 | } | |
561 | print_tabs(fd, depth); | |
562 | fprintf(fd, "</floating_point>\n"); | |
563 | break; | |
564 | case NODE_INTEGER: | |
565 | print_tabs(fd, depth); | |
566 | fprintf(fd, "<integer>\n"); | |
567 | cds_list_for_each_entry(iter, &node->u.integer.expressions, siblings) { | |
568 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
569 | if (ret) | |
570 | return ret; | |
571 | } | |
572 | print_tabs(fd, depth); | |
573 | fprintf(fd, "</integer>\n"); | |
574 | break; | |
575 | case NODE_STRING: | |
576 | print_tabs(fd, depth); | |
577 | fprintf(fd, "<string>\n"); | |
578 | cds_list_for_each_entry(iter, &node->u.string.expressions, siblings) { | |
579 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
580 | if (ret) | |
581 | return ret; | |
582 | } | |
583 | print_tabs(fd, depth); | |
584 | fprintf(fd, "</string>\n"); | |
585 | break; | |
586 | case NODE_ENUMERATOR: | |
587 | print_tabs(fd, depth); | |
588 | fprintf(fd, "<enumerator"); | |
589 | if (node->u.enumerator.id) | |
590 | fprintf(fd, " id=\"%s\"", node->u.enumerator.id); | |
591 | fprintf(fd, ">\n"); | |
48a01768 MD |
592 | cds_list_for_each_entry(iter, &node->u.enumerator.values, siblings) { |
593 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
7de8808c MD |
594 | if (ret) |
595 | return ret; | |
596 | } | |
597 | print_tabs(fd, depth); | |
48a01768 | 598 | fprintf(fd, "</enumerator>\n"); |
7de8808c MD |
599 | break; |
600 | case NODE_ENUM: | |
601 | print_tabs(fd, depth); | |
602 | if (node->u._struct.name) | |
603 | fprintf(fd, "<enum name=\"%s\">\n", | |
604 | node->u._enum.enum_id); | |
605 | else | |
606 | fprintf(fd, "<enum >\n"); | |
607 | depth++; | |
608 | ||
3e11b713 | 609 | if (node->u._enum.container_type) { |
7de8808c | 610 | print_tabs(fd, depth); |
48a01768 | 611 | fprintf(fd, "<container_type>\n"); |
6743829a MD |
612 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type); |
613 | if (ret) | |
614 | return ret; | |
7de8808c | 615 | print_tabs(fd, depth); |
48a01768 | 616 | fprintf(fd, "</container_type>\n"); |
7de8808c MD |
617 | } |
618 | ||
619 | print_tabs(fd, depth); | |
48a01768 | 620 | fprintf(fd, "<enumerator_list>\n"); |
7de8808c MD |
621 | cds_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) { |
622 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
623 | if (ret) | |
624 | return ret; | |
625 | } | |
626 | print_tabs(fd, depth); | |
48a01768 | 627 | fprintf(fd, "</enumerator_list>\n"); |
7de8808c MD |
628 | |
629 | depth--; | |
630 | print_tabs(fd, depth); | |
631 | fprintf(fd, "</enum>\n"); | |
632 | break; | |
633 | case NODE_STRUCT_OR_VARIANT_DECLARATION: | |
3e11b713 MD |
634 | ret = ctf_visitor_print_xml(fd, depth, |
635 | node->u.struct_or_variant_declaration.type_specifier_list); | |
636 | if (ret) | |
637 | return ret; | |
7de8808c MD |
638 | |
639 | print_tabs(fd, depth); | |
3e11b713 | 640 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
641 | cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) { |
642 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
643 | if (ret) | |
644 | return ret; | |
645 | } | |
646 | print_tabs(fd, depth); | |
3e11b713 | 647 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
648 | break; |
649 | case NODE_VARIANT: | |
650 | print_tabs(fd, depth); | |
651 | fprintf(fd, "<variant"); | |
652 | if (node->u.variant.name) | |
653 | fprintf(fd, " name=\"%s\"", node->u.variant.name); | |
654 | if (node->u.variant.choice) | |
655 | fprintf(fd, " choice=\"%s\"", node->u.variant.choice); | |
656 | fprintf(fd, ">\n"); | |
657 | cds_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) { | |
658 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
659 | if (ret) | |
660 | return ret; | |
661 | } | |
662 | print_tabs(fd, depth); | |
663 | fprintf(fd, "</variant>\n"); | |
664 | break; | |
665 | case NODE_STRUCT: | |
666 | print_tabs(fd, depth); | |
667 | if (node->u._struct.name) | |
668 | fprintf(fd, "<struct name=\"%s\">\n", | |
669 | node->u._struct.name); | |
670 | else | |
671 | fprintf(fd, "<struct>\n"); | |
672 | cds_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) { | |
673 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
674 | if (ret) | |
675 | return ret; | |
676 | } | |
677 | print_tabs(fd, depth); | |
678 | fprintf(fd, "</struct>\n"); | |
679 | break; | |
680 | ||
681 | case NODE_UNKNOWN: | |
682 | default: | |
683 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, | |
684 | (int) node->type); | |
685 | return -EINVAL; | |
686 | } | |
687 | return ret; | |
688 | } |