1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Einfo
; use Einfo
;
32 with Einfo
.Entities
; use Einfo
.Entities
;
33 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Errout
; use Errout
;
35 with Expander
; use Expander
;
36 with Exp_Aggr
; use Exp_Aggr
;
37 with Exp_Atag
; use Exp_Atag
;
38 with Exp_Ch4
; use Exp_Ch4
;
39 with Exp_Ch6
; use Exp_Ch6
;
40 with Exp_Ch7
; use Exp_Ch7
;
41 with Exp_Ch9
; use Exp_Ch9
;
42 with Exp_Dbug
; use Exp_Dbug
;
43 with Exp_Disp
; use Exp_Disp
;
44 with Exp_Dist
; use Exp_Dist
;
46 with Exp_Smem
; use Exp_Smem
;
47 with Exp_Strm
; use Exp_Strm
;
48 with Exp_Util
; use Exp_Util
;
49 with Freeze
; use Freeze
;
50 with Ghost
; use Ghost
;
52 with Namet
; use Namet
;
53 with Nlists
; use Nlists
;
54 with Nmake
; use Nmake
;
56 with Restrict
; use Restrict
;
57 with Rident
; use Rident
;
58 with Rtsfind
; use Rtsfind
;
60 with Sem_Aux
; use Sem_Aux
;
61 with Sem_Attr
; use Sem_Attr
;
62 with Sem_Cat
; use Sem_Cat
;
63 with Sem_Ch3
; use Sem_Ch3
;
64 with Sem_Ch6
; use Sem_Ch6
;
65 with Sem_Ch8
; use Sem_Ch8
;
66 with Sem_Disp
; use Sem_Disp
;
67 with Sem_Eval
; use Sem_Eval
;
68 with Sem_Mech
; use Sem_Mech
;
69 with Sem_Res
; use Sem_Res
;
70 with Sem_SCIL
; use Sem_SCIL
;
71 with Sem_Type
; use Sem_Type
;
72 with Sem_Util
; use Sem_Util
;
73 with Sinfo
; use Sinfo
;
74 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
75 with Sinfo
.Utils
; use Sinfo
.Utils
;
76 with Stand
; use Stand
;
77 with Snames
; use Snames
;
78 with Tbuild
; use Tbuild
;
79 with Ttypes
; use Ttypes
;
80 with Validsw
; use Validsw
;
82 package body Exp_Ch3
is
84 -----------------------
85 -- Local Subprograms --
86 -----------------------
88 procedure Adjust_Discriminants
(Rtype
: Entity_Id
);
89 -- This is used when freezing a record type. It attempts to construct
90 -- more restrictive subtypes for discriminants so that the max size of
91 -- the record can be calculated more accurately. See the body of this
92 -- procedure for details.
94 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
);
95 -- Build initialization procedure for given array type. Nod is a node
96 -- used for attachment of any actions required in its construction.
97 -- It also supplies the source location used for the procedure.
99 function Build_Discriminant_Formals
101 Use_Dl
: Boolean) return List_Id
;
102 -- This function uses the discriminants of a type to build a list of
103 -- formal parameters, used in Build_Init_Procedure among other places.
104 -- If the flag Use_Dl is set, the list is built using the already
105 -- defined discriminals of the type, as is the case for concurrent
106 -- types with discriminants. Otherwise new identifiers are created,
107 -- with the source names of the discriminants.
109 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
);
110 -- For each variant component, builds a function which checks whether
111 -- the component name is consistent with the current discriminants
112 -- and sets the component's Dcheck_Function attribute to refer to it.
113 -- N is the full type declaration node; the discriminant checking
114 -- functions are inserted after this node.
116 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
;
117 -- This function builds a static aggregate that can serve as the initial
118 -- value for an array type whose bounds are static, and whose component
119 -- type is a composite type that has a static equivalent aggregate.
120 -- The equivalent array aggregate is used both for object initialization
121 -- and for component initialization, when used in the following function.
123 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
;
124 -- This function builds a static aggregate that can serve as the initial
125 -- value for a record type whose components are scalar and initialized
126 -- with compile-time values, or arrays with similar initialization or
127 -- defaults. When possible, initialization of an object of the type can
128 -- be achieved by using a copy of the aggregate as an initial value, thus
129 -- removing the implicit call that would otherwise constitute elaboration
132 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
);
133 -- Build record initialization procedure. N is the type declaration
134 -- node, and Rec_Ent is the corresponding entity for the record type.
136 procedure Build_Slice_Assignment
(Typ
: Entity_Id
);
137 -- Build assignment procedure for one-dimensional arrays of controlled
138 -- types. Other array and slice assignments are expanded in-line, but
139 -- the code expansion for controlled components (when control actions
140 -- are active) can lead to very large blocks that GCC handles poorly.
142 procedure Build_Untagged_Record_Equality
(Typ
: Entity_Id
);
143 -- AI05-0123: Equality on untagged records composes. This procedure
144 -- builds the equality routine for an untagged record that has components
145 -- of a record type that has user-defined primitive equality operations.
146 -- The resulting operation is a TSS subprogram.
148 procedure Check_Stream_Attributes
(Typ
: Entity_Id
);
149 -- Check that if a limited extension has a parent with user-defined stream
150 -- attributes, and does not itself have user-defined stream-attributes,
151 -- then any limited component of the extension also has the corresponding
152 -- user-defined stream attributes.
154 procedure Clean_Task_Names
156 Proc_Id
: Entity_Id
);
157 -- If an initialization procedure includes calls to generate names
158 -- for task subcomponents, indicate that secondary stack cleanup is
159 -- needed after an initialization. Typ is the component type, and Proc_Id
160 -- the initialization procedure for the enclosing composite type.
162 procedure Copy_Discr_Checking_Funcs
(N
: Node_Id
);
163 -- For a derived untagged type, copy the attributes that were set
164 -- for the components of the parent type onto the components of the
165 -- derived type. No new subprograms are constructed.
166 -- N is the full type declaration node, as for Build_Discr_Checking_Funcs.
168 procedure Expand_Freeze_Array_Type
(N
: Node_Id
);
169 -- Freeze an array type. Deals with building the initialization procedure,
170 -- creating the packed array type for a packed array and also with the
171 -- creation of the controlling procedures for the controlled case. The
172 -- argument N is the N_Freeze_Entity node for the type.
174 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
);
175 -- Freeze a class-wide type. Build routine Finalize_Address for the purpose
176 -- of finalizing controlled derivations from the class-wide's root type.
178 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
);
179 -- Freeze enumeration type with non-standard representation. Builds the
180 -- array and function needed to convert between enumeration pos and
181 -- enumeration representation values. N is the N_Freeze_Entity node
184 procedure Expand_Freeze_Record_Type
(N
: Node_Id
);
185 -- Freeze record type. Builds all necessary discriminant checking
186 -- and other ancillary functions, and builds dispatch tables where
187 -- needed. The argument N is the N_Freeze_Entity node. This processing
188 -- applies only to E_Record_Type entities, not to class wide types,
189 -- record subtypes, or private types.
191 procedure Expand_Tagged_Root
(T
: Entity_Id
);
192 -- Add a field _Tag at the beginning of the record. This field carries
193 -- the value of the access to the Dispatch table. This procedure is only
194 -- called on root type, the _Tag field being inherited by the descendants.
196 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
);
197 -- Treat user-defined stream operations as renaming_as_body if the
198 -- subprogram they rename is not frozen when the type is frozen.
200 package Initialization_Control
is
202 function Requires_Late_Init
203 (Decl
: Node_Id
; Rec_Type
: Entity_Id
) return Boolean;
204 -- Return True iff the given component declaration requires late
205 -- initialization, as defined by 3.3.1 (8.1/5).
207 function Has_Late_Init_Component
208 (Tagged_Rec_Type
: Entity_Id
) return Boolean;
209 -- Return True iff the given tagged record type has at least one
210 -- component that requires late initialization; this includes
211 -- components of ancestor types.
213 type Initialization_Mode
is
214 (Full_Init
, Full_Init_Except_Tag
, Early_Init_Only
, Late_Init_Only
);
215 -- The initialization routine for a tagged type is passed in a
216 -- formal parameter of this type, indicating what initialization
217 -- is to be performed. This parameter defaults to Full_Init in all
218 -- cases except when the init proc of a type extension (let's call
219 -- that type T2) calls the init proc of its parent (let's call that
220 -- type T1). In that case, one of the other 3 values will
221 -- be passed in. In all three of those cases, the Tag component has
222 -- already been initialized before the call and is therefore not to be
223 -- modified. T2's init proc will either call T1's init proc
224 -- once (with Full_Init_Except_Tag as the parameter value) or twice
225 -- (first with Early_Init_Only, then later with Late_Init_Only),
226 -- depending on the result returned by Has_Late_Init_Component (T1).
227 -- In the latter case, the first call does not initialize any
228 -- components that require late initialization and the second call
229 -- then performs that deferred initialization.
230 -- Strictly speaking, the formal parameter subtype is actually Natural
231 -- but calls will only pass in values corresponding to literals
232 -- of this enumeration type.
234 function Make_Mode_Literal
235 (Loc
: Source_Ptr
; Mode
: Initialization_Mode
) return Node_Id
236 is (Make_Integer_Literal
(Loc
, Initialization_Mode
'Pos (Mode
)));
237 -- Generate an integer literal for a given mode value.
239 function Tag_Init_Condition
241 Init_Control_Formal
: Entity_Id
) return Node_Id
;
242 function Early_Init_Condition
244 Init_Control_Formal
: Entity_Id
) return Node_Id
;
245 function Late_Init_Condition
247 Init_Control_Formal
: Entity_Id
) return Node_Id
;
248 -- These three functions each return a Boolean expression that
249 -- can be used to determine whether a given call to the initialization
250 -- expression for a tagged type should initialize (respectively)
251 -- the Tag component, the non-Tag components that do not require late
252 -- initialization, and the components that do require late
255 end Initialization_Control
;
257 procedure Initialization_Warning
(E
: Entity_Id
);
258 -- If static elaboration of the package is requested, indicate
259 -- when a type does meet the conditions for static initialization. If
260 -- E is a type, it has components that have no static initialization.
261 -- if E is an entity, its initial expression is not compile-time known.
263 function Init_Formals
(Typ
: Entity_Id
; Proc_Id
: Entity_Id
) return List_Id
;
264 -- This function builds the list of formals for an initialization routine.
265 -- The first formal is always _Init with the given type. For task value
266 -- record types and types containing tasks, three additional formals are
267 -- added and Proc_Id is decorated with attribute Has_Master_Entity:
269 -- _Master : Master_Id
270 -- _Chain : in out Activation_Chain
271 -- _Task_Name : String
273 -- The caller must append additional entries for discriminants if required.
275 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean;
276 -- Returns true if the initialization procedure of Typ should be inlined
278 function In_Runtime
(E
: Entity_Id
) return Boolean;
279 -- Check if E is defined in the RTL (in a child of Ada or System). Used
280 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
282 function Is_Null_Statement_List
(Stmts
: List_Id
) return Boolean;
283 -- Returns true if Stmts is made of null statements only, possibly wrapped
284 -- in a case statement, recursively. This latter pattern may occur for the
285 -- initialization procedure of an unchecked union.
287 function Make_Eq_Body
289 Eq_Name
: Name_Id
) return Node_Id
;
290 -- Build the body of a primitive equality operation for a tagged record
291 -- type, or in Ada 2012 for any record type that has components with a
292 -- user-defined equality. Factored out of Predefined_Primitive_Bodies.
294 function Make_Eq_Case
297 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
;
298 -- Building block for variant record equality. Defined to share the code
299 -- between the tagged and untagged case. Given a Component_List node CL,
300 -- it generates an 'if' followed by a 'case' statement that compares all
301 -- components of local temporaries named X and Y (that are declared as
302 -- formals at some upper level). E provides the Sloc to be used for the
305 -- IF E is an unchecked_union, Discrs is the list of formals created for
306 -- the inferred discriminants of one operand. These formals are used in
307 -- the generated case statements for each variant of the unchecked union.
311 L
: List_Id
) return Node_Id
;
312 -- Building block for variant record equality. Defined to share the code
313 -- between the tagged and untagged case. Given the list of components
314 -- (or discriminants) L, it generates a return statement that compares all
315 -- components of local temporaries named X and Y (that are declared as
316 -- formals at some upper level). E provides the Sloc to be used for the
319 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
;
320 -- Search for a renaming of the inequality dispatching primitive of
321 -- this tagged type. If found then build and return the corresponding
322 -- rename-as-body inequality subprogram; otherwise return Empty.
324 procedure Make_Predefined_Primitive_Specs
325 (Tag_Typ
: Entity_Id
;
326 Predef_List
: out List_Id
;
327 Renamed_Eq
: out Entity_Id
);
328 -- Create a list with the specs of the predefined primitive operations.
329 -- For tagged types that are interfaces all these primitives are defined
332 -- The following entries are present for all tagged types, and provide
333 -- the results of the corresponding attribute applied to the object.
334 -- Dispatching is required in general, since the result of the attribute
335 -- will vary with the actual object subtype.
337 -- _size provides result of 'Size attribute
338 -- typSR provides result of 'Read attribute
339 -- typSW provides result of 'Write attribute
340 -- typSI provides result of 'Input attribute
341 -- typSO provides result of 'Output attribute
342 -- typPI provides result of 'Put_Image attribute
344 -- The following entries are additionally present for non-limited tagged
345 -- types, and implement additional dispatching operations for predefined
348 -- _equality implements "=" operator
349 -- _assign implements assignment operation
350 -- typDF implements deep finalization
351 -- typDA implements deep adjust
353 -- The latter two are empty procedures unless the type contains some
354 -- controlled components that require finalization actions (the deep
355 -- in the name refers to the fact that the action applies to components).
357 -- The list of specs is returned in Predef_List
359 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean;
360 -- Returns True if there are representation clauses for type T that are not
361 -- inherited. If the result is false, the init_proc and the discriminant
362 -- checking functions of the parent can be reused by a derived type.
364 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
;
365 -- Ada 2005 (AI-251): Makes specs for null procedures associated with any
366 -- null procedures inherited from an interface type that have not been
367 -- overridden. Only one null procedure will be created for a given set of
368 -- inherited null procedures with homographic profiles.
370 function Predef_Spec_Or_Body
375 Ret_Type
: Entity_Id
:= Empty
;
376 For_Body
: Boolean := False) return Node_Id
;
377 -- This function generates the appropriate expansion for a predefined
378 -- primitive operation specified by its name, parameter profile and
379 -- return type (Empty means this is a procedure). If For_Body is false,
380 -- then the returned node is a subprogram declaration. If For_Body is
381 -- true, then the returned node is a empty subprogram body containing
382 -- no declarations and no statements.
384 function Predef_Stream_Attr_Spec
387 Name
: TSS_Name_Type
) return Node_Id
;
388 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
389 -- input and output attribute whose specs are constructed in Exp_Strm.
391 function Predef_Deep_Spec
394 Name
: TSS_Name_Type
;
395 For_Body
: Boolean := False) return Node_Id
;
396 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
397 -- and _deep_finalize
399 function Predefined_Primitive_Bodies
400 (Tag_Typ
: Entity_Id
;
401 Renamed_Eq
: Entity_Id
) return List_Id
;
402 -- Create the bodies of the predefined primitives that are described in
403 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
404 -- the defining unit name of the type's predefined equality as returned
405 -- by Make_Predefined_Primitive_Specs.
407 function Predefined_Primitive_Freeze
(Tag_Typ
: Entity_Id
) return List_Id
;
408 -- Freeze entities of all predefined primitive operations. This is needed
409 -- because the bodies of these operations do not normally do any freezing.
411 --------------------------
412 -- Adjust_Discriminants --
413 --------------------------
415 -- This procedure attempts to define subtypes for discriminants that are
416 -- more restrictive than those declared. Such a replacement is possible if
417 -- we can demonstrate that values outside the restricted range would cause
418 -- constraint errors in any case. The advantage of restricting the
419 -- discriminant types in this way is that the maximum size of the variant
420 -- record can be calculated more conservatively.
422 -- An example of a situation in which we can perform this type of
423 -- restriction is the following:
425 -- subtype B is range 1 .. 10;
426 -- type Q is array (B range <>) of Integer;
428 -- type V (N : Natural) is record
432 -- In this situation, we can restrict the upper bound of N to 10, since
433 -- any larger value would cause a constraint error in any case.
435 -- There are many situations in which such restriction is possible, but
436 -- for now, we just look for cases like the above, where the component
437 -- in question is a one dimensional array whose upper bound is one of
438 -- the record discriminants. Also the component must not be part of
439 -- any variant part, since then the component does not always exist.
441 procedure Adjust_Discriminants
(Rtype
: Entity_Id
) is
442 Loc
: constant Source_Ptr
:= Sloc
(Rtype
);
459 Comp
:= First_Component
(Rtype
);
460 while Present
(Comp
) loop
462 -- If our parent is a variant, quit, we do not look at components
463 -- that are in variant parts, because they may not always exist.
465 P
:= Parent
(Comp
); -- component declaration
466 P
:= Parent
(P
); -- component list
468 exit when Nkind
(Parent
(P
)) = N_Variant
;
470 -- We are looking for a one dimensional array type
472 Ctyp
:= Etype
(Comp
);
474 if not Is_Array_Type
(Ctyp
) or else Number_Dimensions
(Ctyp
) > 1 then
478 -- The lower bound must be constant, and the upper bound is a
479 -- discriminant (which is a discriminant of the current record).
481 Ityp
:= Etype
(First_Index
(Ctyp
));
482 Lo
:= Type_Low_Bound
(Ityp
);
483 Hi
:= Type_High_Bound
(Ityp
);
485 if not Compile_Time_Known_Value
(Lo
)
486 or else Nkind
(Hi
) /= N_Identifier
487 or else No
(Entity
(Hi
))
488 or else Ekind
(Entity
(Hi
)) /= E_Discriminant
493 -- We have an array with appropriate bounds
495 Loval
:= Expr_Value
(Lo
);
496 Discr
:= Entity
(Hi
);
497 Dtyp
:= Etype
(Discr
);
499 -- See if the discriminant has a known upper bound
501 Dhi
:= Type_High_Bound
(Dtyp
);
503 if not Compile_Time_Known_Value
(Dhi
) then
507 Dhiv
:= Expr_Value
(Dhi
);
509 -- See if base type of component array has known upper bound
511 Ahi
:= Type_High_Bound
(Etype
(First_Index
(Base_Type
(Ctyp
))));
513 if not Compile_Time_Known_Value
(Ahi
) then
517 Ahiv
:= Expr_Value
(Ahi
);
519 -- The condition for doing the restriction is that the high bound
520 -- of the discriminant is greater than the low bound of the array,
521 -- and is also greater than the high bound of the base type index.
523 if Dhiv
> Loval
and then Dhiv
> Ahiv
then
525 -- We can reset the upper bound of the discriminant type to
526 -- whichever is larger, the low bound of the component, or
527 -- the high bound of the base type array index.
529 -- We build a subtype that is declared as
531 -- subtype Tnn is discr_type range discr_type'First .. max;
533 -- And insert this declaration into the tree. The type of the
534 -- discriminant is then reset to this more restricted subtype.
536 Tnn
:= Make_Temporary
(Loc
, 'T');
538 Insert_Action
(Declaration_Node
(Rtype
),
539 Make_Subtype_Declaration
(Loc
,
540 Defining_Identifier
=> Tnn
,
541 Subtype_Indication
=>
542 Make_Subtype_Indication
(Loc
,
543 Subtype_Mark
=> New_Occurrence_Of
(Dtyp
, Loc
),
545 Make_Range_Constraint
(Loc
,
549 Make_Attribute_Reference
(Loc
,
550 Attribute_Name
=> Name_First
,
551 Prefix
=> New_Occurrence_Of
(Dtyp
, Loc
)),
553 Make_Integer_Literal
(Loc
,
554 Intval
=> UI_Max
(Loval
, Ahiv
)))))));
556 Set_Etype
(Discr
, Tnn
);
560 Next_Component
(Comp
);
562 end Adjust_Discriminants
;
564 ------------------------------------------
565 -- Build_Access_Subprogram_Wrapper_Body --
566 ------------------------------------------
568 procedure Build_Access_Subprogram_Wrapper_Body
572 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
573 Actuals
: constant List_Id
:= New_List
;
574 Type_Def
: constant Node_Id
:= Type_Definition
(Decl
);
575 Type_Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
576 Spec_Node
: constant Node_Id
:=
577 Copy_Subprogram_Spec
(Specification
(New_Decl
));
578 -- This copy creates new identifiers for formals and subprogram.
586 -- Create List of actuals for indirect call. The last parameter of the
587 -- subprogram declaration is the access value for the indirect call.
589 Act
:= First
(Parameter_Specifications
(Spec_Node
));
591 while Present
(Act
) loop
592 exit when Act
= Last
(Parameter_Specifications
(Spec_Node
));
594 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Act
))));
600 (Last
(Parameter_Specifications
(Specification
(New_Decl
))));
602 if Nkind
(Type_Def
) = N_Access_Procedure_Definition
then
603 Call_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
605 Make_Explicit_Dereference
606 (Loc
, New_Occurrence_Of
(Ptr
, Loc
)),
607 Parameter_Associations
=> Actuals
);
609 Call_Stmt
:= Make_Simple_Return_Statement
(Loc
,
611 Make_Function_Call
(Loc
,
612 Name
=> Make_Explicit_Dereference
613 (Loc
, New_Occurrence_Of
(Ptr
, Loc
)),
614 Parameter_Associations
=> Actuals
));
617 Body_Node
:= Make_Subprogram_Body
(Loc
,
618 Specification
=> Spec_Node
,
619 Declarations
=> New_List
,
620 Handled_Statement_Sequence
=>
621 Make_Handled_Sequence_Of_Statements
(Loc
,
622 Statements
=> New_List
(Call_Stmt
)));
624 -- Place body in list of freeze actions for the type.
626 Append_Freeze_Action
(Type_Id
, Body_Node
);
627 end Build_Access_Subprogram_Wrapper_Body
;
629 ---------------------------
630 -- Build_Array_Init_Proc --
631 ---------------------------
633 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
) is
634 Comp_Type
: constant Entity_Id
:= Component_Type
(A_Type
);
635 Comp_Simple_Init
: constant Boolean :=
636 Needs_Simple_Initialization
639 not (Validity_Check_Copies
and Is_Bit_Packed_Array
(A_Type
)));
640 -- True if the component needs simple initialization, based on its type,
641 -- plus the fact that we do not do simple initialization for components
642 -- of bit-packed arrays when validity checks are enabled, because the
643 -- initialization with deliberately out-of-range values would raise
646 Body_Stmts
: List_Id
;
647 Has_Default_Init
: Boolean;
648 Index_List
: List_Id
;
650 Parameters
: List_Id
;
653 function Init_Component
return List_Id
;
654 -- Create one statement to initialize one array component, designated
655 -- by a full set of indexes.
657 function Init_One_Dimension
(N
: Int
) return List_Id
;
658 -- Create loop to initialize one dimension of the array. The single
659 -- statement in the loop body initializes the inner dimensions if any,
660 -- or else the single component. Note that this procedure is called
661 -- recursively, with N being the dimension to be initialized. A call
662 -- with N greater than the number of dimensions simply generates the
663 -- component initialization, terminating the recursion.
669 function Init_Component
return List_Id
is
674 Make_Indexed_Component
(Loc
,
675 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
676 Expressions
=> Index_List
);
678 if Has_Default_Aspect
(A_Type
) then
679 Set_Assignment_OK
(Comp
);
681 Make_Assignment_Statement
(Loc
,
684 Convert_To
(Comp_Type
,
685 Default_Aspect_Component_Value
(First_Subtype
(A_Type
)))));
687 elsif Comp_Simple_Init
then
688 Set_Assignment_OK
(Comp
);
690 Make_Assignment_Statement
(Loc
,
696 Size
=> Component_Size
(A_Type
))));
699 Clean_Task_Names
(Comp_Type
, Proc_Id
);
701 Build_Initialization_Call
705 In_Init_Proc
=> True,
706 Enclos_Type
=> A_Type
);
710 ------------------------
711 -- Init_One_Dimension --
712 ------------------------
714 function Init_One_Dimension
(N
: Int
) return List_Id
is
717 Result_List
: List_Id
;
719 function Possible_DIC_Call
return Node_Id
;
720 -- If the component type has Default_Initial_Conditions and a DIC
721 -- procedure that is not an empty body, then builds a call to the
722 -- DIC procedure and returns it.
724 -----------------------
725 -- Possible_DIC_Call --
726 -----------------------
728 function Possible_DIC_Call
return Node_Id
is
730 -- When the component's type has a Default_Initial_Condition, then
731 -- create a call for the DIC check.
733 if Has_DIC
(Comp_Type
)
734 -- In GNATprove mode, the component DICs are checked by other
735 -- means. They should not be added to the record type DIC
736 -- procedure, so that the procedure can be used to check the
737 -- record type invariants or DICs if any.
739 and then not GNATprove_Mode
741 -- DIC checks for components of controlled types are done later
742 -- (see Exp_Ch7.Make_Deep_Array_Body).
744 and then not Is_Controlled
(Comp_Type
)
746 and then Present
(DIC_Procedure
(Comp_Type
))
748 and then not Has_Null_Body
(DIC_Procedure
(Comp_Type
))
752 Make_Indexed_Component
(Loc
,
753 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
754 Expressions
=> Index_List
),
759 end Possible_DIC_Call
;
761 -- Start of processing for Init_One_Dimension
764 -- If the component does not need initializing, then there is nothing
765 -- to do here, so we return a null body. This occurs when generating
766 -- the dummy Init_Proc needed for Initialize_Scalars processing.
767 -- An exception is if component type has a Default_Initial_Condition,
768 -- in which case we generate a call to the type's DIC procedure.
770 if not Has_Non_Null_Base_Init_Proc
(Comp_Type
)
771 and then not Comp_Simple_Init
772 and then not Has_Task
(Comp_Type
)
773 and then not Has_Default_Aspect
(A_Type
)
774 and then (not Has_DIC
(Comp_Type
)
775 or else N
> Number_Dimensions
(A_Type
))
777 DIC_Call
:= Possible_DIC_Call
;
779 if Present
(DIC_Call
) then
780 return New_List
(DIC_Call
);
782 return New_List
(Make_Null_Statement
(Loc
));
785 -- If all dimensions dealt with, we simply initialize the component
786 -- and append a call to component type's DIC procedure when needed.
788 elsif N
> Number_Dimensions
(A_Type
) then
789 DIC_Call
:= Possible_DIC_Call
;
791 if Present
(DIC_Call
) then
792 Result_List
:= Init_Component
;
793 Append
(DIC_Call
, Result_List
);
797 return Init_Component
;
800 -- Here we generate the required loop
804 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
806 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
809 Make_Implicit_Loop_Statement
(Nod
,
812 Make_Iteration_Scheme
(Loc
,
813 Loop_Parameter_Specification
=>
814 Make_Loop_Parameter_Specification
(Loc
,
815 Defining_Identifier
=> Index
,
816 Discrete_Subtype_Definition
=>
817 Make_Attribute_Reference
(Loc
,
819 Make_Identifier
(Loc
, Name_uInit
),
820 Attribute_Name
=> Name_Range
,
821 Expressions
=> New_List
(
822 Make_Integer_Literal
(Loc
, N
))))),
823 Statements
=> Init_One_Dimension
(N
+ 1)));
825 end Init_One_Dimension
;
827 -- Start of processing for Build_Array_Init_Proc
830 -- The init proc is created when analyzing the freeze node for the type,
831 -- but it properly belongs with the array type declaration. However, if
832 -- the freeze node is for a subtype of a type declared in another unit
833 -- it seems preferable to use the freeze node as the source location of
834 -- the init proc. In any case this is preferable for gcov usage, and
835 -- the Sloc is not otherwise used by the compiler.
837 if In_Open_Scopes
(Scope
(A_Type
)) then
838 Loc
:= Sloc
(A_Type
);
843 -- Nothing to generate in the following cases:
845 -- 1. Initialization is suppressed for the type
846 -- 2. An initialization already exists for the base type
848 if Initialization_Suppressed
(A_Type
)
849 or else Present
(Base_Init_Proc
(A_Type
))
854 Index_List
:= New_List
;
856 -- We need an initialization procedure if any of the following is true:
858 -- 1. The component type has an initialization procedure
859 -- 2. The component type needs simple initialization
860 -- 3. Tasks are present
861 -- 4. The type is marked as a public entity
862 -- 5. The array type has a Default_Component_Value aspect
863 -- 6. The array component type has a Default_Initialization_Condition
865 -- The reason for the public entity test is to deal properly with the
866 -- Initialize_Scalars pragma. This pragma can be set in the client and
867 -- not in the declaring package, this means the client will make a call
868 -- to the initialization procedure (because one of conditions 1-3 must
869 -- apply in this case), and we must generate a procedure (even if it is
870 -- null) to satisfy the call in this case.
872 -- Exception: do not build an array init_proc for a type whose root
873 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
874 -- is no place to put the code, and in any case we handle initialization
875 -- of such types (in the Initialize_Scalars case, that's the only time
876 -- the issue arises) in a special manner anyway which does not need an
879 Has_Default_Init
:= Has_Non_Null_Base_Init_Proc
(Comp_Type
)
880 or else Comp_Simple_Init
881 or else Has_Task
(Comp_Type
)
882 or else Has_Default_Aspect
(A_Type
)
883 or else Has_DIC
(Comp_Type
);
886 or else (not Restriction_Active
(No_Initialize_Scalars
)
887 and then Is_Public
(A_Type
)
888 and then not Is_Standard_String_Type
(A_Type
))
891 Make_Defining_Identifier
(Loc
,
892 Chars
=> Make_Init_Proc_Name
(A_Type
));
894 -- If No_Default_Initialization restriction is active, then we don't
895 -- want to build an init_proc, but we need to mark that an init_proc
896 -- would be needed if this restriction was not active (so that we can
897 -- detect attempts to call it), so set a dummy init_proc in place.
898 -- This is only done though when actual default initialization is
899 -- needed (and not done when only Is_Public is True), since otherwise
900 -- objects such as arrays of scalars could be wrongly flagged as
901 -- violating the restriction.
903 if Restriction_Active
(No_Default_Initialization
) then
904 if Has_Default_Init
then
905 Set_Init_Proc
(A_Type
, Proc_Id
);
911 Body_Stmts
:= Init_One_Dimension
(1);
912 Parameters
:= Init_Formals
(A_Type
, Proc_Id
);
915 Make_Subprogram_Body
(Loc
,
917 Make_Procedure_Specification
(Loc
,
918 Defining_Unit_Name
=> Proc_Id
,
919 Parameter_Specifications
=> Parameters
),
920 Declarations
=> New_List
,
921 Handled_Statement_Sequence
=>
922 Make_Handled_Sequence_Of_Statements
(Loc
,
923 Statements
=> Body_Stmts
)));
925 Mutate_Ekind
(Proc_Id
, E_Procedure
);
926 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
927 Set_Is_Internal
(Proc_Id
);
928 Set_Has_Completion
(Proc_Id
);
930 if not Debug_Generated_Code
then
931 Set_Debug_Info_Off
(Proc_Id
);
934 -- Set Inlined on Init_Proc if it is set on the Init_Proc of the
935 -- component type itself (see also Build_Record_Init_Proc).
937 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Comp_Type
));
939 -- Associate Init_Proc with type, and determine if the procedure
940 -- is null (happens because of the Initialize_Scalars pragma case,
941 -- where we have to generate a null procedure in case it is called
942 -- by a client with Initialize_Scalars set). Such procedures have
943 -- to be generated, but do not have to be called, so we mark them
944 -- as null to suppress the call. Kill also warnings for the _Init
945 -- out parameter, which is left entirely uninitialized.
947 Set_Init_Proc
(A_Type
, Proc_Id
);
949 if Is_Null_Statement_List
(Body_Stmts
) then
950 Set_Is_Null_Init_Proc
(Proc_Id
);
951 Set_Warnings_Off
(Defining_Identifier
(First
(Parameters
)));
954 -- Try to build a static aggregate to statically initialize
955 -- objects of the type. This can only be done for constrained
956 -- one-dimensional arrays with static bounds.
958 Set_Static_Initialization
960 Build_Equivalent_Array_Aggregate
(First_Subtype
(A_Type
)));
963 end Build_Array_Init_Proc
;
965 --------------------------------
966 -- Build_Discr_Checking_Funcs --
967 --------------------------------
969 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
) is
972 Enclosing_Func_Id
: Entity_Id
;
977 function Build_Case_Statement
978 (Case_Id
: Entity_Id
;
979 Variant
: Node_Id
) return Node_Id
;
980 -- Build a case statement containing only two alternatives. The first
981 -- alternative corresponds to the discrete choices given on the variant
982 -- that contains the components that we are generating the checks
983 -- for. If the discriminant is one of these return False. The second
984 -- alternative is an OTHERS choice that returns True indicating the
985 -- discriminant did not match.
987 function Build_Dcheck_Function
988 (Case_Id
: Entity_Id
;
989 Variant
: Node_Id
) return Entity_Id
;
990 -- Build the discriminant checking function for a given variant
992 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
);
993 -- Builds the discriminant checking function for each variant of the
994 -- given variant part of the record type.
996 --------------------------
997 -- Build_Case_Statement --
998 --------------------------
1000 function Build_Case_Statement
1001 (Case_Id
: Entity_Id
;
1002 Variant
: Node_Id
) return Node_Id
1004 Alt_List
: constant List_Id
:= New_List
;
1005 Actuals_List
: List_Id
;
1006 Case_Node
: Node_Id
;
1007 Case_Alt_Node
: Node_Id
;
1009 Choice_List
: List_Id
;
1011 Return_Node
: Node_Id
;
1014 Case_Node
:= New_Node
(N_Case_Statement
, Loc
);
1015 Set_End_Span
(Case_Node
, Uint_0
);
1017 -- Replace the discriminant which controls the variant with the name
1018 -- of the formal of the checking function.
1020 Set_Expression
(Case_Node
, Make_Identifier
(Loc
, Chars
(Case_Id
)));
1022 Choice
:= First
(Discrete_Choices
(Variant
));
1024 if Nkind
(Choice
) = N_Others_Choice
then
1025 Choice_List
:= New_Copy_List
(Others_Discrete_Choices
(Choice
));
1027 Choice_List
:= New_Copy_List
(Discrete_Choices
(Variant
));
1030 if not Is_Empty_List
(Choice_List
) then
1031 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1032 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1034 -- In case this is a nested variant, we need to return the result
1035 -- of the discriminant checking function for the immediately
1036 -- enclosing variant.
1038 if Present
(Enclosing_Func_Id
) then
1039 Actuals_List
:= New_List
;
1041 D
:= First_Discriminant
(Rec_Id
);
1042 while Present
(D
) loop
1043 Append
(Make_Identifier
(Loc
, Chars
(D
)), Actuals_List
);
1044 Next_Discriminant
(D
);
1048 Make_Simple_Return_Statement
(Loc
,
1050 Make_Function_Call
(Loc
,
1052 New_Occurrence_Of
(Enclosing_Func_Id
, Loc
),
1053 Parameter_Associations
=>
1058 Make_Simple_Return_Statement
(Loc
,
1060 New_Occurrence_Of
(Standard_False
, Loc
));
1063 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1064 Append
(Case_Alt_Node
, Alt_List
);
1067 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1068 Choice_List
:= New_List
(New_Node
(N_Others_Choice
, Loc
));
1069 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1072 Make_Simple_Return_Statement
(Loc
,
1074 New_Occurrence_Of
(Standard_True
, Loc
));
1076 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1077 Append
(Case_Alt_Node
, Alt_List
);
1079 Set_Alternatives
(Case_Node
, Alt_List
);
1081 end Build_Case_Statement
;
1083 ---------------------------
1084 -- Build_Dcheck_Function --
1085 ---------------------------
1087 function Build_Dcheck_Function
1088 (Case_Id
: Entity_Id
;
1089 Variant
: Node_Id
) return Entity_Id
1091 Body_Node
: Node_Id
;
1092 Func_Id
: Entity_Id
;
1093 Parameter_List
: List_Id
;
1094 Spec_Node
: Node_Id
;
1097 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
1098 Sequence
:= Sequence
+ 1;
1101 Make_Defining_Identifier
(Loc
,
1102 Chars
=> New_External_Name
(Chars
(Rec_Id
), 'D', Sequence
));
1103 Set_Is_Discriminant_Check_Function
(Func_Id
);
1105 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
1106 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
1108 Parameter_List
:= Build_Discriminant_Formals
(Rec_Id
, False);
1110 Set_Parameter_Specifications
(Spec_Node
, Parameter_List
);
1111 Set_Result_Definition
(Spec_Node
,
1112 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1113 Set_Specification
(Body_Node
, Spec_Node
);
1114 Set_Declarations
(Body_Node
, New_List
);
1116 Set_Handled_Statement_Sequence
(Body_Node
,
1117 Make_Handled_Sequence_Of_Statements
(Loc
,
1118 Statements
=> New_List
(
1119 Build_Case_Statement
(Case_Id
, Variant
))));
1121 Mutate_Ekind
(Func_Id
, E_Function
);
1122 Set_Mechanism
(Func_Id
, Default_Mechanism
);
1123 Set_Is_Inlined
(Func_Id
, True);
1124 Set_Is_Pure
(Func_Id
, True);
1125 Set_Is_Public
(Func_Id
, Is_Public
(Rec_Id
));
1126 Set_Is_Internal
(Func_Id
, True);
1128 if not Debug_Generated_Code
then
1129 Set_Debug_Info_Off
(Func_Id
);
1132 Analyze
(Body_Node
);
1134 Append_Freeze_Action
(Rec_Id
, Body_Node
);
1135 Set_Dcheck_Function
(Variant
, Func_Id
);
1137 end Build_Dcheck_Function
;
1139 ----------------------------
1140 -- Build_Dcheck_Functions --
1141 ----------------------------
1143 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
) is
1144 Component_List_Node
: Node_Id
;
1146 Discr_Name
: Entity_Id
;
1147 Func_Id
: Entity_Id
;
1149 Saved_Enclosing_Func_Id
: Entity_Id
;
1152 -- Build the discriminant-checking function for each variant, and
1153 -- label all components of that variant with the function's name.
1154 -- We only Generate a discriminant-checking function when the
1155 -- variant is not empty, to prevent the creation of dead code.
1157 Discr_Name
:= Entity
(Name
(Variant_Part_Node
));
1158 Variant
:= First_Non_Pragma
(Variants
(Variant_Part_Node
));
1160 while Present
(Variant
) loop
1161 Component_List_Node
:= Component_List
(Variant
);
1163 if not Null_Present
(Component_List_Node
) then
1164 Func_Id
:= Build_Dcheck_Function
(Discr_Name
, Variant
);
1167 First_Non_Pragma
(Component_Items
(Component_List_Node
));
1168 while Present
(Decl
) loop
1169 Set_Discriminant_Checking_Func
1170 (Defining_Identifier
(Decl
), Func_Id
);
1171 Next_Non_Pragma
(Decl
);
1174 if Present
(Variant_Part
(Component_List_Node
)) then
1175 Saved_Enclosing_Func_Id
:= Enclosing_Func_Id
;
1176 Enclosing_Func_Id
:= Func_Id
;
1177 Build_Dcheck_Functions
(Variant_Part
(Component_List_Node
));
1178 Enclosing_Func_Id
:= Saved_Enclosing_Func_Id
;
1182 Next_Non_Pragma
(Variant
);
1184 end Build_Dcheck_Functions
;
1186 -- Start of processing for Build_Discr_Checking_Funcs
1189 -- Only build if not done already
1191 if not Discr_Check_Funcs_Built
(N
) then
1192 Type_Def
:= Type_Definition
(N
);
1194 if Nkind
(Type_Def
) = N_Record_Definition
then
1195 if No
(Component_List
(Type_Def
)) then -- null record.
1198 V
:= Variant_Part
(Component_List
(Type_Def
));
1201 else pragma Assert
(Nkind
(Type_Def
) = N_Derived_Type_Definition
);
1202 if No
(Component_List
(Record_Extension_Part
(Type_Def
))) then
1206 (Component_List
(Record_Extension_Part
(Type_Def
)));
1210 Rec_Id
:= Defining_Identifier
(N
);
1212 if Present
(V
) and then not Is_Unchecked_Union
(Rec_Id
) then
1214 Enclosing_Func_Id
:= Empty
;
1215 Build_Dcheck_Functions
(V
);
1218 Set_Discr_Check_Funcs_Built
(N
);
1220 end Build_Discr_Checking_Funcs
;
1222 ----------------------------------------
1223 -- Build_Or_Copy_Discr_Checking_Funcs --
1224 ----------------------------------------
1226 procedure Build_Or_Copy_Discr_Checking_Funcs
(N
: Node_Id
) is
1227 Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
1229 if Is_Unchecked_Union
(Typ
) or else not Has_Discriminants
(Typ
) then
1231 elsif not Is_Derived_Type
(Typ
)
1232 or else Has_New_Non_Standard_Rep
(Typ
)
1233 or else Is_Tagged_Type
(Typ
)
1235 Build_Discr_Checking_Funcs
(N
);
1237 Copy_Discr_Checking_Funcs
(N
);
1239 end Build_Or_Copy_Discr_Checking_Funcs
;
1241 --------------------------------
1242 -- Build_Discriminant_Formals --
1243 --------------------------------
1245 function Build_Discriminant_Formals
1246 (Rec_Id
: Entity_Id
;
1247 Use_Dl
: Boolean) return List_Id
1249 Loc
: Source_Ptr
:= Sloc
(Rec_Id
);
1250 Parameter_List
: constant List_Id
:= New_List
;
1253 Formal_Type
: Entity_Id
;
1254 Param_Spec_Node
: Node_Id
;
1257 if Has_Discriminants
(Rec_Id
) then
1258 D
:= First_Discriminant
(Rec_Id
);
1259 while Present
(D
) loop
1263 Formal
:= Discriminal
(D
);
1264 Formal_Type
:= Etype
(Formal
);
1266 Formal
:= Make_Defining_Identifier
(Loc
, Chars
(D
));
1267 Formal_Type
:= Etype
(D
);
1271 Make_Parameter_Specification
(Loc
,
1272 Defining_Identifier
=> Formal
,
1274 New_Occurrence_Of
(Formal_Type
, Loc
));
1275 Append
(Param_Spec_Node
, Parameter_List
);
1276 Next_Discriminant
(D
);
1280 return Parameter_List
;
1281 end Build_Discriminant_Formals
;
1283 --------------------------------------
1284 -- Build_Equivalent_Array_Aggregate --
1285 --------------------------------------
1287 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
is
1288 Loc
: constant Source_Ptr
:= Sloc
(T
);
1289 Comp_Type
: constant Entity_Id
:= Component_Type
(T
);
1290 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(T
));
1291 Proc
: constant Entity_Id
:= Base_Init_Proc
(T
);
1297 if not Is_Constrained
(T
)
1298 or else Number_Dimensions
(T
) > 1
1301 Initialization_Warning
(T
);
1305 Lo
:= Type_Low_Bound
(Index_Type
);
1306 Hi
:= Type_High_Bound
(Index_Type
);
1308 if not Compile_Time_Known_Value
(Lo
)
1309 or else not Compile_Time_Known_Value
(Hi
)
1311 Initialization_Warning
(T
);
1315 if Is_Record_Type
(Comp_Type
)
1316 and then Present
(Base_Init_Proc
(Comp_Type
))
1318 Expr
:= Static_Initialization
(Base_Init_Proc
(Comp_Type
));
1321 Initialization_Warning
(T
);
1326 Initialization_Warning
(T
);
1330 Aggr
:= Make_Aggregate
(Loc
, No_List
, New_List
);
1331 Set_Etype
(Aggr
, T
);
1332 Set_Aggregate_Bounds
(Aggr
,
1334 Low_Bound
=> New_Copy
(Lo
),
1335 High_Bound
=> New_Copy
(Hi
)));
1336 Set_Parent
(Aggr
, Parent
(Proc
));
1338 Append_To
(Component_Associations
(Aggr
),
1339 Make_Component_Association
(Loc
,
1343 Low_Bound
=> New_Copy
(Lo
),
1344 High_Bound
=> New_Copy
(Hi
))),
1345 Expression
=> Expr
));
1347 if Static_Array_Aggregate
(Aggr
) then
1350 Initialization_Warning
(T
);
1353 end Build_Equivalent_Array_Aggregate
;
1355 ---------------------------------------
1356 -- Build_Equivalent_Record_Aggregate --
1357 ---------------------------------------
1359 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
is
1362 Comp_Type
: Entity_Id
;
1365 if not Is_Record_Type
(T
)
1366 or else Has_Discriminants
(T
)
1367 or else Is_Limited_Type
(T
)
1368 or else Has_Non_Standard_Rep
(T
)
1370 Initialization_Warning
(T
);
1374 Comp
:= First_Component
(T
);
1376 -- A null record needs no warning
1382 while Present
(Comp
) loop
1384 -- Array components are acceptable if initialized by a positional
1385 -- aggregate with static components.
1387 if Is_Array_Type
(Etype
(Comp
)) then
1388 Comp_Type
:= Component_Type
(Etype
(Comp
));
1390 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1391 or else No
(Expression
(Parent
(Comp
)))
1392 or else Nkind
(Expression
(Parent
(Comp
))) /= N_Aggregate
1394 Initialization_Warning
(T
);
1397 elsif Is_Scalar_Type
(Component_Type
(Etype
(Comp
)))
1399 (not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1401 not Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
)))
1403 Initialization_Warning
(T
);
1407 not Static_Array_Aggregate
(Expression
(Parent
(Comp
)))
1409 Initialization_Warning
(T
);
1412 -- We need to return empty if the type has predicates because
1413 -- this would otherwise duplicate calls to the predicate
1414 -- function. If the type hasn't been frozen before being
1415 -- referenced in the current record, the extraneous call to
1416 -- the predicate function would be inserted somewhere before
1417 -- the predicate function is elaborated, which would result in
1420 elsif Has_Predicates
(Etype
(Comp
)) then
1424 elsif Is_Scalar_Type
(Etype
(Comp
)) then
1425 Comp_Type
:= Etype
(Comp
);
1427 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1428 or else No
(Expression
(Parent
(Comp
)))
1429 or else not Compile_Time_Known_Value
(Expression
(Parent
(Comp
)))
1430 or else not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1432 Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
))
1434 Initialization_Warning
(T
);
1438 -- For now, other types are excluded
1441 Initialization_Warning
(T
);
1445 Next_Component
(Comp
);
1448 -- All components have static initialization. Build positional aggregate
1449 -- from the given expressions or defaults.
1451 Agg
:= Make_Aggregate
(Sloc
(T
), New_List
, New_List
);
1452 Set_Parent
(Agg
, Parent
(T
));
1454 Comp
:= First_Component
(T
);
1455 while Present
(Comp
) loop
1457 (New_Copy_Tree
(Expression
(Parent
(Comp
))), Expressions
(Agg
));
1458 Next_Component
(Comp
);
1461 Analyze_And_Resolve
(Agg
, T
);
1463 end Build_Equivalent_Record_Aggregate
;
1465 ----------------------------
1466 -- Init_Proc_Level_Formal --
1467 ----------------------------
1469 function Init_Proc_Level_Formal
(Proc
: Entity_Id
) return Entity_Id
is
1472 -- Move through the formals of the initialization procedure Proc to find
1473 -- the extra accessibility level parameter associated with the object
1474 -- being initialized.
1476 Form
:= First_Formal
(Proc
);
1477 while Present
(Form
) loop
1478 if Chars
(Form
) = Name_uInit_Level
then
1485 -- No formal was found, return Empty
1488 end Init_Proc_Level_Formal
;
1490 -------------------------------
1491 -- Build_Initialization_Call --
1492 -------------------------------
1494 -- References to a discriminant inside the record type declaration can
1495 -- appear either in the subtype_indication to constrain a record or an
1496 -- array, or as part of a larger expression given for the initial value
1497 -- of a component. In both of these cases N appears in the record
1498 -- initialization procedure and needs to be replaced by the formal
1499 -- parameter of the initialization procedure which corresponds to that
1502 -- In the example below, references to discriminants D1 and D2 in proc_1
1503 -- are replaced by references to formals with the same name
1506 -- A similar replacement is done for calls to any record initialization
1507 -- procedure for any components that are themselves of a record type.
1509 -- type R (D1, D2 : Integer) is record
1510 -- X : Integer := F * D1;
1511 -- Y : Integer := F * D2;
1514 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1518 -- Out_2.X := F * D1;
1519 -- Out_2.Y := F * D2;
1522 function Build_Initialization_Call
1526 In_Init_Proc
: Boolean := False;
1527 Enclos_Type
: Entity_Id
:= Empty
;
1528 Discr_Map
: Elist_Id
:= New_Elmt_List
;
1529 With_Default_Init
: Boolean := False;
1530 Constructor_Ref
: Node_Id
:= Empty
;
1531 Init_Control_Actual
: Entity_Id
:= Empty
) return List_Id
1533 Res
: constant List_Id
:= New_List
;
1535 Full_Type
: Entity_Id
;
1537 procedure Check_Predicated_Discriminant
1540 -- Discriminants whose subtypes have predicates are checked in two
1542 -- a) When an object is default-initialized and assertions are enabled
1543 -- we check that the value of the discriminant obeys the predicate.
1545 -- b) In all cases, if the discriminant controls a variant and the
1546 -- variant has no others_choice, Constraint_Error must be raised if
1547 -- the predicate is violated, because there is no variant covered
1548 -- by the illegal discriminant value.
1550 -----------------------------------
1551 -- Check_Predicated_Discriminant --
1552 -----------------------------------
1554 procedure Check_Predicated_Discriminant
1558 Typ
: constant Entity_Id
:= Etype
(Discr
);
1560 procedure Check_Missing_Others
(V
: Node_Id
);
1561 -- Check that a given variant and its nested variants have an others
1562 -- choice, and generate a constraint error raise when it does not.
1564 --------------------------
1565 -- Check_Missing_Others --
1566 --------------------------
1568 procedure Check_Missing_Others
(V
: Node_Id
) is
1574 Last_Var
:= Last_Non_Pragma
(Variants
(V
));
1575 Choice
:= First
(Discrete_Choices
(Last_Var
));
1577 -- An others_choice is added during expansion for gcc use, but
1578 -- does not cover the illegality.
1580 if Entity
(Name
(V
)) = Discr
then
1582 and then (Nkind
(Choice
) /= N_Others_Choice
1583 or else not Comes_From_Source
(Choice
))
1585 Check_Expression_Against_Static_Predicate
(Val
, Typ
);
1587 if not Is_Static_Expression
(Val
) then
1589 Make_Raise_Constraint_Error
(Loc
,
1592 Right_Opnd
=> Make_Predicate_Call
(Typ
, Val
)),
1593 Reason
=> CE_Invalid_Data
));
1598 -- Check whether some nested variant is ruled by the predicated
1601 Alt
:= First
(Variants
(V
));
1602 while Present
(Alt
) loop
1603 if Nkind
(Alt
) = N_Variant
1604 and then Present
(Variant_Part
(Component_List
(Alt
)))
1606 Check_Missing_Others
1607 (Variant_Part
(Component_List
(Alt
)));
1612 end Check_Missing_Others
;
1618 -- Start of processing for Check_Predicated_Discriminant
1621 if Ekind
(Base_Type
(Full_Type
)) = E_Record_Type
then
1622 Def
:= Type_Definition
(Parent
(Base_Type
(Full_Type
)));
1627 if Policy_In_Effect
(Name_Assert
) = Name_Check
1628 and then not Predicates_Ignored
(Etype
(Discr
))
1630 Prepend_To
(Res
, Make_Predicate_Check
(Typ
, Val
));
1633 -- If discriminant controls a variant, verify that predicate is
1634 -- obeyed or else an Others_Choice is present.
1636 if Nkind
(Def
) = N_Record_Definition
1637 and then Present
(Variant_Part
(Component_List
(Def
)))
1638 and then Policy_In_Effect
(Name_Assert
) = Name_Ignore
1640 Check_Missing_Others
(Variant_Part
(Component_List
(Def
)));
1642 end Check_Predicated_Discriminant
;
1651 First_Arg
: Node_Id
;
1652 Full_Init_Type
: Entity_Id
;
1653 Init_Call
: Node_Id
;
1654 Init_Type
: Entity_Id
;
1657 -- Start of processing for Build_Initialization_Call
1660 pragma Assert
(Constructor_Ref
= Empty
1661 or else Is_CPP_Constructor_Call
(Constructor_Ref
));
1663 if No
(Constructor_Ref
) then
1664 Proc
:= Base_Init_Proc
(Typ
);
1666 Proc
:= Base_Init_Proc
(Typ
, Entity
(Name
(Constructor_Ref
)));
1669 pragma Assert
(Present
(Proc
));
1670 Init_Type
:= Etype
(First_Formal
(Proc
));
1671 Full_Init_Type
:= Underlying_Type
(Init_Type
);
1673 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1674 -- is active (in which case we make the call anyway, since in the
1675 -- actual compiled client it may be non null).
1677 if Is_Null_Init_Proc
(Proc
) and then not Init_Or_Norm_Scalars
then
1680 -- Nothing to do for an array of controlled components that have only
1681 -- the inherited Initialize primitive. This is a useful optimization
1684 elsif Is_Trivial_Subprogram
(Proc
)
1685 and then Is_Array_Type
(Full_Init_Type
)
1687 return New_List
(Make_Null_Statement
(Loc
));
1690 -- Use the [underlying] full view when dealing with a private type. This
1691 -- may require several steps depending on derivations.
1695 if Is_Private_Type
(Full_Type
) then
1696 if Present
(Full_View
(Full_Type
)) then
1697 Full_Type
:= Full_View
(Full_Type
);
1699 elsif Present
(Underlying_Full_View
(Full_Type
)) then
1700 Full_Type
:= Underlying_Full_View
(Full_Type
);
1702 -- When a private type acts as a generic actual and lacks a full
1703 -- view, use the base type.
1705 elsif Is_Generic_Actual_Type
(Full_Type
) then
1706 Full_Type
:= Base_Type
(Full_Type
);
1708 elsif Ekind
(Full_Type
) = E_Private_Subtype
1709 and then (not Has_Discriminants
(Full_Type
)
1710 or else No
(Discriminant_Constraint
(Full_Type
)))
1712 Full_Type
:= Etype
(Full_Type
);
1714 -- The loop has recovered the [underlying] full view, stop the
1721 -- The type is not private, nothing to do
1728 -- If Typ is derived, the procedure is the initialization procedure for
1729 -- the root type. Wrap the argument in an conversion to make it type
1730 -- honest. Actually it isn't quite type honest, because there can be
1731 -- conflicts of views in the private type case. That is why we set
1732 -- Conversion_OK in the conversion node.
1734 if (Is_Record_Type
(Typ
)
1735 or else Is_Array_Type
(Typ
)
1736 or else Is_Private_Type
(Typ
))
1737 and then Init_Type
/= Base_Type
(Typ
)
1739 First_Arg
:= OK_Convert_To
(Etype
(Init_Type
), Id_Ref
);
1740 Set_Etype
(First_Arg
, Init_Type
);
1743 First_Arg
:= Id_Ref
;
1746 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Typ
));
1748 -- In the tasks case, add _Master as the value of the _Master parameter
1749 -- and _Chain as the value of the _Chain parameter. At the outer level,
1750 -- these will be variables holding the corresponding values obtained
1751 -- from GNARL. At inner levels, they will be the parameters passed down
1752 -- through the outer routines.
1754 if Has_Task
(Full_Type
) then
1755 if Restriction_Active
(No_Task_Hierarchy
) then
1756 Append_To
(Args
, Make_Integer_Literal
(Loc
, Library_Task_Level
));
1758 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1761 -- Add _Chain (not done for sequential elaboration policy, see
1762 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1764 if Partition_Elaboration_Policy
/= 'S' then
1765 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1768 -- Ada 2005 (AI-287): In case of default initialized components
1769 -- with tasks, we generate a null string actual parameter.
1770 -- This is just a workaround that must be improved later???
1772 if With_Default_Init
then
1774 Make_String_Literal
(Loc
,
1779 Build_Task_Image_Decls
(Loc
, Id_Ref
, Enclos_Type
, In_Init_Proc
);
1780 Decl
:= Last
(Decls
);
1783 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
));
1784 Append_List
(Decls
, Res
);
1792 -- Handle the optionally generated formal *_skip_null_excluding_checks
1794 -- Look at the associated node for the object we are referencing and
1795 -- verify that we are expanding a call to an Init_Proc for an internally
1796 -- generated object declaration before passing True and skipping the
1799 if Needs_Conditional_Null_Excluding_Check
(Full_Init_Type
)
1800 and then Nkind
(Id_Ref
) in N_Has_Entity
1801 and then (Comes_From_Source
(Id_Ref
)
1802 or else (Present
(Associated_Node
(Id_Ref
))
1803 and then Comes_From_Source
1804 (Associated_Node
(Id_Ref
))))
1806 Append_To
(Args
, New_Occurrence_Of
(Standard_True
, Loc
));
1809 -- Add discriminant values if discriminants are present
1811 if Has_Discriminants
(Full_Init_Type
) then
1812 Discr
:= First_Discriminant
(Full_Init_Type
);
1813 while Present
(Discr
) loop
1815 -- If this is a discriminated concurrent type, the init_proc
1816 -- for the corresponding record is being called. Use that type
1817 -- directly to find the discriminant value, to handle properly
1818 -- intervening renamed discriminants.
1821 T
: Entity_Id
:= Full_Type
;
1824 if Is_Protected_Type
(T
) then
1825 T
:= Corresponding_Record_Type
(T
);
1829 Get_Discriminant_Value
(
1832 Discriminant_Constraint
(Full_Type
));
1835 -- If the target has access discriminants, and is constrained by
1836 -- an access to the enclosing construct, i.e. a current instance,
1837 -- replace the reference to the type by a reference to the object.
1839 if Nkind
(Arg
) = N_Attribute_Reference
1840 and then Is_Access_Type
(Etype
(Arg
))
1841 and then Is_Entity_Name
(Prefix
(Arg
))
1842 and then Is_Type
(Entity
(Prefix
(Arg
)))
1845 Make_Attribute_Reference
(Loc
,
1846 Prefix
=> New_Copy
(Prefix
(Id_Ref
)),
1847 Attribute_Name
=> Name_Unrestricted_Access
);
1849 elsif In_Init_Proc
then
1851 -- Replace any possible references to the discriminant in the
1852 -- call to the record initialization procedure with references
1853 -- to the appropriate formal parameter.
1855 if Nkind
(Arg
) = N_Identifier
1856 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1858 Arg
:= New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
);
1860 -- Otherwise make a copy of the default expression. Note that
1861 -- we use the current Sloc for this, because we do not want the
1862 -- call to appear to be at the declaration point. Within the
1863 -- expression, replace discriminants with their discriminals.
1867 New_Copy_Tree
(Arg
, Map
=> Discr_Map
, New_Sloc
=> Loc
);
1871 if Is_Constrained
(Full_Type
) then
1872 Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
1874 -- The constraints come from the discriminant default exps,
1875 -- they must be reevaluated, so we use New_Copy_Tree but we
1876 -- ensure the proper Sloc (for any embedded calls).
1877 -- In addition, if a predicate check is needed on the value
1878 -- of the discriminant, insert it ahead of the call.
1880 Arg
:= New_Copy_Tree
(Arg
, New_Sloc
=> Loc
);
1883 if Has_Predicates
(Etype
(Discr
)) then
1884 Check_Predicated_Discriminant
(Arg
, Discr
);
1888 -- Ada 2005 (AI-287): In case of default initialized components,
1889 -- if the component is constrained with a discriminant of the
1890 -- enclosing type, we need to generate the corresponding selected
1891 -- component node to access the discriminant value. In other cases
1892 -- this is not required, either because we are inside the init
1893 -- proc and we use the corresponding formal, or else because the
1894 -- component is constrained by an expression.
1896 if With_Default_Init
1897 and then Nkind
(Id_Ref
) = N_Selected_Component
1898 and then Nkind
(Arg
) = N_Identifier
1899 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1902 Make_Selected_Component
(Loc
,
1903 Prefix
=> New_Copy_Tree
(Prefix
(Id_Ref
)),
1904 Selector_Name
=> Arg
));
1906 Append_To
(Args
, Arg
);
1909 Next_Discriminant
(Discr
);
1913 -- If this is a call to initialize the parent component of a derived
1914 -- tagged type, indicate that the tag should not be set in the parent.
1915 -- This is done via the actual parameter value for the Init_Control
1916 -- formal parameter, which is also used to deal with late initialization
1919 -- We pass in Full_Init_Except_Tag unless the caller tells us to do
1920 -- otherwise (by passing in a nonempty Init_Control_Actual parameter).
1922 if Is_Tagged_Type
(Full_Init_Type
)
1923 and then not Is_CPP_Class
(Full_Init_Type
)
1924 and then Nkind
(Id_Ref
) = N_Selected_Component
1925 and then Chars
(Selector_Name
(Id_Ref
)) = Name_uParent
1928 use Initialization_Control
;
1931 (if Present
(Init_Control_Actual
)
1932 then Init_Control_Actual
1933 else Make_Mode_Literal
(Loc
, Full_Init_Except_Tag
)));
1935 elsif Present
(Constructor_Ref
) then
1936 Append_List_To
(Args
,
1937 New_Copy_List
(Parameter_Associations
(Constructor_Ref
)));
1940 -- Pass the extra accessibility level parameter associated with the
1941 -- level of the object being initialized when required.
1943 if Is_Entity_Name
(Id_Ref
)
1944 and then Present
(Init_Proc_Level_Formal
(Proc
))
1947 Make_Parameter_Association
(Loc
,
1949 Make_Identifier
(Loc
, Name_uInit_Level
),
1950 Explicit_Actual_Parameter
=>
1951 Accessibility_Level
(Id_Ref
, Dynamic_Level
)));
1955 Make_Procedure_Call_Statement
(Loc
,
1956 Name
=> New_Occurrence_Of
(Proc
, Loc
),
1957 Parameter_Associations
=> Args
));
1959 if Needs_Finalization
(Typ
)
1960 and then Nkind
(Id_Ref
) = N_Selected_Component
1962 if Chars
(Selector_Name
(Id_Ref
)) /= Name_uParent
then
1965 (Obj_Ref
=> New_Copy_Tree
(First_Arg
),
1968 -- Guard against a missing [Deep_]Initialize when the type was not
1971 if Present
(Init_Call
) then
1972 Append_To
(Res
, Init_Call
);
1980 when RE_Not_Available
=>
1982 end Build_Initialization_Call
;
1984 ----------------------------
1985 -- Build_Record_Init_Proc --
1986 ----------------------------
1988 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
) is
1989 Decls
: constant List_Id
:= New_List
;
1990 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
1991 Loc
: constant Source_Ptr
:= Sloc
(Rec_Ent
);
1993 Proc_Id
: Entity_Id
;
1994 Rec_Type
: Entity_Id
;
1996 Init_Control_Formal
: Entity_Id
:= Empty
; -- set in Build_Init_Statements
1997 Has_Late_Init_Comp
: Boolean := False; -- set in Build_Init_Statements
1999 function Build_Assignment
2001 Default
: Node_Id
) return List_Id
;
2002 -- Build an assignment statement that assigns the default expression to
2003 -- its corresponding record component if defined. The left-hand side of
2004 -- the assignment is marked Assignment_OK so that initialization of
2005 -- limited private records works correctly. This routine may also build
2006 -- an adjustment call if the component is controlled.
2008 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
);
2009 -- If the record has discriminants, add assignment statements to
2010 -- Statement_List to initialize the discriminant values from the
2011 -- arguments of the initialization procedure.
2013 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
;
2014 -- Build a list representing a sequence of statements which initialize
2015 -- components of the given component list. This may involve building
2016 -- case statements for the variant parts. Append any locally declared
2017 -- objects on list Decls.
2019 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
;
2020 -- Given an untagged type-derivation that declares discriminants, e.g.
2022 -- type R (R1, R2 : Integer) is record ... end record;
2023 -- type D (D1 : Integer) is new R (1, D1);
2025 -- we make the _init_proc of D be
2027 -- procedure _init_proc (X : D; D1 : Integer) is
2029 -- _init_proc (R (X), 1, D1);
2032 -- This function builds the call statement in this _init_proc.
2034 procedure Build_CPP_Init_Procedure
;
2035 -- Build the tree corresponding to the procedure specification and body
2036 -- of the IC procedure that initializes the C++ part of the dispatch
2037 -- table of an Ada tagged type that is a derivation of a CPP type.
2038 -- Install it as the CPP_Init TSS.
2040 procedure Build_Init_Procedure
;
2041 -- Build the tree corresponding to the procedure specification and body
2042 -- of the initialization procedure and install it as the _init TSS.
2044 procedure Build_Offset_To_Top_Functions
;
2045 -- Ada 2005 (AI-251): Build the tree corresponding to the procedure spec
2046 -- and body of Offset_To_Top, a function used in conjuction with types
2047 -- having secondary dispatch tables.
2049 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
);
2050 -- Add range checks to components of discriminated records. S is a
2051 -- subtype indication of a record component. Check_List is a list
2052 -- to which the check actions are appended.
2054 function Component_Needs_Simple_Initialization
2055 (T
: Entity_Id
) return Boolean;
2056 -- Determine if a component needs simple initialization, given its type
2057 -- T. This routine is the same as Needs_Simple_Initialization except for
2058 -- components of type Tag and Interface_Tag. These two access types do
2059 -- not require initialization since they are explicitly initialized by
2062 function Parent_Subtype_Renaming_Discrims
return Boolean;
2063 -- Returns True for base types N that rename discriminants, else False
2065 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean;
2066 -- Determine whether a record initialization procedure needs to be
2067 -- generated for the given record type.
2069 ----------------------
2070 -- Build_Assignment --
2071 ----------------------
2073 function Build_Assignment
2075 Default
: Node_Id
) return List_Id
2077 Default_Loc
: constant Source_Ptr
:= Sloc
(Default
);
2078 Typ
: constant Entity_Id
:= Underlying_Type
(Etype
(Id
));
2088 Make_Selected_Component
(Default_Loc
,
2089 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2090 Selector_Name
=> New_Occurrence_Of
(Id
, Default_Loc
));
2091 Set_Assignment_OK
(Lhs
);
2093 -- Take copy of Default to ensure that later copies of this component
2094 -- declaration in derived types see the original tree, not a node
2095 -- rewritten during expansion of the init_proc. If the copy contains
2096 -- itypes, the scope of the new itypes is the init_proc being built.
2099 Map
: Elist_Id
:= No_Elist
;
2102 if Has_Late_Init_Comp
then
2103 -- Map the type to the _Init parameter in order to
2104 -- handle "current instance" references.
2106 Map
:= New_Elmt_List
2108 Elmt2
=> Defining_Identifier
(First
2109 (Parameter_Specifications
2110 (Parent
(Proc_Id
)))));
2112 -- If the type has an incomplete view, a current instance
2113 -- may have an incomplete type. In that case, it must also be
2114 -- replaced by the formal of the Init_Proc.
2116 if Nkind
(Parent
(Rec_Type
)) = N_Full_Type_Declaration
2117 and then Present
(Incomplete_View
(Parent
(Rec_Type
)))
2120 N
=> Incomplete_View
(Parent
(Rec_Type
)),
2123 N
=> Defining_Identifier
2125 (Parameter_Specifications
2126 (Parent
(Proc_Id
)))),
2131 Exp
:= New_Copy_Tree
(Default
, New_Scope
=> Proc_Id
, Map
=> Map
);
2135 Make_Assignment_Statement
(Loc
,
2137 Expression
=> Exp
));
2139 Set_No_Ctrl_Actions
(First
(Res
));
2141 Exp_Q
:= Unqualify
(Exp
);
2143 -- Adjust the tag if tagged (because of possible view conversions).
2144 -- Suppress the tag adjustment when not Tagged_Type_Expansion because
2145 -- tags are represented implicitly in objects, and when the record is
2146 -- initialized with a raise expression.
2148 if Is_Tagged_Type
(Typ
)
2149 and then Tagged_Type_Expansion
2150 and then Nkind
(Exp_Q
) /= N_Raise_Expression
2153 Make_Tag_Assignment_From_Type
2155 New_Copy_Tree
(Lhs
, New_Scope
=> Proc_Id
),
2156 Underlying_Type
(Typ
)));
2159 -- Adjust the component if controlled except if it is an aggregate
2160 -- that will be expanded inline.
2162 if Needs_Finalization
(Typ
)
2163 and then Nkind
(Exp_Q
) not in N_Aggregate | N_Extension_Aggregate
2164 and then not Is_Build_In_Place_Function_Call
(Exp
)
2168 (Obj_Ref
=> New_Copy_Tree
(Lhs
),
2171 -- Guard against a missing [Deep_]Adjust when the component type
2172 -- was not properly frozen.
2174 if Present
(Adj_Call
) then
2175 Append_To
(Res
, Adj_Call
);
2182 when RE_Not_Available
=>
2184 end Build_Assignment
;
2186 ------------------------------------
2187 -- Build_Discriminant_Assignments --
2188 ------------------------------------
2190 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
) is
2191 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Rec_Type
);
2196 if Has_Discriminants
(Rec_Type
)
2197 and then not Is_Unchecked_Union
(Rec_Type
)
2199 D
:= First_Discriminant
(Rec_Type
);
2200 while Present
(D
) loop
2202 -- Don't generate the assignment for discriminants in derived
2203 -- tagged types if the discriminant is a renaming of some
2204 -- ancestor discriminant. This initialization will be done
2205 -- when initializing the _parent field of the derived record.
2208 and then Present
(Corresponding_Discriminant
(D
))
2214 Append_List_To
(Statement_List
,
2215 Build_Assignment
(D
,
2216 New_Occurrence_Of
(Discriminal
(D
), D_Loc
)));
2219 Next_Discriminant
(D
);
2222 end Build_Discriminant_Assignments
;
2224 --------------------------
2225 -- Build_Init_Call_Thru --
2226 --------------------------
2228 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
is
2229 Parent_Proc
: constant Entity_Id
:=
2230 Base_Init_Proc
(Etype
(Rec_Type
));
2232 Parent_Type
: constant Entity_Id
:=
2233 Etype
(First_Formal
(Parent_Proc
));
2235 Uparent_Type
: constant Entity_Id
:=
2236 Underlying_Type
(Parent_Type
);
2238 First_Discr_Param
: Node_Id
;
2242 First_Arg
: Node_Id
;
2243 Parent_Discr
: Entity_Id
;
2247 -- First argument (_Init) is the object to be initialized.
2248 -- ??? not sure where to get a reasonable Loc for First_Arg
2251 OK_Convert_To
(Parent_Type
,
2253 (Defining_Identifier
(First
(Parameters
)), Loc
));
2255 Set_Etype
(First_Arg
, Parent_Type
);
2257 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Rec_Type
));
2259 -- In the tasks case,
2260 -- add _Master as the value of the _Master parameter
2261 -- add _Chain as the value of the _Chain parameter.
2262 -- add _Task_Name as the value of the _Task_Name parameter.
2263 -- At the outer level, these will be variables holding the
2264 -- corresponding values obtained from GNARL or the expander.
2266 -- At inner levels, they will be the parameters passed down through
2267 -- the outer routines.
2269 First_Discr_Param
:= Next
(First
(Parameters
));
2271 if Has_Task
(Rec_Type
) then
2272 if Restriction_Active
(No_Task_Hierarchy
) then
2274 (Args
, Make_Integer_Literal
(Loc
, Library_Task_Level
));
2276 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
2279 -- Add _Chain (not done for sequential elaboration policy, see
2280 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
2282 if Partition_Elaboration_Policy
/= 'S' then
2283 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
2286 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
2287 First_Discr_Param
:= Next
(Next
(Next
(First_Discr_Param
)));
2290 -- Append discriminant values
2292 if Has_Discriminants
(Uparent_Type
) then
2293 pragma Assert
(not Is_Tagged_Type
(Uparent_Type
));
2295 Parent_Discr
:= First_Discriminant
(Uparent_Type
);
2296 while Present
(Parent_Discr
) loop
2298 -- Get the initial value for this discriminant
2299 -- ??? needs to be cleaned up to use parent_Discr_Constr
2303 Discr
: Entity_Id
:=
2304 First_Stored_Discriminant
(Uparent_Type
);
2306 Discr_Value
: Elmt_Id
:=
2307 First_Elmt
(Stored_Constraint
(Rec_Type
));
2310 while Original_Record_Component
(Parent_Discr
) /= Discr
loop
2311 Next_Stored_Discriminant
(Discr
);
2312 Next_Elmt
(Discr_Value
);
2315 Arg
:= Node
(Discr_Value
);
2318 -- Append it to the list
2320 if Nkind
(Arg
) = N_Identifier
2321 and then Ekind
(Entity
(Arg
)) = E_Discriminant
2324 New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
));
2326 -- Case of access discriminants. We replace the reference
2327 -- to the type by a reference to the actual object.
2329 -- Is above comment right??? Use of New_Copy below seems mighty
2333 Append_To
(Args
, New_Copy
(Arg
));
2336 Next_Discriminant
(Parent_Discr
);
2342 Make_Procedure_Call_Statement
(Loc
,
2344 New_Occurrence_Of
(Parent_Proc
, Loc
),
2345 Parameter_Associations
=> Args
));
2348 end Build_Init_Call_Thru
;
2350 -----------------------------------
2351 -- Build_Offset_To_Top_Functions --
2352 -----------------------------------
2354 procedure Build_Offset_To_Top_Functions
is
2356 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
);
2358 -- function Fxx (O : Address) return Storage_Offset is
2359 -- type Acc is access all <Typ>;
2361 -- return Acc!(O).Iface_Comp'Position;
2364 ----------------------------------
2365 -- Build_Offset_To_Top_Function --
2366 ----------------------------------
2368 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
) is
2369 Body_Node
: Node_Id
;
2370 Func_Id
: Entity_Id
;
2371 Spec_Node
: Node_Id
;
2372 Acc_Type
: Entity_Id
;
2375 Func_Id
:= Make_Temporary
(Loc
, 'F');
2376 Set_DT_Offset_To_Top_Func
(Iface_Comp
, Func_Id
);
2379 -- function Fxx (O : in Rec_Typ) return Storage_Offset;
2381 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
2382 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
2383 Set_Parameter_Specifications
(Spec_Node
, New_List
(
2384 Make_Parameter_Specification
(Loc
,
2385 Defining_Identifier
=>
2386 Make_Defining_Identifier
(Loc
, Name_uO
),
2389 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))));
2390 Set_Result_Definition
(Spec_Node
,
2391 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
2394 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2396 -- return -O.Iface_Comp'Position;
2399 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2400 Set_Specification
(Body_Node
, Spec_Node
);
2402 Acc_Type
:= Make_Temporary
(Loc
, 'T');
2403 Set_Declarations
(Body_Node
, New_List
(
2404 Make_Full_Type_Declaration
(Loc
,
2405 Defining_Identifier
=> Acc_Type
,
2407 Make_Access_To_Object_Definition
(Loc
,
2408 All_Present
=> True,
2409 Null_Exclusion_Present
=> False,
2410 Constant_Present
=> False,
2411 Subtype_Indication
=>
2412 New_Occurrence_Of
(Rec_Type
, Loc
)))));
2414 Set_Handled_Statement_Sequence
(Body_Node
,
2415 Make_Handled_Sequence_Of_Statements
(Loc
,
2416 Statements
=> New_List
(
2417 Make_Simple_Return_Statement
(Loc
,
2420 Make_Attribute_Reference
(Loc
,
2422 Make_Selected_Component
(Loc
,
2424 Make_Explicit_Dereference
(Loc
,
2425 Unchecked_Convert_To
(Acc_Type
,
2426 Make_Identifier
(Loc
, Name_uO
))),
2428 New_Occurrence_Of
(Iface_Comp
, Loc
)),
2429 Attribute_Name
=> Name_Position
))))));
2431 Mutate_Ekind
(Func_Id
, E_Function
);
2432 Set_Mechanism
(Func_Id
, Default_Mechanism
);
2433 Set_Is_Internal
(Func_Id
, True);
2435 if not Debug_Generated_Code
then
2436 Set_Debug_Info_Off
(Func_Id
);
2439 Analyze
(Body_Node
);
2441 Append_Freeze_Action
(Rec_Type
, Body_Node
);
2442 end Build_Offset_To_Top_Function
;
2446 Iface_Comp
: Node_Id
;
2447 Iface_Comp_Elmt
: Elmt_Id
;
2448 Ifaces_Comp_List
: Elist_Id
;
2450 -- Start of processing for Build_Offset_To_Top_Functions
2453 -- Offset_To_Top_Functions are built only for derivations of types
2454 -- with discriminants that cover interface types.
2455 -- Nothing is needed either in case of virtual targets, since
2456 -- interfaces are handled directly by the target.
2458 if not Is_Tagged_Type
(Rec_Type
)
2459 or else Etype
(Rec_Type
) = Rec_Type
2460 or else not Has_Discriminants
(Etype
(Rec_Type
))
2461 or else not Tagged_Type_Expansion
2466 Collect_Interface_Components
(Rec_Type
, Ifaces_Comp_List
);
2468 -- For each interface type with secondary dispatch table we generate
2469 -- the Offset_To_Top_Functions (required to displace the pointer in
2470 -- interface conversions)
2472 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
2473 while Present
(Iface_Comp_Elmt
) loop
2474 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
2475 pragma Assert
(Is_Interface
(Related_Type
(Iface_Comp
)));
2477 -- If the interface is a parent of Rec_Type it shares the primary
2478 -- dispatch table and hence there is no need to build the function
2480 if not Is_Ancestor
(Related_Type
(Iface_Comp
), Rec_Type
,
2481 Use_Full_View
=> True)
2483 Build_Offset_To_Top_Function
(Iface_Comp
);
2486 Next_Elmt
(Iface_Comp_Elmt
);
2488 end Build_Offset_To_Top_Functions
;
2490 ------------------------------
2491 -- Build_CPP_Init_Procedure --
2492 ------------------------------
2494 procedure Build_CPP_Init_Procedure
is
2495 Body_Node
: Node_Id
;
2496 Body_Stmts
: List_Id
;
2497 Flag_Id
: Entity_Id
;
2498 Handled_Stmt_Node
: Node_Id
;
2499 Init_Tags_List
: List_Id
;
2500 Proc_Id
: Entity_Id
;
2501 Proc_Spec_Node
: Node_Id
;
2504 -- Check cases requiring no IC routine
2506 if not Is_CPP_Class
(Root_Type
(Rec_Type
))
2507 or else Is_CPP_Class
(Rec_Type
)
2508 or else CPP_Num_Prims
(Rec_Type
) = 0
2509 or else not Tagged_Type_Expansion
2510 or else No_Run_Time_Mode
2517 -- Flag : Boolean := False;
2519 -- procedure Typ_IC is
2522 -- Copy C++ dispatch table slots from parent
2523 -- Update C++ slots of overridden primitives
2527 Flag_Id
:= Make_Temporary
(Loc
, 'F');
2529 Append_Freeze_Action
(Rec_Type
,
2530 Make_Object_Declaration
(Loc
,
2531 Defining_Identifier
=> Flag_Id
,
2532 Object_Definition
=>
2533 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2535 New_Occurrence_Of
(Standard_True
, Loc
)));
2537 Body_Stmts
:= New_List
;
2538 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2540 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2543 Make_Defining_Identifier
(Loc
,
2544 Chars
=> Make_TSS_Name
(Rec_Type
, TSS_CPP_Init_Proc
));
2546 Mutate_Ekind
(Proc_Id
, E_Procedure
);
2547 Set_Is_Internal
(Proc_Id
);
2549 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2551 Set_Parameter_Specifications
(Proc_Spec_Node
, New_List
);
2552 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2553 Set_Declarations
(Body_Node
, New_List
);
2555 Init_Tags_List
:= Build_Inherit_CPP_Prims
(Rec_Type
);
2557 Append_To
(Init_Tags_List
,
2558 Make_Assignment_Statement
(Loc
,
2560 New_Occurrence_Of
(Flag_Id
, Loc
),
2562 New_Occurrence_Of
(Standard_False
, Loc
)));
2564 Append_To
(Body_Stmts
,
2565 Make_If_Statement
(Loc
,
2566 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
2567 Then_Statements
=> Init_Tags_List
));
2569 Handled_Stmt_Node
:=
2570 New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2571 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2572 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2573 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2575 if not Debug_Generated_Code
then
2576 Set_Debug_Info_Off
(Proc_Id
);
2579 -- Associate CPP_Init_Proc with type
2581 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2582 end Build_CPP_Init_Procedure
;
2584 --------------------------
2585 -- Build_Init_Procedure --
2586 --------------------------
2588 procedure Build_Init_Procedure
is
2589 Body_Stmts
: List_Id
;
2590 Body_Node
: Node_Id
;
2591 Handled_Stmt_Node
: Node_Id
;
2592 Init_Tags_List
: List_Id
;
2593 Parameters
: List_Id
;
2594 Proc_Spec_Node
: Node_Id
;
2595 Record_Extension_Node
: Node_Id
;
2597 use Initialization_Control
;
2599 Body_Stmts
:= New_List
;
2600 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2601 Mutate_Ekind
(Proc_Id
, E_Procedure
);
2603 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2604 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2606 Parameters
:= Init_Formals
(Rec_Type
, Proc_Id
);
2607 Append_List_To
(Parameters
,
2608 Build_Discriminant_Formals
(Rec_Type
, True));
2610 -- For tagged types, we add a parameter to indicate what
2611 -- portion of the object's initialization is to be performed.
2612 -- This is used for two purposes:
2613 -- 1) When a type extension's initialization procedure calls
2614 -- the initialization procedure of the parent type, we do
2615 -- not want the parent to initialize the Tag component;
2616 -- it has been set already.
2617 -- 2) If an ancestor type has at least one component that requires
2618 -- late initialization, then we need to be able to initialize
2619 -- those components separately after initializing any other
2622 if Is_Tagged_Type
(Rec_Type
) then
2623 Init_Control_Formal
:= Make_Temporary
(Loc
, 'P');
2625 Append_To
(Parameters
,
2626 Make_Parameter_Specification
(Loc
,
2627 Defining_Identifier
=> Init_Control_Formal
,
2629 New_Occurrence_Of
(Standard_Natural
, Loc
),
2630 Expression
=> Make_Mode_Literal
(Loc
, Full_Init
)));
2633 -- Create an extra accessibility parameter to capture the level of
2634 -- the object being initialized when its type is a limited record.
2636 if Is_Limited_Record
(Rec_Type
) then
2637 Append_To
(Parameters
,
2638 Make_Parameter_Specification
(Loc
,
2639 Defining_Identifier
=> Make_Defining_Identifier
2640 (Loc
, Name_uInit_Level
),
2642 New_Occurrence_Of
(Standard_Natural
, Loc
),
2644 Make_Integer_Literal
2645 (Loc
, Scope_Depth
(Standard_Standard
))));
2648 Set_Parameter_Specifications
(Proc_Spec_Node
, Parameters
);
2649 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2650 Set_Declarations
(Body_Node
, Decls
);
2652 -- N is a Derived_Type_Definition that renames the parameters of the
2653 -- ancestor type. We initialize it by expanding our discriminants and
2654 -- call the ancestor _init_proc with a type-converted object.
2656 if Parent_Subtype_Renaming_Discrims
then
2657 Append_List_To
(Body_Stmts
, Build_Init_Call_Thru
(Parameters
));
2659 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
2660 Build_Discriminant_Assignments
(Body_Stmts
);
2662 if not Null_Present
(Type_Definition
(N
)) then
2663 Append_List_To
(Body_Stmts
,
2664 Build_Init_Statements
(Component_List
(Type_Definition
(N
))));
2667 -- N is a Derived_Type_Definition with a possible non-empty
2668 -- extension. The initialization of a type extension consists in the
2669 -- initialization of the components in the extension.
2672 Build_Discriminant_Assignments
(Body_Stmts
);
2674 Record_Extension_Node
:=
2675 Record_Extension_Part
(Type_Definition
(N
));
2677 if not Null_Present
(Record_Extension_Node
) then
2679 Stmts
: constant List_Id
:=
2680 Build_Init_Statements
(
2681 Component_List
(Record_Extension_Node
));
2684 -- The parent field must be initialized first because the
2685 -- offset of the new discriminants may depend on it. This is
2686 -- not needed if the parent is an interface type because in
2687 -- such case the initialization of the _parent field was not
2690 if not Is_Interface
(Etype
(Rec_Ent
)) then
2692 Parent_IP
: constant Name_Id
:=
2693 Make_Init_Proc_Name
(Etype
(Rec_Ent
));
2694 Stmt
: Node_Id
:= First
(Stmts
);
2695 IP_Call
: Node_Id
:= Empty
;
2697 -- Look for a call to the parent IP associated with
2698 -- the record extension.
2699 -- The call will be inside not one but two
2700 -- if-statements (with the same condition). Testing
2701 -- the same Early_Init condition twice might seem
2702 -- redundant. However, as soon as we exit this loop,
2703 -- we are going to hoist the inner if-statement out
2704 -- of the outer one; the "redundant" test was built
2705 -- in anticipation of this hoisting.
2707 while Present
(Stmt
) loop
2708 if Nkind
(Stmt
) = N_If_Statement
then
2710 Then_Stmt1
: Node_Id
:=
2711 First
(Then_Statements
(Stmt
));
2712 Then_Stmt2
: Node_Id
;
2714 while Present
(Then_Stmt1
) loop
2715 if Nkind
(Then_Stmt1
) = N_If_Statement
then
2717 First
(Then_Statements
(Then_Stmt1
));
2719 if Nkind
(Then_Stmt2
) =
2720 N_Procedure_Call_Statement
2721 and then Chars
(Name
(Then_Stmt2
)) =
2724 -- IP_Call is a call wrapped in an
2726 IP_Call
:= Then_Stmt1
;
2738 -- If found then move it to the beginning of the
2739 -- statements of this IP routine
2741 if Present
(IP_Call
) then
2743 Prepend_List_To
(Body_Stmts
, New_List
(IP_Call
));
2748 Append_List_To
(Body_Stmts
, Stmts
);
2753 -- Add here the assignment to instantiate the Tag
2755 -- The assignment corresponds to the code:
2757 -- _Init._Tag := Typ'Tag;
2759 -- Suppress the tag assignment when not Tagged_Type_Expansion because
2760 -- tags are represented implicitly in objects. It is also suppressed
2761 -- in case of CPP_Class types because in this case the tag is
2762 -- initialized in the C++ side.
2764 if Is_Tagged_Type
(Rec_Type
)
2765 and then Tagged_Type_Expansion
2766 and then not No_Run_Time_Mode
2768 -- Case 1: Ada tagged types with no CPP ancestor. Set the tags of
2769 -- the actual object and invoke the IP of the parent (in this
2770 -- order). The tag must be initialized before the call to the IP
2771 -- of the parent and the assignments to other components because
2772 -- the initial value of the components may depend on the tag (eg.
2773 -- through a dispatching operation on an access to the current
2774 -- type). The tag assignment is not done when initializing the
2775 -- parent component of a type extension, because in that case the
2776 -- tag is set in the extension.
2778 if not Is_CPP_Class
(Root_Type
(Rec_Type
)) then
2780 -- Initialize the primary tag component
2782 Init_Tags_List
:= New_List
(
2783 Make_Tag_Assignment_From_Type
2784 (Loc
, Make_Identifier
(Loc
, Name_uInit
), Rec_Type
));
2786 -- Ada 2005 (AI-251): Initialize the secondary tags components
2787 -- located at fixed positions (tags whose position depends on
2788 -- variable size components are initialized later ---see below)
2790 if Ada_Version
>= Ada_2005
2791 and then not Is_Interface
(Rec_Type
)
2792 and then Has_Interfaces
(Rec_Type
)
2795 Elab_Sec_DT_Stmts_List
: constant List_Id
:= New_List
;
2796 Elab_List
: List_Id
:= New_List
;
2801 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2802 Init_Tags_List
=> Init_Tags_List
,
2803 Stmts_List
=> Elab_Sec_DT_Stmts_List
,
2804 Fixed_Comps
=> True,
2805 Variable_Comps
=> False);
2807 Elab_List
:= New_List
(
2808 Make_If_Statement
(Loc
,
2810 Tag_Init_Condition
(Loc
, Init_Control_Formal
),
2811 Then_Statements
=> Init_Tags_List
));
2813 if Elab_Flag_Needed
(Rec_Type
) then
2814 Append_To
(Elab_Sec_DT_Stmts_List
,
2815 Make_Assignment_Statement
(Loc
,
2818 (Access_Disp_Table_Elab_Flag
(Rec_Type
),
2821 New_Occurrence_Of
(Standard_False
, Loc
)));
2823 Append_To
(Elab_List
,
2824 Make_If_Statement
(Loc
,
2827 (Access_Disp_Table_Elab_Flag
(Rec_Type
), Loc
),
2828 Then_Statements
=> Elab_Sec_DT_Stmts_List
));
2831 Prepend_List_To
(Body_Stmts
, Elab_List
);
2834 Prepend_To
(Body_Stmts
,
2835 Make_If_Statement
(Loc
,
2837 Tag_Init_Condition
(Loc
, Init_Control_Formal
),
2838 Then_Statements
=> Init_Tags_List
));
2841 -- Case 2: CPP type. The imported C++ constructor takes care of
2842 -- tags initialization. No action needed here because the IP
2843 -- is built by Set_CPP_Constructors; in this case the IP is a
2844 -- wrapper that invokes the C++ constructor and copies the C++
2845 -- tags locally. Done to inherit the C++ slots in Ada derivations
2848 elsif Is_CPP_Class
(Rec_Type
) then
2849 pragma Assert
(False);
2852 -- Case 3: Combined hierarchy containing C++ types and Ada tagged
2853 -- type derivations. Derivations of imported C++ classes add a
2854 -- complication, because we cannot inhibit tag setting in the
2855 -- constructor for the parent. Hence we initialize the tag after
2856 -- the call to the parent IP (that is, in reverse order compared
2857 -- with pure Ada hierarchies ---see comment on case 1).
2860 -- Initialize the primary tag
2862 Init_Tags_List
:= New_List
(
2863 Make_Tag_Assignment_From_Type
2864 (Loc
, Make_Identifier
(Loc
, Name_uInit
), Rec_Type
));
2866 -- Ada 2005 (AI-251): Initialize the secondary tags components
2867 -- located at fixed positions (tags whose position depends on
2868 -- variable size components are initialized later ---see below)
2870 if Ada_Version
>= Ada_2005
2871 and then not Is_Interface
(Rec_Type
)
2872 and then Has_Interfaces
(Rec_Type
)
2876 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2877 Init_Tags_List
=> Init_Tags_List
,
2878 Stmts_List
=> Init_Tags_List
,
2879 Fixed_Comps
=> True,
2880 Variable_Comps
=> False);
2883 -- Initialize the tag component after invocation of parent IP.
2886 -- parent_IP(_init.parent); // Invokes the C++ constructor
2887 -- [ typIC; ] // Inherit C++ slots from parent
2894 -- Search for the call to the IP of the parent. We assume
2895 -- that the first init_proc call is for the parent.
2896 -- It is wrapped in an "if Early_Init_Condition"
2899 Ins_Nod
:= First
(Body_Stmts
);
2900 while Present
(Next
(Ins_Nod
))
2902 (Nkind
(Ins_Nod
) /= N_If_Statement
2903 or else Nkind
(First
(Then_Statements
(Ins_Nod
)))
2904 /= N_Procedure_Call_Statement
2905 or else not Is_Init_Proc
2906 (Name
(First
(Then_Statements
2912 -- The IC routine copies the inherited slots of the C+ part
2913 -- of the dispatch table from the parent and updates the
2914 -- overridden C++ slots.
2916 if CPP_Num_Prims
(Rec_Type
) > 0 then
2918 Init_DT
: Entity_Id
;
2922 Init_DT
:= CPP_Init_Proc
(Rec_Type
);
2923 pragma Assert
(Present
(Init_DT
));
2926 Make_Procedure_Call_Statement
(Loc
,
2927 New_Occurrence_Of
(Init_DT
, Loc
));
2928 Insert_After
(Ins_Nod
, New_Nod
);
2930 -- Update location of init tag statements
2936 Insert_List_After
(Ins_Nod
, Init_Tags_List
);
2940 -- Ada 2005 (AI-251): Initialize the secondary tag components
2941 -- located at variable positions. We delay the generation of this
2942 -- code until here because the value of the attribute 'Position
2943 -- applied to variable size components of the parent type that
2944 -- depend on discriminants is only safely read at runtime after
2945 -- the parent components have been initialized.
2947 if Ada_Version
>= Ada_2005
2948 and then not Is_Interface
(Rec_Type
)
2949 and then Has_Interfaces
(Rec_Type
)
2950 and then Has_Discriminants
(Etype
(Rec_Type
))
2951 and then Is_Variable_Size_Record
(Etype
(Rec_Type
))
2953 Init_Tags_List
:= New_List
;
2957 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2958 Init_Tags_List
=> Init_Tags_List
,
2959 Stmts_List
=> Init_Tags_List
,
2960 Fixed_Comps
=> False,
2961 Variable_Comps
=> True);
2963 Append_List_To
(Body_Stmts
, Init_Tags_List
);
2967 Handled_Stmt_Node
:= New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2968 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2971 -- Deep_Finalize (_init, C1, ..., CN);
2975 and then Needs_Finalization
(Rec_Type
)
2976 and then not Is_Abstract_Type
(Rec_Type
)
2977 and then not Restriction_Active
(No_Exception_Propagation
)
2984 -- Create a local version of Deep_Finalize which has indication
2985 -- of partial initialization state.
2988 Make_Defining_Identifier
(Loc
,
2989 Chars
=> New_External_Name
(Name_uFinalizer
));
2991 Append_To
(Decls
, Make_Local_Deep_Finalize
(Rec_Type
, DF_Id
));
2994 Make_Procedure_Call_Statement
(Loc
,
2995 Name
=> New_Occurrence_Of
(DF_Id
, Loc
),
2996 Parameter_Associations
=> New_List
(
2997 Make_Identifier
(Loc
, Name_uInit
),
2998 New_Occurrence_Of
(Standard_False
, Loc
)));
3000 -- Do not emit warnings related to the elaboration order when a
3001 -- controlled object is declared before the body of Finalize is
3004 if Legacy_Elaboration_Checks
then
3005 Set_No_Elaboration_Check
(DF_Call
);
3008 Set_Exception_Handlers
(Handled_Stmt_Node
, New_List
(
3009 Make_Exception_Handler
(Loc
,
3010 Exception_Choices
=> New_List
(
3011 Make_Others_Choice
(Loc
)),
3012 Statements
=> New_List
(
3014 Make_Raise_Statement
(Loc
)))));
3017 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
3020 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
3022 if not Debug_Generated_Code
then
3023 Set_Debug_Info_Off
(Proc_Id
);
3026 -- Associate Init_Proc with type, and determine if the procedure
3027 -- is null (happens because of the Initialize_Scalars pragma case,
3028 -- where we have to generate a null procedure in case it is called
3029 -- by a client with Initialize_Scalars set). Such procedures have
3030 -- to be generated, but do not have to be called, so we mark them
3031 -- as null to suppress the call. Kill also warnings for the _Init
3032 -- out parameter, which is left entirely uninitialized.
3034 Set_Init_Proc
(Rec_Type
, Proc_Id
);
3036 if Is_Null_Statement_List
(Body_Stmts
) then
3037 Set_Is_Null_Init_Proc
(Proc_Id
);
3038 Set_Warnings_Off
(Defining_Identifier
(First
(Parameters
)));
3040 end Build_Init_Procedure
;
3042 ---------------------------
3043 -- Build_Init_Statements --
3044 ---------------------------
3046 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
is
3047 Checks
: constant List_Id
:= New_List
;
3048 Actions
: List_Id
:= No_List
;
3049 Counter_Id
: Entity_Id
:= Empty
;
3050 Comp_Loc
: Source_Ptr
;
3053 Parent_Stmts
: List_Id
;
3054 Parent_Id
: Entity_Id
:= Empty
;
3055 Stmts
, Late_Stmts
: List_Id
:= Empty_List
;
3058 procedure Increment_Counter
3059 (Loc
: Source_Ptr
; Late
: Boolean := False);
3060 -- Generate an "increment by one" statement for the current counter
3061 -- and append it to the appropriate statement list.
3063 procedure Make_Counter
(Loc
: Source_Ptr
);
3064 -- Create a new counter for the current component list. The routine
3065 -- creates a new defining Id, adds an object declaration and sets
3066 -- the Id generator for the next variant.
3068 -----------------------
3069 -- Increment_Counter --
3070 -----------------------
3072 procedure Increment_Counter
3073 (Loc
: Source_Ptr
; Late
: Boolean := False) is
3076 -- Counter := Counter + 1;
3078 Append_To
((if Late
then Late_Stmts
else Stmts
),
3079 Make_Assignment_Statement
(Loc
,
3080 Name
=> New_Occurrence_Of
(Counter_Id
, Loc
),
3083 Left_Opnd
=> New_Occurrence_Of
(Counter_Id
, Loc
),
3084 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
3085 end Increment_Counter
;
3091 procedure Make_Counter
(Loc
: Source_Ptr
) is
3093 -- Increment the Id generator
3095 Counter
:= Counter
+ 1;
3097 -- Create the entity and declaration
3100 Make_Defining_Identifier
(Loc
,
3101 Chars
=> New_External_Name
('C', Counter
));
3104 -- Cnn : Integer := 0;
3107 Make_Object_Declaration
(Loc
,
3108 Defining_Identifier
=> Counter_Id
,
3109 Object_Definition
=>
3110 New_Occurrence_Of
(Standard_Integer
, Loc
),
3112 Make_Integer_Literal
(Loc
, 0)));
3115 -- Start of processing for Build_Init_Statements
3118 if Null_Present
(Comp_List
) then
3119 return New_List
(Make_Null_Statement
(Loc
));
3122 Parent_Stmts
:= New_List
;
3125 -- Loop through visible declarations of task types and protected
3126 -- types moving any expanded code from the spec to the body of the
3129 if Is_Concurrent_Record_Type
(Rec_Type
) then
3131 Decl
: constant Node_Id
:=
3132 Parent
(Corresponding_Concurrent_Type
(Rec_Type
));
3138 if Is_Task_Record_Type
(Rec_Type
) then
3139 Def
:= Task_Definition
(Decl
);
3141 Def
:= Protected_Definition
(Decl
);
3144 if Present
(Def
) then
3145 N1
:= First
(Visible_Declarations
(Def
));
3146 while Present
(N1
) loop
3150 if Nkind
(N2
) in N_Statement_Other_Than_Procedure_Call
3151 or else Nkind
(N2
) in N_Raise_xxx_Error
3152 or else Nkind
(N2
) = N_Procedure_Call_Statement
3155 New_Copy_Tree
(N2
, New_Scope
=> Proc_Id
));
3156 Rewrite
(N2
, Make_Null_Statement
(Sloc
(N2
)));
3164 -- Loop through components, skipping pragmas, in 2 steps. The first
3165 -- step deals with regular components. The second step deals with
3166 -- components that require late initialization.
3168 -- First pass : regular components
3170 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3171 while Present
(Decl
) loop
3172 Comp_Loc
:= Sloc
(Decl
);
3174 (Subtype_Indication
(Component_Definition
(Decl
)), Checks
);
3176 Id
:= Defining_Identifier
(Decl
);
3179 -- Leave any processing of component requiring late initialization
3180 -- for the second pass.
3182 if Initialization_Control
.Requires_Late_Init
(Decl
, Rec_Type
) then
3183 if not Has_Late_Init_Comp
then
3184 Late_Stmts
:= New_List
;
3186 Has_Late_Init_Comp
:= True;
3188 -- Regular component cases
3191 -- In the context of the init proc, references to discriminants
3192 -- resolve to denote the discriminals: this is where we can
3193 -- freeze discriminant dependent component subtypes.
3195 if not Is_Frozen
(Typ
) then
3196 Append_List_To
(Stmts
, Freeze_Entity
(Typ
, N
));
3199 -- Explicit initialization
3201 if Present
(Expression
(Decl
)) then
3202 if Is_CPP_Constructor_Call
(Expression
(Decl
)) then
3204 Build_Initialization_Call
3207 Make_Selected_Component
(Comp_Loc
,
3209 Make_Identifier
(Comp_Loc
, Name_uInit
),
3211 New_Occurrence_Of
(Id
, Comp_Loc
)),
3213 In_Init_Proc
=> True,
3214 Enclos_Type
=> Rec_Type
,
3215 Discr_Map
=> Discr_Map
,
3216 Constructor_Ref
=> Expression
(Decl
));
3218 Actions
:= Build_Assignment
(Id
, Expression
(Decl
));
3221 -- CPU, Dispatching_Domain, Priority, and Secondary_Stack_Size
3222 -- components are filled in with the corresponding rep-item
3223 -- expression of the concurrent type (if any).
3225 elsif Ekind
(Scope
(Id
)) = E_Record_Type
3226 and then Present
(Corresponding_Concurrent_Type
(Scope
(Id
)))
3227 and then Chars
(Id
) in Name_uCPU
3228 | Name_uDispatching_Domain
3230 | Name_uSecondary_Stack_Size
3235 pragma Warnings
(Off
, Nam
);
3239 if Chars
(Id
) = Name_uCPU
then
3242 elsif Chars
(Id
) = Name_uDispatching_Domain
then
3243 Nam
:= Name_Dispatching_Domain
;
3245 elsif Chars
(Id
) = Name_uPriority
then
3246 Nam
:= Name_Priority
;
3248 elsif Chars
(Id
) = Name_uSecondary_Stack_Size
then
3249 Nam
:= Name_Secondary_Stack_Size
;
3252 -- Get the Rep Item (aspect specification, attribute
3253 -- definition clause or pragma) of the corresponding
3258 (Corresponding_Concurrent_Type
(Scope
(Id
)),
3260 Check_Parents
=> False);
3262 if Present
(Ritem
) then
3266 if Nkind
(Ritem
) = N_Pragma
then
3269 (First
(Pragma_Argument_Associations
(Ritem
)));
3271 -- Conversion for Priority expression
3273 if Nam
= Name_Priority
then
3274 if Pragma_Name
(Ritem
) = Name_Priority
3275 and then not GNAT_Mode
3277 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
3280 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
3284 -- Aspect/Attribute definition clause case
3287 Exp
:= Expression
(Ritem
);
3289 -- Conversion for Priority expression
3291 if Nam
= Name_Priority
then
3292 if Chars
(Ritem
) = Name_Priority
3293 and then not GNAT_Mode
3295 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
3298 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
3303 -- Conversion for Dispatching_Domain value
3305 if Nam
= Name_Dispatching_Domain
then
3307 Unchecked_Convert_To
3308 (RTE
(RE_Dispatching_Domain_Access
), Exp
);
3310 -- Conversion for Secondary_Stack_Size value
3312 elsif Nam
= Name_Secondary_Stack_Size
then
3313 Exp
:= Convert_To
(RTE
(RE_Size_Type
), Exp
);
3316 Actions
:= Build_Assignment
(Id
, Exp
);
3318 -- Nothing needed if no Rep Item
3325 -- Composite component with its own Init_Proc
3327 elsif not Is_Interface
(Typ
)
3328 and then Has_Non_Null_Base_Init_Proc
(Typ
)
3331 use Initialization_Control
;
3332 Init_Control_Actual
: Node_Id
:= Empty
;
3333 Is_Parent
: constant Boolean := Chars
(Id
) = Name_uParent
;
3334 Init_Call_Stmts
: List_Id
;
3336 if Is_Parent
and then Has_Late_Init_Component
(Etype
(Id
))
3338 Init_Control_Actual
:=
3339 Make_Mode_Literal
(Comp_Loc
, Early_Init_Only
);
3340 -- Parent_Id used later in second call to parent's
3341 -- init proc to initialize late-init components.
3346 Build_Initialization_Call
3348 Make_Selected_Component
(Comp_Loc
,
3350 Make_Identifier
(Comp_Loc
, Name_uInit
),
3351 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3353 In_Init_Proc
=> True,
3354 Enclos_Type
=> Rec_Type
,
3355 Discr_Map
=> Discr_Map
,
3356 Init_Control_Actual
=> Init_Control_Actual
);
3359 -- This is tricky. At first it looks like
3360 -- we are going to end up with nested
3361 -- if-statements with the same condition:
3362 -- if Early_Init_Condition then
3363 -- if Early_Init_Condition then
3364 -- Parent_TypeIP (...);
3367 -- But later we will hoist the inner if-statement
3368 -- out of the outer one; we do this because the
3369 -- init-proc call for the _Parent component of a type
3370 -- extension has to precede any other initialization.
3372 New_List
(Make_If_Statement
(Loc
,
3374 Early_Init_Condition
(Loc
, Init_Control_Formal
),
3375 Then_Statements
=> Init_Call_Stmts
));
3377 Actions
:= Init_Call_Stmts
;
3381 Clean_Task_Names
(Typ
, Proc_Id
);
3383 -- Simple initialization. If the Esize is not yet set, we pass
3384 -- Uint_0 as expected by Get_Simple_Init_Val.
3386 elsif Component_Needs_Simple_Initialization
(Typ
) then
3395 (if Known_Esize
(Id
) then Esize
(Id
)
3398 -- Nothing needed for this case
3404 -- When the component's type has a Default_Initial_Condition,
3405 -- and the component is default initialized, then check the
3409 and then No
(Expression
(Decl
))
3410 and then Present
(DIC_Procedure
(Typ
))
3411 and then not Has_Null_Body
(DIC_Procedure
(Typ
))
3413 -- The DICs of ancestors are checked as part of the type's
3416 and then Chars
(Id
) /= Name_uParent
3418 -- In GNATprove mode, the component DICs are checked by other
3419 -- means. They should not be added to the record type DIC
3420 -- procedure, so that the procedure can be used to check the
3421 -- record type invariants or DICs if any.
3423 and then not GNATprove_Mode
3425 Append_New_To
(Actions
,
3428 Make_Selected_Component
(Comp_Loc
,
3430 Make_Identifier
(Comp_Loc
, Name_uInit
),
3432 New_Occurrence_Of
(Id
, Comp_Loc
)),
3436 if Present
(Checks
) then
3437 if Chars
(Id
) = Name_uParent
then
3438 Append_List_To
(Parent_Stmts
, Checks
);
3440 Append_List_To
(Stmts
, Checks
);
3444 if Present
(Actions
) then
3445 if Chars
(Id
) = Name_uParent
then
3446 Append_List_To
(Parent_Stmts
, Actions
);
3448 Append_List_To
(Stmts
, Actions
);
3450 -- Preserve initialization state in the current counter
3452 if Needs_Finalization
(Typ
) then
3453 if No
(Counter_Id
) then
3454 Make_Counter
(Comp_Loc
);
3457 Increment_Counter
(Comp_Loc
);
3463 Next_Non_Pragma
(Decl
);
3466 -- The parent field must be initialized first because variable
3467 -- size components of the parent affect the location of all the
3470 Prepend_List_To
(Stmts
, Parent_Stmts
);
3472 -- Set up tasks and protected object support. This needs to be done
3473 -- before any component with a per-object access discriminant
3474 -- constraint, or any variant part (which may contain such
3475 -- components) is initialized, because the initialization of these
3476 -- components may reference the enclosing concurrent object.
3478 -- For a task record type, add the task create call and calls to bind
3479 -- any interrupt (signal) entries.
3481 if Is_Task_Record_Type
(Rec_Type
) then
3483 -- In the case of the restricted run time the ATCB has already
3484 -- been preallocated.
3486 if Restricted_Profile
then
3488 Make_Assignment_Statement
(Loc
,
3490 Make_Selected_Component
(Loc
,
3491 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3492 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3494 Make_Attribute_Reference
(Loc
,
3496 Make_Selected_Component
(Loc
,
3497 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3498 Selector_Name
=> Make_Identifier
(Loc
, Name_uATCB
)),
3499 Attribute_Name
=> Name_Unchecked_Access
)));
3502 Append_To
(Stmts
, Make_Task_Create_Call
(Rec_Type
));
3505 Task_Type
: constant Entity_Id
:=
3506 Corresponding_Concurrent_Type
(Rec_Type
);
3507 Task_Decl
: constant Node_Id
:= Parent
(Task_Type
);
3508 Task_Def
: constant Node_Id
:= Task_Definition
(Task_Decl
);
3509 Decl_Loc
: Source_Ptr
;
3514 if Present
(Task_Def
) then
3515 Vis_Decl
:= First
(Visible_Declarations
(Task_Def
));
3516 while Present
(Vis_Decl
) loop
3517 Decl_Loc
:= Sloc
(Vis_Decl
);
3519 if Nkind
(Vis_Decl
) = N_Attribute_Definition_Clause
then
3520 if Get_Attribute_Id
(Chars
(Vis_Decl
)) =
3523 Ent
:= Entity
(Name
(Vis_Decl
));
3525 if Ekind
(Ent
) = E_Entry
then
3527 Make_Procedure_Call_Statement
(Decl_Loc
,
3529 New_Occurrence_Of
(RTE
(
3530 RE_Bind_Interrupt_To_Entry
), Decl_Loc
),
3531 Parameter_Associations
=> New_List
(
3532 Make_Selected_Component
(Decl_Loc
,
3534 Make_Identifier
(Decl_Loc
, Name_uInit
),
3537 (Decl_Loc
, Name_uTask_Id
)),
3538 Entry_Index_Expression
3539 (Decl_Loc
, Ent
, Empty
, Task_Type
),
3540 Expression
(Vis_Decl
))));
3550 -- For a protected type, add statements generated by
3551 -- Make_Initialize_Protection.
3553 elsif Is_Protected_Record_Type
(Rec_Type
) then
3554 Append_List_To
(Stmts
,
3555 Make_Initialize_Protection
(Rec_Type
));
3558 -- Second pass: components that require late initialization
3560 if Present
(Parent_Id
) then
3562 Parent_Loc
: constant Source_Ptr
:= Sloc
(Parent
(Parent_Id
));
3563 use Initialization_Control
;
3565 -- We are building the init proc for a type extension.
3566 -- Call the parent type's init proc a second time, this
3567 -- time to initialize the parent's components that require
3568 -- late initialization.
3570 Append_List_To
(Late_Stmts
,
3571 Build_Initialization_Call
3574 Make_Selected_Component
(Parent_Loc
,
3575 Prefix
=> Make_Identifier
3576 (Parent_Loc
, Name_uInit
),
3577 Selector_Name
=> New_Occurrence_Of
(Parent_Id
,
3579 Typ
=> Etype
(Parent_Id
),
3580 In_Init_Proc
=> True,
3581 Enclos_Type
=> Rec_Type
,
3582 Discr_Map
=> Discr_Map
,
3583 Init_Control_Actual
=> Make_Mode_Literal
3584 (Parent_Loc
, Late_Init_Only
)));
3588 if Has_Late_Init_Comp
then
3589 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3590 while Present
(Decl
) loop
3591 Comp_Loc
:= Sloc
(Decl
);
3592 Id
:= Defining_Identifier
(Decl
);
3595 if Initialization_Control
.Requires_Late_Init
(Decl
, Rec_Type
)
3597 if Present
(Expression
(Decl
)) then
3598 Append_List_To
(Late_Stmts
,
3599 Build_Assignment
(Id
, Expression
(Decl
)));
3601 elsif Has_Non_Null_Base_Init_Proc
(Typ
) then
3602 Append_List_To
(Late_Stmts
,
3603 Build_Initialization_Call
(Comp_Loc
,
3604 Make_Selected_Component
(Comp_Loc
,
3606 Make_Identifier
(Comp_Loc
, Name_uInit
),
3607 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3609 In_Init_Proc
=> True,
3610 Enclos_Type
=> Rec_Type
,
3611 Discr_Map
=> Discr_Map
));
3613 Clean_Task_Names
(Typ
, Proc_Id
);
3615 -- Preserve initialization state in the current counter
3617 if Needs_Finalization
(Typ
) then
3618 if No
(Counter_Id
) then
3619 Make_Counter
(Comp_Loc
);
3622 Increment_Counter
(Comp_Loc
, Late
=> True);
3624 elsif Component_Needs_Simple_Initialization
(Typ
) then
3625 Append_List_To
(Late_Stmts
,
3632 Size
=> Esize
(Id
))));
3636 Next_Non_Pragma
(Decl
);
3640 -- Process the variant part (incorrectly ignoring late
3641 -- initialization requirements for components therein).
3643 if Present
(Variant_Part
(Comp_List
)) then
3645 Variant_Alts
: constant List_Id
:= New_List
;
3646 Var_Loc
: Source_Ptr
:= No_Location
;
3651 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3652 while Present
(Variant
) loop
3653 Var_Loc
:= Sloc
(Variant
);
3654 Append_To
(Variant_Alts
,
3655 Make_Case_Statement_Alternative
(Var_Loc
,
3657 New_Copy_List
(Discrete_Choices
(Variant
)),
3659 Build_Init_Statements
(Component_List
(Variant
))));
3660 Next_Non_Pragma
(Variant
);
3663 -- The expression of the case statement which is a reference
3664 -- to one of the discriminants is replaced by the appropriate
3665 -- formal parameter of the initialization procedure.
3668 Make_Case_Statement
(Var_Loc
,
3670 New_Occurrence_Of
(Discriminal
(
3671 Entity
(Name
(Variant_Part
(Comp_List
)))), Var_Loc
),
3672 Alternatives
=> Variant_Alts
));
3676 if No
(Init_Control_Formal
) then
3677 Append_List_To
(Stmts
, Late_Stmts
);
3679 -- If no initializations were generated for component declarations
3680 -- and included in Stmts, then append a null statement to Stmts
3681 -- to make it a valid Ada tree.
3683 if Is_Empty_List
(Stmts
) then
3684 Append
(Make_Null_Statement
(Loc
), Stmts
);
3690 use Initialization_Control
;
3692 If_Early
: constant Node_Id
:=
3693 (if Is_Empty_List
(Stmts
) then
3694 Make_Null_Statement
(Loc
)
3696 Make_If_Statement
(Loc
,
3698 Early_Init_Condition
(Loc
, Init_Control_Formal
),
3699 Then_Statements
=> Stmts
));
3700 If_Late
: constant Node_Id
:=
3701 (if Is_Empty_List
(Late_Stmts
) then
3702 Make_Null_Statement
(Loc
)
3704 Make_If_Statement
(Loc
,
3706 Late_Init_Condition
(Loc
, Init_Control_Formal
),
3707 Then_Statements
=> Late_Stmts
));
3709 return New_List
(If_Early
, If_Late
);
3713 when RE_Not_Available
=>
3715 end Build_Init_Statements
;
3717 -------------------------
3718 -- Build_Record_Checks --
3719 -------------------------
3721 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
) is
3722 Subtype_Mark_Id
: Entity_Id
;
3724 procedure Constrain_Array
3726 Check_List
: List_Id
);
3727 -- Apply a list of index constraints to an unconstrained array type.
3728 -- The first parameter is the entity for the resulting subtype.
3729 -- Check_List is a list to which the check actions are appended.
3731 ---------------------
3732 -- Constrain_Array --
3733 ---------------------
3735 procedure Constrain_Array
3737 Check_List
: List_Id
)
3739 C
: constant Node_Id
:= Constraint
(SI
);
3740 Number_Of_Constraints
: Nat
:= 0;
3744 procedure Constrain_Index
3747 Check_List
: List_Id
);
3748 -- Process an index constraint in a constrained array declaration.
3749 -- The constraint can be either a subtype name or a range with or
3750 -- without an explicit subtype mark. Index is the corresponding
3751 -- index of the unconstrained array. S is the range expression.
3752 -- Check_List is a list to which the check actions are appended.
3754 ---------------------
3755 -- Constrain_Index --
3756 ---------------------
3758 procedure Constrain_Index
3761 Check_List
: List_Id
)
3763 T
: constant Entity_Id
:= Etype
(Index
);
3766 if Nkind
(S
) = N_Range
then
3767 Process_Range_Expr_In_Decl
(S
, T
, Check_List
=> Check_List
);
3769 end Constrain_Index
;
3771 -- Start of processing for Constrain_Array
3774 T
:= Entity
(Subtype_Mark
(SI
));
3776 if Is_Access_Type
(T
) then
3777 T
:= Designated_Type
(T
);
3780 S
:= First
(Constraints
(C
));
3781 while Present
(S
) loop
3782 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
3786 -- In either case, the index constraint must provide a discrete
3787 -- range for each index of the array type and the type of each
3788 -- discrete range must be the same as that of the corresponding
3789 -- index. (RM 3.6.1)
3791 S
:= First
(Constraints
(C
));
3792 Index
:= First_Index
(T
);
3795 -- Apply constraints to each index type
3797 for J
in 1 .. Number_Of_Constraints
loop
3798 Constrain_Index
(Index
, S
, Check_List
);
3802 end Constrain_Array
;
3804 -- Start of processing for Build_Record_Checks
3807 if Nkind
(S
) = N_Subtype_Indication
then
3808 Find_Type
(Subtype_Mark
(S
));
3809 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
3811 -- Remaining processing depends on type
3813 case Ekind
(Subtype_Mark_Id
) is
3815 Constrain_Array
(S
, Check_List
);
3821 end Build_Record_Checks
;
3823 -------------------------------------------
3824 -- Component_Needs_Simple_Initialization --
3825 -------------------------------------------
3827 function Component_Needs_Simple_Initialization
3828 (T
: Entity_Id
) return Boolean
3832 Needs_Simple_Initialization
(T
)
3833 and then not Is_RTE
(T
, RE_Tag
)
3835 -- Ada 2005 (AI-251): Check also the tag of abstract interfaces
3837 and then not Is_RTE
(T
, RE_Interface_Tag
);
3838 end Component_Needs_Simple_Initialization
;
3840 --------------------------------------
3841 -- Parent_Subtype_Renaming_Discrims --
3842 --------------------------------------
3844 function Parent_Subtype_Renaming_Discrims
return Boolean is
3849 if Base_Type
(Rec_Ent
) /= Rec_Ent
then
3853 if Etype
(Rec_Ent
) = Rec_Ent
3854 or else not Has_Discriminants
(Rec_Ent
)
3855 or else Is_Constrained
(Rec_Ent
)
3856 or else Is_Tagged_Type
(Rec_Ent
)
3861 -- If there are no explicit stored discriminants we have inherited
3862 -- the root type discriminants so far, so no renamings occurred.
3864 if First_Discriminant
(Rec_Ent
) =
3865 First_Stored_Discriminant
(Rec_Ent
)
3870 -- Check if we have done some trivial renaming of the parent
3871 -- discriminants, i.e. something like
3873 -- type DT (X1, X2: int) is new PT (X1, X2);
3875 De
:= First_Discriminant
(Rec_Ent
);
3876 Dp
:= First_Discriminant
(Etype
(Rec_Ent
));
3877 while Present
(De
) loop
3878 pragma Assert
(Present
(Dp
));
3880 if Corresponding_Discriminant
(De
) /= Dp
then
3884 Next_Discriminant
(De
);
3885 Next_Discriminant
(Dp
);
3888 return Present
(Dp
);
3889 end Parent_Subtype_Renaming_Discrims
;
3891 ------------------------
3892 -- Requires_Init_Proc --
3893 ------------------------
3895 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean is
3896 Comp_Decl
: Node_Id
;
3901 -- Definitely do not need one if specifically suppressed
3903 if Initialization_Suppressed
(Rec_Id
) then
3907 -- If it is a type derived from a type with unknown discriminants,
3908 -- we cannot build an initialization procedure for it.
3910 if Has_Unknown_Discriminants
(Rec_Id
)
3911 or else Has_Unknown_Discriminants
(Etype
(Rec_Id
))
3916 -- Otherwise we need to generate an initialization procedure if
3917 -- Is_CPP_Class is False and at least one of the following applies:
3919 -- 1. Discriminants are present, since they need to be initialized
3920 -- with the appropriate discriminant constraint expressions.
3921 -- However, the discriminant of an unchecked union does not
3922 -- count, since the discriminant is not present.
3924 -- 2. The type is a tagged type, since the implicit Tag component
3925 -- needs to be initialized with a pointer to the dispatch table.
3927 -- 3. The type contains tasks
3929 -- 4. One or more components has an initial value
3931 -- 5. One or more components is for a type which itself requires
3932 -- an initialization procedure.
3934 -- 6. One or more components is a type that requires simple
3935 -- initialization (see Needs_Simple_Initialization), except
3936 -- that types Tag and Interface_Tag are excluded, since fields
3937 -- of these types are initialized by other means.
3939 -- 7. The type is the record type built for a task type (since at
3940 -- the very least, Create_Task must be called)
3942 -- 8. The type is the record type built for a protected type (since
3943 -- at least Initialize_Protection must be called)
3945 -- 9. The type is marked as a public entity. The reason we add this
3946 -- case (even if none of the above apply) is to properly handle
3947 -- Initialize_Scalars. If a package is compiled without an IS
3948 -- pragma, and the client is compiled with an IS pragma, then
3949 -- the client will think an initialization procedure is present
3950 -- and call it, when in fact no such procedure is required, but
3951 -- since the call is generated, there had better be a routine
3952 -- at the other end of the call, even if it does nothing).
3954 -- Note: the reason we exclude the CPP_Class case is because in this
3955 -- case the initialization is performed by the C++ constructors, and
3956 -- the IP is built by Set_CPP_Constructors.
3958 if Is_CPP_Class
(Rec_Id
) then
3961 elsif Is_Interface
(Rec_Id
) then
3964 elsif (Has_Discriminants
(Rec_Id
)
3965 and then not Is_Unchecked_Union
(Rec_Id
))
3966 or else Is_Tagged_Type
(Rec_Id
)
3967 or else Is_Concurrent_Record_Type
(Rec_Id
)
3968 or else Has_Task
(Rec_Id
)
3973 Id
:= First_Component
(Rec_Id
);
3974 while Present
(Id
) loop
3975 Comp_Decl
:= Parent
(Id
);
3978 if Present
(Expression
(Comp_Decl
))
3979 or else Has_Non_Null_Base_Init_Proc
(Typ
)
3980 or else Component_Needs_Simple_Initialization
(Typ
)
3985 Next_Component
(Id
);
3988 -- As explained above, a record initialization procedure is needed
3989 -- for public types in case Initialize_Scalars applies to a client.
3990 -- However, such a procedure is not needed in the case where either
3991 -- of restrictions No_Initialize_Scalars or No_Default_Initialization
3992 -- applies. No_Initialize_Scalars excludes the possibility of using
3993 -- Initialize_Scalars in any partition, and No_Default_Initialization
3994 -- implies that no initialization should ever be done for objects of
3995 -- the type, so is incompatible with Initialize_Scalars.
3997 if not Restriction_Active
(No_Initialize_Scalars
)
3998 and then not Restriction_Active
(No_Default_Initialization
)
3999 and then Is_Public
(Rec_Id
)
4005 end Requires_Init_Proc
;
4007 -- Start of processing for Build_Record_Init_Proc
4010 Rec_Type
:= Defining_Identifier
(N
);
4012 -- This may be full declaration of a private type, in which case
4013 -- the visible entity is a record, and the private entity has been
4014 -- exchanged with it in the private part of the current package.
4015 -- The initialization procedure is built for the record type, which
4016 -- is retrievable from the private entity.
4018 if Is_Incomplete_Or_Private_Type
(Rec_Type
) then
4019 Rec_Type
:= Underlying_Type
(Rec_Type
);
4022 -- If we have a variant record with restriction No_Implicit_Conditionals
4023 -- in effect, then we skip building the procedure. This is safe because
4024 -- if we can see the restriction, so can any caller, calls to initialize
4025 -- such records are not allowed for variant records if this restriction
4028 if Has_Variant_Part
(Rec_Type
)
4029 and then Restriction_Active
(No_Implicit_Conditionals
)
4034 -- If there are discriminants, build the discriminant map to replace
4035 -- discriminants by their discriminals in complex bound expressions.
4036 -- These only arise for the corresponding records of synchronized types.
4038 if Is_Concurrent_Record_Type
(Rec_Type
)
4039 and then Has_Discriminants
(Rec_Type
)
4044 Disc
:= First_Discriminant
(Rec_Type
);
4045 while Present
(Disc
) loop
4046 Append_Elmt
(Disc
, Discr_Map
);
4047 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
4048 Next_Discriminant
(Disc
);
4053 -- Derived types that have no type extension can use the initialization
4054 -- procedure of their parent and do not need a procedure of their own.
4055 -- This is only correct if there are no representation clauses for the
4056 -- type or its parent, and if the parent has in fact been frozen so
4057 -- that its initialization procedure exists.
4059 if Is_Derived_Type
(Rec_Type
)
4060 and then not Is_Tagged_Type
(Rec_Type
)
4061 and then not Is_Unchecked_Union
(Rec_Type
)
4062 and then not Has_New_Non_Standard_Rep
(Rec_Type
)
4063 and then not Parent_Subtype_Renaming_Discrims
4064 and then Present
(Base_Init_Proc
(Etype
(Rec_Type
)))
4066 Copy_TSS
(Base_Init_Proc
(Etype
(Rec_Type
)), Rec_Type
);
4068 -- Otherwise if we need an initialization procedure, then build one,
4069 -- mark it as public and inlinable and as having a completion.
4071 elsif Requires_Init_Proc
(Rec_Type
)
4072 or else Is_Unchecked_Union
(Rec_Type
)
4075 Make_Defining_Identifier
(Loc
,
4076 Chars
=> Make_Init_Proc_Name
(Rec_Type
));
4078 -- If No_Default_Initialization restriction is active, then we don't
4079 -- want to build an init_proc, but we need to mark that an init_proc
4080 -- would be needed if this restriction was not active (so that we can
4081 -- detect attempts to call it), so set a dummy init_proc in place.
4083 if Restriction_Active
(No_Default_Initialization
) then
4084 Set_Init_Proc
(Rec_Type
, Proc_Id
);
4088 Build_Offset_To_Top_Functions
;
4089 Build_CPP_Init_Procedure
;
4090 Build_Init_Procedure
;
4092 Set_Is_Public
(Proc_Id
, Is_Public
(Rec_Ent
));
4093 Set_Is_Internal
(Proc_Id
);
4094 Set_Has_Completion
(Proc_Id
);
4096 if not Debug_Generated_Code
then
4097 Set_Debug_Info_Off
(Proc_Id
);
4100 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Rec_Type
));
4102 -- Do not build an aggregate if Modify_Tree_For_C, this isn't
4103 -- needed and may generate early references to non frozen types
4104 -- since we expand aggregate much more systematically.
4106 if Modify_Tree_For_C
then
4111 Agg
: constant Node_Id
:=
4112 Build_Equivalent_Record_Aggregate
(Rec_Type
);
4114 procedure Collect_Itypes
(Comp
: Node_Id
);
4115 -- Generate references to itypes in the aggregate, because
4116 -- the first use of the aggregate may be in a nested scope.
4118 --------------------
4119 -- Collect_Itypes --
4120 --------------------
4122 procedure Collect_Itypes
(Comp
: Node_Id
) is
4125 Typ
: constant Entity_Id
:= Etype
(Comp
);
4128 if Is_Array_Type
(Typ
) and then Is_Itype
(Typ
) then
4129 Ref
:= Make_Itype_Reference
(Loc
);
4130 Set_Itype
(Ref
, Typ
);
4131 Append_Freeze_Action
(Rec_Type
, Ref
);
4133 Ref
:= Make_Itype_Reference
(Loc
);
4134 Set_Itype
(Ref
, Etype
(First_Index
(Typ
)));
4135 Append_Freeze_Action
(Rec_Type
, Ref
);
4137 -- Recurse on nested arrays
4139 Sub_Aggr
:= First
(Expressions
(Comp
));
4140 while Present
(Sub_Aggr
) loop
4141 Collect_Itypes
(Sub_Aggr
);
4148 -- If there is a static initialization aggregate for the type,
4149 -- generate itype references for the types of its (sub)components,
4150 -- to prevent out-of-scope errors in the resulting tree.
4151 -- The aggregate may have been rewritten as a Raise node, in which
4152 -- case there are no relevant itypes.
4154 if Present
(Agg
) and then Nkind
(Agg
) = N_Aggregate
then
4155 Set_Static_Initialization
(Proc_Id
, Agg
);
4160 Comp
:= First
(Component_Associations
(Agg
));
4161 while Present
(Comp
) loop
4162 Collect_Itypes
(Expression
(Comp
));
4169 end Build_Record_Init_Proc
;
4171 ----------------------------
4172 -- Build_Slice_Assignment --
4173 ----------------------------
4175 -- Generates the following subprogram:
4177 -- procedure array_typeSA
4178 -- (Source, Target : Array_Type,
4179 -- Left_Lo, Left_Hi : Index;
4180 -- Right_Lo, Right_Hi : Index;
4187 -- if Left_Hi < Left_Lo then
4200 -- Target (Li1) := Source (Ri1);
4203 -- exit when Li1 = Left_Lo;
4204 -- Li1 := Index'pred (Li1);
4205 -- Ri1 := Index'pred (Ri1);
4207 -- exit when Li1 = Left_Hi;
4208 -- Li1 := Index'succ (Li1);
4209 -- Ri1 := Index'succ (Ri1);
4212 -- end array_typeSA;
4214 procedure Build_Slice_Assignment
(Typ
: Entity_Id
) is
4215 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4216 Index
: constant Entity_Id
:= Base_Type
(Etype
(First_Index
(Typ
)));
4218 Larray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4219 Rarray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
4220 Left_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
4221 Left_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
4222 Right_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
4223 Right_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
4224 Rev
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
4225 -- Formal parameters of procedure
4227 Proc_Name
: constant Entity_Id
:=
4228 Make_Defining_Identifier
(Loc
,
4229 Chars
=> Make_TSS_Name
(Typ
, TSS_Slice_Assign
));
4231 Lnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
4232 Rnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
4233 -- Subscripts for left and right sides
4240 -- Build declarations for indexes
4245 Make_Object_Declaration
(Loc
,
4246 Defining_Identifier
=> Lnn
,
4247 Object_Definition
=>
4248 New_Occurrence_Of
(Index
, Loc
)));
4251 Make_Object_Declaration
(Loc
,
4252 Defining_Identifier
=> Rnn
,
4253 Object_Definition
=>
4254 New_Occurrence_Of
(Index
, Loc
)));
4258 -- Build test for empty slice case
4261 Make_If_Statement
(Loc
,
4264 Left_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
),
4265 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
)),
4266 Then_Statements
=> New_List
(Make_Simple_Return_Statement
(Loc
))));
4268 -- Build initializations for indexes
4271 F_Init
: constant List_Id
:= New_List
;
4272 B_Init
: constant List_Id
:= New_List
;
4276 Make_Assignment_Statement
(Loc
,
4277 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4278 Expression
=> New_Occurrence_Of
(Left_Lo
, Loc
)));
4281 Make_Assignment_Statement
(Loc
,
4282 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4283 Expression
=> New_Occurrence_Of
(Right_Lo
, Loc
)));
4286 Make_Assignment_Statement
(Loc
,
4287 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4288 Expression
=> New_Occurrence_Of
(Left_Hi
, Loc
)));
4291 Make_Assignment_Statement
(Loc
,
4292 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4293 Expression
=> New_Occurrence_Of
(Right_Hi
, Loc
)));
4296 Make_If_Statement
(Loc
,
4297 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4298 Then_Statements
=> B_Init
,
4299 Else_Statements
=> F_Init
));
4302 -- Now construct the assignment statement
4305 Make_Loop_Statement
(Loc
,
4306 Statements
=> New_List
(
4307 Make_Assignment_Statement
(Loc
,
4309 Make_Indexed_Component
(Loc
,
4310 Prefix
=> New_Occurrence_Of
(Larray
, Loc
),
4311 Expressions
=> New_List
(New_Occurrence_Of
(Lnn
, Loc
))),
4313 Make_Indexed_Component
(Loc
,
4314 Prefix
=> New_Occurrence_Of
(Rarray
, Loc
),
4315 Expressions
=> New_List
(New_Occurrence_Of
(Rnn
, Loc
))))),
4316 End_Label
=> Empty
);
4318 -- Build the exit condition and increment/decrement statements
4321 F_Ass
: constant List_Id
:= New_List
;
4322 B_Ass
: constant List_Id
:= New_List
;
4326 Make_Exit_Statement
(Loc
,
4329 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4330 Right_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
))));
4333 Make_Assignment_Statement
(Loc
,
4334 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4336 Make_Attribute_Reference
(Loc
,
4338 New_Occurrence_Of
(Index
, Loc
),
4339 Attribute_Name
=> Name_Succ
,
4340 Expressions
=> New_List
(
4341 New_Occurrence_Of
(Lnn
, Loc
)))));
4344 Make_Assignment_Statement
(Loc
,
4345 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4347 Make_Attribute_Reference
(Loc
,
4349 New_Occurrence_Of
(Index
, Loc
),
4350 Attribute_Name
=> Name_Succ
,
4351 Expressions
=> New_List
(
4352 New_Occurrence_Of
(Rnn
, Loc
)))));
4355 Make_Exit_Statement
(Loc
,
4358 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4359 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
))));
4362 Make_Assignment_Statement
(Loc
,
4363 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4365 Make_Attribute_Reference
(Loc
,
4367 New_Occurrence_Of
(Index
, Loc
),
4368 Attribute_Name
=> Name_Pred
,
4369 Expressions
=> New_List
(
4370 New_Occurrence_Of
(Lnn
, Loc
)))));
4373 Make_Assignment_Statement
(Loc
,
4374 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4376 Make_Attribute_Reference
(Loc
,
4378 New_Occurrence_Of
(Index
, Loc
),
4379 Attribute_Name
=> Name_Pred
,
4380 Expressions
=> New_List
(
4381 New_Occurrence_Of
(Rnn
, Loc
)))));
4383 Append_To
(Statements
(Loops
),
4384 Make_If_Statement
(Loc
,
4385 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4386 Then_Statements
=> B_Ass
,
4387 Else_Statements
=> F_Ass
));
4390 Append_To
(Stats
, Loops
);
4397 Formals
:= New_List
(
4398 Make_Parameter_Specification
(Loc
,
4399 Defining_Identifier
=> Larray
,
4400 Out_Present
=> True,
4402 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4404 Make_Parameter_Specification
(Loc
,
4405 Defining_Identifier
=> Rarray
,
4407 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4409 Make_Parameter_Specification
(Loc
,
4410 Defining_Identifier
=> Left_Lo
,
4412 New_Occurrence_Of
(Index
, Loc
)),
4414 Make_Parameter_Specification
(Loc
,
4415 Defining_Identifier
=> Left_Hi
,
4417 New_Occurrence_Of
(Index
, Loc
)),
4419 Make_Parameter_Specification
(Loc
,
4420 Defining_Identifier
=> Right_Lo
,
4422 New_Occurrence_Of
(Index
, Loc
)),
4424 Make_Parameter_Specification
(Loc
,
4425 Defining_Identifier
=> Right_Hi
,
4427 New_Occurrence_Of
(Index
, Loc
)));
4430 Make_Parameter_Specification
(Loc
,
4431 Defining_Identifier
=> Rev
,
4433 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
4436 Make_Procedure_Specification
(Loc
,
4437 Defining_Unit_Name
=> Proc_Name
,
4438 Parameter_Specifications
=> Formals
);
4441 Make_Subprogram_Body
(Loc
,
4442 Specification
=> Spec
,
4443 Declarations
=> Decls
,
4444 Handled_Statement_Sequence
=>
4445 Make_Handled_Sequence_Of_Statements
(Loc
,
4446 Statements
=> Stats
)));
4449 Set_TSS
(Typ
, Proc_Name
);
4450 Set_Is_Pure
(Proc_Name
);
4451 end Build_Slice_Assignment
;
4453 ------------------------------------
4454 -- Build_Untagged_Record_Equality --
4455 ------------------------------------
4457 procedure Build_Untagged_Record_Equality
(Typ
: Entity_Id
) is
4464 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
;
4465 -- Check whether the type T has a user-defined primitive equality. If so
4466 -- return it, else return Empty. If true for a component of Typ, we have
4467 -- to build the primitive equality for it.
4469 ---------------------
4470 -- User_Defined_Eq --
4471 ---------------------
4473 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
is
4474 Op
: constant Entity_Id
:= TSS
(T
, TSS_Composite_Equality
);
4477 if Present
(Op
) then
4480 return Get_User_Defined_Equality
(T
);
4482 end User_Defined_Eq
;
4484 -- Start of processing for Build_Untagged_Record_Equality
4487 -- If a record component has a primitive equality operation, we must
4488 -- build the corresponding one for the current type.
4491 Comp
:= First_Component
(Typ
);
4492 while Present
(Comp
) loop
4493 if Is_Record_Type
(Etype
(Comp
))
4494 and then Present
(User_Defined_Eq
(Etype
(Comp
)))
4500 Next_Component
(Comp
);
4503 -- If there is a user-defined equality for the type, we do not create
4504 -- the implicit one.
4506 Eq_Op
:= Get_User_Defined_Equality
(Typ
);
4507 if Present
(Eq_Op
) then
4508 if Comes_From_Source
(Eq_Op
) then
4515 -- If the type is derived, inherit the operation, if present, from the
4516 -- parent type. It may have been declared after the type derivation. If
4517 -- the parent type itself is derived, it may have inherited an operation
4518 -- that has itself been overridden, so update its alias and related
4519 -- flags. Ditto for inequality.
4521 if No
(Eq_Op
) and then Is_Derived_Type
(Typ
) then
4522 Eq_Op
:= Get_User_Defined_Equality
(Etype
(Typ
));
4523 if Present
(Eq_Op
) then
4524 Copy_TSS
(Eq_Op
, Typ
);
4528 Op
: constant Entity_Id
:= User_Defined_Eq
(Typ
);
4529 NE_Op
: constant Entity_Id
:= Next_Entity
(Eq_Op
);
4532 if Present
(Op
) then
4533 Set_Alias
(Op
, Eq_Op
);
4534 Set_Is_Abstract_Subprogram
4535 (Op
, Is_Abstract_Subprogram
(Eq_Op
));
4537 if Chars
(Next_Entity
(Op
)) = Name_Op_Ne
then
4538 Set_Is_Abstract_Subprogram
4539 (Next_Entity
(Op
), Is_Abstract_Subprogram
(NE_Op
));
4546 -- If not inherited and not user-defined, build body as for a type with
4547 -- components of record type (i.e. a type for which "=" composes when
4548 -- used as a component in an outer composite type).
4552 Make_Eq_Body
(Typ
, Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4553 Op
:= Defining_Entity
(Decl
);
4557 if Is_Library_Level_Entity
(Typ
) then
4561 end Build_Untagged_Record_Equality
;
4563 -----------------------------------
4564 -- Build_Variant_Record_Equality --
4565 -----------------------------------
4569 -- function <<Body_Id>> (Left, Right : T) return Boolean is
4570 -- [ X : T renames Left; ]
4571 -- [ Y : T renames Right; ]
4572 -- -- The above renamings are generated only if the parameters of
4573 -- -- this built function (which are passed by the caller) are not
4574 -- -- named 'X' and 'Y'; these names are required to reuse several
4575 -- -- expander routines when generating this body.
4578 -- -- Compare discriminants
4580 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4584 -- -- Compare components
4586 -- if X.C1 /= Y.C1 or else X.C2 /= Y.C2 or else ... then
4590 -- -- Compare variant part
4594 -- if X.C2 /= Y.C2 or else X.C3 /= Y.C3 or else ... then
4599 -- if X.Cn /= Y.Cn or else ... then
4607 function Build_Variant_Record_Equality
4609 Spec_Id
: Entity_Id
;
4610 Body_Id
: Entity_Id
;
4611 Param_Specs
: List_Id
) return Node_Id
4613 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4614 Def
: constant Node_Id
:= Parent
(Typ
);
4615 Comps
: constant Node_Id
:= Component_List
(Type_Definition
(Def
));
4616 Left
: constant Entity_Id
:= Defining_Identifier
(First
(Param_Specs
));
4617 Right
: constant Entity_Id
:=
4618 Defining_Identifier
(Next
(First
(Param_Specs
)));
4619 Decls
: constant List_Id
:= New_List
;
4620 Stmts
: constant List_Id
:= New_List
;
4622 Subp_Body
: Node_Id
;
4625 pragma Assert
(not Is_Tagged_Type
(Typ
));
4627 -- In order to reuse the expander routines Make_Eq_If and Make_Eq_Case
4628 -- the name of the formals must be X and Y; otherwise we generate two
4629 -- renaming declarations for such purpose.
4631 if Chars
(Left
) /= Name_X
then
4633 Make_Object_Renaming_Declaration
(Loc
,
4634 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
4635 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4636 Name
=> Make_Identifier
(Loc
, Chars
(Left
))));
4639 if Chars
(Right
) /= Name_Y
then
4641 Make_Object_Renaming_Declaration
(Loc
,
4642 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
4643 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4644 Name
=> Make_Identifier
(Loc
, Chars
(Right
))));
4647 -- Unchecked_Unions require additional machinery to support equality.
4648 -- Two extra parameters (A and B) are added to the equality function
4649 -- parameter list for each discriminant of the type, in order to
4650 -- capture the inferred values of the discriminants in equality calls.
4651 -- The names of the parameters match the names of the corresponding
4652 -- discriminant, with an added suffix.
4654 if Is_Unchecked_Union
(Typ
) then
4656 Right_Formal
: constant Entity_Id
:=
4657 (if Present
(Spec_Id
) then Last_Formal
(Spec_Id
) else Right
);
4658 Scop
: constant Entity_Id
:=
4659 (if Present
(Spec_Id
) then Spec_Id
else Body_Id
);
4661 procedure Decorate_Extra_Formal
(F
, F_Typ
: Entity_Id
);
4662 -- Decorate extra formal F with type F_Typ
4664 ---------------------------
4665 -- Decorate_Extra_Formal --
4666 ---------------------------
4668 procedure Decorate_Extra_Formal
(F
, F_Typ
: Entity_Id
) is
4670 Mutate_Ekind
(F
, E_In_Parameter
);
4671 Set_Etype
(F
, F_Typ
);
4672 Set_Scope
(F
, Scop
);
4673 Set_Mechanism
(F
, By_Copy
);
4674 end Decorate_Extra_Formal
;
4679 Discr_Type
: Entity_Id
;
4680 Last_Extra
: Entity_Id
:= Empty
;
4681 New_Discrs
: Elist_Id
;
4684 Mutate_Ekind
(Body_Id
, E_Subprogram_Body
);
4685 New_Discrs
:= New_Elmt_List
;
4687 Discr
:= First_Discriminant
(Typ
);
4688 while Present
(Discr
) loop
4689 Discr_Type
:= Etype
(Discr
);
4691 -- Add the new parameters as extra formals
4694 Make_Defining_Identifier
(Loc
,
4695 Chars
=> New_External_Name
(Chars
(Discr
), 'A'));
4697 Decorate_Extra_Formal
(A
, Discr_Type
);
4699 if Present
(Last_Extra
) then
4700 Set_Extra_Formal
(Last_Extra
, A
);
4702 Set_Extra_Formal
(Right_Formal
, A
);
4703 Set_Extra_Formals
(Scop
, A
);
4706 Append_Elmt
(A
, New_Discrs
);
4709 Make_Defining_Identifier
(Loc
,
4710 Chars
=> New_External_Name
(Chars
(Discr
), 'B'));
4712 Decorate_Extra_Formal
(B
, Discr_Type
);
4714 Set_Extra_Formal
(A
, B
);
4717 -- Generate the following code to compare each of the inferred
4725 Make_If_Statement
(Loc
,
4728 Left_Opnd
=> New_Occurrence_Of
(A
, Loc
),
4729 Right_Opnd
=> New_Occurrence_Of
(B
, Loc
)),
4730 Then_Statements
=> New_List
(
4731 Make_Simple_Return_Statement
(Loc
,
4733 New_Occurrence_Of
(Standard_False
, Loc
)))));
4735 Next_Discriminant
(Discr
);
4738 -- Generate component-by-component comparison. Note that we must
4739 -- propagate the inferred discriminants formals to act as the case
4740 -- statement switch. Their value is added when an equality call on
4741 -- unchecked unions is expanded.
4743 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
, New_Discrs
));
4746 -- Normal case (not unchecked union)
4750 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
4751 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
4755 Make_Simple_Return_Statement
(Loc
,
4756 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
4759 Make_Subprogram_Body
(Loc
,
4761 Make_Function_Specification
(Loc
,
4762 Defining_Unit_Name
=> Body_Id
,
4763 Parameter_Specifications
=> Param_Specs
,
4764 Result_Definition
=>
4765 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
4766 Declarations
=> Decls
,
4767 Handled_Statement_Sequence
=>
4768 Make_Handled_Sequence_Of_Statements
(Loc
,
4769 Statements
=> Stmts
));
4772 end Build_Variant_Record_Equality
;
4774 -----------------------------
4775 -- Check_Stream_Attributes --
4776 -----------------------------
4778 procedure Check_Stream_Attributes
(Typ
: Entity_Id
) is
4780 Par_Read
: constant Boolean :=
4781 Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
4782 and then not Has_Specified_Stream_Read
(Typ
);
4783 Par_Write
: constant Boolean :=
4784 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
4785 and then not Has_Specified_Stream_Write
(Typ
);
4787 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
);
4788 -- Check that Comp has a user-specified Nam stream attribute
4794 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
) is
4796 -- Move this check to sem???
4798 if not Stream_Attribute_Available
(Etype
(Comp
), TSS_Nam
) then
4799 Error_Msg_Name_1
:= Nam
;
4801 ("|component& in limited extension must have% attribute", Comp
);
4805 -- Start of processing for Check_Stream_Attributes
4808 if Par_Read
or else Par_Write
then
4809 Comp
:= First_Component
(Typ
);
4810 while Present
(Comp
) loop
4811 if Comes_From_Source
(Comp
)
4812 and then Original_Record_Component
(Comp
) = Comp
4813 and then Is_Limited_Type
(Etype
(Comp
))
4816 Check_Attr
(Name_Read
, TSS_Stream_Read
);
4820 Check_Attr
(Name_Write
, TSS_Stream_Write
);
4824 Next_Component
(Comp
);
4827 end Check_Stream_Attributes
;
4829 ----------------------
4830 -- Clean_Task_Names --
4831 ----------------------
4833 procedure Clean_Task_Names
4835 Proc_Id
: Entity_Id
)
4839 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
4840 and then not Global_Discard_Names
4841 and then Tagged_Type_Expansion
4843 Set_Uses_Sec_Stack
(Proc_Id
);
4845 end Clean_Task_Names
;
4847 -------------------------------
4848 -- Copy_Discr_Checking_Funcs --
4849 -------------------------------
4851 procedure Copy_Discr_Checking_Funcs
(N
: Node_Id
) is
4852 Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
4853 Comp
: Entity_Id
:= First_Component
(Typ
);
4854 Old_Comp
: Entity_Id
:= First_Component
4855 (Base_Type
(Underlying_Type
(Etype
(Typ
))));
4857 while Present
(Comp
) loop
4858 if Chars
(Comp
) = Chars
(Old_Comp
) then
4859 Set_Discriminant_Checking_Func
4860 (Comp
, Discriminant_Checking_Func
(Old_Comp
));
4863 Next_Component
(Old_Comp
);
4864 Next_Component
(Comp
);
4866 end Copy_Discr_Checking_Funcs
;
4868 ------------------------------
4869 -- Expand_Freeze_Array_Type --
4870 ------------------------------
4872 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
4873 Typ
: constant Entity_Id
:= Entity
(N
);
4874 Base
: constant Entity_Id
:= Base_Type
(Typ
);
4875 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
4878 if not Is_Bit_Packed_Array
(Typ
) then
4880 -- If the component contains tasks, so does the array type. This may
4881 -- not be indicated in the array type because the component may have
4882 -- been a private type at the point of definition. Same if component
4883 -- type is controlled or contains protected objects.
4885 Propagate_Concurrent_Flags
(Base
, Comp_Typ
);
4886 Set_Has_Controlled_Component
4887 (Base
, Has_Controlled_Component
(Comp_Typ
)
4888 or else Is_Controlled
(Comp_Typ
));
4890 if No
(Init_Proc
(Base
)) then
4892 -- If this is an anonymous array created for a declaration with
4893 -- an initial value, its init_proc will never be called. The
4894 -- initial value itself may have been expanded into assignments,
4895 -- in which case the object declaration is carries the
4896 -- No_Initialization flag.
4899 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
4900 N_Object_Declaration
4902 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
4903 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
4907 -- We do not need an init proc for string or wide [wide] string,
4908 -- since the only time these need initialization in normalize or
4909 -- initialize scalars mode, and these types are treated specially
4910 -- and do not need initialization procedures.
4912 elsif Is_Standard_String_Type
(Base
) then
4915 -- Otherwise we have to build an init proc for the subtype
4918 Build_Array_Init_Proc
(Base
, N
);
4922 if Typ
= Base
and then Has_Controlled_Component
(Base
) then
4923 Build_Controlling_Procs
(Base
);
4925 if not Is_Limited_Type
(Comp_Typ
)
4926 and then Number_Dimensions
(Typ
) = 1
4928 Build_Slice_Assignment
(Typ
);
4932 -- For packed case, default initialization, except if the component type
4933 -- is itself a packed structure with an initialization procedure, or
4934 -- initialize/normalize scalars active, and we have a base type, or the
4935 -- type is public, because in that case a client might specify
4936 -- Normalize_Scalars and there better be a public Init_Proc for it.
4938 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
4939 and then No
(Base_Init_Proc
(Base
)))
4940 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
4941 or else Is_Public
(Typ
)
4943 Build_Array_Init_Proc
(Base
, N
);
4945 end Expand_Freeze_Array_Type
;
4947 -----------------------------------
4948 -- Expand_Freeze_Class_Wide_Type --
4949 -----------------------------------
4951 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
4952 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
4953 -- Given a type, determine whether it is derived from a C or C++ root
4955 ---------------------
4956 -- Is_C_Derivation --
4957 ---------------------
4959 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
4966 or else Convention
(T
) = Convention_C
4967 or else Convention
(T
) = Convention_CPP
4972 exit when T
= Etype
(T
);
4978 end Is_C_Derivation
;
4982 Typ
: constant Entity_Id
:= Entity
(N
);
4983 Root
: constant Entity_Id
:= Root_Type
(Typ
);
4985 -- Start of processing for Expand_Freeze_Class_Wide_Type
4988 -- Certain run-time configurations and targets do not provide support
4989 -- for controlled types.
4991 if Restriction_Active
(No_Finalization
) then
4994 -- Do not create TSS routine Finalize_Address when dispatching calls are
4995 -- disabled since the core of the routine is a dispatching call.
4997 elsif Restriction_Active
(No_Dispatching_Calls
) then
5000 -- Do not create TSS routine Finalize_Address for concurrent class-wide
5001 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
5002 -- non-Ada side will handle their destruction.
5004 -- Concurrent Ada types are functionally represented by an associated
5005 -- "corresponding record type" (typenameV), which owns the actual TSS
5006 -- finalize bodies for the type (and technically class-wide type).
5008 elsif Is_Concurrent_Type
(Root
)
5009 or else Is_C_Derivation
(Root
)
5010 or else Convention
(Typ
) = Convention_CPP
5014 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
5015 -- mode since the routine contains an Unchecked_Conversion.
5017 elsif CodePeer_Mode
then
5021 -- Create the body of TSS primitive Finalize_Address. This automatically
5022 -- sets the TSS entry for the class-wide type.
5024 Make_Finalize_Address_Body
(Typ
);
5025 end Expand_Freeze_Class_Wide_Type
;
5027 ------------------------------------
5028 -- Expand_Freeze_Enumeration_Type --
5029 ------------------------------------
5031 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
5032 Typ
: constant Entity_Id
:= Entity
(N
);
5033 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5038 Is_Contiguous
: Boolean;
5039 Index_Typ
: Entity_Id
;
5047 pragma Warnings
(Off
, Func
);
5050 -- Various optimizations possible if given representation is contiguous
5052 Is_Contiguous
:= True;
5054 Ent
:= First_Literal
(Typ
);
5055 Last_Repval
:= Enumeration_Rep
(Ent
);
5059 while Present
(Ent
) loop
5060 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
5061 Is_Contiguous
:= False;
5063 Last_Repval
:= Enumeration_Rep
(Ent
);
5070 if Is_Contiguous
then
5071 Set_Has_Contiguous_Rep
(Typ
);
5073 -- Now build a subtype declaration
5075 -- subtype typI is new Natural range 0 .. num - 1
5078 Make_Defining_Identifier
(Loc
,
5079 Chars
=> New_External_Name
(Chars
(Typ
), 'I'));
5081 Append_Freeze_Action
(Typ
,
5082 Make_Subtype_Declaration
(Loc
,
5083 Defining_Identifier
=> Index_Typ
,
5084 Subtype_Indication
=>
5085 Make_Subtype_Indication
(Loc
,
5087 New_Occurrence_Of
(Standard_Natural
, Loc
),
5089 Make_Range_Constraint
(Loc
,
5093 Make_Integer_Literal
(Loc
, 0),
5095 Make_Integer_Literal
(Loc
, Num
- 1))))));
5097 Set_Enum_Pos_To_Rep
(Typ
, Index_Typ
);
5100 -- Build list of literal references
5103 Ent
:= First_Literal
(Typ
);
5104 while Present
(Ent
) loop
5105 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
5109 -- Now build an array declaration
5111 -- typA : constant array (Natural range 0 .. num - 1) of typ :=
5112 -- (v, v, v, v, v, ....)
5115 Make_Defining_Identifier
(Loc
,
5116 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
5118 Append_Freeze_Action
(Typ
,
5119 Make_Object_Declaration
(Loc
,
5120 Defining_Identifier
=> Arr
,
5121 Constant_Present
=> True,
5123 Object_Definition
=>
5124 Make_Constrained_Array_Definition
(Loc
,
5125 Discrete_Subtype_Definitions
=> New_List
(
5126 Make_Subtype_Indication
(Loc
,
5128 New_Occurrence_Of
(Standard_Natural
, Loc
),
5130 Make_Range_Constraint
(Loc
,
5134 Make_Integer_Literal
(Loc
, 0),
5136 Make_Integer_Literal
(Loc
, Num
- 1))))),
5138 Component_Definition
=>
5139 Make_Component_Definition
(Loc
,
5140 Aliased_Present
=> False,
5141 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
5144 Make_Aggregate
(Loc
,
5145 Expressions
=> Lst
)));
5147 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
5150 -- Now we build the function that converts representation values to
5151 -- position values. This function has the form:
5153 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
5156 -- when enum-lit'Enum_Rep => return posval;
5157 -- when enum-lit'Enum_Rep => return posval;
5160 -- [raise Constraint_Error when F "invalid data"]
5165 -- Note: the F parameter determines whether the others case (no valid
5166 -- representation) raises Constraint_Error or returns a unique value
5167 -- of minus one. The latter case is used, e.g. in 'Valid code.
5169 -- Note: the reason we use Enum_Rep values in the case here is to avoid
5170 -- the code generator making inappropriate assumptions about the range
5171 -- of the values in the case where the value is invalid. ityp is a
5172 -- signed or unsigned integer type of appropriate width.
5174 -- Note: if exceptions are not supported, then we suppress the raise
5175 -- and return -1 unconditionally (this is an erroneous program in any
5176 -- case and there is no obligation to raise Constraint_Error here). We
5177 -- also do this if pragma Restrictions (No_Exceptions) is active.
5179 -- Is this right??? What about No_Exception_Propagation???
5181 -- The underlying type is signed. Reset the Is_Unsigned_Type explicitly
5182 -- because it might have been inherited from the parent type.
5184 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
5185 Set_Is_Unsigned_Type
(Typ
, False);
5188 Ityp
:= Integer_Type_For
(Esize
(Typ
), Is_Unsigned_Type
(Typ
));
5190 -- The body of the function is a case statement. First collect case
5191 -- alternatives, or optimize the contiguous case.
5195 -- If representation is contiguous, Pos is computed by subtracting
5196 -- the representation of the first literal.
5198 if Is_Contiguous
then
5199 Ent
:= First_Literal
(Typ
);
5201 if Enumeration_Rep
(Ent
) = Last_Repval
then
5203 -- Another special case: for a single literal, Pos is zero
5205 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
5209 Convert_To
(Standard_Integer
,
5210 Make_Op_Subtract
(Loc
,
5212 Unchecked_Convert_To
5213 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
5215 Make_Integer_Literal
(Loc
,
5216 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
5220 Make_Case_Statement_Alternative
(Loc
,
5221 Discrete_Choices
=> New_List
(
5222 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
5224 Make_Integer_Literal
(Loc
,
5225 Intval
=> Enumeration_Rep
(Ent
)),
5227 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
5229 Statements
=> New_List
(
5230 Make_Simple_Return_Statement
(Loc
,
5231 Expression
=> Pos_Expr
))));
5234 Ent
:= First_Literal
(Typ
);
5235 while Present
(Ent
) loop
5237 Make_Case_Statement_Alternative
(Loc
,
5238 Discrete_Choices
=> New_List
(
5239 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
5240 Intval
=> Enumeration_Rep
(Ent
))),
5242 Statements
=> New_List
(
5243 Make_Simple_Return_Statement
(Loc
,
5245 Make_Integer_Literal
(Loc
,
5246 Intval
=> Enumeration_Pos
(Ent
))))));
5252 -- In normal mode, add the others clause with the test.
5253 -- If Predicates_Ignored is True, validity checks do not apply to
5256 if not No_Exception_Handlers_Set
5257 and then not Predicates_Ignored
(Typ
)
5260 Make_Case_Statement_Alternative
(Loc
,
5261 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5262 Statements
=> New_List
(
5263 Make_Raise_Constraint_Error
(Loc
,
5264 Condition
=> Make_Identifier
(Loc
, Name_uF
),
5265 Reason
=> CE_Invalid_Data
),
5266 Make_Simple_Return_Statement
(Loc
,
5267 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
5269 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
5270 -- active then return -1 (we cannot usefully raise Constraint_Error in
5271 -- this case). See description above for further details.
5275 Make_Case_Statement_Alternative
(Loc
,
5276 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5277 Statements
=> New_List
(
5278 Make_Simple_Return_Statement
(Loc
,
5279 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
5282 -- Now we can build the function body
5285 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
5288 Make_Subprogram_Body
(Loc
,
5290 Make_Function_Specification
(Loc
,
5291 Defining_Unit_Name
=> Fent
,
5292 Parameter_Specifications
=> New_List
(
5293 Make_Parameter_Specification
(Loc
,
5294 Defining_Identifier
=>
5295 Make_Defining_Identifier
(Loc
, Name_uA
),
5296 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
5297 Make_Parameter_Specification
(Loc
,
5298 Defining_Identifier
=>
5299 Make_Defining_Identifier
(Loc
, Name_uF
),
5301 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
5303 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
5305 Declarations
=> Empty_List
,
5307 Handled_Statement_Sequence
=>
5308 Make_Handled_Sequence_Of_Statements
(Loc
,
5309 Statements
=> New_List
(
5310 Make_Case_Statement
(Loc
,
5312 Unchecked_Convert_To
5313 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
5314 Alternatives
=> Lst
))));
5316 Set_TSS
(Typ
, Fent
);
5318 -- Set Pure flag (it will be reset if the current context is not Pure).
5319 -- We also pretend there was a pragma Pure_Function so that for purposes
5320 -- of optimization and constant-folding, we will consider the function
5321 -- Pure even if we are not in a Pure context).
5324 Set_Has_Pragma_Pure_Function
(Fent
);
5326 -- Unless we are in -gnatD mode, where we are debugging generated code,
5327 -- this is an internal entity for which we don't need debug info.
5329 if not Debug_Generated_Code
then
5330 Set_Debug_Info_Off
(Fent
);
5333 Set_Is_Inlined
(Fent
);
5336 when RE_Not_Available
=>
5338 end Expand_Freeze_Enumeration_Type
;
5340 -------------------------------
5341 -- Expand_Freeze_Record_Type --
5342 -------------------------------
5344 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
5346 procedure Build_Class_Condition_Subprograms
(Typ
: Entity_Id
);
5347 -- Create internal subprograms of Typ primitives that have class-wide
5348 -- preconditions or postconditions; they are invoked by the caller to
5349 -- evaluate the conditions.
5351 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
);
5352 -- Create an equality function for the untagged variant record Typ and
5353 -- attach it to the TSS list.
5355 procedure Register_Dispatch_Table_Wrappers
(Typ
: Entity_Id
);
5356 -- Register dispatch-table wrappers in the dispatch table of Typ
5358 procedure Validate_Tagged_Type_Extra_Formals
(Typ
: Entity_Id
);
5359 -- Check extra formals of dispatching primitives of tagged type Typ.
5360 -- Used in pragma Debug.
5362 ---------------------------------------
5363 -- Build_Class_Condition_Subprograms --
5364 ---------------------------------------
5366 procedure Build_Class_Condition_Subprograms
(Typ
: Entity_Id
) is
5367 Prim_List
: constant Elist_Id
:= Primitive_Operations
(Typ
);
5368 Prim_Elmt
: Elmt_Id
:= First_Elmt
(Prim_List
);
5372 while Present
(Prim_Elmt
) loop
5373 Prim
:= Node
(Prim_Elmt
);
5375 -- Primitive with class-wide preconditions
5377 if Comes_From_Source
(Prim
)
5378 and then Has_Significant_Contract
(Prim
)
5380 (Present
(Class_Preconditions
(Prim
))
5381 or else Present
(Ignored_Class_Preconditions
(Prim
)))
5383 if Expander_Active
then
5384 Make_Class_Precondition_Subps
(Prim
);
5387 -- Wrapper of a primitive that has or inherits class-wide
5390 elsif Is_Primitive_Wrapper
(Prim
)
5392 (Present
(Nearest_Class_Condition_Subprogram
5394 Kind
=> Class_Precondition
))
5396 Present
(Nearest_Class_Condition_Subprogram
5398 Kind
=> Ignored_Class_Precondition
)))
5400 if Expander_Active
then
5401 Make_Class_Precondition_Subps
(Prim
);
5405 Next_Elmt
(Prim_Elmt
);
5407 end Build_Class_Condition_Subprograms
;
5409 -----------------------------------
5410 -- Build_Variant_Record_Equality --
5411 -----------------------------------
5413 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
) is
5414 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5415 F
: constant Entity_Id
:=
5416 Make_Defining_Identifier
(Loc
,
5417 Chars
=> Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
5419 -- For a variant record with restriction No_Implicit_Conditionals
5420 -- in effect we skip building the procedure. This is safe because
5421 -- if we can see the restriction, so can any caller, and calls to
5422 -- equality test routines are not allowed for variant records if
5423 -- this restriction is active.
5425 if Restriction_Active
(No_Implicit_Conditionals
) then
5429 -- Derived Unchecked_Union types no longer inherit the equality
5430 -- function of their parent.
5432 if Is_Derived_Type
(Typ
)
5433 and then not Is_Unchecked_Union
(Typ
)
5434 and then not Has_New_Non_Standard_Rep
(Typ
)
5437 Parent_Eq
: constant Entity_Id
:=
5438 TSS
(Root_Type
(Typ
), TSS_Composite_Equality
);
5440 if Present
(Parent_Eq
) then
5441 Copy_TSS
(Parent_Eq
, Typ
);
5448 Build_Variant_Record_Equality
5452 Param_Specs
=> New_List
(
5453 Make_Parameter_Specification
(Loc
,
5454 Defining_Identifier
=>
5455 Make_Defining_Identifier
(Loc
, Name_X
),
5456 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
5458 Make_Parameter_Specification
(Loc
,
5459 Defining_Identifier
=>
5460 Make_Defining_Identifier
(Loc
, Name_Y
),
5461 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))));
5466 if not Debug_Generated_Code
then
5467 Set_Debug_Info_Off
(F
);
5469 end Build_Variant_Record_Equality
;
5471 --------------------------------------
5472 -- Register_Dispatch_Table_Wrappers --
5473 --------------------------------------
5475 procedure Register_Dispatch_Table_Wrappers
(Typ
: Entity_Id
) is
5476 Elmt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
5480 while Present
(Elmt
) loop
5481 Subp
:= Node
(Elmt
);
5483 if Is_Dispatch_Table_Wrapper
(Subp
) then
5484 Append_Freeze_Actions
(Typ
,
5485 Register_Primitive
(Sloc
(Subp
), Subp
));
5490 end Register_Dispatch_Table_Wrappers
;
5492 ----------------------------------------
5493 -- Validate_Tagged_Type_Extra_Formals --
5494 ----------------------------------------
5496 procedure Validate_Tagged_Type_Extra_Formals
(Typ
: Entity_Id
) is
5497 Ovr_Subp
: Entity_Id
;
5502 pragma Assert
(not Is_Class_Wide_Type
(Typ
));
5504 -- No check required if expansion is not active since we never
5505 -- generate extra formals in such case.
5507 if not Expander_Active
then
5511 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5512 while Present
(Elmt
) loop
5513 Subp
:= Node
(Elmt
);
5515 -- Extra formals of a dispatching primitive must match:
5517 -- 1) The extra formals of its covered interface primitive
5519 if Present
(Interface_Alias
(Subp
)) then
5521 (Extra_Formals_Match_OK
5522 (E
=> Interface_Alias
(Subp
),
5523 Ref_E
=> Alias
(Subp
)));
5526 -- 2) The extra formals of its renamed primitive
5528 if Present
(Alias
(Subp
)) then
5530 (Extra_Formals_Match_OK
5532 Ref_E
=> Ultimate_Alias
(Subp
)));
5535 -- 3) The extra formals of its overridden primitive
5537 if Present
(Overridden_Operation
(Subp
)) then
5538 Ovr_Subp
:= Overridden_Operation
(Subp
);
5540 -- Handle controlling function wrapper
5542 if Is_Wrapper
(Subp
)
5543 and then Ultimate_Alias
(Ovr_Subp
) = Subp
5545 if Present
(Overridden_Operation
(Ovr_Subp
)) then
5547 (Extra_Formals_Match_OK
5549 Ref_E
=> Overridden_Operation
(Ovr_Subp
)));
5554 (Extra_Formals_Match_OK
5556 Ref_E
=> Ovr_Subp
));
5562 end Validate_Tagged_Type_Extra_Formals
;
5566 Typ
: constant Node_Id
:= Entity
(N
);
5567 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
5570 Comp_Typ
: Entity_Id
;
5571 Predef_List
: List_Id
;
5573 Wrapper_Decl_List
: List_Id
;
5574 Wrapper_Body_List
: List_Id
:= No_List
;
5576 Renamed_Eq
: Node_Id
:= Empty
;
5577 -- Defining unit name for the predefined equality function in the case
5578 -- where the type has a primitive operation that is a renaming of
5579 -- predefined equality (but only if there is also an overriding
5580 -- user-defined equality function). Used to pass this entity from
5581 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
5583 -- Start of processing for Expand_Freeze_Record_Type
5586 -- Build discriminant checking functions if not a derived type (for
5587 -- derived types that are not tagged types, always use the discriminant
5588 -- checking functions of the parent type). However, for untagged types
5589 -- the derivation may have taken place before the parent was frozen, so
5590 -- we copy explicitly the discriminant checking functions from the
5591 -- parent into the components of the derived type.
5593 Build_Or_Copy_Discr_Checking_Funcs
(Typ_Decl
);
5595 if Is_Derived_Type
(Typ
)
5596 and then Is_Limited_Type
(Typ
)
5597 and then Is_Tagged_Type
(Typ
)
5599 Check_Stream_Attributes
(Typ
);
5602 -- Update task, protected, and controlled component flags, because some
5603 -- of the component types may have been private at the point of the
5604 -- record declaration. Detect anonymous access-to-controlled components.
5606 Comp
:= First_Component
(Typ
);
5607 while Present
(Comp
) loop
5608 Comp_Typ
:= Etype
(Comp
);
5610 Propagate_Concurrent_Flags
(Typ
, Comp_Typ
);
5612 -- Do not set Has_Controlled_Component on a class-wide equivalent
5613 -- type. See Make_CW_Equivalent_Type.
5615 if not Is_Class_Wide_Equivalent_Type
(Typ
)
5617 (Has_Controlled_Component
(Comp_Typ
)
5618 or else (Chars
(Comp
) /= Name_uParent
5619 and then Is_Controlled
(Comp_Typ
)))
5621 Set_Has_Controlled_Component
(Typ
);
5624 Next_Component
(Comp
);
5627 -- Handle constructors of untagged CPP_Class types
5629 if not Is_Tagged_Type
(Typ
) and then Is_CPP_Class
(Typ
) then
5630 Set_CPP_Constructors
(Typ
);
5633 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
5634 -- for regular tagged types as well as for Ada types deriving from a C++
5635 -- Class, but not for tagged types directly corresponding to C++ classes
5636 -- In the later case we assume that it is created in the C++ side and we
5639 if Is_Tagged_Type
(Typ
) then
5641 -- Add the _Tag component
5643 if Underlying_Type
(Etype
(Typ
)) = Typ
then
5644 Expand_Tagged_Root
(Typ
);
5647 if Is_CPP_Class
(Typ
) then
5648 Set_All_DT_Position
(Typ
);
5650 -- Create the tag entities with a minimum decoration
5652 if Tagged_Type_Expansion
then
5653 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5656 Set_CPP_Constructors
(Typ
);
5659 if not Building_Static_DT
(Typ
) then
5661 -- Usually inherited primitives are not delayed but the first
5662 -- Ada extension of a CPP_Class is an exception since the
5663 -- address of the inherited subprogram has to be inserted in
5664 -- the new Ada Dispatch Table and this is a freezing action.
5666 -- Similarly, if this is an inherited operation whose parent is
5667 -- not frozen yet, it is not in the DT of the parent, and we
5668 -- generate an explicit freeze node for the inherited operation
5669 -- so it is properly inserted in the DT of the current type.
5676 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5677 while Present
(Elmt
) loop
5678 Subp
:= Node
(Elmt
);
5680 if Present
(Alias
(Subp
)) then
5681 if Is_CPP_Class
(Etype
(Typ
)) then
5682 Set_Has_Delayed_Freeze
(Subp
);
5684 elsif Has_Delayed_Freeze
(Alias
(Subp
))
5685 and then not Is_Frozen
(Alias
(Subp
))
5687 Set_Is_Frozen
(Subp
, False);
5688 Set_Has_Delayed_Freeze
(Subp
);
5697 -- Unfreeze momentarily the type to add the predefined primitives
5698 -- operations. The reason we unfreeze is so that these predefined
5699 -- operations will indeed end up as primitive operations (which
5700 -- must be before the freeze point).
5702 Set_Is_Frozen
(Typ
, False);
5704 -- Do not add the spec of predefined primitives in case of
5705 -- CPP tagged type derivations that have convention CPP.
5707 if Is_CPP_Class
(Root_Type
(Typ
))
5708 and then Convention
(Typ
) = Convention_CPP
5712 -- Do not add the spec of the predefined primitives if we are
5713 -- compiling under restriction No_Dispatching_Calls.
5715 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5716 Make_Predefined_Primitive_Specs
(Typ
, Predef_List
, Renamed_Eq
);
5717 Insert_List_Before_And_Analyze
(N
, Predef_List
);
5720 -- Ada 2005 (AI-391): For a nonabstract null extension, create
5721 -- wrapper functions for each nonoverridden inherited function
5722 -- with a controlling result of the type. The wrapper for such
5723 -- a function returns an extension aggregate that invokes the
5726 if Ada_Version
>= Ada_2005
5727 and then not Is_Abstract_Type
(Typ
)
5728 and then Is_Null_Extension
(Typ
)
5730 Make_Controlling_Function_Wrappers
5731 (Typ
, Wrapper_Decl_List
, Wrapper_Body_List
);
5732 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
5735 -- Ada 2005 (AI-251): For a nonabstract type extension, build
5736 -- null procedure declarations for each set of homographic null
5737 -- procedures that are inherited from interface types but not
5738 -- overridden. This is done to ensure that the dispatch table
5739 -- entry associated with such null primitives are properly filled.
5741 if Ada_Version
>= Ada_2005
5742 and then Etype
(Typ
) /= Typ
5743 and then not Is_Abstract_Type
(Typ
)
5744 and then Has_Interfaces
(Typ
)
5746 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Typ
));
5749 Set_Is_Frozen
(Typ
);
5751 if not Is_Derived_Type
(Typ
)
5752 or else Is_Tagged_Type
(Etype
(Typ
))
5754 Set_All_DT_Position
(Typ
);
5756 -- If this is a type derived from an untagged private type whose
5757 -- full view is tagged, the type is marked tagged for layout
5758 -- reasons, but it has no dispatch table.
5760 elsif Is_Derived_Type
(Typ
)
5761 and then Is_Private_Type
(Etype
(Typ
))
5762 and then not Is_Tagged_Type
(Etype
(Typ
))
5767 -- Create and decorate the tags. Suppress their creation when
5768 -- not Tagged_Type_Expansion because the dispatching mechanism is
5769 -- handled internally by the virtual target.
5771 if Tagged_Type_Expansion
then
5772 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5774 -- Generate dispatch table of locally defined tagged type.
5775 -- Dispatch tables of library level tagged types are built
5776 -- later (see Build_Static_Dispatch_Tables).
5778 if not Building_Static_DT
(Typ
) then
5779 Append_Freeze_Actions
(Typ
, Make_DT
(Typ
));
5781 -- Register dispatch table wrappers in the dispatch table.
5782 -- It could not be done when these wrappers were built
5783 -- because, at that stage, the dispatch table was not
5786 Register_Dispatch_Table_Wrappers
(Typ
);
5790 -- If the type has unknown discriminants, propagate dispatching
5791 -- information to its underlying record view, which does not get
5792 -- its own dispatch table.
5794 if Is_Derived_Type
(Typ
)
5795 and then Has_Unknown_Discriminants
(Typ
)
5796 and then Present
(Underlying_Record_View
(Typ
))
5799 Rep
: constant Entity_Id
:= Underlying_Record_View
(Typ
);
5801 Set_Access_Disp_Table
5802 (Rep
, Access_Disp_Table
(Typ
));
5803 Set_Dispatch_Table_Wrappers
5804 (Rep
, Dispatch_Table_Wrappers
(Typ
));
5805 Set_Direct_Primitive_Operations
5806 (Rep
, Direct_Primitive_Operations
(Typ
));
5810 -- Make sure that the primitives Initialize, Adjust and Finalize
5811 -- are Frozen before other TSS subprograms. We don't want them
5814 if Is_Controlled
(Typ
) then
5815 if not Is_Limited_Type
(Typ
) then
5816 Append_Freeze_Actions
(Typ
,
5817 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Adjust
), Typ
));
5820 Append_Freeze_Actions
(Typ
,
5821 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Initialize
), Typ
));
5823 Append_Freeze_Actions
(Typ
,
5824 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Finalize
), Typ
));
5827 -- Freeze rest of primitive operations. There is no need to handle
5828 -- the predefined primitives if we are compiling under restriction
5829 -- No_Dispatching_Calls.
5831 if not Restriction_Active
(No_Dispatching_Calls
) then
5832 Append_Freeze_Actions
(Typ
, Predefined_Primitive_Freeze
(Typ
));
5836 -- In the untagged case, ever since Ada 83 an equality function must
5837 -- be provided for variant records that are not unchecked unions.
5839 elsif Has_Discriminants
(Typ
)
5840 and then not Is_Limited_Type
(Typ
)
5841 and then Present
(Component_List
(Type_Definition
(Typ_Decl
)))
5843 Present
(Variant_Part
(Component_List
(Type_Definition
(Typ_Decl
))))
5845 Build_Variant_Record_Equality
(Typ
);
5847 -- In Ada 2012 the equality function composes, and thus must be built
5848 -- explicitly just as for tagged records.
5850 -- This is done unconditionally to ensure that tools can be linked
5851 -- properly with user programs compiled with older language versions.
5852 -- In addition, this is needed because "=" composes for bounded strings
5853 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
5855 elsif Comes_From_Source
(Typ
)
5856 and then Convention
(Typ
) = Convention_Ada
5857 and then not Is_Limited_Type
(Typ
)
5859 Build_Untagged_Record_Equality
(Typ
);
5862 -- Before building the record initialization procedure, if we are
5863 -- dealing with a concurrent record value type, then we must go through
5864 -- the discriminants, exchanging discriminals between the concurrent
5865 -- type and the concurrent record value type. See the section "Handling
5866 -- of Discriminants" in the Einfo spec for details.
5868 if Is_Concurrent_Record_Type
(Typ
) and then Has_Discriminants
(Typ
) then
5870 Ctyp
: constant Entity_Id
:=
5871 Corresponding_Concurrent_Type
(Typ
);
5872 Conc_Discr
: Entity_Id
;
5873 Rec_Discr
: Entity_Id
;
5877 Conc_Discr
:= First_Discriminant
(Ctyp
);
5878 Rec_Discr
:= First_Discriminant
(Typ
);
5879 while Present
(Conc_Discr
) loop
5880 Temp
:= Discriminal
(Conc_Discr
);
5881 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
5882 Set_Discriminal
(Rec_Discr
, Temp
);
5884 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
5885 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
5887 Next_Discriminant
(Conc_Discr
);
5888 Next_Discriminant
(Rec_Discr
);
5893 if Has_Controlled_Component
(Typ
) then
5894 Build_Controlling_Procs
(Typ
);
5897 Adjust_Discriminants
(Typ
);
5899 -- Do not need init for interfaces on virtual targets since they're
5902 if Tagged_Type_Expansion
or else not Is_Interface
(Typ
) then
5903 Build_Record_Init_Proc
(Typ_Decl
, Typ
);
5906 -- For tagged type that are not interfaces, build bodies of primitive
5907 -- operations. Note: do this after building the record initialization
5908 -- procedure, since the primitive operations may need the initialization
5909 -- routine. There is no need to add predefined primitives of interfaces
5910 -- because all their predefined primitives are abstract.
5912 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
5914 -- Do not add the body of predefined primitives in case of CPP tagged
5915 -- type derivations that have convention CPP.
5917 if Is_CPP_Class
(Root_Type
(Typ
))
5918 and then Convention
(Typ
) = Convention_CPP
5922 -- Do not add the body of the predefined primitives if we are
5923 -- compiling under restriction No_Dispatching_Calls or if we are
5924 -- compiling a CPP tagged type.
5926 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5928 -- Create the body of TSS primitive Finalize_Address. This must
5929 -- be done before the bodies of all predefined primitives are
5930 -- created. If Typ is limited, Stream_Input and Stream_Read may
5931 -- produce build-in-place allocations and for those the expander
5932 -- needs Finalize_Address.
5934 Make_Finalize_Address_Body
(Typ
);
5935 Predef_List
:= Predefined_Primitive_Bodies
(Typ
, Renamed_Eq
);
5936 Append_Freeze_Actions
(Typ
, Predef_List
);
5939 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
5940 -- inherited functions, then add their bodies to the freeze actions.
5942 Append_Freeze_Actions
(Typ
, Wrapper_Body_List
);
5945 -- Create extra formals for the primitive operations of the type.
5946 -- This must be done before analyzing the body of the initialization
5947 -- procedure, because a self-referential type might call one of these
5948 -- primitives in the body of the init_proc itself.
5950 -- This is not needed:
5951 -- 1) If expansion is disabled, because extra formals are only added
5952 -- when we are generating code.
5954 -- 2) For types with foreign convention since primitives with foreign
5955 -- convention don't have extra formals and AI95-117 requires that
5956 -- all primitives of a tagged type inherit the convention.
5959 and then Is_Tagged_Type
(Typ
)
5960 and then not Has_Foreign_Convention
(Typ
)
5967 -- Add extra formals to primitive operations
5969 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5970 while Present
(Elmt
) loop
5971 Create_Extra_Formals
(Node
(Elmt
));
5975 -- Add extra formals to renamings of primitive operations. The
5976 -- addition of extra formals is done in two steps to minimize
5977 -- the compile time required for this action; the evaluation of
5978 -- Find_Dispatching_Type() and Contains() is only done here for
5979 -- renamings that are not primitive operations.
5981 E
:= First_Entity
(Scope
(Typ
));
5982 while Present
(E
) loop
5983 if Is_Dispatching_Operation
(E
)
5984 and then Present
(Alias
(E
))
5985 and then Find_Dispatching_Type
(E
) = Typ
5986 and then not Contains
(Primitive_Operations
(Typ
), E
)
5988 Create_Extra_Formals
(E
);
5994 pragma Debug
(Validate_Tagged_Type_Extra_Formals
(Typ
));
5998 -- Build internal subprograms of primitives with class-wide
5999 -- pre/postconditions.
6001 if Is_Tagged_Type
(Typ
) then
6002 Build_Class_Condition_Subprograms
(Typ
);
6004 end Expand_Freeze_Record_Type
;
6006 ------------------------------------
6007 -- Expand_N_Full_Type_Declaration --
6008 ------------------------------------
6010 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
) is
6011 procedure Build_Master
(Ptr_Typ
: Entity_Id
);
6012 -- Create the master associated with Ptr_Typ
6018 procedure Build_Master
(Ptr_Typ
: Entity_Id
) is
6019 Desig_Typ
: Entity_Id
:= Designated_Type
(Ptr_Typ
);
6022 -- If the designated type is an incomplete view coming from a
6023 -- limited-with'ed package, we need to use the nonlimited view in
6024 -- case it has tasks.
6026 if Is_Incomplete_Type
(Desig_Typ
)
6027 and then Present
(Non_Limited_View
(Desig_Typ
))
6029 Desig_Typ
:= Non_Limited_View
(Desig_Typ
);
6032 -- Anonymous access types are created for the components of the
6033 -- record parameter for an entry declaration. No master is created
6036 if Has_Task
(Desig_Typ
) then
6037 Build_Master_Entity
(Ptr_Typ
);
6038 Build_Master_Renaming
(Ptr_Typ
);
6040 -- Create a class-wide master because a Master_Id must be generated
6041 -- for access-to-limited-class-wide types whose root may be extended
6042 -- with task components.
6044 -- Note: This code covers access-to-limited-interfaces because they
6045 -- can be used to reference tasks implementing them.
6047 -- Suppress the master creation for access types created for entry
6048 -- formal parameters (parameter block component types). Seems like
6049 -- suppression should be more general for compiler-generated types,
6050 -- but testing Comes_From_Source may be too general in this case
6051 -- (affects some test output)???
6053 elsif not Is_Param_Block_Component_Type
(Ptr_Typ
)
6054 and then Is_Limited_Class_Wide_Type
(Desig_Typ
)
6056 Build_Class_Wide_Master
(Ptr_Typ
);
6060 -- Local declarations
6062 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6063 B_Id
: constant Entity_Id
:= Base_Type
(Def_Id
);
6067 -- Start of processing for Expand_N_Full_Type_Declaration
6070 if Is_Access_Type
(Def_Id
) then
6071 Build_Master
(Def_Id
);
6073 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
6074 Expand_Access_Protected_Subprogram_Type
(N
);
6077 -- Array of anonymous access-to-task pointers
6079 elsif Ada_Version
>= Ada_2005
6080 and then Is_Array_Type
(Def_Id
)
6081 and then Is_Access_Type
(Component_Type
(Def_Id
))
6082 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
6084 Build_Master
(Component_Type
(Def_Id
));
6086 elsif Has_Task
(Def_Id
) then
6087 Expand_Previous_Access_Type
(Def_Id
);
6089 -- Check the components of a record type or array of records for
6090 -- anonymous access-to-task pointers.
6092 elsif Ada_Version
>= Ada_2005
6093 and then (Is_Record_Type
(Def_Id
)
6095 (Is_Array_Type
(Def_Id
)
6096 and then Is_Record_Type
(Component_Type
(Def_Id
))))
6101 M_Id
: Entity_Id
:= Empty
;
6105 if Is_Array_Type
(Def_Id
) then
6106 Comp
:= First_Entity
(Component_Type
(Def_Id
));
6108 Comp
:= First_Entity
(Def_Id
);
6111 -- Examine all components looking for anonymous access-to-task
6115 while Present
(Comp
) loop
6116 Typ
:= Etype
(Comp
);
6118 if Ekind
(Typ
) = E_Anonymous_Access_Type
6119 and then Might_Have_Tasks
6120 (Available_View
(Designated_Type
(Typ
)))
6121 and then No
(Master_Id
(Typ
))
6123 -- Ensure that the record or array type have a _master
6126 Build_Master_Entity
(Def_Id
);
6127 Build_Master_Renaming
(Typ
);
6128 M_Id
:= Master_Id
(Typ
);
6132 -- Reuse the same master to service any additional types
6135 pragma Assert
(Present
(M_Id
));
6136 Set_Master_Id
(Typ
, M_Id
);
6145 Par_Id
:= Etype
(B_Id
);
6147 -- The parent type is private then we need to inherit any TSS operations
6148 -- from the full view.
6150 if Is_Private_Type
(Par_Id
)
6151 and then Present
(Full_View
(Par_Id
))
6153 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
6156 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
6157 and then not Is_Tagged_Type
(Def_Id
)
6158 and then Present
(Freeze_Node
(Par_Id
))
6159 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
6161 Ensure_Freeze_Node
(B_Id
);
6162 FN
:= Freeze_Node
(B_Id
);
6164 if No
(TSS_Elist
(FN
)) then
6165 Set_TSS_Elist
(FN
, New_Elmt_List
);
6169 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
6173 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
6174 while Present
(Elmt
) loop
6175 if Chars
(Node
(Elmt
)) /= Name_uInit
then
6176 Append_Elmt
(Node
(Elmt
), T_E
);
6182 -- If the derived type itself is private with a full view, then
6183 -- associate the full view with the inherited TSS_Elist as well.
6185 if Is_Private_Type
(B_Id
)
6186 and then Present
(Full_View
(B_Id
))
6188 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
6190 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
6194 end Expand_N_Full_Type_Declaration
;
6196 ---------------------------------
6197 -- Expand_N_Object_Declaration --
6198 ---------------------------------
6200 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
6201 Loc
: constant Source_Ptr
:= Sloc
(N
);
6202 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6203 Expr
: constant Node_Id
:= Expression
(N
);
6204 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
6205 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
6206 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6207 Next_N
: constant Node_Id
:= Next
(N
);
6209 Special_Ret_Obj
: constant Boolean := Is_Special_Return_Object
(Def_Id
);
6210 -- If this is a special return object, it will be allocated differently
6211 -- and ultimately rewritten as a renaming, so initialization activities
6212 -- need to be deferred until after that is done.
6214 Func_Id
: constant Entity_Id
:=
6215 (if Special_Ret_Obj
then Return_Applies_To
(Scope
(Def_Id
)) else Empty
);
6216 -- The function if this is a special return object, otherwise Empty
6218 function Build_Equivalent_Aggregate
return Boolean;
6219 -- If the object has a constrained discriminated type and no initial
6220 -- value, it may be possible to build an equivalent aggregate instead,
6221 -- and prevent an actual call to the initialization procedure.
6223 function Build_Heap_Or_Pool_Allocator
6224 (Temp_Id
: Entity_Id
;
6225 Temp_Typ
: Entity_Id
;
6226 Ret_Typ
: Entity_Id
;
6227 Alloc_Expr
: Node_Id
) return Node_Id
;
6228 -- Create the statements necessary to allocate a return object on the
6229 -- heap or user-defined storage pool. The object may need finalization
6230 -- actions depending on the return type.
6232 -- * Controlled case
6234 -- if BIPfinalizationmaster = null then
6235 -- Temp_Id := <Alloc_Expr>;
6238 -- type Ptr_Typ is access Ret_Typ;
6239 -- for Ptr_Typ'Storage_Pool use
6240 -- Base_Pool (BIPfinalizationmaster.all).all;
6244 -- procedure Allocate (...) is
6246 -- System.Storage_Pools.Subpools.Allocate_Any (...);
6249 -- Local := <Alloc_Expr>;
6250 -- Temp_Id := Temp_Typ (Local);
6254 -- * Non-controlled case
6256 -- Temp_Id := <Alloc_Expr>;
6258 -- Temp_Id is the temporary which is used to reference the internally
6259 -- created object in all allocation forms. Temp_Typ is the type of the
6260 -- temporary. Func_Id is the enclosing function. Ret_Typ is the return
6261 -- type of Func_Id. Alloc_Expr is the actual allocator.
6263 function BIP_Function_Call_Id
return Entity_Id
;
6264 -- If the object initialization expression is a call to a build-in-place
6265 -- function, return the id of the called function; otherwise return
6268 procedure Count_Default_Sized_Task_Stacks
6270 Pri_Stacks
: out Int
;
6271 Sec_Stacks
: out Int
);
6272 -- Count the number of default-sized primary and secondary task stacks
6273 -- required for task objects contained within type Typ. If the number of
6274 -- task objects contained within the type is not known at compile time
6275 -- the procedure will return the stack counts of zero.
6277 procedure Default_Initialize_Object
(After
: Node_Id
);
6278 -- Generate all default initialization actions for object Def_Id. Any
6279 -- new code is inserted after node After.
6281 procedure Initialize_Return_Object
6282 (Tag_Assign
: Node_Id
;
6285 Init_Stmt
: Node_Id
;
6287 -- Generate all initialization actions for return object Def_Id. Any
6288 -- new code is inserted after node After.
6290 function Is_Renamable_Function_Call
(Expr
: Node_Id
) return Boolean;
6291 -- If we are not at library level and the object declaration originally
6292 -- appears in the form:
6294 -- Obj : Typ := Func (...);
6296 -- and has been rewritten as the dereference of a captured reference
6297 -- to the function result built either on the primary or the secondary
6298 -- stack, then the declaration can be rewritten as the renaming of this
6301 -- type Ann is access all Typ;
6302 -- Rnn : constant Axx := Func (...)'reference;
6303 -- Obj : Typ renames Rnn.all;
6305 -- This will avoid making an extra copy and, in the case where Typ needs
6306 -- finalization, a pair of calls to the Adjust and Finalize primitives,
6307 -- or Deep_Adjust and Deep_Finalize routines, depending on whether Typ
6308 -- has components that themselves need finalization.
6310 -- However, in the case of a special return object, we need to make sure
6311 -- that the object Rnn is recognized by the Is_Related_To_Func_Return
6312 -- predicate; otherwise, if it is of a type that needs finalization,
6313 -- then Requires_Cleanup_Actions would return true because of this and
6314 -- Build_Finalizer would finalize it prematurely because of this (see
6315 -- also Expand_Simple_Function_Return for the same test in the case of
6316 -- a simple return).
6318 -- Finally, in the case of a special return object, we also need to make
6319 -- sure that the two functions return on the same stack, otherwise we
6320 -- would create a dangling reference.
6322 function Make_Allocator_For_Return
(Expr
: Node_Id
) return Node_Id
;
6323 -- Make an allocator for a return object initialized with Expr
6325 function OK_To_Rename_Ref
(N
: Node_Id
) return Boolean;
6326 -- Return True if N denotes an entity with OK_To_Rename set
6328 --------------------------------
6329 -- Build_Equivalent_Aggregate --
6330 --------------------------------
6332 function Build_Equivalent_Aggregate
return Boolean is
6336 Full_Type
: Entity_Id
;
6341 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
6342 Full_Type
:= Full_View
(Typ
);
6345 -- Only perform this transformation if Elaboration_Code is forbidden
6346 -- or undesirable, and if this is a global entity of a constrained
6349 -- If Initialize_Scalars might be active this transformation cannot
6350 -- be performed either, because it will lead to different semantics
6351 -- or because elaboration code will in fact be created.
6353 if Ekind
(Full_Type
) /= E_Record_Subtype
6354 or else not Has_Discriminants
(Full_Type
)
6355 or else not Is_Constrained
(Full_Type
)
6356 or else Is_Controlled
(Full_Type
)
6357 or else Is_Limited_Type
(Full_Type
)
6358 or else not Restriction_Active
(No_Initialize_Scalars
)
6363 if Ekind
(Current_Scope
) = E_Package
6365 (Restriction_Active
(No_Elaboration_Code
)
6366 or else Is_Preelaborated
(Current_Scope
))
6368 -- Building a static aggregate is possible if the discriminants
6369 -- have static values and the other components have static
6370 -- defaults or none.
6372 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
6373 while Present
(Discr
) loop
6374 if not Is_OK_Static_Expression
(Node
(Discr
)) then
6381 -- Check that initialized components are OK, and that non-
6382 -- initialized components do not require a call to their own
6383 -- initialization procedure.
6385 Comp
:= First_Component
(Full_Type
);
6386 while Present
(Comp
) loop
6387 if Present
(Expression
(Parent
(Comp
)))
6389 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
6393 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
6398 Next_Component
(Comp
);
6401 -- Everything is static, assemble the aggregate, discriminant
6405 Make_Aggregate
(Loc
,
6406 Expressions
=> New_List
,
6407 Component_Associations
=> New_List
);
6409 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
6410 while Present
(Discr
) loop
6411 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
6415 -- Now collect values of initialized components
6417 Comp
:= First_Component
(Full_Type
);
6418 while Present
(Comp
) loop
6419 if Present
(Expression
(Parent
(Comp
))) then
6420 Append_To
(Component_Associations
(Aggr
),
6421 Make_Component_Association
(Loc
,
6422 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
6423 Expression
=> New_Copy_Tree
6424 (Expression
(Parent
(Comp
)))));
6427 Next_Component
(Comp
);
6430 -- Finally, box-initialize remaining components
6432 Append_To
(Component_Associations
(Aggr
),
6433 Make_Component_Association
(Loc
,
6434 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6435 Expression
=> Empty
));
6436 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
6437 Set_Expression
(N
, Aggr
);
6439 if Typ
/= Full_Type
then
6440 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
6441 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
6442 Analyze_And_Resolve
(Aggr
, Typ
);
6444 Analyze_And_Resolve
(Aggr
, Full_Type
);
6452 end Build_Equivalent_Aggregate
;
6454 ----------------------------------
6455 -- Build_Heap_Or_Pool_Allocator --
6456 ----------------------------------
6458 function Build_Heap_Or_Pool_Allocator
6459 (Temp_Id
: Entity_Id
;
6460 Temp_Typ
: Entity_Id
;
6461 Ret_Typ
: Entity_Id
;
6462 Alloc_Expr
: Node_Id
) return Node_Id
6465 pragma Assert
(Is_Build_In_Place_Function
(Func_Id
));
6467 -- Processing for objects that require finalization actions
6469 if Needs_Finalization
(Ret_Typ
) then
6471 Decls
: constant List_Id
:= New_List
;
6472 Fin_Mas_Id
: constant Entity_Id
:=
6473 Build_In_Place_Formal
(Func_Id
, BIP_Finalization_Master
);
6474 Orig_Expr
: constant Node_Id
:= New_Copy_Tree
(Alloc_Expr
);
6475 Stmts
: constant List_Id
:= New_List
;
6476 Local_Id
: Entity_Id
;
6477 Pool_Id
: Entity_Id
;
6478 Ptr_Typ
: Entity_Id
;
6482 -- Pool_Id renames Base_Pool (BIPfinalizationmaster.all).all;
6484 Pool_Id
:= Make_Temporary
(Loc
, 'P');
6487 Make_Object_Renaming_Declaration
(Loc
,
6488 Defining_Identifier
=> Pool_Id
,
6490 New_Occurrence_Of
(RTE
(RE_Root_Storage_Pool
), Loc
),
6492 Make_Explicit_Dereference
(Loc
,
6494 Make_Function_Call
(Loc
,
6496 New_Occurrence_Of
(RTE
(RE_Base_Pool
), Loc
),
6497 Parameter_Associations
=> New_List
(
6498 Make_Explicit_Dereference
(Loc
,
6500 New_Occurrence_Of
(Fin_Mas_Id
, Loc
)))))));
6502 -- Create an access type which uses the storage pool of the
6503 -- caller's master. This additional type is necessary because
6504 -- the finalization master cannot be associated with the type
6505 -- of the temporary. Otherwise the secondary stack allocation
6509 -- type Ptr_Typ is access Ret_Typ;
6511 Ptr_Typ
:= Make_Temporary
(Loc
, 'P');
6514 Make_Full_Type_Declaration
(Loc
,
6515 Defining_Identifier
=> Ptr_Typ
,
6517 Make_Access_To_Object_Definition
(Loc
,
6518 Subtype_Indication
=>
6519 New_Occurrence_Of
(Ret_Typ
, Loc
))));
6521 -- Perform minor decoration in order to set the master and the
6522 -- storage pool attributes.
6524 Mutate_Ekind
(Ptr_Typ
, E_Access_Type
);
6525 Set_Finalization_Master
(Ptr_Typ
, Fin_Mas_Id
);
6526 Set_Associated_Storage_Pool
(Ptr_Typ
, Pool_Id
);
6528 -- Create the temporary, generate:
6529 -- Local_Id : Ptr_Typ;
6531 Local_Id
:= Make_Temporary
(Loc
, 'T');
6534 Make_Object_Declaration
(Loc
,
6535 Defining_Identifier
=> Local_Id
,
6536 Object_Definition
=>
6537 New_Occurrence_Of
(Ptr_Typ
, Loc
)));
6539 -- Allocate the object, generate:
6540 -- Local_Id := <Alloc_Expr>;
6543 Make_Assignment_Statement
(Loc
,
6544 Name
=> New_Occurrence_Of
(Local_Id
, Loc
),
6545 Expression
=> Alloc_Expr
));
6548 -- Temp_Id := Temp_Typ (Local_Id);
6551 Make_Assignment_Statement
(Loc
,
6552 Name
=> New_Occurrence_Of
(Temp_Id
, Loc
),
6554 Unchecked_Convert_To
(Temp_Typ
,
6555 New_Occurrence_Of
(Local_Id
, Loc
))));
6557 -- Wrap the allocation in a block. This is further conditioned
6558 -- by checking the caller finalization master at runtime. A
6559 -- null value indicates a non-existent master, most likely due
6560 -- to a Finalize_Storage_Only allocation.
6563 -- if BIPfinalizationmaster = null then
6564 -- Temp_Id := <Orig_Expr>;
6574 Make_If_Statement
(Loc
,
6577 Left_Opnd
=> New_Occurrence_Of
(Fin_Mas_Id
, Loc
),
6578 Right_Opnd
=> Make_Null
(Loc
)),
6580 Then_Statements
=> New_List
(
6581 Make_Assignment_Statement
(Loc
,
6582 Name
=> New_Occurrence_Of
(Temp_Id
, Loc
),
6583 Expression
=> Orig_Expr
)),
6585 Else_Statements
=> New_List
(
6586 Make_Block_Statement
(Loc
,
6587 Declarations
=> Decls
,
6588 Handled_Statement_Sequence
=>
6589 Make_Handled_Sequence_Of_Statements
(Loc
,
6590 Statements
=> Stmts
))));
6593 -- For all other cases, generate:
6594 -- Temp_Id := <Alloc_Expr>;
6598 Make_Assignment_Statement
(Loc
,
6599 Name
=> New_Occurrence_Of
(Temp_Id
, Loc
),
6600 Expression
=> Alloc_Expr
);
6602 end Build_Heap_Or_Pool_Allocator
;
6604 --------------------------
6605 -- BIP_Function_Call_Id --
6606 --------------------------
6608 function BIP_Function_Call_Id
return Entity_Id
is
6610 function Func_Call_Id
(Function_Call
: Node_Id
) return Entity_Id
;
6611 -- Return the id of the called function.
6613 function Func_Call_Id
(Function_Call
: Node_Id
) return Entity_Id
is
6614 Call_Node
: constant Node_Id
:= Unqual_Conv
(Function_Call
);
6617 if Is_Entity_Name
(Name
(Call_Node
)) then
6618 return Entity
(Name
(Call_Node
));
6620 elsif Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
6621 return Etype
(Name
(Call_Node
));
6624 pragma Assert
(Nkind
(Name
(Call_Node
)) = N_Selected_Component
);
6625 return Etype
(Entity
(Selector_Name
(Name
(Call_Node
))));
6629 -- Local declarations
6631 BIP_Func_Call
: Node_Id
;
6632 Expr_Q
: constant Node_Id
:= Unqual_Conv
(Expr
);
6634 -- Start of processing for BIP_Function_Call_Id
6637 if Is_Build_In_Place_Function_Call
(Expr_Q
) then
6638 return Func_Call_Id
(Expr_Q
);
6641 BIP_Func_Call
:= Unqual_BIP_Iface_Function_Call
(Expr_Q
);
6643 if Present
(BIP_Func_Call
) then
6645 -- In the case of an explicitly dereferenced call, return the
6648 if Nkind
(Name
(BIP_Func_Call
)) = N_Explicit_Dereference
then
6649 return Etype
(Name
(BIP_Func_Call
));
6651 pragma Assert
(Is_Entity_Name
(Name
(BIP_Func_Call
)));
6652 return Entity
(Name
(BIP_Func_Call
));
6655 elsif Nkind
(Expr_Q
) = N_Reference
6656 and then Is_Build_In_Place_Function_Call
(Prefix
(Expr_Q
))
6658 return Func_Call_Id
(Prefix
(Expr_Q
));
6663 end BIP_Function_Call_Id
;
6665 -------------------------------------
6666 -- Count_Default_Sized_Task_Stacks --
6667 -------------------------------------
6669 procedure Count_Default_Sized_Task_Stacks
6671 Pri_Stacks
: out Int
;
6672 Sec_Stacks
: out Int
)
6674 Component
: Entity_Id
;
6677 -- To calculate the number of default-sized task stacks required for
6678 -- an object of Typ, a depth-first recursive traversal of the AST
6679 -- from the Typ entity node is undertaken. Only type nodes containing
6680 -- task objects are visited.
6685 if not Has_Task
(Typ
) then
6693 -- A task type is found marking the bottom of the descent. If
6694 -- the type has no representation aspect for the corresponding
6695 -- stack then that stack is using the default size.
6697 if Present
(Get_Rep_Item
(Typ
, Name_Storage_Size
)) then
6703 if Present
(Get_Rep_Item
(Typ
, Name_Secondary_Stack_Size
)) then
6709 when E_Array_Subtype
6712 -- First find the number of default stacks contained within an
6715 Count_Default_Sized_Task_Stacks
6716 (Component_Type
(Typ
),
6720 -- Then multiply the result by the size of the array
6723 Quantity
: constant Int
:= Number_Of_Elements_In_Array
(Typ
);
6724 -- Number_Of_Elements_In_Array is non-trival, consequently
6725 -- its result is captured as an optimization.
6728 Pri_Stacks
:= Pri_Stacks
* Quantity
;
6729 Sec_Stacks
:= Sec_Stacks
* Quantity
;
6732 when E_Protected_Subtype
6737 Component
:= First_Component_Or_Discriminant
(Typ
);
6739 -- Recursively descend each component of the composite type
6740 -- looking for tasks, but only if the component is marked as
6743 while Present
(Component
) loop
6744 if Has_Task
(Etype
(Component
)) then
6750 Count_Default_Sized_Task_Stacks
6751 (Etype
(Component
), P
, S
);
6752 Pri_Stacks
:= Pri_Stacks
+ P
;
6753 Sec_Stacks
:= Sec_Stacks
+ S
;
6757 Next_Component_Or_Discriminant
(Component
);
6760 when E_Limited_Private_Subtype
6761 | E_Limited_Private_Type
6762 | E_Record_Subtype_With_Private
6763 | E_Record_Type_With_Private
6765 -- Switch to the full view of the private type to continue
6768 Count_Default_Sized_Task_Stacks
6769 (Full_View
(Typ
), Pri_Stacks
, Sec_Stacks
);
6771 -- Other types should not contain tasks
6774 raise Program_Error
;
6776 end Count_Default_Sized_Task_Stacks
;
6778 -------------------------------
6779 -- Default_Initialize_Object --
6780 -------------------------------
6782 procedure Default_Initialize_Object
(After
: Node_Id
) is
6783 function New_Object_Reference
return Node_Id
;
6784 -- Return a new reference to Def_Id with attributes Assignment_OK and
6785 -- Must_Not_Freeze already set.
6787 function Simple_Initialization_OK
6788 (Init_Typ
: Entity_Id
) return Boolean;
6789 -- Determine whether object declaration N with entity Def_Id needs
6790 -- simple initialization, assuming that it is of type Init_Typ.
6792 --------------------------
6793 -- New_Object_Reference --
6794 --------------------------
6796 function New_Object_Reference
return Node_Id
is
6797 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
6800 -- The call to the type init proc or [Deep_]Finalize must not
6801 -- freeze the related object as the call is internally generated.
6802 -- This way legal rep clauses that apply to the object will not be
6803 -- flagged. Note that the initialization call may be removed if
6804 -- pragma Import is encountered or moved to the freeze actions of
6805 -- the object because of an address clause.
6807 Set_Assignment_OK
(Obj_Ref
);
6808 Set_Must_Not_Freeze
(Obj_Ref
);
6811 end New_Object_Reference
;
6813 ------------------------------
6814 -- Simple_Initialization_OK --
6815 ------------------------------
6817 function Simple_Initialization_OK
6818 (Init_Typ
: Entity_Id
) return Boolean
6821 -- Do not consider the object declaration if it comes with an
6822 -- initialization expression, or is internal in which case it
6823 -- will be assigned later.
6826 not Is_Internal
(Def_Id
)
6827 and then not Has_Init_Expression
(N
)
6828 and then Needs_Simple_Initialization
6832 and then No
(Following_Address_Clause
(N
)));
6833 end Simple_Initialization_OK
;
6837 Exceptions_OK
: constant Boolean :=
6838 not Restriction_Active
(No_Exception_Propagation
);
6840 Aggr_Init
: Node_Id
;
6841 Comp_Init
: List_Id
:= No_List
;
6842 Fin_Block
: Node_Id
;
6844 Init_Stmts
: List_Id
:= No_List
;
6845 Obj_Init
: Node_Id
:= Empty
;
6848 -- Start of processing for Default_Initialize_Object
6851 -- Default initialization is suppressed for objects that are already
6852 -- known to be imported (i.e. whose declaration specifies the Import
6853 -- aspect). Note that for objects with a pragma Import, we generate
6854 -- initialization here, and then remove it downstream when processing
6855 -- the pragma. It is also suppressed for variables for which a pragma
6856 -- Suppress_Initialization has been explicitly given
6858 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
6861 -- Nothing to do if the object being initialized is of a task type
6862 -- and restriction No_Tasking is in effect, because this is a direct
6863 -- violation of the restriction.
6865 elsif Is_Task_Type
(Base_Typ
)
6866 and then Restriction_Active
(No_Tasking
)
6871 -- The expansion performed by this routine is as follows:
6875 -- Type_Init_Proc (Obj);
6878 -- [Deep_]Initialize (Obj);
6882 -- [Deep_]Finalize (Obj, Self => False);
6886 -- Abort_Undefer_Direct;
6889 -- Initialize the components of the object
6891 if Has_Non_Null_Base_Init_Proc
(Typ
)
6892 and then not No_Initialization
(N
)
6893 and then not Initialization_Suppressed
(Typ
)
6895 -- Do not initialize the components if No_Default_Initialization
6896 -- applies as the actual restriction check will occur later when
6897 -- the object is frozen as it is not known yet whether the object
6898 -- is imported or not.
6900 if not Restriction_Active
(No_Default_Initialization
) then
6902 -- If the values of the components are compile-time known, use
6903 -- their prebuilt aggregate form directly.
6905 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
6907 if Present
(Aggr_Init
) then
6909 New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
6911 -- If type has discriminants, try to build an equivalent
6912 -- aggregate using discriminant values from the declaration.
6913 -- This is a useful optimization, in particular if restriction
6914 -- No_Elaboration_Code is active.
6916 elsif Build_Equivalent_Aggregate
then
6919 -- Optimize the default initialization of an array object when
6920 -- pragma Initialize_Scalars or Normalize_Scalars is in effect.
6921 -- Construct an in-place initialization aggregate which may be
6922 -- convert into a fast memset by the backend.
6924 elsif Init_Or_Norm_Scalars
6925 and then Is_Array_Type
(Typ
)
6927 -- The array must lack atomic components because they are
6928 -- treated as non-static, and as a result the backend will
6929 -- not initialize the memory in one go.
6931 and then not Has_Atomic_Components
(Typ
)
6933 -- The array must not be packed because the invalid values
6934 -- in System.Scalar_Values are multiples of Storage_Unit.
6936 and then not Is_Packed
(Typ
)
6938 -- The array must have static non-empty ranges, otherwise
6939 -- the backend cannot initialize the memory in one go.
6941 and then Has_Static_Non_Empty_Array_Bounds
(Typ
)
6943 -- The optimization is only relevant for arrays of scalar
6946 and then Is_Scalar_Type
(Component_Type
(Typ
))
6948 -- Similar to regular array initialization using a type
6949 -- init proc, predicate checks are not performed because the
6950 -- initialization values are intentionally invalid, and may
6951 -- violate the predicate.
6953 and then not Has_Predicates
(Component_Type
(Typ
))
6955 -- Array default component value takes precedence over
6956 -- Init_Or_Norm_Scalars.
6958 and then No
(Find_Aspect
(Typ
,
6959 Aspect_Default_Component_Value
))
6961 -- The component type must have a single initialization value
6963 and then Simple_Initialization_OK
(Component_Type
(Typ
))
6965 Set_No_Initialization
(N
, False);
6970 Size
=> (if Known_Esize
(Def_Id
) then Esize
(Def_Id
)
6974 (Expression
(N
), Typ
, Suppress
=> All_Checks
);
6976 -- Otherwise invoke the type init proc, generate:
6977 -- Type_Init_Proc (Obj);
6980 Obj_Ref
:= New_Object_Reference
;
6982 if Comes_From_Source
(Def_Id
) then
6983 Initialization_Warning
(Obj_Ref
);
6986 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
6990 -- Provide a default value if the object needs simple initialization
6992 elsif Simple_Initialization_OK
(Typ
) then
6993 Set_No_Initialization
(N
, False);
6999 (if Known_Esize
(Def_Id
) then Esize
(Def_Id
) else Uint_0
)));
7001 Analyze_And_Resolve
(Expression
(N
), Typ
);
7004 -- Initialize the object, generate:
7005 -- [Deep_]Initialize (Obj);
7007 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
7010 (Obj_Ref
=> New_Object_Reference
,
7014 -- Build a special finalization block when both the object and its
7015 -- controlled components are to be initialized. The block finalizes
7016 -- the components if the object initialization fails. Generate:
7027 if Has_Controlled_Component
(Typ
)
7028 and then Present
(Comp_Init
)
7029 and then Present
(Obj_Init
)
7030 and then Exceptions_OK
7032 Init_Stmts
:= Comp_Init
;
7036 (Obj_Ref
=> New_Object_Reference
,
7040 if Present
(Fin_Call
) then
7042 -- Do not emit warnings related to the elaboration order when a
7043 -- controlled object is declared before the body of Finalize is
7046 if Legacy_Elaboration_Checks
then
7047 Set_No_Elaboration_Check
(Fin_Call
);
7051 Make_Block_Statement
(Loc
,
7052 Declarations
=> No_List
,
7054 Handled_Statement_Sequence
=>
7055 Make_Handled_Sequence_Of_Statements
(Loc
,
7056 Statements
=> New_List
(Obj_Init
),
7058 Exception_Handlers
=> New_List
(
7059 Make_Exception_Handler
(Loc
,
7060 Exception_Choices
=> New_List
(
7061 Make_Others_Choice
(Loc
)),
7063 Statements
=> New_List
(
7065 Make_Raise_Statement
(Loc
))))));
7067 -- Signal the ABE mechanism that the block carries out
7068 -- initialization actions.
7070 Set_Is_Initialization_Block
(Fin_Block
);
7072 Append_To
(Init_Stmts
, Fin_Block
);
7075 -- Otherwise finalization is not required, the initialization calls
7076 -- are passed to the abort block building circuitry, generate:
7078 -- Type_Init_Proc (Obj);
7079 -- [Deep_]Initialize (Obj);
7082 if Present
(Comp_Init
) then
7083 Init_Stmts
:= Comp_Init
;
7086 if Present
(Obj_Init
) then
7087 if No
(Init_Stmts
) then
7088 Init_Stmts
:= New_List
;
7091 Append_To
(Init_Stmts
, Obj_Init
);
7095 -- Build an abort block to protect the initialization calls
7098 and then Present
(Comp_Init
)
7099 and then Present
(Obj_Init
)
7104 Prepend_To
(Init_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7106 -- When exceptions are propagated, abort deferral must take place
7107 -- in the presence of initialization or finalization exceptions.
7114 -- Abort_Undefer_Direct;
7117 if Exceptions_OK
then
7118 Init_Stmts
:= New_List
(
7119 Build_Abort_Undefer_Block
(Loc
,
7120 Stmts
=> Init_Stmts
,
7123 -- Otherwise exceptions are not propagated. Generate:
7130 Append_To
(Init_Stmts
,
7131 Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7135 -- Insert the whole initialization sequence into the tree. If the
7136 -- object has a delayed freeze, as will be the case when it has
7137 -- aspect specifications, the initialization sequence is part of
7138 -- the freeze actions.
7140 if Present
(Init_Stmts
) then
7141 if Has_Delayed_Freeze
(Def_Id
) then
7142 Append_Freeze_Actions
(Def_Id
, Init_Stmts
);
7144 Insert_Actions_After
(After
, Init_Stmts
);
7147 end Default_Initialize_Object
;
7149 ------------------------------
7150 -- Initialize_Return_Object --
7151 ------------------------------
7153 procedure Initialize_Return_Object
7154 (Tag_Assign
: Node_Id
;
7157 Init_Stmt
: Node_Id
;
7161 if Present
(Tag_Assign
) then
7162 Insert_Action_After
(After
, Tag_Assign
);
7165 if Present
(Adj_Call
) then
7166 Insert_Action_After
(After
, Adj_Call
);
7170 Default_Initialize_Object
(After
);
7172 elsif Is_Delayed_Aggregate
(Expr
)
7173 and then not No_Initialization
(N
)
7175 Convert_Aggr_In_Object_Decl
(N
);
7177 elsif Present
(Init_Stmt
) then
7178 Insert_Action_After
(After
, Init_Stmt
);
7179 Set_Expression
(N
, Empty
);
7181 end Initialize_Return_Object
;
7183 --------------------------------
7184 -- Is_Renamable_Function_Call --
7185 --------------------------------
7187 function Is_Renamable_Function_Call
(Expr
: Node_Id
) return Boolean is
7189 return not Is_Library_Level_Entity
(Def_Id
)
7190 and then Is_Captured_Function_Call
(Expr
)
7191 and then (not Special_Ret_Obj
7193 (Is_Related_To_Func_Return
(Entity
(Prefix
(Expr
)))
7194 and then Needs_Secondary_Stack
(Etype
(Expr
)) =
7195 Needs_Secondary_Stack
(Etype
(Func_Id
))));
7196 end Is_Renamable_Function_Call
;
7198 -------------------------------
7199 -- Make_Allocator_For_Return --
7200 -------------------------------
7202 function Make_Allocator_For_Return
(Expr
: Node_Id
) return Node_Id
is
7204 Alloc_Expr
: Entity_Id
;
7205 Alloc_Typ
: Entity_Id
;
7208 -- If the return object's declaration does not include an expression,
7209 -- then we use its subtype for the allocation. Likewise in the case
7210 -- of a degenerate expression like a raise expression.
7213 or else Nkind
(Original_Node
(Expr
)) = N_Raise_Expression
7217 -- If the return object's declaration includes an expression, then
7218 -- there are two cases: either the nominal subtype of the object is
7219 -- definite and we can use it for the allocation directly, or it is
7220 -- not and Analyze_Object_Declaration should have built an actual
7221 -- subtype from the expression.
7223 -- However, there are exceptions in the latter case for interfaces
7224 -- (see Analyze_Object_Declaration), as well as class-wide types and
7225 -- types with unknown discriminants if they are additionally limited
7226 -- (see Expand_Subtype_From_Expr), so we must cope with them.
7228 elsif Is_Interface
(Typ
) then
7229 pragma Assert
(Is_Class_Wide_Type
(Typ
));
7231 -- For interfaces, we use the type of the expression, except if
7232 -- we need to put back a conversion that we have removed earlier
7233 -- in the processing.
7235 if Is_Class_Wide_Type
(Etype
(Expr
)) then
7238 Alloc_Typ
:= Etype
(Expr
);
7241 elsif Is_Class_Wide_Type
(Typ
) then
7243 -- For class-wide types, we have to make sure that we use the
7244 -- dynamic type of the expression for the allocation, either by
7245 -- means of its (static) subtype or through the actual subtype.
7247 if Has_Tag_Of_Type
(Expr
) then
7248 Alloc_Typ
:= Etype
(Expr
);
7250 else pragma Assert
(Ekind
(Typ
) = E_Class_Wide_Subtype
7251 and then Present
(Equivalent_Type
(Typ
)));
7256 else pragma Assert
(Is_Definite_Subtype
(Typ
)
7257 or else (Has_Unknown_Discriminants
(Typ
)
7258 and then Is_Inherently_Limited_Type
(Typ
)));
7263 -- If the return object's declaration includes an expression and the
7264 -- declaration isn't marked as No_Initialization, then we generate an
7265 -- allocator with a qualified expression. Although this is necessary
7266 -- only in the case where the result type is an interface (or class-
7267 -- wide interface), we do it in all cases for the sake of consistency
7268 -- instead of subsequently generating a separate assignment.
7271 and then not Is_Delayed_Aggregate
(Expr
)
7272 and then not No_Initialization
(N
)
7274 -- Ada 2005 (AI95-344): If the result type is class-wide, insert
7275 -- a check that the level of the return expression's underlying
7276 -- type is not deeper than the level of the master enclosing the
7279 -- AI12-043: The check is made immediately after the return object
7282 if Is_Class_Wide_Type
(Etype
(Func_Id
)) then
7283 Apply_CW_Accessibility_Check
(Expr
, Func_Id
);
7286 Alloc_Expr
:= New_Copy_Tree
(Expr
);
7288 if Etype
(Alloc_Expr
) /= Alloc_Typ
then
7289 Alloc_Expr
:= Convert_To
(Alloc_Typ
, Alloc_Expr
);
7293 Make_Allocator
(Loc
,
7295 Make_Qualified_Expression
(Loc
,
7297 New_Occurrence_Of
(Alloc_Typ
, Loc
),
7298 Expression
=> Alloc_Expr
));
7302 Make_Allocator
(Loc
,
7303 Expression
=> New_Occurrence_Of
(Alloc_Typ
, Loc
));
7305 -- If the return object requires default initialization, then it
7306 -- will happen later following the elaboration of the renaming.
7307 -- If we don't turn it off here, then the object will be default
7308 -- initialized twice.
7310 Set_No_Initialization
(Alloc
);
7313 -- Set the flag indicating that the allocator is made for a special
7314 -- return object. This is used to bypass various legality checks as
7315 -- well as to make sure that the result is not adjusted twice.
7317 Set_For_Special_Return_Object
(Alloc
);
7320 end Make_Allocator_For_Return
;
7322 ----------------------
7323 -- OK_To_Rename_Ref --
7324 ----------------------
7326 function OK_To_Rename_Ref
(N
: Node_Id
) return Boolean is
7328 return Is_Entity_Name
(N
)
7329 and then Ekind
(Entity
(N
)) = E_Variable
7330 and then OK_To_Rename
(Entity
(N
));
7331 end OK_To_Rename_Ref
;
7335 Adj_Call
: Node_Id
:= Empty
;
7336 Expr_Q
: Node_Id
:= Empty
;
7337 Tag_Assign
: Node_Id
:= Empty
;
7339 Init_After
: Node_Id
:= N
;
7340 -- Node after which the initialization actions are to be inserted. This
7341 -- is normally N, except for the case of a shared passive variable, in
7342 -- which case the init proc call must be inserted only after the bodies
7343 -- of the shared variable procedures have been seen.
7345 Has_BIP_Init_Expr
: Boolean := False;
7346 -- Whether the object is initialized with a BIP function call
7348 Rewrite_As_Renaming
: Boolean := False;
7349 -- Whether to turn the declaration into a renaming at the end
7351 -- Start of processing for Expand_N_Object_Declaration
7354 -- Don't do anything for deferred constants. All proper actions will be
7355 -- expanded during the full declaration.
7357 if No
(Expr
) and Constant_Present
(N
) then
7361 -- The type of the object cannot be abstract. This is diagnosed at the
7362 -- point the object is frozen, which happens after the declaration is
7363 -- fully expanded, so simply return now.
7365 if Is_Abstract_Type
(Typ
) then
7369 -- No action needed for the internal imported dummy object added by
7370 -- Make_DT to compute the offset of the components that reference
7371 -- secondary dispatch tables; required to avoid never-ending loop
7372 -- processing this internal object declaration.
7374 if Tagged_Type_Expansion
7375 and then Is_Internal
(Def_Id
)
7376 and then Is_Imported
(Def_Id
)
7377 and then Related_Type
(Def_Id
) = Implementation_Base_Type
(Typ
)
7382 -- Make shared memory routines for shared passive variable
7384 if Is_Shared_Passive
(Def_Id
) then
7385 Init_After
:= Make_Shared_Var_Procs
(N
);
7388 -- Determine whether the object is initialized with a BIP function call
7390 if Present
(Expr
) then
7391 Expr_Q
:= Unqualify
(Expr
);
7393 Has_BIP_Init_Expr
:=
7394 Is_Build_In_Place_Function_Call
(Expr_Q
)
7395 or else Present
(Unqual_BIP_Iface_Function_Call
(Expr_Q
))
7396 or else (Nkind
(Expr_Q
) = N_Reference
7398 Is_Build_In_Place_Function_Call
(Prefix
(Expr_Q
)));
7401 -- If tasks are being declared, make sure we have an activation chain
7402 -- defined for the tasks (has no effect if we already have one), and
7403 -- also that a Master variable is established (and that the appropriate
7404 -- enclosing construct is established as a task master).
7407 or else Might_Have_Tasks
(Typ
)
7408 or else (Has_BIP_Init_Expr
7409 and then Needs_BIP_Task_Actuals
(BIP_Function_Call_Id
))
7411 Build_Activation_Chain_Entity
(N
);
7413 if Has_Task
(Typ
) then
7414 Build_Master_Entity
(Def_Id
);
7416 -- Handle objects initialized with BIP function calls
7418 elsif Has_BIP_Init_Expr
then
7419 Build_Master_Entity
(Def_Id
);
7423 -- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
7424 -- restrictions are active then default-sized secondary stacks are
7425 -- generated by the binder and allocated by SS_Init. To provide the
7426 -- binder the number of stacks to generate, the number of default-sized
7427 -- stacks required for task objects contained within the object
7428 -- declaration N is calculated here as it is at this point where
7429 -- unconstrained types become constrained. The result is stored in the
7430 -- enclosing unit's Unit_Record.
7432 -- Note if N is an array object declaration that has an initialization
7433 -- expression, a second object declaration for the initialization
7434 -- expression is created by the compiler. To prevent double counting
7435 -- of the stacks in this scenario, the stacks of the first array are
7438 if Might_Have_Tasks
(Typ
)
7439 and then not Restriction_Active
(No_Secondary_Stack
)
7440 and then (Restriction_Active
(No_Implicit_Heap_Allocations
)
7441 or else Restriction_Active
(No_Implicit_Task_Allocations
))
7442 and then not (Ekind
(Typ
) in E_Array_Type | E_Array_Subtype
7443 and then Has_Init_Expression
(N
))
7446 PS_Count
, SS_Count
: Int
:= 0;
7448 Count_Default_Sized_Task_Stacks
(Typ
, PS_Count
, SS_Count
);
7449 Increment_Primary_Stack_Count
(PS_Count
);
7450 Increment_Sec_Stack_Count
(SS_Count
);
7454 -- Default initialization required, and no expression present
7457 -- If we have a type with a variant part, the initialization proc
7458 -- will contain implicit tests of the discriminant values, which
7459 -- counts as a violation of the restriction No_Implicit_Conditionals.
7461 if Has_Variant_Part
(Typ
) then
7466 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
7470 ("\initialization of variant record tests discriminants",
7477 -- For the default initialization case, if we have a private type
7478 -- with invariants, and invariant checks are enabled, then insert an
7479 -- invariant check after the object declaration. Note that it is OK
7480 -- to clobber the object with an invalid value since if the exception
7481 -- is raised, then the object will go out of scope. In the case where
7482 -- an array object is initialized with an aggregate, the expression
7483 -- is removed. Check flag Has_Init_Expression to avoid generating a
7484 -- junk invariant check and flag No_Initialization to avoid checking
7485 -- an uninitialized object such as a compiler temporary used for an
7488 if Has_Invariants
(Base_Typ
)
7489 and then Present
(Invariant_Procedure
(Base_Typ
))
7490 and then not Has_Init_Expression
(N
)
7491 and then not No_Initialization
(N
)
7493 -- If entity has an address clause or aspect, make invariant
7494 -- call into a freeze action for the explicit freeze node for
7495 -- object. Otherwise insert invariant check after declaration.
7497 if Present
(Following_Address_Clause
(N
))
7498 or else Has_Aspect
(Def_Id
, Aspect_Address
)
7500 Ensure_Freeze_Node
(Def_Id
);
7501 Set_Has_Delayed_Freeze
(Def_Id
);
7502 Set_Is_Frozen
(Def_Id
, False);
7504 if not Partial_View_Has_Unknown_Discr
(Typ
) then
7505 Append_Freeze_Action
(Def_Id
,
7506 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
7509 elsif not Partial_View_Has_Unknown_Discr
(Typ
) then
7511 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
7515 if not Special_Ret_Obj
then
7516 Default_Initialize_Object
(Init_After
);
7519 -- Generate attribute for Persistent_BSS if needed
7521 if Persistent_BSS_Mode
7522 and then Comes_From_Source
(N
)
7523 and then Is_Potentially_Persistent_Type
(Typ
)
7524 and then not Has_Init_Expression
(N
)
7525 and then Is_Library_Level_Entity
(Def_Id
)
7531 Make_Linker_Section_Pragma
7532 (Def_Id
, Sloc
(N
), ".persistent.bss");
7533 Insert_After
(N
, Prag
);
7538 -- If access type, then we know it is null if not initialized
7540 if Is_Access_Type
(Typ
) then
7541 Set_Is_Known_Null
(Def_Id
);
7544 -- Explicit initialization present
7547 -- Obtain actual expression from qualified expression
7549 Expr_Q
:= Unqualify
(Expr
);
7551 -- When we have the appropriate type of aggregate in the expression
7552 -- (it has been determined during analysis of the aggregate by
7553 -- setting the delay flag), let's perform in place assignment and
7554 -- thus avoid creating a temporary.
7556 if Is_Delayed_Aggregate
(Expr_Q
) then
7558 -- An aggregate that must be built in place is not resolved and
7559 -- expanded until the enclosing construct is expanded. This will
7560 -- happen when the aggregate is limited and the declared object
7561 -- has a following address clause; it happens also when generating
7562 -- C code for an aggregate that has an alignment or address clause
7563 -- (see Analyze_Object_Declaration). Resolution is done without
7564 -- expansion because it will take place when the declaration
7565 -- itself is expanded.
7567 if (Is_Limited_Type
(Typ
) or else Modify_Tree_For_C
)
7568 and then not Analyzed
(Expr
)
7570 Expander_Mode_Save_And_Set
(False);
7571 Resolve
(Expr
, Typ
);
7572 Expander_Mode_Restore
;
7575 if not Special_Ret_Obj
then
7576 Convert_Aggr_In_Object_Decl
(N
);
7579 -- Ada 2005 (AI-318-02): If the initialization expression is a call
7580 -- to a build-in-place function, then access to the declared object
7581 -- must be passed to the function. Currently we limit such functions
7582 -- to those with constrained limited result subtypes, but eventually
7583 -- plan to expand the allowed forms of functions that are treated as
7586 elsif Is_Build_In_Place_Function_Call
(Expr_Q
) then
7587 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
7589 -- The previous call expands the expression initializing the
7590 -- built-in-place object into further code that will be analyzed
7591 -- later. No further expansion needed here.
7595 -- This is the same as the previous 'elsif', except that the call has
7596 -- been transformed by other expansion activities into something like
7597 -- F(...)'Reference.
7599 elsif Nkind
(Expr_Q
) = N_Reference
7600 and then Is_Build_In_Place_Function_Call
(Prefix
(Expr_Q
))
7601 and then not Is_Expanded_Build_In_Place_Call
7602 (Unqual_Conv
(Prefix
(Expr_Q
)))
7604 Make_Build_In_Place_Call_In_Anonymous_Context
(Prefix
(Expr_Q
));
7606 -- The previous call expands the expression initializing the
7607 -- built-in-place object into further code that will be analyzed
7608 -- later. No further expansion needed here.
7612 -- Ada 2005 (AI-318-02): Specialization of the previous case for
7613 -- expressions containing a build-in-place function call whose
7614 -- returned object covers interface types, and Expr_Q has calls to
7615 -- Ada.Tags.Displace to displace the pointer to the returned build-
7616 -- in-place object to reference the secondary dispatch table of a
7617 -- covered interface type.
7619 elsif Present
(Unqual_BIP_Iface_Function_Call
(Expr_Q
)) then
7620 Make_Build_In_Place_Iface_Call_In_Object_Declaration
(N
, Expr_Q
);
7622 -- The previous call expands the expression initializing the
7623 -- built-in-place object into further code that will be analyzed
7624 -- later. No further expansion needed here.
7628 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
7629 -- class-wide interface object to ensure that we copy the full
7630 -- object, unless we are targetting a VM where interfaces are handled
7631 -- by VM itself. Note that if the root type of Typ is an ancestor of
7632 -- Expr's type, both types share the same dispatch table and there is
7633 -- no need to displace the pointer.
7635 elsif Is_Interface
(Typ
)
7637 -- Avoid never-ending recursion because if Equivalent_Type is set
7638 -- then we've done it already and must not do it again.
7641 (Nkind
(Obj_Def
) = N_Identifier
7642 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
7644 pragma Assert
(Is_Class_Wide_Type
(Typ
));
7646 -- If the original node of the expression was a conversion
7647 -- to this specific class-wide interface type then restore
7648 -- the original node because we must copy the object before
7649 -- displacing the pointer to reference the secondary tag
7650 -- component. This code must be kept synchronized with the
7651 -- expansion done by routine Expand_Interface_Conversion
7653 if not Comes_From_Source
(Expr
)
7654 and then Nkind
(Expr
) = N_Explicit_Dereference
7655 and then Nkind
(Original_Node
(Expr
)) = N_Type_Conversion
7656 and then Etype
(Original_Node
(Expr
)) = Typ
7658 Rewrite
(Expr
, Original_Node
(Expression
(N
)));
7661 -- Avoid expansion of redundant interface conversion
7663 if Nkind
(Expr
) = N_Type_Conversion
7664 and then Etype
(Expr
) = Typ
7666 Expr_Q
:= Expression
(Expr
);
7671 -- We may use a renaming if the initialization expression is a
7672 -- captured function call that meets a few conditions.
7674 Rewrite_As_Renaming
:= Is_Renamable_Function_Call
(Expr_Q
);
7676 -- If the object is a special return object, then bypass special
7677 -- treatment of class-wide interface initialization below. In this
7678 -- case, the expansion of the return object will take care of this
7679 -- initialization via the expansion of the allocator.
7681 if Special_Ret_Obj
and then not Rewrite_As_Renaming
then
7683 -- If the type needs finalization and is not inherently
7684 -- limited, then the target is adjusted after the copy
7685 -- and attached to the finalization list.
7687 if Needs_Finalization
(Typ
)
7688 and then not Is_Inherently_Limited_Type
(Typ
)
7692 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
7696 -- Renaming an expression of the object's type is immediate
7698 elsif Rewrite_As_Renaming
7699 and then Base_Type
(Etype
(Expr_Q
)) = Base_Type
(Typ
)
7703 elsif Tagged_Type_Expansion
then
7705 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
7707 Expr_Typ
: Entity_Id
;
7710 Ptr_Obj_Decl
: Node_Id
;
7711 Ptr_Obj_Id
: Entity_Id
;
7715 Expr_Typ
:= Base_Type
(Etype
(Expr_Q
));
7716 if Is_Class_Wide_Type
(Expr_Typ
) then
7717 Expr_Typ
:= Root_Type
(Expr_Typ
);
7720 -- Rename limited objects since they cannot be copied
7722 if Is_Limited_Record
(Expr_Typ
) then
7723 Rewrite_As_Renaming
:= True;
7726 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_Q
);
7729 -- IW : I'Class := Expr;
7731 -- Dnn : Tag renames Tag_Ptr!(Expr'Address).all;
7732 -- type Ityp is not null access I'Class;
7733 -- Rnn : constant Ityp :=
7734 -- Ityp!(Displace (Dnn'Address, I'Tag));
7735 -- IW : I'Class renames Rnn.all;
7737 if Rewrite_As_Renaming
then
7739 Make_Explicit_Dereference
(Loc
,
7740 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
7741 Make_Attribute_Reference
(Loc
,
7742 Prefix
=> Relocate_Node
(Expr_Q
),
7743 Attribute_Name
=> Name_Address
)));
7745 -- Suppress junk access checks on RE_Tag_Ptr
7748 Make_Object_Renaming_Declaration
(Loc
,
7749 Defining_Identifier
=> Obj_Id
,
7751 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7753 Suppress
=> Access_Check
);
7755 -- Dynamically reference the tag associated with the
7759 Make_Function_Call
(Loc
,
7760 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
7761 Parameter_Associations
=> New_List
(
7762 Make_Attribute_Reference
(Loc
,
7763 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
7764 Attribute_Name
=> Name_Address
),
7766 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
7770 -- IW : I'Class := Expr;
7772 -- Dnn : Typ := Expr;
7773 -- type Ityp is not null access I'Class;
7774 -- Rnn : constant Ityp := Ityp (Dnn.I_Tag'Address);
7775 -- IW : I'Class renames Rnn.all;
7777 elsif Has_Tag_Of_Type
(Expr_Q
)
7778 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
7779 and then (Expr_Typ
= Etype
(Expr_Typ
)
7781 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
7784 Make_Object_Declaration
(Loc
,
7785 Defining_Identifier
=> Obj_Id
,
7786 Object_Definition
=>
7787 New_Occurrence_Of
(Expr_Typ
, Loc
),
7788 Expression
=> Relocate_Node
(Expr_Q
)));
7790 -- Statically reference the tag associated with the
7794 Make_Selected_Component
(Loc
,
7795 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
7798 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
7801 -- IW : I'Class := Expr;
7803 -- type Equiv_Record is record ... end record;
7804 -- implicit subtype CW is <Class_Wide_Subtype>;
7805 -- Dnn : CW := CW!(Expr);
7806 -- type Ityp is not null access I'Class;
7807 -- Rnn : constant Ityp :=
7808 -- Ityp!(Displace (Dnn'Address, I'Tag));
7809 -- IW : I'Class renames Rnn.all;
7812 -- Generate the equivalent record type and update the
7813 -- subtype indication to reference it.
7815 Expand_Subtype_From_Expr
7818 Subtype_Indic
=> Obj_Def
,
7821 -- For interface types we use 'Address which displaces
7822 -- the pointer to the base of the object (if required).
7824 if Is_Interface
(Etype
(Expr_Q
)) then
7826 Unchecked_Convert_To
(Etype
(Obj_Def
),
7827 Make_Explicit_Dereference
(Loc
,
7828 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
7829 Make_Attribute_Reference
(Loc
,
7830 Prefix
=> Relocate_Node
(Expr_Q
),
7831 Attribute_Name
=> Name_Address
))));
7833 -- For other types, no displacement is needed
7836 New_Expr
:= Relocate_Node
(Expr_Q
);
7839 -- Suppress junk access checks on RE_Tag_Ptr
7842 Make_Object_Declaration
(Loc
,
7843 Defining_Identifier
=> Obj_Id
,
7844 Object_Definition
=>
7845 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
7846 Expression
=> New_Expr
),
7847 Suppress
=> Access_Check
);
7849 -- Dynamically reference the tag associated with the
7853 Make_Function_Call
(Loc
,
7854 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
7855 Parameter_Associations
=> New_List
(
7856 Make_Attribute_Reference
(Loc
,
7857 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
7858 Attribute_Name
=> Name_Address
),
7860 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
7864 -- As explained in Exp_Disp, we use Convert_Tag_To_Interface
7865 -- to do the final conversion, but we insert an intermediate
7866 -- temporary before the dereference so that we can process
7867 -- the expansion as part of the analysis of the declaration
7868 -- of this temporary, and then rewrite manually the original
7869 -- object as the simple renaming of this dereference.
7871 Tag_Comp
:= Convert_Tag_To_Interface
(Typ
, Tag_Comp
);
7872 pragma Assert
(Nkind
(Tag_Comp
) = N_Explicit_Dereference
7874 Nkind
(Prefix
(Tag_Comp
)) = N_Unchecked_Type_Conversion
);
7876 Ptr_Obj_Id
:= Make_Temporary
(Loc
, 'R');
7879 Make_Object_Declaration
(Loc
,
7880 Defining_Identifier
=> Ptr_Obj_Id
,
7881 Constant_Present
=> True,
7882 Object_Definition
=>
7884 (Entity
(Subtype_Mark
(Prefix
(Tag_Comp
))), Loc
),
7885 Expression
=> Prefix
(Tag_Comp
));
7887 Insert_Action
(N
, Ptr_Obj_Decl
, Suppress
=> All_Checks
);
7889 Set_Prefix
(Tag_Comp
, New_Occurrence_Of
(Ptr_Obj_Id
, Loc
));
7891 Set_Etype
(Expr_Q
, Typ
);
7892 Set_Parent
(Expr_Q
, N
);
7894 Rewrite_As_Renaming
:= True;
7901 -- Common case of explicit object initialization
7904 -- Small optimization: if the expression is a function call and
7905 -- the object is stand-alone, not declared at library level and of
7906 -- a class-wide type, then we capture the result of the call into
7907 -- a temporary, with the benefit that, if the result's type does
7908 -- not need finalization, nothing will be finalized and, if it
7909 -- does, the temporary only will be finalized by means of a direct
7910 -- call to the Finalize primitive if the result's type is not a
7911 -- class-wide type; whereas, in both cases, the stand-alone object
7912 -- itself would be finalized by means of a dispatching call to the
7913 -- Deep_Finalize routine.
7915 if Nkind
(Expr_Q
) = N_Function_Call
7916 and then not Special_Ret_Obj
7917 and then not Is_Library_Level_Entity
(Def_Id
)
7918 and then Is_Class_Wide_Type
(Typ
)
7920 Remove_Side_Effects
(Expr_Q
);
7923 -- In most cases, we must check that the initial value meets any
7924 -- constraint imposed by the declared type. However, there is one
7925 -- very important exception to this rule. If the entity has an
7926 -- unconstrained nominal subtype, then it acquired its constraints
7927 -- from the expression in the first place, and not only does this
7928 -- mean that the constraint check is not needed, but an attempt to
7929 -- perform the constraint check can cause order of elaboration
7932 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
7934 -- If this is an allocator for an aggregate that has been
7935 -- allocated in place, delay checks until assignments are
7936 -- made, because the discriminants are not initialized.
7938 if Nkind
(Expr
) = N_Allocator
7939 and then No_Initialization
(Expr
)
7943 -- Otherwise apply a constraint check now if no prev error
7945 elsif Nkind
(Expr
) /= N_Error
then
7946 Apply_Constraint_Check
(Expr
, Typ
);
7948 -- Deal with possible range check
7950 if Do_Range_Check
(Expr
) then
7952 -- If assignment checks are suppressed, turn off flag
7954 if Suppress_Assignment_Checks
(N
) then
7955 Set_Do_Range_Check
(Expr
, False);
7957 -- Otherwise generate the range check
7960 Generate_Range_Check
7961 (Expr
, Typ
, CE_Range_Check_Failed
);
7967 -- For tagged types, when an init value is given, the tag has to
7968 -- be re-initialized separately in order to avoid the propagation
7969 -- of a wrong tag coming from a view conversion unless the type
7970 -- is class wide (in this case the tag comes from the init value).
7971 -- Suppress the tag assignment when not Tagged_Type_Expansion
7972 -- because tags are represented implicitly in objects. Ditto for
7973 -- types that are CPP_CLASS, and for initializations that are
7974 -- aggregates, because they have to have the right tag.
7976 -- The re-assignment of the tag has to be done even if the object
7977 -- is a constant. The assignment must be analyzed after the
7978 -- declaration. If an address clause follows, this is handled as
7979 -- part of the freeze actions for the object, otherwise insert
7980 -- tag assignment here.
7982 Tag_Assign
:= Make_Tag_Assignment
(N
);
7984 if Present
(Tag_Assign
) then
7985 if Present
(Following_Address_Clause
(N
)) then
7986 Ensure_Freeze_Node
(Def_Id
);
7987 elsif not Special_Ret_Obj
then
7988 Insert_Action_After
(Init_After
, Tag_Assign
);
7991 -- Handle C++ constructor calls. Note that we do not check that
7992 -- Typ is a tagged type since the equivalent Ada type of a C++
7993 -- class that has no virtual methods is an untagged limited
7996 elsif Is_CPP_Constructor_Call
(Expr
) then
7998 Id_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
8001 -- The call to the initialization procedure does NOT freeze
8002 -- the object being initialized.
8004 Set_Must_Not_Freeze
(Id_Ref
);
8005 Set_Assignment_OK
(Id_Ref
);
8007 Insert_Actions_After
(Init_After
,
8008 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
8009 Constructor_Ref
=> Expr
));
8011 -- We remove here the original call to the constructor
8012 -- to avoid its management in the backend
8014 Set_Expression
(N
, Empty
);
8018 -- Handle initialization of limited tagged types
8020 elsif Is_Tagged_Type
(Typ
)
8021 and then Is_Class_Wide_Type
(Typ
)
8022 and then Is_Limited_Record
(Typ
)
8023 and then not Is_Limited_Interface
(Typ
)
8025 -- Given that the type is limited we cannot perform a copy. If
8026 -- Expr_Q is the reference to a variable we mark the variable
8027 -- as OK_To_Rename to expand this declaration into a renaming
8028 -- declaration (see below).
8030 if Is_Entity_Name
(Expr_Q
) then
8031 Set_OK_To_Rename
(Entity
(Expr_Q
));
8033 -- If we cannot convert the expression into a renaming we must
8034 -- consider it an internal error because the backend does not
8035 -- have support to handle it. But avoid crashing on a raise
8036 -- expression or conditional expression.
8038 elsif Nkind
(Original_Node
(Expr_Q
)) not in
8039 N_Raise_Expression | N_If_Expression | N_Case_Expression
8041 raise Program_Error
;
8044 -- For discrete types, set the Is_Known_Valid flag if the
8045 -- initializing value is known to be valid. Only do this for
8046 -- source assignments, since otherwise we can end up turning
8047 -- on the known valid flag prematurely from inserted code.
8049 elsif Comes_From_Source
(N
)
8050 and then Is_Discrete_Type
(Typ
)
8051 and then Expr_Known_Valid
(Expr
)
8052 and then Safe_To_Capture_Value
(N
, Def_Id
)
8054 Set_Is_Known_Valid
(Def_Id
);
8056 -- For access types, set the Is_Known_Non_Null flag if the
8057 -- initializing value is known to be non-null. We can also
8058 -- set Can_Never_Be_Null if this is a constant.
8060 elsif Is_Access_Type
(Typ
) and then Known_Non_Null
(Expr
) then
8061 Set_Is_Known_Non_Null
(Def_Id
, True);
8063 if Constant_Present
(N
) then
8064 Set_Can_Never_Be_Null
(Def_Id
);
8068 -- If validity checking on copies, validate initial expression.
8069 -- But skip this if declaration is for a generic type, since it
8070 -- makes no sense to validate generic types. Not clear if this
8071 -- can happen for legal programs, but it definitely can arise
8072 -- from previous instantiation errors.
8074 if Validity_Checks_On
8075 and then Comes_From_Source
(N
)
8076 and then Validity_Check_Copies
8077 and then not Is_Generic_Type
(Typ
)
8079 Ensure_Valid
(Expr
);
8081 if Safe_To_Capture_Value
(N
, Def_Id
) then
8082 Set_Is_Known_Valid
(Def_Id
);
8086 -- Now determine whether we will use a renaming
8088 Rewrite_As_Renaming
:=
8090 -- The declaration cannot be rewritten if it has got constraints
8092 Is_Entity_Name
(Original_Node
(Obj_Def
))
8094 -- If we have "X : S := ...;", and S is a constrained array
8095 -- subtype, then we cannot rename, because renamings ignore
8096 -- the constraints of S, so that would change the semantics
8097 -- (sliding would not occur on the initial value). This is
8098 -- only a problem for source objects though, the others have
8099 -- the correct bounds.
8101 and then not (Comes_From_Source
(Obj_Def
)
8102 and then Is_Array_Type
(Typ
)
8103 and then Is_Constrained
(Typ
))
8105 -- Moreover, if we have "X : aliased S := "...;" and S is an
8106 -- unconstrained array type, then we can rename only if the
8107 -- initialization expression has an unconstrained subtype too,
8108 -- because the bounds must be present within X.
8110 and then not (Is_Array_Type
(Typ
)
8111 and then Is_Constr_Subt_For_UN_Aliased
(Typ
)
8112 and then Is_Constrained
(Etype
(Expr_Q
)))
8114 -- We may use a renaming if the initialization expression is a
8115 -- captured function call that meets a few conditions.
8118 (Is_Renamable_Function_Call
(Expr_Q
)
8120 -- Or else if it is a variable with OK_To_Rename set
8122 or else (OK_To_Rename_Ref
(Expr_Q
)
8123 and then not Special_Ret_Obj
)
8125 -- Or else if it is a slice of such a variable
8127 or else (Nkind
(Expr_Q
) = N_Slice
8128 and then OK_To_Rename_Ref
(Prefix
(Expr_Q
))
8129 and then not Special_Ret_Obj
));
8131 -- If the type needs finalization and is not inherently limited,
8132 -- then the target is adjusted after the copy and attached to the
8133 -- finalization list. However, no adjustment is needed in the case
8134 -- where the object has been initialized by a call to a function
8135 -- returning on the primary stack (see Expand_Ctrl_Function_Call)
8136 -- since no copy occurred, given that the type is by-reference.
8137 -- Similarly, no adjustment is needed if we are going to rewrite
8138 -- the object declaration into a renaming declaration.
8140 if Needs_Finalization
(Typ
)
8141 and then not Is_Inherently_Limited_Type
(Typ
)
8142 and then Nkind
(Expr_Q
) /= N_Function_Call
8143 and then not Rewrite_As_Renaming
8147 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
8150 if Present
(Adj_Call
) and then not Special_Ret_Obj
then
8151 Insert_Action_After
(Init_After
, Adj_Call
);
8156 -- Cases where the back end cannot handle the initialization
8157 -- directly. In such cases, we expand an assignment that will
8158 -- be appropriately handled by Expand_N_Assignment_Statement.
8160 -- The exclusion of the unconstrained case is wrong, but for now it
8161 -- is too much trouble ???
8163 if (Is_Possibly_Unaligned_Slice
(Expr
)
8164 or else (Is_Possibly_Unaligned_Object
(Expr
)
8165 and then not Represented_As_Scalar
(Etype
(Expr
))))
8166 and then not (Is_Array_Type
(Etype
(Expr
))
8167 and then not Is_Constrained
(Etype
(Expr
)))
8170 Stat
: constant Node_Id
:=
8171 Make_Assignment_Statement
(Loc
,
8172 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
8173 Expression
=> Relocate_Node
(Expr
));
8175 Set_Assignment_OK
(Name
(Stat
));
8176 Set_No_Ctrl_Actions
(Stat
);
8177 Insert_Action_After
(Init_After
, Stat
);
8178 Set_Expression
(N
, Empty
);
8179 Set_No_Initialization
(N
);
8184 if Nkind
(Obj_Def
) = N_Access_Definition
8185 and then not Is_Local_Anonymous_Access
(Typ
)
8187 -- An Ada 2012 stand-alone object of an anonymous access type
8190 Loc
: constant Source_Ptr
:= Sloc
(N
);
8192 Level
: constant Entity_Id
:=
8193 Make_Defining_Identifier
(Sloc
(N
),
8195 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
8197 Level_Decl
: Node_Id
;
8198 Level_Expr
: Node_Id
;
8201 Mutate_Ekind
(Level
, Ekind
(Def_Id
));
8202 Set_Etype
(Level
, Standard_Natural
);
8203 Set_Scope
(Level
, Scope
(Def_Id
));
8205 -- Set accessibility level of null
8209 Make_Integer_Literal
8210 (Loc
, Scope_Depth
(Standard_Standard
));
8212 -- When the expression of the object is a function which returns
8213 -- an anonymous access type the master of the call is the object
8214 -- being initialized instead of the type.
8216 elsif Nkind
(Expr
) = N_Function_Call
8217 and then Ekind
(Etype
(Name
(Expr
))) = E_Anonymous_Access_Type
8219 Level_Expr
:= Accessibility_Level
8220 (Def_Id
, Object_Decl_Level
);
8225 Level_Expr
:= Accessibility_Level
(Expr
, Dynamic_Level
);
8229 Make_Object_Declaration
(Loc
,
8230 Defining_Identifier
=> Level
,
8231 Object_Definition
=>
8232 New_Occurrence_Of
(Standard_Natural
, Loc
),
8233 Expression
=> Level_Expr
,
8234 Constant_Present
=> Constant_Present
(N
),
8235 Has_Init_Expression
=> True);
8237 Insert_Action_After
(Init_After
, Level_Decl
);
8239 Set_Extra_Accessibility
(Def_Id
, Level
);
8243 -- If the object is default initialized and its type is subject to
8244 -- pragma Default_Initial_Condition, add a runtime check to verify
8245 -- the assumption of the pragma (SPARK RM 7.3.3). Generate:
8247 -- <Base_Typ>DIC (<Base_Typ> (Def_Id));
8249 -- Note that the check is generated for source objects only
8251 if Comes_From_Source
(Def_Id
)
8252 and then Has_DIC
(Typ
)
8253 and then Present
(DIC_Procedure
(Typ
))
8254 and then not Has_Null_Body
(DIC_Procedure
(Typ
))
8255 and then not Has_Init_Expression
(N
)
8257 and then not Is_Imported
(Def_Id
)
8260 DIC_Call
: constant Node_Id
:=
8262 (Loc
, New_Occurrence_Of
(Def_Id
, Loc
), Typ
);
8264 if Present
(Next_N
) then
8265 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
8267 -- The object declaration is the last node in a declarative or a
8271 Append_To
(List_Containing
(N
), DIC_Call
);
8277 -- If this is the return object of a build-in-place function, locate the
8278 -- implicit BIPaccess parameter designating the caller-supplied return
8279 -- object and convert the declaration to a renaming of a dereference of
8280 -- this parameter. If the declaration includes an expression, add an
8281 -- assignment statement to ensure the return object gets initialized.
8283 -- Result : T [:= <expression>];
8287 -- Result : T renames BIPaccess.all;
8288 -- [Result := <expression>;]
8290 -- in the constrained case, or to
8292 -- type Txx is access all ...;
8293 -- Rxx : Txx := null;
8295 -- if BIPalloc = 1 then
8296 -- Rxx := BIPaccess;
8297 -- Rxx.all := <expression>;
8298 -- elsif BIPalloc = 2 then
8299 -- Rxx := new <expression-type>'(<expression>)[storage_pool =
8300 -- system__secondary_stack__ss_pool][procedure_to_call =
8301 -- system__secondary_stack__ss_allocate];
8302 -- elsif BIPalloc = 3 then
8303 -- Rxx := new <expression-type>'(<expression>)
8304 -- elsif BIPalloc = 4 then
8305 -- Pxx : system__storage_pools__root_storage_pool renames
8306 -- BIPstoragepool.all;
8307 -- Rxx := new <expression-type>'(<expression>)[storage_pool =
8308 -- Pxx][procedure_to_call =
8309 -- system__storage_pools__allocate_any];
8311 -- [program_error "build in place mismatch"]
8314 -- Result : T renames Rxx.all;
8316 -- in the unconstrained case.
8318 if Is_Build_In_Place_Return_Object
(Def_Id
) then
8320 Init_Stmt
: Node_Id
;
8321 Obj_Acc_Formal
: Entity_Id
;
8324 -- Retrieve the implicit access parameter passed by the caller
8327 Build_In_Place_Formal
(Func_Id
, BIP_Object_Access
);
8329 -- If the return object's declaration includes an expression
8330 -- and the declaration isn't marked as No_Initialization, then
8331 -- we need to generate an assignment to the object and insert
8332 -- it after the declaration before rewriting it as a renaming
8333 -- (otherwise we'll lose the initialization). The case where
8334 -- the result type is an interface (or class-wide interface)
8335 -- is also excluded because the context of the function call
8336 -- must be unconstrained, so the initialization will always
8337 -- be done as part of an allocator evaluation (storage pool
8338 -- or secondary stack), never to a constrained target object
8339 -- passed in by the caller. Besides the assignment being
8340 -- unneeded in this case, it avoids problems with trying to
8341 -- generate a dispatching assignment when the return expression
8342 -- is a nonlimited descendant of a limited interface (the
8343 -- interface has no assignment operation).
8346 and then not Is_Delayed_Aggregate
(Expr_Q
)
8347 and then not No_Initialization
(N
)
8348 and then not Is_Interface
(Typ
)
8350 if Is_Class_Wide_Type
(Typ
)
8351 and then not Is_Class_Wide_Type
(Etype
(Expr_Q
))
8354 Make_Assignment_Statement
(Loc
,
8355 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
8357 Make_Type_Conversion
(Loc
,
8359 New_Occurrence_Of
(Typ
, Loc
),
8360 Expression
=> New_Copy_Tree
(Expr_Q
)));
8364 Make_Assignment_Statement
(Loc
,
8365 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
8366 Expression
=> New_Copy_Tree
(Expr_Q
));
8369 Set_Assignment_OK
(Name
(Init_Stmt
));
8370 Set_No_Ctrl_Actions
(Init_Stmt
);
8376 -- When the function's subtype is unconstrained, a run-time
8377 -- test may be needed to decide the form of allocation to use
8378 -- for the return object. The function has an implicit formal
8379 -- parameter indicating this. If the BIP_Alloc_Form formal has
8380 -- the value one, then the caller has passed access to an
8381 -- existing object for use as the return object. If the value
8382 -- is two, then the return object must be allocated on the
8383 -- secondary stack. If the value is three, then the return
8384 -- object must be allocated on the heap. Otherwise, the object
8385 -- must be allocated in a storage pool. We generate an if
8386 -- statement to test the BIP_Alloc_Form formal and initialize
8387 -- a local access value appropriately.
8389 if Needs_BIP_Alloc_Form
(Func_Id
) then
8391 Desig_Typ
: constant Entity_Id
:=
8392 (if Ekind
(Typ
) = E_Array_Subtype
8393 then Etype
(Func_Id
) else Typ
);
8394 -- Ensure that the we use a fat pointer when allocating
8395 -- an unconstrained array on the heap. In this case the
8396 -- result object's type is a constrained array type even
8397 -- though the function's type is unconstrained.
8399 Obj_Alloc_Formal
: constant Entity_Id
:=
8400 Build_In_Place_Formal
(Func_Id
, BIP_Alloc_Form
);
8401 Pool_Id
: constant Entity_Id
:=
8402 Make_Temporary
(Loc
, 'P');
8404 Acc_Typ
: Entity_Id
;
8405 Alloc_Obj_Decl
: Node_Id
;
8406 Alloc_Obj_Id
: Entity_Id
;
8407 Alloc_Stmt
: Node_Id
;
8408 Guard_Except
: Node_Id
;
8409 Heap_Allocator
: Node_Id
;
8410 Pool_Allocator
: Node_Id
;
8411 Pool_Decl
: Node_Id
;
8412 Ptr_Typ_Decl
: Node_Id
;
8413 SS_Allocator
: Node_Id
;
8416 -- Create an access type designating the function's
8419 Acc_Typ
:= Make_Temporary
(Loc
, 'A');
8422 Make_Full_Type_Declaration
(Loc
,
8423 Defining_Identifier
=> Acc_Typ
,
8425 Make_Access_To_Object_Definition
(Loc
,
8426 All_Present
=> True,
8427 Subtype_Indication
=>
8428 New_Occurrence_Of
(Desig_Typ
, Loc
)));
8430 Insert_Action
(N
, Ptr_Typ_Decl
, Suppress
=> All_Checks
);
8432 -- Create an access object that will be initialized to an
8433 -- access value denoting the return object, either coming
8434 -- from an implicit access value passed in by the caller
8435 -- or from the result of an allocator.
8437 Alloc_Obj_Id
:= Make_Temporary
(Loc
, 'R');
8440 Make_Object_Declaration
(Loc
,
8441 Defining_Identifier
=> Alloc_Obj_Id
,
8442 Object_Definition
=>
8443 New_Occurrence_Of
(Acc_Typ
, Loc
));
8445 Insert_Action
(N
, Alloc_Obj_Decl
, Suppress
=> All_Checks
);
8447 -- First create the Heap_Allocator
8449 Heap_Allocator
:= Make_Allocator_For_Return
(Expr_Q
);
8451 -- The Pool_Allocator is just like the Heap_Allocator,
8452 -- except we set Storage_Pool and Procedure_To_Call so
8453 -- it will use the user-defined storage pool.
8455 Pool_Allocator
:= Make_Allocator_For_Return
(Expr_Q
);
8457 -- Do not generate the renaming of the build-in-place
8458 -- pool parameter on ZFP because the parameter is not
8459 -- created in the first place.
8461 if RTE_Available
(RE_Root_Storage_Pool_Ptr
) then
8463 Make_Object_Renaming_Declaration
(Loc
,
8464 Defining_Identifier
=> Pool_Id
,
8467 (RTE
(RE_Root_Storage_Pool
), Loc
),
8469 Make_Explicit_Dereference
(Loc
,
8471 (Build_In_Place_Formal
8472 (Func_Id
, BIP_Storage_Pool
), Loc
)));
8473 Set_Storage_Pool
(Pool_Allocator
, Pool_Id
);
8474 Set_Procedure_To_Call
8475 (Pool_Allocator
, RTE
(RE_Allocate_Any
));
8477 Pool_Decl
:= Make_Null_Statement
(Loc
);
8480 -- If the No_Allocators restriction is active, then only
8481 -- an allocator for secondary stack allocation is needed.
8482 -- It's OK for such allocators to have Comes_From_Source
8483 -- set to False, because gigi knows not to flag them as
8484 -- being a violation of No_Implicit_Heap_Allocations.
8486 if Restriction_Active
(No_Allocators
) then
8487 SS_Allocator
:= Heap_Allocator
;
8488 Heap_Allocator
:= Make_Null
(Loc
);
8489 Pool_Allocator
:= Make_Null
(Loc
);
8491 -- Otherwise the heap and pool allocators may be needed,
8492 -- so we make another allocator for secondary stack
8496 SS_Allocator
:= Make_Allocator_For_Return
(Expr_Q
);
8498 -- The heap and pool allocators are marked as
8499 -- Comes_From_Source since they correspond to an
8500 -- explicit user-written allocator (that is, it will
8501 -- only be executed on behalf of callers that call the
8502 -- function as initialization for such an allocator).
8503 -- Prevents errors when No_Implicit_Heap_Allocations
8506 Set_Comes_From_Source
(Heap_Allocator
, True);
8507 Set_Comes_From_Source
(Pool_Allocator
, True);
8510 -- The allocator is returned on the secondary stack
8512 Check_Restriction
(No_Secondary_Stack
, N
);
8513 Set_Storage_Pool
(SS_Allocator
, RTE
(RE_SS_Pool
));
8514 Set_Procedure_To_Call
8515 (SS_Allocator
, RTE
(RE_SS_Allocate
));
8517 -- The allocator is returned on the secondary stack,
8518 -- so indicate that the function return, as well as
8519 -- all blocks that encloses the allocator, must not
8520 -- release it. The flags must be set now because
8521 -- the decision to use the secondary stack is done
8522 -- very late in the course of expanding the return
8523 -- statement, past the point where these flags are
8526 Set_Uses_Sec_Stack
(Func_Id
);
8527 Set_Uses_Sec_Stack
(Scope
(Def_Id
));
8528 Set_Sec_Stack_Needed_For_Return
(Scope
(Def_Id
));
8530 -- Guard against poor expansion on the caller side by
8531 -- using a raise statement to catch out-of-range values
8532 -- of formal parameter BIP_Alloc_Form.
8534 if Exceptions_OK
then
8536 Make_Raise_Program_Error
(Loc
,
8537 Reason
=> PE_Build_In_Place_Mismatch
);
8539 Guard_Except
:= Make_Null_Statement
(Loc
);
8542 -- Create an if statement to test the BIP_Alloc_Form
8543 -- formal and initialize the access object to either the
8544 -- BIP_Object_Access formal (BIP_Alloc_Form =
8545 -- Caller_Allocation), the result of allocating the
8546 -- object in the secondary stack (BIP_Alloc_Form =
8547 -- Secondary_Stack), or else an allocator to create the
8548 -- return object in the heap or user-defined pool
8549 -- (BIP_Alloc_Form = Global_Heap or User_Storage_Pool).
8551 -- ??? An unchecked type conversion must be made in the
8552 -- case of assigning the access object formal to the
8553 -- local access object, because a normal conversion would
8554 -- be illegal in some cases (such as converting access-
8555 -- to-unconstrained to access-to-constrained), but the
8556 -- the unchecked conversion will presumably fail to work
8557 -- right in just such cases. It's not clear at all how to
8561 Make_If_Statement
(Loc
,
8565 New_Occurrence_Of
(Obj_Alloc_Formal
, Loc
),
8567 Make_Integer_Literal
(Loc
,
8568 UI_From_Int
(BIP_Allocation_Form
'Pos
8569 (Caller_Allocation
)))),
8571 Then_Statements
=> New_List
(
8572 Make_Assignment_Statement
(Loc
,
8574 New_Occurrence_Of
(Alloc_Obj_Id
, Loc
),
8576 Unchecked_Convert_To
8578 New_Occurrence_Of
(Obj_Acc_Formal
, Loc
)))),
8580 Elsif_Parts
=> New_List
(
8581 Make_Elsif_Part
(Loc
,
8585 New_Occurrence_Of
(Obj_Alloc_Formal
, Loc
),
8587 Make_Integer_Literal
(Loc
,
8588 UI_From_Int
(BIP_Allocation_Form
'Pos
8589 (Secondary_Stack
)))),
8591 Then_Statements
=> New_List
(
8592 Make_Assignment_Statement
(Loc
,
8594 New_Occurrence_Of
(Alloc_Obj_Id
, Loc
),
8595 Expression
=> SS_Allocator
))),
8597 Make_Elsif_Part
(Loc
,
8601 New_Occurrence_Of
(Obj_Alloc_Formal
, Loc
),
8603 Make_Integer_Literal
(Loc
,
8604 UI_From_Int
(BIP_Allocation_Form
'Pos
8607 Then_Statements
=> New_List
(
8608 Build_Heap_Or_Pool_Allocator
8609 (Temp_Id
=> Alloc_Obj_Id
,
8610 Temp_Typ
=> Acc_Typ
,
8611 Ret_Typ
=> Desig_Typ
,
8612 Alloc_Expr
=> Heap_Allocator
))),
8614 -- ??? If all is well, we can put the following
8615 -- 'elsif' in the 'else', but this is a useful
8616 -- self-check in case caller and callee don't agree
8617 -- on whether BIPAlloc and so on should be passed.
8619 Make_Elsif_Part
(Loc
,
8623 New_Occurrence_Of
(Obj_Alloc_Formal
, Loc
),
8625 Make_Integer_Literal
(Loc
,
8626 UI_From_Int
(BIP_Allocation_Form
'Pos
8627 (User_Storage_Pool
)))),
8629 Then_Statements
=> New_List
(
8631 Build_Heap_Or_Pool_Allocator
8632 (Temp_Id
=> Alloc_Obj_Id
,
8633 Temp_Typ
=> Acc_Typ
,
8634 Ret_Typ
=> Desig_Typ
,
8635 Alloc_Expr
=> Pool_Allocator
)))),
8637 -- Raise Program_Error if it's none of the above;
8638 -- this is a compiler bug.
8640 Else_Statements
=> New_List
(Guard_Except
));
8642 -- If a separate initialization assignment was created
8643 -- earlier, append that following the assignment of the
8644 -- implicit access formal to the access object, to ensure
8645 -- that the return object is initialized in that case. In
8646 -- this situation, the target of the assignment must be
8647 -- rewritten to denote a dereference of the access to the
8648 -- return object passed in by the caller.
8650 if Present
(Init_Stmt
) then
8651 Set_Name
(Init_Stmt
,
8652 Make_Explicit_Dereference
(Loc
,
8653 Prefix
=> New_Occurrence_Of
(Alloc_Obj_Id
, Loc
)));
8654 Set_Assignment_OK
(Name
(Init_Stmt
));
8656 Append_To
(Then_Statements
(Alloc_Stmt
), Init_Stmt
);
8660 Insert_Action
(N
, Alloc_Stmt
, Suppress
=> All_Checks
);
8662 -- From now on, the type of the return object is the
8665 if Desig_Typ
/= Typ
then
8666 Set_Etype
(Def_Id
, Desig_Typ
);
8667 Set_Actual_Subtype
(Def_Id
, Typ
);
8670 -- Remember the local access object for use in the
8671 -- dereference of the renaming created below.
8673 Obj_Acc_Formal
:= Alloc_Obj_Id
;
8676 -- When the function's type is unconstrained and a run-time test
8677 -- is not needed, we nevertheless need to build the return using
8678 -- the return object's type.
8680 elsif not Is_Constrained
(Underlying_Type
(Etype
(Func_Id
))) then
8682 Acc_Typ
: Entity_Id
;
8683 Alloc_Obj_Decl
: Node_Id
;
8684 Alloc_Obj_Id
: Entity_Id
;
8685 Ptr_Typ_Decl
: Node_Id
;
8688 -- Create an access type designating the function's
8691 Acc_Typ
:= Make_Temporary
(Loc
, 'A');
8694 Make_Full_Type_Declaration
(Loc
,
8695 Defining_Identifier
=> Acc_Typ
,
8697 Make_Access_To_Object_Definition
(Loc
,
8698 All_Present
=> True,
8699 Subtype_Indication
=>
8700 New_Occurrence_Of
(Typ
, Loc
)));
8702 Insert_Action
(N
, Ptr_Typ_Decl
, Suppress
=> All_Checks
);
8704 -- Create an access object initialized to the conversion
8705 -- of the implicit access value passed in by the caller.
8707 Alloc_Obj_Id
:= Make_Temporary
(Loc
, 'R');
8709 -- See the ??? comment a few lines above about the use of
8710 -- an unchecked conversion here.
8713 Make_Object_Declaration
(Loc
,
8714 Defining_Identifier
=> Alloc_Obj_Id
,
8715 Constant_Present
=> True,
8716 Object_Definition
=>
8717 New_Occurrence_Of
(Acc_Typ
, Loc
),
8719 Unchecked_Convert_To
8720 (Acc_Typ
, New_Occurrence_Of
(Obj_Acc_Formal
, Loc
)));
8722 Insert_Action
(N
, Alloc_Obj_Decl
, Suppress
=> All_Checks
);
8724 -- Remember the local access object for use in the
8725 -- dereference of the renaming created below.
8727 Obj_Acc_Formal
:= Alloc_Obj_Id
;
8731 -- Initialize the object now that it has got its final subtype,
8732 -- but before rewriting it as a renaming.
8734 Initialize_Return_Object
8735 (Tag_Assign
, Adj_Call
, Expr_Q
, Init_Stmt
, Init_After
);
8737 -- Replace the return object declaration with a renaming of a
8738 -- dereference of the access value designating the return object.
8741 Make_Explicit_Dereference
(Loc
,
8742 Prefix
=> New_Occurrence_Of
(Obj_Acc_Formal
, Loc
));
8743 Set_Etype
(Expr_Q
, Etype
(Def_Id
));
8745 Rewrite_As_Renaming
:= True;
8748 -- If we can rename the initialization expression, we need to make sure
8749 -- that we use the proper type in the case of a return object that lives
8750 -- on the secondary stack (see other cases below for a similar handling)
8751 -- and that the tag is assigned in the case of any return object.
8753 elsif Rewrite_As_Renaming
then
8754 if Special_Ret_Obj
then
8756 Desig_Typ
: constant Entity_Id
:=
8757 (if Ekind
(Typ
) = E_Array_Subtype
8758 then Etype
(Func_Id
) else Typ
);
8761 -- From now on, the type of the return object is the
8764 if Desig_Typ
/= Typ
then
8765 Set_Etype
(Def_Id
, Desig_Typ
);
8766 Set_Actual_Subtype
(Def_Id
, Typ
);
8769 if Present
(Tag_Assign
) then
8770 Insert_Action_After
(Init_After
, Tag_Assign
);
8773 -- Ada 2005 (AI95-344): If the result type is class-wide,
8774 -- insert a check that the level of the return expression's
8775 -- underlying type is not deeper than the level of the master
8776 -- enclosing the function.
8778 -- AI12-043: The check is made immediately after the return
8779 -- object is created.
8781 if Is_Class_Wide_Type
(Etype
(Func_Id
)) then
8782 Apply_CW_Accessibility_Check
(Expr_Q
, Func_Id
);
8787 -- If this is the return object of a function returning on the secondary
8788 -- stack, convert the declaration to a renaming of the dereference of ah
8789 -- allocator for the secondary stack.
8791 -- Result : T [:= <expression>];
8795 -- type Txx is access all ...;
8796 -- Rxx : constant Txx :=
8797 -- new <expression-type>['(<expression>)][storage_pool =
8798 -- system__secondary_stack__ss_pool][procedure_to_call =
8799 -- system__secondary_stack__ss_allocate];
8801 -- Result : T renames Rxx.all;
8803 elsif Is_Secondary_Stack_Return_Object
(Def_Id
) then
8805 Desig_Typ
: constant Entity_Id
:=
8806 (if Ekind
(Typ
) = E_Array_Subtype
8807 then Etype
(Func_Id
) else Typ
);
8808 -- Ensure that the we use a fat pointer when allocating
8809 -- an unconstrained array on the heap. In this case the
8810 -- result object's type is a constrained array type even
8811 -- though the function's type is unconstrained.
8813 Acc_Typ
: Entity_Id
;
8814 Alloc_Obj_Decl
: Node_Id
;
8815 Alloc_Obj_Id
: Entity_Id
;
8816 Ptr_Type_Decl
: Node_Id
;
8819 -- Create an access type designating the function's
8822 Acc_Typ
:= Make_Temporary
(Loc
, 'A');
8825 Make_Full_Type_Declaration
(Loc
,
8826 Defining_Identifier
=> Acc_Typ
,
8828 Make_Access_To_Object_Definition
(Loc
,
8829 All_Present
=> True,
8830 Subtype_Indication
=>
8831 New_Occurrence_Of
(Desig_Typ
, Loc
)));
8833 Insert_Action
(N
, Ptr_Type_Decl
, Suppress
=> All_Checks
);
8835 Set_Associated_Storage_Pool
(Acc_Typ
, RTE
(RE_SS_Pool
));
8837 Alloc_Obj_Id
:= Make_Temporary
(Loc
, 'R');
8840 Make_Object_Declaration
(Loc
,
8841 Defining_Identifier
=> Alloc_Obj_Id
,
8842 Constant_Present
=> True,
8843 Object_Definition
=>
8844 New_Occurrence_Of
(Acc_Typ
, Loc
),
8845 Expression
=> Make_Allocator_For_Return
(Expr_Q
));
8847 Insert_Action
(N
, Alloc_Obj_Decl
, Suppress
=> All_Checks
);
8849 Set_Uses_Sec_Stack
(Func_Id
);
8850 Set_Uses_Sec_Stack
(Scope
(Def_Id
));
8851 Set_Sec_Stack_Needed_For_Return
(Scope
(Def_Id
));
8853 -- From now on, the type of the return object is the
8856 if Desig_Typ
/= Typ
then
8857 Set_Etype
(Def_Id
, Desig_Typ
);
8858 Set_Actual_Subtype
(Def_Id
, Typ
);
8861 -- Initialize the object now that it has got its final subtype,
8862 -- but before rewriting it as a renaming.
8864 Initialize_Return_Object
8865 (Tag_Assign
, Adj_Call
, Expr_Q
, Empty
, Init_After
);
8867 -- Replace the return object declaration with a renaming of a
8868 -- dereference of the access value designating the return object.
8871 Make_Explicit_Dereference
(Loc
,
8872 Prefix
=> New_Occurrence_Of
(Alloc_Obj_Id
, Loc
));
8873 Set_Etype
(Expr_Q
, Etype
(Def_Id
));
8875 Rewrite_As_Renaming
:= True;
8878 -- If this is the return object of a function returning a by-reference
8879 -- type, convert the declaration to a renaming of the dereference of ah
8880 -- allocator for the return stack.
8882 -- Result : T [:= <expression>];
8886 -- type Txx is access all ...;
8887 -- Rxx : constant Txx :=
8888 -- new <expression-type>['(<expression>)][storage_pool =
8889 -- system__return_stack__rs_pool][procedure_to_call =
8890 -- system__return_stack__rs_allocate];
8892 -- Result : T renames Rxx.all;
8894 elsif Back_End_Return_Slot
8895 and then Is_By_Reference_Return_Object
(Def_Id
)
8898 Acc_Typ
: Entity_Id
;
8899 Alloc_Obj_Decl
: Node_Id
;
8900 Alloc_Obj_Id
: Entity_Id
;
8901 Ptr_Type_Decl
: Node_Id
;
8904 -- Create an access type designating the function's
8907 Acc_Typ
:= Make_Temporary
(Loc
, 'A');
8910 Make_Full_Type_Declaration
(Loc
,
8911 Defining_Identifier
=> Acc_Typ
,
8913 Make_Access_To_Object_Definition
(Loc
,
8914 All_Present
=> True,
8915 Subtype_Indication
=>
8916 New_Occurrence_Of
(Typ
, Loc
)));
8918 Insert_Action
(N
, Ptr_Type_Decl
, Suppress
=> All_Checks
);
8920 Set_Associated_Storage_Pool
(Acc_Typ
, RTE
(RE_RS_Pool
));
8922 Alloc_Obj_Id
:= Make_Temporary
(Loc
, 'R');
8925 Make_Object_Declaration
(Loc
,
8926 Defining_Identifier
=> Alloc_Obj_Id
,
8927 Constant_Present
=> True,
8928 Object_Definition
=>
8929 New_Occurrence_Of
(Acc_Typ
, Loc
),
8930 Expression
=> Make_Allocator_For_Return
(Expr_Q
));
8932 Insert_Action
(N
, Alloc_Obj_Decl
, Suppress
=> All_Checks
);
8934 -- Initialize the object now that it has got its final subtype,
8935 -- but before rewriting it as a renaming.
8937 Initialize_Return_Object
8938 (Tag_Assign
, Adj_Call
, Expr_Q
, Empty
, Init_After
);
8940 -- Replace the return object declaration with a renaming of a
8941 -- dereference of the access value designating the return object.
8944 Make_Explicit_Dereference
(Loc
,
8945 Prefix
=> New_Occurrence_Of
(Alloc_Obj_Id
, Loc
));
8946 Set_Etype
(Expr_Q
, Etype
(Def_Id
));
8948 Rewrite_As_Renaming
:= True;
8952 -- Final transformation - turn the object declaration into a renaming
8953 -- if appropriate. If this is the completion of a deferred constant
8954 -- declaration, then this transformation generates what would be
8955 -- illegal code if written by hand, but that's OK.
8957 if Rewrite_As_Renaming
then
8959 Make_Object_Renaming_Declaration
(Loc
,
8960 Defining_Identifier
=> Def_Id
,
8961 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Def_Id
), Loc
),
8964 -- Keep original aspects
8966 Move_Aspects
(Original_Node
(N
), N
);
8968 -- We do not analyze this renaming declaration, because all its
8969 -- components have already been analyzed, and if we were to go
8970 -- ahead and analyze it, we would in effect be trying to generate
8971 -- another declaration of X, which won't do.
8973 Set_Renamed_Object
(Def_Id
, Expr_Q
);
8976 -- We do need to deal with debug issues for this renaming
8978 -- First, if entity comes from source, then mark it as needing
8979 -- debug information, even though it is defined by a generated
8980 -- renaming that does not come from source.
8982 Set_Debug_Info_Defining_Id
(N
);
8984 -- Now call the routine to generate debug info for the renaming
8986 Insert_Action
(N
, Debug_Renaming_Declaration
(N
));
8989 -- Exception on library entity not available
8992 when RE_Not_Available
=>
8994 end Expand_N_Object_Declaration
;
8996 ---------------------------------
8997 -- Expand_N_Subtype_Indication --
8998 ---------------------------------
9000 -- Add a check on the range of the subtype and deal with validity checking
9002 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
9003 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
9004 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
9007 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
9008 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
9011 -- Do not duplicate the work of Process_Range_Expr_In_Decl in Sem_Ch3
9013 if Nkind
(Parent
(N
)) in N_Constrained_Array_Definition | N_Slice
9014 and then Nkind
(Parent
(Parent
(N
))) not in
9015 N_Full_Type_Declaration | N_Object_Declaration
9017 Apply_Range_Check
(Ran
, Typ
);
9019 end Expand_N_Subtype_Indication
;
9021 ---------------------------
9022 -- Expand_N_Variant_Part --
9023 ---------------------------
9025 -- Note: this procedure no longer has any effect. It used to be that we
9026 -- would replace the choices in the last variant by a when others, and
9027 -- also expanded static predicates in variant choices here, but both of
9028 -- those activities were being done too early, since we can't check the
9029 -- choices until the statically predicated subtypes are frozen, which can
9030 -- happen as late as the free point of the record, and we can't change the
9031 -- last choice to an others before checking the choices, which is now done
9032 -- at the freeze point of the record.
9034 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
9037 end Expand_N_Variant_Part
;
9039 ---------------------------------
9040 -- Expand_Previous_Access_Type --
9041 ---------------------------------
9043 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
9044 Ptr_Typ
: Entity_Id
;
9047 -- Find all access types in the current scope whose designated type is
9048 -- Def_Id and build master renamings for them.
9050 Ptr_Typ
:= First_Entity
(Current_Scope
);
9051 while Present
(Ptr_Typ
) loop
9052 if Is_Access_Type
(Ptr_Typ
)
9053 and then Designated_Type
(Ptr_Typ
) = Def_Id
9054 and then No
(Master_Id
(Ptr_Typ
))
9056 -- Ensure that the designated type has a master
9058 Build_Master_Entity
(Def_Id
);
9060 -- Private and incomplete types complicate the insertion of master
9061 -- renamings because the access type may precede the full view of
9062 -- the designated type. For this reason, the master renamings are
9063 -- inserted relative to the designated type.
9065 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
9068 Next_Entity
(Ptr_Typ
);
9070 end Expand_Previous_Access_Type
;
9072 -----------------------------
9073 -- Expand_Record_Extension --
9074 -----------------------------
9076 -- Add a field _parent at the beginning of the record extension. This is
9077 -- used to implement inheritance. Here are some examples of expansion:
9079 -- 1. no discriminants
9080 -- type T2 is new T1 with null record;
9082 -- type T2 is new T1 with record
9086 -- 2. renamed discriminants
9087 -- type T2 (B, C : Int) is new T1 (A => B) with record
9088 -- _Parent : T1 (A => B);
9092 -- 3. inherited discriminants
9093 -- type T2 is new T1 with record -- discriminant A inherited
9094 -- _Parent : T1 (A);
9098 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
) is
9099 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
9100 Loc
: constant Source_Ptr
:= Sloc
(Def
);
9101 Rec_Ext_Part
: Node_Id
:= Record_Extension_Part
(Def
);
9102 Par_Subtype
: Entity_Id
;
9103 Comp_List
: Node_Id
;
9104 Comp_Decl
: Node_Id
;
9107 List_Constr
: constant List_Id
:= New_List
;
9110 -- Expand_Record_Extension is called directly from the semantics, so
9111 -- we must check to see whether expansion is active before proceeding,
9112 -- because this affects the visibility of selected components in bodies
9113 -- of instances. Within a generic we still need to set Parent_Subtype
9114 -- link because the visibility of inherited components will have to be
9115 -- verified in subsequent instances.
9117 if not Expander_Active
then
9118 if Inside_A_Generic
and then Ekind
(T
) = E_Record_Type
then
9119 Set_Parent_Subtype
(T
, Etype
(T
));
9124 -- This may be a derivation of an untagged private type whose full
9125 -- view is tagged, in which case the Derived_Type_Definition has no
9126 -- extension part. Build an empty one now.
9128 if No
(Rec_Ext_Part
) then
9130 Make_Record_Definition
(Loc
,
9132 Component_List
=> Empty
,
9133 Null_Present
=> True);
9135 Set_Record_Extension_Part
(Def
, Rec_Ext_Part
);
9136 Mark_Rewrite_Insertion
(Rec_Ext_Part
);
9139 Comp_List
:= Component_List
(Rec_Ext_Part
);
9141 Parent_N
:= Make_Defining_Identifier
(Loc
, Name_uParent
);
9143 -- If the derived type inherits its discriminants the type of the
9144 -- _parent field must be constrained by the inherited discriminants
9146 if Has_Discriminants
(T
)
9147 and then Nkind
(Indic
) /= N_Subtype_Indication
9148 and then not Is_Constrained
(Entity
(Indic
))
9150 D
:= First_Discriminant
(T
);
9151 while Present
(D
) loop
9152 Append_To
(List_Constr
, New_Occurrence_Of
(D
, Loc
));
9153 Next_Discriminant
(D
);
9158 Make_Subtype_Indication
(Loc
,
9159 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Indic
), Loc
),
9161 Make_Index_Or_Discriminant_Constraint
(Loc
,
9162 Constraints
=> List_Constr
)),
9165 -- Otherwise the original subtype_indication is just what is needed
9168 Par_Subtype
:= Process_Subtype
(New_Copy_Tree
(Indic
), Def
);
9171 Set_Parent_Subtype
(T
, Par_Subtype
);
9174 Make_Component_Declaration
(Loc
,
9175 Defining_Identifier
=> Parent_N
,
9176 Component_Definition
=>
9177 Make_Component_Definition
(Loc
,
9178 Aliased_Present
=> False,
9179 Subtype_Indication
=> New_Occurrence_Of
(Par_Subtype
, Loc
)));
9181 if Null_Present
(Rec_Ext_Part
) then
9182 Set_Component_List
(Rec_Ext_Part
,
9183 Make_Component_List
(Loc
,
9184 Component_Items
=> New_List
(Comp_Decl
),
9185 Variant_Part
=> Empty
,
9186 Null_Present
=> False));
9187 Set_Null_Present
(Rec_Ext_Part
, False);
9189 elsif Null_Present
(Comp_List
)
9190 or else Is_Empty_List
(Component_Items
(Comp_List
))
9192 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
9193 Set_Null_Present
(Comp_List
, False);
9196 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
9199 Analyze
(Comp_Decl
);
9200 end Expand_Record_Extension
;
9202 ------------------------
9203 -- Expand_Tagged_Root --
9204 ------------------------
9206 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
9207 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
9208 Comp_List
: Node_Id
;
9209 Comp_Decl
: Node_Id
;
9210 Sloc_N
: Source_Ptr
;
9213 if Null_Present
(Def
) then
9214 Set_Component_List
(Def
,
9215 Make_Component_List
(Sloc
(Def
),
9216 Component_Items
=> Empty_List
,
9217 Variant_Part
=> Empty
,
9218 Null_Present
=> True));
9221 Comp_List
:= Component_List
(Def
);
9223 if Null_Present
(Comp_List
)
9224 or else Is_Empty_List
(Component_Items
(Comp_List
))
9226 Sloc_N
:= Sloc
(Comp_List
);
9228 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
9232 Make_Component_Declaration
(Sloc_N
,
9233 Defining_Identifier
=> First_Tag_Component
(T
),
9234 Component_Definition
=>
9235 Make_Component_Definition
(Sloc_N
,
9236 Aliased_Present
=> False,
9237 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
9239 if Null_Present
(Comp_List
)
9240 or else Is_Empty_List
(Component_Items
(Comp_List
))
9242 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
9243 Set_Null_Present
(Comp_List
, False);
9246 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
9249 -- We don't Analyze the whole expansion because the tag component has
9250 -- already been analyzed previously. Here we just insure that the tree
9251 -- is coherent with the semantic decoration
9253 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
9256 when RE_Not_Available
=>
9258 end Expand_Tagged_Root
;
9260 ------------------------------
9261 -- Freeze_Stream_Operations --
9262 ------------------------------
9264 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
9265 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
9270 Stream_Op
: Entity_Id
;
9273 -- Primitive operations of tagged types are frozen when the dispatch
9274 -- table is constructed.
9276 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
9280 for J
in Names
'Range loop
9281 Stream_Op
:= TSS
(Typ
, Names
(J
));
9283 if Present
(Stream_Op
)
9284 and then Is_Subprogram
(Stream_Op
)
9285 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
9286 N_Subprogram_Declaration
9287 and then not Is_Frozen
(Stream_Op
)
9289 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
9292 end Freeze_Stream_Operations
;
9298 -- Full type declarations are expanded at the point at which the type is
9299 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
9300 -- declarations generated by the freezing (e.g. the procedure generated
9301 -- for initialization) are chained in the Actions field list of the freeze
9302 -- node using Append_Freeze_Actions.
9304 -- WARNING: This routine manages Ghost regions. Return statements must be
9305 -- replaced by gotos which jump to the end of the routine and restore the
9308 function Freeze_Type
(N
: Node_Id
) return Boolean is
9309 procedure Process_RACW_Types
(Typ
: Entity_Id
);
9310 -- Validate and generate stubs for all RACW types associated with type
9313 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
);
9314 -- Associate type Typ's Finalize_Address primitive with the finalization
9315 -- masters of pending access-to-Typ types.
9317 ------------------------
9318 -- Process_RACW_Types --
9319 ------------------------
9321 procedure Process_RACW_Types
(Typ
: Entity_Id
) is
9322 List
: constant Elist_Id
:= Access_Types_To_Process
(N
);
9324 Seen
: Boolean := False;
9327 if Present
(List
) then
9328 E
:= First_Elmt
(List
);
9329 while Present
(E
) loop
9330 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
9331 Validate_RACW_Primitives
(Node
(E
));
9339 -- If there are RACWs designating this type, make stubs now
9342 Remote_Types_Tagged_Full_View_Encountered
(Typ
);
9344 end Process_RACW_Types
;
9346 ----------------------------------
9347 -- Process_Pending_Access_Types --
9348 ----------------------------------
9350 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
) is
9354 -- Finalize_Address is not generated in CodePeer mode because the
9355 -- body contains address arithmetic. This processing is disabled.
9357 if CodePeer_Mode
then
9360 -- Certain itypes are generated for contexts that cannot allocate
9361 -- objects and should not set primitive Finalize_Address.
9363 elsif Is_Itype
(Typ
)
9364 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
9365 N_Explicit_Dereference
9369 -- When an access type is declared after the incomplete view of a
9370 -- Taft-amendment type, the access type is considered pending in
9371 -- case the full view of the Taft-amendment type is controlled. If
9372 -- this is indeed the case, associate the Finalize_Address routine
9373 -- of the full view with the finalization masters of all pending
9374 -- access types. This scenario applies to anonymous access types as
9375 -- well. But the Finalize_Address routine is missing if the type is
9376 -- class-wide and we are under restriction No_Dispatching_Calls, see
9377 -- Expand_Freeze_Class_Wide_Type above for the rationale.
9379 elsif Needs_Finalization
(Typ
)
9380 and then (not Is_Class_Wide_Type
(Typ
)
9381 or else not Restriction_Active
(No_Dispatching_Calls
))
9382 and then Present
(Pending_Access_Types
(Typ
))
9384 E
:= First_Elmt
(Pending_Access_Types
(Typ
));
9385 while Present
(E
) loop
9388 -- Set_Finalize_Address
9389 -- (Ptr_Typ, <Typ>FD'Unrestricted_Access);
9391 Append_Freeze_Action
(Typ
,
9392 Make_Set_Finalize_Address_Call
9394 Ptr_Typ
=> Node
(E
)));
9399 end Process_Pending_Access_Types
;
9403 Def_Id
: constant Entity_Id
:= Entity
(N
);
9405 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
9406 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
9407 -- Save the Ghost-related attributes to restore on exit
9409 Result
: Boolean := False;
9411 -- Start of processing for Freeze_Type
9414 -- The type being frozen may be subject to pragma Ghost. Set the mode
9415 -- now to ensure that any nodes generated during freezing are properly
9418 Set_Ghost_Mode
(Def_Id
);
9420 -- Process any remote access-to-class-wide types designating the type
9423 Process_RACW_Types
(Def_Id
);
9425 -- Freeze processing for record types
9427 if Is_Record_Type
(Def_Id
) then
9428 if Ekind
(Def_Id
) = E_Record_Type
then
9429 Expand_Freeze_Record_Type
(N
);
9430 elsif Is_Class_Wide_Type
(Def_Id
) then
9431 Expand_Freeze_Class_Wide_Type
(N
);
9434 -- Freeze processing for array types
9436 elsif Is_Array_Type
(Def_Id
) then
9437 Expand_Freeze_Array_Type
(N
);
9439 -- Freeze processing for access types
9441 -- For pool-specific access types, find out the pool object used for
9442 -- this type, needs actual expansion of it in some cases. Here are the
9443 -- different cases :
9445 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
9446 -- ---> don't use any storage pool
9448 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
9450 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
9452 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
9453 -- ---> Storage Pool is the specified one
9455 -- See GNAT Pool packages in the Run-Time for more details
9457 elsif Ekind
(Def_Id
) in E_Access_Type | E_General_Access_Type
then
9459 Loc
: constant Source_Ptr
:= Sloc
(N
);
9460 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
9462 Freeze_Action_Typ
: Entity_Id
;
9463 Pool_Object
: Entity_Id
;
9468 -- Rep Clause "for Def_Id'Storage_Size use 0;"
9469 -- ---> don't use any storage pool
9471 if No_Pool_Assigned
(Def_Id
) then
9476 -- Rep Clause : for Def_Id'Storage_Size use Expr.
9478 -- Def_Id__Pool : Stack_Bounded_Pool
9479 -- (Expr, DT'Size, DT'Alignment);
9481 elsif Has_Storage_Size_Clause
(Def_Id
) then
9487 -- For unconstrained composite types we give a size of zero
9488 -- so that the pool knows that it needs a special algorithm
9489 -- for variable size object allocation.
9491 if Is_Composite_Type
(Desig_Type
)
9492 and then not Is_Constrained
(Desig_Type
)
9494 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
9495 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
9499 Make_Attribute_Reference
(Loc
,
9500 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
9501 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
9504 Make_Attribute_Reference
(Loc
,
9505 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
9506 Attribute_Name
=> Name_Alignment
);
9510 Make_Defining_Identifier
(Loc
,
9511 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
9513 -- We put the code associated with the pools in the entity
9514 -- that has the later freeze node, usually the access type
9515 -- but it can also be the designated_type; because the pool
9516 -- code requires both those types to be frozen
9518 if Is_Frozen
(Desig_Type
)
9519 and then (No
(Freeze_Node
(Desig_Type
))
9520 or else Analyzed
(Freeze_Node
(Desig_Type
)))
9522 Freeze_Action_Typ
:= Def_Id
;
9524 -- A Taft amendment type cannot get the freeze actions
9525 -- since the full view is not there.
9527 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
9528 and then No
(Full_View
(Desig_Type
))
9530 Freeze_Action_Typ
:= Def_Id
;
9533 Freeze_Action_Typ
:= Desig_Type
;
9536 Append_Freeze_Action
(Freeze_Action_Typ
,
9537 Make_Object_Declaration
(Loc
,
9538 Defining_Identifier
=> Pool_Object
,
9539 Object_Definition
=>
9540 Make_Subtype_Indication
(Loc
,
9543 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
9546 Make_Index_Or_Discriminant_Constraint
(Loc
,
9547 Constraints
=> New_List
(
9549 -- First discriminant is the Pool Size
9552 Storage_Size_Variable
(Def_Id
), Loc
),
9554 -- Second discriminant is the element size
9558 -- Third discriminant is the alignment
9563 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
9567 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
9568 -- ---> Storage Pool is the specified one
9570 -- When compiling in Ada 2012 mode, ensure that the accessibility
9571 -- level of the subpool access type is not deeper than that of the
9572 -- pool_with_subpools.
9574 elsif Ada_Version
>= Ada_2012
9575 and then Present
(Associated_Storage_Pool
(Def_Id
))
9576 and then RTU_Loaded
(System_Storage_Pools_Subpools
)
9579 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
9580 Pool
: constant Entity_Id
:=
9581 Associated_Storage_Pool
(Def_Id
);
9584 -- It is known that the accessibility level of the access
9585 -- type is deeper than that of the pool.
9587 if Type_Access_Level
(Def_Id
)
9588 > Static_Accessibility_Level
(Pool
, Object_Decl_Level
)
9589 and then Is_Class_Wide_Type
(Etype
(Pool
))
9590 and then not Accessibility_Checks_Suppressed
(Def_Id
)
9591 and then not Accessibility_Checks_Suppressed
(Pool
)
9593 -- When the pool is of a class-wide type, it may or may
9594 -- not support subpools depending on the path of
9595 -- derivation. Generate:
9597 -- if Def_Id in RSPWS'Class then
9598 -- raise Program_Error;
9601 Append_Freeze_Action
(Def_Id
,
9602 Make_If_Statement
(Loc
,
9605 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
9610 (RE_Root_Storage_Pool_With_Subpools
)),
9612 Then_Statements
=> New_List
(
9613 Make_Raise_Program_Error
(Loc
,
9614 Reason
=> PE_Accessibility_Check_Failed
))));
9619 -- For access-to-controlled types (including class-wide types and
9620 -- Taft-amendment types, which potentially have controlled
9621 -- components), expand the list controller object that will store
9622 -- the dynamically allocated objects. Don't do this transformation
9623 -- for expander-generated access types, except do it for types
9624 -- that are the full view of types derived from other private
9625 -- types and for access types used to implement indirect temps.
9626 -- Also suppress the list controller in the case of a designated
9627 -- type with convention Java, since this is used when binding to
9628 -- Java API specs, where there's no equivalent of a finalization
9629 -- list and we don't want to pull in the finalization support if
9632 if not Comes_From_Source
(Def_Id
)
9633 and then not Has_Private_Declaration
(Def_Id
)
9634 and then not Old_Attr_Util
.Indirect_Temps
9635 .Is_Access_Type_For_Indirect_Temp
(Def_Id
)
9639 -- An exception is made for types defined in the run-time because
9640 -- Ada.Tags.Tag itself is such a type and cannot afford this
9641 -- unnecessary overhead that would generates a loop in the
9642 -- expansion scheme. Another exception is if Restrictions
9643 -- (No_Finalization) is active, since then we know nothing is
9646 elsif Restriction_Active
(No_Finalization
)
9647 or else In_Runtime
(Def_Id
)
9651 -- Create a finalization master for an access-to-controlled type
9652 -- or an access-to-incomplete type. It is assumed that the full
9653 -- view will be controlled.
9655 elsif Needs_Finalization
(Desig_Type
)
9656 or else (Is_Incomplete_Type
(Desig_Type
)
9657 and then No
(Full_View
(Desig_Type
)))
9659 Build_Finalization_Master
(Def_Id
);
9661 -- Create a finalization master when the designated type contains
9662 -- a private component. It is assumed that the full view will be
9665 elsif Has_Private_Component
(Desig_Type
) then
9666 Build_Finalization_Master
9668 For_Private
=> True,
9669 Context_Scope
=> Scope
(Def_Id
),
9670 Insertion_Node
=> Declaration_Node
(Desig_Type
));
9674 -- Freeze processing for enumeration types
9676 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
9678 -- We only have something to do if we have a non-standard
9679 -- representation (i.e. at least one literal whose pos value
9680 -- is not the same as its representation)
9682 if Has_Non_Standard_Rep
(Def_Id
) then
9683 Expand_Freeze_Enumeration_Type
(N
);
9686 -- Private types that are completed by a derivation from a private
9687 -- type have an internally generated full view, that needs to be
9688 -- frozen. This must be done explicitly because the two views share
9689 -- the freeze node, and the underlying full view is not visible when
9690 -- the freeze node is analyzed.
9692 elsif Is_Private_Type
(Def_Id
)
9693 and then Is_Derived_Type
(Def_Id
)
9694 and then Present
(Full_View
(Def_Id
))
9695 and then Is_Itype
(Full_View
(Def_Id
))
9696 and then Has_Private_Declaration
(Full_View
(Def_Id
))
9697 and then Freeze_Node
(Full_View
(Def_Id
)) = N
9699 Set_Entity
(N
, Full_View
(Def_Id
));
9700 Result
:= Freeze_Type
(N
);
9701 Set_Entity
(N
, Def_Id
);
9703 -- All other types require no expander action. There are such cases
9704 -- (e.g. task types and protected types). In such cases, the freeze
9705 -- nodes are there for use by Gigi.
9709 -- Complete the initialization of all pending access types' finalization
9710 -- masters now that the designated type has been is frozen and primitive
9711 -- Finalize_Address generated.
9713 Process_Pending_Access_Types
(Def_Id
);
9714 Freeze_Stream_Operations
(N
, Def_Id
);
9716 -- Generate the [spec and] body of the invariant procedure tasked with
9717 -- the runtime verification of all invariants that pertain to the type.
9718 -- This includes invariants on the partial and full view, inherited
9719 -- class-wide invariants from parent types or interfaces, and invariants
9720 -- on array elements or record components. But skip internal types.
9722 if Is_Itype
(Def_Id
) then
9725 elsif Is_Interface
(Def_Id
) then
9727 -- Interfaces are treated as the partial view of a private type in
9728 -- order to achieve uniformity with the general case. As a result, an
9729 -- interface receives only a "partial" invariant procedure which is
9732 if Has_Own_Invariants
(Def_Id
) then
9733 Build_Invariant_Procedure_Body
9735 Partial_Invariant
=> Is_Interface
(Def_Id
));
9738 -- Non-interface types
9740 -- Do not generate invariant procedure within other assertion
9741 -- subprograms, which may involve local declarations of local
9742 -- subtypes to which these checks do not apply.
9745 if Has_Invariants
(Def_Id
) then
9746 if not Predicate_Check_In_Scope
(Def_Id
)
9747 or else (Ekind
(Current_Scope
) = E_Function
9748 and then Is_Predicate_Function
(Current_Scope
))
9752 Build_Invariant_Procedure_Body
(Def_Id
);
9756 -- Generate the [spec and] body of the procedure tasked with the
9757 -- run-time verification of pragma Default_Initial_Condition's
9760 if Has_DIC
(Def_Id
) then
9761 Build_DIC_Procedure_Body
(Def_Id
);
9765 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
9770 when RE_Not_Available
=>
9771 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
9776 -------------------------
9777 -- Get_Simple_Init_Val --
9778 -------------------------
9780 function Get_Simple_Init_Val
9783 Size
: Uint
:= No_Uint
) return Node_Id
9785 IV_Attribute
: constant Boolean :=
9786 Nkind
(N
) = N_Attribute_Reference
9787 and then Attribute_Name
(N
) = Name_Invalid_Value
;
9789 Loc
: constant Source_Ptr
:= Sloc
(N
);
9791 procedure Extract_Subtype_Bounds
9792 (Lo_Bound
: out Uint
;
9793 Hi_Bound
: out Uint
);
9794 -- Inspect subtype Typ as well its ancestor subtypes and derived types
9795 -- to determine the best known information about the bounds of the type.
9796 -- The output parameters are set as follows:
9798 -- * Lo_Bound - Set to No_Unit when there is no information available,
9799 -- or to the known low bound.
9801 -- * Hi_Bound - Set to No_Unit when there is no information available,
9802 -- or to the known high bound.
9804 function Simple_Init_Array_Type
return Node_Id
;
9805 -- Build an expression to initialize array type Typ
9807 function Simple_Init_Defaulted_Type
return Node_Id
;
9808 -- Build an expression to initialize type Typ which is subject to
9809 -- aspect Default_Value.
9811 function Simple_Init_Initialize_Scalars_Type
9812 (Size_To_Use
: Uint
) return Node_Id
;
9813 -- Build an expression to initialize scalar type Typ which is subject to
9814 -- pragma Initialize_Scalars. Size_To_Use is the size of the object.
9816 function Simple_Init_Normalize_Scalars_Type
9817 (Size_To_Use
: Uint
) return Node_Id
;
9818 -- Build an expression to initialize scalar type Typ which is subject to
9819 -- pragma Normalize_Scalars. Size_To_Use is the size of the object.
9821 function Simple_Init_Private_Type
return Node_Id
;
9822 -- Build an expression to initialize private type Typ
9824 function Simple_Init_Scalar_Type
return Node_Id
;
9825 -- Build an expression to initialize scalar type Typ
9827 ----------------------------
9828 -- Extract_Subtype_Bounds --
9829 ----------------------------
9831 procedure Extract_Subtype_Bounds
9832 (Lo_Bound
: out Uint
;
9833 Hi_Bound
: out Uint
)
9843 Lo_Bound
:= No_Uint
;
9844 Hi_Bound
:= No_Uint
;
9846 -- Loop to climb ancestor subtypes and derived types
9850 if not Is_Discrete_Type
(ST1
) then
9854 Lo
:= Type_Low_Bound
(ST1
);
9855 Hi
:= Type_High_Bound
(ST1
);
9857 if Compile_Time_Known_Value
(Lo
) then
9858 Lo_Val
:= Expr_Value
(Lo
);
9860 if No
(Lo_Bound
) or else Lo_Bound
< Lo_Val
then
9865 if Compile_Time_Known_Value
(Hi
) then
9866 Hi_Val
:= Expr_Value
(Hi
);
9868 if No
(Hi_Bound
) or else Hi_Bound
> Hi_Val
then
9873 ST2
:= Ancestor_Subtype
(ST1
);
9879 exit when ST1
= ST2
;
9882 end Extract_Subtype_Bounds
;
9884 ----------------------------
9885 -- Simple_Init_Array_Type --
9886 ----------------------------
9888 function Simple_Init_Array_Type
return Node_Id
is
9889 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
9891 function Simple_Init_Dimension
(Index
: Node_Id
) return Node_Id
;
9892 -- Initialize a single array dimension with index constraint Index
9894 --------------------
9895 -- Simple_Init_Dimension --
9896 --------------------
9898 function Simple_Init_Dimension
(Index
: Node_Id
) return Node_Id
is
9900 -- Process the current dimension
9902 if Present
(Index
) then
9904 -- Build a suitable "others" aggregate for the next dimension,
9905 -- or initialize the component itself. Generate:
9910 Make_Aggregate
(Loc
,
9911 Component_Associations
=> New_List
(
9912 Make_Component_Association
(Loc
,
9913 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
9915 Simple_Init_Dimension
(Next_Index
(Index
)))));
9917 -- Otherwise all dimensions have been processed. Initialize the
9918 -- component itself.
9925 Size
=> Esize
(Comp_Typ
));
9927 end Simple_Init_Dimension
;
9929 -- Start of processing for Simple_Init_Array_Type
9932 return Simple_Init_Dimension
(First_Index
(Typ
));
9933 end Simple_Init_Array_Type
;
9935 --------------------------------
9936 -- Simple_Init_Defaulted_Type --
9937 --------------------------------
9939 function Simple_Init_Defaulted_Type
return Node_Id
is
9940 Subtyp
: Entity_Id
:= First_Subtype
(Typ
);
9943 -- When the first subtype is private, retrieve the expression of the
9944 -- Default_Value from the underlying type.
9946 if Is_Private_Type
(Subtyp
) then
9947 Subtyp
:= Full_View
(Subtyp
);
9950 -- Use the Sloc of the context node when constructing the initial
9951 -- value because the expression of Default_Value may come from a
9952 -- different unit. Updating the Sloc will result in accurate error
9960 (Source
=> Default_Aspect_Value
(Subtyp
),
9962 end Simple_Init_Defaulted_Type
;
9964 -----------------------------------------
9965 -- Simple_Init_Initialize_Scalars_Type --
9966 -----------------------------------------
9968 function Simple_Init_Initialize_Scalars_Type
9969 (Size_To_Use
: Uint
) return Node_Id
9971 Float_Typ
: Entity_Id
;
9974 Scal_Typ
: Scalar_Id
;
9977 Extract_Subtype_Bounds
(Lo_Bound
, Hi_Bound
);
9981 if Is_Floating_Point_Type
(Typ
) then
9982 Float_Typ
:= Root_Type
(Typ
);
9984 if Float_Typ
= Standard_Short_Float
then
9985 Scal_Typ
:= Name_Short_Float
;
9986 elsif Float_Typ
= Standard_Float
then
9987 Scal_Typ
:= Name_Float
;
9988 elsif Float_Typ
= Standard_Long_Float
then
9989 Scal_Typ
:= Name_Long_Float
;
9990 else pragma Assert
(Float_Typ
= Standard_Long_Long_Float
);
9991 Scal_Typ
:= Name_Long_Long_Float
;
9994 -- If zero is invalid, it is a convenient value to use that is for
9995 -- sure an appropriate invalid value in all situations.
9997 elsif Present
(Lo_Bound
) and then Lo_Bound
> Uint_0
then
9998 return Make_Integer_Literal
(Loc
, 0);
10002 elsif Is_Unsigned_Type
(Typ
) then
10003 if Size_To_Use
<= 8 then
10004 Scal_Typ
:= Name_Unsigned_8
;
10005 elsif Size_To_Use
<= 16 then
10006 Scal_Typ
:= Name_Unsigned_16
;
10007 elsif Size_To_Use
<= 32 then
10008 Scal_Typ
:= Name_Unsigned_32
;
10009 elsif Size_To_Use
<= 64 then
10010 Scal_Typ
:= Name_Unsigned_64
;
10012 Scal_Typ
:= Name_Unsigned_128
;
10018 if Size_To_Use
<= 8 then
10019 Scal_Typ
:= Name_Signed_8
;
10020 elsif Size_To_Use
<= 16 then
10021 Scal_Typ
:= Name_Signed_16
;
10022 elsif Size_To_Use
<= 32 then
10023 Scal_Typ
:= Name_Signed_32
;
10024 elsif Size_To_Use
<= 64 then
10025 Scal_Typ
:= Name_Signed_64
;
10027 Scal_Typ
:= Name_Signed_128
;
10031 -- Use the values specified by pragma Initialize_Scalars or the ones
10032 -- provided by the binder. Higher precedence is given to the pragma.
10034 return Invalid_Scalar_Value
(Loc
, Scal_Typ
);
10035 end Simple_Init_Initialize_Scalars_Type
;
10037 ----------------------------------------
10038 -- Simple_Init_Normalize_Scalars_Type --
10039 ----------------------------------------
10041 function Simple_Init_Normalize_Scalars_Type
10042 (Size_To_Use
: Uint
) return Node_Id
10044 Signed_Size
: constant Uint
:= UI_Min
(Uint_63
, Size_To_Use
- 1);
10051 Extract_Subtype_Bounds
(Lo_Bound
, Hi_Bound
);
10053 -- If zero is invalid, it is a convenient value to use that is for
10054 -- sure an appropriate invalid value in all situations.
10056 if Present
(Lo_Bound
) and then Lo_Bound
> Uint_0
then
10057 Expr
:= Make_Integer_Literal
(Loc
, 0);
10059 -- Cases where all one bits is the appropriate invalid value
10061 -- For modular types, all 1 bits is either invalid or valid. If it
10062 -- is valid, then there is nothing that can be done since there are
10063 -- no invalid values (we ruled out zero already).
10065 -- For signed integer types that have no negative values, either
10066 -- there is room for negative values, or there is not. If there
10067 -- is, then all 1-bits may be interpreted as minus one, which is
10068 -- certainly invalid. Alternatively it is treated as the largest
10069 -- positive value, in which case the observation for modular types
10072 -- For float types, all 1-bits is a NaN (not a number), which is
10073 -- certainly an appropriately invalid value.
10075 elsif Is_Enumeration_Type
(Typ
)
10076 or else Is_Floating_Point_Type
(Typ
)
10077 or else Is_Unsigned_Type
(Typ
)
10079 Expr
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
10081 -- Resolve as Long_Long_Long_Unsigned, because the largest number
10082 -- we can generate is out of range of universal integer.
10084 Analyze_And_Resolve
(Expr
, Standard_Long_Long_Long_Unsigned
);
10086 -- Case of signed types
10089 -- Normally we like to use the most negative number. The one
10090 -- exception is when this number is in the known subtype range and
10091 -- the largest positive number is not in the known subtype range.
10093 -- For this exceptional case, use largest positive value
10095 if Present
(Lo_Bound
) and then Present
(Hi_Bound
)
10096 and then Lo_Bound
<= (-(2 ** Signed_Size
))
10097 and then Hi_Bound
< 2 ** Signed_Size
10099 Expr
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
10101 -- Normal case of largest negative value
10104 Expr
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
10109 end Simple_Init_Normalize_Scalars_Type
;
10111 ------------------------------
10112 -- Simple_Init_Private_Type --
10113 ------------------------------
10115 function Simple_Init_Private_Type
return Node_Id
is
10116 Under_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
10120 -- The availability of the underlying view must be checked by routine
10121 -- Needs_Simple_Initialization.
10123 pragma Assert
(Present
(Under_Typ
));
10125 Expr
:= Get_Simple_Init_Val
(Under_Typ
, N
, Size
);
10127 -- If the initial value is null or an aggregate, qualify it with the
10128 -- underlying type in order to provide a proper context.
10130 if Nkind
(Expr
) in N_Aggregate | N_Null
then
10132 Make_Qualified_Expression
(Loc
,
10133 Subtype_Mark
=> New_Occurrence_Of
(Under_Typ
, Loc
),
10134 Expression
=> Expr
);
10137 Expr
:= Unchecked_Convert_To
(Typ
, Expr
);
10139 -- Do not truncate the result when scalar types are involved and
10140 -- Initialize/Normalize_Scalars is in effect.
10142 if Nkind
(Expr
) = N_Unchecked_Type_Conversion
10143 and then Is_Scalar_Type
(Under_Typ
)
10145 Set_No_Truncation
(Expr
);
10149 end Simple_Init_Private_Type
;
10151 -----------------------------
10152 -- Simple_Init_Scalar_Type --
10153 -----------------------------
10155 function Simple_Init_Scalar_Type
return Node_Id
is
10157 Size_To_Use
: Uint
;
10160 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
10162 -- Determine the size of the object. This is either the size provided
10163 -- by the caller, or the Esize of the scalar type.
10165 if No
(Size
) or else Size
<= Uint_0
then
10166 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(Typ
));
10168 Size_To_Use
:= Size
;
10171 -- The maximum size to use is System_Max_Integer_Size bits. This
10172 -- will create values of type Long_Long_Long_Unsigned and the range
10173 -- must fit this type.
10175 if Present
(Size_To_Use
)
10176 and then Size_To_Use
> System_Max_Integer_Size
10178 Size_To_Use
:= UI_From_Int
(System_Max_Integer_Size
);
10181 if Normalize_Scalars
and then not IV_Attribute
then
10182 Expr
:= Simple_Init_Normalize_Scalars_Type
(Size_To_Use
);
10184 Expr
:= Simple_Init_Initialize_Scalars_Type
(Size_To_Use
);
10187 -- The final expression is obtained by doing an unchecked conversion
10188 -- of this result to the base type of the required subtype. Use the
10189 -- base type to prevent the unchecked conversion from chopping bits,
10190 -- and then we set Kill_Range_Check to preserve the "bad" value.
10192 Expr
:= Unchecked_Convert_To
(Base_Type
(Typ
), Expr
);
10194 -- Ensure that the expression is not truncated since the "bad" bits
10195 -- are desired, and also kill the range checks.
10197 if Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
10198 Set_Kill_Range_Check
(Expr
);
10199 Set_No_Truncation
(Expr
);
10203 end Simple_Init_Scalar_Type
;
10205 -- Start of processing for Get_Simple_Init_Val
10208 if Is_Private_Type
(Typ
) then
10209 return Simple_Init_Private_Type
;
10211 elsif Is_Scalar_Type
(Typ
) then
10212 if Has_Default_Aspect
(Typ
) then
10213 return Simple_Init_Defaulted_Type
;
10215 return Simple_Init_Scalar_Type
;
10218 -- Array type with Initialize or Normalize_Scalars
10220 elsif Is_Array_Type
(Typ
) then
10221 pragma Assert
(Init_Or_Norm_Scalars
);
10222 return Simple_Init_Array_Type
;
10224 -- Access type is initialized to null
10226 elsif Is_Access_Type
(Typ
) then
10227 return Make_Null
(Loc
);
10229 -- No other possibilities should arise, since we should only be calling
10230 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
10231 -- indicating one of the above cases held.
10234 raise Program_Error
;
10238 when RE_Not_Available
=>
10240 end Get_Simple_Init_Val
;
10242 ------------------------------
10243 -- Has_New_Non_Standard_Rep --
10244 ------------------------------
10246 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
10248 if not Is_Derived_Type
(T
) then
10249 return Has_Non_Standard_Rep
(T
)
10250 or else Has_Non_Standard_Rep
(Root_Type
(T
));
10252 -- If Has_Non_Standard_Rep is not set on the derived type, the
10253 -- representation is fully inherited.
10255 elsif not Has_Non_Standard_Rep
(T
) then
10259 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
10261 -- May need a more precise check here: the First_Rep_Item may be a
10262 -- stream attribute, which does not affect the representation of the
10266 end Has_New_Non_Standard_Rep
;
10268 ----------------------
10269 -- Inline_Init_Proc --
10270 ----------------------
10272 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean is
10274 -- The initialization proc of protected records is not worth inlining.
10275 -- In addition, when compiled for another unit for inlining purposes,
10276 -- it may make reference to entities that have not been elaborated yet.
10277 -- The initialization proc of records that need finalization contains
10278 -- a nested clean-up procedure that makes it impractical to inline as
10279 -- well, except for simple controlled types themselves. And similar
10280 -- considerations apply to task types.
10282 if Is_Concurrent_Type
(Typ
) then
10285 elsif Needs_Finalization
(Typ
) and then not Is_Controlled
(Typ
) then
10288 elsif Has_Task
(Typ
) then
10294 end Inline_Init_Proc
;
10300 function In_Runtime
(E
: Entity_Id
) return Boolean is
10305 while Scope
(S1
) /= Standard_Standard
loop
10309 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
10312 package body Initialization_Control
is
10314 ------------------------
10315 -- Requires_Late_Init --
10316 ------------------------
10318 function Requires_Late_Init
10320 Rec_Type
: Entity_Id
) return Boolean
10322 References_Current_Instance
: Boolean := False;
10323 Has_Access_Discriminant
: Boolean := False;
10324 Has_Internal_Call
: Boolean := False;
10326 function Find_Access_Discriminant
10327 (N
: Node_Id
) return Traverse_Result
;
10328 -- Look for a name denoting an access discriminant
10330 function Find_Current_Instance
10331 (N
: Node_Id
) return Traverse_Result
;
10332 -- Look for a reference to the current instance of the type
10334 function Find_Internal_Call
10335 (N
: Node_Id
) return Traverse_Result
;
10336 -- Look for an internal protected function call
10338 ------------------------------
10339 -- Find_Access_Discriminant --
10340 ------------------------------
10342 function Find_Access_Discriminant
10343 (N
: Node_Id
) return Traverse_Result
is
10345 if Is_Entity_Name
(N
)
10346 and then Denotes_Discriminant
(N
)
10347 and then Is_Access_Type
(Etype
(N
))
10349 Has_Access_Discriminant
:= True;
10354 end Find_Access_Discriminant
;
10356 ---------------------------
10357 -- Find_Current_Instance --
10358 ---------------------------
10360 function Find_Current_Instance
10361 (N
: Node_Id
) return Traverse_Result
is
10363 if Is_Entity_Name
(N
)
10364 and then Present
(Entity
(N
))
10365 and then Is_Current_Instance
(N
)
10367 References_Current_Instance
:= True;
10372 end Find_Current_Instance
;
10374 ------------------------
10375 -- Find_Internal_Call --
10376 ------------------------
10378 function Find_Internal_Call
(N
: Node_Id
) return Traverse_Result
is
10380 function Call_Scope
(N
: Node_Id
) return Entity_Id
;
10381 -- Return the scope enclosing a given call node N
10387 function Call_Scope
(N
: Node_Id
) return Entity_Id
is
10388 Nam
: constant Node_Id
:= Name
(N
);
10390 if Nkind
(Nam
) = N_Selected_Component
then
10391 return Scope
(Entity
(Prefix
(Nam
)));
10393 return Scope
(Entity
(Nam
));
10398 if Nkind
(N
) = N_Function_Call
10399 and then Call_Scope
(N
)
10400 = Corresponding_Concurrent_Type
(Rec_Type
)
10402 Has_Internal_Call
:= True;
10407 end Find_Internal_Call
;
10409 procedure Search_Access_Discriminant
is new
10410 Traverse_Proc
(Find_Access_Discriminant
);
10412 procedure Search_Current_Instance
is new
10413 Traverse_Proc
(Find_Current_Instance
);
10415 procedure Search_Internal_Call
is new
10416 Traverse_Proc
(Find_Internal_Call
);
10418 -- Start of processing for Requires_Late_Init
10421 -- A component of an object is said to require late initialization
10424 -- it has an access discriminant value constrained by a per-object
10427 if Has_Access_Constraint
(Defining_Identifier
(Decl
))
10428 and then No
(Expression
(Decl
))
10432 elsif Present
(Expression
(Decl
)) then
10434 -- it has an initialization expression that includes a name
10435 -- denoting an access discriminant;
10437 Search_Access_Discriminant
(Expression
(Decl
));
10439 if Has_Access_Discriminant
then
10443 -- or it has an initialization expression that includes a
10444 -- reference to the current instance of the type either by
10447 Search_Current_Instance
(Expression
(Decl
));
10449 if References_Current_Instance
then
10453 -- ...or implicitly as the target object of a call.
10455 if Is_Protected_Record_Type
(Rec_Type
) then
10456 Search_Internal_Call
(Expression
(Decl
));
10458 if Has_Internal_Call
then
10465 end Requires_Late_Init
;
10467 -----------------------------
10468 -- Has_Late_Init_Component --
10469 -----------------------------
10471 function Has_Late_Init_Component
10472 (Tagged_Rec_Type
: Entity_Id
) return Boolean
10474 Comp_Id
: Entity_Id
:=
10475 First_Component
(Implementation_Base_Type
(Tagged_Rec_Type
));
10477 while Present
(Comp_Id
) loop
10478 if Requires_Late_Init
(Decl
=> Parent
(Comp_Id
),
10479 Rec_Type
=> Tagged_Rec_Type
)
10481 return True; -- found a component that requires late init
10483 elsif Chars
(Comp_Id
) = Name_uParent
10484 and then Has_Late_Init_Component
(Etype
(Comp_Id
))
10486 return True; -- an ancestor type has a late init component
10489 Next_Component
(Comp_Id
);
10493 end Has_Late_Init_Component
;
10495 ------------------------
10496 -- Tag_Init_Condition --
10497 ------------------------
10499 function Tag_Init_Condition
10501 Init_Control_Formal
: Entity_Id
) return Node_Id
is
10503 return Make_Op_Eq
(Loc
,
10504 New_Occurrence_Of
(Init_Control_Formal
, Loc
),
10505 Make_Mode_Literal
(Loc
, Full_Init
));
10506 end Tag_Init_Condition
;
10508 --------------------------
10509 -- Early_Init_Condition --
10510 --------------------------
10512 function Early_Init_Condition
10514 Init_Control_Formal
: Entity_Id
) return Node_Id
is
10516 return Make_Op_Ne
(Loc
,
10517 New_Occurrence_Of
(Init_Control_Formal
, Loc
),
10518 Make_Mode_Literal
(Loc
, Late_Init_Only
));
10519 end Early_Init_Condition
;
10521 -------------------------
10522 -- Late_Init_Condition --
10523 -------------------------
10525 function Late_Init_Condition
10527 Init_Control_Formal
: Entity_Id
) return Node_Id
is
10529 return Make_Op_Ne
(Loc
,
10530 New_Occurrence_Of
(Init_Control_Formal
, Loc
),
10531 Make_Mode_Literal
(Loc
, Early_Init_Only
));
10532 end Late_Init_Condition
;
10534 end Initialization_Control
;
10536 ----------------------------
10537 -- Initialization_Warning --
10538 ----------------------------
10540 procedure Initialization_Warning
(E
: Entity_Id
) is
10541 Warning_Needed
: Boolean;
10544 Warning_Needed
:= False;
10546 if Ekind
(Current_Scope
) = E_Package
10547 and then Static_Elaboration_Desired
(Current_Scope
)
10549 if Is_Type
(E
) then
10550 if Is_Record_Type
(E
) then
10551 if Has_Discriminants
(E
)
10552 or else Is_Limited_Type
(E
)
10553 or else Has_Non_Standard_Rep
(E
)
10555 Warning_Needed
:= True;
10558 -- Verify that at least one component has an initialization
10559 -- expression. No need for a warning on a type if all its
10560 -- components have no initialization.
10566 Comp
:= First_Component
(E
);
10567 while Present
(Comp
) loop
10569 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
);
10571 if Present
(Expression
(Parent
(Comp
))) then
10572 Warning_Needed
:= True;
10576 Next_Component
(Comp
);
10581 if Warning_Needed
then
10583 ("objects of the type cannot be initialized statically "
10584 & "by default??", Parent
(E
));
10589 Error_Msg_N
("object cannot be initialized statically??", E
);
10592 end Initialization_Warning
;
10598 function Init_Formals
(Typ
: Entity_Id
; Proc_Id
: Entity_Id
) return List_Id
10600 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
10601 Unc_Arr
: constant Boolean :=
10602 Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
);
10603 With_Prot
: constant Boolean :=
10604 Has_Protected
(Typ
)
10605 or else (Is_Record_Type
(Typ
)
10606 and then Is_Protected_Record_Type
(Typ
));
10607 With_Task
: constant Boolean :=
10608 not Global_No_Tasking
10611 or else (Is_Record_Type
(Typ
)
10612 and then Is_Task_Record_Type
(Typ
)));
10616 -- The first parameter is always _Init : [in] out Typ. Note that we need
10617 -- it to be in/out in the case of an unconstrained array, because of the
10618 -- need to have the bounds, and in the case of protected or task record
10619 -- value, because there are default record fields that may be referenced
10620 -- in the generated initialization routine.
10622 Formals
:= New_List
(
10623 Make_Parameter_Specification
(Loc
,
10624 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
10625 In_Present
=> Unc_Arr
or else With_Prot
or else With_Task
,
10626 Out_Present
=> True,
10627 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
10629 -- For task record value, or type that contains tasks, add two more
10630 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
10631 -- We also add these parameters for the task record type case.
10634 Append_To
(Formals
,
10635 Make_Parameter_Specification
(Loc
,
10636 Defining_Identifier
=>
10637 Make_Defining_Identifier
(Loc
, Name_uMaster
),
10639 New_Occurrence_Of
(Standard_Integer
, Loc
)));
10641 Set_Has_Master_Entity
(Proc_Id
);
10643 -- Add _Chain (not done for sequential elaboration policy, see
10644 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
10646 if Partition_Elaboration_Policy
/= 'S' then
10647 Append_To
(Formals
,
10648 Make_Parameter_Specification
(Loc
,
10649 Defining_Identifier
=>
10650 Make_Defining_Identifier
(Loc
, Name_uChain
),
10651 In_Present
=> True,
10652 Out_Present
=> True,
10654 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
10657 Append_To
(Formals
,
10658 Make_Parameter_Specification
(Loc
,
10659 Defining_Identifier
=>
10660 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
10661 In_Present
=> True,
10662 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
10665 -- Due to certain edge cases such as arrays with null-excluding
10666 -- components being built with the secondary stack it becomes necessary
10667 -- to add a formal to the Init_Proc which controls whether we raise
10668 -- Constraint_Errors on generated calls for internal object
10671 if Needs_Conditional_Null_Excluding_Check
(Typ
) then
10672 Append_To
(Formals
,
10673 Make_Parameter_Specification
(Loc
,
10674 Defining_Identifier
=>
10675 Make_Defining_Identifier
(Loc
,
10676 New_External_Name
(Chars
10677 (Component_Type
(Typ
)), "_skip_null_excluding_check")),
10678 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
),
10679 In_Present
=> True,
10681 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
10687 when RE_Not_Available
=>
10691 -------------------------
10692 -- Init_Secondary_Tags --
10693 -------------------------
10695 procedure Init_Secondary_Tags
10698 Init_Tags_List
: List_Id
;
10699 Stmts_List
: List_Id
;
10700 Fixed_Comps
: Boolean := True;
10701 Variable_Comps
: Boolean := True)
10703 Loc
: constant Source_Ptr
:= Sloc
(Target
);
10705 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
10706 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
10708 procedure Initialize_Tag
10711 Tag_Comp
: Entity_Id
;
10712 Iface_Tag
: Node_Id
);
10713 -- Initialize the tag of the secondary dispatch table of Typ associated
10714 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
10715 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
10716 -- of Typ CPP tagged type we generate code to inherit the contents of
10717 -- the dispatch table directly from the ancestor.
10719 --------------------
10720 -- Initialize_Tag --
10721 --------------------
10723 procedure Initialize_Tag
10726 Tag_Comp
: Entity_Id
;
10727 Iface_Tag
: Node_Id
)
10729 Comp_Typ
: Entity_Id
;
10730 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
10733 -- Initialize pointer to secondary DT associated with the interface
10735 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
10736 Append_To
(Init_Tags_List
,
10737 Make_Assignment_Statement
(Loc
,
10739 Make_Selected_Component
(Loc
,
10740 Prefix
=> New_Copy_Tree
(Target
),
10741 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
10743 New_Occurrence_Of
(Iface_Tag
, Loc
)));
10746 Comp_Typ
:= Scope
(Tag_Comp
);
10748 -- Initialize the entries of the table of interfaces. We generate a
10749 -- different call when the parent of the type has variable size
10752 if Comp_Typ
/= Etype
(Comp_Typ
)
10753 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
10754 and then Chars
(Tag_Comp
) /= Name_uTag
10756 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
10758 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
10759 -- configurable run-time environment.
10761 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
10763 ("variable size record with interface types", Typ
);
10768 -- Set_Dynamic_Offset_To_Top
10770 -- Prim_T => Typ'Tag,
10771 -- Interface_T => Iface'Tag,
10772 -- Offset_Value => n,
10773 -- Offset_Func => Fn'Unrestricted_Access)
10775 Append_To
(Stmts_List
,
10776 Make_Procedure_Call_Statement
(Loc
,
10778 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
10779 Parameter_Associations
=> New_List
(
10780 Make_Attribute_Reference
(Loc
,
10781 Prefix
=> New_Copy_Tree
(Target
),
10782 Attribute_Name
=> Name_Address
),
10784 Unchecked_Convert_To
(RTE
(RE_Tag
),
10786 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)),
10788 Unchecked_Convert_To
(RTE
(RE_Tag
),
10790 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
10793 Unchecked_Convert_To
10794 (RTE
(RE_Storage_Offset
),
10795 Make_Op_Minus
(Loc
,
10796 Make_Attribute_Reference
(Loc
,
10798 Make_Selected_Component
(Loc
,
10799 Prefix
=> New_Copy_Tree
(Target
),
10801 New_Occurrence_Of
(Tag_Comp
, Loc
)),
10802 Attribute_Name
=> Name_Position
))),
10804 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
10805 Make_Attribute_Reference
(Loc
,
10806 Prefix
=> New_Occurrence_Of
10807 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
10808 Attribute_Name
=> Name_Unrestricted_Access
)))));
10810 -- In this case the next component stores the value of the offset
10813 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
10814 pragma Assert
(Present
(Offset_To_Top_Comp
));
10816 Append_To
(Init_Tags_List
,
10817 Make_Assignment_Statement
(Loc
,
10819 Make_Selected_Component
(Loc
,
10820 Prefix
=> New_Copy_Tree
(Target
),
10822 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
10825 Make_Op_Minus
(Loc
,
10826 Make_Attribute_Reference
(Loc
,
10828 Make_Selected_Component
(Loc
,
10829 Prefix
=> New_Copy_Tree
(Target
),
10830 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
10831 Attribute_Name
=> Name_Position
))));
10833 -- Normal case: No discriminants in the parent type
10836 -- Don't need to set any value if the offset-to-top field is
10837 -- statically set or if this interface shares the primary
10840 if not Building_Static_Secondary_DT
(Typ
)
10841 and then not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True)
10843 Append_To
(Stmts_List
,
10844 Build_Set_Static_Offset_To_Top
(Loc
,
10845 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
10847 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
10848 Make_Op_Minus
(Loc
,
10849 Make_Attribute_Reference
(Loc
,
10851 Make_Selected_Component
(Loc
,
10852 Prefix
=> New_Copy_Tree
(Target
),
10854 New_Occurrence_Of
(Tag_Comp
, Loc
)),
10855 Attribute_Name
=> Name_Position
)))));
10859 -- Register_Interface_Offset
10860 -- (Prim_T => Typ'Tag,
10861 -- Interface_T => Iface'Tag,
10862 -- Is_Constant => True,
10863 -- Offset_Value => n,
10864 -- Offset_Func => null);
10866 if not Building_Static_Secondary_DT
(Typ
)
10867 and then RTE_Available
(RE_Register_Interface_Offset
)
10869 Append_To
(Stmts_List
,
10870 Make_Procedure_Call_Statement
(Loc
,
10873 (RTE
(RE_Register_Interface_Offset
), Loc
),
10874 Parameter_Associations
=> New_List
(
10875 Unchecked_Convert_To
(RTE
(RE_Tag
),
10877 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)),
10879 Unchecked_Convert_To
(RTE
(RE_Tag
),
10881 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
10883 New_Occurrence_Of
(Standard_True
, Loc
),
10885 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
10886 Make_Op_Minus
(Loc
,
10887 Make_Attribute_Reference
(Loc
,
10889 Make_Selected_Component
(Loc
,
10890 Prefix
=> New_Copy_Tree
(Target
),
10892 New_Occurrence_Of
(Tag_Comp
, Loc
)),
10893 Attribute_Name
=> Name_Position
))),
10895 Make_Null
(Loc
))));
10898 end Initialize_Tag
;
10902 Full_Typ
: Entity_Id
;
10903 Ifaces_List
: Elist_Id
;
10904 Ifaces_Comp_List
: Elist_Id
;
10905 Ifaces_Tag_List
: Elist_Id
;
10906 Iface_Elmt
: Elmt_Id
;
10907 Iface_Comp_Elmt
: Elmt_Id
;
10908 Iface_Tag_Elmt
: Elmt_Id
;
10909 Tag_Comp
: Node_Id
;
10910 In_Variable_Pos
: Boolean;
10912 -- Start of processing for Init_Secondary_Tags
10915 -- Handle private types
10917 if Present
(Full_View
(Typ
)) then
10918 Full_Typ
:= Full_View
(Typ
);
10923 Collect_Interfaces_Info
10924 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
10926 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10927 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
10928 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
10929 while Present
(Iface_Elmt
) loop
10930 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
10932 -- Check if parent of record type has variable size components
10934 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
10935 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
10937 -- If we are compiling under the CPP full ABI compatibility mode and
10938 -- the ancestor is a CPP_Pragma tagged type then we generate code to
10939 -- initialize the secondary tag components from tags that reference
10940 -- secondary tables filled with copy of parent slots.
10942 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
10944 -- Reject interface components located at variable offset in
10945 -- C++ derivations. This is currently unsupported.
10947 if not Fixed_Comps
and then In_Variable_Pos
then
10949 -- Locate the first dynamic component of the record. Done to
10950 -- improve the text of the warning.
10954 Comp_Typ
: Entity_Id
;
10957 Comp
:= First_Entity
(Typ
);
10958 while Present
(Comp
) loop
10959 Comp_Typ
:= Etype
(Comp
);
10961 if Ekind
(Comp
) /= E_Discriminant
10962 and then not Is_Tag
(Comp
)
10965 (Is_Record_Type
(Comp_Typ
)
10967 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
10969 (Is_Array_Type
(Comp_Typ
)
10970 and then Is_Variable_Size_Array
(Comp_Typ
));
10973 Next_Entity
(Comp
);
10976 pragma Assert
(Present
(Comp
));
10978 -- Move this check to sem???
10979 Error_Msg_Node_2
:= Comp
;
10981 ("parent type & with dynamic component & cannot be parent"
10982 & " of 'C'P'P derivation if new interfaces are present",
10983 Typ
, Scope
(Original_Record_Component
(Comp
)));
10986 Sloc
(Scope
(Original_Record_Component
(Comp
)));
10988 ("type derived from 'C'P'P type & defined #",
10989 Typ
, Scope
(Original_Record_Component
(Comp
)));
10991 -- Avoid duplicated warnings
10996 -- Initialize secondary tags
11001 Iface
=> Node
(Iface_Elmt
),
11002 Tag_Comp
=> Tag_Comp
,
11003 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
11006 -- Otherwise generate code to initialize the tag
11009 if (In_Variable_Pos
and then Variable_Comps
)
11010 or else (not In_Variable_Pos
and then Fixed_Comps
)
11014 Iface
=> Node
(Iface_Elmt
),
11015 Tag_Comp
=> Tag_Comp
,
11016 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
11020 Next_Elmt
(Iface_Elmt
);
11021 Next_Elmt
(Iface_Comp_Elmt
);
11022 Next_Elmt
(Iface_Tag_Elmt
);
11024 end Init_Secondary_Tags
;
11026 ----------------------------
11027 -- Is_Null_Statement_List --
11028 ----------------------------
11030 function Is_Null_Statement_List
(Stmts
: List_Id
) return Boolean is
11034 -- We must skip SCIL nodes because they may have been added to the list
11035 -- by Insert_Actions.
11037 Stmt
:= First_Non_SCIL_Node
(Stmts
);
11038 while Present
(Stmt
) loop
11039 if Nkind
(Stmt
) = N_Case_Statement
then
11043 Alt
:= First
(Alternatives
(Stmt
));
11044 while Present
(Alt
) loop
11045 if not Is_Null_Statement_List
(Statements
(Alt
)) then
11053 elsif Nkind
(Stmt
) /= N_Null_Statement
then
11057 Stmt
:= Next_Non_SCIL_Node
(Stmt
);
11061 end Is_Null_Statement_List
;
11063 ----------------------------------------
11064 -- Make_Controlling_Function_Wrappers --
11065 ----------------------------------------
11067 procedure Make_Controlling_Function_Wrappers
11068 (Tag_Typ
: Entity_Id
;
11069 Decl_List
: out List_Id
;
11070 Body_List
: out List_Id
)
11072 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
11074 function Make_Wrapper_Specification
(Subp
: Entity_Id
) return Node_Id
;
11075 -- Returns a function specification with the same profile as Subp
11077 --------------------------------
11078 -- Make_Wrapper_Specification --
11079 --------------------------------
11081 function Make_Wrapper_Specification
(Subp
: Entity_Id
) return Node_Id
is
11084 Make_Function_Specification
(Loc
,
11085 Defining_Unit_Name
=>
11086 Make_Defining_Identifier
(Loc
,
11087 Chars
=> Chars
(Subp
)),
11088 Parameter_Specifications
=>
11089 Copy_Parameter_List
(Subp
),
11090 Result_Definition
=>
11091 New_Occurrence_Of
(Etype
(Subp
), Loc
));
11092 end Make_Wrapper_Specification
;
11094 Prim_Elmt
: Elmt_Id
;
11096 Actual_List
: List_Id
;
11097 Formal
: Entity_Id
;
11098 Par_Formal
: Entity_Id
;
11099 Ext_Aggr
: Node_Id
;
11100 Formal_Node
: Node_Id
;
11101 Func_Body
: Node_Id
;
11102 Func_Decl
: Node_Id
;
11103 Func_Id
: Entity_Id
;
11105 -- Start of processing for Make_Controlling_Function_Wrappers
11108 Decl_List
:= New_List
;
11109 Body_List
:= New_List
;
11111 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
11112 while Present
(Prim_Elmt
) loop
11113 Subp
:= Node
(Prim_Elmt
);
11115 -- If a primitive function with a controlling result of the type has
11116 -- not been overridden by the user, then we must create a wrapper
11117 -- function here that effectively overrides it and invokes the
11118 -- (non-abstract) parent function. This can only occur for a null
11119 -- extension. Note that functions with anonymous controlling access
11120 -- results don't qualify and must be overridden. We also exclude
11121 -- Input attributes, since each type will have its own version of
11122 -- Input constructed by the expander. The test for Comes_From_Source
11123 -- is needed to distinguish inherited operations from renamings
11124 -- (which also have Alias set). We exclude internal entities with
11125 -- Interface_Alias to avoid generating duplicated wrappers since
11126 -- the primitive which covers the interface is also available in
11127 -- the list of primitive operations.
11129 -- The function may be abstract, or require_Overriding may be set
11130 -- for it, because tests for null extensions may already have reset
11131 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
11132 -- set, functions that need wrappers are recognized by having an
11133 -- alias that returns the parent type.
11135 if Comes_From_Source
(Subp
)
11136 or else No
(Alias
(Subp
))
11137 or else Present
(Interface_Alias
(Subp
))
11138 or else Ekind
(Subp
) /= E_Function
11139 or else not Has_Controlling_Result
(Subp
)
11140 or else Is_Access_Type
(Etype
(Subp
))
11141 or else Is_Abstract_Subprogram
(Alias
(Subp
))
11142 or else Is_TSS
(Subp
, TSS_Stream_Input
)
11146 elsif Is_Abstract_Subprogram
(Subp
)
11147 or else Requires_Overriding
(Subp
)
11149 (Is_Null_Extension
(Etype
(Subp
))
11150 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
11152 -- If there is a non-overloadable homonym in the current
11153 -- scope, the implicit declaration remains invisible.
11154 -- We check the current entity with the same name, or its
11155 -- homonym in case the derivation takes place after the
11156 -- hiding object declaration.
11158 if Present
(Current_Entity
(Subp
)) then
11160 Curr
: constant Entity_Id
:= Current_Entity
(Subp
);
11161 Prev
: constant Entity_Id
:= Homonym
(Curr
);
11163 if (Comes_From_Source
(Curr
)
11164 and then Scope
(Curr
) = Current_Scope
11165 and then not Is_Overloadable
(Curr
))
11168 and then Comes_From_Source
(Prev
)
11169 and then Scope
(Prev
) = Current_Scope
11170 and then not Is_Overloadable
(Prev
))
11178 Make_Subprogram_Declaration
(Loc
,
11179 Specification
=> Make_Wrapper_Specification
(Subp
));
11181 Append_To
(Decl_List
, Func_Decl
);
11183 -- Build a wrapper body that calls the parent function. The body
11184 -- contains a single return statement that returns an extension
11185 -- aggregate whose ancestor part is a call to the parent function,
11186 -- passing the formals as actuals (with any controlling arguments
11187 -- converted to the types of the corresponding formals of the
11188 -- parent function, which might be anonymous access types), and
11189 -- having a null extension.
11191 Formal
:= First_Formal
(Subp
);
11192 Par_Formal
:= First_Formal
(Alias
(Subp
));
11194 First
(Parameter_Specifications
(Specification
(Func_Decl
)));
11196 if Present
(Formal
) then
11197 Actual_List
:= New_List
;
11199 while Present
(Formal
) loop
11200 if Is_Controlling_Formal
(Formal
) then
11201 Append_To
(Actual_List
,
11202 Make_Type_Conversion
(Loc
,
11204 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
11207 (Defining_Identifier
(Formal_Node
), Loc
)));
11212 (Defining_Identifier
(Formal_Node
), Loc
));
11215 Next_Formal
(Formal
);
11216 Next_Formal
(Par_Formal
);
11217 Next
(Formal_Node
);
11220 Actual_List
:= No_List
;
11224 Make_Extension_Aggregate
(Loc
,
11226 Make_Function_Call
(Loc
,
11228 New_Occurrence_Of
(Alias
(Subp
), Loc
),
11229 Parameter_Associations
=> Actual_List
),
11230 Null_Record_Present
=> True);
11232 -- GNATprove will use expression of an expression function as an
11233 -- implicit postcondition. GNAT will also benefit from expression
11234 -- function to avoid premature freezing, but would struggle if we
11235 -- added an expression function to freezing actions, so we create
11236 -- the expanded form directly.
11238 if GNATprove_Mode
then
11240 Make_Expression_Function
(Loc
,
11242 Make_Wrapper_Specification
(Subp
),
11243 Expression
=> Ext_Aggr
);
11246 Make_Subprogram_Body
(Loc
,
11248 Make_Wrapper_Specification
(Subp
),
11249 Declarations
=> Empty_List
,
11250 Handled_Statement_Sequence
=>
11251 Make_Handled_Sequence_Of_Statements
(Loc
,
11252 Statements
=> New_List
(
11253 Make_Simple_Return_Statement
(Loc
,
11254 Expression
=> Ext_Aggr
))));
11255 Set_Was_Expression_Function
(Func_Body
);
11258 Append_To
(Body_List
, Func_Body
);
11260 -- Replace the inherited function with the wrapper function in the
11261 -- primitive operations list. We add the minimum decoration needed
11262 -- to override interface primitives.
11264 Func_Id
:= Defining_Unit_Name
(Specification
(Func_Decl
));
11266 Mutate_Ekind
(Func_Id
, E_Function
);
11267 Set_Is_Wrapper
(Func_Id
);
11269 -- Corresponding_Spec will be set again to the same value during
11270 -- analysis, but we need this information earlier.
11271 -- Expand_N_Freeze_Entity needs to know whether a subprogram body
11272 -- is a wrapper's body in order to get check suppression right.
11274 Set_Corresponding_Spec
(Func_Body
, Func_Id
);
11278 Next_Elmt
(Prim_Elmt
);
11280 end Make_Controlling_Function_Wrappers
;
11286 function Make_Eq_Body
11288 Eq_Name
: Name_Id
) return Node_Id
11290 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
11292 Def
: constant Node_Id
:= Parent
(Typ
);
11293 Stmts
: constant List_Id
:= New_List
;
11294 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
11295 Comps
: Node_Id
:= Empty
;
11296 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
11300 Predef_Spec_Or_Body
(Loc
,
11303 Profile
=> New_List
(
11304 Make_Parameter_Specification
(Loc
,
11305 Defining_Identifier
=>
11306 Make_Defining_Identifier
(Loc
, Name_X
),
11307 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
11309 Make_Parameter_Specification
(Loc
,
11310 Defining_Identifier
=>
11311 Make_Defining_Identifier
(Loc
, Name_Y
),
11312 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
11314 Ret_Type
=> Standard_Boolean
,
11317 if Variant_Case
then
11318 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
11319 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
11322 if Present
(Typ_Def
) then
11323 Comps
:= Component_List
(Typ_Def
);
11327 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
11330 if Variant_Case
then
11332 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
11333 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
11335 Make_Simple_Return_Statement
(Loc
,
11336 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11340 Make_Simple_Return_Statement
(Loc
,
11342 Expand_Record_Equality
11345 Lhs
=> Make_Identifier
(Loc
, Name_X
),
11346 Rhs
=> Make_Identifier
(Loc
, Name_Y
))));
11349 Set_Handled_Statement_Sequence
11350 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
11358 -- <Make_Eq_If shared components>
11361 -- when V1 => <Make_Eq_Case> on subcomponents
11363 -- when Vn => <Make_Eq_Case> on subcomponents
11366 function Make_Eq_Case
11369 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
11371 Loc
: constant Source_Ptr
:= Sloc
(E
);
11372 Result
: constant List_Id
:= New_List
;
11374 Alt_List
: List_Id
;
11376 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
11377 -- Given the discriminant that controls a given variant of an unchecked
11378 -- union, find the formal of the equality function that carries the
11379 -- inferred value of the discriminant.
11381 function External_Name
(E
: Entity_Id
) return Name_Id
;
11382 -- The value of a given discriminant is conveyed in the corresponding
11383 -- formal parameter of the equality routine. The name of this formal
11384 -- parameter carries a one-character suffix which is removed here.
11386 --------------------------
11387 -- Corresponding_Formal --
11388 --------------------------
11390 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
11391 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
11395 Elm
:= First_Elmt
(Discrs
);
11396 while Present
(Elm
) loop
11397 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
11404 -- A formal of the proper name must be found
11406 raise Program_Error
;
11407 end Corresponding_Formal
;
11409 -------------------
11410 -- External_Name --
11411 -------------------
11413 function External_Name
(E
: Entity_Id
) return Name_Id
is
11415 Get_Name_String
(Chars
(E
));
11416 Name_Len
:= Name_Len
- 1;
11420 -- Start of processing for Make_Eq_Case
11423 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
11425 if No
(Variant_Part
(CL
)) then
11429 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
11431 if No
(Variant
) then
11435 Alt_List
:= New_List
;
11436 while Present
(Variant
) loop
11437 Append_To
(Alt_List
,
11438 Make_Case_Statement_Alternative
(Loc
,
11439 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
11441 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
11442 Next_Non_Pragma
(Variant
);
11445 -- If we have an Unchecked_Union, use one of the parameters of the
11446 -- enclosing equality routine that captures the discriminant, to use
11447 -- as the expression in the generated case statement.
11449 if Is_Unchecked_Union
(E
) then
11451 Make_Case_Statement
(Loc
,
11453 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
11454 Alternatives
=> Alt_List
));
11458 Make_Case_Statement
(Loc
,
11460 Make_Selected_Component
(Loc
,
11461 Prefix
=> Make_Identifier
(Loc
, Name_X
),
11462 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
11463 Alternatives
=> Alt_List
));
11484 -- or a null statement if the list L is empty
11486 -- Equality may be user-defined for a given component type, in which case
11487 -- a function call is constructed instead of an operator node. This is an
11488 -- Ada 2012 change in the composability of equality for untagged composite
11491 function Make_Eq_If
11493 L
: List_Id
) return Node_Id
11495 Loc
: constant Source_Ptr
:= Sloc
(E
);
11499 Field_Name
: Name_Id
;
11500 Next_Test
: Node_Id
;
11505 return Make_Null_Statement
(Loc
);
11510 C
:= First_Non_Pragma
(L
);
11511 while Present
(C
) loop
11512 Typ
:= Etype
(Defining_Identifier
(C
));
11513 Field_Name
:= Chars
(Defining_Identifier
(C
));
11515 -- The tags must not be compared: they are not part of the value.
11516 -- Ditto for parent interfaces because their equality operator is
11519 -- Note also that in the following, we use Make_Identifier for
11520 -- the component names. Use of New_Occurrence_Of to identify the
11521 -- components would be incorrect because the wrong entities for
11522 -- discriminants could be picked up in the private type case.
11524 if Field_Name
= Name_uParent
11525 and then Is_Interface
(Typ
)
11529 elsif Field_Name
/= Name_uTag
then
11531 Lhs
: constant Node_Id
:=
11532 Make_Selected_Component
(Loc
,
11533 Prefix
=> Make_Identifier
(Loc
, Name_X
),
11534 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
));
11536 Rhs
: constant Node_Id
:=
11537 Make_Selected_Component
(Loc
,
11538 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
11539 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
));
11543 -- Build equality code with a user-defined operator, if
11544 -- available, and with the predefined "=" otherwise. For
11545 -- compatibility with older Ada versions, we also use the
11546 -- predefined operation if the component-type equality is
11547 -- abstract, rather than raising Program_Error.
11549 if Ada_Version
< Ada_2012
then
11550 Next_Test
:= Make_Op_Ne
(Loc
, Lhs
, Rhs
);
11553 Eq_Call
:= Build_Eq_Call
(Typ
, Loc
, Lhs
, Rhs
);
11555 if No
(Eq_Call
) then
11556 Next_Test
:= Make_Op_Ne
(Loc
, Lhs
, Rhs
);
11558 -- If a component has a defined abstract equality, its
11559 -- application raises Program_Error on that component
11560 -- and therefore on the current variant.
11562 elsif Nkind
(Eq_Call
) = N_Raise_Program_Error
then
11563 Set_Etype
(Eq_Call
, Standard_Boolean
);
11564 Next_Test
:= Make_Op_Not
(Loc
, Eq_Call
);
11567 Next_Test
:= Make_Op_Not
(Loc
, Eq_Call
);
11572 Evolve_Or_Else
(Cond
, Next_Test
);
11575 Next_Non_Pragma
(C
);
11579 return Make_Null_Statement
(Loc
);
11583 Make_Implicit_If_Statement
(E
,
11585 Then_Statements
=> New_List
(
11586 Make_Simple_Return_Statement
(Loc
,
11587 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
11592 -------------------
11593 -- Make_Neq_Body --
11594 -------------------
11596 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
11598 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
11599 -- Returns true if Prim is a renaming of an unresolved predefined
11600 -- inequality operation.
11602 --------------------------------
11603 -- Is_Predefined_Neq_Renaming --
11604 --------------------------------
11606 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
11608 return Chars
(Prim
) /= Name_Op_Ne
11609 and then Present
(Alias
(Prim
))
11610 and then Comes_From_Source
(Prim
)
11611 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
11612 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
11613 end Is_Predefined_Neq_Renaming
;
11617 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
11619 Eq_Prim
: Entity_Id
;
11620 Left_Op
: Entity_Id
;
11621 Renaming_Prim
: Entity_Id
;
11622 Right_Op
: Entity_Id
;
11623 Target
: Entity_Id
;
11625 -- Start of processing for Make_Neq_Body
11628 -- For a call on a renaming of a dispatching subprogram that is
11629 -- overridden, if the overriding occurred before the renaming, then
11630 -- the body executed is that of the overriding declaration, even if the
11631 -- overriding declaration is not visible at the place of the renaming;
11632 -- otherwise, the inherited or predefined subprogram is called, see
11635 -- Stage 1: Search for a renaming of the inequality primitive and also
11636 -- search for an overriding of the equality primitive located before the
11637 -- renaming declaration.
11645 Renaming_Prim
:= Empty
;
11647 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
11648 while Present
(Elmt
) loop
11649 Prim
:= Node
(Elmt
);
11651 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
11652 if No
(Renaming_Prim
) then
11653 pragma Assert
(No
(Eq_Prim
));
11657 elsif Is_Predefined_Neq_Renaming
(Prim
) then
11658 Renaming_Prim
:= Prim
;
11665 -- No further action needed if no renaming was found
11667 if No
(Renaming_Prim
) then
11671 -- Stage 2: Replace the renaming declaration by a subprogram declaration
11672 -- (required to add its body)
11674 Decl
:= Parent
(Parent
(Renaming_Prim
));
11676 Make_Subprogram_Declaration
(Loc
,
11677 Specification
=> Specification
(Decl
)));
11678 Set_Analyzed
(Decl
);
11680 -- Remove the decoration of intrinsic renaming subprogram
11682 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
11683 Set_Convention
(Renaming_Prim
, Convention_Ada
);
11684 Set_Alias
(Renaming_Prim
, Empty
);
11685 Set_Has_Completion
(Renaming_Prim
, False);
11687 -- Stage 3: Build the corresponding body
11689 Left_Op
:= First_Formal
(Renaming_Prim
);
11690 Right_Op
:= Next_Formal
(Left_Op
);
11693 Predef_Spec_Or_Body
(Loc
,
11694 Tag_Typ
=> Tag_Typ
,
11695 Name
=> Chars
(Renaming_Prim
),
11696 Profile
=> New_List
(
11697 Make_Parameter_Specification
(Loc
,
11698 Defining_Identifier
=>
11699 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
11700 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
11702 Make_Parameter_Specification
(Loc
,
11703 Defining_Identifier
=>
11704 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
11705 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
11707 Ret_Type
=> Standard_Boolean
,
11710 -- If the overriding of the equality primitive occurred before the
11711 -- renaming, then generate:
11713 -- function <Neq_Name> (X : Y : Typ) return Boolean is
11715 -- return not Oeq (X, Y);
11718 if Present
(Eq_Prim
) then
11721 -- Otherwise build a nested subprogram which performs the predefined
11722 -- evaluation of the equality operator. That is, generate:
11724 -- function <Neq_Name> (X : Y : Typ) return Boolean is
11725 -- function Oeq (X : Y) return Boolean is
11727 -- <<body of default implementation>>
11730 -- return not Oeq (X, Y);
11735 Local_Subp
: Node_Id
;
11737 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
11738 Set_Declarations
(Decl
, New_List
(Local_Subp
));
11739 Target
:= Defining_Entity
(Local_Subp
);
11743 Set_Handled_Statement_Sequence
11745 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
11746 Make_Simple_Return_Statement
(Loc
,
11749 Make_Function_Call
(Loc
,
11750 Name
=> New_Occurrence_Of
(Target
, Loc
),
11751 Parameter_Associations
=> New_List
(
11752 Make_Identifier
(Loc
, Chars
(Left_Op
)),
11753 Make_Identifier
(Loc
, Chars
(Right_Op
)))))))));
11758 -------------------------------
11759 -- Make_Null_Procedure_Specs --
11760 -------------------------------
11762 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
11763 Decl_List
: constant List_Id
:= New_List
;
11764 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
11765 Formal
: Entity_Id
;
11766 New_Param_Spec
: Node_Id
;
11767 New_Spec
: Node_Id
;
11768 Parent_Subp
: Entity_Id
;
11769 Prim_Elmt
: Elmt_Id
;
11773 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
11774 while Present
(Prim_Elmt
) loop
11775 Subp
:= Node
(Prim_Elmt
);
11777 -- If a null procedure inherited from an interface has not been
11778 -- overridden, then we build a null procedure declaration to
11779 -- override the inherited procedure.
11781 Parent_Subp
:= Alias
(Subp
);
11783 if Present
(Parent_Subp
)
11784 and then Is_Null_Interface_Primitive
(Parent_Subp
)
11786 -- The null procedure spec is copied from the inherited procedure,
11787 -- except for the IS NULL (which must be added) and the overriding
11788 -- indicators (which must be removed, if present).
11791 Copy_Subprogram_Spec
(Subprogram_Specification
(Subp
), Loc
);
11793 Set_Null_Present
(New_Spec
, True);
11794 Set_Must_Override
(New_Spec
, False);
11795 Set_Must_Not_Override
(New_Spec
, False);
11797 Formal
:= First_Formal
(Subp
);
11798 New_Param_Spec
:= First
(Parameter_Specifications
(New_Spec
));
11800 while Present
(Formal
) loop
11802 -- For controlling arguments we must change their parameter
11803 -- type to reference the tagged type (instead of the interface
11806 if Is_Controlling_Formal
(Formal
) then
11807 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
11809 Set_Parameter_Type
(New_Param_Spec
,
11810 New_Occurrence_Of
(Tag_Typ
, Loc
));
11813 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
11814 N_Access_Definition
);
11815 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
11816 New_Occurrence_Of
(Tag_Typ
, Loc
));
11820 Next_Formal
(Formal
);
11821 Next
(New_Param_Spec
);
11824 Append_To
(Decl_List
,
11825 Make_Subprogram_Declaration
(Loc
,
11826 Specification
=> New_Spec
));
11829 Next_Elmt
(Prim_Elmt
);
11833 end Make_Null_Procedure_Specs
;
11835 ---------------------------------------
11836 -- Make_Predefined_Primitive_Eq_Spec --
11837 ---------------------------------------
11839 procedure Make_Predefined_Primitive_Eq_Spec
11840 (Tag_Typ
: Entity_Id
;
11841 Predef_List
: List_Id
;
11842 Renamed_Eq
: out Entity_Id
)
11844 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
11845 -- Returns true if Prim is a renaming of an unresolved predefined
11846 -- equality operation.
11848 -------------------------------
11849 -- Is_Predefined_Eq_Renaming --
11850 -------------------------------
11852 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
11854 return Chars
(Prim
) /= Name_Op_Eq
11855 and then Present
(Alias
(Prim
))
11856 and then Comes_From_Source
(Prim
)
11857 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
11858 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
11859 end Is_Predefined_Eq_Renaming
;
11863 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
11865 Eq_Name
: Name_Id
:= Name_Op_Eq
;
11866 Eq_Needed
: Boolean := True;
11870 Has_Predef_Eq_Renaming
: Boolean := False;
11871 -- Set to True if Tag_Typ has a primitive that renames the predefined
11872 -- equality operator. Used to implement (RM 8-5-4(8)).
11874 -- Start of processing for Make_Predefined_Primitive_Specs
11877 Renamed_Eq
:= Empty
;
11879 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
11880 while Present
(Prim
) loop
11882 -- If a primitive is encountered that renames the predefined equality
11883 -- operator before reaching any explicit equality primitive, then we
11884 -- still need to create a predefined equality function, because calls
11885 -- to it can occur via the renaming. A new name is created for the
11886 -- equality to avoid conflicting with any user-defined equality.
11887 -- (Note that this doesn't account for renamings of equality nested
11888 -- within subpackages???)
11890 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
11891 Has_Predef_Eq_Renaming
:= True;
11892 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
11894 -- User-defined equality
11896 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
11897 if No
(Alias
(Node
(Prim
)))
11898 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
11899 N_Subprogram_Renaming_Declaration
11901 Eq_Needed
:= False;
11904 -- If the parent is not an interface type and has an abstract
11905 -- equality function explicitly defined in the sources, then the
11906 -- inherited equality is abstract as well, and no body can be
11909 elsif not Is_Interface
(Etype
(Tag_Typ
))
11910 and then Present
(Alias
(Node
(Prim
)))
11911 and then Comes_From_Source
(Alias
(Node
(Prim
)))
11912 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
11914 Eq_Needed
:= False;
11917 -- If the type has an equality function corresponding with a
11918 -- primitive defined in an interface type, the inherited equality
11919 -- is abstract as well, and no body can be created for it.
11921 elsif Present
(Alias
(Node
(Prim
)))
11922 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
11925 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
11927 Eq_Needed
:= False;
11935 -- If a renaming of predefined equality was found but there was no
11936 -- user-defined equality (so Eq_Needed is still true), then set the name
11937 -- back to Name_Op_Eq. But in the case where a user-defined equality was
11938 -- located after such a renaming, then the predefined equality function
11939 -- is still needed, so Eq_Needed must be set back to True.
11941 if Eq_Name
/= Name_Op_Eq
then
11943 Eq_Name
:= Name_Op_Eq
;
11950 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
11951 Tag_Typ
=> Tag_Typ
,
11953 Profile
=> New_List
(
11954 Make_Parameter_Specification
(Loc
,
11955 Defining_Identifier
=>
11956 Make_Defining_Identifier
(Loc
, Name_X
),
11957 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
11959 Make_Parameter_Specification
(Loc
,
11960 Defining_Identifier
=>
11961 Make_Defining_Identifier
(Loc
, Name_Y
),
11962 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
11963 Ret_Type
=> Standard_Boolean
);
11964 Append_To
(Predef_List
, Eq_Spec
);
11966 if Has_Predef_Eq_Renaming
then
11967 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
11969 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
11970 while Present
(Prim
) loop
11972 -- Any renamings of equality that appeared before an overriding
11973 -- equality must be updated to refer to the entity for the
11974 -- predefined equality, otherwise calls via the renaming would
11975 -- get incorrectly resolved to call the user-defined equality
11978 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
11979 Set_Alias
(Node
(Prim
), Renamed_Eq
);
11981 -- Exit upon encountering a user-defined equality
11983 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
11984 and then No
(Alias
(Node
(Prim
)))
11993 end Make_Predefined_Primitive_Eq_Spec
;
11995 -------------------------------------
11996 -- Make_Predefined_Primitive_Specs --
11997 -------------------------------------
11999 procedure Make_Predefined_Primitive_Specs
12000 (Tag_Typ
: Entity_Id
;
12001 Predef_List
: out List_Id
;
12002 Renamed_Eq
: out Entity_Id
)
12004 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
12005 Res
: constant List_Id
:= New_List
;
12010 Renamed_Eq
:= Empty
;
12014 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
12015 Tag_Typ
=> Tag_Typ
,
12016 Name
=> Name_uSize
,
12017 Profile
=> New_List
(
12018 Make_Parameter_Specification
(Loc
,
12019 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
12020 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
12022 Ret_Type
=> Standard_Long_Long_Integer
));
12024 -- Spec of Put_Image
12026 if not No_Run_Time_Mode
12027 and then RTE_Available
(RE_Root_Buffer_Type
)
12029 -- No_Run_Time_Mode implies that the declaration of Tag_Typ
12030 -- (like any tagged type) will be rejected. Given this, avoid
12031 -- cascading errors associated with the Tag_Typ's TSS_Put_Image
12034 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
12035 Tag_Typ
=> Tag_Typ
,
12036 Name
=> Make_TSS_Name
(Tag_Typ
, TSS_Put_Image
),
12037 Profile
=> Build_Put_Image_Profile
(Loc
, Tag_Typ
)));
12040 -- Specs for dispatching stream attributes
12043 Stream_Op_TSS_Names
:
12044 constant array (Positive range <>) of TSS_Name_Type
:=
12048 TSS_Stream_Output
);
12051 for Op
in Stream_Op_TSS_Names
'Range loop
12052 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
12054 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
12055 Stream_Op_TSS_Names
(Op
)));
12060 -- Spec of "=" is expanded if the type is not limited and if a user
12061 -- defined "=" was not already declared for the non-full view of a
12062 -- private extension.
12064 if not Is_Limited_Type
(Tag_Typ
) then
12065 Make_Predefined_Primitive_Eq_Spec
(Tag_Typ
, Res
, Renamed_Eq
);
12067 -- Spec for dispatching assignment
12069 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
12070 Tag_Typ
=> Tag_Typ
,
12071 Name
=> Name_uAssign
,
12072 Profile
=> New_List
(
12073 Make_Parameter_Specification
(Loc
,
12074 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
12075 Out_Present
=> True,
12076 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
12078 Make_Parameter_Specification
(Loc
,
12079 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
12080 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
12083 -- Ada 2005: Generate declarations for the following primitive
12084 -- operations for limited interfaces and synchronized types that
12085 -- implement a limited interface.
12087 -- Disp_Asynchronous_Select
12088 -- Disp_Conditional_Select
12089 -- Disp_Get_Prim_Op_Kind
12090 -- Disp_Get_Task_Id
12092 -- Disp_Timed_Select
12094 -- Disable the generation of these bodies if Ravenscar or ZFP is active
12096 if Ada_Version
>= Ada_2005
12097 and then not Restriction_Active
(No_Select_Statements
)
12098 and then RTE_Available
(RE_Select_Specific_Data
)
12100 -- These primitives are defined abstract in interface types
12102 if Is_Interface
(Tag_Typ
)
12103 and then Is_Limited_Record
(Tag_Typ
)
12106 Make_Abstract_Subprogram_Declaration
(Loc
,
12108 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
12111 Make_Abstract_Subprogram_Declaration
(Loc
,
12113 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
12116 Make_Abstract_Subprogram_Declaration
(Loc
,
12118 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
12121 Make_Abstract_Subprogram_Declaration
(Loc
,
12123 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
12126 Make_Abstract_Subprogram_Declaration
(Loc
,
12128 Make_Disp_Requeue_Spec
(Tag_Typ
)));
12131 Make_Abstract_Subprogram_Declaration
(Loc
,
12133 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
12135 -- If ancestor is an interface type, declare non-abstract primitives
12136 -- to override the abstract primitives of the interface type.
12138 -- In VM targets we define these primitives in all root tagged types
12139 -- that are not interface types. Done because in VM targets we don't
12140 -- have secondary dispatch tables and any derivation of Tag_Typ may
12141 -- cover limited interfaces (which always have these primitives since
12142 -- they may be ancestors of synchronized interface types).
12144 elsif (not Is_Interface
(Tag_Typ
)
12145 and then Is_Interface
(Etype
(Tag_Typ
))
12146 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
12148 (Is_Concurrent_Record_Type
(Tag_Typ
)
12149 and then Has_Interfaces
(Tag_Typ
))
12151 (not Tagged_Type_Expansion
12152 and then not Is_Interface
(Tag_Typ
)
12153 and then Tag_Typ
= Root_Type
(Tag_Typ
))
12156 Make_Subprogram_Declaration
(Loc
,
12158 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
12161 Make_Subprogram_Declaration
(Loc
,
12163 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
12166 Make_Subprogram_Declaration
(Loc
,
12168 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
12171 Make_Subprogram_Declaration
(Loc
,
12173 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
12176 Make_Subprogram_Declaration
(Loc
,
12178 Make_Disp_Requeue_Spec
(Tag_Typ
)));
12181 Make_Subprogram_Declaration
(Loc
,
12183 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
12187 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
12188 -- regardless of whether they are controlled or may contain controlled
12191 -- Do not generate the routines if finalization is disabled
12193 if Restriction_Active
(No_Finalization
) then
12197 if not Is_Limited_Type
(Tag_Typ
) then
12198 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
12201 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
12204 Predef_List
:= Res
;
12205 end Make_Predefined_Primitive_Specs
;
12207 -------------------------
12208 -- Make_Tag_Assignment --
12209 -------------------------
12211 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
12212 Loc
: constant Source_Ptr
:= Sloc
(N
);
12213 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
12214 Expr
: constant Node_Id
:= Expression
(N
);
12215 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
12216 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
12219 -- This expansion activity is called during analysis
12221 if Is_Tagged_Type
(Typ
)
12222 and then not Is_Class_Wide_Type
(Typ
)
12223 and then not Is_CPP_Class
(Typ
)
12224 and then Tagged_Type_Expansion
12225 and then Nkind
(Unqualify
(Expr
)) /= N_Aggregate
12228 Make_Tag_Assignment_From_Type
12229 (Loc
, New_Occurrence_Of
(Def_Id
, Loc
), Full_Typ
);
12234 end Make_Tag_Assignment
;
12236 ----------------------
12237 -- Predef_Deep_Spec --
12238 ----------------------
12240 function Predef_Deep_Spec
12242 Tag_Typ
: Entity_Id
;
12243 Name
: TSS_Name_Type
;
12244 For_Body
: Boolean := False) return Node_Id
12249 -- V : in out Tag_Typ
12251 Formals
:= New_List
(
12252 Make_Parameter_Specification
(Loc
,
12253 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12254 In_Present
=> True,
12255 Out_Present
=> True,
12256 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
12258 -- F : Boolean := True
12260 if Name
= TSS_Deep_Adjust
12261 or else Name
= TSS_Deep_Finalize
12263 Append_To
(Formals
,
12264 Make_Parameter_Specification
(Loc
,
12265 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
12266 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
12267 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12271 Predef_Spec_Or_Body
(Loc
,
12272 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
12273 Tag_Typ
=> Tag_Typ
,
12274 Profile
=> Formals
,
12275 For_Body
=> For_Body
);
12278 when RE_Not_Available
=>
12280 end Predef_Deep_Spec
;
12282 -------------------------
12283 -- Predef_Spec_Or_Body --
12284 -------------------------
12286 function Predef_Spec_Or_Body
12288 Tag_Typ
: Entity_Id
;
12291 Ret_Type
: Entity_Id
:= Empty
;
12292 For_Body
: Boolean := False) return Node_Id
12294 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
12298 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
12300 -- The internal flag is set to mark these declarations because they have
12301 -- specific properties. First, they are primitives even if they are not
12302 -- defined in the type scope (the freezing point is not necessarily in
12303 -- the same scope). Second, the predefined equality can be overridden by
12304 -- a user-defined equality, no body will be generated in this case.
12306 Set_Is_Internal
(Id
);
12308 if not Debug_Generated_Code
then
12309 Set_Debug_Info_Off
(Id
);
12312 if No
(Ret_Type
) then
12314 Make_Procedure_Specification
(Loc
,
12315 Defining_Unit_Name
=> Id
,
12316 Parameter_Specifications
=> Profile
);
12319 Make_Function_Specification
(Loc
,
12320 Defining_Unit_Name
=> Id
,
12321 Parameter_Specifications
=> Profile
,
12322 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
12325 -- Declare an abstract subprogram for primitive subprograms of an
12326 -- interface type (except for "=").
12328 if Is_Interface
(Tag_Typ
) then
12329 if Name
/= Name_Op_Eq
then
12330 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
12332 -- The equality function (if any) for an interface type is defined
12333 -- to be nonabstract, so we create an expression function for it that
12334 -- always returns False. Note that the function can never actually be
12335 -- invoked because interface types are abstract, so there aren't any
12336 -- objects of such types (and their equality operation will always
12340 return Make_Expression_Function
12341 (Loc
, Spec
, New_Occurrence_Of
(Standard_False
, Loc
));
12344 -- If body case, return empty subprogram body. Note that this is ill-
12345 -- formed, because there is not even a null statement, and certainly not
12346 -- a return in the function case. The caller is expected to do surgery
12347 -- on the body to add the appropriate stuff.
12349 elsif For_Body
then
12350 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
12352 -- For the case of an Input attribute predefined for an abstract type,
12353 -- generate an abstract specification. This will never be called, but we
12354 -- need the slot allocated in the dispatching table so that attributes
12355 -- typ'Class'Input and typ'Class'Output will work properly.
12357 elsif Is_TSS
(Name
, TSS_Stream_Input
)
12358 and then Is_Abstract_Type
(Tag_Typ
)
12360 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
12362 -- Normal spec case, where we return a subprogram declaration
12365 return Make_Subprogram_Declaration
(Loc
, Spec
);
12367 end Predef_Spec_Or_Body
;
12369 -----------------------------
12370 -- Predef_Stream_Attr_Spec --
12371 -----------------------------
12373 function Predef_Stream_Attr_Spec
12375 Tag_Typ
: Entity_Id
;
12376 Name
: TSS_Name_Type
) return Node_Id
12378 Ret_Type
: Entity_Id
;
12381 if Name
= TSS_Stream_Input
then
12382 Ret_Type
:= Tag_Typ
;
12388 Predef_Spec_Or_Body
12390 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
12391 Tag_Typ
=> Tag_Typ
,
12392 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
12393 Ret_Type
=> Ret_Type
,
12394 For_Body
=> False);
12395 end Predef_Stream_Attr_Spec
;
12397 ----------------------------------
12398 -- Predefined_Primitive_Eq_Body --
12399 ----------------------------------
12401 procedure Predefined_Primitive_Eq_Body
12402 (Tag_Typ
: Entity_Id
;
12403 Predef_List
: List_Id
;
12404 Renamed_Eq
: Entity_Id
)
12407 Eq_Needed
: Boolean;
12412 -- See if we have a predefined "=" operator
12414 if Present
(Renamed_Eq
) then
12416 Eq_Name
:= Chars
(Renamed_Eq
);
12418 -- If the parent is an interface type then it has defined all the
12419 -- predefined primitives abstract and we need to check if the type
12420 -- has some user defined "=" function which matches the profile of
12421 -- the Ada predefined equality operator to avoid generating it.
12423 elsif Is_Interface
(Etype
(Tag_Typ
)) then
12425 Eq_Name
:= Name_Op_Eq
;
12427 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
12428 while Present
(Prim
) loop
12429 if Is_User_Defined_Equality
(Node
(Prim
))
12430 and then not Is_Internal
(Node
(Prim
))
12432 Eq_Needed
:= False;
12433 Eq_Name
:= No_Name
;
12441 Eq_Needed
:= False;
12442 Eq_Name
:= No_Name
;
12444 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
12445 while Present
(Prim
) loop
12446 if Is_User_Defined_Equality
(Node
(Prim
))
12447 and then Is_Internal
(Node
(Prim
))
12450 Eq_Name
:= Name_Op_Eq
;
12458 -- If equality is needed, we will have its name
12460 pragma Assert
(Eq_Needed
= Present
(Eq_Name
));
12462 -- Body for equality
12465 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
12466 Append_To
(Predef_List
, Decl
);
12469 -- Body for inequality (if required)
12471 Decl
:= Make_Neq_Body
(Tag_Typ
);
12473 if Present
(Decl
) then
12474 Append_To
(Predef_List
, Decl
);
12476 end Predefined_Primitive_Eq_Body
;
12478 ---------------------------------
12479 -- Predefined_Primitive_Bodies --
12480 ---------------------------------
12482 function Predefined_Primitive_Bodies
12483 (Tag_Typ
: Entity_Id
;
12484 Renamed_Eq
: Entity_Id
) return List_Id
12486 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
12487 Res
: constant List_Id
:= New_List
;
12488 Adj_Call
: Node_Id
;
12490 Fin_Call
: Node_Id
;
12493 pragma Warnings
(Off
, Ent
);
12498 pragma Assert
(not Is_Interface
(Tag_Typ
));
12502 Decl
:= Predef_Spec_Or_Body
(Loc
,
12503 Tag_Typ
=> Tag_Typ
,
12504 Name
=> Name_uSize
,
12505 Profile
=> New_List
(
12506 Make_Parameter_Specification
(Loc
,
12507 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
12508 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
12510 Ret_Type
=> Standard_Long_Long_Integer
,
12513 Set_Handled_Statement_Sequence
(Decl
,
12514 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
12515 Make_Simple_Return_Statement
(Loc
,
12517 Make_Attribute_Reference
(Loc
,
12518 Prefix
=> Make_Identifier
(Loc
, Name_X
),
12519 Attribute_Name
=> Name_Size
)))));
12521 Append_To
(Res
, Decl
);
12523 -- Body of Put_Image
12525 if No
(TSS
(Tag_Typ
, TSS_Put_Image
))
12526 and then not No_Run_Time_Mode
12527 and then RTE_Available
(RE_Root_Buffer_Type
)
12529 Build_Record_Put_Image_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
12530 Append_To
(Res
, Decl
);
12533 -- Bodies for Dispatching stream IO routines. We need these only for
12534 -- non-limited types (in the limited case there is no dispatching).
12535 -- We also skip them if dispatching or finalization are not available
12536 -- or if stream operations are prohibited by restriction No_Streams or
12537 -- from use of pragma/aspect No_Tagged_Streams.
12539 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
12540 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
12542 Build_Record_Read_Procedure
(Tag_Typ
, Decl
, Ent
);
12543 Append_To
(Res
, Decl
);
12546 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
12547 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
12549 Build_Record_Write_Procedure
(Tag_Typ
, Decl
, Ent
);
12550 Append_To
(Res
, Decl
);
12553 -- Skip body of _Input for the abstract case, since the corresponding
12554 -- spec is abstract (see Predef_Spec_Or_Body).
12556 if not Is_Abstract_Type
(Tag_Typ
)
12557 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
12558 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
12560 Build_Record_Or_Elementary_Input_Function
12561 (Tag_Typ
, Decl
, Ent
);
12562 Append_To
(Res
, Decl
);
12565 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
12566 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
12568 Build_Record_Or_Elementary_Output_Procedure
(Tag_Typ
, Decl
, Ent
);
12569 Append_To
(Res
, Decl
);
12572 -- Ada 2005: Generate bodies for the following primitive operations for
12573 -- limited interfaces and synchronized types that implement a limited
12576 -- disp_asynchronous_select
12577 -- disp_conditional_select
12578 -- disp_get_prim_op_kind
12579 -- disp_get_task_id
12580 -- disp_timed_select
12582 -- The interface versions will have null bodies
12584 -- Disable the generation of these bodies if Ravenscar or ZFP is active
12586 -- In VM targets we define these primitives in all root tagged types
12587 -- that are not interface types. Done because in VM targets we don't
12588 -- have secondary dispatch tables and any derivation of Tag_Typ may
12589 -- cover limited interfaces (which always have these primitives since
12590 -- they may be ancestors of synchronized interface types).
12592 if Ada_Version
>= Ada_2005
12594 ((Is_Interface
(Etype
(Tag_Typ
))
12595 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
12597 (Is_Concurrent_Record_Type
(Tag_Typ
)
12598 and then Has_Interfaces
(Tag_Typ
))
12600 (not Tagged_Type_Expansion
12601 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
12602 and then not Restriction_Active
(No_Select_Statements
)
12603 and then RTE_Available
(RE_Select_Specific_Data
)
12605 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
12606 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
12607 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
12608 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
12609 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
12610 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
12613 if not Is_Limited_Type
(Tag_Typ
) then
12614 -- Body for equality and inequality
12616 Predefined_Primitive_Eq_Body
(Tag_Typ
, Res
, Renamed_Eq
);
12618 -- Body for dispatching assignment
12621 Predef_Spec_Or_Body
(Loc
,
12622 Tag_Typ
=> Tag_Typ
,
12623 Name
=> Name_uAssign
,
12624 Profile
=> New_List
(
12625 Make_Parameter_Specification
(Loc
,
12626 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
12627 Out_Present
=> True,
12628 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
12630 Make_Parameter_Specification
(Loc
,
12631 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
12632 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
12635 Set_Handled_Statement_Sequence
(Decl
,
12636 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
12637 Make_Assignment_Statement
(Loc
,
12638 Name
=> Make_Identifier
(Loc
, Name_X
),
12639 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
12641 Append_To
(Res
, Decl
);
12644 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
12645 -- tagged types which do not contain controlled components.
12647 -- Do not generate the routines if finalization is disabled
12649 if Restriction_Active
(No_Finalization
) then
12652 elsif not Has_Controlled_Component
(Tag_Typ
) then
12653 if not Is_Limited_Type
(Tag_Typ
) then
12655 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
12657 if Is_Controlled
(Tag_Typ
) then
12660 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
12664 if No
(Adj_Call
) then
12665 Adj_Call
:= Make_Null_Statement
(Loc
);
12668 Set_Handled_Statement_Sequence
(Decl
,
12669 Make_Handled_Sequence_Of_Statements
(Loc
,
12670 Statements
=> New_List
(Adj_Call
)));
12672 Append_To
(Res
, Decl
);
12676 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
12678 if Is_Controlled
(Tag_Typ
) then
12681 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
12685 if No
(Fin_Call
) then
12686 Fin_Call
:= Make_Null_Statement
(Loc
);
12689 Set_Handled_Statement_Sequence
(Decl
,
12690 Make_Handled_Sequence_Of_Statements
(Loc
,
12691 Statements
=> New_List
(Fin_Call
)));
12693 Append_To
(Res
, Decl
);
12697 end Predefined_Primitive_Bodies
;
12699 ---------------------------------
12700 -- Predefined_Primitive_Freeze --
12701 ---------------------------------
12703 function Predefined_Primitive_Freeze
12704 (Tag_Typ
: Entity_Id
) return List_Id
12706 Res
: constant List_Id
:= New_List
;
12711 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
12712 while Present
(Prim
) loop
12713 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
12714 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
12716 if Present
(Frnodes
) then
12717 Append_List_To
(Res
, Frnodes
);
12725 end Predefined_Primitive_Freeze
;
12727 -------------------------
12728 -- Stream_Operation_OK --
12729 -------------------------
12731 function Stream_Operation_OK
12733 Operation
: TSS_Name_Type
) return Boolean
12735 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
12738 -- Special case of a limited type extension: a default implementation
12739 -- of the stream attributes Read or Write exists if that attribute
12740 -- has been specified or is available for an ancestor type; a default
12741 -- implementation of the attribute Output (resp. Input) exists if the
12742 -- attribute has been specified or Write (resp. Read) is available for
12743 -- an ancestor type. The last condition only applies under Ada 2005.
12745 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
12746 if Operation
= TSS_Stream_Read
then
12747 Has_Predefined_Or_Specified_Stream_Attribute
:=
12748 Has_Specified_Stream_Read
(Typ
);
12750 elsif Operation
= TSS_Stream_Write
then
12751 Has_Predefined_Or_Specified_Stream_Attribute
:=
12752 Has_Specified_Stream_Write
(Typ
);
12754 elsif Operation
= TSS_Stream_Input
then
12755 Has_Predefined_Or_Specified_Stream_Attribute
:=
12756 Has_Specified_Stream_Input
(Typ
)
12758 (Ada_Version
>= Ada_2005
12759 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
12761 elsif Operation
= TSS_Stream_Output
then
12762 Has_Predefined_Or_Specified_Stream_Attribute
:=
12763 Has_Specified_Stream_Output
(Typ
)
12765 (Ada_Version
>= Ada_2005
12766 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
12769 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
12771 if not Has_Predefined_Or_Specified_Stream_Attribute
12772 and then Is_Derived_Type
(Typ
)
12773 and then (Operation
= TSS_Stream_Read
12774 or else Operation
= TSS_Stream_Write
)
12776 Has_Predefined_Or_Specified_Stream_Attribute
:=
12778 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
12782 -- If the type is not limited, or else is limited but the attribute is
12783 -- explicitly specified or is predefined for the type, then return True,
12784 -- unless other conditions prevail, such as restrictions prohibiting
12785 -- streams or dispatching operations. We also return True for limited
12786 -- interfaces, because they may be extended by nonlimited types and
12787 -- permit inheritance in this case (addresses cases where an abstract
12788 -- extension doesn't get 'Input declared, as per comments below, but
12789 -- 'Class'Input must still be allowed). Note that attempts to apply
12790 -- stream attributes to a limited interface or its class-wide type
12791 -- (or limited extensions thereof) will still get properly rejected
12792 -- by Check_Stream_Attribute.
12794 -- We exclude the Input operation from being a predefined subprogram in
12795 -- the case where the associated type is an abstract extension, because
12796 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
12797 -- we don't want an abstract version created because types derived from
12798 -- the abstract type may not even have Input available (for example if
12799 -- derived from a private view of the abstract type that doesn't have
12800 -- a visible Input).
12802 -- Do not generate stream routines for type Finalization_Master because
12803 -- a master may never appear in types and therefore cannot be read or
12807 (not Is_Limited_Type
(Typ
)
12808 or else Is_Interface
(Typ
)
12809 or else Has_Predefined_Or_Specified_Stream_Attribute
)
12811 (Operation
/= TSS_Stream_Input
12812 or else not Is_Abstract_Type
(Typ
)
12813 or else not Is_Derived_Type
(Typ
))
12814 and then not Has_Unknown_Discriminants
(Typ
)
12815 and then not Is_Concurrent_Interface
(Typ
)
12816 and then not Restriction_Active
(No_Streams
)
12817 and then not Restriction_Active
(No_Dispatch
)
12818 and then No
(No_Tagged_Streams_Pragma
(Typ
))
12819 and then not No_Run_Time_Mode
12820 and then RTE_Available
(RE_Tag
)
12821 and then No
(Type_Without_Stream_Operation
(Typ
))
12822 and then RTE_Available
(RE_Root_Stream_Type
)
12823 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
12824 end Stream_Operation_OK
;