diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-29 20:49:51 +0200 |
---|---|---|
committer | Carlos Maniero <carlosmaniero@gmail.com> | 2023-04-29 15:57:15 -0300 |
commit | 3bc44f85de340c8da88d74b561b75716162d84d0 (patch) | |
tree | aba9d34bdbfb199a705bb0d15e7185ca7fe83a8c /src/ast.h | |
parent | cd77ac7997fa956c1d67ef91cde056e817aa16c7 (diff) |
ast: Remove ast visitor pattern to simplify the code
I decided to remove the visitor pattern due to the lack of Object
Oriented Programming support for C. Now if you want to navigate through
the AST, you should do it with switch case and recursion.
The code looks way simpler without visitor pattern.
I have added a CFLAG -Werror which validates if the switch statement
covers all branches for a given enum at compile time.
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/ast.h')
-rw-r--r-- | src/ast.h | 15 |
1 files changed, 0 insertions, 15 deletions
@@ -20,14 +20,11 @@ #include "vector.h" #include <stdint.h> -#define ast_visitor_visit(visitor, node) ast_node_accept_visitor(node, (ast_visitor_t *)visitor); - typedef enum { TYPE_I32 } type_t; -typedef struct ast_visitor_t ast_visitor_t; typedef struct ast_node_t ast_node_t; typedef struct ast_return_stmt_t @@ -85,14 +82,6 @@ typedef struct ast_variable_declaration_t ast_node_t *value; } ast_variable_declaration_t; -typedef struct ast_visitor_t -{ - void (*visit_function)(struct ast_visitor_t *, ast_function_declaration_t *); - void (*visit_return_stmt)(struct ast_visitor_t *, ast_return_stmt_t *); - void (*visit_literal)(struct ast_visitor_t *, ast_literal_t *); - void (*visit_binary_operation)(struct ast_visitor_t *, ast_binary_operation_t *); -} ast_visitor_t; - typedef enum { AST_BINARY_OPERATION, @@ -116,14 +105,10 @@ typedef union typedef struct ast_node_t { - void (*accept_visitor)(ast_node_t *, ast_visitor_t *); ast_node_kind_t kind; ast_node_data_t data; } ast_node_t; -void -ast_node_accept_visitor(ast_node_t *node, ast_visitor_t *visitor); - ast_node_t * ast_node_new(); void |