2 * ctf-visitor-generate-ir.c
4 * Common Trace Format metadata visitor (generates CTF IR objects).
6 * Based on older ctf-visitor-generate-io-struct.c.
8 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Copyright 2015-2016 - Philippe Proulx <philippe.proulx@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-IR-VISITOR"
43 #include <babeltrace/compat/uuid-internal.h>
44 #include <babeltrace/endian-internal.h>
45 #include <babeltrace/ref.h>
46 #include <babeltrace/ctf-ir/trace.h>
47 #include <babeltrace/ctf-ir/stream-class.h>
48 #include <babeltrace/ctf-ir/event.h>
49 #include <babeltrace/ctf-ir/event-class.h>
50 #include <babeltrace/ctf-ir/field-types.h>
51 #include <babeltrace/ctf-ir/field-types-internal.h>
52 #include <babeltrace/ctf-ir/clock-class.h>
58 /* Bit value (left shift) */
59 #define _BV(_val) (1 << (_val))
61 /* Bit is set in a set of bits */
62 #define _IS_SET(_set, _mask) (*(_set) & (_mask))
64 /* Set bit in a set of bits */
65 #define _SET(_set, _mask) (*(_set) |= (_mask))
67 /* Bits for verifying existing attributes in various declarations */
69 _CLOCK_NAME_SET
= _BV(0),
70 _CLOCK_UUID_SET
= _BV(1),
71 _CLOCK_FREQ_SET
= _BV(2),
72 _CLOCK_PRECISION_SET
= _BV(3),
73 _CLOCK_OFFSET_S_SET
= _BV(4),
74 _CLOCK_OFFSET_SET
= _BV(5),
75 _CLOCK_ABSOLUTE_SET
= _BV(6),
76 _CLOCK_DESCRIPTION_SET
= _BV(7),
80 _INTEGER_ALIGN_SET
= _BV(0),
81 _INTEGER_SIZE_SET
= _BV(1),
82 _INTEGER_BASE_SET
= _BV(2),
83 _INTEGER_ENCODING_SET
= _BV(3),
84 _INTEGER_BYTE_ORDER_SET
= _BV(4),
85 _INTEGER_SIGNED_SET
= _BV(5),
86 _INTEGER_MAP_SET
= _BV(6),
90 _FLOAT_ALIGN_SET
= _BV(0),
91 _FLOAT_MANT_DIG_SET
= _BV(1),
92 _FLOAT_EXP_DIG_SET
= _BV(2),
93 _FLOAT_BYTE_ORDER_SET
= _BV(3),
97 _STRING_ENCODING_SET
= _BV(0),
101 _TRACE_MINOR_SET
= _BV(0),
102 _TRACE_MAJOR_SET
= _BV(1),
103 _TRACE_BYTE_ORDER_SET
= _BV(2),
104 _TRACE_UUID_SET
= _BV(3),
105 _TRACE_PACKET_HEADER_SET
= _BV(4),
109 _STREAM_ID_SET
= _BV(0),
110 _STREAM_PACKET_CONTEXT_SET
= _BV(1),
111 _STREAM_EVENT_HEADER_SET
= _BV(2),
112 _STREAM_EVENT_CONTEXT_SET
= _BV(3),
116 _EVENT_NAME_SET
= _BV(0),
117 _EVENT_ID_SET
= _BV(1),
118 _EVENT_MODEL_EMF_URI_SET
= _BV(2),
119 _EVENT_STREAM_ID_SET
= _BV(3),
120 _EVENT_LOGLEVEL_SET
= _BV(4),
121 _EVENT_CONTEXT_SET
= _BV(5),
122 _EVENT_FIELDS_SET
= _BV(6),
130 LOGLEVEL_WARNING
= 4,
133 LOGLEVEL_DEBUG_SYSTEM
= 7,
134 LOGLEVEL_DEBUG_PROGRAM
= 8,
135 LOGLEVEL_DEBUG_PROCESS
= 9,
136 LOGLEVEL_DEBUG_MODULE
= 10,
137 LOGLEVEL_DEBUG_UNIT
= 11,
138 LOGLEVEL_DEBUG_FUNCTION
= 12,
139 LOGLEVEL_DEBUG_LINE
= 13,
144 /* Prefixes of type aliases */
145 #define _PREFIX_ALIAS 'a'
146 #define _PREFIX_ENUM 'e'
147 #define _PREFIX_STRUCT 's'
148 #define _PREFIX_VARIANT 'v'
150 /* First entry in a BT list */
151 #define _BT_LIST_FIRST_ENTRY(_ptr, _type, _member) \
152 bt_list_entry((_ptr)->next, _type, _member)
154 #define _BT_CTF_FIELD_TYPE_INIT(_name) struct bt_ctf_field_type *_name = NULL;
156 #define _BT_LOGE_DUP_ATTR(_attr, _entity) \
158 BT_LOGE("Duplicate attribute in %s: attr-name=\"%s\"", \
163 * Declaration scope of a visitor context. This represents a TSDL
164 * lexical scope, so that aliases and named structures, variants,
165 * and enumerations may be registered and looked up hierarchically.
167 struct ctx_decl_scope
{
169 * Alias name to field type.
171 * GQuark -> struct bt_ctf_field_type *
173 GHashTable
*decl_map
;
175 /* Parent scope; NULL if this is the root declaration scope */
176 struct ctx_decl_scope
*parent_scope
;
180 * Visitor context (private).
183 /* Trace being filled (owned by this) */
184 struct bt_ctf_trace
*trace
;
186 /* Current declaration scope (top of the stack) */
187 struct ctx_decl_scope
*current_scope
;
189 /* 1 if trace declaration is visited */
190 int is_trace_visited
;
192 /* 1 if this is an LTTng trace */
195 /* Offset (ns) to apply to clock classes on creation */
196 int64_t clock_class_offset_ns
;
198 /* Eventual name suffix of the trace to set */
199 char *trace_name_suffix
;
201 /* Trace attributes */
202 enum bt_ctf_byte_order trace_bo
;
203 uint64_t trace_major
;
204 uint64_t trace_minor
;
205 unsigned char trace_uuid
[BABELTRACE_UUID_LEN
];
208 * Stream IDs to stream classes.
210 * int64_t -> struct bt_ctf_stream_class *
212 GHashTable
*stream_classes
;
218 struct ctf_visitor_generate_ir
{ };
221 const char *loglevel_str
[] = {
222 [ LOGLEVEL_EMERG
] = "TRACE_EMERG",
223 [ LOGLEVEL_ALERT
] = "TRACE_ALERT",
224 [ LOGLEVEL_CRIT
] = "TRACE_CRIT",
225 [ LOGLEVEL_ERR
] = "TRACE_ERR",
226 [ LOGLEVEL_WARNING
] = "TRACE_WARNING",
227 [ LOGLEVEL_NOTICE
] = "TRACE_NOTICE",
228 [ LOGLEVEL_INFO
] = "TRACE_INFO",
229 [ LOGLEVEL_DEBUG_SYSTEM
] = "TRACE_DEBUG_SYSTEM",
230 [ LOGLEVEL_DEBUG_PROGRAM
] = "TRACE_DEBUG_PROGRAM",
231 [ LOGLEVEL_DEBUG_PROCESS
] = "TRACE_DEBUG_PROCESS",
232 [ LOGLEVEL_DEBUG_MODULE
] = "TRACE_DEBUG_MODULE",
233 [ LOGLEVEL_DEBUG_UNIT
] = "TRACE_DEBUG_UNIT",
234 [ LOGLEVEL_DEBUG_FUNCTION
] = "TRACE_DEBUG_FUNCTION",
235 [ LOGLEVEL_DEBUG_LINE
] = "TRACE_DEBUG_LINE",
236 [ LOGLEVEL_DEBUG
] = "TRACE_DEBUG",
240 const char *print_loglevel(int64_t value
)
245 if (value
>= _NR_LOGLEVELS
) {
246 return "<<UNKNOWN>>";
248 return loglevel_str
[value
];
252 * Creates a new declaration scope.
254 * @param par_scope Parent scope (NULL if creating a root scope)
255 * @returns New declaration scope, or NULL on error
258 struct ctx_decl_scope
*ctx_decl_scope_create(struct ctx_decl_scope
*par_scope
)
260 struct ctx_decl_scope
*scope
;
262 scope
= g_new(struct ctx_decl_scope
, 1);
267 scope
->decl_map
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
268 NULL
, (GDestroyNotify
) bt_ctf_field_type_put
);
269 scope
->parent_scope
= par_scope
;
276 * Destroys a declaration scope.
278 * This function does not destroy the parent scope.
280 * @param scope Scope to destroy
283 void ctx_decl_scope_destroy(struct ctx_decl_scope
*scope
)
289 g_hash_table_destroy(scope
->decl_map
);
297 * Returns the GQuark of a prefixed alias.
299 * @param prefix Prefix character
301 * @returns Associated GQuark, or 0 on error
304 GQuark
get_prefixed_named_quark(char prefix
, const char *name
)
310 /* Prefix character + original string + '\0' */
311 char *prname
= g_new(char, strlen(name
) + 2);
316 sprintf(prname
, "%c%s", prefix
, name
);
317 qname
= g_quark_from_string(prname
);
325 * Looks up a prefixed type alias within a declaration scope.
327 * @param scope Declaration scope
328 * @param prefix Prefix character
329 * @param name Alias name
330 * @param level Number of levels to dig (-1 means infinite)
331 * @returns Declaration, or NULL if not found
334 struct bt_ctf_field_type
*ctx_decl_scope_lookup_prefix_alias(
335 struct ctx_decl_scope
*scope
, char prefix
,
336 const char *name
, int levels
)
340 _BT_CTF_FIELD_TYPE_INIT(decl
);
341 struct ctx_decl_scope
*cur_scope
= scope
;
345 qname
= get_prefixed_named_quark(prefix
, name
);
354 while (cur_scope
&& cur_levels
< levels
) {
355 decl
= g_hash_table_lookup(cur_scope
->decl_map
,
356 (gconstpointer
) GUINT_TO_POINTER(qname
));
358 /* Caller's reference */
363 cur_scope
= cur_scope
->parent_scope
;
374 * Looks up a type alias within a declaration scope.
376 * @param scope Declaration scope
377 * @param name Alias name
378 * @param level Number of levels to dig (-1 means infinite)
379 * @returns Declaration, or NULL if not found
382 struct bt_ctf_field_type
*ctx_decl_scope_lookup_alias(
383 struct ctx_decl_scope
*scope
, const char *name
, int levels
)
385 return ctx_decl_scope_lookup_prefix_alias(scope
, _PREFIX_ALIAS
,
390 * Looks up an enumeration within a declaration scope.
392 * @param scope Declaration scope
393 * @param name Enumeration name
394 * @param level Number of levels to dig (-1 means infinite)
395 * @returns Declaration, or NULL if not found
398 struct bt_ctf_field_type
*ctx_decl_scope_lookup_enum(
399 struct ctx_decl_scope
*scope
, const char *name
, int levels
)
401 return ctx_decl_scope_lookup_prefix_alias(scope
, _PREFIX_ENUM
,
406 * Looks up a structure within a declaration scope.
408 * @param scope Declaration scope
409 * @param name Structure name
410 * @param level Number of levels to dig (-1 means infinite)
411 * @returns Declaration, or NULL if not found
414 struct bt_ctf_field_type
*ctx_decl_scope_lookup_struct(
415 struct ctx_decl_scope
*scope
, const char *name
, int levels
)
417 return ctx_decl_scope_lookup_prefix_alias(scope
, _PREFIX_STRUCT
,
422 * Looks up a variant within a declaration scope.
424 * @param scope Declaration scope
425 * @param name Variant name
426 * @param level Number of levels to dig (-1 means infinite)
427 * @returns Declaration, or NULL if not found
430 struct bt_ctf_field_type
*ctx_decl_scope_lookup_variant(
431 struct ctx_decl_scope
*scope
, const char *name
, int levels
)
433 return ctx_decl_scope_lookup_prefix_alias(scope
, _PREFIX_VARIANT
,
438 * Registers a prefixed type alias within a declaration scope.
440 * @param scope Declaration scope
441 * @param prefix Prefix character
442 * @param name Alias name (non-NULL)
443 * @param decl Declaration to register
444 * @returns 0 if registration went okay, negative value otherwise
447 int ctx_decl_scope_register_prefix_alias(struct ctx_decl_scope
*scope
,
448 char prefix
, const char *name
, struct bt_ctf_field_type
*decl
)
452 _BT_CTF_FIELD_TYPE_INIT(edecl
);
457 qname
= get_prefixed_named_quark(prefix
, name
);
463 /* Make sure alias does not exist in local scope */
464 edecl
= ctx_decl_scope_lookup_prefix_alias(scope
, prefix
, name
, 1);
471 g_hash_table_insert(scope
->decl_map
,
472 GUINT_TO_POINTER(qname
), decl
);
474 /* Hash table's reference */
484 * Registers a type alias within a declaration scope.
486 * @param scope Declaration scope
487 * @param name Alias name (non-NULL)
488 * @param decl Declaration to register
489 * @returns 0 if registration went okay, negative value otherwise
492 int ctx_decl_scope_register_alias(struct ctx_decl_scope
*scope
,
493 const char *name
, struct bt_ctf_field_type
*decl
)
495 return ctx_decl_scope_register_prefix_alias(scope
, _PREFIX_ALIAS
,
500 * Registers an enumeration declaration within a declaration scope.
502 * @param scope Declaration scope
503 * @param name Enumeration name (non-NULL)
504 * @param decl Enumeration declaration to register
505 * @returns 0 if registration went okay, negative value otherwise
508 int ctx_decl_scope_register_enum(struct ctx_decl_scope
*scope
,
509 const char *name
, struct bt_ctf_field_type
*decl
)
511 return ctx_decl_scope_register_prefix_alias(scope
, _PREFIX_ENUM
,
516 * Registers a structure declaration within a declaration scope.
518 * @param scope Declaration scope
519 * @param name Structure name (non-NULL)
520 * @param decl Structure declaration to register
521 * @returns 0 if registration went okay, negative value otherwise
524 int ctx_decl_scope_register_struct(struct ctx_decl_scope
*scope
,
525 const char *name
, struct bt_ctf_field_type
*decl
)
527 return ctx_decl_scope_register_prefix_alias(scope
, _PREFIX_STRUCT
,
532 * Registers a variant declaration within a declaration scope.
534 * @param scope Declaration scope
535 * @param name Variant name (non-NULL)
536 * @param decl Variant declaration to register
537 * @returns 0 if registration went okay, negative value otherwise
540 int ctx_decl_scope_register_variant(struct ctx_decl_scope
*scope
,
541 const char *name
, struct bt_ctf_field_type
*decl
)
543 return ctx_decl_scope_register_prefix_alias(scope
, _PREFIX_VARIANT
,
548 * Destroys a visitor context.
550 * @param ctx Visitor context to destroy
553 void ctx_destroy(struct ctx
*ctx
)
555 struct ctx_decl_scope
*scope
;
557 * Destroy all scopes, from current one to the root scope.
564 scope
= ctx
->current_scope
;
567 struct ctx_decl_scope
*parent_scope
= scope
->parent_scope
;
569 ctx_decl_scope_destroy(scope
);
570 scope
= parent_scope
;
575 if (ctx
->stream_classes
) {
576 g_hash_table_destroy(ctx
->stream_classes
);
579 free(ctx
->trace_name_suffix
);
587 * Creates a new visitor context.
589 * @param trace Associated trace
590 * @returns New visitor context, or NULL on error
593 struct ctx
*ctx_create(struct bt_ctf_trace
*trace
,
594 int64_t clock_class_offset_ns
, const char *trace_name_suffix
)
596 struct ctx
*ctx
= NULL
;
597 struct ctx_decl_scope
*scope
= NULL
;
599 ctx
= g_new0(struct ctx
, 1);
604 /* Root declaration scope */
605 scope
= ctx_decl_scope_create(NULL
);
610 ctx
->stream_classes
= g_hash_table_new_full(g_direct_hash
,
611 g_direct_equal
, NULL
, (GDestroyNotify
) bt_put
);
612 if (!ctx
->stream_classes
) {
616 if (trace_name_suffix
) {
617 ctx
->trace_name_suffix
= strdup(trace_name_suffix
);
618 if (!ctx
->trace_name_suffix
) {
624 ctx
->current_scope
= scope
;
626 ctx
->trace_bo
= BT_CTF_BYTE_ORDER_NATIVE
;
627 ctx
->clock_class_offset_ns
= clock_class_offset_ns
;
632 ctx_decl_scope_destroy(scope
);
637 * Pushes a new declaration scope on top of a visitor context's
638 * declaration scope stack.
640 * @param ctx Visitor context
641 * @returns 0 on success, or a negative value on error
644 int ctx_push_scope(struct ctx
*ctx
)
647 struct ctx_decl_scope
*new_scope
;
650 new_scope
= ctx_decl_scope_create(ctx
->current_scope
);
656 ctx
->current_scope
= new_scope
;
663 void ctx_pop_scope(struct ctx
*ctx
)
665 struct ctx_decl_scope
*parent_scope
= NULL
;
669 if (!ctx
->current_scope
) {
673 parent_scope
= ctx
->current_scope
->parent_scope
;
674 ctx_decl_scope_destroy(ctx
->current_scope
);
675 ctx
->current_scope
= parent_scope
;
682 int visit_type_specifier_list(struct ctx
*ctx
, struct ctf_node
*ts_list
,
683 struct bt_ctf_field_type
**decl
);
686 int is_unary_string(struct bt_list_head
*head
)
689 struct ctf_node
*node
;
691 bt_list_for_each_entry(node
, head
, siblings
) {
692 if (node
->type
!= NODE_UNARY_EXPRESSION
) {
696 if (node
->u
.unary_expression
.type
!= UNARY_STRING
) {
705 char *concatenate_unary_strings(struct bt_list_head
*head
)
709 struct ctf_node
*node
;
711 str
= g_string_new(NULL
);
714 bt_list_for_each_entry(node
, head
, siblings
) {
718 node
->type
!= NODE_UNARY_EXPRESSION
||
719 node
->u
.unary_expression
.type
!= UNARY_STRING
||
722 node
->u
.unary_expression
.link
!=
730 switch (node
->u
.unary_expression
.link
) {
732 g_string_append(str
, ".");
734 case UNARY_ARROWLINK
:
735 g_string_append(str
, "->");
737 case UNARY_DOTDOTDOT
:
738 g_string_append(str
, "...");
744 src_string
= node
->u
.unary_expression
.u
.string
;
745 g_string_append(str
, src_string
);
749 /* Destroys the container, returns the underlying string */
750 return g_string_free(str
, FALSE
);
753 /* This always returns NULL */
754 return g_string_free(str
, TRUE
);
758 const char *get_map_clock_name_value(struct bt_list_head
*head
)
761 struct ctf_node
*node
;
762 const char *name
= NULL
;
764 bt_list_for_each_entry(node
, head
, siblings
) {
766 int uexpr_type
= node
->u
.unary_expression
.type
;
767 int uexpr_link
= node
->u
.unary_expression
.link
;
768 int cond
= node
->type
!= NODE_UNARY_EXPRESSION
||
769 uexpr_type
!= UNARY_STRING
||
770 !((uexpr_link
!= UNARY_LINK_UNKNOWN
) ^ (i
== 0));
775 /* Needs to be chained with . */
776 switch (node
->u
.unary_expression
.link
) {
779 case UNARY_ARROWLINK
:
780 case UNARY_DOTDOTDOT
:
786 src_string
= node
->u
.unary_expression
.u
.string
;
790 if (strcmp("clock", src_string
)) {
798 if (strcmp("value", src_string
)) {
803 /* Extra identifier, unknown */
817 int is_unary_unsigned(struct bt_list_head
*head
)
820 struct ctf_node
*node
;
822 bt_list_for_each_entry(node
, head
, siblings
) {
823 if (node
->type
!= NODE_UNARY_EXPRESSION
) {
827 if (node
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
836 int get_unary_unsigned(struct bt_list_head
*head
, uint64_t *value
)
840 struct ctf_node
*node
;
842 if (bt_list_empty(head
)) {
847 bt_list_for_each_entry(node
, head
, siblings
) {
848 int uexpr_type
= node
->u
.unary_expression
.type
;
849 int uexpr_link
= node
->u
.unary_expression
.link
;
850 int cond
= node
->type
!= NODE_UNARY_EXPRESSION
||
851 uexpr_type
!= UNARY_UNSIGNED_CONSTANT
||
852 uexpr_link
!= UNARY_LINK_UNKNOWN
|| i
!= 0;
858 *value
= node
->u
.unary_expression
.u
.unsigned_constant
;
867 int is_unary_signed(struct bt_list_head
*head
)
870 struct ctf_node
*node
;
872 bt_list_for_each_entry(node
, head
, siblings
) {
873 if (node
->type
!= NODE_UNARY_EXPRESSION
) {
877 if (node
->u
.unary_expression
.type
!= UNARY_SIGNED_CONSTANT
) {
886 int get_unary_signed(struct bt_list_head
*head
, int64_t *value
)
890 struct ctf_node
*node
;
892 bt_list_for_each_entry(node
, head
, siblings
) {
893 int uexpr_type
= node
->u
.unary_expression
.type
;
894 int uexpr_link
= node
->u
.unary_expression
.link
;
895 int cond
= node
->type
!= NODE_UNARY_EXPRESSION
||
896 (uexpr_type
!= UNARY_UNSIGNED_CONSTANT
) ||
897 (uexpr_type
!= UNARY_UNSIGNED_CONSTANT
&&
898 uexpr_type
!= UNARY_SIGNED_CONSTANT
) ||
899 uexpr_link
!= UNARY_LINK_UNKNOWN
|| i
!= 0;
905 switch (node
->u
.unary_expression
.type
) {
906 case UNARY_UNSIGNED_CONSTANT
:
908 node
->u
.unary_expression
.u
.unsigned_constant
;
910 case UNARY_SIGNED_CONSTANT
:
911 *value
= node
->u
.unary_expression
.u
.signed_constant
;
926 int get_unary_uuid(struct bt_list_head
*head
, unsigned char *uuid
)
930 struct ctf_node
*node
;
932 bt_list_for_each_entry(node
, head
, siblings
) {
933 int uexpr_type
= node
->u
.unary_expression
.type
;
934 int uexpr_link
= node
->u
.unary_expression
.link
;
935 const char *src_string
;
937 if (node
->type
!= NODE_UNARY_EXPRESSION
||
938 uexpr_type
!= UNARY_STRING
||
939 uexpr_link
!= UNARY_LINK_UNKNOWN
||
945 src_string
= node
->u
.unary_expression
.u
.string
;
946 ret
= bt_uuid_parse(src_string
, uuid
);
957 int get_boolean(struct ctf_node
*unary_expr
)
961 if (unary_expr
->type
!= NODE_UNARY_EXPRESSION
) {
962 BT_LOGE("Expecting unary expression: node-type=%d",
968 switch (unary_expr
->u
.unary_expression
.type
) {
969 case UNARY_UNSIGNED_CONSTANT
:
970 ret
= (unary_expr
->u
.unary_expression
.u
.unsigned_constant
!= 0);
972 case UNARY_SIGNED_CONSTANT
:
973 ret
= (unary_expr
->u
.unary_expression
.u
.signed_constant
!= 0);
977 const char *str
= unary_expr
->u
.unary_expression
.u
.string
;
979 if (!strcmp(str
, "true") || !strcmp(str
, "TRUE")) {
981 } else if (!strcmp(str
, "false") || !strcmp(str
, "FALSE")) {
984 BT_LOGE("Unexpected boolean value: value=\"%s\"", str
);
991 BT_LOGE("Unexpected unary expression type: node-type=%d",
992 unary_expr
->u
.unary_expression
.type
);
1002 enum bt_ctf_byte_order
byte_order_from_unary_expr(struct ctf_node
*unary_expr
)
1005 enum bt_ctf_byte_order bo
= BT_CTF_BYTE_ORDER_UNKNOWN
;
1007 if (unary_expr
->u
.unary_expression
.type
!= UNARY_STRING
) {
1008 BT_LOGE_STR("\"byte_order\" attribute: expecting `be`, `le`, `network`, or `native`.");
1012 str
= unary_expr
->u
.unary_expression
.u
.string
;
1014 if (!strcmp(str
, "be") || !strcmp(str
, "network")) {
1015 bo
= BT_CTF_BYTE_ORDER_BIG_ENDIAN
;
1016 } else if (!strcmp(str
, "le")) {
1017 bo
= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
;
1018 } else if (!strcmp(str
, "native")) {
1019 bo
= BT_CTF_BYTE_ORDER_NATIVE
;
1021 BT_LOGE("Unexpected \"byte_order\" attribute value: "
1022 "expecting `be`, `le`, `network`, or `native`: value=\"%s\"",
1032 enum bt_ctf_byte_order
get_real_byte_order(struct ctx
*ctx
,
1033 struct ctf_node
*uexpr
)
1035 enum bt_ctf_byte_order bo
= byte_order_from_unary_expr(uexpr
);
1037 if (bo
== BT_CTF_BYTE_ORDER_NATIVE
) {
1038 bo
= bt_ctf_trace_get_native_byte_order(ctx
->trace
);
1045 int is_align_valid(uint64_t align
)
1047 return (align
!= 0) && !(align
& (align
- 1));
1051 int get_type_specifier_name(struct ctx
*ctx
, struct ctf_node
*type_specifier
,
1056 if (type_specifier
->type
!= NODE_TYPE_SPECIFIER
) {
1061 switch (type_specifier
->u
.type_specifier
.type
) {
1063 g_string_append(str
, "void");
1066 g_string_append(str
, "char");
1068 case TYPESPEC_SHORT
:
1069 g_string_append(str
, "short");
1072 g_string_append(str
, "int");
1075 g_string_append(str
, "long");
1077 case TYPESPEC_FLOAT
:
1078 g_string_append(str
, "float");
1080 case TYPESPEC_DOUBLE
:
1081 g_string_append(str
, "double");
1083 case TYPESPEC_SIGNED
:
1084 g_string_append(str
, "signed");
1086 case TYPESPEC_UNSIGNED
:
1087 g_string_append(str
, "unsigned");
1090 g_string_append(str
, "bool");
1092 case TYPESPEC_COMPLEX
:
1093 g_string_append(str
, "_Complex");
1095 case TYPESPEC_IMAGINARY
:
1096 g_string_append(str
, "_Imaginary");
1098 case TYPESPEC_CONST
:
1099 g_string_append(str
, "const");
1101 case TYPESPEC_ID_TYPE
:
1102 if (type_specifier
->u
.type_specifier
.id_type
) {
1103 g_string_append(str
,
1104 type_specifier
->u
.type_specifier
.id_type
);
1107 case TYPESPEC_STRUCT
:
1109 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
1111 if (!node
->u
._struct
.name
) {
1112 BT_LOGE_STR("Unexpected empty structure name.");
1117 g_string_append(str
, "struct ");
1118 g_string_append(str
, node
->u
._struct
.name
);
1121 case TYPESPEC_VARIANT
:
1123 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
1125 if (!node
->u
.variant
.name
) {
1126 BT_LOGE_STR("Unexpected empty variant name.");
1131 g_string_append(str
, "variant ");
1132 g_string_append(str
, node
->u
.variant
.name
);
1137 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
1139 if (!node
->u
._enum
.enum_id
) {
1140 BT_LOGE_STR("Unexpected empty enumeration field type (`enum`) name.");
1145 g_string_append(str
, "enum ");
1146 g_string_append(str
, node
->u
._enum
.enum_id
);
1149 case TYPESPEC_FLOATING_POINT
:
1150 case TYPESPEC_INTEGER
:
1151 case TYPESPEC_STRING
:
1153 BT_LOGE("Unexpected type specifier type: %d",
1154 type_specifier
->u
.type_specifier
.type
);
1164 int get_type_specifier_list_name(struct ctx
*ctx
,
1165 struct ctf_node
*type_specifier_list
, GString
*str
)
1168 struct ctf_node
*iter
;
1169 int alias_item_nr
= 0;
1170 struct bt_list_head
*head
=
1171 &type_specifier_list
->u
.type_specifier_list
.head
;
1173 bt_list_for_each_entry(iter
, head
, siblings
) {
1174 if (alias_item_nr
!= 0) {
1175 g_string_append(str
, " ");
1179 ret
= get_type_specifier_name(ctx
, iter
, str
);
1190 GQuark
create_typealias_identifier(struct ctx
*ctx
,
1191 struct ctf_node
*type_specifier_list
,
1192 struct ctf_node
*node_type_declarator
)
1198 struct ctf_node
*iter
;
1199 struct bt_list_head
*pointers
=
1200 &node_type_declarator
->u
.type_declarator
.pointers
;
1202 str
= g_string_new("");
1203 ret
= get_type_specifier_list_name(ctx
, type_specifier_list
, str
);
1205 g_string_free(str
, TRUE
);
1209 bt_list_for_each_entry(iter
, pointers
, siblings
) {
1210 g_string_append(str
, " *");
1212 if (iter
->u
.pointer
.const_qualifier
) {
1213 g_string_append(str
, " const");
1217 str_c
= g_string_free(str
, FALSE
);
1218 qalias
= g_quark_from_string(str_c
);
1226 int visit_type_declarator(struct ctx
*ctx
, struct ctf_node
*type_specifier_list
,
1227 GQuark
*field_name
, struct ctf_node
*node_type_declarator
,
1228 struct bt_ctf_field_type
**field_decl
,
1229 struct bt_ctf_field_type
*nested_decl
)
1232 * During this whole function, nested_decl is always OURS,
1233 * whereas field_decl is an output which we create, but
1234 * belongs to the caller (it is moved).
1240 /* Validate type declarator node */
1241 if (node_type_declarator
) {
1242 if (node_type_declarator
->u
.type_declarator
.type
==
1244 BT_LOGE("Unexpected type declarator type: type=%d",
1245 node_type_declarator
->u
.type_declarator
.type
);
1250 /* TODO: GCC bitfields not supported yet */
1251 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!=
1253 BT_LOGE_STR("GCC bitfields are not supported as of this version.");
1259 /* Find the right nested declaration if not provided */
1261 struct bt_list_head
*pointers
=
1262 &node_type_declarator
->u
.type_declarator
.pointers
;
1264 if (node_type_declarator
&& !bt_list_empty(pointers
)) {
1266 _BT_CTF_FIELD_TYPE_INIT(nested_decl_copy
);
1269 * If we have a pointer declarator, it HAS to
1270 * be present in the typealiases (else fail).
1272 qalias
= create_typealias_identifier(ctx
,
1273 type_specifier_list
, node_type_declarator
);
1275 ctx_decl_scope_lookup_alias(ctx
->current_scope
,
1276 g_quark_to_string(qalias
), -1);
1278 BT_LOGE("Cannot find type alias: name=\"%s\"",
1279 g_quark_to_string(qalias
));
1284 /* Make a copy of it */
1285 nested_decl_copy
= bt_ctf_field_type_copy(nested_decl
);
1286 BT_PUT(nested_decl
);
1287 if (!nested_decl_copy
) {
1288 BT_LOGE_STR("Cannot copy nested field type.");
1293 BT_MOVE(nested_decl
, nested_decl_copy
);
1295 /* Force integer's base to 16 since it's a pointer */
1296 if (bt_ctf_field_type_is_integer(nested_decl
)) {
1297 bt_ctf_field_type_integer_set_base(nested_decl
,
1298 BT_CTF_INTEGER_BASE_HEXADECIMAL
);
1301 ret
= visit_type_specifier_list(ctx
,
1302 type_specifier_list
, &nested_decl
);
1304 assert(!nested_decl
);
1310 assert(nested_decl
);
1312 if (!node_type_declarator
) {
1313 BT_MOVE(*field_decl
, nested_decl
);
1317 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
1318 if (node_type_declarator
->u
.type_declarator
.u
.id
) {
1320 node_type_declarator
->u
.type_declarator
.u
.id
;
1322 *field_name
= g_quark_from_string(id
);
1327 BT_MOVE(*field_decl
, nested_decl
);
1330 struct ctf_node
*first
;
1331 _BT_CTF_FIELD_TYPE_INIT(decl
);
1332 _BT_CTF_FIELD_TYPE_INIT(outer_field_decl
);
1333 struct bt_list_head
*length
=
1334 &node_type_declarator
->
1335 u
.type_declarator
.u
.nested
.length
;
1337 /* Create array/sequence, pass nested_decl as child */
1338 if (bt_list_empty(length
)) {
1339 BT_LOGE_STR("Expecting length field reference or value.");
1344 first
= _BT_LIST_FIRST_ENTRY(length
, struct ctf_node
, siblings
);
1345 if (first
->type
!= NODE_UNARY_EXPRESSION
) {
1350 switch (first
->u
.unary_expression
.type
) {
1351 case UNARY_UNSIGNED_CONSTANT
:
1354 _BT_CTF_FIELD_TYPE_INIT(array_decl
);
1356 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
1357 array_decl
= bt_ctf_field_type_array_create(nested_decl
,
1359 BT_PUT(nested_decl
);
1361 BT_LOGE_STR("Cannot create array field type.");
1366 BT_MOVE(decl
, array_decl
);
1371 /* Lookup unsigned integer definition, create seq. */
1372 _BT_CTF_FIELD_TYPE_INIT(seq_decl
);
1373 char *length_name
= concatenate_unary_strings(length
);
1380 seq_decl
= bt_ctf_field_type_sequence_create(
1381 nested_decl
, length_name
);
1382 g_free(length_name
);
1383 BT_PUT(nested_decl
);
1385 BT_LOGE_STR("Cannot create sequence field type.");
1390 BT_MOVE(decl
, seq_decl
);
1398 assert(!nested_decl
);
1400 assert(!*field_decl
);
1403 * At this point, we found the next nested declaration.
1404 * We currently own this (and lost the ownership of
1405 * nested_decl in the meantime). Pass this next
1406 * nested declaration as the content of the outer
1407 * container, MOVING its ownership.
1409 ret
= visit_type_declarator(ctx
, type_specifier_list
,
1411 node_type_declarator
->
1412 u
.type_declarator
.u
.nested
.type_declarator
,
1413 &outer_field_decl
, decl
);
1416 assert(!outer_field_decl
);
1421 assert(outer_field_decl
);
1422 BT_MOVE(*field_decl
, outer_field_decl
);
1426 BT_PUT(nested_decl
);
1427 assert(*field_decl
);
1432 BT_PUT(nested_decl
);
1433 BT_PUT(*field_decl
);
1439 int visit_struct_decl_field(struct ctx
*ctx
,
1440 struct bt_ctf_field_type
*struct_decl
,
1441 struct ctf_node
*type_specifier_list
,
1442 struct bt_list_head
*type_declarators
)
1445 struct ctf_node
*iter
;
1446 _BT_CTF_FIELD_TYPE_INIT(field_decl
);
1448 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
1451 const char *field_name
;
1452 _BT_CTF_FIELD_TYPE_INIT(efield_decl
);
1454 ret
= visit_type_declarator(ctx
, type_specifier_list
,
1455 &qfield_name
, iter
, &field_decl
, NULL
);
1457 assert(!field_decl
);
1458 BT_LOGE("Cannot visit type declarator: ret=%d", ret
);
1463 field_name
= g_quark_to_string(qfield_name
);
1465 /* Check if field with same name already exists */
1467 bt_ctf_field_type_structure_get_field_type_by_name(
1468 struct_decl
, field_name
);
1470 BT_PUT(efield_decl
);
1471 BT_LOGE("Duplicate field in structure field type: "
1472 "field-name=\"%s\"", field_name
);
1477 /* Add field to structure */
1478 ret
= bt_ctf_field_type_structure_add_field(struct_decl
,
1479 field_decl
, field_name
);
1482 BT_LOGE("Cannot add field to structure field type: "
1483 "field-name=\"%s\", ret=%d",
1484 g_quark_to_string(qfield_name
), ret
);
1498 int visit_variant_decl_field(struct ctx
*ctx
,
1499 struct bt_ctf_field_type
*variant_decl
,
1500 struct ctf_node
*type_specifier_list
,
1501 struct bt_list_head
*type_declarators
)
1504 struct ctf_node
*iter
;
1505 _BT_CTF_FIELD_TYPE_INIT(field_decl
);
1507 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
1510 const char *field_name
;
1511 _BT_CTF_FIELD_TYPE_INIT(efield_decl
);
1513 ret
= visit_type_declarator(ctx
, type_specifier_list
,
1514 &qfield_name
, iter
, &field_decl
, NULL
);
1516 assert(!field_decl
);
1517 BT_LOGE("Cannot visit type declarator: ret=%d", ret
);
1522 field_name
= g_quark_to_string(qfield_name
);
1524 /* Check if field with same name already exists */
1526 bt_ctf_field_type_variant_get_field_type_by_name(
1527 variant_decl
, field_name
);
1529 BT_PUT(efield_decl
);
1530 BT_LOGE("Duplicate field in variant field type: "
1531 "field-name=\"%s\"", field_name
);
1536 /* Add field to structure */
1537 ret
= bt_ctf_field_type_variant_add_field(variant_decl
,
1538 field_decl
, field_name
);
1541 BT_LOGE("Cannot add field to variant field type: "
1542 "field-name=\"%s\", ret=%d",
1543 g_quark_to_string(qfield_name
), ret
);
1557 int visit_typedef(struct ctx
*ctx
, struct ctf_node
*type_specifier_list
,
1558 struct bt_list_head
*type_declarators
)
1562 struct ctf_node
*iter
;
1563 _BT_CTF_FIELD_TYPE_INIT(type_decl
);
1565 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
1566 ret
= visit_type_declarator(ctx
, type_specifier_list
,
1567 &qidentifier
, iter
, &type_decl
, NULL
);
1569 BT_LOGE("Cannot visit type declarator: ret=%d", ret
);
1574 /* Do not allow typedef and typealias of untagged variants */
1575 if (bt_ctf_field_type_is_variant(type_decl
)) {
1576 if (bt_ctf_field_type_variant_get_tag_name(type_decl
)) {
1577 BT_LOGE_STR("Type definition of untagged variant field type is not allowed.");
1583 ret
= ctx_decl_scope_register_alias(ctx
->current_scope
,
1584 g_quark_to_string(qidentifier
), type_decl
);
1586 BT_LOGE("Cannot register type definition: name=\"%s\"",
1587 g_quark_to_string(qidentifier
));
1599 int visit_typealias(struct ctx
*ctx
, struct ctf_node
*target
,
1600 struct ctf_node
*alias
)
1604 struct ctf_node
*node
;
1605 GQuark qdummy_field_name
;
1606 _BT_CTF_FIELD_TYPE_INIT(type_decl
);
1608 /* Create target type declaration */
1609 if (bt_list_empty(&target
->u
.typealias_target
.type_declarators
)) {
1612 node
= _BT_LIST_FIRST_ENTRY(
1613 &target
->u
.typealias_target
.type_declarators
,
1614 struct ctf_node
, siblings
);
1617 ret
= visit_type_declarator(ctx
,
1618 target
->u
.typealias_target
.type_specifier_list
,
1619 &qdummy_field_name
, node
, &type_decl
, NULL
);
1622 BT_LOGE("Cannot visit type declarator: ret=%d", ret
);
1626 /* Do not allow typedef and typealias of untagged variants */
1627 if (bt_ctf_field_type_is_variant(type_decl
)) {
1628 if (bt_ctf_field_type_variant_get_tag_name(type_decl
)) {
1629 BT_LOGE_STR("Type definition of untagged variant field type is not allowed.");
1636 * The semantic validator does not check whether the target is
1637 * abstract or not (if it has an identifier). Check it here.
1639 if (qdummy_field_name
!= 0) {
1640 BT_LOGE("Expecting empty identifier: id=\"%s\"",
1641 g_quark_to_string(qdummy_field_name
));
1646 /* Create alias identifier */
1647 node
= _BT_LIST_FIRST_ENTRY(&alias
->u
.typealias_alias
.type_declarators
,
1648 struct ctf_node
, siblings
);
1649 qalias
= create_typealias_identifier(ctx
,
1650 alias
->u
.typealias_alias
.type_specifier_list
, node
);
1651 ret
= ctx_decl_scope_register_alias(ctx
->current_scope
,
1652 g_quark_to_string(qalias
), type_decl
);
1654 BT_LOGE("Cannot register type alias: name=\"%s\"",
1655 g_quark_to_string(qalias
));
1666 int visit_struct_decl_entry(struct ctx
*ctx
, struct ctf_node
*entry_node
,
1667 struct bt_ctf_field_type
*struct_decl
)
1671 switch (entry_node
->type
) {
1673 ret
= visit_typedef(ctx
,
1674 entry_node
->u
._typedef
.type_specifier_list
,
1675 &entry_node
->u
._typedef
.type_declarators
);
1677 BT_LOGE("Cannot add type definition found in structure field type: ret=%d",
1682 case NODE_TYPEALIAS
:
1683 ret
= visit_typealias(ctx
, entry_node
->u
.typealias
.target
,
1684 entry_node
->u
.typealias
.alias
);
1686 BT_LOGE("Cannot add type alias found in structure field type: ret=%d",
1691 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
1693 ret
= visit_struct_decl_field(ctx
, struct_decl
,
1694 entry_node
->u
.struct_or_variant_declaration
.
1695 type_specifier_list
,
1696 &entry_node
->u
.struct_or_variant_declaration
.
1703 BT_LOGE("Unexpected node type: node-type=%d", entry_node
->type
);
1713 int visit_variant_decl_entry(struct ctx
*ctx
, struct ctf_node
*entry_node
,
1714 struct bt_ctf_field_type
*variant_decl
)
1718 switch (entry_node
->type
) {
1720 ret
= visit_typedef(ctx
,
1721 entry_node
->u
._typedef
.type_specifier_list
,
1722 &entry_node
->u
._typedef
.type_declarators
);
1724 BT_LOGE("Cannot add type definition found in variant field type: ret=%d",
1729 case NODE_TYPEALIAS
:
1730 ret
= visit_typealias(ctx
, entry_node
->u
.typealias
.target
,
1731 entry_node
->u
.typealias
.alias
);
1733 BT_LOGE("Cannot add type alias found in variant field type: ret=%d",
1738 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
1740 ret
= visit_variant_decl_field(ctx
, variant_decl
,
1741 entry_node
->u
.struct_or_variant_declaration
.
1742 type_specifier_list
,
1743 &entry_node
->u
.struct_or_variant_declaration
.
1750 BT_LOGE("Unexpected node type: node-type=%d",
1761 int visit_struct_decl(struct ctx
*ctx
, const char *name
,
1762 struct bt_list_head
*decl_list
, int has_body
,
1763 struct bt_list_head
*min_align
,
1764 struct bt_ctf_field_type
**struct_decl
)
1768 *struct_decl
= NULL
;
1770 /* For named struct (without body), lookup in declaration scope */
1772 _BT_CTF_FIELD_TYPE_INIT(struct_decl_copy
);
1779 *struct_decl
= ctx_decl_scope_lookup_struct(ctx
->current_scope
,
1781 if (!*struct_decl
) {
1782 BT_LOGE("Cannot find structure field type: name=\"struct %s\"",
1788 /* Make a copy of it */
1789 struct_decl_copy
= bt_ctf_field_type_copy(*struct_decl
);
1790 if (!struct_decl_copy
) {
1791 BT_LOGE_STR("Cannot create copy of structure field type.");
1796 BT_MOVE(*struct_decl
, struct_decl_copy
);
1798 struct ctf_node
*entry_node
;
1799 uint64_t min_align_value
= 0;
1802 _BT_CTF_FIELD_TYPE_INIT(estruct_decl
);
1804 estruct_decl
= ctx_decl_scope_lookup_struct(
1805 ctx
->current_scope
, name
, 1);
1807 BT_PUT(estruct_decl
);
1808 BT_LOGE("Structure field type already declared in local scope: "
1809 "name=\"struct %s\"", name
);
1815 if (!bt_list_empty(min_align
)) {
1816 ret
= get_unary_unsigned(min_align
, &min_align_value
);
1818 BT_LOGE("Unexpected unary expression for structure field type's `align` attribute: "
1824 *struct_decl
= bt_ctf_field_type_structure_create();
1825 if (!*struct_decl
) {
1826 BT_LOGE_STR("Cannot create empty structure field type.");
1831 if (min_align_value
!= 0) {
1832 ret
= bt_ctf_field_type_set_alignment(*struct_decl
,
1835 BT_LOGE("Cannot set structure field type's alignment: "
1841 ret
= ctx_push_scope(ctx
);
1843 BT_LOGE_STR("Cannot push scope.");
1847 bt_list_for_each_entry(entry_node
, decl_list
, siblings
) {
1848 ret
= visit_struct_decl_entry(ctx
, entry_node
,
1859 ret
= ctx_decl_scope_register_struct(ctx
->current_scope
,
1860 name
, *struct_decl
);
1862 BT_LOGE("Cannot register structure field type in declaration scope: "
1863 "name=\"struct %s\", ret=%d", name
, ret
);
1872 BT_PUT(*struct_decl
);
1878 int visit_variant_decl(struct ctx
*ctx
, const char *name
,
1879 const char *tag
, struct bt_list_head
*decl_list
,
1880 int has_body
, struct bt_ctf_field_type
**variant_decl
)
1883 _BT_CTF_FIELD_TYPE_INIT(untagged_variant_decl
);
1885 *variant_decl
= NULL
;
1887 /* For named variant (without body), lookup in declaration scope */
1889 _BT_CTF_FIELD_TYPE_INIT(variant_decl_copy
);
1896 untagged_variant_decl
=
1897 ctx_decl_scope_lookup_variant(ctx
->current_scope
,
1899 if (!untagged_variant_decl
) {
1900 BT_LOGE("Cannot find variant field type: name=\"variant %s\"",
1906 /* Make a copy of it */
1907 variant_decl_copy
= bt_ctf_field_type_copy(
1908 untagged_variant_decl
);
1909 if (!variant_decl_copy
) {
1910 BT_LOGE_STR("Cannot create copy of variant field type.");
1915 BT_MOVE(untagged_variant_decl
, variant_decl_copy
);
1917 struct ctf_node
*entry_node
;
1920 struct bt_ctf_field_type
*evariant_decl
=
1921 ctx_decl_scope_lookup_struct(ctx
->current_scope
,
1924 if (evariant_decl
) {
1925 BT_PUT(evariant_decl
);
1926 BT_LOGE("Variant field type already declared in local scope: "
1927 "name=\"variant %s\"", name
);
1933 untagged_variant_decl
= bt_ctf_field_type_variant_create(NULL
,
1935 if (!untagged_variant_decl
) {
1936 BT_LOGE_STR("Cannot create empty variant field type.");
1941 ret
= ctx_push_scope(ctx
);
1943 BT_LOGE_STR("Cannot push scope.");
1947 bt_list_for_each_entry(entry_node
, decl_list
, siblings
) {
1948 ret
= visit_variant_decl_entry(ctx
, entry_node
,
1949 untagged_variant_decl
);
1959 ret
= ctx_decl_scope_register_variant(
1960 ctx
->current_scope
, name
,
1961 untagged_variant_decl
);
1963 BT_LOGE("Cannot register variant field type in declaration scope: "
1964 "name=\"variant %s\", ret=%d", name
, ret
);
1971 * If tagged, create tagged variant and return; otherwise
1972 * return untagged variant.
1975 BT_MOVE(*variant_decl
, untagged_variant_decl
);
1978 * At this point, we have a fresh untagged variant; nobody
1979 * else owns it. Set its tag now.
1981 ret
= bt_ctf_field_type_variant_set_tag_name(
1982 untagged_variant_decl
, tag
);
1987 BT_MOVE(*variant_decl
, untagged_variant_decl
);
1990 assert(!untagged_variant_decl
);
1991 assert(*variant_decl
);
1996 BT_PUT(untagged_variant_decl
);
1997 BT_PUT(*variant_decl
);
2003 int visit_enum_decl_entry(struct ctx
*ctx
, struct ctf_node
*enumerator
,
2004 struct bt_ctf_field_type
*enum_decl
, int64_t *last
, int is_signed
)
2008 struct ctf_node
*iter
;
2009 int64_t start
= 0, end
= 0;
2010 const char *label
= enumerator
->u
.enumerator
.id
;
2011 struct bt_list_head
*values
= &enumerator
->u
.enumerator
.values
;
2013 bt_list_for_each_entry(iter
, values
, siblings
) {
2016 if (iter
->type
!= NODE_UNARY_EXPRESSION
) {
2017 BT_LOGE("Wrong expression for enumeration field type label: "
2018 "node-type=%d, label=\"%s\"", iter
->type
,
2030 switch (iter
->u
.unary_expression
.type
) {
2031 case UNARY_SIGNED_CONSTANT
:
2032 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
2034 case UNARY_UNSIGNED_CONSTANT
:
2036 iter
->u
.unary_expression
.u
.unsigned_constant
;
2039 BT_LOGE("Invalid enumeration field type entry: "
2040 "expecting constant signed or unsigned integer: "
2041 "node-type=%d, label=\"%s\"",
2042 iter
->u
.unary_expression
.type
, label
);
2048 BT_LOGE("Invalid enumeration field type entry: label=\"%s\"",
2068 ret
= bt_ctf_field_type_enumeration_add_mapping(enum_decl
, label
,
2071 ret
= bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_decl
,
2072 label
, (uint64_t) start
, (uint64_t) end
);
2075 BT_LOGE("Cannot add mapping to enumeration field type: "
2076 "label=\"%s\", ret=%d, "
2077 "start-value-unsigned=%" PRIu64
", "
2078 "end-value-unsigned=%" PRIu64
, label
, ret
,
2079 (uint64_t) start
, (uint64_t) end
);
2090 int visit_enum_decl(struct ctx
*ctx
, const char *name
,
2091 struct ctf_node
*container_type
,
2092 struct bt_list_head
*enumerator_list
,
2094 struct bt_ctf_field_type
**enum_decl
)
2098 _BT_CTF_FIELD_TYPE_INIT(integer_decl
);
2102 /* For named enum (without body), lookup in declaration scope */
2104 _BT_CTF_FIELD_TYPE_INIT(enum_decl_copy
);
2111 *enum_decl
= ctx_decl_scope_lookup_enum(ctx
->current_scope
,
2114 BT_LOGE("Cannot find enumeration field type: "
2115 "name=\"enum %s\"", name
);
2120 /* Make a copy of it */
2121 enum_decl_copy
= bt_ctf_field_type_copy(*enum_decl
);
2122 if (!enum_decl_copy
) {
2123 BT_LOGE_STR("Cannot create copy of enumeration field type.");
2129 BT_MOVE(*enum_decl
, enum_decl_copy
);
2131 struct ctf_node
*iter
;
2132 int64_t last_value
= 0;
2135 _BT_CTF_FIELD_TYPE_INIT(eenum_decl
);
2137 eenum_decl
= ctx_decl_scope_lookup_enum(
2138 ctx
->current_scope
, name
, 1);
2141 BT_LOGE("Enumeration field type already declared in local scope: "
2142 "name=\"enum %s\"", name
);
2148 if (!container_type
) {
2149 integer_decl
= ctx_decl_scope_lookup_alias(
2150 ctx
->current_scope
, "int", -1);
2151 if (!integer_decl
) {
2152 BT_LOGE_STR("Cannot find implicit `int` field type alias for enumeration field type.");
2157 ret
= visit_type_declarator(ctx
, container_type
,
2158 &qdummy_id
, NULL
, &integer_decl
, NULL
);
2160 assert(!integer_decl
);
2166 assert(integer_decl
);
2168 if (!bt_ctf_field_type_is_integer(integer_decl
)) {
2169 BT_LOGE("Container field type for enumeration field type is not an integer field type: "
2171 bt_ctf_field_type_id_string(
2172 bt_ctf_field_type_get_type_id(integer_decl
)));
2177 *enum_decl
= bt_ctf_field_type_enumeration_create(integer_decl
);
2179 BT_LOGE_STR("Cannot create enumeration field type.");
2184 bt_list_for_each_entry(iter
, enumerator_list
, siblings
) {
2185 ret
= visit_enum_decl_entry(ctx
, iter
, *enum_decl
,
2187 bt_ctf_field_type_integer_get_signed(integer_decl
));
2194 ret
= ctx_decl_scope_register_enum(ctx
->current_scope
,
2202 BT_PUT(integer_decl
);
2207 BT_PUT(integer_decl
);
2214 int visit_type_specifier(struct ctx
*ctx
,
2215 struct ctf_node
*type_specifier_list
,
2216 struct bt_ctf_field_type
**decl
)
2219 GString
*str
= NULL
;
2220 _BT_CTF_FIELD_TYPE_INIT(decl_copy
);
2223 str
= g_string_new("");
2224 ret
= get_type_specifier_list_name(ctx
, type_specifier_list
, str
);
2229 *decl
= ctx_decl_scope_lookup_alias(ctx
->current_scope
, str
->str
, -1);
2231 BT_LOGE("Cannot find type alias: name=\"%s\"", str
->str
);
2236 /* Make a copy of the type declaration */
2237 decl_copy
= bt_ctf_field_type_copy(*decl
);
2239 BT_LOGE_STR("Cannot create field type copy.");
2244 BT_MOVE(*decl
, decl_copy
);
2245 (void) g_string_free(str
, TRUE
);
2252 (void) g_string_free(str
, TRUE
);
2261 int visit_integer_decl(struct ctx
*ctx
,
2262 struct bt_list_head
*expressions
,
2263 struct bt_ctf_field_type
**integer_decl
)
2268 struct ctf_node
*expression
;
2269 uint64_t alignment
= 0, size
= 0;
2270 struct bt_ctf_clock_class
*mapped_clock
= NULL
;
2271 enum bt_ctf_string_encoding encoding
= BT_CTF_STRING_ENCODING_NONE
;
2272 enum bt_ctf_integer_base base
= BT_CTF_INTEGER_BASE_DECIMAL
;
2273 enum bt_ctf_byte_order byte_order
=
2274 bt_ctf_trace_get_native_byte_order(ctx
->trace
);
2276 *integer_decl
= NULL
;
2278 bt_list_for_each_entry(expression
, expressions
, siblings
) {
2279 struct ctf_node
*left
, *right
;
2281 left
= _BT_LIST_FIRST_ENTRY(&expression
->u
.ctf_expression
.left
,
2282 struct ctf_node
, siblings
);
2283 right
= _BT_LIST_FIRST_ENTRY(
2284 &expression
->u
.ctf_expression
.right
, struct ctf_node
,
2287 if (left
->u
.unary_expression
.type
!= UNARY_STRING
) {
2292 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
2293 if (_IS_SET(&set
, _INTEGER_SIGNED_SET
)) {
2294 _BT_LOGE_DUP_ATTR("signed",
2295 "integer field type");
2300 signedness
= get_boolean(right
);
2301 if (signedness
< 0) {
2306 _SET(&set
, _INTEGER_SIGNED_SET
);
2307 } else if (!strcmp(left
->u
.unary_expression
.u
.string
,
2309 if (_IS_SET(&set
, _INTEGER_BYTE_ORDER_SET
)) {
2310 _BT_LOGE_DUP_ATTR("byte_order",
2311 "integer field type");
2316 byte_order
= get_real_byte_order(ctx
, right
);
2317 if (byte_order
== BT_CTF_BYTE_ORDER_UNKNOWN
) {
2318 BT_LOGE("Invalid `byte_order` attribute in integer field type: "
2324 _SET(&set
, _INTEGER_BYTE_ORDER_SET
);
2325 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
2326 if (_IS_SET(&set
, _INTEGER_SIZE_SET
)) {
2327 _BT_LOGE_DUP_ATTR("size",
2328 "integer field type");
2333 if (right
->u
.unary_expression
.type
!=
2334 UNARY_UNSIGNED_CONSTANT
) {
2335 BT_LOGE("Invalid `size` attribute in integer field type: "
2336 "expecting unsigned constant integer: "
2338 right
->u
.unary_expression
.type
);
2343 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
2345 BT_LOGE("Invalid `size` attribute in integer field type: "
2346 "expecting positive constant integer: "
2347 "size=%" PRIu64
, size
);
2350 } else if (size
> 64) {
2351 BT_LOGE("Invalid `size` attribute in integer field type: "
2352 "integer fields over 64 bits are not supported as of this version: "
2353 "size=%" PRIu64
, size
);
2358 _SET(&set
, _INTEGER_SIZE_SET
);
2359 } else if (!strcmp(left
->u
.unary_expression
.u
.string
,
2361 if (_IS_SET(&set
, _INTEGER_ALIGN_SET
)) {
2362 _BT_LOGE_DUP_ATTR("align",
2363 "integer field type");
2368 if (right
->u
.unary_expression
.type
!=
2369 UNARY_UNSIGNED_CONSTANT
) {
2370 BT_LOGE("Invalid `align` attribute in integer field type: "
2371 "expecting unsigned constant integer: "
2373 right
->u
.unary_expression
.type
);
2379 right
->u
.unary_expression
.u
.unsigned_constant
;
2380 if (!is_align_valid(alignment
)) {
2381 BT_LOGE("Invalid `align` attribute in integer field type: "
2382 "expecting power of two: "
2383 "align=%" PRIu64
, alignment
);
2388 _SET(&set
, _INTEGER_ALIGN_SET
);
2389 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
2390 if (_IS_SET(&set
, _INTEGER_BASE_SET
)) {
2391 _BT_LOGE_DUP_ATTR("base", "integer field type");
2396 switch (right
->u
.unary_expression
.type
) {
2397 case UNARY_UNSIGNED_CONSTANT
:
2399 uint64_t constant
= right
->u
.unary_expression
.
2400 u
.unsigned_constant
;
2404 base
= BT_CTF_INTEGER_BASE_BINARY
;
2407 base
= BT_CTF_INTEGER_BASE_OCTAL
;
2410 base
= BT_CTF_INTEGER_BASE_DECIMAL
;
2413 base
= BT_CTF_INTEGER_BASE_HEXADECIMAL
;
2416 BT_LOGE("Invalid `base` attribute in integer field type: "
2418 right
->u
.unary_expression
.u
.unsigned_constant
);
2426 char *s_right
= concatenate_unary_strings(
2427 &expression
->u
.ctf_expression
.right
);
2429 BT_LOGE_STR("Unexpected unary expression for integer field type's `base` attribute.");
2434 if (!strcmp(s_right
, "decimal") ||
2435 !strcmp(s_right
, "dec") ||
2436 !strcmp(s_right
, "d") ||
2437 !strcmp(s_right
, "i") ||
2438 !strcmp(s_right
, "u")) {
2439 base
= BT_CTF_INTEGER_BASE_DECIMAL
;
2440 } else if (!strcmp(s_right
, "hexadecimal") ||
2441 !strcmp(s_right
, "hex") ||
2442 !strcmp(s_right
, "x") ||
2443 !strcmp(s_right
, "X") ||
2444 !strcmp(s_right
, "p")) {
2445 base
= BT_CTF_INTEGER_BASE_HEXADECIMAL
;
2446 } else if (!strcmp(s_right
, "octal") ||
2447 !strcmp(s_right
, "oct") ||
2448 !strcmp(s_right
, "o")) {
2449 base
= BT_CTF_INTEGER_BASE_OCTAL
;
2450 } else if (!strcmp(s_right
, "binary") ||
2451 !strcmp(s_right
, "b")) {
2452 base
= BT_CTF_INTEGER_BASE_BINARY
;
2454 BT_LOGE("Unexpected unary expression for integer field type's `base` attribute: "
2455 "base=\"%s\"", s_right
);
2465 BT_LOGE_STR("Invalid `base` attribute in integer field type: "
2466 "expecting unsigned constant integer or unary string.");
2471 _SET(&set
, _INTEGER_BASE_SET
);
2472 } else if (!strcmp(left
->u
.unary_expression
.u
.string
,
2476 if (_IS_SET(&set
, _INTEGER_ENCODING_SET
)) {
2477 _BT_LOGE_DUP_ATTR("encoding",
2478 "integer field type");
2483 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
2484 BT_LOGE_STR("Invalid `encoding` attribute in integer field type: "
2485 "expecting unary string.");
2490 s_right
= concatenate_unary_strings(
2491 &expression
->u
.ctf_expression
.right
);
2493 BT_LOGE_STR("Unexpected unary expression for integer field type's `encoding` attribute.");
2498 if (!strcmp(s_right
, "UTF8") ||
2499 !strcmp(s_right
, "utf8") ||
2500 !strcmp(s_right
, "utf-8") ||
2501 !strcmp(s_right
, "UTF-8")) {
2502 encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2503 } else if (!strcmp(s_right
, "ASCII") ||
2504 !strcmp(s_right
, "ascii")) {
2505 encoding
= BT_CTF_STRING_ENCODING_ASCII
;
2506 } else if (!strcmp(s_right
, "none")) {
2507 encoding
= BT_CTF_STRING_ENCODING_NONE
;
2509 BT_LOGE("Invalid `encoding` attribute in integer field type: "
2510 "unknown encoding: encoding=\"%s\"",
2518 _SET(&set
, _INTEGER_ENCODING_SET
);
2519 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
2520 const char *clock_name
;
2522 if (_IS_SET(&set
, _INTEGER_MAP_SET
)) {
2523 _BT_LOGE_DUP_ATTR("map", "integer field type");
2528 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
2529 BT_LOGE_STR("Invalid `map` attribute in integer field type: "
2530 "expecting unary string.");
2536 get_map_clock_name_value(
2537 &expression
->u
.ctf_expression
.right
);
2539 char *s_right
= concatenate_unary_strings(
2540 &expression
->u
.ctf_expression
.right
);
2543 BT_LOGE_STR("Unexpected unary expression for integer field type's `map` attribute.");
2548 BT_LOGE("Invalid `map` attribute in integer field type: "
2549 "cannot find clock class at this point: name=\"%s\"",
2551 _SET(&set
, _INTEGER_MAP_SET
);
2556 mapped_clock
= bt_ctf_trace_get_clock_class_by_name(
2557 ctx
->trace
, clock_name
);
2558 if (!mapped_clock
) {
2559 BT_LOGE("Invalid `map` attribute in integer field type: "
2560 "cannot find clock class at this point: name=\"%s\"",
2566 _SET(&set
, _INTEGER_MAP_SET
);
2568 BT_LOGW("Unknown attribute in integer field type: "
2570 left
->u
.unary_expression
.u
.string
);
2574 if (!_IS_SET(&set
, _INTEGER_SIZE_SET
)) {
2575 BT_LOGE_STR("Missing `size` attribute in integer field type.");
2580 if (!_IS_SET(&set
, _INTEGER_ALIGN_SET
)) {
2581 if (size
% CHAR_BIT
) {
2582 /* Bit-packed alignment */
2585 /* Byte-packed alignment */
2586 alignment
= CHAR_BIT
;
2590 *integer_decl
= bt_ctf_field_type_integer_create((unsigned int) size
);
2591 if (!*integer_decl
) {
2592 BT_LOGE_STR("Cannot create integer field type.");
2597 ret
= bt_ctf_field_type_integer_set_signed(*integer_decl
, signedness
);
2598 ret
|= bt_ctf_field_type_integer_set_base(*integer_decl
, base
);
2599 ret
|= bt_ctf_field_type_integer_set_encoding(*integer_decl
, encoding
);
2600 ret
|= bt_ctf_field_type_set_alignment(*integer_decl
,
2601 (unsigned int) alignment
);
2602 ret
|= bt_ctf_field_type_set_byte_order(*integer_decl
, byte_order
);
2606 ret
|= bt_ctf_field_type_integer_set_mapped_clock_class(
2607 *integer_decl
, mapped_clock
);
2608 bt_put(mapped_clock
);
2609 mapped_clock
= NULL
;
2613 BT_LOGE_STR("Cannot configure integer field type.");
2622 bt_put(mapped_clock
);
2625 BT_PUT(*integer_decl
);
2631 int visit_floating_point_number_decl(struct ctx
*ctx
,
2632 struct bt_list_head
*expressions
,
2633 struct bt_ctf_field_type
**float_decl
)
2637 struct ctf_node
*expression
;
2638 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0;
2639 enum bt_ctf_byte_order byte_order
=
2640 bt_ctf_trace_get_native_byte_order(ctx
->trace
);
2644 bt_list_for_each_entry(expression
, expressions
, siblings
) {
2645 struct ctf_node
*left
, *right
;
2647 left
= _BT_LIST_FIRST_ENTRY(&expression
->u
.ctf_expression
.left
,
2648 struct ctf_node
, siblings
);
2649 right
= _BT_LIST_FIRST_ENTRY(
2650 &expression
->u
.ctf_expression
.right
, struct ctf_node
,
2653 if (left
->u
.unary_expression
.type
!= UNARY_STRING
) {
2658 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
2659 if (_IS_SET(&set
, _FLOAT_BYTE_ORDER_SET
)) {
2660 _BT_LOGE_DUP_ATTR("byte_order",
2661 "floating point number field type");
2666 byte_order
= get_real_byte_order(ctx
, right
);
2667 if (byte_order
== BT_CTF_BYTE_ORDER_UNKNOWN
) {
2668 BT_LOGE("Invalid `byte_order` attribute in floating point number field type: "
2674 _SET(&set
, _FLOAT_BYTE_ORDER_SET
);
2675 } else if (!strcmp(left
->u
.unary_expression
.u
.string
,
2677 if (_IS_SET(&set
, _FLOAT_EXP_DIG_SET
)) {
2678 _BT_LOGE_DUP_ATTR("exp_dig",
2679 "floating point number field type");
2684 if (right
->u
.unary_expression
.type
!=
2685 UNARY_UNSIGNED_CONSTANT
) {
2686 BT_LOGE("Invalid `exp_dig` attribute in floating point number field type: "
2687 "expecting unsigned constant integer: "
2689 right
->u
.unary_expression
.type
);
2694 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
2695 _SET(&set
, _FLOAT_EXP_DIG_SET
);
2696 } else if (!strcmp(left
->u
.unary_expression
.u
.string
,
2698 if (_IS_SET(&set
, _FLOAT_MANT_DIG_SET
)) {
2699 _BT_LOGE_DUP_ATTR("mant_dig",
2700 "floating point number field type");
2705 if (right
->u
.unary_expression
.type
!=
2706 UNARY_UNSIGNED_CONSTANT
) {
2707 BT_LOGE("Invalid `mant_dig` attribute in floating point number field type: "
2708 "expecting unsigned constant integer: "
2710 right
->u
.unary_expression
.type
);
2715 mant_dig
= right
->u
.unary_expression
.u
.
2717 _SET(&set
, _FLOAT_MANT_DIG_SET
);
2718 } else if (!strcmp(left
->u
.unary_expression
.u
.string
,
2720 if (_IS_SET(&set
, _FLOAT_ALIGN_SET
)) {
2721 _BT_LOGE_DUP_ATTR("align",
2722 "floating point number field type");
2727 if (right
->u
.unary_expression
.type
!=
2728 UNARY_UNSIGNED_CONSTANT
) {
2729 BT_LOGE("Invalid `align` attribute in floating point number field type: "
2730 "expecting unsigned constant integer: "
2732 right
->u
.unary_expression
.type
);
2737 alignment
= right
->u
.unary_expression
.u
.
2740 if (!is_align_valid(alignment
)) {
2741 BT_LOGE("Invalid `align` attribute in floating point number field type: "
2742 "expecting power of two: "
2743 "align=%" PRIu64
, alignment
);
2748 _SET(&set
, _FLOAT_ALIGN_SET
);
2750 BT_LOGW("Unknown attribute in floating point number field type: "
2752 left
->u
.unary_expression
.u
.string
);
2756 if (!_IS_SET(&set
, _FLOAT_MANT_DIG_SET
)) {
2757 BT_LOGE_STR("Missing `mant_dig` attribute in floating point number field type.");
2762 if (!_IS_SET(&set
, _FLOAT_EXP_DIG_SET
)) {
2763 BT_LOGE_STR("Missing `exp_dig` attribute in floating point number field type.");
2768 if (!_IS_SET(&set
, _INTEGER_ALIGN_SET
)) {
2769 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
2770 /* Bit-packed alignment */
2773 /* Byte-packed alignment */
2774 alignment
= CHAR_BIT
;
2778 *float_decl
= bt_ctf_field_type_floating_point_create();
2780 BT_LOGE_STR("Cannot create floating point number field type.");
2785 ret
= bt_ctf_field_type_floating_point_set_exponent_digits(
2786 *float_decl
, exp_dig
);
2787 ret
|= bt_ctf_field_type_floating_point_set_mantissa_digits(
2788 *float_decl
, mant_dig
);
2789 ret
|= bt_ctf_field_type_set_byte_order(*float_decl
, byte_order
);
2790 ret
|= bt_ctf_field_type_set_alignment(*float_decl
, alignment
);
2792 BT_LOGE_STR("Cannot configure floating point number field type.");
2800 BT_PUT(*float_decl
);
2806 int visit_string_decl(struct ctx
*ctx
,
2807 struct bt_list_head
*expressions
,
2808 struct bt_ctf_field_type
**string_decl
)
2812 struct ctf_node
*expression
;
2813 enum bt_ctf_string_encoding encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2815 *string_decl
= NULL
;
2817 bt_list_for_each_entry(expression
, expressions
, siblings
) {
2818 struct ctf_node
*left
, *right
;
2820 left
= _BT_LIST_FIRST_ENTRY(&expression
->u
.ctf_expression
.left
,
2821 struct ctf_node
, siblings
);
2822 right
= _BT_LIST_FIRST_ENTRY(
2823 &expression
->u
.ctf_expression
.right
, struct ctf_node
,
2826 if (left
->u
.unary_expression
.type
!= UNARY_STRING
) {
2831 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
2834 if (_IS_SET(&set
, _STRING_ENCODING_SET
)) {
2835 _BT_LOGE_DUP_ATTR("encoding",
2836 "string field type");
2841 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
2842 BT_LOGE_STR("Invalid `encoding` attribute in string field type: "
2843 "expecting unary string.");
2848 s_right
= concatenate_unary_strings(
2849 &expression
->u
.ctf_expression
.right
);
2851 BT_LOGE_STR("Unexpected unary expression for string field type's `encoding` attribute.");
2856 if (!strcmp(s_right
, "UTF8") ||
2857 !strcmp(s_right
, "utf8") ||
2858 !strcmp(s_right
, "utf-8") ||
2859 !strcmp(s_right
, "UTF-8")) {
2860 encoding
= BT_CTF_STRING_ENCODING_UTF8
;
2861 } else if (!strcmp(s_right
, "ASCII") ||
2862 !strcmp(s_right
, "ascii")) {
2863 encoding
= BT_CTF_STRING_ENCODING_ASCII
;
2864 } else if (!strcmp(s_right
, "none")) {
2865 encoding
= BT_CTF_STRING_ENCODING_NONE
;
2867 BT_LOGE("Invalid `encoding` attribute in string field type: "
2868 "unknown encoding: encoding=\"%s\"",
2876 _SET(&set
, _STRING_ENCODING_SET
);
2878 BT_LOGW("Unknown attribute in string field type: "
2880 left
->u
.unary_expression
.u
.string
);
2884 *string_decl
= bt_ctf_field_type_string_create();
2885 if (!*string_decl
) {
2886 BT_LOGE_STR("Cannot create string field type.");
2891 ret
= bt_ctf_field_type_string_set_encoding(*string_decl
, encoding
);
2893 BT_LOGE_STR("Cannot configure string field type.");
2901 BT_PUT(*string_decl
);
2907 int visit_type_specifier_list(struct ctx
*ctx
,
2908 struct ctf_node
*ts_list
,
2909 struct bt_ctf_field_type
**decl
)
2912 struct ctf_node
*first
, *node
;
2916 if (ts_list
->type
!= NODE_TYPE_SPECIFIER_LIST
) {
2921 first
= _BT_LIST_FIRST_ENTRY(&ts_list
->u
.type_specifier_list
.head
,
2922 struct ctf_node
, siblings
);
2923 if (first
->type
!= NODE_TYPE_SPECIFIER
) {
2928 node
= first
->u
.type_specifier
.node
;
2930 switch (first
->u
.type_specifier
.type
) {
2931 case TYPESPEC_INTEGER
:
2932 ret
= visit_integer_decl(ctx
, &node
->u
.integer
.expressions
,
2939 case TYPESPEC_FLOATING_POINT
:
2940 ret
= visit_floating_point_number_decl(ctx
,
2941 &node
->u
.floating_point
.expressions
, decl
);
2947 case TYPESPEC_STRING
:
2948 ret
= visit_string_decl(ctx
,
2949 &node
->u
.string
.expressions
, decl
);
2955 case TYPESPEC_STRUCT
:
2956 ret
= visit_struct_decl(ctx
, node
->u
._struct
.name
,
2957 &node
->u
._struct
.declaration_list
,
2958 node
->u
._struct
.has_body
,
2959 &node
->u
._struct
.min_align
, decl
);
2965 case TYPESPEC_VARIANT
:
2966 ret
= visit_variant_decl(ctx
, node
->u
.variant
.name
,
2967 node
->u
.variant
.choice
,
2968 &node
->u
.variant
.declaration_list
,
2969 node
->u
.variant
.has_body
, decl
);
2976 ret
= visit_enum_decl(ctx
, node
->u
._enum
.enum_id
,
2977 node
->u
._enum
.container_type
,
2978 &node
->u
._enum
.enumerator_list
,
2979 node
->u
._enum
.has_body
, decl
);
2987 case TYPESPEC_SHORT
:
2990 case TYPESPEC_FLOAT
:
2991 case TYPESPEC_DOUBLE
:
2992 case TYPESPEC_SIGNED
:
2993 case TYPESPEC_UNSIGNED
:
2995 case TYPESPEC_COMPLEX
:
2996 case TYPESPEC_IMAGINARY
:
2997 case TYPESPEC_CONST
:
2998 case TYPESPEC_ID_TYPE
:
2999 ret
= visit_type_specifier(ctx
, ts_list
, decl
);
3006 BT_LOGE("Unexpected node type: node-type=%d",
3007 first
->u
.type_specifier
.type
);
3023 int visit_event_decl_entry(struct ctx
*ctx
, struct ctf_node
*node
,
3024 struct bt_ctf_event_class
*event_class
, int64_t *stream_id
,
3029 _BT_CTF_FIELD_TYPE_INIT(decl
);
3031 switch (node
->type
) {
3033 ret
= visit_typedef(ctx
, node
->u
._typedef
.type_specifier_list
,
3034 &node
->u
._typedef
.type_declarators
);
3036 BT_LOGE_STR("Cannot add type definition found in event class.");
3040 case NODE_TYPEALIAS
:
3041 ret
= visit_typealias(ctx
, node
->u
.typealias
.target
,
3042 node
->u
.typealias
.alias
);
3044 BT_LOGE_STR("Cannot add type alias found in event class.");
3048 case NODE_CTF_EXPRESSION
:
3050 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
3056 if (!strcmp(left
, "name")) {
3057 /* This is already known at this stage */
3058 if (_IS_SET(set
, _EVENT_NAME_SET
)) {
3059 _BT_LOGE_DUP_ATTR("name", "event declaration");
3064 _SET(set
, _EVENT_NAME_SET
);
3065 } else if (!strcmp(left
, "id")) {
3068 if (_IS_SET(set
, _EVENT_ID_SET
)) {
3069 _BT_LOGE_DUP_ATTR("id", "event declaration");
3074 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
,
3076 /* Only read "id" if get_unary_unsigned() succeeded. */
3077 if (ret
|| (!ret
&& id
< 0)) {
3078 BT_LOGE_STR("Unexpected unary expression for event class's `id` attribute.");
3083 ret
= bt_ctf_event_class_set_id(event_class
, id
);
3085 BT_LOGE("Cannot set event class's ID: "
3090 _SET(set
, _EVENT_ID_SET
);
3091 } else if (!strcmp(left
, "stream_id")) {
3092 if (_IS_SET(set
, _EVENT_STREAM_ID_SET
)) {
3093 _BT_LOGE_DUP_ATTR("stream_id",
3099 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
,
3100 (uint64_t *) stream_id
);
3102 * Only read "stream_id" if get_unary_unsigned()
3105 if (ret
|| (!ret
&& *stream_id
< 0)) {
3106 BT_LOGE_STR("Unexpected unary expression for event class's `stream_id` attribute.");
3111 _SET(set
, _EVENT_STREAM_ID_SET
);
3112 } else if (!strcmp(left
, "context")) {
3113 if (_IS_SET(set
, _EVENT_CONTEXT_SET
)) {
3114 BT_LOGE_STR("Duplicate `context` entry in event class.");
3119 ret
= visit_type_specifier_list(ctx
,
3120 _BT_LIST_FIRST_ENTRY(
3121 &node
->u
.ctf_expression
.right
,
3122 struct ctf_node
, siblings
),
3125 BT_LOGE_STR("Cannot create event class's context field type.");
3130 ret
= bt_ctf_event_class_set_context_type(
3134 BT_LOGE_STR("Cannot set event class's context field type.");
3138 _SET(set
, _EVENT_CONTEXT_SET
);
3139 } else if (!strcmp(left
, "fields")) {
3140 if (_IS_SET(set
, _EVENT_FIELDS_SET
)) {
3141 BT_LOGE_STR("Duplicate `fields` entry in event class.");
3146 ret
= visit_type_specifier_list(ctx
,
3147 _BT_LIST_FIRST_ENTRY(
3148 &node
->u
.ctf_expression
.right
,
3149 struct ctf_node
, siblings
),
3152 BT_LOGE_STR("Cannot create event class's payload field type.");
3157 ret
= bt_ctf_event_class_set_payload_type(
3161 BT_LOGE_STR("Cannot set event class's payload field type.");
3165 _SET(set
, _EVENT_FIELDS_SET
);
3166 } else if (!strcmp(left
, "loglevel")) {
3167 uint64_t loglevel_value
;
3168 const char *loglevel_str
;
3169 struct bt_value
*value_obj
, *str_obj
;
3171 if (_IS_SET(set
, _EVENT_LOGLEVEL_SET
)) {
3172 _BT_LOGE_DUP_ATTR("loglevel",
3178 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
,
3181 BT_LOGE_STR("Unexpected unary expression for event class's `loglevel` attribute.");
3185 value_obj
= bt_value_integer_create_init(loglevel_value
);
3187 BT_LOGE_STR("Cannot create integer value object.");
3191 if (bt_ctf_event_class_set_attribute(event_class
,
3192 "loglevel", value_obj
) != BT_VALUE_STATUS_OK
) {
3193 BT_LOGE_STR("Cannot set event class's `loglevel` attribute.");
3198 loglevel_str
= print_loglevel(loglevel_value
);
3200 str_obj
= bt_value_string_create_init(loglevel_str
);
3201 if (bt_ctf_event_class_set_attribute(event_class
,
3202 "loglevel_string", str_obj
) != BT_VALUE_STATUS_OK
) {
3203 BT_LOGE_STR("Cannot set event class's `loglevel_string` attribute.");
3211 _SET(set
, _EVENT_LOGLEVEL_SET
);
3212 } else if (!strcmp(left
, "model.emf.uri")) {
3215 if (_IS_SET(set
, _EVENT_MODEL_EMF_URI_SET
)) {
3216 _BT_LOGE_DUP_ATTR("model.emf.uri",
3217 "event declaration");
3222 right
= concatenate_unary_strings(
3223 &node
->u
.ctf_expression
.right
);
3225 BT_LOGE_STR("Unexpected unary expression for event class's `model.emf.uri` attribute.");
3230 // TODO: FIXME: set model EMF URI here
3233 _SET(set
, _EVENT_MODEL_EMF_URI_SET
);
3235 BT_LOGW("Unknown attribute in event class: "
3236 "attr-name=\"%s\"", left
);
3261 char *get_event_decl_name(struct ctx
*ctx
, struct ctf_node
*node
)
3265 struct ctf_node
*iter
;
3266 struct bt_list_head
*decl_list
= &node
->u
.event
.declaration_list
;
3268 bt_list_for_each_entry(iter
, decl_list
, siblings
) {
3269 if (iter
->type
!= NODE_CTF_EXPRESSION
) {
3273 left
= concatenate_unary_strings(&iter
->u
.ctf_expression
.left
);
3278 if (!strcmp(left
, "name")) {
3279 name
= concatenate_unary_strings(
3280 &iter
->u
.ctf_expression
.right
);
3282 BT_LOGE_STR("Unexpected unary expression for event class's `name` attribute.");
3304 int reset_event_decl_types(struct ctx
*ctx
,
3305 struct bt_ctf_event_class
*event_class
)
3310 ret
= bt_ctf_event_class_set_context_type(event_class
, NULL
);
3312 BT_LOGE_STR("Cannot reset initial event class's context field type.");
3316 /* Event payload. */
3317 ret
= bt_ctf_event_class_set_payload_type(event_class
, NULL
);
3319 BT_LOGE_STR("Cannot reset initial event class's payload field type.");
3327 int reset_stream_decl_types(struct ctx
*ctx
,
3328 struct bt_ctf_stream_class
*stream_class
)
3332 /* Packet context. */
3333 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
3335 BT_LOGE_STR("Cannot reset initial stream class's packet context field type.");
3340 ret
= bt_ctf_stream_class_set_event_header_type(stream_class
, NULL
);
3342 BT_LOGE_STR("Cannot reset initial stream class's event header field type.");
3346 /* Event context. */
3347 ret
= bt_ctf_stream_class_set_event_context_type(stream_class
, NULL
);
3349 BT_LOGE_STR("Cannot reset initial stream class's event context field type.");
3357 struct bt_ctf_stream_class
*create_reset_stream_class(struct ctx
*ctx
)
3360 struct bt_ctf_stream_class
*stream_class
;
3362 stream_class
= bt_ctf_stream_class_create_empty(NULL
);
3363 if (!stream_class
) {
3364 BT_LOGE_STR("Cannot create empty stream class.");
3369 * Set packet context, event header, and event context to NULL to
3370 * override the default ones.
3372 ret
= reset_stream_decl_types(ctx
, stream_class
);
3377 return stream_class
;
3380 BT_PUT(stream_class
);
3386 int visit_event_decl(struct ctx
*ctx
, struct ctf_node
*node
)
3391 struct ctf_node
*iter
;
3392 int64_t stream_id
= -1;
3393 char *event_name
= NULL
;
3394 struct bt_ctf_event_class
*event_class
= NULL
;
3395 struct bt_ctf_event_class
*eevent_class
;
3396 struct bt_ctf_stream_class
*stream_class
= NULL
;
3397 struct bt_list_head
*decl_list
= &node
->u
.event
.declaration_list
;
3398 bool pop_scope
= false;
3400 if (node
->visited
) {
3404 node
->visited
= TRUE
;
3405 event_name
= get_event_decl_name(ctx
, node
);
3407 BT_LOGE_STR("Missing `name` attribute in event class.");
3412 event_class
= bt_ctf_event_class_create(event_name
);
3415 * Unset context and fields to override the default ones.
3417 ret
= reset_event_decl_types(ctx
, event_class
);
3422 ret
= ctx_push_scope(ctx
);
3424 BT_LOGE_STR("Cannot push scope.");
3430 bt_list_for_each_entry(iter
, decl_list
, siblings
) {
3431 ret
= visit_event_decl_entry(ctx
, iter
, event_class
,
3438 if (!_IS_SET(&set
, _EVENT_STREAM_ID_SET
)) {
3440 struct bt_ctf_stream_class
*new_stream_class
;
3441 size_t stream_class_count
=
3442 g_hash_table_size(ctx
->stream_classes
) +
3443 bt_ctf_trace_get_stream_class_count(ctx
->trace
);
3446 * Allow missing stream_id if there is only a single
3449 switch (stream_class_count
) {
3451 /* Create implicit stream class if there's none */
3452 new_stream_class
= create_reset_stream_class(ctx
);
3453 if (!new_stream_class
) {
3458 ret
= bt_ctf_stream_class_set_id(new_stream_class
, 0);
3460 BT_LOGE("Cannot set stream class's ID: "
3461 "id=0, ret=%d", ret
);
3462 BT_PUT(new_stream_class
);
3468 /* Move reference to visitor's context */
3469 g_hash_table_insert(ctx
->stream_classes
,
3470 (gpointer
) stream_id
, new_stream_class
);
3471 new_stream_class
= NULL
;
3474 /* Single stream class: get its ID */
3475 if (g_hash_table_size(ctx
->stream_classes
) == 1) {
3476 keys
= g_hash_table_get_keys(ctx
->stream_classes
);
3477 stream_id
= (int64_t) keys
->data
;
3480 assert(bt_ctf_trace_get_stream_class_count(
3483 bt_ctf_trace_get_stream_class_by_index(
3485 assert(stream_class
);
3486 stream_id
= bt_ctf_stream_class_get_id(
3488 BT_PUT(stream_class
);
3492 BT_LOGE_STR("Missing `stream_id` attribute in event class.");
3498 assert(stream_id
>= 0);
3500 /* We have the stream ID now; get the stream class if found */
3501 stream_class
= g_hash_table_lookup(ctx
->stream_classes
,
3502 (gpointer
) stream_id
);
3503 bt_get(stream_class
);
3504 if (!stream_class
) {
3505 stream_class
= bt_ctf_trace_get_stream_class_by_id(ctx
->trace
,
3507 if (!stream_class
) {
3508 BT_LOGE("Cannot find stream class at this point: "
3509 "id=%" PRId64
, stream_id
);
3515 assert(stream_class
);
3517 if (!_IS_SET(&set
, _EVENT_ID_SET
)) {
3518 /* Allow only one event without ID per stream */
3519 if (bt_ctf_stream_class_get_event_class_count(stream_class
) !=
3521 BT_LOGE_STR("Missing `id` attribute in event class.");
3527 ret
= bt_ctf_event_class_set_id(event_class
, 0);
3529 BT_LOGE("Cannot set event class's ID: id=0, ret=%d",
3535 event_id
= bt_ctf_event_class_get_id(event_class
);
3537 BT_LOGE_STR("Cannot get event class's ID.");
3542 eevent_class
= bt_ctf_stream_class_get_event_class_by_id(stream_class
,
3545 BT_PUT(eevent_class
);
3546 BT_LOGE("Duplicate event class (same ID) in the same stream class: "
3547 "id=%" PRId64
, event_id
);
3552 ret
= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
3553 BT_PUT(event_class
);
3555 BT_LOGE("Cannot add event class to stream class: ret=%d", ret
);
3562 bt_put(event_class
);
3570 bt_put(stream_class
);
3575 int visit_stream_decl_entry(struct ctx
*ctx
, struct ctf_node
*node
,
3576 struct bt_ctf_stream_class
*stream_class
, int *set
)
3580 _BT_CTF_FIELD_TYPE_INIT(decl
);
3582 switch (node
->type
) {
3584 ret
= visit_typedef(ctx
, node
->u
._typedef
.type_specifier_list
,
3585 &node
->u
._typedef
.type_declarators
);
3587 BT_LOGE_STR("Cannot add type definition found in stream class.");
3591 case NODE_TYPEALIAS
:
3592 ret
= visit_typealias(ctx
, node
->u
.typealias
.target
,
3593 node
->u
.typealias
.alias
);
3595 BT_LOGE_STR("Cannot add type alias found in stream class.");
3599 case NODE_CTF_EXPRESSION
:
3601 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
3607 if (!strcmp(left
, "id")) {
3611 if (_IS_SET(set
, _STREAM_ID_SET
)) {
3612 _BT_LOGE_DUP_ATTR("id", "stream declaration");
3617 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
,
3619 /* Only read "id" if get_unary_unsigned() succeeded. */
3620 if (ret
|| (!ret
&& id
< 0)) {
3621 BT_LOGE_STR("Unexpected unary expression for stream class's `id` attribute.");
3626 ptr
= g_hash_table_lookup(ctx
->stream_classes
,
3629 BT_LOGE("Duplicate stream class (same ID): id=%" PRId64
,
3635 ret
= bt_ctf_stream_class_set_id(stream_class
, id
);
3637 BT_LOGE("Cannot set stream class's ID: "
3638 "id=%" PRId64
", ret=%d", id
, ret
);
3642 _SET(set
, _STREAM_ID_SET
);
3643 } else if (!strcmp(left
, "event.header")) {
3644 if (_IS_SET(set
, _STREAM_EVENT_HEADER_SET
)) {
3645 BT_LOGE_STR("Duplicate `event.header` entry in stream class.");
3650 ret
= visit_type_specifier_list(ctx
,
3651 _BT_LIST_FIRST_ENTRY(
3652 &node
->u
.ctf_expression
.right
,
3653 struct ctf_node
, siblings
),
3656 BT_LOGE_STR("Cannot create stream class's event header field type.");
3662 ret
= bt_ctf_stream_class_set_event_header_type(
3663 stream_class
, decl
);
3666 BT_LOGE_STR("Cannot set stream class's event header field type.");
3670 _SET(set
, _STREAM_EVENT_HEADER_SET
);
3671 } else if (!strcmp(left
, "event.context")) {
3672 if (_IS_SET(set
, _STREAM_EVENT_CONTEXT_SET
)) {
3673 BT_LOGE_STR("Duplicate `event.context` entry in stream class.");
3678 ret
= visit_type_specifier_list(ctx
,
3679 _BT_LIST_FIRST_ENTRY(
3680 &node
->u
.ctf_expression
.right
,
3681 struct ctf_node
, siblings
),
3684 BT_LOGE_STR("Cannot create stream class's event context field type.");
3690 ret
= bt_ctf_stream_class_set_event_context_type(
3691 stream_class
, decl
);
3694 BT_LOGE_STR("Cannot set stream class's event context field type.");
3698 _SET(set
, _STREAM_EVENT_CONTEXT_SET
);
3699 } else if (!strcmp(left
, "packet.context")) {
3700 if (_IS_SET(set
, _STREAM_PACKET_CONTEXT_SET
)) {
3701 BT_LOGE_STR("Duplicate `packet.context` entry in stream class.");
3706 ret
= visit_type_specifier_list(ctx
,
3707 _BT_LIST_FIRST_ENTRY(
3708 &node
->u
.ctf_expression
.right
,
3709 struct ctf_node
, siblings
),
3712 BT_LOGE_STR("Cannot create stream class's packet context field type.");
3718 ret
= bt_ctf_stream_class_set_packet_context_type(
3719 stream_class
, decl
);
3722 BT_LOGE_STR("Cannot set stream class's packet context field type.");
3726 _SET(set
, _STREAM_PACKET_CONTEXT_SET
);
3728 BT_LOGW("Unknown attribute in stream class: "
3729 "attr-name=\"%s\"", left
);
3752 int visit_stream_decl(struct ctx
*ctx
, struct ctf_node
*node
)
3757 struct ctf_node
*iter
;
3758 struct bt_ctf_stream_class
*stream_class
= NULL
;
3759 struct bt_ctf_stream_class
*existing_stream_class
= NULL
;
3760 struct bt_list_head
*decl_list
= &node
->u
.stream
.declaration_list
;
3762 if (node
->visited
) {
3766 node
->visited
= TRUE
;
3767 stream_class
= create_reset_stream_class(ctx
);
3768 if (!stream_class
) {
3773 ret
= ctx_push_scope(ctx
);
3775 BT_LOGE_STR("Cannot push scope.");
3779 bt_list_for_each_entry(iter
, decl_list
, siblings
) {
3780 ret
= visit_stream_decl_entry(ctx
, iter
, stream_class
, &set
);
3789 if (_IS_SET(&set
, _STREAM_ID_SET
)) {
3790 /* Check that packet header has stream_id field */
3791 _BT_CTF_FIELD_TYPE_INIT(stream_id_decl
);
3792 _BT_CTF_FIELD_TYPE_INIT(packet_header_decl
);
3794 packet_header_decl
=
3795 bt_ctf_trace_get_packet_header_type(ctx
->trace
);
3796 if (!packet_header_decl
) {
3797 BT_LOGE_STR("Stream class has a `id` attribute, "
3798 "but trace has no packet header field type.");
3803 bt_ctf_field_type_structure_get_field_type_by_name(
3804 packet_header_decl
, "stream_id");
3805 BT_PUT(packet_header_decl
);
3806 if (!stream_id_decl
) {
3807 BT_LOGE_STR("Stream class has a `id` attribute, "
3808 "but trace's packet header field type has no `stream_id` field.");
3812 if (!bt_ctf_field_type_is_integer(stream_id_decl
)) {
3813 BT_PUT(stream_id_decl
);
3814 BT_LOGE_STR("Stream class has a `id` attribute, "
3815 "but trace's packet header field type's `stream_id` field is not an integer field type.");
3819 BT_PUT(stream_id_decl
);
3821 /* Allow only _one_ ID-less stream */
3822 if (g_hash_table_size(ctx
->stream_classes
) != 0) {
3823 BT_LOGE_STR("Missing `id` attribute in stream class as there's more than one stream class in the trace.");
3828 /* Automatic ID: 0 */
3829 ret
= bt_ctf_stream_class_set_id(stream_class
, 0);
3833 id
= bt_ctf_stream_class_get_id(stream_class
);
3835 BT_LOGE_STR("Cannot get stream class's ID.");
3841 * Make sure that this stream class's ID is currently unique in
3844 existing_stream_class
= bt_ctf_trace_get_stream_class_by_id(ctx
->trace
,
3846 if (g_hash_table_lookup(ctx
->stream_classes
, (gpointer
) id
) ||
3847 existing_stream_class
) {
3848 BT_LOGE("Duplicate stream class (same ID): id=%" PRId64
,
3854 /* Move reference to visitor's context */
3855 g_hash_table_insert(ctx
->stream_classes
, (gpointer
) (int64_t) id
,
3857 stream_class
= NULL
;
3861 bt_put(stream_class
);
3864 bt_put(existing_stream_class
);
3869 int visit_trace_decl_entry(struct ctx
*ctx
, struct ctf_node
*node
, int *set
)
3873 _BT_CTF_FIELD_TYPE_INIT(packet_header_decl
);
3875 switch (node
->type
) {
3877 ret
= visit_typedef(ctx
, node
->u
._typedef
.type_specifier_list
,
3878 &node
->u
._typedef
.type_declarators
);
3880 BT_LOGE_STR("Cannot add type definition found in trace (`trace` block).");
3884 case NODE_TYPEALIAS
:
3885 ret
= visit_typealias(ctx
, node
->u
.typealias
.target
,
3886 node
->u
.typealias
.alias
);
3888 BT_LOGE_STR("Cannot add type alias found in trace (`trace` block).");
3892 case NODE_CTF_EXPRESSION
:
3894 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
3900 if (!strcmp(left
, "major")) {
3901 if (_IS_SET(set
, _TRACE_MAJOR_SET
)) {
3902 _BT_LOGE_DUP_ATTR("major", "trace");
3907 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
,
3910 BT_LOGE_STR("Unexpected unary expression for trace's `major` attribute.");
3915 _SET(set
, _TRACE_MAJOR_SET
);
3916 } else if (!strcmp(left
, "minor")) {
3917 if (_IS_SET(set
, _TRACE_MINOR_SET
)) {
3918 _BT_LOGE_DUP_ATTR("minor", "trace");
3923 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
,
3926 BT_LOGE_STR("Unexpected unary expression for trace's `minor` attribute.");
3931 _SET(set
, _TRACE_MINOR_SET
);
3932 } else if (!strcmp(left
, "uuid")) {
3933 if (_IS_SET(set
, _TRACE_UUID_SET
)) {
3934 _BT_LOGE_DUP_ATTR("uuid", "trace");
3939 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
,
3942 BT_LOGE_STR("Invalid trace's `uuid` attribute.");
3946 ret
= bt_ctf_trace_set_uuid(ctx
->trace
, ctx
->trace_uuid
);
3948 BT_LOGE_STR("Cannot set trace's UUID.");
3952 _SET(set
, _TRACE_UUID_SET
);
3953 } else if (!strcmp(left
, "byte_order")) {
3954 /* Native byte order is already known at this stage */
3955 if (_IS_SET(set
, _TRACE_BYTE_ORDER_SET
)) {
3956 _BT_LOGE_DUP_ATTR("byte_order",
3962 _SET(set
, _TRACE_BYTE_ORDER_SET
);
3963 } else if (!strcmp(left
, "packet.header")) {
3964 if (_IS_SET(set
, _TRACE_PACKET_HEADER_SET
)) {
3965 BT_LOGE_STR("Duplicate `packet.header` entry in trace.");
3970 ret
= visit_type_specifier_list(ctx
,
3971 _BT_LIST_FIRST_ENTRY(
3972 &node
->u
.ctf_expression
.right
,
3973 struct ctf_node
, siblings
),
3974 &packet_header_decl
);
3976 BT_LOGE_STR("Cannot create trace's packet header field type.");
3980 assert(packet_header_decl
);
3981 ret
= bt_ctf_trace_set_packet_header_type(ctx
->trace
,
3982 packet_header_decl
);
3983 BT_PUT(packet_header_decl
);
3985 BT_LOGE_STR("Cannot set trace's packet header field type.");
3989 _SET(set
, _TRACE_PACKET_HEADER_SET
);
3991 BT_LOGW("Unknown attribute in stream class: "
3992 "attr-name=\"%s\"", left
);
4000 BT_LOGE_STR("Unknown expression in trace.");
4009 BT_PUT(packet_header_decl
);
4015 int visit_trace_decl(struct ctx
*ctx
, struct ctf_node
*node
)
4019 struct ctf_node
*iter
;
4020 struct bt_list_head
*decl_list
= &node
->u
.trace
.declaration_list
;
4022 if (node
->visited
) {
4026 node
->visited
= TRUE
;
4028 if (ctx
->is_trace_visited
) {
4029 BT_LOGE_STR("Duplicate trace (`trace` block).");
4034 ret
= ctx_push_scope(ctx
);
4036 BT_LOGE_STR("Cannot push scope.");
4040 bt_list_for_each_entry(iter
, decl_list
, siblings
) {
4041 ret
= visit_trace_decl_entry(ctx
, iter
, &set
);
4050 if (!_IS_SET(&set
, _TRACE_MAJOR_SET
)) {
4051 BT_LOGE_STR("Missing `major` attribute in trace (`trace` block).");
4056 if (!_IS_SET(&set
, _TRACE_MINOR_SET
)) {
4057 BT_LOGE_STR("Missing `minor` attribute in trace (`trace` block).");
4062 if (!_IS_SET(&set
, _TRACE_BYTE_ORDER_SET
)) {
4063 BT_LOGE_STR("Missing `byte_order` attribute in trace (`trace` block).");
4068 ctx
->is_trace_visited
= TRUE
;
4078 int visit_env(struct ctx
*ctx
, struct ctf_node
*node
)
4082 struct ctf_node
*entry_node
;
4083 struct bt_list_head
*decl_list
= &node
->u
.env
.declaration_list
;
4085 if (node
->visited
) {
4089 node
->visited
= TRUE
;
4091 bt_list_for_each_entry(entry_node
, decl_list
, siblings
) {
4092 struct bt_list_head
*right_head
=
4093 &entry_node
->u
.ctf_expression
.right
;
4095 if (entry_node
->type
!= NODE_CTF_EXPRESSION
) {
4096 BT_LOGE("Wrong expression in environment entry: "
4097 "node-type=%d", entry_node
->type
);
4102 left
= concatenate_unary_strings(
4103 &entry_node
->u
.ctf_expression
.left
);
4105 BT_LOGE_STR("Cannot get environment entry's name.");
4110 if (is_unary_string(right_head
)) {
4111 char *right
= concatenate_unary_strings(right_head
);
4114 BT_LOGE("Unexpected unary expression for environment entry's value: "
4115 "name=\"%s\"", left
);
4120 if (strcmp(left
, "tracer_name") == 0) {
4121 if (strncmp(right
, "lttng", 5) == 0) {
4126 ret
= bt_ctf_trace_set_environment_field_string(
4127 ctx
->trace
, left
, right
);
4131 BT_LOGE("Cannot add string environment entry to trace: "
4132 "name=\"%s\", ret=%d", left
, ret
);
4135 } else if (is_unary_unsigned(right_head
) ||
4136 is_unary_signed(right_head
)) {
4139 if (is_unary_unsigned(right_head
)) {
4140 ret
= get_unary_unsigned(right_head
,
4143 ret
= get_unary_signed(right_head
, &v
);
4146 BT_LOGE("Unexpected unary expression for environment entry's value: "
4147 "name=\"%s\"", left
);
4152 ret
= bt_ctf_trace_set_environment_field_integer(
4153 ctx
->trace
, left
, v
);
4155 BT_LOGE("Cannot add integer environment entry to trace: "
4156 "name=\"%s\", ret=%d", left
, ret
);
4160 BT_LOGW("Environment entry has unknown type: "
4161 "name=\"%s\"", left
);
4178 int set_trace_byte_order(struct ctx
*ctx
, struct ctf_node
*trace_node
)
4183 struct ctf_node
*node
;
4184 struct bt_list_head
*decl_list
= &trace_node
->u
.trace
.declaration_list
;
4186 bt_list_for_each_entry(node
, decl_list
, siblings
) {
4187 if (node
->type
== NODE_CTF_EXPRESSION
) {
4188 struct ctf_node
*right_node
;
4190 left
= concatenate_unary_strings(
4191 &node
->u
.ctf_expression
.left
);
4197 if (!strcmp(left
, "byte_order")) {
4198 enum bt_ctf_byte_order bo
;
4200 if (_IS_SET(&set
, _TRACE_BYTE_ORDER_SET
)) {
4201 _BT_LOGE_DUP_ATTR("byte_order",
4207 _SET(&set
, _TRACE_BYTE_ORDER_SET
);
4208 right_node
= _BT_LIST_FIRST_ENTRY(
4209 &node
->u
.ctf_expression
.right
,
4210 struct ctf_node
, siblings
);
4211 bo
= byte_order_from_unary_expr(right_node
);
4212 if (bo
== BT_CTF_BYTE_ORDER_UNKNOWN
) {
4215 } else if (bo
== BT_CTF_BYTE_ORDER_NATIVE
) {
4216 BT_LOGE_STR("Invalid `byte_order` attribute in trace (`trace` block): "
4217 "cannot be set to `native` here.");
4223 ret
= bt_ctf_trace_set_native_byte_order(
4226 BT_LOGE("Cannot set trace's byte order: "
4237 if (!_IS_SET(&set
, _TRACE_BYTE_ORDER_SET
)) {
4238 BT_LOGE_STR("Missing `byte_order` attribute in trace (`trace` block).");
4252 int visit_clock_decl_entry(struct ctx
*ctx
, struct ctf_node
*entry_node
,
4253 struct bt_ctf_clock_class
*clock
, int *set
)
4258 if (entry_node
->type
!= NODE_CTF_EXPRESSION
) {
4263 left
= concatenate_unary_strings(&entry_node
->u
.ctf_expression
.left
);
4269 if (!strcmp(left
, "name")) {
4272 if (_IS_SET(set
, _CLOCK_NAME_SET
)) {
4273 _BT_LOGE_DUP_ATTR("name", "clock class");
4278 right
= concatenate_unary_strings(
4279 &entry_node
->u
.ctf_expression
.right
);
4281 BT_LOGE_STR("Unexpected unary expression for clock class's `name` attribute.");
4286 ret
= bt_ctf_clock_class_set_name(clock
, right
);
4288 BT_LOGE("cannot set clock class's name");
4294 _SET(set
, _CLOCK_NAME_SET
);
4295 } else if (!strcmp(left
, "uuid")) {
4296 unsigned char uuid
[BABELTRACE_UUID_LEN
];
4298 if (_IS_SET(set
, _CLOCK_UUID_SET
)) {
4299 _BT_LOGE_DUP_ATTR("uuid", "clock class");
4304 ret
= get_unary_uuid(&entry_node
->u
.ctf_expression
.right
, uuid
);
4306 BT_LOGE_STR("Invalid clock class's `uuid` attribute.");
4310 ret
= bt_ctf_clock_class_set_uuid(clock
, uuid
);
4312 BT_LOGE_STR("Cannot set clock class's UUID.");
4316 _SET(set
, _CLOCK_UUID_SET
);
4317 } else if (!strcmp(left
, "description")) {
4320 if (_IS_SET(set
, _CLOCK_DESCRIPTION_SET
)) {
4321 _BT_LOGE_DUP_ATTR("description", "clock class");
4326 right
= concatenate_unary_strings(
4327 &entry_node
->u
.ctf_expression
.right
);
4329 BT_LOGE_STR("Unexpected unary expression for clock class's `description` attribute.");
4334 ret
= bt_ctf_clock_class_set_description(clock
, right
);
4336 BT_LOGE_STR("Cannot set clock class's description.");
4342 _SET(set
, _CLOCK_DESCRIPTION_SET
);
4343 } else if (!strcmp(left
, "freq")) {
4346 if (_IS_SET(set
, _CLOCK_FREQ_SET
)) {
4347 _BT_LOGE_DUP_ATTR("freq", "clock class");
4352 ret
= get_unary_unsigned(
4353 &entry_node
->u
.ctf_expression
.right
, &freq
);
4355 BT_LOGE_STR("Unexpected unary expression for clock class's `freq` attribute.");
4360 ret
= bt_ctf_clock_class_set_frequency(clock
, freq
);
4362 BT_LOGE_STR("Cannot set clock class's frequency.");
4366 _SET(set
, _CLOCK_FREQ_SET
);
4367 } else if (!strcmp(left
, "precision")) {
4370 if (_IS_SET(set
, _CLOCK_PRECISION_SET
)) {
4371 _BT_LOGE_DUP_ATTR("precision", "clock class");
4376 ret
= get_unary_unsigned(
4377 &entry_node
->u
.ctf_expression
.right
, &precision
);
4379 BT_LOGE_STR("Unexpected unary expression for clock class's `precision` attribute.");
4384 ret
= bt_ctf_clock_class_set_precision(clock
, precision
);
4386 BT_LOGE_STR("Cannot set clock class's precision.");
4390 _SET(set
, _CLOCK_PRECISION_SET
);
4391 } else if (!strcmp(left
, "offset_s")) {
4394 if (_IS_SET(set
, _CLOCK_OFFSET_S_SET
)) {
4395 _BT_LOGE_DUP_ATTR("offset_s", "clock class");
4400 ret
= get_unary_unsigned(
4401 &entry_node
->u
.ctf_expression
.right
, &offset_s
);
4403 BT_LOGE_STR("Unexpected unary expression for clock class's `offset_s` attribute.");
4408 ret
= bt_ctf_clock_class_set_offset_s(clock
, offset_s
);
4410 BT_LOGE_STR("Cannot set clock class's offset in seconds.");
4414 _SET(set
, _CLOCK_OFFSET_S_SET
);
4415 } else if (!strcmp(left
, "offset")) {
4418 if (_IS_SET(set
, _CLOCK_OFFSET_SET
)) {
4419 _BT_LOGE_DUP_ATTR("offset", "clock class");
4424 ret
= get_unary_unsigned(
4425 &entry_node
->u
.ctf_expression
.right
, &offset
);
4427 BT_LOGE_STR("Unexpected unary expression for clock class's `offset` attribute.");
4432 ret
= bt_ctf_clock_class_set_offset_cycles(clock
, offset
);
4434 BT_LOGE_STR("Cannot set clock class's offset in cycles.");
4438 _SET(set
, _CLOCK_OFFSET_SET
);
4439 } else if (!strcmp(left
, "absolute")) {
4440 struct ctf_node
*right
;
4442 if (_IS_SET(set
, _CLOCK_ABSOLUTE_SET
)) {
4443 _BT_LOGE_DUP_ATTR("absolute", "clock class");
4448 right
= _BT_LIST_FIRST_ENTRY(
4449 &entry_node
->u
.ctf_expression
.right
,
4450 struct ctf_node
, siblings
);
4451 ret
= get_boolean(right
);
4453 BT_LOGE_STR("Unexpected unary expression for clock class's `absolute` attribute.");
4458 ret
= bt_ctf_clock_class_set_is_absolute(clock
, ret
);
4460 BT_LOGE_STR("Cannot set clock class's absolute flag.");
4464 _SET(set
, _CLOCK_ABSOLUTE_SET
);
4466 BT_LOGW("Unknown attribute in clock class: attr-name=\"%s\"",
4482 int64_t cycles_from_ns(uint64_t frequency
, int64_t ns
)
4487 if (frequency
== 1000000000ULL) {
4490 cycles
= (uint64_t) (((double) ns
* (double) frequency
) / 1e9
);
4497 int apply_clock_class_offset(struct ctx
*ctx
, struct bt_ctf_clock_class
*clock
)
4501 int64_t offset_cycles
;
4503 freq
= bt_ctf_clock_class_get_frequency(clock
);
4504 if (freq
== -1ULL) {
4505 BT_LOGE_STR("Cannot get clock class's frequency.");
4510 ret
= bt_ctf_clock_class_get_offset_cycles(clock
, &offset_cycles
);
4512 BT_LOGE_STR("Cannot get clock class's offset in cycles.");
4517 offset_cycles
+= cycles_from_ns(freq
, ctx
->clock_class_offset_ns
);
4518 ret
= bt_ctf_clock_class_set_offset_cycles(clock
, offset_cycles
);
4525 int visit_clock_decl(struct ctx
*ctx
, struct ctf_node
*clock_node
)
4529 struct bt_ctf_clock_class
*clock
;
4530 struct ctf_node
*entry_node
;
4531 struct bt_list_head
*decl_list
= &clock_node
->u
.clock
.declaration_list
;
4532 const char *clock_class_name
;
4534 if (clock_node
->visited
) {
4538 clock_node
->visited
= TRUE
;
4539 clock
= bt_ctf_clock_class_create(NULL
);
4541 BT_LOGE_STR("Cannot create default clock class.");
4546 bt_list_for_each_entry(entry_node
, decl_list
, siblings
) {
4547 ret
= visit_clock_decl_entry(ctx
, entry_node
, clock
, &set
);
4553 if (!_IS_SET(&set
, _CLOCK_NAME_SET
)) {
4554 BT_LOGE_STR("Missing `name` attribute in clock class.");
4559 clock_class_name
= bt_ctf_clock_class_get_name(clock
);
4560 assert(clock_class_name
);
4561 if (ctx
->is_lttng
&& strcmp(clock_class_name
, "monotonic") == 0) {
4563 * Old versions of LTTng forgot to set its clock class
4564 * as absolute, even if it is. This is important because
4565 * it's a condition to be able to sort notifications
4566 * from different sources.
4568 ret
= bt_ctf_clock_class_set_is_absolute(clock
, 1);
4570 BT_LOGE_STR("Cannot set clock class's absolute flag.");
4575 ret
= apply_clock_class_offset(ctx
, clock
);
4577 BT_LOGE_STR("Cannot apply clock class's custom offset.");
4581 ret
= bt_ctf_trace_add_clock_class(ctx
->trace
, clock
);
4583 BT_LOGE_STR("Cannot add clock class to trace.");
4594 int visit_root_decl(struct ctx
*ctx
, struct ctf_node
*root_decl_node
)
4598 if (root_decl_node
->visited
) {
4602 root_decl_node
->visited
= TRUE
;
4604 switch (root_decl_node
->type
) {
4606 ret
= visit_typedef(ctx
,
4607 root_decl_node
->u
._typedef
.type_specifier_list
,
4608 &root_decl_node
->u
._typedef
.type_declarators
);
4610 BT_LOGE_STR("Cannot add type definition found in root scope.");
4614 case NODE_TYPEALIAS
:
4615 ret
= visit_typealias(ctx
, root_decl_node
->u
.typealias
.target
,
4616 root_decl_node
->u
.typealias
.alias
);
4618 BT_LOGE_STR("Cannot add type alias found in root scope.");
4622 case NODE_TYPE_SPECIFIER_LIST
:
4624 _BT_CTF_FIELD_TYPE_INIT(decl
);
4627 * Just add the type specifier to the root
4628 * declaration scope. Put local reference.
4630 ret
= visit_type_specifier_list(ctx
, root_decl_node
, &decl
);
4649 int set_trace_name(struct ctx
*ctx
)
4653 struct bt_value
*value
= NULL
;
4655 assert(bt_ctf_trace_get_stream_class_count(ctx
->trace
) == 0);
4656 name
= g_string_new(NULL
);
4663 * Check if we have a trace environment string value named `hostname`.
4664 * If so, use it as the trace name's prefix.
4666 value
= bt_ctf_trace_get_environment_field_value_by_name(ctx
->trace
,
4668 if (bt_value_is_string(value
)) {
4669 const char *hostname
;
4671 ret
= bt_value_string_get(value
, &hostname
);
4673 g_string_append(name
, hostname
);
4675 if (ctx
->trace_name_suffix
) {
4676 g_string_append_c(name
, G_DIR_SEPARATOR
);
4680 if (ctx
->trace_name_suffix
) {
4681 g_string_append(name
, ctx
->trace_name_suffix
);
4684 ret
= bt_ctf_trace_set_name(ctx
->trace
, name
->str
);
4698 g_string_free(name
, TRUE
);
4705 int move_ctx_stream_classes_to_trace(struct ctx
*ctx
)
4708 GHashTableIter iter
;
4709 gpointer key
, stream_class
;
4711 if (g_hash_table_size(ctx
->stream_classes
) > 0 &&
4712 bt_ctf_trace_get_stream_class_count(ctx
->trace
) == 0) {
4714 * We're about to add the first stream class to the
4715 * trace. This will freeze the trace, and after this
4716 * we cannot set the name anymore. At this point,
4717 * set the trace name.
4719 ret
= set_trace_name(ctx
);
4725 g_hash_table_iter_init(&iter
, ctx
->stream_classes
);
4727 while (g_hash_table_iter_next(&iter
, &key
, &stream_class
)) {
4728 ret
= bt_ctf_trace_add_stream_class(ctx
->trace
,
4731 int64_t id
= bt_ctf_stream_class_get_id(stream_class
);
4732 BT_LOGE("Cannot add stream class to trace: id=%" PRId64
,
4738 g_hash_table_remove_all(ctx
->stream_classes
);
4745 struct ctf_visitor_generate_ir
*ctf_visitor_generate_ir_create(
4746 int64_t clock_class_offset_ns
, const char *name
)
4749 struct ctx
*ctx
= NULL
;
4750 struct bt_ctf_trace
*trace
;
4752 trace
= bt_ctf_trace_create();
4754 BT_LOGE_STR("Cannot create empty trace.");
4758 /* Set packet header to NULL to override the default one */
4759 ret
= bt_ctf_trace_set_packet_header_type(trace
, NULL
);
4761 BT_LOGE_STR("Cannot reset initial trace's packet header field type.");
4765 /* Create visitor's context */
4766 ctx
= ctx_create(trace
, clock_class_offset_ns
, name
);
4768 BT_LOGE_STR("Cannot create visitor's context.");
4781 return (void *) ctx
;
4785 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir
*visitor
)
4787 ctx_destroy((void *) visitor
);
4791 struct bt_ctf_trace
*ctf_visitor_generate_ir_get_trace(
4792 struct ctf_visitor_generate_ir
*visitor
)
4794 struct ctx
*ctx
= (void *) visitor
;
4798 return bt_get(ctx
->trace
);
4802 int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir
*visitor
,
4803 struct ctf_node
*node
)
4806 struct ctx
*ctx
= (void *) visitor
;
4808 BT_LOGI_STR("Visiting metadata's AST to generate CTF IR objects.");
4810 switch (node
->type
) {
4813 struct ctf_node
*iter
;
4814 int got_trace_decl
= FALSE
;
4815 int found_callsite
= FALSE
;
4818 * The first thing we need is the native byte order of
4819 * the trace block, because early type aliases can have
4820 * a `byte_order` attribute set to `native`. If we don't
4821 * have the native byte order yet, and we don't have any
4822 * trace block yet, then fail with EINCOMPLETE.
4824 if (ctx
->trace_bo
== BT_CTF_BYTE_ORDER_NATIVE
) {
4825 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
4826 if (got_trace_decl
) {
4827 BT_LOGE_STR("Duplicate trace (`trace` block).");
4832 ret
= set_trace_byte_order(ctx
, iter
);
4834 BT_LOGE("Cannot set trace's native byte order: "
4839 got_trace_decl
= TRUE
;
4842 if (!got_trace_decl
) {
4848 assert(ctx
->trace_bo
== BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
||
4849 ctx
->trace_bo
== BT_CTF_BYTE_ORDER_BIG_ENDIAN
);
4850 assert(ctx
->current_scope
&&
4851 ctx
->current_scope
->parent_scope
== NULL
);
4854 bt_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
4855 ret
= visit_env(ctx
, iter
);
4857 BT_LOGE("Cannot visit trace's environment (`env` block): "
4863 assert(ctx
->current_scope
&&
4864 ctx
->current_scope
->parent_scope
== NULL
);
4867 * Visit clock blocks.
4869 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
4870 ret
= visit_clock_decl(ctx
, iter
);
4872 BT_LOGE("Cannot visit clock class: ret=%d",
4878 assert(ctx
->current_scope
&&
4879 ctx
->current_scope
->parent_scope
== NULL
);
4882 * Visit root declarations next, as they can be used by any
4885 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
4887 ret
= visit_root_decl(ctx
, iter
);
4889 BT_LOGE("Cannot visit root entry: ret=%d",
4895 assert(ctx
->current_scope
&&
4896 ctx
->current_scope
->parent_scope
== NULL
);
4898 /* Callsite blocks are not supported */
4899 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
4900 found_callsite
= TRUE
;
4904 assert(ctx
->current_scope
&&
4905 ctx
->current_scope
->parent_scope
== NULL
);
4907 if (found_callsite
) {
4908 BT_LOGW("\"callsite\" blocks are not supported as of this version.");
4912 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
4913 ret
= visit_trace_decl(ctx
, iter
);
4915 BT_LOGE("Cannot visit trace (`trace` block): "
4921 assert(ctx
->current_scope
&&
4922 ctx
->current_scope
->parent_scope
== NULL
);
4925 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
4926 ret
= visit_stream_decl(ctx
, iter
);
4928 BT_LOGE("Cannot visit stream class: ret=%d",
4934 assert(ctx
->current_scope
&&
4935 ctx
->current_scope
->parent_scope
== NULL
);
4938 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
4939 ret
= visit_event_decl(ctx
, iter
);
4941 BT_LOGE("Cannot visit event class: ret=%d",
4947 assert(ctx
->current_scope
&&
4948 ctx
->current_scope
->parent_scope
== NULL
);
4952 BT_LOGE("Unexpected node type: node-type=%d",
4958 /* Move decoded stream classes to trace, if any */
4959 ret
= move_ctx_stream_classes_to_trace(ctx
);
4961 BT_LOGE("Cannot move stream classes to trace: ret=%d", ret
);