Adding norm to that fils

This commit is contained in:
Raphaël 2024-07-26 12:16:27 +02:00
parent e507d7fbf7
commit 1ca0aeb072
9 changed files with 437 additions and 396 deletions

View file

@ -9,11 +9,11 @@ me_alloc/merge_blocks \
me_alloc/pages \
me_alloc/realloc \
vg/dummy_block \
vg/dummy_mem_status \
vg/dummy_mempool \
vg/dummy_mempool_bis \
vg/dummy_mem_status \
vg/valgrind_block \
vg/valgrind_mem_status \
vg/valgrind_mempool \
vg/valgrind_mempool_bis \
vg/valgrind_mem_status \

View file

@ -1,5 +1,6 @@
SRC_FILES = \
from_node \
not_done_function \
not_done_print \
print_ast \

View file

@ -0,0 +1,67 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* function_declaration.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 11:30:24 by rparodi #+# #+# */
/* Updated: 2024/07/26 11:38:39 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FUNCTION_DECLARATION_H
# define FUNCTION_DECLARATION_H
#include "ast/ast.h"
#include "me/types.h"
#include <stdio.h>
#define NOT_DONE \
{ \
printf("function `%s` isn't done !\n", __func__); \
(void)(self); \
}
void ast_print_node(t_ast_node self);
void ast_print_node_command(t_ast_node self);
void ast_print_node_command_substitution(t_ast_node self);
void ast_print_node_compound_statement(t_ast_node self);
void ast_print_node_expansion(t_ast_node self);
void ast_print_node_extglob(t_ast_node self);
void ast_print_node_file_redirection(t_ast_node self);
void ast_print_node_list(t_ast_node self);
void ast_print_node_pipeline(t_ast_node self);
void ast_print_node_program(t_ast_node self);
void ast_print_node_raw_string(t_ast_node self);
void ast_print_node_regex(t_ast_node self);
void ast_print_node_subshell(t_ast_node self);
void ast_print_node_variable_assignment(t_ast_node self);
void ast_print_node_word(t_ast_node self);
void ast_print_node_function_definition(t_ast_node self);
void ast_print_node_arithmetic_expansion(t_ast_node self);
void ast_print_node_function_definition(t_ast_node self);
void ast_print_node_variable_assignment(t_ast_node self);
void ast_print_node_pipeline(t_ast_node self);
void ast_print_node_list(t_ast_node self);
/*^^^ DONE ^^^*/
/*vvv NOT DONE vvv*/
void ast_print_node_if(t_ast_node self) NOT_DONE;
void ast_print_node_case(t_ast_node self) NOT_DONE;
void ast_print_node_case_item(t_ast_node self) NOT_DONE;
void ast_print_node_elif(t_ast_node self) NOT_DONE;
void ast_print_node_else(t_ast_node self) NOT_DONE;
void ast_print_node_for(t_ast_node self) NOT_DONE;
void ast_print_node_until(t_ast_node self) NOT_DONE;
void ast_print_node_while(t_ast_node self) NOT_DONE;
void ast_print_node_heredoc_redirection(t_ast_node self) NOT_DONE;
/// HELPER_FUNCS
void _print_term(t_ast_terminator_kind term);
#endif

View file

