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

30 lines
609 B
C

#include "ast.h"
#include <stdbool.h>
void ast_free(struct ast *node)
{
if (node == NULL)
return;
// ast void does not need to be freed.
if (ast_is_if(node))
ast_free_if(ast_get_if(node));
else if (ast_is_command(node))
ast_free_command(ast_get_command(node));
else if (ast_is_list(node))
ast_free_list(ast_get_list(node));
free(node);
}
struct ast *ast_create(enum ast_type type, void *data)
{
struct ast *node = malloc(sizeof(struct ast));
if (!node)
return NULL;
node->type = type;
node->data = data;
return node;
}