diff options
author | Viljar Indus <indus@adacore.com> | 2024-09-16 12:14:00 +0300 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-11-26 10:49:34 +0100 |
commit | 7cdb07a77bac31dc39f8eea2e7eaabf99bbd00ab (patch) | |
tree | 2cd6ffe453d67771b3bc54623f9ca322c5b4cb16 /gcc/ada | |
parent | 92e782e7758b068a6399c97f8b8e1972d67b0739 (diff) | |
download | gcc-7cdb07a77bac31dc39f8eea2e7eaabf99bbd00ab.zip gcc-7cdb07a77bac31dc39f8eea2e7eaabf99bbd00ab.tar.gz gcc-7cdb07a77bac31dc39f8eea2e7eaabf99bbd00ab.tar.bz2 |
ada: Simplify code
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.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/diagnostics-converter.adb | 64 | ||||
-rw-r--r-- | gcc/ada/diagnostics-pretty_emitter.adb | 14 | ||||
-rw-r--r-- | gcc/ada/diagnostics-utils.adb | 5 | ||||
-rw-r--r-- | gcc/ada/diagnostics.adb | 13 | ||||
-rw-r--r-- | 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 45bb19c..e1613f6 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 389be8a..df27a5c 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 3203e63..a590536 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 8acc915..c9c5483 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 f456927..67800d9 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 |