7 * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
23 #include "common/list.h"
24 #include <babeltrace2/babeltrace.h>
25 #include "common/macros.h"
26 #include "common/assert.h"
31 // the parameter name (of the reentrant 'yyparse' function)
32 // data is a pointer to a 'SParserParam' structure
33 //#define YYPARSE_PARAM scanner
37 struct ctf_visitor_generate_ir
;
39 #define EINCOMPLETE 1000
41 #define FOREACH_CTF_NODES(F) \
51 F(NODE_CTF_EXPRESSION) \
52 F(NODE_UNARY_EXPRESSION) \
54 F(NODE_TYPEALIAS_TARGET) \
55 F(NODE_TYPEALIAS_ALIAS) \
57 F(NODE_TYPE_SPECIFIER) \
58 F(NODE_TYPE_SPECIFIER_LIST) \
60 F(NODE_TYPE_DECLARATOR) \
61 F(NODE_FLOATING_POINT) \
66 F(NODE_STRUCT_OR_VARIANT_DECLARATION) \
72 FOREACH_CTF_NODES(ENTRY
)
79 * Parent node is only set on demand by specific visitor.
81 struct ctf_node
*parent
;
82 struct bt_list_head siblings
;
83 struct bt_list_head tmp_head
;
86 * We mark nodes visited in the generate-ir phase (last
87 * phase). We only mark the 1-depth level nodes as visited
88 * (never the root node, and not their sub-nodes). This allows
89 * skipping already visited nodes when doing incremental
100 * Children nodes are ctf_expression, field_class_def,
101 * field_class_alias and field_class_specifier_list.
103 struct bt_list_head declaration_list
;
104 struct bt_list_head trace
;
105 struct bt_list_head env
;
106 struct bt_list_head stream
;
107 struct bt_list_head event
;
108 struct bt_list_head clock
;
109 struct bt_list_head callsite
;
113 * Children nodes are ctf_expression, field_class_def,
114 * field_class_alias and field_class_specifier_list.
116 struct bt_list_head declaration_list
;
120 * Children nodes are ctf_expression, field_class_def,
121 * field_class_alias and field_class_specifier_list.
123 struct bt_list_head declaration_list
;
127 * Children nodes are ctf_expression, field_class_def,
128 * field_class_alias and field_class_specifier_list.
130 struct bt_list_head declaration_list
;
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
;
141 * Children nodes are ctf_expression, field_class_def,
142 * field_class_alias and field_class_specifier_list.
144 struct bt_list_head declaration_list
;
148 * Children nodes are ctf_expression, field_class_def,
149 * field_class_alias and field_class_specifier_list.
151 struct bt_list_head declaration_list
;
154 struct bt_list_head left
; /* Should be string */
155 struct bt_list_head right
; /* Unary exp. or type */
161 UNARY_SIGNED_CONSTANT
,
162 UNARY_UNSIGNED_CONSTANT
,
167 * string for identifier, id_type, keywords,
168 * string literals and character constants.
171 int64_t signed_constant
;
172 uint64_t unsigned_constant
;
173 struct ctf_node
*sbrac_exp
;
176 UNARY_LINK_UNKNOWN
= 0,
183 struct ctf_node
*field_class_specifier_list
;
184 struct bt_list_head field_class_declarators
;
186 /* new type is "alias", existing type "target" */
188 struct ctf_node
*field_class_specifier_list
;
189 struct bt_list_head field_class_declarators
;
190 } field_class_alias_target
;
192 struct ctf_node
*field_class_specifier_list
;
193 struct bt_list_head field_class_declarators
;
194 } field_class_alias_name
;
196 struct ctf_node
*target
;
197 struct ctf_node
*alias
;
201 TYPESPEC_UNKNOWN
= 0,
216 TYPESPEC_FLOATING_POINT
,
223 /* For struct, variant and enum */
224 struct ctf_node
*node
;
226 } field_class_specifier
;
228 /* list of field_class_specifier */
229 struct bt_list_head head
;
230 } field_class_specifier_list
;
232 unsigned int const_qualifier
;
235 struct bt_list_head pointers
;
238 TYPEDEC_ID
, /* identifier */
239 TYPEDEC_NESTED
, /* (), array or sequence */
244 /* typedec has no pointer list */
245 struct ctf_node
*field_class_declarator
;
247 * unary expression (value) or
248 * field_class_specifier_list.
250 struct bt_list_head length
;
251 /* for abstract type declarator */
252 unsigned int abstract_array
;
255 struct ctf_node
*bitfield_len
;
256 } field_class_declarator
;
258 /* Children nodes are ctf_expression. */
259 struct bt_list_head expressions
;
262 /* Children nodes are ctf_expression. */
263 struct bt_list_head expressions
;
266 /* Children nodes are ctf_expression. */
267 struct bt_list_head expressions
;
272 * Range list or single value node. Contains unary
275 struct bt_list_head values
;
280 * Either NULL, or points to unary expression or
281 * field_class_specifier_list.
283 struct ctf_node
*container_field_class
;
284 struct bt_list_head enumerator_list
;
288 struct ctf_node
*field_class_specifier_list
;
289 struct bt_list_head field_class_declarators
;
290 } struct_or_variant_declaration
;
295 * list of field_class_def, field_class_alias and
298 struct bt_list_head declaration_list
;
304 * list of field_class_def, field_class_alias and
307 struct bt_list_head declaration_list
;
309 struct bt_list_head min_align
; /* align() attribute */
315 struct ctf_node root
;
318 const char *node_type(struct ctf_node
*node
);
320 struct meta_log_config
;
323 struct ctf_visitor_generate_ir
*ctf_visitor_generate_ir_create(
324 const struct ctf_metadata_decoder_config
*config
);
326 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir
*visitor
);
329 bt_trace_class
*ctf_visitor_generate_ir_get_ir_trace_class(
330 struct ctf_visitor_generate_ir
*visitor
);
333 struct ctf_trace_class
*ctf_visitor_generate_ir_borrow_ctf_trace_class(
334 struct ctf_visitor_generate_ir
*visitor
);
337 int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir
*visitor
,
338 struct ctf_node
*node
);
341 int ctf_visitor_semantic_check(int depth
, struct ctf_node
*node
,
342 struct meta_log_config
*log_cfg
);
345 int ctf_visitor_parent_links(int depth
, struct ctf_node
*node
,
346 struct meta_log_config
*log_cfg
);
349 char *ctf_ast_concatenate_unary_strings(struct bt_list_head
*head
)
353 struct ctf_node
*node
;
355 str
= g_string_new(NULL
);
358 bt_list_for_each_entry(node
, head
, siblings
) {
362 node
->type
!= NODE_UNARY_EXPRESSION
||
363 node
->u
.unary_expression
.type
!= UNARY_STRING
||
366 node
->u
.unary_expression
.link
!=
374 switch (node
->u
.unary_expression
.link
) {
376 g_string_append(str
, ".");
378 case UNARY_ARROWLINK
:
379 g_string_append(str
, "->");
381 case UNARY_DOTDOTDOT
:
382 g_string_append(str
, "...");
388 src_string
= node
->u
.unary_expression
.u
.string
;
389 g_string_append(str
, src_string
);
393 /* Destroys the container, returns the underlying string */
394 return g_string_free(str
, FALSE
);
397 /* This always returns NULL */
398 return g_string_free(str
, TRUE
);
402 int ctf_ast_get_unary_uuid(struct bt_list_head
*head
,
403 bt_uuid_t uuid
, int log_level
, bt_self_component
*self_comp
)
407 struct ctf_node
*node
;
409 bt_list_for_each_entry(node
, head
, siblings
) {
410 int uexpr_type
= node
->u
.unary_expression
.type
;
411 int uexpr_link
= node
->u
.unary_expression
.link
;
412 const char *src_string
;
414 if (node
->type
!= NODE_UNARY_EXPRESSION
||
415 uexpr_type
!= UNARY_STRING
||
416 uexpr_link
!= UNARY_LINK_UNKNOWN
||
422 src_string
= node
->u
.unary_expression
.u
.string
;
423 ret
= bt_uuid_from_str(src_string
, uuid
);
425 #ifdef BT_COMP_LOG_CUR_LVL
426 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
,
428 "Cannot parse UUID: uuid=\"%s\"", src_string
);
438 #endif /* _CTF_AST_H */