Files
ivy/lang/ast/property.c
T

53 lines
1.3 KiB
C
Raw Normal View History

2024-12-06 19:47:27 +00:00
#include "iterate.h"
#include "node.h"
2026-03-16 14:07:33 +00:00
#include <fx/ds/string.h>
2024-12-06 19:47:27 +00:00
#include <ivy/lang/lex.h>
#include <stdio.h>
#define PROPERTY_TYPE(flags) (flags & (PROPERTY_FULL | PROPERTY_AUTO))
static void collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_property_node *prop = (struct ivy_ast_property_node *)node;
if (prop->n_get) {
ast_node_iterator_enqueue_node(iterator, node, prop->n_get);
}
if (prop->n_set) {
ast_node_iterator_enqueue_node(iterator, node, prop->n_set);
}
}
2026-03-16 14:07:33 +00:00
static void to_string(struct ivy_ast_node *node, fx_string *str)
2024-12-06 19:47:27 +00:00
{
struct ivy_ast_property_node *prop = (struct ivy_ast_property_node *)node;
2026-03-16 14:07:33 +00:00
fx_string_append_cstrf(
str, "%s (%s) [", ivy_ast_node_type_to_string(node->n_type),
prop->n_ident->t_str);
2024-12-06 19:47:27 +00:00
if (prop->n_flags & IVY_AST_PROPERTY_GET) {
2026-03-16 14:07:33 +00:00
fx_string_append_cstr(str, "get");
2024-12-06 19:47:27 +00:00
}
if ((prop->n_flags & IVY_AST_PROPERTY_GET)
&& prop->n_flags & IVY_AST_PROPERTY_SET) {
2026-03-16 14:07:33 +00:00
fx_string_append_cstr(str, ", ");
2024-12-06 19:47:27 +00:00
}
if (prop->n_flags & IVY_AST_PROPERTY_SET) {
2026-03-16 14:07:33 +00:00
fx_string_append_cstr(str, "set");
2024-12-06 19:47:27 +00:00
}
2026-03-16 14:07:33 +00:00
fx_string_append_cstr(str, "]");
2024-12-06 19:47:27 +00:00
}
struct ast_node_type property_node_ops = {
.n_to_string = to_string,
2024-12-06 19:47:27 +00:00
.n_collect_children = collect_children,
.n_node_size = sizeof(struct ivy_ast_property_node),
};