summaryrefslogtreecommitdiff
path: root/src/ast.h
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-08 23:53:42 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-05-09 21:46:51 +0200
commit35425aa5837543e4cc3fc82266dc2ae429cb2779 (patch)
tree1d7dec87dc17785162c20206371818f5e28fd99b /src/ast.h
parent3842de0e22d72075f06bd8cc44b8744e86c21725 (diff)
parser: Ensure the expression types
When assign a variable or returning a value it now ensures that the expression matches the expected type. To make this possible a %result_type% field was added to ast_node_t and this field is used whenever to make the comparison. Signed-off-by: Carlos Maniero <carlos@maniero.me> Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/ast.h')
-rw-r--r--src/ast.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/ast.h b/src/ast.h
index 80148dc..f91632c 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -23,7 +23,8 @@
typedef enum
{
TYPE_I32,
- TYPE_BOOL
+ TYPE_BOOL,
+ TYPE_VOID,
} type_t;
typedef struct ast_node_t ast_node_t;
@@ -124,8 +125,12 @@ typedef struct ast_node_t
{
ast_node_kind_t kind;
ast_node_data_t data;
+ type_t result_type;
} ast_node_t;
+char *
+ast_type_to_str(type_t type);
+
ast_node_t *
ast_node_new(void);
@@ -136,7 +141,10 @@ void
ast_node_destroy(ast_node_t *node);
ast_node_t *
-ast_node_new_binary_operation(ast_binary_operation_kind_t kind, ast_node_t *left, ast_node_t *right);
+ast_node_new_binary_operation(ast_binary_operation_kind_t kind,
+ ast_node_t *left,
+ ast_node_t *right,
+ type_t result_type);
ast_node_t *
ast_node_new_function_declaration(string_view_t function_name, type_t return_type, vector_t *body);
@@ -154,7 +162,7 @@ ast_node_t *
ast_node_new_literal_bool(bool boolean);
ast_node_t *
-ast_node_new_variable(ast_identifier_t *identifier);
+ast_node_new_variable(ast_identifier_t *identifier, type_t result_type);
ast_node_t *
ast_node_new_variable_assignment(ast_identifier_t *identifier, ast_node_t *expression);