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/list.h>
28 #include "ctf-scanner.h"
29 #include "ctf-parser.h"
32 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
35 int ctf_visitor_unary_expression(FILE *fd
, int depth
, struct ctf_node
*node
)
39 switch (node
->u
.unary_expression
.link
) {
40 case UNARY_LINK_UNKNOWN
:
46 fprintf(fd
, "[error] %s: unknown expression link type %d\n", __func__
,
47 (int) node
->u
.unary_expression
.link
);
51 switch (node
->u
.unary_expression
.type
) {
53 case UNARY_SIGNED_CONSTANT
:
54 case UNARY_UNSIGNED_CONSTANT
:
57 node
->u
.unary_expression
.u
.sbrac_exp
->parent
= node
;
58 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
59 node
->u
.unary_expression
.u
.sbrac_exp
);
64 node
->u
.unary_expression
.u
.nested_exp
->parent
= node
;
65 ret
= ctf_visitor_unary_expression(fd
, depth
+ 1,
66 node
->u
.unary_expression
.u
.nested_exp
);
73 fprintf(fd
, "[error] %s: unknown expression type %d\n", __func__
,
74 (int) node
->u
.unary_expression
.type
);
81 int ctf_visitor_type_specifier(FILE *fd
, int depth
, struct ctf_node
*node
)
83 switch (node
->u
.type_specifier
.type
) {
92 case TYPESPEC_UNSIGNED
:
94 case TYPESPEC_COMPLEX
:
95 case TYPESPEC_IMAGINARY
:
97 case TYPESPEC_ID_TYPE
:
100 case TYPESPEC_UNKNOWN
:
102 fprintf(fd
, "[error] %s: unknown type specifier %d\n", __func__
,
103 (int) node
->u
.type_specifier
.type
);
110 int ctf_visitor_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
113 struct ctf_node
*iter
;
117 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
118 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
121 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
127 switch (node
->u
.type_declarator
.type
) {
131 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
132 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
133 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
134 node
->u
.type_declarator
.u
.nested
.type_declarator
);
138 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.u
.nested
.length
,
141 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
145 if (node
->u
.type_declarator
.bitfield_len
) {
146 node
->u
.type_declarator
.bitfield_len
= node
;
147 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
148 node
->u
.type_declarator
.bitfield_len
);
153 case TYPEDEC_UNKNOWN
:
155 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
156 (int) node
->u
.type_declarator
.type
);
163 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
166 struct ctf_node
*iter
;
168 switch (node
->type
) {
170 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
173 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
177 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
180 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
184 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, 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 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
258 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
262 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
264 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
270 case NODE_TYPEALIAS_TARGET
:
272 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
274 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
278 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
280 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
286 case NODE_TYPEALIAS_ALIAS
:
288 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
290 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
294 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
296 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
303 node
->u
.typealias
.target
->parent
= node
;
304 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
307 node
->u
.typealias
.alias
->parent
= node
;
308 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
313 case NODE_TYPE_SPECIFIER
:
314 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
320 case NODE_TYPE_DECLARATOR
:
321 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
326 case NODE_FLOATING_POINT
:
327 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
329 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
335 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
337 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
343 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
345 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
350 case NODE_ENUMERATOR
:
351 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
353 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
361 cds_list_for_each_entry(iter
, &node
->u
._enum
.container_type
,
364 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
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 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
380 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
384 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.type_declarators
, siblings
) {
386 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
392 cds_list_for_each_entry(iter
, &node
->u
.variant
.declaration_list
, siblings
) {
394 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
400 cds_list_for_each_entry(iter
, &node
->u
._struct
.declaration_list
, siblings
) {
402 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
410 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,