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
;
183 switch (node
->type
) {
185 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
187 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
191 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
193 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
197 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
199 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
203 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
205 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
209 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
211 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
215 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
217 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
224 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
226 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
232 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
234 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
240 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
242 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
248 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
250 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
256 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
258 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
264 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
266 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
272 case NODE_CTF_EXPRESSION
:
274 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
276 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
280 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
282 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
288 case NODE_UNARY_EXPRESSION
:
289 return ctf_visitor_unary_expression(fd
, depth
, node
);
293 node
->u
._typedef
.type_specifier_list
->parent
= node
;
294 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
297 bt_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
299 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
305 case NODE_TYPEALIAS_TARGET
:
307 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
308 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
311 bt_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
313 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
319 case NODE_TYPEALIAS_ALIAS
:
321 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
322 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
325 bt_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
327 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
334 node
->u
.typealias
.target
->parent
= node
;
335 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
338 node
->u
.typealias
.alias
->parent
= node
;
339 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
344 case NODE_TYPE_SPECIFIER_LIST
:
345 bt_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
347 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
353 case NODE_TYPE_SPECIFIER
:
354 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
360 case NODE_TYPE_DECLARATOR
:
361 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
366 case NODE_FLOATING_POINT
:
367 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
369 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
375 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
377 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
383 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
385 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
390 case NODE_ENUMERATOR
:
391 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
393 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
400 if (node
->u
._enum
.container_type
) {
401 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
406 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
408 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
414 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
415 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
416 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
417 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
420 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
422 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
428 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
430 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
436 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
438 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
442 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
445 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
453 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,