From 2e386e2eac53ecc4d938a2939673cce13acbe51f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 21 Aug 2016 18:13:03 +1200 Subject: [PATCH] Add support for errors with a range of columns Use the same style as GCC and clang do. --- src/datain.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/datain.c b/src/datain.c index e7c22805..33a4e205 100644 --- a/src/datain.c +++ b/src/datain.c @@ -117,7 +117,7 @@ error_list_parent_files(void) } static void -show_line(int col) +show_line(int col, int width) { /* Rewind to beginning of line. */ long cur_pos = ftell(file.fh); @@ -134,8 +134,13 @@ show_line(int col) /* If we have a location in the line for the error, indicate it. */ if (col) { + col -= width; while (--col) PUTC(' ', STDERR); PUTC('^', STDERR); + while (width > 1) { + PUTC('~', STDERR); + --width; + } fputnl(STDERR); } @@ -144,6 +149,8 @@ show_line(int col) fatalerror_in_file(file.filename, 0, /*Error reading file*/18); } +static int caret_width = 0; + static void compile_v_report(int severity, int en, va_list ap) { @@ -155,7 +162,7 @@ compile_v_report(int severity, int en, va_list ap) } v_report(severity, file.filename, file.line, col, en, ap); if (file.fh) - show_line(col); + show_line(col, caret_width); } void @@ -230,8 +237,14 @@ compile_error_token(int en) s_catchar(&p, &len, (char)ch); nextch(); } - compile_error(en, p ? p : ""); - osfree(p); + if (p) { + caret_width = strlen(p); + compile_error(en, p); + caret_width = 0; + osfree(p); + } else { + compile_error(en, ""); + } } void -- 2.11.4.GIT