| 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 | * 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. |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <unistd.h> |
| 29 | #include <string.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <assert.h> |
| 32 | #include <glib.h> |
| 33 | #include <inttypes.h> |
| 34 | #include <errno.h> |
| 35 | #include <babeltrace/babeltrace-internal.h> |
| 36 | #include <babeltrace/list.h> |
| 37 | #include "ctf-scanner.h" |
| 38 | #include "ctf-parser.h" |
| 39 | #include "ctf-ast.h" |
| 40 | |
| 41 | #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args) |
| 42 | |
| 43 | static |
| 44 | void print_tabs(FILE *fd, int depth) |
| 45 | { |
| 46 | int i; |
| 47 | |
| 48 | for (i = 0; i < depth; i++) |
| 49 | fprintf(fd, "\t"); |
| 50 | } |
| 51 | |
| 52 | static |
| 53 | int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *node) |
| 54 | { |
| 55 | int ret = 0; |
| 56 | |
| 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 | |
| 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); |
| 83 | fprintf(fd, " />\n"); |
| 84 | break; |
| 85 | case UNARY_SIGNED_CONSTANT: |
| 86 | print_tabs(fd, depth); |
| 87 | fprintf(fd, "<unary_expression value=\""); |
| 88 | fprintf(fd, "%" PRId64, node->u.unary_expression.u.signed_constant); |
| 89 | fprintf(fd, "\" />\n"); |
| 90 | break; |
| 91 | case UNARY_UNSIGNED_CONSTANT: |
| 92 | print_tabs(fd, depth); |
| 93 | fprintf(fd, "<unary_expression value=\""); |
| 94 | fprintf(fd, "%" PRIu64, node->u.unary_expression.u.signed_constant); |
| 95 | fprintf(fd, "\" />\n"); |
| 96 | break; |
| 97 | case UNARY_SBRAC: |
| 98 | print_tabs(fd, depth); |
| 99 | fprintf(fd, "<unary_expression_sbrac>\n"); |
| 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); |
| 105 | fprintf(fd, "</unary_expression_sbrac>\n"); |
| 106 | break; |
| 107 | case UNARY_NESTED: |
| 108 | print_tabs(fd, depth); |
| 109 | fprintf(fd, "<unary_expression_nested>\n"); |
| 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); |
| 115 | fprintf(fd, "</unary_expression_nested>\n"); |
| 116 | break; |
| 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 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static |
| 128 | int 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"); |
| 135 | bt_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) { |
| 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 | |
| 145 | static |
| 146 | int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node) |
| 147 | { |
| 148 | int ret; |
| 149 | print_tabs(fd, depth); |
| 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: |
| 166 | fprintf(fd, "<type_specifier type=\""); |
| 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 | } |
| 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: |
| 216 | fprintf(fd, "_Complex"); |
| 217 | break; |
| 218 | case TYPESPEC_IMAGINARY: |
| 219 | fprintf(fd, "_Imaginary"); |
| 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; |
| 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: |
| 233 | ret = ctf_visitor_print_xml(fd, depth, node->u.type_specifier.node); |
| 234 | if (ret) |
| 235 | return ret; |
| 236 | break; |
| 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 | } |
| 243 | |
| 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: |
| 267 | depth--; |
| 268 | print_tabs(fd, depth); |
| 269 | fprintf(fd, "</type_specifier>\n"); |
| 270 | break; |
| 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 | } |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | static |
| 282 | int 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 | |
| 291 | if (!bt_list_empty(&node->u.type_declarator.pointers)) { |
| 292 | print_tabs(fd, depth); |
| 293 | fprintf(fd, "<pointers>\n"); |
| 294 | bt_list_for_each_entry(iter, &node->u.type_declarator.pointers, |
| 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"); |
| 302 | } |
| 303 | |
| 304 | switch (node->u.type_declarator.type) { |
| 305 | case TYPEDEC_ID: |
| 306 | if (node->u.type_declarator.u.id) { |
| 307 | print_tabs(fd, depth); |
| 308 | fprintf(fd, "<id name=\""); |
| 309 | fprintf(fd, "%s", node->u.type_declarator.u.id); |
| 310 | fprintf(fd, "\" />\n"); |
| 311 | } |
| 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 | } |
| 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"); |
| 329 | } else if (!bt_list_empty(&node->u.type_declarator.u.nested.length)) { |
| 330 | print_tabs(fd, depth); |
| 331 | fprintf(fd, "<length>\n"); |
| 332 | bt_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length, |
| 333 | siblings) { |
| 334 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 335 | if (ret) |
| 336 | return ret; |
| 337 | } |
| 338 | print_tabs(fd, depth); |
| 339 | fprintf(fd, "</length>\n"); |
| 340 | } |
| 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 | |
| 365 | int 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"); |
| 374 | bt_list_for_each_entry(iter, &node->u.root.declaration_list, |
| 375 | siblings) { |
| 376 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 377 | if (ret) |
| 378 | return ret; |
| 379 | } |
| 380 | bt_list_for_each_entry(iter, &node->u.root.trace, siblings) { |
| 381 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 382 | if (ret) |
| 383 | return ret; |
| 384 | } |
| 385 | bt_list_for_each_entry(iter, &node->u.root.stream, siblings) { |
| 386 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 387 | if (ret) |
| 388 | return ret; |
| 389 | } |
| 390 | bt_list_for_each_entry(iter, &node->u.root.event, siblings) { |
| 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"); |
| 402 | bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) { |
| 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"); |
| 413 | bt_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) { |
| 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; |
| 421 | case NODE_ENV: |
| 422 | print_tabs(fd, depth); |
| 423 | fprintf(fd, "<env>\n"); |
| 424 | bt_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) { |
| 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; |
| 432 | case NODE_TRACE: |
| 433 | print_tabs(fd, depth); |
| 434 | fprintf(fd, "<trace>\n"); |
| 435 | bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) { |
| 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; |
| 443 | case NODE_CLOCK: |
| 444 | print_tabs(fd, depth); |
| 445 | fprintf(fd, "<clock>\n"); |
| 446 | bt_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) { |
| 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; |
| 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; |
| 465 | |
| 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"); |
| 473 | bt_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) { |
| 474 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 475 | if (ret) |
| 476 | return ret; |
| 477 | } |
| 478 | |
| 479 | print_tabs(fd, depth); |
| 480 | fprintf(fd, "</left>\n"); |
| 481 | |
| 482 | print_tabs(fd, depth); |
| 483 | fprintf(fd, "<right>\n"); |
| 484 | bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) { |
| 485 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 486 | if (ret) |
| 487 | return ret; |
| 488 | } |
| 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++; |
| 502 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list); |
| 503 | if (ret) |
| 504 | return ret; |
| 505 | |
| 506 | print_tabs(fd, depth); |
| 507 | fprintf(fd, "<type_declarator_list>\n"); |
| 508 | bt_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) { |
| 509 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 510 | if (ret) |
| 511 | return ret; |
| 512 | } |
| 513 | print_tabs(fd, depth); |
| 514 | fprintf(fd, "</type_declarator_list>\n"); |
| 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 | |
| 524 | ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list); |
| 525 | if (ret) |
| 526 | return ret; |
| 527 | |
| 528 | print_tabs(fd, depth); |
| 529 | fprintf(fd, "<type_declarator_list>\n"); |
| 530 | bt_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) { |
| 531 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 532 | if (ret) |
| 533 | return ret; |
| 534 | } |
| 535 | print_tabs(fd, depth); |
| 536 | fprintf(fd, "</type_declarator_list>\n"); |
| 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 | |
| 547 | ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list); |
| 548 | if (ret) |
| 549 | return ret; |
| 550 | |
| 551 | print_tabs(fd, depth); |
| 552 | fprintf(fd, "<type_declarator_list>\n"); |
| 553 | bt_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) { |
| 554 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 555 | if (ret) |
| 556 | return ret; |
| 557 | } |
| 558 | print_tabs(fd, depth); |
| 559 | fprintf(fd, "</type_declarator_list>\n"); |
| 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 | |
| 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 | |
| 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"); |
| 605 | bt_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) { |
| 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"); |
| 616 | bt_list_for_each_entry(iter, &node->u.integer.expressions, siblings) { |
| 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"); |
| 627 | bt_list_for_each_entry(iter, &node->u.string.expressions, siblings) { |
| 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"); |
| 641 | bt_list_for_each_entry(iter, &node->u.enumerator.values, siblings) { |
| 642 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 643 | if (ret) |
| 644 | return ret; |
| 645 | } |
| 646 | print_tabs(fd, depth); |
| 647 | fprintf(fd, "</enumerator>\n"); |
| 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 | |
| 658 | if (node->u._enum.container_type) { |
| 659 | print_tabs(fd, depth); |
| 660 | fprintf(fd, "<container_type>\n"); |
| 661 | ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type); |
| 662 | if (ret) |
| 663 | return ret; |
| 664 | print_tabs(fd, depth); |
| 665 | fprintf(fd, "</container_type>\n"); |
| 666 | } |
| 667 | |
| 668 | print_tabs(fd, depth); |
| 669 | fprintf(fd, "<enumerator_list>\n"); |
| 670 | bt_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) { |
| 671 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 672 | if (ret) |
| 673 | return ret; |
| 674 | } |
| 675 | print_tabs(fd, depth); |
| 676 | fprintf(fd, "</enumerator_list>\n"); |
| 677 | |
| 678 | depth--; |
| 679 | print_tabs(fd, depth); |
| 680 | fprintf(fd, "</enum>\n"); |
| 681 | break; |
| 682 | case NODE_STRUCT_OR_VARIANT_DECLARATION: |
| 683 | ret = ctf_visitor_print_xml(fd, depth, |
| 684 | node->u.struct_or_variant_declaration.type_specifier_list); |
| 685 | if (ret) |
| 686 | return ret; |
| 687 | |
| 688 | print_tabs(fd, depth); |
| 689 | fprintf(fd, "<type_declarator_list>\n"); |
| 690 | bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) { |
| 691 | ret = ctf_visitor_print_xml(fd, depth + 1, iter); |
| 692 | if (ret) |
| 693 | return ret; |
| 694 | } |
| 695 | print_tabs(fd, depth); |
| 696 | fprintf(fd, "</type_declarator_list>\n"); |
| 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"); |
| 706 | bt_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) { |
| 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"); |
| 721 | bt_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) { |
| 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"); |
| 728 | if (!bt_list_empty(&node->u._struct.min_align)) { |
| 729 | print_tabs(fd, depth); |
| 730 | fprintf(fd, "<align>\n"); |
| 731 | bt_list_for_each_entry(iter, &node->u._struct.min_align, siblings) { |
| 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 | } |
| 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 | } |