1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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_Ch11
; use Exp_Ch11
;
38 with Exp_Dbug
; use Exp_Dbug
;
39 with Exp_Disp
; use Exp_Disp
;
40 with Exp_Dist
; use Exp_Dist
;
41 with Exp_Smem
; use Exp_Smem
;
42 with Exp_Strm
; use Exp_Strm
;
43 with Exp_Tss
; use Exp_Tss
;
44 with Exp_Util
; use Exp_Util
;
45 with Freeze
; use Freeze
;
46 with Ghost
; use Ghost
;
47 with Inline
; use Inline
;
48 with Namet
; use Namet
;
49 with Nlists
; use Nlists
;
50 with Nmake
; use Nmake
;
52 with Restrict
; use Restrict
;
53 with Rident
; use Rident
;
54 with Rtsfind
; use Rtsfind
;
56 with Sem_Aux
; use Sem_Aux
;
57 with Sem_Attr
; use Sem_Attr
;
58 with Sem_Cat
; use Sem_Cat
;
59 with Sem_Ch3
; use Sem_Ch3
;
60 with Sem_Ch6
; use Sem_Ch6
;
61 with Sem_Ch8
; use Sem_Ch8
;
62 with Sem_Ch13
; use Sem_Ch13
;
63 with Sem_Disp
; use Sem_Disp
;
64 with Sem_Eval
; use Sem_Eval
;
65 with Sem_Mech
; use Sem_Mech
;
66 with Sem_Res
; use Sem_Res
;
67 with Sem_SCIL
; use Sem_SCIL
;
68 with Sem_Type
; use Sem_Type
;
69 with Sem_Util
; use Sem_Util
;
70 with Sinfo
; use Sinfo
;
71 with Stand
; use Stand
;
72 with Snames
; use Snames
;
73 with Targparm
; use Targparm
;
74 with Tbuild
; use Tbuild
;
75 with Ttypes
; use Ttypes
;
76 with Validsw
; use Validsw
;
78 package body Exp_Ch3
is
80 -----------------------
81 -- Local Subprograms --
82 -----------------------
84 procedure Adjust_Discriminants
(Rtype
: Entity_Id
);
85 -- This is used when freezing a record type. It attempts to construct
86 -- more restrictive subtypes for discriminants so that the max size of
87 -- the record can be calculated more accurately. See the body of this
88 -- procedure for details.
90 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
);
91 -- Build initialization procedure for given array type. Nod is a node
92 -- used for attachment of any actions required in its construction.
93 -- It also supplies the source location used for the procedure.
95 function Build_Array_Invariant_Proc
97 Nod
: Node_Id
) return Node_Id
;
98 -- If the component of type of array type has invariants, build procedure
99 -- that checks invariant on all components of the array. Ada 2012 specifies
100 -- that an invariant on some type T must be applied to in-out parameters
101 -- and return values that include a part of type T. If the array type has
102 -- an otherwise specified invariant, the component check procedure is
103 -- called from within the user-specified invariant. Otherwise this becomes
104 -- the invariant procedure for the array type.
106 function Build_Record_Invariant_Proc
108 Nod
: Node_Id
) return Node_Id
;
109 -- Ditto for record types.
111 function Build_Discriminant_Formals
113 Use_Dl
: Boolean) return List_Id
;
114 -- This function uses the discriminants of a type to build a list of
115 -- formal parameters, used in Build_Init_Procedure among other places.
116 -- If the flag Use_Dl is set, the list is built using the already
117 -- defined discriminals of the type, as is the case for concurrent
118 -- types with discriminants. Otherwise new identifiers are created,
119 -- with the source names of the discriminants.
121 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
;
122 -- This function builds a static aggregate that can serve as the initial
123 -- value for an array type whose bounds are static, and whose component
124 -- type is a composite type that has a static equivalent aggregate.
125 -- The equivalent array aggregate is used both for object initialization
126 -- and for component initialization, when used in the following function.
128 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
;
129 -- This function builds a static aggregate that can serve as the initial
130 -- value for a record type whose components are scalar and initialized
131 -- with compile-time values, or arrays with similar initialization or
132 -- defaults. When possible, initialization of an object of the type can
133 -- be achieved by using a copy of the aggregate as an initial value, thus
134 -- removing the implicit call that would otherwise constitute elaboration
137 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
);
138 -- Build record initialization procedure. N is the type declaration
139 -- node, and Rec_Ent is the corresponding entity for the record type.
141 procedure Build_Slice_Assignment
(Typ
: Entity_Id
);
142 -- Build assignment procedure for one-dimensional arrays of controlled
143 -- types. Other array and slice assignments are expanded in-line, but
144 -- the code expansion for controlled components (when control actions
145 -- are active) can lead to very large blocks that GCC3 handles poorly.
147 procedure Build_Untagged_Equality
(Typ
: Entity_Id
);
148 -- AI05-0123: Equality on untagged records composes. This procedure
149 -- builds the equality routine for an untagged record that has components
150 -- of a record type that has user-defined primitive equality operations.
151 -- The resulting operation is a TSS subprogram.
153 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
);
154 -- Create An Equality function for the untagged variant record Typ and
155 -- attach it to the TSS list
157 procedure Check_Stream_Attributes
(Typ
: Entity_Id
);
158 -- Check that if a limited extension has a parent with user-defined stream
159 -- attributes, and does not itself have user-defined stream-attributes,
160 -- then any limited component of the extension also has the corresponding
161 -- user-defined stream attributes.
163 procedure Clean_Task_Names
165 Proc_Id
: Entity_Id
);
166 -- If an initialization procedure includes calls to generate names
167 -- for task subcomponents, indicate that secondary stack cleanup is
168 -- needed after an initialization. Typ is the component type, and Proc_Id
169 -- the initialization procedure for the enclosing composite type.
171 procedure Expand_Freeze_Array_Type
(N
: Node_Id
);
172 -- Freeze an array type. Deals with building the initialization procedure,
173 -- creating the packed array type for a packed array and also with the
174 -- creation of the controlling procedures for the controlled case. The
175 -- argument N is the N_Freeze_Entity node for the type.
177 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
);
178 -- Freeze a class-wide type. Build routine Finalize_Address for the purpose
179 -- of finalizing controlled derivations from the class-wide's root type.
181 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
);
182 -- Freeze enumeration type with non-standard representation. Builds the
183 -- array and function needed to convert between enumeration pos and
184 -- enumeration representation values. N is the N_Freeze_Entity node
187 procedure Expand_Freeze_Record_Type
(N
: Node_Id
);
188 -- Freeze record type. Builds all necessary discriminant checking
189 -- and other ancillary functions, and builds dispatch tables where
190 -- needed. The argument N is the N_Freeze_Entity node. This processing
191 -- applies only to E_Record_Type entities, not to class wide types,
192 -- record subtypes, or private types.
194 procedure Expand_Tagged_Root
(T
: Entity_Id
);
195 -- Add a field _Tag at the beginning of the record. This field carries
196 -- the value of the access to the Dispatch table. This procedure is only
197 -- called on root type, the _Tag field being inherited by the descendants.
199 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
);
200 -- Treat user-defined stream operations as renaming_as_body if the
201 -- subprogram they rename is not frozen when the type is frozen.
203 procedure Insert_Component_Invariant_Checks
207 -- If a composite type has invariants and also has components with defined
208 -- invariants. the component invariant procedure is inserted into the user-
209 -- defined invariant procedure and added to the checks to be performed.
211 procedure Initialization_Warning
(E
: Entity_Id
);
212 -- If static elaboration of the package is requested, indicate
213 -- when a type does meet the conditions for static initialization. If
214 -- E is a type, it has components that have no static initialization.
215 -- if E is an entity, its initial expression is not compile-time known.
217 function Init_Formals
(Typ
: Entity_Id
) return List_Id
;
218 -- This function builds the list of formals for an initialization routine.
219 -- The first formal is always _Init with the given type. For task value
220 -- record types and types containing tasks, three additional formals are
223 -- _Master : Master_Id
224 -- _Chain : in out Activation_Chain
225 -- _Task_Name : String
227 -- The caller must append additional entries for discriminants if required.
229 function In_Runtime
(E
: Entity_Id
) return Boolean;
230 -- Check if E is defined in the RTL (in a child of Ada or System). Used
231 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
233 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean;
234 -- Returns true if Prim is a user defined equality function
236 function Make_Eq_Body
238 Eq_Name
: Name_Id
) return Node_Id
;
239 -- Build the body of a primitive equality operation for a tagged record
240 -- type, or in Ada 2012 for any record type that has components with a
241 -- user-defined equality. Factored out of Predefined_Primitive_Bodies.
243 function Make_Eq_Case
246 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
;
247 -- Building block for variant record equality. Defined to share the code
248 -- between the tagged and untagged case. Given a Component_List node CL,
249 -- it generates an 'if' followed by a 'case' statement that compares all
250 -- components of local temporaries named X and Y (that are declared as
251 -- formals at some upper level). E provides the Sloc to be used for the
254 -- IF E is an unchecked_union, Discrs is the list of formals created for
255 -- the inferred discriminants of one operand. These formals are used in
256 -- the generated case statements for each variant of the unchecked union.
260 L
: List_Id
) return Node_Id
;
261 -- Building block for variant record equality. Defined to share the code
262 -- between the tagged and untagged case. Given the list of components
263 -- (or discriminants) L, it generates a return statement that compares all
264 -- components of local temporaries named X and Y (that are declared as
265 -- formals at some upper level). E provides the Sloc to be used for the
268 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
;
269 -- Search for a renaming of the inequality dispatching primitive of
270 -- this tagged type. If found then build and return the corresponding
271 -- rename-as-body inequality subprogram; otherwise return Empty.
273 procedure Make_Predefined_Primitive_Specs
274 (Tag_Typ
: Entity_Id
;
275 Predef_List
: out List_Id
;
276 Renamed_Eq
: out Entity_Id
);
277 -- Create a list with the specs of the predefined primitive operations.
278 -- For tagged types that are interfaces all these primitives are defined
281 -- The following entries are present for all tagged types, and provide
282 -- the results of the corresponding attribute applied to the object.
283 -- Dispatching is required in general, since the result of the attribute
284 -- will vary with the actual object subtype.
286 -- _size provides result of 'Size attribute
287 -- typSR provides result of 'Read attribute
288 -- typSW provides result of 'Write attribute
289 -- typSI provides result of 'Input attribute
290 -- typSO provides result of 'Output attribute
292 -- The following entries are additionally present for non-limited tagged
293 -- types, and implement additional dispatching operations for predefined
296 -- _equality implements "=" operator
297 -- _assign implements assignment operation
298 -- typDF implements deep finalization
299 -- typDA implements deep adjust
301 -- The latter two are empty procedures unless the type contains some
302 -- controlled components that require finalization actions (the deep
303 -- in the name refers to the fact that the action applies to components).
305 -- The list is returned in Predef_List. The Parameter Renamed_Eq either
306 -- returns the value Empty, or else the defining unit name for the
307 -- predefined equality function in the case where the type has a primitive
308 -- operation that is a renaming of predefined equality (but only if there
309 -- is also an overriding user-defined equality function). The returned
310 -- Renamed_Eq will be passed to the corresponding parameter of
311 -- Predefined_Primitive_Bodies.
313 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean;
314 -- returns True if there are representation clauses for type T that are not
315 -- inherited. If the result is false, the init_proc and the discriminant
316 -- checking functions of the parent can be reused by a derived type.
318 procedure Make_Controlling_Function_Wrappers
319 (Tag_Typ
: Entity_Id
;
320 Decl_List
: out List_Id
;
321 Body_List
: out List_Id
);
322 -- Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
323 -- associated with inherited functions with controlling results which
324 -- are not overridden. The body of each wrapper function consists solely
325 -- of a return statement whose expression is an extension aggregate
326 -- invoking the inherited subprogram's parent subprogram and extended
327 -- with a null association list.
329 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
;
330 -- Ada 2005 (AI-251): Makes specs for null procedures associated with any
331 -- null procedures inherited from an interface type that have not been
332 -- overridden. Only one null procedure will be created for a given set of
333 -- inherited null procedures with homographic profiles.
335 function Predef_Spec_Or_Body
340 Ret_Type
: Entity_Id
:= Empty
;
341 For_Body
: Boolean := False) return Node_Id
;
342 -- This function generates the appropriate expansion for a predefined
343 -- primitive operation specified by its name, parameter profile and
344 -- return type (Empty means this is a procedure). If For_Body is false,
345 -- then the returned node is a subprogram declaration. If For_Body is
346 -- true, then the returned node is a empty subprogram body containing
347 -- no declarations and no statements.
349 function Predef_Stream_Attr_Spec
352 Name
: TSS_Name_Type
;
353 For_Body
: Boolean := False) return Node_Id
;
354 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
355 -- input and output attribute whose specs are constructed in Exp_Strm.
357 function Predef_Deep_Spec
360 Name
: TSS_Name_Type
;
361 For_Body
: Boolean := False) return Node_Id
;
362 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
363 -- and _deep_finalize
365 function Predefined_Primitive_Bodies
366 (Tag_Typ
: Entity_Id
;
367 Renamed_Eq
: Entity_Id
) return List_Id
;
368 -- Create the bodies of the predefined primitives that are described in
369 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
370 -- the defining unit name of the type's predefined equality as returned
371 -- by Make_Predefined_Primitive_Specs.
373 function Predefined_Primitive_Freeze
(Tag_Typ
: Entity_Id
) return List_Id
;
374 -- Freeze entities of all predefined primitive operations. This is needed
375 -- because the bodies of these operations do not normally do any freezing.
377 function Stream_Operation_OK
379 Operation
: TSS_Name_Type
) return Boolean;
380 -- Check whether the named stream operation must be emitted for a given
381 -- type. The rules for inheritance of stream attributes by type extensions
382 -- are enforced by this function. Furthermore, various restrictions prevent
383 -- the generation of these operations, as a useful optimization or for
384 -- certification purposes and to save unnecessary generated code.
386 --------------------------
387 -- Adjust_Discriminants --
388 --------------------------
390 -- This procedure attempts to define subtypes for discriminants that are
391 -- more restrictive than those declared. Such a replacement is possible if
392 -- we can demonstrate that values outside the restricted range would cause
393 -- constraint errors in any case. The advantage of restricting the
394 -- discriminant types in this way is that the maximum size of the variant
395 -- record can be calculated more conservatively.
397 -- An example of a situation in which we can perform this type of
398 -- restriction is the following:
400 -- subtype B is range 1 .. 10;
401 -- type Q is array (B range <>) of Integer;
403 -- type V (N : Natural) is record
407 -- In this situation, we can restrict the upper bound of N to 10, since
408 -- any larger value would cause a constraint error in any case.
410 -- There are many situations in which such restriction is possible, but
411 -- for now, we just look for cases like the above, where the component
412 -- in question is a one dimensional array whose upper bound is one of
413 -- the record discriminants. Also the component must not be part of
414 -- any variant part, since then the component does not always exist.
416 procedure Adjust_Discriminants
(Rtype
: Entity_Id
) is
417 Loc
: constant Source_Ptr
:= Sloc
(Rtype
);
434 Comp
:= First_Component
(Rtype
);
435 while Present
(Comp
) loop
437 -- If our parent is a variant, quit, we do not look at components
438 -- that are in variant parts, because they may not always exist.
440 P
:= Parent
(Comp
); -- component declaration
441 P
:= Parent
(P
); -- component list
443 exit when Nkind
(Parent
(P
)) = N_Variant
;
445 -- We are looking for a one dimensional array type
447 Ctyp
:= Etype
(Comp
);
449 if not Is_Array_Type
(Ctyp
) or else Number_Dimensions
(Ctyp
) > 1 then
453 -- The lower bound must be constant, and the upper bound is a
454 -- discriminant (which is a discriminant of the current record).
456 Ityp
:= Etype
(First_Index
(Ctyp
));
457 Lo
:= Type_Low_Bound
(Ityp
);
458 Hi
:= Type_High_Bound
(Ityp
);
460 if not Compile_Time_Known_Value
(Lo
)
461 or else Nkind
(Hi
) /= N_Identifier
462 or else No
(Entity
(Hi
))
463 or else Ekind
(Entity
(Hi
)) /= E_Discriminant
468 -- We have an array with appropriate bounds
470 Loval
:= Expr_Value
(Lo
);
471 Discr
:= Entity
(Hi
);
472 Dtyp
:= Etype
(Discr
);
474 -- See if the discriminant has a known upper bound
476 Dhi
:= Type_High_Bound
(Dtyp
);
478 if not Compile_Time_Known_Value
(Dhi
) then
482 Dhiv
:= Expr_Value
(Dhi
);
484 -- See if base type of component array has known upper bound
486 Ahi
:= Type_High_Bound
(Etype
(First_Index
(Base_Type
(Ctyp
))));
488 if not Compile_Time_Known_Value
(Ahi
) then
492 Ahiv
:= Expr_Value
(Ahi
);
494 -- The condition for doing the restriction is that the high bound
495 -- of the discriminant is greater than the low bound of the array,
496 -- and is also greater than the high bound of the base type index.
498 if Dhiv
> Loval
and then Dhiv
> Ahiv
then
500 -- We can reset the upper bound of the discriminant type to
501 -- whichever is larger, the low bound of the component, or
502 -- the high bound of the base type array index.
504 -- We build a subtype that is declared as
506 -- subtype Tnn is discr_type range discr_type'First .. max;
508 -- And insert this declaration into the tree. The type of the
509 -- discriminant is then reset to this more restricted subtype.
511 Tnn
:= Make_Temporary
(Loc
, 'T');
513 Insert_Action
(Declaration_Node
(Rtype
),
514 Make_Subtype_Declaration
(Loc
,
515 Defining_Identifier
=> Tnn
,
516 Subtype_Indication
=>
517 Make_Subtype_Indication
(Loc
,
518 Subtype_Mark
=> New_Occurrence_Of
(Dtyp
, Loc
),
520 Make_Range_Constraint
(Loc
,
524 Make_Attribute_Reference
(Loc
,
525 Attribute_Name
=> Name_First
,
526 Prefix
=> New_Occurrence_Of
(Dtyp
, Loc
)),
528 Make_Integer_Literal
(Loc
,
529 Intval
=> UI_Max
(Loval
, Ahiv
)))))));
531 Set_Etype
(Discr
, Tnn
);
535 Next_Component
(Comp
);
537 end Adjust_Discriminants
;
539 ---------------------------
540 -- Build_Array_Init_Proc --
541 ---------------------------
543 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
) is
544 Comp_Type
: constant Entity_Id
:= Component_Type
(A_Type
);
545 Body_Stmts
: List_Id
;
546 Has_Default_Init
: Boolean;
547 Index_List
: List_Id
;
551 function Init_Component
return List_Id
;
552 -- Create one statement to initialize one array component, designated
553 -- by a full set of indexes.
555 function Init_One_Dimension
(N
: Int
) return List_Id
;
556 -- Create loop to initialize one dimension of the array. The single
557 -- statement in the loop body initializes the inner dimensions if any,
558 -- or else the single component. Note that this procedure is called
559 -- recursively, with N being the dimension to be initialized. A call
560 -- with N greater than the number of dimensions simply generates the
561 -- component initialization, terminating the recursion.
567 function Init_Component
return List_Id
is
572 Make_Indexed_Component
(Loc
,
573 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
574 Expressions
=> Index_List
);
576 if Has_Default_Aspect
(A_Type
) then
577 Set_Assignment_OK
(Comp
);
579 Make_Assignment_Statement
(Loc
,
582 Convert_To
(Comp_Type
,
583 Default_Aspect_Component_Value
(First_Subtype
(A_Type
)))));
585 elsif Needs_Simple_Initialization
(Comp_Type
) then
586 Set_Assignment_OK
(Comp
);
588 Make_Assignment_Statement
(Loc
,
592 (Comp_Type
, Nod
, Component_Size
(A_Type
))));
595 Clean_Task_Names
(Comp_Type
, Proc_Id
);
597 Build_Initialization_Call
598 (Loc
, Comp
, Comp_Type
,
599 In_Init_Proc
=> True,
600 Enclos_Type
=> A_Type
);
604 ------------------------
605 -- Init_One_Dimension --
606 ------------------------
608 function Init_One_Dimension
(N
: Int
) return List_Id
is
612 -- If the component does not need initializing, then there is nothing
613 -- to do here, so we return a null body. This occurs when generating
614 -- the dummy Init_Proc needed for Initialize_Scalars processing.
616 if not Has_Non_Null_Base_Init_Proc
(Comp_Type
)
617 and then not Needs_Simple_Initialization
(Comp_Type
)
618 and then not Has_Task
(Comp_Type
)
619 and then not Has_Default_Aspect
(A_Type
)
621 return New_List
(Make_Null_Statement
(Loc
));
623 -- If all dimensions dealt with, we simply initialize the component
625 elsif N
> Number_Dimensions
(A_Type
) then
626 return Init_Component
;
628 -- Here we generate the required loop
632 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
634 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
637 Make_Implicit_Loop_Statement
(Nod
,
640 Make_Iteration_Scheme
(Loc
,
641 Loop_Parameter_Specification
=>
642 Make_Loop_Parameter_Specification
(Loc
,
643 Defining_Identifier
=> Index
,
644 Discrete_Subtype_Definition
=>
645 Make_Attribute_Reference
(Loc
,
647 Make_Identifier
(Loc
, Name_uInit
),
648 Attribute_Name
=> Name_Range
,
649 Expressions
=> New_List
(
650 Make_Integer_Literal
(Loc
, N
))))),
651 Statements
=> Init_One_Dimension
(N
+ 1)));
653 end Init_One_Dimension
;
655 -- Start of processing for Build_Array_Init_Proc
658 -- The init proc is created when analyzing the freeze node for the type,
659 -- but it properly belongs with the array type declaration. However, if
660 -- the freeze node is for a subtype of a type declared in another unit
661 -- it seems preferable to use the freeze node as the source location of
662 -- the init proc. In any case this is preferable for gcov usage, and
663 -- the Sloc is not otherwise used by the compiler.
665 if In_Open_Scopes
(Scope
(A_Type
)) then
666 Loc
:= Sloc
(A_Type
);
671 -- Nothing to generate in the following cases:
673 -- 1. Initialization is suppressed for the type
674 -- 2. The type is a value type, in the CIL sense.
675 -- 3. The type has CIL/JVM convention.
676 -- 4. An initialization already exists for the base type
678 if Initialization_Suppressed
(A_Type
)
679 or else Is_Value_Type
(Comp_Type
)
680 or else Convention
(A_Type
) = Convention_CIL
681 or else Convention
(A_Type
) = Convention_Java
682 or else Present
(Base_Init_Proc
(A_Type
))
687 Index_List
:= New_List
;
689 -- We need an initialization procedure if any of the following is true:
691 -- 1. The component type has an initialization procedure
692 -- 2. The component type needs simple initialization
693 -- 3. Tasks are present
694 -- 4. The type is marked as a public entity
695 -- 5. The array type has a Default_Component_Value aspect
697 -- The reason for the public entity test is to deal properly with the
698 -- Initialize_Scalars pragma. This pragma can be set in the client and
699 -- not in the declaring package, this means the client will make a call
700 -- to the initialization procedure (because one of conditions 1-3 must
701 -- apply in this case), and we must generate a procedure (even if it is
702 -- null) to satisfy the call in this case.
704 -- Exception: do not build an array init_proc for a type whose root
705 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
706 -- is no place to put the code, and in any case we handle initialization
707 -- of such types (in the Initialize_Scalars case, that's the only time
708 -- the issue arises) in a special manner anyway which does not need an
711 Has_Default_Init
:= Has_Non_Null_Base_Init_Proc
(Comp_Type
)
712 or else Needs_Simple_Initialization
(Comp_Type
)
713 or else Has_Task
(Comp_Type
)
714 or else Has_Default_Aspect
(A_Type
);
717 or else (not Restriction_Active
(No_Initialize_Scalars
)
718 and then Is_Public
(A_Type
)
719 and then not Is_Standard_String_Type
(A_Type
))
722 Make_Defining_Identifier
(Loc
,
723 Chars
=> Make_Init_Proc_Name
(A_Type
));
725 -- If No_Default_Initialization restriction is active, then we don't
726 -- want to build an init_proc, but we need to mark that an init_proc
727 -- would be needed if this restriction was not active (so that we can
728 -- detect attempts to call it), so set a dummy init_proc in place.
729 -- This is only done though when actual default initialization is
730 -- needed (and not done when only Is_Public is True), since otherwise
731 -- objects such as arrays of scalars could be wrongly flagged as
732 -- violating the restriction.
734 if Restriction_Active
(No_Default_Initialization
) then
735 if Has_Default_Init
then
736 Set_Init_Proc
(A_Type
, Proc_Id
);
742 Body_Stmts
:= Init_One_Dimension
(1);
745 Make_Subprogram_Body
(Loc
,
747 Make_Procedure_Specification
(Loc
,
748 Defining_Unit_Name
=> Proc_Id
,
749 Parameter_Specifications
=> Init_Formals
(A_Type
)),
750 Declarations
=> New_List
,
751 Handled_Statement_Sequence
=>
752 Make_Handled_Sequence_Of_Statements
(Loc
,
753 Statements
=> Body_Stmts
)));
755 Set_Ekind
(Proc_Id
, E_Procedure
);
756 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
757 Set_Is_Internal
(Proc_Id
);
758 Set_Has_Completion
(Proc_Id
);
760 if not Debug_Generated_Code
then
761 Set_Debug_Info_Off
(Proc_Id
);
764 -- Set inlined unless controlled stuff or tasks around, in which
765 -- case we do not want to inline, because nested stuff may cause
766 -- difficulties in inter-unit inlining, and furthermore there is
767 -- in any case no point in inlining such complex init procs.
769 if not Has_Task
(Proc_Id
)
770 and then not Needs_Finalization
(Proc_Id
)
772 Set_Is_Inlined
(Proc_Id
);
775 -- Associate Init_Proc with type, and determine if the procedure
776 -- is null (happens because of the Initialize_Scalars pragma case,
777 -- where we have to generate a null procedure in case it is called
778 -- by a client with Initialize_Scalars set). Such procedures have
779 -- to be generated, but do not have to be called, so we mark them
780 -- as null to suppress the call.
782 Set_Init_Proc
(A_Type
, Proc_Id
);
784 if List_Length
(Body_Stmts
) = 1
786 -- We must skip SCIL nodes because they may have been added to this
787 -- list by Insert_Actions.
789 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
791 Set_Is_Null_Init_Proc
(Proc_Id
);
794 -- Try to build a static aggregate to statically initialize
795 -- objects of the type. This can only be done for constrained
796 -- one-dimensional arrays with static bounds.
798 Set_Static_Initialization
800 Build_Equivalent_Array_Aggregate
(First_Subtype
(A_Type
)));
803 end Build_Array_Init_Proc
;
805 --------------------------------
806 -- Build_Array_Invariant_Proc --
807 --------------------------------
809 function Build_Array_Invariant_Proc
811 Nod
: Node_Id
) return Node_Id
813 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
815 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
816 -- Name for argument of invariant procedure
818 Object_Entity
: constant Node_Id
:=
819 Make_Defining_Identifier
(Loc
, Object_Name
);
820 -- The procedure declaration entity for the argument
822 Body_Stmts
: List_Id
;
823 Index_List
: List_Id
;
827 function Build_Component_Invariant_Call
return Node_Id
;
828 -- Create one statement to verify invariant on one array component,
829 -- designated by a full set of indexes.
831 function Check_One_Dimension
(N
: Int
) return List_Id
;
832 -- Create loop to check on one dimension of the array. The single
833 -- statement in the loop body checks the inner dimensions if any, or
834 -- else a single component. This procedure is called recursively, with
835 -- N being the dimension to be initialized. A call with N greater than
836 -- the number of dimensions generates the component initialization
837 -- and terminates the recursion.
839 ------------------------------------
840 -- Build_Component_Invariant_Call --
841 ------------------------------------
843 function Build_Component_Invariant_Call
return Node_Id
is
847 Make_Indexed_Component
(Loc
,
848 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
849 Expressions
=> Index_List
);
851 Make_Procedure_Call_Statement
(Loc
,
854 (Invariant_Procedure
(Component_Type
(A_Type
)), Loc
),
855 Parameter_Associations
=> New_List
(Comp
));
856 end Build_Component_Invariant_Call
;
858 -------------------------
859 -- Check_One_Dimension --
860 -------------------------
862 function Check_One_Dimension
(N
: Int
) return List_Id
is
866 -- If all dimensions dealt with, we simply check invariant of the
869 if N
> Number_Dimensions
(A_Type
) then
870 return New_List
(Build_Component_Invariant_Call
);
872 -- Else generate one loop and recurse
876 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
878 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
881 Make_Implicit_Loop_Statement
(Nod
,
884 Make_Iteration_Scheme
(Loc
,
885 Loop_Parameter_Specification
=>
886 Make_Loop_Parameter_Specification
(Loc
,
887 Defining_Identifier
=> Index
,
888 Discrete_Subtype_Definition
=>
889 Make_Attribute_Reference
(Loc
,
891 New_Occurrence_Of
(Object_Entity
, Loc
),
892 Attribute_Name
=> Name_Range
,
893 Expressions
=> New_List
(
894 Make_Integer_Literal
(Loc
, N
))))),
895 Statements
=> Check_One_Dimension
(N
+ 1)));
897 end Check_One_Dimension
;
899 -- Start of processing for Build_Array_Invariant_Proc
902 Index_List
:= New_List
;
905 Make_Defining_Identifier
(Loc
,
906 Chars
=> New_External_Name
(Chars
(A_Type
), "CInvariant"));
908 Body_Stmts
:= Check_One_Dimension
(1);
911 Make_Subprogram_Body
(Loc
,
913 Make_Procedure_Specification
(Loc
,
914 Defining_Unit_Name
=> Proc_Id
,
915 Parameter_Specifications
=> New_List
(
916 Make_Parameter_Specification
(Loc
,
917 Defining_Identifier
=> Object_Entity
,
918 Parameter_Type
=> New_Occurrence_Of
(A_Type
, Loc
)))),
920 Declarations
=> Empty_List
,
921 Handled_Statement_Sequence
=>
922 Make_Handled_Sequence_Of_Statements
(Loc
,
923 Statements
=> Body_Stmts
));
925 Set_Ekind
(Proc_Id
, E_Procedure
);
926 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
927 Set_Is_Internal
(Proc_Id
);
928 Set_Has_Completion
(Proc_Id
);
930 if not Debug_Generated_Code
then
931 Set_Debug_Info_Off
(Proc_Id
);
935 end Build_Array_Invariant_Proc
;
937 --------------------------------
938 -- Build_Discr_Checking_Funcs --
939 --------------------------------
941 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
) is
944 Enclosing_Func_Id
: Entity_Id
;
949 function Build_Case_Statement
950 (Case_Id
: Entity_Id
;
951 Variant
: Node_Id
) return Node_Id
;
952 -- Build a case statement containing only two alternatives. The first
953 -- alternative corresponds exactly to the discrete choices given on the
954 -- variant with contains the components that we are generating the
955 -- checks for. If the discriminant is one of these return False. The
956 -- second alternative is an OTHERS choice that will return True
957 -- indicating the discriminant did not match.
959 function Build_Dcheck_Function
960 (Case_Id
: Entity_Id
;
961 Variant
: Node_Id
) return Entity_Id
;
962 -- Build the discriminant checking function for a given variant
964 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
);
965 -- Builds the discriminant checking function for each variant of the
966 -- given variant part of the record type.
968 --------------------------
969 -- Build_Case_Statement --
970 --------------------------
972 function Build_Case_Statement
973 (Case_Id
: Entity_Id
;
974 Variant
: Node_Id
) return Node_Id
976 Alt_List
: constant List_Id
:= New_List
;
977 Actuals_List
: List_Id
;
979 Case_Alt_Node
: Node_Id
;
981 Choice_List
: List_Id
;
983 Return_Node
: Node_Id
;
986 Case_Node
:= New_Node
(N_Case_Statement
, Loc
);
988 -- Replace the discriminant which controls the variant with the name
989 -- of the formal of the checking function.
991 Set_Expression
(Case_Node
, Make_Identifier
(Loc
, Chars
(Case_Id
)));
993 Choice
:= First
(Discrete_Choices
(Variant
));
995 if Nkind
(Choice
) = N_Others_Choice
then
996 Choice_List
:= New_Copy_List
(Others_Discrete_Choices
(Choice
));
998 Choice_List
:= New_Copy_List
(Discrete_Choices
(Variant
));
1001 if not Is_Empty_List
(Choice_List
) then
1002 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1003 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1005 -- In case this is a nested variant, we need to return the result
1006 -- of the discriminant checking function for the immediately
1007 -- enclosing variant.
1009 if Present
(Enclosing_Func_Id
) then
1010 Actuals_List
:= New_List
;
1012 D
:= First_Discriminant
(Rec_Id
);
1013 while Present
(D
) loop
1014 Append
(Make_Identifier
(Loc
, Chars
(D
)), Actuals_List
);
1015 Next_Discriminant
(D
);
1019 Make_Simple_Return_Statement
(Loc
,
1021 Make_Function_Call
(Loc
,
1023 New_Occurrence_Of
(Enclosing_Func_Id
, Loc
),
1024 Parameter_Associations
=>
1029 Make_Simple_Return_Statement
(Loc
,
1031 New_Occurrence_Of
(Standard_False
, Loc
));
1034 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1035 Append
(Case_Alt_Node
, Alt_List
);
1038 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1039 Choice_List
:= New_List
(New_Node
(N_Others_Choice
, Loc
));
1040 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1043 Make_Simple_Return_Statement
(Loc
,
1045 New_Occurrence_Of
(Standard_True
, Loc
));
1047 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1048 Append
(Case_Alt_Node
, Alt_List
);
1050 Set_Alternatives
(Case_Node
, Alt_List
);
1052 end Build_Case_Statement
;
1054 ---------------------------
1055 -- Build_Dcheck_Function --
1056 ---------------------------
1058 function Build_Dcheck_Function
1059 (Case_Id
: Entity_Id
;
1060 Variant
: Node_Id
) return Entity_Id
1062 Body_Node
: Node_Id
;
1063 Func_Id
: Entity_Id
;
1064 Parameter_List
: List_Id
;
1065 Spec_Node
: Node_Id
;
1068 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
1069 Sequence
:= Sequence
+ 1;
1072 Make_Defining_Identifier
(Loc
,
1073 Chars
=> New_External_Name
(Chars
(Rec_Id
), 'D', Sequence
));
1074 Set_Is_Discriminant_Check_Function
(Func_Id
);
1076 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
1077 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
1079 Parameter_List
:= Build_Discriminant_Formals
(Rec_Id
, False);
1081 Set_Parameter_Specifications
(Spec_Node
, Parameter_List
);
1082 Set_Result_Definition
(Spec_Node
,
1083 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1084 Set_Specification
(Body_Node
, Spec_Node
);
1085 Set_Declarations
(Body_Node
, New_List
);
1087 Set_Handled_Statement_Sequence
(Body_Node
,
1088 Make_Handled_Sequence_Of_Statements
(Loc
,
1089 Statements
=> New_List
(
1090 Build_Case_Statement
(Case_Id
, Variant
))));
1092 Set_Ekind
(Func_Id
, E_Function
);
1093 Set_Mechanism
(Func_Id
, Default_Mechanism
);
1094 Set_Is_Inlined
(Func_Id
, True);
1095 Set_Is_Pure
(Func_Id
, True);
1096 Set_Is_Public
(Func_Id
, Is_Public
(Rec_Id
));
1097 Set_Is_Internal
(Func_Id
, True);
1099 if not Debug_Generated_Code
then
1100 Set_Debug_Info_Off
(Func_Id
);
1103 Analyze
(Body_Node
);
1105 Append_Freeze_Action
(Rec_Id
, Body_Node
);
1106 Set_Dcheck_Function
(Variant
, Func_Id
);
1108 end Build_Dcheck_Function
;
1110 ----------------------------
1111 -- Build_Dcheck_Functions --
1112 ----------------------------
1114 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
) is
1115 Component_List_Node
: Node_Id
;
1117 Discr_Name
: Entity_Id
;
1118 Func_Id
: Entity_Id
;
1120 Saved_Enclosing_Func_Id
: Entity_Id
;
1123 -- Build the discriminant-checking function for each variant, and
1124 -- label all components of that variant with the function's name.
1125 -- We only Generate a discriminant-checking function when the
1126 -- variant is not empty, to prevent the creation of dead code.
1127 -- The exception to that is when Frontend_Layout_On_Target is set,
1128 -- because the variant record size function generated in package
1129 -- Layout needs to generate calls to all discriminant-checking
1130 -- functions, including those for empty variants.
1132 Discr_Name
:= Entity
(Name
(Variant_Part_Node
));
1133 Variant
:= First_Non_Pragma
(Variants
(Variant_Part_Node
));
1135 while Present
(Variant
) loop
1136 Component_List_Node
:= Component_List
(Variant
);
1138 if not Null_Present
(Component_List_Node
)
1139 or else Frontend_Layout_On_Target
1141 Func_Id
:= Build_Dcheck_Function
(Discr_Name
, Variant
);
1144 First_Non_Pragma
(Component_Items
(Component_List_Node
));
1145 while Present
(Decl
) loop
1146 Set_Discriminant_Checking_Func
1147 (Defining_Identifier
(Decl
), Func_Id
);
1148 Next_Non_Pragma
(Decl
);
1151 if Present
(Variant_Part
(Component_List_Node
)) then
1152 Saved_Enclosing_Func_Id
:= Enclosing_Func_Id
;
1153 Enclosing_Func_Id
:= Func_Id
;
1154 Build_Dcheck_Functions
(Variant_Part
(Component_List_Node
));
1155 Enclosing_Func_Id
:= Saved_Enclosing_Func_Id
;
1159 Next_Non_Pragma
(Variant
);
1161 end Build_Dcheck_Functions
;
1163 -- Start of processing for Build_Discr_Checking_Funcs
1166 -- Only build if not done already
1168 if not Discr_Check_Funcs_Built
(N
) then
1169 Type_Def
:= Type_Definition
(N
);
1171 if Nkind
(Type_Def
) = N_Record_Definition
then
1172 if No
(Component_List
(Type_Def
)) then -- null record.
1175 V
:= Variant_Part
(Component_List
(Type_Def
));
1178 else pragma Assert
(Nkind
(Type_Def
) = N_Derived_Type_Definition
);
1179 if No
(Component_List
(Record_Extension_Part
(Type_Def
))) then
1183 (Component_List
(Record_Extension_Part
(Type_Def
)));
1187 Rec_Id
:= Defining_Identifier
(N
);
1189 if Present
(V
) and then not Is_Unchecked_Union
(Rec_Id
) then
1191 Enclosing_Func_Id
:= Empty
;
1192 Build_Dcheck_Functions
(V
);
1195 Set_Discr_Check_Funcs_Built
(N
);
1197 end Build_Discr_Checking_Funcs
;
1199 --------------------------------
1200 -- Build_Discriminant_Formals --
1201 --------------------------------
1203 function Build_Discriminant_Formals
1204 (Rec_Id
: Entity_Id
;
1205 Use_Dl
: Boolean) return List_Id
1207 Loc
: Source_Ptr
:= Sloc
(Rec_Id
);
1208 Parameter_List
: constant List_Id
:= New_List
;
1211 Formal_Type
: Entity_Id
;
1212 Param_Spec_Node
: Node_Id
;
1215 if Has_Discriminants
(Rec_Id
) then
1216 D
:= First_Discriminant
(Rec_Id
);
1217 while Present
(D
) loop
1221 Formal
:= Discriminal
(D
);
1222 Formal_Type
:= Etype
(Formal
);
1224 Formal
:= Make_Defining_Identifier
(Loc
, Chars
(D
));
1225 Formal_Type
:= Etype
(D
);
1229 Make_Parameter_Specification
(Loc
,
1230 Defining_Identifier
=> Formal
,
1232 New_Occurrence_Of
(Formal_Type
, Loc
));
1233 Append
(Param_Spec_Node
, Parameter_List
);
1234 Next_Discriminant
(D
);
1238 return Parameter_List
;
1239 end Build_Discriminant_Formals
;
1241 --------------------------------------
1242 -- Build_Equivalent_Array_Aggregate --
1243 --------------------------------------
1245 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
is
1246 Loc
: constant Source_Ptr
:= Sloc
(T
);
1247 Comp_Type
: constant Entity_Id
:= Component_Type
(T
);
1248 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(T
));
1249 Proc
: constant Entity_Id
:= Base_Init_Proc
(T
);
1255 if not Is_Constrained
(T
)
1256 or else Number_Dimensions
(T
) > 1
1259 Initialization_Warning
(T
);
1263 Lo
:= Type_Low_Bound
(Index_Type
);
1264 Hi
:= Type_High_Bound
(Index_Type
);
1266 if not Compile_Time_Known_Value
(Lo
)
1267 or else not Compile_Time_Known_Value
(Hi
)
1269 Initialization_Warning
(T
);
1273 if Is_Record_Type
(Comp_Type
)
1274 and then Present
(Base_Init_Proc
(Comp_Type
))
1276 Expr
:= Static_Initialization
(Base_Init_Proc
(Comp_Type
));
1279 Initialization_Warning
(T
);
1284 Initialization_Warning
(T
);
1288 Aggr
:= Make_Aggregate
(Loc
, No_List
, New_List
);
1289 Set_Etype
(Aggr
, T
);
1290 Set_Aggregate_Bounds
(Aggr
,
1292 Low_Bound
=> New_Copy
(Lo
),
1293 High_Bound
=> New_Copy
(Hi
)));
1294 Set_Parent
(Aggr
, Parent
(Proc
));
1296 Append_To
(Component_Associations
(Aggr
),
1297 Make_Component_Association
(Loc
,
1301 Low_Bound
=> New_Copy
(Lo
),
1302 High_Bound
=> New_Copy
(Hi
))),
1303 Expression
=> Expr
));
1305 if Static_Array_Aggregate
(Aggr
) then
1308 Initialization_Warning
(T
);
1311 end Build_Equivalent_Array_Aggregate
;
1313 ---------------------------------------
1314 -- Build_Equivalent_Record_Aggregate --
1315 ---------------------------------------
1317 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
is
1320 Comp_Type
: Entity_Id
;
1322 -- Start of processing for Build_Equivalent_Record_Aggregate
1325 if not Is_Record_Type
(T
)
1326 or else Has_Discriminants
(T
)
1327 or else Is_Limited_Type
(T
)
1328 or else Has_Non_Standard_Rep
(T
)
1330 Initialization_Warning
(T
);
1334 Comp
:= First_Component
(T
);
1336 -- A null record needs no warning
1342 while Present
(Comp
) loop
1344 -- Array components are acceptable if initialized by a positional
1345 -- aggregate with static components.
1347 if Is_Array_Type
(Etype
(Comp
)) then
1348 Comp_Type
:= Component_Type
(Etype
(Comp
));
1350 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1351 or else No
(Expression
(Parent
(Comp
)))
1352 or else Nkind
(Expression
(Parent
(Comp
))) /= N_Aggregate
1354 Initialization_Warning
(T
);
1357 elsif Is_Scalar_Type
(Component_Type
(Etype
(Comp
)))
1359 (not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1361 not Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
)))
1363 Initialization_Warning
(T
);
1367 not Static_Array_Aggregate
(Expression
(Parent
(Comp
)))
1369 Initialization_Warning
(T
);
1373 elsif Is_Scalar_Type
(Etype
(Comp
)) then
1374 Comp_Type
:= Etype
(Comp
);
1376 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1377 or else No
(Expression
(Parent
(Comp
)))
1378 or else not Compile_Time_Known_Value
(Expression
(Parent
(Comp
)))
1379 or else not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1381 Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
))
1383 Initialization_Warning
(T
);
1387 -- For now, other types are excluded
1390 Initialization_Warning
(T
);
1394 Next_Component
(Comp
);
1397 -- All components have static initialization. Build positional aggregate
1398 -- from the given expressions or defaults.
1400 Agg
:= Make_Aggregate
(Sloc
(T
), New_List
, New_List
);
1401 Set_Parent
(Agg
, Parent
(T
));
1403 Comp
:= First_Component
(T
);
1404 while Present
(Comp
) loop
1406 (New_Copy_Tree
(Expression
(Parent
(Comp
))), Expressions
(Agg
));
1407 Next_Component
(Comp
);
1410 Analyze_And_Resolve
(Agg
, T
);
1412 end Build_Equivalent_Record_Aggregate
;
1414 -------------------------------
1415 -- Build_Initialization_Call --
1416 -------------------------------
1418 -- References to a discriminant inside the record type declaration can
1419 -- appear either in the subtype_indication to constrain a record or an
1420 -- array, or as part of a larger expression given for the initial value
1421 -- of a component. In both of these cases N appears in the record
1422 -- initialization procedure and needs to be replaced by the formal
1423 -- parameter of the initialization procedure which corresponds to that
1426 -- In the example below, references to discriminants D1 and D2 in proc_1
1427 -- are replaced by references to formals with the same name
1430 -- A similar replacement is done for calls to any record initialization
1431 -- procedure for any components that are themselves of a record type.
1433 -- type R (D1, D2 : Integer) is record
1434 -- X : Integer := F * D1;
1435 -- Y : Integer := F * D2;
1438 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1442 -- Out_2.X := F * D1;
1443 -- Out_2.Y := F * D2;
1446 function Build_Initialization_Call
1450 In_Init_Proc
: Boolean := False;
1451 Enclos_Type
: Entity_Id
:= Empty
;
1452 Discr_Map
: Elist_Id
:= New_Elmt_List
;
1453 With_Default_Init
: Boolean := False;
1454 Constructor_Ref
: Node_Id
:= Empty
) return List_Id
1456 Res
: constant List_Id
:= New_List
;
1462 First_Arg
: Node_Id
;
1463 Full_Init_Type
: Entity_Id
;
1464 Full_Type
: Entity_Id
;
1465 Init_Type
: Entity_Id
;
1469 pragma Assert
(Constructor_Ref
= Empty
1470 or else Is_CPP_Constructor_Call
(Constructor_Ref
));
1472 if No
(Constructor_Ref
) then
1473 Proc
:= Base_Init_Proc
(Typ
);
1475 Proc
:= Base_Init_Proc
(Typ
, Entity
(Name
(Constructor_Ref
)));
1478 pragma Assert
(Present
(Proc
));
1479 Init_Type
:= Etype
(First_Formal
(Proc
));
1480 Full_Init_Type
:= Underlying_Type
(Init_Type
);
1482 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1483 -- is active (in which case we make the call anyway, since in the
1484 -- actual compiled client it may be non null).
1485 -- Also nothing to do for value types.
1487 if (Is_Null_Init_Proc
(Proc
) and then not Init_Or_Norm_Scalars
)
1488 or else Is_Value_Type
(Typ
)
1490 (Is_Array_Type
(Typ
) and then Is_Value_Type
(Component_Type
(Typ
)))
1495 -- Use the [underlying] full view when dealing with a private type. This
1496 -- may require several steps depending on derivations.
1500 if Is_Private_Type
(Full_Type
) then
1501 if Present
(Full_View
(Full_Type
)) then
1502 Full_Type
:= Full_View
(Full_Type
);
1504 elsif Present
(Underlying_Full_View
(Full_Type
)) then
1505 Full_Type
:= Underlying_Full_View
(Full_Type
);
1507 -- When a private type acts as a generic actual and lacks a full
1508 -- view, use the base type.
1510 elsif Is_Generic_Actual_Type
(Full_Type
) then
1511 Full_Type
:= Base_Type
(Full_Type
);
1513 -- The loop has recovered the [underlying] full view, stop the
1520 -- The type is not private, nothing to do
1527 -- If Typ is derived, the procedure is the initialization procedure for
1528 -- the root type. Wrap the argument in an conversion to make it type
1529 -- honest. Actually it isn't quite type honest, because there can be
1530 -- conflicts of views in the private type case. That is why we set
1531 -- Conversion_OK in the conversion node.
1533 if (Is_Record_Type
(Typ
)
1534 or else Is_Array_Type
(Typ
)
1535 or else Is_Private_Type
(Typ
))
1536 and then Init_Type
/= Base_Type
(Typ
)
1538 First_Arg
:= OK_Convert_To
(Etype
(Init_Type
), Id_Ref
);
1539 Set_Etype
(First_Arg
, Init_Type
);
1542 First_Arg
:= Id_Ref
;
1545 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Typ
));
1547 -- In the tasks case, add _Master as the value of the _Master parameter
1548 -- and _Chain as the value of the _Chain parameter. At the outer level,
1549 -- these will be variables holding the corresponding values obtained
1550 -- from GNARL. At inner levels, they will be the parameters passed down
1551 -- through the outer routines.
1553 if Has_Task
(Full_Type
) then
1554 if Restriction_Active
(No_Task_Hierarchy
) then
1556 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1558 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1561 -- Add _Chain (not done for sequential elaboration policy, see
1562 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1564 if Partition_Elaboration_Policy
/= 'S' then
1565 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1568 -- Ada 2005 (AI-287): In case of default initialized components
1569 -- with tasks, we generate a null string actual parameter.
1570 -- This is just a workaround that must be improved later???
1572 if With_Default_Init
then
1574 Make_String_Literal
(Loc
,
1579 Build_Task_Image_Decls
(Loc
, Id_Ref
, Enclos_Type
, In_Init_Proc
);
1580 Decl
:= Last
(Decls
);
1583 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
));
1584 Append_List
(Decls
, Res
);
1592 -- Add discriminant values if discriminants are present
1594 if Has_Discriminants
(Full_Init_Type
) then
1595 Discr
:= First_Discriminant
(Full_Init_Type
);
1596 while Present
(Discr
) loop
1598 -- If this is a discriminated concurrent type, the init_proc
1599 -- for the corresponding record is being called. Use that type
1600 -- directly to find the discriminant value, to handle properly
1601 -- intervening renamed discriminants.
1604 T
: Entity_Id
:= Full_Type
;
1607 if Is_Protected_Type
(T
) then
1608 T
:= Corresponding_Record_Type
(T
);
1612 Get_Discriminant_Value
(
1615 Discriminant_Constraint
(Full_Type
));
1618 -- If the target has access discriminants, and is constrained by
1619 -- an access to the enclosing construct, i.e. a current instance,
1620 -- replace the reference to the type by a reference to the object.
1622 if Nkind
(Arg
) = N_Attribute_Reference
1623 and then Is_Access_Type
(Etype
(Arg
))
1624 and then Is_Entity_Name
(Prefix
(Arg
))
1625 and then Is_Type
(Entity
(Prefix
(Arg
)))
1628 Make_Attribute_Reference
(Loc
,
1629 Prefix
=> New_Copy
(Prefix
(Id_Ref
)),
1630 Attribute_Name
=> Name_Unrestricted_Access
);
1632 elsif In_Init_Proc
then
1634 -- Replace any possible references to the discriminant in the
1635 -- call to the record initialization procedure with references
1636 -- to the appropriate formal parameter.
1638 if Nkind
(Arg
) = N_Identifier
1639 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1641 Arg
:= New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
);
1643 -- Otherwise make a copy of the default expression. Note that
1644 -- we use the current Sloc for this, because we do not want the
1645 -- call to appear to be at the declaration point. Within the
1646 -- expression, replace discriminants with their discriminals.
1650 New_Copy_Tree
(Arg
, Map
=> Discr_Map
, New_Sloc
=> Loc
);
1654 if Is_Constrained
(Full_Type
) then
1655 Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
1657 -- The constraints come from the discriminant default exps,
1658 -- they must be reevaluated, so we use New_Copy_Tree but we
1659 -- ensure the proper Sloc (for any embedded calls).
1661 Arg
:= New_Copy_Tree
(Arg
, New_Sloc
=> Loc
);
1665 -- Ada 2005 (AI-287): In case of default initialized components,
1666 -- if the component is constrained with a discriminant of the
1667 -- enclosing type, we need to generate the corresponding selected
1668 -- component node to access the discriminant value. In other cases
1669 -- this is not required, either because we are inside the init
1670 -- proc and we use the corresponding formal, or else because the
1671 -- component is constrained by an expression.
1673 if With_Default_Init
1674 and then Nkind
(Id_Ref
) = N_Selected_Component
1675 and then Nkind
(Arg
) = N_Identifier
1676 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1679 Make_Selected_Component
(Loc
,
1680 Prefix
=> New_Copy_Tree
(Prefix
(Id_Ref
)),
1681 Selector_Name
=> Arg
));
1683 Append_To
(Args
, Arg
);
1686 Next_Discriminant
(Discr
);
1690 -- If this is a call to initialize the parent component of a derived
1691 -- tagged type, indicate that the tag should not be set in the parent.
1693 if Is_Tagged_Type
(Full_Init_Type
)
1694 and then not Is_CPP_Class
(Full_Init_Type
)
1695 and then Nkind
(Id_Ref
) = N_Selected_Component
1696 and then Chars
(Selector_Name
(Id_Ref
)) = Name_uParent
1698 Append_To
(Args
, New_Occurrence_Of
(Standard_False
, Loc
));
1700 elsif Present
(Constructor_Ref
) then
1701 Append_List_To
(Args
,
1702 New_Copy_List
(Parameter_Associations
(Constructor_Ref
)));
1706 Make_Procedure_Call_Statement
(Loc
,
1707 Name
=> New_Occurrence_Of
(Proc
, Loc
),
1708 Parameter_Associations
=> Args
));
1710 if Needs_Finalization
(Typ
)
1711 and then Nkind
(Id_Ref
) = N_Selected_Component
1713 if Chars
(Selector_Name
(Id_Ref
)) /= Name_uParent
then
1716 (Obj_Ref
=> New_Copy_Tree
(First_Arg
),
1724 when RE_Not_Available
=>
1726 end Build_Initialization_Call
;
1728 ----------------------------
1729 -- Build_Record_Init_Proc --
1730 ----------------------------
1732 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
) is
1733 Decls
: constant List_Id
:= New_List
;
1734 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
1735 Loc
: constant Source_Ptr
:= Sloc
(Rec_Ent
);
1737 Proc_Id
: Entity_Id
;
1738 Rec_Type
: Entity_Id
;
1739 Set_Tag
: Entity_Id
:= Empty
;
1741 function Build_Assignment
(Id
: Entity_Id
; N
: Node_Id
) return List_Id
;
1742 -- Build an assignment statement which assigns the default expression
1743 -- to its corresponding record component if defined. The left hand side
1744 -- of the assignment is marked Assignment_OK so that initialization of
1745 -- limited private records works correctly. This routine may also build
1746 -- an adjustment call if the component is controlled.
1748 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
);
1749 -- If the record has discriminants, add assignment statements to
1750 -- Statement_List to initialize the discriminant values from the
1751 -- arguments of the initialization procedure.
1753 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
;
1754 -- Build a list representing a sequence of statements which initialize
1755 -- components of the given component list. This may involve building
1756 -- case statements for the variant parts. Append any locally declared
1757 -- objects on list Decls.
1759 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
;
1760 -- Given an untagged type-derivation that declares discriminants, e.g.
1762 -- type R (R1, R2 : Integer) is record ... end record;
1763 -- type D (D1 : Integer) is new R (1, D1);
1765 -- we make the _init_proc of D be
1767 -- procedure _init_proc (X : D; D1 : Integer) is
1769 -- _init_proc (R (X), 1, D1);
1772 -- This function builds the call statement in this _init_proc.
1774 procedure Build_CPP_Init_Procedure
;
1775 -- Build the tree corresponding to the procedure specification and body
1776 -- of the IC procedure that initializes the C++ part of the dispatch
1777 -- table of an Ada tagged type that is a derivation of a CPP type.
1778 -- Install it as the CPP_Init TSS.
1780 procedure Build_Init_Procedure
;
1781 -- Build the tree corresponding to the procedure specification and body
1782 -- of the initialization procedure and install it as the _init TSS.
1784 procedure Build_Offset_To_Top_Functions
;
1785 -- Ada 2005 (AI-251): Build the tree corresponding to the procedure spec
1786 -- and body of Offset_To_Top, a function used in conjuction with types
1787 -- having secondary dispatch tables.
1789 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
);
1790 -- Add range checks to components of discriminated records. S is a
1791 -- subtype indication of a record component. Check_List is a list
1792 -- to which the check actions are appended.
1794 function Component_Needs_Simple_Initialization
1795 (T
: Entity_Id
) return Boolean;
1796 -- Determine if a component needs simple initialization, given its type
1797 -- T. This routine is the same as Needs_Simple_Initialization except for
1798 -- components of type Tag and Interface_Tag. These two access types do
1799 -- not require initialization since they are explicitly initialized by
1802 function Parent_Subtype_Renaming_Discrims
return Boolean;
1803 -- Returns True for base types N that rename discriminants, else False
1805 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean;
1806 -- Determine whether a record initialization procedure needs to be
1807 -- generated for the given record type.
1809 ----------------------
1810 -- Build_Assignment --
1811 ----------------------
1813 function Build_Assignment
(Id
: Entity_Id
; N
: Node_Id
) return List_Id
is
1814 N_Loc
: constant Source_Ptr
:= Sloc
(N
);
1815 Typ
: constant Entity_Id
:= Underlying_Type
(Etype
(Id
));
1817 Kind
: Node_Kind
:= Nkind
(N
);
1823 Make_Selected_Component
(N_Loc
,
1824 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1825 Selector_Name
=> New_Occurrence_Of
(Id
, N_Loc
));
1826 Set_Assignment_OK
(Lhs
);
1828 -- Case of an access attribute applied to the current instance.
1829 -- Replace the reference to the type by a reference to the actual
1830 -- object. (Note that this handles the case of the top level of
1831 -- the expression being given by such an attribute, but does not
1832 -- cover uses nested within an initial value expression. Nested
1833 -- uses are unlikely to occur in practice, but are theoretically
1834 -- possible.) It is not clear how to handle them without fully
1835 -- traversing the expression. ???
1837 if Kind
= N_Attribute_Reference
1838 and then Nam_In
(Attribute_Name
(N
), Name_Unchecked_Access
,
1839 Name_Unrestricted_Access
)
1840 and then Is_Entity_Name
(Prefix
(N
))
1841 and then Is_Type
(Entity
(Prefix
(N
)))
1842 and then Entity
(Prefix
(N
)) = Rec_Type
1845 Make_Attribute_Reference
(N_Loc
,
1847 Make_Identifier
(N_Loc
, Name_uInit
),
1848 Attribute_Name
=> Name_Unrestricted_Access
);
1851 -- Take a copy of Exp to ensure that later copies of this component
1852 -- declaration in derived types see the original tree, not a node
1853 -- rewritten during expansion of the init_proc. If the copy contains
1854 -- itypes, the scope of the new itypes is the init_proc being built.
1856 Exp
:= New_Copy_Tree
(Exp
, New_Scope
=> Proc_Id
);
1859 Make_Assignment_Statement
(Loc
,
1861 Expression
=> Exp
));
1863 Set_No_Ctrl_Actions
(First
(Res
));
1865 -- Adjust the tag if tagged (because of possible view conversions).
1866 -- Suppress the tag adjustment when VM_Target because VM tags are
1867 -- represented implicitly in objects.
1869 if Is_Tagged_Type
(Typ
) and then Tagged_Type_Expansion
then
1871 Make_Assignment_Statement
(N_Loc
,
1873 Make_Selected_Component
(N_Loc
,
1875 New_Copy_Tree
(Lhs
, New_Scope
=> Proc_Id
),
1877 New_Occurrence_Of
(First_Tag_Component
(Typ
), N_Loc
)),
1880 Unchecked_Convert_To
(RTE
(RE_Tag
),
1884 (Access_Disp_Table
(Underlying_Type
(Typ
)))),
1888 -- Adjust the component if controlled except if it is an aggregate
1889 -- that will be expanded inline.
1891 if Kind
= N_Qualified_Expression
then
1892 Kind
:= Nkind
(Expression
(N
));
1895 if Needs_Finalization
(Typ
)
1896 and then not (Nkind_In
(Kind
, N_Aggregate
, N_Extension_Aggregate
))
1897 and then not Is_Limited_View
(Typ
)
1901 (Obj_Ref
=> New_Copy_Tree
(Lhs
),
1902 Typ
=> Etype
(Id
)));
1908 when RE_Not_Available
=>
1910 end Build_Assignment
;
1912 ------------------------------------
1913 -- Build_Discriminant_Assignments --
1914 ------------------------------------
1916 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
) is
1917 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Rec_Type
);
1922 if Has_Discriminants
(Rec_Type
)
1923 and then not Is_Unchecked_Union
(Rec_Type
)
1925 D
:= First_Discriminant
(Rec_Type
);
1926 while Present
(D
) loop
1928 -- Don't generate the assignment for discriminants in derived
1929 -- tagged types if the discriminant is a renaming of some
1930 -- ancestor discriminant. This initialization will be done
1931 -- when initializing the _parent field of the derived record.
1934 and then Present
(Corresponding_Discriminant
(D
))
1940 Append_List_To
(Statement_List
,
1941 Build_Assignment
(D
,
1942 New_Occurrence_Of
(Discriminal
(D
), D_Loc
)));
1945 Next_Discriminant
(D
);
1948 end Build_Discriminant_Assignments
;
1950 --------------------------
1951 -- Build_Init_Call_Thru --
1952 --------------------------
1954 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
is
1955 Parent_Proc
: constant Entity_Id
:=
1956 Base_Init_Proc
(Etype
(Rec_Type
));
1958 Parent_Type
: constant Entity_Id
:=
1959 Etype
(First_Formal
(Parent_Proc
));
1961 Uparent_Type
: constant Entity_Id
:=
1962 Underlying_Type
(Parent_Type
);
1964 First_Discr_Param
: Node_Id
;
1968 First_Arg
: Node_Id
;
1969 Parent_Discr
: Entity_Id
;
1973 -- First argument (_Init) is the object to be initialized.
1974 -- ??? not sure where to get a reasonable Loc for First_Arg
1977 OK_Convert_To
(Parent_Type
,
1979 (Defining_Identifier
(First
(Parameters
)), Loc
));
1981 Set_Etype
(First_Arg
, Parent_Type
);
1983 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Rec_Type
));
1985 -- In the tasks case,
1986 -- add _Master as the value of the _Master parameter
1987 -- add _Chain as the value of the _Chain parameter.
1988 -- add _Task_Name as the value of the _Task_Name parameter.
1989 -- At the outer level, these will be variables holding the
1990 -- corresponding values obtained from GNARL or the expander.
1992 -- At inner levels, they will be the parameters passed down through
1993 -- the outer routines.
1995 First_Discr_Param
:= Next
(First
(Parameters
));
1997 if Has_Task
(Rec_Type
) then
1998 if Restriction_Active
(No_Task_Hierarchy
) then
2000 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
2002 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
2005 -- Add _Chain (not done for sequential elaboration policy, see
2006 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
2008 if Partition_Elaboration_Policy
/= 'S' then
2009 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
2012 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
2013 First_Discr_Param
:= Next
(Next
(Next
(First_Discr_Param
)));
2016 -- Append discriminant values
2018 if Has_Discriminants
(Uparent_Type
) then
2019 pragma Assert
(not Is_Tagged_Type
(Uparent_Type
));
2021 Parent_Discr
:= First_Discriminant
(Uparent_Type
);
2022 while Present
(Parent_Discr
) loop
2024 -- Get the initial value for this discriminant
2025 -- ??? needs to be cleaned up to use parent_Discr_Constr
2029 Discr
: Entity_Id
:=
2030 First_Stored_Discriminant
(Uparent_Type
);
2032 Discr_Value
: Elmt_Id
:=
2033 First_Elmt
(Stored_Constraint
(Rec_Type
));
2036 while Original_Record_Component
(Parent_Discr
) /= Discr
loop
2037 Next_Stored_Discriminant
(Discr
);
2038 Next_Elmt
(Discr_Value
);
2041 Arg
:= Node
(Discr_Value
);
2044 -- Append it to the list
2046 if Nkind
(Arg
) = N_Identifier
2047 and then Ekind
(Entity
(Arg
)) = E_Discriminant
2050 New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
));
2052 -- Case of access discriminants. We replace the reference
2053 -- to the type by a reference to the actual object.
2055 -- Is above comment right??? Use of New_Copy below seems mighty
2059 Append_To
(Args
, New_Copy
(Arg
));
2062 Next_Discriminant
(Parent_Discr
);
2068 Make_Procedure_Call_Statement
(Loc
,
2070 New_Occurrence_Of
(Parent_Proc
, Loc
),
2071 Parameter_Associations
=> Args
));
2074 end Build_Init_Call_Thru
;
2076 -----------------------------------
2077 -- Build_Offset_To_Top_Functions --
2078 -----------------------------------
2080 procedure Build_Offset_To_Top_Functions
is
2082 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
);
2084 -- function Fxx (O : Address) return Storage_Offset is
2085 -- type Acc is access all <Typ>;
2087 -- return Acc!(O).Iface_Comp'Position;
2090 ----------------------------------
2091 -- Build_Offset_To_Top_Function --
2092 ----------------------------------
2094 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
) is
2095 Body_Node
: Node_Id
;
2096 Func_Id
: Entity_Id
;
2097 Spec_Node
: Node_Id
;
2098 Acc_Type
: Entity_Id
;
2101 Func_Id
:= Make_Temporary
(Loc
, 'F');
2102 Set_DT_Offset_To_Top_Func
(Iface_Comp
, Func_Id
);
2105 -- function Fxx (O : in Rec_Typ) return Storage_Offset;
2107 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
2108 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
2109 Set_Parameter_Specifications
(Spec_Node
, New_List
(
2110 Make_Parameter_Specification
(Loc
,
2111 Defining_Identifier
=>
2112 Make_Defining_Identifier
(Loc
, Name_uO
),
2115 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))));
2116 Set_Result_Definition
(Spec_Node
,
2117 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
2120 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2122 -- return O.Iface_Comp'Position;
2125 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2126 Set_Specification
(Body_Node
, Spec_Node
);
2128 Acc_Type
:= Make_Temporary
(Loc
, 'T');
2129 Set_Declarations
(Body_Node
, New_List
(
2130 Make_Full_Type_Declaration
(Loc
,
2131 Defining_Identifier
=> Acc_Type
,
2133 Make_Access_To_Object_Definition
(Loc
,
2134 All_Present
=> True,
2135 Null_Exclusion_Present
=> False,
2136 Constant_Present
=> False,
2137 Subtype_Indication
=>
2138 New_Occurrence_Of
(Rec_Type
, Loc
)))));
2140 Set_Handled_Statement_Sequence
(Body_Node
,
2141 Make_Handled_Sequence_Of_Statements
(Loc
,
2142 Statements
=> New_List
(
2143 Make_Simple_Return_Statement
(Loc
,
2145 Make_Attribute_Reference
(Loc
,
2147 Make_Selected_Component
(Loc
,
2149 Unchecked_Convert_To
(Acc_Type
,
2150 Make_Identifier
(Loc
, Name_uO
)),
2152 New_Occurrence_Of
(Iface_Comp
, Loc
)),
2153 Attribute_Name
=> Name_Position
)))));
2155 Set_Ekind
(Func_Id
, E_Function
);
2156 Set_Mechanism
(Func_Id
, Default_Mechanism
);
2157 Set_Is_Internal
(Func_Id
, True);
2159 if not Debug_Generated_Code
then
2160 Set_Debug_Info_Off
(Func_Id
);
2163 Analyze
(Body_Node
);
2165 Append_Freeze_Action
(Rec_Type
, Body_Node
);
2166 end Build_Offset_To_Top_Function
;
2170 Iface_Comp
: Node_Id
;
2171 Iface_Comp_Elmt
: Elmt_Id
;
2172 Ifaces_Comp_List
: Elist_Id
;
2174 -- Start of processing for Build_Offset_To_Top_Functions
2177 -- Offset_To_Top_Functions are built only for derivations of types
2178 -- with discriminants that cover interface types.
2179 -- Nothing is needed either in case of virtual machines, since
2180 -- interfaces are handled directly by the VM.
2182 if not Is_Tagged_Type
(Rec_Type
)
2183 or else Etype
(Rec_Type
) = Rec_Type
2184 or else not Has_Discriminants
(Etype
(Rec_Type
))
2185 or else not Tagged_Type_Expansion
2190 Collect_Interface_Components
(Rec_Type
, Ifaces_Comp_List
);
2192 -- For each interface type with secondary dispatch table we generate
2193 -- the Offset_To_Top_Functions (required to displace the pointer in
2194 -- interface conversions)
2196 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
2197 while Present
(Iface_Comp_Elmt
) loop
2198 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
2199 pragma Assert
(Is_Interface
(Related_Type
(Iface_Comp
)));
2201 -- If the interface is a parent of Rec_Type it shares the primary
2202 -- dispatch table and hence there is no need to build the function
2204 if not Is_Ancestor
(Related_Type
(Iface_Comp
), Rec_Type
,
2205 Use_Full_View
=> True)
2207 Build_Offset_To_Top_Function
(Iface_Comp
);
2210 Next_Elmt
(Iface_Comp_Elmt
);
2212 end Build_Offset_To_Top_Functions
;
2214 ------------------------------
2215 -- Build_CPP_Init_Procedure --
2216 ------------------------------
2218 procedure Build_CPP_Init_Procedure
is
2219 Body_Node
: Node_Id
;
2220 Body_Stmts
: List_Id
;
2221 Flag_Id
: Entity_Id
;
2222 Handled_Stmt_Node
: Node_Id
;
2223 Init_Tags_List
: List_Id
;
2224 Proc_Id
: Entity_Id
;
2225 Proc_Spec_Node
: Node_Id
;
2228 -- Check cases requiring no IC routine
2230 if not Is_CPP_Class
(Root_Type
(Rec_Type
))
2231 or else Is_CPP_Class
(Rec_Type
)
2232 or else CPP_Num_Prims
(Rec_Type
) = 0
2233 or else not Tagged_Type_Expansion
2234 or else No_Run_Time_Mode
2241 -- Flag : Boolean := False;
2243 -- procedure Typ_IC is
2246 -- Copy C++ dispatch table slots from parent
2247 -- Update C++ slots of overridden primitives
2251 Flag_Id
:= Make_Temporary
(Loc
, 'F');
2253 Append_Freeze_Action
(Rec_Type
,
2254 Make_Object_Declaration
(Loc
,
2255 Defining_Identifier
=> Flag_Id
,
2256 Object_Definition
=>
2257 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2259 New_Occurrence_Of
(Standard_True
, Loc
)));
2261 Body_Stmts
:= New_List
;
2262 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2264 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2267 Make_Defining_Identifier
(Loc
,
2268 Chars
=> Make_TSS_Name
(Rec_Type
, TSS_CPP_Init_Proc
));
2270 Set_Ekind
(Proc_Id
, E_Procedure
);
2271 Set_Is_Internal
(Proc_Id
);
2273 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2275 Set_Parameter_Specifications
(Proc_Spec_Node
, New_List
);
2276 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2277 Set_Declarations
(Body_Node
, New_List
);
2279 Init_Tags_List
:= Build_Inherit_CPP_Prims
(Rec_Type
);
2281 Append_To
(Init_Tags_List
,
2282 Make_Assignment_Statement
(Loc
,
2284 New_Occurrence_Of
(Flag_Id
, Loc
),
2286 New_Occurrence_Of
(Standard_False
, Loc
)));
2288 Append_To
(Body_Stmts
,
2289 Make_If_Statement
(Loc
,
2290 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
2291 Then_Statements
=> Init_Tags_List
));
2293 Handled_Stmt_Node
:=
2294 New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2295 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2296 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2297 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2299 if not Debug_Generated_Code
then
2300 Set_Debug_Info_Off
(Proc_Id
);
2303 -- Associate CPP_Init_Proc with type
2305 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2306 end Build_CPP_Init_Procedure
;
2308 --------------------------
2309 -- Build_Init_Procedure --
2310 --------------------------
2312 procedure Build_Init_Procedure
is
2313 Body_Stmts
: List_Id
;
2314 Body_Node
: Node_Id
;
2315 Handled_Stmt_Node
: Node_Id
;
2316 Init_Tags_List
: List_Id
;
2317 Parameters
: List_Id
;
2318 Proc_Spec_Node
: Node_Id
;
2319 Record_Extension_Node
: Node_Id
;
2322 Body_Stmts
:= New_List
;
2323 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2324 Set_Ekind
(Proc_Id
, E_Procedure
);
2326 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2327 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2329 Parameters
:= Init_Formals
(Rec_Type
);
2330 Append_List_To
(Parameters
,
2331 Build_Discriminant_Formals
(Rec_Type
, True));
2333 -- For tagged types, we add a flag to indicate whether the routine
2334 -- is called to initialize a parent component in the init_proc of
2335 -- a type extension. If the flag is false, we do not set the tag
2336 -- because it has been set already in the extension.
2338 if Is_Tagged_Type
(Rec_Type
) then
2339 Set_Tag
:= Make_Temporary
(Loc
, 'P');
2341 Append_To
(Parameters
,
2342 Make_Parameter_Specification
(Loc
,
2343 Defining_Identifier
=> Set_Tag
,
2345 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2347 New_Occurrence_Of
(Standard_True
, Loc
)));
2350 Set_Parameter_Specifications
(Proc_Spec_Node
, Parameters
);
2351 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2352 Set_Declarations
(Body_Node
, Decls
);
2354 -- N is a Derived_Type_Definition that renames the parameters of the
2355 -- ancestor type. We initialize it by expanding our discriminants and
2356 -- call the ancestor _init_proc with a type-converted object.
2358 if Parent_Subtype_Renaming_Discrims
then
2359 Append_List_To
(Body_Stmts
, Build_Init_Call_Thru
(Parameters
));
2361 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
2362 Build_Discriminant_Assignments
(Body_Stmts
);
2364 if not Null_Present
(Type_Definition
(N
)) then
2365 Append_List_To
(Body_Stmts
,
2366 Build_Init_Statements
(Component_List
(Type_Definition
(N
))));
2369 -- N is a Derived_Type_Definition with a possible non-empty
2370 -- extension. The initialization of a type extension consists in the
2371 -- initialization of the components in the extension.
2374 Build_Discriminant_Assignments
(Body_Stmts
);
2376 Record_Extension_Node
:=
2377 Record_Extension_Part
(Type_Definition
(N
));
2379 if not Null_Present
(Record_Extension_Node
) then
2381 Stmts
: constant List_Id
:=
2382 Build_Init_Statements
(
2383 Component_List
(Record_Extension_Node
));
2386 -- The parent field must be initialized first because the
2387 -- offset of the new discriminants may depend on it. This is
2388 -- not needed if the parent is an interface type because in
2389 -- such case the initialization of the _parent field was not
2392 if not Is_Interface
(Etype
(Rec_Ent
)) then
2394 Parent_IP
: constant Name_Id
:=
2395 Make_Init_Proc_Name
(Etype
(Rec_Ent
));
2401 -- Look for a call to the parent IP at the beginning
2402 -- of Stmts associated with the record extension
2404 Stmt
:= First
(Stmts
);
2406 while Present
(Stmt
) loop
2407 if Nkind
(Stmt
) = N_Procedure_Call_Statement
2408 and then Chars
(Name
(Stmt
)) = Parent_IP
2417 -- If found then move it to the beginning of the
2418 -- statements of this IP routine
2420 if Present
(IP_Call
) then
2421 IP_Stmts
:= New_List
;
2423 Stmt
:= Remove_Head
(Stmts
);
2424 Append_To
(IP_Stmts
, Stmt
);
2425 exit when Stmt
= IP_Call
;
2428 Prepend_List_To
(Body_Stmts
, IP_Stmts
);
2433 Append_List_To
(Body_Stmts
, Stmts
);
2438 -- Add here the assignment to instantiate the Tag
2440 -- The assignment corresponds to the code:
2442 -- _Init._Tag := Typ'Tag;
2444 -- Suppress the tag assignment when VM_Target because VM tags are
2445 -- represented implicitly in objects. It is also suppressed in case
2446 -- of CPP_Class types because in this case the tag is initialized in
2449 if Is_Tagged_Type
(Rec_Type
)
2450 and then Tagged_Type_Expansion
2451 and then not No_Run_Time_Mode
2453 -- Case 1: Ada tagged types with no CPP ancestor. Set the tags of
2454 -- the actual object and invoke the IP of the parent (in this
2455 -- order). The tag must be initialized before the call to the IP
2456 -- of the parent and the assignments to other components because
2457 -- the initial value of the components may depend on the tag (eg.
2458 -- through a dispatching operation on an access to the current
2459 -- type). The tag assignment is not done when initializing the
2460 -- parent component of a type extension, because in that case the
2461 -- tag is set in the extension.
2463 if not Is_CPP_Class
(Root_Type
(Rec_Type
)) then
2465 -- Initialize the primary tag component
2467 Init_Tags_List
:= New_List
(
2468 Make_Assignment_Statement
(Loc
,
2470 Make_Selected_Component
(Loc
,
2471 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2474 (First_Tag_Component
(Rec_Type
), Loc
)),
2478 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2480 -- Ada 2005 (AI-251): Initialize the secondary tags components
2481 -- located at fixed positions (tags whose position depends on
2482 -- variable size components are initialized later ---see below)
2484 if Ada_Version
>= Ada_2005
2485 and then not Is_Interface
(Rec_Type
)
2486 and then Has_Interfaces
(Rec_Type
)
2490 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2491 Stmts_List
=> Init_Tags_List
,
2492 Fixed_Comps
=> True,
2493 Variable_Comps
=> False);
2496 Prepend_To
(Body_Stmts
,
2497 Make_If_Statement
(Loc
,
2498 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2499 Then_Statements
=> Init_Tags_List
));
2501 -- Case 2: CPP type. The imported C++ constructor takes care of
2502 -- tags initialization. No action needed here because the IP
2503 -- is built by Set_CPP_Constructors; in this case the IP is a
2504 -- wrapper that invokes the C++ constructor and copies the C++
2505 -- tags locally. Done to inherit the C++ slots in Ada derivations
2508 elsif Is_CPP_Class
(Rec_Type
) then
2509 pragma Assert
(False);
2512 -- Case 3: Combined hierarchy containing C++ types and Ada tagged
2513 -- type derivations. Derivations of imported C++ classes add a
2514 -- complication, because we cannot inhibit tag setting in the
2515 -- constructor for the parent. Hence we initialize the tag after
2516 -- the call to the parent IP (that is, in reverse order compared
2517 -- with pure Ada hierarchies ---see comment on case 1).
2520 -- Initialize the primary tag
2522 Init_Tags_List
:= New_List
(
2523 Make_Assignment_Statement
(Loc
,
2525 Make_Selected_Component
(Loc
,
2526 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2529 (First_Tag_Component
(Rec_Type
), Loc
)),
2533 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2535 -- Ada 2005 (AI-251): Initialize the secondary tags components
2536 -- located at fixed positions (tags whose position depends on
2537 -- variable size components are initialized later ---see below)
2539 if Ada_Version
>= Ada_2005
2540 and then not Is_Interface
(Rec_Type
)
2541 and then Has_Interfaces
(Rec_Type
)
2545 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2546 Stmts_List
=> Init_Tags_List
,
2547 Fixed_Comps
=> True,
2548 Variable_Comps
=> False);
2551 -- Initialize the tag component after invocation of parent IP.
2554 -- parent_IP(_init.parent); // Invokes the C++ constructor
2555 -- [ typIC; ] // Inherit C++ slots from parent
2562 -- Search for the call to the IP of the parent. We assume
2563 -- that the first init_proc call is for the parent.
2565 Ins_Nod
:= First
(Body_Stmts
);
2566 while Present
(Next
(Ins_Nod
))
2567 and then (Nkind
(Ins_Nod
) /= N_Procedure_Call_Statement
2568 or else not Is_Init_Proc
(Name
(Ins_Nod
)))
2573 -- The IC routine copies the inherited slots of the C+ part
2574 -- of the dispatch table from the parent and updates the
2575 -- overridden C++ slots.
2577 if CPP_Num_Prims
(Rec_Type
) > 0 then
2579 Init_DT
: Entity_Id
;
2583 Init_DT
:= CPP_Init_Proc
(Rec_Type
);
2584 pragma Assert
(Present
(Init_DT
));
2587 Make_Procedure_Call_Statement
(Loc
,
2588 New_Occurrence_Of
(Init_DT
, Loc
));
2589 Insert_After
(Ins_Nod
, New_Nod
);
2591 -- Update location of init tag statements
2597 Insert_List_After
(Ins_Nod
, Init_Tags_List
);
2601 -- Ada 2005 (AI-251): Initialize the secondary tag components
2602 -- located at variable positions. We delay the generation of this
2603 -- code until here because the value of the attribute 'Position
2604 -- applied to variable size components of the parent type that
2605 -- depend on discriminants is only safely read at runtime after
2606 -- the parent components have been initialized.
2608 if Ada_Version
>= Ada_2005
2609 and then not Is_Interface
(Rec_Type
)
2610 and then Has_Interfaces
(Rec_Type
)
2611 and then Has_Discriminants
(Etype
(Rec_Type
))
2612 and then Is_Variable_Size_Record
(Etype
(Rec_Type
))
2614 Init_Tags_List
:= New_List
;
2618 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2619 Stmts_List
=> Init_Tags_List
,
2620 Fixed_Comps
=> False,
2621 Variable_Comps
=> True);
2623 if Is_Non_Empty_List
(Init_Tags_List
) then
2624 Append_List_To
(Body_Stmts
, Init_Tags_List
);
2629 Handled_Stmt_Node
:= New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2630 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2633 -- Deep_Finalize (_init, C1, ..., CN);
2637 and then Needs_Finalization
(Rec_Type
)
2638 and then not Is_Abstract_Type
(Rec_Type
)
2639 and then not Restriction_Active
(No_Exception_Propagation
)
2646 -- Create a local version of Deep_Finalize which has indication
2647 -- of partial initialization state.
2649 DF_Id
:= Make_Temporary
(Loc
, 'F');
2651 Append_To
(Decls
, Make_Local_Deep_Finalize
(Rec_Type
, DF_Id
));
2654 Make_Procedure_Call_Statement
(Loc
,
2655 Name
=> New_Occurrence_Of
(DF_Id
, Loc
),
2656 Parameter_Associations
=> New_List
(
2657 Make_Identifier
(Loc
, Name_uInit
),
2658 New_Occurrence_Of
(Standard_False
, Loc
)));
2660 -- Do not emit warnings related to the elaboration order when a
2661 -- controlled object is declared before the body of Finalize is
2664 Set_No_Elaboration_Check
(DF_Call
);
2666 Set_Exception_Handlers
(Handled_Stmt_Node
, New_List
(
2667 Make_Exception_Handler
(Loc
,
2668 Exception_Choices
=> New_List
(
2669 Make_Others_Choice
(Loc
)),
2670 Statements
=> New_List
(
2672 Make_Raise_Statement
(Loc
)))));
2675 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2678 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2680 if not Debug_Generated_Code
then
2681 Set_Debug_Info_Off
(Proc_Id
);
2684 -- Associate Init_Proc with type, and determine if the procedure
2685 -- is null (happens because of the Initialize_Scalars pragma case,
2686 -- where we have to generate a null procedure in case it is called
2687 -- by a client with Initialize_Scalars set). Such procedures have
2688 -- to be generated, but do not have to be called, so we mark them
2689 -- as null to suppress the call.
2691 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2693 if List_Length
(Body_Stmts
) = 1
2695 -- We must skip SCIL nodes because they may have been added to this
2696 -- list by Insert_Actions.
2698 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
2699 and then VM_Target
= No_VM
2701 -- Even though the init proc may be null at this time it might get
2702 -- some stuff added to it later by the VM backend.
2704 Set_Is_Null_Init_Proc
(Proc_Id
);
2706 end Build_Init_Procedure
;
2708 ---------------------------
2709 -- Build_Init_Statements --
2710 ---------------------------
2712 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
is
2713 Checks
: constant List_Id
:= New_List
;
2714 Actions
: List_Id
:= No_List
;
2715 Counter_Id
: Entity_Id
:= Empty
;
2716 Comp_Loc
: Source_Ptr
;
2720 Parent_Stmts
: List_Id
;
2724 procedure Increment_Counter
(Loc
: Source_Ptr
);
2725 -- Generate an "increment by one" statement for the current counter
2726 -- and append it to the list Stmts.
2728 procedure Make_Counter
(Loc
: Source_Ptr
);
2729 -- Create a new counter for the current component list. The routine
2730 -- creates a new defining Id, adds an object declaration and sets
2731 -- the Id generator for the next variant.
2733 -----------------------
2734 -- Increment_Counter --
2735 -----------------------
2737 procedure Increment_Counter
(Loc
: Source_Ptr
) is
2740 -- Counter := Counter + 1;
2743 Make_Assignment_Statement
(Loc
,
2744 Name
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2747 Left_Opnd
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2748 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
2749 end Increment_Counter
;
2755 procedure Make_Counter
(Loc
: Source_Ptr
) is
2757 -- Increment the Id generator
2759 Counter
:= Counter
+ 1;
2761 -- Create the entity and declaration
2764 Make_Defining_Identifier
(Loc
,
2765 Chars
=> New_External_Name
('C', Counter
));
2768 -- Cnn : Integer := 0;
2771 Make_Object_Declaration
(Loc
,
2772 Defining_Identifier
=> Counter_Id
,
2773 Object_Definition
=>
2774 New_Occurrence_Of
(Standard_Integer
, Loc
),
2776 Make_Integer_Literal
(Loc
, 0)));
2779 -- Start of processing for Build_Init_Statements
2782 if Null_Present
(Comp_List
) then
2783 return New_List
(Make_Null_Statement
(Loc
));
2786 Parent_Stmts
:= New_List
;
2789 -- Loop through visible declarations of task types and protected
2790 -- types moving any expanded code from the spec to the body of the
2793 if Is_Task_Record_Type
(Rec_Type
)
2794 or else Is_Protected_Record_Type
(Rec_Type
)
2797 Decl
: constant Node_Id
:=
2798 Parent
(Corresponding_Concurrent_Type
(Rec_Type
));
2804 if Is_Task_Record_Type
(Rec_Type
) then
2805 Def
:= Task_Definition
(Decl
);
2807 Def
:= Protected_Definition
(Decl
);
2810 if Present
(Def
) then
2811 N1
:= First
(Visible_Declarations
(Def
));
2812 while Present
(N1
) loop
2816 if Nkind
(N2
) in N_Statement_Other_Than_Procedure_Call
2817 or else Nkind
(N2
) in N_Raise_xxx_Error
2818 or else Nkind
(N2
) = N_Procedure_Call_Statement
2821 New_Copy_Tree
(N2
, New_Scope
=> Proc_Id
));
2822 Rewrite
(N2
, Make_Null_Statement
(Sloc
(N2
)));
2830 -- Loop through components, skipping pragmas, in 2 steps. The first
2831 -- step deals with regular components. The second step deals with
2832 -- components that have per object constraints and no explicit
2837 -- First pass : regular components
2839 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
2840 while Present
(Decl
) loop
2841 Comp_Loc
:= Sloc
(Decl
);
2843 (Subtype_Indication
(Component_Definition
(Decl
)), Checks
);
2845 Id
:= Defining_Identifier
(Decl
);
2848 -- Leave any processing of per-object constrained component for
2851 if Has_Access_Constraint
(Id
) and then No
(Expression
(Decl
)) then
2854 -- Regular component cases
2857 -- In the context of the init proc, references to discriminants
2858 -- resolve to denote the discriminals: this is where we can
2859 -- freeze discriminant dependent component subtypes.
2861 if not Is_Frozen
(Typ
) then
2862 Append_List_To
(Stmts
, Freeze_Entity
(Typ
, N
));
2865 -- Explicit initialization
2867 if Present
(Expression
(Decl
)) then
2868 if Is_CPP_Constructor_Call
(Expression
(Decl
)) then
2870 Build_Initialization_Call
2873 Make_Selected_Component
(Comp_Loc
,
2875 Make_Identifier
(Comp_Loc
, Name_uInit
),
2877 New_Occurrence_Of
(Id
, Comp_Loc
)),
2879 In_Init_Proc
=> True,
2880 Enclos_Type
=> Rec_Type
,
2881 Discr_Map
=> Discr_Map
,
2882 Constructor_Ref
=> Expression
(Decl
));
2884 Actions
:= Build_Assignment
(Id
, Expression
(Decl
));
2887 -- CPU, Dispatching_Domain, Priority and Size components are
2888 -- filled with the corresponding rep item expression of the
2889 -- concurrent type (if any).
2891 elsif Ekind
(Scope
(Id
)) = E_Record_Type
2892 and then Present
(Corresponding_Concurrent_Type
(Scope
(Id
)))
2893 and then Nam_In
(Chars
(Id
), Name_uCPU
,
2894 Name_uDispatching_Domain
,
2903 if Chars
(Id
) = Name_uCPU
then
2906 elsif Chars
(Id
) = Name_uDispatching_Domain
then
2907 Nam
:= Name_Dispatching_Domain
;
2909 elsif Chars
(Id
) = Name_uPriority
then
2910 Nam
:= Name_Priority
;
2913 -- Get the Rep Item (aspect specification, attribute
2914 -- definition clause or pragma) of the corresponding
2919 (Corresponding_Concurrent_Type
(Scope
(Id
)),
2921 Check_Parents
=> False);
2923 if Present
(Ritem
) then
2927 if Nkind
(Ritem
) = N_Pragma
then
2928 Exp
:= First
(Pragma_Argument_Associations
(Ritem
));
2930 if Nkind
(Exp
) = N_Pragma_Argument_Association
then
2931 Exp
:= Expression
(Exp
);
2934 -- Conversion for Priority expression
2936 if Nam
= Name_Priority
then
2937 if Pragma_Name
(Ritem
) = Name_Priority
2938 and then not GNAT_Mode
2940 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
2943 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
2947 -- Aspect/Attribute definition clause case
2950 Exp
:= Expression
(Ritem
);
2952 -- Conversion for Priority expression
2954 if Nam
= Name_Priority
then
2955 if Chars
(Ritem
) = Name_Priority
2956 and then not GNAT_Mode
2958 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
2961 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
2966 -- Conversion for Dispatching_Domain value
2968 if Nam
= Name_Dispatching_Domain
then
2970 Unchecked_Convert_To
2971 (RTE
(RE_Dispatching_Domain_Access
), Exp
);
2974 Actions
:= Build_Assignment
(Id
, Exp
);
2976 -- Nothing needed if no Rep Item
2983 -- Composite component with its own Init_Proc
2985 elsif not Is_Interface
(Typ
)
2986 and then Has_Non_Null_Base_Init_Proc
(Typ
)
2989 Build_Initialization_Call
2991 Make_Selected_Component
(Comp_Loc
,
2993 Make_Identifier
(Comp_Loc
, Name_uInit
),
2994 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
2996 In_Init_Proc
=> True,
2997 Enclos_Type
=> Rec_Type
,
2998 Discr_Map
=> Discr_Map
);
3000 Clean_Task_Names
(Typ
, Proc_Id
);
3002 -- Simple initialization
3004 elsif Component_Needs_Simple_Initialization
(Typ
) then
3007 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
)));
3009 -- Nothing needed for this case
3015 if Present
(Checks
) then
3016 if Chars
(Id
) = Name_uParent
then
3017 Append_List_To
(Parent_Stmts
, Checks
);
3019 Append_List_To
(Stmts
, Checks
);
3023 if Present
(Actions
) then
3024 if Chars
(Id
) = Name_uParent
then
3025 Append_List_To
(Parent_Stmts
, Actions
);
3028 Append_List_To
(Stmts
, Actions
);
3030 -- Preserve initialization state in the current counter
3032 if Needs_Finalization
(Typ
) then
3033 if No
(Counter_Id
) then
3034 Make_Counter
(Comp_Loc
);
3037 Increment_Counter
(Comp_Loc
);
3043 Next_Non_Pragma
(Decl
);
3046 -- The parent field must be initialized first because variable
3047 -- size components of the parent affect the location of all the
3050 Prepend_List_To
(Stmts
, Parent_Stmts
);
3052 -- Set up tasks and protected object support. This needs to be done
3053 -- before any component with a per-object access discriminant
3054 -- constraint, or any variant part (which may contain such
3055 -- components) is initialized, because the initialization of these
3056 -- components may reference the enclosing concurrent object.
3058 -- For a task record type, add the task create call and calls to bind
3059 -- any interrupt (signal) entries.
3061 if Is_Task_Record_Type
(Rec_Type
) then
3063 -- In the case of the restricted run time the ATCB has already
3064 -- been preallocated.
3066 if Restricted_Profile
then
3068 Make_Assignment_Statement
(Loc
,
3070 Make_Selected_Component
(Loc
,
3071 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3072 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3074 Make_Attribute_Reference
(Loc
,
3076 Make_Selected_Component
(Loc
,
3077 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3078 Selector_Name
=> Make_Identifier
(Loc
, Name_uATCB
)),
3079 Attribute_Name
=> Name_Unchecked_Access
)));
3082 Append_To
(Stmts
, Make_Task_Create_Call
(Rec_Type
));
3085 Task_Type
: constant Entity_Id
:=
3086 Corresponding_Concurrent_Type
(Rec_Type
);
3087 Task_Decl
: constant Node_Id
:= Parent
(Task_Type
);
3088 Task_Def
: constant Node_Id
:= Task_Definition
(Task_Decl
);
3089 Decl_Loc
: Source_Ptr
;
3094 if Present
(Task_Def
) then
3095 Vis_Decl
:= First
(Visible_Declarations
(Task_Def
));
3096 while Present
(Vis_Decl
) loop
3097 Decl_Loc
:= Sloc
(Vis_Decl
);
3099 if Nkind
(Vis_Decl
) = N_Attribute_Definition_Clause
then
3100 if Get_Attribute_Id
(Chars
(Vis_Decl
)) =
3103 Ent
:= Entity
(Name
(Vis_Decl
));
3105 if Ekind
(Ent
) = E_Entry
then
3107 Make_Procedure_Call_Statement
(Decl_Loc
,
3109 New_Occurrence_Of
(RTE
(
3110 RE_Bind_Interrupt_To_Entry
), Decl_Loc
),
3111 Parameter_Associations
=> New_List
(
3112 Make_Selected_Component
(Decl_Loc
,
3114 Make_Identifier
(Decl_Loc
, Name_uInit
),
3117 (Decl_Loc
, Name_uTask_Id
)),
3118 Entry_Index_Expression
3119 (Decl_Loc
, Ent
, Empty
, Task_Type
),
3120 Expression
(Vis_Decl
))));
3131 -- For a protected type, add statements generated by
3132 -- Make_Initialize_Protection.
3134 if Is_Protected_Record_Type
(Rec_Type
) then
3135 Append_List_To
(Stmts
,
3136 Make_Initialize_Protection
(Rec_Type
));
3139 -- Second pass: components with per-object constraints
3142 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3143 while Present
(Decl
) loop
3144 Comp_Loc
:= Sloc
(Decl
);
3145 Id
:= Defining_Identifier
(Decl
);
3148 if Has_Access_Constraint
(Id
)
3149 and then No
(Expression
(Decl
))
3151 if Has_Non_Null_Base_Init_Proc
(Typ
) then
3152 Append_List_To
(Stmts
,
3153 Build_Initialization_Call
(Comp_Loc
,
3154 Make_Selected_Component
(Comp_Loc
,
3156 Make_Identifier
(Comp_Loc
, Name_uInit
),
3157 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3159 In_Init_Proc
=> True,
3160 Enclos_Type
=> Rec_Type
,
3161 Discr_Map
=> Discr_Map
));
3163 Clean_Task_Names
(Typ
, Proc_Id
);
3165 -- Preserve initialization state in the current counter
3167 if Needs_Finalization
(Typ
) then
3168 if No
(Counter_Id
) then
3169 Make_Counter
(Comp_Loc
);
3172 Increment_Counter
(Comp_Loc
);
3175 elsif Component_Needs_Simple_Initialization
(Typ
) then
3176 Append_List_To
(Stmts
,
3178 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
))));
3182 Next_Non_Pragma
(Decl
);
3186 -- Process the variant part
3188 if Present
(Variant_Part
(Comp_List
)) then
3190 Variant_Alts
: constant List_Id
:= New_List
;
3191 Var_Loc
: Source_Ptr
;
3196 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3197 while Present
(Variant
) loop
3198 Var_Loc
:= Sloc
(Variant
);
3199 Append_To
(Variant_Alts
,
3200 Make_Case_Statement_Alternative
(Var_Loc
,
3202 New_Copy_List
(Discrete_Choices
(Variant
)),
3204 Build_Init_Statements
(Component_List
(Variant
))));
3205 Next_Non_Pragma
(Variant
);
3208 -- The expression of the case statement which is a reference
3209 -- to one of the discriminants is replaced by the appropriate
3210 -- formal parameter of the initialization procedure.
3213 Make_Case_Statement
(Var_Loc
,
3215 New_Occurrence_Of
(Discriminal
(
3216 Entity
(Name
(Variant_Part
(Comp_List
)))), Var_Loc
),
3217 Alternatives
=> Variant_Alts
));
3221 -- If no initializations when generated for component declarations
3222 -- corresponding to this Stmts, append a null statement to Stmts to
3223 -- to make it a valid Ada tree.
3225 if Is_Empty_List
(Stmts
) then
3226 Append
(Make_Null_Statement
(Loc
), Stmts
);
3232 when RE_Not_Available
=>
3234 end Build_Init_Statements
;
3236 -------------------------
3237 -- Build_Record_Checks --
3238 -------------------------
3240 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
) is
3241 Subtype_Mark_Id
: Entity_Id
;
3243 procedure Constrain_Array
3245 Check_List
: List_Id
);
3246 -- Apply a list of index constraints to an unconstrained array type.
3247 -- The first parameter is the entity for the resulting subtype.
3248 -- Check_List is a list to which the check actions are appended.
3250 ---------------------
3251 -- Constrain_Array --
3252 ---------------------
3254 procedure Constrain_Array
3256 Check_List
: List_Id
)
3258 C
: constant Node_Id
:= Constraint
(SI
);
3259 Number_Of_Constraints
: Nat
:= 0;
3263 procedure Constrain_Index
3266 Check_List
: List_Id
);
3267 -- Process an index constraint in a constrained array declaration.
3268 -- The constraint can be either a subtype name or a range with or
3269 -- without an explicit subtype mark. Index is the corresponding
3270 -- index of the unconstrained array. S is the range expression.
3271 -- Check_List is a list to which the check actions are appended.
3273 ---------------------
3274 -- Constrain_Index --
3275 ---------------------
3277 procedure Constrain_Index
3280 Check_List
: List_Id
)
3282 T
: constant Entity_Id
:= Etype
(Index
);
3285 if Nkind
(S
) = N_Range
then
3286 Process_Range_Expr_In_Decl
(S
, T
, Check_List
=> Check_List
);
3288 end Constrain_Index
;
3290 -- Start of processing for Constrain_Array
3293 T
:= Entity
(Subtype_Mark
(SI
));
3295 if Is_Access_Type
(T
) then
3296 T
:= Designated_Type
(T
);
3299 S
:= First
(Constraints
(C
));
3300 while Present
(S
) loop
3301 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
3305 -- In either case, the index constraint must provide a discrete
3306 -- range for each index of the array type and the type of each
3307 -- discrete range must be the same as that of the corresponding
3308 -- index. (RM 3.6.1)
3310 S
:= First
(Constraints
(C
));
3311 Index
:= First_Index
(T
);
3314 -- Apply constraints to each index type
3316 for J
in 1 .. Number_Of_Constraints
loop
3317 Constrain_Index
(Index
, S
, Check_List
);
3321 end Constrain_Array
;
3323 -- Start of processing for Build_Record_Checks
3326 if Nkind
(S
) = N_Subtype_Indication
then
3327 Find_Type
(Subtype_Mark
(S
));
3328 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
3330 -- Remaining processing depends on type
3332 case Ekind
(Subtype_Mark_Id
) is
3335 Constrain_Array
(S
, Check_List
);
3341 end Build_Record_Checks
;
3343 -------------------------------------------
3344 -- Component_Needs_Simple_Initialization --
3345 -------------------------------------------
3347 function Component_Needs_Simple_Initialization
3348 (T
: Entity_Id
) return Boolean
3352 Needs_Simple_Initialization
(T
)
3353 and then not Is_RTE
(T
, RE_Tag
)
3355 -- Ada 2005 (AI-251): Check also the tag of abstract interfaces
3357 and then not Is_RTE
(T
, RE_Interface_Tag
);
3358 end Component_Needs_Simple_Initialization
;
3360 --------------------------------------
3361 -- Parent_Subtype_Renaming_Discrims --
3362 --------------------------------------
3364 function Parent_Subtype_Renaming_Discrims
return Boolean is
3369 if Base_Type
(Rec_Ent
) /= Rec_Ent
then
3373 if Etype
(Rec_Ent
) = Rec_Ent
3374 or else not Has_Discriminants
(Rec_Ent
)
3375 or else Is_Constrained
(Rec_Ent
)
3376 or else Is_Tagged_Type
(Rec_Ent
)
3381 -- If there are no explicit stored discriminants we have inherited
3382 -- the root type discriminants so far, so no renamings occurred.
3384 if First_Discriminant
(Rec_Ent
) =
3385 First_Stored_Discriminant
(Rec_Ent
)
3390 -- Check if we have done some trivial renaming of the parent
3391 -- discriminants, i.e. something like
3393 -- type DT (X1, X2: int) is new PT (X1, X2);
3395 De
:= First_Discriminant
(Rec_Ent
);
3396 Dp
:= First_Discriminant
(Etype
(Rec_Ent
));
3397 while Present
(De
) loop
3398 pragma Assert
(Present
(Dp
));
3400 if Corresponding_Discriminant
(De
) /= Dp
then
3404 Next_Discriminant
(De
);
3405 Next_Discriminant
(Dp
);
3408 return Present
(Dp
);
3409 end Parent_Subtype_Renaming_Discrims
;
3411 ------------------------
3412 -- Requires_Init_Proc --
3413 ------------------------
3415 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean is
3416 Comp_Decl
: Node_Id
;
3421 -- Definitely do not need one if specifically suppressed
3423 if Initialization_Suppressed
(Rec_Id
) then
3427 -- If it is a type derived from a type with unknown discriminants,
3428 -- we cannot build an initialization procedure for it.
3430 if Has_Unknown_Discriminants
(Rec_Id
)
3431 or else Has_Unknown_Discriminants
(Etype
(Rec_Id
))
3436 -- Otherwise we need to generate an initialization procedure if
3437 -- Is_CPP_Class is False and at least one of the following applies:
3439 -- 1. Discriminants are present, since they need to be initialized
3440 -- with the appropriate discriminant constraint expressions.
3441 -- However, the discriminant of an unchecked union does not
3442 -- count, since the discriminant is not present.
3444 -- 2. The type is a tagged type, since the implicit Tag component
3445 -- needs to be initialized with a pointer to the dispatch table.
3447 -- 3. The type contains tasks
3449 -- 4. One or more components has an initial value
3451 -- 5. One or more components is for a type which itself requires
3452 -- an initialization procedure.
3454 -- 6. One or more components is a type that requires simple
3455 -- initialization (see Needs_Simple_Initialization), except
3456 -- that types Tag and Interface_Tag are excluded, since fields
3457 -- of these types are initialized by other means.
3459 -- 7. The type is the record type built for a task type (since at
3460 -- the very least, Create_Task must be called)
3462 -- 8. The type is the record type built for a protected type (since
3463 -- at least Initialize_Protection must be called)
3465 -- 9. The type is marked as a public entity. The reason we add this
3466 -- case (even if none of the above apply) is to properly handle
3467 -- Initialize_Scalars. If a package is compiled without an IS
3468 -- pragma, and the client is compiled with an IS pragma, then
3469 -- the client will think an initialization procedure is present
3470 -- and call it, when in fact no such procedure is required, but
3471 -- since the call is generated, there had better be a routine
3472 -- at the other end of the call, even if it does nothing).
3474 -- Note: the reason we exclude the CPP_Class case is because in this
3475 -- case the initialization is performed by the C++ constructors, and
3476 -- the IP is built by Set_CPP_Constructors.
3478 if Is_CPP_Class
(Rec_Id
) then
3481 elsif Is_Interface
(Rec_Id
) then
3484 elsif (Has_Discriminants
(Rec_Id
)
3485 and then not Is_Unchecked_Union
(Rec_Id
))
3486 or else Is_Tagged_Type
(Rec_Id
)
3487 or else Is_Concurrent_Record_Type
(Rec_Id
)
3488 or else Has_Task
(Rec_Id
)
3493 Id
:= First_Component
(Rec_Id
);
3494 while Present
(Id
) loop
3495 Comp_Decl
:= Parent
(Id
);
3498 if Present
(Expression
(Comp_Decl
))
3499 or else Has_Non_Null_Base_Init_Proc
(Typ
)
3500 or else Component_Needs_Simple_Initialization
(Typ
)
3505 Next_Component
(Id
);
3508 -- As explained above, a record initialization procedure is needed
3509 -- for public types in case Initialize_Scalars applies to a client.
3510 -- However, such a procedure is not needed in the case where either
3511 -- of restrictions No_Initialize_Scalars or No_Default_Initialization
3512 -- applies. No_Initialize_Scalars excludes the possibility of using
3513 -- Initialize_Scalars in any partition, and No_Default_Initialization
3514 -- implies that no initialization should ever be done for objects of
3515 -- the type, so is incompatible with Initialize_Scalars.
3517 if not Restriction_Active
(No_Initialize_Scalars
)
3518 and then not Restriction_Active
(No_Default_Initialization
)
3519 and then Is_Public
(Rec_Id
)
3525 end Requires_Init_Proc
;
3527 -- Start of processing for Build_Record_Init_Proc
3530 -- Check for value type, which means no initialization required
3532 Rec_Type
:= Defining_Identifier
(N
);
3534 if Is_Value_Type
(Rec_Type
) then
3538 -- This may be full declaration of a private type, in which case
3539 -- the visible entity is a record, and the private entity has been
3540 -- exchanged with it in the private part of the current package.
3541 -- The initialization procedure is built for the record type, which
3542 -- is retrievable from the private entity.
3544 if Is_Incomplete_Or_Private_Type
(Rec_Type
) then
3545 Rec_Type
:= Underlying_Type
(Rec_Type
);
3548 -- If we have a variant record with restriction No_Implicit_Conditionals
3549 -- in effect, then we skip building the procedure. This is safe because
3550 -- if we can see the restriction, so can any caller, calls to initialize
3551 -- such records are not allowed for variant records if this restriction
3554 if Has_Variant_Part
(Rec_Type
)
3555 and then Restriction_Active
(No_Implicit_Conditionals
)
3560 -- If there are discriminants, build the discriminant map to replace
3561 -- discriminants by their discriminals in complex bound expressions.
3562 -- These only arise for the corresponding records of synchronized types.
3564 if Is_Concurrent_Record_Type
(Rec_Type
)
3565 and then Has_Discriminants
(Rec_Type
)
3570 Disc
:= First_Discriminant
(Rec_Type
);
3571 while Present
(Disc
) loop
3572 Append_Elmt
(Disc
, Discr_Map
);
3573 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
3574 Next_Discriminant
(Disc
);
3579 -- Derived types that have no type extension can use the initialization
3580 -- procedure of their parent and do not need a procedure of their own.
3581 -- This is only correct if there are no representation clauses for the
3582 -- type or its parent, and if the parent has in fact been frozen so
3583 -- that its initialization procedure exists.
3585 if Is_Derived_Type
(Rec_Type
)
3586 and then not Is_Tagged_Type
(Rec_Type
)
3587 and then not Is_Unchecked_Union
(Rec_Type
)
3588 and then not Has_New_Non_Standard_Rep
(Rec_Type
)
3589 and then not Parent_Subtype_Renaming_Discrims
3590 and then Has_Non_Null_Base_Init_Proc
(Etype
(Rec_Type
))
3592 Copy_TSS
(Base_Init_Proc
(Etype
(Rec_Type
)), Rec_Type
);
3594 -- Otherwise if we need an initialization procedure, then build one,
3595 -- mark it as public and inlinable and as having a completion.
3597 elsif Requires_Init_Proc
(Rec_Type
)
3598 or else Is_Unchecked_Union
(Rec_Type
)
3601 Make_Defining_Identifier
(Loc
,
3602 Chars
=> Make_Init_Proc_Name
(Rec_Type
));
3604 -- If No_Default_Initialization restriction is active, then we don't
3605 -- want to build an init_proc, but we need to mark that an init_proc
3606 -- would be needed if this restriction was not active (so that we can
3607 -- detect attempts to call it), so set a dummy init_proc in place.
3609 if Restriction_Active
(No_Default_Initialization
) then
3610 Set_Init_Proc
(Rec_Type
, Proc_Id
);
3614 Build_Offset_To_Top_Functions
;
3615 Build_CPP_Init_Procedure
;
3616 Build_Init_Procedure
;
3617 Set_Is_Public
(Proc_Id
, Is_Public
(Rec_Ent
));
3619 -- The initialization of protected records is not worth inlining.
3620 -- In addition, when compiled for another unit for inlining purposes,
3621 -- it may make reference to entities that have not been elaborated
3622 -- yet. The initialization of controlled records contains a nested
3623 -- clean-up procedure that makes it impractical to inline as well,
3624 -- and leads to undefined symbols if inlined in a different unit.
3625 -- Similar considerations apply to task types.
3627 if not Is_Concurrent_Type
(Rec_Type
)
3628 and then not Has_Task
(Rec_Type
)
3629 and then not Needs_Finalization
(Rec_Type
)
3631 Set_Is_Inlined
(Proc_Id
);
3634 Set_Is_Internal
(Proc_Id
);
3635 Set_Has_Completion
(Proc_Id
);
3637 if not Debug_Generated_Code
then
3638 Set_Debug_Info_Off
(Proc_Id
);
3642 Agg
: constant Node_Id
:=
3643 Build_Equivalent_Record_Aggregate
(Rec_Type
);
3645 procedure Collect_Itypes
(Comp
: Node_Id
);
3646 -- Generate references to itypes in the aggregate, because
3647 -- the first use of the aggregate may be in a nested scope.
3649 --------------------
3650 -- Collect_Itypes --
3651 --------------------
3653 procedure Collect_Itypes
(Comp
: Node_Id
) is
3656 Typ
: constant Entity_Id
:= Etype
(Comp
);
3659 if Is_Array_Type
(Typ
) and then Is_Itype
(Typ
) then
3660 Ref
:= Make_Itype_Reference
(Loc
);
3661 Set_Itype
(Ref
, Typ
);
3662 Append_Freeze_Action
(Rec_Type
, Ref
);
3664 Ref
:= Make_Itype_Reference
(Loc
);
3665 Set_Itype
(Ref
, Etype
(First_Index
(Typ
)));
3666 Append_Freeze_Action
(Rec_Type
, Ref
);
3668 -- Recurse on nested arrays
3670 Sub_Aggr
:= First
(Expressions
(Comp
));
3671 while Present
(Sub_Aggr
) loop
3672 Collect_Itypes
(Sub_Aggr
);
3679 -- If there is a static initialization aggregate for the type,
3680 -- generate itype references for the types of its (sub)components,
3681 -- to prevent out-of-scope errors in the resulting tree.
3682 -- The aggregate may have been rewritten as a Raise node, in which
3683 -- case there are no relevant itypes.
3685 if Present
(Agg
) and then Nkind
(Agg
) = N_Aggregate
then
3686 Set_Static_Initialization
(Proc_Id
, Agg
);
3691 Comp
:= First
(Component_Associations
(Agg
));
3692 while Present
(Comp
) loop
3693 Collect_Itypes
(Expression
(Comp
));
3700 end Build_Record_Init_Proc
;
3702 --------------------------------
3703 -- Build_Record_Invariant_Proc --
3704 --------------------------------
3706 function Build_Record_Invariant_Proc
3707 (R_Type
: Entity_Id
;
3708 Nod
: Node_Id
) return Node_Id
3710 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
3712 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
3713 -- Name for argument of invariant procedure
3715 Object_Entity
: constant Node_Id
:=
3716 Make_Defining_Identifier
(Loc
, Object_Name
);
3717 -- The procedure declaration entity for the argument
3719 Invariant_Found
: Boolean;
3720 -- Set if any component needs an invariant check.
3722 Proc_Id
: Entity_Id
;
3723 Proc_Body
: Node_Id
;
3727 function Build_Invariant_Checks
(Comp_List
: Node_Id
) return List_Id
;
3728 -- Recursive procedure that generates a list of checks for components
3729 -- that need it, and recurses through variant parts when present.
3731 function Build_Component_Invariant_Call
(Comp
: Entity_Id
)
3733 -- Build call to invariant procedure for a record component.
3735 ------------------------------------
3736 -- Build_Component_Invariant_Call --
3737 ------------------------------------
3739 function Build_Component_Invariant_Call
(Comp
: Entity_Id
)
3747 Invariant_Found
:= True;
3748 Typ
:= Etype
(Comp
);
3751 Make_Selected_Component
(Loc
,
3752 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
3753 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
3755 if Is_Access_Type
(Typ
) then
3757 -- If the access component designates a type with an invariant,
3758 -- the check applies to the designated object. The access type
3759 -- itself may have an invariant, in which case it applies to the
3760 -- access value directly.
3762 -- Note: we are assuming that invariants will not occur on both
3763 -- the access type and the type that it designates. This is not
3764 -- really justified but it is hard to imagine that this case will
3765 -- ever cause trouble ???
3767 if not (Has_Invariants
(Typ
)) then
3768 Sel_Comp
:= Make_Explicit_Dereference
(Loc
, Sel_Comp
);
3769 Typ
:= Designated_Type
(Typ
);
3773 -- The aspect is type-specific, so retrieve it from the base type
3776 Make_Procedure_Call_Statement
(Loc
,
3778 New_Occurrence_Of
(Invariant_Procedure
(Base_Type
(Typ
)), Loc
),
3779 Parameter_Associations
=> New_List
(Sel_Comp
));
3781 if Is_Access_Type
(Etype
(Comp
)) then
3783 Make_If_Statement
(Loc
,
3786 Left_Opnd
=> Make_Null
(Loc
),
3788 Make_Selected_Component
(Loc
,
3789 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
3790 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
))),
3791 Then_Statements
=> New_List
(Call
));
3795 end Build_Component_Invariant_Call
;
3797 ----------------------------
3798 -- Build_Invariant_Checks --
3799 ----------------------------
3801 function Build_Invariant_Checks
(Comp_List
: Node_Id
) return List_Id
is
3808 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3809 while Present
(Decl
) loop
3810 if Nkind
(Decl
) = N_Component_Declaration
then
3811 Id
:= Defining_Identifier
(Decl
);
3813 if Has_Invariants
(Etype
(Id
))
3814 and then In_Open_Scopes
(Scope
(R_Type
))
3816 if Has_Unchecked_Union
(R_Type
) then
3818 ("invariants cannot be checked on components of "
3819 & "unchecked_union type&?", Decl
, R_Type
);
3823 Append_To
(Stmts
, Build_Component_Invariant_Call
(Id
));
3826 elsif Is_Access_Type
(Etype
(Id
))
3827 and then not Is_Access_Constant
(Etype
(Id
))
3828 and then Has_Invariants
(Designated_Type
(Etype
(Id
)))
3829 and then In_Open_Scopes
(Scope
(Designated_Type
(Etype
(Id
))))
3831 Append_To
(Stmts
, Build_Component_Invariant_Call
(Id
));
3838 if Present
(Variant_Part
(Comp_List
)) then
3840 Variant_Alts
: constant List_Id
:= New_List
;
3841 Var_Loc
: Source_Ptr
;
3843 Variant_Stmts
: List_Id
;
3847 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3848 while Present
(Variant
) loop
3850 Build_Invariant_Checks
(Component_List
(Variant
));
3851 Var_Loc
:= Sloc
(Variant
);
3852 Append_To
(Variant_Alts
,
3853 Make_Case_Statement_Alternative
(Var_Loc
,
3855 New_Copy_List
(Discrete_Choices
(Variant
)),
3856 Statements
=> Variant_Stmts
));
3858 Next_Non_Pragma
(Variant
);
3861 -- The expression in the case statement is the reference to
3862 -- the discriminant of the target object.
3865 Make_Case_Statement
(Var_Loc
,
3867 Make_Selected_Component
(Var_Loc
,
3868 Prefix
=> New_Occurrence_Of
(Object_Entity
, Var_Loc
),
3869 Selector_Name
=> New_Occurrence_Of
3871 (Name
(Variant_Part
(Comp_List
))), Var_Loc
)),
3872 Alternatives
=> Variant_Alts
));
3877 end Build_Invariant_Checks
;
3879 -- Start of processing for Build_Record_Invariant_Proc
3882 Invariant_Found
:= False;
3883 Type_Def
:= Type_Definition
(Parent
(R_Type
));
3885 if Nkind
(Type_Def
) = N_Record_Definition
3886 and then not Null_Present
(Type_Def
)
3888 Stmts
:= Build_Invariant_Checks
(Component_List
(Type_Def
));
3893 if not Invariant_Found
then
3897 -- The name of the invariant procedure reflects the fact that the
3898 -- checks correspond to invariants on the component types. The
3899 -- record type itself may have invariants that will create a separate
3900 -- procedure whose name carries the Invariant suffix.
3903 Make_Defining_Identifier
(Loc
,
3904 Chars
=> New_External_Name
(Chars
(R_Type
), "CInvariant"));
3907 Make_Subprogram_Body
(Loc
,
3909 Make_Procedure_Specification
(Loc
,
3910 Defining_Unit_Name
=> Proc_Id
,
3911 Parameter_Specifications
=> New_List
(
3912 Make_Parameter_Specification
(Loc
,
3913 Defining_Identifier
=> Object_Entity
,
3914 Parameter_Type
=> New_Occurrence_Of
(R_Type
, Loc
)))),
3916 Declarations
=> Empty_List
,
3917 Handled_Statement_Sequence
=>
3918 Make_Handled_Sequence_Of_Statements
(Loc
,
3919 Statements
=> Stmts
));
3921 Set_Ekind
(Proc_Id
, E_Procedure
);
3922 Set_Is_Public
(Proc_Id
, Is_Public
(R_Type
));
3923 Set_Is_Internal
(Proc_Id
);
3924 Set_Has_Completion
(Proc_Id
);
3927 -- Insert_After (Nod, Proc_Body);
3928 -- Analyze (Proc_Body);
3929 end Build_Record_Invariant_Proc
;
3931 ----------------------------
3932 -- Build_Slice_Assignment --
3933 ----------------------------
3935 -- Generates the following subprogram:
3938 -- (Source, Target : Array_Type,
3939 -- Left_Lo, Left_Hi : Index;
3940 -- Right_Lo, Right_Hi : Index;
3948 -- if Left_Hi < Left_Lo then
3961 -- Target (Li1) := Source (Ri1);
3964 -- exit when Li1 = Left_Lo;
3965 -- Li1 := Index'pred (Li1);
3966 -- Ri1 := Index'pred (Ri1);
3968 -- exit when Li1 = Left_Hi;
3969 -- Li1 := Index'succ (Li1);
3970 -- Ri1 := Index'succ (Ri1);
3975 procedure Build_Slice_Assignment
(Typ
: Entity_Id
) is
3976 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3977 Index
: constant Entity_Id
:= Base_Type
(Etype
(First_Index
(Typ
)));
3979 Larray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
3980 Rarray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3981 Left_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3982 Left_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3983 Right_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3984 Right_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3985 Rev
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
3986 -- Formal parameters of procedure
3988 Proc_Name
: constant Entity_Id
:=
3989 Make_Defining_Identifier
(Loc
,
3990 Chars
=> Make_TSS_Name
(Typ
, TSS_Slice_Assign
));
3992 Lnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3993 Rnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3994 -- Subscripts for left and right sides
4001 -- Build declarations for indexes
4006 Make_Object_Declaration
(Loc
,
4007 Defining_Identifier
=> Lnn
,
4008 Object_Definition
=>
4009 New_Occurrence_Of
(Index
, Loc
)));
4012 Make_Object_Declaration
(Loc
,
4013 Defining_Identifier
=> Rnn
,
4014 Object_Definition
=>
4015 New_Occurrence_Of
(Index
, Loc
)));
4019 -- Build test for empty slice case
4022 Make_If_Statement
(Loc
,
4025 Left_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
),
4026 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
)),
4027 Then_Statements
=> New_List
(Make_Simple_Return_Statement
(Loc
))));
4029 -- Build initializations for indexes
4032 F_Init
: constant List_Id
:= New_List
;
4033 B_Init
: constant List_Id
:= New_List
;
4037 Make_Assignment_Statement
(Loc
,
4038 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4039 Expression
=> New_Occurrence_Of
(Left_Lo
, Loc
)));
4042 Make_Assignment_Statement
(Loc
,
4043 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4044 Expression
=> New_Occurrence_Of
(Right_Lo
, Loc
)));
4047 Make_Assignment_Statement
(Loc
,
4048 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4049 Expression
=> New_Occurrence_Of
(Left_Hi
, Loc
)));
4052 Make_Assignment_Statement
(Loc
,
4053 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4054 Expression
=> New_Occurrence_Of
(Right_Hi
, Loc
)));
4057 Make_If_Statement
(Loc
,
4058 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4059 Then_Statements
=> B_Init
,
4060 Else_Statements
=> F_Init
));
4063 -- Now construct the assignment statement
4066 Make_Loop_Statement
(Loc
,
4067 Statements
=> New_List
(
4068 Make_Assignment_Statement
(Loc
,
4070 Make_Indexed_Component
(Loc
,
4071 Prefix
=> New_Occurrence_Of
(Larray
, Loc
),
4072 Expressions
=> New_List
(New_Occurrence_Of
(Lnn
, Loc
))),
4074 Make_Indexed_Component
(Loc
,
4075 Prefix
=> New_Occurrence_Of
(Rarray
, Loc
),
4076 Expressions
=> New_List
(New_Occurrence_Of
(Rnn
, Loc
))))),
4077 End_Label
=> Empty
);
4079 -- Build the exit condition and increment/decrement statements
4082 F_Ass
: constant List_Id
:= New_List
;
4083 B_Ass
: constant List_Id
:= New_List
;
4087 Make_Exit_Statement
(Loc
,
4090 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4091 Right_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
))));
4094 Make_Assignment_Statement
(Loc
,
4095 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4097 Make_Attribute_Reference
(Loc
,
4099 New_Occurrence_Of
(Index
, Loc
),
4100 Attribute_Name
=> Name_Succ
,
4101 Expressions
=> New_List
(
4102 New_Occurrence_Of
(Lnn
, Loc
)))));
4105 Make_Assignment_Statement
(Loc
,
4106 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4108 Make_Attribute_Reference
(Loc
,
4110 New_Occurrence_Of
(Index
, Loc
),
4111 Attribute_Name
=> Name_Succ
,
4112 Expressions
=> New_List
(
4113 New_Occurrence_Of
(Rnn
, Loc
)))));
4116 Make_Exit_Statement
(Loc
,
4119 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4120 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
))));
4123 Make_Assignment_Statement
(Loc
,
4124 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4126 Make_Attribute_Reference
(Loc
,
4128 New_Occurrence_Of
(Index
, Loc
),
4129 Attribute_Name
=> Name_Pred
,
4130 Expressions
=> New_List
(
4131 New_Occurrence_Of
(Lnn
, Loc
)))));
4134 Make_Assignment_Statement
(Loc
,
4135 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4137 Make_Attribute_Reference
(Loc
,
4139 New_Occurrence_Of
(Index
, Loc
),
4140 Attribute_Name
=> Name_Pred
,
4141 Expressions
=> New_List
(
4142 New_Occurrence_Of
(Rnn
, Loc
)))));
4144 Append_To
(Statements
(Loops
),
4145 Make_If_Statement
(Loc
,
4146 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4147 Then_Statements
=> B_Ass
,
4148 Else_Statements
=> F_Ass
));
4151 Append_To
(Stats
, Loops
);
4155 Formals
: List_Id
:= New_List
;
4158 Formals
:= New_List
(
4159 Make_Parameter_Specification
(Loc
,
4160 Defining_Identifier
=> Larray
,
4161 Out_Present
=> True,
4163 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4165 Make_Parameter_Specification
(Loc
,
4166 Defining_Identifier
=> Rarray
,
4168 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4170 Make_Parameter_Specification
(Loc
,
4171 Defining_Identifier
=> Left_Lo
,
4173 New_Occurrence_Of
(Index
, Loc
)),
4175 Make_Parameter_Specification
(Loc
,
4176 Defining_Identifier
=> Left_Hi
,
4178 New_Occurrence_Of
(Index
, Loc
)),
4180 Make_Parameter_Specification
(Loc
,
4181 Defining_Identifier
=> Right_Lo
,
4183 New_Occurrence_Of
(Index
, Loc
)),
4185 Make_Parameter_Specification
(Loc
,
4186 Defining_Identifier
=> Right_Hi
,
4188 New_Occurrence_Of
(Index
, Loc
)));
4191 Make_Parameter_Specification
(Loc
,
4192 Defining_Identifier
=> Rev
,
4194 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
4197 Make_Procedure_Specification
(Loc
,
4198 Defining_Unit_Name
=> Proc_Name
,
4199 Parameter_Specifications
=> Formals
);
4202 Make_Subprogram_Body
(Loc
,
4203 Specification
=> Spec
,
4204 Declarations
=> Decls
,
4205 Handled_Statement_Sequence
=>
4206 Make_Handled_Sequence_Of_Statements
(Loc
,
4207 Statements
=> Stats
)));
4210 Set_TSS
(Typ
, Proc_Name
);
4211 Set_Is_Pure
(Proc_Name
);
4212 end Build_Slice_Assignment
;
4214 -----------------------------
4215 -- Build_Untagged_Equality --
4216 -----------------------------
4218 procedure Build_Untagged_Equality
(Typ
: Entity_Id
) is
4226 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
;
4227 -- Check whether the type T has a user-defined primitive equality. If so
4228 -- return it, else return Empty. If true for a component of Typ, we have
4229 -- to build the primitive equality for it.
4231 ---------------------
4232 -- User_Defined_Eq --
4233 ---------------------
4235 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
is
4240 Op
:= TSS
(T
, TSS_Composite_Equality
);
4242 if Present
(Op
) then
4246 Prim
:= First_Elmt
(Collect_Primitive_Operations
(T
));
4247 while Present
(Prim
) loop
4250 if Chars
(Op
) = Name_Op_Eq
4251 and then Etype
(Op
) = Standard_Boolean
4252 and then Etype
(First_Formal
(Op
)) = T
4253 and then Etype
(Next_Formal
(First_Formal
(Op
))) = T
4262 end User_Defined_Eq
;
4264 -- Start of processing for Build_Untagged_Equality
4267 -- If a record component has a primitive equality operation, we must
4268 -- build the corresponding one for the current type.
4271 Comp
:= First_Component
(Typ
);
4272 while Present
(Comp
) loop
4273 if Is_Record_Type
(Etype
(Comp
))
4274 and then Present
(User_Defined_Eq
(Etype
(Comp
)))
4279 Next_Component
(Comp
);
4282 -- If there is a user-defined equality for the type, we do not create
4283 -- the implicit one.
4285 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Typ
));
4287 while Present
(Prim
) loop
4288 if Chars
(Node
(Prim
)) = Name_Op_Eq
4289 and then Comes_From_Source
(Node
(Prim
))
4291 -- Don't we also need to check formal types and return type as in
4292 -- User_Defined_Eq above???
4295 Eq_Op
:= Node
(Prim
);
4303 -- If the type is derived, inherit the operation, if present, from the
4304 -- parent type. It may have been declared after the type derivation. If
4305 -- the parent type itself is derived, it may have inherited an operation
4306 -- that has itself been overridden, so update its alias and related
4307 -- flags. Ditto for inequality.
4309 if No
(Eq_Op
) and then Is_Derived_Type
(Typ
) then
4310 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Etype
(Typ
)));
4311 while Present
(Prim
) loop
4312 if Chars
(Node
(Prim
)) = Name_Op_Eq
then
4313 Copy_TSS
(Node
(Prim
), Typ
);
4317 Op
: constant Entity_Id
:= User_Defined_Eq
(Typ
);
4318 Eq_Op
: constant Entity_Id
:= Node
(Prim
);
4319 NE_Op
: constant Entity_Id
:= Next_Entity
(Eq_Op
);
4322 if Present
(Op
) then
4323 Set_Alias
(Op
, Eq_Op
);
4324 Set_Is_Abstract_Subprogram
4325 (Op
, Is_Abstract_Subprogram
(Eq_Op
));
4327 if Chars
(Next_Entity
(Op
)) = Name_Op_Ne
then
4328 Set_Is_Abstract_Subprogram
4329 (Next_Entity
(Op
), Is_Abstract_Subprogram
(NE_Op
));
4341 -- If not inherited and not user-defined, build body as for a type with
4342 -- tagged components.
4346 Make_Eq_Body
(Typ
, Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4347 Op
:= Defining_Entity
(Decl
);
4351 if Is_Library_Level_Entity
(Typ
) then
4355 end Build_Untagged_Equality
;
4357 -----------------------------------
4358 -- Build_Variant_Record_Equality --
4359 -----------------------------------
4363 -- function _Equality (X, Y : T) return Boolean is
4365 -- -- Compare discriminants
4367 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4371 -- -- Compare components
4373 -- if X.C1 /= Y.C1 or else X.C2 /= Y.C2 or else ... then
4377 -- -- Compare variant part
4381 -- if X.C2 /= Y.C2 or else X.C3 /= Y.C3 or else ... then
4386 -- if X.Cn /= Y.Cn or else ... then
4394 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
) is
4395 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4397 F
: constant Entity_Id
:=
4398 Make_Defining_Identifier
(Loc
,
4399 Chars
=> Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4401 X
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_X
);
4402 Y
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_Y
);
4404 Def
: constant Node_Id
:= Parent
(Typ
);
4405 Comps
: constant Node_Id
:= Component_List
(Type_Definition
(Def
));
4406 Stmts
: constant List_Id
:= New_List
;
4407 Pspecs
: constant List_Id
:= New_List
;
4410 -- If we have a variant record with restriction No_Implicit_Conditionals
4411 -- in effect, then we skip building the procedure. This is safe because
4412 -- if we can see the restriction, so can any caller, calls to equality
4413 -- test routines are not allowed for variant records if this restriction
4416 if Restriction_Active
(No_Implicit_Conditionals
) then
4420 -- Derived Unchecked_Union types no longer inherit the equality function
4423 if Is_Derived_Type
(Typ
)
4424 and then not Is_Unchecked_Union
(Typ
)
4425 and then not Has_New_Non_Standard_Rep
(Typ
)
4428 Parent_Eq
: constant Entity_Id
:=
4429 TSS
(Root_Type
(Typ
), TSS_Composite_Equality
);
4431 if Present
(Parent_Eq
) then
4432 Copy_TSS
(Parent_Eq
, Typ
);
4439 Make_Subprogram_Body
(Loc
,
4441 Make_Function_Specification
(Loc
,
4442 Defining_Unit_Name
=> F
,
4443 Parameter_Specifications
=> Pspecs
,
4444 Result_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
)),
4445 Declarations
=> New_List
,
4446 Handled_Statement_Sequence
=>
4447 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
)));
4450 Make_Parameter_Specification
(Loc
,
4451 Defining_Identifier
=> X
,
4452 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4455 Make_Parameter_Specification
(Loc
,
4456 Defining_Identifier
=> Y
,
4457 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4459 -- Unchecked_Unions require additional machinery to support equality.
4460 -- Two extra parameters (A and B) are added to the equality function
4461 -- parameter list for each discriminant of the type, in order to
4462 -- capture the inferred values of the discriminants in equality calls.
4463 -- The names of the parameters match the names of the corresponding
4464 -- discriminant, with an added suffix.
4466 if Is_Unchecked_Union
(Typ
) then
4469 Discr_Type
: Entity_Id
;
4471 New_Discrs
: Elist_Id
;
4474 New_Discrs
:= New_Elmt_List
;
4476 Discr
:= First_Discriminant
(Typ
);
4477 while Present
(Discr
) loop
4478 Discr_Type
:= Etype
(Discr
);
4479 A
:= Make_Defining_Identifier
(Loc
,
4480 Chars
=> New_External_Name
(Chars
(Discr
), 'A'));
4482 B
:= Make_Defining_Identifier
(Loc
,
4483 Chars
=> New_External_Name
(Chars
(Discr
), 'B'));
4485 -- Add new parameters to the parameter list
4488 Make_Parameter_Specification
(Loc
,
4489 Defining_Identifier
=> A
,
4491 New_Occurrence_Of
(Discr_Type
, Loc
)));
4494 Make_Parameter_Specification
(Loc
,
4495 Defining_Identifier
=> B
,
4497 New_Occurrence_Of
(Discr_Type
, Loc
)));
4499 Append_Elmt
(A
, New_Discrs
);
4501 -- Generate the following code to compare each of the inferred
4509 Make_If_Statement
(Loc
,
4512 Left_Opnd
=> New_Occurrence_Of
(A
, Loc
),
4513 Right_Opnd
=> New_Occurrence_Of
(B
, Loc
)),
4514 Then_Statements
=> New_List
(
4515 Make_Simple_Return_Statement
(Loc
,
4517 New_Occurrence_Of
(Standard_False
, Loc
)))));
4518 Next_Discriminant
(Discr
);
4521 -- Generate component-by-component comparison. Note that we must
4522 -- propagate the inferred discriminants formals to act as
4523 -- the case statement switch. Their value is added when an
4524 -- equality call on unchecked unions is expanded.
4526 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
, New_Discrs
));
4529 -- Normal case (not unchecked union)
4533 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
4534 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
4538 Make_Simple_Return_Statement
(Loc
,
4539 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
4544 if not Debug_Generated_Code
then
4545 Set_Debug_Info_Off
(F
);
4547 end Build_Variant_Record_Equality
;
4549 -----------------------------
4550 -- Check_Stream_Attributes --
4551 -----------------------------
4553 procedure Check_Stream_Attributes
(Typ
: Entity_Id
) is
4555 Par_Read
: constant Boolean :=
4556 Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
4557 and then not Has_Specified_Stream_Read
(Typ
);
4558 Par_Write
: constant Boolean :=
4559 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
4560 and then not Has_Specified_Stream_Write
(Typ
);
4562 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
);
4563 -- Check that Comp has a user-specified Nam stream attribute
4569 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
) is
4571 if not Stream_Attribute_Available
(Etype
(Comp
), TSS_Nam
) then
4572 Error_Msg_Name_1
:= Nam
;
4574 ("|component& in limited extension must have% attribute", Comp
);
4578 -- Start of processing for Check_Stream_Attributes
4581 if Par_Read
or else Par_Write
then
4582 Comp
:= First_Component
(Typ
);
4583 while Present
(Comp
) loop
4584 if Comes_From_Source
(Comp
)
4585 and then Original_Record_Component
(Comp
) = Comp
4586 and then Is_Limited_Type
(Etype
(Comp
))
4589 Check_Attr
(Name_Read
, TSS_Stream_Read
);
4593 Check_Attr
(Name_Write
, TSS_Stream_Write
);
4597 Next_Component
(Comp
);
4600 end Check_Stream_Attributes
;
4602 -----------------------------
4603 -- Expand_Record_Extension --
4604 -----------------------------
4606 -- Add a field _parent at the beginning of the record extension. This is
4607 -- used to implement inheritance. Here are some examples of expansion:
4609 -- 1. no discriminants
4610 -- type T2 is new T1 with null record;
4612 -- type T2 is new T1 with record
4616 -- 2. renamed discriminants
4617 -- type T2 (B, C : Int) is new T1 (A => B) with record
4618 -- _Parent : T1 (A => B);
4622 -- 3. inherited discriminants
4623 -- type T2 is new T1 with record -- discriminant A inherited
4624 -- _Parent : T1 (A);
4628 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
) is
4629 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
4630 Loc
: constant Source_Ptr
:= Sloc
(Def
);
4631 Rec_Ext_Part
: Node_Id
:= Record_Extension_Part
(Def
);
4632 Par_Subtype
: Entity_Id
;
4633 Comp_List
: Node_Id
;
4634 Comp_Decl
: Node_Id
;
4637 List_Constr
: constant List_Id
:= New_List
;
4640 -- Expand_Record_Extension is called directly from the semantics, so
4641 -- we must check to see whether expansion is active before proceeding,
4642 -- because this affects the visibility of selected components in bodies
4645 if not Expander_Active
then
4649 -- This may be a derivation of an untagged private type whose full
4650 -- view is tagged, in which case the Derived_Type_Definition has no
4651 -- extension part. Build an empty one now.
4653 if No
(Rec_Ext_Part
) then
4655 Make_Record_Definition
(Loc
,
4657 Component_List
=> Empty
,
4658 Null_Present
=> True);
4660 Set_Record_Extension_Part
(Def
, Rec_Ext_Part
);
4661 Mark_Rewrite_Insertion
(Rec_Ext_Part
);
4664 Comp_List
:= Component_List
(Rec_Ext_Part
);
4666 Parent_N
:= Make_Defining_Identifier
(Loc
, Name_uParent
);
4668 -- If the derived type inherits its discriminants the type of the
4669 -- _parent field must be constrained by the inherited discriminants
4671 if Has_Discriminants
(T
)
4672 and then Nkind
(Indic
) /= N_Subtype_Indication
4673 and then not Is_Constrained
(Entity
(Indic
))
4675 D
:= First_Discriminant
(T
);
4676 while Present
(D
) loop
4677 Append_To
(List_Constr
, New_Occurrence_Of
(D
, Loc
));
4678 Next_Discriminant
(D
);
4683 Make_Subtype_Indication
(Loc
,
4684 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Indic
), Loc
),
4686 Make_Index_Or_Discriminant_Constraint
(Loc
,
4687 Constraints
=> List_Constr
)),
4690 -- Otherwise the original subtype_indication is just what is needed
4693 Par_Subtype
:= Process_Subtype
(New_Copy_Tree
(Indic
), Def
);
4696 Set_Parent_Subtype
(T
, Par_Subtype
);
4699 Make_Component_Declaration
(Loc
,
4700 Defining_Identifier
=> Parent_N
,
4701 Component_Definition
=>
4702 Make_Component_Definition
(Loc
,
4703 Aliased_Present
=> False,
4704 Subtype_Indication
=> New_Occurrence_Of
(Par_Subtype
, Loc
)));
4706 if Null_Present
(Rec_Ext_Part
) then
4707 Set_Component_List
(Rec_Ext_Part
,
4708 Make_Component_List
(Loc
,
4709 Component_Items
=> New_List
(Comp_Decl
),
4710 Variant_Part
=> Empty
,
4711 Null_Present
=> False));
4712 Set_Null_Present
(Rec_Ext_Part
, False);
4714 elsif Null_Present
(Comp_List
)
4715 or else Is_Empty_List
(Component_Items
(Comp_List
))
4717 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
4718 Set_Null_Present
(Comp_List
, False);
4721 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
4724 Analyze
(Comp_Decl
);
4725 end Expand_Record_Extension
;
4727 ------------------------------------
4728 -- Expand_N_Full_Type_Declaration --
4729 ------------------------------------
4731 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
) is
4732 procedure Build_Master
(Ptr_Typ
: Entity_Id
);
4733 -- Create the master associated with Ptr_Typ
4739 procedure Build_Master
(Ptr_Typ
: Entity_Id
) is
4740 Desig_Typ
: Entity_Id
:= Designated_Type
(Ptr_Typ
);
4743 -- If the designated type is an incomplete view coming from a
4744 -- limited-with'ed package, we need to use the nonlimited view in
4745 -- case it has tasks.
4747 if Ekind
(Desig_Typ
) in Incomplete_Kind
4748 and then Present
(Non_Limited_View
(Desig_Typ
))
4750 Desig_Typ
:= Non_Limited_View
(Desig_Typ
);
4753 -- Anonymous access types are created for the components of the
4754 -- record parameter for an entry declaration. No master is created
4757 if Comes_From_Source
(N
) and then Has_Task
(Desig_Typ
) then
4758 Build_Master_Entity
(Ptr_Typ
);
4759 Build_Master_Renaming
(Ptr_Typ
);
4761 -- Create a class-wide master because a Master_Id must be generated
4762 -- for access-to-limited-class-wide types whose root may be extended
4763 -- with task components.
4765 -- Note: This code covers access-to-limited-interfaces because they
4766 -- can be used to reference tasks implementing them.
4768 elsif Is_Limited_Class_Wide_Type
(Desig_Typ
)
4769 and then Tasking_Allowed
4771 -- Do not create a class-wide master for types whose convention is
4772 -- Java since these types cannot embed Ada tasks anyway. Note that
4773 -- the following test cannot catch the following case:
4775 -- package java.lang.Object is
4776 -- type Typ is tagged limited private;
4777 -- type Ref is access all Typ'Class;
4779 -- type Typ is tagged limited ...;
4780 -- pragma Convention (Typ, Java)
4783 -- Because the convention appears after we have done the
4784 -- processing for type Ref.
4786 and then Convention
(Desig_Typ
) /= Convention_Java
4787 and then Convention
(Desig_Typ
) /= Convention_CIL
4789 Build_Class_Wide_Master
(Ptr_Typ
);
4793 -- Local declarations
4795 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
4796 B_Id
: constant Entity_Id
:= Base_Type
(Def_Id
);
4797 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4801 -- Start of processing for Expand_N_Full_Type_Declaration
4804 -- The type declaration may be subject to pragma Ghost with policy
4805 -- Ignore. Set the mode now to ensure that any nodes generated during
4806 -- expansion are properly flagged as ignored Ghost.
4810 if Is_Access_Type
(Def_Id
) then
4811 Build_Master
(Def_Id
);
4813 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
4814 Expand_Access_Protected_Subprogram_Type
(N
);
4817 -- Array of anonymous access-to-task pointers
4819 elsif Ada_Version
>= Ada_2005
4820 and then Is_Array_Type
(Def_Id
)
4821 and then Is_Access_Type
(Component_Type
(Def_Id
))
4822 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
4824 Build_Master
(Component_Type
(Def_Id
));
4826 elsif Has_Task
(Def_Id
) then
4827 Expand_Previous_Access_Type
(Def_Id
);
4829 -- Check the components of a record type or array of records for
4830 -- anonymous access-to-task pointers.
4832 elsif Ada_Version
>= Ada_2005
4833 and then (Is_Record_Type
(Def_Id
)
4835 (Is_Array_Type
(Def_Id
)
4836 and then Is_Record_Type
(Component_Type
(Def_Id
))))
4845 if Is_Array_Type
(Def_Id
) then
4846 Comp
:= First_Entity
(Component_Type
(Def_Id
));
4848 Comp
:= First_Entity
(Def_Id
);
4851 -- Examine all components looking for anonymous access-to-task
4855 while Present
(Comp
) loop
4856 Typ
:= Etype
(Comp
);
4858 if Ekind
(Typ
) = E_Anonymous_Access_Type
4859 and then Has_Task
(Available_View
(Designated_Type
(Typ
)))
4860 and then No
(Master_Id
(Typ
))
4862 -- Ensure that the record or array type have a _master
4865 Build_Master_Entity
(Def_Id
);
4866 Build_Master_Renaming
(Typ
);
4867 M_Id
:= Master_Id
(Typ
);
4871 -- Reuse the same master to service any additional types
4874 Set_Master_Id
(Typ
, M_Id
);
4883 Par_Id
:= Etype
(B_Id
);
4885 -- The parent type is private then we need to inherit any TSS operations
4886 -- from the full view.
4888 if Ekind
(Par_Id
) in Private_Kind
4889 and then Present
(Full_View
(Par_Id
))
4891 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
4894 if Nkind
(Type_Definition
(Original_Node
(N
))) =
4895 N_Derived_Type_Definition
4896 and then not Is_Tagged_Type
(Def_Id
)
4897 and then Present
(Freeze_Node
(Par_Id
))
4898 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
4900 Ensure_Freeze_Node
(B_Id
);
4901 FN
:= Freeze_Node
(B_Id
);
4903 if No
(TSS_Elist
(FN
)) then
4904 Set_TSS_Elist
(FN
, New_Elmt_List
);
4908 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
4912 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
4913 while Present
(Elmt
) loop
4914 if Chars
(Node
(Elmt
)) /= Name_uInit
then
4915 Append_Elmt
(Node
(Elmt
), T_E
);
4921 -- If the derived type itself is private with a full view, then
4922 -- associate the full view with the inherited TSS_Elist as well.
4924 if Ekind
(B_Id
) in Private_Kind
4925 and then Present
(Full_View
(B_Id
))
4927 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
4929 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
4934 -- Restore the original Ghost mode once analysis and expansion have
4938 end Expand_N_Full_Type_Declaration
;
4940 ---------------------------------
4941 -- Expand_N_Object_Declaration --
4942 ---------------------------------
4944 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
4945 Loc
: constant Source_Ptr
:= Sloc
(N
);
4946 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
4947 Expr
: constant Node_Id
:= Expression
(N
);
4948 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4949 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
4950 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
4951 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4954 function Build_Equivalent_Aggregate
return Boolean;
4955 -- If the object has a constrained discriminated type and no initial
4956 -- value, it may be possible to build an equivalent aggregate instead,
4957 -- and prevent an actual call to the initialization procedure.
4959 procedure Default_Initialize_Object
(After
: Node_Id
);
4960 -- Generate all default initialization actions for object Def_Id. Any
4961 -- new code is inserted after node After.
4963 procedure Restore_Globals
;
4964 -- Restore the values of all saved global variables
4966 function Rewrite_As_Renaming
return Boolean;
4967 -- Indicate whether to rewrite a declaration with initialization into an
4968 -- object renaming declaration (see below).
4970 --------------------------------
4971 -- Build_Equivalent_Aggregate --
4972 --------------------------------
4974 function Build_Equivalent_Aggregate
return Boolean is
4978 Full_Type
: Entity_Id
;
4983 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
4984 Full_Type
:= Full_View
(Typ
);
4987 -- Only perform this transformation if Elaboration_Code is forbidden
4988 -- or undesirable, and if this is a global entity of a constrained
4991 -- If Initialize_Scalars might be active this transformation cannot
4992 -- be performed either, because it will lead to different semantics
4993 -- or because elaboration code will in fact be created.
4995 if Ekind
(Full_Type
) /= E_Record_Subtype
4996 or else not Has_Discriminants
(Full_Type
)
4997 or else not Is_Constrained
(Full_Type
)
4998 or else Is_Controlled
(Full_Type
)
4999 or else Is_Limited_Type
(Full_Type
)
5000 or else not Restriction_Active
(No_Initialize_Scalars
)
5005 if Ekind
(Current_Scope
) = E_Package
5007 (Restriction_Active
(No_Elaboration_Code
)
5008 or else Is_Preelaborated
(Current_Scope
))
5010 -- Building a static aggregate is possible if the discriminants
5011 -- have static values and the other components have static
5012 -- defaults or none.
5014 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5015 while Present
(Discr
) loop
5016 if not Is_OK_Static_Expression
(Node
(Discr
)) then
5023 -- Check that initialized components are OK, and that non-
5024 -- initialized components do not require a call to their own
5025 -- initialization procedure.
5027 Comp
:= First_Component
(Full_Type
);
5028 while Present
(Comp
) loop
5029 if Ekind
(Comp
) = E_Component
5030 and then Present
(Expression
(Parent
(Comp
)))
5032 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
5036 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
5041 Next_Component
(Comp
);
5044 -- Everything is static, assemble the aggregate, discriminant
5048 Make_Aggregate
(Loc
,
5049 Expressions
=> New_List
,
5050 Component_Associations
=> New_List
);
5052 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5053 while Present
(Discr
) loop
5054 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
5058 -- Now collect values of initialized components
5060 Comp
:= First_Component
(Full_Type
);
5061 while Present
(Comp
) loop
5062 if Ekind
(Comp
) = E_Component
5063 and then Present
(Expression
(Parent
(Comp
)))
5065 Append_To
(Component_Associations
(Aggr
),
5066 Make_Component_Association
(Loc
,
5067 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
5068 Expression
=> New_Copy_Tree
5069 (Expression
(Parent
(Comp
)))));
5072 Next_Component
(Comp
);
5075 -- Finally, box-initialize remaining components
5077 Append_To
(Component_Associations
(Aggr
),
5078 Make_Component_Association
(Loc
,
5079 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5080 Expression
=> Empty
));
5081 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
5082 Set_Expression
(N
, Aggr
);
5084 if Typ
/= Full_Type
then
5085 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
5086 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
5087 Analyze_And_Resolve
(Aggr
, Typ
);
5089 Analyze_And_Resolve
(Aggr
, Full_Type
);
5097 end Build_Equivalent_Aggregate
;
5099 -------------------------------
5100 -- Default_Initialize_Object --
5101 -------------------------------
5103 procedure Default_Initialize_Object
(After
: Node_Id
) is
5104 function New_Object_Reference
return Node_Id
;
5105 -- Return a new reference to Def_Id with attributes Assignment_OK and
5106 -- Must_Not_Freeze already set.
5108 --------------------------
5109 -- New_Object_Reference --
5110 --------------------------
5112 function New_Object_Reference
return Node_Id
is
5113 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
5116 -- The call to the type init proc or [Deep_]Finalize must not
5117 -- freeze the related object as the call is internally generated.
5118 -- This way legal rep clauses that apply to the object will not be
5119 -- flagged. Note that the initialization call may be removed if
5120 -- pragma Import is encountered or moved to the freeze actions of
5121 -- the object because of an address clause.
5123 Set_Assignment_OK
(Obj_Ref
);
5124 Set_Must_Not_Freeze
(Obj_Ref
);
5127 end New_Object_Reference
;
5133 Abrt_Id
: Entity_Id
;
5134 Abrt_Stmts
: List_Id
;
5135 Aggr_Init
: Node_Id
;
5136 Comp_Init
: List_Id
:= No_List
;
5138 Fin_Stmts
: List_Id
:= No_List
;
5139 Obj_Init
: Node_Id
:= Empty
;
5143 -- This variable captures a dummy internal entity, see the comment
5144 -- associated with its use.
5146 -- Start of processing for Default_Initialize_Object
5149 -- Default initialization is suppressed for objects that are already
5150 -- known to be imported (i.e. whose declaration specifies the Import
5151 -- aspect). Note that for objects with a pragma Import, we generate
5152 -- initialization here, and then remove it downstream when processing
5153 -- the pragma. It is also suppressed for variables for which a pragma
5154 -- Suppress_Initialization has been explicitly given
5156 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
5160 -- Step 1: Initialize the object
5162 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
5165 (Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
5169 -- Step 2: Initialize the components of the object
5171 -- Do not initialize the components if their initialization is
5172 -- prohibited or the type represents a value type in a .NET VM.
5174 if Has_Non_Null_Base_Init_Proc
(Typ
)
5175 and then not No_Initialization
(N
)
5176 and then not Initialization_Suppressed
(Typ
)
5177 and then not Is_Value_Type
(Typ
)
5179 -- Do not initialize the components if No_Default_Initialization
5180 -- applies as the actual restriction check will occur later
5181 -- when the object is frozen as it is not known yet whether the
5182 -- object is imported or not.
5184 if not Restriction_Active
(No_Default_Initialization
) then
5186 -- If the values of the components are compile-time known, use
5187 -- their prebuilt aggregate form directly.
5189 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
5191 if Present
(Aggr_Init
) then
5193 (N
, New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
5195 -- If type has discriminants, try to build an equivalent
5196 -- aggregate using discriminant values from the declaration.
5197 -- This is a useful optimization, in particular if restriction
5198 -- No_Elaboration_Code is active.
5200 elsif Build_Equivalent_Aggregate
then
5203 -- Otherwise invoke the type init proc
5206 Obj_Ref
:= New_Object_Reference
;
5208 if Comes_From_Source
(Def_Id
) then
5209 Initialization_Warning
(Obj_Ref
);
5212 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
5216 -- Provide a default value if the object needs simple initialization
5217 -- and does not already have an initial value. A generated temporary
5218 -- do not require initialization because it will be assigned later.
5220 elsif Needs_Simple_Initialization
5221 (Typ
, Initialize_Scalars
5222 and then No
(Following_Address_Clause
(N
)))
5223 and then not Is_Internal
(Def_Id
)
5224 and then not Has_Init_Expression
(N
)
5226 Set_No_Initialization
(N
, False);
5227 Set_Expression
(N
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Def_Id
)));
5228 Analyze_And_Resolve
(Expression
(N
), Typ
);
5231 -- Step 3: Add partial finalization and abort actions, generate:
5233 -- Type_Init_Proc (Obj);
5235 -- Deep_Initialize (Obj);
5238 -- Deep_Finalize (Obj, Self => False);
5242 -- Step 3a: Build the finalization block (if applicable)
5244 -- The finalization block is required when both the object and its
5245 -- controlled components are to be initialized. The block finalizes
5246 -- the components if the object initialization fails.
5248 if Has_Controlled_Component
(Typ
)
5249 and then Present
(Comp_Init
)
5250 and then Present
(Obj_Init
)
5251 and then not Restriction_Active
(No_Exception_Propagation
)
5254 -- Type_Init_Proc (Obj);
5256 Fin_Stmts
:= Comp_Init
;
5260 -- Deep_Initialize (Obj);
5263 -- Deep_Finalize (Obj, Self => False);
5269 (Obj_Ref
=> New_Object_Reference
,
5273 if Present
(Fin_Call
) then
5275 -- Do not emit warnings related to the elaboration order when a
5276 -- controlled object is declared before the body of Finalize is
5279 Set_No_Elaboration_Check
(Fin_Call
);
5281 Append_To
(Fin_Stmts
,
5282 Make_Block_Statement
(Loc
,
5283 Declarations
=> No_List
,
5285 Handled_Statement_Sequence
=>
5286 Make_Handled_Sequence_Of_Statements
(Loc
,
5287 Statements
=> New_List
(Obj_Init
),
5289 Exception_Handlers
=> New_List
(
5290 Make_Exception_Handler
(Loc
,
5291 Exception_Choices
=> New_List
(
5292 Make_Others_Choice
(Loc
)),
5294 Statements
=> New_List
(
5296 Make_Raise_Statement
(Loc
)))))));
5299 -- Finalization is not required, the initialization calls are passed
5300 -- to the abort block building circuitry, generate:
5302 -- Type_Init_Proc (Obj);
5303 -- Deep_Initialize (Obj);
5306 if Present
(Comp_Init
) then
5307 Fin_Stmts
:= Comp_Init
;
5310 if Present
(Obj_Init
) then
5311 if No
(Fin_Stmts
) then
5312 Fin_Stmts
:= New_List
;
5315 Append_To
(Fin_Stmts
, Obj_Init
);
5319 -- Step 3b: Build the abort block (if applicable)
5321 -- The abort block is required when aborts are allowed in order to
5322 -- protect both initialization calls.
5324 if Present
(Comp_Init
) and then Present
(Obj_Init
) then
5325 if Abort_Allowed
then
5331 (Fin_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
5336 -- <finalization statements>
5338 -- Abort_Undefer_Direct;
5342 AUD
: constant Entity_Id
:= RTE
(RE_Abort_Undefer_Direct
);
5346 Make_Handled_Sequence_Of_Statements
(Loc
,
5347 Statements
=> Fin_Stmts
,
5348 At_End_Proc
=> New_Occurrence_Of
(AUD
, Loc
));
5350 -- Present the Abort_Undefer_Direct function to the backend
5351 -- so that it can inline the call to the function.
5353 Add_Inlined_Body
(AUD
, N
);
5357 Make_Block_Statement
(Loc
,
5358 Declarations
=> No_List
,
5359 Handled_Statement_Sequence
=> Abrt_HSS
);
5361 Add_Block_Identifier
(Abrt_Blk
, Abrt_Id
);
5362 Expand_At_End_Handler
(Abrt_HSS
, Abrt_Id
);
5364 Abrt_Stmts
:= New_List
(Abrt_Blk
);
5366 -- Abort is not required
5369 -- Generate a dummy entity to ensure that the internal symbols
5370 -- are in sync when a unit is compiled with and without aborts.
5371 -- The entity is a block with proper scope and type.
5373 Dummy
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
5374 Set_Etype
(Dummy
, Standard_Void_Type
);
5375 Abrt_Stmts
:= Fin_Stmts
;
5378 -- No initialization calls present
5381 Abrt_Stmts
:= Fin_Stmts
;
5384 -- Step 4: Insert the whole initialization sequence into the tree
5385 -- If the object has a delayed freeze, as will be the case when
5386 -- it has aspect specifications, the initialization sequence is
5387 -- part of the freeze actions.
5389 if Has_Delayed_Freeze
(Def_Id
) then
5390 Append_Freeze_Actions
(Def_Id
, Abrt_Stmts
);
5392 Insert_Actions_After
(After
, Abrt_Stmts
);
5394 end Default_Initialize_Object
;
5396 ---------------------
5397 -- Restore_Globals --
5398 ---------------------
5400 procedure Restore_Globals
is
5403 end Restore_Globals
;
5405 -------------------------
5406 -- Rewrite_As_Renaming --
5407 -------------------------
5409 function Rewrite_As_Renaming
return Boolean is
5411 return not Aliased_Present
(N
)
5412 and then Is_Entity_Name
(Expr_Q
)
5413 and then Ekind
(Entity
(Expr_Q
)) = E_Variable
5414 and then OK_To_Rename
(Entity
(Expr_Q
))
5415 and then Is_Entity_Name
(Obj_Def
);
5416 end Rewrite_As_Renaming
;
5420 Next_N
: constant Node_Id
:= Next
(N
);
5422 Tag_Assign
: Node_Id
;
5424 Init_After
: Node_Id
:= N
;
5425 -- Node after which the initialization actions are to be inserted. This
5426 -- is normally N, except for the case of a shared passive variable, in
5427 -- which case the init proc call must be inserted only after the bodies
5428 -- of the shared variable procedures have been seen.
5430 -- Start of processing for Expand_N_Object_Declaration
5433 -- Don't do anything for deferred constants. All proper actions will be
5434 -- expanded during the full declaration.
5436 if No
(Expr
) and Constant_Present
(N
) then
5440 -- The type of the object cannot be abstract. This is diagnosed at the
5441 -- point the object is frozen, which happens after the declaration is
5442 -- fully expanded, so simply return now.
5444 if Is_Abstract_Type
(Typ
) then
5448 -- The object declaration may be subject to pragma Ghost with policy
5449 -- Ignore. Set the mode now to ensure that any nodes generated during
5450 -- expansion are properly flagged as ignored Ghost.
5454 -- First we do special processing for objects of a tagged type where
5455 -- this is the point at which the type is frozen. The creation of the
5456 -- dispatch table and the initialization procedure have to be deferred
5457 -- to this point, since we reference previously declared primitive
5460 -- Force construction of dispatch tables of library level tagged types
5462 if Tagged_Type_Expansion
5463 and then Static_Dispatch_Tables
5464 and then Is_Library_Level_Entity
(Def_Id
)
5465 and then Is_Library_Level_Tagged_Type
(Base_Typ
)
5466 and then Ekind_In
(Base_Typ
, E_Record_Type
,
5469 and then not Has_Dispatch_Table
(Base_Typ
)
5472 New_Nodes
: List_Id
:= No_List
;
5475 if Is_Concurrent_Type
(Base_Typ
) then
5476 New_Nodes
:= Make_DT
(Corresponding_Record_Type
(Base_Typ
), N
);
5478 New_Nodes
:= Make_DT
(Base_Typ
, N
);
5481 if not Is_Empty_List
(New_Nodes
) then
5482 Insert_List_Before
(N
, New_Nodes
);
5487 -- Make shared memory routines for shared passive variable
5489 if Is_Shared_Passive
(Def_Id
) then
5490 Init_After
:= Make_Shared_Var_Procs
(N
);
5493 -- If tasks being declared, make sure we have an activation chain
5494 -- defined for the tasks (has no effect if we already have one), and
5495 -- also that a Master variable is established and that the appropriate
5496 -- enclosing construct is established as a task master.
5498 if Has_Task
(Typ
) then
5499 Build_Activation_Chain_Entity
(N
);
5500 Build_Master_Entity
(Def_Id
);
5503 -- Default initialization required, and no expression present
5507 -- If we have a type with a variant part, the initialization proc
5508 -- will contain implicit tests of the discriminant values, which
5509 -- counts as a violation of the restriction No_Implicit_Conditionals.
5511 if Has_Variant_Part
(Typ
) then
5516 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
5520 ("\initialization of variant record tests discriminants",
5527 -- For the default initialization case, if we have a private type
5528 -- with invariants, and invariant checks are enabled, then insert an
5529 -- invariant check after the object declaration. Note that it is OK
5530 -- to clobber the object with an invalid value since if the exception
5531 -- is raised, then the object will go out of scope. In the case where
5532 -- an array object is initialized with an aggregate, the expression
5533 -- is removed. Check flag Has_Init_Expression to avoid generating a
5534 -- junk invariant check and flag No_Initialization to avoid checking
5535 -- an uninitialized object such as a compiler temporary used for an
5538 if Has_Invariants
(Base_Typ
)
5539 and then Present
(Invariant_Procedure
(Base_Typ
))
5540 and then not Has_Init_Expression
(N
)
5541 and then not No_Initialization
(N
)
5543 -- If entity has an address clause or aspect, make invariant
5544 -- call into a freeze action for the explicit freeze node for
5545 -- object. Otherwise insert invariant check after declaration.
5547 if Present
(Following_Address_Clause
(N
))
5548 or else Has_Aspect
(Def_Id
, Aspect_Address
)
5550 Ensure_Freeze_Node
(Def_Id
);
5551 Set_Has_Delayed_Freeze
(Def_Id
);
5552 Set_Is_Frozen
(Def_Id
, False);
5554 if not Partial_View_Has_Unknown_Discr
(Typ
) then
5555 Append_Freeze_Action
(Def_Id
,
5556 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
5559 elsif not Partial_View_Has_Unknown_Discr
(Typ
) then
5561 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
5565 Default_Initialize_Object
(Init_After
);
5567 -- Generate attribute for Persistent_BSS if needed
5569 if Persistent_BSS_Mode
5570 and then Comes_From_Source
(N
)
5571 and then Is_Potentially_Persistent_Type
(Typ
)
5572 and then not Has_Init_Expression
(N
)
5573 and then Is_Library_Level_Entity
(Def_Id
)
5579 Make_Linker_Section_Pragma
5580 (Def_Id
, Sloc
(N
), ".persistent.bss");
5581 Insert_After
(N
, Prag
);
5586 -- If access type, then we know it is null if not initialized
5588 if Is_Access_Type
(Typ
) then
5589 Set_Is_Known_Null
(Def_Id
);
5592 -- Explicit initialization present
5595 -- Obtain actual expression from qualified expression
5597 if Nkind
(Expr
) = N_Qualified_Expression
then
5598 Expr_Q
:= Expression
(Expr
);
5603 -- When we have the appropriate type of aggregate in the expression
5604 -- (it has been determined during analysis of the aggregate by
5605 -- setting the delay flag), let's perform in place assignment and
5606 -- thus avoid creating a temporary.
5608 if Is_Delayed_Aggregate
(Expr_Q
) then
5609 Convert_Aggr_In_Object_Decl
(N
);
5611 -- Ada 2005 (AI-318-02): If the initialization expression is a call
5612 -- to a build-in-place function, then access to the declared object
5613 -- must be passed to the function. Currently we limit such functions
5614 -- to those with constrained limited result subtypes, but eventually
5615 -- plan to expand the allowed forms of functions that are treated as
5618 elsif Ada_Version
>= Ada_2005
5619 and then Is_Build_In_Place_Function_Call
(Expr_Q
)
5621 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
5624 -- The previous call expands the expression initializing the
5625 -- built-in-place object into further code that will be analyzed
5626 -- later. No further expansion needed here.
5630 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
5631 -- class-wide interface object to ensure that we copy the full
5632 -- object, unless we are targetting a VM where interfaces are handled
5633 -- by VM itself. Note that if the root type of Typ is an ancestor of
5634 -- Expr's type, both types share the same dispatch table and there is
5635 -- no need to displace the pointer.
5637 elsif Is_Interface
(Typ
)
5639 -- Avoid never-ending recursion because if Equivalent_Type is set
5640 -- then we've done it already and must not do it again.
5643 (Nkind
(Obj_Def
) = N_Identifier
5644 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
5646 pragma Assert
(Is_Class_Wide_Type
(Typ
));
5648 -- If the object is a return object of an inherently limited type,
5649 -- which implies build-in-place treatment, bypass the special
5650 -- treatment of class-wide interface initialization below. In this
5651 -- case, the expansion of the return statement will take care of
5652 -- creating the object (via allocator) and initializing it.
5654 if Is_Return_Object
(Def_Id
) and then Is_Limited_View
(Typ
) then
5657 elsif Tagged_Type_Expansion
then
5659 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
5660 Expr_N
: Node_Id
:= Expr
;
5661 Expr_Typ
: Entity_Id
;
5667 -- If the original node of the expression was a conversion
5668 -- to this specific class-wide interface type then restore
5669 -- the original node because we must copy the object before
5670 -- displacing the pointer to reference the secondary tag
5671 -- component. This code must be kept synchronized with the
5672 -- expansion done by routine Expand_Interface_Conversion
5674 if not Comes_From_Source
(Expr_N
)
5675 and then Nkind
(Expr_N
) = N_Explicit_Dereference
5676 and then Nkind
(Original_Node
(Expr_N
)) = N_Type_Conversion
5677 and then Etype
(Original_Node
(Expr_N
)) = Typ
5679 Rewrite
(Expr_N
, Original_Node
(Expression
(N
)));
5682 -- Avoid expansion of redundant interface conversion
5684 if Is_Interface
(Etype
(Expr_N
))
5685 and then Nkind
(Expr_N
) = N_Type_Conversion
5686 and then Etype
(Expr_N
) = Typ
5688 Expr_N
:= Expression
(Expr_N
);
5689 Set_Expression
(N
, Expr_N
);
5692 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_N
);
5693 Expr_Typ
:= Base_Type
(Etype
(Expr_N
));
5695 if Is_Class_Wide_Type
(Expr_Typ
) then
5696 Expr_Typ
:= Root_Type
(Expr_Typ
);
5700 -- CW : I'Class := Obj;
5703 -- type Ityp is not null access I'Class;
5704 -- CW : I'Class renames Ityp (Tmp.I_Tag'Address).all;
5706 if Comes_From_Source
(Expr_N
)
5707 and then Nkind
(Expr_N
) = N_Identifier
5708 and then not Is_Interface
(Expr_Typ
)
5709 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
5710 and then (Expr_Typ
= Etype
(Expr_Typ
)
5712 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
5717 Make_Object_Declaration
(Loc
,
5718 Defining_Identifier
=> Obj_Id
,
5719 Object_Definition
=>
5720 New_Occurrence_Of
(Expr_Typ
, Loc
),
5721 Expression
=> Relocate_Node
(Expr_N
)));
5723 -- Statically reference the tag associated with the
5727 Make_Selected_Component
(Loc
,
5728 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
5731 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
5734 -- IW : I'Class := Obj;
5736 -- type Equiv_Record is record ... end record;
5737 -- implicit subtype CW is <Class_Wide_Subtype>;
5738 -- Tmp : CW := CW!(Obj);
5739 -- type Ityp is not null access I'Class;
5740 -- IW : I'Class renames
5741 -- Ityp!(Displace (Temp'Address, I'Tag)).all;
5744 -- Generate the equivalent record type and update the
5745 -- subtype indication to reference it.
5747 Expand_Subtype_From_Expr
5750 Subtype_Indic
=> Obj_Def
,
5753 if not Is_Interface
(Etype
(Expr_N
)) then
5754 New_Expr
:= Relocate_Node
(Expr_N
);
5756 -- For interface types we use 'Address which displaces
5757 -- the pointer to the base of the object (if required)
5761 Unchecked_Convert_To
(Etype
(Obj_Def
),
5762 Make_Explicit_Dereference
(Loc
,
5763 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5764 Make_Attribute_Reference
(Loc
,
5765 Prefix
=> Relocate_Node
(Expr_N
),
5766 Attribute_Name
=> Name_Address
))));
5771 if not Is_Limited_Record
(Expr_Typ
) then
5773 Make_Object_Declaration
(Loc
,
5774 Defining_Identifier
=> Obj_Id
,
5775 Object_Definition
=>
5776 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
5777 Expression
=> New_Expr
));
5779 -- Rename limited type object since they cannot be copied
5780 -- This case occurs when the initialization expression
5781 -- has been previously expanded into a temporary object.
5783 else pragma Assert
(not Comes_From_Source
(Expr_Q
));
5785 Make_Object_Renaming_Declaration
(Loc
,
5786 Defining_Identifier
=> Obj_Id
,
5788 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
5790 Unchecked_Convert_To
5791 (Etype
(Obj_Def
), New_Expr
)));
5794 -- Dynamically reference the tag associated with the
5798 Make_Function_Call
(Loc
,
5799 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
5800 Parameter_Associations
=> New_List
(
5801 Make_Attribute_Reference
(Loc
,
5802 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
5803 Attribute_Name
=> Name_Address
),
5805 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
5810 Make_Object_Renaming_Declaration
(Loc
,
5811 Defining_Identifier
=> Make_Temporary
(Loc
, 'D'),
5812 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
5814 Convert_Tag_To_Interface
(Typ
, Tag_Comp
)));
5816 -- If the original entity comes from source, then mark the
5817 -- new entity as needing debug information, even though it's
5818 -- defined by a generated renaming that does not come from
5819 -- source, so that Materialize_Entity will be set on the
5820 -- entity when Debug_Renaming_Declaration is called during
5823 if Comes_From_Source
(Def_Id
) then
5824 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
5827 Analyze
(N
, Suppress
=> All_Checks
);
5829 -- Replace internal identifier of rewritten node by the
5830 -- identifier found in the sources. We also have to exchange
5831 -- entities containing their defining identifiers to ensure
5832 -- the correct replacement of the object declaration by this
5833 -- object renaming declaration because these identifiers
5834 -- were previously added by Enter_Name to the current scope.
5835 -- We must preserve the homonym chain of the source entity
5836 -- as well. We must also preserve the kind of the entity,
5837 -- which may be a constant. Preserve entity chain because
5838 -- itypes may have been generated already, and the full
5839 -- chain must be preserved for final freezing. Finally,
5840 -- preserve Comes_From_Source setting, so that debugging
5841 -- and cross-referencing information is properly kept, and
5842 -- preserve source location, to prevent spurious errors when
5843 -- entities are declared (they must have their own Sloc).
5846 New_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5847 Next_Temp
: constant Entity_Id
:= Next_Entity
(New_Id
);
5848 S_Flag
: constant Boolean :=
5849 Comes_From_Source
(Def_Id
);
5852 Set_Next_Entity
(New_Id
, Next_Entity
(Def_Id
));
5853 Set_Next_Entity
(Def_Id
, Next_Temp
);
5855 Set_Chars
(Defining_Identifier
(N
), Chars
(Def_Id
));
5856 Set_Homonym
(Defining_Identifier
(N
), Homonym
(Def_Id
));
5857 Set_Ekind
(Defining_Identifier
(N
), Ekind
(Def_Id
));
5858 Set_Sloc
(Defining_Identifier
(N
), Sloc
(Def_Id
));
5860 Set_Comes_From_Source
(Def_Id
, False);
5861 Exchange_Entities
(Defining_Identifier
(N
), Def_Id
);
5862 Set_Comes_From_Source
(Def_Id
, S_Flag
);
5870 -- Common case of explicit object initialization
5873 -- In most cases, we must check that the initial value meets any
5874 -- constraint imposed by the declared type. However, there is one
5875 -- very important exception to this rule. If the entity has an
5876 -- unconstrained nominal subtype, then it acquired its constraints
5877 -- from the expression in the first place, and not only does this
5878 -- mean that the constraint check is not needed, but an attempt to
5879 -- perform the constraint check can cause order of elaboration
5882 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
5884 -- If this is an allocator for an aggregate that has been
5885 -- allocated in place, delay checks until assignments are
5886 -- made, because the discriminants are not initialized.
5888 if Nkind
(Expr
) = N_Allocator
and then No_Initialization
(Expr
)
5892 -- Otherwise apply a constraint check now if no prev error
5894 elsif Nkind
(Expr
) /= N_Error
then
5895 Apply_Constraint_Check
(Expr
, Typ
);
5897 -- Deal with possible range check
5899 if Do_Range_Check
(Expr
) then
5901 -- If assignment checks are suppressed, turn off flag
5903 if Suppress_Assignment_Checks
(N
) then
5904 Set_Do_Range_Check
(Expr
, False);
5906 -- Otherwise generate the range check
5909 Generate_Range_Check
5910 (Expr
, Typ
, CE_Range_Check_Failed
);
5916 -- If the type is controlled and not inherently limited, then
5917 -- the target is adjusted after the copy and attached to the
5918 -- finalization list. However, no adjustment is done in the case
5919 -- where the object was initialized by a call to a function whose
5920 -- result is built in place, since no copy occurred. (Eventually
5921 -- we plan to support in-place function results for some cases
5922 -- of nonlimited types. ???) Similarly, no adjustment is required
5923 -- if we are going to rewrite the object declaration into a
5924 -- renaming declaration.
5926 if Needs_Finalization
(Typ
)
5927 and then not Is_Limited_View
(Typ
)
5928 and then not Rewrite_As_Renaming
5930 Insert_Action_After
(Init_After
,
5932 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
5936 -- For tagged types, when an init value is given, the tag has to
5937 -- be re-initialized separately in order to avoid the propagation
5938 -- of a wrong tag coming from a view conversion unless the type
5939 -- is class wide (in this case the tag comes from the init value).
5940 -- Suppress the tag assignment when VM_Target because VM tags are
5941 -- represented implicitly in objects. Ditto for types that are
5942 -- CPP_CLASS, and for initializations that are aggregates, because
5943 -- they have to have the right tag.
5945 -- The re-assignment of the tag has to be done even if the object
5946 -- is a constant. The assignment must be analyzed after the
5947 -- declaration. If an address clause follows, this is handled as
5948 -- part of the freeze actions for the object, otherwise insert
5949 -- tag assignment here.
5951 Tag_Assign
:= Make_Tag_Assignment
(N
);
5953 if Present
(Tag_Assign
) then
5954 if Present
(Following_Address_Clause
(N
)) then
5955 Ensure_Freeze_Node
(Def_Id
);
5958 Insert_Action_After
(Init_After
, Tag_Assign
);
5961 -- Handle C++ constructor calls. Note that we do not check that
5962 -- Typ is a tagged type since the equivalent Ada type of a C++
5963 -- class that has no virtual methods is an untagged limited
5966 elsif Is_CPP_Constructor_Call
(Expr
) then
5968 -- The call to the initialization procedure does NOT freeze the
5969 -- object being initialized.
5971 Id_Ref
:= New_Occurrence_Of
(Def_Id
, Loc
);
5972 Set_Must_Not_Freeze
(Id_Ref
);
5973 Set_Assignment_OK
(Id_Ref
);
5975 Insert_Actions_After
(Init_After
,
5976 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
5977 Constructor_Ref
=> Expr
));
5979 -- We remove here the original call to the constructor
5980 -- to avoid its management in the backend
5982 Set_Expression
(N
, Empty
);
5986 -- Handle initialization of limited tagged types
5988 elsif Is_Tagged_Type
(Typ
)
5989 and then Is_Class_Wide_Type
(Typ
)
5990 and then Is_Limited_Record
(Typ
)
5992 -- Given that the type is limited we cannot perform a copy. If
5993 -- Expr_Q is the reference to a variable we mark the variable
5994 -- as OK_To_Rename to expand this declaration into a renaming
5995 -- declaration (see bellow).
5997 if Is_Entity_Name
(Expr_Q
) then
5998 Set_OK_To_Rename
(Entity
(Expr_Q
));
6000 -- If we cannot convert the expression into a renaming we must
6001 -- consider it an internal error because the backend does not
6002 -- have support to handle it.
6005 pragma Assert
(False);
6006 raise Program_Error
;
6009 -- For discrete types, set the Is_Known_Valid flag if the
6010 -- initializing value is known to be valid. Only do this for
6011 -- source assignments, since otherwise we can end up turning
6012 -- on the known valid flag prematurely from inserted code.
6014 elsif Comes_From_Source
(N
)
6015 and then Is_Discrete_Type
(Typ
)
6016 and then Expr_Known_Valid
(Expr
)
6018 Set_Is_Known_Valid
(Def_Id
);
6020 elsif Is_Access_Type
(Typ
) then
6022 -- For access types set the Is_Known_Non_Null flag if the
6023 -- initializing value is known to be non-null. We can also set
6024 -- Can_Never_Be_Null if this is a constant.
6026 if Known_Non_Null
(Expr
) then
6027 Set_Is_Known_Non_Null
(Def_Id
, True);
6029 if Constant_Present
(N
) then
6030 Set_Can_Never_Be_Null
(Def_Id
);
6035 -- If validity checking on copies, validate initial expression.
6036 -- But skip this if declaration is for a generic type, since it
6037 -- makes no sense to validate generic types. Not clear if this
6038 -- can happen for legal programs, but it definitely can arise
6039 -- from previous instantiation errors.
6041 if Validity_Checks_On
6042 and then Validity_Check_Copies
6043 and then not Is_Generic_Type
(Etype
(Def_Id
))
6045 Ensure_Valid
(Expr
);
6046 Set_Is_Known_Valid
(Def_Id
);
6050 -- Cases where the back end cannot handle the initialization directly
6051 -- In such cases, we expand an assignment that will be appropriately
6052 -- handled by Expand_N_Assignment_Statement.
6054 -- The exclusion of the unconstrained case is wrong, but for now it
6055 -- is too much trouble ???
6057 if (Is_Possibly_Unaligned_Slice
(Expr
)
6058 or else (Is_Possibly_Unaligned_Object
(Expr
)
6059 and then not Represented_As_Scalar
(Etype
(Expr
))))
6060 and then not (Is_Array_Type
(Etype
(Expr
))
6061 and then not Is_Constrained
(Etype
(Expr
)))
6064 Stat
: constant Node_Id
:=
6065 Make_Assignment_Statement
(Loc
,
6066 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
6067 Expression
=> Relocate_Node
(Expr
));
6069 Set_Expression
(N
, Empty
);
6070 Set_No_Initialization
(N
);
6071 Set_Assignment_OK
(Name
(Stat
));
6072 Set_No_Ctrl_Actions
(Stat
);
6073 Insert_After_And_Analyze
(Init_After
, Stat
);
6077 -- Final transformation, if the initializing expression is an entity
6078 -- for a variable with OK_To_Rename set, then we transform:
6084 -- X : typ renames expr
6086 -- provided that X is not aliased. The aliased case has to be
6087 -- excluded in general because Expr will not be aliased in general.
6089 if Rewrite_As_Renaming
then
6091 Make_Object_Renaming_Declaration
(Loc
,
6092 Defining_Identifier
=> Defining_Identifier
(N
),
6093 Subtype_Mark
=> Obj_Def
,
6096 -- We do not analyze this renaming declaration, because all its
6097 -- components have already been analyzed, and if we were to go
6098 -- ahead and analyze it, we would in effect be trying to generate
6099 -- another declaration of X, which won't do.
6101 Set_Renamed_Object
(Defining_Identifier
(N
), Expr_Q
);
6104 -- We do need to deal with debug issues for this renaming
6106 -- First, if entity comes from source, then mark it as needing
6107 -- debug information, even though it is defined by a generated
6108 -- renaming that does not come from source.
6110 if Comes_From_Source
(Defining_Identifier
(N
)) then
6111 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
6114 -- Now call the routine to generate debug info for the renaming
6117 Decl
: constant Node_Id
:= Debug_Renaming_Declaration
(N
);
6119 if Present
(Decl
) then
6120 Insert_Action
(N
, Decl
);
6126 if Nkind
(N
) = N_Object_Declaration
6127 and then Nkind
(Obj_Def
) = N_Access_Definition
6128 and then not Is_Local_Anonymous_Access
(Etype
(Def_Id
))
6130 -- An Ada 2012 stand-alone object of an anonymous access type
6133 Loc
: constant Source_Ptr
:= Sloc
(N
);
6135 Level
: constant Entity_Id
:=
6136 Make_Defining_Identifier
(Sloc
(N
),
6138 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
6140 Level_Expr
: Node_Id
;
6141 Level_Decl
: Node_Id
;
6144 Set_Ekind
(Level
, Ekind
(Def_Id
));
6145 Set_Etype
(Level
, Standard_Natural
);
6146 Set_Scope
(Level
, Scope
(Def_Id
));
6150 -- Set accessibility level of null
6153 Make_Integer_Literal
(Loc
, Scope_Depth
(Standard_Standard
));
6156 Level_Expr
:= Dynamic_Accessibility_Level
(Expr
);
6160 Make_Object_Declaration
(Loc
,
6161 Defining_Identifier
=> Level
,
6162 Object_Definition
=>
6163 New_Occurrence_Of
(Standard_Natural
, Loc
),
6164 Expression
=> Level_Expr
,
6165 Constant_Present
=> Constant_Present
(N
),
6166 Has_Init_Expression
=> True);
6168 Insert_Action_After
(Init_After
, Level_Decl
);
6170 Set_Extra_Accessibility
(Def_Id
, Level
);
6174 -- If the object is default initialized and its type is subject to
6175 -- pragma Default_Initial_Condition, add a runtime check to verify
6176 -- the assumption of the pragma (SPARK RM 7.3.3). Generate:
6178 -- <Base_Typ>Default_Init_Cond (<Base_Typ> (Def_Id));
6180 -- Note that the check is generated for source objects only
6182 if Comes_From_Source
(Def_Id
)
6183 and then (Has_Default_Init_Cond
(Typ
)
6185 Has_Inherited_Default_Init_Cond
(Typ
))
6186 and then not Has_Init_Expression
(N
)
6189 DIC_Call
: constant Node_Id
:=
6190 Build_Default_Init_Cond_Call
(Loc
, Def_Id
, Typ
);
6192 if Present
(Next_N
) then
6193 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
6195 -- The object declaration is the last node in a declarative or a
6199 Append_To
(List_Containing
(N
), DIC_Call
);
6207 -- Exception on library entity not available
6210 when RE_Not_Available
=>
6213 end Expand_N_Object_Declaration
;
6215 ---------------------------------
6216 -- Expand_N_Subtype_Indication --
6217 ---------------------------------
6219 -- Add a check on the range of the subtype. The static case is partially
6220 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
6221 -- to check here for the static case in order to avoid generating
6222 -- extraneous expanded code. Also deal with validity checking.
6224 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
6225 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6226 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
6229 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
6230 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
6233 if Nkind_In
(Parent
(N
), N_Constrained_Array_Definition
, N_Slice
) then
6234 Apply_Range_Check
(Ran
, Typ
);
6236 end Expand_N_Subtype_Indication
;
6238 ---------------------------
6239 -- Expand_N_Variant_Part --
6240 ---------------------------
6242 -- Note: this procedure no longer has any effect. It used to be that we
6243 -- would replace the choices in the last variant by a when others, and
6244 -- also expanded static predicates in variant choices here, but both of
6245 -- those activities were being done too early, since we can't check the
6246 -- choices until the statically predicated subtypes are frozen, which can
6247 -- happen as late as the free point of the record, and we can't change the
6248 -- last choice to an others before checking the choices, which is now done
6249 -- at the freeze point of the record.
6251 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
6254 end Expand_N_Variant_Part
;
6256 ---------------------------------
6257 -- Expand_Previous_Access_Type --
6258 ---------------------------------
6260 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
6261 Ptr_Typ
: Entity_Id
;
6264 -- Find all access types in the current scope whose designated type is
6265 -- Def_Id and build master renamings for them.
6267 Ptr_Typ
:= First_Entity
(Current_Scope
);
6268 while Present
(Ptr_Typ
) loop
6269 if Is_Access_Type
(Ptr_Typ
)
6270 and then Designated_Type
(Ptr_Typ
) = Def_Id
6271 and then No
(Master_Id
(Ptr_Typ
))
6273 -- Ensure that the designated type has a master
6275 Build_Master_Entity
(Def_Id
);
6277 -- Private and incomplete types complicate the insertion of master
6278 -- renamings because the access type may precede the full view of
6279 -- the designated type. For this reason, the master renamings are
6280 -- inserted relative to the designated type.
6282 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
6285 Next_Entity
(Ptr_Typ
);
6287 end Expand_Previous_Access_Type
;
6289 ------------------------
6290 -- Expand_Tagged_Root --
6291 ------------------------
6293 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
6294 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
6295 Comp_List
: Node_Id
;
6296 Comp_Decl
: Node_Id
;
6297 Sloc_N
: Source_Ptr
;
6300 if Null_Present
(Def
) then
6301 Set_Component_List
(Def
,
6302 Make_Component_List
(Sloc
(Def
),
6303 Component_Items
=> Empty_List
,
6304 Variant_Part
=> Empty
,
6305 Null_Present
=> True));
6308 Comp_List
:= Component_List
(Def
);
6310 if Null_Present
(Comp_List
)
6311 or else Is_Empty_List
(Component_Items
(Comp_List
))
6313 Sloc_N
:= Sloc
(Comp_List
);
6315 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
6319 Make_Component_Declaration
(Sloc_N
,
6320 Defining_Identifier
=> First_Tag_Component
(T
),
6321 Component_Definition
=>
6322 Make_Component_Definition
(Sloc_N
,
6323 Aliased_Present
=> False,
6324 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
6326 if Null_Present
(Comp_List
)
6327 or else Is_Empty_List
(Component_Items
(Comp_List
))
6329 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
6330 Set_Null_Present
(Comp_List
, False);
6333 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
6336 -- We don't Analyze the whole expansion because the tag component has
6337 -- already been analyzed previously. Here we just insure that the tree
6338 -- is coherent with the semantic decoration
6340 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
6343 when RE_Not_Available
=>
6345 end Expand_Tagged_Root
;
6347 ----------------------
6348 -- Clean_Task_Names --
6349 ----------------------
6351 procedure Clean_Task_Names
6353 Proc_Id
: Entity_Id
)
6357 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
6358 and then not Global_Discard_Names
6359 and then Tagged_Type_Expansion
6361 Set_Uses_Sec_Stack
(Proc_Id
);
6363 end Clean_Task_Names
;
6365 ------------------------------
6366 -- Expand_Freeze_Array_Type --
6367 ------------------------------
6369 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
6370 Typ
: constant Entity_Id
:= Entity
(N
);
6371 Base
: constant Entity_Id
:= Base_Type
(Typ
);
6372 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
6376 if not Is_Bit_Packed_Array
(Typ
) then
6378 -- If the component contains tasks, so does the array type. This may
6379 -- not be indicated in the array type because the component may have
6380 -- been a private type at the point of definition. Same if component
6381 -- type is controlled or contains protected objects.
6383 Set_Has_Task
(Base
, Has_Task
(Comp_Typ
));
6384 Set_Has_Protected
(Base
, Has_Protected
(Comp_Typ
));
6385 Set_Has_Controlled_Component
6386 (Base
, Has_Controlled_Component
6389 Is_Controlled
(Comp_Typ
));
6391 if No
(Init_Proc
(Base
)) then
6393 -- If this is an anonymous array created for a declaration with
6394 -- an initial value, its init_proc will never be called. The
6395 -- initial value itself may have been expanded into assignments,
6396 -- in which case the object declaration is carries the
6397 -- No_Initialization flag.
6400 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
6401 N_Object_Declaration
6403 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
6404 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
6408 -- We do not need an init proc for string or wide [wide] string,
6409 -- since the only time these need initialization in normalize or
6410 -- initialize scalars mode, and these types are treated specially
6411 -- and do not need initialization procedures.
6413 elsif Is_Standard_String_Type
(Base
) then
6416 -- Otherwise we have to build an init proc for the subtype
6419 Build_Array_Init_Proc
(Base
, N
);
6424 if Has_Controlled_Component
(Base
) then
6425 Build_Controlling_Procs
(Base
);
6427 if not Is_Limited_Type
(Comp_Typ
)
6428 and then Number_Dimensions
(Typ
) = 1
6430 Build_Slice_Assignment
(Typ
);
6434 -- Create a finalization master to service the anonymous access
6435 -- components of the array.
6437 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
6438 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
6440 -- The finalization master is inserted before the declaration
6441 -- of the array type. The only exception to this is when the
6442 -- array type is an itype, in which case the master appears
6443 -- before the related context.
6445 if Is_Itype
(Typ
) then
6446 Ins_Node
:= Associated_Node_For_Itype
(Typ
);
6448 Ins_Node
:= Parent
(Typ
);
6451 Build_Finalization_Master
6453 For_Anonymous
=> True,
6454 Context_Scope
=> Scope
(Typ
),
6455 Insertion_Node
=> Ins_Node
);
6459 -- For packed case, default initialization, except if the component type
6460 -- is itself a packed structure with an initialization procedure, or
6461 -- initialize/normalize scalars active, and we have a base type, or the
6462 -- type is public, because in that case a client might specify
6463 -- Normalize_Scalars and there better be a public Init_Proc for it.
6465 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
6466 and then No
(Base_Init_Proc
(Base
)))
6467 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
6468 or else Is_Public
(Typ
)
6470 Build_Array_Init_Proc
(Base
, N
);
6473 if Has_Invariants
(Component_Type
(Base
))
6475 and then In_Open_Scopes
(Scope
(Component_Type
(Base
)))
6477 -- Generate component invariant checking procedure. This is only
6478 -- relevant if the array type is within the scope of the component
6479 -- type. Otherwise an array object can only be built using the public
6480 -- subprograms for the component type, and calls to those will have
6481 -- invariant checks. The invariant procedure is only generated for
6482 -- a base type, not a subtype.
6484 Insert_Component_Invariant_Checks
6485 (N
, Base
, Build_Array_Invariant_Proc
(Base
, N
));
6487 end Expand_Freeze_Array_Type
;
6489 -----------------------------------
6490 -- Expand_Freeze_Class_Wide_Type --
6491 -----------------------------------
6493 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
6494 Typ
: constant Entity_Id
:= Entity
(N
);
6495 Root
: constant Entity_Id
:= Root_Type
(Typ
);
6497 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
6498 -- Given a type, determine whether it is derived from a C or C++ root
6500 ---------------------
6501 -- Is_C_Derivation --
6502 ---------------------
6504 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
6511 or else Convention
(T
) = Convention_C
6512 or else Convention
(T
) = Convention_CPP
6517 exit when T
= Etype
(T
);
6523 end Is_C_Derivation
;
6525 -- Start of processing for Expand_Freeze_Class_Wide_Type
6528 -- Certain run-time configurations and targets do not provide support
6529 -- for controlled types.
6531 if Restriction_Active
(No_Finalization
) then
6534 -- Do not create TSS routine Finalize_Address when dispatching calls are
6535 -- disabled since the core of the routine is a dispatching call.
6537 elsif Restriction_Active
(No_Dispatching_Calls
) then
6540 -- Do not create TSS routine Finalize_Address for concurrent class-wide
6541 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
6542 -- non-Ada side will handle their destruction.
6544 elsif Is_Concurrent_Type
(Root
)
6545 or else Is_C_Derivation
(Root
)
6546 or else Convention
(Typ
) = Convention_CIL
6547 or else Convention
(Typ
) = Convention_CPP
6548 or else Convention
(Typ
) = Convention_Java
6552 -- Do not create TSS routine Finalize_Address for .NET/JVM because these
6553 -- targets do not support address arithmetic and unchecked conversions.
6555 elsif VM_Target
/= No_VM
then
6558 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
6559 -- mode since the routine contains an Unchecked_Conversion.
6561 elsif CodePeer_Mode
then
6565 -- Create the body of TSS primitive Finalize_Address. This automatically
6566 -- sets the TSS entry for the class-wide type.
6568 Make_Finalize_Address_Body
(Typ
);
6569 end Expand_Freeze_Class_Wide_Type
;
6571 ------------------------------------
6572 -- Expand_Freeze_Enumeration_Type --
6573 ------------------------------------
6575 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
6576 Typ
: constant Entity_Id
:= Entity
(N
);
6577 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6584 Is_Contiguous
: Boolean;
6589 pragma Warnings
(Off
, Func
);
6592 -- Various optimizations possible if given representation is contiguous
6594 Is_Contiguous
:= True;
6596 Ent
:= First_Literal
(Typ
);
6597 Last_Repval
:= Enumeration_Rep
(Ent
);
6600 while Present
(Ent
) loop
6601 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
6602 Is_Contiguous
:= False;
6605 Last_Repval
:= Enumeration_Rep
(Ent
);
6611 if Is_Contiguous
then
6612 Set_Has_Contiguous_Rep
(Typ
);
6613 Ent
:= First_Literal
(Typ
);
6615 Lst
:= New_List
(New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
6618 -- Build list of literal references
6623 Ent
:= First_Literal
(Typ
);
6624 while Present
(Ent
) loop
6625 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
6631 -- Now build an array declaration
6633 -- typA : array (Natural range 0 .. num - 1) of ctype :=
6634 -- (v, v, v, v, v, ....)
6636 -- where ctype is the corresponding integer type. If the representation
6637 -- is contiguous, we only keep the first literal, which provides the
6638 -- offset for Pos_To_Rep computations.
6641 Make_Defining_Identifier
(Loc
,
6642 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
6644 Append_Freeze_Action
(Typ
,
6645 Make_Object_Declaration
(Loc
,
6646 Defining_Identifier
=> Arr
,
6647 Constant_Present
=> True,
6649 Object_Definition
=>
6650 Make_Constrained_Array_Definition
(Loc
,
6651 Discrete_Subtype_Definitions
=> New_List
(
6652 Make_Subtype_Indication
(Loc
,
6653 Subtype_Mark
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
6655 Make_Range_Constraint
(Loc
,
6659 Make_Integer_Literal
(Loc
, 0),
6661 Make_Integer_Literal
(Loc
, Num
- 1))))),
6663 Component_Definition
=>
6664 Make_Component_Definition
(Loc
,
6665 Aliased_Present
=> False,
6666 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
6669 Make_Aggregate
(Loc
,
6670 Expressions
=> Lst
)));
6672 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
6674 -- Now we build the function that converts representation values to
6675 -- position values. This function has the form:
6677 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
6680 -- when enum-lit'Enum_Rep => return posval;
6681 -- when enum-lit'Enum_Rep => return posval;
6684 -- [raise Constraint_Error when F "invalid data"]
6689 -- Note: the F parameter determines whether the others case (no valid
6690 -- representation) raises Constraint_Error or returns a unique value
6691 -- of minus one. The latter case is used, e.g. in 'Valid code.
6693 -- Note: the reason we use Enum_Rep values in the case here is to avoid
6694 -- the code generator making inappropriate assumptions about the range
6695 -- of the values in the case where the value is invalid. ityp is a
6696 -- signed or unsigned integer type of appropriate width.
6698 -- Note: if exceptions are not supported, then we suppress the raise
6699 -- and return -1 unconditionally (this is an erroneous program in any
6700 -- case and there is no obligation to raise Constraint_Error here). We
6701 -- also do this if pragma Restrictions (No_Exceptions) is active.
6703 -- Is this right??? What about No_Exception_Propagation???
6705 -- Representations are signed
6707 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
6709 -- The underlying type is signed. Reset the Is_Unsigned_Type
6710 -- explicitly, because it might have been inherited from
6713 Set_Is_Unsigned_Type
(Typ
, False);
6715 if Esize
(Typ
) <= Standard_Integer_Size
then
6716 Ityp
:= Standard_Integer
;
6718 Ityp
:= Universal_Integer
;
6721 -- Representations are unsigned
6724 if Esize
(Typ
) <= Standard_Integer_Size
then
6725 Ityp
:= RTE
(RE_Unsigned
);
6727 Ityp
:= RTE
(RE_Long_Long_Unsigned
);
6731 -- The body of the function is a case statement. First collect case
6732 -- alternatives, or optimize the contiguous case.
6736 -- If representation is contiguous, Pos is computed by subtracting
6737 -- the representation of the first literal.
6739 if Is_Contiguous
then
6740 Ent
:= First_Literal
(Typ
);
6742 if Enumeration_Rep
(Ent
) = Last_Repval
then
6744 -- Another special case: for a single literal, Pos is zero
6746 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
6750 Convert_To
(Standard_Integer
,
6751 Make_Op_Subtract
(Loc
,
6753 Unchecked_Convert_To
6754 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
6756 Make_Integer_Literal
(Loc
,
6757 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
6761 Make_Case_Statement_Alternative
(Loc
,
6762 Discrete_Choices
=> New_List
(
6763 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
6765 Make_Integer_Literal
(Loc
,
6766 Intval
=> Enumeration_Rep
(Ent
)),
6768 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
6770 Statements
=> New_List
(
6771 Make_Simple_Return_Statement
(Loc
,
6772 Expression
=> Pos_Expr
))));
6775 Ent
:= First_Literal
(Typ
);
6776 while Present
(Ent
) loop
6778 Make_Case_Statement_Alternative
(Loc
,
6779 Discrete_Choices
=> New_List
(
6780 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
6781 Intval
=> Enumeration_Rep
(Ent
))),
6783 Statements
=> New_List
(
6784 Make_Simple_Return_Statement
(Loc
,
6786 Make_Integer_Literal
(Loc
,
6787 Intval
=> Enumeration_Pos
(Ent
))))));
6793 -- In normal mode, add the others clause with the test
6795 if not No_Exception_Handlers_Set
then
6797 Make_Case_Statement_Alternative
(Loc
,
6798 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6799 Statements
=> New_List
(
6800 Make_Raise_Constraint_Error
(Loc
,
6801 Condition
=> Make_Identifier
(Loc
, Name_uF
),
6802 Reason
=> CE_Invalid_Data
),
6803 Make_Simple_Return_Statement
(Loc
,
6805 Make_Integer_Literal
(Loc
, -1)))));
6807 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
6808 -- active then return -1 (we cannot usefully raise Constraint_Error in
6809 -- this case). See description above for further details.
6813 Make_Case_Statement_Alternative
(Loc
,
6814 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6815 Statements
=> New_List
(
6816 Make_Simple_Return_Statement
(Loc
,
6818 Make_Integer_Literal
(Loc
, -1)))));
6821 -- Now we can build the function body
6824 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
6827 Make_Subprogram_Body
(Loc
,
6829 Make_Function_Specification
(Loc
,
6830 Defining_Unit_Name
=> Fent
,
6831 Parameter_Specifications
=> New_List
(
6832 Make_Parameter_Specification
(Loc
,
6833 Defining_Identifier
=>
6834 Make_Defining_Identifier
(Loc
, Name_uA
),
6835 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
6836 Make_Parameter_Specification
(Loc
,
6837 Defining_Identifier
=>
6838 Make_Defining_Identifier
(Loc
, Name_uF
),
6840 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
6842 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
6844 Declarations
=> Empty_List
,
6846 Handled_Statement_Sequence
=>
6847 Make_Handled_Sequence_Of_Statements
(Loc
,
6848 Statements
=> New_List
(
6849 Make_Case_Statement
(Loc
,
6851 Unchecked_Convert_To
6852 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
6853 Alternatives
=> Lst
))));
6855 Set_TSS
(Typ
, Fent
);
6857 -- Set Pure flag (it will be reset if the current context is not Pure).
6858 -- We also pretend there was a pragma Pure_Function so that for purposes
6859 -- of optimization and constant-folding, we will consider the function
6860 -- Pure even if we are not in a Pure context).
6863 Set_Has_Pragma_Pure_Function
(Fent
);
6865 -- Unless we are in -gnatD mode, where we are debugging generated code,
6866 -- this is an internal entity for which we don't need debug info.
6868 if not Debug_Generated_Code
then
6869 Set_Debug_Info_Off
(Fent
);
6873 when RE_Not_Available
=>
6875 end Expand_Freeze_Enumeration_Type
;
6877 -------------------------------
6878 -- Expand_Freeze_Record_Type --
6879 -------------------------------
6881 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
6882 Def_Id
: constant Node_Id
:= Entity
(N
);
6883 Type_Decl
: constant Node_Id
:= Parent
(Def_Id
);
6885 Comp_Typ
: Entity_Id
;
6887 Predef_List
: List_Id
;
6889 Renamed_Eq
: Node_Id
:= Empty
;
6890 -- Defining unit name for the predefined equality function in the case
6891 -- where the type has a primitive operation that is a renaming of
6892 -- predefined equality (but only if there is also an overriding
6893 -- user-defined equality function). Used to pass this entity from
6894 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
6896 Wrapper_Decl_List
: List_Id
:= No_List
;
6897 Wrapper_Body_List
: List_Id
:= No_List
;
6899 -- Start of processing for Expand_Freeze_Record_Type
6902 -- Build discriminant checking functions if not a derived type (for
6903 -- derived types that are not tagged types, always use the discriminant
6904 -- checking functions of the parent type). However, for untagged types
6905 -- the derivation may have taken place before the parent was frozen, so
6906 -- we copy explicitly the discriminant checking functions from the
6907 -- parent into the components of the derived type.
6909 if not Is_Derived_Type
(Def_Id
)
6910 or else Has_New_Non_Standard_Rep
(Def_Id
)
6911 or else Is_Tagged_Type
(Def_Id
)
6913 Build_Discr_Checking_Funcs
(Type_Decl
);
6915 elsif Is_Derived_Type
(Def_Id
)
6916 and then not Is_Tagged_Type
(Def_Id
)
6918 -- If we have a derived Unchecked_Union, we do not inherit the
6919 -- discriminant checking functions from the parent type since the
6920 -- discriminants are non existent.
6922 and then not Is_Unchecked_Union
(Def_Id
)
6923 and then Has_Discriminants
(Def_Id
)
6926 Old_Comp
: Entity_Id
;
6930 First_Component
(Base_Type
(Underlying_Type
(Etype
(Def_Id
))));
6931 Comp
:= First_Component
(Def_Id
);
6932 while Present
(Comp
) loop
6933 if Ekind
(Comp
) = E_Component
6934 and then Chars
(Comp
) = Chars
(Old_Comp
)
6936 Set_Discriminant_Checking_Func
(Comp
,
6937 Discriminant_Checking_Func
(Old_Comp
));
6940 Next_Component
(Old_Comp
);
6941 Next_Component
(Comp
);
6946 if Is_Derived_Type
(Def_Id
)
6947 and then Is_Limited_Type
(Def_Id
)
6948 and then Is_Tagged_Type
(Def_Id
)
6950 Check_Stream_Attributes
(Def_Id
);
6953 -- Update task, protected, and controlled component flags, because some
6954 -- of the component types may have been private at the point of the
6955 -- record declaration. Detect anonymous access-to-controlled components.
6959 Comp
:= First_Component
(Def_Id
);
6960 while Present
(Comp
) loop
6961 Comp_Typ
:= Etype
(Comp
);
6963 if Has_Task
(Comp_Typ
) then
6964 Set_Has_Task
(Def_Id
);
6967 if Has_Protected
(Comp_Typ
) then
6968 Set_Has_Protected
(Def_Id
);
6971 -- Do not set Has_Controlled_Component on a class-wide equivalent
6972 -- type. See Make_CW_Equivalent_Type.
6974 if not Is_Class_Wide_Equivalent_Type
(Def_Id
)
6976 (Has_Controlled_Component
(Comp_Typ
)
6977 or else (Chars
(Comp
) /= Name_uParent
6978 and then (Is_Controlled_Active
(Comp_Typ
))))
6980 Set_Has_Controlled_Component
(Def_Id
);
6983 -- Non-self-referential anonymous access-to-controlled component
6985 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
6986 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
6987 and then Designated_Type
(Comp_Typ
) /= Def_Id
6992 Next_Component
(Comp
);
6995 -- Handle constructors of untagged CPP_Class types
6997 if not Is_Tagged_Type
(Def_Id
) and then Is_CPP_Class
(Def_Id
) then
6998 Set_CPP_Constructors
(Def_Id
);
7001 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
7002 -- for regular tagged types as well as for Ada types deriving from a C++
7003 -- Class, but not for tagged types directly corresponding to C++ classes
7004 -- In the later case we assume that it is created in the C++ side and we
7007 if Is_Tagged_Type
(Def_Id
) then
7009 -- Add the _Tag component
7011 if Underlying_Type
(Etype
(Def_Id
)) = Def_Id
then
7012 Expand_Tagged_Root
(Def_Id
);
7015 if Is_CPP_Class
(Def_Id
) then
7016 Set_All_DT_Position
(Def_Id
);
7018 -- Create the tag entities with a minimum decoration
7020 if Tagged_Type_Expansion
then
7021 Append_Freeze_Actions
(Def_Id
, Make_Tags
(Def_Id
));
7024 Set_CPP_Constructors
(Def_Id
);
7027 if not Building_Static_DT
(Def_Id
) then
7029 -- Usually inherited primitives are not delayed but the first
7030 -- Ada extension of a CPP_Class is an exception since the
7031 -- address of the inherited subprogram has to be inserted in
7032 -- the new Ada Dispatch Table and this is a freezing action.
7034 -- Similarly, if this is an inherited operation whose parent is
7035 -- not frozen yet, it is not in the DT of the parent, and we
7036 -- generate an explicit freeze node for the inherited operation
7037 -- so it is properly inserted in the DT of the current type.
7044 Elmt
:= First_Elmt
(Primitive_Operations
(Def_Id
));
7045 while Present
(Elmt
) loop
7046 Subp
:= Node
(Elmt
);
7048 if Present
(Alias
(Subp
)) then
7049 if Is_CPP_Class
(Etype
(Def_Id
)) then
7050 Set_Has_Delayed_Freeze
(Subp
);
7052 elsif Has_Delayed_Freeze
(Alias
(Subp
))
7053 and then not Is_Frozen
(Alias
(Subp
))
7055 Set_Is_Frozen
(Subp
, False);
7056 Set_Has_Delayed_Freeze
(Subp
);
7065 -- Unfreeze momentarily the type to add the predefined primitives
7066 -- operations. The reason we unfreeze is so that these predefined
7067 -- operations will indeed end up as primitive operations (which
7068 -- must be before the freeze point).
7070 Set_Is_Frozen
(Def_Id
, False);
7072 -- Do not add the spec of predefined primitives in case of
7073 -- CPP tagged type derivations that have convention CPP.
7075 if Is_CPP_Class
(Root_Type
(Def_Id
))
7076 and then Convention
(Def_Id
) = Convention_CPP
7080 -- Do not add the spec of predefined primitives in case of
7081 -- CIL and Java tagged types
7083 elsif Convention
(Def_Id
) = Convention_CIL
7084 or else Convention
(Def_Id
) = Convention_Java
7088 -- Do not add the spec of the predefined primitives if we are
7089 -- compiling under restriction No_Dispatching_Calls.
7091 elsif not Restriction_Active
(No_Dispatching_Calls
) then
7092 Make_Predefined_Primitive_Specs
7093 (Def_Id
, Predef_List
, Renamed_Eq
);
7094 Insert_List_Before_And_Analyze
(N
, Predef_List
);
7097 -- Ada 2005 (AI-391): For a nonabstract null extension, create
7098 -- wrapper functions for each nonoverridden inherited function
7099 -- with a controlling result of the type. The wrapper for such
7100 -- a function returns an extension aggregate that invokes the
7103 if Ada_Version
>= Ada_2005
7104 and then not Is_Abstract_Type
(Def_Id
)
7105 and then Is_Null_Extension
(Def_Id
)
7107 Make_Controlling_Function_Wrappers
7108 (Def_Id
, Wrapper_Decl_List
, Wrapper_Body_List
);
7109 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
7112 -- Ada 2005 (AI-251): For a nonabstract type extension, build
7113 -- null procedure declarations for each set of homographic null
7114 -- procedures that are inherited from interface types but not
7115 -- overridden. This is done to ensure that the dispatch table
7116 -- entry associated with such null primitives are properly filled.
7118 if Ada_Version
>= Ada_2005
7119 and then Etype
(Def_Id
) /= Def_Id
7120 and then not Is_Abstract_Type
(Def_Id
)
7121 and then Has_Interfaces
(Def_Id
)
7123 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Def_Id
));
7126 Set_Is_Frozen
(Def_Id
);
7127 if not Is_Derived_Type
(Def_Id
)
7128 or else Is_Tagged_Type
(Etype
(Def_Id
))
7130 Set_All_DT_Position
(Def_Id
);
7132 -- If this is a type derived from an untagged private type whose
7133 -- full view is tagged, the type is marked tagged for layout
7134 -- reasons, but it has no dispatch table.
7136 elsif Is_Derived_Type
(Def_Id
)
7137 and then Is_Private_Type
(Etype
(Def_Id
))
7138 and then not Is_Tagged_Type
(Etype
(Def_Id
))
7143 -- Create and decorate the tags. Suppress their creation when
7144 -- VM_Target because the dispatching mechanism is handled
7145 -- internally by the VMs.
7147 if Tagged_Type_Expansion
then
7148 Append_Freeze_Actions
(Def_Id
, Make_Tags
(Def_Id
));
7150 -- Generate dispatch table of locally defined tagged type.
7151 -- Dispatch tables of library level tagged types are built
7152 -- later (see Analyze_Declarations).
7154 if not Building_Static_DT
(Def_Id
) then
7155 Append_Freeze_Actions
(Def_Id
, Make_DT
(Def_Id
));
7158 elsif VM_Target
/= No_VM
then
7159 Append_Freeze_Actions
(Def_Id
, Make_VM_TSD
(Def_Id
));
7162 -- If the type has unknown discriminants, propagate dispatching
7163 -- information to its underlying record view, which does not get
7164 -- its own dispatch table.
7166 if Is_Derived_Type
(Def_Id
)
7167 and then Has_Unknown_Discriminants
(Def_Id
)
7168 and then Present
(Underlying_Record_View
(Def_Id
))
7171 Rep
: constant Entity_Id
:= Underlying_Record_View
(Def_Id
);
7173 Set_Access_Disp_Table
7174 (Rep
, Access_Disp_Table
(Def_Id
));
7175 Set_Dispatch_Table_Wrappers
7176 (Rep
, Dispatch_Table_Wrappers
(Def_Id
));
7177 Set_Direct_Primitive_Operations
7178 (Rep
, Direct_Primitive_Operations
(Def_Id
));
7182 -- Make sure that the primitives Initialize, Adjust and Finalize
7183 -- are Frozen before other TSS subprograms. We don't want them
7186 if Is_Controlled
(Def_Id
) then
7187 if not Is_Limited_Type
(Def_Id
) then
7188 Append_Freeze_Actions
(Def_Id
,
7190 (Find_Prim_Op
(Def_Id
, Name_Adjust
), Def_Id
));
7193 Append_Freeze_Actions
(Def_Id
,
7195 (Find_Prim_Op
(Def_Id
, Name_Initialize
), Def_Id
));
7197 Append_Freeze_Actions
(Def_Id
,
7199 (Find_Prim_Op
(Def_Id
, Name_Finalize
), Def_Id
));
7202 -- Freeze rest of primitive operations. There is no need to handle
7203 -- the predefined primitives if we are compiling under restriction
7204 -- No_Dispatching_Calls.
7206 if not Restriction_Active
(No_Dispatching_Calls
) then
7207 Append_Freeze_Actions
7208 (Def_Id
, Predefined_Primitive_Freeze
(Def_Id
));
7212 -- In the untagged case, ever since Ada 83 an equality function must
7213 -- be provided for variant records that are not unchecked unions.
7214 -- In Ada 2012 the equality function composes, and thus must be built
7215 -- explicitly just as for tagged records.
7217 elsif Has_Discriminants
(Def_Id
)
7218 and then not Is_Limited_Type
(Def_Id
)
7221 Comps
: constant Node_Id
:=
7222 Component_List
(Type_Definition
(Type_Decl
));
7225 and then Present
(Variant_Part
(Comps
))
7227 Build_Variant_Record_Equality
(Def_Id
);
7231 -- Otherwise create primitive equality operation (AI05-0123)
7233 -- This is done unconditionally to ensure that tools can be linked
7234 -- properly with user programs compiled with older language versions.
7235 -- In addition, this is needed because "=" composes for bounded strings
7236 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
7238 elsif Comes_From_Source
(Def_Id
)
7239 and then Convention
(Def_Id
) = Convention_Ada
7240 and then not Is_Limited_Type
(Def_Id
)
7242 Build_Untagged_Equality
(Def_Id
);
7245 -- Before building the record initialization procedure, if we are
7246 -- dealing with a concurrent record value type, then we must go through
7247 -- the discriminants, exchanging discriminals between the concurrent
7248 -- type and the concurrent record value type. See the section "Handling
7249 -- of Discriminants" in the Einfo spec for details.
7251 if Is_Concurrent_Record_Type
(Def_Id
)
7252 and then Has_Discriminants
(Def_Id
)
7255 Ctyp
: constant Entity_Id
:=
7256 Corresponding_Concurrent_Type
(Def_Id
);
7257 Conc_Discr
: Entity_Id
;
7258 Rec_Discr
: Entity_Id
;
7262 Conc_Discr
:= First_Discriminant
(Ctyp
);
7263 Rec_Discr
:= First_Discriminant
(Def_Id
);
7264 while Present
(Conc_Discr
) loop
7265 Temp
:= Discriminal
(Conc_Discr
);
7266 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
7267 Set_Discriminal
(Rec_Discr
, Temp
);
7269 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
7270 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
7272 Next_Discriminant
(Conc_Discr
);
7273 Next_Discriminant
(Rec_Discr
);
7278 if Has_Controlled_Component
(Def_Id
) then
7279 Build_Controlling_Procs
(Def_Id
);
7282 Adjust_Discriminants
(Def_Id
);
7284 if Tagged_Type_Expansion
or else not Is_Interface
(Def_Id
) then
7286 -- Do not need init for interfaces on e.g. CIL since they're
7287 -- abstract. Helps operation of peverify (the PE Verify tool).
7289 Build_Record_Init_Proc
(Type_Decl
, Def_Id
);
7292 -- For tagged type that are not interfaces, build bodies of primitive
7293 -- operations. Note: do this after building the record initialization
7294 -- procedure, since the primitive operations may need the initialization
7295 -- routine. There is no need to add predefined primitives of interfaces
7296 -- because all their predefined primitives are abstract.
7298 if Is_Tagged_Type
(Def_Id
) and then not Is_Interface
(Def_Id
) then
7300 -- Do not add the body of predefined primitives in case of CPP tagged
7301 -- type derivations that have convention CPP.
7303 if Is_CPP_Class
(Root_Type
(Def_Id
))
7304 and then Convention
(Def_Id
) = Convention_CPP
7308 -- Do not add the body of predefined primitives in case of CIL and
7309 -- Java tagged types.
7311 elsif Convention
(Def_Id
) = Convention_CIL
7312 or else Convention
(Def_Id
) = Convention_Java
7316 -- Do not add the body of the predefined primitives if we are
7317 -- compiling under restriction No_Dispatching_Calls or if we are
7318 -- compiling a CPP tagged type.
7320 elsif not Restriction_Active
(No_Dispatching_Calls
) then
7322 -- Create the body of TSS primitive Finalize_Address. This must
7323 -- be done before the bodies of all predefined primitives are
7324 -- created. If Def_Id is limited, Stream_Input and Stream_Read
7325 -- may produce build-in-place allocations and for those the
7326 -- expander needs Finalize_Address.
7328 Make_Finalize_Address_Body
(Def_Id
);
7329 Predef_List
:= Predefined_Primitive_Bodies
(Def_Id
, Renamed_Eq
);
7330 Append_Freeze_Actions
(Def_Id
, Predef_List
);
7333 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
7334 -- inherited functions, then add their bodies to the freeze actions.
7336 if Present
(Wrapper_Body_List
) then
7337 Append_Freeze_Actions
(Def_Id
, Wrapper_Body_List
);
7340 -- Create extra formals for the primitive operations of the type.
7341 -- This must be done before analyzing the body of the initialization
7342 -- procedure, because a self-referential type might call one of these
7343 -- primitives in the body of the init_proc itself.
7350 Elmt
:= First_Elmt
(Primitive_Operations
(Def_Id
));
7351 while Present
(Elmt
) loop
7352 Subp
:= Node
(Elmt
);
7353 if not Has_Foreign_Convention
(Subp
)
7354 and then not Is_Predefined_Dispatching_Operation
(Subp
)
7356 Create_Extra_Formals
(Subp
);
7364 -- Create a heterogeneous finalization master to service the anonymous
7365 -- access-to-controlled components of the record type.
7369 Encl_Scope
: constant Entity_Id
:= Scope
(Def_Id
);
7370 Ins_Node
: constant Node_Id
:= Parent
(Def_Id
);
7371 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7372 Fin_Mas_Id
: Entity_Id
;
7374 Attributes_Set
: Boolean := False;
7375 Master_Built
: Boolean := False;
7376 -- Two flags which control the creation and initialization of a
7377 -- common heterogeneous master.
7380 Comp
:= First_Component
(Def_Id
);
7381 while Present
(Comp
) loop
7382 Comp_Typ
:= Etype
(Comp
);
7384 -- A non-self-referential anonymous access-to-controlled
7387 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
7388 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
7389 and then Designated_Type
(Comp_Typ
) /= Def_Id
7391 if VM_Target
= No_VM
then
7393 -- Build a homogeneous master for the first anonymous
7394 -- access-to-controlled component. This master may be
7395 -- converted into a heterogeneous collection if more
7396 -- components are to follow.
7398 if not Master_Built
then
7399 Master_Built
:= True;
7401 -- All anonymous access-to-controlled types allocate
7402 -- on the global pool. Note that the finalization
7403 -- master and the associated storage pool must be set
7404 -- on the root type (both are "root type only").
7406 Set_Associated_Storage_Pool
7407 (Root_Type
(Comp_Typ
), RTE
(RE_Global_Pool_Object
));
7409 Build_Finalization_Master
7410 (Typ
=> Root_Type
(Comp_Typ
),
7411 For_Anonymous
=> True,
7412 Context_Scope
=> Encl_Scope
,
7413 Insertion_Node
=> Ins_Node
);
7415 Fin_Mas_Id
:= Finalization_Master
(Comp_Typ
);
7417 -- Subsequent anonymous access-to-controlled components
7418 -- reuse the available master.
7421 -- All anonymous access-to-controlled types allocate
7422 -- on the global pool. Note that both the finalization
7423 -- master and the associated storage pool must be set
7424 -- on the root type (both are "root type only").
7426 Set_Associated_Storage_Pool
7427 (Root_Type
(Comp_Typ
), RTE
(RE_Global_Pool_Object
));
7429 -- Shared the master among multiple components
7431 Set_Finalization_Master
7432 (Root_Type
(Comp_Typ
), Fin_Mas_Id
);
7434 -- Convert the master into a heterogeneous collection.
7436 -- Set_Is_Heterogeneous (<Fin_Mas_Id>);
7438 if not Attributes_Set
then
7439 Attributes_Set
:= True;
7441 Insert_Action
(Ins_Node
,
7442 Make_Procedure_Call_Statement
(Loc
,
7445 (RTE
(RE_Set_Is_Heterogeneous
), Loc
),
7446 Parameter_Associations
=> New_List
(
7447 New_Occurrence_Of
(Fin_Mas_Id
, Loc
))));
7451 -- Since .NET/JVM targets do not support heterogeneous
7452 -- masters, each component must have its own master.
7455 Build_Finalization_Master
7457 For_Anonymous
=> True,
7458 Context_Scope
=> Encl_Scope
,
7459 Insertion_Node
=> Ins_Node
);
7463 Next_Component
(Comp
);
7468 -- Check whether individual components have a defined invariant, and add
7469 -- the corresponding component invariant checks.
7471 -- Do not create an invariant procedure for some internally generated
7472 -- subtypes, in particular those created for objects of a class-wide
7473 -- type. Such types may have components to which invariant apply, but
7474 -- the corresponding checks will be applied when an object of the parent
7475 -- type is constructed.
7477 -- Such objects will show up in a class-wide postcondition, and the
7478 -- invariant will be checked, if necessary, upon return from the
7479 -- enclosing subprogram.
7481 if not Is_Class_Wide_Equivalent_Type
(Def_Id
) then
7482 Insert_Component_Invariant_Checks
7483 (N
, Def_Id
, Build_Record_Invariant_Proc
(Def_Id
, N
));
7485 end Expand_Freeze_Record_Type
;
7487 ------------------------------
7488 -- Freeze_Stream_Operations --
7489 ------------------------------
7491 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
7492 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
7497 Stream_Op
: Entity_Id
;
7500 -- Primitive operations of tagged types are frozen when the dispatch
7501 -- table is constructed.
7503 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
7507 for J
in Names
'Range loop
7508 Stream_Op
:= TSS
(Typ
, Names
(J
));
7510 if Present
(Stream_Op
)
7511 and then Is_Subprogram
(Stream_Op
)
7512 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
7513 N_Subprogram_Declaration
7514 and then not Is_Frozen
(Stream_Op
)
7516 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
7519 end Freeze_Stream_Operations
;
7525 -- Full type declarations are expanded at the point at which the type is
7526 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
7527 -- declarations generated by the freezing (e.g. the procedure generated
7528 -- for initialization) are chained in the Actions field list of the freeze
7529 -- node using Append_Freeze_Actions.
7531 function Freeze_Type
(N
: Node_Id
) return Boolean is
7532 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
7533 -- Save the current Ghost mode in effect in case the type being frozen
7534 -- sets a different mode.
7536 procedure Process_RACW_Types
(Typ
: Entity_Id
);
7537 -- Validate and generate stubs for all RACW types associated with type
7540 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
);
7541 -- Associate type Typ's Finalize_Address primitive with the finalization
7542 -- masters of pending access-to-Typ types.
7544 procedure Restore_Globals
;
7545 -- Restore the values of all saved global variables
7547 ------------------------
7548 -- Process_RACW_Types --
7549 ------------------------
7551 procedure Process_RACW_Types
(Typ
: Entity_Id
) is
7552 List
: constant Elist_Id
:= Access_Types_To_Process
(N
);
7554 Seen
: Boolean := False;
7557 if Present
(List
) then
7558 E
:= First_Elmt
(List
);
7559 while Present
(E
) loop
7560 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
7561 Validate_RACW_Primitives
(Node
(E
));
7569 -- If there are RACWs designating this type, make stubs now
7572 Remote_Types_Tagged_Full_View_Encountered
(Typ
);
7574 end Process_RACW_Types
;
7576 ----------------------------------
7577 -- Process_Pending_Access_Types --
7578 ----------------------------------
7580 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
) is
7584 -- Finalize_Address is not generated in CodePeer mode because the
7585 -- body contains address arithmetic. This processing is disabled.
7587 if CodePeer_Mode
then
7590 -- Certain itypes are generated for contexts that cannot allocate
7591 -- objects and should not set primitive Finalize_Address.
7593 elsif Is_Itype
(Typ
)
7594 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
7595 N_Explicit_Dereference
7599 -- When an access type is declared after the incomplete view of a
7600 -- Taft-amendment type, the access type is considered pending in
7601 -- case the full view of the Taft-amendment type is controlled. If
7602 -- this is indeed the case, associate the Finalize_Address routine
7603 -- of the full view with the finalization masters of all pending
7604 -- access types. This scenario applies to anonymous access types as
7607 elsif Needs_Finalization
(Typ
)
7608 and then Present
(Pending_Access_Types
(Typ
))
7610 E
:= First_Elmt
(Pending_Access_Types
(Typ
));
7611 while Present
(E
) loop
7614 -- Set_Finalize_Address
7615 -- (Ptr_Typ, <Typ>FD'Unrestricted_Access);
7617 Append_Freeze_Action
(Typ
,
7618 Make_Set_Finalize_Address_Call
7620 Ptr_Typ
=> Node
(E
)));
7625 end Process_Pending_Access_Types
;
7627 ---------------------
7628 -- Restore_Globals --
7629 ---------------------
7631 procedure Restore_Globals
is
7634 end Restore_Globals
;
7638 Def_Id
: constant Entity_Id
:= Entity
(N
);
7639 Result
: Boolean := False;
7641 -- Start of processing for Freeze_Type
7644 -- The type being frozen may be subject to pragma Ghost with policy
7645 -- Ignore. Set the mode now to ensure that any nodes generated during
7646 -- freezing are properly flagged as ignored Ghost.
7648 Set_Ghost_Mode
(N
, Def_Id
);
7650 -- Process any remote access-to-class-wide types designating the type
7653 Process_RACW_Types
(Def_Id
);
7655 -- Freeze processing for record types
7657 if Is_Record_Type
(Def_Id
) then
7658 if Ekind
(Def_Id
) = E_Record_Type
then
7659 Expand_Freeze_Record_Type
(N
);
7660 elsif Is_Class_Wide_Type
(Def_Id
) then
7661 Expand_Freeze_Class_Wide_Type
(N
);
7664 -- Freeze processing for array types
7666 elsif Is_Array_Type
(Def_Id
) then
7667 Expand_Freeze_Array_Type
(N
);
7669 -- Freeze processing for access types
7671 -- For pool-specific access types, find out the pool object used for
7672 -- this type, needs actual expansion of it in some cases. Here are the
7673 -- different cases :
7675 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
7676 -- ---> don't use any storage pool
7678 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
7680 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
7682 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7683 -- ---> Storage Pool is the specified one
7685 -- See GNAT Pool packages in the Run-Time for more details
7687 elsif Ekind_In
(Def_Id
, E_Access_Type
, E_General_Access_Type
) then
7689 Loc
: constant Source_Ptr
:= Sloc
(N
);
7690 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
7691 Pool_Object
: Entity_Id
;
7693 Freeze_Action_Typ
: Entity_Id
;
7698 -- Rep Clause "for Def_Id'Storage_Size use 0;"
7699 -- ---> don't use any storage pool
7701 if No_Pool_Assigned
(Def_Id
) then
7706 -- Rep Clause : for Def_Id'Storage_Size use Expr.
7708 -- Def_Id__Pool : Stack_Bounded_Pool
7709 -- (Expr, DT'Size, DT'Alignment);
7711 elsif Has_Storage_Size_Clause
(Def_Id
) then
7717 -- For unconstrained composite types we give a size of zero
7718 -- so that the pool knows that it needs a special algorithm
7719 -- for variable size object allocation.
7721 if Is_Composite_Type
(Desig_Type
)
7722 and then not Is_Constrained
(Desig_Type
)
7724 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
7725 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
7729 Make_Attribute_Reference
(Loc
,
7730 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7731 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
7734 Make_Attribute_Reference
(Loc
,
7735 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7736 Attribute_Name
=> Name_Alignment
);
7740 Make_Defining_Identifier
(Loc
,
7741 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
7743 -- We put the code associated with the pools in the entity
7744 -- that has the later freeze node, usually the access type
7745 -- but it can also be the designated_type; because the pool
7746 -- code requires both those types to be frozen
7748 if Is_Frozen
(Desig_Type
)
7749 and then (No
(Freeze_Node
(Desig_Type
))
7750 or else Analyzed
(Freeze_Node
(Desig_Type
)))
7752 Freeze_Action_Typ
:= Def_Id
;
7754 -- A Taft amendment type cannot get the freeze actions
7755 -- since the full view is not there.
7757 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
7758 and then No
(Full_View
(Desig_Type
))
7760 Freeze_Action_Typ
:= Def_Id
;
7763 Freeze_Action_Typ
:= Desig_Type
;
7766 Append_Freeze_Action
(Freeze_Action_Typ
,
7767 Make_Object_Declaration
(Loc
,
7768 Defining_Identifier
=> Pool_Object
,
7769 Object_Definition
=>
7770 Make_Subtype_Indication
(Loc
,
7773 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
7776 Make_Index_Or_Discriminant_Constraint
(Loc
,
7777 Constraints
=> New_List
(
7779 -- First discriminant is the Pool Size
7782 Storage_Size_Variable
(Def_Id
), Loc
),
7784 -- Second discriminant is the element size
7788 -- Third discriminant is the alignment
7793 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
7797 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7798 -- ---> Storage Pool is the specified one
7800 -- When compiling in Ada 2012 mode, ensure that the accessibility
7801 -- level of the subpool access type is not deeper than that of the
7802 -- pool_with_subpools.
7804 elsif Ada_Version
>= Ada_2012
7805 and then Present
(Associated_Storage_Pool
(Def_Id
))
7807 -- Omit this check on .NET/JVM where pools are not supported
7809 and then VM_Target
= No_VM
7811 -- Omit this check for the case of a configurable run-time that
7812 -- does not provide package System.Storage_Pools.Subpools.
7814 and then RTE_Available
(RE_Root_Storage_Pool_With_Subpools
)
7817 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7818 Pool
: constant Entity_Id
:=
7819 Associated_Storage_Pool
(Def_Id
);
7820 RSPWS
: constant Entity_Id
:=
7821 RTE
(RE_Root_Storage_Pool_With_Subpools
);
7824 -- It is known that the accessibility level of the access
7825 -- type is deeper than that of the pool.
7827 if Type_Access_Level
(Def_Id
) > Object_Access_Level
(Pool
)
7828 and then not Accessibility_Checks_Suppressed
(Def_Id
)
7829 and then not Accessibility_Checks_Suppressed
(Pool
)
7831 -- Static case: the pool is known to be a descendant of
7832 -- Root_Storage_Pool_With_Subpools.
7834 if Is_Ancestor
(RSPWS
, Etype
(Pool
)) then
7836 ("??subpool access type has deeper accessibility "
7837 & "level than pool", Def_Id
);
7839 Append_Freeze_Action
(Def_Id
,
7840 Make_Raise_Program_Error
(Loc
,
7841 Reason
=> PE_Accessibility_Check_Failed
));
7843 -- Dynamic case: when the pool is of a class-wide type,
7844 -- it may or may not support subpools depending on the
7845 -- path of derivation. Generate:
7847 -- if Def_Id in RSPWS'Class then
7848 -- raise Program_Error;
7851 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
7852 Append_Freeze_Action
(Def_Id
,
7853 Make_If_Statement
(Loc
,
7856 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
7859 (Class_Wide_Type
(RSPWS
), Loc
)),
7861 Then_Statements
=> New_List
(
7862 Make_Raise_Program_Error
(Loc
,
7863 Reason
=> PE_Accessibility_Check_Failed
))));
7869 -- For access-to-controlled types (including class-wide types and
7870 -- Taft-amendment types, which potentially have controlled
7871 -- components), expand the list controller object that will store
7872 -- the dynamically allocated objects. Don't do this transformation
7873 -- for expander-generated access types, but do it for types that
7874 -- are the full view of types derived from other private types.
7875 -- Also suppress the list controller in the case of a designated
7876 -- type with convention Java, since this is used when binding to
7877 -- Java API specs, where there's no equivalent of a finalization
7878 -- list and we don't want to pull in the finalization support if
7881 if not Comes_From_Source
(Def_Id
)
7882 and then not Has_Private_Declaration
(Def_Id
)
7886 -- An exception is made for types defined in the run-time because
7887 -- Ada.Tags.Tag itself is such a type and cannot afford this
7888 -- unnecessary overhead that would generates a loop in the
7889 -- expansion scheme. Another exception is if Restrictions
7890 -- (No_Finalization) is active, since then we know nothing is
7893 elsif Restriction_Active
(No_Finalization
)
7894 or else In_Runtime
(Def_Id
)
7898 -- Create a finalization master for an access-to-controlled type
7899 -- or an access-to-incomplete type. It is assumed that the full
7900 -- view will be controlled.
7902 elsif Needs_Finalization
(Desig_Type
)
7903 or else (Is_Incomplete_Type
(Desig_Type
)
7904 and then No
(Full_View
(Desig_Type
)))
7906 Build_Finalization_Master
(Def_Id
);
7908 -- Create a finalization master when the designated type contains
7909 -- a private component. It is assumed that the full view will be
7912 elsif Has_Private_Component
(Desig_Type
) then
7913 Build_Finalization_Master
7915 For_Private
=> True,
7916 Context_Scope
=> Scope
(Def_Id
),
7917 Insertion_Node
=> Declaration_Node
(Desig_Type
));
7921 -- Freeze processing for enumeration types
7923 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
7925 -- We only have something to do if we have a non-standard
7926 -- representation (i.e. at least one literal whose pos value
7927 -- is not the same as its representation)
7929 if Has_Non_Standard_Rep
(Def_Id
) then
7930 Expand_Freeze_Enumeration_Type
(N
);
7933 -- Private types that are completed by a derivation from a private
7934 -- type have an internally generated full view, that needs to be
7935 -- frozen. This must be done explicitly because the two views share
7936 -- the freeze node, and the underlying full view is not visible when
7937 -- the freeze node is analyzed.
7939 elsif Is_Private_Type
(Def_Id
)
7940 and then Is_Derived_Type
(Def_Id
)
7941 and then Present
(Full_View
(Def_Id
))
7942 and then Is_Itype
(Full_View
(Def_Id
))
7943 and then Has_Private_Declaration
(Full_View
(Def_Id
))
7944 and then Freeze_Node
(Full_View
(Def_Id
)) = N
7946 Set_Entity
(N
, Full_View
(Def_Id
));
7947 Result
:= Freeze_Type
(N
);
7948 Set_Entity
(N
, Def_Id
);
7950 -- All other types require no expander action. There are such cases
7951 -- (e.g. task types and protected types). In such cases, the freeze
7952 -- nodes are there for use by Gigi.
7956 -- Complete the initialization of all pending access types' finalization
7957 -- masters now that the designated type has been is frozen and primitive
7958 -- Finalize_Address generated.
7960 Process_Pending_Access_Types
(Def_Id
);
7961 Freeze_Stream_Operations
(N
, Def_Id
);
7967 when RE_Not_Available
=>
7972 -------------------------
7973 -- Get_Simple_Init_Val --
7974 -------------------------
7976 function Get_Simple_Init_Val
7979 Size
: Uint
:= No_Uint
) return Node_Id
7981 Loc
: constant Source_Ptr
:= Sloc
(N
);
7987 -- This is the size to be used for computation of the appropriate
7988 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
7990 IV_Attribute
: constant Boolean :=
7991 Nkind
(N
) = N_Attribute_Reference
7992 and then Attribute_Name
(N
) = Name_Invalid_Value
;
7996 -- These are the values computed by the procedure Check_Subtype_Bounds
7998 procedure Check_Subtype_Bounds
;
7999 -- This procedure examines the subtype T, and its ancestor subtypes and
8000 -- derived types to determine the best known information about the
8001 -- bounds of the subtype. After the call Lo_Bound is set either to
8002 -- No_Uint if no information can be determined, or to a value which
8003 -- represents a known low bound, i.e. a valid value of the subtype can
8004 -- not be less than this value. Hi_Bound is similarly set to a known
8005 -- high bound (valid value cannot be greater than this).
8007 --------------------------
8008 -- Check_Subtype_Bounds --
8009 --------------------------
8011 procedure Check_Subtype_Bounds
is
8020 Lo_Bound
:= No_Uint
;
8021 Hi_Bound
:= No_Uint
;
8023 -- Loop to climb ancestor subtypes and derived types
8027 if not Is_Discrete_Type
(ST1
) then
8031 Lo
:= Type_Low_Bound
(ST1
);
8032 Hi
:= Type_High_Bound
(ST1
);
8034 if Compile_Time_Known_Value
(Lo
) then
8035 Loval
:= Expr_Value
(Lo
);
8037 if Lo_Bound
= No_Uint
or else Lo_Bound
< Loval
then
8042 if Compile_Time_Known_Value
(Hi
) then
8043 Hival
:= Expr_Value
(Hi
);
8045 if Hi_Bound
= No_Uint
or else Hi_Bound
> Hival
then
8050 ST2
:= Ancestor_Subtype
(ST1
);
8056 exit when ST1
= ST2
;
8059 end Check_Subtype_Bounds
;
8061 -- Start of processing for Get_Simple_Init_Val
8064 -- For a private type, we should always have an underlying type (because
8065 -- this was already checked in Needs_Simple_Initialization). What we do
8066 -- is to get the value for the underlying type and then do an unchecked
8067 -- conversion to the private type.
8069 if Is_Private_Type
(T
) then
8070 Val
:= Get_Simple_Init_Val
(Underlying_Type
(T
), N
, Size
);
8072 -- A special case, if the underlying value is null, then qualify it
8073 -- with the underlying type, so that the null is properly typed.
8074 -- Similarly, if it is an aggregate it must be qualified, because an
8075 -- unchecked conversion does not provide a context for it.
8077 if Nkind_In
(Val
, N_Null
, N_Aggregate
) then
8079 Make_Qualified_Expression
(Loc
,
8081 New_Occurrence_Of
(Underlying_Type
(T
), Loc
),
8085 Result
:= Unchecked_Convert_To
(T
, Val
);
8087 -- Don't truncate result (important for Initialize/Normalize_Scalars)
8089 if Nkind
(Result
) = N_Unchecked_Type_Conversion
8090 and then Is_Scalar_Type
(Underlying_Type
(T
))
8092 Set_No_Truncation
(Result
);
8097 -- Scalars with Default_Value aspect. The first subtype may now be
8098 -- private, so retrieve value from underlying type.
8100 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
8101 if Is_Private_Type
(First_Subtype
(T
)) then
8102 return Unchecked_Convert_To
(T
,
8103 Default_Aspect_Value
(Full_View
(First_Subtype
(T
))));
8106 Convert_To
(T
, Default_Aspect_Value
(First_Subtype
(T
)));
8109 -- Otherwise, for scalars, we must have normalize/initialize scalars
8110 -- case, or if the node N is an 'Invalid_Value attribute node.
8112 elsif Is_Scalar_Type
(T
) then
8113 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
8115 -- Compute size of object. If it is given by the caller, we can use
8116 -- it directly, otherwise we use Esize (T) as an estimate. As far as
8117 -- we know this covers all cases correctly.
8119 if Size
= No_Uint
or else Size
<= Uint_0
then
8120 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(T
));
8122 Size_To_Use
:= Size
;
8125 -- Maximum size to use is 64 bits, since we will create values of
8126 -- type Unsigned_64 and the range must fit this type.
8128 if Size_To_Use
/= No_Uint
and then Size_To_Use
> Uint_64
then
8129 Size_To_Use
:= Uint_64
;
8132 -- Check known bounds of subtype
8134 Check_Subtype_Bounds
;
8136 -- Processing for Normalize_Scalars case
8138 if Normalize_Scalars
and then not IV_Attribute
then
8140 -- If zero is invalid, it is a convenient value to use that is
8141 -- for sure an appropriate invalid value in all situations.
8143 if Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8144 Val
:= Make_Integer_Literal
(Loc
, 0);
8146 -- Cases where all one bits is the appropriate invalid value
8148 -- For modular types, all 1 bits is either invalid or valid. If
8149 -- it is valid, then there is nothing that can be done since there
8150 -- are no invalid values (we ruled out zero already).
8152 -- For signed integer types that have no negative values, either
8153 -- there is room for negative values, or there is not. If there
8154 -- is, then all 1-bits may be interpreted as minus one, which is
8155 -- certainly invalid. Alternatively it is treated as the largest
8156 -- positive value, in which case the observation for modular types
8159 -- For float types, all 1-bits is a NaN (not a number), which is
8160 -- certainly an appropriately invalid value.
8162 elsif Is_Unsigned_Type
(T
)
8163 or else Is_Floating_Point_Type
(T
)
8164 or else Is_Enumeration_Type
(T
)
8166 Val
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
8168 -- Resolve as Unsigned_64, because the largest number we can
8169 -- generate is out of range of universal integer.
8171 Analyze_And_Resolve
(Val
, RTE
(RE_Unsigned_64
));
8173 -- Case of signed types
8177 Signed_Size
: constant Uint
:=
8178 UI_Min
(Uint_63
, Size_To_Use
- 1);
8181 -- Normally we like to use the most negative number. The one
8182 -- exception is when this number is in the known subtype
8183 -- range and the largest positive number is not in the known
8186 -- For this exceptional case, use largest positive value
8188 if Lo_Bound
/= No_Uint
and then Hi_Bound
/= No_Uint
8189 and then Lo_Bound
<= (-(2 ** Signed_Size
))
8190 and then Hi_Bound
< 2 ** Signed_Size
8192 Val
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
8194 -- Normal case of largest negative value
8197 Val
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
8202 -- Here for Initialize_Scalars case (or Invalid_Value attribute used)
8205 -- For float types, use float values from System.Scalar_Values
8207 if Is_Floating_Point_Type
(T
) then
8208 if Root_Type
(T
) = Standard_Short_Float
then
8209 Val_RE
:= RE_IS_Isf
;
8210 elsif Root_Type
(T
) = Standard_Float
then
8211 Val_RE
:= RE_IS_Ifl
;
8212 elsif Root_Type
(T
) = Standard_Long_Float
then
8213 Val_RE
:= RE_IS_Ilf
;
8214 else pragma Assert
(Root_Type
(T
) = Standard_Long_Long_Float
);
8215 Val_RE
:= RE_IS_Ill
;
8218 -- If zero is invalid, use zero values from System.Scalar_Values
8220 elsif Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8221 if Size_To_Use
<= 8 then
8222 Val_RE
:= RE_IS_Iz1
;
8223 elsif Size_To_Use
<= 16 then
8224 Val_RE
:= RE_IS_Iz2
;
8225 elsif Size_To_Use
<= 32 then
8226 Val_RE
:= RE_IS_Iz4
;
8228 Val_RE
:= RE_IS_Iz8
;
8231 -- For unsigned, use unsigned values from System.Scalar_Values
8233 elsif Is_Unsigned_Type
(T
) then
8234 if Size_To_Use
<= 8 then
8235 Val_RE
:= RE_IS_Iu1
;
8236 elsif Size_To_Use
<= 16 then
8237 Val_RE
:= RE_IS_Iu2
;
8238 elsif Size_To_Use
<= 32 then
8239 Val_RE
:= RE_IS_Iu4
;
8241 Val_RE
:= RE_IS_Iu8
;
8244 -- For signed, use signed values from System.Scalar_Values
8247 if Size_To_Use
<= 8 then
8248 Val_RE
:= RE_IS_Is1
;
8249 elsif Size_To_Use
<= 16 then
8250 Val_RE
:= RE_IS_Is2
;
8251 elsif Size_To_Use
<= 32 then
8252 Val_RE
:= RE_IS_Is4
;
8254 Val_RE
:= RE_IS_Is8
;
8258 Val
:= New_Occurrence_Of
(RTE
(Val_RE
), Loc
);
8261 -- The final expression is obtained by doing an unchecked conversion
8262 -- of this result to the base type of the required subtype. Use the
8263 -- base type to prevent the unchecked conversion from chopping bits,
8264 -- and then we set Kill_Range_Check to preserve the "bad" value.
8266 Result
:= Unchecked_Convert_To
(Base_Type
(T
), Val
);
8268 -- Ensure result is not truncated, since we want the "bad" bits, and
8269 -- also kill range check on result.
8271 if Nkind
(Result
) = N_Unchecked_Type_Conversion
then
8272 Set_No_Truncation
(Result
);
8273 Set_Kill_Range_Check
(Result
, True);
8278 -- String or Wide_[Wide]_String (must have Initialize_Scalars set)
8280 elsif Is_Standard_String_Type
(T
) then
8281 pragma Assert
(Init_Or_Norm_Scalars
);
8284 Make_Aggregate
(Loc
,
8285 Component_Associations
=> New_List
(
8286 Make_Component_Association
(Loc
,
8287 Choices
=> New_List
(
8288 Make_Others_Choice
(Loc
)),
8291 (Component_Type
(T
), N
, Esize
(Root_Type
(T
))))));
8293 -- Access type is initialized to null
8295 elsif Is_Access_Type
(T
) then
8296 return Make_Null
(Loc
);
8298 -- No other possibilities should arise, since we should only be calling
8299 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8300 -- indicating one of the above cases held.
8303 raise Program_Error
;
8307 when RE_Not_Available
=>
8309 end Get_Simple_Init_Val
;
8311 ------------------------------
8312 -- Has_New_Non_Standard_Rep --
8313 ------------------------------
8315 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
8317 if not Is_Derived_Type
(T
) then
8318 return Has_Non_Standard_Rep
(T
)
8319 or else Has_Non_Standard_Rep
(Root_Type
(T
));
8321 -- If Has_Non_Standard_Rep is not set on the derived type, the
8322 -- representation is fully inherited.
8324 elsif not Has_Non_Standard_Rep
(T
) then
8328 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
8330 -- May need a more precise check here: the First_Rep_Item may be a
8331 -- stream attribute, which does not affect the representation of the
8335 end Has_New_Non_Standard_Rep
;
8341 function In_Runtime
(E
: Entity_Id
) return Boolean is
8346 while Scope
(S1
) /= Standard_Standard
loop
8350 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
8353 ---------------------------------------
8354 -- Insert_Component_Invariant_Checks --
8355 ---------------------------------------
8357 procedure Insert_Component_Invariant_Checks
8362 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8363 Proc_Id
: Entity_Id
;
8366 if Present
(Proc
) then
8367 Proc_Id
:= Defining_Entity
(Proc
);
8369 if not Has_Invariants
(Typ
) then
8370 Set_Has_Invariants
(Typ
);
8371 Set_Is_Invariant_Procedure
(Proc_Id
);
8372 Set_Invariant_Procedure
(Typ
, Proc_Id
);
8373 Insert_After
(N
, Proc
);
8378 -- Find already created invariant subprogram, insert body of
8379 -- component invariant proc in its body, and add call after
8384 Inv_Id
: constant Entity_Id
:= Invariant_Procedure
(Typ
);
8385 Call
: constant Node_Id
:=
8386 Make_Procedure_Call_Statement
(Sloc
(N
),
8387 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
8388 Parameter_Associations
=>
8390 (New_Occurrence_Of
(First_Formal
(Inv_Id
), Loc
)));
8393 -- The invariant body has not been analyzed yet, so we do a
8394 -- sequential search forward, and retrieve it by name.
8397 while Present
(Bod
) loop
8398 exit when Nkind
(Bod
) = N_Subprogram_Body
8399 and then Chars
(Defining_Entity
(Bod
)) = Chars
(Inv_Id
);
8403 -- If the body is not found, it is the case of an invariant
8404 -- appearing on a full declaration in a private part, in
8405 -- which case the type has been frozen but the invariant
8406 -- procedure for the composite type not created yet. Create
8410 Build_Invariant_Procedure
(Typ
, Parent
(Current_Scope
));
8411 Bod
:= Unit_Declaration_Node
8412 (Corresponding_Body
(Unit_Declaration_Node
(Inv_Id
)));
8415 Append_To
(Declarations
(Bod
), Proc
);
8416 Append_To
(Statements
(Handled_Statement_Sequence
(Bod
)), Call
);
8422 end Insert_Component_Invariant_Checks
;
8424 ----------------------------
8425 -- Initialization_Warning --
8426 ----------------------------
8428 procedure Initialization_Warning
(E
: Entity_Id
) is
8429 Warning_Needed
: Boolean;
8432 Warning_Needed
:= False;
8434 if Ekind
(Current_Scope
) = E_Package
8435 and then Static_Elaboration_Desired
(Current_Scope
)
8438 if Is_Record_Type
(E
) then
8439 if Has_Discriminants
(E
)
8440 or else Is_Limited_Type
(E
)
8441 or else Has_Non_Standard_Rep
(E
)
8443 Warning_Needed
:= True;
8446 -- Verify that at least one component has an initialization
8447 -- expression. No need for a warning on a type if all its
8448 -- components have no initialization.
8454 Comp
:= First_Component
(E
);
8455 while Present
(Comp
) loop
8456 if Ekind
(Comp
) = E_Discriminant
8458 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
8459 and then Present
(Expression
(Parent
(Comp
))))
8461 Warning_Needed
:= True;
8465 Next_Component
(Comp
);
8470 if Warning_Needed
then
8472 ("Objects of the type cannot be initialized statically "
8473 & "by default??", Parent
(E
));
8478 Error_Msg_N
("Object cannot be initialized statically??", E
);
8481 end Initialization_Warning
;
8487 function Init_Formals
(Typ
: Entity_Id
) return List_Id
is
8488 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8492 -- First parameter is always _Init : in out typ. Note that we need this
8493 -- to be in/out because in the case of the task record value, there
8494 -- are default record fields (_Priority, _Size, -Task_Info) that may
8495 -- be referenced in the generated initialization routine.
8497 Formals
:= New_List
(
8498 Make_Parameter_Specification
(Loc
,
8499 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
8501 Out_Present
=> True,
8502 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8504 -- For task record value, or type that contains tasks, add two more
8505 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8506 -- We also add these parameters for the task record type case.
8509 or else (Is_Record_Type
(Typ
) and then Is_Task_Record_Type
(Typ
))
8512 Make_Parameter_Specification
(Loc
,
8513 Defining_Identifier
=>
8514 Make_Defining_Identifier
(Loc
, Name_uMaster
),
8516 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
)));
8518 -- Add _Chain (not done for sequential elaboration policy, see
8519 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
8521 if Partition_Elaboration_Policy
/= 'S' then
8523 Make_Parameter_Specification
(Loc
,
8524 Defining_Identifier
=>
8525 Make_Defining_Identifier
(Loc
, Name_uChain
),
8527 Out_Present
=> True,
8529 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
8533 Make_Parameter_Specification
(Loc
,
8534 Defining_Identifier
=>
8535 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
8537 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
8543 when RE_Not_Available
=>
8547 -------------------------
8548 -- Init_Secondary_Tags --
8549 -------------------------
8551 procedure Init_Secondary_Tags
8554 Stmts_List
: List_Id
;
8555 Fixed_Comps
: Boolean := True;
8556 Variable_Comps
: Boolean := True)
8558 Loc
: constant Source_Ptr
:= Sloc
(Target
);
8560 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
8561 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8563 procedure Initialize_Tag
8566 Tag_Comp
: Entity_Id
;
8567 Iface_Tag
: Node_Id
);
8568 -- Initialize the tag of the secondary dispatch table of Typ associated
8569 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8570 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
8571 -- of Typ CPP tagged type we generate code to inherit the contents of
8572 -- the dispatch table directly from the ancestor.
8574 --------------------
8575 -- Initialize_Tag --
8576 --------------------
8578 procedure Initialize_Tag
8581 Tag_Comp
: Entity_Id
;
8582 Iface_Tag
: Node_Id
)
8584 Comp_Typ
: Entity_Id
;
8585 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
8588 -- Initialize pointer to secondary DT associated with the interface
8590 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8591 Append_To
(Stmts_List
,
8592 Make_Assignment_Statement
(Loc
,
8594 Make_Selected_Component
(Loc
,
8595 Prefix
=> New_Copy_Tree
(Target
),
8596 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8598 New_Occurrence_Of
(Iface_Tag
, Loc
)));
8601 Comp_Typ
:= Scope
(Tag_Comp
);
8603 -- Initialize the entries of the table of interfaces. We generate a
8604 -- different call when the parent of the type has variable size
8607 if Comp_Typ
/= Etype
(Comp_Typ
)
8608 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
8609 and then Chars
(Tag_Comp
) /= Name_uTag
8611 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
8613 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
8614 -- configurable run-time environment.
8616 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
8618 ("variable size record with interface types", Typ
);
8623 -- Set_Dynamic_Offset_To_Top
8625 -- Interface_T => Iface'Tag,
8626 -- Offset_Value => n,
8627 -- Offset_Func => Fn'Address)
8629 Append_To
(Stmts_List
,
8630 Make_Procedure_Call_Statement
(Loc
,
8632 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
8633 Parameter_Associations
=> New_List
(
8634 Make_Attribute_Reference
(Loc
,
8635 Prefix
=> New_Copy_Tree
(Target
),
8636 Attribute_Name
=> Name_Address
),
8638 Unchecked_Convert_To
(RTE
(RE_Tag
),
8640 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
8643 Unchecked_Convert_To
8644 (RTE
(RE_Storage_Offset
),
8645 Make_Attribute_Reference
(Loc
,
8647 Make_Selected_Component
(Loc
,
8648 Prefix
=> New_Copy_Tree
(Target
),
8650 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8651 Attribute_Name
=> Name_Position
)),
8653 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
8654 Make_Attribute_Reference
(Loc
,
8655 Prefix
=> New_Occurrence_Of
8656 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
8657 Attribute_Name
=> Name_Address
)))));
8659 -- In this case the next component stores the value of the offset
8662 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
8663 pragma Assert
(Present
(Offset_To_Top_Comp
));
8665 Append_To
(Stmts_List
,
8666 Make_Assignment_Statement
(Loc
,
8668 Make_Selected_Component
(Loc
,
8669 Prefix
=> New_Copy_Tree
(Target
),
8671 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
8674 Make_Attribute_Reference
(Loc
,
8676 Make_Selected_Component
(Loc
,
8677 Prefix
=> New_Copy_Tree
(Target
),
8678 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8679 Attribute_Name
=> Name_Position
)));
8681 -- Normal case: No discriminants in the parent type
8684 -- Don't need to set any value if this interface shares the
8685 -- primary dispatch table.
8687 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8688 Append_To
(Stmts_List
,
8689 Build_Set_Static_Offset_To_Top
(Loc
,
8690 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
8692 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8693 Make_Attribute_Reference
(Loc
,
8695 Make_Selected_Component
(Loc
,
8696 Prefix
=> New_Copy_Tree
(Target
),
8698 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8699 Attribute_Name
=> Name_Position
))));
8703 -- Register_Interface_Offset
8705 -- Interface_T => Iface'Tag,
8706 -- Is_Constant => True,
8707 -- Offset_Value => n,
8708 -- Offset_Func => null);
8710 if RTE_Available
(RE_Register_Interface_Offset
) then
8711 Append_To
(Stmts_List
,
8712 Make_Procedure_Call_Statement
(Loc
,
8715 (RTE
(RE_Register_Interface_Offset
), Loc
),
8716 Parameter_Associations
=> New_List
(
8717 Make_Attribute_Reference
(Loc
,
8718 Prefix
=> New_Copy_Tree
(Target
),
8719 Attribute_Name
=> Name_Address
),
8721 Unchecked_Convert_To
(RTE
(RE_Tag
),
8723 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
8725 New_Occurrence_Of
(Standard_True
, Loc
),
8727 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8728 Make_Attribute_Reference
(Loc
,
8730 Make_Selected_Component
(Loc
,
8731 Prefix
=> New_Copy_Tree
(Target
),
8733 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8734 Attribute_Name
=> Name_Position
)),
8743 Full_Typ
: Entity_Id
;
8744 Ifaces_List
: Elist_Id
;
8745 Ifaces_Comp_List
: Elist_Id
;
8746 Ifaces_Tag_List
: Elist_Id
;
8747 Iface_Elmt
: Elmt_Id
;
8748 Iface_Comp_Elmt
: Elmt_Id
;
8749 Iface_Tag_Elmt
: Elmt_Id
;
8751 In_Variable_Pos
: Boolean;
8753 -- Start of processing for Init_Secondary_Tags
8756 -- Handle private types
8758 if Present
(Full_View
(Typ
)) then
8759 Full_Typ
:= Full_View
(Typ
);
8764 Collect_Interfaces_Info
8765 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
8767 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8768 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
8769 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
8770 while Present
(Iface_Elmt
) loop
8771 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
8773 -- Check if parent of record type has variable size components
8775 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
8776 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
8778 -- If we are compiling under the CPP full ABI compatibility mode and
8779 -- the ancestor is a CPP_Pragma tagged type then we generate code to
8780 -- initialize the secondary tag components from tags that reference
8781 -- secondary tables filled with copy of parent slots.
8783 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
8785 -- Reject interface components located at variable offset in
8786 -- C++ derivations. This is currently unsupported.
8788 if not Fixed_Comps
and then In_Variable_Pos
then
8790 -- Locate the first dynamic component of the record. Done to
8791 -- improve the text of the warning.
8795 Comp_Typ
: Entity_Id
;
8798 Comp
:= First_Entity
(Typ
);
8799 while Present
(Comp
) loop
8800 Comp_Typ
:= Etype
(Comp
);
8802 if Ekind
(Comp
) /= E_Discriminant
8803 and then not Is_Tag
(Comp
)
8806 (Is_Record_Type
(Comp_Typ
)
8808 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
8810 (Is_Array_Type
(Comp_Typ
)
8811 and then Is_Variable_Size_Array
(Comp_Typ
));
8817 pragma Assert
(Present
(Comp
));
8818 Error_Msg_Node_2
:= Comp
;
8820 ("parent type & with dynamic component & cannot be parent"
8821 & " of 'C'P'P derivation if new interfaces are present",
8822 Typ
, Scope
(Original_Record_Component
(Comp
)));
8825 Sloc
(Scope
(Original_Record_Component
(Comp
)));
8827 ("type derived from 'C'P'P type & defined #",
8828 Typ
, Scope
(Original_Record_Component
(Comp
)));
8830 -- Avoid duplicated warnings
8835 -- Initialize secondary tags
8838 Append_To
(Stmts_List
,
8839 Make_Assignment_Statement
(Loc
,
8841 Make_Selected_Component
(Loc
,
8842 Prefix
=> New_Copy_Tree
(Target
),
8844 New_Occurrence_Of
(Node
(Iface_Comp_Elmt
), Loc
)),
8846 New_Occurrence_Of
(Node
(Iface_Tag_Elmt
), Loc
)));
8849 -- Otherwise generate code to initialize the tag
8852 if (In_Variable_Pos
and then Variable_Comps
)
8853 or else (not In_Variable_Pos
and then Fixed_Comps
)
8855 Initialize_Tag
(Full_Typ
,
8856 Iface
=> Node
(Iface_Elmt
),
8857 Tag_Comp
=> Tag_Comp
,
8858 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
8862 Next_Elmt
(Iface_Elmt
);
8863 Next_Elmt
(Iface_Comp_Elmt
);
8864 Next_Elmt
(Iface_Tag_Elmt
);
8866 end Init_Secondary_Tags
;
8868 ------------------------
8869 -- Is_User_Defined_Eq --
8870 ------------------------
8872 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean is
8874 return Chars
(Prim
) = Name_Op_Eq
8875 and then Etype
(First_Formal
(Prim
)) =
8876 Etype
(Next_Formal
(First_Formal
(Prim
)))
8877 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
;
8878 end Is_User_Defined_Equality
;
8880 ----------------------------------------
8881 -- Make_Controlling_Function_Wrappers --
8882 ----------------------------------------
8884 procedure Make_Controlling_Function_Wrappers
8885 (Tag_Typ
: Entity_Id
;
8886 Decl_List
: out List_Id
;
8887 Body_List
: out List_Id
)
8889 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
8890 Prim_Elmt
: Elmt_Id
;
8892 Actual_List
: List_Id
;
8893 Formal_List
: List_Id
;
8895 Par_Formal
: Entity_Id
;
8896 Formal_Node
: Node_Id
;
8897 Func_Body
: Node_Id
;
8898 Func_Decl
: Node_Id
;
8899 Func_Spec
: Node_Id
;
8900 Return_Stmt
: Node_Id
;
8903 Decl_List
:= New_List
;
8904 Body_List
:= New_List
;
8906 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
8907 while Present
(Prim_Elmt
) loop
8908 Subp
:= Node
(Prim_Elmt
);
8910 -- If a primitive function with a controlling result of the type has
8911 -- not been overridden by the user, then we must create a wrapper
8912 -- function here that effectively overrides it and invokes the
8913 -- (non-abstract) parent function. This can only occur for a null
8914 -- extension. Note that functions with anonymous controlling access
8915 -- results don't qualify and must be overridden. We also exclude
8916 -- Input attributes, since each type will have its own version of
8917 -- Input constructed by the expander. The test for Comes_From_Source
8918 -- is needed to distinguish inherited operations from renamings
8919 -- (which also have Alias set). We exclude internal entities with
8920 -- Interface_Alias to avoid generating duplicated wrappers since
8921 -- the primitive which covers the interface is also available in
8922 -- the list of primitive operations.
8924 -- The function may be abstract, or require_Overriding may be set
8925 -- for it, because tests for null extensions may already have reset
8926 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
8927 -- set, functions that need wrappers are recognized by having an
8928 -- alias that returns the parent type.
8930 if Comes_From_Source
(Subp
)
8931 or else No
(Alias
(Subp
))
8932 or else Present
(Interface_Alias
(Subp
))
8933 or else Ekind
(Subp
) /= E_Function
8934 or else not Has_Controlling_Result
(Subp
)
8935 or else Is_Access_Type
(Etype
(Subp
))
8936 or else Is_Abstract_Subprogram
(Alias
(Subp
))
8937 or else Is_TSS
(Subp
, TSS_Stream_Input
)
8941 elsif Is_Abstract_Subprogram
(Subp
)
8942 or else Requires_Overriding
(Subp
)
8944 (Is_Null_Extension
(Etype
(Subp
))
8945 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
8947 Formal_List
:= No_List
;
8948 Formal
:= First_Formal
(Subp
);
8950 if Present
(Formal
) then
8951 Formal_List
:= New_List
;
8953 while Present
(Formal
) loop
8955 (Make_Parameter_Specification
8957 Defining_Identifier
=>
8958 Make_Defining_Identifier
(Sloc
(Formal
),
8959 Chars
=> Chars
(Formal
)),
8960 In_Present
=> In_Present
(Parent
(Formal
)),
8961 Out_Present
=> Out_Present
(Parent
(Formal
)),
8962 Null_Exclusion_Present
=>
8963 Null_Exclusion_Present
(Parent
(Formal
)),
8965 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8967 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
8970 Next_Formal
(Formal
);
8975 Make_Function_Specification
(Loc
,
8976 Defining_Unit_Name
=>
8977 Make_Defining_Identifier
(Loc
,
8978 Chars
=> Chars
(Subp
)),
8979 Parameter_Specifications
=> Formal_List
,
8980 Result_Definition
=>
8981 New_Occurrence_Of
(Etype
(Subp
), Loc
));
8983 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Func_Spec
);
8984 Append_To
(Decl_List
, Func_Decl
);
8986 -- Build a wrapper body that calls the parent function. The body
8987 -- contains a single return statement that returns an extension
8988 -- aggregate whose ancestor part is a call to the parent function,
8989 -- passing the formals as actuals (with any controlling arguments
8990 -- converted to the types of the corresponding formals of the
8991 -- parent function, which might be anonymous access types), and
8992 -- having a null extension.
8994 Formal
:= First_Formal
(Subp
);
8995 Par_Formal
:= First_Formal
(Alias
(Subp
));
8996 Formal_Node
:= First
(Formal_List
);
8998 if Present
(Formal
) then
8999 Actual_List
:= New_List
;
9001 Actual_List
:= No_List
;
9004 while Present
(Formal
) loop
9005 if Is_Controlling_Formal
(Formal
) then
9006 Append_To
(Actual_List
,
9007 Make_Type_Conversion
(Loc
,
9009 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
9012 (Defining_Identifier
(Formal_Node
), Loc
)));
9017 (Defining_Identifier
(Formal_Node
), Loc
));
9020 Next_Formal
(Formal
);
9021 Next_Formal
(Par_Formal
);
9026 Make_Simple_Return_Statement
(Loc
,
9028 Make_Extension_Aggregate
(Loc
,
9030 Make_Function_Call
(Loc
,
9032 New_Occurrence_Of
(Alias
(Subp
), Loc
),
9033 Parameter_Associations
=> Actual_List
),
9034 Null_Record_Present
=> True));
9037 Make_Subprogram_Body
(Loc
,
9038 Specification
=> New_Copy_Tree
(Func_Spec
),
9039 Declarations
=> Empty_List
,
9040 Handled_Statement_Sequence
=>
9041 Make_Handled_Sequence_Of_Statements
(Loc
,
9042 Statements
=> New_List
(Return_Stmt
)));
9044 Set_Defining_Unit_Name
9045 (Specification
(Func_Body
),
9046 Make_Defining_Identifier
(Loc
, Chars
(Subp
)));
9048 Append_To
(Body_List
, Func_Body
);
9050 -- Replace the inherited function with the wrapper function in the
9051 -- primitive operations list. We add the minimum decoration needed
9052 -- to override interface primitives.
9054 Set_Ekind
(Defining_Unit_Name
(Func_Spec
), E_Function
);
9056 Override_Dispatching_Operation
9057 (Tag_Typ
, Subp
, New_Op
=> Defining_Unit_Name
(Func_Spec
),
9058 Is_Wrapper
=> True);
9062 Next_Elmt
(Prim_Elmt
);
9064 end Make_Controlling_Function_Wrappers
;
9070 function Make_Eq_Body
9072 Eq_Name
: Name_Id
) return Node_Id
9074 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
9076 Def
: constant Node_Id
:= Parent
(Typ
);
9077 Stmts
: constant List_Id
:= New_List
;
9078 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
9079 Comps
: Node_Id
:= Empty
;
9080 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
9084 Predef_Spec_Or_Body
(Loc
,
9087 Profile
=> New_List
(
9088 Make_Parameter_Specification
(Loc
,
9089 Defining_Identifier
=>
9090 Make_Defining_Identifier
(Loc
, Name_X
),
9091 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
9093 Make_Parameter_Specification
(Loc
,
9094 Defining_Identifier
=>
9095 Make_Defining_Identifier
(Loc
, Name_Y
),
9096 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9098 Ret_Type
=> Standard_Boolean
,
9101 if Variant_Case
then
9102 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
9103 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
9106 if Present
(Typ_Def
) then
9107 Comps
:= Component_List
(Typ_Def
);
9111 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
9114 if Variant_Case
then
9116 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
9117 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
9119 Make_Simple_Return_Statement
(Loc
,
9120 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9124 Make_Simple_Return_Statement
(Loc
,
9126 Expand_Record_Equality
9129 Lhs
=> Make_Identifier
(Loc
, Name_X
),
9130 Rhs
=> Make_Identifier
(Loc
, Name_Y
),
9131 Bodies
=> Declarations
(Decl
))));
9134 Set_Handled_Statement_Sequence
9135 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9143 -- <Make_Eq_If shared components>
9146 -- when V1 => <Make_Eq_Case> on subcomponents
9148 -- when Vn => <Make_Eq_Case> on subcomponents
9151 function Make_Eq_Case
9154 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
9156 Loc
: constant Source_Ptr
:= Sloc
(E
);
9157 Result
: constant List_Id
:= New_List
;
9161 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
9162 -- Given the discriminant that controls a given variant of an unchecked
9163 -- union, find the formal of the equality function that carries the
9164 -- inferred value of the discriminant.
9166 function External_Name
(E
: Entity_Id
) return Name_Id
;
9167 -- The value of a given discriminant is conveyed in the corresponding
9168 -- formal parameter of the equality routine. The name of this formal
9169 -- parameter carries a one-character suffix which is removed here.
9171 --------------------------
9172 -- Corresponding_Formal --
9173 --------------------------
9175 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
9176 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
9180 Elm
:= First_Elmt
(Discrs
);
9181 while Present
(Elm
) loop
9182 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
9189 -- A formal of the proper name must be found
9191 raise Program_Error
;
9192 end Corresponding_Formal
;
9198 function External_Name
(E
: Entity_Id
) return Name_Id
is
9200 Get_Name_String
(Chars
(E
));
9201 Name_Len
:= Name_Len
- 1;
9205 -- Start of processing for Make_Eq_Case
9208 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
9210 if No
(Variant_Part
(CL
)) then
9214 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
9216 if No
(Variant
) then
9220 Alt_List
:= New_List
;
9221 while Present
(Variant
) loop
9222 Append_To
(Alt_List
,
9223 Make_Case_Statement_Alternative
(Loc
,
9224 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
9226 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
9227 Next_Non_Pragma
(Variant
);
9230 -- If we have an Unchecked_Union, use one of the parameters of the
9231 -- enclosing equality routine that captures the discriminant, to use
9232 -- as the expression in the generated case statement.
9234 if Is_Unchecked_Union
(E
) then
9236 Make_Case_Statement
(Loc
,
9238 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
9239 Alternatives
=> Alt_List
));
9243 Make_Case_Statement
(Loc
,
9245 Make_Selected_Component
(Loc
,
9246 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9247 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
9248 Alternatives
=> Alt_List
));
9269 -- or a null statement if the list L is empty
9273 L
: List_Id
) return Node_Id
9275 Loc
: constant Source_Ptr
:= Sloc
(E
);
9277 Field_Name
: Name_Id
;
9282 return Make_Null_Statement
(Loc
);
9287 C
:= First_Non_Pragma
(L
);
9288 while Present
(C
) loop
9289 Field_Name
:= Chars
(Defining_Identifier
(C
));
9291 -- The tags must not be compared: they are not part of the value.
9292 -- Ditto for parent interfaces because their equality operator is
9295 -- Note also that in the following, we use Make_Identifier for
9296 -- the component names. Use of New_Occurrence_Of to identify the
9297 -- components would be incorrect because the wrong entities for
9298 -- discriminants could be picked up in the private type case.
9300 if Field_Name
= Name_uParent
9301 and then Is_Interface
(Etype
(Defining_Identifier
(C
)))
9305 elsif Field_Name
/= Name_uTag
then
9306 Evolve_Or_Else
(Cond
,
9309 Make_Selected_Component
(Loc
,
9310 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9311 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
)),
9314 Make_Selected_Component
(Loc
,
9315 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
9316 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
))));
9319 Next_Non_Pragma
(C
);
9323 return Make_Null_Statement
(Loc
);
9327 Make_Implicit_If_Statement
(E
,
9329 Then_Statements
=> New_List
(
9330 Make_Simple_Return_Statement
(Loc
,
9331 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
9340 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
9342 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
9343 -- Returns true if Prim is a renaming of an unresolved predefined
9344 -- inequality operation.
9346 --------------------------------
9347 -- Is_Predefined_Neq_Renaming --
9348 --------------------------------
9350 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
9352 return Chars
(Prim
) /= Name_Op_Ne
9353 and then Present
(Alias
(Prim
))
9354 and then Comes_From_Source
(Prim
)
9355 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9356 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
9357 end Is_Predefined_Neq_Renaming
;
9361 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
9362 Stmts
: constant List_Id
:= New_List
;
9364 Eq_Prim
: Entity_Id
;
9365 Left_Op
: Entity_Id
;
9366 Renaming_Prim
: Entity_Id
;
9367 Right_Op
: Entity_Id
;
9370 -- Start of processing for Make_Neq_Body
9373 -- For a call on a renaming of a dispatching subprogram that is
9374 -- overridden, if the overriding occurred before the renaming, then
9375 -- the body executed is that of the overriding declaration, even if the
9376 -- overriding declaration is not visible at the place of the renaming;
9377 -- otherwise, the inherited or predefined subprogram is called, see
9380 -- Stage 1: Search for a renaming of the inequality primitive and also
9381 -- search for an overriding of the equality primitive located before the
9382 -- renaming declaration.
9390 Renaming_Prim
:= Empty
;
9392 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9393 while Present
(Elmt
) loop
9394 Prim
:= Node
(Elmt
);
9396 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
9397 if No
(Renaming_Prim
) then
9398 pragma Assert
(No
(Eq_Prim
));
9402 elsif Is_Predefined_Neq_Renaming
(Prim
) then
9403 Renaming_Prim
:= Prim
;
9410 -- No further action needed if no renaming was found
9412 if No
(Renaming_Prim
) then
9416 -- Stage 2: Replace the renaming declaration by a subprogram declaration
9417 -- (required to add its body)
9419 Decl
:= Parent
(Parent
(Renaming_Prim
));
9421 Make_Subprogram_Declaration
(Loc
,
9422 Specification
=> Specification
(Decl
)));
9423 Set_Analyzed
(Decl
);
9425 -- Remove the decoration of intrinsic renaming subprogram
9427 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
9428 Set_Convention
(Renaming_Prim
, Convention_Ada
);
9429 Set_Alias
(Renaming_Prim
, Empty
);
9430 Set_Has_Completion
(Renaming_Prim
, False);
9432 -- Stage 3: Build the corresponding body
9434 Left_Op
:= First_Formal
(Renaming_Prim
);
9435 Right_Op
:= Next_Formal
(Left_Op
);
9438 Predef_Spec_Or_Body
(Loc
,
9440 Name
=> Chars
(Renaming_Prim
),
9441 Profile
=> New_List
(
9442 Make_Parameter_Specification
(Loc
,
9443 Defining_Identifier
=>
9444 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
9445 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9447 Make_Parameter_Specification
(Loc
,
9448 Defining_Identifier
=>
9449 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
9450 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9452 Ret_Type
=> Standard_Boolean
,
9455 -- If the overriding of the equality primitive occurred before the
9456 -- renaming, then generate:
9458 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9460 -- return not Oeq (X, Y);
9463 if Present
(Eq_Prim
) then
9466 -- Otherwise build a nested subprogram which performs the predefined
9467 -- evaluation of the equality operator. That is, generate:
9469 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9470 -- function Oeq (X : Y) return Boolean is
9472 -- <<body of default implementation>>
9475 -- return not Oeq (X, Y);
9480 Local_Subp
: Node_Id
;
9482 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
9483 Set_Declarations
(Decl
, New_List
(Local_Subp
));
9484 Target
:= Defining_Entity
(Local_Subp
);
9489 Make_Simple_Return_Statement
(Loc
,
9492 Make_Function_Call
(Loc
,
9493 Name
=> New_Occurrence_Of
(Target
, Loc
),
9494 Parameter_Associations
=> New_List
(
9495 Make_Identifier
(Loc
, Chars
(Left_Op
)),
9496 Make_Identifier
(Loc
, Chars
(Right_Op
)))))));
9498 Set_Handled_Statement_Sequence
9499 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9503 -------------------------------
9504 -- Make_Null_Procedure_Specs --
9505 -------------------------------
9507 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
9508 Decl_List
: constant List_Id
:= New_List
;
9509 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9511 Formal_List
: List_Id
;
9512 New_Param_Spec
: Node_Id
;
9513 Parent_Subp
: Entity_Id
;
9514 Prim_Elmt
: Elmt_Id
;
9518 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9519 while Present
(Prim_Elmt
) loop
9520 Subp
:= Node
(Prim_Elmt
);
9522 -- If a null procedure inherited from an interface has not been
9523 -- overridden, then we build a null procedure declaration to
9524 -- override the inherited procedure.
9526 Parent_Subp
:= Alias
(Subp
);
9528 if Present
(Parent_Subp
)
9529 and then Is_Null_Interface_Primitive
(Parent_Subp
)
9531 Formal_List
:= No_List
;
9532 Formal
:= First_Formal
(Subp
);
9534 if Present
(Formal
) then
9535 Formal_List
:= New_List
;
9537 while Present
(Formal
) loop
9539 -- Copy the parameter spec including default expressions
9542 New_Copy_Tree
(Parent
(Formal
), New_Sloc
=> Loc
);
9544 -- Generate a new defining identifier for the new formal.
9545 -- required because New_Copy_Tree does not duplicate
9546 -- semantic fields (except itypes).
9548 Set_Defining_Identifier
(New_Param_Spec
,
9549 Make_Defining_Identifier
(Sloc
(Formal
),
9550 Chars
=> Chars
(Formal
)));
9552 -- For controlling arguments we must change their
9553 -- parameter type to reference the tagged type (instead
9554 -- of the interface type)
9556 if Is_Controlling_Formal
(Formal
) then
9557 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
9559 Set_Parameter_Type
(New_Param_Spec
,
9560 New_Occurrence_Of
(Tag_Typ
, Loc
));
9563 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
9564 N_Access_Definition
);
9565 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
9566 New_Occurrence_Of
(Tag_Typ
, Loc
));
9570 Append
(New_Param_Spec
, Formal_List
);
9572 Next_Formal
(Formal
);
9576 Append_To
(Decl_List
,
9577 Make_Subprogram_Declaration
(Loc
,
9578 Make_Procedure_Specification
(Loc
,
9579 Defining_Unit_Name
=>
9580 Make_Defining_Identifier
(Loc
, Chars
(Subp
)),
9581 Parameter_Specifications
=> Formal_List
,
9582 Null_Present
=> True)));
9585 Next_Elmt
(Prim_Elmt
);
9589 end Make_Null_Procedure_Specs
;
9591 -------------------------------------
9592 -- Make_Predefined_Primitive_Specs --
9593 -------------------------------------
9595 procedure Make_Predefined_Primitive_Specs
9596 (Tag_Typ
: Entity_Id
;
9597 Predef_List
: out List_Id
;
9598 Renamed_Eq
: out Entity_Id
)
9600 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
9601 -- Returns true if Prim is a renaming of an unresolved predefined
9602 -- equality operation.
9604 -------------------------------
9605 -- Is_Predefined_Eq_Renaming --
9606 -------------------------------
9608 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
9610 return Chars
(Prim
) /= Name_Op_Eq
9611 and then Present
(Alias
(Prim
))
9612 and then Comes_From_Source
(Prim
)
9613 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9614 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
9615 end Is_Predefined_Eq_Renaming
;
9619 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9620 Res
: constant List_Id
:= New_List
;
9621 Eq_Name
: Name_Id
:= Name_Op_Eq
;
9622 Eq_Needed
: Boolean;
9626 Has_Predef_Eq_Renaming
: Boolean := False;
9627 -- Set to True if Tag_Typ has a primitive that renames the predefined
9628 -- equality operator. Used to implement (RM 8-5-4(8)).
9630 -- Start of processing for Make_Predefined_Primitive_Specs
9633 Renamed_Eq
:= Empty
;
9637 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9640 Profile
=> New_List
(
9641 Make_Parameter_Specification
(Loc
,
9642 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9643 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9645 Ret_Type
=> Standard_Long_Long_Integer
));
9647 -- Specs for dispatching stream attributes
9650 Stream_Op_TSS_Names
:
9651 constant array (Integer range <>) of TSS_Name_Type
:=
9658 for Op
in Stream_Op_TSS_Names
'Range loop
9659 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
9661 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
9662 Stream_Op_TSS_Names
(Op
)));
9667 -- Spec of "=" is expanded if the type is not limited and if a user
9668 -- defined "=" was not already declared for the non-full view of a
9669 -- private extension
9671 if not Is_Limited_Type
(Tag_Typ
) then
9673 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9674 while Present
(Prim
) loop
9676 -- If a primitive is encountered that renames the predefined
9677 -- equality operator before reaching any explicit equality
9678 -- primitive, then we still need to create a predefined equality
9679 -- function, because calls to it can occur via the renaming. A
9680 -- new name is created for the equality to avoid conflicting with
9681 -- any user-defined equality. (Note that this doesn't account for
9682 -- renamings of equality nested within subpackages???)
9684 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9685 Has_Predef_Eq_Renaming
:= True;
9686 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
9688 -- User-defined equality
9690 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
9691 if No
(Alias
(Node
(Prim
)))
9692 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
9693 N_Subprogram_Renaming_Declaration
9698 -- If the parent is not an interface type and has an abstract
9699 -- equality function, the inherited equality is abstract as
9700 -- well, and no body can be created for it.
9702 elsif not Is_Interface
(Etype
(Tag_Typ
))
9703 and then Present
(Alias
(Node
(Prim
)))
9704 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
9709 -- If the type has an equality function corresponding with
9710 -- a primitive defined in an interface type, the inherited
9711 -- equality is abstract as well, and no body can be created
9714 elsif Present
(Alias
(Node
(Prim
)))
9715 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
9718 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
9728 -- If a renaming of predefined equality was found but there was no
9729 -- user-defined equality (so Eq_Needed is still true), then set the
9730 -- name back to Name_Op_Eq. But in the case where a user-defined
9731 -- equality was located after such a renaming, then the predefined
9732 -- equality function is still needed, so Eq_Needed must be set back
9735 if Eq_Name
/= Name_Op_Eq
then
9737 Eq_Name
:= Name_Op_Eq
;
9744 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
9747 Profile
=> New_List
(
9748 Make_Parameter_Specification
(Loc
,
9749 Defining_Identifier
=>
9750 Make_Defining_Identifier
(Loc
, Name_X
),
9751 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9753 Make_Parameter_Specification
(Loc
,
9754 Defining_Identifier
=>
9755 Make_Defining_Identifier
(Loc
, Name_Y
),
9756 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9757 Ret_Type
=> Standard_Boolean
);
9758 Append_To
(Res
, Eq_Spec
);
9760 if Has_Predef_Eq_Renaming
then
9761 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
9763 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9764 while Present
(Prim
) loop
9766 -- Any renamings of equality that appeared before an
9767 -- overriding equality must be updated to refer to the
9768 -- entity for the predefined equality, otherwise calls via
9769 -- the renaming would get incorrectly resolved to call the
9770 -- user-defined equality function.
9772 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9773 Set_Alias
(Node
(Prim
), Renamed_Eq
);
9775 -- Exit upon encountering a user-defined equality
9777 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
9778 and then No
(Alias
(Node
(Prim
)))
9788 -- Spec for dispatching assignment
9790 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9792 Name
=> Name_uAssign
,
9793 Profile
=> New_List
(
9794 Make_Parameter_Specification
(Loc
,
9795 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9796 Out_Present
=> True,
9797 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9799 Make_Parameter_Specification
(Loc
,
9800 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
9801 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
9804 -- Ada 2005: Generate declarations for the following primitive
9805 -- operations for limited interfaces and synchronized types that
9806 -- implement a limited interface.
9808 -- Disp_Asynchronous_Select
9809 -- Disp_Conditional_Select
9810 -- Disp_Get_Prim_Op_Kind
9813 -- Disp_Timed_Select
9815 -- Disable the generation of these bodies if No_Dispatching_Calls,
9816 -- Ravenscar or ZFP is active.
9818 if Ada_Version
>= Ada_2005
9819 and then not Restriction_Active
(No_Dispatching_Calls
)
9820 and then not Restriction_Active
(No_Select_Statements
)
9821 and then RTE_Available
(RE_Select_Specific_Data
)
9823 -- These primitives are defined abstract in interface types
9825 if Is_Interface
(Tag_Typ
)
9826 and then Is_Limited_Record
(Tag_Typ
)
9829 Make_Abstract_Subprogram_Declaration
(Loc
,
9831 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9834 Make_Abstract_Subprogram_Declaration
(Loc
,
9836 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9839 Make_Abstract_Subprogram_Declaration
(Loc
,
9841 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9844 Make_Abstract_Subprogram_Declaration
(Loc
,
9846 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9849 Make_Abstract_Subprogram_Declaration
(Loc
,
9851 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9854 Make_Abstract_Subprogram_Declaration
(Loc
,
9856 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9858 -- If ancestor is an interface type, declare non-abstract primitives
9859 -- to override the abstract primitives of the interface type.
9861 -- In VM targets we define these primitives in all root tagged types
9862 -- that are not interface types. Done because in VM targets we don't
9863 -- have secondary dispatch tables and any derivation of Tag_Typ may
9864 -- cover limited interfaces (which always have these primitives since
9865 -- they may be ancestors of synchronized interface types).
9867 elsif (not Is_Interface
(Tag_Typ
)
9868 and then Is_Interface
(Etype
(Tag_Typ
))
9869 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
9871 (Is_Concurrent_Record_Type
(Tag_Typ
)
9872 and then Has_Interfaces
(Tag_Typ
))
9874 (not Tagged_Type_Expansion
9875 and then not Is_Interface
(Tag_Typ
)
9876 and then Tag_Typ
= Root_Type
(Tag_Typ
))
9879 Make_Subprogram_Declaration
(Loc
,
9881 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9884 Make_Subprogram_Declaration
(Loc
,
9886 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9889 Make_Subprogram_Declaration
(Loc
,
9891 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9894 Make_Subprogram_Declaration
(Loc
,
9896 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9899 Make_Subprogram_Declaration
(Loc
,
9901 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9904 Make_Subprogram_Declaration
(Loc
,
9906 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9910 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
9911 -- regardless of whether they are controlled or may contain controlled
9914 -- Do not generate the routines if finalization is disabled
9916 if Restriction_Active
(No_Finalization
) then
9919 -- Finalization is not available for CIL value types
9921 elsif Is_Value_Type
(Tag_Typ
) then
9925 if not Is_Limited_Type
(Tag_Typ
) then
9926 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
9929 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
9933 end Make_Predefined_Primitive_Specs
;
9935 -------------------------
9936 -- Make_Tag_Assignment --
9937 -------------------------
9939 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
9940 Loc
: constant Source_Ptr
:= Sloc
(N
);
9941 Def_If
: constant Entity_Id
:= Defining_Identifier
(N
);
9942 Expr
: constant Node_Id
:= Expression
(N
);
9943 Typ
: constant Entity_Id
:= Etype
(Def_If
);
9944 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
9948 -- This expansion activity is called during analysis, but cannot
9949 -- be applied in ASIS mode when other expansion is disabled.
9951 if Is_Tagged_Type
(Typ
)
9952 and then not Is_Class_Wide_Type
(Typ
)
9953 and then not Is_CPP_Class
(Typ
)
9954 and then Tagged_Type_Expansion
9955 and then Nkind
(Expr
) /= N_Aggregate
9956 and then not ASIS_Mode
9957 and then (Nkind
(Expr
) /= N_Qualified_Expression
9958 or else Nkind
(Expression
(Expr
)) /= N_Aggregate
)
9961 Make_Selected_Component
(Loc
,
9962 Prefix
=> New_Occurrence_Of
(Def_If
, Loc
),
9964 New_Occurrence_Of
(First_Tag_Component
(Full_Typ
), Loc
));
9965 Set_Assignment_OK
(New_Ref
);
9968 Make_Assignment_Statement
(Loc
,
9971 Unchecked_Convert_To
(RTE
(RE_Tag
),
9972 New_Occurrence_Of
(Node
9973 (First_Elmt
(Access_Disp_Table
(Full_Typ
))), Loc
)));
9977 end Make_Tag_Assignment
;
9979 ---------------------------------
9980 -- Needs_Simple_Initialization --
9981 ---------------------------------
9983 function Needs_Simple_Initialization
9985 Consider_IS
: Boolean := True) return Boolean
9987 Consider_IS_NS
: constant Boolean :=
9988 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
9991 -- Never need initialization if it is suppressed
9993 if Initialization_Suppressed
(T
) then
9997 -- Check for private type, in which case test applies to the underlying
9998 -- type of the private type.
10000 if Is_Private_Type
(T
) then
10002 RT
: constant Entity_Id
:= Underlying_Type
(T
);
10004 if Present
(RT
) then
10005 return Needs_Simple_Initialization
(RT
);
10011 -- Scalar type with Default_Value aspect requires initialization
10013 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
10016 -- Cases needing simple initialization are access types, and, if pragma
10017 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
10020 elsif Is_Access_Type
(T
)
10021 or else (Consider_IS_NS
and then (Is_Scalar_Type
(T
)))
10025 -- If Initialize/Normalize_Scalars is in effect, string objects also
10026 -- need initialization, unless they are created in the course of
10027 -- expanding an aggregate (since in the latter case they will be
10028 -- filled with appropriate initializing values before they are used).
10030 elsif Consider_IS_NS
10031 and then Is_Standard_String_Type
(T
)
10034 or else Nkind
(Associated_Node_For_Itype
(T
)) /= N_Aggregate
)
10041 end Needs_Simple_Initialization
;
10043 ----------------------
10044 -- Predef_Deep_Spec --
10045 ----------------------
10047 function Predef_Deep_Spec
10049 Tag_Typ
: Entity_Id
;
10050 Name
: TSS_Name_Type
;
10051 For_Body
: Boolean := False) return Node_Id
10056 -- V : in out Tag_Typ
10058 Formals
:= New_List
(
10059 Make_Parameter_Specification
(Loc
,
10060 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
10061 In_Present
=> True,
10062 Out_Present
=> True,
10063 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
10065 -- F : Boolean := True
10067 if Name
= TSS_Deep_Adjust
10068 or else Name
= TSS_Deep_Finalize
10070 Append_To
(Formals
,
10071 Make_Parameter_Specification
(Loc
,
10072 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
10073 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
10074 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10078 Predef_Spec_Or_Body
(Loc
,
10079 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10080 Tag_Typ
=> Tag_Typ
,
10081 Profile
=> Formals
,
10082 For_Body
=> For_Body
);
10085 when RE_Not_Available
=>
10087 end Predef_Deep_Spec
;
10089 -------------------------
10090 -- Predef_Spec_Or_Body --
10091 -------------------------
10093 function Predef_Spec_Or_Body
10095 Tag_Typ
: Entity_Id
;
10098 Ret_Type
: Entity_Id
:= Empty
;
10099 For_Body
: Boolean := False) return Node_Id
10101 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
10105 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
10107 -- The internal flag is set to mark these declarations because they have
10108 -- specific properties. First, they are primitives even if they are not
10109 -- defined in the type scope (the freezing point is not necessarily in
10110 -- the same scope). Second, the predefined equality can be overridden by
10111 -- a user-defined equality, no body will be generated in this case.
10113 Set_Is_Internal
(Id
);
10115 if not Debug_Generated_Code
then
10116 Set_Debug_Info_Off
(Id
);
10119 if No
(Ret_Type
) then
10121 Make_Procedure_Specification
(Loc
,
10122 Defining_Unit_Name
=> Id
,
10123 Parameter_Specifications
=> Profile
);
10126 Make_Function_Specification
(Loc
,
10127 Defining_Unit_Name
=> Id
,
10128 Parameter_Specifications
=> Profile
,
10129 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
10132 if Is_Interface
(Tag_Typ
) then
10133 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10135 -- If body case, return empty subprogram body. Note that this is ill-
10136 -- formed, because there is not even a null statement, and certainly not
10137 -- a return in the function case. The caller is expected to do surgery
10138 -- on the body to add the appropriate stuff.
10140 elsif For_Body
then
10141 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
10143 -- For the case of an Input attribute predefined for an abstract type,
10144 -- generate an abstract specification. This will never be called, but we
10145 -- need the slot allocated in the dispatching table so that attributes
10146 -- typ'Class'Input and typ'Class'Output will work properly.
10148 elsif Is_TSS
(Name
, TSS_Stream_Input
)
10149 and then Is_Abstract_Type
(Tag_Typ
)
10151 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10153 -- Normal spec case, where we return a subprogram declaration
10156 return Make_Subprogram_Declaration
(Loc
, Spec
);
10158 end Predef_Spec_Or_Body
;
10160 -----------------------------
10161 -- Predef_Stream_Attr_Spec --
10162 -----------------------------
10164 function Predef_Stream_Attr_Spec
10166 Tag_Typ
: Entity_Id
;
10167 Name
: TSS_Name_Type
;
10168 For_Body
: Boolean := False) return Node_Id
10170 Ret_Type
: Entity_Id
;
10173 if Name
= TSS_Stream_Input
then
10174 Ret_Type
:= Tag_Typ
;
10180 Predef_Spec_Or_Body
10182 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10183 Tag_Typ
=> Tag_Typ
,
10184 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
10185 Ret_Type
=> Ret_Type
,
10186 For_Body
=> For_Body
);
10187 end Predef_Stream_Attr_Spec
;
10189 ---------------------------------
10190 -- Predefined_Primitive_Bodies --
10191 ---------------------------------
10193 function Predefined_Primitive_Bodies
10194 (Tag_Typ
: Entity_Id
;
10195 Renamed_Eq
: Entity_Id
) return List_Id
10197 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
10198 Res
: constant List_Id
:= New_List
;
10201 Eq_Needed
: Boolean;
10205 pragma Warnings
(Off
, Ent
);
10208 pragma Assert
(not Is_Interface
(Tag_Typ
));
10210 -- See if we have a predefined "=" operator
10212 if Present
(Renamed_Eq
) then
10214 Eq_Name
:= Chars
(Renamed_Eq
);
10216 -- If the parent is an interface type then it has defined all the
10217 -- predefined primitives abstract and we need to check if the type
10218 -- has some user defined "=" function which matches the profile of
10219 -- the Ada predefined equality operator to avoid generating it.
10221 elsif Is_Interface
(Etype
(Tag_Typ
)) then
10223 Eq_Name
:= Name_Op_Eq
;
10225 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10226 while Present
(Prim
) loop
10227 if Chars
(Node
(Prim
)) = Name_Op_Eq
10228 and then not Is_Internal
(Node
(Prim
))
10229 and then Present
(First_Entity
(Node
(Prim
)))
10231 -- The predefined equality primitive must have exactly two
10232 -- formals whose type is this tagged type
10234 and then Present
(Last_Entity
(Node
(Prim
)))
10235 and then Next_Entity
(First_Entity
(Node
(Prim
)))
10236 = Last_Entity
(Node
(Prim
))
10237 and then Etype
(First_Entity
(Node
(Prim
))) = Tag_Typ
10238 and then Etype
(Last_Entity
(Node
(Prim
))) = Tag_Typ
10240 Eq_Needed
:= False;
10241 Eq_Name
:= No_Name
;
10249 Eq_Needed
:= False;
10250 Eq_Name
:= No_Name
;
10252 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10253 while Present
(Prim
) loop
10254 if Chars
(Node
(Prim
)) = Name_Op_Eq
10255 and then Is_Internal
(Node
(Prim
))
10258 Eq_Name
:= Name_Op_Eq
;
10268 Decl
:= Predef_Spec_Or_Body
(Loc
,
10269 Tag_Typ
=> Tag_Typ
,
10270 Name
=> Name_uSize
,
10271 Profile
=> New_List
(
10272 Make_Parameter_Specification
(Loc
,
10273 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10274 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10276 Ret_Type
=> Standard_Long_Long_Integer
,
10279 Set_Handled_Statement_Sequence
(Decl
,
10280 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10281 Make_Simple_Return_Statement
(Loc
,
10283 Make_Attribute_Reference
(Loc
,
10284 Prefix
=> Make_Identifier
(Loc
, Name_X
),
10285 Attribute_Name
=> Name_Size
)))));
10287 Append_To
(Res
, Decl
);
10289 -- Bodies for Dispatching stream IO routines. We need these only for
10290 -- non-limited types (in the limited case there is no dispatching).
10291 -- We also skip them if dispatching or finalization are not available
10292 -- or if stream operations are prohibited by restriction No_Streams or
10293 -- from use of pragma/aspect No_Tagged_Streams.
10295 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
10296 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
10298 Build_Record_Read_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10299 Append_To
(Res
, Decl
);
10302 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
10303 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
10305 Build_Record_Write_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10306 Append_To
(Res
, Decl
);
10309 -- Skip body of _Input for the abstract case, since the corresponding
10310 -- spec is abstract (see Predef_Spec_Or_Body).
10312 if not Is_Abstract_Type
(Tag_Typ
)
10313 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
10314 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
10316 Build_Record_Or_Elementary_Input_Function
10317 (Loc
, Tag_Typ
, Decl
, Ent
);
10318 Append_To
(Res
, Decl
);
10321 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
10322 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
10324 Build_Record_Or_Elementary_Output_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10325 Append_To
(Res
, Decl
);
10328 -- Ada 2005: Generate bodies for the following primitive operations for
10329 -- limited interfaces and synchronized types that implement a limited
10332 -- disp_asynchronous_select
10333 -- disp_conditional_select
10334 -- disp_get_prim_op_kind
10335 -- disp_get_task_id
10336 -- disp_timed_select
10338 -- The interface versions will have null bodies
10340 -- Disable the generation of these bodies if No_Dispatching_Calls,
10341 -- Ravenscar or ZFP is active.
10343 -- In VM targets we define these primitives in all root tagged types
10344 -- that are not interface types. Done because in VM targets we don't
10345 -- have secondary dispatch tables and any derivation of Tag_Typ may
10346 -- cover limited interfaces (which always have these primitives since
10347 -- they may be ancestors of synchronized interface types).
10349 if Ada_Version
>= Ada_2005
10350 and then not Is_Interface
(Tag_Typ
)
10352 ((Is_Interface
(Etype
(Tag_Typ
))
10353 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10355 (Is_Concurrent_Record_Type
(Tag_Typ
)
10356 and then Has_Interfaces
(Tag_Typ
))
10358 (not Tagged_Type_Expansion
10359 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
10360 and then not Restriction_Active
(No_Dispatching_Calls
)
10361 and then not Restriction_Active
(No_Select_Statements
)
10362 and then RTE_Available
(RE_Select_Specific_Data
)
10364 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
10365 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
10366 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
10367 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
10368 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
10369 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
10372 if not Is_Limited_Type
(Tag_Typ
) and then not Is_Interface
(Tag_Typ
) then
10374 -- Body for equality
10377 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
10378 Append_To
(Res
, Decl
);
10381 -- Body for inequality (if required)
10383 Decl
:= Make_Neq_Body
(Tag_Typ
);
10385 if Present
(Decl
) then
10386 Append_To
(Res
, Decl
);
10389 -- Body for dispatching assignment
10392 Predef_Spec_Or_Body
(Loc
,
10393 Tag_Typ
=> Tag_Typ
,
10394 Name
=> Name_uAssign
,
10395 Profile
=> New_List
(
10396 Make_Parameter_Specification
(Loc
,
10397 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10398 Out_Present
=> True,
10399 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
10401 Make_Parameter_Specification
(Loc
,
10402 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
10403 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10406 Set_Handled_Statement_Sequence
(Decl
,
10407 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10408 Make_Assignment_Statement
(Loc
,
10409 Name
=> Make_Identifier
(Loc
, Name_X
),
10410 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
10412 Append_To
(Res
, Decl
);
10415 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
10416 -- tagged types which do not contain controlled components.
10418 -- Do not generate the routines if finalization is disabled
10420 if Restriction_Active
(No_Finalization
) then
10423 elsif not Has_Controlled_Component
(Tag_Typ
) then
10424 if not Is_Limited_Type
(Tag_Typ
) then
10425 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
10427 if Is_Controlled
(Tag_Typ
) then
10428 Set_Handled_Statement_Sequence
(Decl
,
10429 Make_Handled_Sequence_Of_Statements
(Loc
,
10430 Statements
=> New_List
(
10432 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10433 Typ
=> Tag_Typ
))));
10436 Set_Handled_Statement_Sequence
(Decl
,
10437 Make_Handled_Sequence_Of_Statements
(Loc
,
10438 Statements
=> New_List
(
10439 Make_Null_Statement
(Loc
))));
10442 Append_To
(Res
, Decl
);
10445 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
10447 if Is_Controlled
(Tag_Typ
) then
10448 Set_Handled_Statement_Sequence
(Decl
,
10449 Make_Handled_Sequence_Of_Statements
(Loc
,
10450 Statements
=> New_List
(
10452 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10453 Typ
=> Tag_Typ
))));
10456 Set_Handled_Statement_Sequence
(Decl
,
10457 Make_Handled_Sequence_Of_Statements
(Loc
,
10458 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
10461 Append_To
(Res
, Decl
);
10465 end Predefined_Primitive_Bodies
;
10467 ---------------------------------
10468 -- Predefined_Primitive_Freeze --
10469 ---------------------------------
10471 function Predefined_Primitive_Freeze
10472 (Tag_Typ
: Entity_Id
) return List_Id
10474 Res
: constant List_Id
:= New_List
;
10479 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10480 while Present
(Prim
) loop
10481 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
10482 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
10484 if Present
(Frnodes
) then
10485 Append_List_To
(Res
, Frnodes
);
10493 end Predefined_Primitive_Freeze
;
10495 -------------------------
10496 -- Stream_Operation_OK --
10497 -------------------------
10499 function Stream_Operation_OK
10501 Operation
: TSS_Name_Type
) return Boolean
10503 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
10506 -- Special case of a limited type extension: a default implementation
10507 -- of the stream attributes Read or Write exists if that attribute
10508 -- has been specified or is available for an ancestor type; a default
10509 -- implementation of the attribute Output (resp. Input) exists if the
10510 -- attribute has been specified or Write (resp. Read) is available for
10511 -- an ancestor type. The last condition only applies under Ada 2005.
10513 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
10514 if Operation
= TSS_Stream_Read
then
10515 Has_Predefined_Or_Specified_Stream_Attribute
:=
10516 Has_Specified_Stream_Read
(Typ
);
10518 elsif Operation
= TSS_Stream_Write
then
10519 Has_Predefined_Or_Specified_Stream_Attribute
:=
10520 Has_Specified_Stream_Write
(Typ
);
10522 elsif Operation
= TSS_Stream_Input
then
10523 Has_Predefined_Or_Specified_Stream_Attribute
:=
10524 Has_Specified_Stream_Input
(Typ
)
10526 (Ada_Version
>= Ada_2005
10527 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
10529 elsif Operation
= TSS_Stream_Output
then
10530 Has_Predefined_Or_Specified_Stream_Attribute
:=
10531 Has_Specified_Stream_Output
(Typ
)
10533 (Ada_Version
>= Ada_2005
10534 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
10537 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
10539 if not Has_Predefined_Or_Specified_Stream_Attribute
10540 and then Is_Derived_Type
(Typ
)
10541 and then (Operation
= TSS_Stream_Read
10542 or else Operation
= TSS_Stream_Write
)
10544 Has_Predefined_Or_Specified_Stream_Attribute
:=
10546 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
10550 -- If the type is not limited, or else is limited but the attribute is
10551 -- explicitly specified or is predefined for the type, then return True,
10552 -- unless other conditions prevail, such as restrictions prohibiting
10553 -- streams or dispatching operations. We also return True for limited
10554 -- interfaces, because they may be extended by nonlimited types and
10555 -- permit inheritance in this case (addresses cases where an abstract
10556 -- extension doesn't get 'Input declared, as per comments below, but
10557 -- 'Class'Input must still be allowed). Note that attempts to apply
10558 -- stream attributes to a limited interface or its class-wide type
10559 -- (or limited extensions thereof) will still get properly rejected
10560 -- by Check_Stream_Attribute.
10562 -- We exclude the Input operation from being a predefined subprogram in
10563 -- the case where the associated type is an abstract extension, because
10564 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
10565 -- we don't want an abstract version created because types derived from
10566 -- the abstract type may not even have Input available (for example if
10567 -- derived from a private view of the abstract type that doesn't have
10568 -- a visible Input), but a VM such as .NET or the Java VM can treat the
10569 -- operation as inherited anyway, and we don't want an abstract function
10570 -- to be (implicitly) inherited in that case because it can lead to a VM
10573 -- Do not generate stream routines for type Finalization_Master because
10574 -- a master may never appear in types and therefore cannot be read or
10578 (not Is_Limited_Type
(Typ
)
10579 or else Is_Interface
(Typ
)
10580 or else Has_Predefined_Or_Specified_Stream_Attribute
)
10582 (Operation
/= TSS_Stream_Input
10583 or else not Is_Abstract_Type
(Typ
)
10584 or else not Is_Derived_Type
(Typ
))
10585 and then not Has_Unknown_Discriminants
(Typ
)
10587 (Is_Interface
(Typ
)
10589 (Is_Task_Interface
(Typ
)
10590 or else Is_Protected_Interface
(Typ
)
10591 or else Is_Synchronized_Interface
(Typ
)))
10592 and then not Restriction_Active
(No_Streams
)
10593 and then not Restriction_Active
(No_Dispatch
)
10594 and then No
(No_Tagged_Streams_Pragma
(Typ
))
10595 and then not No_Run_Time_Mode
10596 and then RTE_Available
(RE_Tag
)
10597 and then No
(Type_Without_Stream_Operation
(Typ
))
10598 and then RTE_Available
(RE_Root_Stream_Type
)
10599 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
10600 end Stream_Operation_OK
;