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
);
4800 -- Start of processing for Expand_N_Full_Type_Declaration
4803 if Is_Access_Type
(Def_Id
) then
4804 Build_Master
(Def_Id
);
4806 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
4807 Expand_Access_Protected_Subprogram_Type
(N
);
4810 -- Array of anonymous access-to-task pointers
4812 elsif Ada_Version
>= Ada_2005
4813 and then Is_Array_Type
(Def_Id
)
4814 and then Is_Access_Type
(Component_Type
(Def_Id
))
4815 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
4817 Build_Master
(Component_Type
(Def_Id
));
4819 elsif Has_Task
(Def_Id
) then
4820 Expand_Previous_Access_Type
(Def_Id
);
4822 -- Check the components of a record type or array of records for
4823 -- anonymous access-to-task pointers.
4825 elsif Ada_Version
>= Ada_2005
4826 and then (Is_Record_Type
(Def_Id
)
4828 (Is_Array_Type
(Def_Id
)
4829 and then Is_Record_Type
(Component_Type
(Def_Id
))))
4838 if Is_Array_Type
(Def_Id
) then
4839 Comp
:= First_Entity
(Component_Type
(Def_Id
));
4841 Comp
:= First_Entity
(Def_Id
);
4844 -- Examine all components looking for anonymous access-to-task
4848 while Present
(Comp
) loop
4849 Typ
:= Etype
(Comp
);
4851 if Ekind
(Typ
) = E_Anonymous_Access_Type
4852 and then Has_Task
(Available_View
(Designated_Type
(Typ
)))
4853 and then No
(Master_Id
(Typ
))
4855 -- Ensure that the record or array type have a _master
4858 Build_Master_Entity
(Def_Id
);
4859 Build_Master_Renaming
(Typ
);
4860 M_Id
:= Master_Id
(Typ
);
4864 -- Reuse the same master to service any additional types
4867 Set_Master_Id
(Typ
, M_Id
);
4876 Par_Id
:= Etype
(B_Id
);
4878 -- The parent type is private then we need to inherit any TSS operations
4879 -- from the full view.
4881 if Ekind
(Par_Id
) in Private_Kind
4882 and then Present
(Full_View
(Par_Id
))
4884 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
4887 if Nkind
(Type_Definition
(Original_Node
(N
))) =
4888 N_Derived_Type_Definition
4889 and then not Is_Tagged_Type
(Def_Id
)
4890 and then Present
(Freeze_Node
(Par_Id
))
4891 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
4893 Ensure_Freeze_Node
(B_Id
);
4894 FN
:= Freeze_Node
(B_Id
);
4896 if No
(TSS_Elist
(FN
)) then
4897 Set_TSS_Elist
(FN
, New_Elmt_List
);
4901 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
4905 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
4906 while Present
(Elmt
) loop
4907 if Chars
(Node
(Elmt
)) /= Name_uInit
then
4908 Append_Elmt
(Node
(Elmt
), T_E
);
4914 -- If the derived type itself is private with a full view, then
4915 -- associate the full view with the inherited TSS_Elist as well.
4917 if Ekind
(B_Id
) in Private_Kind
4918 and then Present
(Full_View
(B_Id
))
4920 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
4922 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
4926 end Expand_N_Full_Type_Declaration
;
4928 ---------------------------------
4929 -- Expand_N_Object_Declaration --
4930 ---------------------------------
4932 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
4933 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
4934 Expr
: constant Node_Id
:= Expression
(N
);
4935 Loc
: constant Source_Ptr
:= Sloc
(N
);
4936 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
4937 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
4938 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4941 function Build_Equivalent_Aggregate
return Boolean;
4942 -- If the object has a constrained discriminated type and no initial
4943 -- value, it may be possible to build an equivalent aggregate instead,
4944 -- and prevent an actual call to the initialization procedure.
4946 procedure Default_Initialize_Object
(After
: Node_Id
);
4947 -- Generate all default initialization actions for object Def_Id. Any
4948 -- new code is inserted after node After.
4950 function Rewrite_As_Renaming
return Boolean;
4951 -- Indicate whether to rewrite a declaration with initialization into an
4952 -- object renaming declaration (see below).
4954 --------------------------------
4955 -- Build_Equivalent_Aggregate --
4956 --------------------------------
4958 function Build_Equivalent_Aggregate
return Boolean is
4962 Full_Type
: Entity_Id
;
4967 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
4968 Full_Type
:= Full_View
(Typ
);
4971 -- Only perform this transformation if Elaboration_Code is forbidden
4972 -- or undesirable, and if this is a global entity of a constrained
4975 -- If Initialize_Scalars might be active this transformation cannot
4976 -- be performed either, because it will lead to different semantics
4977 -- or because elaboration code will in fact be created.
4979 if Ekind
(Full_Type
) /= E_Record_Subtype
4980 or else not Has_Discriminants
(Full_Type
)
4981 or else not Is_Constrained
(Full_Type
)
4982 or else Is_Controlled
(Full_Type
)
4983 or else Is_Limited_Type
(Full_Type
)
4984 or else not Restriction_Active
(No_Initialize_Scalars
)
4989 if Ekind
(Current_Scope
) = E_Package
4991 (Restriction_Active
(No_Elaboration_Code
)
4992 or else Is_Preelaborated
(Current_Scope
))
4994 -- Building a static aggregate is possible if the discriminants
4995 -- have static values and the other components have static
4996 -- defaults or none.
4998 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
4999 while Present
(Discr
) loop
5000 if not Is_OK_Static_Expression
(Node
(Discr
)) then
5007 -- Check that initialized components are OK, and that non-
5008 -- initialized components do not require a call to their own
5009 -- initialization procedure.
5011 Comp
:= First_Component
(Full_Type
);
5012 while Present
(Comp
) loop
5013 if Ekind
(Comp
) = E_Component
5014 and then Present
(Expression
(Parent
(Comp
)))
5016 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
5020 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
5025 Next_Component
(Comp
);
5028 -- Everything is static, assemble the aggregate, discriminant
5032 Make_Aggregate
(Loc
,
5033 Expressions
=> New_List
,
5034 Component_Associations
=> New_List
);
5036 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5037 while Present
(Discr
) loop
5038 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
5042 -- Now collect values of initialized components
5044 Comp
:= First_Component
(Full_Type
);
5045 while Present
(Comp
) loop
5046 if Ekind
(Comp
) = E_Component
5047 and then Present
(Expression
(Parent
(Comp
)))
5049 Append_To
(Component_Associations
(Aggr
),
5050 Make_Component_Association
(Loc
,
5051 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
5052 Expression
=> New_Copy_Tree
5053 (Expression
(Parent
(Comp
)))));
5056 Next_Component
(Comp
);
5059 -- Finally, box-initialize remaining components
5061 Append_To
(Component_Associations
(Aggr
),
5062 Make_Component_Association
(Loc
,
5063 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5064 Expression
=> Empty
));
5065 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
5066 Set_Expression
(N
, Aggr
);
5068 if Typ
/= Full_Type
then
5069 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
5070 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
5071 Analyze_And_Resolve
(Aggr
, Typ
);
5073 Analyze_And_Resolve
(Aggr
, Full_Type
);
5081 end Build_Equivalent_Aggregate
;
5083 -------------------------------
5084 -- Default_Initialize_Object --
5085 -------------------------------
5087 procedure Default_Initialize_Object
(After
: Node_Id
) is
5088 function New_Object_Reference
return Node_Id
;
5089 -- Return a new reference to Def_Id with attributes Assignment_OK and
5090 -- Must_Not_Freeze already set.
5092 --------------------------
5093 -- New_Object_Reference --
5094 --------------------------
5096 function New_Object_Reference
return Node_Id
is
5097 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
5100 -- The call to the type init proc or [Deep_]Finalize must not
5101 -- freeze the related object as the call is internally generated.
5102 -- This way legal rep clauses that apply to the object will not be
5103 -- flagged. Note that the initialization call may be removed if
5104 -- pragma Import is encountered or moved to the freeze actions of
5105 -- the object because of an address clause.
5107 Set_Assignment_OK
(Obj_Ref
);
5108 Set_Must_Not_Freeze
(Obj_Ref
);
5111 end New_Object_Reference
;
5117 Abrt_Id
: Entity_Id
;
5118 Abrt_Stmts
: List_Id
;
5119 Aggr_Init
: Node_Id
;
5120 Comp_Init
: List_Id
:= No_List
;
5122 Fin_Stmts
: List_Id
:= No_List
;
5123 Obj_Init
: Node_Id
:= Empty
;
5127 -- This variable captures a dummy internal entity, see the comment
5128 -- associated with its use.
5130 -- Start of processing for Default_Initialize_Object
5133 -- Default initialization is suppressed for objects that are already
5134 -- known to be imported (i.e. whose declaration specifies the Import
5135 -- aspect). Note that for objects with a pragma Import, we generate
5136 -- initialization here, and then remove it downstream when processing
5137 -- the pragma. It is also suppressed for variables for which a pragma
5138 -- Suppress_Initialization has been explicitly given
5140 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
5144 -- Step 1: Initialize the object
5146 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
5149 (Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
5153 -- Step 2: Initialize the components of the object
5155 -- Do not initialize the components if their initialization is
5156 -- prohibited or the type represents a value type in a .NET VM.
5158 if Has_Non_Null_Base_Init_Proc
(Typ
)
5159 and then not No_Initialization
(N
)
5160 and then not Initialization_Suppressed
(Typ
)
5161 and then not Is_Value_Type
(Typ
)
5163 -- Do not initialize the components if No_Default_Initialization
5164 -- applies as the the actual restriction check will occur later
5165 -- when the object is frozen as it is not known yet whether the
5166 -- object is imported or not.
5168 if not Restriction_Active
(No_Default_Initialization
) then
5170 -- If the values of the components are compile-time known, use
5171 -- their prebuilt aggregate form directly.
5173 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
5175 if Present
(Aggr_Init
) then
5177 (N
, New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
5179 -- If type has discriminants, try to build an equivalent
5180 -- aggregate using discriminant values from the declaration.
5181 -- This is a useful optimization, in particular if restriction
5182 -- No_Elaboration_Code is active.
5184 elsif Build_Equivalent_Aggregate
then
5187 -- Otherwise invoke the type init proc
5190 Obj_Ref
:= New_Object_Reference
;
5192 if Comes_From_Source
(Def_Id
) then
5193 Initialization_Warning
(Obj_Ref
);
5196 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
5200 -- Provide a default value if the object needs simple initialization
5201 -- and does not already have an initial value. A generated temporary
5202 -- do not require initialization because it will be assigned later.
5204 elsif Needs_Simple_Initialization
5205 (Typ
, Initialize_Scalars
5206 and then No
(Following_Address_Clause
(N
)))
5207 and then not Is_Internal
(Def_Id
)
5208 and then not Has_Init_Expression
(N
)
5210 Set_No_Initialization
(N
, False);
5211 Set_Expression
(N
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Def_Id
)));
5212 Analyze_And_Resolve
(Expression
(N
), Typ
);
5215 -- Step 3: Add partial finalization and abort actions, generate:
5217 -- Type_Init_Proc (Obj);
5219 -- Deep_Initialize (Obj);
5222 -- Deep_Finalize (Obj, Self => False);
5226 -- Step 3a: Build the finalization block (if applicable)
5228 -- The finalization block is required when both the object and its
5229 -- controlled components are to be initialized. The block finalizes
5230 -- the components if the object initialization fails.
5232 if Has_Controlled_Component
(Typ
)
5233 and then Present
(Comp_Init
)
5234 and then Present
(Obj_Init
)
5235 and then not Restriction_Active
(No_Exception_Propagation
)
5238 -- Type_Init_Proc (Obj);
5240 Fin_Stmts
:= Comp_Init
;
5244 -- Deep_Initialize (Obj);
5247 -- Deep_Finalize (Obj, Self => False);
5253 (Obj_Ref
=> New_Object_Reference
,
5257 if Present
(Fin_Call
) then
5259 -- Do not emit warnings related to the elaboration order when a
5260 -- controlled object is declared before the body of Finalize is
5263 Set_No_Elaboration_Check
(Fin_Call
);
5265 Append_To
(Fin_Stmts
,
5266 Make_Block_Statement
(Loc
,
5267 Declarations
=> No_List
,
5269 Handled_Statement_Sequence
=>
5270 Make_Handled_Sequence_Of_Statements
(Loc
,
5271 Statements
=> New_List
(Obj_Init
),
5273 Exception_Handlers
=> New_List
(
5274 Make_Exception_Handler
(Loc
,
5275 Exception_Choices
=> New_List
(
5276 Make_Others_Choice
(Loc
)),
5278 Statements
=> New_List
(
5280 Make_Raise_Statement
(Loc
)))))));
5283 -- Finalization is not required, the initialization calls are passed
5284 -- to the abort block building circuitry, generate:
5286 -- Type_Init_Proc (Obj);
5287 -- Deep_Initialize (Obj);
5290 if Present
(Comp_Init
) then
5291 Fin_Stmts
:= Comp_Init
;
5294 if Present
(Obj_Init
) then
5295 if No
(Fin_Stmts
) then
5296 Fin_Stmts
:= New_List
;
5299 Append_To
(Fin_Stmts
, Obj_Init
);
5303 -- Step 3b: Build the abort block (if applicable)
5305 -- The abort block is required when aborts are allowed in order to
5306 -- protect both initialization calls.
5308 if Present
(Comp_Init
) and then Present
(Obj_Init
) then
5309 if Abort_Allowed
then
5315 (Fin_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
5320 -- <finalization statements>
5322 -- Abort_Undefer_Direct;
5326 AUD
: constant Entity_Id
:= RTE
(RE_Abort_Undefer_Direct
);
5330 Make_Handled_Sequence_Of_Statements
(Loc
,
5331 Statements
=> Fin_Stmts
,
5332 At_End_Proc
=> New_Occurrence_Of
(AUD
, Loc
));
5334 -- Present the Abort_Undefer_Direct function to the backend
5335 -- so that it can inline the call to the function.
5337 Add_Inlined_Body
(AUD
, N
);
5341 Make_Block_Statement
(Loc
,
5342 Declarations
=> No_List
,
5343 Handled_Statement_Sequence
=> Abrt_HSS
);
5345 Add_Block_Identifier
(Abrt_Blk
, Abrt_Id
);
5346 Expand_At_End_Handler
(Abrt_HSS
, Abrt_Id
);
5348 Abrt_Stmts
:= New_List
(Abrt_Blk
);
5350 -- Abort is not required
5353 -- Generate a dummy entity to ensure that the internal symbols
5354 -- are in sync when a unit is compiled with and without aborts.
5355 -- The entity is a block with proper scope and type.
5357 Dummy
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
5358 Set_Etype
(Dummy
, Standard_Void_Type
);
5359 Abrt_Stmts
:= Fin_Stmts
;
5362 -- No initialization calls present
5365 Abrt_Stmts
:= Fin_Stmts
;
5368 -- Step 4: Insert the whole initialization sequence into the tree
5369 -- If the object has a delayed freeze, as will be the case when
5370 -- it has aspect specifications, the initialization sequence is
5371 -- part of the freeze actions.
5373 if Has_Delayed_Freeze
(Def_Id
) then
5374 Append_Freeze_Actions
(Def_Id
, Abrt_Stmts
);
5376 Insert_Actions_After
(After
, Abrt_Stmts
);
5378 end Default_Initialize_Object
;
5380 -------------------------
5381 -- Rewrite_As_Renaming --
5382 -------------------------
5384 function Rewrite_As_Renaming
return Boolean is
5386 return not Aliased_Present
(N
)
5387 and then Is_Entity_Name
(Expr_Q
)
5388 and then Ekind
(Entity
(Expr_Q
)) = E_Variable
5389 and then OK_To_Rename
(Entity
(Expr_Q
))
5390 and then Is_Entity_Name
(Obj_Def
);
5391 end Rewrite_As_Renaming
;
5395 Next_N
: constant Node_Id
:= Next
(N
);
5398 Init_After
: Node_Id
:= N
;
5399 -- Node after which the initialization actions are to be inserted. This
5400 -- is normally N, except for the case of a shared passive variable, in
5401 -- which case the init proc call must be inserted only after the bodies
5402 -- of the shared variable procedures have been seen.
5404 Tag_Assign
: Node_Id
;
5406 -- Start of processing for Expand_N_Object_Declaration
5409 -- Don't do anything for deferred constants. All proper actions will be
5410 -- expanded during the full declaration.
5412 if No
(Expr
) and Constant_Present
(N
) then
5416 -- The type of the object cannot be abstract. This is diagnosed at the
5417 -- point the object is frozen, which happens after the declaration is
5418 -- fully expanded, so simply return now.
5420 if Is_Abstract_Type
(Typ
) then
5424 -- First we do special processing for objects of a tagged type where
5425 -- this is the point at which the type is frozen. The creation of the
5426 -- dispatch table and the initialization procedure have to be deferred
5427 -- to this point, since we reference previously declared primitive
5430 -- Force construction of dispatch tables of library level tagged types
5432 if Tagged_Type_Expansion
5433 and then Static_Dispatch_Tables
5434 and then Is_Library_Level_Entity
(Def_Id
)
5435 and then Is_Library_Level_Tagged_Type
(Base_Typ
)
5436 and then Ekind_In
(Base_Typ
, E_Record_Type
,
5439 and then not Has_Dispatch_Table
(Base_Typ
)
5442 New_Nodes
: List_Id
:= No_List
;
5445 if Is_Concurrent_Type
(Base_Typ
) then
5446 New_Nodes
:= Make_DT
(Corresponding_Record_Type
(Base_Typ
), N
);
5448 New_Nodes
:= Make_DT
(Base_Typ
, N
);
5451 if not Is_Empty_List
(New_Nodes
) then
5452 Insert_List_Before
(N
, New_Nodes
);
5457 -- Make shared memory routines for shared passive variable
5459 if Is_Shared_Passive
(Def_Id
) then
5460 Init_After
:= Make_Shared_Var_Procs
(N
);
5463 -- If tasks being declared, make sure we have an activation chain
5464 -- defined for the tasks (has no effect if we already have one), and
5465 -- also that a Master variable is established and that the appropriate
5466 -- enclosing construct is established as a task master.
5468 if Has_Task
(Typ
) then
5469 Build_Activation_Chain_Entity
(N
);
5470 Build_Master_Entity
(Def_Id
);
5473 -- Default initialization required, and no expression present
5477 -- If we have a type with a variant part, the initialization proc
5478 -- will contain implicit tests of the discriminant values, which
5479 -- counts as a violation of the restriction No_Implicit_Conditionals.
5481 if Has_Variant_Part
(Typ
) then
5486 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
5490 ("\initialization of variant record tests discriminants",
5497 -- For the default initialization case, if we have a private type
5498 -- with invariants, and invariant checks are enabled, then insert an
5499 -- invariant check after the object declaration. Note that it is OK
5500 -- to clobber the object with an invalid value since if the exception
5501 -- is raised, then the object will go out of scope. In the case where
5502 -- an array object is initialized with an aggregate, the expression
5503 -- is removed. Check flag Has_Init_Expression to avoid generating a
5504 -- junk invariant check and flag No_Initialization to avoid checking
5505 -- an uninitialized object such as a compiler temporary used for an
5508 if Has_Invariants
(Base_Typ
)
5509 and then Present
(Invariant_Procedure
(Base_Typ
))
5510 and then not Has_Init_Expression
(N
)
5511 and then not No_Initialization
(N
)
5513 -- If entity has an address clause or aspect, make invariant
5514 -- call into a freeze action for the explicit freeze node for
5515 -- object. Otherwise insert invariant check after declaration.
5517 if Present
(Following_Address_Clause
(N
))
5518 or else Has_Aspect
(Def_Id
, Aspect_Address
)
5520 Ensure_Freeze_Node
(Def_Id
);
5521 Set_Has_Delayed_Freeze
(Def_Id
);
5522 Set_Is_Frozen
(Def_Id
, False);
5524 if not Partial_View_Has_Unknown_Discr
(Typ
) then
5525 Append_Freeze_Action
(Def_Id
,
5526 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
5529 elsif not Partial_View_Has_Unknown_Discr
(Typ
) then
5531 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
5535 Default_Initialize_Object
(Init_After
);
5537 -- Generate attribute for Persistent_BSS if needed
5539 if Persistent_BSS_Mode
5540 and then Comes_From_Source
(N
)
5541 and then Is_Potentially_Persistent_Type
(Typ
)
5542 and then not Has_Init_Expression
(N
)
5543 and then Is_Library_Level_Entity
(Def_Id
)
5549 Make_Linker_Section_Pragma
5550 (Def_Id
, Sloc
(N
), ".persistent.bss");
5551 Insert_After
(N
, Prag
);
5556 -- If access type, then we know it is null if not initialized
5558 if Is_Access_Type
(Typ
) then
5559 Set_Is_Known_Null
(Def_Id
);
5562 -- Explicit initialization present
5565 -- Obtain actual expression from qualified expression
5567 if Nkind
(Expr
) = N_Qualified_Expression
then
5568 Expr_Q
:= Expression
(Expr
);
5573 -- When we have the appropriate type of aggregate in the expression
5574 -- (it has been determined during analysis of the aggregate by
5575 -- setting the delay flag), let's perform in place assignment and
5576 -- thus avoid creating a temporary.
5578 if Is_Delayed_Aggregate
(Expr_Q
) then
5579 Convert_Aggr_In_Object_Decl
(N
);
5581 -- Ada 2005 (AI-318-02): If the initialization expression is a call
5582 -- to a build-in-place function, then access to the declared object
5583 -- must be passed to the function. Currently we limit such functions
5584 -- to those with constrained limited result subtypes, but eventually
5585 -- plan to expand the allowed forms of functions that are treated as
5588 elsif Ada_Version
>= Ada_2005
5589 and then Is_Build_In_Place_Function_Call
(Expr_Q
)
5591 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
5593 -- The previous call expands the expression initializing the
5594 -- built-in-place object into further code that will be analyzed
5595 -- later. No further expansion needed here.
5599 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
5600 -- class-wide interface object to ensure that we copy the full
5601 -- object, unless we are targetting a VM where interfaces are handled
5602 -- by VM itself. Note that if the root type of Typ is an ancestor of
5603 -- Expr's type, both types share the same dispatch table and there is
5604 -- no need to displace the pointer.
5606 elsif Is_Interface
(Typ
)
5608 -- Avoid never-ending recursion because if Equivalent_Type is set
5609 -- then we've done it already and must not do it again.
5612 (Nkind
(Obj_Def
) = N_Identifier
5613 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
5615 pragma Assert
(Is_Class_Wide_Type
(Typ
));
5617 -- If the object is a return object of an inherently limited type,
5618 -- which implies build-in-place treatment, bypass the special
5619 -- treatment of class-wide interface initialization below. In this
5620 -- case, the expansion of the return statement will take care of
5621 -- creating the object (via allocator) and initializing it.
5623 if Is_Return_Object
(Def_Id
) and then Is_Limited_View
(Typ
) then
5626 elsif Tagged_Type_Expansion
then
5628 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
5629 Expr_N
: Node_Id
:= Expr
;
5630 Expr_Typ
: Entity_Id
;
5636 -- If the original node of the expression was a conversion
5637 -- to this specific class-wide interface type then restore
5638 -- the original node because we must copy the object before
5639 -- displacing the pointer to reference the secondary tag
5640 -- component. This code must be kept synchronized with the
5641 -- expansion done by routine Expand_Interface_Conversion
5643 if not Comes_From_Source
(Expr_N
)
5644 and then Nkind
(Expr_N
) = N_Explicit_Dereference
5645 and then Nkind
(Original_Node
(Expr_N
)) = N_Type_Conversion
5646 and then Etype
(Original_Node
(Expr_N
)) = Typ
5648 Rewrite
(Expr_N
, Original_Node
(Expression
(N
)));
5651 -- Avoid expansion of redundant interface conversion
5653 if Is_Interface
(Etype
(Expr_N
))
5654 and then Nkind
(Expr_N
) = N_Type_Conversion
5655 and then Etype
(Expr_N
) = Typ
5657 Expr_N
:= Expression
(Expr_N
);
5658 Set_Expression
(N
, Expr_N
);
5661 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_N
);
5662 Expr_Typ
:= Base_Type
(Etype
(Expr_N
));
5664 if Is_Class_Wide_Type
(Expr_Typ
) then
5665 Expr_Typ
:= Root_Type
(Expr_Typ
);
5669 -- CW : I'Class := Obj;
5672 -- type Ityp is not null access I'Class;
5673 -- CW : I'Class renames Ityp (Tmp.I_Tag'Address).all;
5675 if Comes_From_Source
(Expr_N
)
5676 and then Nkind
(Expr_N
) = N_Identifier
5677 and then not Is_Interface
(Expr_Typ
)
5678 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
5679 and then (Expr_Typ
= Etype
(Expr_Typ
)
5681 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
5686 Make_Object_Declaration
(Loc
,
5687 Defining_Identifier
=> Obj_Id
,
5688 Object_Definition
=>
5689 New_Occurrence_Of
(Expr_Typ
, Loc
),
5690 Expression
=> Relocate_Node
(Expr_N
)));
5692 -- Statically reference the tag associated with the
5696 Make_Selected_Component
(Loc
,
5697 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
5700 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
5703 -- IW : I'Class := Obj;
5705 -- type Equiv_Record is record ... end record;
5706 -- implicit subtype CW is <Class_Wide_Subtype>;
5707 -- Tmp : CW := CW!(Obj);
5708 -- type Ityp is not null access I'Class;
5709 -- IW : I'Class renames
5710 -- Ityp!(Displace (Temp'Address, I'Tag)).all;
5713 -- Generate the equivalent record type and update the
5714 -- subtype indication to reference it.
5716 Expand_Subtype_From_Expr
5719 Subtype_Indic
=> Obj_Def
,
5722 if not Is_Interface
(Etype
(Expr_N
)) then
5723 New_Expr
:= Relocate_Node
(Expr_N
);
5725 -- For interface types we use 'Address which displaces
5726 -- the pointer to the base of the object (if required)
5730 Unchecked_Convert_To
(Etype
(Obj_Def
),
5731 Make_Explicit_Dereference
(Loc
,
5732 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5733 Make_Attribute_Reference
(Loc
,
5734 Prefix
=> Relocate_Node
(Expr_N
),
5735 Attribute_Name
=> Name_Address
))));
5740 if not Is_Limited_Record
(Expr_Typ
) then
5742 Make_Object_Declaration
(Loc
,
5743 Defining_Identifier
=> Obj_Id
,
5744 Object_Definition
=>
5745 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
5746 Expression
=> New_Expr
));
5748 -- Rename limited type object since they cannot be copied
5749 -- This case occurs when the initialization expression
5750 -- has been previously expanded into a temporary object.
5752 else pragma Assert
(not Comes_From_Source
(Expr_Q
));
5754 Make_Object_Renaming_Declaration
(Loc
,
5755 Defining_Identifier
=> Obj_Id
,
5757 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
5759 Unchecked_Convert_To
5760 (Etype
(Obj_Def
), New_Expr
)));
5763 -- Dynamically reference the tag associated with the
5767 Make_Function_Call
(Loc
,
5768 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
5769 Parameter_Associations
=> New_List
(
5770 Make_Attribute_Reference
(Loc
,
5771 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
5772 Attribute_Name
=> Name_Address
),
5774 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
5779 Make_Object_Renaming_Declaration
(Loc
,
5780 Defining_Identifier
=> Make_Temporary
(Loc
, 'D'),
5781 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
5783 Convert_Tag_To_Interface
(Typ
, Tag_Comp
)));
5785 -- If the original entity comes from source, then mark the
5786 -- new entity as needing debug information, even though it's
5787 -- defined by a generated renaming that does not come from
5788 -- source, so that Materialize_Entity will be set on the
5789 -- entity when Debug_Renaming_Declaration is called during
5792 if Comes_From_Source
(Def_Id
) then
5793 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
5796 Analyze
(N
, Suppress
=> All_Checks
);
5798 -- Replace internal identifier of rewritten node by the
5799 -- identifier found in the sources. We also have to exchange
5800 -- entities containing their defining identifiers to ensure
5801 -- the correct replacement of the object declaration by this
5802 -- object renaming declaration because these identifiers
5803 -- were previously added by Enter_Name to the current scope.
5804 -- We must preserve the homonym chain of the source entity
5805 -- as well. We must also preserve the kind of the entity,
5806 -- which may be a constant. Preserve entity chain because
5807 -- itypes may have been generated already, and the full
5808 -- chain must be preserved for final freezing. Finally,
5809 -- preserve Comes_From_Source setting, so that debugging
5810 -- and cross-referencing information is properly kept, and
5811 -- preserve source location, to prevent spurious errors when
5812 -- entities are declared (they must have their own Sloc).
5815 New_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5816 Next_Temp
: constant Entity_Id
:= Next_Entity
(New_Id
);
5817 S_Flag
: constant Boolean :=
5818 Comes_From_Source
(Def_Id
);
5821 Set_Next_Entity
(New_Id
, Next_Entity
(Def_Id
));
5822 Set_Next_Entity
(Def_Id
, Next_Temp
);
5824 Set_Chars
(Defining_Identifier
(N
), Chars
(Def_Id
));
5825 Set_Homonym
(Defining_Identifier
(N
), Homonym
(Def_Id
));
5826 Set_Ekind
(Defining_Identifier
(N
), Ekind
(Def_Id
));
5827 Set_Sloc
(Defining_Identifier
(N
), Sloc
(Def_Id
));
5829 Set_Comes_From_Source
(Def_Id
, False);
5830 Exchange_Entities
(Defining_Identifier
(N
), Def_Id
);
5831 Set_Comes_From_Source
(Def_Id
, S_Flag
);
5838 -- Common case of explicit object initialization
5841 -- In most cases, we must check that the initial value meets any
5842 -- constraint imposed by the declared type. However, there is one
5843 -- very important exception to this rule. If the entity has an
5844 -- unconstrained nominal subtype, then it acquired its constraints
5845 -- from the expression in the first place, and not only does this
5846 -- mean that the constraint check is not needed, but an attempt to
5847 -- perform the constraint check can cause order of elaboration
5850 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
5852 -- If this is an allocator for an aggregate that has been
5853 -- allocated in place, delay checks until assignments are
5854 -- made, because the discriminants are not initialized.
5856 if Nkind
(Expr
) = N_Allocator
and then No_Initialization
(Expr
)
5860 -- Otherwise apply a constraint check now if no prev error
5862 elsif Nkind
(Expr
) /= N_Error
then
5863 Apply_Constraint_Check
(Expr
, Typ
);
5865 -- Deal with possible range check
5867 if Do_Range_Check
(Expr
) then
5869 -- If assignment checks are suppressed, turn off flag
5871 if Suppress_Assignment_Checks
(N
) then
5872 Set_Do_Range_Check
(Expr
, False);
5874 -- Otherwise generate the range check
5877 Generate_Range_Check
5878 (Expr
, Typ
, CE_Range_Check_Failed
);
5884 -- If the type is controlled and not inherently limited, then
5885 -- the target is adjusted after the copy and attached to the
5886 -- finalization list. However, no adjustment is done in the case
5887 -- where the object was initialized by a call to a function whose
5888 -- result is built in place, since no copy occurred. (Eventually
5889 -- we plan to support in-place function results for some cases
5890 -- of nonlimited types. ???) Similarly, no adjustment is required
5891 -- if we are going to rewrite the object declaration into a
5892 -- renaming declaration.
5894 if Needs_Finalization
(Typ
)
5895 and then not Is_Limited_View
(Typ
)
5896 and then not Rewrite_As_Renaming
5898 Insert_Action_After
(Init_After
,
5900 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
5904 -- For tagged types, when an init value is given, the tag has to
5905 -- be re-initialized separately in order to avoid the propagation
5906 -- of a wrong tag coming from a view conversion unless the type
5907 -- is class wide (in this case the tag comes from the init value).
5908 -- Suppress the tag assignment when VM_Target because VM tags are
5909 -- represented implicitly in objects. Ditto for types that are
5910 -- CPP_CLASS, and for initializations that are aggregates, because
5911 -- they have to have the right tag.
5913 -- The re-assignment of the tag has to be done even if the object
5914 -- is a constant. The assignment must be analyzed after the
5915 -- declaration. If an address clause follows, this is handled as
5916 -- part of the freeze actions for the object, otherwise insert
5917 -- tag assignment here.
5919 Tag_Assign
:= Make_Tag_Assignment
(N
);
5921 if Present
(Tag_Assign
) then
5922 if Present
(Following_Address_Clause
(N
)) then
5923 Ensure_Freeze_Node
(Def_Id
);
5926 Insert_Action_After
(Init_After
, Tag_Assign
);
5929 -- Handle C++ constructor calls. Note that we do not check that
5930 -- Typ is a tagged type since the equivalent Ada type of a C++
5931 -- class that has no virtual methods is an untagged limited
5934 elsif Is_CPP_Constructor_Call
(Expr
) then
5936 -- The call to the initialization procedure does NOT freeze the
5937 -- object being initialized.
5939 Id_Ref
:= New_Occurrence_Of
(Def_Id
, Loc
);
5940 Set_Must_Not_Freeze
(Id_Ref
);
5941 Set_Assignment_OK
(Id_Ref
);
5943 Insert_Actions_After
(Init_After
,
5944 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
5945 Constructor_Ref
=> Expr
));
5947 -- We remove here the original call to the constructor
5948 -- to avoid its management in the backend
5950 Set_Expression
(N
, Empty
);
5953 -- Handle initialization of limited tagged types
5955 elsif Is_Tagged_Type
(Typ
)
5956 and then Is_Class_Wide_Type
(Typ
)
5957 and then Is_Limited_Record
(Typ
)
5959 -- Given that the type is limited we cannot perform a copy. If
5960 -- Expr_Q is the reference to a variable we mark the variable
5961 -- as OK_To_Rename to expand this declaration into a renaming
5962 -- declaration (see bellow).
5964 if Is_Entity_Name
(Expr_Q
) then
5965 Set_OK_To_Rename
(Entity
(Expr_Q
));
5967 -- If we cannot convert the expression into a renaming we must
5968 -- consider it an internal error because the backend does not
5969 -- have support to handle it.
5972 pragma Assert
(False);
5973 raise Program_Error
;
5976 -- For discrete types, set the Is_Known_Valid flag if the
5977 -- initializing value is known to be valid. Only do this for
5978 -- source assignments, since otherwise we can end up turning
5979 -- on the known valid flag prematurely from inserted code.
5981 elsif Comes_From_Source
(N
)
5982 and then Is_Discrete_Type
(Typ
)
5983 and then Expr_Known_Valid
(Expr
)
5985 Set_Is_Known_Valid
(Def_Id
);
5987 elsif Is_Access_Type
(Typ
) then
5989 -- For access types set the Is_Known_Non_Null flag if the
5990 -- initializing value is known to be non-null. We can also set
5991 -- Can_Never_Be_Null if this is a constant.
5993 if Known_Non_Null
(Expr
) then
5994 Set_Is_Known_Non_Null
(Def_Id
, True);
5996 if Constant_Present
(N
) then
5997 Set_Can_Never_Be_Null
(Def_Id
);
6002 -- If validity checking on copies, validate initial expression.
6003 -- But skip this if declaration is for a generic type, since it
6004 -- makes no sense to validate generic types. Not clear if this
6005 -- can happen for legal programs, but it definitely can arise
6006 -- from previous instantiation errors.
6008 if Validity_Checks_On
6009 and then Validity_Check_Copies
6010 and then not Is_Generic_Type
(Etype
(Def_Id
))
6012 Ensure_Valid
(Expr
);
6013 Set_Is_Known_Valid
(Def_Id
);
6017 -- Cases where the back end cannot handle the initialization directly
6018 -- In such cases, we expand an assignment that will be appropriately
6019 -- handled by Expand_N_Assignment_Statement.
6021 -- The exclusion of the unconstrained case is wrong, but for now it
6022 -- is too much trouble ???
6024 if (Is_Possibly_Unaligned_Slice
(Expr
)
6025 or else (Is_Possibly_Unaligned_Object
(Expr
)
6026 and then not Represented_As_Scalar
(Etype
(Expr
))))
6027 and then not (Is_Array_Type
(Etype
(Expr
))
6028 and then not Is_Constrained
(Etype
(Expr
)))
6031 Stat
: constant Node_Id
:=
6032 Make_Assignment_Statement
(Loc
,
6033 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
6034 Expression
=> Relocate_Node
(Expr
));
6036 Set_Expression
(N
, Empty
);
6037 Set_No_Initialization
(N
);
6038 Set_Assignment_OK
(Name
(Stat
));
6039 Set_No_Ctrl_Actions
(Stat
);
6040 Insert_After_And_Analyze
(Init_After
, Stat
);
6044 -- Final transformation, if the initializing expression is an entity
6045 -- for a variable with OK_To_Rename set, then we transform:
6051 -- X : typ renames expr
6053 -- provided that X is not aliased. The aliased case has to be
6054 -- excluded in general because Expr will not be aliased in general.
6056 if Rewrite_As_Renaming
then
6058 Make_Object_Renaming_Declaration
(Loc
,
6059 Defining_Identifier
=> Defining_Identifier
(N
),
6060 Subtype_Mark
=> Obj_Def
,
6063 -- We do not analyze this renaming declaration, because all its
6064 -- components have already been analyzed, and if we were to go
6065 -- ahead and analyze it, we would in effect be trying to generate
6066 -- another declaration of X, which won't do.
6068 Set_Renamed_Object
(Defining_Identifier
(N
), Expr_Q
);
6071 -- We do need to deal with debug issues for this renaming
6073 -- First, if entity comes from source, then mark it as needing
6074 -- debug information, even though it is defined by a generated
6075 -- renaming that does not come from source.
6077 if Comes_From_Source
(Defining_Identifier
(N
)) then
6078 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
6081 -- Now call the routine to generate debug info for the renaming
6084 Decl
: constant Node_Id
:= Debug_Renaming_Declaration
(N
);
6086 if Present
(Decl
) then
6087 Insert_Action
(N
, Decl
);
6093 if Nkind
(N
) = N_Object_Declaration
6094 and then Nkind
(Obj_Def
) = N_Access_Definition
6095 and then not Is_Local_Anonymous_Access
(Etype
(Def_Id
))
6097 -- An Ada 2012 stand-alone object of an anonymous access type
6100 Loc
: constant Source_Ptr
:= Sloc
(N
);
6102 Level
: constant Entity_Id
:=
6103 Make_Defining_Identifier
(Sloc
(N
),
6105 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
6107 Level_Expr
: Node_Id
;
6108 Level_Decl
: Node_Id
;
6111 Set_Ekind
(Level
, Ekind
(Def_Id
));
6112 Set_Etype
(Level
, Standard_Natural
);
6113 Set_Scope
(Level
, Scope
(Def_Id
));
6117 -- Set accessibility level of null
6120 Make_Integer_Literal
(Loc
, Scope_Depth
(Standard_Standard
));
6123 Level_Expr
:= Dynamic_Accessibility_Level
(Expr
);
6127 Make_Object_Declaration
(Loc
,
6128 Defining_Identifier
=> Level
,
6129 Object_Definition
=>
6130 New_Occurrence_Of
(Standard_Natural
, Loc
),
6131 Expression
=> Level_Expr
,
6132 Constant_Present
=> Constant_Present
(N
),
6133 Has_Init_Expression
=> True);
6135 Insert_Action_After
(Init_After
, Level_Decl
);
6137 Set_Extra_Accessibility
(Def_Id
, Level
);
6141 -- At this point the object is fully initialized by either invoking the
6142 -- related type init proc, routine [Deep_]Initialize or performing in-
6143 -- place assingments for an array object. If the related type is subject
6144 -- to pragma Default_Initial_Condition, add a runtime check to verify
6145 -- the assumption of the pragma. Generate:
6147 -- <Base_Typ>Default_Init_Cond (<Base_Typ> (Def_Id));
6149 -- Note that the check is generated for source objects only
6151 if Comes_From_Source
(Def_Id
)
6152 and then (Has_Default_Init_Cond
(Base_Typ
)
6154 Has_Inherited_Default_Init_Cond
(Base_Typ
))
6157 DIC_Call
: constant Node_Id
:=
6158 Build_Default_Init_Cond_Call
(Loc
, Def_Id
, Base_Typ
);
6160 if Present
(Next_N
) then
6161 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
6163 -- The object declaration is the last node in a declarative or a
6167 Append_To
(List_Containing
(N
), DIC_Call
);
6173 -- Exception on library entity not available
6176 when RE_Not_Available
=>
6178 end Expand_N_Object_Declaration
;
6180 ---------------------------------
6181 -- Expand_N_Subtype_Indication --
6182 ---------------------------------
6184 -- Add a check on the range of the subtype. The static case is partially
6185 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
6186 -- to check here for the static case in order to avoid generating
6187 -- extraneous expanded code. Also deal with validity checking.
6189 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
6190 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6191 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
6194 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
6195 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
6198 if Nkind_In
(Parent
(N
), N_Constrained_Array_Definition
, N_Slice
) then
6199 Apply_Range_Check
(Ran
, Typ
);
6201 end Expand_N_Subtype_Indication
;
6203 ---------------------------
6204 -- Expand_N_Variant_Part --
6205 ---------------------------
6207 -- Note: this procedure no longer has any effect. It used to be that we
6208 -- would replace the choices in the last variant by a when others, and
6209 -- also expanded static predicates in variant choices here, but both of
6210 -- those activities were being done too early, since we can't check the
6211 -- choices until the statically predicated subtypes are frozen, which can
6212 -- happen as late as the free point of the record, and we can't change the
6213 -- last choice to an others before checking the choices, which is now done
6214 -- at the freeze point of the record.
6216 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
6219 end Expand_N_Variant_Part
;
6221 ---------------------------------
6222 -- Expand_Previous_Access_Type --
6223 ---------------------------------
6225 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
6226 Ptr_Typ
: Entity_Id
;
6229 -- Find all access types in the current scope whose designated type is
6230 -- Def_Id and build master renamings for them.
6232 Ptr_Typ
:= First_Entity
(Current_Scope
);
6233 while Present
(Ptr_Typ
) loop
6234 if Is_Access_Type
(Ptr_Typ
)
6235 and then Designated_Type
(Ptr_Typ
) = Def_Id
6236 and then No
(Master_Id
(Ptr_Typ
))
6238 -- Ensure that the designated type has a master
6240 Build_Master_Entity
(Def_Id
);
6242 -- Private and incomplete types complicate the insertion of master
6243 -- renamings because the access type may precede the full view of
6244 -- the designated type. For this reason, the master renamings are
6245 -- inserted relative to the designated type.
6247 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
6250 Next_Entity
(Ptr_Typ
);
6252 end Expand_Previous_Access_Type
;
6254 ------------------------
6255 -- Expand_Tagged_Root --
6256 ------------------------
6258 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
6259 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
6260 Comp_List
: Node_Id
;
6261 Comp_Decl
: Node_Id
;
6262 Sloc_N
: Source_Ptr
;
6265 if Null_Present
(Def
) then
6266 Set_Component_List
(Def
,
6267 Make_Component_List
(Sloc
(Def
),
6268 Component_Items
=> Empty_List
,
6269 Variant_Part
=> Empty
,
6270 Null_Present
=> True));
6273 Comp_List
:= Component_List
(Def
);
6275 if Null_Present
(Comp_List
)
6276 or else Is_Empty_List
(Component_Items
(Comp_List
))
6278 Sloc_N
:= Sloc
(Comp_List
);
6280 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
6284 Make_Component_Declaration
(Sloc_N
,
6285 Defining_Identifier
=> First_Tag_Component
(T
),
6286 Component_Definition
=>
6287 Make_Component_Definition
(Sloc_N
,
6288 Aliased_Present
=> False,
6289 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
6291 if Null_Present
(Comp_List
)
6292 or else Is_Empty_List
(Component_Items
(Comp_List
))
6294 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
6295 Set_Null_Present
(Comp_List
, False);
6298 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
6301 -- We don't Analyze the whole expansion because the tag component has
6302 -- already been analyzed previously. Here we just insure that the tree
6303 -- is coherent with the semantic decoration
6305 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
6308 when RE_Not_Available
=>
6310 end Expand_Tagged_Root
;
6312 ----------------------
6313 -- Clean_Task_Names --
6314 ----------------------
6316 procedure Clean_Task_Names
6318 Proc_Id
: Entity_Id
)
6322 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
6323 and then not Global_Discard_Names
6324 and then Tagged_Type_Expansion
6326 Set_Uses_Sec_Stack
(Proc_Id
);
6328 end Clean_Task_Names
;
6330 ------------------------------
6331 -- Expand_Freeze_Array_Type --
6332 ------------------------------
6334 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
6335 Typ
: constant Entity_Id
:= Entity
(N
);
6336 Base
: constant Entity_Id
:= Base_Type
(Typ
);
6337 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
6341 if not Is_Bit_Packed_Array
(Typ
) then
6343 -- If the component contains tasks, so does the array type. This may
6344 -- not be indicated in the array type because the component may have
6345 -- been a private type at the point of definition. Same if component
6346 -- type is controlled or contains protected objects.
6348 Set_Has_Task
(Base
, Has_Task
(Comp_Typ
));
6349 Set_Has_Protected
(Base
, Has_Protected
(Comp_Typ
));
6350 Set_Has_Controlled_Component
6351 (Base
, Has_Controlled_Component
6354 Is_Controlled
(Comp_Typ
));
6356 if No
(Init_Proc
(Base
)) then
6358 -- If this is an anonymous array created for a declaration with
6359 -- an initial value, its init_proc will never be called. The
6360 -- initial value itself may have been expanded into assignments,
6361 -- in which case the object declaration is carries the
6362 -- No_Initialization flag.
6365 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
6366 N_Object_Declaration
6368 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
6369 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
6373 -- We do not need an init proc for string or wide [wide] string,
6374 -- since the only time these need initialization in normalize or
6375 -- initialize scalars mode, and these types are treated specially
6376 -- and do not need initialization procedures.
6378 elsif Is_Standard_String_Type
(Base
) then
6381 -- Otherwise we have to build an init proc for the subtype
6384 Build_Array_Init_Proc
(Base
, N
);
6389 if Has_Controlled_Component
(Base
) then
6390 Build_Controlling_Procs
(Base
);
6392 if not Is_Limited_Type
(Comp_Typ
)
6393 and then Number_Dimensions
(Typ
) = 1
6395 Build_Slice_Assignment
(Typ
);
6399 -- Create a finalization master to service the anonymous access
6400 -- components of the array.
6402 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
6403 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
6405 -- The finalization master is inserted before the declaration
6406 -- of the array type. The only exception to this is when the
6407 -- array type is an itype, in which case the master appears
6408 -- before the related context.
6410 if Is_Itype
(Typ
) then
6411 Ins_Node
:= Associated_Node_For_Itype
(Typ
);
6413 Ins_Node
:= Parent
(Typ
);
6416 Build_Finalization_Master
6418 For_Anonymous
=> True,
6419 Context_Scope
=> Scope
(Typ
),
6420 Insertion_Node
=> Ins_Node
);
6424 -- For packed case, default initialization, except if the component type
6425 -- is itself a packed structure with an initialization procedure, or
6426 -- initialize/normalize scalars active, and we have a base type, or the
6427 -- type is public, because in that case a client might specify
6428 -- Normalize_Scalars and there better be a public Init_Proc for it.
6430 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
6431 and then No
(Base_Init_Proc
(Base
)))
6432 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
6433 or else Is_Public
(Typ
)
6435 Build_Array_Init_Proc
(Base
, N
);
6438 if Has_Invariants
(Component_Type
(Base
))
6440 and then In_Open_Scopes
(Scope
(Component_Type
(Base
)))
6442 -- Generate component invariant checking procedure. This is only
6443 -- relevant if the array type is within the scope of the component
6444 -- type. Otherwise an array object can only be built using the public
6445 -- subprograms for the component type, and calls to those will have
6446 -- invariant checks. The invariant procedure is only generated for
6447 -- a base type, not a subtype.
6449 Insert_Component_Invariant_Checks
6450 (N
, Base
, Build_Array_Invariant_Proc
(Base
, N
));
6452 end Expand_Freeze_Array_Type
;
6454 -----------------------------------
6455 -- Expand_Freeze_Class_Wide_Type --
6456 -----------------------------------
6458 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
6459 Typ
: constant Entity_Id
:= Entity
(N
);
6460 Root
: constant Entity_Id
:= Root_Type
(Typ
);
6462 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
6463 -- Given a type, determine whether it is derived from a C or C++ root
6465 ---------------------
6466 -- Is_C_Derivation --
6467 ---------------------
6469 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
6476 or else Convention
(T
) = Convention_C
6477 or else Convention
(T
) = Convention_CPP
6482 exit when T
= Etype
(T
);
6488 end Is_C_Derivation
;
6490 -- Start of processing for Expand_Freeze_Class_Wide_Type
6493 -- Certain run-time configurations and targets do not provide support
6494 -- for controlled types.
6496 if Restriction_Active
(No_Finalization
) then
6499 -- Do not create TSS routine Finalize_Address when dispatching calls are
6500 -- disabled since the core of the routine is a dispatching call.
6502 elsif Restriction_Active
(No_Dispatching_Calls
) then
6505 -- Do not create TSS routine Finalize_Address for concurrent class-wide
6506 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
6507 -- non-Ada side will handle their destruction.
6509 elsif Is_Concurrent_Type
(Root
)
6510 or else Is_C_Derivation
(Root
)
6511 or else Convention
(Typ
) = Convention_CIL
6512 or else Convention
(Typ
) = Convention_CPP
6513 or else Convention
(Typ
) = Convention_Java
6517 -- Do not create TSS routine Finalize_Address for .NET/JVM because these
6518 -- targets do not support address arithmetic and unchecked conversions.
6520 elsif VM_Target
/= No_VM
then
6523 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
6524 -- mode since the routine contains an Unchecked_Conversion.
6526 elsif CodePeer_Mode
then
6530 -- Create the body of TSS primitive Finalize_Address. This automatically
6531 -- sets the TSS entry for the class-wide type.
6533 Make_Finalize_Address_Body
(Typ
);
6534 end Expand_Freeze_Class_Wide_Type
;
6536 ------------------------------------
6537 -- Expand_Freeze_Enumeration_Type --
6538 ------------------------------------
6540 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
6541 Typ
: constant Entity_Id
:= Entity
(N
);
6542 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6549 Is_Contiguous
: Boolean;
6554 pragma Warnings
(Off
, Func
);
6557 -- Various optimizations possible if given representation is contiguous
6559 Is_Contiguous
:= True;
6561 Ent
:= First_Literal
(Typ
);
6562 Last_Repval
:= Enumeration_Rep
(Ent
);
6565 while Present
(Ent
) loop
6566 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
6567 Is_Contiguous
:= False;
6570 Last_Repval
:= Enumeration_Rep
(Ent
);
6576 if Is_Contiguous
then
6577 Set_Has_Contiguous_Rep
(Typ
);
6578 Ent
:= First_Literal
(Typ
);
6580 Lst
:= New_List
(New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
6583 -- Build list of literal references
6588 Ent
:= First_Literal
(Typ
);
6589 while Present
(Ent
) loop
6590 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
6596 -- Now build an array declaration
6598 -- typA : array (Natural range 0 .. num - 1) of ctype :=
6599 -- (v, v, v, v, v, ....)
6601 -- where ctype is the corresponding integer type. If the representation
6602 -- is contiguous, we only keep the first literal, which provides the
6603 -- offset for Pos_To_Rep computations.
6606 Make_Defining_Identifier
(Loc
,
6607 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
6609 Append_Freeze_Action
(Typ
,
6610 Make_Object_Declaration
(Loc
,
6611 Defining_Identifier
=> Arr
,
6612 Constant_Present
=> True,
6614 Object_Definition
=>
6615 Make_Constrained_Array_Definition
(Loc
,
6616 Discrete_Subtype_Definitions
=> New_List
(
6617 Make_Subtype_Indication
(Loc
,
6618 Subtype_Mark
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
6620 Make_Range_Constraint
(Loc
,
6624 Make_Integer_Literal
(Loc
, 0),
6626 Make_Integer_Literal
(Loc
, Num
- 1))))),
6628 Component_Definition
=>
6629 Make_Component_Definition
(Loc
,
6630 Aliased_Present
=> False,
6631 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
6634 Make_Aggregate
(Loc
,
6635 Expressions
=> Lst
)));
6637 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
6639 -- Now we build the function that converts representation values to
6640 -- position values. This function has the form:
6642 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
6645 -- when enum-lit'Enum_Rep => return posval;
6646 -- when enum-lit'Enum_Rep => return posval;
6649 -- [raise Constraint_Error when F "invalid data"]
6654 -- Note: the F parameter determines whether the others case (no valid
6655 -- representation) raises Constraint_Error or returns a unique value
6656 -- of minus one. The latter case is used, e.g. in 'Valid code.
6658 -- Note: the reason we use Enum_Rep values in the case here is to avoid
6659 -- the code generator making inappropriate assumptions about the range
6660 -- of the values in the case where the value is invalid. ityp is a
6661 -- signed or unsigned integer type of appropriate width.
6663 -- Note: if exceptions are not supported, then we suppress the raise
6664 -- and return -1 unconditionally (this is an erroneous program in any
6665 -- case and there is no obligation to raise Constraint_Error here). We
6666 -- also do this if pragma Restrictions (No_Exceptions) is active.
6668 -- Is this right??? What about No_Exception_Propagation???
6670 -- Representations are signed
6672 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
6674 -- The underlying type is signed. Reset the Is_Unsigned_Type
6675 -- explicitly, because it might have been inherited from
6678 Set_Is_Unsigned_Type
(Typ
, False);
6680 if Esize
(Typ
) <= Standard_Integer_Size
then
6681 Ityp
:= Standard_Integer
;
6683 Ityp
:= Universal_Integer
;
6686 -- Representations are unsigned
6689 if Esize
(Typ
) <= Standard_Integer_Size
then
6690 Ityp
:= RTE
(RE_Unsigned
);
6692 Ityp
:= RTE
(RE_Long_Long_Unsigned
);
6696 -- The body of the function is a case statement. First collect case
6697 -- alternatives, or optimize the contiguous case.
6701 -- If representation is contiguous, Pos is computed by subtracting
6702 -- the representation of the first literal.
6704 if Is_Contiguous
then
6705 Ent
:= First_Literal
(Typ
);
6707 if Enumeration_Rep
(Ent
) = Last_Repval
then
6709 -- Another special case: for a single literal, Pos is zero
6711 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
6715 Convert_To
(Standard_Integer
,
6716 Make_Op_Subtract
(Loc
,
6718 Unchecked_Convert_To
6719 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
6721 Make_Integer_Literal
(Loc
,
6722 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
6726 Make_Case_Statement_Alternative
(Loc
,
6727 Discrete_Choices
=> New_List
(
6728 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
6730 Make_Integer_Literal
(Loc
,
6731 Intval
=> Enumeration_Rep
(Ent
)),
6733 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
6735 Statements
=> New_List
(
6736 Make_Simple_Return_Statement
(Loc
,
6737 Expression
=> Pos_Expr
))));
6740 Ent
:= First_Literal
(Typ
);
6741 while Present
(Ent
) loop
6743 Make_Case_Statement_Alternative
(Loc
,
6744 Discrete_Choices
=> New_List
(
6745 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
6746 Intval
=> Enumeration_Rep
(Ent
))),
6748 Statements
=> New_List
(
6749 Make_Simple_Return_Statement
(Loc
,
6751 Make_Integer_Literal
(Loc
,
6752 Intval
=> Enumeration_Pos
(Ent
))))));
6758 -- In normal mode, add the others clause with the test
6760 if not No_Exception_Handlers_Set
then
6762 Make_Case_Statement_Alternative
(Loc
,
6763 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6764 Statements
=> New_List
(
6765 Make_Raise_Constraint_Error
(Loc
,
6766 Condition
=> Make_Identifier
(Loc
, Name_uF
),
6767 Reason
=> CE_Invalid_Data
),
6768 Make_Simple_Return_Statement
(Loc
,
6770 Make_Integer_Literal
(Loc
, -1)))));
6772 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
6773 -- active then return -1 (we cannot usefully raise Constraint_Error in
6774 -- this case). See description above for further details.
6778 Make_Case_Statement_Alternative
(Loc
,
6779 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6780 Statements
=> New_List
(
6781 Make_Simple_Return_Statement
(Loc
,
6783 Make_Integer_Literal
(Loc
, -1)))));
6786 -- Now we can build the function body
6789 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
6792 Make_Subprogram_Body
(Loc
,
6794 Make_Function_Specification
(Loc
,
6795 Defining_Unit_Name
=> Fent
,
6796 Parameter_Specifications
=> New_List
(
6797 Make_Parameter_Specification
(Loc
,
6798 Defining_Identifier
=>
6799 Make_Defining_Identifier
(Loc
, Name_uA
),
6800 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
6801 Make_Parameter_Specification
(Loc
,
6802 Defining_Identifier
=>
6803 Make_Defining_Identifier
(Loc
, Name_uF
),
6805 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
6807 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
6809 Declarations
=> Empty_List
,
6811 Handled_Statement_Sequence
=>
6812 Make_Handled_Sequence_Of_Statements
(Loc
,
6813 Statements
=> New_List
(
6814 Make_Case_Statement
(Loc
,
6816 Unchecked_Convert_To
6817 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
6818 Alternatives
=> Lst
))));
6820 Set_TSS
(Typ
, Fent
);
6822 -- Set Pure flag (it will be reset if the current context is not Pure).
6823 -- We also pretend there was a pragma Pure_Function so that for purposes
6824 -- of optimization and constant-folding, we will consider the function
6825 -- Pure even if we are not in a Pure context).
6828 Set_Has_Pragma_Pure_Function
(Fent
);
6830 -- Unless we are in -gnatD mode, where we are debugging generated code,
6831 -- this is an internal entity for which we don't need debug info.
6833 if not Debug_Generated_Code
then
6834 Set_Debug_Info_Off
(Fent
);
6838 when RE_Not_Available
=>
6840 end Expand_Freeze_Enumeration_Type
;
6842 -------------------------------
6843 -- Expand_Freeze_Record_Type --
6844 -------------------------------
6846 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
6847 Def_Id
: constant Node_Id
:= Entity
(N
);
6848 Type_Decl
: constant Node_Id
:= Parent
(Def_Id
);
6850 Comp_Typ
: Entity_Id
;
6852 Predef_List
: List_Id
;
6854 Renamed_Eq
: Node_Id
:= Empty
;
6855 -- Defining unit name for the predefined equality function in the case
6856 -- where the type has a primitive operation that is a renaming of
6857 -- predefined equality (but only if there is also an overriding
6858 -- user-defined equality function). Used to pass this entity from
6859 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
6861 Wrapper_Decl_List
: List_Id
:= No_List
;
6862 Wrapper_Body_List
: List_Id
:= No_List
;
6864 -- Start of processing for Expand_Freeze_Record_Type
6867 -- Build discriminant checking functions if not a derived type (for
6868 -- derived types that are not tagged types, always use the discriminant
6869 -- checking functions of the parent type). However, for untagged types
6870 -- the derivation may have taken place before the parent was frozen, so
6871 -- we copy explicitly the discriminant checking functions from the
6872 -- parent into the components of the derived type.
6874 if not Is_Derived_Type
(Def_Id
)
6875 or else Has_New_Non_Standard_Rep
(Def_Id
)
6876 or else Is_Tagged_Type
(Def_Id
)
6878 Build_Discr_Checking_Funcs
(Type_Decl
);
6880 elsif Is_Derived_Type
(Def_Id
)
6881 and then not Is_Tagged_Type
(Def_Id
)
6883 -- If we have a derived Unchecked_Union, we do not inherit the
6884 -- discriminant checking functions from the parent type since the
6885 -- discriminants are non existent.
6887 and then not Is_Unchecked_Union
(Def_Id
)
6888 and then Has_Discriminants
(Def_Id
)
6891 Old_Comp
: Entity_Id
;
6895 First_Component
(Base_Type
(Underlying_Type
(Etype
(Def_Id
))));
6896 Comp
:= First_Component
(Def_Id
);
6897 while Present
(Comp
) loop
6898 if Ekind
(Comp
) = E_Component
6899 and then Chars
(Comp
) = Chars
(Old_Comp
)
6901 Set_Discriminant_Checking_Func
(Comp
,
6902 Discriminant_Checking_Func
(Old_Comp
));
6905 Next_Component
(Old_Comp
);
6906 Next_Component
(Comp
);
6911 if Is_Derived_Type
(Def_Id
)
6912 and then Is_Limited_Type
(Def_Id
)
6913 and then Is_Tagged_Type
(Def_Id
)
6915 Check_Stream_Attributes
(Def_Id
);
6918 -- Update task, protected, and controlled component flags, because some
6919 -- of the component types may have been private at the point of the
6920 -- record declaration. Detect anonymous access-to-controlled components.
6924 Comp
:= First_Component
(Def_Id
);
6925 while Present
(Comp
) loop
6926 Comp_Typ
:= Etype
(Comp
);
6928 if Has_Task
(Comp_Typ
) then
6929 Set_Has_Task
(Def_Id
);
6932 if Has_Protected
(Comp_Typ
) then
6933 Set_Has_Protected
(Def_Id
);
6936 -- Do not set Has_Controlled_Component on a class-wide equivalent
6937 -- type. See Make_CW_Equivalent_Type.
6939 if not Is_Class_Wide_Equivalent_Type
(Def_Id
)
6940 and then (Has_Controlled_Component
(Comp_Typ
)
6941 or else (Chars
(Comp
) /= Name_uParent
6942 and then Is_Controlled
(Comp_Typ
)))
6944 Set_Has_Controlled_Component
(Def_Id
);
6947 -- Non-self-referential anonymous access-to-controlled component
6949 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
6950 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
6951 and then Designated_Type
(Comp_Typ
) /= Def_Id
6956 Next_Component
(Comp
);
6959 -- Handle constructors of untagged CPP_Class types
6961 if not Is_Tagged_Type
(Def_Id
) and then Is_CPP_Class
(Def_Id
) then
6962 Set_CPP_Constructors
(Def_Id
);
6965 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
6966 -- for regular tagged types as well as for Ada types deriving from a C++
6967 -- Class, but not for tagged types directly corresponding to C++ classes
6968 -- In the later case we assume that it is created in the C++ side and we
6971 if Is_Tagged_Type
(Def_Id
) then
6973 -- Add the _Tag component
6975 if Underlying_Type
(Etype
(Def_Id
)) = Def_Id
then
6976 Expand_Tagged_Root
(Def_Id
);
6979 if Is_CPP_Class
(Def_Id
) then
6980 Set_All_DT_Position
(Def_Id
);
6982 -- Create the tag entities with a minimum decoration
6984 if Tagged_Type_Expansion
then
6985 Append_Freeze_Actions
(Def_Id
, Make_Tags
(Def_Id
));
6988 Set_CPP_Constructors
(Def_Id
);
6991 if not Building_Static_DT
(Def_Id
) then
6993 -- Usually inherited primitives are not delayed but the first
6994 -- Ada extension of a CPP_Class is an exception since the
6995 -- address of the inherited subprogram has to be inserted in
6996 -- the new Ada Dispatch Table and this is a freezing action.
6998 -- Similarly, if this is an inherited operation whose parent is
6999 -- not frozen yet, it is not in the DT of the parent, and we
7000 -- generate an explicit freeze node for the inherited operation
7001 -- so it is properly inserted in the DT of the current type.
7008 Elmt
:= First_Elmt
(Primitive_Operations
(Def_Id
));
7009 while Present
(Elmt
) loop
7010 Subp
:= Node
(Elmt
);
7012 if Present
(Alias
(Subp
)) then
7013 if Is_CPP_Class
(Etype
(Def_Id
)) then
7014 Set_Has_Delayed_Freeze
(Subp
);
7016 elsif Has_Delayed_Freeze
(Alias
(Subp
))
7017 and then not Is_Frozen
(Alias
(Subp
))
7019 Set_Is_Frozen
(Subp
, False);
7020 Set_Has_Delayed_Freeze
(Subp
);
7029 -- Unfreeze momentarily the type to add the predefined primitives
7030 -- operations. The reason we unfreeze is so that these predefined
7031 -- operations will indeed end up as primitive operations (which
7032 -- must be before the freeze point).
7034 Set_Is_Frozen
(Def_Id
, False);
7036 -- Do not add the spec of predefined primitives in case of
7037 -- CPP tagged type derivations that have convention CPP.
7039 if Is_CPP_Class
(Root_Type
(Def_Id
))
7040 and then Convention
(Def_Id
) = Convention_CPP
7044 -- Do not add the spec of predefined primitives in case of
7045 -- CIL and Java tagged types
7047 elsif Convention
(Def_Id
) = Convention_CIL
7048 or else Convention
(Def_Id
) = Convention_Java
7052 -- Do not add the spec of the predefined primitives if we are
7053 -- compiling under restriction No_Dispatching_Calls.
7055 elsif not Restriction_Active
(No_Dispatching_Calls
) then
7056 Make_Predefined_Primitive_Specs
7057 (Def_Id
, Predef_List
, Renamed_Eq
);
7058 Insert_List_Before_And_Analyze
(N
, Predef_List
);
7061 -- Ada 2005 (AI-391): For a nonabstract null extension, create
7062 -- wrapper functions for each nonoverridden inherited function
7063 -- with a controlling result of the type. The wrapper for such
7064 -- a function returns an extension aggregate that invokes the
7067 if Ada_Version
>= Ada_2005
7068 and then not Is_Abstract_Type
(Def_Id
)
7069 and then Is_Null_Extension
(Def_Id
)
7071 Make_Controlling_Function_Wrappers
7072 (Def_Id
, Wrapper_Decl_List
, Wrapper_Body_List
);
7073 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
7076 -- Ada 2005 (AI-251): For a nonabstract type extension, build
7077 -- null procedure declarations for each set of homographic null
7078 -- procedures that are inherited from interface types but not
7079 -- overridden. This is done to ensure that the dispatch table
7080 -- entry associated with such null primitives are properly filled.
7082 if Ada_Version
>= Ada_2005
7083 and then Etype
(Def_Id
) /= Def_Id
7084 and then not Is_Abstract_Type
(Def_Id
)
7085 and then Has_Interfaces
(Def_Id
)
7087 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Def_Id
));
7090 Set_Is_Frozen
(Def_Id
);
7091 if not Is_Derived_Type
(Def_Id
)
7092 or else Is_Tagged_Type
(Etype
(Def_Id
))
7094 Set_All_DT_Position
(Def_Id
);
7096 -- If this is a type derived from an untagged private type whose
7097 -- full view is tagged, the type is marked tagged for layout
7098 -- reasons, but it has no dispatch table.
7100 elsif Is_Derived_Type
(Def_Id
)
7101 and then Is_Private_Type
(Etype
(Def_Id
))
7102 and then not Is_Tagged_Type
(Etype
(Def_Id
))
7107 -- Create and decorate the tags. Suppress their creation when
7108 -- VM_Target because the dispatching mechanism is handled
7109 -- internally by the VMs.
7111 if Tagged_Type_Expansion
then
7112 Append_Freeze_Actions
(Def_Id
, Make_Tags
(Def_Id
));
7114 -- Generate dispatch table of locally defined tagged type.
7115 -- Dispatch tables of library level tagged types are built
7116 -- later (see Analyze_Declarations).
7118 if not Building_Static_DT
(Def_Id
) then
7119 Append_Freeze_Actions
(Def_Id
, Make_DT
(Def_Id
));
7122 elsif VM_Target
/= No_VM
then
7123 Append_Freeze_Actions
(Def_Id
, Make_VM_TSD
(Def_Id
));
7126 -- If the type has unknown discriminants, propagate dispatching
7127 -- information to its underlying record view, which does not get
7128 -- its own dispatch table.
7130 if Is_Derived_Type
(Def_Id
)
7131 and then Has_Unknown_Discriminants
(Def_Id
)
7132 and then Present
(Underlying_Record_View
(Def_Id
))
7135 Rep
: constant Entity_Id
:= Underlying_Record_View
(Def_Id
);
7137 Set_Access_Disp_Table
7138 (Rep
, Access_Disp_Table
(Def_Id
));
7139 Set_Dispatch_Table_Wrappers
7140 (Rep
, Dispatch_Table_Wrappers
(Def_Id
));
7141 Set_Direct_Primitive_Operations
7142 (Rep
, Direct_Primitive_Operations
(Def_Id
));
7146 -- Make sure that the primitives Initialize, Adjust and Finalize
7147 -- are Frozen before other TSS subprograms. We don't want them
7150 if Is_Controlled
(Def_Id
) then
7151 if not Is_Limited_Type
(Def_Id
) then
7152 Append_Freeze_Actions
(Def_Id
,
7154 (Find_Prim_Op
(Def_Id
, Name_Adjust
), Def_Id
));
7157 Append_Freeze_Actions
(Def_Id
,
7159 (Find_Prim_Op
(Def_Id
, Name_Initialize
), Def_Id
));
7161 Append_Freeze_Actions
(Def_Id
,
7163 (Find_Prim_Op
(Def_Id
, Name_Finalize
), Def_Id
));
7166 -- Freeze rest of primitive operations. There is no need to handle
7167 -- the predefined primitives if we are compiling under restriction
7168 -- No_Dispatching_Calls.
7170 if not Restriction_Active
(No_Dispatching_Calls
) then
7171 Append_Freeze_Actions
7172 (Def_Id
, Predefined_Primitive_Freeze
(Def_Id
));
7176 -- In the untagged case, ever since Ada 83 an equality function must
7177 -- be provided for variant records that are not unchecked unions.
7178 -- In Ada 2012 the equality function composes, and thus must be built
7179 -- explicitly just as for tagged records.
7181 elsif Has_Discriminants
(Def_Id
)
7182 and then not Is_Limited_Type
(Def_Id
)
7185 Comps
: constant Node_Id
:=
7186 Component_List
(Type_Definition
(Type_Decl
));
7189 and then Present
(Variant_Part
(Comps
))
7191 Build_Variant_Record_Equality
(Def_Id
);
7195 -- Otherwise create primitive equality operation (AI05-0123)
7197 -- This is done unconditionally to ensure that tools can be linked
7198 -- properly with user programs compiled with older language versions.
7199 -- In addition, this is needed because "=" composes for bounded strings
7200 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
7202 elsif Comes_From_Source
(Def_Id
)
7203 and then Convention
(Def_Id
) = Convention_Ada
7204 and then not Is_Limited_Type
(Def_Id
)
7206 Build_Untagged_Equality
(Def_Id
);
7209 -- Before building the record initialization procedure, if we are
7210 -- dealing with a concurrent record value type, then we must go through
7211 -- the discriminants, exchanging discriminals between the concurrent
7212 -- type and the concurrent record value type. See the section "Handling
7213 -- of Discriminants" in the Einfo spec for details.
7215 if Is_Concurrent_Record_Type
(Def_Id
)
7216 and then Has_Discriminants
(Def_Id
)
7219 Ctyp
: constant Entity_Id
:=
7220 Corresponding_Concurrent_Type
(Def_Id
);
7221 Conc_Discr
: Entity_Id
;
7222 Rec_Discr
: Entity_Id
;
7226 Conc_Discr
:= First_Discriminant
(Ctyp
);
7227 Rec_Discr
:= First_Discriminant
(Def_Id
);
7228 while Present
(Conc_Discr
) loop
7229 Temp
:= Discriminal
(Conc_Discr
);
7230 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
7231 Set_Discriminal
(Rec_Discr
, Temp
);
7233 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
7234 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
7236 Next_Discriminant
(Conc_Discr
);
7237 Next_Discriminant
(Rec_Discr
);
7242 if Has_Controlled_Component
(Def_Id
) then
7243 Build_Controlling_Procs
(Def_Id
);
7246 Adjust_Discriminants
(Def_Id
);
7248 if Tagged_Type_Expansion
or else not Is_Interface
(Def_Id
) then
7250 -- Do not need init for interfaces on e.g. CIL since they're
7251 -- abstract. Helps operation of peverify (the PE Verify tool).
7253 Build_Record_Init_Proc
(Type_Decl
, Def_Id
);
7256 -- For tagged type that are not interfaces, build bodies of primitive
7257 -- operations. Note: do this after building the record initialization
7258 -- procedure, since the primitive operations may need the initialization
7259 -- routine. There is no need to add predefined primitives of interfaces
7260 -- because all their predefined primitives are abstract.
7262 if Is_Tagged_Type
(Def_Id
) and then not Is_Interface
(Def_Id
) then
7264 -- Do not add the body of predefined primitives in case of CPP tagged
7265 -- type derivations that have convention CPP.
7267 if Is_CPP_Class
(Root_Type
(Def_Id
))
7268 and then Convention
(Def_Id
) = Convention_CPP
7272 -- Do not add the body of predefined primitives in case of CIL and
7273 -- Java tagged types.
7275 elsif Convention
(Def_Id
) = Convention_CIL
7276 or else Convention
(Def_Id
) = Convention_Java
7280 -- Do not add the body of the predefined primitives if we are
7281 -- compiling under restriction No_Dispatching_Calls or if we are
7282 -- compiling a CPP tagged type.
7284 elsif not Restriction_Active
(No_Dispatching_Calls
) then
7286 -- Create the body of TSS primitive Finalize_Address. This must
7287 -- be done before the bodies of all predefined primitives are
7288 -- created. If Def_Id is limited, Stream_Input and Stream_Read
7289 -- may produce build-in-place allocations and for those the
7290 -- expander needs Finalize_Address.
7292 Make_Finalize_Address_Body
(Def_Id
);
7293 Predef_List
:= Predefined_Primitive_Bodies
(Def_Id
, Renamed_Eq
);
7294 Append_Freeze_Actions
(Def_Id
, Predef_List
);
7297 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
7298 -- inherited functions, then add their bodies to the freeze actions.
7300 if Present
(Wrapper_Body_List
) then
7301 Append_Freeze_Actions
(Def_Id
, Wrapper_Body_List
);
7304 -- Create extra formals for the primitive operations of the type.
7305 -- This must be done before analyzing the body of the initialization
7306 -- procedure, because a self-referential type might call one of these
7307 -- primitives in the body of the init_proc itself.
7314 Elmt
:= First_Elmt
(Primitive_Operations
(Def_Id
));
7315 while Present
(Elmt
) loop
7316 Subp
:= Node
(Elmt
);
7317 if not Has_Foreign_Convention
(Subp
)
7318 and then not Is_Predefined_Dispatching_Operation
(Subp
)
7320 Create_Extra_Formals
(Subp
);
7328 -- Create a heterogeneous finalization master to service the anonymous
7329 -- access-to-controlled components of the record type.
7333 Encl_Scope
: constant Entity_Id
:= Scope
(Def_Id
);
7334 Ins_Node
: constant Node_Id
:= Parent
(Def_Id
);
7335 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7336 Fin_Mas_Id
: Entity_Id
;
7338 Attributes_Set
: Boolean := False;
7339 Master_Built
: Boolean := False;
7340 -- Two flags which control the creation and initialization of a
7341 -- common heterogeneous master.
7344 Comp
:= First_Component
(Def_Id
);
7345 while Present
(Comp
) loop
7346 Comp_Typ
:= Etype
(Comp
);
7348 -- A non-self-referential anonymous access-to-controlled
7351 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
7352 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
7353 and then Designated_Type
(Comp_Typ
) /= Def_Id
7355 if VM_Target
= No_VM
then
7357 -- Build a homogeneous master for the first anonymous
7358 -- access-to-controlled component. This master may be
7359 -- converted into a heterogeneous collection if more
7360 -- components are to follow.
7362 if not Master_Built
then
7363 Master_Built
:= True;
7365 -- All anonymous access-to-controlled types allocate
7366 -- on the global pool. Note that the finalization
7367 -- master and the associated storage pool must be set
7368 -- on the root type (both are "root type only").
7370 Set_Associated_Storage_Pool
7371 (Root_Type
(Comp_Typ
), RTE
(RE_Global_Pool_Object
));
7373 Build_Finalization_Master
7374 (Typ
=> Root_Type
(Comp_Typ
),
7375 For_Anonymous
=> True,
7376 Context_Scope
=> Encl_Scope
,
7377 Insertion_Node
=> Ins_Node
);
7379 Fin_Mas_Id
:= Finalization_Master
(Comp_Typ
);
7381 -- Subsequent anonymous access-to-controlled components
7382 -- reuse the available master.
7385 -- All anonymous access-to-controlled types allocate
7386 -- on the global pool. Note that both the finalization
7387 -- master and the associated storage pool must be set
7388 -- on the root type (both are "root type only").
7390 Set_Associated_Storage_Pool
7391 (Root_Type
(Comp_Typ
), RTE
(RE_Global_Pool_Object
));
7393 -- Shared the master among multiple components
7395 Set_Finalization_Master
7396 (Root_Type
(Comp_Typ
), Fin_Mas_Id
);
7398 -- Convert the master into a heterogeneous collection.
7400 -- Set_Is_Heterogeneous (<Fin_Mas_Id>);
7402 if not Attributes_Set
then
7403 Attributes_Set
:= True;
7405 Insert_Action
(Ins_Node
,
7406 Make_Procedure_Call_Statement
(Loc
,
7409 (RTE
(RE_Set_Is_Heterogeneous
), Loc
),
7410 Parameter_Associations
=> New_List
(
7411 New_Occurrence_Of
(Fin_Mas_Id
, Loc
))));
7415 -- Since .NET/JVM targets do not support heterogeneous
7416 -- masters, each component must have its own master.
7419 Build_Finalization_Master
7421 For_Anonymous
=> True,
7422 Context_Scope
=> Encl_Scope
,
7423 Insertion_Node
=> Ins_Node
);
7427 Next_Component
(Comp
);
7432 -- Check whether individual components have a defined invariant, and add
7433 -- the corresponding component invariant checks.
7435 -- Do not create an invariant procedure for some internally generated
7436 -- subtypes, in particular those created for objects of a class-wide
7437 -- type. Such types may have components to which invariant apply, but
7438 -- the corresponding checks will be applied when an object of the parent
7439 -- type is constructed.
7441 -- Such objects will show up in a class-wide postcondition, and the
7442 -- invariant will be checked, if necessary, upon return from the
7443 -- enclosing subprogram.
7445 if not Is_Class_Wide_Equivalent_Type
(Def_Id
) then
7446 Insert_Component_Invariant_Checks
7447 (N
, Def_Id
, Build_Record_Invariant_Proc
(Def_Id
, N
));
7449 end Expand_Freeze_Record_Type
;
7451 ------------------------------
7452 -- Freeze_Stream_Operations --
7453 ------------------------------
7455 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
7456 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
7461 Stream_Op
: Entity_Id
;
7464 -- Primitive operations of tagged types are frozen when the dispatch
7465 -- table is constructed.
7467 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
7471 for J
in Names
'Range loop
7472 Stream_Op
:= TSS
(Typ
, Names
(J
));
7474 if Present
(Stream_Op
)
7475 and then Is_Subprogram
(Stream_Op
)
7476 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
7477 N_Subprogram_Declaration
7478 and then not Is_Frozen
(Stream_Op
)
7480 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
7483 end Freeze_Stream_Operations
;
7489 -- Full type declarations are expanded at the point at which the type is
7490 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
7491 -- declarations generated by the freezing (e.g. the procedure generated
7492 -- for initialization) are chained in the Actions field list of the freeze
7493 -- node using Append_Freeze_Actions.
7495 function Freeze_Type
(N
: Node_Id
) return Boolean is
7496 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
7497 -- Save the current Ghost mode in effect in case the type being frozen
7498 -- sets a different mode.
7500 procedure Process_RACW_Types
(Typ
: Entity_Id
);
7501 -- Validate and generate stubs for all RACW types associated with type
7504 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
);
7505 -- Associate type Typ's Finalize_Address primitive with the finalization
7506 -- masters of pending access-to-Typ types.
7508 procedure Restore_Globals
;
7509 -- Restore the values of all saved global variables
7511 ------------------------
7512 -- Process_RACW_Types --
7513 ------------------------
7515 procedure Process_RACW_Types
(Typ
: Entity_Id
) is
7516 List
: constant Elist_Id
:= Access_Types_To_Process
(N
);
7518 Seen
: Boolean := False;
7521 if Present
(List
) then
7522 E
:= First_Elmt
(List
);
7523 while Present
(E
) loop
7524 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
7525 Validate_RACW_Primitives
(Node
(E
));
7533 -- If there are RACWs designating this type, make stubs now
7536 Remote_Types_Tagged_Full_View_Encountered
(Typ
);
7538 end Process_RACW_Types
;
7540 ----------------------------------
7541 -- Process_Pending_Access_Types --
7542 ----------------------------------
7544 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
) is
7548 -- Finalize_Address is not generated in CodePeer mode because the
7549 -- body contains address arithmetic. This processing is disabled.
7551 if CodePeer_Mode
then
7554 -- Certain itypes are generated for contexts that cannot allocate
7555 -- objects and should not set primitive Finalize_Address.
7557 elsif Is_Itype
(Typ
)
7558 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
7559 N_Explicit_Dereference
7563 -- When an access type is declared after the incomplete view of a
7564 -- Taft-amendment type, the access type is considered pending in
7565 -- case the full view of the Taft-amendment type is controlled. If
7566 -- this is indeed the case, associate the Finalize_Address routine
7567 -- of the full view with the finalization masters of all pending
7568 -- access types. This scenario applies to anonymous access types as
7571 elsif Needs_Finalization
(Typ
)
7572 and then Present
(Pending_Access_Types
(Typ
))
7574 E
:= First_Elmt
(Pending_Access_Types
(Typ
));
7575 while Present
(E
) loop
7578 -- Set_Finalize_Address
7579 -- (Ptr_Typ, <Typ>FD'Unrestricted_Access);
7581 Append_Freeze_Action
(Typ
,
7582 Make_Set_Finalize_Address_Call
7584 Ptr_Typ
=> Node
(E
)));
7589 end Process_Pending_Access_Types
;
7591 ---------------------
7592 -- Restore_Globals --
7593 ---------------------
7595 procedure Restore_Globals
is
7598 end Restore_Globals
;
7602 Def_Id
: constant Entity_Id
:= Entity
(N
);
7603 Result
: Boolean := False;
7605 -- Start of processing for Freeze_Type
7608 -- The type being frozen may be subject to pragma Ghost with policy
7609 -- Ignore. Set the mode now to ensure that any nodes generated during
7610 -- freezing are properly flagged as ignored Ghost.
7612 Set_Ghost_Mode_For_Freeze
(Def_Id
, N
);
7614 -- Process any remote access-to-class-wide types designating the type
7617 Process_RACW_Types
(Def_Id
);
7619 -- Freeze processing for record types
7621 if Is_Record_Type
(Def_Id
) then
7622 if Ekind
(Def_Id
) = E_Record_Type
then
7623 Expand_Freeze_Record_Type
(N
);
7624 elsif Is_Class_Wide_Type
(Def_Id
) then
7625 Expand_Freeze_Class_Wide_Type
(N
);
7628 -- Freeze processing for array types
7630 elsif Is_Array_Type
(Def_Id
) then
7631 Expand_Freeze_Array_Type
(N
);
7633 -- Freeze processing for access types
7635 -- For pool-specific access types, find out the pool object used for
7636 -- this type, needs actual expansion of it in some cases. Here are the
7637 -- different cases :
7639 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
7640 -- ---> don't use any storage pool
7642 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
7644 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
7646 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7647 -- ---> Storage Pool is the specified one
7649 -- See GNAT Pool packages in the Run-Time for more details
7651 elsif Ekind_In
(Def_Id
, E_Access_Type
, E_General_Access_Type
) then
7653 Loc
: constant Source_Ptr
:= Sloc
(N
);
7654 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
7655 Pool_Object
: Entity_Id
;
7657 Freeze_Action_Typ
: Entity_Id
;
7662 -- Rep Clause "for Def_Id'Storage_Size use 0;"
7663 -- ---> don't use any storage pool
7665 if No_Pool_Assigned
(Def_Id
) then
7670 -- Rep Clause : for Def_Id'Storage_Size use Expr.
7672 -- Def_Id__Pool : Stack_Bounded_Pool
7673 -- (Expr, DT'Size, DT'Alignment);
7675 elsif Has_Storage_Size_Clause
(Def_Id
) then
7681 -- For unconstrained composite types we give a size of zero
7682 -- so that the pool knows that it needs a special algorithm
7683 -- for variable size object allocation.
7685 if Is_Composite_Type
(Desig_Type
)
7686 and then not Is_Constrained
(Desig_Type
)
7688 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
7689 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
7693 Make_Attribute_Reference
(Loc
,
7694 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7695 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
7698 Make_Attribute_Reference
(Loc
,
7699 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7700 Attribute_Name
=> Name_Alignment
);
7704 Make_Defining_Identifier
(Loc
,
7705 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
7707 -- We put the code associated with the pools in the entity
7708 -- that has the later freeze node, usually the access type
7709 -- but it can also be the designated_type; because the pool
7710 -- code requires both those types to be frozen
7712 if Is_Frozen
(Desig_Type
)
7713 and then (No
(Freeze_Node
(Desig_Type
))
7714 or else Analyzed
(Freeze_Node
(Desig_Type
)))
7716 Freeze_Action_Typ
:= Def_Id
;
7718 -- A Taft amendment type cannot get the freeze actions
7719 -- since the full view is not there.
7721 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
7722 and then No
(Full_View
(Desig_Type
))
7724 Freeze_Action_Typ
:= Def_Id
;
7727 Freeze_Action_Typ
:= Desig_Type
;
7730 Append_Freeze_Action
(Freeze_Action_Typ
,
7731 Make_Object_Declaration
(Loc
,
7732 Defining_Identifier
=> Pool_Object
,
7733 Object_Definition
=>
7734 Make_Subtype_Indication
(Loc
,
7737 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
7740 Make_Index_Or_Discriminant_Constraint
(Loc
,
7741 Constraints
=> New_List
(
7743 -- First discriminant is the Pool Size
7746 Storage_Size_Variable
(Def_Id
), Loc
),
7748 -- Second discriminant is the element size
7752 -- Third discriminant is the alignment
7757 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
7761 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7762 -- ---> Storage Pool is the specified one
7764 -- When compiling in Ada 2012 mode, ensure that the accessibility
7765 -- level of the subpool access type is not deeper than that of the
7766 -- pool_with_subpools.
7768 elsif Ada_Version
>= Ada_2012
7769 and then Present
(Associated_Storage_Pool
(Def_Id
))
7771 -- Omit this check on .NET/JVM where pools are not supported
7773 and then VM_Target
= No_VM
7775 -- Omit this check for the case of a configurable run-time that
7776 -- does not provide package System.Storage_Pools.Subpools.
7778 and then RTE_Available
(RE_Root_Storage_Pool_With_Subpools
)
7781 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7782 Pool
: constant Entity_Id
:=
7783 Associated_Storage_Pool
(Def_Id
);
7784 RSPWS
: constant Entity_Id
:=
7785 RTE
(RE_Root_Storage_Pool_With_Subpools
);
7788 -- It is known that the accessibility level of the access
7789 -- type is deeper than that of the pool.
7791 if Type_Access_Level
(Def_Id
) > Object_Access_Level
(Pool
)
7792 and then not Accessibility_Checks_Suppressed
(Def_Id
)
7793 and then not Accessibility_Checks_Suppressed
(Pool
)
7795 -- Static case: the pool is known to be a descendant of
7796 -- Root_Storage_Pool_With_Subpools.
7798 if Is_Ancestor
(RSPWS
, Etype
(Pool
)) then
7800 ("??subpool access type has deeper accessibility "
7801 & "level than pool", Def_Id
);
7803 Append_Freeze_Action
(Def_Id
,
7804 Make_Raise_Program_Error
(Loc
,
7805 Reason
=> PE_Accessibility_Check_Failed
));
7807 -- Dynamic case: when the pool is of a class-wide type,
7808 -- it may or may not support subpools depending on the
7809 -- path of derivation. Generate:
7811 -- if Def_Id in RSPWS'Class then
7812 -- raise Program_Error;
7815 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
7816 Append_Freeze_Action
(Def_Id
,
7817 Make_If_Statement
(Loc
,
7820 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
7823 (Class_Wide_Type
(RSPWS
), Loc
)),
7825 Then_Statements
=> New_List
(
7826 Make_Raise_Program_Error
(Loc
,
7827 Reason
=> PE_Accessibility_Check_Failed
))));
7833 -- For access-to-controlled types (including class-wide types and
7834 -- Taft-amendment types, which potentially have controlled
7835 -- components), expand the list controller object that will store
7836 -- the dynamically allocated objects. Don't do this transformation
7837 -- for expander-generated access types, but do it for types that
7838 -- are the full view of types derived from other private types.
7839 -- Also suppress the list controller in the case of a designated
7840 -- type with convention Java, since this is used when binding to
7841 -- Java API specs, where there's no equivalent of a finalization
7842 -- list and we don't want to pull in the finalization support if
7845 if not Comes_From_Source
(Def_Id
)
7846 and then not Has_Private_Declaration
(Def_Id
)
7850 -- An exception is made for types defined in the run-time because
7851 -- Ada.Tags.Tag itself is such a type and cannot afford this
7852 -- unnecessary overhead that would generates a loop in the
7853 -- expansion scheme. Another exception is if Restrictions
7854 -- (No_Finalization) is active, since then we know nothing is
7857 elsif Restriction_Active
(No_Finalization
)
7858 or else In_Runtime
(Def_Id
)
7862 -- Create a finalization master for an access-to-controlled type
7863 -- or an access-to-incomplete type. It is assumed that the full
7864 -- view will be controlled.
7866 elsif Needs_Finalization
(Desig_Type
)
7867 or else (Is_Incomplete_Type
(Desig_Type
)
7868 and then No
(Full_View
(Desig_Type
)))
7870 Build_Finalization_Master
(Def_Id
);
7872 -- Create a finalization master when the designated type contains
7873 -- a private component. It is assumed that the full view will be
7876 elsif Has_Private_Component
(Desig_Type
) then
7877 Build_Finalization_Master
7879 For_Private
=> True,
7880 Context_Scope
=> Scope
(Def_Id
),
7881 Insertion_Node
=> Declaration_Node
(Desig_Type
));
7885 -- Freeze processing for enumeration types
7887 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
7889 -- We only have something to do if we have a non-standard
7890 -- representation (i.e. at least one literal whose pos value
7891 -- is not the same as its representation)
7893 if Has_Non_Standard_Rep
(Def_Id
) then
7894 Expand_Freeze_Enumeration_Type
(N
);
7897 -- Private types that are completed by a derivation from a private
7898 -- type have an internally generated full view, that needs to be
7899 -- frozen. This must be done explicitly because the two views share
7900 -- the freeze node, and the underlying full view is not visible when
7901 -- the freeze node is analyzed.
7903 elsif Is_Private_Type
(Def_Id
)
7904 and then Is_Derived_Type
(Def_Id
)
7905 and then Present
(Full_View
(Def_Id
))
7906 and then Is_Itype
(Full_View
(Def_Id
))
7907 and then Has_Private_Declaration
(Full_View
(Def_Id
))
7908 and then Freeze_Node
(Full_View
(Def_Id
)) = N
7910 Set_Entity
(N
, Full_View
(Def_Id
));
7911 Result
:= Freeze_Type
(N
);
7912 Set_Entity
(N
, Def_Id
);
7914 -- All other types require no expander action. There are such cases
7915 -- (e.g. task types and protected types). In such cases, the freeze
7916 -- nodes are there for use by Gigi.
7920 -- Complete the initialization of all pending access types' finalization
7921 -- masters now that the designated type has been is frozen and primitive
7922 -- Finalize_Address generated.
7924 Process_Pending_Access_Types
(Def_Id
);
7925 Freeze_Stream_Operations
(N
, Def_Id
);
7931 when RE_Not_Available
=>
7936 -------------------------
7937 -- Get_Simple_Init_Val --
7938 -------------------------
7940 function Get_Simple_Init_Val
7943 Size
: Uint
:= No_Uint
) return Node_Id
7945 Loc
: constant Source_Ptr
:= Sloc
(N
);
7951 -- This is the size to be used for computation of the appropriate
7952 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
7954 IV_Attribute
: constant Boolean :=
7955 Nkind
(N
) = N_Attribute_Reference
7956 and then Attribute_Name
(N
) = Name_Invalid_Value
;
7960 -- These are the values computed by the procedure Check_Subtype_Bounds
7962 procedure Check_Subtype_Bounds
;
7963 -- This procedure examines the subtype T, and its ancestor subtypes and
7964 -- derived types to determine the best known information about the
7965 -- bounds of the subtype. After the call Lo_Bound is set either to
7966 -- No_Uint if no information can be determined, or to a value which
7967 -- represents a known low bound, i.e. a valid value of the subtype can
7968 -- not be less than this value. Hi_Bound is similarly set to a known
7969 -- high bound (valid value cannot be greater than this).
7971 --------------------------
7972 -- Check_Subtype_Bounds --
7973 --------------------------
7975 procedure Check_Subtype_Bounds
is
7984 Lo_Bound
:= No_Uint
;
7985 Hi_Bound
:= No_Uint
;
7987 -- Loop to climb ancestor subtypes and derived types
7991 if not Is_Discrete_Type
(ST1
) then
7995 Lo
:= Type_Low_Bound
(ST1
);
7996 Hi
:= Type_High_Bound
(ST1
);
7998 if Compile_Time_Known_Value
(Lo
) then
7999 Loval
:= Expr_Value
(Lo
);
8001 if Lo_Bound
= No_Uint
or else Lo_Bound
< Loval
then
8006 if Compile_Time_Known_Value
(Hi
) then
8007 Hival
:= Expr_Value
(Hi
);
8009 if Hi_Bound
= No_Uint
or else Hi_Bound
> Hival
then
8014 ST2
:= Ancestor_Subtype
(ST1
);
8020 exit when ST1
= ST2
;
8023 end Check_Subtype_Bounds
;
8025 -- Start of processing for Get_Simple_Init_Val
8028 -- For a private type, we should always have an underlying type (because
8029 -- this was already checked in Needs_Simple_Initialization). What we do
8030 -- is to get the value for the underlying type and then do an unchecked
8031 -- conversion to the private type.
8033 if Is_Private_Type
(T
) then
8034 Val
:= Get_Simple_Init_Val
(Underlying_Type
(T
), N
, Size
);
8036 -- A special case, if the underlying value is null, then qualify it
8037 -- with the underlying type, so that the null is properly typed.
8038 -- Similarly, if it is an aggregate it must be qualified, because an
8039 -- unchecked conversion does not provide a context for it.
8041 if Nkind_In
(Val
, N_Null
, N_Aggregate
) then
8043 Make_Qualified_Expression
(Loc
,
8045 New_Occurrence_Of
(Underlying_Type
(T
), Loc
),
8049 Result
:= Unchecked_Convert_To
(T
, Val
);
8051 -- Don't truncate result (important for Initialize/Normalize_Scalars)
8053 if Nkind
(Result
) = N_Unchecked_Type_Conversion
8054 and then Is_Scalar_Type
(Underlying_Type
(T
))
8056 Set_No_Truncation
(Result
);
8061 -- Scalars with Default_Value aspect. The first subtype may now be
8062 -- private, so retrieve value from underlying type.
8064 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
8065 if Is_Private_Type
(First_Subtype
(T
)) then
8066 return Unchecked_Convert_To
(T
,
8067 Default_Aspect_Value
(Full_View
(First_Subtype
(T
))));
8070 Convert_To
(T
, Default_Aspect_Value
(First_Subtype
(T
)));
8073 -- Otherwise, for scalars, we must have normalize/initialize scalars
8074 -- case, or if the node N is an 'Invalid_Value attribute node.
8076 elsif Is_Scalar_Type
(T
) then
8077 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
8079 -- Compute size of object. If it is given by the caller, we can use
8080 -- it directly, otherwise we use Esize (T) as an estimate. As far as
8081 -- we know this covers all cases correctly.
8083 if Size
= No_Uint
or else Size
<= Uint_0
then
8084 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(T
));
8086 Size_To_Use
:= Size
;
8089 -- Maximum size to use is 64 bits, since we will create values of
8090 -- type Unsigned_64 and the range must fit this type.
8092 if Size_To_Use
/= No_Uint
and then Size_To_Use
> Uint_64
then
8093 Size_To_Use
:= Uint_64
;
8096 -- Check known bounds of subtype
8098 Check_Subtype_Bounds
;
8100 -- Processing for Normalize_Scalars case
8102 if Normalize_Scalars
and then not IV_Attribute
then
8104 -- If zero is invalid, it is a convenient value to use that is
8105 -- for sure an appropriate invalid value in all situations.
8107 if Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8108 Val
:= Make_Integer_Literal
(Loc
, 0);
8110 -- Cases where all one bits is the appropriate invalid value
8112 -- For modular types, all 1 bits is either invalid or valid. If
8113 -- it is valid, then there is nothing that can be done since there
8114 -- are no invalid values (we ruled out zero already).
8116 -- For signed integer types that have no negative values, either
8117 -- there is room for negative values, or there is not. If there
8118 -- is, then all 1-bits may be interpreted as minus one, which is
8119 -- certainly invalid. Alternatively it is treated as the largest
8120 -- positive value, in which case the observation for modular types
8123 -- For float types, all 1-bits is a NaN (not a number), which is
8124 -- certainly an appropriately invalid value.
8126 elsif Is_Unsigned_Type
(T
)
8127 or else Is_Floating_Point_Type
(T
)
8128 or else Is_Enumeration_Type
(T
)
8130 Val
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
8132 -- Resolve as Unsigned_64, because the largest number we can
8133 -- generate is out of range of universal integer.
8135 Analyze_And_Resolve
(Val
, RTE
(RE_Unsigned_64
));
8137 -- Case of signed types
8141 Signed_Size
: constant Uint
:=
8142 UI_Min
(Uint_63
, Size_To_Use
- 1);
8145 -- Normally we like to use the most negative number. The one
8146 -- exception is when this number is in the known subtype
8147 -- range and the largest positive number is not in the known
8150 -- For this exceptional case, use largest positive value
8152 if Lo_Bound
/= No_Uint
and then Hi_Bound
/= No_Uint
8153 and then Lo_Bound
<= (-(2 ** Signed_Size
))
8154 and then Hi_Bound
< 2 ** Signed_Size
8156 Val
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
8158 -- Normal case of largest negative value
8161 Val
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
8166 -- Here for Initialize_Scalars case (or Invalid_Value attribute used)
8169 -- For float types, use float values from System.Scalar_Values
8171 if Is_Floating_Point_Type
(T
) then
8172 if Root_Type
(T
) = Standard_Short_Float
then
8173 Val_RE
:= RE_IS_Isf
;
8174 elsif Root_Type
(T
) = Standard_Float
then
8175 Val_RE
:= RE_IS_Ifl
;
8176 elsif Root_Type
(T
) = Standard_Long_Float
then
8177 Val_RE
:= RE_IS_Ilf
;
8178 else pragma Assert
(Root_Type
(T
) = Standard_Long_Long_Float
);
8179 Val_RE
:= RE_IS_Ill
;
8182 -- If zero is invalid, use zero values from System.Scalar_Values
8184 elsif Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8185 if Size_To_Use
<= 8 then
8186 Val_RE
:= RE_IS_Iz1
;
8187 elsif Size_To_Use
<= 16 then
8188 Val_RE
:= RE_IS_Iz2
;
8189 elsif Size_To_Use
<= 32 then
8190 Val_RE
:= RE_IS_Iz4
;
8192 Val_RE
:= RE_IS_Iz8
;
8195 -- For unsigned, use unsigned values from System.Scalar_Values
8197 elsif Is_Unsigned_Type
(T
) then
8198 if Size_To_Use
<= 8 then
8199 Val_RE
:= RE_IS_Iu1
;
8200 elsif Size_To_Use
<= 16 then
8201 Val_RE
:= RE_IS_Iu2
;
8202 elsif Size_To_Use
<= 32 then
8203 Val_RE
:= RE_IS_Iu4
;
8205 Val_RE
:= RE_IS_Iu8
;
8208 -- For signed, use signed values from System.Scalar_Values
8211 if Size_To_Use
<= 8 then
8212 Val_RE
:= RE_IS_Is1
;
8213 elsif Size_To_Use
<= 16 then
8214 Val_RE
:= RE_IS_Is2
;
8215 elsif Size_To_Use
<= 32 then
8216 Val_RE
:= RE_IS_Is4
;
8218 Val_RE
:= RE_IS_Is8
;
8222 Val
:= New_Occurrence_Of
(RTE
(Val_RE
), Loc
);
8225 -- The final expression is obtained by doing an unchecked conversion
8226 -- of this result to the base type of the required subtype. Use the
8227 -- base type to prevent the unchecked conversion from chopping bits,
8228 -- and then we set Kill_Range_Check to preserve the "bad" value.
8230 Result
:= Unchecked_Convert_To
(Base_Type
(T
), Val
);
8232 -- Ensure result is not truncated, since we want the "bad" bits, and
8233 -- also kill range check on result.
8235 if Nkind
(Result
) = N_Unchecked_Type_Conversion
then
8236 Set_No_Truncation
(Result
);
8237 Set_Kill_Range_Check
(Result
, True);
8242 -- String or Wide_[Wide]_String (must have Initialize_Scalars set)
8244 elsif Is_Standard_String_Type
(T
) then
8245 pragma Assert
(Init_Or_Norm_Scalars
);
8248 Make_Aggregate
(Loc
,
8249 Component_Associations
=> New_List
(
8250 Make_Component_Association
(Loc
,
8251 Choices
=> New_List
(
8252 Make_Others_Choice
(Loc
)),
8255 (Component_Type
(T
), N
, Esize
(Root_Type
(T
))))));
8257 -- Access type is initialized to null
8259 elsif Is_Access_Type
(T
) then
8260 return Make_Null
(Loc
);
8262 -- No other possibilities should arise, since we should only be calling
8263 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8264 -- indicating one of the above cases held.
8267 raise Program_Error
;
8271 when RE_Not_Available
=>
8273 end Get_Simple_Init_Val
;
8275 ------------------------------
8276 -- Has_New_Non_Standard_Rep --
8277 ------------------------------
8279 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
8281 if not Is_Derived_Type
(T
) then
8282 return Has_Non_Standard_Rep
(T
)
8283 or else Has_Non_Standard_Rep
(Root_Type
(T
));
8285 -- If Has_Non_Standard_Rep is not set on the derived type, the
8286 -- representation is fully inherited.
8288 elsif not Has_Non_Standard_Rep
(T
) then
8292 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
8294 -- May need a more precise check here: the First_Rep_Item may be a
8295 -- stream attribute, which does not affect the representation of the
8299 end Has_New_Non_Standard_Rep
;
8305 function In_Runtime
(E
: Entity_Id
) return Boolean is
8310 while Scope
(S1
) /= Standard_Standard
loop
8314 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
8317 ---------------------------------------
8318 -- Insert_Component_Invariant_Checks --
8319 ---------------------------------------
8321 procedure Insert_Component_Invariant_Checks
8326 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8327 Proc_Id
: Entity_Id
;
8330 if Present
(Proc
) then
8331 Proc_Id
:= Defining_Entity
(Proc
);
8333 if not Has_Invariants
(Typ
) then
8334 Set_Has_Invariants
(Typ
);
8335 Set_Is_Invariant_Procedure
(Proc_Id
);
8336 Set_Invariant_Procedure
(Typ
, Proc_Id
);
8337 Insert_After
(N
, Proc
);
8342 -- Find already created invariant subprogram, insert body of
8343 -- component invariant proc in its body, and add call after
8348 Inv_Id
: constant Entity_Id
:= Invariant_Procedure
(Typ
);
8349 Call
: constant Node_Id
:=
8350 Make_Procedure_Call_Statement
(Sloc
(N
),
8351 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
8352 Parameter_Associations
=>
8354 (New_Occurrence_Of
(First_Formal
(Inv_Id
), Loc
)));
8357 -- The invariant body has not been analyzed yet, so we do a
8358 -- sequential search forward, and retrieve it by name.
8361 while Present
(Bod
) loop
8362 exit when Nkind
(Bod
) = N_Subprogram_Body
8363 and then Chars
(Defining_Entity
(Bod
)) = Chars
(Inv_Id
);
8367 -- If the body is not found, it is the case of an invariant
8368 -- appearing on a full declaration in a private part, in
8369 -- which case the type has been frozen but the invariant
8370 -- procedure for the composite type not created yet. Create
8374 Build_Invariant_Procedure
(Typ
, Parent
(Current_Scope
));
8375 Bod
:= Unit_Declaration_Node
8376 (Corresponding_Body
(Unit_Declaration_Node
(Inv_Id
)));
8379 Append_To
(Declarations
(Bod
), Proc
);
8380 Append_To
(Statements
(Handled_Statement_Sequence
(Bod
)), Call
);
8386 end Insert_Component_Invariant_Checks
;
8388 ----------------------------
8389 -- Initialization_Warning --
8390 ----------------------------
8392 procedure Initialization_Warning
(E
: Entity_Id
) is
8393 Warning_Needed
: Boolean;
8396 Warning_Needed
:= False;
8398 if Ekind
(Current_Scope
) = E_Package
8399 and then Static_Elaboration_Desired
(Current_Scope
)
8402 if Is_Record_Type
(E
) then
8403 if Has_Discriminants
(E
)
8404 or else Is_Limited_Type
(E
)
8405 or else Has_Non_Standard_Rep
(E
)
8407 Warning_Needed
:= True;
8410 -- Verify that at least one component has an initialization
8411 -- expression. No need for a warning on a type if all its
8412 -- components have no initialization.
8418 Comp
:= First_Component
(E
);
8419 while Present
(Comp
) loop
8420 if Ekind
(Comp
) = E_Discriminant
8422 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
8423 and then Present
(Expression
(Parent
(Comp
))))
8425 Warning_Needed
:= True;
8429 Next_Component
(Comp
);
8434 if Warning_Needed
then
8436 ("Objects of the type cannot be initialized statically "
8437 & "by default??", Parent
(E
));
8442 Error_Msg_N
("Object cannot be initialized statically??", E
);
8445 end Initialization_Warning
;
8451 function Init_Formals
(Typ
: Entity_Id
) return List_Id
is
8452 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8456 -- First parameter is always _Init : in out typ. Note that we need this
8457 -- to be in/out because in the case of the task record value, there
8458 -- are default record fields (_Priority, _Size, -Task_Info) that may
8459 -- be referenced in the generated initialization routine.
8461 Formals
:= New_List
(
8462 Make_Parameter_Specification
(Loc
,
8463 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
8465 Out_Present
=> True,
8466 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8468 -- For task record value, or type that contains tasks, add two more
8469 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8470 -- We also add these parameters for the task record type case.
8473 or else (Is_Record_Type
(Typ
) and then Is_Task_Record_Type
(Typ
))
8476 Make_Parameter_Specification
(Loc
,
8477 Defining_Identifier
=>
8478 Make_Defining_Identifier
(Loc
, Name_uMaster
),
8480 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
)));
8482 -- Add _Chain (not done for sequential elaboration policy, see
8483 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
8485 if Partition_Elaboration_Policy
/= 'S' then
8487 Make_Parameter_Specification
(Loc
,
8488 Defining_Identifier
=>
8489 Make_Defining_Identifier
(Loc
, Name_uChain
),
8491 Out_Present
=> True,
8493 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
8497 Make_Parameter_Specification
(Loc
,
8498 Defining_Identifier
=>
8499 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
8501 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
8507 when RE_Not_Available
=>
8511 -------------------------
8512 -- Init_Secondary_Tags --
8513 -------------------------
8515 procedure Init_Secondary_Tags
8518 Stmts_List
: List_Id
;
8519 Fixed_Comps
: Boolean := True;
8520 Variable_Comps
: Boolean := True)
8522 Loc
: constant Source_Ptr
:= Sloc
(Target
);
8524 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
8525 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8527 procedure Initialize_Tag
8530 Tag_Comp
: Entity_Id
;
8531 Iface_Tag
: Node_Id
);
8532 -- Initialize the tag of the secondary dispatch table of Typ associated
8533 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8534 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
8535 -- of Typ CPP tagged type we generate code to inherit the contents of
8536 -- the dispatch table directly from the ancestor.
8538 --------------------
8539 -- Initialize_Tag --
8540 --------------------
8542 procedure Initialize_Tag
8545 Tag_Comp
: Entity_Id
;
8546 Iface_Tag
: Node_Id
)
8548 Comp_Typ
: Entity_Id
;
8549 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
8552 -- Initialize pointer to secondary DT associated with the interface
8554 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8555 Append_To
(Stmts_List
,
8556 Make_Assignment_Statement
(Loc
,
8558 Make_Selected_Component
(Loc
,
8559 Prefix
=> New_Copy_Tree
(Target
),
8560 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8562 New_Occurrence_Of
(Iface_Tag
, Loc
)));
8565 Comp_Typ
:= Scope
(Tag_Comp
);
8567 -- Initialize the entries of the table of interfaces. We generate a
8568 -- different call when the parent of the type has variable size
8571 if Comp_Typ
/= Etype
(Comp_Typ
)
8572 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
8573 and then Chars
(Tag_Comp
) /= Name_uTag
8575 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
8577 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
8578 -- configurable run-time environment.
8580 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
8582 ("variable size record with interface types", Typ
);
8587 -- Set_Dynamic_Offset_To_Top
8589 -- Interface_T => Iface'Tag,
8590 -- Offset_Value => n,
8591 -- Offset_Func => Fn'Address)
8593 Append_To
(Stmts_List
,
8594 Make_Procedure_Call_Statement
(Loc
,
8596 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
8597 Parameter_Associations
=> New_List
(
8598 Make_Attribute_Reference
(Loc
,
8599 Prefix
=> New_Copy_Tree
(Target
),
8600 Attribute_Name
=> Name_Address
),
8602 Unchecked_Convert_To
(RTE
(RE_Tag
),
8604 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
8607 Unchecked_Convert_To
8608 (RTE
(RE_Storage_Offset
),
8609 Make_Attribute_Reference
(Loc
,
8611 Make_Selected_Component
(Loc
,
8612 Prefix
=> New_Copy_Tree
(Target
),
8614 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8615 Attribute_Name
=> Name_Position
)),
8617 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
8618 Make_Attribute_Reference
(Loc
,
8619 Prefix
=> New_Occurrence_Of
8620 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
8621 Attribute_Name
=> Name_Address
)))));
8623 -- In this case the next component stores the value of the offset
8626 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
8627 pragma Assert
(Present
(Offset_To_Top_Comp
));
8629 Append_To
(Stmts_List
,
8630 Make_Assignment_Statement
(Loc
,
8632 Make_Selected_Component
(Loc
,
8633 Prefix
=> New_Copy_Tree
(Target
),
8635 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
8638 Make_Attribute_Reference
(Loc
,
8640 Make_Selected_Component
(Loc
,
8641 Prefix
=> New_Copy_Tree
(Target
),
8642 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8643 Attribute_Name
=> Name_Position
)));
8645 -- Normal case: No discriminants in the parent type
8648 -- Don't need to set any value if this interface shares the
8649 -- primary dispatch table.
8651 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8652 Append_To
(Stmts_List
,
8653 Build_Set_Static_Offset_To_Top
(Loc
,
8654 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
8656 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8657 Make_Attribute_Reference
(Loc
,
8659 Make_Selected_Component
(Loc
,
8660 Prefix
=> New_Copy_Tree
(Target
),
8662 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8663 Attribute_Name
=> Name_Position
))));
8667 -- Register_Interface_Offset
8669 -- Interface_T => Iface'Tag,
8670 -- Is_Constant => True,
8671 -- Offset_Value => n,
8672 -- Offset_Func => null);
8674 if RTE_Available
(RE_Register_Interface_Offset
) then
8675 Append_To
(Stmts_List
,
8676 Make_Procedure_Call_Statement
(Loc
,
8679 (RTE
(RE_Register_Interface_Offset
), Loc
),
8680 Parameter_Associations
=> New_List
(
8681 Make_Attribute_Reference
(Loc
,
8682 Prefix
=> New_Copy_Tree
(Target
),
8683 Attribute_Name
=> Name_Address
),
8685 Unchecked_Convert_To
(RTE
(RE_Tag
),
8687 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
8689 New_Occurrence_Of
(Standard_True
, Loc
),
8691 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8692 Make_Attribute_Reference
(Loc
,
8694 Make_Selected_Component
(Loc
,
8695 Prefix
=> New_Copy_Tree
(Target
),
8697 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8698 Attribute_Name
=> Name_Position
)),
8707 Full_Typ
: Entity_Id
;
8708 Ifaces_List
: Elist_Id
;
8709 Ifaces_Comp_List
: Elist_Id
;
8710 Ifaces_Tag_List
: Elist_Id
;
8711 Iface_Elmt
: Elmt_Id
;
8712 Iface_Comp_Elmt
: Elmt_Id
;
8713 Iface_Tag_Elmt
: Elmt_Id
;
8715 In_Variable_Pos
: Boolean;
8717 -- Start of processing for Init_Secondary_Tags
8720 -- Handle private types
8722 if Present
(Full_View
(Typ
)) then
8723 Full_Typ
:= Full_View
(Typ
);
8728 Collect_Interfaces_Info
8729 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
8731 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8732 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
8733 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
8734 while Present
(Iface_Elmt
) loop
8735 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
8737 -- Check if parent of record type has variable size components
8739 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
8740 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
8742 -- If we are compiling under the CPP full ABI compatibility mode and
8743 -- the ancestor is a CPP_Pragma tagged type then we generate code to
8744 -- initialize the secondary tag components from tags that reference
8745 -- secondary tables filled with copy of parent slots.
8747 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
8749 -- Reject interface components located at variable offset in
8750 -- C++ derivations. This is currently unsupported.
8752 if not Fixed_Comps
and then In_Variable_Pos
then
8754 -- Locate the first dynamic component of the record. Done to
8755 -- improve the text of the warning.
8759 Comp_Typ
: Entity_Id
;
8762 Comp
:= First_Entity
(Typ
);
8763 while Present
(Comp
) loop
8764 Comp_Typ
:= Etype
(Comp
);
8766 if Ekind
(Comp
) /= E_Discriminant
8767 and then not Is_Tag
(Comp
)
8770 (Is_Record_Type
(Comp_Typ
)
8772 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
8774 (Is_Array_Type
(Comp_Typ
)
8775 and then Is_Variable_Size_Array
(Comp_Typ
));
8781 pragma Assert
(Present
(Comp
));
8782 Error_Msg_Node_2
:= Comp
;
8784 ("parent type & with dynamic component & cannot be parent"
8785 & " of 'C'P'P derivation if new interfaces are present",
8786 Typ
, Scope
(Original_Record_Component
(Comp
)));
8789 Sloc
(Scope
(Original_Record_Component
(Comp
)));
8791 ("type derived from 'C'P'P type & defined #",
8792 Typ
, Scope
(Original_Record_Component
(Comp
)));
8794 -- Avoid duplicated warnings
8799 -- Initialize secondary tags
8802 Append_To
(Stmts_List
,
8803 Make_Assignment_Statement
(Loc
,
8805 Make_Selected_Component
(Loc
,
8806 Prefix
=> New_Copy_Tree
(Target
),
8808 New_Occurrence_Of
(Node
(Iface_Comp_Elmt
), Loc
)),
8810 New_Occurrence_Of
(Node
(Iface_Tag_Elmt
), Loc
)));
8813 -- Otherwise generate code to initialize the tag
8816 if (In_Variable_Pos
and then Variable_Comps
)
8817 or else (not In_Variable_Pos
and then Fixed_Comps
)
8819 Initialize_Tag
(Full_Typ
,
8820 Iface
=> Node
(Iface_Elmt
),
8821 Tag_Comp
=> Tag_Comp
,
8822 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
8826 Next_Elmt
(Iface_Elmt
);
8827 Next_Elmt
(Iface_Comp_Elmt
);
8828 Next_Elmt
(Iface_Tag_Elmt
);
8830 end Init_Secondary_Tags
;
8832 ------------------------
8833 -- Is_User_Defined_Eq --
8834 ------------------------
8836 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean is
8838 return Chars
(Prim
) = Name_Op_Eq
8839 and then Etype
(First_Formal
(Prim
)) =
8840 Etype
(Next_Formal
(First_Formal
(Prim
)))
8841 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
;
8842 end Is_User_Defined_Equality
;
8844 ----------------------------------------
8845 -- Make_Controlling_Function_Wrappers --
8846 ----------------------------------------
8848 procedure Make_Controlling_Function_Wrappers
8849 (Tag_Typ
: Entity_Id
;
8850 Decl_List
: out List_Id
;
8851 Body_List
: out List_Id
)
8853 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
8854 Prim_Elmt
: Elmt_Id
;
8856 Actual_List
: List_Id
;
8857 Formal_List
: List_Id
;
8859 Par_Formal
: Entity_Id
;
8860 Formal_Node
: Node_Id
;
8861 Func_Body
: Node_Id
;
8862 Func_Decl
: Node_Id
;
8863 Func_Spec
: Node_Id
;
8864 Return_Stmt
: Node_Id
;
8867 Decl_List
:= New_List
;
8868 Body_List
:= New_List
;
8870 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
8871 while Present
(Prim_Elmt
) loop
8872 Subp
:= Node
(Prim_Elmt
);
8874 -- If a primitive function with a controlling result of the type has
8875 -- not been overridden by the user, then we must create a wrapper
8876 -- function here that effectively overrides it and invokes the
8877 -- (non-abstract) parent function. This can only occur for a null
8878 -- extension. Note that functions with anonymous controlling access
8879 -- results don't qualify and must be overridden. We also exclude
8880 -- Input attributes, since each type will have its own version of
8881 -- Input constructed by the expander. The test for Comes_From_Source
8882 -- is needed to distinguish inherited operations from renamings
8883 -- (which also have Alias set). We exclude internal entities with
8884 -- Interface_Alias to avoid generating duplicated wrappers since
8885 -- the primitive which covers the interface is also available in
8886 -- the list of primitive operations.
8888 -- The function may be abstract, or require_Overriding may be set
8889 -- for it, because tests for null extensions may already have reset
8890 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
8891 -- set, functions that need wrappers are recognized by having an
8892 -- alias that returns the parent type.
8894 if Comes_From_Source
(Subp
)
8895 or else No
(Alias
(Subp
))
8896 or else Present
(Interface_Alias
(Subp
))
8897 or else Ekind
(Subp
) /= E_Function
8898 or else not Has_Controlling_Result
(Subp
)
8899 or else Is_Access_Type
(Etype
(Subp
))
8900 or else Is_Abstract_Subprogram
(Alias
(Subp
))
8901 or else Is_TSS
(Subp
, TSS_Stream_Input
)
8905 elsif Is_Abstract_Subprogram
(Subp
)
8906 or else Requires_Overriding
(Subp
)
8908 (Is_Null_Extension
(Etype
(Subp
))
8909 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
8911 Formal_List
:= No_List
;
8912 Formal
:= First_Formal
(Subp
);
8914 if Present
(Formal
) then
8915 Formal_List
:= New_List
;
8917 while Present
(Formal
) loop
8919 (Make_Parameter_Specification
8921 Defining_Identifier
=>
8922 Make_Defining_Identifier
(Sloc
(Formal
),
8923 Chars
=> Chars
(Formal
)),
8924 In_Present
=> In_Present
(Parent
(Formal
)),
8925 Out_Present
=> Out_Present
(Parent
(Formal
)),
8926 Null_Exclusion_Present
=>
8927 Null_Exclusion_Present
(Parent
(Formal
)),
8929 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8931 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
8934 Next_Formal
(Formal
);
8939 Make_Function_Specification
(Loc
,
8940 Defining_Unit_Name
=>
8941 Make_Defining_Identifier
(Loc
,
8942 Chars
=> Chars
(Subp
)),
8943 Parameter_Specifications
=> Formal_List
,
8944 Result_Definition
=>
8945 New_Occurrence_Of
(Etype
(Subp
), Loc
));
8947 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Func_Spec
);
8948 Append_To
(Decl_List
, Func_Decl
);
8950 -- Build a wrapper body that calls the parent function. The body
8951 -- contains a single return statement that returns an extension
8952 -- aggregate whose ancestor part is a call to the parent function,
8953 -- passing the formals as actuals (with any controlling arguments
8954 -- converted to the types of the corresponding formals of the
8955 -- parent function, which might be anonymous access types), and
8956 -- having a null extension.
8958 Formal
:= First_Formal
(Subp
);
8959 Par_Formal
:= First_Formal
(Alias
(Subp
));
8960 Formal_Node
:= First
(Formal_List
);
8962 if Present
(Formal
) then
8963 Actual_List
:= New_List
;
8965 Actual_List
:= No_List
;
8968 while Present
(Formal
) loop
8969 if Is_Controlling_Formal
(Formal
) then
8970 Append_To
(Actual_List
,
8971 Make_Type_Conversion
(Loc
,
8973 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
8976 (Defining_Identifier
(Formal_Node
), Loc
)));
8981 (Defining_Identifier
(Formal_Node
), Loc
));
8984 Next_Formal
(Formal
);
8985 Next_Formal
(Par_Formal
);
8990 Make_Simple_Return_Statement
(Loc
,
8992 Make_Extension_Aggregate
(Loc
,
8994 Make_Function_Call
(Loc
,
8996 New_Occurrence_Of
(Alias
(Subp
), Loc
),
8997 Parameter_Associations
=> Actual_List
),
8998 Null_Record_Present
=> True));
9001 Make_Subprogram_Body
(Loc
,
9002 Specification
=> New_Copy_Tree
(Func_Spec
),
9003 Declarations
=> Empty_List
,
9004 Handled_Statement_Sequence
=>
9005 Make_Handled_Sequence_Of_Statements
(Loc
,
9006 Statements
=> New_List
(Return_Stmt
)));
9008 Set_Defining_Unit_Name
9009 (Specification
(Func_Body
),
9010 Make_Defining_Identifier
(Loc
, Chars
(Subp
)));
9012 Append_To
(Body_List
, Func_Body
);
9014 -- Replace the inherited function with the wrapper function in the
9015 -- primitive operations list. We add the minimum decoration needed
9016 -- to override interface primitives.
9018 Set_Ekind
(Defining_Unit_Name
(Func_Spec
), E_Function
);
9020 Override_Dispatching_Operation
9021 (Tag_Typ
, Subp
, New_Op
=> Defining_Unit_Name
(Func_Spec
),
9022 Is_Wrapper
=> True);
9026 Next_Elmt
(Prim_Elmt
);
9028 end Make_Controlling_Function_Wrappers
;
9034 function Make_Eq_Body
9036 Eq_Name
: Name_Id
) return Node_Id
9038 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
9040 Def
: constant Node_Id
:= Parent
(Typ
);
9041 Stmts
: constant List_Id
:= New_List
;
9042 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
9043 Comps
: Node_Id
:= Empty
;
9044 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
9048 Predef_Spec_Or_Body
(Loc
,
9051 Profile
=> New_List
(
9052 Make_Parameter_Specification
(Loc
,
9053 Defining_Identifier
=>
9054 Make_Defining_Identifier
(Loc
, Name_X
),
9055 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
9057 Make_Parameter_Specification
(Loc
,
9058 Defining_Identifier
=>
9059 Make_Defining_Identifier
(Loc
, Name_Y
),
9060 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9062 Ret_Type
=> Standard_Boolean
,
9065 if Variant_Case
then
9066 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
9067 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
9070 if Present
(Typ_Def
) then
9071 Comps
:= Component_List
(Typ_Def
);
9075 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
9078 if Variant_Case
then
9080 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
9081 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
9083 Make_Simple_Return_Statement
(Loc
,
9084 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9088 Make_Simple_Return_Statement
(Loc
,
9090 Expand_Record_Equality
9093 Lhs
=> Make_Identifier
(Loc
, Name_X
),
9094 Rhs
=> Make_Identifier
(Loc
, Name_Y
),
9095 Bodies
=> Declarations
(Decl
))));
9098 Set_Handled_Statement_Sequence
9099 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9107 -- <Make_Eq_If shared components>
9110 -- when V1 => <Make_Eq_Case> on subcomponents
9112 -- when Vn => <Make_Eq_Case> on subcomponents
9115 function Make_Eq_Case
9118 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
9120 Loc
: constant Source_Ptr
:= Sloc
(E
);
9121 Result
: constant List_Id
:= New_List
;
9125 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
9126 -- Given the discriminant that controls a given variant of an unchecked
9127 -- union, find the formal of the equality function that carries the
9128 -- inferred value of the discriminant.
9130 function External_Name
(E
: Entity_Id
) return Name_Id
;
9131 -- The value of a given discriminant is conveyed in the corresponding
9132 -- formal parameter of the equality routine. The name of this formal
9133 -- parameter carries a one-character suffix which is removed here.
9135 --------------------------
9136 -- Corresponding_Formal --
9137 --------------------------
9139 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
9140 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
9144 Elm
:= First_Elmt
(Discrs
);
9145 while Present
(Elm
) loop
9146 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
9153 -- A formal of the proper name must be found
9155 raise Program_Error
;
9156 end Corresponding_Formal
;
9162 function External_Name
(E
: Entity_Id
) return Name_Id
is
9164 Get_Name_String
(Chars
(E
));
9165 Name_Len
:= Name_Len
- 1;
9169 -- Start of processing for Make_Eq_Case
9172 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
9174 if No
(Variant_Part
(CL
)) then
9178 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
9180 if No
(Variant
) then
9184 Alt_List
:= New_List
;
9185 while Present
(Variant
) loop
9186 Append_To
(Alt_List
,
9187 Make_Case_Statement_Alternative
(Loc
,
9188 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
9190 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
9191 Next_Non_Pragma
(Variant
);
9194 -- If we have an Unchecked_Union, use one of the parameters of the
9195 -- enclosing equality routine that captures the discriminant, to use
9196 -- as the expression in the generated case statement.
9198 if Is_Unchecked_Union
(E
) then
9200 Make_Case_Statement
(Loc
,
9202 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
9203 Alternatives
=> Alt_List
));
9207 Make_Case_Statement
(Loc
,
9209 Make_Selected_Component
(Loc
,
9210 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9211 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
9212 Alternatives
=> Alt_List
));
9233 -- or a null statement if the list L is empty
9237 L
: List_Id
) return Node_Id
9239 Loc
: constant Source_Ptr
:= Sloc
(E
);
9241 Field_Name
: Name_Id
;
9246 return Make_Null_Statement
(Loc
);
9251 C
:= First_Non_Pragma
(L
);
9252 while Present
(C
) loop
9253 Field_Name
:= Chars
(Defining_Identifier
(C
));
9255 -- The tags must not be compared: they are not part of the value.
9256 -- Ditto for parent interfaces because their equality operator is
9259 -- Note also that in the following, we use Make_Identifier for
9260 -- the component names. Use of New_Occurrence_Of to identify the
9261 -- components would be incorrect because the wrong entities for
9262 -- discriminants could be picked up in the private type case.
9264 if Field_Name
= Name_uParent
9265 and then Is_Interface
(Etype
(Defining_Identifier
(C
)))
9269 elsif Field_Name
/= Name_uTag
then
9270 Evolve_Or_Else
(Cond
,
9273 Make_Selected_Component
(Loc
,
9274 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9275 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
)),
9278 Make_Selected_Component
(Loc
,
9279 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
9280 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
))));
9283 Next_Non_Pragma
(C
);
9287 return Make_Null_Statement
(Loc
);
9291 Make_Implicit_If_Statement
(E
,
9293 Then_Statements
=> New_List
(
9294 Make_Simple_Return_Statement
(Loc
,
9295 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
9304 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
9306 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
9307 -- Returns true if Prim is a renaming of an unresolved predefined
9308 -- inequality operation.
9310 --------------------------------
9311 -- Is_Predefined_Neq_Renaming --
9312 --------------------------------
9314 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
9316 return Chars
(Prim
) /= Name_Op_Ne
9317 and then Present
(Alias
(Prim
))
9318 and then Comes_From_Source
(Prim
)
9319 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9320 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
9321 end Is_Predefined_Neq_Renaming
;
9325 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
9326 Stmts
: constant List_Id
:= New_List
;
9328 Eq_Prim
: Entity_Id
;
9329 Left_Op
: Entity_Id
;
9330 Renaming_Prim
: Entity_Id
;
9331 Right_Op
: Entity_Id
;
9334 -- Start of processing for Make_Neq_Body
9337 -- For a call on a renaming of a dispatching subprogram that is
9338 -- overridden, if the overriding occurred before the renaming, then
9339 -- the body executed is that of the overriding declaration, even if the
9340 -- overriding declaration is not visible at the place of the renaming;
9341 -- otherwise, the inherited or predefined subprogram is called, see
9344 -- Stage 1: Search for a renaming of the inequality primitive and also
9345 -- search for an overriding of the equality primitive located before the
9346 -- renaming declaration.
9354 Renaming_Prim
:= Empty
;
9356 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9357 while Present
(Elmt
) loop
9358 Prim
:= Node
(Elmt
);
9360 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
9361 if No
(Renaming_Prim
) then
9362 pragma Assert
(No
(Eq_Prim
));
9366 elsif Is_Predefined_Neq_Renaming
(Prim
) then
9367 Renaming_Prim
:= Prim
;
9374 -- No further action needed if no renaming was found
9376 if No
(Renaming_Prim
) then
9380 -- Stage 2: Replace the renaming declaration by a subprogram declaration
9381 -- (required to add its body)
9383 Decl
:= Parent
(Parent
(Renaming_Prim
));
9385 Make_Subprogram_Declaration
(Loc
,
9386 Specification
=> Specification
(Decl
)));
9387 Set_Analyzed
(Decl
);
9389 -- Remove the decoration of intrinsic renaming subprogram
9391 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
9392 Set_Convention
(Renaming_Prim
, Convention_Ada
);
9393 Set_Alias
(Renaming_Prim
, Empty
);
9394 Set_Has_Completion
(Renaming_Prim
, False);
9396 -- Stage 3: Build the corresponding body
9398 Left_Op
:= First_Formal
(Renaming_Prim
);
9399 Right_Op
:= Next_Formal
(Left_Op
);
9402 Predef_Spec_Or_Body
(Loc
,
9404 Name
=> Chars
(Renaming_Prim
),
9405 Profile
=> New_List
(
9406 Make_Parameter_Specification
(Loc
,
9407 Defining_Identifier
=>
9408 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
9409 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9411 Make_Parameter_Specification
(Loc
,
9412 Defining_Identifier
=>
9413 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
9414 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9416 Ret_Type
=> Standard_Boolean
,
9419 -- If the overriding of the equality primitive occurred before the
9420 -- renaming, then generate:
9422 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9424 -- return not Oeq (X, Y);
9427 if Present
(Eq_Prim
) then
9430 -- Otherwise build a nested subprogram which performs the predefined
9431 -- evaluation of the equality operator. That is, generate:
9433 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9434 -- function Oeq (X : Y) return Boolean is
9436 -- <<body of default implementation>>
9439 -- return not Oeq (X, Y);
9444 Local_Subp
: Node_Id
;
9446 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
9447 Set_Declarations
(Decl
, New_List
(Local_Subp
));
9448 Target
:= Defining_Entity
(Local_Subp
);
9453 Make_Simple_Return_Statement
(Loc
,
9456 Make_Function_Call
(Loc
,
9457 Name
=> New_Occurrence_Of
(Target
, Loc
),
9458 Parameter_Associations
=> New_List
(
9459 Make_Identifier
(Loc
, Chars
(Left_Op
)),
9460 Make_Identifier
(Loc
, Chars
(Right_Op
)))))));
9462 Set_Handled_Statement_Sequence
9463 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9467 -------------------------------
9468 -- Make_Null_Procedure_Specs --
9469 -------------------------------
9471 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
9472 Decl_List
: constant List_Id
:= New_List
;
9473 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9475 Formal_List
: List_Id
;
9476 New_Param_Spec
: Node_Id
;
9477 Parent_Subp
: Entity_Id
;
9478 Prim_Elmt
: Elmt_Id
;
9482 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9483 while Present
(Prim_Elmt
) loop
9484 Subp
:= Node
(Prim_Elmt
);
9486 -- If a null procedure inherited from an interface has not been
9487 -- overridden, then we build a null procedure declaration to
9488 -- override the inherited procedure.
9490 Parent_Subp
:= Alias
(Subp
);
9492 if Present
(Parent_Subp
)
9493 and then Is_Null_Interface_Primitive
(Parent_Subp
)
9495 Formal_List
:= No_List
;
9496 Formal
:= First_Formal
(Subp
);
9498 if Present
(Formal
) then
9499 Formal_List
:= New_List
;
9501 while Present
(Formal
) loop
9503 -- Copy the parameter spec including default expressions
9506 New_Copy_Tree
(Parent
(Formal
), New_Sloc
=> Loc
);
9508 -- Generate a new defining identifier for the new formal.
9509 -- required because New_Copy_Tree does not duplicate
9510 -- semantic fields (except itypes).
9512 Set_Defining_Identifier
(New_Param_Spec
,
9513 Make_Defining_Identifier
(Sloc
(Formal
),
9514 Chars
=> Chars
(Formal
)));
9516 -- For controlling arguments we must change their
9517 -- parameter type to reference the tagged type (instead
9518 -- of the interface type)
9520 if Is_Controlling_Formal
(Formal
) then
9521 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
9523 Set_Parameter_Type
(New_Param_Spec
,
9524 New_Occurrence_Of
(Tag_Typ
, Loc
));
9527 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
9528 N_Access_Definition
);
9529 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
9530 New_Occurrence_Of
(Tag_Typ
, Loc
));
9534 Append
(New_Param_Spec
, Formal_List
);
9536 Next_Formal
(Formal
);
9540 Append_To
(Decl_List
,
9541 Make_Subprogram_Declaration
(Loc
,
9542 Make_Procedure_Specification
(Loc
,
9543 Defining_Unit_Name
=>
9544 Make_Defining_Identifier
(Loc
, Chars
(Subp
)),
9545 Parameter_Specifications
=> Formal_List
,
9546 Null_Present
=> True)));
9549 Next_Elmt
(Prim_Elmt
);
9553 end Make_Null_Procedure_Specs
;
9555 -------------------------------------
9556 -- Make_Predefined_Primitive_Specs --
9557 -------------------------------------
9559 procedure Make_Predefined_Primitive_Specs
9560 (Tag_Typ
: Entity_Id
;
9561 Predef_List
: out List_Id
;
9562 Renamed_Eq
: out Entity_Id
)
9564 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
9565 -- Returns true if Prim is a renaming of an unresolved predefined
9566 -- equality operation.
9568 -------------------------------
9569 -- Is_Predefined_Eq_Renaming --
9570 -------------------------------
9572 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
9574 return Chars
(Prim
) /= Name_Op_Eq
9575 and then Present
(Alias
(Prim
))
9576 and then Comes_From_Source
(Prim
)
9577 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9578 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
9579 end Is_Predefined_Eq_Renaming
;
9583 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9584 Res
: constant List_Id
:= New_List
;
9585 Eq_Name
: Name_Id
:= Name_Op_Eq
;
9586 Eq_Needed
: Boolean;
9590 Has_Predef_Eq_Renaming
: Boolean := False;
9591 -- Set to True if Tag_Typ has a primitive that renames the predefined
9592 -- equality operator. Used to implement (RM 8-5-4(8)).
9594 -- Start of processing for Make_Predefined_Primitive_Specs
9597 Renamed_Eq
:= Empty
;
9601 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9604 Profile
=> New_List
(
9605 Make_Parameter_Specification
(Loc
,
9606 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9607 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9609 Ret_Type
=> Standard_Long_Long_Integer
));
9611 -- Specs for dispatching stream attributes
9614 Stream_Op_TSS_Names
:
9615 constant array (Integer range <>) of TSS_Name_Type
:=
9622 for Op
in Stream_Op_TSS_Names
'Range loop
9623 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
9625 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
9626 Stream_Op_TSS_Names
(Op
)));
9631 -- Spec of "=" is expanded if the type is not limited and if a user
9632 -- defined "=" was not already declared for the non-full view of a
9633 -- private extension
9635 if not Is_Limited_Type
(Tag_Typ
) then
9637 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9638 while Present
(Prim
) loop
9640 -- If a primitive is encountered that renames the predefined
9641 -- equality operator before reaching any explicit equality
9642 -- primitive, then we still need to create a predefined equality
9643 -- function, because calls to it can occur via the renaming. A
9644 -- new name is created for the equality to avoid conflicting with
9645 -- any user-defined equality. (Note that this doesn't account for
9646 -- renamings of equality nested within subpackages???)
9648 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9649 Has_Predef_Eq_Renaming
:= True;
9650 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
9652 -- User-defined equality
9654 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
9655 if No
(Alias
(Node
(Prim
)))
9656 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
9657 N_Subprogram_Renaming_Declaration
9662 -- If the parent is not an interface type and has an abstract
9663 -- equality function, the inherited equality is abstract as
9664 -- well, and no body can be created for it.
9666 elsif not Is_Interface
(Etype
(Tag_Typ
))
9667 and then Present
(Alias
(Node
(Prim
)))
9668 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
9673 -- If the type has an equality function corresponding with
9674 -- a primitive defined in an interface type, the inherited
9675 -- equality is abstract as well, and no body can be created
9678 elsif Present
(Alias
(Node
(Prim
)))
9679 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
9682 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
9692 -- If a renaming of predefined equality was found but there was no
9693 -- user-defined equality (so Eq_Needed is still true), then set the
9694 -- name back to Name_Op_Eq. But in the case where a user-defined
9695 -- equality was located after such a renaming, then the predefined
9696 -- equality function is still needed, so Eq_Needed must be set back
9699 if Eq_Name
/= Name_Op_Eq
then
9701 Eq_Name
:= Name_Op_Eq
;
9708 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
9711 Profile
=> New_List
(
9712 Make_Parameter_Specification
(Loc
,
9713 Defining_Identifier
=>
9714 Make_Defining_Identifier
(Loc
, Name_X
),
9715 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9717 Make_Parameter_Specification
(Loc
,
9718 Defining_Identifier
=>
9719 Make_Defining_Identifier
(Loc
, Name_Y
),
9720 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9721 Ret_Type
=> Standard_Boolean
);
9722 Append_To
(Res
, Eq_Spec
);
9724 if Has_Predef_Eq_Renaming
then
9725 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
9727 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9728 while Present
(Prim
) loop
9730 -- Any renamings of equality that appeared before an
9731 -- overriding equality must be updated to refer to the
9732 -- entity for the predefined equality, otherwise calls via
9733 -- the renaming would get incorrectly resolved to call the
9734 -- user-defined equality function.
9736 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9737 Set_Alias
(Node
(Prim
), Renamed_Eq
);
9739 -- Exit upon encountering a user-defined equality
9741 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
9742 and then No
(Alias
(Node
(Prim
)))
9752 -- Spec for dispatching assignment
9754 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9756 Name
=> Name_uAssign
,
9757 Profile
=> New_List
(
9758 Make_Parameter_Specification
(Loc
,
9759 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9760 Out_Present
=> True,
9761 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9763 Make_Parameter_Specification
(Loc
,
9764 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
9765 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
9768 -- Ada 2005: Generate declarations for the following primitive
9769 -- operations for limited interfaces and synchronized types that
9770 -- implement a limited interface.
9772 -- Disp_Asynchronous_Select
9773 -- Disp_Conditional_Select
9774 -- Disp_Get_Prim_Op_Kind
9777 -- Disp_Timed_Select
9779 -- Disable the generation of these bodies if No_Dispatching_Calls,
9780 -- Ravenscar or ZFP is active.
9782 if Ada_Version
>= Ada_2005
9783 and then not Restriction_Active
(No_Dispatching_Calls
)
9784 and then not Restriction_Active
(No_Select_Statements
)
9785 and then RTE_Available
(RE_Select_Specific_Data
)
9787 -- These primitives are defined abstract in interface types
9789 if Is_Interface
(Tag_Typ
)
9790 and then Is_Limited_Record
(Tag_Typ
)
9793 Make_Abstract_Subprogram_Declaration
(Loc
,
9795 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9798 Make_Abstract_Subprogram_Declaration
(Loc
,
9800 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9803 Make_Abstract_Subprogram_Declaration
(Loc
,
9805 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9808 Make_Abstract_Subprogram_Declaration
(Loc
,
9810 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9813 Make_Abstract_Subprogram_Declaration
(Loc
,
9815 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9818 Make_Abstract_Subprogram_Declaration
(Loc
,
9820 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9822 -- If ancestor is an interface type, declare non-abstract primitives
9823 -- to override the abstract primitives of the interface type.
9825 -- In VM targets we define these primitives in all root tagged types
9826 -- that are not interface types. Done because in VM targets we don't
9827 -- have secondary dispatch tables and any derivation of Tag_Typ may
9828 -- cover limited interfaces (which always have these primitives since
9829 -- they may be ancestors of synchronized interface types).
9831 elsif (not Is_Interface
(Tag_Typ
)
9832 and then Is_Interface
(Etype
(Tag_Typ
))
9833 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
9835 (Is_Concurrent_Record_Type
(Tag_Typ
)
9836 and then Has_Interfaces
(Tag_Typ
))
9838 (not Tagged_Type_Expansion
9839 and then not Is_Interface
(Tag_Typ
)
9840 and then Tag_Typ
= Root_Type
(Tag_Typ
))
9843 Make_Subprogram_Declaration
(Loc
,
9845 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9848 Make_Subprogram_Declaration
(Loc
,
9850 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9853 Make_Subprogram_Declaration
(Loc
,
9855 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9858 Make_Subprogram_Declaration
(Loc
,
9860 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9863 Make_Subprogram_Declaration
(Loc
,
9865 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9868 Make_Subprogram_Declaration
(Loc
,
9870 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9874 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
9875 -- regardless of whether they are controlled or may contain controlled
9878 -- Do not generate the routines if finalization is disabled
9880 if Restriction_Active
(No_Finalization
) then
9883 -- Finalization is not available for CIL value types
9885 elsif Is_Value_Type
(Tag_Typ
) then
9889 if not Is_Limited_Type
(Tag_Typ
) then
9890 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
9893 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
9897 end Make_Predefined_Primitive_Specs
;
9899 -------------------------
9900 -- Make_Tag_Assignment --
9901 -------------------------
9903 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
9904 Loc
: constant Source_Ptr
:= Sloc
(N
);
9905 Def_If
: constant Entity_Id
:= Defining_Identifier
(N
);
9906 Expr
: constant Node_Id
:= Expression
(N
);
9907 Typ
: constant Entity_Id
:= Etype
(Def_If
);
9908 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
9912 -- This expansion activity is called during analysis, but cannot
9913 -- be applied in ASIS mode when other expansion is disabled.
9915 if Is_Tagged_Type
(Typ
)
9916 and then not Is_Class_Wide_Type
(Typ
)
9917 and then not Is_CPP_Class
(Typ
)
9918 and then Tagged_Type_Expansion
9919 and then Nkind
(Expr
) /= N_Aggregate
9920 and then not ASIS_Mode
9921 and then (Nkind
(Expr
) /= N_Qualified_Expression
9922 or else Nkind
(Expression
(Expr
)) /= N_Aggregate
)
9925 Make_Selected_Component
(Loc
,
9926 Prefix
=> New_Occurrence_Of
(Def_If
, Loc
),
9928 New_Occurrence_Of
(First_Tag_Component
(Full_Typ
), Loc
));
9929 Set_Assignment_OK
(New_Ref
);
9932 Make_Assignment_Statement
(Loc
,
9935 Unchecked_Convert_To
(RTE
(RE_Tag
),
9936 New_Occurrence_Of
(Node
9937 (First_Elmt
(Access_Disp_Table
(Full_Typ
))), Loc
)));
9941 end Make_Tag_Assignment
;
9943 ---------------------------------
9944 -- Needs_Simple_Initialization --
9945 ---------------------------------
9947 function Needs_Simple_Initialization
9949 Consider_IS
: Boolean := True) return Boolean
9951 Consider_IS_NS
: constant Boolean :=
9952 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
9955 -- Never need initialization if it is suppressed
9957 if Initialization_Suppressed
(T
) then
9961 -- Check for private type, in which case test applies to the underlying
9962 -- type of the private type.
9964 if Is_Private_Type
(T
) then
9966 RT
: constant Entity_Id
:= Underlying_Type
(T
);
9968 if Present
(RT
) then
9969 return Needs_Simple_Initialization
(RT
);
9975 -- Scalar type with Default_Value aspect requires initialization
9977 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
9980 -- Cases needing simple initialization are access types, and, if pragma
9981 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
9984 elsif Is_Access_Type
(T
)
9985 or else (Consider_IS_NS
and then (Is_Scalar_Type
(T
)))
9989 -- If Initialize/Normalize_Scalars is in effect, string objects also
9990 -- need initialization, unless they are created in the course of
9991 -- expanding an aggregate (since in the latter case they will be
9992 -- filled with appropriate initializing values before they are used).
9994 elsif Consider_IS_NS
9995 and then Is_Standard_String_Type
(T
)
9998 or else Nkind
(Associated_Node_For_Itype
(T
)) /= N_Aggregate
)
10005 end Needs_Simple_Initialization
;
10007 ----------------------
10008 -- Predef_Deep_Spec --
10009 ----------------------
10011 function Predef_Deep_Spec
10013 Tag_Typ
: Entity_Id
;
10014 Name
: TSS_Name_Type
;
10015 For_Body
: Boolean := False) return Node_Id
10020 -- V : in out Tag_Typ
10022 Formals
:= New_List
(
10023 Make_Parameter_Specification
(Loc
,
10024 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
10025 In_Present
=> True,
10026 Out_Present
=> True,
10027 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
10029 -- F : Boolean := True
10031 if Name
= TSS_Deep_Adjust
10032 or else Name
= TSS_Deep_Finalize
10034 Append_To
(Formals
,
10035 Make_Parameter_Specification
(Loc
,
10036 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
10037 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
10038 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10042 Predef_Spec_Or_Body
(Loc
,
10043 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10044 Tag_Typ
=> Tag_Typ
,
10045 Profile
=> Formals
,
10046 For_Body
=> For_Body
);
10049 when RE_Not_Available
=>
10051 end Predef_Deep_Spec
;
10053 -------------------------
10054 -- Predef_Spec_Or_Body --
10055 -------------------------
10057 function Predef_Spec_Or_Body
10059 Tag_Typ
: Entity_Id
;
10062 Ret_Type
: Entity_Id
:= Empty
;
10063 For_Body
: Boolean := False) return Node_Id
10065 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
10069 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
10071 -- The internal flag is set to mark these declarations because they have
10072 -- specific properties. First, they are primitives even if they are not
10073 -- defined in the type scope (the freezing point is not necessarily in
10074 -- the same scope). Second, the predefined equality can be overridden by
10075 -- a user-defined equality, no body will be generated in this case.
10077 Set_Is_Internal
(Id
);
10079 if not Debug_Generated_Code
then
10080 Set_Debug_Info_Off
(Id
);
10083 if No
(Ret_Type
) then
10085 Make_Procedure_Specification
(Loc
,
10086 Defining_Unit_Name
=> Id
,
10087 Parameter_Specifications
=> Profile
);
10090 Make_Function_Specification
(Loc
,
10091 Defining_Unit_Name
=> Id
,
10092 Parameter_Specifications
=> Profile
,
10093 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
10096 if Is_Interface
(Tag_Typ
) then
10097 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10099 -- If body case, return empty subprogram body. Note that this is ill-
10100 -- formed, because there is not even a null statement, and certainly not
10101 -- a return in the function case. The caller is expected to do surgery
10102 -- on the body to add the appropriate stuff.
10104 elsif For_Body
then
10105 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
10107 -- For the case of an Input attribute predefined for an abstract type,
10108 -- generate an abstract specification. This will never be called, but we
10109 -- need the slot allocated in the dispatching table so that attributes
10110 -- typ'Class'Input and typ'Class'Output will work properly.
10112 elsif Is_TSS
(Name
, TSS_Stream_Input
)
10113 and then Is_Abstract_Type
(Tag_Typ
)
10115 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
10117 -- Normal spec case, where we return a subprogram declaration
10120 return Make_Subprogram_Declaration
(Loc
, Spec
);
10122 end Predef_Spec_Or_Body
;
10124 -----------------------------
10125 -- Predef_Stream_Attr_Spec --
10126 -----------------------------
10128 function Predef_Stream_Attr_Spec
10130 Tag_Typ
: Entity_Id
;
10131 Name
: TSS_Name_Type
;
10132 For_Body
: Boolean := False) return Node_Id
10134 Ret_Type
: Entity_Id
;
10137 if Name
= TSS_Stream_Input
then
10138 Ret_Type
:= Tag_Typ
;
10144 Predef_Spec_Or_Body
10146 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
10147 Tag_Typ
=> Tag_Typ
,
10148 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
10149 Ret_Type
=> Ret_Type
,
10150 For_Body
=> For_Body
);
10151 end Predef_Stream_Attr_Spec
;
10153 ---------------------------------
10154 -- Predefined_Primitive_Bodies --
10155 ---------------------------------
10157 function Predefined_Primitive_Bodies
10158 (Tag_Typ
: Entity_Id
;
10159 Renamed_Eq
: Entity_Id
) return List_Id
10161 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
10162 Res
: constant List_Id
:= New_List
;
10165 Eq_Needed
: Boolean;
10169 pragma Warnings
(Off
, Ent
);
10172 pragma Assert
(not Is_Interface
(Tag_Typ
));
10174 -- See if we have a predefined "=" operator
10176 if Present
(Renamed_Eq
) then
10178 Eq_Name
:= Chars
(Renamed_Eq
);
10180 -- If the parent is an interface type then it has defined all the
10181 -- predefined primitives abstract and we need to check if the type
10182 -- has some user defined "=" function which matches the profile of
10183 -- the Ada predefined equality operator to avoid generating it.
10185 elsif Is_Interface
(Etype
(Tag_Typ
)) then
10187 Eq_Name
:= Name_Op_Eq
;
10189 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10190 while Present
(Prim
) loop
10191 if Chars
(Node
(Prim
)) = Name_Op_Eq
10192 and then not Is_Internal
(Node
(Prim
))
10193 and then Present
(First_Entity
(Node
(Prim
)))
10195 -- The predefined equality primitive must have exactly two
10196 -- formals whose type is this tagged type
10198 and then Present
(Last_Entity
(Node
(Prim
)))
10199 and then Next_Entity
(First_Entity
(Node
(Prim
)))
10200 = Last_Entity
(Node
(Prim
))
10201 and then Etype
(First_Entity
(Node
(Prim
))) = Tag_Typ
10202 and then Etype
(Last_Entity
(Node
(Prim
))) = Tag_Typ
10204 Eq_Needed
:= False;
10205 Eq_Name
:= No_Name
;
10213 Eq_Needed
:= False;
10214 Eq_Name
:= No_Name
;
10216 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10217 while Present
(Prim
) loop
10218 if Chars
(Node
(Prim
)) = Name_Op_Eq
10219 and then Is_Internal
(Node
(Prim
))
10222 Eq_Name
:= Name_Op_Eq
;
10232 Decl
:= Predef_Spec_Or_Body
(Loc
,
10233 Tag_Typ
=> Tag_Typ
,
10234 Name
=> Name_uSize
,
10235 Profile
=> New_List
(
10236 Make_Parameter_Specification
(Loc
,
10237 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10238 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10240 Ret_Type
=> Standard_Long_Long_Integer
,
10243 Set_Handled_Statement_Sequence
(Decl
,
10244 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10245 Make_Simple_Return_Statement
(Loc
,
10247 Make_Attribute_Reference
(Loc
,
10248 Prefix
=> Make_Identifier
(Loc
, Name_X
),
10249 Attribute_Name
=> Name_Size
)))));
10251 Append_To
(Res
, Decl
);
10253 -- Bodies for Dispatching stream IO routines. We need these only for
10254 -- non-limited types (in the limited case there is no dispatching).
10255 -- We also skip them if dispatching or finalization are not available
10256 -- or if stream operations are prohibited by restriction No_Streams or
10257 -- from use of pragma/aspect No_Tagged_Streams.
10259 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
10260 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
10262 Build_Record_Read_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10263 Append_To
(Res
, Decl
);
10266 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
10267 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
10269 Build_Record_Write_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10270 Append_To
(Res
, Decl
);
10273 -- Skip body of _Input for the abstract case, since the corresponding
10274 -- spec is abstract (see Predef_Spec_Or_Body).
10276 if not Is_Abstract_Type
(Tag_Typ
)
10277 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
10278 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
10280 Build_Record_Or_Elementary_Input_Function
10281 (Loc
, Tag_Typ
, Decl
, Ent
);
10282 Append_To
(Res
, Decl
);
10285 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
10286 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
10288 Build_Record_Or_Elementary_Output_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10289 Append_To
(Res
, Decl
);
10292 -- Ada 2005: Generate bodies for the following primitive operations for
10293 -- limited interfaces and synchronized types that implement a limited
10296 -- disp_asynchronous_select
10297 -- disp_conditional_select
10298 -- disp_get_prim_op_kind
10299 -- disp_get_task_id
10300 -- disp_timed_select
10302 -- The interface versions will have null bodies
10304 -- Disable the generation of these bodies if No_Dispatching_Calls,
10305 -- Ravenscar or ZFP is active.
10307 -- In VM targets we define these primitives in all root tagged types
10308 -- that are not interface types. Done because in VM targets we don't
10309 -- have secondary dispatch tables and any derivation of Tag_Typ may
10310 -- cover limited interfaces (which always have these primitives since
10311 -- they may be ancestors of synchronized interface types).
10313 if Ada_Version
>= Ada_2005
10314 and then not Is_Interface
(Tag_Typ
)
10316 ((Is_Interface
(Etype
(Tag_Typ
))
10317 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10319 (Is_Concurrent_Record_Type
(Tag_Typ
)
10320 and then Has_Interfaces
(Tag_Typ
))
10322 (not Tagged_Type_Expansion
10323 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
10324 and then not Restriction_Active
(No_Dispatching_Calls
)
10325 and then not Restriction_Active
(No_Select_Statements
)
10326 and then RTE_Available
(RE_Select_Specific_Data
)
10328 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
10329 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
10330 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
10331 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
10332 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
10333 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
10336 if not Is_Limited_Type
(Tag_Typ
) and then not Is_Interface
(Tag_Typ
) then
10338 -- Body for equality
10341 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
10342 Append_To
(Res
, Decl
);
10345 -- Body for inequality (if required)
10347 Decl
:= Make_Neq_Body
(Tag_Typ
);
10349 if Present
(Decl
) then
10350 Append_To
(Res
, Decl
);
10353 -- Body for dispatching assignment
10356 Predef_Spec_Or_Body
(Loc
,
10357 Tag_Typ
=> Tag_Typ
,
10358 Name
=> Name_uAssign
,
10359 Profile
=> New_List
(
10360 Make_Parameter_Specification
(Loc
,
10361 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10362 Out_Present
=> True,
10363 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
10365 Make_Parameter_Specification
(Loc
,
10366 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
10367 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10370 Set_Handled_Statement_Sequence
(Decl
,
10371 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10372 Make_Assignment_Statement
(Loc
,
10373 Name
=> Make_Identifier
(Loc
, Name_X
),
10374 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
10376 Append_To
(Res
, Decl
);
10379 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
10380 -- tagged types which do not contain controlled components.
10382 -- Do not generate the routines if finalization is disabled
10384 if Restriction_Active
(No_Finalization
) then
10387 elsif not Has_Controlled_Component
(Tag_Typ
) then
10388 if not Is_Limited_Type
(Tag_Typ
) then
10389 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
10391 if Is_Controlled
(Tag_Typ
) then
10392 Set_Handled_Statement_Sequence
(Decl
,
10393 Make_Handled_Sequence_Of_Statements
(Loc
,
10394 Statements
=> New_List
(
10396 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10397 Typ
=> Tag_Typ
))));
10400 Set_Handled_Statement_Sequence
(Decl
,
10401 Make_Handled_Sequence_Of_Statements
(Loc
,
10402 Statements
=> New_List
(
10403 Make_Null_Statement
(Loc
))));
10406 Append_To
(Res
, Decl
);
10409 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
10411 if Is_Controlled
(Tag_Typ
) then
10412 Set_Handled_Statement_Sequence
(Decl
,
10413 Make_Handled_Sequence_Of_Statements
(Loc
,
10414 Statements
=> New_List
(
10416 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10417 Typ
=> Tag_Typ
))));
10420 Set_Handled_Statement_Sequence
(Decl
,
10421 Make_Handled_Sequence_Of_Statements
(Loc
,
10422 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
10425 Append_To
(Res
, Decl
);
10429 end Predefined_Primitive_Bodies
;
10431 ---------------------------------
10432 -- Predefined_Primitive_Freeze --
10433 ---------------------------------
10435 function Predefined_Primitive_Freeze
10436 (Tag_Typ
: Entity_Id
) return List_Id
10438 Res
: constant List_Id
:= New_List
;
10443 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10444 while Present
(Prim
) loop
10445 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
10446 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
10448 if Present
(Frnodes
) then
10449 Append_List_To
(Res
, Frnodes
);
10457 end Predefined_Primitive_Freeze
;
10459 -------------------------
10460 -- Stream_Operation_OK --
10461 -------------------------
10463 function Stream_Operation_OK
10465 Operation
: TSS_Name_Type
) return Boolean
10467 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
10470 -- Special case of a limited type extension: a default implementation
10471 -- of the stream attributes Read or Write exists if that attribute
10472 -- has been specified or is available for an ancestor type; a default
10473 -- implementation of the attribute Output (resp. Input) exists if the
10474 -- attribute has been specified or Write (resp. Read) is available for
10475 -- an ancestor type. The last condition only applies under Ada 2005.
10477 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
10478 if Operation
= TSS_Stream_Read
then
10479 Has_Predefined_Or_Specified_Stream_Attribute
:=
10480 Has_Specified_Stream_Read
(Typ
);
10482 elsif Operation
= TSS_Stream_Write
then
10483 Has_Predefined_Or_Specified_Stream_Attribute
:=
10484 Has_Specified_Stream_Write
(Typ
);
10486 elsif Operation
= TSS_Stream_Input
then
10487 Has_Predefined_Or_Specified_Stream_Attribute
:=
10488 Has_Specified_Stream_Input
(Typ
)
10490 (Ada_Version
>= Ada_2005
10491 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
10493 elsif Operation
= TSS_Stream_Output
then
10494 Has_Predefined_Or_Specified_Stream_Attribute
:=
10495 Has_Specified_Stream_Output
(Typ
)
10497 (Ada_Version
>= Ada_2005
10498 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
10501 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
10503 if not Has_Predefined_Or_Specified_Stream_Attribute
10504 and then Is_Derived_Type
(Typ
)
10505 and then (Operation
= TSS_Stream_Read
10506 or else Operation
= TSS_Stream_Write
)
10508 Has_Predefined_Or_Specified_Stream_Attribute
:=
10510 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
10514 -- If the type is not limited, or else is limited but the attribute is
10515 -- explicitly specified or is predefined for the type, then return True,
10516 -- unless other conditions prevail, such as restrictions prohibiting
10517 -- streams or dispatching operations. We also return True for limited
10518 -- interfaces, because they may be extended by nonlimited types and
10519 -- permit inheritance in this case (addresses cases where an abstract
10520 -- extension doesn't get 'Input declared, as per comments below, but
10521 -- 'Class'Input must still be allowed). Note that attempts to apply
10522 -- stream attributes to a limited interface or its class-wide type
10523 -- (or limited extensions thereof) will still get properly rejected
10524 -- by Check_Stream_Attribute.
10526 -- We exclude the Input operation from being a predefined subprogram in
10527 -- the case where the associated type is an abstract extension, because
10528 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
10529 -- we don't want an abstract version created because types derived from
10530 -- the abstract type may not even have Input available (for example if
10531 -- derived from a private view of the abstract type that doesn't have
10532 -- a visible Input), but a VM such as .NET or the Java VM can treat the
10533 -- operation as inherited anyway, and we don't want an abstract function
10534 -- to be (implicitly) inherited in that case because it can lead to a VM
10537 -- Do not generate stream routines for type Finalization_Master because
10538 -- a master may never appear in types and therefore cannot be read or
10542 (not Is_Limited_Type
(Typ
)
10543 or else Is_Interface
(Typ
)
10544 or else Has_Predefined_Or_Specified_Stream_Attribute
)
10546 (Operation
/= TSS_Stream_Input
10547 or else not Is_Abstract_Type
(Typ
)
10548 or else not Is_Derived_Type
(Typ
))
10549 and then not Has_Unknown_Discriminants
(Typ
)
10551 (Is_Interface
(Typ
)
10553 (Is_Task_Interface
(Typ
)
10554 or else Is_Protected_Interface
(Typ
)
10555 or else Is_Synchronized_Interface
(Typ
)))
10556 and then not Restriction_Active
(No_Streams
)
10557 and then not Restriction_Active
(No_Dispatch
)
10558 and then No
(No_Tagged_Streams_Pragma
(Typ
))
10559 and then not No_Run_Time_Mode
10560 and then RTE_Available
(RE_Tag
)
10561 and then No
(Type_Without_Stream_Operation
(Typ
))
10562 and then RTE_Available
(RE_Root_Stream_Type
)
10563 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
10564 end Stream_Operation_OK
;