* SOFTWARE.
*/
+#define BT_LOG_TAG "PLUGIN-CTF-METADATA-PARENT-LINKS-VISITOR"
+#include "logging.h"
+
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <babeltrace2/assert-internal.h>
#include <glib.h>
#include <inttypes.h>
#include <errno.h>
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/list.h>
+#include <babeltrace2/babeltrace-internal.h>
+#include <babeltrace2/list-internal.h>
#include "scanner.h"
#include "parser.h"
#include "ast.h"
-#define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
-
static
-int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
+int ctf_visitor_unary_expression(int depth, struct ctf_node *node)
{
int ret = 0;
case UNARY_DOTDOTDOT:
break;
default:
- fprintf(fd, "[error] %s: unknown expression link type %d\n", __func__,
- (int) node->u.unary_expression.link);
+ _BT_LOGE_LINENO(node->lineno,
+ "Unknown expression link type: type=%d\n",
+ node->u.unary_expression.link);
return -EINVAL;
}
break;
case UNARY_SBRAC:
node->u.unary_expression.u.sbrac_exp->parent = node;
- ret = ctf_visitor_unary_expression(fd, depth + 1,
+ ret = ctf_visitor_unary_expression(depth + 1,
node->u.unary_expression.u.sbrac_exp);
if (ret)
return ret;
case UNARY_UNKNOWN:
default:
- fprintf(fd, "[error] %s: unknown expression type %d\n", __func__,
- (int) node->u.unary_expression.type);
+ _BT_LOGE_LINENO(node->lineno,
+ "Unknown expression link type: type=%d\n",
+ node->u.unary_expression.link);
return -EINVAL;
}
return 0;
}
static
-int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
+int ctf_visitor_type_specifier(int depth, struct ctf_node *node)
{
int ret;
- switch (node->u.type_specifier.type) {
+ switch (node->u.field_class_specifier.type) {
case TYPESPEC_VOID:
case TYPESPEC_CHAR:
case TYPESPEC_SHORT:
case TYPESPEC_STRUCT:
case TYPESPEC_VARIANT:
case TYPESPEC_ENUM:
- node->u.type_specifier.node->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u.type_specifier.node);
+ node->u.field_class_specifier.node->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_specifier.node);
if (ret)
return ret;
break;
case TYPESPEC_UNKNOWN:
default:
- fprintf(fd, "[error] %s: unknown type specifier %d\n", __func__,
- (int) node->u.type_specifier.type);
+ _BT_LOGE_LINENO(node->lineno,
+ "Unknown type specifier: type=%d\n",
+ node->u.field_class_specifier.type);
return -EINVAL;
}
return 0;
}
static
-int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
+int ctf_visitor_field_class_declarator(int depth, struct ctf_node *node)
{
int ret = 0;
struct ctf_node *iter;
depth++;
- bt_list_for_each_entry(iter, &node->u.type_declarator.pointers,
+ bt_list_for_each_entry(iter, &node->u.field_class_declarator.pointers,
siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
- switch (node->u.type_declarator.type) {
+ switch (node->u.field_class_declarator.type) {
case TYPEDEC_ID:
break;
case TYPEDEC_NESTED:
- if (node->u.type_declarator.u.nested.type_declarator) {
- node->u.type_declarator.u.nested.type_declarator->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1,
- node->u.type_declarator.u.nested.type_declarator);
+ if (node->u.field_class_declarator.u.nested.field_class_declarator) {
+ node->u.field_class_declarator.u.nested.field_class_declarator->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1,
+ node->u.field_class_declarator.u.nested.field_class_declarator);
if (ret)
return ret;
}
- if (!node->u.type_declarator.u.nested.abstract_array) {
- bt_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
+ if (!node->u.field_class_declarator.u.nested.abstract_array) {
+ bt_list_for_each_entry(iter, &node->u.field_class_declarator.u.nested.length,
siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
}
- if (node->u.type_declarator.bitfield_len) {
- node->u.type_declarator.bitfield_len = node;
- ret = ctf_visitor_parent_links(fd, depth + 1,
- node->u.type_declarator.bitfield_len);
+ if (node->u.field_class_declarator.bitfield_len) {
+ node->u.field_class_declarator.bitfield_len = node;
+ ret = ctf_visitor_parent_links(depth + 1,
+ node->u.field_class_declarator.bitfield_len);
if (ret)
return ret;
}
break;
case TYPEDEC_UNKNOWN:
default:
- fprintf(fd, "[error] %s: unknown type declarator %d\n", __func__,
- (int) node->u.type_declarator.type);
+ _BT_LOGE_LINENO(node->lineno,
+ "Unknown type declarator: type=%d\n",
+ node->u.field_class_declarator.type);
return -EINVAL;
}
depth--;
return 0;
}
-int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
+int ctf_visitor_parent_links(int depth, struct ctf_node *node)
{
int ret = 0;
struct ctf_node *iter;
case NODE_ROOT:
bt_list_for_each_entry(iter, &node->u.root.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u.root.clock, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_EVENT:
bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_STREAM:
bt_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_ENV:
bt_list_for_each_entry(iter, &node->u.env.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_TRACE:
bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_CLOCK:
bt_list_for_each_entry(iter, &node->u.clock.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_CALLSITE:
bt_list_for_each_entry(iter, &node->u.callsite.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
depth++;
bt_list_for_each_entry(iter, &node->u.ctf_expression.left, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u.ctf_expression.right, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
depth--;
break;
case NODE_UNARY_EXPRESSION:
- return ctf_visitor_unary_expression(fd, depth, node);
+ return ctf_visitor_unary_expression(depth, node);
case NODE_TYPEDEF:
depth++;
- node->u._typedef.type_specifier_list->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u._typedef.type_specifier_list);
+ node->u.field_class_def.field_class_specifier_list->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_def.field_class_specifier_list);
if (ret)
return ret;
- bt_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
+ bt_list_for_each_entry(iter, &node->u.field_class_def.field_class_declarators, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
break;
case NODE_TYPEALIAS_TARGET:
depth++;
- node->u.typealias_target.type_specifier_list->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_target.type_specifier_list);
+ node->u.field_class_alias_target.field_class_specifier_list->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias_target.field_class_specifier_list);
if (ret)
return ret;
- bt_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
+ bt_list_for_each_entry(iter, &node->u.field_class_alias_target.field_class_declarators, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
break;
case NODE_TYPEALIAS_ALIAS:
depth++;
- node->u.typealias_alias.type_specifier_list->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_alias.type_specifier_list);
+ node->u.field_class_alias_name.field_class_specifier_list->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias_name.field_class_specifier_list);
if (ret)
return ret;
- bt_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
+ bt_list_for_each_entry(iter, &node->u.field_class_alias_name.field_class_declarators, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
depth--;
break;
case NODE_TYPEALIAS:
- node->u.typealias.target->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias.target);
+ node->u.field_class_alias.target->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias.target);
if (ret)
return ret;
- node->u.typealias.alias->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias.alias);
+ node->u.field_class_alias.alias->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1, node->u.field_class_alias.alias);
if (ret)
return ret;
break;
case NODE_TYPE_SPECIFIER_LIST:
- bt_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
+ bt_list_for_each_entry(iter, &node->u.field_class_specifier_list.head, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
break;
case NODE_TYPE_SPECIFIER:
- ret = ctf_visitor_type_specifier(fd, depth, node);
+ ret = ctf_visitor_type_specifier(depth, node);
if (ret)
return ret;
break;
case NODE_POINTER:
break;
case NODE_TYPE_DECLARATOR:
- ret = ctf_visitor_type_declarator(fd, depth, node);
+ ret = ctf_visitor_field_class_declarator(depth, node);
if (ret)
return ret;
break;
case NODE_FLOATING_POINT:
bt_list_for_each_entry(iter, &node->u.floating_point.expressions, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_INTEGER:
bt_list_for_each_entry(iter, &node->u.integer.expressions, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_STRING:
bt_list_for_each_entry(iter, &node->u.string.expressions, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_ENUMERATOR:
bt_list_for_each_entry(iter, &node->u.enumerator.values, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
break;
case NODE_ENUM:
depth++;
- if (node->u._enum.container_type) {
- ret = ctf_visitor_parent_links(fd, depth + 1, node->u._enum.container_type);
+ if (node->u._enum.container_field_class) {
+ ret = ctf_visitor_parent_links(depth + 1, node->u._enum.container_field_class);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
depth--;
break;
case NODE_STRUCT_OR_VARIANT_DECLARATION:
- node->u.struct_or_variant_declaration.type_specifier_list->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1,
- node->u.struct_or_variant_declaration.type_specifier_list);
+ node->u.struct_or_variant_declaration.field_class_specifier_list->parent = node;
+ ret = ctf_visitor_parent_links(depth + 1,
+ node->u.struct_or_variant_declaration.field_class_specifier_list);
if (ret)
return ret;
- bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
+ bt_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.field_class_declarators, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_VARIANT:
bt_list_for_each_entry(iter, &node->u.variant.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_STRUCT:
bt_list_for_each_entry(iter, &node->u._struct.declaration_list, siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
bt_list_for_each_entry(iter, &node->u._struct.min_align,
siblings) {
iter->parent = node;
- ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+ ret = ctf_visitor_parent_links(depth + 1, iter);
if (ret)
return ret;
}
case NODE_UNKNOWN:
default:
- fprintf(fd, "[error] %s: unknown node type %d\n", __func__,
- (int) node->type);
+ _BT_LOGE_LINENO(node->lineno,
+ "Unknown node type: type=%d\n", node->type);
return -EINVAL;
}
return ret;