with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch11; use Exp_Ch11;
with Exp_Pakd; use Exp_Pakd;
with Exp_Util; use Exp_Util;
with Exp_Tss; use Exp_Tss;
with Layout; use Layout;
with Lib.Xref; use Lib.Xref;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Sem; use Sem;
with Sem_Cat; use Sem_Cat;
with Sem_Ch6; use Sem_Ch6;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
with Sem_Eval; use Sem_Eval;
with Sem_Mech; use Sem_Mech;
with Sem_Prag; use Sem_Prag;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Urealp; use Urealp;
package body Freeze is
procedure Adjust_Esize_For_Alignment (Typ : Entity_Id);
procedure Build_And_Analyze_Renamed_Body
(Decl : Node_Id;
New_S : Entity_Id;
After : in out Node_Id);
procedure Check_Address_Clause (E : Entity_Id);
procedure Check_Strict_Alignment (E : Entity_Id);
procedure Check_Unsigned_Type (E : Entity_Id);
pragma Inline (Check_Unsigned_Type);
procedure Freeze_And_Append
(Ent : Entity_Id;
Loc : Source_Ptr;
Result : in out List_Id);
procedure Freeze_Enumeration_Type (Typ : Entity_Id);
procedure Freeze_Static_Object (E : Entity_Id);
procedure Freeze_Subprogram (E : Entity_Id);
function Is_Fully_Defined (T : Entity_Id) return Boolean;
procedure Process_Default_Expressions
(E : Entity_Id;
After : in out Node_Id);
procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id);
procedure Check_Debug_Info_Needed (T : Entity_Id);
procedure Set_Debug_Info_Needed (T : Entity_Id);
procedure Warn_Overlay
(Expr : Node_Id;
Typ : Entity_Id;
Nam : Node_Id);
procedure Adjust_Esize_For_Alignment (Typ : Entity_Id) is
Align : Uint;
begin
if Known_Esize (Typ) and then Known_Alignment (Typ) then
Align := Alignment_In_Bits (Typ);
if Align > Esize (Typ)
and then Align <= Standard_Long_Long_Integer_Size
then
Set_Esize (Typ, Align);
end if;
end if;
end Adjust_Esize_For_Alignment;
procedure Build_And_Analyze_Renamed_Body
(Decl : Node_Id;
New_S : Entity_Id;
After : in out Node_Id)
is
Body_Node : constant Node_Id := Build_Renamed_Body (Decl, New_S);
begin
Insert_After (After, Body_Node);
Mark_Rewrite_Insertion (Body_Node);
Analyze (Body_Node);
After := Body_Node;
end Build_And_Analyze_Renamed_Body;
function Build_Renamed_Body
(Decl : Node_Id;
New_S : Entity_Id) return Node_Id
is
Loc : constant Source_Ptr := Sloc (New_S);
N : constant Node_Id := Unit_Declaration_Node (New_S);
Nam : constant Node_Id := Name (N);
Old_S : Entity_Id;
Spec : constant Node_Id := New_Copy_Tree (Specification (Decl));
Actuals : List_Id := No_List;
Call_Node : Node_Id;
Call_Name : Node_Id;
Body_Node : Node_Id;
Formal : Entity_Id;
O_Formal : Entity_Id;
Param_Spec : Node_Id;
begin
if Nkind (Nam) = N_Selected_Component then
Old_S := Entity (Selector_Name (Nam));
elsif Nkind (Nam) = N_Explicit_Dereference then
Old_S := Etype (Nam);
elsif Nkind (Nam) = N_Indexed_Component then
if Is_Entity_Name (Prefix (Nam)) then
Old_S := Entity (Prefix (Nam));
else
Old_S := Entity (Selector_Name (Prefix (Nam)));
end if;
elsif Nkind (Nam) = N_Character_Literal then
Old_S := Etype (New_S);
else
Old_S := Entity (Nam);
end if;
if Is_Entity_Name (Nam) then
if Ekind (Old_S) = E_Operator
and then Nkind (Nam) = N_Expanded_Name
then
Call_Name := New_Copy (Name (N));
else
Call_Name := New_Reference_To (Old_S, Loc);
end if;
else
Call_Name := New_Copy (Name (N));
Set_Is_Overloaded (Call_Name, False);
end if;
if (Ekind (Old_S) = E_Function
or else Ekind (Old_S) = E_Procedure)
and then Nkind (Decl) = N_Subprogram_Declaration
then
Set_Body_To_Inline (Decl, Old_S);
end if;
Set_Must_Not_Freeze (Call_Name);
Formal := First_Formal (Defining_Entity (Decl));
if Present (Formal) then
Actuals := New_List;
while Present (Formal) loop
Append (New_Reference_To (Formal, Loc), Actuals);
Next_Formal (Formal);
end loop;
end if;
Formal := First_Formal (Defining_Entity (Decl));
if Present (Formal) then
O_Formal := First_Formal (Old_S);
Param_Spec := First (Parameter_Specifications (Spec));
while Present (Formal) loop
if Is_Entry (Old_S) then
if Nkind (Parameter_Type (Param_Spec)) /=
N_Access_Definition
then
Set_Etype (Formal, Etype (O_Formal));
Set_Entity (Parameter_Type (Param_Spec), Etype (O_Formal));
end if;
elsif Nkind (Default_Value (O_Formal)) = N_Aggregate
or else Nkind (Original_Node (Default_Value (O_Formal))) /=
Nkind (Default_Value (O_Formal))
then
Set_Expression (Param_Spec,
New_Copy_Tree (Original_Node (Default_Value (O_Formal))));
end if;
Next_Formal (Formal);
Next_Formal (O_Formal);
Next (Param_Spec);
end loop;
end if;
if Ekind (Old_S) = E_Function
or else Ekind (Old_S) = E_Operator
or else (Ekind (Old_S) = E_Subprogram_Type
and then Etype (Old_S) /= Standard_Void_Type)
then
Call_Node :=
Make_Return_Statement (Loc,
Expression =>
Make_Function_Call (Loc,
Name => Call_Name,
Parameter_Associations => Actuals));
elsif Ekind (Old_S) = E_Enumeration_Literal then
Call_Node :=
Make_Return_Statement (Loc,
Expression => New_Occurrence_Of (Old_S, Loc));
elsif Nkind (Nam) = N_Character_Literal then
Call_Node :=
Make_Return_Statement (Loc,
Expression => Call_Name);
else
Call_Node :=
Make_Procedure_Call_Statement (Loc,
Name => Call_Name,
Parameter_Associations => Actuals);
end if;
Set_Defining_Unit_Name (Spec,
Make_Defining_Identifier (Loc, Chars => Chars (New_S)));
Param_Spec := First (Parameter_Specifications (Spec));
while Present (Param_Spec) loop
Set_Defining_Identifier (Param_Spec,
Make_Defining_Identifier (Loc,
Chars => Chars (Defining_Identifier (Param_Spec))));
Next (Param_Spec);
end loop;
Body_Node :=
Make_Subprogram_Body (Loc,
Specification => Spec,
Declarations => New_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Call_Node)));
if Nkind (Decl) /= N_Subprogram_Declaration then
Rewrite (N,
Make_Subprogram_Declaration (Loc,
Specification => Specification (N)));
end if;
if Nkind (N) = N_Subprogram_Renaming_Declaration
and then Present (Corresponding_Spec (N))
then
Set_Corresponding_Spec (Body_Node, Corresponding_Spec (N));
else
Set_Corresponding_Spec (Body_Node, New_S);
end if;
return Body_Node;
end Build_Renamed_Body;
procedure Check_Address_Clause (E : Entity_Id) is
Addr : constant Node_Id := Address_Clause (E);
Expr : Node_Id;
Decl : constant Node_Id := Declaration_Node (E);
Typ : constant Entity_Id := Etype (E);
begin
if Present (Addr) then
Expr := Expression (Addr);
if (No (Expression (Decl))
and then not Controlled_Type (Typ)
and then
(not Has_Non_Null_Base_Init_Proc (Typ)
or else Is_Imported (E)))
or else
(Present (Expression (Decl))
and then Is_Scalar_Type (Typ))
or else
Is_Access_Type (Typ)
or else
(Is_Bit_Packed_Array (Typ)
and then
Is_Modular_Integer_Type (Packed_Array_Type (Typ)))
then
null;
else
Check_Constant_Address_Clause (Expr, E);
Set_Has_Delayed_Freeze (E, False);
end if;
if not Error_Posted (Expr)
and then not Controlled_Type (Typ)
then
Warn_Overlay (Expr, Typ, Name (Addr));
end if;
end if;
end Check_Address_Clause;
procedure Check_Compile_Time_Size (T : Entity_Id) is
procedure Set_Small_Size (S : Uint);
function Size_Known (T : Entity_Id) return Boolean;
function Static_Discriminated_Components (T : Entity_Id) return Boolean;
procedure Set_Small_Size (S : Uint) is
begin
if S > 32 then
return;
elsif Has_Size_Clause (T) then
if RM_Size (T) < S then
Error_Msg_Uint_1 := S;
Error_Msg_NE
("size for & is too small, minimum is ^",
Size_Clause (T), T);
elsif Unknown_Esize (T) then
Set_Esize (T, S);
end if;
else
if Unknown_Esize (T) then
Set_Esize (T, S);
end if;
if Unknown_RM_Size (T) then
Set_RM_Size (T, S);
end if;
end if;
end Set_Small_Size;
function Size_Known (T : Entity_Id) return Boolean is
Index : Entity_Id;
Comp : Entity_Id;
Ctyp : Entity_Id;
Low : Node_Id;
High : Node_Id;
begin
if Size_Known_At_Compile_Time (T) then
return True;
elsif Is_Scalar_Type (T)
or else Is_Task_Type (T)
then
return not Is_Generic_Type (T);
elsif Is_Array_Type (T) then
if Ekind (T) = E_String_Literal_Subtype then
Set_Small_Size (Component_Size (T) * String_Literal_Length (T));
return True;
elsif not Is_Constrained (T) then
return False;
elsif Error_Posted (T) then
return False;
elsif not Size_Known (Component_Type (T)) then
return False;
end if;
declare
Esiz : Uint := Component_Size (T);
Dim : Uint;
begin
Index := First_Index (T);
while Present (Index) loop
if Nkind (Index) = N_Range then
Get_Index_Bounds (Index, Low, High);
elsif Error_Posted (Scalar_Range (Etype (Index))) then
return False;
else
Low := Type_Low_Bound (Etype (Index));
High := Type_High_Bound (Etype (Index));
end if;
if not Compile_Time_Known_Value (Low)
or else not Compile_Time_Known_Value (High)
or else Etype (Index) = Any_Type
then
return False;
else
Dim := Expr_Value (High) - Expr_Value (Low) + 1;
if Dim >= 0 then
Esiz := Esiz * Dim;
else
Esiz := Uint_0;
end if;
end if;
Next_Index (Index);
end loop;
Set_Small_Size (Esiz);
return True;
end;
elsif Is_Access_Type (T) then
return True;
elsif Is_Private_Type (T)
and then not Is_Generic_Type (T)
and then Present (Underlying_Type (T))
then
if Error_Posted (T) then
return False;
else
return Size_Known (Underlying_Type (T));
end if;
elsif Is_Record_Type (T) then
if Is_Class_Wide_Type (T) then
return False;
elsif T /= Base_Type (T)
and then not Static_Discriminated_Components (T)
then
return False;
elsif Error_Posted (T) then
return False;
end if;
declare
Packed_Size_Known : Boolean :=
Is_Packed (T)
and then not Has_Discriminants (T);
Packed_Size : Uint := Uint_0;
begin
if Has_Discriminants (T)
and then Present (Parent (T))
and then Nkind (Parent (T)) = N_Full_Type_Declaration
and then Nkind (Type_Definition (Parent (T))) =
N_Record_Definition
and then not Null_Present (Type_Definition (Parent (T)))
and then Present (Variant_Part
(Component_List (Type_Definition (Parent (T)))))
then
if not Is_Constrained (T)
and then
No (Discriminant_Default_Value
(First_Discriminant (T)))
and then Unknown_Esize (T)
then
return False;
end if;
end if;
Comp := First_Entity (T);
while Present (Comp) loop
if Ekind (Comp) = E_Component
or else
Ekind (Comp) = E_Discriminant
then
Ctyp := Etype (Comp);
if Present (Component_Clause (Comp)) then
Packed_Size_Known := False;
end if;
if Is_Array_Type (Etype (Comp))
and then Present (Packed_Array_Type (Etype (Comp)))
then
declare
Ocomp : constant Entity_Id :=
Original_Record_Component (Comp);
OCtyp : constant Entity_Id := Etype (Ocomp);
Ind : Node_Id;
Indtyp : Entity_Id;
Lo, Hi : Node_Id;
begin
Ind := First_Index (OCtyp);
while Present (Ind) loop
Indtyp := Etype (Ind);
if Is_Enumeration_Type (Indtyp)
and then Has_Non_Standard_Rep (Indtyp)
then
Lo := Type_Low_Bound (Indtyp);
Hi := Type_High_Bound (Indtyp);
if Is_Entity_Name (Lo)
and then
Ekind (Entity (Lo)) = E_Discriminant
then
return False;
elsif Is_Entity_Name (Hi)
and then
Ekind (Entity (Hi)) = E_Discriminant
then
return False;
end if;
end if;
Next_Index (Ind);
end loop;
end;
end if;
if not Size_Known (Ctyp) then
return False;
end if;
if Packed_Size_Known then
if Is_Elementary_Type (Ctyp)
or else (Is_Array_Type (Ctyp)
and then
Present (Packed_Array_Type (Ctyp))
and then
Is_Modular_Integer_Type
(Packed_Array_Type (Ctyp)))
then
if Known_Static_RM_Size (Ctyp) then
if RM_Size (Ctyp) = Uint_0 then
Packed_Size_Known := False;
else
Packed_Size := Packed_Size + RM_Size (Ctyp);
end if;
else
Packed_Size_Known := False;
end if;
else
Packed_Size_Known := False;
end if;
end if;
end if;
Next_Entity (Comp);
end loop;
if Packed_Size_Known then
Set_Small_Size (Packed_Size);
end if;
return True;
end;
else
return False;
end if;
end Size_Known;
function Static_Discriminated_Components
(T : Entity_Id) return Boolean
is
Constraint : Elmt_Id;
begin
if Has_Discriminants (T)
and then Present (Discriminant_Constraint (T))
and then Present (First_Component (T))
then
Constraint := First_Elmt (Discriminant_Constraint (T));
while Present (Constraint) loop
if not Compile_Time_Known_Value (Node (Constraint)) then
return False;
end if;
Next_Elmt (Constraint);
end loop;
end if;
return True;
end Static_Discriminated_Components;
begin
Set_Size_Known_At_Compile_Time (T, Size_Known (T));
end Check_Compile_Time_Size;
procedure Check_Debug_Info_Needed (T : Entity_Id) is
begin
if Needs_Debug_Info (T) or else Debug_Info_Off (T) then
return;
elsif Comes_From_Source (T)
or else Debug_Generated_Code
or else Debug_Flag_VV
then
Set_Debug_Info_Needed (T);
end if;
end Check_Debug_Info_Needed;
procedure Check_Strict_Alignment (E : Entity_Id) is
Comp : Entity_Id;
begin
if Is_Tagged_Type (E) or else Is_Concurrent_Type (E) then
Set_Strict_Alignment (E);
elsif Is_Array_Type (E) then
Set_Strict_Alignment (E, Strict_Alignment (Component_Type (E)));
elsif Is_Record_Type (E) then
if Is_Limited_Record (E) then
Set_Strict_Alignment (E);
return;
end if;
Comp := First_Component (E);
while Present (Comp) loop
if not Is_Type (Comp)
and then (Strict_Alignment (Etype (Comp))
or else Is_Aliased (Comp))
then
Set_Strict_Alignment (E);
return;
end if;
Next_Component (Comp);
end loop;
end if;
end Check_Strict_Alignment;
procedure Check_Unsigned_Type (E : Entity_Id) is
Ancestor : Entity_Id;
Lo_Bound : Node_Id;
Btyp : Entity_Id;
begin
if not Is_Discrete_Or_Fixed_Point_Type (E) then
return;
end if;
if Error_Posted (Scalar_Range (E)) then
return;
end if;
Ancestor := E;
loop
if Ancestor = Any_Type or else Etype (Ancestor) = Any_Type then
return;
end if;
Lo_Bound := Type_Low_Bound (Ancestor);
if Compile_Time_Known_Value (Lo_Bound) then
if Expr_Rep_Value (Lo_Bound) >= 0 then
Set_Is_Unsigned_Type (E, True);
end if;
return;
else
Ancestor := Ancestor_Subtype (Ancestor);
if No (Ancestor) then
Btyp := Base_Type (E);
if Btyp = Any_Type or else Etype (Btyp) = Any_Type then
return;
end if;
Lo_Bound := Type_Low_Bound (Base_Type (E));
if Compile_Time_Known_Value (Lo_Bound)
and then Expr_Rep_Value (Lo_Bound) >= 0
then
Set_Is_Unsigned_Type (E, True);
end if;
return;
end if;
end if;
end loop;
end Check_Unsigned_Type;
procedure Expand_Atomic_Aggregate (E : Entity_Id; Typ : Entity_Id) is
Loc : constant Source_Ptr := Sloc (E);
New_N : Node_Id;
Temp : Entity_Id;
begin
if (Nkind (Parent (E)) = N_Object_Declaration
or else Nkind (Parent (E)) = N_Assignment_Statement)
and then Comes_From_Source (Parent (E))
and then Nkind (E) = N_Aggregate
then
Temp :=
Make_Defining_Identifier (Loc,
New_Internal_Name ('T'));
New_N :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_definition => New_Occurrence_Of (Typ, Loc),
Expression => Relocate_Node (E));
Insert_Before (Parent (E), New_N);
Analyze (New_N);
Set_Expression (Parent (E), New_Occurrence_Of (Temp, Loc));
Set_Is_True_Constant (Temp, False);
end if;
end Expand_Atomic_Aggregate;
procedure Freeze_All (From : Entity_Id; After : in out Node_Id) is
Loc : constant Source_Ptr := Sloc (After);
E : Entity_Id;
Decl : Node_Id;
procedure Freeze_All_Ent (From : Entity_Id; After : in out Node_Id);
procedure Freeze_All_Ent
(From : Entity_Id;
After : in out Node_Id)
is
E : Entity_Id;
Flist : List_Id;
Lastn : Node_Id;
procedure Process_Flist;
procedure Process_Flist is
begin
if Is_Non_Empty_List (Flist) then
Lastn := Next (After);
Insert_List_After_And_Analyze (After, Flist);
if Present (Lastn) then
After := Prev (Lastn);
else
After := Last (List_Containing (After));
end if;
end if;
end Process_Flist;
begin
E := From;
while Present (E) loop
if Ekind (E) = E_Package
and then No (Renamed_Object (E))
and then not Is_Child_Unit (E)
and then not Is_Frozen (E)
then
New_Scope (E);
Install_Visible_Declarations (E);
Install_Private_Declarations (E);
Freeze_All (First_Entity (E), After);
End_Package_Scope (E);
elsif Ekind (E) in Task_Kind
and then
(Nkind (Parent (E)) = N_Task_Type_Declaration
or else
Nkind (Parent (E)) = N_Single_Task_Declaration)
then
New_Scope (E);
Freeze_All (First_Entity (E), After);
End_Scope;
elsif Ekind (E) = E_Record_Type
and then Is_Tagged_Type (E)
and then Is_Tagged_Type (Etype (E))
and then Is_Derived_Type (E)
then
declare
Prim_List : constant Elist_Id :=
Primitive_Operations (Etype (E));
Prim : Elmt_Id;
Subp : Entity_Id;
begin
Prim := First_Elmt (Prim_List);
while Present (Prim) loop
Subp := Node (Prim);
if Comes_From_Source (Subp)
and then not Is_Frozen (Subp)
then
Flist := Freeze_Entity (Subp, Loc);
Process_Flist;
end if;
Next_Elmt (Prim);
end loop;
end;
end if;
if not Is_Frozen (E) then
Flist := Freeze_Entity (E, Loc);
Process_Flist;
end if;
if not Is_Frozen (E)
and then Ekind (E) = E_Incomplete_Type
then
declare
Bod : constant Node_Id := Next (After);
begin
if (Nkind (Bod) = N_Subprogram_Body
or else Nkind (Bod) = N_Entry_Body
or else Nkind (Bod) = N_Package_Body
or else Nkind (Bod) = N_Protected_Body
or else Nkind (Bod) = N_Task_Body
or else Nkind (Bod) in N_Body_Stub)
and then
List_Containing (After) = List_Containing (Parent (E))
then
Error_Msg_Sloc := Sloc (Next (After));
Error_Msg_NE
("type& is frozen# before its full declaration",
Parent (E), E);
end if;
end;
end if;
Next_Entity (E);
end loop;
end Freeze_All_Ent;
begin
Freeze_All_Ent (From, After);
E := From;
while Present (E) loop
if Is_Subprogram (E) then
if not Default_Expressions_Processed (E) then
Process_Default_Expressions (E, After);
end if;
if not Has_Completion (E) then
Decl := Unit_Declaration_Node (E);
if Nkind (Decl) = N_Subprogram_Renaming_Declaration then
Build_And_Analyze_Renamed_Body (Decl, E, After);
elsif Nkind (Decl) = N_Subprogram_Declaration
and then Present (Corresponding_Body (Decl))
and then
Nkind (Unit_Declaration_Node (Corresponding_Body (Decl)))
= N_Subprogram_Renaming_Declaration
then
Build_And_Analyze_Renamed_Body
(Decl, Corresponding_Body (Decl), After);
end if;
end if;
elsif Ekind (E) in Task_Kind
and then
(Nkind (Parent (E)) = N_Task_Type_Declaration
or else
Nkind (Parent (E)) = N_Single_Task_Declaration)
then
declare
Ent : Entity_Id;
begin
Ent := First_Entity (E);
while Present (Ent) loop
if Is_Entry (Ent)
and then not Default_Expressions_Processed (Ent)
then
Process_Default_Expressions (Ent, After);
end if;
Next_Entity (Ent);
end loop;
end;
elsif Is_Access_Type (E)
and then Comes_From_Source (E)
and then Ekind (Directly_Designated_Type (E)) = E_Incomplete_Type
and then Controlled_Type (Designated_Type (E))
and then No (Associated_Final_Chain (E))
then
Build_Final_List (Parent (E), E);
end if;
Next_Entity (E);
end loop;
end Freeze_All;
procedure Freeze_And_Append
(Ent : Entity_Id;
Loc : Source_Ptr;
Result : in out List_Id)
is
L : constant List_Id := Freeze_Entity (Ent, Loc);
begin
if Is_Non_Empty_List (L) then
if Result = No_List then
Result := L;
else
Append_List (L, Result);
end if;
end if;
end Freeze_And_Append;
procedure Freeze_Before (N : Node_Id; T : Entity_Id) is
Freeze_Nodes : constant List_Id := Freeze_Entity (T, Sloc (N));
begin
if Is_Non_Empty_List (Freeze_Nodes) then
Insert_Actions (N, Freeze_Nodes);
end if;
end Freeze_Before;
function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id is
Comp : Entity_Id;
F_Node : Node_Id;
Result : List_Id;
Indx : Node_Id;
Formal : Entity_Id;
Atype : Entity_Id;
procedure Check_Current_Instance (Comp_Decl : Node_Id);
function After_Last_Declaration return Boolean;
procedure Freeze_Record_Type (Rec : Entity_Id);
function After_Last_Declaration return Boolean is
Spec : constant Node_Id := Parent (Current_Scope);
begin
if Nkind (Spec) = N_Package_Specification then
if Present (Private_Declarations (Spec)) then
return Loc >= Sloc (Last (Private_Declarations (Spec)));
elsif Present (Visible_Declarations (Spec)) then
return Loc >= Sloc (Last (Visible_Declarations (Spec)));
else
return False;
end if;
else
return False;
end if;
end After_Last_Declaration;
procedure Check_Current_Instance (Comp_Decl : Node_Id) is
function Process (N : Node_Id) return Traverse_Result;
function Process (N : Node_Id) return Traverse_Result is
begin
case Nkind (N) is
when N_Attribute_Reference =>
if (Attribute_Name (N) = Name_Access
or else
Attribute_Name (N) = Name_Unchecked_Access)
and then Is_Entity_Name (Prefix (N))
and then Is_Type (Entity (Prefix (N)))
and then Entity (Prefix (N)) = E
then
Error_Msg_N
("current instance must be a limited type", Prefix (N));
return Abandon;
else
return OK;
end if;
when others => return OK;
end case;
end Process;
procedure Traverse is new Traverse_Proc (Process);
begin
Traverse (Comp_Decl);
end Check_Current_Instance;
procedure Freeze_Record_Type (Rec : Entity_Id) is
Comp : Entity_Id;
IR : Node_Id;
Junk : Boolean;
ADC : Node_Id;
Unplaced_Component : Boolean := False;
Placed_Component : Boolean := False;
procedure Check_Itype (Desig : Entity_Id);
procedure Check_Itype (Desig : Entity_Id) is
begin
if not Is_Frozen (Desig)
and then Is_Frozen (Base_Type (Desig))
then
Set_Is_Frozen (Desig);
if Ekind (Comp) = E_Component
and then Is_Itype (Etype (Comp))
and then not Has_Discriminants (Rec)
then
IR := Make_Itype_Reference (Sloc (Comp));
Set_Itype (IR, Desig);
if No (Result) then
Result := New_List (IR);
else
Append (IR, Result);
end if;
end if;
end if;
end Check_Itype;
begin
if Rec /= Base_Type (Rec)
and then Has_Controlled_Component (Rec)
then
if Nkind (Parent (Rec)) = N_Subtype_Declaration
and then Is_Entity_Name (Subtype_Indication (Parent (Rec)))
then
Set_First_Entity (Rec, First_Entity (Base_Type (Rec)));
elsif Is_Itype (Rec)
and then Has_Delayed_Freeze (Base_Type (Rec))
and then
Nkind (Associated_Node_For_Itype (Rec)) =
N_Component_Declaration
then
Ensure_Freeze_Node (Rec);
end if;
end if;
Comp := First_Entity (Rec);
while Present (Comp) loop
if not Is_Type (Comp) then
Freeze_And_Append (Etype (Comp), Loc, Result);
end if;
if Is_Access_Type (Etype (Comp))
and then Present (Parent (Comp))
and then Present (Expression (Parent (Comp)))
and then Nkind (Expression (Parent (Comp))) = N_Allocator
then
declare
Alloc : constant Node_Id := Expression (Parent (Comp));
begin
if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then
if Is_Entity_Name (Expression (Alloc)) then
Freeze_And_Append
(Entity (Expression (Alloc)), Loc, Result);
elsif
Nkind (Expression (Alloc)) = N_Subtype_Indication
then
Freeze_And_Append
(Entity (Subtype_Mark (Expression (Alloc))),
Loc, Result);
end if;
elsif Is_Itype (Designated_Type (Etype (Comp))) then
Check_Itype (Designated_Type (Etype (Comp)));
else
Freeze_And_Append
(Designated_Type (Etype (Comp)), Loc, Result);
end if;
end;
elsif Is_Access_Type (Etype (Comp))
and then Is_Itype (Designated_Type (Etype (Comp)))
then
Check_Itype (Designated_Type (Etype (Comp)));
elsif Is_Array_Type (Etype (Comp))
and then Is_Access_Type (Component_Type (Etype (Comp)))
and then Present (Parent (Comp))
and then Nkind (Parent (Comp)) = N_Component_Declaration
and then Present (Expression (Parent (Comp)))
and then Nkind (Expression (Parent (Comp))) = N_Aggregate
and then Is_Fully_Defined
(Designated_Type (Component_Type (Etype (Comp))))
then
Freeze_And_Append
(Designated_Type
(Component_Type (Etype (Comp))), Loc, Result);
end if;
if Ekind (Comp) = E_Component
or else Ekind (Comp) = E_Discriminant
then
declare
CC : constant Node_Id := Component_Clause (Comp);
begin
if Present (CC) then
Placed_Component := True;
if Inside_A_Generic then
null;
elsif not Size_Known_At_Compile_Time
(Underlying_Type (Etype (Comp)))
then
Error_Msg_N
("component clause not allowed for variable " &
"length component", CC);
end if;
else
Unplaced_Component := True;
end if;
if Must_Be_On_Byte_Boundary (Etype (Comp)) then
Set_Must_Be_On_Byte_Boundary (Rec);
if Present (CC)
and then Normalized_First_Bit (Comp) mod
System_Storage_Unit /= 0
then
Error_Msg_N
("component & must be byte aligned",
Component_Name (Component_Clause (Comp)));
end if;
end if;
if Present (CC)
and then Reverse_Bit_Order (Rec)
and then Ekind (E) = E_Record_Type
then
declare
CFB : constant Uint := Component_Bit_Offset (Comp);
CSZ : constant Uint := Esize (Comp);
CLC : constant Node_Id := Component_Clause (Comp);
Pos : constant Node_Id := Position (CLC);
FB : constant Node_Id := First_Bit (CLC);
Storage_Unit_Offset : constant Uint :=
CFB / System_Storage_Unit;
Start_Bit : constant Uint :=
CFB mod System_Storage_Unit;
begin
if Start_Bit + CSZ > System_Storage_Unit then
if Start_Bit mod System_Storage_Unit = 0
and then CSZ mod System_Storage_Unit = 0
then
Error_Msg_N
("multi-byte field specified with non-standard"
& " Bit_Order?", CLC);
if Bytes_Big_Endian then
Error_Msg_N
("bytes are not reversed "
& "(component is big-endian)?", CLC);
else
Error_Msg_N
("bytes are not reversed "
& "(component is little-endian)?", CLC);
end if;
else
Error_Msg_N
("attempt to specify non-contiguous field"
& " not permitted", CLC);
Error_Msg_N
("\(caused by non-standard Bit_Order "
& "specified)", CLC);
end if;
else
if Intval (FB) >= System_Storage_Unit then
Error_Msg_N
("?Bit_Order clause does not affect " &
"byte ordering", Pos);
Error_Msg_Uint_1 :=
Intval (Pos) + Intval (FB) /
System_Storage_Unit;
Error_Msg_N
("?position normalized to ^ before bit " &
"order interpreted", Pos);
end if;
Set_Component_Bit_Offset
(Comp,
(Storage_Unit_Offset * System_Storage_Unit) +
(System_Storage_Unit - 1) -
(Start_Bit + CSZ - 1));
Set_Normalized_First_Bit
(Comp,
Component_Bit_Offset (Comp) mod
System_Storage_Unit);
end if;
end;
end if;
end;
end if;
Next_Entity (Comp);
end loop;
if not Placed_Component and then Reverse_Bit_Order (Rec) then
ADC := Get_Attribute_Definition_Clause (Rec, Attribute_Bit_Order);
Error_Msg_N ("?Bit_Order specification has no effect", ADC);
Error_Msg_N ("\?since no component clauses were specified", ADC);
end if;
if Is_Packed (Rec)
and then not Unplaced_Component
and then Warn_On_Redundant_Constructs
then
Error_Msg_N
("?pragma Pack has no effect, no unplaced components",
Get_Rep_Pragma (Rec, Name_Pack));
Set_Is_Packed (Rec, False);
end if;
if Ekind (Rec) = E_Record_Type then
if Present (Corresponding_Remote_Type (Rec)) then
Freeze_And_Append
(Corresponding_Remote_Type (Rec), Loc, Result);
end if;
Comp := First_Component (Rec);
while Present (Comp) loop
if Has_Controlled_Component (Etype (Comp))
or else (Chars (Comp) /= Name_uParent
and then Is_Controlled (Etype (Comp)))
or else (Is_Protected_Type (Etype (Comp))
and then Present
(Corresponding_Record_Type (Etype (Comp)))
and then Has_Controlled_Component
(Corresponding_Record_Type (Etype (Comp))))
then
Set_Has_Controlled_Component (Rec);
exit;
end if;
if Has_Unchecked_Union (Etype (Comp)) then
Set_Has_Unchecked_Union (Rec);
end if;
if Has_Per_Object_Constraint (Comp)
and then not Is_Limited_Type (Rec)
then
Check_Current_Instance (Parent (Comp));
end if;
Next_Component (Comp);
end loop;
end if;
Set_Component_Alignment_If_Not_Set (Rec);
if Is_First_Subtype (Rec) then
Comp := First_Component (Rec);
while Present (Comp) loop
if Present (Component_Clause (Comp))
and then (Is_Fixed_Point_Type (Etype (Comp))
or else
Is_Bit_Packed_Array (Etype (Comp)))
then
Check_Size
(Component_Name (Component_Clause (Comp)),
Etype (Comp),
Esize (Comp),
Junk);
end if;
Next_Component (Comp);
end loop;
end if;
end Freeze_Record_Type;
begin
if Is_Frozen (E) then
return No_List;
elsif Inside_A_Generic and then External_Ref_In_Generic (E) then
return No_List;
elsif In_Open_Scopes (Scope (E))
and then Scope (E) /= Current_Scope
and then Ekind (E) /= E_Constant
then
declare
S : Entity_Id := Current_Scope;
begin
while Present (S) loop
if Is_Overloadable (S) then
if Comes_From_Source (S)
or else Is_Generic_Instance (S)
then
exit;
else
return No_List;
end if;
end if;
S := Scope (S);
end loop;
end;
elsif Front_End_Inlining
and then In_Instance_Body
and then Present (Scope (E))
then
declare
S : Entity_Id := Scope (E);
begin
while Present (S) loop
if Is_Generic_Instance (S) then
exit;
else
S := Scope (S);
end if;
end loop;
if No (S) then
return No_List;
end if;
end;
end if;
Result := No_List;
Set_Is_Frozen (E);
if not Is_Type (E) then
if (Is_Imported (E) or else Is_Exported (E))
and then No (Interface_Name (E))
and then Convention (E) /= Convention_Stubbed
then
Set_Encoded_Interface_Name
(E, Get_Default_External_Name (E));
elsif Is_Atomic (E)
and then Nkind (Parent (E)) = N_Object_Declaration
and then Present (Expression (Parent (E)))
then
declare
Expr : constant Node_Id := Expression (Parent (E));
begin
if Nkind (Expr) = N_Aggregate then
Expand_Atomic_Aggregate (Expr, Etype (E));
elsif Is_Entity_Name (Expr)
and then (Is_Record_Type (Etype (Expr))
or else
Is_Array_Type (Etype (Expr)))
then
Set_Is_True_Constant (Entity (Expr), False);
end if;
end;
end if;
if Is_Subprogram (E) then
if not Is_Internal (E) then
declare
F_Type : Entity_Id;
Warn_Node : Node_Id;
function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean;
function Is_Fat_C_Ptr_Type (T : Entity_Id) return Boolean is
begin
return (Convention (E) = Convention_C
or else
Convention (E) = Convention_CPP)
and then Is_Access_Type (T)
and then Esize (T) > Ttypes.System_Address_Size;
end Is_Fat_C_Ptr_Type;
begin
Formal := First_Formal (E);
while Present (Formal) loop
F_Type := Etype (Formal);
Freeze_And_Append (F_Type, Loc, Result);
if Is_Private_Type (F_Type)
and then Is_Private_Type (Base_Type (F_Type))
and then No (Full_View (Base_Type (F_Type)))
and then not Is_Generic_Type (F_Type)
and then not Is_Derived_Type (F_Type)
then
if In_Instance then
Set_Is_Frozen (E, False);
return No_List;
elsif not After_Last_Declaration then
Error_Msg_Node_1 := F_Type;
Error_Msg
("type& must be fully defined before this point",
Loc);
end if;
end if;
if Warn_On_Export_Import and then
Is_Fat_C_Ptr_Type (F_Type)
then
Error_Msg_Qual_Level := 1;
Error_Msg_N
("?type of & does not correspond to C pointer",
Formal);
Error_Msg_Qual_Level := 0;
end if;
if Convention (E) in Foreign_Convention
and then not Is_Imported (E)
and then Is_Array_Type (F_Type)
and then not Is_Constrained (F_Type)
and then Warn_On_Export_Import
then
Error_Msg_Qual_Level := 1;
if Nkind (Original_Node (Parent (E))) =
N_Full_Type_Declaration
then
Warn_Node := Parent (E);
if Formal = First_Formal (E) then
Error_Msg_NE
("?in inherited operation&!", Warn_Node, E);
end if;
else
Warn_Node := Formal;
end if;
Error_Msg_NE
("?type of argument& is unconstrained array",
Warn_Node, Formal);
Error_Msg_NE
("?foreign caller must pass bounds explicitly",
Warn_Node, Formal);
Error_Msg_Qual_Level := 0;
end if;
Next_Formal (Formal);
end loop;
if Ekind (E) = E_Function then
Freeze_And_Append (Etype (E), Loc, Result);
if Warn_On_Export_Import
and then Is_Fat_C_Ptr_Type (Etype (E))
then
Error_Msg_N
("?return type of& does not correspond to C pointer",
E);
elsif Is_Array_Type (Etype (E))
and then not Is_Constrained (Etype (E))
and then not Is_Imported (E)
and then Convention (E) in Foreign_Convention
and then Warn_On_Export_Import
then
Error_Msg_N
("?foreign convention function& should not " &
"return unconstrained array", E);
end if;
end if;
end;
end if;
if Present (Alias (E)) then
Freeze_And_Append (Alias (E), Loc, Result);
end if;
if Ekind (E) = E_Function
and then Functions_Return_By_DSP_On_Target
and then Requires_Transient_Scope (Etype (E))
then
Set_Function_Returns_With_DSP (E);
end if;
if not Is_Internal (E) then
Freeze_Subprogram (E);
end if;
else
if Present (Etype (E))
and then Ekind (E) /= E_Generic_Function
then
Freeze_And_Append (Etype (E), Loc, Result);
end if;
if Nkind (Declaration_Node (E)) = N_Object_Declaration then
Validate_Object_Declaration (Declaration_Node (E));
Check_Address_Clause (E);
if Is_Imported (E)
and then not Present (Address_Clause (E))
then
Set_Is_Public (E);
end if;
end if;
if Ekind (E) = E_Constant
and then (Has_Volatile_Components (E) or else Is_Volatile (E))
and then not Is_Imported (E)
then
if Present (Get_Rep_Pragma (E, Name_Atomic))
or else
Present (Get_Rep_Pragma (E, Name_Atomic_Components))
then
Error_Msg_N
("stand alone atomic constant must be " &
"imported ('R'M 'C.6(13))", E);
elsif Present (Get_Rep_Pragma (E, Name_Volatile))
or else
Present (Get_Rep_Pragma (E, Name_Volatile_Components))
then
Error_Msg_N
("stand alone volatile constant must be " &
"imported ('R'M 'C.6(13))", E);
end if;
end if;
if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
and then Is_Statically_Allocated (E)
then
Freeze_Static_Object (E);
end if;
if Ekind (E) = E_Variable
or else
Ekind (E) = E_Constant
or else
Ekind (E) = E_Loop_Parameter
or else
Is_Formal (E)
then
Layout_Object (E);
end if;
end if;
else
if Present (Scope (E))
and then Is_Generic_Unit (Scope (E))
then
Check_Compile_Time_Size (E);
return No_List;
end if;
if E /= Base_Type (E) then
Atype := Ancestor_Subtype (E);
if Present (Atype) then
Freeze_And_Append (Atype, Loc, Result);
elsif E /= Base_Type (E) then
Freeze_And_Append (Base_Type (E), Loc, Result);
end if;
elsif Is_Derived_Type (E) then
Freeze_And_Append (Etype (E), Loc, Result);
Freeze_And_Append (First_Subtype (Etype (E)), Loc, Result);
end if;
if Is_Array_Type (E) then
declare
Ctyp : constant Entity_Id := Component_Type (E);
Pnod : Node_Id;
Non_Standard_Enum : Boolean := False;
begin
Freeze_And_Append (Ctyp, Loc, Result);
Indx := First_Index (E);
while Present (Indx) loop
Freeze_And_Append (Etype (Indx), Loc, Result);
if Is_Enumeration_Type (Etype (Indx))
and then Has_Non_Standard_Rep (Etype (Indx))
then
Non_Standard_Enum := True;
end if;
Next_Index (Indx);
end loop;
if Ekind (E) = E_Array_Type then
if Is_Controlled (Component_Type (E))
or else Has_Controlled_Component (Ctyp)
then
Set_Has_Controlled_Component (E);
end if;
if Has_Unchecked_Union (Component_Type (E)) then
Set_Has_Unchecked_Union (E);
end if;
declare
Csiz : Uint;
Esiz : Uint;
begin
if (Is_Packed (E) or else Has_Pragma_Pack (E))
and then not Has_Atomic_Components (E)
and then Known_Static_RM_Size (Ctyp)
then
Csiz := UI_Max (RM_Size (Ctyp), 1);
elsif Known_Component_Size (E) then
Csiz := Component_Size (E);
elsif not Known_Static_Esize (Ctyp) then
Csiz := Uint_0;
else
Esiz := Esize (Ctyp);
if Esiz <= 8 then
Csiz := Uint_8;
elsif Esiz <= 16 then
Csiz := Uint_16;
else
Csiz := Uint_0;
end if;
if Csiz /= 0 then
declare
A : constant Uint := Alignment_In_Bits (Ctyp);
begin
if Csiz < A then
Csiz := A;
end if;
end;
end if;
end if;
if 1 <= Csiz and then Csiz <= 64 then
Set_Component_Size (Base_Type (E), Csiz);
if Has_Pragma_Pack (E)
and then not Has_Component_Size_Clause (E)
and then
(Csiz = 7 or else Csiz = 15 or else Csiz = 31)
and then Esize (Base_Type (Ctyp)) = Csiz + 1
then
Error_Msg_Uint_1 := Csiz;
Pnod :=
Get_Rep_Pragma (First_Subtype (E), Name_Pack);
if Present (Pnod) then
Error_Msg_N
("pragma Pack causes component size to be ^?",
Pnod);
Error_Msg_N
("\use Component_Size to set desired value",
Pnod);
end if;
end if;
if Csiz = 8
or else Csiz = 16
or else Csiz = 32
or else Csiz = 64
or else (Csiz = 24 and then Alignment (Ctyp) = 1)
then
Set_Is_Packed (Base_Type (E), False);
else
Set_Has_Non_Standard_Rep (Base_Type (E));
Set_Is_Bit_Packed_Array (Base_Type (E));
Set_Is_Packed (Base_Type (E));
end if;
end if;
end;
else
if Unknown_Alignment (E) then
Set_Alignment (E, Alignment (Base_Type (E)));
end if;
end if;
if Is_Bit_Packed_Array (E)
and then Known_Esize (E)
then
declare
Discard : Boolean;
SizC : constant Node_Id := Size_Clause (E);
begin
if Present (SizC) then
Check_Size (Name (SizC), E, Esize (E), Discard);
else
Check_Size (E, E, Esize (E), Discard);
end if;
end;
end if;
declare
Lo, Hi : Node_Id;
Ctyp : constant Entity_Id := Component_Type (E);
begin
if Present (Size_Clause (E))
and then Known_Static_Esize (E)
and then not Is_Bit_Packed_Array (E)
and then not Has_Pragma_Pack (E)
and then Number_Dimensions (E) = 1
and then not Has_Component_Size_Clause (E)
and then Known_Static_Esize (Ctyp)
then
Get_Index_Bounds (First_Index (E), Lo, Hi);
if Compile_Time_Known_Value (Lo)
and then Compile_Time_Known_Value (Hi)
and then Known_Static_RM_Size (Ctyp)
and then RM_Size (Ctyp) < 64
then
declare
Lov : constant Uint := Expr_Value (Lo);
Hiv : constant Uint := Expr_Value (Hi);
Len : constant Uint :=
UI_Max (Uint_0, Hiv - Lov + 1);
Rsiz : constant Uint := RM_Size (Ctyp);
begin
if Esize (E) = Len * Rsiz
and then Rsiz mod System_Storage_Unit /= 0
then
Error_Msg_NE
("size given for& too small",
Size_Clause (E), E);
Error_Msg_N
("\explicit pragma Pack is required",
Size_Clause (E));
end if;
end;
end if;
end if;
end;
if Non_Standard_Enum then
Set_Has_Non_Standard_Rep (Base_Type (E));
Set_Is_Packed (Base_Type (E));
end if;
Set_Component_Alignment_If_Not_Set (E);
if Is_Packed (E)
and then Ekind (E) /= E_String_Literal_Subtype
then
Create_Packed_Array_Type (E);
Freeze_And_Append (Packed_Array_Type (E), Loc, Result);
Set_Size_Info (E, Packed_Array_Type (E));
Set_RM_Size (E, RM_Size (Packed_Array_Type (E)));
end if;
if not Is_Packed (E)
and then Unknown_Alignment (E)
and then Known_Alignment (Ctyp)
and then Known_Static_Component_Size (E)
and then Known_Static_Esize (Ctyp)
and then Esize (Ctyp) = Component_Size (E)
and then not Is_Atomic (E)
then
Set_Alignment (E, Alignment (Component_Type (E)));
end if;
end;
elsif Is_Class_Wide_Type (E) then
Freeze_And_Append (Root_Type (E), Loc, Result);
if Is_Itype (E)
and then Is_Compilation_Unit (Scope (E))
then
declare
Ref : constant Node_Id := Make_Itype_Reference (Loc);
begin
Set_Itype (Ref, E);
if No (Result) then
Result := New_List (Ref);
else
Append (Ref, Result);
end if;
end;
end if;
if Ekind (E) = E_Class_Wide_Subtype
and then Present (Equivalent_Type (E))
then
Freeze_And_Append (Equivalent_Type (E), Loc, Result);
end if;
elsif Ekind (E) = E_Record_Type
or else Ekind (E) = E_Record_Subtype
then
Freeze_Record_Type (E);
elsif Is_Concurrent_Type (E) then
if Present (Corresponding_Record_Type (E)) then
Freeze_And_Append
(Corresponding_Record_Type (E), Loc, Result);
end if;
Comp := First_Entity (E);
while Present (Comp) loop
if Is_Type (Comp) then
Freeze_And_Append (Comp, Loc, Result);
elsif (Ekind (Comp)) /= E_Function then
Freeze_And_Append (Etype (Comp), Loc, Result);
end if;
Next_Entity (Comp);
end loop;
elsif Is_Incomplete_Or_Private_Type (E)
and then not Is_Generic_Type (E)
then
if Present (Full_View (E)) then
if Is_Frozen (Full_View (E)) then
Set_Has_Delayed_Freeze (E, False);
Set_Freeze_Node (E, Empty);
Check_Debug_Info_Needed (E);
else
declare
Full : constant Entity_Id := Full_View (E);
begin
if Is_Private_Type (Full)
and then Present (Underlying_Full_View (Full))
then
Freeze_And_Append
(Underlying_Full_View (Full), Loc, Result);
end if;
Freeze_And_Append (Full, Loc, Result);
if Has_Delayed_Freeze (E) then
F_Node := Freeze_Node (Full);
if Present (F_Node) then
Set_Freeze_Node (E, F_Node);
Set_Entity (F_Node, E);
else
Set_Has_Delayed_Freeze (E, False);
Set_Freeze_Node (E, Empty);
end if;
end if;
end;
Check_Debug_Info_Needed (E);
end if;
Set_Convention (E, Convention (Full_View (E)));
Set_Size_Known_At_Compile_Time (E,
Size_Known_At_Compile_Time (Full_View (E)));
if Is_Type (Full_View (E)) then
Set_Size_Info (E, Full_View (E));
Set_RM_Size (E, RM_Size (Full_View (E)));
end if;
return Result;
elsif E /= Base_Type (E)
or else Is_Derived_Type (E)
then
null;
else
Set_Is_Frozen (E, False);
return No_List;
end if;
elsif Ekind (E) = E_Subprogram_Type then
Formal := First_Formal (E);
while Present (Formal) loop
Freeze_And_Append (Etype (Formal), Loc, Result);
Next_Formal (Formal);
end loop;
if Functions_Return_By_DSP_On_Target
and then Requires_Transient_Scope (Etype (E))
then
Set_Function_Returns_With_DSP (E);
end if;
Freeze_Subprogram (E);
elsif Ekind (E) = E_Access_Protected_Subprogram_Type
and then Operating_Mode = Generate_Code
and then Present (Equivalent_Type (E))
then
Freeze_And_Append (Equivalent_Type (E), Loc, Result);
end if;
if Is_Generic_Type (E) then
return Result;
end if;
if Is_Fixed_Point_Type (E) then
Freeze_Fixed_Point_Type (E);
if Is_Ordinary_Fixed_Point_Type (E)
and then E = Base_Type (E)
then
if Small_Value (E) < Ureal_2_M_80 then
Error_Msg_Name_1 := Name_Small;
Error_Msg_N
("`&''%` is too small, minimum is 2.0'*'*(-80)", E);
elsif Small_Value (E) > Ureal_2_80 then
Error_Msg_Name_1 := Name_Small;
Error_Msg_N
("`&''%` is too large, maximum is 2.0'*'*80", E);
end if;
if Expr_Value_R (Type_Low_Bound (E)) < Ureal_M_10_36 then
Error_Msg_Name_1 := Name_First;
Error_Msg_N
("`&''%` is too small, minimum is -10.0'*'*36", E);
end if;
if Expr_Value_R (Type_High_Bound (E)) > Ureal_10_36 then
Error_Msg_Name_1 := Name_Last;
Error_Msg_N
("`&''%` is too large, maximum is 10.0'*'*36", E);
end if;
end if;
elsif Is_Enumeration_Type (E) then
Freeze_Enumeration_Type (E);
elsif Is_Integer_Type (E) then
Adjust_Esize_For_Alignment (E);
elsif Is_Access_Type (E)
and then No (Associated_Storage_Pool (E))
then
Check_Restriction (No_Standard_Storage_Pools, E);
end if;
if Is_Composite_Type (E) then
if Is_Array_Type (E) then
declare
Index : Node_Id := First_Index (E);
Expr1 : Node_Id;
Expr2 : Node_Id;
begin
while Present (Index) loop
if Etype (Index) /= Any_Type then
Get_Index_Bounds (Index, Expr1, Expr2);
for J in 1 .. 2 loop
if Nkind (Expr1) = N_Identifier
and then Ekind (Entity (Expr1)) = E_Discriminant
then
Set_Has_Delayed_Freeze (E, False);
Set_Freeze_Node (E, Empty);
Check_Debug_Info_Needed (E);
return Result;
end if;
Expr1 := Expr2;
end loop;
end if;
Next_Index (Index);
end loop;
end;
elsif Has_Discriminants (E)
and Is_Constrained (E)
then
declare
Constraint : Elmt_Id;
Expr : Node_Id;
begin
Constraint := First_Elmt (Discriminant_Constraint (E));
while Present (Constraint) loop
Expr := Node (Constraint);
if Nkind (Expr) = N_Identifier
and then Ekind (Entity (Expr)) = E_Discriminant
then
Set_Has_Delayed_Freeze (E, False);
Set_Freeze_Node (E, Empty);
Check_Debug_Info_Needed (E);
return Result;
end if;
Next_Elmt (Constraint);
end loop;
end;
end if;
if Is_Tagged_Type (E)
and then not Is_Class_Wide_Type (E)
and then Convention (E) /= Convention_Ada
then
declare
Prim_List : constant Elist_Id := Primitive_Operations (E);
Prim : Elmt_Id;
begin
Prim := First_Elmt (Prim_List);
while Present (Prim) loop
if Convention (Node (Prim)) = Convention_Ada then
Set_Convention (Node (Prim), Convention (E));
end if;
Next_Elmt (Prim);
end loop;
end;
end if;
end if;
if Is_Tagged_Type (E)
and then not Is_Class_Wide_Type (E)
then
declare
Prim_List : constant Elist_Id := Primitive_Operations (E);
Prim : Elmt_Id;
Ent : Entity_Id;
begin
Prim := First_Elmt (Prim_List);
while Present (Prim) loop
Ent := Node (Prim);
while Present (Alias (Ent)) loop
Ent := Alias (Ent);
end loop;
Generate_Reference (E, Ent, 'p', Set_Ref => False);
Next_Elmt (Prim);
end loop;
exception
when others => null;
end;
end if;
Check_Compile_Time_Size (E);
Check_Unsigned_Type (E);
if Base_Type (E) = E then
Check_Strict_Alignment (E);
end if;
if Has_Size_Clause (E)
and then not Size_Known_At_Compile_Time (E)
then
if not Error_Posted (E) then
Error_Msg_N
("size clause not allowed for variable length type",
Size_Clause (E));
end if;
end if;
if Is_Generic_Type (E) then
return Result;
else
Layout_Type (E);
end if;
end if;
if Has_Delayed_Freeze (E) then
if Present (Freeze_Node (E)) then
F_Node := Freeze_Node (E);
Set_Sloc (F_Node, Loc);
else
F_Node := New_Node (N_Freeze_Entity, Loc);
Set_Freeze_Node (E, F_Node);
Set_Access_Types_To_Process (F_Node, No_Elist);
Set_TSS_Elist (F_Node, No_Elist);
Set_Actions (F_Node, No_List);
end if;
Set_Entity (F_Node, E);
if Result = No_List then
Result := New_List (F_Node);
else
Append (F_Node, Result);
end if;
if Ekind (E) = E_Record_Type
and then Has_Discriminants (E)
then
declare
Comp : Entity_Id;
IR : Node_Id;
Typ : Entity_Id;
begin
Comp := First_Component (E);
while Present (Comp) loop
Typ := Etype (Comp);
if Ekind (Comp) = E_Component
and then Is_Access_Type (Typ)
and then Scope (Typ) /= E
and then Base_Type (Designated_Type (Typ)) = E
and then Is_Itype (Designated_Type (Typ))
then
IR := Make_Itype_Reference (Sloc (Comp));
Set_Itype (IR, Designated_Type (Typ));
Append (IR, Result);
end if;
Next_Component (Comp);
end loop;
end;
end if;
end if;
if Is_Type (E) then
Freeze_And_Append (First_Subtype (E), Loc, Result);
if Is_Tagged_Type (E)
and then not Is_Class_Wide_Type (E)
and then Present (Class_Wide_Type (E))
then
Freeze_And_Append (Class_Wide_Type (E), Loc, Result);
end if;
end if;
Check_Debug_Info_Needed (E);
if Is_Subprogram (E) then
if Present (Address_Clause (E))
and then not Is_Library_Level_Entity (E)
then
Set_Is_Public (E, False);
elsif Propagate_Exceptions
and then Is_Imported (E)
and then not Is_Intrinsic_Subprogram (E)
and then Convention (E) /= Convention_Stubbed
then
if Result = No_List then
Result := Empty_List;
end if;
Generate_Subprogram_Descriptor_For_Imported_Subprogram
(E, Result);
end if;
end if;
return Result;
end Freeze_Entity;
procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
begin
if Has_Foreign_Convention (Typ)
and then not Has_Size_Clause (Typ)
and then Esize (Typ) < Standard_Integer_Size
then
Init_Esize (Typ, Standard_Integer_Size);
else
Adjust_Esize_For_Alignment (Typ);
end if;
end Freeze_Enumeration_Type;
procedure Freeze_Expression (N : Node_Id) is
In_Def_Exp : constant Boolean := In_Default_Expression;
Typ : Entity_Id;
Nam : Entity_Id;
Desig_Typ : Entity_Id;
P : Node_Id;
Parent_P : Node_Id;
Freeze_Outside : Boolean := False;
function In_Exp_Body (N : Node_Id) return Boolean;
function In_Exp_Body (N : Node_Id) return Boolean is
P : Node_Id;
begin
if Nkind (N) = N_Subprogram_Body then
P := N;
else
P := Parent (N);
end if;
if Nkind (P) /= N_Subprogram_Body then
return False;
else
P := Defining_Unit_Name (Specification (P));
if Nkind (P) = N_Defining_Identifier
and then (Is_Init_Proc (P) or else
Is_TSS (P, TSS_Stream_Input) or else
Is_TSS (P, TSS_Stream_Output) or else
Is_TSS (P, TSS_Stream_Read) or else
Is_TSS (P, TSS_Stream_Write))
then
return True;
else
return False;
end if;
end if;
end In_Exp_Body;
begin
if Must_Not_Freeze (N) then
return;
end if;
if In_Def_Exp
and then Nkind (N) in N_Subexpr
and then not Is_Static_Expression (N)
then
return;
end if;
Typ := Empty;
if Nkind (N) in N_Has_Etype then
if not Is_Frozen (Etype (N)) then
Typ := Etype (N);
elsif not Is_Frozen (First_Subtype (Etype (N))) then
Typ := First_Subtype (Etype (N));
end if;
end if;
if Is_Entity_Name (N)
and then not Is_Frozen (Entity (N))
and then (Nkind (N) /= N_Identifier
or else Comes_From_Source (N)
or else not Comes_From_Source (Entity (N)))
then
Nam := Entity (N);
else
Nam := Empty;
end if;
Desig_Typ := Empty;
case Nkind (N) is
when N_Allocator =>
Desig_Typ := Designated_Type (Etype (N));
when N_Aggregate =>
if Is_Array_Type (Etype (N))
and then Is_Access_Type (Component_Type (Etype (N)))
then
Desig_Typ := Designated_Type (Component_Type (Etype (N)));
end if;
when N_Selected_Component |
N_Indexed_Component |
N_Slice =>
if Is_Access_Type (Etype (Prefix (N))) then
Desig_Typ := Designated_Type (Etype (Prefix (N)));
end if;
when others =>
null;
end case;
if Desig_Typ /= Empty
and then (Is_Frozen (Desig_Typ)
or else (not Is_Fully_Defined (Desig_Typ)))
then
Desig_Typ := Empty;
end if;
if No (Typ)
and then No (Nam)
and then No (Desig_Typ)
then
return;
end if;
P := N;
loop
Parent_P := Parent (P);
if No (Parent_P) then
return;
end if;
case Nkind (Parent_P) is
when N_Component_Declaration =>
if not In_Default_Expression
and then Nkind (N) = N_Identifier
and then (Present (Entity (N)))
then
if Ekind (Entity (N)) = E_Discriminant then
return;
elsif Entity (N) = Current_Scope then
return;
end if;
end if;
when N_Enumeration_Representation_Clause =>
if (Nkind (N) = N_Identifier or Nkind (N) = N_Character_Literal)
and then Is_Enumeration_Type (Etype (N))
then
if Nkind (Parent (N)) = N_Component_Association
and then First (Choices (Parent (N))) = N
then
return;
elsif Nkind (Parent (N)) = N_Function_Call
and then
Nkind (Parent (Parent (N))) = N_Component_Association
and then
First (Choices (Parent (Parent (N)))) = Parent (N)
then
return;
end if;
end if;
when N_Handled_Sequence_Of_Statements =>
if In_Exp_Body (Parent_P) then
declare
Subp : constant Node_Id := Parent (Parent_P);
Cspc : Entity_Id;
begin
if Nkind (Subp) = N_Subprogram_Body then
Cspc := Corresponding_Spec (Subp);
if (Present (Typ) and then Scope (Typ) = Cspc)
or else
(Present (Nam) and then Scope (Nam) = Cspc)
then
exit;
elsif Present (Typ)
and then Scope (Typ) = Current_Scope
and then Current_Scope = Defining_Entity (Subp)
then
exit;
end if;
end if;
end;
Parent_P := Parent (Parent_P);
Freeze_Outside := True;
else
exit;
end if;
when N_Package_Specification |
N_Package_Body |
N_Subprogram_Body |
N_Task_Body |
N_Protected_Body |
N_Entry_Body |
N_Block_Statement => exit;
when N_Exception_Handler |
N_If_Statement |
N_Elsif_Part |
N_Case_Statement_Alternative |
N_Compilation_Unit_Aux |
N_Selective_Accept |
N_Accept_Alternative |
N_Delay_Alternative |
N_Conditional_Entry_Call |
N_Entry_Call_Alternative |
N_Triggering_Alternative |
N_Abortable_Part |
N_Freeze_Entity =>
exit when Is_List_Member (P);
when N_Loop_Statement =>
exit when not Comes_From_Source (Etype (N))
and then (No (Nam) or else not Comes_From_Source (Nam));
when others =>
null;
end case;
P := Parent_P;
end loop;
if (In_Def_Exp and not Inside_A_Generic)
or else Freeze_Outside
or else (Is_Type (Current_Scope)
and then (not Is_Concurrent_Type (Current_Scope)
or else not Has_Completion (Current_Scope)))
or else Ekind (Current_Scope) = E_Void
then
declare
Loc : constant Source_Ptr := Sloc (Current_Scope);
Freeze_Nodes : List_Id := No_List;
begin
if Present (Desig_Typ) then
Freeze_And_Append (Desig_Typ, Loc, Freeze_Nodes);
end if;
if Present (Typ) then
Freeze_And_Append (Typ, Loc, Freeze_Nodes);
end if;
if Present (Nam) then
Freeze_And_Append (Nam, Loc, Freeze_Nodes);
end if;
if Is_Non_Empty_List (Freeze_Nodes) then
if No (Scope_Stack.Table
(Scope_Stack.Last).Pending_Freeze_Actions)
then
Scope_Stack.Table
(Scope_Stack.Last).Pending_Freeze_Actions :=
Freeze_Nodes;
else
Append_List (Freeze_Nodes, Scope_Stack.Table
(Scope_Stack.Last).Pending_Freeze_Actions);
end if;
end if;
end;
return;
end if;
In_Default_Expression := False;
if Present (Desig_Typ) then
Freeze_Before (P, Desig_Typ);
end if;
if Present (Typ) then
Freeze_Before (P, Typ);
end if;
if Present (Nam) then
Freeze_Before (P, Nam);
end if;
In_Default_Expression := In_Def_Exp;
end Freeze_Expression;
procedure Freeze_Fixed_Point_Type (Typ : Entity_Id) is
Rng : constant Node_Id := Scalar_Range (Typ);
Lo : constant Node_Id := Low_Bound (Rng);
Hi : constant Node_Id := High_Bound (Rng);
Btyp : constant Entity_Id := Base_Type (Typ);
Brng : constant Node_Id := Scalar_Range (Btyp);
BLo : constant Node_Id := Low_Bound (Brng);
BHi : constant Node_Id := High_Bound (Brng);
Small : constant Ureal := Small_Value (Typ);
Loval : Ureal;
Hival : Ureal;
Atype : Entity_Id;
Actual_Size : Nat;
function Fsize (Lov, Hiv : Ureal) return Nat;
function Fsize (Lov, Hiv : Ureal) return Nat is
begin
Set_Realval (Lo, Lov);
Set_Realval (Hi, Hiv);
return Minimum_Size (Typ);
end Fsize;
begin
if Unknown_Esize (Typ) then
Atype := Ancestor_Subtype (Typ);
if Present (Atype) then
Set_Esize (Typ, Esize (Atype));
else
Set_Esize (Typ, Esize (Base_Type (Typ)));
end if;
end if;
if Analyzed (Rng) then
return;
end if;
if Raises_Constraint_Error (Lo)
or else Raises_Constraint_Error (Hi)
then
return;
end if;
Loval := Realval (Lo);
Hival := Realval (Hi);
if Is_Ordinary_Fixed_Point_Type (Typ) then
Fudge : declare
Loval_Incl_EP : Ureal;
Hival_Incl_EP : Ureal;
Loval_Excl_EP : Ureal;
Hival_Excl_EP : Ureal;
Size_Incl_EP : Nat;
Size_Excl_EP : Nat;
Model_Num : Ureal;
First_Subt : Entity_Id;
Actual_Lo : Ureal;
Actual_Hi : Ureal;
begin
if Typ = Btyp
and then not UR_Is_Negative (Loval)
and then Hival > Loval
then
Loval := -Hival;
Set_Realval (Lo, Loval);
end if;
Model_Num := UR_Trunc (Loval / Small) * Small;
if Loval = Model_Num then
Loval_Incl_EP := Model_Num;
else
Loval_Incl_EP := Model_Num - Small;
end if;
if UR_Is_Negative (Loval_Incl_EP) then
Loval_Excl_EP := Loval_Incl_EP + Small;
else
Loval_Excl_EP := Loval_Incl_EP;
end if;
Model_Num := UR_Trunc (Hival / Small) * Small;
if Hival = Model_Num then
Hival_Incl_EP := Model_Num;
else
Hival_Incl_EP := Model_Num + Small;
end if;
if UR_Is_Positive (Hival_Incl_EP) then
Hival_Excl_EP := Hival_Incl_EP - Small;
else
Hival_Excl_EP := Hival_Incl_EP;
end if;
if Typ /= Btyp then
Loval_Incl_EP := UR_Max (Loval_Incl_EP, Realval (BLo));
Hival_Incl_EP := UR_Min (Hival_Incl_EP, Realval (BHi));
end if;
Size_Incl_EP := Fsize (Loval_Incl_EP, Hival_Incl_EP);
Size_Excl_EP := Fsize (Loval_Excl_EP, Hival_Excl_EP);
if Fsize (Loval_Incl_EP, Hival_Excl_EP) = Size_Excl_EP then
Loval_Excl_EP := Loval_Incl_EP;
end if;
if Fsize (Loval_Excl_EP, Hival_Incl_EP) = Size_Excl_EP then
Hival_Excl_EP := Hival_Incl_EP;
end if;
if Has_Size_Clause (Typ) then
if Size_Incl_EP <= RM_Size (Typ) then
Actual_Lo := Loval_Incl_EP;
Actual_Hi := Hival_Incl_EP;
Actual_Size := Size_Incl_EP;
else
Actual_Lo := Loval_Excl_EP;
Actual_Hi := Hival_Excl_EP;
Actual_Size := Size_Excl_EP;
end if;
else
First_Subt := First_Subtype (Typ);
if Has_Size_Clause (First_Subt)
and then Size_Incl_EP <= Esize (First_Subt)
then
Actual_Size := Size_Incl_EP;
Actual_Lo := Loval_Incl_EP;
Actual_Hi := Hival_Incl_EP;
elsif Size_Incl_EP /= Size_Excl_EP
and then
(Size_Excl_EP = 8 or else
Size_Excl_EP = 16 or else
Size_Excl_EP = 32 or else
Size_Excl_EP = 64)
then
Actual_Size := Size_Excl_EP;
Actual_Lo := Loval_Excl_EP;
Actual_Hi := Hival_Excl_EP;
else
Actual_Size := Size_Incl_EP;
Actual_Lo := Loval_Incl_EP;
Actual_Hi := Hival_Incl_EP;
end if;
if Actual_Lo > Actual_Hi then
if UR_Is_Positive (Actual_Lo) then
Actual_Lo := Loval_Incl_EP - Small;
Actual_Size := Fsize (Actual_Lo, Actual_Hi);
elsif UR_Is_Negative (Actual_Hi) then
Actual_Hi := Hival_Incl_EP + Small;
Actual_Size := Fsize (Actual_Lo, Actual_Hi);
end if;
end if;
end if;
Set_Realval (Lo, Actual_Lo);
Set_Realval (Hi, Actual_Hi);
end Fudge;
else
Actual_Size := Fsize (Loval, Hival);
end if;
if Actual_Size > 64 then
Error_Msg_Uint_1 := UI_From_Int (Actual_Size);
Error_Msg_N
("size required (^) for type& too large, maximum is 64", Typ);
Actual_Size := 64;
end if;
if Has_Size_Clause (Typ) then
if Actual_Size > RM_Size (Typ) then
Error_Msg_Uint_1 := RM_Size (Typ);
Error_Msg_Uint_2 := UI_From_Int (Actual_Size);
Error_Msg_NE
("size given (^) for type& too small, minimum is ^",
Size_Clause (Typ), Typ);
else
Actual_Size := UI_To_Int (Esize (Typ));
end if;
else
if Actual_Size <= 8 then
Actual_Size := 8;
elsif Actual_Size <= 16 then
Actual_Size := 16;
elsif Actual_Size <= 32 then
Actual_Size := 32;
else
Actual_Size := 64;
end if;
Init_Esize (Typ, Actual_Size);
Adjust_Esize_For_Alignment (Typ);
end if;
if Base_Type (Typ) = Typ then
Set_Realval (Lo, -(Small * (Uint_2 ** (Actual_Size - 1))));
Set_Realval (Hi, (Small * (Uint_2 ** (Actual_Size - 1) - 1)));
end if;
Set_Etype (Lo, Empty);
Set_Analyzed (Lo, False);
Analyze (Lo);
if Typ = Btyp then
Resolve (Lo, Universal_Fixed);
else
Resolve (Lo, Btyp);
end if;
Set_Corresponding_Integer_Value
(Lo, UR_To_Uint (Realval (Lo) / Small));
Set_Etype (Hi, Empty);
Set_Analyzed (Hi, False);
Analyze (Hi);
if Typ = Btyp then
Resolve (Hi, Universal_Fixed);
else
Resolve (Hi, Btyp);
end if;
Set_Corresponding_Integer_Value
(Hi, UR_To_Uint (Realval (Hi) / Small));
Set_Etype (Rng, Etype (Lo));
if Unknown_Esize (Typ) then
Init_Esize (Typ, Actual_Size);
end if;
declare
Minsiz : constant Uint := UI_From_Int (Minimum_Size (Typ));
begin
if RM_Size (Typ) /= Uint_0 then
if RM_Size (Typ) < Minsiz then
Error_Msg_Uint_1 := RM_Size (Typ);
Error_Msg_Uint_2 := Minsiz;
Error_Msg_NE
("size given (^) for type& too small, minimum is ^",
Size_Clause (Typ), Typ);
end if;
else
Set_RM_Size (Typ, Minsiz);
end if;
end;
end Freeze_Fixed_Point_Type;
procedure Freeze_Itype (T : Entity_Id; N : Node_Id) is
L : List_Id;
begin
Set_Has_Delayed_Freeze (T);
L := Freeze_Entity (T, Sloc (N));
if Is_Non_Empty_List (L) then
Insert_Actions (N, L);
end if;
end Freeze_Itype;
procedure Freeze_Static_Object (E : Entity_Id) is
Cannot_Be_Static : exception;
procedure Ensure_Expression_Is_SA (N : Node_Id);
procedure Ensure_Type_Is_SA (Typ : Entity_Id);
procedure Ensure_Expression_Is_SA (N : Node_Id) is
Ent : Entity_Id;
begin
Ensure_Type_Is_SA (Etype (N));
if Is_Static_Expression (N) then
return;
elsif Nkind (N) = N_Identifier then
Ent := Entity (N);
if Present (Ent)
and then Ekind (Ent) = E_Constant
and then Is_Library_Level_Entity (Ent)
then
return;
end if;
end if;
raise Cannot_Be_Static;
end Ensure_Expression_Is_SA;
procedure Ensure_Type_Is_SA (Typ : Entity_Id) is
N : Node_Id;
C : Entity_Id;
begin
if Is_Library_Level_Entity (Typ) then
return;
end if;
if Is_Statically_Allocated (Typ) then
return;
end if;
Set_Is_Statically_Allocated (Typ);
if Is_Scalar_Type (Typ) or else Is_Real_Type (Typ) then
Ensure_Expression_Is_SA (Type_Low_Bound (Typ));
Ensure_Expression_Is_SA (Type_High_Bound (Typ));
elsif Is_Array_Type (Typ) then
N := First_Index (Typ);
while Present (N) loop
Ensure_Type_Is_SA (Etype (N));
Next_Index (N);
end loop;
Ensure_Type_Is_SA (Component_Type (Typ));
elsif Is_Access_Type (Typ) then
if Ekind (Designated_Type (Typ)) = E_Subprogram_Type then
declare
F : Entity_Id;
T : constant Entity_Id := Etype (Designated_Type (Typ));
begin
if T /= Standard_Void_Type then
Ensure_Type_Is_SA (T);
end if;
F := First_Formal (Designated_Type (Typ));
while Present (F) loop
Ensure_Type_Is_SA (Etype (F));
Next_Formal (F);
end loop;
end;
else
Ensure_Type_Is_SA (Designated_Type (Typ));
end if;
elsif Is_Record_Type (Typ) then
C := First_Entity (Typ);
while Present (C) loop
if Ekind (C) = E_Discriminant
or else Ekind (C) = E_Component
then
Ensure_Type_Is_SA (Etype (C));
elsif Is_Type (C) then
Ensure_Type_Is_SA (C);
end if;
Next_Entity (C);
end loop;
elsif Ekind (Typ) = E_Subprogram_Type then
Ensure_Type_Is_SA (Etype (Typ));
C := First_Formal (Typ);
while Present (C) loop
Ensure_Type_Is_SA (Etype (C));
Next_Formal (C);
end loop;
else
raise Cannot_Be_Static;
end if;
end Ensure_Type_Is_SA;
begin
Ensure_Type_Is_SA (Etype (E));
Set_Is_True_Constant (E, False);
Set_Current_Value (E, Empty);
exception
when Cannot_Be_Static =>
if Is_Imported (E) then
Error_Msg_N
("& cannot be imported (local type is not constant)", E);
else pragma Assert (Is_Exported (E));
Error_Msg_N
("& cannot be exported (local type is not constant)", E);
end if;
end Freeze_Static_Object;
procedure Freeze_Subprogram (E : Entity_Id) is
Retype : Entity_Id;
F : Entity_Id;
begin
if Present (Address_Clause (E)) then
if not Is_Imported (E) then
Error_Msg_N
("address clause can only be given " &
"for imported subprogram",
Name (Address_Clause (E)));
end if;
end if;
if Is_Imported (E)
and then Is_Pure (E)
and then not Has_Pragma_Pure_Function (E)
then
Set_Is_Pure (E, False);
end if;
if not Has_Foreign_Convention (E) then
Create_Extra_Formals (E);
Set_Mechanisms (E);
if Ekind (E) = E_Procedure
and then Is_Valued_Procedure (E)
and then Convention (E) = Convention_Ada
and then Warn_On_Export_Import
then
Error_Msg_N
("?Valued_Procedure has no effect for convention Ada", E);
Set_Is_Valued_Procedure (E, False);
end if;
else
Set_Mechanisms (E);
if Ekind (E) = E_Function then
Retype := Underlying_Type (Etype (E));
if No (Retype) then
null;
elsif Is_Generic_Type (Etype (E)) then
null;
elsif Is_Array_Type (Retype)
and then not Is_Constrained (Retype)
and then Mechanism (E) not in Descriptor_Codes
and then Warn_On_Export_Import
then
Error_Msg_N
("?foreign convention function& should not return " &
"unconstrained array", E);
return;
end if;
end if;
if Is_Exported (E) then
F := First_Formal (E);
while Present (F) loop
if Warn_On_Export_Import
and then Present (Default_Value (F))
then
Error_Msg_N
("?parameter cannot be defaulted in non-Ada call",
Default_Value (F));
end if;
Next_Formal (F);
end loop;
end if;
end if;
if OpenVMS_On_Target then
if not Is_Imported (E) then
F := First_Formal (E);
while Present (F) loop
if Mechanism (F) in Descriptor_Codes then
Error_Msg_N
("descriptor mechanism for parameter not permitted", F);
Error_Msg_N
("\can only be used for imported subprogram", F);
end if;
Next_Formal (F);
end loop;
end if;
end if;
end Freeze_Subprogram;
function Is_Fully_Defined (T : Entity_Id) return Boolean is
begin
if Ekind (T) = E_Class_Wide_Type then
return Is_Fully_Defined (Etype (T));
elsif Is_Array_Type (T) then
return Is_Fully_Defined (Component_Type (T));
elsif Is_Record_Type (T)
and not Is_Private_Type (T)
then
declare
Comp : Entity_Id;
begin
Comp := First_Component (T);
while Present (Comp) loop
if not Is_Fully_Defined (Etype (Comp)) then
return False;
end if;
Next_Component (Comp);
end loop;
return True;
end;
else return not Is_Private_Type (T)
or else Present (Full_View (Base_Type (T)));
end if;
end Is_Fully_Defined;
procedure Process_Default_Expressions
(E : Entity_Id;
After : in out Node_Id)
is
Loc : constant Source_Ptr := Sloc (E);
Dbody : Node_Id;
Formal : Node_Id;
Dcopy : Node_Id;
Dnam : Entity_Id;
begin
Set_Default_Expressions_Processed (E);
if Is_Generic_Instance (E)
and then Present (Alias (E))
and then Default_Expressions_Processed (Alias (E))
then
return;
end if;
Formal := First_Formal (E);
while Present (Formal) loop
if Present (Default_Value (Formal)) then
Dcopy := New_Copy_Tree (Default_Value (Formal));
if Nkind (Dcopy) = N_Identifier
or else Nkind (Dcopy) = N_Expanded_Name
or else Nkind (Dcopy) = N_Integer_Literal
or else (Nkind (Dcopy) = N_Real_Literal
and then not Vax_Float (Etype (Dcopy)))
or else Nkind (Dcopy) = N_Character_Literal
or else Nkind (Dcopy) = N_String_Literal
or else Nkind (Dcopy) = N_Null
or else (Nkind (Dcopy) = N_Attribute_Reference
and then
Attribute_Name (Dcopy) = Name_Null_Parameter)
then
Set_Parent (Dcopy, Declaration_Node (Formal));
Analyze (Dcopy);
if Ekind (Scope (E)) = E_Generic_Package then
Resolve (Dcopy);
else
Resolve (Dcopy, Etype (Formal));
end if;
if Raises_Constraint_Error (Dcopy) then
Set_Raises_Constraint_Error (Default_Value (Formal));
end if;
elsif Nkind (Dcopy) = N_Function_Call
and then No (Parameter_Associations (Dcopy))
then
null;
else
Dnam :=
Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
Dbody :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Dnam),
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier =>
Make_Defining_Identifier (Loc,
New_Internal_Name ('T')),
Object_Definition =>
New_Occurrence_Of (Etype (Formal), Loc),
Expression => New_Copy_Tree (Dcopy))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List));
Set_Scope (Dnam, Scope (E));
Set_Assignment_OK (First (Declarations (Dbody)));
Set_Is_Eliminated (Dnam);
Insert_After (After, Dbody);
Analyze (Dbody);
After := Dbody;
end if;
end if;
Next_Formal (Formal);
end loop;
end Process_Default_Expressions;
procedure Set_Component_Alignment_If_Not_Set (Typ : Entity_Id) is
begin
if Typ /= Base_Type (Typ) then
return;
end if;
if Is_Packed (Typ) then
return;
elsif Has_Specified_Layout (Typ) then
return;
elsif Component_Alignment (Typ) /= Calign_Default then
return;
else
Set_Component_Alignment
(Typ, Scope_Stack.Table
(Scope_Stack.Last).Component_Alignment_Default);
end if;
end Set_Component_Alignment_If_Not_Set;
procedure Set_Debug_Info_Needed (T : Entity_Id) is
begin
if No (T)
or else Needs_Debug_Info (T)
or else Debug_Info_Off (T)
then
return;
else
Set_Needs_Debug_Info (T);
end if;
if Is_Object (T) then
Set_Debug_Info_Needed (Etype (T));
elsif Is_Type (T) then
Set_Debug_Info_Needed (Etype (T));
if Is_Record_Type (T) then
declare
Ent : Entity_Id := First_Entity (T);
begin
while Present (Ent) loop
Set_Debug_Info_Needed (Ent);
Next_Entity (Ent);
end loop;
end;
elsif Is_Array_Type (T) then
Set_Debug_Info_Needed (Component_Type (T));
declare
Indx : Node_Id := First_Index (T);
begin
while Present (Indx) loop
Set_Debug_Info_Needed (Etype (Indx));
Indx := Next_Index (Indx);
end loop;
end;
if Is_Packed (T) then
Set_Debug_Info_Needed (Packed_Array_Type (T));
end if;
elsif Is_Access_Type (T) then
Set_Debug_Info_Needed (Directly_Designated_Type (T));
elsif Is_Private_Type (T) then
Set_Debug_Info_Needed (Full_View (T));
elsif Is_Protected_Type (T) then
Set_Debug_Info_Needed (Corresponding_Record_Type (T));
end if;
end if;
end Set_Debug_Info_Needed;
procedure Warn_Overlay
(Expr : Node_Id;
Typ : Entity_Id;
Nam : Entity_Id)
is
Ent : constant Entity_Id := Entity (Nam);
Init : Node_Id;
Old : Entity_Id := Empty;
Decl : Node_Id;
begin
if not Address_Clause_Overlay_Warnings then
return;
end if;
Init := Original_Node (Expression (Declaration_Node (Ent)));
if Present (Init) and then Comes_From_Source (Init) then
return;
end if;
if Present (Expr)
and then (Has_Non_Null_Base_Init_Proc (Typ)
or else Is_Access_Type (Typ))
and then not Is_Imported (Ent)
then
if Nkind (Expr) = N_Attribute_Reference
and then Is_Entity_Name (Prefix (Expr))
then
Old := Entity (Prefix (Expr));
elsif Is_Entity_Name (Expr)
and then Ekind (Entity (Expr)) = E_Constant
then
Decl := Declaration_Node (Entity (Expr));
if Nkind (Decl) = N_Object_Declaration
and then Present (Expression (Decl))
and then Nkind (Expression (Decl)) = N_Attribute_Reference
and then Is_Entity_Name (Prefix (Expression (Decl)))
then
Old := Entity (Prefix (Expression (Decl)));
elsif Nkind (Expr) = N_Function_Call then
return;
end if;
elsif Nkind (Original_Node (Expr)) = N_Function_Call then
return;
end if;
Decl := Next (Parent (Expr));
if Present (Decl)
and then Nkind (Decl) = N_Pragma
and then Chars (Decl) = Name_Import
then
return;
end if;
if Present (Old) then
Error_Msg_Node_2 := Old;
Error_Msg_N
("default initialization of & may modify &?",
Nam);
else
Error_Msg_N
("default initialization of & may modify overlaid storage?",
Nam);
end if;
if Is_Record_Type (Typ) then
declare
Comp : Entity_Id;
begin
Comp := First_Component (Typ);
while Present (Comp) loop
if Nkind (Parent (Comp)) = N_Component_Declaration
and then Present (Expression (Parent (Comp)))
then
exit;
elsif Is_Array_Type (Etype (Comp))
and then Present (Packed_Array_Type (Etype (Comp)))
then
Error_Msg_NE
("packed array component& will be initialized to zero?",
Nam, Comp);
exit;
else
Next_Component (Comp);
end if;
end loop;
end;
end if;
Error_Msg_N
("use pragma Import for & to " &
"suppress initialization ('R'M B.1(24))?",
Nam);
end if;
end Warn_Overlay;
end Freeze;