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

@@ -349,29 +349,29 @@ static void collect_children(
}
}
static void print(struct ivy_ast_node *node)
static void to_string(struct ivy_ast_node *node, b_string *str)
{
struct ivy_ast_property_node *prop = (struct ivy_ast_property_node *)node;
printf("%s (%s) [", ivy_ast_node_type_to_string(node->n_type), prop->n_ident->t_str);
b_string_append_cstrf(str, "%s (%s) [", ivy_ast_node_type_to_string(node->n_type), prop->n_ident->t_str);
if (prop->n_flags & IVY_AST_PROPERTY_GET) {
puts("get");
b_string_append_cstr(str, "get");
}
if ((prop->n_flags & IVY_AST_PROPERTY_GET) && prop->n_flags & IVY_AST_PROPERTY_SET) {
puts(", ");
b_string_append_cstr(str, ", ");
}
if (prop->n_flags & IVY_AST_PROPERTY_SET) {
puts("set");
b_string_append_cstr(str, "set");
}
puts("]\n");
b_string_append_cstr(str, "]");
}
struct ast_node_type property_node_ops = {
.n_print = print,
.n_to_string = to_string,
.n_add_child = add_child,
.n_init_state = init_state,
.n_collect_children = collect_children,