with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Expander; use Expander;
with Exp_Ch7; use Exp_Ch7;
with Exp_Tss; use Exp_Tss;
with Fname; use Fname;
with Freeze; use Freeze;
with Itypes; use Itypes;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Lib; use Lib;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch4; use Sem_Ch4;
with Sem_Ch5; use Sem_Ch5;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch10; use Sem_Ch10;
with Sem_Ch12; use Sem_Ch12;
with Sem_Disp; use Sem_Disp;
with Sem_Dist; use Sem_Dist;
with Sem_Elim; use Sem_Elim;
with Sem_Eval; use Sem_Eval;
with Sem_Mech; use Sem_Mech;
with Sem_Prag; use Sem_Prag;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sem_Type; use Sem_Type;
with Sem_Warn; use Sem_Warn;
with Sinput; use Sinput;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.CN; use Sinfo.CN;
with Snames; use Snames;
with Stringt; use Stringt;
with Style;
with Stylesw; use Stylesw;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Urealp; use Urealp;
with Validsw; use Validsw;
package body Sem_Ch6 is
May_Hide_Profile : Boolean := False;
procedure Analyze_Return_Type (N : Node_Id);
procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id);
procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id);
type Conformance_Type is
(Type_Conformant, Mode_Conformant, Subtype_Conformant, Fully_Conformant);
procedure Check_Conformance
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Ctype : Conformance_Type;
Errmsg : Boolean;
Conforms : out Boolean;
Err_Loc : Node_Id := Empty;
Get_Inst : Boolean := False;
Skip_Controlling_Formals : Boolean := False);
procedure Check_Overriding_Indicator
(Subp : Entity_Id;
Does_Override : Boolean);
procedure Check_Subprogram_Order (N : Node_Id);
procedure Check_Returns
(HSS : Node_Id;
Mode : Character;
Err : out Boolean;
Proc : Entity_Id := Empty);
function Conforming_Types
(T1 : Entity_Id;
T2 : Entity_Id;
Ctype : Conformance_Type;
Get_Inst : Boolean := False) return Boolean;
procedure Enter_Overloaded_Entity (S : Entity_Id);
procedure Install_Entity (E : Entity_Id);
procedure Install_Formals (Id : Entity_Id);
function Is_Non_Overriding_Operation
(Prev_E : Entity_Id;
New_E : Entity_Id) return Boolean;
procedure Make_Inequality_Operator (S : Entity_Id);
procedure May_Need_Actuals (Fun : Entity_Id);
procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id);
procedure Set_Formal_Validity (Formal_Id : Entity_Id);
procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is
Designator : constant Entity_Id :=
Analyze_Subprogram_Specification (Specification (N));
Scop : constant Entity_Id := Current_Scope;
begin
Generate_Definition (Designator);
Set_Is_Abstract (Designator);
New_Overloaded_Entity (Designator);
Check_Delayed_Subprogram (Designator);
Set_Categorization_From_Scope (Designator, Scop);
if Ekind (Scope (Designator)) = E_Protected_Type then
Error_Msg_N
("abstract subprogram not allowed in protected type", N);
end if;
Generate_Reference_To_Formals (Designator);
end Analyze_Abstract_Subprogram_Declaration;
procedure Analyze_Function_Call (N : Node_Id) is
P : constant Node_Id := Name (N);
L : constant List_Id := Parameter_Associations (N);
Actual : Node_Id;
begin
Analyze (P);
if Nkind (P) = N_Selected_Component
and then Name (N) /= P
and then Is_Rewrite_Substitution (N)
and then Present (Etype (N))
then
return;
end if;
if Etype (P) = Any_Type then
Set_Etype (N, Any_Type);
return;
end if;
if Present (L) then
Actual := First (L);
while Present (Actual) loop
Analyze (Actual);
Check_Parameterless_Call (Actual);
Next (Actual);
end loop;
end if;
Analyze_Call (N);
end Analyze_Function_Call;
procedure Analyze_Generic_Subprogram_Body
(N : Node_Id;
Gen_Id : Entity_Id)
is
Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id);
Kind : constant Entity_Kind := Ekind (Gen_Id);
Body_Id : Entity_Id;
New_N : Node_Id;
Spec : Node_Id;
begin
if Nkind (N) /= N_Subprogram_Body_Stub then
New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
Rewrite (N, New_N);
Start_Generic;
end if;
Spec := Specification (N);
Body_Id := Defining_Entity (Spec);
if Kind = E_Generic_Procedure
and then Nkind (Spec) /= N_Procedure_Specification
then
Error_Msg_N ("invalid body for generic procedure ", Body_Id);
return;
elsif Kind = E_Generic_Function
and then Nkind (Spec) /= N_Function_Specification
then
Error_Msg_N ("invalid body for generic function ", Body_Id);
return;
end if;
Set_Corresponding_Body (Gen_Decl, Body_Id);
if Has_Completion (Gen_Id)
and then Nkind (Parent (N)) /= N_Subunit
then
Error_Msg_N ("duplicate generic body", N);
return;
else
Set_Has_Completion (Gen_Id);
end if;
if Nkind (N) = N_Subprogram_Body_Stub then
Set_Ekind (Defining_Entity (Specification (N)), Kind);
else
Set_Corresponding_Spec (N, Gen_Id);
end if;
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N));
end if;
New_Scope (Gen_Id);
declare
E : Entity_Id;
First_Ent : Entity_Id;
begin
First_Ent := First_Entity (Gen_Id);
E := First_Ent;
while Present (E) and then not Is_Formal (E) loop
Install_Entity (E);
Next_Entity (E);
end loop;
Set_Use (Generic_Formal_Declarations (Gen_Decl));
Body_Id := Analyze_Subprogram_Specification (Spec);
if Present (E) then
Set_First_Entity (Gen_Id, E);
while Present (E) loop
Install_Entity (E);
Next_Formal (E);
end loop;
end if;
Set_Ekind (Gen_Id, Ekind (Body_Id));
Set_Ekind (Body_Id, E_Subprogram_Body);
Set_Convention (Body_Id, Convention (Gen_Id));
Set_Scope (Body_Id, Scope (Gen_Id));
Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id);
if Nkind (N) = N_Subprogram_Body_Stub then
Set_Ekind (Gen_Id, Kind);
Set_Ekind (Body_Id, Kind);
if Present (First_Ent) then
Set_First_Entity (Gen_Id, First_Ent);
end if;
End_Scope;
return;
end if;
Set_Is_Immediately_Visible (Gen_Id);
Reference_Body_Formals (Gen_Id, Body_Id);
Set_Actual_Subtypes (N, Current_Scope);
Analyze_Declarations (Declarations (N));
Check_Completion;
Analyze (Handled_Statement_Sequence (N));
Save_Global_References (Original_Node (N));
if Present (First_Ent) then
Set_First_Entity (Gen_Id, First_Ent);
end if;
Check_References (Gen_Id);
end;
Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope);
End_Scope;
Check_Subprogram_Order (N);
Set_Ekind (Gen_Id, Kind);
Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False);
Style.Check_Identifier (Body_Id, Gen_Id);
End_Generic;
end Analyze_Generic_Subprogram_Body;
procedure Analyze_Operator_Symbol (N : Node_Id) is
Par : constant Node_Id := Parent (N);
begin
if (Nkind (Par) = N_Function_Call and then N = Name (Par))
or else Nkind (Par) = N_Function_Instantiation
or else (Nkind (Par) = N_Indexed_Component and then N = Prefix (Par))
or else (Nkind (Par) = N_Pragma_Argument_Association
and then not Is_Pragma_String_Literal (Par))
or else Nkind (Par) = N_Subprogram_Renaming_Declaration
or else (Nkind (Par) = N_Attribute_Reference
and then Attribute_Name (Par) /= Name_Value)
then
Find_Direct_Name (N);
else
Change_Operator_Symbol_To_String_Literal (N);
Analyze (N);
end if;
end Analyze_Operator_Symbol;
procedure Analyze_Parameter_Association (N : Node_Id) is
begin
Analyze (Explicit_Actual_Parameter (N));
end Analyze_Parameter_Association;
procedure Analyze_Procedure_Call (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
P : constant Node_Id := Name (N);
Actuals : constant List_Id := Parameter_Associations (N);
Actual : Node_Id;
New_N : Node_Id;
procedure Analyze_Call_And_Resolve;
procedure Analyze_Call_And_Resolve is
begin
if Nkind (N) = N_Procedure_Call_Statement then
Analyze_Call (N);
Resolve (N, Standard_Void_Type);
else
Analyze (N);
end if;
end Analyze_Call_And_Resolve;
begin
Analyze (P);
if Analyzed (N) then
return;
end if;
if Etype (P) = Any_Type then
Set_Etype (N, Any_Type);
return;
end if;
if Present (Actuals) then
Actual := First (Actuals);
while Present (Actual) loop
Analyze (Actual);
Check_Parameterless_Call (Actual);
Next (Actual);
end loop;
end if;
if Nkind (P) = N_Attribute_Reference
and then (Attribute_Name (P) = Name_Elab_Spec
or else Attribute_Name (P) = Name_Elab_Body)
then
if Present (Actuals) then
Error_Msg_N
("no parameters allowed for this call", First (Actuals));
return;
end if;
Set_Etype (N, Standard_Void_Type);
Set_Analyzed (N);
elsif Is_Entity_Name (P)
and then Is_Record_Type (Etype (Entity (P)))
and then Remote_AST_I_Dereference (P)
then
return;
elsif Is_Entity_Name (P)
and then Ekind (Entity (P)) /= E_Entry_Family
then
if Is_Access_Type (Etype (P))
and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
and then No (Actuals)
and then Comes_From_Source (N)
then
Error_Msg_N ("missing explicit dereference in call", N);
end if;
Analyze_Call_And_Resolve;
elsif Is_Entity_Name (P)
and then Nkind (P) = N_Identifier
and then Ekind (Entity (P)) = E_Entry_Family
and then Present (Actuals)
and then No (Next (First (Actuals)))
then
New_N :=
Make_Indexed_Component (Loc,
Prefix =>
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc),
Selector_Name => New_Occurrence_Of (Entity (P), Loc)),
Expressions => Actuals);
Set_Name (N, New_N);
Set_Etype (New_N, Standard_Void_Type);
Set_Parameter_Associations (N, No_List);
Analyze_Call_And_Resolve;
elsif Nkind (P) = N_Explicit_Dereference then
if Ekind (Etype (P)) = E_Subprogram_Type then
Analyze_Call_And_Resolve;
else
Error_Msg_N ("expect access to procedure in call", P);
end if;
elsif Is_Access_Type (Etype (P))
and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
then
if Present (Actuals) then
Analyze_Call_And_Resolve;
else
Error_Msg_N ("missing explicit dereference in call ", N);
end if;
elsif Nkind (P) = N_Selected_Component
and then (Ekind (Entity (Selector_Name (P))) = E_Entry
or else
Ekind (Entity (Selector_Name (P))) = E_Procedure
or else
Ekind (Entity (Selector_Name (P))) = E_Function)
then
Analyze_Call_And_Resolve;
elsif Nkind (P) = N_Selected_Component
and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family
and then Present (Actuals)
and then No (Next (First (Actuals)))
then
New_N :=
Make_Indexed_Component (Loc,
Prefix => New_Copy (P),
Expressions => Actuals);
Set_Name (N, New_N);
Set_Etype (New_N, Standard_Void_Type);
Set_Parameter_Associations (N, No_List);
Analyze_Call_And_Resolve;
elsif Nkind (P) = N_Indexed_Component
and then Nkind (Prefix (P)) = N_Selected_Component
and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family
then
Analyze_Call_And_Resolve;
elsif Nkind (P) = N_Indexed_Component
and then Nkind (Prefix (P)) = N_Identifier
and then Ekind (Entity (Prefix (P))) = E_Entry_Family
then
New_N :=
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc),
Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc));
Rewrite (Prefix (P), New_N);
Analyze (P);
Analyze_Call_And_Resolve;
else
Error_Msg_N ("invalid procedure or entry call", N);
end if;
end Analyze_Procedure_Call;
procedure Analyze_Return_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Expr : Node_Id;
Scope_Id : Entity_Id;
Kind : Entity_Kind;
R_Type : Entity_Id;
begin
Scope_Id := Empty;
for J in reverse 0 .. Scope_Stack.Last loop
Scope_Id := Scope_Stack.Table (J).Entity;
exit when Ekind (Scope_Id) /= E_Block and then
Ekind (Scope_Id) /= E_Loop;
end loop;
pragma Assert (Present (Scope_Id));
Kind := Ekind (Scope_Id);
Expr := Expression (N);
if Kind /= E_Function
and then Kind /= E_Generic_Function
and then Kind /= E_Procedure
and then Kind /= E_Generic_Procedure
and then Kind /= E_Entry
and then Kind /= E_Entry_Family
then
Error_Msg_N ("illegal context for return statement", N);
elsif Present (Expr) then
if Kind = E_Function or else Kind = E_Generic_Function then
Set_Return_Present (Scope_Id);
R_Type := Etype (Scope_Id);
Set_Return_Type (N, R_Type);
Analyze_And_Resolve (Expr, R_Type);
if Ada_Version >= Ada_05
and then Ekind (R_Type) = E_Anonymous_Access_Type
then
Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr)));
Analyze_And_Resolve (Expr, R_Type);
end if;
if (Is_Class_Wide_Type (Etype (Expr))
or else Is_Dynamically_Tagged (Expr))
and then not Is_Class_Wide_Type (R_Type)
then
Error_Msg_N
("dynamically tagged expression not allowed!", Expr);
end if;
Apply_Constraint_Check (Expr, R_Type);
if Is_Return_By_Reference_Type (Etype (Scope_Id))
and then Object_Access_Level (Expr)
> Subprogram_Access_Level (Scope_Id)
then
Rewrite (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Accessibility_Check_Failed));
Analyze (N);
Error_Msg_N
("cannot return a local value by reference?", N);
Error_Msg_NE
("\& will be raised at run time?",
N, Standard_Program_Error);
end if;
elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then
Error_Msg_N ("procedure cannot return value (use function)", N);
else
Error_Msg_N ("accept statement cannot return value", N);
end if;
else
if Kind = E_Function or Kind = E_Generic_Function then
Error_Msg_N ("missing expression in return from function", N);
end if;
if (Ekind (Scope_Id) = E_Procedure
or else Ekind (Scope_Id) = E_Generic_Procedure)
and then No_Return (Scope_Id)
then
Error_Msg_N
("RETURN statement not allowed (No_Return)", N);
end if;
end if;
Check_Unreachable_Code (N);
end Analyze_Return_Statement;
procedure Analyze_Return_Type (N : Node_Id) is
Designator : constant Entity_Id := Defining_Entity (N);
Typ : Entity_Id := Empty;
begin
if Result_Definition (N) /= Error then
if Nkind (Result_Definition (N)) = N_Access_Definition then
Typ := Access_Definition (N, Result_Definition (N));
Set_Parent (Typ, Result_Definition (N));
Set_Is_Local_Anonymous_Access (Typ);
Set_Etype (Designator, Typ);
else
Find_Type (Result_Definition (N));
Typ := Entity (Result_Definition (N));
Set_Etype (Designator, Typ);
if Ekind (Typ) = E_Incomplete_Type
or else (Is_Class_Wide_Type (Typ)
and then
Ekind (Root_Type (Typ)) = E_Incomplete_Type)
then
Error_Msg_N
("invalid use of incomplete type", Result_Definition (N));
end if;
end if;
else
Set_Etype (Designator, Any_Type);
end if;
end Analyze_Return_Type;
procedure Analyze_Subprogram_Body (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Body_Spec : constant Node_Id := Specification (N);
Body_Id : Entity_Id := Defining_Entity (Body_Spec);
Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id);
Body_Deleted : constant Boolean := False;
HSS : Node_Id;
Spec_Id : Entity_Id;
Spec_Decl : Node_Id := Empty;
Last_Formal : Entity_Id := Empty;
Conformant : Boolean;
Missing_Ret : Boolean;
P_Ent : Entity_Id;
procedure Check_Inline_Pragma (Spec : in out Node_Id);
procedure Copy_Parameter_List (Plist : List_Id);
procedure Verify_Overriding_Indicator;
procedure Check_Inline_Pragma (Spec : in out Node_Id) is
Prag : Node_Id;
Plist : List_Id;
begin
if not Expander_Active then
return;
end if;
if Is_List_Member (N)
and then Present (Next (N))
and then Nkind (Next (N)) = N_Pragma
then
Prag := Next (N);
if Nkind (Prag) = N_Pragma
and then
(Get_Pragma_Id (Chars (Prag)) = Pragma_Inline_Always
or else
(Front_End_Inlining
and then Get_Pragma_Id (Chars (Prag)) = Pragma_Inline))
and then
Chars
(Expression (First (Pragma_Argument_Associations (Prag))))
= Chars (Body_Id)
then
Prag := Next (N);
else
Prag := Empty;
end if;
else
Prag := Empty;
end if;
if Present (Prag) then
if Present (Spec_Id) then
if List_Containing (N) =
List_Containing (Unit_Declaration_Node (Spec_Id))
then
Analyze (Prag);
end if;
else
declare
Subp : constant Entity_Id :=
Make_Defining_Identifier (Loc, Chars (Body_Id));
Decl : constant Node_Id :=
Make_Subprogram_Declaration (Loc,
Specification => New_Copy_Tree (Specification (N)));
begin
Set_Defining_Unit_Name (Specification (Decl), Subp);
if Present (First_Formal (Body_Id)) then
Plist := New_List;
Copy_Parameter_List (Plist);
Set_Parameter_Specifications
(Specification (Decl), Plist);
end if;
Insert_Before (N, Decl);
Analyze (Decl);
Analyze (Prag);
Set_Has_Pragma_Inline (Subp);
if Get_Pragma_Id (Chars (Prag)) = Pragma_Inline_Always then
Set_Is_Inlined (Subp);
Set_Next_Rep_Item (Prag, First_Rep_Item (Subp));
Set_First_Rep_Item (Subp, Prag);
end if;
Spec := Subp;
end;
end if;
end if;
end Check_Inline_Pragma;
procedure Copy_Parameter_List (Plist : List_Id) is
Formal : Entity_Id;
begin
Formal := First_Formal (Body_Id);
while Present (Formal) loop
Append
(Make_Parameter_Specification (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Sloc (Formal),
Chars => Chars (Formal)),
In_Present => In_Present (Parent (Formal)),
Out_Present => Out_Present (Parent (Formal)),
Parameter_Type =>
New_Reference_To (Etype (Formal), Loc),
Expression =>
New_Copy_Tree (Expression (Parent (Formal)))),
Plist);
Next_Formal (Formal);
end loop;
end Copy_Parameter_List;
procedure Verify_Overriding_Indicator is
begin
if Must_Override (Body_Spec)
and then not Is_Overriding_Operation (Spec_Id)
then
Error_Msg_NE
("subprogram& is not overriding", Body_Spec, Spec_Id);
elsif Must_Not_Override (Body_Spec)
and then Is_Overriding_Operation (Spec_Id)
then
Error_Msg_NE
("subprogram& overrides inherited operation",
Body_Spec, Spec_Id);
end if;
end Verify_Overriding_Indicator;
begin
if Debug_Flag_C then
Write_Str ("==== Compiling subprogram body ");
Write_Name (Chars (Body_Id));
Write_Str (" from ");
Write_Location (Loc);
Write_Eol;
end if;
Trace_Scope (N, Body_Id, " Analyze subprogram");
if Present (Prev_Id)
and then not Is_Overloadable (Prev_Id)
and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
or else Comes_From_Source (Prev_Id))
then
if Is_Generic_Subprogram (Prev_Id) then
Spec_Id := Prev_Id;
Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
Analyze_Generic_Subprogram_Body (N, Spec_Id);
return;
else
Enter_Name (Body_Id);
return;
end if;
elsif Prev_Id = Body_Id
and then Has_Completion (Body_Id)
then
return;
else
Body_Id := Analyze_Subprogram_Specification (Body_Spec);
if Nkind (N) = N_Subprogram_Body_Stub
or else No (Corresponding_Spec (N))
then
Spec_Id := Find_Corresponding_Spec (N);
if Error_Posted (N) then
return;
end if;
if No (Spec_Id) then
Freeze_Before (N, Body_Id);
elsif Nkind (Parent (N)) = N_Compilation_Unit then
Freeze_Before (N, Spec_Id);
end if;
else
Spec_Id := Corresponding_Spec (N);
end if;
end if;
if Comes_From_Source (Body_Id)
and then Serious_Errors_Detected = 0
then
P_Ent := Body_Id;
loop
P_Ent := Scope (P_Ent);
exit when No (P_Ent) or else P_Ent = Standard_Standard;
if Is_Subprogram (P_Ent) then
Set_Is_Inlined (P_Ent, False);
if Comes_From_Source (P_Ent)
and then Has_Pragma_Inline (P_Ent)
then
Cannot_Inline
("cannot inline& (nested subprogram)?",
N, P_Ent);
end if;
end if;
end loop;
end if;
Check_Inline_Pragma (Spec_Id);
if No (Spec_Id)
and then Comes_From_Source (N)
and then Is_Protected_Type (Current_Scope)
then
declare
Decl : Node_Id;
Plist : List_Id;
Formal : Entity_Id;
New_Spec : Node_Id;
begin
Formal := First_Formal (Body_Id);
if Present (Formal)
or else Expander_Active
then
Plist := New_List;
else
Plist := No_List;
end if;
Copy_Parameter_List (Plist);
if Nkind (Body_Spec) = N_Procedure_Specification then
New_Spec :=
Make_Procedure_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Sloc (Body_Id),
Chars => Chars (Body_Id)),
Parameter_Specifications => Plist);
else
New_Spec :=
Make_Function_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Sloc (Body_Id),
Chars => Chars (Body_Id)),
Parameter_Specifications => Plist,
Result_Definition =>
New_Occurrence_Of (Etype (Body_Id), Loc));
end if;
Decl :=
Make_Subprogram_Declaration (Loc,
Specification => New_Spec);
Insert_Before (N, Decl);
Spec_Id := Defining_Unit_Name (New_Spec);
Set_Comes_From_Source (Spec_Id, True);
Analyze (Decl);
Set_Has_Completion (Spec_Id);
Set_Convention (Spec_Id, Convention_Protected);
end;
elsif Present (Spec_Id) then
Spec_Decl := Unit_Declaration_Node (Spec_Id);
Verify_Overriding_Indicator;
end if;
if Present (Spec_Id) then
Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
if Is_Child_Unit (Spec_Id) then
Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False);
end if;
if Style_Check then
Style.Check_Identifier (Body_Id, Spec_Id);
end if;
Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
if Is_Abstract (Spec_Id) then
Error_Msg_N ("an abstract subprogram cannot have a body", N);
return;
else
Set_Convention (Body_Id, Convention (Spec_Id));
Set_Has_Completion (Spec_Id);
if Is_Protected_Type (Scope (Spec_Id)) then
Set_Privals_Chain (Spec_Id, New_Elmt_List);
end if;
if Present (Spec_Decl)
and then not Comes_From_Source (N)
and then
(Nkind (Original_Node (Spec_Decl)) =
N_Subprogram_Renaming_Declaration
or else (Present (Corresponding_Body (Spec_Decl))
and then
Nkind (Unit_Declaration_Node
(Corresponding_Body (Spec_Decl))) =
N_Subprogram_Renaming_Declaration))
then
Conformant := True;
else
Check_Conformance
(Body_Id, Spec_Id,
Fully_Conformant, True, Conformant, Body_Id);
end if;
if not Conformant
and then not Mode_Conformant (Body_Id, Spec_Id)
then
return;
end if;
end if;
if Spec_Id /= Body_Id then
Reference_Body_Formals (Spec_Id, Body_Id);
end if;
if Nkind (N) /= N_Subprogram_Body_Stub then
Set_Corresponding_Spec (N, Spec_Id);
if Comes_From_Source (Spec_Id)
and then Present (First_Entity (Spec_Id))
and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type
and then Is_Tagged_Type (Etype (First_Entity (Spec_Id)))
and then Present (Abstract_Interfaces
(Etype (First_Entity (Spec_Id))))
and then Present (Corresponding_Concurrent_Type
(Etype (First_Entity (Spec_Id))))
then
Set_Etype (First_Entity (Spec_Id),
Corresponding_Concurrent_Type
(Etype (First_Entity (Spec_Id))));
end if;
if Ada_Version >= Ada_05 then
declare
F_Spec : Entity_Id;
F_Body : Entity_Id;
begin
F_Spec := First_Formal (Spec_Id);
F_Body := First_Formal (Body_Id);
while Present (F_Spec) loop
if Ekind (Etype (F_Spec)) = E_Anonymous_Access_Type
and then
From_With_Type (Designated_Type (Etype (F_Spec)))
then
Set_Etype (F_Spec, Etype (F_Body));
end if;
Next_Formal (F_Spec);
Next_Formal (F_Body);
end loop;
end;
end if;
Install_Formals (Spec_Id);
Last_Formal := Last_Entity (Spec_Id);
New_Scope (Spec_Id);
Set_Is_Immediately_Visible (Spec_Id);
end if;
Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id);
Set_Ekind (Body_Id, E_Subprogram_Body);
Set_Scope (Body_Id, Scope (Spec_Id));
else
if Style_Check
and then Comes_From_Source (Body_Id)
and then not Suppress_Style_Checks (Body_Id)
and then not In_Instance
then
Style.Body_With_No_Spec (N);
end if;
New_Overloaded_Entity (Body_Id);
if Nkind (N) /= N_Subprogram_Body_Stub then
Set_Acts_As_Spec (N);
Generate_Definition (Body_Id);
Generate_Reference
(Body_Id, Body_Id, 'b', Set_Ref => False, Force => True);
Generate_Reference_To_Formals (Body_Id);
Install_Formals (Body_Id);
New_Scope (Body_Id);
end if;
end if;
if Nkind (Parent (N)) = N_Subunit
and then Comes_From_Source (N)
and then not Error_Posted (Body_Id)
and then Nkind (Corresponding_Stub (Parent (N))) =
N_Subprogram_Body_Stub
then
declare
Old_Id : constant Entity_Id :=
Defining_Entity
(Specification (Corresponding_Stub (Parent (N))));
Conformant : Boolean := False;
begin
if No (Spec_Id) then
Check_Fully_Conformant (Body_Id, Old_Id);
else
Check_Conformance
(Body_Id, Old_Id, Fully_Conformant, False, Conformant);
if not Conformant then
Set_Has_Completion (Old_Id, False);
end if;
end if;
end;
end if;
Set_Has_Completion (Body_Id);
Check_Eliminated (Body_Id);
if Nkind (N) = N_Subprogram_Body_Stub then
return;
elsif Present (Spec_Id)
and then Expander_Active
and then
(Is_Always_Inlined (Spec_Id)
or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining))
then
Build_Body_To_Inline (N, Spec_Id);
end if;
if Is_Compilation_Unit (Body_Id)
and then Scope (Body_Id) = Standard_Standard
then
Install_Private_With_Clauses (Body_Id);
end if;
HSS := Handled_Statement_Sequence (N);
Set_Actual_Subtypes (N, Current_Scope);
Analyze_Declarations (Declarations (N));
Check_Completion;
Analyze (HSS);
Process_End_Label (HSS, 't', Current_Scope);
End_Scope;
Check_Subprogram_Order (N);
Set_Analyzed (Body_Id);
if Present (Spec_Id) then
Validate_Categorization_Dependency (N, Spec_Id);
if Is_Child_Unit (Spec_Id) then
Validate_Categorization_Dependency
(Unit_Declaration_Node (Spec_Id), Spec_Id);
end if;
if Present (Last_Formal) then
Set_Next_Entity
(Last_Entity (Body_Id), Next_Entity (Last_Formal));
Set_Next_Entity (Last_Formal, Empty);
Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
Set_Last_Entity (Spec_Id, Last_Formal);
else
Set_First_Entity (Body_Id, First_Entity (Spec_Id));
Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
Set_First_Entity (Spec_Id, Empty);
Set_Last_Entity (Spec_Id, Empty);
end if;
end if;
if Nkind (Body_Spec) = N_Function_Specification then
declare
Id : Entity_Id;
begin
if Present (Spec_Id) then
Id := Spec_Id;
else
Id := Body_Id;
end if;
if Return_Present (Id) then
Check_Returns (HSS, 'F', Missing_Ret);
if Missing_Ret then
Set_Has_Missing_Return (Id);
end if;
elsif not Is_Machine_Code_Subprogram (Id)
and then not Body_Deleted
then
Error_Msg_N ("missing RETURN statement in function body", N);
end if;
end;
elsif Nkind (Body_Spec) = N_Procedure_Specification
and then Present (Spec_Id)
and then No_Return (Spec_Id)
then
Check_Returns (HSS, 'P', Missing_Ret, Spec_Id);
end if;
declare
Stm : Node_Id := First (Statements (HSS));
begin
if Nkind (Stm) = N_Label then
Next (Stm);
end if;
declare
Ostm : constant Node_Id := Original_Node (Stm);
begin
if Nkind (Ostm) = N_Raise_Statement then
return;
elsif Nkind (Ostm) = N_Procedure_Call_Statement then
if Is_Entity_Name (Name (Ostm)) then
declare
Ent : constant Entity_Id := Entity (Name (Ostm));
begin
if Ekind (Ent) = E_Procedure
and then No_Return (Ent)
then
return;
elsif Chars (Ent) = Name_Raise_Exception then
return;
end if;
end;
end if;
end if;
end;
end;
declare
E1, E2 : Entity_Id;
begin
if Present (Spec_Id) then
E1 := First_Entity (Spec_Id);
while Present (E1) loop
if Ekind (E1) = E_Out_Parameter then
E2 := First_Entity (Body_Id);
while Present (E2) loop
exit when Chars (E1) = Chars (E2);
Next_Entity (E2);
end loop;
if Present (E2) then
Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
end if;
end if;
Next_Entity (E1);
end loop;
end if;
if not Body_Deleted then
Check_References (Body_Id);
end if;
end;
end Analyze_Subprogram_Body;
procedure Analyze_Subprogram_Declaration (N : Node_Id) is
Designator : constant Entity_Id :=
Analyze_Subprogram_Specification (Specification (N));
Scop : constant Entity_Id := Current_Scope;
begin
Generate_Definition (Designator);
Validate_RCI_Subprogram_Declaration (N);
Trace_Scope
(N,
Defining_Entity (N),
" Analyze subprogram spec. ");
if Debug_Flag_C then
Write_Str ("==== Compiling subprogram spec ");
Write_Name (Chars (Designator));
Write_Str (" from ");
Write_Location (Sloc (N));
Write_Eol;
end if;
New_Overloaded_Entity (Designator);
Check_Delayed_Subprogram (Designator);
if Elaboration_Checks_Suppressed (Designator) then
Set_Kill_Elaboration_Checks (Designator);
end if;
if Scop /= Standard_Standard
and then not Is_Child_Unit (Designator)
then
Set_Categorization_From_Scope (Designator, Scop);
else
New_Scope (Designator);
Set_Categorization_From_Pragmas (N);
Validate_Categorization_Dependency (N, Designator);
Pop_Scope;
end if;
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Body_Required (Parent (N), True);
if Ada_Version >= Ada_05
and then Nkind (Specification (N)) = N_Procedure_Specification
and then Null_Present (Specification (N))
then
Error_Msg_N
("null procedure cannot be declared at library level", N);
end if;
end if;
Generate_Reference_To_Formals (Designator);
Check_Eliminated (Designator);
if Nkind (Specification (N)) = N_Procedure_Specification
and then Null_Present (Specification (N))
then
Set_Has_Completion (Designator);
Set_Is_Inlined (Designator);
end if;
end Analyze_Subprogram_Declaration;
function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is
Designator : constant Entity_Id := Defining_Entity (N);
Formals : constant List_Id := Parameter_Specifications (N);
function Has_Interface_Formals (T : List_Id) return Boolean;
function Has_Interface_Formals (T : List_Id) return Boolean is
Param_Spec : Node_Id;
Formal : Entity_Id;
begin
Param_Spec := First (T);
while Present (Param_Spec) loop
Formal := Defining_Identifier (Param_Spec);
if Is_Class_Wide_Type (Etype (Formal)) then
null;
elsif Is_Interface (Etype (Formal)) then
return True;
end if;
Next (Param_Spec);
end loop;
return False;
end Has_Interface_Formals;
begin
Generate_Definition (Designator);
if Nkind (N) = N_Function_Specification then
Set_Ekind (Designator, E_Function);
Set_Mechanism (Designator, Default_Mechanism);
else
Set_Ekind (Designator, E_Procedure);
Set_Etype (Designator, Standard_Void_Type);
end if;
Set_Scope (Designator, Current_Scope);
if Present (Formals) then
New_Scope (Designator);
Process_Formals (Formals, N);
if Ada_Version >= Ada_05
and then Comes_From_Source (Designator)
and then Present (First_Entity (Designator))
and then (Ekind (Etype (First_Entity (Designator)))
= E_Protected_Type
or else
Ekind (Etype (First_Entity (Designator)))
= E_Task_Type)
and then Present (Corresponding_Record_Type
(Etype (First_Entity (Designator))))
and then Present (Abstract_Interfaces
(Corresponding_Record_Type
(Etype (First_Entity (Designator)))))
then
Set_Etype (First_Entity (Designator),
Corresponding_Record_Type (Etype (First_Entity (Designator))));
end if;
End_Scope;
elsif Nkind (N) = N_Function_Specification then
Analyze_Return_Type (N);
end if;
if Nkind (N) = N_Function_Specification then
if Nkind (Designator) = N_Defining_Operator_Symbol then
Valid_Operator_Definition (Designator);
end if;
May_Need_Actuals (Designator);
if Is_Abstract (Etype (Designator))
and then Nkind (Parent (N))
/= N_Abstract_Subprogram_Declaration
and then (Nkind (Parent (N)))
/= N_Formal_Abstract_Subprogram_Declaration
and then (Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
or else not Is_Entity_Name (Name (Parent (N)))
or else not Is_Abstract (Entity (Name (Parent (N)))))
then
Error_Msg_N
("function that returns abstract type must be abstract", N);
end if;
end if;
if Ada_Version >= Ada_05
and then Comes_From_Source (N)
and then Nkind (Parent (N)) /= N_Abstract_Subprogram_Declaration
and then (Nkind (N) /= N_Procedure_Specification
or else
not Null_Present (N))
and then Has_Interface_Formals (Formals)
then
Error_Msg_Name_1 := Chars (Defining_Unit_Name
(Specification (Parent (N))));
Error_Msg_N
("(Ada 2005) interface subprogram % must be abstract or null", N);
end if;
return Designator;
end Analyze_Subprogram_Specification;
procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is
Decl : constant Node_Id := Unit_Declaration_Node (Subp);
Original_Body : Node_Id;
Body_To_Analyze : Node_Id;
Max_Size : constant := 10;
Stat_Count : Integer := 0;
function Has_Excluded_Declaration (Decls : List_Id) return Boolean;
function Has_Excluded_Statement (Stats : List_Id) return Boolean;
function Has_Pending_Instantiation return Boolean;
function Has_Single_Return return Boolean;
procedure Remove_Pragmas;
function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
function Has_Excluded_Declaration (Decls : List_Id) return Boolean is
D : Node_Id;
function Is_Unchecked_Conversion (D : Node_Id) return Boolean;
function Is_Unchecked_Conversion (D : Node_Id) return Boolean is
Id : constant Node_Id := Name (D);
Conv : Entity_Id;
begin
if Nkind (Id) = N_Identifier
and then Chars (Id) = Name_Unchecked_Conversion
then
Conv := Current_Entity (Id);
elsif (Nkind (Id) = N_Selected_Component
or else Nkind (Id) = N_Expanded_Name)
and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion
then
Conv := Current_Entity (Selector_Name (Id));
else
return False;
end if;
return Present (Conv)
and then Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Conv)))
and then Is_Intrinsic_Subprogram (Conv);
end Is_Unchecked_Conversion;
begin
D := First (Decls);
while Present (D) loop
if (Nkind (D) = N_Function_Instantiation
and then not Is_Unchecked_Conversion (D))
or else Nkind (D) = N_Protected_Type_Declaration
or else Nkind (D) = N_Package_Declaration
or else Nkind (D) = N_Package_Instantiation
or else Nkind (D) = N_Subprogram_Body
or else Nkind (D) = N_Procedure_Instantiation
or else Nkind (D) = N_Task_Type_Declaration
then
Cannot_Inline
("cannot inline & (non-allowed declaration)?", D, Subp);
return True;
end if;
Next (D);
end loop;
return False;
end Has_Excluded_Declaration;
function Has_Excluded_Statement (Stats : List_Id) return Boolean is
S : Node_Id;
E : Node_Id;
begin
S := First (Stats);
while Present (S) loop
Stat_Count := Stat_Count + 1;
if Nkind (S) = N_Abort_Statement
or else Nkind (S) = N_Asynchronous_Select
or else Nkind (S) = N_Conditional_Entry_Call
or else Nkind (S) = N_Delay_Relative_Statement
or else Nkind (S) = N_Delay_Until_Statement
or else Nkind (S) = N_Selective_Accept
or else Nkind (S) = N_Timed_Entry_Call
then
Cannot_Inline
("cannot inline & (non-allowed statement)?", S, Subp);
return True;
elsif Nkind (S) = N_Block_Statement then
if Present (Declarations (S))
and then Has_Excluded_Declaration (Declarations (S))
then
return True;
elsif Present (Handled_Statement_Sequence (S))
and then
(Present
(Exception_Handlers (Handled_Statement_Sequence (S)))
or else
Has_Excluded_Statement
(Statements (Handled_Statement_Sequence (S))))
then
return True;
end if;
elsif Nkind (S) = N_Case_Statement then
E := First (Alternatives (S));
while Present (E) loop
if Has_Excluded_Statement (Statements (E)) then
return True;
end if;
Next (E);
end loop;
elsif Nkind (S) = N_If_Statement then
if Has_Excluded_Statement (Then_Statements (S)) then
return True;
end if;
if Present (Elsif_Parts (S)) then
E := First (Elsif_Parts (S));
while Present (E) loop
if Has_Excluded_Statement (Then_Statements (E)) then
return True;
end if;
Next (E);
end loop;
end if;
if Present (Else_Statements (S))
and then Has_Excluded_Statement (Else_Statements (S))
then
return True;
end if;
elsif Nkind (S) = N_Loop_Statement
and then Has_Excluded_Statement (Statements (S))
then
return True;
end if;
Next (S);
end loop;
return False;
end Has_Excluded_Statement;
function Has_Pending_Instantiation return Boolean is
S : Entity_Id := Current_Scope;
begin
while Present (S) loop
if Is_Compilation_Unit (S)
or else Is_Child_Unit (S)
then
return False;
elsif Ekind (S) = E_Package
and then Has_Forward_Instantiation (S)
then
return True;
end if;
S := Scope (S);
end loop;
return False;
end Has_Pending_Instantiation;
function Has_Single_Return return Boolean is
Return_Statement : Node_Id := Empty;
function Check_Return (N : Node_Id) return Traverse_Result;
function Check_Return (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) = N_Return_Statement then
if Present (Expression (N))
and then Is_Entity_Name (Expression (N))
then
if No (Return_Statement) then
Return_Statement := N;
return OK;
elsif Chars (Expression (N)) =
Chars (Expression (Return_Statement))
then
return OK;
else
return Abandon;
end if;
else
return Abandon;
end if;
else
return OK;
end if;
end Check_Return;
function Check_All_Returns is new Traverse_Func (Check_Return);
begin
return Check_All_Returns (N) = OK
and then Present (Declarations (N))
and then Chars (Expression (Return_Statement)) =
Chars (Defining_Identifier (First (Declarations (N))));
end Has_Single_Return;
procedure Remove_Pragmas is
Decl : Node_Id;
Nxt : Node_Id;
begin
Decl := First (Declarations (Body_To_Analyze));
while Present (Decl) loop
Nxt := Next (Decl);
if Nkind (Decl) = N_Pragma
and then Chars (Decl) = Name_Unreferenced
then
Remove (Decl);
end if;
Decl := Nxt;
end loop;
end Remove_Pragmas;
function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is
function Check_Call (N : Node_Id) return Traverse_Result;
function Check_Call (N : Node_Id) return Traverse_Result is
begin
if Nkind (N) = N_Function_Call
and then Is_Entity_Name (Name (N))
and then Is_Composite_Type (Etype (Entity (Name (N))))
and then not Is_Constrained (Etype (Entity (Name (N))))
then
Cannot_Inline
("cannot inline & (call returns unconstrained type)?",
N, Subp);
return Abandon;
else
return OK;
end if;
end Check_Call;
function Check_Calls is new Traverse_Func (Check_Call);
begin
return Check_Calls (Bod) = Abandon;
end Uses_Secondary_Stack;
begin
if Nkind (Decl) = N_Subprogram_Declaration
and then Present (Body_To_Inline (Decl))
then
return;
elsif Ekind (Subp) = E_Function
and then not Is_Scalar_Type (Etype (Subp))
and then not Is_Access_Type (Etype (Subp))
and then not Is_Constrained (Etype (Subp))
then
if not Has_Single_Return then
Cannot_Inline
("cannot inline & (unconstrained return type)?", N, Subp);
return;
end if;
elsif Ekind (Subp) = E_Function
and then Controlled_Type (Etype (Subp))
then
Cannot_Inline
("cannot inline & (controlled return type)?", N, Subp);
return;
end if;
if Present (Declarations (N))
and then Has_Excluded_Declaration (Declarations (N))
then
return;
end if;
if Present (Handled_Statement_Sequence (N)) then
if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
Cannot_Inline
("cannot inline& (exception handler)?",
First (Exception_Handlers (Handled_Statement_Sequence (N))),
Subp);
return;
elsif
Has_Excluded_Statement
(Statements (Handled_Statement_Sequence (N)))
then
return;
end if;
end if;
if Stat_Count > Max_Size
and then not Is_Always_Inlined (Subp)
then
Cannot_Inline ("cannot inline& (body too large)?", N, Subp);
return;
end if;
if Has_Pending_Instantiation then
Cannot_Inline
("cannot inline& (forward instance within enclosing body)?",
N, Subp);
return;
end if;
if In_Instance then
Save_Env (Scope (Current_Scope), Scope (Current_Scope));
Original_Body := Copy_Generic_Node (N, Empty, True);
else
Original_Body := Copy_Separate_Tree (N);
end if;
Set_Parameter_Specifications (Specification (Original_Body), No_List);
Set_Defining_Unit_Name
(Specification (Original_Body),
Make_Defining_Identifier (Sloc (N), Name_uParent));
Set_Corresponding_Spec (Original_Body, Empty);
Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False);
if Ekind (Subp) = E_Function then
Set_Result_Definition (Specification (Body_To_Analyze),
New_Occurrence_Of (Etype (Subp), Sloc (N)));
end if;
if No (Declarations (N)) then
Set_Declarations (N, New_List (Body_To_Analyze));
else
Append (Body_To_Analyze, Declarations (N));
end if;
Expander_Mode_Save_And_Set (False);
Remove_Pragmas;
Analyze (Body_To_Analyze);
New_Scope (Defining_Entity (Body_To_Analyze));
Save_Global_References (Original_Body);
End_Scope;
Remove (Body_To_Analyze);
Expander_Mode_Restore;
if In_Instance then
Restore_Env;
end if;
if Uses_Secondary_Stack (Body_To_Analyze) then
return;
end if;
Set_Body_To_Inline (Decl, Original_Body);
Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp));
Set_Is_Inlined (Subp);
end Build_Body_To_Inline;
procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is
begin
if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp)))
and then not In_Extended_Main_Source_Unit (Subp)
then
null;
elsif Is_Always_Inlined (Subp) then
Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
elsif Ineffective_Inline_Warnings then
Error_Msg_NE (Msg, N, Subp);
end if;
end Cannot_Inline;
procedure Check_Conformance
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Ctype : Conformance_Type;
Errmsg : Boolean;
Conforms : out Boolean;
Err_Loc : Node_Id := Empty;
Get_Inst : Boolean := False;
Skip_Controlling_Formals : Boolean := False)
is
Old_Type : constant Entity_Id := Etype (Old_Id);
New_Type : constant Entity_Id := Etype (New_Id);
Old_Formal : Entity_Id;
New_Formal : Entity_Id;
procedure Conformance_Error (Msg : String; N : Node_Id := New_Id);
procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is
Enode : Node_Id;
begin
Conforms := False;
if Errmsg then
if No (Err_Loc) then
Enode := N;
else
Enode := Err_Loc;
end if;
Error_Msg_Sloc := Sloc (Old_Id);
case Ctype is
when Type_Conformant =>
Error_Msg_N
("not type conformant with declaration#!", Enode);
when Mode_Conformant =>
Error_Msg_N
("not mode conformant with declaration#!", Enode);
when Subtype_Conformant =>
Error_Msg_N
("not subtype conformant with declaration#!", Enode);
when Fully_Conformant =>
Error_Msg_N
("not fully conformant with declaration#!", Enode);
end case;
Error_Msg_NE (Msg, Enode, N);
end if;
end Conformance_Error;
begin
Conforms := True;
if Ctype = Type_Conformant then
if Ekind (New_Id) = E_Operator
and then Operator_Matches_Spec (New_Id, Old_Id)
then
return;
end if;
end if;
if Old_Type /= Standard_Void_Type
and then New_Type /= Standard_Void_Type
then
if not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then
Conformance_Error ("return type does not match!", New_Id);
return;
end if;
if Ada_Version >= Ada_05
and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type
and then
(Can_Never_Be_Null (Old_Type)
/= Can_Never_Be_Null (New_Type)
or else Is_Access_Constant (Etype (Old_Type))
/= Is_Access_Constant (Etype (New_Type)))
then
Conformance_Error ("return type does not match!", New_Id);
return;
end if;
elsif Old_Type /= Standard_Void_Type
or else New_Type /= Standard_Void_Type
then
Conformance_Error ("functions can only match functions!", New_Id);
return;
end if;
if Ctype >= Subtype_Conformant then
if Convention (Old_Id) /= Convention (New_Id) then
if not Is_Frozen (New_Id) then
null;
elsif Present (Err_Loc)
and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration
and then Present (Corresponding_Spec (Err_Loc))
then
Error_Msg_Name_1 := Chars (New_Id);
Error_Msg_Name_2 :=
Name_Ada + Convention_Id'Pos (Convention (New_Id));
Conformance_Error ("prior declaration for% has convention %!");
else
Conformance_Error ("calling conventions do not match!");
end if;
return;
elsif Is_Formal_Subprogram (Old_Id)
or else Is_Formal_Subprogram (New_Id)
then
Conformance_Error ("formal subprograms not allowed!");
return;
end if;
end if;
Old_Formal := First_Formal (Old_Id);
New_Formal := First_Formal (New_Id);
while Present (Old_Formal) and then Present (New_Formal) loop
if Is_Controlling_Formal (Old_Formal)
and then Is_Controlling_Formal (New_Formal)
and then Skip_Controlling_Formals
then
goto Skip_Controlling_Formal;
end if;
if Ctype = Fully_Conformant then
if Chars (Old_Formal) /= Chars (New_Formal) then
Conformance_Error ("name & does not match!", New_Formal);
Set_Error_Posted (New_Formal);
return;
end if;
end if;
if In_Instance_Visible_Part
and then Is_Dispatching_Operation (New_Id)
then
if not Conforming_Types
(Base_Type (Etype (Old_Formal)),
Base_Type (Etype (New_Formal)), Ctype, Get_Inst)
then
Conformance_Error ("type of & does not match!", New_Formal);
return;
end if;
elsif not Conforming_Types
(Etype (Old_Formal), Etype (New_Formal), Ctype, Get_Inst)
then
Conformance_Error ("type of & does not match!", New_Formal);
return;
end if;
if Ctype >= Mode_Conformant
and then Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal)
then
Conformance_Error ("mode of & does not match!", New_Formal);
return;
end if;
if Ctype = Fully_Conformant then
if Parameter_Mode (Old_Formal) = E_In_Parameter then
if Ada_Version >= Ada_05
and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type
and then
(Can_Never_Be_Null (Old_Formal)
/= Can_Never_Be_Null (New_Formal)
or else Is_Access_Constant (Etype (Old_Formal))
/= Is_Access_Constant (Etype (New_Formal)))
then
declare
TSS_Name : TSS_Name_Type;
begin
Get_Name_String (Chars (New_Id));
TSS_Name :=
TSS_Name_Type
(Name_Buffer
(Name_Len - TSS_Name'Length + 1 .. Name_Len));
if TSS_Name /= TSS_Stream_Read
and then TSS_Name /= TSS_Stream_Write
and then TSS_Name /= TSS_Stream_Input
and then TSS_Name /= TSS_Stream_Output
then
Conformance_Error
("type of & does not match!", New_Formal);
return;
end if;
end;
end if;
declare
NewD : constant Boolean :=
Present (Default_Value (New_Formal));
OldD : constant Boolean :=
Present (Default_Value (Old_Formal));
begin
if NewD or OldD then
if NewD then
New_Scope (New_Id);
Analyze_Per_Use_Expression
(Default_Value (New_Formal), Etype (New_Formal));
End_Scope;
end if;
if not (NewD and OldD)
or else not Fully_Conformant_Expressions
(Default_Value (Old_Formal),
Default_Value (New_Formal))
then
Conformance_Error
("default expression for & does not match!",
New_Formal);
return;
end if;
end if;
end;
end if;
end if;
if Ada_Version = Ada_83
and then Sloc (Old_Id) > Standard_Location
and then Sloc (New_Id) > Standard_Location
and then Comes_From_Source (Old_Id)
and then Comes_From_Source (New_Id)
then
declare
Old_Param : constant Node_Id := Declaration_Node (Old_Formal);
New_Param : constant Node_Id := Declaration_Node (New_Formal);
begin
if In_Present (Old_Param) /= In_Present (New_Param)
and then Ctype = Fully_Conformant
then
Conformance_Error
("(Ada 83) IN must appear in both declarations",
New_Formal);
return;
end if;
if More_Ids (Old_Param) /= More_Ids (New_Param)
or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param)
then
Conformance_Error
("grouping of & does not match!", New_Formal);
return;
end if;
end;
end if;
<<Skip_Controlling_Formal>>
Next_Formal (Old_Formal);
Next_Formal (New_Formal);
end loop;
if Present (Old_Formal) then
Conformance_Error ("too few parameters!");
return;
elsif Present (New_Formal) then
Conformance_Error ("too many parameters!", New_Formal);
return;
end if;
end Check_Conformance;
procedure Check_Delayed_Subprogram (Designator : Entity_Id) is
F : Entity_Id;
procedure Possible_Freeze (T : Entity_Id);
procedure Possible_Freeze (T : Entity_Id) is
begin
if Has_Delayed_Freeze (T)
and then not Is_Frozen (T)
then
Set_Has_Delayed_Freeze (Designator);
elsif Is_Access_Type (T)
and then Has_Delayed_Freeze (Designated_Type (T))
and then not Is_Frozen (Designated_Type (T))
then
Set_Has_Delayed_Freeze (Designator);
end if;
end Possible_Freeze;
begin
if Is_Abstract (Designator) then
null;
else
Possible_Freeze (Etype (Designator));
Possible_Freeze (Base_Type (Etype (Designator)));
F := First_Formal (Designator);
while Present (F) loop
Possible_Freeze (Etype (F));
Possible_Freeze (Base_Type (Etype (F))); Next_Formal (F);
end loop;
end if;
if not Has_Delayed_Freeze (Designator)
and then Expander_Active
then
declare
Typ : constant Entity_Id := Etype (Designator);
Utyp : constant Entity_Id := Underlying_Type (Typ);
begin
if Is_Return_By_Reference_Type (Typ) then
Set_Returns_By_Ref (Designator);
elsif Present (Utyp) and then Controlled_Type (Utyp) then
Set_Returns_By_Ref (Designator);
end if;
end;
end if;
end Check_Delayed_Subprogram;
procedure Check_Discriminant_Conformance
(N : Node_Id;
Prev : Entity_Id;
Prev_Loc : Node_Id)
is
Old_Discr : Entity_Id := First_Discriminant (Prev);
New_Discr : Node_Id := First (Discriminant_Specifications (N));
New_Discr_Id : Entity_Id;
New_Discr_Type : Entity_Id;
procedure Conformance_Error (Msg : String; N : Node_Id);
procedure Conformance_Error (Msg : String; N : Node_Id) is
begin
Error_Msg_Sloc := Sloc (Prev_Loc);
Error_Msg_N ("not fully conformant with declaration#!", N);
Error_Msg_NE (Msg, N, N);
end Conformance_Error;
begin
while Present (Old_Discr) and then Present (New_Discr) loop
New_Discr_Id := Defining_Identifier (New_Discr);
if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then
New_Discr_Type :=
Access_Definition (N, Discriminant_Type (New_Discr));
else
Analyze (Discriminant_Type (New_Discr));
New_Discr_Type := Etype (Discriminant_Type (New_Discr));
end if;
if not Conforming_Types
(Etype (Old_Discr), New_Discr_Type, Fully_Conformant)
then
Conformance_Error ("type of & does not match!", New_Discr_Id);
return;
else
Generate_Reference (Old_Discr, New_Discr_Id, 'r');
Set_Etype (New_Discr_Id, Etype (Old_Discr));
Set_Scope (New_Discr_Id, Scope (Old_Discr));
end if;
if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then
Conformance_Error ("name & does not match!", New_Discr_Id);
return;
end if;
declare
NewD : constant Boolean :=
Present (Expression (New_Discr));
OldD : constant Boolean :=
Present (Expression (Parent (Old_Discr)));
begin
if NewD or OldD then
if NewD then
Analyze_Per_Use_Expression
(Expression (New_Discr), New_Discr_Type);
end if;
if not (NewD and OldD)
or else not Fully_Conformant_Expressions
(Expression (Parent (Old_Discr)),
Expression (New_Discr))
then
Conformance_Error
("default expression for & does not match!",
New_Discr_Id);
return;
end if;
end if;
end;
if Ada_Version = Ada_83 then
declare
Old_Disc : constant Node_Id := Declaration_Node (Old_Discr);
begin
if More_Ids (Old_Disc) /= More_Ids (New_Discr)
or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr)
then
Conformance_Error
("grouping of & does not match!", New_Discr_Id);
return;
end if;
end;
end if;
Next_Discriminant (Old_Discr);
Next (New_Discr);
end loop;
if Present (Old_Discr) then
Conformance_Error ("too few discriminants!", Defining_Identifier (N));
return;
elsif Present (New_Discr) then
Conformance_Error
("too many discriminants!", Defining_Identifier (New_Discr));
return;
end if;
end Check_Discriminant_Conformance;
procedure Check_Fully_Conformant
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Err_Loc : Node_Id := Empty)
is
Result : Boolean;
pragma Warnings (Off, Result);
begin
Check_Conformance
(New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc);
end Check_Fully_Conformant;
procedure Check_Mode_Conformant
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Err_Loc : Node_Id := Empty;
Get_Inst : Boolean := False)
is
Result : Boolean;
pragma Warnings (Off, Result);
begin
Check_Conformance
(New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst);
end Check_Mode_Conformant;
procedure Check_Overriding_Indicator
(Subp : Entity_Id;
Does_Override : Boolean)
is
Decl : Node_Id;
Spec : Node_Id;
begin
if Ekind (Subp) = E_Enumeration_Literal then
return;
else
Decl := Unit_Declaration_Node (Subp);
end if;
if Nkind (Decl) = N_Subprogram_Declaration
or else Nkind (Decl) = N_Subprogram_Body
or else Nkind (Decl) = N_Subprogram_Renaming_Declaration
or else Nkind (Decl) = N_Subprogram_Body_Stub
then
Spec := Specification (Decl);
else
return;
end if;
if not Does_Override then
if Must_Override (Spec) then
Error_Msg_NE ("subprogram& is not overriding", Spec, Subp);
end if;
else
if Must_Not_Override (Spec) then
Error_Msg_NE
("subprogram& overrides inherited operation", Spec, Subp);
end if;
end if;
end Check_Overriding_Indicator;
procedure Check_Returns
(HSS : Node_Id;
Mode : Character;
Err : out Boolean;
Proc : Entity_Id := Empty)
is
Handler : Node_Id;
procedure Check_Statement_Sequence (L : List_Id);
procedure Check_Statement_Sequence (L : List_Id) is
Last_Stm : Node_Id;
Kind : Node_Kind;
Raise_Exception_Call : Boolean;
begin
Raise_Exception_Call := False;
Last_Stm := Last (L);
while Nkind (Last_Stm) = N_Pragma
or else
(Nkind (Last_Stm) = N_Procedure_Call_Statement
and then
Nkind (Name (Last_Stm)) = N_Identifier
and then
Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release))
or else
((Nkind (Last_Stm) = N_Goto_Statement
or else Nkind (Last_Stm) = N_Label
or else Nkind (Last_Stm) = N_Object_Declaration)
and then Exception_Junk (Last_Stm))
loop
Prev (Last_Stm);
end loop;
Kind := Nkind (Last_Stm);
if Is_Transfer (Last_Stm) then
return;
elsif Kind = N_Procedure_Call_Statement
and then Is_Entity_Name (Name (Last_Stm))
then
if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception)
or else
Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence)
then
Raise_Exception_Call := True;
declare
Arg : constant Node_Id :=
Original_Node (First_Actual (Last_Stm));
begin
if Nkind (Arg) = N_Attribute_Reference
and then Attribute_Name (Arg) = Name_Identity
then
return;
end if;
end;
end if;
elsif Kind = N_If_Statement
and then Present (Else_Statements (Last_Stm))
then
Check_Statement_Sequence (Then_Statements (Last_Stm));
Check_Statement_Sequence (Else_Statements (Last_Stm));
if Present (Elsif_Parts (Last_Stm)) then
declare
Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm));
begin
while Present (Elsif_Part) loop
Check_Statement_Sequence (Then_Statements (Elsif_Part));
Next (Elsif_Part);
end loop;
end;
end if;
return;
elsif Kind = N_Case_Statement then
declare
Case_Alt : Node_Id;
begin
Case_Alt := First_Non_Pragma (Alternatives (Last_Stm));
while Present (Case_Alt) loop
Check_Statement_Sequence (Statements (Case_Alt));
Next_Non_Pragma (Case_Alt);
end loop;
end;
return;
elsif Kind = N_Block_Statement then
declare
Err1 : Boolean;
begin
Check_Returns
(Handled_Statement_Sequence (Last_Stm), Mode, Err1);
if Err1 then
Err := True;
end if;
return;
end;
elsif Kind = N_Loop_Statement then
if Present (Iteration_Scheme (Last_Stm))
or else Has_Exit (Entity (Identifier (Last_Stm)))
then
null;
else
return;
end if;
elsif Kind = N_Timed_Entry_Call then
declare
ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
DCA : constant Node_Id := Delay_Alternative (Last_Stm);
begin
if No (Statements (ECA)) then
Last_Stm := ECA;
elsif No (Statements (DCA)) then
Last_Stm := DCA;
else
Check_Statement_Sequence (Statements (ECA));
Check_Statement_Sequence (Statements (DCA));
return;
end if;
end;
elsif Kind = N_Conditional_Entry_Call then
declare
ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
begin
if No (Statements (ECA)) then
Last_Stm := ECA;
else
Check_Statement_Sequence (Statements (ECA));
Check_Statement_Sequence (Else_Statements (Last_Stm));
return;
end if;
end;
end if;
if Mode = 'F' then
if not Raise_Exception_Call then
Error_Msg_N
("?RETURN statement missing following this statement",
Last_Stm);
Error_Msg_N
("\?Program_Error may be raised at run time",
Last_Stm);
end if;
Err := True;
else
Error_Msg_N
("?implied return after this statement will raise Program_Error",
Last_Stm);
Error_Msg_NE
("?procedure & is marked as No_Return",
Last_Stm, Proc);
declare
RE : constant Node_Id :=
Make_Raise_Program_Error (Sloc (Last_Stm),
Reason => PE_Implicit_Return);
begin
Insert_After (Last_Stm, RE);
Analyze (RE);
end;
end if;
end Check_Statement_Sequence;
begin
Err := False;
Check_Statement_Sequence (Statements (HSS));
if Present (Exception_Handlers (HSS)) then
Handler := First_Non_Pragma (Exception_Handlers (HSS));
while Present (Handler) loop
Check_Statement_Sequence (Statements (Handler));
Next_Non_Pragma (Handler);
end loop;
end if;
end Check_Returns;
procedure Check_Subprogram_Order (N : Node_Id) is
function Subprogram_Name_Greater (S1, S2 : String) return Boolean;
function Subprogram_Name_Greater (S1, S2 : String) return Boolean is
L1, L2 : Positive;
N1, N2 : Natural;
begin
L1 := S1'Last;
while S1 (L1) in '0' .. '9' loop
L1 := L1 - 1;
end loop;
L2 := S2'Last;
while S2 (L2) in '0' .. '9' loop
L2 := L2 - 1;
end loop;
if S1 (S1'First .. L1) < S2 (S2'First .. L2) then
return False;
elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then
return True;
else
N1 := 0;
while L1 < S1'Last loop
L1 := L1 + 1;
N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0');
end loop;
N2 := 0;
while L2 < S2'Last loop
L2 := L2 + 1;
N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0');
end loop;
return N1 > N2;
end if;
end Subprogram_Name_Greater;
begin
if Style_Check
and then Style_Check_Order_Subprograms
and then Nkind (N) = N_Subprogram_Body
and then Comes_From_Source (N)
and then In_Extended_Main_Source_Unit (N)
then
declare
LSN : String_Ptr
renames Scope_Stack.Table
(Scope_Stack.Last).Last_Subprogram_Name;
Body_Id : constant Entity_Id :=
Defining_Entity (Specification (N));
begin
Get_Decoded_Name_String (Chars (Body_Id));
if LSN /= null then
if Subprogram_Name_Greater
(LSN.all, Name_Buffer (1 .. Name_Len))
then
Style.Subprogram_Not_In_Alpha_Order (Body_Id);
end if;
Free (LSN);
end if;
LSN := new String'(Name_Buffer (1 .. Name_Len));
end;
end if;
end Check_Subprogram_Order;
procedure Check_Subtype_Conformant
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Err_Loc : Node_Id := Empty)
is
Result : Boolean;
pragma Warnings (Off, Result);
begin
Check_Conformance
(New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
end Check_Subtype_Conformant;
procedure Check_Type_Conformant
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Err_Loc : Node_Id := Empty)
is
Result : Boolean;
pragma Warnings (Off, Result);
begin
Check_Conformance
(New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
end Check_Type_Conformant;
function Conforming_Types
(T1 : Entity_Id;
T2 : Entity_Id;
Ctype : Conformance_Type;
Get_Inst : Boolean := False) return Boolean
is
Type_1 : Entity_Id := T1;
Type_2 : Entity_Id := T2;
Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
begin
if T1 = T2 then
return True;
elsif Base_Type (T1) = Base_Type (T2) then
return not Is_Generic_Actual_Type (T1)
or else not Is_Generic_Actual_Type (T2)
or else Scope (T1) /= Scope (T2);
elsif From_With_Type (T1)
and then Ekind (T1) = E_Incomplete_Type
and then T2 = Non_Limited_View (T1)
then
return True;
elsif From_With_Type (T2)
and then Ekind (T2) = E_Incomplete_Type
and then T1 = Non_Limited_View (T2)
then
return True;
else
return False;
end if;
end Base_Types_Match;
begin
if Get_Inst then
Type_1 := Get_Instance_Of (T1);
Type_2 := Get_Instance_Of (T2);
end if;
if Base_Types_Match (Type_1, Type_2) then
return Ctype <= Mode_Conformant
or else Subtypes_Statically_Match (Type_1, Type_2);
elsif Is_Incomplete_Or_Private_Type (Type_1)
and then Present (Full_View (Type_1))
and then Base_Types_Match (Full_View (Type_1), Type_2)
then
return Ctype <= Mode_Conformant
or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
elsif Ekind (Type_2) = E_Incomplete_Type
and then Present (Full_View (Type_2))
and then Base_Types_Match (Type_1, Full_View (Type_2))
then
return Ctype <= Mode_Conformant
or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
elsif Is_Private_Type (Type_2)
and then In_Instance
and then Present (Full_View (Type_2))
and then Base_Types_Match (Type_1, Full_View (Type_2))
then
return Ctype <= Mode_Conformant
or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
end if;
Are_Anonymous_Access_To_Subprogram_Types :=
(Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
and then Ekind (Type_2) = E_Anonymous_Access_Subprogram_Type)
or else
(Ekind (Type_1) = E_Access_Protected_Subprogram_Type
and then Ekind (Type_2) = E_Access_Protected_Subprogram_Type
and then not Comes_From_Source (Type_1)
and then not Comes_From_Source (Type_2)
and then Present (Original_Access_Type (Type_1))
and then Present (Original_Access_Type (Type_2))
and then Ekind (Original_Access_Type (Type_1)) =
E_Anonymous_Access_Protected_Subprogram_Type
and then Ekind (Original_Access_Type (Type_2)) =
E_Anonymous_Access_Protected_Subprogram_Type);
if (Ekind (Type_1) = E_Anonymous_Access_Type
and then Ekind (Type_2) = E_Anonymous_Access_Type)
or else Are_Anonymous_Access_To_Subprogram_Types then
declare
Desig_1 : Entity_Id;
Desig_2 : Entity_Id;
begin
Desig_1 := Directly_Designated_Type (Type_1);
if Ekind (Desig_1) = E_Incomplete_Type then
if Present (Full_View (Desig_1)) then
Desig_1 := Full_View (Desig_1);
elsif Present (Non_Limited_View (Desig_1)) then
Desig_1 := Non_Limited_View (Desig_1);
end if;
end if;
Desig_2 := Directly_Designated_Type (Type_2);
if Ekind (Desig_2) = E_Incomplete_Type then
if Present (Full_View (Desig_2)) then
Desig_2 := Full_View (Desig_2);
elsif Present (Non_Limited_View (Desig_2)) then
Desig_2 := Non_Limited_View (Desig_2);
end if;
end if;
if Get_Inst then
Desig_1 := Get_Instance_Of (Desig_1);
Desig_2 := Get_Instance_Of (Desig_2);
end if;
if Is_Class_Wide_Type (Desig_1)
and then Is_Class_Wide_Type (Desig_2)
then
return
Conforming_Types
(Etype (Base_Type (Desig_1)),
Etype (Base_Type (Desig_2)), Ctype);
elsif Are_Anonymous_Access_To_Subprogram_Types then
if Ada_Version < Ada_05 then
return Ctype = Type_Conformant
or else
Subtypes_Statically_Match (Desig_1, Desig_2);
else
declare
Conformant : Boolean;
begin
Check_Conformance
(Desig_1, Desig_2, Ctype, False, Conformant);
return Conformant;
end;
end if;
else
return Base_Type (Desig_1) = Base_Type (Desig_2)
and then (Ctype = Type_Conformant
or else
Subtypes_Statically_Match (Desig_1, Desig_2));
end if;
end;
else
if ((Ekind (Type_1) = E_Anonymous_Access_Type
and then Is_Access_Type (Type_2))
or else (Ekind (Type_2) = E_Anonymous_Access_Type
and then Is_Access_Type (Type_1)))
and then
Conforming_Types
(Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
then
May_Hide_Profile := True;
end if;
return False;
end if;
end Conforming_Types;
procedure Create_Extra_Formals (E : Entity_Id) is
Formal : Entity_Id;
Last_Extra : Entity_Id;
Formal_Type : Entity_Id;
P_Formal : Entity_Id := Empty;
function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
EF : constant Entity_Id :=
Make_Defining_Identifier (Sloc (Formal),
Chars => New_External_Name (Chars (Formal), 'F'));
begin
if not Expander_Active then
return Empty;
end if;
if Chars (Formal) = Name_uInit then
return Empty;
end if;
Set_Ekind (EF, E_In_Parameter);
Set_Actual_Subtype (EF, Typ);
Set_Etype (EF, Typ);
Set_Scope (EF, Scope (Formal));
Set_Mechanism (EF, Default_Mechanism);
Set_Formal_Validity (EF);
Set_Extra_Formal (Last_Extra, EF);
Last_Extra := EF;
return EF;
end Add_Extra_Formal;
begin
if Is_Overloadable (E) and then Present (Alias (E)) then
P_Formal := First_Formal (Alias (E));
end if;
Last_Extra := Empty;
Formal := First_Formal (E);
while Present (Formal) loop
Last_Extra := Formal;
Next_Formal (Formal);
end loop;
if Present (Last_Extra) and then
Present (Extra_Formal (Last_Extra))
then
return;
end if;
Formal := First_Formal (E);
while Present (Formal) loop
if Ekind (Formal) /= E_In_Parameter then
if Present (P_Formal) then
Formal_Type := Etype (P_Formal);
else
Formal_Type := Etype (Formal);
end if;
if Is_Unchecked_Union (Base_Type (Formal_Type)) then
goto Skip_Extra_Formal_Generation;
end if;
if not Has_Discriminants (Formal_Type)
and then Ekind (Formal_Type) in Private_Kind
and then Present (Underlying_Type (Formal_Type))
then
Formal_Type := Underlying_Type (Formal_Type);
end if;
if Has_Discriminants (Formal_Type)
and then
((not Is_Constrained (Formal_Type)
and then not Is_Indefinite_Subtype (Formal_Type))
or else Present (Extra_Formal (Formal)))
then
Set_Extra_Constrained
(Formal, Add_Extra_Formal (Standard_Boolean));
end if;
end if;
if Ekind (Etype (Formal)) = E_Anonymous_Access_Type
and then not
(Explicit_Suppress (E, Accessibility_Check)
or else
Explicit_Suppress (Scope (E), Accessibility_Check))
and then
(No (P_Formal)
or else Present (Extra_Accessibility (P_Formal)))
then
if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition
and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body
then
Set_Extra_Accessibility
(Formal, Add_Extra_Formal (Standard_Natural));
end if;
end if;
if Present (P_Formal) then
Next_Formal (P_Formal);
end if;
<<Skip_Extra_Formal_Generation>>
Next_Formal (Formal);
end loop;
end Create_Extra_Formals;
procedure Enter_Overloaded_Entity (S : Entity_Id) is
E : Entity_Id := Current_Entity_In_Scope (S);
C_E : Entity_Id := Current_Entity (S);
begin
if Present (E) then
Set_Has_Homonym (E);
Set_Has_Homonym (S);
end if;
Set_Is_Immediately_Visible (S);
Set_Scope (S, Current_Scope);
if Present (E)
and then E /= C_E
then
while Homonym (C_E) /= E loop
C_E := Homonym (C_E);
end loop;
Set_Homonym (C_E, S);
else
E := C_E;
Set_Current_Entity (S);
end if;
Set_Homonym (S, E);
Append_Entity (S, Current_Scope);
Set_Public_Status (S);
if Debug_Flag_E then
Write_Str ("New overloaded entity chain: ");
Write_Name (Chars (S));
E := S;
while Present (E) loop
Write_Str (" "); Write_Int (Int (E));
E := Homonym (E);
end loop;
Write_Eol;
end if;
if Warn_On_Hiding
and then Comes_From_Source (S)
and then In_Extended_Main_Source_Unit (S)
then
E := S;
loop
E := Homonym (E);
exit when No (E);
if (not Is_Overloadable (E))
or else Subtype_Conformant (E, S)
then
Error_Msg_Sloc := Sloc (E);
Error_Msg_N ("declaration of & hides one#?", S);
end if;
end loop;
end if;
end Enter_Overloaded_Entity;
function Find_Corresponding_Spec (N : Node_Id) return Entity_Id is
Spec : constant Node_Id := Specification (N);
Designator : constant Entity_Id := Defining_Entity (Spec);
E : Entity_Id;
begin
E := Current_Entity (Designator);
while Present (E) loop
if Scope (E) = Current_Scope then
if Current_Scope = Standard_Standard
or else (Ekind (E) = Ekind (Designator)
and then Type_Conformant (E, Designator))
then
if In_Instance then
Set_Convention (Designator, Convention (E));
if Nkind (N) = N_Subprogram_Body
and then Present (Homonym (E))
and then not Fully_Conformant (E, Designator)
then
goto Next_Entity;
elsif not Subtype_Conformant (E, Designator) then
goto Next_Entity;
end if;
end if;
if not Has_Completion (E) then
if Nkind (N) /= N_Subprogram_Body_Stub then
Set_Corresponding_Spec (N, E);
end if;
Set_Has_Completion (E);
return E;
elsif Nkind (Parent (N)) = N_Subunit then
return E;
elsif No (Alias (E))
and then not Is_Intrinsic_Subprogram (E)
and then not In_Instance
then
Error_Msg_Sloc := Sloc (E);
if Is_Imported (E) then
Error_Msg_NE
("body not allowed for imported subprogram & declared#",
N, E);
else
Error_Msg_NE ("duplicate body for & declared#", N, E);
end if;
end if;
elsif Is_Child_Unit (E)
and then
Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body
and then
Nkind (Parent (Unit_Declaration_Node (Designator)))
= N_Compilation_Unit
then
Error_Msg_N
("body of child unit does not match previous declaration", N);
end if;
end if;
<<Next_Entity>>
E := Homonym (E);
end loop;
return Empty;
end Find_Corresponding_Spec;
function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
Result : Boolean;
begin
Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result);
return Result;
end Fully_Conformant;
function Fully_Conformant_Expressions
(Given_E1 : Node_Id;
Given_E2 : Node_Id) return Boolean
is
E1 : constant Node_Id := Original_Node (Given_E1);
E2 : constant Node_Id := Original_Node (Given_E2);
function FCE (Given_E1, Given_E2 : Node_Id) return Boolean
renames Fully_Conformant_Expressions;
function FCL (L1, L2 : List_Id) return Boolean;
function FCO (Op_Node, Call_Node : Node_Id) return Boolean;
function FCL (L1, L2 : List_Id) return Boolean is
N1, N2 : Node_Id;
begin
if L1 = No_List then
N1 := Empty;
else
N1 := First (L1);
end if;
if L2 = No_List then
N2 := Empty;
else
N2 := First (L2);
end if;
loop
if Is_Rewrite_Insertion (N1) then
Next (N1);
elsif Is_Rewrite_Insertion (N2) then
Next (N2);
elsif No (N1) then
return No (N2);
elsif No (N2) then
return False;
elsif not FCE (N1, N2) then
return False;
else
Next (N1);
Next (N2);
end if;
end loop;
end FCL;
function FCO (Op_Node, Call_Node : Node_Id) return Boolean is
Actuals : constant List_Id := Parameter_Associations (Call_Node);
Act : Node_Id;
begin
if No (Actuals)
or else Entity (Op_Node) /= Entity (Name (Call_Node))
then
return False;
else
Act := First (Actuals);
if Nkind (Op_Node) in N_Binary_Op then
if not FCE (Left_Opnd (Op_Node), Act) then
return False;
end if;
Next (Act);
end if;
return Present (Act)
and then FCE (Right_Opnd (Op_Node), Act)
and then No (Next (Act));
end if;
end FCO;
begin
if Paren_Count (E1) /= Paren_Count (E2) then
return False;
elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then
if Present (Entity (E1)) then
return Entity (E1) = Entity (E2)
or else (Chars (Entity (E1)) = Chars (Entity (E2))
and then Ekind (Entity (E1)) = E_Discriminant
and then Ekind (Entity (E2)) = E_In_Parameter);
elsif Nkind (E1) = N_Expanded_Name
and then Nkind (E2) = N_Expanded_Name
and then Nkind (Selector_Name (E1)) = N_Character_Literal
and then Nkind (Selector_Name (E2)) = N_Character_Literal
then
return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2));
else
return Nkind (E1) = N_Identifier
and then Nkind (E2) = N_Identifier
and then Chars (E1) = Chars (E2);
end if;
elsif Nkind (E1) = N_Character_Literal
and then Nkind (E2) = N_Expanded_Name
then
return Nkind (Selector_Name (E2)) = N_Character_Literal
and then Chars (E1) = Chars (Selector_Name (E2));
elsif Nkind (E2) = N_Character_Literal
and then Nkind (E1) = N_Expanded_Name
then
return Nkind (Selector_Name (E1)) = N_Character_Literal
and then Chars (E2) = Chars (Selector_Name (E1));
elsif Nkind (E1) in N_Op
and then Nkind (E2) = N_Function_Call
then
return FCO (E1, E2);
elsif Nkind (E2) in N_Op
and then Nkind (E1) = N_Function_Call
then
return FCO (E2, E1);
elsif Nkind (E1) /= Nkind (E2) then
return False;
else
case Nkind (E1) is
when N_Aggregate =>
return
FCL (Expressions (E1), Expressions (E2))
and then FCL (Component_Associations (E1),
Component_Associations (E2));
when N_Allocator =>
if Nkind (Expression (E1)) = N_Qualified_Expression
or else
Nkind (Expression (E2)) = N_Qualified_Expression
then
return FCE (Expression (E1), Expression (E2));
else
declare
Indic1 : constant Node_Id := Expression (E1);
Indic2 : constant Node_Id := Expression (E2);
Elt1 : Node_Id;
Elt2 : Node_Id;
begin
if Nkind (Indic1) /= N_Subtype_Indication then
return
Nkind (Indic2) /= N_Subtype_Indication
and then Entity (Indic1) = Entity (Indic2);
elsif Nkind (Indic2) /= N_Subtype_Indication then
return
Nkind (Indic1) /= N_Subtype_Indication
and then Entity (Indic1) = Entity (Indic2);
else
if Entity (Subtype_Mark (Indic1)) /=
Entity (Subtype_Mark (Indic2))
then
return False;
end if;
Elt1 := First (Constraints (Constraint (Indic1)));
Elt2 := First (Constraints (Constraint (Indic2)));
while Present (Elt1) and then Present (Elt2) loop
if not FCE (Elt1, Elt2) then
return False;
end if;
Next (Elt1);
Next (Elt2);
end loop;
return True;
end if;
end;
end if;
when N_Attribute_Reference =>
return
Attribute_Name (E1) = Attribute_Name (E2)
and then FCL (Expressions (E1), Expressions (E2));
when N_Binary_Op =>
return
Entity (E1) = Entity (E2)
and then FCE (Left_Opnd (E1), Left_Opnd (E2))
and then FCE (Right_Opnd (E1), Right_Opnd (E2));
when N_And_Then | N_Or_Else | N_In | N_Not_In =>
return
FCE (Left_Opnd (E1), Left_Opnd (E2))
and then
FCE (Right_Opnd (E1), Right_Opnd (E2));
when N_Character_Literal =>
return
Char_Literal_Value (E1) = Char_Literal_Value (E2);
when N_Component_Association =>
return
FCL (Choices (E1), Choices (E2))
and then FCE (Expression (E1), Expression (E2));
when N_Conditional_Expression =>
return
FCL (Expressions (E1), Expressions (E2));
when N_Explicit_Dereference =>
return
FCE (Prefix (E1), Prefix (E2));
when N_Extension_Aggregate =>
return
FCL (Expressions (E1), Expressions (E2))
and then Null_Record_Present (E1) =
Null_Record_Present (E2)
and then FCL (Component_Associations (E1),
Component_Associations (E2));
when N_Function_Call =>
return
FCE (Name (E1), Name (E2))
and then FCL (Parameter_Associations (E1),
Parameter_Associations (E2));
when N_Indexed_Component =>
return
FCE (Prefix (E1), Prefix (E2))
and then FCL (Expressions (E1), Expressions (E2));
when N_Integer_Literal =>
return (Intval (E1) = Intval (E2));
when N_Null =>
return True;
when N_Operator_Symbol =>
return
Chars (E1) = Chars (E2);
when N_Others_Choice =>
return True;
when N_Parameter_Association =>
return
Chars (Selector_Name (E1)) = Chars (Selector_Name (E2))
and then FCE (Explicit_Actual_Parameter (E1),
Explicit_Actual_Parameter (E2));
when N_Qualified_Expression =>
return
FCE (Subtype_Mark (E1), Subtype_Mark (E2))
and then FCE (Expression (E1), Expression (E2));
when N_Range =>
return
FCE (Low_Bound (E1), Low_Bound (E2))
and then FCE (High_Bound (E1), High_Bound (E2));
when N_Real_Literal =>
return (Realval (E1) = Realval (E2));
when N_Selected_Component =>
return
FCE (Prefix (E1), Prefix (E2))
and then FCE (Selector_Name (E1), Selector_Name (E2));
when N_Slice =>
return
FCE (Prefix (E1), Prefix (E2))
and then FCE (Discrete_Range (E1), Discrete_Range (E2));
when N_String_Literal =>
declare
S1 : constant String_Id := Strval (E1);
S2 : constant String_Id := Strval (E2);
L1 : constant Nat := String_Length (S1);
L2 : constant Nat := String_Length (S2);
begin
if L1 /= L2 then
return False;
else
for J in 1 .. L1 loop
if Get_String_Char (S1, J) /=
Get_String_Char (S2, J)
then
return False;
end if;
end loop;
return True;
end if;
end;
when N_Type_Conversion =>
return
FCE (Subtype_Mark (E1), Subtype_Mark (E2))
and then FCE (Expression (E1), Expression (E2));
when N_Unary_Op =>
return
Entity (E1) = Entity (E2)
and then FCE (Right_Opnd (E1), Right_Opnd (E2));
when N_Unchecked_Type_Conversion =>
return
FCE (Subtype_Mark (E1), Subtype_Mark (E2))
and then FCE (Expression (E1), Expression (E2));
when others =>
return True;
end case;
end if;
end Fully_Conformant_Expressions;
function Fully_Conformant_Discrete_Subtypes
(Given_S1 : Node_Id;
Given_S2 : Node_Id) return Boolean
is
S1 : constant Node_Id := Original_Node (Given_S1);
S2 : constant Node_Id := Original_Node (Given_S2);
function Conforming_Bounds (B1, B2 : Node_Id) return Boolean;
function Conforming_Ranges (R1, R2 : Node_Id) return Boolean;
function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is
begin
if Is_Entity_Name (B1)
and then Is_Entity_Name (B2)
and then Ekind (Entity (B1)) = E_Discriminant
then
return Chars (B1) = Chars (B2);
else
return Fully_Conformant_Expressions (B1, B2);
end if;
end Conforming_Bounds;
function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is
begin
return
Conforming_Bounds (Low_Bound (R1), Low_Bound (R2))
and then
Conforming_Bounds (High_Bound (R1), High_Bound (R2));
end Conforming_Ranges;
begin
if Nkind (S1) /= Nkind (S2) then
return False;
elsif Is_Entity_Name (S1) then
return Entity (S1) = Entity (S2);
elsif Nkind (S1) = N_Range then
return Conforming_Ranges (S1, S2);
elsif Nkind (S1) = N_Subtype_Indication then
return
Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2))
and then
Conforming_Ranges
(Range_Expression (Constraint (S1)),
Range_Expression (Constraint (S2)));
else
return True;
end if;
end Fully_Conformant_Discrete_Subtypes;
procedure Install_Entity (E : Entity_Id) is
Prev : constant Entity_Id := Current_Entity (E);
begin
Set_Is_Immediately_Visible (E);
Set_Current_Entity (E);
Set_Homonym (E, Prev);
end Install_Entity;
procedure Install_Formals (Id : Entity_Id) is
F : Entity_Id;
begin
F := First_Formal (Id);
while Present (F) loop
Install_Entity (F);
Next_Formal (F);
end loop;
end Install_Formals;
function Is_Non_Overriding_Operation
(Prev_E : Entity_Id;
New_E : Entity_Id) return Boolean
is
Formal : Entity_Id;
F_Typ : Entity_Id;
G_Typ : Entity_Id := Empty;
function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id;
function Types_Correspond
(P_Type : Entity_Id;
N_Type : Entity_Id) return Boolean;
function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is
G_Typ : Entity_Id;
Indic : Node_Id;
begin
if Is_Derived_Type (F_Typ)
and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration
then
Indic := Subtype_Indication
(Type_Definition (Original_Node (Parent (F_Typ))));
if Nkind (Indic) = N_Subtype_Indication then
G_Typ := Entity (Subtype_Mark (Indic));
else
G_Typ := Entity (Indic);
end if;
if Nkind (Parent (G_Typ)) = N_Subtype_Declaration
and then Present (Generic_Parent_Type (Parent (G_Typ)))
then
return Generic_Parent_Type (Parent (G_Typ));
end if;
end if;
return Empty;
end Get_Generic_Parent_Type;
function Types_Correspond
(P_Type : Entity_Id;
N_Type : Entity_Id) return Boolean
is
Prev_Type : Entity_Id := Base_Type (P_Type);
New_Type : Entity_Id := Base_Type (N_Type);
begin
if Ekind (Prev_Type) = E_Anonymous_Access_Type then
Prev_Type := Designated_Type (Prev_Type);
end if;
if Ekind (New_Type) = E_Anonymous_Access_Type then
New_Type := Designated_Type (New_Type);
end if;
if Prev_Type = New_Type then
return True;
elsif not Is_Class_Wide_Type (New_Type) then
while Etype (New_Type) /= New_Type loop
New_Type := Etype (New_Type);
if New_Type = Prev_Type then
return True;
end if;
end loop;
end if;
return False;
end Types_Correspond;
begin
if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then
return True;
elsif Ekind (Current_Scope) = E_Package
and then Is_Generic_Instance (Current_Scope)
and then In_Private_Part (Current_Scope)
and then Comes_From_Source (New_E)
then
Formal := First_Formal (Prev_E);
while Present (Formal) loop
F_Typ := Base_Type (Etype (Formal));
if Ekind (F_Typ) = E_Anonymous_Access_Type then
F_Typ := Designated_Type (F_Typ);
end if;
G_Typ := Get_Generic_Parent_Type (F_Typ);
Next_Formal (Formal);
end loop;
if No (G_Typ) and then Ekind (Prev_E) = E_Function then
G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E)));
end if;
if No (G_Typ) then
return False;
end if;
if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration
and then Nkind (Formal_Type_Definition (Parent (G_Typ))) =
N_Formal_Private_Type_Definition
then
return True;
else
declare
P_Formal : Entity_Id;
N_Formal : Entity_Id;
P_Typ : Entity_Id;
N_Typ : Entity_Id;
P_Prim : Entity_Id;
Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ));
begin
while Present (Prim_Elt) loop
P_Prim := Node (Prim_Elt);
if Chars (P_Prim) = Chars (New_E)
and then Ekind (P_Prim) = Ekind (New_E)
then
P_Formal := First_Formal (P_Prim);
N_Formal := First_Formal (New_E);
while Present (P_Formal) and then Present (N_Formal) loop
P_Typ := Etype (P_Formal);
N_Typ := Etype (N_Formal);
if not Types_Correspond (P_Typ, N_Typ) then
exit;
end if;
Next_Entity (P_Formal);
Next_Entity (N_Formal);
end loop;
if No (P_Formal)
and then No (N_Formal)
and then (Ekind (New_E) /= E_Function
or else
Types_Correspond
(Etype (P_Prim), Etype (New_E)))
then
return False;
end if;
end if;
Next_Elmt (Prim_Elt);
end loop;
return True;
end;
end if;
else
return False;
end if;
end Is_Non_Overriding_Operation;
procedure Make_Inequality_Operator (S : Entity_Id) is
Loc : constant Source_Ptr := Sloc (S);
Decl : Node_Id;
Formals : List_Id;
Op_Name : Entity_Id;
FF : constant Entity_Id := First_Formal (S);
NF : constant Entity_Id := Next_Formal (FF);
begin
if No (NF) then
return;
end if;
declare
A : constant Entity_Id :=
Make_Defining_Identifier (Sloc (FF),
Chars => Chars (FF));
B : constant Entity_Id :=
Make_Defining_Identifier (Sloc (NF),
Chars => Chars (NF));
begin
Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne);
Formals := New_List (
Make_Parameter_Specification (Loc,
Defining_Identifier => A,
Parameter_Type =>
New_Reference_To (Etype (First_Formal (S)),
Sloc (Etype (First_Formal (S))))),
Make_Parameter_Specification (Loc,
Defining_Identifier => B,
Parameter_Type =>
New_Reference_To (Etype (Next_Formal (First_Formal (S))),
Sloc (Etype (Next_Formal (First_Formal (S)))))));
Decl :=
Make_Subprogram_Declaration (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name => Op_Name,
Parameter_Specifications => Formals,
Result_Definition =>
New_Reference_To (Standard_Boolean, Loc)));
if No (Alias (S)) then
Insert_After (Unit_Declaration_Node (S), Decl);
elsif Is_List_Member (Parent (S)) then
Insert_After (Parent (S), Decl);
else
Insert_After (Parent (Etype (First_Formal (S))), Decl);
end if;
Mark_Rewrite_Insertion (Decl);
Set_Is_Intrinsic_Subprogram (Op_Name);
Analyze (Decl);
Remove (Decl);
Set_Has_Completion (Op_Name);
Set_Corresponding_Equality (Op_Name, S);
Set_Is_Abstract (Op_Name, Is_Abstract (S));
end;
end Make_Inequality_Operator;
procedure May_Need_Actuals (Fun : Entity_Id) is
F : Entity_Id;
B : Boolean;
begin
F := First_Formal (Fun);
B := True;
while Present (F) loop
if No (Default_Value (F)) then
B := False;
exit;
end if;
Next_Formal (F);
end loop;
Set_Needs_No_Actuals (Fun, B);
end May_Need_Actuals;
function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
Result : Boolean;
begin
Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result);
return Result;
end Mode_Conformant;
procedure New_Overloaded_Entity
(S : Entity_Id;
Derived_Type : Entity_Id := Empty)
is
Does_Override : Boolean := False;
E : Entity_Id;
Prev_Vis : Entity_Id := Empty;
Is_Alias_Interface : Boolean := False;
function Is_Private_Declaration (E : Entity_Id) return Boolean;
procedure Maybe_Primitive_Operation (Is_Overriding : Boolean := False);
function Is_Private_Declaration (E : Entity_Id) return Boolean is
Priv_Decls : List_Id;
Decl : constant Node_Id := Unit_Declaration_Node (E);
begin
if Is_Package_Or_Generic_Package (Current_Scope)
and then In_Private_Part (Current_Scope)
then
Priv_Decls :=
Private_Declarations (
Specification (Unit_Declaration_Node (Current_Scope)));
return In_Package_Body (Current_Scope)
or else
(Is_List_Member (Decl)
and then List_Containing (Decl) = Priv_Decls)
or else (Nkind (Parent (Decl)) = N_Package_Specification
and then not Is_Compilation_Unit (
Defining_Entity (Parent (Decl)))
and then List_Containing (Parent (Parent (Decl)))
= Priv_Decls);
else
return False;
end if;
end Is_Private_Declaration;
procedure Maybe_Primitive_Operation (Is_Overriding : Boolean := False) is
Formal : Entity_Id;
F_Typ : Entity_Id;
B_Typ : Entity_Id;
function Visible_Part_Type (T : Entity_Id) return Boolean;
procedure Check_Private_Overriding (T : Entity_Id);
procedure Check_Private_Overriding (T : Entity_Id) is
begin
if Ekind (Current_Scope) = E_Package
and then In_Private_Part (Current_Scope)
and then Visible_Part_Type (T)
and then not In_Instance
then
if Is_Abstract (T)
and then Is_Abstract (S)
and then (not Is_Overriding or else not Is_Abstract (E))
then
if not Is_Interface (T) then
Error_Msg_N ("abstract subprograms must be visible "
& "('R'M 3.9.3(10))!", S);
else
Error_Msg_N ("primitive subprograms of interface types "
& "declared in a visible part, must be declared in "
& "the visible part ('R'M 3.9.4)!", S);
end if;
elsif Ekind (S) = E_Function
and then Is_Tagged_Type (T)
and then T = Base_Type (Etype (S))
and then not Is_Overriding
then
Error_Msg_N
("private function with tagged result must"
& " override visible-part function", S);
Error_Msg_N
("\move subprogram to the visible part"
& " ('R'M 3.9.3(10))", S);
end if;
end if;
end Check_Private_Overriding;
function Visible_Part_Type (T : Entity_Id) return Boolean is
P : constant Node_Id := Unit_Declaration_Node (Scope (T));
N : Node_Id;
begin
if Ekind (T) in Private_Kind then
return True;
end if;
N := First (Visible_Declarations (Specification (P)));
while Present (N) loop
if Nkind (N) = N_Full_Type_Declaration
and then Present (Defining_Identifier (N))
and then T = Defining_Identifier (N)
then
return True;
elsif (Nkind (N) = N_Private_Type_Declaration
or else
Nkind (N) = N_Private_Extension_Declaration)
and then Present (Defining_Identifier (N))
and then T = Full_View (Defining_Identifier (N))
then
return True;
end if;
Next (N);
end loop;
return False;
end Visible_Part_Type;
begin
if not Comes_From_Source (S) then
null;
elsif Current_Scope = Standard_Standard then
null;
elsif (Ekind (Current_Scope) = E_Package
and then not In_Package_Body (Current_Scope))
or else Is_Overriding
then
if Ekind (S) = E_Function then
B_Typ := Base_Type (Etype (S));
if Scope (B_Typ) = Current_Scope then
Set_Has_Primitive_Operations (B_Typ);
Check_Private_Overriding (B_Typ);
end if;
end if;
Formal := First_Formal (S);
while Present (Formal) loop
if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
F_Typ := Designated_Type (Etype (Formal));
else
F_Typ := Etype (Formal);
end if;
B_Typ := Base_Type (F_Typ);
if Scope (B_Typ) = Current_Scope then
Set_Has_Primitive_Operations (B_Typ);
Check_Private_Overriding (B_Typ);
end if;
Next_Formal (Formal);
end loop;
end if;
end Maybe_Primitive_Operation;
begin
E := Current_Entity_In_Scope (S);
if No (E) then
Enter_Overloaded_Entity (S);
Check_Dispatching_Operation (S, Empty);
Maybe_Primitive_Operation;
if Ekind (S) not in Subprogram_Kind
or else Ekind (Scope (S)) /= E_Protected_Type
then
Check_Overriding_Indicator (S, False);
end if;
elsif not Is_Overloadable (E) then
if Ekind (E) = E_Package
and then Present (Renamed_Object (E))
and then Renamed_Object (E) = Current_Scope
and then Nkind (Parent (Renamed_Object (E))) =
N_Package_Specification
and then Present (Generic_Parent (Parent (Renamed_Object (E))))
then
Set_Is_Hidden (E);
Set_Is_Immediately_Visible (E, False);
Enter_Overloaded_Entity (S);
Set_Homonym (S, Homonym (E));
Check_Dispatching_Operation (S, Empty);
Check_Overriding_Indicator (S, False);
elsif Present (Alias (S))
and then not Comes_From_Source (S)
then
Set_Scope (S, Current_Scope);
if Is_Dispatching_Operation (Alias (S)) then
Check_Dispatching_Operation (S, Empty);
end if;
return;
else
Error_Msg_Sloc := Sloc (E);
Error_Msg_N ("& conflicts with declaration#", S);
if Is_Generic_Unit (E) then
Error_Msg_N ("\previous generic unit cannot be overloaded", S);
end if;
return;
end if;
else
Is_Alias_Interface :=
Present (Alias (S))
and then Is_Dispatching_Operation (Alias (S))
and then Present (DTC_Entity (Alias (S)))
and then Is_Interface (Scope (DTC_Entity (Alias (S))));
while Present (E) loop
if Scope (E) /= Current_Scope then
null;
elsif not Is_Alias_Interface
and then Type_Conformant (E, S)
and then not (Is_Subprogram (E)
and then Present (Abstract_Interface_Alias (E)))
then
if Present (Alias (S))
and then (No (Alias (E))
or else Comes_From_Source (E)
or else Is_Dispatching_Operation (E))
and then
(Ekind (E) = E_Entry
or else Ekind (E) /= E_Enumeration_Literal)
then
if Is_Package_Or_Generic_Package (Current_Scope)
and then In_Private_Part (Current_Scope)
then
Check_Operation_From_Private_View (S, E);
end if;
Set_Is_Overriding_Operation (E);
if Comes_From_Source (E) then
Check_Overriding_Indicator (E, True);
if Present (Alias (S)) then
Set_Overridden_Operation (E, Alias (S));
else
Set_Overridden_Operation (E, S);
end if;
end if;
return;
elsif Ekind (E) /= E_Entry
and then not Comes_From_Source (E)
and then not Is_Generic_Instance (E)
and then (Present (Alias (E))
or else Is_Intrinsic_Subprogram (E))
and then (not In_Instance
or else No (Parent (E))
or else Nkind (Unit_Declaration_Node (E)) /=
N_Subprogram_Renaming_Declaration)
then
if Is_Child_Unit (S) then
Error_Msg_N
("child unit overrides inherited subprogram in parent",
S);
return;
end if;
if Is_Non_Overriding_Operation (E, S) then
Enter_Overloaded_Entity (S);
if No (Derived_Type)
or else Is_Tagged_Type (Derived_Type)
then
Check_Dispatching_Operation (S, Empty);
end if;
return;
end if;
Does_Override := True;
declare
Prev : Entity_Id;
begin
Prev := First_Entity (Current_Scope);
while Present (Prev)
and then Next_Entity (Prev) /= E
loop
Next_Entity (Prev);
end loop;
pragma Assert
(Present (Prev) or else Chars (E) = Name_Op_Concat);
if Debug_Flag_E then
Write_Str ("Override implicit operation ");
Write_Int (Int (E));
Write_Eol;
end if;
if Chars (E) /= Name_Op_Concat
or else Ekind (E) /= E_Operator
then
if Is_Private_Declaration (S) then
if not Is_Dispatching_Operation (E) then
Set_Is_Immediately_Visible (E, False);
else
null;
end if;
else
if E = Current_Entity (E) then
Prev_Vis := Empty;
else
Prev_Vis := Current_Entity (E);
while Homonym (Prev_Vis) /= E loop
Prev_Vis := Homonym (Prev_Vis);
end loop;
end if;
if Prev_Vis /= Empty then
Set_Homonym (Prev_Vis, Homonym (E));
else
Set_Name_Entity_Id (Chars (E), Homonym (E));
end if;
Set_Next_Entity (Prev, Next_Entity (E));
if No (Next_Entity (Prev)) then
Set_Last_Entity (Current_Scope, Prev);
end if;
end if;
end if;
Enter_Overloaded_Entity (S);
Set_Is_Overriding_Operation (S);
Check_Overriding_Indicator (S, True);
if Comes_From_Source (S) then
if Present (Alias (E)) then
Set_Overridden_Operation (S, Alias (E));
else
Set_Overridden_Operation (S, E);
end if;
end if;
if Is_Dispatching_Operation (E) then
Set_Convention (S, Convention (E));
if Has_Homonym (E)
and then Present (Alias (E))
and then Ekind (Alias (E)) /= E_Operator
and then Present (DTC_Entity (Alias (E)))
and then Is_Interface (Scope (DTC_Entity
(Alias (E))))
then
declare
E1 : Entity_Id;
begin
E1 := Homonym (E);
while Present (E1) loop
if (Is_Overloadable (E1)
or else Ekind (E1) = E_Subprogram_Type)
and then Present (Alias (E1))
and then Ekind (Alias (E1)) /= E_Operator
and then Present (DTC_Entity (Alias (E1)))
and then Is_Abstract
(Scope (DTC_Entity (Alias (E1))))
and then Type_Conformant (E1, S)
then
Check_Dispatching_Operation (S, E1);
end if;
E1 := Homonym (E1);
end loop;
end;
end if;
Check_Dispatching_Operation (S, E);
declare
E1 : Entity_Id;
begin
E1 := Current_Entity_In_Scope (S);
while Present (E1) loop
if Is_Subprogram (E1)
and then Present
(Abstract_Interface_Alias (E1))
and then Alias (E1) = E
then
Set_Alias (E1, S);
end if;
E1 := Homonym (E1);
end loop;
end;
else
Check_Dispatching_Operation (S, Empty);
end if;
Maybe_Primitive_Operation (Is_Overriding => True);
goto Check_Inequality;
end;
elsif (In_Instance_Visible_Part
and then not Is_Dispatching_Operation (E))
or else In_Instance_Not_Visible
then
null;
else
Error_Msg_Sloc := Sloc (E);
Set_Scope (S, Current_Scope);
Error_Msg_N ("& conflicts with declaration#", S);
if Is_Generic_Instance (S)
and then not Has_Completion (E)
then
Error_Msg_N
("\instantiation cannot provide body for it", S);
end if;
return;
end if;
else
if May_Hide_Profile then
declare
F1 : Entity_Id;
F2 : Entity_Id;
begin
F1 := First_Formal (S);
F2 := First_Formal (E);
while Present (F1) and then Present (F2) loop
if Is_Access_Type (Etype (F1)) then
if not Is_Access_Type (Etype (F2))
or else not Conforming_Types
(Designated_Type (Etype (F1)),
Designated_Type (Etype (F2)),
Type_Conformant)
then
May_Hide_Profile := False;
end if;
elsif
not Conforming_Types
(Etype (F1), Etype (F2), Type_Conformant)
then
May_Hide_Profile := False;
end if;
Next_Formal (F1);
Next_Formal (F2);
end loop;
if May_Hide_Profile
and then No (F1)
and then No (F2)
then
Error_Msg_NE ("calls to& may be ambiguous?", S, S);
end if;
end;
end if;
end if;
Prev_Vis := E;
E := Homonym (E);
end loop;
Enter_Overloaded_Entity (S);
Maybe_Primitive_Operation;
Check_Overriding_Indicator (S, Does_Override);
if No (Derived_Type)
or else Is_Tagged_Type (Derived_Type)
then
Check_Dispatching_Operation (S, Empty);
end if;
end if;
<<Check_Inequality>>
if Chars (S) = Name_Op_Eq
and then Etype (S) = Standard_Boolean
and then Present (Parent (S))
and then not Is_Dispatching_Operation (S)
then
Make_Inequality_Operator (S);
end if;
end New_Overloaded_Entity;
procedure Process_Formals
(T : List_Id;
Related_Nod : Node_Id)
is
Param_Spec : Node_Id;
Formal : Entity_Id;
Formal_Type : Entity_Id;
Default : Node_Id;
Ptype : Entity_Id;
function Is_Class_Wide_Default (D : Node_Id) return Boolean;
function Is_Class_Wide_Default (D : Node_Id) return Boolean is
begin
return Is_Class_Wide_Type (Designated_Type (Etype (D)))
or else (Nkind (D) = N_Attribute_Reference
and then Attribute_Name (D) = Name_Access
and then Is_Class_Wide_Type (Etype (Prefix (D))));
end Is_Class_Wide_Default;
begin
Param_Spec := First (T);
while Present (Param_Spec) loop
Formal := Defining_Identifier (Param_Spec);
Enter_Name (Formal);
if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
Find_Type (Parameter_Type (Param_Spec));
Ptype := Parameter_Type (Param_Spec);
if Ptype = Error then
goto Continue;
end if;
Formal_Type := Entity (Ptype);
if Ekind (Formal_Type) = E_Incomplete_Type
or else (Is_Class_Wide_Type (Formal_Type)
and then Ekind (Root_Type (Formal_Type)) =
E_Incomplete_Type)
then
if Is_Tagged_Type (Formal_Type) then
null;
elsif Nkind (Parent (T)) /= N_Access_Function_Definition
and then Nkind (Parent (T)) /= N_Access_Procedure_Definition
then
Error_Msg_N ("invalid use of incomplete type", Param_Spec);
end if;
elsif Ekind (Formal_Type) = E_Void then
Error_Msg_NE ("premature use of&",
Parameter_Type (Param_Spec), Formal_Type);
end if;
if Ada_Version >= Ada_05
and then Is_Access_Type (Formal_Type)
and then Null_Exclusion_Present (Param_Spec)
then
if Can_Never_Be_Null (Formal_Type)
and then Comes_From_Source (Related_Nod)
then
Error_Msg_N
("null exclusion must apply to a type that does not "
& "exclude null ('R'M 3.10 (14)", Related_Nod);
end if;
Formal_Type :=
Create_Null_Excluding_Itype
(T => Formal_Type,
Related_Nod => Related_Nod,
Scope_Id => Scope (Current_Scope));
end if;
else
Formal_Type :=
Access_Definition (Related_Nod, Parameter_Type (Param_Spec));
declare
AD : constant Node_Id :=
Access_To_Subprogram_Definition
(Parameter_Type (Param_Spec));
begin
if Present (AD) and then Protected_Present (AD) then
Formal_Type :=
Replace_Anonymous_Access_To_Protected_Subprogram
(Param_Spec, Formal_Type);
end if;
end;
end if;
Set_Etype (Formal, Formal_Type);
Default := Expression (Param_Spec);
if Present (Default) then
if Out_Present (Param_Spec) then
Error_Msg_N
("default initialization only allowed for IN parameters",
Param_Spec);
end if;
Analyze_Per_Use_Expression (Default, Formal_Type);
if Ekind (Formal_Type) = E_Anonymous_Access_Type
and then not From_With_Type (Formal_Type)
and then Is_Class_Wide_Default (Default)
and then not Is_Class_Wide_Type (Designated_Type (Formal_Type))
then
Error_Msg_N
("access to class-wide expression not allowed here", Default);
end if;
end if;
if Ada_Version >= Ada_05
and then Is_Access_Type (Etype (Formal))
and then Can_Never_Be_Null (Etype (Formal))
then
Null_Exclusion_Static_Checks (Param_Spec);
end if;
<<Continue>>
Next (Param_Spec);
end loop;
if Nkind (Related_Nod) = N_Function_Specification then
Analyze_Return_Type (Related_Nod);
end if;
Param_Spec := First (T);
while Present (Param_Spec) loop
Formal := Defining_Identifier (Param_Spec);
Set_Formal_Mode (Formal);
if Ekind (Formal) = E_In_Parameter then
Set_Default_Value (Formal, Expression (Param_Spec));
if Present (Expression (Param_Spec)) then
Default := Expression (Param_Spec);
if Is_Scalar_Type (Etype (Default)) then
if Nkind
(Parameter_Type (Param_Spec)) /= N_Access_Definition
then
Formal_Type := Entity (Parameter_Type (Param_Spec));
else
Formal_Type := Access_Definition
(Related_Nod, Parameter_Type (Param_Spec));
end if;
Apply_Scalar_Range_Check (Default, Formal_Type);
end if;
end if;
end if;
Next (Param_Spec);
end loop;
end Process_Formals;
procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is
Fs : Entity_Id;
Fb : Entity_Id;
begin
if Error_Posted (Spec) then
return;
end if;
Fs := First_Formal (Spec);
Fb := First_Formal (Bod);
while Present (Fs) loop
Generate_Reference (Fs, Fb, 'b');
if Style_Check then
Style.Check_Identifier (Fb, Fs);
end if;
Set_Spec_Entity (Fb, Fs);
Set_Referenced (Fs, False);
Next_Formal (Fs);
Next_Formal (Fb);
end loop;
end Reference_Body_Formals;
procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N);
Decl : Node_Id;
Formal : Entity_Id;
T : Entity_Id;
First_Stmt : Node_Id := Empty;
AS_Needed : Boolean;
begin
if Ekind (Subp) = E_Procedure
and then Is_Null_Init_Proc (Subp)
then
return;
end if;
Formal := First_Formal (Subp);
while Present (Formal) loop
T := Etype (Formal);
if Is_Constrained (T) then
AS_Needed := False;
elsif Has_Unknown_Discriminants (T) then
AS_Needed := False;
elsif Is_Array_Type (T) then
AS_Needed := True;
elsif Is_Record_Type (T)
and then Ekind (Formal) = E_In_Parameter
and then Chars (Formal) /= Name_uInit
and then not Is_Unchecked_Union (T)
and then not Is_Discrim_SO_Function (Subp)
then
AS_Needed := True;
else
AS_Needed := False;
end if;
if AS_Needed then
if Nkind (N) = N_Accept_Statement then
if Expander_Active then
Decl := Build_Actual_Subtype (T, Renamed_Object (Formal));
else
Decl := Build_Actual_Subtype (T, Formal);
end if;
if Present (Handled_Statement_Sequence (N)) then
First_Stmt :=
First (Statements (Handled_Statement_Sequence (N)));
Prepend (Decl, Statements (Handled_Statement_Sequence (N)));
Mark_Rewrite_Insertion (Decl);
else
return;
end if;
else
Decl := Build_Actual_Subtype (T, Formal);
Prepend (Decl, Declarations (N));
Mark_Rewrite_Insertion (Decl);
end if;
Analyze (Decl, Suppress => All_Checks);
if Present (First_Stmt) then
Insert_List_Before_And_Analyze (First_Stmt,
Freeze_Entity (Defining_Identifier (Decl), Loc));
end if;
if Nkind (N) = N_Accept_Statement
and then Expander_Active
then
Set_Actual_Subtype (Renamed_Object (Formal),
Defining_Identifier (Decl));
else
Set_Actual_Subtype (Formal, Defining_Identifier (Decl));
end if;
end if;
Next_Formal (Formal);
end loop;
end Set_Actual_Subtypes;
procedure Set_Formal_Mode (Formal_Id : Entity_Id) is
Spec : constant Node_Id := Parent (Formal_Id);
begin
if Out_Present (Spec) then
if Ekind (Scope (Formal_Id)) = E_Function
or else Ekind (Scope (Formal_Id)) = E_Generic_Function
then
Error_Msg_N ("functions can only have IN parameters", Spec);
Set_Ekind (Formal_Id, E_In_Parameter);
elsif In_Present (Spec) then
Set_Ekind (Formal_Id, E_In_Out_Parameter);
else
Set_Ekind (Formal_Id, E_Out_Parameter);
Set_Never_Set_In_Source (Formal_Id, True);
Set_Is_True_Constant (Formal_Id, False);
Set_Current_Value (Formal_Id, Empty);
end if;
else
Set_Ekind (Formal_Id, E_In_Parameter);
end if;
if Nkind (Parameter_Type (Spec)) = N_Access_Definition then
if Ada_Version < Ada_05
or else Can_Never_Be_Null (Etype (Formal_Id))
then
Set_Is_Known_Non_Null (Formal_Id);
Set_Can_Never_Be_Null (Formal_Id);
end if;
elsif Is_Access_Type (Etype (Formal_Id))
and then Can_Never_Be_Null (Etype (Formal_Id))
then
Set_Is_Known_Non_Null (Formal_Id);
end if;
Set_Mechanism (Formal_Id, Default_Mechanism);
Set_Formal_Validity (Formal_Id);
end Set_Formal_Mode;
procedure Set_Formal_Validity (Formal_Id : Entity_Id) is
begin
if not Validity_Checks_On then
return;
elsif Validity_Check_Parameters then
return;
elsif Ekind (Formal_Id) = E_In_Parameter
and then Validity_Check_In_Params
then
Set_Is_Known_Valid (Formal_Id, True);
elsif Ekind (Formal_Id) = E_In_Out_Parameter
and then Validity_Check_In_Out_Params
then
Set_Is_Known_Valid (Formal_Id, True);
end if;
end Set_Formal_Validity;
function Subtype_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
Result : Boolean;
begin
Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result);
return Result;
end Subtype_Conformant;
function Type_Conformant
(New_Id : Entity_Id;
Old_Id : Entity_Id;
Skip_Controlling_Formals : Boolean := False) return Boolean
is
Result : Boolean;
begin
May_Hide_Profile := False;
Check_Conformance
(New_Id, Old_Id, Type_Conformant, False, Result,
Skip_Controlling_Formals => Skip_Controlling_Formals);
return Result;
end Type_Conformant;
procedure Valid_Operator_Definition (Designator : Entity_Id) is
N : Integer := 0;
F : Entity_Id;
Id : constant Name_Id := Chars (Designator);
N_OK : Boolean;
begin
F := First_Formal (Designator);
while Present (F) loop
N := N + 1;
if Present (Default_Value (F)) then
Error_Msg_N
("default values not allowed for operator parameters",
Parent (F));
end if;
Next_Formal (F);
end loop;
if Id = Name_Op_Not
or else Id = Name_Op_Abs
then
N_OK := (N = 1);
elsif Id = Name_Op_Add
or Id = Name_Op_Subtract
then
N_OK := (N in 1 .. 2);
else
N_OK := (N = 2);
end if;
if not N_OK then
Error_Msg_N
("incorrect number of arguments for operator", Designator);
end if;
if Id = Name_Op_Ne
and then Base_Type (Etype (Designator)) = Standard_Boolean
and then not Is_Intrinsic_Subprogram (Designator)
then
Error_Msg_N
("explicit definition of inequality not allowed", Designator);
end if;
end Valid_Operator_Definition;
end Sem_Ch6;