From: Viljar Indus <[email protected]>
Verify that every diagnostic that has a switch also has the same
diagnostic marked as one of the diagnostics for that same switch.
Additionally verify that for every diagnostic marked for a switch
these diagnostics have the same switch marked as its switch.
gcc/ada/ChangeLog:
* errid.adb (Check_Diagnostic_To_Switch_Consistency): New subprogram
for checking the consistency of diagnostics.
(Check_Switch_To_Diagnostic_Consistency) New subprogram for checking
the consistency of switches.
(Add_All_Diagnostic_Rules): Check diagnostic consitency.
(Add_All_Switch_Rules): Check switch consitency.
Tested on x86_64-pc-linux-gnu (before the recent bootstrap breakage), committed
on master.
---
gcc/ada/errid.adb | 69 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/gcc/ada/errid.adb b/gcc/ada/errid.adb
index a432f016652..f20e08fab06 100644
--- a/gcc/ada/errid.adb
+++ b/gcc/ada/errid.adb
@@ -23,19 +23,84 @@
-- --
------------------------------------------------------------------------------
-with Erroutc.SARIF_Emitter; use Erroutc.SARIF_Emitter;
+with Errid.Diagnostic_Repository; use Errid.Diagnostic_Repository;
+with Errid.Switch_Repository; use Errid.Switch_Repository;
+with Erroutc.SARIF_Emitter; use Erroutc.SARIF_Emitter;
package body Errid is
Doc_Directory : constant String := "./error_codes";
Doc_Extension : constant String := ".md";
+ Diagnostic_Inconsistency : exception;
+
procedure Add_All_Diagnostic_Rules (Printer : in out SARIF_Printer);
-- Add all active Diagnostic_Id-s to the SARIF_Printer
procedure Add_All_Switch_Rules (Printer : in out SARIF_Printer);
-- Add all active Switch_Id-s to the SARIF_Printer
+ procedure Check_Diagnostic_To_Switch_Consistency (D_Id : Diagnostic_Id);
+ -- Check that if a diagnostic has a switch then that diagnostic is also
+ -- included in the list of diagnostics for that switch.
+
+ procedure Check_Switch_To_Diagnostic_Consistency (S_Id : Switch_Id);
+ -- Check that if a Switch has diagnostics then that diagnostic has the same
+ -- switch marked as its switch.
+
+ --------------------------------------------
+ -- Check_Diagnostic_To_Switch_Consistency --
+ --------------------------------------------
+
+ procedure Check_Diagnostic_To_Switch_Consistency (D_Id : Diagnostic_Id) is
+ D : constant Diagnostic_Entry_Type := Diagnostic_Entries (D_Id);
+ Err_Msg : constant String :=
+ Switch_Id'Image (D.Switch)
+ & " should contain "
+ & Diagnostic_Id'Image (D_Id)
+ & " in its diagnostics";
+ begin
+ if D.Switch = No_Switch_Id then
+ return;
+ end if;
+
+ if Switches (D.Switch).Diagnostics = null then
+ raise Diagnostic_Inconsistency with Err_Msg;
+ end if;
+
+ for DD of Switches (D.Switch).Diagnostics.all loop
+ if D_Id = DD then
+ return;
+ end if;
+ end loop;
+
+ raise Diagnostic_Inconsistency with Err_Msg;
+ end Check_Diagnostic_To_Switch_Consistency;
+
+ --------------------------------------------
+ -- Check_Switch_To_Diagnostic_Consistency --
+ --------------------------------------------
+
+ procedure Check_Switch_To_Diagnostic_Consistency (S_Id : Switch_Id) is
+ S : constant Switch_Type := Switches (S_Id);
+ D : Diagnostic_Entry_Type;
+ begin
+ if S.Diagnostics = null then
+ return;
+ end if;
+
+ for D_Id of S.Diagnostics.all loop
+ D := Diagnostic_Entries (D_Id);
+ if D.Switch /= S_Id then
+ raise Diagnostic_Inconsistency
+ with
+ Switch_Id'Image (S_Id)
+ & " should be the switch for "
+ & Diagnostic_Id'Image (D_Id);
+ end if;
+ end loop;
+ end Check_Switch_To_Diagnostic_Consistency;
+
----------------------------
-- Get_Documentation_File --
----------------------------
@@ -72,6 +137,7 @@ package body Errid is
for Id in Diagnostic_Id loop
if Id /= No_Diagnostic_Id then
Diagnostic_Id_Lists.Append (Printer.Diagnostics, Id);
+ Check_Diagnostic_To_Switch_Consistency (Id);
end if;
end loop;
end Add_All_Diagnostic_Rules;
@@ -86,6 +152,7 @@ package body Errid is
for S in Switch_Id loop
if S /= No_Switch_Id then
Switch_Id_Lists.Append (Printer.Switches, S);
+ Check_Switch_To_Diagnostic_Consistency (S);
end if;
end loop;
end Add_All_Switch_Rules;
--
2.51.0