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
:
96 case TYPESPEC_ID_TYPE
:
99 case TYPESPEC_UNKNOWN
:
101 fprintf(fd
, "[error] %s: unknown type specifier %d\n", __func__
,
102 (int) node
->u
.type_specifier
.type
);
109 int ctf_visitor_type_declarator(FILE *fd
, int depth
, struct ctf_node
*node
)
112 struct ctf_node
*iter
;
116 if (!cds_list_empty(&node
->u
.type_declarator
.pointers
)) {
117 cds_list_for_each_entry(iter
, &node
->u
.type_declarator
.pointers
,
120 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
126 switch (node
->u
.type_declarator
.type
) {
130 if (node
->u
.type_declarator
.u
.nested
.type_declarator
) {
131 node
->u
.type_declarator
.u
.nested
.type_declarator
->parent
= node
;
132 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
133 node
->u
.type_declarator
.u
.nested
.type_declarator
);
137 if (node
->u
.type_declarator
.u
.nested
.length
) {
138 node
->u
.type_declarator
.u
.nested
.length
->parent
= node
;
139 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
140 node
->u
.type_declarator
.u
.nested
.length
);
144 if (node
->u
.type_declarator
.bitfield_len
) {
145 node
->u
.type_declarator
.bitfield_len
= node
;
146 ret
= ctf_visitor_parent_links(fd
, depth
+ 1,
147 node
->u
.type_declarator
.bitfield_len
);
152 case TYPEDEC_UNKNOWN
:
154 fprintf(fd
, "[error] %s: unknown type declarator %d\n", __func__
,
155 (int) node
->u
.type_declarator
.type
);
162 int ctf_visitor_parent_links(FILE *fd
, int depth
, struct ctf_node
*node
)
165 struct ctf_node
*iter
;
167 switch (node
->type
) {
169 cds_list_for_each_entry(iter
, &node
->u
.root
._typedef
,
172 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
176 cds_list_for_each_entry(iter
, &node
->u
.root
.typealias
,
179 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
183 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_specifier
, 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 cds_list_for_each_entry(iter
, &node
->u
._typedef
.declaration_specifier
, siblings
) {
257 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
261 cds_list_for_each_entry(iter
, &node
->u
._typedef
.type_declarators
, siblings
) {
263 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
269 case NODE_TYPEALIAS_TARGET
:
271 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.declaration_specifier
, siblings
) {
273 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
277 cds_list_for_each_entry(iter
, &node
->u
.typealias_target
.type_declarators
, siblings
) {
279 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
285 case NODE_TYPEALIAS_ALIAS
:
287 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.declaration_specifier
, siblings
) {
289 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
293 cds_list_for_each_entry(iter
, &node
->u
.typealias_alias
.type_declarators
, siblings
) {
295 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
302 node
->u
.typealias
.target
->parent
= node
;
303 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.target
);
306 node
->u
.typealias
.alias
->parent
= node
;
307 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
.typealias
.alias
);
312 case NODE_TYPE_SPECIFIER
:
313 ret
= ctf_visitor_type_specifier(fd
, depth
, node
);
319 case NODE_TYPE_DECLARATOR
:
320 ret
= ctf_visitor_type_declarator(fd
, depth
, node
);
325 case NODE_FLOATING_POINT
:
326 cds_list_for_each_entry(iter
, &node
->u
.floating_point
.expressions
, siblings
) {
328 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
334 cds_list_for_each_entry(iter
, &node
->u
.integer
.expressions
, siblings
) {
336 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
342 cds_list_for_each_entry(iter
, &node
->u
.string
.expressions
, siblings
) {
344 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
349 case NODE_ENUMERATOR
:
350 cds_list_for_each_entry(iter
, &node
->u
.enumerator
.values
, siblings
) {
352 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
360 if (node
->u
._enum
.container_type
) {
361 node
->u
._enum
.container_type
->parent
= node
;
362 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, node
->u
._enum
.container_type
);
367 cds_list_for_each_entry(iter
, &node
->u
._enum
.enumerator_list
, siblings
) {
369 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
375 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
376 cds_list_for_each_entry(iter
, &node
->u
.struct_or_variant_declaration
.declaration_specifier
, siblings
) {
378 ret
= ctf_visitor_parent_links(fd
, depth
+ 1, iter
);
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__
,