Update AST signatures to remove the t_node type

This commit is contained in:
Maieul BOYER 2024-06-17 15:05:03 +02:00
parent c9baa2b499
commit 77a3b305aa
No known key found for this signature in database
7 changed files with 291 additions and 33 deletions

View file

@ -6,13 +6,13 @@
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ # # By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
# Updated: 2024/05/25 16:29:47 by maiboyer ### ########.fr # # Updated: 2024/06/17 13:12:53 by maiboyer ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
BUILD_DIR ?= ../build BUILD_DIR ?= ../build
SRC_DIR = src SRC_DIR = src
INCLUDE_DIR = include output/include ../includes INCLUDE_DIR = include output/include ../includes ../output/include/
LIBS_DIR = . LIBS_DIR = .
GENERIC_DIR = output/src GENERIC_DIR = output/src
GENERIC_INCLUDE = output/include GENERIC_INCLUDE = output/include
@ -25,6 +25,7 @@ TARGET = $(BUILD_DIR)/$(NAME)
CC ?= clang CC ?= clang
CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"'
# CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope # CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope
CFLAGS += -O2
BONUS_FILES = BONUS_FILES =
LIBS_NAME = LIBS_NAME =
SUBJECT_URL = SUBJECT_URL =

View file

@ -6,44 +6,55 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */ /* Created: 2024/06/11 14:23:40 by maiboyer #+# #+# */
/* Updated: 2024/06/11 14:24:38 by maiboyer ### ########.fr */ /* Updated: 2024/06/17 13:27:23 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef AST_H #ifndef AST_H
#define AST_H #define AST_H
#include "ast/ast_forward_def.h" #include "ast/ast_forward_def.h" // IWYU pragma: keep
#include "ast/ast_raw_structs.h" #include "ast/ast_raw_structs.h" // IWYU pragma: keep
enum e_ast_node_kind enum e_ast_node_kind
{ {
AST_ARITHMETIC_EXPANSION, S_AST_CATEGORY_MASK = 0xFFFF0000,
AST_CASE_ITEM, S_AST_NODETYPE_MASK = 0x0000FFFF,
AST_CASE,
AST_COMMAND_SUBSTITUTION,
AST_COMMAND,
AST_COMPOUND_STATEMENT,
AST_ELIF,
AST_ELSE,
AST_EMPTY,
AST_EXPANSION,
AST_FILE_REDIRECTION,
AST_FOR,
AST_FUNCTION_DEFINITION,
AST_HEREDOC_REDIRECTION,
AST_IF,
AST_LIST,
AST_PIPELINE,
AST_RAW_STRING,
AST_STRING,
AST_SUBSHELL,
AST_UNTIL,
AST_VARIABLE_ASSIGNMENT,
AST_WHILE,
AST_WORD,
__AST_LAST_NODETYPE__, S_AST_NONE = 0,
S_AST_COMPOUND_COMMAND = 1 << 16,
S_AST_COMMAND = 1 << 17,
S_AST_REDIRECT = 1 << 18,
S_AST_EXPANSION = 1 << 19,
AST_ARITHMETIC_EXPANSION = S_AST_EXPANSION | 0x0001,
AST_COMMAND_SUBSTITUTION = S_AST_EXPANSION | 0x0002,
AST_EXPANSION = S_AST_EXPANSION | 0x0003,
AST_COMMAND = S_AST_COMMAND | 0x0004,
AST_CASE_ITEM = S_AST_NONE | 0x0005,
AST_ELIF = S_AST_NONE | 0x0006,
AST_ELSE = S_AST_NONE | 0x0007,
AST_EMPTY = S_AST_NONE | 0x0008,
AST_LIST = S_AST_NONE | 0x0009,
AST_RAW_STRING = S_AST_NONE | 0x000A,
AST_STRING = S_AST_NONE | 0x000B,
AST_WORD = S_AST_NONE | 0x000C,
AST_FUNCTION_DEFINITION = S_AST_NONE | 0x000D,
AST_VARIABLE_ASSIGNMENT = S_AST_NONE | 0x000E,
AST_FILE_REDIRECTION = S_AST_REDIRECT | 0x000F,
AST_HEREDOC_REDIRECTION = S_AST_REDIRECT | 0x0010,
AST_FOR = S_AST_COMPOUND_COMMAND | 0x0011,
AST_CASE = S_AST_COMPOUND_COMMAND | 0x0012,
AST_COMPOUND_STATEMENT = S_AST_COMPOUND_COMMAND | 0x0013,
AST_IF = S_AST_COMPOUND_COMMAND | 0x0014,
AST_PIPELINE = S_AST_COMPOUND_COMMAND | 0x00015,
AST_SUBSHELL = S_AST_COMPOUND_COMMAND | 0x00016,
AST_UNTIL = S_AST_COMPOUND_COMMAND | 0x0017,
AST_WHILE = S_AST_COMPOUND_COMMAND | 0x0018,
}; };
union u_ast_node_data { union u_ast_node_data {
@ -69,7 +80,6 @@ union u_ast_node_data {
t_ast_subshell subshell; t_ast_subshell subshell;
t_ast_until until; t_ast_until until;
t_ast_variable_assignment variable_assignment; t_ast_variable_assignment variable_assignment;
t_ast_while while_;
t_ast_word word; t_ast_word word;
}; };
@ -79,4 +89,14 @@ struct s_ast_node
t_ast_node_data data; t_ast_node_data data;
}; };
static inline bool ast_category(t_ast_node node)
{
return (node->kind & S_AST_CATEGORY_MASK);
}
static inline bool ast_nodetype(t_ast_node node)
{
return (node->kind & S_AST_NODETYPE_MASK);
}
#endif /* AST_H */ #endif /* AST_H */

