* Common Trace Format metadata visitor (generates CTF IR objects).
*/
+#include <string>
+
+#include <errno.h>
+#include <glib.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <babeltrace2/babeltrace.h>
+
#define BT_COMP_LOG_SELF_COMP (ctx->log_cfg.self_comp)
#define BT_COMP_LOG_SELF_COMP_CLASS (ctx->log_cfg.self_comp_class)
#define BT_LOG_OUTPUT_LEVEL (ctx->log_cfg.log_level)
#define BT_LOG_TAG "PLUGIN/CTF/META/IR-VISITOR"
+#include "logging.hpp"
#include "logging/comp-logging.h"
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <ctype.h>
#include "common/assert.h"
-#include <glib.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <string>
#include "common/common.h"
#include "common/uuid.h"
-#include "compat/endian.h"
-#include <babeltrace2/babeltrace.h>
+#include "compat/endian.h" /* IWYU pragma: keep */
-#include "logging.hpp"
-#include "scanner.hpp"
#include "ast.hpp"
-#include "decoder.hpp"
-#include "ctf-meta.hpp"
#include "ctf-meta-visitors.hpp"
+#include "ctf-meta.hpp"
+#include "decoder.hpp"
/* Bit value (left shift) */
#define _BV(_val) (1 << (_val))
* @param name Name
* @returns Associated GQuark, or 0 on error
*/
-static GQuark get_prefixed_named_quark(struct ctf_visitor_generate_ir *ctx, char prefix,
- const char *name)
+static GQuark get_prefixed_named_quark(char prefix, const char *name)
{
BT_ASSERT(name);
std::string prname = std::string {prefix} + name;
* @returns Declaration (owned by caller if \p copy is true),
* or NULL if not found
*/
-static struct ctf_field_class *
-ctx_decl_scope_lookup_prefix_alias(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope, char prefix, const char *name,
- int levels, bool copy)
+static struct ctf_field_class *ctx_decl_scope_lookup_prefix_alias(struct ctx_decl_scope *scope,
+ char prefix, const char *name,
+ int levels, bool copy)
{
GQuark qname = 0;
int cur_levels = 0;
BT_ASSERT(scope);
BT_ASSERT(name);
- qname = get_prefixed_named_quark(ctx, prefix, name);
+ qname = get_prefixed_named_quark(prefix, name);
if (!qname) {
goto end;
}
* @returns Declaration (owned by caller if \p copy is true),
* or NULL if not found
*/
-static struct ctf_field_class *ctx_decl_scope_lookup_alias(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope,
+static struct ctf_field_class *ctx_decl_scope_lookup_alias(struct ctx_decl_scope *scope,
const char *name, int levels, bool copy)
{
- return ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_ALIAS, name, levels, copy);
+ return ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ALIAS, name, levels, copy);
}
/**
* @returns Declaration (owned by caller if \p copy is true),
* or NULL if not found
*/
-static struct ctf_field_class_enum *ctx_decl_scope_lookup_enum(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope,
- const char *name, int levels,
- bool copy)
+static struct ctf_field_class_enum *
+ctx_decl_scope_lookup_enum(struct ctx_decl_scope *scope, const char *name, int levels, bool copy)
{
return ctf_field_class_as_enum(
- ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_ENUM, name, levels, copy));
+ ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_ENUM, name, levels, copy));
}
/**
* or NULL if not found
*/
static struct ctf_field_class_struct *
-ctx_decl_scope_lookup_struct(struct ctf_visitor_generate_ir *ctx, struct ctx_decl_scope *scope,
- const char *name, int levels, bool copy)
+ctx_decl_scope_lookup_struct(struct ctx_decl_scope *scope, const char *name, int levels, bool copy)
{
return ctf_field_class_as_struct(
- ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_STRUCT, name, levels, copy));
+ ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_STRUCT, name, levels, copy));
}
/**
* or NULL if not found
*/
static struct ctf_field_class_variant *
-ctx_decl_scope_lookup_variant(struct ctf_visitor_generate_ir *ctx, struct ctx_decl_scope *scope,
- const char *name, int levels, bool copy)
+ctx_decl_scope_lookup_variant(struct ctx_decl_scope *scope, const char *name, int levels, bool copy)
{
return ctf_field_class_as_variant(
- ctx_decl_scope_lookup_prefix_alias(ctx, scope, _PREFIX_VARIANT, name, levels, copy));
+ ctx_decl_scope_lookup_prefix_alias(scope, _PREFIX_VARIANT, name, levels, copy));
}
/**
* @param decl Field class to register (copied)
* @returns 0 if registration went okay, negative value otherwise
*/
-static int ctx_decl_scope_register_prefix_alias(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope, char prefix,
+static int ctx_decl_scope_register_prefix_alias(struct ctx_decl_scope *scope, char prefix,
const char *name, struct ctf_field_class *decl)
{
int ret = 0;
BT_ASSERT(scope);
BT_ASSERT(name);
BT_ASSERT(decl);
- qname = get_prefixed_named_quark(ctx, prefix, name);
+ qname = get_prefixed_named_quark(prefix, name);
if (!qname) {
ret = -ENOMEM;
goto end;
}
/* Make sure alias does not exist in local scope */
- if (ctx_decl_scope_lookup_prefix_alias(ctx, scope, prefix, name, 1, false)) {
+ if (ctx_decl_scope_lookup_prefix_alias(scope, prefix, name, 1, false)) {
ret = -EEXIST;
goto end;
}
* @param decl Field class to register (copied)
* @returns 0 if registration went okay, negative value otherwise
*/
-static int ctx_decl_scope_register_alias(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope, const char *name,
+static int ctx_decl_scope_register_alias(struct ctx_decl_scope *scope, const char *name,
struct ctf_field_class *decl)
{
- return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_ALIAS, name, decl);
+ return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ALIAS, name, decl);
}
/**
* @param decl Enumeration field class to register (copied)
* @returns 0 if registration went okay, negative value otherwise
*/
-static int ctx_decl_scope_register_enum(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope, const char *name,
+static int ctx_decl_scope_register_enum(struct ctx_decl_scope *scope, const char *name,
struct ctf_field_class_enum *decl)
{
- return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_ENUM, name,
- &decl->base.base.base);
+ return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_ENUM, name, &decl->base.base.base);
}
/**
* @param decl Structure field class to register (copied)
* @returns 0 if registration went okay, negative value otherwise
*/
-static int ctx_decl_scope_register_struct(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope, const char *name,
+static int ctx_decl_scope_register_struct(struct ctx_decl_scope *scope, const char *name,
struct ctf_field_class_struct *decl)
{
- return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_STRUCT, name, &decl->base);
+ return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_STRUCT, name, &decl->base);
}
/**
* @param decl Variant field class to register
* @returns 0 if registration went okay, negative value otherwise
*/
-static int ctx_decl_scope_register_variant(struct ctf_visitor_generate_ir *ctx,
- struct ctx_decl_scope *scope, const char *name,
+static int ctx_decl_scope_register_variant(struct ctx_decl_scope *scope, const char *name,
struct ctf_field_class_variant *decl)
{
- return ctx_decl_scope_register_prefix_alias(ctx, scope, _PREFIX_VARIANT, name, &decl->base);
+ return ctx_decl_scope_register_prefix_alias(scope, _PREFIX_VARIANT, name, &decl->base);
}
/**
*/
qalias =
create_class_alias_identifier(ctx, cls_specifier_list, node_field_class_declarator);
- nested_decl = ctx_decl_scope_lookup_alias(ctx, ctx->current_scope,
- g_quark_to_string(qalias), -1, true);
+ nested_decl = ctx_decl_scope_lookup_alias(ctx->current_scope, g_quark_to_string(qalias),
+ -1, true);
if (!nested_decl) {
_BT_COMP_LOGE_APPEND_CAUSE_NODE(node_field_class_declarator,
"Cannot find class alias: name=\"%s\"",
}
}
- ret = ctx_decl_scope_register_alias(ctx, ctx->current_scope, g_quark_to_string(qidentifier),
+ ret = ctx_decl_scope_register_alias(ctx->current_scope, g_quark_to_string(qidentifier),
class_decl);
if (ret) {
_BT_COMP_LOGE_APPEND_CAUSE_NODE(iter, "Cannot register field class alias: name=\"%s\"",
struct ctf_node, siblings);
qalias = create_class_alias_identifier(
ctx, alias->u.field_class_alias_name.field_class_specifier_list, node);
- ret = ctx_decl_scope_register_alias(ctx, ctx->current_scope, g_quark_to_string(qalias),
- class_decl);
+ ret = ctx_decl_scope_register_alias(ctx->current_scope, g_quark_to_string(qalias), class_decl);
if (ret) {
_BT_COMP_LOGE_APPEND_CAUSE_NODE(node, "Cannot register class alias: name=\"%s\"",
g_quark_to_string(qalias));
goto error;
}
- *struct_decl = ctx_decl_scope_lookup_struct(ctx, ctx->current_scope, name, -1, true);
+ *struct_decl = ctx_decl_scope_lookup_struct(ctx->current_scope, name, -1, true);
if (!*struct_decl) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Cannot find structure field class: name=\"struct %s\"", name);
uint64_t min_align_value = 0;
if (name) {
- if (ctx_decl_scope_lookup_struct(ctx, ctx->current_scope, name, 1, false)) {
+ if (ctx_decl_scope_lookup_struct(ctx->current_scope, name, 1, false)) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Structure field class already declared in local scope: "
"name=\"struct %s\"",
ctx_pop_scope(ctx);
if (name) {
- ret = ctx_decl_scope_register_struct(ctx, ctx->current_scope, name, *struct_decl);
+ ret = ctx_decl_scope_register_struct(ctx->current_scope, name, *struct_decl);
if (ret) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Cannot register structure field class in declaration scope: "
goto error;
}
- untagged_variant_decl =
- ctx_decl_scope_lookup_variant(ctx, ctx->current_scope, name, -1, true);
+ untagged_variant_decl = ctx_decl_scope_lookup_variant(ctx->current_scope, name, -1, true);
if (!untagged_variant_decl) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Cannot find variant field class: name=\"variant %s\"", name);
struct ctf_node *entry_node;
if (name) {
- if (ctx_decl_scope_lookup_variant(ctx, ctx->current_scope, name, 1, false)) {
+ if (ctx_decl_scope_lookup_variant(ctx->current_scope, name, 1, false)) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Variant field class already declared in local scope: "
"name=\"variant %s\"",
ctx_pop_scope(ctx);
if (name) {
- ret = ctx_decl_scope_register_variant(ctx, ctx->current_scope, name,
- untagged_variant_decl);
+ ret = ctx_decl_scope_register_variant(ctx->current_scope, name, untagged_variant_decl);
if (ret) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Cannot register variant field class in declaration scope: "
goto error;
}
- *enum_decl = ctx_decl_scope_lookup_enum(ctx, ctx->current_scope, name, -1, true);
+ *enum_decl = ctx_decl_scope_lookup_enum(ctx->current_scope, name, -1, true);
if (!*enum_decl) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot find enumeration field class: "
"name=\"enum %s\"",
};
if (name) {
- if (ctx_decl_scope_lookup_enum(ctx, ctx->current_scope, name, 1, false)) {
+ if (ctx_decl_scope_lookup_enum(ctx->current_scope, name, 1, false)) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Enumeration field class already declared in local scope: "
"name=\"enum %s\"",
if (!container_cls) {
integer_decl = ctf_field_class_as_int(
- ctx_decl_scope_lookup_alias(ctx, ctx->current_scope, "int", -1, true));
+ ctx_decl_scope_lookup_alias(ctx->current_scope, "int", -1, true));
if (!integer_decl) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Cannot find implicit `int` field class alias for enumeration field class.");
}
if (name) {
- ret = ctx_decl_scope_register_enum(ctx, ctx->current_scope, name, *enum_decl);
+ ret = ctx_decl_scope_register_enum(ctx->current_scope, name, *enum_decl);
if (ret) {
_BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
"Cannot register enumeration field class in declaration scope: "
goto error;
}
- *decl = ctx_decl_scope_lookup_alias(ctx, ctx->current_scope, str->str, -1, true);
+ *decl = ctx_decl_scope_lookup_alias(ctx->current_scope, str->str, -1, true);
if (!*decl) {
_BT_COMP_LOGE_APPEND_CAUSE_NODE(cls_specifier_list,
"Cannot find field class alias: name=\"%s\"", str->str);