Fix: define macros for logging levels
[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"
d9c39b0a 30#include "logging/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 42#include "scanner.h"
06a626b8 43#include "ast.h"
0746848c 44#include "logging.h"
e98a2d6e 45
e98a2d6e 46static
0746848c 47int ctf_visitor_unary_expression(int depth, struct ctf_node *node,
f7b785ac 48 struct meta_log_config *log_cfg)
e98a2d6e
PP
49{
50 int ret = 0;
51
52 switch (node->u.unary_expression.link) {
53 case UNARY_LINK_UNKNOWN:
54 case UNARY_DOTLINK:
55 case UNARY_ARROWLINK:
56 case UNARY_DOTDOTDOT:
57 break;
58 default:
f7b785ac 59 _BT_COMP_LOGE_LINENO(node->lineno,
6fe1fe62
PP
60 "Unknown expression link type: type=%d\n",
61 node->u.unary_expression.link);
e98a2d6e
PP
62 return -EINVAL;
63 }
64
65 switch (node->u.unary_expression.type) {
66 case UNARY_STRING:
67 case UNARY_SIGNED_CONSTANT:
68 case UNARY_UNSIGNED_CONSTANT:
69 break;
70 case UNARY_SBRAC:
71 node->u.unary_expression.u.sbrac_exp->parent = node;
55314f2a 72 ret = ctf_visitor_unary_expression(depth + 1,
0746848c 73 node->u.unary_expression.u.sbrac_exp,
f7b785ac 74 log_cfg);
e98a2d6e
PP
75 if (ret)
76 return ret;
77 break;
78
79 case UNARY_UNKNOWN:
80 default:
f7b785ac 81 _BT_COMP_LOGE_LINENO(node->lineno,
6fe1fe62
PP
82 "Unknown expression link type: type=%d\n",
83 node->u.unary_expression.link);
e98a2d6e
PP
84 return -EINVAL;
85 }
86 return 0;
87}
88
89static
0746848c 90int ctf_visitor_type_specifier(int depth, struct ctf_node *node,
f7b785ac 91 struct meta_log_config *log_cfg)
e98a2d6e
PP
92{
93 int ret;
94
5cd6d0e5 95 switch (node->u.field_class_specifier.type) {
e98a2d6e
PP
96 case TYPESPEC_VOID:
97 case TYPESPEC_CHAR:
98 case TYPESPEC_SHORT:
99 case TYPESPEC_INT:
100 case TYPESPEC_LONG:
101 case TYPESPEC_FLOAT:
102 case TYPESPEC_DOUBLE:
103 case TYPESPEC_SIGNED:
104 case TYPESPEC_UNSIGNED:
105 case TYPESPEC_BOOL:
106 case TYPESPEC_COMPLEX:
107 case TYPESPEC_IMAGINARY:
108 case TYPESPEC_CONST:
109 case TYPESPEC_ID_TYPE:
110 break;
111 case TYPESPEC_FLOATING_POINT:
112 case TYPESPEC_INTEGER:
113 case TYPESPEC_STRING:
114 case TYPESPEC_STRUCT:
115 case TYPESPEC_VARIANT:
116 case TYPESPEC_ENUM:
5cd6d0e5 117 node->u.field_class_specifier.node->parent = node;
0746848c
PP
118 ret = ctf_visitor_parent_links(depth + 1,
119 node->u.field_class_specifier.node,
f7b785ac 120 log_cfg);
e98a2d6e
PP
121 if (ret)
122 return ret;
123 break;
124
125 case TYPESPEC_UNKNOWN:
126 default:
f7b785ac 127 _BT_COMP_LOGE_LINENO(node->lineno,
6fe1fe62 128 "Unknown type specifier: type=%d\n",
5cd6d0e5 129 node->u.field_class_specifier.type);
e98a2d6e
PP
130 return -EINVAL;
131 }
132 return 0;
133}
134
135static
0746848c 136int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node,
f7b785ac 137 struct meta_log_config *log_cfg)
e98a2d6e
PP
138{
139 int ret = 0;
140 struct ctf_node *iter;
141
142 depth++;
143
5cd6d0e5 144 bt_list_for_each_entry(iter, &node->u.field_class_declarator.pointers,
e98a2d6e
PP
145 siblings) {
146 iter->parent = node;
f7b785ac 147 ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg);
e98a2d6e
PP
148 if (ret)
149 return ret;
150 }
151
5cd6d0e5 152 switch (node->u.field_class_declarator.type) {
e98a2d6e
PP
153 case TYPEDEC_ID:
154 break;
155 case TYPEDEC_NESTED:
5cd6d0e5
PP
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;
55314f2a 158 ret = ctf_visitor_parent_links(depth + 1,
0746848c 159 node->u.field_class_declarator.u.nested.field_class_declarator,
f7b785ac 160 log_cfg);
e98a2d6e
PP
161 if (ret)
162 return ret;
163 }
5cd6d0e5
PP
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,
e98a2d6e
PP
166 siblings) {
167 iter->parent = node;
0746848c 168 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 169 log_cfg);
e98a2d6e
PP
170 if (ret)
171 return ret;
172 }
173 }
5cd6d0e5
PP
174 if (node->u.field_class_declarator.bitfield_len) {
175 node->u.field_class_declarator.bitfield_len = node;
55314f2a 176 ret = ctf_visitor_parent_links(depth + 1,
0746848c 177 node->u.field_class_declarator.bitfield_len,
f7b785ac 178 log_cfg);
e98a2d6e
PP
179 if (ret)
180 return ret;
181 }
182 break;
183 case TYPEDEC_UNKNOWN:
184 default:
f7b785ac 185 _BT_COMP_LOGE_LINENO(node->lineno,
6fe1fe62 186 "Unknown type declarator: type=%d\n",
5cd6d0e5 187 node->u.field_class_declarator.type);
e98a2d6e
PP
188 return -EINVAL;
189 }
190 depth--;
191 return 0;
192}
193
0746848c 194int ctf_visitor_parent_links(int depth, struct ctf_node *node,
f7b785ac 195 struct meta_log_config *log_cfg)
e98a2d6e
PP
196{
197 int ret = 0;
198 struct ctf_node *iter;
199
200 if (node->visited)
201 return 0;
202
203 switch (node->type) {
204 case NODE_ROOT:
205 bt_list_for_each_entry(iter, &node->u.root.declaration_list, siblings) {
206 iter->parent = node;
0746848c 207 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 208 log_cfg);
e98a2d6e
PP
209 if (ret)
210 return ret;
211 }
212 bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
213 iter->parent = node;
0746848c 214 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 215 log_cfg);
e98a2d6e
PP
216 if (ret)
217 return ret;
218 }
219 bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
220 iter->parent = node;
0746848c 221 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 222 log_cfg);
e98a2d6e
PP
223 if (ret)
224 return ret;
225 }
226 bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
227 iter->parent = node;
0746848c 228 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 229 log_cfg);
e98a2d6e
PP
230 if (ret)
231 return ret;
232 }
233 bt_list_for_each_entry(iter, &node->u.root.clock, siblings) {
234 iter->parent = node;
0746848c 235 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 236 log_cfg);
e98a2d6e
PP
237 if (ret)
238 return ret;
239 }
240 bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
241 iter->parent = node;
0746848c 242 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 243 log_cfg);
e98a2d6e
PP
244 if (ret)
245 return ret;
246 }
247 break;
248
249 case NODE_EVENT:
250 bt_list_for_each_entry(iter, &node->u.event.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_STREAM:
259 bt_list_for_each_entry(iter, &node->u.stream.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_ENV:
268 bt_list_for_each_entry(iter, &node->u.env.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_TRACE:
277 bt_list_for_each_entry(iter, &node->u.trace.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 case NODE_CLOCK:
286 bt_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
287 iter->parent = node;
0746848c 288 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 289 log_cfg);
e98a2d6e
PP
290 if (ret)
291 return ret;
292 }
293 break;
294 case NODE_CALLSITE:
295 bt_list_for_each_entry(iter, &node->u.callsite.declaration_list, 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 break;
303
304 case NODE_CTF_EXPRESSION:
305 depth++;
306 bt_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) {
307 iter->parent = node;
0746848c 308 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 309 log_cfg);
e98a2d6e
PP
310 if (ret)
311 return ret;
312 }
313 bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
314 iter->parent = node;
0746848c 315 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 316 log_cfg);
e98a2d6e
PP
317 if (ret)
318 return ret;
319 }
320 depth--;
321 break;
322 case NODE_UNARY_EXPRESSION:
f7b785ac 323 return ctf_visitor_unary_expression(depth, node, log_cfg);
e98a2d6e
PP
324
325 case NODE_TYPEDEF:
326 depth++;
5cd6d0e5 327 node->u.field_class_def.field_class_specifier_list->parent = node;
0746848c
PP
328 ret = ctf_visitor_parent_links(depth + 1,
329 node->u.field_class_def.field_class_specifier_list,
f7b785ac 330 log_cfg);
e98a2d6e
PP
331 if (ret)
332 return ret;
5cd6d0e5 333 bt_list_for_each_entry(iter, &node->u.field_class_def.field_class_declarators, siblings) {
e98a2d6e 334 iter->parent = node;
0746848c 335 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 336 log_cfg);
e98a2d6e
PP
337 if (ret)
338 return ret;
339 }
340 depth--;
341 break;
342 case NODE_TYPEALIAS_TARGET:
343 depth++;
5cd6d0e5 344 node->u.field_class_alias_target.field_class_specifier_list->parent = node;
0746848c
PP
345 ret = ctf_visitor_parent_links(depth + 1,
346 node->u.field_class_alias_target.field_class_specifier_list,
f7b785ac 347 log_cfg);
e98a2d6e
PP
348 if (ret)
349 return ret;
5cd6d0e5 350 bt_list_for_each_entry(iter, &node->u.field_class_alias_target.field_class_declarators, siblings) {
e98a2d6e 351 iter->parent = node;
0746848c 352 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 353 log_cfg);
e98a2d6e
PP
354 if (ret)
355 return ret;
356 }
357 depth--;
358 break;
359 case NODE_TYPEALIAS_ALIAS:
360 depth++;
5cd6d0e5 361 node->u.field_class_alias_name.field_class_specifier_list->parent = node;
0746848c
PP
362 ret = ctf_visitor_parent_links(depth + 1,
363 node->u.field_class_alias_name.field_class_specifier_list,
f7b785ac 364 log_cfg);
e98a2d6e
PP
365 if (ret)
366 return ret;
5cd6d0e5 367 bt_list_for_each_entry(iter, &node->u.field_class_alias_name.field_class_declarators, siblings) {
e98a2d6e 368 iter->parent = node;
0746848c 369 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 370 log_cfg);
e98a2d6e
PP
371 if (ret)
372 return ret;
373 }
374 depth--;
375 break;
376 case NODE_TYPEALIAS:
5cd6d0e5 377 node->u.field_class_alias.target->parent = node;
0746848c 378 ret = ctf_visitor_parent_links(depth + 1,
f7b785ac 379 node->u.field_class_alias.target, log_cfg);
e98a2d6e
PP
380 if (ret)
381 return ret;
5cd6d0e5 382 node->u.field_class_alias.alias->parent = node;
0746848c 383 ret = ctf_visitor_parent_links(depth + 1,
f7b785ac 384 node->u.field_class_alias.alias, log_cfg);
e98a2d6e
PP
385 if (ret)
386 return ret;
387 break;
388
389 case NODE_TYPE_SPECIFIER_LIST:
5cd6d0e5 390 bt_list_for_each_entry(iter, &node->u.field_class_specifier_list.head, siblings) {
e98a2d6e 391 iter->parent = node;
0746848c 392 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 393 log_cfg);
e98a2d6e
PP
394 if (ret)
395 return ret;
396 }
397 break;
398
399 case NODE_TYPE_SPECIFIER:
f7b785ac 400 ret = ctf_visitor_type_specifier(depth, node, log_cfg);
e98a2d6e
PP
401 if (ret)
402 return ret;
403 break;
404 case NODE_POINTER:
405 break;
406 case NODE_TYPE_DECLARATOR:
0746848c 407 ret = ctf_visitor_field_class_declarator(depth, node,
f7b785ac 408 log_cfg);
e98a2d6e
PP
409 if (ret)
410 return ret;
411 break;
412
413 case NODE_FLOATING_POINT:
414 bt_list_for_each_entry(iter, &node->u.floating_point.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_INTEGER:
423 bt_list_for_each_entry(iter, &node->u.integer.expressions, 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_STRING:
432 bt_list_for_each_entry(iter, &node->u.string.expressions, siblings) {
433 iter->parent = node;
0746848c 434 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 435 log_cfg);
e98a2d6e
PP
436 if (ret)
437 return ret;
438 }
439 break;
440 case NODE_ENUMERATOR:
441 bt_list_for_each_entry(iter, &node->u.enumerator.values, siblings) {
442 iter->parent = node;
0746848c 443 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 444 log_cfg);
e98a2d6e
PP
445 if (ret)
446 return ret;
447 }
448 break;
449 case NODE_ENUM:
450 depth++;
5cd6d0e5 451 if (node->u._enum.container_field_class) {
0746848c 452 ret = ctf_visitor_parent_links(depth + 1,
f7b785ac 453 node->u._enum.container_field_class, log_cfg);
e98a2d6e
PP
454 if (ret)
455 return ret;
456 }
457
458 bt_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
459 iter->parent = node;
0746848c 460 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 461 log_cfg);
e98a2d6e
PP
462 if (ret)
463 return ret;
464 }
465 depth--;
466 break;
467 case NODE_STRUCT_OR_VARIANT_DECLARATION:
5cd6d0e5 468 node->u.struct_or_variant_declaration.field_class_specifier_list->parent = node;
55314f2a 469 ret = ctf_visitor_parent_links(depth + 1,
0746848c 470 node->u.struct_or_variant_declaration.field_class_specifier_list,
f7b785ac 471 log_cfg);
e98a2d6e
PP
472 if (ret)
473 return ret;
5cd6d0e5 474 bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.field_class_declarators, siblings) {
e98a2d6e 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 break;
482 case NODE_VARIANT:
483 bt_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
484 iter->parent = node;
0746848c 485 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 486 log_cfg);
e98a2d6e
PP
487 if (ret)
488 return ret;
489 }
490 break;
491 case NODE_STRUCT:
492 bt_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) {
493 iter->parent = node;
0746848c 494 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 495 log_cfg);
e98a2d6e
PP
496 if (ret)
497 return ret;
498 }
499 bt_list_for_each_entry(iter, &node->u._struct.min_align,
500 siblings) {
501 iter->parent = node;
0746848c 502 ret = ctf_visitor_parent_links(depth + 1, iter,
f7b785ac 503 log_cfg);
e98a2d6e
PP
504 if (ret)
505 return ret;
506 }
507 break;
508
509 case NODE_UNKNOWN:
510 default:
f7b785ac 511 _BT_COMP_LOGE_LINENO(node->lineno,
6fe1fe62 512 "Unknown node type: type=%d\n", node->type);
e98a2d6e
PP
513 return -EINVAL;
514 }
515 return ret;
516}
This page took 0.079336 seconds and 4 git commands to generate.