with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Util; use Exp_Util;
with Fname; use Fname;
with Freeze; use Freeze;
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_Ch3; use Sem_Ch3;
with Sem_Ch4; use Sem_Ch4;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch12; use Sem_Ch12;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sem_Type; use Sem_Type;
with Stand; use Stand;
with Sinfo; use Sinfo;
with Sinfo.CN; use Sinfo.CN;
with Snames; use Snames;
with Style; use Style;
with Table;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
package body Sem_Ch8 is
type Uref_Entry is record
Node : Node_Id;
Err : Error_Msg_Id;
Nvis : Boolean;
Loc : Source_Ptr;
end record;
package Urefs is new Table.Table (
Table_Component_Type => Uref_Entry,
Table_Index_Type => Nat,
Table_Low_Bound => 1,
Table_Initial => 10,
Table_Increment => 100,
Table_Name => "Urefs");
Candidate_Renaming : Entity_Id;
procedure Analyze_Generic_Renaming
(N : Node_Id;
K : Entity_Kind);
procedure Analyze_Renamed_Character
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
procedure Analyze_Renamed_Dereference
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
procedure Analyze_Renamed_Entry
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
procedure Analyze_Renamed_Family_Member
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean);
procedure Attribute_Renaming (N : Node_Id);
procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
procedure Chain_Use_Clause (N : Node_Id);
function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
function Find_Renamed_Entity
(N : Node_Id;
Nam : Node_Id;
New_S : Entity_Id;
Is_Actual : Boolean := False) return Entity_Id;
procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
procedure Premature_Usage (N : Node_Id);
procedure Write_Info;
procedure Write_Scopes;
pragma Warnings (Off, Write_Scopes);
procedure Analyze_Exception_Renaming (N : Node_Id) is
Id : constant Node_Id := Defining_Identifier (N);
Nam : constant Node_Id := Name (N);
begin
Enter_Name (Id);
Analyze (Nam);
Set_Ekind (Id, E_Exception);
Set_Exception_Code (Id, Uint_0);
Set_Etype (Id, Standard_Exception_Type);
Set_Is_Pure (Id, Is_Pure (Current_Scope));
if not Is_Entity_Name (Nam) or else
Ekind (Entity (Nam)) /= E_Exception
then
Error_Msg_N ("invalid exception name in renaming", Nam);
else
if Present (Renamed_Object (Entity (Nam))) then
Set_Renamed_Object (Id, Renamed_Object (Entity (Nam)));
else
Set_Renamed_Object (Id, Entity (Nam));
end if;
end if;
end Analyze_Exception_Renaming;
procedure Analyze_Expanded_Name (N : Node_Id) is
begin
if Present (Entity (N)) then
if Is_Type (Entity (N)) then
Set_Etype (N, Entity (N));
else
Set_Etype (N, Etype (Entity (N)));
end if;
Analyze (Prefix (N));
return;
else
Find_Expanded_Name (N);
end if;
end Analyze_Expanded_Name;
procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
begin
Analyze_Generic_Renaming (N, E_Generic_Function);
end Analyze_Generic_Function_Renaming;
procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
begin
Text_IO_Kludge (Name (N));
Analyze_Generic_Renaming (N, E_Generic_Package);
end Analyze_Generic_Package_Renaming;
procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
begin
Analyze_Generic_Renaming (N, E_Generic_Procedure);
end Analyze_Generic_Procedure_Renaming;
procedure Analyze_Generic_Renaming
(N : Node_Id;
K : Entity_Kind)
is
New_P : Entity_Id := Defining_Entity (N);
Old_P : Entity_Id;
Inst : Boolean := False;
begin
if Name (N) = Error then
return;
end if;
Generate_Definition (New_P);
if Current_Scope /= Standard_Standard then
Set_Is_Pure (New_P, Is_Pure (Current_Scope));
end if;
if Nkind (Name (N)) = N_Selected_Component then
Check_Generic_Child_Unit (Name (N), Inst);
else
Analyze (Name (N));
end if;
if not Is_Entity_Name (Name (N)) then
Error_Msg_N ("expect entity name in renaming declaration", Name (N));
Old_P := Any_Id;
else
Old_P := Entity (Name (N));
end if;
Enter_Name (New_P);
Set_Ekind (New_P, K);
if Etype (Old_P) = Any_Type then
null;
elsif Ekind (Old_P) /= K then
Error_Msg_N ("invalid generic unit name", Name (N));
else
if Present (Renamed_Object (Old_P)) then
Set_Renamed_Object (New_P, Renamed_Object (Old_P));
else
Set_Renamed_Object (New_P, Old_P);
end if;
Set_Etype (New_P, Etype (Old_P));
Set_Has_Completion (New_P);
if In_Open_Scopes (Old_P) then
Error_Msg_N ("within its scope, generic denotes its instance", N);
end if;
Check_Library_Unit_Renaming (N, Old_P);
end if;
end Analyze_Generic_Renaming;
procedure Analyze_Object_Renaming (N : Node_Id) is
Id : constant Entity_Id := Defining_Identifier (N);
Dec : Node_Id;
Nam : constant Node_Id := Name (N);
S : constant Entity_Id := Subtype_Mark (N);
T : Entity_Id;
T2 : Entity_Id;
begin
if Nam = Error then
return;
end if;
Set_Is_Pure (Id, Is_Pure (Current_Scope));
Enter_Name (Id);
if Nkind (Nam) = N_Selected_Component
and then Analyzed (Nam)
then
T := Etype (Nam);
Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
if Present (Dec) then
Insert_Action (N, Dec);
T := Defining_Identifier (Dec);
Set_Etype (Nam, T);
end if;
else
Find_Type (S);
T := Entity (S);
Analyze_And_Resolve (Nam, T);
end if;
if Is_Class_Wide_Type (T)
and then Base_Type (Etype (Nam)) /= Base_Type (T)
then
Wrong_Type (Nam, T);
end if;
T2 := Etype (Nam);
Set_Ekind (Id, E_Variable);
Init_Size_Align (Id);
if T = Any_Type or else Etype (Nam) = Any_Type then
return;
elsif Is_Object_Reference (Nam) then
if Comes_From_Source (N)
and then Is_Dependent_Component_Of_Mutable_Object (Nam)
then
Error_Msg_N
("illegal renaming of discriminant-dependent component", Nam);
else
null;
end if;
elsif Nkind (Original_Node (Nam)) = N_Function_Call
or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
and then Is_Function_Attribute_Name
(Attribute_Name (Original_Node (Nam))))
or else (Is_Entity_Name (Nam)
and then Ekind (Entity (Nam)) = E_Enumeration_Literal)
or else (Nkind (Nam) = N_Type_Conversion
and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
then
null;
else
if Nkind (Nam) = N_Type_Conversion then
Error_Msg_N
("renaming of conversion only allowed for tagged types", Nam);
else
Error_Msg_N ("expect object name in renaming", Nam);
end if;
end if;
Set_Etype (Id, T2);
if not Is_Variable (Nam) then
Set_Ekind (Id, E_Constant);
Set_Not_Source_Assigned (Id, True);
Set_Is_True_Constant (Id, True);
end if;
Set_Renamed_Object (Id, Nam);
end Analyze_Object_Renaming;
procedure Analyze_Package_Renaming (N : Node_Id) is
New_P : constant Entity_Id := Defining_Entity (N);
Old_P : Entity_Id;
Spec : Node_Id;
begin
if Name (N) = Error then
return;
end if;
Text_IO_Kludge (Name (N));
if Current_Scope /= Standard_Standard then
Set_Is_Pure (New_P, Is_Pure (Current_Scope));
end if;
Enter_Name (New_P);
Analyze (Name (N));
if Is_Entity_Name (Name (N)) then
Old_P := Entity (Name (N));
else
Old_P := Any_Id;
end if;
if Etype (Old_P) = Any_Type then
Error_Msg_N
("expect package name in renaming", Name (N));
elsif Ekind (Old_P) /= E_Package
and then not (Ekind (Old_P) = E_Generic_Package
and then In_Open_Scopes (Old_P))
then
if Ekind (Old_P) = E_Generic_Package then
Error_Msg_N
("generic package cannot be renamed as a package", Name (N));
else
Error_Msg_Sloc := Sloc (Old_P);
Error_Msg_NE
("expect package name in renaming, found& declared#",
Name (N), Old_P);
end if;
Set_Ekind (New_P, E_Package);
Set_Etype (New_P, Standard_Void_Type);
elsif Ekind (Old_P) = E_Package
and then From_With_Type (Old_P)
then
Error_Msg_N ("imported package cannot be renamed", Name (N));
else
Set_Ekind (New_P, E_Package);
Set_Etype (New_P, Standard_Void_Type);
if Present (Renamed_Object (Old_P)) then
Set_Renamed_Object (New_P, Renamed_Object (Old_P));
else
Set_Renamed_Object (New_P, Old_P);
end if;
Set_Has_Completion (New_P);
Set_First_Entity (New_P, First_Entity (Old_P));
Set_Last_Entity (New_P, Last_Entity (Old_P));
Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
Check_Library_Unit_Renaming (N, Old_P);
Generate_Reference (Old_P, Name (N));
if not Is_Generic_Instance (Old_P) then
return;
else
Spec := Specification (Unit_Declaration_Node (Old_P));
end if;
if Nkind (Spec) = N_Package_Specification
and then Present (Generic_Parent (Spec))
and then Old_P = Current_Scope
and then Chars (New_P) = Chars (Generic_Parent (Spec))
then
declare
E : Entity_Id := First_Entity (Old_P);
begin
while Present (E)
and then E /= New_P
loop
if Is_Type (E)
and then Nkind (Parent (E)) = N_Subtype_Declaration
then
Set_Is_Generic_Actual_Type (E);
if Is_Private_Type (E)
and then Present (Full_View (E))
then
Set_Is_Generic_Actual_Type (Full_View (E));
end if;
end if;
Next_Entity (E);
end loop;
end;
end if;
end if;
end Analyze_Package_Renaming;
procedure Analyze_Renamed_Character
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
C : constant Node_Id := Name (N);
begin
if Ekind (New_S) = E_Function then
Resolve (C, Etype (New_S));
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
else
Error_Msg_N ("character literal can only be renamed as function", N);
end if;
end Analyze_Renamed_Character;
procedure Analyze_Renamed_Dereference
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Nam : constant Node_Id := Name (N);
P : constant Node_Id := Prefix (Nam);
Typ : Entity_Id;
I : Interp_Index;
It : Interp;
begin
if not Is_Overloaded (P) then
if Ekind (Etype (Nam)) /= E_Subprogram_Type
or else not Type_Conformant (Etype (Nam), New_S) then
Error_Msg_N ("designated type does not match specification", P);
else
Resolve (P, Etype (P));
end if;
return;
else
Typ := Any_Type;
Get_First_Interp (Nam, I, It);
while Present (It.Nam) loop
if Ekind (It.Nam) = E_Subprogram_Type
and then Type_Conformant (It.Nam, New_S) then
if Typ /= Any_Id then
Error_Msg_N ("ambiguous renaming", P);
return;
else
Typ := It.Nam;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
if Typ = Any_Type then
Error_Msg_N ("designated type does not match specification", P);
else
Resolve (N, Typ);
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
end if;
end if;
end Analyze_Renamed_Dereference;
procedure Analyze_Renamed_Entry
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Nam : Node_Id := Name (N);
Sel : Node_Id := Selector_Name (Nam);
Old_S : Entity_Id;
begin
if Entity (Sel) = Any_Id then
Set_Has_Completion (New_S);
return;
end if;
Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
if Old_S = Any_Id then
Error_Msg_N (" no subprogram or entry matches specification", N);
else
if Is_Body then
Check_Subtype_Conformant (New_S, Old_S, N);
Generate_Reference (New_S, Defining_Entity (N), 'b');
Style.Check_Identifier (Defining_Entity (N), New_S);
end if;
Inherit_Renamed_Profile (New_S, Old_S);
end if;
Set_Convention (New_S, Convention (Old_S));
Set_Has_Completion (New_S, Inside_A_Generic);
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
end Analyze_Renamed_Entry;
procedure Analyze_Renamed_Family_Member
(N : Node_Id;
New_S : Entity_Id;
Is_Body : Boolean)
is
Nam : Node_Id := Name (N);
P : Node_Id := Prefix (Nam);
Old_S : Entity_Id;
begin
if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
or else (Nkind (P) = N_Selected_Component
and then
Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
then
if Is_Entity_Name (P) then
Old_S := Entity (P);
else
Old_S := Entity (Selector_Name (P));
end if;
if not Entity_Matches_Spec (Old_S, New_S) then
Error_Msg_N ("entry family does not match specification", N);
elsif Is_Body then
Check_Subtype_Conformant (New_S, Old_S, N);
Generate_Reference (New_S, Defining_Entity (N), 'b');
Style.Check_Identifier (Defining_Entity (N), New_S);
end if;
else
Error_Msg_N ("no entry family matches specification", N);
end if;
Set_Has_Completion (New_S, Inside_A_Generic);
if Is_Body then
Check_Frozen_Renaming (N, New_S);
end if;
end Analyze_Renamed_Family_Member;
procedure Analyze_Subprogram_Renaming (N : Node_Id) is
Nam : Node_Id := Name (N);
Spec : constant Node_Id := Specification (N);
New_S : Entity_Id;
Old_S : Entity_Id := Empty;
Rename_Spec : Entity_Id;
Is_Actual : Boolean := False;
Inst_Node : Node_Id := Empty;
Save_83 : Boolean := Ada_83;
function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
Orig_Decl : Node_Id;
Orig_Subp : Entity_Id;
begin
if Present (Alias (Subp)) then
return Alias (Subp);
elsif
Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
and then Present
(Corresponding_Body (Unit_Declaration_Node (Subp)))
then
Orig_Decl :=
Unit_Declaration_Node
(Corresponding_Body (Unit_Declaration_Node (Subp)));
if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
Orig_Subp := Entity (Name (Orig_Decl));
if Orig_Subp = Rename_Spec then
return Orig_Subp;
else
return (Original_Subprogram (Orig_Subp));
end if;
else
return Subp;
end if;
else
return Subp;
end if;
end Original_Subprogram;
begin
if Nkind (Nam) = N_Attribute_Reference then
Attribute_Renaming (N);
return;
end if;
if Present (Corresponding_Spec (N)) then
Is_Actual := True;
Inst_Node := Corresponding_Spec (N);
if Is_Entity_Name (Nam)
and then Present (Entity (Nam))
and then not Comes_From_Source (Nam)
and then not Is_Overloaded (Nam)
then
Old_S := Entity (Nam);
New_S := Analyze_Spec (Spec);
if Ekind (Entity (Nam)) = E_Operator
and then Box_Present (Corresponding_Spec (N))
then
Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
end if;
else
Analyze (Nam);
New_S := Analyze_Spec (Spec);
end if;
Set_Corresponding_Spec (N, Empty);
else
Analyze (Nam);
New_S := Analyze_Spec (Spec);
end if;
if Current_Scope /= Standard_Standard then
Set_Is_Pure (New_S, Is_Pure (Current_Scope));
end if;
Rename_Spec := Find_Corresponding_Spec (N);
if Present (Rename_Spec) then
Set_Corresponding_Spec (N, Rename_Spec);
Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
Set_Has_Completion (Rename_Spec, Inside_A_Generic);
if Ada_83 and then Comes_From_Source (N) then
Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
end if;
Set_Convention (New_S, Convention (Rename_Spec));
Check_Fully_Conformant (New_S, Rename_Spec);
Set_Public_Status (New_S);
Set_Ekind (New_S, E_Subprogram_Body);
New_S := Rename_Spec;
else
Generate_Definition (New_S);
New_Overloaded_Entity (New_S);
if Is_Entity_Name (Nam)
and then Is_Intrinsic_Subprogram (Entity (Nam))
then
null;
else
Check_Delayed_Subprogram (New_S);
end if;
end if;
Set_Suppress_Elaboration_Checks (New_S, True);
if Etype (Nam) = Any_Type then
Set_Has_Completion (New_S);
return;
elsif Nkind (Nam) = N_Selected_Component then
Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
return;
elsif Nkind (Nam) = N_Explicit_Dereference then
Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
return;
elsif Nkind (Nam) = N_Indexed_Component then
Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
return;
elsif Nkind (Nam) = N_Character_Literal then
Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
return;
elsif (not Is_Entity_Name (Nam)
and then Nkind (Nam) /= N_Operator_Symbol)
or else not Is_Overloadable (Entity (Nam))
then
Error_Msg_N ("expect valid subprogram name in renaming", N);
return;
end if;
if No (Rename_Spec) then
Set_Has_Completion (New_S);
end if;
Ada_83 := False;
if No (Old_S) then
Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
end if;
if Old_S /= Any_Id then
if Is_Actual
and then Box_Present (Inst_Node)
then
Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
else
Generate_Reference (Old_S, Nam);
end if;
if Present (Rename_Spec) then
Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
if not Is_Frozen (Rename_Spec) then
if not Has_Convention_Pragma (Rename_Spec) then
Set_Convention (New_S, Convention (Old_S));
end if;
if Ekind (Old_S) /= E_Operator then
Check_Mode_Conformant (New_S, Old_S, Spec);
end if;
if Original_Subprogram (Old_S) = Rename_Spec then
Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
end if;
else
Check_Subtype_Conformant (New_S, Old_S, Spec);
end if;
Check_Frozen_Renaming (N, Rename_Spec);
elsif Ekind (Old_S) /= E_Operator then
Check_Mode_Conformant (New_S, Old_S);
if Is_Actual
and then Error_Posted (New_S)
then
Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
end if;
end if;
if No (Rename_Spec) then
Inherit_Renamed_Profile (New_S, Old_S);
if Present (Alias (Old_S)) then
Set_Alias (New_S, Alias (Old_S));
else
Set_Alias (New_S, Old_S);
end if;
Set_Is_Intrinsic_Subprogram
(New_S, Is_Intrinsic_Subprogram (Old_S));
if Ekind (Alias (New_S)) = E_Operator then
Set_Has_Delayed_Freeze (New_S, False);
end if;
end if;
if not Is_Actual
and then (Old_S = New_S
or else (Nkind (Nam) /= N_Expanded_Name
and then Chars (Old_S) = Chars (New_S)))
then
Error_Msg_N ("subprogram cannot rename itself", N);
end if;
Set_Convention (New_S, Convention (Old_S));
Set_Is_Abstract (New_S, Is_Abstract (Old_S));
Check_Library_Unit_Renaming (N, Old_S);
if Ekind (Old_S) = E_Entry then
Set_Has_Completion (New_S, False);
Set_Alias (New_S, Empty);
end if;
if Is_Actual then
Freeze_Before (N, Old_S);
Set_Has_Delayed_Freeze (New_S, False);
Freeze_Before (N, New_S);
if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
and then Is_Abstract (Old_S)
then
Error_Msg_N
("abstract subprogram not allowed as generic actual", Nam);
end if;
end if;
else
if Nkind (Nam) = N_Expanded_Name
and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
and then Scope (Entity (Nam)) = Standard_Standard
then
declare
T : constant Entity_Id :=
Base_Type (Etype (First_Formal (New_S)));
begin
Error_Msg_Node_2 := Prefix (Nam);
Error_Msg_NE ("\operator for type& is not declared in&",
Prefix (Nam), T);
end;
else
Error_Msg_NE
("no visible subprogram matches the specification for&",
Spec, New_S);
end if;
if Present (Candidate_Renaming) then
declare
F1 : Entity_Id;
F2 : Entity_Id;
begin
F1 := First_Formal (Candidate_Renaming);
F2 := First_Formal (New_S);
while Present (F1) and then Present (F2) loop
Next_Formal (F1);
Next_Formal (F2);
end loop;
if Present (F1) and then Present (Default_Value (F1)) then
if Present (Next_Formal (F1)) then
Error_Msg_NE
("\missing specification for &" &
" and other formals with defaults", Spec, F1);
else
Error_Msg_NE
("\missing specification for &", Spec, F1);
end if;
end if;
end;
end if;
end if;
Ada_83 := Save_83;
end Analyze_Subprogram_Renaming;
procedure Analyze_Use_Package (N : Node_Id) is
Pack_Name : Node_Id;
Pack : Entity_Id;
function In_Previous_With_Clause return Boolean;
function In_Previous_With_Clause return Boolean is
Item : Node_Id;
begin
Item := First (Context_Items (Parent (N)));
while Present (Item)
and then Item /= N
loop
if Nkind (Item) = N_With_Clause
and then Entity (Name (Item)) = Pack
then
return True;
end if;
Next (Item);
end loop;
return False;
end In_Previous_With_Clause;
begin
Set_Hidden_By_Use_Clause (N, No_Elist);
if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
and then Name_Buffer (1 .. 3) /= "a-n"
and then
Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
then
Error_Msg_N ("use clause not allowed in predefined spec", N);
end if;
if Nkind (Parent (N)) /= N_Compilation_Unit then
Chain_Use_Clause (N);
end if;
Pack_Name := First (Names (N));
while Present (Pack_Name) loop
Analyze (Pack_Name);
if Nkind (Parent (N)) = N_Compilation_Unit
and then Nkind (Pack_Name) = N_Expanded_Name
then
declare
Pref : Node_Id := Prefix (Pack_Name);
begin
while Nkind (Pref) = N_Expanded_Name loop
Pref := Prefix (Pref);
end loop;
if Entity (Pref) = Standard_Standard then
Error_Msg_N
("predefined package Standard cannot appear"
& " in a context clause", Pref);
end if;
end;
end if;
Next (Pack_Name);
end loop;
Pack_Name := First (Names (N));
while Present (Pack_Name) loop
if Is_Entity_Name (Pack_Name) then
Pack := Entity (Pack_Name);
if Ekind (Pack) /= E_Package
and then Etype (Pack) /= Any_Type
then
if Ekind (Pack) = E_Generic_Package then
Error_Msg_N
("a generic package is not allowed in a use clause",
Pack_Name);
else
Error_Msg_N ("& is not a usable package", Pack_Name);
end if;
elsif Nkind (Parent (N)) = N_Compilation_Unit
and then Nkind (Pack_Name) /= N_Expanded_Name
and then not In_Previous_With_Clause
then
Error_Msg_N ("package is not directly visible", Pack_Name);
elsif Applicable_Use (Pack_Name) then
Use_One_Package (Pack, N);
end if;
end if;
Next (Pack_Name);
end loop;
end Analyze_Use_Package;
procedure Analyze_Use_Type (N : Node_Id) is
Id : Entity_Id;
begin
Set_Hidden_By_Use_Clause (N, No_Elist);
if Nkind (Parent (N)) /= N_Compilation_Unit then
Chain_Use_Clause (N);
end if;
Id := First (Subtype_Marks (N));
while Present (Id) loop
Find_Type (Id);
if Entity (Id) /= Any_Type then
Use_One_Type (Id);
end if;
Next (Id);
end loop;
end Analyze_Use_Type;
function Applicable_Use (Pack_Name : Node_Id) return Boolean is
Pack : constant Entity_Id := Entity (Pack_Name);
begin
if In_Open_Scopes (Pack) then
return False;
elsif In_Use (Pack) then
Set_Redundant_Use (Pack_Name, True);
return False;
elsif Present (Renamed_Object (Pack))
and then In_Use (Renamed_Object (Pack))
then
Set_Redundant_Use (Pack_Name, True);
return False;
else
return True;
end if;
end Applicable_Use;
procedure Attribute_Renaming (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Nam : constant Node_Id := Name (N);
Spec : constant Node_Id := Specification (N);
New_S : constant Entity_Id := Defining_Unit_Name (Spec);
Aname : constant Name_Id := Attribute_Name (Nam);
Form_Num : Nat := 0;
Expr_List : List_Id := No_List;
Attr_Node : Node_Id;
Body_Node : Node_Id;
Param_Spec : Node_Id;
begin
Generate_Definition (New_S);
if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
if Aname /= Name_AST_Entry then
Error_Msg_N
("subprogram renaming an attribute must have formals", N);
return;
end if;
else
Param_Spec := First (Parameter_Specifications (Spec));
while Present (Param_Spec) loop
Form_Num := Form_Num + 1;
if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
Find_Type (Parameter_Type (Param_Spec));
Rewrite (Parameter_Type (Param_Spec),
New_Reference_To
(Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
end if;
if No (Expr_List) then
Expr_List := New_List;
end if;
Append_To (Expr_List,
Make_Identifier (Loc,
Chars => Chars (Defining_Identifier (Param_Spec))));
Next (Param_Spec);
end loop;
end if;
if Form_Num > 2 then
Error_Msg_N ("too many formals for attribute", N);
elsif
Aname = Name_Compose or else
Aname = Name_Exponent or else
Aname = Name_Leading_Part or else
Aname = Name_Pos or else
Aname = Name_Round or else
Aname = Name_Scaling or else
Aname = Name_Val
then
if Nkind (N) = N_Subprogram_Renaming_Declaration
and then Present (Corresponding_Spec (N))
and then Nkind (Corresponding_Spec (N)) =
N_Formal_Subprogram_Declaration
then
Error_Msg_N
("generic actual cannot be attribute involving universal type",
Nam);
else
Error_Msg_N
("attribute involving a universal type cannot be renamed",
Nam);
end if;
end if;
if Aname = Name_AST_Entry then
declare
Ent : Entity_Id;
Decl : Node_Id;
begin
Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Ent,
Object_Definition =>
New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
Expression => Nam,
Constant_Present => True);
Set_Assignment_OK (Decl, True);
Insert_Action (N, Decl);
Attr_Node := Make_Identifier (Loc, Chars (Ent));
end;
else
Attr_Node :=
Make_Attribute_Reference (Loc,
Prefix => Prefix (Nam),
Attribute_Name => Aname,
Expressions => Expr_List);
Set_Must_Not_Freeze (Attr_Node);
Set_Must_Not_Freeze (Prefix (Nam));
end if;
if Nkind (Spec) = N_Function_Specification then
if Is_Procedure_Attribute_Name (Aname) then
Error_Msg_N ("attribute can only be renamed as procedure", Nam);
return;
end if;
Find_Type (Subtype_Mark (Spec));
Rewrite (Subtype_Mark (Spec),
New_Reference_To (Base_Type (Entity (Subtype_Mark (Spec))), Loc));
Body_Node :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Return_Statement (Loc,
Expression => Attr_Node))));
else
if not Is_Procedure_Attribute_Name (Aname) then
Error_Msg_N ("attribute can only be renamed as function", Nam);
return;
end if;
Body_Node :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Attr_Node)));
end if;
Rewrite (N, Body_Node);
Analyze (N);
Set_Etype (New_S, Base_Type (Etype (New_S)));
Set_Suppress_Elaboration_Warnings (New_S);
end Attribute_Renaming;
procedure Chain_Use_Clause (N : Node_Id) is
begin
Set_Next_Use_Clause (N,
Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause);
Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause := N;
end Chain_Use_Clause;
procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
B_Node : Node_Id;
Old_S : Entity_Id;
begin
if Is_Frozen (Subp)
and then not Has_Completion (Subp)
then
B_Node :=
Build_Renamed_Body
(Parent (Declaration_Node (Subp)), Defining_Entity (N));
if Is_Entity_Name (Name (N)) then
Old_S := Entity (Name (N));
if not Is_Frozen (Old_S) then
Ensure_Freeze_Node (Old_S);
if No (Actions (Freeze_Node (Old_S))) then
Set_Actions (Freeze_Node (Old_S), New_List (B_Node));
else
Append (B_Node, Actions (Freeze_Node (Old_S)));
end if;
else
Insert_After (N, B_Node);
Analyze (B_Node);
end if;
if Is_Intrinsic_Subprogram (Old_S)
and then not In_Instance
then
Error_Msg_N
("subprogram used in renaming_as_body cannot be intrinsic",
Name (N));
end if;
else
Insert_After (N, B_Node);
Analyze (B_Node);
end if;
end if;
end Check_Frozen_Renaming;
procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
New_E : Entity_Id;
begin
if Nkind (Parent (N)) /= N_Compilation_Unit then
return;
elsif Scope (Old_E) /= Standard_Standard
and then not Is_Child_Unit (Old_E)
then
Error_Msg_N ("renamed unit must be a library unit", Name (N));
elsif Present (Parent_Spec (N))
and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
and then not Is_Child_Unit (Old_E)
then
Error_Msg_N
("renamed unit must be a child unit of generic parent", Name (N));
elsif Nkind (N) in N_Generic_Renaming_Declaration
and then Nkind (Name (N)) = N_Expanded_Name
and then Is_Generic_Instance (Entity (Prefix (Name (N))))
and then Is_Generic_Unit (Old_E)
then
Error_Msg_N
("renamed generic unit must be a library unit", Name (N));
elsif Ekind (Old_E) = E_Package
or else Ekind (Old_E) = E_Generic_Package
then
New_E := Defining_Entity (N);
Set_Is_Pure (New_E, Is_Pure (Old_E));
Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
Set_Is_Remote_Call_Interface (New_E,
Is_Remote_Call_Interface (Old_E));
Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
end if;
end Check_Library_Unit_Renaming;
procedure End_Scope is
Id : Entity_Id;
Prev : Entity_Id;
Outer : Entity_Id;
begin
Id := First_Entity (Current_Scope);
while Present (Id) loop
if Id /= Current_Entity (Id) then
Prev := Current_Entity (Id);
while Present (Prev)
and then Present (Homonym (Prev))
and then Homonym (Prev) /= Id
loop
Prev := Homonym (Prev);
end loop;
if No (Prev) or else Homonym (Prev) /= Id then
goto Next_Ent;
end if;
else
Prev := Empty;
end if;
Outer := Homonym (Id);
Set_Is_Immediately_Visible (Id, False);
while Present (Outer) and then Scope (Outer) = Current_Scope loop
Outer := Homonym (Outer);
end loop;
if No (Prev) then
Set_Name_Entity_Id (Chars (Id), Outer);
elsif Scope (Prev) /= Scope (Id) then
Set_Homonym (Prev, Outer);
end if;
<<Next_Ent>>
Next_Entity (Id);
end loop;
if Present
(Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
then
declare
Decl : Node_Id;
L : constant List_Id := Scope_Stack.Table
(Scope_Stack.Last).Pending_Freeze_Actions;
begin
if Is_Itype (Current_Scope) then
Decl := Associated_Node_For_Itype (Current_Scope);
else
Decl := Parent (Current_Scope);
end if;
Pop_Scope;
while not (Is_List_Member (Decl))
or else Nkind (Parent (Decl)) = N_Protected_Definition
or else Nkind (Parent (Decl)) = N_Task_Definition
loop
Decl := Parent (Decl);
end loop;
Insert_List_Before_And_Analyze (Decl, L);
end;
else
Pop_Scope;
end if;
end End_Scope;
procedure End_Use_Clauses (Clause : Node_Id) is
U : Node_Id := Clause;
begin
while Present (U) loop
if Nkind (U) = N_Use_Package_Clause then
End_Use_Package (U);
elsif Nkind (U) = N_Use_Type_Clause then
End_Use_Type (U);
end if;
Next_Use_Clause (U);
end loop;
end End_Use_Clauses;
procedure End_Use_Package (N : Node_Id) is
Pack_Name : Node_Id;
Pack : Entity_Id;
Id : Entity_Id;
Elmt : Elmt_Id;
begin
Pack_Name := First (Names (N));
while Present (Pack_Name) loop
Pack := Entity (Pack_Name);
if Ekind (Pack) = E_Package then
if In_Open_Scopes (Pack) then
null;
elsif not Redundant_Use (Pack_Name) then
Set_In_Use (Pack, False);
Id := First_Entity (Pack);
while Present (Id) loop
if Nkind (Id) = N_Defining_Operator_Symbol
and then
(In_Use (Etype (First_Formal (Id)))
or else
(Present (Next_Formal (First_Formal (Id)))
and then In_Use (Etype (Next_Formal
(First_Formal (Id))))))
then
null;
else
Set_Is_Potentially_Use_Visible (Id, False);
end if;
if Is_Private_Type (Id)
and then Present (Full_View (Id))
then
Set_Is_Potentially_Use_Visible (Full_View (Id), False);
end if;
Next_Entity (Id);
end loop;
if Present (Renamed_Object (Pack)) then
Set_In_Use (Renamed_Object (Pack), False);
end if;
if Chars (Pack) = Name_System
and then Scope (Pack) = Standard_Standard
and then Present_System_Aux
then
Id := First_Entity (System_Aux_Id);
while Present (Id) loop
Set_Is_Potentially_Use_Visible (Id, False);
if Is_Private_Type (Id)
and then Present (Full_View (Id))
then
Set_Is_Potentially_Use_Visible (Full_View (Id), False);
end if;
Next_Entity (Id);
end loop;
Set_In_Use (System_Aux_Id, False);
end if;
else
Set_Redundant_Use (Pack_Name, False);
end if;
end if;
Next (Pack_Name);
end loop;
if Present (Hidden_By_Use_Clause (N)) then
Elmt := First_Elmt (Hidden_By_Use_Clause (N));
while Present (Elmt) loop
Set_Is_Immediately_Visible (Node (Elmt));
Next_Elmt (Elmt);
end loop;
Set_Hidden_By_Use_Clause (N, No_Elist);
end if;
end End_Use_Package;
procedure End_Use_Type (N : Node_Id) is
Id : Entity_Id;
Op_List : Elist_Id;
Elmt : Elmt_Id;
T : Entity_Id;
begin
Id := First (Subtype_Marks (N));
while Present (Id) loop
T := Entity (Id);
if T = Any_Type then
null;
elsif In_Open_Scopes (Scope (Base_Type (T))) then
null;
elsif not Redundant_Use (Id) then
Set_In_Use (T, False);
Set_In_Use (Base_Type (T), False);
Op_List := Collect_Primitive_Operations (T);
Elmt := First_Elmt (Op_List);
while Present (Elmt) loop
if Nkind (Node (Elmt)) = N_Defining_Operator_Symbol then
Set_Is_Potentially_Use_Visible (Node (Elmt), False);
end if;
Next_Elmt (Elmt);
end loop;
end if;
Next (Id);
end loop;
end End_Use_Type;
procedure Find_Direct_Name (N : Node_Id) is
E : Entity_Id;
E2 : Entity_Id;
Msg : Boolean;
Inst : Entity_Id := Empty;
Homonyms : Entity_Id;
Nvis_Entity : Boolean;
function From_Actual_Package (E : Entity_Id) return Boolean;
function Known_But_Invisible (E : Entity_Id) return Boolean;
procedure Nvis_Messages;
procedure Undefined (Nvis : Boolean);
function From_Actual_Package (E : Entity_Id) return Boolean is
Scop : constant Entity_Id := Scope (E);
Act : Entity_Id;
begin
if not In_Instance then
return False;
else
Inst := Current_Scope;
while Present (Inst)
and then Ekind (Inst) /= E_Package
and then not Is_Generic_Instance (Inst)
loop
Inst := Scope (Inst);
end loop;
if No (Inst) then
return False;
end if;
Act := First_Entity (Inst);
while Present (Act) loop
if Ekind (Act) = E_Package then
if Renamed_Object (Act) = Inst then
return False;
elsif Present (Associated_Formal_Package (Act))
and then Renamed_Object (Act) = Scop
then
return True;
else
Next_Entity (Act);
end if;
else
Next_Entity (Act);
end if;
end loop;
return False;
end if;
end From_Actual_Package;
function Known_But_Invisible (E : Entity_Id) return Boolean is
Fname : File_Name_Type;
begin
if Sloc (E) <= Standard_Location then
return True;
elsif not Comes_From_Source (E) then
return False;
elsif GNAT_Mode then
return True;
end if;
Fname := Unit_File_Name (Get_Source_Unit (E));
if Is_Internal_File_Name (Fname) then
if Is_Hidden (E) then
return False;
end if;
Get_Name_String (Fname);
return
Name_Len < 2
or else
Name_Buffer (1 .. 2) /= "s-"
or else
Name_Buffer (3 .. 8) = "stoele"
or else
Name_Buffer (3 .. 5) = "aux";
else
return True;
end if;
end Known_But_Invisible;
procedure Nvis_Messages is
Ent : Entity_Id;
Hidden : Boolean := False;
begin
Undefined (Nvis => True);
if Msg then
Ent := Homonyms;
while Present (Ent) loop
if Is_Potentially_Use_Visible (Ent) then
if not Hidden then
Error_Msg_N ("multiple use clauses cause hiding!", N);
Hidden := True;
end if;
Error_Msg_Sloc := Sloc (Ent);
Error_Msg_N ("hidden declaration#!", N);
end if;
Ent := Homonym (Ent);
end loop;
if Hidden then
return;
end if;
Ent := Homonyms;
while Present (Ent) loop
if not Is_Potentially_Use_Visible (Ent) then
if not Known_But_Invisible (Ent) then
goto Continue;
end if;
Error_Msg_Sloc := Sloc (Ent);
if Is_Hidden (Ent) then
Error_Msg_N ("non-visible (private) declaration#!", N);
else
Error_Msg_N ("non-visible declaration#!", N);
end if;
if Comes_From_Source (Ent) then
Set_Referenced (Ent);
Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
end if;
end if;
<<Continue>>
Ent := Homonym (Ent);
end loop;
end if;
end Nvis_Messages;
procedure Undefined (Nvis : Boolean) is
Emsg : Error_Msg_Id;
begin
if Nkind (N) = N_Identifier
and then Nkind (Parent (N)) = N_Case_Statement_Alternative
then
Get_Name_String (Chars (N));
declare
Case_Str : constant String := Name_Buffer (1 .. Name_Len);
Case_Stm : constant Node_Id := Parent (Parent (N));
Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
Lit : Node_Id;
begin
if Is_Enumeration_Type (Case_Typ)
and then Case_Typ /= Standard_Character
and then Case_Typ /= Standard_Wide_Character
then
Lit := First_Literal (Case_Typ);
Get_Name_String (Chars (Lit));
if Chars (Lit) /= Chars (N)
and then Is_Bad_Spelling_Of
(Case_Str, Name_Buffer (1 .. Name_Len))
then
Error_Msg_Node_2 := Lit;
Error_Msg_N
("& is undefined, assume misspelling of &", N);
Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
return;
end if;
Lit := Next_Literal (Lit);
end if;
end;
end if;
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
for J in Urefs.First .. Urefs.Last loop
if Chars (N) = Chars (Urefs.Table (J).Node) then
if Urefs.Table (J).Err /= No_Error_Msg
and then Sloc (N) /= Urefs.Table (J).Loc
then
Error_Msg_Node_1 := Urefs.Table (J).Node;
if Urefs.Table (J).Nvis then
Change_Error_Text (Urefs.Table (J).Err,
"& is not visible (more references follow)");
else
Change_Error_Text (Urefs.Table (J).Err,
"& is undefined (more references follow)");
end if;
Urefs.Table (J).Err := No_Error_Msg;
end if;
Msg := False;
Set_Error_Posted (N, True);
return;
end if;
end loop;
if Nvis then
Error_Msg_N ("& is not visible!", N);
Emsg := Get_Msg_Id;
else
Error_Msg_N ("& is undefined!", N);
Emsg := Get_Msg_Id;
if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
Error_Msg_N ("\possible missing with of 'Text_'I'O!", N);
end if;
Get_Name_String (Chars (N));
declare
E : Entity_Id;
Ematch : Entity_Id := Empty;
Last_Name_Id : constant Name_Id :=
Name_Id (Nat (First_Name_Id) +
Name_Entries_Count - 1);
S : constant String (1 .. Name_Len) :=
Name_Buffer (1 .. Name_Len);
begin
for N in First_Name_Id .. Last_Name_Id loop
E := Get_Name_Entity_Id (N);
if Present (E)
and then (Is_Immediately_Visible (E)
or else
Is_Potentially_Use_Visible (E))
then
Get_Name_String (N);
if Is_Bad_Spelling_Of
(Name_Buffer (1 .. Name_Len), S)
then
Ematch := E;
exit;
end if;
end if;
end loop;
if Present (Ematch) then
Error_Msg_NE ("\possible misspelling of&", N, Ematch);
end if;
end;
end if;
if not All_Errors_Mode then
Urefs.Increment_Last;
Urefs.Table (Urefs.Last).Node := N;
Urefs.Table (Urefs.Last).Err := Emsg;
Urefs.Table (Urefs.Last).Nvis := Nvis;
Urefs.Table (Urefs.Last).Loc := Sloc (N);
end if;
Msg := True;
end Undefined;
begin
if Present (Entity (N)) then
if Is_Type (Entity (N)) then
Set_Etype (N, Entity (N));
else
declare
Entyp : constant Entity_Id := Etype (Entity (N));
begin
if Is_Array_Type (Entyp)
and then Is_Packed (Entyp)
and then Present (Etype (N))
and then Etype (N) = Packed_Array_Type (Entyp)
then
null;
else
Set_Etype (N, Etype (Entity (N)));
end if;
end;
end if;
return;
end if;
if Debug_Flag_E then
Write_Str ("Looking for ");
Write_Name (Chars (N));
Write_Eol;
end if;
Homonyms := Current_Entity (N);
Nvis_Entity := False;
E := Homonyms;
while Present (E) loop
if Is_Immediately_Visible (E) then
goto Immediately_Visible_Entity;
elsif Is_Potentially_Use_Visible (E) then
goto Potentially_Use_Visible_Entity;
elsif Known_But_Invisible (E) then
Nvis_Entity := True;
end if;
E := Homonym (E);
end loop;
if not Nvis_Entity then
Undefined (Nvis => False);
return;
else
Nvis_Messages;
return;
end if;
<<Potentially_Use_Visible_Entity>> declare
Only_One_Visible : Boolean := True;
All_Overloadable : Boolean := Is_Overloadable (E);
begin
E2 := Homonym (E);
while Present (E2) loop
if Is_Immediately_Visible (E2) then
if From_Actual_Package (E)
and then Scope_Depth (E2) < Scope_Depth (Inst)
then
goto Found;
else
E := E2;
goto Immediately_Visible_Entity;
end if;
elsif Is_Potentially_Use_Visible (E2) then
Only_One_Visible := False;
All_Overloadable := All_Overloadable and Is_Overloadable (E2);
end if;
E2 := Homonym (E2);
end loop;
if Only_One_Visible or All_Overloadable then
goto Found;
else
if In_Instance then
E2 := E;
while Present (E2) loop
if Is_Generic_Instance (Scope (E2)) then
E := E2;
goto Found;
end if;
E2 := Homonym (E2);
end loop;
Nvis_Messages;
return;
else
Nvis_Messages;
return;
end if;
end if;
end;
<<Immediately_Visible_Entity>> declare
Level : Int;
Scop : Entity_Id;
begin
Level := Scope_Stack.Last;
loop
Scop := Scope_Stack.Table (Level).Entity;
exit when Scop = Scope (E);
Level := Level - 1;
exit when Scop = Standard_Standard;
end loop;
E2 := Homonym (E);
while Present (E2) loop
if Is_Immediately_Visible (E2) then
for J in Level + 1 .. Scope_Stack.Last loop
if Scope_Stack.Table (J).Entity = Scope (E2)
or else Scope_Stack.Table (J).Entity = E2
then
Level := J;
E := E2;
exit;
end if;
end loop;
end if;
E2 := Homonym (E2);
end loop;
end;
<<Found>> begin
if Comes_From_Source (N)
and then Is_Remote_Access_To_Subprogram_Type (E)
and then Expander_Active
then
Rewrite (N,
New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
return;
end if;
Set_Entity (N, E);
if Is_Type (E) then
Set_Etype (N, E);
else
Set_Etype (N, Get_Full_View (Etype (E)));
end if;
if Debug_Flag_E then
Write_Str (" found ");
Write_Entity_Info (E, " ");
end if;
if Ekind (E) = E_Void
and then
(not Is_Record_Type (Current_Scope)
or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
then
Premature_Usage (N);
elsif Is_Overloadable (E)
and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
then
Collect_Interps (N);
if not Is_Overloaded (N) then
Generate_Reference (E, N);
end if;
else
if Nkind (Parent (N)) = N_Label then
declare
R : constant Boolean := Referenced (E);
begin
Generate_Reference (E, N);
Set_Referenced (E, R);
end;
else
Generate_Reference (E, N);
end if;
if not In_Default_Expression
or else Ekind (E) /= E_Discriminant
or else Inside_A_Generic
then
Set_Entity_With_Style_Check (N, E);
elsif Is_Concurrent_Type (Scope (E)) then
declare
P : Node_Id := Parent (N);
begin
while Present (P)
and then Nkind (P) /= N_Parameter_Specification
and then Nkind (P) /= N_Component_Declaration
loop
P := Parent (P);
end loop;
if Present (P)
and then Nkind (P) = N_Parameter_Specification
then
null;
else
Set_Entity (N, Discriminal (E));
end if;
end;
else
Set_Entity (N, Discriminal (E));
end if;
end if;
end;
end Find_Direct_Name;
procedure Find_Expanded_Name (N : Node_Id) is
Selector : constant Node_Id := Selector_Name (N);
Candidate : Entity_Id := Empty;
P_Name : Entity_Id;
O_Name : Entity_Id;
Id : Entity_Id;
begin
P_Name := Entity (Prefix (N));
O_Name := P_Name;
if Ekind (P_Name) = E_Package
and then Present (Renamed_Object (P_Name))
then
P_Name := Renamed_Object (P_Name);
Rewrite (Prefix (N), New_Copy (Prefix (N)));
Set_Entity (Prefix (N), P_Name);
elsif Is_Concurrent_Type (Etype (P_Name)) then
P_Name := Etype (P_Name);
end if;
Id := Current_Entity (Selector);
while Present (Id) loop
if Scope (Id) = P_Name then
Candidate := Id;
if Is_Child_Unit (Id) then
exit when
(Is_Visible_Child_Unit (Id)
or else Is_Immediately_Visible (Id));
else
exit when
(not Is_Hidden (Id) or else Is_Immediately_Visible (Id));
end if;
end if;
Id := Homonym (Id);
end loop;
if No (Id)
and then (Ekind (P_Name) = E_Procedure
or else
Ekind (P_Name) = E_Function)
and then Is_Generic_Instance (P_Name)
then
P_Name := Scope (P_Name);
Id := Current_Entity (Selector);
while Present (Id) loop
exit when Scope (Id) = P_Name;
Id := Homonym (Id);
end loop;
end if;
if No (Id) or else Chars (Id) /= Chars (Selector) then
Set_Etype (N, Any_Type);
if Chars (P_Name) = Name_System
and then Scope (P_Name) = Standard_Standard
and then Present (System_Extend_Pragma_Arg)
and then Present_System_Aux (N)
then
Set_Entity (Prefix (N), System_Aux_Id);
Find_Expanded_Name (N);
return;
elsif (Nkind (Selector) = N_Operator_Symbol
and then Has_Implicit_Operator (N))
then
return;
elsif Nkind (Selector) = N_Character_Literal
and then Has_Implicit_Character_Literal (N)
then
return;
else
if Is_Concurrent_Type (P_Name)
and then Is_Internal_Name (Chars (P_Name))
then
Error_Msg_Node_2 := Entity (Prefix (N));
else
Error_Msg_Node_2 := P_Name;
end if;
if P_Name = System_Aux_Id then
P_Name := Scope (P_Name);
Set_Entity (Prefix (N), P_Name);
end if;
if Present (Candidate) then
if Is_Child_Unit (Candidate) then
Error_Msg_N
("missing with_clause for child unit &", Selector);
else
Error_Msg_NE ("& is not a visible entity of&", N, Selector);
end if;
else
if O_Name /= P_Name
and then In_Open_Scopes (P_Name)
and then Is_Generic_Instance (P_Name)
then
declare
S : Entity_Id := Current_Scope;
P : Entity_Id;
begin
for J in reverse 0 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
exit when S = Standard_Standard;
if Ekind (S) = E_Function
or else Ekind (S) = E_Package
or else Ekind (S) = E_Procedure
then
P := Generic_Parent (Specification
(Unit_Declaration_Node (S)));
if Present (P)
and then Chars (Scope (P)) = Chars (O_Name)
and then Chars (P) = Chars (Selector)
then
Id := S;
goto found;
end if;
end if;
end loop;
end;
end if;
if (Chars (P_Name) = Name_Ada
and then Scope (P_Name) = Standard_Standard)
then
Error_Msg_Node_2 := Selector;
Error_Msg_NE
("\missing with for `&.&`", N, P_Name);
elsif Sloc (Error_Msg_Node_2) = No_Location then
null;
else
Error_Msg_NE ("& not declared in&", N, Selector);
Id := First_Entity (P_Name);
Get_Name_String (Chars (Selector));
declare
S : constant String (1 .. Name_Len) :=
Name_Buffer (1 .. Name_Len);
begin
while Present (Id) loop
Get_Name_String (Chars (Id));
if Is_Bad_Spelling_Of
(Name_Buffer (1 .. Name_Len), S)
and then not Is_Internal_Name (Chars (Id))
then
Error_Msg_NE
("possible misspelling of&", Selector, Id);
exit;
end if;
Next_Entity (Id);
end loop;
end;
if Nkind (Parent (N)) = N_Package_Instantiation
and then Is_Generic_Instance (Entity (Prefix (N)))
and then Is_Compilation_Unit
(Generic_Parent (Parent (Entity (Prefix (N)))))
then
Error_Msg_NE
("\possible missing with clause on child unit&",
N, Selector);
end if;
end if;
end if;
Id := Any_Id;
end if;
end if;
<<found>>
if Comes_From_Source (N)
and then Is_Remote_Access_To_Subprogram_Type (Id)
then
Id := Equivalent_Type (Id);
Set_Chars (Selector, Chars (Id));
end if;
if Ekind (P_Name) = E_Package
and then From_With_Type (P_Name)
then
if From_With_Type (Id)
or else (Ekind (Id) = E_Package and then From_With_Type (Id))
then
null;
else
Error_Msg_N
("imported package can only be used to access imported type",
N);
end if;
end if;
if Is_Task_Type (P_Name)
and then ((Ekind (Id) = E_Entry
and then Nkind (Parent (N)) /= N_Attribute_Reference)
or else
(Ekind (Id) = E_Entry_Family
and then
Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
then
Analyze_Selected_Component (N);
return;
end if;
Change_Selected_Component_To_Expanded_Name (N);
if Has_Homonym (Id) then
Set_Entity (N, Id);
else
Set_Entity_With_Style_Check (N, Id);
Generate_Reference (Id, N);
end if;
if Is_Type (Id) then
Set_Etype (N, Id);
else
Set_Etype (N, Get_Full_View (Etype (Id)));
end if;
if Ekind (Id) = E_Void then
Premature_Usage (N);
elsif Is_Overloadable (Id)
and then Present (Homonym (Id))
then
declare
H : Entity_Id := Homonym (Id);
begin
while Present (H) loop
if Scope (H) = Scope (Id) then
Collect_Interps (N);
exit;
end if;
H := Homonym (H);
end loop;
end;
end if;
if Nkind (Selector_Name (N)) = N_Operator_Symbol
and then Scope (Id) /= Standard_Standard
then
if Has_Implicit_Operator (N) then
null;
end if;
end if;
end Find_Expanded_Name;
function Find_Renamed_Entity
(N : Node_Id;
Nam : Node_Id;
New_S : Entity_Id;
Is_Actual : Boolean := False) return Entity_Id
is
I : Interp_Index;
I1 : Interp_Index := 0; It : Interp;
It1 : Interp;
Old_S : Entity_Id;
Inst : Entity_Id;
function Enclosing_Instance return Entity_Id;
function Within (Inner, Outer : Entity_Id) return Boolean;
function Is_Visible_Operation (Op : Entity_Id) return Boolean;
function Enclosing_Instance return Entity_Id is
S : Entity_Id;
begin
if not Is_Generic_Instance (Current_Scope)
and then not Is_Actual
then
return Empty;
end if;
S := Scope (Current_Scope);
while S /= Standard_Standard loop
if Is_Generic_Instance (S) then
return S;
end if;
S := Scope (S);
end loop;
return Empty;
end Enclosing_Instance;
function Is_Visible_Operation (Op : Entity_Id) return Boolean is
Scop : Entity_Id;
Typ : Entity_Id;
Btyp : Entity_Id;
begin
if Ekind (Op) /= E_Operator
or else Scope (Op) /= Standard_Standard
or else (In_Instance
and then
(not Is_Actual
or else Present (Enclosing_Instance)))
then
return True;
else
if Present (Next_Formal (First_Formal (New_S)))
and then Is_Fixed_Point_Type (Etype (New_S))
then
Typ := Etype (New_S);
else
Typ := Etype (First_Formal (New_S));
end if;
Btyp := Base_Type (Typ);
if Nkind (Nam) /= N_Expanded_Name then
return (In_Open_Scopes (Scope (Btyp))
or else Is_Potentially_Use_Visible (Btyp)
or else In_Use (Btyp)
or else In_Use (Scope (Btyp)));
else
Scop := Entity (Prefix (Nam));
if Ekind (Scop) = E_Package
and then Present (Renamed_Object (Scop))
then
Scop := Renamed_Object (Scop);
end if;
return Scope (Btyp) = Scop
or else (Scope (Btyp) = System_Aux_Id
and then Scope (Scope (Btyp)) = Scop);
end if;
end if;
end Is_Visible_Operation;
function Within (Inner, Outer : Entity_Id) return Boolean is
Sc : Entity_Id := Scope (Inner);
begin
while Sc /= Standard_Standard loop
if Sc = Outer then
return True;
else
Sc := Scope (Sc);
end if;
end loop;
return False;
end Within;
begin
Old_S := Any_Id;
Candidate_Renaming := Empty;
if not Is_Overloaded (Nam) then
if Entity_Matches_Spec (Entity (Nam), New_S)
and then Is_Visible_Operation (Entity (Nam))
then
Old_S := Entity (Nam);
elsif
Present (First_Formal (Entity (Nam)))
and then Present (First_Formal (New_S))
and then (Base_Type (Etype (First_Formal (Entity (Nam))))
= Base_Type (Etype (First_Formal (New_S))))
then
Candidate_Renaming := Entity (Nam);
end if;
else
Get_First_Interp (Nam, I, It);
while Present (It.Nam) loop
if Entity_Matches_Spec (It.Nam, New_S)
and then Is_Visible_Operation (It.Nam)
then
if Old_S /= Any_Id then
It1 := Disambiguate (Nam, I1, I, Etype (Old_S));
if It1 = No_Interp then
Inst := Enclosing_Instance;
if Present (Inst) then
if Within (It.Nam, Inst) then
return (It.Nam);
elsif Within (Old_S, Inst) then
return (Old_S);
else
Error_Msg_N ("ambiguous renaming", N);
return Old_S;
end if;
else
Error_Msg_N ("ambiguous renaming", N);
return Old_S;
end if;
else
Old_S := It1.Nam;
exit;
end if;
else
I1 := I;
Old_S := It.Nam;
end if;
elsif
Present (First_Formal (It.Nam))
and then Present (First_Formal (New_S))
and then (Base_Type (Etype (First_Formal (It.Nam)))
= Base_Type (Etype (First_Formal (New_S))))
then
Candidate_Renaming := It.Nam;
end if;
Get_Next_Interp (I, It);
end loop;
Set_Entity (Nam, Old_S);
Set_Is_Overloaded (Nam, False);
end if;
return Old_S;
end Find_Renamed_Entity;
procedure Find_Selected_Component (N : Node_Id) is
P : Node_Id := Prefix (N);
P_Name : Entity_Id;
P_Type : Entity_Id;
Nam : Node_Id;
begin
Analyze (P);
if Nkind (P) = N_Error then
return;
elsif Present (Entity (Selector_Name (N))) then
if No (Etype (N))
or else Etype (N) = Any_Type
then
declare
Sel_Name : Node_Id := Selector_Name (N);
Selector : Entity_Id := Entity (Sel_Name);
C_Etype : Node_Id;
begin
Set_Etype (Sel_Name, Etype (Selector));
if not Is_Entity_Name (P) then
Resolve (P, Etype (P));
end if;
if Is_Entity_Name (P)
and then Ekind (Entity (P)) = E_Function
then
Nam := New_Copy (P);
if Is_Overloaded (P) then
Save_Interps (P, Nam);
end if;
Rewrite (P,
Make_Function_Call (Sloc (P), Name => Nam));
Analyze_Call (P);
Analyze_Selected_Component (N);
return;
elsif Ekind (Selector) = E_Component
and then (not Is_Entity_Name (P)
or else Chars (Entity (P)) /= Name_uInit)
then
C_Etype :=
Build_Actual_Subtype_Of_Component (
Etype (Selector), N);
else
C_Etype := Empty;
end if;
if No (C_Etype) then
C_Etype := Etype (Selector);
else
Insert_Action (N, C_Etype);
C_Etype := Defining_Identifier (C_Etype);
end if;
Set_Etype (N, C_Etype);
end;
if Is_Access_Type (Etype (P))
and then Is_Concurrent_Type (Designated_Type (Etype (P)))
then
declare
New_P : Node_Id :=
Make_Explicit_Dereference (Sloc (P),
Prefix => Relocate_Node (P));
begin
Rewrite (P, New_P);
Set_Etype (P, Designated_Type (Etype (Prefix (P))));
end;
end if;
elsif Inside_Init_Proc then
declare
Typ : constant Entity_Id := Etype (N);
Decl : constant Node_Id := Declaration_Node (Typ);
begin
if Nkind (Decl) = N_Subtype_Declaration
and then not Analyzed (Decl)
and then Is_List_Member (Decl)
and then No (Parent (Decl))
then
Remove (Decl);
Insert_Action (N, Decl);
end if;
end;
end if;
return;
elsif Is_Entity_Name (P) then
P_Name := Entity (P);
if Is_Type (P_Name) then
Set_Entity (P, Get_Full_View (P_Name));
Set_Etype (P, Entity (P));
P_Name := Entity (P);
end if;
P_Type := Base_Type (Etype (P));
if Debug_Flag_E then
Write_Str ("Found prefix type to be ");
Write_Entity_Info (P_Type, " "); Write_Eol;
end if;
if Is_Appropriate_For_Record (P_Type)
and then not Is_Overloadable (P_Name)
and then not Is_Type (P_Name)
then
Analyze_Selected_Component (N);
elsif Is_Appropriate_For_Entry_Prefix (P_Type)
and then not In_Open_Scopes (P_Name)
and then (not Is_Concurrent_Type (Etype (P_Name))
or else not In_Open_Scopes (Etype (P_Name)))
then
Analyze_Selected_Component (N);
elsif (In_Open_Scopes (P_Name)
and then Ekind (P_Name) /= E_Void
and then not Is_Overloadable (P_Name))
or else (Is_Concurrent_Type (Etype (P_Name))
and then In_Open_Scopes (Etype (P_Name)))
then
Find_Expanded_Name (N);
elsif Ekind (P_Name) = E_Package then
Find_Expanded_Name (N);
elsif Is_Overloadable (P_Name) then
if (Ekind (P_Name) = E_Procedure
or else Ekind (P_Name) = E_Function)
and then Present (Alias (P_Name))
and then Is_Generic_Instance (Alias (P_Name))
then
P_Name := Alias (P_Name);
end if;
if Is_Overloaded (P) then
declare
Found : Boolean := False;
I : Interp_Index;
It : Interp;
begin
Get_First_Interp (P, I, It);
while Present (It.Nam) loop
if In_Open_Scopes (It.Nam) then
if Found then
Error_Msg_N (
"prefix must be unique enclosing scope", N);
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
return;
else
Found := True;
P_Name := It.Nam;
end if;
end if;
Get_Next_Interp (I, It);
end loop;
end;
end if;
if In_Open_Scopes (P_Name) then
Set_Entity (P, P_Name);
Set_Is_Overloaded (P, False);
Find_Expanded_Name (N);
else
if Ekind (P_Name) /= E_Function
and then (not Is_Overloaded (P)
or else
Nkind (Parent (N)) = N_Procedure_Call_Statement)
then
if Present (Homonym (Current_Entity (P_Name))) then
P_Name := Current_Entity (P_Name);
while Present (P_Name) loop
exit when Ekind (P_Name) = E_Package;
P_Name := Homonym (P_Name);
end loop;
if Present (P_Name) then
Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
Error_Msg_NE
("package& is hidden by declaration#",
N, P_Name);
Set_Entity (Prefix (N), P_Name);
Find_Expanded_Name (N);
return;
else
P_Name := Entity (Prefix (N));
end if;
end if;
Error_Msg_NE
("invalid prefix in selected component&", N, P_Name);
Change_Selected_Component_To_Expanded_Name (N);
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
else
Nam := New_Copy (P);
Save_Interps (P, Nam);
Rewrite (P,
Make_Function_Call (Sloc (P), Name => Nam));
Analyze_Call (P);
Analyze_Selected_Component (N);
end if;
end if;
else
Change_Node (N, N_Expanded_Name);
Set_Prefix (N, P);
Set_Entity (N, Any_Id);
Set_Etype (N, Any_Type);
if P_Name = Any_Id then
null;
elsif Ekind (P_Name) = E_Void then
Premature_Usage (P);
elsif Nkind (P) /= N_Attribute_Reference then
Error_Msg_N (
"invalid prefix in selected component&", P);
else
Error_Msg_N (
"invalid prefix in selected component", P);
end if;
end if;
else
Analyze_Selected_Component (N);
end if;
end Find_Selected_Component;
procedure Find_Type (N : Node_Id) is
C : Entity_Id;
Typ : Entity_Id;
T : Entity_Id;
T_Name : Entity_Id;
begin
if N = Error then
return;
elsif Nkind (N) = N_Attribute_Reference then
if Attribute_Name (N) = Name_Class then
Check_Restriction (No_Dispatch, N);
Find_Type (Prefix (N));
if Etype (Prefix (N)) = Any_Type then
Set_Entity (N, Any_Type);
Set_Etype (N, Any_Type);
return;
end if;
T := Base_Type (Entity (Prefix (N)));
if not Is_Tagged_Type (T) then
if Ekind (T) = E_Incomplete_Type then
Set_Is_Tagged_Type (T);
Make_Class_Wide_Type (T);
Set_Entity (N, Class_Wide_Type (T));
Set_Etype (N, Class_Wide_Type (T));
elsif Ekind (T) = E_Private_Type
and then not Is_Generic_Type (T)
and then In_Private_Part (Scope (T))
then
if not Present (Class_Wide_Type (T)) then
Make_Class_Wide_Type (T);
end if;
Set_Entity (N, Class_Wide_Type (T));
Set_Etype (N, Class_Wide_Type (T));
else
Error_Msg_NE
("tagged type required, found}",
Prefix (N), First_Subtype (T));
Set_Entity (N, Any_Type);
return;
end if;
else
C := Class_Wide_Type (Entity (Prefix (N)));
Set_Entity_With_Style_Check (N, C);
Generate_Reference (C, N);
Set_Etype (N, C);
if From_With_Type (C)
and then Nkind (Parent (N)) /= N_Access_Definition
and then not Analyzed (T)
then
Error_Msg_N
("imported class-wide type can only be used" &
" for access parameters", N);
end if;
end if;
elsif Attribute_Name (N) = Name_Base then
if Ada_83 and then Comes_From_Source (N) then
Error_Msg_N
("(Ada 83) Base attribute not allowed in subtype mark", N);
else
Find_Type (Prefix (N));
Typ := Entity (Prefix (N));
if Sloc (Typ) = Standard_Location
and then Base_Type (Typ) = Typ
and then Warn_On_Redundant_Constructs
then
Error_Msg_NE
("?redudant attribute, & is its own base type", N, Typ);
end if;
T := Base_Type (Typ);
Set_Entity (N, T);
Set_Etype (N, T);
Rewrite (N,
New_Reference_To (Entity (N), Sloc (N)));
Set_Etype (N, T);
end if;
else
Error_Msg_N ("invalid attribute in subtype mark", N);
end if;
else
Analyze (N);
if Is_Entity_Name (N) then
T_Name := Entity (N);
else
Error_Msg_N ("subtype mark required in this context", N);
Set_Etype (N, Any_Type);
return;
end if;
if T_Name = Any_Id or else Etype (N) = Any_Type then
Set_Entity (N, Any_Type);
elsif not Is_Type (T_Name)
and then T_Name /= Standard_Void_Type
then
Error_Msg_Sloc := Sloc (T_Name);
Error_Msg_N ("subtype mark required in this context", N);
Error_Msg_NE ("\found & declared#", N, T_Name);
Set_Entity (N, Any_Type);
else
T_Name := Get_Full_View (T_Name);
if In_Open_Scopes (T_Name) then
if Ekind (Base_Type (T_Name)) = E_Task_Type then
Error_Msg_N ("task type cannot be used as type mark " &
"within its own body", N);
else
Error_Msg_N ("type declaration cannot refer to itself", N);
end if;
Set_Etype (N, Any_Type);
Set_Entity (N, Any_Type);
Set_Error_Posted (T_Name);
return;
end if;
Set_Entity (N, T_Name);
Set_Etype (N, T_Name);
end if;
end if;
if Present (Etype (N)) and then Comes_From_Source (N) then
if Is_Fixed_Point_Type (Etype (N)) then
Check_Restriction (No_Fixed_Point, N);
elsif Is_Floating_Point_Type (Etype (N)) then
Check_Restriction (No_Floating_Point, N);
end if;
end if;
end Find_Type;
function Get_Full_View (T_Name : Entity_Id) return Entity_Id is
begin
if (Ekind (T_Name) = E_Incomplete_Type
and then Present (Full_View (T_Name)))
then
return Full_View (T_Name);
elsif Is_Class_Wide_Type (T_Name)
and then Ekind (Root_Type (T_Name)) = E_Incomplete_Type
and then Present (Full_View (Root_Type (T_Name)))
then
return Class_Wide_Type (Full_View (Root_Type (T_Name)));
else
return T_Name;
end if;
end Get_Full_View;
function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
Id : Entity_Id;
Found : Boolean := False;
P : constant Entity_Id := Entity (Prefix (N));
Priv_Id : Entity_Id := Empty;
begin
if Ekind (P) = E_Package
and then not In_Open_Scopes (P)
then
Priv_Id := First_Private_Entity (P);
end if;
if P = Standard_Standard then
Change_Selected_Component_To_Expanded_Name (N);
Rewrite (N, Selector_Name (N));
Analyze (N);
Set_Etype (Original_Node (N), Standard_Character);
return True;
end if;
Id := First_Entity (P);
while Present (Id)
and then Id /= Priv_Id
loop
if Is_Character_Type (Id)
and then (Root_Type (Id) = Standard_Character
or else Root_Type (Id) = Standard_Wide_Character)
and then Id = Base_Type (Id)
then
if not Found then
Change_Selected_Component_To_Expanded_Name (N);
Rewrite (N, Selector_Name (N));
Analyze (N);
Set_Etype (N, Id);
Set_Etype (Original_Node (N), Id);
Found := True;
else
Add_One_Interp (N, Id, Id);
end if;
end if;
Next_Entity (Id);
end loop;
return Found;
end Has_Implicit_Character_Literal;
function Has_Implicit_Operator (N : Node_Id) return Boolean is
Op_Id : constant Name_Id := Chars (Selector_Name (N));
P : constant Entity_Id := Entity (Prefix (N));
Id : Entity_Id;
Priv_Id : Entity_Id := Empty;
procedure Add_Implicit_Operator (T : Entity_Id);
procedure Add_Implicit_Operator (T : Entity_Id) is
Predef_Op : Entity_Id;
begin
Predef_Op := Current_Entity (Selector_Name (N));
while Present (Predef_Op)
and then Scope (Predef_Op) /= Standard_Standard
loop
Predef_Op := Homonym (Predef_Op);
end loop;
if Nkind (N) = N_Selected_Component then
Change_Selected_Component_To_Expanded_Name (N);
end if;
Add_One_Interp (N, Predef_Op, T);
if Present (Homonym (Predef_Op)) then
Add_One_Interp (N, Homonym (Predef_Op), T);
end if;
end Add_Implicit_Operator;
begin
if Ekind (P) = E_Package
and then not In_Open_Scopes (P)
then
Priv_Id := First_Private_Entity (P);
end if;
Id := First_Entity (P);
case Op_Id is
when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
while Id /= Priv_Id loop
if Valid_Boolean_Arg (Id)
and then Id = Base_Type (Id)
then
Add_Implicit_Operator (Id);
return True;
end if;
Next_Entity (Id);
end loop;
when Name_Op_Eq | Name_Op_Ne =>
while Id /= Priv_Id loop
if Is_Type (Id)
and then not Is_Limited_Type (Id)
and then Id = Base_Type (Id)
then
Add_Implicit_Operator (Standard_Boolean);
return True;
end if;
Next_Entity (Id);
end loop;
when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
while Id /= Priv_Id loop
if (Is_Scalar_Type (Id)
or else (Is_Array_Type (Id)
and then Is_Scalar_Type (Component_Type (Id))))
and then Id = Base_Type (Id)
then
Add_Implicit_Operator (Standard_Boolean);
return True;
end if;
Next_Entity (Id);
end loop;
when Name_Op_Abs |
Name_Op_Add |
Name_Op_Mod |
Name_Op_Rem |
Name_Op_Subtract |
Name_Op_Multiply |
Name_Op_Divide |
Name_Op_Expon =>
while Id /= Priv_Id loop
if Is_Numeric_Type (Id)
and then Id = Base_Type (Id)
then
Add_Implicit_Operator (Id);
return True;
end if;
Next_Entity (Id);
end loop;
when Name_Op_Concat =>
while Id /= Priv_Id loop
if Is_Array_Type (Id) and then Number_Dimensions (Id) = 1
and then Id = Base_Type (Id)
then
Add_Implicit_Operator (Id);
return True;
end if;
Next_Entity (Id);
end loop;
when others => null;
end case;
return False;
end Has_Implicit_Operator;
function In_Open_Scopes (S : Entity_Id) return Boolean is
begin
for J in reverse 0 .. Scope_Stack.Last loop
if Scope_Stack.Table (J).Entity = S then
return True;
end if;
exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
end loop;
return False;
end In_Open_Scopes;
procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
New_F : Entity_Id;
Old_F : Entity_Id;
Old_T : Entity_Id;
New_T : Entity_Id;
begin
if Ekind (Old_S) = E_Operator then
New_F := First_Formal (New_S);
while Present (New_F) loop
Set_Etype (New_F, Base_Type (Etype (New_F)));
Next_Formal (New_F);
end loop;
Set_Etype (New_S, Base_Type (Etype (New_S)));
else
New_F := First_Formal (New_S);
Old_F := First_Formal (Old_S);
while Present (New_F) loop
New_T := Etype (New_F);
Old_T := Etype (Old_F);
if Nkind (Parent (New_T)) = N_Subtype_Declaration
and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
then
null;
else
Set_Etype (New_F, Old_T);
end if;
Next_Formal (New_F);
Next_Formal (Old_F);
end loop;
if Ekind (Old_S) = E_Function
or else Ekind (Old_S) = E_Enumeration_Literal
then
Set_Etype (New_S, Etype (Old_S));
end if;
end if;
end Inherit_Renamed_Profile;
procedure Initialize is
begin
Urefs.Init;
end Initialize;
procedure Install_Use_Clauses (Clause : Node_Id) is
U : Node_Id := Clause;
P : Node_Id;
Id : Entity_Id;
begin
while Present (U) loop
if Nkind (U) = N_Use_Package_Clause then
P := First (Names (U));
while Present (P) loop
Id := Entity (P);
if Ekind (Id) = E_Package then
if In_Use (Id) then
Set_Redundant_Use (P, True);
elsif Present (Renamed_Object (Id))
and then In_Use (Renamed_Object (Id))
then
Set_Redundant_Use (P, True);
else
Use_One_Package (Id, U);
end if;
end if;
Next (P);
end loop;
else
P := First (Subtype_Marks (U));
while Present (P) loop
if Entity (P) /= Any_Type then
Use_One_Type (P);
end if;
Next (P);
end loop;
end if;
Next_Use_Clause (U);
end loop;
end Install_Use_Clauses;
function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
P_Type : Entity_Id := T;
begin
if Is_Access_Type (P_Type) then
P_Type := Designated_Type (P_Type);
end if;
return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
end Is_Appropriate_For_Entry_Prefix;
function Is_Appropriate_For_Record
(T : Entity_Id)
return Boolean
is
function Has_Components (T1 : Entity_Id) return Boolean;
function Has_Components (T1 : Entity_Id) return Boolean is
begin
return Is_Record_Type (T1)
or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
or else (Is_Task_Type (T1) and then Has_Discriminants (T1));
end Has_Components;
begin
return
Present (T)
and then (Has_Components (T)
or else (Is_Access_Type (T)
and then
Has_Components (Designated_Type (T))));
end Is_Appropriate_For_Record;
procedure New_Scope (S : Entity_Id) is
E : Entity_Id;
begin
if Ekind (S) = E_Void then
null;
elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
and then not Scope_Depth_Set (S)
then
if S = Standard_Standard then
Set_Scope_Depth_Value (S, Uint_0);
elsif Is_Child_Unit (S) then
Set_Scope_Depth_Value (S, Uint_1);
elsif not Is_Record_Type (Current_Scope) then
if Ekind (S) = E_Loop then
Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
else
Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
end if;
end if;
end if;
Scope_Stack.Increment_Last;
Scope_Stack.Table (Scope_Stack.Last).Entity := S;
Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
Scope_Suppress;
Scope_Stack.Table (Scope_Stack.Last).Save_Entity_Suppress :=
Entity_Suppress.Last;
if Scope_Stack.Last > Scope_Stack.First then
Scope_Stack.Table (Scope_Stack.Last).Component_Alignment_Default :=
Scope_Stack.Table (Scope_Stack.Last - 1).Component_Alignment_Default;
end if;
Scope_Stack.Table (Scope_Stack.Last).Last_Subprogram_Name := null;
Scope_Stack.Table (Scope_Stack.Last).Is_Transient := False;
Scope_Stack.Table (Scope_Stack.Last).Node_To_Be_Wrapped := Empty;
Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions := No_List;
Scope_Stack.Table
(Scope_Stack.Last).Actions_To_Be_Wrapped_Before := No_List;
Scope_Stack.Table
(Scope_Stack.Last).Actions_To_Be_Wrapped_After := No_List;
Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause := Empty;
Scope_Stack.Table (Scope_Stack.Last).Is_Active_Stack_Base := False;
if Debug_Flag_W then
Write_Str ("--> new scope: ");
Write_Name (Chars (Current_Scope));
Write_Str (", Id=");
Write_Int (Int (Current_Scope));
Write_Str (", Depth=");
Write_Int (Int (Scope_Stack.Last));
Write_Eol;
end if;
if S /= Standard_Standard
and then Scope (S) /= Standard_Standard
and then not Is_Child_Unit (S)
then
E := Scope (S);
if Nkind (E) not in N_Entity then
return;
end if;
if Is_Library_Level_Entity (S) then
Set_Is_Pure (S, Is_Pure (E));
Set_Is_Preelaborated (S, Is_Preelaborated (E));
Set_Is_Remote_Call_Interface (S, Is_Remote_Call_Interface (E));
Set_Is_Remote_Types (S, Is_Remote_Types (E));
Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
end if;
end if;
end New_Scope;
procedure Pop_Scope is
E : Entity_Id;
begin
if Debug_Flag_E then
Write_Info;
end if;
Scope_Suppress :=
Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress;
while Entity_Suppress.Last >
Scope_Stack.Table (Scope_Stack.Last).Save_Entity_Suppress
loop
E := Entity_Suppress.Table (Entity_Suppress.Last).Entity;
case Entity_Suppress.Table (Entity_Suppress.Last).Check is
when Access_Check =>
Set_Suppress_Access_Checks (E, False);
when Accessibility_Check =>
Set_Suppress_Accessibility_Checks (E, False);
when Discriminant_Check =>
Set_Suppress_Discriminant_Checks (E, False);
when Division_Check =>
Set_Suppress_Division_Checks (E, False);
when Elaboration_Check =>
Set_Suppress_Elaboration_Checks (E, False);
when Index_Check =>
Set_Suppress_Index_Checks (E, False);
when Length_Check =>
Set_Suppress_Length_Checks (E, False);
when Overflow_Check =>
Set_Suppress_Overflow_Checks (E, False);
when Range_Check =>
Set_Suppress_Range_Checks (E, False);
when Storage_Check =>
Set_Suppress_Storage_Checks (E, False);
when Tag_Check =>
Set_Suppress_Tag_Checks (E, False);
when All_Checks =>
raise Program_Error;
end case;
Entity_Suppress.Decrement_Last;
end loop;
if Debug_Flag_W then
Write_Str ("--> exiting scope: ");
Write_Name (Chars (Current_Scope));
Write_Str (", Depth=");
Write_Int (Int (Scope_Stack.Last));
Write_Eol;
end if;
End_Use_Clauses (Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause);
pragma Assert (Scope_Stack.Table
(Scope_Stack.Last).Actions_To_Be_Wrapped_Before = No_List);
pragma Assert (Scope_Stack.Table
(Scope_Stack.Last).Actions_To_Be_Wrapped_After = No_List);
Free (Scope_Stack.Table (Scope_Stack.Last).Last_Subprogram_Name);
Scope_Stack.Decrement_Last;
end Pop_Scope;
procedure Premature_Usage (N : Node_Id) is
Kind : Node_Kind := Nkind (Parent (Entity (N)));
E : Entity_Id := Entity (N);
begin
if In_Instance
and then Present (Homonym (E))
then
E := Homonym (E);
while Present (E)
and then not In_Open_Scopes (Scope (E))
loop
E := Homonym (E);
end loop;
if Present (E) then
Set_Entity (N, E);
Set_Etype (N, Etype (E));
return;
end if;
end if;
if Kind = N_Component_Declaration then
Error_Msg_N
("component&! cannot be used before end of record declaration", N);
elsif Kind = N_Parameter_Specification then
Error_Msg_N
("formal parameter&! cannot be used before end of specification",
N);
elsif Kind = N_Discriminant_Specification then
Error_Msg_N
("discriminant&! cannot be used before end of discriminant part",
N);
elsif Kind = N_Procedure_Specification
or else Kind = N_Function_Specification
then
Error_Msg_N
("subprogram&! cannot be used before end of its declaration",
N);
else
Error_Msg_N
("object& cannot be used before end of its declaration!", N);
end if;
end Premature_Usage;
function Present_System_Aux (N : Node_Id := Empty) return Boolean is
Loc : Source_Ptr;
Aux_Name : Name_Id;
Unum : Unit_Number_Type;
Withn : Node_Id;
With_Sys : Node_Id;
The_Unit : Node_Id;
function Find_System (C_Unit : Node_Id) return Entity_Id;
function Find_System (C_Unit : Node_Id) return Entity_Id is
With_Clause : Node_Id;
begin
With_Clause := First (Context_Items (C_Unit));
while Present (With_Clause) loop
if (Nkind (With_Clause) = N_With_Clause
and then Chars (Name (With_Clause)) = Name_System)
and then Comes_From_Source (With_Clause)
then
return With_Clause;
end if;
Next (With_Clause);
end loop;
return Empty;
end Find_System;
begin
if Present (System_Aux_Id) then
return True;
elsif No (System_Extend_Pragma_Arg) then
return False;
else
With_Sys := Find_System (Cunit (Current_Sem_Unit));
The_Unit := Unit (Cunit (Current_Sem_Unit));
if No (With_Sys)
and then (Nkind (The_Unit) = N_Package_Body
or else (Nkind (The_Unit) = N_Subprogram_Body
and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
then
With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
end if;
if No (With_Sys)
and then Present (N)
then
The_Unit := Parent (N);
while Nkind (The_Unit) /= N_Compilation_Unit loop
The_Unit := Parent (The_Unit);
end loop;
if Nkind (Unit (The_Unit)) = N_Subunit then
With_Sys := Find_System (The_Unit);
end if;
end if;
if No (With_Sys) then
return False;
end if;
Loc := Sloc (With_Sys);
Get_Name_String (Chars (Expression (System_Extend_Pragma_Arg)));
Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
Name_Buffer (1 .. 7) := "system.";
Name_Buffer (Name_Len + 8) := '%';
Name_Buffer (Name_Len + 9) := 's';
Name_Len := Name_Len + 9;
Aux_Name := Name_Find;
Unum :=
Load_Unit
(Load_Name => Aux_Name,
Required => False,
Subunit => False,
Error_Node => With_Sys);
if Unum /= No_Unit then
Semantics (Cunit (Unum));
System_Aux_Id :=
Defining_Entity (Specification (Unit (Cunit (Unum))));
Withn := Make_With_Clause (Loc,
Name =>
Make_Expanded_Name (Loc,
Chars => Chars (System_Aux_Id),
Prefix =>
New_Reference_To (Scope (System_Aux_Id), Loc),
Selector_Name =>
New_Reference_To (System_Aux_Id, Loc)));
Set_Entity (Name (Withn), System_Aux_Id);
Set_Library_Unit (Withn, Cunit (Unum));
Set_Corresponding_Spec (Withn, System_Aux_Id);
Set_First_Name (Withn, True);
Set_Implicit_With (Withn, True);
Insert_After (With_Sys, Withn);
Mark_Rewrite_Insertion (Withn);
Set_Context_Installed (Withn);
return True;
else
Error_Msg_Name_1 := Name_System;
Error_Msg_Name_2 := Chars (Expression (System_Extend_Pragma_Arg));
Error_Msg_N
("extension package `%.%` does not exist",
Opt.System_Extend_Pragma_Arg);
return False;
end if;
end if;
end Present_System_Aux;
procedure Restore_Scope_Stack is
E : Entity_Id;
S : Entity_Id;
Comp_Unit : Node_Id;
In_Child : Boolean := False;
Full_Vis : Boolean := True;
begin
for J in reverse 0 .. Scope_Stack.Last loop
exit when Scope_Stack.Table (J).Entity = Standard_Standard
or else No (Scope_Stack.Table (J).Entity);
S := Scope_Stack.Table (J).Entity;
if not Is_Hidden_Open_Scope (S) then
if not Is_Hidden_Open_Scope (Scope (S))
or else not Analyzed (Parent (S))
or else Scope (S) = Standard_Standard
then
Set_Is_Immediately_Visible (S, True);
end if;
E := First_Entity (S);
while Present (E) loop
if Is_Child_Unit (E) then
Set_Is_Immediately_Visible (E,
Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
else
Set_Is_Immediately_Visible (E, True);
end if;
Next_Entity (E);
if not Full_Vis then
exit when E = First_Private_Entity (S);
end if;
end loop;
if not Full_Vis
and then Present (E)
then
while Present (E) loop
if Is_Child_Unit (E) then
Set_Is_Immediately_Visible (E,
Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
end if;
Next_Entity (E);
end loop;
end if;
end if;
if Is_Child_Unit (S)
and not In_Child then
In_Child := True;
Comp_Unit := Parent (Unit_Declaration_Node (S));
if Nkind (Comp_Unit) = N_Compilation_Unit
and then Private_Present (Comp_Unit)
then
Full_Vis := True;
elsif (Ekind (S) = E_Package
or else Ekind (S) = E_Generic_Package)
and then (In_Private_Part (S)
or else In_Package_Body (S))
then
Full_Vis := True;
elsif (Ekind (S) = E_Procedure
or else Ekind (S) = E_Function)
and then Has_Completion (S)
then
Full_Vis := True;
else
Full_Vis := False;
end if;
else
Full_Vis := True;
end if;
end loop;
end Restore_Scope_Stack;
procedure Save_Scope_Stack is
E : Entity_Id;
S : Entity_Id;
SS_Last : constant Int := Scope_Stack.Last;
begin
if SS_Last >= Scope_Stack.First
and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
then
for J in reverse 0 .. SS_Last loop
exit when Scope_Stack.Table (J).Entity = Standard_Standard
or else No (Scope_Stack.Table (J).Entity);
S := Scope_Stack.Table (J).Entity;
Set_Is_Immediately_Visible (S, False);
E := First_Entity (S);
while Present (E) loop
Set_Is_Immediately_Visible (E, False);
Next_Entity (E);
end loop;
end loop;
end if;
end Save_Scope_Stack;
procedure Set_Use (L : List_Id) is
Decl : Node_Id;
Pack_Name : Node_Id;
Pack : Entity_Id;
Id : Entity_Id;
begin
if Present (L) then
Decl := First (L);
while Present (Decl) loop
if Nkind (Decl) = N_Use_Package_Clause then
Chain_Use_Clause (Decl);
Pack_Name := First (Names (Decl));
while Present (Pack_Name) loop
Pack := Entity (Pack_Name);
if Ekind (Pack) = E_Package
and then Applicable_Use (Pack_Name)
then
Use_One_Package (Pack, Decl);
end if;
Next (Pack_Name);
end loop;
elsif Nkind (Decl) = N_Use_Type_Clause then
Chain_Use_Clause (Decl);
Id := First (Subtype_Marks (Decl));
while Present (Id) loop
if Entity (Id) /= Any_Type then
Use_One_Type (Id);
end if;
Next (Id);
end loop;
end if;
Next (Decl);
end loop;
end if;
end Set_Use;
procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
Id : Entity_Id;
Prev : Entity_Id;
Current_Instance : Entity_Id := Empty;
Real_P : Entity_Id;
begin
if Ekind (P) /= E_Package then
return;
end if;
Set_In_Use (P);
if From_With_Type (P) then
Error_Msg_N ("imported package cannot appear in use clause", N);
end if;
if In_Instance then
Current_Instance := Current_Scope;
while not Is_Generic_Instance (Current_Instance) loop
Current_Instance := Scope (Current_Instance);
end loop;
if No (Hidden_By_Use_Clause (N)) then
Set_Hidden_By_Use_Clause (N, New_Elmt_List);
end if;
end if;
if Present (Renamed_Object (P)) then
Set_In_Use (Renamed_Object (P));
Real_P := Renamed_Object (P);
else
Real_P := P;
end if;
Id := First_Entity (P);
while Present (Id)
and then Id /= First_Private_Entity (P)
loop
Prev := Current_Entity (Id);
while Present (Prev) loop
if Is_Immediately_Visible (Prev)
and then (not Is_Overloadable (Prev)
or else not Is_Overloadable (Id)
or else (Type_Conformant (Id, Prev)))
then
if No (Current_Instance) then
goto Next_Usable_Entity;
elsif not Is_Hidden (Id)
and then not Is_Wrapper_Package (Scope (Prev))
and then Scope_Depth (Scope (Prev)) <
Scope_Depth (Current_Instance)
and then (Scope (Prev) /= Standard_Standard
or else Sloc (Prev) > Standard_Location)
then
Set_Is_Potentially_Use_Visible (Id);
Set_Is_Immediately_Visible (Prev, False);
Append_Elmt (Prev, Hidden_By_Use_Clause (N));
end if;
elsif Ekind (Prev) = E_Operator
and then Operator_Matches_Spec (Prev, Id)
and then In_Open_Scopes
(Scope (Base_Type (Etype (First_Formal (Id)))))
and then (No (Next_Formal (First_Formal (Id)))
or else Etype (First_Formal (Id))
= Etype (Next_Formal (First_Formal (Id)))
or else Chars (Prev) = Name_Op_Expon)
then
goto Next_Usable_Entity;
end if;
Prev := Homonym (Prev);
end loop;
if not Is_Hidden (Id)
and then ((not Is_Child_Unit (Id))
or else Is_Visible_Child_Unit (Id))
then
Set_Is_Potentially_Use_Visible (Id);
if Is_Private_Type (Id)
and then Present (Full_View (Id))
then
Set_Is_Potentially_Use_Visible (Full_View (Id));
end if;
end if;
<<Next_Usable_Entity>>
Next_Entity (Id);
end loop;
while Present (Id) loop
if Is_Child_Unit (Id)
and then Is_Visible_Child_Unit (Id)
then
Set_Is_Potentially_Use_Visible (Id);
end if;
Next_Entity (Id);
end loop;
if Chars (Real_P) = Name_System
and then Scope (Real_P) = Standard_Standard
and then Present_System_Aux (N)
then
Use_One_Package (System_Aux_Id, N);
end if;
end Use_One_Package;
procedure Use_One_Type (Id : Node_Id) is
T : Entity_Id;
Op_List : Elist_Id;
Elmt : Elmt_Id;
begin
T := Base_Type (Entity (Id));
Set_Redundant_Use
(Id, In_Use (T) or else Is_Potentially_Use_Visible (T));
if In_Open_Scopes (Scope (T)) then
null;
elsif not Redundant_Use (Id) then
Set_In_Use (T);
Op_List := Collect_Primitive_Operations (T);
Elmt := First_Elmt (Op_List);
while Present (Elmt) loop
if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
or else Chars (Node (Elmt)) in Any_Operator_Name)
and then not Is_Hidden (Node (Elmt))
then
Set_Is_Potentially_Use_Visible (Node (Elmt));
end if;
Next_Elmt (Elmt);
end loop;
end if;
end Use_One_Type;
procedure Write_Info is
Id : Entity_Id := First_Entity (Current_Scope);
begin
if Current_Scope = Standard_Standard then
return;
end if;
Write_Str ("========================================================");
Write_Eol;
Write_Str (" Defined Entities in ");
Write_Name (Chars (Current_Scope));
Write_Eol;
Write_Str ("========================================================");
Write_Eol;
if No (Id) then
Write_Str ("-- none --");
Write_Eol;
else
while Present (Id) loop
Write_Entity_Info (Id, " ");
Next_Entity (Id);
end loop;
end if;
if Scope (Current_Scope) = Standard_Standard then
Write_Entity_Info (Current_Scope, " ");
end if;
Write_Eol;
end Write_Info;
procedure Write_Scopes is
S : Entity_Id;
begin
for J in reverse 1 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
Write_Int (Int (S));
Write_Str (" === ");
Write_Name (Chars (S));
Write_Eol;
end loop;
end Write_Scopes;
end Sem_Ch8;