@ -1,7 +1,12 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* from_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
/* Updated: 2024/07/20 16:29:05 by maiboyer ### ########.fr */
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
/* Updated: 2024/07/26 11:27:49 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -13,6 +18,7 @@
#include "me/types.h"
#include "me/vec/vec_ast.h"
#include "parser/api.h"
#include <stdio.h>
/*
sym_arithmetic_binary_expression
@ -71,13 +77,13 @@ sym_word
#include <stdio.h>
#undef ERROR
#define ERROR ((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)
#define ERROR\
((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)
void ast_free(t_ast_node elem)
{
if (elem == NULL)
return ;
if (elem->kind == AST_ARITHMETIC_EXPANSION)
{
ast_free(elem->data.arithmetic_expansion.expr);
@ -214,7 +220,6 @@ void ast_free(t_ast_node elem)
{
mem_free(elem->data.regex.pattern);
}
mem_free(elem);
}
@ -224,7 +229,6 @@ t_ast_node ast_alloc(t_ast_node_kind kind)
ret = mem_alloc(sizeof(*ret));
ret->kind = kind;
if (kind == AST_ARITHMETIC_EXPANSION)
{
ret->data.arithmetic_expansion.expr = NULL;
@ -268,7 +272,8 @@ t_ast_node ast_alloc(t_ast_node_kind kind)
if (kind == AST_COMPOUND_STATEMENT)
{
ret->data.compound_statement.body = vec_ast_new(16, ast_free);
ret->data.compound_statement.suffixes_redirections = vec_ast_new(16, ast_free);
ret->data.compound_statement.suffixes_redirections \
= vec_ast_new(16, ast_free);
ret->data.compound_statement.term = AST_TERM_NONE;
}
if (kind == AST_ELIF)
@ -386,7 +391,6 @@ t_ast_node ast_alloc(t_ast_node_kind kind)
{
ret->data.regex.pattern = NULL;
}
return (ret);
}
@ -412,7 +416,6 @@ void ast_set_term(t_ast_node *node, t_ast_terminator_kind term)
ptr = &val->data.if_.term;
if (val->kind == AST_SUBSHELL)
ptr = &val->data.subshell.term;
*ptr = term;
if (ptr == &void_storage)
printf("node wasn't a term capable node\n");
@ -452,7 +455,8 @@ void _append_redirection(t_ast_node node, t_ast_node redirection)
t_vec_ast *vec;
vec = NULL;
if (!(redirection->kind == AST_FILE_REDIRECTION || redirection->kind == AST_HEREDOC_REDIRECTION))
if (!(redirection->kind == AST_FILE_REDIRECTION || \
redirection->kind == AST_HEREDOC_REDIRECTION))
return (ast_free(redirection));
if (node->kind == AST_CASE)
vec = &node->data.case_.suffixes_redirections;
@ -525,6 +529,7 @@ t_ast_expansion_operator _extract_exp_op(t_parse_node self)
{
t_ast_expansion_operator kind;
t_symbol symbol;
kind = E_OP_NONE;
symbol = ts_node_grammar_symbol(self);
if (symbol == anon_sym_DASH)
@ -658,8 +663,6 @@ t_error build_sym_heredoc_content(t_parse_node self, t_const_str input, t_ast_no
t_error build_sym_heredoc_end(t_parse_node self, t_const_str input, t_ast_node *out);
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node *out);
#include <stdio.h>
t_error build_sym_arithmetic_binary_expression(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_usize i;
@ -757,7 +760,7 @@ t_error build_sym_arithmetic_ternary_expression(t_parse_node self, t_const_str i
if (ast_from_node(ts_node_child(self, i), input, &ret->data.arithmetic_ternary.else_))
return (ast_free(ret), ERROR);
i++;
};
}
return (*out = ret, NO_ERROR);
}
@ -1042,7 +1045,6 @@ t_error build_sym_function_definition(t_parse_node self, t_const_str input, t_as
}
i++;
}
return (*out = ret, NO_ERROR);
}
@ -1078,7 +1080,6 @@ t_error build_sym_case_statement(t_parse_node self, t_const_str input, t_ast_nod
}
i++;
}
return (*out = ret, NO_ERROR);
}
@ -1313,7 +1314,6 @@ t_error build_sym_for_statement(t_parse_node self, t_const_str input, t_ast_node
t_error build_sym_pipeline(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
t_ast_node tmp;
t_usize i;
@ -1358,7 +1358,6 @@ t_error build_sym_do_group(t_parse_node self, t_const_str input, t_ast_node *out
while (i < ts_node_child_count(self))
{
if (ts_node_symbol(ts_node_child(self, i)) == anon_sym_do || ts_node_symbol(ts_node_child(self, i)) == anon_sym_done)
{
i++;
continue ;
@ -1404,7 +1403,6 @@ t_error build_sym_subshell(t_parse_node self, t_const_str input, t_ast_node *out
}
else
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue ;
if (ast_from_node(ts_node_child(self, i), input, &tmp))
@ -1484,7 +1482,7 @@ t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_a
{
if (!ts_node_is_named(ts_node_child(self, i)) && (i++, true))
continue ;
if (!(ts_node_symbol(ts_node_child(self, i)) == sym_file_redirect ||
if (!(ts_node_symbol(ts_node_child(self, i)) == sym_file_redirect || \
ts_node_symbol(ts_node_child(self, i)) == sym_heredoc_redirect))
{
if (ast_from_node(ts_node_child(self, i++), input, &ret))
@ -1500,10 +1498,7 @@ t_error build_sym_redirected_statement(t_parse_node self, t_const_str input, t_a
t_error build_sym_negated_command(t_parse_node self, t_const_str input, t_ast_node *out)
{
t_ast_node ret;
// t_ast_node tmp;
// t_usize i;
(void)(out);
(void)(input);
@ -1541,7 +1536,6 @@ t_error build_sym_compound_statement(t_parse_node self, t_const_str input, t_ast
if (ts_node_field_id_for_child(self, i) == field_term && ret->data.compound_statement.body.len != 0)
{
term = _select_term(ts_node_child(self, i));
ast_set_term(&ret->data.compound_statement.body.buffer[ret->data.compound_statement.body.len - 1], term);
}
else
@ -1649,7 +1643,6 @@ t_error build_sym_concatenation(t_parse_node self, t_const_str input, t_ast_node
vec_ast_push(&ret->data.word.inner, temp);
i++;
}
return (*out = ret, NO_ERROR);
}
@ -1791,7 +1784,6 @@ t_error build_sym_list(t_parse_node self, t_const_str input, t_ast_node *out)
if (out == NULL)
return (ERROR);
ret = ast_alloc(AST_LIST);
i = 0;
output = &ret->data.list.left;

13
ast/src/not_done_print.c Normal file
View file

@ -0,0 +1,13 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* not_done_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 11:00:25 by rparodi #+# #+# */
/* Updated: 2024/07/26 11:33:01 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/07/25 11:05:38 by rparodi ### ########.fr */
/* Updated: 2024/07/26 11:36:30 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,13 +14,7 @@
#include "me/types.h"
#include <stdio.h>
void ast_print_node(t_ast_node self);
#define NOT_DONE \
{ \
printf("function `%s` isn't done !\n", __func__); \
(void)(self); \
}
#include "../include/function_declaration.h"
/*
t_ast_arithmetic_expansion arithmetic_expansion;
@ -51,35 +45,8 @@ t_ast_while while_;
t_ast_word word;
*/
void ast_print_node_command(t_ast_node self);
void ast_print_node_command_substitution(t_ast_node self);
void ast_print_node_compound_statement(t_ast_node self);
void ast_print_node_expansion(t_ast_node self);
void ast_print_node_extglob(t_ast_node self);
void ast_print_node_file_redirection(t_ast_node self);
void ast_print_node_list(t_ast_node self);
void ast_print_node_pipeline(t_ast_node self);
void ast_print_node_program(t_ast_node self);
void ast_print_node_raw_string(t_ast_node self);
void ast_print_node_regex(t_ast_node self);
void ast_print_node_subshell(t_ast_node self);
void ast_print_node_variable_assignment(t_ast_node self);
void ast_print_node_word(t_ast_node self);
void ast_print_node_function_definition(t_ast_node self);
/*^^^ DONE ^^^*/
/*vvv NOT DONE vvv*/
void ast_print_node_if(t_ast_node self) NOT_DONE;
void ast_print_node_case(t_ast_node self) NOT_DONE;
void ast_print_node_case_item(t_ast_node self) NOT_DONE;
void ast_print_node_elif(t_ast_node self) NOT_DONE;
void ast_print_node_else(t_ast_node self) NOT_DONE;
void ast_print_node_for(t_ast_node self) NOT_DONE;
void ast_print_node_until(t_ast_node self) NOT_DONE;
void ast_print_node_while(t_ast_node self) NOT_DONE;
void ast_print_node_heredoc_redirection(t_ast_node self) NOT_DONE;
/// HELPER_FUNCS
@ -116,6 +83,7 @@ void ast_print_node_arithmetic_expansion(t_ast_node self)
void ast_print_node_function_definition(t_ast_node self)
{
t_usize i;
if (self == NULL)
return ;
if (self->kind != AST_FUNCTION_DEFINITION)
@ -167,7 +135,9 @@ void ast_print_node_pipeline(t_ast_node self)
while (i < self->data.pipeline.suffixes_redirections.len)
{
printf(" ");
ast_print_node(self->data.pipeline.suffixes_redirections.buffer[i++]); } _print_term(self->data.pipeline.term);
ast_print_node(self->data.pipeline.suffixes_redirections.buffer[i++]);
}
_print_term(self->data.pipeline.term);
}
void ast_print_node_list(t_ast_node self)
@ -210,7 +180,6 @@ void ast_print_node_file_redirection(t_ast_node self)
return ;
if (self->data.file_redirection.input != NULL)
ast_print_node(self->data.file_redirection.input);
if (self->data.file_redirection.op == AST_REDIR_INPUT)
printf("<");
if (self->data.file_redirection.op == AST_REDIR_OUTPUT)
@ -229,7 +198,6 @@ void ast_print_node_file_redirection(t_ast_node self)
// printf("<<");
// if (self->data.file_redirection.op == AST_REDIR_HEREDOC_INDENT)
// printf("<<-");
if (self->data.file_redirection.output != NULL)
ast_print_node(self->data.file_redirection.output);
}

