lang: ast: replace ast node print callback with to_string
This commit is contained in:
@@ -192,27 +192,19 @@ struct ivy_ast_node *ast_node_create(enum ivy_ast_node_type type)
|
||||
return node;
|
||||
}
|
||||
|
||||
static enum ivy_status node_print(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *it)
|
||||
|
||||
void ivy_ast_node_to_string(struct ivy_ast_node *node, struct b_string *out)
|
||||
{
|
||||
for (unsigned int i = 0; i < node->n_it.it_depth; i++) {
|
||||
fputs(" ", stdout);
|
||||
const struct ast_node_type *type_info = get_ast_node_type(node->n_type);
|
||||
if (!type_info) {
|
||||
return;
|
||||
}
|
||||
|
||||
const struct ast_node_type *type = get_ast_node_type(node->n_type);
|
||||
if (type && type->n_print) {
|
||||
type->n_print(node);
|
||||
if (type_info->n_to_string) {
|
||||
type_info->n_to_string(node, out);
|
||||
} else {
|
||||
printf("%s\n", ivy_ast_node_type_to_string(node->n_type));
|
||||
b_string_append_cstr(out, ivy_ast_node_type_to_string(node->n_type));
|
||||
}
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
void ivy_ast_node_print(struct ivy_ast_node *node)
|
||||
{
|
||||
struct ivy_ast_node_iterator it = {0};
|
||||
ivy_ast_node_iterate(node, &it, node_print);
|
||||
}
|
||||
|
||||
void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||
|
||||
Reference in New Issue
Block a user