X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmetadata%2Fast.h;h=afab4093ae2612ca5005090003a7f354e95f788d;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hp=6b305e53f4e85db3fd6ad42f8a8ce631bcc292e6;hpb=f7b785acaab5692fd58bb3b2db7da23fc307931b;p=babeltrace.git diff --git a/src/plugins/ctf/common/metadata/ast.h b/src/plugins/ctf/common/metadata/ast.h index 6b305e53..afab4093 100644 --- a/src/plugins/ctf/common/metadata/ast.h +++ b/src/plugins/ctf/common/metadata/ast.h @@ -1,28 +1,19 @@ -#ifndef _CTF_AST_H -#define _CTF_AST_H - /* - * ctf-ast.h + * SPDX-License-Identifier: MIT * - * Copyright 2011-2012 - Mathieu Desnoyers - * - * 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 */ +#ifndef _CTF_AST_H +#define _CTF_AST_H + #include #include #include #include "common/list.h" #include #include "common/macros.h" +#include "common/assert.h" #include "decoder.h" #include "ctf-meta.h" @@ -344,4 +335,94 @@ BT_HIDDEN 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 */