#include #include "ast.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; 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; } void ast_free_list(struct ast_list *ast_list) { if (ast_list == NULL) return; ast_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; struct ast *node = (struct ast *)elt->data; ast_free(&node); free(elt); elt = next_elt; } }