From 2eb59ee61e49b60472f82c000dd4f3536bd1987c Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 1 Apr 2020 15:55:57 +0200 Subject: Added builtin support in command eval, Refactoring eval/builtin function, Added doc --- src/ast.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src/ast.c') diff --git a/src/ast.c b/src/ast.c index 7c3fb8f..12761ac 100644 --- a/src/ast.c +++ b/src/ast.c @@ -1,5 +1,18 @@ +/** +** \file ast.c +** \brief AST functions +*/ + #include "ast.h" +/** +** \brief Create a new AST node according to `tag` +** \param tag Tag of node +** \param data Pointer to node data (t_cmd or t_line) +** which will be copied in ast::data union +** \return Created node or NULL on error +*/ + t_ast *ast_new(t_ast_tag tag, void *data) { t_ast *ast; @@ -17,26 +30,25 @@ t_ast *ast_new(t_ast_tag tag, void *data) return (ast); } -static void cmd_destroy(t_cmd *cmd) -{ - ft_split_destroy(cmd->argv); - free(cmd->in); - free(cmd->out); -} - -static void line_destroy(t_line *line) -{ - ast_destroy(line->left); - ast_destroy(line->right); -} +/** +** \brief Destroy an AST node and all his child nodes +** \param ast AST to destroy +*/ void ast_destroy(t_ast *ast) { if (ast == NULL) return ; if (ast->tag == TAG_CMD) - cmd_destroy(&ast->data.cmd); + { + ft_split_destroy(ast->data.cmd.argv); + free(ast->data.cmd.in); + free(ast->data.cmd.out); + } else if (ast->tag == TAG_LINE) - line_destroy(&ast->data.line); + { + ast_destroy(ast->data.line.left); + ast_destroy(ast->data.line.right); + } free(ast); } -- cgit