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.
27 #include <babeltrace/babeltrace.h>
28 #include <babeltrace/list.h>
29 #include "ctf-scanner.h"
30 #include "ctf-parser.h"
33 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
36 int ctf_visitor_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
40 switch (node
->u
.unary_expression
.link
) {
41 case UNARY_LINK_UNKNOWN
:
47 fprintf(fd
, "[error] %s: unknown expression link type %d\n", __func__
,
48 (int) node
->u
.unary_expression
.link
);
52 switch (node
->u
.unary_expression
.type
) {
54 case UNARY_SIGNED_CONSTANT
:
55 case UNARY_UNSIGNED_CONSTANT
:
58 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
59 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
60 node
->u
.unary_expression
.u
.sbrac_exp
);
65 node
->u
.unary_expression
.u
.nested_exp
->parent
= node
;
66 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
67 node
->u
.unary_expression
.u
.nested_exp
);
74 fprintf(fd
, "[error] %s: unknown expression type %d\n", __func__
,
75 (int) node
->u
.unary_expression
.type
);
82 int ctf_visitor_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
86 switch (node
->u
.type_specifier
.type
) {
95 case TYPESPEC_UNSIGNED
:
97 case TYPESPEC_COMPLEX
:
98 case TYPESPEC_IMAGINARY
:
100 case TYPESPEC_ID_TYPE
:
102 case TYPESPEC_FLOATING_POINT
:
103 case TYPESPEC_INTEGER
:
104 case TYPESPEC_STRING
:
105 case TYPESPEC_STRUCT
:
106 case TYPESPEC_VARIANT
:
108 node
->u
.type_specifier
.node
->parent
= node
;
109 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.type_specifier
.node
);
114 case TYPESPEC_UNKNOWN
:
116 fprintf(fd
, "[error] %s: unknown type specifier %d\n", __func__
,
117 (int) node
->u
.type_specifier
.type
);
124 int ctf_visitor_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
127 struct ctf_node
*iter
;
131 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
132 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
135 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
141 switch (node
->u
.type_declarator
.type
) {
145 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
146 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
147 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
148 node
->u
.type_declarator
.u
.nested
.type_declarator
);
152 if (node
->u
.type_declarator
.u
.nested
.length
) {
153 node
->u
.type_declarator
.u
.nested
.length
->parent
= node
;
154 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.type_declarator
.u
.nested
.length
);
158 if (node
->u
.type_declarator
.bitfield_len
) {
159 node
->u
.type_declarator
.bitfield_len
= node
;
160 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
161 node
->u
.type_declarator
.bitfield_len
);
166 case TYPEDEC_UNKNOWN
:
168 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
169 (int) node
->u
.type_declarator
.type
);
176 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
179 struct ctf_node
*iter
;
181 switch (node
->type
) {
183 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
185 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
189 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
191 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
195 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
197 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
201 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
203 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
210 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
212 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
218 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
220 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
226 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
228 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
234 case NODE_CTF_EXPRESSION
:
236 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
238 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
242 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
244 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
250 case NODE_UNARY_EXPRESSION
:
251 return ctf_visitor_unary_expression(fd
, depth
, node
);
255 node
->u
._typedef
.type_specifier_list
->parent
= node
;
256 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
259 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
261 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
267 case NODE_TYPEALIAS_TARGET
:
269 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
270 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
273 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
275 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
281 case NODE_TYPEALIAS_ALIAS
:
283 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
284 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
287 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
289 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
296 node
->u
.typealias
.target
->parent
= node
;
297 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
300 node
->u
.typealias
.alias
->parent
= node
;
301 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
306 case NODE_TYPE_SPECIFIER_LIST
:
307 cds_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
309 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
315 case NODE_TYPE_SPECIFIER
:
316 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
322 case NODE_TYPE_DECLARATOR
:
323 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
328 case NODE_FLOATING_POINT
:
329 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
331 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
337 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
339 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
345 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
347 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
352 case NODE_ENUMERATOR
:
353 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
355 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
362 if (node
->u
._enum
.container_type
) {
363 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
368 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
370 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
376 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
377 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
378 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
379 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
382 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
384 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
390 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
392 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
398 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
400 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
408 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,