bfa3f0cf8c322066ed3f26f4c1fdd4ccfa4b10a6
[babeltrace.git] / src / plugins / ctf / common / metadata / visitor-parent-links.c
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
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"
31
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include "common/assert.h"
37 #include <glib.h>
38 #include <inttypes.h>
39 #include <errno.h>
40 #include "common/macros.h"
41 #include "common/list.h"
42 #include "scanner.h"
43 #include "parser.h"
44 #include "ast.h"
45 #include "logging.h"
46
47 static
48 int ctf_visitor_unary_expression(int depth, struct ctf_node *node,
49 struct meta_log_config *log_cfg)
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:
60 _BT_COMP_LOGE_LINENO(node->lineno,
61 "Unknown expression link type: type=%d\n",
62 node->u.unary_expression.link);
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;
73 ret = ctf_visitor_unary_expression(depth + 1,
74 node->u.unary_expression.u.sbrac_exp,
75 log_cfg);
76 if (ret)
77 return ret;
78 break;
79
80 case UNARY_UNKNOWN:
81 default:
82 _BT_COMP_LOGE_LINENO(node->lineno,
83 "Unknown expression link type: type=%d\n",
84 node->u.unary_expression.link);
85 return -EINVAL;
86 }
87 return 0;
88 }
89
90 static
91 int ctf_visitor_type_specifier(int depth, struct ctf_node *node,
92 struct meta_log_config *log_cfg)
93 {
94 int ret;
95
96 switch (node->u.field_class_specifier.type) {
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:
118 node->u.field_class_specifier.node->parent = node;
119 ret = ctf_visitor_parent_links(depth + 1,
120 node->u.field_class_specifier.node,
121 log_cfg);
122 if (ret)
123 return ret;
124 break;
125
126 case TYPESPEC_UNKNOWN:
127 default:
128 _BT_COMP_LOGE_LINENO(node->lineno,
129 "Unknown type specifier: type=%d\n",
130 node->u.field_class_specifier.type);
131 return -EINVAL;
132 }
133 return 0;
134 }
135
136 static
137 int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node,
138 struct meta_log_config *log_cfg)
139 {
140 int ret = 0;
141 struct ctf_node *iter;
142
143 depth++;
144
145 bt_list_for_each_entry(iter, &node->u.field_class_declarator.pointers,
146 siblings) {
147 iter->parent = node;
148 ret = ctf_visitor_parent_links(depth + 1, iter, log_cfg);
149 if (ret)
150 return ret;
151 }
152
153 switch (node->u.field_class_declarator.type) {
154 case TYPEDEC_ID:
155 break;
156 case TYPEDEC_NESTED:
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,
161 log_cfg);
162 if (ret)
163 return ret;
164 }
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,
167 siblings) {
168 iter->parent = node;
169 ret = ctf_visitor_parent_links(depth + 1, iter,
170 log_cfg);
171 if (ret)
172 return ret;
173 }
174 }
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,
179 log_cfg);
180 if (ret)
181 return ret;
182 }
183 break;
184 case TYPEDEC_UNKNOWN:
185 default:
186 _BT_COMP_LOGE_LINENO(node->lineno,
187 "Unknown type declarator: type=%d\n",
188 node->u.field_class_declarator.type);
189 return -EINVAL;
190 }
191 depth--;
192 return 0;
193 }
194
195 int ctf_visitor_parent_links(int depth, struct ctf_node *node,
196 struct meta_log_config *log_cfg)
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;
208 ret = ctf_visitor_parent_links(depth + 1, iter,
209 log_cfg);
210 if (ret)
211 return ret;
212 }
213 bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
214 iter->parent = node;
215 ret = ctf_visitor_parent_links(depth + 1, iter,
216 log_cfg);
217 if (ret)
218 return ret;
219 }
220 bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
221 iter->parent = node;
222 ret = ctf_visitor_parent_links(depth + 1, iter,
223 log_cfg);
224 if (ret)
225 return ret;
226 }
227 bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
228 iter->parent = node;
229 ret = ctf_visitor_parent_links(depth + 1, iter,
230 log_cfg);
231 if (ret)
232 return ret;
233 }
234 bt_list_for_each_entry(iter, &node->u.root.clock, siblings) {
235 iter->parent = node;
236 ret = ctf_visitor_parent_links(depth + 1, iter,
237 log_cfg);
238 if (ret)
239 return ret;
240 }
241 bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
242 iter->parent = node;
243 ret = ctf_visitor_parent_links(depth + 1, iter,
244 log_cfg);
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;
253 ret = ctf_visitor_parent_links(depth + 1, iter,
254 log_cfg);
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;
262 ret = ctf_visitor_parent_links(depth + 1, iter,
263 log_cfg);
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;
271 ret = ctf_visitor_parent_links(depth + 1, iter,
272 log_cfg);
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;
280 ret = ctf_visitor_parent_links(depth + 1, iter,
281 log_cfg);
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;
289 ret = ctf_visitor_parent_links(depth + 1, iter,
290 log_cfg);
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;
298 ret = ctf_visitor_parent_links(depth + 1, iter,
299 log_cfg);
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;
309 ret = ctf_visitor_parent_links(depth + 1, iter,
310 log_cfg);
311 if (ret)
312 return ret;
313 }
314 bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
315 iter->parent = node;
316 ret = ctf_visitor_parent_links(depth + 1, iter,
317 log_cfg);
318 if (ret)
319 return ret;
320 }
321 depth--;
322 break;
323 case NODE_UNARY_EXPRESSION:
324 return ctf_visitor_unary_expression(depth, node, log_cfg);
325
326 case NODE_TYPEDEF:
327 depth++;
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,
331 log_cfg);
332 if (ret)
333 return ret;
334 bt_list_for_each_entry(iter, &node->u.field_class_def.field_class_declarators, siblings) {
335 iter->parent = node;
336 ret = ctf_visitor_parent_links(depth + 1, iter,
337 log_cfg);
338 if (ret)
339 return ret;
340 }
341 depth--;
342 break;
343 case NODE_TYPEALIAS_TARGET:
344 depth++;
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,
348 log_cfg);
349 if (ret)
350 return ret;
351 bt_list_for_each_entry(iter, &node->u.field_class_alias_target.field_class_declarators, siblings) {
352 iter->parent = node;
353 ret = ctf_visitor_parent_links(depth + 1, iter,
354 log_cfg);
355 if (ret)
356 return ret;
357 }
358 depth--;
359 break;
360 case NODE_TYPEALIAS_ALIAS:
361 depth++;
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,
365 log_cfg);
366 if (ret)
367 return ret;
368 bt_list_for_each_entry(iter, &node->u.field_class_alias_name.field_class_declarators, siblings) {
369 iter->parent = node;
370 ret = ctf_visitor_parent_links(depth + 1, iter,
371 log_cfg);
372 if (ret)
373 return ret;
374 }
375 depth--;
376 break;
377 case NODE_TYPEALIAS:
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);
381 if (ret)
382 return ret;
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);
386 if (ret)
387 return ret;
388 break;
389
390 case NODE_TYPE_SPECIFIER_LIST:
391 bt_list_for_each_entry(iter, &node->u.field_class_specifier_list.head, siblings) {
392 iter->parent = node;
393 ret = ctf_visitor_parent_links(depth + 1, iter,
394 log_cfg);
395 if (ret)
396 return ret;
397 }
398 break;
399
400 case NODE_TYPE_SPECIFIER:
401 ret = ctf_visitor_type_specifier(depth, node, log_cfg);
402 if (ret)
403 return ret;
404 break;
405 case NODE_POINTER:
406 break;
407 case NODE_TYPE_DECLARATOR:
408 ret = ctf_visitor_field_class_declarator(depth, node,
409 log_cfg);
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;
417 ret = ctf_visitor_parent_links(depth + 1, iter,
418 log_cfg);
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;
426 ret = ctf_visitor_parent_links(depth + 1, iter,
427 log_cfg);
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;
435 ret = ctf_visitor_parent_links(depth + 1, iter,
436 log_cfg);
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;
444 ret = ctf_visitor_parent_links(depth + 1, iter,
445 log_cfg);
446 if (ret)
447 return ret;
448 }
449 break;
450 case NODE_ENUM:
451 depth++;
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);
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;
461 ret = ctf_visitor_parent_links(depth + 1, iter,
462 log_cfg);
463 if (ret)
464 return ret;
465 }
466 depth--;
467 break;
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,
472 log_cfg);
473 if (ret)
474 return ret;
475 bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.field_class_declarators, siblings) {
476 iter->parent = node;
477 ret = ctf_visitor_parent_links(depth + 1, iter,
478 log_cfg);
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;
486 ret = ctf_visitor_parent_links(depth + 1, iter,
487 log_cfg);
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;
495 ret = ctf_visitor_parent_links(depth + 1, iter,
496 log_cfg);
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;
503 ret = ctf_visitor_parent_links(depth + 1, iter,
504 log_cfg);
505 if (ret)
506 return ret;
507 }
508 break;
509
510 case NODE_UNKNOWN:
511 default:
512 _BT_COMP_LOGE_LINENO(node->lineno,
513 "Unknown node type: type=%d\n", node->type);
514 return -EINVAL;
515 }
516 return ret;
517 }
This page took 0.0397380000000001 seconds and 3 git commands to generate.