diff --git a/src/apfl.h b/src/apfl.h index 20df27c..8eee50a 100644 --- a/src/apfl.h +++ b/src/apfl.h @@ -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 diff --git a/src/bytecode.c b/src/bytecode.c index b5cbbbd..3459f05 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -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) { diff --git a/src/bytecode.h b/src/bytecode.h index d005a39..5d47bd4 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -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 *); diff --git a/src/compile.c b/src/compile.c index d0cef4c..bf4d46b 100644 --- a/src/compile.c +++ b/src/compile.c @@ -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 ( diff --git a/src/context.c b/src/context.c index 709e186..0c68a80 100644 --- a/src/context.c +++ b/src/context.c @@ -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) { diff --git a/src/context.h b/src/context.h index b03af2a..fe258e8 100644 --- a/src/context.h +++ b/src/context.h @@ -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 diff --git a/src/error.c b/src/error.c index 4b52116..cb1b0ac 100644 --- a/src/error.c +++ b/src/error.c @@ -1,12 +1,13 @@ +#include #include #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) diff --git a/src/format.c b/src/format.c index 855de7e..bd2080c 100644 --- a/src/format.c +++ b/src/format.c @@ -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; } diff --git a/src/parser_test.c b/src/parser_test.c index 5a69899..b630e73 100644 --- a/src/parser_test.c +++ b/src/parser_test.c @@ -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); diff --git a/src/token.c b/src/token.c index 72e2aa9..1485354 100644 --- a/src/token.c +++ b/src/token.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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 ); } } diff --git a/src/tokenizer_test.c b/src/tokenizer_test.c index 0d97511..9b62aa1 100644 --- a/src/tokenizer_test.c +++ b/src/tokenizer_test.c @@ -1,4 +1,5 @@ #include +#include #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)) {