79 lines
1.8 KiB
C
79 lines
1.8 KiB
C
#include "node.h"
|
|
|
|
#include <fx/ds/string.h>
|
|
#include <ivy/lang/lex.h>
|
|
#include <stdio.h>
|
|
|
|
static void to_string(struct ivy_ast_node *node, fx_string *str)
|
|
{
|
|
struct ivy_ast_selector_node *sel = (struct ivy_ast_selector_node *)node;
|
|
|
|
fx_string_append_cstrf(
|
|
str, "%s [", ivy_ast_node_type_to_string(node->n_type));
|
|
|
|
switch (sel->n_recipient) {
|
|
case IVY_SELECTOR_RECIPIENT_CLASS:
|
|
fx_string_append_cstr(str, "+");
|
|
break;
|
|
case IVY_SELECTOR_RECIPIENT_OBJECT:
|
|
fx_string_append_cstr(str, "-");
|
|
break;
|
|
default:
|
|
/* this will occur if the selector is being used to send a
|
|
message at runtime, rather than as part of a message
|
|
handler definition. */
|
|
break;
|
|
}
|
|
|
|
if (sel->n_msg_name) {
|
|
fx_string_append_cstr(str, sel->n_msg_name->t_str);
|
|
}
|
|
|
|
if (sel->n_msg_name && !fx_queue_empty(&sel->n_arg_labels)) {
|
|
fx_string_append_cstr(str, "(");
|
|
}
|
|
|
|
fx_queue_entry *label_entry = fx_queue_first(&sel->n_arg_labels);
|
|
fx_queue_entry *name_entry = fx_queue_first(&sel->n_arg_names);
|
|
|
|
int i = 0;
|
|
while (label_entry) {
|
|
if (i > 0) {
|
|
fx_string_append_cstr(str, " ");
|
|
}
|
|
|
|
struct ivy_token *label, *name;
|
|
|
|
label = fx_unbox(struct ivy_token, label_entry, t_entry);
|
|
name = fx_unbox(struct ivy_token, name_entry, t_entry);
|
|
|
|
if (label && label->t_type == IVY_TOK_LABEL && label->t_str) {
|
|
fx_string_append_cstrf(str, "%s:", label->t_str);
|
|
} else {
|
|
fx_string_append_cstrf(str, "_:");
|
|
}
|
|
|
|
if (name) {
|
|
fx_string_append_cstrf(str, "%s", name->t_str);
|
|
}
|
|
|
|
if (name) {
|
|
i++;
|
|
}
|
|
|
|
label_entry = fx_queue_next(label_entry);
|
|
name_entry = fx_queue_next(name_entry);
|
|
}
|
|
|
|
if (sel->n_msg_name && !fx_queue_empty(&sel->n_arg_labels)) {
|
|
fx_string_append_cstr(str, ")");
|
|
}
|
|
|
|
fx_string_append_cstr(str, "]");
|
|
}
|
|
|
|
struct ast_node_type selector_node_ops = {
|
|
.n_to_string = to_string,
|
|
.n_node_size = sizeof(struct ivy_ast_selector_node),
|
|
};
|