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
);
73 node
->u
.unary_expression
.u
.nested_exp
->parent
= node
;
74 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
75 node
->u
.unary_expression
.u
.nested_exp
);
82 fprintf(fd
, "[error] %s: unknown expression type %d\n", __func__
,
83 (int) node
->u
.unary_expression
.type
);
90 int ctf_visitor_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
94 switch (node
->u
.type_specifier
.type
) {
101 case TYPESPEC_DOUBLE
:
102 case TYPESPEC_SIGNED
:
103 case TYPESPEC_UNSIGNED
:
105 case TYPESPEC_COMPLEX
:
106 case TYPESPEC_IMAGINARY
:
108 case TYPESPEC_ID_TYPE
:
110 case TYPESPEC_FLOATING_POINT
:
111 case TYPESPEC_INTEGER
:
112 case TYPESPEC_STRING
:
113 case TYPESPEC_STRUCT
:
114 case TYPESPEC_VARIANT
:
116 node
->u
.type_specifier
.node
->parent
= node
;
117 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.type_specifier
.node
);
122 case TYPESPEC_UNKNOWN
:
124 fprintf(fd
, "[error] %s: unknown type specifier %d\n", __func__
,
125 (int) node
->u
.type_specifier
.type
);
132 int ctf_visitor_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
135 struct ctf_node
*iter
;
139 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
142 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
147 switch (node
->u
.type_declarator
.type
) {
151 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
152 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
153 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
154 node
->u
.type_declarator
.u
.nested
.type_declarator
);
158 if (!node
->u
.type_declarator
.u
.nested
.abstract_array
) {
159 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
162 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
167 if (node
->u
.type_declarator
.bitfield_len
) {
168 node
->u
.type_declarator
.bitfield_len
= node
;
169 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
170 node
->u
.type_declarator
.bitfield_len
);
175 case TYPEDEC_UNKNOWN
:
177 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
178 (int) node
->u
.type_declarator
.type
);
185 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
188 struct ctf_node
*iter
;
190 switch (node
->type
) {
192 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
194 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
198 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
200 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
204 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
206 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
210 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
212 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
216 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
218 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
222 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
224 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
231 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
233 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
239 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
241 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
247 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
249 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
255 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
257 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
263 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
265 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
271 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
273 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
279 case NODE_CTF_EXPRESSION
:
281 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
283 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
287 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
289 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
295 case NODE_UNARY_EXPRESSION
:
296 return ctf_visitor_unary_expression(fd
, depth
, node
);
300 node
->u
._typedef
.type_specifier_list
->parent
= node
;
301 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
304 bt_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
306 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
312 case NODE_TYPEALIAS_TARGET
:
314 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
315 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
318 bt_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
320 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
326 case NODE_TYPEALIAS_ALIAS
:
328 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
329 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
332 bt_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
334 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
341 node
->u
.typealias
.target
->parent
= node
;
342 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
345 node
->u
.typealias
.alias
->parent
= node
;
346 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
351 case NODE_TYPE_SPECIFIER_LIST
:
352 bt_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
354 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
360 case NODE_TYPE_SPECIFIER
:
361 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
367 case NODE_TYPE_DECLARATOR
:
368 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
373 case NODE_FLOATING_POINT
:
374 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
376 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
382 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
384 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
390 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
392 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
397 case NODE_ENUMERATOR
:
398 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
400 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
407 if (node
->u
._enum
.container_type
) {
408 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
413 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
415 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
421 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
422 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
423 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
424 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
427 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
429 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
435 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
437 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
443 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
445 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
449 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
452 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
460 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,