diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-10 11:52:35 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-10 11:52:35 -0500 |
commit | 50e64bed4bc38e949d440d83337a90b8c011a4c7 (patch) | |
tree | 54ccc9cab73bb18c0a48636a441aca5c8a9417e7 | |
parent | 79a9f6d1e6fb8d9fb4b630751fad0750c7fc5b33 (diff) |
importing locations
-rw-r--r-- | err.c | 35 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | package.c | 8 | ||||
-rw-r--r-- | types.h | 9 |
4 files changed, 33 insertions, 20 deletions
@@ -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); @@ -18,7 +18,6 @@ /* TODO: -test EOF error packages --- X ::= newtype(int); or something @@ -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) { @@ -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; |