1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package contains virtually all expansion mechanisms related to
31 with Atree; use Atree;
32 with Debug; use Debug;
33 with Einfo; use Einfo;
34 with Errout; use Errout;
35 with Exp_Ch9; use Exp_Ch9;
36 with Exp_Ch11; use Exp_Ch11;
37 with Exp_Dbug; use Exp_Dbug;
38 with Exp_Tss; use Exp_Tss;
39 with Exp_Util; use Exp_Util;
40 with Freeze; use Freeze;
41 with Hostparm; use Hostparm;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
49 with Targparm; use Targparm;
50 with Sinfo; use Sinfo;
52 with Sem_Ch3; use Sem_Ch3;
53 with Sem_Ch7; use Sem_Ch7;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Snames; use Snames;
59 with Stand; use Stand;
60 with Tbuild; use Tbuild;
61 with Uintp; use Uintp;
63 package body Exp_Ch7 is
65 --------------------------------
66 -- Transient Scope Management --
67 --------------------------------
69 -- A transient scope is created when temporary objects are created by the
70 -- compiler. These temporary objects are allocated on the secondary stack
71 -- and the transient scope is responsible for finalizing the object when
72 -- appropriate and reclaiming the memory at the right time. The temporary
73 -- objects are generally the objects allocated to store the result of a
74 -- function returning an unconstrained or a tagged value. Expressions
75 -- needing to be wrapped in a transient scope (functions calls returning
76 -- unconstrained or tagged values) may appear in 3 different contexts which
77 -- lead to 3 different kinds of transient scope expansion:
79 -- 1. In a simple statement (procedure call, assignment, ...). In
80 -- this case the instruction is wrapped into a transient block.
81 -- (See Wrap_Transient_Statement for details)
83 -- 2. In an expression of a control structure (test in a IF statement,
84 -- expression in a CASE statement, ...).
85 -- (See Wrap_Transient_Expression for details)
87 -- 3. In a expression of an object_declaration. No wrapping is possible
88 -- here, so the finalization actions, if any are done right after the
89 -- declaration and the secondary stack deallocation is done in the
90 -- proper enclosing scope (see Wrap_Transient_Declaration for details)
92 -- Note about function returning tagged types: It has been decided to
93 -- always allocate their result in the secondary stack while it is not
94 -- absolutely mandatory when the tagged type is constrained because the
95 -- caller knows the size of the returned object and thus could allocate the
96 -- result in the primary stack. But, allocating them always in the
97 -- secondary stack simplifies many implementation hassles:
99 -- - If it is dispatching function call, the computation of the size of
100 -- the result is possible but complex from the outside.
102 -- - If the returned type is controlled, the assignment of the returned
103 -- value to the anonymous object involves an Adjust, and we have no
104 -- easy way to access the anonymous object created by the back-end
106 -- - If the returned type is class-wide, this is an unconstrained type
109 -- Furthermore, the little loss in efficiency which is the result of this
110 -- decision is not such a big deal because function returning tagged types
111 -- are not very much used in real life as opposed to functions returning
112 -- access to a tagged type
114 --------------------------------------------------
115 -- Transient Blocks and Finalization Management --
116 --------------------------------------------------
118 function Find_Node_To_Be_Wrapped (N : Node_Id) return Node_Id;
119 -- N is a node wich may generate a transient scope. Loop over the
120 -- parent pointers of N until it find the appropriate node to
121 -- wrap. It it returns Empty, it means that no transient scope is
122 -- needed in this context.
131 Is_Protected_Subprogram : Boolean;
132 Is_Task_Allocation_Block : Boolean;
133 Is_Asynchronous_Call_Block : Boolean) return Node_Id;
134 -- Expand a the clean-up procedure for controlled and/or transient
135 -- block, and/or task master or task body, or blocks used to
136 -- implement task allocation or asynchronous entry calls, or
137 -- procedures used to implement protected procedures. Clean is the
138 -- entity for such a procedure. Mark is the entity for the secondary
139 -- stack mark, if empty only controlled block clean-up will be
140 -- performed. Flist is the entity for the local final list, if empty
141 -- only transient scope clean-up will be performed. The flags
142 -- Is_Task and Is_Master control the calls to the corresponding
143 -- finalization actions for a task body or for an entity that is a
146 procedure Set_Node_To_Be_Wrapped (N : Node_Id);
147 -- Set the field Node_To_Be_Wrapped of the current scope
149 procedure Insert_Actions_In_Scope_Around (N : Node_Id);
150 -- Insert the before-actions kept in the scope stack before N, and the
151 -- after after-actions, after N which must be a member of a list.
153 function Make_Transient_Block
155 Action : Node_Id) return Node_Id;
156 -- Create a transient block whose name is Scope, which is also a
157 -- controlled block if Flist is not empty and whose only code is
158 -- Action (either a single statement or single declaration).
160 type Final_Primitives is (Initialize_Case, Adjust_Case, Finalize_Case);
161 -- This enumeration type is defined in order to ease sharing code for
162 -- building finalization procedures for composite types.
164 Name_Of : constant array (Final_Primitives) of Name_Id :=
165 (Initialize_Case => Name_Initialize,
166 Adjust_Case => Name_Adjust,
167 Finalize_Case => Name_Finalize);
169 Deep_Name_Of : constant array (Final_Primitives) of TSS_Name_Type :=
170 (Initialize_Case => TSS_Deep_Initialize,
171 Adjust_Case => TSS_Deep_Adjust,
172 Finalize_Case => TSS_Deep_Finalize);
174 procedure Build_Record_Deep_Procs (Typ : Entity_Id);
175 -- Build the deep Initialize/Adjust/Finalize for a record Typ with
176 -- Has_Component_Component set and store them using the TSS mechanism.
178 procedure Build_Array_Deep_Procs (Typ : Entity_Id);
179 -- Build the deep Initialize/Adjust/Finalize for a record Typ with
180 -- Has_Controlled_Component set and store them using the TSS mechanism.
182 function Make_Deep_Proc
183 (Prim : Final_Primitives;
185 Stmts : List_Id) return Node_Id;
186 -- This function generates the tree for Deep_Initialize, Deep_Adjust
187 -- or Deep_Finalize procedures according to the first parameter,
188 -- these procedures operate on the type Typ. The Stmts parameter
189 -- gives the body of the procedure.
191 function Make_Deep_Array_Body
192 (Prim : Final_Primitives;
193 Typ : Entity_Id) return List_Id;
194 -- This function generates the list of statements for implementing
195 -- Deep_Initialize, Deep_Adjust or Deep_Finalize procedures
196 -- according to the first parameter, these procedures operate on the
199 function Make_Deep_Record_Body
200 (Prim : Final_Primitives;
201 Typ : Entity_Id) return List_Id;
202 -- This function generates the list of statements for implementing
203 -- Deep_Initialize, Deep_Adjust or Deep_Finalize procedures
204 -- according to the first parameter, these procedures operate on the
207 procedure Check_Visibly_Controlled
208 (Prim : Final_Primitives;
210 E : in out Entity_Id;
211 Cref : in out Node_Id);
212 -- The controlled operation declared for a derived type may not be
213 -- overriding, if the controlled operations of the parent type are
214 -- hidden, for example when the parent is a private type whose full
215 -- view is controlled. For other primitive operations we modify the
216 -- name of the operation to indicate that it is not overriding, but
217 -- this is not possible for Initialize, etc. because they have to be
218 -- retrievable by name. Before generating the proper call to one of
219 -- these operations we check whether Typ is known to be controlled at
220 -- the point of definition. If it is not then we must retrieve the
221 -- hidden operation of the parent and use it instead. This is one
222 -- case that might be solved more cleanly once Overriding pragmas or
223 -- declarations are in place.
225 function Convert_View
228 Ind : Pos := 1) return Node_Id;
229 -- Proc is one of the Initialize/Adjust/Finalize operations, and
230 -- Arg is the argument being passed to it. Ind indicates which
231 -- formal of procedure Proc we are trying to match. This function
232 -- will, if necessary, generate an conversion between the partial
233 -- and full view of Arg to match the type of the formal of Proc,
234 -- or force a conversion to the class-wide type in the case where
235 -- the operation is abstract.
237 -----------------------------
238 -- Finalization Management --
239 -----------------------------
241 -- This part describe how Initialization/Adjusment/Finalization procedures
242 -- are generated and called. Two cases must be considered, types that are
243 -- Controlled (Is_Controlled flag set) and composite types that contain
244 -- controlled components (Has_Controlled_Component flag set). In the first
245 -- case the procedures to call are the user-defined primitive operations
246 -- Initialize/Adjust/Finalize. In the second case, GNAT generates
247 -- Deep_Initialize, Deep_Adjust and Deep_Finalize that are in charge of
248 -- calling the former procedures on the controlled components.
250 -- For records with Has_Controlled_Component set, a hidden "controller"
251 -- component is inserted. This controller component contains its own
252 -- finalization list on which all controlled components are attached
253 -- creating an indirection on the upper-level Finalization list. This
254 -- technique facilitates the management of objects whose number of
255 -- controlled components changes during execution. This controller
256 -- component is itself controlled and is attached to the upper-level
257 -- finalization chain. Its adjust primitive is in charge of calling
258 -- adjust on the components and adusting the finalization pointer to
259 -- match their new location (see a-finali.adb).
261 -- It is not possible to use a similar technique for arrays that have
262 -- Has_Controlled_Component set. In this case, deep procedures are
263 -- generated that call initialize/adjust/finalize + attachment or
264 -- detachment on the finalization list for all component.
266 -- Initialize calls: they are generated for declarations or dynamic
267 -- allocations of Controlled objects with no initial value. They are
268 -- always followed by an attachment to the current Finalization
269 -- Chain. For the dynamic allocation case this the chain attached to
270 -- the scope of the access type definition otherwise, this is the chain
271 -- of the current scope.
273 -- Adjust Calls: They are generated on 2 occasions: (1) for
274 -- declarations or dynamic allocations of Controlled objects with an
275 -- initial value. (2) after an assignment. In the first case they are
276 -- followed by an attachment to the final chain, in the second case
279 -- Finalization Calls: They are generated on (1) scope exit, (2)
280 -- assignments, (3) unchecked deallocations. In case (3) they have to
281 -- be detached from the final chain, in case (2) they must not and in
282 -- case (1) this is not important since we are exiting the scope
286 -- - Type extensions will have a new record controller at each derivation
287 -- level containing controlled components.
288 -- - For types that are both Is_Controlled and Has_Controlled_Components,
289 -- the record controller and the object itself are handled separately.
290 -- It could seem simpler to attach the object at the end of its record
291 -- controller but this would not tackle view conversions properly.
292 -- - A classwide type can always potentially have controlled components
293 -- but the record controller of the corresponding actual type may not
294 -- be nown at compile time so the dispatch table contains a special
295 -- field that allows to compute the offset of the record controller
296 -- dynamically. See s-finimp.Deep_Tag_Attach and a-tags.RC_Offset
298 -- Here is a simple example of the expansion of a controlled block :
302 -- Y : Controlled := Init;
308 -- Z : R := (C => X);
317 -- _L : System.FI.Finalizable_Ptr;
319 -- procedure _Clean is
322 -- System.FI.Finalize_List (_L);
330 -- Attach_To_Final_List (_L, Finalizable (X), 1);
331 -- at end: Abort_Undefer;
332 -- Y : Controlled := Init;
334 -- Attach_To_Final_List (_L, Finalizable (Y), 1);
337 -- _C : Record_Controller;
343 -- Deep_Initialize (W, _L, 1);
344 -- at end: Abort_Under;
345 -- Z : R := (C => X);
346 -- Deep_Adjust (Z, _L, 1);
350 -- Deep_Finalize (W, False);
351 -- <save W's final pointers>
353 -- <restore W's final pointers>
354 -- Deep_Adjust (W, _L, 0);
359 function Global_Flist_Ref (Flist_Ref : Node_Id) return Boolean;
360 -- Return True if Flist_Ref refers to a global final list, either
361 -- the object GLobal_Final_List which is used to attach standalone
362 -- objects, or any of the list controllers associated with library
363 -- level access to controlled objects
365 procedure Clean_Simple_Protected_Objects (N : Node_Id);
366 -- Protected objects without entries are not controlled types, and the
367 -- locks have to be released explicitly when such an object goes out
368 -- of scope. Traverse declarations in scope to determine whether such
369 -- objects are present.
371 ----------------------------
372 -- Build_Array_Deep_Procs --
373 ----------------------------
375 procedure Build_Array_Deep_Procs (Typ : Entity_Id) is
379 Prim => Initialize_Case,
381 Stmts => Make_Deep_Array_Body (Initialize_Case, Typ)));
383 if not Is_Return_By_Reference_Type (Typ) then
388 Stmts => Make_Deep_Array_Body (Adjust_Case, Typ)));
393 Prim => Finalize_Case,
395 Stmts => Make_Deep_Array_Body (Finalize_Case, Typ)));
396 end Build_Array_Deep_Procs;
398 -----------------------------
399 -- Build_Controlling_Procs --
400 -----------------------------
402 procedure Build_Controlling_Procs (Typ : Entity_Id) is
404 if Is_Array_Type (Typ) then
405 Build_Array_Deep_Procs (Typ);
407 else pragma Assert (Is_Record_Type (Typ));
408 Build_Record_Deep_Procs (Typ);
410 end Build_Controlling_Procs;
412 ----------------------
413 -- Build_Final_List --
414 ----------------------
416 procedure Build_Final_List (N : Node_Id; Typ : Entity_Id) is
417 Loc : constant Source_Ptr := Sloc (N);
421 Set_Associated_Final_Chain (Typ,
422 Make_Defining_Identifier (Loc,
423 New_External_Name (Chars (Typ), 'L')));
426 Make_Object_Declaration (Loc,
427 Defining_Identifier =>
428 Associated_Final_Chain (Typ),
431 (RTE (RE_List_Controller), Loc));
433 -- The type may have been frozen already, and this is a late freezing
434 -- action, in which case the declaration must be elaborated at once.
435 -- If the call is for an allocator, the chain must also be created now,
436 -- because the freezing of the type does not build one. Otherwise, the
437 -- declaration is one of the freezing actions for a user-defined type.
440 or else (Nkind (N) = N_Allocator
441 and then Ekind (Etype (N)) = E_Anonymous_Access_Type)
443 Insert_Action (N, Decl);
445 Append_Freeze_Action (Typ, Decl);
447 end Build_Final_List;
449 ---------------------
450 -- Build_Late_Proc --
451 ---------------------
453 procedure Build_Late_Proc (Typ : Entity_Id; Nam : Name_Id) is
455 for Final_Prim in Name_Of'Range loop
456 if Name_Of (Final_Prim) = Nam then
461 Stmts => Make_Deep_Record_Body (Final_Prim, Typ)));
466 -----------------------------
467 -- Build_Record_Deep_Procs --
468 -----------------------------
470 procedure Build_Record_Deep_Procs (Typ : Entity_Id) is
474 Prim => Initialize_Case,
476 Stmts => Make_Deep_Record_Body (Initialize_Case, Typ)));
478 if not Is_Return_By_Reference_Type (Typ) then
483 Stmts => Make_Deep_Record_Body (Adjust_Case, Typ)));
488 Prim => Finalize_Case,
490 Stmts => Make_Deep_Record_Body (Finalize_Case, Typ)));
491 end Build_Record_Deep_Procs;
497 function Cleanup_Array
500 Typ : Entity_Id) return List_Id
502 Loc : constant Source_Ptr := Sloc (N);
503 Index_List : constant List_Id := New_List;
505 function Free_Component return List_Id;
506 -- Generate the code to finalize the task or protected subcomponents
507 -- of a single component of the array.
509 function Free_One_Dimension (Dim : Int) return List_Id;
510 -- Generate a loop over one dimension of the array.
516 function Free_Component return List_Id is
517 Stmts : List_Id := New_List;
519 C_Typ : constant Entity_Id := Component_Type (Typ);
522 -- Component type is known to contain tasks or protected objects
525 Make_Indexed_Component (Loc,
526 Prefix => Duplicate_Subexpr_No_Checks (Obj),
527 Expressions => Index_List);
529 Set_Etype (Tsk, C_Typ);
531 if Is_Task_Type (C_Typ) then
532 Append_To (Stmts, Cleanup_Task (N, Tsk));
534 elsif Is_Simple_Protected_Type (C_Typ) then
535 Append_To (Stmts, Cleanup_Protected_Object (N, Tsk));
537 elsif Is_Record_Type (C_Typ) then
538 Stmts := Cleanup_Record (N, Tsk, C_Typ);
540 elsif Is_Array_Type (C_Typ) then
541 Stmts := Cleanup_Array (N, Tsk, C_Typ);
547 ------------------------
548 -- Free_One_Dimension --
549 ------------------------
551 function Free_One_Dimension (Dim : Int) return List_Id is
555 if Dim > Number_Dimensions (Typ) then
556 return Free_Component;
558 -- Here we generate the required loop
562 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
564 Append (New_Reference_To (Index, Loc), Index_List);
567 Make_Implicit_Loop_Statement (N,
570 Make_Iteration_Scheme (Loc,
571 Loop_Parameter_Specification =>
572 Make_Loop_Parameter_Specification (Loc,
573 Defining_Identifier => Index,
574 Discrete_Subtype_Definition =>
575 Make_Attribute_Reference (Loc,
576 Prefix => Duplicate_Subexpr (Obj),
577 Attribute_Name => Name_Range,
578 Expressions => New_List (
579 Make_Integer_Literal (Loc, Dim))))),
580 Statements => Free_One_Dimension (Dim + 1)));
582 end Free_One_Dimension;
584 -- Start of processing for Cleanup_Array
587 return Free_One_Dimension (1);
594 function Cleanup_Record
597 Typ : Entity_Id) return List_Id
599 Loc : constant Source_Ptr := Sloc (N);
602 Stmts : constant List_Id := New_List;
603 U_Typ : constant Entity_Id := Underlying_Type (Typ);
606 if Has_Discriminants (U_Typ)
607 and then Nkind (Parent (U_Typ)) = N_Full_Type_Declaration
609 Nkind (Type_Definition (Parent (U_Typ))) = N_Record_Definition
613 (Component_List (Type_Definition (Parent (U_Typ)))))
615 -- For now, do not attempt to free a component that may appear in
616 -- a variant, and instead issue a warning. Doing this "properly"
617 -- would require building a case statement and would be quite a
618 -- mess. Note that the RM only requires that free "work" for the
619 -- case of a task access value, so already we go way beyond this
620 -- in that we deal with the array case and non-discriminated
624 ("task/protected object in variant record will not be freed?", N);
625 return New_List (Make_Null_Statement (Loc));
628 Comp := First_Component (Typ);
630 while Present (Comp) loop
631 if Has_Task (Etype (Comp))
632 or else Has_Simple_Protected_Object (Etype (Comp))
635 Make_Selected_Component (Loc,
636 Prefix => Duplicate_Subexpr_No_Checks (Obj),
637 Selector_Name => New_Occurrence_Of (Comp, Loc));
638 Set_Etype (Tsk, Etype (Comp));
640 if Is_Task_Type (Etype (Comp)) then
641 Append_To (Stmts, Cleanup_Task (N, Tsk));
643 elsif Is_Simple_Protected_Type (Etype (Comp)) then
644 Append_To (Stmts, Cleanup_Protected_Object (N, Tsk));
646 elsif Is_Record_Type (Etype (Comp)) then
648 -- Recurse, by generating the prefix of the argument to
649 -- the eventual cleanup call.
652 (Stmts, Cleanup_Record (N, Tsk, Etype (Comp)));
654 elsif Is_Array_Type (Etype (Comp)) then
656 (Stmts, Cleanup_Array (N, Tsk, Etype (Comp)));
660 Next_Component (Comp);
666 ------------------------------
667 -- Cleanup_Protected_Object --
668 ------------------------------
670 function Cleanup_Protected_Object
672 Ref : Node_Id) return Node_Id
674 Loc : constant Source_Ptr := Sloc (N);
678 Make_Procedure_Call_Statement (Loc,
679 Name => New_Reference_To (RTE (RE_Finalize_Protection), Loc),
680 Parameter_Associations => New_List (
681 Concurrent_Ref (Ref)));
682 end Cleanup_Protected_Object;
684 ------------------------------------
685 -- Clean_Simple_Protected_Objects --
686 ------------------------------------
688 procedure Clean_Simple_Protected_Objects (N : Node_Id) is
689 Stmts : constant List_Id := Statements (Handled_Statement_Sequence (N));
690 Stmt : Node_Id := Last (Stmts);
694 E := First_Entity (Current_Scope);
695 while Present (E) loop
696 if (Ekind (E) = E_Variable
697 or else Ekind (E) = E_Constant)
698 and then Has_Simple_Protected_Object (Etype (E))
699 and then not Has_Task (Etype (E))
700 and then Nkind (Parent (E)) /= N_Object_Renaming_Declaration
703 Typ : constant Entity_Id := Etype (E);
704 Ref : constant Node_Id := New_Occurrence_Of (E, Sloc (Stmt));
707 if Is_Simple_Protected_Type (Typ) then
708 Append_To (Stmts, Cleanup_Protected_Object (N, Ref));
710 elsif Has_Simple_Protected_Object (Typ) then
711 if Is_Record_Type (Typ) then
712 Append_List_To (Stmts, Cleanup_Record (N, Ref, Typ));
714 elsif Is_Array_Type (Typ) then
715 Append_List_To (Stmts, Cleanup_Array (N, Ref, Typ));
724 -- Analyze inserted cleanup statements.
726 if Present (Stmt) then
729 while Present (Stmt) loop
734 end Clean_Simple_Protected_Objects;
740 function Cleanup_Task
742 Ref : Node_Id) return Node_Id
744 Loc : constant Source_Ptr := Sloc (N);
747 Make_Procedure_Call_Statement (Loc,
748 Name => New_Reference_To (RTE (RE_Free_Task), Loc),
749 Parameter_Associations =>
750 New_List (Concurrent_Ref (Ref)));
753 ---------------------------------
754 -- Has_Simple_Protected_Object --
755 ---------------------------------
757 function Has_Simple_Protected_Object (T : Entity_Id) return Boolean is
761 if Is_Simple_Protected_Type (T) then
764 elsif Is_Array_Type (T) then
765 return Has_Simple_Protected_Object (Component_Type (T));
767 elsif Is_Record_Type (T) then
768 Comp := First_Component (T);
770 while Present (Comp) loop
771 if Has_Simple_Protected_Object (Etype (Comp)) then
775 Next_Component (Comp);
783 end Has_Simple_Protected_Object;
785 ------------------------------
786 -- Is_Simple_Protected_Type --
787 ------------------------------
789 function Is_Simple_Protected_Type (T : Entity_Id) return Boolean is
791 return Is_Protected_Type (T) and then not Has_Entries (T);
792 end Is_Simple_Protected_Type;
794 ------------------------------
795 -- Check_Visibly_Controlled --
796 ------------------------------
798 procedure Check_Visibly_Controlled
799 (Prim : Final_Primitives;
801 E : in out Entity_Id;
802 Cref : in out Node_Id)
804 Parent_Type : Entity_Id;
808 if Is_Derived_Type (Typ)
809 and then Comes_From_Source (E)
810 and then not Is_Overriding_Operation (E)
812 -- We know that the explicit operation on the type does not override
813 -- the inherited operation of the parent, and that the derivation
814 -- is from a private type that is not visibly controlled.
816 Parent_Type := Etype (Typ);
817 Op := Find_Prim_Op (Parent_Type, Name_Of (Prim));
822 -- Wrap the object to be initialized into the proper
823 -- unchecked conversion, to be compatible with the operation
826 if Nkind (Cref) = N_Unchecked_Type_Conversion then
827 Cref := Unchecked_Convert_To (Parent_Type, Expression (Cref));
829 Cref := Unchecked_Convert_To (Parent_Type, Cref);
833 end Check_Visibly_Controlled;
835 ---------------------
836 -- Controlled_Type --
837 ---------------------
839 function Controlled_Type (T : Entity_Id) return Boolean is
841 function Has_Some_Controlled_Component (Rec : Entity_Id) return Boolean;
842 -- If type is not frozen yet, check explicitly among its components,
843 -- because flag is not necessarily set.
845 -----------------------------------
846 -- Has_Some_Controlled_Component --
847 -----------------------------------
849 function Has_Some_Controlled_Component
850 (Rec : Entity_Id) return Boolean
855 if Has_Controlled_Component (Rec) then
858 elsif not Is_Frozen (Rec) then
859 if Is_Record_Type (Rec) then
860 Comp := First_Entity (Rec);
862 while Present (Comp) loop
863 if not Is_Type (Comp)
864 and then Controlled_Type (Etype (Comp))
874 elsif Is_Array_Type (Rec) then
875 return Is_Controlled (Component_Type (Rec));
878 return Has_Controlled_Component (Rec);
883 end Has_Some_Controlled_Component;
885 -- Start of processing for Controlled_Type
888 -- Class-wide types must be treated as controlled because they may
889 -- contain an extension that has controlled components
891 -- We can skip this if finalization is not available
893 return (Is_Class_Wide_Type (T)
894 and then not In_Finalization_Root (T)
895 and then not Restriction_Active (No_Finalization))
896 or else Is_Controlled (T)
897 or else Has_Some_Controlled_Component (T)
898 or else (Is_Concurrent_Type (T)
899 and then Present (Corresponding_Record_Type (T))
900 and then Controlled_Type (Corresponding_Record_Type (T)));
903 --------------------------
904 -- Controller_Component --
905 --------------------------
907 function Controller_Component (Typ : Entity_Id) return Entity_Id is
908 T : Entity_Id := Base_Type (Typ);
910 Comp_Scop : Entity_Id;
911 Res : Entity_Id := Empty;
912 Res_Scop : Entity_Id := Empty;
915 if Is_Class_Wide_Type (T) then
919 if Is_Private_Type (T) then
920 T := Underlying_Type (T);
923 -- Fetch the outermost controller
925 Comp := First_Entity (T);
926 while Present (Comp) loop
927 if Chars (Comp) = Name_uController then
928 Comp_Scop := Scope (Original_Record_Component (Comp));
930 -- If this controller is at the outermost level, no need to
931 -- look for another one
933 if Comp_Scop = T then
936 -- Otherwise record the outermost one and continue looking
938 elsif Res = Empty or else Is_Ancestor (Res_Scop, Comp_Scop) then
940 Res_Scop := Comp_Scop;
947 -- If we fall through the loop, there is no controller component
950 end Controller_Component;
956 function Convert_View
959 Ind : Pos := 1) return Node_Id
961 Fent : Entity_Id := First_Entity (Proc);
966 for J in 2 .. Ind loop
970 Ftyp := Etype (Fent);
972 if Nkind (Arg) = N_Type_Conversion
973 or else Nkind (Arg) = N_Unchecked_Type_Conversion
975 Atyp := Entity (Subtype_Mark (Arg));
980 if Is_Abstract (Proc) and then Is_Tagged_Type (Ftyp) then
981 return Unchecked_Convert_To (Class_Wide_Type (Ftyp), Arg);
984 and then Present (Atyp)
986 (Is_Private_Type (Ftyp) or else Is_Private_Type (Atyp))
987 and then Underlying_Type (Atyp) = Underlying_Type (Ftyp)
989 return Unchecked_Convert_To (Ftyp, Arg);
991 -- If the argument is already a conversion, as generated by
992 -- Make_Init_Call, set the target type to the type of the formal
993 -- directly, to avoid spurious typing problems.
995 elsif (Nkind (Arg) = N_Unchecked_Type_Conversion
996 or else Nkind (Arg) = N_Type_Conversion)
997 and then not Is_Class_Wide_Type (Atyp)
999 Set_Subtype_Mark (Arg, New_Occurrence_Of (Ftyp, Sloc (Arg)));
1000 Set_Etype (Arg, Ftyp);
1008 -------------------------------
1009 -- Establish_Transient_Scope --
1010 -------------------------------
1012 -- This procedure is called each time a transient block has to be inserted
1013 -- that is to say for each call to a function with unconstrained ot tagged
1014 -- result. It creates a new scope on the stack scope in order to enclose
1015 -- all transient variables generated
1017 procedure Establish_Transient_Scope (N : Node_Id; Sec_Stack : Boolean) is
1018 Loc : constant Source_Ptr := Sloc (N);
1019 Wrap_Node : Node_Id;
1021 Sec_Stk : constant Boolean :=
1022 Sec_Stack and not Functions_Return_By_DSP_On_Target;
1023 -- We never need a secondary stack if functions return by DSP
1026 -- Do not create a transient scope if we are already inside one
1028 for S in reverse Scope_Stack.First .. Scope_Stack.Last loop
1030 if Scope_Stack.Table (S).Is_Transient then
1032 Set_Uses_Sec_Stack (Scope_Stack.Table (S).Entity);
1037 -- If we have encountered Standard there are no enclosing
1038 -- transient scopes.
1040 elsif Scope_Stack.Table (S).Entity = Standard_Standard then
1046 Wrap_Node := Find_Node_To_Be_Wrapped (N);
1048 -- Case of no wrap node, false alert, no transient scope needed
1050 if No (Wrap_Node) then
1053 elsif Nkind (Wrap_Node) = N_Iteration_Scheme then
1055 -- Create a declaration followed by an assignment, so that
1056 -- the assignment can have its own transient scope.
1057 -- We generate the equivalent of:
1059 -- type Ptr is access all expr_type;
1062 -- Var := Expr'reference;
1065 -- This closely resembles what is done in Remove_Side_Effect,
1066 -- but it has to be done here, before the analysis of the call
1070 Ptr_Typ : constant Entity_Id :=
1071 Make_Defining_Identifier (Loc,
1072 Chars => New_Internal_Name ('A'));
1073 Ptr : constant Entity_Id :=
1074 Make_Defining_Identifier (Loc,
1075 Chars => New_Internal_Name ('T'));
1077 Expr_Type : constant Entity_Id := Etype (N);
1078 New_Expr : constant Node_Id := Relocate_Node (N);
1080 Ptr_Typ_Decl : Node_Id;
1085 Make_Full_Type_Declaration (Loc,
1086 Defining_Identifier => Ptr_Typ,
1088 Make_Access_To_Object_Definition (Loc,
1089 All_Present => True,
1090 Subtype_Indication =>
1091 New_Reference_To (Expr_Type, Loc)));
1094 Make_Object_Declaration (Loc,
1095 Defining_Identifier => Ptr,
1096 Object_Definition => New_Occurrence_Of (Ptr_Typ, Loc));
1098 Set_Etype (Ptr, Ptr_Typ);
1100 Make_Assignment_Statement (Loc,
1101 Name => New_Occurrence_Of (Ptr, Loc),
1102 Expression => Make_Reference (Loc, New_Expr));
1104 Set_Analyzed (New_Expr, False);
1106 Insert_List_Before_And_Analyze
1107 (Parent (Wrap_Node),
1111 Make_Block_Statement (Loc,
1112 Handled_Statement_Sequence =>
1113 Make_Handled_Sequence_Of_Statements (Loc,
1114 New_List (Stmt)))));
1117 Make_Explicit_Dereference (Loc,
1118 Prefix => New_Reference_To (Ptr, Loc)));
1119 Analyze_And_Resolve (N, Expr_Type);
1123 -- Transient scope is required
1126 New_Scope (New_Internal_Entity (E_Block, Current_Scope, Loc, 'B'));
1127 Set_Scope_Is_Transient;
1130 Set_Uses_Sec_Stack (Current_Scope);
1131 Check_Restriction (No_Secondary_Stack, N);
1134 Set_Etype (Current_Scope, Standard_Void_Type);
1135 Set_Node_To_Be_Wrapped (Wrap_Node);
1137 if Debug_Flag_W then
1138 Write_Str (" <Transient>");
1142 end Establish_Transient_Scope;
1144 ----------------------------
1145 -- Expand_Cleanup_Actions --
1146 ----------------------------
1148 procedure Expand_Cleanup_Actions (N : Node_Id) is
1150 S : constant Entity_Id :=
1152 Flist : constant Entity_Id :=
1153 Finalization_Chain_Entity (S);
1154 Is_Task : constant Boolean :=
1155 (Nkind (Original_Node (N)) = N_Task_Body);
1156 Is_Master : constant Boolean :=
1157 Nkind (N) /= N_Entry_Body
1158 and then Is_Task_Master (N);
1159 Is_Protected : constant Boolean :=
1160 Nkind (N) = N_Subprogram_Body
1161 and then Is_Protected_Subprogram_Body (N);
1162 Is_Task_Allocation : constant Boolean :=
1163 Nkind (N) = N_Block_Statement
1164 and then Is_Task_Allocation_Block (N);
1165 Is_Asynchronous_Call : constant Boolean :=
1166 Nkind (N) = N_Block_Statement
1167 and then Is_Asynchronous_Call_Block (N);
1170 Mark : Entity_Id := Empty;
1171 New_Decls : constant List_Id := New_List;
1174 Chain : Entity_Id := Empty;
1180 -- Compute a location that is not directly in the user code in
1181 -- order to avoid to generate confusing debug info. A good
1182 -- approximation is the name of the outer user-defined scope
1185 S1 : Entity_Id := S;
1188 while not Comes_From_Source (S1) and then S1 /= Standard_Standard loop
1195 -- There are cleanup actions only if the secondary stack needs
1196 -- releasing or some finalizations are needed or in the context
1199 if Uses_Sec_Stack (Current_Scope)
1200 and then not Sec_Stack_Needed_For_Return (Current_Scope)
1204 and then not Is_Master
1205 and then not Is_Task
1206 and then not Is_Protected
1207 and then not Is_Task_Allocation
1208 and then not Is_Asynchronous_Call
1210 Clean_Simple_Protected_Objects (N);
1214 -- If the current scope is the subprogram body that is the rewriting
1215 -- of a task body, and the descriptors have not been delayed (due to
1216 -- some nested instantiations) do not generate redundant cleanup
1217 -- actions: the cleanup procedure already exists for this body.
1219 if Nkind (N) = N_Subprogram_Body
1220 and then Nkind (Original_Node (N)) = N_Task_Body
1221 and then not Delay_Subprogram_Descriptors (Corresponding_Spec (N))
1226 -- Set polling off, since we don't need to poll during cleanup
1227 -- actions, and indeed for the cleanup routine, which is executed
1228 -- with aborts deferred, we don't want polling.
1230 Old_Poll := Polling_Required;
1231 Polling_Required := False;
1233 -- Make sure we have a declaration list, since we will add to it
1235 if No (Declarations (N)) then
1236 Set_Declarations (N, New_List);
1239 -- The task activation call has already been built for task
1240 -- allocation blocks.
1242 if not Is_Task_Allocation then
1243 Build_Task_Activation_Call (N);
1247 Establish_Task_Master (N);
1250 -- If secondary stack is in use, expand:
1251 -- _Mxx : constant Mark_Id := SS_Mark;
1253 -- Suppress calls to SS_Mark and SS_Release if Java_VM,
1254 -- since we never use the secondary stack on the JVM.
1256 if Uses_Sec_Stack (Current_Scope)
1257 and then not Sec_Stack_Needed_For_Return (Current_Scope)
1258 and then not Java_VM
1260 Mark := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
1261 Append_To (New_Decls,
1262 Make_Object_Declaration (Loc,
1263 Defining_Identifier => Mark,
1264 Object_Definition => New_Reference_To (RTE (RE_Mark_Id), Loc),
1266 Make_Function_Call (Loc,
1267 Name => New_Reference_To (RTE (RE_SS_Mark), Loc))));
1269 Set_Uses_Sec_Stack (Current_Scope, False);
1272 -- If finalization list is present then expand:
1273 -- Local_Final_List : System.FI.Finalizable_Ptr;
1275 if Present (Flist) then
1276 Append_To (New_Decls,
1277 Make_Object_Declaration (Loc,
1278 Defining_Identifier => Flist,
1279 Object_Definition =>
1280 New_Reference_To (RTE (RE_Finalizable_Ptr), Loc)));
1283 -- Clean-up procedure definition
1285 Clean := Make_Defining_Identifier (Loc, Name_uClean);
1286 Set_Suppress_Elaboration_Warnings (Clean);
1287 Append_To (New_Decls,
1288 Make_Clean (N, Clean, Mark, Flist,
1293 Is_Asynchronous_Call));
1295 -- If exception handlers are present, wrap the Sequence of
1296 -- statements in a block because it is not possible to get
1297 -- exception handlers and an AT END call in the same scope.
1299 if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
1301 Make_Block_Statement (Loc,
1302 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
1303 Set_Handled_Statement_Sequence (N,
1304 Make_Handled_Sequence_Of_Statements (Loc, New_List (Blok)));
1307 -- Otherwise we do not wrap
1314 -- Don't move the _chain Activation_Chain declaration in task
1315 -- allocation blocks. Task allocation blocks use this object
1316 -- in their cleanup handlers, and gigi complains if it is declared
1317 -- in the sequence of statements of the scope that declares the
1320 if Is_Task_Allocation then
1321 Chain := Activation_Chain_Entity (N);
1322 Decl := First (Declarations (N));
1324 while Nkind (Decl) /= N_Object_Declaration
1325 or else Defining_Identifier (Decl) /= Chain
1328 pragma Assert (Present (Decl));
1332 Prepend_To (New_Decls, Decl);
1335 -- Now we move the declarations into the Sequence of statements
1336 -- in order to get them protected by the AT END call. It may seem
1337 -- weird to put declarations in the sequence of statement but in
1338 -- fact nothing forbids that at the tree level. We also set the
1339 -- First_Real_Statement field so that we remember where the real
1340 -- statements (i.e. original statements) begin. Note that if we
1341 -- wrapped the statements, the first real statement is inside the
1342 -- inner block. If the First_Real_Statement is already set (as is
1343 -- the case for subprogram bodies that are expansions of task bodies)
1344 -- then do not reset it, because its declarative part would migrate
1345 -- to the statement part.
1348 if No (First_Real_Statement (Handled_Statement_Sequence (N))) then
1349 Set_First_Real_Statement (Handled_Statement_Sequence (N),
1350 First (Statements (Handled_Statement_Sequence (N))));
1354 Set_First_Real_Statement (Handled_Statement_Sequence (N), Blok);
1357 Append_List_To (Declarations (N),
1358 Statements (Handled_Statement_Sequence (N)));
1359 Set_Statements (Handled_Statement_Sequence (N), Declarations (N));
1361 -- We need to reset the Sloc of the handled statement sequence to
1362 -- properly reflect the new initial "statement" in the sequence.
1365 (Handled_Statement_Sequence (N), Sloc (First (Declarations (N))));
1367 -- The declarations of the _Clean procedure and finalization chain
1368 -- replace the old declarations that have been moved inward
1370 Set_Declarations (N, New_Decls);
1371 Analyze_Declarations (New_Decls);
1373 -- The At_End call is attached to the sequence of statements.
1379 -- If the construct is a protected subprogram, then the call to
1380 -- the corresponding unprotected program appears in a block which
1381 -- is the last statement in the body, and it is this block that
1382 -- must be covered by the At_End handler.
1384 if Is_Protected then
1385 HSS := Handled_Statement_Sequence
1386 (Last (Statements (Handled_Statement_Sequence (N))));
1388 HSS := Handled_Statement_Sequence (N);
1391 Set_At_End_Proc (HSS, New_Occurrence_Of (Clean, Loc));
1392 Expand_At_End_Handler (HSS, Empty);
1395 -- Restore saved polling mode
1397 Polling_Required := Old_Poll;
1398 end Expand_Cleanup_Actions;
1400 -------------------------------
1401 -- Expand_Ctrl_Function_Call --
1402 -------------------------------
1404 procedure Expand_Ctrl_Function_Call (N : Node_Id) is
1405 Loc : constant Source_Ptr := Sloc (N);
1406 Rtype : constant Entity_Id := Etype (N);
1407 Utype : constant Entity_Id := Underlying_Type (Rtype);
1410 Action2 : Node_Id := Empty;
1412 Attach_Level : Uint := Uint_1;
1413 Len_Ref : Node_Id := Empty;
1415 function Last_Array_Component
1417 Typ : Entity_Id) return Node_Id;
1418 -- Creates a reference to the last component of the array object
1419 -- designated by Ref whose type is Typ.
1421 --------------------------
1422 -- Last_Array_Component --
1423 --------------------------
1425 function Last_Array_Component
1427 Typ : Entity_Id) return Node_Id
1429 Index_List : constant List_Id := New_List;
1432 for N in 1 .. Number_Dimensions (Typ) loop
1433 Append_To (Index_List,
1434 Make_Attribute_Reference (Loc,
1435 Prefix => Duplicate_Subexpr_No_Checks (Ref),
1436 Attribute_Name => Name_Last,
1437 Expressions => New_List (
1438 Make_Integer_Literal (Loc, N))));
1442 Make_Indexed_Component (Loc,
1443 Prefix => Duplicate_Subexpr (Ref),
1444 Expressions => Index_List);
1445 end Last_Array_Component;
1447 -- Start of processing for Expand_Ctrl_Function_Call
1450 -- Optimization, if the returned value (which is on the sec-stack)
1451 -- is returned again, no need to copy/readjust/finalize, we can just
1452 -- pass the value thru (see Expand_N_Return_Statement), and thus no
1453 -- attachment is needed
1455 if Nkind (Parent (N)) = N_Return_Statement then
1459 -- Resolution is now finished, make sure we don't start analysis again
1460 -- because of the duplication
1463 Ref := Duplicate_Subexpr_No_Checks (N);
1465 -- Now we can generate the Attach Call, note that this value is
1466 -- always in the (secondary) stack and thus is attached to a singly
1467 -- linked final list:
1469 -- Resx := F (X)'reference;
1470 -- Attach_To_Final_List (_Lx, Resx.all, 1);
1472 -- or when there are controlled components
1474 -- Attach_To_Final_List (_Lx, Resx._controller, 1);
1476 -- or when it is both is_controlled and has_controlled_components
1478 -- Attach_To_Final_List (_Lx, Resx._controller, 1);
1479 -- Attach_To_Final_List (_Lx, Resx, 1);
1481 -- or if it is an array with is_controlled (and has_controlled)
1483 -- Attach_To_Final_List (_Lx, Resx (Resx'last), 3);
1484 -- An attach level of 3 means that a whole array is to be
1485 -- attached to the finalization list (including the controlled
1488 -- or if it is an array with has_controlled components but not
1491 -- Attach_To_Final_List (_Lx, Resx (Resx'last)._controller, 3);
1493 if Has_Controlled_Component (Rtype) then
1495 T1 : Entity_Id := Rtype;
1496 T2 : Entity_Id := Utype;
1499 if Is_Array_Type (T2) then
1501 Make_Attribute_Reference (Loc,
1503 Duplicate_Subexpr_Move_Checks
1504 (Unchecked_Convert_To (T2, Ref)),
1505 Attribute_Name => Name_Length);
1508 while Is_Array_Type (T2) loop
1510 Ref := Unchecked_Convert_To (T2, Ref);
1513 Ref := Last_Array_Component (Ref, T2);
1514 Attach_Level := Uint_3;
1515 T1 := Component_Type (T2);
1516 T2 := Underlying_Type (T1);
1519 -- If the type has controlled components, go to the controller
1520 -- except in the case of arrays of controlled objects since in
1521 -- this case objects and their components are already chained
1522 -- and the head of the chain is the last array element.
1524 if Is_Array_Type (Rtype) and then Is_Controlled (T2) then
1527 elsif Has_Controlled_Component (T2) then
1529 Ref := Unchecked_Convert_To (T2, Ref);
1533 Make_Selected_Component (Loc,
1535 Selector_Name => Make_Identifier (Loc, Name_uController));
1539 -- Here we know that 'Ref' has a controller so we may as well
1540 -- attach it directly
1545 Flist_Ref => Find_Final_List (Current_Scope),
1546 With_Attach => Make_Integer_Literal (Loc, Attach_Level));
1548 -- If it is also Is_Controlled we need to attach the global object
1550 if Is_Controlled (Rtype) then
1553 Obj_Ref => Duplicate_Subexpr_No_Checks (N),
1554 Flist_Ref => Find_Final_List (Current_Scope),
1555 With_Attach => Make_Integer_Literal (Loc, Attach_Level));
1559 -- Here, we have a controlled type that does not seem to have
1560 -- controlled components but it could be a class wide type whose
1561 -- further derivations have controlled components. So we don't know
1562 -- if the object itself needs to be attached or if it
1563 -- has a record controller. We need to call a runtime function
1564 -- (Deep_Tag_Attach) which knows what to do thanks to the
1565 -- RC_Offset in the dispatch table.
1568 Make_Procedure_Call_Statement (Loc,
1569 Name => New_Reference_To (RTE (RE_Deep_Tag_Attach), Loc),
1570 Parameter_Associations => New_List (
1571 Find_Final_List (Current_Scope),
1573 Make_Attribute_Reference (Loc,
1575 Attribute_Name => Name_Address),
1577 Make_Integer_Literal (Loc, Attach_Level)));
1580 if Present (Len_Ref) then
1582 Make_Implicit_If_Statement (N,
1583 Condition => Make_Op_Gt (Loc,
1584 Left_Opnd => Len_Ref,
1585 Right_Opnd => Make_Integer_Literal (Loc, 0)),
1586 Then_Statements => New_List (Action));
1589 Insert_Action (N, Action);
1590 if Present (Action2) then
1591 Insert_Action (N, Action2);
1593 end Expand_Ctrl_Function_Call;
1595 ---------------------------
1596 -- Expand_N_Package_Body --
1597 ---------------------------
1599 -- Add call to Activate_Tasks if body is an activator (actual
1600 -- processing is in chapter 9).
1602 -- Generate subprogram descriptor for elaboration routine
1604 -- ENcode entity names in package body
1606 procedure Expand_N_Package_Body (N : Node_Id) is
1607 Ent : constant Entity_Id := Corresponding_Spec (N);
1610 -- This is done only for non-generic packages
1612 if Ekind (Ent) = E_Package then
1613 New_Scope (Corresponding_Spec (N));
1614 Build_Task_Activation_Call (N);
1618 Set_Elaboration_Flag (N, Corresponding_Spec (N));
1620 -- Generate a subprogram descriptor for the elaboration routine of
1621 -- a package body if the package body has no pending instantiations
1622 -- and it has generated at least one exception handler
1624 if Present (Handler_Records (Body_Entity (Ent)))
1625 and then Is_Compilation_Unit (Ent)
1626 and then not Delay_Subprogram_Descriptors (Body_Entity (Ent))
1628 Generate_Subprogram_Descriptor_For_Package
1629 (N, Body_Entity (Ent));
1632 Set_In_Package_Body (Ent, False);
1634 -- Set to encode entity names in package body before gigi is called
1636 Qualify_Entity_Names (N);
1637 end Expand_N_Package_Body;
1639 ----------------------------------
1640 -- Expand_N_Package_Declaration --
1641 ----------------------------------
1643 -- Add call to Activate_Tasks if there are tasks declared and the
1644 -- package has no body. Note that in Ada83, this may result in
1645 -- premature activation of some tasks, given that we cannot tell
1646 -- whether a body will eventually appear.
1648 procedure Expand_N_Package_Declaration (N : Node_Id) is
1650 if Nkind (Parent (N)) = N_Compilation_Unit
1651 and then not Body_Required (Parent (N))
1652 and then not Unit_Requires_Body (Defining_Entity (N))
1653 and then Present (Activation_Chain_Entity (N))
1655 New_Scope (Defining_Entity (N));
1656 Build_Task_Activation_Call (N);
1660 -- Note: it is not necessary to worry about generating a subprogram
1661 -- descriptor, since the only way to get exception handlers into a
1662 -- package spec is to include instantiations, and that would cause
1663 -- generation of subprogram descriptors to be delayed in any case.
1665 -- Set to encode entity names in package spec before gigi is called
1667 Qualify_Entity_Names (N);
1668 end Expand_N_Package_Declaration;
1670 ---------------------
1671 -- Find_Final_List --
1672 ---------------------
1674 function Find_Final_List
1676 Ref : Node_Id := Empty) return Node_Id
1678 Loc : constant Source_Ptr := Sloc (Ref);
1684 -- Case of an internal component. The Final list is the record
1685 -- controller of the enclosing record
1687 if Present (Ref) then
1691 when N_Unchecked_Type_Conversion | N_Type_Conversion =>
1692 R := Expression (R);
1694 when N_Indexed_Component | N_Explicit_Dereference =>
1697 when N_Selected_Component =>
1701 when N_Identifier =>
1705 raise Program_Error;
1710 Make_Selected_Component (Loc,
1712 Make_Selected_Component (Loc,
1714 Selector_Name => Make_Identifier (Loc, Name_uController)),
1715 Selector_Name => Make_Identifier (Loc, Name_F));
1717 -- Case of a dynamically allocated object. The final list is the
1718 -- corresponding list controller (The next entity in the scope of
1719 -- the access type with the right type). If the type comes from a
1720 -- With_Type clause, no controller was created, and we use the
1721 -- global chain instead.
1723 elsif Is_Access_Type (E) then
1724 if not From_With_Type (E) then
1726 Make_Selected_Component (Loc,
1729 (Associated_Final_Chain (Base_Type (E)), Loc),
1730 Selector_Name => Make_Identifier (Loc, Name_F));
1732 return New_Reference_To (RTE (RE_Global_Final_List), Sloc (E));
1736 if Is_Dynamic_Scope (E) then
1739 S := Enclosing_Dynamic_Scope (E);
1742 -- When the finalization chain entity is 'Error', it means that
1743 -- there should not be any chain at that level and that the
1744 -- enclosing one should be used
1746 -- This is a nasty kludge, see ??? note in exp_ch11
1748 while Finalization_Chain_Entity (S) = Error loop
1749 S := Enclosing_Dynamic_Scope (S);
1752 if S = Standard_Standard then
1753 return New_Reference_To (RTE (RE_Global_Final_List), Sloc (E));
1755 if No (Finalization_Chain_Entity (S)) then
1757 Id := Make_Defining_Identifier (Sloc (S),
1758 New_Internal_Name ('F'));
1759 Set_Finalization_Chain_Entity (S, Id);
1761 -- Set momentarily some semantics attributes to allow normal
1762 -- analysis of expansions containing references to this chain.
1763 -- Will be fully decorated during the expansion of the scope
1766 Set_Ekind (Id, E_Variable);
1767 Set_Etype (Id, RTE (RE_Finalizable_Ptr));
1770 return New_Reference_To (Finalization_Chain_Entity (S), Sloc (E));
1773 end Find_Final_List;
1775 -----------------------------
1776 -- Find_Node_To_Be_Wrapped --
1777 -----------------------------
1779 function Find_Node_To_Be_Wrapped (N : Node_Id) return Node_Id is
1781 The_Parent : Node_Id;
1787 pragma Assert (P /= Empty);
1788 The_Parent := Parent (P);
1790 case Nkind (The_Parent) is
1792 -- Simple statement can be wrapped
1797 -- Usually assignments are good candidate for wrapping
1798 -- except when they have been generated as part of a
1799 -- controlled aggregate where the wrapping should take
1800 -- place more globally.
1802 when N_Assignment_Statement =>
1803 if No_Ctrl_Actions (The_Parent) then
1809 -- An entry call statement is a special case if it occurs in
1810 -- the context of a Timed_Entry_Call. In this case we wrap
1811 -- the entire timed entry call.
1813 when N_Entry_Call_Statement |
1814 N_Procedure_Call_Statement =>
1815 if Nkind (Parent (The_Parent)) = N_Entry_Call_Alternative
1817 Nkind (Parent (Parent (The_Parent))) = N_Timed_Entry_Call
1819 return Parent (Parent (The_Parent));
1824 -- Object declarations are also a boundary for the transient scope
1825 -- even if they are not really wrapped
1826 -- (see Wrap_Transient_Declaration)
1828 when N_Object_Declaration |
1829 N_Object_Renaming_Declaration |
1830 N_Subtype_Declaration =>
1833 -- The expression itself is to be wrapped if its parent is a
1834 -- compound statement or any other statement where the expression
1835 -- is known to be scalar
1837 when N_Accept_Alternative |
1838 N_Attribute_Definition_Clause |
1841 N_Delay_Alternative |
1842 N_Delay_Until_Statement |
1843 N_Delay_Relative_Statement |
1844 N_Discriminant_Association |
1846 N_Entry_Body_Formal_Part |
1849 N_Iteration_Scheme |
1850 N_Terminate_Alternative =>
1853 when N_Attribute_Reference =>
1855 if Is_Procedure_Attribute_Name
1856 (Attribute_Name (The_Parent))
1861 -- If the expression is within the iteration scheme of a loop,
1862 -- we must create a declaration for it, followed by an assignment
1863 -- in order to have a usable statement to wrap.
1865 when N_Loop_Parameter_Specification =>
1866 return Parent (The_Parent);
1868 -- The following nodes contains "dummy calls" which don't
1869 -- need to be wrapped.
1871 when N_Parameter_Specification |
1872 N_Discriminant_Specification |
1873 N_Component_Declaration =>
1876 -- The return statement is not to be wrapped when the function
1877 -- itself needs wrapping at the outer-level
1879 when N_Return_Statement =>
1880 if Requires_Transient_Scope (Return_Type (The_Parent)) then
1886 -- If we leave a scope without having been able to find a node to
1887 -- wrap, something is going wrong but this can happen in error
1888 -- situation that are not detected yet (such as a dynamic string
1889 -- in a pragma export)
1891 when N_Subprogram_Body |
1892 N_Package_Declaration |
1894 N_Block_Statement =>
1897 -- otherwise continue the search
1903 end Find_Node_To_Be_Wrapped;
1905 ----------------------
1906 -- Global_Flist_Ref --
1907 ----------------------
1909 function Global_Flist_Ref (Flist_Ref : Node_Id) return Boolean is
1913 -- Look for the Global_Final_List
1915 if Is_Entity_Name (Flist_Ref) then
1916 Flist := Entity (Flist_Ref);
1918 -- Look for the final list associated with an access to controlled
1920 elsif Nkind (Flist_Ref) = N_Selected_Component
1921 and then Is_Entity_Name (Prefix (Flist_Ref))
1923 Flist := Entity (Prefix (Flist_Ref));
1928 return Present (Flist)
1929 and then Present (Scope (Flist))
1930 and then Enclosing_Dynamic_Scope (Flist) = Standard_Standard;
1931 end Global_Flist_Ref;
1933 ----------------------------------
1934 -- Has_New_Controlled_Component --
1935 ----------------------------------
1937 function Has_New_Controlled_Component (E : Entity_Id) return Boolean is
1941 if not Is_Tagged_Type (E) then
1942 return Has_Controlled_Component (E);
1943 elsif not Is_Derived_Type (E) then
1944 return Has_Controlled_Component (E);
1947 Comp := First_Component (E);
1948 while Present (Comp) loop
1950 if Chars (Comp) = Name_uParent then
1953 elsif Scope (Original_Record_Component (Comp)) = E
1954 and then Controlled_Type (Etype (Comp))
1959 Next_Component (Comp);
1963 end Has_New_Controlled_Component;
1965 --------------------------
1966 -- In_Finalization_Root --
1967 --------------------------
1969 -- It would seem simpler to test Scope (RTE (RE_Root_Controlled)) but
1970 -- the purpose of this function is to avoid a circular call to Rtsfind
1971 -- which would been caused by such a test.
1973 function In_Finalization_Root (E : Entity_Id) return Boolean is
1974 S : constant Entity_Id := Scope (E);
1977 return Chars (Scope (S)) = Name_System
1978 and then Chars (S) = Name_Finalization_Root
1979 and then Scope (Scope (S)) = Standard_Standard;
1980 end In_Finalization_Root;
1982 ------------------------------------
1983 -- Insert_Actions_In_Scope_Around --
1984 ------------------------------------
1986 procedure Insert_Actions_In_Scope_Around (N : Node_Id) is
1987 SE : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
1991 -- If the node to be wrapped is the triggering alternative of an
1992 -- asynchronous select, it is not part of a statement list. The
1993 -- actions must be inserted before the Select itself, which is
1994 -- part of some list of statements.
1996 if Nkind (Parent (Node_To_Be_Wrapped)) = N_Triggering_Alternative then
1997 Target := Parent (Parent (Node_To_Be_Wrapped));
2002 if Present (SE.Actions_To_Be_Wrapped_Before) then
2003 Insert_List_Before (Target, SE.Actions_To_Be_Wrapped_Before);
2004 SE.Actions_To_Be_Wrapped_Before := No_List;
2007 if Present (SE.Actions_To_Be_Wrapped_After) then
2008 Insert_List_After (Target, SE.Actions_To_Be_Wrapped_After);
2009 SE.Actions_To_Be_Wrapped_After := No_List;
2011 end Insert_Actions_In_Scope_Around;
2013 -----------------------
2014 -- Make_Adjust_Call --
2015 -----------------------
2017 function Make_Adjust_Call
2020 Flist_Ref : Node_Id;
2021 With_Attach : Node_Id) return List_Id
2023 Loc : constant Source_Ptr := Sloc (Ref);
2024 Res : constant List_Id := New_List;
2027 Cref : Node_Id := Ref;
2029 Attach : Node_Id := With_Attach;
2032 if Is_Class_Wide_Type (Typ) then
2033 Utyp := Underlying_Type (Base_Type (Root_Type (Typ)));
2035 Utyp := Underlying_Type (Base_Type (Typ));
2038 Set_Assignment_OK (Cref);
2040 -- Deal with non-tagged derivation of private views
2042 if Is_Untagged_Derivation (Typ) then
2043 Utyp := Underlying_Type (Root_Type (Base_Type (Typ)));
2044 Cref := Unchecked_Convert_To (Utyp, Cref);
2045 Set_Assignment_OK (Cref);
2046 -- To prevent problems with UC see 1.156 RH ???
2049 -- If the underlying_type is a subtype, we are dealing with
2050 -- the completion of a private type. We need to access
2051 -- the base type and generate a conversion to it.
2053 if Utyp /= Base_Type (Utyp) then
2054 pragma Assert (Is_Private_Type (Typ));
2055 Utyp := Base_Type (Utyp);
2056 Cref := Unchecked_Convert_To (Utyp, Cref);
2059 -- If the object is unanalyzed, set its expected type for use
2060 -- in Convert_View in case an additional conversion is needed.
2062 if No (Etype (Cref))
2063 and then Nkind (Cref) /= N_Unchecked_Type_Conversion
2065 Set_Etype (Cref, Typ);
2068 -- We do not need to attach to one of the Global Final Lists
2069 -- the objects whose type is Finalize_Storage_Only
2071 if Finalize_Storage_Only (Typ)
2072 and then (Global_Flist_Ref (Flist_Ref)
2073 or else Entity (Constant_Value (RTE (RE_Garbage_Collected)))
2076 Attach := Make_Integer_Literal (Loc, 0);
2080 -- Deep_Adjust (Flist_Ref, Ref, With_Attach);
2082 if Has_Controlled_Component (Utyp)
2083 or else Is_Class_Wide_Type (Typ)
2085 if Is_Tagged_Type (Utyp) then
2086 Proc := Find_Prim_Op (Utyp, TSS_Deep_Adjust);
2089 Proc := TSS (Utyp, TSS_Deep_Adjust);
2092 Cref := Convert_View (Proc, Cref, 2);
2095 Make_Procedure_Call_Statement (Loc,
2096 Name => New_Reference_To (Proc, Loc),
2097 Parameter_Associations =>
2098 New_List (Flist_Ref, Cref, Attach)));
2101 -- if With_Attach then
2102 -- Attach_To_Final_List (Ref, Flist_Ref);
2106 else -- Is_Controlled (Utyp)
2108 Proc := Find_Prim_Op (Utyp, Name_Of (Adjust_Case));
2109 Cref := Convert_View (Proc, Cref);
2110 Cref2 := New_Copy_Tree (Cref);
2113 Make_Procedure_Call_Statement (Loc,
2114 Name => New_Reference_To (Proc, Loc),
2115 Parameter_Associations => New_List (Cref2)));
2117 Append_To (Res, Make_Attach_Call (Cref, Flist_Ref, Attach));
2121 end Make_Adjust_Call;
2123 ----------------------
2124 -- Make_Attach_Call --
2125 ----------------------
2128 -- System.FI.Attach_To_Final_List (Flist, Ref, Nb_Link)
2130 function Make_Attach_Call
2132 Flist_Ref : Node_Id;
2133 With_Attach : Node_Id) return Node_Id
2135 Loc : constant Source_Ptr := Sloc (Obj_Ref);
2138 -- Optimization: If the number of links is statically '0', don't
2139 -- call the attach_proc.
2141 if Nkind (With_Attach) = N_Integer_Literal
2142 and then Intval (With_Attach) = Uint_0
2144 return Make_Null_Statement (Loc);
2148 Make_Procedure_Call_Statement (Loc,
2149 Name => New_Reference_To (RTE (RE_Attach_To_Final_List), Loc),
2150 Parameter_Associations => New_List (
2152 OK_Convert_To (RTE (RE_Finalizable), Obj_Ref),
2154 end Make_Attach_Call;
2166 Is_Master : Boolean;
2167 Is_Protected_Subprogram : Boolean;
2168 Is_Task_Allocation_Block : Boolean;
2169 Is_Asynchronous_Call_Block : Boolean) return Node_Id
2171 Loc : constant Source_Ptr := Sloc (Clean);
2172 Stmt : constant List_Id := New_List;
2178 Param_Type : Entity_Id;
2179 Pid : Entity_Id := Empty;
2180 Cancel_Param : Entity_Id;
2184 if Restricted_Profile then
2186 (Stmt, Build_Runtime_Call (Loc, RE_Complete_Restricted_Task));
2188 Append_To (Stmt, Build_Runtime_Call (Loc, RE_Complete_Task));
2191 elsif Is_Master then
2192 if Restriction_Active (No_Task_Hierarchy) = False then
2193 Append_To (Stmt, Build_Runtime_Call (Loc, RE_Complete_Master));
2196 elsif Is_Protected_Subprogram then
2198 -- Add statements to the cleanup handler of the (ordinary)
2199 -- subprogram expanded to implement a protected subprogram,
2200 -- unlocking the protected object parameter and undeferring abortion.
2201 -- If this is a protected procedure, and the object contains
2202 -- entries, this also calls the entry service routine.
2204 -- NOTE: This cleanup handler references _object, a parameter
2205 -- to the procedure.
2207 -- Find the _object parameter representing the protected object.
2209 Spec := Parent (Corresponding_Spec (N));
2211 Param := First (Parameter_Specifications (Spec));
2213 Param_Type := Etype (Parameter_Type (Param));
2215 if Ekind (Param_Type) = E_Record_Type then
2216 Pid := Corresponding_Concurrent_Type (Param_Type);
2219 exit when not Present (Param) or else Present (Pid);
2223 pragma Assert (Present (Param));
2225 -- If the associated protected object declares entries,
2226 -- a protected procedure has to service entry queues.
2227 -- In this case, add
2229 -- Service_Entries (_object._object'Access);
2231 -- _object is the record used to implement the protected object.
2232 -- It is a parameter to the protected subprogram.
2234 if Nkind (Specification (N)) = N_Procedure_Specification
2235 and then Has_Entries (Pid)
2238 or else Restriction_Active (No_Entry_Queue) = False
2239 or else Number_Entries (Pid) > 1
2241 Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
2243 Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
2247 Make_Procedure_Call_Statement (Loc,
2249 Parameter_Associations => New_List (
2250 Make_Attribute_Reference (Loc,
2252 Make_Selected_Component (Loc,
2253 Prefix => New_Reference_To (
2254 Defining_Identifier (Param), Loc),
2256 Make_Identifier (Loc, Name_uObject)),
2257 Attribute_Name => Name_Unchecked_Access))));
2260 -- Unlock (_object._object'Access);
2262 -- object is the record used to implement the protected object.
2263 -- It is a parameter to the protected subprogram.
2265 -- If the protected object is controlled (i.e it has entries or
2266 -- needs finalization for interrupt handling), call
2267 -- Unlock_Entries, except if the protected object follows the
2268 -- ravenscar profile, in which case call Unlock_Entry, otherwise
2269 -- call the simplified version, Unlock.
2271 if Has_Entries (Pid)
2272 or else Has_Interrupt_Handler (Pid)
2273 or else (Has_Attach_Handler (Pid)
2274 and then not Restricted_Profile)
2277 or else Restriction_Active (No_Entry_Queue) = False
2278 or else Number_Entries (Pid) > 1
2280 Name := New_Reference_To (RTE (RE_Unlock_Entries), Loc);
2282 Name := New_Reference_To (RTE (RE_Unlock_Entry), Loc);
2286 Name := New_Reference_To (RTE (RE_Unlock), Loc);
2290 Make_Procedure_Call_Statement (Loc,
2292 Parameter_Associations => New_List (
2293 Make_Attribute_Reference (Loc,
2295 Make_Selected_Component (Loc,
2297 New_Reference_To (Defining_Identifier (Param), Loc),
2299 Make_Identifier (Loc, Name_uObject)),
2300 Attribute_Name => Name_Unchecked_Access))));
2303 if Abort_Allowed then
2308 Make_Procedure_Call_Statement (Loc,
2311 RTE (RE_Abort_Undefer), Loc),
2312 Parameter_Associations => Empty_List));
2315 elsif Is_Task_Allocation_Block then
2317 -- Add a call to Expunge_Unactivated_Tasks to the cleanup
2318 -- handler of a block created for the dynamic allocation of
2321 -- Expunge_Unactivated_Tasks (_chain);
2323 -- where _chain is the list of tasks created by the allocator
2324 -- but not yet activated. This list will be empty unless
2325 -- the block completes abnormally.
2327 -- This only applies to dynamically allocated tasks;
2328 -- other unactivated tasks are completed by Complete_Task or
2331 -- NOTE: This cleanup handler references _chain, a local
2335 Make_Procedure_Call_Statement (Loc,
2338 RTE (RE_Expunge_Unactivated_Tasks), Loc),
2339 Parameter_Associations => New_List (
2340 New_Reference_To (Activation_Chain_Entity (N), Loc))));
2342 elsif Is_Asynchronous_Call_Block then
2344 -- Add a call to attempt to cancel the asynchronous entry call
2345 -- whenever the block containing the abortable part is exited.
2347 -- NOTE: This cleanup handler references C, a local object
2349 -- Get the argument to the Cancel procedure
2350 Cancel_Param := Entry_Cancel_Parameter (Entity (Identifier (N)));
2352 -- If it is of type Communication_Block, this must be a
2353 -- protected entry call.
2355 if Is_RTE (Etype (Cancel_Param), RE_Communication_Block) then
2359 -- if Enqueued (Cancel_Parameter) then
2361 Make_Implicit_If_Statement (Clean,
2362 Condition => Make_Function_Call (Loc,
2363 Name => New_Reference_To (
2364 RTE (RE_Enqueued), Loc),
2365 Parameter_Associations => New_List (
2366 New_Reference_To (Cancel_Param, Loc))),
2367 Then_Statements => New_List (
2369 -- Cancel_Protected_Entry_Call (Cancel_Param);
2371 Make_Procedure_Call_Statement (Loc,
2372 Name => New_Reference_To (
2373 RTE (RE_Cancel_Protected_Entry_Call), Loc),
2374 Parameter_Associations => New_List (
2375 New_Reference_To (Cancel_Param, Loc))))));
2377 -- Asynchronous delay
2379 elsif Is_RTE (Etype (Cancel_Param), RE_Delay_Block) then
2381 Make_Procedure_Call_Statement (Loc,
2382 Name => New_Reference_To (RTE (RE_Cancel_Async_Delay), Loc),
2383 Parameter_Associations => New_List (
2384 Make_Attribute_Reference (Loc,
2385 Prefix => New_Reference_To (Cancel_Param, Loc),
2386 Attribute_Name => Name_Unchecked_Access))));
2391 -- Append call to Cancel_Task_Entry_Call (C);
2394 Make_Procedure_Call_Statement (Loc,
2395 Name => New_Reference_To (
2396 RTE (RE_Cancel_Task_Entry_Call),
2398 Parameter_Associations => New_List (
2399 New_Reference_To (Cancel_Param, Loc))));
2404 if Present (Flist) then
2406 Make_Procedure_Call_Statement (Loc,
2407 Name => New_Reference_To (RTE (RE_Finalize_List), Loc),
2408 Parameter_Associations => New_List (
2409 New_Reference_To (Flist, Loc))));
2412 if Present (Mark) then
2414 Make_Procedure_Call_Statement (Loc,
2415 Name => New_Reference_To (RTE (RE_SS_Release), Loc),
2416 Parameter_Associations => New_List (
2417 New_Reference_To (Mark, Loc))));
2421 Make_Subprogram_Body (Loc,
2423 Make_Procedure_Specification (Loc,
2424 Defining_Unit_Name => Clean),
2426 Declarations => New_List,
2428 Handled_Statement_Sequence =>
2429 Make_Handled_Sequence_Of_Statements (Loc,
2430 Statements => Stmt));
2432 if Present (Flist) or else Is_Task or else Is_Master then
2433 Wrap_Cleanup_Procedure (Sbody);
2436 -- We do not want debug information for _Clean routines,
2437 -- since it just confuses the debugging operation unless
2438 -- we are debugging generated code.
2440 if not Debug_Generated_Code then
2441 Set_Debug_Info_Off (Clean, True);
2447 --------------------------
2448 -- Make_Deep_Array_Body --
2449 --------------------------
2451 -- Array components are initialized and adjusted in the normal order
2452 -- and finalized in the reverse order. Exceptions are handled and
2453 -- Program_Error is re-raise in the Adjust and Finalize case
2454 -- (RM 7.6.1(12)). Generate the following code :
2456 -- procedure Deep_<P> -- with <P> being Initialize or Adjust or Finalize
2457 -- (L : in out Finalizable_Ptr;
2461 -- for J1 in Typ'First (1) .. Typ'Last (1) loop
2462 -- ^ reverse ^ -- in the finalization case
2464 -- for J2 in Typ'First (n) .. Typ'Last (n) loop
2465 -- Make_<P>_Call (Typ, V (J1, .. , Jn), L, V);
2469 -- exception -- not in the
2470 -- when others => raise Program_Error; -- Initialize case
2473 function Make_Deep_Array_Body
2474 (Prim : Final_Primitives;
2475 Typ : Entity_Id) return List_Id
2477 Loc : constant Source_Ptr := Sloc (Typ);
2479 Index_List : constant List_Id := New_List;
2480 -- Stores the list of references to the indexes (one per dimension)
2482 function One_Component return List_Id;
2483 -- Create one statement to initialize/adjust/finalize one array
2484 -- component, designated by a full set of indices.
2486 function One_Dimension (N : Int) return List_Id;
2487 -- Create loop to deal with one dimension of the array. The single
2488 -- statement in the body of the loop initializes the inner dimensions if
2489 -- any, or else a single component.
2495 function One_Component return List_Id is
2496 Comp_Typ : constant Entity_Id := Component_Type (Typ);
2497 Comp_Ref : constant Node_Id :=
2498 Make_Indexed_Component (Loc,
2499 Prefix => Make_Identifier (Loc, Name_V),
2500 Expressions => Index_List);
2503 -- Set the etype of the component Reference, which is used to
2504 -- determine whether a conversion to a parent type is needed.
2506 Set_Etype (Comp_Ref, Comp_Typ);
2509 when Initialize_Case =>
2510 return Make_Init_Call (Comp_Ref, Comp_Typ,
2511 Make_Identifier (Loc, Name_L),
2512 Make_Identifier (Loc, Name_B));
2515 return Make_Adjust_Call (Comp_Ref, Comp_Typ,
2516 Make_Identifier (Loc, Name_L),
2517 Make_Identifier (Loc, Name_B));
2519 when Finalize_Case =>
2520 return Make_Final_Call (Comp_Ref, Comp_Typ,
2521 Make_Identifier (Loc, Name_B));
2529 function One_Dimension (N : Int) return List_Id is
2533 if N > Number_Dimensions (Typ) then
2534 return One_Component;
2538 Make_Defining_Identifier (Loc, New_External_Name ('J', N));
2540 Append_To (Index_List, New_Reference_To (Index, Loc));
2543 Make_Implicit_Loop_Statement (Typ,
2544 Identifier => Empty,
2546 Make_Iteration_Scheme (Loc,
2547 Loop_Parameter_Specification =>
2548 Make_Loop_Parameter_Specification (Loc,
2549 Defining_Identifier => Index,
2550 Discrete_Subtype_Definition =>
2551 Make_Attribute_Reference (Loc,
2552 Prefix => Make_Identifier (Loc, Name_V),
2553 Attribute_Name => Name_Range,
2554 Expressions => New_List (
2555 Make_Integer_Literal (Loc, N))),
2556 Reverse_Present => Prim = Finalize_Case)),
2557 Statements => One_Dimension (N + 1)));
2561 -- Start of processing for Make_Deep_Array_Body
2564 return One_Dimension (1);
2565 end Make_Deep_Array_Body;
2567 --------------------
2568 -- Make_Deep_Proc --
2569 --------------------
2572 -- procedure DEEP_<prim>
2573 -- (L : IN OUT Finalizable_Ptr; -- not for Finalize
2574 -- V : IN OUT <typ>;
2575 -- B : IN Short_Short_Integer) is
2578 -- exception -- Finalize and Adjust Cases only
2579 -- raise Program_Error; -- idem
2582 function Make_Deep_Proc
2583 (Prim : Final_Primitives;
2585 Stmts : List_Id) return Entity_Id
2587 Loc : constant Source_Ptr := Sloc (Typ);
2589 Proc_Name : Entity_Id;
2590 Handler : List_Id := No_List;
2594 if Prim = Finalize_Case then
2595 Formals := New_List;
2596 Type_B := Standard_Boolean;
2599 Formals := New_List (
2600 Make_Parameter_Specification (Loc,
2601 Defining_Identifier => Make_Defining_Identifier (Loc, Name_L),
2603 Out_Present => True,
2605 New_Reference_To (RTE (RE_Finalizable_Ptr), Loc)));
2606 Type_B := Standard_Short_Short_Integer;
2610 Make_Parameter_Specification (Loc,
2611 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
2613 Out_Present => True,
2614 Parameter_Type => New_Reference_To (Typ, Loc)));
2617 Make_Parameter_Specification (Loc,
2618 Defining_Identifier => Make_Defining_Identifier (Loc, Name_B),
2619 Parameter_Type => New_Reference_To (Type_B, Loc)));
2621 if Prim = Finalize_Case or else Prim = Adjust_Case then
2622 Handler := New_List (
2623 Make_Exception_Handler (Loc,
2624 Exception_Choices => New_List (Make_Others_Choice (Loc)),
2625 Statements => New_List (
2626 Make_Raise_Program_Error (Loc,
2627 Reason => PE_Finalize_Raised_Exception))));
2631 Make_Defining_Identifier (Loc,
2632 Chars => Make_TSS_Name (Typ, Deep_Name_Of (Prim)));
2635 Make_Subprogram_Body (Loc,
2637 Make_Procedure_Specification (Loc,
2638 Defining_Unit_Name => Proc_Name,
2639 Parameter_Specifications => Formals),
2641 Declarations => Empty_List,
2642 Handled_Statement_Sequence =>
2643 Make_Handled_Sequence_Of_Statements (Loc,
2644 Statements => Stmts,
2645 Exception_Handlers => Handler)));
2650 ---------------------------
2651 -- Make_Deep_Record_Body --
2652 ---------------------------
2654 -- The Deep procedures call the appropriate Controlling proc on the
2655 -- the controller component. In the init case, it also attach the
2656 -- controller to the current finalization list.
2658 function Make_Deep_Record_Body
2659 (Prim : Final_Primitives;
2660 Typ : Entity_Id) return List_Id
2662 Loc : constant Source_Ptr := Sloc (Typ);
2663 Controller_Typ : Entity_Id;
2664 Obj_Ref : constant Node_Id := Make_Identifier (Loc, Name_V);
2665 Controller_Ref : constant Node_Id :=
2666 Make_Selected_Component (Loc,
2669 Make_Identifier (Loc, Name_uController));
2670 Res : constant List_Id := New_List;
2673 if Is_Return_By_Reference_Type (Typ) then
2674 Controller_Typ := RTE (RE_Limited_Record_Controller);
2676 Controller_Typ := RTE (RE_Record_Controller);
2680 when Initialize_Case =>
2681 Append_List_To (Res,
2683 Ref => Controller_Ref,
2684 Typ => Controller_Typ,
2685 Flist_Ref => Make_Identifier (Loc, Name_L),
2686 With_Attach => Make_Identifier (Loc, Name_B)));
2688 -- When the type is also a controlled type by itself,
2689 -- Initialize it and attach it to the finalization chain
2691 if Is_Controlled (Typ) then
2693 Make_Procedure_Call_Statement (Loc,
2694 Name => New_Reference_To (
2695 Find_Prim_Op (Typ, Name_Of (Prim)), Loc),
2696 Parameter_Associations =>
2697 New_List (New_Copy_Tree (Obj_Ref))));
2699 Append_To (Res, Make_Attach_Call (
2700 Obj_Ref => New_Copy_Tree (Obj_Ref),
2701 Flist_Ref => Make_Identifier (Loc, Name_L),
2702 With_Attach => Make_Identifier (Loc, Name_B)));
2706 Append_List_To (Res,
2707 Make_Adjust_Call (Controller_Ref, Controller_Typ,
2708 Make_Identifier (Loc, Name_L),
2709 Make_Identifier (Loc, Name_B)));
2711 -- When the type is also a controlled type by itself,
2712 -- Adjust it it and attach it to the finalization chain
2714 if Is_Controlled (Typ) then
2716 Make_Procedure_Call_Statement (Loc,
2717 Name => New_Reference_To (
2718 Find_Prim_Op (Typ, Name_Of (Prim)), Loc),
2719 Parameter_Associations =>
2720 New_List (New_Copy_Tree (Obj_Ref))));
2722 Append_To (Res, Make_Attach_Call (
2723 Obj_Ref => New_Copy_Tree (Obj_Ref),
2724 Flist_Ref => Make_Identifier (Loc, Name_L),
2725 With_Attach => Make_Identifier (Loc, Name_B)));
2728 when Finalize_Case =>
2729 if Is_Controlled (Typ) then
2731 Make_Implicit_If_Statement (Obj_Ref,
2732 Condition => Make_Identifier (Loc, Name_B),
2733 Then_Statements => New_List (
2734 Make_Procedure_Call_Statement (Loc,
2735 Name => New_Reference_To (RTE (RE_Finalize_One), Loc),
2736 Parameter_Associations => New_List (
2737 OK_Convert_To (RTE (RE_Finalizable),
2738 New_Copy_Tree (Obj_Ref))))),
2740 Else_Statements => New_List (
2741 Make_Procedure_Call_Statement (Loc,
2742 Name => New_Reference_To (
2743 Find_Prim_Op (Typ, Name_Of (Prim)), Loc),
2744 Parameter_Associations =>
2745 New_List (New_Copy_Tree (Obj_Ref))))));
2748 Append_List_To (Res,
2749 Make_Final_Call (Controller_Ref, Controller_Typ,
2750 Make_Identifier (Loc, Name_B)));
2753 end Make_Deep_Record_Body;
2755 ----------------------
2756 -- Make_Final_Call --
2757 ----------------------
2759 function Make_Final_Call
2762 With_Detach : Node_Id) return List_Id
2764 Loc : constant Source_Ptr := Sloc (Ref);
2765 Res : constant List_Id := New_List;
2772 if Is_Class_Wide_Type (Typ) then
2773 Utyp := Root_Type (Typ);
2776 elsif Is_Concurrent_Type (Typ) then
2777 Utyp := Corresponding_Record_Type (Typ);
2778 Cref := Convert_Concurrent (Ref, Typ);
2780 elsif Is_Private_Type (Typ)
2781 and then Present (Full_View (Typ))
2782 and then Is_Concurrent_Type (Full_View (Typ))
2784 Utyp := Corresponding_Record_Type (Full_View (Typ));
2785 Cref := Convert_Concurrent (Ref, Full_View (Typ));
2791 Utyp := Underlying_Type (Base_Type (Utyp));
2792 Set_Assignment_OK (Cref);
2794 -- Deal with non-tagged derivation of private views
2796 if Is_Untagged_Derivation (Typ) then
2797 Utyp := Underlying_Type (Root_Type (Base_Type (Typ)));
2798 Cref := Unchecked_Convert_To (Utyp, Cref);
2799 Set_Assignment_OK (Cref);
2800 -- To prevent problems with UC see 1.156 RH ???
2803 -- If the underlying_type is a subtype, we are dealing with
2804 -- the completion of a private type. We need to access
2805 -- the base type and generate a conversion to it.
2807 if Utyp /= Base_Type (Utyp) then
2808 pragma Assert (Is_Private_Type (Typ));
2809 Utyp := Base_Type (Utyp);
2810 Cref := Unchecked_Convert_To (Utyp, Cref);
2814 -- Deep_Finalize (Ref, With_Detach);
2816 if Has_Controlled_Component (Utyp)
2817 or else Is_Class_Wide_Type (Typ)
2819 if Is_Tagged_Type (Utyp) then
2820 Proc := Find_Prim_Op (Utyp, TSS_Deep_Finalize);
2822 Proc := TSS (Utyp, TSS_Deep_Finalize);
2825 Cref := Convert_View (Proc, Cref);
2828 Make_Procedure_Call_Statement (Loc,
2829 Name => New_Reference_To (Proc, Loc),
2830 Parameter_Associations =>
2831 New_List (Cref, With_Detach)));
2834 -- if With_Detach then
2835 -- Finalize_One (Ref);
2841 Proc := Find_Prim_Op (Utyp, Name_Of (Finalize_Case));
2843 if Chars (With_Detach) = Chars (Standard_True) then
2845 Make_Procedure_Call_Statement (Loc,
2846 Name => New_Reference_To (RTE (RE_Finalize_One), Loc),
2847 Parameter_Associations => New_List (
2848 OK_Convert_To (RTE (RE_Finalizable), Cref))));
2850 elsif Chars (With_Detach) = Chars (Standard_False) then
2852 Make_Procedure_Call_Statement (Loc,
2853 Name => New_Reference_To (Proc, Loc),
2854 Parameter_Associations =>
2855 New_List (Convert_View (Proc, Cref))));
2858 Cref2 := New_Copy_Tree (Cref);
2860 Make_Implicit_If_Statement (Ref,
2861 Condition => With_Detach,
2862 Then_Statements => New_List (
2863 Make_Procedure_Call_Statement (Loc,
2864 Name => New_Reference_To (RTE (RE_Finalize_One), Loc),
2865 Parameter_Associations => New_List (
2866 OK_Convert_To (RTE (RE_Finalizable), Cref)))),
2868 Else_Statements => New_List (
2869 Make_Procedure_Call_Statement (Loc,
2870 Name => New_Reference_To (Proc, Loc),
2871 Parameter_Associations =>
2872 New_List (Convert_View (Proc, Cref2))))));
2877 end Make_Final_Call;
2879 --------------------
2880 -- Make_Init_Call --
2881 --------------------
2883 function Make_Init_Call
2886 Flist_Ref : Node_Id;
2887 With_Attach : Node_Id) return List_Id
2889 Loc : constant Source_Ptr := Sloc (Ref);
2891 Res : constant List_Id := New_List;
2896 Attach : Node_Id := With_Attach;
2899 if Is_Concurrent_Type (Typ) then
2901 Utyp := Corresponding_Record_Type (Typ);
2902 Cref := Convert_Concurrent (Ref, Typ);
2904 elsif Is_Private_Type (Typ)
2905 and then Present (Full_View (Typ))
2906 and then Is_Concurrent_Type (Underlying_Type (Typ))
2909 Utyp := Corresponding_Record_Type (Underlying_Type (Typ));
2910 Cref := Convert_Concurrent (Ref, Underlying_Type (Typ));
2918 Utyp := Underlying_Type (Base_Type (Utyp));
2920 Set_Assignment_OK (Cref);
2922 -- Deal with non-tagged derivation of private views
2924 if Is_Untagged_Derivation (Typ)
2925 and then not Is_Conc
2927 Utyp := Underlying_Type (Root_Type (Base_Type (Typ)));
2928 Cref := Unchecked_Convert_To (Utyp, Cref);
2929 Set_Assignment_OK (Cref);
2930 -- To prevent problems with UC see 1.156 RH ???
2933 -- If the underlying_type is a subtype, we are dealing with
2934 -- the completion of a private type. We need to access
2935 -- the base type and generate a conversion to it.
2937 if Utyp /= Base_Type (Utyp) then
2938 pragma Assert (Is_Private_Type (Typ));
2939 Utyp := Base_Type (Utyp);
2940 Cref := Unchecked_Convert_To (Utyp, Cref);
2943 -- We do not need to attach to one of the Global Final Lists
2944 -- the objects whose type is Finalize_Storage_Only
2946 if Finalize_Storage_Only (Typ)
2947 and then (Global_Flist_Ref (Flist_Ref)
2948 or else Entity (Constant_Value (RTE (RE_Garbage_Collected)))
2951 Attach := Make_Integer_Literal (Loc, 0);
2955 -- Deep_Initialize (Ref, Flist_Ref);
2957 if Has_Controlled_Component (Utyp) then
2958 Proc := TSS (Utyp, Deep_Name_Of (Initialize_Case));
2960 Cref := Convert_View (Proc, Cref, 2);
2963 Make_Procedure_Call_Statement (Loc,
2964 Name => New_Reference_To (Proc, Loc),
2965 Parameter_Associations => New_List (
2971 -- Attach_To_Final_List (Ref, Flist_Ref);
2972 -- Initialize (Ref);
2974 else -- Is_Controlled (Utyp)
2975 Proc := Find_Prim_Op (Utyp, Name_Of (Initialize_Case));
2976 Check_Visibly_Controlled (Initialize_Case, Typ, Proc, Cref);
2978 Cref := Convert_View (Proc, Cref);
2979 Cref2 := New_Copy_Tree (Cref);
2982 Make_Procedure_Call_Statement (Loc,
2983 Name => New_Reference_To (Proc, Loc),
2984 Parameter_Associations => New_List (Cref2)));
2987 Make_Attach_Call (Cref, Flist_Ref, Attach));
2993 --------------------------
2994 -- Make_Transient_Block --
2995 --------------------------
2997 -- If finalization is involved, this function just wraps the instruction
2998 -- into a block whose name is the transient block entity, and then
2999 -- Expand_Cleanup_Actions (called on the expansion of the handled
3000 -- sequence of statements will do the necessary expansions for
3003 function Make_Transient_Block
3005 Action : Node_Id) return Node_Id
3007 Flist : constant Entity_Id := Finalization_Chain_Entity (Current_Scope);
3008 Decls : constant List_Id := New_List;
3009 Par : constant Node_Id := Parent (Action);
3010 Instrs : constant List_Id := New_List (Action);
3014 -- Case where only secondary stack use is involved
3016 if Uses_Sec_Stack (Current_Scope)
3018 and then Nkind (Action) /= N_Return_Statement
3019 and then Nkind (Par) /= N_Exception_Handler
3026 S := Scope (Current_Scope);
3030 -- At the outer level, no need to release the sec stack
3032 if S = Standard_Standard then
3033 Set_Uses_Sec_Stack (Current_Scope, False);
3036 -- In a function, only release the sec stack if the
3037 -- function does not return on the sec stack otherwise
3038 -- the result may be lost. The caller is responsible for
3041 elsif K = E_Function then
3042 Set_Uses_Sec_Stack (Current_Scope, False);
3044 if not Requires_Transient_Scope (Etype (S)) then
3045 if not Functions_Return_By_DSP_On_Target then
3046 Set_Uses_Sec_Stack (S, True);
3047 Check_Restriction (No_Secondary_Stack, Action);
3053 -- In a loop or entry we should install a block encompassing
3054 -- all the construct. For now just release right away.
3056 elsif K = E_Loop or else K = E_Entry then
3059 -- In a procedure or a block, we release on exit of the
3060 -- procedure or block. ??? memory leak can be created by
3063 elsif K = E_Procedure
3066 if not Functions_Return_By_DSP_On_Target then
3067 Set_Uses_Sec_Stack (S, True);
3068 Check_Restriction (No_Secondary_Stack, Action);
3071 Set_Uses_Sec_Stack (Current_Scope, False);
3081 -- Insert actions stuck in the transient scopes as well as all
3082 -- freezing nodes needed by those actions
3084 Insert_Actions_In_Scope_Around (Action);
3087 Last_Inserted : Node_Id := Prev (Action);
3090 if Present (Last_Inserted) then
3091 Freeze_All (First_Entity (Current_Scope), Last_Inserted);
3096 Make_Block_Statement (Loc,
3097 Identifier => New_Reference_To (Current_Scope, Loc),
3098 Declarations => Decls,
3099 Handled_Statement_Sequence =>
3100 Make_Handled_Sequence_Of_Statements (Loc, Statements => Instrs),
3101 Has_Created_Identifier => True);
3103 -- When the transient scope was established, we pushed the entry for
3104 -- the transient scope onto the scope stack, so that the scope was
3105 -- active for the installation of finalizable entities etc. Now we
3106 -- must remove this entry, since we have constructed a proper block.
3111 end Make_Transient_Block;
3113 ------------------------
3114 -- Node_To_Be_Wrapped --
3115 ------------------------
3117 function Node_To_Be_Wrapped return Node_Id is
3119 return Scope_Stack.Table (Scope_Stack.Last).Node_To_Be_Wrapped;
3120 end Node_To_Be_Wrapped;
3122 ----------------------------
3123 -- Set_Node_To_Be_Wrapped --
3124 ----------------------------
3126 procedure Set_Node_To_Be_Wrapped (N : Node_Id) is
3128 Scope_Stack.Table (Scope_Stack.Last).Node_To_Be_Wrapped := N;
3129 end Set_Node_To_Be_Wrapped;
3131 ----------------------------------
3132 -- Store_After_Actions_In_Scope --
3133 ----------------------------------
3135 procedure Store_After_Actions_In_Scope (L : List_Id) is
3136 SE : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
3139 if Present (SE.Actions_To_Be_Wrapped_After) then
3140 Insert_List_Before_And_Analyze (
3141 First (SE.Actions_To_Be_Wrapped_After), L);
3144 SE.Actions_To_Be_Wrapped_After := L;
3146 if Is_List_Member (SE.Node_To_Be_Wrapped) then
3147 Set_Parent (L, Parent (SE.Node_To_Be_Wrapped));
3149 Set_Parent (L, SE.Node_To_Be_Wrapped);
3154 end Store_After_Actions_In_Scope;
3156 -----------------------------------
3157 -- Store_Before_Actions_In_Scope --
3158 -----------------------------------
3160 procedure Store_Before_Actions_In_Scope (L : List_Id) is
3161 SE : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
3164 if Present (SE.Actions_To_Be_Wrapped_Before) then
3165 Insert_List_After_And_Analyze (
3166 Last (SE.Actions_To_Be_Wrapped_Before), L);
3169 SE.Actions_To_Be_Wrapped_Before := L;
3171 if Is_List_Member (SE.Node_To_Be_Wrapped) then
3172 Set_Parent (L, Parent (SE.Node_To_Be_Wrapped));
3174 Set_Parent (L, SE.Node_To_Be_Wrapped);
3179 end Store_Before_Actions_In_Scope;
3181 --------------------------------
3182 -- Wrap_Transient_Declaration --
3183 --------------------------------
3185 -- If a transient scope has been established during the processing of the
3186 -- Expression of an Object_Declaration, it is not possible to wrap the
3187 -- declaration into a transient block as usual case, otherwise the object
3188 -- would be itself declared in the wrong scope. Therefore, all entities (if
3189 -- any) defined in the transient block are moved to the proper enclosing
3190 -- scope, furthermore, if they are controlled variables they are finalized
3191 -- right after the declaration. The finalization list of the transient
3192 -- scope is defined as a renaming of the enclosing one so during their
3193 -- initialization they will be attached to the proper finalization
3194 -- list. For instance, the following declaration :
3196 -- X : Typ := F (G (A), G (B));
3198 -- (where G(A) and G(B) return controlled values, expanded as _v1 and _v2)
3199 -- is expanded into :
3201 -- _local_final_list_1 : Finalizable_Ptr;
3202 -- X : Typ := [ complex Expression-Action ];
3203 -- Finalize_One(_v1);
3204 -- Finalize_One (_v2);
3206 procedure Wrap_Transient_Declaration (N : Node_Id) is
3208 LC : Entity_Id := Empty;
3210 Loc : constant Source_Ptr := Sloc (N);
3211 Enclosing_S : Entity_Id;
3213 Next_N : constant Node_Id := Next (N);
3217 Enclosing_S := Scope (S);
3219 -- Insert Actions kept in the Scope stack
3221 Insert_Actions_In_Scope_Around (N);
3223 -- If the declaration is consuming some secondary stack, mark the
3224 -- Enclosing scope appropriately.
3226 Uses_SS := Uses_Sec_Stack (S);
3229 -- Create a List controller and rename the final list to be its
3230 -- internal final pointer:
3231 -- Lxxx : Simple_List_Controller;
3232 -- Fxxx : Finalizable_Ptr renames Lxxx.F;
3234 if Present (Finalization_Chain_Entity (S)) then
3235 LC := Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
3238 Make_Object_Declaration (Loc,
3239 Defining_Identifier => LC,
3240 Object_Definition =>
3241 New_Reference_To (RTE (RE_Simple_List_Controller), Loc)),
3243 Make_Object_Renaming_Declaration (Loc,
3244 Defining_Identifier => Finalization_Chain_Entity (S),
3245 Subtype_Mark => New_Reference_To (RTE (RE_Finalizable_Ptr), Loc),
3247 Make_Selected_Component (Loc,
3248 Prefix => New_Reference_To (LC, Loc),
3249 Selector_Name => Make_Identifier (Loc, Name_F))));
3251 -- Put the declaration at the beginning of the declaration part
3252 -- to make sure it will be before all other actions that have been
3253 -- inserted before N.
3255 Insert_List_Before_And_Analyze (First (List_Containing (N)), Nodes);
3257 -- Generate the Finalization calls by finalizing the list
3258 -- controller right away. It will be re-finalized on scope
3259 -- exit but it doesn't matter. It cannot be done when the
3260 -- call initializes a renaming object though because in this
3261 -- case, the object becomes a pointer to the temporary and thus
3262 -- increases its life span.
3264 if Nkind (N) = N_Object_Renaming_Declaration
3265 and then Controlled_Type (Etype (Defining_Identifier (N)))
3272 Ref => New_Reference_To (LC, Loc),
3274 With_Detach => New_Reference_To (Standard_False, Loc));
3275 if Present (Next_N) then
3276 Insert_List_Before_And_Analyze (Next_N, Nodes);
3278 Append_List_To (List_Containing (N), Nodes);
3283 -- Put the local entities back in the enclosing scope, and set the
3284 -- Is_Public flag appropriately.
3286 Transfer_Entities (S, Enclosing_S);
3288 -- Mark the enclosing dynamic scope so that the sec stack will be
3289 -- released upon its exit unless this is a function that returns on
3290 -- the sec stack in which case this will be done by the caller.
3293 S := Enclosing_Dynamic_Scope (S);
3295 if Ekind (S) = E_Function
3296 and then Requires_Transient_Scope (Etype (S))
3300 Set_Uses_Sec_Stack (S);
3301 Check_Restriction (No_Secondary_Stack, N);
3304 end Wrap_Transient_Declaration;
3306 -------------------------------
3307 -- Wrap_Transient_Expression --
3308 -------------------------------
3310 -- Insert actions before <Expression>:
3312 -- (lines marked with <CTRL> are expanded only in presence of Controlled
3313 -- objects needing finalization)
3317 -- _M : constant Mark_Id := SS_Mark;
3318 -- Local_Final_List : System.FI.Finalizable_Ptr; <CTRL>
3320 -- procedure _Clean is
3323 -- System.FI.Finalize_List (Local_Final_List); <CTRL>
3329 -- _E := <Expression>;
3334 -- then expression is replaced by _E
3336 procedure Wrap_Transient_Expression (N : Node_Id) is
3337 Loc : constant Source_Ptr := Sloc (N);
3338 E : constant Entity_Id :=
3339 Make_Defining_Identifier (Loc, New_Internal_Name ('E'));
3340 Etyp : constant Entity_Id := Etype (N);
3343 Insert_Actions (N, New_List (
3344 Make_Object_Declaration (Loc,
3345 Defining_Identifier => E,
3346 Object_Definition => New_Reference_To (Etyp, Loc)),
3348 Make_Transient_Block (Loc,
3350 Make_Assignment_Statement (Loc,
3351 Name => New_Reference_To (E, Loc),
3352 Expression => Relocate_Node (N)))));
3354 Rewrite (N, New_Reference_To (E, Loc));
3355 Analyze_And_Resolve (N, Etyp);
3356 end Wrap_Transient_Expression;
3358 ------------------------------
3359 -- Wrap_Transient_Statement --
3360 ------------------------------
3362 -- Transform <Instruction> into
3364 -- (lines marked with <CTRL> are expanded only in presence of Controlled
3365 -- objects needing finalization)
3368 -- _M : Mark_Id := SS_Mark;
3369 -- Local_Final_List : System.FI.Finalizable_Ptr ; <CTRL>
3371 -- procedure _Clean is
3374 -- System.FI.Finalize_List (Local_Final_List); <CTRL>
3385 procedure Wrap_Transient_Statement (N : Node_Id) is
3386 Loc : constant Source_Ptr := Sloc (N);
3387 New_Statement : constant Node_Id := Relocate_Node (N);
3390 Rewrite (N, Make_Transient_Block (Loc, New_Statement));
3392 -- With the scope stack back to normal, we can call analyze on the
3393 -- resulting block. At this point, the transient scope is being
3394 -- treated like a perfectly normal scope, so there is nothing
3395 -- special about it.
3397 -- Note: Wrap_Transient_Statement is called with the node already
3398 -- analyzed (i.e. Analyzed (N) is True). This is important, since
3399 -- otherwise we would get a recursive processing of the node when
3400 -- we do this Analyze call.
3403 end Wrap_Transient_Statement;