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

gcc/ada/ChangeLog:

        * diagnostics-converter.adb: Remove uses of Info_Warning type. Use
        common constructors to simplify implementation.
        * diagnostics-pretty_emitter.adb: Remove Info_Warning type.
        * diagnostics-utils.adb: Remove uses of Info_Warning.
        * diagnostics.adb: Simplify implementation of Primary_Location.
        * diagnostics.ads: Remove Info_Warning type.

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

---
 gcc/ada/diagnostics-converter.adb      | 64 ++++++++------------------
 gcc/ada/diagnostics-pretty_emitter.adb | 14 ++----
 gcc/ada/diagnostics-utils.adb          |  5 +-
 gcc/ada/diagnostics.adb                | 13 +-----
 gcc/ada/diagnostics.ads                |  6 +--
 5 files changed, 27 insertions(+), 75 deletions(-)

diff --git a/gcc/ada/diagnostics-converter.adb 
b/gcc/ada/diagnostics-converter.adb
index 45bb19c0a84..e1613f674c6 100644
--- a/gcc/ada/diagnostics-converter.adb
+++ b/gcc/ada/diagnostics-converter.adb
@@ -41,8 +41,7 @@ package body Diagnostics.Converter is
      (E_Id : Error_Msg_Id) return Sub_Diagnostic_Type;
 
    function Get_Warning_Kind (E_Msg : Error_Msg_Object) return Diagnostic_Kind
-   is (if E_Msg.Info then Info_Warning
-       elsif E_Msg.Warn_Chr = "* " then Restriction_Warning
+   is (if E_Msg.Warn_Chr = "* " then Restriction_Warning
        elsif E_Msg.Warn_Chr = "? " then Default_Warning
        elsif E_Msg.Warn_Chr = "  " then Tagless_Warning
        else Warning);
@@ -50,6 +49,13 @@ package body Diagnostics.Converter is
    --  printer added the warning switch label but treated the message as
    --  an info message.
 
+   function Get_Diagnostics_Kind (E_Msg : Error_Msg_Object)
+                                  return Diagnostic_Kind
+   is (if E_Msg.Warn then Get_Warning_Kind (E_Msg)
+      elsif E_Msg.Style then Style
+      elsif E_Msg.Info then Info
+      else Error);
+
    -----------------------------------
    -- Convert_Errors_To_Diagnostics --
    -----------------------------------
@@ -92,27 +98,14 @@ package body Diagnostics.Converter is
       --  shall be printed with the same kind token as the main diagnostic.
       D.Kind := Continuation;
 
-      declare
-         L : Labeled_Span_Type;
-      begin
-         if E_Msg.Insertion_Sloc /= No_Location then
-            L.Span := To_Span (E_Msg.Insertion_Sloc);
-         else
-            L.Span := E_Msg.Sptr;
-         end if;
-
-         L.Is_Primary := True;
-         Add_Location (D, L);
-      end;
+      Add_Location (D,
+        Primary_Labeled_Span
+          (if E_Msg.Insertion_Sloc /= No_Location
+           then To_Span (E_Msg.Insertion_Sloc)
+           else E_Msg.Sptr));
 
       if E_Msg.Optr.Ptr /= E_Msg.Sptr.Ptr then
-         declare
-            L : Labeled_Span_Type;
-         begin
-            L.Span       := E_Msg.Optr;
-            L.Is_Primary := False;
-            Add_Location (D, L);
-         end;
+         Add_Location (D, Secondary_Labeled_Span (E_Msg.Optr));
       end if;
 
       return D;
@@ -131,17 +124,10 @@ package body Diagnostics.Converter is
    begin
       D.Message := E_Msg.Text;
 
-      if E_Msg.Warn then
-         D.Kind   := Get_Warning_Kind (E_Msg);
-         D.Switch := Get_Switch_Id (E_Msg);
-      elsif E_Msg.Style then
-         D.Kind   := Style;
-         D.Switch := Get_Switch_Id (E_Msg);
-      elsif E_Msg.Info then
-         D.Kind := Info;
+      D.Kind := Get_Diagnostics_Kind (E_Msg);
+
+      if E_Msg.Warn or E_Msg.Style or E_Msg.Info then
          D.Switch := Get_Switch_Id (E_Msg);
-      else
-         D.Kind := Error;
       end if;
 
       D.Warn_Err := E_Msg.Warn_Err;
@@ -150,24 +136,12 @@ package body Diagnostics.Converter is
 
       --  Convert the primary location
 
-      declare
-         L : Labeled_Span_Type;
-      begin
-         L.Span       := E_Msg.Sptr;
-         L.Is_Primary := True;
-         Add_Location (D, L);
-      end;
+      Add_Location (D, Primary_Labeled_Span (E_Msg.Sptr));
 
       --  Convert the secondary location if it is different from the primary
 
       if E_Msg.Optr.Ptr /= E_Msg.Sptr.Ptr then
-         declare
-            L : Labeled_Span_Type;
-         begin
-            L.Span       := E_Msg.Optr;
-            L.Is_Primary := False;
-            Add_Location (D, L);
-         end;
+         Add_Location (D, Secondary_Labeled_Span (E_Msg.Optr));
       end if;
 
       E_Next_Id := Errors.Table (E_Id).Next;
diff --git a/gcc/ada/diagnostics-pretty_emitter.adb 
b/gcc/ada/diagnostics-pretty_emitter.adb
index 389be8a6533..df27a5c6fde 100644
--- a/gcc/ada/diagnostics-pretty_emitter.adb
+++ b/gcc/ada/diagnostics-pretty_emitter.adb
@@ -1075,11 +1075,8 @@ package body Diagnostics.Pretty_Emitter is
                                     Diag : Diagnostic_Type)
                                     return Boolean
    is
