with Atree; use Atree;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Expander; use Expander;
with Fname; use Fname;
with Fname.UF; use Fname.UF;
with Freeze; use Freeze;
with Hostparm;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Lib.Xref; use Lib.Xref;
with Nlists; use Nlists;
with Namet; use Namet;
with Nmake; use Nmake;
with Opt; use Opt;
with Rident; use Rident;
with Restrict; use Restrict;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch10; use Sem_Ch10;
with Sem_Ch13; use Sem_Ch13;
with Sem_Disp; use Sem_Disp;
with Sem_Elab; use Sem_Elab;
with Sem_Elim; use Sem_Elim;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.CN; use Sinfo.CN;
with Sinput; use Sinput;
with Sinput.L; use Sinput.L;
with Snames; use Snames;
with Stringt; use Stringt;
with Uname; use Uname;
with Table;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Urealp; use Urealp;
with GNAT.HTable;
package body Sem_Ch12 is
Circularity_Detected : Boolean := False;
procedure Abandon_Instantiation (N : Node_Id);
pragma No_Return (Abandon_Instantiation);
procedure Analyze_Formal_Array_Type
(T : in out Entity_Id;
Def : Node_Id);
procedure Analyze_Formal_Derived_Interface_Type
(T : Entity_Id;
Def : Node_Id);
procedure Analyze_Formal_Derived_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id);
procedure Analyze_Formal_Decimal_Fixed_Point_Type
(T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Discrete_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Floating_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Interface_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Signed_Integer_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Modular_Type (T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Ordinary_Fixed_Point_Type
(T : Entity_Id; Def : Node_Id);
procedure Analyze_Formal_Private_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id);
procedure Analyze_Generic_Formal_Part (N : Node_Id);
procedure Analyze_Generic_Access_Type (T : Entity_Id; Def : Node_Id);
function Analyze_Associations
(I_Node : Node_Id;
Formals : List_Id;
F_Copy : List_Id) return List_Id;
procedure Analyze_Subprogram_Instantiation
(N : Node_Id;
K : Entity_Kind);
procedure Build_Instance_Compilation_Unit_Nodes
(N : Node_Id;
Act_Body : Node_Id;
Act_Decl : Node_Id);
procedure Check_Formal_Packages (P_Id : Entity_Id);
procedure Check_Formal_Package_Instance
(Formal_Pack : Entity_Id;
Actual_Pack : Entity_Id);
procedure Check_Forward_Instantiation (Decl : Node_Id);
procedure Check_Hidden_Child_Unit
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl_Id : Entity_Id);
procedure Check_Private_View (N : Node_Id);
procedure Check_Generic_Actuals
(Instance : Entity_Id;
Is_Formal_Box : Boolean);
function Contains_Instance_Of
(Inner : Entity_Id;
Outer : Entity_Id;
N : Node_Id) return Boolean;
function Denotes_Formal_Package
(Pack : Entity_Id;
On_Exit : Boolean := False) return Boolean;
function Find_Actual_Type
(Typ : Entity_Id;
Gen_Scope : Entity_Id) return Entity_Id;
function In_Same_Declarative_Part
(F_Node : Node_Id;
Inst : Node_Id) return Boolean;
function In_Main_Context (E : Entity_Id) return Boolean;
procedure Set_Instance_Env
(Gen_Unit : Entity_Id;
Act_Unit : Entity_Id);
procedure Set_Instance_Of (A : Entity_Id; B : Entity_Id);
function Has_Been_Exchanged (E : Entity_Id) return Boolean;
procedure Hide_Current_Scope;
procedure Install_Body
(Act_Body : Node_Id;
N : Node_Id;
Gen_Body : Node_Id;
Gen_Decl : Node_Id);
procedure Insert_After_Last_Decl (N : Node_Id; F_Node : Node_Id);
procedure Freeze_Subprogram_Body
(Inst_Node : Node_Id;
Gen_Body : Node_Id;
Pack_Id : Entity_Id);
procedure Init_Env;
procedure Install_Parent (P : Entity_Id; In_Body : Boolean := False);
procedure Remove_Parent (In_Body : Boolean := False);
procedure Inline_Instance_Body
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl : Node_Id);
function Instantiate_Object
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id;
function Instantiate_Type
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id;
Actual_Decls : List_Id) return Node_Id;
function Instantiate_Formal_Subprogram
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return Node_Id;
function Instantiate_Formal_Package
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id;
function Is_In_Main_Unit (N : Node_Id) return Boolean;
procedure Load_Parent_Of_Generic (N : Node_Id; Spec : Node_Id);
procedure Inherit_Context (Gen_Decl : Node_Id; Inst : Node_Id);
function Get_Associated_Node (N : Node_Id) return Node_Id;
procedure Move_Freeze_Nodes
(Out_Of : Entity_Id;
After : Node_Id;
L : List_Id);
procedure Pre_Analyze_Actuals (N : Node_Id);
procedure Valid_Default_Attribute (Nam : Entity_Id; Def : Node_Id);
type Assoc_Ptr is new Int;
Assoc_Null : constant Assoc_Ptr := -1;
type Assoc is record
Gen_Id : Entity_Id;
Act_Id : Entity_Id;
Next_In_HTable : Assoc_Ptr;
end record;
package Generic_Renamings is new Table.Table
(Table_Component_Type => Assoc,
Table_Index_Type => Assoc_Ptr,
Table_Low_Bound => 0,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Generic_Renamings");
Current_Instantiated_Parent : Assoc := (Empty, Empty, Assoc_Null);
HTable_Size : constant := 37;
type HTable_Range is range 0 .. HTable_Size - 1;
procedure Set_Next_Assoc (E : Assoc_Ptr; Next : Assoc_Ptr);
function Next_Assoc (E : Assoc_Ptr) return Assoc_Ptr;
function Get_Gen_Id (E : Assoc_Ptr) return Entity_Id;
function Hash (F : Entity_Id) return HTable_Range;
package Generic_Renamings_HTable is new GNAT.HTable.Static_HTable (
Header_Num => HTable_Range,
Element => Assoc,
Elmt_Ptr => Assoc_Ptr,
Null_Ptr => Assoc_Null,
Set_Next => Set_Next_Assoc,
Next => Next_Assoc,
Key => Entity_Id,
Get_Key => Get_Gen_Id,
Hash => Hash,
Equal => "=");
Exchanged_Views : Elist_Id;
Hidden_Entities : Elist_Id;
Parent_Unit_Visible : Boolean := False;
Instance_Parent_Unit : Entity_Id := Empty;
type Instance_Env is record
Ada_Version : Ada_Version_Type;
Ada_Version_Explicit : Ada_Version_Type;
Instantiated_Parent : Assoc;
Exchanged_Views : Elist_Id;
Hidden_Entities : Elist_Id;
Current_Sem_Unit : Unit_Number_Type;
Parent_Unit_Visible : Boolean := False;
Instance_Parent_Unit : Entity_Id := Empty;
end record;
package Instance_Envs is new Table.Table (
Table_Component_Type => Instance_Env,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 32,
Table_Increment => 100,
Table_Name => "Instance_Envs");
procedure Restore_Private_Views
(Pack_Id : Entity_Id;
Is_Package : Boolean := True);
procedure Switch_View (T : Entity_Id);
Instantiation_Node : Node_Id;
Instantiation_Error : exception;
S_Adjustment : Sloc_Adjustment;
package Generic_Flags is new Table.Table (
Table_Component_Type => Boolean,
Table_Index_Type => Int,
Table_Low_Bound => 0,
Table_Initial => 32,
Table_Increment => 200,
Table_Name => "Generic_Flags");
procedure Abandon_Instantiation (N : Node_Id) is
begin
Error_Msg_N ("instantiation abandoned!", N);
raise Instantiation_Error;
end Abandon_Instantiation;
function Analyze_Associations
(I_Node : Node_Id;
Formals : List_Id;
F_Copy : List_Id) return List_Id
is
Actual_Types : constant Elist_Id := New_Elmt_List;
Assoc : constant List_Id := New_List;
Defaults : constant Elist_Id := New_Elmt_List;
Gen_Unit : constant Entity_Id := Defining_Entity (Parent (F_Copy));
Actuals : List_Id;
Actual : Node_Id;
Formal : Node_Id;
Next_Formal : Node_Id;
Temp_Formal : Node_Id;
Analyzed_Formal : Node_Id;
Match : Node_Id;
Named : Node_Id;
First_Named : Node_Id := Empty;
Found_Assoc : Node_Id;
Is_Named_Assoc : Boolean;
Num_Matched : Int := 0;
Num_Actuals : Int := 0;
function Matching_Actual
(F : Entity_Id;
A_F : Entity_Id) return Node_Id;
procedure Set_Analyzed_Formal;
function Matching_Actual
(F : Entity_Id;
A_F : Entity_Id) return Node_Id
is
Found : Node_Id;
Prev : Node_Id;
begin
Is_Named_Assoc := False;
if No (Actual) then
Found := Empty;
elsif No (Selector_Name (Actual)) then
Found := Explicit_Generic_Actual_Parameter (Actual);
Found_Assoc := Actual;
Num_Matched := Num_Matched + 1;
Next (Actual);
else
Is_Named_Assoc := True;
Found := Empty;
Prev := Empty;
while Present (Actual) loop
if Chars (Selector_Name (Actual)) = Chars (F) then
Found := Explicit_Generic_Actual_Parameter (Actual);
Set_Entity (Selector_Name (Actual), A_F);
Set_Etype (Selector_Name (Actual), Etype (A_F));
Generate_Reference (A_F, Selector_Name (Actual));
Found_Assoc := Actual;
Num_Matched := Num_Matched + 1;
exit;
end if;
Prev := Actual;
Next (Actual);
end loop;
if Actual = First_Named then
Next (First_Named);
elsif Present (Actual) then
Insert_Before (First_Named, Remove_Next (Prev));
end if;
Actual := First_Named;
end if;
return Found;
end Matching_Actual;
procedure Set_Analyzed_Formal is
Kind : Node_Kind;
begin
while Present (Analyzed_Formal) loop
Kind := Nkind (Analyzed_Formal);
case Nkind (Formal) is
when N_Formal_Subprogram_Declaration =>
exit when Kind in N_Formal_Subprogram_Declaration
and then
Chars
(Defining_Unit_Name (Specification (Formal))) =
Chars
(Defining_Unit_Name (Specification (Analyzed_Formal)));
when N_Formal_Package_Declaration =>
exit when
Kind = N_Formal_Package_Declaration
or else
Kind = N_Generic_Package_Declaration;
when N_Use_Package_Clause | N_Use_Type_Clause => exit;
when others =>
exit when
Kind not in N_Formal_Subprogram_Declaration
and then Kind /= N_Subprogram_Declaration
and then Kind /= N_Freeze_Entity
and then Kind /= N_Null_Statement
and then Kind /= N_Itype_Reference
and then Chars (Defining_Identifier (Formal)) =
Chars (Defining_Identifier (Analyzed_Formal));
end case;
Next (Analyzed_Formal);
end loop;
end Set_Analyzed_Formal;
begin
Actuals := Generic_Associations (I_Node);
if Present (Actuals) then
First_Named := First (Actuals);
while Present (First_Named)
and then No (Selector_Name (First_Named))
loop
Num_Actuals := Num_Actuals + 1;
Next (First_Named);
end loop;
end if;
Named := First_Named;
while Present (Named) loop
if No (Selector_Name (Named)) then
Error_Msg_N ("invalid positional actual after named one", Named);
Abandon_Instantiation (Named);
end if;
if Present (Explicit_Generic_Actual_Parameter (Named)) then
Num_Actuals := Num_Actuals + 1;
end if;
Next (Named);
end loop;
if Present (Formals) then
Formal := First_Non_Pragma (Formals);
Analyzed_Formal := First_Non_Pragma (F_Copy);
if Present (Actuals) then
Actual := First (Actuals);
else
Actual := Empty;
end if;
while Present (Formal) loop
Set_Analyzed_Formal;
Next_Formal := Next_Non_Pragma (Formal);
case Nkind (Formal) is
when N_Formal_Object_Declaration =>
Match :=
Matching_Actual (
Defining_Identifier (Formal),
Defining_Identifier (Analyzed_Formal));
Append_List
(Instantiate_Object (Formal, Match, Analyzed_Formal),
Assoc);
when N_Formal_Type_Declaration =>
Match :=
Matching_Actual (
Defining_Identifier (Formal),
Defining_Identifier (Analyzed_Formal));
if No (Match) then
Error_Msg_Sloc := Sloc (Gen_Unit);
Error_Msg_NE
("missing actual&",
Instantiation_Node, Defining_Identifier (Formal));
Error_Msg_NE ("\in instantiation of & declared#",
Instantiation_Node, Gen_Unit);
Abandon_Instantiation (Instantiation_Node);
else
Analyze (Match);
Append_To (Assoc,
Instantiate_Type
(Formal, Match, Analyzed_Formal, Assoc));
if Nkind (I_Node) /= N_Formal_Package_Declaration then
Append_Elmt (Entity (Match), Actual_Types);
end if;
end if;
if Nkind (Analyzed_Formal) = N_Formal_Type_Declaration
and then
Nkind (Formal_Type_Definition (Analyzed_Formal)) =
N_Access_To_Object_Definition
then
Validate_Remote_Access_To_Class_Wide_Type (Match);
end if;
when N_Formal_Subprogram_Declaration =>
Match :=
Matching_Actual (
Defining_Unit_Name (Specification (Formal)),
Defining_Unit_Name (Specification (Analyzed_Formal)));
if Present (Match)
and then Is_Named_Assoc
and then Comes_From_Source (Found_Assoc)
then
Temp_Formal := First (Formals);
while Present (Temp_Formal) loop
if Nkind (Temp_Formal) in
N_Formal_Subprogram_Declaration
and then Temp_Formal /= Formal
and then
Chars (Selector_Name (Found_Assoc)) =
Chars (Defining_Unit_Name
(Specification (Temp_Formal)))
then
Error_Msg_N
("name not allowed for overloaded formal",
Found_Assoc);
Abandon_Instantiation (Instantiation_Node);
end if;
Next (Temp_Formal);
end loop;
end if;
Append_To (Assoc,
Instantiate_Formal_Subprogram
(Formal, Match, Analyzed_Formal));
if No (Match)
and then Box_Present (Formal)
then
Append_Elmt
(Defining_Unit_Name (Specification (Last (Assoc))),
Defaults);
end if;
when N_Formal_Package_Declaration =>
Match :=
Matching_Actual (
Defining_Identifier (Formal),
Defining_Identifier (Original_Node (Analyzed_Formal)));
if No (Match) then
Error_Msg_Sloc := Sloc (Gen_Unit);
Error_Msg_NE
("missing actual&",
Instantiation_Node, Defining_Identifier (Formal));
Error_Msg_NE ("\in instantiation of & declared#",
Instantiation_Node, Gen_Unit);
Abandon_Instantiation (Instantiation_Node);
else
Analyze (Match);
Append_List
(Instantiate_Formal_Package
(Formal, Match, Analyzed_Formal),
Assoc);
end if;
when N_Use_Package_Clause |
N_Use_Type_Clause =>
Remove (Formal);
Append (Formal, Assoc);
when others =>
raise Program_Error;
end case;
Formal := Next_Formal;
Next_Non_Pragma (Analyzed_Formal);
end loop;
if Num_Actuals > Num_Matched then
Error_Msg_Sloc := Sloc (Gen_Unit);
if Present (Selector_Name (Actual)) then
Error_Msg_NE
("unmatched actual&",
Actual, Selector_Name (Actual));
Error_Msg_NE ("\in instantiation of& declared#",
Actual, Gen_Unit);
else
Error_Msg_NE
("unmatched actual in instantiation of& declared#",
Actual, Gen_Unit);
end if;
end if;
elsif Present (Actuals) then
Error_Msg_N
("too many actuals in generic instantiation", Instantiation_Node);
end if;
declare
Elmt : Elmt_Id := First_Elmt (Actual_Types);
begin
while Present (Elmt) loop
Freeze_Before (I_Node, Node (Elmt));
Next_Elmt (Elmt);
end loop;
end;
declare
Elmt : Elmt_Id;
Subp : Entity_Id;
New_D : Node_Id;
begin
Elmt := First_Elmt (Defaults);
while Present (Elmt) loop
if No (Actuals) then
Actuals := New_List;
Set_Generic_Associations (I_Node, Actuals);
end if;
Subp := Node (Elmt);
New_D :=
Make_Generic_Association (Sloc (Subp),
Selector_Name => New_Occurrence_Of (Subp, Sloc (Subp)),
Explicit_Generic_Actual_Parameter =>
New_Occurrence_Of (Subp, Sloc (Subp)));
Mark_Rewrite_Insertion (New_D);
Append_To (Actuals, New_D);
Next_Elmt (Elmt);
end loop;
end;
return Assoc;
end Analyze_Associations;
procedure Analyze_Formal_Array_Type
(T : in out Entity_Id;
Def : Node_Id)
is
DSS : Node_Id;
begin
Enter_Name (T);
if Nkind (Def) = N_Constrained_Array_Definition then
DSS := First (Discrete_Subtype_Definitions (Def));
while Present (DSS) loop
if Nkind (DSS) = N_Subtype_Indication
or else Nkind (DSS) = N_Range
or else Nkind (DSS) = N_Attribute_Reference
then
Error_Msg_N ("only a subtype mark is allowed in a formal", DSS);
end if;
Next (DSS);
end loop;
end if;
Array_Type_Declaration (T, Def);
Set_Is_Generic_Type (Base_Type (T));
if Ekind (Component_Type (T)) = E_Incomplete_Type
and then No (Full_View (Component_Type (T)))
then
Error_Msg_N ("premature usage of incomplete type", Def);
elsif Is_Internal (Component_Type (T))
and then Present (Subtype_Indication (Component_Definition (Def)))
and then Nkind (Original_Node
(Subtype_Indication (Component_Definition (Def))))
= N_Subtype_Indication
then
Error_Msg_N
("in a formal, a subtype indication can only be "
& "a subtype mark ('R'M 12.5.3(3))",
Subtype_Indication (Component_Definition (Def)));
end if;
end Analyze_Formal_Array_Type;
procedure Analyze_Formal_Decimal_Fixed_Point_Type
(T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Base : constant Entity_Id :=
New_Internal_Entity
(E_Decimal_Fixed_Point_Type,
Current_Scope, Sloc (Def), 'G');
Int_Base : constant Entity_Id := Standard_Integer;
Delta_Val : constant Ureal := Ureal_1;
Digs_Val : constant Uint := Uint_6;
begin
Enter_Name (T);
Set_Etype (Base, Base);
Set_Size_Info (Base, Int_Base);
Set_RM_Size (Base, RM_Size (Int_Base));
Set_First_Rep_Item (Base, First_Rep_Item (Int_Base));
Set_Digits_Value (Base, Digs_Val);
Set_Delta_Value (Base, Delta_Val);
Set_Small_Value (Base, Delta_Val);
Set_Scalar_Range (Base,
Make_Range (Loc,
Low_Bound => Make_Real_Literal (Loc, Ureal_1),
High_Bound => Make_Real_Literal (Loc, Ureal_1)));
Set_Is_Generic_Type (Base);
Set_Parent (Base, Parent (Def));
Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, Int_Base);
Set_RM_Size (T, RM_Size (Int_Base));
Set_First_Rep_Item (T, First_Rep_Item (Int_Base));
Set_Digits_Value (T, Digs_Val);
Set_Delta_Value (T, Delta_Val);
Set_Small_Value (T, Delta_Val);
Set_Scalar_Range (T, Scalar_Range (Base));
Set_Is_Constrained (T);
Check_Restriction (No_Fixed_Point, Def);
end Analyze_Formal_Decimal_Fixed_Point_Type;
procedure Analyze_Formal_Derived_Interface_Type
(T : Entity_Id;
Def : Node_Id)
is
begin
Enter_Name (T);
Set_Ekind (T, E_Record_Type);
Set_Etype (T, T);
Analyze (Subtype_Indication (Def));
Analyze_Interface_Declaration (T, Def);
Make_Class_Wide_Type (T);
Set_Primitive_Operations (T, New_Elmt_List);
Analyze_List (Interface_List (Def));
Collect_Interfaces (Def, T);
end Analyze_Formal_Derived_Interface_Type;
procedure Analyze_Formal_Derived_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Unk_Disc : constant Boolean := Unknown_Discriminants_Present (N);
New_N : Node_Id;
begin
Set_Is_Generic_Type (T);
if Private_Present (Def) then
New_N :=
Make_Private_Extension_Declaration (Loc,
Defining_Identifier => T,
Discriminant_Specifications => Discriminant_Specifications (N),
Unknown_Discriminants_Present => Unk_Disc,
Subtype_Indication => Subtype_Mark (Def));
Set_Abstract_Present (New_N, Abstract_Present (Def));
Set_Limited_Present (New_N, Limited_Present (Def));
else
New_N :=
Make_Full_Type_Declaration (Loc,
Defining_Identifier => T,
Discriminant_Specifications =>
Discriminant_Specifications (Parent (T)),
Type_Definition =>
Make_Derived_Type_Definition (Loc,
Subtype_Indication => Subtype_Mark (Def)));
Set_Abstract_Present
(Type_Definition (New_N), Abstract_Present (Def));
Set_Limited_Present
(Type_Definition (New_N), Limited_Present (Def));
end if;
Rewrite (N, New_N);
Analyze (N);
if Unk_Disc then
if not Is_Composite_Type (T) then
Error_Msg_N
("unknown discriminants not allowed for elementary types", N);
else
Set_Has_Unknown_Discriminants (T);
Set_Is_Constrained (T, False);
end if;
end if;
Set_Size_Known_At_Compile_Time
(T, Size_Known_At_Compile_Time (Entity (Subtype_Mark (Def))));
end Analyze_Formal_Derived_Type;
procedure Analyze_Formal_Discrete_Type (T : Entity_Id; Def : Node_Id) is
Loc : constant Source_Ptr := Sloc (Def);
Lo : Node_Id;
Hi : Node_Id;
Base : constant Entity_Id :=
New_Internal_Entity
(E_Floating_Point_Type, Current_Scope, Sloc (Def), 'G');
begin
Enter_Name (T);
Set_Ekind (T, E_Enumeration_Subtype);
Set_Etype (T, Base);
Init_Size (T, 8);
Init_Alignment (T);
Set_Is_Generic_Type (T);
Set_Is_Constrained (T);
Lo :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Reference_To (T, Loc));
Set_Etype (Lo, T);
Hi :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix => New_Reference_To (T, Loc));
Set_Etype (Hi, T);
Set_Scalar_Range (T,
Make_Range (Loc,
Low_Bound => Lo,
High_Bound => Hi));
Set_Ekind (Base, E_Enumeration_Type);
Set_Etype (Base, Base);
Init_Size (Base, 8);
Init_Alignment (Base);
Set_Is_Generic_Type (Base);
Set_Scalar_Range (Base, Scalar_Range (T));
Set_Parent (Base, Parent (Def));
end Analyze_Formal_Discrete_Type;
procedure Analyze_Formal_Floating_Type (T : Entity_Id; Def : Node_Id) is
Base : constant Entity_Id :=
New_Internal_Entity
(E_Floating_Point_Type, Current_Scope, Sloc (Def), 'G');
begin
Enter_Name (T);
Set_Ekind (T, E_Floating_Point_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, (Standard_Float));
Set_RM_Size (T, RM_Size (Standard_Float));
Set_Digits_Value (T, Digits_Value (Standard_Float));
Set_Scalar_Range (T, Scalar_Range (Standard_Float));
Set_Is_Constrained (T);
Set_Is_Generic_Type (Base);
Set_Etype (Base, Base);
Set_Size_Info (Base, (Standard_Float));
Set_RM_Size (Base, RM_Size (Standard_Float));
Set_Digits_Value (Base, Digits_Value (Standard_Float));
Set_Scalar_Range (Base, Scalar_Range (Standard_Float));
Set_Parent (Base, Parent (Def));
Check_Restriction (No_Floating_Point, Def);
end Analyze_Formal_Floating_Type;
procedure Analyze_Formal_Interface_Type (T : Entity_Id; Def : Node_Id) is
begin
Enter_Name (T);
Set_Ekind (T, E_Record_Type);
Set_Etype (T, T);
Analyze_Interface_Declaration (T, Def);
Make_Class_Wide_Type (T);
Set_Primitive_Operations (T, New_Elmt_List);
end Analyze_Formal_Interface_Type;
procedure Analyze_Formal_Modular_Type (T : Entity_Id; Def : Node_Id) is
begin
Analyze_Formal_Signed_Integer_Type (T, Def);
Set_Ekind (T, E_Modular_Integer_Subtype);
Set_Ekind (Etype (T), E_Modular_Integer_Type);
end Analyze_Formal_Modular_Type;
procedure Analyze_Formal_Object_Declaration (N : Node_Id) is
E : constant Node_Id := Expression (N);
Id : constant Node_Id := Defining_Identifier (N);
K : Entity_Kind;
T : Node_Id;
begin
Enter_Name (Id);
if Out_Present (N) then
K := E_Generic_In_Out_Parameter;
if not In_Present (N) then
Error_Msg_N ("formal generic objects cannot have mode OUT", N);
end if;
else
K := E_Generic_In_Parameter;
end if;
Find_Type (Subtype_Mark (N));
T := Entity (Subtype_Mark (N));
if Ekind (T) = E_Incomplete_Type then
Error_Msg_N ("premature usage of incomplete type", Subtype_Mark (N));
end if;
if K = E_Generic_In_Parameter then
if Ada_Version < Ada_05 and then Is_Limited_Type (T) then
Error_Msg_N
("generic formal of mode IN must not be of limited type", N);
Explain_Limited_Type (T, N);
end if;
if Is_Abstract (T) then
Error_Msg_N
("generic formal of mode IN must not be of abstract type", N);
end if;
if Present (E) then
Analyze_Per_Use_Expression (E, T);
end if;
Set_Ekind (Id, K);
Set_Etype (Id, T);
else
Set_Ekind (Id, K);
Set_Etype (Id, T);
if (Is_Array_Type (T)
and then not Is_Constrained (T))
or else
(Ekind (T) = E_Record_Type
and then Has_Discriminants (T))
then
declare
Non_Freezing_Ref : constant Node_Id :=
New_Reference_To (Id, Sloc (Id));
Decl : Node_Id;
begin
Set_Must_Not_Freeze (Non_Freezing_Ref);
Decl := Build_Actual_Subtype (T, Non_Freezing_Ref);
Insert_Before_And_Analyze (N, Decl);
Set_Actual_Subtype (Id, Defining_Identifier (Decl));
end;
else
Set_Actual_Subtype (Id, T);
end if;
if Present (E) then
Error_Msg_N
("initialization not allowed for `IN OUT` formals", N);
end if;
end if;
end Analyze_Formal_Object_Declaration;
procedure Analyze_Formal_Ordinary_Fixed_Point_Type
(T : Entity_Id;
Def : Node_Id)
is
Loc : constant Source_Ptr := Sloc (Def);
Base : constant Entity_Id :=
New_Internal_Entity
(E_Ordinary_Fixed_Point_Type, Current_Scope, Sloc (Def), 'G');
begin
Enter_Name (T);
Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, Standard_Integer);
Set_RM_Size (T, RM_Size (Standard_Integer));
Set_Small_Value (T, Ureal_1);
Set_Delta_Value (T, Ureal_1);
Set_Scalar_Range (T,
Make_Range (Loc,
Low_Bound => Make_Real_Literal (Loc, Ureal_1),
High_Bound => Make_Real_Literal (Loc, Ureal_1)));
Set_Is_Constrained (T);
Set_Is_Generic_Type (Base);
Set_Etype (Base, Base);
Set_Size_Info (Base, Standard_Integer);
Set_RM_Size (Base, RM_Size (Standard_Integer));
Set_Small_Value (Base, Ureal_1);
Set_Delta_Value (Base, Ureal_1);
Set_Scalar_Range (Base, Scalar_Range (T));
Set_Parent (Base, Parent (Def));
Check_Restriction (No_Fixed_Point, Def);
end Analyze_Formal_Ordinary_Fixed_Point_Type;
procedure Analyze_Formal_Package (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Pack_Id : constant Entity_Id := Defining_Identifier (N);
Formal : Entity_Id;
Gen_Id : constant Node_Id := Name (N);
Gen_Decl : Node_Id;
Gen_Unit : Entity_Id;
New_N : Node_Id;
Parent_Installed : Boolean := False;
Renaming : Node_Id;
Parent_Instance : Entity_Id;
Renaming_In_Par : Entity_Id;
begin
Text_IO_Kludge (Gen_Id);
Init_Env;
Check_Generic_Child_Unit (Gen_Id, Parent_Installed);
Gen_Unit := Entity (Gen_Id);
if Present (Renamed_Object (Gen_Unit)) then
Gen_Unit := Renamed_Object (Gen_Unit);
end if;
if Ekind (Gen_Unit) /= E_Generic_Package then
Error_Msg_N ("expect generic package name", Gen_Id);
Restore_Env;
return;
elsif Gen_Unit = Current_Scope then
Error_Msg_N
("generic package cannot be used as a formal package of itself",
Gen_Id);
Restore_Env;
return;
elsif In_Open_Scopes (Gen_Unit) then
if Is_Compilation_Unit (Gen_Unit)
and then Is_Child_Unit (Current_Scope)
then
Error_Msg_N
("generic parent cannot be used as formal package "
& "of a child unit",
Gen_Id);
else
Error_Msg_N
("generic package cannot be used as a formal package "
& "within itself",
Gen_Id);
Restore_Env;
return;
end if;
end if;
if not Box_Present (N) then
Hidden_Entities := New_Elmt_List;
Analyze_Package_Instantiation (N);
if Parent_Installed then
Remove_Parent;
end if;
else
Gen_Decl := Unit_Declaration_Node (Gen_Unit);
if In_Extended_Main_Source_Unit (N) then
Set_Is_Instantiated (Gen_Unit);
Generate_Reference (Gen_Unit, N);
end if;
Formal := New_Copy (Pack_Id);
Create_Instantiation_Source (N, Gen_Unit, False, S_Adjustment);
New_N :=
Copy_Generic_Node
(Original_Node (Gen_Decl), Empty, Instantiating => True);
Rewrite (N, New_N);
Set_Defining_Unit_Name (Specification (New_N), Formal);
Set_Generic_Parent (Specification (N), Gen_Unit);
Set_Instance_Env (Gen_Unit, Formal);
Enter_Name (Formal);
Set_Ekind (Formal, E_Generic_Package);
Set_Etype (Formal, Standard_Void_Type);
Set_Inner_Instances (Formal, New_Elmt_List);
New_Scope (Formal);
Renaming := Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Gen_Unit)),
Name => New_Reference_To (Formal, Loc));
if Present (Visible_Declarations (Specification (N))) then
Prepend (Renaming, To => Visible_Declarations (Specification (N)));
elsif Present (Private_Declarations (Specification (N))) then
Prepend (Renaming, To => Private_Declarations (Specification (N)));
end if;
if Is_Child_Unit (Gen_Unit)
and then Parent_Installed
then
Parent_Instance := Scope_Stack.Table (Scope_Stack.Last - 1).Entity;
Renaming_In_Par :=
Make_Defining_Identifier (Loc, Chars (Gen_Unit));
Set_Ekind (Renaming_In_Par, E_Package);
Set_Etype (Renaming_In_Par, Standard_Void_Type);
Set_Scope (Renaming_In_Par, Parent_Instance);
Set_Parent (Renaming_In_Par, Parent (Formal));
Set_Renamed_Object (Renaming_In_Par, Formal);
Append_Entity (Renaming_In_Par, Parent_Instance);
end if;
Analyze_Generic_Formal_Part (N);
Analyze (Specification (N));
End_Package_Scope (Formal);
if Parent_Installed then
Remove_Parent;
end if;
Restore_Env;
Set_Ekind (Formal, E_Package);
Set_Has_Completion (Formal, True);
Set_Ekind (Pack_Id, E_Package);
Set_Etype (Pack_Id, Standard_Void_Type);
Set_Scope (Pack_Id, Scope (Formal));
Set_Has_Completion (Pack_Id, True);
end if;
end Analyze_Formal_Package;
procedure Analyze_Formal_Private_Type
(N : Node_Id;
T : Entity_Id;
Def : Node_Id)
is
begin
New_Private_Type (N, T, Def);
Set_Size_Info (T, Standard_Integer);
Set_RM_Size (T, RM_Size (Standard_Integer));
end Analyze_Formal_Private_Type;
procedure Analyze_Formal_Signed_Integer_Type
(T : Entity_Id;
Def : Node_Id)
is
Base : constant Entity_Id :=
New_Internal_Entity
(E_Signed_Integer_Type, Current_Scope, Sloc (Def), 'G');
begin
Enter_Name (T);
Set_Ekind (T, E_Signed_Integer_Subtype);
Set_Etype (T, Base);
Set_Size_Info (T, Standard_Integer);
Set_RM_Size (T, RM_Size (Standard_Integer));
Set_Scalar_Range (T, Scalar_Range (Standard_Integer));
Set_Is_Constrained (T);
Set_Is_Generic_Type (Base);
Set_Size_Info (Base, Standard_Integer);
Set_RM_Size (Base, RM_Size (Standard_Integer));
Set_Etype (Base, Base);
Set_Scalar_Range (Base, Scalar_Range (Standard_Integer));
Set_Parent (Base, Parent (Def));
end Analyze_Formal_Signed_Integer_Type;
procedure Analyze_Formal_Subprogram (N : Node_Id) is
Spec : constant Node_Id := Specification (N);
Def : constant Node_Id := Default_Name (N);
Nam : constant Entity_Id := Defining_Unit_Name (Spec);
Subp : Entity_Id;
begin
if Nam = Error then
return;
end if;
if Nkind (Nam) = N_Defining_Program_Unit_Name then
Error_Msg_N ("name of formal subprogram must be a direct name", Nam);
return;
end if;
Analyze_Subprogram_Declaration (N);
Set_Is_Formal_Subprogram (Nam);
Set_Has_Completion (Nam);
if Nkind (N) = N_Formal_Abstract_Subprogram_Declaration then
Set_Is_Abstract (Nam);
Set_Is_Dispatching_Operation (Nam);
declare
Ctrl_Type : constant Entity_Id := Find_Dispatching_Type (Nam);
begin
if No (Ctrl_Type) then
Error_Msg_N
("abstract formal subprogram must have a controlling type",
N);
else
Check_Controlling_Formals (Ctrl_Type, Nam);
end if;
end;
end if;
if Box_Present (N) then
null;
elsif Present (Def) then
if Nkind (Def) = N_Operator_Symbol then
Find_Direct_Name (Def);
elsif Nkind (Def) /= N_Attribute_Reference then
Analyze (Def);
else
Analyze (Prefix (Def));
Valid_Default_Attribute (Nam, Def);
return;
end if;
if Etype (Def) = Any_Type then
return;
elsif Nkind (Def) = N_Selected_Component then
Subp := Entity (Selector_Name (Def));
if Ekind (Subp) /= E_Entry then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
end if;
elsif Nkind (Def) = N_Indexed_Component then
if Nkind (Prefix (Def)) /= N_Selected_Component then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
else
Subp := Entity (Selector_Name (Prefix (Def)));
if Ekind (Subp) /= E_Entry_Family then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
end if;
end if;
elsif Nkind (Def) = N_Character_Literal then
Resolve (Def, (Etype (Nam)));
elsif not Is_Entity_Name (Def)
or else not Is_Overloadable (Entity (Def))
then
Error_Msg_N ("expect valid subprogram name as default", Def);
return;
elsif not Is_Overloaded (Def) then
Subp := Entity (Def);
if Subp = Nam then
Error_Msg_N ("premature usage of formal subprogram", Def);
elsif not Entity_Matches_Spec (Subp, Nam) then
Error_Msg_N ("no visible entity matches specification", Def);
end if;
else
declare
I : Interp_Index;
I1 : Interp_Index := 0;
It : Interp;
It1 : Interp;
begin
Subp := Any_Id;
Get_First_Interp (Def, I, It);
while Present (It.Nam) loop
if Entity_Matches_Spec (It.Nam, Nam) then
if Subp /= Any_Id then
It1 := Disambiguate (Def, I1, I, Etype (Subp));
if It1 = No_Interp then
Error_Msg_N ("ambiguous default subprogram", Def);
else
Subp := It1.Nam;
end if;
exit;
else
I1 := I;
Subp := It.Nam;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
end;
if Subp /= Any_Id then
Set_Entity (Def, Subp);
if Subp = Nam then
Error_Msg_N ("premature usage of formal subprogram", Def);
elsif Ekind (Subp) /= E_Operator then
Check_Mode_Conformant (Subp, Nam);
end if;
else
Error_Msg_N ("no visible subprogram matches specification", N);
end if;
end if;
end if;
end Analyze_Formal_Subprogram;
procedure Analyze_Formal_Type_Declaration (N : Node_Id) is
Def : constant Node_Id := Formal_Type_Definition (N);
T : Entity_Id;
begin
T := Defining_Identifier (N);
if Present (Discriminant_Specifications (N))
and then Nkind (Def) /= N_Formal_Private_Type_Definition
then
Error_Msg_N
("discriminants not allowed for this formal type",
Defining_Identifier (First (Discriminant_Specifications (N))));
end if;
case Nkind (Def) is
when N_Formal_Private_Type_Definition =>
Analyze_Formal_Private_Type (N, T, Def);
when N_Formal_Derived_Type_Definition =>
Analyze_Formal_Derived_Type (N, T, Def);
when N_Formal_Discrete_Type_Definition =>
Analyze_Formal_Discrete_Type (T, Def);
when N_Formal_Signed_Integer_Type_Definition =>
Analyze_Formal_Signed_Integer_Type (T, Def);
when N_Formal_Modular_Type_Definition =>
Analyze_Formal_Modular_Type (T, Def);
when N_Formal_Floating_Point_Definition =>
Analyze_Formal_Floating_Type (T, Def);
when N_Formal_Ordinary_Fixed_Point_Definition =>
Analyze_Formal_Ordinary_Fixed_Point_Type (T, Def);
when N_Formal_Decimal_Fixed_Point_Definition =>
Analyze_Formal_Decimal_Fixed_Point_Type (T, Def);
when N_Array_Type_Definition =>
Analyze_Formal_Array_Type (T, Def);
when N_Access_To_Object_Definition |
N_Access_Function_Definition |
N_Access_Procedure_Definition =>
Analyze_Generic_Access_Type (T, Def);
when N_Record_Definition =>
Analyze_Formal_Interface_Type (T, Def);
when N_Derived_Type_Definition =>
Analyze_Formal_Derived_Interface_Type (T, Def);
when N_Error =>
null;
when others =>
raise Program_Error;
end case;
Set_Is_Generic_Type (T);
end Analyze_Formal_Type_Declaration;
procedure Analyze_Function_Instantiation (N : Node_Id) is
begin
Analyze_Subprogram_Instantiation (N, E_Function);
end Analyze_Function_Instantiation;
procedure Analyze_Generic_Access_Type (T : Entity_Id; Def : Node_Id) is
begin
Enter_Name (T);
if Nkind (Def) = N_Access_To_Object_Definition then
Access_Type_Declaration (T, Def);
if Is_Incomplete_Or_Private_Type (Designated_Type (T))
and then No (Full_View (Designated_Type (T)))
and then not Is_Generic_Type (Designated_Type (T))
then
Error_Msg_N ("premature usage of incomplete type", Def);
elsif Is_Internal (Designated_Type (T)) then
Error_Msg_N
("only a subtype mark is allowed in a formal", Def);
end if;
else
Access_Subprogram_Declaration (T, Def);
end if;
end Analyze_Generic_Access_Type;
procedure Analyze_Generic_Formal_Part (N : Node_Id) is
Gen_Parm_Decl : Node_Id;
begin
Gen_Parm_Decl := First (Generic_Formal_Declarations (N));
while Present (Gen_Parm_Decl) loop
Analyze (Gen_Parm_Decl);
Next (Gen_Parm_Decl);
end loop;
Generate_Reference_To_Generic_Formals (Current_Scope);
end Analyze_Generic_Formal_Part;
procedure Analyze_Generic_Package_Declaration (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Id : Entity_Id;
New_N : Node_Id;
Save_Parent : Node_Id;
Renaming : Node_Id;
Decls : constant List_Id :=
Visible_Declarations (Specification (N));
Decl : Node_Id;
begin
Renaming :=
Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Defining_Entity (N)), "GH")),
Name => Make_Identifier (Loc, Chars (Defining_Entity (N))));
if Present (Decls) then
Decl := First (Decls);
while Present (Decl)
and then Nkind (Decl) = N_Pragma
loop
Next (Decl);
end loop;
if Present (Decl) then
Insert_Before (Decl, Renaming);
else
Append (Renaming, Visible_Declarations (Specification (N)));
end if;
else
Set_Visible_Declarations (Specification (N), New_List (Renaming));
end if;
Save_Parent := Parent_Spec (N);
Set_Parent_Spec (N, Empty);
New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
Set_Parent_Spec (New_N, Save_Parent);
Rewrite (N, New_N);
Id := Defining_Entity (N);
Generate_Definition (Id);
Start_Generic;
Enter_Name (Id);
Set_Ekind (Id, E_Generic_Package);
Set_Etype (Id, Standard_Void_Type);
New_Scope (Id);
Enter_Generic_Scope (Id);
Set_Inner_Instances (Id, New_Elmt_List);
Set_Categorization_From_Pragmas (N);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
Set_Generic_Homonym (Id, Defining_Unit_Name (Renaming));
Set_Entity (Associated_Node (Name (Renaming)), Id);
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Cunit_Entity (Current_Sem_Unit, Id);
end if;
Analyze_Generic_Formal_Part (N);
Analyze (Specification (N));
Validate_Categorization_Dependency (N, Id);
End_Generic;
End_Package_Scope (Id);
Exit_Generic_Scope (Id);
if Nkind (Parent (N)) /= N_Compilation_Unit then
Move_Freeze_Nodes (Id, N, Visible_Declarations (Specification (N)));
Move_Freeze_Nodes (Id, N, Private_Declarations (Specification (N)));
Move_Freeze_Nodes (Id, N, Generic_Formal_Declarations (N));
else
Set_Body_Required (Parent (N), Unit_Requires_Body (Id));
Validate_RT_RAT_Component (N);
if not Body_Required (Parent (N)) then
Check_References (Id);
end if;
end if;
end Analyze_Generic_Package_Declaration;
procedure Analyze_Generic_Subprogram_Declaration (N : Node_Id) is
Spec : Node_Id;
Id : Entity_Id;
Formals : List_Id;
New_N : Node_Id;
Result_Type : Entity_Id;
Save_Parent : Node_Id;
begin
Save_Parent := Parent_Spec (N);
Set_Parent_Spec (N, Empty);
New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
Set_Parent_Spec (New_N, Save_Parent);
Rewrite (N, New_N);
Spec := Specification (N);
Id := Defining_Entity (Spec);
Generate_Definition (Id);
if Nkind (Id) = N_Defining_Operator_Symbol then
Error_Msg_N
("operator symbol not allowed for generic subprogram", Id);
end if;
Start_Generic;
Enter_Name (Id);
Set_Scope_Depth_Value (Id, Scope_Depth (Current_Scope) + 1);
New_Scope (Id);
Enter_Generic_Scope (Id);
Set_Inner_Instances (Id, New_Elmt_List);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
Analyze_Generic_Formal_Part (N);
Formals := Parameter_Specifications (Spec);
if Present (Formals) then
Process_Formals (Formals, Spec);
end if;
if Nkind (Spec) = N_Function_Specification then
Set_Ekind (Id, E_Generic_Function);
if Nkind (Result_Definition (Spec)) = N_Access_Definition then
Result_Type := Access_Definition (Spec, Result_Definition (Spec));
Set_Etype (Id, Result_Type);
else
Find_Type (Result_Definition (Spec));
Set_Etype (Id, Entity (Result_Definition (Spec)));
end if;
else
Set_Ekind (Id, E_Generic_Procedure);
Set_Etype (Id, Standard_Void_Type);
end if;
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Cunit_Entity (Current_Sem_Unit, Id);
Set_Body_Required (Parent (N), Unit_Requires_Body (Id));
end if;
Set_Categorization_From_Pragmas (N);
Validate_Categorization_Dependency (N, Id);
Save_Global_References (Original_Node (N));
End_Generic;
End_Scope;
Exit_Generic_Scope (Id);
Generate_Reference_To_Formals (Id);
end Analyze_Generic_Subprogram_Declaration;
procedure Analyze_Package_Instantiation (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Gen_Id : constant Node_Id := Name (N);
Act_Decl : Node_Id;
Act_Decl_Name : Node_Id;
Act_Decl_Id : Entity_Id;
Act_Spec : Node_Id;
Act_Tree : Node_Id;
Gen_Decl : Node_Id;
Gen_Unit : Entity_Id;
Is_Actual_Pack : constant Boolean :=
Is_Internal (Defining_Entity (N));
Env_Installed : Boolean := False;
Parent_Installed : Boolean := False;
Renaming_List : List_Id;
Unit_Renaming : Node_Id;
Needs_Body : Boolean;
Inline_Now : Boolean := False;
procedure Delay_Descriptors (E : Entity_Id);
function Might_Inline_Subp return Boolean;
procedure Delay_Descriptors (E : Entity_Id) is
begin
if not Delay_Subprogram_Descriptors (E) then
Set_Delay_Subprogram_Descriptors (E);
Pending_Descriptor.Increment_Last;
Pending_Descriptor.Table (Pending_Descriptor.Last) := E;
end if;
end Delay_Descriptors;
function Might_Inline_Subp return Boolean is
E : Entity_Id;
begin
if not Inline_Processing_Required then
return False;
else
E := First_Entity (Gen_Unit);
while Present (E) loop
if Is_Subprogram (E)
and then Is_Inlined (E)
then
return True;
end if;
Next_Entity (E);
end loop;
end if;
return False;
end Might_Inline_Subp;
begin
Text_IO_Kludge (Name (N));
Instantiation_Node := N;
if Nkind (N) = N_Package_Instantiation then
Act_Decl_Id := New_Copy (Defining_Entity (N));
Set_Comes_From_Source (Act_Decl_Id, True);
if Nkind (Defining_Unit_Name (N)) = N_Defining_Program_Unit_Name then
Act_Decl_Name :=
Make_Defining_Program_Unit_Name (Loc,
Name => New_Copy_Tree (Name (Defining_Unit_Name (N))),
Defining_Identifier => Act_Decl_Id);
else
Act_Decl_Name := Act_Decl_Id;
end if;
else
Act_Decl_Id := Defining_Identifier (N);
Act_Decl_Name := Act_Decl_Id;
end if;
Generate_Definition (Act_Decl_Id);
Pre_Analyze_Actuals (N);
Init_Env;
Env_Installed := True;
Check_Generic_Child_Unit (Gen_Id, Parent_Installed);
Gen_Unit := Entity (Gen_Id);
if Etype (Gen_Unit) = Any_Type then
Restore_Env;
return;
elsif Ekind (Gen_Unit) /= E_Generic_Package then
if From_With_Type (Gen_Unit) then
Error_Msg_N
("cannot instantiate a limited withed package", Gen_Id);
else
Error_Msg_N
("expect name of generic package in instantiation", Gen_Id);
end if;
Restore_Env;
return;
end if;
if In_Extended_Main_Source_Unit (N) then
Set_Is_Instantiated (Gen_Unit);
Generate_Reference (Gen_Unit, N);
if Present (Renamed_Object (Gen_Unit)) then
Set_Is_Instantiated (Renamed_Object (Gen_Unit));
Generate_Reference (Renamed_Object (Gen_Unit), N);
end if;
end if;
if Nkind (Gen_Id) = N_Identifier
and then Chars (Gen_Unit) = Chars (Defining_Entity (N))
then
Error_Msg_NE
("& is hidden within declaration of instance", Gen_Id, Gen_Unit);
elsif Nkind (Gen_Id) = N_Expanded_Name
and then Is_Child_Unit (Gen_Unit)
and then Nkind (Prefix (Gen_Id)) = N_Identifier
and then Chars (Act_Decl_Id) = Chars (Prefix (Gen_Id))
then
Error_Msg_N
("& is hidden within declaration of instance ", Prefix (Gen_Id));
end if;
Set_Entity (Gen_Id, Gen_Unit);
if Present (Renamed_Object (Gen_Unit))
and then Ekind (Renamed_Object (Gen_Unit)) = E_Generic_Package
then
Gen_Unit := Renamed_Object (Gen_Unit);
end if;
if In_Open_Scopes (Gen_Unit) then
Error_Msg_NE ("instantiation of & within itself", N, Gen_Unit);
Restore_Env;
return;
elsif Contains_Instance_Of (Gen_Unit, Current_Scope, Gen_Id) then
Error_Msg_Node_2 := Current_Scope;
Error_Msg_NE
("circular Instantiation: & instantiated in &!", N, Gen_Unit);
Circularity_Detected := True;
Restore_Env;
return;
else
Set_Instance_Env (Gen_Unit, Act_Decl_Id);
Gen_Decl := Unit_Declaration_Node (Gen_Unit);
Generic_Renamings.Set_Last (0);
Generic_Renamings_HTable.Reset;
Create_Instantiation_Source (N, Gen_Unit, False, S_Adjustment);
Act_Tree :=
Copy_Generic_Node
(Original_Node (Gen_Decl), Empty, Instantiating => True);
Act_Spec := Specification (Act_Tree);
if Is_Actual_Pack then
Set_Visible_Declarations (Act_Spec, New_List);
Set_Private_Declarations (Act_Spec, New_List);
end if;
Renaming_List :=
Analyze_Associations
(N,
Generic_Formal_Declarations (Act_Tree),
Generic_Formal_Declarations (Gen_Decl));
Set_Defining_Unit_Name (Act_Spec, Act_Decl_Name);
Set_Is_Generic_Instance (Act_Decl_Id);
Set_Generic_Parent (Act_Spec, Gen_Unit);
Unit_Renaming :=
Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Gen_Unit)),
Name => New_Reference_To (Act_Decl_Id, Loc));
Append (Unit_Renaming, Renaming_List);
if Is_Non_Empty_List (Visible_Declarations (Act_Spec)) then
Insert_List_Before
(First (Visible_Declarations (Act_Spec)), Renaming_List);
else
Set_Visible_Declarations (Act_Spec, Renaming_List);
end if;
Act_Decl :=
Make_Package_Declaration (Loc,
Specification => Act_Spec);
declare
Enclosing_Body_Present : Boolean := False;
Scop : Entity_Id;
begin
if Scope (Gen_Unit) /= Standard_Standard
and then not Is_Child_Unit (Gen_Unit)
then
Scop := Scope (Gen_Unit);
while Present (Scop)
and then Scop /= Standard_Standard
loop
if Unit_Requires_Body (Scop) then
Enclosing_Body_Present := True;
exit;
elsif In_Open_Scopes (Scop)
and then In_Package_Body (Scop)
then
Enclosing_Body_Present := True;
exit;
end if;
exit when Is_Compilation_Unit (Scop);
Scop := Scope (Scop);
end loop;
end if;
if Expander_Active
and then (not Is_Child_Unit (Gen_Unit)
or else not Is_Generic_Unit (Scope (Gen_Unit)))
and then Might_Inline_Subp
and then not Is_Actual_Pack
then
if Front_End_Inlining
and then (Is_In_Main_Unit (N)
or else In_Main_Context (Current_Scope))
and then Nkind (Parent (N)) /= N_Compilation_Unit
then
Inline_Now := True;
elsif Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Gen_Decl)))
and then Configurable_Run_Time_Mode
and then Nkind (Parent (N)) /= N_Compilation_Unit
then
Inline_Now := True;
end if;
if Is_Generic_Instance (Current_Scope) then
declare
Curr_Unit : constant Entity_Id :=
Cunit_Entity (Current_Sem_Unit);
begin
if Curr_Unit /= Current_Scope
and then Is_Child_Unit (Curr_Unit)
then
Inline_Now := False;
end if;
end;
end if;
end if;
Needs_Body :=
(Unit_Requires_Body (Gen_Unit)
or else Enclosing_Body_Present
or else Present (Corresponding_Body (Gen_Decl)))
and then (Is_In_Main_Unit (N)
or else Might_Inline_Subp)
and then not Is_Actual_Pack
and then not Inline_Now
and then (Operating_Mode = Generate_Code
or else (Operating_Mode = Check_Semantics
and then ASIS_Mode));
if (Front_End_Inlining
and then not Expander_Active)
or else Is_Generic_Unit (Cunit_Entity (Main_Unit))
then
Needs_Body := False;
end if;
if In_Open_Scopes (Scope (Scope (Gen_Unit))) then
declare
Decl : constant Node_Id :=
Original_Node
(Unit_Declaration_Node (Scope (Gen_Unit)));
begin
if Nkind (Decl) = N_Formal_Package_Declaration
or else (Nkind (Decl) = N_Package_Declaration
and then Is_List_Member (Decl)
and then Present (Next (Decl))
and then
Nkind (Next (Decl)) = N_Formal_Package_Declaration)
then
Needs_Body := False;
end if;
end;
end if;
end;
if Distribution_Stub_Mode = Generate_Caller_Stub_Body
and then Is_Compilation_Unit (Defining_Entity (N))
then
Needs_Body := False;
end if;
if Needs_Body then
if Pending_Instantiations.Last >
Hostparm.Max_Instantiations
then
Error_Msg_N ("too many instantiations", N);
raise Unrecoverable_Error;
end if;
Check_Forward_Instantiation (Gen_Decl);
if Nkind (N) = N_Package_Instantiation then
declare
Enclosing_Master : Entity_Id := Current_Scope;
begin
while Enclosing_Master /= Standard_Standard loop
if Ekind (Enclosing_Master) = E_Package then
if Is_Compilation_Unit (Enclosing_Master) then
if In_Package_Body (Enclosing_Master) then
Delay_Descriptors
(Body_Entity (Enclosing_Master));
else
Delay_Descriptors
(Enclosing_Master);
end if;
exit;
else
Enclosing_Master := Scope (Enclosing_Master);
end if;
elsif Ekind (Enclosing_Master) = E_Generic_Package then
Enclosing_Master := Scope (Enclosing_Master);
elsif Is_Generic_Subprogram (Enclosing_Master)
or else Ekind (Enclosing_Master) = E_Void
then
exit;
else
if Ekind (Enclosing_Master) = E_Entry
and then
Ekind (Scope (Enclosing_Master)) = E_Protected_Type
then
Enclosing_Master :=
Protected_Body_Subprogram (Enclosing_Master);
end if;
Set_Delay_Cleanups (Enclosing_Master);
while Ekind (Enclosing_Master) = E_Block loop
Enclosing_Master := Scope (Enclosing_Master);
end loop;
if Is_Subprogram (Enclosing_Master) then
Delay_Descriptors (Enclosing_Master);
elsif Is_Task_Type (Enclosing_Master) then
declare
TBP : constant Node_Id :=
Get_Task_Body_Procedure
(Enclosing_Master);
begin
if Present (TBP) then
Delay_Descriptors (TBP);
Set_Delay_Cleanups (TBP);
end if;
end;
end if;
exit;
end if;
end loop;
end;
Pending_Instantiations.Increment_Last;
Pending_Instantiations.Table (Pending_Instantiations.Last) :=
(N, Act_Decl, Expander_Active, Current_Sem_Unit);
end if;
end if;
Set_Categorization_From_Pragmas (Act_Decl);
if Parent_Installed then
Hide_Current_Scope;
end if;
Set_Instance_Spec (N, Act_Decl);
if Nkind (Parent (N)) /= N_Compilation_Unit then
Mark_Rewrite_Insertion (Act_Decl);
Insert_Before (N, Act_Decl);
Analyze (Act_Decl);
else
if Cunit_Entity (Current_Sem_Unit) = Defining_Entity (N) then
Set_Cunit_Entity (Current_Sem_Unit, Act_Decl_Id);
if Current_Sem_Unit = Main_Unit then
Main_Unit_Entity := Act_Decl_Id;
end if;
end if;
Set_Unit (Parent (N), Act_Decl);
Set_Parent_Spec (Act_Decl, Parent_Spec (N));
Set_Package_Instantiation (Act_Decl_Id, N);
Analyze (Act_Decl);
Set_Unit (Parent (N), N);
Set_Body_Required (Parent (N), False);
Set_Suppress_Elaboration_Warnings (Act_Decl_Id);
Set_Kill_Elaboration_Checks (Act_Decl_Id);
end if;
Check_Elab_Instantiation (N);
if ABE_Is_Certain (N) and then Needs_Body then
Pending_Instantiations.Decrement_Last;
end if;
Check_Hidden_Child_Unit (N, Gen_Unit, Act_Decl_Id);
Set_First_Private_Entity (Defining_Unit_Name (Unit_Renaming),
First_Private_Entity (Act_Decl_Id));
if Nkind (Parent (N)) = N_Compilation_Unit
and then not Needs_Body
then
Rewrite (N, Act_Decl);
end if;
if Present (Corresponding_Body (Gen_Decl))
or else Unit_Requires_Body (Gen_Unit)
then
Set_Has_Completion (Act_Decl_Id);
end if;
Check_Formal_Packages (Act_Decl_Id);
Restore_Private_Views (Act_Decl_Id);
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Decl, N);
end if;
if Parent_Installed then
Remove_Parent;
end if;
Restore_Env;
Env_Installed := False;
end if;
Validate_Categorization_Dependency (N, Act_Decl_Id);
if Ekind (Act_Decl_Id) /= E_Void
and then not Is_Library_Level_Entity (Act_Decl_Id)
then
Check_Restriction (No_Local_Allocators, N);
end if;
if Inline_Now then
Inline_Instance_Body (N, Gen_Unit, Act_Decl);
end if;
if Nkind (N) = N_Formal_Package_Declaration then
Act_Decl_Id := New_Copy (Defining_Entity (N));
Set_Comes_From_Source (Act_Decl_Id, True);
Set_Is_Generic_Instance (Act_Decl_Id, False);
Set_Defining_Identifier (N, Act_Decl_Id);
end if;
exception
when Instantiation_Error =>
if Parent_Installed then
Remove_Parent;
end if;
if Env_Installed then
Restore_Env;
end if;
end Analyze_Package_Instantiation;
procedure Inline_Instance_Body
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl : Node_Id)
is
Vis : Boolean;
Gen_Comp : constant Entity_Id :=
Cunit_Entity (Get_Source_Unit (Gen_Unit));
Curr_Comp : constant Node_Id := Cunit (Current_Sem_Unit);
Curr_Scope : Entity_Id := Empty;
Curr_Unit : constant Entity_Id :=
Cunit_Entity (Current_Sem_Unit);
Removed : Boolean := False;
Num_Scopes : Int := 0;
Scope_Stack_Depth : constant Int :=
Scope_Stack.Last - Scope_Stack.First + 1;
Use_Clauses : array (1 .. Scope_Stack_Depth) of Node_Id;
Instances : array (1 .. Scope_Stack_Depth) of Entity_Id;
Inner_Scopes : array (1 .. Scope_Stack_Depth) of Entity_Id;
Num_Inner : Int := 0;
N_Instances : Int := 0;
S : Entity_Id;
begin
if Gen_Comp /= Cunit_Entity (Current_Sem_Unit) then
S := Current_Scope;
while Present (S) and then S /= Standard_Standard loop
loop
Num_Scopes := Num_Scopes + 1;
Use_Clauses (Num_Scopes) :=
(Scope_Stack.Table
(Scope_Stack.Last - Num_Scopes + 1).
First_Use_Clause);
End_Use_Clauses (Use_Clauses (Num_Scopes));
exit when Scope_Stack.Last - Num_Scopes + 1 = Scope_Stack.First
or else Scope_Stack.Table
(Scope_Stack.Last - Num_Scopes).Entity
= Scope (S);
end loop;
exit when Is_Generic_Instance (S)
and then (In_Package_Body (S)
or else Ekind (S) = E_Procedure
or else Ekind (S) = E_Function);
S := Scope (S);
end loop;
Vis := Is_Immediately_Visible (Gen_Comp);
S := Current_Scope;
while Present (S)
and then S /= Standard_Standard
loop
if Is_Generic_Instance (S) then
N_Instances := N_Instances + 1;
Instances (N_Instances) := S;
exit when In_Package_Body (S);
end if;
S := Scope (S);
end loop;
S := Current_Scope;
while Present (S)
and then S /= Standard_Standard
loop
exit when Is_Generic_Instance (S)
and then (In_Package_Body (S)
or else Ekind (S) = E_Procedure
or else Ekind (S) = E_Function);
if S = Curr_Unit
or else (Ekind (Curr_Unit) = E_Package_Body
and then S = Spec_Entity (Curr_Unit))
or else (Ekind (Curr_Unit) = E_Subprogram_Body
and then S =
Corresponding_Spec
(Unit_Declaration_Node (Curr_Unit)))
then
Removed := True;
Save_Scope_Stack (Handle_Use => False);
if Is_Child_Unit (S) then
while Current_Scope /= S loop
Num_Inner := Num_Inner + 1;
Inner_Scopes (Num_Inner) := Current_Scope;
Pop_Scope;
end loop;
Pop_Scope;
Remove_Context (Curr_Comp);
Curr_Scope := S;
else
Remove_Context (Curr_Comp);
end if;
if Ekind (Curr_Unit) = E_Package_Body then
Remove_Context (Library_Unit (Curr_Comp));
end if;
end if;
S := Scope (S);
end loop;
pragma Assert (Num_Inner < Num_Scopes);
New_Scope (Standard_Standard);
Scope_Stack.Table (Scope_Stack.Last).Is_Active_Stack_Base := True;
Instantiate_Package_Body
((N, Act_Decl, Expander_Active, Current_Sem_Unit), True);
Pop_Scope;
Set_Is_Immediately_Visible (Gen_Comp, Vis);
for J in 1 .. N_Instances loop
Set_Is_Generic_Instance (Instances (J), False);
end loop;
if Removed then
Install_Context (Curr_Comp);
if Present (Curr_Scope)
and then Is_Child_Unit (Curr_Scope)
then
New_Scope (Curr_Scope);
Set_Is_Immediately_Visible (Curr_Scope);
for J in reverse 1 .. Num_Inner loop
New_Scope (Inner_Scopes (J));
end loop;
end if;
Restore_Scope_Stack (Handle_Use => False);
if Present (Curr_Scope)
and then
(In_Private_Part (Curr_Scope)
or else In_Package_Body (Curr_Scope))
then
declare
Par : Entity_Id;
begin
Par := Scope (Curr_Scope);
while (Present (Par))
and then Par /= Standard_Standard
loop
Install_Private_Declarations (Par);
Par := Scope (Par);
end loop;
end;
end if;
end if;
if Is_Child_Unit (Curr_Unit)
and then Removed
then
for J in reverse 1 .. Num_Inner + 1 loop
Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause :=
Use_Clauses (J);
Install_Use_Clauses (Use_Clauses (J));
end loop;
else
for J in reverse 1 .. Num_Scopes loop
Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause :=
Use_Clauses (J);
Install_Use_Clauses (Use_Clauses (J));
end loop;
end if;
for J in 1 .. N_Instances loop
Set_Is_Generic_Instance (Instances (J), True);
end loop;
else
Instantiate_Package_Body
((N, Act_Decl, Expander_Active, Current_Sem_Unit), True);
end if;
end Inline_Instance_Body;
procedure Analyze_Procedure_Instantiation (N : Node_Id) is
begin
Analyze_Subprogram_Instantiation (N, E_Procedure);
end Analyze_Procedure_Instantiation;
procedure Analyze_Subprogram_Instantiation
(N : Node_Id;
K : Entity_Kind)
is
Loc : constant Source_Ptr := Sloc (N);
Gen_Id : constant Node_Id := Name (N);
Anon_Id : constant Entity_Id :=
Make_Defining_Identifier (Sloc (Defining_Entity (N)),
Chars => New_External_Name
(Chars (Defining_Entity (N)), 'R'));
Act_Decl_Id : Entity_Id;
Act_Decl : Node_Id;
Act_Spec : Node_Id;
Act_Tree : Node_Id;
Env_Installed : Boolean := False;
Gen_Unit : Entity_Id;
Gen_Decl : Node_Id;
Pack_Id : Entity_Id;
Parent_Installed : Boolean := False;
Renaming_List : List_Id;
procedure Analyze_Instance_And_Renamings;
procedure Analyze_Instance_And_Renamings is
Def_Ent : constant Entity_Id := Defining_Entity (N);
Pack_Decl : Node_Id;
begin
if Nkind (Parent (N)) = N_Compilation_Unit then
Pack_Id := New_Copy (Def_Ent);
else
Pack_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name
(Related_Id => Chars (Def_Ent),
Suffix => "GP",
Suffix_Index => Source_Offset (Sloc (Def_Ent))));
end if;
Pack_Decl := Make_Package_Declaration (Loc,
Specification => Make_Package_Specification (Loc,
Defining_Unit_Name => Pack_Id,
Visible_Declarations => Renaming_List,
End_Label => Empty));
Set_Instance_Spec (N, Pack_Decl);
Set_Is_Generic_Instance (Pack_Id);
Set_Needs_Debug_Info (Pack_Id);
if Nkind (Parent (N)) /= N_Compilation_Unit then
Mark_Rewrite_Insertion (Pack_Decl);
Insert_Before (N, Pack_Decl);
Set_Has_Completion (Pack_Id);
else
Set_Unit (Parent (N), Pack_Decl);
Set_Parent_Spec (Pack_Decl, Parent_Spec (N));
end if;
Analyze (Pack_Decl);
Check_Formal_Packages (Pack_Id);
Set_Is_Generic_Instance (Pack_Id, False);
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Name_Entity_Id (Chars (Pack_Id), Homonym (Pack_Id));
Set_Chars (Anon_Id, Chars (Defining_Entity (N)));
Set_Scope (Anon_Id, Scope (Pack_Id));
Set_Referenced (Pack_Id);
end if;
Set_Is_Generic_Instance (Anon_Id);
Set_Needs_Debug_Info (Anon_Id);
Act_Decl_Id := New_Copy (Anon_Id);
Set_Parent (Act_Decl_Id, Parent (Anon_Id));
Set_Chars (Act_Decl_Id, Chars (Defining_Entity (N)));
Set_Sloc (Act_Decl_Id, Sloc (Defining_Entity (N)));
Set_Comes_From_Source (Act_Decl_Id, True);
Set_Has_Delayed_Freeze (Anon_Id, False);
Set_Is_Child_Unit (Act_Decl_Id, Is_Child_Unit (Defining_Entity (N)));
Set_Is_Child_Unit (Anon_Id, Is_Child_Unit (Defining_Entity (N)));
New_Overloaded_Entity (Act_Decl_Id);
Check_Eliminated (Act_Decl_Id);
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Suppress_Elaboration_Warnings (Act_Decl_Id);
Set_Kill_Elaboration_Checks (Act_Decl_Id);
Set_Is_Compilation_Unit (Anon_Id);
Set_Cunit_Entity (Current_Sem_Unit, Pack_Id);
end if;
Set_Is_Frozen (Act_Decl_Id, False);
if Nkind (Defining_Entity (N)) = N_Defining_Operator_Symbol then
Valid_Operator_Definition (Act_Decl_Id);
end if;
Set_Alias (Act_Decl_Id, Anon_Id);
Set_Parent (Act_Decl_Id, Parent (Anon_Id));
Set_Has_Completion (Act_Decl_Id);
Set_Related_Instance (Pack_Id, Act_Decl_Id);
if Nkind (Parent (N)) = N_Compilation_Unit then
Set_Body_Required (Parent (N), False);
end if;
end Analyze_Instance_And_Renamings;
begin
Text_IO_Kludge (Gen_Id);
Instantiation_Node := N;
Pre_Analyze_Actuals (N);
Init_Env;
Env_Installed := True;
Check_Generic_Child_Unit (Gen_Id, Parent_Installed);
Gen_Unit := Entity (Gen_Id);
Generate_Reference (Gen_Unit, Gen_Id);
if Nkind (Gen_Id) = N_Identifier
and then Chars (Gen_Unit) = Chars (Defining_Entity (N))
then
Error_Msg_NE
("& is hidden within declaration of instance", Gen_Id, Gen_Unit);
end if;
if Etype (Gen_Unit) = Any_Type then
Restore_Env;
return;
end if;
if Ekind (Gen_Unit) /= E_Generic_Procedure
and then Ekind (Gen_Unit) /= E_Generic_Function
then
Error_Msg_N ("expect generic subprogram in instantiation", Gen_Id);
elsif In_Open_Scopes (Gen_Unit) then
Error_Msg_NE ("instantiation of & within itself", N, Gen_Unit);
elsif K = E_Procedure
and then Ekind (Gen_Unit) /= E_Generic_Procedure
then
if Ekind (Gen_Unit) = E_Generic_Function then
Error_Msg_N
("cannot instantiate generic function as procedure", Gen_Id);
else
Error_Msg_N
("expect name of generic procedure in instantiation", Gen_Id);
end if;
elsif K = E_Function
and then Ekind (Gen_Unit) /= E_Generic_Function
then
if Ekind (Gen_Unit) = E_Generic_Procedure then
Error_Msg_N
("cannot instantiate generic procedure as function", Gen_Id);
else
Error_Msg_N
("expect name of generic function in instantiation", Gen_Id);
end if;
else
Set_Entity (Gen_Id, Gen_Unit);
Set_Is_Instantiated (Gen_Unit);
if In_Extended_Main_Source_Unit (N) then
Generate_Reference (Gen_Unit, N);
end if;
if Present (Renamed_Object (Gen_Unit))
and then (Ekind (Renamed_Object (Gen_Unit)) = E_Generic_Procedure
or else
Ekind (Renamed_Object (Gen_Unit)) = E_Generic_Function)
then
Gen_Unit := Renamed_Object (Gen_Unit);
Set_Is_Instantiated (Gen_Unit);
Generate_Reference (Gen_Unit, N);
end if;
if Contains_Instance_Of (Gen_Unit, Current_Scope, Gen_Id) then
Error_Msg_Node_2 := Current_Scope;
Error_Msg_NE
("circular Instantiation: & instantiated in &!", N, Gen_Unit);
Circularity_Detected := True;
return;
end if;
Gen_Decl := Unit_Declaration_Node (Gen_Unit);
Set_Instance_Env (Gen_Unit, Empty);
Generic_Renamings.Set_Last (0);
Generic_Renamings_HTable.Reset;
Create_Instantiation_Source (N, Gen_Unit, False, S_Adjustment);
Act_Tree :=
Copy_Generic_Node
(Original_Node (Gen_Decl), Empty, Instantiating => True);
Act_Spec := Specification (Act_Tree);
Renaming_List :=
Analyze_Associations
(N,
Generic_Formal_Declarations (Act_Tree),
Generic_Formal_Declarations (Gen_Decl));
Set_Defining_Unit_Name (Act_Spec, Anon_Id);
Set_Generic_Parent (Act_Spec, Gen_Unit);
Act_Decl :=
Make_Subprogram_Declaration (Sloc (Act_Spec),
Specification => Act_Spec);
Set_Categorization_From_Pragmas (Act_Decl);
if Parent_Installed then
Hide_Current_Scope;
end if;
Append (Act_Decl, Renaming_List);
Analyze_Instance_And_Renamings;
if Is_Intrinsic_Subprogram (Gen_Unit) then
Set_Is_Intrinsic_Subprogram (Anon_Id);
Set_Is_Intrinsic_Subprogram (Act_Decl_Id);
if Chars (Gen_Unit) = Name_Unchecked_Conversion then
Validate_Unchecked_Conversion (N, Act_Decl_Id);
end if;
end if;
Generate_Definition (Act_Decl_Id);
Set_Is_Inlined (Act_Decl_Id, Is_Inlined (Gen_Unit));
Set_Is_Inlined (Anon_Id, Is_Inlined (Gen_Unit));
if not Is_Intrinsic_Subprogram (Gen_Unit) then
Check_Elab_Instantiation (N);
end if;
if Is_Dispatching_Operation (Act_Decl_Id)
and then Ada_Version >= Ada_05
then
declare
Formal : Entity_Id;
begin
Formal := First_Formal (Act_Decl_Id);
while Present (Formal) loop
if Ekind (Etype (Formal)) = E_Anonymous_Access_Type
and then Is_Controlling_Formal (Formal)
and then not Can_Never_Be_Null (Formal)
then
Error_Msg_NE ("access parameter& is controlling,",
N, Formal);
Error_Msg_NE ("\corresponding parameter of & must be"
& " explicitly null-excluding", N, Gen_Id);
end if;
Next_Formal (Formal);
end loop;
end;
end if;
Check_Hidden_Child_Unit (N, Gen_Unit, Act_Decl_Id);
Validate_Categorization_Dependency (N, Act_Decl_Id);
if not Is_Intrinsic_Subprogram (Act_Decl_Id) then
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Decl, N);
end if;
Restore_Private_Views (Pack_Id, False);
if (Is_In_Main_Unit (N)
or else Is_Inlined (Act_Decl_Id))
and then (Operating_Mode = Generate_Code
or else (Operating_Mode = Check_Semantics
and then ASIS_Mode))
and then (Expander_Active or else ASIS_Mode)
and then not ABE_Is_Certain (N)
and then not Is_Eliminated (Act_Decl_Id)
then
Pending_Instantiations.Increment_Last;
Pending_Instantiations.Table (Pending_Instantiations.Last) :=
(N, Act_Decl, Expander_Active, Current_Sem_Unit);
Check_Forward_Instantiation (Gen_Decl);
elsif Nkind (Parent (N)) = N_Compilation_Unit then
Rewrite (N, Unit (Parent (N)));
Set_Unit (Parent (N), N);
end if;
elsif Nkind (Parent (N)) = N_Compilation_Unit then
Rewrite (N, Unit (Parent (N)));
Set_Unit (Parent (N), N);
end if;
if Parent_Installed then
Remove_Parent;
end if;
Restore_Env;
Env_Installed := False;
Generic_Renamings.Set_Last (0);
Generic_Renamings_HTable.Reset;
end if;
exception
when Instantiation_Error =>
if Parent_Installed then
Remove_Parent;
end if;
if Env_Installed then
Restore_Env;
end if;
end Analyze_Subprogram_Instantiation;
function Get_Associated_Node (N : Node_Id) return Node_Id is
Assoc : Node_Id := Associated_Node (N);
begin
if Nkind (Assoc) /= Nkind (N) then
return Assoc;
elsif Nkind (Assoc) = N_Aggregate
or else Nkind (Assoc) = N_Extension_Aggregate
then
return Assoc;
else
while Present (Associated_Node (Assoc))
and then Nkind (Associated_Node (Assoc)) = Nkind (Assoc)
loop
Assoc := Associated_Node (Assoc);
end loop;
if (Nkind (Assoc) = N_Identifier or else Nkind (Assoc) in N_Op)
and then Present (Associated_Node (Assoc))
and then (Nkind (Associated_Node (Assoc)) = N_Function_Call
or else
Nkind (Associated_Node (Assoc)) = N_Explicit_Dereference
or else
Nkind (Associated_Node (Assoc)) = N_Integer_Literal
or else
Nkind (Associated_Node (Assoc)) = N_Real_Literal
or else
Nkind (Associated_Node (Assoc)) = N_String_Literal)
then
Assoc := Associated_Node (Assoc);
end if;
return Assoc;
end if;
end Get_Associated_Node;
procedure Build_Instance_Compilation_Unit_Nodes
(N : Node_Id;
Act_Body : Node_Id;
Act_Decl : Node_Id)
is
Decl_Cunit : Node_Id;
Body_Cunit : Node_Id;
Citem : Node_Id;
New_Main : constant Entity_Id := Defining_Entity (Act_Decl);
Old_Main : constant Entity_Id := Cunit_Entity (Main_Unit);
begin
Decl_Cunit :=
Make_Compilation_Unit (Sloc (N),
Context_Items => Empty_List,
Unit => Act_Decl,
Aux_Decls_Node =>
Make_Compilation_Unit_Aux (Sloc (N)));
Set_Parent_Spec (Act_Decl, Parent_Spec (N));
Set_Body_Required (Decl_Cunit, True);
Rewrite (N, Act_Body);
Body_Cunit := Parent (N);
Set_Library_Unit (Decl_Cunit, Body_Cunit);
Set_Library_Unit (Body_Cunit, Decl_Cunit);
Set_Private_Present (Decl_Cunit, Private_Present (Body_Cunit));
if Parent (N) /= Cunit (Main_Unit) then
return;
end if;
Citem := First (Context_Items (Body_Cunit));
while Present (Citem) loop
Append (New_Copy (Citem), Context_Items (Decl_Cunit));
Next (Citem);
end loop;
if Ekind (New_Main) = E_Package then
Set_Is_Pure (Old_Main, Is_Pure (New_Main));
Set_Is_Preelaborated (Old_Main, Is_Preelaborated (New_Main));
Set_Is_Remote_Types (Old_Main, Is_Remote_Types (New_Main));
Set_Is_Shared_Passive (Old_Main, Is_Shared_Passive (New_Main));
Set_Is_Remote_Call_Interface
(Old_Main, Is_Remote_Call_Interface (New_Main));
end if;
Make_Instance_Unit (Body_Cunit);
Main_Unit_Entity := New_Main;
Set_Cunit_Entity (Main_Unit, Main_Unit_Entity);
Build_Elaboration_Entity (Decl_Cunit, New_Main);
end Build_Instance_Compilation_Unit_Nodes;
procedure Check_Formal_Package_Instance
(Formal_Pack : Entity_Id;
Actual_Pack : Entity_Id)
is
E1 : Entity_Id := First_Entity (Actual_Pack);
E2 : Entity_Id := First_Entity (Formal_Pack);
Expr1 : Node_Id;
Expr2 : Node_Id;
procedure Check_Mismatch (B : Boolean);
function Same_Instantiated_Constant (E1, E2 : Entity_Id) return Boolean;
function Same_Instantiated_Variable (E1, E2 : Entity_Id) return Boolean;
procedure Check_Mismatch (B : Boolean) is
begin
if B then
Error_Msg_NE
("actual for & in actual instance does not match formal",
Parent (Actual_Pack), E1);
end if;
end Check_Mismatch;
function Same_Instantiated_Constant
(E1, E2 : Entity_Id) return Boolean
is
Ent : Entity_Id;
begin
Ent := E2;
while Present (Ent) loop
if E1 = Ent then
return True;
elsif Ekind (Ent) /= E_Constant then
return False;
elsif Is_Entity_Name (Constant_Value (Ent)) then
if Entity (Constant_Value (Ent)) = E1 then
return True;
else
Ent := Entity (Constant_Value (Ent));
end if;
elsif Is_Entity_Name (Original_Node (Constant_Value (Ent))) then
Ent := Entity (Original_Node (Constant_Value (Ent)));
else
return False;
end if;
end loop;
return False;
end Same_Instantiated_Constant;
function Same_Instantiated_Variable
(E1, E2 : Entity_Id) return Boolean
is
function Original_Entity (E : Entity_Id) return Entity_Id;
function Original_Entity (E : Entity_Id) return Entity_Id is
Orig : Entity_Id;
begin
Orig := E;
while Nkind (Parent (Orig)) = N_Object_Renaming_Declaration
and then Present (Renamed_Object (Orig))
and then Is_Entity_Name (Renamed_Object (Orig))
loop
Orig := Entity (Renamed_Object (Orig));
end loop;
return Orig;
end Original_Entity;
begin
return Ekind (E1) = Ekind (E2)
and then Original_Entity (E1) = Original_Entity (E2);
end Same_Instantiated_Variable;
begin
while Present (E1)
and then Present (E2)
loop
exit when Ekind (E1) = E_Package
and then Renamed_Entity (E1) = Renamed_Entity (Actual_Pack);
if Is_Type (E1) then
if not Is_Itype (E1)
and then not Is_Itype (E2)
then
Check_Mismatch
(not Is_Type (E2)
or else Etype (E1) /= Etype (E2)
or else not Subtypes_Statically_Match (E1, E2));
end if;
elsif Ekind (E1) = E_Constant then
Expr1 := Expression (Parent (E1));
if Ekind (E2) /= E_Constant then
Check_Mismatch (True);
goto Next_E;
else
Expr2 := Expression (Parent (E2));
end if;
if Is_Static_Expression (Expr1) then
if not Is_Static_Expression (Expr2) then
Check_Mismatch (True);
elsif Is_Integer_Type (Etype (E1)) then
declare
V1 : constant Uint := Expr_Value (Expr1);
V2 : constant Uint := Expr_Value (Expr2);
begin
Check_Mismatch (V1 /= V2);
end;
elsif Is_Real_Type (Etype (E1)) then
declare
V1 : constant Ureal := Expr_Value_R (Expr1);
V2 : constant Ureal := Expr_Value_R (Expr2);
begin
Check_Mismatch (V1 /= V2);
end;
elsif Is_String_Type (Etype (E1))
and then Nkind (Expr1) = N_String_Literal
then
if Nkind (Expr2) /= N_String_Literal then
Check_Mismatch (True);
else
Check_Mismatch
(not String_Equal (Strval (Expr1), Strval (Expr2)));
end if;
end if;
elsif Is_Entity_Name (Expr1) then
if Is_Entity_Name (Expr2) then
if Entity (Expr1) = Entity (Expr2) then
null;
else
Check_Mismatch
(not Same_Instantiated_Constant
(Entity (Expr1), Entity (Expr2)));
end if;
else
Check_Mismatch (True);
end if;
elsif Is_Entity_Name (Original_Node (Expr1))
and then Is_Entity_Name (Expr2)
and then
Same_Instantiated_Constant
(Entity (Original_Node (Expr1)), Entity (Expr2))
then
null;
elsif Nkind (Expr1) = N_Null then
Check_Mismatch (Nkind (Expr1) /= N_Null);
else
Check_Mismatch (True);
end if;
elsif Ekind (E1) = E_Variable then
Check_Mismatch (not Same_Instantiated_Variable (E1, E2));
elsif Ekind (E1) = E_Package then
Check_Mismatch
(Ekind (E1) /= Ekind (E2)
or else Renamed_Object (E1) /= Renamed_Object (E2));
elsif Is_Overloadable (E1) then
Check_Mismatch
(Ekind (E2) /= Ekind (E1) or else (Alias (E1)) /= Alias (E2));
else
raise Program_Error;
end if;
<<Next_E>>
Next_Entity (E1);
Next_Entity (E2);
end loop;
end Check_Formal_Package_Instance;
procedure Check_Formal_Packages (P_Id : Entity_Id) is
E : Entity_Id;
Formal_P : Entity_Id;
begin
E := First_Entity (P_Id);
while Present (E) loop
if Ekind (E) = E_Package then
if Renamed_Object (E) = P_Id then
exit;
elsif Nkind (Parent (E)) /= N_Package_Renaming_Declaration then
null;
elsif not Box_Present (Parent (Associated_Formal_Package (E))) then
Formal_P := Next_Entity (E);
Check_Formal_Package_Instance (Formal_P, E);
end if;
end if;
Next_Entity (E);
end loop;
end Check_Formal_Packages;
procedure Check_Forward_Instantiation (Decl : Node_Id) is
S : Entity_Id;
Gen_Comp : Entity_Id := Cunit_Entity (Get_Source_Unit (Decl));
begin
if Ekind (Gen_Comp) = E_Package_Body then
Gen_Comp := Spec_Entity (Gen_Comp);
end if;
if In_Open_Scopes (Gen_Comp)
and then No (Corresponding_Body (Decl))
then
S := Current_Scope;
while Present (S)
and then not Is_Compilation_Unit (S)
and then not Is_Child_Unit (S)
loop
if Ekind (S) = E_Package then
Set_Has_Forward_Instantiation (S);
end if;
S := Scope (S);
end loop;
end if;
end Check_Forward_Instantiation;
procedure Check_Generic_Actuals
(Instance : Entity_Id;
Is_Formal_Box : Boolean)
is
E : Entity_Id;
Astype : Entity_Id;
function Denotes_Previous_Actual (Typ : Entity_Id) return Boolean;
function Denotes_Previous_Actual (Typ : Entity_Id) return Boolean is
Prev : Entity_Id;
begin
Prev := First_Entity (Instance);
while Present (Prev) loop
if Is_Type (Prev)
and then Nkind (Parent (Prev)) = N_Subtype_Declaration
and then Is_Entity_Name (Subtype_Indication (Parent (Prev)))
and then Entity (Subtype_Indication (Parent (Prev))) = Typ
then
return True;
elsif Prev = E then
return False;
else
Next_Entity (Prev);
end if;
end loop;
return False;
end Denotes_Previous_Actual;
begin
E := First_Entity (Instance);
while Present (E) loop
if Is_Type (E)
and then Nkind (Parent (E)) = N_Subtype_Declaration
and then Scope (Etype (E)) /= Instance
and then Is_Entity_Name (Subtype_Indication (Parent (E)))
then
if Is_Array_Type (E)
and then Denotes_Previous_Actual (Component_Type (E))
then
null;
else
Check_Private_View (Subtype_Indication (Parent (E)));
end if;
Set_Is_Generic_Actual_Type (E, True);
Set_Is_Hidden (E, False);
Set_Is_Potentially_Use_Visible (E,
In_Use (Instance));
Astype := Ancestor_Subtype (E);
if No (Astype) then
Astype := Base_Type (E);
end if;
Set_Size_Info (E, (Astype));
Set_RM_Size (E, RM_Size (Astype));
Set_First_Rep_Item (E, First_Rep_Item (Astype));
if Is_Discrete_Or_Fixed_Point_Type (E) then
Set_RM_Size (E, RM_Size (Astype));
elsif Is_Access_Type (E)
and then Is_Private_Type (Etype (E))
then
Check_Private_View
(New_Occurrence_Of (Etype (E), Sloc (Instance)));
end if;
elsif Ekind (E) = E_Package then
if Renamed_Object (E) = Instance then
exit;
elsif Nkind (Parent (E)) /= N_Package_Renaming_Declaration then
null;
elsif Denotes_Formal_Package (E) then
null;
elsif Present (Associated_Formal_Package (E)) then
if Box_Present (Parent (Associated_Formal_Package (E))) then
Check_Generic_Actuals (Renamed_Object (E), True);
end if;
Set_Is_Hidden (E, False);
end if;
elsif Is_Wrapper_Package (Instance) then
Set_Is_Hidden (E, False);
else
Set_Is_Hidden (E, not Is_Formal_Box);
end if;
Next_Entity (E);
end loop;
end Check_Generic_Actuals;
procedure Check_Generic_Child_Unit
(Gen_Id : Node_Id;
Parent_Installed : in out Boolean)
is
Loc : constant Source_Ptr := Sloc (Gen_Id);
Gen_Par : Entity_Id := Empty;
Inst_Par : Entity_Id;
E : Entity_Id;
S : Node_Id;
function Find_Generic_Child
(Scop : Entity_Id;
Id : Node_Id) return Entity_Id;
function In_Enclosing_Instance return Boolean;
function Find_Generic_Child
(Scop : Entity_Id;
Id : Node_Id) return Entity_Id
is
E : Entity_Id;
begin
if Present (Entity (Id)) then
if Scope (Entity (Id)) = Scop then
return Entity (Id);
else
return Empty;
end if;
else
E := First_Entity (Scop);
while Present (E) loop
if Chars (E) = Chars (Id)
and then Is_Child_Unit (E)
then
if Is_Child_Unit (E)
and then not Is_Visible_Child_Unit (E)
then
Error_Msg_NE
("generic child unit& is not visible", Gen_Id, E);
end if;
Set_Entity (Id, E);
return E;
end if;
Next_Entity (E);
end loop;
return Empty;
end if;
end Find_Generic_Child;
function In_Enclosing_Instance return Boolean is
Enclosing_Instance : Node_Id;
Instance_Decl : Node_Id;
begin
if In_Inlined_Body then
pragma Assert (Chars (Gen_Id) = Name_Unchecked_Conversion);
return False;
end if;
Enclosing_Instance := Current_Scope;
while Present (Enclosing_Instance) loop
Instance_Decl := Unit_Declaration_Node (Enclosing_Instance);
if Ekind (Enclosing_Instance) = E_Package
and then Is_Generic_Instance (Enclosing_Instance)
and then Present
(Generic_Parent (Specification (Instance_Decl)))
then
E := Find_Generic_Child
(Generic_Parent (Specification (Instance_Decl)), Gen_Id);
exit when Present (E);
else
E := Empty;
end if;
Enclosing_Instance := Scope (Enclosing_Instance);
end loop;
if No (E) then
Analyze (Gen_Id);
return False;
else
Rewrite (Gen_Id,
Make_Expanded_Name (Loc,
Chars => Chars (E),
Prefix => New_Occurrence_Of (Enclosing_Instance, Loc),
Selector_Name => New_Occurrence_Of (E, Loc)));
Set_Entity (Gen_Id, E);
Set_Etype (Gen_Id, Etype (E));
Parent_Installed := False; return True;
end if;
end In_Enclosing_Instance;
begin
if Nkind (Gen_Id) = N_Selected_Component then
S := Selector_Name (Gen_Id);
Analyze (Prefix (Gen_Id));
Inst_Par := Entity (Prefix (Gen_Id));
if Ekind (Inst_Par) = E_Package
and then Present (Renamed_Object (Inst_Par))
then
Inst_Par := Renamed_Object (Inst_Par);
end if;
if Ekind (Inst_Par) = E_Package then
if Nkind (Parent (Inst_Par)) = N_Package_Specification then
Gen_Par := Generic_Parent (Parent (Inst_Par));
elsif Nkind (Parent (Inst_Par)) = N_Defining_Program_Unit_Name
and then
Nkind (Parent (Parent (Inst_Par))) = N_Package_Specification
then
Gen_Par := Generic_Parent (Parent (Parent (Inst_Par)));
end if;
elsif Ekind (Inst_Par) = E_Generic_Package
and then Nkind (Parent (Gen_Id)) = N_Formal_Package_Declaration
then
Gen_Par := Inst_Par;
end if;
if Present (Gen_Par) then
E := Find_Generic_Child (Gen_Par, S);
if Present (E) then
Change_Selected_Component_To_Expanded_Name (Gen_Id);
Set_Entity (Gen_Id, E);
Set_Etype (Gen_Id, Etype (E));
Set_Entity (S, E);
Set_Etype (S, Etype (E));
if In_Extended_Main_Source_Unit (Gen_Id) then
Set_Is_Instantiated (Inst_Par);
end if;
if Is_Child_Unit (E)
and then not Comes_From_Source (Entity (Prefix (Gen_Id)))
and then (not In_Instance
or else Nkind (Parent (Parent (Gen_Id))) =
N_Compilation_Unit)
then
Error_Msg_N
("prefix of generic child unit must be instance of parent",
Gen_Id);
end if;
if not In_Open_Scopes (Inst_Par)
and then Nkind (Parent (Gen_Id)) not in
N_Generic_Renaming_Declaration
then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
else
Analyze (Gen_Id);
end if;
else
Analyze (Gen_Id);
if Is_Child_Unit (Entity (Gen_Id))
and then
Nkind (Parent (Gen_Id)) not in N_Generic_Renaming_Declaration
and then not In_Open_Scopes (Inst_Par)
then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
end if;
elsif Nkind (Gen_Id) = N_Expanded_Name then
Analyze (Prefix (Gen_Id));
Inst_Par := Entity (Prefix (Gen_Id));
if In_Enclosing_Instance then
null;
elsif Present (Entity (Gen_Id))
and then Is_Child_Unit (Entity (Gen_Id))
and then not In_Open_Scopes (Inst_Par)
then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
elsif In_Enclosing_Instance then
null;
else
Analyze (Gen_Id);
if Is_Entity_Name (Gen_Id) then
E := Entity (Gen_Id);
if Is_Generic_Unit (E)
and then Nkind (Parent (E)) in N_Generic_Renaming_Declaration
and then Is_Child_Unit (Renamed_Object (E))
and then Is_Generic_Unit (Scope (Renamed_Object (E)))
and then Nkind (Name (Parent (E))) = N_Expanded_Name
then
Rewrite (Gen_Id,
New_Copy_Tree (Name (Parent (E))));
Inst_Par := Entity (Prefix (Gen_Id));
if not In_Open_Scopes (Inst_Par) then
Install_Parent (Inst_Par);
Parent_Installed := True;
end if;
elsif Is_Generic_Unit (E)
and then Is_Child_Unit (E)
and then
Nkind (Parent (Gen_Id)) not in N_Generic_Renaming_Declaration
and then not Is_Generic_Unit (Scope (E))
then
if not In_Open_Scopes (Scope (E)) then
Install_Parent (Scope (E));
Parent_Installed := True;
end if;
end if;
end if;
end if;
end Check_Generic_Child_Unit;
procedure Check_Hidden_Child_Unit
(N : Node_Id;
Gen_Unit : Entity_Id;
Act_Decl_Id : Entity_Id)
is
Gen_Id : constant Node_Id := Name (N);
begin
if Is_Child_Unit (Gen_Unit)
and then Is_Child_Unit (Act_Decl_Id)
and then Nkind (Gen_Id) = N_Expanded_Name
and then Entity (Prefix (Gen_Id)) = Scope (Act_Decl_Id)
and then Chars (Gen_Unit) = Chars (Act_Decl_Id)
then
Error_Msg_Node_2 := Scope (Act_Decl_Id);
Error_Msg_NE
("generic unit & is implicitly declared in &",
Defining_Unit_Name (N), Gen_Unit);
Error_Msg_N ("\instance must have different name",
Defining_Unit_Name (N));
end if;
end Check_Hidden_Child_Unit;
procedure Check_Private_View (N : Node_Id) is
T : constant Entity_Id := Etype (N);
BT : Entity_Id;
begin
if Present (T) then
BT := Base_Type (T);
if Is_Private_Type (T)
and then not Has_Private_View (N)
and then Present (Full_View (T))
and then not In_Open_Scopes (Scope (T))
then
Switch_View (T);
elsif Has_Private_View (N)
and then not Is_Private_Type (T)
and then not Has_Been_Exchanged (T)
and then Etype (Get_Associated_Node (N)) /= T
then
if In_Open_Scopes (Scope (Base_Type (T)))
and then not Is_Private_Type (Base_Type (T))
and then Comes_From_Source (Base_Type (T))
then
null;
elsif Nkind (Parent (N)) = N_Subtype_Declaration
or else not In_Private_Part (Scope (Base_Type (T)))
then
Prepend_Elmt (T, Exchanged_Views);
Exchange_Declarations (Etype (Get_Associated_Node (N)));
end if;
elsif Is_Access_Type (T)
and then Is_Private_Type (Designated_Type (T))
and then not Has_Private_View (N)
and then Present (Full_View (Designated_Type (T)))
then
Switch_View (Designated_Type (T));
elsif Is_Array_Type (T)
and then Is_Private_Type (Component_Type (T))
and then not Has_Private_View (N)
and then Present (Full_View (Component_Type (T)))
then
Switch_View (Component_Type (T));
elsif Is_Private_Type (T)
and then Present (Full_View (T))
and then Is_Array_Type (Full_View (T))
and then Is_Private_Type (Component_Type (Full_View (T)))
then
Switch_View (T);
elsif not Is_Private_Type (T)
and then not Has_Private_View (N)
and then Is_Private_Type (Base_Type (T))
and then Present (Full_View (BT))
and then not Is_Generic_Type (BT)
and then not In_Open_Scopes (BT)
then
Prepend_Elmt (Full_View (BT), Exchanged_Views);
Exchange_Declarations (BT);
end if;
end if;
end Check_Private_View;
function Contains_Instance_Of
(Inner : Entity_Id;
Outer : Entity_Id;
N : Node_Id) return Boolean
is
Elmt : Elmt_Id;
Scop : Entity_Id;
begin
Scop := Outer;
loop
if Ekind (Scop) = E_Generic_Package
or else (Is_Subprogram (Scop)
and then Nkind (Unit_Declaration_Node (Scop)) =
N_Generic_Subprogram_Declaration)
then
Elmt := First_Elmt (Inner_Instances (Inner));
while Present (Elmt) loop
if Node (Elmt) = Scop then
Error_Msg_Node_2 := Inner;
Error_Msg_NE
("circular Instantiation: & instantiated within &!",
N, Scop);
return True;
elsif Node (Elmt) = Inner then
return True;
elsif Contains_Instance_Of (Node (Elmt), Scop, N) then
Error_Msg_Node_2 := Inner;
Error_Msg_NE
("circular Instantiation: & instantiated within &!",
N, Node (Elmt));
return True;
end if;
Next_Elmt (Elmt);
end loop;
Append_Elmt (Inner, Inner_Instances (Scop));
end if;
if Scop = Standard_Standard then
exit;
else
Scop := Scope (Scop);
end if;
end loop;
return False;
end Contains_Instance_Of;
function Copy_Generic_Node
(N : Node_Id;
Parent_Id : Node_Id;
Instantiating : Boolean) return Node_Id
is
Ent : Entity_Id;
New_N : Node_Id;
function Copy_Generic_Descendant (D : Union_Id) return Union_Id;
procedure Copy_Descendants;
function Copy_Generic_Elist (E : Elist_Id) return Elist_Id;
function Copy_Generic_List
(L : List_Id;
Parent_Id : Node_Id) return List_Id;
function In_Defining_Unit_Name (Nam : Node_Id) return Boolean;
procedure Copy_Descendants is
use Atree.Unchecked_Access;
begin
Set_Field1 (New_N, Copy_Generic_Descendant (Field1 (N)));
Set_Field2 (New_N, Copy_Generic_Descendant (Field2 (N)));
Set_Field3 (New_N, Copy_Generic_Descendant (Field3 (N)));
Set_Field4 (New_N, Copy_Generic_Descendant (Field4 (N)));
Set_Field5 (New_N, Copy_Generic_Descendant (Field5 (N)));
end Copy_Descendants;
function Copy_Generic_Descendant (D : Union_Id) return Union_Id is
begin
if D = Union_Id (Empty) then
return D;
elsif D in Node_Range then
return Union_Id
(Copy_Generic_Node (Node_Id (D), New_N, Instantiating));
elsif D in List_Range then
return Union_Id (Copy_Generic_List (List_Id (D), New_N));
elsif D in Elist_Range then
return Union_Id (Copy_Generic_Elist (Elist_Id (D)));
else
return D;
end if;
end Copy_Generic_Descendant;
function Copy_Generic_Elist (E : Elist_Id) return Elist_Id is
M : Elmt_Id;
L : Elist_Id;
begin
if Present (E) then
L := New_Elmt_List;
M := First_Elmt (E);
while Present (M) loop
Append_Elmt
(Copy_Generic_Node (Node (M), Empty, Instantiating), L);
Next_Elmt (M);
end loop;
return L;
else
return No_Elist;
end if;
end Copy_Generic_Elist;
function Copy_Generic_List
(L : List_Id;
Parent_Id : Node_Id) return List_Id
is
N : Node_Id;
New_L : List_Id;
begin
if Present (L) then
New_L := New_List;
Set_Parent (New_L, Parent_Id);
N := First (L);
while Present (N) loop
Append (Copy_Generic_Node (N, Empty, Instantiating), New_L);
Next (N);
end loop;
return New_L;
else
return No_List;
end if;
end Copy_Generic_List;
function In_Defining_Unit_Name (Nam : Node_Id) return Boolean is
begin
return Present (Parent (Nam))
and then (Nkind (Parent (Nam)) = N_Defining_Program_Unit_Name
or else
(Nkind (Parent (Nam)) = N_Expanded_Name
and then In_Defining_Unit_Name (Parent (Nam))));
end In_Defining_Unit_Name;
begin
if N = Empty then
return N;
end if;
New_N := New_Copy (N);
if Instantiating then
Adjust_Instantiation_Sloc (New_N, S_Adjustment);
end if;
if not Is_List_Member (N) then
Set_Parent (New_N, Parent_Id);
end if;
if Nkind (New_N) in N_Entity then
null;
elsif Nkind (New_N) = N_Identifier
or else Nkind (New_N) = N_Character_Literal
or else Nkind (New_N) = N_Expanded_Name
or else Nkind (New_N) = N_Operator_Symbol
or else Nkind (New_N) in N_Op
then
if not Instantiating then
Set_Associated_Node (N, New_N);
Ent := Entity (New_N);
if No (Current_Instantiated_Parent.Gen_Id) then
if No (Ent)
or else Nkind (Ent) /= N_Defining_Identifier
or else not In_Defining_Unit_Name (N)
then
Set_Associated_Node (New_N, Empty);
end if;
elsif No (Ent)
or else
not (Nkind (Ent) = N_Defining_Identifier
or else
Nkind (Ent) = N_Defining_Character_Literal
or else
Nkind (Ent) = N_Defining_Operator_Symbol)
or else No (Scope (Ent))
or else Scope (Ent) = Current_Instantiated_Parent.Gen_Id
or else (Scope_Depth (Scope (Ent)) >
Scope_Depth (Current_Instantiated_Parent.Gen_Id)
and then
Get_Source_Unit (Ent) =
Get_Source_Unit (Current_Instantiated_Parent.Gen_Id))
then
Set_Associated_Node (New_N, Empty);
end if;
else
declare
Assoc : constant Node_Id := Get_Associated_Node (N);
begin
if Present (Assoc) then
if Nkind (Assoc) = Nkind (N) then
Set_Entity (New_N, Entity (Assoc));
Check_Private_View (N);
elsif Nkind (Assoc) = N_Function_Call then
Set_Entity (New_N, Entity (Name (Assoc)));
elsif (Nkind (Assoc) = N_Defining_Identifier
or else Nkind (Assoc) = N_Defining_Character_Literal
or else Nkind (Assoc) = N_Defining_Operator_Symbol)
and then Expander_Active
then
null;
else
Set_Entity (New_N, Empty);
end if;
end if;
end;
end if;
if Nkind (N) = N_Expanded_Name then
Set_Prefix
(New_N, Copy_Generic_Node (Prefix (N), New_N, Instantiating));
Set_Selector_Name (New_N,
Copy_Generic_Node (Selector_Name (N), New_N, Instantiating));
elsif Nkind (N) in N_Op then
Set_Right_Opnd (New_N,
Copy_Generic_Node (Right_Opnd (N), New_N, Instantiating));
if Nkind (N) in N_Binary_Op then
Set_Left_Opnd (New_N,
Copy_Generic_Node (Left_Opnd (N), New_N, Instantiating));
end if;
end if;
elsif Nkind (N) in N_Body_Stub then
if Nkind (N) = N_Subprogram_Body_Stub then
Set_Specification (New_N,
Copy_Generic_Node (Specification (N), New_N, Instantiating));
else
Set_Defining_Identifier (New_N,
Copy_Generic_Node
(Defining_Identifier (N), New_N, Instantiating));
end if;
if not Instantiating then
declare
Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
Subunit : Node_Id;
Unum : Unit_Number_Type;
New_Body : Node_Id;
begin
Unum :=
Load_Unit
(Load_Name => Subunit_Name,
Required => False,
Subunit => True,
Error_Node => N);
if Unum = No_Unit then
Subunits_Missing := True;
goto Subunit_Not_Found;
end if;
Subunit := Cunit (Unum);
if Nkind (Unit (Subunit)) /= N_Subunit then
Error_Msg_Sloc := Sloc (N);
Error_Msg_N
("expected SEPARATE subunit to complete stub at#,"
& " found child unit", Subunit);
goto Subunit_Not_Found;
end if;
New_Body :=
Copy_Generic_Node
(Proper_Body (Unit (Subunit)),
Empty, Instantiating => False);
Rewrite (N, Proper_Body (Unit (Subunit)));
Set_Is_Compilation_Unit (Defining_Entity (N), False);
Set_Was_Originally_Stub (N);
Set_Proper_Body (Unit (Subunit), New_Body);
Set_Library_Unit (New_N, Subunit);
Inherit_Context (Unit (Subunit), N);
end;
else
null;
end if;
<<Subunit_Not_Found>> null;
elsif Nkind (N) = N_Compilation_Unit then
pragma Assert (not Instantiating);
Set_Context_Items (New_N,
Copy_Generic_List (Context_Items (N), New_N));
Set_Unit (New_N,
Copy_Generic_Node (Unit (N), New_N, False));
Set_First_Inlined_Subprogram (New_N,
Copy_Generic_Node
(First_Inlined_Subprogram (N), New_N, False));
Set_Aux_Decls_Node (New_N,
Copy_Generic_Node (Aux_Decls_Node (N), New_N, False));
elsif Nkind (N) = N_Assignment_Statement then
Set_Name (New_N,
Copy_Generic_Node (Name (N), New_N, Instantiating));
Set_Expression (New_N,
Copy_Generic_Node (Expression (N), New_N, Instantiating));
if Instantiating then
Set_Assignment_OK (Name (New_N), True);
end if;
elsif Nkind (N) = N_Aggregate
or else Nkind (N) = N_Extension_Aggregate
then
if not Instantiating then
Set_Associated_Node (N, New_N);
else
if Present (Get_Associated_Node (N))
and then Nkind (Get_Associated_Node (N)) = Nkind (N)
then
declare
T : Entity_Id := (Etype (Get_Associated_Node (New_N)));
Rt : Entity_Id;
begin
if Present (T)
and then Is_Private_Type (T)
then
Switch_View (T);
end if;
if Present (T)
and then Is_Tagged_Type (T)
and then Is_Derived_Type (T)
then
Rt := Root_Type (T);
loop
T := Etype (T);
if Is_Private_Type (T) then
Switch_View (T);
end if;
exit when T = Rt;
end loop;
end if;
end;
end if;
end if;
declare
use Atree.Unchecked_Access;
begin
Set_Field1 (New_N, Copy_Generic_Descendant (Field1 (N)));
Set_Field2 (New_N, Copy_Generic_Descendant (Field2 (N)));
Set_Field3 (New_N, Copy_Generic_Descendant (Field3 (N)));
Set_Field5 (New_N, Copy_Generic_Descendant (Field5 (N)));
end;
elsif Nkind (N) = N_Allocator
and then Nkind (Expression (N)) = N_Qualified_Expression
and then Is_Entity_Name (Subtype_Mark (Expression (N)))
and then Instantiating
then
declare
T : constant Node_Id :=
Get_Associated_Node (Subtype_Mark (Expression (N)));
Acc_T : Entity_Id;
begin
if Present (T) then
Acc_T := Etype (Parent (Parent (T)));
if Present (Acc_T)
and then Is_Private_Type (Acc_T)
then
Switch_View (Acc_T);
end if;
end if;
Copy_Descendants;
end;
elsif Nkind (N) in N_Proper_Body then
declare
Save_Adjustment : constant Sloc_Adjustment := S_Adjustment;
begin
if Instantiating and then Was_Originally_Stub (N) then
Create_Instantiation_Source
(Instantiation_Node,
Defining_Entity (N),
False,
S_Adjustment);
end if;
Copy_Descendants;
S_Adjustment := Save_Adjustment;
end;
elsif Nkind (N) = N_Pragma
and then Instantiating
then
declare
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Chars (N));
begin
if Prag_Id = Pragma_Ident
or else Prag_Id = Pragma_Comment
then
New_N := Make_Null_Statement (Sloc (N));
else
Copy_Descendants;
end if;
end;
elsif Nkind (N) = N_Integer_Literal
or else Nkind (N) = N_Real_Literal
then
null;
else
Copy_Descendants;
if Instantiating
and then Nkind (N) = N_Subprogram_Body
then
Set_Generic_Parent (Specification (New_N), N);
end if;
end if;
return New_N;
end Copy_Generic_Node;
function Denotes_Formal_Package
(Pack : Entity_Id;
On_Exit : Boolean := False) return Boolean
is
Par : Entity_Id;
Scop : constant Entity_Id := Scope (Pack);
E : Entity_Id;
begin
if On_Exit then
Par :=
Instance_Envs.Table
(Instance_Envs.Last).Instantiated_Parent.Act_Id;
else
Par := Current_Instantiated_Parent.Act_Id;
end if;
if Ekind (Scop) = E_Generic_Package
or else Nkind (Unit_Declaration_Node (Scop)) =
N_Generic_Subprogram_Declaration
then
return True;
elsif Nkind (Parent (Pack)) = N_Formal_Package_Declaration then
return True;
elsif No (Par) then
return False;
else
E := First_Entity (Par);
while Present (E) loop
if Ekind (E) /= E_Package
or else Nkind (Parent (E)) /= N_Package_Renaming_Declaration
then
null;
elsif Renamed_Object (E) = Par then
return False;
elsif Renamed_Object (E) = Pack then
return True;
end if;
Next_Entity (E);
end loop;
return False;
end if;
end Denotes_Formal_Package;
procedure End_Generic is
begin
Inside_A_Generic := Generic_Flags.Table (Generic_Flags.Last);
Generic_Flags.Decrement_Last;
Expander_Mode_Restore;
end End_Generic;
function Find_Actual_Type
(Typ : Entity_Id;
Gen_Scope : Entity_Id) return Entity_Id
is
T : Entity_Id;
begin
if not Is_Child_Unit (Gen_Scope) then
return Get_Instance_Of (Typ);
elsif not Is_Generic_Type (Typ)
or else Scope (Typ) = Gen_Scope
then
return Get_Instance_Of (Typ);
else
T := Current_Entity (Typ);
while Present (T) loop
if In_Open_Scopes (Scope (T)) then
return T;
end if;
T := Homonym (T);
end loop;
return Typ;
end if;
end Find_Actual_Type;
procedure Freeze_Subprogram_Body
(Inst_Node : Node_Id;
Gen_Body : Node_Id;
Pack_Id : Entity_Id)
is
F_Node : Node_Id;
Gen_Unit : constant Entity_Id := Get_Generic_Entity (Inst_Node);
Par : constant Entity_Id := Scope (Gen_Unit);
Enc_G : Entity_Id;
Enc_I : Node_Id;
E_G_Id : Entity_Id;
function Earlier (N1, N2 : Node_Id) return Boolean;
function Enclosing_Body (N : Node_Id) return Node_Id;
function Package_Freeze_Node (B : Node_Id) return Node_Id;
function True_Parent (N : Node_Id) return Node_Id;
function Earlier (N1, N2 : Node_Id) return Boolean is
D1 : Integer := 0;
D2 : Integer := 0;
P1 : Node_Id := N1;
P2 : Node_Id := N2;
procedure Find_Depth (P : in out Node_Id; D : in out Integer);
procedure Find_Depth (P : in out Node_Id; D : in out Integer) is
begin
while Present (P)
and then Nkind (P) /= N_Compilation_Unit
loop
P := True_Parent (P);
D := D + 1;
end loop;
end Find_Depth;
begin
Find_Depth (P1, D1);
Find_Depth (P2, D2);
if P1 /= P2 then
return False;
else
P1 := N1;
P2 := N2;
end if;
while D1 > D2 loop
P1 := True_Parent (P1);
D1 := D1 - 1;
end loop;
while D2 > D1 loop
P2 := True_Parent (P2);
D2 := D2 - 1;
end loop;
while not Is_List_Member (P1)
or else not Is_List_Member (P2)
or else List_Containing (P1) /= List_Containing (P2)
loop
P1 := True_Parent (P1);
P2 := True_Parent (P2);
if Nkind (Parent (P1)) = N_Subunit then
P1 := Corresponding_Stub (Parent (P1));
end if;
if Nkind (Parent (P2)) = N_Subunit then
P2 := Corresponding_Stub (Parent (P2));
end if;
if P1 = P2 then
return False;
end if;
end loop;
return
Top_Level_Location (Sloc (P1)) < Top_Level_Location (Sloc (P2));
end Earlier;
function Enclosing_Body (N : Node_Id) return Node_Id is
P : Node_Id := Parent (N);
begin
while Present (P)
and then Nkind (Parent (P)) /= N_Compilation_Unit
loop
if Nkind (P) = N_Package_Body then
if Nkind (Parent (P)) = N_Subunit then
return Corresponding_Stub (Parent (P));
else
return P;
end if;
end if;
P := True_Parent (P);
end loop;
return Empty;
end Enclosing_Body;
function Package_Freeze_Node (B : Node_Id) return Node_Id is
Id : Entity_Id;
begin
if Nkind (B) = N_Package_Body then
Id := Corresponding_Spec (B);
else pragma Assert (Nkind (B) = N_Package_Body_Stub);
Id := Corresponding_Spec (Proper_Body (Unit (Library_Unit (B))));
end if;
Ensure_Freeze_Node (Id);
return Freeze_Node (Id);
end Package_Freeze_Node;
function True_Parent (N : Node_Id) return Node_Id is
begin
if Nkind (Parent (N)) = N_Subunit then
return Parent (Corresponding_Stub (Parent (N)));
else
return Parent (N);
end if;
end True_Parent;
begin
Enc_G := Enclosing_Body (Gen_Body);
Enc_I := Enclosing_Body (Inst_Node);
Ensure_Freeze_Node (Pack_Id);
F_Node := Freeze_Node (Pack_Id);
if Is_Generic_Instance (Par)
and then Present (Freeze_Node (Par))
and then
In_Same_Declarative_Part (Freeze_Node (Par), Inst_Node)
then
if ABE_Is_Certain (Get_Package_Instantiation_Node (Par)) then
Insert_After_Last_Decl (Inst_Node, F_Node);
else
Insert_After (Freeze_Node (Par), F_Node);
end if;
elsif Is_Generic_Instance (Par)
and then Present (Freeze_Node (Par))
and then Present (Enc_I)
then
if In_Same_Declarative_Part (Freeze_Node (Par), Enc_I)
or else
(Nkind (Enc_I) = N_Package_Body
and then
In_Same_Declarative_Part (Freeze_Node (Par), Parent (Enc_I)))
then
Insert_After_Last_Decl
(Freeze_Node (Par), Package_Freeze_Node (Enc_I));
end if;
Insert_After_Last_Decl (Inst_Node, F_Node);
elsif Present (Enc_G)
and then Present (Enc_I)
and then Enc_G /= Enc_I
and then Earlier (Inst_Node, Gen_Body)
then
if Nkind (Enc_G) = N_Package_Body then
E_G_Id := Corresponding_Spec (Enc_G);
else pragma Assert (Nkind (Enc_G) = N_Package_Body_Stub);
E_G_Id :=
Corresponding_Spec (Proper_Body (Unit (Library_Unit (Enc_G))));
end if;
Insert_After_Last_Decl (Enc_G, Package_Freeze_Node (Enc_I));
Ensure_Freeze_Node (E_G_Id);
if not Is_List_Member (Freeze_Node (E_G_Id)) then
Insert_After (Enc_G, Freeze_Node (E_G_Id));
end if;
Insert_After_Last_Decl (Inst_Node, F_Node);
else
Insert_After_Last_Decl (Inst_Node, F_Node);
end if;
end Freeze_Subprogram_Body;
function Get_Gen_Id (E : Assoc_Ptr) return Entity_Id is
begin
return Generic_Renamings.Table (E).Gen_Id;
end Get_Gen_Id;
function Get_Instance_Of (A : Entity_Id) return Entity_Id is
Res : constant Assoc_Ptr := Generic_Renamings_HTable.Get (A);
begin
if Res /= Assoc_Null then
return Generic_Renamings.Table (Res).Act_Id;
else
return A;
end if;
end Get_Instance_Of;
function Get_Package_Instantiation_Node (A : Entity_Id) return Node_Id is
Decl : Node_Id := Unit_Declaration_Node (A);
Inst : Node_Id;
begin
if Present (Package_Instantiation (A)) then
if Nkind (Package_Instantiation (A)) = N_Package_Instantiation then
return Package_Instantiation (A);
elsif Nkind (Original_Node (Package_Instantiation (A)))
= N_Package_Instantiation
then
return Original_Node (Package_Instantiation (A));
end if;
end if;
if Nkind (Parent (Decl)) = N_Compilation_Unit then
if Nkind (Decl) = N_Package_Declaration
and then Present (Corresponding_Body (Decl))
then
Decl := Unit_Declaration_Node (Corresponding_Body (Decl));
end if;
if Nkind (Original_Node (Decl)) = N_Package_Instantiation then
return Original_Node (Decl);
else
return Unit (Parent (Decl));
end if;
elsif Nkind (Decl) = N_Generic_Package_Declaration
and then Nkind (Original_Node (Decl)) = N_Formal_Package_Declaration
then
return Original_Node (Decl);
else
Inst := Next (Decl);
while Nkind (Inst) /= N_Package_Instantiation
and then Nkind (Inst) /= N_Formal_Package_Declaration
loop
Next (Inst);
end loop;
return Inst;
end if;
end Get_Package_Instantiation_Node;
function Has_Been_Exchanged (E : Entity_Id) return Boolean is
Next : Elmt_Id := First_Elmt (Exchanged_Views);
begin
while Present (Next) loop
if Full_View (Node (Next)) = E then
return True;
end if;
Next_Elmt (Next);
end loop;
return False;
end Has_Been_Exchanged;
function Hash (F : Entity_Id) return HTable_Range is
begin
return HTable_Range (F mod HTable_Size);
end Hash;
procedure Hide_Current_Scope is
C : constant Entity_Id := Current_Scope;
E : Entity_Id;
begin
Set_Is_Hidden_Open_Scope (C);
E := First_Entity (C);
while Present (E) loop
if Is_Immediately_Visible (E) then
Set_Is_Immediately_Visible (E, False);
Append_Elmt (E, Hidden_Entities);
end if;
Next_Entity (E);
end loop;
if Is_Immediately_Visible (C)
and then C /= Standard_Standard
then
Set_Is_Immediately_Visible (C, False);
Append_Elmt (C, Hidden_Entities);
end if;
end Hide_Current_Scope;
procedure Init_Env is
Saved : Instance_Env;
begin
Saved.Ada_Version := Ada_Version;
Saved.Ada_Version_Explicit := Ada_Version_Explicit;
Saved.Instantiated_Parent := Current_Instantiated_Parent;
Saved.Exchanged_Views := Exchanged_Views;
Saved.Hidden_Entities := Hidden_Entities;
Saved.Current_Sem_Unit := Current_Sem_Unit;
Saved.Parent_Unit_Visible := Parent_Unit_Visible;
Saved.Instance_Parent_Unit := Instance_Parent_Unit;
Instance_Envs.Increment_Last;
Instance_Envs.Table (Instance_Envs.Last) := Saved;
Exchanged_Views := New_Elmt_List;
Hidden_Entities := New_Elmt_List;
Current_Instantiated_Parent :=
(Current_Scope, Current_Scope, Assoc_Null);
end Init_Env;
function In_Same_Declarative_Part
(F_Node : Node_Id;
Inst : Node_Id) return Boolean
is
Decls : constant Node_Id := Parent (F_Node);
Nod : Node_Id := Parent (Inst);
begin
while Present (Nod) loop
if Nod = Decls then
return True;
elsif Nkind (Nod) = N_Subprogram_Body
or else Nkind (Nod) = N_Package_Body
or else Nkind (Nod) = N_Task_Body
or else Nkind (Nod) = N_Protected_Body
or else Nkind (Nod) = N_Block_Statement
then
return False;
elsif Nkind (Nod) = N_Subunit then
Nod := Corresponding_Stub (Nod);
elsif Nkind (Nod) = N_Compilation_Unit then
return False;
else
Nod := Parent (Nod);
end if;
end loop;
return False;
end In_Same_Declarative_Part;
function In_Main_Context (E : Entity_Id) return Boolean is
Context : List_Id;
Clause : Node_Id;
Nam : Node_Id;
begin
if not Is_Compilation_Unit (E)
or else Ekind (E) /= E_Package
or else In_Private_Part (E)
then
return False;
end if;
Context := Context_Items (Cunit (Main_Unit));
Clause := First (Context);
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause then
Nam := Name (Clause);
if (Nkind (Nam) = N_Identifier
and then Chars (Nam) = Chars (E))
or else (Nkind (Nam) = N_Selected_Component
and then Chars (Selector_Name (Nam)) = Chars (E))
then
return True;
end if;
end if;
Next (Clause);
end loop;
return False;
end In_Main_Context;
procedure Inherit_Context (Gen_Decl : Node_Id; Inst : Node_Id) is
Current_Context : List_Id;
Current_Unit : Node_Id;
Item : Node_Id;
New_I : Node_Id;
begin
if Nkind (Parent (Gen_Decl)) = N_Compilation_Unit then
Current_Unit := Parent (Inst);
while Present (Current_Unit)
and then Nkind (Current_Unit) /= N_Compilation_Unit
loop
Current_Unit := Parent (Current_Unit);
end loop;
Current_Context := Context_Items (Current_Unit);
Item := First (Context_Items (Parent (Gen_Decl)));
while Present (Item) loop
if Nkind (Item) = N_With_Clause then
New_I := New_Copy (Item);
Set_Implicit_With (New_I, True);
Append (New_I, Current_Context);
end if;
Next (Item);
end loop;
end if;
end Inherit_Context;
procedure Initialize is
begin
Generic_Renamings.Init;
Instance_Envs.Init;
Generic_Flags.Init;
Generic_Renamings_HTable.Reset;
Circularity_Detected := False;
Exchanged_Views := No_Elist;
Hidden_Entities := No_Elist;
end Initialize;
procedure Insert_After_Last_Decl (N : Node_Id; F_Node : Node_Id) is
L : List_Id := List_Containing (N);
P : constant Node_Id := Parent (L);
begin
if not Is_List_Member (F_Node) then
if Nkind (P) = N_Package_Specification
and then L = Visible_Declarations (P)
and then Present (Private_Declarations (P))
and then not Is_Empty_List (Private_Declarations (P))
then
L := Private_Declarations (P);
end if;
Insert_After (Last (L), F_Node);
end if;
end Insert_After_Last_Decl;
procedure Install_Body
(Act_Body : Node_Id;
N : Node_Id;
Gen_Body : Node_Id;
Gen_Decl : Node_Id)
is
Act_Id : constant Entity_Id := Corresponding_Spec (Act_Body);
Act_Unit : constant Node_Id := Unit (Cunit (Get_Source_Unit (N)));
Gen_Id : constant Entity_Id := Corresponding_Spec (Gen_Body);
Par : constant Entity_Id := Scope (Gen_Id);
Gen_Unit : constant Node_Id :=
Unit (Cunit (Get_Source_Unit (Gen_Decl)));
Orig_Body : Node_Id := Gen_Body;
F_Node : Node_Id;
Body_Unit : Node_Id;
Must_Delay : Boolean;
function Enclosing_Subp (Id : Entity_Id) return Entity_Id;
function True_Sloc (N : Node_Id) return Source_Ptr;
function Enclosing_Subp (Id : Entity_Id) return Entity_Id is
Scop : Entity_Id := Scope (Id);
begin
while Scop /= Standard_Standard
and then not Is_Overloadable (Scop)
loop
Scop := Scope (Scop);
end loop;
return Scop;
end Enclosing_Subp;
function True_Sloc (N : Node_Id) return Source_Ptr is
Res : Source_Ptr;
N1 : Node_Id;
begin
Res := Sloc (N);
N1 := N;
while Present (N1) and then N1 /= Act_Unit loop
if Sloc (N1) > Res then
Res := Sloc (N1);
end if;
N1 := Parent (N1);
end loop;
return Res;
end True_Sloc;
begin
if Nkind (Parent (Gen_Body)) = N_Subunit then
Orig_Body := Corresponding_Stub (Parent (Gen_Body));
else
Orig_Body := Gen_Body;
end if;
Body_Unit := Unit (Cunit (Get_Source_Unit (Orig_Body)));
Must_Delay :=
(Gen_Unit = Act_Unit
and then ((Nkind (Gen_Unit) = N_Package_Declaration)
or else Nkind (Gen_Unit) = N_Generic_Package_Declaration
or else (Gen_Unit = Body_Unit
and then True_Sloc (N) < Sloc (Orig_Body)))
and then Is_In_Main_Unit (Gen_Unit)
and then (Scope (Act_Id) = Scope (Gen_Id)
or else
Enclosing_Subp (Act_Id) = Enclosing_Subp (Gen_Id)));
if Expander_Active then
Ensure_Freeze_Node (Act_Id);
F_Node := Freeze_Node (Act_Id);
if Must_Delay then
Insert_After (Orig_Body, F_Node);
elsif Is_Generic_Instance (Par)
and then Present (Freeze_Node (Par))
and then Scope (Act_Id) /= Par
then
if In_Same_Declarative_Part (Freeze_Node (Par), N) then
Insert_After (Freeze_Node (Par), F_Node);
elsif Nkind (Parent (N)) = N_Package_Body
and then In_Same_Declarative_Part (Freeze_Node (Par), Parent (N))
then
declare
Enclosing : constant Entity_Id :=
Corresponding_Spec (Parent (N));
begin
Insert_After_Last_Decl (N, F_Node);
Ensure_Freeze_Node (Enclosing);
if not Is_List_Member (Freeze_Node (Enclosing)) then
Insert_After (Freeze_Node (Par), Freeze_Node (Enclosing));
end if;
end;
else
Insert_After_Last_Decl (N, F_Node);
end if;
else
Insert_After_Last_Decl (N, F_Node);
end if;
end if;
Set_Is_Frozen (Act_Id);
Insert_Before (N, Act_Body);
Mark_Rewrite_Insertion (Act_Body);
end Install_Body;
procedure Install_Parent (P : Entity_Id; In_Body : Boolean := False) is
Ancestors : constant Elist_Id := New_Elmt_List;
S : constant Entity_Id := Current_Scope;
Inst_Par : Entity_Id;
First_Par : Entity_Id;
Inst_Node : Node_Id;
Gen_Par : Entity_Id;
First_Gen : Entity_Id;
Elmt : Elmt_Id;
procedure Install_Formal_Packages (Par : Entity_Id);
procedure Install_Noninstance_Specs (Par : Entity_Id);
procedure Install_Spec (Par : Entity_Id);
procedure Install_Formal_Packages (Par : Entity_Id) is
E : Entity_Id;
begin
E := First_Entity (Par);
while Present (E) loop
if Ekind (E) = E_Package
and then Nkind (Parent (E)) = N_Package_Renaming_Declaration
then
if Renamed_Object (E) = Par then
exit;
elsif Denotes_Formal_Package (E) then
null;
elsif Present (Associated_Formal_Package (E))
and then Box_Present (Parent (Associated_Formal_Package (E)))
then
Check_Generic_Actuals (Renamed_Object (E), True);
Set_Is_Hidden (E, False);
end if;
end if;
Next_Entity (E);
end loop;
end Install_Formal_Packages;
procedure Install_Noninstance_Specs (Par : Entity_Id) is
begin
if Present (Par)
and then Par /= Standard_Standard
and then not In_Open_Scopes (Par)
then
Install_Noninstance_Specs (Scope (Par));
Install_Spec (Par);
end if;
end Install_Noninstance_Specs;
procedure Install_Spec (Par : Entity_Id) is
Spec : constant Node_Id :=
Specification (Unit_Declaration_Node (Par));
begin
if Scope (Par) = Standard_Standard
and then not Is_Generic_Instance (Par)
then
Parent_Unit_Visible := Is_Immediately_Visible (Par);
Instance_Parent_Unit := Par;
end if;
New_Scope (Par);
Set_Is_Immediately_Visible (Par);
Install_Visible_Declarations (Par);
Set_Use (Visible_Declarations (Spec));
if In_Body or else Is_RTU (Par, Ada_Tags) then
Install_Private_Declarations (Par);
Set_Use (Private_Declarations (Spec));
end if;
end Install_Spec;
begin
Inst_Par := P;
if Present (Renamed_Entity (Inst_Par)) then
Inst_Par := Renamed_Entity (Inst_Par);
end if;
First_Par := Inst_Par;
Gen_Par :=
Generic_Parent (Specification (Unit_Declaration_Node (Inst_Par)));
First_Gen := Gen_Par;
while Present (Gen_Par)
and then Is_Child_Unit (Gen_Par)
loop
Inst_Node := Get_Package_Instantiation_Node (Inst_Par);
if Nkind (Name (Inst_Node)) = N_Expanded_Name then
Inst_Par := Entity (Prefix (Name (Inst_Node)));
if Present (Renamed_Entity (Inst_Par)) then
Inst_Par := Renamed_Entity (Inst_Par);
end if;
Gen_Par :=
Generic_Parent
(Specification (Unit_Declaration_Node (Inst_Par)));
if Present (Gen_Par) then
Prepend_Elmt (Inst_Par, Ancestors);
else
Install_Noninstance_Specs (Inst_Par);
exit;
end if;
else
exit;
end if;
end loop;
if Present (First_Gen) then
Append_Elmt (First_Par, Ancestors);
else
Install_Noninstance_Specs (First_Par);
end if;
if not Is_Empty_Elmt_List (Ancestors) then
Elmt := First_Elmt (Ancestors);
while Present (Elmt) loop
Install_Spec (Node (Elmt));
Install_Formal_Packages (Node (Elmt));
Next_Elmt (Elmt);
end loop;
end if;
if not In_Body then
New_Scope (S);
end if;
end Install_Parent;
function Instantiate_Formal_Package
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id
is
Loc : constant Source_Ptr := Sloc (Actual);
Actual_Pack : Entity_Id;
Formal_Pack : Entity_Id;
Gen_Parent : Entity_Id;
Decls : List_Id;
Nod : Node_Id;
Parent_Spec : Node_Id;
procedure Find_Matching_Actual
(F : Node_Id;
Act : in out Entity_Id);
function Get_Formal_Entity (N : Node_Id) return Entity_Id;
procedure Match_Formal_Entity
(Formal_Node : Node_Id;
Formal_Ent : Entity_Id;
Actual_Ent : Entity_Id);
function Is_Instance_Of
(Act_Spec : Entity_Id;
Gen_Anc : Entity_Id) return Boolean;
procedure Map_Entities (Form : Entity_Id; Act : Entity_Id);
procedure Process_Nested_Formal (Formal : Entity_Id);
procedure Find_Matching_Actual
(F : Node_Id;
Act : in out Entity_Id)
is
Formal_Ent : Entity_Id;
begin
case Nkind (Original_Node (F)) is
when N_Formal_Object_Declaration |
N_Formal_Type_Declaration =>
Formal_Ent := Defining_Identifier (F);
while Chars (Act) /= Chars (Formal_Ent) loop
Next_Entity (Act);
end loop;
when N_Formal_Subprogram_Declaration |
N_Formal_Package_Declaration |
N_Package_Declaration |
N_Generic_Package_Declaration =>
Formal_Ent := Defining_Entity (F);
while Chars (Act) /= Chars (Formal_Ent) loop
Next_Entity (Act);
end loop;
when others =>
raise Program_Error;
end case;
end Find_Matching_Actual;
procedure Match_Formal_Entity
(Formal_Node : Node_Id;
Formal_Ent : Entity_Id;
Actual_Ent : Entity_Id)
is
Act_Pkg : Entity_Id;
begin
Set_Instance_Of (Formal_Ent, Actual_Ent);
if Ekind (Actual_Ent) = E_Package then
Act_Pkg := Actual_Ent;
declare
A_Ent : Entity_Id := First_Entity (Act_Pkg);
F_Ent : Entity_Id;
F_Node : Node_Id;
Gen_Decl : Node_Id;
Formals : List_Id;
Actual : Entity_Id;
begin
Actual := Entity (Name (Original_Node (Formal_Node)));
if Present (Renamed_Entity (Actual)) then
Gen_Decl := Unit_Declaration_Node (Renamed_Entity (Actual));
else
Gen_Decl := Unit_Declaration_Node (Actual);
end if;
Formals := Generic_Formal_Declarations (Gen_Decl);
if Present (Formals) then
F_Node := First_Non_Pragma (Formals);
else
F_Node := Empty;
end if;
while Present (A_Ent)
and then Present (F_Node)
and then A_Ent /= First_Private_Entity (Act_Pkg)
loop
F_Ent := Get_Formal_Entity (F_Node);
if Present (F_Ent) then
Find_Matching_Actual (F_Node, A_Ent);
Match_Formal_Entity (F_Node, F_Ent, A_Ent);
Next_Entity (A_Ent);
end if;
Next_Non_Pragma (F_Node);
end loop;
end;
end if;
end Match_Formal_Entity;
function Get_Formal_Entity (N : Node_Id) return Entity_Id is
Kind : constant Node_Kind := Nkind (Original_Node (N));
begin
case Kind is
when N_Formal_Object_Declaration =>
return Defining_Identifier (N);
when N_Formal_Type_Declaration =>
return Defining_Identifier (N);
when N_Formal_Subprogram_Declaration =>
return Defining_Unit_Name (Specification (N));
when N_Formal_Package_Declaration =>
return Defining_Identifier (Original_Node (N));
when N_Generic_Package_Declaration =>
return Defining_Identifier (Original_Node (N));
when others =>
return Empty;
end case;
end Get_Formal_Entity;
function Is_Instance_Of
(Act_Spec : Entity_Id;
Gen_Anc : Entity_Id) return Boolean
is
Gen_Par : constant Entity_Id := Generic_Parent (Act_Spec);
begin
if No (Gen_Par) then
return False;
elsif Gen_Par = Gen_Anc then
return True;
elsif Chars (Gen_Par) /= Chars (Gen_Anc) then
return False;
elsif not Is_Generic_Instance (Scope (Gen_Par)) then
return False;
else
return Generic_Parent (Parent (Scope (Gen_Par))) = Scope (Gen_Anc);
end if;
end Is_Instance_Of;
procedure Map_Entities (Form : Entity_Id; Act : Entity_Id) is
E1 : Entity_Id;
E2 : Entity_Id;
begin
Set_Instance_Of (Form, Act);
E1 := First_Entity (Form);
E2 := First_Entity (Act);
while Present (E1)
and then E1 /= First_Private_Entity (Form)
loop
if not Is_Internal (E1)
and then Present (Parent (E1))
and then not Is_Class_Wide_Type (E1)
and then not Is_Internal_Name (Chars (E1))
then
while Present (E2)
and then Chars (E2) /= Chars (E1)
loop
Next_Entity (E2);
end loop;
if No (E2) then
exit;
else
Set_Instance_Of (E1, E2);
if Is_Type (E1)
and then Is_Tagged_Type (E2)
then
Set_Instance_Of
(Class_Wide_Type (E1), Class_Wide_Type (E2));
end if;
if Ekind (E1) = E_Package
and then No (Renamed_Object (E1))
then
Map_Entities (E1, E2);
end if;
end if;
end if;
Next_Entity (E1);
end loop;
end Map_Entities;
procedure Process_Nested_Formal (Formal : Entity_Id) is
Ent : Entity_Id;
begin
if Present (Associated_Formal_Package (Formal))
and then Box_Present (Parent (Associated_Formal_Package (Formal)))
then
Ent := First_Entity (Formal);
while Present (Ent) loop
Set_Is_Hidden (Ent, False);
Set_Is_Potentially_Use_Visible
(Ent, Is_Potentially_Use_Visible (Formal));
if Ekind (Ent) = E_Package then
exit when Renamed_Entity (Ent) = Renamed_Entity (Formal);
Process_Nested_Formal (Ent);
end if;
Next_Entity (Ent);
end loop;
end if;
end Process_Nested_Formal;
begin
Analyze (Actual);
if not Is_Entity_Name (Actual)
or else Ekind (Entity (Actual)) /= E_Package
then
Error_Msg_N
("expect package instance to instantiate formal", Actual);
Abandon_Instantiation (Actual);
raise Program_Error;
else
Actual_Pack := Entity (Actual);
Set_Is_Instantiated (Actual_Pack);
if Present (Renamed_Object (Actual_Pack)) then
Actual_Pack := Renamed_Object (Actual_Pack);
end if;
if Nkind (Analyzed_Formal) = N_Formal_Package_Declaration then
Gen_Parent := Get_Instance_Of (Entity (Name (Analyzed_Formal)));
Formal_Pack := Defining_Identifier (Analyzed_Formal);
else
Gen_Parent :=
Generic_Parent (Specification (Analyzed_Formal));
Formal_Pack :=
Defining_Unit_Name (Specification (Analyzed_Formal));
end if;
if Nkind (Parent (Actual_Pack)) = N_Defining_Program_Unit_Name then
Parent_Spec := Specification (Unit_Declaration_Node (Actual_Pack));
else
Parent_Spec := Parent (Actual_Pack);
end if;
if Gen_Parent = Any_Id then
Error_Msg_N
("previous error in declaration of formal package", Actual);
Abandon_Instantiation (Actual);
elsif
Is_Instance_Of (Parent_Spec, Get_Instance_Of (Gen_Parent))
then
null;
else
Error_Msg_NE
("actual parameter must be instance of&", Actual, Gen_Parent);
Abandon_Instantiation (Actual);
end if;
Set_Instance_Of (Defining_Identifier (Formal), Actual_Pack);
Map_Entities (Formal_Pack, Actual_Pack);
Nod :=
Make_Package_Renaming_Declaration (Loc,
Defining_Unit_Name => New_Copy (Defining_Identifier (Formal)),
Name => New_Reference_To (Actual_Pack, Loc));
Set_Associated_Formal_Package (Defining_Unit_Name (Nod),
Defining_Identifier (Formal));
Decls := New_List (Nod);
if Box_Present (Formal) then
declare
Gen_Decl : constant Node_Id :=
Unit_Declaration_Node (Gen_Parent);
Formals : constant List_Id :=
Generic_Formal_Declarations (Gen_Decl);
Actual_Ent : Entity_Id;
Formal_Node : Node_Id;
Formal_Ent : Entity_Id;
begin
if Present (Formals) then
Formal_Node := First_Non_Pragma (Formals);
else
Formal_Node := Empty;
end if;
Actual_Ent := First_Entity (Actual_Pack);
while Present (Actual_Ent)
and then Actual_Ent /= First_Private_Entity (Actual_Pack)
loop
Set_Is_Hidden (Actual_Ent, False);
Set_Is_Potentially_Use_Visible
(Actual_Ent, In_Use (Actual_Pack));
if Ekind (Actual_Ent) = E_Package then
Process_Nested_Formal (Actual_Ent);
end if;
if Present (Formal_Node) then
Formal_Ent := Get_Formal_Entity (Formal_Node);
if Present (Formal_Ent) then
Find_Matching_Actual (Formal_Node, Actual_Ent);
Match_Formal_Entity
(Formal_Node, Formal_Ent, Actual_Ent);
end if;
Next_Non_Pragma (Formal_Node);
else
Next_Entity (Actual_Ent);
end if;
end loop;
end;
else
declare
I_Pack : constant Entity_Id :=
Make_Defining_Identifier (Sloc (Actual),
Chars => New_Internal_Name ('P'));
begin
Set_Is_Internal (I_Pack);
Append_To (Decls,
Make_Package_Instantiation (Sloc (Actual),
Defining_Unit_Name => I_Pack,
Name => New_Occurrence_Of (Gen_Parent, Sloc (Actual)),
Generic_Associations =>
Generic_Associations (Formal)));
end;
end if;
return Decls;
end if;
end Instantiate_Formal_Package;
function Instantiate_Formal_Subprogram
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return Node_Id
is
Loc : Source_Ptr := Sloc (Instantiation_Node);
Formal_Sub : constant Entity_Id :=
Defining_Unit_Name (Specification (Formal));
Analyzed_S : constant Entity_Id :=
Defining_Unit_Name (Specification (Analyzed_Formal));
Decl_Node : Node_Id;
Nam : Node_Id;
New_Spec : Node_Id;
function From_Parent_Scope (Subp : Entity_Id) return Boolean;
procedure Valid_Actual_Subprogram (Act : Node_Id);
function From_Parent_Scope (Subp : Entity_Id) return Boolean is
Gen_Scope : Node_Id := Scope (Analyzed_S);
begin
while Present (Gen_Scope)
and then Is_Child_Unit (Gen_Scope)
loop
if Scope (Subp) = Scope (Gen_Scope) then
return True;
end if;
Gen_Scope := Scope (Gen_Scope);
end loop;
return False;
end From_Parent_Scope;
procedure Valid_Actual_Subprogram (Act : Node_Id) is
Act_E : Entity_Id := Empty;
begin
if Is_Entity_Name (Act) then
Act_E := Entity (Act);
elsif Nkind (Act) = N_Selected_Component
and then Is_Entity_Name (Selector_Name (Act))
then
Act_E := Entity (Selector_Name (Act));
end if;
if (Present (Act_E) and then Is_Overloadable (Act_E))
or else Nkind (Act) = N_Attribute_Reference
or else Nkind (Act) = N_Indexed_Component
or else Nkind (Act) = N_Character_Literal
or else Nkind (Act) = N_Explicit_Dereference
then
return;
end if;
Error_Msg_NE
("expect subprogram or entry name in instantiation of&",
Instantiation_Node, Formal_Sub);
Abandon_Instantiation (Instantiation_Node);
end Valid_Actual_Subprogram;
begin
New_Spec := New_Copy_Tree (Specification (Formal));
Set_Defining_Unit_Name
(New_Spec, Make_Defining_Identifier (Loc, Chars (Formal_Sub)));
if Present (Actual) then
Loc := Sloc (Actual);
Set_Sloc (New_Spec, Loc);
if Nkind (Actual) = N_Operator_Symbol then
Find_Direct_Name (Actual);
elsif Nkind (Actual) = N_Explicit_Dereference then
Analyze (Prefix (Actual));
elsif Nkind (Actual) /= N_Attribute_Reference then
Analyze (Actual);
end if;
Valid_Actual_Subprogram (Actual);
Nam := Actual;
elsif Present (Default_Name (Formal)) then
if Nkind (Default_Name (Formal)) /= N_Attribute_Reference
and then Nkind (Default_Name (Formal)) /= N_Selected_Component
and then Nkind (Default_Name (Formal)) /= N_Indexed_Component
and then Nkind (Default_Name (Formal)) /= N_Character_Literal
and then Present (Entity (Default_Name (Formal)))
then
Nam := New_Occurrence_Of (Entity (Default_Name (Formal)), Loc);
else
Nam := New_Copy (Default_Name (Formal));
Set_Sloc (Nam, Loc);
end if;
elsif Box_Present (Formal) then
if Nkind (Formal_Sub) = N_Defining_Operator_Symbol then
Nam := Make_Operator_Symbol (Loc,
Chars => Chars (Formal_Sub),
Strval => No_String);
else
Nam := Make_Identifier (Loc, Chars (Formal_Sub));
end if;
elsif Nkind (Specification (Formal)) = N_Procedure_Specification
and then Null_Present (Specification (Formal))
then
Decl_Node :=
Make_Subprogram_Body (Loc,
Specification => New_Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Make_Null_Statement (Loc))));
Set_Is_Intrinsic_Subprogram (Defining_Unit_Name (New_Spec));
return Decl_Node;
else
Error_Msg_Sloc := Sloc (Scope (Analyzed_S));
Error_Msg_NE
("missing actual&", Instantiation_Node, Formal_Sub);
Error_Msg_NE
("\in instantiation of & declared#",
Instantiation_Node, Scope (Analyzed_S));
Abandon_Instantiation (Instantiation_Node);
end if;
Decl_Node :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification => New_Spec,
Name => Nam);
if No (Actual) and then Box_Present (Formal) then
Set_From_Default (Decl_Node);
end if;
if Box_Present (Formal)
and then No (Actual)
then
Analyze (Nam);
if Is_Child_Unit (Scope (Analyzed_S))
and then Present (Entity (Nam))
then
if not Is_Overloaded (Nam) then
if From_Parent_Scope (Entity (Nam)) then
Set_Is_Immediately_Visible (Entity (Nam), False);
Set_Entity (Nam, Empty);
Set_Etype (Nam, Empty);
Analyze (Nam);
Set_Is_Immediately_Visible (Entity (Nam));
end if;
else
declare
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (Nam, I, It);
while Present (It.Nam) loop
if From_Parent_Scope (It.Nam) then
Remove_Interp (I);
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
end if;
end if;
Set_Corresponding_Formal_Spec (Decl_Node, Analyzed_S);
Set_Instance_Of (Analyzed_S, Nam);
if Nkind (Actual) = N_Selected_Component
and then Is_Task_Type (Etype (Prefix (Actual)))
and then not Is_Frozen (Etype (Prefix (Actual)))
then
declare
Anon_Id : constant Entity_Id :=
Make_Defining_Identifier
(Loc, New_Internal_Name ('E'));
begin
Set_Defining_Unit_Name (New_Spec, Anon_Id);
Insert_Before (Instantiation_Node, Decl_Node);
Analyze (Decl_Node);
Decl_Node :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification => New_Copy_Tree (New_Spec),
Name => New_Occurrence_Of (Anon_Id, Loc));
Set_Defining_Unit_Name (Specification (Decl_Node),
Make_Defining_Identifier (Loc, Chars (Formal_Sub)));
end;
end if;
return Decl_Node;
end Instantiate_Formal_Subprogram;
function Instantiate_Object
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id) return List_Id
is
Formal_Id : constant Entity_Id := Defining_Identifier (Formal);
Type_Id : constant Node_Id := Subtype_Mark (Formal);
Loc : constant Source_Ptr := Sloc (Actual);
Act_Assoc : constant Node_Id := Parent (Actual);
Orig_Ftyp : constant Entity_Id :=
Etype (Defining_Identifier (Analyzed_Formal));
List : constant List_Id := New_List;
Ftyp : Entity_Id;
Decl_Node : Node_Id;
Subt_Decl : Node_Id := Empty;
begin
Error_Msg_Sloc := Sloc (Scope (Defining_Identifier (Analyzed_Formal)));
if Get_Instance_Of (Formal_Id) /= Formal_Id then
Error_Msg_N ("duplicate instantiation of generic parameter", Actual);
end if;
Set_Parent (List, Parent (Actual));
if Out_Present (Formal) then
if No (Actual) then
Error_Msg_NE
("missing actual&",
Instantiation_Node, Formal_Id);
Error_Msg_NE
("\in instantiation of & declared#",
Instantiation_Node,
Scope (Defining_Identifier (Analyzed_Formal)));
Abandon_Instantiation (Instantiation_Node);
end if;
Decl_Node :=
Make_Object_Renaming_Declaration (Loc,
Defining_Identifier => New_Copy (Formal_Id),
Subtype_Mark => New_Copy_Tree (Type_Id),
Name => Actual);
Set_Corresponding_Generic_Association (Decl_Node, Act_Assoc);
Append (Decl_Node, List);
Analyze (Actual);
if Etype (Actual) = Any_Type then
return List;
end if;
if Is_Object_Reference (Actual)
and then Is_Dependent_Component_Of_Mutable_Object (Actual)
then
Error_Msg_N
("illegal discriminant-dependent component for in out parameter",
Actual);
end if;
Ftyp :=
Get_Instance_Of (Etype (Defining_Identifier (Analyzed_Formal)));
if Is_Private_Type (Ftyp)
and then not Is_Private_Type (Etype (Actual))
and then (Base_Type (Full_View (Ftyp)) = Base_Type (Etype (Actual))
or else Base_Type (Etype (Actual)) = Ftyp)
then
Subt_Decl :=
Make_Subtype_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
Subtype_Indication => New_Occurrence_Of (Ftyp, Loc));
Prepend (Subt_Decl, List);
Prepend_Elmt (Full_View (Ftyp), Exchanged_Views);
Exchange_Declarations (Ftyp);
end if;
Resolve (Actual, Ftyp);
if not Is_Variable (Actual) or else Paren_Count (Actual) > 0 then
Error_Msg_NE
("actual for& must be a variable", Actual, Formal_Id);
elsif Base_Type (Ftyp) /= Base_Type (Etype (Actual)) then
Error_Msg_NE (
"type of actual does not match type of&", Actual, Formal_Id);
end if;
Note_Possible_Modification (Actual);
if Is_Atomic_Object (Actual)
and then not Is_Atomic (Orig_Ftyp)
then
Error_Msg_N
("cannot instantiate non-atomic formal object " &
"with atomic actual", Actual);
elsif Is_Volatile_Object (Actual)
and then not Is_Volatile (Orig_Ftyp)
then
Error_Msg_N
("cannot instantiate non-volatile formal object " &
"with volatile actual", Actual);
end if;
else
if Present (Actual) then
Decl_Node := Make_Object_Declaration (Loc,
Defining_Identifier => New_Copy (Formal_Id),
Constant_Present => True,
Object_Definition => New_Copy_Tree (Type_Id),
Expression => Actual);
Set_Corresponding_Generic_Association (Decl_Node, Act_Assoc);
if Is_Tagged_Type
(Etype (Defining_Identifier (Analyzed_Formal)))
then
Set_Aliased_Present (Decl_Node);
end if;
Append (Decl_Node, List);
if Nkind (Actual) /= N_Allocator then
Analyze (Actual);
if Etype (Actual) = Any_Type then
return List;
end if;
end if;
declare
Typ : constant Entity_Id :=
Get_Instance_Of
(Etype (Defining_Identifier (Analyzed_Formal)));
begin
Freeze_Before (Instantiation_Node, Typ);
if Nkind (Actual) = N_Aggregate then
Pre_Analyze_And_Resolve (Actual, Typ);
end if;
end;
elsif Present (Expression (Formal)) then
Decl_Node :=
Make_Object_Declaration (Sloc (Formal),
Defining_Identifier => New_Copy (Formal_Id),
Constant_Present => True,
Object_Definition => New_Copy (Type_Id),
Expression => New_Copy_Tree (Expression (Formal)));
Append (Decl_Node, List);
Set_Analyzed (Expression (Decl_Node), False);
else
Error_Msg_NE
("missing actual&",
Instantiation_Node, Formal_Id);
Error_Msg_NE ("\in instantiation of & declared#",
Instantiation_Node,
Scope (Defining_Identifier (Analyzed_Formal)));
if Is_Scalar_Type
(Etype (Defining_Identifier (Analyzed_Formal)))
then
Decl_Node :=
Make_Object_Declaration (Loc,
Defining_Identifier => New_Copy (Formal_Id),
Constant_Present => True,
Object_Definition => New_Copy (Type_Id),
Expression =>
Make_Attribute_Reference (Sloc (Formal_Id),
Attribute_Name => Name_First,
Prefix => New_Copy (Type_Id)));
Append (Decl_Node, List);
else
Abandon_Instantiation (Instantiation_Node);
end if;
end if;
end if;
return List;
end Instantiate_Object;
procedure Instantiate_Package_Body
(Body_Info : Pending_Body_Info;
Inlined_Body : Boolean := False)
is
Act_Decl : constant Node_Id := Body_Info.Act_Decl;
Inst_Node : constant Node_Id := Body_Info.Inst_Node;
Loc : constant Source_Ptr := Sloc (Inst_Node);
Gen_Id : constant Node_Id := Name (Inst_Node);
Gen_Unit : constant Entity_Id := Get_Generic_Entity (Inst_Node);
Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Unit);
Act_Spec : constant Node_Id := Specification (Act_Decl);
Act_Decl_Id : constant Entity_Id := Defining_Entity (Act_Spec);
Act_Body_Name : Node_Id;
Gen_Body : Node_Id;
Gen_Body_Id : Node_Id;
Act_Body : Node_Id;
Act_Body_Id : Entity_Id;
Parent_Installed : Boolean := False;
Save_Style_Check : constant Boolean := Style_Check;
begin
Gen_Body_Id := Corresponding_Body (Gen_Decl);
if Present (Corresponding_Body (Instance_Spec (Inst_Node))) then
return;
end if;
Expander_Mode_Save_And_Set (Body_Info.Expander_Status);
if No (Gen_Body_Id) then
Load_Parent_Of_Generic (Inst_Node, Specification (Gen_Decl));
Gen_Body_Id := Corresponding_Body (Gen_Decl);
end if;
Instantiation_Node := Inst_Node;
if Present (Gen_Body_Id) then
Save_Env (Gen_Unit, Act_Decl_Id);
Style_Check := False;
Current_Sem_Unit := Body_Info.Current_Sem_Unit;
Gen_Body := Unit_Declaration_Node (Gen_Body_Id);
Create_Instantiation_Source
(Inst_Node, Gen_Body_Id, False, S_Adjustment);
Act_Body :=
Copy_Generic_Node
(Original_Node (Gen_Body), Empty, Instantiating => True);
Act_Body_Id := New_Copy (Act_Decl_Id);
Set_Handler_Records (Act_Body_Id, No_List);
if Nkind (Defining_Unit_Name (Act_Spec)) =
N_Defining_Program_Unit_Name
then
Act_Body_Name :=
Make_Defining_Program_Unit_Name (Loc,
Name => New_Copy_Tree (Name (Defining_Unit_Name (Act_Spec))),
Defining_Identifier => Act_Body_Id);
else
Act_Body_Name := Act_Body_Id;
end if;
Set_Defining_Unit_Name (Act_Body, Act_Body_Name);
Set_Corresponding_Spec (Act_Body, Act_Decl_Id);
Check_Generic_Actuals (Act_Decl_Id, False);
if Ekind (Scope (Gen_Unit)) = E_Generic_Package
and then Nkind (Gen_Id) = N_Expanded_Name
then
Install_Parent (Entity (Prefix (Gen_Id)), In_Body => True);
Parent_Installed := True;
elsif Is_Child_Unit (Gen_Unit) then
Install_Parent (Scope (Gen_Unit), In_Body => True);
Parent_Installed := True;
end if;
if Nkind (Parent (Inst_Node)) = N_Compilation_Unit then
Build_Instance_Compilation_Unit_Nodes
(Inst_Node, Act_Body, Act_Decl);
Analyze (Inst_Node);
if Parent (Inst_Node) = Cunit (Main_Unit) then
if Nkind (Defining_Unit_Name (Act_Spec)) =
N_Defining_Program_Unit_Name
then
Set_Scope
(Defining_Entity (Inst_Node), Scope (Act_Decl_Id));
end if;
end if;
else
Install_Body (Act_Body, Inst_Node, Gen_Body, Gen_Decl);
if Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Gen_Decl)))
then
Analyze (Act_Body, Suppress => All_Checks);
else
Analyze (Act_Body);
end if;
end if;
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Body, Inst_Node);
end if;
if Parent_Installed then
Remove_Parent (In_Body => True);
end if;
Restore_Private_Views (Act_Decl_Id);
if not Inlined_Body then
Set_Is_Immediately_Visible (Act_Decl_Id, False);
end if;
Restore_Env;
Style_Check := Save_Style_Check;
elsif Unit_Requires_Body (Gen_Unit) then
if Serious_Errors_Detected = 0 then
Error_Msg_NE
("cannot find body of generic package &", Inst_Node, Gen_Unit);
else
return;
end if;
else
if Nkind (Parent (Inst_Node)) = N_Compilation_Unit then
Set_Parent_Spec (Act_Decl, Parent_Spec (Inst_Node));
Rewrite (Inst_Node, Act_Decl);
Set_Elaboration_Entity_Required (Act_Decl_Id, False);
Build_Elaboration_Entity (Parent (Inst_Node), Act_Decl_Id);
elsif not Is_List_Member (Act_Decl) then
Mark_Rewrite_Insertion (Act_Decl);
Insert_Before (Inst_Node, Act_Decl);
end if;
end if;
Expander_Mode_Restore;
end Instantiate_Package_Body;
procedure Instantiate_Subprogram_Body
(Body_Info : Pending_Body_Info)
is
Act_Decl : constant Node_Id := Body_Info.Act_Decl;
Inst_Node : constant Node_Id := Body_Info.Inst_Node;
Loc : constant Source_Ptr := Sloc (Inst_Node);
Gen_Id : constant Node_Id := Name (Inst_Node);
Gen_Unit : constant Entity_Id := Get_Generic_Entity (Inst_Node);
Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Unit);
Anon_Id : constant Entity_Id :=
Defining_Unit_Name (Specification (Act_Decl));
Pack_Id : constant Entity_Id :=
Defining_Unit_Name (Parent (Act_Decl));
Decls : List_Id;
Gen_Body : Node_Id;
Gen_Body_Id : Node_Id;
Act_Body : Node_Id;
Act_Body_Id : Entity_Id;
Pack_Body : Node_Id;
Prev_Formal : Entity_Id;
Ret_Expr : Node_Id;
Unit_Renaming : Node_Id;
Parent_Installed : Boolean := False;
Save_Style_Check : constant Boolean := Style_Check;
begin
Gen_Body_Id := Corresponding_Body (Gen_Decl);
Expander_Mode_Save_And_Set (Body_Info.Expander_Status);
if No (Gen_Body_Id) then
Load_Parent_Of_Generic (Inst_Node, Specification (Gen_Decl));
Gen_Body_Id := Corresponding_Body (Gen_Decl);
end if;
Instantiation_Node := Inst_Node;
if Present (Gen_Body_Id) then
Gen_Body := Unit_Declaration_Node (Gen_Body_Id);
if Nkind (Gen_Body) = N_Subprogram_Body_Stub then
if Expander_Active
and then Operating_Mode = Generate_Code
then
Error_Msg_N
("missing proper body for instantiation", Gen_Body);
end if;
Set_Has_Completion (Anon_Id);
return;
end if;
Save_Env (Gen_Unit, Anon_Id);
Style_Check := False;
Current_Sem_Unit := Body_Info.Current_Sem_Unit;
Create_Instantiation_Source
(Inst_Node,
Gen_Body_Id,
False,
S_Adjustment);
Act_Body :=
Copy_Generic_Node
(Original_Node (Gen_Body), Empty, Instantiating => True);
Act_Body_Id := Defining_Entity (Act_Body);
Set_Chars (Act_Body_Id, Chars (Anon_Id));
Set_Sloc (Act_Body_Id, Sloc (Defining_Entity (Inst_Node)));
Set_Corresponding_Spec (Act_Body, Anon_Id);
Set_Has_Completion (Anon_Id);
Check_Generic_Actuals (Pack_Id, False);
if Ekind (Scope (Gen_Unit)) = E_Generic_Package
and then Nkind (Gen_Id) = N_Expanded_Name
then
Install_Parent (Entity (Prefix (Gen_Id)), In_Body => True);
Parent_Installed := True;
elsif Is_Child_Unit (Gen_Unit) then
Install_Parent (Scope (Gen_Unit), In_Body => True);
Parent_Installed := True;
end if;
Unit_Renaming :=
Make_Subprogram_Renaming_Declaration (Loc,
Specification =>
Copy_Generic_Node (
Specification (Original_Node (Gen_Body)),
Empty,
Instantiating => True),
Name => New_Occurrence_Of (Anon_Id, Loc));
Prev_Formal := First_Entity (Pack_Id);
while Present (Prev_Formal) loop
if Chars (Prev_Formal) = Chars (Gen_Unit)
and then Is_Overloadable (Prev_Formal)
then
exit;
end if;
Next_Entity (Prev_Formal);
end loop;
if Present (Prev_Formal) then
Decls := New_List (Act_Body);
else
Decls := New_List (Unit_Renaming, Act_Body);
end if;
Pack_Body := Make_Package_Body (Loc,
Defining_Unit_Name => New_Copy (Pack_Id),
Declarations => Decls);
Set_Corresponding_Spec (Pack_Body, Pack_Id);
if Nkind (Parent (Inst_Node)) = N_Compilation_Unit then
if Parent (Inst_Node) = Cunit (Main_Unit) then
Set_Unit (Parent (Inst_Node), Inst_Node);
Build_Instance_Compilation_Unit_Nodes
(Inst_Node, Pack_Body, Parent (Parent (Act_Decl)));
Analyze (Inst_Node);
else
Set_Parent (Pack_Body, Parent (Inst_Node));
Analyze (Pack_Body);
end if;
else
Insert_Before (Inst_Node, Pack_Body);
Mark_Rewrite_Insertion (Pack_Body);
Analyze (Pack_Body);
if Expander_Active then
Freeze_Subprogram_Body (Inst_Node, Gen_Body, Pack_Id);
end if;
end if;
if not Generic_Separately_Compiled (Gen_Unit) then
Inherit_Context (Gen_Body, Inst_Node);
end if;
Restore_Private_Views (Pack_Id, False);
if Parent_Installed then
Remove_Parent (In_Body => True);
end if;
Restore_Env;
Style_Check := Save_Style_Check;
elsif Serious_Errors_Detected = 0
and then Nkind (Parent (Inst_Node)) /= N_Compilation_Unit
then
if Ekind (Anon_Id) = E_Procedure then
Act_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Anon_Id)),
Parameter_Specifications =>
New_Copy_List
(Parameter_Specifications (Parent (Anon_Id)))),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements =>
New_List (
Make_Raise_Program_Error (Loc,
Reason =>
PE_Access_Before_Elaboration))));
else
Ret_Expr :=
Make_Raise_Program_Error (Loc,
Reason => PE_Access_Before_Elaboration);
Set_Etype (Ret_Expr, (Etype (Anon_Id)));
Set_Analyzed (Ret_Expr);
Act_Body :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Function_Specification (Loc,
Defining_Unit_Name =>
Make_Defining_Identifier (Loc, Chars (Anon_Id)),
Parameter_Specifications =>
New_Copy_List
(Parameter_Specifications (Parent (Anon_Id))),
Result_Definition =>
New_Occurrence_Of (Etype (Anon_Id), Loc)),
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements =>
New_List (Make_Return_Statement (Loc, Ret_Expr))));
end if;
Pack_Body := Make_Package_Body (Loc,
Defining_Unit_Name => New_Copy (Pack_Id),
Declarations => New_List (Act_Body));
Insert_After (Inst_Node, Pack_Body);
Set_Corresponding_Spec (Pack_Body, Pack_Id);
Analyze (Pack_Body);
end if;
Expander_Mode_Restore;
end Instantiate_Subprogram_Body;
function Instantiate_Type
(Formal : Node_Id;
Actual : Node_Id;
Analyzed_Formal : Node_Id;
Actual_Decls : List_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Actual);
Gen_T : constant Entity_Id := Defining_Identifier (Formal);
A_Gen_T : constant Entity_Id := Defining_Identifier (Analyzed_Formal);
Ancestor : Entity_Id := Empty;
Def : constant Node_Id := Formal_Type_Definition (Formal);
Act_T : Entity_Id;
Decl_Node : Node_Id;
procedure Validate_Array_Type_Instance;
procedure Validate_Access_Subprogram_Instance;
procedure Validate_Access_Type_Instance;
procedure Validate_Derived_Type_Instance;
procedure Validate_Derived_Interface_Type_Instance;
procedure Validate_Interface_Type_Instance;
procedure Validate_Private_Type_Instance;
function Subtypes_Match (Gen_T, Act_T : Entity_Id) return Boolean;
function Subtypes_Match (Gen_T, Act_T : Entity_Id) return Boolean is
T : constant Entity_Id := Get_Instance_Of (Gen_T);
begin
return (Base_Type (T) = Base_Type (Act_T)
and then Subtypes_Statically_Match (T, Act_T))
or else (Is_Class_Wide_Type (Gen_T)
and then Is_Class_Wide_Type (Act_T)
and then
Subtypes_Match
(Get_Instance_Of (Root_Type (Gen_T)),
Root_Type (Act_T)))
or else
((Ekind (Gen_T) = E_Anonymous_Access_Subprogram_Type
or else Ekind (Gen_T) = E_Anonymous_Access_Type)
and then Ekind (Act_T) = Ekind (Gen_T)
and then
Subtypes_Statically_Match
(Designated_Type (Gen_T), Designated_Type (Act_T)));
end Subtypes_Match;
procedure Validate_Access_Subprogram_Instance is
begin
if not Is_Access_Type (Act_T)
or else Ekind (Designated_Type (Act_T)) /= E_Subprogram_Type
then
Error_Msg_NE
("expect access type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Check_Mode_Conformant
(Designated_Type (Act_T),
Designated_Type (A_Gen_T),
Actual,
Get_Inst => True);
if Ekind (Base_Type (Act_T)) = E_Access_Protected_Subprogram_Type then
if Ekind (A_Gen_T) = E_Access_Subprogram_Type then
Error_Msg_NE
("protected access type not allowed for formal &",
Actual, Gen_T);
end if;
elsif Ekind (A_Gen_T) = E_Access_Protected_Subprogram_Type then
Error_Msg_NE
("expect protected access type for formal &",
Actual, Gen_T);
end if;
end Validate_Access_Subprogram_Instance;
procedure Validate_Access_Type_Instance is
Desig_Type : constant Entity_Id :=
Find_Actual_Type
(Designated_Type (A_Gen_T), Scope (A_Gen_T));
begin
if not Is_Access_Type (Act_T) then
Error_Msg_NE
("expect access type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
if Is_Access_Constant (A_Gen_T) then
if not Is_Access_Constant (Act_T) then
Error_Msg_N
("actual type must be access-to-constant type", Actual);
Abandon_Instantiation (Actual);
end if;
else
if Is_Access_Constant (Act_T) then
Error_Msg_N
("actual type must be access-to-variable type", Actual);
Abandon_Instantiation (Actual);
elsif Ekind (A_Gen_T) = E_General_Access_Type
and then Ekind (Base_Type (Act_T)) /= E_General_Access_Type
then
Error_Msg_N ("actual must be general access type!", Actual);
Error_Msg_NE ("add ALL to }!", Actual, Act_T);
Abandon_Instantiation (Actual);
end if;
end if;
if not Subtypes_Match
(Desig_Type, Designated_Type (Base_Type (Act_T)))
then
Error_Msg_NE
("designated type of actual does not match that of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Is_Access_Type (Designated_Type (Act_T))
and then Is_Constrained (Designated_Type (Designated_Type (Act_T)))
/=
Is_Constrained (Designated_Type (Desig_Type))
then
Error_Msg_NE
("designated type of actual does not match that of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
end Validate_Access_Type_Instance;
procedure Validate_Array_Type_Instance is
I1 : Node_Id;
I2 : Node_Id;
T2 : Entity_Id;
function Formal_Dimensions return Int;
function Formal_Dimensions return Int is
Num : Int := 0;
Index : Node_Id;
begin
if Nkind (Def) = N_Constrained_Array_Definition then
Index := First (Discrete_Subtype_Definitions (Def));
else
Index := First (Subtype_Marks (Def));
end if;
while Present (Index) loop
Num := Num + 1;
Next_Index (Index);
end loop;
return Num;
end Formal_Dimensions;
begin
if not Is_Array_Type (Act_T) then
Error_Msg_NE
("expect array type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Nkind (Def) = N_Constrained_Array_Definition then
if not (Is_Constrained (Act_T)) then
Error_Msg_NE
("expect constrained array in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
else
if Is_Constrained (Act_T) then
Error_Msg_NE
("expect unconstrained array in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
end if;
if Formal_Dimensions /= Number_Dimensions (Act_T) then
Error_Msg_NE
("dimensions of actual do not match formal &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
I1 := First_Index (A_Gen_T);
I2 := First_Index (Act_T);
for J in 1 .. Formal_Dimensions loop
if Is_Entity_Name (Original_Node (I2)) then
T2 := Entity (Original_Node (I2));
else
T2 := Etype (I2);
end if;
if not Subtypes_Match
(Find_Actual_Type (Etype (I1), Scope (A_Gen_T)), T2)
then
Error_Msg_NE
("index types of actual do not match those of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Next_Index (I1);
Next_Index (I2);
end loop;
if not Subtypes_Match (
Find_Actual_Type (Component_Type (A_Gen_T), Scope (A_Gen_T)),
Component_Type (Act_T))
then
Error_Msg_NE
("component subtype of actual does not match that of formal &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
if Has_Aliased_Components (A_Gen_T)
and then not Has_Aliased_Components (Act_T)
then
Error_Msg_NE
("actual must have aliased components to match formal type &",
Actual, Gen_T);
end if;
end Validate_Array_Type_Instance;
procedure Validate_Derived_Interface_Type_Instance is
Par : constant Entity_Id := Entity (Subtype_Indication (Def));
Elmt : Elmt_Id;
begin
Validate_Interface_Type_Instance;
if Present (Par)
and then not Interface_Present_In_Ancestor (Act_T, Par)
then
Error_Msg_NE
("interface actual must include progenitor&", Actual, Par);
end if;
Elmt := First_Elmt (Abstract_Interfaces (A_Gen_T));
while Present (Elmt) loop
if not Interface_Present_In_Ancestor (Act_T, Node (Elmt)) then
Error_Msg_NE
("interface actual must include progenitor&",
Actual, Node (Elmt));
end if;
Next_Elmt (Elmt);
end loop;
end Validate_Derived_Interface_Type_Instance;
procedure Validate_Derived_Type_Instance is
Actual_Discr : Entity_Id;
Ancestor_Discr : Entity_Id;
begin
if Is_Entity_Name (Subtype_Mark (Def))
and then Present (Entity (Subtype_Mark (Def)))
then
Ancestor := Get_Instance_Of (Entity (Subtype_Mark (Def)));
elsif
Scope (Scope (Base_Type (Etype (A_Gen_T)))) = Scope (A_Gen_T)
then
Ancestor :=
Get_Instance_Of (Base_Type (Etype (A_Gen_T)));
elsif Is_Derived_Type (Get_Instance_Of (A_Gen_T))
or else
Ekind (Get_Instance_Of (A_Gen_T)) = E_Record_Type_With_Private
then
if Etype (A_Gen_T) /= A_Gen_T
and then Is_Generic_Type (Etype (A_Gen_T))
and then Scope (Etype (A_Gen_T)) = Scope (A_Gen_T)
and then Etype (Etype (A_Gen_T)) /= Etype (A_Gen_T)
then
declare
Decl : Node_Id;
begin
Decl := First (Actual_Decls);
while Present (Decl) loop
if Nkind (Decl) = N_Subtype_Declaration
and then Chars (Defining_Identifier (Decl)) =
Chars (Etype (A_Gen_T))
then
Ancestor := Generic_Parent_Type (Decl);
exit;
else
Next (Decl);
end if;
end loop;
end;
pragma Assert (Present (Ancestor));
else
Ancestor :=
Get_Instance_Of (Base_Type (Get_Instance_Of (A_Gen_T)));
end if;
else
Ancestor := Get_Instance_Of (Etype (Base_Type (A_Gen_T)));
end if;
if Ada_Version >= Ada_05
and then Is_Interface (Ancestor)
then
if not Interface_Present_In_Ancestor (Act_T, Ancestor) then
Error_Msg_NE
("(Ada 2005) expected type implementing & in instantiation",
Actual, Ancestor);
end if;
elsif not Is_Ancestor (Base_Type (Ancestor), Act_T) then
Error_Msg_NE
("expect type derived from & in instantiation",
Actual, First_Subtype (Ancestor));
Abandon_Instantiation (Actual);
end if;
if Is_Atomic (Act_T) and then not Is_Atomic (Ancestor) then
Error_Msg_N
("cannot have atomic actual type for non-atomic formal type",
Actual);
elsif Is_Volatile (Act_T)
and then not Is_Volatile (Ancestor)
and then Is_By_Reference_Type (Ancestor)
then
Error_Msg_N
("cannot have volatile actual type for non-volatile formal type",
Actual);
end if;
if not Is_Indefinite_Subtype (A_Gen_T)
and then not Unknown_Discriminants_Present (Formal)
and then Is_Indefinite_Subtype (Act_T)
then
Error_Msg_N
("actual subtype must be constrained", Actual);
Abandon_Instantiation (Actual);
end if;
if not Unknown_Discriminants_Present (Formal) then
if Is_Constrained (Ancestor) then
if not Is_Constrained (Act_T) then
Error_Msg_N
("actual subtype must be constrained", Actual);
Abandon_Instantiation (Actual);
end if;
elsif Is_Constrained (Act_T) then
if Ekind (Ancestor) = E_Access_Type
or else Is_Composite_Type (Ancestor)
then
Error_Msg_N
("actual subtype must be unconstrained", Actual);
Abandon_Instantiation (Actual);
end if;
elsif Is_Class_Wide_Type (Act_T)
and then not Has_Unknown_Discriminants (Ancestor)
then
Error_Msg_NE
("actual for & cannot be a class-wide type", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Has_Discriminants (Act_T)
and then not Has_Unknown_Discriminants (Act_T)
and then Has_Discriminants (Ancestor)
then
Actual_Discr := First_Discriminant (Act_T);
Ancestor_Discr := First_Discriminant (Ancestor);
while Present (Actual_Discr)
and then Present (Ancestor_Discr)
loop
if Base_Type (Act_T) /= Base_Type (Ancestor) and then
No (Corresponding_Discriminant (Actual_Discr))
then
Error_Msg_NE
("discriminant & does not correspond " &
"to ancestor discriminant", Actual, Actual_Discr);
Abandon_Instantiation (Actual);
end if;
Next_Discriminant (Actual_Discr);
Next_Discriminant (Ancestor_Discr);
end loop;
if Present (Actual_Discr) or else Present (Ancestor_Discr) then
Error_Msg_NE
("actual for & must have same number of discriminants",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
elsif Has_Discriminants (Act_T)
and then not Has_Unknown_Discriminants (Act_T)
then
Error_Msg_NE
("actual for & must not have discriminants", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Has_Discriminants (Ancestor) then
Error_Msg_NE
("actual for & must have known discriminants", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
if not Subtypes_Statically_Compatible (Act_T, Ancestor) then
Error_Msg_N
("constraint on actual is incompatible with formal", Actual);
Abandon_Instantiation (Actual);
end if;
end if;
end Validate_Derived_Type_Instance;
procedure Validate_Interface_Type_Instance is
begin
if not Is_Interface (Act_T) then
Error_Msg_NE
("actual for formal interface type must be an interface",
Actual, Gen_T);
elsif Is_Limited_Type (Act_T) /= Is_Limited_Type (A_Gen_T)
or else
Is_Task_Interface (A_Gen_T) /= Is_Task_Interface (Act_T)
or else
Is_Protected_Interface (A_Gen_T) /=
Is_Protected_Interface (Act_T)
or else
Is_Synchronized_Interface (A_Gen_T) /=
Is_Synchronized_Interface (Act_T)
then
Error_Msg_NE
("actual for interface& does not match ('R'M 12.5.5(5))",
Actual, Gen_T);
end if;
end Validate_Interface_Type_Instance;
procedure Validate_Private_Type_Instance is
Formal_Discr : Entity_Id;
Actual_Discr : Entity_Id;
Formal_Subt : Entity_Id;
begin
if Is_Limited_Type (Act_T)
and then not Is_Limited_Type (A_Gen_T)
then
Error_Msg_NE
("actual for non-limited & cannot be a limited type", Actual,
Gen_T);
Explain_Limited_Type (Act_T, Actual);
Abandon_Instantiation (Actual);
elsif Is_Indefinite_Subtype (Act_T)
and then not Is_Indefinite_Subtype (A_Gen_T)
and then Ada_Version >= Ada_95
then
Error_Msg_NE
("actual for & must be a definite subtype", Actual, Gen_T);
elsif not Is_Tagged_Type (Act_T)
and then Is_Tagged_Type (A_Gen_T)
then
Error_Msg_NE
("actual for & must be a tagged type", Actual, Gen_T);
elsif Has_Discriminants (A_Gen_T) then
if not Has_Discriminants (Act_T) then
Error_Msg_NE
("actual for & must have discriminants", Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif Is_Constrained (Act_T) then
Error_Msg_NE
("actual for & must be unconstrained", Actual, Gen_T);
Abandon_Instantiation (Actual);
else
Formal_Discr := First_Discriminant (A_Gen_T);
Actual_Discr := First_Discriminant (Act_T);
while Formal_Discr /= Empty loop
if Actual_Discr = Empty then
Error_Msg_NE
("discriminants on actual do not match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Formal_Subt := Get_Instance_Of (Etype (Formal_Discr));
if Ekind (Base_Type (Formal_Subt)) = E_Anonymous_Access_Type
and then (Ekind (Base_Type (Etype (Actual_Discr)))) =
E_Anonymous_Access_Type
and then
Get_Instance_Of
(Designated_Type (Base_Type (Formal_Subt))) =
Designated_Type (Base_Type (Etype (Actual_Discr)))
then
null;
elsif Base_Type (Formal_Subt) /=
Base_Type (Etype (Actual_Discr))
then
Error_Msg_NE
("types of actual discriminants must match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
elsif not Subtypes_Statically_Match
(Formal_Subt, Etype (Actual_Discr))
and then Ada_Version >= Ada_95
then
Error_Msg_NE
("subtypes of actual discriminants must match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
Next_Discriminant (Formal_Discr);
Next_Discriminant (Actual_Discr);
end loop;
if Actual_Discr /= Empty then
Error_Msg_NE
("discriminants on actual do not match formal",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
end if;
end if;
Ancestor := Gen_T;
end Validate_Private_Type_Instance;
begin
if Get_Instance_Of (A_Gen_T) /= A_Gen_T then
Error_Msg_N ("duplicate instantiation of generic type", Actual);
return Error;
elsif not Is_Entity_Name (Actual)
or else not Is_Type (Entity (Actual))
then
Error_Msg_NE
("expect valid subtype mark to instantiate &", Actual, Gen_T);
Abandon_Instantiation (Actual);
else
Act_T := Entity (Actual);
if Is_Unchecked_Union (Base_Type (Act_T)) then
if not Has_Discriminants (A_Gen_T)
or else
(Is_Derived_Type (A_Gen_T)
and then
Is_Unchecked_Union (A_Gen_T))
then
null;
else
Error_Msg_N ("Unchecked_Union cannot be the actual for a" &
" discriminated formal type", Act_T);
end if;
end if;
if Is_Floating_Point_Type (Act_T) then
Check_Restriction (No_Floating_Point, Actual);
elsif Is_Fixed_Point_Type (Act_T) then
Check_Restriction (No_Fixed_Point, Actual);
end if;
if Ekind (Act_T) = E_Incomplete_Type then
if No (Underlying_Type (Act_T)) then
Error_Msg_N ("premature use of incomplete type", Actual);
Abandon_Instantiation (Actual);
else
Act_T := Full_View (Act_T);
Set_Entity (Actual, Act_T);
if Has_Private_Component (Act_T) then
Error_Msg_N
("premature use of type with private component", Actual);
end if;
end if;
elsif Is_Private_Type (Act_T)
and then Is_Private_Type (Base_Type (Act_T))
and then not Is_Generic_Type (Act_T)
and then not Is_Derived_Type (Act_T)
and then No (Full_View (Root_Type (Act_T)))
then
Error_Msg_N ("premature use of private type", Actual);
elsif Has_Private_Component (Act_T) then
Error_Msg_N
("premature use of type with private component", Actual);
end if;
Set_Instance_Of (A_Gen_T, Act_T);
if Is_Tagged_Type (A_Gen_T)
and then Is_Tagged_Type (Act_T)
and then not Is_Class_Wide_Type (A_Gen_T)
then
Set_Instance_Of (Class_Wide_Type (A_Gen_T),
Class_Wide_Type (Act_T));
end if;
if not Is_Abstract (A_Gen_T)
and then Is_Abstract (Act_T)
then
Error_Msg_N
("actual of non-abstract formal cannot be abstract", Actual);
end if;
if Is_Scalar_Type (Gen_T) then
Set_Instance_Of (Etype (A_Gen_T), Etype (Act_T));
end if;
end if;
case Nkind (Def) is
when N_Formal_Private_Type_Definition =>
Validate_Private_Type_Instance;
when N_Formal_Derived_Type_Definition =>
Validate_Derived_Type_Instance;
when N_Formal_Discrete_Type_Definition =>
if not Is_Discrete_Type (Act_T) then
Error_Msg_NE
("expect discrete type in instantiation of&", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Signed_Integer_Type_Definition =>
if not Is_Signed_Integer_Type (Act_T) then
Error_Msg_NE
("expect signed integer type in instantiation of&",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Modular_Type_Definition =>
if not Is_Modular_Integer_Type (Act_T) then
Error_Msg_NE
("expect modular type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Floating_Point_Definition =>
if not Is_Floating_Point_Type (Act_T) then
Error_Msg_NE
("expect float type in instantiation of &", Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Ordinary_Fixed_Point_Definition =>
if not Is_Ordinary_Fixed_Point_Type (Act_T) then
Error_Msg_NE
("expect ordinary fixed point type in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Formal_Decimal_Fixed_Point_Definition =>
if not Is_Decimal_Fixed_Point_Type (Act_T) then
Error_Msg_NE
("expect decimal type in instantiation of &",
Actual, Gen_T);
Abandon_Instantiation (Actual);
end if;
when N_Array_Type_Definition =>
Validate_Array_Type_Instance;
when N_Access_To_Object_Definition =>
Validate_Access_Type_Instance;
when N_Access_Function_Definition |
N_Access_Procedure_Definition =>
Validate_Access_Subprogram_Instance;
when N_Record_Definition =>
Validate_Interface_Type_Instance;
when N_Derived_Type_Definition =>
Validate_Derived_Interface_Type_Instance;
when others =>
raise Program_Error;
end case;
Decl_Node :=
Make_Subtype_Declaration (Loc,
Defining_Identifier => New_Copy (Gen_T),
Subtype_Indication => New_Reference_To (Act_T, Loc));
if Is_Private_Type (Act_T) then
Set_Has_Private_View (Subtype_Indication (Decl_Node));
elsif Is_Access_Type (Act_T)
and then Is_Private_Type (Designated_Type (Act_T))
then
Set_Has_Private_View (Subtype_Indication (Decl_Node));
end if;
if Nkind (Def) = N_Formal_Derived_Type_Definition
or else Nkind (Def) = N_Formal_Private_Type_Definition
then
Set_Generic_Parent_Type (Decl_Node, Ancestor);
end if;
return Decl_Node;
end Instantiate_Type;
function Is_In_Main_Unit (N : Node_Id) return Boolean is
Unum : constant Unit_Number_Type := Get_Source_Unit (N);
Current_Unit : Node_Id;
begin
if Unum = Main_Unit then
return True;
elsif Nkind (N) = N_Compilation_Unit then
return Nkind (Unit (N)) = N_Subunit;
end if;
Current_Unit := Parent (N);
while Present (Current_Unit)
and then Nkind (Current_Unit) /= N_Compilation_Unit
loop
Current_Unit := Parent (Current_Unit);
end loop;
return Unum = Main_Unit
or else Current_Unit = Cunit (Main_Unit)
or else Current_Unit = Library_Unit (Cunit (Main_Unit))
or else (Present (Library_Unit (Current_Unit))
and then Is_In_Main_Unit (Library_Unit (Current_Unit)));
end Is_In_Main_Unit;
procedure Load_Parent_Of_Generic (N : Node_Id; Spec : Node_Id) is
Comp_Unit : constant Node_Id := Cunit (Get_Source_Unit (Spec));
Save_Style_Check : constant Boolean := Style_Check;
True_Parent : Node_Id;
Inst_Node : Node_Id;
OK : Boolean;
begin
if not In_Same_Source_Unit (N, Spec)
or else Nkind (Unit (Comp_Unit)) = N_Package_Declaration
or else (Nkind (Unit (Comp_Unit)) = N_Package_Body
and then not Is_In_Main_Unit (Spec))
then
True_Parent := Parent (Spec);
Inst_Node := Empty;
while Present (True_Parent)
and then Nkind (True_Parent) /= N_Compilation_Unit
loop
if Nkind (True_Parent) = N_Package_Declaration
and then
Nkind (Original_Node (True_Parent)) = N_Package_Instantiation
then
Inst_Node := Original_Node (True_Parent);
exit;
elsif Nkind (True_Parent) = N_Package_Declaration
and then Present (Generic_Parent (Specification (True_Parent)))
and then Nkind (Parent (True_Parent)) /= N_Compilation_Unit
then
Inst_Node := Next (True_Parent);
while Present (Inst_Node)
and then Nkind (Inst_Node) /= N_Package_Instantiation
loop
Next (Inst_Node);
end loop;
if No (Inst_Node) then
return;
end if;
exit;
else
True_Parent := Parent (True_Parent);
end if;
end loop;
if Present (Inst_Node) then
if Nkind (Parent (True_Parent)) = N_Compilation_Unit then
Set_Unit (Parent (True_Parent), Inst_Node);
end if;
if No (Corresponding_Body (Instance_Spec (Inst_Node))) then
declare
Exp_Status : Boolean := True;
Scop : Entity_Id;
begin
Scop := Scope (Defining_Entity (Instance_Spec (Inst_Node)));
while Present (Scop)
and then Scop /= Standard_Standard
loop
if Ekind (Scop) = E_Generic_Package then
Exp_Status := False;
exit;
end if;
Scop := Scope (Scop);
end loop;
Instantiate_Package_Body
(Pending_Body_Info'(
Inst_Node, True_Parent, Exp_Status,
Get_Code_Unit (Sloc (Inst_Node))));
end;
end if;
else
Opt.Style_Check := False;
Expander_Mode_Save_And_Set (True);
Load_Needed_Body (Comp_Unit, OK);
Opt.Style_Check := Save_Style_Check;
Expander_Mode_Restore;
if not OK
and then Unit_Requires_Body (Defining_Entity (Spec))
then
declare
Bname : constant Unit_Name_Type :=
Get_Body_Name (Get_Unit_Name (Unit (Comp_Unit)));
begin
Error_Msg_Unit_1 := Bname;
Error_Msg_N ("this instantiation requires$!", N);
Error_Msg_Name_1 :=
Get_File_Name (Bname, Subunit => False);
Error_Msg_N ("\but file{ was not found!", N);
raise Unrecoverable_Error;
end;
end if;
end if;
end if;
if Circularity_Detected then
raise Unrecoverable_Error;
end if;
end Load_Parent_Of_Generic;
procedure Move_Freeze_Nodes
(Out_Of : Entity_Id;
After : Node_Id;
L : List_Id)
is
Decl : Node_Id;
Next_Decl : Node_Id;
Next_Node : Node_Id := After;
Spec : Node_Id;
function Is_Outer_Type (T : Entity_Id) return Boolean;
function Is_Outer_Type (T : Entity_Id) return Boolean is
Scop : Entity_Id := Scope (T);
begin
if Scope_Depth (Scop) < Scope_Depth (Out_Of) then
return True;
else
while Scop /= Standard_Standard loop
if Scop = Out_Of then
return False;
else
Scop := Scope (Scop);
end if;
end loop;
return True;
end if;
end Is_Outer_Type;
begin
if No (L) then
return;
end if;
Decl := First (L);
while Present (Decl)
and then Nkind (Decl) = N_Freeze_Entity
and then Is_Outer_Type (Entity (Decl))
loop
Decl := Remove_Head (L);
Insert_After (Next_Node, Decl);
Set_Analyzed (Decl, False);
Next_Node := Decl;
Decl := First (L);
end loop;
while Present (Decl) loop
while Present (Next (Decl))
and then Nkind (Next (Decl)) = N_Freeze_Entity
and then Is_Outer_Type (Entity (Next (Decl)))
loop
Next_Decl := Remove_Next (Decl);
Insert_After (Next_Node, Next_Decl);
Set_Analyzed (Next_Decl, False);
Next_Node := Next_Decl;
end loop;
if Nkind (Decl) = N_Package_Declaration then
Spec := Specification (Decl);
elsif Nkind (Decl) = N_Task_Type_Declaration then
Spec := Task_Definition (Decl);
elsif Nkind (Decl) = N_Protected_Type_Declaration then
Spec := Protected_Definition (Decl);
else
Spec := Empty;
end if;
if Present (Spec) then
Move_Freeze_Nodes (Out_Of, Next_Node,
Visible_Declarations (Spec));
Move_Freeze_Nodes (Out_Of, Next_Node,
Private_Declarations (Spec));
end if;
Next (Decl);
end loop;
end Move_Freeze_Nodes;
function Next_Assoc (E : Assoc_Ptr) return Assoc_Ptr is
begin
return Generic_Renamings.Table (E).Next_In_HTable;
end Next_Assoc;
procedure Pre_Analyze_Actuals (N : Node_Id) is
Assoc : Node_Id;
Act : Node_Id;
Errs : constant Int := Serious_Errors_Detected;
begin
Assoc := First (Generic_Associations (N));
while Present (Assoc) loop
Act := Explicit_Generic_Actual_Parameter (Assoc);
if No (Act) then
null;
elsif Nkind (Act) = N_Attribute_Reference then
Analyze (Prefix (Act));
elsif Nkind (Act) = N_Explicit_Dereference then
Analyze (Prefix (Act));
elsif Nkind (Act) = N_Allocator then
declare
Expr : constant Node_Id := Expression (Act);
begin
if Nkind (Expr) = N_Subtype_Indication then
Analyze (Subtype_Mark (Expr));
Analyze_List (Constraints (Constraint (Expr)));
else
Analyze (Expr);
end if;
end;
elsif Nkind (Act) /= N_Operator_Symbol then
Analyze (Act);
end if;
if Errs /= Serious_Errors_Detected then
Abandon_Instantiation (Act);
end if;
Next (Assoc);
end loop;
end Pre_Analyze_Actuals;
procedure Remove_Parent (In_Body : Boolean := False) is
S : Entity_Id := Current_Scope;
E : Entity_Id;
P : Entity_Id;
Hidden : Elmt_Id;
begin
if not In_Body then
Pop_Scope;
while Current_Scope /= S loop
P := Current_Scope;
End_Package_Scope (Current_Scope);
if In_Open_Scopes (P) then
E := First_Entity (P);
while Present (E) loop
Set_Is_Immediately_Visible (E, True);
Next_Entity (E);
end loop;
if Is_Generic_Instance (Current_Scope)
and then P /= Current_Scope
then
Set_In_Private_Part (P);
Install_Private_Declarations (P);
end if;
elsif not In_Open_Scopes (Scope (P))
or else (P = Instance_Parent_Unit
and then not Parent_Unit_Visible)
then
Set_Is_Immediately_Visible (P, False);
end if;
end loop;
Set_Is_Hidden_Open_Scope (Current_Scope, False);
Hidden := First_Elmt (Hidden_Entities);
while Present (Hidden) loop
Set_Is_Immediately_Visible (Node (Hidden), True);
Next_Elmt (Hidden);
end loop;
else
while Present (S) loop
End_Package_Scope (S);
Set_Is_Immediately_Visible (S, False);
S := Current_Scope;
exit when S = Standard_Standard;
end loop;
end if;
end Remove_Parent;
procedure Restore_Env is
Saved : Instance_Env renames Instance_Envs.Table (Instance_Envs.Last);
begin
Ada_Version := Saved.Ada_Version;
Ada_Version_Explicit := Saved.Ada_Version_Explicit;
if No (Current_Instantiated_Parent.Act_Id) then
Restore_Private_Views (Empty);
end if;
Current_Instantiated_Parent := Saved.Instantiated_Parent;
Exchanged_Views := Saved.Exchanged_Views;
Hidden_Entities := Saved.Hidden_Entities;
Current_Sem_Unit := Saved.Current_Sem_Unit;
Parent_Unit_Visible := Saved.Parent_Unit_Visible;
Instance_Parent_Unit := Saved.Instance_Parent_Unit;
Instance_Envs.Decrement_Last;
end Restore_Env;
procedure Restore_Private_Views
(Pack_Id : Entity_Id;
Is_Package : Boolean := True)
is
M : Elmt_Id;
E : Entity_Id;
Typ : Entity_Id;
Dep_Elmt : Elmt_Id;
Dep_Typ : Node_Id;
procedure Restore_Nested_Formal (Formal : Entity_Id);
procedure Restore_Nested_Formal (Formal : Entity_Id) is
Ent : Entity_Id;
begin
if Present (Renamed_Object (Formal))
and then Denotes_Formal_Package (Renamed_Object (Formal), True)
then
return;
elsif Present (Associated_Formal_Package (Formal))
and then Box_Present (Parent (Associated_Formal_Package (Formal)))
then
Ent := First_Entity (Formal);
while Present (Ent) loop
exit when Ekind (Ent) = E_Package
and then Renamed_Entity (Ent) = Renamed_Entity (Formal);
Set_Is_Hidden (Ent);
Set_Is_Potentially_Use_Visible (Ent, False);
if Ekind (Ent) = E_Package then
Restore_Nested_Formal (Ent);
end if;
Next_Entity (Ent);
end loop;
end if;
end Restore_Nested_Formal;
begin
M := First_Elmt (Exchanged_Views);
while Present (M) loop
Typ := Node (M);
if Ekind (Typ) = E_Private_Type
or else Ekind (Typ) = E_Limited_Private_Type
or else Ekind (Typ) = E_Record_Type_With_Private
then
Dep_Elmt := First_Elmt (Private_Dependents (Typ));
while Present (Dep_Elmt) loop
Dep_Typ := Node (Dep_Elmt);
if Scope (Dep_Typ) = Pack_Id
and then Present (Full_View (Dep_Typ))
then
Replace_Elmt (Dep_Elmt, Full_View (Dep_Typ));
Exchange_Declarations (Dep_Typ);
end if;
Next_Elmt (Dep_Elmt);
end loop;
end if;
Exchange_Declarations (Node (M));
Next_Elmt (M);
end loop;
if No (Pack_Id) then
return;
end if;
E := First_Entity (Pack_Id);
while Present (E) loop
Set_Is_Hidden (E, True);
if Is_Type (E)
and then Nkind (Parent (E)) = N_Subtype_Declaration
then
Set_Is_Generic_Actual_Type (E, False);
if Is_Private_Type (E)
and then not Is_Private_Type (Etype (E))
then
Exchange_Declarations (E);
end if;
elsif Ekind (E) = E_Package then
if Is_Package
and then Renamed_Object (E) = Pack_Id
then
exit;
elsif Nkind (Parent (E)) /= N_Package_Renaming_Declaration then
null;
elsif Denotes_Formal_Package (Renamed_Object (E), True) then
Set_Is_Hidden (E, False);
else
declare
Act_P : constant Entity_Id := Renamed_Object (E);
Id : Entity_Id;
begin
Id := First_Entity (Act_P);
while Present (Id)
and then Id /= First_Private_Entity (Act_P)
loop
exit when Ekind (Id) = E_Package
and then Renamed_Object (Id) = Act_P;
Set_Is_Hidden (Id, True);
Set_Is_Potentially_Use_Visible (Id, In_Use (Act_P));
if Ekind (Id) = E_Package then
Restore_Nested_Formal (Id);
end if;
Next_Entity (Id);
end loop;
end;
end if;
end if;
Next_Entity (E);
end loop;
end Restore_Private_Views;
procedure Save_Env
(Gen_Unit : Entity_Id;
Act_Unit : Entity_Id)
is
begin
Init_Env;
Set_Instance_Env (Gen_Unit, Act_Unit);
end Save_Env;
procedure Save_Global_References (N : Node_Id) is
Gen_Scope : Entity_Id;
E : Entity_Id;
N2 : Node_Id;
function Is_Global (E : Entity_Id) return Boolean;
procedure Reset_Entity (N : Node_Id);
procedure Save_Entity_Descendants (N : Node_Id);
procedure Save_Global_Defaults (N1, N2 : Node_Id);
procedure Save_Global_Descendant (D : Union_Id);
procedure Save_References (N : Node_Id);
function Is_Global (E : Entity_Id) return Boolean is
Se : Entity_Id := Scope (E);
function Is_Instance_Node (Decl : Node_Id) return Boolean;
function Is_Instance_Node (Decl : Node_Id) return Boolean is
begin
return (Nkind (Decl) in N_Generic_Instantiation
or else
Nkind (Original_Node (Decl)) = N_Formal_Package_Declaration);
end Is_Instance_Node;
begin
if E = Gen_Scope then
return False;
elsif E = Standard_Standard then
return True;
elsif Is_Child_Unit (E)
and then (Is_Instance_Node (Parent (N2))
or else (Nkind (Parent (N2)) = N_Expanded_Name
and then N2 = Selector_Name (Parent (N2))
and then Is_Instance_Node (Parent (Parent (N2)))))
then
return True;
else
while Se /= Gen_Scope loop
if Se = Standard_Standard then
return True;
else
Se := Scope (Se);
end if;
end loop;
return False;
end if;
end Is_Global;
procedure Reset_Entity (N : Node_Id) is
procedure Set_Global_Type (N : Node_Id; N2 : Node_Id);
function Top_Ancestor (E : Entity_Id) return Entity_Id;
procedure Set_Global_Type (N : Node_Id; N2 : Node_Id) is
Typ : constant Entity_Id := Etype (N2);
begin
Set_Etype (N, Typ);
if Entity (N) /= N2
and then Has_Private_View (Entity (N))
then
Set_Has_Private_View (N);
end if;
if not Is_Private_Type (Typ) then
if Is_Array_Type (Typ)
and then Is_Private_Type (Component_Type (Typ))
then
Set_Has_Private_View (N);
end if;
elsif No (Full_View (Typ)) and then Typ /= Etype (Typ) then
null;
else
Set_Has_Private_View (N);
if Present (Full_View (Typ)) then
Set_Etype (N2, Full_View (Typ));
end if;
end if;
end Set_Global_Type;
function Top_Ancestor (E : Entity_Id) return Entity_Id is
Par : Entity_Id := E;
begin
while Is_Child_Unit (Par) loop
Par := Scope (Par);
end loop;
return Par;
end Top_Ancestor;
begin
N2 := Get_Associated_Node (N);
E := Entity (N2);
if Present (E) then
if Is_Global (E) then
Set_Global_Type (N, N2);
elsif Nkind (N) = N_Op_Concat
and then Is_Generic_Type (Etype (N2))
and then
(Base_Type (Etype (Right_Opnd (N2))) = Etype (N2)
or else Base_Type (Etype (Left_Opnd (N2))) = Etype (N2))
and then Is_Intrinsic_Subprogram (E)
then
null;
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
if Nkind (Parent (N)) in N_Generic_Instantiation
and then N = Name (Parent (N))
then
Save_Global_Defaults (Parent (N), Parent (N2));
end if;
elsif Nkind (Parent (N)) = N_Selected_Component
and then Nkind (Parent (N2)) = N_Expanded_Name
then
if Is_Global (Entity (Parent (N2))) then
Change_Selected_Component_To_Expanded_Name (Parent (N));
Set_Associated_Node (Parent (N), Parent (N2));
Set_Global_Type (Parent (N), Parent (N2));
Save_Entity_Descendants (N);
elsif In_Open_Scopes (Entity (Parent (N2)))
and then not
Is_Generic_Unit (Top_Ancestor (Entity (Prefix (Parent (N2)))))
then
if Ekind (Entity (Parent (N2))) = E_Generic_Package then
Rewrite (Parent (N),
Make_Identifier (Sloc (N),
Chars =>
Chars (Generic_Homonym (Entity (Parent (N2))))));
else
Rewrite (Parent (N),
Make_Identifier (Sloc (N),
Chars => Chars (Selector_Name (Parent (N2)))));
end if;
end if;
if Nkind (Parent (Parent (N))) in N_Generic_Instantiation
and then Parent (N) = Name (Parent (Parent (N)))
then
Save_Global_Defaults
(Parent (Parent (N)), Parent (Parent ((N2))));
end if;
elsif Nkind (Parent (N)) = N_Selected_Component
and then (Nkind (Parent (N2)) = N_Integer_Literal
or else Nkind (Parent (N2)) = N_Real_Literal)
then
Rewrite (Parent (N),
New_Copy (Parent (N2)));
Set_Analyzed (Parent (N), False);
elsif Nkind (Parent (N)) = N_Selected_Component
and then Nkind (Parent (N2)) = N_Function_Call
and then Is_Global (Entity (Name (Parent (N2))))
then
Change_Selected_Component_To_Expanded_Name (Parent (N));
Set_Associated_Node (Parent (N), Name (Parent (N2)));
Set_Global_Type (Parent (N), Name (Parent (N2)));
Save_Entity_Descendants (N);
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
end Reset_Entity;
procedure Save_Entity_Descendants (N : Node_Id) is
begin
case Nkind (N) is
when N_Binary_Op =>
Save_Global_Descendant (Union_Id (Left_Opnd (N)));
Save_Global_Descendant (Union_Id (Right_Opnd (N)));
when N_Unary_Op =>
Save_Global_Descendant (Union_Id (Right_Opnd (N)));
when N_Expanded_Name | N_Selected_Component =>
Save_Global_Descendant (Union_Id (Prefix (N)));
Save_Global_Descendant (Union_Id (Selector_Name (N)));
when N_Identifier | N_Character_Literal | N_Operator_Symbol =>
null;
when others =>
raise Program_Error;
end case;
end Save_Entity_Descendants;
procedure Save_Global_Defaults (N1, N2 : Node_Id) is
Loc : constant Source_Ptr := Sloc (N1);
Assoc2 : constant List_Id := Generic_Associations (N2);
Gen_Id : constant Entity_Id := Get_Generic_Entity (N2);
Assoc1 : List_Id;
Act1 : Node_Id;
Act2 : Node_Id;
Def : Node_Id;
Ndec : Node_Id;
Subp : Entity_Id;
Actual : Entity_Id;
begin
Assoc1 := Generic_Associations (N1);
if Present (Assoc1) then
Act1 := First (Assoc1);
else
Act1 := Empty;
Set_Generic_Associations (N1, New_List);
Assoc1 := Generic_Associations (N1);
end if;
if Present (Assoc2) then
Act2 := First (Assoc2);
else
return;
end if;
while Present (Act1) and then Present (Act2) loop
Next (Act1);
Next (Act2);
end loop;
if Present (Act2) then
while Nkind (Act2) /= N_Generic_Association
or else No (Entity (Selector_Name (Act2)))
or else not Is_Overloadable (Entity (Selector_Name (Act2)))
loop
Next (Act2);
end loop;
while Present (Act2) loop
Subp := Entity (Selector_Name (Act2));
Def := Explicit_Generic_Actual_Parameter (Act2);
if No (Alias (Subp)) then
return;
end if;
Actual := Entity (Name (Parent (Parent (Subp))));
Set_Entity (Def, Actual);
Set_Etype (Def, Etype (Actual));
if Is_Global (Actual) then
Ndec :=
Make_Generic_Association (Loc,
Selector_Name => New_Occurrence_Of (Subp, Loc),
Explicit_Generic_Actual_Parameter =>
New_Occurrence_Of (Actual, Loc));
Set_Associated_Node
(Explicit_Generic_Actual_Parameter (Ndec), Def);
Append (Ndec, Assoc1);
elsif Present (Next (Act2)) then
Ndec :=
Make_Generic_Association (Loc,
Selector_Name => New_Occurrence_Of (Subp, Loc),
Explicit_Generic_Actual_Parameter => Empty);
Append (Ndec, Assoc1);
end if;
Next (Act2);
end loop;
end if;
if Nkind (Name (N1)) = N_Identifier
and then Is_Child_Unit (Gen_Id)
and then Is_Global (Gen_Id)
and then Is_Generic_Unit (Scope (Gen_Id))
and then In_Open_Scopes (Scope (Gen_Id))
then
Rewrite (Name (N2),
Make_Expanded_Name (Loc,
Chars => Chars (Gen_Id),
Prefix => New_Occurrence_Of (Scope (Gen_Id), Loc),
Selector_Name => New_Occurrence_Of (Gen_Id, Loc)));
Set_Entity (Name (N2), Gen_Id);
Rewrite (Name (N1),
Make_Expanded_Name (Loc,
Chars => Chars (Gen_Id),
Prefix => New_Occurrence_Of (Scope (Gen_Id), Loc),
Selector_Name => New_Occurrence_Of (Gen_Id, Loc)));
Set_Associated_Node (Name (N1), Name (N2));
Set_Associated_Node (Prefix (Name (N1)), Empty);
Set_Associated_Node
(Selector_Name (Name (N1)), Selector_Name (Name (N2)));
Set_Etype (Name (N1), Etype (Gen_Id));
end if;
end Save_Global_Defaults;
procedure Save_Global_Descendant (D : Union_Id) is
N1 : Node_Id;
begin
if D in Node_Range then
if D = Union_Id (Empty) then
null;
elsif Nkind (Node_Id (D)) /= N_Compilation_Unit then
Save_References (Node_Id (D));
end if;
elsif D in List_Range then
if D = Union_Id (No_List)
or else Is_Empty_List (List_Id (D))
then
null;
else
N1 := First (List_Id (D));
while Present (N1) loop
Save_References (N1);
Next (N1);
end loop;
end if;
else
null;
end if;
end Save_Global_Descendant;
procedure Save_References (N : Node_Id) is
begin
if N = Empty then
null;
elsif Nkind (N) = N_Character_Literal
or else Nkind (N) = N_Operator_Symbol
then
if Nkind (N) = Nkind (Get_Associated_Node (N)) then
Reset_Entity (N);
elsif Nkind (N) = N_Operator_Symbol
and then Nkind (Get_Associated_Node (N)) = N_String_Literal
then
Change_Operator_Symbol_To_String_Literal (N);
end if;
elsif Nkind (N) in N_Op then
if Nkind (N) = Nkind (Get_Associated_Node (N)) then
if Nkind (N) = N_Op_Concat then
Set_Is_Component_Left_Opnd (N,
Is_Component_Left_Opnd (Get_Associated_Node (N)));
Set_Is_Component_Right_Opnd (N,
Is_Component_Right_Opnd (Get_Associated_Node (N)));
end if;
Reset_Entity (N);
else
N2 := Get_Associated_Node (N);
if Nkind (N2) = N_Function_Call then
E := Entity (Name (N2));
if Present (E)
and then Is_Global (E)
then
Set_Etype (N, Etype (N2));
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
elsif Nkind (N2) = N_Integer_Literal
or else Nkind (N2) = N_Real_Literal
or else Nkind (N2) = N_String_Literal
then
Rewrite (N, New_Copy (N2));
Set_Analyzed (N, False);
elsif Nkind (N2) = N_Identifier
and then Ekind (Entity (N2)) = E_Enumeration_Literal
then
Rewrite (N, New_Copy (N2));
Set_Analyzed (N, False);
end if;
end if;
if Nkind (N) in N_Op then
Save_Entity_Descendants (N);
end if;
elsif Nkind (N) = N_Identifier then
if Nkind (N) = Nkind (Get_Associated_Node (N)) then
Set_Original_Discriminant
(N, Original_Discriminant (Get_Associated_Node (N)));
Reset_Entity (N);
else
N2 := Get_Associated_Node (N);
if Nkind (N2) = N_Function_Call then
E := Entity (Name (N2));
if Present (E)
and then Is_Global (E)
then
Set_Etype (N, Etype (N2));
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
elsif
Nkind (N2) = N_Integer_Literal or else
Nkind (N2) = N_Real_Literal or else
Nkind (N2) = N_String_Literal
then
Rewrite (N, New_Copy (N2));
Set_Analyzed (N, False);
elsif Nkind (N2) = N_Explicit_Dereference then
if Is_Entity_Name (Prefix (N2))
and then Present (Entity (Prefix (N2)))
and then Is_Global (Entity (Prefix (N2)))
then
Rewrite (N,
Make_Explicit_Dereference (Sloc (N),
Prefix => Make_Identifier (Sloc (N),
Chars => Chars (N))));
Set_Associated_Node (Prefix (N), Prefix (N2));
elsif Nkind (Prefix (N2)) = N_Function_Call
and then Is_Global (Entity (Name (Prefix (N2))))
then
Rewrite (N,
Make_Explicit_Dereference (Sloc (N),
Prefix => Make_Function_Call (Sloc (N),
Name =>
Make_Identifier (Sloc (N),
Chars => Chars (N)))));
Set_Associated_Node
(Name (Prefix (N)), Name (Prefix (N2)));
else
Set_Associated_Node (N, Empty);
Set_Etype (N, Empty);
end if;
elsif Nkind (N2) = N_Subtype_Indication
and then Is_Entity_Name (Original_Node (N2))
then
Set_Associated_Node (N, Original_Node (N2));
Reset_Entity (N);
else
null;
end if;
end if;
elsif Nkind (N) in N_Entity then
null;
else
declare
Loc : constant Source_Ptr := Sloc (N);
Qual : Node_Id := Empty;
Typ : Entity_Id := Empty;
Nam : Node_Id;
use Atree.Unchecked_Access;
begin
if Nkind (N) = N_Aggregate
or else
Nkind (N) = N_Extension_Aggregate
then
N2 := Get_Associated_Node (N);
if No (N2) then
Typ := Empty;
else
Typ := Etype (N2);
if Nkind (Parent (Typ)) = N_Subtype_Declaration
and then
Present (Generic_Parent_Type (Parent (Typ)))
then
Typ := Base_Type (Typ);
Set_Etype (N2, Typ);
end if;
end if;
if No (N2)
or else No (Typ)
or else not Is_Global (Typ)
then
Set_Associated_Node (N, Empty);
if Nkind (N2) = Nkind (N)
and then
(Nkind (Parent (N2)) = N_Procedure_Call_Statement
or else Nkind (Parent (N2)) = N_Function_Call)
and then Comes_From_Source (Typ)
then
if Is_Immediately_Visible (Scope (Typ)) then
Nam := Make_Selected_Component (Loc,
Prefix =>
Make_Identifier (Loc, Chars (Scope (Typ))),
Selector_Name =>
Make_Identifier (Loc, Chars (Typ)));
else
Nam := Make_Identifier (Loc, Chars (Typ));
end if;
Qual :=
Make_Qualified_Expression (Loc,
Subtype_Mark => Nam,
Expression => Relocate_Node (N));
end if;
end if;
Save_Global_Descendant (Field1 (N));
Save_Global_Descendant (Field2 (N));
Save_Global_Descendant (Field3 (N));
Save_Global_Descendant (Field5 (N));
if Present (Qual) then
Rewrite (N, Qual);
end if;
else
Save_Global_Descendant (Field1 (N));
Save_Global_Descendant (Field2 (N));
Save_Global_Descendant (Field3 (N));
Save_Global_Descendant (Field4 (N));
Save_Global_Descendant (Field5 (N));
end if;
end;
end if;
end Save_References;
begin
Gen_Scope := Current_Scope;
while Is_Child_Unit (Gen_Scope)
and then Ekind (Scope (Gen_Scope)) = E_Generic_Package
loop
Gen_Scope := Scope (Gen_Scope);
end loop;
Save_References (N);
end Save_Global_References;
procedure Set_Copied_Sloc_For_Inlined_Body (N : Node_Id; E : Entity_Id) is
begin
Create_Instantiation_Source (N, E, True, S_Adjustment);
end Set_Copied_Sloc_For_Inlined_Body;
procedure Set_Instance_Of (A : Entity_Id; B : Entity_Id) is
begin
Generic_Renamings.Table (Generic_Renamings.Last) := (A, B, Assoc_Null);
Generic_Renamings_HTable.Set (Generic_Renamings.Last);
Generic_Renamings.Increment_Last;
end Set_Instance_Of;
procedure Set_Next_Assoc (E : Assoc_Ptr; Next : Assoc_Ptr) is
begin
Generic_Renamings.Table (E).Next_In_HTable := Next;
end Set_Next_Assoc;
procedure Start_Generic is
begin
Generic_Flags.Increment_Last;
Generic_Flags.Table (Generic_Flags.Last) := Inside_A_Generic;
Inside_A_Generic := True;
Expander_Mode_Save_And_Set (False);
end Start_Generic;
procedure Set_Instance_Env
(Gen_Unit : Entity_Id;
Act_Unit : Entity_Id)
is
begin
if Is_Internal_File_Name
(Fname => Unit_File_Name (Get_Source_Unit (Gen_Unit)),
Renamings_Included => True) then
Ada_Version := Ada_Version_Type'Last;
end if;
Current_Instantiated_Parent := (Gen_Unit, Act_Unit, Assoc_Null);
end Set_Instance_Env;
procedure Switch_View (T : Entity_Id) is
BT : constant Entity_Id := Base_Type (T);
Priv_Elmt : Elmt_Id := No_Elmt;
Priv_Sub : Entity_Id;
begin
if not Is_Private_Type (BT) then
return;
end if;
Priv_Elmt := First_Elmt (Private_Dependents (BT));
if Present (Full_View (BT)) then
Prepend_Elmt (Full_View (BT), Exchanged_Views);
Exchange_Declarations (BT);
end if;
while Present (Priv_Elmt) loop
Priv_Sub := (Node (Priv_Elmt));
if Present (Full_View (Priv_Sub))
and then not Is_Private_Type (Etype (Full_View (Priv_Sub)))
then
Prepend_Elmt (Full_View (Priv_Sub), Exchanged_Views);
Exchange_Declarations (Priv_Sub);
end if;
Next_Elmt (Priv_Elmt);
end loop;
end Switch_View;
procedure Valid_Default_Attribute (Nam : Entity_Id; Def : Node_Id) is
Attr_Id : constant Attribute_Id :=
Get_Attribute_Id (Attribute_Name (Def));
T : constant Entity_Id := Entity (Prefix (Def));
Is_Fun : constant Boolean := (Ekind (Nam) = E_Function);
F : Entity_Id;
Num_F : Int;
OK : Boolean;
begin
if No (T)
or else T = Any_Id
then
return;
end if;
Num_F := 0;
F := First_Formal (Nam);
while Present (F) loop
Num_F := Num_F + 1;
Next_Formal (F);
end loop;
case Attr_Id is
when Attribute_Adjacent | Attribute_Ceiling | Attribute_Copy_Sign |
Attribute_Floor | Attribute_Fraction | Attribute_Machine |
Attribute_Model | Attribute_Remainder | Attribute_Rounding |
Attribute_Unbiased_Rounding =>
OK := Is_Fun
and then Num_F = 1
and then Is_Floating_Point_Type (T);
when Attribute_Image | Attribute_Pred | Attribute_Succ |
Attribute_Value | Attribute_Wide_Image |
Attribute_Wide_Value =>
OK := (Is_Fun and then Num_F = 1 and then Is_Scalar_Type (T));
when Attribute_Max | Attribute_Min =>
OK := (Is_Fun and then Num_F = 2 and then Is_Scalar_Type (T));
when Attribute_Input =>
OK := (Is_Fun and then Num_F = 1);
when Attribute_Output | Attribute_Read | Attribute_Write =>
OK := (not Is_Fun and then Num_F = 2);
when others =>
OK := False;
end case;
if not OK then
Error_Msg_N ("attribute reference has wrong profile for subprogram",
Def);
end if;
end Valid_Default_Attribute;
end Sem_Ch12;