Files
bshell/bshell.runtime/ast/func.c
T
2026-05-30 19:50:13 +01:00

46 lines
1.2 KiB
C

#include <bshell/ast.h>
#include <bshell/parse/token.h>
static enum bshell_status collect_children(
struct bshell_ast_node *node,
struct bshell_ast_iterator *it)
{
struct bshell_func_ast_node *func = (struct bshell_func_ast_node *)node;
fx_queue_entry *cur = fx_queue_first(&func->n_params);
while (cur) {
struct bshell_ast_node *child
= fx_unbox(struct bshell_ast_node, cur, n_entry);
bshell_ast_iterator_enqueue(it, child);
cur = fx_queue_next(cur);
}
if (func->n_body) {
bshell_ast_iterator_enqueue(it, func->n_body);
}
return BSHELL_SUCCESS;
}
static void to_string(const struct bshell_ast_node *node, fx_bstr *out)
{
const struct bshell_func_ast_node *func
= (const struct bshell_func_ast_node *)node;
fx_bstr_write_fmt(out, NULL, "%s", func->n_name->tok_str);
}
static enum bshell_status cleanup(struct bshell_ast_node *node)
{
struct bshell_func_ast_node *d = (struct bshell_func_ast_node *)node;
bshell_lex_token_destroy(d->n_name);
return BSHELL_SUCCESS;
}
struct bshell_ast_node_definition func_bshell_ast_node = {
.def_id = BSHELL_AST_FUNC,
.def_node_size = sizeof(struct bshell_func_ast_node),
.def_collect_children = collect_children,
.def_to_string = to_string,
.def_cleanup = cleanup,
};