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 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
134 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
139 switch (node
->u
.type_declarator
.type
) {
143 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
144 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
145 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
146 node
->u
.type_declarator
.u
.nested
.type_declarator
);
150 if (!node
->u
.type_declarator
.u
.nested
.abstract_array
) {
151 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
154 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
159 if (node
->u
.type_declarator
.bitfield_len
) {
160 node
->u
.type_declarator
.bitfield_len
= node
;
161 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
162 node
->u
.type_declarator
.bitfield_len
);
167 case TYPEDEC_UNKNOWN
:
169 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
170 (int) node
->u
.type_declarator
.type
);
177 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
180 struct ctf_node
*iter
;
182 switch (node
->type
) {
184 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
, siblings
) {
186 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
190 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
192 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
196 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
198 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
202 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
204 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
211 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
213 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
219 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
221 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
227 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
229 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
235 case NODE_CTF_EXPRESSION
:
237 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.left
, siblings
) {
239 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
243 cds_list_for_each_entry(iter
, &node
->u
.ctf_expression
.right
, siblings
) {
245 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
251 case NODE_UNARY_EXPRESSION
:
252 return ctf_visitor_unary_expression(fd
, depth
, node
);
256 node
->u
._typedef
.type_specifier_list
->parent
= node
;
257 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._typedef
.type_specifier_list
);
260 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
262 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
268 case NODE_TYPEALIAS_TARGET
:
270 node
->u
.typealias_target
.type_specifier_list
->parent
= node
;
271 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_target
.type_specifier_list
);
274 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
276 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
282 case NODE_TYPEALIAS_ALIAS
:
284 node
->u
.typealias_alias
.type_specifier_list
->parent
= node
;
285 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias_alias
.type_specifier_list
);
288 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
290 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
297 node
->u
.typealias
.target
->parent
= node
;
298 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
301 node
->u
.typealias
.alias
->parent
= node
;
302 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
307 case NODE_TYPE_SPECIFIER_LIST
:
308 cds_list_for_each_entry(iter
, &node
->u
.type_specifier_list
.head
, siblings
) {
310 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
316 case NODE_TYPE_SPECIFIER
:
317 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
323 case NODE_TYPE_DECLARATOR
:
324 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
329 case NODE_FLOATING_POINT
:
330 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
332 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
338 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
340 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
346 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
348 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
353 case NODE_ENUMERATOR
:
354 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
356 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
363 if (node
->u
._enum
.container_type
) {
364 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
369 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
371 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
377 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
378 node
->u
.struct_or_variant_declaration
.type_specifier_list
->parent
= node
;
379 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
380 node
->u
.struct_or_variant_declaration
.type_specifier_list
);
383 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
385 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
391 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
393 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
399 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
401 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
405 cds_list_for_each_entry(iter
, &node
->u
._struct
.min_align
,
408 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
416 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,