lang: fix lots of compiler warnings/errors

This commit is contained in:
2024-12-01 13:25:36 +00:00
parent bb34e46c69
commit b5cb87e8df
8 changed files with 90 additions and 52 deletions

View File

@@ -65,7 +65,8 @@ static void print_operand(struct ivy_ast_node *node)
{
switch (node->n_type) {
case IVY_AST_IDENT: {
struct ivy_ast_ident_node *ident = (struct ivy_ast_ident_node *)node;
struct ivy_ast_ident_node *ident
= (struct ivy_ast_ident_node *)node;
printf("%s", ident->n_content->t_str);
break;
}
@@ -100,7 +101,8 @@ static void print_operand(struct ivy_ast_node *node)
}
}
static enum ivy_status finalise_expr(struct expr_parser_state *state, struct ivy_ast_node **root)
static enum ivy_status finalise_expr(
struct expr_parser_state *state, struct ivy_ast_node **root)
{
b_queue_iterator it = {0};
while (true) {
@@ -109,7 +111,8 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state, struct ivy
break;
}
struct ivy_ast_node *node = b_unbox(struct ivy_ast_node, entry, n_entry);
struct ivy_ast_node *node
= b_unbox(struct ivy_ast_node, entry, n_entry);
if (!node) {
/* this should never happen */
return IVY_ERR_INTERNAL_FAILURE;
@@ -149,9 +152,11 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state, struct ivy
const struct ivy_operator *op = NULL;
if (item->n_type == IVY_AST_MSG) {
struct ivy_ast_msg_node *msg = (struct ivy_ast_msg_node *)item;
struct ivy_ast_msg_node *msg
= (struct ivy_ast_msg_node *)item;
tmp = b_queue_pop_back(&q);
msg->n_recipient = b_unbox(struct ivy_ast_node, tmp, n_entry);
msg->n_recipient
= b_unbox(struct ivy_ast_node, tmp, n_entry);
b_queue_push_back(&q, &msg->n_base.n_entry);
continue;
}
@@ -163,7 +168,8 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state, struct ivy
if (op->op_arity == IVY_OP_BINARY) {
tmp = b_queue_pop_back(&q);
op_node->n_left = b_unbox(struct ivy_ast_node, tmp, n_entry);
op_node->n_left
= b_unbox(struct ivy_ast_node, tmp, n_entry);
}
b_queue_push_back(&q, &op_node->n_base.n_entry);
@@ -179,19 +185,21 @@ static const struct ivy_operator *get_operator(struct ivy_token *tok)
{
switch (tok->t_type) {
case IVY_TOK_IDENT:
return ivy_operator_get(tok->t_type);
return ivy_operator_get_by_token(tok->t_type);
case IVY_TOK_KEYWORD:
return ivy_operator_get(tok->t_keyword);
return ivy_operator_get_by_token(tok->t_keyword);
case IVY_TOK_SYMBOL:
return ivy_operator_get(tok->t_symbol);
return ivy_operator_get_by_token(tok->t_symbol);
default:
return NULL;
}
}
static struct ivy_ast_selector_node *create_unary_selector_from_ident(struct ivy_token *tok)
static struct ivy_ast_selector_node *create_unary_selector_from_ident(
struct ivy_token *tok)
{
struct ivy_ast_selector_node *sel = (struct ivy_ast_selector_node *)ast_node_create(IVY_AST_SELECTOR);
struct ivy_ast_selector_node *sel
= (struct ivy_ast_selector_node *)ast_node_create(IVY_AST_SELECTOR);
if (!sel) {
return NULL;
}
@@ -203,7 +211,8 @@ static struct ivy_ast_selector_node *create_unary_selector_from_ident(struct ivy
}
static enum ivy_status push_operator(
struct expr_parser_state *state, struct ivy_token *tok, const struct ivy_operator *op)
struct expr_parser_state *state, struct ivy_token *tok,
const struct ivy_operator *op)
{
if (!op) {
op = get_operator(tok);
@@ -214,12 +223,11 @@ static enum ivy_status push_operator(
}
if ((op->op_location == IVY_OP_INFIX || op->op_location == IVY_OP_POSTFIX)
&& state->s_prev_part != EXPR_OPERAND) {
&& state->s_prev_part != EXPR_OPERAND) {
return IVY_ERR_BAD_SYNTAX;
}
if (op->op_location == IVY_OP_PREFIX
&& state->s_prev_part == EXPR_OPERAND) {
if (op->op_location == IVY_OP_PREFIX && state->s_prev_part == EXPR_OPERAND) {
return IVY_ERR_BAD_SYNTAX;
}
@@ -235,11 +243,12 @@ static enum ivy_status push_operator(
const struct ivy_operator *top_op = NULL;
if (top->n_type == IVY_AST_OP) {
struct ivy_ast_op_node *op_node = (struct ivy_ast_op_node *)top;
struct ivy_ast_op_node *op_node
= (struct ivy_ast_op_node *)top;
top_op = op_node->n_op;
} else if (top->n_type == IVY_AST_MSG) {
top_op = ivy_operator_get(IVY_TOK_IDENT);
}
top_op = ivy_operator_get_by_token(IVY_TOK_IDENT);
}
if (top_op->op_id == IVY_OP_LEFT_PAREN) {
break;
@@ -259,19 +268,22 @@ static enum ivy_status push_operator(
}
if (tok->t_type == IVY_TOK_IDENT) {
struct ivy_ast_msg_node *msg_node = (struct ivy_ast_msg_node *)ast_node_create(IVY_AST_MSG);
struct ivy_ast_msg_node *msg_node
= (struct ivy_ast_msg_node *)ast_node_create(IVY_AST_MSG);
msg_node->n_sel = create_unary_selector_from_ident(tok);
b_queue_push_back(&state->s_operator_stack, &msg_node->n_base.n_entry);
b_queue_push_back(
&state->s_operator_stack, &msg_node->n_base.n_entry);
} else {
struct ivy_ast_op_node *op_node = (struct ivy_ast_op_node *)ast_node_create(IVY_AST_OP);
struct ivy_ast_op_node *op_node
= (struct ivy_ast_op_node *)ast_node_create(IVY_AST_OP);
op_node->n_op = op;
b_queue_push_back(&state->s_operator_stack, &op_node->n_base.n_entry);
b_queue_push_back(
&state->s_operator_stack, &op_node->n_base.n_entry);
}
return IVY_OK;
}
static enum ivy_status push_operand(
struct expr_parser_state *state, struct ivy_token *tok)
{
@@ -279,25 +291,32 @@ static enum ivy_status push_operand(
switch (tok->t_type) {
case IVY_TOK_INT: {
struct ivy_ast_int_node *v = (struct ivy_ast_int_node *)ast_node_create(IVY_AST_INT);
struct ivy_ast_int_node *v
= (struct ivy_ast_int_node *)ast_node_create(IVY_AST_INT);
v->n_value = tok;
node = (struct ivy_ast_node *)v;
break;
}
case IVY_TOK_DOUBLE: {
struct ivy_ast_double_node *v = (struct ivy_ast_double_node *)ast_node_create(IVY_AST_DOUBLE);
struct ivy_ast_double_node *v
= (struct ivy_ast_double_node *)ast_node_create(
IVY_AST_DOUBLE);
v->n_value = tok;
node = (struct ivy_ast_node *)v;
break;
}
case IVY_TOK_STRING: {
struct ivy_ast_string_node *v = (struct ivy_ast_string_node *)ast_node_create(IVY_AST_STRING);
struct ivy_ast_string_node *v
= (struct ivy_ast_string_node *)ast_node_create(
IVY_AST_STRING);
v->n_value = tok;
node = (struct ivy_ast_node *)v;
break;
}
case IVY_TOK_IDENT: {
struct ivy_ast_ident_node *v = (struct ivy_ast_ident_node *)ast_node_create(IVY_AST_IDENT);
struct ivy_ast_ident_node *v
= (struct ivy_ast_ident_node *)ast_node_create(
IVY_AST_IDENT);
v->n_content = tok;
node = (struct ivy_ast_node *)v;
break;
@@ -325,7 +344,7 @@ static struct token_parse_result parse_ident(
} else {
push_operand(state, tok);
}
set_previous(state, tok);
state->s_prev_part = EXPR_OPERAND;
@@ -461,8 +480,9 @@ static struct token_parse_result parse_left_paren(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
struct ivy_ast_op_node *paren_node = (struct ivy_ast_op_node *)ast_node_create(IVY_AST_OP);
paren_node->n_op = ivy_operator_get(tok->t_symbol);
struct ivy_ast_op_node *paren_node
= (struct ivy_ast_op_node *)ast_node_create(IVY_AST_OP);
paren_node->n_op = ivy_operator_get_by_token(tok->t_symbol);
b_queue_push_back(&state->s_operator_stack, &paren_node->n_base.n_entry);
set_previous(state, tok);
@@ -597,10 +617,10 @@ static struct token_parse_result parse_bang(
if (state->s_end != EXPR_END_DOT) {
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
struct ivy_ast_node *expr_tree = NULL;
enum ivy_status status = finalise_expr(state, &expr_tree);
if (status != IVY_OK) {
return PARSE_RESULT(status, 0);
}
@@ -622,7 +642,7 @@ static struct token_parse_result parse_dot(
struct ivy_ast_node *expr_tree = NULL;
enum ivy_status status = finalise_expr(state, &expr_tree);
if (status != IVY_OK) {
return PARSE_RESULT(status, 0);
}