1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
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_Atag
; use Exp_Atag
;
33 with Exp_Ch4
; use Exp_Ch4
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Ch9
; use Exp_Ch9
;
37 with Exp_Dbug
; use Exp_Dbug
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Dist
; use Exp_Dist
;
40 with Exp_Smem
; use Exp_Smem
;
41 with Exp_Strm
; use Exp_Strm
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Freeze
; use Freeze
;
45 with Ghost
; use Ghost
;
47 with Namet
; use Namet
;
48 with Nlists
; use Nlists
;
49 with Nmake
; use Nmake
;
51 with Restrict
; use Restrict
;
52 with Rident
; use Rident
;
53 with Rtsfind
; use Rtsfind
;
55 with Sem_Aux
; use Sem_Aux
;
56 with Sem_Attr
; use Sem_Attr
;
57 with Sem_Cat
; use Sem_Cat
;
58 with Sem_Ch3
; use Sem_Ch3
;
59 with Sem_Ch6
; use Sem_Ch6
;
60 with Sem_Ch8
; use Sem_Ch8
;
61 with Sem_Disp
; use Sem_Disp
;
62 with Sem_Eval
; use Sem_Eval
;
63 with Sem_Mech
; use Sem_Mech
;
64 with Sem_Res
; use Sem_Res
;
65 with Sem_SCIL
; use Sem_SCIL
;
66 with Sem_Type
; use Sem_Type
;
67 with Sem_Util
; use Sem_Util
;
68 with Sinfo
; use Sinfo
;
69 with Stand
; use Stand
;
70 with Snames
; use Snames
;
71 with Tbuild
; use Tbuild
;
72 with Ttypes
; use Ttypes
;
73 with Validsw
; use Validsw
;
75 package body Exp_Ch3
is
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Adjust_Discriminants
(Rtype
: Entity_Id
);
82 -- This is used when freezing a record type. It attempts to construct
83 -- more restrictive subtypes for discriminants so that the max size of
84 -- the record can be calculated more accurately. See the body of this
85 -- procedure for details.
87 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
);
88 -- Build initialization procedure for given array type. Nod is a node
89 -- used for attachment of any actions required in its construction.
90 -- It also supplies the source location used for the procedure.
92 function Build_Discriminant_Formals
94 Use_Dl
: Boolean) return List_Id
;
95 -- This function uses the discriminants of a type to build a list of
96 -- formal parameters, used in Build_Init_Procedure among other places.
97 -- If the flag Use_Dl is set, the list is built using the already
98 -- defined discriminals of the type, as is the case for concurrent
99 -- types with discriminants. Otherwise new identifiers are created,
100 -- with the source names of the discriminants.
102 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
;
103 -- This function builds a static aggregate that can serve as the initial
104 -- value for an array type whose bounds are static, and whose component
105 -- type is a composite type that has a static equivalent aggregate.
106 -- The equivalent array aggregate is used both for object initialization
107 -- and for component initialization, when used in the following function.
109 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
;
110 -- This function builds a static aggregate that can serve as the initial
111 -- value for a record type whose components are scalar and initialized
112 -- with compile-time values, or arrays with similar initialization or
113 -- defaults. When possible, initialization of an object of the type can
114 -- be achieved by using a copy of the aggregate as an initial value, thus
115 -- removing the implicit call that would otherwise constitute elaboration
118 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
);
119 -- Build record initialization procedure. N is the type declaration
120 -- node, and Rec_Ent is the corresponding entity for the record type.
122 procedure Build_Slice_Assignment
(Typ
: Entity_Id
);
123 -- Build assignment procedure for one-dimensional arrays of controlled
124 -- types. Other array and slice assignments are expanded in-line, but
125 -- the code expansion for controlled components (when control actions
126 -- are active) can lead to very large blocks that GCC3 handles poorly.
128 procedure Build_Untagged_Equality
(Typ
: Entity_Id
);
129 -- AI05-0123: Equality on untagged records composes. This procedure
130 -- builds the equality routine for an untagged record that has components
131 -- of a record type that has user-defined primitive equality operations.
132 -- The resulting operation is a TSS subprogram.
134 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
);
135 -- Create An Equality function for the untagged variant record Typ and
136 -- attach it to the TSS list
138 procedure Check_Stream_Attributes
(Typ
: Entity_Id
);
139 -- Check that if a limited extension has a parent with user-defined stream
140 -- attributes, and does not itself have user-defined stream-attributes,
141 -- then any limited component of the extension also has the corresponding
142 -- user-defined stream attributes.
144 procedure Clean_Task_Names
146 Proc_Id
: Entity_Id
);
147 -- If an initialization procedure includes calls to generate names
148 -- for task subcomponents, indicate that secondary stack cleanup is
149 -- needed after an initialization. Typ is the component type, and Proc_Id
150 -- the initialization procedure for the enclosing composite type.
152 procedure Expand_Freeze_Array_Type
(N
: Node_Id
);
153 -- Freeze an array type. Deals with building the initialization procedure,
154 -- creating the packed array type for a packed array and also with the
155 -- creation of the controlling procedures for the controlled case. The
156 -- argument N is the N_Freeze_Entity node for the type.
158 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
);
159 -- Freeze a class-wide type. Build routine Finalize_Address for the purpose
160 -- of finalizing controlled derivations from the class-wide's root type.
162 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
);
163 -- Freeze enumeration type with non-standard representation. Builds the
164 -- array and function needed to convert between enumeration pos and
165 -- enumeration representation values. N is the N_Freeze_Entity node
168 procedure Expand_Freeze_Record_Type
(N
: Node_Id
);
169 -- Freeze record type. Builds all necessary discriminant checking
170 -- and other ancillary functions, and builds dispatch tables where
171 -- needed. The argument N is the N_Freeze_Entity node. This processing
172 -- applies only to E_Record_Type entities, not to class wide types,
173 -- record subtypes, or private types.
175 procedure Expand_Tagged_Root
(T
: Entity_Id
);
176 -- Add a field _Tag at the beginning of the record. This field carries
177 -- the value of the access to the Dispatch table. This procedure is only
178 -- called on root type, the _Tag field being inherited by the descendants.
180 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
);
181 -- Treat user-defined stream operations as renaming_as_body if the
182 -- subprogram they rename is not frozen when the type is frozen.
184 procedure Initialization_Warning
(E
: Entity_Id
);
185 -- If static elaboration of the package is requested, indicate
186 -- when a type does meet the conditions for static initialization. If
187 -- E is a type, it has components that have no static initialization.
188 -- if E is an entity, its initial expression is not compile-time known.
190 function Init_Formals
(Typ
: Entity_Id
) return List_Id
;
191 -- This function builds the list of formals for an initialization routine.
192 -- The first formal is always _Init with the given type. For task value
193 -- record types and types containing tasks, three additional formals are
196 -- _Master : Master_Id
197 -- _Chain : in out Activation_Chain
198 -- _Task_Name : String
200 -- The caller must append additional entries for discriminants if required.
202 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean;
203 -- Returns true if the initialization procedure of Typ should be inlined
205 function In_Runtime
(E
: Entity_Id
) return Boolean;
206 -- Check if E is defined in the RTL (in a child of Ada or System). Used
207 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
209 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean;
210 -- Returns true if Prim is a user defined equality function
212 function Make_Eq_Body
214 Eq_Name
: Name_Id
) return Node_Id
;
215 -- Build the body of a primitive equality operation for a tagged record
216 -- type, or in Ada 2012 for any record type that has components with a
217 -- user-defined equality. Factored out of Predefined_Primitive_Bodies.
219 function Make_Eq_Case
222 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
;
223 -- Building block for variant record equality. Defined to share the code
224 -- between the tagged and untagged case. Given a Component_List node CL,
225 -- it generates an 'if' followed by a 'case' statement that compares all
226 -- components of local temporaries named X and Y (that are declared as
227 -- formals at some upper level). E provides the Sloc to be used for the
230 -- IF E is an unchecked_union, Discrs is the list of formals created for
231 -- the inferred discriminants of one operand. These formals are used in
232 -- the generated case statements for each variant of the unchecked union.
236 L
: List_Id
) return Node_Id
;
237 -- Building block for variant record equality. Defined to share the code
238 -- between the tagged and untagged case. Given the list of components
239 -- (or discriminants) L, it generates a return statement that compares all
240 -- components of local temporaries named X and Y (that are declared as
241 -- formals at some upper level). E provides the Sloc to be used for the
244 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
;
245 -- Search for a renaming of the inequality dispatching primitive of
246 -- this tagged type. If found then build and return the corresponding
247 -- rename-as-body inequality subprogram; otherwise return Empty.
249 procedure Make_Predefined_Primitive_Specs
250 (Tag_Typ
: Entity_Id
;
251 Predef_List
: out List_Id
;
252 Renamed_Eq
: out Entity_Id
);
253 -- Create a list with the specs of the predefined primitive operations.
254 -- For tagged types that are interfaces all these primitives are defined
257 -- The following entries are present for all tagged types, and provide
258 -- the results of the corresponding attribute applied to the object.
259 -- Dispatching is required in general, since the result of the attribute
260 -- will vary with the actual object subtype.
262 -- _size provides result of 'Size attribute
263 -- typSR provides result of 'Read attribute
264 -- typSW provides result of 'Write attribute
265 -- typSI provides result of 'Input attribute
266 -- typSO provides result of 'Output attribute
268 -- The following entries are additionally present for non-limited tagged
269 -- types, and implement additional dispatching operations for predefined
272 -- _equality implements "=" operator
273 -- _assign implements assignment operation
274 -- typDF implements deep finalization
275 -- typDA implements deep adjust
277 -- The latter two are empty procedures unless the type contains some
278 -- controlled components that require finalization actions (the deep
279 -- in the name refers to the fact that the action applies to components).
281 -- The list is returned in Predef_List. The Parameter Renamed_Eq either
282 -- returns the value Empty, or else the defining unit name for the
283 -- predefined equality function in the case where the type has a primitive
284 -- operation that is a renaming of predefined equality (but only if there
285 -- is also an overriding user-defined equality function). The returned
286 -- Renamed_Eq will be passed to the corresponding parameter of
287 -- Predefined_Primitive_Bodies.
289 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean;
290 -- Returns True if there are representation clauses for type T that are not
291 -- inherited. If the result is false, the init_proc and the discriminant
292 -- checking functions of the parent can be reused by a derived type.
294 procedure Make_Controlling_Function_Wrappers
295 (Tag_Typ
: Entity_Id
;
296 Decl_List
: out List_Id
;
297 Body_List
: out List_Id
);
298 -- Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
299 -- associated with inherited functions with controlling results which
300 -- are not overridden. The body of each wrapper function consists solely
301 -- of a return statement whose expression is an extension aggregate
302 -- invoking the inherited subprogram's parent subprogram and extended
303 -- with a null association list.
305 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
;
306 -- Ada 2005 (AI-251): Makes specs for null procedures associated with any
307 -- null procedures inherited from an interface type that have not been
308 -- overridden. Only one null procedure will be created for a given set of
309 -- inherited null procedures with homographic profiles.
311 function Predef_Spec_Or_Body
316 Ret_Type
: Entity_Id
:= Empty
;
317 For_Body
: Boolean := False) return Node_Id
;
318 -- This function generates the appropriate expansion for a predefined
319 -- primitive operation specified by its name, parameter profile and
320 -- return type (Empty means this is a procedure). If For_Body is false,
321 -- then the returned node is a subprogram declaration. If For_Body is
322 -- true, then the returned node is a empty subprogram body containing
323 -- no declarations and no statements.
325 function Predef_Stream_Attr_Spec
328 Name
: TSS_Name_Type
;
329 For_Body
: Boolean := False) return Node_Id
;
330 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
331 -- input and output attribute whose specs are constructed in Exp_Strm.
333 function Predef_Deep_Spec
336 Name
: TSS_Name_Type
;
337 For_Body
: Boolean := False) return Node_Id
;
338 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
339 -- and _deep_finalize
341 function Predefined_Primitive_Bodies
342 (Tag_Typ
: Entity_Id
;
343 Renamed_Eq
: Entity_Id
) return List_Id
;
344 -- Create the bodies of the predefined primitives that are described in
345 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
346 -- the defining unit name of the type's predefined equality as returned
347 -- by Make_Predefined_Primitive_Specs.
349 function Predefined_Primitive_Freeze
(Tag_Typ
: Entity_Id
) return List_Id
;
350 -- Freeze entities of all predefined primitive operations. This is needed
351 -- because the bodies of these operations do not normally do any freezing.
353 function Stream_Operation_OK
355 Operation
: TSS_Name_Type
) return Boolean;
356 -- Check whether the named stream operation must be emitted for a given
357 -- type. The rules for inheritance of stream attributes by type extensions
358 -- are enforced by this function. Furthermore, various restrictions prevent
359 -- the generation of these operations, as a useful optimization or for
360 -- certification purposes and to save unnecessary generated code.
362 --------------------------
363 -- Adjust_Discriminants --
364 --------------------------
366 -- This procedure attempts to define subtypes for discriminants that are
367 -- more restrictive than those declared. Such a replacement is possible if
368 -- we can demonstrate that values outside the restricted range would cause
369 -- constraint errors in any case. The advantage of restricting the
370 -- discriminant types in this way is that the maximum size of the variant
371 -- record can be calculated more conservatively.
373 -- An example of a situation in which we can perform this type of
374 -- restriction is the following:
376 -- subtype B is range 1 .. 10;
377 -- type Q is array (B range <>) of Integer;
379 -- type V (N : Natural) is record
383 -- In this situation, we can restrict the upper bound of N to 10, since
384 -- any larger value would cause a constraint error in any case.
386 -- There are many situations in which such restriction is possible, but
387 -- for now, we just look for cases like the above, where the component
388 -- in question is a one dimensional array whose upper bound is one of
389 -- the record discriminants. Also the component must not be part of
390 -- any variant part, since then the component does not always exist.
392 procedure Adjust_Discriminants
(Rtype
: Entity_Id
) is
393 Loc
: constant Source_Ptr
:= Sloc
(Rtype
);
410 Comp
:= First_Component
(Rtype
);
411 while Present
(Comp
) loop
413 -- If our parent is a variant, quit, we do not look at components
414 -- that are in variant parts, because they may not always exist.
416 P
:= Parent
(Comp
); -- component declaration
417 P
:= Parent
(P
); -- component list
419 exit when Nkind
(Parent
(P
)) = N_Variant
;
421 -- We are looking for a one dimensional array type
423 Ctyp
:= Etype
(Comp
);
425 if not Is_Array_Type
(Ctyp
) or else Number_Dimensions
(Ctyp
) > 1 then
429 -- The lower bound must be constant, and the upper bound is a
430 -- discriminant (which is a discriminant of the current record).
432 Ityp
:= Etype
(First_Index
(Ctyp
));
433 Lo
:= Type_Low_Bound
(Ityp
);
434 Hi
:= Type_High_Bound
(Ityp
);
436 if not Compile_Time_Known_Value
(Lo
)
437 or else Nkind
(Hi
) /= N_Identifier
438 or else No
(Entity
(Hi
))
439 or else Ekind
(Entity
(Hi
)) /= E_Discriminant
444 -- We have an array with appropriate bounds
446 Loval
:= Expr_Value
(Lo
);
447 Discr
:= Entity
(Hi
);
448 Dtyp
:= Etype
(Discr
);
450 -- See if the discriminant has a known upper bound
452 Dhi
:= Type_High_Bound
(Dtyp
);
454 if not Compile_Time_Known_Value
(Dhi
) then
458 Dhiv
:= Expr_Value
(Dhi
);
460 -- See if base type of component array has known upper bound
462 Ahi
:= Type_High_Bound
(Etype
(First_Index
(Base_Type
(Ctyp
))));
464 if not Compile_Time_Known_Value
(Ahi
) then
468 Ahiv
:= Expr_Value
(Ahi
);
470 -- The condition for doing the restriction is that the high bound
471 -- of the discriminant is greater than the low bound of the array,
472 -- and is also greater than the high bound of the base type index.
474 if Dhiv
> Loval
and then Dhiv
> Ahiv
then
476 -- We can reset the upper bound of the discriminant type to
477 -- whichever is larger, the low bound of the component, or
478 -- the high bound of the base type array index.
480 -- We build a subtype that is declared as
482 -- subtype Tnn is discr_type range discr_type'First .. max;
484 -- And insert this declaration into the tree. The type of the
485 -- discriminant is then reset to this more restricted subtype.
487 Tnn
:= Make_Temporary
(Loc
, 'T');
489 Insert_Action
(Declaration_Node
(Rtype
),
490 Make_Subtype_Declaration
(Loc
,
491 Defining_Identifier
=> Tnn
,
492 Subtype_Indication
=>
493 Make_Subtype_Indication
(Loc
,
494 Subtype_Mark
=> New_Occurrence_Of
(Dtyp
, Loc
),
496 Make_Range_Constraint
(Loc
,
500 Make_Attribute_Reference
(Loc
,
501 Attribute_Name
=> Name_First
,
502 Prefix
=> New_Occurrence_Of
(Dtyp
, Loc
)),
504 Make_Integer_Literal
(Loc
,
505 Intval
=> UI_Max
(Loval
, Ahiv
)))))));
507 Set_Etype
(Discr
, Tnn
);
511 Next_Component
(Comp
);
513 end Adjust_Discriminants
;
515 ---------------------------
516 -- Build_Array_Init_Proc --
517 ---------------------------
519 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
) is
520 Comp_Type
: constant Entity_Id
:= Component_Type
(A_Type
);
521 Comp_Simple_Init
: constant Boolean :=
522 Needs_Simple_Initialization
525 not (Validity_Check_Copies
and Is_Bit_Packed_Array
(A_Type
)));
526 -- True if the component needs simple initialization, based on its type,
527 -- plus the fact that we do not do simple initialization for components
528 -- of bit-packed arrays when validity checks are enabled, because the
529 -- initialization with deliberately out-of-range values would raise
532 Body_Stmts
: List_Id
;
533 Has_Default_Init
: Boolean;
534 Index_List
: List_Id
;
538 function Init_Component
return List_Id
;
539 -- Create one statement to initialize one array component, designated
540 -- by a full set of indexes.
542 function Init_One_Dimension
(N
: Int
) return List_Id
;
543 -- Create loop to initialize one dimension of the array. The single
544 -- statement in the loop body initializes the inner dimensions if any,
545 -- or else the single component. Note that this procedure is called
546 -- recursively, with N being the dimension to be initialized. A call
547 -- with N greater than the number of dimensions simply generates the
548 -- component initialization, terminating the recursion.
554 function Init_Component
return List_Id
is
559 Make_Indexed_Component
(Loc
,
560 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
561 Expressions
=> Index_List
);
563 if Has_Default_Aspect
(A_Type
) then
564 Set_Assignment_OK
(Comp
);
566 Make_Assignment_Statement
(Loc
,
569 Convert_To
(Comp_Type
,
570 Default_Aspect_Component_Value
(First_Subtype
(A_Type
)))));
572 elsif Comp_Simple_Init
then
573 Set_Assignment_OK
(Comp
);
575 Make_Assignment_Statement
(Loc
,
579 (Comp_Type
, Nod
, Component_Size
(A_Type
))));
582 Clean_Task_Names
(Comp_Type
, Proc_Id
);
584 Build_Initialization_Call
585 (Loc
, Comp
, Comp_Type
,
586 In_Init_Proc
=> True,
587 Enclos_Type
=> A_Type
);
591 ------------------------
592 -- Init_One_Dimension --
593 ------------------------
595 function Init_One_Dimension
(N
: Int
) return List_Id
is
599 -- If the component does not need initializing, then there is nothing
600 -- to do here, so we return a null body. This occurs when generating
601 -- the dummy Init_Proc needed for Initialize_Scalars processing.
603 if not Has_Non_Null_Base_Init_Proc
(Comp_Type
)
604 and then not Comp_Simple_Init
605 and then not Has_Task
(Comp_Type
)
606 and then not Has_Default_Aspect
(A_Type
)
608 return New_List
(Make_Null_Statement
(Loc
));
610 -- If all dimensions dealt with, we simply initialize the component
612 elsif N
> Number_Dimensions
(A_Type
) then
613 return Init_Component
;
615 -- Here we generate the required loop
619 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
621 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
624 Make_Implicit_Loop_Statement
(Nod
,
627 Make_Iteration_Scheme
(Loc
,
628 Loop_Parameter_Specification
=>
629 Make_Loop_Parameter_Specification
(Loc
,
630 Defining_Identifier
=> Index
,
631 Discrete_Subtype_Definition
=>
632 Make_Attribute_Reference
(Loc
,
634 Make_Identifier
(Loc
, Name_uInit
),
635 Attribute_Name
=> Name_Range
,
636 Expressions
=> New_List
(
637 Make_Integer_Literal
(Loc
, N
))))),
638 Statements
=> Init_One_Dimension
(N
+ 1)));
640 end Init_One_Dimension
;
642 -- Start of processing for Build_Array_Init_Proc
645 -- The init proc is created when analyzing the freeze node for the type,
646 -- but it properly belongs with the array type declaration. However, if
647 -- the freeze node is for a subtype of a type declared in another unit
648 -- it seems preferable to use the freeze node as the source location of
649 -- the init proc. In any case this is preferable for gcov usage, and
650 -- the Sloc is not otherwise used by the compiler.
652 if In_Open_Scopes
(Scope
(A_Type
)) then
653 Loc
:= Sloc
(A_Type
);
658 -- Nothing to generate in the following cases:
660 -- 1. Initialization is suppressed for the type
661 -- 2. An initialization already exists for the base type
663 if Initialization_Suppressed
(A_Type
)
664 or else Present
(Base_Init_Proc
(A_Type
))
669 Index_List
:= New_List
;
671 -- We need an initialization procedure if any of the following is true:
673 -- 1. The component type has an initialization procedure
674 -- 2. The component type needs simple initialization
675 -- 3. Tasks are present
676 -- 4. The type is marked as a public entity
677 -- 5. The array type has a Default_Component_Value aspect
679 -- The reason for the public entity test is to deal properly with the
680 -- Initialize_Scalars pragma. This pragma can be set in the client and
681 -- not in the declaring package, this means the client will make a call
682 -- to the initialization procedure (because one of conditions 1-3 must
683 -- apply in this case), and we must generate a procedure (even if it is
684 -- null) to satisfy the call in this case.
686 -- Exception: do not build an array init_proc for a type whose root
687 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
688 -- is no place to put the code, and in any case we handle initialization
689 -- of such types (in the Initialize_Scalars case, that's the only time
690 -- the issue arises) in a special manner anyway which does not need an
693 Has_Default_Init
:= Has_Non_Null_Base_Init_Proc
(Comp_Type
)
694 or else Comp_Simple_Init
695 or else Has_Task
(Comp_Type
)
696 or else Has_Default_Aspect
(A_Type
);
699 or else (not Restriction_Active
(No_Initialize_Scalars
)
700 and then Is_Public
(A_Type
)
701 and then not Is_Standard_String_Type
(A_Type
))
704 Make_Defining_Identifier
(Loc
,
705 Chars
=> Make_Init_Proc_Name
(A_Type
));
707 -- If No_Default_Initialization restriction is active, then we don't
708 -- want to build an init_proc, but we need to mark that an init_proc
709 -- would be needed if this restriction was not active (so that we can
710 -- detect attempts to call it), so set a dummy init_proc in place.
711 -- This is only done though when actual default initialization is
712 -- needed (and not done when only Is_Public is True), since otherwise
713 -- objects such as arrays of scalars could be wrongly flagged as
714 -- violating the restriction.
716 if Restriction_Active
(No_Default_Initialization
) then
717 if Has_Default_Init
then
718 Set_Init_Proc
(A_Type
, Proc_Id
);
724 Body_Stmts
:= Init_One_Dimension
(1);
727 Make_Subprogram_Body
(Loc
,
729 Make_Procedure_Specification
(Loc
,
730 Defining_Unit_Name
=> Proc_Id
,
731 Parameter_Specifications
=> Init_Formals
(A_Type
)),
732 Declarations
=> New_List
,
733 Handled_Statement_Sequence
=>
734 Make_Handled_Sequence_Of_Statements
(Loc
,
735 Statements
=> Body_Stmts
)));
737 Set_Ekind
(Proc_Id
, E_Procedure
);
738 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
739 Set_Is_Internal
(Proc_Id
);
740 Set_Has_Completion
(Proc_Id
);
742 if not Debug_Generated_Code
then
743 Set_Debug_Info_Off
(Proc_Id
);
746 -- Set Inlined on Init_Proc if it is set on the Init_Proc of the
747 -- component type itself (see also Build_Record_Init_Proc).
749 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Comp_Type
));
751 -- Associate Init_Proc with type, and determine if the procedure
752 -- is null (happens because of the Initialize_Scalars pragma case,
753 -- where we have to generate a null procedure in case it is called
754 -- by a client with Initialize_Scalars set). Such procedures have
755 -- to be generated, but do not have to be called, so we mark them
756 -- as null to suppress the call.
758 Set_Init_Proc
(A_Type
, Proc_Id
);
760 if List_Length
(Body_Stmts
) = 1
762 -- We must skip SCIL nodes because they may have been added to this
763 -- list by Insert_Actions.
765 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
767 Set_Is_Null_Init_Proc
(Proc_Id
);
770 -- Try to build a static aggregate to statically initialize
771 -- objects of the type. This can only be done for constrained
772 -- one-dimensional arrays with static bounds.
774 Set_Static_Initialization
776 Build_Equivalent_Array_Aggregate
(First_Subtype
(A_Type
)));
779 end Build_Array_Init_Proc
;
781 --------------------------------
782 -- Build_Discr_Checking_Funcs --
783 --------------------------------
785 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
) is
788 Enclosing_Func_Id
: Entity_Id
;
793 function Build_Case_Statement
794 (Case_Id
: Entity_Id
;
795 Variant
: Node_Id
) return Node_Id
;
796 -- Build a case statement containing only two alternatives. The first
797 -- alternative corresponds exactly to the discrete choices given on the
798 -- variant with contains the components that we are generating the
799 -- checks for. If the discriminant is one of these return False. The
800 -- second alternative is an OTHERS choice that will return True
801 -- indicating the discriminant did not match.
803 function Build_Dcheck_Function
804 (Case_Id
: Entity_Id
;
805 Variant
: Node_Id
) return Entity_Id
;
806 -- Build the discriminant checking function for a given variant
808 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
);
809 -- Builds the discriminant checking function for each variant of the
810 -- given variant part of the record type.
812 --------------------------
813 -- Build_Case_Statement --
814 --------------------------
816 function Build_Case_Statement
817 (Case_Id
: Entity_Id
;
818 Variant
: Node_Id
) return Node_Id
820 Alt_List
: constant List_Id
:= New_List
;
821 Actuals_List
: List_Id
;
823 Case_Alt_Node
: Node_Id
;
825 Choice_List
: List_Id
;
827 Return_Node
: Node_Id
;
830 Case_Node
:= New_Node
(N_Case_Statement
, Loc
);
832 -- Replace the discriminant which controls the variant with the name
833 -- of the formal of the checking function.
835 Set_Expression
(Case_Node
, Make_Identifier
(Loc
, Chars
(Case_Id
)));
837 Choice
:= First
(Discrete_Choices
(Variant
));
839 if Nkind
(Choice
) = N_Others_Choice
then
840 Choice_List
:= New_Copy_List
(Others_Discrete_Choices
(Choice
));
842 Choice_List
:= New_Copy_List
(Discrete_Choices
(Variant
));
845 if not Is_Empty_List
(Choice_List
) then
846 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
847 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
849 -- In case this is a nested variant, we need to return the result
850 -- of the discriminant checking function for the immediately
851 -- enclosing variant.
853 if Present
(Enclosing_Func_Id
) then
854 Actuals_List
:= New_List
;
856 D
:= First_Discriminant
(Rec_Id
);
857 while Present
(D
) loop
858 Append
(Make_Identifier
(Loc
, Chars
(D
)), Actuals_List
);
859 Next_Discriminant
(D
);
863 Make_Simple_Return_Statement
(Loc
,
865 Make_Function_Call
(Loc
,
867 New_Occurrence_Of
(Enclosing_Func_Id
, Loc
),
868 Parameter_Associations
=>
873 Make_Simple_Return_Statement
(Loc
,
875 New_Occurrence_Of
(Standard_False
, Loc
));
878 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
879 Append
(Case_Alt_Node
, Alt_List
);
882 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
883 Choice_List
:= New_List
(New_Node
(N_Others_Choice
, Loc
));
884 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
887 Make_Simple_Return_Statement
(Loc
,
889 New_Occurrence_Of
(Standard_True
, Loc
));
891 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
892 Append
(Case_Alt_Node
, Alt_List
);
894 Set_Alternatives
(Case_Node
, Alt_List
);
896 end Build_Case_Statement
;
898 ---------------------------
899 -- Build_Dcheck_Function --
900 ---------------------------
902 function Build_Dcheck_Function
903 (Case_Id
: Entity_Id
;
904 Variant
: Node_Id
) return Entity_Id
908 Parameter_List
: List_Id
;
912 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
913 Sequence
:= Sequence
+ 1;
916 Make_Defining_Identifier
(Loc
,
917 Chars
=> New_External_Name
(Chars
(Rec_Id
), 'D', Sequence
));
918 Set_Is_Discriminant_Check_Function
(Func_Id
);
920 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
921 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
923 Parameter_List
:= Build_Discriminant_Formals
(Rec_Id
, False);
925 Set_Parameter_Specifications
(Spec_Node
, Parameter_List
);
926 Set_Result_Definition
(Spec_Node
,
927 New_Occurrence_Of
(Standard_Boolean
, Loc
));
928 Set_Specification
(Body_Node
, Spec_Node
);
929 Set_Declarations
(Body_Node
, New_List
);
931 Set_Handled_Statement_Sequence
(Body_Node
,
932 Make_Handled_Sequence_Of_Statements
(Loc
,
933 Statements
=> New_List
(
934 Build_Case_Statement
(Case_Id
, Variant
))));
936 Set_Ekind
(Func_Id
, E_Function
);
937 Set_Mechanism
(Func_Id
, Default_Mechanism
);
938 Set_Is_Inlined
(Func_Id
, True);
939 Set_Is_Pure
(Func_Id
, True);
940 Set_Is_Public
(Func_Id
, Is_Public
(Rec_Id
));
941 Set_Is_Internal
(Func_Id
, True);
943 if not Debug_Generated_Code
then
944 Set_Debug_Info_Off
(Func_Id
);
949 Append_Freeze_Action
(Rec_Id
, Body_Node
);
950 Set_Dcheck_Function
(Variant
, Func_Id
);
952 end Build_Dcheck_Function
;
954 ----------------------------
955 -- Build_Dcheck_Functions --
956 ----------------------------
958 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
) is
959 Component_List_Node
: Node_Id
;
961 Discr_Name
: Entity_Id
;
964 Saved_Enclosing_Func_Id
: Entity_Id
;
967 -- Build the discriminant-checking function for each variant, and
968 -- label all components of that variant with the function's name.
969 -- We only Generate a discriminant-checking function when the
970 -- variant is not empty, to prevent the creation of dead code.
972 Discr_Name
:= Entity
(Name
(Variant_Part_Node
));
973 Variant
:= First_Non_Pragma
(Variants
(Variant_Part_Node
));
975 while Present
(Variant
) loop
976 Component_List_Node
:= Component_List
(Variant
);
978 if not Null_Present
(Component_List_Node
) then
979 Func_Id
:= Build_Dcheck_Function
(Discr_Name
, Variant
);
982 First_Non_Pragma
(Component_Items
(Component_List_Node
));
983 while Present
(Decl
) loop
984 Set_Discriminant_Checking_Func
985 (Defining_Identifier
(Decl
), Func_Id
);
986 Next_Non_Pragma
(Decl
);
989 if Present
(Variant_Part
(Component_List_Node
)) then
990 Saved_Enclosing_Func_Id
:= Enclosing_Func_Id
;
991 Enclosing_Func_Id
:= Func_Id
;
992 Build_Dcheck_Functions
(Variant_Part
(Component_List_Node
));
993 Enclosing_Func_Id
:= Saved_Enclosing_Func_Id
;
997 Next_Non_Pragma
(Variant
);
999 end Build_Dcheck_Functions
;
1001 -- Start of processing for Build_Discr_Checking_Funcs
1004 -- Only build if not done already
1006 if not Discr_Check_Funcs_Built
(N
) then
1007 Type_Def
:= Type_Definition
(N
);
1009 if Nkind
(Type_Def
) = N_Record_Definition
then
1010 if No
(Component_List
(Type_Def
)) then -- null record.
1013 V
:= Variant_Part
(Component_List
(Type_Def
));
1016 else pragma Assert
(Nkind
(Type_Def
) = N_Derived_Type_Definition
);
1017 if No
(Component_List
(Record_Extension_Part
(Type_Def
))) then
1021 (Component_List
(Record_Extension_Part
(Type_Def
)));
1025 Rec_Id
:= Defining_Identifier
(N
);
1027 if Present
(V
) and then not Is_Unchecked_Union
(Rec_Id
) then
1029 Enclosing_Func_Id
:= Empty
;
1030 Build_Dcheck_Functions
(V
);
1033 Set_Discr_Check_Funcs_Built
(N
);
1035 end Build_Discr_Checking_Funcs
;
1037 --------------------------------
1038 -- Build_Discriminant_Formals --
1039 --------------------------------
1041 function Build_Discriminant_Formals
1042 (Rec_Id
: Entity_Id
;
1043 Use_Dl
: Boolean) return List_Id
1045 Loc
: Source_Ptr
:= Sloc
(Rec_Id
);
1046 Parameter_List
: constant List_Id
:= New_List
;
1049 Formal_Type
: Entity_Id
;
1050 Param_Spec_Node
: Node_Id
;
1053 if Has_Discriminants
(Rec_Id
) then
1054 D
:= First_Discriminant
(Rec_Id
);
1055 while Present
(D
) loop
1059 Formal
:= Discriminal
(D
);
1060 Formal_Type
:= Etype
(Formal
);
1062 Formal
:= Make_Defining_Identifier
(Loc
, Chars
(D
));
1063 Formal_Type
:= Etype
(D
);
1067 Make_Parameter_Specification
(Loc
,
1068 Defining_Identifier
=> Formal
,
1070 New_Occurrence_Of
(Formal_Type
, Loc
));
1071 Append
(Param_Spec_Node
, Parameter_List
);
1072 Next_Discriminant
(D
);
1076 return Parameter_List
;
1077 end Build_Discriminant_Formals
;
1079 --------------------------------------
1080 -- Build_Equivalent_Array_Aggregate --
1081 --------------------------------------
1083 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
is
1084 Loc
: constant Source_Ptr
:= Sloc
(T
);
1085 Comp_Type
: constant Entity_Id
:= Component_Type
(T
);
1086 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(T
));
1087 Proc
: constant Entity_Id
:= Base_Init_Proc
(T
);
1093 if not Is_Constrained
(T
)
1094 or else Number_Dimensions
(T
) > 1
1097 Initialization_Warning
(T
);
1101 Lo
:= Type_Low_Bound
(Index_Type
);
1102 Hi
:= Type_High_Bound
(Index_Type
);
1104 if not Compile_Time_Known_Value
(Lo
)
1105 or else not Compile_Time_Known_Value
(Hi
)
1107 Initialization_Warning
(T
);
1111 if Is_Record_Type
(Comp_Type
)
1112 and then Present
(Base_Init_Proc
(Comp_Type
))
1114 Expr
:= Static_Initialization
(Base_Init_Proc
(Comp_Type
));
1117 Initialization_Warning
(T
);
1122 Initialization_Warning
(T
);
1126 Aggr
:= Make_Aggregate
(Loc
, No_List
, New_List
);
1127 Set_Etype
(Aggr
, T
);
1128 Set_Aggregate_Bounds
(Aggr
,
1130 Low_Bound
=> New_Copy
(Lo
),
1131 High_Bound
=> New_Copy
(Hi
)));
1132 Set_Parent
(Aggr
, Parent
(Proc
));
1134 Append_To
(Component_Associations
(Aggr
),
1135 Make_Component_Association
(Loc
,
1139 Low_Bound
=> New_Copy
(Lo
),
1140 High_Bound
=> New_Copy
(Hi
))),
1141 Expression
=> Expr
));
1143 if Static_Array_Aggregate
(Aggr
) then
1146 Initialization_Warning
(T
);
1149 end Build_Equivalent_Array_Aggregate
;
1151 ---------------------------------------
1152 -- Build_Equivalent_Record_Aggregate --
1153 ---------------------------------------
1155 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
is
1158 Comp_Type
: Entity_Id
;
1160 -- Start of processing for Build_Equivalent_Record_Aggregate
1163 if not Is_Record_Type
(T
)
1164 or else Has_Discriminants
(T
)
1165 or else Is_Limited_Type
(T
)
1166 or else Has_Non_Standard_Rep
(T
)
1168 Initialization_Warning
(T
);
1172 Comp
:= First_Component
(T
);
1174 -- A null record needs no warning
1180 while Present
(Comp
) loop
1182 -- Array components are acceptable if initialized by a positional
1183 -- aggregate with static components.
1185 if Is_Array_Type
(Etype
(Comp
)) then
1186 Comp_Type
:= Component_Type
(Etype
(Comp
));
1188 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1189 or else No
(Expression
(Parent
(Comp
)))
1190 or else Nkind
(Expression
(Parent
(Comp
))) /= N_Aggregate
1192 Initialization_Warning
(T
);
1195 elsif Is_Scalar_Type
(Component_Type
(Etype
(Comp
)))
1197 (not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1199 not Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
)))
1201 Initialization_Warning
(T
);
1205 not Static_Array_Aggregate
(Expression
(Parent
(Comp
)))
1207 Initialization_Warning
(T
);
1211 elsif Is_Scalar_Type
(Etype
(Comp
)) then
1212 Comp_Type
:= Etype
(Comp
);
1214 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1215 or else No
(Expression
(Parent
(Comp
)))
1216 or else not Compile_Time_Known_Value
(Expression
(Parent
(Comp
)))
1217 or else not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1219 Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
))
1221 Initialization_Warning
(T
);
1225 -- For now, other types are excluded
1228 Initialization_Warning
(T
);
1232 Next_Component
(Comp
);
1235 -- All components have static initialization. Build positional aggregate
1236 -- from the given expressions or defaults.
1238 Agg
:= Make_Aggregate
(Sloc
(T
), New_List
, New_List
);
1239 Set_Parent
(Agg
, Parent
(T
));
1241 Comp
:= First_Component
(T
);
1242 while Present
(Comp
) loop
1244 (New_Copy_Tree
(Expression
(Parent
(Comp
))), Expressions
(Agg
));
1245 Next_Component
(Comp
);
1248 Analyze_And_Resolve
(Agg
, T
);
1250 end Build_Equivalent_Record_Aggregate
;
1252 -------------------------------
1253 -- Build_Initialization_Call --
1254 -------------------------------
1256 -- References to a discriminant inside the record type declaration can
1257 -- appear either in the subtype_indication to constrain a record or an
1258 -- array, or as part of a larger expression given for the initial value
1259 -- of a component. In both of these cases N appears in the record
1260 -- initialization procedure and needs to be replaced by the formal
1261 -- parameter of the initialization procedure which corresponds to that
1264 -- In the example below, references to discriminants D1 and D2 in proc_1
1265 -- are replaced by references to formals with the same name
1268 -- A similar replacement is done for calls to any record initialization
1269 -- procedure for any components that are themselves of a record type.
1271 -- type R (D1, D2 : Integer) is record
1272 -- X : Integer := F * D1;
1273 -- Y : Integer := F * D2;
1276 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1280 -- Out_2.X := F * D1;
1281 -- Out_2.Y := F * D2;
1284 function Build_Initialization_Call
1288 In_Init_Proc
: Boolean := False;
1289 Enclos_Type
: Entity_Id
:= Empty
;
1290 Discr_Map
: Elist_Id
:= New_Elmt_List
;
1291 With_Default_Init
: Boolean := False;
1292 Constructor_Ref
: Node_Id
:= Empty
) return List_Id
1294 Res
: constant List_Id
:= New_List
;
1296 Full_Type
: Entity_Id
;
1298 procedure Check_Predicated_Discriminant
1301 -- Discriminants whose subtypes have predicates are checked in two
1303 -- a) When an object is default-initialized and assertions are enabled
1304 -- we check that the value of the discriminant obeys the predicate.
1306 -- b) In all cases, if the discriminant controls a variant and the
1307 -- variant has no others_choice, Constraint_Error must be raised if
1308 -- the predicate is violated, because there is no variant covered
1309 -- by the illegal discriminant value.
1311 -----------------------------------
1312 -- Check_Predicated_Discriminant --
1313 -----------------------------------
1315 procedure Check_Predicated_Discriminant
1319 Typ
: constant Entity_Id
:= Etype
(Discr
);
1321 procedure Check_Missing_Others
(V
: Node_Id
);
1324 --------------------------
1325 -- Check_Missing_Others --
1326 --------------------------
1328 procedure Check_Missing_Others
(V
: Node_Id
) is
1334 Last_Var
:= Last_Non_Pragma
(Variants
(V
));
1335 Choice
:= First
(Discrete_Choices
(Last_Var
));
1337 -- An others_choice is added during expansion for gcc use, but
1338 -- does not cover the illegality.
1340 if Entity
(Name
(V
)) = Discr
then
1342 and then (Nkind
(Choice
) /= N_Others_Choice
1343 or else not Comes_From_Source
(Choice
))
1345 Check_Expression_Against_Static_Predicate
(Val
, Typ
);
1347 if not Is_Static_Expression
(Val
) then
1349 Make_Raise_Constraint_Error
(Loc
,
1352 Right_Opnd
=> Make_Predicate_Call
(Typ
, Val
)),
1353 Reason
=> CE_Invalid_Data
));
1358 -- Check whether some nested variant is ruled by the predicated
1361 Alt
:= First
(Variants
(V
));
1362 while Present
(Alt
) loop
1363 if Nkind
(Alt
) = N_Variant
1364 and then Present
(Variant_Part
(Component_List
(Alt
)))
1366 Check_Missing_Others
1367 (Variant_Part
(Component_List
(Alt
)));
1372 end Check_Missing_Others
;
1378 -- Start of processing for Check_Predicated_Discriminant
1381 if Ekind
(Base_Type
(Full_Type
)) = E_Record_Type
then
1382 Def
:= Type_Definition
(Parent
(Base_Type
(Full_Type
)));
1387 if Policy_In_Effect
(Name_Assert
) = Name_Check
1388 and then not Predicates_Ignored
(Etype
(Discr
))
1390 Prepend_To
(Res
, Make_Predicate_Check
(Typ
, Val
));
1393 -- If discriminant controls a variant, verify that predicate is
1394 -- obeyed or else an Others_Choice is present.
1396 if Nkind
(Def
) = N_Record_Definition
1397 and then Present
(Variant_Part
(Component_List
(Def
)))
1398 and then Policy_In_Effect
(Name_Assert
) = Name_Ignore
1400 Check_Missing_Others
(Variant_Part
(Component_List
(Def
)));
1402 end Check_Predicated_Discriminant
;
1411 First_Arg
: Node_Id
;
1412 Full_Init_Type
: Entity_Id
;
1413 Init_Call
: Node_Id
;
1414 Init_Type
: Entity_Id
;
1417 -- Start of processing for Build_Initialization_Call
1420 pragma Assert
(Constructor_Ref
= Empty
1421 or else Is_CPP_Constructor_Call
(Constructor_Ref
));
1423 if No
(Constructor_Ref
) then
1424 Proc
:= Base_Init_Proc
(Typ
);
1426 Proc
:= Base_Init_Proc
(Typ
, Entity
(Name
(Constructor_Ref
)));
1429 pragma Assert
(Present
(Proc
));
1430 Init_Type
:= Etype
(First_Formal
(Proc
));
1431 Full_Init_Type
:= Underlying_Type
(Init_Type
);
1433 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1434 -- is active (in which case we make the call anyway, since in the
1435 -- actual compiled client it may be non null).
1437 if Is_Null_Init_Proc
(Proc
) and then not Init_Or_Norm_Scalars
then
1440 -- Nothing to do for an array of controlled components that have only
1441 -- the inherited Initialize primitive. This is a useful optimization
1444 elsif Is_Trivial_Subprogram
(Proc
)
1445 and then Is_Array_Type
(Full_Init_Type
)
1447 return New_List
(Make_Null_Statement
(Loc
));
1450 -- Use the [underlying] full view when dealing with a private type. This
1451 -- may require several steps depending on derivations.
1455 if Is_Private_Type
(Full_Type
) then
1456 if Present
(Full_View
(Full_Type
)) then
1457 Full_Type
:= Full_View
(Full_Type
);
1459 elsif Present
(Underlying_Full_View
(Full_Type
)) then
1460 Full_Type
:= Underlying_Full_View
(Full_Type
);
1462 -- When a private type acts as a generic actual and lacks a full
1463 -- view, use the base type.
1465 elsif Is_Generic_Actual_Type
(Full_Type
) then
1466 Full_Type
:= Base_Type
(Full_Type
);
1468 elsif Ekind
(Full_Type
) = E_Private_Subtype
1469 and then (not Has_Discriminants
(Full_Type
)
1470 or else No
(Discriminant_Constraint
(Full_Type
)))
1472 Full_Type
:= Etype
(Full_Type
);
1474 -- The loop has recovered the [underlying] full view, stop the
1481 -- The type is not private, nothing to do
1488 -- If Typ is derived, the procedure is the initialization procedure for
1489 -- the root type. Wrap the argument in an conversion to make it type
1490 -- honest. Actually it isn't quite type honest, because there can be
1491 -- conflicts of views in the private type case. That is why we set
1492 -- Conversion_OK in the conversion node.
1494 if (Is_Record_Type
(Typ
)
1495 or else Is_Array_Type
(Typ
)
1496 or else Is_Private_Type
(Typ
))
1497 and then Init_Type
/= Base_Type
(Typ
)
1499 First_Arg
:= OK_Convert_To
(Etype
(Init_Type
), Id_Ref
);
1500 Set_Etype
(First_Arg
, Init_Type
);
1503 First_Arg
:= Id_Ref
;
1506 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Typ
));
1508 -- In the tasks case, add _Master as the value of the _Master parameter
1509 -- and _Chain as the value of the _Chain parameter. At the outer level,
1510 -- these will be variables holding the corresponding values obtained
1511 -- from GNARL. At inner levels, they will be the parameters passed down
1512 -- through the outer routines.
1514 if Has_Task
(Full_Type
) then
1515 if Restriction_Active
(No_Task_Hierarchy
) then
1517 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1519 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1522 -- Add _Chain (not done for sequential elaboration policy, see
1523 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1525 if Partition_Elaboration_Policy
/= 'S' then
1526 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1529 -- Ada 2005 (AI-287): In case of default initialized components
1530 -- with tasks, we generate a null string actual parameter.
1531 -- This is just a workaround that must be improved later???
1533 if With_Default_Init
then
1535 Make_String_Literal
(Loc
,
1540 Build_Task_Image_Decls
(Loc
, Id_Ref
, Enclos_Type
, In_Init_Proc
);
1541 Decl
:= Last
(Decls
);
1544 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
));
1545 Append_List
(Decls
, Res
);
1553 -- Add discriminant values if discriminants are present
1555 if Has_Discriminants
(Full_Init_Type
) then
1556 Discr
:= First_Discriminant
(Full_Init_Type
);
1557 while Present
(Discr
) loop
1559 -- If this is a discriminated concurrent type, the init_proc
1560 -- for the corresponding record is being called. Use that type
1561 -- directly to find the discriminant value, to handle properly
1562 -- intervening renamed discriminants.
1565 T
: Entity_Id
:= Full_Type
;
1568 if Is_Protected_Type
(T
) then
1569 T
:= Corresponding_Record_Type
(T
);
1573 Get_Discriminant_Value
(
1576 Discriminant_Constraint
(Full_Type
));
1579 -- If the target has access discriminants, and is constrained by
1580 -- an access to the enclosing construct, i.e. a current instance,
1581 -- replace the reference to the type by a reference to the object.
1583 if Nkind
(Arg
) = N_Attribute_Reference
1584 and then Is_Access_Type
(Etype
(Arg
))
1585 and then Is_Entity_Name
(Prefix
(Arg
))
1586 and then Is_Type
(Entity
(Prefix
(Arg
)))
1589 Make_Attribute_Reference
(Loc
,
1590 Prefix
=> New_Copy
(Prefix
(Id_Ref
)),
1591 Attribute_Name
=> Name_Unrestricted_Access
);
1593 elsif In_Init_Proc
then
1595 -- Replace any possible references to the discriminant in the
1596 -- call to the record initialization procedure with references
1597 -- to the appropriate formal parameter.
1599 if Nkind
(Arg
) = N_Identifier
1600 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1602 Arg
:= New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
);
1604 -- Otherwise make a copy of the default expression. Note that
1605 -- we use the current Sloc for this, because we do not want the
1606 -- call to appear to be at the declaration point. Within the
1607 -- expression, replace discriminants with their discriminals.
1611 New_Copy_Tree
(Arg
, Map
=> Discr_Map
, New_Sloc
=> Loc
);
1615 if Is_Constrained
(Full_Type
) then
1616 Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
1618 -- The constraints come from the discriminant default exps,
1619 -- they must be reevaluated, so we use New_Copy_Tree but we
1620 -- ensure the proper Sloc (for any embedded calls).
1621 -- In addition, if a predicate check is needed on the value
1622 -- of the discriminant, insert it ahead of the call.
1624 Arg
:= New_Copy_Tree
(Arg
, New_Sloc
=> Loc
);
1627 if Has_Predicates
(Etype
(Discr
)) then
1628 Check_Predicated_Discriminant
(Arg
, Discr
);
1632 -- Ada 2005 (AI-287): In case of default initialized components,
1633 -- if the component is constrained with a discriminant of the
1634 -- enclosing type, we need to generate the corresponding selected
1635 -- component node to access the discriminant value. In other cases
1636 -- this is not required, either because we are inside the init
1637 -- proc and we use the corresponding formal, or else because the
1638 -- component is constrained by an expression.
1640 if With_Default_Init
1641 and then Nkind
(Id_Ref
) = N_Selected_Component
1642 and then Nkind
(Arg
) = N_Identifier
1643 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1646 Make_Selected_Component
(Loc
,
1647 Prefix
=> New_Copy_Tree
(Prefix
(Id_Ref
)),
1648 Selector_Name
=> Arg
));
1650 Append_To
(Args
, Arg
);
1653 Next_Discriminant
(Discr
);
1657 -- If this is a call to initialize the parent component of a derived
1658 -- tagged type, indicate that the tag should not be set in the parent.
1660 if Is_Tagged_Type
(Full_Init_Type
)
1661 and then not Is_CPP_Class
(Full_Init_Type
)
1662 and then Nkind
(Id_Ref
) = N_Selected_Component
1663 and then Chars
(Selector_Name
(Id_Ref
)) = Name_uParent
1665 Append_To
(Args
, New_Occurrence_Of
(Standard_False
, Loc
));
1667 elsif Present
(Constructor_Ref
) then
1668 Append_List_To
(Args
,
1669 New_Copy_List
(Parameter_Associations
(Constructor_Ref
)));
1673 Make_Procedure_Call_Statement
(Loc
,
1674 Name
=> New_Occurrence_Of
(Proc
, Loc
),
1675 Parameter_Associations
=> Args
));
1677 if Needs_Finalization
(Typ
)
1678 and then Nkind
(Id_Ref
) = N_Selected_Component
1680 if Chars
(Selector_Name
(Id_Ref
)) /= Name_uParent
then
1683 (Obj_Ref
=> New_Copy_Tree
(First_Arg
),
1686 -- Guard against a missing [Deep_]Initialize when the type was not
1689 if Present
(Init_Call
) then
1690 Append_To
(Res
, Init_Call
);
1698 when RE_Not_Available
=>
1700 end Build_Initialization_Call
;
1702 ----------------------------
1703 -- Build_Record_Init_Proc --
1704 ----------------------------
1706 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
) is
1707 Decls
: constant List_Id
:= New_List
;
1708 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
1709 Loc
: constant Source_Ptr
:= Sloc
(Rec_Ent
);
1711 Proc_Id
: Entity_Id
;
1712 Rec_Type
: Entity_Id
;
1713 Set_Tag
: Entity_Id
:= Empty
;
1715 function Build_Assignment
1717 Default
: Node_Id
) return List_Id
;
1718 -- Build an assignment statement that assigns the default expression to
1719 -- its corresponding record component if defined. The left-hand side of
1720 -- the assignment is marked Assignment_OK so that initialization of
1721 -- limited private records works correctly. This routine may also build
1722 -- an adjustment call if the component is controlled.
1724 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
);
1725 -- If the record has discriminants, add assignment statements to
1726 -- Statement_List to initialize the discriminant values from the
1727 -- arguments of the initialization procedure.
1729 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
;
1730 -- Build a list representing a sequence of statements which initialize
1731 -- components of the given component list. This may involve building
1732 -- case statements for the variant parts. Append any locally declared
1733 -- objects on list Decls.
1735 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
;
1736 -- Given an untagged type-derivation that declares discriminants, e.g.
1738 -- type R (R1, R2 : Integer) is record ... end record;
1739 -- type D (D1 : Integer) is new R (1, D1);
1741 -- we make the _init_proc of D be
1743 -- procedure _init_proc (X : D; D1 : Integer) is
1745 -- _init_proc (R (X), 1, D1);
1748 -- This function builds the call statement in this _init_proc.
1750 procedure Build_CPP_Init_Procedure
;
1751 -- Build the tree corresponding to the procedure specification and body
1752 -- of the IC procedure that initializes the C++ part of the dispatch
1753 -- table of an Ada tagged type that is a derivation of a CPP type.
1754 -- Install it as the CPP_Init TSS.
1756 procedure Build_Init_Procedure
;
1757 -- Build the tree corresponding to the procedure specification and body
1758 -- of the initialization procedure and install it as the _init TSS.
1760 procedure Build_Offset_To_Top_Functions
;
1761 -- Ada 2005 (AI-251): Build the tree corresponding to the procedure spec
1762 -- and body of Offset_To_Top, a function used in conjuction with types
1763 -- having secondary dispatch tables.
1765 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
);
1766 -- Add range checks to components of discriminated records. S is a
1767 -- subtype indication of a record component. Check_List is a list
1768 -- to which the check actions are appended.
1770 function Component_Needs_Simple_Initialization
1771 (T
: Entity_Id
) return Boolean;
1772 -- Determine if a component needs simple initialization, given its type
1773 -- T. This routine is the same as Needs_Simple_Initialization except for
1774 -- components of type Tag and Interface_Tag. These two access types do
1775 -- not require initialization since they are explicitly initialized by
1778 function Parent_Subtype_Renaming_Discrims
return Boolean;
1779 -- Returns True for base types N that rename discriminants, else False
1781 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean;
1782 -- Determine whether a record initialization procedure needs to be
1783 -- generated for the given record type.
1785 ----------------------
1786 -- Build_Assignment --
1787 ----------------------
1789 function Build_Assignment
1791 Default
: Node_Id
) return List_Id
1793 Default_Loc
: constant Source_Ptr
:= Sloc
(Default
);
1794 Typ
: constant Entity_Id
:= Underlying_Type
(Etype
(Id
));
1797 Exp
: Node_Id
:= Default
;
1798 Kind
: Node_Kind
:= Nkind
(Default
);
1802 function Replace_Discr_Ref
(N
: Node_Id
) return Traverse_Result
;
1803 -- Analysis of the aggregate has replaced discriminants by their
1804 -- corresponding discriminals, but these are irrelevant when the
1805 -- component has a mutable type and is initialized with an aggregate.
1806 -- Instead, they must be replaced by the values supplied in the
1807 -- aggregate, that will be assigned during the expansion of the
1810 -----------------------
1811 -- Replace_Discr_Ref --
1812 -----------------------
1814 function Replace_Discr_Ref
(N
: Node_Id
) return Traverse_Result
is
1818 if Is_Entity_Name
(N
)
1819 and then Present
(Entity
(N
))
1820 and then Is_Formal
(Entity
(N
))
1821 and then Present
(Discriminal_Link
(Entity
(N
)))
1824 Make_Selected_Component
(Default_Loc
,
1825 Prefix
=> New_Copy_Tree
(Lhs
),
1828 (Discriminal_Link
(Entity
(N
)), Default_Loc
));
1830 if Present
(Val
) then
1831 Rewrite
(N
, New_Copy_Tree
(Val
));
1836 end Replace_Discr_Ref
;
1838 procedure Replace_Discriminant_References
is
1839 new Traverse_Proc
(Replace_Discr_Ref
);
1841 -- Start of processing for Build_Assignment
1845 Make_Selected_Component
(Default_Loc
,
1846 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1847 Selector_Name
=> New_Occurrence_Of
(Id
, Default_Loc
));
1848 Set_Assignment_OK
(Lhs
);
1850 if Nkind
(Exp
) = N_Aggregate
1851 and then Has_Discriminants
(Typ
)
1852 and then not Is_Constrained
(Base_Type
(Typ
))
1854 -- The aggregate may provide new values for the discriminants
1855 -- of the component, and other components may depend on those
1856 -- discriminants. Previous analysis of those expressions have
1857 -- replaced the discriminants by the formals of the initialization
1858 -- procedure for the type, but these are irrelevant in the
1859 -- enclosing initialization procedure: those discriminant
1860 -- references must be replaced by the values provided in the
1863 Replace_Discriminant_References
(Exp
);
1866 -- Case of an access attribute applied to the current instance.
1867 -- Replace the reference to the type by a reference to the actual
1868 -- object. (Note that this handles the case of the top level of
1869 -- the expression being given by such an attribute, but does not
1870 -- cover uses nested within an initial value expression. Nested
1871 -- uses are unlikely to occur in practice, but are theoretically
1872 -- possible.) It is not clear how to handle them without fully
1873 -- traversing the expression. ???
1875 if Kind
= N_Attribute_Reference
1876 and then Nam_In
(Attribute_Name
(Default
), Name_Unchecked_Access
,
1877 Name_Unrestricted_Access
)
1878 and then Is_Entity_Name
(Prefix
(Default
))
1879 and then Is_Type
(Entity
(Prefix
(Default
)))
1880 and then Entity
(Prefix
(Default
)) = Rec_Type
1883 Make_Attribute_Reference
(Default_Loc
,
1885 Make_Identifier
(Default_Loc
, Name_uInit
),
1886 Attribute_Name
=> Name_Unrestricted_Access
);
1889 -- Take a copy of Exp to ensure that later copies of this component
1890 -- declaration in derived types see the original tree, not a node
1891 -- rewritten during expansion of the init_proc. If the copy contains
1892 -- itypes, the scope of the new itypes is the init_proc being built.
1894 Exp
:= New_Copy_Tree
(Exp
, New_Scope
=> Proc_Id
);
1897 Make_Assignment_Statement
(Loc
,
1899 Expression
=> Exp
));
1901 Set_No_Ctrl_Actions
(First
(Res
));
1903 -- Adjust the tag if tagged (because of possible view conversions).
1904 -- Suppress the tag adjustment when not Tagged_Type_Expansion because
1905 -- tags are represented implicitly in objects.
1907 if Is_Tagged_Type
(Typ
) and then Tagged_Type_Expansion
then
1909 Make_Assignment_Statement
(Default_Loc
,
1911 Make_Selected_Component
(Default_Loc
,
1913 New_Copy_Tree
(Lhs
, New_Scope
=> Proc_Id
),
1916 (First_Tag_Component
(Typ
), Default_Loc
)),
1919 Unchecked_Convert_To
(RTE
(RE_Tag
),
1921 (Node
(First_Elmt
(Access_Disp_Table
(Underlying_Type
1926 -- Adjust the component if controlled except if it is an aggregate
1927 -- that will be expanded inline.
1929 if Kind
= N_Qualified_Expression
then
1930 Kind
:= Nkind
(Expression
(Default
));
1933 if Needs_Finalization
(Typ
)
1934 and then not (Nkind_In
(Kind
, N_Aggregate
, N_Extension_Aggregate
))
1935 and then not Is_Build_In_Place_Function_Call
(Exp
)
1939 (Obj_Ref
=> New_Copy_Tree
(Lhs
),
1942 -- Guard against a missing [Deep_]Adjust when the component type
1943 -- was not properly frozen.
1945 if Present
(Adj_Call
) then
1946 Append_To
(Res
, Adj_Call
);
1950 -- If a component type has a predicate, add check to the component
1951 -- assignment. Discriminants are handled at the point of the call,
1952 -- which provides for a better error message.
1954 if Comes_From_Source
(Exp
)
1955 and then Has_Predicates
(Typ
)
1956 and then not Predicate_Checks_Suppressed
(Empty
)
1957 and then not Predicates_Ignored
(Typ
)
1959 Append
(Make_Predicate_Check
(Typ
, Exp
), Res
);
1965 when RE_Not_Available
=>
1967 end Build_Assignment
;
1969 ------------------------------------
1970 -- Build_Discriminant_Assignments --
1971 ------------------------------------
1973 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
) is
1974 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Rec_Type
);
1979 if Has_Discriminants
(Rec_Type
)
1980 and then not Is_Unchecked_Union
(Rec_Type
)
1982 D
:= First_Discriminant
(Rec_Type
);
1983 while Present
(D
) loop
1985 -- Don't generate the assignment for discriminants in derived
1986 -- tagged types if the discriminant is a renaming of some
1987 -- ancestor discriminant. This initialization will be done
1988 -- when initializing the _parent field of the derived record.
1991 and then Present
(Corresponding_Discriminant
(D
))
1997 Append_List_To
(Statement_List
,
1998 Build_Assignment
(D
,
1999 New_Occurrence_Of
(Discriminal
(D
), D_Loc
)));
2002 Next_Discriminant
(D
);
2005 end Build_Discriminant_Assignments
;
2007 --------------------------
2008 -- Build_Init_Call_Thru --
2009 --------------------------
2011 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
is
2012 Parent_Proc
: constant Entity_Id
:=
2013 Base_Init_Proc
(Etype
(Rec_Type
));
2015 Parent_Type
: constant Entity_Id
:=
2016 Etype
(First_Formal
(Parent_Proc
));
2018 Uparent_Type
: constant Entity_Id
:=
2019 Underlying_Type
(Parent_Type
);
2021 First_Discr_Param
: Node_Id
;
2025 First_Arg
: Node_Id
;
2026 Parent_Discr
: Entity_Id
;
2030 -- First argument (_Init) is the object to be initialized.
2031 -- ??? not sure where to get a reasonable Loc for First_Arg
2034 OK_Convert_To
(Parent_Type
,
2036 (Defining_Identifier
(First
(Parameters
)), Loc
));
2038 Set_Etype
(First_Arg
, Parent_Type
);
2040 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Rec_Type
));
2042 -- In the tasks case,
2043 -- add _Master as the value of the _Master parameter
2044 -- add _Chain as the value of the _Chain parameter.
2045 -- add _Task_Name as the value of the _Task_Name parameter.
2046 -- At the outer level, these will be variables holding the
2047 -- corresponding values obtained from GNARL or the expander.
2049 -- At inner levels, they will be the parameters passed down through
2050 -- the outer routines.
2052 First_Discr_Param
:= Next
(First
(Parameters
));
2054 if Has_Task
(Rec_Type
) then
2055 if Restriction_Active
(No_Task_Hierarchy
) then
2057 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
2059 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
2062 -- Add _Chain (not done for sequential elaboration policy, see
2063 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
2065 if Partition_Elaboration_Policy
/= 'S' then
2066 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
2069 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
2070 First_Discr_Param
:= Next
(Next
(Next
(First_Discr_Param
)));
2073 -- Append discriminant values
2075 if Has_Discriminants
(Uparent_Type
) then
2076 pragma Assert
(not Is_Tagged_Type
(Uparent_Type
));
2078 Parent_Discr
:= First_Discriminant
(Uparent_Type
);
2079 while Present
(Parent_Discr
) loop
2081 -- Get the initial value for this discriminant
2082 -- ??? needs to be cleaned up to use parent_Discr_Constr
2086 Discr
: Entity_Id
:=
2087 First_Stored_Discriminant
(Uparent_Type
);
2089 Discr_Value
: Elmt_Id
:=
2090 First_Elmt
(Stored_Constraint
(Rec_Type
));
2093 while Original_Record_Component
(Parent_Discr
) /= Discr
loop
2094 Next_Stored_Discriminant
(Discr
);
2095 Next_Elmt
(Discr_Value
);
2098 Arg
:= Node
(Discr_Value
);
2101 -- Append it to the list
2103 if Nkind
(Arg
) = N_Identifier
2104 and then Ekind
(Entity
(Arg
)) = E_Discriminant
2107 New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
));
2109 -- Case of access discriminants. We replace the reference
2110 -- to the type by a reference to the actual object.
2112 -- Is above comment right??? Use of New_Copy below seems mighty
2116 Append_To
(Args
, New_Copy
(Arg
));
2119 Next_Discriminant
(Parent_Discr
);
2125 Make_Procedure_Call_Statement
(Loc
,
2127 New_Occurrence_Of
(Parent_Proc
, Loc
),
2128 Parameter_Associations
=> Args
));
2131 end Build_Init_Call_Thru
;
2133 -----------------------------------
2134 -- Build_Offset_To_Top_Functions --
2135 -----------------------------------
2137 procedure Build_Offset_To_Top_Functions
is
2139 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
);
2141 -- function Fxx (O : Address) return Storage_Offset is
2142 -- type Acc is access all <Typ>;
2144 -- return Acc!(O).Iface_Comp'Position;
2147 ----------------------------------
2148 -- Build_Offset_To_Top_Function --
2149 ----------------------------------
2151 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
) is
2152 Body_Node
: Node_Id
;
2153 Func_Id
: Entity_Id
;
2154 Spec_Node
: Node_Id
;
2155 Acc_Type
: Entity_Id
;
2158 Func_Id
:= Make_Temporary
(Loc
, 'F');
2159 Set_DT_Offset_To_Top_Func
(Iface_Comp
, Func_Id
);
2162 -- function Fxx (O : in Rec_Typ) return Storage_Offset;
2164 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
2165 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
2166 Set_Parameter_Specifications
(Spec_Node
, New_List
(
2167 Make_Parameter_Specification
(Loc
,
2168 Defining_Identifier
=>
2169 Make_Defining_Identifier
(Loc
, Name_uO
),
2172 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))));
2173 Set_Result_Definition
(Spec_Node
,
2174 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
2177 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2179 -- return -O.Iface_Comp'Position;
2182 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2183 Set_Specification
(Body_Node
, Spec_Node
);
2185 Acc_Type
:= Make_Temporary
(Loc
, 'T');
2186 Set_Declarations
(Body_Node
, New_List
(
2187 Make_Full_Type_Declaration
(Loc
,
2188 Defining_Identifier
=> Acc_Type
,
2190 Make_Access_To_Object_Definition
(Loc
,
2191 All_Present
=> True,
2192 Null_Exclusion_Present
=> False,
2193 Constant_Present
=> False,
2194 Subtype_Indication
=>
2195 New_Occurrence_Of
(Rec_Type
, Loc
)))));
2197 Set_Handled_Statement_Sequence
(Body_Node
,
2198 Make_Handled_Sequence_Of_Statements
(Loc
,
2199 Statements
=> New_List
(
2200 Make_Simple_Return_Statement
(Loc
,
2203 Make_Attribute_Reference
(Loc
,
2205 Make_Selected_Component
(Loc
,
2207 Unchecked_Convert_To
(Acc_Type
,
2208 Make_Identifier
(Loc
, Name_uO
)),
2210 New_Occurrence_Of
(Iface_Comp
, Loc
)),
2211 Attribute_Name
=> Name_Position
))))));
2213 Set_Ekind
(Func_Id
, E_Function
);
2214 Set_Mechanism
(Func_Id
, Default_Mechanism
);
2215 Set_Is_Internal
(Func_Id
, True);
2217 if not Debug_Generated_Code
then
2218 Set_Debug_Info_Off
(Func_Id
);
2221 Analyze
(Body_Node
);
2223 Append_Freeze_Action
(Rec_Type
, Body_Node
);
2224 end Build_Offset_To_Top_Function
;
2228 Iface_Comp
: Node_Id
;
2229 Iface_Comp_Elmt
: Elmt_Id
;
2230 Ifaces_Comp_List
: Elist_Id
;
2232 -- Start of processing for Build_Offset_To_Top_Functions
2235 -- Offset_To_Top_Functions are built only for derivations of types
2236 -- with discriminants that cover interface types.
2237 -- Nothing is needed either in case of virtual targets, since
2238 -- interfaces are handled directly by the target.
2240 if not Is_Tagged_Type
(Rec_Type
)
2241 or else Etype
(Rec_Type
) = Rec_Type
2242 or else not Has_Discriminants
(Etype
(Rec_Type
))
2243 or else not Tagged_Type_Expansion
2248 Collect_Interface_Components
(Rec_Type
, Ifaces_Comp_List
);
2250 -- For each interface type with secondary dispatch table we generate
2251 -- the Offset_To_Top_Functions (required to displace the pointer in
2252 -- interface conversions)
2254 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
2255 while Present
(Iface_Comp_Elmt
) loop
2256 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
2257 pragma Assert
(Is_Interface
(Related_Type
(Iface_Comp
)));
2259 -- If the interface is a parent of Rec_Type it shares the primary
2260 -- dispatch table and hence there is no need to build the function
2262 if not Is_Ancestor
(Related_Type
(Iface_Comp
), Rec_Type
,
2263 Use_Full_View
=> True)
2265 Build_Offset_To_Top_Function
(Iface_Comp
);
2268 Next_Elmt
(Iface_Comp_Elmt
);
2270 end Build_Offset_To_Top_Functions
;
2272 ------------------------------
2273 -- Build_CPP_Init_Procedure --
2274 ------------------------------
2276 procedure Build_CPP_Init_Procedure
is
2277 Body_Node
: Node_Id
;
2278 Body_Stmts
: List_Id
;
2279 Flag_Id
: Entity_Id
;
2280 Handled_Stmt_Node
: Node_Id
;
2281 Init_Tags_List
: List_Id
;
2282 Proc_Id
: Entity_Id
;
2283 Proc_Spec_Node
: Node_Id
;
2286 -- Check cases requiring no IC routine
2288 if not Is_CPP_Class
(Root_Type
(Rec_Type
))
2289 or else Is_CPP_Class
(Rec_Type
)
2290 or else CPP_Num_Prims
(Rec_Type
) = 0
2291 or else not Tagged_Type_Expansion
2292 or else No_Run_Time_Mode
2299 -- Flag : Boolean := False;
2301 -- procedure Typ_IC is
2304 -- Copy C++ dispatch table slots from parent
2305 -- Update C++ slots of overridden primitives
2309 Flag_Id
:= Make_Temporary
(Loc
, 'F');
2311 Append_Freeze_Action
(Rec_Type
,
2312 Make_Object_Declaration
(Loc
,
2313 Defining_Identifier
=> Flag_Id
,
2314 Object_Definition
=>
2315 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2317 New_Occurrence_Of
(Standard_True
, Loc
)));
2319 Body_Stmts
:= New_List
;
2320 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2322 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2325 Make_Defining_Identifier
(Loc
,
2326 Chars
=> Make_TSS_Name
(Rec_Type
, TSS_CPP_Init_Proc
));
2328 Set_Ekind
(Proc_Id
, E_Procedure
);
2329 Set_Is_Internal
(Proc_Id
);
2331 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2333 Set_Parameter_Specifications
(Proc_Spec_Node
, New_List
);
2334 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2335 Set_Declarations
(Body_Node
, New_List
);
2337 Init_Tags_List
:= Build_Inherit_CPP_Prims
(Rec_Type
);
2339 Append_To
(Init_Tags_List
,
2340 Make_Assignment_Statement
(Loc
,
2342 New_Occurrence_Of
(Flag_Id
, Loc
),
2344 New_Occurrence_Of
(Standard_False
, Loc
)));
2346 Append_To
(Body_Stmts
,
2347 Make_If_Statement
(Loc
,
2348 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
2349 Then_Statements
=> Init_Tags_List
));
2351 Handled_Stmt_Node
:=
2352 New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2353 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2354 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2355 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2357 if not Debug_Generated_Code
then
2358 Set_Debug_Info_Off
(Proc_Id
);
2361 -- Associate CPP_Init_Proc with type
2363 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2364 end Build_CPP_Init_Procedure
;
2366 --------------------------
2367 -- Build_Init_Procedure --
2368 --------------------------
2370 procedure Build_Init_Procedure
is
2371 Body_Stmts
: List_Id
;
2372 Body_Node
: Node_Id
;
2373 Handled_Stmt_Node
: Node_Id
;
2374 Init_Tags_List
: List_Id
;
2375 Parameters
: List_Id
;
2376 Proc_Spec_Node
: Node_Id
;
2377 Record_Extension_Node
: Node_Id
;
2380 Body_Stmts
:= New_List
;
2381 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2382 Set_Ekind
(Proc_Id
, E_Procedure
);
2384 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2385 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2387 Parameters
:= Init_Formals
(Rec_Type
);
2388 Append_List_To
(Parameters
,
2389 Build_Discriminant_Formals
(Rec_Type
, True));
2391 -- For tagged types, we add a flag to indicate whether the routine
2392 -- is called to initialize a parent component in the init_proc of
2393 -- a type extension. If the flag is false, we do not set the tag
2394 -- because it has been set already in the extension.
2396 if Is_Tagged_Type
(Rec_Type
) then
2397 Set_Tag
:= Make_Temporary
(Loc
, 'P');
2399 Append_To
(Parameters
,
2400 Make_Parameter_Specification
(Loc
,
2401 Defining_Identifier
=> Set_Tag
,
2403 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2405 New_Occurrence_Of
(Standard_True
, Loc
)));
2408 Set_Parameter_Specifications
(Proc_Spec_Node
, Parameters
);
2409 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2410 Set_Declarations
(Body_Node
, Decls
);
2412 -- N is a Derived_Type_Definition that renames the parameters of the
2413 -- ancestor type. We initialize it by expanding our discriminants and
2414 -- call the ancestor _init_proc with a type-converted object.
2416 if Parent_Subtype_Renaming_Discrims
then
2417 Append_List_To
(Body_Stmts
, Build_Init_Call_Thru
(Parameters
));
2419 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
2420 Build_Discriminant_Assignments
(Body_Stmts
);
2422 if not Null_Present
(Type_Definition
(N
)) then
2423 Append_List_To
(Body_Stmts
,
2424 Build_Init_Statements
(Component_List
(Type_Definition
(N
))));
2427 -- N is a Derived_Type_Definition with a possible non-empty
2428 -- extension. The initialization of a type extension consists in the
2429 -- initialization of the components in the extension.
2432 Build_Discriminant_Assignments
(Body_Stmts
);
2434 Record_Extension_Node
:=
2435 Record_Extension_Part
(Type_Definition
(N
));
2437 if not Null_Present
(Record_Extension_Node
) then
2439 Stmts
: constant List_Id
:=
2440 Build_Init_Statements
(
2441 Component_List
(Record_Extension_Node
));
2444 -- The parent field must be initialized first because the
2445 -- offset of the new discriminants may depend on it. This is
2446 -- not needed if the parent is an interface type because in
2447 -- such case the initialization of the _parent field was not
2450 if not Is_Interface
(Etype
(Rec_Ent
)) then
2452 Parent_IP
: constant Name_Id
:=
2453 Make_Init_Proc_Name
(Etype
(Rec_Ent
));
2459 -- Look for a call to the parent IP at the beginning
2460 -- of Stmts associated with the record extension
2462 Stmt
:= First
(Stmts
);
2464 while Present
(Stmt
) loop
2465 if Nkind
(Stmt
) = N_Procedure_Call_Statement
2466 and then Chars
(Name
(Stmt
)) = Parent_IP
2475 -- If found then move it to the beginning of the
2476 -- statements of this IP routine
2478 if Present
(IP_Call
) then
2479 IP_Stmts
:= New_List
;
2481 Stmt
:= Remove_Head
(Stmts
);
2482 Append_To
(IP_Stmts
, Stmt
);
2483 exit when Stmt
= IP_Call
;
2486 Prepend_List_To
(Body_Stmts
, IP_Stmts
);
2491 Append_List_To
(Body_Stmts
, Stmts
);
2496 -- Add here the assignment to instantiate the Tag
2498 -- The assignment corresponds to the code:
2500 -- _Init._Tag := Typ'Tag;
2502 -- Suppress the tag assignment when not Tagged_Type_Expansion because
2503 -- tags are represented implicitly in objects. It is also suppressed
2504 -- in case of CPP_Class types because in this case the tag is
2505 -- initialized in the C++ side.
2507 if Is_Tagged_Type
(Rec_Type
)
2508 and then Tagged_Type_Expansion
2509 and then not No_Run_Time_Mode
2511 -- Case 1: Ada tagged types with no CPP ancestor. Set the tags of
2512 -- the actual object and invoke the IP of the parent (in this
2513 -- order). The tag must be initialized before the call to the IP
2514 -- of the parent and the assignments to other components because
2515 -- the initial value of the components may depend on the tag (eg.
2516 -- through a dispatching operation on an access to the current
2517 -- type). The tag assignment is not done when initializing the
2518 -- parent component of a type extension, because in that case the
2519 -- tag is set in the extension.
2521 if not Is_CPP_Class
(Root_Type
(Rec_Type
)) then
2523 -- Initialize the primary tag component
2525 Init_Tags_List
:= New_List
(
2526 Make_Assignment_Statement
(Loc
,
2528 Make_Selected_Component
(Loc
,
2529 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2532 (First_Tag_Component
(Rec_Type
), Loc
)),
2536 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2538 -- Ada 2005 (AI-251): Initialize the secondary tags components
2539 -- located at fixed positions (tags whose position depends on
2540 -- variable size components are initialized later ---see below)
2542 if Ada_Version
>= Ada_2005
2543 and then not Is_Interface
(Rec_Type
)
2544 and then Has_Interfaces
(Rec_Type
)
2547 Elab_Sec_DT_Stmts_List
: constant List_Id
:= New_List
;
2548 Elab_List
: List_Id
:= New_List
;
2553 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2554 Init_Tags_List
=> Init_Tags_List
,
2555 Stmts_List
=> Elab_Sec_DT_Stmts_List
,
2556 Fixed_Comps
=> True,
2557 Variable_Comps
=> False);
2559 Elab_List
:= New_List
(
2560 Make_If_Statement
(Loc
,
2561 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2562 Then_Statements
=> Init_Tags_List
));
2564 if Elab_Flag_Needed
(Rec_Type
) then
2565 Append_To
(Elab_Sec_DT_Stmts_List
,
2566 Make_Assignment_Statement
(Loc
,
2569 (Access_Disp_Table_Elab_Flag
(Rec_Type
),
2572 New_Occurrence_Of
(Standard_False
, Loc
)));
2574 Append_To
(Elab_List
,
2575 Make_If_Statement
(Loc
,
2578 (Access_Disp_Table_Elab_Flag
(Rec_Type
), Loc
),
2579 Then_Statements
=> Elab_Sec_DT_Stmts_List
));
2582 Prepend_List_To
(Body_Stmts
, Elab_List
);
2585 Prepend_To
(Body_Stmts
,
2586 Make_If_Statement
(Loc
,
2587 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2588 Then_Statements
=> Init_Tags_List
));
2591 -- Case 2: CPP type. The imported C++ constructor takes care of
2592 -- tags initialization. No action needed here because the IP
2593 -- is built by Set_CPP_Constructors; in this case the IP is a
2594 -- wrapper that invokes the C++ constructor and copies the C++
2595 -- tags locally. Done to inherit the C++ slots in Ada derivations
2598 elsif Is_CPP_Class
(Rec_Type
) then
2599 pragma Assert
(False);
2602 -- Case 3: Combined hierarchy containing C++ types and Ada tagged
2603 -- type derivations. Derivations of imported C++ classes add a
2604 -- complication, because we cannot inhibit tag setting in the
2605 -- constructor for the parent. Hence we initialize the tag after
2606 -- the call to the parent IP (that is, in reverse order compared
2607 -- with pure Ada hierarchies ---see comment on case 1).
2610 -- Initialize the primary tag
2612 Init_Tags_List
:= New_List
(
2613 Make_Assignment_Statement
(Loc
,
2615 Make_Selected_Component
(Loc
,
2616 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2619 (First_Tag_Component
(Rec_Type
), Loc
)),
2623 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2625 -- Ada 2005 (AI-251): Initialize the secondary tags components
2626 -- located at fixed positions (tags whose position depends on
2627 -- variable size components are initialized later ---see below)
2629 if Ada_Version
>= Ada_2005
2630 and then not Is_Interface
(Rec_Type
)
2631 and then Has_Interfaces
(Rec_Type
)
2635 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2636 Init_Tags_List
=> Init_Tags_List
,
2637 Stmts_List
=> Init_Tags_List
,
2638 Fixed_Comps
=> True,
2639 Variable_Comps
=> False);
2642 -- Initialize the tag component after invocation of parent IP.
2645 -- parent_IP(_init.parent); // Invokes the C++ constructor
2646 -- [ typIC; ] // Inherit C++ slots from parent
2653 -- Search for the call to the IP of the parent. We assume
2654 -- that the first init_proc call is for the parent.
2656 Ins_Nod
:= First
(Body_Stmts
);
2657 while Present
(Next
(Ins_Nod
))
2658 and then (Nkind
(Ins_Nod
) /= N_Procedure_Call_Statement
2659 or else not Is_Init_Proc
(Name
(Ins_Nod
)))
2664 -- The IC routine copies the inherited slots of the C+ part
2665 -- of the dispatch table from the parent and updates the
2666 -- overridden C++ slots.
2668 if CPP_Num_Prims
(Rec_Type
) > 0 then
2670 Init_DT
: Entity_Id
;
2674 Init_DT
:= CPP_Init_Proc
(Rec_Type
);
2675 pragma Assert
(Present
(Init_DT
));
2678 Make_Procedure_Call_Statement
(Loc
,
2679 New_Occurrence_Of
(Init_DT
, Loc
));
2680 Insert_After
(Ins_Nod
, New_Nod
);
2682 -- Update location of init tag statements
2688 Insert_List_After
(Ins_Nod
, Init_Tags_List
);
2692 -- Ada 2005 (AI-251): Initialize the secondary tag components
2693 -- located at variable positions. We delay the generation of this
2694 -- code until here because the value of the attribute 'Position
2695 -- applied to variable size components of the parent type that
2696 -- depend on discriminants is only safely read at runtime after
2697 -- the parent components have been initialized.
2699 if Ada_Version
>= Ada_2005
2700 and then not Is_Interface
(Rec_Type
)
2701 and then Has_Interfaces
(Rec_Type
)
2702 and then Has_Discriminants
(Etype
(Rec_Type
))
2703 and then Is_Variable_Size_Record
(Etype
(Rec_Type
))
2705 Init_Tags_List
:= New_List
;
2709 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2710 Init_Tags_List
=> Init_Tags_List
,
2711 Stmts_List
=> Init_Tags_List
,
2712 Fixed_Comps
=> False,
2713 Variable_Comps
=> True);
2715 if Is_Non_Empty_List
(Init_Tags_List
) then
2716 Append_List_To
(Body_Stmts
, Init_Tags_List
);
2721 Handled_Stmt_Node
:= New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2722 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2725 -- Deep_Finalize (_init, C1, ..., CN);
2729 and then Needs_Finalization
(Rec_Type
)
2730 and then not Is_Abstract_Type
(Rec_Type
)
2731 and then not Restriction_Active
(No_Exception_Propagation
)
2737 -- Create a local version of Deep_Finalize which has indication
2738 -- of partial initialization state.
2741 Make_Defining_Identifier
(Loc
,
2742 Chars
=> New_External_Name
(Name_uFinalizer
));
2744 Append_To
(Decls
, Make_Local_Deep_Finalize
(Rec_Type
, DF_Id
));
2746 Set_Exception_Handlers
(Handled_Stmt_Node
, New_List
(
2747 Make_Exception_Handler
(Loc
,
2748 Exception_Choices
=> New_List
(
2749 Make_Others_Choice
(Loc
)),
2750 Statements
=> New_List
(
2751 Make_Procedure_Call_Statement
(Loc
,
2753 New_Occurrence_Of
(DF_Id
, Loc
),
2754 Parameter_Associations
=> New_List
(
2755 Make_Identifier
(Loc
, Name_uInit
),
2756 New_Occurrence_Of
(Standard_False
, Loc
))),
2758 Make_Raise_Statement
(Loc
)))));
2761 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2764 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2766 if not Debug_Generated_Code
then
2767 Set_Debug_Info_Off
(Proc_Id
);
2770 -- Associate Init_Proc with type, and determine if the procedure
2771 -- is null (happens because of the Initialize_Scalars pragma case,
2772 -- where we have to generate a null procedure in case it is called
2773 -- by a client with Initialize_Scalars set). Such procedures have
2774 -- to be generated, but do not have to be called, so we mark them
2775 -- as null to suppress the call.
2777 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2779 if List_Length
(Body_Stmts
) = 1
2781 -- We must skip SCIL nodes because they may have been added to this
2782 -- list by Insert_Actions.
2784 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
2786 Set_Is_Null_Init_Proc
(Proc_Id
);
2788 end Build_Init_Procedure
;
2790 ---------------------------
2791 -- Build_Init_Statements --
2792 ---------------------------
2794 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
is
2795 Checks
: constant List_Id
:= New_List
;
2796 Actions
: List_Id
:= No_List
;
2797 Counter_Id
: Entity_Id
:= Empty
;
2798 Comp_Loc
: Source_Ptr
;
2802 Parent_Stmts
: List_Id
;
2806 procedure Increment_Counter
(Loc
: Source_Ptr
);
2807 -- Generate an "increment by one" statement for the current counter
2808 -- and append it to the list Stmts.
2810 procedure Make_Counter
(Loc
: Source_Ptr
);
2811 -- Create a new counter for the current component list. The routine
2812 -- creates a new defining Id, adds an object declaration and sets
2813 -- the Id generator for the next variant.
2815 -----------------------
2816 -- Increment_Counter --
2817 -----------------------
2819 procedure Increment_Counter
(Loc
: Source_Ptr
) is
2822 -- Counter := Counter + 1;
2825 Make_Assignment_Statement
(Loc
,
2826 Name
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2829 Left_Opnd
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2830 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
2831 end Increment_Counter
;
2837 procedure Make_Counter
(Loc
: Source_Ptr
) is
2839 -- Increment the Id generator
2841 Counter
:= Counter
+ 1;
2843 -- Create the entity and declaration
2846 Make_Defining_Identifier
(Loc
,
2847 Chars
=> New_External_Name
('C', Counter
));
2850 -- Cnn : Integer := 0;
2853 Make_Object_Declaration
(Loc
,
2854 Defining_Identifier
=> Counter_Id
,
2855 Object_Definition
=>
2856 New_Occurrence_Of
(Standard_Integer
, Loc
),
2858 Make_Integer_Literal
(Loc
, 0)));
2861 -- Start of processing for Build_Init_Statements
2864 if Null_Present
(Comp_List
) then
2865 return New_List
(Make_Null_Statement
(Loc
));
2868 Parent_Stmts
:= New_List
;
2871 -- Loop through visible declarations of task types and protected
2872 -- types moving any expanded code from the spec to the body of the
2875 if Is_Task_Record_Type
(Rec_Type
)
2876 or else Is_Protected_Record_Type
(Rec_Type
)
2879 Decl
: constant Node_Id
:=
2880 Parent
(Corresponding_Concurrent_Type
(Rec_Type
));
2886 if Is_Task_Record_Type
(Rec_Type
) then
2887 Def
:= Task_Definition
(Decl
);
2889 Def
:= Protected_Definition
(Decl
);
2892 if Present
(Def
) then
2893 N1
:= First
(Visible_Declarations
(Def
));
2894 while Present
(N1
) loop
2898 if Nkind
(N2
) in N_Statement_Other_Than_Procedure_Call
2899 or else Nkind
(N2
) in N_Raise_xxx_Error
2900 or else Nkind
(N2
) = N_Procedure_Call_Statement
2903 New_Copy_Tree
(N2
, New_Scope
=> Proc_Id
));
2904 Rewrite
(N2
, Make_Null_Statement
(Sloc
(N2
)));
2912 -- Loop through components, skipping pragmas, in 2 steps. The first
2913 -- step deals with regular components. The second step deals with
2914 -- components that have per object constraints and no explicit
2919 -- First pass : regular components
2921 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
2922 while Present
(Decl
) loop
2923 Comp_Loc
:= Sloc
(Decl
);
2925 (Subtype_Indication
(Component_Definition
(Decl
)), Checks
);
2927 Id
:= Defining_Identifier
(Decl
);
2930 -- Leave any processing of per-object constrained component for
2933 if Has_Access_Constraint
(Id
) and then No
(Expression
(Decl
)) then
2936 -- Regular component cases
2939 -- In the context of the init proc, references to discriminants
2940 -- resolve to denote the discriminals: this is where we can
2941 -- freeze discriminant dependent component subtypes.
2943 if not Is_Frozen
(Typ
) then
2944 Append_List_To
(Stmts
, Freeze_Entity
(Typ
, N
));
2947 -- Explicit initialization
2949 if Present
(Expression
(Decl
)) then
2950 if Is_CPP_Constructor_Call
(Expression
(Decl
)) then
2952 Build_Initialization_Call
2955 Make_Selected_Component
(Comp_Loc
,
2957 Make_Identifier
(Comp_Loc
, Name_uInit
),
2959 New_Occurrence_Of
(Id
, Comp_Loc
)),
2961 In_Init_Proc
=> True,
2962 Enclos_Type
=> Rec_Type
,
2963 Discr_Map
=> Discr_Map
,
2964 Constructor_Ref
=> Expression
(Decl
));
2966 Actions
:= Build_Assignment
(Id
, Expression
(Decl
));
2969 -- CPU, Dispatching_Domain, Priority, and Secondary_Stack_Size
2970 -- components are filled in with the corresponding rep-item
2971 -- expression of the concurrent type (if any).
2973 elsif Ekind
(Scope
(Id
)) = E_Record_Type
2974 and then Present
(Corresponding_Concurrent_Type
(Scope
(Id
)))
2975 and then Nam_In
(Chars
(Id
), Name_uCPU
,
2976 Name_uDispatching_Domain
,
2978 Name_uSecondary_Stack_Size
)
2983 pragma Warnings
(Off
, Nam
);
2987 if Chars
(Id
) = Name_uCPU
then
2990 elsif Chars
(Id
) = Name_uDispatching_Domain
then
2991 Nam
:= Name_Dispatching_Domain
;
2993 elsif Chars
(Id
) = Name_uPriority
then
2994 Nam
:= Name_Priority
;
2996 elsif Chars
(Id
) = Name_uSecondary_Stack_Size
then
2997 Nam
:= Name_Secondary_Stack_Size
;
3000 -- Get the Rep Item (aspect specification, attribute
3001 -- definition clause or pragma) of the corresponding
3006 (Corresponding_Concurrent_Type
(Scope
(Id
)),
3008 Check_Parents
=> False);
3010 if Present
(Ritem
) then
3014 if Nkind
(Ritem
) = N_Pragma
then
3015 Exp
:= First
(Pragma_Argument_Associations
(Ritem
));
3017 if Nkind
(Exp
) = N_Pragma_Argument_Association
then
3018 Exp
:= Expression
(Exp
);
3021 -- Conversion for Priority expression
3023 if Nam
= Name_Priority
then
3024 if Pragma_Name
(Ritem
) = Name_Priority
3025 and then not GNAT_Mode
3027 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
3030 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
3034 -- Aspect/Attribute definition clause case
3037 Exp
:= Expression
(Ritem
);
3039 -- Conversion for Priority expression
3041 if Nam
= Name_Priority
then
3042 if Chars
(Ritem
) = Name_Priority
3043 and then not GNAT_Mode
3045 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
3048 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
3053 -- Conversion for Dispatching_Domain value
3055 if Nam
= Name_Dispatching_Domain
then
3057 Unchecked_Convert_To
3058 (RTE
(RE_Dispatching_Domain_Access
), Exp
);
3060 -- Conversion for Secondary_Stack_Size value
3062 elsif Nam
= Name_Secondary_Stack_Size
then
3063 Exp
:= Convert_To
(RTE
(RE_Size_Type
), Exp
);
3066 Actions
:= Build_Assignment
(Id
, Exp
);
3068 -- Nothing needed if no Rep Item
3075 -- Composite component with its own Init_Proc
3077 elsif not Is_Interface
(Typ
)
3078 and then Has_Non_Null_Base_Init_Proc
(Typ
)
3081 Build_Initialization_Call
3083 Make_Selected_Component
(Comp_Loc
,
3085 Make_Identifier
(Comp_Loc
, Name_uInit
),
3086 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3088 In_Init_Proc
=> True,
3089 Enclos_Type
=> Rec_Type
,
3090 Discr_Map
=> Discr_Map
);
3092 Clean_Task_Names
(Typ
, Proc_Id
);
3094 -- Simple initialization
3096 elsif Component_Needs_Simple_Initialization
(Typ
) then
3099 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
)));
3101 -- Nothing needed for this case
3107 if Present
(Checks
) then
3108 if Chars
(Id
) = Name_uParent
then
3109 Append_List_To
(Parent_Stmts
, Checks
);
3111 Append_List_To
(Stmts
, Checks
);
3115 if Present
(Actions
) then
3116 if Chars
(Id
) = Name_uParent
then
3117 Append_List_To
(Parent_Stmts
, Actions
);
3120 Append_List_To
(Stmts
, Actions
);
3122 -- Preserve initialization state in the current counter
3124 if Needs_Finalization
(Typ
) then
3125 if No
(Counter_Id
) then
3126 Make_Counter
(Comp_Loc
);
3129 Increment_Counter
(Comp_Loc
);
3135 Next_Non_Pragma
(Decl
);
3138 -- The parent field must be initialized first because variable
3139 -- size components of the parent affect the location of all the
3142 Prepend_List_To
(Stmts
, Parent_Stmts
);
3144 -- Set up tasks and protected object support. This needs to be done
3145 -- before any component with a per-object access discriminant
3146 -- constraint, or any variant part (which may contain such
3147 -- components) is initialized, because the initialization of these
3148 -- components may reference the enclosing concurrent object.
3150 -- For a task record type, add the task create call and calls to bind
3151 -- any interrupt (signal) entries.
3153 if Is_Task_Record_Type
(Rec_Type
) then
3155 -- In the case of the restricted run time the ATCB has already
3156 -- been preallocated.
3158 if Restricted_Profile
then
3160 Make_Assignment_Statement
(Loc
,
3162 Make_Selected_Component
(Loc
,
3163 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3164 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3166 Make_Attribute_Reference
(Loc
,
3168 Make_Selected_Component
(Loc
,
3169 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3170 Selector_Name
=> Make_Identifier
(Loc
, Name_uATCB
)),
3171 Attribute_Name
=> Name_Unchecked_Access
)));
3174 Append_To
(Stmts
, Make_Task_Create_Call
(Rec_Type
));
3177 Task_Type
: constant Entity_Id
:=
3178 Corresponding_Concurrent_Type
(Rec_Type
);
3179 Task_Decl
: constant Node_Id
:= Parent
(Task_Type
);
3180 Task_Def
: constant Node_Id
:= Task_Definition
(Task_Decl
);
3181 Decl_Loc
: Source_Ptr
;
3186 if Present
(Task_Def
) then
3187 Vis_Decl
:= First
(Visible_Declarations
(Task_Def
));
3188 while Present
(Vis_Decl
) loop
3189 Decl_Loc
:= Sloc
(Vis_Decl
);
3191 if Nkind
(Vis_Decl
) = N_Attribute_Definition_Clause
then
3192 if Get_Attribute_Id
(Chars
(Vis_Decl
)) =
3195 Ent
:= Entity
(Name
(Vis_Decl
));
3197 if Ekind
(Ent
) = E_Entry
then
3199 Make_Procedure_Call_Statement
(Decl_Loc
,
3201 New_Occurrence_Of
(RTE
(
3202 RE_Bind_Interrupt_To_Entry
), Decl_Loc
),
3203 Parameter_Associations
=> New_List
(
3204 Make_Selected_Component
(Decl_Loc
,
3206 Make_Identifier
(Decl_Loc
, Name_uInit
),
3209 (Decl_Loc
, Name_uTask_Id
)),
3210 Entry_Index_Expression
3211 (Decl_Loc
, Ent
, Empty
, Task_Type
),
3212 Expression
(Vis_Decl
))));
3223 -- For a protected type, add statements generated by
3224 -- Make_Initialize_Protection.
3226 if Is_Protected_Record_Type
(Rec_Type
) then
3227 Append_List_To
(Stmts
,
3228 Make_Initialize_Protection
(Rec_Type
));
3231 -- Second pass: components with per-object constraints
3234 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3235 while Present
(Decl
) loop
3236 Comp_Loc
:= Sloc
(Decl
);
3237 Id
:= Defining_Identifier
(Decl
);
3240 if Has_Access_Constraint
(Id
)
3241 and then No
(Expression
(Decl
))
3243 if Has_Non_Null_Base_Init_Proc
(Typ
) then
3244 Append_List_To
(Stmts
,
3245 Build_Initialization_Call
(Comp_Loc
,
3246 Make_Selected_Component
(Comp_Loc
,
3248 Make_Identifier
(Comp_Loc
, Name_uInit
),
3249 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3251 In_Init_Proc
=> True,
3252 Enclos_Type
=> Rec_Type
,
3253 Discr_Map
=> Discr_Map
));
3255 Clean_Task_Names
(Typ
, Proc_Id
);
3257 -- Preserve initialization state in the current counter
3259 if Needs_Finalization
(Typ
) then
3260 if No
(Counter_Id
) then
3261 Make_Counter
(Comp_Loc
);
3264 Increment_Counter
(Comp_Loc
);
3267 elsif Component_Needs_Simple_Initialization
(Typ
) then
3268 Append_List_To
(Stmts
,
3270 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
))));
3274 Next_Non_Pragma
(Decl
);
3278 -- Process the variant part
3280 if Present
(Variant_Part
(Comp_List
)) then
3282 Variant_Alts
: constant List_Id
:= New_List
;
3283 Var_Loc
: Source_Ptr
:= No_Location
;
3288 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3289 while Present
(Variant
) loop
3290 Var_Loc
:= Sloc
(Variant
);
3291 Append_To
(Variant_Alts
,
3292 Make_Case_Statement_Alternative
(Var_Loc
,
3294 New_Copy_List
(Discrete_Choices
(Variant
)),
3296 Build_Init_Statements
(Component_List
(Variant
))));
3297 Next_Non_Pragma
(Variant
);
3300 -- The expression of the case statement which is a reference
3301 -- to one of the discriminants is replaced by the appropriate
3302 -- formal parameter of the initialization procedure.
3305 Make_Case_Statement
(Var_Loc
,
3307 New_Occurrence_Of
(Discriminal
(
3308 Entity
(Name
(Variant_Part
(Comp_List
)))), Var_Loc
),
3309 Alternatives
=> Variant_Alts
));
3313 -- If no initializations when generated for component declarations
3314 -- corresponding to this Stmts, append a null statement to Stmts to
3315 -- to make it a valid Ada tree.
3317 if Is_Empty_List
(Stmts
) then
3318 Append
(Make_Null_Statement
(Loc
), Stmts
);
3324 when RE_Not_Available
=>
3326 end Build_Init_Statements
;
3328 -------------------------
3329 -- Build_Record_Checks --
3330 -------------------------
3332 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
) is
3333 Subtype_Mark_Id
: Entity_Id
;
3335 procedure Constrain_Array
3337 Check_List
: List_Id
);
3338 -- Apply a list of index constraints to an unconstrained array type.
3339 -- The first parameter is the entity for the resulting subtype.
3340 -- Check_List is a list to which the check actions are appended.
3342 ---------------------
3343 -- Constrain_Array --
3344 ---------------------
3346 procedure Constrain_Array
3348 Check_List
: List_Id
)
3350 C
: constant Node_Id
:= Constraint
(SI
);
3351 Number_Of_Constraints
: Nat
:= 0;
3355 procedure Constrain_Index
3358 Check_List
: List_Id
);
3359 -- Process an index constraint in a constrained array declaration.
3360 -- The constraint can be either a subtype name or a range with or
3361 -- without an explicit subtype mark. Index is the corresponding
3362 -- index of the unconstrained array. S is the range expression.
3363 -- Check_List is a list to which the check actions are appended.
3365 ---------------------
3366 -- Constrain_Index --
3367 ---------------------
3369 procedure Constrain_Index
3372 Check_List
: List_Id
)
3374 T
: constant Entity_Id
:= Etype
(Index
);
3377 if Nkind
(S
) = N_Range
then
3378 Process_Range_Expr_In_Decl
(S
, T
, Check_List
=> Check_List
);
3380 end Constrain_Index
;
3382 -- Start of processing for Constrain_Array
3385 T
:= Entity
(Subtype_Mark
(SI
));
3387 if Is_Access_Type
(T
) then
3388 T
:= Designated_Type
(T
);
3391 S
:= First
(Constraints
(C
));
3392 while Present
(S
) loop
3393 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
3397 -- In either case, the index constraint must provide a discrete
3398 -- range for each index of the array type and the type of each
3399 -- discrete range must be the same as that of the corresponding
3400 -- index. (RM 3.6.1)
3402 S
:= First
(Constraints
(C
));
3403 Index
:= First_Index
(T
);
3406 -- Apply constraints to each index type
3408 for J
in 1 .. Number_Of_Constraints
loop
3409 Constrain_Index
(Index
, S
, Check_List
);
3413 end Constrain_Array
;
3415 -- Start of processing for Build_Record_Checks
3418 if Nkind
(S
) = N_Subtype_Indication
then
3419 Find_Type
(Subtype_Mark
(S
));
3420 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
3422 -- Remaining processing depends on type
3424 case Ekind
(Subtype_Mark_Id
) is
3426 Constrain_Array
(S
, Check_List
);
3432 end Build_Record_Checks
;
3434 -------------------------------------------
3435 -- Component_Needs_Simple_Initialization --
3436 -------------------------------------------
3438 function Component_Needs_Simple_Initialization
3439 (T
: Entity_Id
) return Boolean
3443 Needs_Simple_Initialization
(T
)
3444 and then not Is_RTE
(T
, RE_Tag
)
3446 -- Ada 2005 (AI-251): Check also the tag of abstract interfaces
3448 and then not Is_RTE
(T
, RE_Interface_Tag
);
3449 end Component_Needs_Simple_Initialization
;
3451 --------------------------------------
3452 -- Parent_Subtype_Renaming_Discrims --
3453 --------------------------------------
3455 function Parent_Subtype_Renaming_Discrims
return Boolean is
3460 if Base_Type
(Rec_Ent
) /= Rec_Ent
then
3464 if Etype
(Rec_Ent
) = Rec_Ent
3465 or else not Has_Discriminants
(Rec_Ent
)
3466 or else Is_Constrained
(Rec_Ent
)
3467 or else Is_Tagged_Type
(Rec_Ent
)
3472 -- If there are no explicit stored discriminants we have inherited
3473 -- the root type discriminants so far, so no renamings occurred.
3475 if First_Discriminant
(Rec_Ent
) =
3476 First_Stored_Discriminant
(Rec_Ent
)
3481 -- Check if we have done some trivial renaming of the parent
3482 -- discriminants, i.e. something like
3484 -- type DT (X1, X2: int) is new PT (X1, X2);
3486 De
:= First_Discriminant
(Rec_Ent
);
3487 Dp
:= First_Discriminant
(Etype
(Rec_Ent
));
3488 while Present
(De
) loop
3489 pragma Assert
(Present
(Dp
));
3491 if Corresponding_Discriminant
(De
) /= Dp
then
3495 Next_Discriminant
(De
);
3496 Next_Discriminant
(Dp
);
3499 return Present
(Dp
);
3500 end Parent_Subtype_Renaming_Discrims
;
3502 ------------------------
3503 -- Requires_Init_Proc --
3504 ------------------------
3506 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean is
3507 Comp_Decl
: Node_Id
;
3512 -- Definitely do not need one if specifically suppressed
3514 if Initialization_Suppressed
(Rec_Id
) then
3518 -- If it is a type derived from a type with unknown discriminants,
3519 -- we cannot build an initialization procedure for it.
3521 if Has_Unknown_Discriminants
(Rec_Id
)
3522 or else Has_Unknown_Discriminants
(Etype
(Rec_Id
))
3527 -- Otherwise we need to generate an initialization procedure if
3528 -- Is_CPP_Class is False and at least one of the following applies:
3530 -- 1. Discriminants are present, since they need to be initialized
3531 -- with the appropriate discriminant constraint expressions.
3532 -- However, the discriminant of an unchecked union does not
3533 -- count, since the discriminant is not present.
3535 -- 2. The type is a tagged type, since the implicit Tag component
3536 -- needs to be initialized with a pointer to the dispatch table.
3538 -- 3. The type contains tasks
3540 -- 4. One or more components has an initial value
3542 -- 5. One or more components is for a type which itself requires
3543 -- an initialization procedure.
3545 -- 6. One or more components is a type that requires simple
3546 -- initialization (see Needs_Simple_Initialization), except
3547 -- that types Tag and Interface_Tag are excluded, since fields
3548 -- of these types are initialized by other means.
3550 -- 7. The type is the record type built for a task type (since at
3551 -- the very least, Create_Task must be called)
3553 -- 8. The type is the record type built for a protected type (since
3554 -- at least Initialize_Protection must be called)
3556 -- 9. The type is marked as a public entity. The reason we add this
3557 -- case (even if none of the above apply) is to properly handle
3558 -- Initialize_Scalars. If a package is compiled without an IS
3559 -- pragma, and the client is compiled with an IS pragma, then
3560 -- the client will think an initialization procedure is present
3561 -- and call it, when in fact no such procedure is required, but
3562 -- since the call is generated, there had better be a routine
3563 -- at the other end of the call, even if it does nothing).
3565 -- Note: the reason we exclude the CPP_Class case is because in this
3566 -- case the initialization is performed by the C++ constructors, and
3567 -- the IP is built by Set_CPP_Constructors.
3569 if Is_CPP_Class
(Rec_Id
) then
3572 elsif Is_Interface
(Rec_Id
) then
3575 elsif (Has_Discriminants
(Rec_Id
)
3576 and then not Is_Unchecked_Union
(Rec_Id
))
3577 or else Is_Tagged_Type
(Rec_Id
)
3578 or else Is_Concurrent_Record_Type
(Rec_Id
)
3579 or else Has_Task
(Rec_Id
)
3584 Id
:= First_Component
(Rec_Id
);
3585 while Present
(Id
) loop
3586 Comp_Decl
:= Parent
(Id
);
3589 if Present
(Expression
(Comp_Decl
))
3590 or else Has_Non_Null_Base_Init_Proc
(Typ
)
3591 or else Component_Needs_Simple_Initialization
(Typ
)
3596 Next_Component
(Id
);
3599 -- As explained above, a record initialization procedure is needed
3600 -- for public types in case Initialize_Scalars applies to a client.
3601 -- However, such a procedure is not needed in the case where either
3602 -- of restrictions No_Initialize_Scalars or No_Default_Initialization
3603 -- applies. No_Initialize_Scalars excludes the possibility of using
3604 -- Initialize_Scalars in any partition, and No_Default_Initialization
3605 -- implies that no initialization should ever be done for objects of
3606 -- the type, so is incompatible with Initialize_Scalars.
3608 if not Restriction_Active
(No_Initialize_Scalars
)
3609 and then not Restriction_Active
(No_Default_Initialization
)
3610 and then Is_Public
(Rec_Id
)
3616 end Requires_Init_Proc
;
3618 -- Start of processing for Build_Record_Init_Proc
3621 Rec_Type
:= Defining_Identifier
(N
);
3623 -- This may be full declaration of a private type, in which case
3624 -- the visible entity is a record, and the private entity has been
3625 -- exchanged with it in the private part of the current package.
3626 -- The initialization procedure is built for the record type, which
3627 -- is retrievable from the private entity.
3629 if Is_Incomplete_Or_Private_Type
(Rec_Type
) then
3630 Rec_Type
:= Underlying_Type
(Rec_Type
);
3633 -- If we have a variant record with restriction No_Implicit_Conditionals
3634 -- in effect, then we skip building the procedure. This is safe because
3635 -- if we can see the restriction, so can any caller, calls to initialize
3636 -- such records are not allowed for variant records if this restriction
3639 if Has_Variant_Part
(Rec_Type
)
3640 and then Restriction_Active
(No_Implicit_Conditionals
)
3645 -- If there are discriminants, build the discriminant map to replace
3646 -- discriminants by their discriminals in complex bound expressions.
3647 -- These only arise for the corresponding records of synchronized types.
3649 if Is_Concurrent_Record_Type
(Rec_Type
)
3650 and then Has_Discriminants
(Rec_Type
)
3655 Disc
:= First_Discriminant
(Rec_Type
);
3656 while Present
(Disc
) loop
3657 Append_Elmt
(Disc
, Discr_Map
);
3658 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
3659 Next_Discriminant
(Disc
);
3664 -- Derived types that have no type extension can use the initialization
3665 -- procedure of their parent and do not need a procedure of their own.
3666 -- This is only correct if there are no representation clauses for the
3667 -- type or its parent, and if the parent has in fact been frozen so
3668 -- that its initialization procedure exists.
3670 if Is_Derived_Type
(Rec_Type
)
3671 and then not Is_Tagged_Type
(Rec_Type
)
3672 and then not Is_Unchecked_Union
(Rec_Type
)
3673 and then not Has_New_Non_Standard_Rep
(Rec_Type
)
3674 and then not Parent_Subtype_Renaming_Discrims
3675 and then Has_Non_Null_Base_Init_Proc
(Etype
(Rec_Type
))
3677 Copy_TSS
(Base_Init_Proc
(Etype
(Rec_Type
)), Rec_Type
);
3679 -- Otherwise if we need an initialization procedure, then build one,
3680 -- mark it as public and inlinable and as having a completion.
3682 elsif Requires_Init_Proc
(Rec_Type
)
3683 or else Is_Unchecked_Union
(Rec_Type
)
3686 Make_Defining_Identifier
(Loc
,
3687 Chars
=> Make_Init_Proc_Name
(Rec_Type
));
3689 -- If No_Default_Initialization restriction is active, then we don't
3690 -- want to build an init_proc, but we need to mark that an init_proc
3691 -- would be needed if this restriction was not active (so that we can
3692 -- detect attempts to call it), so set a dummy init_proc in place.
3694 if Restriction_Active
(No_Default_Initialization
) then
3695 Set_Init_Proc
(Rec_Type
, Proc_Id
);
3699 Build_Offset_To_Top_Functions
;
3700 Build_CPP_Init_Procedure
;
3701 Build_Init_Procedure
;
3703 Set_Is_Public
(Proc_Id
, Is_Public
(Rec_Ent
));
3704 Set_Is_Internal
(Proc_Id
);
3705 Set_Has_Completion
(Proc_Id
);
3707 if not Debug_Generated_Code
then
3708 Set_Debug_Info_Off
(Proc_Id
);
3711 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Rec_Type
));
3713 -- Do not build an aggregate if Modify_Tree_For_C, this isn't
3714 -- needed and may generate early references to non frozen types
3715 -- since we expand aggregate much more systematically.
3717 if Modify_Tree_For_C
then
3722 Agg
: constant Node_Id
:=
3723 Build_Equivalent_Record_Aggregate
(Rec_Type
);
3725 procedure Collect_Itypes
(Comp
: Node_Id
);
3726 -- Generate references to itypes in the aggregate, because
3727 -- the first use of the aggregate may be in a nested scope.
3729 --------------------
3730 -- Collect_Itypes --
3731 --------------------
3733 procedure Collect_Itypes
(Comp
: Node_Id
) is
3736 Typ
: constant Entity_Id
:= Etype
(Comp
);
3739 if Is_Array_Type
(Typ
) and then Is_Itype
(Typ
) then
3740 Ref
:= Make_Itype_Reference
(Loc
);
3741 Set_Itype
(Ref
, Typ
);
3742 Append_Freeze_Action
(Rec_Type
, Ref
);
3744 Ref
:= Make_Itype_Reference
(Loc
);
3745 Set_Itype
(Ref
, Etype
(First_Index
(Typ
)));
3746 Append_Freeze_Action
(Rec_Type
, Ref
);
3748 -- Recurse on nested arrays
3750 Sub_Aggr
:= First
(Expressions
(Comp
));
3751 while Present
(Sub_Aggr
) loop
3752 Collect_Itypes
(Sub_Aggr
);
3759 -- If there is a static initialization aggregate for the type,
3760 -- generate itype references for the types of its (sub)components,
3761 -- to prevent out-of-scope errors in the resulting tree.
3762 -- The aggregate may have been rewritten as a Raise node, in which
3763 -- case there are no relevant itypes.
3765 if Present
(Agg
) and then Nkind
(Agg
) = N_Aggregate
then
3766 Set_Static_Initialization
(Proc_Id
, Agg
);
3771 Comp
:= First
(Component_Associations
(Agg
));
3772 while Present
(Comp
) loop
3773 Collect_Itypes
(Expression
(Comp
));
3780 end Build_Record_Init_Proc
;
3782 ----------------------------
3783 -- Build_Slice_Assignment --
3784 ----------------------------
3786 -- Generates the following subprogram:
3789 -- (Source, Target : Array_Type,
3790 -- Left_Lo, Left_Hi : Index;
3791 -- Right_Lo, Right_Hi : Index;
3799 -- if Left_Hi < Left_Lo then
3812 -- Target (Li1) := Source (Ri1);
3815 -- exit when Li1 = Left_Lo;
3816 -- Li1 := Index'pred (Li1);
3817 -- Ri1 := Index'pred (Ri1);
3819 -- exit when Li1 = Left_Hi;
3820 -- Li1 := Index'succ (Li1);
3821 -- Ri1 := Index'succ (Ri1);
3826 procedure Build_Slice_Assignment
(Typ
: Entity_Id
) is
3827 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3828 Index
: constant Entity_Id
:= Base_Type
(Etype
(First_Index
(Typ
)));
3830 Larray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
3831 Rarray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3832 Left_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3833 Left_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3834 Right_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3835 Right_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3836 Rev
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
3837 -- Formal parameters of procedure
3839 Proc_Name
: constant Entity_Id
:=
3840 Make_Defining_Identifier
(Loc
,
3841 Chars
=> Make_TSS_Name
(Typ
, TSS_Slice_Assign
));
3843 Lnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3844 Rnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3845 -- Subscripts for left and right sides
3852 -- Build declarations for indexes
3857 Make_Object_Declaration
(Loc
,
3858 Defining_Identifier
=> Lnn
,
3859 Object_Definition
=>
3860 New_Occurrence_Of
(Index
, Loc
)));
3863 Make_Object_Declaration
(Loc
,
3864 Defining_Identifier
=> Rnn
,
3865 Object_Definition
=>
3866 New_Occurrence_Of
(Index
, Loc
)));
3870 -- Build test for empty slice case
3873 Make_If_Statement
(Loc
,
3876 Left_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
),
3877 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
)),
3878 Then_Statements
=> New_List
(Make_Simple_Return_Statement
(Loc
))));
3880 -- Build initializations for indexes
3883 F_Init
: constant List_Id
:= New_List
;
3884 B_Init
: constant List_Id
:= New_List
;
3888 Make_Assignment_Statement
(Loc
,
3889 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3890 Expression
=> New_Occurrence_Of
(Left_Lo
, Loc
)));
3893 Make_Assignment_Statement
(Loc
,
3894 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3895 Expression
=> New_Occurrence_Of
(Right_Lo
, Loc
)));
3898 Make_Assignment_Statement
(Loc
,
3899 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3900 Expression
=> New_Occurrence_Of
(Left_Hi
, Loc
)));
3903 Make_Assignment_Statement
(Loc
,
3904 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3905 Expression
=> New_Occurrence_Of
(Right_Hi
, Loc
)));
3908 Make_If_Statement
(Loc
,
3909 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
3910 Then_Statements
=> B_Init
,
3911 Else_Statements
=> F_Init
));
3914 -- Now construct the assignment statement
3917 Make_Loop_Statement
(Loc
,
3918 Statements
=> New_List
(
3919 Make_Assignment_Statement
(Loc
,
3921 Make_Indexed_Component
(Loc
,
3922 Prefix
=> New_Occurrence_Of
(Larray
, Loc
),
3923 Expressions
=> New_List
(New_Occurrence_Of
(Lnn
, Loc
))),
3925 Make_Indexed_Component
(Loc
,
3926 Prefix
=> New_Occurrence_Of
(Rarray
, Loc
),
3927 Expressions
=> New_List
(New_Occurrence_Of
(Rnn
, Loc
))))),
3928 End_Label
=> Empty
);
3930 -- Build the exit condition and increment/decrement statements
3933 F_Ass
: constant List_Id
:= New_List
;
3934 B_Ass
: constant List_Id
:= New_List
;
3938 Make_Exit_Statement
(Loc
,
3941 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
3942 Right_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
))));
3945 Make_Assignment_Statement
(Loc
,
3946 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3948 Make_Attribute_Reference
(Loc
,
3950 New_Occurrence_Of
(Index
, Loc
),
3951 Attribute_Name
=> Name_Succ
,
3952 Expressions
=> New_List
(
3953 New_Occurrence_Of
(Lnn
, Loc
)))));
3956 Make_Assignment_Statement
(Loc
,
3957 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3959 Make_Attribute_Reference
(Loc
,
3961 New_Occurrence_Of
(Index
, Loc
),
3962 Attribute_Name
=> Name_Succ
,
3963 Expressions
=> New_List
(
3964 New_Occurrence_Of
(Rnn
, Loc
)))));
3967 Make_Exit_Statement
(Loc
,
3970 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
3971 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
))));
3974 Make_Assignment_Statement
(Loc
,
3975 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3977 Make_Attribute_Reference
(Loc
,
3979 New_Occurrence_Of
(Index
, Loc
),
3980 Attribute_Name
=> Name_Pred
,
3981 Expressions
=> New_List
(
3982 New_Occurrence_Of
(Lnn
, Loc
)))));
3985 Make_Assignment_Statement
(Loc
,
3986 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3988 Make_Attribute_Reference
(Loc
,
3990 New_Occurrence_Of
(Index
, Loc
),
3991 Attribute_Name
=> Name_Pred
,
3992 Expressions
=> New_List
(
3993 New_Occurrence_Of
(Rnn
, Loc
)))));
3995 Append_To
(Statements
(Loops
),
3996 Make_If_Statement
(Loc
,
3997 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
3998 Then_Statements
=> B_Ass
,
3999 Else_Statements
=> F_Ass
));
4002 Append_To
(Stats
, Loops
);
4006 Formals
: List_Id
:= New_List
;
4009 Formals
:= New_List
(
4010 Make_Parameter_Specification
(Loc
,
4011 Defining_Identifier
=> Larray
,
4012 Out_Present
=> True,
4014 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4016 Make_Parameter_Specification
(Loc
,
4017 Defining_Identifier
=> Rarray
,
4019 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4021 Make_Parameter_Specification
(Loc
,
4022 Defining_Identifier
=> Left_Lo
,
4024 New_Occurrence_Of
(Index
, Loc
)),
4026 Make_Parameter_Specification
(Loc
,
4027 Defining_Identifier
=> Left_Hi
,
4029 New_Occurrence_Of
(Index
, Loc
)),
4031 Make_Parameter_Specification
(Loc
,
4032 Defining_Identifier
=> Right_Lo
,
4034 New_Occurrence_Of
(Index
, Loc
)),
4036 Make_Parameter_Specification
(Loc
,
4037 Defining_Identifier
=> Right_Hi
,
4039 New_Occurrence_Of
(Index
, Loc
)));
4042 Make_Parameter_Specification
(Loc
,
4043 Defining_Identifier
=> Rev
,
4045 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
4048 Make_Procedure_Specification
(Loc
,
4049 Defining_Unit_Name
=> Proc_Name
,
4050 Parameter_Specifications
=> Formals
);
4053 Make_Subprogram_Body
(Loc
,
4054 Specification
=> Spec
,
4055 Declarations
=> Decls
,
4056 Handled_Statement_Sequence
=>
4057 Make_Handled_Sequence_Of_Statements
(Loc
,
4058 Statements
=> Stats
)));
4061 Set_TSS
(Typ
, Proc_Name
);
4062 Set_Is_Pure
(Proc_Name
);
4063 end Build_Slice_Assignment
;
4065 -----------------------------
4066 -- Build_Untagged_Equality --
4067 -----------------------------
4069 procedure Build_Untagged_Equality
(Typ
: Entity_Id
) is
4077 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
;
4078 -- Check whether the type T has a user-defined primitive equality. If so
4079 -- return it, else return Empty. If true for a component of Typ, we have
4080 -- to build the primitive equality for it.
4082 ---------------------
4083 -- User_Defined_Eq --
4084 ---------------------
4086 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
is
4091 Op
:= TSS
(T
, TSS_Composite_Equality
);
4093 if Present
(Op
) then
4097 Prim
:= First_Elmt
(Collect_Primitive_Operations
(T
));
4098 while Present
(Prim
) loop
4101 if Chars
(Op
) = Name_Op_Eq
4102 and then Etype
(Op
) = Standard_Boolean
4103 and then Etype
(First_Formal
(Op
)) = T
4104 and then Etype
(Next_Formal
(First_Formal
(Op
))) = T
4113 end User_Defined_Eq
;
4115 -- Start of processing for Build_Untagged_Equality
4118 -- If a record component has a primitive equality operation, we must
4119 -- build the corresponding one for the current type.
4122 Comp
:= First_Component
(Typ
);
4123 while Present
(Comp
) loop
4124 if Is_Record_Type
(Etype
(Comp
))
4125 and then Present
(User_Defined_Eq
(Etype
(Comp
)))
4130 Next_Component
(Comp
);
4133 -- If there is a user-defined equality for the type, we do not create
4134 -- the implicit one.
4136 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Typ
));
4138 while Present
(Prim
) loop
4139 if Chars
(Node
(Prim
)) = Name_Op_Eq
4140 and then Comes_From_Source
(Node
(Prim
))
4142 -- Don't we also need to check formal types and return type as in
4143 -- User_Defined_Eq above???
4146 Eq_Op
:= Node
(Prim
);
4154 -- If the type is derived, inherit the operation, if present, from the
4155 -- parent type. It may have been declared after the type derivation. If
4156 -- the parent type itself is derived, it may have inherited an operation
4157 -- that has itself been overridden, so update its alias and related
4158 -- flags. Ditto for inequality.
4160 if No
(Eq_Op
) and then Is_Derived_Type
(Typ
) then
4161 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Etype
(Typ
)));
4162 while Present
(Prim
) loop
4163 if Chars
(Node
(Prim
)) = Name_Op_Eq
then
4164 Copy_TSS
(Node
(Prim
), Typ
);
4168 Op
: constant Entity_Id
:= User_Defined_Eq
(Typ
);
4169 Eq_Op
: constant Entity_Id
:= Node
(Prim
);
4170 NE_Op
: constant Entity_Id
:= Next_Entity
(Eq_Op
);
4173 if Present
(Op
) then
4174 Set_Alias
(Op
, Eq_Op
);
4175 Set_Is_Abstract_Subprogram
4176 (Op
, Is_Abstract_Subprogram
(Eq_Op
));
4178 if Chars
(Next_Entity
(Op
)) = Name_Op_Ne
then
4179 Set_Is_Abstract_Subprogram
4180 (Next_Entity
(Op
), Is_Abstract_Subprogram
(NE_Op
));
4192 -- If not inherited and not user-defined, build body as for a type with
4193 -- tagged components.
4197 Make_Eq_Body
(Typ
, Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4198 Op
:= Defining_Entity
(Decl
);
4202 if Is_Library_Level_Entity
(Typ
) then
4206 end Build_Untagged_Equality
;
4208 -----------------------------------
4209 -- Build_Variant_Record_Equality --
4210 -----------------------------------
4214 -- function _Equality (X, Y : T) return Boolean is
4216 -- -- Compare discriminants
4218 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4222 -- -- Compare components
4224 -- if X.C1 /= Y.C1 or else X.C2 /= Y.C2 or else ... then
4228 -- -- Compare variant part
4232 -- if X.C2 /= Y.C2 or else X.C3 /= Y.C3 or else ... then
4237 -- if X.Cn /= Y.Cn or else ... then
4245 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
) is
4246 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4248 F
: constant Entity_Id
:=
4249 Make_Defining_Identifier
(Loc
,
4250 Chars
=> Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4252 X
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_X
);
4253 Y
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_Y
);
4255 Def
: constant Node_Id
:= Parent
(Typ
);
4256 Comps
: constant Node_Id
:= Component_List
(Type_Definition
(Def
));
4257 Stmts
: constant List_Id
:= New_List
;
4258 Pspecs
: constant List_Id
:= New_List
;
4261 -- If we have a variant record with restriction No_Implicit_Conditionals
4262 -- in effect, then we skip building the procedure. This is safe because
4263 -- if we can see the restriction, so can any caller, calls to equality
4264 -- test routines are not allowed for variant records if this restriction
4267 if Restriction_Active
(No_Implicit_Conditionals
) then
4271 -- Derived Unchecked_Union types no longer inherit the equality function
4274 if Is_Derived_Type
(Typ
)
4275 and then not Is_Unchecked_Union
(Typ
)
4276 and then not Has_New_Non_Standard_Rep
(Typ
)
4279 Parent_Eq
: constant Entity_Id
:=
4280 TSS
(Root_Type
(Typ
), TSS_Composite_Equality
);
4282 if Present
(Parent_Eq
) then
4283 Copy_TSS
(Parent_Eq
, Typ
);
4290 Make_Subprogram_Body
(Loc
,
4292 Make_Function_Specification
(Loc
,
4293 Defining_Unit_Name
=> F
,
4294 Parameter_Specifications
=> Pspecs
,
4295 Result_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
)),
4296 Declarations
=> New_List
,
4297 Handled_Statement_Sequence
=>
4298 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
)));
4301 Make_Parameter_Specification
(Loc
,
4302 Defining_Identifier
=> X
,
4303 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4306 Make_Parameter_Specification
(Loc
,
4307 Defining_Identifier
=> Y
,
4308 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4310 -- Unchecked_Unions require additional machinery to support equality.
4311 -- Two extra parameters (A and B) are added to the equality function
4312 -- parameter list for each discriminant of the type, in order to
4313 -- capture the inferred values of the discriminants in equality calls.
4314 -- The names of the parameters match the names of the corresponding
4315 -- discriminant, with an added suffix.
4317 if Is_Unchecked_Union
(Typ
) then
4320 Discr_Type
: Entity_Id
;
4322 New_Discrs
: Elist_Id
;
4325 New_Discrs
:= New_Elmt_List
;
4327 Discr
:= First_Discriminant
(Typ
);
4328 while Present
(Discr
) loop
4329 Discr_Type
:= Etype
(Discr
);
4330 A
:= Make_Defining_Identifier
(Loc
,
4331 Chars
=> New_External_Name
(Chars
(Discr
), 'A'));
4333 B
:= Make_Defining_Identifier
(Loc
,
4334 Chars
=> New_External_Name
(Chars
(Discr
), 'B'));
4336 -- Add new parameters to the parameter list
4339 Make_Parameter_Specification
(Loc
,
4340 Defining_Identifier
=> A
,
4342 New_Occurrence_Of
(Discr_Type
, Loc
)));
4345 Make_Parameter_Specification
(Loc
,
4346 Defining_Identifier
=> B
,
4348 New_Occurrence_Of
(Discr_Type
, Loc
)));
4350 Append_Elmt
(A
, New_Discrs
);
4352 -- Generate the following code to compare each of the inferred
4360 Make_If_Statement
(Loc
,
4363 Left_Opnd
=> New_Occurrence_Of
(A
, Loc
),
4364 Right_Opnd
=> New_Occurrence_Of
(B
, Loc
)),
4365 Then_Statements
=> New_List
(
4366 Make_Simple_Return_Statement
(Loc
,
4368 New_Occurrence_Of
(Standard_False
, Loc
)))));
4369 Next_Discriminant
(Discr
);
4372 -- Generate component-by-component comparison. Note that we must
4373 -- propagate the inferred discriminants formals to act as
4374 -- the case statement switch. Their value is added when an
4375 -- equality call on unchecked unions is expanded.
4377 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
, New_Discrs
));
4380 -- Normal case (not unchecked union)
4384 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
4385 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
4389 Make_Simple_Return_Statement
(Loc
,
4390 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
4395 if not Debug_Generated_Code
then
4396 Set_Debug_Info_Off
(F
);
4398 end Build_Variant_Record_Equality
;
4400 -----------------------------
4401 -- Check_Stream_Attributes --
4402 -----------------------------
4404 procedure Check_Stream_Attributes
(Typ
: Entity_Id
) is
4406 Par_Read
: constant Boolean :=
4407 Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
4408 and then not Has_Specified_Stream_Read
(Typ
);
4409 Par_Write
: constant Boolean :=
4410 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
4411 and then not Has_Specified_Stream_Write
(Typ
);
4413 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
);
4414 -- Check that Comp has a user-specified Nam stream attribute
4420 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
) is
4422 if not Stream_Attribute_Available
(Etype
(Comp
), TSS_Nam
) then
4423 Error_Msg_Name_1
:= Nam
;
4425 ("|component& in limited extension must have% attribute", Comp
);
4429 -- Start of processing for Check_Stream_Attributes
4432 if Par_Read
or else Par_Write
then
4433 Comp
:= First_Component
(Typ
);
4434 while Present
(Comp
) loop
4435 if Comes_From_Source
(Comp
)
4436 and then Original_Record_Component
(Comp
) = Comp
4437 and then Is_Limited_Type
(Etype
(Comp
))
4440 Check_Attr
(Name_Read
, TSS_Stream_Read
);
4444 Check_Attr
(Name_Write
, TSS_Stream_Write
);
4448 Next_Component
(Comp
);
4451 end Check_Stream_Attributes
;
4453 ----------------------
4454 -- Clean_Task_Names --
4455 ----------------------
4457 procedure Clean_Task_Names
4459 Proc_Id
: Entity_Id
)
4463 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
4464 and then not Global_Discard_Names
4465 and then Tagged_Type_Expansion
4467 Set_Uses_Sec_Stack
(Proc_Id
);
4469 end Clean_Task_Names
;
4471 ------------------------------
4472 -- Expand_Freeze_Array_Type --
4473 ------------------------------
4475 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
4476 Typ
: constant Entity_Id
:= Entity
(N
);
4477 Base
: constant Entity_Id
:= Base_Type
(Typ
);
4478 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
4481 if not Is_Bit_Packed_Array
(Typ
) then
4483 -- If the component contains tasks, so does the array type. This may
4484 -- not be indicated in the array type because the component may have
4485 -- been a private type at the point of definition. Same if component
4486 -- type is controlled or contains protected objects.
4488 Propagate_Concurrent_Flags
(Base
, Comp_Typ
);
4489 Set_Has_Controlled_Component
4490 (Base
, Has_Controlled_Component
(Comp_Typ
)
4491 or else Is_Controlled
(Comp_Typ
));
4493 if No
(Init_Proc
(Base
)) then
4495 -- If this is an anonymous array created for a declaration with
4496 -- an initial value, its init_proc will never be called. The
4497 -- initial value itself may have been expanded into assignments,
4498 -- in which case the object declaration is carries the
4499 -- No_Initialization flag.
4502 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
4503 N_Object_Declaration
4505 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
4506 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
4510 -- We do not need an init proc for string or wide [wide] string,
4511 -- since the only time these need initialization in normalize or
4512 -- initialize scalars mode, and these types are treated specially
4513 -- and do not need initialization procedures.
4515 elsif Is_Standard_String_Type
(Base
) then
4518 -- Otherwise we have to build an init proc for the subtype
4521 Build_Array_Init_Proc
(Base
, N
);
4525 if Typ
= Base
and then Has_Controlled_Component
(Base
) then
4526 Build_Controlling_Procs
(Base
);
4528 if not Is_Limited_Type
(Comp_Typ
)
4529 and then Number_Dimensions
(Typ
) = 1
4531 Build_Slice_Assignment
(Typ
);
4535 -- For packed case, default initialization, except if the component type
4536 -- is itself a packed structure with an initialization procedure, or
4537 -- initialize/normalize scalars active, and we have a base type, or the
4538 -- type is public, because in that case a client might specify
4539 -- Normalize_Scalars and there better be a public Init_Proc for it.
4541 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
4542 and then No
(Base_Init_Proc
(Base
)))
4543 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
4544 or else Is_Public
(Typ
)
4546 Build_Array_Init_Proc
(Base
, N
);
4548 end Expand_Freeze_Array_Type
;
4550 -----------------------------------
4551 -- Expand_Freeze_Class_Wide_Type --
4552 -----------------------------------
4554 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
4555 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
4556 -- Given a type, determine whether it is derived from a C or C++ root
4558 ---------------------
4559 -- Is_C_Derivation --
4560 ---------------------
4562 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
4569 or else Convention
(T
) = Convention_C
4570 or else Convention
(T
) = Convention_CPP
4575 exit when T
= Etype
(T
);
4581 end Is_C_Derivation
;
4585 Typ
: constant Entity_Id
:= Entity
(N
);
4586 Root
: constant Entity_Id
:= Root_Type
(Typ
);
4588 -- Start of processing for Expand_Freeze_Class_Wide_Type
4591 -- Certain run-time configurations and targets do not provide support
4592 -- for controlled types.
4594 if Restriction_Active
(No_Finalization
) then
4597 -- Do not create TSS routine Finalize_Address when dispatching calls are
4598 -- disabled since the core of the routine is a dispatching call.
4600 elsif Restriction_Active
(No_Dispatching_Calls
) then
4603 -- Do not create TSS routine Finalize_Address for concurrent class-wide
4604 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
4605 -- non-Ada side will handle their destruction.
4607 elsif Is_Concurrent_Type
(Root
)
4608 or else Is_C_Derivation
(Root
)
4609 or else Convention
(Typ
) = Convention_CPP
4613 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
4614 -- mode since the routine contains an Unchecked_Conversion.
4616 elsif CodePeer_Mode
then
4620 -- Create the body of TSS primitive Finalize_Address. This automatically
4621 -- sets the TSS entry for the class-wide type.
4623 Make_Finalize_Address_Body
(Typ
);
4624 end Expand_Freeze_Class_Wide_Type
;
4626 ------------------------------------
4627 -- Expand_Freeze_Enumeration_Type --
4628 ------------------------------------
4630 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
4631 Typ
: constant Entity_Id
:= Entity
(N
);
4632 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4637 Is_Contiguous
: Boolean;
4645 pragma Warnings
(Off
, Func
);
4648 -- Various optimizations possible if given representation is contiguous
4650 Is_Contiguous
:= True;
4652 Ent
:= First_Literal
(Typ
);
4653 Last_Repval
:= Enumeration_Rep
(Ent
);
4656 while Present
(Ent
) loop
4657 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
4658 Is_Contiguous
:= False;
4661 Last_Repval
:= Enumeration_Rep
(Ent
);
4667 if Is_Contiguous
then
4668 Set_Has_Contiguous_Rep
(Typ
);
4669 Ent
:= First_Literal
(Typ
);
4671 Lst
:= New_List
(New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
4674 -- Build list of literal references
4679 Ent
:= First_Literal
(Typ
);
4680 while Present
(Ent
) loop
4681 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
4687 -- Now build an array declaration
4689 -- typA : array (Natural range 0 .. num - 1) of ctype :=
4690 -- (v, v, v, v, v, ....)
4692 -- where ctype is the corresponding integer type. If the representation
4693 -- is contiguous, we only keep the first literal, which provides the
4694 -- offset for Pos_To_Rep computations.
4697 Make_Defining_Identifier
(Loc
,
4698 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
4700 Append_Freeze_Action
(Typ
,
4701 Make_Object_Declaration
(Loc
,
4702 Defining_Identifier
=> Arr
,
4703 Constant_Present
=> True,
4705 Object_Definition
=>
4706 Make_Constrained_Array_Definition
(Loc
,
4707 Discrete_Subtype_Definitions
=> New_List
(
4708 Make_Subtype_Indication
(Loc
,
4709 Subtype_Mark
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
4711 Make_Range_Constraint
(Loc
,
4715 Make_Integer_Literal
(Loc
, 0),
4717 Make_Integer_Literal
(Loc
, Num
- 1))))),
4719 Component_Definition
=>
4720 Make_Component_Definition
(Loc
,
4721 Aliased_Present
=> False,
4722 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
4725 Make_Aggregate
(Loc
,
4726 Expressions
=> Lst
)));
4728 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
4730 -- Now we build the function that converts representation values to
4731 -- position values. This function has the form:
4733 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
4736 -- when enum-lit'Enum_Rep => return posval;
4737 -- when enum-lit'Enum_Rep => return posval;
4740 -- [raise Constraint_Error when F "invalid data"]
4745 -- Note: the F parameter determines whether the others case (no valid
4746 -- representation) raises Constraint_Error or returns a unique value
4747 -- of minus one. The latter case is used, e.g. in 'Valid code.
4749 -- Note: the reason we use Enum_Rep values in the case here is to avoid
4750 -- the code generator making inappropriate assumptions about the range
4751 -- of the values in the case where the value is invalid. ityp is a
4752 -- signed or unsigned integer type of appropriate width.
4754 -- Note: if exceptions are not supported, then we suppress the raise
4755 -- and return -1 unconditionally (this is an erroneous program in any
4756 -- case and there is no obligation to raise Constraint_Error here). We
4757 -- also do this if pragma Restrictions (No_Exceptions) is active.
4759 -- Is this right??? What about No_Exception_Propagation???
4761 -- Representations are signed
4763 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
4765 -- The underlying type is signed. Reset the Is_Unsigned_Type
4766 -- explicitly, because it might have been inherited from
4769 Set_Is_Unsigned_Type
(Typ
, False);
4771 if Esize
(Typ
) <= Standard_Integer_Size
then
4772 Ityp
:= Standard_Integer
;
4774 Ityp
:= Universal_Integer
;
4777 -- Representations are unsigned
4780 if Esize
(Typ
) <= Standard_Integer_Size
then
4781 Ityp
:= RTE
(RE_Unsigned
);
4783 Ityp
:= RTE
(RE_Long_Long_Unsigned
);
4787 -- The body of the function is a case statement. First collect case
4788 -- alternatives, or optimize the contiguous case.
4792 -- If representation is contiguous, Pos is computed by subtracting
4793 -- the representation of the first literal.
4795 if Is_Contiguous
then
4796 Ent
:= First_Literal
(Typ
);
4798 if Enumeration_Rep
(Ent
) = Last_Repval
then
4800 -- Another special case: for a single literal, Pos is zero
4802 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
4806 Convert_To
(Standard_Integer
,
4807 Make_Op_Subtract
(Loc
,
4809 Unchecked_Convert_To
4810 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
4812 Make_Integer_Literal
(Loc
,
4813 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
4817 Make_Case_Statement_Alternative
(Loc
,
4818 Discrete_Choices
=> New_List
(
4819 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
4821 Make_Integer_Literal
(Loc
,
4822 Intval
=> Enumeration_Rep
(Ent
)),
4824 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
4826 Statements
=> New_List
(
4827 Make_Simple_Return_Statement
(Loc
,
4828 Expression
=> Pos_Expr
))));
4831 Ent
:= First_Literal
(Typ
);
4832 while Present
(Ent
) loop
4834 Make_Case_Statement_Alternative
(Loc
,
4835 Discrete_Choices
=> New_List
(
4836 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
4837 Intval
=> Enumeration_Rep
(Ent
))),
4839 Statements
=> New_List
(
4840 Make_Simple_Return_Statement
(Loc
,
4842 Make_Integer_Literal
(Loc
,
4843 Intval
=> Enumeration_Pos
(Ent
))))));
4849 -- In normal mode, add the others clause with the test.
4850 -- If Predicates_Ignored is True, validity checks do not apply to
4853 if not No_Exception_Handlers_Set
4854 and then not Predicates_Ignored
(Typ
)
4857 Make_Case_Statement_Alternative
(Loc
,
4858 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
4859 Statements
=> New_List
(
4860 Make_Raise_Constraint_Error
(Loc
,
4861 Condition
=> Make_Identifier
(Loc
, Name_uF
),
4862 Reason
=> CE_Invalid_Data
),
4863 Make_Simple_Return_Statement
(Loc
,
4864 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
4866 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
4867 -- active then return -1 (we cannot usefully raise Constraint_Error in
4868 -- this case). See description above for further details.
4872 Make_Case_Statement_Alternative
(Loc
,
4873 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
4874 Statements
=> New_List
(
4875 Make_Simple_Return_Statement
(Loc
,
4876 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
4879 -- Now we can build the function body
4882 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
4885 Make_Subprogram_Body
(Loc
,
4887 Make_Function_Specification
(Loc
,
4888 Defining_Unit_Name
=> Fent
,
4889 Parameter_Specifications
=> New_List
(
4890 Make_Parameter_Specification
(Loc
,
4891 Defining_Identifier
=>
4892 Make_Defining_Identifier
(Loc
, Name_uA
),
4893 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
4894 Make_Parameter_Specification
(Loc
,
4895 Defining_Identifier
=>
4896 Make_Defining_Identifier
(Loc
, Name_uF
),
4898 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
4900 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
4902 Declarations
=> Empty_List
,
4904 Handled_Statement_Sequence
=>
4905 Make_Handled_Sequence_Of_Statements
(Loc
,
4906 Statements
=> New_List
(
4907 Make_Case_Statement
(Loc
,
4909 Unchecked_Convert_To
4910 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
4911 Alternatives
=> Lst
))));
4913 Set_TSS
(Typ
, Fent
);
4915 -- Set Pure flag (it will be reset if the current context is not Pure).
4916 -- We also pretend there was a pragma Pure_Function so that for purposes
4917 -- of optimization and constant-folding, we will consider the function
4918 -- Pure even if we are not in a Pure context).
4921 Set_Has_Pragma_Pure_Function
(Fent
);
4923 -- Unless we are in -gnatD mode, where we are debugging generated code,
4924 -- this is an internal entity for which we don't need debug info.
4926 if not Debug_Generated_Code
then
4927 Set_Debug_Info_Off
(Fent
);
4930 Set_Is_Inlined
(Fent
);
4933 when RE_Not_Available
=>
4935 end Expand_Freeze_Enumeration_Type
;
4937 -------------------------------
4938 -- Expand_Freeze_Record_Type --
4939 -------------------------------
4941 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
4942 Typ
: constant Node_Id
:= Entity
(N
);
4943 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
4946 Comp_Typ
: Entity_Id
;
4947 Predef_List
: List_Id
;
4949 Wrapper_Decl_List
: List_Id
:= No_List
;
4950 Wrapper_Body_List
: List_Id
:= No_List
;
4952 Renamed_Eq
: Node_Id
:= Empty
;
4953 -- Defining unit name for the predefined equality function in the case
4954 -- where the type has a primitive operation that is a renaming of
4955 -- predefined equality (but only if there is also an overriding
4956 -- user-defined equality function). Used to pass this entity from
4957 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
4959 -- Start of processing for Expand_Freeze_Record_Type
4962 -- Build discriminant checking functions if not a derived type (for
4963 -- derived types that are not tagged types, always use the discriminant
4964 -- checking functions of the parent type). However, for untagged types
4965 -- the derivation may have taken place before the parent was frozen, so
4966 -- we copy explicitly the discriminant checking functions from the
4967 -- parent into the components of the derived type.
4969 if not Is_Derived_Type
(Typ
)
4970 or else Has_New_Non_Standard_Rep
(Typ
)
4971 or else Is_Tagged_Type
(Typ
)
4973 Build_Discr_Checking_Funcs
(Typ_Decl
);
4975 elsif Is_Derived_Type
(Typ
)
4976 and then not Is_Tagged_Type
(Typ
)
4978 -- If we have a derived Unchecked_Union, we do not inherit the
4979 -- discriminant checking functions from the parent type since the
4980 -- discriminants are non existent.
4982 and then not Is_Unchecked_Union
(Typ
)
4983 and then Has_Discriminants
(Typ
)
4986 Old_Comp
: Entity_Id
;
4990 First_Component
(Base_Type
(Underlying_Type
(Etype
(Typ
))));
4991 Comp
:= First_Component
(Typ
);
4992 while Present
(Comp
) loop
4993 if Ekind
(Comp
) = E_Component
4994 and then Chars
(Comp
) = Chars
(Old_Comp
)
4996 Set_Discriminant_Checking_Func
4997 (Comp
, Discriminant_Checking_Func
(Old_Comp
));
5000 Next_Component
(Old_Comp
);
5001 Next_Component
(Comp
);
5006 if Is_Derived_Type
(Typ
)
5007 and then Is_Limited_Type
(Typ
)
5008 and then Is_Tagged_Type
(Typ
)
5010 Check_Stream_Attributes
(Typ
);
5013 -- Update task, protected, and controlled component flags, because some
5014 -- of the component types may have been private at the point of the
5015 -- record declaration. Detect anonymous access-to-controlled components.
5017 Comp
:= First_Component
(Typ
);
5018 while Present
(Comp
) loop
5019 Comp_Typ
:= Etype
(Comp
);
5021 Propagate_Concurrent_Flags
(Typ
, Comp_Typ
);
5023 -- Do not set Has_Controlled_Component on a class-wide equivalent
5024 -- type. See Make_CW_Equivalent_Type.
5026 if not Is_Class_Wide_Equivalent_Type
(Typ
)
5028 (Has_Controlled_Component
(Comp_Typ
)
5029 or else (Chars
(Comp
) /= Name_uParent
5030 and then Is_Controlled
(Comp_Typ
)))
5032 Set_Has_Controlled_Component
(Typ
);
5035 Next_Component
(Comp
);
5038 -- Handle constructors of untagged CPP_Class types
5040 if not Is_Tagged_Type
(Typ
) and then Is_CPP_Class
(Typ
) then
5041 Set_CPP_Constructors
(Typ
);
5044 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
5045 -- for regular tagged types as well as for Ada types deriving from a C++
5046 -- Class, but not for tagged types directly corresponding to C++ classes
5047 -- In the later case we assume that it is created in the C++ side and we
5050 if Is_Tagged_Type
(Typ
) then
5052 -- Add the _Tag component
5054 if Underlying_Type
(Etype
(Typ
)) = Typ
then
5055 Expand_Tagged_Root
(Typ
);
5058 if Is_CPP_Class
(Typ
) then
5059 Set_All_DT_Position
(Typ
);
5061 -- Create the tag entities with a minimum decoration
5063 if Tagged_Type_Expansion
then
5064 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5067 Set_CPP_Constructors
(Typ
);
5070 if not Building_Static_DT
(Typ
) then
5072 -- Usually inherited primitives are not delayed but the first
5073 -- Ada extension of a CPP_Class is an exception since the
5074 -- address of the inherited subprogram has to be inserted in
5075 -- the new Ada Dispatch Table and this is a freezing action.
5077 -- Similarly, if this is an inherited operation whose parent is
5078 -- not frozen yet, it is not in the DT of the parent, and we
5079 -- generate an explicit freeze node for the inherited operation
5080 -- so it is properly inserted in the DT of the current type.
5087 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5088 while Present
(Elmt
) loop
5089 Subp
:= Node
(Elmt
);
5091 if Present
(Alias
(Subp
)) then
5092 if Is_CPP_Class
(Etype
(Typ
)) then
5093 Set_Has_Delayed_Freeze
(Subp
);
5095 elsif Has_Delayed_Freeze
(Alias
(Subp
))
5096 and then not Is_Frozen
(Alias
(Subp
))
5098 Set_Is_Frozen
(Subp
, False);
5099 Set_Has_Delayed_Freeze
(Subp
);
5108 -- Unfreeze momentarily the type to add the predefined primitives
5109 -- operations. The reason we unfreeze is so that these predefined
5110 -- operations will indeed end up as primitive operations (which
5111 -- must be before the freeze point).
5113 Set_Is_Frozen
(Typ
, False);
5115 -- Do not add the spec of predefined primitives in case of
5116 -- CPP tagged type derivations that have convention CPP.
5118 if Is_CPP_Class
(Root_Type
(Typ
))
5119 and then Convention
(Typ
) = Convention_CPP
5123 -- Do not add the spec of the predefined primitives if we are
5124 -- compiling under restriction No_Dispatching_Calls.
5126 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5127 Make_Predefined_Primitive_Specs
(Typ
, Predef_List
, Renamed_Eq
);
5128 Insert_List_Before_And_Analyze
(N
, Predef_List
);
5131 -- Ada 2005 (AI-391): For a nonabstract null extension, create
5132 -- wrapper functions for each nonoverridden inherited function
5133 -- with a controlling result of the type. The wrapper for such
5134 -- a function returns an extension aggregate that invokes the
5137 if Ada_Version
>= Ada_2005
5138 and then not Is_Abstract_Type
(Typ
)
5139 and then Is_Null_Extension
(Typ
)
5141 Make_Controlling_Function_Wrappers
5142 (Typ
, Wrapper_Decl_List
, Wrapper_Body_List
);
5143 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
5146 -- Ada 2005 (AI-251): For a nonabstract type extension, build
5147 -- null procedure declarations for each set of homographic null
5148 -- procedures that are inherited from interface types but not
5149 -- overridden. This is done to ensure that the dispatch table
5150 -- entry associated with such null primitives are properly filled.
5152 if Ada_Version
>= Ada_2005
5153 and then Etype
(Typ
) /= Typ
5154 and then not Is_Abstract_Type
(Typ
)
5155 and then Has_Interfaces
(Typ
)
5157 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Typ
));
5160 Set_Is_Frozen
(Typ
);
5162 if not Is_Derived_Type
(Typ
)
5163 or else Is_Tagged_Type
(Etype
(Typ
))
5165 Set_All_DT_Position
(Typ
);
5167 -- If this is a type derived from an untagged private type whose
5168 -- full view is tagged, the type is marked tagged for layout
5169 -- reasons, but it has no dispatch table.
5171 elsif Is_Derived_Type
(Typ
)
5172 and then Is_Private_Type
(Etype
(Typ
))
5173 and then not Is_Tagged_Type
(Etype
(Typ
))
5178 -- Create and decorate the tags. Suppress their creation when
5179 -- not Tagged_Type_Expansion because the dispatching mechanism is
5180 -- handled internally by the virtual target.
5182 if Tagged_Type_Expansion
then
5183 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5185 -- Generate dispatch table of locally defined tagged type.
5186 -- Dispatch tables of library level tagged types are built
5187 -- later (see Analyze_Declarations).
5189 if not Building_Static_DT
(Typ
) then
5190 Append_Freeze_Actions
(Typ
, Make_DT
(Typ
));
5194 -- If the type has unknown discriminants, propagate dispatching
5195 -- information to its underlying record view, which does not get
5196 -- its own dispatch table.
5198 if Is_Derived_Type
(Typ
)
5199 and then Has_Unknown_Discriminants
(Typ
)
5200 and then Present
(Underlying_Record_View
(Typ
))
5203 Rep
: constant Entity_Id
:= Underlying_Record_View
(Typ
);
5205 Set_Access_Disp_Table
5206 (Rep
, Access_Disp_Table
(Typ
));
5207 Set_Dispatch_Table_Wrappers
5208 (Rep
, Dispatch_Table_Wrappers
(Typ
));
5209 Set_Direct_Primitive_Operations
5210 (Rep
, Direct_Primitive_Operations
(Typ
));
5214 -- Make sure that the primitives Initialize, Adjust and Finalize
5215 -- are Frozen before other TSS subprograms. We don't want them
5218 if Is_Controlled
(Typ
) then
5219 if not Is_Limited_Type
(Typ
) then
5220 Append_Freeze_Actions
(Typ
,
5221 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Adjust
), Typ
));
5224 Append_Freeze_Actions
(Typ
,
5225 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Initialize
), Typ
));
5227 Append_Freeze_Actions
(Typ
,
5228 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Finalize
), Typ
));
5231 -- Freeze rest of primitive operations. There is no need to handle
5232 -- the predefined primitives if we are compiling under restriction
5233 -- No_Dispatching_Calls.
5235 if not Restriction_Active
(No_Dispatching_Calls
) then
5236 Append_Freeze_Actions
(Typ
, Predefined_Primitive_Freeze
(Typ
));
5240 -- In the untagged case, ever since Ada 83 an equality function must
5241 -- be provided for variant records that are not unchecked unions.
5242 -- In Ada 2012 the equality function composes, and thus must be built
5243 -- explicitly just as for tagged records.
5245 elsif Has_Discriminants
(Typ
)
5246 and then not Is_Limited_Type
(Typ
)
5249 Comps
: constant Node_Id
:=
5250 Component_List
(Type_Definition
(Typ_Decl
));
5253 and then Present
(Variant_Part
(Comps
))
5255 Build_Variant_Record_Equality
(Typ
);
5259 -- Otherwise create primitive equality operation (AI05-0123)
5261 -- This is done unconditionally to ensure that tools can be linked
5262 -- properly with user programs compiled with older language versions.
5263 -- In addition, this is needed because "=" composes for bounded strings
5264 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
5266 elsif Comes_From_Source
(Typ
)
5267 and then Convention
(Typ
) = Convention_Ada
5268 and then not Is_Limited_Type
(Typ
)
5270 Build_Untagged_Equality
(Typ
);
5273 -- Before building the record initialization procedure, if we are
5274 -- dealing with a concurrent record value type, then we must go through
5275 -- the discriminants, exchanging discriminals between the concurrent
5276 -- type and the concurrent record value type. See the section "Handling
5277 -- of Discriminants" in the Einfo spec for details.
5279 if Is_Concurrent_Record_Type
(Typ
)
5280 and then Has_Discriminants
(Typ
)
5283 Ctyp
: constant Entity_Id
:=
5284 Corresponding_Concurrent_Type
(Typ
);
5285 Conc_Discr
: Entity_Id
;
5286 Rec_Discr
: Entity_Id
;
5290 Conc_Discr
:= First_Discriminant
(Ctyp
);
5291 Rec_Discr
:= First_Discriminant
(Typ
);
5292 while Present
(Conc_Discr
) loop
5293 Temp
:= Discriminal
(Conc_Discr
);
5294 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
5295 Set_Discriminal
(Rec_Discr
, Temp
);
5297 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
5298 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
5300 Next_Discriminant
(Conc_Discr
);
5301 Next_Discriminant
(Rec_Discr
);
5306 if Has_Controlled_Component
(Typ
) then
5307 Build_Controlling_Procs
(Typ
);
5310 Adjust_Discriminants
(Typ
);
5312 -- Do not need init for interfaces on virtual targets since they're
5315 if Tagged_Type_Expansion
or else not Is_Interface
(Typ
) then
5316 Build_Record_Init_Proc
(Typ_Decl
, Typ
);
5319 -- For tagged type that are not interfaces, build bodies of primitive
5320 -- operations. Note: do this after building the record initialization
5321 -- procedure, since the primitive operations may need the initialization
5322 -- routine. There is no need to add predefined primitives of interfaces
5323 -- because all their predefined primitives are abstract.
5325 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
5327 -- Do not add the body of predefined primitives in case of CPP tagged
5328 -- type derivations that have convention CPP.
5330 if Is_CPP_Class
(Root_Type
(Typ
))
5331 and then Convention
(Typ
) = Convention_CPP
5335 -- Do not add the body of the predefined primitives if we are
5336 -- compiling under restriction No_Dispatching_Calls or if we are
5337 -- compiling a CPP tagged type.
5339 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5341 -- Create the body of TSS primitive Finalize_Address. This must
5342 -- be done before the bodies of all predefined primitives are
5343 -- created. If Typ is limited, Stream_Input and Stream_Read may
5344 -- produce build-in-place allocations and for those the expander
5345 -- needs Finalize_Address.
5347 Make_Finalize_Address_Body
(Typ
);
5348 Predef_List
:= Predefined_Primitive_Bodies
(Typ
, Renamed_Eq
);
5349 Append_Freeze_Actions
(Typ
, Predef_List
);
5352 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
5353 -- inherited functions, then add their bodies to the freeze actions.
5355 if Present
(Wrapper_Body_List
) then
5356 Append_Freeze_Actions
(Typ
, Wrapper_Body_List
);
5359 -- Create extra formals for the primitive operations of the type.
5360 -- This must be done before analyzing the body of the initialization
5361 -- procedure, because a self-referential type might call one of these
5362 -- primitives in the body of the init_proc itself.
5369 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5370 while Present
(Elmt
) loop
5371 Subp
:= Node
(Elmt
);
5372 if not Has_Foreign_Convention
(Subp
)
5373 and then not Is_Predefined_Dispatching_Operation
(Subp
)
5375 Create_Extra_Formals
(Subp
);
5382 end Expand_Freeze_Record_Type
;
5384 ------------------------------------
5385 -- Expand_N_Full_Type_Declaration --
5386 ------------------------------------
5388 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
) is
5389 procedure Build_Master
(Ptr_Typ
: Entity_Id
);
5390 -- Create the master associated with Ptr_Typ
5396 procedure Build_Master
(Ptr_Typ
: Entity_Id
) is
5397 Desig_Typ
: Entity_Id
:= Designated_Type
(Ptr_Typ
);
5400 -- If the designated type is an incomplete view coming from a
5401 -- limited-with'ed package, we need to use the nonlimited view in
5402 -- case it has tasks.
5404 if Ekind
(Desig_Typ
) in Incomplete_Kind
5405 and then Present
(Non_Limited_View
(Desig_Typ
))
5407 Desig_Typ
:= Non_Limited_View
(Desig_Typ
);
5410 -- Anonymous access types are created for the components of the
5411 -- record parameter for an entry declaration. No master is created
5414 if Comes_From_Source
(N
) and then Has_Task
(Desig_Typ
) then
5415 Build_Master_Entity
(Ptr_Typ
);
5416 Build_Master_Renaming
(Ptr_Typ
);
5418 -- Create a class-wide master because a Master_Id must be generated
5419 -- for access-to-limited-class-wide types whose root may be extended
5420 -- with task components.
5422 -- Note: This code covers access-to-limited-interfaces because they
5423 -- can be used to reference tasks implementing them.
5425 elsif Is_Limited_Class_Wide_Type
(Desig_Typ
)
5426 and then Tasking_Allowed
5428 Build_Class_Wide_Master
(Ptr_Typ
);
5432 -- Local declarations
5434 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5435 B_Id
: constant Entity_Id
:= Base_Type
(Def_Id
);
5439 -- Start of processing for Expand_N_Full_Type_Declaration
5442 if Is_Access_Type
(Def_Id
) then
5443 Build_Master
(Def_Id
);
5445 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
5446 Expand_Access_Protected_Subprogram_Type
(N
);
5449 -- Array of anonymous access-to-task pointers
5451 elsif Ada_Version
>= Ada_2005
5452 and then Is_Array_Type
(Def_Id
)
5453 and then Is_Access_Type
(Component_Type
(Def_Id
))
5454 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
5456 Build_Master
(Component_Type
(Def_Id
));
5458 elsif Has_Task
(Def_Id
) then
5459 Expand_Previous_Access_Type
(Def_Id
);
5461 -- Check the components of a record type or array of records for
5462 -- anonymous access-to-task pointers.
5464 elsif Ada_Version
>= Ada_2005
5465 and then (Is_Record_Type
(Def_Id
)
5467 (Is_Array_Type
(Def_Id
)
5468 and then Is_Record_Type
(Component_Type
(Def_Id
))))
5477 if Is_Array_Type
(Def_Id
) then
5478 Comp
:= First_Entity
(Component_Type
(Def_Id
));
5480 Comp
:= First_Entity
(Def_Id
);
5483 -- Examine all components looking for anonymous access-to-task
5487 while Present
(Comp
) loop
5488 Typ
:= Etype
(Comp
);
5490 if Ekind
(Typ
) = E_Anonymous_Access_Type
5491 and then Has_Task
(Available_View
(Designated_Type
(Typ
)))
5492 and then No
(Master_Id
(Typ
))
5494 -- Ensure that the record or array type have a _master
5497 Build_Master_Entity
(Def_Id
);
5498 Build_Master_Renaming
(Typ
);
5499 M_Id
:= Master_Id
(Typ
);
5503 -- Reuse the same master to service any additional types
5506 Set_Master_Id
(Typ
, M_Id
);
5515 Par_Id
:= Etype
(B_Id
);
5517 -- The parent type is private then we need to inherit any TSS operations
5518 -- from the full view.
5520 if Ekind
(Par_Id
) in Private_Kind
5521 and then Present
(Full_View
(Par_Id
))
5523 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
5526 if Nkind
(Type_Definition
(Original_Node
(N
))) =
5527 N_Derived_Type_Definition
5528 and then not Is_Tagged_Type
(Def_Id
)
5529 and then Present
(Freeze_Node
(Par_Id
))
5530 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
5532 Ensure_Freeze_Node
(B_Id
);
5533 FN
:= Freeze_Node
(B_Id
);
5535 if No
(TSS_Elist
(FN
)) then
5536 Set_TSS_Elist
(FN
, New_Elmt_List
);
5540 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
5544 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
5545 while Present
(Elmt
) loop
5546 if Chars
(Node
(Elmt
)) /= Name_uInit
then
5547 Append_Elmt
(Node
(Elmt
), T_E
);
5553 -- If the derived type itself is private with a full view, then
5554 -- associate the full view with the inherited TSS_Elist as well.
5556 if Ekind
(B_Id
) in Private_Kind
5557 and then Present
(Full_View
(B_Id
))
5559 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
5561 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
5565 end Expand_N_Full_Type_Declaration
;
5567 ---------------------------------
5568 -- Expand_N_Object_Declaration --
5569 ---------------------------------
5571 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
5572 Loc
: constant Source_Ptr
:= Sloc
(N
);
5573 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5574 Expr
: constant Node_Id
:= Expression
(N
);
5575 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
5576 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
5577 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5580 function Build_Equivalent_Aggregate
return Boolean;
5581 -- If the object has a constrained discriminated type and no initial
5582 -- value, it may be possible to build an equivalent aggregate instead,
5583 -- and prevent an actual call to the initialization procedure.
5585 procedure Check_Large_Modular_Array
;
5586 -- Check that the size of the array can be computed without overflow,
5587 -- and generate a Storage_Error otherwise. This is only relevant for
5588 -- array types whose index in a (mod 2**64) type, where wrap-around
5589 -- arithmetic might yield a meaningless value for the length of the
5590 -- array, or its corresponding attribute.
5592 procedure Count_Default_Sized_Task_Stacks
5594 Pri_Stacks
: out Int
;
5595 Sec_Stacks
: out Int
);
5596 -- Count the number of default-sized primary and secondary task stacks
5597 -- required for task objects contained within type Typ. If the number of
5598 -- task objects contained within the type is not known at compile time
5599 -- the procedure will return the stack counts of zero.
5601 procedure Default_Initialize_Object
(After
: Node_Id
);
5602 -- Generate all default initialization actions for object Def_Id. Any
5603 -- new code is inserted after node After.
5605 function Rewrite_As_Renaming
return Boolean;
5606 -- Indicate whether to rewrite a declaration with initialization into an
5607 -- object renaming declaration (see below).
5609 --------------------------------
5610 -- Build_Equivalent_Aggregate --
5611 --------------------------------
5613 function Build_Equivalent_Aggregate
return Boolean is
5617 Full_Type
: Entity_Id
;
5622 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
5623 Full_Type
:= Full_View
(Typ
);
5626 -- Only perform this transformation if Elaboration_Code is forbidden
5627 -- or undesirable, and if this is a global entity of a constrained
5630 -- If Initialize_Scalars might be active this transformation cannot
5631 -- be performed either, because it will lead to different semantics
5632 -- or because elaboration code will in fact be created.
5634 if Ekind
(Full_Type
) /= E_Record_Subtype
5635 or else not Has_Discriminants
(Full_Type
)
5636 or else not Is_Constrained
(Full_Type
)
5637 or else Is_Controlled
(Full_Type
)
5638 or else Is_Limited_Type
(Full_Type
)
5639 or else not Restriction_Active
(No_Initialize_Scalars
)
5644 if Ekind
(Current_Scope
) = E_Package
5646 (Restriction_Active
(No_Elaboration_Code
)
5647 or else Is_Preelaborated
(Current_Scope
))
5649 -- Building a static aggregate is possible if the discriminants
5650 -- have static values and the other components have static
5651 -- defaults or none.
5653 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5654 while Present
(Discr
) loop
5655 if not Is_OK_Static_Expression
(Node
(Discr
)) then
5662 -- Check that initialized components are OK, and that non-
5663 -- initialized components do not require a call to their own
5664 -- initialization procedure.
5666 Comp
:= First_Component
(Full_Type
);
5667 while Present
(Comp
) loop
5668 if Ekind
(Comp
) = E_Component
5669 and then Present
(Expression
(Parent
(Comp
)))
5671 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
5675 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
5680 Next_Component
(Comp
);
5683 -- Everything is static, assemble the aggregate, discriminant
5687 Make_Aggregate
(Loc
,
5688 Expressions
=> New_List
,
5689 Component_Associations
=> New_List
);
5691 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5692 while Present
(Discr
) loop
5693 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
5697 -- Now collect values of initialized components
5699 Comp
:= First_Component
(Full_Type
);
5700 while Present
(Comp
) loop
5701 if Ekind
(Comp
) = E_Component
5702 and then Present
(Expression
(Parent
(Comp
)))
5704 Append_To
(Component_Associations
(Aggr
),
5705 Make_Component_Association
(Loc
,
5706 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
5707 Expression
=> New_Copy_Tree
5708 (Expression
(Parent
(Comp
)))));
5711 Next_Component
(Comp
);
5714 -- Finally, box-initialize remaining components
5716 Append_To
(Component_Associations
(Aggr
),
5717 Make_Component_Association
(Loc
,
5718 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5719 Expression
=> Empty
));
5720 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
5721 Set_Expression
(N
, Aggr
);
5723 if Typ
/= Full_Type
then
5724 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
5725 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
5726 Analyze_And_Resolve
(Aggr
, Typ
);
5728 Analyze_And_Resolve
(Aggr
, Full_Type
);
5736 end Build_Equivalent_Aggregate
;
5738 -------------------------------
5739 -- Check_Large_Modular_Array --
5740 -------------------------------
5742 procedure Check_Large_Modular_Array
is
5743 Index_Typ
: Entity_Id
;
5746 if Is_Array_Type
(Typ
)
5747 and then Is_Modular_Integer_Type
(Etype
(First_Index
(Typ
)))
5749 -- To prevent arithmetic overflow with large values, we raise
5750 -- Storage_Error under the following guard:
5752 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
5754 -- This takes care of the boundary case, but it is preferable to
5755 -- use a smaller limit, because even on 64-bit architectures an
5756 -- array of more than 2 ** 30 bytes is likely to raise
5759 Index_Typ
:= Etype
(First_Index
(Typ
));
5761 if RM_Size
(Index_Typ
) = RM_Size
(Standard_Long_Long_Integer
) then
5763 Make_Raise_Storage_Error
(Loc
,
5767 Make_Op_Subtract
(Loc
,
5769 Make_Op_Divide
(Loc
,
5771 Make_Attribute_Reference
(Loc
,
5773 New_Occurrence_Of
(Typ
, Loc
),
5774 Attribute_Name
=> Name_Last
),
5776 Make_Integer_Literal
(Loc
, Uint_2
)),
5778 Make_Op_Divide
(Loc
,
5780 Make_Attribute_Reference
(Loc
,
5782 New_Occurrence_Of
(Typ
, Loc
),
5783 Attribute_Name
=> Name_First
),
5785 Make_Integer_Literal
(Loc
, Uint_2
))),
5787 Make_Integer_Literal
(Loc
, (Uint_2
** 30))),
5788 Reason
=> SE_Object_Too_Large
));
5791 end Check_Large_Modular_Array
;
5793 -------------------------------------
5794 -- Count_Default_Sized_Task_Stacks --
5795 -------------------------------------
5797 procedure Count_Default_Sized_Task_Stacks
5799 Pri_Stacks
: out Int
;
5800 Sec_Stacks
: out Int
)
5802 Component
: Entity_Id
;
5805 -- To calculate the number of default-sized task stacks required for
5806 -- an object of Typ, a depth-first recursive traversal of the AST
5807 -- from the Typ entity node is undertaken. Only type nodes containing
5808 -- task objects are visited.
5813 if not Has_Task
(Typ
) then
5821 -- A task type is found marking the bottom of the descent. If
5822 -- the type has no representation aspect for the corresponding
5823 -- stack then that stack is using the default size.
5825 if Present
(Get_Rep_Item
(Typ
, Name_Storage_Size
)) then
5831 if Present
(Get_Rep_Item
(Typ
, Name_Secondary_Stack_Size
)) then
5837 when E_Array_Subtype
5840 -- First find the number of default stacks contained within an
5843 Count_Default_Sized_Task_Stacks
5844 (Component_Type
(Typ
),
5848 -- Then multiply the result by the size of the array
5851 Quantity
: constant Int
:= Number_Of_Elements_In_Array
(Typ
);
5852 -- Number_Of_Elements_In_Array is non-trival, consequently
5853 -- its result is captured as an optimization.
5856 Pri_Stacks
:= Pri_Stacks
* Quantity
;
5857 Sec_Stacks
:= Sec_Stacks
* Quantity
;
5860 when E_Protected_Subtype
5865 Component
:= First_Component_Or_Discriminant
(Typ
);
5867 -- Recursively descend each component of the composite type
5868 -- looking for tasks, but only if the component is marked as
5871 while Present
(Component
) loop
5872 if Has_Task
(Etype
(Component
)) then
5878 Count_Default_Sized_Task_Stacks
5879 (Etype
(Component
), P
, S
);
5880 Pri_Stacks
:= Pri_Stacks
+ P
;
5881 Sec_Stacks
:= Sec_Stacks
+ S
;
5885 Next_Component_Or_Discriminant
(Component
);
5888 when E_Limited_Private_Subtype
5889 | E_Limited_Private_Type
5890 | E_Record_Subtype_With_Private
5891 | E_Record_Type_With_Private
5893 -- Switch to the full view of the private type to continue
5896 Count_Default_Sized_Task_Stacks
5897 (Full_View
(Typ
), Pri_Stacks
, Sec_Stacks
);
5899 -- Other types should not contain tasks
5902 raise Program_Error
;
5904 end Count_Default_Sized_Task_Stacks
;
5906 -------------------------------
5907 -- Default_Initialize_Object --
5908 -------------------------------
5910 procedure Default_Initialize_Object
(After
: Node_Id
) is
5911 function New_Object_Reference
return Node_Id
;
5912 -- Return a new reference to Def_Id with attributes Assignment_OK and
5913 -- Must_Not_Freeze already set.
5915 --------------------------
5916 -- New_Object_Reference --
5917 --------------------------
5919 function New_Object_Reference
return Node_Id
is
5920 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
5923 -- The call to the type init proc or [Deep_]Finalize must not
5924 -- freeze the related object as the call is internally generated.
5925 -- This way legal rep clauses that apply to the object will not be
5926 -- flagged. Note that the initialization call may be removed if
5927 -- pragma Import is encountered or moved to the freeze actions of
5928 -- the object because of an address clause.
5930 Set_Assignment_OK
(Obj_Ref
);
5931 Set_Must_Not_Freeze
(Obj_Ref
);
5934 end New_Object_Reference
;
5938 Exceptions_OK
: constant Boolean :=
5939 not Restriction_Active
(No_Exception_Propagation
);
5941 Aggr_Init
: Node_Id
;
5942 Comp_Init
: List_Id
:= No_List
;
5943 Fin_Block
: Node_Id
;
5945 Init_Stmts
: List_Id
:= No_List
;
5946 Obj_Init
: Node_Id
:= Empty
;
5949 -- Start of processing for Default_Initialize_Object
5952 -- Default initialization is suppressed for objects that are already
5953 -- known to be imported (i.e. whose declaration specifies the Import
5954 -- aspect). Note that for objects with a pragma Import, we generate
5955 -- initialization here, and then remove it downstream when processing
5956 -- the pragma. It is also suppressed for variables for which a pragma
5957 -- Suppress_Initialization has been explicitly given
5959 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
5962 -- Nothing to do if the object being initialized is of a task type
5963 -- and restriction No_Tasking is in effect, because this is a direct
5964 -- violation of the restriction.
5966 elsif Is_Task_Type
(Base_Typ
)
5967 and then Restriction_Active
(No_Tasking
)
5972 -- The expansion performed by this routine is as follows:
5976 -- Type_Init_Proc (Obj);
5979 -- [Deep_]Initialize (Obj);
5983 -- [Deep_]Finalize (Obj, Self => False);
5987 -- Abort_Undefer_Direct;
5990 -- Initialize the components of the object
5992 if Has_Non_Null_Base_Init_Proc
(Typ
)
5993 and then not No_Initialization
(N
)
5994 and then not Initialization_Suppressed
(Typ
)
5996 -- Do not initialize the components if No_Default_Initialization
5997 -- applies as the actual restriction check will occur later
5998 -- when the object is frozen as it is not known yet whether the
5999 -- object is imported or not.
6001 if not Restriction_Active
(No_Default_Initialization
) then
6003 -- If the values of the components are compile-time known, use
6004 -- their prebuilt aggregate form directly.
6006 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
6008 if Present
(Aggr_Init
) then
6010 (N
, New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
6012 -- If type has discriminants, try to build an equivalent
6013 -- aggregate using discriminant values from the declaration.
6014 -- This is a useful optimization, in particular if restriction
6015 -- No_Elaboration_Code is active.
6017 elsif Build_Equivalent_Aggregate
then
6020 -- Otherwise invoke the type init proc, generate:
6021 -- Type_Init_Proc (Obj);
6024 Obj_Ref
:= New_Object_Reference
;
6026 if Comes_From_Source
(Def_Id
) then
6027 Initialization_Warning
(Obj_Ref
);
6030 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
6034 -- Provide a default value if the object needs simple initialization
6035 -- and does not already have an initial value. A generated temporary
6036 -- does not require initialization because it will be assigned later.
6038 elsif Needs_Simple_Initialization
6039 (Typ
, Initialize_Scalars
6040 and then No
(Following_Address_Clause
(N
)))
6041 and then not Is_Internal
(Def_Id
)
6042 and then not Has_Init_Expression
(N
)
6044 Set_No_Initialization
(N
, False);
6045 Set_Expression
(N
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Def_Id
)));
6046 Analyze_And_Resolve
(Expression
(N
), Typ
);
6049 -- Initialize the object, generate:
6050 -- [Deep_]Initialize (Obj);
6052 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
6055 (Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
6059 -- Build a special finalization block when both the object and its
6060 -- controlled components are to be initialized. The block finalizes
6061 -- the components if the object initialization fails. Generate:
6072 if Has_Controlled_Component
(Typ
)
6073 and then Present
(Comp_Init
)
6074 and then Present
(Obj_Init
)
6075 and then Exceptions_OK
6077 Init_Stmts
:= Comp_Init
;
6081 (Obj_Ref
=> New_Object_Reference
,
6085 if Present
(Fin_Call
) then
6087 Make_Block_Statement
(Loc
,
6088 Declarations
=> No_List
,
6090 Handled_Statement_Sequence
=>
6091 Make_Handled_Sequence_Of_Statements
(Loc
,
6092 Statements
=> New_List
(Obj_Init
),
6094 Exception_Handlers
=> New_List
(
6095 Make_Exception_Handler
(Loc
,
6096 Exception_Choices
=> New_List
(
6097 Make_Others_Choice
(Loc
)),
6099 Statements
=> New_List
(
6101 Make_Raise_Statement
(Loc
))))));
6103 -- Signal the ABE mechanism that the block carries out
6104 -- initialization actions.
6106 Set_Is_Initialization_Block
(Fin_Block
);
6108 Append_To
(Init_Stmts
, Fin_Block
);
6111 -- Otherwise finalization is not required, the initialization calls
6112 -- are passed to the abort block building circuitry, generate:
6114 -- Type_Init_Proc (Obj);
6115 -- [Deep_]Initialize (Obj);
6118 if Present
(Comp_Init
) then
6119 Init_Stmts
:= Comp_Init
;
6122 if Present
(Obj_Init
) then
6123 if No
(Init_Stmts
) then
6124 Init_Stmts
:= New_List
;
6127 Append_To
(Init_Stmts
, Obj_Init
);
6131 -- Build an abort block to protect the initialization calls
6134 and then Present
(Comp_Init
)
6135 and then Present
(Obj_Init
)
6140 Prepend_To
(Init_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
6142 -- When exceptions are propagated, abort deferral must take place
6143 -- in the presence of initialization or finalization exceptions.
6150 -- Abort_Undefer_Direct;
6153 if Exceptions_OK
then
6154 Init_Stmts
:= New_List
(
6155 Build_Abort_Undefer_Block
(Loc
,
6156 Stmts
=> Init_Stmts
,
6159 -- Otherwise exceptions are not propagated. Generate:
6166 Append_To
(Init_Stmts
,
6167 Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
6171 -- Insert the whole initialization sequence into the tree. If the
6172 -- object has a delayed freeze, as will be the case when it has
6173 -- aspect specifications, the initialization sequence is part of
6174 -- the freeze actions.
6176 if Present
(Init_Stmts
) then
6177 if Has_Delayed_Freeze
(Def_Id
) then
6178 Append_Freeze_Actions
(Def_Id
, Init_Stmts
);
6180 Insert_Actions_After
(After
, Init_Stmts
);
6183 end Default_Initialize_Object
;
6185 -------------------------
6186 -- Rewrite_As_Renaming --
6187 -------------------------
6189 function Rewrite_As_Renaming
return Boolean is
6191 -- If the object declaration appears in the form
6193 -- Obj : Ctrl_Typ := Func (...);
6195 -- where Ctrl_Typ is controlled but not immutably limited type, then
6196 -- the expansion of the function call should use a dereference of the
6197 -- result to reference the value on the secondary stack.
6199 -- Obj : Ctrl_Typ renames Func (...).all;
6201 -- As a result, the call avoids an extra copy. This an optimization,
6202 -- but it is required for passing ACATS tests in some cases where it
6203 -- would otherwise make two copies. The RM allows removing redunant
6204 -- Adjust/Finalize calls, but does not allow insertion of extra ones.
6206 -- This part is disabled for now, because it breaks GPS builds
6208 return (False -- ???
6209 and then Nkind
(Expr_Q
) = N_Explicit_Dereference
6210 and then not Comes_From_Source
(Expr_Q
)
6211 and then Nkind
(Original_Node
(Expr_Q
)) = N_Function_Call
6212 and then Nkind
(Object_Definition
(N
)) in N_Has_Entity
6213 and then (Needs_Finalization
(Entity
(Object_Definition
(N
)))))
6215 -- If the initializing expression is for a variable with attribute
6216 -- OK_To_Rename set, then transform:
6218 -- Obj : Typ := Expr;
6222 -- Obj : Typ renames Expr;
6224 -- provided that Obj is not aliased. The aliased case has to be
6225 -- excluded in general because Expr will not be aliased in
6229 (not Aliased_Present
(N
)
6230 and then Is_Entity_Name
(Expr_Q
)
6231 and then Ekind
(Entity
(Expr_Q
)) = E_Variable
6232 and then OK_To_Rename
(Entity
(Expr_Q
))
6233 and then Is_Entity_Name
(Obj_Def
));
6234 end Rewrite_As_Renaming
;
6238 Next_N
: constant Node_Id
:= Next
(N
);
6242 Tag_Assign
: Node_Id
;
6244 Init_After
: Node_Id
:= N
;
6245 -- Node after which the initialization actions are to be inserted. This
6246 -- is normally N, except for the case of a shared passive variable, in
6247 -- which case the init proc call must be inserted only after the bodies
6248 -- of the shared variable procedures have been seen.
6250 -- Start of processing for Expand_N_Object_Declaration
6253 -- Don't do anything for deferred constants. All proper actions will be
6254 -- expanded during the full declaration.
6256 if No
(Expr
) and Constant_Present
(N
) then
6260 -- The type of the object cannot be abstract. This is diagnosed at the
6261 -- point the object is frozen, which happens after the declaration is
6262 -- fully expanded, so simply return now.
6264 if Is_Abstract_Type
(Typ
) then
6268 -- No action needed for the internal imported dummy object added by
6269 -- Make_DT to compute the offset of the components that reference
6270 -- secondary dispatch tables; required to avoid never-ending loop
6271 -- processing this internal object declaration.
6273 if Tagged_Type_Expansion
6274 and then Is_Internal
(Def_Id
)
6275 and then Is_Imported
(Def_Id
)
6276 and then Related_Type
(Def_Id
) = Implementation_Base_Type
(Typ
)
6281 -- First we do special processing for objects of a tagged type where
6282 -- this is the point at which the type is frozen. The creation of the
6283 -- dispatch table and the initialization procedure have to be deferred
6284 -- to this point, since we reference previously declared primitive
6287 -- Force construction of dispatch tables of library level tagged types
6289 if Tagged_Type_Expansion
6290 and then Building_Static_Dispatch_Tables
6291 and then Is_Library_Level_Entity
(Def_Id
)
6292 and then Is_Library_Level_Tagged_Type
(Base_Typ
)
6293 and then Ekind_In
(Base_Typ
, E_Record_Type
,
6296 and then not Has_Dispatch_Table
(Base_Typ
)
6299 New_Nodes
: List_Id
:= No_List
;
6302 if Is_Concurrent_Type
(Base_Typ
) then
6303 New_Nodes
:= Make_DT
(Corresponding_Record_Type
(Base_Typ
), N
);
6305 New_Nodes
:= Make_DT
(Base_Typ
, N
);
6308 if not Is_Empty_List
(New_Nodes
) then
6309 Insert_List_Before
(N
, New_Nodes
);
6314 -- Make shared memory routines for shared passive variable
6316 if Is_Shared_Passive
(Def_Id
) then
6317 Init_After
:= Make_Shared_Var_Procs
(N
);
6320 -- If tasks being declared, make sure we have an activation chain
6321 -- defined for the tasks (has no effect if we already have one), and
6322 -- also that a Master variable is established and that the appropriate
6323 -- enclosing construct is established as a task master.
6325 if Has_Task
(Typ
) then
6326 Build_Activation_Chain_Entity
(N
);
6327 Build_Master_Entity
(Def_Id
);
6330 Check_Large_Modular_Array
;
6332 -- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
6333 -- restrictions are active then default-sized secondary stacks are
6334 -- generated by the binder and allocated by SS_Init. To provide the
6335 -- binder the number of stacks to generate, the number of default-sized
6336 -- stacks required for task objects contained within the object
6337 -- declaration N is calculated here as it is at this point where
6338 -- unconstrained types become constrained. The result is stored in the
6339 -- enclosing unit's Unit_Record.
6341 -- Note if N is an array object declaration that has an initialization
6342 -- expression, a second object declaration for the initialization
6343 -- expression is created by the compiler. To prevent double counting
6344 -- of the stacks in this scenario, the stacks of the first array are
6348 and then not Restriction_Active
(No_Secondary_Stack
)
6349 and then (Restriction_Active
(No_Implicit_Heap_Allocations
)
6350 or else Restriction_Active
(No_Implicit_Task_Allocations
))
6351 and then not (Ekind_In
(Ekind
(Typ
), E_Array_Type
, E_Array_Subtype
)
6352 and then (Has_Init_Expression
(N
)))
6355 PS_Count
, SS_Count
: Int
:= 0;
6357 Count_Default_Sized_Task_Stacks
(Typ
, PS_Count
, SS_Count
);
6358 Increment_Primary_Stack_Count
(PS_Count
);
6359 Increment_Sec_Stack_Count
(SS_Count
);
6363 -- Default initialization required, and no expression present
6367 -- If we have a type with a variant part, the initialization proc
6368 -- will contain implicit tests of the discriminant values, which
6369 -- counts as a violation of the restriction No_Implicit_Conditionals.
6371 if Has_Variant_Part
(Typ
) then
6376 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
6380 ("\initialization of variant record tests discriminants",
6387 -- For the default initialization case, if we have a private type
6388 -- with invariants, and invariant checks are enabled, then insert an
6389 -- invariant check after the object declaration. Note that it is OK
6390 -- to clobber the object with an invalid value since if the exception
6391 -- is raised, then the object will go out of scope. In the case where
6392 -- an array object is initialized with an aggregate, the expression
6393 -- is removed. Check flag Has_Init_Expression to avoid generating a
6394 -- junk invariant check and flag No_Initialization to avoid checking
6395 -- an uninitialized object such as a compiler temporary used for an
6398 if Has_Invariants
(Base_Typ
)
6399 and then Present
(Invariant_Procedure
(Base_Typ
))
6400 and then not Has_Init_Expression
(N
)
6401 and then not No_Initialization
(N
)
6403 -- If entity has an address clause or aspect, make invariant
6404 -- call into a freeze action for the explicit freeze node for
6405 -- object. Otherwise insert invariant check after declaration.
6407 if Present
(Following_Address_Clause
(N
))
6408 or else Has_Aspect
(Def_Id
, Aspect_Address
)
6410 Ensure_Freeze_Node
(Def_Id
);
6411 Set_Has_Delayed_Freeze
(Def_Id
);
6412 Set_Is_Frozen
(Def_Id
, False);
6414 if not Partial_View_Has_Unknown_Discr
(Typ
) then
6415 Append_Freeze_Action
(Def_Id
,
6416 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
6419 elsif not Partial_View_Has_Unknown_Discr
(Typ
) then
6421 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
6425 Default_Initialize_Object
(Init_After
);
6427 -- Generate attribute for Persistent_BSS if needed
6429 if Persistent_BSS_Mode
6430 and then Comes_From_Source
(N
)
6431 and then Is_Potentially_Persistent_Type
(Typ
)
6432 and then not Has_Init_Expression
(N
)
6433 and then Is_Library_Level_Entity
(Def_Id
)
6439 Make_Linker_Section_Pragma
6440 (Def_Id
, Sloc
(N
), ".persistent.bss");
6441 Insert_After
(N
, Prag
);
6446 -- If access type, then we know it is null if not initialized
6448 if Is_Access_Type
(Typ
) then
6449 Set_Is_Known_Null
(Def_Id
);
6452 -- Explicit initialization present
6455 -- Obtain actual expression from qualified expression
6457 if Nkind
(Expr
) = N_Qualified_Expression
then
6458 Expr_Q
:= Expression
(Expr
);
6463 -- When we have the appropriate type of aggregate in the expression
6464 -- (it has been determined during analysis of the aggregate by
6465 -- setting the delay flag), let's perform in place assignment and
6466 -- thus avoid creating a temporary.
6468 if Is_Delayed_Aggregate
(Expr_Q
) then
6469 Convert_Aggr_In_Object_Decl
(N
);
6471 -- Ada 2005 (AI-318-02): If the initialization expression is a call
6472 -- to a build-in-place function, then access to the declared object
6473 -- must be passed to the function. Currently we limit such functions
6474 -- to those with constrained limited result subtypes, but eventually
6475 -- plan to expand the allowed forms of functions that are treated as
6478 elsif Is_Build_In_Place_Function_Call
(Expr_Q
) then
6479 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
6481 -- The previous call expands the expression initializing the
6482 -- built-in-place object into further code that will be analyzed
6483 -- later. No further expansion needed here.
6487 -- This is the same as the previous 'elsif', except that the call has
6488 -- been transformed by other expansion activities into something like
6489 -- F(...)'Reference.
6491 elsif Nkind
(Expr_Q
) = N_Reference
6492 and then Is_Build_In_Place_Function_Call
(Prefix
(Expr_Q
))
6493 and then not Is_Expanded_Build_In_Place_Call
6494 (Unqual_Conv
(Prefix
(Expr_Q
)))
6496 Make_Build_In_Place_Call_In_Anonymous_Context
(Prefix
(Expr_Q
));
6498 -- The previous call expands the expression initializing the
6499 -- built-in-place object into further code that will be analyzed
6500 -- later. No further expansion needed here.
6504 -- Ada 2005 (AI-318-02): Specialization of the previous case for
6505 -- expressions containing a build-in-place function call whose
6506 -- returned object covers interface types, and Expr_Q has calls to
6507 -- Ada.Tags.Displace to displace the pointer to the returned build-
6508 -- in-place object to reference the secondary dispatch table of a
6509 -- covered interface type.
6511 elsif Present
(Unqual_BIP_Iface_Function_Call
(Expr_Q
)) then
6512 Make_Build_In_Place_Iface_Call_In_Object_Declaration
(N
, Expr_Q
);
6514 -- The previous call expands the expression initializing the
6515 -- built-in-place object into further code that will be analyzed
6516 -- later. No further expansion needed here.
6520 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
6521 -- class-wide interface object to ensure that we copy the full
6522 -- object, unless we are targetting a VM where interfaces are handled
6523 -- by VM itself. Note that if the root type of Typ is an ancestor of
6524 -- Expr's type, both types share the same dispatch table and there is
6525 -- no need to displace the pointer.
6527 elsif Is_Interface
(Typ
)
6529 -- Avoid never-ending recursion because if Equivalent_Type is set
6530 -- then we've done it already and must not do it again.
6533 (Nkind
(Obj_Def
) = N_Identifier
6534 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
6536 pragma Assert
(Is_Class_Wide_Type
(Typ
));
6538 -- If the object is a return object of an inherently limited type,
6539 -- which implies build-in-place treatment, bypass the special
6540 -- treatment of class-wide interface initialization below. In this
6541 -- case, the expansion of the return statement will take care of
6542 -- creating the object (via allocator) and initializing it.
6544 if Is_Return_Object
(Def_Id
) and then Is_Limited_View
(Typ
) then
6547 elsif Tagged_Type_Expansion
then
6549 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
6550 Expr_N
: Node_Id
:= Expr
;
6551 Expr_Typ
: Entity_Id
;
6557 -- If the original node of the expression was a conversion
6558 -- to this specific class-wide interface type then restore
6559 -- the original node because we must copy the object before
6560 -- displacing the pointer to reference the secondary tag
6561 -- component. This code must be kept synchronized with the
6562 -- expansion done by routine Expand_Interface_Conversion
6564 if not Comes_From_Source
(Expr_N
)
6565 and then Nkind
(Expr_N
) = N_Explicit_Dereference
6566 and then Nkind
(Original_Node
(Expr_N
)) = N_Type_Conversion
6567 and then Etype
(Original_Node
(Expr_N
)) = Typ
6569 Rewrite
(Expr_N
, Original_Node
(Expression
(N
)));
6572 -- Avoid expansion of redundant interface conversion
6574 if Is_Interface
(Etype
(Expr_N
))
6575 and then Nkind
(Expr_N
) = N_Type_Conversion
6576 and then Etype
(Expr_N
) = Typ
6578 Expr_N
:= Expression
(Expr_N
);
6579 Set_Expression
(N
, Expr_N
);
6582 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_N
);
6583 Expr_Typ
:= Base_Type
(Etype
(Expr_N
));
6585 if Is_Class_Wide_Type
(Expr_Typ
) then
6586 Expr_Typ
:= Root_Type
(Expr_Typ
);
6590 -- CW : I'Class := Obj;
6593 -- type Ityp is not null access I'Class;
6594 -- CW : I'Class renames Ityp (Tmp.I_Tag'Address).all;
6596 if Comes_From_Source
(Expr_N
)
6597 and then Nkind
(Expr_N
) = N_Identifier
6598 and then not Is_Interface
(Expr_Typ
)
6599 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
6600 and then (Expr_Typ
= Etype
(Expr_Typ
)
6602 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
6607 Make_Object_Declaration
(Loc
,
6608 Defining_Identifier
=> Obj_Id
,
6609 Object_Definition
=>
6610 New_Occurrence_Of
(Expr_Typ
, Loc
),
6611 Expression
=> Relocate_Node
(Expr_N
)));
6613 -- Statically reference the tag associated with the
6617 Make_Selected_Component
(Loc
,
6618 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
6621 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
6624 -- IW : I'Class := Obj;
6626 -- type Equiv_Record is record ... end record;
6627 -- implicit subtype CW is <Class_Wide_Subtype>;
6628 -- Tmp : CW := CW!(Obj);
6629 -- type Ityp is not null access I'Class;
6630 -- IW : I'Class renames
6631 -- Ityp!(Displace (Temp'Address, I'Tag)).all;
6634 -- Generate the equivalent record type and update the
6635 -- subtype indication to reference it.
6637 Expand_Subtype_From_Expr
6640 Subtype_Indic
=> Obj_Def
,
6643 if not Is_Interface
(Etype
(Expr_N
)) then
6644 New_Expr
:= Relocate_Node
(Expr_N
);
6646 -- For interface types we use 'Address which displaces
6647 -- the pointer to the base of the object (if required)
6651 Unchecked_Convert_To
(Etype
(Obj_Def
),
6652 Make_Explicit_Dereference
(Loc
,
6653 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
6654 Make_Attribute_Reference
(Loc
,
6655 Prefix
=> Relocate_Node
(Expr_N
),
6656 Attribute_Name
=> Name_Address
))));
6661 if not Is_Limited_Record
(Expr_Typ
) then
6663 Make_Object_Declaration
(Loc
,
6664 Defining_Identifier
=> Obj_Id
,
6665 Object_Definition
=>
6666 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
6667 Expression
=> New_Expr
));
6669 -- Rename limited type object since they cannot be copied
6670 -- This case occurs when the initialization expression
6671 -- has been previously expanded into a temporary object.
6673 else pragma Assert
(not Comes_From_Source
(Expr_Q
));
6675 Make_Object_Renaming_Declaration
(Loc
,
6676 Defining_Identifier
=> Obj_Id
,
6678 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
6680 Unchecked_Convert_To
6681 (Etype
(Obj_Def
), New_Expr
)));
6684 -- Dynamically reference the tag associated with the
6688 Make_Function_Call
(Loc
,
6689 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
6690 Parameter_Associations
=> New_List
(
6691 Make_Attribute_Reference
(Loc
,
6692 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
6693 Attribute_Name
=> Name_Address
),
6695 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
6700 Make_Object_Renaming_Declaration
(Loc
,
6701 Defining_Identifier
=> Make_Temporary
(Loc
, 'D'),
6702 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
6704 Convert_Tag_To_Interface
(Typ
, Tag_Comp
)));
6706 -- If the original entity comes from source, then mark the
6707 -- new entity as needing debug information, even though it's
6708 -- defined by a generated renaming that does not come from
6709 -- source, so that Materialize_Entity will be set on the
6710 -- entity when Debug_Renaming_Declaration is called during
6713 if Comes_From_Source
(Def_Id
) then
6714 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
6717 Analyze
(N
, Suppress
=> All_Checks
);
6719 -- Replace internal identifier of rewritten node by the
6720 -- identifier found in the sources. We also have to exchange
6721 -- entities containing their defining identifiers to ensure
6722 -- the correct replacement of the object declaration by this
6723 -- object renaming declaration because these identifiers
6724 -- were previously added by Enter_Name to the current scope.
6725 -- We must preserve the homonym chain of the source entity
6726 -- as well. We must also preserve the kind of the entity,
6727 -- which may be a constant. Preserve entity chain because
6728 -- itypes may have been generated already, and the full
6729 -- chain must be preserved for final freezing. Finally,
6730 -- preserve Comes_From_Source setting, so that debugging
6731 -- and cross-referencing information is properly kept, and
6732 -- preserve source location, to prevent spurious errors when
6733 -- entities are declared (they must have their own Sloc).
6736 New_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6737 Next_Temp
: constant Entity_Id
:= Next_Entity
(New_Id
);
6738 Save_CFS
: constant Boolean :=
6739 Comes_From_Source
(Def_Id
);
6740 Save_SP
: constant Node_Id
:= SPARK_Pragma
(Def_Id
);
6741 Save_SPI
: constant Boolean :=
6742 SPARK_Pragma_Inherited
(Def_Id
);
6745 Set_Next_Entity
(New_Id
, Next_Entity
(Def_Id
));
6746 Set_Next_Entity
(Def_Id
, Next_Temp
);
6748 Set_Chars
(Defining_Identifier
(N
), Chars
(Def_Id
));
6749 Set_Homonym
(Defining_Identifier
(N
), Homonym
(Def_Id
));
6750 Set_Ekind
(Defining_Identifier
(N
), Ekind
(Def_Id
));
6751 Set_Sloc
(Defining_Identifier
(N
), Sloc
(Def_Id
));
6753 Set_Comes_From_Source
(Def_Id
, False);
6755 -- ??? This is extremely dangerous!!! Exchanging entities
6756 -- is very low level, and as a result it resets flags and
6757 -- fields which belong to the original Def_Id. Several of
6758 -- these attributes are saved and restored, but there may
6759 -- be many more that need to be preserverd.
6761 Exchange_Entities
(Defining_Identifier
(N
), Def_Id
);
6763 -- Restore clobbered attributes
6765 Set_Comes_From_Source
(Def_Id
, Save_CFS
);
6766 Set_SPARK_Pragma
(Def_Id
, Save_SP
);
6767 Set_SPARK_Pragma_Inherited
(Def_Id
, Save_SPI
);
6774 -- Common case of explicit object initialization
6777 -- In most cases, we must check that the initial value meets any
6778 -- constraint imposed by the declared type. However, there is one
6779 -- very important exception to this rule. If the entity has an
6780 -- unconstrained nominal subtype, then it acquired its constraints
6781 -- from the expression in the first place, and not only does this
6782 -- mean that the constraint check is not needed, but an attempt to
6783 -- perform the constraint check can cause order of elaboration
6786 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
6788 -- If this is an allocator for an aggregate that has been
6789 -- allocated in place, delay checks until assignments are
6790 -- made, because the discriminants are not initialized.
6792 if Nkind
(Expr
) = N_Allocator
6793 and then No_Initialization
(Expr
)
6797 -- Otherwise apply a constraint check now if no prev error
6799 elsif Nkind
(Expr
) /= N_Error
then
6800 Apply_Constraint_Check
(Expr
, Typ
);
6802 -- Deal with possible range check
6804 if Do_Range_Check
(Expr
) then
6806 -- If assignment checks are suppressed, turn off flag
6808 if Suppress_Assignment_Checks
(N
) then
6809 Set_Do_Range_Check
(Expr
, False);
6811 -- Otherwise generate the range check
6814 Generate_Range_Check
6815 (Expr
, Typ
, CE_Range_Check_Failed
);
6821 -- If the type is controlled and not inherently limited, then
6822 -- the target is adjusted after the copy and attached to the
6823 -- finalization list. However, no adjustment is done in the case
6824 -- where the object was initialized by a call to a function whose
6825 -- result is built in place, since no copy occurred. Similarly, no
6826 -- adjustment is required if we are going to rewrite the object
6827 -- declaration into a renaming declaration.
6829 if Needs_Finalization
(Typ
)
6830 and then not Is_Limited_View
(Typ
)
6831 and then not Rewrite_As_Renaming
6835 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
6838 -- Guard against a missing [Deep_]Adjust when the base type
6839 -- was not properly frozen.
6841 if Present
(Adj_Call
) then
6842 Insert_Action_After
(Init_After
, Adj_Call
);
6846 -- For tagged types, when an init value is given, the tag has to
6847 -- be re-initialized separately in order to avoid the propagation
6848 -- of a wrong tag coming from a view conversion unless the type
6849 -- is class wide (in this case the tag comes from the init value).
6850 -- Suppress the tag assignment when not Tagged_Type_Expansion
6851 -- because tags are represented implicitly in objects. Ditto for
6852 -- types that are CPP_CLASS, and for initializations that are
6853 -- aggregates, because they have to have the right tag.
6855 -- The re-assignment of the tag has to be done even if the object
6856 -- is a constant. The assignment must be analyzed after the
6857 -- declaration. If an address clause follows, this is handled as
6858 -- part of the freeze actions for the object, otherwise insert
6859 -- tag assignment here.
6861 Tag_Assign
:= Make_Tag_Assignment
(N
);
6863 if Present
(Tag_Assign
) then
6864 if Present
(Following_Address_Clause
(N
)) then
6865 Ensure_Freeze_Node
(Def_Id
);
6868 Insert_Action_After
(Init_After
, Tag_Assign
);
6871 -- Handle C++ constructor calls. Note that we do not check that
6872 -- Typ is a tagged type since the equivalent Ada type of a C++
6873 -- class that has no virtual methods is an untagged limited
6876 elsif Is_CPP_Constructor_Call
(Expr
) then
6878 -- The call to the initialization procedure does NOT freeze the
6879 -- object being initialized.
6881 Id_Ref
:= New_Occurrence_Of
(Def_Id
, Loc
);
6882 Set_Must_Not_Freeze
(Id_Ref
);
6883 Set_Assignment_OK
(Id_Ref
);
6885 Insert_Actions_After
(Init_After
,
6886 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
6887 Constructor_Ref
=> Expr
));
6889 -- We remove here the original call to the constructor
6890 -- to avoid its management in the backend
6892 Set_Expression
(N
, Empty
);
6895 -- Handle initialization of limited tagged types
6897 elsif Is_Tagged_Type
(Typ
)
6898 and then Is_Class_Wide_Type
(Typ
)
6899 and then Is_Limited_Record
(Typ
)
6900 and then not Is_Limited_Interface
(Typ
)
6902 -- Given that the type is limited we cannot perform a copy. If
6903 -- Expr_Q is the reference to a variable we mark the variable
6904 -- as OK_To_Rename to expand this declaration into a renaming
6905 -- declaration (see bellow).
6907 if Is_Entity_Name
(Expr_Q
) then
6908 Set_OK_To_Rename
(Entity
(Expr_Q
));
6910 -- If we cannot convert the expression into a renaming we must
6911 -- consider it an internal error because the backend does not
6912 -- have support to handle it.
6915 pragma Assert
(False);
6916 raise Program_Error
;
6919 -- For discrete types, set the Is_Known_Valid flag if the
6920 -- initializing value is known to be valid. Only do this for
6921 -- source assignments, since otherwise we can end up turning
6922 -- on the known valid flag prematurely from inserted code.
6924 elsif Comes_From_Source
(N
)
6925 and then Is_Discrete_Type
(Typ
)
6926 and then Expr_Known_Valid
(Expr
)
6928 Set_Is_Known_Valid
(Def_Id
);
6930 elsif Is_Access_Type
(Typ
) then
6932 -- For access types set the Is_Known_Non_Null flag if the
6933 -- initializing value is known to be non-null. We can also set
6934 -- Can_Never_Be_Null if this is a constant.
6936 if Known_Non_Null
(Expr
) then
6937 Set_Is_Known_Non_Null
(Def_Id
, True);
6939 if Constant_Present
(N
) then
6940 Set_Can_Never_Be_Null
(Def_Id
);
6945 -- If validity checking on copies, validate initial expression.
6946 -- But skip this if declaration is for a generic type, since it
6947 -- makes no sense to validate generic types. Not clear if this
6948 -- can happen for legal programs, but it definitely can arise
6949 -- from previous instantiation errors.
6951 if Validity_Checks_On
6952 and then Comes_From_Source
(N
)
6953 and then Validity_Check_Copies
6954 and then not Is_Generic_Type
(Etype
(Def_Id
))
6956 Ensure_Valid
(Expr
);
6957 Set_Is_Known_Valid
(Def_Id
);
6961 -- Cases where the back end cannot handle the initialization
6962 -- directly. In such cases, we expand an assignment that will
6963 -- be appropriately handled by Expand_N_Assignment_Statement.
6965 -- The exclusion of the unconstrained case is wrong, but for now it
6966 -- is too much trouble ???
6968 if (Is_Possibly_Unaligned_Slice
(Expr
)
6969 or else (Is_Possibly_Unaligned_Object
(Expr
)
6970 and then not Represented_As_Scalar
(Etype
(Expr
))))
6971 and then not (Is_Array_Type
(Etype
(Expr
))
6972 and then not Is_Constrained
(Etype
(Expr
)))
6975 Stat
: constant Node_Id
:=
6976 Make_Assignment_Statement
(Loc
,
6977 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
6978 Expression
=> Relocate_Node
(Expr
));
6980 Set_Expression
(N
, Empty
);
6981 Set_No_Initialization
(N
);
6982 Set_Assignment_OK
(Name
(Stat
));
6983 Set_No_Ctrl_Actions
(Stat
);
6984 Insert_After_And_Analyze
(Init_After
, Stat
);
6989 if Nkind
(Obj_Def
) = N_Access_Definition
6990 and then not Is_Local_Anonymous_Access
(Etype
(Def_Id
))
6992 -- An Ada 2012 stand-alone object of an anonymous access type
6995 Loc
: constant Source_Ptr
:= Sloc
(N
);
6997 Level
: constant Entity_Id
:=
6998 Make_Defining_Identifier
(Sloc
(N
),
7000 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
7002 Level_Expr
: Node_Id
;
7003 Level_Decl
: Node_Id
;
7006 Set_Ekind
(Level
, Ekind
(Def_Id
));
7007 Set_Etype
(Level
, Standard_Natural
);
7008 Set_Scope
(Level
, Scope
(Def_Id
));
7012 -- Set accessibility level of null
7015 Make_Integer_Literal
(Loc
, Scope_Depth
(Standard_Standard
));
7018 Level_Expr
:= Dynamic_Accessibility_Level
(Expr
);
7022 Make_Object_Declaration
(Loc
,
7023 Defining_Identifier
=> Level
,
7024 Object_Definition
=>
7025 New_Occurrence_Of
(Standard_Natural
, Loc
),
7026 Expression
=> Level_Expr
,
7027 Constant_Present
=> Constant_Present
(N
),
7028 Has_Init_Expression
=> True);
7030 Insert_Action_After
(Init_After
, Level_Decl
);
7032 Set_Extra_Accessibility
(Def_Id
, Level
);
7036 -- If the object is default initialized and its type is subject to
7037 -- pragma Default_Initial_Condition, add a runtime check to verify
7038 -- the assumption of the pragma (SPARK RM 7.3.3). Generate:
7040 -- <Base_Typ>DIC (<Base_Typ> (Def_Id));
7042 -- Note that the check is generated for source objects only
7044 if Comes_From_Source
(Def_Id
)
7045 and then Has_DIC
(Typ
)
7046 and then Present
(DIC_Procedure
(Typ
))
7047 and then not Has_Init_Expression
(N
)
7050 DIC_Call
: constant Node_Id
:= Build_DIC_Call
(Loc
, Def_Id
, Typ
);
7053 if Present
(Next_N
) then
7054 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
7056 -- The object declaration is the last node in a declarative or a
7060 Append_To
(List_Containing
(N
), DIC_Call
);
7066 -- Final transformation - turn the object declaration into a renaming
7067 -- if appropriate. If this is the completion of a deferred constant
7068 -- declaration, then this transformation generates what would be
7069 -- illegal code if written by hand, but that's OK.
7071 if Present
(Expr
) then
7072 if Rewrite_As_Renaming
then
7074 Make_Object_Renaming_Declaration
(Loc
,
7075 Defining_Identifier
=> Defining_Identifier
(N
),
7076 Subtype_Mark
=> Obj_Def
,
7079 -- We do not analyze this renaming declaration, because all its
7080 -- components have already been analyzed, and if we were to go
7081 -- ahead and analyze it, we would in effect be trying to generate
7082 -- another declaration of X, which won't do.
7084 Set_Renamed_Object
(Defining_Identifier
(N
), Expr_Q
);
7087 -- We do need to deal with debug issues for this renaming
7089 -- First, if entity comes from source, then mark it as needing
7090 -- debug information, even though it is defined by a generated
7091 -- renaming that does not come from source.
7093 if Comes_From_Source
(Defining_Identifier
(N
)) then
7094 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
7097 -- Now call the routine to generate debug info for the renaming
7100 Decl
: constant Node_Id
:= Debug_Renaming_Declaration
(N
);
7102 if Present
(Decl
) then
7103 Insert_Action
(N
, Decl
);
7109 -- Exception on library entity not available
7112 when RE_Not_Available
=>
7114 end Expand_N_Object_Declaration
;
7116 ---------------------------------
7117 -- Expand_N_Subtype_Indication --
7118 ---------------------------------
7120 -- Add a check on the range of the subtype. The static case is partially
7121 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
7122 -- to check here for the static case in order to avoid generating
7123 -- extraneous expanded code. Also deal with validity checking.
7125 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
7126 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
7127 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
7130 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
7131 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
7134 if Nkind_In
(Parent
(N
), N_Constrained_Array_Definition
, N_Slice
) then
7135 Apply_Range_Check
(Ran
, Typ
);
7137 end Expand_N_Subtype_Indication
;
7139 ---------------------------
7140 -- Expand_N_Variant_Part --
7141 ---------------------------
7143 -- Note: this procedure no longer has any effect. It used to be that we
7144 -- would replace the choices in the last variant by a when others, and
7145 -- also expanded static predicates in variant choices here, but both of
7146 -- those activities were being done too early, since we can't check the
7147 -- choices until the statically predicated subtypes are frozen, which can
7148 -- happen as late as the free point of the record, and we can't change the
7149 -- last choice to an others before checking the choices, which is now done
7150 -- at the freeze point of the record.
7152 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
7155 end Expand_N_Variant_Part
;
7157 ---------------------------------
7158 -- Expand_Previous_Access_Type --
7159 ---------------------------------
7161 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
7162 Ptr_Typ
: Entity_Id
;
7165 -- Find all access types in the current scope whose designated type is
7166 -- Def_Id and build master renamings for them.
7168 Ptr_Typ
:= First_Entity
(Current_Scope
);
7169 while Present
(Ptr_Typ
) loop
7170 if Is_Access_Type
(Ptr_Typ
)
7171 and then Designated_Type
(Ptr_Typ
) = Def_Id
7172 and then No
(Master_Id
(Ptr_Typ
))
7174 -- Ensure that the designated type has a master
7176 Build_Master_Entity
(Def_Id
);
7178 -- Private and incomplete types complicate the insertion of master
7179 -- renamings because the access type may precede the full view of
7180 -- the designated type. For this reason, the master renamings are
7181 -- inserted relative to the designated type.
7183 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
7186 Next_Entity
(Ptr_Typ
);
7188 end Expand_Previous_Access_Type
;
7190 -----------------------------
7191 -- Expand_Record_Extension --
7192 -----------------------------
7194 -- Add a field _parent at the beginning of the record extension. This is
7195 -- used to implement inheritance. Here are some examples of expansion:
7197 -- 1. no discriminants
7198 -- type T2 is new T1 with null record;
7200 -- type T2 is new T1 with record
7204 -- 2. renamed discriminants
7205 -- type T2 (B, C : Int) is new T1 (A => B) with record
7206 -- _Parent : T1 (A => B);
7210 -- 3. inherited discriminants
7211 -- type T2 is new T1 with record -- discriminant A inherited
7212 -- _Parent : T1 (A);
7216 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
) is
7217 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7218 Loc
: constant Source_Ptr
:= Sloc
(Def
);
7219 Rec_Ext_Part
: Node_Id
:= Record_Extension_Part
(Def
);
7220 Par_Subtype
: Entity_Id
;
7221 Comp_List
: Node_Id
;
7222 Comp_Decl
: Node_Id
;
7225 List_Constr
: constant List_Id
:= New_List
;
7228 -- Expand_Record_Extension is called directly from the semantics, so
7229 -- we must check to see whether expansion is active before proceeding,
7230 -- because this affects the visibility of selected components in bodies
7233 if not Expander_Active
then
7237 -- This may be a derivation of an untagged private type whose full
7238 -- view is tagged, in which case the Derived_Type_Definition has no
7239 -- extension part. Build an empty one now.
7241 if No
(Rec_Ext_Part
) then
7243 Make_Record_Definition
(Loc
,
7245 Component_List
=> Empty
,
7246 Null_Present
=> True);
7248 Set_Record_Extension_Part
(Def
, Rec_Ext_Part
);
7249 Mark_Rewrite_Insertion
(Rec_Ext_Part
);
7252 Comp_List
:= Component_List
(Rec_Ext_Part
);
7254 Parent_N
:= Make_Defining_Identifier
(Loc
, Name_uParent
);
7256 -- If the derived type inherits its discriminants the type of the
7257 -- _parent field must be constrained by the inherited discriminants
7259 if Has_Discriminants
(T
)
7260 and then Nkind
(Indic
) /= N_Subtype_Indication
7261 and then not Is_Constrained
(Entity
(Indic
))
7263 D
:= First_Discriminant
(T
);
7264 while Present
(D
) loop
7265 Append_To
(List_Constr
, New_Occurrence_Of
(D
, Loc
));
7266 Next_Discriminant
(D
);
7271 Make_Subtype_Indication
(Loc
,
7272 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Indic
), Loc
),
7274 Make_Index_Or_Discriminant_Constraint
(Loc
,
7275 Constraints
=> List_Constr
)),
7278 -- Otherwise the original subtype_indication is just what is needed
7281 Par_Subtype
:= Process_Subtype
(New_Copy_Tree
(Indic
), Def
);
7284 Set_Parent_Subtype
(T
, Par_Subtype
);
7287 Make_Component_Declaration
(Loc
,
7288 Defining_Identifier
=> Parent_N
,
7289 Component_Definition
=>
7290 Make_Component_Definition
(Loc
,
7291 Aliased_Present
=> False,
7292 Subtype_Indication
=> New_Occurrence_Of
(Par_Subtype
, Loc
)));
7294 if Null_Present
(Rec_Ext_Part
) then
7295 Set_Component_List
(Rec_Ext_Part
,
7296 Make_Component_List
(Loc
,
7297 Component_Items
=> New_List
(Comp_Decl
),
7298 Variant_Part
=> Empty
,
7299 Null_Present
=> False));
7300 Set_Null_Present
(Rec_Ext_Part
, False);
7302 elsif Null_Present
(Comp_List
)
7303 or else Is_Empty_List
(Component_Items
(Comp_List
))
7305 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
7306 Set_Null_Present
(Comp_List
, False);
7309 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
7312 Analyze
(Comp_Decl
);
7313 end Expand_Record_Extension
;
7315 ------------------------
7316 -- Expand_Tagged_Root --
7317 ------------------------
7319 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
7320 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
7321 Comp_List
: Node_Id
;
7322 Comp_Decl
: Node_Id
;
7323 Sloc_N
: Source_Ptr
;
7326 if Null_Present
(Def
) then
7327 Set_Component_List
(Def
,
7328 Make_Component_List
(Sloc
(Def
),
7329 Component_Items
=> Empty_List
,
7330 Variant_Part
=> Empty
,
7331 Null_Present
=> True));
7334 Comp_List
:= Component_List
(Def
);
7336 if Null_Present
(Comp_List
)
7337 or else Is_Empty_List
(Component_Items
(Comp_List
))
7339 Sloc_N
:= Sloc
(Comp_List
);
7341 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
7345 Make_Component_Declaration
(Sloc_N
,
7346 Defining_Identifier
=> First_Tag_Component
(T
),
7347 Component_Definition
=>
7348 Make_Component_Definition
(Sloc_N
,
7349 Aliased_Present
=> False,
7350 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
7352 if Null_Present
(Comp_List
)
7353 or else Is_Empty_List
(Component_Items
(Comp_List
))
7355 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
7356 Set_Null_Present
(Comp_List
, False);
7359 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
7362 -- We don't Analyze the whole expansion because the tag component has
7363 -- already been analyzed previously. Here we just insure that the tree
7364 -- is coherent with the semantic decoration
7366 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
7369 when RE_Not_Available
=>
7371 end Expand_Tagged_Root
;
7373 ------------------------------
7374 -- Freeze_Stream_Operations --
7375 ------------------------------
7377 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
7378 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
7383 Stream_Op
: Entity_Id
;
7386 -- Primitive operations of tagged types are frozen when the dispatch
7387 -- table is constructed.
7389 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
7393 for J
in Names
'Range loop
7394 Stream_Op
:= TSS
(Typ
, Names
(J
));
7396 if Present
(Stream_Op
)
7397 and then Is_Subprogram
(Stream_Op
)
7398 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
7399 N_Subprogram_Declaration
7400 and then not Is_Frozen
(Stream_Op
)
7402 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
7405 end Freeze_Stream_Operations
;
7411 -- Full type declarations are expanded at the point at which the type is
7412 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
7413 -- declarations generated by the freezing (e.g. the procedure generated
7414 -- for initialization) are chained in the Actions field list of the freeze
7415 -- node using Append_Freeze_Actions.
7417 -- WARNING: This routine manages Ghost regions. Return statements must be
7418 -- replaced by gotos which jump to the end of the routine and restore the
7421 function Freeze_Type
(N
: Node_Id
) return Boolean is
7422 procedure Process_RACW_Types
(Typ
: Entity_Id
);
7423 -- Validate and generate stubs for all RACW types associated with type
7426 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
);
7427 -- Associate type Typ's Finalize_Address primitive with the finalization
7428 -- masters of pending access-to-Typ types.
7430 ------------------------
7431 -- Process_RACW_Types --
7432 ------------------------
7434 procedure Process_RACW_Types
(Typ
: Entity_Id
) is
7435 List
: constant Elist_Id
:= Access_Types_To_Process
(N
);
7437 Seen
: Boolean := False;
7440 if Present
(List
) then
7441 E
:= First_Elmt
(List
);
7442 while Present
(E
) loop
7443 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
7444 Validate_RACW_Primitives
(Node
(E
));
7452 -- If there are RACWs designating this type, make stubs now
7455 Remote_Types_Tagged_Full_View_Encountered
(Typ
);
7457 end Process_RACW_Types
;
7459 ----------------------------------
7460 -- Process_Pending_Access_Types --
7461 ----------------------------------
7463 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
) is
7467 -- Finalize_Address is not generated in CodePeer mode because the
7468 -- body contains address arithmetic. This processing is disabled.
7470 if CodePeer_Mode
then
7473 -- Certain itypes are generated for contexts that cannot allocate
7474 -- objects and should not set primitive Finalize_Address.
7476 elsif Is_Itype
(Typ
)
7477 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
7478 N_Explicit_Dereference
7482 -- When an access type is declared after the incomplete view of a
7483 -- Taft-amendment type, the access type is considered pending in
7484 -- case the full view of the Taft-amendment type is controlled. If
7485 -- this is indeed the case, associate the Finalize_Address routine
7486 -- of the full view with the finalization masters of all pending
7487 -- access types. This scenario applies to anonymous access types as
7490 elsif Needs_Finalization
(Typ
)
7491 and then Present
(Pending_Access_Types
(Typ
))
7493 E
:= First_Elmt
(Pending_Access_Types
(Typ
));
7494 while Present
(E
) loop
7497 -- Set_Finalize_Address
7498 -- (Ptr_Typ, <Typ>FD'Unrestricted_Access);
7500 Append_Freeze_Action
(Typ
,
7501 Make_Set_Finalize_Address_Call
7503 Ptr_Typ
=> Node
(E
)));
7508 end Process_Pending_Access_Types
;
7512 Def_Id
: constant Entity_Id
:= Entity
(N
);
7514 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
7515 -- Save the Ghost mode to restore on exit
7517 Result
: Boolean := False;
7519 -- Start of processing for Freeze_Type
7522 -- The type being frozen may be subject to pragma Ghost. Set the mode
7523 -- now to ensure that any nodes generated during freezing are properly
7526 Set_Ghost_Mode
(Def_Id
);
7528 -- Process any remote access-to-class-wide types designating the type
7531 Process_RACW_Types
(Def_Id
);
7533 -- Freeze processing for record types
7535 if Is_Record_Type
(Def_Id
) then
7536 if Ekind
(Def_Id
) = E_Record_Type
then
7537 Expand_Freeze_Record_Type
(N
);
7538 elsif Is_Class_Wide_Type
(Def_Id
) then
7539 Expand_Freeze_Class_Wide_Type
(N
);
7542 -- Freeze processing for array types
7544 elsif Is_Array_Type
(Def_Id
) then
7545 Expand_Freeze_Array_Type
(N
);
7547 -- Freeze processing for access types
7549 -- For pool-specific access types, find out the pool object used for
7550 -- this type, needs actual expansion of it in some cases. Here are the
7551 -- different cases :
7553 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
7554 -- ---> don't use any storage pool
7556 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
7558 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
7560 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7561 -- ---> Storage Pool is the specified one
7563 -- See GNAT Pool packages in the Run-Time for more details
7565 elsif Ekind_In
(Def_Id
, E_Access_Type
, E_General_Access_Type
) then
7567 Loc
: constant Source_Ptr
:= Sloc
(N
);
7568 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
7570 Freeze_Action_Typ
: Entity_Id
;
7571 Pool_Object
: Entity_Id
;
7576 -- Rep Clause "for Def_Id'Storage_Size use 0;"
7577 -- ---> don't use any storage pool
7579 if No_Pool_Assigned
(Def_Id
) then
7584 -- Rep Clause : for Def_Id'Storage_Size use Expr.
7586 -- Def_Id__Pool : Stack_Bounded_Pool
7587 -- (Expr, DT'Size, DT'Alignment);
7589 elsif Has_Storage_Size_Clause
(Def_Id
) then
7595 -- For unconstrained composite types we give a size of zero
7596 -- so that the pool knows that it needs a special algorithm
7597 -- for variable size object allocation.
7599 if Is_Composite_Type
(Desig_Type
)
7600 and then not Is_Constrained
(Desig_Type
)
7602 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
7603 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
7607 Make_Attribute_Reference
(Loc
,
7608 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7609 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
7612 Make_Attribute_Reference
(Loc
,
7613 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7614 Attribute_Name
=> Name_Alignment
);
7618 Make_Defining_Identifier
(Loc
,
7619 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
7621 -- We put the code associated with the pools in the entity
7622 -- that has the later freeze node, usually the access type
7623 -- but it can also be the designated_type; because the pool
7624 -- code requires both those types to be frozen
7626 if Is_Frozen
(Desig_Type
)
7627 and then (No
(Freeze_Node
(Desig_Type
))
7628 or else Analyzed
(Freeze_Node
(Desig_Type
)))
7630 Freeze_Action_Typ
:= Def_Id
;
7632 -- A Taft amendment type cannot get the freeze actions
7633 -- since the full view is not there.
7635 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
7636 and then No
(Full_View
(Desig_Type
))
7638 Freeze_Action_Typ
:= Def_Id
;
7641 Freeze_Action_Typ
:= Desig_Type
;
7644 Append_Freeze_Action
(Freeze_Action_Typ
,
7645 Make_Object_Declaration
(Loc
,
7646 Defining_Identifier
=> Pool_Object
,
7647 Object_Definition
=>
7648 Make_Subtype_Indication
(Loc
,
7651 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
7654 Make_Index_Or_Discriminant_Constraint
(Loc
,
7655 Constraints
=> New_List
(
7657 -- First discriminant is the Pool Size
7660 Storage_Size_Variable
(Def_Id
), Loc
),
7662 -- Second discriminant is the element size
7666 -- Third discriminant is the alignment
7671 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
7675 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7676 -- ---> Storage Pool is the specified one
7678 -- When compiling in Ada 2012 mode, ensure that the accessibility
7679 -- level of the subpool access type is not deeper than that of the
7680 -- pool_with_subpools.
7682 elsif Ada_Version
>= Ada_2012
7683 and then Present
(Associated_Storage_Pool
(Def_Id
))
7685 -- Omit this check for the case of a configurable run-time that
7686 -- does not provide package System.Storage_Pools.Subpools.
7688 and then RTE_Available
(RE_Root_Storage_Pool_With_Subpools
)
7691 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7692 Pool
: constant Entity_Id
:=
7693 Associated_Storage_Pool
(Def_Id
);
7694 RSPWS
: constant Entity_Id
:=
7695 RTE
(RE_Root_Storage_Pool_With_Subpools
);
7698 -- It is known that the accessibility level of the access
7699 -- type is deeper than that of the pool.
7701 if Type_Access_Level
(Def_Id
) > Object_Access_Level
(Pool
)
7702 and then not Accessibility_Checks_Suppressed
(Def_Id
)
7703 and then not Accessibility_Checks_Suppressed
(Pool
)
7705 -- Static case: the pool is known to be a descendant of
7706 -- Root_Storage_Pool_With_Subpools.
7708 if Is_Ancestor
(RSPWS
, Etype
(Pool
)) then
7710 ("??subpool access type has deeper accessibility "
7711 & "level than pool", Def_Id
);
7713 Append_Freeze_Action
(Def_Id
,
7714 Make_Raise_Program_Error
(Loc
,
7715 Reason
=> PE_Accessibility_Check_Failed
));
7717 -- Dynamic case: when the pool is of a class-wide type,
7718 -- it may or may not support subpools depending on the
7719 -- path of derivation. Generate:
7721 -- if Def_Id in RSPWS'Class then
7722 -- raise Program_Error;
7725 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
7726 Append_Freeze_Action
(Def_Id
,
7727 Make_If_Statement
(Loc
,
7730 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
7733 (Class_Wide_Type
(RSPWS
), Loc
)),
7735 Then_Statements
=> New_List
(
7736 Make_Raise_Program_Error
(Loc
,
7737 Reason
=> PE_Accessibility_Check_Failed
))));
7743 -- For access-to-controlled types (including class-wide types and
7744 -- Taft-amendment types, which potentially have controlled
7745 -- components), expand the list controller object that will store
7746 -- the dynamically allocated objects. Don't do this transformation
7747 -- for expander-generated access types, but do it for types that
7748 -- are the full view of types derived from other private types.
7749 -- Also suppress the list controller in the case of a designated
7750 -- type with convention Java, since this is used when binding to
7751 -- Java API specs, where there's no equivalent of a finalization
7752 -- list and we don't want to pull in the finalization support if
7755 if not Comes_From_Source
(Def_Id
)
7756 and then not Has_Private_Declaration
(Def_Id
)
7760 -- An exception is made for types defined in the run-time because
7761 -- Ada.Tags.Tag itself is such a type and cannot afford this
7762 -- unnecessary overhead that would generates a loop in the
7763 -- expansion scheme. Another exception is if Restrictions
7764 -- (No_Finalization) is active, since then we know nothing is
7767 elsif Restriction_Active
(No_Finalization
)
7768 or else In_Runtime
(Def_Id
)
7772 -- Create a finalization master for an access-to-controlled type
7773 -- or an access-to-incomplete type. It is assumed that the full
7774 -- view will be controlled.
7776 elsif Needs_Finalization
(Desig_Type
)
7777 or else (Is_Incomplete_Type
(Desig_Type
)
7778 and then No
(Full_View
(Desig_Type
)))
7780 Build_Finalization_Master
(Def_Id
);
7782 -- Create a finalization master when the designated type contains
7783 -- a private component. It is assumed that the full view will be
7786 elsif Has_Private_Component
(Desig_Type
) then
7787 Build_Finalization_Master
7789 For_Private
=> True,
7790 Context_Scope
=> Scope
(Def_Id
),
7791 Insertion_Node
=> Declaration_Node
(Desig_Type
));
7795 -- Freeze processing for enumeration types
7797 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
7799 -- We only have something to do if we have a non-standard
7800 -- representation (i.e. at least one literal whose pos value
7801 -- is not the same as its representation)
7803 if Has_Non_Standard_Rep
(Def_Id
) then
7804 Expand_Freeze_Enumeration_Type
(N
);
7807 -- Private types that are completed by a derivation from a private
7808 -- type have an internally generated full view, that needs to be
7809 -- frozen. This must be done explicitly because the two views share
7810 -- the freeze node, and the underlying full view is not visible when
7811 -- the freeze node is analyzed.
7813 elsif Is_Private_Type
(Def_Id
)
7814 and then Is_Derived_Type
(Def_Id
)
7815 and then Present
(Full_View
(Def_Id
))
7816 and then Is_Itype
(Full_View
(Def_Id
))
7817 and then Has_Private_Declaration
(Full_View
(Def_Id
))
7818 and then Freeze_Node
(Full_View
(Def_Id
)) = N
7820 Set_Entity
(N
, Full_View
(Def_Id
));
7821 Result
:= Freeze_Type
(N
);
7822 Set_Entity
(N
, Def_Id
);
7824 -- All other types require no expander action. There are such cases
7825 -- (e.g. task types and protected types). In such cases, the freeze
7826 -- nodes are there for use by Gigi.
7830 -- Complete the initialization of all pending access types' finalization
7831 -- masters now that the designated type has been is frozen and primitive
7832 -- Finalize_Address generated.
7834 Process_Pending_Access_Types
(Def_Id
);
7835 Freeze_Stream_Operations
(N
, Def_Id
);
7837 -- Generate the [spec and] body of the procedure tasked with the runtime
7838 -- verification of pragma Default_Initial_Condition's expression.
7840 if Has_DIC
(Def_Id
) then
7841 Build_DIC_Procedure_Body
(Def_Id
, For_Freeze
=> True);
7844 -- Generate the [spec and] body of the invariant procedure tasked with
7845 -- the runtime verification of all invariants that pertain to the type.
7846 -- This includes invariants on the partial and full view, inherited
7847 -- class-wide invariants from parent types or interfaces, and invariants
7848 -- on array elements or record components.
7850 if Is_Interface
(Def_Id
) then
7852 -- Interfaces are treated as the partial view of a private type in
7853 -- order to achieve uniformity with the general case. As a result, an
7854 -- interface receives only a "partial" invariant procedure which is
7857 if Has_Own_Invariants
(Def_Id
) then
7858 Build_Invariant_Procedure_Body
7860 Partial_Invariant
=> Is_Interface
(Def_Id
));
7863 -- Non-interface types
7865 -- Do not generate invariant procedure within other assertion
7866 -- subprograms, which may involve local declarations of local
7867 -- subtypes to which these checks do not apply.
7869 elsif Has_Invariants
(Def_Id
) then
7870 if Within_Internal_Subprogram
7871 or else (Ekind
(Current_Scope
) = E_Function
7872 and then Is_Predicate_Function
(Current_Scope
))
7876 Build_Invariant_Procedure_Body
(Def_Id
);
7880 Restore_Ghost_Mode
(Saved_GM
);
7885 when RE_Not_Available
=>
7886 Restore_Ghost_Mode
(Saved_GM
);
7891 -------------------------
7892 -- Get_Simple_Init_Val --
7893 -------------------------
7895 function Get_Simple_Init_Val
7898 Size
: Uint
:= No_Uint
) return Node_Id
7900 Loc
: constant Source_Ptr
:= Sloc
(N
);
7906 -- This is the size to be used for computation of the appropriate
7907 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
7909 IV_Attribute
: constant Boolean :=
7910 Nkind
(N
) = N_Attribute_Reference
7911 and then Attribute_Name
(N
) = Name_Invalid_Value
;
7915 -- These are the values computed by the procedure Check_Subtype_Bounds
7917 procedure Check_Subtype_Bounds
;
7918 -- This procedure examines the subtype T, and its ancestor subtypes and
7919 -- derived types to determine the best known information about the
7920 -- bounds of the subtype. After the call Lo_Bound is set either to
7921 -- No_Uint if no information can be determined, or to a value which
7922 -- represents a known low bound, i.e. a valid value of the subtype can
7923 -- not be less than this value. Hi_Bound is similarly set to a known
7924 -- high bound (valid value cannot be greater than this).
7926 --------------------------
7927 -- Check_Subtype_Bounds --
7928 --------------------------
7930 procedure Check_Subtype_Bounds
is
7939 Lo_Bound
:= No_Uint
;
7940 Hi_Bound
:= No_Uint
;
7942 -- Loop to climb ancestor subtypes and derived types
7946 if not Is_Discrete_Type
(ST1
) then
7950 Lo
:= Type_Low_Bound
(ST1
);
7951 Hi
:= Type_High_Bound
(ST1
);
7953 if Compile_Time_Known_Value
(Lo
) then
7954 Loval
:= Expr_Value
(Lo
);
7956 if Lo_Bound
= No_Uint
or else Lo_Bound
< Loval
then
7961 if Compile_Time_Known_Value
(Hi
) then
7962 Hival
:= Expr_Value
(Hi
);
7964 if Hi_Bound
= No_Uint
or else Hi_Bound
> Hival
then
7969 ST2
:= Ancestor_Subtype
(ST1
);
7975 exit when ST1
= ST2
;
7978 end Check_Subtype_Bounds
;
7980 -- Start of processing for Get_Simple_Init_Val
7983 -- For a private type, we should always have an underlying type (because
7984 -- this was already checked in Needs_Simple_Initialization). What we do
7985 -- is to get the value for the underlying type and then do an unchecked
7986 -- conversion to the private type.
7988 if Is_Private_Type
(T
) then
7989 Val
:= Get_Simple_Init_Val
(Underlying_Type
(T
), N
, Size
);
7991 -- A special case, if the underlying value is null, then qualify it
7992 -- with the underlying type, so that the null is properly typed.
7993 -- Similarly, if it is an aggregate it must be qualified, because an
7994 -- unchecked conversion does not provide a context for it.
7996 if Nkind_In
(Val
, N_Null
, N_Aggregate
) then
7998 Make_Qualified_Expression
(Loc
,
8000 New_Occurrence_Of
(Underlying_Type
(T
), Loc
),
8004 Result
:= Unchecked_Convert_To
(T
, Val
);
8006 -- Don't truncate result (important for Initialize/Normalize_Scalars)
8008 if Nkind
(Result
) = N_Unchecked_Type_Conversion
8009 and then Is_Scalar_Type
(Underlying_Type
(T
))
8011 Set_No_Truncation
(Result
);
8016 -- Scalars with Default_Value aspect. The first subtype may now be
8017 -- private, so retrieve value from underlying type.
8019 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
8020 if Is_Private_Type
(First_Subtype
(T
)) then
8021 return Unchecked_Convert_To
(T
,
8022 Default_Aspect_Value
(Full_View
(First_Subtype
(T
))));
8025 Convert_To
(T
, Default_Aspect_Value
(First_Subtype
(T
)));
8028 -- Otherwise, for scalars, we must have normalize/initialize scalars
8029 -- case, or if the node N is an 'Invalid_Value attribute node.
8031 elsif Is_Scalar_Type
(T
) then
8032 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
8034 -- Compute size of object. If it is given by the caller, we can use
8035 -- it directly, otherwise we use Esize (T) as an estimate. As far as
8036 -- we know this covers all cases correctly.
8038 if Size
= No_Uint
or else Size
<= Uint_0
then
8039 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(T
));
8041 Size_To_Use
:= Size
;
8044 -- Maximum size to use is 64 bits, since we will create values of
8045 -- type Unsigned_64 and the range must fit this type.
8047 if Size_To_Use
/= No_Uint
and then Size_To_Use
> Uint_64
then
8048 Size_To_Use
:= Uint_64
;
8051 -- Check known bounds of subtype
8053 Check_Subtype_Bounds
;
8055 -- Processing for Normalize_Scalars case
8057 if Normalize_Scalars
and then not IV_Attribute
then
8059 -- If zero is invalid, it is a convenient value to use that is
8060 -- for sure an appropriate invalid value in all situations.
8062 if Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8063 Val
:= Make_Integer_Literal
(Loc
, 0);
8065 -- Cases where all one bits is the appropriate invalid value
8067 -- For modular types, all 1 bits is either invalid or valid. If
8068 -- it is valid, then there is nothing that can be done since there
8069 -- are no invalid values (we ruled out zero already).
8071 -- For signed integer types that have no negative values, either
8072 -- there is room for negative values, or there is not. If there
8073 -- is, then all 1-bits may be interpreted as minus one, which is
8074 -- certainly invalid. Alternatively it is treated as the largest
8075 -- positive value, in which case the observation for modular types
8078 -- For float types, all 1-bits is a NaN (not a number), which is
8079 -- certainly an appropriately invalid value.
8081 elsif Is_Unsigned_Type
(T
)
8082 or else Is_Floating_Point_Type
(T
)
8083 or else Is_Enumeration_Type
(T
)
8085 Val
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
8087 -- Resolve as Unsigned_64, because the largest number we can
8088 -- generate is out of range of universal integer.
8090 Analyze_And_Resolve
(Val
, RTE
(RE_Unsigned_64
));
8092 -- Case of signed types
8096 Signed_Size
: constant Uint
:=
8097 UI_Min
(Uint_63
, Size_To_Use
- 1);
8100 -- Normally we like to use the most negative number. The one
8101 -- exception is when this number is in the known subtype
8102 -- range and the largest positive number is not in the known
8105 -- For this exceptional case, use largest positive value
8107 if Lo_Bound
/= No_Uint
and then Hi_Bound
/= No_Uint
8108 and then Lo_Bound
<= (-(2 ** Signed_Size
))
8109 and then Hi_Bound
< 2 ** Signed_Size
8111 Val
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
8113 -- Normal case of largest negative value
8116 Val
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
8121 -- Here for Initialize_Scalars case (or Invalid_Value attribute used)
8124 -- For float types, use float values from System.Scalar_Values
8126 if Is_Floating_Point_Type
(T
) then
8127 if Root_Type
(T
) = Standard_Short_Float
then
8128 Val_RE
:= RE_IS_Isf
;
8129 elsif Root_Type
(T
) = Standard_Float
then
8130 Val_RE
:= RE_IS_Ifl
;
8131 elsif Root_Type
(T
) = Standard_Long_Float
then
8132 Val_RE
:= RE_IS_Ilf
;
8133 else pragma Assert
(Root_Type
(T
) = Standard_Long_Long_Float
);
8134 Val_RE
:= RE_IS_Ill
;
8137 -- If zero is invalid, use zero values from System.Scalar_Values
8139 elsif Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8140 if Size_To_Use
<= 8 then
8141 Val_RE
:= RE_IS_Iz1
;
8142 elsif Size_To_Use
<= 16 then
8143 Val_RE
:= RE_IS_Iz2
;
8144 elsif Size_To_Use
<= 32 then
8145 Val_RE
:= RE_IS_Iz4
;
8147 Val_RE
:= RE_IS_Iz8
;
8150 -- For unsigned, use unsigned values from System.Scalar_Values
8152 elsif Is_Unsigned_Type
(T
) then
8153 if Size_To_Use
<= 8 then
8154 Val_RE
:= RE_IS_Iu1
;
8155 elsif Size_To_Use
<= 16 then
8156 Val_RE
:= RE_IS_Iu2
;
8157 elsif Size_To_Use
<= 32 then
8158 Val_RE
:= RE_IS_Iu4
;
8160 Val_RE
:= RE_IS_Iu8
;
8163 -- For signed, use signed values from System.Scalar_Values
8166 if Size_To_Use
<= 8 then
8167 Val_RE
:= RE_IS_Is1
;
8168 elsif Size_To_Use
<= 16 then
8169 Val_RE
:= RE_IS_Is2
;
8170 elsif Size_To_Use
<= 32 then
8171 Val_RE
:= RE_IS_Is4
;
8173 Val_RE
:= RE_IS_Is8
;
8177 Val
:= New_Occurrence_Of
(RTE
(Val_RE
), Loc
);
8180 -- The final expression is obtained by doing an unchecked conversion
8181 -- of this result to the base type of the required subtype. Use the
8182 -- base type to prevent the unchecked conversion from chopping bits,
8183 -- and then we set Kill_Range_Check to preserve the "bad" value.
8185 Result
:= Unchecked_Convert_To
(Base_Type
(T
), Val
);
8187 -- Ensure result is not truncated, since we want the "bad" bits, and
8188 -- also kill range check on result.
8190 if Nkind
(Result
) = N_Unchecked_Type_Conversion
then
8191 Set_No_Truncation
(Result
);
8192 Set_Kill_Range_Check
(Result
, True);
8197 -- String or Wide_[Wide]_String (must have Initialize_Scalars set)
8199 elsif Is_Standard_String_Type
(T
) then
8200 pragma Assert
(Init_Or_Norm_Scalars
);
8203 Make_Aggregate
(Loc
,
8204 Component_Associations
=> New_List
(
8205 Make_Component_Association
(Loc
,
8206 Choices
=> New_List
(
8207 Make_Others_Choice
(Loc
)),
8210 (Component_Type
(T
), N
, Esize
(Root_Type
(T
))))));
8212 -- Access type is initialized to null
8214 elsif Is_Access_Type
(T
) then
8215 return Make_Null
(Loc
);
8217 -- No other possibilities should arise, since we should only be calling
8218 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8219 -- indicating one of the above cases held.
8222 raise Program_Error
;
8226 when RE_Not_Available
=>
8228 end Get_Simple_Init_Val
;
8230 ------------------------------
8231 -- Has_New_Non_Standard_Rep --
8232 ------------------------------
8234 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
8236 if not Is_Derived_Type
(T
) then
8237 return Has_Non_Standard_Rep
(T
)
8238 or else Has_Non_Standard_Rep
(Root_Type
(T
));
8240 -- If Has_Non_Standard_Rep is not set on the derived type, the
8241 -- representation is fully inherited.
8243 elsif not Has_Non_Standard_Rep
(T
) then
8247 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
8249 -- May need a more precise check here: the First_Rep_Item may be a
8250 -- stream attribute, which does not affect the representation of the
8254 end Has_New_Non_Standard_Rep
;
8256 ----------------------
8257 -- Inline_Init_Proc --
8258 ----------------------
8260 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean is
8262 -- The initialization proc of protected records is not worth inlining.
8263 -- In addition, when compiled for another unit for inlining purposes,
8264 -- it may make reference to entities that have not been elaborated yet.
8265 -- The initialization proc of records that need finalization contains
8266 -- a nested clean-up procedure that makes it impractical to inline as
8267 -- well, except for simple controlled types themselves. And similar
8268 -- considerations apply to task types.
8270 if Is_Concurrent_Type
(Typ
) then
8273 elsif Needs_Finalization
(Typ
) and then not Is_Controlled
(Typ
) then
8276 elsif Has_Task
(Typ
) then
8282 end Inline_Init_Proc
;
8288 function In_Runtime
(E
: Entity_Id
) return Boolean is
8293 while Scope
(S1
) /= Standard_Standard
loop
8297 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
8300 ----------------------------
8301 -- Initialization_Warning --
8302 ----------------------------
8304 procedure Initialization_Warning
(E
: Entity_Id
) is
8305 Warning_Needed
: Boolean;
8308 Warning_Needed
:= False;
8310 if Ekind
(Current_Scope
) = E_Package
8311 and then Static_Elaboration_Desired
(Current_Scope
)
8314 if Is_Record_Type
(E
) then
8315 if Has_Discriminants
(E
)
8316 or else Is_Limited_Type
(E
)
8317 or else Has_Non_Standard_Rep
(E
)
8319 Warning_Needed
:= True;
8322 -- Verify that at least one component has an initialization
8323 -- expression. No need for a warning on a type if all its
8324 -- components have no initialization.
8330 Comp
:= First_Component
(E
);
8331 while Present
(Comp
) loop
8332 if Ekind
(Comp
) = E_Discriminant
8334 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
8335 and then Present
(Expression
(Parent
(Comp
))))
8337 Warning_Needed
:= True;
8341 Next_Component
(Comp
);
8346 if Warning_Needed
then
8348 ("Objects of the type cannot be initialized statically "
8349 & "by default??", Parent
(E
));
8354 Error_Msg_N
("Object cannot be initialized statically??", E
);
8357 end Initialization_Warning
;
8363 function Init_Formals
(Typ
: Entity_Id
) return List_Id
is
8364 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8368 -- First parameter is always _Init : in out typ. Note that we need this
8369 -- to be in/out because in the case of the task record value, there
8370 -- are default record fields (_Priority, _Size, -Task_Info) that may
8371 -- be referenced in the generated initialization routine.
8373 Formals
:= New_List
(
8374 Make_Parameter_Specification
(Loc
,
8375 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
8377 Out_Present
=> True,
8378 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8380 -- For task record value, or type that contains tasks, add two more
8381 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8382 -- We also add these parameters for the task record type case.
8385 or else (Is_Record_Type
(Typ
) and then Is_Task_Record_Type
(Typ
))
8388 Make_Parameter_Specification
(Loc
,
8389 Defining_Identifier
=>
8390 Make_Defining_Identifier
(Loc
, Name_uMaster
),
8392 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
)));
8394 -- Add _Chain (not done for sequential elaboration policy, see
8395 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
8397 if Partition_Elaboration_Policy
/= 'S' then
8399 Make_Parameter_Specification
(Loc
,
8400 Defining_Identifier
=>
8401 Make_Defining_Identifier
(Loc
, Name_uChain
),
8403 Out_Present
=> True,
8405 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
8409 Make_Parameter_Specification
(Loc
,
8410 Defining_Identifier
=>
8411 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
8413 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
8419 when RE_Not_Available
=>
8423 -------------------------
8424 -- Init_Secondary_Tags --
8425 -------------------------
8427 procedure Init_Secondary_Tags
8430 Init_Tags_List
: List_Id
;
8431 Stmts_List
: List_Id
;
8432 Fixed_Comps
: Boolean := True;
8433 Variable_Comps
: Boolean := True)
8435 Loc
: constant Source_Ptr
:= Sloc
(Target
);
8437 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
8438 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8440 procedure Initialize_Tag
8443 Tag_Comp
: Entity_Id
;
8444 Iface_Tag
: Node_Id
);
8445 -- Initialize the tag of the secondary dispatch table of Typ associated
8446 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8447 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
8448 -- of Typ CPP tagged type we generate code to inherit the contents of
8449 -- the dispatch table directly from the ancestor.
8451 --------------------
8452 -- Initialize_Tag --
8453 --------------------
8455 procedure Initialize_Tag
8458 Tag_Comp
: Entity_Id
;
8459 Iface_Tag
: Node_Id
)
8461 Comp_Typ
: Entity_Id
;
8462 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
8465 -- Initialize pointer to secondary DT associated with the interface
8467 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8468 Append_To
(Init_Tags_List
,
8469 Make_Assignment_Statement
(Loc
,
8471 Make_Selected_Component
(Loc
,
8472 Prefix
=> New_Copy_Tree
(Target
),
8473 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8475 New_Occurrence_Of
(Iface_Tag
, Loc
)));
8478 Comp_Typ
:= Scope
(Tag_Comp
);
8480 -- Initialize the entries of the table of interfaces. We generate a
8481 -- different call when the parent of the type has variable size
8484 if Comp_Typ
/= Etype
(Comp_Typ
)
8485 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
8486 and then Chars
(Tag_Comp
) /= Name_uTag
8488 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
8490 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
8491 -- configurable run-time environment.
8493 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
8495 ("variable size record with interface types", Typ
);
8500 -- Set_Dynamic_Offset_To_Top
8502 -- Prim_T => Typ'Tag,
8503 -- Interface_T => Iface'Tag,
8504 -- Offset_Value => n,
8505 -- Offset_Func => Fn'Address)
8507 Append_To
(Stmts_List
,
8508 Make_Procedure_Call_Statement
(Loc
,
8510 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
8511 Parameter_Associations
=> New_List
(
8512 Make_Attribute_Reference
(Loc
,
8513 Prefix
=> New_Copy_Tree
(Target
),
8514 Attribute_Name
=> Name_Address
),
8516 Unchecked_Convert_To
(RTE
(RE_Tag
),
8518 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)),
8520 Unchecked_Convert_To
(RTE
(RE_Tag
),
8522 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
8525 Unchecked_Convert_To
8526 (RTE
(RE_Storage_Offset
),
8528 Make_Attribute_Reference
(Loc
,
8530 Make_Selected_Component
(Loc
,
8531 Prefix
=> New_Copy_Tree
(Target
),
8533 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8534 Attribute_Name
=> Name_Position
))),
8536 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
8537 Make_Attribute_Reference
(Loc
,
8538 Prefix
=> New_Occurrence_Of
8539 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
8540 Attribute_Name
=> Name_Address
)))));
8542 -- In this case the next component stores the value of the offset
8545 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
8546 pragma Assert
(Present
(Offset_To_Top_Comp
));
8548 Append_To
(Init_Tags_List
,
8549 Make_Assignment_Statement
(Loc
,
8551 Make_Selected_Component
(Loc
,
8552 Prefix
=> New_Copy_Tree
(Target
),
8554 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
8558 Make_Attribute_Reference
(Loc
,
8560 Make_Selected_Component
(Loc
,
8561 Prefix
=> New_Copy_Tree
(Target
),
8562 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8563 Attribute_Name
=> Name_Position
))));
8565 -- Normal case: No discriminants in the parent type
8568 -- Don't need to set any value if the offset-to-top field is
8569 -- statically set or if this interface shares the primary
8572 if not Building_Static_Secondary_DT
(Typ
)
8573 and then not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True)
8575 Append_To
(Stmts_List
,
8576 Build_Set_Static_Offset_To_Top
(Loc
,
8577 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
8579 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8581 Make_Attribute_Reference
(Loc
,
8583 Make_Selected_Component
(Loc
,
8584 Prefix
=> New_Copy_Tree
(Target
),
8586 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8587 Attribute_Name
=> Name_Position
)))));
8591 -- Register_Interface_Offset
8592 -- (Prim_T => Typ'Tag,
8593 -- Interface_T => Iface'Tag,
8594 -- Is_Constant => True,
8595 -- Offset_Value => n,
8596 -- Offset_Func => null);
8598 if not Building_Static_Secondary_DT
(Typ
)
8599 and then RTE_Available
(RE_Register_Interface_Offset
)
8601 Append_To
(Stmts_List
,
8602 Make_Procedure_Call_Statement
(Loc
,
8605 (RTE
(RE_Register_Interface_Offset
), Loc
),
8606 Parameter_Associations
=> New_List
(
8607 Unchecked_Convert_To
(RTE
(RE_Tag
),
8609 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)),
8611 Unchecked_Convert_To
(RTE
(RE_Tag
),
8613 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
8615 New_Occurrence_Of
(Standard_True
, Loc
),
8617 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8619 Make_Attribute_Reference
(Loc
,
8621 Make_Selected_Component
(Loc
,
8622 Prefix
=> New_Copy_Tree
(Target
),
8624 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8625 Attribute_Name
=> Name_Position
))),
8634 Full_Typ
: Entity_Id
;
8635 Ifaces_List
: Elist_Id
;
8636 Ifaces_Comp_List
: Elist_Id
;
8637 Ifaces_Tag_List
: Elist_Id
;
8638 Iface_Elmt
: Elmt_Id
;
8639 Iface_Comp_Elmt
: Elmt_Id
;
8640 Iface_Tag_Elmt
: Elmt_Id
;
8642 In_Variable_Pos
: Boolean;
8644 -- Start of processing for Init_Secondary_Tags
8647 -- Handle private types
8649 if Present
(Full_View
(Typ
)) then
8650 Full_Typ
:= Full_View
(Typ
);
8655 Collect_Interfaces_Info
8656 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
8658 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8659 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
8660 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
8661 while Present
(Iface_Elmt
) loop
8662 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
8664 -- Check if parent of record type has variable size components
8666 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
8667 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
8669 -- If we are compiling under the CPP full ABI compatibility mode and
8670 -- the ancestor is a CPP_Pragma tagged type then we generate code to
8671 -- initialize the secondary tag components from tags that reference
8672 -- secondary tables filled with copy of parent slots.
8674 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
8676 -- Reject interface components located at variable offset in
8677 -- C++ derivations. This is currently unsupported.
8679 if not Fixed_Comps
and then In_Variable_Pos
then
8681 -- Locate the first dynamic component of the record. Done to
8682 -- improve the text of the warning.
8686 Comp_Typ
: Entity_Id
;
8689 Comp
:= First_Entity
(Typ
);
8690 while Present
(Comp
) loop
8691 Comp_Typ
:= Etype
(Comp
);
8693 if Ekind
(Comp
) /= E_Discriminant
8694 and then not Is_Tag
(Comp
)
8697 (Is_Record_Type
(Comp_Typ
)
8699 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
8701 (Is_Array_Type
(Comp_Typ
)
8702 and then Is_Variable_Size_Array
(Comp_Typ
));
8708 pragma Assert
(Present
(Comp
));
8709 Error_Msg_Node_2
:= Comp
;
8711 ("parent type & with dynamic component & cannot be parent"
8712 & " of 'C'P'P derivation if new interfaces are present",
8713 Typ
, Scope
(Original_Record_Component
(Comp
)));
8716 Sloc
(Scope
(Original_Record_Component
(Comp
)));
8718 ("type derived from 'C'P'P type & defined #",
8719 Typ
, Scope
(Original_Record_Component
(Comp
)));
8721 -- Avoid duplicated warnings
8726 -- Initialize secondary tags
8731 Iface
=> Node
(Iface_Elmt
),
8732 Tag_Comp
=> Tag_Comp
,
8733 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
8736 -- Otherwise generate code to initialize the tag
8739 if (In_Variable_Pos
and then Variable_Comps
)
8740 or else (not In_Variable_Pos
and then Fixed_Comps
)
8744 Iface
=> Node
(Iface_Elmt
),
8745 Tag_Comp
=> Tag_Comp
,
8746 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
8750 Next_Elmt
(Iface_Elmt
);
8751 Next_Elmt
(Iface_Comp_Elmt
);
8752 Next_Elmt
(Iface_Tag_Elmt
);
8754 end Init_Secondary_Tags
;
8756 ------------------------
8757 -- Is_User_Defined_Eq --
8758 ------------------------
8760 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean is
8762 return Chars
(Prim
) = Name_Op_Eq
8763 and then Etype
(First_Formal
(Prim
)) =
8764 Etype
(Next_Formal
(First_Formal
(Prim
)))
8765 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
;
8766 end Is_User_Defined_Equality
;
8768 ----------------------------------------
8769 -- Make_Controlling_Function_Wrappers --
8770 ----------------------------------------
8772 procedure Make_Controlling_Function_Wrappers
8773 (Tag_Typ
: Entity_Id
;
8774 Decl_List
: out List_Id
;
8775 Body_List
: out List_Id
)
8777 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
8778 Prim_Elmt
: Elmt_Id
;
8780 Actual_List
: List_Id
;
8781 Formal_List
: List_Id
;
8783 Par_Formal
: Entity_Id
;
8784 Formal_Node
: Node_Id
;
8785 Func_Body
: Node_Id
;
8786 Func_Decl
: Node_Id
;
8787 Func_Spec
: Node_Id
;
8788 Return_Stmt
: Node_Id
;
8791 Decl_List
:= New_List
;
8792 Body_List
:= New_List
;
8794 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
8795 while Present
(Prim_Elmt
) loop
8796 Subp
:= Node
(Prim_Elmt
);
8798 -- If a primitive function with a controlling result of the type has
8799 -- not been overridden by the user, then we must create a wrapper
8800 -- function here that effectively overrides it and invokes the
8801 -- (non-abstract) parent function. This can only occur for a null
8802 -- extension. Note that functions with anonymous controlling access
8803 -- results don't qualify and must be overridden. We also exclude
8804 -- Input attributes, since each type will have its own version of
8805 -- Input constructed by the expander. The test for Comes_From_Source
8806 -- is needed to distinguish inherited operations from renamings
8807 -- (which also have Alias set). We exclude internal entities with
8808 -- Interface_Alias to avoid generating duplicated wrappers since
8809 -- the primitive which covers the interface is also available in
8810 -- the list of primitive operations.
8812 -- The function may be abstract, or require_Overriding may be set
8813 -- for it, because tests for null extensions may already have reset
8814 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
8815 -- set, functions that need wrappers are recognized by having an
8816 -- alias that returns the parent type.
8818 if Comes_From_Source
(Subp
)
8819 or else No
(Alias
(Subp
))
8820 or else Present
(Interface_Alias
(Subp
))
8821 or else Ekind
(Subp
) /= E_Function
8822 or else not Has_Controlling_Result
(Subp
)
8823 or else Is_Access_Type
(Etype
(Subp
))
8824 or else Is_Abstract_Subprogram
(Alias
(Subp
))
8825 or else Is_TSS
(Subp
, TSS_Stream_Input
)
8829 elsif Is_Abstract_Subprogram
(Subp
)
8830 or else Requires_Overriding
(Subp
)
8832 (Is_Null_Extension
(Etype
(Subp
))
8833 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
8835 Formal_List
:= No_List
;
8836 Formal
:= First_Formal
(Subp
);
8838 if Present
(Formal
) then
8839 Formal_List
:= New_List
;
8841 while Present
(Formal
) loop
8843 (Make_Parameter_Specification
8845 Defining_Identifier
=>
8846 Make_Defining_Identifier
(Sloc
(Formal
),
8847 Chars
=> Chars
(Formal
)),
8848 In_Present
=> In_Present
(Parent
(Formal
)),
8849 Out_Present
=> Out_Present
(Parent
(Formal
)),
8850 Null_Exclusion_Present
=>
8851 Null_Exclusion_Present
(Parent
(Formal
)),
8853 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8855 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
8858 Next_Formal
(Formal
);
8863 Make_Function_Specification
(Loc
,
8864 Defining_Unit_Name
=>
8865 Make_Defining_Identifier
(Loc
,
8866 Chars
=> Chars
(Subp
)),
8867 Parameter_Specifications
=> Formal_List
,
8868 Result_Definition
=>
8869 New_Occurrence_Of
(Etype
(Subp
), Loc
));
8871 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Func_Spec
);
8872 Append_To
(Decl_List
, Func_Decl
);
8874 -- Build a wrapper body that calls the parent function. The body
8875 -- contains a single return statement that returns an extension
8876 -- aggregate whose ancestor part is a call to the parent function,
8877 -- passing the formals as actuals (with any controlling arguments
8878 -- converted to the types of the corresponding formals of the
8879 -- parent function, which might be anonymous access types), and
8880 -- having a null extension.
8882 Formal
:= First_Formal
(Subp
);
8883 Par_Formal
:= First_Formal
(Alias
(Subp
));
8884 Formal_Node
:= First
(Formal_List
);
8886 if Present
(Formal
) then
8887 Actual_List
:= New_List
;
8889 Actual_List
:= No_List
;
8892 while Present
(Formal
) loop
8893 if Is_Controlling_Formal
(Formal
) then
8894 Append_To
(Actual_List
,
8895 Make_Type_Conversion
(Loc
,
8897 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
8900 (Defining_Identifier
(Formal_Node
), Loc
)));
8905 (Defining_Identifier
(Formal_Node
), Loc
));
8908 Next_Formal
(Formal
);
8909 Next_Formal
(Par_Formal
);
8914 Make_Simple_Return_Statement
(Loc
,
8916 Make_Extension_Aggregate
(Loc
,
8918 Make_Function_Call
(Loc
,
8920 New_Occurrence_Of
(Alias
(Subp
), Loc
),
8921 Parameter_Associations
=> Actual_List
),
8922 Null_Record_Present
=> True));
8925 Make_Subprogram_Body
(Loc
,
8926 Specification
=> New_Copy_Tree
(Func_Spec
),
8927 Declarations
=> Empty_List
,
8928 Handled_Statement_Sequence
=>
8929 Make_Handled_Sequence_Of_Statements
(Loc
,
8930 Statements
=> New_List
(Return_Stmt
)));
8932 Set_Defining_Unit_Name
8933 (Specification
(Func_Body
),
8934 Make_Defining_Identifier
(Loc
, Chars
(Subp
)));
8936 Append_To
(Body_List
, Func_Body
);
8938 -- Replace the inherited function with the wrapper function in the
8939 -- primitive operations list. We add the minimum decoration needed
8940 -- to override interface primitives.
8942 Set_Ekind
(Defining_Unit_Name
(Func_Spec
), E_Function
);
8944 Override_Dispatching_Operation
8945 (Tag_Typ
, Subp
, New_Op
=> Defining_Unit_Name
(Func_Spec
),
8946 Is_Wrapper
=> True);
8950 Next_Elmt
(Prim_Elmt
);
8952 end Make_Controlling_Function_Wrappers
;
8958 function Make_Eq_Body
8960 Eq_Name
: Name_Id
) return Node_Id
8962 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
8964 Def
: constant Node_Id
:= Parent
(Typ
);
8965 Stmts
: constant List_Id
:= New_List
;
8966 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
8967 Comps
: Node_Id
:= Empty
;
8968 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
8972 Predef_Spec_Or_Body
(Loc
,
8975 Profile
=> New_List
(
8976 Make_Parameter_Specification
(Loc
,
8977 Defining_Identifier
=>
8978 Make_Defining_Identifier
(Loc
, Name_X
),
8979 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
8981 Make_Parameter_Specification
(Loc
,
8982 Defining_Identifier
=>
8983 Make_Defining_Identifier
(Loc
, Name_Y
),
8984 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8986 Ret_Type
=> Standard_Boolean
,
8989 if Variant_Case
then
8990 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
8991 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
8994 if Present
(Typ_Def
) then
8995 Comps
:= Component_List
(Typ_Def
);
8999 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
9002 if Variant_Case
then
9004 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
9005 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
9007 Make_Simple_Return_Statement
(Loc
,
9008 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9012 Make_Simple_Return_Statement
(Loc
,
9014 Expand_Record_Equality
9017 Lhs
=> Make_Identifier
(Loc
, Name_X
),
9018 Rhs
=> Make_Identifier
(Loc
, Name_Y
),
9019 Bodies
=> Declarations
(Decl
))));
9022 Set_Handled_Statement_Sequence
9023 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9031 -- <Make_Eq_If shared components>
9034 -- when V1 => <Make_Eq_Case> on subcomponents
9036 -- when Vn => <Make_Eq_Case> on subcomponents
9039 function Make_Eq_Case
9042 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
9044 Loc
: constant Source_Ptr
:= Sloc
(E
);
9045 Result
: constant List_Id
:= New_List
;
9049 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
9050 -- Given the discriminant that controls a given variant of an unchecked
9051 -- union, find the formal of the equality function that carries the
9052 -- inferred value of the discriminant.
9054 function External_Name
(E
: Entity_Id
) return Name_Id
;
9055 -- The value of a given discriminant is conveyed in the corresponding
9056 -- formal parameter of the equality routine. The name of this formal
9057 -- parameter carries a one-character suffix which is removed here.
9059 --------------------------
9060 -- Corresponding_Formal --
9061 --------------------------
9063 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
9064 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
9068 Elm
:= First_Elmt
(Discrs
);
9069 while Present
(Elm
) loop
9070 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
9077 -- A formal of the proper name must be found
9079 raise Program_Error
;
9080 end Corresponding_Formal
;
9086 function External_Name
(E
: Entity_Id
) return Name_Id
is
9088 Get_Name_String
(Chars
(E
));
9089 Name_Len
:= Name_Len
- 1;
9093 -- Start of processing for Make_Eq_Case
9096 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
9098 if No
(Variant_Part
(CL
)) then
9102 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
9104 if No
(Variant
) then
9108 Alt_List
:= New_List
;
9109 while Present
(Variant
) loop
9110 Append_To
(Alt_List
,
9111 Make_Case_Statement_Alternative
(Loc
,
9112 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
9114 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
9115 Next_Non_Pragma
(Variant
);
9118 -- If we have an Unchecked_Union, use one of the parameters of the
9119 -- enclosing equality routine that captures the discriminant, to use
9120 -- as the expression in the generated case statement.
9122 if Is_Unchecked_Union
(E
) then
9124 Make_Case_Statement
(Loc
,
9126 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
9127 Alternatives
=> Alt_List
));
9131 Make_Case_Statement
(Loc
,
9133 Make_Selected_Component
(Loc
,
9134 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9135 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
9136 Alternatives
=> Alt_List
));
9157 -- or a null statement if the list L is empty
9161 L
: List_Id
) return Node_Id
9163 Loc
: constant Source_Ptr
:= Sloc
(E
);
9165 Field_Name
: Name_Id
;
9170 return Make_Null_Statement
(Loc
);
9175 C
:= First_Non_Pragma
(L
);
9176 while Present
(C
) loop
9177 Field_Name
:= Chars
(Defining_Identifier
(C
));
9179 -- The tags must not be compared: they are not part of the value.
9180 -- Ditto for parent interfaces because their equality operator is
9183 -- Note also that in the following, we use Make_Identifier for
9184 -- the component names. Use of New_Occurrence_Of to identify the
9185 -- components would be incorrect because the wrong entities for
9186 -- discriminants could be picked up in the private type case.
9188 if Field_Name
= Name_uParent
9189 and then Is_Interface
(Etype
(Defining_Identifier
(C
)))
9193 elsif Field_Name
/= Name_uTag
then
9194 Evolve_Or_Else
(Cond
,
9197 Make_Selected_Component
(Loc
,
9198 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9199 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
)),
9202 Make_Selected_Component
(Loc
,
9203 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
9204 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
))));
9207 Next_Non_Pragma
(C
);
9211 return Make_Null_Statement
(Loc
);
9215 Make_Implicit_If_Statement
(E
,
9217 Then_Statements
=> New_List
(
9218 Make_Simple_Return_Statement
(Loc
,
9219 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
9228 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
9230 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
9231 -- Returns true if Prim is a renaming of an unresolved predefined
9232 -- inequality operation.
9234 --------------------------------
9235 -- Is_Predefined_Neq_Renaming --
9236 --------------------------------
9238 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
9240 return Chars
(Prim
) /= Name_Op_Ne
9241 and then Present
(Alias
(Prim
))
9242 and then Comes_From_Source
(Prim
)
9243 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9244 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
9245 end Is_Predefined_Neq_Renaming
;
9249 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
9250 Stmts
: constant List_Id
:= New_List
;
9252 Eq_Prim
: Entity_Id
;
9253 Left_Op
: Entity_Id
;
9254 Renaming_Prim
: Entity_Id
;
9255 Right_Op
: Entity_Id
;
9258 -- Start of processing for Make_Neq_Body
9261 -- For a call on a renaming of a dispatching subprogram that is
9262 -- overridden, if the overriding occurred before the renaming, then
9263 -- the body executed is that of the overriding declaration, even if the
9264 -- overriding declaration is not visible at the place of the renaming;
9265 -- otherwise, the inherited or predefined subprogram is called, see
9268 -- Stage 1: Search for a renaming of the inequality primitive and also
9269 -- search for an overriding of the equality primitive located before the
9270 -- renaming declaration.
9278 Renaming_Prim
:= Empty
;
9280 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9281 while Present
(Elmt
) loop
9282 Prim
:= Node
(Elmt
);
9284 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
9285 if No
(Renaming_Prim
) then
9286 pragma Assert
(No
(Eq_Prim
));
9290 elsif Is_Predefined_Neq_Renaming
(Prim
) then
9291 Renaming_Prim
:= Prim
;
9298 -- No further action needed if no renaming was found
9300 if No
(Renaming_Prim
) then
9304 -- Stage 2: Replace the renaming declaration by a subprogram declaration
9305 -- (required to add its body)
9307 Decl
:= Parent
(Parent
(Renaming_Prim
));
9309 Make_Subprogram_Declaration
(Loc
,
9310 Specification
=> Specification
(Decl
)));
9311 Set_Analyzed
(Decl
);
9313 -- Remove the decoration of intrinsic renaming subprogram
9315 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
9316 Set_Convention
(Renaming_Prim
, Convention_Ada
);
9317 Set_Alias
(Renaming_Prim
, Empty
);
9318 Set_Has_Completion
(Renaming_Prim
, False);
9320 -- Stage 3: Build the corresponding body
9322 Left_Op
:= First_Formal
(Renaming_Prim
);
9323 Right_Op
:= Next_Formal
(Left_Op
);
9326 Predef_Spec_Or_Body
(Loc
,
9328 Name
=> Chars
(Renaming_Prim
),
9329 Profile
=> New_List
(
9330 Make_Parameter_Specification
(Loc
,
9331 Defining_Identifier
=>
9332 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
9333 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9335 Make_Parameter_Specification
(Loc
,
9336 Defining_Identifier
=>
9337 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
9338 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9340 Ret_Type
=> Standard_Boolean
,
9343 -- If the overriding of the equality primitive occurred before the
9344 -- renaming, then generate:
9346 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9348 -- return not Oeq (X, Y);
9351 if Present
(Eq_Prim
) then
9354 -- Otherwise build a nested subprogram which performs the predefined
9355 -- evaluation of the equality operator. That is, generate:
9357 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9358 -- function Oeq (X : Y) return Boolean is
9360 -- <<body of default implementation>>
9363 -- return not Oeq (X, Y);
9368 Local_Subp
: Node_Id
;
9370 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
9371 Set_Declarations
(Decl
, New_List
(Local_Subp
));
9372 Target
:= Defining_Entity
(Local_Subp
);
9377 Make_Simple_Return_Statement
(Loc
,
9380 Make_Function_Call
(Loc
,
9381 Name
=> New_Occurrence_Of
(Target
, Loc
),
9382 Parameter_Associations
=> New_List
(
9383 Make_Identifier
(Loc
, Chars
(Left_Op
)),
9384 Make_Identifier
(Loc
, Chars
(Right_Op
)))))));
9386 Set_Handled_Statement_Sequence
9387 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9391 -------------------------------
9392 -- Make_Null_Procedure_Specs --
9393 -------------------------------
9395 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
9396 Decl_List
: constant List_Id
:= New_List
;
9397 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9399 Formal_List
: List_Id
;
9400 New_Param_Spec
: Node_Id
;
9401 Parent_Subp
: Entity_Id
;
9402 Prim_Elmt
: Elmt_Id
;
9406 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9407 while Present
(Prim_Elmt
) loop
9408 Subp
:= Node
(Prim_Elmt
);
9410 -- If a null procedure inherited from an interface has not been
9411 -- overridden, then we build a null procedure declaration to
9412 -- override the inherited procedure.
9414 Parent_Subp
:= Alias
(Subp
);
9416 if Present
(Parent_Subp
)
9417 and then Is_Null_Interface_Primitive
(Parent_Subp
)
9419 Formal_List
:= No_List
;
9420 Formal
:= First_Formal
(Subp
);
9422 if Present
(Formal
) then
9423 Formal_List
:= New_List
;
9425 while Present
(Formal
) loop
9427 -- Copy the parameter spec including default expressions
9430 New_Copy_Tree
(Parent
(Formal
), New_Sloc
=> Loc
);
9432 -- Generate a new defining identifier for the new formal.
9433 -- required because New_Copy_Tree does not duplicate
9434 -- semantic fields (except itypes).
9436 Set_Defining_Identifier
(New_Param_Spec
,
9437 Make_Defining_Identifier
(Sloc
(Formal
),
9438 Chars
=> Chars
(Formal
)));
9440 -- For controlling arguments we must change their
9441 -- parameter type to reference the tagged type (instead
9442 -- of the interface type)
9444 if Is_Controlling_Formal
(Formal
) then
9445 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
9447 Set_Parameter_Type
(New_Param_Spec
,
9448 New_Occurrence_Of
(Tag_Typ
, Loc
));
9451 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
9452 N_Access_Definition
);
9453 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
9454 New_Occurrence_Of
(Tag_Typ
, Loc
));
9458 Append
(New_Param_Spec
, Formal_List
);
9460 Next_Formal
(Formal
);
9464 Append_To
(Decl_List
,
9465 Make_Subprogram_Declaration
(Loc
,
9466 Make_Procedure_Specification
(Loc
,
9467 Defining_Unit_Name
=>
9468 Make_Defining_Identifier
(Loc
, Chars
(Subp
)),
9469 Parameter_Specifications
=> Formal_List
,
9470 Null_Present
=> True)));
9473 Next_Elmt
(Prim_Elmt
);
9477 end Make_Null_Procedure_Specs
;
9479 -------------------------------------
9480 -- Make_Predefined_Primitive_Specs --
9481 -------------------------------------
9483 procedure Make_Predefined_Primitive_Specs
9484 (Tag_Typ
: Entity_Id
;
9485 Predef_List
: out List_Id
;
9486 Renamed_Eq
: out Entity_Id
)
9488 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
9489 -- Returns true if Prim is a renaming of an unresolved predefined
9490 -- equality operation.
9492 -------------------------------
9493 -- Is_Predefined_Eq_Renaming --
9494 -------------------------------
9496 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
9498 return Chars
(Prim
) /= Name_Op_Eq
9499 and then Present
(Alias
(Prim
))
9500 and then Comes_From_Source
(Prim
)
9501 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9502 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
9503 end Is_Predefined_Eq_Renaming
;
9507 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9508 Res
: constant List_Id
:= New_List
;
9509 Eq_Name
: Name_Id
:= Name_Op_Eq
;
9510 Eq_Needed
: Boolean;
9514 Has_Predef_Eq_Renaming
: Boolean := False;
9515 -- Set to True if Tag_Typ has a primitive that renames the predefined
9516 -- equality operator. Used to implement (RM 8-5-4(8)).
9518 -- Start of processing for Make_Predefined_Primitive_Specs
9521 Renamed_Eq
:= Empty
;
9525 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9528 Profile
=> New_List
(
9529 Make_Parameter_Specification
(Loc
,
9530 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9531 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9533 Ret_Type
=> Standard_Long_Long_Integer
));
9535 -- Specs for dispatching stream attributes
9538 Stream_Op_TSS_Names
:
9539 constant array (Positive range <>) of TSS_Name_Type
:=
9546 for Op
in Stream_Op_TSS_Names
'Range loop
9547 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
9549 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
9550 Stream_Op_TSS_Names
(Op
)));
9555 -- Spec of "=" is expanded if the type is not limited and if a user
9556 -- defined "=" was not already declared for the non-full view of a
9557 -- private extension
9559 if not Is_Limited_Type
(Tag_Typ
) then
9561 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9562 while Present
(Prim
) loop
9564 -- If a primitive is encountered that renames the predefined
9565 -- equality operator before reaching any explicit equality
9566 -- primitive, then we still need to create a predefined equality
9567 -- function, because calls to it can occur via the renaming. A
9568 -- new name is created for the equality to avoid conflicting with
9569 -- any user-defined equality. (Note that this doesn't account for
9570 -- renamings of equality nested within subpackages???)
9572 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9573 Has_Predef_Eq_Renaming
:= True;
9574 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
9576 -- User-defined equality
9578 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
9579 if No
(Alias
(Node
(Prim
)))
9580 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
9581 N_Subprogram_Renaming_Declaration
9586 -- If the parent is not an interface type and has an abstract
9587 -- equality function explicitly defined in the sources, then
9588 -- the inherited equality is abstract as well, and no body can
9589 -- be created for it.
9591 elsif not Is_Interface
(Etype
(Tag_Typ
))
9592 and then Present
(Alias
(Node
(Prim
)))
9593 and then Comes_From_Source
(Alias
(Node
(Prim
)))
9594 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
9599 -- If the type has an equality function corresponding with
9600 -- a primitive defined in an interface type, the inherited
9601 -- equality is abstract as well, and no body can be created
9604 elsif Present
(Alias
(Node
(Prim
)))
9605 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
9608 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
9618 -- If a renaming of predefined equality was found but there was no
9619 -- user-defined equality (so Eq_Needed is still true), then set the
9620 -- name back to Name_Op_Eq. But in the case where a user-defined
9621 -- equality was located after such a renaming, then the predefined
9622 -- equality function is still needed, so Eq_Needed must be set back
9625 if Eq_Name
/= Name_Op_Eq
then
9627 Eq_Name
:= Name_Op_Eq
;
9634 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
9637 Profile
=> New_List
(
9638 Make_Parameter_Specification
(Loc
,
9639 Defining_Identifier
=>
9640 Make_Defining_Identifier
(Loc
, Name_X
),
9641 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9643 Make_Parameter_Specification
(Loc
,
9644 Defining_Identifier
=>
9645 Make_Defining_Identifier
(Loc
, Name_Y
),
9646 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9647 Ret_Type
=> Standard_Boolean
);
9648 Append_To
(Res
, Eq_Spec
);
9650 if Has_Predef_Eq_Renaming
then
9651 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
9653 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9654 while Present
(Prim
) loop
9656 -- Any renamings of equality that appeared before an
9657 -- overriding equality must be updated to refer to the
9658 -- entity for the predefined equality, otherwise calls via
9659 -- the renaming would get incorrectly resolved to call the
9660 -- user-defined equality function.
9662 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9663 Set_Alias
(Node
(Prim
), Renamed_Eq
);
9665 -- Exit upon encountering a user-defined equality
9667 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
9668 and then No
(Alias
(Node
(Prim
)))
9678 -- Spec for dispatching assignment
9680 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9682 Name
=> Name_uAssign
,
9683 Profile
=> New_List
(
9684 Make_Parameter_Specification
(Loc
,
9685 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9686 Out_Present
=> True,
9687 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9689 Make_Parameter_Specification
(Loc
,
9690 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
9691 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
9694 -- Ada 2005: Generate declarations for the following primitive
9695 -- operations for limited interfaces and synchronized types that
9696 -- implement a limited interface.
9698 -- Disp_Asynchronous_Select
9699 -- Disp_Conditional_Select
9700 -- Disp_Get_Prim_Op_Kind
9703 -- Disp_Timed_Select
9705 -- Disable the generation of these bodies if No_Dispatching_Calls,
9706 -- Ravenscar or ZFP is active.
9708 if Ada_Version
>= Ada_2005
9709 and then not Restriction_Active
(No_Dispatching_Calls
)
9710 and then not Restriction_Active
(No_Select_Statements
)
9711 and then RTE_Available
(RE_Select_Specific_Data
)
9713 -- These primitives are defined abstract in interface types
9715 if Is_Interface
(Tag_Typ
)
9716 and then Is_Limited_Record
(Tag_Typ
)
9719 Make_Abstract_Subprogram_Declaration
(Loc
,
9721 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9724 Make_Abstract_Subprogram_Declaration
(Loc
,
9726 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9729 Make_Abstract_Subprogram_Declaration
(Loc
,
9731 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9734 Make_Abstract_Subprogram_Declaration
(Loc
,
9736 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9739 Make_Abstract_Subprogram_Declaration
(Loc
,
9741 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9744 Make_Abstract_Subprogram_Declaration
(Loc
,
9746 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9748 -- If ancestor is an interface type, declare non-abstract primitives
9749 -- to override the abstract primitives of the interface type.
9751 -- In VM targets we define these primitives in all root tagged types
9752 -- that are not interface types. Done because in VM targets we don't
9753 -- have secondary dispatch tables and any derivation of Tag_Typ may
9754 -- cover limited interfaces (which always have these primitives since
9755 -- they may be ancestors of synchronized interface types).
9757 elsif (not Is_Interface
(Tag_Typ
)
9758 and then Is_Interface
(Etype
(Tag_Typ
))
9759 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
9761 (Is_Concurrent_Record_Type
(Tag_Typ
)
9762 and then Has_Interfaces
(Tag_Typ
))
9764 (not Tagged_Type_Expansion
9765 and then not Is_Interface
(Tag_Typ
)
9766 and then Tag_Typ
= Root_Type
(Tag_Typ
))
9769 Make_Subprogram_Declaration
(Loc
,
9771 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9774 Make_Subprogram_Declaration
(Loc
,
9776 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9779 Make_Subprogram_Declaration
(Loc
,
9781 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9784 Make_Subprogram_Declaration
(Loc
,
9786 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9789 Make_Subprogram_Declaration
(Loc
,
9791 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9794 Make_Subprogram_Declaration
(Loc
,
9796 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9800 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
9801 -- regardless of whether they are controlled or may contain controlled
9804 -- Do not generate the routines if finalization is disabled
9806 if Restriction_Active
(No_Finalization
) then
9810 if not Is_Limited_Type
(Tag_Typ
) then
9811 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
9814 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
9818 end Make_Predefined_Primitive_Specs
;
9820 -------------------------
9821 -- Make_Tag_Assignment --
9822 -------------------------
9824 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
9825 Loc
: constant Source_Ptr
:= Sloc
(N
);
9826 Def_If
: constant Entity_Id
:= Defining_Identifier
(N
);
9827 Expr
: constant Node_Id
:= Expression
(N
);
9828 Typ
: constant Entity_Id
:= Etype
(Def_If
);
9829 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
9833 -- This expansion activity is called during analysis, but cannot
9834 -- be applied in ASIS mode when other expansion is disabled.
9836 if Is_Tagged_Type
(Typ
)
9837 and then not Is_Class_Wide_Type
(Typ
)
9838 and then not Is_CPP_Class
(Typ
)
9839 and then Tagged_Type_Expansion
9840 and then Nkind
(Expr
) /= N_Aggregate
9841 and then not ASIS_Mode
9842 and then (Nkind
(Expr
) /= N_Qualified_Expression
9843 or else Nkind
(Expression
(Expr
)) /= N_Aggregate
)
9846 Make_Selected_Component
(Loc
,
9847 Prefix
=> New_Occurrence_Of
(Def_If
, Loc
),
9849 New_Occurrence_Of
(First_Tag_Component
(Full_Typ
), Loc
));
9850 Set_Assignment_OK
(New_Ref
);
9853 Make_Assignment_Statement
(Loc
,
9856 Unchecked_Convert_To
(RTE
(RE_Tag
),
9857 New_Occurrence_Of
(Node
9858 (First_Elmt
(Access_Disp_Table
(Full_Typ
))), Loc
)));
9862 end Make_Tag_Assignment
;
9864 ---------------------------------
9865 -- Needs_Simple_Initialization --
9866 ---------------------------------
9868 function Needs_Simple_Initialization
9870 Consider_IS
: Boolean := True) return Boolean
9872 Consider_IS_NS
: constant Boolean :=
9873 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
9876 -- Never need initialization if it is suppressed
9878 if Initialization_Suppressed
(T
) then
9882 -- Check for private type, in which case test applies to the underlying
9883 -- type of the private type.
9885 if Is_Private_Type
(T
) then
9887 RT
: constant Entity_Id
:= Underlying_Type
(T
);
9889 if Present
(RT
) then
9890 return Needs_Simple_Initialization
(RT
);
9896 -- Scalar type with Default_Value aspect requires initialization
9898 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
9901 -- Cases needing simple initialization are access types, and, if pragma
9902 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
9905 elsif Is_Access_Type
(T
)
9906 or else (Consider_IS_NS
and then (Is_Scalar_Type
(T
)))
9910 -- If Initialize/Normalize_Scalars is in effect, string objects also
9911 -- need initialization, unless they are created in the course of
9912 -- expanding an aggregate (since in the latter case they will be
9913 -- filled with appropriate initializing values before they are used).
9915 elsif Consider_IS_NS
9916 and then Is_Standard_String_Type
(T
)
9919 or else Nkind
(Associated_Node_For_Itype
(T
)) /= N_Aggregate
)
9926 end Needs_Simple_Initialization
;
9928 ----------------------
9929 -- Predef_Deep_Spec --
9930 ----------------------
9932 function Predef_Deep_Spec
9934 Tag_Typ
: Entity_Id
;
9935 Name
: TSS_Name_Type
;
9936 For_Body
: Boolean := False) return Node_Id
9941 -- V : in out Tag_Typ
9943 Formals
:= New_List
(
9944 Make_Parameter_Specification
(Loc
,
9945 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
9947 Out_Present
=> True,
9948 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
9950 -- F : Boolean := True
9952 if Name
= TSS_Deep_Adjust
9953 or else Name
= TSS_Deep_Finalize
9956 Make_Parameter_Specification
(Loc
,
9957 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
9958 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
9959 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9963 Predef_Spec_Or_Body
(Loc
,
9964 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
9967 For_Body
=> For_Body
);
9970 when RE_Not_Available
=>
9972 end Predef_Deep_Spec
;
9974 -------------------------
9975 -- Predef_Spec_Or_Body --
9976 -------------------------
9978 function Predef_Spec_Or_Body
9980 Tag_Typ
: Entity_Id
;
9983 Ret_Type
: Entity_Id
:= Empty
;
9984 For_Body
: Boolean := False) return Node_Id
9986 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
9990 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
9992 -- The internal flag is set to mark these declarations because they have
9993 -- specific properties. First, they are primitives even if they are not
9994 -- defined in the type scope (the freezing point is not necessarily in
9995 -- the same scope). Second, the predefined equality can be overridden by
9996 -- a user-defined equality, no body will be generated in this case.
9998 Set_Is_Internal
(Id
);
10000 if not Debug_Generated_Code
then
10001 Set_Debug_Info_Off
(Id
);
10004 if No
(Ret_Type
) then
10006 Make_Procedure_Specification
(Loc
,
10007 Defining_Unit_Name
=> Id
,
10008 Parameter_Specifications
=> Profile
);
10011 Make_Function_Specification
(Loc
,
10012 Defining_Unit_Name
=> Id
,
10013 Parameter_Specifications
=> Profile
,
10014 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
10017 if Is_Interface
(Tag_Typ
) then
10018 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10020 -- If body case, return empty subprogram body. Note that this is ill-
10021 -- formed, because there is not even a null statement, and certainly not
10022 -- a return in the function case. The caller is expected to do surgery
10023 -- on the body to add the appropriate stuff.
10025 elsif For_Body
then
10026 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
10028 -- For the case of an Input attribute predefined for an abstract type,
10029 -- generate an abstract specification. This will never be called, but we
10030 -- need the slot allocated in the dispatching table so that attributes
10031 -- typ'Class'Input and typ'Class'Output will work properly.
10033 elsif Is_TSS
(Name
, TSS_Stream_Input
)
10034 and then Is_Abstract_Type
(Tag_Typ
)
10036 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10038 -- Normal spec case, where we return a subprogram declaration
10041 return Make_Subprogram_Declaration
(Loc
, Spec
);
10043 end Predef_Spec_Or_Body
;
10045 -----------------------------
10046 -- Predef_Stream_Attr_Spec --
10047 -----------------------------
10049 function Predef_Stream_Attr_Spec
10051 Tag_Typ
: Entity_Id
;
10052 Name
: TSS_Name_Type
;
10053 For_Body
: Boolean := False) return Node_Id
10055 Ret_Type
: Entity_Id
;
10058 if Name
= TSS_Stream_Input
then
10059 Ret_Type
:= Tag_Typ
;
10065 Predef_Spec_Or_Body
10067 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10068 Tag_Typ
=> Tag_Typ
,
10069 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
10070 Ret_Type
=> Ret_Type
,
10071 For_Body
=> For_Body
);
10072 end Predef_Stream_Attr_Spec
;
10074 ---------------------------------
10075 -- Predefined_Primitive_Bodies --
10076 ---------------------------------
10078 function Predefined_Primitive_Bodies
10079 (Tag_Typ
: Entity_Id
;
10080 Renamed_Eq
: Entity_Id
) return List_Id
10082 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
10083 Res
: constant List_Id
:= New_List
;
10084 Adj_Call
: Node_Id
;
10086 Fin_Call
: Node_Id
;
10088 Eq_Needed
: Boolean;
10092 pragma Warnings
(Off
, Ent
);
10095 pragma Assert
(not Is_Interface
(Tag_Typ
));
10097 -- See if we have a predefined "=" operator
10099 if Present
(Renamed_Eq
) then
10101 Eq_Name
:= Chars
(Renamed_Eq
);
10103 -- If the parent is an interface type then it has defined all the
10104 -- predefined primitives abstract and we need to check if the type
10105 -- has some user defined "=" function which matches the profile of
10106 -- the Ada predefined equality operator to avoid generating it.
10108 elsif Is_Interface
(Etype
(Tag_Typ
)) then
10110 Eq_Name
:= Name_Op_Eq
;
10112 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10113 while Present
(Prim
) loop
10114 if Chars
(Node
(Prim
)) = Name_Op_Eq
10115 and then not Is_Internal
(Node
(Prim
))
10116 and then Present
(First_Entity
(Node
(Prim
)))
10118 -- The predefined equality primitive must have exactly two
10119 -- formals whose type is this tagged type
10121 and then Present
(Last_Entity
(Node
(Prim
)))
10122 and then Next_Entity
(First_Entity
(Node
(Prim
)))
10123 = Last_Entity
(Node
(Prim
))
10124 and then Etype
(First_Entity
(Node
(Prim
))) = Tag_Typ
10125 and then Etype
(Last_Entity
(Node
(Prim
))) = Tag_Typ
10127 Eq_Needed
:= False;
10128 Eq_Name
:= No_Name
;
10136 Eq_Needed
:= False;
10137 Eq_Name
:= No_Name
;
10139 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10140 while Present
(Prim
) loop
10141 if Chars
(Node
(Prim
)) = Name_Op_Eq
10142 and then Is_Internal
(Node
(Prim
))
10145 Eq_Name
:= Name_Op_Eq
;
10155 Decl
:= Predef_Spec_Or_Body
(Loc
,
10156 Tag_Typ
=> Tag_Typ
,
10157 Name
=> Name_uSize
,
10158 Profile
=> New_List
(
10159 Make_Parameter_Specification
(Loc
,
10160 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10161 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10163 Ret_Type
=> Standard_Long_Long_Integer
,
10166 Set_Handled_Statement_Sequence
(Decl
,
10167 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10168 Make_Simple_Return_Statement
(Loc
,
10170 Make_Attribute_Reference
(Loc
,
10171 Prefix
=> Make_Identifier
(Loc
, Name_X
),
10172 Attribute_Name
=> Name_Size
)))));
10174 Append_To
(Res
, Decl
);
10176 -- Bodies for Dispatching stream IO routines. We need these only for
10177 -- non-limited types (in the limited case there is no dispatching).
10178 -- We also skip them if dispatching or finalization are not available
10179 -- or if stream operations are prohibited by restriction No_Streams or
10180 -- from use of pragma/aspect No_Tagged_Streams.
10182 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
10183 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
10185 Build_Record_Read_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10186 Append_To
(Res
, Decl
);
10189 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
10190 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
10192 Build_Record_Write_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10193 Append_To
(Res
, Decl
);
10196 -- Skip body of _Input for the abstract case, since the corresponding
10197 -- spec is abstract (see Predef_Spec_Or_Body).
10199 if not Is_Abstract_Type
(Tag_Typ
)
10200 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
10201 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
10203 Build_Record_Or_Elementary_Input_Function
10204 (Loc
, Tag_Typ
, Decl
, Ent
);
10205 Append_To
(Res
, Decl
);
10208 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
10209 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
10211 Build_Record_Or_Elementary_Output_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10212 Append_To
(Res
, Decl
);
10215 -- Ada 2005: Generate bodies for the following primitive operations for
10216 -- limited interfaces and synchronized types that implement a limited
10219 -- disp_asynchronous_select
10220 -- disp_conditional_select
10221 -- disp_get_prim_op_kind
10222 -- disp_get_task_id
10223 -- disp_timed_select
10225 -- The interface versions will have null bodies
10227 -- Disable the generation of these bodies if No_Dispatching_Calls,
10228 -- Ravenscar or ZFP is active.
10230 -- In VM targets we define these primitives in all root tagged types
10231 -- that are not interface types. Done because in VM targets we don't
10232 -- have secondary dispatch tables and any derivation of Tag_Typ may
10233 -- cover limited interfaces (which always have these primitives since
10234 -- they may be ancestors of synchronized interface types).
10236 if Ada_Version
>= Ada_2005
10237 and then not Is_Interface
(Tag_Typ
)
10239 ((Is_Interface
(Etype
(Tag_Typ
))
10240 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10242 (Is_Concurrent_Record_Type
(Tag_Typ
)
10243 and then Has_Interfaces
(Tag_Typ
))
10245 (not Tagged_Type_Expansion
10246 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
10247 and then not Restriction_Active
(No_Dispatching_Calls
)
10248 and then not Restriction_Active
(No_Select_Statements
)
10249 and then RTE_Available
(RE_Select_Specific_Data
)
10251 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
10252 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
10253 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
10254 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
10255 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
10256 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
10259 if not Is_Limited_Type
(Tag_Typ
) and then not Is_Interface
(Tag_Typ
) then
10261 -- Body for equality
10264 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
10265 Append_To
(Res
, Decl
);
10268 -- Body for inequality (if required)
10270 Decl
:= Make_Neq_Body
(Tag_Typ
);
10272 if Present
(Decl
) then
10273 Append_To
(Res
, Decl
);
10276 -- Body for dispatching assignment
10279 Predef_Spec_Or_Body
(Loc
,
10280 Tag_Typ
=> Tag_Typ
,
10281 Name
=> Name_uAssign
,
10282 Profile
=> New_List
(
10283 Make_Parameter_Specification
(Loc
,
10284 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10285 Out_Present
=> True,
10286 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
10288 Make_Parameter_Specification
(Loc
,
10289 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
10290 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10293 Set_Handled_Statement_Sequence
(Decl
,
10294 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10295 Make_Assignment_Statement
(Loc
,
10296 Name
=> Make_Identifier
(Loc
, Name_X
),
10297 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
10299 Append_To
(Res
, Decl
);
10302 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
10303 -- tagged types which do not contain controlled components.
10305 -- Do not generate the routines if finalization is disabled
10307 if Restriction_Active
(No_Finalization
) then
10310 elsif not Has_Controlled_Component
(Tag_Typ
) then
10311 if not Is_Limited_Type
(Tag_Typ
) then
10313 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
10315 if Is_Controlled
(Tag_Typ
) then
10318 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10322 if No
(Adj_Call
) then
10323 Adj_Call
:= Make_Null_Statement
(Loc
);
10326 Set_Handled_Statement_Sequence
(Decl
,
10327 Make_Handled_Sequence_Of_Statements
(Loc
,
10328 Statements
=> New_List
(Adj_Call
)));
10330 Append_To
(Res
, Decl
);
10334 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
10336 if Is_Controlled
(Tag_Typ
) then
10339 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10343 if No
(Fin_Call
) then
10344 Fin_Call
:= Make_Null_Statement
(Loc
);
10347 Set_Handled_Statement_Sequence
(Decl
,
10348 Make_Handled_Sequence_Of_Statements
(Loc
,
10349 Statements
=> New_List
(Fin_Call
)));
10351 Append_To
(Res
, Decl
);
10355 end Predefined_Primitive_Bodies
;
10357 ---------------------------------
10358 -- Predefined_Primitive_Freeze --
10359 ---------------------------------
10361 function Predefined_Primitive_Freeze
10362 (Tag_Typ
: Entity_Id
) return List_Id
10364 Res
: constant List_Id
:= New_List
;
10369 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10370 while Present
(Prim
) loop
10371 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
10372 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
10374 if Present
(Frnodes
) then
10375 Append_List_To
(Res
, Frnodes
);
10383 end Predefined_Primitive_Freeze
;
10385 -------------------------
10386 -- Stream_Operation_OK --
10387 -------------------------
10389 function Stream_Operation_OK
10391 Operation
: TSS_Name_Type
) return Boolean
10393 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
10396 -- Special case of a limited type extension: a default implementation
10397 -- of the stream attributes Read or Write exists if that attribute
10398 -- has been specified or is available for an ancestor type; a default
10399 -- implementation of the attribute Output (resp. Input) exists if the
10400 -- attribute has been specified or Write (resp. Read) is available for
10401 -- an ancestor type. The last condition only applies under Ada 2005.
10403 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
10404 if Operation
= TSS_Stream_Read
then
10405 Has_Predefined_Or_Specified_Stream_Attribute
:=
10406 Has_Specified_Stream_Read
(Typ
);
10408 elsif Operation
= TSS_Stream_Write
then
10409 Has_Predefined_Or_Specified_Stream_Attribute
:=
10410 Has_Specified_Stream_Write
(Typ
);
10412 elsif Operation
= TSS_Stream_Input
then
10413 Has_Predefined_Or_Specified_Stream_Attribute
:=
10414 Has_Specified_Stream_Input
(Typ
)
10416 (Ada_Version
>= Ada_2005
10417 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
10419 elsif Operation
= TSS_Stream_Output
then
10420 Has_Predefined_Or_Specified_Stream_Attribute
:=
10421 Has_Specified_Stream_Output
(Typ
)
10423 (Ada_Version
>= Ada_2005
10424 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
10427 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
10429 if not Has_Predefined_Or_Specified_Stream_Attribute
10430 and then Is_Derived_Type
(Typ
)
10431 and then (Operation
= TSS_Stream_Read
10432 or else Operation
= TSS_Stream_Write
)
10434 Has_Predefined_Or_Specified_Stream_Attribute
:=
10436 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
10440 -- If the type is not limited, or else is limited but the attribute is
10441 -- explicitly specified or is predefined for the type, then return True,
10442 -- unless other conditions prevail, such as restrictions prohibiting
10443 -- streams or dispatching operations. We also return True for limited
10444 -- interfaces, because they may be extended by nonlimited types and
10445 -- permit inheritance in this case (addresses cases where an abstract
10446 -- extension doesn't get 'Input declared, as per comments below, but
10447 -- 'Class'Input must still be allowed). Note that attempts to apply
10448 -- stream attributes to a limited interface or its class-wide type
10449 -- (or limited extensions thereof) will still get properly rejected
10450 -- by Check_Stream_Attribute.
10452 -- We exclude the Input operation from being a predefined subprogram in
10453 -- the case where the associated type is an abstract extension, because
10454 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
10455 -- we don't want an abstract version created because types derived from
10456 -- the abstract type may not even have Input available (for example if
10457 -- derived from a private view of the abstract type that doesn't have
10458 -- a visible Input).
10460 -- Do not generate stream routines for type Finalization_Master because
10461 -- a master may never appear in types and therefore cannot be read or
10465 (not Is_Limited_Type
(Typ
)
10466 or else Is_Interface
(Typ
)
10467 or else Has_Predefined_Or_Specified_Stream_Attribute
)
10469 (Operation
/= TSS_Stream_Input
10470 or else not Is_Abstract_Type
(Typ
)
10471 or else not Is_Derived_Type
(Typ
))
10472 and then not Has_Unknown_Discriminants
(Typ
)
10474 (Is_Interface
(Typ
)
10476 (Is_Task_Interface
(Typ
)
10477 or else Is_Protected_Interface
(Typ
)
10478 or else Is_Synchronized_Interface
(Typ
)))
10479 and then not Restriction_Active
(No_Streams
)
10480 and then not Restriction_Active
(No_Dispatch
)
10481 and then No
(No_Tagged_Streams_Pragma
(Typ
))
10482 and then not No_Run_Time_Mode
10483 and then RTE_Available
(RE_Tag
)
10484 and then No
(Type_Without_Stream_Operation
(Typ
))
10485 and then RTE_Available
(RE_Root_Stream_Type
)
10486 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
10487 end Stream_Operation_OK
;