2026-01-27 00:30:19 +01:00
|
|
|
#include "ast_neg.h"
|
|
|
|
|
|
2026-01-31 15:50:57 +01:00
|
|
|
#include <stdio.h>
|
2026-01-27 00:30:19 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
struct ast_neg *ast_get_neg(struct ast *node)
|
|
|
|
|
{
|
2026-01-31 15:50:57 +01:00
|
|
|
if (node == NULL || node->type != AST_NEG)
|
|
|
|
|
return NULL;
|
|
|
|
|
return node->data;
|
2026-01-27 00:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ast *ast_create_neg(bool negation, struct ast *child)
|
|
|
|
|
{
|
2026-01-31 15:50:57 +01:00
|
|
|
struct ast_neg *neg_data = malloc(sizeof(struct ast_neg));
|
|
|
|
|
if (neg_data == NULL)
|
|
|
|
|
{
|
|
|
|
|
perror("Error: could not allocate more memory");
|
2026-01-27 00:30:19 +01:00
|
|
|
return NULL;
|
2026-01-31 15:50:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
neg_data->negation = negation;
|
|
|
|
|
neg_data->child = child;
|
|
|
|
|
struct ast *result = ast_create(AST_NEG, neg_data);
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
free(neg_data);
|
2026-01-27 00:30:19 +01:00
|
|
|
|
2026-01-31 15:50:57 +01:00
|
|
|
return result;
|
2026-01-27 00:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ast_free_neg(struct ast_neg *node)
|
|
|
|
|
{
|
2026-01-31 15:50:57 +01:00
|
|
|
if (node == NULL)
|
2026-01-27 00:30:19 +01:00
|
|
|
return;
|
2026-01-31 15:50:57 +01:00
|
|
|
|
2026-01-27 00:30:19 +01:00
|
|
|
ast_free(&node->child);
|
|
|
|
|
free(node);
|
|
|
|
|
}
|