#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>
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,
};
/*
*/
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];
}
/*
* 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;
}
}
/* 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,
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;
/* 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 =
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;
/* 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);
}
end:
- bt_ctf_field_path_destroy(tail_field_path);
+ BT_PUT(tail_field_path);
return ret;
}
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;
}
/* 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);
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,
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;
}
/*
* 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;
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) {
{
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;
* 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) {
}
end:
- bt_ctf_field_path_destroy(ctx_field_path);
+ BT_PUT(ctx_field_path);
return ret;
}
_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);
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;
}
end:
- bt_ctf_field_path_destroy(target_field_path);
+ BT_PUT(target_field_path);
BT_PUT(target_type);
return ret;
}
* 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 ctf_type_id 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;
}
event_context_type,
event_payload_type,
},
- .root_node = CTF_NODE_UNKNOWN,
+ .root_scope = BT_CTF_SCOPE_UNKNOWN,
};
/* Initialize type stack */
/* 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;
/* 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;
/* 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;
/* 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;
/* 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;
/* 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;