36 lines
889 B
C
36 lines
889 B
C
#include "ctx.h"
|
|
#include "iterate.h"
|
|
#include "node.h"
|
|
|
|
#include <blue/ds/string.h>
|
|
|
|
static void to_string(struct ivy_ast_node *node, b_string *str)
|
|
{
|
|
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)node;
|
|
|
|
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));
|
|
}
|
|
|
|
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 = {
|
|
.n_to_string = to_string,
|
|
.n_collect_children = collect_children,
|
|
.n_state_size = sizeof(struct parser_state),
|
|
.n_node_size = sizeof(struct ivy_ast_op_node),
|
|
};
|