fix: fixed A LOT of bugs and memory leaks. Removed ast_is_* commands as they're not really useful and seems redundant with ast_get_*. Also made some changes to lists utils to make architecture clearer and some other random tweaks or fixes.

This commit is contained in:
Gu://em_ 2026-01-31 15:50:57 +01:00
parent f31fca4204
commit ac851fa895
31 changed files with 411 additions and 236 deletions

View file

@ -1,34 +1,38 @@
#include "ast_neg.h"
#include <stdio.h>
#include <stdlib.h>
bool ast_is_neg(struct ast *node)
{
return node != NULL && node->type == AST_NEG;
}
struct ast_neg *ast_get_neg(struct ast *node)
{
if (ast_is_neg(node))
return node->data;
return NULL;
if (node == NULL || node->type != AST_NEG)
return NULL;
return node->data;
}
struct ast *ast_create_neg(bool negation, struct ast *child)
{
struct ast_neg *node = malloc(sizeof(struct ast_neg));
if (!node)
struct ast_neg *neg_data = malloc(sizeof(struct ast_neg));
if (neg_data == NULL)
{
perror("Error: could not allocate more memory");
return NULL;
}
node->negation = negation;
node->child = child;
return ast_create(AST_NEG, node);
neg_data->negation = negation;
neg_data->child = child;
struct ast *result = ast_create(AST_NEG, neg_data);
if (result == NULL)
free(neg_data);
return result;
}
void ast_free_neg(struct ast_neg *node)
{
if (!node)
if (node == NULL)
return;
ast_free(&node->child);
free(node);
}