2024-11-26 13:08:39 +00:00
|
|
|
#include "node.h"
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
#include <fx/ds/string.h>
|
2024-11-26 13:08:39 +00:00
|
|
|
#include <ivy/lang/lex.h>
|
2024-11-28 16:58:01 +00:00
|
|
|
#include <stdio.h>
|
2024-11-26 13:08:39 +00:00
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
2024-11-28 16:58:01 +00:00
|
|
|
{
|
|
|
|
|
struct ivy_ast_selector_node *sel = (struct ivy_ast_selector_node *)node;
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstrf(
|
2024-12-06 22:25:33 +00:00
|
|
|
str, "%s [", ivy_ast_node_type_to_string(node->n_type));
|
2024-11-28 16:58:01 +00:00
|
|
|
|
|
|
|
|
switch (sel->n_recipient) {
|
|
|
|
|
case IVY_SELECTOR_RECIPIENT_CLASS:
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstr(str, "+");
|
2024-11-28 16:58:01 +00:00
|
|
|
break;
|
|
|
|
|
case IVY_SELECTOR_RECIPIENT_OBJECT:
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstr(str, "-");
|
2024-11-28 16:58:01 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2024-11-28 22:06:25 +00:00
|
|
|
/* this will occur if the selector is being used to send a
|
|
|
|
|
message at runtime, rather than as part of a message
|
|
|
|
|
handler definition. */
|
2024-11-28 16:58:01 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sel->n_msg_name) {
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstr(str, sel->n_msg_name->t_str);
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
if (sel->n_msg_name && !fx_queue_empty(&sel->n_arg_labels)) {
|
|
|
|
|
fx_string_append_cstr(str, "(");
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_queue_entry *label_entry = fx_queue_first(&sel->n_arg_labels);
|
|
|
|
|
fx_queue_entry *name_entry = fx_queue_first(&sel->n_arg_names);
|
2024-11-28 16:58:01 +00:00
|
|
|
|
|
|
|
|
int i = 0;
|
2025-11-06 10:38:32 +00:00
|
|
|
while (label_entry) {
|
2024-11-28 16:58:01 +00:00
|
|
|
if (i > 0) {
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstr(str, " ");
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-06 22:25:33 +00:00
|
|
|
struct ivy_token *label, *name;
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
label = fx_unbox(struct ivy_token, label_entry, t_entry);
|
|
|
|
|
name = fx_unbox(struct ivy_token, name_entry, t_entry);
|
2024-12-06 22:25:33 +00:00
|
|
|
|
2025-04-23 10:58:22 +01:00
|
|
|
if (label && label->t_type == IVY_TOK_LABEL && label->t_str) {
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstrf(str, "%s:", label->t_str);
|
2024-12-07 10:07:20 +00:00
|
|
|
} else {
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstrf(str, "_:");
|
2024-12-06 22:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name) {
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstrf(str, "%s", name->t_str);
|
2024-12-06 22:25:33 +00:00
|
|
|
}
|
2024-11-28 16:58:01 +00:00
|
|
|
|
2024-12-06 22:25:33 +00:00
|
|
|
if (name) {
|
|
|
|
|
i++;
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
label_entry = fx_queue_next(label_entry);
|
|
|
|
|
name_entry = fx_queue_next(name_entry);
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
if (sel->n_msg_name && !fx_queue_empty(&sel->n_arg_labels)) {
|
|
|
|
|
fx_string_append_cstr(str, ")");
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 14:07:33 +00:00
|
|
|
fx_string_append_cstr(str, "]");
|
2024-11-28 16:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-26 21:30:40 +00:00
|
|
|
struct ast_node_type selector_node_ops = {
|
2024-12-06 20:24:08 +00:00
|
|
|
.n_to_string = to_string,
|
2026-04-06 18:25:43 +01:00
|
|
|
.n_node_size = sizeof(struct ivy_ast_selector_node),
|
2024-11-26 13:08:39 +00:00
|
|
|
};
|