This patch changes the output on the simple test I tried from:

$ ./gcobol -B. hello.cob -S
hello.cob:2:8: error: syntax error, unexpected NAME, expecting FUNCTION or 
PROGRAM-ID
    2 |        porgram-id. hello.
      |        ^
cobol1: error: failed compiling hello.cob

to:

$ ./gcobol -B. hello.cob -S
hello.cob:2:8: error: syntax error, unexpected NAME, expecting FUNCTION or 
PROGRAM-ID
    2 |        porgram-id. hello.
      |        ^~~~~~~~~~~
cobol1: error: failed compiling hello.cob

I haven't tested this patch properly yet.

gcc/cobol/ChangeLog:
        * util.cc (gcc_location_set_impl): Capture the start and end of "loc"
        as a range, rather than just the (last_line, first_column).
---
 gcc/cobol/util.cc | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
index 6ade146b5dda..aba4a1003554 100644
--- a/gcc/cobol/util.cc
+++ b/gcc/cobol/util.cc
@@ -1857,11 +1857,23 @@ cobol_filename_restore() {
 
 static location_t token_location;
 
+/* Update global token_location with a location_t expressing a source
+   range with start and caret at the first line/column of LOC, and
+   finishing at the last line/column of LOC.  */
+
 template <typename LOC>
 static void
 gcc_location_set_impl( const LOC& loc ) {
-  token_location = linemap_line_start( line_table, loc.last_line, 80 );
-  token_location = linemap_position_for_column( line_table, loc.first_column);
+  const location_t start_line
+    = linemap_line_start( line_table, loc.first_line, 80 );
+  const location_t token_start
+    = linemap_position_for_column( line_table, loc.first_column);
+  const location_t finish_line
+    = linemap_line_start( line_table, loc.last_line, 80 );
+  const location_t token_finish
+    = linemap_position_for_column( line_table, loc.last_column);
+  token_location
+    = make_location (token_start, token_start, token_finish);
   location_dump(__func__, __LINE__, "parser", loc);
 }
 
-- 
2.26.3

Reply via email to