Updated to fix fucking dumb bug
This commit is contained in:
parent
efec224b6a
commit
14647f3671
7 changed files with 45 additions and 38 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/06/24 00:51:59 by maiboyer ### ########.fr */
|
/* Updated: 2024/06/24 17:38:03 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -79,7 +79,6 @@ sym_word
|
||||||
|
|
||||||
void ast_free(t_ast_node elem)
|
void ast_free(t_ast_node elem)
|
||||||
{
|
{
|
||||||
printf("elem = %p\n", elem);
|
|
||||||
if (elem == NULL)
|
if (elem == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -193,7 +192,6 @@ void ast_free(t_ast_node elem)
|
||||||
}
|
}
|
||||||
if (elem->kind == AST_VARIABLE_ASSIGNMENT)
|
if (elem->kind == AST_VARIABLE_ASSIGNMENT)
|
||||||
{
|
{
|
||||||
printf("value = %p\n", elem->data.variable_assignment.value);
|
|
||||||
ast_free(elem->data.variable_assignment.value);
|
ast_free(elem->data.variable_assignment.value);
|
||||||
mem_free(elem->data.variable_assignment.name);
|
mem_free(elem->data.variable_assignment.name);
|
||||||
}
|
}
|
||||||
|
|
@ -445,7 +443,8 @@ t_error build_sym_while_statement(t_parse_node self, t_const_str input, t_ast_no
|
||||||
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out)
|
t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_ast_node *out)
|
||||||
{
|
{
|
||||||
t_ast_node ret;
|
t_ast_node ret;
|
||||||
t_str temp_str;
|
t_parse_node temp_ast;
|
||||||
|
//t_str temp_str;
|
||||||
|
|
||||||
(void)(self);
|
(void)(self);
|
||||||
(void)(input);
|
(void)(input);
|
||||||
|
|
@ -455,9 +454,18 @@ t_error build_sym_variable_assignment(t_parse_node self, t_const_str input, t_as
|
||||||
if (ts_node_grammar_symbol(self) != sym_variable_assignment)
|
if (ts_node_grammar_symbol(self) != sym_variable_assignment)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
ret = ast_alloc(AST_VARIABLE_ASSIGNMENT);
|
ret = ast_alloc(AST_VARIABLE_ASSIGNMENT);
|
||||||
temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
|
//temp_str = str_substring(input, ts_node_start_byte(self), ts_node_end_byte(self) - ts_node_start_byte(self));
|
||||||
ret->data.raw_string.str = temp_str;
|
if (ts_node_named_child_count(self) >= 1)
|
||||||
ret->data.raw_string.len = str_len(temp_str);
|
{
|
||||||
|
temp_ast = ts_node_named_child(self, 0);
|
||||||
|
if (ts_node_grammar_symbol(temp_ast) != sym_variable_name)
|
||||||
|
return (ast_free(ret), ERROR);
|
||||||
|
ret->data.variable_assignment.name = str_substring(input, ts_node_start_byte(temp_ast), ts_node_end_byte(temp_ast) - ts_node_start_byte(temp_ast));
|
||||||
|
}
|
||||||
|
if (ts_node_named_child_count(self) > 1){
|
||||||
|
if (ast_from_node(ts_node_named_child(self, 1) ,input,&ret->data.variable_assignment.value))
|
||||||
|
return (ast_free(ret), ERROR);
|
||||||
|
}
|
||||||
return (*out = ret, NO_ERROR);
|
return (*out = ret, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -826,7 +834,6 @@ sym_word
|
||||||
|
|
||||||
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
t_error ast_from_node(t_parse_node node, t_const_str input, t_ast_node *out)
|
||||||
{
|
{
|
||||||
return (ERROR);
|
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (ts_node_grammar_symbol(node) == sym_arithmetic_binary_expression)
|
if (ts_node_grammar_symbol(node) == sym_arithmetic_binary_expression)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/vec/vec_ast.h"
|
#include "me/vec/vec_ast.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
@ -45,7 +42,7 @@ t_error vec_ast_push(t_vec_ast *vec, t_ast_node element)
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
|
t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
size_t new_capacity;
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -54,7 +51,8 @@ t_error vec_ast_reserve(t_vec_ast *vec, t_usize wanted_capacity)
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_ast_node));
|
vec->buffer =
|
||||||
|
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_ast_node));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -83,6 +81,8 @@ t_error vec_ast_pop(t_vec_ast *vec, t_ast_node *value)
|
||||||
/// This function is safe to call with `free_elem` being NULL
|
/// This function is safe to call with `free_elem` being NULL
|
||||||
void vec_ast_free(t_vec_ast vec)
|
void vec_ast_free(t_vec_ast vec)
|
||||||
{
|
{
|
||||||
|
if (vec.buffer == NULL)
|
||||||
|
return;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/vec/vec_parser_heredoc.h"
|
#include "me/vec/vec_parser_heredoc.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
@ -45,7 +42,7 @@ t_error vec_parser_heredoc_push(t_vec_parser_heredoc *vec, t_heredoc element)
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, t_usize wanted_capacity)
|
t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, t_usize wanted_capacity)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
size_t new_capacity;
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -54,7 +51,8 @@ t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, t_usize wanted_cap
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
vec->buffer =
|
||||||
|
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -83,6 +81,8 @@ t_error vec_parser_heredoc_pop(t_vec_parser_heredoc *vec, t_heredoc *value)
|
||||||
/// This function is safe to call with `free_elem` being NULL
|
/// This function is safe to call with `free_elem` being NULL
|
||||||
void vec_parser_heredoc_free(t_vec_parser_heredoc vec)
|
void vec_parser_heredoc_free(t_vec_parser_heredoc vec)
|
||||||
{
|
{
|
||||||
|
if (vec.buffer == NULL)
|
||||||
|
return;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/vec/vec_parser_range.h"
|
#include "me/vec/vec_parser_range.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
@ -45,7 +42,7 @@ t_error vec_parser_range_push(t_vec_parser_range *vec, t_parser_range element)
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_parser_range_reserve(t_vec_parser_range *vec, t_usize wanted_capacity)
|
t_error vec_parser_range_reserve(t_vec_parser_range *vec, t_usize wanted_capacity)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
size_t new_capacity;
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -54,7 +51,8 @@ t_error vec_parser_range_reserve(t_vec_parser_range *vec, t_usize wanted_capacit
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
|
vec->buffer =
|
||||||
|
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -83,6 +81,8 @@ t_error vec_parser_range_pop(t_vec_parser_range *vec, t_parser_range *value)
|
||||||
/// This function is safe to call with `free_elem` being NULL
|
/// This function is safe to call with `free_elem` being NULL
|
||||||
void vec_parser_range_free(t_vec_parser_range vec)
|
void vec_parser_range_free(t_vec_parser_range vec)
|
||||||
{
|
{
|
||||||
|
if (vec.buffer == NULL)
|
||||||
|
return;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/vec/vec_reduce_action.h"
|
#include "me/vec/vec_reduce_action.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
@ -45,7 +42,7 @@ t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capacity)
|
t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capacity)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
size_t new_capacity;
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -54,7 +51,8 @@ t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capac
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
|
vec->buffer =
|
||||||
|
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -83,6 +81,8 @@ t_error vec_reduce_action_pop(t_vec_reduce_action *vec, t_reduce_action *value)
|
||||||
/// This function is safe to call with `free_elem` being NULL
|
/// This function is safe to call with `free_elem` being NULL
|
||||||
void vec_reduce_action_free(t_vec_reduce_action vec)
|
void vec_reduce_action_free(t_vec_reduce_action vec)
|
||||||
{
|
{
|
||||||
|
if (vec.buffer == NULL)
|
||||||
|
return;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/vec/vec_str.h"
|
#include "me/vec/vec_str.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
@ -45,7 +42,7 @@ t_error vec_str_push(t_vec_str *vec, t_str element)
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
size_t new_capacity;
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -54,7 +51,8 @@ t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
vec->buffer =
|
||||||
|
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -83,6 +81,8 @@ t_error vec_str_pop(t_vec_str *vec, t_str *value)
|
||||||
/// This function is safe to call with `free_elem` being NULL
|
/// This function is safe to call with `free_elem` being NULL
|
||||||
void vec_str_free(t_vec_str vec)
|
void vec_str_free(t_vec_str vec)
|
||||||
{
|
{
|
||||||
|
if (vec.buffer == NULL)
|
||||||
|
return;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/vec/vec_C__PREFIX__.h"
|
#include "me/vec/vec_C__PREFIX__.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
@ -45,7 +42,7 @@ t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element)
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity)
|
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
size_t new_capacity;
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -54,7 +51,8 @@ t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity)
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||||
while (wanted_capacity > new_capacity)
|
while (wanted_capacity > new_capacity)
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
vec->buffer =
|
||||||
|
mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||||
vec->capacity = new_capacity;
|
vec->capacity = new_capacity;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -83,6 +81,8 @@ t_error vec_C__PREFIX___pop(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value)
|
||||||
/// This function is safe to call with `free_elem` being NULL
|
/// This function is safe to call with `free_elem` being NULL
|
||||||
void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec)
|
void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec)
|
||||||
{
|
{
|
||||||
|
if (vec.buffer == NULL)
|
||||||
|
return;
|
||||||
if (vec.free_func)
|
if (vec.free_func)
|
||||||
{
|
{
|
||||||
while (vec.len)
|
while (vec.len)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue