aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2025-05-08 14:56:34 +0200
committerHimbeer <himbeer@disroot.org>2025-05-08 14:56:34 +0200
commit999491d046547dafa7238163d6231a5b3257c250 (patch)
treed414e5fb1ff538a80a049953227c70b87671f383
parent973812e4720912e9e326eb494c9e506e642d7afe (diff)
Move error function to util.c
-rw-r--r--include/util.h2
-rw-r--r--src/check.c15
-rw-r--r--src/parse.c15
-rw-r--r--src/util.c15
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 <stddef.h>
+#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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
@@ -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 <stdarg.h>
#include <stdlib.h>
#include <stdnoreturn.h>
#include <string.h>
#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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#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);
+}