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