42sh/src/utils/ast/ast_list.c

49 lines
880 B
C
Raw Normal View History

#include "utils/ast/ast.h"
2026-01-15 18:49:42 +01:00
#include <assert.h>
struct ast *ast_create_list(struct list *list)
{
struct ast_list *ast_list = malloc(sizeof(struct ast_list));
if (ast_list == NULL)
return NULL;
2026-01-15 18:49:42 +01:00
ast_list->children = list;
return ast_create(AST_LIST, ast_list);
}
struct ast_list *ast_get_list(struct ast *node)
{
assert(node != NULL);
return (struct ast_list*)node->data;
}
bool ast_is_list(struct ast *node)
{
return node->type == AST_LIST;
}
2026-01-15 18:49:42 +01:00
void ast_free_list(struct ast_list *ast_list)
{
2026-01-15 18:49:42 +01:00
if (ast_list == NULL)
return;
2026-01-15 18:49:42 +01:00
list_deep_destroy(ast_list->children);
free(ast_list);
}
void ast_list_deep_destroy(struct list *l)
{
struct list *elt = l;
struct list *next_elt;
while (elt != NULL)
{
next_elt = elt->next;
ast_free(elt->data);
free(elt);
elt = next_elt;
}
}