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"
18 #include "decoder.hpp"
19 #include "ctf-meta.hpp"
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 UNARY_SIGNED_CONSTANT,
70 UNARY_UNSIGNED_CONSTANT,
75 UNARY_LINK_UNKNOWN = 0,
83 TYPEDEC_ID, /* identifier */
84 TYPEDEC_NESTED, /* (), array or sequence */
103 TYPESPEC_FLOATING_POINT,
113 * Parent node is only set on demand by specific visitor.
115 struct ctf_node *parent;
116 struct bt_list_head siblings;
117 struct bt_list_head tmp_head;
120 * We mark nodes visited in the generate-ir phase (last
121 * phase). We only mark the 1-depth level nodes as visited
122 * (never the root node, and not their sub-nodes). This allows
123 * skipping already visited nodes when doing incremental
134 * Children nodes are ctf_expression, field_class_def,
135 * field_class_alias and field_class_specifier_list.
137 struct bt_list_head declaration_list;
138 struct bt_list_head trace;
139 struct bt_list_head env;
140 struct bt_list_head stream;
141 struct bt_list_head event;
142 struct bt_list_head clock;
143 struct bt_list_head callsite;
147 * Children nodes are ctf_expression, field_class_def,
148 * field_class_alias and field_class_specifier_list.
150 struct bt_list_head declaration_list;
154 * Children nodes are ctf_expression, field_class_def,
155 * field_class_alias and field_class_specifier_list.
157 struct bt_list_head declaration_list;
161 * Children nodes are ctf_expression, field_class_def,
162 * field_class_alias and field_class_specifier_list.
164 struct bt_list_head declaration_list;
168 * Children nodes are ctf_expression, field_class_def,
169 * field_class_alias and field_class_specifier_list.
171 struct bt_list_head declaration_list;
175 * Children nodes are ctf_expression, field_class_def,
176 * field_class_alias and field_class_specifier_list.
178 struct bt_list_head declaration_list;
182 * Children nodes are ctf_expression, field_class_def,
183 * field_class_alias and field_class_specifier_list.
185 struct bt_list_head declaration_list;
188 struct bt_list_head left; /* Should be string */
189 struct bt_list_head right; /* Unary exp. or type */
195 * string for identifier, id_type, keywords,
196 * string literals and character constants.
199 int64_t signed_constant;
200 uint64_t unsigned_constant;
201 struct ctf_node *sbrac_exp;
206 struct ctf_node *field_class_specifier_list;
207 struct bt_list_head field_class_declarators;
209 /* new type is "alias", existing type "target" */
211 struct ctf_node *field_class_specifier_list;
212 struct bt_list_head field_class_declarators;
213 } field_class_alias_target;
215 struct ctf_node *field_class_specifier_list;
216 struct bt_list_head field_class_declarators;
217 } field_class_alias_name;
219 struct ctf_node *target;
220 struct ctf_node *alias;
224 /* For struct, variant and enum */
225 struct ctf_node *node;
227 } field_class_specifier;
229 /* list of field_class_specifier */
230 struct bt_list_head head;
231 } field_class_specifier_list;
233 unsigned int const_qualifier;
236 struct bt_list_head pointers;
241 /* typedec has no pointer list */
242 struct ctf_node *field_class_declarator;
244 * unary expression (value) or
245 * field_class_specifier_list.
247 struct bt_list_head length;
248 /* for abstract type declarator */
249 unsigned int abstract_array;
252 struct ctf_node *bitfield_len;
253 } field_class_declarator;
255 /* Children nodes are ctf_expression. */
256 struct bt_list_head expressions;
259 /* Children nodes are ctf_expression. */
260 struct bt_list_head expressions;
263 /* Children nodes are ctf_expression. */
264 struct bt_list_head expressions;
269 * Range list or single value node. Contains unary
272 struct bt_list_head values;
277 * Either NULL, or points to unary expression or
278 * field_class_specifier_list.
280 struct ctf_node *container_field_class;
281 struct bt_list_head enumerator_list;
285 struct ctf_node *field_class_specifier_list;
286 struct bt_list_head field_class_declarators;
287 } struct_or_variant_declaration;
292 * list of field_class_def, field_class_alias and
295 struct bt_list_head declaration_list;
301 * list of field_class_def, field_class_alias and
304 struct bt_list_head declaration_list;
306 struct bt_list_head min_align; /* align() attribute */
312 struct ctf_node root;
315 const char *node_type(struct ctf_node *node);
317 struct meta_log_config;
320 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
321 const struct ctf_metadata_decoder_config *config);
323 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor);
326 bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
327 struct ctf_visitor_generate_ir *visitor);
330 struct ctf_trace_class *ctf_visitor_generate_ir_borrow_ctf_trace_class(
331 struct ctf_visitor_generate_ir *visitor);
334 int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
335 struct ctf_node *node);
338 int ctf_visitor_semantic_check(int depth, struct ctf_node *node,
339 struct meta_log_config *log_cfg);
342 int ctf_visitor_parent_links(int depth, struct ctf_node *node,
343 struct meta_log_config *log_cfg);
346 char *ctf_ast_concatenate_unary_strings(struct bt_list_head *head)
350 struct ctf_node *node;
352 str = g_string_new(NULL);
355 bt_list_for_each_entry(node, head, siblings) {
359 node->type != NODE_UNARY_EXPRESSION ||
360 node->u.unary_expression.type != UNARY_STRING ||
363 node->u.unary_expression.link !=
371 switch (node->u.unary_expression.link) {
373 g_string_append(str, ".");
375 case UNARY_ARROWLINK:
376 g_string_append(str, "->");
378 case UNARY_DOTDOTDOT:
379 g_string_append(str, "...");
385 src_string = node->u.unary_expression.u.string;
386 g_string_append(str, src_string);
390 /* Destroys the container, returns the underlying string */
391 return g_string_free(str, FALSE);
394 /* This always returns NULL */
395 return g_string_free(str, TRUE);
399 int ctf_ast_get_unary_uuid(struct bt_list_head *head,
400 bt_uuid_t uuid, int log_level, bt_self_component *self_comp)
404 struct ctf_node *node;
406 bt_list_for_each_entry(node, head, siblings) {
407 int uexpr_type = node->u.unary_expression.type;
408 int uexpr_link = node->u.unary_expression.link;
409 const char *src_string;
411 if (node->type != NODE_UNARY_EXPRESSION ||
412 uexpr_type != UNARY_STRING ||
413 uexpr_link != UNARY_LINK_UNKNOWN ||
419 src_string = node->u.unary_expression.u.string;
420 ret = bt_uuid_from_str(src_string, uuid);
422 #ifdef BT_COMP_LOG_CUR_LVL
423 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level,
425 "Cannot parse UUID: uuid=\"%s\"", src_string);
435 #endif /* _CTF_AST_H */