lang: fix a bunch of compiler warnings
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
#include <ivy/lang/operator.h>
|
|
||||||
#include <ivy/lang/lex.h>
|
#include <ivy/lang/lex.h>
|
||||||
|
#include <ivy/lang/operator.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
enum expr_end {
|
enum expr_end {
|
||||||
@@ -94,7 +94,8 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state)
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
b_queue_foreach (&it, &state->s_operand_queue) {
|
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) {
|
if (i > 0) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
@@ -105,7 +106,8 @@ static enum ivy_status finalise_expr(struct expr_parser_state *state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
b_queue_foreach (&it, &state->s_operator_stack) {
|
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) {
|
if (i > 0) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
@@ -212,11 +214,11 @@ static struct token_parse_result parse_double(
|
|||||||
|
|
||||||
b_queue_push_back(&state->s_operand_queue, &tok->t_entry);
|
b_queue_push_back(&state->s_operand_queue, &tok->t_entry);
|
||||||
set_previous(state, tok);
|
set_previous(state, tok);
|
||||||
|
|
||||||
return PARSE_RESULT(IVY_OK, 0);
|
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) {
|
switch (tok->t_type) {
|
||||||
case IVY_TOK_KEYWORD:
|
case IVY_TOK_KEYWORD:
|
||||||
@@ -238,7 +240,7 @@ static struct token_parse_result parse_symbol(
|
|||||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
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) {
|
if (!op) {
|
||||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||||
}
|
}
|
||||||
@@ -250,17 +252,19 @@ static struct token_parse_result parse_symbol(
|
|||||||
break;
|
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)) {
|
if (ivy_token_is_symbol(top, IVY_SYM_LEFT_PAREN)) {
|
||||||
break;
|
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) {
|
if (top_op->op_precedence < op->op_precedence) {
|
||||||
break;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +290,7 @@ static struct token_parse_result parse_left_paren(
|
|||||||
|
|
||||||
b_queue_push_back(&state->s_operator_stack, &tok->t_entry);
|
b_queue_push_back(&state->s_operator_stack, &tok->t_entry);
|
||||||
set_previous(state, tok);
|
set_previous(state, tok);
|
||||||
|
|
||||||
return PARSE_RESULT(IVY_OK, 0);
|
return PARSE_RESULT(IVY_OK, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type)
|
|||||||
return node_ops[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) {
|
switch (tok->t_type) {
|
||||||
case IVY_TOK_IDENT:
|
case IVY_TOK_IDENT:
|
||||||
@@ -136,7 +136,7 @@ token_parse_function get_token_parser(
|
|||||||
return better_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) {
|
switch (expr_type) {
|
||||||
case TOK_EXPR_BEGIN:
|
case TOK_EXPR_BEGIN:
|
||||||
better_parser = type->n_expr_parser.expr_begin
|
better_parser = type->n_expr_parser.expr_begin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ enum token_parse_flags {
|
|||||||
PARSE_REPEAT_TOKEN = 0x01u,
|
PARSE_REPEAT_TOKEN = 0x01u,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum tok_expr_type {
|
enum token_expr_type {
|
||||||
TOK_EXPR_NONE = 0,
|
TOK_EXPR_NONE = 0,
|
||||||
TOK_EXPR_BEGIN,
|
TOK_EXPR_BEGIN,
|
||||||
TOK_EXPR_ANY,
|
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 const struct ast_node_type *get_ast_node_type(enum ivy_ast_node_type type);
|
||||||
extern token_parse_function get_token_parser(
|
extern token_parse_function get_token_parser(
|
||||||
struct ivy_ast_node *context, struct ivy_token *tok);
|
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(
|
extern struct ivy_ast_node *ast_node_create_with_size(
|
||||||
enum ivy_ast_node_type type, size_t size);
|
enum ivy_ast_node_type type, size_t size);
|
||||||
extern enum ivy_status ast_node_add_child(
|
extern enum ivy_status ast_node_add_child(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define IVY_LANG_AST_H_
|
#define IVY_LANG_AST_H_
|
||||||
|
|
||||||
#include <blue/core/queue.h>
|
#include <blue/core/queue.h>
|
||||||
|
#include <ivy/lang/operator.h>
|
||||||
#include <ivy/misc.h>
|
#include <ivy/misc.h>
|
||||||
#include <ivy/status.h>
|
#include <ivy/status.h>
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ struct ivy_ast_unit_node {
|
|||||||
|
|
||||||
struct ivy_ast_op_node {
|
struct ivy_ast_op_node {
|
||||||
struct ivy_ast_node n_base;
|
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_left; // NULL for unary operators.
|
||||||
struct ivy_ast_node *n_right;
|
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 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_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(
|
IVY_API const char *ivy_ast_msgh_recipient_type_to_string(
|
||||||
enum ivy_ast_msgh_recipient_type v);
|
enum ivy_ast_msgh_recipient_type v);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
#include <ivy/lang/operator.h>
|
|
||||||
#include <ivy/lang/lex.h>
|
#include <ivy/lang/lex.h>
|
||||||
|
#include <ivy/lang/operator.h>
|
||||||
#include <stddef.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 SYM_OP(id, t, p, 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) }
|
[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[] = {
|
static const struct ivy_operator operators[] = {
|
||||||
SYM_OP(ASSIGN, EQUAL, ASSIGN, RIGHT),
|
SYM_OP(ASSIGN, EQUAL, ASSIGN, RIGHT),
|
||||||
SYM_OP(ADD, PLUS, ADDITION, LEFT),
|
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),
|
SYM_OP(PKG_ACCESS, HYPHEN_RIGHT_ANGLE, SUBSCRIPT, LEFT),
|
||||||
};
|
};
|
||||||
static const size_t nr_operators = sizeof operators / sizeof operators[0];
|
static const size_t nr_operators = sizeof operators / sizeof operators[0];
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
const struct ivy_operator *ivy_operator_get(unsigned int token)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ivy_operator *op = &operators[token];
|
const struct ivy_operator *op = &operators[token];
|
||||||
if (op->op_token != token) {
|
if (op->op_token != token) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user