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-internal.h>
41 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-VISITOR-PARENT-LINKS"
45 int ctf_visitor_unary_expression(int depth
, struct ctf_node
*node
)
49 switch (node
->u
.unary_expression
.link
) {
50 case UNARY_LINK_UNKNOWN
:
56 BT_LOGE("unknown expression link type %d\n",
57 (int) node
->u
.unary_expression
.link
);
61 switch (node
->u
.unary_expression
.type
) {
63 case UNARY_SIGNED_CONSTANT
:
64 case UNARY_UNSIGNED_CONSTANT
:
67 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
68 ret
= ctf_visitor_unary_expression(depth
+ 1,
69 node
->u
.unary_expression
.u
.sbrac_exp
);
76 BT_LOGE("unknown expression type %d\n",
77 (int) node
->u
.unary_expression
.type
);
84 int ctf_visitor_type_specifier(int depth
, struct ctf_node
*node
)
88 switch (node
->u
.type_specifier
.type
) {
97 case TYPESPEC_UNSIGNED
:
99 case TYPESPEC_COMPLEX
:
100 case TYPESPEC_IMAGINARY
:
102 case TYPESPEC_ID_TYPE
:
104 case TYPESPEC_FLOATING_POINT
:
105 case TYPESPEC_INTEGER
:
106 case TYPESPEC_STRING
:
107 case TYPESPEC_STRUCT
:
108 case TYPESPEC_VARIANT
:
110 node
->u
.type_specifier
.node
->parent
= node
;
111 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.type_specifier
.node
);
116 case TYPESPEC_UNKNOWN
:
118 BT_LOGE("unknown type specifier %d\n",
119 (int) node
->u
.type_specifier
.type
);
126 int ctf_visitor_type_declarator(int depth
, struct ctf_node
*node
)
129 struct ctf_node
*iter
;
133 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
136 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
141 switch (node
->u
.type_declarator
.type
) {
145 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
146 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
147 ret
= ctf_visitor_parent_links(depth
+ 1,
148 node
->u
.type_declarator
.u
.nested
.type_declarator
);
152 if (!node
->u
.type_declarator
.u
.nested
.abstract_array
) {
153 bt_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
156 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
161 if (node
->u
.type_declarator
.bitfield_len
) {
162 node
->u
.type_declarator
.bitfield_len
= node
;
163 ret
= ctf_visitor_parent_links(depth
+ 1,
164 node
->u
.type_declarator
.bitfield_len
);
169 case TYPEDEC_UNKNOWN
:
171 BT_LOGE("unknown type declarator %d\n",
172 (int) node
->u
.type_declarator
.type
);
179 int ctf_visitor_parent_links(int depth
, struct ctf_node
*node
)
182 struct ctf_node
*iter
;
187 switch (node
->type
) {
189 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
191 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
195 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
197 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
201 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
203 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
207 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
209 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
213 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
215 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
219 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
221 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
228 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
230 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
236 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
238 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
244 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
246 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
252 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
254 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
260 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
262 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
268 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
270 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
276 case NODE_CTF_EXPRESSION
:
278 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
280 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
284 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
286 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
292 case NODE_UNARY_EXPRESSION
:
293 return ctf_visitor_unary_expression(depth
, node
);
297 node
->u
._typedef
.type_specifier_list
->parent
= node
;
298 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
._typedef
.type_specifier_list
);
301 bt_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
303 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
309 case NODE_TYPEALIAS_TARGET
:
311 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
312 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
315 bt_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
317 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
323 case NODE_TYPEALIAS_ALIAS
:
325 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
326 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
329 bt_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
331 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
338 node
->u
.typealias
.target
->parent
= node
;
339 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.typealias
.target
);
342 node
->u
.typealias
.alias
->parent
= node
;
343 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.typealias
.alias
);
348 case NODE_TYPE_SPECIFIER_LIST
:
349 bt_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
351 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
357 case NODE_TYPE_SPECIFIER
:
358 ret
= ctf_visitor_type_specifier(depth
, node
);
364 case NODE_TYPE_DECLARATOR
:
365 ret
= ctf_visitor_type_declarator(depth
, node
);
370 case NODE_FLOATING_POINT
:
371 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
373 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
379 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
381 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
387 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
389 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
394 case NODE_ENUMERATOR
:
395 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
397 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
404 if (node
->u
._enum
.container_type
) {
405 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
._enum
.container_type
);
410 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
412 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
418 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
419 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
420 ret
= ctf_visitor_parent_links(depth
+ 1,
421 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
424 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
426 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
432 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
434 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
440 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
442 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
446 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
449 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
457 BT_LOGE("unknown node type %d\n", (int) node
->type
);