ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / formats / ctf / ir / resolve.c
index fd4540108d7baabeec76f4cc6eee48ea0d4806e5..4bc4130f96856b0018e91e449038430618df963e 100644 (file)
@@ -31,7 +31,9 @@
 #include <babeltrace/ctf-ir/event.h>
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/resolve-internal.h>
-#include <babeltrace/ctf-ir/event-types-internal.h>
+#include <babeltrace/ctf-ir/field-types.h>
+#include <babeltrace/ctf-ir/field-path.h>
+#include <babeltrace/ctf-ir/field-path-internal.h>
 #include <babeltrace/ctf-ir/event-internal.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/babeltrace-internal.h>
@@ -75,32 +77,32 @@ struct resolve_context {
        struct bt_value *environment;
        struct bt_ctf_field_type *scopes[6];
 
-       /* Root node being visited */
-       enum bt_ctf_node root_node;
+       /* Root scope being visited */
+       enum bt_ctf_scope root_scope;
        type_stack *type_stack;
        struct bt_ctf_field_type *cur_field_type;
 };
 
 /* TSDL dynamic scope prefixes as defined in CTF Section 7.3.2 */
 static const char * const absolute_path_prefixes[] = {
-       [CTF_NODE_ENV]                          = "env.",
-       [CTF_NODE_TRACE_PACKET_HEADER]          = "trace.packet.header.",
-       [CTF_NODE_STREAM_PACKET_CONTEXT]        = "stream.packet.context.",
-       [CTF_NODE_STREAM_EVENT_HEADER]          = "stream.event.header.",
-       [CTF_NODE_STREAM_EVENT_CONTEXT]         = "stream.event.context.",
-       [CTF_NODE_EVENT_CONTEXT]                = "event.context.",
-       [CTF_NODE_EVENT_FIELDS]                 = "event.fields.",
+       [BT_CTF_SCOPE_ENV]                      = "env.",
+       [BT_CTF_SCOPE_TRACE_PACKET_HEADER]      = "trace.packet.header.",
+       [BT_CTF_SCOPE_STREAM_PACKET_CONTEXT]    = "stream.packet.context.",
+       [BT_CTF_SCOPE_STREAM_EVENT_HEADER]      = "stream.event.header.",
+       [BT_CTF_SCOPE_STREAM_EVENT_CONTEXT]     = "stream.event.context.",
+       [BT_CTF_SCOPE_EVENT_CONTEXT]            = "event.context.",
+       [BT_CTF_SCOPE_EVENT_FIELDS]             = "event.fields.",
 };
 
 /* Number of path tokens used for the absolute prefixes */
 static const int absolute_path_prefix_ptoken_counts[] = {
-       [CTF_NODE_ENV]                          = 1,
-       [CTF_NODE_TRACE_PACKET_HEADER]          = 3,
-       [CTF_NODE_STREAM_PACKET_CONTEXT]        = 3,
-       [CTF_NODE_STREAM_EVENT_HEADER]          = 3,
-       [CTF_NODE_STREAM_EVENT_CONTEXT]         = 3,
-       [CTF_NODE_EVENT_CONTEXT]                = 2,
-       [CTF_NODE_EVENT_FIELDS]                 = 2,
+       [BT_CTF_SCOPE_ENV]                      = 1,
+       [BT_CTF_SCOPE_TRACE_PACKET_HEADER]      = 3,
+       [BT_CTF_SCOPE_STREAM_PACKET_CONTEXT]    = 3,
+       [BT_CTF_SCOPE_STREAM_EVENT_HEADER]      = 3,
+       [BT_CTF_SCOPE_STREAM_EVENT_CONTEXT]     = 3,
+       [BT_CTF_SCOPE_EVENT_CONTEXT]            = 2,
+       [BT_CTF_SCOPE_EVENT_FIELDS]             = 2,
 };
 
 /*
@@ -244,12 +246,12 @@ void type_stack_pop(type_stack *stack)
  */
 static
 struct bt_ctf_field_type *get_type_from_ctx(struct resolve_context *ctx,
-               enum bt_ctf_node node)
+               enum bt_ctf_scope scope)
 {
-       assert(node >= CTF_NODE_TRACE_PACKET_HEADER &&
-               node <= CTF_NODE_EVENT_FIELDS);
+       assert(scope >= BT_CTF_SCOPE_TRACE_PACKET_HEADER &&
+               scope <= BT_CTF_SCOPE_EVENT_FIELDS);
 
-       return ctx->scopes[node - CTF_NODE_TRACE_PACKET_HEADER];
+       return ctx->scopes[scope - BT_CTF_SCOPE_TRACE_PACKET_HEADER];
 }
 
 /*
@@ -257,29 +259,29 @@ struct bt_ctf_field_type *get_type_from_ctx(struct resolve_context *ctx,
  * CTF_NODE_UNKNOWN if the path is found to be relative.
  */
 static
