Commit | Line | Data |
---|---|---|
e98a2d6e | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
e98a2d6e | 3 | * |
0235b0db | 4 | * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
e98a2d6e | 5 | * |
0235b0db | 6 | * Common Trace Format Metadata Parent Link Creator. |
e98a2d6e PP |
7 | */ |
8 | ||
f7b785ac PP |
9 | #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) |
10 | #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) | |
350ad6c1 | 11 | #define BT_LOG_TAG "PLUGIN/CTF/META/PARENT-LINKS-VISITOR" |
d9c39b0a | 12 | #include "logging/comp-logging.h" |
6fe1fe62 | 13 | |
e98a2d6e PP |
14 | #include <stdio.h> |
15 | #include <unistd.h> | |
16 | #include <string.h> | |
17 | #include <stdlib.h> | |
578e048b | 18 | #include "common/assert.h" |
e98a2d6e PP |
19 | #include <glib.h> |
20 | #include <inttypes.h> | |
21 | #include <errno.h> | |
91d81473 | 22 | #include "common/macros.h" |
578e048b | 23 | #include "common/list.h" |
06a626b8 | 24 | #include "scanner.h" |
06a626b8 | 25 | #include "ast.h" |
0746848c | 26 | #include "logging.h" |
e98a2d6e | 27 | |
e98a2d6e | 28 | static |
0746848c | 29 | int ctf_visitor_unary_expression(int depth, struct ctf_node *node, |
f7b785ac | 30 | struct meta_log_config *log_cfg) |
e98a2d6e PP |
31 | { |
32 | int ret = 0; | |
33 | ||
34 | switch (node->u.unary_expression.link) { | |
35 | case UNARY_LINK_UNKNOWN: | |
36 | case UNARY_DOTLINK: | |
37 | case UNARY_ARROWLINK: | |
38 | case UNARY_DOTDOTDOT: | |
39 | break; | |
40 | default: | |
f7b785ac | 41 | _BT_COMP_LOGE_LINENO(node->lineno, |
6fe1fe62 PP |
42 | "Unknown expression link type: type=%d\n", |
43 | node->u.unary_expression.link); | |
e98a2d6e PP |
44 | return -EINVAL; |
45 | } | |
46 | ||
47 | switch (node->u.unary_expression.type) { | |
48 | case UNARY_STRING: | |
49 | case UNARY_SIGNED_CONSTANT: | |
50 | case UNARY_UNSIGNED_CONSTANT: | |
51 | break; | |
52 | case UNARY_SBRAC: | |
53 | node->u.unary_expression.u.sbrac_exp->parent = node; | |
55314f2a | 54 | ret = ctf_visitor_unary_expression(depth + 1, |
0746848c | 55 | node->u.unary_expression.u.sbrac_exp, |
f7b785ac | 56 | log_cfg); |
e98a2d6e PP |
57 | if (ret) |
58 | return ret; | |
59 | break; | |
60 | ||
61 | case UNARY_UNKNOWN: | |
62 | default: | |
f7b785ac | 63 | _BT_COMP_LOGE_LINENO(node->lineno, |
6fe1fe62 PP |
64 | "Unknown expression link type: type=%d\n", |
65 | node->u.unary_expression.link); | |
e98a2d6e PP |
66 | return -EINVAL; |
67 | } | |
68 | return 0; | |
69 | } | |
70 | ||
71 | static | |
0746848c | 72 | int ctf_visitor_type_specifier(int depth, struct ctf_node *node, |
f7b785ac | 73 | struct meta_log_config *log_cfg) |
e98a2d6e PP |
74 | { |
75 | int ret; | |
76 | ||
5cd6d0e5 | 77 | switch (node->u.field_class_specifier.type) { |
e98a2d6e PP |
78 | case TYPESPEC_VOID: |
79 | case TYPESPEC_CHAR: | |
80 | case TYPESPEC_SHORT: | |
81 | case TYPESPEC_INT: | |
82 | case TYPESPEC_LONG: | |
83 | case TYPESPEC_FLOAT: | |
84 | case TYPESPEC_DOUBLE: | |
85 | case TYPESPEC_SIGNED: | |
86 | case TYPESPEC_UNSIGNED: | |
87 | case TYPESPEC_BOOL: | |
88 | case TYPESPEC_COMPLEX: | |
89 | case TYPESPEC_IMAGINARY: | |
90 | case TYPESPEC_CONST: | |
91 | case TYPESPEC_ID_TYPE: | |
92 | break; | |
93 | case TYPESPEC_FLOATING_POINT: | |
94 | case TYPESPEC_INTEGER: | |
95 | case TYPESPEC_STRING: | |
96 | case TYPESPEC_STRUCT: | |
97 | case TYPESPEC_VARIANT: | |
98 | case TYPESPEC_ENUM: | |
5cd6d0e5 | 99 | node->u.field_class_specifier.node->parent = node; |
0746848c PP |
100 | ret = ctf_visitor_parent_links(depth + 1, |
101 | node->u.field_class_specifier.node, | |
f7b785ac | 102 | log_cfg); |
e98a2d6e PP |
103 | if (ret) |
104 | return ret; | |
105 | break; | |
106 | ||
107 | case TYPESPEC_UNKNOWN: | |
108 | default: | |
f7b785ac | 109 | _BT_COMP_LOGE_LINENO(node->lineno, |
6fe1fe62 | 110 | "Unknown type specifier: type=%d\n", |
5cd6d0e5 | 111 | node->u.field_class_specifier.type); |
e98a2d6e PP |
112 | return -EINVAL; |
113 | } | |
114 | return 0; | |
115 | } | |
116 | ||
117 | static | |
0746848c | 118 | int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node, |
f7b785ac | 119 | struct meta_log_config *log_cfg) |
e98a2d6e PP |
120 | { |
121 | int ret = 0; | |
122 | struct ctf_node *iter; | |
123 | ||
124 | depth++; | |
125 | ||
5cd6d0e5 | 126 | bt_list_for_each_entry(iter, &node->u.field_class_declarator.pointers, |
e98a2d6e PP |
127 | siblings) { |
128 | iter->parent = node; | |
f7b785ac | 129 | ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg); |
e98a2d6e PP |
130 | if (ret) |
131 | return ret; | |
132 | } | |
133 | ||
5cd6d0e5 | 134 | switch (node->u.field_class_declarator.type) { |
e98a2d6e PP |
135 | case TYPEDEC_ID: |
136 | break; | |
137 | case TYPEDEC_NESTED: | |
5cd6d0e5 PP |
138 | if (node->u.field_class_declarator.u.nested.field_class_declarator) { |
139 | node->u.field_class_declarator.u.nested.field_class_declarator->parent = node; | |
55314f2a | 140 | ret = ctf_visitor_parent_links(depth + 1, |
0746848c | 141 | node->u.field_class_declarator.u.nested.field_class_declarator, |
f7b785ac | 142 | log_cfg); |
e98a2d6e PP |
143 | if (ret) |
144 | return ret; | |
145 | } | |
5cd6d0e5 PP |
146 | if (!node->u.field_class_declarator.u.nested.abstract_array) { |
147 | bt_list_for_each_entry(iter, &node->u.field_class_declarator.u.nested.length, | |
e98a2d6e PP |
148 | siblings) { |
149 | iter->parent = node; | |
0746848c | 150 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 151 | log_cfg); |
e98a2d6e PP |
152 | if (ret) |
153 | return ret; | |
154 | } | |
155 | } | |
5cd6d0e5 PP |
156 | if (node->u.field_class_declarator.bitfield_len) { |
157 | node->u.field_class_declarator.bitfield_len = node; | |
55314f2a | 158 | ret = ctf_visitor_parent_links(depth + 1, |
0746848c | 159 | node->u.field_class_declarator.bitfield_len, |
f7b785ac | 160 | log_cfg); |
e98a2d6e PP |
161 | if (ret) |
162 | return ret; | |
163 | } | |
164 | break; | |
165 | case TYPEDEC_UNKNOWN: | |
166 | default: | |
f7b785ac | 167 | _BT_COMP_LOGE_LINENO(node->lineno, |
6fe1fe62 | 168 | "Unknown type declarator: type=%d\n", |
5cd6d0e5 | 169 | node->u.field_class_declarator.type); |
e98a2d6e PP |
170 | return -EINVAL; |
171 | } | |
172 | depth--; | |
173 | return 0; | |
174 | } | |
175 | ||
0746848c | 176 | int ctf_visitor_parent_links(int depth, struct ctf_node *node, |
f7b785ac | 177 | struct meta_log_config *log_cfg) |
e98a2d6e PP |
178 | { |
179 | int ret = 0; | |
180 | struct ctf_node *iter; | |
181 | ||
182 | if (node->visited) | |
183 | return 0; | |
184 | ||
185 | switch (node->type) { | |
186 | case NODE_ROOT: | |
187 | bt_list_for_each_entry(iter, &node->u.root.declaration_list, siblings) { | |
188 | iter->parent = node; | |
0746848c | 189 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 190 | log_cfg); |
e98a2d6e PP |
191 | if (ret) |
192 | return ret; | |
193 | } | |
194 | bt_list_for_each_entry(iter, &node->u.root.trace, siblings) { | |
195 | iter->parent = node; | |
0746848c | 196 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 197 | log_cfg); |
e98a2d6e PP |
198 | if (ret) |
199 | return ret; | |
200 | } | |
201 | bt_list_for_each_entry(iter, &node->u.root.stream, siblings) { | |
202 | iter->parent = node; | |
0746848c | 203 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 204 | log_cfg); |
e98a2d6e PP |
205 | if (ret) |
206 | return ret; | |
207 | } | |
208 | bt_list_for_each_entry(iter, &node->u.root.event, siblings) { | |
209 | iter->parent = node; | |
0746848c | 210 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 211 | log_cfg); |
e98a2d6e PP |
212 | if (ret) |
213 | return ret; | |
214 | } | |
215 | bt_list_for_each_entry(iter, &node->u.root.clock, siblings) { | |
216 | iter->parent = node; | |
0746848c | 217 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 218 | log_cfg); |
e98a2d6e PP |
219 | if (ret) |
220 | return ret; | |
221 | } | |
222 | bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) { | |
223 | iter->parent = node; | |
0746848c | 224 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 225 | log_cfg); |
e98a2d6e PP |
226 | if (ret) |
227 | return ret; | |
228 | } | |
229 | break; | |
230 | ||
231 | case NODE_EVENT: | |
232 | bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) { | |
233 | iter->parent = node; | |
0746848c | 234 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 235 | log_cfg); |
e98a2d6e PP |
236 | if (ret) |
237 | return ret; | |
238 | } | |
239 | break; | |
240 | case NODE_STREAM: | |
241 | bt_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) { | |
242 | iter->parent = node; | |
0746848c | 243 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 244 | log_cfg); |
e98a2d6e PP |
245 | if (ret) |
246 | return ret; | |
247 | } | |
248 | break; | |
249 | case NODE_ENV: | |
250 | bt_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) { | |
251 | iter->parent = node; | |
0746848c | 252 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 253 | log_cfg); |
e98a2d6e PP |
254 | if (ret) |
255 | return ret; | |
256 | } | |
257 | break; | |
258 | case NODE_TRACE: | |
259 | bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) { | |
260 | iter->parent = node; | |
0746848c | 261 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 262 | log_cfg); |
e98a2d6e PP |
263 | if (ret) |
264 | return ret; | |
265 | } | |
266 | break; | |
267 | case NODE_CLOCK: | |
268 | bt_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) { | |
269 | iter->parent = node; | |
0746848c | 270 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 271 | log_cfg); |
e98a2d6e PP |
272 | if (ret) |
273 | return ret; | |
274 | } | |
275 | break; | |
276 | case NODE_CALLSITE: | |
277 | bt_list_for_each_entry(iter, &node->u.callsite.declaration_list, siblings) { | |
278 | iter->parent = node; | |
0746848c | 279 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 280 | log_cfg); |
e98a2d6e PP |
281 | if (ret) |
282 | return ret; | |
283 | } | |
284 | break; | |
285 | ||
286 | case NODE_CTF_EXPRESSION: | |
287 | depth++; | |
288 | bt_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) { | |
289 | iter->parent = node; | |
0746848c | 290 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 291 | log_cfg); |
e98a2d6e PP |
292 | if (ret) |
293 | return ret; | |
294 | } | |
295 | bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) { | |
296 | iter->parent = node; | |
0746848c | 297 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 298 | log_cfg); |
e98a2d6e PP |
299 | if (ret) |
300 | return ret; | |
301 | } | |
302 | depth--; | |
303 | break; | |
304 | case NODE_UNARY_EXPRESSION: | |
f7b785ac | 305 | return ctf_visitor_unary_expression(depth, node, log_cfg); |
e98a2d6e PP |
306 | |
307 | case NODE_TYPEDEF: | |
308 | depth++; | |
5cd6d0e5 | 309 | node->u.field_class_def.field_class_specifier_list->parent = node; |
0746848c PP |
310 | ret = ctf_visitor_parent_links(depth + 1, |
311 | node->u.field_class_def.field_class_specifier_list, | |
f7b785ac | 312 | log_cfg); |
e98a2d6e PP |
313 | if (ret) |
314 | return ret; | |
5cd6d0e5 | 315 | bt_list_for_each_entry(iter, &node->u.field_class_def.field_class_declarators, siblings) { |
e98a2d6e | 316 | iter->parent = node; |
0746848c | 317 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 318 | log_cfg); |
e98a2d6e PP |
319 | if (ret) |
320 | return ret; | |
321 | } | |
322 | depth--; | |
323 | break; | |
324 | case NODE_TYPEALIAS_TARGET: | |
325 | depth++; | |
5cd6d0e5 | 326 | node->u.field_class_alias_target.field_class_specifier_list->parent = node; |
0746848c PP |
327 | ret = ctf_visitor_parent_links(depth + 1, |
328 | node->u.field_class_alias_target.field_class_specifier_list, | |
f7b785ac | 329 | log_cfg); |
e98a2d6e PP |
330 | if (ret) |
331 | return ret; | |
5cd6d0e5 | 332 | bt_list_for_each_entry(iter, &node->u.field_class_alias_target.field_class_declarators, siblings) { |
e98a2d6e | 333 | iter->parent = node; |
0746848c | 334 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 335 | log_cfg); |
e98a2d6e PP |
336 | if (ret) |
337 | return ret; | |
338 | } | |
339 | depth--; | |
340 | break; | |
341 | case NODE_TYPEALIAS_ALIAS: | |
342 | depth++; | |
5cd6d0e5 | 343 | node->u.field_class_alias_name.field_class_specifier_list->parent = node; |
0746848c PP |
344 | ret = ctf_visitor_parent_links(depth + 1, |
345 | node->u.field_class_alias_name.field_class_specifier_list, | |
f7b785ac | 346 | log_cfg); |
e98a2d6e PP |
347 | if (ret) |
348 | return ret; | |
5cd6d0e5 | 349 | bt_list_for_each_entry(iter, &node->u.field_class_alias_name.field_class_declarators, siblings) { |
e98a2d6e | 350 | iter->parent = node; |
0746848c | 351 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 352 | log_cfg); |
e98a2d6e PP |
353 | if (ret) |
354 | return ret; | |
355 | } | |
356 | depth--; | |
357 | break; | |
358 | case NODE_TYPEALIAS: | |
5cd6d0e5 | 359 | node->u.field_class_alias.target->parent = node; |
0746848c | 360 | ret = ctf_visitor_parent_links(depth + 1, |
f7b785ac | 361 | node->u.field_class_alias.target, log_cfg); |
e98a2d6e PP |
362 | if (ret) |
363 | return ret; | |
5cd6d0e5 | 364 | node->u.field_class_alias.alias->parent = node; |
0746848c | 365 | ret = ctf_visitor_parent_links(depth + 1, |
f7b785ac | 366 | node->u.field_class_alias.alias, log_cfg); |
e98a2d6e PP |
367 | if (ret) |
368 | return ret; | |
369 | break; | |
370 | ||
371 | case NODE_TYPE_SPECIFIER_LIST: | |
5cd6d0e5 | 372 | bt_list_for_each_entry(iter, &node->u.field_class_specifier_list.head, siblings) { |
e98a2d6e | 373 | iter->parent = node; |
0746848c | 374 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 375 | log_cfg); |
e98a2d6e PP |
376 | if (ret) |
377 | return ret; | |
378 | } | |
379 | break; | |
380 | ||
381 | case NODE_TYPE_SPECIFIER: | |
f7b785ac | 382 | ret = ctf_visitor_type_specifier(depth, node, log_cfg); |
e98a2d6e PP |
383 | if (ret) |
384 | return ret; | |
385 | break; | |
386 | case NODE_POINTER: | |
387 | break; | |
388 | case NODE_TYPE_DECLARATOR: | |
0746848c | 389 | ret = ctf_visitor_field_class_declarator(depth, node, |
f7b785ac | 390 | log_cfg); |
e98a2d6e PP |
391 | if (ret) |
392 | return ret; | |
393 | break; | |
394 | ||
395 | case NODE_FLOATING_POINT: | |
396 | bt_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) { | |
397 | iter->parent = node; | |
0746848c | 398 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 399 | log_cfg); |
e98a2d6e PP |
400 | if (ret) |
401 | return ret; | |
402 | } | |
403 | break; | |
404 | case NODE_INTEGER: | |
405 | bt_list_for_each_entry(iter, &node->u.integer.expressions, siblings) { | |
406 | iter->parent = node; | |
0746848c | 407 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 408 | log_cfg); |
e98a2d6e PP |
409 | if (ret) |
410 | return ret; | |
411 | } | |
412 | break; | |
413 | case NODE_STRING: | |
414 | bt_list_for_each_entry(iter, &node->u.string.expressions, siblings) { | |
415 | iter->parent = node; | |
0746848c | 416 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 417 | log_cfg); |
e98a2d6e PP |
418 | if (ret) |
419 | return ret; | |
420 | } | |
421 | break; | |
422 | case NODE_ENUMERATOR: | |
423 | bt_list_for_each_entry(iter, &node->u.enumerator.values, siblings) { | |
424 | iter->parent = node; | |
0746848c | 425 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 426 | log_cfg); |
e98a2d6e PP |
427 | if (ret) |
428 | return ret; | |
429 | } | |
430 | break; | |
431 | case NODE_ENUM: | |
432 | depth++; | |
5cd6d0e5 | 433 | if (node->u._enum.container_field_class) { |
0746848c | 434 | ret = ctf_visitor_parent_links(depth + 1, |
f7b785ac | 435 | node->u._enum.container_field_class, log_cfg); |
e98a2d6e PP |
436 | if (ret) |
437 | return ret; | |
438 | } | |
439 | ||
440 | bt_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) { | |
441 | iter->parent = node; | |
0746848c | 442 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 443 | log_cfg); |
e98a2d6e PP |
444 | if (ret) |
445 | return ret; | |
446 | } | |
447 | depth--; | |
448 | break; | |
449 | case NODE_STRUCT_OR_VARIANT_DECLARATION: | |
5cd6d0e5 | 450 | node->u.struct_or_variant_declaration.field_class_specifier_list->parent = node; |
55314f2a | 451 | ret = ctf_visitor_parent_links(depth + 1, |
0746848c | 452 | node->u.struct_or_variant_declaration.field_class_specifier_list, |
f7b785ac | 453 | log_cfg); |
e98a2d6e PP |
454 | if (ret) |
455 | return ret; | |
5cd6d0e5 | 456 | bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.field_class_declarators, siblings) { |
e98a2d6e | 457 | iter->parent = node; |
0746848c | 458 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 459 | log_cfg); |
e98a2d6e PP |
460 | if (ret) |
461 | return ret; | |
462 | } | |
463 | break; | |
464 | case NODE_VARIANT: | |
465 | bt_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) { | |
466 | iter->parent = node; | |
0746848c | 467 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 468 | log_cfg); |
e98a2d6e PP |
469 | if (ret) |
470 | return ret; | |
471 | } | |
472 | break; | |
473 | case NODE_STRUCT: | |
474 | bt_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) { | |
475 | iter->parent = node; | |
0746848c | 476 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 477 | log_cfg); |
e98a2d6e PP |
478 | if (ret) |
479 | return ret; | |
480 | } | |
481 | bt_list_for_each_entry(iter, &node->u._struct.min_align, | |
482 | siblings) { | |
483 | iter->parent = node; | |
0746848c | 484 | ret = ctf_visitor_parent_links(depth + 1, iter, |
f7b785ac | 485 | log_cfg); |
e98a2d6e PP |
486 | if (ret) |
487 | return ret; | |
488 | } | |
489 | break; | |
490 | ||
491 | case NODE_UNKNOWN: | |
492 | default: | |
f7b785ac | 493 | _BT_COMP_LOGE_LINENO(node->lineno, |
6fe1fe62 | 494 | "Unknown node type: type=%d\n", node->type); |
e98a2d6e PP |
495 | return -EINVAL; |
496 | } | |
497 | return ret; | |
498 | } |