summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--err.c35
-rw-r--r--main.c1
-rw-r--r--package.c8
-rw-r--r--types.h9
4 files changed, 33 insertions, 20 deletions
diff --git a/err.c b/err.c
index 2472d3d..1307a15 100644
--- a/err.c
+++ b/err.c
@@ -81,37 +81,37 @@ static void err_vfprint(const char *fmt, va_list args) {
vfprintf(stderr, fmt, args);
}
+static void err_print_line_file(Location where) {
+ if (where.start) {
+ err_fprint(" at line %lu of %s:\n", (unsigned long)where.start->pos.line, where.start->pos.ctx->filename);
+ } else if (where.simple_location) {
+ err_fprint(" at line %lu of %s:\n", (unsigned long)where.simple_location->line, where.simple_location->ctx->filename);
+ } else {
+ err_fprint(":\n");
+
+ }
+
+}
+
static void err_print_header_(Location where) {
SourcePos start_pos = where.start->pos;
ErrCtx *ctx = start_pos.ctx;
err_text_err(ctx, "error");
- if (!where.start)
- err_fprint(":\n");
- else {
- err_fprint(" at line %lu of %s:\n", (unsigned long)start_pos.line, ctx->filename);
- }
+ err_print_line_file(where);
}
static void info_print_header_(Location where) {
SourcePos start_pos = where.start->pos;
ErrCtx *ctx = start_pos.ctx;
err_text_info(ctx, "info");
- if (!where.start)
- err_fprint(":\n");
- else {
- err_fprint(" at line %lu of %s:\n", (unsigned long)start_pos.line, ctx->filename);
- }
+ err_print_line_file(where);
}
static void warn_print_header_(Location where) {
SourcePos start_pos = where.start->pos;
ErrCtx *ctx = start_pos.ctx;
err_text_warn(ctx, "warning");
- if (!where.start)
- err_fprint(":\n");
- else {
- err_fprint(" at line %lu of %s:\n", (unsigned long)start_pos.line, ctx->filename);
- }
+ err_print_line_file(where);
}
static void err_print_pos_text(ErrCtx *ctx, U32 start_pos, U32 end_pos) {
@@ -162,8 +162,6 @@ static void err_print_location_text(Location where) {
if (where.start) {
ErrCtx *ctx = where.start->pos.ctx;
err_print_pos_text(ctx, where.start->pos.start, where.end[-1].pos.end);
- } else {
- err_fprint("\t<no location available>");
}
}
@@ -182,11 +180,12 @@ static void err_print_footer_(Location where) {
/* Write nicely-formatted errors to the error file */
-
static void err_vprint(Location where, const char *fmt, va_list args) {
if (location_is_ctx_disabled(where)) return;
if (where.start) {
where.start->pos.ctx->have_errored = true;
+ } else if (where.simple_location) {
+ where.simple_location->ctx->have_errored = true;
}
err_print_header_(where);
err_vfprint(fmt, args);
diff --git a/main.c b/main.c
index 5c0e800..e80f892 100644
--- a/main.c
+++ b/main.c
@@ -18,7 +18,6 @@
/*
TODO:
-test EOF error
packages
---
X ::= newtype(int); or something
diff --git a/package.c b/package.c
index 1ad2c4f..beb7b0a 100644
--- a/package.c
+++ b/package.c
@@ -128,6 +128,14 @@ static void export_location(Exporter *ex, Location where) {
export_vlq(ex, (U64)where.start->pos.line);
}
}
+static Location import_location(Importer *im) {
+ Location l;
+ l.start = NULL;
+ l.simple_location = imptr_malloc(im, sizeof *l.simple_location);
+ l.simple_location->ctx = &im->err_ctx;
+ l.simple_location->line = (U32)import_vlq(im);
+ return l;
+}
static inline void export_ident(Exporter *ex, Identifier i) {
if (!i->export_id) {
diff --git a/types.h b/types.h
index 7ea2c25..605b6d2 100644
--- a/types.h
+++ b/types.h
@@ -322,8 +322,15 @@ typedef struct Token {
typedef struct Location {
+ /* if start is NULL, simple_location will be used. */
Token *start;
- Token *end; /* Exclusive */
+ union {
+ Token *end; /* Exclusive */
+ struct {
+ ErrCtx *ctx;
+ U32 line;
+ } *simple_location;
+ };
} Location;