From 7f9894d8f941c7911636fa2d973f12a2ddad3fac Mon Sep 17 00:00:00 2001 From: Max Wash Date: Wed, 27 Nov 2024 22:45:34 +0000 Subject: [PATCH] lang: fix a bunch of compiler warnings --- lang/ast/expr.c | 24 ++++++++++++++---------- lang/ast/node.c | 4 ++-- lang/ast/node.h | 4 ++-- lang/include/ivy/lang/ast.h | 4 ++-- lang/operator.c | 24 +++++++++++++++++++----- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lang/ast/expr.c b/lang/ast/expr.c index 7f598c6..c1bf33f 100644 --- a/lang/ast/expr.c +++ b/lang/ast/expr.c @@ -2,8 +2,8 @@ #include "node.h" #include -#include #include +#include #include enum expr_end { @@ -94,7 +94,8 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state) int i = 0; b_queue_foreach (&it, &state->s_operand_queue) { - struct ivy_token *operand = b_unbox(struct ivy_token, it.entry, t_entry); + struct ivy_token *operand + = b_unbox(struct ivy_token, it.entry, t_entry); if (i > 0) { printf(" "); @@ -105,7 +106,8 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state) } b_queue_foreach (&it, &state->s_operator_stack) { - struct ivy_token *operator = b_unbox(struct ivy_token, it.entry, t_entry); + struct ivy_token *operator= b_unbox( + struct ivy_token, it.entry, t_entry); if (i > 0) { printf(" "); @@ -212,11 +214,11 @@ static struct token_parse_result parse_double( b_queue_push_back(&state->s_operand_queue, &tok->t_entry); set_previous(state, tok); - + return PARSE_RESULT(IVY_OK, 0); } -static struct ivy_operator *get_operator(struct ivy_token *tok) +static const struct ivy_operator *get_operator(struct ivy_token *tok) { switch (tok->t_type) { case IVY_TOK_KEYWORD: @@ -238,7 +240,7 @@ static struct token_parse_result parse_symbol( return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); } - struct ivy_operator *op = ivy_operator_get(tok->t_symbol); + const struct ivy_operator *op = ivy_operator_get(tok->t_symbol); if (!op) { return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0); } @@ -250,17 +252,19 @@ static struct token_parse_result parse_symbol( break; } - struct ivy_token *top = b_unbox(struct ivy_token, top_entry, t_entry); + struct ivy_token *top + = b_unbox(struct ivy_token, top_entry, t_entry); if (ivy_token_is_symbol(top, IVY_SYM_LEFT_PAREN)) { break; } - struct ivy_operator *top_op = get_operator(top); + const struct ivy_operator *top_op = get_operator(top); if (top_op->op_precedence < op->op_precedence) { break; } - if (top_op->op_precedence == op->op_precedence && op->op_associativity != IVY_ASSOCIATIVITY_LEFT) { + if (top_op->op_precedence == op->op_precedence + && op->op_associativity != IVY_ASSOCIATIVITY_LEFT) { break; } @@ -286,7 +290,7 @@ static struct token_parse_result parse_left_paren( b_queue_push_back(&state->s_operator_stack, &tok->t_entry); set_previous(state, tok); - + return PARSE_RESULT(IVY_OK, 0); } diff --git a/lang/ast/node.c b/lang/ast/node.c index 4760d0b..3419503 100644 --- a/lang/ast/node.c +++ b/lang/ast/node.c @@ -33,7 +33,7 @@ const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type) return node_ops[type]; } -enum tok_expr_type get_tok_expr_type(struct ivy_token *tok) +enum token_expr_type get_token_expr_type(struct ivy_token *tok) { switch (tok->t_type) { case IVY_TOK_IDENT: @@ -136,7 +136,7 @@ token_parse_function get_token_parser( return better_parser; } - enum token_expr_type expr_type = get_tok_expr_type(tok); + enum token_expr_type expr_type = get_token_expr_type(tok); switch (expr_type) { case TOK_EXPR_BEGIN: better_parser = type->n_expr_parser.expr_begin diff --git a/lang/ast/node.h b/lang/ast/node.h index 7d29fda..c050a25 100644 --- a/lang/ast/node.h +++ b/lang/ast/node.h @@ -16,7 +16,7 @@ enum token_parse_flags { PARSE_REPEAT_TOKEN = 0x01u, }; -enum tok_expr_type { +enum token_expr_type { TOK_EXPR_NONE = 0, TOK_EXPR_BEGIN, TOK_EXPR_ANY, @@ -54,7 +54,7 @@ struct ast_node_type { extern const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type); extern token_parse_function get_token_parser( struct ivy_ast_node *context, struct ivy_token *tok); -extern enum tok_expr_type get_tok_expr_type(struct ivy_token *tok); +extern enum token_expr_type get_token_expr_type(struct ivy_token *tok); extern struct ivy_ast_node *ast_node_create_with_size( enum ivy_ast_node_type type, size_t size); extern enum ivy_status ast_node_add_child( diff --git a/lang/include/ivy/lang/ast.h b/lang/include/ivy/lang/ast.h index e38bbd1..d9919fe 100644 --- a/lang/include/ivy/lang/ast.h +++ b/lang/include/ivy/lang/ast.h @@ -2,6 +2,7 @@ #define IVY_LANG_AST_H_ #include +#include #include #include @@ -65,7 +66,7 @@ struct ivy_ast_unit_node { struct ivy_ast_op_node { struct ivy_ast_node n_base; - enum ivy_ast_op n_op; + enum ivy_operator_id n_op; struct ivy_ast_node *n_left; // NULL for unary operators. struct ivy_ast_node *n_right; }; @@ -248,7 +249,6 @@ IVY_API void ivy_ast_node_print(struct ivy_ast_node *node); IVY_API void ivy_ast_node_destroy(struct ivy_ast_node *node); IVY_API const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v); -IVY_API const char *ivy_ast_op_to_string(enum ivy_ast_op v); IVY_API const char *ivy_ast_msgh_recipient_type_to_string( enum ivy_ast_msgh_recipient_type v); diff --git a/lang/operator.c b/lang/operator.c index d1216b5..a004a12 100644 --- a/lang/operator.c +++ b/lang/operator.c @@ -1,10 +1,23 @@ -#include #include +#include #include -#define SYM_OP(id, t, p, a) [IVY_SYM_ ## t] = { .op_id = (IVY_OP_ ## id), .op_token = (IVY_SYM_ ## t), .op_precedence = (IVY_PRECEDENCE_ ## p), .op_associativity = (IVY_ASSOCIATIVITY_ ## a) } -#define KW_OP(id, t, p, a) [IVY_KW_ ## t] = { .op_id = (IVY_OP_ ## id), .op_token = (IVY_KW_ ## t), .op_precedence = (IVY_PRECEDENCE_ ## p), .op_associativity = (IVY_ASSOCIATIVITY_ ## a) } +#define SYM_OP(id, t, p, a) \ + [IVY_SYM_##t] = { \ + .op_id = (IVY_OP_##id), \ + .op_token = (IVY_SYM_##t), \ + .op_precedence = (IVY_PRECEDENCE_##p), \ + .op_associativity = (IVY_ASSOCIATIVITY_##a), \ + } +#define KW_OP(id, t, p, a) \ + [IVY_KW_##t] = { \ + .op_id = (IVY_OP_##id), \ + .op_token = (IVY_KW_##t), \ + .op_precedence = (IVY_PRECEDENCE_##p), \ + .op_associativity = (IVY_ASSOCIATIVITY_##a), \ + } +/* clang-format off */ static const struct ivy_operator operators[] = { SYM_OP(ASSIGN, EQUAL, ASSIGN, RIGHT), SYM_OP(ADD, PLUS, ADDITION, LEFT), @@ -43,6 +56,7 @@ static const struct ivy_operator operators[] = { SYM_OP(PKG_ACCESS, HYPHEN_RIGHT_ANGLE, SUBSCRIPT, LEFT), }; static const size_t nr_operators = sizeof operators / sizeof operators[0]; +/* clang-format on */ const struct ivy_operator *ivy_operator_get(unsigned int token) { @@ -50,10 +64,10 @@ const struct ivy_operator *ivy_operator_get(unsigned int token) return NULL; } - struct ivy_operator *op = &operators[token]; + const struct ivy_operator *op = &operators[token]; if (op->op_token != token) { return NULL; } return op; -} \ No newline at end of file +}