From: Viljar Indus <in...@adacore.com> Reuse the same implementation in Errout and Errutil.
gcc/ada/ChangeLog: * errout.adb: Remove implmentation of Write_Error_Summary. * erroutc.adb: Add implemenetation of Write_Error_Summary. * erroutc.ads: Add spec of Write_Error_Summary. * errutil.adb: Remove implementation for writing the error summary. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/errout.adb | 141 -------------------------------------------- gcc/ada/erroutc.adb | 138 +++++++++++++++++++++++++++++++++++++++++++ gcc/ada/erroutc.ads | 3 + gcc/ada/errutil.adb | 73 +---------------------- 4 files changed, 142 insertions(+), 213 deletions(-) diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 4070d92992d..7e24970f187 100644 --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -2495,9 +2495,6 @@ package body Errout is -- Emit all error messages in the table use the pretty printed format if -- -gnatdF is used otherwise use the brief format. - procedure Write_Error_Summary; - -- Write error summary - procedure Write_Header (Sfile : Source_File_Index); -- Write header line (compiling or checking given file) @@ -2615,144 +2612,6 @@ package body Errout is Set_Standard_Output; end Emit_Error_Msgs; - ------------------------- - -- Write_Error_Summary -- - ------------------------- - - procedure Write_Error_Summary is - begin - -- Extra blank line if error messages or source listing were output - - if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List - then - Write_Eol; - end if; - - -- Message giving number of lines read and number of errors detected. - -- This normally goes to Standard_Output. The exception is when brief - -- mode is not set, verbose mode (or full list mode) is set, and - -- there are errors. In this case we send the message to standard - -- error to make sure that *something* appears on standard error - -- in an error situation. - - if Total_Errors_Detected + Warnings_Detected /= 0 - and then not Brief_Output - and then (Verbose_Mode or Full_List) - then - Set_Standard_Error; - end if; - - -- Message giving total number of lines. Don't give this message if - -- the Main_Source line is unknown (this happens in error situations, - -- e.g. when integrated preprocessing fails). - - if Main_Source_File > No_Source_File then - Write_Str (" "); - Write_Int (Num_Source_Lines (Main_Source_File)); - - if Num_Source_Lines (Main_Source_File) = 1 then - Write_Str (" line: "); - else - Write_Str (" lines: "); - end if; - end if; - - if Total_Errors_Detected = 0 then - Write_Str ("No errors"); - - elsif Total_Errors_Detected = 1 then - Write_Str ("1 error"); - - else - Write_Int (Total_Errors_Detected); - Write_Str (" errors"); - end if; - - -- We now need to output warnings. When using -gnatwe, all warnings - -- should be treated as errors, except for warnings originating from - -- the use of the Compile_Time_Warning pragma. Another situation - -- where a warning might be treated as an error is when the source - -- code contains a Warning_As_Error pragma. - -- When warnings are treated as errors, we still log them as - -- warnings, but we add a message denoting how many of these warnings - -- are also errors. - - declare - Warnings_Count : constant Int := Warnings_Detected; - - Compile_Time_Warnings : Int; - -- Number of warnings that come from a Compile_Time_Warning - -- pragma. - - Non_Compile_Time_Warnings : Int; - -- Number of warnings that do not come from a Compile_Time_Warning - -- pragmas. - - begin - if Warnings_Count > 0 then - Write_Str (", "); - Write_Int (Warnings_Count); - Write_Str (" warning"); - - if Warnings_Count > 1 then - Write_Char ('s'); - end if; - - Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings; - Non_Compile_Time_Warnings := - Warnings_Count - Compile_Time_Warnings; - - if Warning_Mode = Treat_As_Error - and then Non_Compile_Time_Warnings > 0 - then - Write_Str (" ("); - - if Compile_Time_Warnings > 0 then - Write_Int (Non_Compile_Time_Warnings); - Write_Str (" "); - end if; - - Write_Str ("treated as error"); - - if Non_Compile_Time_Warnings > 1 then - Write_Char ('s'); - end if; - - Write_Char (')'); - - elsif Warnings_Treated_As_Errors > 0 then - Write_Str (" ("); - - if Warnings_Treated_As_Errors /= Warnings_Count then - Write_Int (Warnings_Treated_As_Errors); - Write_Str (" "); - end if; - - Write_Str ("treated as error"); - - if Warnings_Treated_As_Errors > 1 then - Write_Str ("s"); - end if; - - Write_Str (")"); - end if; - end if; - end; - - if Info_Messages /= 0 then - Write_Str (", "); - Write_Int (Info_Messages); - Write_Str (" info message"); - - if Info_Messages > 1 then - Write_Char ('s'); - end if; - end if; - - Write_Eol; - Set_Standard_Output; - end Write_Error_Summary; - ------------------ -- Write_Header -- ------------------ diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb index 209159e1765..d025273a4a4 100644 --- a/gcc/ada/erroutc.adb +++ b/gcc/ada/erroutc.adb @@ -2027,4 +2027,142 @@ package body Erroutc is end if; end Warnings_Suppressed; + ------------------------- + -- Write_Error_Summary -- + ------------------------- + + procedure Write_Error_Summary is + begin + -- Extra blank line if error messages or source listing were output + + if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List + then + Write_Eol; + end if; + + -- Message giving number of lines read and number of errors detected. + -- This normally goes to Standard_Output. The exception is when brief + -- mode is not set, verbose mode (or full list mode) is set, and + -- there are errors. In this case we send the message to standard + -- error to make sure that *something* appears on standard error + -- in an error situation. + + if Total_Errors_Detected + Warnings_Detected /= 0 + and then not Brief_Output + and then (Verbose_Mode or Full_List) + then + Set_Standard_Error; + end if; + + -- Message giving total number of lines. Don't give this message if + -- the Main_Source line is unknown (this happens in error situations, + -- e.g. when integrated preprocessing fails). + + if Main_Source_File > No_Source_File then + Write_Str (" "); + Write_Int (Num_Source_Lines (Main_Source_File)); + + if Num_Source_Lines (Main_Source_File) = 1 then + Write_Str (" line: "); + else + Write_Str (" lines: "); + end if; + end if; + + if Total_Errors_Detected = 0 then + Write_Str ("No errors"); + + elsif Total_Errors_Detected = 1 then + Write_Str ("1 error"); + + else + Write_Int (Total_Errors_Detected); + Write_Str (" errors"); + end if; + + -- We now need to output warnings. When using -gnatwe, all warnings + -- should be treated as errors, except for warnings originating from + -- the use of the Compile_Time_Warning pragma. Another situation + -- where a warning might be treated as an error is when the source + -- code contains a Warning_As_Error pragma. + -- When warnings are treated as errors, we still log them as + -- warnings, but we add a message denoting how many of these warnings + -- are also errors. + + declare + Warnings_Count : constant Int := Warnings_Detected; + + Compile_Time_Warnings : Int; + -- Number of warnings that come from a Compile_Time_Warning + -- pragma. + + Non_Compile_Time_Warnings : Int; + -- Number of warnings that do not come from a Compile_Time_Warning + -- pragmas. + + begin + if Warnings_Count > 0 then + Write_Str (", "); + Write_Int (Warnings_Count); + Write_Str (" warning"); + + if Warnings_Count > 1 then + Write_Char ('s'); + end if; + + Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings; + Non_Compile_Time_Warnings := + Warnings_Count - Compile_Time_Warnings; + + if Warning_Mode = Treat_As_Error + and then Non_Compile_Time_Warnings > 0 + then + Write_Str (" ("); + + if Compile_Time_Warnings > 0 then + Write_Int (Non_Compile_Time_Warnings); + Write_Str (" "); + end if; + + Write_Str ("treated as error"); + + if Non_Compile_Time_Warnings > 1 then + Write_Char ('s'); + end if; + + Write_Char (')'); + + elsif Warnings_Treated_As_Errors > 0 then + Write_Str (" ("); + + if Warnings_Treated_As_Errors /= Warnings_Count then + Write_Int (Warnings_Treated_As_Errors); + Write_Str (" "); + end if; + + Write_Str ("treated as error"); + + if Warnings_Treated_As_Errors > 1 then + Write_Str ("s"); + end if; + + Write_Str (")"); + end if; + end if; + end; + + if Info_Messages /= 0 then + Write_Str (", "); + Write_Int (Info_Messages); + Write_Str (" info message"); + + if Info_Messages > 1 then + Write_Char ('s'); + end if; + end if; + + Write_Eol; + Set_Standard_Output; + end Write_Error_Summary; + end Erroutc; diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads index 0853bdbeab6..a861b85c676 100644 --- a/gcc/ada/erroutc.ads +++ b/gcc/ada/erroutc.ads @@ -705,4 +705,7 @@ package Erroutc is -- given by Warning_As_Error pragmas, as stored in the Warnings_As_Errors -- table. + procedure Write_Error_Summary; + -- Write error summary + end Erroutc; diff --git a/gcc/ada/errutil.adb b/gcc/ada/errutil.adb index 0891d4618aa..aba6cfc20a3 100644 --- a/gcc/ada/errutil.adb +++ b/gcc/ada/errutil.adb @@ -413,78 +413,7 @@ package body Errutil is -- Output error summary if verbose or full list mode if Verbose_Mode or else Full_List then - - -- Extra blank line if error messages or source listing were output - - if Total_Errors_Detected + Warnings_Detected > 0 - or else Full_List - then - Write_Eol; - end if; - - -- Message giving number of lines read and number of errors detected. - -- This normally goes to Standard_Output. The exception is when brief - -- mode is not set, verbose mode (or full list mode) is set, and - -- there are errors. In this case we send the message to standard - -- error to make sure that *something* appears on standard error in - -- an error situation. - - -- Historical note: Formerly, only the "# errors" suffix was sent - -- to stderr, whereas "# lines:" appeared on stdout. This caused - -- some problems on now-obsolete ports, but there seems to be no - -- reason to revert this page since it would be incompatible. - - if Total_Errors_Detected + Warnings_Detected /= 0 - and then not Brief_Output - and then (Verbose_Mode or Full_List) - then - Set_Standard_Error; - end if; - - -- Message giving total number of lines - - Write_Str (" "); - Write_Int (Num_Source_Lines (Main_Source_File)); - - if Num_Source_Lines (Main_Source_File) = 1 then - Write_Str (" line: "); - else - Write_Str (" lines: "); - end if; - - if Total_Errors_Detected = 0 then - Write_Str ("No errors"); - - elsif Total_Errors_Detected = 1 then - Write_Str ("1 error"); - - else - Write_Int (Total_Errors_Detected); - Write_Str (" errors"); - end if; - - if Warnings_Detected /= 0 then - Write_Str (", "); - Write_Int (Warnings_Detected); - Write_Str (" warning"); - - if Warnings_Detected /= 1 then - Write_Char ('s'); - end if; - - if Warning_Mode = Treat_As_Error then - Write_Str (" (treated as error"); - - if Warnings_Detected /= 1 then - Write_Char ('s'); - end if; - - Write_Char (')'); - end if; - end if; - - Write_Eol; - Set_Standard_Output; + Write_Error_Summary; end if; if Maximum_Messages /= 0 then -- 2.43.0