View file

@ -53,7 +53,6 @@ enum e_ast_word_kind
AST_WORD_NO_QUOTE, AST_WORD_NO_QUOTE,
AST_WORD_SINGLE_STRING, AST_WORD_SINGLE_STRING,
AST_WORD_DOUBLE_QUOTED, AST_WORD_DOUBLE_QUOTED,
AST_WORD_BACK_QUOTED,
}; };
struct s_ast_raw_string struct s_ast_raw_string

View file

@ -1 +1,3 @@
empty empty
from_node
not_done_function

154
ast/src/from_node.c Normal file
View file

@ -0,0 +1,154 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* from_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 12:41:56 by maiboyer #+# #+# */
/* Updated: 2024/06/17 15:04:13 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser/api.h"
#include "ast/ast.h"
#include "gmr/symbols.h"
#include "me/mem/mem.h"
#include "me/types.h"
/*
sym_arithmetic_binary_expression
sym_arithmetic_expansion
sym_arithmetic_literal
sym_arithmetic_parenthesized_expression
sym_arithmetic_postfix_expression
sym_arithmetic_ternary_expression
sym_arithmetic_unary_expression
sym_case_item
sym_case_statement
sym_command
sym_command_name
sym_command_substitution
sym_comment
sym_compound_statement
sym_concatenation
sym_do_group
sym_elif_clause
sym_else_clause
sym_expansion
sym_expansion_expression
sym_expansion_regex
sym_extglob_pattern
sym_file_descriptor
sym_file_redirect
sym_for_statement
sym_function_definition
sym_heredoc_body
sym_heredoc_content
sym_heredoc_end
sym_heredoc_redirect
sym_heredoc_start
sym_if_statement
sym_list
sym_negated_command
sym_number
sym_pipeline
sym_program
sym_raw_string
sym_redirected_statement
sym_regex
sym_simple_expansion
sym_simple_heredoc_body
sym_string
sym_string_content
sym_subshell
sym_variable_assignment
sym_variable_assignments
sym_variable_name
sym_while_statement
sym_word
*/
// t_error build_sym_word(t_parser_node *node, t_ast_node *out);
t_error build_sym_arithmetic_binary_expression(t_parser_node *self, t_ast_node *out);
t_error build_sym_arithmetic_expansion(t_parser_node *self, t_ast_node *out);
t_error build_sym_arithmetic_literal(t_parser_node *self, t_ast_node *out);
t_error build_sym_arithmetic_parenthesized_expression(t_parser_node *self, t_ast_node *out);
t_error build_sym_arithmetic_postfix_expression(t_parser_node *self, t_ast_node *out);
t_error build_sym_arithmetic_ternary_expression(t_parser_node *self, t_ast_node *out);
t_error build_sym_arithmetic_unary_expression(t_parser_node *self, t_ast_node *out);
t_error build_sym_case_item(t_parser_node *self, t_ast_node *out);
t_error build_sym_case_statement(t_parser_node *self, t_ast_node *out);
t_error build_sym_command(t_parser_node *self, t_ast_node *out);
t_error build_sym_command_name(t_parser_node *self, t_ast_node *out);
t_error build_sym_command_substitution(t_parser_node *self, t_ast_node *out);
t_error build_sym_comment(t_parser_node *self, t_ast_node *out);
t_error build_sym_compound_statement(t_parser_node *self, t_ast_node *out);
t_error build_sym_concatenation(t_parser_node *self, t_ast_node *out);
t_error build_sym_do_group(t_parser_node *self, t_ast_node *out);
t_error build_sym_elif_clause(t_parser_node *self, t_ast_node *out);
t_error build_sym_else_clause(t_parser_node *self, t_ast_node *out);
t_error build_sym_expansion(t_parser_node *self, t_ast_node *out);
t_error build_sym_expansion_expression(t_parser_node *self, t_ast_node *out);
t_error build_sym_expansion_regex(t_parser_node *self, t_ast_node *out);
t_error build_sym_extglob_pattern(t_parser_node *self, t_ast_node *out);
t_error build_sym_file_descriptor(t_parser_node *self, t_ast_node *out);
t_error build_sym_file_redirect(t_parser_node *self, t_ast_node *out);
t_error build_sym_for_statement(t_parser_node *self, t_ast_node *out);
t_error build_sym_function_definition(t_parser_node *self, t_ast_node *out);
t_error build_sym_heredoc_body(t_parser_node *self, t_ast_node *out);
t_error build_sym_heredoc_content(t_parser_node *self, t_ast_node *out);
t_error build_sym_heredoc_end(t_parser_node *self, t_ast_node *out);
t_error build_sym_heredoc_redirect(t_parser_node *self, t_ast_node *out);
t_error build_sym_heredoc_start(t_parser_node *self, t_ast_node *out);
t_error build_sym_if_statement(t_parser_node *self, t_ast_node *out);
t_error build_sym_list(t_parser_node *self, t_ast_node *out);
t_error build_sym_negated_command(t_parser_node *self, t_ast_node *out);
t_error build_sym_number(t_parser_node *self, t_ast_node *out);
t_error build_sym_pipeline(t_parser_node *self, t_ast_node *out);
t_error build_sym_program(t_parser_node *self, t_ast_node *out);
t_error build_sym_raw_string(t_parser_node *self, t_ast_node *out);
t_error build_sym_redirected_statement(t_parser_node *self, t_ast_node *out);
t_error build_sym_regex(t_parser_node *self, t_ast_node *out);
t_error build_sym_simple_expansion(t_parser_node *self, t_ast_node *out);
t_error build_sym_simple_heredoc_body(t_parser_node *self, t_ast_node *out);
t_error build_sym_string(t_parser_node *self, t_ast_node *out);
t_error build_sym_string_content(t_parser_node *self, t_ast_node *out);
t_error build_sym_subshell(t_parser_node *self, t_ast_node *out);
t_error build_sym_variable_assignment(t_parser_node *self, t_ast_node *out);
t_error build_sym_variable_assignments(t_parser_node *self, t_ast_node *out);
t_error build_sym_variable_name(t_parser_node *self, t_ast_node *out);
t_error build_sym_while_statement(t_parser_node *self, t_ast_node *out);
t_error build_sym_word(t_parser_node *self, t_ast_node *out);
t_error build_sym_program(t_parser_node *self, t_ast_node *out)
{
t_ast_node ret;
t_usize i;
if (self == NULL || out == NULL)
return (ERROR);
if (self->kind != sym_program)
return (ERROR);
ret = mem_alloc(sizeof(*ret));
i = 0;
ret->kind = AST_COMPOUND_STATEMENT;
while (i < self->childs_count)
{
i++;
}
return (*out = ret, NO_ERROR);
return (mem_free(ret), ERROR);
}
t_error from_node(t_parser_node *node, t_ast_node *out)
{
if (node == NULL || out == NULL)
return (ERROR);
return (build_sym_word(node, out));
return (NO_ERROR);
}