-enum bt_ctf_node get_root_node_from_absolute_pathstr(const char *pathstr)
+enum bt_ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr)
 {
-       enum bt_ctf_node node;
-       enum bt_ctf_node ret = CTF_NODE_UNKNOWN;
+       enum bt_ctf_scope scope;
+       enum bt_ctf_scope ret = BT_CTF_SCOPE_UNKNOWN;
        const size_t prefixes_count = sizeof(absolute_path_prefixes) /
                sizeof(*absolute_path_prefixes);
 
-       for (node = CTF_NODE_ENV; node < CTF_NODE_ENV + prefixes_count;
-                       node++) {
+       for (scope = BT_CTF_SCOPE_ENV; scope < BT_CTF_SCOPE_ENV +
+                       prefixes_count; scope++) {
                /*
                 * Chech if path string starts with a known absolute
                 * path prefix.
                 *
                 * Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES.
                 */
-               if (strncmp(pathstr, absolute_path_prefixes[node],
-                               strlen(absolute_path_prefixes[node]))) {
+               if (strncmp(pathstr, absolute_path_prefixes[scope],
+                               strlen(absolute_path_prefixes[scope]))) {
                        /* Prefix does not match: try the next one */
                        continue;
                }
 
                /* Found it! */
-               ret = node;
+               ret = scope;
                goto end;
        }
 
@@ -423,7 +425,7 @@ int ptokens_to_field_path(GList *ptokens, struct bt_ctf_field_path *field_path,
                }
 
                /* Create new field path entry */
-               g_array_append_val(field_path->path_indexes, child_index);
+               g_array_append_val(field_path->indexes, child_index);
 
                /* Get child field type */
                child_type = bt_ctf_field_type_get_field_at_index(type,
@@ -468,7 +470,7 @@ int absolute_ptokens_to_field_path(GList *ptokens,
        type = get_type_from_ctx(ctx, field_path->root);
        if (!type) {
                /* Error: root type is not available */
-               _printf_error("Root type with node type %d is not available\n",
+               _printf_error("Root type with scope type %d is not available\n",
                        field_path->root);
                ret = -1;
                goto end;
@@ -522,7 +524,7 @@ int relative_ptokens_to_field_path(GList *ptokens,
                        /* Found: stitch tail field path to head field path */
                        int i = 0;
                        int tail_field_path_len =
-                               tail_field_path->path_indexes->len;
+                               tail_field_path->indexes->len;
 
                        while (true) {
                                struct bt_ctf_field_type *cur_type =
@@ -534,17 +536,17 @@ int relative_ptokens_to_field_path(GList *ptokens,
                                        break;
                                }
 
-                               g_array_append_val(field_path->path_indexes,
+                               g_array_append_val(field_path->indexes,
                                        index);
                                i++;
                        }
 
                        for (i = 0; i < tail_field_path_len; i++) {
                                int index = g_array_index(
-                                       tail_field_path->path_indexes,
+                                       tail_field_path->indexes,
                                        int, i);
 
-                               g_array_append_val(field_path->path_indexes,
+                               g_array_append_val(field_path->indexes,
                                        index);
                        }
                        break;
@@ -557,7 +559,7 @@ int relative_ptokens_to_field_path(GList *ptokens,
                /* Not found: look in previous scopes */
                field_path->root--;
 
-               while (field_path->root >= CTF_NODE_TRACE_PACKET_HEADER) {
+               while (field_path->root >= BT_CTF_SCOPE_TRACE_PACKET_HEADER) {
                        struct bt_ctf_field_type *root_type;
                        bt_ctf_field_path_clear(field_path);
 
@@ -582,7 +584,7 @@ int relative_ptokens_to_field_path(GList *ptokens,
        }
 
 end:
-       bt_ctf_field_path_destroy(tail_field_path);
+       BT_PUT(tail_field_path);
        return ret;
 }
 
@@ -597,7 +599,7 @@ struct bt_ctf_field_path *pathstr_to_field_path(const char *pathstr,
                struct resolve_context *ctx)
 {
        int ret;
-       enum bt_ctf_node root_node;
+       enum bt_ctf_scope root_scope;
        GList *ptokens = NULL;
        struct bt_ctf_field_path *field_path = NULL;
 
@@ -619,39 +621,38 @@ struct bt_ctf_field_path *pathstr_to_field_path(const char *pathstr,
        }
 
        /* Absolute or relative path? */
-       root_node = get_root_node_from_absolute_pathstr(pathstr);
+       root_scope = get_root_scope_from_absolute_pathstr(pathstr);
 
-       if (root_node == CTF_NODE_UNKNOWN) {
-               /* Relative path: start with current root node */
-               field_path->root = ctx->root_node;
+       if (root_scope == BT_CTF_SCOPE_UNKNOWN) {
+               /* Relative path: start with current root scope */
+               field_path->root = ctx->root_scope;
                ret = relative_ptokens_to_field_path(ptokens, field_path, ctx);
                if (ret) {
                        _printf_error("Cannot get relative field path of path string \"%s\"\n",
                                pathstr);
-                       _printf_error("  Starting at root node %d, finished at root node %d\n",
-                               ctx->root_node, field_path->root);
+                       _printf_error("  Starting at root scope %d, finished at root scope %d\n",
+                               ctx->root_scope, field_path->root);
                        goto end;
                }
-       } else if (root_node == CTF_NODE_ENV) {
+       } else if (root_scope == BT_CTF_SCOPE_ENV) {
                _printf_error("Sequence field types referring the trace environment are not supported as of this version\n");
                ret = -1;
                goto end;
        } else {
-               /* Absolute path: use found root node */
-               field_path->root = root_node;
+               /* Absolute path: use found root scope */
+               field_path->root = root_scope;
                ret = absolute_ptokens_to_field_path(ptokens, field_path, ctx);
                if (ret) {
                        _printf_error("Cannot get absolute field path of path string \"%s\"\n",
                                pathstr);
-                       _printf_error("  Looking in root node %d\n", root_node);
+                       _printf_error("  Looking in root scope %d\n", root_scope);
                        goto end;
                }
        }
 
 end:
        if (ret) {
-               bt_ctf_field_path_destroy(field_path);
-               field_path = NULL;
+               BT_PUT(field_path);
        }
 
        ptokens_destroy(ptokens);
@@ -678,16 +679,16 @@ struct bt_ctf_field_type *field_path_to_field_type(
        bt_get(type);
        if (!type) {
                /* Error: root type is not available */
-               _printf_error("Root type with node type %d is not available\n",
+               _printf_error("Root type with scope type %d is not available\n",
                        field_path->root);
                goto error;
        }
 
        /* Locate target */
-       for (i = 0; i < field_path->path_indexes->len; i++) {
+       for (i = 0; i < field_path->indexes->len; i++) {
                struct bt_ctf_field_type *child_type;
                int child_index =
-                       g_array_index(field_path->path_indexes, int, i);
+                       g_array_index(field_path->indexes, int, i);
 
                /* Get child field type */
                child_type = bt_ctf_field_type_get_field_at_index(type,
@@ -727,20 +728,20 @@ struct bt_ctf_field_path *get_ctx_stack_field_path(struct resolve_context *ctx)
                goto error;
        }
 
-       field_path->root = ctx->root_node;
+       field_path->root = ctx->root_scope;
 
        for (i = 0; i < type_stack_size(ctx->type_stack); i++) {
                struct type_stack_frame *frame;
 
                frame = type_stack_at(ctx->type_stack, i);
-               g_array_append_val(field_path->path_indexes, frame->index);
+               g_array_append_val(field_path->indexes, frame->index);
        }
 
        return field_path;
 
 error:
-       bt_ctf_field_path_destroy(field_path);
-       return NULL;
+       BT_PUT(field_path);
+       return field_path;
 }
 
 /*
@@ -759,8 +760,8 @@ int get_field_paths_lca_index(struct bt_ctf_field_path *field_path1,
         * Start from both roots and find the first mismatch.
         */
        assert(field_path1->root == field_path2->root);
-       field_path1_len = field_path1->path_indexes->len;
-       field_path2_len = field_path2->path_indexes->len;
+       field_path1_len = field_path1->indexes->len;
+       field_path2_len = field_path2->indexes->len;
 
        while (true) {
                int target_index, ctx_index;
@@ -777,9 +778,9 @@ int get_field_paths_lca_index(struct bt_ctf_field_path *field_path1,
                        break;
                }
 
-               target_index = g_array_index(field_path1->path_indexes, int,
+               target_index = g_array_index(field_path1->indexes, int,
                        lca_index);
-               ctx_index = g_array_index(field_path2->path_indexes, int,
+               ctx_index = g_array_index(field_path2->indexes, int,
                        lca_index);
 
                if (target_index != ctx_index) {
@@ -805,7 +806,7 @@ int validate_target_field_path(struct bt_ctf_field_path *target_field_path,
 {
        int ret = 0;
        struct bt_ctf_field_path *ctx_field_path;
-       int target_field_path_len = target_field_path->path_indexes->len;
+       int target_field_path_len = target_field_path->indexes->len;
        int lca_index;
        int ctx_cur_field_type_id;
        int target_type_id;
@@ -856,9 +857,9 @@ int validate_target_field_path(struct bt_ctf_field_path *target_field_path,
                 * Make sure the target field path is located before the
                 * context field path.
                 */
-               target_index = g_array_index(target_field_path->path_indexes,
+               target_index = g_array_index(target_field_path->indexes,
                        int, lca_index);
-               ctx_index = g_array_index(ctx_field_path->path_indexes,
+               ctx_index = g_array_index(ctx_field_path->indexes,
                        int, lca_index);
 
                if (target_index >= ctx_index) {
@@ -895,7 +896,7 @@ int validate_target_field_path(struct bt_ctf_field_path *target_field_path,
        }
 
 end:
-       bt_ctf_field_path_destroy(ctx_field_path);
+       BT_PUT(ctx_field_path);
        return ret;
 }
 
@@ -926,6 +927,8 @@ int resolve_sequence_or_variant_type(struct bt_ctf_field_type *type,
                break;
        default:
                assert(false);
+               ret = -1;
+               goto end;
        }
 
        /* Get target field path out of path string */
@@ -961,8 +964,6 @@ int resolve_sequence_or_variant_type(struct bt_ctf_field_type *type,
                        _printf_error("Cannot set sequence field type's length field path\n");
                        goto end;
                }
-
-               target_field_path = NULL;
        } else if (type_id == CTF_TYPE_VARIANT) {
                ret = bt_ctf_field_type_variant_set_tag_field_path(
                        type, target_field_path);
@@ -971,9 +972,8 @@ int resolve_sequence_or_variant_type(struct bt_ctf_field_type *type,
                        goto end;
                }
 
-               target_field_path = NULL;
-
-               ret = bt_ctf_field_type_variant_set_tag(type, target_type);
+               ret = bt_ctf_field_type_variant_set_tag_field_type(
+                       type, target_type);
                if (ret) {
                        _printf_error("Cannot set variant field type's tag field type\n");
                        goto end;
@@ -983,7 +983,7 @@ int resolve_sequence_or_variant_type(struct bt_ctf_field_type *type,
        }
 
 end:
-       bt_ctf_field_path_destroy(target_field_path);
+       BT_PUT(target_field_path);
        BT_PUT(target_type);
        return ret;
 }
@@ -1087,14 +1087,14 @@ end:
  * Resolves the root field type corresponding to the scope `root_scope`.
  */
 static
-int resolve_root_type(enum ctf_type_id root_node, struct resolve_context *ctx)
+int resolve_root_type(enum bt_ctf_scope root_scope, struct resolve_context *ctx)
 {
        int ret;
 
        assert(type_stack_size(ctx->type_stack) == 0);
-       ctx->root_node = root_node;
-       ret = resolve_type(get_type_from_ctx(ctx, root_node), ctx);
-       ctx->root_node = CTF_NODE_UNKNOWN;
+       ctx->root_scope = root_scope;
+       ret = resolve_type(get_type_from_ctx(ctx, root_scope), ctx);
+       ctx->root_scope = BT_CTF_SCOPE_UNKNOWN;
 
        return ret;
 }
@@ -1121,7 +1121,7 @@ int bt_ctf_resolve_types(
                        event_context_type,
                        event_payload_type,
                },
-               .root_node = CTF_NODE_UNKNOWN,
+               .root_scope = BT_CTF_SCOPE_UNKNOWN,
        };
 
        /* Initialize type stack */
@@ -1134,7 +1134,7 @@ int bt_ctf_resolve_types(
 
        /* Resolve packet header type */
        if (flags & BT_CTF_RESOLVE_FLAG_PACKET_HEADER) {
-               ret = resolve_root_type(CTF_NODE_TRACE_PACKET_HEADER, &ctx);
+               ret = resolve_root_type(BT_CTF_SCOPE_TRACE_PACKET_HEADER, &ctx);
                if (ret) {
                        _printf_error("Cannot resolve trace packet header type\n");
                        goto end;
@@ -1143,7 +1143,7 @@ int bt_ctf_resolve_types(
 
        /* Resolve packet context type */
        if (flags & BT_CTF_RESOLVE_FLAG_PACKET_CONTEXT) {
-               ret = resolve_root_type(CTF_NODE_STREAM_PACKET_CONTEXT, &ctx);
+               ret = resolve_root_type(BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, &ctx);
                if (ret) {
                        _printf_error("Cannot resolve stream packet context type\n");
                        goto end;
@@ -1152,8 +1152,7 @@ int bt_ctf_resolve_types(
 
        /* Resolve event header type */
        if (flags & BT_CTF_RESOLVE_FLAG_EVENT_HEADER) {
-               ret = resolve_root_type(CTF_NODE_STREAM_EVENT_HEADER, &ctx);
-
+               ret = resolve_root_type(BT_CTF_SCOPE_STREAM_EVENT_HEADER, &ctx);
                if (ret) {
                        _printf_error("Cannot resolve stream event header type\n");
                        goto end;
@@ -1162,7 +1161,7 @@ int bt_ctf_resolve_types(
 
        /* Resolve stream event context type */
        if (flags & BT_CTF_RESOLVE_FLAG_STREAM_EVENT_CTX) {
-               ret = resolve_root_type(CTF_NODE_STREAM_EVENT_CONTEXT, &ctx);
+               ret = resolve_root_type(BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, &ctx);
                if (ret) {
                        _printf_error("Cannot resolve stream event context type\n");
                        goto end;
@@ -1171,7 +1170,7 @@ int bt_ctf_resolve_types(
 
        /* Resolve event context type */
        if (flags & BT_CTF_RESOLVE_FLAG_EVENT_CONTEXT) {
-               ret = resolve_root_type(CTF_NODE_EVENT_CONTEXT, &ctx);
+               ret = resolve_root_type(BT_CTF_SCOPE_EVENT_CONTEXT, &ctx);
                if (ret) {
                        _printf_error("Cannot resolve event context type\n");
                        goto end;
@@ -1180,7 +1179,7 @@ int bt_ctf_resolve_types(
 
        /* Resolve event payload type */
        if (flags & BT_CTF_RESOLVE_FLAG_EVENT_PAYLOAD) {
-               ret = resolve_root_type(CTF_NODE_EVENT_FIELDS, &ctx);
+               ret = resolve_root_type(BT_CTF_SCOPE_EVENT_FIELDS, &ctx);
                if (ret) {
                        _printf_error("Cannot resolve event payload type\n");
                        goto end;
This page took 0.032521 seconds and 4 git commands to generate.