feat: ast_subshell

This commit is contained in:
matteo 2026-01-31 19:25:42 +01:00
parent bb7d4b772e
commit 5eed5fa65f
5 changed files with 54 additions and 1 deletions

View file

@ -21,6 +21,7 @@ libutils_a_SOURCES = \
args/args.c \
vars/vars.c \
ast/ast_assignment.c \
ast/ast_subshell.c \
ast/ast_function.c
libutils_a_CPPFLAGS = -I$(top_srcdir)/src

View file

@ -15,5 +15,6 @@
#include "ast_redir.h"
#include "ast_void.h"
#include "ast_word.h"
#include "ast_subshell.h"
#endif /* ! AST_H */

View file

@ -18,7 +18,8 @@ enum ast_type
AST_NEG,
AST_LOOP,
AST_ASSIGNMENT,
AST_FUNCTION
AST_FUNCTION,
AST_SUBSHELL
};
struct ast

View file

@ -0,0 +1,31 @@
#include "ast_subshell.h"
bool ast_is_subshell(struct ast *node)
{
return node != NULL && node->type == AST_SUBSHELL;
}
struct ast_subshell *ast_get_subshell(struct ast *node)
{
if (ast_is_subshell(node))
return (struct ast_subshell *)node->data;
return NULL;
}
struct ast *ast_create_subshell(struct ast *child)
{
struct ast_subshell *subshell = calloc(1, sizeof(struct ast_subshell));
if (subshell == NULL)
return NULL;
subshell->child = child;
return ast_create(AST_SUBSHELL, subshell);
}
void ast_free_subshell(struct ast_subshell *subshell)
{
if (!subshell)
return;
ast_free(&subshell->child);
free(subshell);
}

View file

@ -0,0 +1,19 @@
#ifndef AST_SUBSHELL_H
#define AST_SUBSHELL_H
#include "ast_base.h"
struct ast_subshell
{
struct ast *child;
};
bool ast_is_subshell(struct ast *node);
struct ast_subshell *ast_get_subshell(struct ast *node);
struct ast *ast_create_subshell(struct ast *child);
void ast_free_subshell(struct ast_subshell *subshell);
#endif /* ! AST_SUBSHELL_H */