]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Refactor code for printing the error location
authorViljar Indus <indus@adacore.com>
Fri, 1 Nov 2024 11:15:21 +0000 (13:15 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 Nov 2024 09:49:34 +0000 (10:49 +0100)
gcc/ada/ChangeLog:

* errout.adb: Use Output_Msg_Location
* erroutc.adb: add common implementation for printing the
error message line.
* erroutc.ads: Add new method Output_Msg_Location
* errutil.adb: use Output_Msg_Location

gcc/ada/errout.adb
gcc/ada/erroutc.adb
gcc/ada/erroutc.ads
gcc/ada/errutil.adb

index 21c8adf5e4f356d00d610ebe6a420937d2be2ef5..de2413a8f15860a54aa7850698e1a11206e978b8 100644 (file)
@@ -2635,28 +2635,7 @@ package body Errout is
                end if;
 
                if Use_Prefix then
-                  Write_Str (SGR_Locus);
-
-                  if Full_Path_Name_For_Brief_Errors then
-                     Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
-                  else
-                     Write_Name (Reference_Name (Errors.Table (E).Sfile));
-                  end if;
-
-                  Write_Char (':');
-                  Write_Int (Int (Physical_To_Logical
-                           (Errors.Table (E).Line,
-                              Errors.Table (E).Sfile)));
-                  Write_Char (':');
-
-                  if Errors.Table (E).Col < 10 then
-                     Write_Char ('0');
-                  end if;
-
-                  Write_Int (Int (Errors.Table (E).Col));
-                  Write_Str (": ");
-
-                  Write_Str (SGR_Reset);
+                  Output_Msg_Location (E);
                end if;
 
                Output_Msg_Text (E);
index db1c0923e907b932613dbbedc02b2bd689f81f82..606600c613b78f1f56fd25a7074bd853dd81fc18 100644 (file)
@@ -774,6 +774,35 @@ package body Erroutc is
       end loop;
    end Output_Text_Within;
 
+   -------------------------
+   -- Output_Msg_Location --
+   -------------------------
+
+   procedure Output_Msg_Location (E : Error_Msg_Id) is
+      E_Obj : constant Error_Msg_Object := Errors.Table (E);
+   begin
+      Write_Str (SGR_Locus);
+
+      if Full_Path_Name_For_Brief_Errors then
+         Write_Name (Full_Ref_Name (E_Obj.Sfile));
+      else
+         Write_Name (Reference_Name (E_Obj.Sfile));
+      end if;
+
+      Write_Char (':');
+      Write_Int (Int (Physical_To_Logical (E_Obj.Line, E_Obj.Sfile)));
+      Write_Char (':');
+
+      if E_Obj.Col < 10 then
+         Write_Char ('0');
+      end if;
+
+      Write_Int (Int (E_Obj.Col));
+      Write_Str (": ");
+
+      Write_Str (SGR_Reset);
+   end Output_Msg_Location;
+
    ---------------------
    -- Output_Msg_Text --
    ---------------------
index 0a52af5033c2387658d84de14ad7550ea6203002..6c3b9daef34d8c3e492946d3b8bce2fd6975814a 100644 (file)
@@ -512,6 +512,13 @@ package Erroutc is
    --  that match or are less than the last Source_Reference pragma are listed
    --  as all blanks, avoiding output of junk line numbers.
 
+   procedure Output_Msg_Location (E : Error_Msg_Id);
+   --  Write the location of the error message in the following format:
+   --
+   --  <File_Name>:<Line>:<Col>:
+   --
+   --  If Full_Path_Name_For_Brief_Errors then full path of the file is used.
+
    procedure Output_Msg_Text (E : Error_Msg_Id);
    --  Outputs characters of text in the text of the error message E. Note that
    --  no end of line is output, the caller is responsible for adding the end
index 6747fe59d24bfbd75c768a0a15db6fe06df6ddab..795b2f21962dc8daf91ff8770577af0541642843 100644 (file)
@@ -411,24 +411,7 @@ package body Errutil is
 
          while E /= No_Error_Msg loop
             if not Errors.Table (E).Deleted then
-               if Full_Path_Name_For_Brief_Errors then
-                  Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
-               else
-                  Write_Name (Reference_Name (Errors.Table (E).Sfile));
-               end if;
-
-               Write_Char (':');
-               Write_Int (Int (Physical_To_Logical
-                                (Errors.Table (E).Line,
-                                 Errors.Table (E).Sfile)));
-               Write_Char (':');
-
-               if Errors.Table (E).Col < 10 then
-                  Write_Char ('0');
-               end if;
-
-               Write_Int (Int (Errors.Table (E).Col));
-               Write_Str (": ");
+               Output_Msg_Location (E);
                Output_Msg_Text (E);
                Write_Eol;
             end if;