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-internal.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 bt_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 if (!node
->u
.type_declarator
.u
.nested
.abstract_array
) {
151 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
154 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
159 if (node
->u
.type_declarator
.bitfield_len
) {
160 node
->u
.type_declarator
.bitfield_len
= node
;
161 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
162 node
->u
.type_declarator
.bitfield_len
);
167 case TYPEDEC_UNKNOWN
:
169 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
170 (int) node
->u
.type_declarator
.type
);
177 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
180 struct ctf_node
*iter
;
182 switch (node
->type
) {
184 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
186 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
190 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
192 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
196 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
198 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
202 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
204 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
208 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
210 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
217 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
219 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
225 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
227 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
233 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
235 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
241 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
243 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
249 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
251 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
257 case NODE_CTF_EXPRESSION
:
259 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
261 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
265 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
267 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
273 case NODE_UNARY_EXPRESSION
:
274 return ctf_visitor_unary_expression(fd
, depth
, node
);
278 node
->u
._typedef
.type_specifier_list
->parent
= node
;
279 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
282 bt_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
284 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
290 case NODE_TYPEALIAS_TARGET
:
292 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
293 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
296 bt_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
298 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
304 case NODE_TYPEALIAS_ALIAS
:
306 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
307 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
310 bt_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
312 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
319 node
->u
.typealias
.target
->parent
= node
;
320 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
323 node
->u
.typealias
.alias
->parent
= node
;
324 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
329 case NODE_TYPE_SPECIFIER_LIST
:
330 bt_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
332 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
338 case NODE_TYPE_SPECIFIER
:
339 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
345 case NODE_TYPE_DECLARATOR
:
346 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
351 case NODE_FLOATING_POINT
:
352 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
354 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
360 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
362 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
368 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
370 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
375 case NODE_ENUMERATOR
:
376 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
378 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
385 if (node
->u
._enum
.container_type
) {
386 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
391 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
393 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
399 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
400 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
401 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
402 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
405 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
407 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
413 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
415 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
421 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
423 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
427 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
430 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
438 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,