feat: ast_subshell
This commit is contained in:
parent
bb7d4b772e
commit
5eed5fa65f
5 changed files with 54 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ libutils_a_SOURCES = \
|
||||||
args/args.c \
|
args/args.c \
|
||||||
vars/vars.c \
|
vars/vars.c \
|
||||||
ast/ast_assignment.c \
|
ast/ast_assignment.c \
|
||||||
|
ast/ast_subshell.c \
|
||||||
ast/ast_function.c
|
ast/ast_function.c
|
||||||
|
|
||||||
libutils_a_CPPFLAGS = -I$(top_srcdir)/src
|
libutils_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,6 @@
|
||||||
#include "ast_redir.h"
|
#include "ast_redir.h"
|
||||||
#include "ast_void.h"
|
#include "ast_void.h"
|
||||||
#include "ast_word.h"
|
#include "ast_word.h"
|
||||||
|
#include "ast_subshell.h"
|
||||||
|
|
||||||
#endif /* ! AST_H */
|
#endif /* ! AST_H */
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ enum ast_type
|
||||||
AST_NEG,
|
AST_NEG,
|
||||||
AST_LOOP,
|
AST_LOOP,
|
||||||
AST_ASSIGNMENT,
|
AST_ASSIGNMENT,
|
||||||
AST_FUNCTION
|
AST_FUNCTION,
|
||||||
|
AST_SUBSHELL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ast
|
struct ast
|
||||||
|
|
|
||||||
31
src/utils/ast/ast_subshell.c
Normal file
31
src/utils/ast/ast_subshell.c
Normal 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);
|
||||||
|
}
|
||||||
19
src/utils/ast/ast_subshell.h
Normal file
19
src/utils/ast/ast_subshell.h
Normal 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 */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue