1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Einfo
; use Einfo
;
30 with Errout
; use Errout
;
31 with Exp_Aggr
; use Exp_Aggr
;
32 with Exp_Atag
; use Exp_Atag
;
33 with Exp_Ch4
; use Exp_Ch4
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Ch9
; use Exp_Ch9
;
37 with Exp_Dbug
; use Exp_Dbug
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Dist
; use Exp_Dist
;
40 with Exp_Smem
; use Exp_Smem
;
41 with Exp_Strm
; use Exp_Strm
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Freeze
; use Freeze
;
45 with Ghost
; use Ghost
;
47 with Namet
; use Namet
;
48 with Nlists
; use Nlists
;
49 with Nmake
; use Nmake
;
51 with Restrict
; use Restrict
;
52 with Rident
; use Rident
;
53 with Rtsfind
; use Rtsfind
;
55 with Sem_Aux
; use Sem_Aux
;
56 with Sem_Attr
; use Sem_Attr
;
57 with Sem_Cat
; use Sem_Cat
;
58 with Sem_Ch3
; use Sem_Ch3
;
59 with Sem_Ch6
; use Sem_Ch6
;
60 with Sem_Ch8
; use Sem_Ch8
;
61 with Sem_Disp
; use Sem_Disp
;
62 with Sem_Eval
; use Sem_Eval
;
63 with Sem_Mech
; use Sem_Mech
;
64 with Sem_Res
; use Sem_Res
;
65 with Sem_SCIL
; use Sem_SCIL
;
66 with Sem_Type
; use Sem_Type
;
67 with Sem_Util
; use Sem_Util
;
68 with Sinfo
; use Sinfo
;
69 with Stand
; use Stand
;
70 with Snames
; use Snames
;
71 with Tbuild
; use Tbuild
;
72 with Ttypes
; use Ttypes
;
73 with Validsw
; use Validsw
;
75 package body Exp_Ch3
is
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Adjust_Discriminants
(Rtype
: Entity_Id
);
82 -- This is used when freezing a record type. It attempts to construct
83 -- more restrictive subtypes for discriminants so that the max size of
84 -- the record can be calculated more accurately. See the body of this
85 -- procedure for details.
87 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
);
88 -- Build initialization procedure for given array type. Nod is a node
89 -- used for attachment of any actions required in its construction.
90 -- It also supplies the source location used for the procedure.
92 function Build_Discriminant_Formals
94 Use_Dl
: Boolean) return List_Id
;
95 -- This function uses the discriminants of a type to build a list of
96 -- formal parameters, used in Build_Init_Procedure among other places.
97 -- If the flag Use_Dl is set, the list is built using the already
98 -- defined discriminals of the type, as is the case for concurrent
99 -- types with discriminants. Otherwise new identifiers are created,
100 -- with the source names of the discriminants.
102 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
;
103 -- This function builds a static aggregate that can serve as the initial
104 -- value for an array type whose bounds are static, and whose component
105 -- type is a composite type that has a static equivalent aggregate.
106 -- The equivalent array aggregate is used both for object initialization
107 -- and for component initialization, when used in the following function.
109 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
;
110 -- This function builds a static aggregate that can serve as the initial
111 -- value for a record type whose components are scalar and initialized
112 -- with compile-time values, or arrays with similar initialization or
113 -- defaults. When possible, initialization of an object of the type can
114 -- be achieved by using a copy of the aggregate as an initial value, thus
115 -- removing the implicit call that would otherwise constitute elaboration
118 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
);
119 -- Build record initialization procedure. N is the type declaration
120 -- node, and Rec_Ent is the corresponding entity for the record type.
122 procedure Build_Slice_Assignment
(Typ
: Entity_Id
);
123 -- Build assignment procedure for one-dimensional arrays of controlled
124 -- types. Other array and slice assignments are expanded in-line, but
125 -- the code expansion for controlled components (when control actions
126 -- are active) can lead to very large blocks that GCC3 handles poorly.
128 procedure Build_Untagged_Equality
(Typ
: Entity_Id
);
129 -- AI05-0123: Equality on untagged records composes. This procedure
130 -- builds the equality routine for an untagged record that has components
131 -- of a record type that has user-defined primitive equality operations.
132 -- The resulting operation is a TSS subprogram.
134 procedure Check_Stream_Attributes
(Typ
: Entity_Id
);
135 -- Check that if a limited extension has a parent with user-defined stream
136 -- attributes, and does not itself have user-defined stream-attributes,
137 -- then any limited component of the extension also has the corresponding
138 -- user-defined stream attributes.
140 procedure Clean_Task_Names
142 Proc_Id
: Entity_Id
);
143 -- If an initialization procedure includes calls to generate names
144 -- for task subcomponents, indicate that secondary stack cleanup is
145 -- needed after an initialization. Typ is the component type, and Proc_Id
146 -- the initialization procedure for the enclosing composite type.
148 procedure Expand_Freeze_Array_Type
(N
: Node_Id
);
149 -- Freeze an array type. Deals with building the initialization procedure,
150 -- creating the packed array type for a packed array and also with the
151 -- creation of the controlling procedures for the controlled case. The
152 -- argument N is the N_Freeze_Entity node for the type.
154 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
);
155 -- Freeze a class-wide type. Build routine Finalize_Address for the purpose
156 -- of finalizing controlled derivations from the class-wide's root type.
158 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
);
159 -- Freeze enumeration type with non-standard representation. Builds the
160 -- array and function needed to convert between enumeration pos and
161 -- enumeration representation values. N is the N_Freeze_Entity node
164 procedure Expand_Freeze_Record_Type
(N
: Node_Id
);
165 -- Freeze record type. Builds all necessary discriminant checking
166 -- and other ancillary functions, and builds dispatch tables where
167 -- needed. The argument N is the N_Freeze_Entity node. This processing
168 -- applies only to E_Record_Type entities, not to class wide types,
169 -- record subtypes, or private types.
171 procedure Expand_Tagged_Root
(T
: Entity_Id
);
172 -- Add a field _Tag at the beginning of the record. This field carries
173 -- the value of the access to the Dispatch table. This procedure is only
174 -- called on root type, the _Tag field being inherited by the descendants.
176 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
);
177 -- Treat user-defined stream operations as renaming_as_body if the
178 -- subprogram they rename is not frozen when the type is frozen.
180 procedure Initialization_Warning
(E
: Entity_Id
);
181 -- If static elaboration of the package is requested, indicate
182 -- when a type does meet the conditions for static initialization. If
183 -- E is a type, it has components that have no static initialization.
184 -- if E is an entity, its initial expression is not compile-time known.
186 function Init_Formals
(Typ
: Entity_Id
) return List_Id
;
187 -- This function builds the list of formals for an initialization routine.
188 -- The first formal is always _Init with the given type. For task value
189 -- record types and types containing tasks, three additional formals are
192 -- _Master : Master_Id
193 -- _Chain : in out Activation_Chain
194 -- _Task_Name : String
196 -- The caller must append additional entries for discriminants if required.
198 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean;
199 -- Returns true if the initialization procedure of Typ should be inlined
201 function In_Runtime
(E
: Entity_Id
) return Boolean;
202 -- Check if E is defined in the RTL (in a child of Ada or System). Used
203 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
205 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean;
206 -- Returns true if Prim is a user defined equality function
208 function Make_Eq_Body
210 Eq_Name
: Name_Id
) return Node_Id
;
211 -- Build the body of a primitive equality operation for a tagged record
212 -- type, or in Ada 2012 for any record type that has components with a
213 -- user-defined equality. Factored out of Predefined_Primitive_Bodies.
215 function Make_Eq_Case
218 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
;
219 -- Building block for variant record equality. Defined to share the code
220 -- between the tagged and untagged case. Given a Component_List node CL,
221 -- it generates an 'if' followed by a 'case' statement that compares all
222 -- components of local temporaries named X and Y (that are declared as
223 -- formals at some upper level). E provides the Sloc to be used for the
226 -- IF E is an unchecked_union, Discrs is the list of formals created for
227 -- the inferred discriminants of one operand. These formals are used in
228 -- the generated case statements for each variant of the unchecked union.
232 L
: List_Id
) return Node_Id
;
233 -- Building block for variant record equality. Defined to share the code
234 -- between the tagged and untagged case. Given the list of components
235 -- (or discriminants) L, it generates a return statement that compares all
236 -- components of local temporaries named X and Y (that are declared as
237 -- formals at some upper level). E provides the Sloc to be used for the
240 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
;
241 -- Search for a renaming of the inequality dispatching primitive of
242 -- this tagged type. If found then build and return the corresponding
243 -- rename-as-body inequality subprogram; otherwise return Empty.
245 procedure Make_Predefined_Primitive_Specs
246 (Tag_Typ
: Entity_Id
;
247 Predef_List
: out List_Id
;
248 Renamed_Eq
: out Entity_Id
);
249 -- Create a list with the specs of the predefined primitive operations.
250 -- For tagged types that are interfaces all these primitives are defined
253 -- The following entries are present for all tagged types, and provide
254 -- the results of the corresponding attribute applied to the object.
255 -- Dispatching is required in general, since the result of the attribute
256 -- will vary with the actual object subtype.
258 -- _size provides result of 'Size attribute
259 -- typSR provides result of 'Read attribute
260 -- typSW provides result of 'Write attribute
261 -- typSI provides result of 'Input attribute
262 -- typSO provides result of 'Output attribute
264 -- The following entries are additionally present for non-limited tagged
265 -- types, and implement additional dispatching operations for predefined
268 -- _equality implements "=" operator
269 -- _assign implements assignment operation
270 -- typDF implements deep finalization
271 -- typDA implements deep adjust
273 -- The latter two are empty procedures unless the type contains some
274 -- controlled components that require finalization actions (the deep
275 -- in the name refers to the fact that the action applies to components).
277 -- The list is returned in Predef_List. The Parameter Renamed_Eq either
278 -- returns the value Empty, or else the defining unit name for the
279 -- predefined equality function in the case where the type has a primitive
280 -- operation that is a renaming of predefined equality (but only if there
281 -- is also an overriding user-defined equality function). The returned
282 -- Renamed_Eq will be passed to the corresponding parameter of
283 -- Predefined_Primitive_Bodies.
285 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean;
286 -- Returns True if there are representation clauses for type T that are not
287 -- inherited. If the result is false, the init_proc and the discriminant
288 -- checking functions of the parent can be reused by a derived type.
290 procedure Make_Controlling_Function_Wrappers
291 (Tag_Typ
: Entity_Id
;
292 Decl_List
: out List_Id
;
293 Body_List
: out List_Id
);
294 -- Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
295 -- associated with inherited functions with controlling results which
296 -- are not overridden. The body of each wrapper function consists solely
297 -- of a return statement whose expression is an extension aggregate
298 -- invoking the inherited subprogram's parent subprogram and extended
299 -- with a null association list.
301 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
;
302 -- Ada 2005 (AI-251): Makes specs for null procedures associated with any
303 -- null procedures inherited from an interface type that have not been
304 -- overridden. Only one null procedure will be created for a given set of
305 -- inherited null procedures with homographic profiles.
307 function Predef_Spec_Or_Body
312 Ret_Type
: Entity_Id
:= Empty
;
313 For_Body
: Boolean := False) return Node_Id
;
314 -- This function generates the appropriate expansion for a predefined
315 -- primitive operation specified by its name, parameter profile and
316 -- return type (Empty means this is a procedure). If For_Body is false,
317 -- then the returned node is a subprogram declaration. If For_Body is
318 -- true, then the returned node is a empty subprogram body containing
319 -- no declarations and no statements.
321 function Predef_Stream_Attr_Spec
324 Name
: TSS_Name_Type
;
325 For_Body
: Boolean := False) return Node_Id
;
326 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
327 -- input and output attribute whose specs are constructed in Exp_Strm.
329 function Predef_Deep_Spec
332 Name
: TSS_Name_Type
;
333 For_Body
: Boolean := False) return Node_Id
;
334 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
335 -- and _deep_finalize
337 function Predefined_Primitive_Bodies
338 (Tag_Typ
: Entity_Id
;
339 Renamed_Eq
: Entity_Id
) return List_Id
;
340 -- Create the bodies of the predefined primitives that are described in
341 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
342 -- the defining unit name of the type's predefined equality as returned
343 -- by Make_Predefined_Primitive_Specs.
345 function Predefined_Primitive_Freeze
(Tag_Typ
: Entity_Id
) return List_Id
;
346 -- Freeze entities of all predefined primitive operations. This is needed
347 -- because the bodies of these operations do not normally do any freezing.
349 function Stream_Operation_OK
351 Operation
: TSS_Name_Type
) return Boolean;
352 -- Check whether the named stream operation must be emitted for a given
353 -- type. The rules for inheritance of stream attributes by type extensions
354 -- are enforced by this function. Furthermore, various restrictions prevent
355 -- the generation of these operations, as a useful optimization or for
356 -- certification purposes and to save unnecessary generated code.
358 --------------------------
359 -- Adjust_Discriminants --
360 --------------------------
362 -- This procedure attempts to define subtypes for discriminants that are
363 -- more restrictive than those declared. Such a replacement is possible if
364 -- we can demonstrate that values outside the restricted range would cause
365 -- constraint errors in any case. The advantage of restricting the
366 -- discriminant types in this way is that the maximum size of the variant
367 -- record can be calculated more conservatively.
369 -- An example of a situation in which we can perform this type of
370 -- restriction is the following:
372 -- subtype B is range 1 .. 10;
373 -- type Q is array (B range <>) of Integer;
375 -- type V (N : Natural) is record
379 -- In this situation, we can restrict the upper bound of N to 10, since
380 -- any larger value would cause a constraint error in any case.
382 -- There are many situations in which such restriction is possible, but
383 -- for now, we just look for cases like the above, where the component
384 -- in question is a one dimensional array whose upper bound is one of
385 -- the record discriminants. Also the component must not be part of
386 -- any variant part, since then the component does not always exist.
388 procedure Adjust_Discriminants
(Rtype
: Entity_Id
) is
389 Loc
: constant Source_Ptr
:= Sloc
(Rtype
);
406 Comp
:= First_Component
(Rtype
);
407 while Present
(Comp
) loop
409 -- If our parent is a variant, quit, we do not look at components
410 -- that are in variant parts, because they may not always exist.
412 P
:= Parent
(Comp
); -- component declaration
413 P
:= Parent
(P
); -- component list
415 exit when Nkind
(Parent
(P
)) = N_Variant
;
417 -- We are looking for a one dimensional array type
419 Ctyp
:= Etype
(Comp
);
421 if not Is_Array_Type
(Ctyp
) or else Number_Dimensions
(Ctyp
) > 1 then
425 -- The lower bound must be constant, and the upper bound is a
426 -- discriminant (which is a discriminant of the current record).
428 Ityp
:= Etype
(First_Index
(Ctyp
));
429 Lo
:= Type_Low_Bound
(Ityp
);
430 Hi
:= Type_High_Bound
(Ityp
);
432 if not Compile_Time_Known_Value
(Lo
)
433 or else Nkind
(Hi
) /= N_Identifier
434 or else No
(Entity
(Hi
))
435 or else Ekind
(Entity
(Hi
)) /= E_Discriminant
440 -- We have an array with appropriate bounds
442 Loval
:= Expr_Value
(Lo
);
443 Discr
:= Entity
(Hi
);
444 Dtyp
:= Etype
(Discr
);
446 -- See if the discriminant has a known upper bound
448 Dhi
:= Type_High_Bound
(Dtyp
);
450 if not Compile_Time_Known_Value
(Dhi
) then
454 Dhiv
:= Expr_Value
(Dhi
);
456 -- See if base type of component array has known upper bound
458 Ahi
:= Type_High_Bound
(Etype
(First_Index
(Base_Type
(Ctyp
))));
460 if not Compile_Time_Known_Value
(Ahi
) then
464 Ahiv
:= Expr_Value
(Ahi
);
466 -- The condition for doing the restriction is that the high bound
467 -- of the discriminant is greater than the low bound of the array,
468 -- and is also greater than the high bound of the base type index.
470 if Dhiv
> Loval
and then Dhiv
> Ahiv
then
472 -- We can reset the upper bound of the discriminant type to
473 -- whichever is larger, the low bound of the component, or
474 -- the high bound of the base type array index.
476 -- We build a subtype that is declared as
478 -- subtype Tnn is discr_type range discr_type'First .. max;
480 -- And insert this declaration into the tree. The type of the
481 -- discriminant is then reset to this more restricted subtype.
483 Tnn
:= Make_Temporary
(Loc
, 'T');
485 Insert_Action
(Declaration_Node
(Rtype
),
486 Make_Subtype_Declaration
(Loc
,
487 Defining_Identifier
=> Tnn
,
488 Subtype_Indication
=>
489 Make_Subtype_Indication
(Loc
,
490 Subtype_Mark
=> New_Occurrence_Of
(Dtyp
, Loc
),
492 Make_Range_Constraint
(Loc
,
496 Make_Attribute_Reference
(Loc
,
497 Attribute_Name
=> Name_First
,
498 Prefix
=> New_Occurrence_Of
(Dtyp
, Loc
)),
500 Make_Integer_Literal
(Loc
,
501 Intval
=> UI_Max
(Loval
, Ahiv
)))))));
503 Set_Etype
(Discr
, Tnn
);
507 Next_Component
(Comp
);
509 end Adjust_Discriminants
;
511 ---------------------------
512 -- Build_Array_Init_Proc --
513 ---------------------------
515 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
) is
516 Comp_Type
: constant Entity_Id
:= Component_Type
(A_Type
);
517 Comp_Simple_Init
: constant Boolean :=
518 Needs_Simple_Initialization
521 not (Validity_Check_Copies
and Is_Bit_Packed_Array
(A_Type
)));
522 -- True if the component needs simple initialization, based on its type,
523 -- plus the fact that we do not do simple initialization for components
524 -- of bit-packed arrays when validity checks are enabled, because the
525 -- initialization with deliberately out-of-range values would raise
528 Body_Stmts
: List_Id
;
529 Has_Default_Init
: Boolean;
530 Index_List
: List_Id
;
534 function Init_Component
return List_Id
;
535 -- Create one statement to initialize one array component, designated
536 -- by a full set of indexes.
538 function Init_One_Dimension
(N
: Int
) return List_Id
;
539 -- Create loop to initialize one dimension of the array. The single
540 -- statement in the loop body initializes the inner dimensions if any,
541 -- or else the single component. Note that this procedure is called
542 -- recursively, with N being the dimension to be initialized. A call
543 -- with N greater than the number of dimensions simply generates the
544 -- component initialization, terminating the recursion.
550 function Init_Component
return List_Id
is
555 Make_Indexed_Component
(Loc
,
556 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
557 Expressions
=> Index_List
);
559 if Has_Default_Aspect
(A_Type
) then
560 Set_Assignment_OK
(Comp
);
562 Make_Assignment_Statement
(Loc
,
565 Convert_To
(Comp_Type
,
566 Default_Aspect_Component_Value
(First_Subtype
(A_Type
)))));
568 elsif Comp_Simple_Init
then
569 Set_Assignment_OK
(Comp
);
571 Make_Assignment_Statement
(Loc
,
577 Size
=> Component_Size
(A_Type
))));
580 Clean_Task_Names
(Comp_Type
, Proc_Id
);
582 Build_Initialization_Call
586 In_Init_Proc
=> True,
587 Enclos_Type
=> A_Type
);
591 ------------------------
592 -- Init_One_Dimension --
593 ------------------------
595 function Init_One_Dimension
(N
: Int
) return List_Id
is
599 -- If the component does not need initializing, then there is nothing
600 -- to do here, so we return a null body. This occurs when generating
601 -- the dummy Init_Proc needed for Initialize_Scalars processing.
603 if not Has_Non_Null_Base_Init_Proc
(Comp_Type
)
604 and then not Comp_Simple_Init
605 and then not Has_Task
(Comp_Type
)
606 and then not Has_Default_Aspect
(A_Type
)
608 return New_List
(Make_Null_Statement
(Loc
));
610 -- If all dimensions dealt with, we simply initialize the component
612 elsif N
> Number_Dimensions
(A_Type
) then
613 return Init_Component
;
615 -- Here we generate the required loop
619 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
621 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
624 Make_Implicit_Loop_Statement
(Nod
,
627 Make_Iteration_Scheme
(Loc
,
628 Loop_Parameter_Specification
=>
629 Make_Loop_Parameter_Specification
(Loc
,
630 Defining_Identifier
=> Index
,
631 Discrete_Subtype_Definition
=>
632 Make_Attribute_Reference
(Loc
,
634 Make_Identifier
(Loc
, Name_uInit
),
635 Attribute_Name
=> Name_Range
,
636 Expressions
=> New_List
(
637 Make_Integer_Literal
(Loc
, N
))))),
638 Statements
=> Init_One_Dimension
(N
+ 1)));
640 end Init_One_Dimension
;
642 -- Start of processing for Build_Array_Init_Proc
645 -- The init proc is created when analyzing the freeze node for the type,
646 -- but it properly belongs with the array type declaration. However, if
647 -- the freeze node is for a subtype of a type declared in another unit
648 -- it seems preferable to use the freeze node as the source location of
649 -- the init proc. In any case this is preferable for gcov usage, and
650 -- the Sloc is not otherwise used by the compiler.
652 if In_Open_Scopes
(Scope
(A_Type
)) then
653 Loc
:= Sloc
(A_Type
);
658 -- Nothing to generate in the following cases:
660 -- 1. Initialization is suppressed for the type
661 -- 2. An initialization already exists for the base type
663 if Initialization_Suppressed
(A_Type
)
664 or else Present
(Base_Init_Proc
(A_Type
))
669 Index_List
:= New_List
;
671 -- We need an initialization procedure if any of the following is true:
673 -- 1. The component type has an initialization procedure
674 -- 2. The component type needs simple initialization
675 -- 3. Tasks are present
676 -- 4. The type is marked as a public entity
677 -- 5. The array type has a Default_Component_Value aspect
679 -- The reason for the public entity test is to deal properly with the
680 -- Initialize_Scalars pragma. This pragma can be set in the client and
681 -- not in the declaring package, this means the client will make a call
682 -- to the initialization procedure (because one of conditions 1-3 must
683 -- apply in this case), and we must generate a procedure (even if it is
684 -- null) to satisfy the call in this case.
686 -- Exception: do not build an array init_proc for a type whose root
687 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
688 -- is no place to put the code, and in any case we handle initialization
689 -- of such types (in the Initialize_Scalars case, that's the only time
690 -- the issue arises) in a special manner anyway which does not need an
693 Has_Default_Init
:= Has_Non_Null_Base_Init_Proc
(Comp_Type
)
694 or else Comp_Simple_Init
695 or else Has_Task
(Comp_Type
)
696 or else Has_Default_Aspect
(A_Type
);
699 or else (not Restriction_Active
(No_Initialize_Scalars
)
700 and then Is_Public
(A_Type
)
701 and then not Is_Standard_String_Type
(A_Type
))
704 Make_Defining_Identifier
(Loc
,
705 Chars
=> Make_Init_Proc_Name
(A_Type
));
707 -- If No_Default_Initialization restriction is active, then we don't
708 -- want to build an init_proc, but we need to mark that an init_proc
709 -- would be needed if this restriction was not active (so that we can
710 -- detect attempts to call it), so set a dummy init_proc in place.
711 -- This is only done though when actual default initialization is
712 -- needed (and not done when only Is_Public is True), since otherwise
713 -- objects such as arrays of scalars could be wrongly flagged as
714 -- violating the restriction.
716 if Restriction_Active
(No_Default_Initialization
) then
717 if Has_Default_Init
then
718 Set_Init_Proc
(A_Type
, Proc_Id
);
724 Body_Stmts
:= Init_One_Dimension
(1);
727 Make_Subprogram_Body
(Loc
,
729 Make_Procedure_Specification
(Loc
,
730 Defining_Unit_Name
=> Proc_Id
,
731 Parameter_Specifications
=> Init_Formals
(A_Type
)),
732 Declarations
=> New_List
,
733 Handled_Statement_Sequence
=>
734 Make_Handled_Sequence_Of_Statements
(Loc
,
735 Statements
=> Body_Stmts
)));
737 Set_Ekind
(Proc_Id
, E_Procedure
);
738 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
739 Set_Is_Internal
(Proc_Id
);
740 Set_Has_Completion
(Proc_Id
);
742 if not Debug_Generated_Code
then
743 Set_Debug_Info_Off
(Proc_Id
);
746 -- Set Inlined on Init_Proc if it is set on the Init_Proc of the
747 -- component type itself (see also Build_Record_Init_Proc).
749 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Comp_Type
));
751 -- Associate Init_Proc with type, and determine if the procedure
752 -- is null (happens because of the Initialize_Scalars pragma case,
753 -- where we have to generate a null procedure in case it is called
754 -- by a client with Initialize_Scalars set). Such procedures have
755 -- to be generated, but do not have to be called, so we mark them
756 -- as null to suppress the call.
758 Set_Init_Proc
(A_Type
, Proc_Id
);
760 if List_Length
(Body_Stmts
) = 1
762 -- We must skip SCIL nodes because they may have been added to this
763 -- list by Insert_Actions.
765 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
767 Set_Is_Null_Init_Proc
(Proc_Id
);
770 -- Try to build a static aggregate to statically initialize
771 -- objects of the type. This can only be done for constrained
772 -- one-dimensional arrays with static bounds.
774 Set_Static_Initialization
776 Build_Equivalent_Array_Aggregate
(First_Subtype
(A_Type
)));
779 end Build_Array_Init_Proc
;
781 --------------------------------
782 -- Build_Discr_Checking_Funcs --
783 --------------------------------
785 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
) is
788 Enclosing_Func_Id
: Entity_Id
;
793 function Build_Case_Statement
794 (Case_Id
: Entity_Id
;
795 Variant
: Node_Id
) return Node_Id
;
796 -- Build a case statement containing only two alternatives. The first
797 -- alternative corresponds exactly to the discrete choices given on the
798 -- variant with contains the components that we are generating the
799 -- checks for. If the discriminant is one of these return False. The
800 -- second alternative is an OTHERS choice that will return True
801 -- indicating the discriminant did not match.
803 function Build_Dcheck_Function
804 (Case_Id
: Entity_Id
;
805 Variant
: Node_Id
) return Entity_Id
;
806 -- Build the discriminant checking function for a given variant
808 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
);
809 -- Builds the discriminant checking function for each variant of the
810 -- given variant part of the record type.
812 --------------------------
813 -- Build_Case_Statement --
814 --------------------------
816 function Build_Case_Statement
817 (Case_Id
: Entity_Id
;
818 Variant
: Node_Id
) return Node_Id
820 Alt_List
: constant List_Id
:= New_List
;
821 Actuals_List
: List_Id
;
823 Case_Alt_Node
: Node_Id
;
825 Choice_List
: List_Id
;
827 Return_Node
: Node_Id
;
830 Case_Node
:= New_Node
(N_Case_Statement
, Loc
);
832 -- Replace the discriminant which controls the variant with the name
833 -- of the formal of the checking function.
835 Set_Expression
(Case_Node
, Make_Identifier
(Loc
, Chars
(Case_Id
)));
837 Choice
:= First
(Discrete_Choices
(Variant
));
839 if Nkind
(Choice
) = N_Others_Choice
then
840 Choice_List
:= New_Copy_List
(Others_Discrete_Choices
(Choice
));
842 Choice_List
:= New_Copy_List
(Discrete_Choices
(Variant
));
845 if not Is_Empty_List
(Choice_List
) then
846 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
847 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
849 -- In case this is a nested variant, we need to return the result
850 -- of the discriminant checking function for the immediately
851 -- enclosing variant.
853 if Present
(Enclosing_Func_Id
) then
854 Actuals_List
:= New_List
;
856 D
:= First_Discriminant
(Rec_Id
);
857 while Present
(D
) loop
858 Append
(Make_Identifier
(Loc
, Chars
(D
)), Actuals_List
);
859 Next_Discriminant
(D
);
863 Make_Simple_Return_Statement
(Loc
,
865 Make_Function_Call
(Loc
,
867 New_Occurrence_Of
(Enclosing_Func_Id
, Loc
),
868 Parameter_Associations
=>
873 Make_Simple_Return_Statement
(Loc
,
875 New_Occurrence_Of
(Standard_False
, Loc
));
878 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
879 Append
(Case_Alt_Node
, Alt_List
);
882 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
883 Choice_List
:= New_List
(New_Node
(N_Others_Choice
, Loc
));
884 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
887 Make_Simple_Return_Statement
(Loc
,
889 New_Occurrence_Of
(Standard_True
, Loc
));
891 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
892 Append
(Case_Alt_Node
, Alt_List
);
894 Set_Alternatives
(Case_Node
, Alt_List
);
896 end Build_Case_Statement
;
898 ---------------------------
899 -- Build_Dcheck_Function --
900 ---------------------------
902 function Build_Dcheck_Function
903 (Case_Id
: Entity_Id
;
904 Variant
: Node_Id
) return Entity_Id
908 Parameter_List
: List_Id
;
912 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
913 Sequence
:= Sequence
+ 1;
916 Make_Defining_Identifier
(Loc
,
917 Chars
=> New_External_Name
(Chars
(Rec_Id
), 'D', Sequence
));
918 Set_Is_Discriminant_Check_Function
(Func_Id
);
920 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
921 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
923 Parameter_List
:= Build_Discriminant_Formals
(Rec_Id
, False);
925 Set_Parameter_Specifications
(Spec_Node
, Parameter_List
);
926 Set_Result_Definition
(Spec_Node
,
927 New_Occurrence_Of
(Standard_Boolean
, Loc
));
928 Set_Specification
(Body_Node
, Spec_Node
);
929 Set_Declarations
(Body_Node
, New_List
);
931 Set_Handled_Statement_Sequence
(Body_Node
,
932 Make_Handled_Sequence_Of_Statements
(Loc
,
933 Statements
=> New_List
(
934 Build_Case_Statement
(Case_Id
, Variant
))));
936 Set_Ekind
(Func_Id
, E_Function
);
937 Set_Mechanism
(Func_Id
, Default_Mechanism
);
938 Set_Is_Inlined
(Func_Id
, True);
939 Set_Is_Pure
(Func_Id
, True);
940 Set_Is_Public
(Func_Id
, Is_Public
(Rec_Id
));
941 Set_Is_Internal
(Func_Id
, True);
943 if not Debug_Generated_Code
then
944 Set_Debug_Info_Off
(Func_Id
);
949 Append_Freeze_Action
(Rec_Id
, Body_Node
);
950 Set_Dcheck_Function
(Variant
, Func_Id
);
952 end Build_Dcheck_Function
;
954 ----------------------------
955 -- Build_Dcheck_Functions --
956 ----------------------------
958 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
) is
959 Component_List_Node
: Node_Id
;
961 Discr_Name
: Entity_Id
;
964 Saved_Enclosing_Func_Id
: Entity_Id
;
967 -- Build the discriminant-checking function for each variant, and
968 -- label all components of that variant with the function's name.
969 -- We only Generate a discriminant-checking function when the
970 -- variant is not empty, to prevent the creation of dead code.
972 Discr_Name
:= Entity
(Name
(Variant_Part_Node
));
973 Variant
:= First_Non_Pragma
(Variants
(Variant_Part_Node
));
975 while Present
(Variant
) loop
976 Component_List_Node
:= Component_List
(Variant
);
978 if not Null_Present
(Component_List_Node
) then
979 Func_Id
:= Build_Dcheck_Function
(Discr_Name
, Variant
);
982 First_Non_Pragma
(Component_Items
(Component_List_Node
));
983 while Present
(Decl
) loop
984 Set_Discriminant_Checking_Func
985 (Defining_Identifier
(Decl
), Func_Id
);
986 Next_Non_Pragma
(Decl
);
989 if Present
(Variant_Part
(Component_List_Node
)) then
990 Saved_Enclosing_Func_Id
:= Enclosing_Func_Id
;
991 Enclosing_Func_Id
:= Func_Id
;
992 Build_Dcheck_Functions
(Variant_Part
(Component_List_Node
));
993 Enclosing_Func_Id
:= Saved_Enclosing_Func_Id
;
997 Next_Non_Pragma
(Variant
);
999 end Build_Dcheck_Functions
;
1001 -- Start of processing for Build_Discr_Checking_Funcs
1004 -- Only build if not done already
1006 if not Discr_Check_Funcs_Built
(N
) then
1007 Type_Def
:= Type_Definition
(N
);
1009 if Nkind
(Type_Def
) = N_Record_Definition
then
1010 if No
(Component_List
(Type_Def
)) then -- null record.
1013 V
:= Variant_Part
(Component_List
(Type_Def
));
1016 else pragma Assert
(Nkind
(Type_Def
) = N_Derived_Type_Definition
);
1017 if No
(Component_List
(Record_Extension_Part
(Type_Def
))) then
1021 (Component_List
(Record_Extension_Part
(Type_Def
)));
1025 Rec_Id
:= Defining_Identifier
(N
);
1027 if Present
(V
) and then not Is_Unchecked_Union
(Rec_Id
) then
1029 Enclosing_Func_Id
:= Empty
;
1030 Build_Dcheck_Functions
(V
);
1033 Set_Discr_Check_Funcs_Built
(N
);
1035 end Build_Discr_Checking_Funcs
;
1037 --------------------------------
1038 -- Build_Discriminant_Formals --
1039 --------------------------------
1041 function Build_Discriminant_Formals
1042 (Rec_Id
: Entity_Id
;
1043 Use_Dl
: Boolean) return List_Id
1045 Loc
: Source_Ptr
:= Sloc
(Rec_Id
);
1046 Parameter_List
: constant List_Id
:= New_List
;
1049 Formal_Type
: Entity_Id
;
1050 Param_Spec_Node
: Node_Id
;
1053 if Has_Discriminants
(Rec_Id
) then
1054 D
:= First_Discriminant
(Rec_Id
);
1055 while Present
(D
) loop
1059 Formal
:= Discriminal
(D
);
1060 Formal_Type
:= Etype
(Formal
);
1062 Formal
:= Make_Defining_Identifier
(Loc
, Chars
(D
));
1063 Formal_Type
:= Etype
(D
);
1067 Make_Parameter_Specification
(Loc
,
1068 Defining_Identifier
=> Formal
,
1070 New_Occurrence_Of
(Formal_Type
, Loc
));
1071 Append
(Param_Spec_Node
, Parameter_List
);
1072 Next_Discriminant
(D
);
1076 return Parameter_List
;
1077 end Build_Discriminant_Formals
;
1079 --------------------------------------
1080 -- Build_Equivalent_Array_Aggregate --
1081 --------------------------------------
1083 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
is
1084 Loc
: constant Source_Ptr
:= Sloc
(T
);
1085 Comp_Type
: constant Entity_Id
:= Component_Type
(T
);
1086 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(T
));
1087 Proc
: constant Entity_Id
:= Base_Init_Proc
(T
);
1093 if not Is_Constrained
(T
)
1094 or else Number_Dimensions
(T
) > 1
1097 Initialization_Warning
(T
);
1101 Lo
:= Type_Low_Bound
(Index_Type
);
1102 Hi
:= Type_High_Bound
(Index_Type
);
1104 if not Compile_Time_Known_Value
(Lo
)
1105 or else not Compile_Time_Known_Value
(Hi
)
1107 Initialization_Warning
(T
);
1111 if Is_Record_Type
(Comp_Type
)
1112 and then Present
(Base_Init_Proc
(Comp_Type
))
1114 Expr
:= Static_Initialization
(Base_Init_Proc
(Comp_Type
));
1117 Initialization_Warning
(T
);
1122 Initialization_Warning
(T
);
1126 Aggr
:= Make_Aggregate
(Loc
, No_List
, New_List
);
1127 Set_Etype
(Aggr
, T
);
1128 Set_Aggregate_Bounds
(Aggr
,
1130 Low_Bound
=> New_Copy
(Lo
),
1131 High_Bound
=> New_Copy
(Hi
)));
1132 Set_Parent
(Aggr
, Parent
(Proc
));
1134 Append_To
(Component_Associations
(Aggr
),
1135 Make_Component_Association
(Loc
,
1139 Low_Bound
=> New_Copy
(Lo
),
1140 High_Bound
=> New_Copy
(Hi
))),
1141 Expression
=> Expr
));
1143 if Static_Array_Aggregate
(Aggr
) then
1146 Initialization_Warning
(T
);
1149 end Build_Equivalent_Array_Aggregate
;
1151 ---------------------------------------
1152 -- Build_Equivalent_Record_Aggregate --
1153 ---------------------------------------
1155 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
is
1158 Comp_Type
: Entity_Id
;
1160 -- Start of processing for Build_Equivalent_Record_Aggregate
1163 if not Is_Record_Type
(T
)
1164 or else Has_Discriminants
(T
)
1165 or else Is_Limited_Type
(T
)
1166 or else Has_Non_Standard_Rep
(T
)
1168 Initialization_Warning
(T
);
1172 Comp
:= First_Component
(T
);
1174 -- A null record needs no warning
1180 while Present
(Comp
) loop
1182 -- Array components are acceptable if initialized by a positional
1183 -- aggregate with static components.
1185 if Is_Array_Type
(Etype
(Comp
)) then
1186 Comp_Type
:= Component_Type
(Etype
(Comp
));
1188 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1189 or else No
(Expression
(Parent
(Comp
)))
1190 or else Nkind
(Expression
(Parent
(Comp
))) /= N_Aggregate
1192 Initialization_Warning
(T
);
1195 elsif Is_Scalar_Type
(Component_Type
(Etype
(Comp
)))
1197 (not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1199 not Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
)))
1201 Initialization_Warning
(T
);
1205 not Static_Array_Aggregate
(Expression
(Parent
(Comp
)))
1207 Initialization_Warning
(T
);
1211 elsif Is_Scalar_Type
(Etype
(Comp
)) then
1212 Comp_Type
:= Etype
(Comp
);
1214 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1215 or else No
(Expression
(Parent
(Comp
)))
1216 or else not Compile_Time_Known_Value
(Expression
(Parent
(Comp
)))
1217 or else not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1219 Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
))
1221 Initialization_Warning
(T
);
1225 -- For now, other types are excluded
1228 Initialization_Warning
(T
);
1232 Next_Component
(Comp
);
1235 -- All components have static initialization. Build positional aggregate
1236 -- from the given expressions or defaults.
1238 Agg
:= Make_Aggregate
(Sloc
(T
), New_List
, New_List
);
1239 Set_Parent
(Agg
, Parent
(T
));
1241 Comp
:= First_Component
(T
);
1242 while Present
(Comp
) loop
1244 (New_Copy_Tree
(Expression
(Parent
(Comp
))), Expressions
(Agg
));
1245 Next_Component
(Comp
);
1248 Analyze_And_Resolve
(Agg
, T
);
1250 end Build_Equivalent_Record_Aggregate
;
1252 -------------------------------
1253 -- Build_Initialization_Call --
1254 -------------------------------
1256 -- References to a discriminant inside the record type declaration can
1257 -- appear either in the subtype_indication to constrain a record or an
1258 -- array, or as part of a larger expression given for the initial value
1259 -- of a component. In both of these cases N appears in the record
1260 -- initialization procedure and needs to be replaced by the formal
1261 -- parameter of the initialization procedure which corresponds to that
1264 -- In the example below, references to discriminants D1 and D2 in proc_1
1265 -- are replaced by references to formals with the same name
1268 -- A similar replacement is done for calls to any record initialization
1269 -- procedure for any components that are themselves of a record type.
1271 -- type R (D1, D2 : Integer) is record
1272 -- X : Integer := F * D1;
1273 -- Y : Integer := F * D2;
1276 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1280 -- Out_2.X := F * D1;
1281 -- Out_2.Y := F * D2;
1284 function Build_Initialization_Call
1288 In_Init_Proc
: Boolean := False;
1289 Enclos_Type
: Entity_Id
:= Empty
;
1290 Discr_Map
: Elist_Id
:= New_Elmt_List
;
1291 With_Default_Init
: Boolean := False;
1292 Constructor_Ref
: Node_Id
:= Empty
) return List_Id
1294 Res
: constant List_Id
:= New_List
;
1296 Full_Type
: Entity_Id
;
1298 procedure Check_Predicated_Discriminant
1301 -- Discriminants whose subtypes have predicates are checked in two
1303 -- a) When an object is default-initialized and assertions are enabled
1304 -- we check that the value of the discriminant obeys the predicate.
1306 -- b) In all cases, if the discriminant controls a variant and the
1307 -- variant has no others_choice, Constraint_Error must be raised if
1308 -- the predicate is violated, because there is no variant covered
1309 -- by the illegal discriminant value.
1311 -----------------------------------
1312 -- Check_Predicated_Discriminant --
1313 -----------------------------------
1315 procedure Check_Predicated_Discriminant
1319 Typ
: constant Entity_Id
:= Etype
(Discr
);
1321 procedure Check_Missing_Others
(V
: Node_Id
);
1324 --------------------------
1325 -- Check_Missing_Others --
1326 --------------------------
1328 procedure Check_Missing_Others
(V
: Node_Id
) is
1334 Last_Var
:= Last_Non_Pragma
(Variants
(V
));
1335 Choice
:= First
(Discrete_Choices
(Last_Var
));
1337 -- An others_choice is added during expansion for gcc use, but
1338 -- does not cover the illegality.
1340 if Entity
(Name
(V
)) = Discr
then
1342 and then (Nkind
(Choice
) /= N_Others_Choice
1343 or else not Comes_From_Source
(Choice
))
1345 Check_Expression_Against_Static_Predicate
(Val
, Typ
);
1347 if not Is_Static_Expression
(Val
) then
1349 Make_Raise_Constraint_Error
(Loc
,
1352 Right_Opnd
=> Make_Predicate_Call
(Typ
, Val
)),
1353 Reason
=> CE_Invalid_Data
));
1358 -- Check whether some nested variant is ruled by the predicated
1361 Alt
:= First
(Variants
(V
));
1362 while Present
(Alt
) loop
1363 if Nkind
(Alt
) = N_Variant
1364 and then Present
(Variant_Part
(Component_List
(Alt
)))
1366 Check_Missing_Others
1367 (Variant_Part
(Component_List
(Alt
)));
1372 end Check_Missing_Others
;
1378 -- Start of processing for Check_Predicated_Discriminant
1381 if Ekind
(Base_Type
(Full_Type
)) = E_Record_Type
then
1382 Def
:= Type_Definition
(Parent
(Base_Type
(Full_Type
)));
1387 if Policy_In_Effect
(Name_Assert
) = Name_Check
1388 and then not Predicates_Ignored
(Etype
(Discr
))
1390 Prepend_To
(Res
, Make_Predicate_Check
(Typ
, Val
));
1393 -- If discriminant controls a variant, verify that predicate is
1394 -- obeyed or else an Others_Choice is present.
1396 if Nkind
(Def
) = N_Record_Definition
1397 and then Present
(Variant_Part
(Component_List
(Def
)))
1398 and then Policy_In_Effect
(Name_Assert
) = Name_Ignore
1400 Check_Missing_Others
(Variant_Part
(Component_List
(Def
)));
1402 end Check_Predicated_Discriminant
;
1411 First_Arg
: Node_Id
;
1412 Full_Init_Type
: Entity_Id
;
1413 Init_Call
: Node_Id
;
1414 Init_Type
: Entity_Id
;
1417 -- Start of processing for Build_Initialization_Call
1420 pragma Assert
(Constructor_Ref
= Empty
1421 or else Is_CPP_Constructor_Call
(Constructor_Ref
));
1423 if No
(Constructor_Ref
) then
1424 Proc
:= Base_Init_Proc
(Typ
);
1426 Proc
:= Base_Init_Proc
(Typ
, Entity
(Name
(Constructor_Ref
)));
1429 pragma Assert
(Present
(Proc
));
1430 Init_Type
:= Etype
(First_Formal
(Proc
));
1431 Full_Init_Type
:= Underlying_Type
(Init_Type
);
1433 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1434 -- is active (in which case we make the call anyway, since in the
1435 -- actual compiled client it may be non null).
1437 if Is_Null_Init_Proc
(Proc
) and then not Init_Or_Norm_Scalars
then
1440 -- Nothing to do for an array of controlled components that have only
1441 -- the inherited Initialize primitive. This is a useful optimization
1444 elsif Is_Trivial_Subprogram
(Proc
)
1445 and then Is_Array_Type
(Full_Init_Type
)
1447 return New_List
(Make_Null_Statement
(Loc
));
1450 -- Use the [underlying] full view when dealing with a private type. This
1451 -- may require several steps depending on derivations.
1455 if Is_Private_Type
(Full_Type
) then
1456 if Present
(Full_View
(Full_Type
)) then
1457 Full_Type
:= Full_View
(Full_Type
);
1459 elsif Present
(Underlying_Full_View
(Full_Type
)) then
1460 Full_Type
:= Underlying_Full_View
(Full_Type
);
1462 -- When a private type acts as a generic actual and lacks a full
1463 -- view, use the base type.
1465 elsif Is_Generic_Actual_Type
(Full_Type
) then
1466 Full_Type
:= Base_Type
(Full_Type
);
1468 elsif Ekind
(Full_Type
) = E_Private_Subtype
1469 and then (not Has_Discriminants
(Full_Type
)
1470 or else No
(Discriminant_Constraint
(Full_Type
)))
1472 Full_Type
:= Etype
(Full_Type
);
1474 -- The loop has recovered the [underlying] full view, stop the
1481 -- The type is not private, nothing to do
1488 -- If Typ is derived, the procedure is the initialization procedure for
1489 -- the root type. Wrap the argument in an conversion to make it type
1490 -- honest. Actually it isn't quite type honest, because there can be
1491 -- conflicts of views in the private type case. That is why we set
1492 -- Conversion_OK in the conversion node.
1494 if (Is_Record_Type
(Typ
)
1495 or else Is_Array_Type
(Typ
)
1496 or else Is_Private_Type
(Typ
))
1497 and then Init_Type
/= Base_Type
(Typ
)
1499 First_Arg
:= OK_Convert_To
(Etype
(Init_Type
), Id_Ref
);
1500 Set_Etype
(First_Arg
, Init_Type
);
1503 First_Arg
:= Id_Ref
;
1506 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Typ
));
1508 -- In the tasks case, add _Master as the value of the _Master parameter
1509 -- and _Chain as the value of the _Chain parameter. At the outer level,
1510 -- these will be variables holding the corresponding values obtained
1511 -- from GNARL. At inner levels, they will be the parameters passed down
1512 -- through the outer routines.
1514 if Has_Task
(Full_Type
) then
1515 if Restriction_Active
(No_Task_Hierarchy
) then
1517 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1519 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1522 -- Add _Chain (not done for sequential elaboration policy, see
1523 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1525 if Partition_Elaboration_Policy
/= 'S' then
1526 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1529 -- Ada 2005 (AI-287): In case of default initialized components
1530 -- with tasks, we generate a null string actual parameter.
1531 -- This is just a workaround that must be improved later???
1533 if With_Default_Init
then
1535 Make_String_Literal
(Loc
,
1540 Build_Task_Image_Decls
(Loc
, Id_Ref
, Enclos_Type
, In_Init_Proc
);
1541 Decl
:= Last
(Decls
);
1544 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
));
1545 Append_List
(Decls
, Res
);
1553 -- Handle the optionally generated formal *_skip_null_excluding_checks
1555 if Needs_Conditional_Null_Excluding_Check
(Full_Init_Type
) then
1557 -- Look at the associated node for the object we are referencing
1558 -- and verify that we are expanding a call to an Init_Proc for an
1559 -- internally generated object declaration before passing True and
1560 -- skipping the relevant checks.
1562 if Nkind
(Id_Ref
) in N_Has_Entity
1563 and then Comes_From_Source
(Associated_Node
(Id_Ref
))
1565 Append_To
(Args
, New_Occurrence_Of
(Standard_True
, Loc
));
1567 -- Otherwise, we pass False to perform null-excluding checks
1570 Append_To
(Args
, New_Occurrence_Of
(Standard_False
, Loc
));
1574 -- Add discriminant values if discriminants are present
1576 if Has_Discriminants
(Full_Init_Type
) then
1577 Discr
:= First_Discriminant
(Full_Init_Type
);
1578 while Present
(Discr
) loop
1580 -- If this is a discriminated concurrent type, the init_proc
1581 -- for the corresponding record is being called. Use that type
1582 -- directly to find the discriminant value, to handle properly
1583 -- intervening renamed discriminants.
1586 T
: Entity_Id
:= Full_Type
;
1589 if Is_Protected_Type
(T
) then
1590 T
:= Corresponding_Record_Type
(T
);
1594 Get_Discriminant_Value
(
1597 Discriminant_Constraint
(Full_Type
));
1600 -- If the target has access discriminants, and is constrained by
1601 -- an access to the enclosing construct, i.e. a current instance,
1602 -- replace the reference to the type by a reference to the object.
1604 if Nkind
(Arg
) = N_Attribute_Reference
1605 and then Is_Access_Type
(Etype
(Arg
))
1606 and then Is_Entity_Name
(Prefix
(Arg
))
1607 and then Is_Type
(Entity
(Prefix
(Arg
)))
1610 Make_Attribute_Reference
(Loc
,
1611 Prefix
=> New_Copy
(Prefix
(Id_Ref
)),
1612 Attribute_Name
=> Name_Unrestricted_Access
);
1614 elsif In_Init_Proc
then
1616 -- Replace any possible references to the discriminant in the
1617 -- call to the record initialization procedure with references
1618 -- to the appropriate formal parameter.
1620 if Nkind
(Arg
) = N_Identifier
1621 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1623 Arg
:= New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
);
1625 -- Otherwise make a copy of the default expression. Note that
1626 -- we use the current Sloc for this, because we do not want the
1627 -- call to appear to be at the declaration point. Within the
1628 -- expression, replace discriminants with their discriminals.
1632 New_Copy_Tree
(Arg
, Map
=> Discr_Map
, New_Sloc
=> Loc
);
1636 if Is_Constrained
(Full_Type
) then
1637 Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
1639 -- The constraints come from the discriminant default exps,
1640 -- they must be reevaluated, so we use New_Copy_Tree but we
1641 -- ensure the proper Sloc (for any embedded calls).
1642 -- In addition, if a predicate check is needed on the value
1643 -- of the discriminant, insert it ahead of the call.
1645 Arg
:= New_Copy_Tree
(Arg
, New_Sloc
=> Loc
);
1648 if Has_Predicates
(Etype
(Discr
)) then
1649 Check_Predicated_Discriminant
(Arg
, Discr
);
1653 -- Ada 2005 (AI-287): In case of default initialized components,
1654 -- if the component is constrained with a discriminant of the
1655 -- enclosing type, we need to generate the corresponding selected
1656 -- component node to access the discriminant value. In other cases
1657 -- this is not required, either because we are inside the init
1658 -- proc and we use the corresponding formal, or else because the
1659 -- component is constrained by an expression.
1661 if With_Default_Init
1662 and then Nkind
(Id_Ref
) = N_Selected_Component
1663 and then Nkind
(Arg
) = N_Identifier
1664 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1667 Make_Selected_Component
(Loc
,
1668 Prefix
=> New_Copy_Tree
(Prefix
(Id_Ref
)),
1669 Selector_Name
=> Arg
));
1671 Append_To
(Args
, Arg
);
1674 Next_Discriminant
(Discr
);
1678 -- If this is a call to initialize the parent component of a derived
1679 -- tagged type, indicate that the tag should not be set in the parent.
1681 if Is_Tagged_Type
(Full_Init_Type
)
1682 and then not Is_CPP_Class
(Full_Init_Type
)
1683 and then Nkind
(Id_Ref
) = N_Selected_Component
1684 and then Chars
(Selector_Name
(Id_Ref
)) = Name_uParent
1686 Append_To
(Args
, New_Occurrence_Of
(Standard_False
, Loc
));
1688 elsif Present
(Constructor_Ref
) then
1689 Append_List_To
(Args
,
1690 New_Copy_List
(Parameter_Associations
(Constructor_Ref
)));
1694 Make_Procedure_Call_Statement
(Loc
,
1695 Name
=> New_Occurrence_Of
(Proc
, Loc
),
1696 Parameter_Associations
=> Args
));
1698 if Needs_Finalization
(Typ
)
1699 and then Nkind
(Id_Ref
) = N_Selected_Component
1701 if Chars
(Selector_Name
(Id_Ref
)) /= Name_uParent
then
1704 (Obj_Ref
=> New_Copy_Tree
(First_Arg
),
1707 -- Guard against a missing [Deep_]Initialize when the type was not
1710 if Present
(Init_Call
) then
1711 Append_To
(Res
, Init_Call
);
1719 when RE_Not_Available
=>
1721 end Build_Initialization_Call
;
1723 ----------------------------
1724 -- Build_Record_Init_Proc --
1725 ----------------------------
1727 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
) is
1728 Decls
: constant List_Id
:= New_List
;
1729 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
1730 Loc
: constant Source_Ptr
:= Sloc
(Rec_Ent
);
1732 Proc_Id
: Entity_Id
;
1733 Rec_Type
: Entity_Id
;
1734 Set_Tag
: Entity_Id
:= Empty
;
1736 function Build_Assignment
1738 Default
: Node_Id
) return List_Id
;
1739 -- Build an assignment statement that assigns the default expression to
1740 -- its corresponding record component if defined. The left-hand side of
1741 -- the assignment is marked Assignment_OK so that initialization of
1742 -- limited private records works correctly. This routine may also build
1743 -- an adjustment call if the component is controlled.
1745 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
);
1746 -- If the record has discriminants, add assignment statements to
1747 -- Statement_List to initialize the discriminant values from the
1748 -- arguments of the initialization procedure.
1750 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
;
1751 -- Build a list representing a sequence of statements which initialize
1752 -- components of the given component list. This may involve building
1753 -- case statements for the variant parts. Append any locally declared
1754 -- objects on list Decls.
1756 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
;
1757 -- Given an untagged type-derivation that declares discriminants, e.g.
1759 -- type R (R1, R2 : Integer) is record ... end record;
1760 -- type D (D1 : Integer) is new R (1, D1);
1762 -- we make the _init_proc of D be
1764 -- procedure _init_proc (X : D; D1 : Integer) is
1766 -- _init_proc (R (X), 1, D1);
1769 -- This function builds the call statement in this _init_proc.
1771 procedure Build_CPP_Init_Procedure
;
1772 -- Build the tree corresponding to the procedure specification and body
1773 -- of the IC procedure that initializes the C++ part of the dispatch
1774 -- table of an Ada tagged type that is a derivation of a CPP type.
1775 -- Install it as the CPP_Init TSS.
1777 procedure Build_Init_Procedure
;
1778 -- Build the tree corresponding to the procedure specification and body
1779 -- of the initialization procedure and install it as the _init TSS.
1781 procedure Build_Offset_To_Top_Functions
;
1782 -- Ada 2005 (AI-251): Build the tree corresponding to the procedure spec
1783 -- and body of Offset_To_Top, a function used in conjuction with types
1784 -- having secondary dispatch tables.
1786 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
);
1787 -- Add range checks to components of discriminated records. S is a
1788 -- subtype indication of a record component. Check_List is a list
1789 -- to which the check actions are appended.
1791 function Component_Needs_Simple_Initialization
1792 (T
: Entity_Id
) return Boolean;
1793 -- Determine if a component needs simple initialization, given its type
1794 -- T. This routine is the same as Needs_Simple_Initialization except for
1795 -- components of type Tag and Interface_Tag. These two access types do
1796 -- not require initialization since they are explicitly initialized by
1799 function Parent_Subtype_Renaming_Discrims
return Boolean;
1800 -- Returns True for base types N that rename discriminants, else False
1802 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean;
1803 -- Determine whether a record initialization procedure needs to be
1804 -- generated for the given record type.
1806 ----------------------
1807 -- Build_Assignment --
1808 ----------------------
1810 function Build_Assignment
1812 Default
: Node_Id
) return List_Id
1814 Default_Loc
: constant Source_Ptr
:= Sloc
(Default
);
1815 Typ
: constant Entity_Id
:= Underlying_Type
(Etype
(Id
));
1818 Exp
: Node_Id
:= Default
;
1819 Kind
: Node_Kind
:= Nkind
(Default
);
1823 function Replace_Discr_Ref
(N
: Node_Id
) return Traverse_Result
;
1824 -- Analysis of the aggregate has replaced discriminants by their
1825 -- corresponding discriminals, but these are irrelevant when the
1826 -- component has a mutable type and is initialized with an aggregate.
1827 -- Instead, they must be replaced by the values supplied in the
1828 -- aggregate, that will be assigned during the expansion of the
1831 -----------------------
1832 -- Replace_Discr_Ref --
1833 -----------------------
1835 function Replace_Discr_Ref
(N
: Node_Id
) return Traverse_Result
is
1839 if Is_Entity_Name
(N
)
1840 and then Present
(Entity
(N
))
1841 and then Is_Formal
(Entity
(N
))
1842 and then Present
(Discriminal_Link
(Entity
(N
)))
1845 Make_Selected_Component
(Default_Loc
,
1846 Prefix
=> New_Copy_Tree
(Lhs
),
1849 (Discriminal_Link
(Entity
(N
)), Default_Loc
));
1851 if Present
(Val
) then
1852 Rewrite
(N
, New_Copy_Tree
(Val
));
1857 end Replace_Discr_Ref
;
1859 procedure Replace_Discriminant_References
is
1860 new Traverse_Proc
(Replace_Discr_Ref
);
1862 -- Start of processing for Build_Assignment
1866 Make_Selected_Component
(Default_Loc
,
1867 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1868 Selector_Name
=> New_Occurrence_Of
(Id
, Default_Loc
));
1869 Set_Assignment_OK
(Lhs
);
1871 if Nkind
(Exp
) = N_Aggregate
1872 and then Has_Discriminants
(Typ
)
1873 and then not Is_Constrained
(Base_Type
(Typ
))
1875 -- The aggregate may provide new values for the discriminants
1876 -- of the component, and other components may depend on those
1877 -- discriminants. Previous analysis of those expressions have
1878 -- replaced the discriminants by the formals of the initialization
1879 -- procedure for the type, but these are irrelevant in the
1880 -- enclosing initialization procedure: those discriminant
1881 -- references must be replaced by the values provided in the
1884 Replace_Discriminant_References
(Exp
);
1887 -- Case of an access attribute applied to the current instance.
1888 -- Replace the reference to the type by a reference to the actual
1889 -- object. (Note that this handles the case of the top level of
1890 -- the expression being given by such an attribute, but does not
1891 -- cover uses nested within an initial value expression. Nested
1892 -- uses are unlikely to occur in practice, but are theoretically
1893 -- possible.) It is not clear how to handle them without fully
1894 -- traversing the expression. ???
1896 if Kind
= N_Attribute_Reference
1897 and then Nam_In
(Attribute_Name
(Default
), Name_Unchecked_Access
,
1898 Name_Unrestricted_Access
)
1899 and then Is_Entity_Name
(Prefix
(Default
))
1900 and then Is_Type
(Entity
(Prefix
(Default
)))
1901 and then Entity
(Prefix
(Default
)) = Rec_Type
1904 Make_Attribute_Reference
(Default_Loc
,
1906 Make_Identifier
(Default_Loc
, Name_uInit
),
1907 Attribute_Name
=> Name_Unrestricted_Access
);
1910 -- Take a copy of Exp to ensure that later copies of this component
1911 -- declaration in derived types see the original tree, not a node
1912 -- rewritten during expansion of the init_proc. If the copy contains
1913 -- itypes, the scope of the new itypes is the init_proc being built.
1915 Exp
:= New_Copy_Tree
(Exp
, New_Scope
=> Proc_Id
);
1918 Make_Assignment_Statement
(Loc
,
1920 Expression
=> Exp
));
1922 Set_No_Ctrl_Actions
(First
(Res
));
1924 -- Adjust the tag if tagged (because of possible view conversions).
1925 -- Suppress the tag adjustment when not Tagged_Type_Expansion because
1926 -- tags are represented implicitly in objects.
1928 if Is_Tagged_Type
(Typ
) and then Tagged_Type_Expansion
then
1930 Make_Assignment_Statement
(Default_Loc
,
1932 Make_Selected_Component
(Default_Loc
,
1934 New_Copy_Tree
(Lhs
, New_Scope
=> Proc_Id
),
1937 (First_Tag_Component
(Typ
), Default_Loc
)),
1940 Unchecked_Convert_To
(RTE
(RE_Tag
),
1942 (Node
(First_Elmt
(Access_Disp_Table
(Underlying_Type
1947 -- Adjust the component if controlled except if it is an aggregate
1948 -- that will be expanded inline.
1950 if Kind
= N_Qualified_Expression
then
1951 Kind
:= Nkind
(Expression
(Default
));
1954 if Needs_Finalization
(Typ
)
1955 and then not (Nkind_In
(Kind
, N_Aggregate
, N_Extension_Aggregate
))
1956 and then not Is_Build_In_Place_Function_Call
(Exp
)
1960 (Obj_Ref
=> New_Copy_Tree
(Lhs
),
1963 -- Guard against a missing [Deep_]Adjust when the component type
1964 -- was not properly frozen.
1966 if Present
(Adj_Call
) then
1967 Append_To
(Res
, Adj_Call
);
1971 -- If a component type has a predicate, add check to the component
1972 -- assignment. Discriminants are handled at the point of the call,
1973 -- which provides for a better error message.
1975 if Comes_From_Source
(Exp
)
1976 and then Has_Predicates
(Typ
)
1977 and then not Predicate_Checks_Suppressed
(Empty
)
1978 and then not Predicates_Ignored
(Typ
)
1980 Append
(Make_Predicate_Check
(Typ
, Exp
), Res
);
1986 when RE_Not_Available
=>
1988 end Build_Assignment
;
1990 ------------------------------------
1991 -- Build_Discriminant_Assignments --
1992 ------------------------------------
1994 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
) is
1995 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Rec_Type
);
2000 if Has_Discriminants
(Rec_Type
)
2001 and then not Is_Unchecked_Union
(Rec_Type
)
2003 D
:= First_Discriminant
(Rec_Type
);
2004 while Present
(D
) loop
2006 -- Don't generate the assignment for discriminants in derived
2007 -- tagged types if the discriminant is a renaming of some
2008 -- ancestor discriminant. This initialization will be done
2009 -- when initializing the _parent field of the derived record.
2012 and then Present
(Corresponding_Discriminant
(D
))
2018 Append_List_To
(Statement_List
,
2019 Build_Assignment
(D
,
2020 New_Occurrence_Of
(Discriminal
(D
), D_Loc
)));
2023 Next_Discriminant
(D
);
2026 end Build_Discriminant_Assignments
;
2028 --------------------------
2029 -- Build_Init_Call_Thru --
2030 --------------------------
2032 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
is
2033 Parent_Proc
: constant Entity_Id
:=
2034 Base_Init_Proc
(Etype
(Rec_Type
));
2036 Parent_Type
: constant Entity_Id
:=
2037 Etype
(First_Formal
(Parent_Proc
));
2039 Uparent_Type
: constant Entity_Id
:=
2040 Underlying_Type
(Parent_Type
);
2042 First_Discr_Param
: Node_Id
;
2046 First_Arg
: Node_Id
;
2047 Parent_Discr
: Entity_Id
;
2051 -- First argument (_Init) is the object to be initialized.
2052 -- ??? not sure where to get a reasonable Loc for First_Arg
2055 OK_Convert_To
(Parent_Type
,
2057 (Defining_Identifier
(First
(Parameters
)), Loc
));
2059 Set_Etype
(First_Arg
, Parent_Type
);
2061 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Rec_Type
));
2063 -- In the tasks case,
2064 -- add _Master as the value of the _Master parameter
2065 -- add _Chain as the value of the _Chain parameter.
2066 -- add _Task_Name as the value of the _Task_Name parameter.
2067 -- At the outer level, these will be variables holding the
2068 -- corresponding values obtained from GNARL or the expander.
2070 -- At inner levels, they will be the parameters passed down through
2071 -- the outer routines.
2073 First_Discr_Param
:= Next
(First
(Parameters
));
2075 if Has_Task
(Rec_Type
) then
2076 if Restriction_Active
(No_Task_Hierarchy
) then
2078 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
2080 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
2083 -- Add _Chain (not done for sequential elaboration policy, see
2084 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
2086 if Partition_Elaboration_Policy
/= 'S' then
2087 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
2090 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
2091 First_Discr_Param
:= Next
(Next
(Next
(First_Discr_Param
)));
2094 -- Append discriminant values
2096 if Has_Discriminants
(Uparent_Type
) then
2097 pragma Assert
(not Is_Tagged_Type
(Uparent_Type
));
2099 Parent_Discr
:= First_Discriminant
(Uparent_Type
);
2100 while Present
(Parent_Discr
) loop
2102 -- Get the initial value for this discriminant
2103 -- ??? needs to be cleaned up to use parent_Discr_Constr
2107 Discr
: Entity_Id
:=
2108 First_Stored_Discriminant
(Uparent_Type
);
2110 Discr_Value
: Elmt_Id
:=
2111 First_Elmt
(Stored_Constraint
(Rec_Type
));
2114 while Original_Record_Component
(Parent_Discr
) /= Discr
loop
2115 Next_Stored_Discriminant
(Discr
);
2116 Next_Elmt
(Discr_Value
);
2119 Arg
:= Node
(Discr_Value
);
2122 -- Append it to the list
2124 if Nkind
(Arg
) = N_Identifier
2125 and then Ekind
(Entity
(Arg
)) = E_Discriminant
2128 New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
));
2130 -- Case of access discriminants. We replace the reference
2131 -- to the type by a reference to the actual object.
2133 -- Is above comment right??? Use of New_Copy below seems mighty
2137 Append_To
(Args
, New_Copy
(Arg
));
2140 Next_Discriminant
(Parent_Discr
);
2146 Make_Procedure_Call_Statement
(Loc
,
2148 New_Occurrence_Of
(Parent_Proc
, Loc
),
2149 Parameter_Associations
=> Args
));
2152 end Build_Init_Call_Thru
;
2154 -----------------------------------
2155 -- Build_Offset_To_Top_Functions --
2156 -----------------------------------
2158 procedure Build_Offset_To_Top_Functions
is
2160 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
);
2162 -- function Fxx (O : Address) return Storage_Offset is
2163 -- type Acc is access all <Typ>;
2165 -- return Acc!(O).Iface_Comp'Position;
2168 ----------------------------------
2169 -- Build_Offset_To_Top_Function --
2170 ----------------------------------
2172 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
) is
2173 Body_Node
: Node_Id
;
2174 Func_Id
: Entity_Id
;
2175 Spec_Node
: Node_Id
;
2176 Acc_Type
: Entity_Id
;
2179 Func_Id
:= Make_Temporary
(Loc
, 'F');
2180 Set_DT_Offset_To_Top_Func
(Iface_Comp
, Func_Id
);
2183 -- function Fxx (O : in Rec_Typ) return Storage_Offset;
2185 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
2186 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
2187 Set_Parameter_Specifications
(Spec_Node
, New_List
(
2188 Make_Parameter_Specification
(Loc
,
2189 Defining_Identifier
=>
2190 Make_Defining_Identifier
(Loc
, Name_uO
),
2193 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))));
2194 Set_Result_Definition
(Spec_Node
,
2195 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
2198 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2200 -- return -O.Iface_Comp'Position;
2203 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2204 Set_Specification
(Body_Node
, Spec_Node
);
2206 Acc_Type
:= Make_Temporary
(Loc
, 'T');
2207 Set_Declarations
(Body_Node
, New_List
(
2208 Make_Full_Type_Declaration
(Loc
,
2209 Defining_Identifier
=> Acc_Type
,
2211 Make_Access_To_Object_Definition
(Loc
,
2212 All_Present
=> True,
2213 Null_Exclusion_Present
=> False,
2214 Constant_Present
=> False,
2215 Subtype_Indication
=>
2216 New_Occurrence_Of
(Rec_Type
, Loc
)))));
2218 Set_Handled_Statement_Sequence
(Body_Node
,
2219 Make_Handled_Sequence_Of_Statements
(Loc
,
2220 Statements
=> New_List
(
2221 Make_Simple_Return_Statement
(Loc
,
2224 Make_Attribute_Reference
(Loc
,
2226 Make_Selected_Component
(Loc
,
2228 Unchecked_Convert_To
(Acc_Type
,
2229 Make_Identifier
(Loc
, Name_uO
)),
2231 New_Occurrence_Of
(Iface_Comp
, Loc
)),
2232 Attribute_Name
=> Name_Position
))))));
2234 Set_Ekind
(Func_Id
, E_Function
);
2235 Set_Mechanism
(Func_Id
, Default_Mechanism
);
2236 Set_Is_Internal
(Func_Id
, True);
2238 if not Debug_Generated_Code
then
2239 Set_Debug_Info_Off
(Func_Id
);
2242 Analyze
(Body_Node
);
2244 Append_Freeze_Action
(Rec_Type
, Body_Node
);
2245 end Build_Offset_To_Top_Function
;
2249 Iface_Comp
: Node_Id
;
2250 Iface_Comp_Elmt
: Elmt_Id
;
2251 Ifaces_Comp_List
: Elist_Id
;
2253 -- Start of processing for Build_Offset_To_Top_Functions
2256 -- Offset_To_Top_Functions are built only for derivations of types
2257 -- with discriminants that cover interface types.
2258 -- Nothing is needed either in case of virtual targets, since
2259 -- interfaces are handled directly by the target.
2261 if not Is_Tagged_Type
(Rec_Type
)
2262 or else Etype
(Rec_Type
) = Rec_Type
2263 or else not Has_Discriminants
(Etype
(Rec_Type
))
2264 or else not Tagged_Type_Expansion
2269 Collect_Interface_Components
(Rec_Type
, Ifaces_Comp_List
);
2271 -- For each interface type with secondary dispatch table we generate
2272 -- the Offset_To_Top_Functions (required to displace the pointer in
2273 -- interface conversions)
2275 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
2276 while Present
(Iface_Comp_Elmt
) loop
2277 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
2278 pragma Assert
(Is_Interface
(Related_Type
(Iface_Comp
)));
2280 -- If the interface is a parent of Rec_Type it shares the primary
2281 -- dispatch table and hence there is no need to build the function
2283 if not Is_Ancestor
(Related_Type
(Iface_Comp
), Rec_Type
,
2284 Use_Full_View
=> True)
2286 Build_Offset_To_Top_Function
(Iface_Comp
);
2289 Next_Elmt
(Iface_Comp_Elmt
);
2291 end Build_Offset_To_Top_Functions
;
2293 ------------------------------
2294 -- Build_CPP_Init_Procedure --
2295 ------------------------------
2297 procedure Build_CPP_Init_Procedure
is
2298 Body_Node
: Node_Id
;
2299 Body_Stmts
: List_Id
;
2300 Flag_Id
: Entity_Id
;
2301 Handled_Stmt_Node
: Node_Id
;
2302 Init_Tags_List
: List_Id
;
2303 Proc_Id
: Entity_Id
;
2304 Proc_Spec_Node
: Node_Id
;
2307 -- Check cases requiring no IC routine
2309 if not Is_CPP_Class
(Root_Type
(Rec_Type
))
2310 or else Is_CPP_Class
(Rec_Type
)
2311 or else CPP_Num_Prims
(Rec_Type
) = 0
2312 or else not Tagged_Type_Expansion
2313 or else No_Run_Time_Mode
2320 -- Flag : Boolean := False;
2322 -- procedure Typ_IC is
2325 -- Copy C++ dispatch table slots from parent
2326 -- Update C++ slots of overridden primitives
2330 Flag_Id
:= Make_Temporary
(Loc
, 'F');
2332 Append_Freeze_Action
(Rec_Type
,
2333 Make_Object_Declaration
(Loc
,
2334 Defining_Identifier
=> Flag_Id
,
2335 Object_Definition
=>
2336 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2338 New_Occurrence_Of
(Standard_True
, Loc
)));
2340 Body_Stmts
:= New_List
;
2341 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2343 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2346 Make_Defining_Identifier
(Loc
,
2347 Chars
=> Make_TSS_Name
(Rec_Type
, TSS_CPP_Init_Proc
));
2349 Set_Ekind
(Proc_Id
, E_Procedure
);
2350 Set_Is_Internal
(Proc_Id
);
2352 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2354 Set_Parameter_Specifications
(Proc_Spec_Node
, New_List
);
2355 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2356 Set_Declarations
(Body_Node
, New_List
);
2358 Init_Tags_List
:= Build_Inherit_CPP_Prims
(Rec_Type
);
2360 Append_To
(Init_Tags_List
,
2361 Make_Assignment_Statement
(Loc
,
2363 New_Occurrence_Of
(Flag_Id
, Loc
),
2365 New_Occurrence_Of
(Standard_False
, Loc
)));
2367 Append_To
(Body_Stmts
,
2368 Make_If_Statement
(Loc
,
2369 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
2370 Then_Statements
=> Init_Tags_List
));
2372 Handled_Stmt_Node
:=
2373 New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2374 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2375 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2376 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2378 if not Debug_Generated_Code
then
2379 Set_Debug_Info_Off
(Proc_Id
);
2382 -- Associate CPP_Init_Proc with type
2384 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2385 end Build_CPP_Init_Procedure
;
2387 --------------------------
2388 -- Build_Init_Procedure --
2389 --------------------------
2391 procedure Build_Init_Procedure
is
2392 Body_Stmts
: List_Id
;
2393 Body_Node
: Node_Id
;
2394 Handled_Stmt_Node
: Node_Id
;
2395 Init_Tags_List
: List_Id
;
2396 Parameters
: List_Id
;
2397 Proc_Spec_Node
: Node_Id
;
2398 Record_Extension_Node
: Node_Id
;
2401 Body_Stmts
:= New_List
;
2402 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2403 Set_Ekind
(Proc_Id
, E_Procedure
);
2405 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2406 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2408 Parameters
:= Init_Formals
(Rec_Type
);
2409 Append_List_To
(Parameters
,
2410 Build_Discriminant_Formals
(Rec_Type
, True));
2412 -- For tagged types, we add a flag to indicate whether the routine
2413 -- is called to initialize a parent component in the init_proc of
2414 -- a type extension. If the flag is false, we do not set the tag
2415 -- because it has been set already in the extension.
2417 if Is_Tagged_Type
(Rec_Type
) then
2418 Set_Tag
:= Make_Temporary
(Loc
, 'P');
2420 Append_To
(Parameters
,
2421 Make_Parameter_Specification
(Loc
,
2422 Defining_Identifier
=> Set_Tag
,
2424 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2426 New_Occurrence_Of
(Standard_True
, Loc
)));
2429 Set_Parameter_Specifications
(Proc_Spec_Node
, Parameters
);
2430 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2431 Set_Declarations
(Body_Node
, Decls
);
2433 -- N is a Derived_Type_Definition that renames the parameters of the
2434 -- ancestor type. We initialize it by expanding our discriminants and
2435 -- call the ancestor _init_proc with a type-converted object.
2437 if Parent_Subtype_Renaming_Discrims
then
2438 Append_List_To
(Body_Stmts
, Build_Init_Call_Thru
(Parameters
));
2440 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
2441 Build_Discriminant_Assignments
(Body_Stmts
);
2443 if not Null_Present
(Type_Definition
(N
)) then
2444 Append_List_To
(Body_Stmts
,
2445 Build_Init_Statements
(Component_List
(Type_Definition
(N
))));
2448 -- N is a Derived_Type_Definition with a possible non-empty
2449 -- extension. The initialization of a type extension consists in the
2450 -- initialization of the components in the extension.
2453 Build_Discriminant_Assignments
(Body_Stmts
);
2455 Record_Extension_Node
:=
2456 Record_Extension_Part
(Type_Definition
(N
));
2458 if not Null_Present
(Record_Extension_Node
) then
2460 Stmts
: constant List_Id
:=
2461 Build_Init_Statements
(
2462 Component_List
(Record_Extension_Node
));
2465 -- The parent field must be initialized first because the
2466 -- offset of the new discriminants may depend on it. This is
2467 -- not needed if the parent is an interface type because in
2468 -- such case the initialization of the _parent field was not
2471 if not Is_Interface
(Etype
(Rec_Ent
)) then
2473 Parent_IP
: constant Name_Id
:=
2474 Make_Init_Proc_Name
(Etype
(Rec_Ent
));
2480 -- Look for a call to the parent IP at the beginning
2481 -- of Stmts associated with the record extension
2483 Stmt
:= First
(Stmts
);
2485 while Present
(Stmt
) loop
2486 if Nkind
(Stmt
) = N_Procedure_Call_Statement
2487 and then Chars
(Name
(Stmt
)) = Parent_IP
2496 -- If found then move it to the beginning of the
2497 -- statements of this IP routine
2499 if Present
(IP_Call
) then
2500 IP_Stmts
:= New_List
;
2502 Stmt
:= Remove_Head
(Stmts
);
2503 Append_To
(IP_Stmts
, Stmt
);
2504 exit when Stmt
= IP_Call
;
2507 Prepend_List_To
(Body_Stmts
, IP_Stmts
);
2512 Append_List_To
(Body_Stmts
, Stmts
);
2517 -- Add here the assignment to instantiate the Tag
2519 -- The assignment corresponds to the code:
2521 -- _Init._Tag := Typ'Tag;
2523 -- Suppress the tag assignment when not Tagged_Type_Expansion because
2524 -- tags are represented implicitly in objects. It is also suppressed
2525 -- in case of CPP_Class types because in this case the tag is
2526 -- initialized in the C++ side.
2528 if Is_Tagged_Type
(Rec_Type
)
2529 and then Tagged_Type_Expansion
2530 and then not No_Run_Time_Mode
2532 -- Case 1: Ada tagged types with no CPP ancestor. Set the tags of
2533 -- the actual object and invoke the IP of the parent (in this
2534 -- order). The tag must be initialized before the call to the IP
2535 -- of the parent and the assignments to other components because
2536 -- the initial value of the components may depend on the tag (eg.
2537 -- through a dispatching operation on an access to the current
2538 -- type). The tag assignment is not done when initializing the
2539 -- parent component of a type extension, because in that case the
2540 -- tag is set in the extension.
2542 if not Is_CPP_Class
(Root_Type
(Rec_Type
)) then
2544 -- Initialize the primary tag component
2546 Init_Tags_List
:= New_List
(
2547 Make_Assignment_Statement
(Loc
,
2549 Make_Selected_Component
(Loc
,
2550 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2553 (First_Tag_Component
(Rec_Type
), Loc
)),
2557 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2559 -- Ada 2005 (AI-251): Initialize the secondary tags components
2560 -- located at fixed positions (tags whose position depends on
2561 -- variable size components are initialized later ---see below)
2563 if Ada_Version
>= Ada_2005
2564 and then not Is_Interface
(Rec_Type
)
2565 and then Has_Interfaces
(Rec_Type
)
2568 Elab_Sec_DT_Stmts_List
: constant List_Id
:= New_List
;
2569 Elab_List
: List_Id
:= New_List
;
2574 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2575 Init_Tags_List
=> Init_Tags_List
,
2576 Stmts_List
=> Elab_Sec_DT_Stmts_List
,
2577 Fixed_Comps
=> True,
2578 Variable_Comps
=> False);
2580 Elab_List
:= New_List
(
2581 Make_If_Statement
(Loc
,
2582 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2583 Then_Statements
=> Init_Tags_List
));
2585 if Elab_Flag_Needed
(Rec_Type
) then
2586 Append_To
(Elab_Sec_DT_Stmts_List
,
2587 Make_Assignment_Statement
(Loc
,
2590 (Access_Disp_Table_Elab_Flag
(Rec_Type
),
2593 New_Occurrence_Of
(Standard_False
, Loc
)));
2595 Append_To
(Elab_List
,
2596 Make_If_Statement
(Loc
,
2599 (Access_Disp_Table_Elab_Flag
(Rec_Type
), Loc
),
2600 Then_Statements
=> Elab_Sec_DT_Stmts_List
));
2603 Prepend_List_To
(Body_Stmts
, Elab_List
);
2606 Prepend_To
(Body_Stmts
,
2607 Make_If_Statement
(Loc
,
2608 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2609 Then_Statements
=> Init_Tags_List
));
2612 -- Case 2: CPP type. The imported C++ constructor takes care of
2613 -- tags initialization. No action needed here because the IP
2614 -- is built by Set_CPP_Constructors; in this case the IP is a
2615 -- wrapper that invokes the C++ constructor and copies the C++
2616 -- tags locally. Done to inherit the C++ slots in Ada derivations
2619 elsif Is_CPP_Class
(Rec_Type
) then
2620 pragma Assert
(False);
2623 -- Case 3: Combined hierarchy containing C++ types and Ada tagged
2624 -- type derivations. Derivations of imported C++ classes add a
2625 -- complication, because we cannot inhibit tag setting in the
2626 -- constructor for the parent. Hence we initialize the tag after
2627 -- the call to the parent IP (that is, in reverse order compared
2628 -- with pure Ada hierarchies ---see comment on case 1).
2631 -- Initialize the primary tag
2633 Init_Tags_List
:= New_List
(
2634 Make_Assignment_Statement
(Loc
,
2636 Make_Selected_Component
(Loc
,
2637 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2640 (First_Tag_Component
(Rec_Type
), Loc
)),
2644 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2646 -- Ada 2005 (AI-251): Initialize the secondary tags components
2647 -- located at fixed positions (tags whose position depends on
2648 -- variable size components are initialized later ---see below)
2650 if Ada_Version
>= Ada_2005
2651 and then not Is_Interface
(Rec_Type
)
2652 and then Has_Interfaces
(Rec_Type
)
2656 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2657 Init_Tags_List
=> Init_Tags_List
,
2658 Stmts_List
=> Init_Tags_List
,
2659 Fixed_Comps
=> True,
2660 Variable_Comps
=> False);
2663 -- Initialize the tag component after invocation of parent IP.
2666 -- parent_IP(_init.parent); // Invokes the C++ constructor
2667 -- [ typIC; ] // Inherit C++ slots from parent
2674 -- Search for the call to the IP of the parent. We assume
2675 -- that the first init_proc call is for the parent.
2677 Ins_Nod
:= First
(Body_Stmts
);
2678 while Present
(Next
(Ins_Nod
))
2679 and then (Nkind
(Ins_Nod
) /= N_Procedure_Call_Statement
2680 or else not Is_Init_Proc
(Name
(Ins_Nod
)))
2685 -- The IC routine copies the inherited slots of the C+ part
2686 -- of the dispatch table from the parent and updates the
2687 -- overridden C++ slots.
2689 if CPP_Num_Prims
(Rec_Type
) > 0 then
2691 Init_DT
: Entity_Id
;
2695 Init_DT
:= CPP_Init_Proc
(Rec_Type
);
2696 pragma Assert
(Present
(Init_DT
));
2699 Make_Procedure_Call_Statement
(Loc
,
2700 New_Occurrence_Of
(Init_DT
, Loc
));
2701 Insert_After
(Ins_Nod
, New_Nod
);
2703 -- Update location of init tag statements
2709 Insert_List_After
(Ins_Nod
, Init_Tags_List
);
2713 -- Ada 2005 (AI-251): Initialize the secondary tag components
2714 -- located at variable positions. We delay the generation of this
2715 -- code until here because the value of the attribute 'Position
2716 -- applied to variable size components of the parent type that
2717 -- depend on discriminants is only safely read at runtime after
2718 -- the parent components have been initialized.
2720 if Ada_Version
>= Ada_2005
2721 and then not Is_Interface
(Rec_Type
)
2722 and then Has_Interfaces
(Rec_Type
)
2723 and then Has_Discriminants
(Etype
(Rec_Type
))
2724 and then Is_Variable_Size_Record
(Etype
(Rec_Type
))
2726 Init_Tags_List
:= New_List
;
2730 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2731 Init_Tags_List
=> Init_Tags_List
,
2732 Stmts_List
=> Init_Tags_List
,
2733 Fixed_Comps
=> False,
2734 Variable_Comps
=> True);
2736 if Is_Non_Empty_List
(Init_Tags_List
) then
2737 Append_List_To
(Body_Stmts
, Init_Tags_List
);
2742 Handled_Stmt_Node
:= New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2743 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2746 -- Deep_Finalize (_init, C1, ..., CN);
2750 and then Needs_Finalization
(Rec_Type
)
2751 and then not Is_Abstract_Type
(Rec_Type
)
2752 and then not Restriction_Active
(No_Exception_Propagation
)
2759 -- Create a local version of Deep_Finalize which has indication
2760 -- of partial initialization state.
2763 Make_Defining_Identifier
(Loc
,
2764 Chars
=> New_External_Name
(Name_uFinalizer
));
2766 Append_To
(Decls
, Make_Local_Deep_Finalize
(Rec_Type
, DF_Id
));
2769 Make_Procedure_Call_Statement
(Loc
,
2770 Name
=> New_Occurrence_Of
(DF_Id
, Loc
),
2771 Parameter_Associations
=> New_List
(
2772 Make_Identifier
(Loc
, Name_uInit
),
2773 New_Occurrence_Of
(Standard_False
, Loc
)));
2775 -- Do not emit warnings related to the elaboration order when a
2776 -- controlled object is declared before the body of Finalize is
2779 if Legacy_Elaboration_Checks
then
2780 Set_No_Elaboration_Check
(DF_Call
);
2783 Set_Exception_Handlers
(Handled_Stmt_Node
, New_List
(
2784 Make_Exception_Handler
(Loc
,
2785 Exception_Choices
=> New_List
(
2786 Make_Others_Choice
(Loc
)),
2787 Statements
=> New_List
(
2789 Make_Raise_Statement
(Loc
)))));
2792 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2795 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2797 if not Debug_Generated_Code
then
2798 Set_Debug_Info_Off
(Proc_Id
);
2801 -- Associate Init_Proc with type, and determine if the procedure
2802 -- is null (happens because of the Initialize_Scalars pragma case,
2803 -- where we have to generate a null procedure in case it is called
2804 -- by a client with Initialize_Scalars set). Such procedures have
2805 -- to be generated, but do not have to be called, so we mark them
2806 -- as null to suppress the call.
2808 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2810 if List_Length
(Body_Stmts
) = 1
2812 -- We must skip SCIL nodes because they may have been added to this
2813 -- list by Insert_Actions.
2815 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
2817 Set_Is_Null_Init_Proc
(Proc_Id
);
2819 end Build_Init_Procedure
;
2821 ---------------------------
2822 -- Build_Init_Statements --
2823 ---------------------------
2825 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
is
2826 Checks
: constant List_Id
:= New_List
;
2827 Actions
: List_Id
:= No_List
;
2828 Counter_Id
: Entity_Id
:= Empty
;
2829 Comp_Loc
: Source_Ptr
;
2833 Parent_Stmts
: List_Id
;
2837 procedure Increment_Counter
(Loc
: Source_Ptr
);
2838 -- Generate an "increment by one" statement for the current counter
2839 -- and append it to the list Stmts.
2841 procedure Make_Counter
(Loc
: Source_Ptr
);
2842 -- Create a new counter for the current component list. The routine
2843 -- creates a new defining Id, adds an object declaration and sets
2844 -- the Id generator for the next variant.
2846 -----------------------
2847 -- Increment_Counter --
2848 -----------------------
2850 procedure Increment_Counter
(Loc
: Source_Ptr
) is
2853 -- Counter := Counter + 1;
2856 Make_Assignment_Statement
(Loc
,
2857 Name
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2860 Left_Opnd
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2861 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
2862 end Increment_Counter
;
2868 procedure Make_Counter
(Loc
: Source_Ptr
) is
2870 -- Increment the Id generator
2872 Counter
:= Counter
+ 1;
2874 -- Create the entity and declaration
2877 Make_Defining_Identifier
(Loc
,
2878 Chars
=> New_External_Name
('C', Counter
));
2881 -- Cnn : Integer := 0;
2884 Make_Object_Declaration
(Loc
,
2885 Defining_Identifier
=> Counter_Id
,
2886 Object_Definition
=>
2887 New_Occurrence_Of
(Standard_Integer
, Loc
),
2889 Make_Integer_Literal
(Loc
, 0)));
2892 -- Start of processing for Build_Init_Statements
2895 if Null_Present
(Comp_List
) then
2896 return New_List
(Make_Null_Statement
(Loc
));
2899 Parent_Stmts
:= New_List
;
2902 -- Loop through visible declarations of task types and protected
2903 -- types moving any expanded code from the spec to the body of the
2906 if Is_Task_Record_Type
(Rec_Type
)
2907 or else Is_Protected_Record_Type
(Rec_Type
)
2910 Decl
: constant Node_Id
:=
2911 Parent
(Corresponding_Concurrent_Type
(Rec_Type
));
2917 if Is_Task_Record_Type
(Rec_Type
) then
2918 Def
:= Task_Definition
(Decl
);
2920 Def
:= Protected_Definition
(Decl
);
2923 if Present
(Def
) then
2924 N1
:= First
(Visible_Declarations
(Def
));
2925 while Present
(N1
) loop
2929 if Nkind
(N2
) in N_Statement_Other_Than_Procedure_Call
2930 or else Nkind
(N2
) in N_Raise_xxx_Error
2931 or else Nkind
(N2
) = N_Procedure_Call_Statement
2934 New_Copy_Tree
(N2
, New_Scope
=> Proc_Id
));
2935 Rewrite
(N2
, Make_Null_Statement
(Sloc
(N2
)));
2943 -- Loop through components, skipping pragmas, in 2 steps. The first
2944 -- step deals with regular components. The second step deals with
2945 -- components that have per object constraints and no explicit
2950 -- First pass : regular components
2952 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
2953 while Present
(Decl
) loop
2954 Comp_Loc
:= Sloc
(Decl
);
2956 (Subtype_Indication
(Component_Definition
(Decl
)), Checks
);
2958 Id
:= Defining_Identifier
(Decl
);
2961 -- Leave any processing of per-object constrained component for
2964 if Has_Access_Constraint
(Id
) and then No
(Expression
(Decl
)) then
2967 -- Regular component cases
2970 -- In the context of the init proc, references to discriminants
2971 -- resolve to denote the discriminals: this is where we can
2972 -- freeze discriminant dependent component subtypes.
2974 if not Is_Frozen
(Typ
) then
2975 Append_List_To
(Stmts
, Freeze_Entity
(Typ
, N
));
2978 -- Explicit initialization
2980 if Present
(Expression
(Decl
)) then
2981 if Is_CPP_Constructor_Call
(Expression
(Decl
)) then
2983 Build_Initialization_Call
2986 Make_Selected_Component
(Comp_Loc
,
2988 Make_Identifier
(Comp_Loc
, Name_uInit
),
2990 New_Occurrence_Of
(Id
, Comp_Loc
)),
2992 In_Init_Proc
=> True,
2993 Enclos_Type
=> Rec_Type
,
2994 Discr_Map
=> Discr_Map
,
2995 Constructor_Ref
=> Expression
(Decl
));
2997 Actions
:= Build_Assignment
(Id
, Expression
(Decl
));
3000 -- CPU, Dispatching_Domain, Priority, and Secondary_Stack_Size
3001 -- components are filled in with the corresponding rep-item
3002 -- expression of the concurrent type (if any).
3004 elsif Ekind
(Scope
(Id
)) = E_Record_Type
3005 and then Present
(Corresponding_Concurrent_Type
(Scope
(Id
)))
3006 and then Nam_In
(Chars
(Id
), Name_uCPU
,
3007 Name_uDispatching_Domain
,
3009 Name_uSecondary_Stack_Size
)
3014 pragma Warnings
(Off
, Nam
);
3018 if Chars
(Id
) = Name_uCPU
then
3021 elsif Chars
(Id
) = Name_uDispatching_Domain
then
3022 Nam
:= Name_Dispatching_Domain
;
3024 elsif Chars
(Id
) = Name_uPriority
then
3025 Nam
:= Name_Priority
;
3027 elsif Chars
(Id
) = Name_uSecondary_Stack_Size
then
3028 Nam
:= Name_Secondary_Stack_Size
;
3031 -- Get the Rep Item (aspect specification, attribute
3032 -- definition clause or pragma) of the corresponding
3037 (Corresponding_Concurrent_Type
(Scope
(Id
)),
3039 Check_Parents
=> False);
3041 if Present
(Ritem
) then
3045 if Nkind
(Ritem
) = N_Pragma
then
3046 Exp
:= First
(Pragma_Argument_Associations
(Ritem
));
3048 if Nkind
(Exp
) = N_Pragma_Argument_Association
then
3049 Exp
:= Expression
(Exp
);
3052 -- Conversion for Priority expression
3054 if Nam
= Name_Priority
then
3055 if Pragma_Name
(Ritem
) = Name_Priority
3056 and then not GNAT_Mode
3058 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
3061 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
3065 -- Aspect/Attribute definition clause case
3068 Exp
:= Expression
(Ritem
);
3070 -- Conversion for Priority expression
3072 if Nam
= Name_Priority
then
3073 if Chars
(Ritem
) = Name_Priority
3074 and then not GNAT_Mode
3076 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
3079 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
3084 -- Conversion for Dispatching_Domain value
3086 if Nam
= Name_Dispatching_Domain
then
3088 Unchecked_Convert_To
3089 (RTE
(RE_Dispatching_Domain_Access
), Exp
);
3091 -- Conversion for Secondary_Stack_Size value
3093 elsif Nam
= Name_Secondary_Stack_Size
then
3094 Exp
:= Convert_To
(RTE
(RE_Size_Type
), Exp
);
3097 Actions
:= Build_Assignment
(Id
, Exp
);
3099 -- Nothing needed if no Rep Item
3106 -- Composite component with its own Init_Proc
3108 elsif not Is_Interface
(Typ
)
3109 and then Has_Non_Null_Base_Init_Proc
(Typ
)
3112 Build_Initialization_Call
3114 Make_Selected_Component
(Comp_Loc
,
3116 Make_Identifier
(Comp_Loc
, Name_uInit
),
3117 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3119 In_Init_Proc
=> True,
3120 Enclos_Type
=> Rec_Type
,
3121 Discr_Map
=> Discr_Map
);
3123 Clean_Task_Names
(Typ
, Proc_Id
);
3125 -- Simple initialization
3127 elsif Component_Needs_Simple_Initialization
(Typ
) then
3135 Size
=> Esize
(Id
)));
3137 -- Nothing needed for this case
3143 if Present
(Checks
) then
3144 if Chars
(Id
) = Name_uParent
then
3145 Append_List_To
(Parent_Stmts
, Checks
);
3147 Append_List_To
(Stmts
, Checks
);
3151 if Present
(Actions
) then
3152 if Chars
(Id
) = Name_uParent
then
3153 Append_List_To
(Parent_Stmts
, Actions
);
3156 Append_List_To
(Stmts
, Actions
);
3158 -- Preserve initialization state in the current counter
3160 if Needs_Finalization
(Typ
) then
3161 if No
(Counter_Id
) then
3162 Make_Counter
(Comp_Loc
);
3165 Increment_Counter
(Comp_Loc
);
3171 Next_Non_Pragma
(Decl
);
3174 -- The parent field must be initialized first because variable
3175 -- size components of the parent affect the location of all the
3178 Prepend_List_To
(Stmts
, Parent_Stmts
);
3180 -- Set up tasks and protected object support. This needs to be done
3181 -- before any component with a per-object access discriminant
3182 -- constraint, or any variant part (which may contain such
3183 -- components) is initialized, because the initialization of these
3184 -- components may reference the enclosing concurrent object.
3186 -- For a task record type, add the task create call and calls to bind
3187 -- any interrupt (signal) entries.
3189 if Is_Task_Record_Type
(Rec_Type
) then
3191 -- In the case of the restricted run time the ATCB has already
3192 -- been preallocated.
3194 if Restricted_Profile
then
3196 Make_Assignment_Statement
(Loc
,
3198 Make_Selected_Component
(Loc
,
3199 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3200 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3202 Make_Attribute_Reference
(Loc
,
3204 Make_Selected_Component
(Loc
,
3205 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3206 Selector_Name
=> Make_Identifier
(Loc
, Name_uATCB
)),
3207 Attribute_Name
=> Name_Unchecked_Access
)));
3210 Append_To
(Stmts
, Make_Task_Create_Call
(Rec_Type
));
3213 Task_Type
: constant Entity_Id
:=
3214 Corresponding_Concurrent_Type
(Rec_Type
);
3215 Task_Decl
: constant Node_Id
:= Parent
(Task_Type
);
3216 Task_Def
: constant Node_Id
:= Task_Definition
(Task_Decl
);
3217 Decl_Loc
: Source_Ptr
;
3222 if Present
(Task_Def
) then
3223 Vis_Decl
:= First
(Visible_Declarations
(Task_Def
));
3224 while Present
(Vis_Decl
) loop
3225 Decl_Loc
:= Sloc
(Vis_Decl
);
3227 if Nkind
(Vis_Decl
) = N_Attribute_Definition_Clause
then
3228 if Get_Attribute_Id
(Chars
(Vis_Decl
)) =
3231 Ent
:= Entity
(Name
(Vis_Decl
));
3233 if Ekind
(Ent
) = E_Entry
then
3235 Make_Procedure_Call_Statement
(Decl_Loc
,
3237 New_Occurrence_Of
(RTE
(
3238 RE_Bind_Interrupt_To_Entry
), Decl_Loc
),
3239 Parameter_Associations
=> New_List
(
3240 Make_Selected_Component
(Decl_Loc
,
3242 Make_Identifier
(Decl_Loc
, Name_uInit
),
3245 (Decl_Loc
, Name_uTask_Id
)),
3246 Entry_Index_Expression
3247 (Decl_Loc
, Ent
, Empty
, Task_Type
),
3248 Expression
(Vis_Decl
))));
3259 -- For a protected type, add statements generated by
3260 -- Make_Initialize_Protection.
3262 if Is_Protected_Record_Type
(Rec_Type
) then
3263 Append_List_To
(Stmts
,
3264 Make_Initialize_Protection
(Rec_Type
));
3267 -- Second pass: components with per-object constraints
3270 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3271 while Present
(Decl
) loop
3272 Comp_Loc
:= Sloc
(Decl
);
3273 Id
:= Defining_Identifier
(Decl
);
3276 if Has_Access_Constraint
(Id
)
3277 and then No
(Expression
(Decl
))
3279 if Has_Non_Null_Base_Init_Proc
(Typ
) then
3280 Append_List_To
(Stmts
,
3281 Build_Initialization_Call
(Comp_Loc
,
3282 Make_Selected_Component
(Comp_Loc
,
3284 Make_Identifier
(Comp_Loc
, Name_uInit
),
3285 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3287 In_Init_Proc
=> True,
3288 Enclos_Type
=> Rec_Type
,
3289 Discr_Map
=> Discr_Map
));
3291 Clean_Task_Names
(Typ
, Proc_Id
);
3293 -- Preserve initialization state in the current counter
3295 if Needs_Finalization
(Typ
) then
3296 if No
(Counter_Id
) then
3297 Make_Counter
(Comp_Loc
);
3300 Increment_Counter
(Comp_Loc
);
3303 elsif Component_Needs_Simple_Initialization
(Typ
) then
3304 Append_List_To
(Stmts
,
3311 Size
=> Esize
(Id
))));
3315 Next_Non_Pragma
(Decl
);
3319 -- Process the variant part
3321 if Present
(Variant_Part
(Comp_List
)) then
3323 Variant_Alts
: constant List_Id
:= New_List
;
3324 Var_Loc
: Source_Ptr
:= No_Location
;
3329 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3330 while Present
(Variant
) loop
3331 Var_Loc
:= Sloc
(Variant
);
3332 Append_To
(Variant_Alts
,
3333 Make_Case_Statement_Alternative
(Var_Loc
,
3335 New_Copy_List
(Discrete_Choices
(Variant
)),
3337 Build_Init_Statements
(Component_List
(Variant
))));
3338 Next_Non_Pragma
(Variant
);
3341 -- The expression of the case statement which is a reference
3342 -- to one of the discriminants is replaced by the appropriate
3343 -- formal parameter of the initialization procedure.
3346 Make_Case_Statement
(Var_Loc
,
3348 New_Occurrence_Of
(Discriminal
(
3349 Entity
(Name
(Variant_Part
(Comp_List
)))), Var_Loc
),
3350 Alternatives
=> Variant_Alts
));
3354 -- If no initializations when generated for component declarations
3355 -- corresponding to this Stmts, append a null statement to Stmts to
3356 -- to make it a valid Ada tree.
3358 if Is_Empty_List
(Stmts
) then
3359 Append
(Make_Null_Statement
(Loc
), Stmts
);
3365 when RE_Not_Available
=>
3367 end Build_Init_Statements
;
3369 -------------------------
3370 -- Build_Record_Checks --
3371 -------------------------
3373 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
) is
3374 Subtype_Mark_Id
: Entity_Id
;
3376 procedure Constrain_Array
3378 Check_List
: List_Id
);
3379 -- Apply a list of index constraints to an unconstrained array type.
3380 -- The first parameter is the entity for the resulting subtype.
3381 -- Check_List is a list to which the check actions are appended.
3383 ---------------------
3384 -- Constrain_Array --
3385 ---------------------
3387 procedure Constrain_Array
3389 Check_List
: List_Id
)
3391 C
: constant Node_Id
:= Constraint
(SI
);
3392 Number_Of_Constraints
: Nat
:= 0;
3396 procedure Constrain_Index
3399 Check_List
: List_Id
);
3400 -- Process an index constraint in a constrained array declaration.
3401 -- The constraint can be either a subtype name or a range with or
3402 -- without an explicit subtype mark. Index is the corresponding
3403 -- index of the unconstrained array. S is the range expression.
3404 -- Check_List is a list to which the check actions are appended.
3406 ---------------------
3407 -- Constrain_Index --
3408 ---------------------
3410 procedure Constrain_Index
3413 Check_List
: List_Id
)
3415 T
: constant Entity_Id
:= Etype
(Index
);
3418 if Nkind
(S
) = N_Range
then
3419 Process_Range_Expr_In_Decl
(S
, T
, Check_List
=> Check_List
);
3421 end Constrain_Index
;
3423 -- Start of processing for Constrain_Array
3426 T
:= Entity
(Subtype_Mark
(SI
));
3428 if Is_Access_Type
(T
) then
3429 T
:= Designated_Type
(T
);
3432 S
:= First
(Constraints
(C
));
3433 while Present
(S
) loop
3434 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
3438 -- In either case, the index constraint must provide a discrete
3439 -- range for each index of the array type and the type of each
3440 -- discrete range must be the same as that of the corresponding
3441 -- index. (RM 3.6.1)
3443 S
:= First
(Constraints
(C
));
3444 Index
:= First_Index
(T
);
3447 -- Apply constraints to each index type
3449 for J
in 1 .. Number_Of_Constraints
loop
3450 Constrain_Index
(Index
, S
, Check_List
);
3454 end Constrain_Array
;
3456 -- Start of processing for Build_Record_Checks
3459 if Nkind
(S
) = N_Subtype_Indication
then
3460 Find_Type
(Subtype_Mark
(S
));
3461 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
3463 -- Remaining processing depends on type
3465 case Ekind
(Subtype_Mark_Id
) is
3467 Constrain_Array
(S
, Check_List
);
3473 end Build_Record_Checks
;
3475 -------------------------------------------
3476 -- Component_Needs_Simple_Initialization --
3477 -------------------------------------------
3479 function Component_Needs_Simple_Initialization
3480 (T
: Entity_Id
) return Boolean
3484 Needs_Simple_Initialization
(T
)
3485 and then not Is_RTE
(T
, RE_Tag
)
3487 -- Ada 2005 (AI-251): Check also the tag of abstract interfaces
3489 and then not Is_RTE
(T
, RE_Interface_Tag
);
3490 end Component_Needs_Simple_Initialization
;
3492 --------------------------------------
3493 -- Parent_Subtype_Renaming_Discrims --
3494 --------------------------------------
3496 function Parent_Subtype_Renaming_Discrims
return Boolean is
3501 if Base_Type
(Rec_Ent
) /= Rec_Ent
then
3505 if Etype
(Rec_Ent
) = Rec_Ent
3506 or else not Has_Discriminants
(Rec_Ent
)
3507 or else Is_Constrained
(Rec_Ent
)
3508 or else Is_Tagged_Type
(Rec_Ent
)
3513 -- If there are no explicit stored discriminants we have inherited
3514 -- the root type discriminants so far, so no renamings occurred.
3516 if First_Discriminant
(Rec_Ent
) =
3517 First_Stored_Discriminant
(Rec_Ent
)
3522 -- Check if we have done some trivial renaming of the parent
3523 -- discriminants, i.e. something like
3525 -- type DT (X1, X2: int) is new PT (X1, X2);
3527 De
:= First_Discriminant
(Rec_Ent
);
3528 Dp
:= First_Discriminant
(Etype
(Rec_Ent
));
3529 while Present
(De
) loop
3530 pragma Assert
(Present
(Dp
));
3532 if Corresponding_Discriminant
(De
) /= Dp
then
3536 Next_Discriminant
(De
);
3537 Next_Discriminant
(Dp
);
3540 return Present
(Dp
);
3541 end Parent_Subtype_Renaming_Discrims
;
3543 ------------------------
3544 -- Requires_Init_Proc --
3545 ------------------------
3547 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean is
3548 Comp_Decl
: Node_Id
;
3553 -- Definitely do not need one if specifically suppressed
3555 if Initialization_Suppressed
(Rec_Id
) then
3559 -- If it is a type derived from a type with unknown discriminants,
3560 -- we cannot build an initialization procedure for it.
3562 if Has_Unknown_Discriminants
(Rec_Id
)
3563 or else Has_Unknown_Discriminants
(Etype
(Rec_Id
))
3568 -- Otherwise we need to generate an initialization procedure if
3569 -- Is_CPP_Class is False and at least one of the following applies:
3571 -- 1. Discriminants are present, since they need to be initialized
3572 -- with the appropriate discriminant constraint expressions.
3573 -- However, the discriminant of an unchecked union does not
3574 -- count, since the discriminant is not present.
3576 -- 2. The type is a tagged type, since the implicit Tag component
3577 -- needs to be initialized with a pointer to the dispatch table.
3579 -- 3. The type contains tasks
3581 -- 4. One or more components has an initial value
3583 -- 5. One or more components is for a type which itself requires
3584 -- an initialization procedure.
3586 -- 6. One or more components is a type that requires simple
3587 -- initialization (see Needs_Simple_Initialization), except
3588 -- that types Tag and Interface_Tag are excluded, since fields
3589 -- of these types are initialized by other means.
3591 -- 7. The type is the record type built for a task type (since at
3592 -- the very least, Create_Task must be called)
3594 -- 8. The type is the record type built for a protected type (since
3595 -- at least Initialize_Protection must be called)
3597 -- 9. The type is marked as a public entity. The reason we add this
3598 -- case (even if none of the above apply) is to properly handle
3599 -- Initialize_Scalars. If a package is compiled without an IS
3600 -- pragma, and the client is compiled with an IS pragma, then
3601 -- the client will think an initialization procedure is present
3602 -- and call it, when in fact no such procedure is required, but
3603 -- since the call is generated, there had better be a routine
3604 -- at the other end of the call, even if it does nothing).
3606 -- Note: the reason we exclude the CPP_Class case is because in this
3607 -- case the initialization is performed by the C++ constructors, and
3608 -- the IP is built by Set_CPP_Constructors.
3610 if Is_CPP_Class
(Rec_Id
) then
3613 elsif Is_Interface
(Rec_Id
) then
3616 elsif (Has_Discriminants
(Rec_Id
)
3617 and then not Is_Unchecked_Union
(Rec_Id
))
3618 or else Is_Tagged_Type
(Rec_Id
)
3619 or else Is_Concurrent_Record_Type
(Rec_Id
)
3620 or else Has_Task
(Rec_Id
)
3625 Id
:= First_Component
(Rec_Id
);
3626 while Present
(Id
) loop
3627 Comp_Decl
:= Parent
(Id
);
3630 if Present
(Expression
(Comp_Decl
))
3631 or else Has_Non_Null_Base_Init_Proc
(Typ
)
3632 or else Component_Needs_Simple_Initialization
(Typ
)
3637 Next_Component
(Id
);
3640 -- As explained above, a record initialization procedure is needed
3641 -- for public types in case Initialize_Scalars applies to a client.
3642 -- However, such a procedure is not needed in the case where either
3643 -- of restrictions No_Initialize_Scalars or No_Default_Initialization
3644 -- applies. No_Initialize_Scalars excludes the possibility of using
3645 -- Initialize_Scalars in any partition, and No_Default_Initialization
3646 -- implies that no initialization should ever be done for objects of
3647 -- the type, so is incompatible with Initialize_Scalars.
3649 if not Restriction_Active
(No_Initialize_Scalars
)
3650 and then not Restriction_Active
(No_Default_Initialization
)
3651 and then Is_Public
(Rec_Id
)
3657 end Requires_Init_Proc
;
3659 -- Start of processing for Build_Record_Init_Proc
3662 Rec_Type
:= Defining_Identifier
(N
);
3664 -- This may be full declaration of a private type, in which case
3665 -- the visible entity is a record, and the private entity has been
3666 -- exchanged with it in the private part of the current package.
3667 -- The initialization procedure is built for the record type, which
3668 -- is retrievable from the private entity.
3670 if Is_Incomplete_Or_Private_Type
(Rec_Type
) then
3671 Rec_Type
:= Underlying_Type
(Rec_Type
);
3674 -- If we have a variant record with restriction No_Implicit_Conditionals
3675 -- in effect, then we skip building the procedure. This is safe because
3676 -- if we can see the restriction, so can any caller, calls to initialize
3677 -- such records are not allowed for variant records if this restriction
3680 if Has_Variant_Part
(Rec_Type
)
3681 and then Restriction_Active
(No_Implicit_Conditionals
)
3686 -- If there are discriminants, build the discriminant map to replace
3687 -- discriminants by their discriminals in complex bound expressions.
3688 -- These only arise for the corresponding records of synchronized types.
3690 if Is_Concurrent_Record_Type
(Rec_Type
)
3691 and then Has_Discriminants
(Rec_Type
)
3696 Disc
:= First_Discriminant
(Rec_Type
);
3697 while Present
(Disc
) loop
3698 Append_Elmt
(Disc
, Discr_Map
);
3699 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
3700 Next_Discriminant
(Disc
);
3705 -- Derived types that have no type extension can use the initialization
3706 -- procedure of their parent and do not need a procedure of their own.
3707 -- This is only correct if there are no representation clauses for the
3708 -- type or its parent, and if the parent has in fact been frozen so
3709 -- that its initialization procedure exists.
3711 if Is_Derived_Type
(Rec_Type
)
3712 and then not Is_Tagged_Type
(Rec_Type
)
3713 and then not Is_Unchecked_Union
(Rec_Type
)
3714 and then not Has_New_Non_Standard_Rep
(Rec_Type
)
3715 and then not Parent_Subtype_Renaming_Discrims
3716 and then Has_Non_Null_Base_Init_Proc
(Etype
(Rec_Type
))
3718 Copy_TSS
(Base_Init_Proc
(Etype
(Rec_Type
)), Rec_Type
);
3720 -- Otherwise if we need an initialization procedure, then build one,
3721 -- mark it as public and inlinable and as having a completion.
3723 elsif Requires_Init_Proc
(Rec_Type
)
3724 or else Is_Unchecked_Union
(Rec_Type
)
3727 Make_Defining_Identifier
(Loc
,
3728 Chars
=> Make_Init_Proc_Name
(Rec_Type
));
3730 -- If No_Default_Initialization restriction is active, then we don't
3731 -- want to build an init_proc, but we need to mark that an init_proc
3732 -- would be needed if this restriction was not active (so that we can
3733 -- detect attempts to call it), so set a dummy init_proc in place.
3735 if Restriction_Active
(No_Default_Initialization
) then
3736 Set_Init_Proc
(Rec_Type
, Proc_Id
);
3740 Build_Offset_To_Top_Functions
;
3741 Build_CPP_Init_Procedure
;
3742 Build_Init_Procedure
;
3744 Set_Is_Public
(Proc_Id
, Is_Public
(Rec_Ent
));
3745 Set_Is_Internal
(Proc_Id
);
3746 Set_Has_Completion
(Proc_Id
);
3748 if not Debug_Generated_Code
then
3749 Set_Debug_Info_Off
(Proc_Id
);
3752 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Rec_Type
));
3754 -- Do not build an aggregate if Modify_Tree_For_C, this isn't
3755 -- needed and may generate early references to non frozen types
3756 -- since we expand aggregate much more systematically.
3758 if Modify_Tree_For_C
then
3763 Agg
: constant Node_Id
:=
3764 Build_Equivalent_Record_Aggregate
(Rec_Type
);
3766 procedure Collect_Itypes
(Comp
: Node_Id
);
3767 -- Generate references to itypes in the aggregate, because
3768 -- the first use of the aggregate may be in a nested scope.
3770 --------------------
3771 -- Collect_Itypes --
3772 --------------------
3774 procedure Collect_Itypes
(Comp
: Node_Id
) is
3777 Typ
: constant Entity_Id
:= Etype
(Comp
);
3780 if Is_Array_Type
(Typ
) and then Is_Itype
(Typ
) then
3781 Ref
:= Make_Itype_Reference
(Loc
);
3782 Set_Itype
(Ref
, Typ
);
3783 Append_Freeze_Action
(Rec_Type
, Ref
);
3785 Ref
:= Make_Itype_Reference
(Loc
);
3786 Set_Itype
(Ref
, Etype
(First_Index
(Typ
)));
3787 Append_Freeze_Action
(Rec_Type
, Ref
);
3789 -- Recurse on nested arrays
3791 Sub_Aggr
:= First
(Expressions
(Comp
));
3792 while Present
(Sub_Aggr
) loop
3793 Collect_Itypes
(Sub_Aggr
);
3800 -- If there is a static initialization aggregate for the type,
3801 -- generate itype references for the types of its (sub)components,
3802 -- to prevent out-of-scope errors in the resulting tree.
3803 -- The aggregate may have been rewritten as a Raise node, in which
3804 -- case there are no relevant itypes.
3806 if Present
(Agg
) and then Nkind
(Agg
) = N_Aggregate
then
3807 Set_Static_Initialization
(Proc_Id
, Agg
);
3812 Comp
:= First
(Component_Associations
(Agg
));
3813 while Present
(Comp
) loop
3814 Collect_Itypes
(Expression
(Comp
));
3821 end Build_Record_Init_Proc
;
3823 ----------------------------
3824 -- Build_Slice_Assignment --
3825 ----------------------------
3827 -- Generates the following subprogram:
3830 -- (Source, Target : Array_Type,
3831 -- Left_Lo, Left_Hi : Index;
3832 -- Right_Lo, Right_Hi : Index;
3840 -- if Left_Hi < Left_Lo then
3853 -- Target (Li1) := Source (Ri1);
3856 -- exit when Li1 = Left_Lo;
3857 -- Li1 := Index'pred (Li1);
3858 -- Ri1 := Index'pred (Ri1);
3860 -- exit when Li1 = Left_Hi;
3861 -- Li1 := Index'succ (Li1);
3862 -- Ri1 := Index'succ (Ri1);
3867 procedure Build_Slice_Assignment
(Typ
: Entity_Id
) is
3868 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3869 Index
: constant Entity_Id
:= Base_Type
(Etype
(First_Index
(Typ
)));
3871 Larray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
3872 Rarray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3873 Left_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3874 Left_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3875 Right_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3876 Right_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3877 Rev
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
3878 -- Formal parameters of procedure
3880 Proc_Name
: constant Entity_Id
:=
3881 Make_Defining_Identifier
(Loc
,
3882 Chars
=> Make_TSS_Name
(Typ
, TSS_Slice_Assign
));
3884 Lnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3885 Rnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3886 -- Subscripts for left and right sides
3893 -- Build declarations for indexes
3898 Make_Object_Declaration
(Loc
,
3899 Defining_Identifier
=> Lnn
,
3900 Object_Definition
=>
3901 New_Occurrence_Of
(Index
, Loc
)));
3904 Make_Object_Declaration
(Loc
,
3905 Defining_Identifier
=> Rnn
,
3906 Object_Definition
=>
3907 New_Occurrence_Of
(Index
, Loc
)));
3911 -- Build test for empty slice case
3914 Make_If_Statement
(Loc
,
3917 Left_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
),
3918 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
)),
3919 Then_Statements
=> New_List
(Make_Simple_Return_Statement
(Loc
))));
3921 -- Build initializations for indexes
3924 F_Init
: constant List_Id
:= New_List
;
3925 B_Init
: constant List_Id
:= New_List
;
3929 Make_Assignment_Statement
(Loc
,
3930 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3931 Expression
=> New_Occurrence_Of
(Left_Lo
, Loc
)));
3934 Make_Assignment_Statement
(Loc
,
3935 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3936 Expression
=> New_Occurrence_Of
(Right_Lo
, Loc
)));
3939 Make_Assignment_Statement
(Loc
,
3940 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3941 Expression
=> New_Occurrence_Of
(Left_Hi
, Loc
)));
3944 Make_Assignment_Statement
(Loc
,
3945 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3946 Expression
=> New_Occurrence_Of
(Right_Hi
, Loc
)));
3949 Make_If_Statement
(Loc
,
3950 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
3951 Then_Statements
=> B_Init
,
3952 Else_Statements
=> F_Init
));
3955 -- Now construct the assignment statement
3958 Make_Loop_Statement
(Loc
,
3959 Statements
=> New_List
(
3960 Make_Assignment_Statement
(Loc
,
3962 Make_Indexed_Component
(Loc
,
3963 Prefix
=> New_Occurrence_Of
(Larray
, Loc
),
3964 Expressions
=> New_List
(New_Occurrence_Of
(Lnn
, Loc
))),
3966 Make_Indexed_Component
(Loc
,
3967 Prefix
=> New_Occurrence_Of
(Rarray
, Loc
),
3968 Expressions
=> New_List
(New_Occurrence_Of
(Rnn
, Loc
))))),
3969 End_Label
=> Empty
);
3971 -- Build the exit condition and increment/decrement statements
3974 F_Ass
: constant List_Id
:= New_List
;
3975 B_Ass
: constant List_Id
:= New_List
;
3979 Make_Exit_Statement
(Loc
,
3982 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
3983 Right_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
))));
3986 Make_Assignment_Statement
(Loc
,
3987 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3989 Make_Attribute_Reference
(Loc
,
3991 New_Occurrence_Of
(Index
, Loc
),
3992 Attribute_Name
=> Name_Succ
,
3993 Expressions
=> New_List
(
3994 New_Occurrence_Of
(Lnn
, Loc
)))));
3997 Make_Assignment_Statement
(Loc
,
3998 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4000 Make_Attribute_Reference
(Loc
,
4002 New_Occurrence_Of
(Index
, Loc
),
4003 Attribute_Name
=> Name_Succ
,
4004 Expressions
=> New_List
(
4005 New_Occurrence_Of
(Rnn
, Loc
)))));
4008 Make_Exit_Statement
(Loc
,
4011 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4012 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
))));
4015 Make_Assignment_Statement
(Loc
,
4016 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4018 Make_Attribute_Reference
(Loc
,
4020 New_Occurrence_Of
(Index
, Loc
),
4021 Attribute_Name
=> Name_Pred
,
4022 Expressions
=> New_List
(
4023 New_Occurrence_Of
(Lnn
, Loc
)))));
4026 Make_Assignment_Statement
(Loc
,
4027 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4029 Make_Attribute_Reference
(Loc
,
4031 New_Occurrence_Of
(Index
, Loc
),
4032 Attribute_Name
=> Name_Pred
,
4033 Expressions
=> New_List
(
4034 New_Occurrence_Of
(Rnn
, Loc
)))));
4036 Append_To
(Statements
(Loops
),
4037 Make_If_Statement
(Loc
,
4038 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4039 Then_Statements
=> B_Ass
,
4040 Else_Statements
=> F_Ass
));
4043 Append_To
(Stats
, Loops
);
4047 Formals
: List_Id
:= New_List
;
4050 Formals
:= New_List
(
4051 Make_Parameter_Specification
(Loc
,
4052 Defining_Identifier
=> Larray
,
4053 Out_Present
=> True,
4055 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4057 Make_Parameter_Specification
(Loc
,
4058 Defining_Identifier
=> Rarray
,
4060 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4062 Make_Parameter_Specification
(Loc
,
4063 Defining_Identifier
=> Left_Lo
,
4065 New_Occurrence_Of
(Index
, Loc
)),
4067 Make_Parameter_Specification
(Loc
,
4068 Defining_Identifier
=> Left_Hi
,
4070 New_Occurrence_Of
(Index
, Loc
)),
4072 Make_Parameter_Specification
(Loc
,
4073 Defining_Identifier
=> Right_Lo
,
4075 New_Occurrence_Of
(Index
, Loc
)),
4077 Make_Parameter_Specification
(Loc
,
4078 Defining_Identifier
=> Right_Hi
,
4080 New_Occurrence_Of
(Index
, Loc
)));
4083 Make_Parameter_Specification
(Loc
,
4084 Defining_Identifier
=> Rev
,
4086 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
4089 Make_Procedure_Specification
(Loc
,
4090 Defining_Unit_Name
=> Proc_Name
,
4091 Parameter_Specifications
=> Formals
);
4094 Make_Subprogram_Body
(Loc
,
4095 Specification
=> Spec
,
4096 Declarations
=> Decls
,
4097 Handled_Statement_Sequence
=>
4098 Make_Handled_Sequence_Of_Statements
(Loc
,
4099 Statements
=> Stats
)));
4102 Set_TSS
(Typ
, Proc_Name
);
4103 Set_Is_Pure
(Proc_Name
);
4104 end Build_Slice_Assignment
;
4106 -----------------------------
4107 -- Build_Untagged_Equality --
4108 -----------------------------
4110 procedure Build_Untagged_Equality
(Typ
: Entity_Id
) is
4118 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
;
4119 -- Check whether the type T has a user-defined primitive equality. If so
4120 -- return it, else return Empty. If true for a component of Typ, we have
4121 -- to build the primitive equality for it.
4123 ---------------------
4124 -- User_Defined_Eq --
4125 ---------------------
4127 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
is
4132 Op
:= TSS
(T
, TSS_Composite_Equality
);
4134 if Present
(Op
) then
4138 Prim
:= First_Elmt
(Collect_Primitive_Operations
(T
));
4139 while Present
(Prim
) loop
4142 if Chars
(Op
) = Name_Op_Eq
4143 and then Etype
(Op
) = Standard_Boolean
4144 and then Etype
(First_Formal
(Op
)) = T
4145 and then Etype
(Next_Formal
(First_Formal
(Op
))) = T
4154 end User_Defined_Eq
;
4156 -- Start of processing for Build_Untagged_Equality
4159 -- If a record component has a primitive equality operation, we must
4160 -- build the corresponding one for the current type.
4163 Comp
:= First_Component
(Typ
);
4164 while Present
(Comp
) loop
4165 if Is_Record_Type
(Etype
(Comp
))
4166 and then Present
(User_Defined_Eq
(Etype
(Comp
)))
4171 Next_Component
(Comp
);
4174 -- If there is a user-defined equality for the type, we do not create
4175 -- the implicit one.
4177 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Typ
));
4179 while Present
(Prim
) loop
4180 if Chars
(Node
(Prim
)) = Name_Op_Eq
4181 and then Comes_From_Source
(Node
(Prim
))
4183 -- Don't we also need to check formal types and return type as in
4184 -- User_Defined_Eq above???
4187 Eq_Op
:= Node
(Prim
);
4195 -- If the type is derived, inherit the operation, if present, from the
4196 -- parent type. It may have been declared after the type derivation. If
4197 -- the parent type itself is derived, it may have inherited an operation
4198 -- that has itself been overridden, so update its alias and related
4199 -- flags. Ditto for inequality.
4201 if No
(Eq_Op
) and then Is_Derived_Type
(Typ
) then
4202 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Etype
(Typ
)));
4203 while Present
(Prim
) loop
4204 if Chars
(Node
(Prim
)) = Name_Op_Eq
then
4205 Copy_TSS
(Node
(Prim
), Typ
);
4209 Op
: constant Entity_Id
:= User_Defined_Eq
(Typ
);
4210 Eq_Op
: constant Entity_Id
:= Node
(Prim
);
4211 NE_Op
: constant Entity_Id
:= Next_Entity
(Eq_Op
);
4214 if Present
(Op
) then
4215 Set_Alias
(Op
, Eq_Op
);
4216 Set_Is_Abstract_Subprogram
4217 (Op
, Is_Abstract_Subprogram
(Eq_Op
));
4219 if Chars
(Next_Entity
(Op
)) = Name_Op_Ne
then
4220 Set_Is_Abstract_Subprogram
4221 (Next_Entity
(Op
), Is_Abstract_Subprogram
(NE_Op
));
4233 -- If not inherited and not user-defined, build body as for a type with
4234 -- tagged components.
4238 Make_Eq_Body
(Typ
, Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4239 Op
:= Defining_Entity
(Decl
);
4243 if Is_Library_Level_Entity
(Typ
) then
4247 end Build_Untagged_Equality
;
4249 -----------------------------------
4250 -- Build_Variant_Record_Equality --
4251 -----------------------------------
4255 -- function <<Body_Id>> (Left, Right : T) return Boolean is
4256 -- [ X : T renames Left; ]
4257 -- [ Y : T renames Right; ]
4258 -- -- The above renamings are generated only if the parameters of
4259 -- -- this built function (which are passed by the caller) are not
4260 -- -- named 'X' and 'Y'; these names are required to reuse several
4261 -- -- expander routines when generating this body.
4264 -- -- Compare discriminants
4266 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4270 -- -- Compare components
4272 -- if X.C1 /= Y.C1 or else X.C2 /= Y.C2 or else ... then
4276 -- -- Compare variant part
4280 -- if X.C2 /= Y.C2 or else X.C3 /= Y.C3 or else ... then
4285 -- if X.Cn /= Y.Cn or else ... then
4293 function Build_Variant_Record_Equality
4295 Body_Id
: Entity_Id
;
4296 Param_Specs
: List_Id
) return Node_Id
4298 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4299 Def
: constant Node_Id
:= Parent
(Typ
);
4300 Comps
: constant Node_Id
:= Component_List
(Type_Definition
(Def
));
4301 Left
: constant Entity_Id
:= Defining_Identifier
(First
(Param_Specs
));
4302 Right
: constant Entity_Id
:=
4303 Defining_Identifier
(Next
(First
(Param_Specs
)));
4304 Decls
: constant List_Id
:= New_List
;
4305 Stmts
: constant List_Id
:= New_List
;
4307 Subp_Body
: Node_Id
;
4310 pragma Assert
(not Is_Tagged_Type
(Typ
));
4312 -- In order to reuse the expander routines Make_Eq_If and Make_Eq_Case
4313 -- the name of the formals must be X and Y; otherwise we generate two
4314 -- renaming declarations for such purpose.
4316 if Chars
(Left
) /= Name_X
then
4318 Make_Object_Renaming_Declaration
(Loc
,
4319 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
4320 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4321 Name
=> Make_Identifier
(Loc
, Chars
(Left
))));
4324 if Chars
(Right
) /= Name_Y
then
4326 Make_Object_Renaming_Declaration
(Loc
,
4327 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
4328 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4329 Name
=> Make_Identifier
(Loc
, Chars
(Right
))));
4332 -- Unchecked_Unions require additional machinery to support equality.
4333 -- Two extra parameters (A and B) are added to the equality function
4334 -- parameter list for each discriminant of the type, in order to
4335 -- capture the inferred values of the discriminants in equality calls.
4336 -- The names of the parameters match the names of the corresponding
4337 -- discriminant, with an added suffix.
4339 if Is_Unchecked_Union
(Typ
) then
4344 Discr_Type
: Entity_Id
;
4345 New_Discrs
: Elist_Id
;
4348 New_Discrs
:= New_Elmt_List
;
4350 Discr
:= First_Discriminant
(Typ
);
4351 while Present
(Discr
) loop
4352 Discr_Type
:= Etype
(Discr
);
4355 Make_Defining_Identifier
(Loc
,
4356 Chars
=> New_External_Name
(Chars
(Discr
), 'A'));
4359 Make_Defining_Identifier
(Loc
,
4360 Chars
=> New_External_Name
(Chars
(Discr
), 'B'));
4362 -- Add new parameters to the parameter list
4364 Append_To
(Param_Specs
,
4365 Make_Parameter_Specification
(Loc
,
4366 Defining_Identifier
=> A
,
4368 New_Occurrence_Of
(Discr_Type
, Loc
)));
4370 Append_To
(Param_Specs
,
4371 Make_Parameter_Specification
(Loc
,
4372 Defining_Identifier
=> B
,
4374 New_Occurrence_Of
(Discr_Type
, Loc
)));
4376 Append_Elmt
(A
, New_Discrs
);
4378 -- Generate the following code to compare each of the inferred
4386 Make_If_Statement
(Loc
,
4389 Left_Opnd
=> New_Occurrence_Of
(A
, Loc
),
4390 Right_Opnd
=> New_Occurrence_Of
(B
, Loc
)),
4391 Then_Statements
=> New_List
(
4392 Make_Simple_Return_Statement
(Loc
,
4394 New_Occurrence_Of
(Standard_False
, Loc
)))));
4395 Next_Discriminant
(Discr
);
4398 -- Generate component-by-component comparison. Note that we must
4399 -- propagate the inferred discriminants formals to act as the case
4400 -- statement switch. Their value is added when an equality call on
4401 -- unchecked unions is expanded.
4403 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
, New_Discrs
));
4406 -- Normal case (not unchecked union)
4410 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
4411 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
4415 Make_Simple_Return_Statement
(Loc
,
4416 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
4419 Make_Subprogram_Body
(Loc
,
4421 Make_Function_Specification
(Loc
,
4422 Defining_Unit_Name
=> Body_Id
,
4423 Parameter_Specifications
=> Param_Specs
,
4424 Result_Definition
=>
4425 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
4426 Declarations
=> Decls
,
4427 Handled_Statement_Sequence
=>
4428 Make_Handled_Sequence_Of_Statements
(Loc
,
4429 Statements
=> Stmts
));
4432 end Build_Variant_Record_Equality
;
4434 -----------------------------
4435 -- Check_Stream_Attributes --
4436 -----------------------------
4438 procedure Check_Stream_Attributes
(Typ
: Entity_Id
) is
4440 Par_Read
: constant Boolean :=
4441 Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
4442 and then not Has_Specified_Stream_Read
(Typ
);
4443 Par_Write
: constant Boolean :=
4444 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
4445 and then not Has_Specified_Stream_Write
(Typ
);
4447 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
);
4448 -- Check that Comp has a user-specified Nam stream attribute
4454 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
) is
4456 if not Stream_Attribute_Available
(Etype
(Comp
), TSS_Nam
) then
4457 Error_Msg_Name_1
:= Nam
;
4459 ("|component& in limited extension must have% attribute", Comp
);
4463 -- Start of processing for Check_Stream_Attributes
4466 if Par_Read
or else Par_Write
then
4467 Comp
:= First_Component
(Typ
);
4468 while Present
(Comp
) loop
4469 if Comes_From_Source
(Comp
)
4470 and then Original_Record_Component
(Comp
) = Comp
4471 and then Is_Limited_Type
(Etype
(Comp
))
4474 Check_Attr
(Name_Read
, TSS_Stream_Read
);
4478 Check_Attr
(Name_Write
, TSS_Stream_Write
);
4482 Next_Component
(Comp
);
4485 end Check_Stream_Attributes
;
4487 ----------------------
4488 -- Clean_Task_Names --
4489 ----------------------
4491 procedure Clean_Task_Names
4493 Proc_Id
: Entity_Id
)
4497 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
4498 and then not Global_Discard_Names
4499 and then Tagged_Type_Expansion
4501 Set_Uses_Sec_Stack
(Proc_Id
);
4503 end Clean_Task_Names
;
4505 ------------------------------
4506 -- Expand_Freeze_Array_Type --
4507 ------------------------------
4509 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
4510 Typ
: constant Entity_Id
:= Entity
(N
);
4511 Base
: constant Entity_Id
:= Base_Type
(Typ
);
4512 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
4515 if not Is_Bit_Packed_Array
(Typ
) then
4517 -- If the component contains tasks, so does the array type. This may
4518 -- not be indicated in the array type because the component may have
4519 -- been a private type at the point of definition. Same if component
4520 -- type is controlled or contains protected objects.
4522 Propagate_Concurrent_Flags
(Base
, Comp_Typ
);
4523 Set_Has_Controlled_Component
4524 (Base
, Has_Controlled_Component
(Comp_Typ
)
4525 or else Is_Controlled
(Comp_Typ
));
4527 if No
(Init_Proc
(Base
)) then
4529 -- If this is an anonymous array created for a declaration with
4530 -- an initial value, its init_proc will never be called. The
4531 -- initial value itself may have been expanded into assignments,
4532 -- in which case the object declaration is carries the
4533 -- No_Initialization flag.
4536 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
4537 N_Object_Declaration
4539 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
4540 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
4544 -- We do not need an init proc for string or wide [wide] string,
4545 -- since the only time these need initialization in normalize or
4546 -- initialize scalars mode, and these types are treated specially
4547 -- and do not need initialization procedures.
4549 elsif Is_Standard_String_Type
(Base
) then
4552 -- Otherwise we have to build an init proc for the subtype
4555 Build_Array_Init_Proc
(Base
, N
);
4559 if Typ
= Base
and then Has_Controlled_Component
(Base
) then
4560 Build_Controlling_Procs
(Base
);
4562 if not Is_Limited_Type
(Comp_Typ
)
4563 and then Number_Dimensions
(Typ
) = 1
4565 Build_Slice_Assignment
(Typ
);
4569 -- For packed case, default initialization, except if the component type
4570 -- is itself a packed structure with an initialization procedure, or
4571 -- initialize/normalize scalars active, and we have a base type, or the
4572 -- type is public, because in that case a client might specify
4573 -- Normalize_Scalars and there better be a public Init_Proc for it.
4575 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
4576 and then No
(Base_Init_Proc
(Base
)))
4577 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
4578 or else Is_Public
(Typ
)
4580 Build_Array_Init_Proc
(Base
, N
);
4582 end Expand_Freeze_Array_Type
;
4584 -----------------------------------
4585 -- Expand_Freeze_Class_Wide_Type --
4586 -----------------------------------
4588 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
4589 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
4590 -- Given a type, determine whether it is derived from a C or C++ root
4592 ---------------------
4593 -- Is_C_Derivation --
4594 ---------------------
4596 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
4603 or else Convention
(T
) = Convention_C
4604 or else Convention
(T
) = Convention_CPP
4609 exit when T
= Etype
(T
);
4615 end Is_C_Derivation
;
4619 Typ
: constant Entity_Id
:= Entity
(N
);
4620 Root
: constant Entity_Id
:= Root_Type
(Typ
);
4622 -- Start of processing for Expand_Freeze_Class_Wide_Type
4625 -- Certain run-time configurations and targets do not provide support
4626 -- for controlled types.
4628 if Restriction_Active
(No_Finalization
) then
4631 -- Do not create TSS routine Finalize_Address when dispatching calls are
4632 -- disabled since the core of the routine is a dispatching call.
4634 elsif Restriction_Active
(No_Dispatching_Calls
) then
4637 -- Do not create TSS routine Finalize_Address for concurrent class-wide
4638 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
4639 -- non-Ada side will handle their destruction.
4641 elsif Is_Concurrent_Type
(Root
)
4642 or else Is_C_Derivation
(Root
)
4643 or else Convention
(Typ
) = Convention_CPP
4647 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
4648 -- mode since the routine contains an Unchecked_Conversion.
4650 elsif CodePeer_Mode
then
4654 -- Create the body of TSS primitive Finalize_Address. This automatically
4655 -- sets the TSS entry for the class-wide type.
4657 Make_Finalize_Address_Body
(Typ
);
4658 end Expand_Freeze_Class_Wide_Type
;
4660 ------------------------------------
4661 -- Expand_Freeze_Enumeration_Type --
4662 ------------------------------------
4664 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
4665 Typ
: constant Entity_Id
:= Entity
(N
);
4666 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4671 Is_Contiguous
: Boolean;
4679 pragma Warnings
(Off
, Func
);
4682 -- Various optimizations possible if given representation is contiguous
4684 Is_Contiguous
:= True;
4686 Ent
:= First_Literal
(Typ
);
4687 Last_Repval
:= Enumeration_Rep
(Ent
);
4690 while Present
(Ent
) loop
4691 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
4692 Is_Contiguous
:= False;
4695 Last_Repval
:= Enumeration_Rep
(Ent
);
4701 if Is_Contiguous
then
4702 Set_Has_Contiguous_Rep
(Typ
);
4703 Ent
:= First_Literal
(Typ
);
4705 Lst
:= New_List
(New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
4708 -- Build list of literal references
4713 Ent
:= First_Literal
(Typ
);
4714 while Present
(Ent
) loop
4715 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
4721 -- Now build an array declaration
4723 -- typA : array (Natural range 0 .. num - 1) of ctype :=
4724 -- (v, v, v, v, v, ....)
4726 -- where ctype is the corresponding integer type. If the representation
4727 -- is contiguous, we only keep the first literal, which provides the
4728 -- offset for Pos_To_Rep computations.
4731 Make_Defining_Identifier
(Loc
,
4732 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
4734 Append_Freeze_Action
(Typ
,
4735 Make_Object_Declaration
(Loc
,
4736 Defining_Identifier
=> Arr
,
4737 Constant_Present
=> True,
4739 Object_Definition
=>
4740 Make_Constrained_Array_Definition
(Loc
,
4741 Discrete_Subtype_Definitions
=> New_List
(
4742 Make_Subtype_Indication
(Loc
,
4743 Subtype_Mark
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
4745 Make_Range_Constraint
(Loc
,
4749 Make_Integer_Literal
(Loc
, 0),
4751 Make_Integer_Literal
(Loc
, Num
- 1))))),
4753 Component_Definition
=>
4754 Make_Component_Definition
(Loc
,
4755 Aliased_Present
=> False,
4756 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
4759 Make_Aggregate
(Loc
,
4760 Expressions
=> Lst
)));
4762 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
4764 -- Now we build the function that converts representation values to
4765 -- position values. This function has the form:
4767 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
4770 -- when enum-lit'Enum_Rep => return posval;
4771 -- when enum-lit'Enum_Rep => return posval;
4774 -- [raise Constraint_Error when F "invalid data"]
4779 -- Note: the F parameter determines whether the others case (no valid
4780 -- representation) raises Constraint_Error or returns a unique value
4781 -- of minus one. The latter case is used, e.g. in 'Valid code.
4783 -- Note: the reason we use Enum_Rep values in the case here is to avoid
4784 -- the code generator making inappropriate assumptions about the range
4785 -- of the values in the case where the value is invalid. ityp is a
4786 -- signed or unsigned integer type of appropriate width.
4788 -- Note: if exceptions are not supported, then we suppress the raise
4789 -- and return -1 unconditionally (this is an erroneous program in any
4790 -- case and there is no obligation to raise Constraint_Error here). We
4791 -- also do this if pragma Restrictions (No_Exceptions) is active.
4793 -- Is this right??? What about No_Exception_Propagation???
4795 -- Representations are signed
4797 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
4799 -- The underlying type is signed. Reset the Is_Unsigned_Type
4800 -- explicitly, because it might have been inherited from
4803 Set_Is_Unsigned_Type
(Typ
, False);
4805 if Esize
(Typ
) <= Standard_Integer_Size
then
4806 Ityp
:= Standard_Integer
;
4808 Ityp
:= Universal_Integer
;
4811 -- Representations are unsigned
4814 if Esize
(Typ
) <= Standard_Integer_Size
then
4815 Ityp
:= RTE
(RE_Unsigned
);
4817 Ityp
:= RTE
(RE_Long_Long_Unsigned
);
4821 -- The body of the function is a case statement. First collect case
4822 -- alternatives, or optimize the contiguous case.
4826 -- If representation is contiguous, Pos is computed by subtracting
4827 -- the representation of the first literal.
4829 if Is_Contiguous
then
4830 Ent
:= First_Literal
(Typ
);
4832 if Enumeration_Rep
(Ent
) = Last_Repval
then
4834 -- Another special case: for a single literal, Pos is zero
4836 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
4840 Convert_To
(Standard_Integer
,
4841 Make_Op_Subtract
(Loc
,
4843 Unchecked_Convert_To
4844 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
4846 Make_Integer_Literal
(Loc
,
4847 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
4851 Make_Case_Statement_Alternative
(Loc
,
4852 Discrete_Choices
=> New_List
(
4853 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
4855 Make_Integer_Literal
(Loc
,
4856 Intval
=> Enumeration_Rep
(Ent
)),
4858 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
4860 Statements
=> New_List
(
4861 Make_Simple_Return_Statement
(Loc
,
4862 Expression
=> Pos_Expr
))));
4865 Ent
:= First_Literal
(Typ
);
4866 while Present
(Ent
) loop
4868 Make_Case_Statement_Alternative
(Loc
,
4869 Discrete_Choices
=> New_List
(
4870 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
4871 Intval
=> Enumeration_Rep
(Ent
))),
4873 Statements
=> New_List
(
4874 Make_Simple_Return_Statement
(Loc
,
4876 Make_Integer_Literal
(Loc
,
4877 Intval
=> Enumeration_Pos
(Ent
))))));
4883 -- In normal mode, add the others clause with the test.
4884 -- If Predicates_Ignored is True, validity checks do not apply to
4887 if not No_Exception_Handlers_Set
4888 and then not Predicates_Ignored
(Typ
)
4891 Make_Case_Statement_Alternative
(Loc
,
4892 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
4893 Statements
=> New_List
(
4894 Make_Raise_Constraint_Error
(Loc
,
4895 Condition
=> Make_Identifier
(Loc
, Name_uF
),
4896 Reason
=> CE_Invalid_Data
),
4897 Make_Simple_Return_Statement
(Loc
,
4898 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
4900 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
4901 -- active then return -1 (we cannot usefully raise Constraint_Error in
4902 -- this case). See description above for further details.
4906 Make_Case_Statement_Alternative
(Loc
,
4907 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
4908 Statements
=> New_List
(
4909 Make_Simple_Return_Statement
(Loc
,
4910 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
4913 -- Now we can build the function body
4916 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
4919 Make_Subprogram_Body
(Loc
,
4921 Make_Function_Specification
(Loc
,
4922 Defining_Unit_Name
=> Fent
,
4923 Parameter_Specifications
=> New_List
(
4924 Make_Parameter_Specification
(Loc
,
4925 Defining_Identifier
=>
4926 Make_Defining_Identifier
(Loc
, Name_uA
),
4927 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
4928 Make_Parameter_Specification
(Loc
,
4929 Defining_Identifier
=>
4930 Make_Defining_Identifier
(Loc
, Name_uF
),
4932 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
4934 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
4936 Declarations
=> Empty_List
,
4938 Handled_Statement_Sequence
=>
4939 Make_Handled_Sequence_Of_Statements
(Loc
,
4940 Statements
=> New_List
(
4941 Make_Case_Statement
(Loc
,
4943 Unchecked_Convert_To
4944 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
4945 Alternatives
=> Lst
))));
4947 Set_TSS
(Typ
, Fent
);
4949 -- Set Pure flag (it will be reset if the current context is not Pure).
4950 -- We also pretend there was a pragma Pure_Function so that for purposes
4951 -- of optimization and constant-folding, we will consider the function
4952 -- Pure even if we are not in a Pure context).
4955 Set_Has_Pragma_Pure_Function
(Fent
);
4957 -- Unless we are in -gnatD mode, where we are debugging generated code,
4958 -- this is an internal entity for which we don't need debug info.
4960 if not Debug_Generated_Code
then
4961 Set_Debug_Info_Off
(Fent
);
4964 Set_Is_Inlined
(Fent
);
4967 when RE_Not_Available
=>
4969 end Expand_Freeze_Enumeration_Type
;
4971 -------------------------------
4972 -- Expand_Freeze_Record_Type --
4973 -------------------------------
4975 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
4976 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
);
4977 -- Create An Equality function for the untagged variant record Typ and
4978 -- attach it to the TSS list.
4980 -----------------------------------
4981 -- Build_Variant_Record_Equality --
4982 -----------------------------------
4984 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
) is
4985 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4986 F
: constant Entity_Id
:=
4987 Make_Defining_Identifier
(Loc
,
4988 Chars
=> Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4990 -- For a variant record with restriction No_Implicit_Conditionals
4991 -- in effect we skip building the procedure. This is safe because
4992 -- if we can see the restriction, so can any caller, and calls to
4993 -- equality test routines are not allowed for variant records if
4994 -- this restriction is active.
4996 if Restriction_Active
(No_Implicit_Conditionals
) then
5000 -- Derived Unchecked_Union types no longer inherit the equality
5001 -- function of their parent.
5003 if Is_Derived_Type
(Typ
)
5004 and then not Is_Unchecked_Union
(Typ
)
5005 and then not Has_New_Non_Standard_Rep
(Typ
)
5008 Parent_Eq
: constant Entity_Id
:=
5009 TSS
(Root_Type
(Typ
), TSS_Composite_Equality
);
5011 if Present
(Parent_Eq
) then
5012 Copy_TSS
(Parent_Eq
, Typ
);
5019 Build_Variant_Record_Equality
5022 Param_Specs
=> New_List
(
5023 Make_Parameter_Specification
(Loc
,
5024 Defining_Identifier
=>
5025 Make_Defining_Identifier
(Loc
, Name_X
),
5026 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
5028 Make_Parameter_Specification
(Loc
,
5029 Defining_Identifier
=>
5030 Make_Defining_Identifier
(Loc
, Name_Y
),
5031 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))));
5036 if not Debug_Generated_Code
then
5037 Set_Debug_Info_Off
(F
);
5039 end Build_Variant_Record_Equality
;
5043 Typ
: constant Node_Id
:= Entity
(N
);
5044 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
5047 Comp_Typ
: Entity_Id
;
5048 Predef_List
: List_Id
;
5050 Wrapper_Decl_List
: List_Id
:= No_List
;
5051 Wrapper_Body_List
: List_Id
:= No_List
;
5053 Renamed_Eq
: Node_Id
:= Empty
;
5054 -- Defining unit name for the predefined equality function in the case
5055 -- where the type has a primitive operation that is a renaming of
5056 -- predefined equality (but only if there is also an overriding
5057 -- user-defined equality function). Used to pass this entity from
5058 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
5060 -- Start of processing for Expand_Freeze_Record_Type
5063 -- Build discriminant checking functions if not a derived type (for
5064 -- derived types that are not tagged types, always use the discriminant
5065 -- checking functions of the parent type). However, for untagged types
5066 -- the derivation may have taken place before the parent was frozen, so
5067 -- we copy explicitly the discriminant checking functions from the
5068 -- parent into the components of the derived type.
5070 if not Is_Derived_Type
(Typ
)
5071 or else Has_New_Non_Standard_Rep
(Typ
)
5072 or else Is_Tagged_Type
(Typ
)
5074 Build_Discr_Checking_Funcs
(Typ_Decl
);
5076 elsif Is_Derived_Type
(Typ
)
5077 and then not Is_Tagged_Type
(Typ
)
5079 -- If we have a derived Unchecked_Union, we do not inherit the
5080 -- discriminant checking functions from the parent type since the
5081 -- discriminants are non existent.
5083 and then not Is_Unchecked_Union
(Typ
)
5084 and then Has_Discriminants
(Typ
)
5087 Old_Comp
: Entity_Id
;
5091 First_Component
(Base_Type
(Underlying_Type
(Etype
(Typ
))));
5092 Comp
:= First_Component
(Typ
);
5093 while Present
(Comp
) loop
5094 if Ekind
(Comp
) = E_Component
5095 and then Chars
(Comp
) = Chars
(Old_Comp
)
5097 Set_Discriminant_Checking_Func
5098 (Comp
, Discriminant_Checking_Func
(Old_Comp
));
5101 Next_Component
(Old_Comp
);
5102 Next_Component
(Comp
);
5107 if Is_Derived_Type
(Typ
)
5108 and then Is_Limited_Type
(Typ
)
5109 and then Is_Tagged_Type
(Typ
)
5111 Check_Stream_Attributes
(Typ
);
5114 -- Update task, protected, and controlled component flags, because some
5115 -- of the component types may have been private at the point of the
5116 -- record declaration. Detect anonymous access-to-controlled components.
5118 Comp
:= First_Component
(Typ
);
5119 while Present
(Comp
) loop
5120 Comp_Typ
:= Etype
(Comp
);
5122 Propagate_Concurrent_Flags
(Typ
, Comp_Typ
);
5124 -- Do not set Has_Controlled_Component on a class-wide equivalent
5125 -- type. See Make_CW_Equivalent_Type.
5127 if not Is_Class_Wide_Equivalent_Type
(Typ
)
5129 (Has_Controlled_Component
(Comp_Typ
)
5130 or else (Chars
(Comp
) /= Name_uParent
5131 and then Is_Controlled
(Comp_Typ
)))
5133 Set_Has_Controlled_Component
(Typ
);
5136 Next_Component
(Comp
);
5139 -- Handle constructors of untagged CPP_Class types
5141 if not Is_Tagged_Type
(Typ
) and then Is_CPP_Class
(Typ
) then
5142 Set_CPP_Constructors
(Typ
);
5145 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
5146 -- for regular tagged types as well as for Ada types deriving from a C++
5147 -- Class, but not for tagged types directly corresponding to C++ classes
5148 -- In the later case we assume that it is created in the C++ side and we
5151 if Is_Tagged_Type
(Typ
) then
5153 -- Add the _Tag component
5155 if Underlying_Type
(Etype
(Typ
)) = Typ
then
5156 Expand_Tagged_Root
(Typ
);
5159 if Is_CPP_Class
(Typ
) then
5160 Set_All_DT_Position
(Typ
);
5162 -- Create the tag entities with a minimum decoration
5164 if Tagged_Type_Expansion
then
5165 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5168 Set_CPP_Constructors
(Typ
);
5171 if not Building_Static_DT
(Typ
) then
5173 -- Usually inherited primitives are not delayed but the first
5174 -- Ada extension of a CPP_Class is an exception since the
5175 -- address of the inherited subprogram has to be inserted in
5176 -- the new Ada Dispatch Table and this is a freezing action.
5178 -- Similarly, if this is an inherited operation whose parent is
5179 -- not frozen yet, it is not in the DT of the parent, and we
5180 -- generate an explicit freeze node for the inherited operation
5181 -- so it is properly inserted in the DT of the current type.
5188 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5189 while Present
(Elmt
) loop
5190 Subp
:= Node
(Elmt
);
5192 if Present
(Alias
(Subp
)) then
5193 if Is_CPP_Class
(Etype
(Typ
)) then
5194 Set_Has_Delayed_Freeze
(Subp
);
5196 elsif Has_Delayed_Freeze
(Alias
(Subp
))
5197 and then not Is_Frozen
(Alias
(Subp
))
5199 Set_Is_Frozen
(Subp
, False);
5200 Set_Has_Delayed_Freeze
(Subp
);
5209 -- Unfreeze momentarily the type to add the predefined primitives
5210 -- operations. The reason we unfreeze is so that these predefined
5211 -- operations will indeed end up as primitive operations (which
5212 -- must be before the freeze point).
5214 Set_Is_Frozen
(Typ
, False);
5216 -- Do not add the spec of predefined primitives in case of
5217 -- CPP tagged type derivations that have convention CPP.
5219 if Is_CPP_Class
(Root_Type
(Typ
))
5220 and then Convention
(Typ
) = Convention_CPP
5224 -- Do not add the spec of the predefined primitives if we are
5225 -- compiling under restriction No_Dispatching_Calls.
5227 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5228 Make_Predefined_Primitive_Specs
(Typ
, Predef_List
, Renamed_Eq
);
5229 Insert_List_Before_And_Analyze
(N
, Predef_List
);
5232 -- Ada 2005 (AI-391): For a nonabstract null extension, create
5233 -- wrapper functions for each nonoverridden inherited function
5234 -- with a controlling result of the type. The wrapper for such
5235 -- a function returns an extension aggregate that invokes the
5238 if Ada_Version
>= Ada_2005
5239 and then not Is_Abstract_Type
(Typ
)
5240 and then Is_Null_Extension
(Typ
)
5242 Make_Controlling_Function_Wrappers
5243 (Typ
, Wrapper_Decl_List
, Wrapper_Body_List
);
5244 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
5247 -- Ada 2005 (AI-251): For a nonabstract type extension, build
5248 -- null procedure declarations for each set of homographic null
5249 -- procedures that are inherited from interface types but not
5250 -- overridden. This is done to ensure that the dispatch table
5251 -- entry associated with such null primitives are properly filled.
5253 if Ada_Version
>= Ada_2005
5254 and then Etype
(Typ
) /= Typ
5255 and then not Is_Abstract_Type
(Typ
)
5256 and then Has_Interfaces
(Typ
)
5258 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Typ
));
5261 Set_Is_Frozen
(Typ
);
5263 if not Is_Derived_Type
(Typ
)
5264 or else Is_Tagged_Type
(Etype
(Typ
))
5266 Set_All_DT_Position
(Typ
);
5268 -- If this is a type derived from an untagged private type whose
5269 -- full view is tagged, the type is marked tagged for layout
5270 -- reasons, but it has no dispatch table.
5272 elsif Is_Derived_Type
(Typ
)
5273 and then Is_Private_Type
(Etype
(Typ
))
5274 and then not Is_Tagged_Type
(Etype
(Typ
))
5279 -- Create and decorate the tags. Suppress their creation when
5280 -- not Tagged_Type_Expansion because the dispatching mechanism is
5281 -- handled internally by the virtual target.
5283 if Tagged_Type_Expansion
then
5284 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5286 -- Generate dispatch table of locally defined tagged type.
5287 -- Dispatch tables of library level tagged types are built
5288 -- later (see Analyze_Declarations).
5290 if not Building_Static_DT
(Typ
) then
5291 Append_Freeze_Actions
(Typ
, Make_DT
(Typ
));
5295 -- If the type has unknown discriminants, propagate dispatching
5296 -- information to its underlying record view, which does not get
5297 -- its own dispatch table.
5299 if Is_Derived_Type
(Typ
)
5300 and then Has_Unknown_Discriminants
(Typ
)
5301 and then Present
(Underlying_Record_View
(Typ
))
5304 Rep
: constant Entity_Id
:= Underlying_Record_View
(Typ
);
5306 Set_Access_Disp_Table
5307 (Rep
, Access_Disp_Table
(Typ
));
5308 Set_Dispatch_Table_Wrappers
5309 (Rep
, Dispatch_Table_Wrappers
(Typ
));
5310 Set_Direct_Primitive_Operations
5311 (Rep
, Direct_Primitive_Operations
(Typ
));
5315 -- Make sure that the primitives Initialize, Adjust and Finalize
5316 -- are Frozen before other TSS subprograms. We don't want them
5319 if Is_Controlled
(Typ
) then
5320 if not Is_Limited_Type
(Typ
) then
5321 Append_Freeze_Actions
(Typ
,
5322 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Adjust
), Typ
));
5325 Append_Freeze_Actions
(Typ
,
5326 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Initialize
), Typ
));
5328 Append_Freeze_Actions
(Typ
,
5329 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Finalize
), Typ
));
5332 -- Freeze rest of primitive operations. There is no need to handle
5333 -- the predefined primitives if we are compiling under restriction
5334 -- No_Dispatching_Calls.
5336 if not Restriction_Active
(No_Dispatching_Calls
) then
5337 Append_Freeze_Actions
(Typ
, Predefined_Primitive_Freeze
(Typ
));
5341 -- In the untagged case, ever since Ada 83 an equality function must
5342 -- be provided for variant records that are not unchecked unions.
5343 -- In Ada 2012 the equality function composes, and thus must be built
5344 -- explicitly just as for tagged records.
5346 elsif Has_Discriminants
(Typ
)
5347 and then not Is_Limited_Type
(Typ
)
5350 Comps
: constant Node_Id
:=
5351 Component_List
(Type_Definition
(Typ_Decl
));
5354 and then Present
(Variant_Part
(Comps
))
5356 Build_Variant_Record_Equality
(Typ
);
5360 -- Otherwise create primitive equality operation (AI05-0123)
5362 -- This is done unconditionally to ensure that tools can be linked
5363 -- properly with user programs compiled with older language versions.
5364 -- In addition, this is needed because "=" composes for bounded strings
5365 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
5367 elsif Comes_From_Source
(Typ
)
5368 and then Convention
(Typ
) = Convention_Ada
5369 and then not Is_Limited_Type
(Typ
)
5371 Build_Untagged_Equality
(Typ
);
5374 -- Before building the record initialization procedure, if we are
5375 -- dealing with a concurrent record value type, then we must go through
5376 -- the discriminants, exchanging discriminals between the concurrent
5377 -- type and the concurrent record value type. See the section "Handling
5378 -- of Discriminants" in the Einfo spec for details.
5380 if Is_Concurrent_Record_Type
(Typ
)
5381 and then Has_Discriminants
(Typ
)
5384 Ctyp
: constant Entity_Id
:=
5385 Corresponding_Concurrent_Type
(Typ
);
5386 Conc_Discr
: Entity_Id
;
5387 Rec_Discr
: Entity_Id
;
5391 Conc_Discr
:= First_Discriminant
(Ctyp
);
5392 Rec_Discr
:= First_Discriminant
(Typ
);
5393 while Present
(Conc_Discr
) loop
5394 Temp
:= Discriminal
(Conc_Discr
);
5395 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
5396 Set_Discriminal
(Rec_Discr
, Temp
);
5398 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
5399 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
5401 Next_Discriminant
(Conc_Discr
);
5402 Next_Discriminant
(Rec_Discr
);
5407 if Has_Controlled_Component
(Typ
) then
5408 Build_Controlling_Procs
(Typ
);
5411 Adjust_Discriminants
(Typ
);
5413 -- Do not need init for interfaces on virtual targets since they're
5416 if Tagged_Type_Expansion
or else not Is_Interface
(Typ
) then
5417 Build_Record_Init_Proc
(Typ_Decl
, Typ
);
5420 -- For tagged type that are not interfaces, build bodies of primitive
5421 -- operations. Note: do this after building the record initialization
5422 -- procedure, since the primitive operations may need the initialization
5423 -- routine. There is no need to add predefined primitives of interfaces
5424 -- because all their predefined primitives are abstract.
5426 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
5428 -- Do not add the body of predefined primitives in case of CPP tagged
5429 -- type derivations that have convention CPP.
5431 if Is_CPP_Class
(Root_Type
(Typ
))
5432 and then Convention
(Typ
) = Convention_CPP
5436 -- Do not add the body of the predefined primitives if we are
5437 -- compiling under restriction No_Dispatching_Calls or if we are
5438 -- compiling a CPP tagged type.
5440 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5442 -- Create the body of TSS primitive Finalize_Address. This must
5443 -- be done before the bodies of all predefined primitives are
5444 -- created. If Typ is limited, Stream_Input and Stream_Read may
5445 -- produce build-in-place allocations and for those the expander
5446 -- needs Finalize_Address.
5448 Make_Finalize_Address_Body
(Typ
);
5449 Predef_List
:= Predefined_Primitive_Bodies
(Typ
, Renamed_Eq
);
5450 Append_Freeze_Actions
(Typ
, Predef_List
);
5453 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
5454 -- inherited functions, then add their bodies to the freeze actions.
5456 if Present
(Wrapper_Body_List
) then
5457 Append_Freeze_Actions
(Typ
, Wrapper_Body_List
);
5460 -- Create extra formals for the primitive operations of the type.
5461 -- This must be done before analyzing the body of the initialization
5462 -- procedure, because a self-referential type might call one of these
5463 -- primitives in the body of the init_proc itself.
5470 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5471 while Present
(Elmt
) loop
5472 Subp
:= Node
(Elmt
);
5473 if not Has_Foreign_Convention
(Subp
)
5474 and then not Is_Predefined_Dispatching_Operation
(Subp
)
5476 Create_Extra_Formals
(Subp
);
5483 end Expand_Freeze_Record_Type
;
5485 ------------------------------------
5486 -- Expand_N_Full_Type_Declaration --
5487 ------------------------------------
5489 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
) is
5490 procedure Build_Master
(Ptr_Typ
: Entity_Id
);
5491 -- Create the master associated with Ptr_Typ
5497 procedure Build_Master
(Ptr_Typ
: Entity_Id
) is
5498 Desig_Typ
: Entity_Id
:= Designated_Type
(Ptr_Typ
);
5501 -- If the designated type is an incomplete view coming from a
5502 -- limited-with'ed package, we need to use the nonlimited view in
5503 -- case it has tasks.
5505 if Ekind
(Desig_Typ
) in Incomplete_Kind
5506 and then Present
(Non_Limited_View
(Desig_Typ
))
5508 Desig_Typ
:= Non_Limited_View
(Desig_Typ
);
5511 -- Anonymous access types are created for the components of the
5512 -- record parameter for an entry declaration. No master is created
5515 if Comes_From_Source
(N
) and then Has_Task
(Desig_Typ
) then
5516 Build_Master_Entity
(Ptr_Typ
);
5517 Build_Master_Renaming
(Ptr_Typ
);
5519 -- Create a class-wide master because a Master_Id must be generated
5520 -- for access-to-limited-class-wide types whose root may be extended
5521 -- with task components.
5523 -- Note: This code covers access-to-limited-interfaces because they
5524 -- can be used to reference tasks implementing them.
5526 elsif Is_Limited_Class_Wide_Type
(Desig_Typ
)
5527 and then Tasking_Allowed
5529 Build_Class_Wide_Master
(Ptr_Typ
);
5533 -- Local declarations
5535 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5536 B_Id
: constant Entity_Id
:= Base_Type
(Def_Id
);
5540 -- Start of processing for Expand_N_Full_Type_Declaration
5543 if Is_Access_Type
(Def_Id
) then
5544 Build_Master
(Def_Id
);
5546 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
5547 Expand_Access_Protected_Subprogram_Type
(N
);
5550 -- Array of anonymous access-to-task pointers
5552 elsif Ada_Version
>= Ada_2005
5553 and then Is_Array_Type
(Def_Id
)
5554 and then Is_Access_Type
(Component_Type
(Def_Id
))
5555 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
5557 Build_Master
(Component_Type
(Def_Id
));
5559 elsif Has_Task
(Def_Id
) then
5560 Expand_Previous_Access_Type
(Def_Id
);
5562 -- Check the components of a record type or array of records for
5563 -- anonymous access-to-task pointers.
5565 elsif Ada_Version
>= Ada_2005
5566 and then (Is_Record_Type
(Def_Id
)
5568 (Is_Array_Type
(Def_Id
)
5569 and then Is_Record_Type
(Component_Type
(Def_Id
))))
5578 if Is_Array_Type
(Def_Id
) then
5579 Comp
:= First_Entity
(Component_Type
(Def_Id
));
5581 Comp
:= First_Entity
(Def_Id
);
5584 -- Examine all components looking for anonymous access-to-task
5588 while Present
(Comp
) loop
5589 Typ
:= Etype
(Comp
);
5591 if Ekind
(Typ
) = E_Anonymous_Access_Type
5592 and then Has_Task
(Available_View
(Designated_Type
(Typ
)))
5593 and then No
(Master_Id
(Typ
))
5595 -- Ensure that the record or array type have a _master
5598 Build_Master_Entity
(Def_Id
);
5599 Build_Master_Renaming
(Typ
);
5600 M_Id
:= Master_Id
(Typ
);
5604 -- Reuse the same master to service any additional types
5607 Set_Master_Id
(Typ
, M_Id
);
5616 Par_Id
:= Etype
(B_Id
);
5618 -- The parent type is private then we need to inherit any TSS operations
5619 -- from the full view.
5621 if Ekind
(Par_Id
) in Private_Kind
5622 and then Present
(Full_View
(Par_Id
))
5624 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
5627 if Nkind
(Type_Definition
(Original_Node
(N
))) =
5628 N_Derived_Type_Definition
5629 and then not Is_Tagged_Type
(Def_Id
)
5630 and then Present
(Freeze_Node
(Par_Id
))
5631 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
5633 Ensure_Freeze_Node
(B_Id
);
5634 FN
:= Freeze_Node
(B_Id
);
5636 if No
(TSS_Elist
(FN
)) then
5637 Set_TSS_Elist
(FN
, New_Elmt_List
);
5641 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
5645 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
5646 while Present
(Elmt
) loop
5647 if Chars
(Node
(Elmt
)) /= Name_uInit
then
5648 Append_Elmt
(Node
(Elmt
), T_E
);
5654 -- If the derived type itself is private with a full view, then
5655 -- associate the full view with the inherited TSS_Elist as well.
5657 if Ekind
(B_Id
) in Private_Kind
5658 and then Present
(Full_View
(B_Id
))
5660 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
5662 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
5666 end Expand_N_Full_Type_Declaration
;
5668 ---------------------------------
5669 -- Expand_N_Object_Declaration --
5670 ---------------------------------
5672 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
5673 Loc
: constant Source_Ptr
:= Sloc
(N
);
5674 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5675 Expr
: constant Node_Id
:= Expression
(N
);
5676 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
5677 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
5678 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5681 function Build_Equivalent_Aggregate
return Boolean;
5682 -- If the object has a constrained discriminated type and no initial
5683 -- value, it may be possible to build an equivalent aggregate instead,
5684 -- and prevent an actual call to the initialization procedure.
5686 procedure Count_Default_Sized_Task_Stacks
5688 Pri_Stacks
: out Int
;
5689 Sec_Stacks
: out Int
);
5690 -- Count the number of default-sized primary and secondary task stacks
5691 -- required for task objects contained within type Typ. If the number of
5692 -- task objects contained within the type is not known at compile time
5693 -- the procedure will return the stack counts of zero.
5695 procedure Default_Initialize_Object
(After
: Node_Id
);
5696 -- Generate all default initialization actions for object Def_Id. Any
5697 -- new code is inserted after node After.
5699 function Rewrite_As_Renaming
return Boolean;
5700 -- Indicate whether to rewrite a declaration with initialization into an
5701 -- object renaming declaration (see below).
5703 --------------------------------
5704 -- Build_Equivalent_Aggregate --
5705 --------------------------------
5707 function Build_Equivalent_Aggregate
return Boolean is
5711 Full_Type
: Entity_Id
;
5716 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
5717 Full_Type
:= Full_View
(Typ
);
5720 -- Only perform this transformation if Elaboration_Code is forbidden
5721 -- or undesirable, and if this is a global entity of a constrained
5724 -- If Initialize_Scalars might be active this transformation cannot
5725 -- be performed either, because it will lead to different semantics
5726 -- or because elaboration code will in fact be created.
5728 if Ekind
(Full_Type
) /= E_Record_Subtype
5729 or else not Has_Discriminants
(Full_Type
)
5730 or else not Is_Constrained
(Full_Type
)
5731 or else Is_Controlled
(Full_Type
)
5732 or else Is_Limited_Type
(Full_Type
)
5733 or else not Restriction_Active
(No_Initialize_Scalars
)
5738 if Ekind
(Current_Scope
) = E_Package
5740 (Restriction_Active
(No_Elaboration_Code
)
5741 or else Is_Preelaborated
(Current_Scope
))
5743 -- Building a static aggregate is possible if the discriminants
5744 -- have static values and the other components have static
5745 -- defaults or none.
5747 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5748 while Present
(Discr
) loop
5749 if not Is_OK_Static_Expression
(Node
(Discr
)) then
5756 -- Check that initialized components are OK, and that non-
5757 -- initialized components do not require a call to their own
5758 -- initialization procedure.
5760 Comp
:= First_Component
(Full_Type
);
5761 while Present
(Comp
) loop
5762 if Ekind
(Comp
) = E_Component
5763 and then Present
(Expression
(Parent
(Comp
)))
5765 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
5769 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
5774 Next_Component
(Comp
);
5777 -- Everything is static, assemble the aggregate, discriminant
5781 Make_Aggregate
(Loc
,
5782 Expressions
=> New_List
,
5783 Component_Associations
=> New_List
);
5785 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5786 while Present
(Discr
) loop
5787 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
5791 -- Now collect values of initialized components
5793 Comp
:= First_Component
(Full_Type
);
5794 while Present
(Comp
) loop
5795 if Ekind
(Comp
) = E_Component
5796 and then Present
(Expression
(Parent
(Comp
)))
5798 Append_To
(Component_Associations
(Aggr
),
5799 Make_Component_Association
(Loc
,
5800 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
5801 Expression
=> New_Copy_Tree
5802 (Expression
(Parent
(Comp
)))));
5805 Next_Component
(Comp
);
5808 -- Finally, box-initialize remaining components
5810 Append_To
(Component_Associations
(Aggr
),
5811 Make_Component_Association
(Loc
,
5812 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5813 Expression
=> Empty
));
5814 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
5815 Set_Expression
(N
, Aggr
);
5817 if Typ
/= Full_Type
then
5818 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
5819 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
5820 Analyze_And_Resolve
(Aggr
, Typ
);
5822 Analyze_And_Resolve
(Aggr
, Full_Type
);
5830 end Build_Equivalent_Aggregate
;
5832 -------------------------------------
5833 -- Count_Default_Sized_Task_Stacks --
5834 -------------------------------------
5836 procedure Count_Default_Sized_Task_Stacks
5838 Pri_Stacks
: out Int
;
5839 Sec_Stacks
: out Int
)
5841 Component
: Entity_Id
;
5844 -- To calculate the number of default-sized task stacks required for
5845 -- an object of Typ, a depth-first recursive traversal of the AST
5846 -- from the Typ entity node is undertaken. Only type nodes containing
5847 -- task objects are visited.
5852 if not Has_Task
(Typ
) then
5860 -- A task type is found marking the bottom of the descent. If
5861 -- the type has no representation aspect for the corresponding
5862 -- stack then that stack is using the default size.
5864 if Present
(Get_Rep_Item
(Typ
, Name_Storage_Size
)) then
5870 if Present
(Get_Rep_Item
(Typ
, Name_Secondary_Stack_Size
)) then
5876 when E_Array_Subtype
5879 -- First find the number of default stacks contained within an
5882 Count_Default_Sized_Task_Stacks
5883 (Component_Type
(Typ
),
5887 -- Then multiply the result by the size of the array
5890 Quantity
: constant Int
:= Number_Of_Elements_In_Array
(Typ
);
5891 -- Number_Of_Elements_In_Array is non-trival, consequently
5892 -- its result is captured as an optimization.
5895 Pri_Stacks
:= Pri_Stacks
* Quantity
;
5896 Sec_Stacks
:= Sec_Stacks
* Quantity
;
5899 when E_Protected_Subtype
5904 Component
:= First_Component_Or_Discriminant
(Typ
);
5906 -- Recursively descend each component of the composite type
5907 -- looking for tasks, but only if the component is marked as
5910 while Present
(Component
) loop
5911 if Has_Task
(Etype
(Component
)) then
5917 Count_Default_Sized_Task_Stacks
5918 (Etype
(Component
), P
, S
);
5919 Pri_Stacks
:= Pri_Stacks
+ P
;
5920 Sec_Stacks
:= Sec_Stacks
+ S
;
5924 Next_Component_Or_Discriminant
(Component
);
5927 when E_Limited_Private_Subtype
5928 | E_Limited_Private_Type
5929 | E_Record_Subtype_With_Private
5930 | E_Record_Type_With_Private
5932 -- Switch to the full view of the private type to continue
5935 Count_Default_Sized_Task_Stacks
5936 (Full_View
(Typ
), Pri_Stacks
, Sec_Stacks
);
5938 -- Other types should not contain tasks
5941 raise Program_Error
;
5943 end Count_Default_Sized_Task_Stacks
;
5945 -------------------------------
5946 -- Default_Initialize_Object --
5947 -------------------------------
5949 procedure Default_Initialize_Object
(After
: Node_Id
) is
5950 function New_Object_Reference
return Node_Id
;
5951 -- Return a new reference to Def_Id with attributes Assignment_OK and
5952 -- Must_Not_Freeze already set.
5954 function Simple_Initialization_OK
5955 (Init_Typ
: Entity_Id
) return Boolean;
5956 -- Determine whether object declaration N with entity Def_Id needs
5957 -- simple initialization, assuming that it is of type Init_Typ.
5959 --------------------------
5960 -- New_Object_Reference --
5961 --------------------------
5963 function New_Object_Reference
return Node_Id
is
5964 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
5967 -- The call to the type init proc or [Deep_]Finalize must not
5968 -- freeze the related object as the call is internally generated.
5969 -- This way legal rep clauses that apply to the object will not be
5970 -- flagged. Note that the initialization call may be removed if
5971 -- pragma Import is encountered or moved to the freeze actions of
5972 -- the object because of an address clause.
5974 Set_Assignment_OK
(Obj_Ref
);
5975 Set_Must_Not_Freeze
(Obj_Ref
);
5978 end New_Object_Reference
;
5980 ------------------------------
5981 -- Simple_Initialization_OK --
5982 ------------------------------
5984 function Simple_Initialization_OK
5985 (Init_Typ
: Entity_Id
) return Boolean
5988 -- Do not consider the object declaration if it comes with an
5989 -- initialization expression, or is internal in which case it
5990 -- will be assigned later.
5993 not Is_Internal
(Def_Id
)
5994 and then not Has_Init_Expression
(N
)
5995 and then Needs_Simple_Initialization
5999 and then No
(Following_Address_Clause
(N
)));
6000 end Simple_Initialization_OK
;
6004 Exceptions_OK
: constant Boolean :=
6005 not Restriction_Active
(No_Exception_Propagation
);
6007 Aggr_Init
: Node_Id
;
6008 Comp_Init
: List_Id
:= No_List
;
6009 Fin_Block
: Node_Id
;
6011 Init_Stmts
: List_Id
:= No_List
;
6012 Obj_Init
: Node_Id
:= Empty
;
6015 -- Start of processing for Default_Initialize_Object
6018 -- Default initialization is suppressed for objects that are already
6019 -- known to be imported (i.e. whose declaration specifies the Import
6020 -- aspect). Note that for objects with a pragma Import, we generate
6021 -- initialization here, and then remove it downstream when processing
6022 -- the pragma. It is also suppressed for variables for which a pragma
6023 -- Suppress_Initialization has been explicitly given
6025 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
6028 -- Nothing to do if the object being initialized is of a task type
6029 -- and restriction No_Tasking is in effect, because this is a direct
6030 -- violation of the restriction.
6032 elsif Is_Task_Type
(Base_Typ
)
6033 and then Restriction_Active
(No_Tasking
)
6038 -- The expansion performed by this routine is as follows:
6042 -- Type_Init_Proc (Obj);
6045 -- [Deep_]Initialize (Obj);
6049 -- [Deep_]Finalize (Obj, Self => False);
6053 -- Abort_Undefer_Direct;
6056 -- Initialize the components of the object
6058 if Has_Non_Null_Base_Init_Proc
(Typ
)
6059 and then not No_Initialization
(N
)
6060 and then not Initialization_Suppressed
(Typ
)
6062 -- Do not initialize the components if No_Default_Initialization
6063 -- applies as the actual restriction check will occur later when
6064 -- the object is frozen as it is not known yet whether the object
6065 -- is imported or not.
6067 if not Restriction_Active
(No_Default_Initialization
) then
6069 -- If the values of the components are compile-time known, use
6070 -- their prebuilt aggregate form directly.
6072 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
6074 if Present
(Aggr_Init
) then
6076 New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
6078 -- If type has discriminants, try to build an equivalent
6079 -- aggregate using discriminant values from the declaration.
6080 -- This is a useful optimization, in particular if restriction
6081 -- No_Elaboration_Code is active.
6083 elsif Build_Equivalent_Aggregate
then
6086 -- Optimize the default initialization of an array object when
6087 -- pragma Initialize_Scalars or Normalize_Scalars is in effect.
6088 -- Construct an in-place initialization aggregate which may be
6089 -- convert into a fast memset by the backend.
6091 elsif Init_Or_Norm_Scalars
6092 and then Is_Array_Type
(Typ
)
6094 -- The array must lack atomic components because they are
6095 -- treated as non-static, and as a result the backend will
6096 -- not initialize the memory in one go.
6098 and then not Has_Atomic_Components
(Typ
)
6100 -- The array must not be packed because the invalid values
6101 -- in System.Scalar_Values are multiples of Storage_Unit.
6103 and then not Is_Packed
(Typ
)
6105 -- The array must have static non-empty ranges, otherwise
6106 -- the backend cannot initialize the memory in one go.
6108 and then Has_Static_Non_Empty_Array_Bounds
(Typ
)
6110 -- The optimization is only relevant for arrays of scalar
6113 and then Is_Scalar_Type
(Component_Type
(Typ
))
6115 -- Similar to regular array initialization using a type
6116 -- init proc, predicate checks are not performed because the
6117 -- initialization values are intentionally invalid, and may
6118 -- violate the predicate.
6120 and then not Has_Predicates
(Component_Type
(Typ
))
6122 -- The component type must have a single initialization value
6124 and then Simple_Initialization_OK
(Component_Type
(Typ
))
6126 Set_No_Initialization
(N
, False);
6131 Size
=> Esize
(Def_Id
)));
6134 (Expression
(N
), Typ
, Suppress
=> All_Checks
);
6136 -- Otherwise invoke the type init proc, generate:
6137 -- Type_Init_Proc (Obj);
6140 Obj_Ref
:= New_Object_Reference
;
6142 if Comes_From_Source
(Def_Id
) then
6143 Initialization_Warning
(Obj_Ref
);
6146 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
6150 -- Provide a default value if the object needs simple initialization
6152 elsif Simple_Initialization_OK
(Typ
) then
6153 Set_No_Initialization
(N
, False);
6158 Size
=> Esize
(Def_Id
)));
6160 Analyze_And_Resolve
(Expression
(N
), Typ
);
6163 -- Initialize the object, generate:
6164 -- [Deep_]Initialize (Obj);
6166 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
6169 (Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
6173 -- Build a special finalization block when both the object and its
6174 -- controlled components are to be initialized. The block finalizes
6175 -- the components if the object initialization fails. Generate:
6186 if Has_Controlled_Component
(Typ
)
6187 and then Present
(Comp_Init
)
6188 and then Present
(Obj_Init
)
6189 and then Exceptions_OK
6191 Init_Stmts
:= Comp_Init
;
6195 (Obj_Ref
=> New_Object_Reference
,
6199 if Present
(Fin_Call
) then
6201 -- Do not emit warnings related to the elaboration order when a
6202 -- controlled object is declared before the body of Finalize is
6205 if Legacy_Elaboration_Checks
then
6206 Set_No_Elaboration_Check
(Fin_Call
);
6210 Make_Block_Statement
(Loc
,
6211 Declarations
=> No_List
,
6213 Handled_Statement_Sequence
=>
6214 Make_Handled_Sequence_Of_Statements
(Loc
,
6215 Statements
=> New_List
(Obj_Init
),
6217 Exception_Handlers
=> New_List
(
6218 Make_Exception_Handler
(Loc
,
6219 Exception_Choices
=> New_List
(
6220 Make_Others_Choice
(Loc
)),
6222 Statements
=> New_List
(
6224 Make_Raise_Statement
(Loc
))))));
6226 -- Signal the ABE mechanism that the block carries out
6227 -- initialization actions.
6229 Set_Is_Initialization_Block
(Fin_Block
);
6231 Append_To
(Init_Stmts
, Fin_Block
);
6234 -- Otherwise finalization is not required, the initialization calls
6235 -- are passed to the abort block building circuitry, generate:
6237 -- Type_Init_Proc (Obj);
6238 -- [Deep_]Initialize (Obj);
6241 if Present
(Comp_Init
) then
6242 Init_Stmts
:= Comp_Init
;
6245 if Present
(Obj_Init
) then
6246 if No
(Init_Stmts
) then
6247 Init_Stmts
:= New_List
;
6250 Append_To
(Init_Stmts
, Obj_Init
);
6254 -- Build an abort block to protect the initialization calls
6257 and then Present
(Comp_Init
)
6258 and then Present
(Obj_Init
)
6263 Prepend_To
(Init_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
6265 -- When exceptions are propagated, abort deferral must take place
6266 -- in the presence of initialization or finalization exceptions.
6273 -- Abort_Undefer_Direct;
6276 if Exceptions_OK
then
6277 Init_Stmts
:= New_List
(
6278 Build_Abort_Undefer_Block
(Loc
,
6279 Stmts
=> Init_Stmts
,
6282 -- Otherwise exceptions are not propagated. Generate:
6289 Append_To
(Init_Stmts
,
6290 Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
6294 -- Insert the whole initialization sequence into the tree. If the
6295 -- object has a delayed freeze, as will be the case when it has
6296 -- aspect specifications, the initialization sequence is part of
6297 -- the freeze actions.
6299 if Present
(Init_Stmts
) then
6300 if Has_Delayed_Freeze
(Def_Id
) then
6301 Append_Freeze_Actions
(Def_Id
, Init_Stmts
);
6303 Insert_Actions_After
(After
, Init_Stmts
);
6306 end Default_Initialize_Object
;
6308 -------------------------
6309 -- Rewrite_As_Renaming --
6310 -------------------------
6312 function Rewrite_As_Renaming
return Boolean is
6314 -- If the object declaration appears in the form
6316 -- Obj : Ctrl_Typ := Func (...);
6318 -- where Ctrl_Typ is controlled but not immutably limited type, then
6319 -- the expansion of the function call should use a dereference of the
6320 -- result to reference the value on the secondary stack.
6322 -- Obj : Ctrl_Typ renames Func (...).all;
6324 -- As a result, the call avoids an extra copy. This an optimization,
6325 -- but it is required for passing ACATS tests in some cases where it
6326 -- would otherwise make two copies. The RM allows removing redunant
6327 -- Adjust/Finalize calls, but does not allow insertion of extra ones.
6329 -- This part is disabled for now, because it breaks GPS builds
6331 return (False -- ???
6332 and then Nkind
(Expr_Q
) = N_Explicit_Dereference
6333 and then not Comes_From_Source
(Expr_Q
)
6334 and then Nkind
(Original_Node
(Expr_Q
)) = N_Function_Call
6335 and then Nkind
(Object_Definition
(N
)) in N_Has_Entity
6336 and then (Needs_Finalization
(Entity
(Object_Definition
(N
)))))
6338 -- If the initializing expression is for a variable with attribute
6339 -- OK_To_Rename set, then transform:
6341 -- Obj : Typ := Expr;
6345 -- Obj : Typ renames Expr;
6347 -- provided that Obj is not aliased. The aliased case has to be
6348 -- excluded in general because Expr will not be aliased in
6352 (not Aliased_Present
(N
)
6353 and then Is_Entity_Name
(Expr_Q
)
6354 and then Ekind
(Entity
(Expr_Q
)) = E_Variable
6355 and then OK_To_Rename
(Entity
(Expr_Q
))
6356 and then Is_Entity_Name
(Obj_Def
));
6357 end Rewrite_As_Renaming
;
6361 Next_N
: constant Node_Id
:= Next
(N
);
6365 Tag_Assign
: Node_Id
;
6367 Init_After
: Node_Id
:= N
;
6368 -- Node after which the initialization actions are to be inserted. This
6369 -- is normally N, except for the case of a shared passive variable, in
6370 -- which case the init proc call must be inserted only after the bodies
6371 -- of the shared variable procedures have been seen.
6373 -- Start of processing for Expand_N_Object_Declaration
6376 -- Don't do anything for deferred constants. All proper actions will be
6377 -- expanded during the full declaration.
6379 if No
(Expr
) and Constant_Present
(N
) then
6383 -- The type of the object cannot be abstract. This is diagnosed at the
6384 -- point the object is frozen, which happens after the declaration is
6385 -- fully expanded, so simply return now.
6387 if Is_Abstract_Type
(Typ
) then
6391 -- No action needed for the internal imported dummy object added by
6392 -- Make_DT to compute the offset of the components that reference
6393 -- secondary dispatch tables; required to avoid never-ending loop
6394 -- processing this internal object declaration.
6396 if Tagged_Type_Expansion
6397 and then Is_Internal
(Def_Id
)
6398 and then Is_Imported
(Def_Id
)
6399 and then Related_Type
(Def_Id
) = Implementation_Base_Type
(Typ
)
6404 -- First we do special processing for objects of a tagged type where
6405 -- this is the point at which the type is frozen. The creation of the
6406 -- dispatch table and the initialization procedure have to be deferred
6407 -- to this point, since we reference previously declared primitive
6410 -- Force construction of dispatch tables of library level tagged types
6412 if Tagged_Type_Expansion
6413 and then Building_Static_Dispatch_Tables
6414 and then Is_Library_Level_Entity
(Def_Id
)
6415 and then Is_Library_Level_Tagged_Type
(Base_Typ
)
6416 and then Ekind_In
(Base_Typ
, E_Record_Type
,
6419 and then not Has_Dispatch_Table
(Base_Typ
)
6422 New_Nodes
: List_Id
:= No_List
;
6425 if Is_Concurrent_Type
(Base_Typ
) then
6426 New_Nodes
:= Make_DT
(Corresponding_Record_Type
(Base_Typ
), N
);
6428 New_Nodes
:= Make_DT
(Base_Typ
, N
);
6431 if not Is_Empty_List
(New_Nodes
) then
6432 Insert_List_Before
(N
, New_Nodes
);
6437 -- Make shared memory routines for shared passive variable
6439 if Is_Shared_Passive
(Def_Id
) then
6440 Init_After
:= Make_Shared_Var_Procs
(N
);
6443 -- If tasks being declared, make sure we have an activation chain
6444 -- defined for the tasks (has no effect if we already have one), and
6445 -- also that a Master variable is established and that the appropriate
6446 -- enclosing construct is established as a task master.
6448 if Has_Task
(Typ
) then
6449 Build_Activation_Chain_Entity
(N
);
6450 Build_Master_Entity
(Def_Id
);
6453 -- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
6454 -- restrictions are active then default-sized secondary stacks are
6455 -- generated by the binder and allocated by SS_Init. To provide the
6456 -- binder the number of stacks to generate, the number of default-sized
6457 -- stacks required for task objects contained within the object
6458 -- declaration N is calculated here as it is at this point where
6459 -- unconstrained types become constrained. The result is stored in the
6460 -- enclosing unit's Unit_Record.
6462 -- Note if N is an array object declaration that has an initialization
6463 -- expression, a second object declaration for the initialization
6464 -- expression is created by the compiler. To prevent double counting
6465 -- of the stacks in this scenario, the stacks of the first array are
6469 and then not Restriction_Active
(No_Secondary_Stack
)
6470 and then (Restriction_Active
(No_Implicit_Heap_Allocations
)
6471 or else Restriction_Active
(No_Implicit_Task_Allocations
))
6472 and then not (Ekind_In
(Ekind
(Typ
), E_Array_Type
, E_Array_Subtype
)
6473 and then (Has_Init_Expression
(N
)))
6476 PS_Count
, SS_Count
: Int
:= 0;
6478 Count_Default_Sized_Task_Stacks
(Typ
, PS_Count
, SS_Count
);
6479 Increment_Primary_Stack_Count
(PS_Count
);
6480 Increment_Sec_Stack_Count
(SS_Count
);
6484 -- Default initialization required, and no expression present
6488 -- If we have a type with a variant part, the initialization proc
6489 -- will contain implicit tests of the discriminant values, which
6490 -- counts as a violation of the restriction No_Implicit_Conditionals.
6492 if Has_Variant_Part
(Typ
) then
6497 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
6501 ("\initialization of variant record tests discriminants",
6508 -- For the default initialization case, if we have a private type
6509 -- with invariants, and invariant checks are enabled, then insert an
6510 -- invariant check after the object declaration. Note that it is OK
6511 -- to clobber the object with an invalid value since if the exception
6512 -- is raised, then the object will go out of scope. In the case where
6513 -- an array object is initialized with an aggregate, the expression
6514 -- is removed. Check flag Has_Init_Expression to avoid generating a
6515 -- junk invariant check and flag No_Initialization to avoid checking
6516 -- an uninitialized object such as a compiler temporary used for an
6519 if Has_Invariants
(Base_Typ
)
6520 and then Present
(Invariant_Procedure
(Base_Typ
))
6521 and then not Has_Init_Expression
(N
)
6522 and then not No_Initialization
(N
)
6524 -- If entity has an address clause or aspect, make invariant
6525 -- call into a freeze action for the explicit freeze node for
6526 -- object. Otherwise insert invariant check after declaration.
6528 if Present
(Following_Address_Clause
(N
))
6529 or else Has_Aspect
(Def_Id
, Aspect_Address
)
6531 Ensure_Freeze_Node
(Def_Id
);
6532 Set_Has_Delayed_Freeze
(Def_Id
);
6533 Set_Is_Frozen
(Def_Id
, False);
6535 if not Partial_View_Has_Unknown_Discr
(Typ
) then
6536 Append_Freeze_Action
(Def_Id
,
6537 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
6540 elsif not Partial_View_Has_Unknown_Discr
(Typ
) then
6542 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
6546 Default_Initialize_Object
(Init_After
);
6548 -- Generate attribute for Persistent_BSS if needed
6550 if Persistent_BSS_Mode
6551 and then Comes_From_Source
(N
)
6552 and then Is_Potentially_Persistent_Type
(Typ
)
6553 and then not Has_Init_Expression
(N
)
6554 and then Is_Library_Level_Entity
(Def_Id
)
6560 Make_Linker_Section_Pragma
6561 (Def_Id
, Sloc
(N
), ".persistent.bss");
6562 Insert_After
(N
, Prag
);
6567 -- If access type, then we know it is null if not initialized
6569 if Is_Access_Type
(Typ
) then
6570 Set_Is_Known_Null
(Def_Id
);
6573 -- Explicit initialization present
6576 -- Obtain actual expression from qualified expression
6578 if Nkind
(Expr
) = N_Qualified_Expression
then
6579 Expr_Q
:= Expression
(Expr
);
6584 -- When we have the appropriate type of aggregate in the expression
6585 -- (it has been determined during analysis of the aggregate by
6586 -- setting the delay flag), let's perform in place assignment and
6587 -- thus avoid creating a temporary.
6589 if Is_Delayed_Aggregate
(Expr_Q
) then
6590 Convert_Aggr_In_Object_Decl
(N
);
6592 -- Ada 2005 (AI-318-02): If the initialization expression is a call
6593 -- to a build-in-place function, then access to the declared object
6594 -- must be passed to the function. Currently we limit such functions
6595 -- to those with constrained limited result subtypes, but eventually
6596 -- plan to expand the allowed forms of functions that are treated as
6599 elsif Is_Build_In_Place_Function_Call
(Expr_Q
) then
6600 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
6602 -- The previous call expands the expression initializing the
6603 -- built-in-place object into further code that will be analyzed
6604 -- later. No further expansion needed here.
6608 -- This is the same as the previous 'elsif', except that the call has
6609 -- been transformed by other expansion activities into something like
6610 -- F(...)'Reference.
6612 elsif Nkind
(Expr_Q
) = N_Reference
6613 and then Is_Build_In_Place_Function_Call
(Prefix
(Expr_Q
))
6614 and then not Is_Expanded_Build_In_Place_Call
6615 (Unqual_Conv
(Prefix
(Expr_Q
)))
6617 Make_Build_In_Place_Call_In_Anonymous_Context
(Prefix
(Expr_Q
));
6619 -- The previous call expands the expression initializing the
6620 -- built-in-place object into further code that will be analyzed
6621 -- later. No further expansion needed here.
6625 -- Ada 2005 (AI-318-02): Specialization of the previous case for
6626 -- expressions containing a build-in-place function call whose
6627 -- returned object covers interface types, and Expr_Q has calls to
6628 -- Ada.Tags.Displace to displace the pointer to the returned build-
6629 -- in-place object to reference the secondary dispatch table of a
6630 -- covered interface type.
6632 elsif Present
(Unqual_BIP_Iface_Function_Call
(Expr_Q
)) then
6633 Make_Build_In_Place_Iface_Call_In_Object_Declaration
(N
, Expr_Q
);
6635 -- The previous call expands the expression initializing the
6636 -- built-in-place object into further code that will be analyzed
6637 -- later. No further expansion needed here.
6641 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
6642 -- class-wide interface object to ensure that we copy the full
6643 -- object, unless we are targetting a VM where interfaces are handled
6644 -- by VM itself. Note that if the root type of Typ is an ancestor of
6645 -- Expr's type, both types share the same dispatch table and there is
6646 -- no need to displace the pointer.
6648 elsif Is_Interface
(Typ
)
6650 -- Avoid never-ending recursion because if Equivalent_Type is set
6651 -- then we've done it already and must not do it again.
6654 (Nkind
(Obj_Def
) = N_Identifier
6655 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
6657 pragma Assert
(Is_Class_Wide_Type
(Typ
));
6659 -- If the object is a return object of an inherently limited type,
6660 -- which implies build-in-place treatment, bypass the special
6661 -- treatment of class-wide interface initialization below. In this
6662 -- case, the expansion of the return statement will take care of
6663 -- creating the object (via allocator) and initializing it.
6665 if Is_Return_Object
(Def_Id
) and then Is_Limited_View
(Typ
) then
6668 elsif Tagged_Type_Expansion
then
6670 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
6671 Expr_N
: Node_Id
:= Expr
;
6672 Expr_Typ
: Entity_Id
;
6678 -- If the original node of the expression was a conversion
6679 -- to this specific class-wide interface type then restore
6680 -- the original node because we must copy the object before
6681 -- displacing the pointer to reference the secondary tag
6682 -- component. This code must be kept synchronized with the
6683 -- expansion done by routine Expand_Interface_Conversion
6685 if not Comes_From_Source
(Expr_N
)
6686 and then Nkind
(Expr_N
) = N_Explicit_Dereference
6687 and then Nkind
(Original_Node
(Expr_N
)) = N_Type_Conversion
6688 and then Etype
(Original_Node
(Expr_N
)) = Typ
6690 Rewrite
(Expr_N
, Original_Node
(Expression
(N
)));
6693 -- Avoid expansion of redundant interface conversion
6695 if Is_Interface
(Etype
(Expr_N
))
6696 and then Nkind
(Expr_N
) = N_Type_Conversion
6697 and then Etype
(Expr_N
) = Typ
6699 Expr_N
:= Expression
(Expr_N
);
6700 Set_Expression
(N
, Expr_N
);
6703 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_N
);
6704 Expr_Typ
:= Base_Type
(Etype
(Expr_N
));
6706 if Is_Class_Wide_Type
(Expr_Typ
) then
6707 Expr_Typ
:= Root_Type
(Expr_Typ
);
6711 -- CW : I'Class := Obj;
6714 -- type Ityp is not null access I'Class;
6715 -- CW : I'Class renames Ityp (Tmp.I_Tag'Address).all;
6717 if Comes_From_Source
(Expr_N
)
6718 and then Nkind
(Expr_N
) = N_Identifier
6719 and then not Is_Interface
(Expr_Typ
)
6720 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
6721 and then (Expr_Typ
= Etype
(Expr_Typ
)
6723 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
6728 Make_Object_Declaration
(Loc
,
6729 Defining_Identifier
=> Obj_Id
,
6730 Object_Definition
=>
6731 New_Occurrence_Of
(Expr_Typ
, Loc
),
6732 Expression
=> Relocate_Node
(Expr_N
)));
6734 -- Statically reference the tag associated with the
6738 Make_Selected_Component
(Loc
,
6739 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
6742 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
6745 -- IW : I'Class := Obj;
6747 -- type Equiv_Record is record ... end record;
6748 -- implicit subtype CW is <Class_Wide_Subtype>;
6749 -- Tmp : CW := CW!(Obj);
6750 -- type Ityp is not null access I'Class;
6751 -- IW : I'Class renames
6752 -- Ityp!(Displace (Temp'Address, I'Tag)).all;
6755 -- Generate the equivalent record type and update the
6756 -- subtype indication to reference it.
6758 Expand_Subtype_From_Expr
6761 Subtype_Indic
=> Obj_Def
,
6764 if not Is_Interface
(Etype
(Expr_N
)) then
6765 New_Expr
:= Relocate_Node
(Expr_N
);
6767 -- For interface types we use 'Address which displaces
6768 -- the pointer to the base of the object (if required)
6772 Unchecked_Convert_To
(Etype
(Obj_Def
),
6773 Make_Explicit_Dereference
(Loc
,
6774 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
6775 Make_Attribute_Reference
(Loc
,
6776 Prefix
=> Relocate_Node
(Expr_N
),
6777 Attribute_Name
=> Name_Address
))));
6782 if not Is_Limited_Record
(Expr_Typ
) then
6784 Make_Object_Declaration
(Loc
,
6785 Defining_Identifier
=> Obj_Id
,
6786 Object_Definition
=>
6787 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
6788 Expression
=> New_Expr
));
6790 -- Rename limited type object since they cannot be copied
6791 -- This case occurs when the initialization expression
6792 -- has been previously expanded into a temporary object.
6794 else pragma Assert
(not Comes_From_Source
(Expr_Q
));
6796 Make_Object_Renaming_Declaration
(Loc
,
6797 Defining_Identifier
=> Obj_Id
,
6799 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
6801 Unchecked_Convert_To
6802 (Etype
(Obj_Def
), New_Expr
)));
6805 -- Dynamically reference the tag associated with the
6809 Make_Function_Call
(Loc
,
6810 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
6811 Parameter_Associations
=> New_List
(
6812 Make_Attribute_Reference
(Loc
,
6813 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
6814 Attribute_Name
=> Name_Address
),
6816 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
6821 Make_Object_Renaming_Declaration
(Loc
,
6822 Defining_Identifier
=> Make_Temporary
(Loc
, 'D'),
6823 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
6825 Convert_Tag_To_Interface
(Typ
, Tag_Comp
)));
6827 -- If the original entity comes from source, then mark the
6828 -- new entity as needing debug information, even though it's
6829 -- defined by a generated renaming that does not come from
6830 -- source, so that Materialize_Entity will be set on the
6831 -- entity when Debug_Renaming_Declaration is called during
6834 if Comes_From_Source
(Def_Id
) then
6835 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
6838 Analyze
(N
, Suppress
=> All_Checks
);
6840 -- Replace internal identifier of rewritten node by the
6841 -- identifier found in the sources. We also have to exchange
6842 -- entities containing their defining identifiers to ensure
6843 -- the correct replacement of the object declaration by this
6844 -- object renaming declaration because these identifiers
6845 -- were previously added by Enter_Name to the current scope.
6846 -- We must preserve the homonym chain of the source entity
6847 -- as well. We must also preserve the kind of the entity,
6848 -- which may be a constant. Preserve entity chain because
6849 -- itypes may have been generated already, and the full
6850 -- chain must be preserved for final freezing. Finally,
6851 -- preserve Comes_From_Source setting, so that debugging
6852 -- and cross-referencing information is properly kept, and
6853 -- preserve source location, to prevent spurious errors when
6854 -- entities are declared (they must have their own Sloc).
6857 New_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6858 Next_Temp
: constant Entity_Id
:= Next_Entity
(New_Id
);
6859 Save_CFS
: constant Boolean :=
6860 Comes_From_Source
(Def_Id
);
6861 Save_SP
: constant Node_Id
:= SPARK_Pragma
(Def_Id
);
6862 Save_SPI
: constant Boolean :=
6863 SPARK_Pragma_Inherited
(Def_Id
);
6866 Link_Entities
(New_Id
, Next_Entity
(Def_Id
));
6867 Link_Entities
(Def_Id
, Next_Temp
);
6869 Set_Chars
(Defining_Identifier
(N
), Chars
(Def_Id
));
6870 Set_Homonym
(Defining_Identifier
(N
), Homonym
(Def_Id
));
6871 Set_Ekind
(Defining_Identifier
(N
), Ekind
(Def_Id
));
6872 Set_Sloc
(Defining_Identifier
(N
), Sloc
(Def_Id
));
6874 Set_Comes_From_Source
(Def_Id
, False);
6876 -- ??? This is extremely dangerous!!! Exchanging entities
6877 -- is very low level, and as a result it resets flags and
6878 -- fields which belong to the original Def_Id. Several of
6879 -- these attributes are saved and restored, but there may
6880 -- be many more that need to be preserverd.
6882 Exchange_Entities
(Defining_Identifier
(N
), Def_Id
);
6884 -- Restore clobbered attributes
6886 Set_Comes_From_Source
(Def_Id
, Save_CFS
);
6887 Set_SPARK_Pragma
(Def_Id
, Save_SP
);
6888 Set_SPARK_Pragma_Inherited
(Def_Id
, Save_SPI
);
6895 -- Common case of explicit object initialization
6898 -- In most cases, we must check that the initial value meets any
6899 -- constraint imposed by the declared type. However, there is one
6900 -- very important exception to this rule. If the entity has an
6901 -- unconstrained nominal subtype, then it acquired its constraints
6902 -- from the expression in the first place, and not only does this
6903 -- mean that the constraint check is not needed, but an attempt to
6904 -- perform the constraint check can cause order of elaboration
6907 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
6909 -- If this is an allocator for an aggregate that has been
6910 -- allocated in place, delay checks until assignments are
6911 -- made, because the discriminants are not initialized.
6913 if Nkind
(Expr
) = N_Allocator
6914 and then No_Initialization
(Expr
)
6918 -- Otherwise apply a constraint check now if no prev error
6920 elsif Nkind
(Expr
) /= N_Error
then
6921 Apply_Constraint_Check
(Expr
, Typ
);
6923 -- Deal with possible range check
6925 if Do_Range_Check
(Expr
) then
6927 -- If assignment checks are suppressed, turn off flag
6929 if Suppress_Assignment_Checks
(N
) then
6930 Set_Do_Range_Check
(Expr
, False);
6932 -- Otherwise generate the range check
6935 Generate_Range_Check
6936 (Expr
, Typ
, CE_Range_Check_Failed
);
6942 -- If the type is controlled and not inherently limited, then
6943 -- the target is adjusted after the copy and attached to the
6944 -- finalization list. However, no adjustment is done in the case
6945 -- where the object was initialized by a call to a function whose
6946 -- result is built in place, since no copy occurred. Similarly, no
6947 -- adjustment is required if we are going to rewrite the object
6948 -- declaration into a renaming declaration.
6950 if Needs_Finalization
(Typ
)
6951 and then not Is_Limited_View
(Typ
)
6952 and then not Rewrite_As_Renaming
6956 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
6959 -- Guard against a missing [Deep_]Adjust when the base type
6960 -- was not properly frozen.
6962 if Present
(Adj_Call
) then
6963 Insert_Action_After
(Init_After
, Adj_Call
);
6967 -- For tagged types, when an init value is given, the tag has to
6968 -- be re-initialized separately in order to avoid the propagation
6969 -- of a wrong tag coming from a view conversion unless the type
6970 -- is class wide (in this case the tag comes from the init value).
6971 -- Suppress the tag assignment when not Tagged_Type_Expansion
6972 -- because tags are represented implicitly in objects. Ditto for
6973 -- types that are CPP_CLASS, and for initializations that are
6974 -- aggregates, because they have to have the right tag.
6976 -- The re-assignment of the tag has to be done even if the object
6977 -- is a constant. The assignment must be analyzed after the
6978 -- declaration. If an address clause follows, this is handled as
6979 -- part of the freeze actions for the object, otherwise insert
6980 -- tag assignment here.
6982 Tag_Assign
:= Make_Tag_Assignment
(N
);
6984 if Present
(Tag_Assign
) then
6985 if Present
(Following_Address_Clause
(N
)) then
6986 Ensure_Freeze_Node
(Def_Id
);
6989 Insert_Action_After
(Init_After
, Tag_Assign
);
6992 -- Handle C++ constructor calls. Note that we do not check that
6993 -- Typ is a tagged type since the equivalent Ada type of a C++
6994 -- class that has no virtual methods is an untagged limited
6997 elsif Is_CPP_Constructor_Call
(Expr
) then
6999 -- The call to the initialization procedure does NOT freeze the
7000 -- object being initialized.
7002 Id_Ref
:= New_Occurrence_Of
(Def_Id
, Loc
);
7003 Set_Must_Not_Freeze
(Id_Ref
);
7004 Set_Assignment_OK
(Id_Ref
);
7006 Insert_Actions_After
(Init_After
,
7007 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
7008 Constructor_Ref
=> Expr
));
7010 -- We remove here the original call to the constructor
7011 -- to avoid its management in the backend
7013 Set_Expression
(N
, Empty
);
7016 -- Handle initialization of limited tagged types
7018 elsif Is_Tagged_Type
(Typ
)
7019 and then Is_Class_Wide_Type
(Typ
)
7020 and then Is_Limited_Record
(Typ
)
7021 and then not Is_Limited_Interface
(Typ
)
7023 -- Given that the type is limited we cannot perform a copy. If
7024 -- Expr_Q is the reference to a variable we mark the variable
7025 -- as OK_To_Rename to expand this declaration into a renaming
7026 -- declaration (see bellow).
7028 if Is_Entity_Name
(Expr_Q
) then
7029 Set_OK_To_Rename
(Entity
(Expr_Q
));
7031 -- If we cannot convert the expression into a renaming we must
7032 -- consider it an internal error because the backend does not
7033 -- have support to handle it. Also, when a raise expression is
7034 -- encountered we ignore it since it doesn't return a value and
7035 -- thus cannot trigger a copy.
7037 elsif Nkind
(Original_Node
(Expr_Q
)) /= N_Raise_Expression
then
7038 pragma Assert
(False);
7039 raise Program_Error
;
7042 -- For discrete types, set the Is_Known_Valid flag if the
7043 -- initializing value is known to be valid. Only do this for
7044 -- source assignments, since otherwise we can end up turning
7045 -- on the known valid flag prematurely from inserted code.
7047 elsif Comes_From_Source
(N
)
7048 and then Is_Discrete_Type
(Typ
)
7049 and then Expr_Known_Valid
(Expr
)
7051 Set_Is_Known_Valid
(Def_Id
);
7053 elsif Is_Access_Type
(Typ
) then
7055 -- For access types set the Is_Known_Non_Null flag if the
7056 -- initializing value is known to be non-null. We can also set
7057 -- Can_Never_Be_Null if this is a constant.
7059 if Known_Non_Null
(Expr
) then
7060 Set_Is_Known_Non_Null
(Def_Id
, True);
7062 if Constant_Present
(N
) then
7063 Set_Can_Never_Be_Null
(Def_Id
);
7068 -- If validity checking on copies, validate initial expression.
7069 -- But skip this if declaration is for a generic type, since it
7070 -- makes no sense to validate generic types. Not clear if this
7071 -- can happen for legal programs, but it definitely can arise
7072 -- from previous instantiation errors.
7074 if Validity_Checks_On
7075 and then Comes_From_Source
(N
)
7076 and then Validity_Check_Copies
7077 and then not Is_Generic_Type
(Etype
(Def_Id
))
7079 Ensure_Valid
(Expr
);
7080 Set_Is_Known_Valid
(Def_Id
);
7084 -- Cases where the back end cannot handle the initialization
7085 -- directly. In such cases, we expand an assignment that will
7086 -- be appropriately handled by Expand_N_Assignment_Statement.
7088 -- The exclusion of the unconstrained case is wrong, but for now it
7089 -- is too much trouble ???
7091 if (Is_Possibly_Unaligned_Slice
(Expr
)
7092 or else (Is_Possibly_Unaligned_Object
(Expr
)
7093 and then not Represented_As_Scalar
(Etype
(Expr
))))
7094 and then not (Is_Array_Type
(Etype
(Expr
))
7095 and then not Is_Constrained
(Etype
(Expr
)))
7098 Stat
: constant Node_Id
:=
7099 Make_Assignment_Statement
(Loc
,
7100 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
7101 Expression
=> Relocate_Node
(Expr
));
7103 Set_Expression
(N
, Empty
);
7104 Set_No_Initialization
(N
);
7105 Set_Assignment_OK
(Name
(Stat
));
7106 Set_No_Ctrl_Actions
(Stat
);
7107 Insert_After_And_Analyze
(Init_After
, Stat
);
7112 if Nkind
(Obj_Def
) = N_Access_Definition
7113 and then not Is_Local_Anonymous_Access
(Etype
(Def_Id
))
7115 -- An Ada 2012 stand-alone object of an anonymous access type
7118 Loc
: constant Source_Ptr
:= Sloc
(N
);
7120 Level
: constant Entity_Id
:=
7121 Make_Defining_Identifier
(Sloc
(N
),
7123 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
7125 Level_Expr
: Node_Id
;
7126 Level_Decl
: Node_Id
;
7129 Set_Ekind
(Level
, Ekind
(Def_Id
));
7130 Set_Etype
(Level
, Standard_Natural
);
7131 Set_Scope
(Level
, Scope
(Def_Id
));
7135 -- Set accessibility level of null
7138 Make_Integer_Literal
(Loc
, Scope_Depth
(Standard_Standard
));
7141 Level_Expr
:= Dynamic_Accessibility_Level
(Expr
);
7145 Make_Object_Declaration
(Loc
,
7146 Defining_Identifier
=> Level
,
7147 Object_Definition
=>
7148 New_Occurrence_Of
(Standard_Natural
, Loc
),
7149 Expression
=> Level_Expr
,
7150 Constant_Present
=> Constant_Present
(N
),
7151 Has_Init_Expression
=> True);
7153 Insert_Action_After
(Init_After
, Level_Decl
);
7155 Set_Extra_Accessibility
(Def_Id
, Level
);
7159 -- If the object is default initialized and its type is subject to
7160 -- pragma Default_Initial_Condition, add a runtime check to verify
7161 -- the assumption of the pragma (SPARK RM 7.3.3). Generate:
7163 -- <Base_Typ>DIC (<Base_Typ> (Def_Id));
7165 -- Note that the check is generated for source objects only
7167 if Comes_From_Source
(Def_Id
)
7168 and then Has_DIC
(Typ
)
7169 and then Present
(DIC_Procedure
(Typ
))
7170 and then not Has_Init_Expression
(N
)
7173 DIC_Call
: constant Node_Id
:= Build_DIC_Call
(Loc
, Def_Id
, Typ
);
7176 if Present
(Next_N
) then
7177 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
7179 -- The object declaration is the last node in a declarative or a
7183 Append_To
(List_Containing
(N
), DIC_Call
);
7189 -- Final transformation - turn the object declaration into a renaming
7190 -- if appropriate. If this is the completion of a deferred constant
7191 -- declaration, then this transformation generates what would be
7192 -- illegal code if written by hand, but that's OK.
7194 if Present
(Expr
) then
7195 if Rewrite_As_Renaming
then
7197 Make_Object_Renaming_Declaration
(Loc
,
7198 Defining_Identifier
=> Defining_Identifier
(N
),
7199 Subtype_Mark
=> Obj_Def
,
7202 -- We do not analyze this renaming declaration, because all its
7203 -- components have already been analyzed, and if we were to go
7204 -- ahead and analyze it, we would in effect be trying to generate
7205 -- another declaration of X, which won't do.
7207 Set_Renamed_Object
(Defining_Identifier
(N
), Expr_Q
);
7210 -- We do need to deal with debug issues for this renaming
7212 -- First, if entity comes from source, then mark it as needing
7213 -- debug information, even though it is defined by a generated
7214 -- renaming that does not come from source.
7216 if Comes_From_Source
(Defining_Identifier
(N
)) then
7217 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
7220 -- Now call the routine to generate debug info for the renaming
7223 Decl
: constant Node_Id
:= Debug_Renaming_Declaration
(N
);
7225 if Present
(Decl
) then
7226 Insert_Action
(N
, Decl
);
7232 -- Exception on library entity not available
7235 when RE_Not_Available
=>
7237 end Expand_N_Object_Declaration
;
7239 ---------------------------------
7240 -- Expand_N_Subtype_Indication --
7241 ---------------------------------
7243 -- Add a check on the range of the subtype. The static case is partially
7244 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
7245 -- to check here for the static case in order to avoid generating
7246 -- extraneous expanded code. Also deal with validity checking.
7248 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
7249 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
7250 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
7253 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
7254 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
7257 if Nkind_In
(Parent
(N
), N_Constrained_Array_Definition
, N_Slice
) then
7258 Apply_Range_Check
(Ran
, Typ
);
7260 end Expand_N_Subtype_Indication
;
7262 ---------------------------
7263 -- Expand_N_Variant_Part --
7264 ---------------------------
7266 -- Note: this procedure no longer has any effect. It used to be that we
7267 -- would replace the choices in the last variant by a when others, and
7268 -- also expanded static predicates in variant choices here, but both of
7269 -- those activities were being done too early, since we can't check the
7270 -- choices until the statically predicated subtypes are frozen, which can
7271 -- happen as late as the free point of the record, and we can't change the
7272 -- last choice to an others before checking the choices, which is now done
7273 -- at the freeze point of the record.
7275 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
7278 end Expand_N_Variant_Part
;
7280 ---------------------------------
7281 -- Expand_Previous_Access_Type --
7282 ---------------------------------
7284 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
7285 Ptr_Typ
: Entity_Id
;
7288 -- Find all access types in the current scope whose designated type is
7289 -- Def_Id and build master renamings for them.
7291 Ptr_Typ
:= First_Entity
(Current_Scope
);
7292 while Present
(Ptr_Typ
) loop
7293 if Is_Access_Type
(Ptr_Typ
)
7294 and then Designated_Type
(Ptr_Typ
) = Def_Id
7295 and then No
(Master_Id
(Ptr_Typ
))
7297 -- Ensure that the designated type has a master
7299 Build_Master_Entity
(Def_Id
);
7301 -- Private and incomplete types complicate the insertion of master
7302 -- renamings because the access type may precede the full view of
7303 -- the designated type. For this reason, the master renamings are
7304 -- inserted relative to the designated type.
7306 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
7309 Next_Entity
(Ptr_Typ
);
7311 end Expand_Previous_Access_Type
;
7313 -----------------------------
7314 -- Expand_Record_Extension --
7315 -----------------------------
7317 -- Add a field _parent at the beginning of the record extension. This is
7318 -- used to implement inheritance. Here are some examples of expansion:
7320 -- 1. no discriminants
7321 -- type T2 is new T1 with null record;
7323 -- type T2 is new T1 with record
7327 -- 2. renamed discriminants
7328 -- type T2 (B, C : Int) is new T1 (A => B) with record
7329 -- _Parent : T1 (A => B);
7333 -- 3. inherited discriminants
7334 -- type T2 is new T1 with record -- discriminant A inherited
7335 -- _Parent : T1 (A);
7339 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
) is
7340 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7341 Loc
: constant Source_Ptr
:= Sloc
(Def
);
7342 Rec_Ext_Part
: Node_Id
:= Record_Extension_Part
(Def
);
7343 Par_Subtype
: Entity_Id
;
7344 Comp_List
: Node_Id
;
7345 Comp_Decl
: Node_Id
;
7348 List_Constr
: constant List_Id
:= New_List
;
7351 -- Expand_Record_Extension is called directly from the semantics, so
7352 -- we must check to see whether expansion is active before proceeding,
7353 -- because this affects the visibility of selected components in bodies
7356 if not Expander_Active
then
7360 -- This may be a derivation of an untagged private type whose full
7361 -- view is tagged, in which case the Derived_Type_Definition has no
7362 -- extension part. Build an empty one now.
7364 if No
(Rec_Ext_Part
) then
7366 Make_Record_Definition
(Loc
,
7368 Component_List
=> Empty
,
7369 Null_Present
=> True);
7371 Set_Record_Extension_Part
(Def
, Rec_Ext_Part
);
7372 Mark_Rewrite_Insertion
(Rec_Ext_Part
);
7375 Comp_List
:= Component_List
(Rec_Ext_Part
);
7377 Parent_N
:= Make_Defining_Identifier
(Loc
, Name_uParent
);
7379 -- If the derived type inherits its discriminants the type of the
7380 -- _parent field must be constrained by the inherited discriminants
7382 if Has_Discriminants
(T
)
7383 and then Nkind
(Indic
) /= N_Subtype_Indication
7384 and then not Is_Constrained
(Entity
(Indic
))
7386 D
:= First_Discriminant
(T
);
7387 while Present
(D
) loop
7388 Append_To
(List_Constr
, New_Occurrence_Of
(D
, Loc
));
7389 Next_Discriminant
(D
);
7394 Make_Subtype_Indication
(Loc
,
7395 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Indic
), Loc
),
7397 Make_Index_Or_Discriminant_Constraint
(Loc
,
7398 Constraints
=> List_Constr
)),
7401 -- Otherwise the original subtype_indication is just what is needed
7404 Par_Subtype
:= Process_Subtype
(New_Copy_Tree
(Indic
), Def
);
7407 Set_Parent_Subtype
(T
, Par_Subtype
);
7410 Make_Component_Declaration
(Loc
,
7411 Defining_Identifier
=> Parent_N
,
7412 Component_Definition
=>
7413 Make_Component_Definition
(Loc
,
7414 Aliased_Present
=> False,
7415 Subtype_Indication
=> New_Occurrence_Of
(Par_Subtype
, Loc
)));
7417 if Null_Present
(Rec_Ext_Part
) then
7418 Set_Component_List
(Rec_Ext_Part
,
7419 Make_Component_List
(Loc
,
7420 Component_Items
=> New_List
(Comp_Decl
),
7421 Variant_Part
=> Empty
,
7422 Null_Present
=> False));
7423 Set_Null_Present
(Rec_Ext_Part
, False);
7425 elsif Null_Present
(Comp_List
)
7426 or else Is_Empty_List
(Component_Items
(Comp_List
))
7428 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
7429 Set_Null_Present
(Comp_List
, False);
7432 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
7435 Analyze
(Comp_Decl
);
7436 end Expand_Record_Extension
;
7438 ------------------------
7439 -- Expand_Tagged_Root --
7440 ------------------------
7442 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
7443 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
7444 Comp_List
: Node_Id
;
7445 Comp_Decl
: Node_Id
;
7446 Sloc_N
: Source_Ptr
;
7449 if Null_Present
(Def
) then
7450 Set_Component_List
(Def
,
7451 Make_Component_List
(Sloc
(Def
),
7452 Component_Items
=> Empty_List
,
7453 Variant_Part
=> Empty
,
7454 Null_Present
=> True));
7457 Comp_List
:= Component_List
(Def
);
7459 if Null_Present
(Comp_List
)
7460 or else Is_Empty_List
(Component_Items
(Comp_List
))
7462 Sloc_N
:= Sloc
(Comp_List
);
7464 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
7468 Make_Component_Declaration
(Sloc_N
,
7469 Defining_Identifier
=> First_Tag_Component
(T
),
7470 Component_Definition
=>
7471 Make_Component_Definition
(Sloc_N
,
7472 Aliased_Present
=> False,
7473 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
7475 if Null_Present
(Comp_List
)
7476 or else Is_Empty_List
(Component_Items
(Comp_List
))
7478 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
7479 Set_Null_Present
(Comp_List
, False);
7482 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
7485 -- We don't Analyze the whole expansion because the tag component has
7486 -- already been analyzed previously. Here we just insure that the tree
7487 -- is coherent with the semantic decoration
7489 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
7492 when RE_Not_Available
=>
7494 end Expand_Tagged_Root
;
7496 ------------------------------
7497 -- Freeze_Stream_Operations --
7498 ------------------------------
7500 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
7501 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
7506 Stream_Op
: Entity_Id
;
7509 -- Primitive operations of tagged types are frozen when the dispatch
7510 -- table is constructed.
7512 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
7516 for J
in Names
'Range loop
7517 Stream_Op
:= TSS
(Typ
, Names
(J
));
7519 if Present
(Stream_Op
)
7520 and then Is_Subprogram
(Stream_Op
)
7521 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
7522 N_Subprogram_Declaration
7523 and then not Is_Frozen
(Stream_Op
)
7525 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
7528 end Freeze_Stream_Operations
;
7534 -- Full type declarations are expanded at the point at which the type is
7535 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
7536 -- declarations generated by the freezing (e.g. the procedure generated
7537 -- for initialization) are chained in the Actions field list of the freeze
7538 -- node using Append_Freeze_Actions.
7540 -- WARNING: This routine manages Ghost regions. Return statements must be
7541 -- replaced by gotos which jump to the end of the routine and restore the
7544 function Freeze_Type
(N
: Node_Id
) return Boolean is
7545 procedure Process_RACW_Types
(Typ
: Entity_Id
);
7546 -- Validate and generate stubs for all RACW types associated with type
7549 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
);
7550 -- Associate type Typ's Finalize_Address primitive with the finalization
7551 -- masters of pending access-to-Typ types.
7553 ------------------------
7554 -- Process_RACW_Types --
7555 ------------------------
7557 procedure Process_RACW_Types
(Typ
: Entity_Id
) is
7558 List
: constant Elist_Id
:= Access_Types_To_Process
(N
);
7560 Seen
: Boolean := False;
7563 if Present
(List
) then
7564 E
:= First_Elmt
(List
);
7565 while Present
(E
) loop
7566 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
7567 Validate_RACW_Primitives
(Node
(E
));
7575 -- If there are RACWs designating this type, make stubs now
7578 Remote_Types_Tagged_Full_View_Encountered
(Typ
);
7580 end Process_RACW_Types
;
7582 ----------------------------------
7583 -- Process_Pending_Access_Types --
7584 ----------------------------------
7586 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
) is
7590 -- Finalize_Address is not generated in CodePeer mode because the
7591 -- body contains address arithmetic. This processing is disabled.
7593 if CodePeer_Mode
then
7596 -- Certain itypes are generated for contexts that cannot allocate
7597 -- objects and should not set primitive Finalize_Address.
7599 elsif Is_Itype
(Typ
)
7600 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
7601 N_Explicit_Dereference
7605 -- When an access type is declared after the incomplete view of a
7606 -- Taft-amendment type, the access type is considered pending in
7607 -- case the full view of the Taft-amendment type is controlled. If
7608 -- this is indeed the case, associate the Finalize_Address routine
7609 -- of the full view with the finalization masters of all pending
7610 -- access types. This scenario applies to anonymous access types as
7613 elsif Needs_Finalization
(Typ
)
7614 and then Present
(Pending_Access_Types
(Typ
))
7616 E
:= First_Elmt
(Pending_Access_Types
(Typ
));
7617 while Present
(E
) loop
7620 -- Set_Finalize_Address
7621 -- (Ptr_Typ, <Typ>FD'Unrestricted_Access);
7623 Append_Freeze_Action
(Typ
,
7624 Make_Set_Finalize_Address_Call
7626 Ptr_Typ
=> Node
(E
)));
7631 end Process_Pending_Access_Types
;
7635 Def_Id
: constant Entity_Id
:= Entity
(N
);
7637 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
7638 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
7639 -- Save the Ghost-related attributes to restore on exit
7641 Result
: Boolean := False;
7643 -- Start of processing for Freeze_Type
7646 -- The type being frozen may be subject to pragma Ghost. Set the mode
7647 -- now to ensure that any nodes generated during freezing are properly
7650 Set_Ghost_Mode
(Def_Id
);
7652 -- Process any remote access-to-class-wide types designating the type
7655 Process_RACW_Types
(Def_Id
);
7657 -- Freeze processing for record types
7659 if Is_Record_Type
(Def_Id
) then
7660 if Ekind
(Def_Id
) = E_Record_Type
then
7661 Expand_Freeze_Record_Type
(N
);
7662 elsif Is_Class_Wide_Type
(Def_Id
) then
7663 Expand_Freeze_Class_Wide_Type
(N
);
7666 -- Freeze processing for array types
7668 elsif Is_Array_Type
(Def_Id
) then
7669 Expand_Freeze_Array_Type
(N
);
7671 -- Freeze processing for access types
7673 -- For pool-specific access types, find out the pool object used for
7674 -- this type, needs actual expansion of it in some cases. Here are the
7675 -- different cases :
7677 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
7678 -- ---> don't use any storage pool
7680 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
7682 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
7684 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7685 -- ---> Storage Pool is the specified one
7687 -- See GNAT Pool packages in the Run-Time for more details
7689 elsif Ekind_In
(Def_Id
, E_Access_Type
, E_General_Access_Type
) then
7691 Loc
: constant Source_Ptr
:= Sloc
(N
);
7692 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
7694 Freeze_Action_Typ
: Entity_Id
;
7695 Pool_Object
: Entity_Id
;
7700 -- Rep Clause "for Def_Id'Storage_Size use 0;"
7701 -- ---> don't use any storage pool
7703 if No_Pool_Assigned
(Def_Id
) then
7708 -- Rep Clause : for Def_Id'Storage_Size use Expr.
7710 -- Def_Id__Pool : Stack_Bounded_Pool
7711 -- (Expr, DT'Size, DT'Alignment);
7713 elsif Has_Storage_Size_Clause
(Def_Id
) then
7719 -- For unconstrained composite types we give a size of zero
7720 -- so that the pool knows that it needs a special algorithm
7721 -- for variable size object allocation.
7723 if Is_Composite_Type
(Desig_Type
)
7724 and then not Is_Constrained
(Desig_Type
)
7726 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
7727 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
7731 Make_Attribute_Reference
(Loc
,
7732 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7733 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
7736 Make_Attribute_Reference
(Loc
,
7737 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7738 Attribute_Name
=> Name_Alignment
);
7742 Make_Defining_Identifier
(Loc
,
7743 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
7745 -- We put the code associated with the pools in the entity
7746 -- that has the later freeze node, usually the access type
7747 -- but it can also be the designated_type; because the pool
7748 -- code requires both those types to be frozen
7750 if Is_Frozen
(Desig_Type
)
7751 and then (No
(Freeze_Node
(Desig_Type
))
7752 or else Analyzed
(Freeze_Node
(Desig_Type
)))
7754 Freeze_Action_Typ
:= Def_Id
;
7756 -- A Taft amendment type cannot get the freeze actions
7757 -- since the full view is not there.
7759 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
7760 and then No
(Full_View
(Desig_Type
))
7762 Freeze_Action_Typ
:= Def_Id
;
7765 Freeze_Action_Typ
:= Desig_Type
;
7768 Append_Freeze_Action
(Freeze_Action_Typ
,
7769 Make_Object_Declaration
(Loc
,
7770 Defining_Identifier
=> Pool_Object
,
7771 Object_Definition
=>
7772 Make_Subtype_Indication
(Loc
,
7775 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
7778 Make_Index_Or_Discriminant_Constraint
(Loc
,
7779 Constraints
=> New_List
(
7781 -- First discriminant is the Pool Size
7784 Storage_Size_Variable
(Def_Id
), Loc
),
7786 -- Second discriminant is the element size
7790 -- Third discriminant is the alignment
7795 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
7799 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7800 -- ---> Storage Pool is the specified one
7802 -- When compiling in Ada 2012 mode, ensure that the accessibility
7803 -- level of the subpool access type is not deeper than that of the
7804 -- pool_with_subpools.
7806 elsif Ada_Version
>= Ada_2012
7807 and then Present
(Associated_Storage_Pool
(Def_Id
))
7809 -- Omit this check for the case of a configurable run-time that
7810 -- does not provide package System.Storage_Pools.Subpools.
7812 and then RTE_Available
(RE_Root_Storage_Pool_With_Subpools
)
7815 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7816 Pool
: constant Entity_Id
:=
7817 Associated_Storage_Pool
(Def_Id
);
7818 RSPWS
: constant Entity_Id
:=
7819 RTE
(RE_Root_Storage_Pool_With_Subpools
);
7822 -- It is known that the accessibility level of the access
7823 -- type is deeper than that of the pool.
7825 if Type_Access_Level
(Def_Id
) > Object_Access_Level
(Pool
)
7826 and then not Accessibility_Checks_Suppressed
(Def_Id
)
7827 and then not Accessibility_Checks_Suppressed
(Pool
)
7829 -- Static case: the pool is known to be a descendant of
7830 -- Root_Storage_Pool_With_Subpools.
7832 if Is_Ancestor
(RSPWS
, Etype
(Pool
)) then
7834 ("??subpool access type has deeper accessibility "
7835 & "level than pool", Def_Id
);
7837 Append_Freeze_Action
(Def_Id
,
7838 Make_Raise_Program_Error
(Loc
,
7839 Reason
=> PE_Accessibility_Check_Failed
));
7841 -- Dynamic case: when the pool is of a class-wide type,
7842 -- it may or may not support subpools depending on the
7843 -- path of derivation. Generate:
7845 -- if Def_Id in RSPWS'Class then
7846 -- raise Program_Error;
7849 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
7850 Append_Freeze_Action
(Def_Id
,
7851 Make_If_Statement
(Loc
,
7854 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
7857 (Class_Wide_Type
(RSPWS
), Loc
)),
7859 Then_Statements
=> New_List
(
7860 Make_Raise_Program_Error
(Loc
,
7861 Reason
=> PE_Accessibility_Check_Failed
))));
7867 -- For access-to-controlled types (including class-wide types and
7868 -- Taft-amendment types, which potentially have controlled
7869 -- components), expand the list controller object that will store
7870 -- the dynamically allocated objects. Don't do this transformation
7871 -- for expander-generated access types, but do it for types that
7872 -- are the full view of types derived from other private types.
7873 -- Also suppress the list controller in the case of a designated
7874 -- type with convention Java, since this is used when binding to
7875 -- Java API specs, where there's no equivalent of a finalization
7876 -- list and we don't want to pull in the finalization support if
7879 if not Comes_From_Source
(Def_Id
)
7880 and then not Has_Private_Declaration
(Def_Id
)
7884 -- An exception is made for types defined in the run-time because
7885 -- Ada.Tags.Tag itself is such a type and cannot afford this
7886 -- unnecessary overhead that would generates a loop in the
7887 -- expansion scheme. Another exception is if Restrictions
7888 -- (No_Finalization) is active, since then we know nothing is
7891 elsif Restriction_Active
(No_Finalization
)
7892 or else In_Runtime
(Def_Id
)
7896 -- Create a finalization master for an access-to-controlled type
7897 -- or an access-to-incomplete type. It is assumed that the full
7898 -- view will be controlled.
7900 elsif Needs_Finalization
(Desig_Type
)
7901 or else (Is_Incomplete_Type
(Desig_Type
)
7902 and then No
(Full_View
(Desig_Type
)))
7904 Build_Finalization_Master
(Def_Id
);
7906 -- Create a finalization master when the designated type contains
7907 -- a private component. It is assumed that the full view will be
7910 elsif Has_Private_Component
(Desig_Type
) then
7911 Build_Finalization_Master
7913 For_Private
=> True,
7914 Context_Scope
=> Scope
(Def_Id
),
7915 Insertion_Node
=> Declaration_Node
(Desig_Type
));
7919 -- Freeze processing for enumeration types
7921 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
7923 -- We only have something to do if we have a non-standard
7924 -- representation (i.e. at least one literal whose pos value
7925 -- is not the same as its representation)
7927 if Has_Non_Standard_Rep
(Def_Id
) then
7928 Expand_Freeze_Enumeration_Type
(N
);
7931 -- Private types that are completed by a derivation from a private
7932 -- type have an internally generated full view, that needs to be
7933 -- frozen. This must be done explicitly because the two views share
7934 -- the freeze node, and the underlying full view is not visible when
7935 -- the freeze node is analyzed.
7937 elsif Is_Private_Type
(Def_Id
)
7938 and then Is_Derived_Type
(Def_Id
)
7939 and then Present
(Full_View
(Def_Id
))
7940 and then Is_Itype
(Full_View
(Def_Id
))
7941 and then Has_Private_Declaration
(Full_View
(Def_Id
))
7942 and then Freeze_Node
(Full_View
(Def_Id
)) = N
7944 Set_Entity
(N
, Full_View
(Def_Id
));
7945 Result
:= Freeze_Type
(N
);
7946 Set_Entity
(N
, Def_Id
);
7948 -- All other types require no expander action. There are such cases
7949 -- (e.g. task types and protected types). In such cases, the freeze
7950 -- nodes are there for use by Gigi.
7954 -- Complete the initialization of all pending access types' finalization
7955 -- masters now that the designated type has been is frozen and primitive
7956 -- Finalize_Address generated.
7958 Process_Pending_Access_Types
(Def_Id
);
7959 Freeze_Stream_Operations
(N
, Def_Id
);
7961 -- Generate the [spec and] body of the procedure tasked with the runtime
7962 -- verification of pragma Default_Initial_Condition's expression.
7964 if Has_DIC
(Def_Id
) then
7965 Build_DIC_Procedure_Body
(Def_Id
, For_Freeze
=> True);
7968 -- Generate the [spec and] body of the invariant procedure tasked with
7969 -- the runtime verification of all invariants that pertain to the type.
7970 -- This includes invariants on the partial and full view, inherited
7971 -- class-wide invariants from parent types or interfaces, and invariants
7972 -- on array elements or record components.
7974 if Is_Interface
(Def_Id
) then
7976 -- Interfaces are treated as the partial view of a private type in
7977 -- order to achieve uniformity with the general case. As a result, an
7978 -- interface receives only a "partial" invariant procedure which is
7981 if Has_Own_Invariants
(Def_Id
) then
7982 Build_Invariant_Procedure_Body
7984 Partial_Invariant
=> Is_Interface
(Def_Id
));
7987 -- Non-interface types
7989 -- Do not generate invariant procedure within other assertion
7990 -- subprograms, which may involve local declarations of local
7991 -- subtypes to which these checks do not apply.
7993 elsif Has_Invariants
(Def_Id
) then
7994 if Within_Internal_Subprogram
7995 or else (Ekind
(Current_Scope
) = E_Function
7996 and then Is_Predicate_Function
(Current_Scope
))
8000 Build_Invariant_Procedure_Body
(Def_Id
);
8004 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
8009 when RE_Not_Available
=>
8010 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
8015 -------------------------
8016 -- Get_Simple_Init_Val --
8017 -------------------------
8019 function Get_Simple_Init_Val
8022 Size
: Uint
:= No_Uint
) return Node_Id
8024 IV_Attribute
: constant Boolean :=
8025 Nkind
(N
) = N_Attribute_Reference
8026 and then Attribute_Name
(N
) = Name_Invalid_Value
;
8028 Loc
: constant Source_Ptr
:= Sloc
(N
);
8030 procedure Extract_Subtype_Bounds
8031 (Lo_Bound
: out Uint
;
8032 Hi_Bound
: out Uint
);
8033 -- Inspect subtype Typ as well its ancestor subtypes and derived types
8034 -- to determine the best known information about the bounds of the type.
8035 -- The output parameters are set as follows:
8037 -- * Lo_Bound - Set to No_Unit when there is no information available,
8038 -- or to the known low bound.
8040 -- * Hi_Bound - Set to No_Unit when there is no information available,
8041 -- or to the known high bound.
8043 function Simple_Init_Array_Type
return Node_Id
;
8044 -- Build an expression to initialize array type Typ
8046 function Simple_Init_Defaulted_Type
return Node_Id
;
8047 -- Build an expression to initialize type Typ which is subject to
8048 -- aspect Default_Value.
8050 function Simple_Init_Initialize_Scalars_Type
8051 (Size_To_Use
: Uint
) return Node_Id
;
8052 -- Build an expression to initialize scalar type Typ which is subject to
8053 -- pragma Initialize_Scalars. Size_To_Use is the size of the object.
8055 function Simple_Init_Normalize_Scalars_Type
8056 (Size_To_Use
: Uint
) return Node_Id
;
8057 -- Build an expression to initialize scalar type Typ which is subject to
8058 -- pragma Normalize_Scalars. Size_To_Use is the size of the object.
8060 function Simple_Init_Private_Type
return Node_Id
;
8061 -- Build an expression to initialize private type Typ
8063 function Simple_Init_Scalar_Type
return Node_Id
;
8064 -- Build an expression to initialize scalar type Typ
8066 ----------------------------
8067 -- Extract_Subtype_Bounds --
8068 ----------------------------
8070 procedure Extract_Subtype_Bounds
8071 (Lo_Bound
: out Uint
;
8072 Hi_Bound
: out Uint
)
8082 Lo_Bound
:= No_Uint
;
8083 Hi_Bound
:= No_Uint
;
8085 -- Loop to climb ancestor subtypes and derived types
8089 if not Is_Discrete_Type
(ST1
) then
8093 Lo
:= Type_Low_Bound
(ST1
);
8094 Hi
:= Type_High_Bound
(ST1
);
8096 if Compile_Time_Known_Value
(Lo
) then
8097 Lo_Val
:= Expr_Value
(Lo
);
8099 if Lo_Bound
= No_Uint
or else Lo_Bound
< Lo_Val
then
8104 if Compile_Time_Known_Value
(Hi
) then
8105 Hi_Val
:= Expr_Value
(Hi
);
8107 if Hi_Bound
= No_Uint
or else Hi_Bound
> Hi_Val
then
8112 ST2
:= Ancestor_Subtype
(ST1
);
8118 exit when ST1
= ST2
;
8121 end Extract_Subtype_Bounds
;
8123 ----------------------------
8124 -- Simple_Init_Array_Type --
8125 ----------------------------
8127 function Simple_Init_Array_Type
return Node_Id
is
8128 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
8130 function Simple_Init_Dimension
(Index
: Node_Id
) return Node_Id
;
8131 -- Initialize a single array dimension with index constraint Index
8133 --------------------
8134 -- Simple_Init_Dimension --
8135 --------------------
8137 function Simple_Init_Dimension
(Index
: Node_Id
) return Node_Id
is
8139 -- Process the current dimension
8141 if Present
(Index
) then
8143 -- Build a suitable "others" aggregate for the next dimension,
8144 -- or initialize the component itself. Generate:
8149 Make_Aggregate
(Loc
,
8150 Component_Associations
=> New_List
(
8151 Make_Component_Association
(Loc
,
8152 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
8154 Simple_Init_Dimension
(Next_Index
(Index
)))));
8156 -- Otherwise all dimensions have been processed. Initialize the
8157 -- component itself.
8164 Size
=> Esize
(Comp_Typ
));
8166 end Simple_Init_Dimension
;
8168 -- Start of processing for Simple_Init_Array_Type
8171 return Simple_Init_Dimension
(First_Index
(Typ
));
8172 end Simple_Init_Array_Type
;
8174 --------------------------------
8175 -- Simple_Init_Defaulted_Type --
8176 --------------------------------
8178 function Simple_Init_Defaulted_Type
return Node_Id
is
8179 Subtyp
: constant Entity_Id
:= First_Subtype
(Typ
);
8182 -- Use the Sloc of the context node when constructing the initial
8183 -- value because the expression of Default_Value may come from a
8184 -- different unit. Updating the Sloc will result in accurate error
8187 -- When the first subtype is private, retrieve the expression of the
8188 -- Default_Value from the underlying type.
8190 if Is_Private_Type
(Subtyp
) then
8192 Unchecked_Convert_To
8196 (Source
=> Default_Aspect_Value
(Full_View
(Subtyp
)),
8205 (Source
=> Default_Aspect_Value
(Subtyp
),
8208 end Simple_Init_Defaulted_Type
;
8210 -----------------------------------------
8211 -- Simple_Init_Initialize_Scalars_Type --
8212 -----------------------------------------
8214 function Simple_Init_Initialize_Scalars_Type
8215 (Size_To_Use
: Uint
) return Node_Id
8217 Float_Typ
: Entity_Id
;
8220 Scal_Typ
: Scalar_Id
;
8223 Extract_Subtype_Bounds
(Lo_Bound
, Hi_Bound
);
8227 if Is_Floating_Point_Type
(Typ
) then
8228 Float_Typ
:= Root_Type
(Typ
);
8230 if Float_Typ
= Standard_Short_Float
then
8231 Scal_Typ
:= Name_Short_Float
;
8232 elsif Float_Typ
= Standard_Float
then
8233 Scal_Typ
:= Name_Float
;
8234 elsif Float_Typ
= Standard_Long_Float
then
8235 Scal_Typ
:= Name_Long_Float
;
8236 else pragma Assert
(Float_Typ
= Standard_Long_Long_Float
);
8237 Scal_Typ
:= Name_Long_Long_Float
;
8240 -- If zero is invalid, it is a convenient value to use that is for
8241 -- sure an appropriate invalid value in all situations.
8243 elsif Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8244 return Make_Integer_Literal
(Loc
, 0);
8248 elsif Is_Unsigned_Type
(Typ
) then
8249 if Size_To_Use
<= 8 then
8250 Scal_Typ
:= Name_Unsigned_8
;
8251 elsif Size_To_Use
<= 16 then
8252 Scal_Typ
:= Name_Unsigned_16
;
8253 elsif Size_To_Use
<= 32 then
8254 Scal_Typ
:= Name_Unsigned_32
;
8256 Scal_Typ
:= Name_Unsigned_64
;
8262 if Size_To_Use
<= 8 then
8263 Scal_Typ
:= Name_Signed_8
;
8264 elsif Size_To_Use
<= 16 then
8265 Scal_Typ
:= Name_Signed_16
;
8266 elsif Size_To_Use
<= 32 then
8267 Scal_Typ
:= Name_Signed_32
;
8269 Scal_Typ
:= Name_Signed_64
;
8273 -- Use the values specified by pragma Initialize_Scalars or the ones
8274 -- provided by the binder. Higher precedence is given to the pragma.
8276 return Invalid_Scalar_Value
(Loc
, Scal_Typ
);
8277 end Simple_Init_Initialize_Scalars_Type
;
8279 ----------------------------------------
8280 -- Simple_Init_Normalize_Scalars_Type --
8281 ----------------------------------------
8283 function Simple_Init_Normalize_Scalars_Type
8284 (Size_To_Use
: Uint
) return Node_Id
8286 Signed_Size
: constant Uint
:= UI_Min
(Uint_63
, Size_To_Use
- 1);
8293 Extract_Subtype_Bounds
(Lo_Bound
, Hi_Bound
);
8295 -- If zero is invalid, it is a convenient value to use that is for
8296 -- sure an appropriate invalid value in all situations.
8298 if Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8299 Expr
:= Make_Integer_Literal
(Loc
, 0);
8301 -- Cases where all one bits is the appropriate invalid value
8303 -- For modular types, all 1 bits is either invalid or valid. If it
8304 -- is valid, then there is nothing that can be done since there are
8305 -- no invalid values (we ruled out zero already).
8307 -- For signed integer types that have no negative values, either
8308 -- there is room for negative values, or there is not. If there
8309 -- is, then all 1-bits may be interpreted as minus one, which is
8310 -- certainly invalid. Alternatively it is treated as the largest
8311 -- positive value, in which case the observation for modular types
8314 -- For float types, all 1-bits is a NaN (not a number), which is
8315 -- certainly an appropriately invalid value.
8317 elsif Is_Enumeration_Type
(Typ
)
8318 or else Is_Floating_Point_Type
(Typ
)
8319 or else Is_Unsigned_Type
(Typ
)
8321 Expr
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
8323 -- Resolve as Unsigned_64, because the largest number we can
8324 -- generate is out of range of universal integer.
8326 Analyze_And_Resolve
(Expr
, RTE
(RE_Unsigned_64
));
8328 -- Case of signed types
8331 -- Normally we like to use the most negative number. The one
8332 -- exception is when this number is in the known subtype range and
8333 -- the largest positive number is not in the known subtype range.
8335 -- For this exceptional case, use largest positive value
8337 if Lo_Bound
/= No_Uint
and then Hi_Bound
/= No_Uint
8338 and then Lo_Bound
<= (-(2 ** Signed_Size
))
8339 and then Hi_Bound
< 2 ** Signed_Size
8341 Expr
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
8343 -- Normal case of largest negative value
8346 Expr
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
8351 end Simple_Init_Normalize_Scalars_Type
;
8353 ------------------------------
8354 -- Simple_Init_Private_Type --
8355 ------------------------------
8357 function Simple_Init_Private_Type
return Node_Id
is
8358 Under_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
8362 -- The availability of the underlying view must be checked by routine
8363 -- Needs_Simple_Initialization.
8365 pragma Assert
(Present
(Under_Typ
));
8367 Expr
:= Get_Simple_Init_Val
(Under_Typ
, N
, Size
);
8369 -- If the initial value is null or an aggregate, qualify it with the
8370 -- underlying type in order to provide a proper context.
8372 if Nkind_In
(Expr
, N_Aggregate
, N_Null
) then
8374 Make_Qualified_Expression
(Loc
,
8375 Subtype_Mark
=> New_Occurrence_Of
(Under_Typ
, Loc
),
8376 Expression
=> Expr
);
8379 Expr
:= Unchecked_Convert_To
(Typ
, Expr
);
8381 -- Do not truncate the result when scalar types are involved and
8382 -- Initialize/Normalize_Scalars is in effect.
8384 if Nkind
(Expr
) = N_Unchecked_Type_Conversion
8385 and then Is_Scalar_Type
(Under_Typ
)
8387 Set_No_Truncation
(Expr
);
8391 end Simple_Init_Private_Type
;
8393 -----------------------------
8394 -- Simple_Init_Scalar_Type --
8395 -----------------------------
8397 function Simple_Init_Scalar_Type
return Node_Id
is
8402 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
8404 -- Determine the size of the object. This is either the size provided
8405 -- by the caller, or the Esize of the scalar type.
8407 if Size
= No_Uint
or else Size
<= Uint_0
then
8408 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(Typ
));
8410 Size_To_Use
:= Size
;
8413 -- The maximum size to use is 64 bits. This will create values of
8414 -- type Unsigned_64 and the range must fit this type.
8416 if Size_To_Use
/= No_Uint
and then Size_To_Use
> Uint_64
then
8417 Size_To_Use
:= Uint_64
;
8420 if Normalize_Scalars
and then not IV_Attribute
then
8421 Expr
:= Simple_Init_Normalize_Scalars_Type
(Size_To_Use
);
8423 Expr
:= Simple_Init_Initialize_Scalars_Type
(Size_To_Use
);
8426 -- The final expression is obtained by doing an unchecked conversion
8427 -- of this result to the base type of the required subtype. Use the
8428 -- base type to prevent the unchecked conversion from chopping bits,
8429 -- and then we set Kill_Range_Check to preserve the "bad" value.
8431 Expr
:= Unchecked_Convert_To
(Base_Type
(Typ
), Expr
);
8433 -- Ensure that the expression is not truncated since the "bad" bits
8434 -- are desired, and also kill the range checks.
8436 if Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
8437 Set_Kill_Range_Check
(Expr
);
8438 Set_No_Truncation
(Expr
);
8442 end Simple_Init_Scalar_Type
;
8444 -- Start of processing for Get_Simple_Init_Val
8447 if Is_Private_Type
(Typ
) then
8448 return Simple_Init_Private_Type
;
8450 elsif Is_Scalar_Type
(Typ
) then
8451 if Has_Default_Aspect
(Typ
) then
8452 return Simple_Init_Defaulted_Type
;
8454 return Simple_Init_Scalar_Type
;
8457 -- Array type with Initialize or Normalize_Scalars
8459 elsif Is_Array_Type
(Typ
) then
8460 pragma Assert
(Init_Or_Norm_Scalars
);
8461 return Simple_Init_Array_Type
;
8463 -- Access type is initialized to null
8465 elsif Is_Access_Type
(Typ
) then
8466 return Make_Null
(Loc
);
8468 -- No other possibilities should arise, since we should only be calling
8469 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8470 -- indicating one of the above cases held.
8473 raise Program_Error
;
8477 when RE_Not_Available
=>
8479 end Get_Simple_Init_Val
;
8481 ------------------------------
8482 -- Has_New_Non_Standard_Rep --
8483 ------------------------------
8485 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
8487 if not Is_Derived_Type
(T
) then
8488 return Has_Non_Standard_Rep
(T
)
8489 or else Has_Non_Standard_Rep
(Root_Type
(T
));
8491 -- If Has_Non_Standard_Rep is not set on the derived type, the
8492 -- representation is fully inherited.
8494 elsif not Has_Non_Standard_Rep
(T
) then
8498 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
8500 -- May need a more precise check here: the First_Rep_Item may be a
8501 -- stream attribute, which does not affect the representation of the
8505 end Has_New_Non_Standard_Rep
;
8507 ----------------------
8508 -- Inline_Init_Proc --
8509 ----------------------
8511 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean is
8513 -- The initialization proc of protected records is not worth inlining.
8514 -- In addition, when compiled for another unit for inlining purposes,
8515 -- it may make reference to entities that have not been elaborated yet.
8516 -- The initialization proc of records that need finalization contains
8517 -- a nested clean-up procedure that makes it impractical to inline as
8518 -- well, except for simple controlled types themselves. And similar
8519 -- considerations apply to task types.
8521 if Is_Concurrent_Type
(Typ
) then
8524 elsif Needs_Finalization
(Typ
) and then not Is_Controlled
(Typ
) then
8527 elsif Has_Task
(Typ
) then
8533 end Inline_Init_Proc
;
8539 function In_Runtime
(E
: Entity_Id
) return Boolean is
8544 while Scope
(S1
) /= Standard_Standard
loop
8548 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
8551 ----------------------------
8552 -- Initialization_Warning --
8553 ----------------------------
8555 procedure Initialization_Warning
(E
: Entity_Id
) is
8556 Warning_Needed
: Boolean;
8559 Warning_Needed
:= False;
8561 if Ekind
(Current_Scope
) = E_Package
8562 and then Static_Elaboration_Desired
(Current_Scope
)
8565 if Is_Record_Type
(E
) then
8566 if Has_Discriminants
(E
)
8567 or else Is_Limited_Type
(E
)
8568 or else Has_Non_Standard_Rep
(E
)
8570 Warning_Needed
:= True;
8573 -- Verify that at least one component has an initialization
8574 -- expression. No need for a warning on a type if all its
8575 -- components have no initialization.
8581 Comp
:= First_Component
(E
);
8582 while Present
(Comp
) loop
8583 if Ekind
(Comp
) = E_Discriminant
8585 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
8586 and then Present
(Expression
(Parent
(Comp
))))
8588 Warning_Needed
:= True;
8592 Next_Component
(Comp
);
8597 if Warning_Needed
then
8599 ("Objects of the type cannot be initialized statically "
8600 & "by default??", Parent
(E
));
8605 Error_Msg_N
("Object cannot be initialized statically??", E
);
8608 end Initialization_Warning
;
8614 function Init_Formals
(Typ
: Entity_Id
) return List_Id
is
8615 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8619 -- First parameter is always _Init : in out typ. Note that we need this
8620 -- to be in/out because in the case of the task record value, there
8621 -- are default record fields (_Priority, _Size, -Task_Info) that may
8622 -- be referenced in the generated initialization routine.
8624 Formals
:= New_List
(
8625 Make_Parameter_Specification
(Loc
,
8626 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
8628 Out_Present
=> True,
8629 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8631 -- For task record value, or type that contains tasks, add two more
8632 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8633 -- We also add these parameters for the task record type case.
8636 or else (Is_Record_Type
(Typ
) and then Is_Task_Record_Type
(Typ
))
8639 Make_Parameter_Specification
(Loc
,
8640 Defining_Identifier
=>
8641 Make_Defining_Identifier
(Loc
, Name_uMaster
),
8643 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
)));
8645 -- Add _Chain (not done for sequential elaboration policy, see
8646 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
8648 if Partition_Elaboration_Policy
/= 'S' then
8650 Make_Parameter_Specification
(Loc
,
8651 Defining_Identifier
=>
8652 Make_Defining_Identifier
(Loc
, Name_uChain
),
8654 Out_Present
=> True,
8656 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
8660 Make_Parameter_Specification
(Loc
,
8661 Defining_Identifier
=>
8662 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
8664 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
8667 -- Due to certain edge cases such as arrays with null-excluding
8668 -- components being built with the secondary stack it becomes necessary
8669 -- to add a formal to the Init_Proc which controls whether we raise
8670 -- Constraint_Errors on generated calls for internal object
8673 if Needs_Conditional_Null_Excluding_Check
(Typ
) then
8675 Make_Parameter_Specification
(Loc
,
8676 Defining_Identifier
=>
8677 Make_Defining_Identifier
(Loc
,
8678 New_External_Name
(Chars
8679 (Component_Type
(Typ
)), "_skip_null_excluding_check")),
8682 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8688 when RE_Not_Available
=>
8692 -------------------------
8693 -- Init_Secondary_Tags --
8694 -------------------------
8696 procedure Init_Secondary_Tags
8699 Init_Tags_List
: List_Id
;
8700 Stmts_List
: List_Id
;
8701 Fixed_Comps
: Boolean := True;
8702 Variable_Comps
: Boolean := True)
8704 Loc
: constant Source_Ptr
:= Sloc
(Target
);
8706 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
8707 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8709 procedure Initialize_Tag
8712 Tag_Comp
: Entity_Id
;
8713 Iface_Tag
: Node_Id
);
8714 -- Initialize the tag of the secondary dispatch table of Typ associated
8715 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8716 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
8717 -- of Typ CPP tagged type we generate code to inherit the contents of
8718 -- the dispatch table directly from the ancestor.
8720 --------------------
8721 -- Initialize_Tag --
8722 --------------------
8724 procedure Initialize_Tag
8727 Tag_Comp
: Entity_Id
;
8728 Iface_Tag
: Node_Id
)
8730 Comp_Typ
: Entity_Id
;
8731 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
8734 -- Initialize pointer to secondary DT associated with the interface
8736 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8737 Append_To
(Init_Tags_List
,
8738 Make_Assignment_Statement
(Loc
,
8740 Make_Selected_Component
(Loc
,
8741 Prefix
=> New_Copy_Tree
(Target
),
8742 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8744 New_Occurrence_Of
(Iface_Tag
, Loc
)));
8747 Comp_Typ
:= Scope
(Tag_Comp
);
8749 -- Initialize the entries of the table of interfaces. We generate a
8750 -- different call when the parent of the type has variable size
8753 if Comp_Typ
/= Etype
(Comp_Typ
)
8754 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
8755 and then Chars
(Tag_Comp
) /= Name_uTag
8757 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
8759 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
8760 -- configurable run-time environment.
8762 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
8764 ("variable size record with interface types", Typ
);
8769 -- Set_Dynamic_Offset_To_Top
8771 -- Prim_T => Typ'Tag,
8772 -- Interface_T => Iface'Tag,
8773 -- Offset_Value => n,
8774 -- Offset_Func => Fn'Address)
8776 Append_To
(Stmts_List
,
8777 Make_Procedure_Call_Statement
(Loc
,
8779 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
8780 Parameter_Associations
=> New_List
(
8781 Make_Attribute_Reference
(Loc
,
8782 Prefix
=> New_Copy_Tree
(Target
),
8783 Attribute_Name
=> Name_Address
),
8785 Unchecked_Convert_To
(RTE
(RE_Tag
),
8787 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)),
8789 Unchecked_Convert_To
(RTE
(RE_Tag
),
8791 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
8794 Unchecked_Convert_To
8795 (RTE
(RE_Storage_Offset
),
8797 Make_Attribute_Reference
(Loc
,
8799 Make_Selected_Component
(Loc
,
8800 Prefix
=> New_Copy_Tree
(Target
),
8802 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8803 Attribute_Name
=> Name_Position
))),
8805 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
8806 Make_Attribute_Reference
(Loc
,
8807 Prefix
=> New_Occurrence_Of
8808 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
8809 Attribute_Name
=> Name_Address
)))));
8811 -- In this case the next component stores the value of the offset
8814 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
8815 pragma Assert
(Present
(Offset_To_Top_Comp
));
8817 Append_To
(Init_Tags_List
,
8818 Make_Assignment_Statement
(Loc
,
8820 Make_Selected_Component
(Loc
,
8821 Prefix
=> New_Copy_Tree
(Target
),
8823 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
8827 Make_Attribute_Reference
(Loc
,
8829 Make_Selected_Component
(Loc
,
8830 Prefix
=> New_Copy_Tree
(Target
),
8831 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8832 Attribute_Name
=> Name_Position
))));
8834 -- Normal case: No discriminants in the parent type
8837 -- Don't need to set any value if the offset-to-top field is
8838 -- statically set or if this interface shares the primary
8841 if not Building_Static_Secondary_DT
(Typ
)
8842 and then not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True)
8844 Append_To
(Stmts_List
,
8845 Build_Set_Static_Offset_To_Top
(Loc
,
8846 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
8848 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8850 Make_Attribute_Reference
(Loc
,
8852 Make_Selected_Component
(Loc
,
8853 Prefix
=> New_Copy_Tree
(Target
),
8855 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8856 Attribute_Name
=> Name_Position
)))));
8860 -- Register_Interface_Offset
8861 -- (Prim_T => Typ'Tag,
8862 -- Interface_T => Iface'Tag,
8863 -- Is_Constant => True,
8864 -- Offset_Value => n,
8865 -- Offset_Func => null);
8867 if not Building_Static_Secondary_DT
(Typ
)
8868 and then RTE_Available
(RE_Register_Interface_Offset
)
8870 Append_To
(Stmts_List
,
8871 Make_Procedure_Call_Statement
(Loc
,
8874 (RTE
(RE_Register_Interface_Offset
), Loc
),
8875 Parameter_Associations
=> New_List
(
8876 Unchecked_Convert_To
(RTE
(RE_Tag
),
8878 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)),
8880 Unchecked_Convert_To
(RTE
(RE_Tag
),
8882 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
8884 New_Occurrence_Of
(Standard_True
, Loc
),
8886 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8888 Make_Attribute_Reference
(Loc
,
8890 Make_Selected_Component
(Loc
,
8891 Prefix
=> New_Copy_Tree
(Target
),
8893 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8894 Attribute_Name
=> Name_Position
))),
8903 Full_Typ
: Entity_Id
;
8904 Ifaces_List
: Elist_Id
;
8905 Ifaces_Comp_List
: Elist_Id
;
8906 Ifaces_Tag_List
: Elist_Id
;
8907 Iface_Elmt
: Elmt_Id
;
8908 Iface_Comp_Elmt
: Elmt_Id
;
8909 Iface_Tag_Elmt
: Elmt_Id
;
8911 In_Variable_Pos
: Boolean;
8913 -- Start of processing for Init_Secondary_Tags
8916 -- Handle private types
8918 if Present
(Full_View
(Typ
)) then
8919 Full_Typ
:= Full_View
(Typ
);
8924 Collect_Interfaces_Info
8925 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
8927 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8928 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
8929 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
8930 while Present
(Iface_Elmt
) loop
8931 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
8933 -- Check if parent of record type has variable size components
8935 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
8936 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
8938 -- If we are compiling under the CPP full ABI compatibility mode and
8939 -- the ancestor is a CPP_Pragma tagged type then we generate code to
8940 -- initialize the secondary tag components from tags that reference
8941 -- secondary tables filled with copy of parent slots.
8943 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
8945 -- Reject interface components located at variable offset in
8946 -- C++ derivations. This is currently unsupported.
8948 if not Fixed_Comps
and then In_Variable_Pos
then
8950 -- Locate the first dynamic component of the record. Done to
8951 -- improve the text of the warning.
8955 Comp_Typ
: Entity_Id
;
8958 Comp
:= First_Entity
(Typ
);
8959 while Present
(Comp
) loop
8960 Comp_Typ
:= Etype
(Comp
);
8962 if Ekind
(Comp
) /= E_Discriminant
8963 and then not Is_Tag
(Comp
)
8966 (Is_Record_Type
(Comp_Typ
)
8968 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
8970 (Is_Array_Type
(Comp_Typ
)
8971 and then Is_Variable_Size_Array
(Comp_Typ
));
8977 pragma Assert
(Present
(Comp
));
8978 Error_Msg_Node_2
:= Comp
;
8980 ("parent type & with dynamic component & cannot be parent"
8981 & " of 'C'P'P derivation if new interfaces are present",
8982 Typ
, Scope
(Original_Record_Component
(Comp
)));
8985 Sloc
(Scope
(Original_Record_Component
(Comp
)));
8987 ("type derived from 'C'P'P type & defined #",
8988 Typ
, Scope
(Original_Record_Component
(Comp
)));
8990 -- Avoid duplicated warnings
8995 -- Initialize secondary tags
9000 Iface
=> Node
(Iface_Elmt
),
9001 Tag_Comp
=> Tag_Comp
,
9002 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
9005 -- Otherwise generate code to initialize the tag
9008 if (In_Variable_Pos
and then Variable_Comps
)
9009 or else (not In_Variable_Pos
and then Fixed_Comps
)
9013 Iface
=> Node
(Iface_Elmt
),
9014 Tag_Comp
=> Tag_Comp
,
9015 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
9019 Next_Elmt
(Iface_Elmt
);
9020 Next_Elmt
(Iface_Comp_Elmt
);
9021 Next_Elmt
(Iface_Tag_Elmt
);
9023 end Init_Secondary_Tags
;
9025 ------------------------------
9026 -- Is_User_Defined_Equality --
9027 ------------------------------
9029 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean is
9031 return Chars
(Prim
) = Name_Op_Eq
9032 and then Etype
(First_Formal
(Prim
)) =
9033 Etype
(Next_Formal
(First_Formal
(Prim
)))
9034 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
;
9035 end Is_User_Defined_Equality
;
9037 ----------------------------------------
9038 -- Make_Controlling_Function_Wrappers --
9039 ----------------------------------------
9041 procedure Make_Controlling_Function_Wrappers
9042 (Tag_Typ
: Entity_Id
;
9043 Decl_List
: out List_Id
;
9044 Body_List
: out List_Id
)
9046 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9047 Prim_Elmt
: Elmt_Id
;
9049 Actual_List
: List_Id
;
9050 Formal_List
: List_Id
;
9052 Par_Formal
: Entity_Id
;
9053 Formal_Node
: Node_Id
;
9054 Func_Body
: Node_Id
;
9055 Func_Decl
: Node_Id
;
9056 Func_Spec
: Node_Id
;
9057 Return_Stmt
: Node_Id
;
9060 Decl_List
:= New_List
;
9061 Body_List
:= New_List
;
9063 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9064 while Present
(Prim_Elmt
) loop
9065 Subp
:= Node
(Prim_Elmt
);
9067 -- If a primitive function with a controlling result of the type has
9068 -- not been overridden by the user, then we must create a wrapper
9069 -- function here that effectively overrides it and invokes the
9070 -- (non-abstract) parent function. This can only occur for a null
9071 -- extension. Note that functions with anonymous controlling access
9072 -- results don't qualify and must be overridden. We also exclude
9073 -- Input attributes, since each type will have its own version of
9074 -- Input constructed by the expander. The test for Comes_From_Source
9075 -- is needed to distinguish inherited operations from renamings
9076 -- (which also have Alias set). We exclude internal entities with
9077 -- Interface_Alias to avoid generating duplicated wrappers since
9078 -- the primitive which covers the interface is also available in
9079 -- the list of primitive operations.
9081 -- The function may be abstract, or require_Overriding may be set
9082 -- for it, because tests for null extensions may already have reset
9083 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
9084 -- set, functions that need wrappers are recognized by having an
9085 -- alias that returns the parent type.
9087 if Comes_From_Source
(Subp
)
9088 or else No
(Alias
(Subp
))
9089 or else Present
(Interface_Alias
(Subp
))
9090 or else Ekind
(Subp
) /= E_Function
9091 or else not Has_Controlling_Result
(Subp
)
9092 or else Is_Access_Type
(Etype
(Subp
))
9093 or else Is_Abstract_Subprogram
(Alias
(Subp
))
9094 or else Is_TSS
(Subp
, TSS_Stream_Input
)
9098 elsif Is_Abstract_Subprogram
(Subp
)
9099 or else Requires_Overriding
(Subp
)
9101 (Is_Null_Extension
(Etype
(Subp
))
9102 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
9104 Formal_List
:= No_List
;
9105 Formal
:= First_Formal
(Subp
);
9107 if Present
(Formal
) then
9108 Formal_List
:= New_List
;
9110 while Present
(Formal
) loop
9112 (Make_Parameter_Specification
9114 Defining_Identifier
=>
9115 Make_Defining_Identifier
(Sloc
(Formal
),
9116 Chars
=> Chars
(Formal
)),
9117 In_Present
=> In_Present
(Parent
(Formal
)),
9118 Out_Present
=> Out_Present
(Parent
(Formal
)),
9119 Null_Exclusion_Present
=>
9120 Null_Exclusion_Present
(Parent
(Formal
)),
9122 New_Occurrence_Of
(Etype
(Formal
), Loc
),
9124 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
9127 Next_Formal
(Formal
);
9132 Make_Function_Specification
(Loc
,
9133 Defining_Unit_Name
=>
9134 Make_Defining_Identifier
(Loc
,
9135 Chars
=> Chars
(Subp
)),
9136 Parameter_Specifications
=> Formal_List
,
9137 Result_Definition
=>
9138 New_Occurrence_Of
(Etype
(Subp
), Loc
));
9140 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Func_Spec
);
9141 Append_To
(Decl_List
, Func_Decl
);
9143 -- Build a wrapper body that calls the parent function. The body
9144 -- contains a single return statement that returns an extension
9145 -- aggregate whose ancestor part is a call to the parent function,
9146 -- passing the formals as actuals (with any controlling arguments
9147 -- converted to the types of the corresponding formals of the
9148 -- parent function, which might be anonymous access types), and
9149 -- having a null extension.
9151 Formal
:= First_Formal
(Subp
);
9152 Par_Formal
:= First_Formal
(Alias
(Subp
));
9153 Formal_Node
:= First
(Formal_List
);
9155 if Present
(Formal
) then
9156 Actual_List
:= New_List
;
9158 Actual_List
:= No_List
;
9161 while Present
(Formal
) loop
9162 if Is_Controlling_Formal
(Formal
) then
9163 Append_To
(Actual_List
,
9164 Make_Type_Conversion
(Loc
,
9166 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
9169 (Defining_Identifier
(Formal_Node
), Loc
)));
9174 (Defining_Identifier
(Formal_Node
), Loc
));
9177 Next_Formal
(Formal
);
9178 Next_Formal
(Par_Formal
);
9183 Make_Simple_Return_Statement
(Loc
,
9185 Make_Extension_Aggregate
(Loc
,
9187 Make_Function_Call
(Loc
,
9189 New_Occurrence_Of
(Alias
(Subp
), Loc
),
9190 Parameter_Associations
=> Actual_List
),
9191 Null_Record_Present
=> True));
9194 Make_Subprogram_Body
(Loc
,
9195 Specification
=> New_Copy_Tree
(Func_Spec
),
9196 Declarations
=> Empty_List
,
9197 Handled_Statement_Sequence
=>
9198 Make_Handled_Sequence_Of_Statements
(Loc
,
9199 Statements
=> New_List
(Return_Stmt
)));
9201 Set_Defining_Unit_Name
9202 (Specification
(Func_Body
),
9203 Make_Defining_Identifier
(Loc
, Chars
(Subp
)));
9205 Append_To
(Body_List
, Func_Body
);
9207 -- Replace the inherited function with the wrapper function in the
9208 -- primitive operations list. We add the minimum decoration needed
9209 -- to override interface primitives.
9211 Set_Ekind
(Defining_Unit_Name
(Func_Spec
), E_Function
);
9213 Override_Dispatching_Operation
9214 (Tag_Typ
, Subp
, New_Op
=> Defining_Unit_Name
(Func_Spec
),
9215 Is_Wrapper
=> True);
9219 Next_Elmt
(Prim_Elmt
);
9221 end Make_Controlling_Function_Wrappers
;
9227 function Make_Eq_Body
9229 Eq_Name
: Name_Id
) return Node_Id
9231 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
9233 Def
: constant Node_Id
:= Parent
(Typ
);
9234 Stmts
: constant List_Id
:= New_List
;
9235 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
9236 Comps
: Node_Id
:= Empty
;
9237 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
9241 Predef_Spec_Or_Body
(Loc
,
9244 Profile
=> New_List
(
9245 Make_Parameter_Specification
(Loc
,
9246 Defining_Identifier
=>
9247 Make_Defining_Identifier
(Loc
, Name_X
),
9248 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
9250 Make_Parameter_Specification
(Loc
,
9251 Defining_Identifier
=>
9252 Make_Defining_Identifier
(Loc
, Name_Y
),
9253 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9255 Ret_Type
=> Standard_Boolean
,
9258 if Variant_Case
then
9259 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
9260 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
9263 if Present
(Typ_Def
) then
9264 Comps
:= Component_List
(Typ_Def
);
9268 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
9271 if Variant_Case
then
9273 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
9274 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
9276 Make_Simple_Return_Statement
(Loc
,
9277 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9281 Make_Simple_Return_Statement
(Loc
,
9283 Expand_Record_Equality
9286 Lhs
=> Make_Identifier
(Loc
, Name_X
),
9287 Rhs
=> Make_Identifier
(Loc
, Name_Y
),
9288 Bodies
=> Declarations
(Decl
))));
9291 Set_Handled_Statement_Sequence
9292 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9300 -- <Make_Eq_If shared components>
9303 -- when V1 => <Make_Eq_Case> on subcomponents
9305 -- when Vn => <Make_Eq_Case> on subcomponents
9308 function Make_Eq_Case
9311 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
9313 Loc
: constant Source_Ptr
:= Sloc
(E
);
9314 Result
: constant List_Id
:= New_List
;
9318 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
9319 -- Given the discriminant that controls a given variant of an unchecked
9320 -- union, find the formal of the equality function that carries the
9321 -- inferred value of the discriminant.
9323 function External_Name
(E
: Entity_Id
) return Name_Id
;
9324 -- The value of a given discriminant is conveyed in the corresponding
9325 -- formal parameter of the equality routine. The name of this formal
9326 -- parameter carries a one-character suffix which is removed here.
9328 --------------------------
9329 -- Corresponding_Formal --
9330 --------------------------
9332 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
9333 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
9337 Elm
:= First_Elmt
(Discrs
);
9338 while Present
(Elm
) loop
9339 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
9346 -- A formal of the proper name must be found
9348 raise Program_Error
;
9349 end Corresponding_Formal
;
9355 function External_Name
(E
: Entity_Id
) return Name_Id
is
9357 Get_Name_String
(Chars
(E
));
9358 Name_Len
:= Name_Len
- 1;
9362 -- Start of processing for Make_Eq_Case
9365 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
9367 if No
(Variant_Part
(CL
)) then
9371 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
9373 if No
(Variant
) then
9377 Alt_List
:= New_List
;
9378 while Present
(Variant
) loop
9379 Append_To
(Alt_List
,
9380 Make_Case_Statement_Alternative
(Loc
,
9381 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
9383 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
9384 Next_Non_Pragma
(Variant
);
9387 -- If we have an Unchecked_Union, use one of the parameters of the
9388 -- enclosing equality routine that captures the discriminant, to use
9389 -- as the expression in the generated case statement.
9391 if Is_Unchecked_Union
(E
) then
9393 Make_Case_Statement
(Loc
,
9395 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
9396 Alternatives
=> Alt_List
));
9400 Make_Case_Statement
(Loc
,
9402 Make_Selected_Component
(Loc
,
9403 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9404 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
9405 Alternatives
=> Alt_List
));
9426 -- or a null statement if the list L is empty
9430 L
: List_Id
) return Node_Id
9432 Loc
: constant Source_Ptr
:= Sloc
(E
);
9434 Field_Name
: Name_Id
;
9439 return Make_Null_Statement
(Loc
);
9444 C
:= First_Non_Pragma
(L
);
9445 while Present
(C
) loop
9446 Field_Name
:= Chars
(Defining_Identifier
(C
));
9448 -- The tags must not be compared: they are not part of the value.
9449 -- Ditto for parent interfaces because their equality operator is
9452 -- Note also that in the following, we use Make_Identifier for
9453 -- the component names. Use of New_Occurrence_Of to identify the
9454 -- components would be incorrect because the wrong entities for
9455 -- discriminants could be picked up in the private type case.
9457 if Field_Name
= Name_uParent
9458 and then Is_Interface
(Etype
(Defining_Identifier
(C
)))
9462 elsif Field_Name
/= Name_uTag
then
9463 Evolve_Or_Else
(Cond
,
9466 Make_Selected_Component
(Loc
,
9467 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9468 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
)),
9471 Make_Selected_Component
(Loc
,
9472 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
9473 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
))));
9476 Next_Non_Pragma
(C
);
9480 return Make_Null_Statement
(Loc
);
9484 Make_Implicit_If_Statement
(E
,
9486 Then_Statements
=> New_List
(
9487 Make_Simple_Return_Statement
(Loc
,
9488 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
9497 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
9499 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
9500 -- Returns true if Prim is a renaming of an unresolved predefined
9501 -- inequality operation.
9503 --------------------------------
9504 -- Is_Predefined_Neq_Renaming --
9505 --------------------------------
9507 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
9509 return Chars
(Prim
) /= Name_Op_Ne
9510 and then Present
(Alias
(Prim
))
9511 and then Comes_From_Source
(Prim
)
9512 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9513 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
9514 end Is_Predefined_Neq_Renaming
;
9518 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
9519 Stmts
: constant List_Id
:= New_List
;
9521 Eq_Prim
: Entity_Id
;
9522 Left_Op
: Entity_Id
;
9523 Renaming_Prim
: Entity_Id
;
9524 Right_Op
: Entity_Id
;
9527 -- Start of processing for Make_Neq_Body
9530 -- For a call on a renaming of a dispatching subprogram that is
9531 -- overridden, if the overriding occurred before the renaming, then
9532 -- the body executed is that of the overriding declaration, even if the
9533 -- overriding declaration is not visible at the place of the renaming;
9534 -- otherwise, the inherited or predefined subprogram is called, see
9537 -- Stage 1: Search for a renaming of the inequality primitive and also
9538 -- search for an overriding of the equality primitive located before the
9539 -- renaming declaration.
9547 Renaming_Prim
:= Empty
;
9549 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9550 while Present
(Elmt
) loop
9551 Prim
:= Node
(Elmt
);
9553 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
9554 if No
(Renaming_Prim
) then
9555 pragma Assert
(No
(Eq_Prim
));
9559 elsif Is_Predefined_Neq_Renaming
(Prim
) then
9560 Renaming_Prim
:= Prim
;
9567 -- No further action needed if no renaming was found
9569 if No
(Renaming_Prim
) then
9573 -- Stage 2: Replace the renaming declaration by a subprogram declaration
9574 -- (required to add its body)
9576 Decl
:= Parent
(Parent
(Renaming_Prim
));
9578 Make_Subprogram_Declaration
(Loc
,
9579 Specification
=> Specification
(Decl
)));
9580 Set_Analyzed
(Decl
);
9582 -- Remove the decoration of intrinsic renaming subprogram
9584 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
9585 Set_Convention
(Renaming_Prim
, Convention_Ada
);
9586 Set_Alias
(Renaming_Prim
, Empty
);
9587 Set_Has_Completion
(Renaming_Prim
, False);
9589 -- Stage 3: Build the corresponding body
9591 Left_Op
:= First_Formal
(Renaming_Prim
);
9592 Right_Op
:= Next_Formal
(Left_Op
);
9595 Predef_Spec_Or_Body
(Loc
,
9597 Name
=> Chars
(Renaming_Prim
),
9598 Profile
=> New_List
(
9599 Make_Parameter_Specification
(Loc
,
9600 Defining_Identifier
=>
9601 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
9602 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9604 Make_Parameter_Specification
(Loc
,
9605 Defining_Identifier
=>
9606 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
9607 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9609 Ret_Type
=> Standard_Boolean
,
9612 -- If the overriding of the equality primitive occurred before the
9613 -- renaming, then generate:
9615 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9617 -- return not Oeq (X, Y);
9620 if Present
(Eq_Prim
) then
9623 -- Otherwise build a nested subprogram which performs the predefined
9624 -- evaluation of the equality operator. That is, generate:
9626 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9627 -- function Oeq (X : Y) return Boolean is
9629 -- <<body of default implementation>>
9632 -- return not Oeq (X, Y);
9637 Local_Subp
: Node_Id
;
9639 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
9640 Set_Declarations
(Decl
, New_List
(Local_Subp
));
9641 Target
:= Defining_Entity
(Local_Subp
);
9646 Make_Simple_Return_Statement
(Loc
,
9649 Make_Function_Call
(Loc
,
9650 Name
=> New_Occurrence_Of
(Target
, Loc
),
9651 Parameter_Associations
=> New_List
(
9652 Make_Identifier
(Loc
, Chars
(Left_Op
)),
9653 Make_Identifier
(Loc
, Chars
(Right_Op
)))))));
9655 Set_Handled_Statement_Sequence
9656 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9660 -------------------------------
9661 -- Make_Null_Procedure_Specs --
9662 -------------------------------
9664 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
9665 Decl_List
: constant List_Id
:= New_List
;
9666 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9668 Formal_List
: List_Id
;
9669 New_Param_Spec
: Node_Id
;
9670 Parent_Subp
: Entity_Id
;
9671 Prim_Elmt
: Elmt_Id
;
9675 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9676 while Present
(Prim_Elmt
) loop
9677 Subp
:= Node
(Prim_Elmt
);
9679 -- If a null procedure inherited from an interface has not been
9680 -- overridden, then we build a null procedure declaration to
9681 -- override the inherited procedure.
9683 Parent_Subp
:= Alias
(Subp
);
9685 if Present
(Parent_Subp
)
9686 and then Is_Null_Interface_Primitive
(Parent_Subp
)
9688 Formal_List
:= No_List
;
9689 Formal
:= First_Formal
(Subp
);
9691 if Present
(Formal
) then
9692 Formal_List
:= New_List
;
9694 while Present
(Formal
) loop
9696 -- Copy the parameter spec including default expressions
9699 New_Copy_Tree
(Parent
(Formal
), New_Sloc
=> Loc
);
9701 -- Generate a new defining identifier for the new formal.
9702 -- required because New_Copy_Tree does not duplicate
9703 -- semantic fields (except itypes).
9705 Set_Defining_Identifier
(New_Param_Spec
,
9706 Make_Defining_Identifier
(Sloc
(Formal
),
9707 Chars
=> Chars
(Formal
)));
9709 -- For controlling arguments we must change their
9710 -- parameter type to reference the tagged type (instead
9711 -- of the interface type)
9713 if Is_Controlling_Formal
(Formal
) then
9714 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
9716 Set_Parameter_Type
(New_Param_Spec
,
9717 New_Occurrence_Of
(Tag_Typ
, Loc
));
9720 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
9721 N_Access_Definition
);
9722 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
9723 New_Occurrence_Of
(Tag_Typ
, Loc
));
9727 Append
(New_Param_Spec
, Formal_List
);
9729 Next_Formal
(Formal
);
9733 Append_To
(Decl_List
,
9734 Make_Subprogram_Declaration
(Loc
,
9735 Make_Procedure_Specification
(Loc
,
9736 Defining_Unit_Name
=>
9737 Make_Defining_Identifier
(Loc
, Chars
(Subp
)),
9738 Parameter_Specifications
=> Formal_List
,
9739 Null_Present
=> True)));
9742 Next_Elmt
(Prim_Elmt
);
9746 end Make_Null_Procedure_Specs
;
9748 -------------------------------------
9749 -- Make_Predefined_Primitive_Specs --
9750 -------------------------------------
9752 procedure Make_Predefined_Primitive_Specs
9753 (Tag_Typ
: Entity_Id
;
9754 Predef_List
: out List_Id
;
9755 Renamed_Eq
: out Entity_Id
)
9757 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
9758 -- Returns true if Prim is a renaming of an unresolved predefined
9759 -- equality operation.
9761 -------------------------------
9762 -- Is_Predefined_Eq_Renaming --
9763 -------------------------------
9765 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
9767 return Chars
(Prim
) /= Name_Op_Eq
9768 and then Present
(Alias
(Prim
))
9769 and then Comes_From_Source
(Prim
)
9770 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9771 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
9772 end Is_Predefined_Eq_Renaming
;
9776 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9777 Res
: constant List_Id
:= New_List
;
9778 Eq_Name
: Name_Id
:= Name_Op_Eq
;
9779 Eq_Needed
: Boolean;
9783 Has_Predef_Eq_Renaming
: Boolean := False;
9784 -- Set to True if Tag_Typ has a primitive that renames the predefined
9785 -- equality operator. Used to implement (RM 8-5-4(8)).
9787 -- Start of processing for Make_Predefined_Primitive_Specs
9790 Renamed_Eq
:= Empty
;
9794 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9797 Profile
=> New_List
(
9798 Make_Parameter_Specification
(Loc
,
9799 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9800 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9802 Ret_Type
=> Standard_Long_Long_Integer
));
9804 -- Specs for dispatching stream attributes
9807 Stream_Op_TSS_Names
:
9808 constant array (Positive range <>) of TSS_Name_Type
:=
9815 for Op
in Stream_Op_TSS_Names
'Range loop
9816 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
9818 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
9819 Stream_Op_TSS_Names
(Op
)));
9824 -- Spec of "=" is expanded if the type is not limited and if a user
9825 -- defined "=" was not already declared for the non-full view of a
9826 -- private extension
9828 if not Is_Limited_Type
(Tag_Typ
) then
9830 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9831 while Present
(Prim
) loop
9833 -- If a primitive is encountered that renames the predefined
9834 -- equality operator before reaching any explicit equality
9835 -- primitive, then we still need to create a predefined equality
9836 -- function, because calls to it can occur via the renaming. A
9837 -- new name is created for the equality to avoid conflicting with
9838 -- any user-defined equality. (Note that this doesn't account for
9839 -- renamings of equality nested within subpackages???)
9841 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9842 Has_Predef_Eq_Renaming
:= True;
9843 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
9845 -- User-defined equality
9847 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
9848 if No
(Alias
(Node
(Prim
)))
9849 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
9850 N_Subprogram_Renaming_Declaration
9855 -- If the parent is not an interface type and has an abstract
9856 -- equality function explicitly defined in the sources, then
9857 -- the inherited equality is abstract as well, and no body can
9858 -- be created for it.
9860 elsif not Is_Interface
(Etype
(Tag_Typ
))
9861 and then Present
(Alias
(Node
(Prim
)))
9862 and then Comes_From_Source
(Alias
(Node
(Prim
)))
9863 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
9868 -- If the type has an equality function corresponding with
9869 -- a primitive defined in an interface type, the inherited
9870 -- equality is abstract as well, and no body can be created
9873 elsif Present
(Alias
(Node
(Prim
)))
9874 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
9877 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
9887 -- If a renaming of predefined equality was found but there was no
9888 -- user-defined equality (so Eq_Needed is still true), then set the
9889 -- name back to Name_Op_Eq. But in the case where a user-defined
9890 -- equality was located after such a renaming, then the predefined
9891 -- equality function is still needed, so Eq_Needed must be set back
9894 if Eq_Name
/= Name_Op_Eq
then
9896 Eq_Name
:= Name_Op_Eq
;
9903 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
9906 Profile
=> New_List
(
9907 Make_Parameter_Specification
(Loc
,
9908 Defining_Identifier
=>
9909 Make_Defining_Identifier
(Loc
, Name_X
),
9910 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9912 Make_Parameter_Specification
(Loc
,
9913 Defining_Identifier
=>
9914 Make_Defining_Identifier
(Loc
, Name_Y
),
9915 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9916 Ret_Type
=> Standard_Boolean
);
9917 Append_To
(Res
, Eq_Spec
);
9919 if Has_Predef_Eq_Renaming
then
9920 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
9922 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9923 while Present
(Prim
) loop
9925 -- Any renamings of equality that appeared before an
9926 -- overriding equality must be updated to refer to the
9927 -- entity for the predefined equality, otherwise calls via
9928 -- the renaming would get incorrectly resolved to call the
9929 -- user-defined equality function.
9931 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9932 Set_Alias
(Node
(Prim
), Renamed_Eq
);
9934 -- Exit upon encountering a user-defined equality
9936 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
9937 and then No
(Alias
(Node
(Prim
)))
9947 -- Spec for dispatching assignment
9949 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9951 Name
=> Name_uAssign
,
9952 Profile
=> New_List
(
9953 Make_Parameter_Specification
(Loc
,
9954 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9955 Out_Present
=> True,
9956 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9958 Make_Parameter_Specification
(Loc
,
9959 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
9960 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
9963 -- Ada 2005: Generate declarations for the following primitive
9964 -- operations for limited interfaces and synchronized types that
9965 -- implement a limited interface.
9967 -- Disp_Asynchronous_Select
9968 -- Disp_Conditional_Select
9969 -- Disp_Get_Prim_Op_Kind
9972 -- Disp_Timed_Select
9974 -- Disable the generation of these bodies if No_Dispatching_Calls,
9975 -- Ravenscar or ZFP is active.
9977 if Ada_Version
>= Ada_2005
9978 and then not Restriction_Active
(No_Dispatching_Calls
)
9979 and then not Restriction_Active
(No_Select_Statements
)
9980 and then RTE_Available
(RE_Select_Specific_Data
)
9982 -- These primitives are defined abstract in interface types
9984 if Is_Interface
(Tag_Typ
)
9985 and then Is_Limited_Record
(Tag_Typ
)
9988 Make_Abstract_Subprogram_Declaration
(Loc
,
9990 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9993 Make_Abstract_Subprogram_Declaration
(Loc
,
9995 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9998 Make_Abstract_Subprogram_Declaration
(Loc
,
10000 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
10003 Make_Abstract_Subprogram_Declaration
(Loc
,
10005 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
10008 Make_Abstract_Subprogram_Declaration
(Loc
,
10010 Make_Disp_Requeue_Spec
(Tag_Typ
)));
10013 Make_Abstract_Subprogram_Declaration
(Loc
,
10015 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
10017 -- If ancestor is an interface type, declare non-abstract primitives
10018 -- to override the abstract primitives of the interface type.
10020 -- In VM targets we define these primitives in all root tagged types
10021 -- that are not interface types. Done because in VM targets we don't
10022 -- have secondary dispatch tables and any derivation of Tag_Typ may
10023 -- cover limited interfaces (which always have these primitives since
10024 -- they may be ancestors of synchronized interface types).
10026 elsif (not Is_Interface
(Tag_Typ
)
10027 and then Is_Interface
(Etype
(Tag_Typ
))
10028 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10030 (Is_Concurrent_Record_Type
(Tag_Typ
)
10031 and then Has_Interfaces
(Tag_Typ
))
10033 (not Tagged_Type_Expansion
10034 and then not Is_Interface
(Tag_Typ
)
10035 and then Tag_Typ
= Root_Type
(Tag_Typ
))
10038 Make_Subprogram_Declaration
(Loc
,
10040 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
10043 Make_Subprogram_Declaration
(Loc
,
10045 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
10048 Make_Subprogram_Declaration
(Loc
,
10050 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
10053 Make_Subprogram_Declaration
(Loc
,
10055 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
10058 Make_Subprogram_Declaration
(Loc
,
10060 Make_Disp_Requeue_Spec
(Tag_Typ
)));
10063 Make_Subprogram_Declaration
(Loc
,
10065 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
10069 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
10070 -- regardless of whether they are controlled or may contain controlled
10073 -- Do not generate the routines if finalization is disabled
10075 if Restriction_Active
(No_Finalization
) then
10079 if not Is_Limited_Type
(Tag_Typ
) then
10080 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
10083 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
10086 Predef_List
:= Res
;
10087 end Make_Predefined_Primitive_Specs
;
10089 -------------------------
10090 -- Make_Tag_Assignment --
10091 -------------------------
10093 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
10094 Loc
: constant Source_Ptr
:= Sloc
(N
);
10095 Def_If
: constant Entity_Id
:= Defining_Identifier
(N
);
10096 Expr
: constant Node_Id
:= Expression
(N
);
10097 Typ
: constant Entity_Id
:= Etype
(Def_If
);
10098 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
10102 -- This expansion activity is called during analysis, but cannot
10103 -- be applied in ASIS mode when other expansion is disabled.
10105 if Is_Tagged_Type
(Typ
)
10106 and then not Is_Class_Wide_Type
(Typ
)
10107 and then not Is_CPP_Class
(Typ
)
10108 and then Tagged_Type_Expansion
10109 and then Nkind
(Expr
) /= N_Aggregate
10110 and then not ASIS_Mode
10111 and then (Nkind
(Expr
) /= N_Qualified_Expression
10112 or else Nkind
(Expression
(Expr
)) /= N_Aggregate
)
10115 Make_Selected_Component
(Loc
,
10116 Prefix
=> New_Occurrence_Of
(Def_If
, Loc
),
10118 New_Occurrence_Of
(First_Tag_Component
(Full_Typ
), Loc
));
10119 Set_Assignment_OK
(New_Ref
);
10122 Make_Assignment_Statement
(Loc
,
10125 Unchecked_Convert_To
(RTE
(RE_Tag
),
10126 New_Occurrence_Of
(Node
10127 (First_Elmt
(Access_Disp_Table
(Full_Typ
))), Loc
)));
10131 end Make_Tag_Assignment
;
10133 ----------------------
10134 -- Predef_Deep_Spec --
10135 ----------------------
10137 function Predef_Deep_Spec
10139 Tag_Typ
: Entity_Id
;
10140 Name
: TSS_Name_Type
;
10141 For_Body
: Boolean := False) return Node_Id
10146 -- V : in out Tag_Typ
10148 Formals
:= New_List
(
10149 Make_Parameter_Specification
(Loc
,
10150 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
10151 In_Present
=> True,
10152 Out_Present
=> True,
10153 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
10155 -- F : Boolean := True
10157 if Name
= TSS_Deep_Adjust
10158 or else Name
= TSS_Deep_Finalize
10160 Append_To
(Formals
,
10161 Make_Parameter_Specification
(Loc
,
10162 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
10163 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
10164 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10168 Predef_Spec_Or_Body
(Loc
,
10169 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10170 Tag_Typ
=> Tag_Typ
,
10171 Profile
=> Formals
,
10172 For_Body
=> For_Body
);
10175 when RE_Not_Available
=>
10177 end Predef_Deep_Spec
;
10179 -------------------------
10180 -- Predef_Spec_Or_Body --
10181 -------------------------
10183 function Predef_Spec_Or_Body
10185 Tag_Typ
: Entity_Id
;
10188 Ret_Type
: Entity_Id
:= Empty
;
10189 For_Body
: Boolean := False) return Node_Id
10191 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
10195 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
10197 -- The internal flag is set to mark these declarations because they have
10198 -- specific properties. First, they are primitives even if they are not
10199 -- defined in the type scope (the freezing point is not necessarily in
10200 -- the same scope). Second, the predefined equality can be overridden by
10201 -- a user-defined equality, no body will be generated in this case.
10203 Set_Is_Internal
(Id
);
10205 if not Debug_Generated_Code
then
10206 Set_Debug_Info_Off
(Id
);
10209 if No
(Ret_Type
) then
10211 Make_Procedure_Specification
(Loc
,
10212 Defining_Unit_Name
=> Id
,
10213 Parameter_Specifications
=> Profile
);
10216 Make_Function_Specification
(Loc
,
10217 Defining_Unit_Name
=> Id
,
10218 Parameter_Specifications
=> Profile
,
10219 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
10222 if Is_Interface
(Tag_Typ
) then
10223 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10225 -- If body case, return empty subprogram body. Note that this is ill-
10226 -- formed, because there is not even a null statement, and certainly not
10227 -- a return in the function case. The caller is expected to do surgery
10228 -- on the body to add the appropriate stuff.
10230 elsif For_Body
then
10231 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
10233 -- For the case of an Input attribute predefined for an abstract type,
10234 -- generate an abstract specification. This will never be called, but we
10235 -- need the slot allocated in the dispatching table so that attributes
10236 -- typ'Class'Input and typ'Class'Output will work properly.
10238 elsif Is_TSS
(Name
, TSS_Stream_Input
)
10239 and then Is_Abstract_Type
(Tag_Typ
)
10241 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10243 -- Normal spec case, where we return a subprogram declaration
10246 return Make_Subprogram_Declaration
(Loc
, Spec
);
10248 end Predef_Spec_Or_Body
;
10250 -----------------------------
10251 -- Predef_Stream_Attr_Spec --
10252 -----------------------------
10254 function Predef_Stream_Attr_Spec
10256 Tag_Typ
: Entity_Id
;
10257 Name
: TSS_Name_Type
;
10258 For_Body
: Boolean := False) return Node_Id
10260 Ret_Type
: Entity_Id
;
10263 if Name
= TSS_Stream_Input
then
10264 Ret_Type
:= Tag_Typ
;
10270 Predef_Spec_Or_Body
10272 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10273 Tag_Typ
=> Tag_Typ
,
10274 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
10275 Ret_Type
=> Ret_Type
,
10276 For_Body
=> For_Body
);
10277 end Predef_Stream_Attr_Spec
;
10279 ---------------------------------
10280 -- Predefined_Primitive_Bodies --
10281 ---------------------------------
10283 function Predefined_Primitive_Bodies
10284 (Tag_Typ
: Entity_Id
;
10285 Renamed_Eq
: Entity_Id
) return List_Id
10287 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
10288 Res
: constant List_Id
:= New_List
;
10289 Adj_Call
: Node_Id
;
10291 Fin_Call
: Node_Id
;
10293 Eq_Needed
: Boolean;
10297 pragma Warnings
(Off
, Ent
);
10300 pragma Assert
(not Is_Interface
(Tag_Typ
));
10302 -- See if we have a predefined "=" operator
10304 if Present
(Renamed_Eq
) then
10306 Eq_Name
:= Chars
(Renamed_Eq
);
10308 -- If the parent is an interface type then it has defined all the
10309 -- predefined primitives abstract and we need to check if the type
10310 -- has some user defined "=" function which matches the profile of
10311 -- the Ada predefined equality operator to avoid generating it.
10313 elsif Is_Interface
(Etype
(Tag_Typ
)) then
10315 Eq_Name
:= Name_Op_Eq
;
10317 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10318 while Present
(Prim
) loop
10319 if Chars
(Node
(Prim
)) = Name_Op_Eq
10320 and then not Is_Internal
(Node
(Prim
))
10321 and then Present
(First_Entity
(Node
(Prim
)))
10323 -- The predefined equality primitive must have exactly two
10324 -- formals whose type is this tagged type
10326 and then Present
(Last_Entity
(Node
(Prim
)))
10327 and then Next_Entity
(First_Entity
(Node
(Prim
)))
10328 = Last_Entity
(Node
(Prim
))
10329 and then Etype
(First_Entity
(Node
(Prim
))) = Tag_Typ
10330 and then Etype
(Last_Entity
(Node
(Prim
))) = Tag_Typ
10332 Eq_Needed
:= False;
10333 Eq_Name
:= No_Name
;
10341 Eq_Needed
:= False;
10342 Eq_Name
:= No_Name
;
10344 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10345 while Present
(Prim
) loop
10346 if Chars
(Node
(Prim
)) = Name_Op_Eq
10347 and then Is_Internal
(Node
(Prim
))
10350 Eq_Name
:= Name_Op_Eq
;
10360 Decl
:= Predef_Spec_Or_Body
(Loc
,
10361 Tag_Typ
=> Tag_Typ
,
10362 Name
=> Name_uSize
,
10363 Profile
=> New_List
(
10364 Make_Parameter_Specification
(Loc
,
10365 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10366 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10368 Ret_Type
=> Standard_Long_Long_Integer
,
10371 Set_Handled_Statement_Sequence
(Decl
,
10372 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10373 Make_Simple_Return_Statement
(Loc
,
10375 Make_Attribute_Reference
(Loc
,
10376 Prefix
=> Make_Identifier
(Loc
, Name_X
),
10377 Attribute_Name
=> Name_Size
)))));
10379 Append_To
(Res
, Decl
);
10381 -- Bodies for Dispatching stream IO routines. We need these only for
10382 -- non-limited types (in the limited case there is no dispatching).
10383 -- We also skip them if dispatching or finalization are not available
10384 -- or if stream operations are prohibited by restriction No_Streams or
10385 -- from use of pragma/aspect No_Tagged_Streams.
10387 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
10388 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
10390 Build_Record_Read_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10391 Append_To
(Res
, Decl
);
10394 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
10395 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
10397 Build_Record_Write_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10398 Append_To
(Res
, Decl
);
10401 -- Skip body of _Input for the abstract case, since the corresponding
10402 -- spec is abstract (see Predef_Spec_Or_Body).
10404 if not Is_Abstract_Type
(Tag_Typ
)
10405 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
10406 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
10408 Build_Record_Or_Elementary_Input_Function
10409 (Loc
, Tag_Typ
, Decl
, Ent
);
10410 Append_To
(Res
, Decl
);
10413 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
10414 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
10416 Build_Record_Or_Elementary_Output_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10417 Append_To
(Res
, Decl
);
10420 -- Ada 2005: Generate bodies for the following primitive operations for
10421 -- limited interfaces and synchronized types that implement a limited
10424 -- disp_asynchronous_select
10425 -- disp_conditional_select
10426 -- disp_get_prim_op_kind
10427 -- disp_get_task_id
10428 -- disp_timed_select
10430 -- The interface versions will have null bodies
10432 -- Disable the generation of these bodies if No_Dispatching_Calls,
10433 -- Ravenscar or ZFP is active.
10435 -- In VM targets we define these primitives in all root tagged types
10436 -- that are not interface types. Done because in VM targets we don't
10437 -- have secondary dispatch tables and any derivation of Tag_Typ may
10438 -- cover limited interfaces (which always have these primitives since
10439 -- they may be ancestors of synchronized interface types).
10441 if Ada_Version
>= Ada_2005
10442 and then not Is_Interface
(Tag_Typ
)
10444 ((Is_Interface
(Etype
(Tag_Typ
))
10445 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10447 (Is_Concurrent_Record_Type
(Tag_Typ
)
10448 and then Has_Interfaces
(Tag_Typ
))
10450 (not Tagged_Type_Expansion
10451 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
10452 and then not Restriction_Active
(No_Dispatching_Calls
)
10453 and then not Restriction_Active
(No_Select_Statements
)
10454 and then RTE_Available
(RE_Select_Specific_Data
)
10456 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
10457 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
10458 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
10459 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
10460 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
10461 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
10464 if not Is_Limited_Type
(Tag_Typ
) and then not Is_Interface
(Tag_Typ
) then
10466 -- Body for equality
10469 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
10470 Append_To
(Res
, Decl
);
10473 -- Body for inequality (if required)
10475 Decl
:= Make_Neq_Body
(Tag_Typ
);
10477 if Present
(Decl
) then
10478 Append_To
(Res
, Decl
);
10481 -- Body for dispatching assignment
10484 Predef_Spec_Or_Body
(Loc
,
10485 Tag_Typ
=> Tag_Typ
,
10486 Name
=> Name_uAssign
,
10487 Profile
=> New_List
(
10488 Make_Parameter_Specification
(Loc
,
10489 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10490 Out_Present
=> True,
10491 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
10493 Make_Parameter_Specification
(Loc
,
10494 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
10495 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10498 Set_Handled_Statement_Sequence
(Decl
,
10499 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10500 Make_Assignment_Statement
(Loc
,
10501 Name
=> Make_Identifier
(Loc
, Name_X
),
10502 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
10504 Append_To
(Res
, Decl
);
10507 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
10508 -- tagged types which do not contain controlled components.
10510 -- Do not generate the routines if finalization is disabled
10512 if Restriction_Active
(No_Finalization
) then
10515 elsif not Has_Controlled_Component
(Tag_Typ
) then
10516 if not Is_Limited_Type
(Tag_Typ
) then
10518 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
10520 if Is_Controlled
(Tag_Typ
) then
10523 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10527 if No
(Adj_Call
) then
10528 Adj_Call
:= Make_Null_Statement
(Loc
);
10531 Set_Handled_Statement_Sequence
(Decl
,
10532 Make_Handled_Sequence_Of_Statements
(Loc
,
10533 Statements
=> New_List
(Adj_Call
)));
10535 Append_To
(Res
, Decl
);
10539 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
10541 if Is_Controlled
(Tag_Typ
) then
10544 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10548 if No
(Fin_Call
) then
10549 Fin_Call
:= Make_Null_Statement
(Loc
);
10552 Set_Handled_Statement_Sequence
(Decl
,
10553 Make_Handled_Sequence_Of_Statements
(Loc
,
10554 Statements
=> New_List
(Fin_Call
)));
10556 Append_To
(Res
, Decl
);
10560 end Predefined_Primitive_Bodies
;
10562 ---------------------------------
10563 -- Predefined_Primitive_Freeze --
10564 ---------------------------------
10566 function Predefined_Primitive_Freeze
10567 (Tag_Typ
: Entity_Id
) return List_Id
10569 Res
: constant List_Id
:= New_List
;
10574 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10575 while Present
(Prim
) loop
10576 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
10577 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
10579 if Present
(Frnodes
) then
10580 Append_List_To
(Res
, Frnodes
);
10588 end Predefined_Primitive_Freeze
;
10590 -------------------------
10591 -- Stream_Operation_OK --
10592 -------------------------
10594 function Stream_Operation_OK
10596 Operation
: TSS_Name_Type
) return Boolean
10598 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
10601 -- Special case of a limited type extension: a default implementation
10602 -- of the stream attributes Read or Write exists if that attribute
10603 -- has been specified or is available for an ancestor type; a default
10604 -- implementation of the attribute Output (resp. Input) exists if the
10605 -- attribute has been specified or Write (resp. Read) is available for
10606 -- an ancestor type. The last condition only applies under Ada 2005.
10608 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
10609 if Operation
= TSS_Stream_Read
then
10610 Has_Predefined_Or_Specified_Stream_Attribute
:=
10611 Has_Specified_Stream_Read
(Typ
);
10613 elsif Operation
= TSS_Stream_Write
then
10614 Has_Predefined_Or_Specified_Stream_Attribute
:=
10615 Has_Specified_Stream_Write
(Typ
);
10617 elsif Operation
= TSS_Stream_Input
then
10618 Has_Predefined_Or_Specified_Stream_Attribute
:=
10619 Has_Specified_Stream_Input
(Typ
)
10621 (Ada_Version
>= Ada_2005
10622 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
10624 elsif Operation
= TSS_Stream_Output
then
10625 Has_Predefined_Or_Specified_Stream_Attribute
:=
10626 Has_Specified_Stream_Output
(Typ
)
10628 (Ada_Version
>= Ada_2005
10629 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
10632 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
10634 if not Has_Predefined_Or_Specified_Stream_Attribute
10635 and then Is_Derived_Type
(Typ
)
10636 and then (Operation
= TSS_Stream_Read
10637 or else Operation
= TSS_Stream_Write
)
10639 Has_Predefined_Or_Specified_Stream_Attribute
:=
10641 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
10645 -- If the type is not limited, or else is limited but the attribute is
10646 -- explicitly specified or is predefined for the type, then return True,
10647 -- unless other conditions prevail, such as restrictions prohibiting
10648 -- streams or dispatching operations. We also return True for limited
10649 -- interfaces, because they may be extended by nonlimited types and
10650 -- permit inheritance in this case (addresses cases where an abstract
10651 -- extension doesn't get 'Input declared, as per comments below, but
10652 -- 'Class'Input must still be allowed). Note that attempts to apply
10653 -- stream attributes to a limited interface or its class-wide type
10654 -- (or limited extensions thereof) will still get properly rejected
10655 -- by Check_Stream_Attribute.
10657 -- We exclude the Input operation from being a predefined subprogram in
10658 -- the case where the associated type is an abstract extension, because
10659 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
10660 -- we don't want an abstract version created because types derived from
10661 -- the abstract type may not even have Input available (for example if
10662 -- derived from a private view of the abstract type that doesn't have
10663 -- a visible Input).
10665 -- Do not generate stream routines for type Finalization_Master because
10666 -- a master may never appear in types and therefore cannot be read or
10670 (not Is_Limited_Type
(Typ
)
10671 or else Is_Interface
(Typ
)
10672 or else Has_Predefined_Or_Specified_Stream_Attribute
)
10674 (Operation
/= TSS_Stream_Input
10675 or else not Is_Abstract_Type
(Typ
)
10676 or else not Is_Derived_Type
(Typ
))
10677 and then not Has_Unknown_Discriminants
(Typ
)
10679 (Is_Interface
(Typ
)
10681 (Is_Task_Interface
(Typ
)
10682 or else Is_Protected_Interface
(Typ
)
10683 or else Is_Synchronized_Interface
(Typ
)))
10684 and then not Restriction_Active
(No_Streams
)
10685 and then not Restriction_Active
(No_Dispatch
)
10686 and then No
(No_Tagged_Streams_Pragma
(Typ
))
10687 and then not No_Run_Time_Mode
10688 and then RTE_Available
(RE_Tag
)
10689 and then No
(Type_Without_Stream_Operation
(Typ
))
10690 and then RTE_Available
(RE_Root_Stream_Type
)
10691 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
10692 end Stream_Operation_OK
;