From 807416940c25728e236041f0e2f30ee0a98f36fb Mon Sep 17 00:00:00 2001 From: "william.valenduc" Date: Fri, 9 Jan 2026 22:36:48 +0000 Subject: [PATCH] feat(ast): data as void* and basic helpers --- src/utils/ast/ast.c | 23 +++++++++++++++++++++++ src/utils/ast/ast.h | 23 +++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/utils/ast/ast.c b/src/utils/ast/ast.c index e69de29..93fa402 100644 --- a/src/utils/ast/ast.c +++ b/src/utils/ast/ast.c @@ -0,0 +1,23 @@ +#include "ast.h" + +#include + +bool ast_is_if(struct ast *node) +{ + return node->type == AST_IF; +} + +bool ast_is_cmd(struct ast *node) +{ + return node->type == AST_CMD; +} + +struct ast_if *ast_get_if(struct ast *node) +{ + return (struct ast_if *)node->data; +} + +struct ast_cmd *ast_get_cmd(struct ast *node) +{ + return (struct ast_cmd *)node->data; +} diff --git a/src/utils/ast/ast.h b/src/utils/ast/ast.h index 8e01551..c68b143 100644 --- a/src/utils/ast/ast.h +++ b/src/utils/ast/ast.h @@ -5,7 +5,7 @@ enum ast_type { - AST_END = 0, + AST_END, AST_IF, AST_CMD }; @@ -15,14 +15,6 @@ struct ast_cmd struct list *cmd; }; -union ast_node; - -struct ast -{ - enum ast_type type; - union ast_node *data; -}; - struct ast_if { struct ast *condition; @@ -30,10 +22,17 @@ struct ast_if struct ast *else_clause; }; -union ast_node +struct ast { - struct ast_if *ast_if; - struct ast_cmd *ast_cmd; + enum ast_type type; + + /** + * Data associated with this AST node. It can be one of the following: + * - NULL (AST_END) + * - struct ast_if* (AST_IF) + * - struct ast_cmd* (AST_CMD) + */ + void *data; }; #endif /* ! AST_H */