diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-26 00:40:44 +0200 |
---|---|---|
committer | Carlos Maniero <carlosmaniero@gmail.com> | 2023-04-25 23:19:13 -0300 |
commit | 127dae1c3b48c3a4dceddb9000309bfeaa8d0a01 (patch) | |
tree | 4d92b3a7b4c29f0ace3a5ff699e4789f60b0aa46 /src/ast.c | |
parent | c1a1bd2320b4c1508c4ab20d23b7c193a94d8026 (diff) |
style: Use clang-format as formatter and linter tool
We want to keep the code style consistent, this first commit adds a
.clang-format in order to "document" our style code.
This patch also adds a target *linter* to Makefile which will complain
if we have any style issue on test and src dirs.
I have run the follow command to create the .clang-format file:
$ clang-format -style=mozilla -dump-config > .clang-format
And I also made some adjusts to .clang-format changing the following
properties:
PointerAlignment: Right
ColumnLimit: 120
Commands executed to fix the current styling:
$ find . -name *.h | xargs clang-format -i
$ find . -name *.c | xargs clang-format -i
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/ast.c')
-rw-r--r-- | src/ast.c | 87 |
1 files changed, 27 insertions, 60 deletions
@@ -1,23 +1,23 @@ /* -* Copyright (C) 2023 Johnny Richard -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ + * Copyright (C) 2023 Johnny Richard + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +#include "ast.h" #include <assert.h> #include <stdio.h> #include <stdlib.h> -#include "ast.h" void ast_node_accept_visitor(ast_node_t *node, ast_visitor_t *visitor) @@ -55,10 +55,10 @@ ast_node_binary_operation_visitor(ast_node_t *node, ast_visitor_t *visitor) visitor->visit_binary_operation(visitor, &node->data.binary_operation); } -ast_node_t* +ast_node_t * ast_node_new() { - ast_node_t *node = (ast_node_t*) malloc(sizeof(ast_node_t)); + ast_node_t *node = (ast_node_t *)malloc(sizeof(ast_node_t)); if (node == NULL) { printf("OOO: could no allocate a node"); exit(EXIT_FAILURE); @@ -70,7 +70,7 @@ ast_node_new() static void ast_node_destroy_vector(vector_t *vector) { - for (size_t i=0; i < vector->size; i++) { + for (size_t i = 0; i < vector->size; i++) { ast_node_destroy(vector_at(vector, i)); } vector_destroy(vector); @@ -108,27 +108,17 @@ ast_node_destroy(ast_node_t *node) void ast_node_init_return_stmt(ast_node_t *node, ast_node_t *argument) { - node->accept_visitor = &ast_node_return_stmt_accept_visitor, + node->accept_visitor = &ast_node_return_stmt_accept_visitor; node->kind = AST_RETURN_STMT; - node->data = (ast_node_data_t) { - .return_stmt = { - .argument = argument - } - }; + node->data.return_stmt = (ast_return_stmt_t){ .argument = argument }; } void ast_node_init_function_declaration(ast_node_t *node, string_view_t name, type_t return_type, vector_t *body) { - node->accept_visitor = &ast_node_function_accept_visitor, + node->accept_visitor = &ast_node_function_accept_visitor; node->kind = AST_FUNCTION_DECLARATION; - node->data = (ast_node_data_t) { - .function = { - .name = name, - .return_type = return_type, - .body = body - } - }; + node->data = (ast_node_data_t){ .function = { .name = name, .return_type = return_type, .body = body } }; } void @@ -136,14 +126,7 @@ ast_literal_integer_create(ast_node_t *node, uint32_t number) { node->accept_visitor = &ast_node_literal_visitor; node->kind = AST_LITERAL; - node->data = (ast_node_data_t) { - .literal = { - .kind = AST_LITERAL_INTEGER, - .value = { - .integer = number - } - } - }; + node->data.literal = (ast_literal_t){ .kind = AST_LITERAL_INTEGER, .value = { .integer = number } }; } void @@ -151,13 +134,7 @@ ast_node_init_binary_operation(ast_node_t *node, string_view_t op, ast_node_t *l { node->accept_visitor = &ast_node_binary_operation_visitor; node->kind = AST_BINARY_OPERATION; - node->data = (ast_node_data_t) { - .binary_operation = { - .op = op, - .left = left, - .right = right - } - }; + node->data = (ast_node_data_t){ .binary_operation = { .op = op, .left = left, .right = right } }; } void @@ -165,13 +142,7 @@ ast_node_init_variable_declaration(ast_node_t *node, string_view_t variable_name { // FIXME: define the visitor strategy node->kind = AST_VARIABLE_DECLARATION; - node->data = (ast_node_data_t) { - .variable = { - .name = variable_name, - .type = type, - .value = value - } - }; + node->data = (ast_node_data_t){ .variable = { .name = variable_name, .type = type, .value = value } }; } void @@ -179,9 +150,5 @@ ast_node_init_identifier(ast_node_t *node, string_view_t name) { // FIXME: define the visitor strategy node->kind = AST_IDENTIFIER; - node->data = (ast_node_data_t) { - .variable = { - .name = name, - } - }; + node->data.identifier = (ast_identifier_t){ .name = name }; } |