2024-11-28 22:05:37 +00:00
|
|
|
#include "ctx.h"
|
|
|
|
|
#include "node.h"
|
|
|
|
|
#include "iterate.h"
|
2024-12-06 20:24:08 +00:00
|
|
|
#include <blue/object/string.h>
|
2024-11-28 22:05:37 +00:00
|
|
|
|
2024-12-06 20:24:08 +00:00
|
|
|
static void to_string(struct ivy_ast_node *node, b_string *str)
|
2024-11-28 22:05:37 +00:00
|
|
|
{
|
|
|
|
|
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)node;
|
|
|
|
|
|
2024-12-06 20:24:08 +00:00
|
|
|
b_string_append_cstrf(str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type), ivy_operator_id_to_string(op->n_op->op_id));
|
2024-11-28 22:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void collect_children(
|
|
|
|
|
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
|
|
|
|
{
|
|
|
|
|
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)node;
|
|
|
|
|
|
|
|
|
|
if (op->n_left) {
|
|
|
|
|
ast_node_iterator_enqueue_node(iterator, node, op->n_left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (op->n_right) {
|
|
|
|
|
ast_node_iterator_enqueue_node(iterator, node, op->n_right);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ast_node_type op_node_ops = {
|
2024-12-06 20:24:08 +00:00
|
|
|
.n_to_string = to_string,
|
2024-11-28 22:05:37 +00:00
|
|
|
.n_collect_children = collect_children,
|
2024-11-29 12:06:06 +00:00
|
|
|
.n_state_size = sizeof(struct parser_state),
|
|
|
|
|
.n_node_size = sizeof(struct ivy_ast_op_node),
|
2024-11-28 22:05:37 +00:00
|
|
|
};
|