-      Sub_Loc : constant Labeled_Span_Type :=
-        Get_Primary_Labeled_Span (Sub_Diag.Locations);
-
-      Diag_Loc : constant Labeled_Span_Type :=
-        Get_Primary_Labeled_Span (Diag.Locations);
+      Sub_Loc  : constant Labeled_Span_Type := Primary_Location (Sub_Diag);
+      Diag_Loc : constant Labeled_Span_Type := Primary_Location (Diag);
 
       function Has_Multiple_Files (Spans : Labeled_Span_List) return Boolean;
 
@@ -1124,11 +1121,8 @@ package body Diagnostics.Pretty_Emitter is
                                 Diag : Diagnostic_Type)
                                 return Boolean
    is
-      Sub_Loc : constant Labeled_Span_Type :=
-        Get_Primary_Labeled_Span (Sub_Diag.Locations);
-
-      Diag_Loc : constant Labeled_Span_Type :=
-        Get_Primary_Labeled_Span (Diag.Locations);
+      Sub_Loc  : constant Labeled_Span_Type := Primary_Location (Sub_Diag);
+      Diag_Loc : constant Labeled_Span_Type := Primary_Location (Diag);
    begin
       return Sub_Loc /= No_Labeled_Span
         and then Diag_Loc /= No_Labeled_Span
diff --git a/gcc/ada/diagnostics-utils.adb b/gcc/ada/diagnostics-utils.adb
index 3203e636290..a590536d917 100644
--- a/gcc/ada/diagnostics-utils.adb
+++ b/gcc/ada/diagnostics-utils.adb
@@ -223,7 +223,7 @@ package body Diagnostics.Utils is
         when Warning | Restriction_Warning | Default_Warning |
              Tagless_Warning => "warning",
         when Style => "style",
-        when Info | Info_Warning => "info"));
+        when Info => "info"));
 
    ------------------------------
    -- Get_Primary_Labeled_Span --
@@ -259,7 +259,6 @@ package body Diagnostics.Utils is
       if Warning_Doc_Switch
         and then Diag.Kind in Default_Warning
           | Info
-          | Info_Warning
           | Restriction_Warning
           | Style
           | Warning
@@ -273,7 +272,7 @@ package body Diagnostics.Utils is
 
             elsif Diag.Kind /= Info then
 
-               --  For Default_Warning and Info_Warning
+               --  For Default_Warning
 
                return "[enabled by default]";
             end if;
diff --git a/gcc/ada/diagnostics.adb b/gcc/ada/diagnostics.adb
index 8acc915b915..c9c5483693c 100644
--- a/gcc/ada/diagnostics.adb
+++ b/gcc/ada/diagnostics.adb
@@ -119,19 +119,8 @@ package body Diagnostics is
    function Primary_Location
      (Diagnostic : Sub_Diagnostic_Type) return Labeled_Span_Type
    is
-      use Labeled_Span_Lists;
-      Loc : Labeled_Span_Type;
-
-      It : Iterator := Iterate (Diagnostic.Locations);
    begin
-      while Has_Next (It) loop
-         Next (It, Loc);
-         if Loc.Is_Primary then
-            return Loc;
-         end if;
-      end loop;
-
-      return (others => <>);
+      return Get_Primary_Labeled_Span (Diagnostic.Locations);
    end Primary_Location;
 
    ------------------
diff --git a/gcc/ada/diagnostics.ads b/gcc/ada/diagnostics.ads
index f456927b06f..67800d93fc2 100644
--- a/gcc/ada/diagnostics.ads
+++ b/gcc/ada/diagnostics.ads
@@ -317,11 +317,7 @@ package Diagnostics is
       Tagless_Warning,
       --  Warning representing the old warnings created with the '?' insertion
       --  character.
-      Info,
-      Info_Warning
-      --  Info warnings are old messages where both warning and info were set
-      --  to true. These info messages behave like warnings and are usually
-      --  accompanied by a warning tag.
+      Info
    );
 
    type Diagnostic_Entry_Type is record
-- 
2.43.0

Reply via email to