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 "plugins/comp-logging.h"
36 #include "common/assert.h"
40 #include "common/macros.h"
41 #include "common/list.h"
48 int ctf_visitor_unary_expression(int depth
, struct ctf_node
*node
,
49 struct meta_log_config
*log_cfg
)
53 switch (node
->u
.unary_expression
.link
) {
54 case UNARY_LINK_UNKNOWN
:
60 _BT_COMP_LOGE_LINENO(node
->lineno
,
61 "Unknown expression link type: type=%d\n",
62 node
->u
.unary_expression
.link
);
66 switch (node
->u
.unary_expression
.type
) {
68 case UNARY_SIGNED_CONSTANT
:
69 case UNARY_UNSIGNED_CONSTANT
:
72 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
73 ret
= ctf_visitor_unary_expression(depth
+ 1,
74 node
->u
.unary_expression
.u
.sbrac_exp
,
82 _BT_COMP_LOGE_LINENO(node
->lineno
,
83 "Unknown expression link type: type=%d\n",
84 node
->u
.unary_expression
.link
);
91 int ctf_visitor_type_specifier(int depth
, struct ctf_node
*node
,
92 struct meta_log_config
*log_cfg
)
96 switch (node
->u
.field_class_specifier
.type
) {
103 case TYPESPEC_DOUBLE
:
104 case TYPESPEC_SIGNED
:
105 case TYPESPEC_UNSIGNED
:
107 case TYPESPEC_COMPLEX
:
108 case TYPESPEC_IMAGINARY
:
110 case TYPESPEC_ID_TYPE
:
112 case TYPESPEC_FLOATING_POINT
:
113 case TYPESPEC_INTEGER
:
114 case TYPESPEC_STRING
:
115 case TYPESPEC_STRUCT
:
116 case TYPESPEC_VARIANT
:
118 node
->u
.field_class_specifier
.node
->parent
= node
;
119 ret
= ctf_visitor_parent_links(depth
+ 1,
120 node
->u
.field_class_specifier
.node
,
126 case TYPESPEC_UNKNOWN
:
128 _BT_COMP_LOGE_LINENO(node
->lineno
,
129 "Unknown type specifier: type=%d\n",
130 node
->u
.field_class_specifier
.type
);
137 int ctf_visitor_field_class_declarator(int depth
, struct ctf_node
*node
,
138 struct meta_log_config
*log_cfg
)
141 struct ctf_node
*iter
;
145 bt_list_for_each_entry(iter
, &node
->u
.field_class_declarator
.pointers
,
148 ret
= ctf_visitor_parent_links(depth
+ 1, iter
, log_cfg
);
153 switch (node
->u
.field_class_declarator
.type
) {
157 if (node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
) {
158 node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
->parent
= node
;
159 ret
= ctf_visitor_parent_links(depth
+ 1,
160 node
->u
.field_class_declarator
.u
.nested
.field_class_declarator
,
165 if (!node
->u
.field_class_declarator
.u
.nested
.abstract_array
) {
166 bt_list_for_each_entry(iter
, &node
->u
.field_class_declarator
.u
.nested
.length
,
169 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
175 if (node
->u
.field_class_declarator
.bitfield_len
) {
176 node
->u
.field_class_declarator
.bitfield_len
= node
;
177 ret
= ctf_visitor_parent_links(depth
+ 1,
178 node
->u
.field_class_declarator
.bitfield_len
,
184 case TYPEDEC_UNKNOWN
:
186 _BT_COMP_LOGE_LINENO(node
->lineno
,
187 "Unknown type declarator: type=%d\n",
188 node
->u
.field_class_declarator
.type
);
195 int ctf_visitor_parent_links(int depth
, struct ctf_node
*node
,
196 struct meta_log_config
*log_cfg
)
199 struct ctf_node
*iter
;
204 switch (node
->type
) {
206 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
208 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
213 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
215 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
220 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
222 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
227 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
229 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
234 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
236 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
241 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
243 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
251 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
253 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
260 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
262 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
269 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
271 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
278 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
280 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
287 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
289 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
296 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
298 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
305 case NODE_CTF_EXPRESSION
:
307 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
309 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
314 bt_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
316 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
323 case NODE_UNARY_EXPRESSION
:
324 return ctf_visitor_unary_expression(depth
, node
, log_cfg
);
328 node
->u
.field_class_def
.field_class_specifier_list
->parent
= node
;
329 ret
= ctf_visitor_parent_links(depth
+ 1,
330 node
->u
.field_class_def
.field_class_specifier_list
,
334 bt_list_for_each_entry(iter
, &node
->u
.field_class_def
.field_class_declarators
, siblings
) {
336 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
343 case NODE_TYPEALIAS_TARGET
:
345 node
->u
.field_class_alias_target
.field_class_specifier_list
->parent
= node
;
346 ret
= ctf_visitor_parent_links(depth
+ 1,
347 node
->u
.field_class_alias_target
.field_class_specifier_list
,
351 bt_list_for_each_entry(iter
, &node
->u
.field_class_alias_target
.field_class_declarators
, siblings
) {
353 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
360 case NODE_TYPEALIAS_ALIAS
:
362 node
->u
.field_class_alias_name
.field_class_specifier_list
->parent
= node
;
363 ret
= ctf_visitor_parent_links(depth
+ 1,
364 node
->u
.field_class_alias_name
.field_class_specifier_list
,
368 bt_list_for_each_entry(iter
, &node
->u
.field_class_alias_name
.field_class_declarators
, siblings
) {
370 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
378 node
->u
.field_class_alias
.target
->parent
= node
;
379 ret
= ctf_visitor_parent_links(depth
+ 1,
380 node
->u
.field_class_alias
.target
, log_cfg
);
383 node
->u
.field_class_alias
.alias
->parent
= node
;
384 ret
= ctf_visitor_parent_links(depth
+ 1,
385 node
->u
.field_class_alias
.alias
, log_cfg
);
390 case NODE_TYPE_SPECIFIER_LIST
:
391 bt_list_for_each_entry(iter
, &node
->u
.field_class_specifier_list
.head
, siblings
) {
393 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
400 case NODE_TYPE_SPECIFIER
:
401 ret
= ctf_visitor_type_specifier(depth
, node
, log_cfg
);
407 case NODE_TYPE_DECLARATOR
:
408 ret
= ctf_visitor_field_class_declarator(depth
, node
,
414 case NODE_FLOATING_POINT
:
415 bt_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
417 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
424 bt_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
426 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
433 bt_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
435 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
441 case NODE_ENUMERATOR
:
442 bt_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
444 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
452 if (node
->u
._enum
.container_field_class
) {
453 ret
= ctf_visitor_parent_links(depth
+ 1,
454 node
->u
._enum
.container_field_class
, log_cfg
);
459 bt_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
461 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
468 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
469 node
->u
.struct_or_variant_declaration
.field_class_specifier_list
->parent
= node
;
470 ret
= ctf_visitor_parent_links(depth
+ 1,
471 node
->u
.struct_or_variant_declaration
.field_class_specifier_list
,
475 bt_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.field_class_declarators
, siblings
) {
477 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
484 bt_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
486 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
493 bt_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
495 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
500 bt_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
503 ret
= ctf_visitor_parent_links(depth
+ 1, iter
,
512 _BT_COMP_LOGE_LINENO(node
->lineno
,
513 "Unknown node type: type=%d\n", node
->type
);