From a47e5ceb6eefdac9c5f5473e1fee0d33a5f4646e Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Thu, 20 Apr 2023 11:05:54 -0300 Subject: ast: Allows recursive nodes Previously, the abstract syntax tree (AST) used static types, meaning that an ast_function_t would always have a ast_return_stmt_t as its body. However, this assumption is not always true, as we may have void functions that do not have a return statement. Additionally, the ast_return_stmt_t always had a number associated with it, but this too is not always the case. To make this possible, I need to perform a few changes in the whole project. One of the main changes is that there is no longer the inheritance hack. That mechanism was replaced by composition and pointers where required for recursive type reference. It is important to mention that I decided to use union type to implement the composition. There is two main advantages in this approach: 1. There is only one function to allocate memory for all kind of nodes. 2. There is no need to cast the data. In summary, this commit introduces changes to support dynamic typing in the AST, by replacing the inheritance hack with composition and using union types to simplify memory allocation and type casting. Signed-off-by: Carlos Maniero Reviewed-by: Johnny Richard --- src/parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parser.h') diff --git a/src/parser.h b/src/parser.h index b846ae1..988006e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -27,7 +27,7 @@ typedef struct parser_t { void parser_init(parser_t *parser, lexer_t *lexer); -ast_function_t parser_parse_function(parser_t *parser); +void parser_parse_function_declaration(parser_t *parser, ast_node_t *node); #endif /* PARSER_H */ -- cgit v1.2.3