with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Exp_Aggr; use Exp_Aggr;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch11; use Exp_Ch11;
with Exp_Dbug; use Exp_Dbug;
with Exp_Pakd; use Exp_Pakd;
with Exp_Util; use Exp_Util;
with Hostparm; use Hostparm;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rtsfind; use Rtsfind;
with Sinfo; use Sinfo;
with Sem; use Sem;
with Sem_Ch8; use Sem_Ch8;
with Sem_Ch13; use Sem_Ch13;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Snames; use Snames;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Validsw; use Validsw;
package body Exp_Ch5 is
function Change_Of_Representation (N : Node_Id) return Boolean;
procedure Expand_Assign_Array (N : Node_Id; Rhs : Node_Id);
function Expand_Assign_Array_Loop
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Ndim : Pos;
Rev : Boolean)
return Node_Id;
procedure Expand_Assign_Record (N : Node_Id);
function Make_Tag_Ctrl_Assignment (N : Node_Id) return List_Id;
function Change_Of_Representation (N : Node_Id) return Boolean is
Rhs : constant Node_Id := Expression (N);
begin
return
Nkind (Rhs) = N_Type_Conversion
and then
not Same_Representation (Etype (Rhs), Etype (Expression (Rhs)));
end Change_Of_Representation;
procedure Expand_Assign_Array (N : Node_Id; Rhs : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Lhs : constant Node_Id := Name (N);
Act_Lhs : constant Node_Id := Get_Referenced_Object (Lhs);
Act_Rhs : Node_Id := Get_Referenced_Object (Rhs);
L_Type : constant Entity_Id :=
Underlying_Type (Get_Actual_Subtype (Act_Lhs));
R_Type : Entity_Id :=
Underlying_Type (Get_Actual_Subtype (Act_Rhs));
L_Slice : constant Boolean := Nkind (Act_Lhs) = N_Slice;
R_Slice : constant Boolean := Nkind (Act_Rhs) = N_Slice;
Crep : constant Boolean := Change_Of_Representation (N);
Larray : Node_Id;
Rarray : Node_Id;
Ndim : constant Pos := Number_Dimensions (L_Type);
Loop_Required : Boolean := False;
function Has_Address_Clause (Exp : Node_Id) return Boolean;
function Is_Formal_Array (Exp : Node_Id) return Boolean;
function Is_Non_Local_Array (Exp : Node_Id) return Boolean;
function Possible_Unaligned_Slice (Arg : Node_Id) return Boolean;
function Has_Address_Clause (Exp : Node_Id) return Boolean is
begin
return
(Is_Entity_Name (Exp) and then
Present (Address_Clause (Entity (Exp))))
or else
(Nkind (Exp) = N_Slice and then Has_Address_Clause (Prefix (Exp)));
end Has_Address_Clause;
function Is_Formal_Array (Exp : Node_Id) return Boolean is
begin
return
(Is_Entity_Name (Exp) and then Is_Formal (Entity (Exp)))
or else
(Nkind (Exp) = N_Slice and then Is_Formal_Array (Prefix (Exp)));
end Is_Formal_Array;
function Is_Non_Local_Array (Exp : Node_Id) return Boolean is
begin
return (Is_Entity_Name (Exp)
and then Scope (Entity (Exp)) /= Current_Scope)
or else (Nkind (Exp) = N_Slice
and then Is_Non_Local_Array (Prefix (Exp)));
end Is_Non_Local_Array;
function Possible_Unaligned_Slice (Arg : Node_Id) return Boolean is
begin
if Nkind (Arg) /= N_Slice
or else not Target_Strict_Alignment
then
return False;
end if;
declare
Array_Typ : constant Entity_Id := Etype (Arg);
Comp_Typ : constant Entity_Id := Component_Type (Array_Typ);
Pref : constant Node_Id := Prefix (Arg);
begin
if Known_Alignment (Array_Typ) then
if Alignment (Array_Typ) = 1 then
return False;
end if;
elsif Known_Component_Size (Array_Typ) then
if Component_Size (Array_Typ) = 1 then
return False;
end if;
elsif Known_Esize (Comp_Typ) then
if Esize (Comp_Typ) <= System_Storage_Unit then
return False;
end if;
end if;
if Nkind (Pref) /= N_Selected_Component then
return False;
end if;
return
Is_Packed (Etype (Pref))
or else
Present (Component_Clause (Entity (Selector_Name (Pref))));
end;
end Possible_Unaligned_Slice;
Lhs_Formal : constant Boolean := Is_Formal_Array (Act_Lhs);
Rhs_Formal : constant Boolean := Is_Formal_Array (Act_Rhs);
Lhs_Non_Local_Var : constant Boolean := Is_Non_Local_Array (Act_Lhs);
Rhs_Non_Local_Var : constant Boolean := Is_Non_Local_Array (Act_Rhs);
begin
Apply_Length_Check (Rhs, L_Type);
Set_Forwards_OK (N, True);
Set_Backwards_OK (N, True);
if Ndim = 1
and then not Crep
and then
((Lhs_Formal and Rhs_Formal)
or else
(Lhs_Formal and Rhs_Non_Local_Var)
or else
(Rhs_Formal and Lhs_Non_Local_Var))
and then not Java_VM
then
Set_Forwards_OK (N, False);
Set_Backwards_OK (N, False);
end if;
if Crep then
Act_Rhs := Get_Referenced_Object (Rhs);
R_Type := Get_Actual_Subtype (Act_Rhs);
Loop_Required := True;
elsif Has_Controlled_Component (L_Type) then
Loop_Required := True;
elsif not L_Slice and not R_Slice then
Temporary_Code : declare
function Is_Deref_Of_UBP (Opnd : Node_Id) return Boolean;
function Is_Deref_Of_UBP (Opnd : Node_Id) return Boolean is
P_Type : Entity_Id;
Des_Type : Entity_Id;
begin
if Nkind (Opnd) /= N_Explicit_Dereference then
return False;
else
P_Type := Etype (Prefix (Opnd));
if not Is_Access_Type (P_Type) then
return False;
else
Des_Type := Designated_Type (P_Type);
return
Is_Bit_Packed_Array (Des_Type)
and then not Is_Constrained (Des_Type);
end if;
end if;
end Is_Deref_Of_UBP;
begin
if Is_Deref_Of_UBP (Lhs)
or else
Is_Deref_Of_UBP (Rhs)
then
Loop_Required := True;
elsif Forwards_OK (N) then
return;
end if;
end Temporary_Code;
elsif Nkind (Rhs) = N_String_Literal then
return;
elsif Is_Bit_Packed_Array (L_Type)
or else Is_Bit_Packed_Array (R_Type)
or else Possible_Unaligned_Slice (Lhs)
or else Possible_Unaligned_Slice (Rhs)
then
Loop_Required := True;
elsif not (L_Slice and R_Slice) then
if Forwards_OK (N) then
return;
end if;
end if;
declare
L_Index_Typ : constant Node_Id := Etype (First_Index (L_Type));
R_Index_Typ : constant Node_Id := Etype (First_Index (R_Type));
Left_Lo : constant Node_Id := Type_Low_Bound (L_Index_Typ);
Left_Hi : constant Node_Id := Type_High_Bound (L_Index_Typ);
Right_Lo : constant Node_Id := Type_Low_Bound (R_Index_Typ);
Right_Hi : constant Node_Id := Type_High_Bound (R_Index_Typ);
Act_L_Array : Node_Id;
Act_R_Array : Node_Id;
Cleft_Lo : Node_Id;
Cright_Lo : Node_Id;
Condition : Node_Id;
Cresult : Compare_Result;
begin
if Nkind (Act_Lhs) = N_Slice then
Larray := Prefix (Act_Lhs);
else
Larray := Act_Lhs;
if Is_Private_Type (Etype (Larray)) then
Larray :=
Unchecked_Convert_To
(Underlying_Type (Etype (Larray)), Larray);
end if;
end if;
if Nkind (Act_Rhs) = N_Slice then
Rarray := Prefix (Act_Rhs);
else
Rarray := Act_Rhs;
if Is_Private_Type (Etype (Rarray)) then
Rarray :=
Unchecked_Convert_To
(Underlying_Type (Etype (Rarray)), Rarray);
end if;
end if;
if (not Crep) and L_Slice and R_Slice then
Act_L_Array := Get_Referenced_Object (Prefix (Act_Lhs));
Act_R_Array := Get_Referenced_Object (Prefix (Act_Rhs));
if Is_Entity_Name (Act_L_Array)
and then Is_Entity_Name (Act_R_Array)
and then Entity (Act_L_Array) /= Entity (Act_R_Array)
then
null;
else
Cresult := Compile_Time_Compare (Left_Lo, Right_Lo);
if Cresult = Unknown then
Cresult := Compile_Time_Compare (Left_Hi, Right_Hi);
end if;
case Cresult is
when LT | LE | EQ => Set_Backwards_OK (N, False);
when GT | GE => Set_Forwards_OK (N, False);
when NE | Unknown => Set_Backwards_OK (N, False);
Set_Forwards_OK (N, False);
end case;
end if;
end if;
if not Loop_Required then
if Forwards_OK (N) then
return;
else
null;
end if;
end if;
if Forwards_OK (N) or else Backwards_OK (N) then
Rewrite (N,
Expand_Assign_Array_Loop
(N, Larray, Rarray, L_Type, R_Type, Ndim,
Rev => not Forwards_OK (N)));
elsif Restrictions (No_Implicit_Conditionals) then
declare
T : Entity_Id := Make_Defining_Identifier (Loc,
Chars => Name_T);
begin
Rewrite (N,
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => T,
Constant_Present => True,
Object_Definition =>
New_Occurrence_Of (Etype (Rhs), Loc),
Expression => Relocate_Node (Rhs))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Assignment_Statement (Loc,
Name => Relocate_Node (Lhs),
Expression => New_Occurrence_Of (T, Loc))))));
end;
else
Ensure_Defined (L_Type, N);
Ensure_Defined (R_Type, N);
if not Is_Bit_Packed_Array (L_Type) and then not Java_VM then
Condition :=
Make_Op_Le (Loc,
Left_Opnd =>
Unchecked_Convert_To (RTE (RE_Integer_Address),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr (Larray, True),
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To
(L_Index_Typ, Loc),
Attribute_Name => Name_First))),
Attribute_Name => Name_Address)),
Right_Opnd =>
Unchecked_Convert_To (RTE (RE_Integer_Address),
Make_Attribute_Reference (Loc,
Prefix =>
Make_Indexed_Component (Loc,
Prefix =>
Duplicate_Subexpr (Rarray, True),
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To
(R_Index_Typ, Loc),
Attribute_Name => Name_First))),
Attribute_Name => Name_Address)));
else
Cleft_Lo := New_Copy_Tree (Left_Lo);
Cright_Lo := New_Copy_Tree (Right_Lo);
Set_Analyzed (Cleft_Lo, False);
Set_Analyzed (Cright_Lo, False);
Condition :=
Make_Op_Le (Loc,
Left_Opnd => Cleft_Lo,
Right_Opnd => Cright_Lo);
end if;
Rewrite (N,
Make_Implicit_If_Statement (N,
Condition => Condition,
Then_Statements => New_List (
Expand_Assign_Array_Loop
(N, Larray, Rarray, L_Type, R_Type, Ndim,
Rev => False)),
Else_Statements => New_List (
Expand_Assign_Array_Loop
(N, Larray, Rarray, L_Type, R_Type, Ndim,
Rev => True))));
end if;
Analyze (N, Suppress => All_Checks);
end;
end Expand_Assign_Array;
function Expand_Assign_Array_Loop
(N : Node_Id;
Larray : Entity_Id;
Rarray : Entity_Id;
L_Type : Entity_Id;
R_Type : Entity_Id;
Ndim : Pos;
Rev : Boolean)
return Node_Id
is
Loc : constant Source_Ptr := Sloc (N);
Lnn : array (1 .. Ndim) of Entity_Id;
Rnn : array (1 .. Ndim) of Entity_Id;
L_Index_Type : array (1 .. Ndim) of Entity_Id;
R_Index_Type : array (1 .. Ndim) of Entity_Id;
Assign : Node_Id;
F_Or_L : Name_Id;
S_Or_P : Name_Id;
begin
if Rev then
F_Or_L := Name_Last;
S_Or_P := Name_Pred;
else
F_Or_L := Name_First;
S_Or_P := Name_Succ;
end if;
declare
L_Index : Node_Id;
R_Index : Node_Id;
begin
L_Index := First_Index (L_Type);
R_Index := First_Index (R_Type);
for J in 1 .. Ndim loop
Lnn (J) :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('L'));
Rnn (J) :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('R'));
L_Index_Type (J) := Etype (L_Index);
R_Index_Type (J) := Etype (R_Index);
Next_Index (L_Index);
Next_Index (R_Index);
end loop;
end;
declare
ExprL : List_Id := New_List;
ExprR : List_Id := New_List;
begin
for J in 1 .. Ndim loop
Append_To (ExprL, New_Occurrence_Of (Lnn (J), Loc));
Append_To (ExprR, New_Occurrence_Of (Rnn (J), Loc));
end loop;
Assign :=
Make_Assignment_Statement (Loc,
Name =>
Make_Indexed_Component (Loc,
Prefix => Duplicate_Subexpr (Larray, Name_Req => True),
Expressions => ExprL),
Expression =>
Make_Indexed_Component (Loc,
Prefix => Duplicate_Subexpr (Rarray, Name_Req => True),
Expressions => ExprR));
Set_No_Ctrl_Actions (Assign, No_Ctrl_Actions (N));
end;
for J in reverse 1 .. Ndim loop
Assign :=
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Rnn (J),
Object_Definition =>
New_Occurrence_Of (R_Index_Type (J), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (R_Index_Type (J), Loc),
Attribute_Name => F_Or_L))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Implicit_Loop_Statement (N,
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => Lnn (J),
Reverse_Present => Rev,
Discrete_Subtype_Definition =>
New_Reference_To (L_Index_Type (J), Loc))),
Statements => New_List (
Assign,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Rnn (J), Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (R_Index_Type (J), Loc),
Attribute_Name => S_Or_P,
Expressions => New_List (
New_Occurrence_Of (Rnn (J), Loc)))))))));
end loop;
return Assign;
end Expand_Assign_Array_Loop;
procedure Expand_Assign_Record (N : Node_Id) is
begin
if not Change_Of_Representation (N) then
return;
end if;
declare
Loc : constant Source_Ptr := Sloc (N);
Lhs : constant Node_Id := Name (N);
Rhs : constant Node_Id := Expression (Expression (N));
R_Rec : constant Node_Id := Expression (Expression (N));
R_Typ : constant Entity_Id := Base_Type (Etype (R_Rec));
L_Typ : constant Entity_Id := Etype (Lhs);
Decl : constant Node_Id := Declaration_Node (R_Typ);
RDef : Node_Id;
F : Entity_Id;
function Find_Component
(Typ : Entity_Id;
Comp : Entity_Id)
return Entity_Id;
function Make_Component_List_Assign (CL : Node_Id) return List_Id;
function Make_Field_Assign (C : Entity_Id) return Node_Id;
function Make_Field_Assigns (CI : List_Id) return List_Id;
function Find_Component
(Typ : Entity_Id;
Comp : Entity_Id)
return Entity_Id
is
Utyp : constant Entity_Id := Underlying_Type (Typ);
C : Entity_Id;
begin
C := First_Entity (Utyp);
while Present (C) loop
if Chars (C) = Chars (Comp) then
return C;
end if;
Next_Entity (C);
end loop;
raise Program_Error;
end Find_Component;
function Make_Component_List_Assign (CL : Node_Id) return List_Id is
CI : constant List_Id := Component_Items (CL);
VP : constant Node_Id := Variant_Part (CL);
Result : List_Id;
Alts : List_Id;
V : Node_Id;
DC : Node_Id;
DCH : List_Id;
begin
Result := Make_Field_Assigns (CI);
if Present (VP) then
V := First_Non_Pragma (Variants (VP));
Alts := New_List;
while Present (V) loop
DCH := New_List;
DC := First (Discrete_Choices (V));
while Present (DC) loop
Append_To (DCH, New_Copy_Tree (DC));
Next (DC);
end loop;
Append_To (Alts,
Make_Case_Statement_Alternative (Loc,
Discrete_Choices => DCH,
Statements =>
Make_Component_List_Assign (Component_List (V))));
Next_Non_Pragma (V);
end loop;
Append_To (Result,
Make_Case_Statement (Loc,
Expression =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Selector_Name =>
Make_Identifier (Loc, Chars (Name (VP)))),
Alternatives => Alts));
end if;
return Result;
end Make_Component_List_Assign;
function Make_Field_Assign (C : Entity_Id) return Node_Id is
A : Node_Id;
begin
A :=
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Lhs),
Selector_Name =>
New_Occurrence_Of (Find_Component (L_Typ, C), Loc)),
Expression =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Selector_Name => New_Occurrence_Of (C, Loc)));
Set_Assignment_OK (Name (A), True);
return A;
end Make_Field_Assign;
function Make_Field_Assigns (CI : List_Id) return List_Id is
Item : Node_Id;
Result : List_Id;
begin
Item := First (CI);
Result := New_List;
while Present (Item) loop
if Nkind (Item) = N_Component_Declaration then
Append_To
(Result, Make_Field_Assign (Defining_Identifier (Item)));
end if;
Next (Item);
end loop;
return Result;
end Make_Field_Assigns;
begin
if Has_Discriminants (L_Typ) then
F := First_Discriminant (R_Typ);
while Present (F) loop
Insert_Action (N, Make_Field_Assign (F));
Next_Discriminant (F);
end loop;
end if;
if Nkind (Decl) = N_Private_Type_Declaration
and then Present (Full_View (R_Typ))
then
RDef := Type_Definition (Declaration_Node (Full_View (R_Typ)));
else
RDef := Type_Definition (Decl);
end if;
if Nkind (RDef) = N_Record_Definition
and then Present (Component_List (RDef))
then
Insert_Actions
(N, Make_Component_List_Assign (Component_List (RDef)));
Rewrite (N, Make_Null_Statement (Loc));
end if;
end;
end Expand_Assign_Record;
procedure Expand_N_Assignment_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Lhs : constant Node_Id := Name (N);
Rhs : constant Node_Id := Expression (N);
Typ : constant Entity_Id := Underlying_Type (Etype (Lhs));
Exp : Node_Id;
begin
if (Nkind (Lhs) = N_Indexed_Component
or else
Nkind (Lhs) = N_Selected_Component)
and then Is_Ref_To_Bit_Packed_Array (Prefix (Lhs))
then
declare
BPAR_Expr : constant Node_Id := Relocate_Node (Prefix (Lhs));
BPAR_Typ : constant Entity_Id := Etype (BPAR_Expr);
Tnn : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('T'));
begin
Insert_After (N,
Make_Assignment_Statement (Loc,
Name => New_Copy_Tree (BPAR_Expr),
Expression => New_Occurrence_Of (Tnn, Loc)));
Exp := BPAR_Expr;
loop
Set_Analyzed (Exp, False);
if Nkind (Exp) = N_Selected_Component
or else
Nkind (Exp) = N_Indexed_Component
then
Exp := Prefix (Exp);
else
exit;
end if;
end loop;
declare
Uses_Transient_Scope : constant Boolean :=
Scope_Is_Transient and then N = Node_To_Be_Wrapped;
begin
if Uses_Transient_Scope then
New_Scope (Scope (Current_Scope));
end if;
Insert_Before_And_Analyze (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Tnn,
Object_Definition => New_Occurrence_Of (BPAR_Typ, Loc),
Expression => BPAR_Expr));
if Uses_Transient_Scope then
Pop_Scope;
end if;
end;
Rewrite (Prefix (Lhs),
New_Occurrence_Of (Tnn, Loc));
end;
end if;
if Is_Delayed_Aggregate (Rhs) then
Convert_Aggr_In_Assignment (N);
Rewrite (N, Make_Null_Statement (Loc));
Analyze (N);
return;
end if;
if Has_Discriminants (Etype (Lhs)) then
if not Change_Of_Representation (N) then
Apply_Discriminant_Check (Rhs, Etype (Lhs), Lhs);
end if;
elsif Is_Private_Type (Etype (Lhs))
and then Has_Discriminants (Typ)
and then Nkind (Lhs) = N_Explicit_Dereference
then
declare
Lt : constant Entity_Id := Etype (Lhs);
begin
Set_Etype (Lhs, Typ);
Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
Apply_Discriminant_Check (Rhs, Typ, Lhs);
Set_Etype (Lhs, Lt);
end;
elsif Has_Unknown_Discriminants (Base_Type (Etype (Lhs)))
and then Has_Discriminants (Typ)
then
Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
Apply_Discriminant_Check (Rhs, Typ, Lhs);
elsif Is_Access_Type (Etype (Lhs))
and then Is_Constrained (Designated_Type (Etype (Lhs)))
then
if Has_Discriminants (Designated_Type (Etype (Lhs))) then
if not Change_Of_Representation (N) then
Apply_Discriminant_Check (Rhs, Etype (Lhs));
end if;
elsif Is_Array_Type (Designated_Type (Etype (Lhs))) then
Apply_Range_Check (Rhs, Etype (Lhs));
if Is_Constrained (Etype (Lhs)) then
Apply_Length_Check (Rhs, Etype (Lhs));
end if;
if Nkind (Rhs) = N_Allocator then
declare
Target_Typ : constant Entity_Id := Etype (Expression (Rhs));
C_Es : Check_Result;
begin
C_Es :=
Range_Check
(Lhs,
Target_Typ,
Etype (Designated_Type (Etype (Lhs))));
Insert_Range_Checks
(C_Es,
N,
Target_Typ,
Sloc (Lhs),
Lhs);
end;
end if;
end if;
elsif Is_Access_Type (Etype (Lhs))
and then Nkind (Rhs) = N_Allocator
and then Nkind (Expression (Rhs)) = N_Qualified_Expression
then
Analyze_And_Resolve (Expression (Rhs));
Apply_Range_Check
(Expression (Rhs), Designated_Type (Etype (Lhs)));
end if;
if Nkind (Lhs) = N_Indexed_Component
and then Is_Bit_Packed_Array (Etype (Prefix (Lhs)))
then
Expand_Bit_Packed_Element_Set (N);
return;
elsif Is_Tagged_Type (Typ)
or else (Controlled_Type (Typ) and then not Is_Array_Type (Typ))
then
Tagged_Case : declare
L : List_Id := No_List;
Expand_Ctrl_Actions : constant Boolean := not No_Ctrl_Actions (N);
begin
Remove_Side_Effects (Lhs);
Remove_Side_Effects (Rhs);
Set_Analyzed (N);
if Is_Class_Wide_Type (Typ)
or else (Is_Tagged_Type (Typ)
and then Chars (Current_Scope) /= Name_uAssign
and then Expand_Ctrl_Actions
and then not Discriminant_Checks_Suppressed (Empty))
then
declare
Op : constant Entity_Id
:= Find_Prim_Op (Typ, Name_uAssign);
F_Typ : Entity_Id := Etype (First_Formal (Op));
begin
if Is_Class_Wide_Type (Typ) then
F_Typ := Class_Wide_Type (F_Typ);
end if;
L := New_List (
Make_Procedure_Call_Statement (Loc,
Name => New_Reference_To (Op, Loc),
Parameter_Associations => New_List (
Unchecked_Convert_To (F_Typ, Duplicate_Subexpr (Lhs)),
Unchecked_Convert_To (F_Typ,
Duplicate_Subexpr (Rhs)))));
end;
else
L := Make_Tag_Ctrl_Assignment (N);
if not Statically_Different (Lhs, Rhs)
and then Expand_Ctrl_Actions
then
L := New_List (
Make_Implicit_If_Statement (N,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Lhs),
Attribute_Name => Name_Address),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Rhs),
Attribute_Name => Name_Address)),
Then_Statements => L));
end if;
if Expand_Ctrl_Actions and then not No_Run_Time then
L := New_List (
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => L,
Exception_Handlers => New_List (
Make_Exception_Handler (Loc,
Exception_Choices =>
New_List (Make_Others_Choice (Loc)),
Statements => New_List (
Make_Raise_Program_Error (Loc)))))));
end if;
end if;
Rewrite (N,
Make_Block_Statement (Loc,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc, Statements => L)));
if Controlled_Type (Typ)
and then Expand_Ctrl_Actions
and then Abort_Allowed
then
declare
Blk : constant Entity_Id :=
New_Internal_Entity (
E_Block, Current_Scope, Sloc (N), 'B');
begin
Set_Scope (Blk, Current_Scope);
Set_Etype (Blk, Standard_Void_Type);
Set_Identifier (N, New_Occurrence_Of (Blk, Sloc (N)));
Prepend_To (L, Build_Runtime_Call (Loc, RE_Abort_Defer));
Set_At_End_Proc (Handled_Statement_Sequence (N),
New_Occurrence_Of (RTE (RE_Abort_Undefer_Direct), Loc));
Expand_At_End_Handler
(Handled_Statement_Sequence (N), Blk);
end;
end if;
Analyze (N);
return;
end Tagged_Case;
elsif Is_Array_Type (Typ) then
declare
Actual_Rhs : Node_Id := Rhs;
begin
while Nkind (Actual_Rhs) = N_Type_Conversion
or else
Nkind (Actual_Rhs) = N_Qualified_Expression
loop
Actual_Rhs := Expression (Actual_Rhs);
end loop;
Expand_Assign_Array (N, Actual_Rhs);
return;
end;
elsif Is_Record_Type (Typ) then
Expand_Assign_Record (N);
return;
elsif Is_Scalar_Type (Typ) then
if Expr_Known_Valid (Rhs) then
if Is_Local_Variable_Reference (Lhs)
and then not Is_Known_Valid (Entity (Lhs))
and then In_Unconditional_Context (N)
then
Set_Is_Known_Valid (Entity (Lhs), True);
end if;
else
if Validity_Checks_On
and then Validity_Check_Copies
then
Ensure_Valid (Rhs);
if Is_Local_Variable_Reference (Lhs)
and then not Is_Known_Valid (Entity (Lhs))
and then In_Unconditional_Context (N)
then
Set_Is_Known_Valid (Entity (Lhs), True);
end if;
elsif Is_Local_Variable_Reference (Lhs) then
Set_Is_Known_Valid (Entity (Lhs), False);
elsif Is_Entity_Name (Lhs)
and then Is_Known_Valid (Entity (Lhs))
then
Ensure_Valid (Rhs);
else
null;
end if;
end if;
end if;
if Validity_Checks_On
and then Validity_Check_Default
and then not Validity_Check_Subscripts
then
Check_Valid_Lvalue_Subscripts (Lhs);
end if;
end Expand_N_Assignment_Statement;
procedure Expand_N_Block_Statement (N : Node_Id) is
begin
Qualify_Entity_Names (N);
end Expand_N_Block_Statement;
procedure Expand_N_Case_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Expr : constant Node_Id := Expression (N);
begin
if Compile_Time_Known_Value (Expr) then
declare
Val : constant Uint := Expr_Value (Expr);
Alt : Node_Id;
Choice : Node_Id;
begin
Alt := First (Alternatives (N));
Search : loop
Choice := First (Discrete_Choices (Alt));
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
exit Search;
elsif Nkind (Choice) = N_Range then
exit Search when
Val >= Expr_Value (Low_Bound (Choice))
and then
Val <= Expr_Value (High_Bound (Choice));
elsif Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice))
then
exit when Is_In_Range (Expr, Etype (Choice));
elsif Nkind (Choice) = N_Subtype_Indication then
declare
C : constant Node_Id := Constraint (Choice);
R : constant Node_Id := Range_Expression (C);
begin
exit Search when
Val >= Expr_Value (Low_Bound (R))
and then
Val <= Expr_Value (High_Bound (R));
end;
else
exit Search when Val = Expr_Value (Choice);
end if;
Next (Choice);
end loop;
Next (Alt);
pragma Assert (Present (Alt));
end loop Search;
Insert_List_After (N, Statements (Alt));
Kill_Dead_Code (Expression (N));
Kill_Dead_Code (Alternatives (N));
Rewrite (N, Make_Null_Statement (Loc));
end;
else
declare
Altnode : constant Node_Id := Last (Alternatives (N));
Others_Node : Node_Id;
begin
if Nkind (First (Discrete_Choices (Altnode)))
/= N_Others_Choice
then
Others_Node := Make_Others_Choice (Sloc (Altnode));
Set_Others_Discrete_Choices
(Others_Node, Discrete_Choices (Altnode));
Set_Discrete_Choices (Altnode, New_List (Others_Node));
end if;
if Comes_From_Source (N)
and then Validity_Checks_On
and then Validity_Check_Default
and then not Expr_Known_Valid (Expr)
then
Insert_Valid_Check (Expr);
end if;
end;
end if;
end Expand_N_Case_Statement;
procedure Expand_N_Exit_Statement (N : Node_Id) is
begin
Adjust_Condition (Condition (N));
end Expand_N_Exit_Statement;
procedure Expand_N_Goto_Statement (N : Node_Id) is
begin
Generate_Poll_Call (N);
end Expand_N_Goto_Statement;
procedure Expand_N_If_Statement (N : Node_Id) is
Hed : Node_Id;
E : Node_Id;
New_If : Node_Id;
begin
Adjust_Condition (Condition (N));
while Compile_Time_Known_Value (Condition (N)) loop
if Is_True (Expr_Value (Condition (N))) then
Kill_Dead_Code (Elsif_Parts (N));
Kill_Dead_Code (Else_Statements (N));
Hed := Remove_Head (Then_Statements (N));
Insert_List_After (N, Then_Statements (N));
Rewrite (N, Hed);
return;
else
if not Constant_Condition_Warnings then
Kill_Dead_Code (Condition (N));
end if;
Kill_Dead_Code (Then_Statements (N));
if No (Elsif_Parts (N)) then
if No (Else_Statements (N))
or else Is_Empty_List (Else_Statements (N))
then
Rewrite (N,
Make_Null_Statement (Sloc (N)));
else
Hed := Remove_Head (Else_Statements (N));
Insert_List_After (N, Else_Statements (N));
Rewrite (N, Hed);
end if;
return;
else
Hed := Remove_Head (Elsif_Parts (N));
Insert_Actions (N, Condition_Actions (Hed));
Set_Condition (N, Condition (Hed));
Set_Then_Statements (N, Then_Statements (Hed));
if Is_Empty_List (Elsif_Parts (N)) then
Set_Elsif_Parts (N, No_List);
end if;
end if;
end if;
end loop;
if Present (Elsif_Parts (N)) then
E := First (Elsif_Parts (N));
while Present (E) loop
Adjust_Condition (Condition (E));
if Present (Condition_Actions (E))
or else Compile_Time_Known_Value (Condition (E))
then
New_If :=
Make_If_Statement (Sloc (E),
Condition => Condition (E),
Then_Statements => Then_Statements (E),
Elsif_Parts => No_List,
Else_Statements => Else_Statements (N));
while Present (Next (E)) loop
if No (Elsif_Parts (New_If)) then
Set_Elsif_Parts (New_If, New_List);
end if;
Append (Remove_Next (E), Elsif_Parts (New_If));
end loop;
Set_Else_Statements (N, New_List (New_If));
if Present (Condition_Actions (E)) then
Insert_List_Before (New_If, Condition_Actions (E));
end if;
Remove (E);
if Is_Empty_List (Elsif_Parts (N)) then
Set_Elsif_Parts (N, No_List);
end if;
Analyze (New_If);
return;
else
Next (E);
end if;
end loop;
end if;
end Expand_N_If_Statement;
procedure Expand_N_Loop_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Isc : constant Node_Id := Iteration_Scheme (N);
begin
if Present (Isc) then
Adjust_Condition (Condition (Isc));
end if;
if Is_Non_Empty_List (Statements (N)) then
Generate_Poll_Call (First (Statements (N)));
end if;
if No (Isc) then
return;
end if;
if Present (Loop_Parameter_Specification (Isc)) then
declare
LPS : constant Node_Id := Loop_Parameter_Specification (Isc);
Loop_Id : constant Entity_Id := Defining_Identifier (LPS);
Ltype : constant Entity_Id := Etype (Loop_Id);
Btype : constant Entity_Id := Base_Type (Ltype);
New_Id : Entity_Id;
Lo, Hi : Node_Id;
begin
if not Is_Enumeration_Type (Btype)
or else No (Enum_Pos_To_Rep (Btype))
then
return;
end if;
New_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Loop_Id), 'P'));
Lo := Type_Low_Bound (Ltype);
Hi := Type_High_Bound (Ltype);
Rewrite (N,
Make_Loop_Statement (Loc,
Identifier => Identifier (N),
Iteration_Scheme =>
Make_Iteration_Scheme (Loc,
Loop_Parameter_Specification =>
Make_Loop_Parameter_Specification (Loc,
Defining_Identifier => New_Id,
Reverse_Present => Reverse_Present (LPS),
Discrete_Subtype_Definition =>
Make_Subtype_Indication (Loc,
Subtype_Mark =>
New_Reference_To (Standard_Natural, Loc),
Constraint =>
Make_Range_Constraint (Loc,
Range_Expression =>
Make_Range (Loc,
Low_Bound =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To (Btype, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Relocate_Node
(Type_Low_Bound (Ltype)))),
High_Bound =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To (Btype, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Relocate_Node
(Type_High_Bound (Ltype))))))))),
Statements => New_List (
Make_Block_Statement (Loc,
Declarations => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Loop_Id,
Constant_Present => True,
Object_Definition => New_Reference_To (Ltype, Loc),
Expression =>
Make_Indexed_Component (Loc,
Prefix =>
New_Reference_To (Enum_Pos_To_Rep (Btype), Loc),
Expressions => New_List (
New_Reference_To (New_Id, Loc))))),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Statements (N)))),
End_Label => End_Label (N)));
Analyze (N);
end;
elsif Present (Isc)
and then Present (Condition_Actions (Isc))
then
declare
ES : Node_Id;
begin
ES :=
Make_Exit_Statement (Sloc (Condition (Isc)),
Condition =>
Make_Op_Not (Sloc (Condition (Isc)),
Right_Opnd => Condition (Isc)));
Prepend (ES, Statements (N));
Insert_List_Before (ES, Condition_Actions (Isc));
Rewrite (N,
Make_Loop_Statement (Sloc (N),
Identifier => Identifier (N),
Statements => Statements (N),
End_Label => End_Label (N)));
Analyze (N);
end;
end if;
end Expand_N_Loop_Statement;
procedure Expand_N_Return_Statement (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Exp : constant Node_Id := Expression (N);
Exptyp : Entity_Id;
T : Entity_Id;
Utyp : Entity_Id;
Scope_Id : Entity_Id;
Kind : Entity_Kind;
Call : Node_Id;
Acc_Stat : Node_Id;
Goto_Stat : Node_Id;
Lab_Node : Node_Id;
Cur_Idx : Nat;
Return_Type : Entity_Id;
Result_Exp : Node_Id;
Result_Id : Entity_Id;
Result_Obj : Node_Id;
begin
if Present (Exp) then
Exptyp := Etype (Exp);
if Is_Boolean_Type (Exptyp)
and then Nonzero_Is_True (Exptyp)
then
Adjust_Condition (Exp);
Adjust_Result_Type (Exp, Exptyp);
end if;
if Validity_Checks_On
and then Validity_Check_Returns
then
Ensure_Valid (Exp);
end if;
end if;
Cur_Idx := Scope_Stack.Last;
loop
Scope_Id := Scope_Stack.Table (Cur_Idx).Entity;
if Ekind (Scope_Id) /= E_Block
and then Ekind (Scope_Id) /= E_Loop
then
exit;
else
Cur_Idx := Cur_Idx - 1;
pragma Assert (Cur_Idx >= 0);
end if;
end loop;
if No (Exp) then
Kind := Ekind (Scope_Id);
if Kind = E_Procedure or else Kind = E_Generic_Procedure then
return;
end if;
pragma Assert (Is_Entry (Scope_Id));
for J in reverse 0 .. Cur_Idx loop
Scope_Id := Scope_Stack.Table (J).Entity;
exit when Is_Concurrent_Type (Scope_Id);
end loop;
if Is_Task_Type (Scope_Id) then
Call := (Make_Procedure_Call_Statement (Loc,
Name => New_Reference_To
(RTE (RE_Complete_Rendezvous), Loc)));
Insert_Before (N, Call);
Analyze (Call);
Acc_Stat := Parent (N);
while Nkind (Acc_Stat) /= N_Accept_Statement loop
Acc_Stat := Parent (Acc_Stat);
end loop;
Lab_Node := Last (Statements
(Handled_Statement_Sequence (Acc_Stat)));
Goto_Stat := Make_Goto_Statement (Loc,
Name => New_Occurrence_Of
(Entity (Identifier (Lab_Node)), Loc));
Set_Analyzed (Goto_Stat);
Rewrite (N, Goto_Stat);
Analyze (N);
elsif Is_Protected_Type (Scope_Id) then
Call :=
Make_Procedure_Call_Statement (Loc,
Name => New_Reference_To
(RTE (RE_Complete_Entry_Body), Loc),
Parameter_Associations => New_List
(Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To
(Object_Ref
(Corresponding_Body (Parent (Scope_Id))),
Loc),
Attribute_Name => Name_Unchecked_Access)));
Insert_Before (N, Call);
Analyze (Call);
end if;
return;
end if;
T := Etype (Exp);
Return_Type := Etype (Scope_Id);
Utyp := Underlying_Type (Return_Type);
if Is_Scalar_Type (T) then
Rewrite (Exp, Convert_To (Return_Type, Exp));
Analyze (Exp);
end if;
if Is_Tagged_Type (Utyp)
and then not Is_Class_Wide_Type (Utyp)
and then (Nkind (Exp) = N_Type_Conversion
or else Nkind (Exp) = N_Unchecked_Type_Conversion
or else (Is_Entity_Name (Exp)
and then Ekind (Entity (Exp)) in Formal_Kind))
then
if Is_Limited_Type (Return_Type) then
Insert_Action (Exp,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Ne (Loc,
Left_Opnd =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (Exp),
Selector_Name =>
New_Reference_To (Tag_Component (Utyp), Loc)),
Right_Opnd =>
Unchecked_Convert_To (RTE (RE_Tag),
New_Reference_To
(Access_Disp_Table (Base_Type (Utyp)), Loc)))));
else
Result_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
Result_Exp := New_Reference_To (Result_Id, Loc);
Result_Obj :=
Make_Object_Declaration (Loc,
Defining_Identifier => Result_Id,
Object_Definition => New_Reference_To (Return_Type, Loc),
Constant_Present => True,
Expression => Relocate_Node (Exp));
Set_Assignment_OK (Result_Obj);
Insert_Action (Exp, Result_Obj);
Rewrite (Exp, Result_Exp);
Analyze_And_Resolve (Exp, Return_Type);
end if;
end if;
if Is_Return_By_Reference_Type (T)
or else not Requires_Transient_Scope (Return_Type)
then
null;
elsif Function_Returns_With_DSP (Scope_Id) then
No_Secondary_Stack_Case : declare
Local_Copy_Required : Boolean := False;
Copy_Ent : Entity_Id;
Decl : Node_Id;
procedure Test_Copy_Required (Expr : Node_Id);
procedure Test_Copy_Required (Expr : Node_Id) is
Ent : Entity_Id;
begin
if Nkind (Expr) = N_Indexed_Component
or else
Nkind (Expr) = N_Selected_Component
then
Test_Copy_Required (Prefix (Expr));
return;
elsif Is_Entity_Name (Expr) then
Ent := Entity (Expr);
if Ekind (Ent) = E_Constant then
return;
elsif Ekind (Ent) = E_Variable
and then Scope (Ent) = Current_Subprogram
then
return;
end if;
end if;
Local_Copy_Required := True;
end Test_Copy_Required;
begin
if Requires_Transient_Scope (T)
and then Is_Constrained (T) = Is_Constrained (Return_Type)
and then (Nkind (Exp) = N_Function_Call
or else
Nkind (Original_Node (Exp)) = N_Function_Call)
then
Set_By_Ref (N);
elsif Controlled_Type (Utyp) then
Copy_Ent :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('R'));
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Copy_Ent,
Object_Definition => New_Occurrence_Of (Return_Type, Loc),
Expression => Relocate_Node (Exp));
Set_Assignment_OK (Decl);
Set_Delay_Finalize_Attach (Decl);
Insert_Action (N, Decl);
Rewrite (Exp, New_Occurrence_Of (Copy_Ent, Loc));
Analyze_And_Resolve (Exp, Return_Type);
Set_By_Ref (N);
else
Test_Copy_Required (Exp);
if not Local_Copy_Required then
Set_By_Ref (N);
end if;
end if;
end No_Secondary_Stack_Case;
else
declare
S : Entity_Id := Current_Scope;
begin
while Ekind (S) = E_Block or else Ekind (S) = E_Loop loop
Set_Sec_Stack_Needed_For_Return (S, True);
S := Enclosing_Dynamic_Scope (S);
end loop;
end;
if Requires_Transient_Scope (T)
and then Is_Constrained (T) = Is_Constrained (Return_Type)
and then (Nkind (Exp) = N_Function_Call
or else Nkind (Original_Node (Exp)) = N_Function_Call)
then
Set_By_Ref (N);
elsif Controlled_Type (Utyp) then
declare
Loc : constant Source_Ptr := Sloc (N);
Temp : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('R'));
Acc_Typ : constant Entity_Id :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('A'));
Alloc_Node : Node_Id;
begin
Set_Ekind (Acc_Typ, E_Access_Type);
Set_Associated_Storage_Pool (Acc_Typ, RTE (RE_SS_Pool));
Alloc_Node :=
Make_Allocator (Loc,
Expression =>
Make_Qualified_Expression (Loc,
Subtype_Mark => New_Reference_To (Etype (Exp), Loc),
Expression => Relocate_Node (Exp)));
Insert_List_Before_And_Analyze (N, New_List (
Make_Full_Type_Declaration (Loc,
Defining_Identifier => Acc_Typ,
Type_Definition =>
Make_Access_To_Object_Definition (Loc,
Subtype_Indication =>
New_Reference_To (Return_Type, Loc))),
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition => New_Reference_To (Acc_Typ, Loc),
Expression => Alloc_Node)));
Rewrite (Exp,
Make_Explicit_Dereference (Loc,
Prefix => New_Reference_To (Temp, Loc)));
Analyze_And_Resolve (Exp, Return_Type);
end;
else
Set_Storage_Pool (N, RTE (RE_SS_Pool));
if not Java_VM then
Set_Procedure_To_Call (N, RTE (RE_SS_Allocate));
end if;
end if;
end if;
end Expand_N_Return_Statement;
function Make_Tag_Ctrl_Assignment (N : Node_Id) return List_Id is
Loc : constant Source_Ptr := Sloc (N);
L : constant Node_Id := Name (N);
T : constant Entity_Id := Underlying_Type (Etype (L));
Ctrl_Act : constant Boolean := Controlled_Type (T)
and then not No_Ctrl_Actions (N);
Save_Tag : constant Boolean := Is_Tagged_Type (T)
and then not No_Ctrl_Actions (N)
and then not Java_VM;
Res : List_Id;
Tag_Tmp : Entity_Id;
Prev_Tmp : Entity_Id;
Next_Tmp : Entity_Id;
Ctrl_Ref : Node_Id;
begin
Res := New_List;
if not Ctrl_Act then
null;
elsif Nkind (L) = N_Type_Conversion
and then Is_Entity_Name (Expression (L))
and then No_Initialization (Parent (Entity (Expression (L))))
then
null;
elsif Nkind (L) = N_Indexed_Component
and then Is_Entity_Name (Original_Node (Prefix (L)))
and then Is_Entry_Formal (Entity (Original_Node (Prefix (L))))
then
null;
else
Append_List_To (Res,
Make_Final_Call (
Ref => Duplicate_Subexpr (L),
Typ => Etype (L),
With_Detach => New_Reference_To (Standard_False, Loc)));
end if;
Next_Tmp := Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
if Save_Tag then
Tag_Tmp :=
Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
Append_To (Res,
Make_Object_Declaration (Loc,
Defining_Identifier => Tag_Tmp,
Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (L),
Selector_Name => New_Reference_To (Tag_Component (T), Loc))));
else
Tag_Tmp := Empty;
end if;
if Ctrl_Act then
Ctrl_Ref := Duplicate_Subexpr (L);
if Has_Controlled_Component (T) then
Ctrl_Ref :=
Make_Selected_Component (Loc,
Prefix => Ctrl_Ref,
Selector_Name =>
New_Reference_To (Controller_Component (T), Loc));
end if;
Prev_Tmp := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
Append_To (Res,
Make_Object_Declaration (Loc,
Defining_Identifier => Prev_Tmp,
Object_Definition =>
New_Reference_To (RTE (RE_Finalizable_Ptr), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Finalizable), Ctrl_Ref),
Selector_Name => Make_Identifier (Loc, Name_Prev))));
Next_Tmp := Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
Append_To (Res,
Make_Object_Declaration (Loc,
Defining_Identifier => Next_Tmp,
Object_Definition =>
New_Reference_To (RTE (RE_Finalizable_Ptr), Loc),
Expression =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Finalizable),
New_Copy_Tree (Ctrl_Ref)),
Selector_Name => Make_Identifier (Loc, Name_Next))));
else
Prev_Tmp := Empty;
Ctrl_Ref := Empty;
end if;
Append_To (Res, Relocate_Node (N));
if Save_Tag then
Append_To (Res,
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix => Duplicate_Subexpr (L),
Selector_Name => New_Reference_To (Tag_Component (T), Loc)),
Expression => New_Reference_To (Tag_Tmp, Loc)));
end if;
if Ctrl_Act then
Append_To (Res,
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Finalizable),
New_Copy_Tree (Ctrl_Ref)),
Selector_Name => Make_Identifier (Loc, Name_Prev)),
Expression => New_Reference_To (Prev_Tmp, Loc)));
Append_To (Res,
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (RTE (RE_Finalizable),
New_Copy_Tree (Ctrl_Ref)),
Selector_Name => Make_Identifier (Loc, Name_Next)),
Expression => New_Reference_To (Next_Tmp, Loc)));
end if;
if Ctrl_Act then
Append_List_To (Res,
Make_Adjust_Call (
Ref => Duplicate_Subexpr (L),
Typ => Etype (L),
Flist_Ref => New_Reference_To (RTE (RE_Global_Final_List), Loc),
With_Attach => Make_Integer_Literal (Loc, 0)));
end if;
return Res;
end Make_Tag_Ctrl_Assignment;
end Exp_Ch5;