From 999491d046547dafa7238163d6231a5b3257c250 Mon Sep 17 00:00:00 2001 From: Himbeer Date: Thu, 8 May 2025 14:56:34 +0200 Subject: Move error function to util.c --- include/util.h | 2 ++ src/check.c | 15 --------------- src/parse.c | 15 --------------- src/util.c | 15 +++++++++++++++ 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/include/util.h b/include/util.h index 70ae619..722e6d3 100644 --- a/include/util.h +++ b/include/util.h @@ -1,6 +1,7 @@ #ifndef CERC_UTIL_H #define CERC_UTIL_H #include +#include "lex.h" enum exit_status { /* EXIT_SUCCESS = 0 (defined in stdlib.h) */ @@ -14,5 +15,6 @@ enum exit_status { void *must_malloc(size_t size); void *must_calloc(size_t nmemb, size_t size); void *must_realloc(void *ptr, size_t size); +void error(struct location loc, const char *fmt, ...); #endif diff --git a/src/check.c b/src/check.c index e1a7187..421d292 100644 --- a/src/check.c +++ b/src/check.c @@ -1,6 +1,5 @@ #define _POSIX_C_SOURCE 200809L -#include #include #include #include @@ -9,20 +8,6 @@ #include "parse.h" #include "util.h" -static noreturn void -error(struct location loc, const char *fmt, ...) -{ - fprintf(stderr, "%s:%d:%d ", loc.file, loc.line, loc.column); - - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - fprintf(stderr, "\n"); - exit(EXIT_CHECK); -} - static void check_toplevels(struct ast_toplevel *tops, int n) { diff --git a/src/parse.c b/src/parse.c index a9d99b0..4bbda03 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1,25 +1,10 @@ -#define _POSIX_C_SOURCE 200809L - -#include #include #include #include #include "parse.h" #include "util.h" -static noreturn void -error(struct location loc, const char *fmt, ...) -{ - fprintf(stderr, "%s:%d:%d: ", loc.file, loc.line, loc.column); - - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - exit(EXIT_PARSE); -} static int parse_include(struct lexer *lexer, struct ast_include *inc) diff --git a/src/util.c b/src/util.c index 6cc9425..e4d827b 100644 --- a/src/util.c +++ b/src/util.c @@ -1,3 +1,4 @@ +#include #include #include #include "util.h" @@ -33,3 +34,17 @@ must_realloc(void *ptr, size_t size) } return ret; } + +void +error(struct location loc, const char *fmt, ...) +{ + fprintf(stderr, "%s:%d:%d: ", loc.file, loc.line, loc.column); + + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + fprintf(stderr, "\n"); + exit(EXIT_PARSE); +} -- cgit v1.2.3