X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fmetadata%2Fvisitor-generate-ir.c;h=388c76f926e89560984357ddf85e2a65f2d3182d;hb=3dca22768a95bef664012559aa9ac977091de6ac;hp=cf7b4611e3e81ac80bfffd82dcbe8aa2736dde65;hpb=942c0e8fbd4c19a3b89514b9693a7a655915eaf9;p=babeltrace.git diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index cf7b4611..388c76f9 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -36,20 +36,14 @@ #include #include #include -#include +#include #include #include #include +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include "scanner.h" #include "parser.h" @@ -152,7 +146,7 @@ enum loglevel { #define _BT_LIST_FIRST_ENTRY(_ptr, _type, _member) \ bt_list_entry((_ptr)->next, _type, _member) -#define _BT_CTF_FIELD_TYPE_INIT(_name) struct bt_ctf_field_type *_name = NULL; +#define _BT_FIELD_TYPE_INIT(_name) struct bt_field_type *_name = NULL; #define _BT_LOGE_DUP_ATTR(_node, _attr, _entity) \ _BT_LOGE_LINENO((_node)->lineno, \ @@ -177,7 +171,7 @@ struct ctx_decl_scope { /* * Alias name to field type. * - * GQuark -> struct bt_ctf_field_type * + * GQuark -> struct bt_field_type * */ GHashTable *decl_map; @@ -190,7 +184,7 @@ struct ctx_decl_scope { */ struct ctx { /* Trace being filled (owned by this) */ - struct bt_ctf_trace *trace; + struct bt_trace *trace; /* Current declaration scope (top of the stack) */ struct ctx_decl_scope *current_scope; @@ -205,7 +199,7 @@ struct ctx { char *trace_name_suffix; /* Trace attributes */ - enum bt_ctf_byte_order trace_bo; + enum bt_byte_order trace_bo; uint64_t trace_major; uint64_t trace_minor; unsigned char trace_uuid[BABELTRACE_UUID_LEN]; @@ -213,7 +207,7 @@ struct ctx { /* * Stream IDs to stream classes. * - * int64_t -> struct bt_ctf_stream_class * + * int64_t -> struct bt_stream_class * */ GHashTable *stream_classes; @@ -244,7 +238,7 @@ struct ctx_decl_scope *ctx_decl_scope_create(struct ctx_decl_scope *par_scope) } scope->decl_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify) bt_ctf_field_type_put); + NULL, (GDestroyNotify) bt_put); scope->parent_scope = par_scope; end: @@ -284,7 +278,7 @@ GQuark get_prefixed_named_quark(char prefix, const char *name) { GQuark qname = 0; - assert(name); + BT_ASSERT(name); /* Prefix character + original string + '\0' */ char *prname = g_new(char, strlen(name) + 2); @@ -311,17 +305,17 @@ end: * @returns Declaration, or NULL if not found */ static -struct bt_ctf_field_type *ctx_decl_scope_lookup_prefix_alias( +struct bt_field_type *ctx_decl_scope_lookup_prefix_alias( struct ctx_decl_scope *scope, char prefix, const char *name, int levels) { GQuark qname = 0; int cur_levels = 0; - _BT_CTF_FIELD_TYPE_INIT(decl); + _BT_FIELD_TYPE_INIT(decl); struct ctx_decl_scope *cur_scope = scope; - assert(scope); - assert(name); + BT_ASSERT(scope); + BT_ASSERT(name); qname = get_prefixed_named_quark(prefix, name); if (!qname) { goto error; @@ -359,7 +353,7 @@ error: * @returns Declaration, or NULL if not found */ static -struct bt_ctf_field_type *ctx_decl_scope_lookup_alias( +struct bt_field_type *ctx_decl_scope_lookup_alias( struct ctx_decl_scope *scope, const char *name, int levels) { return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ALIAS, @@ -375,7 +369,7 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_alias( * @returns Declaration, or NULL if not found */ static -struct bt_ctf_field_type *ctx_decl_scope_lookup_enum( +struct bt_field_type *ctx_decl_scope_lookup_enum( struct ctx_decl_scope *scope, const char *name, int levels) { return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ENUM, @@ -391,7 +385,7 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_enum( * @returns Declaration, or NULL if not found */ static -struct bt_ctf_field_type *ctx_decl_scope_lookup_struct( +struct bt_field_type *ctx_decl_scope_lookup_struct( struct ctx_decl_scope *scope, const char *name, int levels) { return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_STRUCT, @@ -407,7 +401,7 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_struct( * @returns Declaration, or NULL if not found */ static -struct bt_ctf_field_type *ctx_decl_scope_lookup_variant( +struct bt_field_type *ctx_decl_scope_lookup_variant( struct ctx_decl_scope *scope, const char *name, int levels) { return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_VARIANT, @@ -425,15 +419,15 @@ struct bt_ctf_field_type *ctx_decl_scope_lookup_variant( */ static int ctx_decl_scope_register_prefix_alias(struct ctx_decl_scope *scope, - char prefix, const char *name, struct bt_ctf_field_type *decl) + char prefix, const char *name, struct bt_field_type *decl) { int ret = 0; GQuark qname = 0; - _BT_CTF_FIELD_TYPE_INIT(edecl); + _BT_FIELD_TYPE_INIT(edecl); - assert(scope); - assert(name); - assert(decl); + BT_ASSERT(scope); + BT_ASSERT(name); + BT_ASSERT(decl); qname = get_prefixed_named_quark(prefix, name); if (!qname) { ret = -ENOMEM; @@ -470,7 +464,7 @@ error: */ static int ctx_decl_scope_register_alias(struct ctx_decl_scope *scope, - const char *name, struct bt_ctf_field_type *decl) + const char *name, struct bt_field_type *decl) { return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ALIAS, name, decl); @@ -486,7 +480,7 @@ int ctx_decl_scope_register_alias(struct ctx_decl_scope *scope, */ static int ctx_decl_scope_register_enum(struct ctx_decl_scope *scope, - const char *name, struct bt_ctf_field_type *decl) + const char *name, struct bt_field_type *decl) { return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ENUM, name, decl); @@ -502,7 +496,7 @@ int ctx_decl_scope_register_enum(struct ctx_decl_scope *scope, */ static int ctx_decl_scope_register_struct(struct ctx_decl_scope *scope, - const char *name, struct bt_ctf_field_type *decl) + const char *name, struct bt_field_type *decl) { return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_STRUCT, name, decl); @@ -518,7 +512,7 @@ int ctx_decl_scope_register_struct(struct ctx_decl_scope *scope, */ static int ctx_decl_scope_register_variant(struct ctx_decl_scope *scope, - const char *name, struct bt_ctf_field_type *decl) + const char *name, struct bt_field_type *decl) { return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_VARIANT, name, decl); @@ -570,14 +564,14 @@ end: * @returns New visitor context, or NULL on error */ static -struct ctx *ctx_create(struct bt_ctf_trace *trace, +struct ctx *ctx_create(struct bt_trace *trace, const struct ctf_metadata_decoder_config *decoder_config, const char *trace_name_suffix) { struct ctx *ctx = NULL; struct ctx_decl_scope *scope = NULL; - assert(decoder_config); + BT_ASSERT(decoder_config); ctx = g_new0(struct ctx, 1); if (!ctx) { @@ -610,7 +604,7 @@ struct ctx *ctx_create(struct bt_ctf_trace *trace, ctx->trace = trace; ctx->current_scope = scope; scope = NULL; - ctx->trace_bo = BT_CTF_BYTE_ORDER_NATIVE; + ctx->trace_bo = BT_BYTE_ORDER_NATIVE; ctx->decoder_config = *decoder_config; return ctx; @@ -633,7 +627,7 @@ int ctx_push_scope(struct ctx *ctx) int ret = 0; struct ctx_decl_scope *new_scope; - assert(ctx); + BT_ASSERT(ctx); new_scope = ctx_decl_scope_create(ctx->current_scope); if (!new_scope) { BT_LOGE_STR("Cannot create declaration scope."); @@ -652,7 +646,7 @@ void ctx_pop_scope(struct ctx *ctx) { struct ctx_decl_scope *parent_scope = NULL; - assert(ctx); + BT_ASSERT(ctx); if (!ctx->current_scope) { goto end; @@ -668,7 +662,62 @@ end: static int visit_type_specifier_list(struct ctx *ctx, struct ctf_node *ts_list, - struct bt_ctf_field_type **decl); + struct bt_field_type **decl); + +static +char *remove_underscores_from_field_ref(const char *field_ref) +{ + const char *in_ch; + char *out_ch; + char *ret; + enum { + UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE, + UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE, + } state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE; + + BT_ASSERT(field_ref); + ret = calloc(strlen(field_ref) + 1, 1); + if (!ret) { + BT_LOGE("Failed to allocate a string: size=%zu", + strlen(field_ref) + 1); + goto end; + } + + in_ch = field_ref; + out_ch = ret; + + while (*in_ch != '\0') { + switch (*in_ch) { + case ' ': + case '\t': + /* Remove whitespace */ + in_ch++; + continue; + case '_': + if (state == UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE) { + in_ch++; + state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE; + continue; + } + + goto copy; + case '.': + state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE; + goto copy; + default: + state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE; + goto copy; + } + +copy: + *out_ch = *in_ch; + in_ch++; + out_ch++; + } + +end: + return ret; +} static int is_unary_string(struct bt_list_head *head) @@ -697,7 +746,7 @@ char *concatenate_unary_strings(struct bt_list_head *head) struct ctf_node *node; str = g_string_new(NULL); - assert(str); + BT_ASSERT(str); bt_list_for_each_entry(node, head, siblings) { char *src_string; @@ -992,10 +1041,10 @@ end: } static -enum bt_ctf_byte_order byte_order_from_unary_expr(struct ctf_node *unary_expr) +enum bt_byte_order byte_order_from_unary_expr(struct ctf_node *unary_expr) { const char *str; - enum bt_ctf_byte_order bo = BT_CTF_BYTE_ORDER_UNKNOWN; + enum bt_byte_order bo = BT_BYTE_ORDER_UNKNOWN; if (unary_expr->u.unary_expression.type != UNARY_STRING) { _BT_LOGE_NODE(unary_expr, @@ -1006,11 +1055,11 @@ enum bt_ctf_byte_order byte_order_from_unary_expr(struct ctf_node *unary_expr) str = unary_expr->u.unary_expression.u.string; if (!strcmp(str, "be") || !strcmp(str, "network")) { - bo = BT_CTF_BYTE_ORDER_BIG_ENDIAN; + bo = BT_BYTE_ORDER_BIG_ENDIAN; } else if (!strcmp(str, "le")) { - bo = BT_CTF_BYTE_ORDER_LITTLE_ENDIAN; + bo = BT_BYTE_ORDER_LITTLE_ENDIAN; } else if (!strcmp(str, "native")) { - bo = BT_CTF_BYTE_ORDER_NATIVE; + bo = BT_BYTE_ORDER_NATIVE; } else { _BT_LOGE_NODE(unary_expr, "Unexpected \"byte_order\" attribute value: " @@ -1024,13 +1073,13 @@ end: } static -enum bt_ctf_byte_order get_real_byte_order(struct ctx *ctx, +enum bt_byte_order get_real_byte_order(struct ctx *ctx, struct ctf_node *uexpr) { - enum bt_ctf_byte_order bo = byte_order_from_unary_expr(uexpr); + enum bt_byte_order bo = byte_order_from_unary_expr(uexpr); - if (bo == BT_CTF_BYTE_ORDER_NATIVE) { - bo = bt_ctf_trace_get_native_byte_order(ctx->trace); + if (bo == BT_BYTE_ORDER_NATIVE) { + bo = bt_trace_get_native_byte_order(ctx->trace); } return bo; @@ -1039,7 +1088,7 @@ enum bt_ctf_byte_order get_real_byte_order(struct ctx *ctx, static int is_align_valid(uint64_t align) { - return (align != 0) && !(align & (align - 1)); + return (align != 0) && !(align & (align - 1ULL)); } static @@ -1225,8 +1274,8 @@ end: static int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, GQuark *field_name, struct ctf_node *node_type_declarator, - struct bt_ctf_field_type **field_decl, - struct bt_ctf_field_type *nested_decl) + struct bt_field_type **field_decl, + struct bt_field_type *nested_decl) { /* * During this whole function, nested_decl is always OURS, @@ -1265,7 +1314,7 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, if (node_type_declarator && !bt_list_empty(pointers)) { GQuark qalias; - _BT_CTF_FIELD_TYPE_INIT(nested_decl_copy); + _BT_FIELD_TYPE_INIT(nested_decl_copy); /* * If we have a pointer declarator, it HAS to @@ -1285,7 +1334,7 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, } /* Make a copy of it */ - nested_decl_copy = bt_ctf_field_type_copy(nested_decl); + nested_decl_copy = bt_field_type_copy(nested_decl); BT_PUT(nested_decl); if (!nested_decl_copy) { _BT_LOGE_NODE(node_type_declarator, @@ -1297,23 +1346,23 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, BT_MOVE(nested_decl, nested_decl_copy); /* Force integer's base to 16 since it's a pointer */ - if (bt_ctf_field_type_is_integer(nested_decl)) { - ret = bt_ctf_field_type_integer_set_base( + if (bt_field_type_is_integer(nested_decl)) { + ret = bt_field_type_integer_set_base( nested_decl, - BT_CTF_INTEGER_BASE_HEXADECIMAL); - assert(ret == 0); + BT_INTEGER_BASE_HEXADECIMAL); + BT_ASSERT(ret == 0); } } else { ret = visit_type_specifier_list(ctx, type_specifier_list, &nested_decl); if (ret) { - assert(!nested_decl); + BT_ASSERT(!nested_decl); goto error; } } } - assert(nested_decl); + BT_ASSERT(nested_decl); if (!node_type_declarator) { BT_MOVE(*field_decl, nested_decl); @@ -1325,6 +1374,10 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, const char *id = node_type_declarator->u.type_declarator.u.id; + if (id[0] == '_') { + id++; + } + *field_name = g_quark_from_string(id); } else { *field_name = 0; @@ -1334,8 +1387,8 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, goto end; } else { struct ctf_node *first; - _BT_CTF_FIELD_TYPE_INIT(decl); - _BT_CTF_FIELD_TYPE_INIT(outer_field_decl); + _BT_FIELD_TYPE_INIT(decl); + _BT_FIELD_TYPE_INIT(outer_field_decl); struct bt_list_head *length = &node_type_declarator-> u.type_declarator.u.nested.length; @@ -1361,10 +1414,10 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, case UNARY_UNSIGNED_CONSTANT: { size_t len; - _BT_CTF_FIELD_TYPE_INIT(array_decl); + _BT_FIELD_TYPE_INIT(array_decl); len = first->u.unary_expression.u.unsigned_constant; - array_decl = bt_ctf_field_type_array_create(nested_decl, + array_decl = bt_field_type_array_create(nested_decl, len); BT_PUT(nested_decl); if (!array_decl) { @@ -1380,8 +1433,9 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, case UNARY_STRING: { /* Lookup unsigned integer definition, create seq. */ - _BT_CTF_FIELD_TYPE_INIT(seq_decl); + _BT_FIELD_TYPE_INIT(seq_decl); char *length_name = concatenate_unary_strings(length); + char *length_name_no_underscore; if (!length_name) { _BT_LOGE_NODE(node_type_declarator, @@ -1390,8 +1444,16 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, goto error; } - seq_decl = bt_ctf_field_type_sequence_create( - nested_decl, length_name); + length_name_no_underscore = + remove_underscores_from_field_ref(length_name); + if (!length_name_no_underscore) { + /* remove_underscores_from_field_ref() logs errors */ + ret = -EINVAL; + goto error; + } + seq_decl = bt_field_type_sequence_create( + nested_decl, length_name_no_underscore); + free(length_name_no_underscore); g_free(length_name); BT_PUT(nested_decl); if (!seq_decl) { @@ -1409,9 +1471,9 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, goto error; } - assert(!nested_decl); - assert(decl); - assert(!*field_decl); + BT_ASSERT(!nested_decl); + BT_ASSERT(decl); + BT_ASSERT(!*field_decl); /* * At this point, we found the next nested declaration. @@ -1427,18 +1489,18 @@ int visit_type_declarator(struct ctx *ctx, struct ctf_node *type_specifier_list, &outer_field_decl, decl); decl = NULL; if (ret) { - assert(!outer_field_decl); + BT_ASSERT(!outer_field_decl); ret = -EINVAL; goto error; } - assert(outer_field_decl); + BT_ASSERT(outer_field_decl); BT_MOVE(*field_decl, outer_field_decl); } end: BT_PUT(nested_decl); - assert(*field_decl); + BT_ASSERT(*field_decl); return 0; @@ -1451,35 +1513,35 @@ error: static int visit_struct_decl_field(struct ctx *ctx, - struct bt_ctf_field_type *struct_decl, + struct bt_field_type *struct_decl, struct ctf_node *type_specifier_list, struct bt_list_head *type_declarators) { int ret = 0; struct ctf_node *iter; - _BT_CTF_FIELD_TYPE_INIT(field_decl); + _BT_FIELD_TYPE_INIT(field_decl); bt_list_for_each_entry(iter, type_declarators, siblings) { field_decl = NULL; GQuark qfield_name; const char *field_name; - _BT_CTF_FIELD_TYPE_INIT(efield_decl); + _BT_FIELD_TYPE_INIT(efield_decl); ret = visit_type_declarator(ctx, type_specifier_list, &qfield_name, iter, &field_decl, NULL); if (ret) { - assert(!field_decl); + BT_ASSERT(!field_decl); _BT_LOGE_NODE(type_specifier_list, "Cannot visit type declarator: ret=%d", ret); goto error; } - assert(field_decl); + BT_ASSERT(field_decl); field_name = g_quark_to_string(qfield_name); /* Check if field with same name already exists */ efield_decl = - bt_ctf_field_type_structure_get_field_type_by_name( + bt_field_type_structure_get_field_type_by_name( struct_decl, field_name); if (efield_decl) { BT_PUT(efield_decl); @@ -1491,7 +1553,7 @@ int visit_struct_decl_field(struct ctx *ctx, } /* Add field to structure */ - ret = bt_ctf_field_type_structure_add_field(struct_decl, + ret = bt_field_type_structure_add_field(struct_decl, field_decl, field_name); BT_PUT(field_decl); if (ret) { @@ -1513,35 +1575,35 @@ error: static int visit_variant_decl_field(struct ctx *ctx, - struct bt_ctf_field_type *variant_decl, + struct bt_field_type *variant_decl, struct ctf_node *type_specifier_list, struct bt_list_head *type_declarators) { int ret = 0; struct ctf_node *iter; - _BT_CTF_FIELD_TYPE_INIT(field_decl); + _BT_FIELD_TYPE_INIT(field_decl); bt_list_for_each_entry(iter, type_declarators, siblings) { field_decl = NULL; GQuark qfield_name; const char *field_name; - _BT_CTF_FIELD_TYPE_INIT(efield_decl); + _BT_FIELD_TYPE_INIT(efield_decl); ret = visit_type_declarator(ctx, type_specifier_list, &qfield_name, iter, &field_decl, NULL); if (ret) { - assert(!field_decl); + BT_ASSERT(!field_decl); _BT_LOGE_NODE(type_specifier_list, "Cannot visit type declarator: ret=%d", ret); goto error; } - assert(field_decl); + BT_ASSERT(field_decl); field_name = g_quark_to_string(qfield_name); /* Check if field with same name already exists */ efield_decl = - bt_ctf_field_type_variant_get_field_type_by_name( + bt_field_type_variant_get_field_type_by_name( variant_decl, field_name); if (efield_decl) { BT_PUT(efield_decl); @@ -1553,7 +1615,7 @@ int visit_variant_decl_field(struct ctx *ctx, } /* Add field to structure */ - ret = bt_ctf_field_type_variant_add_field(variant_decl, + ret = bt_field_type_variant_add_field(variant_decl, field_decl, field_name); BT_PUT(field_decl); if (ret) { @@ -1580,7 +1642,7 @@ int visit_typedef(struct ctx *ctx, struct ctf_node *type_specifier_list, int ret = 0; GQuark qidentifier; struct ctf_node *iter; - _BT_CTF_FIELD_TYPE_INIT(type_decl); + _BT_FIELD_TYPE_INIT(type_decl); bt_list_for_each_entry(iter, type_declarators, siblings) { ret = visit_type_declarator(ctx, type_specifier_list, @@ -1593,8 +1655,8 @@ int visit_typedef(struct ctx *ctx, struct ctf_node *type_specifier_list, } /* Do not allow typedef and typealias of untagged variants */ - if (bt_ctf_field_type_is_variant(type_decl)) { - if (bt_ctf_field_type_variant_get_tag_name(type_decl)) { + if (bt_field_type_is_variant(type_decl)) { + if (bt_field_type_variant_get_tag_name(type_decl)) { _BT_LOGE_NODE(iter, "Type definition of untagged variant field type is not allowed."); ret = -EPERM; @@ -1626,7 +1688,7 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target, GQuark qalias; struct ctf_node *node; GQuark qdummy_field_name; - _BT_CTF_FIELD_TYPE_INIT(type_decl); + _BT_FIELD_TYPE_INIT(type_decl); /* Create target type declaration */ if (bt_list_empty(&target->u.typealias_target.type_declarators)) { @@ -1641,16 +1703,16 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target, target->u.typealias_target.type_specifier_list, &qdummy_field_name, node, &type_decl, NULL); if (ret) { - assert(!type_decl); + BT_ASSERT(!type_decl); _BT_LOGE_NODE(node, "Cannot visit type declarator: ret=%d", ret); goto end; } /* Do not allow typedef and typealias of untagged variants */ - if (bt_ctf_field_type_is_variant(type_decl)) { - if (bt_ctf_field_type_variant_get_tag_name(type_decl)) { - _BT_LOGE_NODE(node, + if (bt_field_type_is_variant(type_decl)) { + if (bt_field_type_variant_get_tag_name(type_decl)) { + _BT_LOGE_NODE(target, "Type definition of untagged variant field type is not allowed."); ret = -EPERM; goto end; @@ -1662,7 +1724,7 @@ int visit_typealias(struct ctx *ctx, struct ctf_node *target, * abstract or not (if it has an identifier). Check it here. */ if (qdummy_field_name != 0) { - _BT_LOGE_NODE(node, + _BT_LOGE_NODE(target, "Expecting empty identifier: id=\"%s\"", g_quark_to_string(qdummy_field_name)); ret = -EINVAL; @@ -1691,7 +1753,7 @@ end: static int visit_struct_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, - struct bt_ctf_field_type *struct_decl) + struct bt_field_type *struct_decl) { int ret = 0; @@ -1741,7 +1803,7 @@ end: static int visit_variant_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, - struct bt_ctf_field_type *variant_decl) + struct bt_field_type *variant_decl) { int ret = 0; @@ -1794,7 +1856,7 @@ static int visit_struct_decl(struct ctx *ctx, const char *name, struct bt_list_head *decl_list, int has_body, struct bt_list_head *min_align, - struct bt_ctf_field_type **struct_decl) + struct bt_field_type **struct_decl) { int ret = 0; @@ -1802,7 +1864,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name, /* For named struct (without body), lookup in declaration scope */ if (!has_body) { - _BT_CTF_FIELD_TYPE_INIT(struct_decl_copy); + _BT_FIELD_TYPE_INIT(struct_decl_copy); if (!name) { BT_LOGE_STR("Bodyless structure field type: missing name."); @@ -1820,7 +1882,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name, } /* Make a copy of it */ - struct_decl_copy = bt_ctf_field_type_copy(*struct_decl); + struct_decl_copy = bt_field_type_copy(*struct_decl); if (!struct_decl_copy) { BT_LOGE_STR("Cannot create copy of structure field type."); ret = -EINVAL; @@ -1833,7 +1895,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name, uint64_t min_align_value = 0; if (name) { - _BT_CTF_FIELD_TYPE_INIT(estruct_decl); + _BT_FIELD_TYPE_INIT(estruct_decl); estruct_decl = ctx_decl_scope_lookup_struct( ctx->current_scope, name, 1); @@ -1855,7 +1917,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name, } } - *struct_decl = bt_ctf_field_type_structure_create(); + *struct_decl = bt_field_type_structure_create(); if (!*struct_decl) { BT_LOGE_STR("Cannot create empty structure field type."); ret = -ENOMEM; @@ -1863,7 +1925,7 @@ int visit_struct_decl(struct ctx *ctx, const char *name, } if (min_align_value != 0) { - ret = bt_ctf_field_type_set_alignment(*struct_decl, + ret = bt_field_type_set_alignment(*struct_decl, min_align_value); if (ret) { BT_LOGE("Cannot set structure field type's alignment: " @@ -1914,16 +1976,16 @@ error: static int visit_variant_decl(struct ctx *ctx, const char *name, const char *tag, struct bt_list_head *decl_list, - int has_body, struct bt_ctf_field_type **variant_decl) + int has_body, struct bt_field_type **variant_decl) { int ret = 0; - _BT_CTF_FIELD_TYPE_INIT(untagged_variant_decl); + _BT_FIELD_TYPE_INIT(untagged_variant_decl); *variant_decl = NULL; /* For named variant (without body), lookup in declaration scope */ if (!has_body) { - _BT_CTF_FIELD_TYPE_INIT(variant_decl_copy); + _BT_FIELD_TYPE_INIT(variant_decl_copy); if (!name) { BT_LOGE_STR("Bodyless variant field type: missing name."); @@ -1942,7 +2004,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name, } /* Make a copy of it */ - variant_decl_copy = bt_ctf_field_type_copy( + variant_decl_copy = bt_field_type_copy( untagged_variant_decl); if (!variant_decl_copy) { BT_LOGE_STR("Cannot create copy of variant field type."); @@ -1955,7 +2017,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name, struct ctf_node *entry_node; if (name) { - struct bt_ctf_field_type *evariant_decl = + struct bt_field_type *evariant_decl = ctx_decl_scope_lookup_struct(ctx->current_scope, name, 1); @@ -1968,7 +2030,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name, } } - untagged_variant_decl = bt_ctf_field_type_variant_create(NULL, + untagged_variant_decl = bt_field_type_variant_create(NULL, NULL); if (!untagged_variant_decl) { BT_LOGE_STR("Cannot create empty variant field type."); @@ -2019,8 +2081,17 @@ int visit_variant_decl(struct ctx *ctx, const char *name, * At this point, we have a fresh untagged variant; nobody * else owns it. Set its tag now. */ - ret = bt_ctf_field_type_variant_set_tag_name( - untagged_variant_decl, tag); + char *tag_no_underscore = + remove_underscores_from_field_ref(tag); + + if (!tag_no_underscore) { + /* remove_underscores_from_field_ref() logs errors */ + goto error; + } + + ret = bt_field_type_variant_set_tag_name( + untagged_variant_decl, tag_no_underscore); + free(tag_no_underscore); if (ret) { BT_LOGE("Cannot set variant field type's tag name: " "tag-name=\"%s\"", tag); @@ -2030,8 +2101,8 @@ int visit_variant_decl(struct ctx *ctx, const char *name, BT_MOVE(*variant_decl, untagged_variant_decl); } - assert(!untagged_variant_decl); - assert(*variant_decl); + BT_ASSERT(!untagged_variant_decl); + BT_ASSERT(*variant_decl); return 0; @@ -2044,13 +2115,14 @@ error: static int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator, - struct bt_ctf_field_type *enum_decl, int64_t *last, int is_signed) + struct bt_field_type *enum_decl, int64_t *last, bt_bool is_signed) { int ret = 0; int nr_vals = 0; struct ctf_node *iter; int64_t start = 0, end = 0; const char *label = enumerator->u.enumerator.id; + const char *effective_label = label; struct bt_list_head *values = &enumerator->u.enumerator.values; bt_list_for_each_entry(iter, values, siblings) { @@ -2110,12 +2182,24 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator, *last = end + 1; + if (label[0] == '_') { + /* + * Strip the first underscore of any enumeration field + * type's label in case this enumeration FT is used as + * a variant FT tag later. The variant FT choice names + * could also start with `_`, in which case the prefix + * is removed, and it the resulting choice name needs to + * match tag labels. + */ + effective_label = &label[1]; + } + if (is_signed) { - ret = bt_ctf_field_type_enumeration_add_mapping(enum_decl, label, - start, end); + ret = bt_field_type_enumeration_signed_add_mapping(enum_decl, + effective_label, start, end); } else { - ret = bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_decl, - label, (uint64_t) start, (uint64_t) end); + ret = bt_field_type_enumeration_unsigned_add_mapping(enum_decl, + effective_label, (uint64_t) start, (uint64_t) end); } if (ret) { _BT_LOGE_NODE(enumerator, @@ -2138,17 +2222,17 @@ int visit_enum_decl(struct ctx *ctx, const char *name, struct ctf_node *container_type, struct bt_list_head *enumerator_list, int has_body, - struct bt_ctf_field_type **enum_decl) + struct bt_field_type **enum_decl) { int ret = 0; GQuark qdummy_id; - _BT_CTF_FIELD_TYPE_INIT(integer_decl); + _BT_FIELD_TYPE_INIT(integer_decl); *enum_decl = NULL; /* For named enum (without body), lookup in declaration scope */ if (!has_body) { - _BT_CTF_FIELD_TYPE_INIT(enum_decl_copy); + _BT_FIELD_TYPE_INIT(enum_decl_copy); if (!name) { BT_LOGE_STR("Bodyless enumeration field type: missing name."); @@ -2166,7 +2250,7 @@ int visit_enum_decl(struct ctx *ctx, const char *name, } /* Make a copy of it */ - enum_decl_copy = bt_ctf_field_type_copy(*enum_decl); + enum_decl_copy = bt_field_type_copy(*enum_decl); if (!enum_decl_copy) { BT_LOGE_STR("Cannot create copy of enumeration field type."); ret = -EINVAL; @@ -2180,7 +2264,7 @@ int visit_enum_decl(struct ctx *ctx, const char *name, int64_t last_value = 0; if (name) { - _BT_CTF_FIELD_TYPE_INIT(eenum_decl); + _BT_FIELD_TYPE_INIT(eenum_decl); eenum_decl = ctx_decl_scope_lookup_enum( ctx->current_scope, name, 1); @@ -2205,24 +2289,24 @@ int visit_enum_decl(struct ctx *ctx, const char *name, ret = visit_type_declarator(ctx, container_type, &qdummy_id, NULL, &integer_decl, NULL); if (ret) { - assert(!integer_decl); + BT_ASSERT(!integer_decl); ret = -EINVAL; goto error; } } - assert(integer_decl); + BT_ASSERT(integer_decl); - if (!bt_ctf_field_type_is_integer(integer_decl)) { + if (!bt_field_type_is_integer(integer_decl)) { BT_LOGE("Container field type for enumeration field type is not an integer field type: " "ft-id=%s", - bt_ctf_field_type_id_string( - bt_ctf_field_type_get_type_id(integer_decl))); + bt_common_field_type_id_string( + bt_field_type_get_type_id(integer_decl))); ret = -EINVAL; goto error; } - *enum_decl = bt_ctf_field_type_enumeration_create(integer_decl); + *enum_decl = bt_field_type_enumeration_create(integer_decl); if (!*enum_decl) { BT_LOGE_STR("Cannot create enumeration field type."); ret = -ENOMEM; @@ -2232,7 +2316,7 @@ int visit_enum_decl(struct ctx *ctx, const char *name, bt_list_for_each_entry(iter, enumerator_list, siblings) { ret = visit_enum_decl_entry(ctx, iter, *enum_decl, &last_value, - bt_ctf_field_type_integer_get_signed(integer_decl)); + bt_field_type_integer_is_signed(integer_decl)); if (ret) { _BT_LOGE_NODE(iter, "Cannot visit enumeration field type entry: " @@ -2266,11 +2350,11 @@ error: static int visit_type_specifier(struct ctx *ctx, struct ctf_node *type_specifier_list, - struct bt_ctf_field_type **decl) + struct bt_field_type **decl) { int ret = 0; GString *str = NULL; - _BT_CTF_FIELD_TYPE_INIT(decl_copy); + _BT_FIELD_TYPE_INIT(decl_copy); *decl = NULL; str = g_string_new(""); @@ -2290,7 +2374,7 @@ int visit_type_specifier(struct ctx *ctx, } /* Make a copy of the type declaration */ - decl_copy = bt_ctf_field_type_copy(*decl); + decl_copy = bt_field_type_copy(*decl); if (!decl_copy) { _BT_LOGE_NODE(type_specifier_list, "Cannot create field type copy."); @@ -2317,18 +2401,18 @@ error: static int visit_integer_decl(struct ctx *ctx, struct bt_list_head *expressions, - struct bt_ctf_field_type **integer_decl) + struct bt_field_type **integer_decl) { int set = 0; int ret = 0; - int signedness = 0; + bt_bool signedness = 0; struct ctf_node *expression; uint64_t alignment = 0, size = 0; - struct bt_ctf_clock_class *mapped_clock = NULL; - enum bt_ctf_string_encoding encoding = BT_CTF_STRING_ENCODING_NONE; - enum bt_ctf_integer_base base = BT_CTF_INTEGER_BASE_DECIMAL; - enum bt_ctf_byte_order byte_order = - bt_ctf_trace_get_native_byte_order(ctx->trace); + struct bt_clock_class *mapped_clock = NULL; + enum bt_string_encoding encoding = BT_STRING_ENCODING_NONE; + enum bt_integer_base base = BT_INTEGER_BASE_DECIMAL; + enum bt_byte_order byte_order = + bt_trace_get_native_byte_order(ctx->trace); *integer_decl = NULL; @@ -2377,7 +2461,7 @@ int visit_integer_decl(struct ctx *ctx, } byte_order = get_real_byte_order(ctx, right); - if (byte_order == BT_CTF_BYTE_ORDER_UNKNOWN) { + if (byte_order == BT_BYTE_ORDER_UNKNOWN) { _BT_LOGE_NODE(right, "Invalid `byte_order` attribute in integer field type: " "ret=%d", ret); @@ -2471,16 +2555,16 @@ int visit_integer_decl(struct ctx *ctx, switch (constant) { case 2: - base = BT_CTF_INTEGER_BASE_BINARY; + base = BT_INTEGER_BASE_BINARY; break; case 8: - base = BT_CTF_INTEGER_BASE_OCTAL; + base = BT_INTEGER_BASE_OCTAL; break; case 10: - base = BT_CTF_INTEGER_BASE_DECIMAL; + base = BT_INTEGER_BASE_DECIMAL; break; case 16: - base = BT_CTF_INTEGER_BASE_HEXADECIMAL; + base = BT_INTEGER_BASE_HEXADECIMAL; break; default: _BT_LOGE_NODE(right, @@ -2508,20 +2592,20 @@ int visit_integer_decl(struct ctx *ctx, !strcmp(s_right, "d") || !strcmp(s_right, "i") || !strcmp(s_right, "u")) { - base = BT_CTF_INTEGER_BASE_DECIMAL; + base = BT_INTEGER_BASE_DECIMAL; } else if (!strcmp(s_right, "hexadecimal") || !strcmp(s_right, "hex") || !strcmp(s_right, "x") || !strcmp(s_right, "X") || !strcmp(s_right, "p")) { - base = BT_CTF_INTEGER_BASE_HEXADECIMAL; + base = BT_INTEGER_BASE_HEXADECIMAL; } else if (!strcmp(s_right, "octal") || !strcmp(s_right, "oct") || !strcmp(s_right, "o")) { - base = BT_CTF_INTEGER_BASE_OCTAL; + base = BT_INTEGER_BASE_OCTAL; } else if (!strcmp(s_right, "binary") || !strcmp(s_right, "b")) { - base = BT_CTF_INTEGER_BASE_BINARY; + base = BT_INTEGER_BASE_BINARY; } else { _BT_LOGE_NODE(right, "Unexpected unary expression for integer field type's `base` attribute: " @@ -2575,12 +2659,12 @@ int visit_integer_decl(struct ctx *ctx, !strcmp(s_right, "utf8") || !strcmp(s_right, "utf-8") || !strcmp(s_right, "UTF-8")) { - encoding = BT_CTF_STRING_ENCODING_UTF8; + encoding = BT_STRING_ENCODING_UTF8; } else if (!strcmp(s_right, "ASCII") || !strcmp(s_right, "ascii")) { - encoding = BT_CTF_STRING_ENCODING_ASCII; + encoding = BT_STRING_ENCODING_ASCII; } else if (!strcmp(s_right, "none")) { - encoding = BT_CTF_STRING_ENCODING_NONE; + encoding = BT_STRING_ENCODING_NONE; } else { _BT_LOGE_NODE(right, "Invalid `encoding` attribute in integer field type: " @@ -2634,7 +2718,7 @@ int visit_integer_decl(struct ctx *ctx, continue; } - mapped_clock = bt_ctf_trace_get_clock_class_by_name( + mapped_clock = bt_trace_get_clock_class_by_name( ctx->trace, clock_name); if (!mapped_clock) { _BT_LOGE_NODE(right, @@ -2670,23 +2754,23 @@ int visit_integer_decl(struct ctx *ctx, } } - *integer_decl = bt_ctf_field_type_integer_create((unsigned int) size); + *integer_decl = bt_field_type_integer_create((unsigned int) size); if (!*integer_decl) { BT_LOGE_STR("Cannot create integer field type."); ret = -ENOMEM; goto error; } - ret = bt_ctf_field_type_integer_set_signed(*integer_decl, signedness); - ret |= bt_ctf_field_type_integer_set_base(*integer_decl, base); - ret |= bt_ctf_field_type_integer_set_encoding(*integer_decl, encoding); - ret |= bt_ctf_field_type_set_alignment(*integer_decl, + ret = bt_field_type_integer_set_is_signed(*integer_decl, signedness); + ret |= bt_field_type_integer_set_base(*integer_decl, base); + ret |= bt_field_type_integer_set_encoding(*integer_decl, encoding); + ret |= bt_field_type_set_alignment(*integer_decl, (unsigned int) alignment); - ret |= bt_ctf_field_type_set_byte_order(*integer_decl, byte_order); + ret |= bt_field_type_set_byte_order(*integer_decl, byte_order); if (mapped_clock) { /* Move clock */ - ret |= bt_ctf_field_type_integer_set_mapped_clock_class( + ret |= bt_field_type_integer_set_mapped_clock_class( *integer_decl, mapped_clock); bt_put(mapped_clock); mapped_clock = NULL; @@ -2713,14 +2797,14 @@ error: static int visit_floating_point_number_decl(struct ctx *ctx, struct bt_list_head *expressions, - struct bt_ctf_field_type **float_decl) + struct bt_field_type **float_decl) { int set = 0; int ret = 0; struct ctf_node *expression; uint64_t alignment = 1, exp_dig = 0, mant_dig = 0; - enum bt_ctf_byte_order byte_order = - bt_ctf_trace_get_native_byte_order(ctx->trace); + enum bt_byte_order byte_order = + bt_trace_get_native_byte_order(ctx->trace); *float_decl = NULL; @@ -2750,7 +2834,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, } byte_order = get_real_byte_order(ctx, right); - if (byte_order == BT_CTF_BYTE_ORDER_UNKNOWN) { + if (byte_order == BT_BYTE_ORDER_UNKNOWN) { _BT_LOGE_NODE(right, "Invalid `byte_order` attribute in floating point number field type: " "ret=%d", ret); @@ -2867,19 +2951,19 @@ int visit_floating_point_number_decl(struct ctx *ctx, } } - *float_decl = bt_ctf_field_type_floating_point_create(); + *float_decl = bt_field_type_floating_point_create(); if (!*float_decl) { BT_LOGE_STR("Cannot create floating point number field type."); ret = -ENOMEM; goto error; } - ret = bt_ctf_field_type_floating_point_set_exponent_digits( + ret = bt_field_type_floating_point_set_exponent_digits( *float_decl, exp_dig); - ret |= bt_ctf_field_type_floating_point_set_mantissa_digits( + ret |= bt_field_type_floating_point_set_mantissa_digits( *float_decl, mant_dig); - ret |= bt_ctf_field_type_set_byte_order(*float_decl, byte_order); - ret |= bt_ctf_field_type_set_alignment(*float_decl, alignment); + ret |= bt_field_type_set_byte_order(*float_decl, byte_order); + ret |= bt_field_type_set_alignment(*float_decl, alignment); if (ret) { BT_LOGE_STR("Cannot configure floating point number field type."); ret = -EINVAL; @@ -2897,12 +2981,12 @@ error: static int visit_string_decl(struct ctx *ctx, struct bt_list_head *expressions, - struct bt_ctf_field_type **string_decl) + struct bt_field_type **string_decl) { int set = 0; int ret = 0; struct ctf_node *expression; - enum bt_ctf_string_encoding encoding = BT_CTF_STRING_ENCODING_UTF8; + enum bt_string_encoding encoding = BT_STRING_ENCODING_UTF8; *string_decl = NULL; @@ -2954,12 +3038,12 @@ int visit_string_decl(struct ctx *ctx, !strcmp(s_right, "utf8") || !strcmp(s_right, "utf-8") || !strcmp(s_right, "UTF-8")) { - encoding = BT_CTF_STRING_ENCODING_UTF8; + encoding = BT_STRING_ENCODING_UTF8; } else if (!strcmp(s_right, "ASCII") || !strcmp(s_right, "ascii")) { - encoding = BT_CTF_STRING_ENCODING_ASCII; + encoding = BT_STRING_ENCODING_ASCII; } else if (!strcmp(s_right, "none")) { - encoding = BT_CTF_STRING_ENCODING_NONE; + encoding = BT_STRING_ENCODING_NONE; } else { _BT_LOGE_NODE(right, "Invalid `encoding` attribute in string field type: " @@ -2980,14 +3064,14 @@ int visit_string_decl(struct ctx *ctx, } } - *string_decl = bt_ctf_field_type_string_create(); + *string_decl = bt_field_type_string_create(); if (!*string_decl) { BT_LOGE_STR("Cannot create string field type."); ret = -ENOMEM; goto error; } - ret = bt_ctf_field_type_string_set_encoding(*string_decl, encoding); + ret = bt_field_type_string_set_encoding(*string_decl, encoding); if (ret) { BT_LOGE_STR("Cannot configure string field type."); ret = -EINVAL; @@ -3005,7 +3089,7 @@ error: static int visit_type_specifier_list(struct ctx *ctx, struct ctf_node *ts_list, - struct bt_ctf_field_type **decl) + struct bt_field_type **decl) { int ret = 0; struct ctf_node *first, *node; @@ -3035,7 +3119,7 @@ int visit_type_specifier_list(struct ctx *ctx, ret = visit_integer_decl(ctx, &node->u.integer.expressions, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3043,7 +3127,7 @@ int visit_type_specifier_list(struct ctx *ctx, ret = visit_floating_point_number_decl(ctx, &node->u.floating_point.expressions, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3051,7 +3135,7 @@ int visit_type_specifier_list(struct ctx *ctx, ret = visit_string_decl(ctx, &node->u.string.expressions, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3061,7 +3145,7 @@ int visit_type_specifier_list(struct ctx *ctx, node->u._struct.has_body, &node->u._struct.min_align, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3071,7 +3155,7 @@ int visit_type_specifier_list(struct ctx *ctx, &node->u.variant.declaration_list, node->u.variant.has_body, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3081,7 +3165,7 @@ int visit_type_specifier_list(struct ctx *ctx, &node->u._enum.enumerator_list, node->u._enum.has_body, decl); if (ret) { - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3104,7 +3188,7 @@ int visit_type_specifier_list(struct ctx *ctx, _BT_LOGE_NODE(first, "Cannot visit type specifier: ret=%d", ret); - assert(!*decl); + BT_ASSERT(!*decl); goto error; } break; @@ -3116,7 +3200,7 @@ int visit_type_specifier_list(struct ctx *ctx, goto error; } - assert(*decl); + BT_ASSERT(*decl); return 0; @@ -3128,12 +3212,12 @@ error: static int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, - struct bt_ctf_event_class *event_class, int64_t *stream_id, + struct bt_event_class *event_class, int64_t *stream_id, int *set) { int ret = 0; char *left = NULL; - _BT_CTF_FIELD_TYPE_INIT(decl); + _BT_FIELD_TYPE_INIT(decl); switch (node->type) { case NODE_TYPEDEF: @@ -3174,7 +3258,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, _SET(set, _EVENT_NAME_SET); } else if (!strcmp(left, "id")) { - int64_t id; + int64_t id = -1; if (_IS_SET(set, _EVENT_ID_SET)) { _BT_LOGE_DUP_ATTR(node, "id", @@ -3193,7 +3277,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - ret = bt_ctf_event_class_set_id(event_class, id); + ret = bt_event_class_set_id(event_class, id); if (ret) { _BT_LOGE_NODE(node, "Cannot set event class's ID: " @@ -3243,8 +3327,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); - ret = bt_ctf_event_class_set_context_type( + BT_ASSERT(decl); + ret = bt_event_class_set_context_field_type( event_class, decl); BT_PUT(decl); if (ret) { @@ -3273,8 +3357,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); - ret = bt_ctf_event_class_set_payload_type( + BT_ASSERT(decl); + ret = bt_event_class_set_payload_field_type( event_class, decl); BT_PUT(decl); if (ret) { @@ -3286,8 +3370,8 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, _SET(set, _EVENT_FIELDS_SET); } else if (!strcmp(left, "loglevel")) { uint64_t loglevel_value; - enum bt_ctf_event_class_log_level log_level = - BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED; + enum bt_event_class_log_level log_level = + BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED; if (_IS_SET(set, _EVENT_LOGLEVEL_SET)) { _BT_LOGE_DUP_ATTR(node, "loglevel", @@ -3307,57 +3391,57 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, switch (loglevel_value) { case 0: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY; + log_level = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY; break; case 1: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT; + log_level = BT_EVENT_CLASS_LOG_LEVEL_ALERT; break; case 2: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL; + log_level = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL; break; case 3: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR; + log_level = BT_EVENT_CLASS_LOG_LEVEL_ERROR; break; case 4: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING; + log_level = BT_EVENT_CLASS_LOG_LEVEL_WARNING; break; case 5: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE; + log_level = BT_EVENT_CLASS_LOG_LEVEL_NOTICE; break; case 6: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO; + log_level = BT_EVENT_CLASS_LOG_LEVEL_INFO; break; case 7: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM; break; case 8: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM; break; case 9: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS; break; case 10: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE; break; case 11: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT; break; case 12: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION; break; case 13: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE; break; case 14: - log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG; + log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG; break; default: _BT_LOGW_NODE(node, "Not setting event class's log level because its value is unknown: " "log-level=%" PRIu64, loglevel_value); } - if (log_level != BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) { - ret = bt_ctf_event_class_set_log_level( + if (log_level != BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) { + ret = bt_event_class_set_log_level( event_class, log_level); if (ret) { _BT_LOGE_NODE(node, @@ -3390,7 +3474,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, _BT_LOGW_NODE(node, "Not setting event class's EMF URI because it's empty."); } else { - ret = bt_ctf_event_class_set_emf_uri( + ret = bt_event_class_set_emf_uri( event_class, right); if (ret) { _BT_LOGE_NODE(node, @@ -3476,25 +3560,25 @@ error: static int reset_event_decl_types(struct ctx *ctx, - struct bt_ctf_event_class *event_class) + struct bt_event_class *event_class) { int ret = 0; /* Context type. */ - ret = bt_ctf_event_class_set_context_type(event_class, NULL); + ret = bt_event_class_set_context_field_type(event_class, NULL); if (ret) { BT_LOGE("Cannot reset initial event class's context field type: " "event-name=\"%s\"", - bt_ctf_event_class_get_name(event_class)); + bt_event_class_get_name(event_class)); goto end; } /* Event payload. */ - ret = bt_ctf_event_class_set_payload_type(event_class, NULL); + ret = bt_event_class_set_payload_field_type(event_class, NULL); if (ret) { BT_LOGE("Cannot reset initial event class's payload field type: " "event-name=\"%s\"", - bt_ctf_event_class_get_name(event_class)); + bt_event_class_get_name(event_class)); goto end; } end: @@ -3503,26 +3587,26 @@ end: static int reset_stream_decl_types(struct ctx *ctx, - struct bt_ctf_stream_class *stream_class) + struct bt_stream_class *stream_class) { int ret = 0; /* Packet context. */ - ret = bt_ctf_stream_class_set_packet_context_type(stream_class, NULL); + ret = bt_stream_class_set_packet_context_field_type(stream_class, NULL); if (ret) { BT_LOGE_STR("Cannot reset initial stream class's packet context field type."); goto end; } /* Event header. */ - ret = bt_ctf_stream_class_set_event_header_type(stream_class, NULL); + ret = bt_stream_class_set_event_header_field_type(stream_class, NULL); if (ret) { BT_LOGE_STR("Cannot reset initial stream class's event header field type."); goto end; } /* Event context. */ - ret = bt_ctf_stream_class_set_event_context_type(stream_class, NULL); + ret = bt_stream_class_set_event_context_field_type(stream_class, NULL); if (ret) { BT_LOGE_STR("Cannot reset initial stream class's event context field type."); goto end; @@ -3532,12 +3616,12 @@ end: } static -struct bt_ctf_stream_class *create_reset_stream_class(struct ctx *ctx) +struct bt_stream_class *create_reset_stream_class(struct ctx *ctx) { int ret; - struct bt_ctf_stream_class *stream_class; + struct bt_stream_class *stream_class; - stream_class = bt_ctf_stream_class_create_empty(NULL); + stream_class = bt_stream_class_create(NULL); if (!stream_class) { BT_LOGE_STR("Cannot create empty stream class."); goto error; @@ -3569,9 +3653,9 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) struct ctf_node *iter; int64_t stream_id = -1; char *event_name = NULL; - struct bt_ctf_event_class *event_class = NULL; - struct bt_ctf_event_class *eevent_class; - struct bt_ctf_stream_class *stream_class = NULL; + struct bt_event_class *event_class = NULL; + struct bt_event_class *eevent_class; + struct bt_stream_class *stream_class = NULL; struct bt_list_head *decl_list = &node->u.event.declaration_list; bool pop_scope = false; @@ -3588,7 +3672,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) goto error; } - event_class = bt_ctf_event_class_create(event_name); + event_class = bt_event_class_create(event_name); /* * Unset context and fields to override the default ones. @@ -3622,10 +3706,10 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) if (!_IS_SET(&set, _EVENT_STREAM_ID_SET)) { GList *keys = NULL; int64_t *new_stream_id; - struct bt_ctf_stream_class *new_stream_class; + struct bt_stream_class *new_stream_class; size_t stream_class_count = g_hash_table_size(ctx->stream_classes) + - bt_ctf_trace_get_stream_class_count(ctx->trace); + bt_trace_get_stream_class_count(ctx->trace); /* * Allow missing stream_id if there is only a single @@ -3634,6 +3718,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) switch (stream_class_count) { case 0: /* Create implicit stream class if there's none */ + stream_id = 0; new_stream_class = create_reset_stream_class(ctx); if (!new_stream_class) { _BT_LOGE_NODE(node, @@ -3642,7 +3727,8 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) goto error; } - ret = bt_ctf_stream_class_set_id(new_stream_class, 0); + ret = bt_stream_class_set_id(new_stream_class, + stream_id); if (ret) { _BT_LOGE_NODE(node, "Cannot set stream class's ID: " @@ -3658,6 +3744,8 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) goto error; } + *new_stream_id = stream_id; + /* Move reference to visitor's context */ g_hash_table_insert(ctx->stream_classes, new_stream_id, new_stream_class); @@ -3671,13 +3759,13 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) stream_id = *((int64_t *) keys->data); g_list_free(keys); } else { - assert(bt_ctf_trace_get_stream_class_count( + BT_ASSERT(bt_trace_get_stream_class_count( ctx->trace) == 1); stream_class = - bt_ctf_trace_get_stream_class_by_index( + bt_trace_get_stream_class_by_index( ctx->trace, 0); - assert(stream_class); - stream_id = bt_ctf_stream_class_get_id( + BT_ASSERT(stream_class); + stream_id = bt_stream_class_get_id( stream_class); BT_PUT(stream_class); } @@ -3690,13 +3778,13 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) } } - assert(stream_id >= 0); + BT_ASSERT(stream_id >= 0); /* We have the stream ID now; get the stream class if found */ stream_class = g_hash_table_lookup(ctx->stream_classes, &stream_id); bt_get(stream_class); if (!stream_class) { - stream_class = bt_ctf_trace_get_stream_class_by_id(ctx->trace, + stream_class = bt_trace_get_stream_class_by_id(ctx->trace, stream_id); if (!stream_class) { _BT_LOGE_NODE(node, @@ -3707,11 +3795,11 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) } } - assert(stream_class); + BT_ASSERT(stream_class); if (!_IS_SET(&set, _EVENT_ID_SET)) { /* Allow only one event without ID per stream */ - if (bt_ctf_stream_class_get_event_class_count(stream_class) != + if (bt_stream_class_get_event_class_count(stream_class) != 0) { _BT_LOGE_NODE(node, "Missing `id` attribute in event class."); @@ -3720,7 +3808,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) } /* Automatic ID */ - ret = bt_ctf_event_class_set_id(event_class, 0); + ret = bt_event_class_set_id(event_class, 0); if (ret) { _BT_LOGE_NODE(node, "Cannot set event class's ID: id=0, ret=%d", @@ -3729,14 +3817,14 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) } } - event_id = bt_ctf_event_class_get_id(event_class); + event_id = bt_event_class_get_id(event_class); if (event_id < 0) { _BT_LOGE_NODE(node, "Cannot get event class's ID."); ret = -EINVAL; goto error; } - eevent_class = bt_ctf_stream_class_get_event_class_by_id(stream_class, + eevent_class = bt_stream_class_get_event_class_by_id(stream_class, event_id); if (eevent_class) { BT_PUT(eevent_class); @@ -3747,7 +3835,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) goto error; } - ret = bt_ctf_stream_class_add_event_class(stream_class, event_class); + ret = bt_stream_class_add_event_class(stream_class, event_class); BT_PUT(event_class); if (ret) { _BT_LOGE_NODE(node, @@ -3772,25 +3860,25 @@ end: static int auto_map_field_to_trace_clock_class(struct ctx *ctx, - struct bt_ctf_field_type *ft) + struct bt_field_type *ft) { - struct bt_ctf_clock_class *clock_class_to_map_to = NULL; - struct bt_ctf_clock_class *mapped_clock_class = NULL; + struct bt_clock_class *clock_class_to_map_to = NULL; + struct bt_clock_class *mapped_clock_class = NULL; int ret = 0; int64_t clock_class_count; - if (!ft || !bt_ctf_field_type_is_integer(ft)) { + if (!ft || !bt_field_type_is_integer(ft)) { goto end; } mapped_clock_class = - bt_ctf_field_type_integer_get_mapped_clock_class(ft); + bt_field_type_integer_get_mapped_clock_class(ft); if (mapped_clock_class) { goto end; } - clock_class_count = bt_ctf_trace_get_clock_class_count(ctx->trace); - assert(clock_class_count >= 0); + clock_class_count = bt_trace_get_clock_class_count(ctx->trace); + BT_ASSERT(clock_class_count >= 0); switch (clock_class_count) { case 0: @@ -3799,7 +3887,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, * point. Create an implicit one at 1 GHz, * named `default`, and use this clock class. */ - clock_class_to_map_to = bt_ctf_clock_class_create("default", + clock_class_to_map_to = bt_clock_class_create("default", 1000000000); if (!clock_class_to_map_to) { BT_LOGE_STR("Cannot create a clock class."); @@ -3807,7 +3895,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, goto end; } - ret = bt_ctf_trace_add_clock_class(ctx->trace, + ret = bt_trace_add_clock_class(ctx->trace, clock_class_to_map_to); if (ret) { BT_LOGE_STR("Cannot add clock class to trace."); @@ -3820,8 +3908,8 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, * this point: use this one. */ clock_class_to_map_to = - bt_ctf_trace_get_clock_class_by_index(ctx->trace, 0); - assert(clock_class_to_map_to); + bt_trace_get_clock_class_by_index(ctx->trace, 0); + BT_ASSERT(clock_class_to_map_to); break; default: /* @@ -3835,13 +3923,13 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, goto end; } - assert(clock_class_to_map_to); - ret = bt_ctf_field_type_integer_set_mapped_clock_class(ft, + BT_ASSERT(clock_class_to_map_to); + ret = bt_field_type_integer_set_mapped_clock_class(ft, clock_class_to_map_to); if (ret) { BT_LOGE("Cannot map field type's field to trace's clock class: " "clock-class-name=\"%s\", ret=%d", - bt_ctf_clock_class_get_name(clock_class_to_map_to), + bt_clock_class_get_name(clock_class_to_map_to), ret); goto end; } @@ -3854,7 +3942,7 @@ end: static int auto_map_fields_to_trace_clock_class(struct ctx *ctx, - struct bt_ctf_field_type *root_ft, const char *field_name) + struct bt_field_type *root_ft, const char *field_name) { int ret = 0; int64_t i, count; @@ -3863,32 +3951,32 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx, goto end; } - if (!bt_ctf_field_type_is_structure(root_ft) && - !bt_ctf_field_type_is_variant(root_ft)) { + if (!bt_field_type_is_structure(root_ft) && + !bt_field_type_is_variant(root_ft)) { goto end; } - if (bt_ctf_field_type_is_structure(root_ft)) { - count = bt_ctf_field_type_structure_get_field_count(root_ft); + if (bt_field_type_is_structure(root_ft)) { + count = bt_field_type_structure_get_field_count(root_ft); } else { - count = bt_ctf_field_type_variant_get_field_count(root_ft); + count = bt_field_type_variant_get_field_count(root_ft); } - assert(count >= 0); + BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { - _BT_CTF_FIELD_TYPE_INIT(ft); + _BT_FIELD_TYPE_INIT(ft); const char *name; - if (bt_ctf_field_type_is_structure(root_ft)) { - ret = bt_ctf_field_type_structure_get_field_by_index( + if (bt_field_type_is_structure(root_ft)) { + ret = bt_field_type_structure_get_field_by_index( root_ft, &name, &ft, i); - } else if (bt_ctf_field_type_is_variant(root_ft)) { - ret = bt_ctf_field_type_variant_get_field_by_index( + } else if (bt_field_type_is_variant(root_ft)) { + ret = bt_field_type_variant_get_field_by_index( root_ft, &name, &ft, i); } - assert(ret == 0); + BT_ASSERT(ret == 0); if (strcmp(name, field_name) == 0) { ret = auto_map_field_to_trace_clock_class(ctx, ft); @@ -3916,11 +4004,11 @@ end: static int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, - struct bt_ctf_stream_class *stream_class, int *set) + struct bt_stream_class *stream_class, int *set) { int ret = 0; char *left = NULL; - _BT_CTF_FIELD_TYPE_INIT(decl); + _BT_FIELD_TYPE_INIT(decl); switch (node->type) { case NODE_TYPEDEF: @@ -3980,7 +4068,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - ret = bt_ctf_stream_class_set_id(stream_class, id); + ret = bt_stream_class_set_id(stream_class, id); if (ret) { _BT_LOGE_NODE(node, "Cannot set stream class's ID: " @@ -4008,7 +4096,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = auto_map_fields_to_trace_clock_class(ctx, decl, "timestamp"); if (ret) { @@ -4017,7 +4105,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - ret = bt_ctf_stream_class_set_event_header_type( + ret = bt_stream_class_set_event_header_field_type( stream_class, decl); BT_PUT(decl); if (ret) { @@ -4046,9 +4134,9 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); - ret = bt_ctf_stream_class_set_event_context_type( + ret = bt_stream_class_set_event_context_field_type( stream_class, decl); BT_PUT(decl); if (ret) { @@ -4077,7 +4165,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - assert(decl); + BT_ASSERT(decl); ret = auto_map_fields_to_trace_clock_class(ctx, decl, "timestamp_begin"); if (ret) { @@ -4094,7 +4182,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - ret = bt_ctf_stream_class_set_packet_context_type( + ret = bt_stream_class_set_packet_context_field_type( stream_class, decl); BT_PUT(decl); if (ret) { @@ -4137,8 +4225,8 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) int set = 0; int ret = 0; struct ctf_node *iter; - struct bt_ctf_stream_class *stream_class = NULL; - struct bt_ctf_stream_class *existing_stream_class = NULL; + struct bt_stream_class *stream_class = NULL; + struct bt_stream_class *existing_stream_class = NULL; struct bt_list_head *decl_list = &node->u.stream.declaration_list; if (node->visited) { @@ -4174,11 +4262,11 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) if (_IS_SET(&set, _STREAM_ID_SET)) { /* Check that packet header has stream_id field */ - _BT_CTF_FIELD_TYPE_INIT(stream_id_decl); - _BT_CTF_FIELD_TYPE_INIT(packet_header_decl); + _BT_FIELD_TYPE_INIT(stream_id_decl); + _BT_FIELD_TYPE_INIT(packet_header_decl); packet_header_decl = - bt_ctf_trace_get_packet_header_type(ctx->trace); + bt_trace_get_packet_header_field_type(ctx->trace); if (!packet_header_decl) { _BT_LOGE_NODE(node, "Stream class has a `id` attribute, " @@ -4187,7 +4275,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) } stream_id_decl = - bt_ctf_field_type_structure_get_field_type_by_name( + bt_field_type_structure_get_field_type_by_name( packet_header_decl, "stream_id"); BT_PUT(packet_header_decl); if (!stream_id_decl) { @@ -4197,7 +4285,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) goto error; } - if (!bt_ctf_field_type_is_integer(stream_id_decl)) { + if (!bt_field_type_is_integer(stream_id_decl)) { BT_PUT(stream_id_decl); _BT_LOGE_NODE(node, "Stream class has a `id` attribute, " @@ -4216,11 +4304,11 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) } /* Automatic ID: 0 */ - ret = bt_ctf_stream_class_set_id(stream_class, 0); - assert(ret == 0); + ret = bt_stream_class_set_id(stream_class, 0); + BT_ASSERT(ret == 0); } - id = bt_ctf_stream_class_get_id(stream_class); + id = bt_stream_class_get_id(stream_class); if (id < 0) { _BT_LOGE_NODE(node, "Cannot get stream class's ID."); @@ -4232,7 +4320,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) * Make sure that this stream class's ID is currently unique in * the trace. */ - existing_stream_class = bt_ctf_trace_get_stream_class_by_id(ctx->trace, + existing_stream_class = bt_trace_get_stream_class_by_id(ctx->trace, id); if (g_hash_table_lookup(ctx->stream_classes, &id) || existing_stream_class) { @@ -4270,7 +4358,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) { int ret = 0; char *left = NULL; - _BT_CTF_FIELD_TYPE_INIT(packet_header_decl); + _BT_FIELD_TYPE_INIT(packet_header_decl); switch (node->type) { case NODE_TYPEDEF: @@ -4349,7 +4437,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) goto error; } - ret = bt_ctf_trace_set_uuid(ctx->trace, ctx->trace_uuid); + ret = bt_trace_set_uuid(ctx->trace, ctx->trace_uuid); if (ret) { _BT_LOGE_NODE(node, "Cannot set trace's UUID."); goto error; @@ -4385,8 +4473,8 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) goto error; } - assert(packet_header_decl); - ret = bt_ctf_trace_set_packet_header_type(ctx->trace, + BT_ASSERT(packet_header_decl); + ret = bt_trace_set_packet_header_field_type(ctx->trace, packet_header_decl); BT_PUT(packet_header_decl); if (ret) { @@ -4544,7 +4632,7 @@ int visit_env(struct ctx *ctx, struct ctf_node *node) } } - ret = bt_ctf_trace_set_environment_field_string( + ret = bt_trace_set_environment_field_string( ctx->trace, left, right); g_free(right); @@ -4572,7 +4660,7 @@ int visit_env(struct ctx *ctx, struct ctf_node *node) goto error; } - ret = bt_ctf_trace_set_environment_field_integer( + ret = bt_trace_set_environment_field_integer( ctx->trace, left, v); if (ret) { _BT_LOGE_NODE(entry_node, @@ -4622,7 +4710,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node) } if (!strcmp(left, "byte_order")) { - enum bt_ctf_byte_order bo; + enum bt_byte_order bo; if (_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) { _BT_LOGE_DUP_ATTR(node, "byte_order", @@ -4636,13 +4724,13 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node) &node->u.ctf_expression.right, struct ctf_node, siblings); bo = byte_order_from_unary_expr(right_node); - if (bo == BT_CTF_BYTE_ORDER_UNKNOWN) { + if (bo == BT_BYTE_ORDER_UNKNOWN) { _BT_LOGE_NODE(node, "Invalid `byte_order` attribute in trace (`trace` block): " "expecting `le`, `be`, or `network`."); ret = -EINVAL; goto error; - } else if (bo == BT_CTF_BYTE_ORDER_NATIVE) { + } else if (bo == BT_BYTE_ORDER_NATIVE) { _BT_LOGE_NODE(node, "Invalid `byte_order` attribute in trace (`trace` block): " "cannot be set to `native` here."); @@ -4651,7 +4739,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node) } ctx->trace_bo = bo; - ret = bt_ctf_trace_set_native_byte_order( + ret = bt_trace_set_native_byte_order( ctx->trace, bo); if (ret) { _BT_LOGE_NODE(node, @@ -4683,7 +4771,7 @@ error: static int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, - struct bt_ctf_clock_class *clock, int *set) + struct bt_clock_class *clock, int *set) { int ret = 0; char *left = NULL; @@ -4721,7 +4809,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_name(clock, right); + ret = bt_clock_class_set_name(clock, right); if (ret) { _BT_LOGE_NODE(entry_node, "cannot set clock class's name"); @@ -4747,7 +4835,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_uuid(clock, uuid); + ret = bt_clock_class_set_uuid(clock, uuid); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's UUID."); @@ -4774,7 +4862,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_description(clock, right); + ret = bt_clock_class_set_description(clock, right); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's description."); @@ -4785,7 +4873,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, g_free(right); _SET(set, _CLOCK_DESCRIPTION_SET); } else if (!strcmp(left, "freq")) { - uint64_t freq; + uint64_t freq = -1ULL; if (_IS_SET(set, _CLOCK_FREQ_SET)) { _BT_LOGE_DUP_ATTR(entry_node, "freq", "clock class"); @@ -4810,7 +4898,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_frequency(clock, freq); + ret = bt_clock_class_set_frequency(clock, freq); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's frequency."); @@ -4837,7 +4925,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_precision(clock, precision); + ret = bt_clock_class_set_precision(clock, precision); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's precision."); @@ -4864,7 +4952,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_offset_s(clock, offset_s); + ret = bt_clock_class_set_offset_s(clock, offset_s); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's offset in seconds."); @@ -4890,7 +4978,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_offset_cycles(clock, offset); + ret = bt_clock_class_set_offset_cycles(clock, offset); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's offset in cycles."); @@ -4919,7 +5007,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_ctf_clock_class_set_is_absolute(clock, ret); + ret = bt_clock_class_set_is_absolute(clock, ret); if (ret) { _BT_LOGE_NODE(entry_node, "Cannot set clock class's absolute flag."); @@ -4960,21 +5048,21 @@ int64_t cycles_from_ns(uint64_t frequency, int64_t ns) } static -int apply_clock_class_offset(struct ctx *ctx, struct bt_ctf_clock_class *clock) +int apply_clock_class_offset(struct ctx *ctx, struct bt_clock_class *clock) { int ret; uint64_t freq; int64_t offset_cycles; int64_t offset_to_apply; - freq = bt_ctf_clock_class_get_frequency(clock); + freq = bt_clock_class_get_frequency(clock); if (freq == -1ULL) { BT_LOGE_STR("Cannot get clock class's frequency."); ret = -1; goto end; } - ret = bt_ctf_clock_class_get_offset_cycles(clock, &offset_cycles); + ret = bt_clock_class_get_offset_cycles(clock, &offset_cycles); if (ret) { BT_LOGE_STR("Cannot get clock class's offset in cycles."); ret = -1; @@ -4985,7 +5073,7 @@ int apply_clock_class_offset(struct ctx *ctx, struct bt_ctf_clock_class *clock) ctx->decoder_config.clock_class_offset_s * 1000000000LL + ctx->decoder_config.clock_class_offset_ns; offset_cycles += cycles_from_ns(freq, offset_to_apply); - ret = bt_ctf_clock_class_set_offset_cycles(clock, offset_cycles); + ret = bt_clock_class_set_offset_cycles(clock, offset_cycles); end: return ret; @@ -4996,7 +5084,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) { int ret = 0; int set = 0; - struct bt_ctf_clock_class *clock; + struct bt_clock_class *clock; struct ctf_node *entry_node; struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list; const char *clock_class_name; @@ -5008,7 +5096,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) clock_node->visited = TRUE; /* CTF 1.8's default frequency for a clock class is 1 GHz */ - clock = bt_ctf_clock_class_create(NULL, 1000000000); + clock = bt_clock_class_create(NULL, 1000000000); if (!clock) { _BT_LOGE_NODE(clock_node, "Cannot create default clock class."); @@ -5033,8 +5121,8 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) goto error; } - clock_class_name = bt_ctf_clock_class_get_name(clock); - assert(clock_class_name); + clock_class_name = bt_clock_class_get_name(clock); + BT_ASSERT(clock_class_name); if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) { /* * Old versions of LTTng forgot to set its clock class @@ -5042,7 +5130,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) * it's a condition to be able to sort notifications * from different sources. */ - ret = bt_ctf_clock_class_set_is_absolute(clock, 1); + ret = bt_clock_class_set_is_absolute(clock, 1); if (ret) { _BT_LOGE_NODE(clock_node, "Cannot set clock class's absolute flag."); @@ -5057,7 +5145,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) goto error; } - ret = bt_ctf_trace_add_clock_class(ctx->trace, clock); + ret = bt_trace_add_clock_class(ctx->trace, clock); if (ret) { _BT_LOGE_NODE(clock_node, "Cannot add clock class to trace."); @@ -5103,7 +5191,7 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node) break; case NODE_TYPE_SPECIFIER_LIST: { - _BT_CTF_FIELD_TYPE_INIT(decl); + _BT_FIELD_TYPE_INIT(decl); /* * Just add the type specifier to the root @@ -5114,7 +5202,7 @@ int visit_root_decl(struct ctx *ctx, struct ctf_node *root_decl_node) _BT_LOGE_NODE(root_decl_node, "Cannot visit root scope's field type: " "ret=%d", ret); - assert(!decl); + BT_ASSERT(!decl); goto end; } @@ -5140,7 +5228,7 @@ int set_trace_name(struct ctx *ctx) int ret = 0; struct bt_value *value = NULL; - assert(bt_ctf_trace_get_stream_class_count(ctx->trace) == 0); + BT_ASSERT(bt_trace_get_stream_class_count(ctx->trace) == 0); name = g_string_new(NULL); if (!name) { BT_LOGE_STR("Failed to allocate a GString."); @@ -5152,13 +5240,13 @@ int set_trace_name(struct ctx *ctx) * Check if we have a trace environment string value named `hostname`. * If so, use it as the trace name's prefix. */ - value = bt_ctf_trace_get_environment_field_value_by_name(ctx->trace, + value = bt_trace_get_environment_field_value_by_name(ctx->trace, "hostname"); - if (bt_value_is_string(value)) { + if (value && bt_value_is_string(value)) { const char *hostname; ret = bt_value_string_get(value, &hostname); - assert(ret == 0); + BT_ASSERT(ret == 0); g_string_append(name, hostname); if (ctx->trace_name_suffix) { @@ -5170,7 +5258,7 @@ int set_trace_name(struct ctx *ctx) g_string_append(name, ctx->trace_name_suffix); } - ret = bt_ctf_trace_set_name(ctx->trace, name->str); + ret = bt_trace_set_name(ctx->trace, name->str); if (ret) { BT_LOGE("Cannot set trace's name: name=\"%s\"", name->str); goto error; @@ -5199,7 +5287,7 @@ int move_ctx_stream_classes_to_trace(struct ctx *ctx) gpointer key, stream_class; if (g_hash_table_size(ctx->stream_classes) > 0 && - bt_ctf_trace_get_stream_class_count(ctx->trace) == 0) { + bt_trace_get_stream_class_count(ctx->trace) == 0) { /* * We're about to add the first stream class to the * trace. This will freeze the trace, and after this @@ -5216,10 +5304,10 @@ int move_ctx_stream_classes_to_trace(struct ctx *ctx) g_hash_table_iter_init(&iter, ctx->stream_classes); while (g_hash_table_iter_next(&iter, &key, &stream_class)) { - ret = bt_ctf_trace_add_stream_class(ctx->trace, + ret = bt_trace_add_stream_class(ctx->trace, stream_class); if (ret) { - int64_t id = bt_ctf_stream_class_get_id(stream_class); + int64_t id = bt_stream_class_get_id(stream_class); BT_LOGE("Cannot add stream class to trace: id=%" PRId64, id); goto end; @@ -5239,16 +5327,16 @@ struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create( { int ret; struct ctx *ctx = NULL; - struct bt_ctf_trace *trace; + struct bt_trace *trace; - trace = bt_ctf_trace_create(); + trace = bt_trace_create(); if (!trace) { BT_LOGE_STR("Cannot create empty trace."); goto error; } /* Set packet header to NULL to override the default one */ - ret = bt_ctf_trace_set_packet_header_type(trace, NULL); + ret = bt_trace_set_packet_header_field_type(trace, NULL); if (ret) { BT_LOGE_STR("Cannot reset initial trace's packet header field type."); goto error; @@ -5280,13 +5368,13 @@ void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor) } BT_HIDDEN -struct bt_ctf_trace *ctf_visitor_generate_ir_get_trace( +struct bt_trace *ctf_visitor_generate_ir_get_trace( struct ctf_visitor_generate_ir *visitor) { struct ctx *ctx = (void *) visitor; - assert(ctx); - assert(ctx->trace); + BT_ASSERT(ctx); + BT_ASSERT(ctx->trace); return bt_get(ctx->trace); } @@ -5312,7 +5400,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, * have the native byte order yet, and we don't have any * trace block yet, then fail with EINCOMPLETE. */ - if (ctx->trace_bo == BT_CTF_BYTE_ORDER_NATIVE) { + if (ctx->trace_bo == BT_BYTE_ORDER_NATIVE) { bt_list_for_each_entry(iter, &node->u.root.trace, siblings) { if (got_trace_decl) { _BT_LOGE_NODE(node, @@ -5339,9 +5427,9 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->trace_bo == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN || - ctx->trace_bo == BT_CTF_BYTE_ORDER_BIG_ENDIAN); - assert(ctx->current_scope && + BT_ASSERT(ctx->trace_bo == BT_BYTE_ORDER_LITTLE_ENDIAN || + ctx->trace_bo == BT_BYTE_ORDER_BIG_ENDIAN); + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Environment */ @@ -5355,7 +5443,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* @@ -5371,7 +5459,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* @@ -5389,7 +5477,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Callsite blocks are not supported */ @@ -5398,7 +5486,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, "\"callsite\" blocks are not supported as of this version."); } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Trace */ @@ -5412,7 +5500,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Streams */ @@ -5426,7 +5514,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); /* Events */ @@ -5440,7 +5528,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } } - assert(ctx->current_scope && + BT_ASSERT(ctx->current_scope && ctx->current_scope->parent_scope == NULL); break; }