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,6 +1,7 @@
#include "ast_if.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct ast *ast_create_if(struct ast *condition, struct ast *then_clause,
@ -8,13 +9,20 @@ struct ast *ast_create_if(struct ast *condition, struct ast *then_clause,
{
struct ast_if *if_data = malloc(sizeof(struct ast_if));
if (!if_data)
{
perror("Error: could not allocate more memory");
return NULL;
}
if_data->condition = condition;
if_data->then_clause = then_clause;
if_data->else_clause = else_clause;
return ast_create(AST_IF, if_data);
struct ast *result = ast_create(AST_IF, if_data);
if (result == NULL)
free(if_data);
return result;
}
struct ast_if *ast_get_if(struct ast *node)
@ -24,11 +32,6 @@ struct ast_if *ast_get_if(struct ast *node)
return node->data;
}
bool ast_is_if(struct ast *node)
{
return node != NULL && node->type == AST_IF;
}
void ast_free_if(struct ast_if *if_data)
{
if (if_data == NULL)