From: Viljar Indus <in...@adacore.com>

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

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/errout.adb  | 23 +----------------------
 gcc/ada/erroutc.adb | 29 +++++++++++++++++++++++++++++
 gcc/ada/erroutc.ads |  7 +++++++
 gcc/ada/errutil.adb | 19 +------------------
 4 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 21c8adf5e4f..de2413a8f15 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -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);
diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb
index db1c0923e90..606600c613b 100644
--- a/gcc/ada/erroutc.adb
+++ b/gcc/ada/erroutc.adb
@@ -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 --
    ---------------------
diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads
index 0a52af5033c..6c3b9daef34 100644
--- a/gcc/ada/erroutc.ads
+++ b/gcc/ada/erroutc.ads
@@ -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
diff --git a/gcc/ada/errutil.adb b/gcc/ada/errutil.adb
index 6747fe59d24..795b2f21962 100644
--- a/gcc/ada/errutil.adb
+++ b/gcc/ada/errutil.adb
@@ -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;
-- 
2.43.0

Reply via email to