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