Skip to content
ast_destruct.c 1.07 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
** ast_destruct.c for 42sh
**
** Made by Seblu
** Login   <seblu@epita.fr>
**
** Started on  Sat Mar 25 23:11:01 2006 Seblu
Seblu's avatar
Seblu committed
** Last update Tue Aug 29 00:06:45 2006 Seblu
Seblu's avatar
Seblu committed
*/

#include "ast.h"

Seblu's avatar
Seblu committed
#define NODE_TYPE_COUNT 14

typedef void (*destruct_fct)(s_ast_node *);

struct		ast_destruct_switch
{
  e_node_type	type;
  destruct_fct	fct;
};

struct ast_destruct_switch destruction_table[NODE_TYPE_COUNT] =
  {
    {T_IF, ast_if_destruct},
    {T_FOR, ast_for_destruct},
    {T_WHILE, ast_while_destruct},
    {T_UNTIL, ast_until_destruct},
    {T_CMD, ast_cmd_destruct},
    {T_AND, ast_and_destruct},
    {T_OR, ast_or_destruct},
    {T_SUBSHELL, ast_subshell_destruct},
    {T_FUNCDEC, ast_funcdec_destruct},
    {T_BANG, ast_bang_destruct},
    {T_PIPE, ast_pipe_destruct},
    {T_SEPAND, ast_sepand_destruct},
    {T_SEP, ast_sep_destruct},
    {T_CASE, ast_sepand_destruct}
  };

void	ast_destruct(s_ast_node *ast)
Seblu's avatar
Seblu committed
{
  if (ast == NULL)
    return;
Seblu's avatar
Seblu committed
  for (register int i = 0; i < NODE_TYPE_COUNT; ++i)
    if (destruction_table[i].type == ast->type)
      (destruction_table[i].fct)(ast);
Seblu's avatar
Seblu committed
}