with Alloc;
with Atree; use Atree;
with Einfo; use Einfo;
with Errout; use Errout;
with Fname; use Fname;
with Lib; use Lib;
with Nlists; use Nlists;
with Opt; use Opt;
with Sem; use Sem;
with Sem_Ch8; use Sem_Ch8;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Snames; use Snames;
with Stand; use Stand;
with Table;
package body Sem_Warn is
package Unreferenced_Entities is new Table.Table (
Table_Component_Type => Entity_Id,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => Alloc.Unreferenced_Entities_Initial,
Table_Increment => Alloc.Unreferenced_Entities_Increment,
Table_Name => "Unreferenced_Entities");
type Branch_Entry is record
Sloc : Source_Ptr;
Defs : Elist_Id;
Next : Nat;
end record;
package Branch_Table is new Table.Table (
Table_Component_Type => Branch_Entry,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => Alloc.Branches_Initial,
Table_Increment => Alloc.Branches_Increment,
Table_Name => "Branches");
type Conditional_Entry is record
If_Stmt : Boolean;
First_Branch : Nat;
Current_Branch : Nat;
end record;
package Conditional_Table is new Table.Table (
Table_Component_Type => Conditional_Entry,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => Alloc.Conditionals_Initial,
Table_Increment => Alloc.Conditionals_Increment,
Table_Name => "Conditionals");
package Conditional_Stack is new Table.Table (
Table_Component_Type => Nat,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => Alloc.Conditional_Stack_Initial,
Table_Increment => Alloc.Conditional_Stack_Increment,
Table_Name => "Conditional_Stack");
pragma Warnings (Off, Branch_Table);
pragma Warnings (Off, Conditional_Table);
pragma Warnings (Off, Conditional_Stack);
function Generic_Package_Spec_Entity (E : Entity_Id) return Boolean;
function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean;
procedure Check_References (E : Entity_Id; Anod : Node_Id := Empty) is
E1 : Entity_Id;
UR : Node_Id;
function Missing_Subunits return Boolean;
procedure Output_Reference_Error (M : String);
function Publicly_Referenceable (Ent : Entity_Id) return Boolean;
function Missing_Subunits return Boolean is
D : Node_Id;
begin
if not Unloaded_Subunits then
return False;
elsif E /= Main_Unit_Entity then
return True;
elsif Nkind (Unit_Declaration_Node (E)) in N_Proper_Body then
D := First (Declarations (Unit_Declaration_Node (E)));
while Present (D) loop
if Nkind (D) in N_Body_Stub then
return True;
end if;
Next (D);
end loop;
return False;
else
return True;
end if;
end Missing_Subunits;
procedure Output_Reference_Error (M : String) is
begin
if No (Anod) then
Error_Msg_N (M, E1);
else
declare
Parm : Node_Id;
Enod : Node_Id;
Defid : Entity_Id;
begin
Enod := Anod;
if Present (Parameter_Specifications (Anod)) then
Parm := First (Parameter_Specifications (Anod));
while Present (Parm) loop
Defid := Defining_Identifier (Parm);
if Chars (E1) = Chars (Defid) then
Enod := Defid;
exit;
end if;
Next (Parm);
end loop;
end if;
Error_Msg_NE (M, Enod, E1);
end;
end if;
end Output_Reference_Error;
function Publicly_Referenceable (Ent : Entity_Id) return Boolean is
P : Node_Id;
Prev : Node_Id;
begin
Prev := Ent;
P := Parent (Ent);
loop
case Nkind (P) is
when N_Empty =>
return True;
when N_Generic_Package_Declaration =>
return
not Is_List_Member (Prev)
or else List_Containing (Prev)
/= Generic_Formal_Declarations (P);
when N_Generic_Subprogram_Declaration =>
if Is_List_Member (Prev)
and then List_Containing (Prev) =
Generic_Formal_Declarations (P)
then
return False;
else
P := Parent (P);
end if;
when N_Subprogram_Body =>
if Ent /= Defining_Entity (P) then
return False;
else
P := Parent (P);
end if;
when N_Package_Body |
N_Task_Body |
N_Entry_Body |
N_Protected_Body |
N_Block_Statement |
N_Subunit =>
return False;
when others =>
Prev := P;
P := Parent (P);
end case;
end loop;
end Publicly_Referenceable;
begin
if Warning_Mode = Suppress
or else Serious_Errors_Detected /= 0
then
return;
end if;
if Missing_Subunits then
return;
end if;
E1 := First_Entity (E);
while Present (E1) loop
if Comes_From_Source (E1) and then not Warnings_Off (E1) then
if Ekind (E1) = E_Variable
or else
(Ekind (E1) = E_Out_Parameter
and then not Is_Protected_Type (Current_Scope))
then
if Ekind (E1) = E_Out_Parameter
and then Present (Spec_Entity (E1))
then
UR := Unset_Reference (Spec_Entity (E1));
else
UR := Unset_Reference (E1);
end if;
if Ekind (E1) = E_Out_Parameter
and then Present (Spec_Entity (E1))
and then Warnings_Off (Spec_Entity (E1))
then
null;
elsif Present (UR)
and then Is_Access_Type (Etype (E1))
then
Error_Msg_NE ("& may be null?", UR, E1);
goto Continue;
elsif Never_Set_In_Source (E1)
and then not Generic_Package_Spec_Entity (E1)
then
if Warn_On_No_Value_Assigned then
if Has_Pragma_Unreferenced (E1)
or else (Is_Formal (E1)
and then Present (Spec_Entity (E1))
and then
Has_Pragma_Unreferenced (Spec_Entity (E1)))
then
null;
else
Output_Reference_Error
("& is never assigned a value?");
if Ekind (E1) = E_Variable
and then Present (Hiding_Loop_Variable (E1))
then
Error_Msg_Sloc := Sloc (E1);
Error_Msg_N
("declaration hides &#?",
Hiding_Loop_Variable (E1));
Error_Msg_N
("for loop implicitly declares loop variable?",
Hiding_Loop_Variable (E1));
end if;
end if;
end if;
goto Continue;
elsif Warn_On_Constant
and then Ekind (E1) = E_Variable
and then Is_True_Constant (E1)
and then not Generic_Package_Spec_Entity (E1)
then
if (Is_Volatile (E1) or else Has_Volatile_Components (E1))
and then not Is_Imported (E1)
then
Error_Msg_N
("& is not modified, volatile has no effect?", E1);
else
Error_Msg_N
("& is not modified, could be declared constant?", E1);
end if;
end if;
if Warn_On_No_Value_Assigned and then Present (UR) then
UR := Original_Node (UR);
while Nkind (UR) = N_Type_Conversion
or else Nkind (UR) = N_Qualified_Expression
loop
UR := Expression (UR);
end loop;
if Nkind (Parent (UR)) = N_Selected_Component then
Error_Msg_Node_2 := Selector_Name (Parent (UR));
if not Comes_From_Source (Parent (UR)) then
declare
Comp : Entity_Id;
begin
Comp := First_Entity (Etype (E1));
while Present (Comp) loop
if Ekind (Comp) = E_Component
and then Nkind (Parent (Comp)) =
N_Component_Declaration
and then No (Expression (Parent (Comp)))
then
Error_Msg_Node_2 := Comp;
exit;
end if;
Next_Entity (Comp);
end loop;
end;
end if;
Error_Msg_N
("`&.&` may be referenced before it has a value?",
UR);
else
Error_Msg_N
("& may be referenced before it has a value?",
UR);
end if;
goto Continue;
end if;
end if;
if not Referenced (E1)
and then ((Check_Unreferenced and then not Is_Formal (E1))
or else
(Check_Unreferenced_Formals and then Is_Formal (E1))
or else
(Warn_On_Modified_Unread
and then Referenced_As_LHS (E1)))
and then (Is_Object (E1)
or else
Is_Type (E1)
or else
Ekind (E1) = E_Label
or else
Ekind (E1) = E_Exception
or else
Ekind (E1) = E_Named_Integer
or else
Ekind (E1) = E_Named_Real
or else
Is_Overloadable (E1)
or else
(Ekind (E1) = E_Package
and then
(Ekind (E) = E_Function
or else Ekind (E) = E_Package_Body
or else Ekind (E) = E_Procedure
or else Ekind (E) = E_Subprogram_Body
or else Ekind (E) = E_Block)))
and then Instantiation_Location (Sloc (E1)) = No_Location
and then not (Is_Formal (E1)
and then
Ekind (Scope (E1)) = E_Subprogram_Body
and then
Present (Spec_Entity (E1))
and then
Referenced (Spec_Entity (E1)))
and then
not (Is_Private_Type (E1)
and then
Present (Full_View (E1))
and then Referenced (Full_View (E1)))
and then not Has_Private_Declaration (E1)
and then not Is_Dispatching_Operation (E1)
and then not Publicly_Referenceable (E1)
and then Ekind (E1) /= E_Class_Wide_Type
and then ((Ekind (E1) /= E_Variable
and then Ekind (E1) /= E_Constant
and then Ekind (E1) /= E_Component)
or else not Is_Task_Type (Etype (E1)))
and then (Nkind (Unit (Cunit (Main_Unit))) /= N_Subunit
or else
Get_Source_Unit (E1) = Main_Unit)
then
if GNAT_Mode
or else not
Is_Internal_File_Name
(Unit_File_Name (Get_Source_Unit (E1)))
then
if Present (Anod) then
Output_Reference_Error ("& is not referenced?");
else
Unreferenced_Entities.Increment_Last;
Unreferenced_Entities.Table
(Unreferenced_Entities.Last) := E1;
end if;
end if;
elsif Is_Generic_Subprogram (E1)
and then not Is_Instantiated (E1)
and then not Publicly_Referenceable (E1)
and then Instantiation_Depth (Sloc (E1)) = 0
and then Warn_On_Redundant_Constructs
then
Unreferenced_Entities.Increment_Last;
Unreferenced_Entities.Table (Unreferenced_Entities.Last) := E1;
Set_Referenced (E1, False);
end if;
end if;
<<Continue>>
if ((Ekind (E1) = E_Package or else Ekind (E1) = E_Generic_Package)
and then Nkind (Parent (E1)) = N_Package_Specification
and then
Nkind (Original_Node (Unit_Declaration_Node (E1)))
/= N_Formal_Package_Declaration)
or else Ekind (E1) = E_Block
then
Check_References (E1);
end if;
Next_Entity (E1);
end loop;
end Check_References;
procedure Check_Unset_Reference (N : Node_Id) is
begin
if Warning_Mode = Suppress then
return;
end if;
if not Comes_From_Source (N)
and then not Is_Scalar_Type (Etype (N))
then
return;
end if;
case Nkind (N) is
when N_Identifier | N_Expanded_Name =>
declare
E : constant Entity_Id := Entity (N);
begin
if (Ekind (E) = E_Variable
or else Ekind (E) = E_Out_Parameter)
and then Never_Set_In_Source (E)
and then (No (Unset_Reference (E))
or else Earlier_In_Extended_Unit
(Sloc (N), Sloc (Unset_Reference (E))))
and then not Warnings_Off (E)
then
if Nkind (Parent (N)) = N_Selected_Component
and not Is_Access_Type (Etype (N))
then
declare
ES : constant Entity_Id :=
Entity (Selector_Name (Parent (N)));
begin
if Ekind (ES) = E_Discriminant
or else Present (Expression (Declaration_Node (ES)))
then
return;
end if;
end;
end if;
declare
SR : Entity_Id;
SE : constant Entity_Id := Scope (E);
begin
SR := Current_Scope;
while SR /= SE loop
if SR = Standard_Standard
or else Is_Subprogram (SR)
or else Is_Concurrent_Body (SR)
or else Is_Concurrent_Type (SR)
then
return;
end if;
SR := Scope (SR);
end loop;
if Is_Access_Type (Etype (N)) then
Access_Type_Case : declare
P : Node_Id;
function Process
(N : Node_Id)
return Traverse_Result;
function Ref_In (Nod : Node_Id) return Boolean;
function Process
(N : Node_Id)
return Traverse_Result
is
begin
if Is_Entity_Name (N)
and then Entity (N) = E
and then not Is_Dereferenced (N)
then
return Abandon;
else
return OK;
end if;
end Process;
function Ref_In (Nod : Node_Id) return Boolean is
function Traverse is new Traverse_Func (Process);
begin
return Traverse (Nod) = Abandon;
end Ref_In;
begin
if In_Instance then
return;
end if;
if not In_Extended_Main_Source_Unit (E)
or else
not In_Extended_Main_Source_Unit (N)
then
return;
end if;
if not Is_Dereferenced (N) then
return;
end if;
P := Parent (N);
loop
P := Parent (P);
exit when No (P);
if (Nkind (P) = N_If_Statement
or else
Nkind (P) = N_Elsif_Part)
and then Ref_In (Condition (P))
then
return;
elsif Nkind (P) = N_Loop_Statement
and then Present (Iteration_Scheme (P))
and then
Ref_In (Condition (Iteration_Scheme (P)))
then
return;
end if;
end loop;
end Access_Type_Case;
end if;
if Nkind (N) = N_Identifier then
Set_Unset_Reference (E, N);
else
Set_Unset_Reference (E, Selector_Name (N));
end if;
end;
end if;
end;
when N_Indexed_Component | N_Slice =>
Check_Unset_Reference (Prefix (N));
when N_Selected_Component =>
if Present (Entity (Selector_Name (N)))
and then Ekind (Entity (Selector_Name (N))) = E_Discriminant
then
null;
else
Check_Unset_Reference (Prefix (N));
end if;
when N_Type_Conversion | N_Qualified_Expression =>
Check_Unset_Reference (Expression (N));
when others =>
null;
end case;
end Check_Unset_Reference;
procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit) is
Cnode : Node_Id;
Item : Node_Id;
Lunit : Node_Id;
Ent : Entity_Id;
Munite : constant Entity_Id := Cunit_Entity (Main_Unit);
procedure Check_One_Unit (Unit : Unit_Number_Type);
procedure Check_One_Unit (Unit : Unit_Number_Type) is
Is_Visible_Renaming : Boolean := False;
Pack : Entity_Id;
procedure Check_Inner_Package (Pack : Entity_Id);
function Check_System_Aux return Boolean;
function Find_Package_Renaming
(P : Entity_Id;
L : Entity_Id) return Entity_Id;
procedure Check_Inner_Package (Pack : Entity_Id) is
E : Entity_Id;
Un : constant Node_Id := Sinfo.Unit (Cnode);
function Check_Use_Clause (N : Node_Id) return Traverse_Result;
procedure Check_Use_Clauses is new
Traverse_Proc (Check_Use_Clause);
function Check_Use_Clause (N : Node_Id) return Traverse_Result is
Nam : Node_Id;
begin
if Nkind (N) = N_Use_Package_Clause then
Nam := First (Names (N));
while Present (Nam) loop
if Entity (Nam) = Pack then
Error_Msg_Qual_Level := 1;
Error_Msg_NE
("no entities of package& are referenced?",
Nam, Pack);
Error_Msg_Qual_Level := 0;
end if;
Next (Nam);
end loop;
end if;
return OK;
end Check_Use_Clause;
begin
E := First_Entity (Pack);
while Present (E) loop
if Referenced (E) then
return;
end if;
Next_Entity (E);
end loop;
Check_Use_Clauses (Un);
end Check_Inner_Package;
function Check_System_Aux return Boolean is
Ent : Entity_Id;
begin
if Chars (Lunit) = Name_System
and then Scope (Lunit) = Standard_Standard
and then Present_System_Aux
then
Ent := First_Entity (System_Aux_Id);
while Present (Ent) loop
if Referenced (Ent) then
return True;
end if;
Next_Entity (Ent);
end loop;
end if;
return False;
end Check_System_Aux;
function Find_Package_Renaming
(P : Entity_Id;
L : Entity_Id) return Entity_Id
is
E1 : Entity_Id;
R : Entity_Id;
begin
Is_Visible_Renaming := False;
E1 := First_Entity (P);
while Present (E1) loop
if Ekind (E1) = E_Package
and then Renamed_Object (E1) = L
then
Is_Visible_Renaming := not Is_Hidden (E1);
return E1;
elsif Ekind (E1) = E_Package
and then No (Renamed_Object (E1))
and then not Is_Generic_Instance (E1)
then
R := Find_Package_Renaming (E1, L);
if Present (R) then
Is_Visible_Renaming := not Is_Hidden (R);
return R;
end if;
end if;
Next_Entity (E1);
end loop;
return Empty;
end Find_Package_Renaming;
begin
Cnode := Cunit (Unit);
if not In_Extended_Main_Source_Unit (Cnode) then
return;
elsif Configurable_Run_Time_Mode
and then Is_Predefined_File_Name (Unit_File_Name (Unit))
then
return;
end if;
Item := First (Context_Items (Cnode));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Implicit_With (Item)
and then In_Extended_Main_Source_Unit (Item)
then
Lunit := Entity (Name (Item));
if not Referenced (Lunit) then
if GNAT_Mode
or else not Is_Internal_File_Name (Unit_File_Name (Unit))
then
if Unit = Spec_Unit then
Set_Unreferenced_In_Spec (Item);
else
Error_Msg_N
("unit& is not referenced?", Name (Item));
end if;
end if;
elsif Present (Renamed_Entity (Munite))
and then Renamed_Entity (Munite) = Lunit
then
null;
elsif Ekind (Lunit) = E_Package then
if Is_Instantiated (Lunit) then
null;
elsif No (First_Entity (Lunit))
and then Has_Pragma_Elaborate_Body (Lunit)
then
null;
else
if Limited_Present (Item) then
Ent := First_Entity (Limited_View (Lunit));
else
Ent := First_Entity (Lunit);
end if;
loop
if No (Ent) then
if Unit = Spec_Unit then
Set_No_Entities_Ref_In_Spec (Item);
elsif Check_System_Aux then
null;
else
Error_Msg_N
("no entities of & are referenced?",
Name (Item));
Pack := Find_Package_Renaming (Munite, Lunit);
if Present (Pack)
and then not Warnings_Off (Lunit)
then
Error_Msg_NE
("no entities of & are referenced?",
Unit_Declaration_Node (Pack),
Pack);
end if;
end if;
exit;
elsif Referenced (Ent)
or else Referenced_As_LHS (Ent)
then
if Ekind (Munite) = E_Package_Body then
Pack :=
Find_Package_Renaming
(Spec_Entity (Munite), Lunit);
end if;
if Unreferenced_In_Spec (Item) then
Error_Msg_N
("unit& is not referenced in spec?",
Name (Item));
elsif No_Entities_Ref_In_Spec (Item) then
Error_Msg_N
("no entities of & are referenced in spec?",
Name (Item));
else
if Ekind (Ent) = E_Package then
Check_Inner_Package (Ent);
end if;
exit;
end if;
if not Is_Visible_Renaming then
Error_Msg_N
("\with clause might be moved to body?",
Name (Item));
end if;
exit;
else
Next_Entity (Ent);
end if;
end loop;
end if;
elsif Is_Generic_Unit (Lunit) then
if not Is_Instantiated (Lunit) then
if Unit = Spec_Unit then
Set_Unreferenced_In_Spec (Item);
else
Error_Msg_N
("unit& is never instantiated?", Name (Item));
end if;
elsif Unreferenced_In_Spec (Item) then
Error_Msg_N
("unit& is not instantiated in spec?", Name (Item));
Error_Msg_N
("\with clause can be moved to body?", Name (Item));
end if;
end if;
end if;
Next (Item);
end loop;
end Check_One_Unit;
begin
if not Opt.Check_Withs
or else Operating_Mode = Check_Syntax
then
return;
end if;
if Nkind (Unit (Cunit (Main_Unit))) = N_Subunit then
return;
end if;
if Spec_Unit = No_Unit then
for Unit in Main_Unit .. Last_Unit loop
Check_One_Unit (Unit);
end loop;
else
Check_One_Unit (Spec_Unit);
end if;
end Check_Unused_Withs;
function Generic_Package_Spec_Entity (E : Entity_Id) return Boolean is
S : Entity_Id;
begin
if Is_Package_Body_Entity (E) then
return False;
else
S := Scope (E);
loop
if S = Standard_Standard then
return False;
elsif Ekind (S) = E_Generic_Package then
return True;
elsif Ekind (S) = E_Package then
S := Scope (S);
else
return False;
end if;
end loop;
end if;
end Generic_Package_Spec_Entity;
function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean is
function Check_For_Warnings (N : Node_Id) return Traverse_Result;
function Traverse is new Traverse_Func (Check_For_Warnings);
function Check_For_Warnings (N : Node_Id) return Traverse_Result is
R : constant Node_Id := Original_Node (N);
begin
if Nkind (R) in N_Has_Entity
and then Present (Entity (R))
and then Warnings_Off (Entity (R))
then
return Abandon;
else
return OK_Orig;
end if;
end Check_For_Warnings;
begin
return Traverse (N) = Abandon;
exception
when others =>
return False;
end Operand_Has_Warnings_Suppressed;
procedure Output_Unreferenced_Messages is
E : Entity_Id;
begin
for J in Unreferenced_Entities.First ..
Unreferenced_Entities.Last
loop
E := Unreferenced_Entities.Table (J);
if not Referenced (E) and then not Warnings_Off (E) then
case Ekind (E) is
when E_Variable =>
if Referenced_As_LHS (E)
and then No (Address_Clause (E))
and then not Is_Volatile (E)
then
if Warn_On_Modified_Unread
and then not Is_Imported (E)
and then not Is_Aliased (E)
and then No (Renamed_Object (E))
then
Error_Msg_N
("variable & is assigned but never read?", E);
end if;
else
if Present (Renamed_Object (E))
and then Comes_From_Source (Renamed_Object (E))
then
Error_Msg_N
("renamed variable & is not referenced?", E);
else
Error_Msg_N
("variable & is not referenced?", E);
end if;
end if;
when E_Constant =>
if Present (Renamed_Object (E))
and then Comes_From_Source (Renamed_Object (E))
then
Error_Msg_N ("renamed constant & is not referenced?", E);
else
Error_Msg_N ("constant & is not referenced?", E);
end if;
when E_In_Parameter |
E_Out_Parameter |
E_In_Out_Parameter =>
if Nkind (Original_Node (Unit_Declaration_Node (Scope (E))))
/= N_Subprogram_Renaming_Declaration
then
Error_Msg_N ("formal parameter & is not referenced?", E);
end if;
when E_Named_Integer |
E_Named_Real =>
Error_Msg_N ("named number & is not referenced?", E);
when E_Enumeration_Literal =>
Error_Msg_N ("literal & is not referenced?", E);
when E_Function =>
Error_Msg_N ("function & is not referenced?", E);
when E_Procedure =>
Error_Msg_N ("procedure & is not referenced?", E);
when E_Generic_Procedure =>
Error_Msg_N
("generic procedure & is never instantiated?", E);
when E_Generic_Function =>
Error_Msg_N ("generic function & is never instantiated?", E);
when Type_Kind =>
Error_Msg_N ("type & is not referenced?", E);
when others =>
Error_Msg_N ("& is not referenced?", E);
end case;
Set_Warnings_Off (E);
end if;
end loop;
end Output_Unreferenced_Messages;
function Set_Warning_Switch (C : Character) return Boolean is
begin
case C is
when 'a' =>
Check_Unreferenced := True;
Check_Unreferenced_Formals := True;
Check_Withs := True;
Constant_Condition_Warnings := True;
Implementation_Unit_Warnings := True;
Ineffective_Inline_Warnings := True;
Warn_On_Ada_2005_Compatibility := True;
Warn_On_Bad_Fixed_Value := True;
Warn_On_Constant := True;
Warn_On_Export_Import := True;
Warn_On_Modified_Unread := True;
Warn_On_No_Value_Assigned := True;
Warn_On_Obsolescent_Feature := True;
Warn_On_Redundant_Constructs := True;
Warn_On_Unchecked_Conversion := True;
Warn_On_Unrecognized_Pragma := True;
when 'A' =>
Check_Unreferenced := False;
Check_Unreferenced_Formals := False;
Check_Withs := False;
Constant_Condition_Warnings := False;
Elab_Warnings := False;
Implementation_Unit_Warnings := False;
Ineffective_Inline_Warnings := False;
Warn_On_Ada_2005_Compatibility := False;
Warn_On_Bad_Fixed_Value := False;
Warn_On_Constant := False;
Warn_On_Dereference := False;
Warn_On_Export_Import := False;
Warn_On_Hiding := False;
Warn_On_Modified_Unread := False;
Warn_On_No_Value_Assigned := False;
Warn_On_Obsolescent_Feature := False;
Warn_On_Redundant_Constructs := False;
Warn_On_Unchecked_Conversion := False;
Warn_On_Unrecognized_Pragma := False;
when 'b' =>
Warn_On_Bad_Fixed_Value := True;
when 'B' =>
Warn_On_Bad_Fixed_Value := False;
when 'c' =>
Constant_Condition_Warnings := True;
when 'C' =>
Constant_Condition_Warnings := False;
when 'd' =>
Warn_On_Dereference := True;
when 'D' =>
Warn_On_Dereference := False;
when 'e' =>
Warning_Mode := Treat_As_Error;
when 'f' =>
Check_Unreferenced_Formals := True;
when 'F' =>
Check_Unreferenced_Formals := False;
when 'g' =>
Warn_On_Unrecognized_Pragma := True;
when 'G' =>
Warn_On_Unrecognized_Pragma := False;
when 'h' =>
Warn_On_Hiding := True;
when 'H' =>
Warn_On_Hiding := False;
when 'i' =>
Implementation_Unit_Warnings := True;
when 'I' =>
Implementation_Unit_Warnings := False;
when 'j' =>
Warn_On_Obsolescent_Feature := True;
when 'J' =>
Warn_On_Obsolescent_Feature := False;
when 'k' =>
Warn_On_Constant := True;
when 'K' =>
Warn_On_Constant := False;
when 'l' =>
Elab_Warnings := True;
when 'L' =>
Elab_Warnings := False;
when 'm' =>
Warn_On_Modified_Unread := True;
when 'M' =>
Warn_On_Modified_Unread := False;
when 'n' =>
Warning_Mode := Normal;
when 'o' =>
Address_Clause_Overlay_Warnings := True;
when 'O' =>
Address_Clause_Overlay_Warnings := False;
when 'p' =>
Ineffective_Inline_Warnings := True;
when 'P' =>
Ineffective_Inline_Warnings := False;
when 'r' =>
Warn_On_Redundant_Constructs := True;
when 'R' =>
Warn_On_Redundant_Constructs := False;
when 's' =>
Warning_Mode := Suppress;
when 'u' =>
Check_Unreferenced := True;
Check_Withs := True;
Check_Unreferenced_Formals := True;
when 'U' =>
Check_Unreferenced := False;
Check_Withs := False;
Check_Unreferenced_Formals := False;
when 'v' =>
Warn_On_No_Value_Assigned := True;
when 'V' =>
Warn_On_No_Value_Assigned := False;
when 'x' =>
Warn_On_Export_Import := True;
when 'X' =>
Warn_On_Export_Import := False;
when 'y' =>
Warn_On_Ada_2005_Compatibility := True;
when 'Y' =>
Warn_On_Ada_2005_Compatibility := False;
when 'z' =>
Warn_On_Unchecked_Conversion := True;
when 'Z' =>
Warn_On_Unchecked_Conversion := False;
when 'w' =>
null;
when others =>
return False;
end case;
return True;
end Set_Warning_Switch;
procedure Warn_On_Known_Condition (C : Node_Id) is
P : Node_Id;
begin
if In_Inlined_Body then
return;
end if;
if Constant_Condition_Warnings
and then Nkind (C) = N_Identifier
and then
(Entity (C) = Standard_False or else Entity (C) = Standard_True)
and then Comes_From_Source (Original_Node (C))
and then not In_Instance
then
P := Parent (C);
loop
if No (P) then
return;
elsif Nkind (P) in N_Declaration
or else
Nkind (P) in N_Later_Decl_Item
then
return;
elsif Nkind (Original_Node (P)) = N_Pragma
and then Chars (Original_Node (P)) = Name_Assert
then
return;
end if;
exit when Is_Statement (P);
P := Parent (P);
end loop;
if not Operand_Has_Warnings_Suppressed (C) then
declare
True_Branch : Boolean := Entity (C) = Standard_True;
Cond : Node_Id := C;
begin
if Present (Parent (C))
and then Nkind (Parent (C)) = N_Op_Not
then
True_Branch := not True_Branch;
Cond := Parent (C);
end if;
if True_Branch then
if Is_Entity_Name (Original_Node (C))
and then Nkind (Cond) /= N_Op_Not
then
Error_Msg_NE
("object & is always True?", Cond, Original_Node (C));
else
Error_Msg_N ("condition is always True?", Cond);
end if;
else
Error_Msg_N ("condition is always False?", Cond);
end if;
end;
end if;
end if;
end Warn_On_Known_Condition;
end Sem_Warn;