View file

@ -2,9 +2,9 @@ SRC_FILES = \
line \
line_edit_actions \
line_edit_actions2 \
line_edit_mode \
line_editing \
line_editing2 \
line_edit_mode \
line_globals \
line_history \
line_internals \

View file

@ -114,6 +114,28 @@ primary_state_ids/primary_state_ids_18 \
primary_state_ids/primary_state_ids_19 \
primary_state_ids/primary_state_ids_20 \
primary_state_ids/primary_state_ids_21 \
small_parse_table_map/small_parse_table_map_0 \
small_parse_table_map/small_parse_table_map_1 \
small_parse_table_map/small_parse_table_map_2 \
small_parse_table_map/small_parse_table_map_3 \
small_parse_table_map/small_parse_table_map_4 \
small_parse_table_map/small_parse_table_map_5 \
small_parse_table_map/small_parse_table_map_6 \
small_parse_table_map/small_parse_table_map_7 \
small_parse_table_map/small_parse_table_map_8 \
small_parse_table_map/small_parse_table_map_9 \
small_parse_table_map/small_parse_table_map_10 \
small_parse_table_map/small_parse_table_map_11 \
small_parse_table_map/small_parse_table_map_12 \
small_parse_table_map/small_parse_table_map_13 \
small_parse_table_map/small_parse_table_map_14 \
small_parse_table_map/small_parse_table_map_15 \
small_parse_table_map/small_parse_table_map_16 \
small_parse_table_map/small_parse_table_map_17 \
small_parse_table_map/small_parse_table_map_18 \
small_parse_table_map/small_parse_table_map_19 \
small_parse_table_map/small_parse_table_map_20 \
small_parse_table_map/small_parse_table_map_21 \
small_parse_table/small_parse_table_0 \
small_parse_table/small_parse_table_1 \
small_parse_table/small_parse_table_2 \
@ -946,28 +968,6 @@ small_parse_table/small_parse_table_828 \
small_parse_table/small_parse_table_829 \
small_parse_table/small_parse_table_830 \
small_parse_table/small_parse_table_831 \
small_parse_table_map/small_parse_table_map_0 \
small_parse_table_map/small_parse_table_map_1 \
small_parse_table_map/small_parse_table_map_2 \
small_parse_table_map/small_parse_table_map_3 \
small_parse_table_map/small_parse_table_map_4 \
small_parse_table_map/small_parse_table_map_5 \
small_parse_table_map/small_parse_table_map_6 \
small_parse_table_map/small_parse_table_map_7 \
small_parse_table_map/small_parse_table_map_8 \
small_parse_table_map/small_parse_table_map_9 \
small_parse_table_map/small_parse_table_map_10 \
small_parse_table_map/small_parse_table_map_11 \
small_parse_table_map/small_parse_table_map_12 \
small_parse_table_map/small_parse_table_map_13 \
small_parse_table_map/small_parse_table_map_14 \
small_parse_table_map/small_parse_table_map_15 \
small_parse_table_map/small_parse_table_map_16 \
small_parse_table_map/small_parse_table_map_17 \
small_parse_table_map/small_parse_table_map_18 \
small_parse_table_map/small_parse_table_map_19 \
small_parse_table_map/small_parse_table_map_20 \
small_parse_table_map/small_parse_table_map_21 \
symbols_metadata/symbols_metadata_0 \
symbols_metadata/symbols_metadata_1 \
symbols_names/symbols_names_0 \

View file

@ -38,10 +38,10 @@ fs/read \
fs/read_to_vec \
fs/write \
gnl/get_next_line \
hash/hasher \
hash/hash_signed \
hash/hash_str \
hash/hash_unsigned \
hash/hasher \
hash/sip/sip13 \
hash/sip/sip_utils \
hash/sip/sip_utils2 \
@ -89,6 +89,10 @@ printf/printf \
printf/printf_fd \
printf/printf_str \
printf/vprintf \
string/mod \
string/string_insert \
string/string_remove \
string/string_reserve \
str/str_clone \
str/str_compare \
str/str_find_chr \
@ -105,10 +109,6 @@ str/str_n_find_str \
str/str_split \
str/str_substring \
str/str_trim \
string/mod \
string/string_insert \
string/string_remove \
string/string_reserve \
GEN_FILES = \
convert/i16_to_str \