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.
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
35 #include <babeltrace/babeltrace-internal.h>
36 #include <babeltrace/list.h>
37 #include "ctf-scanner.h"
38 #include "ctf-parser.h"
41 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
44 int ctf_visitor_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
48 switch (node
->u
.unary_expression
.link
) {
49 case UNARY_LINK_UNKNOWN
:
55 fprintf(fd
, "[error] %s: unknown expression link type %d\n", __func__
,
56 (int) node
->u
.unary_expression
.link
);
60 switch (node
->u
.unary_expression
.type
) {
62 case UNARY_SIGNED_CONSTANT
:
63 case UNARY_UNSIGNED_CONSTANT
:
66 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
67 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
68 node
->u
.unary_expression
.u
.sbrac_exp
);
75 fprintf(fd
, "[error] %s: unknown expression type %d\n", __func__
,
76 (int) node
->u
.unary_expression
.type
);
83 int ctf_visitor_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
87 switch (node
->u
.type_specifier
.type
) {
96 case TYPESPEC_UNSIGNED
:
98 case TYPESPEC_COMPLEX
:
99 case TYPESPEC_IMAGINARY
:
101 case TYPESPEC_ID_TYPE
:
103 case TYPESPEC_FLOATING_POINT
:
104 case TYPESPEC_INTEGER
:
105 case TYPESPEC_STRING
:
106 case TYPESPEC_STRUCT
:
107 case TYPESPEC_VARIANT
:
109 node
->u
.type_specifier
.node
->parent
= node
;
110 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.type_specifier
.node
);
115 case TYPESPEC_UNKNOWN
:
117 fprintf(fd
, "[error] %s: unknown type specifier %d\n", __func__
,
118 (int) node
->u
.type_specifier
.type
);
125 int ctf_visitor_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
128 struct ctf_node
*iter
;
132 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
135 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
140 switch (node
->u
.type_declarator
.type
) {
144 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
145 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
146 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
147 node
->u
.type_declarator
.u
.nested
.type_declarator
);
151 if (!node
->u
.type_declarator
.u
.nested
.abstract_array
) {
152 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
155 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
160 if (node
->u
.type_declarator
.bitfield_len
) {
161 node
->u
.type_declarator
.bitfield_len
= node
;
162 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
163 node
->u
.type_declarator
.bitfield_len
);
168 case TYPEDEC_UNKNOWN
:
170 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
171 (int) node
->u
.type_declarator
.type
);
178 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
181 struct ctf_node
*iter
;
186 switch (node
->type
) {
188 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
190 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
194 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
196 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
200 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
202 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
206 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
208 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
212 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
214 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
218 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
220 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
227 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
229 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
235 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
237 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
243 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
245 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
251 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
253 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
259 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
261 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
267 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
269 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
275 case NODE_CTF_EXPRESSION
:
277 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
279 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
283 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
285 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
291 case NODE_UNARY_EXPRESSION
:
292 return ctf_visitor_unary_expression(fd
, depth
, node
);
296 node
->u
._typedef
.type_specifier_list
->parent
= node
;
297 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
300 bt_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
302 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
308 case NODE_TYPEALIAS_TARGET
:
310 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
311 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
314 bt_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
316 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
322 case NODE_TYPEALIAS_ALIAS
:
324 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
325 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
328 bt_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
330 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
337 node
->u
.typealias
.target
->parent
= node
;
338 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
341 node
->u
.typealias
.alias
->parent
= node
;
342 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
347 case NODE_TYPE_SPECIFIER_LIST
:
348 bt_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
350 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
356 case NODE_TYPE_SPECIFIER
:
357 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
363 case NODE_TYPE_DECLARATOR
:
364 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
369 case NODE_FLOATING_POINT
:
370 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
372 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
378 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
380 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
386 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
388 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
393 case NODE_ENUMERATOR
:
394 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
396 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
403 if (node
->u
._enum
.container_type
) {
404 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
409 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
411 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
417 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
418 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
419 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
420 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
423 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
425 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
431 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
433 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
439 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
441 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
445 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
448 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
456 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,