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

38 lines
819 B
C
Raw Normal View History

#include "utils/ast/ast_and_or.h"
#include <stdlib.h>
bool ast_is_and_or(struct ast *node)
{
return node != NULL && node->type == AST_AND_OR;
}
struct ast_and_or *ast_get_and_or(struct ast *node)
{
if (ast_is_and_or(node))
return (struct ast_and_or *)node->data;
return NULL;
}
struct ast *ast_create_and_or(struct ast *left, struct ast *right,
enum ast_and_or_type type)
{
struct ast_and_or *and_or = malloc(sizeof(struct ast_and_or));
if (!and_or)
return NULL;
and_or->left = left;
and_or->right = right;
and_or->type = type;
return ast_create(AST_AND_OR, and_or);
}
void ast_free_and_or(struct ast_and_or *and_or)
{
if (!and_or)
return;
ast_free(&and_or->left);
ast_free(&and_or->right);
free(and_or);
}