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> |
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 |
35 | static |
36 | void 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 | 44 | static |
7de8808c MD |
45 | int 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 |
119 | static |
120 | int 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 | 137 | static |
7de8808c MD |
138 | int 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 | 273 | static |
7de8808c MD |
274 | int 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 | } | |
7c7835b0 MD |
316 | if (node->u.type_declarator.u.nested.abstract_array) { |
317 | print_tabs(fd, depth); | |
318 | fprintf(fd, "<length>\n"); | |
319 | print_tabs(fd, depth); | |
320 | fprintf(fd, "</length>\n"); | |
321 | } else if (!cds_list_empty(&node->u.type_declarator.u.nested.length)) { | |
7de8808c MD |
322 | print_tabs(fd, depth); |
323 | fprintf(fd, "<length>\n"); | |
98df1c9f MD |
324 | cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length, |
325 | siblings) { | |
326 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
327 | if (ret) | |
328 | return ret; | |
329 | } | |
7de8808c MD |
330 | print_tabs(fd, depth); |
331 | fprintf(fd, "</length>\n"); | |
332 | } | |
7de8808c MD |
333 | if (node->u.type_declarator.bitfield_len) { |
334 | print_tabs(fd, depth); | |
335 | fprintf(fd, "<bitfield_len>\n"); | |
336 | ret = ctf_visitor_print_xml(fd, depth + 1, | |
337 | node->u.type_declarator.bitfield_len); | |
338 | if (ret) | |
339 | return ret; | |
340 | print_tabs(fd, depth); | |
341 | fprintf(fd, "</bitfield_len>\n"); | |
342 | } | |
343 | break; | |
344 | case TYPEDEC_UNKNOWN: | |
345 | default: | |
346 | fprintf(stderr, "[error] %s: unknown type declarator %d\n", __func__, | |
347 | (int) node->u.type_declarator.type); | |
348 | return -EINVAL; | |
349 | } | |
350 | ||
351 | depth--; | |
352 | print_tabs(fd, depth); | |
353 | fprintf(fd, "</type_declarator>\n"); | |
354 | return 0; | |
355 | } | |
356 | ||
357 | int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node) | |
358 | { | |
359 | int ret = 0; | |
360 | struct ctf_node *iter; | |
361 | ||
362 | switch (node->type) { | |
363 | case NODE_ROOT: | |
364 | print_tabs(fd, depth); | |
365 | fprintf(fd, "<root>\n"); | |
3e11b713 | 366 | cds_list_for_each_entry(iter, &node->u.root.declaration_list, |
7de8808c MD |
367 | siblings) { |
368 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
369 | if (ret) | |
370 | return ret; | |
371 | } | |
7de8808c MD |
372 | cds_list_for_each_entry(iter, &node->u.root.trace, siblings) { |
373 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
374 | if (ret) | |
375 | return ret; | |
376 | } | |
377 | cds_list_for_each_entry(iter, &node->u.root.stream, siblings) { | |
378 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
379 | if (ret) | |
380 | return ret; | |
381 | } | |
382 | cds_list_for_each_entry(iter, &node->u.root.event, siblings) { | |
383 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
384 | if (ret) | |
385 | return ret; | |
386 | } | |
387 | print_tabs(fd, depth); | |
388 | fprintf(fd, "</root>\n"); | |
389 | break; | |
390 | ||
391 | case NODE_EVENT: | |
392 | print_tabs(fd, depth); | |
393 | fprintf(fd, "<event>\n"); | |
394 | cds_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) { | |
395 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
396 | if (ret) | |
397 | return ret; | |
398 | } | |
399 | print_tabs(fd, depth); | |
400 | fprintf(fd, "</event>\n"); | |
401 | break; | |
402 | case NODE_STREAM: | |
403 | print_tabs(fd, depth); | |
404 | fprintf(fd, "<stream>\n"); | |
405 | cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) { | |
406 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
407 | if (ret) | |
408 | return ret; | |
409 | } | |
410 | print_tabs(fd, depth); | |
411 | fprintf(fd, "</stream>\n"); | |
412 | break; | |
413 | case NODE_TRACE: | |
414 | print_tabs(fd, depth); | |
415 | fprintf(fd, "<trace>\n"); | |
416 | cds_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) { | |
417 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
418 | if (ret) | |
419 | return ret; | |
420 | } | |
421 | print_tabs(fd, depth); | |
422 | fprintf(fd, "</trace>\n"); | |
423 | break; | |
424 | ||
425 | case NODE_CTF_EXPRESSION: | |
426 | print_tabs(fd, depth); | |
427 | fprintf(fd, "<ctf_expression>\n"); | |
428 | depth++; | |
429 | print_tabs(fd, depth); | |
430 | fprintf(fd, "<left>\n"); | |
48a01768 MD |
431 | cds_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) { |
432 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
433 | if (ret) | |
434 | return ret; | |
435 | } | |
436 | ||
7de8808c MD |
437 | print_tabs(fd, depth); |
438 | fprintf(fd, "</left>\n"); | |
439 | ||
440 | print_tabs(fd, depth); | |
441 | fprintf(fd, "<right>\n"); | |
48a01768 MD |
442 | cds_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) { |
443 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
444 | if (ret) | |
445 | return ret; | |
446 | } | |
7de8808c MD |
447 | print_tabs(fd, depth); |
448 | fprintf(fd, "</right>\n"); | |
449 | depth--; | |
450 | print_tabs(fd, depth); | |
451 | fprintf(fd, "</ctf_expression>\n"); | |
452 | break; | |
453 | case NODE_UNARY_EXPRESSION: | |
454 | return ctf_visitor_print_unary_expression(fd, depth, node); | |
455 | ||
456 | case NODE_TYPEDEF: | |
457 | print_tabs(fd, depth); | |
458 | fprintf(fd, "<typedef>\n"); | |
459 | depth++; | |
3e11b713 MD |
460 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list); |
461 | if (ret) | |
462 | return ret; | |
7de8808c MD |
463 | |
464 | print_tabs(fd, depth); | |
3e11b713 | 465 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
466 | cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) { |
467 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
468 | if (ret) | |
469 | return ret; | |
470 | } | |
471 | print_tabs(fd, depth); | |
3e11b713 | 472 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
473 | depth--; |
474 | print_tabs(fd, depth); | |
475 | fprintf(fd, "</typedef>\n"); | |
476 | break; | |
477 | case NODE_TYPEALIAS_TARGET: | |
478 | print_tabs(fd, depth); | |
479 | fprintf(fd, "<target>\n"); | |
480 | depth++; | |
481 | ||
3e11b713 MD |
482 | ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list); |
483 | if (ret) | |
484 | return ret; | |
7de8808c MD |
485 | |
486 | print_tabs(fd, depth); | |
3e11b713 | 487 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
488 | cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) { |
489 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
490 | if (ret) | |
491 | return ret; | |
492 | } | |
493 | print_tabs(fd, depth); | |
3e11b713 | 494 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
495 | |
496 | depth--; | |
497 | print_tabs(fd, depth); | |
498 | fprintf(fd, "</target>\n"); | |
499 | break; | |
500 | case NODE_TYPEALIAS_ALIAS: | |
501 | print_tabs(fd, depth); | |
502 | fprintf(fd, "<alias>\n"); | |
503 | depth++; | |
504 | ||
3e11b713 MD |
505 | ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list); |
506 | if (ret) | |
507 | return ret; | |
7de8808c MD |
508 | |
509 | print_tabs(fd, depth); | |
3e11b713 | 510 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
511 | cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) { |
512 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
513 | if (ret) | |
514 | return ret; | |
515 | } | |
516 | print_tabs(fd, depth); | |
3e11b713 | 517 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
518 | |
519 | depth--; | |
520 | print_tabs(fd, depth); | |
521 | fprintf(fd, "</alias>\n"); | |
522 | break; | |
523 | case NODE_TYPEALIAS: | |
524 | print_tabs(fd, depth); | |
525 | fprintf(fd, "<typealias>\n"); | |
526 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.target); | |
527 | if (ret) | |
528 | return ret; | |
529 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u.typealias.alias); | |
530 | if (ret) | |
531 | return ret; | |
532 | print_tabs(fd, depth); | |
533 | fprintf(fd, "</typealias>\n"); | |
534 | break; | |
535 | ||
3e11b713 MD |
536 | case NODE_TYPE_SPECIFIER_LIST: |
537 | ret = ctf_visitor_print_type_specifier_list(fd, depth, node); | |
538 | if (ret) | |
539 | return ret; | |
540 | break; | |
541 | ||
7de8808c MD |
542 | case NODE_TYPE_SPECIFIER: |
543 | ret = ctf_visitor_print_type_specifier(fd, depth, node); | |
544 | if (ret) | |
545 | return ret; | |
546 | break; | |
547 | case NODE_POINTER: | |
548 | print_tabs(fd, depth); | |
549 | if (node->u.pointer.const_qualifier) | |
550 | fprintf(fd, "<const_pointer />\n"); | |
551 | else | |
552 | fprintf(fd, "<pointer />\n"); | |
553 | break; | |
554 | case NODE_TYPE_DECLARATOR: | |
555 | ret = ctf_visitor_print_type_declarator(fd, depth, node); | |
556 | if (ret) | |
557 | return ret; | |
558 | break; | |
559 | ||
560 | case NODE_FLOATING_POINT: | |
561 | print_tabs(fd, depth); | |
562 | fprintf(fd, "<floating_point>\n"); | |
563 | cds_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) { | |
564 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
565 | if (ret) | |
566 | return ret; | |
567 | } | |
568 | print_tabs(fd, depth); | |
569 | fprintf(fd, "</floating_point>\n"); | |
570 | break; | |
571 | case NODE_INTEGER: | |
572 | print_tabs(fd, depth); | |
573 | fprintf(fd, "<integer>\n"); | |
574 | cds_list_for_each_entry(iter, &node->u.integer.expressions, siblings) { | |
575 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
576 | if (ret) | |
577 | return ret; | |
578 | } | |
579 | print_tabs(fd, depth); | |
580 | fprintf(fd, "</integer>\n"); | |
581 | break; | |
582 | case NODE_STRING: | |
583 | print_tabs(fd, depth); | |
584 | fprintf(fd, "<string>\n"); | |
585 | cds_list_for_each_entry(iter, &node->u.string.expressions, siblings) { | |
586 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
587 | if (ret) | |
588 | return ret; | |
589 | } | |
590 | print_tabs(fd, depth); | |
591 | fprintf(fd, "</string>\n"); | |
592 | break; | |
593 | case NODE_ENUMERATOR: | |
594 | print_tabs(fd, depth); | |
595 | fprintf(fd, "<enumerator"); | |
596 | if (node->u.enumerator.id) | |
597 | fprintf(fd, " id=\"%s\"", node->u.enumerator.id); | |
598 | fprintf(fd, ">\n"); | |
48a01768 MD |
599 | cds_list_for_each_entry(iter, &node->u.enumerator.values, siblings) { |
600 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
7de8808c MD |
601 | if (ret) |
602 | return ret; | |
603 | } | |
604 | print_tabs(fd, depth); | |
48a01768 | 605 | fprintf(fd, "</enumerator>\n"); |
7de8808c MD |
606 | break; |
607 | case NODE_ENUM: | |
608 | print_tabs(fd, depth); | |
609 | if (node->u._struct.name) | |
610 | fprintf(fd, "<enum name=\"%s\">\n", | |
611 | node->u._enum.enum_id); | |
612 | else | |
613 | fprintf(fd, "<enum >\n"); | |
614 | depth++; | |
615 | ||
3e11b713 | 616 | if (node->u._enum.container_type) { |
7de8808c | 617 | print_tabs(fd, depth); |
48a01768 | 618 | fprintf(fd, "<container_type>\n"); |
6743829a MD |
619 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type); |
620 | if (ret) | |
621 | return ret; | |
7de8808c | 622 | print_tabs(fd, depth); |
48a01768 | 623 | fprintf(fd, "</container_type>\n"); |
7de8808c MD |
624 | } |
625 | ||
626 | print_tabs(fd, depth); | |
48a01768 | 627 | fprintf(fd, "<enumerator_list>\n"); |
7de8808c MD |
628 | cds_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) { |
629 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
630 | if (ret) | |
631 | return ret; | |
632 | } | |
633 | print_tabs(fd, depth); | |
48a01768 | 634 | fprintf(fd, "</enumerator_list>\n"); |
7de8808c MD |
635 | |
636 | depth--; | |
637 | print_tabs(fd, depth); | |
638 | fprintf(fd, "</enum>\n"); | |
639 | break; | |
640 | case NODE_STRUCT_OR_VARIANT_DECLARATION: | |
3e11b713 MD |
641 | ret = ctf_visitor_print_xml(fd, depth, |
642 | node->u.struct_or_variant_declaration.type_specifier_list); | |
643 | if (ret) | |
644 | return ret; | |
7de8808c MD |
645 | |
646 | print_tabs(fd, depth); | |
3e11b713 | 647 | fprintf(fd, "<type_declarator_list>\n"); |
7de8808c MD |
648 | cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) { |
649 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
650 | if (ret) | |
651 | return ret; | |
652 | } | |
653 | print_tabs(fd, depth); | |
3e11b713 | 654 | fprintf(fd, "</type_declarator_list>\n"); |
7de8808c MD |
655 | break; |
656 | case NODE_VARIANT: | |
657 | print_tabs(fd, depth); | |
658 | fprintf(fd, "<variant"); | |
659 | if (node->u.variant.name) | |
660 | fprintf(fd, " name=\"%s\"", node->u.variant.name); | |
661 | if (node->u.variant.choice) | |
662 | fprintf(fd, " choice=\"%s\"", node->u.variant.choice); | |
663 | fprintf(fd, ">\n"); | |
664 | cds_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) { | |
665 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
666 | if (ret) | |
667 | return ret; | |
668 | } | |
669 | print_tabs(fd, depth); | |
670 | fprintf(fd, "</variant>\n"); | |
671 | break; | |
672 | case NODE_STRUCT: | |
673 | print_tabs(fd, depth); | |
674 | if (node->u._struct.name) | |
675 | fprintf(fd, "<struct name=\"%s\">\n", | |
676 | node->u._struct.name); | |
677 | else | |
678 | fprintf(fd, "<struct>\n"); | |
679 | cds_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) { | |
680 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
681 | if (ret) | |
682 | return ret; | |
683 | } | |
684 | print_tabs(fd, depth); | |
685 | fprintf(fd, "</struct>\n"); | |
b7e35bad MD |
686 | if (!cds_list_empty(&node->u._struct.min_align)) { |
687 | print_tabs(fd, depth); | |
688 | fprintf(fd, "<align>\n"); | |
689 | cds_list_for_each_entry(iter, &node->u._struct.min_align, siblings) { | |
690 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); | |
691 | if (ret) | |
692 | return ret; | |
693 | } | |
694 | print_tabs(fd, depth); | |
695 | fprintf(fd, "</align>\n"); | |
696 | } | |
7de8808c MD |
697 | break; |
698 | ||
699 | case NODE_UNKNOWN: | |
700 | default: | |
701 | fprintf(stderr, "[error] %s: unknown node type %d\n", __func__, | |
702 | (int) node->type); | |
703 | return -EINVAL; | |
704 | } | |
705 | return ret; | |
706 | } |