lang: ast: fix selector, unit-package, and unit-import string conversion
stringifying selectors with unnamed args no longer causes a segfault, and unit-package and unit-import node strings are now formatted correctly.
This commit is contained in:
@@ -269,7 +269,7 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
|||||||
label = b_unbox(struct ivy_token, label_it.entry, t_entry);
|
label = b_unbox(struct ivy_token, label_it.entry, t_entry);
|
||||||
name = b_unbox(struct ivy_token, name_it.entry, t_entry);
|
name = b_unbox(struct ivy_token, name_it.entry, t_entry);
|
||||||
|
|
||||||
if (label && label->t_type == IVY_TOK_LABEL) {
|
if (label && label->t_type == IVY_TOK_LABEL && label->t_str) {
|
||||||
b_string_append_cstrf(str, "%s:", label->t_str);
|
b_string_append_cstrf(str, "%s:", label->t_str);
|
||||||
} else {
|
} else {
|
||||||
b_string_append_cstrf(str, "_:");
|
b_string_append_cstrf(str, "_:");
|
||||||
|
|||||||
@@ -64,16 +64,21 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
|||||||
|
|
||||||
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||||
|
|
||||||
|
b_string_append_cstr(str, " (");
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
b_queue_iterator it = {0};
|
b_queue_iterator it = {0};
|
||||||
b_queue_foreach (&it, &unit_import->n_ident) {
|
b_queue_foreach (&it, &unit_import->n_ident) {
|
||||||
struct ivy_token *tok
|
struct ivy_token *tok
|
||||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||||
|
|
||||||
if (b_string_get_size(str, B_STRLEN_NORMAL) > 0) {
|
if (i > 0) {
|
||||||
b_string_append_cstr(str, ".");
|
b_string_append_cstr(str, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
b_string_append_cstr(str, tok->t_str);
|
b_string_append_cstr(str, tok->t_str);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_string_append_cstr(str, ")");
|
b_string_append_cstr(str, ")");
|
||||||
|
|||||||
@@ -63,16 +63,20 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
|||||||
= (struct ivy_ast_unit_package_node *)node;
|
= (struct ivy_ast_unit_package_node *)node;
|
||||||
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||||
|
|
||||||
|
b_string_append_cstr(str, " (");
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
b_queue_iterator it = {0};
|
b_queue_iterator it = {0};
|
||||||
b_queue_foreach (&it, &unit_package->n_ident) {
|
b_queue_foreach (&it, &unit_package->n_ident) {
|
||||||
struct ivy_token *tok
|
struct ivy_token *tok
|
||||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||||
|
|
||||||
if (b_string_get_size(str, B_STRLEN_NORMAL) > 0) {
|
if (i > 0) {
|
||||||
b_string_append_cstr(str, ".");
|
b_string_append_cstr(str, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
b_string_append_cstr(str, tok->t_str);
|
b_string_append_cstr(str, tok->t_str);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_string_append_cstr(str, ")");
|
b_string_append_cstr(str, ")");
|
||||||
|
|||||||
Reference in New Issue
Block a user