View file

@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* not_done_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/17 13:04:32 by maiboyer #+# #+# */
/* Updated: 2024/06/17 13:09:53 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node.h"
#include "ast/ast.h"
#include "gmr/symbols.h"
#include "me/types.h"
#include <stdio.h>
t_error _build_not_finished(t_parser_node *node, t_ast_node *out)
{
(void)(node);
(void)(out);
printf("building undefined symbol '%s'\n", node->kind_str);
return (ERROR);
}
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_binary_expression(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_expansion(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_literal(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_parenthesized_expression(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_postfix_expression(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_ternary_expression(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_arithmetic_unary_expression(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_case_item(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_case_statement(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command_name(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_command_substitution(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_comment(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_compound_statement(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_concatenation(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_do_group(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_elif_clause(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_else_clause(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion_expression(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_expansion_regex(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_extglob_pattern(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_file_descriptor(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_file_redirect(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_for_statement(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_function_definition(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_body(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_content(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_end(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_redirect(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_heredoc_start(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_if_statement(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_list(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_negated_command(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_number(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_pipeline(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_program(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_raw_string(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_redirected_statement(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_regex(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_expansion(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_simple_heredoc_body(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_string(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_string_content(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_subshell(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_assignment(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_assignments(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_variable_name(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_while_statement(t_parser_node *self, t_ast_node *out);
t_error __attribute__((weak, alias("_build_not_finished"))) build_sym_word(t_parser_node *self, t_ast_node *out);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
/* Updated: 2024/06/09 21:39:11 by maiboyer ### ########.fr */ /* Updated: 2024/06/17 13:27:16 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,6 +28,10 @@
#undef realloc #undef realloc
#undef calloc #undef calloc
#include "ast/ast.h"
t_error from_node();
t_first_parser *ts_parser_new(); t_first_parser *ts_parser_new();
void ts_tree_delete(t_first_tree *); void ts_tree_delete(t_first_tree *);
t_parse_node ts_tree_root_node(t_first_tree *); t_parse_node ts_tree_root_node(t_first_tree *);
@ -153,8 +157,10 @@ void print_node_concat(t_node *self)
void exec_shcat(t_utils *shcat) void exec_shcat(t_utils *shcat)
{ {
t_i32 ret; t_i32 ret;
t_ast_node out;
print_node_data(&shcat->current_node, 0); print_node_data(&shcat->current_node, 0);
from_node(&shcat->current_node, &out);
handle_program(&shcat->current_node, shcat, &ret); handle_program(&shcat->current_node, shcat, &ret);
free_node(shcat->current_node); free_node(shcat->current_node);
(void)ret; (void)ret;