Fixed some stuff

This commit is contained in:
Maieul BOYER 2024-07-30 18:40:27 +02:00
parent 8dbbfcf124
commit 9029af81b6
No known key found for this signature in database
6 changed files with 98 additions and 30 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/30 17:26:13 by rparodi #+# #+# */ /* Created: 2024/07/30 17:26:13 by rparodi #+# #+# */
/* Updated: 2024/07/30 18:32:26 by rparodi ### ########.fr */ /* Updated: 2024/07/30 18:39:53 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -122,7 +122,7 @@ void ast_alloc_other(t_ast_node_kind kind, t_ast_node ret)
t_ast_node ast_alloc(t_ast_node_kind kind) t_ast_node ast_alloc(t_ast_node_kind kind)
{ {
void ret; t_ast_node ret;
ret = mem_alloc(sizeof(*ret)); ret = mem_alloc(sizeof(*ret));
ret->kind = kind; ret->kind = kind;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/30 14:29:42 by rparodi #+# #+# */ /* Created: 2024/07/30 14:29:42 by rparodi #+# #+# */
/* Updated: 2024/07/30 14:58:13 by maiboyer ### ########.fr */ /* Updated: 2024/07/30 18:24:41 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,7 +20,6 @@
#include "parser/api.h" #include "parser/api.h"
#include <stdio.h> #include <stdio.h>
void ast_free_arith(t_ast_node elem); void ast_free_arith(t_ast_node elem);
void ast_free_condition(t_ast_node elem); void ast_free_condition(t_ast_node elem);
void ast_free_exec(t_ast_node elem); void ast_free_exec(t_ast_node elem);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */ /* Created: 2024/07/26 10:55:52 by rparodi #+# #+# */
/* Updated: 2024/07/30 17:26:52 by rparodi ### ########.fr */ /* Updated: 2024/07/30 18:20:33 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -74,6 +74,8 @@ sym_while_statement
sym_word sym_word
*/ */
t_ast_node ast_alloc(t_ast_node_kind kind);
void ast_set_term(t_ast_node *node, t_ast_terminator_kind term) void ast_set_term(t_ast_node *node, t_ast_terminator_kind term)
{ {
t_ast_terminator_kind void_storage; t_ast_terminator_kind void_storage;

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 13:04:32 by maiboyer #+# #+# */ /* Created: 2024/06/17 13:04:32 by maiboyer #+# #+# */
/* Updated: 2024/07/26 15:26:41 by maiboyer ### ########.fr */ /* Updated: 2024/07/30 18:30:47 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,18 +16,24 @@
#include "me/types.h" #include "me/types.h"
#include <stdio.h> #include <stdio.h>
t_error _build_not_finished(t_parse_node self, t_const_str input, t_ast_node *out) t_error _build_not_finished(t_parse_node self, t_const_str i, t_ast_node *out)
{ {
(void)(self); (void)(self);
(void)(out); (void)(out);
(void)(input); (void)(i);
printf("building undefined symbol '%s'\n", ts_node_grammar_type(self)); printf("building undefined symbol '%s'\n", ts_node_type(self));
return (ERROR); return (ERROR);
} }
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_heredoc_body(t_parse_node self, t_const_str input, \
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_content(t_parse_node self, t_const_str input, t_ast_node *out); t_ast_node *out) __attribute__((weak, alias("_build_not_finished")));
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_end(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_heredoc_content(t_parse_node self, t_const_str input, \
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_redirect(t_parse_node self, t_const_str input, t_ast_node *out); t_ast_node *out) __attribute__((weak, alias("_build_not_finished")));
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_start(t_parse_node self, t_const_str input, t_ast_node *out); t_error build_sym_heredoc_end(t_parse_node self, t_const_str input, \
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, t_ast_node *out); t_ast_node *out) __attribute__((weak, alias("_build_not_finished")));
t_error build_sym_heredoc_redirect(t_parse_node self, t_const_str input, \
t_ast_node *out) __attribute__((weak, alias("_build_not_finished")));
t_error build_sym_heredoc_start(t_parse_node self, t_const_str input, \
t_ast_node *out) __attribute__((weak, alias("_build_not_finished")));
t_error build_sym_simple_heredoc_body(t_parse_node self, t_const_str input, \
t_ast_node *out) __attribute__((weak, alias("_build_not_finished")));

View file

@ -6,20 +6,62 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 11:00:25 by rparodi #+# #+# */ /* Created: 2024/07/26 11:00:25 by rparodi #+# #+# */
/* Updated: 2024/07/30 17:01:04 by maiboyer ### ########.fr */ /* Updated: 2024/07/30 18:24:16 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "ast/_function_declaration.h" #include "ast/_function_declaration.h"
#define NOT_DONE {printf("This function is not done '%s'", __func__); (void)(self);} void ast_print_node_if(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_if(t_ast_node self) NOT_DONE; void ast_print_node_case(t_ast_node self)
void ast_print_node_case(t_ast_node self) NOT_DONE; {
void ast_print_node_case_item(t_ast_node self) NOT_DONE; printf("This function is not done '%s'", __func__);
void ast_print_node_elif(t_ast_node self) NOT_DONE; (void)(self);
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_case_item(t_ast_node self)
void ast_print_node_while(t_ast_node self) NOT_DONE; {
void ast_print_node_heredoc_redirection(t_ast_node self) NOT_DONE; printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_elif(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_else(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_for(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_until(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_while(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}
void ast_print_node_heredoc_redirection(t_ast_node self)
{
printf("This function is not done '%s'", __func__);
(void)(self);
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */ /* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/07/26 13:33:00 by rparodi ### ########.fr */ /* Updated: 2024/07/30 18:38:50 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,10 +41,12 @@ t_ast_while while_;
t_ast_word word; t_ast_word word;
*/ */
void ast_print_node(t_ast_node self) static inline void ast_print_block1(t_ast_node self);
static inline void ast_print_block2(t_ast_node self);
static inline void ast_print_block3(t_ast_node self);
static inline void ast_print_block1(t_ast_node self)
{ {
if (self == NULL)
return ((void)printf("ast == NULL\n"));
if (self->kind == AST_ARITHMETIC_EXPANSION) if (self->kind == AST_ARITHMETIC_EXPANSION)
return (ast_print_node_arithmetic_expansion(self)); return (ast_print_node_arithmetic_expansion(self));
if (self->kind == AST_CASE) if (self->kind == AST_CASE)
@ -63,6 +65,11 @@ void ast_print_node(t_ast_node self)
return (ast_print_node_else(self)); return (ast_print_node_else(self));
if (self->kind == AST_EMPTY) if (self->kind == AST_EMPTY)
return ; return ;
ast_print_block2(self);
}
static inline void ast_print_block2(t_ast_node self)
{
if (self->kind == AST_EXPANSION) if (self->kind == AST_EXPANSION)
return (ast_print_node_expansion(self)); return (ast_print_node_expansion(self));
if (self->kind == AST_EXTGLOB) if (self->kind == AST_EXTGLOB)
@ -73,12 +80,19 @@ void ast_print_node(t_ast_node self)
return (ast_print_node_for(self)); return (ast_print_node_for(self));
if (self->kind == AST_FUNCTION_DEFINITION) if (self->kind == AST_FUNCTION_DEFINITION)
return (ast_print_node_function_definition(self)); return (ast_print_node_function_definition(self));
if (self == NULL)
return ((void)printf("ast == NULL\n"));
if (self->kind == AST_HEREDOC_REDIRECTION) if (self->kind == AST_HEREDOC_REDIRECTION)
return (ast_print_node_heredoc_redirection(self)); return (ast_print_node_heredoc_redirection(self));
if (self->kind == AST_IF) if (self->kind == AST_IF)
return (ast_print_node_if(self)); return (ast_print_node_if(self));
if (self->kind == AST_LIST) if (self->kind == AST_LIST)
return (ast_print_node_list(self)); return (ast_print_node_list(self));
ast_print_block3(self);
}
static inline void ast_print_block3(t_ast_node self)
{
if (self->kind == AST_PIPELINE) if (self->kind == AST_PIPELINE)
return (ast_print_node_pipeline(self)); return (ast_print_node_pipeline(self));
if (self->kind == AST_PROGRAM) if (self->kind == AST_PROGRAM)
@ -99,3 +113,8 @@ void ast_print_node(t_ast_node self)
return (ast_print_node_word(self)); return (ast_print_node_word(self));
printf("Unknown ast->kind: %#04x\n", self->kind); printf("Unknown ast->kind: %#04x\n", self->kind);
} }
void ast_print_node(t_ast_node self)
{
ast_print_block1(self);
}