lang: ast: replace ast node print callback with to_string

This commit is contained in:
2024-12-06 20:24:08 +00:00
parent ae15f228d3
commit bd5e524241
14 changed files with 72 additions and 73 deletions

View File

@@ -1,13 +1,13 @@
#include "ctx.h"
#include "node.h"
#include "iterate.h"
#include <stdio.h>
#include <blue/object/string.h>
static void print(struct ivy_ast_node *node)
static void to_string(struct ivy_ast_node *node, b_string *str)
{
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)node;
printf("%s (%s)\n", ivy_ast_node_type_to_string(node->n_type), ivy_operator_id_to_string(op->n_op->op_id));
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(
@@ -25,7 +25,7 @@ static void collect_children(
}
struct ast_node_type op_node_ops = {
.n_print = print,
.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),