]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Simplify code
authorViljar Indus <indus@adacore.com>
Mon, 16 Sep 2024 09:14:00 +0000 (12:14 +0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 Nov 2024 09:49:34 +0000 (10:49 +0100)
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.

gcc/ada/diagnostics-converter.adb
gcc/ada/diagnostics-pretty_emitter.adb
gcc/ada/diagnostics-utils.adb
gcc/ada/diagnostics.adb
gcc/ada/diagnostics.ads

index 45bb19c0a84093d5a74d8a3295e718ae7c08b64b..e1613f674c685866d2a4ee14d37084da0434c347 100644 (file)
@@ -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;
index 389be8a6533dd378b042be1cec4e5d2d0f166f9c..df27a5c6fde46e93743abff180af6c6b705845a0 100644 (file)
@@ -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
index 3203e63629092d14b7ceaff880046f651051793f..a590536d917b594d46bde949a1eceaaebdccfb29 100644 (file)
@@ -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;
index 8acc915b91555df8005175c3e37445f12ab591d7..c9c5483693c9a692bdf3b66fb5389ec3b3fffdbc 100644 (file)
@@ -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;
 
    ------------------
index f456927b06fe6bbeb5e1b2143e53991add923216..67800d93fc24b0b32fcc9dd6ccfb0b2b28352504 100644 (file)
@@ -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