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_COMP_LOG_SELF_COMP (log_cfg->self_comp)
28 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
29 #define BT_LOG_TAG "PLUGIN/CTF/META/PARENT-LINKS-VISITOR"
30 #include "logging/comp-logging.h"
36 #include "common/assert.h"
40 #include "common/macros.h"
41 #include "common/list.h"
47 int ctf_visitor_unary_expression(int depth
, struct ctf_node
*node
,
48 struct meta_log_config
*log_cfg
)
52 switch (node
->u
.unary_expression
.link
) {
53 case UNARY_LINK_UNKNOWN
:
59 _BT_COMP_LOGE_LINENO(node
->lineno
,
60 "Unknown expression link type: type=%d\n",
61 node
->u
.unary_expression
.link
);
65 switch (node
->u
.unary_expression
.type
) {
67 case UNARY_SIGNED_CONSTANT
:
68 case UNARY_UNSIGNED_CONSTANT
:
71 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
72 ret
= ctf_visitor_unary_expression(depth
+ 1,
73 node
->u
.unary_expression
.u
.sbrac_exp
,
81 _BT_COMP_LOGE_LINENO(node
->lineno
,
82 "Unknown expression link type: type=%d\n",
83 node
->u
.unary_expression
.link
);
90 int ctf_visitor_type_specifier(int depth
, struct ctf_node
*node
,
91 struct meta_log_config
*log_cfg
)
95 switch (node
->u
.field_class_specifier
.type
) {
102 case TYPESPEC_DOUBLE
:
103 case TYPESPEC_SIGNED
:
104 case TYPESPEC_UNSIGNED
:
106 case TYPESPEC_COMPLEX
:
107 case TYPESPEC_IMAGINARY
:
109 case TYPESPEC_ID_TYPE
:
111 case TYPESPEC_FLOATING_POINT
:
112 case TYPESPEC_INTEGER
:
113 case TYPESPEC_STRING
:
114 case TYPESPEC_STRUCT
:
115 case TYPESPEC_VARIANT
:
117 node
->u
.field_class_specifier
.node
->parent
= node
;
118 ret
= ctf_visitor_parent_links(depth
+ 1,
119 node
->u
.field_class_specifier
.node
,
125 case TYPESPEC_UNKNOWN
:
127 _BT_COMP_LOGE_LINENO(node
->lineno
,
128 "Unknown type specifier: type=%d\n",
129 node
->u
.field_class_specifier
.type
);
136 int ctf_visitor_field_class_declarator(int depth
, struct ctf_node
*node
,
137 struct meta_log_config
*log_cfg
)
140 struct ctf_node
*iter
;
144 bt_list_for_each_entry(iter
, &node
->u
.field_class_declarator
.pointers
,
147 ret
= ctf_visitor_parent_links(depth
+ 1, iter
, log_cfg
);
152 switch (node
->u
.field_class_declarator
.type
) {
156 if (node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
) {
157 node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
->parent
= node
;
158 ret
= ctf_visitor_parent_links(depth
+ 1,
159 node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
,
164 if (!node
->u
.field_class_declarator
.u
.nested
.abstract_array
) {
165 bt_list_for_each_entry(iter
, &node
->u
.field_class_declarator
.u
.nested
.length
,
168 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
174 if (node
->u
.field_class_declarator
.bitfield_len
) {
175 node
->u
.field_class_declarator
.bitfield_len
= node
;
176 ret
= ctf_visitor_parent_links(depth
+ 1,
177 node
->u
.field_class_declarator
.bitfield_len
,
183 case TYPEDEC_UNKNOWN
:
185 _BT_COMP_LOGE_LINENO(node
->lineno
,
186 "Unknown type declarator: type=%d\n",
187 node
->u
.field_class_declarator
.type
);
194 int ctf_visitor_parent_links(int depth
, struct ctf_node
*node
,
195 struct meta_log_config
*log_cfg
)
198 struct ctf_node
*iter
;
203 switch (node
->type
) {
205 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
207 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
212 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
214 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
219 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
221 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
226 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
228 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
233 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
235 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
240 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
242 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
250 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
252 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
259 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
261 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
268 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
270 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
277 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
279 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
286 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
288 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
295 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
297 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
304 case NODE_CTF_EXPRESSION
:
306 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
308 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
313 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
315 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
322 case NODE_UNARY_EXPRESSION
:
323 return ctf_visitor_unary_expression(depth
, node
, log_cfg
);
327 node
->u
.field_class_def
.field_class_specifier_list
->parent
= node
;
328 ret
= ctf_visitor_parent_links(depth
+ 1,
329 node
->u
.field_class_def
.field_class_specifier_list
,
333 bt_list_for_each_entry(iter
, &node
->u
.field_class_def
.field_class_declarators
, siblings
) {
335 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
342 case NODE_TYPEALIAS_TARGET
:
344 node
->u
.field_class_alias_target
.field_class_specifier_list
->parent
= node
;
345 ret
= ctf_visitor_parent_links(depth
+ 1,
346 node
->u
.field_class_alias_target
.field_class_specifier_list
,
350 bt_list_for_each_entry(iter
, &node
->u
.field_class_alias_target
.field_class_declarators
, siblings
) {
352 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
359 case NODE_TYPEALIAS_ALIAS
:
361 node
->u
.field_class_alias_name
.field_class_specifier_list
->parent
= node
;
362 ret
= ctf_visitor_parent_links(depth
+ 1,
363 node
->u
.field_class_alias_name
.field_class_specifier_list
,
367 bt_list_for_each_entry(iter
, &node
->u
.field_class_alias_name
.field_class_declarators
, siblings
) {
369 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
377 node
->u
.field_class_alias
.target
->parent
= node
;
378 ret
= ctf_visitor_parent_links(depth
+ 1,
379 node
->u
.field_class_alias
.target
, log_cfg
);
382 node
->u
.field_class_alias
.alias
->parent
= node
;
383 ret
= ctf_visitor_parent_links(depth
+ 1,
384 node
->u
.field_class_alias
.alias
, log_cfg
);
389 case NODE_TYPE_SPECIFIER_LIST
:
390 bt_list_for_each_entry(iter
, &node
->u
.field_class_specifier_list
.head
, siblings
) {
392 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
399 case NODE_TYPE_SPECIFIER
:
400 ret
= ctf_visitor_type_specifier(depth
, node
, log_cfg
);
406 case NODE_TYPE_DECLARATOR
:
407 ret
= ctf_visitor_field_class_declarator(depth
, node
,
413 case NODE_FLOATING_POINT
:
414 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
416 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
423 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
425 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
432 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
434 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
440 case NODE_ENUMERATOR
:
441 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
443 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
451 if (node
->u
._enum
.container_field_class
) {
452 ret
= ctf_visitor_parent_links(depth
+ 1,
453 node
->u
._enum
.container_field_class
, log_cfg
);
458 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
460 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
467 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
468 node
->u
.struct_or_variant_declaration
.field_class_specifier_list
->parent
= node
;
469 ret
= ctf_visitor_parent_links(depth
+ 1,
470 node
->u
.struct_or_variant_declaration
.field_class_specifier_list
,
474 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.field_class_declarators
, siblings
) {
476 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
483 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
485 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
492 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
494 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
499 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
502 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
511 _BT_COMP_LOGE_LINENO(node
->lineno
,
512 "Unknown node type: type=%d\n", node
->type
);