Make line and column size_t

This commit is contained in:
Laria 2023-02-16 21:41:02 +01:00
parent f4841ff2cd
commit a4f7f0884d
11 changed files with 49 additions and 37 deletions

View file

@ -40,8 +40,8 @@ struct apfl_allocator apfl_allocator_wrap_verifying(struct apfl_allocator *wrapp
typedef double apfl_number;
struct apfl_position {
int line;
int col;
size_t line;
size_t col;
};
bool apfl_position_eq(struct apfl_position, struct apfl_position);
@ -749,8 +749,8 @@ struct apfl_call_stack_entry_info {
size_t subfunction_index; // Only set for type==APFL_CSE_FUNCTION && !toplevel
struct apfl_string_view filename;
struct apfl_string_view name;
int line_current; // only set for (type==APFL_CSE_FUNCTION && !toplevel) || type == APFL_CSE_FUNCTION_DISPATCH
int line_defined; // only set for type==APFL_CSE_FUNCTION
size_t line_current; // only set for (type==APFL_CSE_FUNCTION && !toplevel) || type == APFL_CSE_FUNCTION_DISPATCH
size_t line_defined; // only set for type==APFL_CSE_FUNCTION
};
// Get the depth of the current call stack

View file

@ -8,7 +8,7 @@
#include "gc.h"
struct instruction_list *
apfl_instructions_new(struct gc *gc, int line, struct apfl_string *filename)
apfl_instructions_new(struct gc *gc, size_t line, struct apfl_string *filename)
{
struct instruction_list *ilist = apfl_gc_new_instructions(gc);
if (ilist == NULL) {

View file

@ -85,14 +85,14 @@ struct instruction_list {
size_t len;
size_t cap;
int line;
size_t line;
struct apfl_string *filename;
};
const char *apfl_instruction_to_string(enum instruction);
const char *apfl_matcher_instruction_to_string(enum matcher_instruction);
struct instruction_list *apfl_instructions_new(struct gc *, int line, struct apfl_string *filename);
struct instruction_list *apfl_instructions_new(struct gc *, size_t line, struct apfl_string *filename);
void apfl_instructions_deinit(struct apfl_allocator, struct instruction_list *);
void apfl_gc_instructions_traverse(struct instruction_list *, gc_visitor, void *);

View file

@ -296,7 +296,7 @@ compile_simple_assignment(
}
static struct instruction_list *
tmp_ilist(struct compiler *compiler, int line, struct apfl_string *filename)
tmp_ilist(struct compiler *compiler, size_t line, struct apfl_string *filename)
{
struct instruction_list *ilist;
if (

View file

@ -1976,7 +1976,7 @@ format_defined_at(
FMT_TRY(apfl_io_write_string(w, ", "));
}
FMT_TRY(apfl_io_write_string(w, "line "));
FMT_TRY(apfl_format_put_int(w, info.line_defined));
FMT_TRY(apfl_format_put_int(w, (int)info.line_defined));
return true;
}
@ -1991,7 +1991,7 @@ apfl_call_stack_entry_info_format(struct apfl_io_writer w, struct apfl_call_stac
FMT_TRY(apfl_io_write_string(w, ", "));
}
FMT_TRY(apfl_io_write_string(w, "Line "));
FMT_TRY(apfl_format_put_int(w, info.line_current));
FMT_TRY(apfl_format_put_int(w, (int)info.line_current));
FMT_TRY(apfl_io_write_string(w, ", "));
if (info.toplevel) {

View file

@ -54,7 +54,7 @@ struct func_call_stack_entry {
// scopes.scope will be created lazily
struct scopes scopes;
int execution_line;
size_t execution_line;
struct function *function; // Can be NULL, in that case it's the toplevel
size_t subfunction_index; // Not set, if function == NULL

View file

@ -1,12 +1,13 @@
#include <inttypes.h>
#include <stdio.h>
#include "apfl.h"
#include "format.h"
#define POSFMT "%d:%d"
#define POSARGS error.position.line, error.position.col
#define POS2ARGS error.position2.line, error.position2.col
#define POSFMT "%" PRIuMAX ":%" PRIuMAX
#define POSARGS (umaxint_t)error.position.line, (umaxint_t)error.position.col
#define POS2ARGS (umaxint_t)error.position2.line, (umaxint_t)error.position2.col
#define TRY(x) do { if (!(x)) return false; } while (0)

View file

@ -86,9 +86,9 @@ apfl_format_put_hexbyte(struct apfl_io_writer w, unsigned char c)
bool
apfl_format_put_pos(struct apfl_io_writer w, struct apfl_position pos)
{
TRY(apfl_format_put_int(w, pos.line));
TRY(apfl_format_put_int(w, (int)pos.line));
TRY(apfl_io_write_string(w, ":"));
TRY(apfl_format_put_int(w, pos.col));
TRY(apfl_format_put_int(w, (int)pos.col));
return true;
}

View file

@ -237,7 +237,7 @@ MKLISTBUILDER(assignable_list, struct apfl_expr_assignable_list, struct apfl_exp
#define POS(l, c) (struct apfl_position) { .line = l, .col = c }
static struct apfl_expr
var(struct parser_test *pt, int line, int col, const char *v)
var(struct parser_test *pt, size_t line, size_t col, const char *v)
{
return (struct apfl_expr) {
.type = APFL_EXPR_VAR,
@ -247,14 +247,14 @@ var(struct parser_test *pt, int line, int col, const char *v)
}
struct apfl_expr *
new_var(struct parser_test *pt, int line, int col, const char *v)
new_var(struct parser_test *pt, size_t line, size_t col, const char *v)
{
struct apfl_expr expr = var(pt, line, col, v);
return new_helper(pt, sizeof(struct apfl_expr), &expr);
}
static struct apfl_expr
dot(struct parser_test *pt, int line, int col, const char *rhs, struct apfl_expr *lhs)
dot(struct parser_test *pt, size_t line, size_t col, const char *rhs, struct apfl_expr *lhs)
{
return (struct apfl_expr) {
.type = APFL_EXPR_DOT,
@ -265,7 +265,7 @@ dot(struct parser_test *pt, int line, int col, const char *rhs, struct apfl_expr
}
static struct apfl_expr *
new_dot(struct parser_test *pt, int line, int col, const char *rhs, struct apfl_expr *lhs)
new_dot(struct parser_test *pt, size_t line, size_t col, const char *rhs, struct apfl_expr *lhs)
{
struct apfl_expr expr = dot(pt, line, col, rhs, lhs);
return new_helper(pt, sizeof(struct apfl_expr), &expr);
@ -300,7 +300,7 @@ bool_const(bool b)
}
static struct apfl_expr
const_expr(int line, int col, struct apfl_expr_const constant)
const_expr(size_t line, size_t col, struct apfl_expr_const constant)
{
return (struct apfl_expr) {
.type = APFL_EXPR_CONSTANT,
@ -310,7 +310,7 @@ const_expr(int line, int col, struct apfl_expr_const constant)
}
static struct apfl_expr *
new_const_expr(struct parser_test *pt, int line, int col, struct apfl_expr_const constant)
new_const_expr(struct parser_test *pt, size_t line, size_t col, struct apfl_expr_const constant)
{
struct apfl_expr expr = const_expr(line, col, constant);
return new_helper(pt, sizeof(struct apfl_expr), &expr);

View file

@ -1,3 +1,4 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@ -95,28 +96,28 @@ apfl_token_print(struct apfl_token token, FILE *file)
if (has_text_data(token.type)) {
fprintf(
file,
"%s (" APFL_STR_FMT ") @ (%d:%d)\n",
"%s (" APFL_STR_FMT ") @ (%" PRIuMAX ":%" PRIuMAX ")\n",
apfl_token_type_name(token.type),
APFL_STR_FMT_ARGS(apfl_string_view_from(token.text)),
token.position.line,
token.position.col
(uintmax_t)token.position.line,
(uintmax_t)token.position.col
);
} else if (has_numeric_data(token.type)) {
fprintf(
file,
"%s (%f) @ (%d:%d)\n",
"%s (%f) @ (%" PRIuMAX ":%" PRIuMAX ")\n",
apfl_token_type_name(token.type),
token.number,
token.position.line,
token.position.col
(uintmax_t)token.position.line,
(uintmax_t)token.position.col
);
} else {
fprintf(
file,
"%s @ (%d:%d)\n",
"%s @ (%" PRIuMAX ":%" PRIuMAX ")\n",
apfl_token_type_name(token.type),
token.position.line,
token.position.col
(uintmax_t)token.position.line,
(uintmax_t)token.position.col
);
}
}

View file

@ -1,4 +1,5 @@
#include <assert.h>
#include <inttypes.h>
#include "apfl.h"
@ -65,7 +66,7 @@ expect_eof(struct tokenizer_test *tt)
}
static bool
expect_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_type type, struct apfl_token *tok)
expect_token(struct tokenizer_test *tt, size_t line, size_t col, enum apfl_token_type type, struct apfl_token *tok)
{
switch (apfl_tokenizer_next(tt->tokenizer, false)) {
case APFL_PARSE_OK:
@ -94,14 +95,23 @@ expect_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_type
}
if (tok->position.line != line || tok->position.col != col) {
test_failf(tt->t, "Got token at wrong position %d:%d (wanted %d:%d)", tok->position.line, tok->position.col, line, col);
test_failf(
tt->t,
"Got token at wrong position %" PRIuMAX ":%" PRIuMAX
" (wanted %" PRIuMAX ":%" PRIuMAX ")",
(uintmax_t)tok->position.line,
(uintmax_t)tok->position.col,
(uintmax_t)line,
(uintmax_t)col
);
}
return true;
}
static void
expect_simple_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_type type)
expect_simple_token(struct tokenizer_test *tt, size_t line, size_t col, enum apfl_token_type type)
{
struct apfl_token tok;
if (expect_token(tt, line, col, type, &tok)) {
@ -110,7 +120,7 @@ expect_simple_token(struct tokenizer_test *tt, int line, int col, enum apfl_toke
}
static void
expect_text_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_type type, const char *text)
expect_text_token(struct tokenizer_test *tt, size_t line, size_t col, enum apfl_token_type type, const char *text)
{
struct apfl_token tok;
if (expect_token(tt, line, col, type, &tok)) {
@ -123,7 +133,7 @@ expect_text_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_
}
static void
expect_text_token_sv(struct tokenizer_test *tt, int line, int col, enum apfl_token_type type, struct apfl_string_view text)
expect_text_token_sv(struct tokenizer_test *tt, size_t line, size_t col, enum apfl_token_type type, struct apfl_string_view text)
{
struct apfl_token tok;
if (expect_token(tt, line, col, type, &tok)) {
@ -136,7 +146,7 @@ expect_text_token_sv(struct tokenizer_test *tt, int line, int col, enum apfl_tok
}
static void
expect_number_token(struct tokenizer_test *tt, int line, int col, enum apfl_token_type type, apfl_number num)
expect_number_token(struct tokenizer_test *tt, size_t line, size_t col, enum apfl_token_type type, apfl_number num)
{
struct apfl_token tok;
if (expect_token(tt, line, col, type, &tok)) {