2 * SPDX-License-Identifier: MIT
4 * Copyright 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include "common/list.h"
14 #include <babeltrace2/babeltrace.h>
15 #include "common/macros.h"
16 #include "common/assert.h"
21 // the parameter name (of the reentrant 'yyparse' function)
22 // data is a pointer to a 'SParserParam' structure
23 //#define YYPARSE_PARAM scanner
27 struct ctf_visitor_generate_ir
;
29 #define EINCOMPLETE 1000
31 #define FOREACH_CTF_NODES(F) \
41 F(NODE_CTF_EXPRESSION) \
42 F(NODE_UNARY_EXPRESSION) \
44 F(NODE_TYPEALIAS_TARGET) \
45 F(NODE_TYPEALIAS_ALIAS) \
47 F(NODE_TYPE_SPECIFIER) \
48 F(NODE_TYPE_SPECIFIER_LIST) \
50 F(NODE_TYPE_DECLARATOR) \
51 F(NODE_FLOATING_POINT) \
56 F(NODE_STRUCT_OR_VARIANT_DECLARATION) \
62 FOREACH_CTF_NODES(ENTRY
)
69 * Parent node is only set on demand by specific visitor.
71 struct ctf_node
*parent
;
72 struct bt_list_head siblings
;
73 struct bt_list_head tmp_head
;
76 * We mark nodes visited in the generate-ir phase (last
77 * phase). We only mark the 1-depth level nodes as visited
78 * (never the root node, and not their sub-nodes). This allows
79 * skipping already visited nodes when doing incremental
90 * Children nodes are ctf_expression, field_class_def,
91 * field_class_alias and field_class_specifier_list.
93 struct bt_list_head declaration_list
;
94 struct bt_list_head trace
;
95 struct bt_list_head env
;
96 struct bt_list_head stream
;
97 struct bt_list_head event
;
98 struct bt_list_head clock
;
99 struct bt_list_head callsite
;
103 * Children nodes are ctf_expression, field_class_def,
104 * field_class_alias and field_class_specifier_list.
106 struct bt_list_head declaration_list
;
110 * Children nodes are ctf_expression, field_class_def,
111 * field_class_alias and field_class_specifier_list.
113 struct bt_list_head declaration_list
;
117 * Children nodes are ctf_expression, field_class_def,
118 * field_class_alias and field_class_specifier_list.
120 struct bt_list_head declaration_list
;
124 * Children nodes are ctf_expression, field_class_def,
125 * field_class_alias and field_class_specifier_list.
127 struct bt_list_head declaration_list
;
131 * Children nodes are ctf_expression, field_class_def,
132 * field_class_alias and field_class_specifier_list.
134 struct bt_list_head declaration_list
;
138 * Children nodes are ctf_expression, field_class_def,
139 * field_class_alias and field_class_specifier_list.
141 struct bt_list_head declaration_list
;
144 struct bt_list_head left
; /* Should be string */
145 struct bt_list_head right
; /* Unary exp. or type */
151 UNARY_SIGNED_CONSTANT
,
152 UNARY_UNSIGNED_CONSTANT
,
157 * string for identifier, id_type, keywords,
158 * string literals and character constants.
161 int64_t signed_constant
;
162 uint64_t unsigned_constant
;
163 struct ctf_node
*sbrac_exp
;
166 UNARY_LINK_UNKNOWN
= 0,
173 struct ctf_node
*field_class_specifier_list
;
174 struct bt_list_head field_class_declarators
;
176 /* new type is "alias", existing type "target" */
178 struct ctf_node
*field_class_specifier_list
;
179 struct bt_list_head field_class_declarators
;
180 } field_class_alias_target
;
182 struct ctf_node
*field_class_specifier_list
;
183 struct bt_list_head field_class_declarators
;
184 } field_class_alias_name
;
186 struct ctf_node
*target
;
187 struct ctf_node
*alias
;
191 TYPESPEC_UNKNOWN
= 0,
206 TYPESPEC_FLOATING_POINT
,
213 /* For struct, variant and enum */
214 struct ctf_node
*node
;
216 } field_class_specifier
;
218 /* list of field_class_specifier */
219 struct bt_list_head head
;
220 } field_class_specifier_list
;
222 unsigned int const_qualifier
;
225 struct bt_list_head pointers
;
228 TYPEDEC_ID
, /* identifier */
229 TYPEDEC_NESTED
, /* (), array or sequence */
234 /* typedec has no pointer list */
235 struct ctf_node
*field_class_declarator
;
237 * unary expression (value) or
238 * field_class_specifier_list.
240 struct bt_list_head length
;
241 /* for abstract type declarator */
242 unsigned int abstract_array
;
245 struct ctf_node
*bitfield_len
;
246 } field_class_declarator
;
248 /* Children nodes are ctf_expression. */
249 struct bt_list_head expressions
;
252 /* Children nodes are ctf_expression. */
253 struct bt_list_head expressions
;
256 /* Children nodes are ctf_expression. */
257 struct bt_list_head expressions
;
262 * Range list or single value node. Contains unary
265 struct bt_list_head values
;
270 * Either NULL, or points to unary expression or
271 * field_class_specifier_list.
273 struct ctf_node
*container_field_class
;
274 struct bt_list_head enumerator_list
;
278 struct ctf_node
*field_class_specifier_list
;
279 struct bt_list_head field_class_declarators
;
280 } struct_or_variant_declaration
;
285 * list of field_class_def, field_class_alias and
288 struct bt_list_head declaration_list
;
294 * list of field_class_def, field_class_alias and
297 struct bt_list_head declaration_list
;
299 struct bt_list_head min_align
; /* align() attribute */
305 struct ctf_node root
;
308 const char *node_type(struct ctf_node
*node
);
310 struct meta_log_config
;
313 struct ctf_visitor_generate_ir
*ctf_visitor_generate_ir_create(
314 const struct ctf_metadata_decoder_config
*config
);
316 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir
*visitor
);
319 bt_trace_class
*ctf_visitor_generate_ir_get_ir_trace_class(
320 struct ctf_visitor_generate_ir
*visitor
);
323 struct ctf_trace_class
*ctf_visitor_generate_ir_borrow_ctf_trace_class(
324 struct ctf_visitor_generate_ir
*visitor
);
327 int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir
*visitor
,
328 struct ctf_node
*node
);
331 int ctf_visitor_semantic_check(int depth
, struct ctf_node
*node
,
332 struct meta_log_config
*log_cfg
);
335 int ctf_visitor_parent_links(int depth
, struct ctf_node
*node
,
336 struct meta_log_config
*log_cfg
);
339 char *ctf_ast_concatenate_unary_strings(struct bt_list_head
*head
)
343 struct ctf_node
*node
;
345 str
= g_string_new(NULL
);
348 bt_list_for_each_entry(node
, head
, siblings
) {
352 node
->type
!= NODE_UNARY_EXPRESSION
||
353 node
->u
.unary_expression
.type
!= UNARY_STRING
||
356 node
->u
.unary_expression
.link
!=
364 switch (node
->u
.unary_expression
.link
) {
366 g_string_append(str
, ".");
368 case UNARY_ARROWLINK
:
369 g_string_append(str
, "->");
371 case UNARY_DOTDOTDOT
:
372 g_string_append(str
, "...");
378 src_string
= node
->u
.unary_expression
.u
.string
;
379 g_string_append(str
, src_string
);
383 /* Destroys the container, returns the underlying string */
384 return g_string_free(str
, FALSE
);
387 /* This always returns NULL */
388 return g_string_free(str
, TRUE
);
392 int ctf_ast_get_unary_uuid(struct bt_list_head
*head
,
393 bt_uuid_t uuid
, int log_level
, bt_self_component
*self_comp
)
397 struct ctf_node
*node
;
399 bt_list_for_each_entry(node
, head
, siblings
) {
400 int uexpr_type
= node
->u
.unary_expression
.type
;
401 int uexpr_link
= node
->u
.unary_expression
.link
;
402 const char *src_string
;
404 if (node
->type
!= NODE_UNARY_EXPRESSION
||
405 uexpr_type
!= UNARY_STRING
||
406 uexpr_link
!= UNARY_LINK_UNKNOWN
||
412 src_string
= node
->u
.unary_expression
.u
.string
;
413 ret
= bt_uuid_from_str(src_string
, uuid
);
415 #ifdef BT_COMP_LOG_CUR_LVL
416 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
,
418 "Cannot parse UUID: uuid=\"%s\"", src_string
);
428 #endif /* _CTF_AST_H */