1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean;
230 -- Returns true if the initialization procedure of Typ should be inlined
232 function In_Runtime
(E
: Entity_Id
) return Boolean;
233 -- Check if E is defined in the RTL (in a child of Ada or System). Used
234 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
236 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean;
237 -- Returns true if Prim is a user defined equality function
239 function Make_Eq_Body
241 Eq_Name
: Name_Id
) return Node_Id
;
242 -- Build the body of a primitive equality operation for a tagged record
243 -- type, or in Ada 2012 for any record type that has components with a
244 -- user-defined equality. Factored out of Predefined_Primitive_Bodies.
246 function Make_Eq_Case
249 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
;
250 -- Building block for variant record equality. Defined to share the code
251 -- between the tagged and untagged case. Given a Component_List node CL,
252 -- it generates an 'if' followed by a 'case' statement that compares all
253 -- components of local temporaries named X and Y (that are declared as
254 -- formals at some upper level). E provides the Sloc to be used for the
257 -- IF E is an unchecked_union, Discrs is the list of formals created for
258 -- the inferred discriminants of one operand. These formals are used in
259 -- the generated case statements for each variant of the unchecked union.
263 L
: List_Id
) return Node_Id
;
264 -- Building block for variant record equality. Defined to share the code
265 -- between the tagged and untagged case. Given the list of components
266 -- (or discriminants) L, it generates a return statement that compares all
267 -- components of local temporaries named X and Y (that are declared as
268 -- formals at some upper level). E provides the Sloc to be used for the
271 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
;
272 -- Search for a renaming of the inequality dispatching primitive of
273 -- this tagged type. If found then build and return the corresponding
274 -- rename-as-body inequality subprogram; otherwise return Empty.
276 procedure Make_Predefined_Primitive_Specs
277 (Tag_Typ
: Entity_Id
;
278 Predef_List
: out List_Id
;
279 Renamed_Eq
: out Entity_Id
);
280 -- Create a list with the specs of the predefined primitive operations.
281 -- For tagged types that are interfaces all these primitives are defined
284 -- The following entries are present for all tagged types, and provide
285 -- the results of the corresponding attribute applied to the object.
286 -- Dispatching is required in general, since the result of the attribute
287 -- will vary with the actual object subtype.
289 -- _size provides result of 'Size attribute
290 -- typSR provides result of 'Read attribute
291 -- typSW provides result of 'Write attribute
292 -- typSI provides result of 'Input attribute
293 -- typSO provides result of 'Output attribute
295 -- The following entries are additionally present for non-limited tagged
296 -- types, and implement additional dispatching operations for predefined
299 -- _equality implements "=" operator
300 -- _assign implements assignment operation
301 -- typDF implements deep finalization
302 -- typDA implements deep adjust
304 -- The latter two are empty procedures unless the type contains some
305 -- controlled components that require finalization actions (the deep
306 -- in the name refers to the fact that the action applies to components).
308 -- The list is returned in Predef_List. The Parameter Renamed_Eq either
309 -- returns the value Empty, or else the defining unit name for the
310 -- predefined equality function in the case where the type has a primitive
311 -- operation that is a renaming of predefined equality (but only if there
312 -- is also an overriding user-defined equality function). The returned
313 -- Renamed_Eq will be passed to the corresponding parameter of
314 -- Predefined_Primitive_Bodies.
316 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean;
317 -- Returns True if there are representation clauses for type T that are not
318 -- inherited. If the result is false, the init_proc and the discriminant
319 -- checking functions of the parent can be reused by a derived type.
321 procedure Make_Controlling_Function_Wrappers
322 (Tag_Typ
: Entity_Id
;
323 Decl_List
: out List_Id
;
324 Body_List
: out List_Id
);
325 -- Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
326 -- associated with inherited functions with controlling results which
327 -- are not overridden. The body of each wrapper function consists solely
328 -- of a return statement whose expression is an extension aggregate
329 -- invoking the inherited subprogram's parent subprogram and extended
330 -- with a null association list.
332 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
;
333 -- Ada 2005 (AI-251): Makes specs for null procedures associated with any
334 -- null procedures inherited from an interface type that have not been
335 -- overridden. Only one null procedure will be created for a given set of
336 -- inherited null procedures with homographic profiles.
338 function Predef_Spec_Or_Body
343 Ret_Type
: Entity_Id
:= Empty
;
344 For_Body
: Boolean := False) return Node_Id
;
345 -- This function generates the appropriate expansion for a predefined
346 -- primitive operation specified by its name, parameter profile and
347 -- return type (Empty means this is a procedure). If For_Body is false,
348 -- then the returned node is a subprogram declaration. If For_Body is
349 -- true, then the returned node is a empty subprogram body containing
350 -- no declarations and no statements.
352 function Predef_Stream_Attr_Spec
355 Name
: TSS_Name_Type
;
356 For_Body
: Boolean := False) return Node_Id
;
357 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
358 -- input and output attribute whose specs are constructed in Exp_Strm.
360 function Predef_Deep_Spec
363 Name
: TSS_Name_Type
;
364 For_Body
: Boolean := False) return Node_Id
;
365 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
366 -- and _deep_finalize
368 function Predefined_Primitive_Bodies
369 (Tag_Typ
: Entity_Id
;
370 Renamed_Eq
: Entity_Id
) return List_Id
;
371 -- Create the bodies of the predefined primitives that are described in
372 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
373 -- the defining unit name of the type's predefined equality as returned
374 -- by Make_Predefined_Primitive_Specs.
376 function Predefined_Primitive_Freeze
(Tag_Typ
: Entity_Id
) return List_Id
;
377 -- Freeze entities of all predefined primitive operations. This is needed
378 -- because the bodies of these operations do not normally do any freezing.
380 function Stream_Operation_OK
382 Operation
: TSS_Name_Type
) return Boolean;
383 -- Check whether the named stream operation must be emitted for a given
384 -- type. The rules for inheritance of stream attributes by type extensions
385 -- are enforced by this function. Furthermore, various restrictions prevent
386 -- the generation of these operations, as a useful optimization or for
387 -- certification purposes and to save unnecessary generated code.
389 --------------------------
390 -- Adjust_Discriminants --
391 --------------------------
393 -- This procedure attempts to define subtypes for discriminants that are
394 -- more restrictive than those declared. Such a replacement is possible if
395 -- we can demonstrate that values outside the restricted range would cause
396 -- constraint errors in any case. The advantage of restricting the
397 -- discriminant types in this way is that the maximum size of the variant
398 -- record can be calculated more conservatively.
400 -- An example of a situation in which we can perform this type of
401 -- restriction is the following:
403 -- subtype B is range 1 .. 10;
404 -- type Q is array (B range <>) of Integer;
406 -- type V (N : Natural) is record
410 -- In this situation, we can restrict the upper bound of N to 10, since
411 -- any larger value would cause a constraint error in any case.
413 -- There are many situations in which such restriction is possible, but
414 -- for now, we just look for cases like the above, where the component
415 -- in question is a one dimensional array whose upper bound is one of
416 -- the record discriminants. Also the component must not be part of
417 -- any variant part, since then the component does not always exist.
419 procedure Adjust_Discriminants
(Rtype
: Entity_Id
) is
420 Loc
: constant Source_Ptr
:= Sloc
(Rtype
);
437 Comp
:= First_Component
(Rtype
);
438 while Present
(Comp
) loop
440 -- If our parent is a variant, quit, we do not look at components
441 -- that are in variant parts, because they may not always exist.
443 P
:= Parent
(Comp
); -- component declaration
444 P
:= Parent
(P
); -- component list
446 exit when Nkind
(Parent
(P
)) = N_Variant
;
448 -- We are looking for a one dimensional array type
450 Ctyp
:= Etype
(Comp
);
452 if not Is_Array_Type
(Ctyp
) or else Number_Dimensions
(Ctyp
) > 1 then
456 -- The lower bound must be constant, and the upper bound is a
457 -- discriminant (which is a discriminant of the current record).
459 Ityp
:= Etype
(First_Index
(Ctyp
));
460 Lo
:= Type_Low_Bound
(Ityp
);
461 Hi
:= Type_High_Bound
(Ityp
);
463 if not Compile_Time_Known_Value
(Lo
)
464 or else Nkind
(Hi
) /= N_Identifier
465 or else No
(Entity
(Hi
))
466 or else Ekind
(Entity
(Hi
)) /= E_Discriminant
471 -- We have an array with appropriate bounds
473 Loval
:= Expr_Value
(Lo
);
474 Discr
:= Entity
(Hi
);
475 Dtyp
:= Etype
(Discr
);
477 -- See if the discriminant has a known upper bound
479 Dhi
:= Type_High_Bound
(Dtyp
);
481 if not Compile_Time_Known_Value
(Dhi
) then
485 Dhiv
:= Expr_Value
(Dhi
);
487 -- See if base type of component array has known upper bound
489 Ahi
:= Type_High_Bound
(Etype
(First_Index
(Base_Type
(Ctyp
))));
491 if not Compile_Time_Known_Value
(Ahi
) then
495 Ahiv
:= Expr_Value
(Ahi
);
497 -- The condition for doing the restriction is that the high bound
498 -- of the discriminant is greater than the low bound of the array,
499 -- and is also greater than the high bound of the base type index.
501 if Dhiv
> Loval
and then Dhiv
> Ahiv
then
503 -- We can reset the upper bound of the discriminant type to
504 -- whichever is larger, the low bound of the component, or
505 -- the high bound of the base type array index.
507 -- We build a subtype that is declared as
509 -- subtype Tnn is discr_type range discr_type'First .. max;
511 -- And insert this declaration into the tree. The type of the
512 -- discriminant is then reset to this more restricted subtype.
514 Tnn
:= Make_Temporary
(Loc
, 'T');
516 Insert_Action
(Declaration_Node
(Rtype
),
517 Make_Subtype_Declaration
(Loc
,
518 Defining_Identifier
=> Tnn
,
519 Subtype_Indication
=>
520 Make_Subtype_Indication
(Loc
,
521 Subtype_Mark
=> New_Occurrence_Of
(Dtyp
, Loc
),
523 Make_Range_Constraint
(Loc
,
527 Make_Attribute_Reference
(Loc
,
528 Attribute_Name
=> Name_First
,
529 Prefix
=> New_Occurrence_Of
(Dtyp
, Loc
)),
531 Make_Integer_Literal
(Loc
,
532 Intval
=> UI_Max
(Loval
, Ahiv
)))))));
534 Set_Etype
(Discr
, Tnn
);
538 Next_Component
(Comp
);
540 end Adjust_Discriminants
;
542 ---------------------------
543 -- Build_Array_Init_Proc --
544 ---------------------------
546 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
) is
547 Comp_Type
: constant Entity_Id
:= Component_Type
(A_Type
);
548 Body_Stmts
: List_Id
;
549 Has_Default_Init
: Boolean;
550 Index_List
: List_Id
;
554 function Init_Component
return List_Id
;
555 -- Create one statement to initialize one array component, designated
556 -- by a full set of indexes.
558 function Init_One_Dimension
(N
: Int
) return List_Id
;
559 -- Create loop to initialize one dimension of the array. The single
560 -- statement in the loop body initializes the inner dimensions if any,
561 -- or else the single component. Note that this procedure is called
562 -- recursively, with N being the dimension to be initialized. A call
563 -- with N greater than the number of dimensions simply generates the
564 -- component initialization, terminating the recursion.
570 function Init_Component
return List_Id
is
575 Make_Indexed_Component
(Loc
,
576 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
577 Expressions
=> Index_List
);
579 if Has_Default_Aspect
(A_Type
) then
580 Set_Assignment_OK
(Comp
);
582 Make_Assignment_Statement
(Loc
,
585 Convert_To
(Comp_Type
,
586 Default_Aspect_Component_Value
(First_Subtype
(A_Type
)))));
588 elsif Needs_Simple_Initialization
(Comp_Type
) then
589 Set_Assignment_OK
(Comp
);
591 Make_Assignment_Statement
(Loc
,
595 (Comp_Type
, Nod
, Component_Size
(A_Type
))));
598 Clean_Task_Names
(Comp_Type
, Proc_Id
);
600 Build_Initialization_Call
601 (Loc
, Comp
, Comp_Type
,
602 In_Init_Proc
=> True,
603 Enclos_Type
=> A_Type
);
607 ------------------------
608 -- Init_One_Dimension --
609 ------------------------
611 function Init_One_Dimension
(N
: Int
) return List_Id
is
615 -- If the component does not need initializing, then there is nothing
616 -- to do here, so we return a null body. This occurs when generating
617 -- the dummy Init_Proc needed for Initialize_Scalars processing.
619 if not Has_Non_Null_Base_Init_Proc
(Comp_Type
)
620 and then not Needs_Simple_Initialization
(Comp_Type
)
621 and then not Has_Task
(Comp_Type
)
622 and then not Has_Default_Aspect
(A_Type
)
624 return New_List
(Make_Null_Statement
(Loc
));
626 -- If all dimensions dealt with, we simply initialize the component
628 elsif N
> Number_Dimensions
(A_Type
) then
629 return Init_Component
;
631 -- Here we generate the required loop
635 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
637 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
640 Make_Implicit_Loop_Statement
(Nod
,
643 Make_Iteration_Scheme
(Loc
,
644 Loop_Parameter_Specification
=>
645 Make_Loop_Parameter_Specification
(Loc
,
646 Defining_Identifier
=> Index
,
647 Discrete_Subtype_Definition
=>
648 Make_Attribute_Reference
(Loc
,
650 Make_Identifier
(Loc
, Name_uInit
),
651 Attribute_Name
=> Name_Range
,
652 Expressions
=> New_List
(
653 Make_Integer_Literal
(Loc
, N
))))),
654 Statements
=> Init_One_Dimension
(N
+ 1)));
656 end Init_One_Dimension
;
658 -- Start of processing for Build_Array_Init_Proc
661 -- The init proc is created when analyzing the freeze node for the type,
662 -- but it properly belongs with the array type declaration. However, if
663 -- the freeze node is for a subtype of a type declared in another unit
664 -- it seems preferable to use the freeze node as the source location of
665 -- the init proc. In any case this is preferable for gcov usage, and
666 -- the Sloc is not otherwise used by the compiler.
668 if In_Open_Scopes
(Scope
(A_Type
)) then
669 Loc
:= Sloc
(A_Type
);
674 -- Nothing to generate in the following cases:
676 -- 1. Initialization is suppressed for the type
677 -- 2. An initialization already exists for the base type
679 if Initialization_Suppressed
(A_Type
)
680 or else Present
(Base_Init_Proc
(A_Type
))
685 Index_List
:= New_List
;
687 -- We need an initialization procedure if any of the following is true:
689 -- 1. The component type has an initialization procedure
690 -- 2. The component type needs simple initialization
691 -- 3. Tasks are present
692 -- 4. The type is marked as a public entity
693 -- 5. The array type has a Default_Component_Value aspect
695 -- The reason for the public entity test is to deal properly with the
696 -- Initialize_Scalars pragma. This pragma can be set in the client and
697 -- not in the declaring package, this means the client will make a call
698 -- to the initialization procedure (because one of conditions 1-3 must
699 -- apply in this case), and we must generate a procedure (even if it is
700 -- null) to satisfy the call in this case.
702 -- Exception: do not build an array init_proc for a type whose root
703 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
704 -- is no place to put the code, and in any case we handle initialization
705 -- of such types (in the Initialize_Scalars case, that's the only time
706 -- the issue arises) in a special manner anyway which does not need an
709 Has_Default_Init
:= Has_Non_Null_Base_Init_Proc
(Comp_Type
)
710 or else Needs_Simple_Initialization
(Comp_Type
)
711 or else Has_Task
(Comp_Type
)
712 or else Has_Default_Aspect
(A_Type
);
715 or else (not Restriction_Active
(No_Initialize_Scalars
)
716 and then Is_Public
(A_Type
)
717 and then not Is_Standard_String_Type
(A_Type
))
720 Make_Defining_Identifier
(Loc
,
721 Chars
=> Make_Init_Proc_Name
(A_Type
));
723 -- If No_Default_Initialization restriction is active, then we don't
724 -- want to build an init_proc, but we need to mark that an init_proc
725 -- would be needed if this restriction was not active (so that we can
726 -- detect attempts to call it), so set a dummy init_proc in place.
727 -- This is only done though when actual default initialization is
728 -- needed (and not done when only Is_Public is True), since otherwise
729 -- objects such as arrays of scalars could be wrongly flagged as
730 -- violating the restriction.
732 if Restriction_Active
(No_Default_Initialization
) then
733 if Has_Default_Init
then
734 Set_Init_Proc
(A_Type
, Proc_Id
);
740 Body_Stmts
:= Init_One_Dimension
(1);
743 Make_Subprogram_Body
(Loc
,
745 Make_Procedure_Specification
(Loc
,
746 Defining_Unit_Name
=> Proc_Id
,
747 Parameter_Specifications
=> Init_Formals
(A_Type
)),
748 Declarations
=> New_List
,
749 Handled_Statement_Sequence
=>
750 Make_Handled_Sequence_Of_Statements
(Loc
,
751 Statements
=> Body_Stmts
)));
753 Set_Ekind
(Proc_Id
, E_Procedure
);
754 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
755 Set_Is_Internal
(Proc_Id
);
756 Set_Has_Completion
(Proc_Id
);
758 if not Debug_Generated_Code
then
759 Set_Debug_Info_Off
(Proc_Id
);
762 -- Set Inlined on Init_Proc if it is set on the Init_Proc of the
763 -- component type itself (see also Build_Record_Init_Proc).
765 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Comp_Type
));
767 -- Associate Init_Proc with type, and determine if the procedure
768 -- is null (happens because of the Initialize_Scalars pragma case,
769 -- where we have to generate a null procedure in case it is called
770 -- by a client with Initialize_Scalars set). Such procedures have
771 -- to be generated, but do not have to be called, so we mark them
772 -- as null to suppress the call.
774 Set_Init_Proc
(A_Type
, Proc_Id
);
776 if List_Length
(Body_Stmts
) = 1
778 -- We must skip SCIL nodes because they may have been added to this
779 -- list by Insert_Actions.
781 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
783 Set_Is_Null_Init_Proc
(Proc_Id
);
786 -- Try to build a static aggregate to statically initialize
787 -- objects of the type. This can only be done for constrained
788 -- one-dimensional arrays with static bounds.
790 Set_Static_Initialization
792 Build_Equivalent_Array_Aggregate
(First_Subtype
(A_Type
)));
795 end Build_Array_Init_Proc
;
797 --------------------------------
798 -- Build_Array_Invariant_Proc --
799 --------------------------------
801 function Build_Array_Invariant_Proc
803 Nod
: Node_Id
) return Node_Id
805 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
807 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
808 -- Name for argument of invariant procedure
810 Object_Entity
: constant Node_Id
:=
811 Make_Defining_Identifier
(Loc
, Object_Name
);
812 -- The procedure declaration entity for the argument
814 Body_Stmts
: List_Id
;
815 Index_List
: List_Id
;
819 function Build_Component_Invariant_Call
return Node_Id
;
820 -- Create one statement to verify invariant on one array component,
821 -- designated by a full set of indexes.
823 function Check_One_Dimension
(N
: Int
) return List_Id
;
824 -- Create loop to check on one dimension of the array. The single
825 -- statement in the loop body checks the inner dimensions if any, or
826 -- else a single component. This procedure is called recursively, with
827 -- N being the dimension to be initialized. A call with N greater than
828 -- the number of dimensions generates the component initialization
829 -- and terminates the recursion.
831 ------------------------------------
832 -- Build_Component_Invariant_Call --
833 ------------------------------------
835 function Build_Component_Invariant_Call
return Node_Id
is
839 Make_Indexed_Component
(Loc
,
840 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
841 Expressions
=> Index_List
);
843 Make_Procedure_Call_Statement
(Loc
,
846 (Invariant_Procedure
(Component_Type
(A_Type
)), Loc
),
847 Parameter_Associations
=> New_List
(Comp
));
848 end Build_Component_Invariant_Call
;
850 -------------------------
851 -- Check_One_Dimension --
852 -------------------------
854 function Check_One_Dimension
(N
: Int
) return List_Id
is
858 -- If all dimensions dealt with, we simply check invariant of the
861 if N
> Number_Dimensions
(A_Type
) then
862 return New_List
(Build_Component_Invariant_Call
);
864 -- Else generate one loop and recurse
868 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
870 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
873 Make_Implicit_Loop_Statement
(Nod
,
876 Make_Iteration_Scheme
(Loc
,
877 Loop_Parameter_Specification
=>
878 Make_Loop_Parameter_Specification
(Loc
,
879 Defining_Identifier
=> Index
,
880 Discrete_Subtype_Definition
=>
881 Make_Attribute_Reference
(Loc
,
883 New_Occurrence_Of
(Object_Entity
, Loc
),
884 Attribute_Name
=> Name_Range
,
885 Expressions
=> New_List
(
886 Make_Integer_Literal
(Loc
, N
))))),
887 Statements
=> Check_One_Dimension
(N
+ 1)));
889 end Check_One_Dimension
;
891 -- Start of processing for Build_Array_Invariant_Proc
894 Index_List
:= New_List
;
897 Make_Defining_Identifier
(Loc
,
898 Chars
=> New_External_Name
(Chars
(A_Type
), "CInvariant"));
900 Body_Stmts
:= Check_One_Dimension
(1);
903 Make_Subprogram_Body
(Loc
,
905 Make_Procedure_Specification
(Loc
,
906 Defining_Unit_Name
=> Proc_Id
,
907 Parameter_Specifications
=> New_List
(
908 Make_Parameter_Specification
(Loc
,
909 Defining_Identifier
=> Object_Entity
,
910 Parameter_Type
=> New_Occurrence_Of
(A_Type
, Loc
)))),
912 Declarations
=> Empty_List
,
913 Handled_Statement_Sequence
=>
914 Make_Handled_Sequence_Of_Statements
(Loc
,
915 Statements
=> Body_Stmts
));
917 Set_Ekind
(Proc_Id
, E_Procedure
);
918 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
919 Set_Is_Internal
(Proc_Id
);
920 Set_Has_Completion
(Proc_Id
);
922 if not Debug_Generated_Code
then
923 Set_Debug_Info_Off
(Proc_Id
);
927 end Build_Array_Invariant_Proc
;
929 --------------------------------
930 -- Build_Discr_Checking_Funcs --
931 --------------------------------
933 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
) is
936 Enclosing_Func_Id
: Entity_Id
;
941 function Build_Case_Statement
942 (Case_Id
: Entity_Id
;
943 Variant
: Node_Id
) return Node_Id
;
944 -- Build a case statement containing only two alternatives. The first
945 -- alternative corresponds exactly to the discrete choices given on the
946 -- variant with contains the components that we are generating the
947 -- checks for. If the discriminant is one of these return False. The
948 -- second alternative is an OTHERS choice that will return True
949 -- indicating the discriminant did not match.
951 function Build_Dcheck_Function
952 (Case_Id
: Entity_Id
;
953 Variant
: Node_Id
) return Entity_Id
;
954 -- Build the discriminant checking function for a given variant
956 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
);
957 -- Builds the discriminant checking function for each variant of the
958 -- given variant part of the record type.
960 --------------------------
961 -- Build_Case_Statement --
962 --------------------------
964 function Build_Case_Statement
965 (Case_Id
: Entity_Id
;
966 Variant
: Node_Id
) return Node_Id
968 Alt_List
: constant List_Id
:= New_List
;
969 Actuals_List
: List_Id
;
971 Case_Alt_Node
: Node_Id
;
973 Choice_List
: List_Id
;
975 Return_Node
: Node_Id
;
978 Case_Node
:= New_Node
(N_Case_Statement
, Loc
);
980 -- Replace the discriminant which controls the variant with the name
981 -- of the formal of the checking function.
983 Set_Expression
(Case_Node
, Make_Identifier
(Loc
, Chars
(Case_Id
)));
985 Choice
:= First
(Discrete_Choices
(Variant
));
987 if Nkind
(Choice
) = N_Others_Choice
then
988 Choice_List
:= New_Copy_List
(Others_Discrete_Choices
(Choice
));
990 Choice_List
:= New_Copy_List
(Discrete_Choices
(Variant
));
993 if not Is_Empty_List
(Choice_List
) then
994 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
995 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
997 -- In case this is a nested variant, we need to return the result
998 -- of the discriminant checking function for the immediately
999 -- enclosing variant.
1001 if Present
(Enclosing_Func_Id
) then
1002 Actuals_List
:= New_List
;
1004 D
:= First_Discriminant
(Rec_Id
);
1005 while Present
(D
) loop
1006 Append
(Make_Identifier
(Loc
, Chars
(D
)), Actuals_List
);
1007 Next_Discriminant
(D
);
1011 Make_Simple_Return_Statement
(Loc
,
1013 Make_Function_Call
(Loc
,
1015 New_Occurrence_Of
(Enclosing_Func_Id
, Loc
),
1016 Parameter_Associations
=>
1021 Make_Simple_Return_Statement
(Loc
,
1023 New_Occurrence_Of
(Standard_False
, Loc
));
1026 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1027 Append
(Case_Alt_Node
, Alt_List
);
1030 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1031 Choice_List
:= New_List
(New_Node
(N_Others_Choice
, Loc
));
1032 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1035 Make_Simple_Return_Statement
(Loc
,
1037 New_Occurrence_Of
(Standard_True
, Loc
));
1039 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1040 Append
(Case_Alt_Node
, Alt_List
);
1042 Set_Alternatives
(Case_Node
, Alt_List
);
1044 end Build_Case_Statement
;
1046 ---------------------------
1047 -- Build_Dcheck_Function --
1048 ---------------------------
1050 function Build_Dcheck_Function
1051 (Case_Id
: Entity_Id
;
1052 Variant
: Node_Id
) return Entity_Id
1054 Body_Node
: Node_Id
;
1055 Func_Id
: Entity_Id
;
1056 Parameter_List
: List_Id
;
1057 Spec_Node
: Node_Id
;
1060 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
1061 Sequence
:= Sequence
+ 1;
1064 Make_Defining_Identifier
(Loc
,
1065 Chars
=> New_External_Name
(Chars
(Rec_Id
), 'D', Sequence
));
1066 Set_Is_Discriminant_Check_Function
(Func_Id
);
1068 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
1069 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
1071 Parameter_List
:= Build_Discriminant_Formals
(Rec_Id
, False);
1073 Set_Parameter_Specifications
(Spec_Node
, Parameter_List
);
1074 Set_Result_Definition
(Spec_Node
,
1075 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1076 Set_Specification
(Body_Node
, Spec_Node
);
1077 Set_Declarations
(Body_Node
, New_List
);
1079 Set_Handled_Statement_Sequence
(Body_Node
,
1080 Make_Handled_Sequence_Of_Statements
(Loc
,
1081 Statements
=> New_List
(
1082 Build_Case_Statement
(Case_Id
, Variant
))));
1084 Set_Ekind
(Func_Id
, E_Function
);
1085 Set_Mechanism
(Func_Id
, Default_Mechanism
);
1086 Set_Is_Inlined
(Func_Id
, True);
1087 Set_Is_Pure
(Func_Id
, True);
1088 Set_Is_Public
(Func_Id
, Is_Public
(Rec_Id
));
1089 Set_Is_Internal
(Func_Id
, True);
1091 if not Debug_Generated_Code
then
1092 Set_Debug_Info_Off
(Func_Id
);
1095 Analyze
(Body_Node
);
1097 Append_Freeze_Action
(Rec_Id
, Body_Node
);
1098 Set_Dcheck_Function
(Variant
, Func_Id
);
1100 end Build_Dcheck_Function
;
1102 ----------------------------
1103 -- Build_Dcheck_Functions --
1104 ----------------------------
1106 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
) is
1107 Component_List_Node
: Node_Id
;
1109 Discr_Name
: Entity_Id
;
1110 Func_Id
: Entity_Id
;
1112 Saved_Enclosing_Func_Id
: Entity_Id
;
1115 -- Build the discriminant-checking function for each variant, and
1116 -- label all components of that variant with the function's name.
1117 -- We only Generate a discriminant-checking function when the
1118 -- variant is not empty, to prevent the creation of dead code.
1119 -- The exception to that is when Frontend_Layout_On_Target is set,
1120 -- because the variant record size function generated in package
1121 -- Layout needs to generate calls to all discriminant-checking
1122 -- functions, including those for empty variants.
1124 Discr_Name
:= Entity
(Name
(Variant_Part_Node
));
1125 Variant
:= First_Non_Pragma
(Variants
(Variant_Part_Node
));
1127 while Present
(Variant
) loop
1128 Component_List_Node
:= Component_List
(Variant
);
1130 if not Null_Present
(Component_List_Node
)
1131 or else Frontend_Layout_On_Target
1133 Func_Id
:= Build_Dcheck_Function
(Discr_Name
, Variant
);
1136 First_Non_Pragma
(Component_Items
(Component_List_Node
));
1137 while Present
(Decl
) loop
1138 Set_Discriminant_Checking_Func
1139 (Defining_Identifier
(Decl
), Func_Id
);
1140 Next_Non_Pragma
(Decl
);
1143 if Present
(Variant_Part
(Component_List_Node
)) then
1144 Saved_Enclosing_Func_Id
:= Enclosing_Func_Id
;
1145 Enclosing_Func_Id
:= Func_Id
;
1146 Build_Dcheck_Functions
(Variant_Part
(Component_List_Node
));
1147 Enclosing_Func_Id
:= Saved_Enclosing_Func_Id
;
1151 Next_Non_Pragma
(Variant
);
1153 end Build_Dcheck_Functions
;
1155 -- Start of processing for Build_Discr_Checking_Funcs
1158 -- Only build if not done already
1160 if not Discr_Check_Funcs_Built
(N
) then
1161 Type_Def
:= Type_Definition
(N
);
1163 if Nkind
(Type_Def
) = N_Record_Definition
then
1164 if No
(Component_List
(Type_Def
)) then -- null record.
1167 V
:= Variant_Part
(Component_List
(Type_Def
));
1170 else pragma Assert
(Nkind
(Type_Def
) = N_Derived_Type_Definition
);
1171 if No
(Component_List
(Record_Extension_Part
(Type_Def
))) then
1175 (Component_List
(Record_Extension_Part
(Type_Def
)));
1179 Rec_Id
:= Defining_Identifier
(N
);
1181 if Present
(V
) and then not Is_Unchecked_Union
(Rec_Id
) then
1183 Enclosing_Func_Id
:= Empty
;
1184 Build_Dcheck_Functions
(V
);
1187 Set_Discr_Check_Funcs_Built
(N
);
1189 end Build_Discr_Checking_Funcs
;
1191 --------------------------------
1192 -- Build_Discriminant_Formals --
1193 --------------------------------
1195 function Build_Discriminant_Formals
1196 (Rec_Id
: Entity_Id
;
1197 Use_Dl
: Boolean) return List_Id
1199 Loc
: Source_Ptr
:= Sloc
(Rec_Id
);
1200 Parameter_List
: constant List_Id
:= New_List
;
1203 Formal_Type
: Entity_Id
;
1204 Param_Spec_Node
: Node_Id
;
1207 if Has_Discriminants
(Rec_Id
) then
1208 D
:= First_Discriminant
(Rec_Id
);
1209 while Present
(D
) loop
1213 Formal
:= Discriminal
(D
);
1214 Formal_Type
:= Etype
(Formal
);
1216 Formal
:= Make_Defining_Identifier
(Loc
, Chars
(D
));
1217 Formal_Type
:= Etype
(D
);
1221 Make_Parameter_Specification
(Loc
,
1222 Defining_Identifier
=> Formal
,
1224 New_Occurrence_Of
(Formal_Type
, Loc
));
1225 Append
(Param_Spec_Node
, Parameter_List
);
1226 Next_Discriminant
(D
);
1230 return Parameter_List
;
1231 end Build_Discriminant_Formals
;
1233 --------------------------------------
1234 -- Build_Equivalent_Array_Aggregate --
1235 --------------------------------------
1237 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
is
1238 Loc
: constant Source_Ptr
:= Sloc
(T
);
1239 Comp_Type
: constant Entity_Id
:= Component_Type
(T
);
1240 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(T
));
1241 Proc
: constant Entity_Id
:= Base_Init_Proc
(T
);
1247 if not Is_Constrained
(T
)
1248 or else Number_Dimensions
(T
) > 1
1251 Initialization_Warning
(T
);
1255 Lo
:= Type_Low_Bound
(Index_Type
);
1256 Hi
:= Type_High_Bound
(Index_Type
);
1258 if not Compile_Time_Known_Value
(Lo
)
1259 or else not Compile_Time_Known_Value
(Hi
)
1261 Initialization_Warning
(T
);
1265 if Is_Record_Type
(Comp_Type
)
1266 and then Present
(Base_Init_Proc
(Comp_Type
))
1268 Expr
:= Static_Initialization
(Base_Init_Proc
(Comp_Type
));
1271 Initialization_Warning
(T
);
1276 Initialization_Warning
(T
);
1280 Aggr
:= Make_Aggregate
(Loc
, No_List
, New_List
);
1281 Set_Etype
(Aggr
, T
);
1282 Set_Aggregate_Bounds
(Aggr
,
1284 Low_Bound
=> New_Copy
(Lo
),
1285 High_Bound
=> New_Copy
(Hi
)));
1286 Set_Parent
(Aggr
, Parent
(Proc
));
1288 Append_To
(Component_Associations
(Aggr
),
1289 Make_Component_Association
(Loc
,
1293 Low_Bound
=> New_Copy
(Lo
),
1294 High_Bound
=> New_Copy
(Hi
))),
1295 Expression
=> Expr
));
1297 if Static_Array_Aggregate
(Aggr
) then
1300 Initialization_Warning
(T
);
1303 end Build_Equivalent_Array_Aggregate
;
1305 ---------------------------------------
1306 -- Build_Equivalent_Record_Aggregate --
1307 ---------------------------------------
1309 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
is
1312 Comp_Type
: Entity_Id
;
1314 -- Start of processing for Build_Equivalent_Record_Aggregate
1317 if not Is_Record_Type
(T
)
1318 or else Has_Discriminants
(T
)
1319 or else Is_Limited_Type
(T
)
1320 or else Has_Non_Standard_Rep
(T
)
1322 Initialization_Warning
(T
);
1326 Comp
:= First_Component
(T
);
1328 -- A null record needs no warning
1334 while Present
(Comp
) loop
1336 -- Array components are acceptable if initialized by a positional
1337 -- aggregate with static components.
1339 if Is_Array_Type
(Etype
(Comp
)) then
1340 Comp_Type
:= Component_Type
(Etype
(Comp
));
1342 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1343 or else No
(Expression
(Parent
(Comp
)))
1344 or else Nkind
(Expression
(Parent
(Comp
))) /= N_Aggregate
1346 Initialization_Warning
(T
);
1349 elsif Is_Scalar_Type
(Component_Type
(Etype
(Comp
)))
1351 (not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1353 not Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
)))
1355 Initialization_Warning
(T
);
1359 not Static_Array_Aggregate
(Expression
(Parent
(Comp
)))
1361 Initialization_Warning
(T
);
1365 elsif Is_Scalar_Type
(Etype
(Comp
)) then
1366 Comp_Type
:= Etype
(Comp
);
1368 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1369 or else No
(Expression
(Parent
(Comp
)))
1370 or else not Compile_Time_Known_Value
(Expression
(Parent
(Comp
)))
1371 or else not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1373 Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
))
1375 Initialization_Warning
(T
);
1379 -- For now, other types are excluded
1382 Initialization_Warning
(T
);
1386 Next_Component
(Comp
);
1389 -- All components have static initialization. Build positional aggregate
1390 -- from the given expressions or defaults.
1392 Agg
:= Make_Aggregate
(Sloc
(T
), New_List
, New_List
);
1393 Set_Parent
(Agg
, Parent
(T
));
1395 Comp
:= First_Component
(T
);
1396 while Present
(Comp
) loop
1398 (New_Copy_Tree
(Expression
(Parent
(Comp
))), Expressions
(Agg
));
1399 Next_Component
(Comp
);
1402 Analyze_And_Resolve
(Agg
, T
);
1404 end Build_Equivalent_Record_Aggregate
;
1406 -------------------------------
1407 -- Build_Initialization_Call --
1408 -------------------------------
1410 -- References to a discriminant inside the record type declaration can
1411 -- appear either in the subtype_indication to constrain a record or an
1412 -- array, or as part of a larger expression given for the initial value
1413 -- of a component. In both of these cases N appears in the record
1414 -- initialization procedure and needs to be replaced by the formal
1415 -- parameter of the initialization procedure which corresponds to that
1418 -- In the example below, references to discriminants D1 and D2 in proc_1
1419 -- are replaced by references to formals with the same name
1422 -- A similar replacement is done for calls to any record initialization
1423 -- procedure for any components that are themselves of a record type.
1425 -- type R (D1, D2 : Integer) is record
1426 -- X : Integer := F * D1;
1427 -- Y : Integer := F * D2;
1430 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1434 -- Out_2.X := F * D1;
1435 -- Out_2.Y := F * D2;
1438 function Build_Initialization_Call
1442 In_Init_Proc
: Boolean := False;
1443 Enclos_Type
: Entity_Id
:= Empty
;
1444 Discr_Map
: Elist_Id
:= New_Elmt_List
;
1445 With_Default_Init
: Boolean := False;
1446 Constructor_Ref
: Node_Id
:= Empty
) return List_Id
1448 Res
: constant List_Id
:= New_List
;
1454 First_Arg
: Node_Id
;
1455 Full_Init_Type
: Entity_Id
;
1456 Full_Type
: Entity_Id
;
1457 Init_Type
: Entity_Id
;
1461 pragma Assert
(Constructor_Ref
= Empty
1462 or else Is_CPP_Constructor_Call
(Constructor_Ref
));
1464 if No
(Constructor_Ref
) then
1465 Proc
:= Base_Init_Proc
(Typ
);
1467 Proc
:= Base_Init_Proc
(Typ
, Entity
(Name
(Constructor_Ref
)));
1470 pragma Assert
(Present
(Proc
));
1471 Init_Type
:= Etype
(First_Formal
(Proc
));
1472 Full_Init_Type
:= Underlying_Type
(Init_Type
);
1474 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1475 -- is active (in which case we make the call anyway, since in the
1476 -- actual compiled client it may be non null).
1478 if Is_Null_Init_Proc
(Proc
) and then not Init_Or_Norm_Scalars
then
1482 -- Use the [underlying] full view when dealing with a private type. This
1483 -- may require several steps depending on derivations.
1487 if Is_Private_Type
(Full_Type
) then
1488 if Present
(Full_View
(Full_Type
)) then
1489 Full_Type
:= Full_View
(Full_Type
);
1491 elsif Present
(Underlying_Full_View
(Full_Type
)) then
1492 Full_Type
:= Underlying_Full_View
(Full_Type
);
1494 -- When a private type acts as a generic actual and lacks a full
1495 -- view, use the base type.
1497 elsif Is_Generic_Actual_Type
(Full_Type
) then
1498 Full_Type
:= Base_Type
(Full_Type
);
1500 -- The loop has recovered the [underlying] full view, stop the
1507 -- The type is not private, nothing to do
1514 -- If Typ is derived, the procedure is the initialization procedure for
1515 -- the root type. Wrap the argument in an conversion to make it type
1516 -- honest. Actually it isn't quite type honest, because there can be
1517 -- conflicts of views in the private type case. That is why we set
1518 -- Conversion_OK in the conversion node.
1520 if (Is_Record_Type
(Typ
)
1521 or else Is_Array_Type
(Typ
)
1522 or else Is_Private_Type
(Typ
))
1523 and then Init_Type
/= Base_Type
(Typ
)
1525 First_Arg
:= OK_Convert_To
(Etype
(Init_Type
), Id_Ref
);
1526 Set_Etype
(First_Arg
, Init_Type
);
1529 First_Arg
:= Id_Ref
;
1532 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Typ
));
1534 -- In the tasks case, add _Master as the value of the _Master parameter
1535 -- and _Chain as the value of the _Chain parameter. At the outer level,
1536 -- these will be variables holding the corresponding values obtained
1537 -- from GNARL. At inner levels, they will be the parameters passed down
1538 -- through the outer routines.
1540 if Has_Task
(Full_Type
) then
1541 if Restriction_Active
(No_Task_Hierarchy
) then
1543 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1545 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1548 -- Add _Chain (not done for sequential elaboration policy, see
1549 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1551 if Partition_Elaboration_Policy
/= 'S' then
1552 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1555 -- Ada 2005 (AI-287): In case of default initialized components
1556 -- with tasks, we generate a null string actual parameter.
1557 -- This is just a workaround that must be improved later???
1559 if With_Default_Init
then
1561 Make_String_Literal
(Loc
,
1566 Build_Task_Image_Decls
(Loc
, Id_Ref
, Enclos_Type
, In_Init_Proc
);
1567 Decl
:= Last
(Decls
);
1570 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
));
1571 Append_List
(Decls
, Res
);
1579 -- Add discriminant values if discriminants are present
1581 if Has_Discriminants
(Full_Init_Type
) then
1582 Discr
:= First_Discriminant
(Full_Init_Type
);
1583 while Present
(Discr
) loop
1585 -- If this is a discriminated concurrent type, the init_proc
1586 -- for the corresponding record is being called. Use that type
1587 -- directly to find the discriminant value, to handle properly
1588 -- intervening renamed discriminants.
1591 T
: Entity_Id
:= Full_Type
;
1594 if Is_Protected_Type
(T
) then
1595 T
:= Corresponding_Record_Type
(T
);
1599 Get_Discriminant_Value
(
1602 Discriminant_Constraint
(Full_Type
));
1605 -- If the target has access discriminants, and is constrained by
1606 -- an access to the enclosing construct, i.e. a current instance,
1607 -- replace the reference to the type by a reference to the object.
1609 if Nkind
(Arg
) = N_Attribute_Reference
1610 and then Is_Access_Type
(Etype
(Arg
))
1611 and then Is_Entity_Name
(Prefix
(Arg
))
1612 and then Is_Type
(Entity
(Prefix
(Arg
)))
1615 Make_Attribute_Reference
(Loc
,
1616 Prefix
=> New_Copy
(Prefix
(Id_Ref
)),
1617 Attribute_Name
=> Name_Unrestricted_Access
);
1619 elsif In_Init_Proc
then
1621 -- Replace any possible references to the discriminant in the
1622 -- call to the record initialization procedure with references
1623 -- to the appropriate formal parameter.
1625 if Nkind
(Arg
) = N_Identifier
1626 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1628 Arg
:= New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
);
1630 -- Otherwise make a copy of the default expression. Note that
1631 -- we use the current Sloc for this, because we do not want the
1632 -- call to appear to be at the declaration point. Within the
1633 -- expression, replace discriminants with their discriminals.
1637 New_Copy_Tree
(Arg
, Map
=> Discr_Map
, New_Sloc
=> Loc
);
1641 if Is_Constrained
(Full_Type
) then
1642 Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
1644 -- The constraints come from the discriminant default exps,
1645 -- they must be reevaluated, so we use New_Copy_Tree but we
1646 -- ensure the proper Sloc (for any embedded calls).
1648 Arg
:= New_Copy_Tree
(Arg
, New_Sloc
=> Loc
);
1652 -- Ada 2005 (AI-287): In case of default initialized components,
1653 -- if the component is constrained with a discriminant of the
1654 -- enclosing type, we need to generate the corresponding selected
1655 -- component node to access the discriminant value. In other cases
1656 -- this is not required, either because we are inside the init
1657 -- proc and we use the corresponding formal, or else because the
1658 -- component is constrained by an expression.
1660 if With_Default_Init
1661 and then Nkind
(Id_Ref
) = N_Selected_Component
1662 and then Nkind
(Arg
) = N_Identifier
1663 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1666 Make_Selected_Component
(Loc
,
1667 Prefix
=> New_Copy_Tree
(Prefix
(Id_Ref
)),
1668 Selector_Name
=> Arg
));
1670 Append_To
(Args
, Arg
);
1673 Next_Discriminant
(Discr
);
1677 -- If this is a call to initialize the parent component of a derived
1678 -- tagged type, indicate that the tag should not be set in the parent.
1680 if Is_Tagged_Type
(Full_Init_Type
)
1681 and then not Is_CPP_Class
(Full_Init_Type
)
1682 and then Nkind
(Id_Ref
) = N_Selected_Component
1683 and then Chars
(Selector_Name
(Id_Ref
)) = Name_uParent
1685 Append_To
(Args
, New_Occurrence_Of
(Standard_False
, Loc
));
1687 elsif Present
(Constructor_Ref
) then
1688 Append_List_To
(Args
,
1689 New_Copy_List
(Parameter_Associations
(Constructor_Ref
)));
1693 Make_Procedure_Call_Statement
(Loc
,
1694 Name
=> New_Occurrence_Of
(Proc
, Loc
),
1695 Parameter_Associations
=> Args
));
1697 if Needs_Finalization
(Typ
)
1698 and then Nkind
(Id_Ref
) = N_Selected_Component
1700 if Chars
(Selector_Name
(Id_Ref
)) /= Name_uParent
then
1703 (Obj_Ref
=> New_Copy_Tree
(First_Arg
),
1711 when RE_Not_Available
=>
1713 end Build_Initialization_Call
;
1715 ----------------------------
1716 -- Build_Record_Init_Proc --
1717 ----------------------------
1719 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
) is
1720 Decls
: constant List_Id
:= New_List
;
1721 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
1722 Loc
: constant Source_Ptr
:= Sloc
(Rec_Ent
);
1724 Proc_Id
: Entity_Id
;
1725 Rec_Type
: Entity_Id
;
1726 Set_Tag
: Entity_Id
:= Empty
;
1728 function Build_Assignment
(Id
: Entity_Id
; N
: Node_Id
) return List_Id
;
1729 -- Build an assignment statement which assigns the default expression
1730 -- to its corresponding record component if defined. The left hand side
1731 -- of the assignment is marked Assignment_OK so that initialization of
1732 -- limited private records works correctly. This routine may also build
1733 -- an adjustment call if the component is controlled.
1735 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
);
1736 -- If the record has discriminants, add assignment statements to
1737 -- Statement_List to initialize the discriminant values from the
1738 -- arguments of the initialization procedure.
1740 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
;
1741 -- Build a list representing a sequence of statements which initialize
1742 -- components of the given component list. This may involve building
1743 -- case statements for the variant parts. Append any locally declared
1744 -- objects on list Decls.
1746 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
;
1747 -- Given an untagged type-derivation that declares discriminants, e.g.
1749 -- type R (R1, R2 : Integer) is record ... end record;
1750 -- type D (D1 : Integer) is new R (1, D1);
1752 -- we make the _init_proc of D be
1754 -- procedure _init_proc (X : D; D1 : Integer) is
1756 -- _init_proc (R (X), 1, D1);
1759 -- This function builds the call statement in this _init_proc.
1761 procedure Build_CPP_Init_Procedure
;
1762 -- Build the tree corresponding to the procedure specification and body
1763 -- of the IC procedure that initializes the C++ part of the dispatch
1764 -- table of an Ada tagged type that is a derivation of a CPP type.
1765 -- Install it as the CPP_Init TSS.
1767 procedure Build_Init_Procedure
;
1768 -- Build the tree corresponding to the procedure specification and body
1769 -- of the initialization procedure and install it as the _init TSS.
1771 procedure Build_Offset_To_Top_Functions
;
1772 -- Ada 2005 (AI-251): Build the tree corresponding to the procedure spec
1773 -- and body of Offset_To_Top, a function used in conjuction with types
1774 -- having secondary dispatch tables.
1776 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
);
1777 -- Add range checks to components of discriminated records. S is a
1778 -- subtype indication of a record component. Check_List is a list
1779 -- to which the check actions are appended.
1781 function Component_Needs_Simple_Initialization
1782 (T
: Entity_Id
) return Boolean;
1783 -- Determine if a component needs simple initialization, given its type
1784 -- T. This routine is the same as Needs_Simple_Initialization except for
1785 -- components of type Tag and Interface_Tag. These two access types do
1786 -- not require initialization since they are explicitly initialized by
1789 function Parent_Subtype_Renaming_Discrims
return Boolean;
1790 -- Returns True for base types N that rename discriminants, else False
1792 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean;
1793 -- Determine whether a record initialization procedure needs to be
1794 -- generated for the given record type.
1796 ----------------------
1797 -- Build_Assignment --
1798 ----------------------
1800 function Build_Assignment
(Id
: Entity_Id
; N
: Node_Id
) return List_Id
is
1801 N_Loc
: constant Source_Ptr
:= Sloc
(N
);
1802 Typ
: constant Entity_Id
:= Underlying_Type
(Etype
(Id
));
1804 Kind
: Node_Kind
:= Nkind
(N
);
1810 Make_Selected_Component
(N_Loc
,
1811 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1812 Selector_Name
=> New_Occurrence_Of
(Id
, N_Loc
));
1813 Set_Assignment_OK
(Lhs
);
1815 -- Case of an access attribute applied to the current instance.
1816 -- Replace the reference to the type by a reference to the actual
1817 -- object. (Note that this handles the case of the top level of
1818 -- the expression being given by such an attribute, but does not
1819 -- cover uses nested within an initial value expression. Nested
1820 -- uses are unlikely to occur in practice, but are theoretically
1821 -- possible.) It is not clear how to handle them without fully
1822 -- traversing the expression. ???
1824 if Kind
= N_Attribute_Reference
1825 and then Nam_In
(Attribute_Name
(N
), Name_Unchecked_Access
,
1826 Name_Unrestricted_Access
)
1827 and then Is_Entity_Name
(Prefix
(N
))
1828 and then Is_Type
(Entity
(Prefix
(N
)))
1829 and then Entity
(Prefix
(N
)) = Rec_Type
1832 Make_Attribute_Reference
(N_Loc
,
1834 Make_Identifier
(N_Loc
, Name_uInit
),
1835 Attribute_Name
=> Name_Unrestricted_Access
);
1838 -- Take a copy of Exp to ensure that later copies of this component
1839 -- declaration in derived types see the original tree, not a node
1840 -- rewritten during expansion of the init_proc. If the copy contains
1841 -- itypes, the scope of the new itypes is the init_proc being built.
1843 Exp
:= New_Copy_Tree
(Exp
, New_Scope
=> Proc_Id
);
1846 Make_Assignment_Statement
(Loc
,
1848 Expression
=> Exp
));
1850 Set_No_Ctrl_Actions
(First
(Res
));
1852 -- Adjust the tag if tagged (because of possible view conversions).
1853 -- Suppress the tag adjustment when not Tagged_Type_Expansion because
1854 -- tags are represented implicitly in objects.
1856 if Is_Tagged_Type
(Typ
) and then Tagged_Type_Expansion
then
1858 Make_Assignment_Statement
(N_Loc
,
1860 Make_Selected_Component
(N_Loc
,
1862 New_Copy_Tree
(Lhs
, New_Scope
=> Proc_Id
),
1864 New_Occurrence_Of
(First_Tag_Component
(Typ
), N_Loc
)),
1867 Unchecked_Convert_To
(RTE
(RE_Tag
),
1871 (Access_Disp_Table
(Underlying_Type
(Typ
)))),
1875 -- Adjust the component if controlled except if it is an aggregate
1876 -- that will be expanded inline.
1878 if Kind
= N_Qualified_Expression
then
1879 Kind
:= Nkind
(Expression
(N
));
1882 if Needs_Finalization
(Typ
)
1883 and then not (Nkind_In
(Kind
, N_Aggregate
, N_Extension_Aggregate
))
1884 and then not Is_Limited_View
(Typ
)
1888 (Obj_Ref
=> New_Copy_Tree
(Lhs
),
1889 Typ
=> Etype
(Id
)));
1895 when RE_Not_Available
=>
1897 end Build_Assignment
;
1899 ------------------------------------
1900 -- Build_Discriminant_Assignments --
1901 ------------------------------------
1903 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
) is
1904 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Rec_Type
);
1909 if Has_Discriminants
(Rec_Type
)
1910 and then not Is_Unchecked_Union
(Rec_Type
)
1912 D
:= First_Discriminant
(Rec_Type
);
1913 while Present
(D
) loop
1915 -- Don't generate the assignment for discriminants in derived
1916 -- tagged types if the discriminant is a renaming of some
1917 -- ancestor discriminant. This initialization will be done
1918 -- when initializing the _parent field of the derived record.
1921 and then Present
(Corresponding_Discriminant
(D
))
1927 Append_List_To
(Statement_List
,
1928 Build_Assignment
(D
,
1929 New_Occurrence_Of
(Discriminal
(D
), D_Loc
)));
1932 Next_Discriminant
(D
);
1935 end Build_Discriminant_Assignments
;
1937 --------------------------
1938 -- Build_Init_Call_Thru --
1939 --------------------------
1941 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
is
1942 Parent_Proc
: constant Entity_Id
:=
1943 Base_Init_Proc
(Etype
(Rec_Type
));
1945 Parent_Type
: constant Entity_Id
:=
1946 Etype
(First_Formal
(Parent_Proc
));
1948 Uparent_Type
: constant Entity_Id
:=
1949 Underlying_Type
(Parent_Type
);
1951 First_Discr_Param
: Node_Id
;
1955 First_Arg
: Node_Id
;
1956 Parent_Discr
: Entity_Id
;
1960 -- First argument (_Init) is the object to be initialized.
1961 -- ??? not sure where to get a reasonable Loc for First_Arg
1964 OK_Convert_To
(Parent_Type
,
1966 (Defining_Identifier
(First
(Parameters
)), Loc
));
1968 Set_Etype
(First_Arg
, Parent_Type
);
1970 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Rec_Type
));
1972 -- In the tasks case,
1973 -- add _Master as the value of the _Master parameter
1974 -- add _Chain as the value of the _Chain parameter.
1975 -- add _Task_Name as the value of the _Task_Name parameter.
1976 -- At the outer level, these will be variables holding the
1977 -- corresponding values obtained from GNARL or the expander.
1979 -- At inner levels, they will be the parameters passed down through
1980 -- the outer routines.
1982 First_Discr_Param
:= Next
(First
(Parameters
));
1984 if Has_Task
(Rec_Type
) then
1985 if Restriction_Active
(No_Task_Hierarchy
) then
1987 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1989 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1992 -- Add _Chain (not done for sequential elaboration policy, see
1993 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1995 if Partition_Elaboration_Policy
/= 'S' then
1996 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1999 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
2000 First_Discr_Param
:= Next
(Next
(Next
(First_Discr_Param
)));
2003 -- Append discriminant values
2005 if Has_Discriminants
(Uparent_Type
) then
2006 pragma Assert
(not Is_Tagged_Type
(Uparent_Type
));
2008 Parent_Discr
:= First_Discriminant
(Uparent_Type
);
2009 while Present
(Parent_Discr
) loop
2011 -- Get the initial value for this discriminant
2012 -- ??? needs to be cleaned up to use parent_Discr_Constr
2016 Discr
: Entity_Id
:=
2017 First_Stored_Discriminant
(Uparent_Type
);
2019 Discr_Value
: Elmt_Id
:=
2020 First_Elmt
(Stored_Constraint
(Rec_Type
));
2023 while Original_Record_Component
(Parent_Discr
) /= Discr
loop
2024 Next_Stored_Discriminant
(Discr
);
2025 Next_Elmt
(Discr_Value
);
2028 Arg
:= Node
(Discr_Value
);
2031 -- Append it to the list
2033 if Nkind
(Arg
) = N_Identifier
2034 and then Ekind
(Entity
(Arg
)) = E_Discriminant
2037 New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
));
2039 -- Case of access discriminants. We replace the reference
2040 -- to the type by a reference to the actual object.
2042 -- Is above comment right??? Use of New_Copy below seems mighty
2046 Append_To
(Args
, New_Copy
(Arg
));
2049 Next_Discriminant
(Parent_Discr
);
2055 Make_Procedure_Call_Statement
(Loc
,
2057 New_Occurrence_Of
(Parent_Proc
, Loc
),
2058 Parameter_Associations
=> Args
));
2061 end Build_Init_Call_Thru
;
2063 -----------------------------------
2064 -- Build_Offset_To_Top_Functions --
2065 -----------------------------------
2067 procedure Build_Offset_To_Top_Functions
is
2069 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
);
2071 -- function Fxx (O : Address) return Storage_Offset is
2072 -- type Acc is access all <Typ>;
2074 -- return Acc!(O).Iface_Comp'Position;
2077 ----------------------------------
2078 -- Build_Offset_To_Top_Function --
2079 ----------------------------------
2081 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
) is
2082 Body_Node
: Node_Id
;
2083 Func_Id
: Entity_Id
;
2084 Spec_Node
: Node_Id
;
2085 Acc_Type
: Entity_Id
;
2088 Func_Id
:= Make_Temporary
(Loc
, 'F');
2089 Set_DT_Offset_To_Top_Func
(Iface_Comp
, Func_Id
);
2092 -- function Fxx (O : in Rec_Typ) return Storage_Offset;
2094 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
2095 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
2096 Set_Parameter_Specifications
(Spec_Node
, New_List
(
2097 Make_Parameter_Specification
(Loc
,
2098 Defining_Identifier
=>
2099 Make_Defining_Identifier
(Loc
, Name_uO
),
2102 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))));
2103 Set_Result_Definition
(Spec_Node
,
2104 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
2107 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2109 -- return O.Iface_Comp'Position;
2112 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2113 Set_Specification
(Body_Node
, Spec_Node
);
2115 Acc_Type
:= Make_Temporary
(Loc
, 'T');
2116 Set_Declarations
(Body_Node
, New_List
(
2117 Make_Full_Type_Declaration
(Loc
,
2118 Defining_Identifier
=> Acc_Type
,
2120 Make_Access_To_Object_Definition
(Loc
,
2121 All_Present
=> True,
2122 Null_Exclusion_Present
=> False,
2123 Constant_Present
=> False,
2124 Subtype_Indication
=>
2125 New_Occurrence_Of
(Rec_Type
, Loc
)))));
2127 Set_Handled_Statement_Sequence
(Body_Node
,
2128 Make_Handled_Sequence_Of_Statements
(Loc
,
2129 Statements
=> New_List
(
2130 Make_Simple_Return_Statement
(Loc
,
2132 Make_Attribute_Reference
(Loc
,
2134 Make_Selected_Component
(Loc
,
2136 Unchecked_Convert_To
(Acc_Type
,
2137 Make_Identifier
(Loc
, Name_uO
)),
2139 New_Occurrence_Of
(Iface_Comp
, Loc
)),
2140 Attribute_Name
=> Name_Position
)))));
2142 Set_Ekind
(Func_Id
, E_Function
);
2143 Set_Mechanism
(Func_Id
, Default_Mechanism
);
2144 Set_Is_Internal
(Func_Id
, True);
2146 if not Debug_Generated_Code
then
2147 Set_Debug_Info_Off
(Func_Id
);
2150 Analyze
(Body_Node
);
2152 Append_Freeze_Action
(Rec_Type
, Body_Node
);
2153 end Build_Offset_To_Top_Function
;
2157 Iface_Comp
: Node_Id
;
2158 Iface_Comp_Elmt
: Elmt_Id
;
2159 Ifaces_Comp_List
: Elist_Id
;
2161 -- Start of processing for Build_Offset_To_Top_Functions
2164 -- Offset_To_Top_Functions are built only for derivations of types
2165 -- with discriminants that cover interface types.
2166 -- Nothing is needed either in case of virtual targets, since
2167 -- interfaces are handled directly by the target.
2169 if not Is_Tagged_Type
(Rec_Type
)
2170 or else Etype
(Rec_Type
) = Rec_Type
2171 or else not Has_Discriminants
(Etype
(Rec_Type
))
2172 or else not Tagged_Type_Expansion
2177 Collect_Interface_Components
(Rec_Type
, Ifaces_Comp_List
);
2179 -- For each interface type with secondary dispatch table we generate
2180 -- the Offset_To_Top_Functions (required to displace the pointer in
2181 -- interface conversions)
2183 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
2184 while Present
(Iface_Comp_Elmt
) loop
2185 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
2186 pragma Assert
(Is_Interface
(Related_Type
(Iface_Comp
)));
2188 -- If the interface is a parent of Rec_Type it shares the primary
2189 -- dispatch table and hence there is no need to build the function
2191 if not Is_Ancestor
(Related_Type
(Iface_Comp
), Rec_Type
,
2192 Use_Full_View
=> True)
2194 Build_Offset_To_Top_Function
(Iface_Comp
);
2197 Next_Elmt
(Iface_Comp_Elmt
);
2199 end Build_Offset_To_Top_Functions
;
2201 ------------------------------
2202 -- Build_CPP_Init_Procedure --
2203 ------------------------------
2205 procedure Build_CPP_Init_Procedure
is
2206 Body_Node
: Node_Id
;
2207 Body_Stmts
: List_Id
;
2208 Flag_Id
: Entity_Id
;
2209 Handled_Stmt_Node
: Node_Id
;
2210 Init_Tags_List
: List_Id
;
2211 Proc_Id
: Entity_Id
;
2212 Proc_Spec_Node
: Node_Id
;
2215 -- Check cases requiring no IC routine
2217 if not Is_CPP_Class
(Root_Type
(Rec_Type
))
2218 or else Is_CPP_Class
(Rec_Type
)
2219 or else CPP_Num_Prims
(Rec_Type
) = 0
2220 or else not Tagged_Type_Expansion
2221 or else No_Run_Time_Mode
2228 -- Flag : Boolean := False;
2230 -- procedure Typ_IC is
2233 -- Copy C++ dispatch table slots from parent
2234 -- Update C++ slots of overridden primitives
2238 Flag_Id
:= Make_Temporary
(Loc
, 'F');
2240 Append_Freeze_Action
(Rec_Type
,
2241 Make_Object_Declaration
(Loc
,
2242 Defining_Identifier
=> Flag_Id
,
2243 Object_Definition
=>
2244 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2246 New_Occurrence_Of
(Standard_True
, Loc
)));
2248 Body_Stmts
:= New_List
;
2249 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2251 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2254 Make_Defining_Identifier
(Loc
,
2255 Chars
=> Make_TSS_Name
(Rec_Type
, TSS_CPP_Init_Proc
));
2257 Set_Ekind
(Proc_Id
, E_Procedure
);
2258 Set_Is_Internal
(Proc_Id
);
2260 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2262 Set_Parameter_Specifications
(Proc_Spec_Node
, New_List
);
2263 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2264 Set_Declarations
(Body_Node
, New_List
);
2266 Init_Tags_List
:= Build_Inherit_CPP_Prims
(Rec_Type
);
2268 Append_To
(Init_Tags_List
,
2269 Make_Assignment_Statement
(Loc
,
2271 New_Occurrence_Of
(Flag_Id
, Loc
),
2273 New_Occurrence_Of
(Standard_False
, Loc
)));
2275 Append_To
(Body_Stmts
,
2276 Make_If_Statement
(Loc
,
2277 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
2278 Then_Statements
=> Init_Tags_List
));
2280 Handled_Stmt_Node
:=
2281 New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2282 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2283 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2284 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2286 if not Debug_Generated_Code
then
2287 Set_Debug_Info_Off
(Proc_Id
);
2290 -- Associate CPP_Init_Proc with type
2292 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2293 end Build_CPP_Init_Procedure
;
2295 --------------------------
2296 -- Build_Init_Procedure --
2297 --------------------------
2299 procedure Build_Init_Procedure
is
2300 Body_Stmts
: List_Id
;
2301 Body_Node
: Node_Id
;
2302 Handled_Stmt_Node
: Node_Id
;
2303 Init_Tags_List
: List_Id
;
2304 Parameters
: List_Id
;
2305 Proc_Spec_Node
: Node_Id
;
2306 Record_Extension_Node
: Node_Id
;
2309 Body_Stmts
:= New_List
;
2310 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2311 Set_Ekind
(Proc_Id
, E_Procedure
);
2313 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2314 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2316 Parameters
:= Init_Formals
(Rec_Type
);
2317 Append_List_To
(Parameters
,
2318 Build_Discriminant_Formals
(Rec_Type
, True));
2320 -- For tagged types, we add a flag to indicate whether the routine
2321 -- is called to initialize a parent component in the init_proc of
2322 -- a type extension. If the flag is false, we do not set the tag
2323 -- because it has been set already in the extension.
2325 if Is_Tagged_Type
(Rec_Type
) then
2326 Set_Tag
:= Make_Temporary
(Loc
, 'P');
2328 Append_To
(Parameters
,
2329 Make_Parameter_Specification
(Loc
,
2330 Defining_Identifier
=> Set_Tag
,
2332 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2334 New_Occurrence_Of
(Standard_True
, Loc
)));
2337 Set_Parameter_Specifications
(Proc_Spec_Node
, Parameters
);
2338 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2339 Set_Declarations
(Body_Node
, Decls
);
2341 -- N is a Derived_Type_Definition that renames the parameters of the
2342 -- ancestor type. We initialize it by expanding our discriminants and
2343 -- call the ancestor _init_proc with a type-converted object.
2345 if Parent_Subtype_Renaming_Discrims
then
2346 Append_List_To
(Body_Stmts
, Build_Init_Call_Thru
(Parameters
));
2348 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
2349 Build_Discriminant_Assignments
(Body_Stmts
);
2351 if not Null_Present
(Type_Definition
(N
)) then
2352 Append_List_To
(Body_Stmts
,
2353 Build_Init_Statements
(Component_List
(Type_Definition
(N
))));
2356 -- N is a Derived_Type_Definition with a possible non-empty
2357 -- extension. The initialization of a type extension consists in the
2358 -- initialization of the components in the extension.
2361 Build_Discriminant_Assignments
(Body_Stmts
);
2363 Record_Extension_Node
:=
2364 Record_Extension_Part
(Type_Definition
(N
));
2366 if not Null_Present
(Record_Extension_Node
) then
2368 Stmts
: constant List_Id
:=
2369 Build_Init_Statements
(
2370 Component_List
(Record_Extension_Node
));
2373 -- The parent field must be initialized first because the
2374 -- offset of the new discriminants may depend on it. This is
2375 -- not needed if the parent is an interface type because in
2376 -- such case the initialization of the _parent field was not
2379 if not Is_Interface
(Etype
(Rec_Ent
)) then
2381 Parent_IP
: constant Name_Id
:=
2382 Make_Init_Proc_Name
(Etype
(Rec_Ent
));
2388 -- Look for a call to the parent IP at the beginning
2389 -- of Stmts associated with the record extension
2391 Stmt
:= First
(Stmts
);
2393 while Present
(Stmt
) loop
2394 if Nkind
(Stmt
) = N_Procedure_Call_Statement
2395 and then Chars
(Name
(Stmt
)) = Parent_IP
2404 -- If found then move it to the beginning of the
2405 -- statements of this IP routine
2407 if Present
(IP_Call
) then
2408 IP_Stmts
:= New_List
;
2410 Stmt
:= Remove_Head
(Stmts
);
2411 Append_To
(IP_Stmts
, Stmt
);
2412 exit when Stmt
= IP_Call
;
2415 Prepend_List_To
(Body_Stmts
, IP_Stmts
);
2420 Append_List_To
(Body_Stmts
, Stmts
);
2425 -- Add here the assignment to instantiate the Tag
2427 -- The assignment corresponds to the code:
2429 -- _Init._Tag := Typ'Tag;
2431 -- Suppress the tag assignment when not Tagged_Type_Expansion because
2432 -- tags are represented implicitly in objects. It is also suppressed
2433 -- in case of CPP_Class types because in this case the tag is
2434 -- initialized in the C++ side.
2436 if Is_Tagged_Type
(Rec_Type
)
2437 and then Tagged_Type_Expansion
2438 and then not No_Run_Time_Mode
2440 -- Case 1: Ada tagged types with no CPP ancestor. Set the tags of
2441 -- the actual object and invoke the IP of the parent (in this
2442 -- order). The tag must be initialized before the call to the IP
2443 -- of the parent and the assignments to other components because
2444 -- the initial value of the components may depend on the tag (eg.
2445 -- through a dispatching operation on an access to the current
2446 -- type). The tag assignment is not done when initializing the
2447 -- parent component of a type extension, because in that case the
2448 -- tag is set in the extension.
2450 if not Is_CPP_Class
(Root_Type
(Rec_Type
)) then
2452 -- Initialize the primary tag component
2454 Init_Tags_List
:= New_List
(
2455 Make_Assignment_Statement
(Loc
,
2457 Make_Selected_Component
(Loc
,
2458 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2461 (First_Tag_Component
(Rec_Type
), Loc
)),
2465 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2467 -- Ada 2005 (AI-251): Initialize the secondary tags components
2468 -- located at fixed positions (tags whose position depends on
2469 -- variable size components are initialized later ---see below)
2471 if Ada_Version
>= Ada_2005
2472 and then not Is_Interface
(Rec_Type
)
2473 and then Has_Interfaces
(Rec_Type
)
2477 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2478 Stmts_List
=> Init_Tags_List
,
2479 Fixed_Comps
=> True,
2480 Variable_Comps
=> False);
2483 Prepend_To
(Body_Stmts
,
2484 Make_If_Statement
(Loc
,
2485 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2486 Then_Statements
=> Init_Tags_List
));
2488 -- Case 2: CPP type. The imported C++ constructor takes care of
2489 -- tags initialization. No action needed here because the IP
2490 -- is built by Set_CPP_Constructors; in this case the IP is a
2491 -- wrapper that invokes the C++ constructor and copies the C++
2492 -- tags locally. Done to inherit the C++ slots in Ada derivations
2495 elsif Is_CPP_Class
(Rec_Type
) then
2496 pragma Assert
(False);
2499 -- Case 3: Combined hierarchy containing C++ types and Ada tagged
2500 -- type derivations. Derivations of imported C++ classes add a
2501 -- complication, because we cannot inhibit tag setting in the
2502 -- constructor for the parent. Hence we initialize the tag after
2503 -- the call to the parent IP (that is, in reverse order compared
2504 -- with pure Ada hierarchies ---see comment on case 1).
2507 -- Initialize the primary tag
2509 Init_Tags_List
:= New_List
(
2510 Make_Assignment_Statement
(Loc
,
2512 Make_Selected_Component
(Loc
,
2513 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2516 (First_Tag_Component
(Rec_Type
), Loc
)),
2520 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2522 -- Ada 2005 (AI-251): Initialize the secondary tags components
2523 -- located at fixed positions (tags whose position depends on
2524 -- variable size components are initialized later ---see below)
2526 if Ada_Version
>= Ada_2005
2527 and then not Is_Interface
(Rec_Type
)
2528 and then Has_Interfaces
(Rec_Type
)
2532 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2533 Stmts_List
=> Init_Tags_List
,
2534 Fixed_Comps
=> True,
2535 Variable_Comps
=> False);
2538 -- Initialize the tag component after invocation of parent IP.
2541 -- parent_IP(_init.parent); // Invokes the C++ constructor
2542 -- [ typIC; ] // Inherit C++ slots from parent
2549 -- Search for the call to the IP of the parent. We assume
2550 -- that the first init_proc call is for the parent.
2552 Ins_Nod
:= First
(Body_Stmts
);
2553 while Present
(Next
(Ins_Nod
))
2554 and then (Nkind
(Ins_Nod
) /= N_Procedure_Call_Statement
2555 or else not Is_Init_Proc
(Name
(Ins_Nod
)))
2560 -- The IC routine copies the inherited slots of the C+ part
2561 -- of the dispatch table from the parent and updates the
2562 -- overridden C++ slots.
2564 if CPP_Num_Prims
(Rec_Type
) > 0 then
2566 Init_DT
: Entity_Id
;
2570 Init_DT
:= CPP_Init_Proc
(Rec_Type
);
2571 pragma Assert
(Present
(Init_DT
));
2574 Make_Procedure_Call_Statement
(Loc
,
2575 New_Occurrence_Of
(Init_DT
, Loc
));
2576 Insert_After
(Ins_Nod
, New_Nod
);
2578 -- Update location of init tag statements
2584 Insert_List_After
(Ins_Nod
, Init_Tags_List
);
2588 -- Ada 2005 (AI-251): Initialize the secondary tag components
2589 -- located at variable positions. We delay the generation of this
2590 -- code until here because the value of the attribute 'Position
2591 -- applied to variable size components of the parent type that
2592 -- depend on discriminants is only safely read at runtime after
2593 -- the parent components have been initialized.
2595 if Ada_Version
>= Ada_2005
2596 and then not Is_Interface
(Rec_Type
)
2597 and then Has_Interfaces
(Rec_Type
)
2598 and then Has_Discriminants
(Etype
(Rec_Type
))
2599 and then Is_Variable_Size_Record
(Etype
(Rec_Type
))
2601 Init_Tags_List
:= New_List
;
2605 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2606 Stmts_List
=> Init_Tags_List
,
2607 Fixed_Comps
=> False,
2608 Variable_Comps
=> True);
2610 if Is_Non_Empty_List
(Init_Tags_List
) then
2611 Append_List_To
(Body_Stmts
, Init_Tags_List
);
2616 Handled_Stmt_Node
:= New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2617 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2620 -- Deep_Finalize (_init, C1, ..., CN);
2624 and then Needs_Finalization
(Rec_Type
)
2625 and then not Is_Abstract_Type
(Rec_Type
)
2626 and then not Restriction_Active
(No_Exception_Propagation
)
2633 -- Create a local version of Deep_Finalize which has indication
2634 -- of partial initialization state.
2636 DF_Id
:= Make_Temporary
(Loc
, 'F');
2638 Append_To
(Decls
, Make_Local_Deep_Finalize
(Rec_Type
, DF_Id
));
2641 Make_Procedure_Call_Statement
(Loc
,
2642 Name
=> New_Occurrence_Of
(DF_Id
, Loc
),
2643 Parameter_Associations
=> New_List
(
2644 Make_Identifier
(Loc
, Name_uInit
),
2645 New_Occurrence_Of
(Standard_False
, Loc
)));
2647 -- Do not emit warnings related to the elaboration order when a
2648 -- controlled object is declared before the body of Finalize is
2651 Set_No_Elaboration_Check
(DF_Call
);
2653 Set_Exception_Handlers
(Handled_Stmt_Node
, New_List
(
2654 Make_Exception_Handler
(Loc
,
2655 Exception_Choices
=> New_List
(
2656 Make_Others_Choice
(Loc
)),
2657 Statements
=> New_List
(
2659 Make_Raise_Statement
(Loc
)))));
2662 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2665 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2667 if not Debug_Generated_Code
then
2668 Set_Debug_Info_Off
(Proc_Id
);
2671 -- Associate Init_Proc with type, and determine if the procedure
2672 -- is null (happens because of the Initialize_Scalars pragma case,
2673 -- where we have to generate a null procedure in case it is called
2674 -- by a client with Initialize_Scalars set). Such procedures have
2675 -- to be generated, but do not have to be called, so we mark them
2676 -- as null to suppress the call.
2678 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2680 if List_Length
(Body_Stmts
) = 1
2682 -- We must skip SCIL nodes because they may have been added to this
2683 -- list by Insert_Actions.
2685 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
2687 Set_Is_Null_Init_Proc
(Proc_Id
);
2689 end Build_Init_Procedure
;
2691 ---------------------------
2692 -- Build_Init_Statements --
2693 ---------------------------
2695 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
is
2696 Checks
: constant List_Id
:= New_List
;
2697 Actions
: List_Id
:= No_List
;
2698 Counter_Id
: Entity_Id
:= Empty
;
2699 Comp_Loc
: Source_Ptr
;
2703 Parent_Stmts
: List_Id
;
2707 procedure Increment_Counter
(Loc
: Source_Ptr
);
2708 -- Generate an "increment by one" statement for the current counter
2709 -- and append it to the list Stmts.
2711 procedure Make_Counter
(Loc
: Source_Ptr
);
2712 -- Create a new counter for the current component list. The routine
2713 -- creates a new defining Id, adds an object declaration and sets
2714 -- the Id generator for the next variant.
2716 -----------------------
2717 -- Increment_Counter --
2718 -----------------------
2720 procedure Increment_Counter
(Loc
: Source_Ptr
) is
2723 -- Counter := Counter + 1;
2726 Make_Assignment_Statement
(Loc
,
2727 Name
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2730 Left_Opnd
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2731 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
2732 end Increment_Counter
;
2738 procedure Make_Counter
(Loc
: Source_Ptr
) is
2740 -- Increment the Id generator
2742 Counter
:= Counter
+ 1;
2744 -- Create the entity and declaration
2747 Make_Defining_Identifier
(Loc
,
2748 Chars
=> New_External_Name
('C', Counter
));
2751 -- Cnn : Integer := 0;
2754 Make_Object_Declaration
(Loc
,
2755 Defining_Identifier
=> Counter_Id
,
2756 Object_Definition
=>
2757 New_Occurrence_Of
(Standard_Integer
, Loc
),
2759 Make_Integer_Literal
(Loc
, 0)));
2762 -- Start of processing for Build_Init_Statements
2765 if Null_Present
(Comp_List
) then
2766 return New_List
(Make_Null_Statement
(Loc
));
2769 Parent_Stmts
:= New_List
;
2772 -- Loop through visible declarations of task types and protected
2773 -- types moving any expanded code from the spec to the body of the
2776 if Is_Task_Record_Type
(Rec_Type
)
2777 or else Is_Protected_Record_Type
(Rec_Type
)
2780 Decl
: constant Node_Id
:=
2781 Parent
(Corresponding_Concurrent_Type
(Rec_Type
));
2787 if Is_Task_Record_Type
(Rec_Type
) then
2788 Def
:= Task_Definition
(Decl
);
2790 Def
:= Protected_Definition
(Decl
);
2793 if Present
(Def
) then
2794 N1
:= First
(Visible_Declarations
(Def
));
2795 while Present
(N1
) loop
2799 if Nkind
(N2
) in N_Statement_Other_Than_Procedure_Call
2800 or else Nkind
(N2
) in N_Raise_xxx_Error
2801 or else Nkind
(N2
) = N_Procedure_Call_Statement
2804 New_Copy_Tree
(N2
, New_Scope
=> Proc_Id
));
2805 Rewrite
(N2
, Make_Null_Statement
(Sloc
(N2
)));
2813 -- Loop through components, skipping pragmas, in 2 steps. The first
2814 -- step deals with regular components. The second step deals with
2815 -- components that have per object constraints and no explicit
2820 -- First pass : regular components
2822 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
2823 while Present
(Decl
) loop
2824 Comp_Loc
:= Sloc
(Decl
);
2826 (Subtype_Indication
(Component_Definition
(Decl
)), Checks
);
2828 Id
:= Defining_Identifier
(Decl
);
2831 -- Leave any processing of per-object constrained component for
2834 if Has_Access_Constraint
(Id
) and then No
(Expression
(Decl
)) then
2837 -- Regular component cases
2840 -- In the context of the init proc, references to discriminants
2841 -- resolve to denote the discriminals: this is where we can
2842 -- freeze discriminant dependent component subtypes.
2844 if not Is_Frozen
(Typ
) then
2845 Append_List_To
(Stmts
, Freeze_Entity
(Typ
, N
));
2848 -- Explicit initialization
2850 if Present
(Expression
(Decl
)) then
2851 if Is_CPP_Constructor_Call
(Expression
(Decl
)) then
2853 Build_Initialization_Call
2856 Make_Selected_Component
(Comp_Loc
,
2858 Make_Identifier
(Comp_Loc
, Name_uInit
),
2860 New_Occurrence_Of
(Id
, Comp_Loc
)),
2862 In_Init_Proc
=> True,
2863 Enclos_Type
=> Rec_Type
,
2864 Discr_Map
=> Discr_Map
,
2865 Constructor_Ref
=> Expression
(Decl
));
2867 Actions
:= Build_Assignment
(Id
, Expression
(Decl
));
2870 -- CPU, Dispatching_Domain, Priority and Size components are
2871 -- filled with the corresponding rep item expression of the
2872 -- concurrent type (if any).
2874 elsif Ekind
(Scope
(Id
)) = E_Record_Type
2875 and then Present
(Corresponding_Concurrent_Type
(Scope
(Id
)))
2876 and then Nam_In
(Chars
(Id
), Name_uCPU
,
2877 Name_uDispatching_Domain
,
2886 if Chars
(Id
) = Name_uCPU
then
2889 elsif Chars
(Id
) = Name_uDispatching_Domain
then
2890 Nam
:= Name_Dispatching_Domain
;
2892 elsif Chars
(Id
) = Name_uPriority
then
2893 Nam
:= Name_Priority
;
2896 -- Get the Rep Item (aspect specification, attribute
2897 -- definition clause or pragma) of the corresponding
2902 (Corresponding_Concurrent_Type
(Scope
(Id
)),
2904 Check_Parents
=> False);
2906 if Present
(Ritem
) then
2910 if Nkind
(Ritem
) = N_Pragma
then
2911 Exp
:= First
(Pragma_Argument_Associations
(Ritem
));
2913 if Nkind
(Exp
) = N_Pragma_Argument_Association
then
2914 Exp
:= Expression
(Exp
);
2917 -- Conversion for Priority expression
2919 if Nam
= Name_Priority
then
2920 if Pragma_Name
(Ritem
) = Name_Priority
2921 and then not GNAT_Mode
2923 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
2926 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
2930 -- Aspect/Attribute definition clause case
2933 Exp
:= Expression
(Ritem
);
2935 -- Conversion for Priority expression
2937 if Nam
= Name_Priority
then
2938 if Chars
(Ritem
) = Name_Priority
2939 and then not GNAT_Mode
2941 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
2944 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
2949 -- Conversion for Dispatching_Domain value
2951 if Nam
= Name_Dispatching_Domain
then
2953 Unchecked_Convert_To
2954 (RTE
(RE_Dispatching_Domain_Access
), Exp
);
2957 Actions
:= Build_Assignment
(Id
, Exp
);
2959 -- Nothing needed if no Rep Item
2966 -- Composite component with its own Init_Proc
2968 elsif not Is_Interface
(Typ
)
2969 and then Has_Non_Null_Base_Init_Proc
(Typ
)
2972 Build_Initialization_Call
2974 Make_Selected_Component
(Comp_Loc
,
2976 Make_Identifier
(Comp_Loc
, Name_uInit
),
2977 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
2979 In_Init_Proc
=> True,
2980 Enclos_Type
=> Rec_Type
,
2981 Discr_Map
=> Discr_Map
);
2983 Clean_Task_Names
(Typ
, Proc_Id
);
2985 -- Simple initialization
2987 elsif Component_Needs_Simple_Initialization
(Typ
) then
2990 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
)));
2992 -- Nothing needed for this case
2998 if Present
(Checks
) then
2999 if Chars
(Id
) = Name_uParent
then
3000 Append_List_To
(Parent_Stmts
, Checks
);
3002 Append_List_To
(Stmts
, Checks
);
3006 if Present
(Actions
) then
3007 if Chars
(Id
) = Name_uParent
then
3008 Append_List_To
(Parent_Stmts
, Actions
);
3011 Append_List_To
(Stmts
, Actions
);
3013 -- Preserve initialization state in the current counter
3015 if Needs_Finalization
(Typ
) then
3016 if No
(Counter_Id
) then
3017 Make_Counter
(Comp_Loc
);
3020 Increment_Counter
(Comp_Loc
);
3026 Next_Non_Pragma
(Decl
);
3029 -- The parent field must be initialized first because variable
3030 -- size components of the parent affect the location of all the
3033 Prepend_List_To
(Stmts
, Parent_Stmts
);
3035 -- Set up tasks and protected object support. This needs to be done
3036 -- before any component with a per-object access discriminant
3037 -- constraint, or any variant part (which may contain such
3038 -- components) is initialized, because the initialization of these
3039 -- components may reference the enclosing concurrent object.
3041 -- For a task record type, add the task create call and calls to bind
3042 -- any interrupt (signal) entries.
3044 if Is_Task_Record_Type
(Rec_Type
) then
3046 -- In the case of the restricted run time the ATCB has already
3047 -- been preallocated.
3049 if Restricted_Profile
then
3051 Make_Assignment_Statement
(Loc
,
3053 Make_Selected_Component
(Loc
,
3054 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3055 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3057 Make_Attribute_Reference
(Loc
,
3059 Make_Selected_Component
(Loc
,
3060 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3061 Selector_Name
=> Make_Identifier
(Loc
, Name_uATCB
)),
3062 Attribute_Name
=> Name_Unchecked_Access
)));
3065 Append_To
(Stmts
, Make_Task_Create_Call
(Rec_Type
));
3068 Task_Type
: constant Entity_Id
:=
3069 Corresponding_Concurrent_Type
(Rec_Type
);
3070 Task_Decl
: constant Node_Id
:= Parent
(Task_Type
);
3071 Task_Def
: constant Node_Id
:= Task_Definition
(Task_Decl
);
3072 Decl_Loc
: Source_Ptr
;
3077 if Present
(Task_Def
) then
3078 Vis_Decl
:= First
(Visible_Declarations
(Task_Def
));
3079 while Present
(Vis_Decl
) loop
3080 Decl_Loc
:= Sloc
(Vis_Decl
);
3082 if Nkind
(Vis_Decl
) = N_Attribute_Definition_Clause
then
3083 if Get_Attribute_Id
(Chars
(Vis_Decl
)) =
3086 Ent
:= Entity
(Name
(Vis_Decl
));
3088 if Ekind
(Ent
) = E_Entry
then
3090 Make_Procedure_Call_Statement
(Decl_Loc
,
3092 New_Occurrence_Of
(RTE
(
3093 RE_Bind_Interrupt_To_Entry
), Decl_Loc
),
3094 Parameter_Associations
=> New_List
(
3095 Make_Selected_Component
(Decl_Loc
,
3097 Make_Identifier
(Decl_Loc
, Name_uInit
),
3100 (Decl_Loc
, Name_uTask_Id
)),
3101 Entry_Index_Expression
3102 (Decl_Loc
, Ent
, Empty
, Task_Type
),
3103 Expression
(Vis_Decl
))));
3114 -- For a protected type, add statements generated by
3115 -- Make_Initialize_Protection.
3117 if Is_Protected_Record_Type
(Rec_Type
) then
3118 Append_List_To
(Stmts
,
3119 Make_Initialize_Protection
(Rec_Type
));
3122 -- Second pass: components with per-object constraints
3125 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3126 while Present
(Decl
) loop
3127 Comp_Loc
:= Sloc
(Decl
);
3128 Id
:= Defining_Identifier
(Decl
);
3131 if Has_Access_Constraint
(Id
)
3132 and then No
(Expression
(Decl
))
3134 if Has_Non_Null_Base_Init_Proc
(Typ
) then
3135 Append_List_To
(Stmts
,
3136 Build_Initialization_Call
(Comp_Loc
,
3137 Make_Selected_Component
(Comp_Loc
,
3139 Make_Identifier
(Comp_Loc
, Name_uInit
),
3140 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3142 In_Init_Proc
=> True,
3143 Enclos_Type
=> Rec_Type
,
3144 Discr_Map
=> Discr_Map
));
3146 Clean_Task_Names
(Typ
, Proc_Id
);
3148 -- Preserve initialization state in the current counter
3150 if Needs_Finalization
(Typ
) then
3151 if No
(Counter_Id
) then
3152 Make_Counter
(Comp_Loc
);
3155 Increment_Counter
(Comp_Loc
);
3158 elsif Component_Needs_Simple_Initialization
(Typ
) then
3159 Append_List_To
(Stmts
,
3161 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
))));
3165 Next_Non_Pragma
(Decl
);
3169 -- Process the variant part
3171 if Present
(Variant_Part
(Comp_List
)) then
3173 Variant_Alts
: constant List_Id
:= New_List
;
3174 Var_Loc
: Source_Ptr
;
3179 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3180 while Present
(Variant
) loop
3181 Var_Loc
:= Sloc
(Variant
);
3182 Append_To
(Variant_Alts
,
3183 Make_Case_Statement_Alternative
(Var_Loc
,
3185 New_Copy_List
(Discrete_Choices
(Variant
)),
3187 Build_Init_Statements
(Component_List
(Variant
))));
3188 Next_Non_Pragma
(Variant
);
3191 -- The expression of the case statement which is a reference
3192 -- to one of the discriminants is replaced by the appropriate
3193 -- formal parameter of the initialization procedure.
3196 Make_Case_Statement
(Var_Loc
,
3198 New_Occurrence_Of
(Discriminal
(
3199 Entity
(Name
(Variant_Part
(Comp_List
)))), Var_Loc
),
3200 Alternatives
=> Variant_Alts
));
3204 -- If no initializations when generated for component declarations
3205 -- corresponding to this Stmts, append a null statement to Stmts to
3206 -- to make it a valid Ada tree.
3208 if Is_Empty_List
(Stmts
) then
3209 Append
(Make_Null_Statement
(Loc
), Stmts
);
3215 when RE_Not_Available
=>
3217 end Build_Init_Statements
;
3219 -------------------------
3220 -- Build_Record_Checks --
3221 -------------------------
3223 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
) is
3224 Subtype_Mark_Id
: Entity_Id
;
3226 procedure Constrain_Array
3228 Check_List
: List_Id
);
3229 -- Apply a list of index constraints to an unconstrained array type.
3230 -- The first parameter is the entity for the resulting subtype.
3231 -- Check_List is a list to which the check actions are appended.
3233 ---------------------
3234 -- Constrain_Array --
3235 ---------------------
3237 procedure Constrain_Array
3239 Check_List
: List_Id
)
3241 C
: constant Node_Id
:= Constraint
(SI
);
3242 Number_Of_Constraints
: Nat
:= 0;
3246 procedure Constrain_Index
3249 Check_List
: List_Id
);
3250 -- Process an index constraint in a constrained array declaration.
3251 -- The constraint can be either a subtype name or a range with or
3252 -- without an explicit subtype mark. Index is the corresponding
3253 -- index of the unconstrained array. S is the range expression.
3254 -- Check_List is a list to which the check actions are appended.
3256 ---------------------
3257 -- Constrain_Index --
3258 ---------------------
3260 procedure Constrain_Index
3263 Check_List
: List_Id
)
3265 T
: constant Entity_Id
:= Etype
(Index
);
3268 if Nkind
(S
) = N_Range
then
3269 Process_Range_Expr_In_Decl
(S
, T
, Check_List
=> Check_List
);
3271 end Constrain_Index
;
3273 -- Start of processing for Constrain_Array
3276 T
:= Entity
(Subtype_Mark
(SI
));
3278 if Is_Access_Type
(T
) then
3279 T
:= Designated_Type
(T
);
3282 S
:= First
(Constraints
(C
));
3283 while Present
(S
) loop
3284 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
3288 -- In either case, the index constraint must provide a discrete
3289 -- range for each index of the array type and the type of each
3290 -- discrete range must be the same as that of the corresponding
3291 -- index. (RM 3.6.1)
3293 S
:= First
(Constraints
(C
));
3294 Index
:= First_Index
(T
);
3297 -- Apply constraints to each index type
3299 for J
in 1 .. Number_Of_Constraints
loop
3300 Constrain_Index
(Index
, S
, Check_List
);
3304 end Constrain_Array
;
3306 -- Start of processing for Build_Record_Checks
3309 if Nkind
(S
) = N_Subtype_Indication
then
3310 Find_Type
(Subtype_Mark
(S
));
3311 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
3313 -- Remaining processing depends on type
3315 case Ekind
(Subtype_Mark_Id
) is
3318 Constrain_Array
(S
, Check_List
);
3324 end Build_Record_Checks
;
3326 -------------------------------------------
3327 -- Component_Needs_Simple_Initialization --
3328 -------------------------------------------
3330 function Component_Needs_Simple_Initialization
3331 (T
: Entity_Id
) return Boolean
3335 Needs_Simple_Initialization
(T
)
3336 and then not Is_RTE
(T
, RE_Tag
)
3338 -- Ada 2005 (AI-251): Check also the tag of abstract interfaces
3340 and then not Is_RTE
(T
, RE_Interface_Tag
);
3341 end Component_Needs_Simple_Initialization
;
3343 --------------------------------------
3344 -- Parent_Subtype_Renaming_Discrims --
3345 --------------------------------------
3347 function Parent_Subtype_Renaming_Discrims
return Boolean is
3352 if Base_Type
(Rec_Ent
) /= Rec_Ent
then
3356 if Etype
(Rec_Ent
) = Rec_Ent
3357 or else not Has_Discriminants
(Rec_Ent
)
3358 or else Is_Constrained
(Rec_Ent
)
3359 or else Is_Tagged_Type
(Rec_Ent
)
3364 -- If there are no explicit stored discriminants we have inherited
3365 -- the root type discriminants so far, so no renamings occurred.
3367 if First_Discriminant
(Rec_Ent
) =
3368 First_Stored_Discriminant
(Rec_Ent
)
3373 -- Check if we have done some trivial renaming of the parent
3374 -- discriminants, i.e. something like
3376 -- type DT (X1, X2: int) is new PT (X1, X2);
3378 De
:= First_Discriminant
(Rec_Ent
);
3379 Dp
:= First_Discriminant
(Etype
(Rec_Ent
));
3380 while Present
(De
) loop
3381 pragma Assert
(Present
(Dp
));
3383 if Corresponding_Discriminant
(De
) /= Dp
then
3387 Next_Discriminant
(De
);
3388 Next_Discriminant
(Dp
);
3391 return Present
(Dp
);
3392 end Parent_Subtype_Renaming_Discrims
;
3394 ------------------------
3395 -- Requires_Init_Proc --
3396 ------------------------
3398 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean is
3399 Comp_Decl
: Node_Id
;
3404 -- Definitely do not need one if specifically suppressed
3406 if Initialization_Suppressed
(Rec_Id
) then
3410 -- If it is a type derived from a type with unknown discriminants,
3411 -- we cannot build an initialization procedure for it.
3413 if Has_Unknown_Discriminants
(Rec_Id
)
3414 or else Has_Unknown_Discriminants
(Etype
(Rec_Id
))
3419 -- Otherwise we need to generate an initialization procedure if
3420 -- Is_CPP_Class is False and at least one of the following applies:
3422 -- 1. Discriminants are present, since they need to be initialized
3423 -- with the appropriate discriminant constraint expressions.
3424 -- However, the discriminant of an unchecked union does not
3425 -- count, since the discriminant is not present.
3427 -- 2. The type is a tagged type, since the implicit Tag component
3428 -- needs to be initialized with a pointer to the dispatch table.
3430 -- 3. The type contains tasks
3432 -- 4. One or more components has an initial value
3434 -- 5. One or more components is for a type which itself requires
3435 -- an initialization procedure.
3437 -- 6. One or more components is a type that requires simple
3438 -- initialization (see Needs_Simple_Initialization), except
3439 -- that types Tag and Interface_Tag are excluded, since fields
3440 -- of these types are initialized by other means.
3442 -- 7. The type is the record type built for a task type (since at
3443 -- the very least, Create_Task must be called)
3445 -- 8. The type is the record type built for a protected type (since
3446 -- at least Initialize_Protection must be called)
3448 -- 9. The type is marked as a public entity. The reason we add this
3449 -- case (even if none of the above apply) is to properly handle
3450 -- Initialize_Scalars. If a package is compiled without an IS
3451 -- pragma, and the client is compiled with an IS pragma, then
3452 -- the client will think an initialization procedure is present
3453 -- and call it, when in fact no such procedure is required, but
3454 -- since the call is generated, there had better be a routine
3455 -- at the other end of the call, even if it does nothing).
3457 -- Note: the reason we exclude the CPP_Class case is because in this
3458 -- case the initialization is performed by the C++ constructors, and
3459 -- the IP is built by Set_CPP_Constructors.
3461 if Is_CPP_Class
(Rec_Id
) then
3464 elsif Is_Interface
(Rec_Id
) then
3467 elsif (Has_Discriminants
(Rec_Id
)
3468 and then not Is_Unchecked_Union
(Rec_Id
))
3469 or else Is_Tagged_Type
(Rec_Id
)
3470 or else Is_Concurrent_Record_Type
(Rec_Id
)
3471 or else Has_Task
(Rec_Id
)
3476 Id
:= First_Component
(Rec_Id
);
3477 while Present
(Id
) loop
3478 Comp_Decl
:= Parent
(Id
);
3481 if Present
(Expression
(Comp_Decl
))
3482 or else Has_Non_Null_Base_Init_Proc
(Typ
)
3483 or else Component_Needs_Simple_Initialization
(Typ
)
3488 Next_Component
(Id
);
3491 -- As explained above, a record initialization procedure is needed
3492 -- for public types in case Initialize_Scalars applies to a client.
3493 -- However, such a procedure is not needed in the case where either
3494 -- of restrictions No_Initialize_Scalars or No_Default_Initialization
3495 -- applies. No_Initialize_Scalars excludes the possibility of using
3496 -- Initialize_Scalars in any partition, and No_Default_Initialization
3497 -- implies that no initialization should ever be done for objects of
3498 -- the type, so is incompatible with Initialize_Scalars.
3500 if not Restriction_Active
(No_Initialize_Scalars
)
3501 and then not Restriction_Active
(No_Default_Initialization
)
3502 and then Is_Public
(Rec_Id
)
3508 end Requires_Init_Proc
;
3510 -- Start of processing for Build_Record_Init_Proc
3513 Rec_Type
:= Defining_Identifier
(N
);
3515 -- This may be full declaration of a private type, in which case
3516 -- the visible entity is a record, and the private entity has been
3517 -- exchanged with it in the private part of the current package.
3518 -- The initialization procedure is built for the record type, which
3519 -- is retrievable from the private entity.
3521 if Is_Incomplete_Or_Private_Type
(Rec_Type
) then
3522 Rec_Type
:= Underlying_Type
(Rec_Type
);
3525 -- If we have a variant record with restriction No_Implicit_Conditionals
3526 -- in effect, then we skip building the procedure. This is safe because
3527 -- if we can see the restriction, so can any caller, calls to initialize
3528 -- such records are not allowed for variant records if this restriction
3531 if Has_Variant_Part
(Rec_Type
)
3532 and then Restriction_Active
(No_Implicit_Conditionals
)
3537 -- If there are discriminants, build the discriminant map to replace
3538 -- discriminants by their discriminals in complex bound expressions.
3539 -- These only arise for the corresponding records of synchronized types.
3541 if Is_Concurrent_Record_Type
(Rec_Type
)
3542 and then Has_Discriminants
(Rec_Type
)
3547 Disc
:= First_Discriminant
(Rec_Type
);
3548 while Present
(Disc
) loop
3549 Append_Elmt
(Disc
, Discr_Map
);
3550 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
3551 Next_Discriminant
(Disc
);
3556 -- Derived types that have no type extension can use the initialization
3557 -- procedure of their parent and do not need a procedure of their own.
3558 -- This is only correct if there are no representation clauses for the
3559 -- type or its parent, and if the parent has in fact been frozen so
3560 -- that its initialization procedure exists.
3562 if Is_Derived_Type
(Rec_Type
)
3563 and then not Is_Tagged_Type
(Rec_Type
)
3564 and then not Is_Unchecked_Union
(Rec_Type
)
3565 and then not Has_New_Non_Standard_Rep
(Rec_Type
)
3566 and then not Parent_Subtype_Renaming_Discrims
3567 and then Has_Non_Null_Base_Init_Proc
(Etype
(Rec_Type
))
3569 Copy_TSS
(Base_Init_Proc
(Etype
(Rec_Type
)), Rec_Type
);
3571 -- Otherwise if we need an initialization procedure, then build one,
3572 -- mark it as public and inlinable and as having a completion.
3574 elsif Requires_Init_Proc
(Rec_Type
)
3575 or else Is_Unchecked_Union
(Rec_Type
)
3578 Make_Defining_Identifier
(Loc
,
3579 Chars
=> Make_Init_Proc_Name
(Rec_Type
));
3581 -- If No_Default_Initialization restriction is active, then we don't
3582 -- want to build an init_proc, but we need to mark that an init_proc
3583 -- would be needed if this restriction was not active (so that we can
3584 -- detect attempts to call it), so set a dummy init_proc in place.
3586 if Restriction_Active
(No_Default_Initialization
) then
3587 Set_Init_Proc
(Rec_Type
, Proc_Id
);
3591 Build_Offset_To_Top_Functions
;
3592 Build_CPP_Init_Procedure
;
3593 Build_Init_Procedure
;
3595 Set_Is_Public
(Proc_Id
, Is_Public
(Rec_Ent
));
3596 Set_Is_Internal
(Proc_Id
);
3597 Set_Has_Completion
(Proc_Id
);
3599 if not Debug_Generated_Code
then
3600 Set_Debug_Info_Off
(Proc_Id
);
3603 Set_Is_Inlined
(Proc_Id
, Inline_Init_Proc
(Rec_Type
));
3605 -- Do not build an aggregate if Modify_Tree_For_C, this isn't
3606 -- needed and may generate early references to non frozen types
3607 -- since we expand aggregate much more systematically.
3609 if Modify_Tree_For_C
then
3614 Agg
: constant Node_Id
:=
3615 Build_Equivalent_Record_Aggregate
(Rec_Type
);
3617 procedure Collect_Itypes
(Comp
: Node_Id
);
3618 -- Generate references to itypes in the aggregate, because
3619 -- the first use of the aggregate may be in a nested scope.
3621 --------------------
3622 -- Collect_Itypes --
3623 --------------------
3625 procedure Collect_Itypes
(Comp
: Node_Id
) is
3628 Typ
: constant Entity_Id
:= Etype
(Comp
);
3631 if Is_Array_Type
(Typ
) and then Is_Itype
(Typ
) then
3632 Ref
:= Make_Itype_Reference
(Loc
);
3633 Set_Itype
(Ref
, Typ
);
3634 Append_Freeze_Action
(Rec_Type
, Ref
);
3636 Ref
:= Make_Itype_Reference
(Loc
);
3637 Set_Itype
(Ref
, Etype
(First_Index
(Typ
)));
3638 Append_Freeze_Action
(Rec_Type
, Ref
);
3640 -- Recurse on nested arrays
3642 Sub_Aggr
:= First
(Expressions
(Comp
));
3643 while Present
(Sub_Aggr
) loop
3644 Collect_Itypes
(Sub_Aggr
);
3651 -- If there is a static initialization aggregate for the type,
3652 -- generate itype references for the types of its (sub)components,
3653 -- to prevent out-of-scope errors in the resulting tree.
3654 -- The aggregate may have been rewritten as a Raise node, in which
3655 -- case there are no relevant itypes.
3657 if Present
(Agg
) and then Nkind
(Agg
) = N_Aggregate
then
3658 Set_Static_Initialization
(Proc_Id
, Agg
);
3663 Comp
:= First
(Component_Associations
(Agg
));
3664 while Present
(Comp
) loop
3665 Collect_Itypes
(Expression
(Comp
));
3672 end Build_Record_Init_Proc
;
3674 --------------------------------
3675 -- Build_Record_Invariant_Proc --
3676 --------------------------------
3678 function Build_Record_Invariant_Proc
3679 (R_Type
: Entity_Id
;
3680 Nod
: Node_Id
) return Node_Id
3682 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
3684 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
3685 -- Name for argument of invariant procedure
3687 Object_Entity
: constant Node_Id
:=
3688 Make_Defining_Identifier
(Loc
, Object_Name
);
3689 -- The procedure declaration entity for the argument
3691 Invariant_Found
: Boolean;
3692 -- Set if any component needs an invariant check.
3694 Proc_Id
: Entity_Id
;
3695 Proc_Body
: Node_Id
;
3699 function Build_Invariant_Checks
(Comp_List
: Node_Id
) return List_Id
;
3700 -- Recursive procedure that generates a list of checks for components
3701 -- that need it, and recurses through variant parts when present.
3703 function Build_Component_Invariant_Call
3704 (Comp
: Entity_Id
) return Node_Id
;
3705 -- Build call to invariant procedure for a record component
3707 ------------------------------------
3708 -- Build_Component_Invariant_Call --
3709 ------------------------------------
3711 function Build_Component_Invariant_Call
3712 (Comp
: Entity_Id
) return Node_Id
3720 Typ
:= Etype
(Comp
);
3723 Make_Selected_Component
(Loc
,
3724 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
3725 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
3727 if Is_Access_Type
(Typ
) then
3729 -- If the access component designates a type with an invariant,
3730 -- the check applies to the designated object. The access type
3731 -- itself may have an invariant, in which case it applies to the
3732 -- access value directly.
3734 -- Note: we are assuming that invariants will not occur on both
3735 -- the access type and the type that it designates. This is not
3736 -- really justified but it is hard to imagine that this case will
3737 -- ever cause trouble ???
3739 if not (Has_Invariants
(Typ
)) then
3740 Sel_Comp
:= Make_Explicit_Dereference
(Loc
, Sel_Comp
);
3741 Typ
:= Designated_Type
(Typ
);
3745 -- The aspect is type-specific, so retrieve it from the base type
3747 Proc
:= Invariant_Procedure
(Base_Type
(Typ
));
3749 if Has_Null_Body
(Proc
) then
3750 return Make_Null_Statement
(Loc
);
3753 Invariant_Found
:= True;
3755 Make_Procedure_Call_Statement
(Loc
,
3756 Name
=> New_Occurrence_Of
(Proc
, Loc
),
3757 Parameter_Associations
=> New_List
(Sel_Comp
));
3759 if Is_Access_Type
(Etype
(Comp
)) then
3761 Make_If_Statement
(Loc
,
3764 Left_Opnd
=> Make_Null
(Loc
),
3766 Make_Selected_Component
(Loc
,
3768 New_Occurrence_Of
(Object_Entity
, Loc
),
3769 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
))),
3770 Then_Statements
=> New_List
(Call
));
3774 end Build_Component_Invariant_Call
;
3776 ----------------------------
3777 -- Build_Invariant_Checks --
3778 ----------------------------
3780 function Build_Invariant_Checks
(Comp_List
: Node_Id
) return List_Id
is
3787 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3788 while Present
(Decl
) loop
3789 if Nkind
(Decl
) = N_Component_Declaration
then
3790 Id
:= Defining_Identifier
(Decl
);
3792 if Has_Invariants
(Etype
(Id
))
3793 and then In_Open_Scopes
(Scope
(R_Type
))
3795 if Has_Unchecked_Union
(R_Type
) then
3797 ("invariants cannot be checked on components of "
3798 & "unchecked_union type&?", Decl
, R_Type
);
3802 Append_To
(Stmts
, Build_Component_Invariant_Call
(Id
));
3805 elsif Is_Access_Type
(Etype
(Id
))
3806 and then not Is_Access_Constant
(Etype
(Id
))
3807 and then Has_Invariants
(Designated_Type
(Etype
(Id
)))
3808 and then In_Open_Scopes
(Scope
(Designated_Type
(Etype
(Id
))))
3810 Append_To
(Stmts
, Build_Component_Invariant_Call
(Id
));
3817 if Present
(Variant_Part
(Comp_List
)) then
3819 Variant_Alts
: constant List_Id
:= New_List
;
3820 Var_Loc
: Source_Ptr
;
3822 Variant_Stmts
: List_Id
;
3826 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3827 while Present
(Variant
) loop
3829 Build_Invariant_Checks
(Component_List
(Variant
));
3830 Var_Loc
:= Sloc
(Variant
);
3831 Append_To
(Variant_Alts
,
3832 Make_Case_Statement_Alternative
(Var_Loc
,
3834 New_Copy_List
(Discrete_Choices
(Variant
)),
3835 Statements
=> Variant_Stmts
));
3837 Next_Non_Pragma
(Variant
);
3840 -- The expression in the case statement is the reference to
3841 -- the discriminant of the target object.
3844 Make_Case_Statement
(Var_Loc
,
3846 Make_Selected_Component
(Var_Loc
,
3847 Prefix
=> New_Occurrence_Of
(Object_Entity
, Var_Loc
),
3848 Selector_Name
=> New_Occurrence_Of
3850 (Name
(Variant_Part
(Comp_List
))), Var_Loc
)),
3851 Alternatives
=> Variant_Alts
));
3856 end Build_Invariant_Checks
;
3858 -- Start of processing for Build_Record_Invariant_Proc
3861 Invariant_Found
:= False;
3862 Type_Def
:= Type_Definition
(Parent
(R_Type
));
3864 if Nkind
(Type_Def
) = N_Record_Definition
3865 and then not Null_Present
(Type_Def
)
3867 Stmts
:= Build_Invariant_Checks
(Component_List
(Type_Def
));
3872 if not Invariant_Found
then
3876 -- The name of the invariant procedure reflects the fact that the
3877 -- checks correspond to invariants on the component types. The
3878 -- record type itself may have invariants that will create a separate
3879 -- procedure whose name carries the Invariant suffix.
3882 Make_Defining_Identifier
(Loc
,
3883 Chars
=> New_External_Name
(Chars
(R_Type
), "CInvariant"));
3886 Make_Subprogram_Body
(Loc
,
3888 Make_Procedure_Specification
(Loc
,
3889 Defining_Unit_Name
=> Proc_Id
,
3890 Parameter_Specifications
=> New_List
(
3891 Make_Parameter_Specification
(Loc
,
3892 Defining_Identifier
=> Object_Entity
,
3893 Parameter_Type
=> New_Occurrence_Of
(R_Type
, Loc
)))),
3895 Declarations
=> Empty_List
,
3896 Handled_Statement_Sequence
=>
3897 Make_Handled_Sequence_Of_Statements
(Loc
,
3898 Statements
=> Stmts
));
3900 Set_Ekind
(Proc_Id
, E_Procedure
);
3901 Set_Is_Public
(Proc_Id
, Is_Public
(R_Type
));
3902 Set_Is_Internal
(Proc_Id
);
3903 Set_Has_Completion
(Proc_Id
);
3906 -- Insert_After (Nod, Proc_Body);
3907 -- Analyze (Proc_Body);
3908 end Build_Record_Invariant_Proc
;
3910 ----------------------------
3911 -- Build_Slice_Assignment --
3912 ----------------------------
3914 -- Generates the following subprogram:
3917 -- (Source, Target : Array_Type,
3918 -- Left_Lo, Left_Hi : Index;
3919 -- Right_Lo, Right_Hi : Index;
3927 -- if Left_Hi < Left_Lo then
3940 -- Target (Li1) := Source (Ri1);
3943 -- exit when Li1 = Left_Lo;
3944 -- Li1 := Index'pred (Li1);
3945 -- Ri1 := Index'pred (Ri1);
3947 -- exit when Li1 = Left_Hi;
3948 -- Li1 := Index'succ (Li1);
3949 -- Ri1 := Index'succ (Ri1);
3954 procedure Build_Slice_Assignment
(Typ
: Entity_Id
) is
3955 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3956 Index
: constant Entity_Id
:= Base_Type
(Etype
(First_Index
(Typ
)));
3958 Larray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
3959 Rarray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3960 Left_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3961 Left_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3962 Right_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3963 Right_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3964 Rev
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
3965 -- Formal parameters of procedure
3967 Proc_Name
: constant Entity_Id
:=
3968 Make_Defining_Identifier
(Loc
,
3969 Chars
=> Make_TSS_Name
(Typ
, TSS_Slice_Assign
));
3971 Lnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3972 Rnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3973 -- Subscripts for left and right sides
3980 -- Build declarations for indexes
3985 Make_Object_Declaration
(Loc
,
3986 Defining_Identifier
=> Lnn
,
3987 Object_Definition
=>
3988 New_Occurrence_Of
(Index
, Loc
)));
3991 Make_Object_Declaration
(Loc
,
3992 Defining_Identifier
=> Rnn
,
3993 Object_Definition
=>
3994 New_Occurrence_Of
(Index
, Loc
)));
3998 -- Build test for empty slice case
4001 Make_If_Statement
(Loc
,
4004 Left_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
),
4005 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
)),
4006 Then_Statements
=> New_List
(Make_Simple_Return_Statement
(Loc
))));
4008 -- Build initializations for indexes
4011 F_Init
: constant List_Id
:= New_List
;
4012 B_Init
: constant List_Id
:= New_List
;
4016 Make_Assignment_Statement
(Loc
,
4017 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4018 Expression
=> New_Occurrence_Of
(Left_Lo
, Loc
)));
4021 Make_Assignment_Statement
(Loc
,
4022 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4023 Expression
=> New_Occurrence_Of
(Right_Lo
, Loc
)));
4026 Make_Assignment_Statement
(Loc
,
4027 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4028 Expression
=> New_Occurrence_Of
(Left_Hi
, Loc
)));
4031 Make_Assignment_Statement
(Loc
,
4032 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4033 Expression
=> New_Occurrence_Of
(Right_Hi
, Loc
)));
4036 Make_If_Statement
(Loc
,
4037 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4038 Then_Statements
=> B_Init
,
4039 Else_Statements
=> F_Init
));
4042 -- Now construct the assignment statement
4045 Make_Loop_Statement
(Loc
,
4046 Statements
=> New_List
(
4047 Make_Assignment_Statement
(Loc
,
4049 Make_Indexed_Component
(Loc
,
4050 Prefix
=> New_Occurrence_Of
(Larray
, Loc
),
4051 Expressions
=> New_List
(New_Occurrence_Of
(Lnn
, Loc
))),
4053 Make_Indexed_Component
(Loc
,
4054 Prefix
=> New_Occurrence_Of
(Rarray
, Loc
),
4055 Expressions
=> New_List
(New_Occurrence_Of
(Rnn
, Loc
))))),
4056 End_Label
=> Empty
);
4058 -- Build the exit condition and increment/decrement statements
4061 F_Ass
: constant List_Id
:= New_List
;
4062 B_Ass
: constant List_Id
:= New_List
;
4066 Make_Exit_Statement
(Loc
,
4069 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4070 Right_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
))));
4073 Make_Assignment_Statement
(Loc
,
4074 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4076 Make_Attribute_Reference
(Loc
,
4078 New_Occurrence_Of
(Index
, Loc
),
4079 Attribute_Name
=> Name_Succ
,
4080 Expressions
=> New_List
(
4081 New_Occurrence_Of
(Lnn
, Loc
)))));
4084 Make_Assignment_Statement
(Loc
,
4085 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4087 Make_Attribute_Reference
(Loc
,
4089 New_Occurrence_Of
(Index
, Loc
),
4090 Attribute_Name
=> Name_Succ
,
4091 Expressions
=> New_List
(
4092 New_Occurrence_Of
(Rnn
, Loc
)))));
4095 Make_Exit_Statement
(Loc
,
4098 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4099 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
))));
4102 Make_Assignment_Statement
(Loc
,
4103 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4105 Make_Attribute_Reference
(Loc
,
4107 New_Occurrence_Of
(Index
, Loc
),
4108 Attribute_Name
=> Name_Pred
,
4109 Expressions
=> New_List
(
4110 New_Occurrence_Of
(Lnn
, Loc
)))));
4113 Make_Assignment_Statement
(Loc
,
4114 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4116 Make_Attribute_Reference
(Loc
,
4118 New_Occurrence_Of
(Index
, Loc
),
4119 Attribute_Name
=> Name_Pred
,
4120 Expressions
=> New_List
(
4121 New_Occurrence_Of
(Rnn
, Loc
)))));
4123 Append_To
(Statements
(Loops
),
4124 Make_If_Statement
(Loc
,
4125 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4126 Then_Statements
=> B_Ass
,
4127 Else_Statements
=> F_Ass
));
4130 Append_To
(Stats
, Loops
);
4134 Formals
: List_Id
:= New_List
;
4137 Formals
:= New_List
(
4138 Make_Parameter_Specification
(Loc
,
4139 Defining_Identifier
=> Larray
,
4140 Out_Present
=> True,
4142 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4144 Make_Parameter_Specification
(Loc
,
4145 Defining_Identifier
=> Rarray
,
4147 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4149 Make_Parameter_Specification
(Loc
,
4150 Defining_Identifier
=> Left_Lo
,
4152 New_Occurrence_Of
(Index
, Loc
)),
4154 Make_Parameter_Specification
(Loc
,
4155 Defining_Identifier
=> Left_Hi
,
4157 New_Occurrence_Of
(Index
, Loc
)),
4159 Make_Parameter_Specification
(Loc
,
4160 Defining_Identifier
=> Right_Lo
,
4162 New_Occurrence_Of
(Index
, Loc
)),
4164 Make_Parameter_Specification
(Loc
,
4165 Defining_Identifier
=> Right_Hi
,
4167 New_Occurrence_Of
(Index
, Loc
)));
4170 Make_Parameter_Specification
(Loc
,
4171 Defining_Identifier
=> Rev
,
4173 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
4176 Make_Procedure_Specification
(Loc
,
4177 Defining_Unit_Name
=> Proc_Name
,
4178 Parameter_Specifications
=> Formals
);
4181 Make_Subprogram_Body
(Loc
,
4182 Specification
=> Spec
,
4183 Declarations
=> Decls
,
4184 Handled_Statement_Sequence
=>
4185 Make_Handled_Sequence_Of_Statements
(Loc
,
4186 Statements
=> Stats
)));
4189 Set_TSS
(Typ
, Proc_Name
);
4190 Set_Is_Pure
(Proc_Name
);
4191 end Build_Slice_Assignment
;
4193 -----------------------------
4194 -- Build_Untagged_Equality --
4195 -----------------------------
4197 procedure Build_Untagged_Equality
(Typ
: Entity_Id
) is
4205 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
;
4206 -- Check whether the type T has a user-defined primitive equality. If so
4207 -- return it, else return Empty. If true for a component of Typ, we have
4208 -- to build the primitive equality for it.
4210 ---------------------
4211 -- User_Defined_Eq --
4212 ---------------------
4214 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
is
4219 Op
:= TSS
(T
, TSS_Composite_Equality
);
4221 if Present
(Op
) then
4225 Prim
:= First_Elmt
(Collect_Primitive_Operations
(T
));
4226 while Present
(Prim
) loop
4229 if Chars
(Op
) = Name_Op_Eq
4230 and then Etype
(Op
) = Standard_Boolean
4231 and then Etype
(First_Formal
(Op
)) = T
4232 and then Etype
(Next_Formal
(First_Formal
(Op
))) = T
4241 end User_Defined_Eq
;
4243 -- Start of processing for Build_Untagged_Equality
4246 -- If a record component has a primitive equality operation, we must
4247 -- build the corresponding one for the current type.
4250 Comp
:= First_Component
(Typ
);
4251 while Present
(Comp
) loop
4252 if Is_Record_Type
(Etype
(Comp
))
4253 and then Present
(User_Defined_Eq
(Etype
(Comp
)))
4258 Next_Component
(Comp
);
4261 -- If there is a user-defined equality for the type, we do not create
4262 -- the implicit one.
4264 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Typ
));
4266 while Present
(Prim
) loop
4267 if Chars
(Node
(Prim
)) = Name_Op_Eq
4268 and then Comes_From_Source
(Node
(Prim
))
4270 -- Don't we also need to check formal types and return type as in
4271 -- User_Defined_Eq above???
4274 Eq_Op
:= Node
(Prim
);
4282 -- If the type is derived, inherit the operation, if present, from the
4283 -- parent type. It may have been declared after the type derivation. If
4284 -- the parent type itself is derived, it may have inherited an operation
4285 -- that has itself been overridden, so update its alias and related
4286 -- flags. Ditto for inequality.
4288 if No
(Eq_Op
) and then Is_Derived_Type
(Typ
) then
4289 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Etype
(Typ
)));
4290 while Present
(Prim
) loop
4291 if Chars
(Node
(Prim
)) = Name_Op_Eq
then
4292 Copy_TSS
(Node
(Prim
), Typ
);
4296 Op
: constant Entity_Id
:= User_Defined_Eq
(Typ
);
4297 Eq_Op
: constant Entity_Id
:= Node
(Prim
);
4298 NE_Op
: constant Entity_Id
:= Next_Entity
(Eq_Op
);
4301 if Present
(Op
) then
4302 Set_Alias
(Op
, Eq_Op
);
4303 Set_Is_Abstract_Subprogram
4304 (Op
, Is_Abstract_Subprogram
(Eq_Op
));
4306 if Chars
(Next_Entity
(Op
)) = Name_Op_Ne
then
4307 Set_Is_Abstract_Subprogram
4308 (Next_Entity
(Op
), Is_Abstract_Subprogram
(NE_Op
));
4320 -- If not inherited and not user-defined, build body as for a type with
4321 -- tagged components.
4325 Make_Eq_Body
(Typ
, Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4326 Op
:= Defining_Entity
(Decl
);
4330 if Is_Library_Level_Entity
(Typ
) then
4334 end Build_Untagged_Equality
;
4336 -----------------------------------
4337 -- Build_Variant_Record_Equality --
4338 -----------------------------------
4342 -- function _Equality (X, Y : T) return Boolean is
4344 -- -- Compare discriminants
4346 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4350 -- -- Compare components
4352 -- if X.C1 /= Y.C1 or else X.C2 /= Y.C2 or else ... then
4356 -- -- Compare variant part
4360 -- if X.C2 /= Y.C2 or else X.C3 /= Y.C3 or else ... then
4365 -- if X.Cn /= Y.Cn or else ... then
4373 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
) is
4374 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4376 F
: constant Entity_Id
:=
4377 Make_Defining_Identifier
(Loc
,
4378 Chars
=> Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4380 X
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_X
);
4381 Y
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_Y
);
4383 Def
: constant Node_Id
:= Parent
(Typ
);
4384 Comps
: constant Node_Id
:= Component_List
(Type_Definition
(Def
));
4385 Stmts
: constant List_Id
:= New_List
;
4386 Pspecs
: constant List_Id
:= New_List
;
4389 -- If we have a variant record with restriction No_Implicit_Conditionals
4390 -- in effect, then we skip building the procedure. This is safe because
4391 -- if we can see the restriction, so can any caller, calls to equality
4392 -- test routines are not allowed for variant records if this restriction
4395 if Restriction_Active
(No_Implicit_Conditionals
) then
4399 -- Derived Unchecked_Union types no longer inherit the equality function
4402 if Is_Derived_Type
(Typ
)
4403 and then not Is_Unchecked_Union
(Typ
)
4404 and then not Has_New_Non_Standard_Rep
(Typ
)
4407 Parent_Eq
: constant Entity_Id
:=
4408 TSS
(Root_Type
(Typ
), TSS_Composite_Equality
);
4410 if Present
(Parent_Eq
) then
4411 Copy_TSS
(Parent_Eq
, Typ
);
4418 Make_Subprogram_Body
(Loc
,
4420 Make_Function_Specification
(Loc
,
4421 Defining_Unit_Name
=> F
,
4422 Parameter_Specifications
=> Pspecs
,
4423 Result_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
)),
4424 Declarations
=> New_List
,
4425 Handled_Statement_Sequence
=>
4426 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
)));
4429 Make_Parameter_Specification
(Loc
,
4430 Defining_Identifier
=> X
,
4431 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4434 Make_Parameter_Specification
(Loc
,
4435 Defining_Identifier
=> Y
,
4436 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4438 -- Unchecked_Unions require additional machinery to support equality.
4439 -- Two extra parameters (A and B) are added to the equality function
4440 -- parameter list for each discriminant of the type, in order to
4441 -- capture the inferred values of the discriminants in equality calls.
4442 -- The names of the parameters match the names of the corresponding
4443 -- discriminant, with an added suffix.
4445 if Is_Unchecked_Union
(Typ
) then
4448 Discr_Type
: Entity_Id
;
4450 New_Discrs
: Elist_Id
;
4453 New_Discrs
:= New_Elmt_List
;
4455 Discr
:= First_Discriminant
(Typ
);
4456 while Present
(Discr
) loop
4457 Discr_Type
:= Etype
(Discr
);
4458 A
:= Make_Defining_Identifier
(Loc
,
4459 Chars
=> New_External_Name
(Chars
(Discr
), 'A'));
4461 B
:= Make_Defining_Identifier
(Loc
,
4462 Chars
=> New_External_Name
(Chars
(Discr
), 'B'));
4464 -- Add new parameters to the parameter list
4467 Make_Parameter_Specification
(Loc
,
4468 Defining_Identifier
=> A
,
4470 New_Occurrence_Of
(Discr_Type
, Loc
)));
4473 Make_Parameter_Specification
(Loc
,
4474 Defining_Identifier
=> B
,
4476 New_Occurrence_Of
(Discr_Type
, Loc
)));
4478 Append_Elmt
(A
, New_Discrs
);
4480 -- Generate the following code to compare each of the inferred
4488 Make_If_Statement
(Loc
,
4491 Left_Opnd
=> New_Occurrence_Of
(A
, Loc
),
4492 Right_Opnd
=> New_Occurrence_Of
(B
, Loc
)),
4493 Then_Statements
=> New_List
(
4494 Make_Simple_Return_Statement
(Loc
,
4496 New_Occurrence_Of
(Standard_False
, Loc
)))));
4497 Next_Discriminant
(Discr
);
4500 -- Generate component-by-component comparison. Note that we must
4501 -- propagate the inferred discriminants formals to act as
4502 -- the case statement switch. Their value is added when an
4503 -- equality call on unchecked unions is expanded.
4505 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
, New_Discrs
));
4508 -- Normal case (not unchecked union)
4512 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
4513 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
4517 Make_Simple_Return_Statement
(Loc
,
4518 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
4523 if not Debug_Generated_Code
then
4524 Set_Debug_Info_Off
(F
);
4526 end Build_Variant_Record_Equality
;
4528 -----------------------------
4529 -- Check_Stream_Attributes --
4530 -----------------------------
4532 procedure Check_Stream_Attributes
(Typ
: Entity_Id
) is
4534 Par_Read
: constant Boolean :=
4535 Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
4536 and then not Has_Specified_Stream_Read
(Typ
);
4537 Par_Write
: constant Boolean :=
4538 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
4539 and then not Has_Specified_Stream_Write
(Typ
);
4541 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
);
4542 -- Check that Comp has a user-specified Nam stream attribute
4548 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
) is
4550 if not Stream_Attribute_Available
(Etype
(Comp
), TSS_Nam
) then
4551 Error_Msg_Name_1
:= Nam
;
4553 ("|component& in limited extension must have% attribute", Comp
);
4557 -- Start of processing for Check_Stream_Attributes
4560 if Par_Read
or else Par_Write
then
4561 Comp
:= First_Component
(Typ
);
4562 while Present
(Comp
) loop
4563 if Comes_From_Source
(Comp
)
4564 and then Original_Record_Component
(Comp
) = Comp
4565 and then Is_Limited_Type
(Etype
(Comp
))
4568 Check_Attr
(Name_Read
, TSS_Stream_Read
);
4572 Check_Attr
(Name_Write
, TSS_Stream_Write
);
4576 Next_Component
(Comp
);
4579 end Check_Stream_Attributes
;
4581 ----------------------
4582 -- Clean_Task_Names --
4583 ----------------------
4585 procedure Clean_Task_Names
4587 Proc_Id
: Entity_Id
)
4591 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
4592 and then not Global_Discard_Names
4593 and then Tagged_Type_Expansion
4595 Set_Uses_Sec_Stack
(Proc_Id
);
4597 end Clean_Task_Names
;
4599 ------------------------------
4600 -- Expand_Freeze_Array_Type --
4601 ------------------------------
4603 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
4604 Typ
: constant Entity_Id
:= Entity
(N
);
4605 Base
: constant Entity_Id
:= Base_Type
(Typ
);
4606 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
4608 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4611 -- Ensure that all freezing activities are properly flagged as Ghost
4613 Set_Ghost_Mode_From_Entity
(Typ
);
4615 if not Is_Bit_Packed_Array
(Typ
) then
4617 -- If the component contains tasks, so does the array type. This may
4618 -- not be indicated in the array type because the component may have
4619 -- been a private type at the point of definition. Same if component
4620 -- type is controlled or contains protected objects.
4622 Propagate_Type_Has_Flags
(Base
, Comp_Typ
);
4623 Set_Has_Controlled_Component
4624 (Base
, Has_Controlled_Component
(Comp_Typ
)
4625 or else Is_Controlled
(Comp_Typ
));
4627 if No
(Init_Proc
(Base
)) then
4629 -- If this is an anonymous array created for a declaration with
4630 -- an initial value, its init_proc will never be called. The
4631 -- initial value itself may have been expanded into assignments,
4632 -- in which case the object declaration is carries the
4633 -- No_Initialization flag.
4636 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
4637 N_Object_Declaration
4639 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
4640 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
4644 -- We do not need an init proc for string or wide [wide] string,
4645 -- since the only time these need initialization in normalize or
4646 -- initialize scalars mode, and these types are treated specially
4647 -- and do not need initialization procedures.
4649 elsif Is_Standard_String_Type
(Base
) then
4652 -- Otherwise we have to build an init proc for the subtype
4655 Build_Array_Init_Proc
(Base
, N
);
4659 if Typ
= Base
and then Has_Controlled_Component
(Base
) then
4660 Build_Controlling_Procs
(Base
);
4662 if not Is_Limited_Type
(Comp_Typ
)
4663 and then Number_Dimensions
(Typ
) = 1
4665 Build_Slice_Assignment
(Typ
);
4669 -- For packed case, default initialization, except if the component type
4670 -- is itself a packed structure with an initialization procedure, or
4671 -- initialize/normalize scalars active, and we have a base type, or the
4672 -- type is public, because in that case a client might specify
4673 -- Normalize_Scalars and there better be a public Init_Proc for it.
4675 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
4676 and then No
(Base_Init_Proc
(Base
)))
4677 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
4678 or else Is_Public
(Typ
)
4680 Build_Array_Init_Proc
(Base
, N
);
4683 if Has_Invariants
(Component_Type
(Base
))
4685 and then In_Open_Scopes
(Scope
(Component_Type
(Base
)))
4687 -- Generate component invariant checking procedure. This is only
4688 -- relevant if the array type is within the scope of the component
4689 -- type. Otherwise an array object can only be built using the public
4690 -- subprograms for the component type, and calls to those will have
4691 -- invariant checks. The invariant procedure is only generated for
4692 -- a base type, not a subtype.
4694 Insert_Component_Invariant_Checks
4695 (N
, Base
, Build_Array_Invariant_Proc
(Base
, N
));
4698 Ghost_Mode
:= Save_Ghost_Mode
;
4699 end Expand_Freeze_Array_Type
;
4701 -----------------------------------
4702 -- Expand_Freeze_Class_Wide_Type --
4703 -----------------------------------
4705 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
4706 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
4707 -- Given a type, determine whether it is derived from a C or C++ root
4709 ---------------------
4710 -- Is_C_Derivation --
4711 ---------------------
4713 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
4720 or else Convention
(T
) = Convention_C
4721 or else Convention
(T
) = Convention_CPP
4726 exit when T
= Etype
(T
);
4732 end Is_C_Derivation
;
4736 Typ
: constant Entity_Id
:= Entity
(N
);
4737 Root
: constant Entity_Id
:= Root_Type
(Typ
);
4739 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4741 -- Start of processing for Expand_Freeze_Class_Wide_Type
4744 -- Certain run-time configurations and targets do not provide support
4745 -- for controlled types.
4747 if Restriction_Active
(No_Finalization
) then
4750 -- Do not create TSS routine Finalize_Address when dispatching calls are
4751 -- disabled since the core of the routine is a dispatching call.
4753 elsif Restriction_Active
(No_Dispatching_Calls
) then
4756 -- Do not create TSS routine Finalize_Address for concurrent class-wide
4757 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
4758 -- non-Ada side will handle their destruction.
4760 elsif Is_Concurrent_Type
(Root
)
4761 or else Is_C_Derivation
(Root
)
4762 or else Convention
(Typ
) = Convention_CPP
4766 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
4767 -- mode since the routine contains an Unchecked_Conversion.
4769 elsif CodePeer_Mode
then
4773 -- Ensure that all freezing activities are properly flagged as Ghost
4775 Set_Ghost_Mode_From_Entity
(Typ
);
4777 -- Create the body of TSS primitive Finalize_Address. This automatically
4778 -- sets the TSS entry for the class-wide type.
4780 Make_Finalize_Address_Body
(Typ
);
4781 Ghost_Mode
:= Save_Ghost_Mode
;
4782 end Expand_Freeze_Class_Wide_Type
;
4784 ------------------------------------
4785 -- Expand_Freeze_Enumeration_Type --
4786 ------------------------------------
4788 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
4789 Typ
: constant Entity_Id
:= Entity
(N
);
4790 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4792 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4797 Is_Contiguous
: Boolean;
4805 pragma Warnings
(Off
, Func
);
4808 -- Ensure that all freezing activities are properly flagged as Ghost
4810 Set_Ghost_Mode_From_Entity
(Typ
);
4812 -- Various optimizations possible if given representation is contiguous
4814 Is_Contiguous
:= True;
4816 Ent
:= First_Literal
(Typ
);
4817 Last_Repval
:= Enumeration_Rep
(Ent
);
4820 while Present
(Ent
) loop
4821 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
4822 Is_Contiguous
:= False;
4825 Last_Repval
:= Enumeration_Rep
(Ent
);
4831 if Is_Contiguous
then
4832 Set_Has_Contiguous_Rep
(Typ
);
4833 Ent
:= First_Literal
(Typ
);
4835 Lst
:= New_List
(New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
4838 -- Build list of literal references
4843 Ent
:= First_Literal
(Typ
);
4844 while Present
(Ent
) loop
4845 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
4851 -- Now build an array declaration
4853 -- typA : array (Natural range 0 .. num - 1) of ctype :=
4854 -- (v, v, v, v, v, ....)
4856 -- where ctype is the corresponding integer type. If the representation
4857 -- is contiguous, we only keep the first literal, which provides the
4858 -- offset for Pos_To_Rep computations.
4861 Make_Defining_Identifier
(Loc
,
4862 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
4864 Append_Freeze_Action
(Typ
,
4865 Make_Object_Declaration
(Loc
,
4866 Defining_Identifier
=> Arr
,
4867 Constant_Present
=> True,
4869 Object_Definition
=>
4870 Make_Constrained_Array_Definition
(Loc
,
4871 Discrete_Subtype_Definitions
=> New_List
(
4872 Make_Subtype_Indication
(Loc
,
4873 Subtype_Mark
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
4875 Make_Range_Constraint
(Loc
,
4879 Make_Integer_Literal
(Loc
, 0),
4881 Make_Integer_Literal
(Loc
, Num
- 1))))),
4883 Component_Definition
=>
4884 Make_Component_Definition
(Loc
,
4885 Aliased_Present
=> False,
4886 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
4889 Make_Aggregate
(Loc
,
4890 Expressions
=> Lst
)));
4892 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
4894 -- Now we build the function that converts representation values to
4895 -- position values. This function has the form:
4897 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
4900 -- when enum-lit'Enum_Rep => return posval;
4901 -- when enum-lit'Enum_Rep => return posval;
4904 -- [raise Constraint_Error when F "invalid data"]
4909 -- Note: the F parameter determines whether the others case (no valid
4910 -- representation) raises Constraint_Error or returns a unique value
4911 -- of minus one. The latter case is used, e.g. in 'Valid code.
4913 -- Note: the reason we use Enum_Rep values in the case here is to avoid
4914 -- the code generator making inappropriate assumptions about the range
4915 -- of the values in the case where the value is invalid. ityp is a
4916 -- signed or unsigned integer type of appropriate width.
4918 -- Note: if exceptions are not supported, then we suppress the raise
4919 -- and return -1 unconditionally (this is an erroneous program in any
4920 -- case and there is no obligation to raise Constraint_Error here). We
4921 -- also do this if pragma Restrictions (No_Exceptions) is active.
4923 -- Is this right??? What about No_Exception_Propagation???
4925 -- Representations are signed
4927 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
4929 -- The underlying type is signed. Reset the Is_Unsigned_Type
4930 -- explicitly, because it might have been inherited from
4933 Set_Is_Unsigned_Type
(Typ
, False);
4935 if Esize
(Typ
) <= Standard_Integer_Size
then
4936 Ityp
:= Standard_Integer
;
4938 Ityp
:= Universal_Integer
;
4941 -- Representations are unsigned
4944 if Esize
(Typ
) <= Standard_Integer_Size
then
4945 Ityp
:= RTE
(RE_Unsigned
);
4947 Ityp
:= RTE
(RE_Long_Long_Unsigned
);
4951 -- The body of the function is a case statement. First collect case
4952 -- alternatives, or optimize the contiguous case.
4956 -- If representation is contiguous, Pos is computed by subtracting
4957 -- the representation of the first literal.
4959 if Is_Contiguous
then
4960 Ent
:= First_Literal
(Typ
);
4962 if Enumeration_Rep
(Ent
) = Last_Repval
then
4964 -- Another special case: for a single literal, Pos is zero
4966 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
4970 Convert_To
(Standard_Integer
,
4971 Make_Op_Subtract
(Loc
,
4973 Unchecked_Convert_To
4974 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
4976 Make_Integer_Literal
(Loc
,
4977 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
4981 Make_Case_Statement_Alternative
(Loc
,
4982 Discrete_Choices
=> New_List
(
4983 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
4985 Make_Integer_Literal
(Loc
,
4986 Intval
=> Enumeration_Rep
(Ent
)),
4988 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
4990 Statements
=> New_List
(
4991 Make_Simple_Return_Statement
(Loc
,
4992 Expression
=> Pos_Expr
))));
4995 Ent
:= First_Literal
(Typ
);
4996 while Present
(Ent
) loop
4998 Make_Case_Statement_Alternative
(Loc
,
4999 Discrete_Choices
=> New_List
(
5000 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
5001 Intval
=> Enumeration_Rep
(Ent
))),
5003 Statements
=> New_List
(
5004 Make_Simple_Return_Statement
(Loc
,
5006 Make_Integer_Literal
(Loc
,
5007 Intval
=> Enumeration_Pos
(Ent
))))));
5013 -- In normal mode, add the others clause with the test.
5014 -- If Predicates_Ignored is True, validity checks do not apply to
5017 if not No_Exception_Handlers_Set
5018 and then not Predicates_Ignored
(Typ
)
5021 Make_Case_Statement_Alternative
(Loc
,
5022 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5023 Statements
=> New_List
(
5024 Make_Raise_Constraint_Error
(Loc
,
5025 Condition
=> Make_Identifier
(Loc
, Name_uF
),
5026 Reason
=> CE_Invalid_Data
),
5027 Make_Simple_Return_Statement
(Loc
,
5028 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
5030 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
5031 -- active then return -1 (we cannot usefully raise Constraint_Error in
5032 -- this case). See description above for further details.
5036 Make_Case_Statement_Alternative
(Loc
,
5037 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5038 Statements
=> New_List
(
5039 Make_Simple_Return_Statement
(Loc
,
5040 Expression
=> Make_Integer_Literal
(Loc
, -1)))));
5043 -- Now we can build the function body
5046 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
5049 Make_Subprogram_Body
(Loc
,
5051 Make_Function_Specification
(Loc
,
5052 Defining_Unit_Name
=> Fent
,
5053 Parameter_Specifications
=> New_List
(
5054 Make_Parameter_Specification
(Loc
,
5055 Defining_Identifier
=>
5056 Make_Defining_Identifier
(Loc
, Name_uA
),
5057 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
5058 Make_Parameter_Specification
(Loc
,
5059 Defining_Identifier
=>
5060 Make_Defining_Identifier
(Loc
, Name_uF
),
5062 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
5064 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
5066 Declarations
=> Empty_List
,
5068 Handled_Statement_Sequence
=>
5069 Make_Handled_Sequence_Of_Statements
(Loc
,
5070 Statements
=> New_List
(
5071 Make_Case_Statement
(Loc
,
5073 Unchecked_Convert_To
5074 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
5075 Alternatives
=> Lst
))));
5077 Set_TSS
(Typ
, Fent
);
5079 -- Set Pure flag (it will be reset if the current context is not Pure).
5080 -- We also pretend there was a pragma Pure_Function so that for purposes
5081 -- of optimization and constant-folding, we will consider the function
5082 -- Pure even if we are not in a Pure context).
5085 Set_Has_Pragma_Pure_Function
(Fent
);
5087 -- Unless we are in -gnatD mode, where we are debugging generated code,
5088 -- this is an internal entity for which we don't need debug info.
5090 if not Debug_Generated_Code
then
5091 Set_Debug_Info_Off
(Fent
);
5094 Ghost_Mode
:= Save_Ghost_Mode
;
5097 when RE_Not_Available
=>
5098 Ghost_Mode
:= Save_Ghost_Mode
;
5100 end Expand_Freeze_Enumeration_Type
;
5102 -------------------------------
5103 -- Expand_Freeze_Record_Type --
5104 -------------------------------
5106 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
5107 Typ
: constant Node_Id
:= Entity
(N
);
5108 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
5110 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
5113 Comp_Typ
: Entity_Id
;
5114 Predef_List
: List_Id
;
5116 Wrapper_Decl_List
: List_Id
:= No_List
;
5117 Wrapper_Body_List
: List_Id
:= No_List
;
5119 Renamed_Eq
: Node_Id
:= Empty
;
5120 -- Defining unit name for the predefined equality function in the case
5121 -- where the type has a primitive operation that is a renaming of
5122 -- predefined equality (but only if there is also an overriding
5123 -- user-defined equality function). Used to pass this entity from
5124 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
5126 -- Start of processing for Expand_Freeze_Record_Type
5129 -- Ensure that all freezing activities are properly flagged as Ghost
5131 Set_Ghost_Mode_From_Entity
(Typ
);
5133 -- Build discriminant checking functions if not a derived type (for
5134 -- derived types that are not tagged types, always use the discriminant
5135 -- checking functions of the parent type). However, for untagged types
5136 -- the derivation may have taken place before the parent was frozen, so
5137 -- we copy explicitly the discriminant checking functions from the
5138 -- parent into the components of the derived type.
5140 if not Is_Derived_Type
(Typ
)
5141 or else Has_New_Non_Standard_Rep
(Typ
)
5142 or else Is_Tagged_Type
(Typ
)
5144 Build_Discr_Checking_Funcs
(Typ_Decl
);
5146 elsif Is_Derived_Type
(Typ
)
5147 and then not Is_Tagged_Type
(Typ
)
5149 -- If we have a derived Unchecked_Union, we do not inherit the
5150 -- discriminant checking functions from the parent type since the
5151 -- discriminants are non existent.
5153 and then not Is_Unchecked_Union
(Typ
)
5154 and then Has_Discriminants
(Typ
)
5157 Old_Comp
: Entity_Id
;
5161 First_Component
(Base_Type
(Underlying_Type
(Etype
(Typ
))));
5162 Comp
:= First_Component
(Typ
);
5163 while Present
(Comp
) loop
5164 if Ekind
(Comp
) = E_Component
5165 and then Chars
(Comp
) = Chars
(Old_Comp
)
5167 Set_Discriminant_Checking_Func
5168 (Comp
, Discriminant_Checking_Func
(Old_Comp
));
5171 Next_Component
(Old_Comp
);
5172 Next_Component
(Comp
);
5177 if Is_Derived_Type
(Typ
)
5178 and then Is_Limited_Type
(Typ
)
5179 and then Is_Tagged_Type
(Typ
)
5181 Check_Stream_Attributes
(Typ
);
5184 -- Update task, protected, and controlled component flags, because some
5185 -- of the component types may have been private at the point of the
5186 -- record declaration. Detect anonymous access-to-controlled components.
5188 Comp
:= First_Component
(Typ
);
5189 while Present
(Comp
) loop
5190 Comp_Typ
:= Etype
(Comp
);
5192 Propagate_Type_Has_Flags
(Typ
, Comp_Typ
);
5194 -- Do not set Has_Controlled_Component on a class-wide equivalent
5195 -- type. See Make_CW_Equivalent_Type.
5197 if not Is_Class_Wide_Equivalent_Type
(Typ
)
5199 (Has_Controlled_Component
(Comp_Typ
)
5200 or else (Chars
(Comp
) /= Name_uParent
5201 and then (Is_Controlled_Active
(Comp_Typ
))))
5203 Set_Has_Controlled_Component
(Typ
);
5206 Next_Component
(Comp
);
5209 -- Handle constructors of untagged CPP_Class types
5211 if not Is_Tagged_Type
(Typ
) and then Is_CPP_Class
(Typ
) then
5212 Set_CPP_Constructors
(Typ
);
5215 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
5216 -- for regular tagged types as well as for Ada types deriving from a C++
5217 -- Class, but not for tagged types directly corresponding to C++ classes
5218 -- In the later case we assume that it is created in the C++ side and we
5221 if Is_Tagged_Type
(Typ
) then
5223 -- Add the _Tag component
5225 if Underlying_Type
(Etype
(Typ
)) = Typ
then
5226 Expand_Tagged_Root
(Typ
);
5229 if Is_CPP_Class
(Typ
) then
5230 Set_All_DT_Position
(Typ
);
5232 -- Create the tag entities with a minimum decoration
5234 if Tagged_Type_Expansion
then
5235 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5238 Set_CPP_Constructors
(Typ
);
5241 if not Building_Static_DT
(Typ
) then
5243 -- Usually inherited primitives are not delayed but the first
5244 -- Ada extension of a CPP_Class is an exception since the
5245 -- address of the inherited subprogram has to be inserted in
5246 -- the new Ada Dispatch Table and this is a freezing action.
5248 -- Similarly, if this is an inherited operation whose parent is
5249 -- not frozen yet, it is not in the DT of the parent, and we
5250 -- generate an explicit freeze node for the inherited operation
5251 -- so it is properly inserted in the DT of the current type.
5258 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5259 while Present
(Elmt
) loop
5260 Subp
:= Node
(Elmt
);
5262 if Present
(Alias
(Subp
)) then
5263 if Is_CPP_Class
(Etype
(Typ
)) then
5264 Set_Has_Delayed_Freeze
(Subp
);
5266 elsif Has_Delayed_Freeze
(Alias
(Subp
))
5267 and then not Is_Frozen
(Alias
(Subp
))
5269 Set_Is_Frozen
(Subp
, False);
5270 Set_Has_Delayed_Freeze
(Subp
);
5279 -- Unfreeze momentarily the type to add the predefined primitives
5280 -- operations. The reason we unfreeze is so that these predefined
5281 -- operations will indeed end up as primitive operations (which
5282 -- must be before the freeze point).
5284 Set_Is_Frozen
(Typ
, False);
5286 -- Do not add the spec of predefined primitives in case of
5287 -- CPP tagged type derivations that have convention CPP.
5289 if Is_CPP_Class
(Root_Type
(Typ
))
5290 and then Convention
(Typ
) = Convention_CPP
5294 -- Do not add the spec of the predefined primitives if we are
5295 -- compiling under restriction No_Dispatching_Calls.
5297 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5298 Make_Predefined_Primitive_Specs
(Typ
, Predef_List
, Renamed_Eq
);
5299 Insert_List_Before_And_Analyze
(N
, Predef_List
);
5302 -- Ada 2005 (AI-391): For a nonabstract null extension, create
5303 -- wrapper functions for each nonoverridden inherited function
5304 -- with a controlling result of the type. The wrapper for such
5305 -- a function returns an extension aggregate that invokes the
5308 if Ada_Version
>= Ada_2005
5309 and then not Is_Abstract_Type
(Typ
)
5310 and then Is_Null_Extension
(Typ
)
5312 Make_Controlling_Function_Wrappers
5313 (Typ
, Wrapper_Decl_List
, Wrapper_Body_List
);
5314 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
5317 -- Ada 2005 (AI-251): For a nonabstract type extension, build
5318 -- null procedure declarations for each set of homographic null
5319 -- procedures that are inherited from interface types but not
5320 -- overridden. This is done to ensure that the dispatch table
5321 -- entry associated with such null primitives are properly filled.
5323 if Ada_Version
>= Ada_2005
5324 and then Etype
(Typ
) /= Typ
5325 and then not Is_Abstract_Type
(Typ
)
5326 and then Has_Interfaces
(Typ
)
5328 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Typ
));
5331 Set_Is_Frozen
(Typ
);
5333 if not Is_Derived_Type
(Typ
)
5334 or else Is_Tagged_Type
(Etype
(Typ
))
5336 Set_All_DT_Position
(Typ
);
5338 -- If this is a type derived from an untagged private type whose
5339 -- full view is tagged, the type is marked tagged for layout
5340 -- reasons, but it has no dispatch table.
5342 elsif Is_Derived_Type
(Typ
)
5343 and then Is_Private_Type
(Etype
(Typ
))
5344 and then not Is_Tagged_Type
(Etype
(Typ
))
5349 -- Create and decorate the tags. Suppress their creation when
5350 -- not Tagged_Type_Expansion because the dispatching mechanism is
5351 -- handled internally by the virtual target.
5353 if Tagged_Type_Expansion
then
5354 Append_Freeze_Actions
(Typ
, Make_Tags
(Typ
));
5356 -- Generate dispatch table of locally defined tagged type.
5357 -- Dispatch tables of library level tagged types are built
5358 -- later (see Analyze_Declarations).
5360 if not Building_Static_DT
(Typ
) then
5361 Append_Freeze_Actions
(Typ
, Make_DT
(Typ
));
5365 -- If the type has unknown discriminants, propagate dispatching
5366 -- information to its underlying record view, which does not get
5367 -- its own dispatch table.
5369 if Is_Derived_Type
(Typ
)
5370 and then Has_Unknown_Discriminants
(Typ
)
5371 and then Present
(Underlying_Record_View
(Typ
))
5374 Rep
: constant Entity_Id
:= Underlying_Record_View
(Typ
);
5376 Set_Access_Disp_Table
5377 (Rep
, Access_Disp_Table
(Typ
));
5378 Set_Dispatch_Table_Wrappers
5379 (Rep
, Dispatch_Table_Wrappers
(Typ
));
5380 Set_Direct_Primitive_Operations
5381 (Rep
, Direct_Primitive_Operations
(Typ
));
5385 -- Make sure that the primitives Initialize, Adjust and Finalize
5386 -- are Frozen before other TSS subprograms. We don't want them
5389 if Is_Controlled
(Typ
) then
5390 if not Is_Limited_Type
(Typ
) then
5391 Append_Freeze_Actions
(Typ
,
5392 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Adjust
), Typ
));
5395 Append_Freeze_Actions
(Typ
,
5396 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Initialize
), Typ
));
5398 Append_Freeze_Actions
(Typ
,
5399 Freeze_Entity
(Find_Prim_Op
(Typ
, Name_Finalize
), Typ
));
5402 -- Freeze rest of primitive operations. There is no need to handle
5403 -- the predefined primitives if we are compiling under restriction
5404 -- No_Dispatching_Calls.
5406 if not Restriction_Active
(No_Dispatching_Calls
) then
5407 Append_Freeze_Actions
(Typ
, Predefined_Primitive_Freeze
(Typ
));
5411 -- In the untagged case, ever since Ada 83 an equality function must
5412 -- be provided for variant records that are not unchecked unions.
5413 -- In Ada 2012 the equality function composes, and thus must be built
5414 -- explicitly just as for tagged records.
5416 elsif Has_Discriminants
(Typ
)
5417 and then not Is_Limited_Type
(Typ
)
5420 Comps
: constant Node_Id
:=
5421 Component_List
(Type_Definition
(Typ_Decl
));
5424 and then Present
(Variant_Part
(Comps
))
5426 Build_Variant_Record_Equality
(Typ
);
5430 -- Otherwise create primitive equality operation (AI05-0123)
5432 -- This is done unconditionally to ensure that tools can be linked
5433 -- properly with user programs compiled with older language versions.
5434 -- In addition, this is needed because "=" composes for bounded strings
5435 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
5437 elsif Comes_From_Source
(Typ
)
5438 and then Convention
(Typ
) = Convention_Ada
5439 and then not Is_Limited_Type
(Typ
)
5441 Build_Untagged_Equality
(Typ
);
5444 -- Before building the record initialization procedure, if we are
5445 -- dealing with a concurrent record value type, then we must go through
5446 -- the discriminants, exchanging discriminals between the concurrent
5447 -- type and the concurrent record value type. See the section "Handling
5448 -- of Discriminants" in the Einfo spec for details.
5450 if Is_Concurrent_Record_Type
(Typ
)
5451 and then Has_Discriminants
(Typ
)
5454 Ctyp
: constant Entity_Id
:=
5455 Corresponding_Concurrent_Type
(Typ
);
5456 Conc_Discr
: Entity_Id
;
5457 Rec_Discr
: Entity_Id
;
5461 Conc_Discr
:= First_Discriminant
(Ctyp
);
5462 Rec_Discr
:= First_Discriminant
(Typ
);
5463 while Present
(Conc_Discr
) loop
5464 Temp
:= Discriminal
(Conc_Discr
);
5465 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
5466 Set_Discriminal
(Rec_Discr
, Temp
);
5468 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
5469 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
5471 Next_Discriminant
(Conc_Discr
);
5472 Next_Discriminant
(Rec_Discr
);
5477 if Has_Controlled_Component
(Typ
) then
5478 Build_Controlling_Procs
(Typ
);
5481 Adjust_Discriminants
(Typ
);
5483 -- Do not need init for interfaces on virtual targets since they're
5486 if Tagged_Type_Expansion
or else not Is_Interface
(Typ
) then
5487 Build_Record_Init_Proc
(Typ_Decl
, Typ
);
5490 -- For tagged type that are not interfaces, build bodies of primitive
5491 -- operations. Note: do this after building the record initialization
5492 -- procedure, since the primitive operations may need the initialization
5493 -- routine. There is no need to add predefined primitives of interfaces
5494 -- because all their predefined primitives are abstract.
5496 if Is_Tagged_Type
(Typ
) and then not Is_Interface
(Typ
) then
5498 -- Do not add the body of predefined primitives in case of CPP tagged
5499 -- type derivations that have convention CPP.
5501 if Is_CPP_Class
(Root_Type
(Typ
))
5502 and then Convention
(Typ
) = Convention_CPP
5506 -- Do not add the body of the predefined primitives if we are
5507 -- compiling under restriction No_Dispatching_Calls or if we are
5508 -- compiling a CPP tagged type.
5510 elsif not Restriction_Active
(No_Dispatching_Calls
) then
5512 -- Create the body of TSS primitive Finalize_Address. This must
5513 -- be done before the bodies of all predefined primitives are
5514 -- created. If Typ is limited, Stream_Input and Stream_Read may
5515 -- produce build-in-place allocations and for those the expander
5516 -- needs Finalize_Address.
5518 Make_Finalize_Address_Body
(Typ
);
5519 Predef_List
:= Predefined_Primitive_Bodies
(Typ
, Renamed_Eq
);
5520 Append_Freeze_Actions
(Typ
, Predef_List
);
5523 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
5524 -- inherited functions, then add their bodies to the freeze actions.
5526 if Present
(Wrapper_Body_List
) then
5527 Append_Freeze_Actions
(Typ
, Wrapper_Body_List
);
5530 -- Create extra formals for the primitive operations of the type.
5531 -- This must be done before analyzing the body of the initialization
5532 -- procedure, because a self-referential type might call one of these
5533 -- primitives in the body of the init_proc itself.
5540 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5541 while Present
(Elmt
) loop
5542 Subp
:= Node
(Elmt
);
5543 if not Has_Foreign_Convention
(Subp
)
5544 and then not Is_Predefined_Dispatching_Operation
(Subp
)
5546 Create_Extra_Formals
(Subp
);
5554 -- Check whether individual components have a defined invariant, and add
5555 -- the corresponding component invariant checks.
5557 -- Do not create an invariant procedure for some internally generated
5558 -- subtypes, in particular those created for objects of a class-wide
5559 -- type. Such types may have components to which invariant apply, but
5560 -- the corresponding checks will be applied when an object of the parent
5561 -- type is constructed.
5563 -- Such objects will show up in a class-wide postcondition, and the
5564 -- invariant will be checked, if necessary, upon return from the
5565 -- enclosing subprogram.
5567 if not Is_Class_Wide_Equivalent_Type
(Typ
) then
5568 Insert_Component_Invariant_Checks
5569 (N
, Typ
, Build_Record_Invariant_Proc
(Typ
, N
));
5572 Ghost_Mode
:= Save_Ghost_Mode
;
5573 end Expand_Freeze_Record_Type
;
5575 ------------------------------------
5576 -- Expand_N_Full_Type_Declaration --
5577 ------------------------------------
5579 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
) is
5580 procedure Build_Master
(Ptr_Typ
: Entity_Id
);
5581 -- Create the master associated with Ptr_Typ
5587 procedure Build_Master
(Ptr_Typ
: Entity_Id
) is
5588 Desig_Typ
: Entity_Id
:= Designated_Type
(Ptr_Typ
);
5591 -- If the designated type is an incomplete view coming from a
5592 -- limited-with'ed package, we need to use the nonlimited view in
5593 -- case it has tasks.
5595 if Ekind
(Desig_Typ
) in Incomplete_Kind
5596 and then Present
(Non_Limited_View
(Desig_Typ
))
5598 Desig_Typ
:= Non_Limited_View
(Desig_Typ
);
5601 -- Anonymous access types are created for the components of the
5602 -- record parameter for an entry declaration. No master is created
5605 if Comes_From_Source
(N
) and then Has_Task
(Desig_Typ
) then
5606 Build_Master_Entity
(Ptr_Typ
);
5607 Build_Master_Renaming
(Ptr_Typ
);
5609 -- Create a class-wide master because a Master_Id must be generated
5610 -- for access-to-limited-class-wide types whose root may be extended
5611 -- with task components.
5613 -- Note: This code covers access-to-limited-interfaces because they
5614 -- can be used to reference tasks implementing them.
5616 elsif Is_Limited_Class_Wide_Type
(Desig_Typ
)
5617 and then Tasking_Allowed
5619 Build_Class_Wide_Master
(Ptr_Typ
);
5623 -- Local declarations
5625 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5626 B_Id
: constant Entity_Id
:= Base_Type
(Def_Id
);
5630 -- Start of processing for Expand_N_Full_Type_Declaration
5633 if Is_Access_Type
(Def_Id
) then
5634 Build_Master
(Def_Id
);
5636 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
5637 Expand_Access_Protected_Subprogram_Type
(N
);
5640 -- Array of anonymous access-to-task pointers
5642 elsif Ada_Version
>= Ada_2005
5643 and then Is_Array_Type
(Def_Id
)
5644 and then Is_Access_Type
(Component_Type
(Def_Id
))
5645 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
5647 Build_Master
(Component_Type
(Def_Id
));
5649 elsif Has_Task
(Def_Id
) then
5650 Expand_Previous_Access_Type
(Def_Id
);
5652 -- Check the components of a record type or array of records for
5653 -- anonymous access-to-task pointers.
5655 elsif Ada_Version
>= Ada_2005
5656 and then (Is_Record_Type
(Def_Id
)
5658 (Is_Array_Type
(Def_Id
)
5659 and then Is_Record_Type
(Component_Type
(Def_Id
))))
5668 if Is_Array_Type
(Def_Id
) then
5669 Comp
:= First_Entity
(Component_Type
(Def_Id
));
5671 Comp
:= First_Entity
(Def_Id
);
5674 -- Examine all components looking for anonymous access-to-task
5678 while Present
(Comp
) loop
5679 Typ
:= Etype
(Comp
);
5681 if Ekind
(Typ
) = E_Anonymous_Access_Type
5682 and then Has_Task
(Available_View
(Designated_Type
(Typ
)))
5683 and then No
(Master_Id
(Typ
))
5685 -- Ensure that the record or array type have a _master
5688 Build_Master_Entity
(Def_Id
);
5689 Build_Master_Renaming
(Typ
);
5690 M_Id
:= Master_Id
(Typ
);
5694 -- Reuse the same master to service any additional types
5697 Set_Master_Id
(Typ
, M_Id
);
5706 Par_Id
:= Etype
(B_Id
);
5708 -- The parent type is private then we need to inherit any TSS operations
5709 -- from the full view.
5711 if Ekind
(Par_Id
) in Private_Kind
5712 and then Present
(Full_View
(Par_Id
))
5714 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
5717 if Nkind
(Type_Definition
(Original_Node
(N
))) =
5718 N_Derived_Type_Definition
5719 and then not Is_Tagged_Type
(Def_Id
)
5720 and then Present
(Freeze_Node
(Par_Id
))
5721 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
5723 Ensure_Freeze_Node
(B_Id
);
5724 FN
:= Freeze_Node
(B_Id
);
5726 if No
(TSS_Elist
(FN
)) then
5727 Set_TSS_Elist
(FN
, New_Elmt_List
);
5731 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
5735 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
5736 while Present
(Elmt
) loop
5737 if Chars
(Node
(Elmt
)) /= Name_uInit
then
5738 Append_Elmt
(Node
(Elmt
), T_E
);
5744 -- If the derived type itself is private with a full view, then
5745 -- associate the full view with the inherited TSS_Elist as well.
5747 if Ekind
(B_Id
) in Private_Kind
5748 and then Present
(Full_View
(B_Id
))
5750 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
5752 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
5756 end Expand_N_Full_Type_Declaration
;
5758 ---------------------------------
5759 -- Expand_N_Object_Declaration --
5760 ---------------------------------
5762 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
5763 Loc
: constant Source_Ptr
:= Sloc
(N
);
5764 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5765 Expr
: constant Node_Id
:= Expression
(N
);
5766 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
5767 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
5768 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5771 function Build_Equivalent_Aggregate
return Boolean;
5772 -- If the object has a constrained discriminated type and no initial
5773 -- value, it may be possible to build an equivalent aggregate instead,
5774 -- and prevent an actual call to the initialization procedure.
5776 procedure Default_Initialize_Object
(After
: Node_Id
);
5777 -- Generate all default initialization actions for object Def_Id. Any
5778 -- new code is inserted after node After.
5780 function Rewrite_As_Renaming
return Boolean;
5781 -- Indicate whether to rewrite a declaration with initialization into an
5782 -- object renaming declaration (see below).
5784 --------------------------------
5785 -- Build_Equivalent_Aggregate --
5786 --------------------------------
5788 function Build_Equivalent_Aggregate
return Boolean is
5792 Full_Type
: Entity_Id
;
5797 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
5798 Full_Type
:= Full_View
(Typ
);
5801 -- Only perform this transformation if Elaboration_Code is forbidden
5802 -- or undesirable, and if this is a global entity of a constrained
5805 -- If Initialize_Scalars might be active this transformation cannot
5806 -- be performed either, because it will lead to different semantics
5807 -- or because elaboration code will in fact be created.
5809 if Ekind
(Full_Type
) /= E_Record_Subtype
5810 or else not Has_Discriminants
(Full_Type
)
5811 or else not Is_Constrained
(Full_Type
)
5812 or else Is_Controlled
(Full_Type
)
5813 or else Is_Limited_Type
(Full_Type
)
5814 or else not Restriction_Active
(No_Initialize_Scalars
)
5819 if Ekind
(Current_Scope
) = E_Package
5821 (Restriction_Active
(No_Elaboration_Code
)
5822 or else Is_Preelaborated
(Current_Scope
))
5824 -- Building a static aggregate is possible if the discriminants
5825 -- have static values and the other components have static
5826 -- defaults or none.
5828 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5829 while Present
(Discr
) loop
5830 if not Is_OK_Static_Expression
(Node
(Discr
)) then
5837 -- Check that initialized components are OK, and that non-
5838 -- initialized components do not require a call to their own
5839 -- initialization procedure.
5841 Comp
:= First_Component
(Full_Type
);
5842 while Present
(Comp
) loop
5843 if Ekind
(Comp
) = E_Component
5844 and then Present
(Expression
(Parent
(Comp
)))
5846 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
5850 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
5855 Next_Component
(Comp
);
5858 -- Everything is static, assemble the aggregate, discriminant
5862 Make_Aggregate
(Loc
,
5863 Expressions
=> New_List
,
5864 Component_Associations
=> New_List
);
5866 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
5867 while Present
(Discr
) loop
5868 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
5872 -- Now collect values of initialized components
5874 Comp
:= First_Component
(Full_Type
);
5875 while Present
(Comp
) loop
5876 if Ekind
(Comp
) = E_Component
5877 and then Present
(Expression
(Parent
(Comp
)))
5879 Append_To
(Component_Associations
(Aggr
),
5880 Make_Component_Association
(Loc
,
5881 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
5882 Expression
=> New_Copy_Tree
5883 (Expression
(Parent
(Comp
)))));
5886 Next_Component
(Comp
);
5889 -- Finally, box-initialize remaining components
5891 Append_To
(Component_Associations
(Aggr
),
5892 Make_Component_Association
(Loc
,
5893 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5894 Expression
=> Empty
));
5895 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
5896 Set_Expression
(N
, Aggr
);
5898 if Typ
/= Full_Type
then
5899 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
5900 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
5901 Analyze_And_Resolve
(Aggr
, Typ
);
5903 Analyze_And_Resolve
(Aggr
, Full_Type
);
5911 end Build_Equivalent_Aggregate
;
5913 -------------------------------
5914 -- Default_Initialize_Object --
5915 -------------------------------
5917 procedure Default_Initialize_Object
(After
: Node_Id
) is
5918 function New_Object_Reference
return Node_Id
;
5919 -- Return a new reference to Def_Id with attributes Assignment_OK and
5920 -- Must_Not_Freeze already set.
5922 --------------------------
5923 -- New_Object_Reference --
5924 --------------------------
5926 function New_Object_Reference
return Node_Id
is
5927 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
5930 -- The call to the type init proc or [Deep_]Finalize must not
5931 -- freeze the related object as the call is internally generated.
5932 -- This way legal rep clauses that apply to the object will not be
5933 -- flagged. Note that the initialization call may be removed if
5934 -- pragma Import is encountered or moved to the freeze actions of
5935 -- the object because of an address clause.
5937 Set_Assignment_OK
(Obj_Ref
);
5938 Set_Must_Not_Freeze
(Obj_Ref
);
5941 end New_Object_Reference
;
5945 Exceptions_OK
: constant Boolean :=
5946 not Restriction_Active
(No_Exception_Propagation
);
5949 Abrt_Blk_Id
: Entity_Id
;
5951 Aggr_Init
: Node_Id
;
5953 Comp_Init
: List_Id
:= No_List
;
5955 Init_Stmts
: List_Id
:= No_List
;
5956 Obj_Init
: Node_Id
:= Empty
;
5959 -- Start of processing for Default_Initialize_Object
5962 -- Default initialization is suppressed for objects that are already
5963 -- known to be imported (i.e. whose declaration specifies the Import
5964 -- aspect). Note that for objects with a pragma Import, we generate
5965 -- initialization here, and then remove it downstream when processing
5966 -- the pragma. It is also suppressed for variables for which a pragma
5967 -- Suppress_Initialization has been explicitly given
5969 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
5973 -- The expansion performed by this routine is as follows:
5977 -- Type_Init_Proc (Obj);
5980 -- [Deep_]Initialize (Obj);
5984 -- [Deep_]Finalize (Obj, Self => False);
5988 -- Abort_Undefer_Direct;
5991 -- Initialize the components of the object
5993 if Has_Non_Null_Base_Init_Proc
(Typ
)
5994 and then not No_Initialization
(N
)
5995 and then not Initialization_Suppressed
(Typ
)
5997 -- Do not initialize the components if No_Default_Initialization
5998 -- applies as the actual restriction check will occur later
5999 -- when the object is frozen as it is not known yet whether the
6000 -- object is imported or not.
6002 if not Restriction_Active
(No_Default_Initialization
) then
6004 -- If the values of the components are compile-time known, use
6005 -- their prebuilt aggregate form directly.
6007 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
6009 if Present
(Aggr_Init
) then
6011 (N
, New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
6013 -- If type has discriminants, try to build an equivalent
6014 -- aggregate using discriminant values from the declaration.
6015 -- This is a useful optimization, in particular if restriction
6016 -- No_Elaboration_Code is active.
6018 elsif Build_Equivalent_Aggregate
then
6021 -- Otherwise invoke the type init proc, generate:
6022 -- Type_Init_Proc (Obj);
6025 Obj_Ref
:= New_Object_Reference
;
6027 if Comes_From_Source
(Def_Id
) then
6028 Initialization_Warning
(Obj_Ref
);
6031 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
6035 -- Provide a default value if the object needs simple initialization
6036 -- and does not already have an initial value. A generated temporary
6037 -- does not require initialization because it will be assigned later.
6039 elsif Needs_Simple_Initialization
6040 (Typ
, Initialize_Scalars
6041 and then No
(Following_Address_Clause
(N
)))
6042 and then not Is_Internal
(Def_Id
)
6043 and then not Has_Init_Expression
(N
)
6045 Set_No_Initialization
(N
, False);
6046 Set_Expression
(N
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Def_Id
)));
6047 Analyze_And_Resolve
(Expression
(N
), Typ
);
6050 -- Initialize the object, generate:
6051 -- [Deep_]Initialize (Obj);
6053 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
6056 (Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
6060 -- Build a special finalization block when both the object and its
6061 -- controlled components are to be initialized. The block finalizes
6062 -- the components if the object initialization fails. Generate:
6073 if Has_Controlled_Component
(Typ
)
6074 and then Present
(Comp_Init
)
6075 and then Present
(Obj_Init
)
6076 and then Exceptions_OK
6078 Init_Stmts
:= Comp_Init
;
6082 (Obj_Ref
=> New_Object_Reference
,
6086 if Present
(Fin_Call
) then
6088 -- Do not emit warnings related to the elaboration order when a
6089 -- controlled object is declared before the body of Finalize is
6092 Set_No_Elaboration_Check
(Fin_Call
);
6094 Append_To
(Init_Stmts
,
6095 Make_Block_Statement
(Loc
,
6096 Declarations
=> No_List
,
6098 Handled_Statement_Sequence
=>
6099 Make_Handled_Sequence_Of_Statements
(Loc
,
6100 Statements
=> New_List
(Obj_Init
),
6102 Exception_Handlers
=> New_List
(
6103 Make_Exception_Handler
(Loc
,
6104 Exception_Choices
=> New_List
(
6105 Make_Others_Choice
(Loc
)),
6107 Statements
=> New_List
(
6109 Make_Raise_Statement
(Loc
)))))));
6112 -- Otherwise finalization is not required, the initialization calls
6113 -- are passed to the abort block building circuitry, generate:
6115 -- Type_Init_Proc (Obj);
6116 -- [Deep_]Initialize (Obj);
6119 if Present
(Comp_Init
) then
6120 Init_Stmts
:= Comp_Init
;
6123 if Present
(Obj_Init
) then
6124 if No
(Init_Stmts
) then
6125 Init_Stmts
:= New_List
;
6128 Append_To
(Init_Stmts
, Obj_Init
);
6132 -- Build an abort block to protect the initialization calls
6135 and then Present
(Comp_Init
)
6136 and then Present
(Obj_Init
)
6141 Prepend_To
(Init_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
6143 -- When exceptions are propagated, abort deferral must take place
6144 -- in the presence of initialization or finalization exceptions.
6151 -- Abort_Undefer_Direct;
6154 if Exceptions_OK
then
6155 AUD
:= RTE
(RE_Abort_Undefer_Direct
);
6158 Make_Handled_Sequence_Of_Statements
(Loc
,
6159 Statements
=> Init_Stmts
,
6160 At_End_Proc
=> New_Occurrence_Of
(AUD
, Loc
));
6163 Make_Block_Statement
(Loc
,
6164 Handled_Statement_Sequence
=> Abrt_HSS
);
6166 Add_Block_Identifier
(Abrt_Blk
, Abrt_Blk_Id
);
6167 Expand_At_End_Handler
(Abrt_HSS
, Abrt_Blk_Id
);
6169 -- Present the Abort_Undefer_Direct function to the backend so
6170 -- that it can inline the call to the function.
6172 Add_Inlined_Body
(AUD
, N
);
6174 Init_Stmts
:= New_List
(Abrt_Blk
);
6176 -- Otherwise exceptions are not propagated. Generate:
6183 Append_To
(Init_Stmts
,
6184 Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
6188 -- Insert the whole initialization sequence into the tree. If the
6189 -- object has a delayed freeze, as will be the case when it has
6190 -- aspect specifications, the initialization sequence is part of
6191 -- the freeze actions.
6193 if Present
(Init_Stmts
) then
6194 if Has_Delayed_Freeze
(Def_Id
) then
6195 Append_Freeze_Actions
(Def_Id
, Init_Stmts
);
6197 Insert_Actions_After
(After
, Init_Stmts
);
6200 end Default_Initialize_Object
;
6202 -------------------------
6203 -- Rewrite_As_Renaming --
6204 -------------------------
6206 function Rewrite_As_Renaming
return Boolean is
6208 -- If the object declaration appears in the form
6210 -- Obj : Ctrl_Typ := Func (...);
6212 -- where Ctrl_Typ is controlled but not immutably limited type, then
6213 -- the expansion of the function call should use a dereference of the
6214 -- result to reference the value on the secondary stack.
6216 -- Obj : Ctrl_Typ renames Func (...).all;
6218 -- As a result, the call avoids an extra copy. This an optimization,
6219 -- but it is required for passing ACATS tests in some cases where it
6220 -- would otherwise make two copies. The RM allows removing redunant
6221 -- Adjust/Finalize calls, but does not allow insertion of extra ones.
6223 -- This part is disabled for now, because it breaks GPS builds
6225 return (False -- ???
6226 and then Nkind
(Expr_Q
) = N_Explicit_Dereference
6227 and then not Comes_From_Source
(Expr_Q
)
6228 and then Nkind
(Original_Node
(Expr_Q
)) = N_Function_Call
6229 and then Nkind
(Object_Definition
(N
)) in N_Has_Entity
6230 and then (Needs_Finalization
(Entity
(Object_Definition
(N
)))))
6232 -- If the initializing expression is for a variable with attribute
6233 -- OK_To_Rename set, then transform:
6235 -- Obj : Typ := Expr;
6239 -- Obj : Typ renames Expr;
6241 -- provided that Obj is not aliased. The aliased case has to be
6242 -- excluded in general because Expr will not be aliased in
6246 (not Aliased_Present
(N
)
6247 and then Is_Entity_Name
(Expr_Q
)
6248 and then Ekind
(Entity
(Expr_Q
)) = E_Variable
6249 and then OK_To_Rename
(Entity
(Expr_Q
))
6250 and then Is_Entity_Name
(Obj_Def
));
6251 end Rewrite_As_Renaming
;
6255 Next_N
: constant Node_Id
:= Next
(N
);
6257 Tag_Assign
: Node_Id
;
6259 Init_After
: Node_Id
:= N
;
6260 -- Node after which the initialization actions are to be inserted. This
6261 -- is normally N, except for the case of a shared passive variable, in
6262 -- which case the init proc call must be inserted only after the bodies
6263 -- of the shared variable procedures have been seen.
6265 -- Start of processing for Expand_N_Object_Declaration
6268 -- Don't do anything for deferred constants. All proper actions will be
6269 -- expanded during the full declaration.
6271 if No
(Expr
) and Constant_Present
(N
) then
6275 -- The type of the object cannot be abstract. This is diagnosed at the
6276 -- point the object is frozen, which happens after the declaration is
6277 -- fully expanded, so simply return now.
6279 if Is_Abstract_Type
(Typ
) then
6283 -- First we do special processing for objects of a tagged type where
6284 -- this is the point at which the type is frozen. The creation of the
6285 -- dispatch table and the initialization procedure have to be deferred
6286 -- to this point, since we reference previously declared primitive
6289 -- Force construction of dispatch tables of library level tagged types
6291 if Tagged_Type_Expansion
6292 and then Static_Dispatch_Tables
6293 and then Is_Library_Level_Entity
(Def_Id
)
6294 and then Is_Library_Level_Tagged_Type
(Base_Typ
)
6295 and then Ekind_In
(Base_Typ
, E_Record_Type
,
6298 and then not Has_Dispatch_Table
(Base_Typ
)
6301 New_Nodes
: List_Id
:= No_List
;
6304 if Is_Concurrent_Type
(Base_Typ
) then
6305 New_Nodes
:= Make_DT
(Corresponding_Record_Type
(Base_Typ
), N
);
6307 New_Nodes
:= Make_DT
(Base_Typ
, N
);
6310 if not Is_Empty_List
(New_Nodes
) then
6311 Insert_List_Before
(N
, New_Nodes
);
6316 -- Make shared memory routines for shared passive variable
6318 if Is_Shared_Passive
(Def_Id
) then
6319 Init_After
:= Make_Shared_Var_Procs
(N
);
6322 -- If tasks being declared, make sure we have an activation chain
6323 -- defined for the tasks (has no effect if we already have one), and
6324 -- also that a Master variable is established and that the appropriate
6325 -- enclosing construct is established as a task master.
6327 if Has_Task
(Typ
) then
6328 Build_Activation_Chain_Entity
(N
);
6329 Build_Master_Entity
(Def_Id
);
6332 -- Default initialization required, and no expression present
6336 -- If we have a type with a variant part, the initialization proc
6337 -- will contain implicit tests of the discriminant values, which
6338 -- counts as a violation of the restriction No_Implicit_Conditionals.
6340 if Has_Variant_Part
(Typ
) then
6345 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
6349 ("\initialization of variant record tests discriminants",
6356 -- For the default initialization case, if we have a private type
6357 -- with invariants, and invariant checks are enabled, then insert an
6358 -- invariant check after the object declaration. Note that it is OK
6359 -- to clobber the object with an invalid value since if the exception
6360 -- is raised, then the object will go out of scope. In the case where
6361 -- an array object is initialized with an aggregate, the expression
6362 -- is removed. Check flag Has_Init_Expression to avoid generating a
6363 -- junk invariant check and flag No_Initialization to avoid checking
6364 -- an uninitialized object such as a compiler temporary used for an
6367 if Has_Invariants
(Base_Typ
)
6368 and then Present
(Invariant_Procedure
(Base_Typ
))
6369 and then not Has_Init_Expression
(N
)
6370 and then not No_Initialization
(N
)
6372 -- If entity has an address clause or aspect, make invariant
6373 -- call into a freeze action for the explicit freeze node for
6374 -- object. Otherwise insert invariant check after declaration.
6376 if Present
(Following_Address_Clause
(N
))
6377 or else Has_Aspect
(Def_Id
, Aspect_Address
)
6379 Ensure_Freeze_Node
(Def_Id
);
6380 Set_Has_Delayed_Freeze
(Def_Id
);
6381 Set_Is_Frozen
(Def_Id
, False);
6383 if not Partial_View_Has_Unknown_Discr
(Typ
) then
6384 Append_Freeze_Action
(Def_Id
,
6385 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
6388 elsif not Partial_View_Has_Unknown_Discr
(Typ
) then
6390 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
6394 Default_Initialize_Object
(Init_After
);
6396 -- Generate attribute for Persistent_BSS if needed
6398 if Persistent_BSS_Mode
6399 and then Comes_From_Source
(N
)
6400 and then Is_Potentially_Persistent_Type
(Typ
)
6401 and then not Has_Init_Expression
(N
)
6402 and then Is_Library_Level_Entity
(Def_Id
)
6408 Make_Linker_Section_Pragma
6409 (Def_Id
, Sloc
(N
), ".persistent.bss");
6410 Insert_After
(N
, Prag
);
6415 -- If access type, then we know it is null if not initialized
6417 if Is_Access_Type
(Typ
) then
6418 Set_Is_Known_Null
(Def_Id
);
6421 -- Explicit initialization present
6424 -- Obtain actual expression from qualified expression
6426 if Nkind
(Expr
) = N_Qualified_Expression
then
6427 Expr_Q
:= Expression
(Expr
);
6432 -- When we have the appropriate type of aggregate in the expression
6433 -- (it has been determined during analysis of the aggregate by
6434 -- setting the delay flag), let's perform in place assignment and
6435 -- thus avoid creating a temporary.
6437 if Is_Delayed_Aggregate
(Expr_Q
) then
6438 Convert_Aggr_In_Object_Decl
(N
);
6440 -- Ada 2005 (AI-318-02): If the initialization expression is a call
6441 -- to a build-in-place function, then access to the declared object
6442 -- must be passed to the function. Currently we limit such functions
6443 -- to those with constrained limited result subtypes, but eventually
6444 -- plan to expand the allowed forms of functions that are treated as
6447 elsif Ada_Version
>= Ada_2005
6448 and then Is_Build_In_Place_Function_Call
(Expr_Q
)
6450 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
6452 -- The previous call expands the expression initializing the
6453 -- built-in-place object into further code that will be analyzed
6454 -- later. No further expansion needed here.
6458 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
6459 -- class-wide interface object to ensure that we copy the full
6460 -- object, unless we are targetting a VM where interfaces are handled
6461 -- by VM itself. Note that if the root type of Typ is an ancestor of
6462 -- Expr's type, both types share the same dispatch table and there is
6463 -- no need to displace the pointer.
6465 elsif Is_Interface
(Typ
)
6467 -- Avoid never-ending recursion because if Equivalent_Type is set
6468 -- then we've done it already and must not do it again.
6471 (Nkind
(Obj_Def
) = N_Identifier
6472 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
6474 pragma Assert
(Is_Class_Wide_Type
(Typ
));
6476 -- If the object is a return object of an inherently limited type,
6477 -- which implies build-in-place treatment, bypass the special
6478 -- treatment of class-wide interface initialization below. In this
6479 -- case, the expansion of the return statement will take care of
6480 -- creating the object (via allocator) and initializing it.
6482 if Is_Return_Object
(Def_Id
) and then Is_Limited_View
(Typ
) then
6485 elsif Tagged_Type_Expansion
then
6487 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
6488 Expr_N
: Node_Id
:= Expr
;
6489 Expr_Typ
: Entity_Id
;
6495 -- If the original node of the expression was a conversion
6496 -- to this specific class-wide interface type then restore
6497 -- the original node because we must copy the object before
6498 -- displacing the pointer to reference the secondary tag
6499 -- component. This code must be kept synchronized with the
6500 -- expansion done by routine Expand_Interface_Conversion
6502 if not Comes_From_Source
(Expr_N
)
6503 and then Nkind
(Expr_N
) = N_Explicit_Dereference
6504 and then Nkind
(Original_Node
(Expr_N
)) = N_Type_Conversion
6505 and then Etype
(Original_Node
(Expr_N
)) = Typ
6507 Rewrite
(Expr_N
, Original_Node
(Expression
(N
)));
6510 -- Avoid expansion of redundant interface conversion
6512 if Is_Interface
(Etype
(Expr_N
))
6513 and then Nkind
(Expr_N
) = N_Type_Conversion
6514 and then Etype
(Expr_N
) = Typ
6516 Expr_N
:= Expression
(Expr_N
);
6517 Set_Expression
(N
, Expr_N
);
6520 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_N
);
6521 Expr_Typ
:= Base_Type
(Etype
(Expr_N
));
6523 if Is_Class_Wide_Type
(Expr_Typ
) then
6524 Expr_Typ
:= Root_Type
(Expr_Typ
);
6528 -- CW : I'Class := Obj;
6531 -- type Ityp is not null access I'Class;
6532 -- CW : I'Class renames Ityp (Tmp.I_Tag'Address).all;
6534 if Comes_From_Source
(Expr_N
)
6535 and then Nkind
(Expr_N
) = N_Identifier
6536 and then not Is_Interface
(Expr_Typ
)
6537 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
6538 and then (Expr_Typ
= Etype
(Expr_Typ
)
6540 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
6545 Make_Object_Declaration
(Loc
,
6546 Defining_Identifier
=> Obj_Id
,
6547 Object_Definition
=>
6548 New_Occurrence_Of
(Expr_Typ
, Loc
),
6549 Expression
=> Relocate_Node
(Expr_N
)));
6551 -- Statically reference the tag associated with the
6555 Make_Selected_Component
(Loc
,
6556 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
6559 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
6562 -- IW : I'Class := Obj;
6564 -- type Equiv_Record is record ... end record;
6565 -- implicit subtype CW is <Class_Wide_Subtype>;
6566 -- Tmp : CW := CW!(Obj);
6567 -- type Ityp is not null access I'Class;
6568 -- IW : I'Class renames
6569 -- Ityp!(Displace (Temp'Address, I'Tag)).all;
6572 -- Generate the equivalent record type and update the
6573 -- subtype indication to reference it.
6575 Expand_Subtype_From_Expr
6578 Subtype_Indic
=> Obj_Def
,
6581 if not Is_Interface
(Etype
(Expr_N
)) then
6582 New_Expr
:= Relocate_Node
(Expr_N
);
6584 -- For interface types we use 'Address which displaces
6585 -- the pointer to the base of the object (if required)
6589 Unchecked_Convert_To
(Etype
(Obj_Def
),
6590 Make_Explicit_Dereference
(Loc
,
6591 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
6592 Make_Attribute_Reference
(Loc
,
6593 Prefix
=> Relocate_Node
(Expr_N
),
6594 Attribute_Name
=> Name_Address
))));
6599 if not Is_Limited_Record
(Expr_Typ
) then
6601 Make_Object_Declaration
(Loc
,
6602 Defining_Identifier
=> Obj_Id
,
6603 Object_Definition
=>
6604 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
6605 Expression
=> New_Expr
));
6607 -- Rename limited type object since they cannot be copied
6608 -- This case occurs when the initialization expression
6609 -- has been previously expanded into a temporary object.
6611 else pragma Assert
(not Comes_From_Source
(Expr_Q
));
6613 Make_Object_Renaming_Declaration
(Loc
,
6614 Defining_Identifier
=> Obj_Id
,
6616 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
6618 Unchecked_Convert_To
6619 (Etype
(Obj_Def
), New_Expr
)));
6622 -- Dynamically reference the tag associated with the
6626 Make_Function_Call
(Loc
,
6627 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
6628 Parameter_Associations
=> New_List
(
6629 Make_Attribute_Reference
(Loc
,
6630 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
6631 Attribute_Name
=> Name_Address
),
6633 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
6638 Make_Object_Renaming_Declaration
(Loc
,
6639 Defining_Identifier
=> Make_Temporary
(Loc
, 'D'),
6640 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
6642 Convert_Tag_To_Interface
(Typ
, Tag_Comp
)));
6644 -- If the original entity comes from source, then mark the
6645 -- new entity as needing debug information, even though it's
6646 -- defined by a generated renaming that does not come from
6647 -- source, so that Materialize_Entity will be set on the
6648 -- entity when Debug_Renaming_Declaration is called during
6651 if Comes_From_Source
(Def_Id
) then
6652 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
6655 Analyze
(N
, Suppress
=> All_Checks
);
6657 -- Replace internal identifier of rewritten node by the
6658 -- identifier found in the sources. We also have to exchange
6659 -- entities containing their defining identifiers to ensure
6660 -- the correct replacement of the object declaration by this
6661 -- object renaming declaration because these identifiers
6662 -- were previously added by Enter_Name to the current scope.
6663 -- We must preserve the homonym chain of the source entity
6664 -- as well. We must also preserve the kind of the entity,
6665 -- which may be a constant. Preserve entity chain because
6666 -- itypes may have been generated already, and the full
6667 -- chain must be preserved for final freezing. Finally,
6668 -- preserve Comes_From_Source setting, so that debugging
6669 -- and cross-referencing information is properly kept, and
6670 -- preserve source location, to prevent spurious errors when
6671 -- entities are declared (they must have their own Sloc).
6674 New_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6675 Next_Temp
: constant Entity_Id
:= Next_Entity
(New_Id
);
6676 S_Flag
: constant Boolean :=
6677 Comes_From_Source
(Def_Id
);
6680 Set_Next_Entity
(New_Id
, Next_Entity
(Def_Id
));
6681 Set_Next_Entity
(Def_Id
, Next_Temp
);
6683 Set_Chars
(Defining_Identifier
(N
), Chars
(Def_Id
));
6684 Set_Homonym
(Defining_Identifier
(N
), Homonym
(Def_Id
));
6685 Set_Ekind
(Defining_Identifier
(N
), Ekind
(Def_Id
));
6686 Set_Sloc
(Defining_Identifier
(N
), Sloc
(Def_Id
));
6688 Set_Comes_From_Source
(Def_Id
, False);
6689 Exchange_Entities
(Defining_Identifier
(N
), Def_Id
);
6690 Set_Comes_From_Source
(Def_Id
, S_Flag
);
6697 -- Common case of explicit object initialization
6700 -- In most cases, we must check that the initial value meets any
6701 -- constraint imposed by the declared type. However, there is one
6702 -- very important exception to this rule. If the entity has an
6703 -- unconstrained nominal subtype, then it acquired its constraints
6704 -- from the expression in the first place, and not only does this
6705 -- mean that the constraint check is not needed, but an attempt to
6706 -- perform the constraint check can cause order of elaboration
6709 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
6711 -- If this is an allocator for an aggregate that has been
6712 -- allocated in place, delay checks until assignments are
6713 -- made, because the discriminants are not initialized.
6715 if Nkind
(Expr
) = N_Allocator
and then No_Initialization
(Expr
)
6719 -- Otherwise apply a constraint check now if no prev error
6721 elsif Nkind
(Expr
) /= N_Error
then
6722 Apply_Constraint_Check
(Expr
, Typ
);
6724 -- Deal with possible range check
6726 if Do_Range_Check
(Expr
) then
6728 -- If assignment checks are suppressed, turn off flag
6730 if Suppress_Assignment_Checks
(N
) then
6731 Set_Do_Range_Check
(Expr
, False);
6733 -- Otherwise generate the range check
6736 Generate_Range_Check
6737 (Expr
, Typ
, CE_Range_Check_Failed
);
6743 -- If the type is controlled and not inherently limited, then
6744 -- the target is adjusted after the copy and attached to the
6745 -- finalization list. However, no adjustment is done in the case
6746 -- where the object was initialized by a call to a function whose
6747 -- result is built in place, since no copy occurred. (Eventually
6748 -- we plan to support in-place function results for some cases
6749 -- of nonlimited types. ???) Similarly, no adjustment is required
6750 -- if we are going to rewrite the object declaration into a
6751 -- renaming declaration.
6753 if Needs_Finalization
(Typ
)
6754 and then not Is_Limited_View
(Typ
)
6755 and then not Rewrite_As_Renaming
6757 Insert_Action_After
(Init_After
,
6759 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
6763 -- For tagged types, when an init value is given, the tag has to
6764 -- be re-initialized separately in order to avoid the propagation
6765 -- of a wrong tag coming from a view conversion unless the type
6766 -- is class wide (in this case the tag comes from the init value).
6767 -- Suppress the tag assignment when not Tagged_Type_Expansion
6768 -- because tags are represented implicitly in objects. Ditto for
6769 -- types that are CPP_CLASS, and for initializations that are
6770 -- aggregates, because they have to have the right tag.
6772 -- The re-assignment of the tag has to be done even if the object
6773 -- is a constant. The assignment must be analyzed after the
6774 -- declaration. If an address clause follows, this is handled as
6775 -- part of the freeze actions for the object, otherwise insert
6776 -- tag assignment here.
6778 Tag_Assign
:= Make_Tag_Assignment
(N
);
6780 if Present
(Tag_Assign
) then
6781 if Present
(Following_Address_Clause
(N
)) then
6782 Ensure_Freeze_Node
(Def_Id
);
6785 Insert_Action_After
(Init_After
, Tag_Assign
);
6788 -- Handle C++ constructor calls. Note that we do not check that
6789 -- Typ is a tagged type since the equivalent Ada type of a C++
6790 -- class that has no virtual methods is an untagged limited
6793 elsif Is_CPP_Constructor_Call
(Expr
) then
6795 -- The call to the initialization procedure does NOT freeze the
6796 -- object being initialized.
6798 Id_Ref
:= New_Occurrence_Of
(Def_Id
, Loc
);
6799 Set_Must_Not_Freeze
(Id_Ref
);
6800 Set_Assignment_OK
(Id_Ref
);
6802 Insert_Actions_After
(Init_After
,
6803 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
6804 Constructor_Ref
=> Expr
));
6806 -- We remove here the original call to the constructor
6807 -- to avoid its management in the backend
6809 Set_Expression
(N
, Empty
);
6812 -- Handle initialization of limited tagged types
6814 elsif Is_Tagged_Type
(Typ
)
6815 and then Is_Class_Wide_Type
(Typ
)
6816 and then Is_Limited_Record
(Typ
)
6817 and then not Is_Limited_Interface
(Typ
)
6819 -- Given that the type is limited we cannot perform a copy. If
6820 -- Expr_Q is the reference to a variable we mark the variable
6821 -- as OK_To_Rename to expand this declaration into a renaming
6822 -- declaration (see bellow).
6824 if Is_Entity_Name
(Expr_Q
) then
6825 Set_OK_To_Rename
(Entity
(Expr_Q
));
6827 -- If we cannot convert the expression into a renaming we must
6828 -- consider it an internal error because the backend does not
6829 -- have support to handle it.
6832 pragma Assert
(False);
6833 raise Program_Error
;
6836 -- For discrete types, set the Is_Known_Valid flag if the
6837 -- initializing value is known to be valid. Only do this for
6838 -- source assignments, since otherwise we can end up turning
6839 -- on the known valid flag prematurely from inserted code.
6841 elsif Comes_From_Source
(N
)
6842 and then Is_Discrete_Type
(Typ
)
6843 and then Expr_Known_Valid
(Expr
)
6845 Set_Is_Known_Valid
(Def_Id
);
6847 elsif Is_Access_Type
(Typ
) then
6849 -- For access types set the Is_Known_Non_Null flag if the
6850 -- initializing value is known to be non-null. We can also set
6851 -- Can_Never_Be_Null if this is a constant.
6853 if Known_Non_Null
(Expr
) then
6854 Set_Is_Known_Non_Null
(Def_Id
, True);
6856 if Constant_Present
(N
) then
6857 Set_Can_Never_Be_Null
(Def_Id
);
6862 -- If validity checking on copies, validate initial expression.
6863 -- But skip this if declaration is for a generic type, since it
6864 -- makes no sense to validate generic types. Not clear if this
6865 -- can happen for legal programs, but it definitely can arise
6866 -- from previous instantiation errors.
6868 if Validity_Checks_On
6869 and then Comes_From_Source
(N
)
6870 and then Validity_Check_Copies
6871 and then not Is_Generic_Type
(Etype
(Def_Id
))
6873 Ensure_Valid
(Expr
);
6874 Set_Is_Known_Valid
(Def_Id
);
6878 -- Cases where the back end cannot handle the initialization directly
6879 -- In such cases, we expand an assignment that will be appropriately
6880 -- handled by Expand_N_Assignment_Statement.
6882 -- The exclusion of the unconstrained case is wrong, but for now it
6883 -- is too much trouble ???
6885 if (Is_Possibly_Unaligned_Slice
(Expr
)
6886 or else (Is_Possibly_Unaligned_Object
(Expr
)
6887 and then not Represented_As_Scalar
(Etype
(Expr
))))
6888 and then not (Is_Array_Type
(Etype
(Expr
))
6889 and then not Is_Constrained
(Etype
(Expr
)))
6892 Stat
: constant Node_Id
:=
6893 Make_Assignment_Statement
(Loc
,
6894 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
6895 Expression
=> Relocate_Node
(Expr
));
6897 Set_Expression
(N
, Empty
);
6898 Set_No_Initialization
(N
);
6899 Set_Assignment_OK
(Name
(Stat
));
6900 Set_No_Ctrl_Actions
(Stat
);
6901 Insert_After_And_Analyze
(Init_After
, Stat
);
6906 if Nkind
(Obj_Def
) = N_Access_Definition
6907 and then not Is_Local_Anonymous_Access
(Etype
(Def_Id
))
6909 -- An Ada 2012 stand-alone object of an anonymous access type
6912 Loc
: constant Source_Ptr
:= Sloc
(N
);
6914 Level
: constant Entity_Id
:=
6915 Make_Defining_Identifier
(Sloc
(N
),
6917 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
6919 Level_Expr
: Node_Id
;
6920 Level_Decl
: Node_Id
;
6923 Set_Ekind
(Level
, Ekind
(Def_Id
));
6924 Set_Etype
(Level
, Standard_Natural
);
6925 Set_Scope
(Level
, Scope
(Def_Id
));
6929 -- Set accessibility level of null
6932 Make_Integer_Literal
(Loc
, Scope_Depth
(Standard_Standard
));
6935 Level_Expr
:= Dynamic_Accessibility_Level
(Expr
);
6939 Make_Object_Declaration
(Loc
,
6940 Defining_Identifier
=> Level
,
6941 Object_Definition
=>
6942 New_Occurrence_Of
(Standard_Natural
, Loc
),
6943 Expression
=> Level_Expr
,
6944 Constant_Present
=> Constant_Present
(N
),
6945 Has_Init_Expression
=> True);
6947 Insert_Action_After
(Init_After
, Level_Decl
);
6949 Set_Extra_Accessibility
(Def_Id
, Level
);
6953 -- If the object is default initialized and its type is subject to
6954 -- pragma Default_Initial_Condition, add a runtime check to verify
6955 -- the assumption of the pragma (SPARK RM 7.3.3). Generate:
6957 -- <Base_Typ>Default_Init_Cond (<Base_Typ> (Def_Id));
6959 -- Note that the check is generated for source objects only
6961 if Comes_From_Source
(Def_Id
)
6962 and then (Has_Default_Init_Cond
(Typ
)
6964 Has_Inherited_Default_Init_Cond
(Typ
))
6965 and then not Has_Init_Expression
(N
)
6968 DIC_Call
: constant Node_Id
:=
6969 Build_Default_Init_Cond_Call
(Loc
, Def_Id
, Typ
);
6971 if Present
(Next_N
) then
6972 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
6974 -- The object declaration is the last node in a declarative or a
6978 Append_To
(List_Containing
(N
), DIC_Call
);
6984 -- Final transformation - turn the object declaration into a renaming
6985 -- if appropriate. If this is the completion of a deferred constant
6986 -- declaration, then this transformation generates what would be
6987 -- illegal code if written by hand, but that's OK.
6989 if Present
(Expr
) then
6990 if Rewrite_As_Renaming
then
6992 Make_Object_Renaming_Declaration
(Loc
,
6993 Defining_Identifier
=> Defining_Identifier
(N
),
6994 Subtype_Mark
=> Obj_Def
,
6997 -- We do not analyze this renaming declaration, because all its
6998 -- components have already been analyzed, and if we were to go
6999 -- ahead and analyze it, we would in effect be trying to generate
7000 -- another declaration of X, which won't do.
7002 Set_Renamed_Object
(Defining_Identifier
(N
), Expr_Q
);
7005 -- We do need to deal with debug issues for this renaming
7007 -- First, if entity comes from source, then mark it as needing
7008 -- debug information, even though it is defined by a generated
7009 -- renaming that does not come from source.
7011 if Comes_From_Source
(Defining_Identifier
(N
)) then
7012 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
7015 -- Now call the routine to generate debug info for the renaming
7018 Decl
: constant Node_Id
:= Debug_Renaming_Declaration
(N
);
7020 if Present
(Decl
) then
7021 Insert_Action
(N
, Decl
);
7027 -- Exception on library entity not available
7030 when RE_Not_Available
=>
7032 end Expand_N_Object_Declaration
;
7034 ---------------------------------
7035 -- Expand_N_Subtype_Indication --
7036 ---------------------------------
7038 -- Add a check on the range of the subtype. The static case is partially
7039 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
7040 -- to check here for the static case in order to avoid generating
7041 -- extraneous expanded code. Also deal with validity checking.
7043 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
7044 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
7045 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
7048 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
7049 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
7052 if Nkind_In
(Parent
(N
), N_Constrained_Array_Definition
, N_Slice
) then
7053 Apply_Range_Check
(Ran
, Typ
);
7055 end Expand_N_Subtype_Indication
;
7057 ---------------------------
7058 -- Expand_N_Variant_Part --
7059 ---------------------------
7061 -- Note: this procedure no longer has any effect. It used to be that we
7062 -- would replace the choices in the last variant by a when others, and
7063 -- also expanded static predicates in variant choices here, but both of
7064 -- those activities were being done too early, since we can't check the
7065 -- choices until the statically predicated subtypes are frozen, which can
7066 -- happen as late as the free point of the record, and we can't change the
7067 -- last choice to an others before checking the choices, which is now done
7068 -- at the freeze point of the record.
7070 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
7073 end Expand_N_Variant_Part
;
7075 ---------------------------------
7076 -- Expand_Previous_Access_Type --
7077 ---------------------------------
7079 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
7080 Ptr_Typ
: Entity_Id
;
7083 -- Find all access types in the current scope whose designated type is
7084 -- Def_Id and build master renamings for them.
7086 Ptr_Typ
:= First_Entity
(Current_Scope
);
7087 while Present
(Ptr_Typ
) loop
7088 if Is_Access_Type
(Ptr_Typ
)
7089 and then Designated_Type
(Ptr_Typ
) = Def_Id
7090 and then No
(Master_Id
(Ptr_Typ
))
7092 -- Ensure that the designated type has a master
7094 Build_Master_Entity
(Def_Id
);
7096 -- Private and incomplete types complicate the insertion of master
7097 -- renamings because the access type may precede the full view of
7098 -- the designated type. For this reason, the master renamings are
7099 -- inserted relative to the designated type.
7101 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
7104 Next_Entity
(Ptr_Typ
);
7106 end Expand_Previous_Access_Type
;
7108 -----------------------------
7109 -- Expand_Record_Extension --
7110 -----------------------------
7112 -- Add a field _parent at the beginning of the record extension. This is
7113 -- used to implement inheritance. Here are some examples of expansion:
7115 -- 1. no discriminants
7116 -- type T2 is new T1 with null record;
7118 -- type T2 is new T1 with record
7122 -- 2. renamed discriminants
7123 -- type T2 (B, C : Int) is new T1 (A => B) with record
7124 -- _Parent : T1 (A => B);
7128 -- 3. inherited discriminants
7129 -- type T2 is new T1 with record -- discriminant A inherited
7130 -- _Parent : T1 (A);
7134 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
) is
7135 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7136 Loc
: constant Source_Ptr
:= Sloc
(Def
);
7137 Rec_Ext_Part
: Node_Id
:= Record_Extension_Part
(Def
);
7138 Par_Subtype
: Entity_Id
;
7139 Comp_List
: Node_Id
;
7140 Comp_Decl
: Node_Id
;
7143 List_Constr
: constant List_Id
:= New_List
;
7146 -- Expand_Record_Extension is called directly from the semantics, so
7147 -- we must check to see whether expansion is active before proceeding,
7148 -- because this affects the visibility of selected components in bodies
7151 if not Expander_Active
then
7155 -- This may be a derivation of an untagged private type whose full
7156 -- view is tagged, in which case the Derived_Type_Definition has no
7157 -- extension part. Build an empty one now.
7159 if No
(Rec_Ext_Part
) then
7161 Make_Record_Definition
(Loc
,
7163 Component_List
=> Empty
,
7164 Null_Present
=> True);
7166 Set_Record_Extension_Part
(Def
, Rec_Ext_Part
);
7167 Mark_Rewrite_Insertion
(Rec_Ext_Part
);
7170 Comp_List
:= Component_List
(Rec_Ext_Part
);
7172 Parent_N
:= Make_Defining_Identifier
(Loc
, Name_uParent
);
7174 -- If the derived type inherits its discriminants the type of the
7175 -- _parent field must be constrained by the inherited discriminants
7177 if Has_Discriminants
(T
)
7178 and then Nkind
(Indic
) /= N_Subtype_Indication
7179 and then not Is_Constrained
(Entity
(Indic
))
7181 D
:= First_Discriminant
(T
);
7182 while Present
(D
) loop
7183 Append_To
(List_Constr
, New_Occurrence_Of
(D
, Loc
));
7184 Next_Discriminant
(D
);
7189 Make_Subtype_Indication
(Loc
,
7190 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Indic
), Loc
),
7192 Make_Index_Or_Discriminant_Constraint
(Loc
,
7193 Constraints
=> List_Constr
)),
7196 -- Otherwise the original subtype_indication is just what is needed
7199 Par_Subtype
:= Process_Subtype
(New_Copy_Tree
(Indic
), Def
);
7202 Set_Parent_Subtype
(T
, Par_Subtype
);
7205 Make_Component_Declaration
(Loc
,
7206 Defining_Identifier
=> Parent_N
,
7207 Component_Definition
=>
7208 Make_Component_Definition
(Loc
,
7209 Aliased_Present
=> False,
7210 Subtype_Indication
=> New_Occurrence_Of
(Par_Subtype
, Loc
)));
7212 if Null_Present
(Rec_Ext_Part
) then
7213 Set_Component_List
(Rec_Ext_Part
,
7214 Make_Component_List
(Loc
,
7215 Component_Items
=> New_List
(Comp_Decl
),
7216 Variant_Part
=> Empty
,
7217 Null_Present
=> False));
7218 Set_Null_Present
(Rec_Ext_Part
, False);
7220 elsif Null_Present
(Comp_List
)
7221 or else Is_Empty_List
(Component_Items
(Comp_List
))
7223 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
7224 Set_Null_Present
(Comp_List
, False);
7227 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
7230 Analyze
(Comp_Decl
);
7231 end Expand_Record_Extension
;
7233 ------------------------
7234 -- Expand_Tagged_Root --
7235 ------------------------
7237 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
7238 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
7239 Comp_List
: Node_Id
;
7240 Comp_Decl
: Node_Id
;
7241 Sloc_N
: Source_Ptr
;
7244 if Null_Present
(Def
) then
7245 Set_Component_List
(Def
,
7246 Make_Component_List
(Sloc
(Def
),
7247 Component_Items
=> Empty_List
,
7248 Variant_Part
=> Empty
,
7249 Null_Present
=> True));
7252 Comp_List
:= Component_List
(Def
);
7254 if Null_Present
(Comp_List
)
7255 or else Is_Empty_List
(Component_Items
(Comp_List
))
7257 Sloc_N
:= Sloc
(Comp_List
);
7259 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
7263 Make_Component_Declaration
(Sloc_N
,
7264 Defining_Identifier
=> First_Tag_Component
(T
),
7265 Component_Definition
=>
7266 Make_Component_Definition
(Sloc_N
,
7267 Aliased_Present
=> False,
7268 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
7270 if Null_Present
(Comp_List
)
7271 or else Is_Empty_List
(Component_Items
(Comp_List
))
7273 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
7274 Set_Null_Present
(Comp_List
, False);
7277 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
7280 -- We don't Analyze the whole expansion because the tag component has
7281 -- already been analyzed previously. Here we just insure that the tree
7282 -- is coherent with the semantic decoration
7284 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
7287 when RE_Not_Available
=>
7289 end Expand_Tagged_Root
;
7291 ------------------------------
7292 -- Freeze_Stream_Operations --
7293 ------------------------------
7295 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
7296 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
7301 Stream_Op
: Entity_Id
;
7304 -- Primitive operations of tagged types are frozen when the dispatch
7305 -- table is constructed.
7307 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
7311 for J
in Names
'Range loop
7312 Stream_Op
:= TSS
(Typ
, Names
(J
));
7314 if Present
(Stream_Op
)
7315 and then Is_Subprogram
(Stream_Op
)
7316 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
7317 N_Subprogram_Declaration
7318 and then not Is_Frozen
(Stream_Op
)
7320 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
7323 end Freeze_Stream_Operations
;
7329 -- Full type declarations are expanded at the point at which the type is
7330 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
7331 -- declarations generated by the freezing (e.g. the procedure generated
7332 -- for initialization) are chained in the Actions field list of the freeze
7333 -- node using Append_Freeze_Actions.
7335 function Freeze_Type
(N
: Node_Id
) return Boolean is
7336 procedure Process_RACW_Types
(Typ
: Entity_Id
);
7337 -- Validate and generate stubs for all RACW types associated with type
7340 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
);
7341 -- Associate type Typ's Finalize_Address primitive with the finalization
7342 -- masters of pending access-to-Typ types.
7344 ------------------------
7345 -- Process_RACW_Types --
7346 ------------------------
7348 procedure Process_RACW_Types
(Typ
: Entity_Id
) is
7349 List
: constant Elist_Id
:= Access_Types_To_Process
(N
);
7351 Seen
: Boolean := False;
7354 if Present
(List
) then
7355 E
:= First_Elmt
(List
);
7356 while Present
(E
) loop
7357 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
7358 Validate_RACW_Primitives
(Node
(E
));
7366 -- If there are RACWs designating this type, make stubs now
7369 Remote_Types_Tagged_Full_View_Encountered
(Typ
);
7371 end Process_RACW_Types
;
7373 ----------------------------------
7374 -- Process_Pending_Access_Types --
7375 ----------------------------------
7377 procedure Process_Pending_Access_Types
(Typ
: Entity_Id
) is
7381 -- Finalize_Address is not generated in CodePeer mode because the
7382 -- body contains address arithmetic. This processing is disabled.
7384 if CodePeer_Mode
then
7387 -- Certain itypes are generated for contexts that cannot allocate
7388 -- objects and should not set primitive Finalize_Address.
7390 elsif Is_Itype
(Typ
)
7391 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
7392 N_Explicit_Dereference
7396 -- When an access type is declared after the incomplete view of a
7397 -- Taft-amendment type, the access type is considered pending in
7398 -- case the full view of the Taft-amendment type is controlled. If
7399 -- this is indeed the case, associate the Finalize_Address routine
7400 -- of the full view with the finalization masters of all pending
7401 -- access types. This scenario applies to anonymous access types as
7404 elsif Needs_Finalization
(Typ
)
7405 and then Present
(Pending_Access_Types
(Typ
))
7407 E
:= First_Elmt
(Pending_Access_Types
(Typ
));
7408 while Present
(E
) loop
7411 -- Set_Finalize_Address
7412 -- (Ptr_Typ, <Typ>FD'Unrestricted_Access);
7414 Append_Freeze_Action
(Typ
,
7415 Make_Set_Finalize_Address_Call
7417 Ptr_Typ
=> Node
(E
)));
7422 end Process_Pending_Access_Types
;
7426 Def_Id
: constant Entity_Id
:= Entity
(N
);
7427 Result
: Boolean := False;
7429 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
7431 -- Start of processing for Freeze_Type
7434 -- The type being frozen may be subject to pragma Ghost. Set the mode
7435 -- now to ensure that any nodes generated during freezing are properly
7438 Set_Ghost_Mode
(N
, Def_Id
);
7440 -- Process any remote access-to-class-wide types designating the type
7443 Process_RACW_Types
(Def_Id
);
7445 -- Freeze processing for record types
7447 if Is_Record_Type
(Def_Id
) then
7448 if Ekind
(Def_Id
) = E_Record_Type
then
7449 Expand_Freeze_Record_Type
(N
);
7450 elsif Is_Class_Wide_Type
(Def_Id
) then
7451 Expand_Freeze_Class_Wide_Type
(N
);
7454 -- Freeze processing for array types
7456 elsif Is_Array_Type
(Def_Id
) then
7457 Expand_Freeze_Array_Type
(N
);
7459 -- Freeze processing for access types
7461 -- For pool-specific access types, find out the pool object used for
7462 -- this type, needs actual expansion of it in some cases. Here are the
7463 -- different cases :
7465 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
7466 -- ---> don't use any storage pool
7468 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
7470 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
7472 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7473 -- ---> Storage Pool is the specified one
7475 -- See GNAT Pool packages in the Run-Time for more details
7477 elsif Ekind_In
(Def_Id
, E_Access_Type
, E_General_Access_Type
) then
7479 Loc
: constant Source_Ptr
:= Sloc
(N
);
7480 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
7481 Pool_Object
: Entity_Id
;
7483 Freeze_Action_Typ
: Entity_Id
;
7488 -- Rep Clause "for Def_Id'Storage_Size use 0;"
7489 -- ---> don't use any storage pool
7491 if No_Pool_Assigned
(Def_Id
) then
7496 -- Rep Clause : for Def_Id'Storage_Size use Expr.
7498 -- Def_Id__Pool : Stack_Bounded_Pool
7499 -- (Expr, DT'Size, DT'Alignment);
7501 elsif Has_Storage_Size_Clause
(Def_Id
) then
7507 -- For unconstrained composite types we give a size of zero
7508 -- so that the pool knows that it needs a special algorithm
7509 -- for variable size object allocation.
7511 if Is_Composite_Type
(Desig_Type
)
7512 and then not Is_Constrained
(Desig_Type
)
7514 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
7515 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
7519 Make_Attribute_Reference
(Loc
,
7520 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7521 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
7524 Make_Attribute_Reference
(Loc
,
7525 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7526 Attribute_Name
=> Name_Alignment
);
7530 Make_Defining_Identifier
(Loc
,
7531 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
7533 -- We put the code associated with the pools in the entity
7534 -- that has the later freeze node, usually the access type
7535 -- but it can also be the designated_type; because the pool
7536 -- code requires both those types to be frozen
7538 if Is_Frozen
(Desig_Type
)
7539 and then (No
(Freeze_Node
(Desig_Type
))
7540 or else Analyzed
(Freeze_Node
(Desig_Type
)))
7542 Freeze_Action_Typ
:= Def_Id
;
7544 -- A Taft amendment type cannot get the freeze actions
7545 -- since the full view is not there.
7547 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
7548 and then No
(Full_View
(Desig_Type
))
7550 Freeze_Action_Typ
:= Def_Id
;
7553 Freeze_Action_Typ
:= Desig_Type
;
7556 Append_Freeze_Action
(Freeze_Action_Typ
,
7557 Make_Object_Declaration
(Loc
,
7558 Defining_Identifier
=> Pool_Object
,
7559 Object_Definition
=>
7560 Make_Subtype_Indication
(Loc
,
7563 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
7566 Make_Index_Or_Discriminant_Constraint
(Loc
,
7567 Constraints
=> New_List
(
7569 -- First discriminant is the Pool Size
7572 Storage_Size_Variable
(Def_Id
), Loc
),
7574 -- Second discriminant is the element size
7578 -- Third discriminant is the alignment
7583 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
7587 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7588 -- ---> Storage Pool is the specified one
7590 -- When compiling in Ada 2012 mode, ensure that the accessibility
7591 -- level of the subpool access type is not deeper than that of the
7592 -- pool_with_subpools.
7594 elsif Ada_Version
>= Ada_2012
7595 and then Present
(Associated_Storage_Pool
(Def_Id
))
7597 -- Omit this check for the case of a configurable run-time that
7598 -- does not provide package System.Storage_Pools.Subpools.
7600 and then RTE_Available
(RE_Root_Storage_Pool_With_Subpools
)
7603 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7604 Pool
: constant Entity_Id
:=
7605 Associated_Storage_Pool
(Def_Id
);
7606 RSPWS
: constant Entity_Id
:=
7607 RTE
(RE_Root_Storage_Pool_With_Subpools
);
7610 -- It is known that the accessibility level of the access
7611 -- type is deeper than that of the pool.
7613 if Type_Access_Level
(Def_Id
) > Object_Access_Level
(Pool
)
7614 and then not Accessibility_Checks_Suppressed
(Def_Id
)
7615 and then not Accessibility_Checks_Suppressed
(Pool
)
7617 -- Static case: the pool is known to be a descendant of
7618 -- Root_Storage_Pool_With_Subpools.
7620 if Is_Ancestor
(RSPWS
, Etype
(Pool
)) then
7622 ("??subpool access type has deeper accessibility "
7623 & "level than pool", Def_Id
);
7625 Append_Freeze_Action
(Def_Id
,
7626 Make_Raise_Program_Error
(Loc
,
7627 Reason
=> PE_Accessibility_Check_Failed
));
7629 -- Dynamic case: when the pool is of a class-wide type,
7630 -- it may or may not support subpools depending on the
7631 -- path of derivation. Generate:
7633 -- if Def_Id in RSPWS'Class then
7634 -- raise Program_Error;
7637 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
7638 Append_Freeze_Action
(Def_Id
,
7639 Make_If_Statement
(Loc
,
7642 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
7645 (Class_Wide_Type
(RSPWS
), Loc
)),
7647 Then_Statements
=> New_List
(
7648 Make_Raise_Program_Error
(Loc
,
7649 Reason
=> PE_Accessibility_Check_Failed
))));
7655 -- For access-to-controlled types (including class-wide types and
7656 -- Taft-amendment types, which potentially have controlled
7657 -- components), expand the list controller object that will store
7658 -- the dynamically allocated objects. Don't do this transformation
7659 -- for expander-generated access types, but do it for types that
7660 -- are the full view of types derived from other private types.
7661 -- Also suppress the list controller in the case of a designated
7662 -- type with convention Java, since this is used when binding to
7663 -- Java API specs, where there's no equivalent of a finalization
7664 -- list and we don't want to pull in the finalization support if
7667 if not Comes_From_Source
(Def_Id
)
7668 and then not Has_Private_Declaration
(Def_Id
)
7672 -- An exception is made for types defined in the run-time because
7673 -- Ada.Tags.Tag itself is such a type and cannot afford this
7674 -- unnecessary overhead that would generates a loop in the
7675 -- expansion scheme. Another exception is if Restrictions
7676 -- (No_Finalization) is active, since then we know nothing is
7679 elsif Restriction_Active
(No_Finalization
)
7680 or else In_Runtime
(Def_Id
)
7684 -- Create a finalization master for an access-to-controlled type
7685 -- or an access-to-incomplete type. It is assumed that the full
7686 -- view will be controlled.
7688 elsif Needs_Finalization
(Desig_Type
)
7689 or else (Is_Incomplete_Type
(Desig_Type
)
7690 and then No
(Full_View
(Desig_Type
)))
7692 Build_Finalization_Master
(Def_Id
);
7694 -- Create a finalization master when the designated type contains
7695 -- a private component. It is assumed that the full view will be
7698 elsif Has_Private_Component
(Desig_Type
) then
7699 Build_Finalization_Master
7701 For_Private
=> True,
7702 Context_Scope
=> Scope
(Def_Id
),
7703 Insertion_Node
=> Declaration_Node
(Desig_Type
));
7707 -- Freeze processing for enumeration types
7709 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
7711 -- We only have something to do if we have a non-standard
7712 -- representation (i.e. at least one literal whose pos value
7713 -- is not the same as its representation)
7715 if Has_Non_Standard_Rep
(Def_Id
) then
7716 Expand_Freeze_Enumeration_Type
(N
);
7719 -- Private types that are completed by a derivation from a private
7720 -- type have an internally generated full view, that needs to be
7721 -- frozen. This must be done explicitly because the two views share
7722 -- the freeze node, and the underlying full view is not visible when
7723 -- the freeze node is analyzed.
7725 elsif Is_Private_Type
(Def_Id
)
7726 and then Is_Derived_Type
(Def_Id
)
7727 and then Present
(Full_View
(Def_Id
))
7728 and then Is_Itype
(Full_View
(Def_Id
))
7729 and then Has_Private_Declaration
(Full_View
(Def_Id
))
7730 and then Freeze_Node
(Full_View
(Def_Id
)) = N
7732 Set_Entity
(N
, Full_View
(Def_Id
));
7733 Result
:= Freeze_Type
(N
);
7734 Set_Entity
(N
, Def_Id
);
7736 -- All other types require no expander action. There are such cases
7737 -- (e.g. task types and protected types). In such cases, the freeze
7738 -- nodes are there for use by Gigi.
7742 -- Complete the initialization of all pending access types' finalization
7743 -- masters now that the designated type has been is frozen and primitive
7744 -- Finalize_Address generated.
7746 Process_Pending_Access_Types
(Def_Id
);
7747 Freeze_Stream_Operations
(N
, Def_Id
);
7749 Ghost_Mode
:= Save_Ghost_Mode
;
7753 when RE_Not_Available
=>
7754 Ghost_Mode
:= Save_Ghost_Mode
;
7758 -------------------------
7759 -- Get_Simple_Init_Val --
7760 -------------------------
7762 function Get_Simple_Init_Val
7765 Size
: Uint
:= No_Uint
) return Node_Id
7767 Loc
: constant Source_Ptr
:= Sloc
(N
);
7773 -- This is the size to be used for computation of the appropriate
7774 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
7776 IV_Attribute
: constant Boolean :=
7777 Nkind
(N
) = N_Attribute_Reference
7778 and then Attribute_Name
(N
) = Name_Invalid_Value
;
7782 -- These are the values computed by the procedure Check_Subtype_Bounds
7784 procedure Check_Subtype_Bounds
;
7785 -- This procedure examines the subtype T, and its ancestor subtypes and
7786 -- derived types to determine the best known information about the
7787 -- bounds of the subtype. After the call Lo_Bound is set either to
7788 -- No_Uint if no information can be determined, or to a value which
7789 -- represents a known low bound, i.e. a valid value of the subtype can
7790 -- not be less than this value. Hi_Bound is similarly set to a known
7791 -- high bound (valid value cannot be greater than this).
7793 --------------------------
7794 -- Check_Subtype_Bounds --
7795 --------------------------
7797 procedure Check_Subtype_Bounds
is
7806 Lo_Bound
:= No_Uint
;
7807 Hi_Bound
:= No_Uint
;
7809 -- Loop to climb ancestor subtypes and derived types
7813 if not Is_Discrete_Type
(ST1
) then
7817 Lo
:= Type_Low_Bound
(ST1
);
7818 Hi
:= Type_High_Bound
(ST1
);
7820 if Compile_Time_Known_Value
(Lo
) then
7821 Loval
:= Expr_Value
(Lo
);
7823 if Lo_Bound
= No_Uint
or else Lo_Bound
< Loval
then
7828 if Compile_Time_Known_Value
(Hi
) then
7829 Hival
:= Expr_Value
(Hi
);
7831 if Hi_Bound
= No_Uint
or else Hi_Bound
> Hival
then
7836 ST2
:= Ancestor_Subtype
(ST1
);
7842 exit when ST1
= ST2
;
7845 end Check_Subtype_Bounds
;
7847 -- Start of processing for Get_Simple_Init_Val
7850 -- For a private type, we should always have an underlying type (because
7851 -- this was already checked in Needs_Simple_Initialization). What we do
7852 -- is to get the value for the underlying type and then do an unchecked
7853 -- conversion to the private type.
7855 if Is_Private_Type
(T
) then
7856 Val
:= Get_Simple_Init_Val
(Underlying_Type
(T
), N
, Size
);
7858 -- A special case, if the underlying value is null, then qualify it
7859 -- with the underlying type, so that the null is properly typed.
7860 -- Similarly, if it is an aggregate it must be qualified, because an
7861 -- unchecked conversion does not provide a context for it.
7863 if Nkind_In
(Val
, N_Null
, N_Aggregate
) then
7865 Make_Qualified_Expression
(Loc
,
7867 New_Occurrence_Of
(Underlying_Type
(T
), Loc
),
7871 Result
:= Unchecked_Convert_To
(T
, Val
);
7873 -- Don't truncate result (important for Initialize/Normalize_Scalars)
7875 if Nkind
(Result
) = N_Unchecked_Type_Conversion
7876 and then Is_Scalar_Type
(Underlying_Type
(T
))
7878 Set_No_Truncation
(Result
);
7883 -- Scalars with Default_Value aspect. The first subtype may now be
7884 -- private, so retrieve value from underlying type.
7886 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
7887 if Is_Private_Type
(First_Subtype
(T
)) then
7888 return Unchecked_Convert_To
(T
,
7889 Default_Aspect_Value
(Full_View
(First_Subtype
(T
))));
7892 Convert_To
(T
, Default_Aspect_Value
(First_Subtype
(T
)));
7895 -- Otherwise, for scalars, we must have normalize/initialize scalars
7896 -- case, or if the node N is an 'Invalid_Value attribute node.
7898 elsif Is_Scalar_Type
(T
) then
7899 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
7901 -- Compute size of object. If it is given by the caller, we can use
7902 -- it directly, otherwise we use Esize (T) as an estimate. As far as
7903 -- we know this covers all cases correctly.
7905 if Size
= No_Uint
or else Size
<= Uint_0
then
7906 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(T
));
7908 Size_To_Use
:= Size
;
7911 -- Maximum size to use is 64 bits, since we will create values of
7912 -- type Unsigned_64 and the range must fit this type.
7914 if Size_To_Use
/= No_Uint
and then Size_To_Use
> Uint_64
then
7915 Size_To_Use
:= Uint_64
;
7918 -- Check known bounds of subtype
7920 Check_Subtype_Bounds
;
7922 -- Processing for Normalize_Scalars case
7924 if Normalize_Scalars
and then not IV_Attribute
then
7926 -- If zero is invalid, it is a convenient value to use that is
7927 -- for sure an appropriate invalid value in all situations.
7929 if Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
7930 Val
:= Make_Integer_Literal
(Loc
, 0);
7932 -- Cases where all one bits is the appropriate invalid value
7934 -- For modular types, all 1 bits is either invalid or valid. If
7935 -- it is valid, then there is nothing that can be done since there
7936 -- are no invalid values (we ruled out zero already).
7938 -- For signed integer types that have no negative values, either
7939 -- there is room for negative values, or there is not. If there
7940 -- is, then all 1-bits may be interpreted as minus one, which is
7941 -- certainly invalid. Alternatively it is treated as the largest
7942 -- positive value, in which case the observation for modular types
7945 -- For float types, all 1-bits is a NaN (not a number), which is
7946 -- certainly an appropriately invalid value.
7948 elsif Is_Unsigned_Type
(T
)
7949 or else Is_Floating_Point_Type
(T
)
7950 or else Is_Enumeration_Type
(T
)
7952 Val
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
7954 -- Resolve as Unsigned_64, because the largest number we can
7955 -- generate is out of range of universal integer.
7957 Analyze_And_Resolve
(Val
, RTE
(RE_Unsigned_64
));
7959 -- Case of signed types
7963 Signed_Size
: constant Uint
:=
7964 UI_Min
(Uint_63
, Size_To_Use
- 1);
7967 -- Normally we like to use the most negative number. The one
7968 -- exception is when this number is in the known subtype
7969 -- range and the largest positive number is not in the known
7972 -- For this exceptional case, use largest positive value
7974 if Lo_Bound
/= No_Uint
and then Hi_Bound
/= No_Uint
7975 and then Lo_Bound
<= (-(2 ** Signed_Size
))
7976 and then Hi_Bound
< 2 ** Signed_Size
7978 Val
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
7980 -- Normal case of largest negative value
7983 Val
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
7988 -- Here for Initialize_Scalars case (or Invalid_Value attribute used)
7991 -- For float types, use float values from System.Scalar_Values
7993 if Is_Floating_Point_Type
(T
) then
7994 if Root_Type
(T
) = Standard_Short_Float
then
7995 Val_RE
:= RE_IS_Isf
;
7996 elsif Root_Type
(T
) = Standard_Float
then
7997 Val_RE
:= RE_IS_Ifl
;
7998 elsif Root_Type
(T
) = Standard_Long_Float
then
7999 Val_RE
:= RE_IS_Ilf
;
8000 else pragma Assert
(Root_Type
(T
) = Standard_Long_Long_Float
);
8001 Val_RE
:= RE_IS_Ill
;
8004 -- If zero is invalid, use zero values from System.Scalar_Values
8006 elsif Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
8007 if Size_To_Use
<= 8 then
8008 Val_RE
:= RE_IS_Iz1
;
8009 elsif Size_To_Use
<= 16 then
8010 Val_RE
:= RE_IS_Iz2
;
8011 elsif Size_To_Use
<= 32 then
8012 Val_RE
:= RE_IS_Iz4
;
8014 Val_RE
:= RE_IS_Iz8
;
8017 -- For unsigned, use unsigned values from System.Scalar_Values
8019 elsif Is_Unsigned_Type
(T
) then
8020 if Size_To_Use
<= 8 then
8021 Val_RE
:= RE_IS_Iu1
;
8022 elsif Size_To_Use
<= 16 then
8023 Val_RE
:= RE_IS_Iu2
;
8024 elsif Size_To_Use
<= 32 then
8025 Val_RE
:= RE_IS_Iu4
;
8027 Val_RE
:= RE_IS_Iu8
;
8030 -- For signed, use signed values from System.Scalar_Values
8033 if Size_To_Use
<= 8 then
8034 Val_RE
:= RE_IS_Is1
;
8035 elsif Size_To_Use
<= 16 then
8036 Val_RE
:= RE_IS_Is2
;
8037 elsif Size_To_Use
<= 32 then
8038 Val_RE
:= RE_IS_Is4
;
8040 Val_RE
:= RE_IS_Is8
;
8044 Val
:= New_Occurrence_Of
(RTE
(Val_RE
), Loc
);
8047 -- The final expression is obtained by doing an unchecked conversion
8048 -- of this result to the base type of the required subtype. Use the
8049 -- base type to prevent the unchecked conversion from chopping bits,
8050 -- and then we set Kill_Range_Check to preserve the "bad" value.
8052 Result
:= Unchecked_Convert_To
(Base_Type
(T
), Val
);
8054 -- Ensure result is not truncated, since we want the "bad" bits, and
8055 -- also kill range check on result.
8057 if Nkind
(Result
) = N_Unchecked_Type_Conversion
then
8058 Set_No_Truncation
(Result
);
8059 Set_Kill_Range_Check
(Result
, True);
8064 -- String or Wide_[Wide]_String (must have Initialize_Scalars set)
8066 elsif Is_Standard_String_Type
(T
) then
8067 pragma Assert
(Init_Or_Norm_Scalars
);
8070 Make_Aggregate
(Loc
,
8071 Component_Associations
=> New_List
(
8072 Make_Component_Association
(Loc
,
8073 Choices
=> New_List
(
8074 Make_Others_Choice
(Loc
)),
8077 (Component_Type
(T
), N
, Esize
(Root_Type
(T
))))));
8079 -- Access type is initialized to null
8081 elsif Is_Access_Type
(T
) then
8082 return Make_Null
(Loc
);
8084 -- No other possibilities should arise, since we should only be calling
8085 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8086 -- indicating one of the above cases held.
8089 raise Program_Error
;
8093 when RE_Not_Available
=>
8095 end Get_Simple_Init_Val
;
8097 ------------------------------
8098 -- Has_New_Non_Standard_Rep --
8099 ------------------------------
8101 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
8103 if not Is_Derived_Type
(T
) then
8104 return Has_Non_Standard_Rep
(T
)
8105 or else Has_Non_Standard_Rep
(Root_Type
(T
));
8107 -- If Has_Non_Standard_Rep is not set on the derived type, the
8108 -- representation is fully inherited.
8110 elsif not Has_Non_Standard_Rep
(T
) then
8114 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
8116 -- May need a more precise check here: the First_Rep_Item may be a
8117 -- stream attribute, which does not affect the representation of the
8121 end Has_New_Non_Standard_Rep
;
8123 ----------------------
8124 -- Inline_Init_Proc --
8125 ----------------------
8127 function Inline_Init_Proc
(Typ
: Entity_Id
) return Boolean is
8129 -- The initialization proc of protected records is not worth inlining.
8130 -- In addition, when compiled for another unit for inlining purposes,
8131 -- it may make reference to entities that have not been elaborated yet.
8132 -- The initialization proc of records that need finalization contains
8133 -- a nested clean-up procedure that makes it impractical to inline as
8134 -- well, except for simple controlled types themselves. And similar
8135 -- considerations apply to task types.
8137 if Is_Concurrent_Type
(Typ
) then
8140 elsif Needs_Finalization
(Typ
) and then not Is_Controlled
(Typ
) then
8143 elsif Has_Task
(Typ
) then
8149 end Inline_Init_Proc
;
8155 function In_Runtime
(E
: Entity_Id
) return Boolean is
8160 while Scope
(S1
) /= Standard_Standard
loop
8164 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
8167 ---------------------------------------
8168 -- Insert_Component_Invariant_Checks --
8169 ---------------------------------------
8171 procedure Insert_Component_Invariant_Checks
8176 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8177 Proc_Id
: Entity_Id
;
8180 if Present
(Proc
) then
8181 Proc_Id
:= Defining_Entity
(Proc
);
8183 if not Has_Invariants
(Typ
) then
8184 Set_Has_Invariants
(Typ
);
8185 Set_Is_Invariant_Procedure
(Proc_Id
);
8186 Set_Invariant_Procedure
(Typ
, Proc_Id
);
8187 Insert_After
(N
, Proc
);
8192 -- Find already created invariant subprogram, insert body of
8193 -- component invariant proc in its body, and add call after
8198 Inv_Id
: constant Entity_Id
:= Invariant_Procedure
(Typ
);
8199 Call
: constant Node_Id
:=
8200 Make_Procedure_Call_Statement
(Sloc
(N
),
8201 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
8202 Parameter_Associations
=>
8204 (New_Occurrence_Of
(First_Formal
(Inv_Id
), Loc
)));
8207 -- The invariant body has not been analyzed yet, so we do a
8208 -- sequential search forward, and retrieve it by name.
8211 while Present
(Bod
) loop
8212 exit when Nkind
(Bod
) = N_Subprogram_Body
8213 and then Chars
(Defining_Entity
(Bod
)) = Chars
(Inv_Id
);
8217 -- If the body is not found, it is the case of an invariant
8218 -- appearing on a full declaration in a private part, in
8219 -- which case the type has been frozen but the invariant
8220 -- procedure for the composite type not created yet. Create
8224 Build_Invariant_Procedure
(Typ
, Parent
(Current_Scope
));
8225 Bod
:= Unit_Declaration_Node
8226 (Corresponding_Body
(Unit_Declaration_Node
(Inv_Id
)));
8229 Append_To
(Declarations
(Bod
), Proc
);
8230 Append_To
(Statements
(Handled_Statement_Sequence
(Bod
)), Call
);
8236 end Insert_Component_Invariant_Checks
;
8238 ----------------------------
8239 -- Initialization_Warning --
8240 ----------------------------
8242 procedure Initialization_Warning
(E
: Entity_Id
) is
8243 Warning_Needed
: Boolean;
8246 Warning_Needed
:= False;
8248 if Ekind
(Current_Scope
) = E_Package
8249 and then Static_Elaboration_Desired
(Current_Scope
)
8252 if Is_Record_Type
(E
) then
8253 if Has_Discriminants
(E
)
8254 or else Is_Limited_Type
(E
)
8255 or else Has_Non_Standard_Rep
(E
)
8257 Warning_Needed
:= True;
8260 -- Verify that at least one component has an initialization
8261 -- expression. No need for a warning on a type if all its
8262 -- components have no initialization.
8268 Comp
:= First_Component
(E
);
8269 while Present
(Comp
) loop
8270 if Ekind
(Comp
) = E_Discriminant
8272 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
8273 and then Present
(Expression
(Parent
(Comp
))))
8275 Warning_Needed
:= True;
8279 Next_Component
(Comp
);
8284 if Warning_Needed
then
8286 ("Objects of the type cannot be initialized statically "
8287 & "by default??", Parent
(E
));
8292 Error_Msg_N
("Object cannot be initialized statically??", E
);
8295 end Initialization_Warning
;
8301 function Init_Formals
(Typ
: Entity_Id
) return List_Id
is
8302 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8306 -- First parameter is always _Init : in out typ. Note that we need this
8307 -- to be in/out because in the case of the task record value, there
8308 -- are default record fields (_Priority, _Size, -Task_Info) that may
8309 -- be referenced in the generated initialization routine.
8311 Formals
:= New_List
(
8312 Make_Parameter_Specification
(Loc
,
8313 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
8315 Out_Present
=> True,
8316 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8318 -- For task record value, or type that contains tasks, add two more
8319 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8320 -- We also add these parameters for the task record type case.
8323 or else (Is_Record_Type
(Typ
) and then Is_Task_Record_Type
(Typ
))
8326 Make_Parameter_Specification
(Loc
,
8327 Defining_Identifier
=>
8328 Make_Defining_Identifier
(Loc
, Name_uMaster
),
8330 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
)));
8332 -- Add _Chain (not done for sequential elaboration policy, see
8333 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
8335 if Partition_Elaboration_Policy
/= 'S' then
8337 Make_Parameter_Specification
(Loc
,
8338 Defining_Identifier
=>
8339 Make_Defining_Identifier
(Loc
, Name_uChain
),
8341 Out_Present
=> True,
8343 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
8347 Make_Parameter_Specification
(Loc
,
8348 Defining_Identifier
=>
8349 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
8351 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
8357 when RE_Not_Available
=>
8361 -------------------------
8362 -- Init_Secondary_Tags --
8363 -------------------------
8365 procedure Init_Secondary_Tags
8368 Stmts_List
: List_Id
;
8369 Fixed_Comps
: Boolean := True;
8370 Variable_Comps
: Boolean := True)
8372 Loc
: constant Source_Ptr
:= Sloc
(Target
);
8374 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
8375 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8377 procedure Initialize_Tag
8380 Tag_Comp
: Entity_Id
;
8381 Iface_Tag
: Node_Id
);
8382 -- Initialize the tag of the secondary dispatch table of Typ associated
8383 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8384 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
8385 -- of Typ CPP tagged type we generate code to inherit the contents of
8386 -- the dispatch table directly from the ancestor.
8388 --------------------
8389 -- Initialize_Tag --
8390 --------------------
8392 procedure Initialize_Tag
8395 Tag_Comp
: Entity_Id
;
8396 Iface_Tag
: Node_Id
)
8398 Comp_Typ
: Entity_Id
;
8399 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
8402 -- Initialize pointer to secondary DT associated with the interface
8404 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8405 Append_To
(Stmts_List
,
8406 Make_Assignment_Statement
(Loc
,
8408 Make_Selected_Component
(Loc
,
8409 Prefix
=> New_Copy_Tree
(Target
),
8410 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8412 New_Occurrence_Of
(Iface_Tag
, Loc
)));
8415 Comp_Typ
:= Scope
(Tag_Comp
);
8417 -- Initialize the entries of the table of interfaces. We generate a
8418 -- different call when the parent of the type has variable size
8421 if Comp_Typ
/= Etype
(Comp_Typ
)
8422 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
8423 and then Chars
(Tag_Comp
) /= Name_uTag
8425 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
8427 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
8428 -- configurable run-time environment.
8430 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
8432 ("variable size record with interface types", Typ
);
8437 -- Set_Dynamic_Offset_To_Top
8439 -- Interface_T => Iface'Tag,
8440 -- Offset_Value => n,
8441 -- Offset_Func => Fn'Address)
8443 Append_To
(Stmts_List
,
8444 Make_Procedure_Call_Statement
(Loc
,
8446 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
8447 Parameter_Associations
=> New_List
(
8448 Make_Attribute_Reference
(Loc
,
8449 Prefix
=> New_Copy_Tree
(Target
),
8450 Attribute_Name
=> Name_Address
),
8452 Unchecked_Convert_To
(RTE
(RE_Tag
),
8454 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
8457 Unchecked_Convert_To
8458 (RTE
(RE_Storage_Offset
),
8459 Make_Attribute_Reference
(Loc
,
8461 Make_Selected_Component
(Loc
,
8462 Prefix
=> New_Copy_Tree
(Target
),
8464 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8465 Attribute_Name
=> Name_Position
)),
8467 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
8468 Make_Attribute_Reference
(Loc
,
8469 Prefix
=> New_Occurrence_Of
8470 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
8471 Attribute_Name
=> Name_Address
)))));
8473 -- In this case the next component stores the value of the offset
8476 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
8477 pragma Assert
(Present
(Offset_To_Top_Comp
));
8479 Append_To
(Stmts_List
,
8480 Make_Assignment_Statement
(Loc
,
8482 Make_Selected_Component
(Loc
,
8483 Prefix
=> New_Copy_Tree
(Target
),
8485 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
8488 Make_Attribute_Reference
(Loc
,
8490 Make_Selected_Component
(Loc
,
8491 Prefix
=> New_Copy_Tree
(Target
),
8492 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8493 Attribute_Name
=> Name_Position
)));
8495 -- Normal case: No discriminants in the parent type
8498 -- Don't need to set any value if this interface shares the
8499 -- primary dispatch table.
8501 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8502 Append_To
(Stmts_List
,
8503 Build_Set_Static_Offset_To_Top
(Loc
,
8504 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
8506 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8507 Make_Attribute_Reference
(Loc
,
8509 Make_Selected_Component
(Loc
,
8510 Prefix
=> New_Copy_Tree
(Target
),
8512 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8513 Attribute_Name
=> Name_Position
))));
8517 -- Register_Interface_Offset
8519 -- Interface_T => Iface'Tag,
8520 -- Is_Constant => True,
8521 -- Offset_Value => n,
8522 -- Offset_Func => null);
8524 if RTE_Available
(RE_Register_Interface_Offset
) then
8525 Append_To
(Stmts_List
,
8526 Make_Procedure_Call_Statement
(Loc
,
8529 (RTE
(RE_Register_Interface_Offset
), Loc
),
8530 Parameter_Associations
=> New_List
(
8531 Make_Attribute_Reference
(Loc
,
8532 Prefix
=> New_Copy_Tree
(Target
),
8533 Attribute_Name
=> Name_Address
),
8535 Unchecked_Convert_To
(RTE
(RE_Tag
),
8537 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
8539 New_Occurrence_Of
(Standard_True
, Loc
),
8541 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8542 Make_Attribute_Reference
(Loc
,
8544 Make_Selected_Component
(Loc
,
8545 Prefix
=> New_Copy_Tree
(Target
),
8547 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8548 Attribute_Name
=> Name_Position
)),
8557 Full_Typ
: Entity_Id
;
8558 Ifaces_List
: Elist_Id
;
8559 Ifaces_Comp_List
: Elist_Id
;
8560 Ifaces_Tag_List
: Elist_Id
;
8561 Iface_Elmt
: Elmt_Id
;
8562 Iface_Comp_Elmt
: Elmt_Id
;
8563 Iface_Tag_Elmt
: Elmt_Id
;
8565 In_Variable_Pos
: Boolean;
8567 -- Start of processing for Init_Secondary_Tags
8570 -- Handle private types
8572 if Present
(Full_View
(Typ
)) then
8573 Full_Typ
:= Full_View
(Typ
);
8578 Collect_Interfaces_Info
8579 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
8581 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8582 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
8583 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
8584 while Present
(Iface_Elmt
) loop
8585 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
8587 -- Check if parent of record type has variable size components
8589 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
8590 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
8592 -- If we are compiling under the CPP full ABI compatibility mode and
8593 -- the ancestor is a CPP_Pragma tagged type then we generate code to
8594 -- initialize the secondary tag components from tags that reference
8595 -- secondary tables filled with copy of parent slots.
8597 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
8599 -- Reject interface components located at variable offset in
8600 -- C++ derivations. This is currently unsupported.
8602 if not Fixed_Comps
and then In_Variable_Pos
then
8604 -- Locate the first dynamic component of the record. Done to
8605 -- improve the text of the warning.
8609 Comp_Typ
: Entity_Id
;
8612 Comp
:= First_Entity
(Typ
);
8613 while Present
(Comp
) loop
8614 Comp_Typ
:= Etype
(Comp
);
8616 if Ekind
(Comp
) /= E_Discriminant
8617 and then not Is_Tag
(Comp
)
8620 (Is_Record_Type
(Comp_Typ
)
8622 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
8624 (Is_Array_Type
(Comp_Typ
)
8625 and then Is_Variable_Size_Array
(Comp_Typ
));
8631 pragma Assert
(Present
(Comp
));
8632 Error_Msg_Node_2
:= Comp
;
8634 ("parent type & with dynamic component & cannot be parent"
8635 & " of 'C'P'P derivation if new interfaces are present",
8636 Typ
, Scope
(Original_Record_Component
(Comp
)));
8639 Sloc
(Scope
(Original_Record_Component
(Comp
)));
8641 ("type derived from 'C'P'P type & defined #",
8642 Typ
, Scope
(Original_Record_Component
(Comp
)));
8644 -- Avoid duplicated warnings
8649 -- Initialize secondary tags
8652 Append_To
(Stmts_List
,
8653 Make_Assignment_Statement
(Loc
,
8655 Make_Selected_Component
(Loc
,
8656 Prefix
=> New_Copy_Tree
(Target
),
8658 New_Occurrence_Of
(Node
(Iface_Comp_Elmt
), Loc
)),
8660 New_Occurrence_Of
(Node
(Iface_Tag_Elmt
), Loc
)));
8663 -- Otherwise generate code to initialize the tag
8666 if (In_Variable_Pos
and then Variable_Comps
)
8667 or else (not In_Variable_Pos
and then Fixed_Comps
)
8669 Initialize_Tag
(Full_Typ
,
8670 Iface
=> Node
(Iface_Elmt
),
8671 Tag_Comp
=> Tag_Comp
,
8672 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
8676 Next_Elmt
(Iface_Elmt
);
8677 Next_Elmt
(Iface_Comp_Elmt
);
8678 Next_Elmt
(Iface_Tag_Elmt
);
8680 end Init_Secondary_Tags
;
8682 ------------------------
8683 -- Is_User_Defined_Eq --
8684 ------------------------
8686 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean is
8688 return Chars
(Prim
) = Name_Op_Eq
8689 and then Etype
(First_Formal
(Prim
)) =
8690 Etype
(Next_Formal
(First_Formal
(Prim
)))
8691 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
;
8692 end Is_User_Defined_Equality
;
8694 ----------------------------------------
8695 -- Make_Controlling_Function_Wrappers --
8696 ----------------------------------------
8698 procedure Make_Controlling_Function_Wrappers
8699 (Tag_Typ
: Entity_Id
;
8700 Decl_List
: out List_Id
;
8701 Body_List
: out List_Id
)
8703 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
8704 Prim_Elmt
: Elmt_Id
;
8706 Actual_List
: List_Id
;
8707 Formal_List
: List_Id
;
8709 Par_Formal
: Entity_Id
;
8710 Formal_Node
: Node_Id
;
8711 Func_Body
: Node_Id
;
8712 Func_Decl
: Node_Id
;
8713 Func_Spec
: Node_Id
;
8714 Return_Stmt
: Node_Id
;
8717 Decl_List
:= New_List
;
8718 Body_List
:= New_List
;
8720 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
8721 while Present
(Prim_Elmt
) loop
8722 Subp
:= Node
(Prim_Elmt
);
8724 -- If a primitive function with a controlling result of the type has
8725 -- not been overridden by the user, then we must create a wrapper
8726 -- function here that effectively overrides it and invokes the
8727 -- (non-abstract) parent function. This can only occur for a null
8728 -- extension. Note that functions with anonymous controlling access
8729 -- results don't qualify and must be overridden. We also exclude
8730 -- Input attributes, since each type will have its own version of
8731 -- Input constructed by the expander. The test for Comes_From_Source
8732 -- is needed to distinguish inherited operations from renamings
8733 -- (which also have Alias set). We exclude internal entities with
8734 -- Interface_Alias to avoid generating duplicated wrappers since
8735 -- the primitive which covers the interface is also available in
8736 -- the list of primitive operations.
8738 -- The function may be abstract, or require_Overriding may be set
8739 -- for it, because tests for null extensions may already have reset
8740 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
8741 -- set, functions that need wrappers are recognized by having an
8742 -- alias that returns the parent type.
8744 if Comes_From_Source
(Subp
)
8745 or else No
(Alias
(Subp
))
8746 or else Present
(Interface_Alias
(Subp
))
8747 or else Ekind
(Subp
) /= E_Function
8748 or else not Has_Controlling_Result
(Subp
)
8749 or else Is_Access_Type
(Etype
(Subp
))
8750 or else Is_Abstract_Subprogram
(Alias
(Subp
))
8751 or else Is_TSS
(Subp
, TSS_Stream_Input
)
8755 elsif Is_Abstract_Subprogram
(Subp
)
8756 or else Requires_Overriding
(Subp
)
8758 (Is_Null_Extension
(Etype
(Subp
))
8759 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
8761 Formal_List
:= No_List
;
8762 Formal
:= First_Formal
(Subp
);
8764 if Present
(Formal
) then
8765 Formal_List
:= New_List
;
8767 while Present
(Formal
) loop
8769 (Make_Parameter_Specification
8771 Defining_Identifier
=>
8772 Make_Defining_Identifier
(Sloc
(Formal
),
8773 Chars
=> Chars
(Formal
)),
8774 In_Present
=> In_Present
(Parent
(Formal
)),
8775 Out_Present
=> Out_Present
(Parent
(Formal
)),
8776 Null_Exclusion_Present
=>
8777 Null_Exclusion_Present
(Parent
(Formal
)),
8779 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8781 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
8784 Next_Formal
(Formal
);
8789 Make_Function_Specification
(Loc
,
8790 Defining_Unit_Name
=>
8791 Make_Defining_Identifier
(Loc
,
8792 Chars
=> Chars
(Subp
)),
8793 Parameter_Specifications
=> Formal_List
,
8794 Result_Definition
=>
8795 New_Occurrence_Of
(Etype
(Subp
), Loc
));
8797 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Func_Spec
);
8798 Append_To
(Decl_List
, Func_Decl
);
8800 -- Build a wrapper body that calls the parent function. The body
8801 -- contains a single return statement that returns an extension
8802 -- aggregate whose ancestor part is a call to the parent function,
8803 -- passing the formals as actuals (with any controlling arguments
8804 -- converted to the types of the corresponding formals of the
8805 -- parent function, which might be anonymous access types), and
8806 -- having a null extension.
8808 Formal
:= First_Formal
(Subp
);
8809 Par_Formal
:= First_Formal
(Alias
(Subp
));
8810 Formal_Node
:= First
(Formal_List
);
8812 if Present
(Formal
) then
8813 Actual_List
:= New_List
;
8815 Actual_List
:= No_List
;
8818 while Present
(Formal
) loop
8819 if Is_Controlling_Formal
(Formal
) then
8820 Append_To
(Actual_List
,
8821 Make_Type_Conversion
(Loc
,
8823 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
8826 (Defining_Identifier
(Formal_Node
), Loc
)));
8831 (Defining_Identifier
(Formal_Node
), Loc
));
8834 Next_Formal
(Formal
);
8835 Next_Formal
(Par_Formal
);
8840 Make_Simple_Return_Statement
(Loc
,
8842 Make_Extension_Aggregate
(Loc
,
8844 Make_Function_Call
(Loc
,
8846 New_Occurrence_Of
(Alias
(Subp
), Loc
),
8847 Parameter_Associations
=> Actual_List
),
8848 Null_Record_Present
=> True));
8851 Make_Subprogram_Body
(Loc
,
8852 Specification
=> New_Copy_Tree
(Func_Spec
),
8853 Declarations
=> Empty_List
,
8854 Handled_Statement_Sequence
=>
8855 Make_Handled_Sequence_Of_Statements
(Loc
,
8856 Statements
=> New_List
(Return_Stmt
)));
8858 Set_Defining_Unit_Name
8859 (Specification
(Func_Body
),
8860 Make_Defining_Identifier
(Loc
, Chars
(Subp
)));
8862 Append_To
(Body_List
, Func_Body
);
8864 -- Replace the inherited function with the wrapper function in the
8865 -- primitive operations list. We add the minimum decoration needed
8866 -- to override interface primitives.
8868 Set_Ekind
(Defining_Unit_Name
(Func_Spec
), E_Function
);
8870 Override_Dispatching_Operation
8871 (Tag_Typ
, Subp
, New_Op
=> Defining_Unit_Name
(Func_Spec
),
8872 Is_Wrapper
=> True);
8876 Next_Elmt
(Prim_Elmt
);
8878 end Make_Controlling_Function_Wrappers
;
8884 function Make_Eq_Body
8886 Eq_Name
: Name_Id
) return Node_Id
8888 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
8890 Def
: constant Node_Id
:= Parent
(Typ
);
8891 Stmts
: constant List_Id
:= New_List
;
8892 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
8893 Comps
: Node_Id
:= Empty
;
8894 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
8898 Predef_Spec_Or_Body
(Loc
,
8901 Profile
=> New_List
(
8902 Make_Parameter_Specification
(Loc
,
8903 Defining_Identifier
=>
8904 Make_Defining_Identifier
(Loc
, Name_X
),
8905 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
8907 Make_Parameter_Specification
(Loc
,
8908 Defining_Identifier
=>
8909 Make_Defining_Identifier
(Loc
, Name_Y
),
8910 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8912 Ret_Type
=> Standard_Boolean
,
8915 if Variant_Case
then
8916 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
8917 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
8920 if Present
(Typ_Def
) then
8921 Comps
:= Component_List
(Typ_Def
);
8925 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
8928 if Variant_Case
then
8930 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
8931 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
8933 Make_Simple_Return_Statement
(Loc
,
8934 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
8938 Make_Simple_Return_Statement
(Loc
,
8940 Expand_Record_Equality
8943 Lhs
=> Make_Identifier
(Loc
, Name_X
),
8944 Rhs
=> Make_Identifier
(Loc
, Name_Y
),
8945 Bodies
=> Declarations
(Decl
))));
8948 Set_Handled_Statement_Sequence
8949 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8957 -- <Make_Eq_If shared components>
8960 -- when V1 => <Make_Eq_Case> on subcomponents
8962 -- when Vn => <Make_Eq_Case> on subcomponents
8965 function Make_Eq_Case
8968 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
8970 Loc
: constant Source_Ptr
:= Sloc
(E
);
8971 Result
: constant List_Id
:= New_List
;
8975 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
8976 -- Given the discriminant that controls a given variant of an unchecked
8977 -- union, find the formal of the equality function that carries the
8978 -- inferred value of the discriminant.
8980 function External_Name
(E
: Entity_Id
) return Name_Id
;
8981 -- The value of a given discriminant is conveyed in the corresponding
8982 -- formal parameter of the equality routine. The name of this formal
8983 -- parameter carries a one-character suffix which is removed here.
8985 --------------------------
8986 -- Corresponding_Formal --
8987 --------------------------
8989 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
8990 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
8994 Elm
:= First_Elmt
(Discrs
);
8995 while Present
(Elm
) loop
8996 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
9003 -- A formal of the proper name must be found
9005 raise Program_Error
;
9006 end Corresponding_Formal
;
9012 function External_Name
(E
: Entity_Id
) return Name_Id
is
9014 Get_Name_String
(Chars
(E
));
9015 Name_Len
:= Name_Len
- 1;
9019 -- Start of processing for Make_Eq_Case
9022 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
9024 if No
(Variant_Part
(CL
)) then
9028 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
9030 if No
(Variant
) then
9034 Alt_List
:= New_List
;
9035 while Present
(Variant
) loop
9036 Append_To
(Alt_List
,
9037 Make_Case_Statement_Alternative
(Loc
,
9038 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
9040 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
9041 Next_Non_Pragma
(Variant
);
9044 -- If we have an Unchecked_Union, use one of the parameters of the
9045 -- enclosing equality routine that captures the discriminant, to use
9046 -- as the expression in the generated case statement.
9048 if Is_Unchecked_Union
(E
) then
9050 Make_Case_Statement
(Loc
,
9052 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
9053 Alternatives
=> Alt_List
));
9057 Make_Case_Statement
(Loc
,
9059 Make_Selected_Component
(Loc
,
9060 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9061 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
9062 Alternatives
=> Alt_List
));
9083 -- or a null statement if the list L is empty
9087 L
: List_Id
) return Node_Id
9089 Loc
: constant Source_Ptr
:= Sloc
(E
);
9091 Field_Name
: Name_Id
;
9096 return Make_Null_Statement
(Loc
);
9101 C
:= First_Non_Pragma
(L
);
9102 while Present
(C
) loop
9103 Field_Name
:= Chars
(Defining_Identifier
(C
));
9105 -- The tags must not be compared: they are not part of the value.
9106 -- Ditto for parent interfaces because their equality operator is
9109 -- Note also that in the following, we use Make_Identifier for
9110 -- the component names. Use of New_Occurrence_Of to identify the
9111 -- components would be incorrect because the wrong entities for
9112 -- discriminants could be picked up in the private type case.
9114 if Field_Name
= Name_uParent
9115 and then Is_Interface
(Etype
(Defining_Identifier
(C
)))
9119 elsif Field_Name
/= Name_uTag
then
9120 Evolve_Or_Else
(Cond
,
9123 Make_Selected_Component
(Loc
,
9124 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9125 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
)),
9128 Make_Selected_Component
(Loc
,
9129 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
9130 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
))));
9133 Next_Non_Pragma
(C
);
9137 return Make_Null_Statement
(Loc
);
9141 Make_Implicit_If_Statement
(E
,
9143 Then_Statements
=> New_List
(
9144 Make_Simple_Return_Statement
(Loc
,
9145 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
9154 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
9156 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
9157 -- Returns true if Prim is a renaming of an unresolved predefined
9158 -- inequality operation.
9160 --------------------------------
9161 -- Is_Predefined_Neq_Renaming --
9162 --------------------------------
9164 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
9166 return Chars
(Prim
) /= Name_Op_Ne
9167 and then Present
(Alias
(Prim
))
9168 and then Comes_From_Source
(Prim
)
9169 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9170 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
9171 end Is_Predefined_Neq_Renaming
;
9175 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
9176 Stmts
: constant List_Id
:= New_List
;
9178 Eq_Prim
: Entity_Id
;
9179 Left_Op
: Entity_Id
;
9180 Renaming_Prim
: Entity_Id
;
9181 Right_Op
: Entity_Id
;
9184 -- Start of processing for Make_Neq_Body
9187 -- For a call on a renaming of a dispatching subprogram that is
9188 -- overridden, if the overriding occurred before the renaming, then
9189 -- the body executed is that of the overriding declaration, even if the
9190 -- overriding declaration is not visible at the place of the renaming;
9191 -- otherwise, the inherited or predefined subprogram is called, see
9194 -- Stage 1: Search for a renaming of the inequality primitive and also
9195 -- search for an overriding of the equality primitive located before the
9196 -- renaming declaration.
9204 Renaming_Prim
:= Empty
;
9206 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9207 while Present
(Elmt
) loop
9208 Prim
:= Node
(Elmt
);
9210 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
9211 if No
(Renaming_Prim
) then
9212 pragma Assert
(No
(Eq_Prim
));
9216 elsif Is_Predefined_Neq_Renaming
(Prim
) then
9217 Renaming_Prim
:= Prim
;
9224 -- No further action needed if no renaming was found
9226 if No
(Renaming_Prim
) then
9230 -- Stage 2: Replace the renaming declaration by a subprogram declaration
9231 -- (required to add its body)
9233 Decl
:= Parent
(Parent
(Renaming_Prim
));
9235 Make_Subprogram_Declaration
(Loc
,
9236 Specification
=> Specification
(Decl
)));
9237 Set_Analyzed
(Decl
);
9239 -- Remove the decoration of intrinsic renaming subprogram
9241 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
9242 Set_Convention
(Renaming_Prim
, Convention_Ada
);
9243 Set_Alias
(Renaming_Prim
, Empty
);
9244 Set_Has_Completion
(Renaming_Prim
, False);
9246 -- Stage 3: Build the corresponding body
9248 Left_Op
:= First_Formal
(Renaming_Prim
);
9249 Right_Op
:= Next_Formal
(Left_Op
);
9252 Predef_Spec_Or_Body
(Loc
,
9254 Name
=> Chars
(Renaming_Prim
),
9255 Profile
=> New_List
(
9256 Make_Parameter_Specification
(Loc
,
9257 Defining_Identifier
=>
9258 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
9259 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9261 Make_Parameter_Specification
(Loc
,
9262 Defining_Identifier
=>
9263 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
9264 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9266 Ret_Type
=> Standard_Boolean
,
9269 -- If the overriding of the equality primitive occurred before the
9270 -- renaming, then generate:
9272 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9274 -- return not Oeq (X, Y);
9277 if Present
(Eq_Prim
) then
9280 -- Otherwise build a nested subprogram which performs the predefined
9281 -- evaluation of the equality operator. That is, generate:
9283 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9284 -- function Oeq (X : Y) return Boolean is
9286 -- <<body of default implementation>>
9289 -- return not Oeq (X, Y);
9294 Local_Subp
: Node_Id
;
9296 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
9297 Set_Declarations
(Decl
, New_List
(Local_Subp
));
9298 Target
:= Defining_Entity
(Local_Subp
);
9303 Make_Simple_Return_Statement
(Loc
,
9306 Make_Function_Call
(Loc
,
9307 Name
=> New_Occurrence_Of
(Target
, Loc
),
9308 Parameter_Associations
=> New_List
(
9309 Make_Identifier
(Loc
, Chars
(Left_Op
)),
9310 Make_Identifier
(Loc
, Chars
(Right_Op
)))))));
9312 Set_Handled_Statement_Sequence
9313 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9317 -------------------------------
9318 -- Make_Null_Procedure_Specs --
9319 -------------------------------
9321 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
9322 Decl_List
: constant List_Id
:= New_List
;
9323 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9325 Formal_List
: List_Id
;
9326 New_Param_Spec
: Node_Id
;
9327 Parent_Subp
: Entity_Id
;
9328 Prim_Elmt
: Elmt_Id
;
9332 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9333 while Present
(Prim_Elmt
) loop
9334 Subp
:= Node
(Prim_Elmt
);
9336 -- If a null procedure inherited from an interface has not been
9337 -- overridden, then we build a null procedure declaration to
9338 -- override the inherited procedure.
9340 Parent_Subp
:= Alias
(Subp
);
9342 if Present
(Parent_Subp
)
9343 and then Is_Null_Interface_Primitive
(Parent_Subp
)
9345 Formal_List
:= No_List
;
9346 Formal
:= First_Formal
(Subp
);
9348 if Present
(Formal
) then
9349 Formal_List
:= New_List
;
9351 while Present
(Formal
) loop
9353 -- Copy the parameter spec including default expressions
9356 New_Copy_Tree
(Parent
(Formal
), New_Sloc
=> Loc
);
9358 -- Generate a new defining identifier for the new formal.
9359 -- required because New_Copy_Tree does not duplicate
9360 -- semantic fields (except itypes).
9362 Set_Defining_Identifier
(New_Param_Spec
,
9363 Make_Defining_Identifier
(Sloc
(Formal
),
9364 Chars
=> Chars
(Formal
)));
9366 -- For controlling arguments we must change their
9367 -- parameter type to reference the tagged type (instead
9368 -- of the interface type)
9370 if Is_Controlling_Formal
(Formal
) then
9371 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
9373 Set_Parameter_Type
(New_Param_Spec
,
9374 New_Occurrence_Of
(Tag_Typ
, Loc
));
9377 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
9378 N_Access_Definition
);
9379 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
9380 New_Occurrence_Of
(Tag_Typ
, Loc
));
9384 Append
(New_Param_Spec
, Formal_List
);
9386 Next_Formal
(Formal
);
9390 Append_To
(Decl_List
,
9391 Make_Subprogram_Declaration
(Loc
,
9392 Make_Procedure_Specification
(Loc
,
9393 Defining_Unit_Name
=>
9394 Make_Defining_Identifier
(Loc
, Chars
(Subp
)),
9395 Parameter_Specifications
=> Formal_List
,
9396 Null_Present
=> True)));
9399 Next_Elmt
(Prim_Elmt
);
9403 end Make_Null_Procedure_Specs
;
9405 -------------------------------------
9406 -- Make_Predefined_Primitive_Specs --
9407 -------------------------------------
9409 procedure Make_Predefined_Primitive_Specs
9410 (Tag_Typ
: Entity_Id
;
9411 Predef_List
: out List_Id
;
9412 Renamed_Eq
: out Entity_Id
)
9414 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
9415 -- Returns true if Prim is a renaming of an unresolved predefined
9416 -- equality operation.
9418 -------------------------------
9419 -- Is_Predefined_Eq_Renaming --
9420 -------------------------------
9422 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
9424 return Chars
(Prim
) /= Name_Op_Eq
9425 and then Present
(Alias
(Prim
))
9426 and then Comes_From_Source
(Prim
)
9427 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9428 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
9429 end Is_Predefined_Eq_Renaming
;
9433 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9434 Res
: constant List_Id
:= New_List
;
9435 Eq_Name
: Name_Id
:= Name_Op_Eq
;
9436 Eq_Needed
: Boolean;
9440 Has_Predef_Eq_Renaming
: Boolean := False;
9441 -- Set to True if Tag_Typ has a primitive that renames the predefined
9442 -- equality operator. Used to implement (RM 8-5-4(8)).
9444 -- Start of processing for Make_Predefined_Primitive_Specs
9447 Renamed_Eq
:= Empty
;
9451 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9454 Profile
=> New_List
(
9455 Make_Parameter_Specification
(Loc
,
9456 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9457 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9459 Ret_Type
=> Standard_Long_Long_Integer
));
9461 -- Specs for dispatching stream attributes
9464 Stream_Op_TSS_Names
:
9465 constant array (Integer range <>) of TSS_Name_Type
:=
9472 for Op
in Stream_Op_TSS_Names
'Range loop
9473 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
9475 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
9476 Stream_Op_TSS_Names
(Op
)));
9481 -- Spec of "=" is expanded if the type is not limited and if a user
9482 -- defined "=" was not already declared for the non-full view of a
9483 -- private extension
9485 if not Is_Limited_Type
(Tag_Typ
) then
9487 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9488 while Present
(Prim
) loop
9490 -- If a primitive is encountered that renames the predefined
9491 -- equality operator before reaching any explicit equality
9492 -- primitive, then we still need to create a predefined equality
9493 -- function, because calls to it can occur via the renaming. A
9494 -- new name is created for the equality to avoid conflicting with
9495 -- any user-defined equality. (Note that this doesn't account for
9496 -- renamings of equality nested within subpackages???)
9498 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9499 Has_Predef_Eq_Renaming
:= True;
9500 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
9502 -- User-defined equality
9504 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
9505 if No
(Alias
(Node
(Prim
)))
9506 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
9507 N_Subprogram_Renaming_Declaration
9512 -- If the parent is not an interface type and has an abstract
9513 -- equality function explicitly defined in the sources, then
9514 -- the inherited equality is abstract as well, and no body can
9515 -- be created for it.
9517 elsif not Is_Interface
(Etype
(Tag_Typ
))
9518 and then Present
(Alias
(Node
(Prim
)))
9519 and then Comes_From_Source
(Alias
(Node
(Prim
)))
9520 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
9525 -- If the type has an equality function corresponding with
9526 -- a primitive defined in an interface type, the inherited
9527 -- equality is abstract as well, and no body can be created
9530 elsif Present
(Alias
(Node
(Prim
)))
9531 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
9534 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
9544 -- If a renaming of predefined equality was found but there was no
9545 -- user-defined equality (so Eq_Needed is still true), then set the
9546 -- name back to Name_Op_Eq. But in the case where a user-defined
9547 -- equality was located after such a renaming, then the predefined
9548 -- equality function is still needed, so Eq_Needed must be set back
9551 if Eq_Name
/= Name_Op_Eq
then
9553 Eq_Name
:= Name_Op_Eq
;
9560 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
9563 Profile
=> New_List
(
9564 Make_Parameter_Specification
(Loc
,
9565 Defining_Identifier
=>
9566 Make_Defining_Identifier
(Loc
, Name_X
),
9567 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9569 Make_Parameter_Specification
(Loc
,
9570 Defining_Identifier
=>
9571 Make_Defining_Identifier
(Loc
, Name_Y
),
9572 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9573 Ret_Type
=> Standard_Boolean
);
9574 Append_To
(Res
, Eq_Spec
);
9576 if Has_Predef_Eq_Renaming
then
9577 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
9579 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9580 while Present
(Prim
) loop
9582 -- Any renamings of equality that appeared before an
9583 -- overriding equality must be updated to refer to the
9584 -- entity for the predefined equality, otherwise calls via
9585 -- the renaming would get incorrectly resolved to call the
9586 -- user-defined equality function.
9588 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9589 Set_Alias
(Node
(Prim
), Renamed_Eq
);
9591 -- Exit upon encountering a user-defined equality
9593 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
9594 and then No
(Alias
(Node
(Prim
)))
9604 -- Spec for dispatching assignment
9606 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9608 Name
=> Name_uAssign
,
9609 Profile
=> New_List
(
9610 Make_Parameter_Specification
(Loc
,
9611 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9612 Out_Present
=> True,
9613 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9615 Make_Parameter_Specification
(Loc
,
9616 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
9617 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
9620 -- Ada 2005: Generate declarations for the following primitive
9621 -- operations for limited interfaces and synchronized types that
9622 -- implement a limited interface.
9624 -- Disp_Asynchronous_Select
9625 -- Disp_Conditional_Select
9626 -- Disp_Get_Prim_Op_Kind
9629 -- Disp_Timed_Select
9631 -- Disable the generation of these bodies if No_Dispatching_Calls,
9632 -- Ravenscar or ZFP is active.
9634 if Ada_Version
>= Ada_2005
9635 and then not Restriction_Active
(No_Dispatching_Calls
)
9636 and then not Restriction_Active
(No_Select_Statements
)
9637 and then RTE_Available
(RE_Select_Specific_Data
)
9639 -- These primitives are defined abstract in interface types
9641 if Is_Interface
(Tag_Typ
)
9642 and then Is_Limited_Record
(Tag_Typ
)
9645 Make_Abstract_Subprogram_Declaration
(Loc
,
9647 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9650 Make_Abstract_Subprogram_Declaration
(Loc
,
9652 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9655 Make_Abstract_Subprogram_Declaration
(Loc
,
9657 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9660 Make_Abstract_Subprogram_Declaration
(Loc
,
9662 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9665 Make_Abstract_Subprogram_Declaration
(Loc
,
9667 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9670 Make_Abstract_Subprogram_Declaration
(Loc
,
9672 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9674 -- If ancestor is an interface type, declare non-abstract primitives
9675 -- to override the abstract primitives of the interface type.
9677 -- In VM targets we define these primitives in all root tagged types
9678 -- that are not interface types. Done because in VM targets we don't
9679 -- have secondary dispatch tables and any derivation of Tag_Typ may
9680 -- cover limited interfaces (which always have these primitives since
9681 -- they may be ancestors of synchronized interface types).
9683 elsif (not Is_Interface
(Tag_Typ
)
9684 and then Is_Interface
(Etype
(Tag_Typ
))
9685 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
9687 (Is_Concurrent_Record_Type
(Tag_Typ
)
9688 and then Has_Interfaces
(Tag_Typ
))
9690 (not Tagged_Type_Expansion
9691 and then not Is_Interface
(Tag_Typ
)
9692 and then Tag_Typ
= Root_Type
(Tag_Typ
))
9695 Make_Subprogram_Declaration
(Loc
,
9697 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9700 Make_Subprogram_Declaration
(Loc
,
9702 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9705 Make_Subprogram_Declaration
(Loc
,
9707 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9710 Make_Subprogram_Declaration
(Loc
,
9712 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9715 Make_Subprogram_Declaration
(Loc
,
9717 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9720 Make_Subprogram_Declaration
(Loc
,
9722 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9726 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
9727 -- regardless of whether they are controlled or may contain controlled
9730 -- Do not generate the routines if finalization is disabled
9732 if Restriction_Active
(No_Finalization
) then
9736 if not Is_Limited_Type
(Tag_Typ
) then
9737 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
9740 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
9744 end Make_Predefined_Primitive_Specs
;
9746 -------------------------
9747 -- Make_Tag_Assignment --
9748 -------------------------
9750 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
9751 Loc
: constant Source_Ptr
:= Sloc
(N
);
9752 Def_If
: constant Entity_Id
:= Defining_Identifier
(N
);
9753 Expr
: constant Node_Id
:= Expression
(N
);
9754 Typ
: constant Entity_Id
:= Etype
(Def_If
);
9755 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
9759 -- This expansion activity is called during analysis, but cannot
9760 -- be applied in ASIS mode when other expansion is disabled.
9762 if Is_Tagged_Type
(Typ
)
9763 and then not Is_Class_Wide_Type
(Typ
)
9764 and then not Is_CPP_Class
(Typ
)
9765 and then Tagged_Type_Expansion
9766 and then Nkind
(Expr
) /= N_Aggregate
9767 and then not ASIS_Mode
9768 and then (Nkind
(Expr
) /= N_Qualified_Expression
9769 or else Nkind
(Expression
(Expr
)) /= N_Aggregate
)
9772 Make_Selected_Component
(Loc
,
9773 Prefix
=> New_Occurrence_Of
(Def_If
, Loc
),
9775 New_Occurrence_Of
(First_Tag_Component
(Full_Typ
), Loc
));
9776 Set_Assignment_OK
(New_Ref
);
9779 Make_Assignment_Statement
(Loc
,
9782 Unchecked_Convert_To
(RTE
(RE_Tag
),
9783 New_Occurrence_Of
(Node
9784 (First_Elmt
(Access_Disp_Table
(Full_Typ
))), Loc
)));
9788 end Make_Tag_Assignment
;
9790 ---------------------------------
9791 -- Needs_Simple_Initialization --
9792 ---------------------------------
9794 function Needs_Simple_Initialization
9796 Consider_IS
: Boolean := True) return Boolean
9798 Consider_IS_NS
: constant Boolean :=
9799 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
9802 -- Never need initialization if it is suppressed
9804 if Initialization_Suppressed
(T
) then
9808 -- Check for private type, in which case test applies to the underlying
9809 -- type of the private type.
9811 if Is_Private_Type
(T
) then
9813 RT
: constant Entity_Id
:= Underlying_Type
(T
);
9815 if Present
(RT
) then
9816 return Needs_Simple_Initialization
(RT
);
9822 -- Scalar type with Default_Value aspect requires initialization
9824 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
9827 -- Cases needing simple initialization are access types, and, if pragma
9828 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
9831 elsif Is_Access_Type
(T
)
9832 or else (Consider_IS_NS
and then (Is_Scalar_Type
(T
)))
9836 -- If Initialize/Normalize_Scalars is in effect, string objects also
9837 -- need initialization, unless they are created in the course of
9838 -- expanding an aggregate (since in the latter case they will be
9839 -- filled with appropriate initializing values before they are used).
9841 elsif Consider_IS_NS
9842 and then Is_Standard_String_Type
(T
)
9845 or else Nkind
(Associated_Node_For_Itype
(T
)) /= N_Aggregate
)
9852 end Needs_Simple_Initialization
;
9854 ----------------------
9855 -- Predef_Deep_Spec --
9856 ----------------------
9858 function Predef_Deep_Spec
9860 Tag_Typ
: Entity_Id
;
9861 Name
: TSS_Name_Type
;
9862 For_Body
: Boolean := False) return Node_Id
9867 -- V : in out Tag_Typ
9869 Formals
:= New_List
(
9870 Make_Parameter_Specification
(Loc
,
9871 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
9873 Out_Present
=> True,
9874 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
9876 -- F : Boolean := True
9878 if Name
= TSS_Deep_Adjust
9879 or else Name
= TSS_Deep_Finalize
9882 Make_Parameter_Specification
(Loc
,
9883 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
9884 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
9885 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9889 Predef_Spec_Or_Body
(Loc
,
9890 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
9893 For_Body
=> For_Body
);
9896 when RE_Not_Available
=>
9898 end Predef_Deep_Spec
;
9900 -------------------------
9901 -- Predef_Spec_Or_Body --
9902 -------------------------
9904 function Predef_Spec_Or_Body
9906 Tag_Typ
: Entity_Id
;
9909 Ret_Type
: Entity_Id
:= Empty
;
9910 For_Body
: Boolean := False) return Node_Id
9912 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
9916 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
9918 -- The internal flag is set to mark these declarations because they have
9919 -- specific properties. First, they are primitives even if they are not
9920 -- defined in the type scope (the freezing point is not necessarily in
9921 -- the same scope). Second, the predefined equality can be overridden by
9922 -- a user-defined equality, no body will be generated in this case.
9924 Set_Is_Internal
(Id
);
9926 if not Debug_Generated_Code
then
9927 Set_Debug_Info_Off
(Id
);
9930 if No
(Ret_Type
) then
9932 Make_Procedure_Specification
(Loc
,
9933 Defining_Unit_Name
=> Id
,
9934 Parameter_Specifications
=> Profile
);
9937 Make_Function_Specification
(Loc
,
9938 Defining_Unit_Name
=> Id
,
9939 Parameter_Specifications
=> Profile
,
9940 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
9943 if Is_Interface
(Tag_Typ
) then
9944 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
9946 -- If body case, return empty subprogram body. Note that this is ill-
9947 -- formed, because there is not even a null statement, and certainly not
9948 -- a return in the function case. The caller is expected to do surgery
9949 -- on the body to add the appropriate stuff.
9952 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
9954 -- For the case of an Input attribute predefined for an abstract type,
9955 -- generate an abstract specification. This will never be called, but we
9956 -- need the slot allocated in the dispatching table so that attributes
9957 -- typ'Class'Input and typ'Class'Output will work properly.
9959 elsif Is_TSS
(Name
, TSS_Stream_Input
)
9960 and then Is_Abstract_Type
(Tag_Typ
)
9962 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
9964 -- Normal spec case, where we return a subprogram declaration
9967 return Make_Subprogram_Declaration
(Loc
, Spec
);
9969 end Predef_Spec_Or_Body
;
9971 -----------------------------
9972 -- Predef_Stream_Attr_Spec --
9973 -----------------------------
9975 function Predef_Stream_Attr_Spec
9977 Tag_Typ
: Entity_Id
;
9978 Name
: TSS_Name_Type
;
9979 For_Body
: Boolean := False) return Node_Id
9981 Ret_Type
: Entity_Id
;
9984 if Name
= TSS_Stream_Input
then
9985 Ret_Type
:= Tag_Typ
;
9993 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
9995 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
9996 Ret_Type
=> Ret_Type
,
9997 For_Body
=> For_Body
);
9998 end Predef_Stream_Attr_Spec
;
10000 ---------------------------------
10001 -- Predefined_Primitive_Bodies --
10002 ---------------------------------
10004 function Predefined_Primitive_Bodies
10005 (Tag_Typ
: Entity_Id
;
10006 Renamed_Eq
: Entity_Id
) return List_Id
10008 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
10009 Res
: constant List_Id
:= New_List
;
10012 Eq_Needed
: Boolean;
10016 pragma Warnings
(Off
, Ent
);
10019 pragma Assert
(not Is_Interface
(Tag_Typ
));
10021 -- See if we have a predefined "=" operator
10023 if Present
(Renamed_Eq
) then
10025 Eq_Name
:= Chars
(Renamed_Eq
);
10027 -- If the parent is an interface type then it has defined all the
10028 -- predefined primitives abstract and we need to check if the type
10029 -- has some user defined "=" function which matches the profile of
10030 -- the Ada predefined equality operator to avoid generating it.
10032 elsif Is_Interface
(Etype
(Tag_Typ
)) then
10034 Eq_Name
:= Name_Op_Eq
;
10036 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10037 while Present
(Prim
) loop
10038 if Chars
(Node
(Prim
)) = Name_Op_Eq
10039 and then not Is_Internal
(Node
(Prim
))
10040 and then Present
(First_Entity
(Node
(Prim
)))
10042 -- The predefined equality primitive must have exactly two
10043 -- formals whose type is this tagged type
10045 and then Present
(Last_Entity
(Node
(Prim
)))
10046 and then Next_Entity
(First_Entity
(Node
(Prim
)))
10047 = Last_Entity
(Node
(Prim
))
10048 and then Etype
(First_Entity
(Node
(Prim
))) = Tag_Typ
10049 and then Etype
(Last_Entity
(Node
(Prim
))) = Tag_Typ
10051 Eq_Needed
:= False;
10052 Eq_Name
:= No_Name
;
10060 Eq_Needed
:= False;
10061 Eq_Name
:= No_Name
;
10063 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10064 while Present
(Prim
) loop
10065 if Chars
(Node
(Prim
)) = Name_Op_Eq
10066 and then Is_Internal
(Node
(Prim
))
10069 Eq_Name
:= Name_Op_Eq
;
10079 Decl
:= Predef_Spec_Or_Body
(Loc
,
10080 Tag_Typ
=> Tag_Typ
,
10081 Name
=> Name_uSize
,
10082 Profile
=> New_List
(
10083 Make_Parameter_Specification
(Loc
,
10084 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10085 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10087 Ret_Type
=> Standard_Long_Long_Integer
,
10090 Set_Handled_Statement_Sequence
(Decl
,
10091 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10092 Make_Simple_Return_Statement
(Loc
,
10094 Make_Attribute_Reference
(Loc
,
10095 Prefix
=> Make_Identifier
(Loc
, Name_X
),
10096 Attribute_Name
=> Name_Size
)))));
10098 Append_To
(Res
, Decl
);
10100 -- Bodies for Dispatching stream IO routines. We need these only for
10101 -- non-limited types (in the limited case there is no dispatching).
10102 -- We also skip them if dispatching or finalization are not available
10103 -- or if stream operations are prohibited by restriction No_Streams or
10104 -- from use of pragma/aspect No_Tagged_Streams.
10106 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
10107 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
10109 Build_Record_Read_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10110 Append_To
(Res
, Decl
);
10113 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
10114 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
10116 Build_Record_Write_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10117 Append_To
(Res
, Decl
);
10120 -- Skip body of _Input for the abstract case, since the corresponding
10121 -- spec is abstract (see Predef_Spec_Or_Body).
10123 if not Is_Abstract_Type
(Tag_Typ
)
10124 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
10125 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
10127 Build_Record_Or_Elementary_Input_Function
10128 (Loc
, Tag_Typ
, Decl
, Ent
);
10129 Append_To
(Res
, Decl
);
10132 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
10133 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
10135 Build_Record_Or_Elementary_Output_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10136 Append_To
(Res
, Decl
);
10139 -- Ada 2005: Generate bodies for the following primitive operations for
10140 -- limited interfaces and synchronized types that implement a limited
10143 -- disp_asynchronous_select
10144 -- disp_conditional_select
10145 -- disp_get_prim_op_kind
10146 -- disp_get_task_id
10147 -- disp_timed_select
10149 -- The interface versions will have null bodies
10151 -- Disable the generation of these bodies if No_Dispatching_Calls,
10152 -- Ravenscar or ZFP is active.
10154 -- In VM targets we define these primitives in all root tagged types
10155 -- that are not interface types. Done because in VM targets we don't
10156 -- have secondary dispatch tables and any derivation of Tag_Typ may
10157 -- cover limited interfaces (which always have these primitives since
10158 -- they may be ancestors of synchronized interface types).
10160 if Ada_Version
>= Ada_2005
10161 and then not Is_Interface
(Tag_Typ
)
10163 ((Is_Interface
(Etype
(Tag_Typ
))
10164 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10166 (Is_Concurrent_Record_Type
(Tag_Typ
)
10167 and then Has_Interfaces
(Tag_Typ
))
10169 (not Tagged_Type_Expansion
10170 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
10171 and then not Restriction_Active
(No_Dispatching_Calls
)
10172 and then not Restriction_Active
(No_Select_Statements
)
10173 and then RTE_Available
(RE_Select_Specific_Data
)
10175 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
10176 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
10177 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
10178 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
10179 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
10180 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
10183 if not Is_Limited_Type
(Tag_Typ
) and then not Is_Interface
(Tag_Typ
) then
10185 -- Body for equality
10188 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
10189 Append_To
(Res
, Decl
);
10192 -- Body for inequality (if required)
10194 Decl
:= Make_Neq_Body
(Tag_Typ
);
10196 if Present
(Decl
) then
10197 Append_To
(Res
, Decl
);
10200 -- Body for dispatching assignment
10203 Predef_Spec_Or_Body
(Loc
,
10204 Tag_Typ
=> Tag_Typ
,
10205 Name
=> Name_uAssign
,
10206 Profile
=> New_List
(
10207 Make_Parameter_Specification
(Loc
,
10208 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10209 Out_Present
=> True,
10210 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
10212 Make_Parameter_Specification
(Loc
,
10213 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
10214 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10217 Set_Handled_Statement_Sequence
(Decl
,
10218 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10219 Make_Assignment_Statement
(Loc
,
10220 Name
=> Make_Identifier
(Loc
, Name_X
),
10221 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
10223 Append_To
(Res
, Decl
);
10226 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
10227 -- tagged types which do not contain controlled components.
10229 -- Do not generate the routines if finalization is disabled
10231 if Restriction_Active
(No_Finalization
) then
10234 elsif not Has_Controlled_Component
(Tag_Typ
) then
10235 if not Is_Limited_Type
(Tag_Typ
) then
10236 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
10238 if Is_Controlled
(Tag_Typ
) then
10239 Set_Handled_Statement_Sequence
(Decl
,
10240 Make_Handled_Sequence_Of_Statements
(Loc
,
10241 Statements
=> New_List
(
10243 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10244 Typ
=> Tag_Typ
))));
10247 Set_Handled_Statement_Sequence
(Decl
,
10248 Make_Handled_Sequence_Of_Statements
(Loc
,
10249 Statements
=> New_List
(
10250 Make_Null_Statement
(Loc
))));
10253 Append_To
(Res
, Decl
);
10256 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
10258 if Is_Controlled
(Tag_Typ
) then
10259 Set_Handled_Statement_Sequence
(Decl
,
10260 Make_Handled_Sequence_Of_Statements
(Loc
,
10261 Statements
=> New_List
(
10263 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10264 Typ
=> Tag_Typ
))));
10267 Set_Handled_Statement_Sequence
(Decl
,
10268 Make_Handled_Sequence_Of_Statements
(Loc
,
10269 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
10272 Append_To
(Res
, Decl
);
10276 end Predefined_Primitive_Bodies
;
10278 ---------------------------------
10279 -- Predefined_Primitive_Freeze --
10280 ---------------------------------
10282 function Predefined_Primitive_Freeze
10283 (Tag_Typ
: Entity_Id
) return List_Id
10285 Res
: constant List_Id
:= New_List
;
10290 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10291 while Present
(Prim
) loop
10292 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
10293 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
10295 if Present
(Frnodes
) then
10296 Append_List_To
(Res
, Frnodes
);
10304 end Predefined_Primitive_Freeze
;
10306 -------------------------
10307 -- Stream_Operation_OK --
10308 -------------------------
10310 function Stream_Operation_OK
10312 Operation
: TSS_Name_Type
) return Boolean
10314 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
10317 -- Special case of a limited type extension: a default implementation
10318 -- of the stream attributes Read or Write exists if that attribute
10319 -- has been specified or is available for an ancestor type; a default
10320 -- implementation of the attribute Output (resp. Input) exists if the
10321 -- attribute has been specified or Write (resp. Read) is available for
10322 -- an ancestor type. The last condition only applies under Ada 2005.
10324 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
10325 if Operation
= TSS_Stream_Read
then
10326 Has_Predefined_Or_Specified_Stream_Attribute
:=
10327 Has_Specified_Stream_Read
(Typ
);
10329 elsif Operation
= TSS_Stream_Write
then
10330 Has_Predefined_Or_Specified_Stream_Attribute
:=
10331 Has_Specified_Stream_Write
(Typ
);
10333 elsif Operation
= TSS_Stream_Input
then
10334 Has_Predefined_Or_Specified_Stream_Attribute
:=
10335 Has_Specified_Stream_Input
(Typ
)
10337 (Ada_Version
>= Ada_2005
10338 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
10340 elsif Operation
= TSS_Stream_Output
then
10341 Has_Predefined_Or_Specified_Stream_Attribute
:=
10342 Has_Specified_Stream_Output
(Typ
)
10344 (Ada_Version
>= Ada_2005
10345 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
10348 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
10350 if not Has_Predefined_Or_Specified_Stream_Attribute
10351 and then Is_Derived_Type
(Typ
)
10352 and then (Operation
= TSS_Stream_Read
10353 or else Operation
= TSS_Stream_Write
)
10355 Has_Predefined_Or_Specified_Stream_Attribute
:=
10357 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
10361 -- If the type is not limited, or else is limited but the attribute is
10362 -- explicitly specified or is predefined for the type, then return True,
10363 -- unless other conditions prevail, such as restrictions prohibiting
10364 -- streams or dispatching operations. We also return True for limited
10365 -- interfaces, because they may be extended by nonlimited types and
10366 -- permit inheritance in this case (addresses cases where an abstract
10367 -- extension doesn't get 'Input declared, as per comments below, but
10368 -- 'Class'Input must still be allowed). Note that attempts to apply
10369 -- stream attributes to a limited interface or its class-wide type
10370 -- (or limited extensions thereof) will still get properly rejected
10371 -- by Check_Stream_Attribute.
10373 -- We exclude the Input operation from being a predefined subprogram in
10374 -- the case where the associated type is an abstract extension, because
10375 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
10376 -- we don't want an abstract version created because types derived from
10377 -- the abstract type may not even have Input available (for example if
10378 -- derived from a private view of the abstract type that doesn't have
10379 -- a visible Input).
10381 -- Do not generate stream routines for type Finalization_Master because
10382 -- a master may never appear in types and therefore cannot be read or
10386 (not Is_Limited_Type
(Typ
)
10387 or else Is_Interface
(Typ
)
10388 or else Has_Predefined_Or_Specified_Stream_Attribute
)
10390 (Operation
/= TSS_Stream_Input
10391 or else not Is_Abstract_Type
(Typ
)
10392 or else not Is_Derived_Type
(Typ
))
10393 and then not Has_Unknown_Discriminants
(Typ
)
10395 (Is_Interface
(Typ
)
10397 (Is_Task_Interface
(Typ
)
10398 or else Is_Protected_Interface
(Typ
)
10399 or else Is_Synchronized_Interface
(Typ
)))
10400 and then not Restriction_Active
(No_Streams
)
10401 and then not Restriction_Active
(No_Dispatch
)
10402 and then No
(No_Tagged_Streams_Pragma
(Typ
))
10403 and then not No_Run_Time_Mode
10404 and then RTE_Available
(RE_Tag
)
10405 and then No
(Type_Without_Stream_Operation
(Typ
))
10406 and then RTE_Available
(RE_Root_Stream_Type
)
10407 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
10408 end Stream_Operation_OK
;