lang: fix a bunch of compiler warnings

This commit is contained in:
2024-11-27 22:45:34 +00:00
parent 9df8474515
commit 7f9894d8f9
5 changed files with 39 additions and 21 deletions

View File

@@ -2,8 +2,8 @@
#include "node.h"
#include <blue/object/string.h>
#include <ivy/lang/operator.h>
#include <ivy/lang/lex.h>
#include <ivy/lang/operator.h>
#include <stdio.h>
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);
}

View File

@@ -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

View File

@@ -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(

View File

@@ -2,6 +2,7 @@
#define IVY_LANG_AST_H_
#include <blue/core/queue.h>
#include <ivy/lang/operator.h>
#include <ivy/misc.h>
#include <ivy/status.h>
@@ -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);

View File

@@ -1,10 +1,23 @@
#include <ivy/lang/operator.h>
#include <ivy/lang/lex.h>
#include <ivy/lang/operator.h>
#include <stddef.h>
#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;
}
}