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

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