1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Exp_Aggr; use Exp_Aggr;
32 with Exp_Ch4; use Exp_Ch4;
33 with Exp_Ch7; use Exp_Ch7;
34 with Exp_Ch9; use Exp_Ch9;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Disp; use Exp_Disp;
37 with Exp_Dist; use Exp_Dist;
38 with Exp_Smem; use Exp_Smem;
39 with Exp_Strm; use Exp_Strm;
40 with Exp_Tss; use Exp_Tss;
41 with Exp_Util; use Exp_Util;
42 with Freeze; use Freeze;
43 with Hostparm; use Hostparm;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Ch3; use Sem_Ch3;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Eval; use Sem_Eval;
55 with Sem_Mech; use Sem_Mech;
56 with Sem_Res; use Sem_Res;
57 with Sem_Util; use Sem_Util;
58 with Sinfo; use Sinfo;
59 with Stand; use Stand;
60 with Snames; use Snames;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Validsw; use Validsw;
65 package body Exp_Ch3 is
67 -----------------------
68 -- Local Subprograms --
69 -----------------------
71 procedure Adjust_Discriminants (Rtype : Entity_Id);
72 -- This is used when freezing a record type. It attempts to construct
73 -- more restrictive subtypes for discriminants so that the max size of
74 -- the record can be calculated more accurately. See the body of this
75 -- procedure for details.
77 procedure Build_Array_Init_Proc (A_Type : Entity_Id; Nod : Node_Id);
78 -- Build initialization procedure for given array type. Nod is a node
79 -- used for attachment of any actions required in its construction.
80 -- It also supplies the source location used for the procedure.
82 function Build_Discriminant_Formals
84 Use_Dl : Boolean) return List_Id;
85 -- This function uses the discriminants of a type to build a list of
86 -- formal parameters, used in the following function. If the flag Use_Dl
87 -- is set, the list is built using the already defined discriminals
88 -- of the type. Otherwise new identifiers are created, with the source
89 -- names of the discriminants.
91 procedure Build_Master_Renaming (N : Node_Id; T : Entity_Id);
92 -- If the designated type of an access type is a task type or contains
93 -- tasks, we make sure that a _Master variable is declared in the current
94 -- scope, and then declare a renaming for it:
96 -- atypeM : Master_Id renames _Master;
98 -- where atyp is the name of the access type. This declaration is
99 -- used when an allocator for the access type is expanded. The node N
100 -- is the full declaration of the designated type that contains tasks.
101 -- The renaming declaration is inserted before N, and after the Master
104 procedure Build_Record_Init_Proc (N : Node_Id; Pe : Entity_Id);
105 -- Build record initialization procedure. N is the type declaration
106 -- node, and Pe is the corresponding entity for the record type.
108 procedure Build_Slice_Assignment (Typ : Entity_Id);
109 -- Build assignment procedure for one-dimensional arrays of controlled
110 -- types. Other array and slice assignments are expanded in-line, but
111 -- the code expansion for controlled components (when control actions
112 -- are active) can lead to very large blocks that GCC3 handles poorly.
114 procedure Build_Variant_Record_Equality (Typ : Entity_Id);
115 -- Create An Equality function for the non-tagged variant record 'Typ'
116 -- and attach it to the TSS list
118 procedure Check_Stream_Attributes (Typ : Entity_Id);
119 -- Check that if a limited extension has a parent with user-defined
120 -- stream attributes, and does not itself have user-definer
121 -- stream-attributes, then any limited component of the extension also
122 -- has the corresponding user-defined stream attributes.
124 procedure Expand_Tagged_Root (T : Entity_Id);
125 -- Add a field _Tag at the beginning of the record. This field carries
126 -- the value of the access to the Dispatch table. This procedure is only
127 -- called on root (non CPP_Class) types, the _Tag field being inherited
128 -- by the descendants.
130 procedure Expand_Record_Controller (T : Entity_Id);
131 -- T must be a record type that Has_Controlled_Component. Add a field
132 -- _controller of type Record_Controller or Limited_Record_Controller
135 procedure Freeze_Array_Type (N : Node_Id);
136 -- Freeze an array type. Deals with building the initialization procedure,
137 -- creating the packed array type for a packed array and also with the
138 -- creation of the controlling procedures for the controlled case. The
139 -- argument N is the N_Freeze_Entity node for the type.
141 procedure Freeze_Enumeration_Type (N : Node_Id);
142 -- Freeze enumeration type with non-standard representation. Builds the
143 -- array and function needed to convert between enumeration pos and
144 -- enumeration representation values. N is the N_Freeze_Entity node
147 procedure Freeze_Record_Type (N : Node_Id);
148 -- Freeze record type. Builds all necessary discriminant checking
149 -- and other ancillary functions, and builds dispatch tables where
150 -- needed. The argument N is the N_Freeze_Entity node. This processing
151 -- applies only to E_Record_Type entities, not to class wide types,
152 -- record subtypes, or private types.
154 procedure Freeze_Stream_Operations (N : Node_Id; Typ : Entity_Id);
155 -- Treat user-defined stream operations as renaming_as_body if the
156 -- subprogram they rename is not frozen when the type is frozen.
158 function Init_Formals (Typ : Entity_Id) return List_Id;
159 -- This function builds the list of formals for an initialization routine.
160 -- The first formal is always _Init with the given type. For task value
161 -- record types and types containing tasks, three additional formals are
164 -- _Master : Master_Id
165 -- _Chain : in out Activation_Chain
166 -- _Task_Name : String
168 -- The caller must append additional entries for discriminants if required.
170 function In_Runtime (E : Entity_Id) return Boolean;
171 -- Check if E is defined in the RTL (in a child of Ada or System). Used
172 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
174 function Make_Eq_Case
177 Discr : Entity_Id := Empty) return List_Id;
178 -- Building block for variant record equality. Defined to share the
179 -- code between the tagged and non-tagged case. Given a Component_List
180 -- node CL, it generates an 'if' followed by a 'case' statement that
181 -- compares all components of local temporaries named X and Y (that
182 -- are declared as formals at some upper level). E provides the Sloc to be
183 -- used for the generated code. Discr is used as the case statement switch
184 -- in the case of Unchecked_Union equality.
188 L : List_Id) return Node_Id;
189 -- Building block for variant record equality. Defined to share the
190 -- code between the tagged and non-tagged case. Given the list of
191 -- components (or discriminants) L, it generates a return statement
192 -- that compares all components of local temporaries named X and Y
193 -- (that are declared as formals at some upper level). E provides the Sloc
194 -- to be used for the generated code.
196 procedure Make_Predefined_Primitive_Specs
197 (Tag_Typ : Entity_Id;
198 Predef_List : out List_Id;
199 Renamed_Eq : out Node_Id);
200 -- Create a list with the specs of the predefined primitive operations.
201 -- The following entries are present for all tagged types, and provide
202 -- the results of the corresponding attribute applied to the object.
203 -- Dispatching is required in general, since the result of the attribute
204 -- will vary with the actual object subtype.
206 -- _alignment provides result of 'Alignment attribute
207 -- _size provides result of 'Size attribute
208 -- typSR provides result of 'Read attribute
209 -- typSW provides result of 'Write attribute
210 -- typSI provides result of 'Input attribute
211 -- typSO provides result of 'Output attribute
213 -- The following entries are additionally present for non-limited
214 -- tagged types, and implement additional dispatching operations
215 -- for predefined operations:
217 -- _equality implements "=" operator
218 -- _assign implements assignment operation
219 -- typDF implements deep finalization
220 -- typDA implements deep adust
222 -- The latter two are empty procedures unless the type contains some
223 -- controlled components that require finalization actions (the deep
224 -- in the name refers to the fact that the action applies to components).
226 -- The list is returned in Predef_List. The Parameter Renamed_Eq
227 -- either returns the value Empty, or else the defining unit name
228 -- for the predefined equality function in the case where the type
229 -- has a primitive operation that is a renaming of predefined equality
230 -- (but only if there is also an overriding user-defined equality
231 -- function). The returned Renamed_Eq will be passed to the
232 -- corresponding parameter of Predefined_Primitive_Bodies.
234 function Has_New_Non_Standard_Rep (T : Entity_Id) return Boolean;
235 -- returns True if there are representation clauses for type T that
236 -- are not inherited. If the result is false, the init_proc and the
237 -- discriminant_checking functions of the parent can be reused by
240 function Predef_Spec_Or_Body
245 Ret_Type : Entity_Id := Empty;
246 For_Body : Boolean := False) return Node_Id;
247 -- This function generates the appropriate expansion for a predefined
248 -- primitive operation specified by its name, parameter profile and
249 -- return type (Empty means this is a procedure). If For_Body is false,
250 -- then the returned node is a subprogram declaration. If For_Body is
251 -- true, then the returned node is a empty subprogram body containing
252 -- no declarations and no statements.
254 function Predef_Stream_Attr_Spec
257 Name : TSS_Name_Type;
258 For_Body : Boolean := False) return Node_Id;
259 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
260 -- input and output attribute whose specs are constructed in Exp_Strm.
262 function Predef_Deep_Spec
265 Name : TSS_Name_Type;
266 For_Body : Boolean := False) return Node_Id;
267 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
268 -- and _deep_finalize
270 function Predefined_Primitive_Bodies
271 (Tag_Typ : Entity_Id;
272 Renamed_Eq : Node_Id) return List_Id;
273 -- Create the bodies of the predefined primitives that are described in
274 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
275 -- the defining unit name of the type's predefined equality as returned
276 -- by Make_Predefined_Primitive_Specs.
278 function Predefined_Primitive_Freeze (Tag_Typ : Entity_Id) return List_Id;
279 -- Freeze entities of all predefined primitive operations. This is needed
280 -- because the bodies of these operations do not normally do any freezeing.
282 function Stream_Operation_OK
284 Operation : TSS_Name_Type) return Boolean;
285 -- Check whether the named stream operation must be emitted for a given
286 -- type. The rules for inheritance of stream attributes by type extensions
287 -- are enforced by this function. Furthermore, various restrictions prevent
288 -- the generation of these operations, as a useful optimization or for
289 -- certification purposes.
291 --------------------------
292 -- Adjust_Discriminants --
293 --------------------------
295 -- This procedure attempts to define subtypes for discriminants that
296 -- are more restrictive than those declared. Such a replacement is
297 -- possible if we can demonstrate that values outside the restricted
298 -- range would cause constraint errors in any case. The advantage of
299 -- restricting the discriminant types in this way is tha the maximum
300 -- size of the variant record can be calculated more conservatively.
302 -- An example of a situation in which we can perform this type of
303 -- restriction is the following:
305 -- subtype B is range 1 .. 10;
306 -- type Q is array (B range <>) of Integer;
308 -- type V (N : Natural) is record
312 -- In this situation, we can restrict the upper bound of N to 10, since
313 -- any larger value would cause a constraint error in any case.
315 -- There are many situations in which such restriction is possible, but
316 -- for now, we just look for cases like the above, where the component
317 -- in question is a one dimensional array whose upper bound is one of
318 -- the record discriminants. Also the component must not be part of
319 -- any variant part, since then the component does not always exist.
321 procedure Adjust_Discriminants (Rtype : Entity_Id) is
322 Loc : constant Source_Ptr := Sloc (Rtype);
339 Comp := First_Component (Rtype);
340 while Present (Comp) loop
342 -- If our parent is a variant, quit, we do not look at components
343 -- that are in variant parts, because they may not always exist.
345 P := Parent (Comp); -- component declaration
346 P := Parent (P); -- component list
348 exit when Nkind (Parent (P)) = N_Variant;
350 -- We are looking for a one dimensional array type
352 Ctyp := Etype (Comp);
354 if not Is_Array_Type (Ctyp)
355 or else Number_Dimensions (Ctyp) > 1
360 -- The lower bound must be constant, and the upper bound is a
361 -- discriminant (which is a discriminant of the current record).
363 Ityp := Etype (First_Index (Ctyp));
364 Lo := Type_Low_Bound (Ityp);
365 Hi := Type_High_Bound (Ityp);
367 if not Compile_Time_Known_Value (Lo)
368 or else Nkind (Hi) /= N_Identifier
369 or else No (Entity (Hi))
370 or else Ekind (Entity (Hi)) /= E_Discriminant
375 -- We have an array with appropriate bounds
377 Loval := Expr_Value (Lo);
378 Discr := Entity (Hi);
379 Dtyp := Etype (Discr);
381 -- See if the discriminant has a known upper bound
383 Dhi := Type_High_Bound (Dtyp);
385 if not Compile_Time_Known_Value (Dhi) then
389 Dhiv := Expr_Value (Dhi);
391 -- See if base type of component array has known upper bound
393 Ahi := Type_High_Bound (Etype (First_Index (Base_Type (Ctyp))));
395 if not Compile_Time_Known_Value (Ahi) then
399 Ahiv := Expr_Value (Ahi);
401 -- The condition for doing the restriction is that the high bound
402 -- of the discriminant is greater than the low bound of the array,
403 -- and is also greater than the high bound of the base type index.
405 if Dhiv > Loval and then Dhiv > Ahiv then
407 -- We can reset the upper bound of the discriminant type to
408 -- whichever is larger, the low bound of the component, or
409 -- the high bound of the base type array index.
411 -- We build a subtype that is declared as
413 -- subtype Tnn is discr_type range discr_type'First .. max;
415 -- And insert this declaration into the tree. The type of the
416 -- discriminant is then reset to this more restricted subtype.
418 Tnn := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
420 Insert_Action (Declaration_Node (Rtype),
421 Make_Subtype_Declaration (Loc,
422 Defining_Identifier => Tnn,
423 Subtype_Indication =>
424 Make_Subtype_Indication (Loc,
425 Subtype_Mark => New_Occurrence_Of (Dtyp, Loc),
427 Make_Range_Constraint (Loc,
431 Make_Attribute_Reference (Loc,
432 Attribute_Name => Name_First,
433 Prefix => New_Occurrence_Of (Dtyp, Loc)),
435 Make_Integer_Literal (Loc,
436 Intval => UI_Max (Loval, Ahiv)))))));
438 Set_Etype (Discr, Tnn);
442 Next_Component (Comp);
444 end Adjust_Discriminants;
446 ---------------------------
447 -- Build_Array_Init_Proc --
448 ---------------------------
450 procedure Build_Array_Init_Proc (A_Type : Entity_Id; Nod : Node_Id) is
451 Loc : constant Source_Ptr := Sloc (Nod);
452 Comp_Type : constant Entity_Id := Component_Type (A_Type);
453 Index_List : List_Id;
455 Body_Stmts : List_Id;
457 function Init_Component return List_Id;
458 -- Create one statement to initialize one array component, designated
459 -- by a full set of indices.
461 function Init_One_Dimension (N : Int) return List_Id;
462 -- Create loop to initialize one dimension of the array. The single
463 -- statement in the loop body initializes the inner dimensions if any,
464 -- or else the single component. Note that this procedure is called
465 -- recursively, with N being the dimension to be initialized. A call
466 -- with N greater than the number of dimensions simply generates the
467 -- component initialization, terminating the recursion.
473 function Init_Component return List_Id is
478 Make_Indexed_Component (Loc,
479 Prefix => Make_Identifier (Loc, Name_uInit),
480 Expressions => Index_List);
482 if Needs_Simple_Initialization (Comp_Type) then
483 Set_Assignment_OK (Comp);
485 Make_Assignment_Statement (Loc,
489 (Comp_Type, Loc, Component_Size (A_Type))));
493 Build_Initialization_Call (Loc, Comp, Comp_Type, True, A_Type);
497 ------------------------
498 -- Init_One_Dimension --
499 ------------------------
501 function Init_One_Dimension (N : Int) return List_Id is
505 -- If the component does not need initializing, then there is nothing
506 -- to do here, so we return a null body. This occurs when generating
507 -- the dummy Init_Proc needed for Initialize_Scalars processing.
509 if not Has_Non_Null_Base_Init_Proc (Comp_Type)
510 and then not Needs_Simple_Initialization (Comp_Type)
511 and then not Has_Task (Comp_Type)
513 return New_List (Make_Null_Statement (Loc));
515 -- If all dimensions dealt with, we simply initialize the component
517 elsif N > Number_Dimensions (A_Type) then
518 return Init_Component;
520 -- Here we generate the required loop
524 Make_Defining_Identifier (Loc, New_External_Name ('J', N));
526 Append (New_Reference_To (Index, Loc), Index_List);
529 Make_Implicit_Loop_Statement (Nod,
532 Make_Iteration_Scheme (Loc,
533 Loop_Parameter_Specification =>
534 Make_Loop_Parameter_Specification (Loc,
535 Defining_Identifier => Index,
536 Discrete_Subtype_Definition =>
537 Make_Attribute_Reference (Loc,
538 Prefix => Make_Identifier (Loc, Name_uInit),
539 Attribute_Name => Name_Range,
540 Expressions => New_List (
541 Make_Integer_Literal (Loc, N))))),
542 Statements => Init_One_Dimension (N + 1)));
544 end Init_One_Dimension;
546 -- Start of processing for Build_Array_Init_Proc
549 if Suppress_Init_Proc (A_Type) then
553 Index_List := New_List;
555 -- We need an initialization procedure if any of the following is true:
557 -- 1. The component type has an initialization procedure
558 -- 2. The component type needs simple initialization
559 -- 3. Tasks are present
560 -- 4. The type is marked as a publc entity
562 -- The reason for the public entity test is to deal properly with the
563 -- Initialize_Scalars pragma. This pragma can be set in the client and
564 -- not in the declaring package, this means the client will make a call
565 -- to the initialization procedure (because one of conditions 1-3 must
566 -- apply in this case), and we must generate a procedure (even if it is
567 -- null) to satisfy the call in this case.
569 -- Exception: do not build an array init_proc for a type whose root
570 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
571 -- is no place to put the code, and in any case we handle initialization
572 -- of such types (in the Initialize_Scalars case, that's the only time
573 -- the issue arises) in a special manner anyway which does not need an
576 if Has_Non_Null_Base_Init_Proc (Comp_Type)
577 or else Needs_Simple_Initialization (Comp_Type)
578 or else Has_Task (Comp_Type)
579 or else (not Restriction_Active (No_Initialize_Scalars)
580 and then Is_Public (A_Type)
581 and then Root_Type (A_Type) /= Standard_String
582 and then Root_Type (A_Type) /= Standard_Wide_String
583 and then Root_Type (A_Type) /= Standard_Wide_Wide_String)
586 Make_Defining_Identifier (Loc, Make_Init_Proc_Name (A_Type));
588 Body_Stmts := Init_One_Dimension (1);
591 Make_Subprogram_Body (Loc,
593 Make_Procedure_Specification (Loc,
594 Defining_Unit_Name => Proc_Id,
595 Parameter_Specifications => Init_Formals (A_Type)),
596 Declarations => New_List,
597 Handled_Statement_Sequence =>
598 Make_Handled_Sequence_Of_Statements (Loc,
599 Statements => Body_Stmts)));
601 Set_Ekind (Proc_Id, E_Procedure);
602 Set_Is_Public (Proc_Id, Is_Public (A_Type));
603 Set_Is_Internal (Proc_Id);
604 Set_Has_Completion (Proc_Id);
606 if not Debug_Generated_Code then
607 Set_Debug_Info_Off (Proc_Id);
610 -- Set inlined unless controlled stuff or tasks around, in which
611 -- case we do not want to inline, because nested stuff may cause
612 -- difficulties in interunit inlining, and furthermore there is
613 -- in any case no point in inlining such complex init procs.
615 if not Has_Task (Proc_Id)
616 and then not Controlled_Type (Proc_Id)
618 Set_Is_Inlined (Proc_Id);
621 -- Associate Init_Proc with type, and determine if the procedure
622 -- is null (happens because of the Initialize_Scalars pragma case,
623 -- where we have to generate a null procedure in case it is called
624 -- by a client with Initialize_Scalars set). Such procedures have
625 -- to be generated, but do not have to be called, so we mark them
626 -- as null to suppress the call.
628 Set_Init_Proc (A_Type, Proc_Id);
630 if List_Length (Body_Stmts) = 1
631 and then Nkind (First (Body_Stmts)) = N_Null_Statement
633 Set_Is_Null_Init_Proc (Proc_Id);
636 end Build_Array_Init_Proc;
638 -----------------------------
639 -- Build_Class_Wide_Master --
640 -----------------------------
642 procedure Build_Class_Wide_Master (T : Entity_Id) is
643 Loc : constant Source_Ptr := Sloc (T);
650 -- Nothing to do if there is no task hierarchy
652 if Restriction_Active (No_Task_Hierarchy) then
656 -- Find declaration that created the access type: either a
657 -- type declaration, or an object declaration with an
658 -- access definition, in which case the type is anonymous.
661 P := Associated_Node_For_Itype (T);
666 -- Nothing to do if we already built a master entity for this scope
668 if not Has_Master_Entity (Scope (T)) then
670 -- first build the master entity
671 -- _Master : constant Master_Id := Current_Master.all;
672 -- and insert it just before the current declaration
675 Make_Object_Declaration (Loc,
676 Defining_Identifier =>
677 Make_Defining_Identifier (Loc, Name_uMaster),
678 Constant_Present => True,
679 Object_Definition => New_Reference_To (Standard_Integer, Loc),
681 Make_Explicit_Dereference (Loc,
682 New_Reference_To (RTE (RE_Current_Master), Loc)));
684 Insert_Before (P, Decl);
686 Set_Has_Master_Entity (Scope (T));
688 -- Now mark the containing scope as a task master
691 while Nkind (Par) /= N_Compilation_Unit loop
694 -- If we fall off the top, we are at the outer level, and the
695 -- environment task is our effective master, so nothing to mark.
697 if Nkind (Par) = N_Task_Body
698 or else Nkind (Par) = N_Block_Statement
699 or else Nkind (Par) = N_Subprogram_Body
701 Set_Is_Task_Master (Par, True);
707 -- Now define the renaming of the master_id
710 Make_Defining_Identifier (Loc,
711 New_External_Name (Chars (T), 'M'));
714 Make_Object_Renaming_Declaration (Loc,
715 Defining_Identifier => M_Id,
716 Subtype_Mark => New_Reference_To (Standard_Integer, Loc),
717 Name => Make_Identifier (Loc, Name_uMaster));
718 Insert_Before (P, Decl);
721 Set_Master_Id (T, M_Id);
724 when RE_Not_Available =>
726 end Build_Class_Wide_Master;
728 --------------------------------
729 -- Build_Discr_Checking_Funcs --
730 --------------------------------
732 procedure Build_Discr_Checking_Funcs (N : Node_Id) is
735 Enclosing_Func_Id : Entity_Id;
740 function Build_Case_Statement
741 (Case_Id : Entity_Id;
742 Variant : Node_Id) return Node_Id;
743 -- Build a case statement containing only two alternatives. The
744 -- first alternative corresponds exactly to the discrete choices
745 -- given on the variant with contains the components that we are
746 -- generating the checks for. If the discriminant is one of these
747 -- return False. The second alternative is an OTHERS choice that
748 -- will return True indicating the discriminant did not match.
750 function Build_Dcheck_Function
751 (Case_Id : Entity_Id;
752 Variant : Node_Id) return Entity_Id;
753 -- Build the discriminant checking function for a given variant
755 procedure Build_Dcheck_Functions (Variant_Part_Node : Node_Id);
756 -- Builds the discriminant checking function for each variant of the
757 -- given variant part of the record type.
759 --------------------------
760 -- Build_Case_Statement --
761 --------------------------
763 function Build_Case_Statement
764 (Case_Id : Entity_Id;
765 Variant : Node_Id) return Node_Id
767 Alt_List : constant List_Id := New_List;
768 Actuals_List : List_Id;
770 Case_Alt_Node : Node_Id;
772 Choice_List : List_Id;
774 Return_Node : Node_Id;
777 Case_Node := New_Node (N_Case_Statement, Loc);
779 -- Replace the discriminant which controls the variant, with the
780 -- name of the formal of the checking function.
782 Set_Expression (Case_Node,
783 Make_Identifier (Loc, Chars (Case_Id)));
785 Choice := First (Discrete_Choices (Variant));
787 if Nkind (Choice) = N_Others_Choice then
788 Choice_List := New_Copy_List (Others_Discrete_Choices (Choice));
790 Choice_List := New_Copy_List (Discrete_Choices (Variant));
793 if not Is_Empty_List (Choice_List) then
794 Case_Alt_Node := New_Node (N_Case_Statement_Alternative, Loc);
795 Set_Discrete_Choices (Case_Alt_Node, Choice_List);
797 -- In case this is a nested variant, we need to return the result
798 -- of the discriminant checking function for the immediately
799 -- enclosing variant.
801 if Present (Enclosing_Func_Id) then
802 Actuals_List := New_List;
804 D := First_Discriminant (Rec_Id);
805 while Present (D) loop
806 Append (Make_Identifier (Loc, Chars (D)), Actuals_List);
807 Next_Discriminant (D);
811 Make_Return_Statement (Loc,
813 Make_Function_Call (Loc,
815 New_Reference_To (Enclosing_Func_Id, Loc),
816 Parameter_Associations =>
821 Make_Return_Statement (Loc,
823 New_Reference_To (Standard_False, Loc));
826 Set_Statements (Case_Alt_Node, New_List (Return_Node));
827 Append (Case_Alt_Node, Alt_List);
830 Case_Alt_Node := New_Node (N_Case_Statement_Alternative, Loc);
831 Choice_List := New_List (New_Node (N_Others_Choice, Loc));
832 Set_Discrete_Choices (Case_Alt_Node, Choice_List);
835 Make_Return_Statement (Loc,
837 New_Reference_To (Standard_True, Loc));
839 Set_Statements (Case_Alt_Node, New_List (Return_Node));
840 Append (Case_Alt_Node, Alt_List);
842 Set_Alternatives (Case_Node, Alt_List);
844 end Build_Case_Statement;
846 ---------------------------
847 -- Build_Dcheck_Function --
848 ---------------------------
850 function Build_Dcheck_Function
851 (Case_Id : Entity_Id;
852 Variant : Node_Id) return Entity_Id
856 Parameter_List : List_Id;
860 Body_Node := New_Node (N_Subprogram_Body, Loc);
861 Sequence := Sequence + 1;
864 Make_Defining_Identifier (Loc,
865 Chars => New_External_Name (Chars (Rec_Id), 'D', Sequence));
867 Spec_Node := New_Node (N_Function_Specification, Loc);
868 Set_Defining_Unit_Name (Spec_Node, Func_Id);
870 Parameter_List := Build_Discriminant_Formals (Rec_Id, False);
872 Set_Parameter_Specifications (Spec_Node, Parameter_List);
873 Set_Result_Definition (Spec_Node,
874 New_Reference_To (Standard_Boolean, Loc));
875 Set_Specification (Body_Node, Spec_Node);
876 Set_Declarations (Body_Node, New_List);
878 Set_Handled_Statement_Sequence (Body_Node,
879 Make_Handled_Sequence_Of_Statements (Loc,
880 Statements => New_List (
881 Build_Case_Statement (Case_Id, Variant))));
883 Set_Ekind (Func_Id, E_Function);
884 Set_Mechanism (Func_Id, Default_Mechanism);
885 Set_Is_Inlined (Func_Id, True);
886 Set_Is_Pure (Func_Id, True);
887 Set_Is_Public (Func_Id, Is_Public (Rec_Id));
888 Set_Is_Internal (Func_Id, True);
890 if not Debug_Generated_Code then
891 Set_Debug_Info_Off (Func_Id);
896 Append_Freeze_Action (Rec_Id, Body_Node);
897 Set_Dcheck_Function (Variant, Func_Id);
899 end Build_Dcheck_Function;
901 ----------------------------
902 -- Build_Dcheck_Functions --
903 ----------------------------
905 procedure Build_Dcheck_Functions (Variant_Part_Node : Node_Id) is
906 Component_List_Node : Node_Id;
908 Discr_Name : Entity_Id;
911 Saved_Enclosing_Func_Id : Entity_Id;
914 -- Build the discriminant checking function for each variant, label
915 -- all components of that variant with the function's name.
917 Discr_Name := Entity (Name (Variant_Part_Node));
918 Variant := First_Non_Pragma (Variants (Variant_Part_Node));
920 while Present (Variant) loop
921 Func_Id := Build_Dcheck_Function (Discr_Name, Variant);
922 Component_List_Node := Component_List (Variant);
924 if not Null_Present (Component_List_Node) then
926 First_Non_Pragma (Component_Items (Component_List_Node));
928 while Present (Decl) loop
929 Set_Discriminant_Checking_Func
930 (Defining_Identifier (Decl), Func_Id);
932 Next_Non_Pragma (Decl);
935 if Present (Variant_Part (Component_List_Node)) then
936 Saved_Enclosing_Func_Id := Enclosing_Func_Id;
937 Enclosing_Func_Id := Func_Id;
938 Build_Dcheck_Functions (Variant_Part (Component_List_Node));
939 Enclosing_Func_Id := Saved_Enclosing_Func_Id;
943 Next_Non_Pragma (Variant);
945 end Build_Dcheck_Functions;
947 -- Start of processing for Build_Discr_Checking_Funcs
950 -- Only build if not done already
952 if not Discr_Check_Funcs_Built (N) then
953 Type_Def := Type_Definition (N);
955 if Nkind (Type_Def) = N_Record_Definition then
956 if No (Component_List (Type_Def)) then -- null record.
959 V := Variant_Part (Component_List (Type_Def));
962 else pragma Assert (Nkind (Type_Def) = N_Derived_Type_Definition);
963 if No (Component_List (Record_Extension_Part (Type_Def))) then
967 (Component_List (Record_Extension_Part (Type_Def)));
971 Rec_Id := Defining_Identifier (N);
973 if Present (V) and then not Is_Unchecked_Union (Rec_Id) then
975 Enclosing_Func_Id := Empty;
976 Build_Dcheck_Functions (V);
979 Set_Discr_Check_Funcs_Built (N);
981 end Build_Discr_Checking_Funcs;
983 --------------------------------
984 -- Build_Discriminant_Formals --
985 --------------------------------
987 function Build_Discriminant_Formals
989 Use_Dl : Boolean) return List_Id
991 Loc : Source_Ptr := Sloc (Rec_Id);
992 Parameter_List : constant List_Id := New_List;
995 Param_Spec_Node : Node_Id;
998 if Has_Discriminants (Rec_Id) then
999 D := First_Discriminant (Rec_Id);
1000 while Present (D) loop
1004 Formal := Discriminal (D);
1006 Formal := Make_Defining_Identifier (Loc, Chars (D));
1010 Make_Parameter_Specification (Loc,
1011 Defining_Identifier => Formal,
1013 New_Reference_To (Etype (D), Loc));
1014 Append (Param_Spec_Node, Parameter_List);
1015 Next_Discriminant (D);
1019 return Parameter_List;
1020 end Build_Discriminant_Formals;
1022 -------------------------------
1023 -- Build_Initialization_Call --
1024 -------------------------------
1026 -- References to a discriminant inside the record type declaration
1027 -- can appear either in the subtype_indication to constrain a
1028 -- record or an array, or as part of a larger expression given for
1029 -- the initial value of a component. In both of these cases N appears
1030 -- in the record initialization procedure and needs to be replaced by
1031 -- the formal parameter of the initialization procedure which
1032 -- corresponds to that discriminant.
1034 -- In the example below, references to discriminants D1 and D2 in proc_1
1035 -- are replaced by references to formals with the same name
1038 -- A similar replacement is done for calls to any record
1039 -- initialization procedure for any components that are themselves
1040 -- of a record type.
1042 -- type R (D1, D2 : Integer) is record
1043 -- X : Integer := F * D1;
1044 -- Y : Integer := F * D2;
1047 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1051 -- Out_2.X := F * D1;
1052 -- Out_2.Y := F * D2;
1055 function Build_Initialization_Call
1059 In_Init_Proc : Boolean := False;
1060 Enclos_Type : Entity_Id := Empty;
1061 Discr_Map : Elist_Id := New_Elmt_List;
1062 With_Default_Init : Boolean := False) return List_Id
1064 First_Arg : Node_Id;
1070 Proc : constant Entity_Id := Base_Init_Proc (Typ);
1071 Init_Type : constant Entity_Id := Etype (First_Formal (Proc));
1072 Full_Init_Type : constant Entity_Id := Underlying_Type (Init_Type);
1073 Res : constant List_Id := New_List;
1074 Full_Type : Entity_Id := Typ;
1075 Controller_Typ : Entity_Id;
1078 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1079 -- is active (in which case we make the call anyway, since in the
1080 -- actual compiled client it may be non null).
1082 if Is_Null_Init_Proc (Proc) and then not Init_Or_Norm_Scalars then
1086 -- Go to full view if private type. In the case of successive
1087 -- private derivations, this can require more than one step.
1089 while Is_Private_Type (Full_Type)
1090 and then Present (Full_View (Full_Type))
1092 Full_Type := Full_View (Full_Type);
1095 -- If Typ is derived, the procedure is the initialization procedure for
1096 -- the root type. Wrap the argument in an conversion to make it type
1097 -- honest. Actually it isn't quite type honest, because there can be
1098 -- conflicts of views in the private type case. That is why we set
1099 -- Conversion_OK in the conversion node.
1100 if (Is_Record_Type (Typ)
1101 or else Is_Array_Type (Typ)
1102 or else Is_Private_Type (Typ))
1103 and then Init_Type /= Base_Type (Typ)
1105 First_Arg := OK_Convert_To (Etype (Init_Type), Id_Ref);
1106 Set_Etype (First_Arg, Init_Type);
1109 First_Arg := Id_Ref;
1112 Args := New_List (Convert_Concurrent (First_Arg, Typ));
1114 -- In the tasks case, add _Master as the value of the _Master parameter
1115 -- and _Chain as the value of the _Chain parameter. At the outer level,
1116 -- these will be variables holding the corresponding values obtained
1117 -- from GNARL. At inner levels, they will be the parameters passed down
1118 -- through the outer routines.
1120 if Has_Task (Full_Type) then
1121 if Restriction_Active (No_Task_Hierarchy) then
1123 -- See comments in System.Tasking.Initialization.Init_RTS
1124 -- for the value 3 (should be rtsfindable constant ???)
1126 Append_To (Args, Make_Integer_Literal (Loc, 3));
1128 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
1131 Append_To (Args, Make_Identifier (Loc, Name_uChain));
1133 -- Ada 2005 (AI-287): In case of default initialized components
1134 -- with tasks, we generate a null string actual parameter.
1135 -- This is just a workaround that must be improved later???
1137 if With_Default_Init then
1139 Make_String_Literal (Loc,
1143 Decls := Build_Task_Image_Decls (Loc, Id_Ref, Enclos_Type);
1144 Decl := Last (Decls);
1147 New_Occurrence_Of (Defining_Identifier (Decl), Loc));
1148 Append_List (Decls, Res);
1156 -- Add discriminant values if discriminants are present
1158 if Has_Discriminants (Full_Init_Type) then
1159 Discr := First_Discriminant (Full_Init_Type);
1161 while Present (Discr) loop
1163 -- If this is a discriminated concurrent type, the init_proc
1164 -- for the corresponding record is being called. Use that
1165 -- type directly to find the discriminant value, to handle
1166 -- properly intervening renamed discriminants.
1169 T : Entity_Id := Full_Type;
1172 if Is_Protected_Type (T) then
1173 T := Corresponding_Record_Type (T);
1175 elsif Is_Private_Type (T)
1176 and then Present (Underlying_Full_View (T))
1177 and then Is_Protected_Type (Underlying_Full_View (T))
1179 T := Corresponding_Record_Type (Underlying_Full_View (T));
1183 Get_Discriminant_Value (
1186 Discriminant_Constraint (Full_Type));
1189 if In_Init_Proc then
1191 -- Replace any possible references to the discriminant in the
1192 -- call to the record initialization procedure with references
1193 -- to the appropriate formal parameter.
1195 if Nkind (Arg) = N_Identifier
1196 and then Ekind (Entity (Arg)) = E_Discriminant
1198 Arg := New_Reference_To (Discriminal (Entity (Arg)), Loc);
1200 -- Case of access discriminants. We replace the reference
1201 -- to the type by a reference to the actual object
1203 elsif Nkind (Arg) = N_Attribute_Reference
1204 and then Is_Access_Type (Etype (Arg))
1205 and then Is_Entity_Name (Prefix (Arg))
1206 and then Is_Type (Entity (Prefix (Arg)))
1209 Make_Attribute_Reference (Loc,
1210 Prefix => New_Copy (Prefix (Id_Ref)),
1211 Attribute_Name => Name_Unrestricted_Access);
1213 -- Otherwise make a copy of the default expression. Note
1214 -- that we use the current Sloc for this, because we do not
1215 -- want the call to appear to be at the declaration point.
1216 -- Within the expression, replace discriminants with their
1221 New_Copy_Tree (Arg, Map => Discr_Map, New_Sloc => Loc);
1225 if Is_Constrained (Full_Type) then
1226 Arg := Duplicate_Subexpr_No_Checks (Arg);
1228 -- The constraints come from the discriminant default
1229 -- exps, they must be reevaluated, so we use New_Copy_Tree
1230 -- but we ensure the proper Sloc (for any embedded calls).
1232 Arg := New_Copy_Tree (Arg, New_Sloc => Loc);
1236 -- Ada 2005 (AI-287) In case of default initialized components,
1237 -- we need to generate the corresponding selected component node
1238 -- to access the discriminant value. In other cases this is not
1239 -- required because we are inside the init proc and we use the
1240 -- corresponding formal.
1242 if With_Default_Init
1243 and then Nkind (Id_Ref) = N_Selected_Component
1246 Make_Selected_Component (Loc,
1247 Prefix => New_Copy_Tree (Prefix (Id_Ref)),
1248 Selector_Name => Arg));
1250 Append_To (Args, Arg);
1253 Next_Discriminant (Discr);
1257 -- If this is a call to initialize the parent component of a derived
1258 -- tagged type, indicate that the tag should not be set in the parent.
1260 if Is_Tagged_Type (Full_Init_Type)
1261 and then not Is_CPP_Class (Full_Init_Type)
1262 and then Nkind (Id_Ref) = N_Selected_Component
1263 and then Chars (Selector_Name (Id_Ref)) = Name_uParent
1265 Append_To (Args, New_Occurrence_Of (Standard_False, Loc));
1269 Make_Procedure_Call_Statement (Loc,
1270 Name => New_Occurrence_Of (Proc, Loc),
1271 Parameter_Associations => Args));
1273 if Controlled_Type (Typ)
1274 and then Nkind (Id_Ref) = N_Selected_Component
1276 if Chars (Selector_Name (Id_Ref)) /= Name_uParent then
1277 Append_List_To (Res,
1279 Ref => New_Copy_Tree (First_Arg),
1282 Find_Final_List (Typ, New_Copy_Tree (First_Arg)),
1283 With_Attach => Make_Integer_Literal (Loc, 1)));
1285 -- If the enclosing type is an extension with new controlled
1286 -- components, it has his own record controller. If the parent
1287 -- also had a record controller, attach it to the new one.
1288 -- Build_Init_Statements relies on the fact that in this specific
1289 -- case the last statement of the result is the attach call to
1290 -- the controller. If this is changed, it must be synchronized.
1292 elsif Present (Enclos_Type)
1293 and then Has_New_Controlled_Component (Enclos_Type)
1294 and then Has_Controlled_Component (Typ)
1296 if Is_Return_By_Reference_Type (Typ) then
1297 Controller_Typ := RTE (RE_Limited_Record_Controller);
1299 Controller_Typ := RTE (RE_Record_Controller);
1302 Append_List_To (Res,
1305 Make_Selected_Component (Loc,
1306 Prefix => New_Copy_Tree (First_Arg),
1307 Selector_Name => Make_Identifier (Loc, Name_uController)),
1308 Typ => Controller_Typ,
1309 Flist_Ref => Find_Final_List (Typ, New_Copy_Tree (First_Arg)),
1310 With_Attach => Make_Integer_Literal (Loc, 1)));
1317 when RE_Not_Available =>
1319 end Build_Initialization_Call;
1321 ---------------------------
1322 -- Build_Master_Renaming --
1323 ---------------------------
1325 procedure Build_Master_Renaming (N : Node_Id; T : Entity_Id) is
1326 Loc : constant Source_Ptr := Sloc (N);
1331 -- Nothing to do if there is no task hierarchy
1333 if Restriction_Active (No_Task_Hierarchy) then
1338 Make_Defining_Identifier (Loc,
1339 New_External_Name (Chars (T), 'M'));
1342 Make_Object_Renaming_Declaration (Loc,
1343 Defining_Identifier => M_Id,
1344 Subtype_Mark => New_Reference_To (RTE (RE_Master_Id), Loc),
1345 Name => Make_Identifier (Loc, Name_uMaster));
1346 Insert_Before (N, Decl);
1349 Set_Master_Id (T, M_Id);
1352 when RE_Not_Available =>
1354 end Build_Master_Renaming;
1356 ----------------------------
1357 -- Build_Record_Init_Proc --
1358 ----------------------------
1360 procedure Build_Record_Init_Proc (N : Node_Id; Pe : Entity_Id) is
1361 Loc : Source_Ptr := Sloc (N);
1362 Discr_Map : constant Elist_Id := New_Elmt_List;
1363 Proc_Id : Entity_Id;
1364 Rec_Type : Entity_Id;
1365 Set_Tag : Entity_Id := Empty;
1367 function Build_Assignment (Id : Entity_Id; N : Node_Id) return List_Id;
1368 -- Build a assignment statement node which assigns to record
1369 -- component its default expression if defined. The left hand side
1370 -- of the assignment is marked Assignment_OK so that initialization
1371 -- of limited private records works correctly, Return also the
1372 -- adjustment call for controlled objects
1374 procedure Build_Discriminant_Assignments (Statement_List : List_Id);
1375 -- If the record has discriminants, adds assignment statements to
1376 -- statement list to initialize the discriminant values from the
1377 -- arguments of the initialization procedure.
1379 function Build_Init_Statements (Comp_List : Node_Id) return List_Id;
1380 -- Build a list representing a sequence of statements which initialize
1381 -- components of the given component list. This may involve building
1382 -- case statements for the variant parts.
1384 function Build_Init_Call_Thru (Parameters : List_Id) return List_Id;
1385 -- Given a non-tagged type-derivation that declares discriminants,
1388 -- type R (R1, R2 : Integer) is record ... end record;
1390 -- type D (D1 : Integer) is new R (1, D1);
1392 -- we make the _init_proc of D be
1394 -- procedure _init_proc(X : D; D1 : Integer) is
1396 -- _init_proc( R(X), 1, D1);
1399 -- This function builds the call statement in this _init_proc.
1401 procedure Build_Init_Procedure;
1402 -- Build the tree corresponding to the procedure specification and body
1403 -- of the initialization procedure (by calling all the preceding
1404 -- auxiliary routines), and install it as the _init TSS.
1406 procedure Build_Record_Checks (S : Node_Id; Check_List : List_Id);
1407 -- Add range checks to components of disciminated records. S is a
1408 -- subtype indication of a record component. Check_List is a list
1409 -- to which the check actions are appended.
1411 function Component_Needs_Simple_Initialization
1412 (T : Entity_Id) return Boolean;
1413 -- Determines if a component needs simple initialization, given its type
1414 -- T. This is the same as Needs_Simple_Initialization except for the
1415 -- following difference: the types Tag, Interface_Tag, and Vtable_Ptr
1416 -- which are access types which would normally require simple
1417 -- initialization to null, do not require initialization as components,
1418 -- since they are explicitly initialized by other means.
1420 procedure Constrain_Array
1422 Check_List : List_Id);
1423 -- Called from Build_Record_Checks.
1424 -- Apply a list of index constraints to an unconstrained array type.
1425 -- The first parameter is the entity for the resulting subtype.
1426 -- Check_List is a list to which the check actions are appended.
1428 procedure Constrain_Index
1431 Check_List : List_Id);
1432 -- Called from Build_Record_Checks.
1433 -- Process an index constraint in a constrained array declaration.
1434 -- The constraint can be a subtype name, or a range with or without
1435 -- an explicit subtype mark. The index is the corresponding index of the
1436 -- unconstrained array. S is the range expression. Check_List is a list
1437 -- to which the check actions are appended.
1439 function Parent_Subtype_Renaming_Discrims return Boolean;
1440 -- Returns True for base types N that rename discriminants, else False
1442 function Requires_Init_Proc (Rec_Id : Entity_Id) return Boolean;
1443 -- Determines whether a record initialization procedure needs to be
1444 -- generated for the given record type.
1446 ----------------------
1447 -- Build_Assignment --
1448 ----------------------
1450 function Build_Assignment (Id : Entity_Id; N : Node_Id) return List_Id is
1453 Typ : constant Entity_Id := Underlying_Type (Etype (Id));
1454 Kind : Node_Kind := Nkind (N);
1460 Make_Selected_Component (Loc,
1461 Prefix => Make_Identifier (Loc, Name_uInit),
1462 Selector_Name => New_Occurrence_Of (Id, Loc));
1463 Set_Assignment_OK (Lhs);
1465 -- Case of an access attribute applied to the current instance.
1466 -- Replace the reference to the type by a reference to the actual
1467 -- object. (Note that this handles the case of the top level of
1468 -- the expression being given by such an attribute, but does not
1469 -- cover uses nested within an initial value expression. Nested
1470 -- uses are unlikely to occur in practice, but are theoretically
1471 -- possible. It is not clear how to handle them without fully
1472 -- traversing the expression. ???
1474 if Kind = N_Attribute_Reference
1475 and then (Attribute_Name (N) = Name_Unchecked_Access
1477 Attribute_Name (N) = Name_Unrestricted_Access)
1478 and then Is_Entity_Name (Prefix (N))
1479 and then Is_Type (Entity (Prefix (N)))
1480 and then Entity (Prefix (N)) = Rec_Type
1483 Make_Attribute_Reference (Loc,
1484 Prefix => Make_Identifier (Loc, Name_uInit),
1485 Attribute_Name => Name_Unrestricted_Access);
1488 -- Ada 2005 (AI-231): Add the run-time check if required
1490 if Ada_Version >= Ada_05
1491 and then Can_Never_Be_Null (Etype (Id)) -- Lhs
1493 if Nkind (Exp) = N_Null then
1495 Make_Raise_Constraint_Error (Sloc (Exp),
1496 Reason => CE_Null_Not_Allowed));
1498 elsif Present (Etype (Exp))
1499 and then not Can_Never_Be_Null (Etype (Exp))
1501 Install_Null_Excluding_Check (Exp);
1505 -- Take a copy of Exp to ensure that later copies of this
1506 -- component_declaration in derived types see the original tree,
1507 -- not a node rewritten during expansion of the init_proc.
1509 Exp := New_Copy_Tree (Exp);
1512 Make_Assignment_Statement (Loc,
1514 Expression => Exp));
1516 Set_No_Ctrl_Actions (First (Res));
1518 -- Adjust the tag if tagged (because of possible view conversions).
1519 -- Suppress the tag adjustment when Java_VM because JVM tags are
1520 -- represented implicitly in objects.
1522 if Is_Tagged_Type (Typ) and then not Java_VM then
1524 Make_Assignment_Statement (Loc,
1526 Make_Selected_Component (Loc,
1527 Prefix => New_Copy_Tree (Lhs),
1529 New_Reference_To (First_Tag_Component (Typ), Loc)),
1532 Unchecked_Convert_To (RTE (RE_Tag),
1534 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc))));
1537 -- Adjust the component if controlled except if it is an
1538 -- aggregate that will be expanded inline
1540 if Kind = N_Qualified_Expression then
1541 Kind := Nkind (Expression (N));
1544 if Controlled_Type (Typ)
1545 and then not (Kind = N_Aggregate or else Kind = N_Extension_Aggregate)
1547 Append_List_To (Res,
1549 Ref => New_Copy_Tree (Lhs),
1552 Find_Final_List (Etype (Id), New_Copy_Tree (Lhs)),
1553 With_Attach => Make_Integer_Literal (Loc, 1)));
1559 when RE_Not_Available =>
1561 end Build_Assignment;
1563 ------------------------------------
1564 -- Build_Discriminant_Assignments --
1565 ------------------------------------
1567 procedure Build_Discriminant_Assignments (Statement_List : List_Id) is
1569 Is_Tagged : constant Boolean := Is_Tagged_Type (Rec_Type);
1572 if Has_Discriminants (Rec_Type)
1573 and then not Is_Unchecked_Union (Rec_Type)
1575 D := First_Discriminant (Rec_Type);
1577 while Present (D) loop
1578 -- Don't generate the assignment for discriminants in derived
1579 -- tagged types if the discriminant is a renaming of some
1580 -- ancestor discriminant. This initialization will be done
1581 -- when initializing the _parent field of the derived record.
1583 if Is_Tagged and then
1584 Present (Corresponding_Discriminant (D))
1590 Append_List_To (Statement_List,
1591 Build_Assignment (D,
1592 New_Reference_To (Discriminal (D), Loc)));
1595 Next_Discriminant (D);
1598 end Build_Discriminant_Assignments;
1600 --------------------------
1601 -- Build_Init_Call_Thru --
1602 --------------------------
1604 function Build_Init_Call_Thru (Parameters : List_Id) return List_Id is
1605 Parent_Proc : constant Entity_Id :=
1606 Base_Init_Proc (Etype (Rec_Type));
1608 Parent_Type : constant Entity_Id :=
1609 Etype (First_Formal (Parent_Proc));
1611 Uparent_Type : constant Entity_Id :=
1612 Underlying_Type (Parent_Type);
1614 First_Discr_Param : Node_Id;
1616 Parent_Discr : Entity_Id;
1617 First_Arg : Node_Id;
1623 -- First argument (_Init) is the object to be initialized.
1624 -- ??? not sure where to get a reasonable Loc for First_Arg
1627 OK_Convert_To (Parent_Type,
1628 New_Reference_To (Defining_Identifier (First (Parameters)), Loc));
1630 Set_Etype (First_Arg, Parent_Type);
1632 Args := New_List (Convert_Concurrent (First_Arg, Rec_Type));
1634 -- In the tasks case,
1635 -- add _Master as the value of the _Master parameter
1636 -- add _Chain as the value of the _Chain parameter.
1637 -- add _Task_Name as the value of the _Task_Name parameter.
1638 -- At the outer level, these will be variables holding the
1639 -- corresponding values obtained from GNARL or the expander.
1641 -- At inner levels, they will be the parameters passed down through
1642 -- the outer routines.
1644 First_Discr_Param := Next (First (Parameters));
1646 if Has_Task (Rec_Type) then
1647 if Restriction_Active (No_Task_Hierarchy) then
1649 -- See comments in System.Tasking.Initialization.Init_RTS
1652 Append_To (Args, Make_Integer_Literal (Loc, 3));
1654 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
1657 Append_To (Args, Make_Identifier (Loc, Name_uChain));
1658 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
1659 First_Discr_Param := Next (Next (Next (First_Discr_Param)));
1662 -- Append discriminant values
1664 if Has_Discriminants (Uparent_Type) then
1665 pragma Assert (not Is_Tagged_Type (Uparent_Type));
1667 Parent_Discr := First_Discriminant (Uparent_Type);
1668 while Present (Parent_Discr) loop
1670 -- Get the initial value for this discriminant
1671 -- ??? needs to be cleaned up to use parent_Discr_Constr
1675 Discr_Value : Elmt_Id :=
1677 (Stored_Constraint (Rec_Type));
1679 Discr : Entity_Id :=
1680 First_Stored_Discriminant (Uparent_Type);
1682 while Original_Record_Component (Parent_Discr) /= Discr loop
1683 Next_Stored_Discriminant (Discr);
1684 Next_Elmt (Discr_Value);
1687 Arg := Node (Discr_Value);
1690 -- Append it to the list
1692 if Nkind (Arg) = N_Identifier
1693 and then Ekind (Entity (Arg)) = E_Discriminant
1696 New_Reference_To (Discriminal (Entity (Arg)), Loc));
1698 -- Case of access discriminants. We replace the reference
1699 -- to the type by a reference to the actual object
1701 -- ??? why is this code deleted without comment
1703 -- elsif Nkind (Arg) = N_Attribute_Reference
1704 -- and then Is_Entity_Name (Prefix (Arg))
1705 -- and then Is_Type (Entity (Prefix (Arg)))
1708 -- Make_Attribute_Reference (Loc,
1709 -- Prefix => New_Copy (Prefix (Id_Ref)),
1710 -- Attribute_Name => Name_Unrestricted_Access));
1713 Append_To (Args, New_Copy (Arg));
1716 Next_Discriminant (Parent_Discr);
1722 Make_Procedure_Call_Statement (Loc,
1723 Name => New_Occurrence_Of (Parent_Proc, Loc),
1724 Parameter_Associations => Args));
1727 end Build_Init_Call_Thru;
1729 --------------------------
1730 -- Build_Init_Procedure --
1731 --------------------------
1733 procedure Build_Init_Procedure is
1734 Body_Node : Node_Id;
1735 Handled_Stmt_Node : Node_Id;
1736 Parameters : List_Id;
1737 Proc_Spec_Node : Node_Id;
1738 Body_Stmts : List_Id;
1739 Record_Extension_Node : Node_Id;
1742 procedure Init_Secondary_Tags (Typ : Entity_Id);
1743 -- Ada 2005 (AI-251): Initialize the tags of all the secondary
1744 -- tables associated with abstract interface types
1746 -------------------------
1747 -- Init_Secondary_Tags --
1748 -------------------------
1750 procedure Init_Secondary_Tags (Typ : Entity_Id) is
1753 procedure Init_Secondary_Tags_Internal (Typ : Entity_Id);
1754 -- Internal subprogram used to recursively climb to the root type
1756 ----------------------------------
1757 -- Init_Secondary_Tags_Internal --
1758 ----------------------------------
1760 procedure Init_Secondary_Tags_Internal (Typ : Entity_Id) is
1765 if not Is_Interface (Typ) then
1767 -- Climb to the ancestor (if any) handling private types
1769 if Present (Full_View (Etype (Typ))) then
1770 if Full_View (Etype (Typ)) /= Typ then
1771 Init_Secondary_Tags_Internal (Full_View (Etype (Typ)));
1774 elsif Etype (Typ) /= Typ then
1775 Init_Secondary_Tags_Internal (Etype (Typ));
1779 if Present (Abstract_Interfaces (Typ))
1780 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ))
1782 E := First_Entity (Typ);
1783 while Present (E) loop
1785 and then Chars (E) /= Name_uTag
1787 Aux_N := Node (ADT);
1788 pragma Assert (Present (Aux_N));
1790 -- Initialize the pointer to the secondary DT
1791 -- associated with the interface
1793 Append_To (Body_Stmts,
1794 Make_Assignment_Statement (Loc,
1796 Make_Selected_Component (Loc,
1797 Prefix => Make_Identifier (Loc, Name_uInit),
1799 New_Reference_To (E, Loc)),
1801 New_Reference_To (Aux_N, Loc)));
1804 -- Set_Offset_To_Top (DT_Ptr, n);
1806 Append_To (Body_Stmts,
1807 Make_Procedure_Call_Statement (Loc,
1808 Name => New_Reference_To
1809 (RTE (RE_Set_Offset_To_Top), Loc),
1810 Parameter_Associations => New_List (
1811 Unchecked_Convert_To (RTE (RE_Tag),
1812 New_Reference_To (Aux_N, Loc)),
1813 Unchecked_Convert_To (RTE (RE_Storage_Offset),
1814 Make_Attribute_Reference (Loc,
1816 Make_Selected_Component (Loc,
1817 Prefix => Make_Identifier (Loc,
1819 Selector_Name => New_Reference_To
1821 Attribute_Name => Name_Position)))));
1829 end Init_Secondary_Tags_Internal;
1831 -- Start of processing for Init_Secondary_Tags
1834 -- Skip the first _Tag, which is the main tag of the
1835 -- tagged type. Following tags correspond with abstract
1838 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (Typ)));
1840 -- Handle private types
1842 if Present (Full_View (Typ)) then
1843 Init_Secondary_Tags_Internal (Full_View (Typ));
1845 Init_Secondary_Tags_Internal (Typ);
1847 end Init_Secondary_Tags;
1849 -- Start of processing for Build_Init_Procedure
1852 Body_Stmts := New_List;
1853 Body_Node := New_Node (N_Subprogram_Body, Loc);
1856 Make_Defining_Identifier (Loc,
1857 Chars => Make_Init_Proc_Name (Rec_Type));
1858 Set_Ekind (Proc_Id, E_Procedure);
1860 Proc_Spec_Node := New_Node (N_Procedure_Specification, Loc);
1861 Set_Defining_Unit_Name (Proc_Spec_Node, Proc_Id);
1863 Parameters := Init_Formals (Rec_Type);
1864 Append_List_To (Parameters,
1865 Build_Discriminant_Formals (Rec_Type, True));
1867 -- For tagged types, we add a flag to indicate whether the routine
1868 -- is called to initialize a parent component in the init_proc of
1869 -- a type extension. If the flag is false, we do not set the tag
1870 -- because it has been set already in the extension.
1872 if Is_Tagged_Type (Rec_Type)
1873 and then not Is_CPP_Class (Rec_Type)
1876 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
1878 Append_To (Parameters,
1879 Make_Parameter_Specification (Loc,
1880 Defining_Identifier => Set_Tag,
1881 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
1882 Expression => New_Occurrence_Of (Standard_True, Loc)));
1885 Set_Parameter_Specifications (Proc_Spec_Node, Parameters);
1886 Set_Specification (Body_Node, Proc_Spec_Node);
1887 Set_Declarations (Body_Node, New_List);
1889 if Parent_Subtype_Renaming_Discrims then
1891 -- N is a Derived_Type_Definition that renames the parameters
1892 -- of the ancestor type. We init it by expanding our discrims
1893 -- and call the ancestor _init_proc with a type-converted object
1895 Append_List_To (Body_Stmts,
1896 Build_Init_Call_Thru (Parameters));
1898 elsif Nkind (Type_Definition (N)) = N_Record_Definition then
1899 Build_Discriminant_Assignments (Body_Stmts);
1901 if not Null_Present (Type_Definition (N)) then
1902 Append_List_To (Body_Stmts,
1903 Build_Init_Statements (
1904 Component_List (Type_Definition (N))));
1908 -- N is a Derived_Type_Definition with a possible non-empty
1909 -- extension. The initialization of a type extension consists
1910 -- in the initialization of the components in the extension.
1912 Build_Discriminant_Assignments (Body_Stmts);
1914 Record_Extension_Node :=
1915 Record_Extension_Part (Type_Definition (N));
1917 if not Null_Present (Record_Extension_Node) then
1919 Stmts : constant List_Id :=
1920 Build_Init_Statements (
1921 Component_List (Record_Extension_Node));
1924 -- The parent field must be initialized first because
1925 -- the offset of the new discriminants may depend on it
1927 Prepend_To (Body_Stmts, Remove_Head (Stmts));
1928 Append_List_To (Body_Stmts, Stmts);
1933 -- Add here the assignment to instantiate the Tag
1935 -- The assignement corresponds to the code:
1937 -- _Init._Tag := Typ'Tag;
1939 -- Suppress the tag assignment when Java_VM because JVM tags are
1940 -- represented implicitly in objects.
1942 if Is_Tagged_Type (Rec_Type)
1943 and then not Is_CPP_Class (Rec_Type)
1944 and then not Java_VM
1947 Make_Assignment_Statement (Loc,
1949 Make_Selected_Component (Loc,
1950 Prefix => Make_Identifier (Loc, Name_uInit),
1952 New_Reference_To (First_Tag_Component (Rec_Type), Loc)),
1956 (Node (First_Elmt (Access_Disp_Table (Rec_Type))), Loc));
1958 -- The tag must be inserted before the assignments to other
1959 -- components, because the initial value of the component may
1960 -- depend ot the tag (eg. through a dispatching operation on
1961 -- an access to the current type). The tag assignment is not done
1962 -- when initializing the parent component of a type extension,
1963 -- because in that case the tag is set in the extension.
1964 -- Extensions of imported C++ classes add a final complication,
1965 -- because we cannot inhibit tag setting in the constructor for
1966 -- the parent. In that case we insert the tag initialization
1967 -- after the calls to initialize the parent.
1970 Make_If_Statement (Loc,
1971 Condition => New_Occurrence_Of (Set_Tag, Loc),
1972 Then_Statements => New_List (Init_Tag));
1974 if not Is_CPP_Class (Etype (Rec_Type)) then
1975 Prepend_To (Body_Stmts, Init_Tag);
1977 -- Ada 2005 (AI-251): Initialization of all the tags
1978 -- corresponding with abstract interfaces
1980 if Ada_Version >= Ada_05
1981 and then not Is_Interface (Rec_Type)
1983 Init_Secondary_Tags (Rec_Type);
1988 Nod : Node_Id := First (Body_Stmts);
1991 -- We assume the first init_proc call is for the parent
1993 while Present (Next (Nod))
1994 and then (Nkind (Nod) /= N_Procedure_Call_Statement
1995 or else not Is_Init_Proc (Name (Nod)))
2000 Insert_After (Nod, Init_Tag);
2005 Handled_Stmt_Node := New_Node (N_Handled_Sequence_Of_Statements, Loc);
2006 Set_Statements (Handled_Stmt_Node, Body_Stmts);
2007 Set_Exception_Handlers (Handled_Stmt_Node, No_List);
2008 Set_Handled_Statement_Sequence (Body_Node, Handled_Stmt_Node);
2010 if not Debug_Generated_Code then
2011 Set_Debug_Info_Off (Proc_Id);
2014 -- Associate Init_Proc with type, and determine if the procedure
2015 -- is null (happens because of the Initialize_Scalars pragma case,
2016 -- where we have to generate a null procedure in case it is called
2017 -- by a client with Initialize_Scalars set). Such procedures have
2018 -- to be generated, but do not have to be called, so we mark them
2019 -- as null to suppress the call.
2021 Set_Init_Proc (Rec_Type, Proc_Id);
2023 if List_Length (Body_Stmts) = 1
2024 and then Nkind (First (Body_Stmts)) = N_Null_Statement
2026 Set_Is_Null_Init_Proc (Proc_Id);
2028 end Build_Init_Procedure;
2030 ---------------------------
2031 -- Build_Init_Statements --
2032 ---------------------------
2034 function Build_Init_Statements (Comp_List : Node_Id) return List_Id is
2035 Check_List : constant List_Id := New_List;
2037 Statement_List : List_Id;
2040 Per_Object_Constraint_Components : Boolean;
2048 function Has_Access_Constraint (E : Entity_Id) return Boolean;
2049 -- Components with access discriminants that depend on the current
2050 -- instance must be initialized after all other components.
2052 ---------------------------
2053 -- Has_Access_Constraint --
2054 ---------------------------
2056 function Has_Access_Constraint (E : Entity_Id) return Boolean is
2058 T : constant Entity_Id := Etype (E);
2061 if Has_Per_Object_Constraint (E)
2062 and then Has_Discriminants (T)
2064 Disc := First_Discriminant (T);
2065 while Present (Disc) loop
2066 if Is_Access_Type (Etype (Disc)) then
2070 Next_Discriminant (Disc);
2077 end Has_Access_Constraint;
2079 -- Start of processing for Build_Init_Statements
2082 if Null_Present (Comp_List) then
2083 return New_List (Make_Null_Statement (Loc));
2086 Statement_List := New_List;
2088 -- Loop through components, skipping pragmas, in 2 steps. The first
2089 -- step deals with regular components. The second step deals with
2090 -- components have per object constraints, and no explicit initia-
2093 Per_Object_Constraint_Components := False;
2095 -- First step : regular components
2097 Decl := First_Non_Pragma (Component_Items (Comp_List));
2098 while Present (Decl) loop
2101 (Subtype_Indication (Component_Definition (Decl)), Check_List);
2103 Id := Defining_Identifier (Decl);
2106 if Has_Access_Constraint (Id)
2107 and then No (Expression (Decl))
2109 -- Skip processing for now and ask for a second pass
2111 Per_Object_Constraint_Components := True;
2114 -- Case of explicit initialization
2116 if Present (Expression (Decl)) then
2117 Stmts := Build_Assignment (Id, Expression (Decl));
2119 -- Case of composite component with its own Init_Proc
2121 elsif Has_Non_Null_Base_Init_Proc (Typ) then
2123 Build_Initialization_Call
2125 Make_Selected_Component (Loc,
2126 Prefix => Make_Identifier (Loc, Name_uInit),
2127 Selector_Name => New_Occurrence_Of (Id, Loc)),
2131 Discr_Map => Discr_Map);
2133 -- Case of component needing simple initialization
2135 elsif Component_Needs_Simple_Initialization (Typ) then
2138 (Id, Get_Simple_Init_Val (Typ, Loc, Esize (Id)));
2140 -- Nothing needed for this case
2146 if Present (Check_List) then
2147 Append_List_To (Statement_List, Check_List);
2150 if Present (Stmts) then
2152 -- Add the initialization of the record controller before
2153 -- the _Parent field is attached to it when the attachment
2154 -- can occur. It does not work to simply initialize the
2155 -- controller first: it must be initialized after the parent
2156 -- if the parent holds discriminants that can be used
2157 -- to compute the offset of the controller. We assume here
2158 -- that the last statement of the initialization call is the
2159 -- attachement of the parent (see Build_Initialization_Call)
2161 if Chars (Id) = Name_uController
2162 and then Rec_Type /= Etype (Rec_Type)
2163 and then Has_Controlled_Component (Etype (Rec_Type))
2164 and then Has_New_Controlled_Component (Rec_Type)
2166 Insert_List_Before (Last (Statement_List), Stmts);
2168 Append_List_To (Statement_List, Stmts);
2173 Next_Non_Pragma (Decl);
2176 if Per_Object_Constraint_Components then
2178 -- Second pass: components with per-object constraints
2180 Decl := First_Non_Pragma (Component_Items (Comp_List));
2182 while Present (Decl) loop
2184 Id := Defining_Identifier (Decl);
2187 if Has_Access_Constraint (Id)
2188 and then No (Expression (Decl))
2190 if Has_Non_Null_Base_Init_Proc (Typ) then
2191 Append_List_To (Statement_List,
2192 Build_Initialization_Call (Loc,
2193 Make_Selected_Component (Loc,
2194 Prefix => Make_Identifier (Loc, Name_uInit),
2195 Selector_Name => New_Occurrence_Of (Id, Loc)),
2196 Typ, True, Rec_Type, Discr_Map => Discr_Map));
2198 elsif Component_Needs_Simple_Initialization (Typ) then
2199 Append_List_To (Statement_List,
2201 (Id, Get_Simple_Init_Val (Typ, Loc, Esize (Id))));
2205 Next_Non_Pragma (Decl);
2209 -- Process the variant part
2211 if Present (Variant_Part (Comp_List)) then
2212 Alt_List := New_List;
2213 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
2215 while Present (Variant) loop
2216 Loc := Sloc (Variant);
2217 Append_To (Alt_List,
2218 Make_Case_Statement_Alternative (Loc,
2220 New_Copy_List (Discrete_Choices (Variant)),
2222 Build_Init_Statements (Component_List (Variant))));
2224 Next_Non_Pragma (Variant);
2227 -- The expression of the case statement which is a reference
2228 -- to one of the discriminants is replaced by the appropriate
2229 -- formal parameter of the initialization procedure.
2231 Append_To (Statement_List,
2232 Make_Case_Statement (Loc,
2234 New_Reference_To (Discriminal (
2235 Entity (Name (Variant_Part (Comp_List)))), Loc),
2236 Alternatives => Alt_List));
2239 -- For a task record type, add the task create call and calls
2240 -- to bind any interrupt (signal) entries.
2242 if Is_Task_Record_Type (Rec_Type) then
2244 -- In the case of the restricted run time the ATCB has already
2245 -- been preallocated.
2247 if Restricted_Profile then
2248 Append_To (Statement_List,
2249 Make_Assignment_Statement (Loc,
2250 Name => Make_Selected_Component (Loc,
2251 Prefix => Make_Identifier (Loc, Name_uInit),
2252 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2253 Expression => Make_Attribute_Reference (Loc,
2255 Make_Selected_Component (Loc,
2256 Prefix => Make_Identifier (Loc, Name_uInit),
2258 Make_Identifier (Loc, Name_uATCB)),
2259 Attribute_Name => Name_Unchecked_Access)));
2262 Append_To (Statement_List, Make_Task_Create_Call (Rec_Type));
2265 Task_Type : constant Entity_Id :=
2266 Corresponding_Concurrent_Type (Rec_Type);
2267 Task_Decl : constant Node_Id := Parent (Task_Type);
2268 Task_Def : constant Node_Id := Task_Definition (Task_Decl);
2273 if Present (Task_Def) then
2274 Vis_Decl := First (Visible_Declarations (Task_Def));
2275 while Present (Vis_Decl) loop
2276 Loc := Sloc (Vis_Decl);
2278 if Nkind (Vis_Decl) = N_Attribute_Definition_Clause then
2279 if Get_Attribute_Id (Chars (Vis_Decl)) =
2282 Ent := Entity (Name (Vis_Decl));
2284 if Ekind (Ent) = E_Entry then
2285 Append_To (Statement_List,
2286 Make_Procedure_Call_Statement (Loc,
2287 Name => New_Reference_To (
2288 RTE (RE_Bind_Interrupt_To_Entry), Loc),
2289 Parameter_Associations => New_List (
2290 Make_Selected_Component (Loc,
2292 Make_Identifier (Loc, Name_uInit),
2294 Make_Identifier (Loc, Name_uTask_Id)),
2295 Entry_Index_Expression (
2296 Loc, Ent, Empty, Task_Type),
2297 Expression (Vis_Decl))));
2308 -- For a protected type, add statements generated by
2309 -- Make_Initialize_Protection.
2311 if Is_Protected_Record_Type (Rec_Type) then
2312 Append_List_To (Statement_List,
2313 Make_Initialize_Protection (Rec_Type));
2316 -- If no initializations when generated for component declarations
2317 -- corresponding to this Statement_List, append a null statement
2318 -- to the Statement_List to make it a valid Ada tree.
2320 if Is_Empty_List (Statement_List) then
2321 Append (New_Node (N_Null_Statement, Loc), Statement_List);
2324 return Statement_List;
2327 when RE_Not_Available =>
2329 end Build_Init_Statements;
2331 -------------------------
2332 -- Build_Record_Checks --
2333 -------------------------
2335 procedure Build_Record_Checks (S : Node_Id; Check_List : List_Id) is
2336 Subtype_Mark_Id : Entity_Id;
2339 if Nkind (S) = N_Subtype_Indication then
2340 Find_Type (Subtype_Mark (S));
2341 Subtype_Mark_Id := Entity (Subtype_Mark (S));
2343 -- Remaining processing depends on type
2345 case Ekind (Subtype_Mark_Id) is
2348 Constrain_Array (S, Check_List);
2354 end Build_Record_Checks;
2356 -------------------------------------------
2357 -- Component_Needs_Simple_Initialization --
2358 -------------------------------------------
2360 function Component_Needs_Simple_Initialization
2361 (T : Entity_Id) return Boolean
2365 Needs_Simple_Initialization (T)
2366 and then not Is_RTE (T, RE_Tag)
2367 and then not Is_RTE (T, RE_Vtable_Ptr)
2368 and then not Is_RTE (T, RE_Interface_Tag); -- Ada 2005 (AI-251)
2369 end Component_Needs_Simple_Initialization;
2371 ---------------------
2372 -- Constrain_Array --
2373 ---------------------
2375 procedure Constrain_Array
2377 Check_List : List_Id)
2379 C : constant Node_Id := Constraint (SI);
2380 Number_Of_Constraints : Nat := 0;
2385 T := Entity (Subtype_Mark (SI));
2387 if Ekind (T) in Access_Kind then
2388 T := Designated_Type (T);
2391 S := First (Constraints (C));
2393 while Present (S) loop
2394 Number_Of_Constraints := Number_Of_Constraints + 1;
2398 -- In either case, the index constraint must provide a discrete
2399 -- range for each index of the array type and the type of each
2400 -- discrete range must be the same as that of the corresponding
2401 -- index. (RM 3.6.1)
2403 S := First (Constraints (C));
2404 Index := First_Index (T);
2407 -- Apply constraints to each index type
2409 for J in 1 .. Number_Of_Constraints loop
2410 Constrain_Index (Index, S, Check_List);
2415 end Constrain_Array;
2417 ---------------------
2418 -- Constrain_Index --
2419 ---------------------
2421 procedure Constrain_Index
2424 Check_List : List_Id)
2426 T : constant Entity_Id := Etype (Index);
2429 if Nkind (S) = N_Range then
2430 Process_Range_Expr_In_Decl (S, T, Check_List);
2432 end Constrain_Index;
2434 --------------------------------------
2435 -- Parent_Subtype_Renaming_Discrims --
2436 --------------------------------------
2438 function Parent_Subtype_Renaming_Discrims return Boolean is
2443 if Base_Type (Pe) /= Pe then
2448 or else not Has_Discriminants (Pe)
2449 or else Is_Constrained (Pe)
2450 or else Is_Tagged_Type (Pe)
2455 -- If there are no explicit stored discriminants we have inherited
2456 -- the root type discriminants so far, so no renamings occurred.
2458 if First_Discriminant (Pe) = First_Stored_Discriminant (Pe) then
2462 -- Check if we have done some trivial renaming of the parent
2463 -- discriminants, i.e. someting like
2465 -- type DT (X1,X2: int) is new PT (X1,X2);
2467 De := First_Discriminant (Pe);
2468 Dp := First_Discriminant (Etype (Pe));
2470 while Present (De) loop
2471 pragma Assert (Present (Dp));
2473 if Corresponding_Discriminant (De) /= Dp then
2477 Next_Discriminant (De);
2478 Next_Discriminant (Dp);
2481 return Present (Dp);
2482 end Parent_Subtype_Renaming_Discrims;
2484 ------------------------
2485 -- Requires_Init_Proc --
2486 ------------------------
2488 function Requires_Init_Proc (Rec_Id : Entity_Id) return Boolean is
2489 Comp_Decl : Node_Id;
2494 -- Definitely do not need one if specifically suppressed
2496 if Suppress_Init_Proc (Rec_Id) then
2500 -- If it is a type derived from a type with unknown discriminants,
2501 -- we cannot build an initialization procedure for it.
2503 if Has_Unknown_Discriminants (Rec_Id) then
2507 -- Otherwise we need to generate an initialization procedure if
2508 -- Is_CPP_Class is False and at least one of the following applies:
2510 -- 1. Discriminants are present, since they need to be initialized
2511 -- with the appropriate discriminant constraint expressions.
2512 -- However, the discriminant of an unchecked union does not
2513 -- count, since the discriminant is not present.
2515 -- 2. The type is a tagged type, since the implicit Tag component
2516 -- needs to be initialized with a pointer to the dispatch table.
2518 -- 3. The type contains tasks
2520 -- 4. One or more components has an initial value
2522 -- 5. One or more components is for a type which itself requires
2523 -- an initialization procedure.
2525 -- 6. One or more components is a type that requires simple
2526 -- initialization (see Needs_Simple_Initialization), except
2527 -- that types Tag and Interface_Tag are excluded, since fields
2528 -- of these types are initialized by other means.
2530 -- 7. The type is the record type built for a task type (since at
2531 -- the very least, Create_Task must be called)
2533 -- 8. The type is the record type built for a protected type (since
2534 -- at least Initialize_Protection must be called)
2536 -- 9. The type is marked as a public entity. The reason we add this
2537 -- case (even if none of the above apply) is to properly handle
2538 -- Initialize_Scalars. If a package is compiled without an IS
2539 -- pragma, and the client is compiled with an IS pragma, then
2540 -- the client will think an initialization procedure is present
2541 -- and call it, when in fact no such procedure is required, but
2542 -- since the call is generated, there had better be a routine
2543 -- at the other end of the call, even if it does nothing!)
2545 -- Note: the reason we exclude the CPP_Class case is ???
2547 if Is_CPP_Class (Rec_Id) then
2550 elsif not Restriction_Active (No_Initialize_Scalars)
2551 and then Is_Public (Rec_Id)
2555 elsif (Has_Discriminants (Rec_Id)
2556 and then not Is_Unchecked_Union (Rec_Id))
2557 or else Is_Tagged_Type (Rec_Id)
2558 or else Is_Concurrent_Record_Type (Rec_Id)
2559 or else Has_Task (Rec_Id)
2564 Id := First_Component (Rec_Id);
2566 while Present (Id) loop
2567 Comp_Decl := Parent (Id);
2570 if Present (Expression (Comp_Decl))
2571 or else Has_Non_Null_Base_Init_Proc (Typ)
2572 or else Component_Needs_Simple_Initialization (Typ)
2577 Next_Component (Id);
2581 end Requires_Init_Proc;
2583 -- Start of processing for Build_Record_Init_Proc
2586 Rec_Type := Defining_Identifier (N);
2588 -- This may be full declaration of a private type, in which case
2589 -- the visible entity is a record, and the private entity has been
2590 -- exchanged with it in the private part of the current package.
2591 -- The initialization procedure is built for the record type, which
2592 -- is retrievable from the private entity.
2594 if Is_Incomplete_Or_Private_Type (Rec_Type) then
2595 Rec_Type := Underlying_Type (Rec_Type);
2598 -- If there are discriminants, build the discriminant map to replace
2599 -- discriminants by their discriminals in complex bound expressions.
2600 -- These only arise for the corresponding records of protected types.
2602 if Is_Concurrent_Record_Type (Rec_Type)
2603 and then Has_Discriminants (Rec_Type)
2609 Disc := First_Discriminant (Rec_Type);
2611 while Present (Disc) loop
2612 Append_Elmt (Disc, Discr_Map);
2613 Append_Elmt (Discriminal (Disc), Discr_Map);
2614 Next_Discriminant (Disc);
2619 -- Derived types that have no type extension can use the initialization
2620 -- procedure of their parent and do not need a procedure of their own.
2621 -- This is only correct if there are no representation clauses for the
2622 -- type or its parent, and if the parent has in fact been frozen so
2623 -- that its initialization procedure exists.
2625 if Is_Derived_Type (Rec_Type)
2626 and then not Is_Tagged_Type (Rec_Type)
2627 and then not Is_Unchecked_Union (Rec_Type)
2628 and then not Has_New_Non_Standard_Rep (Rec_Type)
2629 and then not Parent_Subtype_Renaming_Discrims
2630 and then Has_Non_Null_Base_Init_Proc (Etype (Rec_Type))
2632 Copy_TSS (Base_Init_Proc (Etype (Rec_Type)), Rec_Type);
2634 -- Otherwise if we need an initialization procedure, then build one,
2635 -- mark it as public and inlinable and as having a completion.
2637 elsif Requires_Init_Proc (Rec_Type)
2638 or else Is_Unchecked_Union (Rec_Type)
2640 Build_Init_Procedure;
2641 Set_Is_Public (Proc_Id, Is_Public (Pe));
2643 -- The initialization of protected records is not worth inlining.
2644 -- In addition, when compiled for another unit for inlining purposes,
2645 -- it may make reference to entities that have not been elaborated
2646 -- yet. The initialization of controlled records contains a nested
2647 -- clean-up procedure that makes it impractical to inline as well,
2648 -- and leads to undefined symbols if inlined in a different unit.
2649 -- Similar considerations apply to task types.
2651 if not Is_Concurrent_Type (Rec_Type)
2652 and then not Has_Task (Rec_Type)
2653 and then not Controlled_Type (Rec_Type)
2655 Set_Is_Inlined (Proc_Id);
2658 Set_Is_Internal (Proc_Id);
2659 Set_Has_Completion (Proc_Id);
2661 if not Debug_Generated_Code then
2662 Set_Debug_Info_Off (Proc_Id);
2665 end Build_Record_Init_Proc;
2667 ----------------------------
2668 -- Build_Slice_Assignment --
2669 ----------------------------
2671 -- Generates the following subprogram:
2674 -- (Source, Target : Array_Type,
2675 -- Left_Lo, Left_Hi, Right_Lo, Right_Hi : Index;
2692 -- exit when Li1 < Left_Lo;
2694 -- exit when Li1 > Left_Hi;
2697 -- Target (Li1) := Source (Ri1);
2700 -- Li1 := Index'pred (Li1);
2701 -- Ri1 := Index'pred (Ri1);
2703 -- Li1 := Index'succ (Li1);
2704 -- Ri1 := Index'succ (Ri1);
2709 procedure Build_Slice_Assignment (Typ : Entity_Id) is
2710 Loc : constant Source_Ptr := Sloc (Typ);
2711 Index : constant Entity_Id := Base_Type (Etype (First_Index (Typ)));
2713 -- Build formal parameters of procedure
2715 Larray : constant Entity_Id :=
2716 Make_Defining_Identifier
2717 (Loc, Chars => New_Internal_Name ('A'));
2718 Rarray : constant Entity_Id :=
2719 Make_Defining_Identifier
2720 (Loc, Chars => New_Internal_Name ('R'));
2721 Left_Lo : constant Entity_Id :=
2722 Make_Defining_Identifier
2723 (Loc, Chars => New_Internal_Name ('L'));
2724 Left_Hi : constant Entity_Id :=
2725 Make_Defining_Identifier
2726 (Loc, Chars => New_Internal_Name ('L'));
2727 Right_Lo : constant Entity_Id :=
2728 Make_Defining_Identifier
2729 (Loc, Chars => New_Internal_Name ('R'));
2730 Right_Hi : constant Entity_Id :=
2731 Make_Defining_Identifier
2732 (Loc, Chars => New_Internal_Name ('R'));
2733 Rev : constant Entity_Id :=
2734 Make_Defining_Identifier
2735 (Loc, Chars => New_Internal_Name ('D'));
2736 Proc_Name : constant Entity_Id :=
2737 Make_Defining_Identifier (Loc,
2738 Chars => Make_TSS_Name (Typ, TSS_Slice_Assign));
2740 Lnn : constant Entity_Id :=
2741 Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
2742 Rnn : constant Entity_Id :=
2743 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2744 -- Subscripts for left and right sides
2751 -- Build declarations for indices
2756 Make_Object_Declaration (Loc,
2757 Defining_Identifier => Lnn,
2758 Object_Definition =>
2759 New_Occurrence_Of (Index, Loc)));
2762 Make_Object_Declaration (Loc,
2763 Defining_Identifier => Rnn,
2764 Object_Definition =>
2765 New_Occurrence_Of (Index, Loc)));
2769 -- Build initializations for indices
2772 F_Init : constant List_Id := New_List;
2773 B_Init : constant List_Id := New_List;
2777 Make_Assignment_Statement (Loc,
2778 Name => New_Occurrence_Of (Lnn, Loc),
2779 Expression => New_Occurrence_Of (Left_Lo, Loc)));
2782 Make_Assignment_Statement (Loc,
2783 Name => New_Occurrence_Of (Rnn, Loc),
2784 Expression => New_Occurrence_Of (Right_Lo, Loc)));
2787 Make_Assignment_Statement (Loc,
2788 Name => New_Occurrence_Of (Lnn, Loc),
2789 Expression => New_Occurrence_Of (Left_Hi, Loc)));
2792 Make_Assignment_Statement (Loc,
2793 Name => New_Occurrence_Of (Rnn, Loc),
2794 Expression => New_Occurrence_Of (Right_Hi, Loc)));
2797 Make_If_Statement (Loc,
2798 Condition => New_Occurrence_Of (Rev, Loc),
2799 Then_Statements => B_Init,
2800 Else_Statements => F_Init));
2803 -- Now construct the assignment statement
2806 Make_Loop_Statement (Loc,
2807 Statements => New_List (
2808 Make_Assignment_Statement (Loc,
2810 Make_Indexed_Component (Loc,
2811 Prefix => New_Occurrence_Of (Larray, Loc),
2812 Expressions => New_List (New_Occurrence_Of (Lnn, Loc))),
2814 Make_Indexed_Component (Loc,
2815 Prefix => New_Occurrence_Of (Rarray, Loc),
2816 Expressions => New_List (New_Occurrence_Of (Rnn, Loc))))),
2817 End_Label => Empty);
2819 -- Build exit condition
2822 F_Ass : constant List_Id := New_List;
2823 B_Ass : constant List_Id := New_List;
2827 Make_Exit_Statement (Loc,
2830 Left_Opnd => New_Occurrence_Of (Lnn, Loc),
2831 Right_Opnd => New_Occurrence_Of (Left_Hi, Loc))));
2834 Make_Exit_Statement (Loc,
2837 Left_Opnd => New_Occurrence_Of (Lnn, Loc),
2838 Right_Opnd => New_Occurrence_Of (Left_Lo, Loc))));
2840 Prepend_To (Statements (Loops),
2841 Make_If_Statement (Loc,
2842 Condition => New_Occurrence_Of (Rev, Loc),
2843 Then_Statements => B_Ass,
2844 Else_Statements => F_Ass));
2847 -- Build the increment/decrement statements
2850 F_Ass : constant List_Id := New_List;
2851 B_Ass : constant List_Id := New_List;
2855 Make_Assignment_Statement (Loc,
2856 Name => New_Occurrence_Of (Lnn, Loc),
2858 Make_Attribute_Reference (Loc,
2860 New_Occurrence_Of (Index, Loc),
2861 Attribute_Name => Name_Succ,
2862 Expressions => New_List (
2863 New_Occurrence_Of (Lnn, Loc)))));
2866 Make_Assignment_Statement (Loc,
2867 Name => New_Occurrence_Of (Rnn, Loc),
2869 Make_Attribute_Reference (Loc,
2871 New_Occurrence_Of (Index, Loc),
2872 Attribute_Name => Name_Succ,
2873 Expressions => New_List (
2874 New_Occurrence_Of (Rnn, Loc)))));
2877 Make_Assignment_Statement (Loc,
2878 Name => New_Occurrence_Of (Lnn, Loc),
2880 Make_Attribute_Reference (Loc,
2882 New_Occurrence_Of (Index, Loc),
2883 Attribute_Name => Name_Pred,
2884 Expressions => New_List (
2885 New_Occurrence_Of (Lnn, Loc)))));
2888 Make_Assignment_Statement (Loc,
2889 Name => New_Occurrence_Of (Rnn, Loc),
2891 Make_Attribute_Reference (Loc,
2893 New_Occurrence_Of (Index, Loc),
2894 Attribute_Name => Name_Pred,
2895 Expressions => New_List (
2896 New_Occurrence_Of (Rnn, Loc)))));
2898 Append_To (Statements (Loops),
2899 Make_If_Statement (Loc,
2900 Condition => New_Occurrence_Of (Rev, Loc),
2901 Then_Statements => B_Ass,
2902 Else_Statements => F_Ass));
2905 Append_To (Stats, Loops);
2909 Formals : List_Id := New_List;
2912 Formals := New_List (
2913 Make_Parameter_Specification (Loc,
2914 Defining_Identifier => Larray,
2915 Out_Present => True,
2917 New_Reference_To (Base_Type (Typ), Loc)),
2919 Make_Parameter_Specification (Loc,
2920 Defining_Identifier => Rarray,
2922 New_Reference_To (Base_Type (Typ), Loc)),
2924 Make_Parameter_Specification (Loc,
2925 Defining_Identifier => Left_Lo,
2927 New_Reference_To (Index, Loc)),
2929 Make_Parameter_Specification (Loc,
2930 Defining_Identifier => Left_Hi,
2932 New_Reference_To (Index, Loc)),
2934 Make_Parameter_Specification (Loc,
2935 Defining_Identifier => Right_Lo,
2937 New_Reference_To (Index, Loc)),
2939 Make_Parameter_Specification (Loc,
2940 Defining_Identifier => Right_Hi,
2942 New_Reference_To (Index, Loc)));
2945 Make_Parameter_Specification (Loc,
2946 Defining_Identifier => Rev,
2948 New_Reference_To (Standard_Boolean, Loc)));
2951 Make_Procedure_Specification (Loc,
2952 Defining_Unit_Name => Proc_Name,
2953 Parameter_Specifications => Formals);
2956 Make_Subprogram_Body (Loc,
2957 Specification => Spec,
2958 Declarations => Decls,
2959 Handled_Statement_Sequence =>
2960 Make_Handled_Sequence_Of_Statements (Loc,
2961 Statements => Stats)));
2964 Set_TSS (Typ, Proc_Name);
2965 Set_Is_Pure (Proc_Name);
2966 end Build_Slice_Assignment;
2968 ------------------------------------
2969 -- Build_Variant_Record_Equality --
2970 ------------------------------------
2974 -- function _Equality (X, Y : T) return Boolean is
2976 -- -- Compare discriminants
2978 -- if False or else X.D1 /= Y.D1 or else X.D2 /= Y.D2 then
2982 -- -- Compare components
2984 -- if False or else X.C1 /= Y.C1 or else X.C2 /= Y.C2 then
2988 -- -- Compare variant part
2992 -- if False or else X.C2 /= Y.C2 or else X.C3 /= Y.C3 then
2997 -- if False or else X.Cn /= Y.Cn then
3004 procedure Build_Variant_Record_Equality (Typ : Entity_Id) is
3005 Loc : constant Source_Ptr := Sloc (Typ);
3007 F : constant Entity_Id :=
3008 Make_Defining_Identifier (Loc,
3009 Chars => Make_TSS_Name (Typ, TSS_Composite_Equality));
3011 X : constant Entity_Id :=
3012 Make_Defining_Identifier (Loc,
3015 Y : constant Entity_Id :=
3016 Make_Defining_Identifier (Loc,
3019 Def : constant Node_Id := Parent (Typ);
3020 Comps : constant Node_Id := Component_List (Type_Definition (Def));
3021 Stmts : constant List_Id := New_List;
3022 Pspecs : constant List_Id := New_List;
3025 -- Derived Unchecked_Union types no longer inherit the equality function
3028 if Is_Derived_Type (Typ)
3029 and then not Is_Unchecked_Union (Typ)
3030 and then not Has_New_Non_Standard_Rep (Typ)
3033 Parent_Eq : constant Entity_Id :=
3034 TSS (Root_Type (Typ), TSS_Composite_Equality);
3037 if Present (Parent_Eq) then
3038 Copy_TSS (Parent_Eq, Typ);
3045 Make_Subprogram_Body (Loc,
3047 Make_Function_Specification (Loc,
3048 Defining_Unit_Name => F,
3049 Parameter_Specifications => Pspecs,
3050 Result_Definition => New_Reference_To (Standard_Boolean, Loc)),
3051 Declarations => New_List,
3052 Handled_Statement_Sequence =>
3053 Make_Handled_Sequence_Of_Statements (Loc,
3054 Statements => Stmts)));
3057 Make_Parameter_Specification (Loc,
3058 Defining_Identifier => X,
3059 Parameter_Type => New_Reference_To (Typ, Loc)));
3062 Make_Parameter_Specification (Loc,
3063 Defining_Identifier => Y,
3064 Parameter_Type => New_Reference_To (Typ, Loc)));
3066 -- Unchecked_Unions require additional machinery to support equality.
3067 -- Two extra parameters (A and B) are added to the equality function
3068 -- parameter list in order to capture the inferred values of the
3069 -- discriminants in later calls.
3071 if Is_Unchecked_Union (Typ) then
3073 Discr_Type : constant Node_Id := Etype (First_Discriminant (Typ));
3075 A : constant Node_Id :=
3076 Make_Defining_Identifier (Loc,
3079 B : constant Node_Id :=
3080 Make_Defining_Identifier (Loc,
3084 -- Add A and B to the parameter list
3087 Make_Parameter_Specification (Loc,
3088 Defining_Identifier => A,
3089 Parameter_Type => New_Reference_To (Discr_Type, Loc)));
3092 Make_Parameter_Specification (Loc,
3093 Defining_Identifier => B,
3094 Parameter_Type => New_Reference_To (Discr_Type, Loc)));
3096 -- Generate the following header code to compare the inferred
3104 Make_If_Statement (Loc,
3107 Left_Opnd => New_Reference_To (A, Loc),
3108 Right_Opnd => New_Reference_To (B, Loc)),
3109 Then_Statements => New_List (
3110 Make_Return_Statement (Loc,
3111 Expression => New_Occurrence_Of (Standard_False, Loc)))));
3113 -- Generate component-by-component comparison. Note that we must
3114 -- propagate one of the inferred discriminant formals to act as
3115 -- the case statement switch.
3117 Append_List_To (Stmts,
3118 Make_Eq_Case (Typ, Comps, A));
3122 -- Normal case (not unchecked union)
3127 Discriminant_Specifications (Def)));
3129 Append_List_To (Stmts,
3130 Make_Eq_Case (Typ, Comps));
3134 Make_Return_Statement (Loc,
3135 Expression => New_Reference_To (Standard_True, Loc)));
3140 if not Debug_Generated_Code then
3141 Set_Debug_Info_Off (F);
3143 end Build_Variant_Record_Equality;
3145 -----------------------------
3146 -- Check_Stream_Attributes --
3147 -----------------------------
3149 procedure Check_Stream_Attributes (Typ : Entity_Id) is
3151 Par_Read : constant Boolean :=
3152 Stream_Attribute_Available (Typ, TSS_Stream_Read)
3153 and then not Has_Specified_Stream_Read (Typ);
3154 Par_Write : constant Boolean :=
3155 Stream_Attribute_Available (Typ, TSS_Stream_Write)
3156 and then not Has_Specified_Stream_Write (Typ);
3158 procedure Check_Attr (Nam : Name_Id; TSS_Nam : TSS_Name_Type);
3159 -- Check that Comp has a user-specified Nam stream attribute
3165 procedure Check_Attr (Nam : Name_Id; TSS_Nam : TSS_Name_Type) is
3167 if not Stream_Attribute_Available (Etype (Comp), TSS_Nam) then
3168 Error_Msg_Name_1 := Nam;
3170 ("|component& in limited extension must have% attribute", Comp);
3174 -- Start of processing for Check_Stream_Attributes
3177 if Par_Read or else Par_Write then
3178 Comp := First_Component (Typ);
3179 while Present (Comp) loop
3180 if Comes_From_Source (Comp)
3181 and then Original_Record_Component (Comp) = Comp
3182 and then Is_Limited_Type (Etype (Comp))
3185 Check_Attr (Name_Read, TSS_Stream_Read);
3189 Check_Attr (Name_Write, TSS_Stream_Write);
3193 Next_Component (Comp);
3196 end Check_Stream_Attributes;
3198 -----------------------------
3199 -- Expand_Record_Extension --
3200 -----------------------------
3202 -- Add a field _parent at the beginning of the record extension. This is
3203 -- used to implement inheritance. Here are some examples of expansion:
3205 -- 1. no discriminants
3206 -- type T2 is new T1 with null record;
3208 -- type T2 is new T1 with record
3212 -- 2. renamed discriminants
3213 -- type T2 (B, C : Int) is new T1 (A => B) with record
3214 -- _Parent : T1 (A => B);
3218 -- 3. inherited discriminants
3219 -- type T2 is new T1 with record -- discriminant A inherited
3220 -- _Parent : T1 (A);
3224 procedure Expand_Record_Extension (T : Entity_Id; Def : Node_Id) is
3225 Indic : constant Node_Id := Subtype_Indication (Def);
3226 Loc : constant Source_Ptr := Sloc (Def);
3227 Rec_Ext_Part : Node_Id := Record_Extension_Part (Def);
3228 Par_Subtype : Entity_Id;
3229 Comp_List : Node_Id;
3230 Comp_Decl : Node_Id;
3233 List_Constr : constant List_Id := New_List;
3236 -- Expand_Record_Extension is called directly from the semantics, so
3237 -- we must check to see whether expansion is active before proceeding
3239 if not Expander_Active then
3243 -- This may be a derivation of an untagged private type whose full
3244 -- view is tagged, in which case the Derived_Type_Definition has no
3245 -- extension part. Build an empty one now.
3247 if No (Rec_Ext_Part) then
3249 Make_Record_Definition (Loc,
3251 Component_List => Empty,
3252 Null_Present => True);
3254 Set_Record_Extension_Part (Def, Rec_Ext_Part);
3255 Mark_Rewrite_Insertion (Rec_Ext_Part);
3258 Comp_List := Component_List (Rec_Ext_Part);
3260 Parent_N := Make_Defining_Identifier (Loc, Name_uParent);
3262 -- If the derived type inherits its discriminants the type of the
3263 -- _parent field must be constrained by the inherited discriminants
3265 if Has_Discriminants (T)
3266 and then Nkind (Indic) /= N_Subtype_Indication
3267 and then not Is_Constrained (Entity (Indic))
3269 D := First_Discriminant (T);
3270 while Present (D) loop
3271 Append_To (List_Constr, New_Occurrence_Of (D, Loc));
3272 Next_Discriminant (D);
3277 Make_Subtype_Indication (Loc,
3278 Subtype_Mark => New_Reference_To (Entity (Indic), Loc),
3280 Make_Index_Or_Discriminant_Constraint (Loc,
3281 Constraints => List_Constr)),
3284 -- Otherwise the original subtype_indication is just what is needed
3287 Par_Subtype := Process_Subtype (New_Copy_Tree (Indic), Def);
3290 Set_Parent_Subtype (T, Par_Subtype);
3293 Make_Component_Declaration (Loc,
3294 Defining_Identifier => Parent_N,
3295 Component_Definition =>
3296 Make_Component_Definition (Loc,
3297 Aliased_Present => False,
3298 Subtype_Indication => New_Reference_To (Par_Subtype, Loc)));
3300 if Null_Present (Rec_Ext_Part) then
3301 Set_Component_List (Rec_Ext_Part,
3302 Make_Component_List (Loc,
3303 Component_Items => New_List (Comp_Decl),
3304 Variant_Part => Empty,
3305 Null_Present => False));
3306 Set_Null_Present (Rec_Ext_Part, False);
3308 elsif Null_Present (Comp_List)
3309 or else Is_Empty_List (Component_Items (Comp_List))
3311 Set_Component_Items (Comp_List, New_List (Comp_Decl));
3312 Set_Null_Present (Comp_List, False);
3315 Insert_Before (First (Component_Items (Comp_List)), Comp_Decl);
3318 Analyze (Comp_Decl);
3319 end Expand_Record_Extension;
3321 ------------------------------------
3322 -- Expand_N_Full_Type_Declaration --
3323 ------------------------------------
3325 procedure Expand_N_Full_Type_Declaration (N : Node_Id) is
3326 Def_Id : constant Entity_Id := Defining_Identifier (N);
3327 B_Id : constant Entity_Id := Base_Type (Def_Id);
3332 if Is_Access_Type (Def_Id) then
3334 -- Anonymous access types are created for the components of the
3335 -- record parameter for an entry declaration. No master is created
3338 if Has_Task (Designated_Type (Def_Id))
3339 and then Comes_From_Source (N)
3341 Build_Master_Entity (Def_Id);
3342 Build_Master_Renaming (Parent (Def_Id), Def_Id);
3344 -- Create a class-wide master because a Master_Id must be generated
3345 -- for access-to-limited-class-wide types, whose root may be extended
3346 -- with task components.
3348 elsif Is_Class_Wide_Type (Designated_Type (Def_Id))
3349 and then Is_Limited_Type (Designated_Type (Def_Id))
3350 and then Tasking_Allowed
3352 -- Don't create a class-wide master for types whose convention is
3353 -- Java since these types cannot embed Ada tasks anyway. Note that
3354 -- the following test cannot catch the following case:
3356 -- package java.lang.Object is
3357 -- type Typ is tagged limited private;
3358 -- type Ref is access all Typ'Class;
3360 -- type Typ is tagged limited ...;
3361 -- pragma Convention (Typ, Java)
3364 -- Because the convention appears after we have done the
3365 -- processing for type Ref.
3367 and then Convention (Designated_Type (Def_Id)) /= Convention_Java
3369 Build_Class_Wide_Master (Def_Id);
3371 elsif Ekind (Def_Id) = E_Access_Protected_Subprogram_Type then
3372 Expand_Access_Protected_Subprogram_Type (N);
3375 elsif Has_Task (Def_Id) then
3376 Expand_Previous_Access_Type (Def_Id);
3379 Par_Id := Etype (B_Id);
3381 -- The parent type is private then we need to inherit
3382 -- any TSS operations from the full view.
3384 if Ekind (Par_Id) in Private_Kind
3385 and then Present (Full_View (Par_Id))
3387 Par_Id := Base_Type (Full_View (Par_Id));
3390 if Nkind (Type_Definition (Original_Node (N)))
3391 = N_Derived_Type_Definition
3392 and then not Is_Tagged_Type (Def_Id)
3393 and then Present (Freeze_Node (Par_Id))
3394 and then Present (TSS_Elist (Freeze_Node (Par_Id)))
3396 Ensure_Freeze_Node (B_Id);
3397 FN := Freeze_Node (B_Id);
3399 if No (TSS_Elist (FN)) then
3400 Set_TSS_Elist (FN, New_Elmt_List);
3404 T_E : constant Elist_Id := TSS_Elist (FN);
3408 Elmt := First_Elmt (TSS_Elist (Freeze_Node (Par_Id)));
3410 while Present (Elmt) loop
3411 if Chars (Node (Elmt)) /= Name_uInit then
3412 Append_Elmt (Node (Elmt), T_E);
3418 -- If the derived type itself is private with a full view, then
3419 -- associate the full view with the inherited TSS_Elist as well.
3421 if Ekind (B_Id) in Private_Kind
3422 and then Present (Full_View (B_Id))
3424 Ensure_Freeze_Node (Base_Type (Full_View (B_Id)));
3426 (Freeze_Node (Base_Type (Full_View (B_Id))), TSS_Elist (FN));
3430 end Expand_N_Full_Type_Declaration;
3432 ---------------------------------
3433 -- Expand_N_Object_Declaration --
3434 ---------------------------------
3436 -- First we do special processing for objects of a tagged type where this
3437 -- is the point at which the type is frozen. The creation of the dispatch
3438 -- table and the initialization procedure have to be deferred to this
3439 -- point, since we reference previously declared primitive subprograms.
3441 -- For all types, we call an initialization procedure if there is one
3443 procedure Expand_N_Object_Declaration (N : Node_Id) is
3444 Def_Id : constant Entity_Id := Defining_Identifier (N);
3445 Typ : constant Entity_Id := Etype (Def_Id);
3446 Loc : constant Source_Ptr := Sloc (N);
3447 Expr : constant Node_Id := Expression (N);
3453 -- Don't do anything for deferred constants. All proper actions will
3454 -- be expanded during the full declaration.
3456 if No (Expr) and Constant_Present (N) then
3460 -- Make shared memory routines for shared passive variable
3462 if Is_Shared_Passive (Def_Id) then
3463 Make_Shared_Var_Procs (N);
3466 -- If tasks being declared, make sure we have an activation chain
3467 -- defined for the tasks (has no effect if we already have one), and
3468 -- also that a Master variable is established and that the appropriate
3469 -- enclosing construct is established as a task master.
3471 if Has_Task (Typ) then
3472 Build_Activation_Chain_Entity (N);
3473 Build_Master_Entity (Def_Id);
3476 -- Default initialization required, and no expression present
3480 -- Expand Initialize call for controlled objects. One may wonder why
3481 -- the Initialize Call is not done in the regular Init procedure
3482 -- attached to the record type. That's because the init procedure is
3483 -- recursively called on each component, including _Parent, thus the
3484 -- Init call for a controlled object would generate not only one
3485 -- Initialize call as it is required but one for each ancestor of
3486 -- its type. This processing is suppressed if No_Initialization set.
3488 if not Controlled_Type (Typ)
3489 or else No_Initialization (N)
3493 elsif not Abort_Allowed
3494 or else not Comes_From_Source (N)
3496 Insert_Actions_After (N,
3498 Ref => New_Occurrence_Of (Def_Id, Loc),
3499 Typ => Base_Type (Typ),
3500 Flist_Ref => Find_Final_List (Def_Id),
3501 With_Attach => Make_Integer_Literal (Loc, 1)));
3506 -- We need to protect the initialize call
3510 -- Initialize (...);
3512 -- Undefer_Abort.all;
3515 -- ??? this won't protect the initialize call for controlled
3516 -- components which are part of the init proc, so this block
3517 -- should probably also contain the call to _init_proc but this
3518 -- requires some code reorganization...
3521 L : constant List_Id :=
3523 Ref => New_Occurrence_Of (Def_Id, Loc),
3524 Typ => Base_Type (Typ),
3525 Flist_Ref => Find_Final_List (Def_Id),
3526 With_Attach => Make_Integer_Literal (Loc, 1));
3528 Blk : constant Node_Id :=
3529 Make_Block_Statement (Loc,
3530 Handled_Statement_Sequence =>
3531 Make_Handled_Sequence_Of_Statements (Loc, L));
3534 Prepend_To (L, Build_Runtime_Call (Loc, RE_Abort_Defer));
3535 Set_At_End_Proc (Handled_Statement_Sequence (Blk),
3536 New_Occurrence_Of (RTE (RE_Abort_Undefer_Direct), Loc));
3537 Insert_Actions_After (N, New_List (Blk));
3538 Expand_At_End_Handler
3539 (Handled_Statement_Sequence (Blk), Entity (Identifier (Blk)));
3543 -- Call type initialization procedure if there is one. We build the
3544 -- call and put it immediately after the object declaration, so that
3545 -- it will be expanded in the usual manner. Note that this will
3546 -- result in proper handling of defaulted discriminants. The call
3547 -- to the Init_Proc is suppressed if No_Initialization is set.
3549 if Has_Non_Null_Base_Init_Proc (Typ)
3550 and then not No_Initialization (N)
3552 -- The call to the initialization procedure does NOT freeze
3553 -- the object being initialized. This is because the call is
3554 -- not a source level call. This works fine, because the only
3555 -- possible statements depending on freeze status that can
3556 -- appear after the _Init call are rep clauses which can
3557 -- safely appear after actual references to the object.
3559 Id_Ref := New_Reference_To (Def_Id, Loc);
3560 Set_Must_Not_Freeze (Id_Ref);
3561 Set_Assignment_OK (Id_Ref);
3563 Insert_Actions_After (N,
3564 Build_Initialization_Call (Loc, Id_Ref, Typ));
3566 -- If simple initialization is required, then set an appropriate
3567 -- simple initialization expression in place. This special
3568 -- initialization is required even though No_Init_Flag is present.
3570 -- An internally generated temporary needs no initialization because
3571 -- it will be assigned subsequently. In particular, there is no
3572 -- point in applying Initialize_Scalars to such a temporary.
3574 elsif Needs_Simple_Initialization (Typ)
3575 and then not Is_Internal (Def_Id)
3577 Set_No_Initialization (N, False);
3578 Set_Expression (N, Get_Simple_Init_Val (Typ, Loc, Esize (Def_Id)));
3579 Analyze_And_Resolve (Expression (N), Typ);
3582 -- Generate attribute for Persistent_BSS if needed
3587 if Persistent_BSS_Mode
3588 and then Comes_From_Source (N)
3589 and then Is_Potentially_Persistent_Type (Typ)
3590 and then Is_Library_Level_Entity (Def_Id)
3593 Make_Linker_Section_Pragma
3594 (Def_Id, Sloc (N), ".persistent.bss");
3595 Insert_After (N, Prag);
3600 -- Explicit initialization present
3603 -- Obtain actual expression from qualified expression
3605 if Nkind (Expr) = N_Qualified_Expression then
3606 Expr_Q := Expression (Expr);
3611 -- When we have the appropriate type of aggregate in the
3612 -- expression (it has been determined during analysis of the
3613 -- aggregate by setting the delay flag), let's perform in
3614 -- place assignment and thus avoid creating a temporary.
3616 if Is_Delayed_Aggregate (Expr_Q) then
3617 Convert_Aggr_In_Object_Decl (N);
3620 -- In most cases, we must check that the initial value meets
3621 -- any constraint imposed by the declared type. However, there
3622 -- is one very important exception to this rule. If the entity
3623 -- has an unconstrained nominal subtype, then it acquired its
3624 -- constraints from the expression in the first place, and not
3625 -- only does this mean that the constraint check is not needed,
3626 -- but an attempt to perform the constraint check can
3627 -- cause order of elaboration problems.
3629 if not Is_Constr_Subt_For_U_Nominal (Typ) then
3631 -- If this is an allocator for an aggregate that has been
3632 -- allocated in place, delay checks until assignments are
3633 -- made, because the discriminants are not initialized.
3635 if Nkind (Expr) = N_Allocator
3636 and then No_Initialization (Expr)
3640 Apply_Constraint_Check (Expr, Typ);
3644 -- If the type is controlled we attach the object to the final
3645 -- list and adjust the target after the copy. This
3647 if Controlled_Type (Typ) then
3653 -- Attach the result to a dummy final list which will never
3654 -- be finalized if Delay_Finalize_Attachis set. It is
3655 -- important to attach to a dummy final list rather than
3656 -- not attaching at all in order to reset the pointers
3657 -- coming from the initial value. Equivalent code exists
3658 -- in the sec-stack case in Exp_Ch4.Expand_N_Allocator.
3660 if Delay_Finalize_Attach (N) then
3662 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
3664 Make_Object_Declaration (Loc,
3665 Defining_Identifier => F,
3666 Object_Definition =>
3667 New_Reference_To (RTE (RE_Finalizable_Ptr), Loc)));
3669 Flist := New_Reference_To (F, Loc);
3672 Flist := Find_Final_List (Def_Id);
3675 Insert_Actions_After (N,
3677 Ref => New_Reference_To (Def_Id, Loc),
3678 Typ => Base_Type (Typ),
3680 With_Attach => Make_Integer_Literal (Loc, 1)));
3684 -- For tagged types, when an init value is given, the tag has to
3685 -- be re-initialized separately in order to avoid the propagation
3686 -- of a wrong tag coming from a view conversion unless the type
3687 -- is class wide (in this case the tag comes from the init
3688 -- value). Suppress the tag assignment when Java_VM because JVM
3689 -- tags are represented implicitly in objects. Ditto for types
3690 -- that are CPP_CLASS, and for initializations that are
3691 -- aggregates, because they have to have the right tag.
3693 if Is_Tagged_Type (Typ)
3694 and then not Is_Class_Wide_Type (Typ)
3695 and then not Is_CPP_Class (Typ)
3696 and then not Java_VM
3697 and then Nkind (Expr) /= N_Aggregate
3699 -- The re-assignment of the tag has to be done even if
3700 -- the object is a constant
3703 Make_Selected_Component (Loc,
3704 Prefix => New_Reference_To (Def_Id, Loc),
3706 New_Reference_To (First_Tag_Component (Typ), Loc));
3708 Set_Assignment_OK (New_Ref);
3711 Make_Assignment_Statement (Loc,
3714 Unchecked_Convert_To (RTE (RE_Tag),
3718 (Access_Disp_Table (Base_Type (Typ)))),
3721 -- For discrete types, set the Is_Known_Valid flag if the
3722 -- initializing value is known to be valid.
3724 elsif Is_Discrete_Type (Typ)
3725 and then Expr_Known_Valid (Expr)
3727 Set_Is_Known_Valid (Def_Id);
3729 elsif Is_Access_Type (Typ) then
3731 -- For access types set the Is_Known_Non_Null flag if the
3732 -- initializing value is known to be non-null. We can also set
3733 -- Can_Never_Be_Null if this is a constant.
3735 if Known_Non_Null (Expr) then
3736 Set_Is_Known_Non_Null (Def_Id);
3738 if Constant_Present (N) then
3739 Set_Can_Never_Be_Null (Def_Id);
3744 -- If validity checking on copies, validate initial expression
3746 if Validity_Checks_On
3747 and then Validity_Check_Copies
3749 Ensure_Valid (Expr);
3750 Set_Is_Known_Valid (Def_Id);
3754 -- Cases where the back end cannot handle the initialization
3755 -- directly. In such cases, we expand an assignment that will
3756 -- be appropriately handled by Expand_N_Assignment_Statement.
3758 -- The exclusion of the unconstrained case is wrong, but for
3759 -- now it is too much trouble ???
3761 if (Is_Possibly_Unaligned_Slice (Expr)
3762 or else (Is_Possibly_Unaligned_Object (Expr)
3763 and then not Represented_As_Scalar (Etype (Expr))))
3765 -- The exclusion of the unconstrained case is wrong, but for
3766 -- now it is too much trouble ???
3768 and then not (Is_Array_Type (Etype (Expr))
3769 and then not Is_Constrained (Etype (Expr)))
3772 Stat : constant Node_Id :=
3773 Make_Assignment_Statement (Loc,
3774 Name => New_Reference_To (Def_Id, Loc),
3775 Expression => Relocate_Node (Expr));
3777 Set_Expression (N, Empty);
3778 Set_No_Initialization (N);
3779 Set_Assignment_OK (Name (Stat));
3780 Set_No_Ctrl_Actions (Stat);
3781 Insert_After (N, Stat);
3787 -- For array type, check for size too large
3788 -- We really need this for record types too???
3790 if Is_Array_Type (Typ) then
3791 Apply_Array_Size_Check (N, Typ);
3795 when RE_Not_Available =>
3797 end Expand_N_Object_Declaration;
3799 ---------------------------------
3800 -- Expand_N_Subtype_Indication --
3801 ---------------------------------
3803 -- Add a check on the range of the subtype. The static case is partially
3804 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
3805 -- to check here for the static case in order to avoid generating
3806 -- extraneous expanded code.
3808 procedure Expand_N_Subtype_Indication (N : Node_Id) is
3809 Ran : constant Node_Id := Range_Expression (Constraint (N));
3810 Typ : constant Entity_Id := Entity (Subtype_Mark (N));
3813 if Nkind (Parent (N)) = N_Constrained_Array_Definition or else
3814 Nkind (Parent (N)) = N_Slice
3817 Apply_Range_Check (Ran, Typ);
3819 end Expand_N_Subtype_Indication;
3821 ---------------------------
3822 -- Expand_N_Variant_Part --
3823 ---------------------------
3825 -- If the last variant does not contain the Others choice, replace it with
3826 -- an N_Others_Choice node since Gigi always wants an Others. Note that we
3827 -- do not bother to call Analyze on the modified variant part, since it's
3828 -- only effect would be to compute the contents of the
3829 -- Others_Discrete_Choices node laboriously, and of course we already know
3830 -- the list of choices that corresponds to the others choice (it's the
3831 -- list we are replacing!)
3833 procedure Expand_N_Variant_Part (N : Node_Id) is
3834 Last_Var : constant Node_Id := Last_Non_Pragma (Variants (N));
3835 Others_Node : Node_Id;
3837 if Nkind (First (Discrete_Choices (Last_Var))) /= N_Others_Choice then
3838 Others_Node := Make_Others_Choice (Sloc (Last_Var));
3839 Set_Others_Discrete_Choices
3840 (Others_Node, Discrete_Choices (Last_Var));
3841 Set_Discrete_Choices (Last_Var, New_List (Others_Node));
3843 end Expand_N_Variant_Part;
3845 ---------------------------------
3846 -- Expand_Previous_Access_Type --
3847 ---------------------------------
3849 procedure Expand_Previous_Access_Type (Def_Id : Entity_Id) is
3850 T : Entity_Id := First_Entity (Current_Scope);
3853 -- Find all access types declared in the current scope, whose
3854 -- designated type is Def_Id.
3856 while Present (T) loop
3857 if Is_Access_Type (T)
3858 and then Designated_Type (T) = Def_Id
3860 Build_Master_Entity (Def_Id);
3861 Build_Master_Renaming (Parent (Def_Id), T);
3866 end Expand_Previous_Access_Type;
3868 ------------------------------
3869 -- Expand_Record_Controller --
3870 ------------------------------
3872 procedure Expand_Record_Controller (T : Entity_Id) is
3873 Def : Node_Id := Type_Definition (Parent (T));
3874 Comp_List : Node_Id;
3875 Comp_Decl : Node_Id;
3877 First_Comp : Node_Id;
3878 Controller_Type : Entity_Id;
3882 if Nkind (Def) = N_Derived_Type_Definition then
3883 Def := Record_Extension_Part (Def);
3886 if Null_Present (Def) then
3887 Set_Component_List (Def,
3888 Make_Component_List (Sloc (Def),
3889 Component_Items => Empty_List,
3890 Variant_Part => Empty,
3891 Null_Present => True));
3894 Comp_List := Component_List (Def);
3896 if Null_Present (Comp_List)
3897 or else Is_Empty_List (Component_Items (Comp_List))
3899 Loc := Sloc (Comp_List);
3901 Loc := Sloc (First (Component_Items (Comp_List)));
3904 if Is_Return_By_Reference_Type (T) then
3905 Controller_Type := RTE (RE_Limited_Record_Controller);
3907 Controller_Type := RTE (RE_Record_Controller);
3910 Ent := Make_Defining_Identifier (Loc, Name_uController);
3913 Make_Component_Declaration (Loc,
3914 Defining_Identifier => Ent,
3915 Component_Definition =>
3916 Make_Component_Definition (Loc,
3917 Aliased_Present => False,
3918 Subtype_Indication => New_Reference_To (Controller_Type, Loc)));
3920 if Null_Present (Comp_List)
3921 or else Is_Empty_List (Component_Items (Comp_List))
3923 Set_Component_Items (Comp_List, New_List (Comp_Decl));
3924 Set_Null_Present (Comp_List, False);
3927 -- The controller cannot be placed before the _Parent field since
3928 -- gigi lays out field in order and _parent must be first to
3929 -- preserve the polymorphism of tagged types.
3931 First_Comp := First (Component_Items (Comp_List));
3933 if Chars (Defining_Identifier (First_Comp)) /= Name_uParent
3934 and then Chars (Defining_Identifier (First_Comp)) /= Name_uTag
3936 Insert_Before (First_Comp, Comp_Decl);
3938 Insert_After (First_Comp, Comp_Decl);
3943 Analyze (Comp_Decl);
3944 Set_Ekind (Ent, E_Component);
3945 Init_Component_Location (Ent);
3947 -- Move the _controller entity ahead in the list of internal entities
3948 -- of the enclosing record so that it is selected instead of a
3949 -- potentially inherited one.
3952 E : constant Entity_Id := Last_Entity (T);
3956 pragma Assert (Chars (E) = Name_uController);
3958 Set_Next_Entity (E, First_Entity (T));
3959 Set_First_Entity (T, E);
3961 Comp := Next_Entity (E);
3962 while Next_Entity (Comp) /= E loop
3966 Set_Next_Entity (Comp, Empty);
3967 Set_Last_Entity (T, Comp);
3973 when RE_Not_Available =>
3975 end Expand_Record_Controller;
3977 ------------------------
3978 -- Expand_Tagged_Root --
3979 ------------------------
3981 procedure Expand_Tagged_Root (T : Entity_Id) is
3982 Def : constant Node_Id := Type_Definition (Parent (T));
3983 Comp_List : Node_Id;
3984 Comp_Decl : Node_Id;
3985 Sloc_N : Source_Ptr;
3988 if Null_Present (Def) then
3989 Set_Component_List (Def,
3990 Make_Component_List (Sloc (Def),
3991 Component_Items => Empty_List,
3992 Variant_Part => Empty,
3993 Null_Present => True));
3996 Comp_List := Component_List (Def);
3998 if Null_Present (Comp_List)
3999 or else Is_Empty_List (Component_Items (Comp_List))
4001 Sloc_N := Sloc (Comp_List);
4003 Sloc_N := Sloc (First (Component_Items (Comp_List)));
4007 Make_Component_Declaration (Sloc_N,
4008 Defining_Identifier => First_Tag_Component (T),
4009 Component_Definition =>
4010 Make_Component_Definition (Sloc_N,
4011 Aliased_Present => False,
4012 Subtype_Indication => New_Reference_To (RTE (RE_Tag), Sloc_N)));
4014 if Null_Present (Comp_List)
4015 or else Is_Empty_List (Component_Items (Comp_List))
4017 Set_Component_Items (Comp_List, New_List (Comp_Decl));
4018 Set_Null_Present (Comp_List, False);
4021 Insert_Before (First (Component_Items (Comp_List)), Comp_Decl);
4024 -- We don't Analyze the whole expansion because the tag component has
4025 -- already been analyzed previously. Here we just insure that the tree
4026 -- is coherent with the semantic decoration
4028 Find_Type (Subtype_Indication (Component_Definition (Comp_Decl)));
4031 when RE_Not_Available =>
4033 end Expand_Tagged_Root;
4035 -----------------------
4036 -- Freeze_Array_Type --
4037 -----------------------
4039 procedure Freeze_Array_Type (N : Node_Id) is
4040 Typ : constant Entity_Id := Entity (N);
4041 Base : constant Entity_Id := Base_Type (Typ);
4044 if not Is_Bit_Packed_Array (Typ) then
4046 -- If the component contains tasks, so does the array type. This may
4047 -- not be indicated in the array type because the component may have
4048 -- been a private type at the point of definition. Same if component
4049 -- type is controlled.
4051 Set_Has_Task (Base, Has_Task (Component_Type (Typ)));
4052 Set_Has_Controlled_Component (Base,
4053 Has_Controlled_Component (Component_Type (Typ))
4054 or else Is_Controlled (Component_Type (Typ)));
4056 if No (Init_Proc (Base)) then
4058 -- If this is an anonymous array created for a declaration with
4059 -- an initial value, its init_proc will never be called. The
4060 -- initial value itself may have been expanded into assign-
4061 -- ments, in which case the object declaration is carries the
4062 -- No_Initialization flag.
4065 and then Nkind (Associated_Node_For_Itype (Base)) =
4066 N_Object_Declaration
4067 and then (Present (Expression (Associated_Node_For_Itype (Base)))
4069 No_Initialization (Associated_Node_For_Itype (Base)))
4073 -- We do not need an init proc for string or wide [wide] string,
4074 -- since the only time these need initialization in normalize or
4075 -- initialize scalars mode, and these types are treated specially
4076 -- and do not need initialization procedures.
4078 elsif Root_Type (Base) = Standard_String
4079 or else Root_Type (Base) = Standard_Wide_String
4080 or else Root_Type (Base) = Standard_Wide_Wide_String
4084 -- Otherwise we have to build an init proc for the subtype
4087 Build_Array_Init_Proc (Base, N);
4091 if Typ = Base and then Has_Controlled_Component (Base) then
4092 Build_Controlling_Procs (Base);
4094 if not Is_Limited_Type (Component_Type (Typ))
4095 and then Number_Dimensions (Typ) = 1
4097 Build_Slice_Assignment (Typ);
4101 -- For packed case, there is a default initialization, except if the
4102 -- component type is itself a packed structure with an initialization
4105 elsif Present (Init_Proc (Component_Type (Base)))
4106 and then No (Base_Init_Proc (Base))
4108 Build_Array_Init_Proc (Base, N);
4110 end Freeze_Array_Type;
4112 -----------------------------
4113 -- Freeze_Enumeration_Type --
4114 -----------------------------
4116 procedure Freeze_Enumeration_Type (N : Node_Id) is
4117 Typ : constant Entity_Id := Entity (N);
4118 Loc : constant Source_Ptr := Sloc (Typ);
4125 Is_Contiguous : Boolean;
4130 pragma Warnings (Off, Func);
4133 -- Various optimization are possible if the given representation is
4136 Is_Contiguous := True;
4137 Ent := First_Literal (Typ);
4138 Last_Repval := Enumeration_Rep (Ent);
4141 while Present (Ent) loop
4142 if Enumeration_Rep (Ent) - Last_Repval /= 1 then
4143 Is_Contiguous := False;
4146 Last_Repval := Enumeration_Rep (Ent);
4152 if Is_Contiguous then
4153 Set_Has_Contiguous_Rep (Typ);
4154 Ent := First_Literal (Typ);
4156 Lst := New_List (New_Reference_To (Ent, Sloc (Ent)));
4159 -- Build list of literal references
4164 Ent := First_Literal (Typ);
4165 while Present (Ent) loop
4166 Append_To (Lst, New_Reference_To (Ent, Sloc (Ent)));
4172 -- Now build an array declaration
4174 -- typA : array (Natural range 0 .. num - 1) of ctype :=
4175 -- (v, v, v, v, v, ....)
4177 -- where ctype is the corresponding integer type. If the representation
4178 -- is contiguous, we only keep the first literal, which provides the
4179 -- offset for Pos_To_Rep computations.
4182 Make_Defining_Identifier (Loc,
4183 Chars => New_External_Name (Chars (Typ), 'A'));
4185 Append_Freeze_Action (Typ,
4186 Make_Object_Declaration (Loc,
4187 Defining_Identifier => Arr,
4188 Constant_Present => True,
4190 Object_Definition =>
4191 Make_Constrained_Array_Definition (Loc,
4192 Discrete_Subtype_Definitions => New_List (
4193 Make_Subtype_Indication (Loc,
4194 Subtype_Mark => New_Reference_To (Standard_Natural, Loc),
4196 Make_Range_Constraint (Loc,
4200 Make_Integer_Literal (Loc, 0),
4202 Make_Integer_Literal (Loc, Num - 1))))),
4204 Component_Definition =>
4205 Make_Component_Definition (Loc,
4206 Aliased_Present => False,
4207 Subtype_Indication => New_Reference_To (Typ, Loc))),
4210 Make_Aggregate (Loc,
4211 Expressions => Lst)));
4213 Set_Enum_Pos_To_Rep (Typ, Arr);
4215 -- Now we build the function that converts representation values to
4216 -- position values. This function has the form:
4218 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
4221 -- when enum-lit'Enum_Rep => return posval;
4222 -- when enum-lit'Enum_Rep => return posval;
4225 -- [raise Constraint_Error when F "invalid data"]
4230 -- Note: the F parameter determines whether the others case (no valid
4231 -- representation) raises Constraint_Error or returns a unique value
4232 -- of minus one. The latter case is used, e.g. in 'Valid code.
4234 -- Note: the reason we use Enum_Rep values in the case here is to avoid
4235 -- the code generator making inappropriate assumptions about the range
4236 -- of the values in the case where the value is invalid. ityp is a
4237 -- signed or unsigned integer type of appropriate width.
4239 -- Note: if exceptions are not supported, then we suppress the raise
4240 -- and return -1 unconditionally (this is an erroneous program in any
4241 -- case and there is no obligation to raise Constraint_Error here!) We
4242 -- also do this if pragma Restrictions (No_Exceptions) is active.
4244 -- Representations are signed
4246 if Enumeration_Rep (First_Literal (Typ)) < 0 then
4248 -- The underlying type is signed. Reset the Is_Unsigned_Type
4249 -- explicitly, because it might have been inherited from
4252 Set_Is_Unsigned_Type (Typ, False);
4254 if Esize (Typ) <= Standard_Integer_Size then
4255 Ityp := Standard_Integer;
4257 Ityp := Universal_Integer;
4260 -- Representations are unsigned
4263 if Esize (Typ) <= Standard_Integer_Size then
4264 Ityp := RTE (RE_Unsigned);
4266 Ityp := RTE (RE_Long_Long_Unsigned);
4270 -- The body of the function is a case statement. First collect case
4271 -- alternatives, or optimize the contiguous case.
4275 -- If representation is contiguous, Pos is computed by subtracting
4276 -- the representation of the first literal.
4278 if Is_Contiguous then
4279 Ent := First_Literal (Typ);
4281 if Enumeration_Rep (Ent) = Last_Repval then
4283 -- Another special case: for a single literal, Pos is zero
4285 Pos_Expr := Make_Integer_Literal (Loc, Uint_0);
4289 Convert_To (Standard_Integer,
4290 Make_Op_Subtract (Loc,
4292 Unchecked_Convert_To (Ityp,
4293 Make_Identifier (Loc, Name_uA)),
4295 Make_Integer_Literal (Loc,
4297 Enumeration_Rep (First_Literal (Typ)))));
4301 Make_Case_Statement_Alternative (Loc,
4302 Discrete_Choices => New_List (
4303 Make_Range (Sloc (Enumeration_Rep_Expr (Ent)),
4305 Make_Integer_Literal (Loc,
4306 Intval => Enumeration_Rep (Ent)),
4308 Make_Integer_Literal (Loc, Intval => Last_Repval))),
4310 Statements => New_List (
4311 Make_Return_Statement (Loc,
4312 Expression => Pos_Expr))));
4315 Ent := First_Literal (Typ);
4317 while Present (Ent) loop
4319 Make_Case_Statement_Alternative (Loc,
4320 Discrete_Choices => New_List (
4321 Make_Integer_Literal (Sloc (Enumeration_Rep_Expr (Ent)),
4322 Intval => Enumeration_Rep (Ent))),
4324 Statements => New_List (
4325 Make_Return_Statement (Loc,
4327 Make_Integer_Literal (Loc,
4328 Intval => Enumeration_Pos (Ent))))));
4334 -- In normal mode, add the others clause with the test
4336 if not Restriction_Active (No_Exception_Handlers) then
4338 Make_Case_Statement_Alternative (Loc,
4339 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
4340 Statements => New_List (
4341 Make_Raise_Constraint_Error (Loc,
4342 Condition => Make_Identifier (Loc, Name_uF),
4343 Reason => CE_Invalid_Data),
4344 Make_Return_Statement (Loc,
4346 Make_Integer_Literal (Loc, -1)))));
4348 -- If Restriction (No_Exceptions_Handlers) is active then we always
4349 -- return -1 (since we cannot usefully raise Constraint_Error in
4350 -- this case). See description above for further details.
4354 Make_Case_Statement_Alternative (Loc,
4355 Discrete_Choices => New_List (Make_Others_Choice (Loc)),
4356 Statements => New_List (
4357 Make_Return_Statement (Loc,
4359 Make_Integer_Literal (Loc, -1)))));
4362 -- Now we can build the function body
4365 Make_Defining_Identifier (Loc, Make_TSS_Name (Typ, TSS_Rep_To_Pos));
4368 Make_Subprogram_Body (Loc,
4370 Make_Function_Specification (Loc,
4371 Defining_Unit_Name => Fent,
4372 Parameter_Specifications => New_List (
4373 Make_Parameter_Specification (Loc,
4374 Defining_Identifier =>
4375 Make_Defining_Identifier (Loc, Name_uA),
4376 Parameter_Type => New_Reference_To (Typ, Loc)),
4377 Make_Parameter_Specification (Loc,
4378 Defining_Identifier =>
4379 Make_Defining_Identifier (Loc, Name_uF),
4380 Parameter_Type => New_Reference_To (Standard_Boolean, Loc))),
4382 Result_Definition => New_Reference_To (Standard_Integer, Loc)),
4384 Declarations => Empty_List,
4386 Handled_Statement_Sequence =>
4387 Make_Handled_Sequence_Of_Statements (Loc,
4388 Statements => New_List (
4389 Make_Case_Statement (Loc,
4391 Unchecked_Convert_To (Ityp,
4392 Make_Identifier (Loc, Name_uA)),
4393 Alternatives => Lst))));
4395 Set_TSS (Typ, Fent);
4398 if not Debug_Generated_Code then
4399 Set_Debug_Info_Off (Fent);
4403 when RE_Not_Available =>
4405 end Freeze_Enumeration_Type;
4407 ------------------------
4408 -- Freeze_Record_Type --
4409 ------------------------
4411 procedure Freeze_Record_Type (N : Node_Id) is
4413 Def_Id : constant Node_Id := Entity (N);
4414 Predef_List : List_Id;
4415 Type_Decl : constant Node_Id := Parent (Def_Id);
4417 Renamed_Eq : Node_Id := Empty;
4418 -- Could use some comments ???
4421 -- Build discriminant checking functions if not a derived type (for
4422 -- derived types that are not tagged types, we always use the
4423 -- discriminant checking functions of the parent type). However, for
4424 -- untagged types the derivation may have taken place before the
4425 -- parent was frozen, so we copy explicitly the discriminant checking
4426 -- functions from the parent into the components of the derived type.
4428 if not Is_Derived_Type (Def_Id)
4429 or else Has_New_Non_Standard_Rep (Def_Id)
4430 or else Is_Tagged_Type (Def_Id)
4432 Build_Discr_Checking_Funcs (Type_Decl);
4434 elsif Is_Derived_Type (Def_Id)
4435 and then not Is_Tagged_Type (Def_Id)
4437 -- If we have a derived Unchecked_Union, we do not inherit the
4438 -- discriminant checking functions from the parent type since the
4439 -- discriminants are non existent.
4441 and then not Is_Unchecked_Union (Def_Id)
4442 and then Has_Discriminants (Def_Id)
4445 Old_Comp : Entity_Id;
4449 First_Component (Base_Type (Underlying_Type (Etype (Def_Id))));
4450 Comp := First_Component (Def_Id);
4451 while Present (Comp) loop
4452 if Ekind (Comp) = E_Component
4453 and then Chars (Comp) = Chars (Old_Comp)
4455 Set_Discriminant_Checking_Func (Comp,
4456 Discriminant_Checking_Func (Old_Comp));
4459 Next_Component (Old_Comp);
4460 Next_Component (Comp);
4465 if Is_Derived_Type (Def_Id)
4466 and then Is_Limited_Type (Def_Id)
4467 and then Is_Tagged_Type (Def_Id)
4469 Check_Stream_Attributes (Def_Id);
4472 -- Update task and controlled component flags, because some of the
4473 -- component types may have been private at the point of the record
4476 Comp := First_Component (Def_Id);
4478 while Present (Comp) loop
4479 if Has_Task (Etype (Comp)) then
4480 Set_Has_Task (Def_Id);
4482 elsif Has_Controlled_Component (Etype (Comp))
4483 or else (Chars (Comp) /= Name_uParent
4484 and then Is_Controlled (Etype (Comp)))
4486 Set_Has_Controlled_Component (Def_Id);
4489 Next_Component (Comp);
4492 -- Creation of the Dispatch Table. Note that a Dispatch Table is
4493 -- created for regular tagged types as well as for Ada types deriving
4494 -- from a C++ Class, but not for tagged types directly corresponding to
4495 -- the C++ classes. In the later case we assume that the Vtable is
4496 -- created in the C++ side and we just use it.
4498 if Is_Tagged_Type (Def_Id) then
4500 if Is_CPP_Class (Def_Id) then
4501 Set_All_DT_Position (Def_Id);
4502 Set_Default_Constructor (Def_Id);
4505 -- Usually inherited primitives are not delayed but the first Ada
4506 -- extension of a CPP_Class is an exception since the address of
4507 -- the inherited subprogram has to be inserted in the new Ada
4508 -- Dispatch Table and this is a freezing action (usually the
4509 -- inherited primitive address is inserted in the DT by
4512 -- Similarly, if this is an inherited operation whose parent is
4513 -- not frozen yet, it is not in the DT of the parent, and we
4514 -- generate an explicit freeze node for the inherited operation,
4515 -- so that it is properly inserted in the DT of the current type.
4518 Elmt : Elmt_Id := First_Elmt (Primitive_Operations (Def_Id));
4522 while Present (Elmt) loop
4523 Subp := Node (Elmt);
4525 if Present (Alias (Subp)) then
4526 if Is_CPP_Class (Etype (Def_Id)) then
4527 Set_Has_Delayed_Freeze (Subp);
4529 elsif Has_Delayed_Freeze (Alias (Subp))
4530 and then not Is_Frozen (Alias (Subp))
4532 Set_Is_Frozen (Subp, False);
4533 Set_Has_Delayed_Freeze (Subp);
4541 if Underlying_Type (Etype (Def_Id)) = Def_Id then
4542 Expand_Tagged_Root (Def_Id);
4545 -- Unfreeze momentarily the type to add the predefined primitives
4546 -- operations. The reason we unfreeze is so that these predefined
4547 -- operations will indeed end up as primitive operations (which
4548 -- must be before the freeze point).
4550 Set_Is_Frozen (Def_Id, False);
4551 Make_Predefined_Primitive_Specs
4552 (Def_Id, Predef_List, Renamed_Eq);
4553 Insert_List_Before_And_Analyze (N, Predef_List);
4555 Set_Is_Frozen (Def_Id, True);
4556 Set_All_DT_Position (Def_Id);
4558 -- Add the controlled component before the freezing actions
4559 -- referenced in those actions.
4561 if Has_New_Controlled_Component (Def_Id) then
4562 Expand_Record_Controller (Def_Id);
4565 -- Suppress creation of a dispatch table when Java_VM because the
4566 -- dispatching mechanism is handled internally by the JVM.
4570 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4573 ADT : Elist_Id := Access_Disp_Table (Def_Id);
4575 procedure Add_Secondary_Tables (Typ : Entity_Id);
4576 -- Internal subprogram, recursively climb to the ancestors
4578 --------------------------
4579 -- Add_Secondary_Tables --
4580 --------------------------
4582 procedure Add_Secondary_Tables (Typ : Entity_Id) is
4589 -- Climb to the ancestor (if any) handling private types
4591 if Present (Full_View (Etype (Typ))) then
4592 if Full_View (Etype (Typ)) /= Typ then
4593 Add_Secondary_Tables (Full_View (Etype (Typ)));
4596 elsif Etype (Typ) /= Typ then
4597 Add_Secondary_Tables (Etype (Typ));
4600 if Present (Abstract_Interfaces (Typ))
4602 not Is_Empty_Elmt_List (Abstract_Interfaces (Typ))
4604 Iface := First_Elmt (Abstract_Interfaces (Typ));
4607 E := First_Entity (Typ);
4608 while Present (E) loop
4609 if Is_Tag (E) and then Chars (E) /= Name_uTag then
4612 Ancestor_Typ => Typ,
4613 Suffix_Index => Suffix_Index,
4614 Iface => Node (Iface),
4616 Acc_Disp_Tables => ADT,
4619 Append_Freeze_Actions (Def_Id, Result);
4620 Suffix_Index := Suffix_Index + 1;
4627 end Add_Secondary_Tables;
4629 -- Start of processing to build secondary dispatch tables
4632 -- Handle private types
4634 if Present (Full_View (Def_Id)) then
4635 Add_Secondary_Tables (Full_View (Def_Id));
4637 Add_Secondary_Tables (Def_Id);
4640 Set_Access_Disp_Table (Def_Id, ADT);
4641 Append_Freeze_Actions (Def_Id, Make_DT (Def_Id));
4645 -- Make sure that the primitives Initialize, Adjust and Finalize
4646 -- are Frozen before other TSS subprograms. We don't want them
4649 if Is_Controlled (Def_Id) then
4650 if not Is_Limited_Type (Def_Id) then
4651 Append_Freeze_Actions (Def_Id,
4653 (Find_Prim_Op (Def_Id, Name_Adjust), Sloc (Def_Id)));
4656 Append_Freeze_Actions (Def_Id,
4658 (Find_Prim_Op (Def_Id, Name_Initialize), Sloc (Def_Id)));
4660 Append_Freeze_Actions (Def_Id,
4662 (Find_Prim_Op (Def_Id, Name_Finalize), Sloc (Def_Id)));
4665 -- Freeze rest of primitive operations
4667 Append_Freeze_Actions
4668 (Def_Id, Predefined_Primitive_Freeze (Def_Id));
4669 Append_Freeze_Actions
4670 (Def_Id, Init_Predefined_Interface_Primitives (Def_Id));
4673 -- In the non-tagged case, an equality function is provided only for
4674 -- variant records (that are not unchecked unions).
4676 elsif Has_Discriminants (Def_Id)
4677 and then not Is_Limited_Type (Def_Id)
4680 Comps : constant Node_Id :=
4681 Component_List (Type_Definition (Type_Decl));
4685 and then Present (Variant_Part (Comps))
4687 Build_Variant_Record_Equality (Def_Id);
4692 -- Before building the record initialization procedure, if we are
4693 -- dealing with a concurrent record value type, then we must go through
4694 -- the discriminants, exchanging discriminals between the concurrent
4695 -- type and the concurrent record value type. See the section "Handling
4696 -- of Discriminants" in the Einfo spec for details.
4698 if Is_Concurrent_Record_Type (Def_Id)
4699 and then Has_Discriminants (Def_Id)
4702 Ctyp : constant Entity_Id :=
4703 Corresponding_Concurrent_Type (Def_Id);
4704 Conc_Discr : Entity_Id;
4705 Rec_Discr : Entity_Id;
4709 Conc_Discr := First_Discriminant (Ctyp);
4710 Rec_Discr := First_Discriminant (Def_Id);
4712 while Present (Conc_Discr) loop
4713 Temp := Discriminal (Conc_Discr);
4714 Set_Discriminal (Conc_Discr, Discriminal (Rec_Discr));
4715 Set_Discriminal (Rec_Discr, Temp);
4717 Set_Discriminal_Link (Discriminal (Conc_Discr), Conc_Discr);
4718 Set_Discriminal_Link (Discriminal (Rec_Discr), Rec_Discr);
4720 Next_Discriminant (Conc_Discr);
4721 Next_Discriminant (Rec_Discr);
4726 if Has_Controlled_Component (Def_Id) then
4727 if No (Controller_Component (Def_Id)) then
4728 Expand_Record_Controller (Def_Id);
4731 Build_Controlling_Procs (Def_Id);
4734 Adjust_Discriminants (Def_Id);
4735 Build_Record_Init_Proc (Type_Decl, Def_Id);
4737 -- For tagged type, build bodies of primitive operations. Note that we
4738 -- do this after building the record initialization experiment, since
4739 -- the primitive operations may need the initialization routine
4741 if Is_Tagged_Type (Def_Id) then
4742 Predef_List := Predefined_Primitive_Bodies (Def_Id, Renamed_Eq);
4743 Append_Freeze_Actions (Def_Id, Predef_List);
4745 -- Populate the two auxiliary tables used for dispatching
4746 -- asynchronous, conditional and timed selects for tagged
4747 -- types that implement a limited interface.
4749 if Ada_Version >= Ada_05
4750 and then not Is_Interface (Def_Id)
4751 and then not Is_Abstract (Def_Id)
4752 and then not Is_Controlled (Def_Id)
4754 Implements_Interface
4756 Kind => Any_Limited_Interface,
4757 Check_Parent => True)
4759 Append_Freeze_Actions (Def_Id,
4760 Make_Select_Specific_Data_Table (Def_Id));
4763 end Freeze_Record_Type;
4765 ------------------------------
4766 -- Freeze_Stream_Operations --
4767 ------------------------------
4769 procedure Freeze_Stream_Operations (N : Node_Id; Typ : Entity_Id) is
4770 Names : constant array (1 .. 4) of TSS_Name_Type :=
4775 Stream_Op : Entity_Id;
4778 -- Primitive operations of tagged types are frozen when the dispatch
4779 -- table is constructed.
4781 if not Comes_From_Source (Typ)
4782 or else Is_Tagged_Type (Typ)
4787 for J in Names'Range loop
4788 Stream_Op := TSS (Typ, Names (J));
4790 if Present (Stream_Op)
4791 and then Is_Subprogram (Stream_Op)
4792 and then Nkind (Unit_Declaration_Node (Stream_Op)) =
4793 N_Subprogram_Declaration
4794 and then not Is_Frozen (Stream_Op)
4796 Append_Freeze_Actions
4797 (Typ, Freeze_Entity (Stream_Op, Sloc (N)));
4800 end Freeze_Stream_Operations;
4806 -- Full type declarations are expanded at the point at which the type is
4807 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
4808 -- declarations generated by the freezing (e.g. the procedure generated
4809 -- for initialization) are chained in the Actions field list of the freeze
4810 -- node using Append_Freeze_Actions.
4812 function Freeze_Type (N : Node_Id) return Boolean is
4813 Def_Id : constant Entity_Id := Entity (N);
4814 RACW_Seen : Boolean := False;
4815 Result : Boolean := False;
4818 -- Process associated access types needing special processing
4820 if Present (Access_Types_To_Process (N)) then
4822 E : Elmt_Id := First_Elmt (Access_Types_To_Process (N));
4824 while Present (E) loop
4826 if Is_Remote_Access_To_Class_Wide_Type (Node (E)) then
4836 -- If there are RACWs designating this type, make stubs now
4838 Remote_Types_Tagged_Full_View_Encountered (Def_Id);
4842 -- Freeze processing for record types
4844 if Is_Record_Type (Def_Id) then
4845 if Ekind (Def_Id) = E_Record_Type then
4846 Freeze_Record_Type (N);
4848 -- The subtype may have been declared before the type was frozen. If
4849 -- the type has controlled components it is necessary to create the
4850 -- entity for the controller explicitly because it did not exist at
4851 -- the point of the subtype declaration. Only the entity is needed,
4852 -- the back-end will obtain the layout from the type. This is only
4853 -- necessary if this is constrained subtype whose component list is
4854 -- not shared with the base type.
4856 elsif Ekind (Def_Id) = E_Record_Subtype
4857 and then Has_Discriminants (Def_Id)
4858 and then Last_Entity (Def_Id) /= Last_Entity (Base_Type (Def_Id))
4859 and then Present (Controller_Component (Def_Id))
4862 Old_C : constant Entity_Id := Controller_Component (Def_Id);
4866 if Scope (Old_C) = Base_Type (Def_Id) then
4868 -- The entity is the one in the parent. Create new one
4870 New_C := New_Copy (Old_C);
4871 Set_Parent (New_C, Parent (Old_C));
4878 if Is_Itype (Def_Id)
4879 and then Is_Record_Type (Underlying_Type (Scope (Def_Id)))
4881 -- The freeze node is only used to introduce the controller,
4882 -- the back-end has no use for it for a discriminated
4885 Set_Freeze_Node (Def_Id, Empty);
4886 Set_Has_Delayed_Freeze (Def_Id, False);
4890 -- Similar process if the controller of the subtype is not present
4891 -- but the parent has it. This can happen with constrained
4892 -- record components where the subtype is an itype.
4894 elsif Ekind (Def_Id) = E_Record_Subtype
4895 and then Is_Itype (Def_Id)
4896 and then No (Controller_Component (Def_Id))
4897 and then Present (Controller_Component (Etype (Def_Id)))
4900 Old_C : constant Entity_Id :=
4901 Controller_Component (Etype (Def_Id));
4902 New_C : constant Entity_Id := New_Copy (Old_C);
4905 Set_Next_Entity (New_C, First_Entity (Def_Id));
4906 Set_First_Entity (Def_Id, New_C);
4908 -- The freeze node is only used to introduce the controller,
4909 -- the back-end has no use for it for a discriminated
4912 Set_Freeze_Node (Def_Id, Empty);
4913 Set_Has_Delayed_Freeze (Def_Id, False);
4918 -- Freeze processing for array types
4920 elsif Is_Array_Type (Def_Id) then
4921 Freeze_Array_Type (N);
4923 -- Freeze processing for access types
4925 -- For pool-specific access types, find out the pool object used for
4926 -- this type, needs actual expansion of it in some cases. Here are the
4927 -- different cases :
4929 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
4930 -- ---> don't use any storage pool
4932 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
4934 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
4936 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
4937 -- ---> Storage Pool is the specified one
4939 -- See GNAT Pool packages in the Run-Time for more details
4941 elsif Ekind (Def_Id) = E_Access_Type
4942 or else Ekind (Def_Id) = E_General_Access_Type
4945 Loc : constant Source_Ptr := Sloc (N);
4946 Desig_Type : constant Entity_Id := Designated_Type (Def_Id);
4947 Pool_Object : Entity_Id;
4950 Freeze_Action_Typ : Entity_Id;
4953 if Has_Storage_Size_Clause (Def_Id) then
4954 Siz_Exp := Expression (Parent (Storage_Size_Variable (Def_Id)));
4961 -- Rep Clause "for Def_Id'Storage_Size use 0;"
4962 -- ---> don't use any storage pool
4964 if Has_Storage_Size_Clause (Def_Id)
4965 and then Compile_Time_Known_Value (Siz_Exp)
4966 and then Expr_Value (Siz_Exp) = 0
4972 -- Rep Clause : for Def_Id'Storage_Size use Expr.
4974 -- Def_Id__Pool : Stack_Bounded_Pool
4975 -- (Expr, DT'Size, DT'Alignment);
4977 elsif Has_Storage_Size_Clause (Def_Id) then
4983 -- For unconstrained composite types we give a size of zero
4984 -- so that the pool knows that it needs a special algorithm
4985 -- for variable size object allocation.
4987 if Is_Composite_Type (Desig_Type)
4988 and then not Is_Constrained (Desig_Type)
4991 Make_Integer_Literal (Loc, 0);
4994 Make_Integer_Literal (Loc, Maximum_Alignment);
4998 Make_Attribute_Reference (Loc,
4999 Prefix => New_Reference_To (Desig_Type, Loc),
5000 Attribute_Name => Name_Max_Size_In_Storage_Elements);
5003 Make_Attribute_Reference (Loc,
5004 Prefix => New_Reference_To (Desig_Type, Loc),
5005 Attribute_Name => Name_Alignment);
5009 Make_Defining_Identifier (Loc,
5010 Chars => New_External_Name (Chars (Def_Id), 'P'));
5012 -- We put the code associated with the pools in the entity
5013 -- that has the later freeze node, usually the acces type
5014 -- but it can also be the designated_type; because the pool
5015 -- code requires both those types to be frozen
5017 if Is_Frozen (Desig_Type)
5018 and then (not Present (Freeze_Node (Desig_Type))
5019 or else Analyzed (Freeze_Node (Desig_Type)))
5021 Freeze_Action_Typ := Def_Id;
5023 -- A Taft amendment type cannot get the freeze actions
5024 -- since the full view is not there.
5026 elsif Is_Incomplete_Or_Private_Type (Desig_Type)
5027 and then No (Full_View (Desig_Type))
5029 Freeze_Action_Typ := Def_Id;
5032 Freeze_Action_Typ := Desig_Type;
5035 Append_Freeze_Action (Freeze_Action_Typ,
5036 Make_Object_Declaration (Loc,
5037 Defining_Identifier => Pool_Object,
5038 Object_Definition =>
5039 Make_Subtype_Indication (Loc,
5042 (RTE (RE_Stack_Bounded_Pool), Loc),
5045 Make_Index_Or_Discriminant_Constraint (Loc,
5046 Constraints => New_List (
5048 -- First discriminant is the Pool Size
5051 Storage_Size_Variable (Def_Id), Loc),
5053 -- Second discriminant is the element size
5057 -- Third discriminant is the alignment
5062 Set_Associated_Storage_Pool (Def_Id, Pool_Object);
5066 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
5067 -- ---> Storage Pool is the specified one
5069 elsif Present (Associated_Storage_Pool (Def_Id)) then
5071 -- Nothing to do the associated storage pool has been attached
5072 -- when analyzing the rep. clause
5077 -- For access-to-controlled types (including class-wide types and
5078 -- Taft-amendment types which potentially have controlled
5079 -- components), expand the list controller object that will store
5080 -- the dynamically allocated objects. Do not do this
5081 -- transformation for expander-generated access types, but do it
5082 -- for types that are the full view of types derived from other
5083 -- private types. Also suppress the list controller in the case
5084 -- of a designated type with convention Java, since this is used
5085 -- when binding to Java API specs, where there's no equivalent of
5086 -- a finalization list and we don't want to pull in the
5087 -- finalization support if not needed.
5089 if not Comes_From_Source (Def_Id)
5090 and then not Has_Private_Declaration (Def_Id)
5094 elsif (Controlled_Type (Desig_Type)
5095 and then Convention (Desig_Type) /= Convention_Java)
5097 (Is_Incomplete_Or_Private_Type (Desig_Type)
5098 and then No (Full_View (Desig_Type))
5100 -- An exception is made for types defined in the run-time
5101 -- because Ada.Tags.Tag itself is such a type and cannot
5102 -- afford this unnecessary overhead that would generates a
5103 -- loop in the expansion scheme...
5105 and then not In_Runtime (Def_Id)
5107 -- Another exception is if Restrictions (No_Finalization)
5108 -- is active, since then we know nothing is controlled.
5110 and then not Restriction_Active (No_Finalization))
5112 -- If the designated type is not frozen yet, its controlled
5113 -- status must be retrieved explicitly.
5115 or else (Is_Array_Type (Desig_Type)
5116 and then not Is_Frozen (Desig_Type)
5117 and then Controlled_Type (Component_Type (Desig_Type)))
5119 Set_Associated_Final_Chain (Def_Id,
5120 Make_Defining_Identifier (Loc,
5121 New_External_Name (Chars (Def_Id), 'L')));
5123 Append_Freeze_Action (Def_Id,
5124 Make_Object_Declaration (Loc,
5125 Defining_Identifier => Associated_Final_Chain (Def_Id),
5126 Object_Definition =>
5127 New_Reference_To (RTE (RE_List_Controller), Loc)));
5131 -- Freeze processing for enumeration types
5133 elsif Ekind (Def_Id) = E_Enumeration_Type then
5135 -- We only have something to do if we have a non-standard
5136 -- representation (i.e. at least one literal whose pos value
5137 -- is not the same as its representation)
5139 if Has_Non_Standard_Rep (Def_Id) then
5140 Freeze_Enumeration_Type (N);
5143 -- Private types that are completed by a derivation from a private
5144 -- type have an internally generated full view, that needs to be
5145 -- frozen. This must be done explicitly because the two views share
5146 -- the freeze node, and the underlying full view is not visible when
5147 -- the freeze node is analyzed.
5149 elsif Is_Private_Type (Def_Id)
5150 and then Is_Derived_Type (Def_Id)
5151 and then Present (Full_View (Def_Id))
5152 and then Is_Itype (Full_View (Def_Id))
5153 and then Has_Private_Declaration (Full_View (Def_Id))
5154 and then Freeze_Node (Full_View (Def_Id)) = N
5156 Set_Entity (N, Full_View (Def_Id));
5157 Result := Freeze_Type (N);
5158 Set_Entity (N, Def_Id);
5160 -- All other types require no expander action. There are such cases
5161 -- (e.g. task types and protected types). In such cases, the freeze
5162 -- nodes are there for use by Gigi.
5166 Freeze_Stream_Operations (N, Def_Id);
5170 when RE_Not_Available =>
5174 -------------------------
5175 -- Get_Simple_Init_Val --
5176 -------------------------
5178 function Get_Simple_Init_Val
5181 Size : Uint := No_Uint) return Node_Id
5188 -- This is the size to be used for computation of the appropriate
5189 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
5193 -- These are the values computed by the procedure Check_Subtype_Bounds
5195 procedure Check_Subtype_Bounds;
5196 -- This procedure examines the subtype T, and its ancestor subtypes and
5197 -- derived types to determine the best known information about the
5198 -- bounds of the subtype. After the call Lo_Bound is set either to
5199 -- No_Uint if no information can be determined, or to a value which
5200 -- represents a known low bound, i.e. a valid value of the subtype can
5201 -- not be less than this value. Hi_Bound is similarly set to a known
5202 -- high bound (valid value cannot be greater than this).
5204 --------------------------
5205 -- Check_Subtype_Bounds --
5206 --------------------------
5208 procedure Check_Subtype_Bounds is
5217 Lo_Bound := No_Uint;
5218 Hi_Bound := No_Uint;
5220 -- Loop to climb ancestor subtypes and derived types
5224 if not Is_Discrete_Type (ST1) then
5228 Lo := Type_Low_Bound (ST1);
5229 Hi := Type_High_Bound (ST1);
5231 if Compile_Time_Known_Value (Lo) then
5232 Loval := Expr_Value (Lo);
5234 if Lo_Bound = No_Uint or else Lo_Bound < Loval then
5239 if Compile_Time_Known_Value (Hi) then
5240 Hival := Expr_Value (Hi);
5242 if Hi_Bound = No_Uint or else Hi_Bound > Hival then
5247 ST2 := Ancestor_Subtype (ST1);
5253 exit when ST1 = ST2;
5256 end Check_Subtype_Bounds;
5258 -- Start of processing for Get_Simple_Init_Val
5261 -- For a private type, we should always have an underlying type
5262 -- (because this was already checked in Needs_Simple_Initialization).
5263 -- What we do is to get the value for the underlying type and then do
5264 -- an Unchecked_Convert to the private type.
5266 if Is_Private_Type (T) then
5267 Val := Get_Simple_Init_Val (Underlying_Type (T), Loc, Size);
5269 -- A special case, if the underlying value is null, then qualify it
5270 -- with the underlying type, so that the null is properly typed
5271 -- Similarly, if it is an aggregate it must be qualified, because an
5272 -- unchecked conversion does not provide a context for it.
5274 if Nkind (Val) = N_Null
5275 or else Nkind (Val) = N_Aggregate
5278 Make_Qualified_Expression (Loc,
5280 New_Occurrence_Of (Underlying_Type (T), Loc),
5284 Result := Unchecked_Convert_To (T, Val);
5286 -- Don't truncate result (important for Initialize/Normalize_Scalars)
5288 if Nkind (Result) = N_Unchecked_Type_Conversion
5289 and then Is_Scalar_Type (Underlying_Type (T))
5291 Set_No_Truncation (Result);
5296 -- For scalars, we must have normalize/initialize scalars case
5298 elsif Is_Scalar_Type (T) then
5299 pragma Assert (Init_Or_Norm_Scalars);
5301 -- Compute size of object. If it is given by the caller, we can use
5302 -- it directly, otherwise we use Esize (T) as an estimate. As far as
5303 -- we know this covers all cases correctly.
5305 if Size = No_Uint or else Size <= Uint_0 then
5306 Size_To_Use := UI_Max (Uint_1, Esize (T));
5308 Size_To_Use := Size;
5311 -- Maximum size to use is 64 bits, since we will create values
5312 -- of type Unsigned_64 and the range must fit this type.
5314 if Size_To_Use /= No_Uint and then Size_To_Use > Uint_64 then
5315 Size_To_Use := Uint_64;
5318 -- Check known bounds of subtype
5320 Check_Subtype_Bounds;
5322 -- Processing for Normalize_Scalars case
5324 if Normalize_Scalars then
5326 -- If zero is invalid, it is a convenient value to use that is
5327 -- for sure an appropriate invalid value in all situations.
5329 if Lo_Bound /= No_Uint and then Lo_Bound > Uint_0 then
5330 Val := Make_Integer_Literal (Loc, 0);
5332 -- Cases where all one bits is the appropriate invalid value
5334 -- For modular types, all 1 bits is either invalid or valid. If
5335 -- it is valid, then there is nothing that can be done since there
5336 -- are no invalid values (we ruled out zero already).
5338 -- For signed integer types that have no negative values, either
5339 -- there is room for negative values, or there is not. If there
5340 -- is, then all 1 bits may be interpretecd as minus one, which is
5341 -- certainly invalid. Alternatively it is treated as the largest
5342 -- positive value, in which case the observation for modular types
5345 -- For float types, all 1-bits is a NaN (not a number), which is
5346 -- certainly an appropriately invalid value.
5348 elsif Is_Unsigned_Type (T)
5349 or else Is_Floating_Point_Type (T)
5350 or else Is_Enumeration_Type (T)
5352 Val := Make_Integer_Literal (Loc, 2 ** Size_To_Use - 1);
5354 -- Resolve as Unsigned_64, because the largest number we
5355 -- can generate is out of range of universal integer.
5357 Analyze_And_Resolve (Val, RTE (RE_Unsigned_64));
5359 -- Case of signed types
5363 Signed_Size : constant Uint :=
5364 UI_Min (Uint_63, Size_To_Use - 1);
5367 -- Normally we like to use the most negative number. The
5368 -- one exception is when this number is in the known
5369 -- subtype range and the largest positive number is not in
5370 -- the known subtype range.
5372 -- For this exceptional case, use largest positive value
5374 if Lo_Bound /= No_Uint and then Hi_Bound /= No_Uint
5375 and then Lo_Bound <= (-(2 ** Signed_Size))
5376 and then Hi_Bound < 2 ** Signed_Size
5378 Val := Make_Integer_Literal (Loc, 2 ** Signed_Size - 1);
5380 -- Normal case of largest negative value
5383 Val := Make_Integer_Literal (Loc, -(2 ** Signed_Size));
5388 -- Here for Initialize_Scalars case
5391 -- For float types, use float values from System.Scalar_Values
5393 if Is_Floating_Point_Type (T) then
5394 if Root_Type (T) = Standard_Short_Float then
5395 Val_RE := RE_IS_Isf;
5396 elsif Root_Type (T) = Standard_Float then
5397 Val_RE := RE_IS_Ifl;
5398 elsif Root_Type (T) = Standard_Long_Float then
5399 Val_RE := RE_IS_Ilf;
5400 else pragma Assert (Root_Type (T) = Standard_Long_Long_Float);
5401 Val_RE := RE_IS_Ill;
5404 -- If zero is invalid, use zero values from System.Scalar_Values
5406 elsif Lo_Bound /= No_Uint and then Lo_Bound > Uint_0 then
5407 if Size_To_Use <= 8 then
5408 Val_RE := RE_IS_Iz1;
5409 elsif Size_To_Use <= 16 then
5410 Val_RE := RE_IS_Iz2;
5411 elsif Size_To_Use <= 32 then
5412 Val_RE := RE_IS_Iz4;
5414 Val_RE := RE_IS_Iz8;
5417 -- For unsigned, use unsigned values from System.Scalar_Values
5419 elsif Is_Unsigned_Type (T) then
5420 if Size_To_Use <= 8 then
5421 Val_RE := RE_IS_Iu1;
5422 elsif Size_To_Use <= 16 then
5423 Val_RE := RE_IS_Iu2;
5424 elsif Size_To_Use <= 32 then
5425 Val_RE := RE_IS_Iu4;
5427 Val_RE := RE_IS_Iu8;
5430 -- For signed, use signed values from System.Scalar_Values
5433 if Size_To_Use <= 8 then
5434 Val_RE := RE_IS_Is1;
5435 elsif Size_To_Use <= 16 then
5436 Val_RE := RE_IS_Is2;
5437 elsif Size_To_Use <= 32 then
5438 Val_RE := RE_IS_Is4;
5440 Val_RE := RE_IS_Is8;
5444 Val := New_Occurrence_Of (RTE (Val_RE), Loc);
5447 -- The final expression is obtained by doing an unchecked conversion
5448 -- of this result to the base type of the required subtype. We use
5449 -- the base type to avoid the unchecked conversion from chopping
5450 -- bits, and then we set Kill_Range_Check to preserve the "bad"
5453 Result := Unchecked_Convert_To (Base_Type (T), Val);
5455 -- Ensure result is not truncated, since we want the "bad" bits
5456 -- and also kill range check on result.
5458 if Nkind (Result) = N_Unchecked_Type_Conversion then
5459 Set_No_Truncation (Result);
5460 Set_Kill_Range_Check (Result, True);
5465 -- String or Wide_[Wide]_String (must have Initialize_Scalars set)
5467 elsif Root_Type (T) = Standard_String
5469 Root_Type (T) = Standard_Wide_String
5471 Root_Type (T) = Standard_Wide_Wide_String
5473 pragma Assert (Init_Or_Norm_Scalars);
5476 Make_Aggregate (Loc,
5477 Component_Associations => New_List (
5478 Make_Component_Association (Loc,
5479 Choices => New_List (
5480 Make_Others_Choice (Loc)),
5483 (Component_Type (T), Loc, Esize (Root_Type (T))))));
5485 -- Access type is initialized to null
5487 elsif Is_Access_Type (T) then
5491 -- No other possibilities should arise, since we should only be
5492 -- calling Get_Simple_Init_Val if Needs_Simple_Initialization
5493 -- returned True, indicating one of the above cases held.
5496 raise Program_Error;
5500 when RE_Not_Available =>
5502 end Get_Simple_Init_Val;
5504 ------------------------------
5505 -- Has_New_Non_Standard_Rep --
5506 ------------------------------
5508 function Has_New_Non_Standard_Rep (T : Entity_Id) return Boolean is
5510 if not Is_Derived_Type (T) then
5511 return Has_Non_Standard_Rep (T)
5512 or else Has_Non_Standard_Rep (Root_Type (T));
5514 -- If Has_Non_Standard_Rep is not set on the derived type, the
5515 -- representation is fully inherited.
5517 elsif not Has_Non_Standard_Rep (T) then
5521 return First_Rep_Item (T) /= First_Rep_Item (Root_Type (T));
5523 -- May need a more precise check here: the First_Rep_Item may
5524 -- be a stream attribute, which does not affect the representation
5527 end Has_New_Non_Standard_Rep;
5533 function In_Runtime (E : Entity_Id) return Boolean is
5534 S1 : Entity_Id := Scope (E);
5537 while Scope (S1) /= Standard_Standard loop
5541 return Chars (S1) = Name_System or else Chars (S1) = Name_Ada;
5548 function Init_Formals (Typ : Entity_Id) return List_Id is
5549 Loc : constant Source_Ptr := Sloc (Typ);
5553 -- First parameter is always _Init : in out typ. Note that we need
5554 -- this to be in/out because in the case of the task record value,
5555 -- there are default record fields (_Priority, _Size, -Task_Info)
5556 -- that may be referenced in the generated initialization routine.
5558 Formals := New_List (
5559 Make_Parameter_Specification (Loc,
5560 Defining_Identifier =>
5561 Make_Defining_Identifier (Loc, Name_uInit),
5563 Out_Present => True,
5564 Parameter_Type => New_Reference_To (Typ, Loc)));
5566 -- For task record value, or type that contains tasks, add two more
5567 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
5568 -- We also add these parameters for the task record type case.
5571 or else (Is_Record_Type (Typ) and then Is_Task_Record_Type (Typ))
5574 Make_Parameter_Specification (Loc,
5575 Defining_Identifier =>
5576 Make_Defining_Identifier (Loc, Name_uMaster),
5577 Parameter_Type => New_Reference_To (RTE (RE_Master_Id), Loc)));
5580 Make_Parameter_Specification (Loc,
5581 Defining_Identifier =>
5582 Make_Defining_Identifier (Loc, Name_uChain),
5584 Out_Present => True,
5586 New_Reference_To (RTE (RE_Activation_Chain), Loc)));
5589 Make_Parameter_Specification (Loc,
5590 Defining_Identifier =>
5591 Make_Defining_Identifier (Loc, Name_uTask_Name),
5594 New_Reference_To (Standard_String, Loc)));
5600 when RE_Not_Available =>
5608 -- <Make_Eq_if shared components>
5610 -- when V1 => <Make_Eq_Case> on subcomponents
5612 -- when Vn => <Make_Eq_Case> on subcomponents
5615 function Make_Eq_Case
5618 Discr : Entity_Id := Empty) return List_Id
5620 Loc : constant Source_Ptr := Sloc (E);
5621 Result : constant List_Id := New_List;
5626 Append_To (Result, Make_Eq_If (E, Component_Items (CL)));
5628 if No (Variant_Part (CL)) then
5632 Variant := First_Non_Pragma (Variants (Variant_Part (CL)));
5634 if No (Variant) then
5638 Alt_List := New_List;
5640 while Present (Variant) loop
5641 Append_To (Alt_List,
5642 Make_Case_Statement_Alternative (Loc,
5643 Discrete_Choices => New_Copy_List (Discrete_Choices (Variant)),
5644 Statements => Make_Eq_Case (E, Component_List (Variant))));
5646 Next_Non_Pragma (Variant);
5649 -- If we have an Unchecked_Union, use one of the parameters that
5650 -- captures the discriminants.
5652 if Is_Unchecked_Union (E) then
5654 Make_Case_Statement (Loc,
5655 Expression => New_Reference_To (Discr, Loc),
5656 Alternatives => Alt_List));
5660 Make_Case_Statement (Loc,
5662 Make_Selected_Component (Loc,
5663 Prefix => Make_Identifier (Loc, Name_X),
5664 Selector_Name => New_Copy (Name (Variant_Part (CL)))),
5665 Alternatives => Alt_List));
5686 -- or a null statement if the list L is empty
5690 L : List_Id) return Node_Id
5692 Loc : constant Source_Ptr := Sloc (E);
5694 Field_Name : Name_Id;
5699 return Make_Null_Statement (Loc);
5704 C := First_Non_Pragma (L);
5705 while Present (C) loop
5706 Field_Name := Chars (Defining_Identifier (C));
5708 -- The tags must not be compared they are not part of the value.
5709 -- Note also that in the following, we use Make_Identifier for
5710 -- the component names. Use of New_Reference_To to identify the
5711 -- components would be incorrect because the wrong entities for
5712 -- discriminants could be picked up in the private type case.
5714 if Field_Name /= Name_uTag then
5715 Evolve_Or_Else (Cond,
5718 Make_Selected_Component (Loc,
5719 Prefix => Make_Identifier (Loc, Name_X),
5721 Make_Identifier (Loc, Field_Name)),
5724 Make_Selected_Component (Loc,
5725 Prefix => Make_Identifier (Loc, Name_Y),
5727 Make_Identifier (Loc, Field_Name))));
5730 Next_Non_Pragma (C);
5734 return Make_Null_Statement (Loc);
5738 Make_Implicit_If_Statement (E,
5740 Then_Statements => New_List (
5741 Make_Return_Statement (Loc,
5742 Expression => New_Occurrence_Of (Standard_False, Loc))));
5747 -------------------------------------
5748 -- Make_Predefined_Primitive_Specs --
5749 -------------------------------------
5751 procedure Make_Predefined_Primitive_Specs
5752 (Tag_Typ : Entity_Id;
5753 Predef_List : out List_Id;
5754 Renamed_Eq : out Node_Id)
5756 Loc : constant Source_Ptr := Sloc (Tag_Typ);
5757 Res : constant List_Id := New_List;
5759 Eq_Needed : Boolean;
5761 Eq_Name : Name_Id := Name_Op_Eq;
5763 function Is_Predefined_Eq_Renaming (Prim : Node_Id) return Boolean;
5764 -- Returns true if Prim is a renaming of an unresolved predefined
5765 -- equality operation.
5767 -------------------------------
5768 -- Is_Predefined_Eq_Renaming --
5769 -------------------------------
5771 function Is_Predefined_Eq_Renaming (Prim : Node_Id) return Boolean is
5773 return Chars (Prim) /= Name_Op_Eq
5774 and then Present (Alias (Prim))
5775 and then Comes_From_Source (Prim)
5776 and then Is_Intrinsic_Subprogram (Alias (Prim))
5777 and then Chars (Alias (Prim)) = Name_Op_Eq;
5778 end Is_Predefined_Eq_Renaming;
5780 -- Start of processing for Make_Predefined_Primitive_Specs
5783 Renamed_Eq := Empty;
5787 Append_To (Res, Predef_Spec_Or_Body (Loc,
5790 Profile => New_List (
5791 Make_Parameter_Specification (Loc,
5792 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
5793 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
5795 Ret_Type => Standard_Long_Long_Integer));
5797 -- Spec of _Alignment
5799 Append_To (Res, Predef_Spec_Or_Body (Loc,
5801 Name => Name_uAlignment,
5802 Profile => New_List (
5803 Make_Parameter_Specification (Loc,
5804 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
5805 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
5807 Ret_Type => Standard_Integer));
5809 -- Specs for dispatching stream attributes
5812 Stream_Op_TSS_Names :
5813 constant array (Integer range <>) of TSS_Name_Type :=
5819 for Op in Stream_Op_TSS_Names'Range loop
5820 if Stream_Operation_OK (Tag_Typ, Stream_Op_TSS_Names (Op)) then
5822 Predef_Stream_Attr_Spec (Loc, Tag_Typ,
5823 Stream_Op_TSS_Names (Op)));
5828 -- Spec of "=" if expanded if the type is not limited and if a
5829 -- user defined "=" was not already declared for the non-full
5830 -- view of a private extension
5832 if not Is_Limited_Type (Tag_Typ) then
5835 Prim := First_Elmt (Primitive_Operations (Tag_Typ));
5836 while Present (Prim) loop
5838 -- If a primitive is encountered that renames the predefined
5839 -- equality operator before reaching any explicit equality
5840 -- primitive, then we still need to create a predefined
5841 -- equality function, because calls to it can occur via
5842 -- the renaming. A new name is created for the equality
5843 -- to avoid conflicting with any user-defined equality.
5844 -- (Note that this doesn't account for renamings of
5845 -- equality nested within subpackages???)
5847 if Is_Predefined_Eq_Renaming (Node (Prim)) then
5848 Eq_Name := New_External_Name (Chars (Node (Prim)), 'E');
5850 elsif Chars (Node (Prim)) = Name_Op_Eq
5851 and then (No (Alias (Node (Prim)))
5852 or else Nkind (Unit_Declaration_Node (Node (Prim))) =
5853 N_Subprogram_Renaming_Declaration)
5854 and then Etype (First_Formal (Node (Prim))) =
5855 Etype (Next_Formal (First_Formal (Node (Prim))))
5856 and then Base_Type (Etype (Node (Prim))) = Standard_Boolean
5862 -- If the parent equality is abstract, the inherited equality is
5863 -- abstract as well, and no body can be created for for it.
5865 elsif Chars (Node (Prim)) = Name_Op_Eq
5866 and then Present (Alias (Node (Prim)))
5867 and then Is_Abstract (Alias (Node (Prim)))
5876 -- If a renaming of predefined equality was found
5877 -- but there was no user-defined equality (so Eq_Needed
5878 -- is still true), then set the name back to Name_Op_Eq.
5879 -- But in the case where a user-defined equality was
5880 -- located after such a renaming, then the predefined
5881 -- equality function is still needed, so Eq_Needed must
5882 -- be set back to True.
5884 if Eq_Name /= Name_Op_Eq then
5886 Eq_Name := Name_Op_Eq;
5893 Eq_Spec := Predef_Spec_Or_Body (Loc,
5896 Profile => New_List (
5897 Make_Parameter_Specification (Loc,
5898 Defining_Identifier =>
5899 Make_Defining_Identifier (Loc, Name_X),
5900 Parameter_Type => New_Reference_To (Tag_Typ, Loc)),
5901 Make_Parameter_Specification (Loc,
5902 Defining_Identifier =>
5903 Make_Defining_Identifier (Loc, Name_Y),
5904 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
5905 Ret_Type => Standard_Boolean);
5906 Append_To (Res, Eq_Spec);
5908 if Eq_Name /= Name_Op_Eq then
5909 Renamed_Eq := Defining_Unit_Name (Specification (Eq_Spec));
5911 Prim := First_Elmt (Primitive_Operations (Tag_Typ));
5912 while Present (Prim) loop
5914 -- Any renamings of equality that appeared before an
5915 -- overriding equality must be updated to refer to
5916 -- the entity for the predefined equality, otherwise
5917 -- calls via the renaming would get incorrectly
5918 -- resolved to call the user-defined equality function.
5920 if Is_Predefined_Eq_Renaming (Node (Prim)) then
5921 Set_Alias (Node (Prim), Renamed_Eq);
5923 -- Exit upon encountering a user-defined equality
5925 elsif Chars (Node (Prim)) = Name_Op_Eq
5926 and then No (Alias (Node (Prim)))
5936 -- Spec for dispatching assignment
5938 Append_To (Res, Predef_Spec_Or_Body (Loc,
5940 Name => Name_uAssign,
5941 Profile => New_List (
5942 Make_Parameter_Specification (Loc,
5943 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
5944 Out_Present => True,
5945 Parameter_Type => New_Reference_To (Tag_Typ, Loc)),
5947 Make_Parameter_Specification (Loc,
5948 Defining_Identifier => Make_Defining_Identifier (Loc, Name_Y),
5949 Parameter_Type => New_Reference_To (Tag_Typ, Loc)))));
5952 -- Generate the declarations for the following primitive operations:
5953 -- disp_asynchronous_select
5954 -- disp_conditional_select
5955 -- disp_get_prim_op_kind
5957 -- disp_timed_select
5958 -- for limited interfaces and tagged types that implement a limited
5961 if Ada_Version >= Ada_05
5963 ((Is_Interface (Tag_Typ)
5964 and then Is_Limited_Record (Tag_Typ))
5966 (not Is_Abstract (Tag_Typ)
5967 and then not Is_Controlled (Tag_Typ)
5969 Implements_Interface
5971 Kind => Any_Limited_Interface,
5972 Check_Parent => True)))
5975 Make_Subprogram_Declaration (Loc,
5977 Make_Disp_Asynchronous_Select_Spec (Tag_Typ)));
5980 Make_Subprogram_Declaration (Loc,
5982 Make_Disp_Conditional_Select_Spec (Tag_Typ)));
5985 Make_Subprogram_Declaration (Loc,
5987 Make_Disp_Get_Prim_Op_Kind_Spec (Tag_Typ)));
5990 Make_Subprogram_Declaration (Loc,
5992 Make_Disp_Get_Task_Id_Spec (Tag_Typ)));
5995 Make_Subprogram_Declaration (Loc,
5997 Make_Disp_Timed_Select_Spec (Tag_Typ)));
6000 -- Specs for finalization actions that may be required in case a
6001 -- future extension contain a controlled element. We generate those
6002 -- only for root tagged types where they will get dummy bodies or
6003 -- when the type has controlled components and their body must be
6004 -- generated. It is also impossible to provide those for tagged
6005 -- types defined within s-finimp since it would involve circularity
6008 if In_Finalization_Root (Tag_Typ) then
6011 -- We also skip these if finalization is not available
6013 elsif Restriction_Active (No_Finalization) then
6016 elsif Etype (Tag_Typ) = Tag_Typ or else Controlled_Type (Tag_Typ) then
6017 if not Is_Limited_Type (Tag_Typ) then
6019 Predef_Deep_Spec (Loc, Tag_Typ, TSS_Deep_Adjust));
6022 Append_To (Res, Predef_Deep_Spec (Loc, Tag_Typ, TSS_Deep_Finalize));
6026 end Make_Predefined_Primitive_Specs;
6028 ---------------------------------
6029 -- Needs_Simple_Initialization --
6030 ---------------------------------
6032 function Needs_Simple_Initialization (T : Entity_Id) return Boolean is
6034 -- Check for private type, in which case test applies to the
6035 -- underlying type of the private type.
6037 if Is_Private_Type (T) then
6039 RT : constant Entity_Id := Underlying_Type (T);
6042 if Present (RT) then
6043 return Needs_Simple_Initialization (RT);
6049 -- Cases needing simple initialization are access types, and, if pragma
6050 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
6053 elsif Is_Access_Type (T)
6054 or else (Init_Or_Norm_Scalars and then (Is_Scalar_Type (T)))
6058 -- If Initialize/Normalize_Scalars is in effect, string objects also
6059 -- need initialization, unless they are created in the course of
6060 -- expanding an aggregate (since in the latter case they will be
6061 -- filled with appropriate initializing values before they are used).
6063 elsif Init_Or_Norm_Scalars
6065 (Root_Type (T) = Standard_String
6066 or else Root_Type (T) = Standard_Wide_String
6067 or else Root_Type (T) = Standard_Wide_Wide_String)
6070 or else Nkind (Associated_Node_For_Itype (T)) /= N_Aggregate)
6077 end Needs_Simple_Initialization;
6079 ----------------------
6080 -- Predef_Deep_Spec --
6081 ----------------------
6083 function Predef_Deep_Spec
6085 Tag_Typ : Entity_Id;
6086 Name : TSS_Name_Type;
6087 For_Body : Boolean := False) return Node_Id
6093 if Name = TSS_Deep_Finalize then
6095 Type_B := Standard_Boolean;
6099 Make_Parameter_Specification (Loc,
6100 Defining_Identifier => Make_Defining_Identifier (Loc, Name_L),
6102 Out_Present => True,
6104 New_Reference_To (RTE (RE_Finalizable_Ptr), Loc)));
6105 Type_B := Standard_Short_Short_Integer;
6109 Make_Parameter_Specification (Loc,
6110 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
6112 Out_Present => True,
6113 Parameter_Type => New_Reference_To (Tag_Typ, Loc)));
6116 Make_Parameter_Specification (Loc,
6117 Defining_Identifier => Make_Defining_Identifier (Loc, Name_B),
6118 Parameter_Type => New_Reference_To (Type_B, Loc)));
6120 return Predef_Spec_Or_Body (Loc,
6121 Name => Make_TSS_Name (Tag_Typ, Name),
6124 For_Body => For_Body);
6127 when RE_Not_Available =>
6129 end Predef_Deep_Spec;
6131 -------------------------
6132 -- Predef_Spec_Or_Body --
6133 -------------------------
6135 function Predef_Spec_Or_Body
6137 Tag_Typ : Entity_Id;
6140 Ret_Type : Entity_Id := Empty;
6141 For_Body : Boolean := False) return Node_Id
6143 Id : constant Entity_Id := Make_Defining_Identifier (Loc, Name);
6147 Set_Is_Public (Id, Is_Public (Tag_Typ));
6149 -- The internal flag is set to mark these declarations because
6150 -- they have specific properties. First they are primitives even
6151 -- if they are not defined in the type scope (the freezing point
6152 -- is not necessarily in the same scope), furthermore the
6153 -- predefined equality can be overridden by a user-defined
6154 -- equality, no body will be generated in this case.
6156 Set_Is_Internal (Id);
6158 if not Debug_Generated_Code then
6159 Set_Debug_Info_Off (Id);
6162 if No (Ret_Type) then
6164 Make_Procedure_Specification (Loc,
6165 Defining_Unit_Name => Id,
6166 Parameter_Specifications => Profile);
6169 Make_Function_Specification (Loc,
6170 Defining_Unit_Name => Id,
6171 Parameter_Specifications => Profile,
6172 Result_Definition =>
6173 New_Reference_To (Ret_Type, Loc));
6176 -- If body case, return empty subprogram body. Note that this is
6177 -- ill-formed, because there is not even a null statement, and
6178 -- certainly not a return in the function case. The caller is
6179 -- expected to do surgery on the body to add the appropriate stuff.
6182 return Make_Subprogram_Body (Loc, Spec, Empty_List, Empty);
6184 -- For the case of Input/Output attributes applied to an abstract type,
6185 -- generate abstract specifications. These will never be called,
6186 -- but we need the slots allocated in the dispatching table so
6187 -- that typ'Class'Input and typ'Class'Output will work properly.
6189 elsif (Is_TSS (Name, TSS_Stream_Input)
6191 Is_TSS (Name, TSS_Stream_Output))
6192 and then Is_Abstract (Tag_Typ)
6194 return Make_Abstract_Subprogram_Declaration (Loc, Spec);
6196 -- Normal spec case, where we return a subprogram declaration
6199 return Make_Subprogram_Declaration (Loc, Spec);
6201 end Predef_Spec_Or_Body;
6203 -----------------------------
6204 -- Predef_Stream_Attr_Spec --
6205 -----------------------------
6207 function Predef_Stream_Attr_Spec
6209 Tag_Typ : Entity_Id;
6210 Name : TSS_Name_Type;
6211 For_Body : Boolean := False) return Node_Id
6213 Ret_Type : Entity_Id;
6216 if Name = TSS_Stream_Input then
6217 Ret_Type := Tag_Typ;
6222 return Predef_Spec_Or_Body (Loc,
6223 Name => Make_TSS_Name (Tag_Typ, Name),
6225 Profile => Build_Stream_Attr_Profile (Loc, Tag_Typ, Name),
6226 Ret_Type => Ret_Type,
6227 For_Body => For_Body);
6228 end Predef_Stream_Attr_Spec;
6230 ---------------------------------
6231 -- Predefined_Primitive_Bodies --
6232 ---------------------------------
6234 function Predefined_Primitive_Bodies
6235 (Tag_Typ : Entity_Id;
6236 Renamed_Eq : Node_Id) return List_Id
6238 Loc : constant Source_Ptr := Sloc (Tag_Typ);
6239 Res : constant List_Id := New_List;
6242 Eq_Needed : Boolean;
6247 -- See if we have a predefined "=" operator
6249 if Present (Renamed_Eq) then
6251 Eq_Name := Chars (Renamed_Eq);
6257 Prim := First_Elmt (Primitive_Operations (Tag_Typ));
6258 while Present (Prim) loop
6259 if Chars (Node (Prim)) = Name_Op_Eq
6260 and then Is_Internal (Node (Prim))
6263 Eq_Name := Name_Op_Eq;
6270 -- Body of _Alignment
6272 Decl := Predef_Spec_Or_Body (Loc,
6274 Name => Name_uAlignment,
6275 Profile => New_List (
6276 Make_Parameter_Specification (Loc,
6277 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
6278 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
6280 Ret_Type => Standard_Integer,
6283 Set_Handled_Statement_Sequence (Decl,
6284 Make_Handled_Sequence_Of_Statements (Loc, New_List (
6285 Make_Return_Statement (Loc,
6287 Make_Attribute_Reference (Loc,
6288 Prefix => Make_Identifier (Loc, Name_X),
6289 Attribute_Name => Name_Alignment)))));
6291 Append_To (Res, Decl);
6295 Decl := Predef_Spec_Or_Body (Loc,
6298 Profile => New_List (
6299 Make_Parameter_Specification (Loc,
6300 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
6301 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
6303 Ret_Type => Standard_Long_Long_Integer,
6306 Set_Handled_Statement_Sequence (Decl,
6307 Make_Handled_Sequence_Of_Statements (Loc, New_List (
6308 Make_Return_Statement (Loc,
6310 Make_Attribute_Reference (Loc,
6311 Prefix => Make_Identifier (Loc, Name_X),
6312 Attribute_Name => Name_Size)))));
6314 Append_To (Res, Decl);
6316 -- Bodies for Dispatching stream IO routines. We need these only for
6317 -- non-limited types (in the limited case there is no dispatching).
6318 -- We also skip them if dispatching or finalization are not available.
6320 if Stream_Operation_OK (Tag_Typ, TSS_Stream_Read)
6321 and then No (TSS (Tag_Typ, TSS_Stream_Read))
6323 Build_Record_Read_Procedure (Loc, Tag_Typ, Decl, Ent);
6324 Append_To (Res, Decl);
6327 if Stream_Operation_OK (Tag_Typ, TSS_Stream_Write)
6328 and then No (TSS (Tag_Typ, TSS_Stream_Write))
6330 Build_Record_Write_Procedure (Loc, Tag_Typ, Decl, Ent);
6331 Append_To (Res, Decl);
6334 -- Skip bodies of _Input and _Output for the abstract case, since
6335 -- the corresponding specs are abstract (see Predef_Spec_Or_Body)
6337 if not Is_Abstract (Tag_Typ) then
6338 if Stream_Operation_OK (Tag_Typ, TSS_Stream_Input)
6339 and then No (TSS (Tag_Typ, TSS_Stream_Input))
6341 Build_Record_Or_Elementary_Input_Function
6342 (Loc, Tag_Typ, Decl, Ent);
6343 Append_To (Res, Decl);
6346 if Stream_Operation_OK (Tag_Typ, TSS_Stream_Output)
6347 and then No (TSS (Tag_Typ, TSS_Stream_Output))
6349 Build_Record_Or_Elementary_Output_Procedure
6350 (Loc, Tag_Typ, Decl, Ent);
6351 Append_To (Res, Decl);
6355 -- Generate the bodies for the following primitive operations:
6357 -- disp_asynchronous_select
6358 -- disp_conditional_select
6359 -- disp_get_prim_op_kind
6361 -- disp_timed_select
6363 -- for limited interfaces and tagged types that implement a limited
6364 -- interface. The interface versions will have null bodies.
6366 if Ada_Version >= Ada_05
6368 ((Is_Interface (Tag_Typ) and then Is_Limited_Record (Tag_Typ))
6370 (not Is_Abstract (Tag_Typ)
6371 and then not Is_Controlled (Tag_Typ)
6373 Implements_Interface
6375 Kind => Any_Limited_Interface,
6376 Check_Parent => True)))
6378 Append_To (Res, Make_Disp_Asynchronous_Select_Body (Tag_Typ));
6379 Append_To (Res, Make_Disp_Conditional_Select_Body (Tag_Typ));
6380 Append_To (Res, Make_Disp_Get_Prim_Op_Kind_Body (Tag_Typ));
6381 Append_To (Res, Make_Disp_Get_Task_Id_Body (Tag_Typ));
6382 Append_To (Res, Make_Disp_Timed_Select_Body (Tag_Typ));
6385 if not Is_Limited_Type (Tag_Typ) then
6387 -- Body for equality
6391 Predef_Spec_Or_Body (Loc,
6394 Profile => New_List (
6395 Make_Parameter_Specification (Loc,
6396 Defining_Identifier =>
6397 Make_Defining_Identifier (Loc, Name_X),
6398 Parameter_Type => New_Reference_To (Tag_Typ, Loc)),
6400 Make_Parameter_Specification (Loc,
6401 Defining_Identifier =>
6402 Make_Defining_Identifier (Loc, Name_Y),
6403 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
6405 Ret_Type => Standard_Boolean,
6409 Def : constant Node_Id := Parent (Tag_Typ);
6410 Stmts : constant List_Id := New_List;
6411 Variant_Case : Boolean := Has_Discriminants (Tag_Typ);
6412 Comps : Node_Id := Empty;
6413 Typ_Def : Node_Id := Type_Definition (Def);
6416 if Variant_Case then
6417 if Nkind (Typ_Def) = N_Derived_Type_Definition then
6418 Typ_Def := Record_Extension_Part (Typ_Def);
6421 if Present (Typ_Def) then
6422 Comps := Component_List (Typ_Def);
6425 Variant_Case := Present (Comps)
6426 and then Present (Variant_Part (Comps));
6429 if Variant_Case then
6431 Make_Eq_If (Tag_Typ, Discriminant_Specifications (Def)));
6432 Append_List_To (Stmts, Make_Eq_Case (Tag_Typ, Comps));
6434 Make_Return_Statement (Loc,
6435 Expression => New_Reference_To (Standard_True, Loc)));
6439 Make_Return_Statement (Loc,
6441 Expand_Record_Equality (Tag_Typ,
6443 Lhs => Make_Identifier (Loc, Name_X),
6444 Rhs => Make_Identifier (Loc, Name_Y),
6445 Bodies => Declarations (Decl))));
6448 Set_Handled_Statement_Sequence (Decl,
6449 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
6451 Append_To (Res, Decl);
6454 -- Body for dispatching assignment
6457 Predef_Spec_Or_Body (Loc,
6459 Name => Name_uAssign,
6460 Profile => New_List (
6461 Make_Parameter_Specification (Loc,
6462 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
6463 Out_Present => True,
6464 Parameter_Type => New_Reference_To (Tag_Typ, Loc)),
6466 Make_Parameter_Specification (Loc,
6467 Defining_Identifier => Make_Defining_Identifier (Loc, Name_Y),
6468 Parameter_Type => New_Reference_To (Tag_Typ, Loc))),
6471 Set_Handled_Statement_Sequence (Decl,
6472 Make_Handled_Sequence_Of_Statements (Loc, New_List (
6473 Make_Assignment_Statement (Loc,
6474 Name => Make_Identifier (Loc, Name_X),
6475 Expression => Make_Identifier (Loc, Name_Y)))));
6477 Append_To (Res, Decl);
6480 -- Generate dummy bodies for finalization actions of types that have
6481 -- no controlled components.
6483 -- Skip this processing if we are in the finalization routine in the
6484 -- runtime itself, otherwise we get hopelessly circularly confused!
6486 if In_Finalization_Root (Tag_Typ) then
6489 -- Skip this if finalization is not available
6491 elsif Restriction_Active (No_Finalization) then
6494 elsif (Etype (Tag_Typ) = Tag_Typ or else Is_Controlled (Tag_Typ))
6495 and then not Has_Controlled_Component (Tag_Typ)
6497 if not Is_Limited_Type (Tag_Typ) then
6498 Decl := Predef_Deep_Spec (Loc, Tag_Typ, TSS_Deep_Adjust, True);
6500 if Is_Controlled (Tag_Typ) then
6501 Set_Handled_Statement_Sequence (Decl,
6502 Make_Handled_Sequence_Of_Statements (Loc,
6504 Ref => Make_Identifier (Loc, Name_V),
6506 Flist_Ref => Make_Identifier (Loc, Name_L),
6507 With_Attach => Make_Identifier (Loc, Name_B))));
6510 Set_Handled_Statement_Sequence (Decl,
6511 Make_Handled_Sequence_Of_Statements (Loc, New_List (
6512 Make_Null_Statement (Loc))));
6515 Append_To (Res, Decl);
6518 Decl := Predef_Deep_Spec (Loc, Tag_Typ, TSS_Deep_Finalize, True);
6520 if Is_Controlled (Tag_Typ) then
6521 Set_Handled_Statement_Sequence (Decl,
6522 Make_Handled_Sequence_Of_Statements (Loc,
6524 Ref => Make_Identifier (Loc, Name_V),
6526 With_Detach => Make_Identifier (Loc, Name_B))));
6529 Set_Handled_Statement_Sequence (Decl,
6530 Make_Handled_Sequence_Of_Statements (Loc, New_List (
6531 Make_Null_Statement (Loc))));
6534 Append_To (Res, Decl);
6538 end Predefined_Primitive_Bodies;
6540 ---------------------------------
6541 -- Predefined_Primitive_Freeze --
6542 ---------------------------------
6544 function Predefined_Primitive_Freeze
6545 (Tag_Typ : Entity_Id) return List_Id
6547 Loc : constant Source_Ptr := Sloc (Tag_Typ);
6548 Res : constant List_Id := New_List;
6553 Prim := First_Elmt (Primitive_Operations (Tag_Typ));
6554 while Present (Prim) loop
6555 if Is_Internal (Node (Prim)) then
6556 Frnodes := Freeze_Entity (Node (Prim), Loc);
6558 if Present (Frnodes) then
6559 Append_List_To (Res, Frnodes);
6567 end Predefined_Primitive_Freeze;
6569 -------------------------
6570 -- Stream_Operation_OK --
6571 -------------------------
6573 function Stream_Operation_OK
6575 Operation : TSS_Name_Type) return Boolean
6577 Has_Inheritable_Stream_Attribute : Boolean := False;
6580 if Is_Limited_Type (Typ)
6581 and then Is_Tagged_Type (Typ)
6582 and then Is_Derived_Type (Typ)
6584 -- Special case of a limited type extension: a default implementation
6585 -- of the stream attributes Read and Write exists if the attribute
6586 -- has been specified for an ancestor type.
6588 Has_Inheritable_Stream_Attribute :=
6589 Present (Find_Inherited_TSS (Base_Type (Etype (Typ)), Operation));
6593 not (Is_Limited_Type (Typ)
6594 and then not Has_Inheritable_Stream_Attribute)
6595 and then not Has_Unknown_Discriminants (Typ)
6596 and then RTE_Available (RE_Tag)
6597 and then RTE_Available (RE_Root_Stream_Type)
6598 and then not Restriction_Active (No_Dispatch)
6599 and then not Restriction_Active (No_Streams);
6600 end Stream_Operation_OK;