with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Errout; use Errout;
with Exp_Util; use Exp_Util;
with Fname; use Fname;
with Fname.UF; use Fname.UF;
with Freeze; use Freeze;
with Impunit; use Impunit;
with Inline; use Inline;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Lib.Xref; use Lib.Xref;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Dist; use Sem_Dist;
with Sem_Prag; use Sem_Prag;
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 Snames; use Snames;
with Style; use Style;
with Stylesw; use Stylesw;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uname; use Uname;
package body Sem_Ch10 is
procedure Analyze_Context (N : Node_Id);
procedure Build_Limited_Views (N : Node_Id);
procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id);
procedure Check_With_Type_Clauses (N : Node_Id);
procedure Check_Private_Child_Unit (N : Node_Id);
procedure Check_Stub_Level (N : Node_Id);
procedure Expand_Limited_With_Clause (Nam : Node_Id; N : Node_Id);
procedure Expand_With_Clause (Nam : Node_Id; N : Node_Id);
function Get_Parent_Entity (Unit : Node_Id) return Entity_Id;
procedure Implicit_With_On_Parent (Child_Unit : Node_Id; N : Node_Id);
procedure Install_Context_Clauses (N : Node_Id);
procedure Install_Limited_Context_Clauses (N : Node_Id);
procedure Install_Limited_Withed_Unit (N : Node_Id);
procedure Install_Withed_Unit
(With_Clause : Node_Id;
Private_With_OK : Boolean := False);
procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean);
procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id);
function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean;
procedure Remove_With_Type_Clause (Name : Node_Id);
procedure Remove_Context_Clauses (N : Node_Id);
procedure Remove_Limited_With_Clause (N : Node_Id);
procedure Remove_Parents (Lib_Unit : Node_Id);
procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id);
procedure Unchain (E : Entity_Id);
procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id);
procedure Analyze_Compilation_Unit (N : Node_Id) is
Unit_Node : constant Node_Id := Unit (N);
Lib_Unit : Node_Id := Library_Unit (N);
Spec_Id : Node_Id;
Main_Cunit : constant Node_Id := Cunit (Main_Unit);
Par_Spec_Name : Unit_Name_Type;
Unum : Unit_Number_Type;
procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id);
procedure Generate_Parent_References (N : Node_Id; P_Id : Entity_Id) is
Pref : Node_Id;
P_Name : Entity_Id := P_Id;
begin
Pref := Name (Parent (Defining_Entity (N)));
if Nkind (Pref) = N_Expanded_Name then
return;
end if;
while Nkind (Pref) = N_Selected_Component loop
Change_Selected_Component_To_Expanded_Name (Pref);
Set_Entity (Pref, P_Name);
Set_Etype (Pref, Etype (P_Name));
Generate_Reference (P_Name, Pref, 'r');
Pref := Prefix (Pref);
P_Name := Scope (P_Name);
end loop;
if Present (P_Name) then
Set_Entity (Pref, P_Name);
Set_Etype (Pref, Etype (P_Name));
Generate_Reference (P_Name, Pref, 'r');
Style.Check_Identifier (Pref, P_Name);
end if;
end Generate_Parent_References;
begin
Process_Compilation_Unit_Pragmas (N);
if Nkind (Unit_Node) = N_Subunit
and then not Analyzed (Lib_Unit)
then
Semantics (Lib_Unit);
if not Analyzed (Proper_Body (Unit_Node)) then
if Serious_Errors_Detected > 0 then
Error_Msg_N ("subunit not analyzed (errors in parent unit)", N);
else
Error_Msg_N ("missing stub for subunit", N);
end if;
end if;
return;
end if;
Analyze_Context (N);
if Nkind (Unit_Node) = N_Package_Body then
if No (Lib_Unit) then
return;
else
Semantics (Lib_Unit);
Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
if Nkind (Unit (Lib_Unit)) /= N_Package_Declaration
and then
Nkind (Unit (Lib_Unit)) /= N_Generic_Package_Declaration
then
Error_Msg_N
("no legal package declaration for package body", N);
return;
else
Spec_Id := Defining_Entity (Unit (Lib_Unit));
Set_Is_Immediately_Visible (Spec_Id, True);
Version_Update (N, Lib_Unit);
if Nkind (Defining_Unit_Name (Unit_Node))
= N_Defining_Program_Unit_Name
then
Generate_Parent_References (Unit_Node, Scope (Spec_Id));
end if;
end if;
end if;
elsif Nkind (Unit_Node) = N_Subprogram_Body then
if Acts_As_Spec (N) then
Unum := Get_Cunit_Unit_Number (N);
Par_Spec_Name := Get_Parent_Spec_Name (Unit_Name (Unum));
if Par_Spec_Name /= No_Name then
Unum :=
Load_Unit
(Load_Name => Par_Spec_Name,
Required => True,
Subunit => False,
Error_Node => N);
if Unum /= No_Unit then
declare
Loc : constant Source_Ptr := Sloc (N);
SCS : constant Boolean :=
Get_Comes_From_Source_Default;
begin
Set_Comes_From_Source_Default (False);
Lib_Unit :=
Make_Compilation_Unit (Loc,
Context_Items => New_Copy_List (Context_Items (N)),
Unit =>
Make_Subprogram_Declaration (Sloc (N),
Specification =>
Copy_Separate_Tree
(Specification (Unit_Node))),
Aux_Decls_Node =>
Make_Compilation_Unit_Aux (Loc));
Set_Library_Unit (N, Lib_Unit);
Set_Parent_Spec (Unit (Lib_Unit), Cunit (Unum));
Semantics (Lib_Unit);
Set_Acts_As_Spec (N, False);
Set_Needs_Debug_Info (Defining_Entity (Unit (Lib_Unit)));
Set_Comes_From_Source_Default (SCS);
end;
end if;
end if;
else
Semantics (Lib_Unit);
Check_Unused_Withs (Get_Cunit_Unit_Number (Lib_Unit));
Version_Update (N, Lib_Unit);
end if;
if Nkind (Defining_Unit_Name (Specification (Unit_Node))) =
N_Defining_Program_Unit_Name
then
Generate_Parent_References (
Specification (Unit_Node),
Scope (Defining_Entity (Unit (Lib_Unit))));
end if;
end if;
if Is_Child_Spec (Unit_Node) then
declare
Save_Style_Check : constant Boolean := Style_Check;
Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
Cunit_Boolean_Restrictions_Save;
begin
if not GNAT_Mode then
Style_Check := False;
end if;
Semantics (Parent_Spec (Unit_Node));
Version_Update (N, Parent_Spec (Unit_Node));
Style_Check := Save_Style_Check;
Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
end;
end if;
Install_Context (N);
if Is_Child_Spec (Unit_Node) then
Generate_Parent_References (
Unit_Node, Get_Parent_Entity (Unit (Parent_Spec (Unit_Node))));
end if;
Analyze (Unit_Node);
if Nkind (Unit_Node) = N_Subprogram_Body
and then Acts_As_Spec (Unit_Node)
then
Set_Acts_As_Spec (N);
end if;
declare
Unum : constant Unit_Number_Type := Get_Source_Unit (Sloc (N));
begin
if Is_Predefined_File_Name (Unit_File_Name (Unum)) then
Set_RTU_Loaded (Unit_Node);
end if;
end;
if Present (Pragmas_After (Aux_Decls_Node (N))) then
declare
Prag_Node : Node_Id := First (Pragmas_After (Aux_Decls_Node (N)));
begin
while Present (Prag_Node) loop
Analyze (Prag_Node);
Next (Prag_Node);
end loop;
end;
end if;
if N = Main_Cunit
and then (Distribution_Stub_Mode = Generate_Receiver_Stub_Body
or else
Distribution_Stub_Mode = Generate_Caller_Stub_Body)
and then not Fatal_Error (Main_Unit)
then
if Is_RCI_Pkg_Spec_Or_Body (N) then
Add_Stub_Constructs (N);
elsif (Nkind (Unit_Node) = N_Package_Declaration
and then Is_Shared_Passive (Defining_Entity
(Specification (Unit_Node))))
or else (Nkind (Unit_Node) = N_Package_Body
and then
Is_Shared_Passive (Corresponding_Spec (Unit_Node)))
then
Add_Stub_Constructs (N);
elsif Nkind (Unit_Node) = N_Package_Instantiation
and then
Is_Remote_Call_Interface
(Defining_Entity (Specification (Instance_Spec (Unit_Node))))
then
Add_Stub_Constructs (N);
end if;
end if;
if Nkind (Unit_Node) = N_Package_Declaration
or else Nkind (Unit_Node) in N_Generic_Declaration
or else Nkind (Unit_Node) = N_Package_Renaming_Declaration
or else Nkind (Unit_Node) = N_Subprogram_Declaration
then
Remove_Unit_From_Visibility (Defining_Entity (Unit_Node));
elsif Nkind (Unit_Node) = N_Package_Instantiation
and then not Error_Posted (Unit_Node)
then
Remove_Unit_From_Visibility
(Defining_Entity (Instance_Spec (Unit_Node)));
elsif Nkind (Unit_Node) = N_Package_Body
or else (Nkind (Unit_Node) = N_Subprogram_Body
and then not Acts_As_Spec (Unit_Node))
then
Remove_Context (Lib_Unit);
Set_Is_Immediately_Visible (Defining_Entity (Unit (Lib_Unit)), False);
end if;
Remove_Context (N);
if Get_Cunit_Unit_Number (N) = Main_Unit
and then Operating_Mode = Generate_Code
and then Expander_Active
then
Check_Body_Needed_For_SAL (Cunit_Entity (Main_Unit));
Set_Analyzed (N, True);
Set_Is_Immediately_Visible (Cunit_Entity (Main_Unit), False);
declare
Item : Node_Id;
Nam : Entity_Id;
Un : Unit_Number_Type;
Save_Style_Check : constant Boolean := Style_Check;
Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
Cunit_Boolean_Restrictions_Save;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Implicit_With (Item)
and then not Limited_Present (Item)
then
Nam := Entity (Name (Item));
if (Is_Generic_Subprogram (Nam)
and then not Is_Intrinsic_Subprogram (Nam))
or else (Ekind (Nam) = E_Generic_Package
and then Unit_Requires_Body (Nam))
then
Style_Check := False;
if Present (Renamed_Object (Nam)) then
Un :=
Load_Unit
(Load_Name => Get_Body_Name
(Get_Unit_Name
(Unit_Declaration_Node
(Renamed_Object (Nam)))),
Required => False,
Subunit => False,
Error_Node => N,
Renamings => True);
else
Un :=
Load_Unit
(Load_Name => Get_Body_Name
(Get_Unit_Name (Item)),
Required => False,
Subunit => False,
Error_Node => N,
Renamings => True);
end if;
if Un = No_Unit then
Error_Msg_NE
("body of generic unit& not found", Item, Nam);
exit;
elsif not Analyzed (Cunit (Un))
and then Un /= Main_Unit
and then not Fatal_Error (Un)
then
Style_Check := False;
Semantics (Cunit (Un));
end if;
end if;
end if;
Next (Item);
end loop;
Style_Check := Save_Style_Check;
Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
end;
end if;
if Comes_From_Source (N)
and then
(Nkind (Unit (N)) = N_Package_Declaration or else
Nkind (Unit (N)) = N_Generic_Package_Declaration or else
Nkind (Unit (N)) = N_Subprogram_Declaration or else
Nkind (Unit (N)) = N_Generic_Subprogram_Declaration)
then
declare
Loc : constant Source_Ptr := Sloc (N);
Unum : constant Unit_Number_Type := Get_Source_Unit (Loc);
begin
Spec_Id := Defining_Entity (Unit (N));
Generate_Definition (Spec_Id);
if
Is_Pure (Spec_Id)
or else Is_Preelaborated (Spec_Id)
or else Has_Pragma_Elaborate_Body (Spec_Id)
or else not Unit_Requires_Body (Spec_Id)
or else Is_Predefined_File_Name (Unit_File_Name (Unum))
or else Acts_As_Spec (N)
then
Set_Elaboration_Entity_Required (Spec_Id, False);
else
Set_Elaboration_Entity_Required (Spec_Id, True);
end if;
Build_Elaboration_Entity (N, Spec_Id);
end;
end if;
declare
Loc : constant Source_Ptr := Sloc (N);
L : constant List_Id :=
Freeze_Entity (Cunit_Entity (Current_Sem_Unit), Loc);
begin
while Is_Non_Empty_List (L) loop
Insert_Library_Level_Action (Remove_Head (L));
end loop;
end;
Set_Analyzed (N);
if Nkind (Unit_Node) = N_Package_Declaration
and then Get_Cunit_Unit_Number (N) /= Main_Unit
and then Expander_Active
then
declare
Save_Style_Check : constant Boolean := Style_Check;
Save_Warning : constant Warning_Mode_Type := Warning_Mode;
Options : Style_Check_Options;
begin
Save_Style_Check_Options (Options);
Reset_Style_Check_Options;
Opt.Warning_Mode := Suppress;
Check_Body_For_Inlining (N, Defining_Entity (Unit_Node));
Reset_Style_Check_Options;
Set_Style_Check_Options (Options);
Style_Check := Save_Style_Check;
Warning_Mode := Save_Warning;
end;
end if;
end Analyze_Compilation_Unit;
procedure Analyze_Context (N : Node_Id) is
Item : Node_Id;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Limited_Present (Item)
then
if Present (Library_Unit (Item)) then
Analyze (Item);
end if;
if not Implicit_With (Item) then
Version_Update (N, Library_Unit (Item));
end if;
else
null;
end if;
Next (Item);
end loop;
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
and then Nkind (Name (Item)) = N_Selected_Component
then
Expand_Limited_With_Clause
(Nam => Prefix (Name (Item)), N => Item);
end if;
Next (Item);
end loop;
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
then
if Nkind (Unit (N)) /= N_Package_Declaration then
Error_Msg_N ("limited with_clause only allowed in"
& " package specification", Item);
end if;
if Present (Library_Unit (Item)) then
Analyze (Item);
end if;
if not Implicit_With (Item) then
Version_Update (N, Library_Unit (Item));
end if;
end if;
Next (Item);
end loop;
end Analyze_Context;
procedure Analyze_Package_Body_Stub (N : Node_Id) is
Id : constant Entity_Id := Defining_Identifier (N);
Nam : Entity_Id;
begin
Check_Stub_Level (N);
Nam := Current_Entity_In_Scope (Id);
if No (Nam) or else not Is_Package (Nam) then
Error_Msg_N ("missing specification for package stub", N);
elsif Has_Completion (Nam)
and then Present (Corresponding_Body (Unit_Declaration_Node (Nam)))
then
Error_Msg_N ("duplicate or redundant stub for package", N);
else
Set_Has_Completion (Nam);
Set_Scope (Defining_Entity (N), Current_Scope);
Generate_Reference (Nam, Id, 'b');
Analyze_Proper_Body (N, Nam);
end if;
end Analyze_Package_Body_Stub;
procedure Analyze_Proper_Body (N : Node_Id; Nam : Entity_Id) is
Subunit_Name : constant Unit_Name_Type := Get_Unit_Name (N);
Unum : Unit_Number_Type;
procedure Optional_Subunit;
procedure Optional_Subunit is
Comp_Unit : Node_Id;
begin
if not ASIS_Mode then
Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
end if;
Unum :=
Load_Unit
(Load_Name => Subunit_Name,
Required => False,
Subunit => True,
Error_Node => N);
if not ASIS_Mode then
Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
end if;
if Unum /= No_Unit
and then (not Fatal_Error (Unum) or else Try_Semantics)
then
Comp_Unit := Cunit (Unum);
if No (Unit (Comp_Unit)) then
Error_Msg_N
("subunit does not contain expected proper body", N);
elsif Nkind (Unit (Comp_Unit)) /= N_Subunit then
Error_Msg_N
("expected SEPARATE subunit, found child unit",
Cunit_Entity (Unum));
else
Set_Corresponding_Stub (Unit (Comp_Unit), N);
Analyze_Subunit (Comp_Unit);
Set_Library_Unit (N, Comp_Unit);
end if;
elsif Unum = No_Unit
and then Present (Nam)
then
if Is_Protected_Type (Nam) then
Set_Corresponding_Body (Parent (Nam), Defining_Identifier (N));
else
Set_Corresponding_Body (
Unit_Declaration_Node (Nam), Defining_Identifier (N));
end if;
end if;
end Optional_Subunit;
begin
if Is_Loaded (Subunit_Name) then
if Present (Library_Unit (N)) then
Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
Analyze_Subunit (Library_Unit (N));
else
Unum :=
Load_Unit
(Load_Name => Subunit_Name,
Required => True,
Subunit => False,
Error_Node => N);
if Unum /= No_Unit then
Compiler_State := Analyzing;
if Nkind (Unit (Cunit (Unum))) /= N_Subunit then
return;
end if;
Set_Corresponding_Stub (Unit (Cunit (Unum)), N);
Analyze_Subunit (Cunit (Unum));
Set_Library_Unit (N, Cunit (Unum));
end if;
end if;
elsif Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
and then Subunit_Name /= Unit_Name (Main_Unit)
then
if ASIS_Mode then
Optional_Subunit;
end if;
Unloaded_Subunits := True;
return;
elsif Original_Operating_Mode = Generate_Code then
if Present (Library_Unit (N)) then
Set_Corresponding_Stub (Unit (Library_Unit (N)), N);
Analyze_Subunit (Library_Unit (N));
Version_Update (Cunit (Main_Unit), Library_Unit (N));
else
Unum :=
Load_Unit
(Load_Name => Subunit_Name,
Required => False,
Subunit => True,
Error_Node => N);
if Original_Operating_Mode = Generate_Code
and then Unum = No_Unit
then
Error_Msg_Name_1 := Subunit_Name;
Error_Msg_Name_2 :=
Get_File_Name (Subunit_Name, Subunit => True);
Error_Msg_N
("subunit% in file{ not found!?", N);
Subunits_Missing := True;
end if;
Compiler_State := Analyzing;
if Unum /= No_Unit
and then (not Fatal_Error (Unum) or else Try_Semantics)
then
if Debug_Flag_L then
Write_Str ("*** Loaded subunit from stub. Analyze");
Write_Eol;
end if;
declare
Comp_Unit : constant Node_Id := Cunit (Unum);
begin
if Nkind (Unit (Comp_Unit)) /= N_Subunit then
Error_Msg_N
("expected SEPARATE subunit, found child unit",
Cunit_Entity (Unum));
else
Set_Corresponding_Stub (Unit (Comp_Unit), N);
Analyze_Subunit (Comp_Unit);
Set_Library_Unit (N, Comp_Unit);
Version_Update (Cunit (Main_Unit), Comp_Unit);
end if;
end;
end if;
end if;
else
Optional_Subunit;
end if;
end Analyze_Proper_Body;
procedure Analyze_Protected_Body_Stub (N : Node_Id) is
Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
begin
Check_Stub_Level (N);
if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
Nam := Full_View (Nam);
end if;
if No (Nam)
or else not Is_Protected_Type (Etype (Nam))
then
Error_Msg_N ("missing specification for Protected body", N);
else
Set_Scope (Defining_Entity (N), Current_Scope);
Set_Has_Completion (Etype (Nam));
Generate_Reference (Nam, Defining_Identifier (N), 'b');
Analyze_Proper_Body (N, Etype (Nam));
end if;
end Analyze_Protected_Body_Stub;
procedure Analyze_Subprogram_Body_Stub (N : Node_Id) is
Decl : Node_Id;
begin
Check_Stub_Level (N);
if Nkind (Parent (N)) = N_Block_Statement
or else Nkind (Parent (N)) = N_Package_Body
or else Nkind (Parent (N)) = N_Subprogram_Body
then
Decl := First (Declarations (Parent (N)));
while Present (Decl)
and then Decl /= N
loop
if Nkind (Decl) = N_Subprogram_Body_Stub
and then (Chars (Defining_Unit_Name (Specification (Decl)))
= Chars (Defining_Unit_Name (Specification (N))))
then
Error_Msg_N ("identifier for stub is not unique", N);
end if;
Next (Decl);
end loop;
end if;
Analyze_Subprogram_Body (N);
Analyze_Proper_Body (N, Empty);
end Analyze_Subprogram_Body_Stub;
procedure Analyze_Subunit (N : Node_Id) is
Lib_Unit : constant Node_Id := Library_Unit (N);
Par_Unit : constant Entity_Id := Current_Scope;
Lib_Spec : Node_Id := Library_Unit (Lib_Unit);
Num_Scopes : Int := 0;
Use_Clauses : array (1 .. Scope_Stack.Last) of Node_Id;
Enclosing_Child : Entity_Id := Empty;
Svg : constant Suppress_Array := Scope_Suppress;
procedure Analyze_Subunit_Context;
procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id);
procedure Re_Install_Use_Clauses;
procedure Remove_Scope;
procedure Analyze_Subunit_Context is
Item : Node_Id;
Nam : Node_Id;
Unit_Name : Entity_Id;
begin
Analyze_Context (N);
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause then
Unit_Name := Entity (Name (Item));
while Is_Child_Unit (Unit_Name) loop
Set_Is_Visible_Child_Unit (Unit_Name);
Unit_Name := Scope (Unit_Name);
end loop;
if not Is_Immediately_Visible (Unit_Name) then
Set_Is_Immediately_Visible (Unit_Name);
Set_Context_Installed (Item);
end if;
elsif Nkind (Item) = N_Use_Package_Clause then
Nam := First (Names (Item));
while Present (Nam) loop
Analyze (Nam);
Next (Nam);
end loop;
elsif Nkind (Item) = N_Use_Type_Clause then
Nam := First (Subtype_Marks (Item));
while Present (Nam) loop
Analyze (Nam);
Next (Nam);
end loop;
end if;
Next (Item);
end loop;
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause then
Unit_Name := Entity (Name (Item));
while Is_Child_Unit (Unit_Name) loop
Set_Is_Visible_Child_Unit (Unit_Name, False);
Unit_Name := Scope (Unit_Name);
end loop;
if Context_Installed (Item) then
Set_Is_Immediately_Visible (Unit_Name, False);
Set_Context_Installed (Item, False);
end if;
end if;
Next (Item);
end loop;
end Analyze_Subunit_Context;
procedure Re_Install_Parents (L : Node_Id; Scop : Entity_Id) is
E : Entity_Id;
begin
if Nkind (Unit (L)) = N_Subunit then
Re_Install_Parents (Library_Unit (L), Scope (Scop));
end if;
Install_Context (L);
if Present (Enclosing_Child) then
Install_Siblings (Enclosing_Child, L);
end if;
New_Scope (Scop);
if Scop /= Par_Unit then
Set_Is_Immediately_Visible (Scop);
end if;
E := First_Entity (Current_Scope);
while Present (E) loop
Set_Is_Immediately_Visible (E);
Next_Entity (E);
end loop;
if Ekind (Scop) = E_Package then
Set_In_Package_Body (Scop);
Install_Private_Declarations (Scop);
end if;
end Re_Install_Parents;
procedure Re_Install_Use_Clauses is
U : Node_Id;
begin
for J in reverse 1 .. Num_Scopes loop
U := Use_Clauses (J);
Scope_Stack.Table (Scope_Stack.Last - J + 1).First_Use_Clause := U;
Install_Use_Clauses (U, Force_Installation => True);
end loop;
end Re_Install_Use_Clauses;
procedure Remove_Scope is
E : Entity_Id;
begin
Num_Scopes := Num_Scopes + 1;
Use_Clauses (Num_Scopes) :=
Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause;
E := First_Entity (Current_Scope);
while Present (E) loop
Set_Is_Immediately_Visible (E, False);
Next_Entity (E);
end loop;
if Is_Child_Unit (Current_Scope) then
Enclosing_Child := Current_Scope;
end if;
Pop_Scope;
end Remove_Scope;
begin
if not Is_Empty_List (Context_Items (N)) then
Remove_Scope;
Remove_Context (Lib_Unit);
if Present (Lib_Spec) then
Remove_Context (Lib_Spec);
while Nkind (Unit (Lib_Spec)) = N_Subunit loop
Lib_Spec := Library_Unit (Lib_Spec);
Remove_Scope;
Remove_Context (Lib_Spec);
end loop;
if Nkind (Unit (Lib_Unit)) = N_Subunit then
Remove_Scope;
end if;
if Nkind (Unit (Lib_Spec)) = N_Package_Body then
Remove_Context (Library_Unit (Lib_Spec));
end if;
end if;
Set_Is_Immediately_Visible (Par_Unit, False);
Analyze_Subunit_Context;
Re_Install_Parents (Lib_Unit, Par_Unit);
Set_Is_Immediately_Visible (Par_Unit);
if Ekind (Par_Unit) = E_Package then
if not Is_Immediately_Visible (Par_Unit)
or else (Present (First_Entity (Par_Unit))
and then not Is_Immediately_Visible
(First_Entity (Par_Unit)))
then
Set_Is_Immediately_Visible (Par_Unit);
Install_Visible_Declarations (Par_Unit);
Install_Private_Declarations (Par_Unit);
end if;
end if;
Re_Install_Use_Clauses;
Install_Context (N);
Scope_Suppress := Svg;
if Present (Enclosing_Child) then
Install_Siblings (Enclosing_Child, N);
end if;
end if;
Analyze (Proper_Body (Unit (N)));
Remove_Context (N);
end Analyze_Subunit;
procedure Analyze_Task_Body_Stub (N : Node_Id) is
Nam : Entity_Id := Current_Entity_In_Scope (Defining_Identifier (N));
Loc : constant Source_Ptr := Sloc (N);
begin
Check_Stub_Level (N);
if Present (Nam) and then Ekind (Nam) = E_Incomplete_Type then
Nam := Full_View (Nam);
end if;
if No (Nam)
or else not Is_Task_Type (Etype (Nam))
then
Error_Msg_N ("missing specification for task body", N);
else
Set_Scope (Defining_Entity (N), Current_Scope);
Generate_Reference (Nam, Defining_Identifier (N), 'b');
Set_Has_Completion (Etype (Nam));
Analyze_Proper_Body (N, Etype (Nam));
if Expander_Active then
Insert_After (N,
Make_Assignment_Statement (Loc,
Name =>
Make_Identifier (Loc,
New_External_Name (Chars (Etype (Nam)), 'E')),
Expression => New_Reference_To (Standard_True, Loc)));
end if;
end if;
end Analyze_Task_Body_Stub;
procedure Analyze_With_Clause (N : Node_Id) is
Unit_Kind : constant Node_Kind :=
Nkind (Original_Node (Unit (Library_Unit (N))));
E_Name : Entity_Id;
Par_Name : Entity_Id;
Pref : Node_Id;
U : Node_Id;
Intunit : Boolean;
Save_Style_Check : constant Boolean := Opt.Style_Check;
Save_C_Restrict : constant Save_Cunit_Boolean_Restrictions :=
Cunit_Boolean_Restrictions_Save;
begin
if Limited_Present (N) then
Build_Limited_Views (N);
return;
end if;
if not GNAT_Mode then
Style_Check := False;
end if;
if Configurable_Run_Time_Mode
and then
Is_Predefined_File_Name
(Unit_File_Name (Get_Source_Unit (Unit (Library_Unit (N)))))
then
Configurable_Run_Time_Mode := False;
Semantics (Library_Unit (N));
Configurable_Run_Time_Mode := True;
else
Semantics (Library_Unit (N));
end if;
U := Unit (Library_Unit (N));
Check_Restriction_No_Dependence (Name (N), N);
Intunit := Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit));
if Sloc (U) /= No_Location then
if not Intunit or else Current_Sem_Unit = Main_Unit then
Check_Restricted_Unit (Unit_Name (Get_Source_Unit (U)), N);
end if;
if Implementation_Unit_Warnings
and then Current_Sem_Unit = Main_Unit
and then not Intunit
and then not Implicit_With (N)
and then not GNAT_Mode
then
declare
U_Kind : constant Kind_Of_Unit :=
Get_Kind_Of_Unit (Get_Source_Unit (U));
begin
if U_Kind = Implementation_Unit then
Error_Msg_N ("& is an internal 'G'N'A'T unit?", Name (N));
Error_Msg_N
("\use of this unit is non-portable " &
"and version-dependent?",
Name (N));
elsif U_Kind = Ada_05_Unit and then Ada_Version = Ada_95 then
Error_Msg_N ("& is an Ada 2005 unit?", Name (N));
end if;
end;
end if;
end if;
if Unit_Kind in N_Generic_Declaration then
E_Name := Defining_Entity (U);
elsif (Unit_Kind = N_Package_Instantiation
or else Nkind (Original_Node (Unit (Library_Unit (N)))) =
N_Package_Instantiation)
and then Nkind (U) = N_Package_Body
then
E_Name := Corresponding_Spec (U);
elsif Unit_Kind = N_Package_Instantiation
and then Nkind (U) = N_Package_Instantiation
then
E_Name := Defining_Entity (Specification (Instance_Spec (U)));
elsif Unit_Kind = N_Procedure_Instantiation
or else Unit_Kind = N_Function_Instantiation
then
E_Name := First_Entity (Defining_Entity (U));
while Present (E_Name) loop
exit when Is_Subprogram (E_Name)
and then Is_Generic_Instance (E_Name);
E_Name := Next_Entity (E_Name);
end loop;
elsif Unit_Kind = N_Package_Renaming_Declaration
or else Unit_Kind in N_Generic_Renaming_Declaration
then
E_Name := Defining_Entity (U);
elsif Unit_Kind = N_Subprogram_Body
and then Nkind (Name (N)) = N_Selected_Component
and then not Acts_As_Spec (Library_Unit (N))
then
E_Name := Corresponding_Spec (U);
else
E_Name := Defining_Entity (U);
end if;
if Nkind (Name (N)) = N_Selected_Component then
Change_Selected_Component_To_Expanded_Name (Name (N));
end if;
Style_Check := Save_Style_Check;
Cunit_Boolean_Restrictions_Restore (Save_C_Restrict);
Set_Entity_With_Style_Check (Name (N), E_Name);
Generate_Reference (E_Name, Name (N), 'w', Set_Ref => False);
if Is_Child_Unit (E_Name) then
Pref := Prefix (Name (N));
Par_Name := Scope (E_Name);
while Nkind (Pref) = N_Selected_Component loop
Change_Selected_Component_To_Expanded_Name (Pref);
Set_Entity_With_Style_Check (Pref, Par_Name);
Generate_Reference (Par_Name, Pref);
Pref := Prefix (Pref);
if Par_Name /= Standard_Standard then
Par_Name := Scope (Par_Name);
end if;
end loop;
if Present (Entity (Pref))
and then not Analyzed (Parent (Parent (Entity (Pref))))
then
Analyze (Parent (Parent (Entity (Pref))));
pragma Assert (Renamed_Object (Entity (Pref)) = Par_Name);
Par_Name := Entity (Pref);
end if;
Set_Entity_With_Style_Check (Pref, Par_Name);
Generate_Reference (Par_Name, Pref);
end if;
if Chars (E_Name) = Name_System
and then Scope (E_Name) = Standard_Standard
and then Present (System_Extend_Unit)
and then Present_System_Aux (N)
then
null;
end if;
if Private_Present (N) then
Set_Is_Immediately_Visible (E_Name, False);
end if;
end Analyze_With_Clause;
procedure Analyze_With_Type_Clause (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Nam : constant Node_Id := Name (N);
Pack : Node_Id;
Decl : Node_Id;
P : Entity_Id;
Unum : Unit_Number_Type;
Sel : Node_Id;
procedure Decorate_Tagged_Type (T : Entity_Id);
function In_Chain (E : Entity_Id) return Boolean;
procedure Decorate_Tagged_Type (T : Entity_Id) is
CW : Entity_Id;
begin
Set_Ekind (T, E_Record_Type);
Set_Is_Tagged_Type (T);
Set_Etype (T, T);
Set_From_With_Type (T);
Set_Scope (T, P);
if not In_Chain (T) then
Set_Homonym (T, Current_Entity (T));
Set_Current_Entity (T);
end if;
if No (Class_Wide_Type (T)) then
CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
Set_Ekind (CW, E_Class_Wide_Type);
Set_Etype (CW, T);
Set_Scope (CW, P);
Set_Is_Tagged_Type (CW);
Set_Is_First_Subtype (CW, True);
Init_Size_Align (CW);
Set_Has_Unknown_Discriminants
(CW, True);
Set_Class_Wide_Type (CW, CW);
Set_Equivalent_Type (CW, Empty);
Set_From_With_Type (CW);
Set_Class_Wide_Type (T, CW);
end if;
end Decorate_Tagged_Type;
function In_Chain (E : Entity_Id) return Boolean is
H : Entity_Id := Current_Entity (E);
begin
while Present (H) loop
if H = E then
return True;
else
H := Homonym (H);
end if;
end loop;
return False;
end In_Chain;
begin
if Nkind (Nam) = N_Selected_Component then
Pack := New_Copy_Tree (Prefix (Nam));
Sel := Selector_Name (Nam);
else
Error_Msg_N ("illegal name for imported type", Nam);
return;
end if;
Decl :=
Make_Package_Declaration (Loc,
Specification =>
(Make_Package_Specification (Loc,
Defining_Unit_Name => Pack,
Visible_Declarations => New_List,
End_Label => Empty)));
Unum :=
Load_Unit
(Load_Name => Get_Unit_Name (Decl),
Required => True,
Subunit => False,
Error_Node => Nam);
if Unum = No_Unit
or else Nkind (Unit (Cunit (Unum))) /= N_Package_Declaration
then
Error_Msg_N ("imported type must be declared in package", Nam);
return;
elsif Unum = Current_Sem_Unit then
return;
else
P := Cunit_Entity (Unum);
end if;
declare
Decl : Node_Id;
Typ : Entity_Id;
begin
if not Analyzed (Cunit (Unum))
and then not From_With_Type (P)
then
Set_Ekind (P, E_Package);
Set_Etype (P, Standard_Void_Type);
Set_From_With_Type (P);
Set_Scope (P, Standard_Standard);
Set_Homonym (P, Current_Entity (P));
Set_Current_Entity (P);
elsif Analyzed (Cunit (Unum))
and then Is_Child_Unit (P)
then
Set_Is_Visible_Child_Unit (P);
end if;
if Nkind (Parent (P)) = N_Defining_Program_Unit_Name then
declare
Parent_Comp : Node_Id;
Parent_Id : Entity_Id;
Child : Entity_Id;
begin
Child := P;
Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
loop
Parent_Id := Defining_Entity (Unit (Parent_Comp));
Set_Scope (Child, Parent_Id);
if not Analyzed (Unit_Declaration_Node (Parent_Id))
and then Parent_Id /= Cunit_Entity (Current_Sem_Unit)
then
Set_Ekind (Parent_Id, E_Package);
Set_Etype (Parent_Id, Standard_Void_Type);
if not From_With_Type (Parent_Id) then
Set_Homonym (Parent_Id, Current_Entity (Parent_Id));
Set_Current_Entity (Parent_Id);
Set_From_With_Type (Parent_Id);
end if;
end if;
Set_Is_Immediately_Visible (Parent_Id);
Child := Parent_Id;
Parent_Comp := Parent_Spec (Unit (Parent_Comp));
exit when No (Parent_Comp);
end loop;
Set_Scope (Parent_Id, Standard_Standard);
end;
end if;
Set_Is_Immediately_Visible (P);
Decl :=
First (Visible_Declarations (Specification (Unit (Cunit (Unum)))));
while Present (Decl) loop
if Nkind (Decl) = N_Full_Type_Declaration
and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
then
Typ := Defining_Identifier (Decl);
if Tagged_Present (N) then
if (Nkind (Type_Definition (Decl)) = N_Record_Definition
and then Tagged_Present (Type_Definition (Decl)))
or else
(Nkind (Type_Definition (Decl))
= N_Derived_Type_Definition
and then Present
(Record_Extension_Part (Type_Definition (Decl))))
then
null;
else
Error_Msg_N ("imported type is not a tagged type", Nam);
return;
end if;
if not Analyzed (Decl) then
Init_Size_Align (Typ);
Decorate_Tagged_Type (Typ);
end if;
else
if Nkind (Type_Definition (Decl))
/= N_Access_To_Object_Definition
then
Error_Msg_N
("imported type is not an access type", Nam);
elsif not Analyzed (Decl) then
Set_Ekind (Typ, E_Access_Type);
Set_Etype (Typ, Typ);
Set_Scope (Typ, P);
Init_Size (Typ, System_Address_Size);
Init_Alignment (Typ);
Set_Directly_Designated_Type (Typ, Standard_Integer);
Set_From_With_Type (Typ);
if not In_Chain (Typ) then
Set_Homonym (Typ, Current_Entity (Typ));
Set_Current_Entity (Typ);
end if;
end if;
end if;
Set_Entity (Sel, Typ);
return;
elsif ((Nkind (Decl) = N_Private_Type_Declaration
and then Tagged_Present (Decl))
or else (Nkind (Decl) = N_Private_Extension_Declaration))
and then Chars (Defining_Identifier (Decl)) = Chars (Sel)
then
Typ := Defining_Identifier (Decl);
if not Tagged_Present (N) then
Error_Msg_N ("type must be declared tagged", N);
elsif not Analyzed (Decl) then
Decorate_Tagged_Type (Typ);
end if;
Set_Entity (Sel, Typ);
Set_From_With_Type (Typ);
return;
end if;
Decl := Next (Decl);
end loop;
Error_Msg_NE ("not a visible access or tagged type in&", Nam, P);
end;
end Analyze_With_Type_Clause;
procedure Check_With_Type_Clauses (N : Node_Id) is
Lib_Unit : constant Node_Id := Unit (N);
procedure Check_Parent_Context (U : Node_Id);
procedure Check_Parent_Context (U : Node_Id) is
Item : Node_Id;
begin
Item := First (Context_Items (U));
while Present (Item) loop
if Nkind (Item) = N_With_Type_Clause
and then not Error_Posted (Item)
and then
From_With_Type (Scope (Entity (Selector_Name (Name (Item)))))
then
Error_Msg_Sloc := Sloc (Item);
Error_Msg_N ("Missing With_Clause for With_Type_Clause#", N);
end if;
Next (Item);
end loop;
end Check_Parent_Context;
begin
if Extensions_Allowed
and then (Nkind (Lib_Unit) = N_Package_Body
or else Nkind (Lib_Unit) = N_Subprogram_Body)
then
Check_Parent_Context (Library_Unit (N));
if Is_Child_Spec (Unit (Library_Unit (N))) then
Check_Parent_Context (Parent_Spec (Unit (Library_Unit (N))));
end if;
end if;
end Check_With_Type_Clauses;
procedure Check_Private_Child_Unit (N : Node_Id) is
Lib_Unit : constant Node_Id := Unit (N);
Item : Node_Id;
Curr_Unit : Entity_Id;
Sub_Parent : Node_Id;
Priv_Child : Entity_Id;
Par_Lib : Entity_Id;
Par_Spec : Node_Id;
function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean;
function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
begin
return Private_Present (Comp_Unit);
end Is_Private_Library_Unit;
begin
if Nkind (Lib_Unit) = N_Package_Body
or else Nkind (Lib_Unit) = N_Subprogram_Body
then
Curr_Unit := Defining_Entity (Unit (Library_Unit (N)));
Par_Lib := Curr_Unit;
elsif Nkind (Lib_Unit) = N_Subunit then
Sub_Parent := Library_Unit (N);
Curr_Unit := Defining_Entity (Unit (Library_Unit (Sub_Parent)));
if Ekind (Curr_Unit) = E_Package_Body then
Curr_Unit := Spec_Entity (Curr_Unit);
end if;
Par_Lib := Curr_Unit;
else
Curr_Unit := Defining_Entity (Lib_Unit);
Par_Lib := Curr_Unit;
Par_Spec := Parent_Spec (Lib_Unit);
if No (Par_Spec) then
Par_Lib := Empty;
else
Par_Lib := Defining_Entity (Unit (Par_Spec));
end if;
end if;
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Implicit_With (Item)
and then not Private_Present (Item)
and then Is_Private_Descendant (Entity (Name (Item)))
then
Priv_Child := Entity (Name (Item));
declare
Curr_Parent : Entity_Id := Par_Lib;
Child_Parent : Entity_Id := Scope (Priv_Child);
Prv_Ancestor : Entity_Id := Child_Parent;
Curr_Private : Boolean := Is_Private_Library_Unit (Curr_Unit);
begin
if not Is_Private_Library_Unit (Priv_Child) then
while Present (Prv_Ancestor)
and then not Is_Private_Library_Unit (Prv_Ancestor)
loop
Prv_Ancestor := Scope (Prv_Ancestor);
end loop;
if Present (Prv_Ancestor) then
Child_Parent := Scope (Prv_Ancestor);
end if;
end if;
while Present (Curr_Parent)
and then Curr_Parent /= Standard_Standard
and then Curr_Parent /= Child_Parent
loop
Curr_Private :=
Curr_Private or else Is_Private_Library_Unit (Curr_Parent);
Curr_Parent := Scope (Curr_Parent);
end loop;
if not Present (Curr_Parent) then
Curr_Parent := Standard_Standard;
end if;
if Curr_Parent /= Child_Parent then
if Ekind (Priv_Child) = E_Generic_Package
and then Chars (Priv_Child) in Text_IO_Package_Name
and then Chars (Scope (Scope (Priv_Child))) = Name_Ada
then
Error_Msg_NE
("& is a nested package, not a compilation unit",
Name (Item), Priv_Child);
else
Error_Msg_N
("unit in with clause is private child unit!", Item);
Error_Msg_NE
("current unit must also have parent&!",
Item, Child_Parent);
end if;
elsif not Curr_Private
and then Nkind (Lib_Unit) /= N_Package_Body
and then Nkind (Lib_Unit) /= N_Subprogram_Body
and then Nkind (Lib_Unit) /= N_Subunit
then
Error_Msg_NE
("current unit must also be private descendant of&",
Item, Child_Parent);
end if;
end;
end if;
Next (Item);
end loop;
end Check_Private_Child_Unit;
procedure Check_Stub_Level (N : Node_Id) is
Par : constant Node_Id := Parent (N);
Kind : constant Node_Kind := Nkind (Par);
begin
if (Kind = N_Package_Body
or else Kind = N_Subprogram_Body
or else Kind = N_Task_Body
or else Kind = N_Protected_Body)
and then (Nkind (Parent (Par)) = N_Compilation_Unit
or else Nkind (Parent (Par)) = N_Subunit)
then
null;
elsif not In_Instance then
Error_Msg_N ("stub cannot appear in an inner scope", N);
elsif Expander_Active then
Error_Msg_N ("missing proper body", N);
end if;
end Check_Stub_Level;
procedure Expand_With_Clause (Nam : Node_Id; N : Node_Id) is
Loc : constant Source_Ptr := Sloc (Nam);
Ent : constant Entity_Id := Entity (Nam);
Withn : Node_Id;
P : Node_Id;
function Build_Unit_Name (Nam : Node_Id) return Node_Id;
function Build_Unit_Name (Nam : Node_Id) return Node_Id is
Result : Node_Id;
begin
if Nkind (Nam) = N_Identifier then
return New_Occurrence_Of (Entity (Nam), Loc);
else
Result :=
Make_Expanded_Name (Loc,
Chars => Chars (Entity (Nam)),
Prefix => Build_Unit_Name (Prefix (Nam)),
Selector_Name => New_Occurrence_Of (Entity (Nam), Loc));
Set_Entity (Result, Entity (Nam));
return Result;
end if;
end Build_Unit_Name;
begin
New_Nodes_OK := New_Nodes_OK + 1;
Withn :=
Make_With_Clause (Loc, Name => Build_Unit_Name (Nam));
P := Parent (Unit_Declaration_Node (Ent));
Set_Library_Unit (Withn, P);
Set_Corresponding_Spec (Withn, Ent);
Set_First_Name (Withn, True);
Set_Implicit_With (Withn, True);
Prepend (Withn, Context_Items (N));
Mark_Rewrite_Insertion (Withn);
Install_Withed_Unit (Withn);
if Nkind (Nam) = N_Expanded_Name then
Expand_With_Clause (Prefix (Nam), N);
end if;
New_Nodes_OK := New_Nodes_OK - 1;
end Expand_With_Clause;
procedure Expand_Limited_With_Clause (Nam : Node_Id; N : Node_Id) is
Loc : constant Source_Ptr := Sloc (Nam);
Unum : Unit_Number_Type;
Withn : Node_Id;
begin
New_Nodes_OK := New_Nodes_OK + 1;
if Nkind (Nam) = N_Identifier then
Withn :=
Make_With_Clause (Loc, Name => Nam);
Set_Limited_Present (Withn);
Set_First_Name (Withn);
Set_Implicit_With (Withn);
Unum :=
Load_Unit
(Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
Required => True,
Subunit => False,
Error_Node => Nam);
if not Analyzed (Cunit (Unum)) then
Set_Library_Unit (Withn, Cunit (Unum));
Set_Corresponding_Spec
(Withn, Specification (Unit (Cunit (Unum))));
Prepend (Withn, Context_Items (Parent (N)));
Mark_Rewrite_Insertion (Withn);
end if;
else pragma Assert (Nkind (Nam) = N_Selected_Component);
Withn :=
Make_With_Clause
(Loc,
Name =>
Make_Selected_Component
(Loc,
Prefix => Prefix (Nam),
Selector_Name => Selector_Name (Nam)));
Set_Parent (Withn, Parent (N));
Set_Limited_Present (Withn);
Set_First_Name (Withn);
Set_Implicit_With (Withn);
Unum :=
Load_Unit
(Load_Name => Get_Spec_Name (Get_Unit_Name (Nam)),
Required => True,
Subunit => False,
Error_Node => Nam);
if not Analyzed (Cunit (Unum)) then
Set_Library_Unit (Withn, Cunit (Unum));
Set_Corresponding_Spec
(Withn, Specification (Unit (Cunit (Unum))));
Prepend (Withn, Context_Items (Parent (N)));
Mark_Rewrite_Insertion (Withn);
Expand_Limited_With_Clause (Prefix (Nam), N);
end if;
end if;
New_Nodes_OK := New_Nodes_OK - 1;
end Expand_Limited_With_Clause;
function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
begin
if Nkind (Unit) = N_Package_Body
and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
then
return
Defining_Entity
(Specification (Instance_Spec (Original_Node (Unit))));
elsif Nkind (Unit) = N_Package_Instantiation then
return Defining_Entity (Specification (Instance_Spec (Unit)));
else
return Defining_Entity (Unit);
end if;
end Get_Parent_Entity;
procedure Implicit_With_On_Parent
(Child_Unit : Node_Id;
N : Node_Id)
is
Loc : constant Source_Ptr := Sloc (N);
P : constant Node_Id := Parent_Spec (Child_Unit);
P_Unit : Node_Id := Unit (P);
P_Name : constant Entity_Id := Get_Parent_Entity (P_Unit);
Withn : Node_Id;
function Build_Ancestor_Name (P : Node_Id) return Node_Id;
function Build_Unit_Name return Node_Id;
function Build_Ancestor_Name (P : Node_Id) return Node_Id is
P_Ref : constant Node_Id :=
New_Reference_To (Defining_Entity (P), Loc);
begin
if No (Parent_Spec (P)) then
return P_Ref;
else
return
Make_Selected_Component (Loc,
Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P))),
Selector_Name => P_Ref);
end if;
end Build_Ancestor_Name;
function Build_Unit_Name return Node_Id is
Result : Node_Id;
begin
if No (Parent_Spec (P_Unit)) then
return New_Reference_To (P_Name, Loc);
else
Result :=
Make_Expanded_Name (Loc,
Chars => Chars (P_Name),
Prefix => Build_Ancestor_Name (Unit (Parent_Spec (P_Unit))),
Selector_Name => New_Reference_To (P_Name, Loc));
Set_Entity (Result, P_Name);
return Result;
end if;
end Build_Unit_Name;
begin
if Nkind (P_Unit) = N_Package_Body
and then Nkind (Original_Node (P_Unit)) = N_Package_Instantiation
then
P_Unit := Original_Node (P_Unit);
end if;
New_Nodes_OK := New_Nodes_OK + 1;
Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
Set_Library_Unit (Withn, P);
Set_Corresponding_Spec (Withn, P_Name);
Set_First_Name (Withn, True);
Set_Implicit_With (Withn, True);
Prepend (Withn, Context_Items (N));
Mark_Rewrite_Insertion (Withn);
Install_Withed_Unit (Withn);
if Is_Child_Spec (P_Unit) then
Implicit_With_On_Parent (P_Unit, N);
end if;
New_Nodes_OK := New_Nodes_OK - 1;
end Implicit_With_On_Parent;
procedure Install_Context (N : Node_Id) is
Lib_Unit : constant Node_Id := Unit (N);
begin
Install_Context_Clauses (N);
if Is_Child_Spec (Lib_Unit) then
Install_Parents (Lib_Unit, Private_Present (Parent (Lib_Unit)));
end if;
Install_Limited_Context_Clauses (N);
Check_With_Type_Clauses (N);
end Install_Context;
procedure Install_Context_Clauses (N : Node_Id) is
Lib_Unit : constant Node_Id := Unit (N);
Item : Node_Id;
Uname_Node : Entity_Id;
Check_Private : Boolean := False;
Decl_Node : Node_Id;
Lib_Parent : Entity_Id;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Implicit_With (Item)
then
if Limited_Present (Item) then
goto Continue;
elsif not Is_Entity_Name (Name (Item)) then
goto Continue;
elsif No (Entity (Name (Item))) then
Set_Entity (Name (Item), Any_Id);
goto Continue;
end if;
Uname_Node := Entity (Name (Item));
if Is_Private_Descendant (Uname_Node) then
Check_Private := True;
end if;
Install_Withed_Unit (Item);
Decl_Node := Unit_Declaration_Node (Uname_Node);
if Is_Generic_Instance (Uname_Node)
and then Ekind (Uname_Node) /= E_Package
then
Decl_Node := Parent (Parent (Decl_Node));
end if;
if Is_Child_Spec (Decl_Node) then
if Nkind (Name (Item)) = N_Expanded_Name then
Expand_With_Clause (Prefix (Name (Item)), N);
else
null;
end if;
elsif Nkind (Decl_Node) = N_Subprogram_Body
and then not Acts_As_Spec (Parent (Decl_Node))
and then Is_Child_Spec (Unit (Library_Unit (Parent (Decl_Node))))
then
Implicit_With_On_Parent
(Unit (Library_Unit (Parent (Decl_Node))), N);
end if;
if Sloc (Library_Unit (Item)) /= No_Location then
License_Check : declare
Withl : constant License_Type :=
License (Source_Index
(Get_Source_Unit
(Library_Unit (Item))));
Unitl : constant License_Type :=
License (Source_Index (Current_Sem_Unit));
procedure License_Error;
procedure License_Error is
begin
Error_Msg_N
("?license of with'ed unit & is incompatible",
Name (Item));
end License_Error;
begin
case Unitl is
when Unknown =>
null;
when Restricted =>
if Withl = GPL then
License_Error;
end if;
when GPL =>
if Withl = Restricted then
License_Error;
end if;
when Modified_GPL =>
if Withl = Restricted or else Withl = GPL then
License_Error;
end if;
when Unrestricted =>
null;
end case;
end License_Check;
end if;
elsif Nkind (Item) = N_Use_Package_Clause then
Analyze_Use_Package (Item);
elsif Nkind (Item) = N_Use_Type_Clause then
Analyze_Use_Type (Item);
elsif Nkind (Item) = N_With_Type_Clause then
Analyze_With_Type_Clause (Item);
elsif Nkind (Item) = N_Pragma then
Analyze (Item);
end if;
<<Continue>>
Next (Item);
end loop;
if Is_Child_Spec (Lib_Unit) then
if No (Context_Items (N)) then
Set_Context_Items (N, New_List);
end if;
Implicit_With_On_Parent (Lib_Unit, N);
end if;
if Nkind (Lib_Unit) = N_Package_Body
or else (Nkind (Lib_Unit) = N_Subprogram_Body
and then not Acts_As_Spec (N))
then
Install_Context (Library_Unit (N));
if Is_Child_Spec (Unit (Library_Unit (N))) then
declare
Lib_Spec : Node_Id := Unit (Library_Unit (N));
P : Node_Id;
P_Name : Entity_Id;
begin
while Is_Child_Spec (Lib_Spec) loop
P := Unit (Parent_Spec (Lib_Spec));
if not (Private_Present (Parent (Lib_Spec))) then
P_Name := Defining_Entity (P);
Install_Private_Declarations (P_Name);
Install_Private_With_Clauses (P_Name);
Set_Use (Private_Declarations (Specification (P)));
end if;
Lib_Spec := P;
end loop;
end;
end if;
Install_Siblings (Defining_Entity (Unit (Library_Unit (N))), N);
end if;
if Nkind (Lib_Unit) = N_Generic_Package_Declaration
or else Nkind (Lib_Unit) = N_Generic_Subprogram_Declaration
or else Nkind (Lib_Unit) = N_Package_Declaration
or else Nkind (Lib_Unit) = N_Subprogram_Declaration
then
if Is_Child_Spec (Lib_Unit) then
Lib_Parent := Defining_Entity (Unit (Parent_Spec (Lib_Unit)));
Set_Is_Private_Descendant
(Defining_Entity (Lib_Unit),
Is_Private_Descendant (Lib_Parent)
or else Private_Present (Parent (Lib_Unit)));
else
Set_Is_Private_Descendant
(Defining_Entity (Lib_Unit),
Private_Present (Parent (Lib_Unit)));
end if;
end if;
if Check_Private then
Check_Private_Child_Unit (N);
end if;
end Install_Context_Clauses;
procedure Install_Limited_Context_Clauses (N : Node_Id) is
Item : Node_Id;
procedure Check_Parent (P : Node_Id; W : Node_Id);
procedure Check_Private_Limited_Withed_Unit (N : Node_Id);
procedure Check_Withed_Unit (W : Node_Id);
procedure Check_Parent (P : Node_Id; W : Node_Id) is
Item : Node_Id;
Spec : Node_Id;
WEnt : Entity_Id;
Nam : Node_Id;
E : Entity_Id;
E2 : Entity_Id;
begin
pragma Assert (Nkind (W) = N_With_Clause);
Item := First (Context_Items (P));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Limited_Present (Item)
and then not Implicit_With (Item)
and then Library_Unit (Item) = Library_Unit (W)
then
Error_Msg_N ("unlimited view visible in ancestor", W);
return;
end if;
Next (Item);
end loop;
WEnt := Defining_Unit_Name (Specification (Unit (Library_Unit (W))));
Spec := Specification (Unit (P));
Item := First (Visible_Declarations (Spec));
while Present (Item) loop
if Nkind (Item) = N_Use_Package_Clause then
Nam := First (Names (Item));
while Present (Nam) loop
E := Entity (Nam);
pragma Assert (Present (Parent (E)));
if Nkind (Parent (E))
= N_Package_Renaming_Declaration
and then Renamed_Entity (E) = WEnt
then
Error_Msg_N ("unlimited view visible through "
& "use_clause + renamings", W);
return;
elsif Nkind (Parent (E)) = N_Package_Specification then
E2 := E;
while E2 /= Standard_Standard
and then E2 /= WEnt loop
E2 := Scope (E2);
end loop;
if E2 = WEnt then
Error_Msg_N ("unlimited view visible through "
& "use_clause ", W);
return;
end if;
end if;
Next (Nam);
end loop;
end if;
Next (Item);
end loop;
if Is_Child_Spec (Unit (P)) then
Check_Parent (P => Parent_Spec (Unit (P)), W => W);
end if;
end Check_Parent;
procedure Check_Private_Limited_Withed_Unit (N : Node_Id) is
C : Node_Id;
P : Node_Id;
Found : Boolean := False;
begin
if not Private_Present (Parent (N)) then
Found := False;
else
P := Parent_Spec (Unit (Library_Unit (N)));
C := Parent (N);
while Present (Parent_Spec (Unit (C))) loop
C := Parent_Spec (Unit (C));
if C = P then
Found := True;
exit;
end if;
end loop;
end if;
if not Found then
Error_Msg_N ("current unit is not a private descendant"
& " of the withed unit ('R'M 10.1.2(8)", N);
end if;
end Check_Private_Limited_Withed_Unit;
procedure Check_Withed_Unit (W : Node_Id) is
Item : Node_Id;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Limited_Present (Item)
and then not Implicit_With (Item)
and then Library_Unit (Item) = Library_Unit (W)
then
Error_Msg_N ("limited and unlimited view "
& "not allowed in the same context clauses", W);
return;
end if;
Next (Item);
end loop;
end Check_Withed_Unit;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
then
Check_Withed_Unit (Item);
if Private_Present (Library_Unit (Item)) then
Check_Private_Limited_Withed_Unit (Item);
end if;
if Is_Child_Spec (Unit (N)) then
Check_Parent (Parent_Spec (Unit (N)), Item);
end if;
Install_Limited_Withed_Unit (Item);
end if;
Next (Item);
end loop;
end Install_Limited_Context_Clauses;
procedure Install_Parents (Lib_Unit : Node_Id; Is_Private : Boolean) is
P : Node_Id;
E_Name : Entity_Id;
P_Name : Entity_Id;
P_Spec : Node_Id;
begin
P := Unit (Parent_Spec (Lib_Unit));
P_Name := Get_Parent_Entity (P);
if Etype (P_Name) = Any_Type then
return;
end if;
if Ekind (P_Name) = E_Generic_Package
and then Nkind (Lib_Unit) /= N_Generic_Subprogram_Declaration
and then Nkind (Lib_Unit) /= N_Generic_Package_Declaration
and then Nkind (Lib_Unit) not in N_Generic_Renaming_Declaration
then
Error_Msg_N
("child of a generic package must be a generic unit", Lib_Unit);
elsif not Is_Package (P_Name) then
Error_Msg_N
("parent unit must be package or generic package", Lib_Unit);
raise Unrecoverable_Error;
elsif Present (Renamed_Object (P_Name)) then
Error_Msg_N ("parent unit cannot be a renaming", Lib_Unit);
raise Unrecoverable_Error;
elsif Nkind (Original_Node (P)) = N_Package_Instantiation
and then Nkind (Lib_Unit)
not in N_Renaming_Declaration
and then Nkind (Original_Node (Lib_Unit))
not in N_Generic_Instantiation
then
Error_Msg_N
("child of an instance must be an instance or renaming", Lib_Unit);
end if;
if Is_Child_Spec (P) then
Install_Parents (P,
Is_Private or else Private_Present (Parent (Lib_Unit)));
end if;
Install_Context_Clauses (Parent_Spec (Lib_Unit));
Install_Siblings (P_Name, Parent (Lib_Unit));
E_Name := Defining_Entity (Lib_Unit);
Set_Is_Child_Unit (E_Name);
Set_Is_Private_Descendant (E_Name,
Is_Private_Descendant (P_Name)
or else Private_Present (Parent (Lib_Unit)));
P_Spec := Specification (Unit_Declaration_Node (P_Name));
New_Scope (P_Name);
Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility :=
Is_Immediately_Visible (P_Name);
Set_Is_Immediately_Visible (P_Name);
Install_Visible_Declarations (P_Name);
Set_Use (Visible_Declarations (P_Spec));
if Ekind (P_Name) = E_Generic_Package then
Set_Use (Generic_Formal_Declarations (Parent (P_Spec)));
end if;
if Is_Private
or else Private_Present (Parent (Lib_Unit))
then
Install_Private_Declarations (P_Name);
Install_Private_With_Clauses (P_Name);
Set_Use (Private_Declarations (P_Spec));
end if;
end Install_Parents;
procedure Install_Private_With_Clauses (P : Entity_Id) is
Decl : constant Node_Id := Unit_Declaration_Node (P);
Item : Node_Id;
begin
if Debug_Flag_I then
Write_Str ("install private with clauses of ");
Write_Name (Chars (P));
Write_Eol;
end if;
if Nkind (Parent (Decl)) = N_Compilation_Unit then
Item := First (Context_Items (Parent (Decl)));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Private_Present (Item)
then
if Limited_Present (Item) then
Install_Limited_Withed_Unit (Item);
else
Install_Withed_Unit (Item, Private_With_OK => True);
end if;
end if;
Next (Item);
end loop;
end if;
end Install_Private_With_Clauses;
procedure Install_Siblings (U_Name : Entity_Id; N : Node_Id) is
Item : Node_Id;
Id : Entity_Id;
Prev : Entity_Id;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Implicit_With (Item)
and then not Limited_Present (Item)
then
Id := Entity (Name (Item));
if Is_Child_Unit (Id)
and then Is_Ancestor_Package (Scope (Id), U_Name)
then
Set_Is_Immediately_Visible (Id);
Prev := Current_Entity (Id);
if Present (Prev)
and then Is_Immediately_Visible (Prev)
and then not Is_Child_Unit (Prev)
then
declare
Clause : Node_Id;
begin
Clause := First (Context_Items (N));
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause
and then Entity (Name (Clause)) = Prev
then
Error_Msg_NE
("child unit& hides compilation unit " &
"with the same name?",
Name (Item), Id);
exit;
end if;
Next (Clause);
end loop;
end;
end if;
elsif Is_Child_Unit (Scope (Id))
and then Is_Ancestor_Package (Scope (Scope (Id)), U_Name)
then
Set_Is_Immediately_Visible (Scope (Id));
end if;
end if;
Next (Item);
end loop;
end Install_Siblings;
procedure Install_Limited_Withed_Unit (N : Node_Id) is
Unum : constant Unit_Number_Type :=
Get_Source_Unit (Library_Unit (N));
P_Unit : constant Entity_Id := Unit (Library_Unit (N));
P : Entity_Id;
Is_Child_Package : Boolean := False;
Lim_Header : Entity_Id;
Lim_Typ : Entity_Id;
function In_Chain (E : Entity_Id) return Boolean;
function In_Chain (E : Entity_Id) return Boolean is
H : Entity_Id := Current_Entity (E);
begin
while Present (H) loop
if H = E then
return True;
else
H := Homonym (H);
end if;
end loop;
return False;
end In_Chain;
begin
case Nkind (P_Unit) is
when N_Package_Declaration =>
null;
when N_Subprogram_Declaration |
N_Generic_Package_Declaration |
N_Generic_Subprogram_Declaration |
N_Package_Instantiation |
N_Function_Instantiation |
N_Procedure_Instantiation |
N_Generic_Package_Renaming_Declaration |
N_Generic_Procedure_Renaming_Declaration |
N_Generic_Function_Renaming_Declaration =>
return;
when others =>
raise Program_Error;
end case;
P := Defining_Unit_Name (Specification (P_Unit));
if Nkind (P) = N_Defining_Program_Unit_Name then
Is_Child_Package := True;
P := Defining_Identifier (P);
end if;
if Analyzed (Cunit (Unum))
and then (Is_Immediately_Visible (P)
or else (Is_Child_Package
and then Is_Visible_Child_Unit (P)))
then
if Private_Present (N)
and then not In_Private_Part (P)
then
declare
Id : Entity_Id;
begin
Id := First_Private_Entity (P);
while Present (Id) loop
if not Is_Internal (Id)
and then not Is_Child_Unit (Id)
then
if not In_Chain (Id) then
Set_Homonym (Id, Current_Entity (Id));
Set_Current_Entity (Id);
end if;
Set_Is_Immediately_Visible (Id);
end if;
Next_Entity (Id);
end loop;
Set_In_Private_Part (P);
end;
end if;
return;
end if;
if Debug_Flag_I then
Write_Str ("install limited view of ");
Write_Name (Chars (P));
Write_Eol;
end if;
if not Analyzed (Cunit (Unum)) then
Set_Ekind (P, E_Package);
Set_Etype (P, Standard_Void_Type);
Set_Scope (P, Standard_Standard);
if Current_Entity (P) /= P then
Set_Homonym (P, Current_Entity (P));
Set_Current_Entity (P);
if Debug_Flag_I then
Write_Str (" (homonym) chain ");
Write_Name (Chars (P));
Write_Eol;
end if;
end if;
if Is_Child_Package then
Set_Is_Child_Unit (P);
Set_Is_Visible_Child_Unit (P);
declare
Parent_Comp : Node_Id;
Parent_Id : Entity_Id;
begin
Parent_Comp := Parent_Spec (Unit (Cunit (Unum)));
Parent_Id := Defining_Entity (Unit (Parent_Comp));
Set_Scope (P, Parent_Id);
end;
end if;
else
declare
Ent : Entity_Id;
begin
Ent := First_Entity (P);
while Present (Ent) loop
Unchain (Ent);
Next_Entity (Ent);
end loop;
end;
end if;
Set_Is_Immediately_Visible (P);
Lim_Header := Limited_View (P);
Lim_Typ := First_Entity (Lim_Header);
while Present (Lim_Typ) loop
exit when not Private_Present (N)
and then Lim_Typ = First_Private_Entity (Lim_Header);
if not In_Chain (Lim_Typ) then
Set_Homonym (Lim_Typ, Current_Entity (Lim_Typ));
Set_Current_Entity (Lim_Typ);
if Debug_Flag_I then
Write_Str (" (homonym) chain ");
Write_Name (Chars (Lim_Typ));
Write_Eol;
end if;
end if;
Next_Entity (Lim_Typ);
end loop;
Set_Limited_View_Installed (N);
Set_From_With_Type (P);
end Install_Limited_Withed_Unit;
procedure Install_Withed_Unit
(With_Clause : Node_Id;
Private_With_OK : Boolean := False)
is
Uname : constant Entity_Id := Entity (Name (With_Clause));
P : constant Entity_Id := Scope (Uname);
begin
if Private_Present (With_Clause)
and then Nkind (Cunit (Current_Sem_Unit)) = N_Package_Declaration
and then not (Private_With_OK)
then
return;
end if;
if Debug_Flag_I then
if Private_Present (With_Clause) then
Write_Str ("install private withed unit ");
else
Write_Str ("install withed unit ");
end if;
Write_Name (Chars (Uname));
Write_Eol;
end if;
if Sloc (Uname) /= No_Location
and then (not Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
or else Current_Sem_Unit = Main_Unit)
then
Check_Restricted_Unit
(Unit_Name (Get_Source_Unit (Uname)), With_Clause);
end if;
if P /= Standard_Standard then
if not Analyzed (Uname)
and then Nkind (Parent (Uname)) = N_Package_Instantiation
then
Error_Msg_N
("instantiation depends on itself", Name (With_Clause));
elsif not Is_Visible_Child_Unit (Uname) then
Set_Is_Visible_Child_Unit (Uname);
if Is_Generic_Instance (Uname)
and then Ekind (Uname) in Subprogram_Kind
then
Set_Is_Visible_Child_Unit
(Related_Instance
(Defining_Entity (Unit (Library_Unit (With_Clause)))));
end if;
if In_Use (Scope (Uname)) then
Set_Is_Potentially_Use_Visible (Uname);
end if;
Set_Context_Installed (With_Clause);
end if;
elsif not Is_Immediately_Visible (Uname) then
if not Private_Present (With_Clause)
or else Private_With_OK
then
Set_Is_Immediately_Visible (Uname);
end if;
Set_Context_Installed (With_Clause);
end if;
if Ekind (Uname) = E_Package then
Set_From_With_Type (Uname, False);
end if;
if Is_Child_Unit (Uname)
and then Is_Visible_Child_Unit (Uname)
and then Ada_Version >= Ada_05
then
declare
Decl1 : constant Node_Id := Unit_Declaration_Node (P);
Decl2 : Node_Id;
P2 : Entity_Id;
U2 : Entity_Id;
begin
U2 := Homonym (Uname);
while Present (U2) loop
P2 := Scope (U2);
Decl2 := Unit_Declaration_Node (P2);
if Is_Child_Unit (U2)
and then Is_Visible_Child_Unit (U2)
then
if Is_Generic_Instance (P)
and then Nkind (Decl1) = N_Package_Declaration
and then Generic_Parent (Specification (Decl1)) = P2
then
Error_Msg_N ("illegal with_clause", With_Clause);
Error_Msg_N
("\child unit has visible homograph" &
" ('R'M 8.3(26), 10.1.1(19))",
With_Clause);
exit;
elsif Is_Generic_Instance (P2)
and then Nkind (Decl2) = N_Package_Declaration
and then Generic_Parent (Specification (Decl2)) = P
then
declare
Prev_Clause : Node_Id;
begin
Prev_Clause := First (List_Containing (With_Clause));
while Entity (Name (Prev_Clause)) /= U2 loop
Next (Prev_Clause);
end loop;
pragma Assert (Present (Prev_Clause));
Error_Msg_N ("illegal with_clause", Prev_Clause);
Error_Msg_N
("\child unit has visible homograph" &
" ('R'M 8.3(26), 10.1.1(19))",
Prev_Clause);
exit;
end;
end if;
end if;
U2 := Homonym (U2);
end loop;
end;
end if;
end Install_Withed_Unit;
function Is_Child_Spec (Lib_Unit : Node_Id) return Boolean is
K : constant Node_Kind := Nkind (Lib_Unit);
begin
return (K in N_Generic_Declaration or else
K in N_Generic_Instantiation or else
K in N_Generic_Renaming_Declaration or else
K = N_Package_Declaration or else
K = N_Package_Renaming_Declaration or else
K = N_Subprogram_Declaration or else
K = N_Subprogram_Renaming_Declaration)
and then Present (Parent_Spec (Lib_Unit));
end Is_Child_Spec;
procedure Load_Needed_Body (N : Node_Id; OK : out Boolean) is
Body_Name : Unit_Name_Type;
Unum : Unit_Number_Type;
Save_Style_Check : constant Boolean := Opt.Style_Check;
begin
if not GNAT_Mode then
Style_Check := False;
end if;
Body_Name := Get_Body_Name (Get_Unit_Name (Unit (N)));
Unum :=
Load_Unit
(Load_Name => Body_Name,
Required => False,
Subunit => False,
Error_Node => N,
Renamings => True);
if Unum = No_Unit then
OK := False;
else
Compiler_State := Analyzing;
if not Fatal_Error (Unum) or else Try_Semantics then
if Debug_Flag_L then
Write_Str ("*** Loaded generic body");
Write_Eol;
end if;
Semantics (Cunit (Unum));
end if;
OK := True;
end if;
Style_Check := Save_Style_Check;
end Load_Needed_Body;
procedure Build_Limited_Views (N : Node_Id) is
Unum : constant Unit_Number_Type := Get_Source_Unit (Library_Unit (N));
P : constant Entity_Id := Cunit_Entity (Unum);
Spec : Node_Id; Lim_Typ : Entity_Id; Comp_Typ : Entity_Id;
Lim_Header : Entity_Id; Last_Lim_E : Entity_Id := Empty; Last_Pub_Lim_E : Entity_Id;
procedure Decorate_Incomplete_Type
(E : Entity_Id;
Scop : Entity_Id);
procedure Decorate_Package_Specification (P : Entity_Id);
procedure Decorate_Tagged_Type
(Loc : Source_Ptr;
T : Entity_Id;
Scop : Entity_Id);
procedure Build_Chain
(Scope : Entity_Id;
First_Decl : Node_Id);
function New_Internal_Shadow_Entity
(Kind : Entity_Kind;
Sloc_Value : Source_Ptr;
Id_Char : Character) return Entity_Id;
procedure Decorate_Incomplete_Type
(E : Entity_Id;
Scop : Entity_Id)
is
begin
Set_Ekind (E, E_Incomplete_Type);
Set_Scope (E, Scop);
Set_Etype (E, E);
Set_Is_First_Subtype (E, True);
Set_Stored_Constraint (E, No_Elist);
Set_Full_View (E, Empty);
Init_Size_Align (E);
end Decorate_Incomplete_Type;
procedure Decorate_Tagged_Type
(Loc : Source_Ptr;
T : Entity_Id;
Scop : Entity_Id)
is
CW : Entity_Id;
begin
Decorate_Incomplete_Type (T, Scop);
Set_Is_Tagged_Type (T);
if No (Class_Wide_Type (T)) then
CW := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
Set_Ekind (CW, E_Class_Wide_Type);
Set_Etype (CW, T);
Set_Scope (CW, Scop);
Set_Is_Tagged_Type (CW);
Set_Is_First_Subtype (CW, True);
Init_Size_Align (CW);
Set_Has_Unknown_Discriminants (CW, True);
Set_Class_Wide_Type (CW, CW);
Set_Equivalent_Type (CW, Empty);
Set_From_With_Type (CW, From_With_Type (T));
Set_Class_Wide_Type (T, CW);
end if;
end Decorate_Tagged_Type;
procedure Decorate_Package_Specification (P : Entity_Id) is
begin
Set_Ekind (P, E_Package);
Set_Etype (P, Standard_Void_Type);
end Decorate_Package_Specification;
function New_Internal_Shadow_Entity
(Kind : Entity_Kind;
Sloc_Value : Source_Ptr;
Id_Char : Character) return Entity_Id
is
E : constant Entity_Id :=
Make_Defining_Identifier (Sloc_Value,
Chars => New_Internal_Name (Id_Char));
begin
Set_Ekind (E, Kind);
Set_Is_Internal (E, True);
if Kind in Type_Kind then
Init_Size_Align (E);
end if;
Append_Entity (E, Lim_Header);
Last_Lim_E := E;
return E;
end New_Internal_Shadow_Entity;
procedure Build_Chain
(Scope : Entity_Id;
First_Decl : Node_Id)
is
Analyzed_Unit : constant Boolean := Analyzed (Cunit (Unum));
Is_Tagged : Boolean;
Decl : Node_Id;
begin
Decl := First_Decl;
while Present (Decl) loop
if Nkind (Decl) = N_Full_Type_Declaration then
Is_Tagged :=
Nkind (Type_Definition (Decl)) = N_Record_Definition
and then Tagged_Present (Type_Definition (Decl));
Comp_Typ := Defining_Identifier (Decl);
if not Analyzed_Unit then
if Is_Tagged then
Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
else
Decorate_Incomplete_Type (Comp_Typ, Scope);
end if;
end if;
Lim_Typ := New_Internal_Shadow_Entity
(Kind => Ekind (Comp_Typ),
Sloc_Value => Sloc (Comp_Typ),
Id_Char => 'Z');
Set_Chars (Lim_Typ, Chars (Comp_Typ));
Set_Parent (Lim_Typ, Parent (Comp_Typ));
Set_From_With_Type (Lim_Typ);
if Is_Tagged then
Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
else
Decorate_Incomplete_Type (Lim_Typ, Scope);
end if;
Set_Non_Limited_View (Lim_Typ, Comp_Typ);
elsif Nkind (Decl) = N_Private_Type_Declaration
and then Tagged_Present (Decl)
then
Comp_Typ := Defining_Identifier (Decl);
if not Analyzed_Unit then
Decorate_Tagged_Type (Sloc (Decl), Comp_Typ, Scope);
end if;
Lim_Typ := New_Internal_Shadow_Entity
(Kind => Ekind (Comp_Typ),
Sloc_Value => Sloc (Comp_Typ),
Id_Char => 'Z');
Set_Chars (Lim_Typ, Chars (Comp_Typ));
Set_Parent (Lim_Typ, Parent (Comp_Typ));
Set_From_With_Type (Lim_Typ);
Decorate_Tagged_Type (Sloc (Decl), Lim_Typ, Scope);
Set_Non_Limited_View (Lim_Typ, Comp_Typ);
elsif Nkind (Decl) = N_Package_Declaration then
declare
Spec : constant Node_Id := Specification (Decl);
begin
Comp_Typ := Defining_Unit_Name (Spec);
if not Analyzed (Cunit (Unum)) then
Decorate_Package_Specification (Comp_Typ);
Set_Scope (Comp_Typ, Scope);
end if;
Lim_Typ := New_Internal_Shadow_Entity
(Kind => Ekind (Comp_Typ),
Sloc_Value => Sloc (Comp_Typ),
Id_Char => 'Z');
Decorate_Package_Specification (Lim_Typ);
Set_Scope (Lim_Typ, Scope);
Set_Chars (Lim_Typ, Chars (Comp_Typ));
Set_Parent (Lim_Typ, Parent (Comp_Typ));
Set_From_With_Type (Lim_Typ);
Build_Chain
(Scope => Lim_Typ,
First_Decl => First (Visible_Declarations (Spec)));
end;
end if;
Next (Decl);
end loop;
end Build_Chain;
begin
pragma Assert (Limited_Present (N));
case Nkind (Unit (Library_Unit (N))) is
when N_Package_Declaration =>
null;
when N_Subprogram_Declaration =>
Error_Msg_N ("subprograms not allowed in "
& "limited with_clauses", N);
return;
when N_Generic_Package_Declaration |
N_Generic_Subprogram_Declaration =>
Error_Msg_N ("generics not allowed in "
& "limited with_clauses", N);
return;
when N_Package_Instantiation |
N_Function_Instantiation |
N_Procedure_Instantiation =>
Error_Msg_N ("generic instantiations not allowed in "
& "limited with_clauses", N);
return;
when N_Generic_Package_Renaming_Declaration |
N_Generic_Procedure_Renaming_Declaration |
N_Generic_Function_Renaming_Declaration =>
Error_Msg_N ("generic renamings not allowed in "
& "limited with_clauses", N);
return;
when others =>
raise Program_Error;
end case;
Spec := Specification (Unit (Library_Unit (N)));
if Limited_View_Installed (Spec) then
return;
end if;
Set_Ekind (P, E_Package);
Lim_Header := Make_Defining_Identifier (Sloc (N),
Chars => New_Internal_Name (Id_Char => 'Z'));
Set_Ekind (Lim_Header, E_Package);
Set_Is_Internal (Lim_Header);
Set_Limited_View (P, Lim_Header);
Build_Chain
(Scope => P,
First_Decl => First (Visible_Declarations (Spec)));
Last_Pub_Lim_E := Last_Lim_E;
Build_Chain (Scope => P,
First_Decl => First (Private_Declarations (Spec)));
if Last_Pub_Lim_E /= Empty then
Set_First_Private_Entity (Lim_Header,
Next_Entity (Last_Pub_Lim_E));
else
Set_First_Private_Entity (Lim_Header,
First_Entity (P));
end if;
Set_Limited_View_Installed (Spec);
end Build_Limited_Views;
procedure Check_Body_Needed_For_SAL (Unit_Name : Entity_Id) is
function Entity_Needs_Body (E : Entity_Id) return Boolean;
function Entity_Needs_Body (E : Entity_Id) return Boolean is
Ent : Entity_Id;
begin
if Is_Subprogram (E)
and then Has_Pragma_Inline (E)
then
return True;
elsif Ekind (E) = E_Generic_Function
or else Ekind (E) = E_Generic_Procedure
then
return True;
elsif Ekind (E) = E_Generic_Package
and then
Nkind (Unit_Declaration_Node (E)) = N_Generic_Package_Declaration
and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
then
return True;
elsif Ekind (E) = E_Package
and then
Nkind (Unit_Declaration_Node (E)) = N_Package_Declaration
and then Present (Corresponding_Body (Unit_Declaration_Node (E)))
then
Ent := First_Entity (E);
while Present (Ent) loop
if Entity_Needs_Body (Ent) then
return True;
end if;
Next_Entity (Ent);
end loop;
return False;
else
return False;
end if;
end Entity_Needs_Body;
begin
if Ekind (Unit_Name) = E_Generic_Package
and then
Nkind (Unit_Declaration_Node (Unit_Name)) =
N_Generic_Package_Declaration
and then
Present (Corresponding_Body (Unit_Declaration_Node (Unit_Name)))
then
Set_Body_Needed_For_SAL (Unit_Name);
elsif Ekind (Unit_Name) = E_Generic_Procedure
or else Ekind (Unit_Name) = E_Generic_Function
then
Set_Body_Needed_For_SAL (Unit_Name);
elsif Is_Subprogram (Unit_Name)
and then Nkind (Unit_Declaration_Node (Unit_Name)) =
N_Subprogram_Declaration
and then Has_Pragma_Inline (Unit_Name)
then
Set_Body_Needed_For_SAL (Unit_Name);
elsif Ekind (Unit_Name) = E_Subprogram_Body then
Check_Body_Needed_For_SAL
(Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
elsif Ekind (Unit_Name) = E_Package
and then Entity_Needs_Body (Unit_Name)
then
Set_Body_Needed_For_SAL (Unit_Name);
elsif Ekind (Unit_Name) = E_Package_Body
and then Nkind (Unit_Declaration_Node (Unit_Name)) = N_Package_Body
then
Check_Body_Needed_For_SAL
(Corresponding_Spec (Unit_Declaration_Node (Unit_Name)));
end if;
end Check_Body_Needed_For_SAL;
procedure Remove_Context (N : Node_Id) is
Lib_Unit : constant Node_Id := Unit (N);
begin
if Is_Child_Spec (Lib_Unit) then
Remove_Parents (Lib_Unit);
end if;
Remove_Context_Clauses (N);
end Remove_Context;
procedure Remove_Context_Clauses (N : Node_Id) is
Item : Node_Id;
Unit_Name : Entity_Id;
begin
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
and then Limited_View_Installed (Item)
then
Remove_Limited_With_Clause (Item);
end if;
Next (Item);
end loop;
Item := First (Context_Items (N));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then Limited_Present (Item)
and then Limited_View_Installed (Item)
then
null;
elsif Nkind (Item) = N_With_Clause
and then Context_Installed (Item)
then
Unit_Name := Entity (Name (Item));
Remove_Unit_From_Visibility (Unit_Name);
Set_Context_Installed (Item, False);
elsif Nkind (Item) = N_Use_Package_Clause then
End_Use_Package (Item);
elsif Nkind (Item) = N_Use_Type_Clause then
End_Use_Type (Item);
elsif Nkind (Item) = N_With_Type_Clause then
Remove_With_Type_Clause (Name (Item));
end if;
Next (Item);
end loop;
end Remove_Context_Clauses;
procedure Remove_Limited_With_Clause (N : Node_Id) is
P_Unit : constant Entity_Id := Unit (Library_Unit (N));
P : Entity_Id := Defining_Unit_Name (Specification (P_Unit));
Lim_Typ : Entity_Id;
begin
if Nkind (P) = N_Defining_Program_Unit_Name then
P := Defining_Identifier (P);
end if;
if Debug_Flag_I then
Write_Str ("remove limited view of ");
Write_Name (Chars (P));
Write_Str (" from visibility");
Write_Eol;
end if;
Lim_Typ := First_Entity (Limited_View (P));
while Present (Lim_Typ) loop
Unchain (Lim_Typ);
Next_Entity (Lim_Typ);
end loop;
Set_From_With_Type (P, False);
Set_Limited_View_Installed (N, False);
if not Analyzed (P_Unit) then
Unchain (P);
Set_First_Entity (P, Empty);
Set_Last_Entity (P, Empty);
Set_Ekind (P, E_Void);
Set_Scope (P, Empty);
Set_Is_Immediately_Visible (P, False);
else
declare
Ent : Entity_Id;
begin
Ent := First_Entity (P);
while Present (Ent) and then Ent /= First_Private_Entity (P) loop
if not Is_Class_Wide_Type (Ent) then
Set_Homonym (Ent, Current_Entity (Ent));
Set_Current_Entity (Ent);
if Debug_Flag_I then
Write_Str (" (homonym) chain ");
Write_Name (Chars (Ent));
Write_Eol;
end if;
end if;
Next_Entity (Ent);
end loop;
end;
end if;
end Remove_Limited_With_Clause;
procedure Remove_Parents (Lib_Unit : Node_Id) is
P : Node_Id;
P_Name : Entity_Id;
P_Spec : Node_Id := Empty;
E : Entity_Id;
Vis : constant Boolean :=
Scope_Stack.Table (Scope_Stack.Last).Previous_Visibility;
begin
if Is_Child_Spec (Lib_Unit) then
P_Spec := Parent_Spec (Lib_Unit);
elsif Nkind (Lib_Unit) = N_Package_Body
and then Nkind (Original_Node (Lib_Unit)) = N_Package_Instantiation
then
P_Spec := Parent_Spec (Original_Node (Lib_Unit));
end if;
if Present (P_Spec) then
P := Unit (P_Spec);
P_Name := Get_Parent_Entity (P);
Remove_Context_Clauses (P_Spec);
End_Package_Scope (P_Name);
Set_Is_Immediately_Visible (P_Name, Vis);
E := First_Entity (P_Name);
while Present (E) loop
if Is_Child_Unit (E) then
Set_Is_Immediately_Visible (E, False);
end if;
Next_Entity (E);
end loop;
Set_In_Package_Body (P_Name, False);
Remove_Parents (P);
end if;
end Remove_Parents;
procedure Remove_With_Type_Clause (Name : Node_Id) is
Typ : Entity_Id;
P : Entity_Id;
procedure Unchain (E : Entity_Id);
procedure Unchain (E : Entity_Id) is
Prev : Entity_Id;
begin
Prev := Current_Entity (E);
if No (Prev) then
return;
elsif Prev = E then
Set_Name_Entity_Id (Chars (E), Homonym (E));
else
while Present (Prev)
and then Homonym (Prev) /= E
loop
Prev := Homonym (Prev);
end loop;
if Present (Prev) then
Set_Homonym (Prev, Homonym (E));
end if;
end if;
end Unchain;
begin
if Nkind (Name) = N_Selected_Component then
Typ := Entity (Selector_Name (Name));
if No (Typ) then
return;
end if;
else
return;
end if;
P := Scope (Typ);
if not Analyzed (Unit_Declaration_Node (P)) then
Unchain (P);
Unchain (Typ);
Set_Is_Frozen (Typ, False);
end if;
if Ekind (Typ) = E_Record_Type then
Set_From_With_Type (Class_Wide_Type (Typ), False);
Set_From_With_Type (Typ, False);
end if;
Set_From_With_Type (P, False);
P := Scope (P);
while Present (P)
and then P /= Standard_Standard
loop
Set_From_With_Type (P, False);
if not Analyzed (Unit_Declaration_Node (P)) then
Unchain (P);
end if;
P := Scope (P);
end loop;
end Remove_With_Type_Clause;
procedure Remove_Unit_From_Visibility (Unit_Name : Entity_Id) is
P : constant Entity_Id := Scope (Unit_Name);
begin
if Debug_Flag_I then
Write_Str ("remove unit ");
Write_Name (Chars (Unit_Name));
Write_Str (" from visibility");
Write_Eol;
end if;
if P /= Standard_Standard then
Set_Is_Visible_Child_Unit (Unit_Name, False);
end if;
Set_Is_Potentially_Use_Visible (Unit_Name, False);
Set_Is_Immediately_Visible (Unit_Name, False);
end Remove_Unit_From_Visibility;
procedure Unchain (E : Entity_Id) is
Prev : Entity_Id;
begin
Prev := Current_Entity (E);
if No (Prev) then
return;
elsif Prev = E then
Set_Name_Entity_Id (Chars (E), Homonym (E));
else
while Present (Prev)
and then Homonym (Prev) /= E
loop
Prev := Homonym (Prev);
end loop;
if Present (Prev) then
Set_Homonym (Prev, Homonym (E));
end if;
end if;
if Debug_Flag_I then
Write_Str (" (homonym) unchain ");
Write_Name (Chars (E));
Write_Eol;
end if;
end Unchain;
end Sem_Ch10;