feat: toujours les mêmes qui font les pipes. Plus de assert dans ASTs (pour des raisons évidentes de stabilité du code) et nouveaux types (AST_PIPE et AST_NEG), + modifs random dans le parser
This commit is contained in:
parent
07e7d83c60
commit
96626d9850
27 changed files with 238 additions and 86 deletions
|
|
@ -2,7 +2,6 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "ast.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -11,18 +10,45 @@
|
|||
void ast_free(struct ast **node)
|
||||
{
|
||||
if (node == NULL || *node == NULL)
|
||||
{
|
||||
puts(
|
||||
"WARNING: Internal error: failed to free AST node (NULL argument)");
|
||||
return;
|
||||
// ast void does not need to be freed.
|
||||
if (ast_is_if(*node))
|
||||
}
|
||||
|
||||
switch ((*node)->type)
|
||||
{
|
||||
case AST_IF:
|
||||
ast_free_if(ast_get_if(*node));
|
||||
else if (ast_is_command(*node))
|
||||
break;
|
||||
case AST_CMD:
|
||||
ast_free_command(ast_get_command(*node));
|
||||
else if (ast_is_list(*node))
|
||||
break;
|
||||
case AST_LIST:
|
||||
ast_free_list(ast_get_list(*node));
|
||||
else if (ast_is_and_or(*node))
|
||||
break;
|
||||
case AST_AND_OR:
|
||||
ast_free_and_or(ast_get_and_or(*node));
|
||||
else if (ast_is_redir(*node))
|
||||
break;
|
||||
case AST_REDIR:
|
||||
ast_free_redir(ast_get_redir(*node));
|
||||
break;
|
||||
case AST_PIPE:
|
||||
ast_free_pipe(ast_get_pipe(*node));
|
||||
break;
|
||||
case AST_WORD:
|
||||
ast_free_word(ast_get_word(*node));
|
||||
break;
|
||||
|
||||
case AST_VOID:
|
||||
case AST_END:
|
||||
break;
|
||||
|
||||
default:
|
||||
puts("WARNING: Internal error: failed to free an AST node (Unknown "
|
||||
"type)");
|
||||
return;
|
||||
}
|
||||
|
||||
free(*node);
|
||||
*node = NULL;
|
||||
|
|
@ -40,6 +66,7 @@ struct ast *ast_create(enum ast_type type, void *data)
|
|||
return node;
|
||||
}
|
||||
|
||||
// TODO handle new types (AST_WORD, AST_PIPE, etc.)
|
||||
static void ast_print_dot_recursive(struct ast *node, FILE *out)
|
||||
{
|
||||
if (!node)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue