https://gcc.gnu.org/g:9a485b83e177cb742be17faf20ac5cc7db14fee3

commit r16-601-g9a485b83e177cb742be17faf20ac5cc7db14fee3
Author: Gaius Mulley <gaiusm...@gmail.com>
Date:   Tue May 13 22:54:33 2025 +0100

    PR modula2/120253: Error message column numbers should start at 1 not 0
    
    This patch ensures that column numbers start at 1 rather than 0.
    
    gcc/m2/ChangeLog:
    
            PR modula2/120253
            * m2.flex (FIRST_COLUMN): New define.
            (updatepos): Remove commented code.
            (consumeLine): Assign column to FIRST_COLUMN.
            (initLine): Ditto.
            (m2flex_GetColumnNo): Return FIRST_COLUMN if currentLine is NULL.
            (m2flex_GetLineNo): Rewrite for positive logic.
            (m2flex_GetLocation): Ditto.
    
    Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>

Diff:
---
 gcc/m2/m2.flex | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/gcc/m2/m2.flex b/gcc/m2/m2.flex
index d08ac3edefa9..e3cf010b5901 100644
--- a/gcc/m2/m2.flex
+++ b/gcc/m2/m2.flex
@@ -48,6 +48,8 @@ static int cpreprocessor = 0;  /* Replace this with correct 
getter.  */
 #define EXTERN extern "C"
 #endif
 
+#define FIRST_COLUMN 1
+
   /* m2.flex provides a lexical analyser for GNU Modula-2.  */
 
   struct lineInfo {
@@ -558,7 +560,7 @@ static void consumeLine (void)
   currentLine->lineno = lineno;
   currentLine->tokenpos=0;
   currentLine->nextpos=0;
-  currentLine->column=0;
+  currentLine->column=FIRST_COLUMN;
   START_LINE (lineno, yyleng);
   yyless(1);                  /* push back all but the \n */
   traceLine ();
@@ -621,7 +623,6 @@ static void updatepos (void)
   seenModuleStart      = false;
   currentLine->nextpos = currentLine->tokenpos+yyleng;
   currentLine->toklen  = yyleng;
-  /* if (currentLine->column == 0) */
   currentLine->column = currentLine->tokenpos+1;
   currentLine->location =
     M2Options_OverrideLocation (GET_LOCATION (currentLine->column,
@@ -677,7 +678,7 @@ static void initLine (void)
   currentLine->toklen     = 0;
   currentLine->nextpos    = 0;
   currentLine->lineno = lineno;
-  currentLine->column     = 0;
+  currentLine->column     = FIRST_COLUMN;
   currentLine->inuse      = true;
   currentLine->next       = NULL;
 }
@@ -812,10 +813,10 @@ EXTERN bool m2flex_OpenSource (char *s)
 
 EXTERN int m2flex_GetLineNo (void)
 {
-  if (currentLine != NULL)
-    return currentLine->lineno;
-  else
+  if (currentLine == NULL)
     return 0;
+  else
+    return currentLine->lineno;
 }
 
 /*
@@ -825,10 +826,10 @@ EXTERN int m2flex_GetLineNo (void)
 
 EXTERN int m2flex_GetColumnNo (void)
 {
-  if (currentLine != NULL)
-    return currentLine->column;
+  if (currentLine == NULL)
+    return FIRST_COLUMN;
   else
-    return 0;
+    return currentLine->column;
 }
 
 /*
@@ -837,10 +838,10 @@ EXTERN int m2flex_GetColumnNo (void)
 
 EXTERN location_t m2flex_GetLocation (void)
 {
-  if (currentLine != NULL)
-    return currentLine->location;
-  else
+  if (currentLine == NULL)
     return 0;
+  else
+    return currentLine->location;
 }
 
 /*

Reply via email to