From 0b0ce0d1735b4358691fb1d4a85b550d45ae9d48 Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Tue, 2 May 2023 23:45:56 -0300 Subject: ast: Replace init by allocation (new) functions All parsers have been following the patterns bellow: ast_node_t *node = ast_node_new(); ast_node_init_node_kind(node, ...args); return node; Bringing a uncessessary distraction when reading. The pattern bellow was replaced by: return ast_node_new_node_kind(...args); Signed-off-by: Carlos Maniero --- src/ast.h | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src/ast.h') diff --git a/src/ast.h b/src/ast.h index fb2bb74..e541390 100644 --- a/src/ast.h +++ b/src/ast.h @@ -127,20 +127,25 @@ ast_node_new(void); void ast_node_destroy(ast_node_t *node); -void -ast_node_init_binary_operation(ast_node_t *node, ast_binary_operation_kind_t kind, ast_node_t *left, ast_node_t *right); -void -ast_node_init_function_declaration(ast_node_t *node, string_view_t function_name, type_t return_type, vector_t *body); -void -ast_node_init_return_stmt(ast_node_t *node, ast_node_t *argument); -void -ast_node_init_variable_declaration(ast_node_t *node, string_view_t variable_name, type_t type, ast_node_t *value); -// FIXME: use the naming convention -void -ast_literal_integer_create(ast_node_t *node, uint32_t number); -void -ast_node_init_variable(ast_node_t *node, ast_identifier_t *identifier); -void -ast_node_init_variable_assignment(ast_node_t *node, ast_identifier_t *identifier, ast_node_t *expression); +ast_node_t * +ast_node_new_binary_operation(ast_binary_operation_kind_t kind, ast_node_t *left, ast_node_t *right); + +ast_node_t * +ast_node_new_function_declaration(string_view_t function_name, type_t return_type, vector_t *body); + +ast_node_t * +ast_node_new_return_stmt(ast_node_t *argument); + +ast_node_t * +ast_node_new_variable_declaration(string_view_t variable_name, type_t type, ast_node_t *value); + +ast_node_t * +ast_node_new_literal_integer(uint32_t number); + +ast_node_t * +ast_node_new_variable(ast_identifier_t *identifier); + +ast_node_t * +ast_node_new_variable_assignment(ast_identifier_t *identifier, ast_node_t *expression); #endif /* AST_H */ -- cgit v1.2.3