Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / ast.h
index 6f6fbe7b9f8c2520d2fb01374300030629a6c8e7..afab4093ae2612ca5005090003a7f354e95f788d 100644 (file)
@@ -1,28 +1,19 @@
-#ifndef _CTF_AST_H
-#define _CTF_AST_H
-
 /*
- * ctf-ast.h
+ * SPDX-License-Identifier: MIT
  *
- * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * Copyright 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  */
 
+#ifndef _CTF_AST_H
+#define _CTF_AST_H
+
 #include <stdint.h>
 #include <stdio.h>
 #include <glib.h>
 #include "common/list.h"
 #include <babeltrace2/babeltrace.h>
-#include "common/babeltrace.h"
+#include "common/macros.h"
+#include "common/assert.h"
 
 #include "decoder.h"
 #include "ctf-meta.h"
@@ -316,9 +307,10 @@ struct ctf_ast {
 
 const char *node_type(struct ctf_node *node);
 
+struct meta_log_config;
+
 BT_HIDDEN
 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
-               bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *config);
 
 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor);
@@ -336,9 +328,101 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                struct ctf_node *node);
 
 BT_HIDDEN
-int ctf_visitor_semantic_check(int depth, struct ctf_node *node);
+int ctf_visitor_semantic_check(int depth, struct ctf_node *node,
+               struct meta_log_config *log_cfg);
 
 BT_HIDDEN
-int ctf_visitor_parent_links(int depth, struct ctf_node *node);
+int ctf_visitor_parent_links(int depth, struct ctf_node *node,
+               struct meta_log_config *log_cfg);
+
+static inline
+char *ctf_ast_concatenate_unary_strings(struct bt_list_head *head)
+{
+       int i = 0;
+       GString *str;
+       struct ctf_node *node;
+
+       str = g_string_new(NULL);
+       BT_ASSERT(str);
+
+       bt_list_for_each_entry(node, head, siblings) {
+               char *src_string;
+
+               if (
+                       node->type != NODE_UNARY_EXPRESSION ||
+                       node->u.unary_expression.type != UNARY_STRING ||
+                       !(
+                               (
+                                       node->u.unary_expression.link !=
+                                       UNARY_LINK_UNKNOWN
+                               ) ^ (i == 0)
+                       )
+               ) {
+                       goto error;
+               }
+
+               switch (node->u.unary_expression.link) {
+               case UNARY_DOTLINK:
+                       g_string_append(str, ".");
+                       break;
+               case UNARY_ARROWLINK:
+                       g_string_append(str, "->");
+                       break;
+               case UNARY_DOTDOTDOT:
+                       g_string_append(str, "...");
+                       break;
+               default:
+                       break;
+               }
+
+               src_string = node->u.unary_expression.u.string;
+               g_string_append(str, src_string);
+               i++;
+       }
+
+       /* Destroys the container, returns the underlying string */
+       return g_string_free(str, FALSE);
+
+error:
+       /* This always returns NULL */
+       return g_string_free(str, TRUE);
+}
+
+static inline
+int ctf_ast_get_unary_uuid(struct bt_list_head *head,
+               bt_uuid_t uuid, int log_level, bt_self_component *self_comp)
+{
+       int i = 0;
+       int ret = 0;
+       struct ctf_node *node;
+
+       bt_list_for_each_entry(node, head, siblings) {
+               int uexpr_type = node->u.unary_expression.type;
+               int uexpr_link = node->u.unary_expression.link;
+               const char *src_string;
+
+               if (node->type != NODE_UNARY_EXPRESSION ||
+                               uexpr_type != UNARY_STRING ||
+                               uexpr_link != UNARY_LINK_UNKNOWN ||
+                               i != 0) {
+                       ret = -EINVAL;
+                       goto end;
+               }
+
+               src_string = node->u.unary_expression.u.string;
+               ret = bt_uuid_from_str(src_string, uuid);
+               if (ret) {
+#ifdef BT_COMP_LOG_CUR_LVL
+                       BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level,
+                               self_comp,
+                               "Cannot parse UUID: uuid=\"%s\"", src_string);
+#endif
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
 
 #endif /* _CTF_AST_H */
This page took 0.024501 seconds and 4 git commands to generate.