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
27 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-PARENT-LINKS-VISITOR"
34 #include "common/assert.h"
38 #include "common/macros.h"
39 #include "common/list.h"
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_LINENO(node
->lineno
,
57 "Unknown expression link type: type=%d\n",
58 node
->u
.unary_expression
.link
);
62 switch (node
->u
.unary_expression
.type
) {
64 case UNARY_SIGNED_CONSTANT
:
65 case UNARY_UNSIGNED_CONSTANT
:
68 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
69 ret
= ctf_visitor_unary_expression(depth
+ 1,
70 node
->u
.unary_expression
.u
.sbrac_exp
);
77 _BT_LOGE_LINENO(node
->lineno
,
78 "Unknown expression link type: type=%d\n",
79 node
->u
.unary_expression
.link
);
86 int ctf_visitor_type_specifier(int depth
, struct ctf_node
*node
)
90 switch (node
->u
.field_class_specifier
.type
) {
99 case TYPESPEC_UNSIGNED
:
101 case TYPESPEC_COMPLEX
:
102 case TYPESPEC_IMAGINARY
:
104 case TYPESPEC_ID_TYPE
:
106 case TYPESPEC_FLOATING_POINT
:
107 case TYPESPEC_INTEGER
:
108 case TYPESPEC_STRING
:
109 case TYPESPEC_STRUCT
:
110 case TYPESPEC_VARIANT
:
112 node
->u
.field_class_specifier
.node
->parent
= node
;
113 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.field_class_specifier
.node
);
118 case TYPESPEC_UNKNOWN
:
120 _BT_LOGE_LINENO(node
->lineno
,
121 "Unknown type specifier: type=%d\n",
122 node
->u
.field_class_specifier
.type
);
129 int ctf_visitor_field_class_declarator(int depth
, struct ctf_node
*node
)
132 struct ctf_node
*iter
;
136 bt_list_for_each_entry(iter
, &node
->u
.field_class_declarator
.pointers
,
139 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
144 switch (node
->u
.field_class_declarator
.type
) {
148 if (node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
) {
149 node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
->parent
= node
;
150 ret
= ctf_visitor_parent_links(depth
+ 1,
151 node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
);
155 if (!node
->u
.field_class_declarator
.u
.nested
.abstract_array
) {
156 bt_list_for_each_entry(iter
, &node
->u
.field_class_declarator
.u
.nested
.length
,
159 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
164 if (node
->u
.field_class_declarator
.bitfield_len
) {
165 node
->u
.field_class_declarator
.bitfield_len
= node
;
166 ret
= ctf_visitor_parent_links(depth
+ 1,
167 node
->u
.field_class_declarator
.bitfield_len
);
172 case TYPEDEC_UNKNOWN
:
174 _BT_LOGE_LINENO(node
->lineno
,
175 "Unknown type declarator: type=%d\n",
176 node
->u
.field_class_declarator
.type
);
183 int ctf_visitor_parent_links(int depth
, struct ctf_node
*node
)
186 struct ctf_node
*iter
;
191 switch (node
->type
) {
193 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
195 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
199 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
201 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
205 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
207 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
211 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
213 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
217 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
219 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
223 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
225 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
232 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
234 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
240 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
242 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
248 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
250 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
256 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
258 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
264 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
266 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
272 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
274 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
280 case NODE_CTF_EXPRESSION
:
282 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
284 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
288 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
290 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
296 case NODE_UNARY_EXPRESSION
:
297 return ctf_visitor_unary_expression(depth
, node
);
301 node
->u
.field_class_def
.field_class_specifier_list
->parent
= node
;
302 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.field_class_def
.field_class_specifier_list
);
305 bt_list_for_each_entry(iter
, &node
->u
.field_class_def
.field_class_declarators
, siblings
) {
307 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
313 case NODE_TYPEALIAS_TARGET
:
315 node
->u
.field_class_alias_target
.field_class_specifier_list
->parent
= node
;
316 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.field_class_alias_target
.field_class_specifier_list
);
319 bt_list_for_each_entry(iter
, &node
->u
.field_class_alias_target
.field_class_declarators
, siblings
) {
321 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
327 case NODE_TYPEALIAS_ALIAS
:
329 node
->u
.field_class_alias_name
.field_class_specifier_list
->parent
= node
;
330 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.field_class_alias_name
.field_class_specifier_list
);
333 bt_list_for_each_entry(iter
, &node
->u
.field_class_alias_name
.field_class_declarators
, siblings
) {
335 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
342 node
->u
.field_class_alias
.target
->parent
= node
;
343 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.field_class_alias
.target
);
346 node
->u
.field_class_alias
.alias
->parent
= node
;
347 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
.field_class_alias
.alias
);
352 case NODE_TYPE_SPECIFIER_LIST
:
353 bt_list_for_each_entry(iter
, &node
->u
.field_class_specifier_list
.head
, siblings
) {
355 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
361 case NODE_TYPE_SPECIFIER
:
362 ret
= ctf_visitor_type_specifier(depth
, node
);
368 case NODE_TYPE_DECLARATOR
:
369 ret
= ctf_visitor_field_class_declarator(depth
, node
);
374 case NODE_FLOATING_POINT
:
375 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
377 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
383 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
385 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
391 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
393 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
398 case NODE_ENUMERATOR
:
399 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
401 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
408 if (node
->u
._enum
.container_field_class
) {
409 ret
= ctf_visitor_parent_links(depth
+ 1, node
->u
._enum
.container_field_class
);
414 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
416 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
422 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
423 node
->u
.struct_or_variant_declaration
.field_class_specifier_list
->parent
= node
;
424 ret
= ctf_visitor_parent_links(depth
+ 1,
425 node
->u
.struct_or_variant_declaration
.field_class_specifier_list
);
428 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.field_class_declarators
, siblings
) {
430 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
436 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
438 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
444 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
446 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
450 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
453 ret
= ctf_visitor_parent_links(depth
+ 1, iter
);
461 _BT_LOGE_LINENO(node
->lineno
,
462 "Unknown node type: type=%d\n", node
->type
);