2 * ctf-visitor-parent-links.c
4 * Common Trace Format Metadata Parent Link Creator.
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
27 #include <babeltrace/babeltrace.h>
28 #include <babeltrace/list.h>
29 #include "ctf-scanner.h"
30 #include "ctf-parser.h"
33 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
36 int ctf_visitor_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
40 switch (node
->u
.unary_expression
.link
) {
41 case UNARY_LINK_UNKNOWN
:
47 fprintf(fd
, "[error] %s: unknown expression link type %d\n", __func__
,
48 (int) node
->u
.unary_expression
.link
);
52 switch (node
->u
.unary_expression
.type
) {
54 case UNARY_SIGNED_CONSTANT
:
55 case UNARY_UNSIGNED_CONSTANT
:
58 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
59 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
60 node
->u
.unary_expression
.u
.sbrac_exp
);
65 node
->u
.unary_expression
.u
.nested_exp
->parent
= node
;
66 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
67 node
->u
.unary_expression
.u
.nested_exp
);
74 fprintf(fd
, "[error] %s: unknown expression type %d\n", __func__
,
75 (int) node
->u
.unary_expression
.type
);
82 int ctf_visitor_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
86 switch (node
->u
.type_specifier
.type
) {
95 case TYPESPEC_UNSIGNED
:
97 case TYPESPEC_COMPLEX
:
98 case TYPESPEC_IMAGINARY
:
100 case TYPESPEC_ID_TYPE
:
102 case TYPESPEC_FLOATING_POINT
:
103 case TYPESPEC_INTEGER
:
104 case TYPESPEC_STRING
:
105 case TYPESPEC_STRUCT
:
106 case TYPESPEC_VARIANT
:
108 node
->u
.type_specifier
.node
->parent
= node
;
109 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.type_specifier
.node
);
114 case TYPESPEC_UNKNOWN
:
116 fprintf(fd
, "[error] %s: unknown type specifier %d\n", __func__
,
117 (int) node
->u
.type_specifier
.type
);
124 int ctf_visitor_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
127 struct ctf_node
*iter
;
131 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
134 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
139 switch (node
->u
.type_declarator
.type
) {
143 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
144 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
145 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
146 node
->u
.type_declarator
.u
.nested
.type_declarator
);
150 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
153 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
157 if (node
->u
.type_declarator
.bitfield_len
) {
158 node
->u
.type_declarator
.bitfield_len
= node
;
159 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
160 node
->u
.type_declarator
.bitfield_len
);
165 case TYPEDEC_UNKNOWN
:
167 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
168 (int) node
->u
.type_declarator
.type
);
175 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
178 struct ctf_node
*iter
;
180 switch (node
->type
) {
182 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
184 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
188 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
190 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
194 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
196 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
200 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
202 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
209 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
211 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
217 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
219 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
225 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
227 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
233 case NODE_CTF_EXPRESSION
:
235 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
237 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
241 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
243 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
249 case NODE_UNARY_EXPRESSION
:
250 return ctf_visitor_unary_expression(fd
, depth
, node
);
254 node
->u
._typedef
.type_specifier_list
->parent
= node
;
255 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
258 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
260 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
266 case NODE_TYPEALIAS_TARGET
:
268 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
269 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
272 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
274 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
280 case NODE_TYPEALIAS_ALIAS
:
282 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
283 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
286 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
288 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
295 node
->u
.typealias
.target
->parent
= node
;
296 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
299 node
->u
.typealias
.alias
->parent
= node
;
300 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
305 case NODE_TYPE_SPECIFIER_LIST
:
306 cds_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
308 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
314 case NODE_TYPE_SPECIFIER
:
315 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
321 case NODE_TYPE_DECLARATOR
:
322 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
327 case NODE_FLOATING_POINT
:
328 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
330 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
336 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
338 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
344 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
346 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
351 case NODE_ENUMERATOR
:
352 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
354 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
361 if (node
->u
._enum
.container_type
) {
362 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
367 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
369 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
375 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
376 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
377 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
378 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
381 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
383 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
389 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
391 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
397 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
399 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
403 cds_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
406 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
414 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,