From 75639fbf01bd6ae1212521b6cf822025eb8b598d Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Wed, 10 May 2023 16:07:39 -0300 Subject: namespaces: Add a namespace structure that represents a file We have been always parsing a single function. Since we want to have multiple functions in a near future, this patch introduces an namespace that represents an entire file. To ensure a function is defined inside a namespace, a helper function was created. Today our ast_node structure is highly exposed, and this is something that Johnny and I have been discussed. So then, this is a first step to try to protected the code generation from our ast tree. Signed-off-by: Carlos Maniero --- src/ast.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index b2c565c..7d2d2f1 100644 --- a/src/ast.h +++ b/src/ast.h @@ -29,6 +29,11 @@ typedef enum typedef struct ast_node_t ast_node_t; +typedef struct ast_namespace_t +{ + vector_t *nodes; +} ast_namespace_t; + typedef struct ast_block_t { vector_t *body; @@ -119,6 +124,7 @@ typedef struct ast_if_stmt_t typedef enum { + AST_NAMESPACE, AST_BINARY_OPERATION, AST_BLOCK, AST_FUNCTION_DECLARATION, @@ -133,6 +139,7 @@ typedef enum typedef union { + ast_namespace_t ns; ast_binary_operation_t binary_operation; ast_function_declaration_t function; ast_literal_t literal; @@ -163,6 +170,9 @@ ast_node_destroy_vector(vector_t *vector); void ast_node_destroy(ast_node_t *node); +ast_node_t * +ast_node_new_namespace(vector_t *nodes); + ast_node_t * ast_node_new_binary_operation(ast_binary_operation_kind_t kind, ast_node_t *left, @@ -196,4 +206,10 @@ ast_node_new_variable_assignment(ast_identifier_t *identifier, ast_node_t *expre ast_node_t * ast_node_new_if_stmt(ast_node_t *condition, ast_node_t *body); +ast_node_t * +ast_node_ns_get_function_node_by_sv(ast_node_t *ns, string_view_t name); + +ast_node_t * +ast_node_ns_get_function_node_by_name(ast_node_t *ns, char *function_name); + #endif /* AST_H */ -- cgit v1.2.3