`ctf` plugin: Use CTF_BYTE_ORDER_UNKNOWN in place of -1
[babeltrace.git] / src / plugins / ctf / common / metadata / visitor-generate-ir.c
index 5b64ad28c953c90fbd91fdcc32f5fc5e3968ca28..0799ba19d2e5dedad760d31dba2cd61fc7853331 100644 (file)
@@ -30,7 +30,7 @@
 #define BT_COMP_LOG_SELF_COMP (ctx->log_cfg.self_comp)
 #define BT_LOG_OUTPUT_LEVEL (ctx->log_cfg.log_level)
 #define BT_LOG_TAG "PLUGIN/CTF/META/IR-VISITOR"
-#include "plugins/comp-logging.h"
+#include "logging/comp-logging.h"
 
 #include <stdio.h>
 #include <unistd.h>
@@ -679,61 +679,6 @@ static
 int visit_field_class_specifier_list(struct ctx *ctx, struct ctf_node *ts_list,
                struct ctf_field_class **decl);
 
-static
-char *remove_underscores_from_field_ref(struct ctx *ctx, 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_COMP_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)
 {
@@ -1064,7 +1009,7 @@ enum ctf_byte_order byte_order_from_unary_expr(struct ctx *ctx,
                struct ctf_node *unary_expr)
 {
        const char *str;
-       enum ctf_byte_order bo = -1;
+       enum ctf_byte_order bo = CTF_BYTE_ORDER_UNKNOWN;
 
        if (unary_expr->u.unary_expression.type != UNARY_STRING) {
                _BT_COMP_LOGE_NODE(unary_expr,
@@ -1385,10 +1330,6 @@ int visit_field_class_declarator(struct ctx *ctx,
                        const char *id =
                                node_field_class_declarator->u.field_class_declarator.u.id;
 
-                       if (id[0] == '_') {
-                               id++;
-                       }
-
                        *field_name = g_quark_from_string(id);
                } else {
                        *field_name = 0;
@@ -1493,24 +1434,12 @@ int visit_field_class_declarator(struct ctx *ctx,
                                nested_decl = NULL;
                                decl = (void *) array_decl;
                        } else {
-                               char *length_name_no_underscore =
-                                       remove_underscores_from_field_ref(ctx,
-                                               length_name);
-                               if (!length_name_no_underscore) {
-                                       /*
-                                        * remove_underscores_from_field_ref()
-                                        * logs errors
-                                        */
-                                       ret = -EINVAL;
-                                       goto error;
-                               }
                                seq_decl = ctf_field_class_sequence_create();
                                BT_ASSERT(seq_decl);
                                seq_decl->base.elem_fc = nested_decl;
                                nested_decl = NULL;
                                g_string_assign(seq_decl->length_ref,
-                                       length_name_no_underscore);
-                               free(length_name_no_underscore);
+                                       length_name);
                                decl = (void *) seq_decl;
                        }
 
@@ -2067,17 +1996,7 @@ 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.
                 */
-               char *tag_no_underscore =
-                       remove_underscores_from_field_ref(ctx, tag);
-
-               if (!tag_no_underscore) {
-                       /* remove_underscores_from_field_ref() logs errors */
-                       goto error;
-               }
-
-               g_string_assign(untagged_variant_decl->tag_ref,
-                       tag_no_underscore);
-               free(tag_no_underscore);
+               g_string_assign(untagged_variant_decl->tag_ref, tag);
                *variant_decl = untagged_variant_decl;
                untagged_variant_decl = NULL;
        }
@@ -2118,7 +2037,6 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator,
                .value.u = 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) {
@@ -2185,19 +2103,7 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator,
                last->value.u = end.value.u + 1;
        }
 
-       if (label[0] == '_') {
-               /*
-                * Strip the first underscore of any enumeration field
-                * class's label in case this enumeration FC is used as
-                * a variant FC tag later. The variant FC 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];
-       }
-
-       ctf_field_class_enum_append_mapping(enum_decl, effective_label,
+       ctf_field_class_enum_map_range(enum_decl, label,
                start.value.u, end.value.u);
        return 0;
 
@@ -2423,7 +2329,7 @@ int visit_integer_decl(struct ctx *ctx,
                        }
 
                        byte_order = get_real_byte_order(ctx, right);
-                       if (byte_order == -1) {
+                       if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
                                _BT_COMP_LOGE_NODE(right,
                                        "Invalid `byte_order` attribute in integer field class: "
                                        "ret=%d", ret);
@@ -2770,7 +2676,7 @@ int visit_floating_point_number_decl(struct ctx *ctx,
                        }
 
                        byte_order = get_real_byte_order(ctx, right);
-                       if (byte_order == -1) {
+                       if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
                                _BT_COMP_LOGE_NODE(right,
                                        "Invalid `byte_order` attribute in floating point number field class: "
                                        "ret=%d", ret);
@@ -3267,6 +3173,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        _SET(set, _EVENT_FIELDS_SET);
                } else if (strcmp(left, "loglevel") == 0) {
                        uint64_t loglevel_value;
+                       bool is_log_level_known = true;
                        bt_event_class_log_level log_level = -1;
 
                        if (_IS_SET(set, _EVENT_LOG_LEVEL_SET)) {
@@ -3332,12 +3239,13 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                                log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG;
                                break;
                        default:
+                               is_log_level_known = false;
                                _BT_COMP_LOGW_NODE(node, "Not setting event class's log level because its value is unknown: "
                                        "log-level=%" PRIu64, loglevel_value);
                        }
 
-                       if (log_level != -1) {
-                               event_class->log_level = log_level;
+                       if (is_log_level_known) {
+                               ctf_event_class_set_log_level(event_class, log_level);
                        }
 
                        _SET(set, _EVENT_LOG_LEVEL_SET);
@@ -4078,7 +3986,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set)
                                goto error;
                        }
 
-                       BT_ASSERT(ctx->ctf_tc->default_byte_order != -1);
+                       BT_ASSERT(ctx->ctf_tc->default_byte_order != CTF_BYTE_ORDER_UNKNOWN);
                        _SET(set, _TRACE_BYTE_ORDER_SET);
                } else if (strcmp(left, "packet.header") == 0) {
                        if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) {
@@ -4324,7 +4232,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node)
                                        struct ctf_node, siblings);
                                bo = byte_order_from_unary_expr(ctx,
                                        right_node);
-                               if (bo == -1) {
+                               if (bo == CTF_BYTE_ORDER_UNKNOWN) {
                                        _BT_COMP_LOGE_NODE(node,
                                                "Invalid `byte_order` attribute in trace (`trace` block): "
                                                "expecting `le`, `be`, or `network`.");
@@ -4874,7 +4782,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->ctf_tc->default_byte_order == -1) {
+               if (ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_UNKNOWN) {
                        bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                                if (got_trace_decl) {
                                        _BT_COMP_LOGE_NODE(node,
@@ -4904,7 +4812,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                BT_ASSERT(ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_LITTLE ||
                        ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_BIG);
                BT_ASSERT(ctx->current_scope &&
-                               ctx->current_scope->parent_scope == NULL);
+                               !ctx->current_scope->parent_scope);
 
                /* Environment */
                bt_list_for_each_entry(iter, &node->u.root.env, siblings) {
@@ -4918,7 +4826,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
 
                /*
                 * Visit clock blocks.
@@ -4934,7 +4842,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
 
                /*
                 * Visit root declarations next, as they can be used by any
@@ -4952,7 +4860,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
 
                /* Callsite blocks are not supported */
                bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
@@ -4961,7 +4869,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
 
                /* Trace */
                bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
@@ -4975,7 +4883,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
 
                /* Streams */
                bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
@@ -4989,7 +4897,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
 
                /* Events */
                bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
@@ -5003,7 +4911,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                }
 
                BT_ASSERT(ctx->current_scope &&
-                       ctx->current_scope->parent_scope == NULL);
+                       !ctx->current_scope->parent_scope);
                break;
        }
        default:
This page took 0.028333 seconds and 4 git commands to generate.