1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Einfo
; use Einfo
;
29 with Errout
; use Errout
;
30 with Exp_Aggr
; use Exp_Aggr
;
31 with Exp_Atag
; use Exp_Atag
;
32 with Exp_Ch4
; use Exp_Ch4
;
33 with Exp_Ch6
; use Exp_Ch6
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Ch9
; use Exp_Ch9
;
36 with Exp_Ch11
; use Exp_Ch11
;
37 with Exp_Dbug
; use Exp_Dbug
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Dist
; use Exp_Dist
;
40 with Exp_Smem
; use Exp_Smem
;
41 with Exp_Strm
; use Exp_Strm
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Freeze
; use Freeze
;
45 with Namet
; use Namet
;
46 with Nlists
; use Nlists
;
47 with Nmake
; use Nmake
;
49 with Restrict
; use Restrict
;
50 with Rident
; use Rident
;
51 with Rtsfind
; use Rtsfind
;
53 with Sem_Aux
; use Sem_Aux
;
54 with Sem_Attr
; use Sem_Attr
;
55 with Sem_Cat
; use Sem_Cat
;
56 with Sem_Ch3
; use Sem_Ch3
;
57 with Sem_Ch6
; use Sem_Ch6
;
58 with Sem_Ch8
; use Sem_Ch8
;
59 with Sem_Ch13
; use Sem_Ch13
;
60 with Sem_Disp
; use Sem_Disp
;
61 with Sem_Eval
; use Sem_Eval
;
62 with Sem_Mech
; use Sem_Mech
;
63 with Sem_Res
; use Sem_Res
;
64 with Sem_SCIL
; use Sem_SCIL
;
65 with Sem_Type
; use Sem_Type
;
66 with Sem_Util
; use Sem_Util
;
67 with Sinfo
; use Sinfo
;
68 with Stand
; use Stand
;
69 with Snames
; use Snames
;
70 with Targparm
; use Targparm
;
71 with Tbuild
; use Tbuild
;
72 with Ttypes
; use Ttypes
;
73 with Validsw
; use Validsw
;
75 package body Exp_Ch3
is
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Adjust_Discriminants
(Rtype
: Entity_Id
);
82 -- This is used when freezing a record type. It attempts to construct
83 -- more restrictive subtypes for discriminants so that the max size of
84 -- the record can be calculated more accurately. See the body of this
85 -- procedure for details.
87 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
);
88 -- Build initialization procedure for given array type. Nod is a node
89 -- used for attachment of any actions required in its construction.
90 -- It also supplies the source location used for the procedure.
92 function Build_Array_Invariant_Proc
94 Nod
: Node_Id
) return Node_Id
;
95 -- If the component of type of array type has invariants, build procedure
96 -- that checks invariant on all components of the array. Ada 2012 specifies
97 -- that an invariant on some type T must be applied to in-out parameters
98 -- and return values that include a part of type T. If the array type has
99 -- an otherwise specified invariant, the component check procedure is
100 -- called from within the user-specified invariant. Otherwise this becomes
101 -- the invariant procedure for the array type.
103 function Build_Record_Invariant_Proc
105 Nod
: Node_Id
) return Node_Id
;
106 -- Ditto for record types.
108 function Build_Discriminant_Formals
110 Use_Dl
: Boolean) return List_Id
;
111 -- This function uses the discriminants of a type to build a list of
112 -- formal parameters, used in Build_Init_Procedure among other places.
113 -- If the flag Use_Dl is set, the list is built using the already
114 -- defined discriminals of the type, as is the case for concurrent
115 -- types with discriminants. Otherwise new identifiers are created,
116 -- with the source names of the discriminants.
118 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
;
119 -- This function builds a static aggregate that can serve as the initial
120 -- value for an array type whose bounds are static, and whose component
121 -- type is a composite type that has a static equivalent aggregate.
122 -- The equivalent array aggregate is used both for object initialization
123 -- and for component initialization, when used in the following function.
125 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
;
126 -- This function builds a static aggregate that can serve as the initial
127 -- value for a record type whose components are scalar and initialized
128 -- with compile-time values, or arrays with similar initialization or
129 -- defaults. When possible, initialization of an object of the type can
130 -- be achieved by using a copy of the aggregate as an initial value, thus
131 -- removing the implicit call that would otherwise constitute elaboration
134 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
);
135 -- Build record initialization procedure. N is the type declaration
136 -- node, and Rec_Ent is the corresponding entity for the record type.
138 procedure Build_Slice_Assignment
(Typ
: Entity_Id
);
139 -- Build assignment procedure for one-dimensional arrays of controlled
140 -- types. Other array and slice assignments are expanded in-line, but
141 -- the code expansion for controlled components (when control actions
142 -- are active) can lead to very large blocks that GCC3 handles poorly.
144 procedure Build_Untagged_Equality
(Typ
: Entity_Id
);
145 -- AI05-0123: Equality on untagged records composes. This procedure
146 -- builds the equality routine for an untagged record that has components
147 -- of a record type that has user-defined primitive equality operations.
148 -- The resulting operation is a TSS subprogram.
150 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
);
151 -- Create An Equality function for the untagged variant record Typ and
152 -- attach it to the TSS list
154 procedure Check_Stream_Attributes
(Typ
: Entity_Id
);
155 -- Check that if a limited extension has a parent with user-defined stream
156 -- attributes, and does not itself have user-defined stream-attributes,
157 -- then any limited component of the extension also has the corresponding
158 -- user-defined stream attributes.
160 procedure Clean_Task_Names
162 Proc_Id
: Entity_Id
);
163 -- If an initialization procedure includes calls to generate names
164 -- for task subcomponents, indicate that secondary stack cleanup is
165 -- needed after an initialization. Typ is the component type, and Proc_Id
166 -- the initialization procedure for the enclosing composite type.
168 procedure Expand_Freeze_Array_Type
(N
: Node_Id
);
169 -- Freeze an array type. Deals with building the initialization procedure,
170 -- creating the packed array type for a packed array and also with the
171 -- creation of the controlling procedures for the controlled case. The
172 -- argument N is the N_Freeze_Entity node for the type.
174 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
);
175 -- Freeze a class-wide type. Build routine Finalize_Address for the purpose
176 -- of finalizing controlled derivations from the class-wide's root type.
178 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
);
179 -- Freeze enumeration type with non-standard representation. Builds the
180 -- array and function needed to convert between enumeration pos and
181 -- enumeration representation values. N is the N_Freeze_Entity node
184 procedure Expand_Freeze_Record_Type
(N
: Node_Id
);
185 -- Freeze record type. Builds all necessary discriminant checking
186 -- and other ancillary functions, and builds dispatch tables where
187 -- needed. The argument N is the N_Freeze_Entity node. This processing
188 -- applies only to E_Record_Type entities, not to class wide types,
189 -- record subtypes, or private types.
191 procedure Expand_Tagged_Root
(T
: Entity_Id
);
192 -- Add a field _Tag at the beginning of the record. This field carries
193 -- the value of the access to the Dispatch table. This procedure is only
194 -- called on root type, the _Tag field being inherited by the descendants.
196 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
);
197 -- Treat user-defined stream operations as renaming_as_body if the
198 -- subprogram they rename is not frozen when the type is frozen.
200 procedure Insert_Component_Invariant_Checks
204 -- If a composite type has invariants and also has components with defined
205 -- invariants. the component invariant procedure is inserted into the user-
206 -- defined invariant procedure and added to the checks to be performed.
208 procedure Initialization_Warning
(E
: Entity_Id
);
209 -- If static elaboration of the package is requested, indicate
210 -- when a type does meet the conditions for static initialization. If
211 -- E is a type, it has components that have no static initialization.
212 -- if E is an entity, its initial expression is not compile-time known.
214 function Init_Formals
(Typ
: Entity_Id
) return List_Id
;
215 -- This function builds the list of formals for an initialization routine.
216 -- The first formal is always _Init with the given type. For task value
217 -- record types and types containing tasks, three additional formals are
220 -- _Master : Master_Id
221 -- _Chain : in out Activation_Chain
222 -- _Task_Name : String
224 -- The caller must append additional entries for discriminants if required.
226 function In_Runtime
(E
: Entity_Id
) return Boolean;
227 -- Check if E is defined in the RTL (in a child of Ada or System). Used
228 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
230 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean;
231 -- Returns true if Prim is a user defined equality function
233 function Make_Eq_Body
235 Eq_Name
: Name_Id
) return Node_Id
;
236 -- Build the body of a primitive equality operation for a tagged record
237 -- type, or in Ada 2012 for any record type that has components with a
238 -- user-defined equality. Factored out of Predefined_Primitive_Bodies.
240 function Make_Eq_Case
243 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
;
244 -- Building block for variant record equality. Defined to share the code
245 -- between the tagged and untagged case. Given a Component_List node CL,
246 -- it generates an 'if' followed by a 'case' statement that compares all
247 -- components of local temporaries named X and Y (that are declared as
248 -- formals at some upper level). E provides the Sloc to be used for the
251 -- IF E is an unchecked_union, Discrs is the list of formals created for
252 -- the inferred discriminants of one operand. These formals are used in
253 -- the generated case statements for each variant of the unchecked union.
257 L
: List_Id
) return Node_Id
;
258 -- Building block for variant record equality. Defined to share the code
259 -- between the tagged and untagged case. Given the list of components
260 -- (or discriminants) L, it generates a return statement that compares all
261 -- components of local temporaries named X and Y (that are declared as
262 -- formals at some upper level). E provides the Sloc to be used for the
265 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
;
266 -- Search for a renaming of the inequality dispatching primitive of
267 -- this tagged type. If found then build and return the corresponding
268 -- rename-as-body inequality subprogram; otherwise return Empty.
270 procedure Make_Predefined_Primitive_Specs
271 (Tag_Typ
: Entity_Id
;
272 Predef_List
: out List_Id
;
273 Renamed_Eq
: out Entity_Id
);
274 -- Create a list with the specs of the predefined primitive operations.
275 -- For tagged types that are interfaces all these primitives are defined
278 -- The following entries are present for all tagged types, and provide
279 -- the results of the corresponding attribute applied to the object.
280 -- Dispatching is required in general, since the result of the attribute
281 -- will vary with the actual object subtype.
283 -- _size provides result of 'Size attribute
284 -- typSR provides result of 'Read attribute
285 -- typSW provides result of 'Write attribute
286 -- typSI provides result of 'Input attribute
287 -- typSO provides result of 'Output attribute
289 -- The following entries are additionally present for non-limited tagged
290 -- types, and implement additional dispatching operations for predefined
293 -- _equality implements "=" operator
294 -- _assign implements assignment operation
295 -- typDF implements deep finalization
296 -- typDA implements deep adjust
298 -- The latter two are empty procedures unless the type contains some
299 -- controlled components that require finalization actions (the deep
300 -- in the name refers to the fact that the action applies to components).
302 -- The list is returned in Predef_List. The Parameter Renamed_Eq either
303 -- returns the value Empty, or else the defining unit name for the
304 -- predefined equality function in the case where the type has a primitive
305 -- operation that is a renaming of predefined equality (but only if there
306 -- is also an overriding user-defined equality function). The returned
307 -- Renamed_Eq will be passed to the corresponding parameter of
308 -- Predefined_Primitive_Bodies.
310 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean;
311 -- returns True if there are representation clauses for type T that are not
312 -- inherited. If the result is false, the init_proc and the discriminant
313 -- checking functions of the parent can be reused by a derived type.
315 procedure Make_Controlling_Function_Wrappers
316 (Tag_Typ
: Entity_Id
;
317 Decl_List
: out List_Id
;
318 Body_List
: out List_Id
);
319 -- Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
320 -- associated with inherited functions with controlling results which
321 -- are not overridden. The body of each wrapper function consists solely
322 -- of a return statement whose expression is an extension aggregate
323 -- invoking the inherited subprogram's parent subprogram and extended
324 -- with a null association list.
326 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
;
327 -- Ada 2005 (AI-251): Makes specs for null procedures associated with any
328 -- null procedures inherited from an interface type that have not been
329 -- overridden. Only one null procedure will be created for a given set of
330 -- inherited null procedures with homographic profiles.
332 function Predef_Spec_Or_Body
337 Ret_Type
: Entity_Id
:= Empty
;
338 For_Body
: Boolean := False) return Node_Id
;
339 -- This function generates the appropriate expansion for a predefined
340 -- primitive operation specified by its name, parameter profile and
341 -- return type (Empty means this is a procedure). If For_Body is false,
342 -- then the returned node is a subprogram declaration. If For_Body is
343 -- true, then the returned node is a empty subprogram body containing
344 -- no declarations and no statements.
346 function Predef_Stream_Attr_Spec
349 Name
: TSS_Name_Type
;
350 For_Body
: Boolean := False) return Node_Id
;
351 -- Specialized version of Predef_Spec_Or_Body that apply to read, write,
352 -- input and output attribute whose specs are constructed in Exp_Strm.
354 function Predef_Deep_Spec
357 Name
: TSS_Name_Type
;
358 For_Body
: Boolean := False) return Node_Id
;
359 -- Specialized version of Predef_Spec_Or_Body that apply to _deep_adjust
360 -- and _deep_finalize
362 function Predefined_Primitive_Bodies
363 (Tag_Typ
: Entity_Id
;
364 Renamed_Eq
: Entity_Id
) return List_Id
;
365 -- Create the bodies of the predefined primitives that are described in
366 -- Predefined_Primitive_Specs. When not empty, Renamed_Eq must denote
367 -- the defining unit name of the type's predefined equality as returned
368 -- by Make_Predefined_Primitive_Specs.
370 function Predefined_Primitive_Freeze
(Tag_Typ
: Entity_Id
) return List_Id
;
371 -- Freeze entities of all predefined primitive operations. This is needed
372 -- because the bodies of these operations do not normally do any freezing.
374 function Stream_Operation_OK
376 Operation
: TSS_Name_Type
) return Boolean;
377 -- Check whether the named stream operation must be emitted for a given
378 -- type. The rules for inheritance of stream attributes by type extensions
379 -- are enforced by this function. Furthermore, various restrictions prevent
380 -- the generation of these operations, as a useful optimization or for
381 -- certification purposes and to save unnecessary generated code.
383 --------------------------
384 -- Adjust_Discriminants --
385 --------------------------
387 -- This procedure attempts to define subtypes for discriminants that are
388 -- more restrictive than those declared. Such a replacement is possible if
389 -- we can demonstrate that values outside the restricted range would cause
390 -- constraint errors in any case. The advantage of restricting the
391 -- discriminant types in this way is that the maximum size of the variant
392 -- record can be calculated more conservatively.
394 -- An example of a situation in which we can perform this type of
395 -- restriction is the following:
397 -- subtype B is range 1 .. 10;
398 -- type Q is array (B range <>) of Integer;
400 -- type V (N : Natural) is record
404 -- In this situation, we can restrict the upper bound of N to 10, since
405 -- any larger value would cause a constraint error in any case.
407 -- There are many situations in which such restriction is possible, but
408 -- for now, we just look for cases like the above, where the component
409 -- in question is a one dimensional array whose upper bound is one of
410 -- the record discriminants. Also the component must not be part of
411 -- any variant part, since then the component does not always exist.
413 procedure Adjust_Discriminants
(Rtype
: Entity_Id
) is
414 Loc
: constant Source_Ptr
:= Sloc
(Rtype
);
431 Comp
:= First_Component
(Rtype
);
432 while Present
(Comp
) loop
434 -- If our parent is a variant, quit, we do not look at components
435 -- that are in variant parts, because they may not always exist.
437 P
:= Parent
(Comp
); -- component declaration
438 P
:= Parent
(P
); -- component list
440 exit when Nkind
(Parent
(P
)) = N_Variant
;
442 -- We are looking for a one dimensional array type
444 Ctyp
:= Etype
(Comp
);
446 if not Is_Array_Type
(Ctyp
) or else Number_Dimensions
(Ctyp
) > 1 then
450 -- The lower bound must be constant, and the upper bound is a
451 -- discriminant (which is a discriminant of the current record).
453 Ityp
:= Etype
(First_Index
(Ctyp
));
454 Lo
:= Type_Low_Bound
(Ityp
);
455 Hi
:= Type_High_Bound
(Ityp
);
457 if not Compile_Time_Known_Value
(Lo
)
458 or else Nkind
(Hi
) /= N_Identifier
459 or else No
(Entity
(Hi
))
460 or else Ekind
(Entity
(Hi
)) /= E_Discriminant
465 -- We have an array with appropriate bounds
467 Loval
:= Expr_Value
(Lo
);
468 Discr
:= Entity
(Hi
);
469 Dtyp
:= Etype
(Discr
);
471 -- See if the discriminant has a known upper bound
473 Dhi
:= Type_High_Bound
(Dtyp
);
475 if not Compile_Time_Known_Value
(Dhi
) then
479 Dhiv
:= Expr_Value
(Dhi
);
481 -- See if base type of component array has known upper bound
483 Ahi
:= Type_High_Bound
(Etype
(First_Index
(Base_Type
(Ctyp
))));
485 if not Compile_Time_Known_Value
(Ahi
) then
489 Ahiv
:= Expr_Value
(Ahi
);
491 -- The condition for doing the restriction is that the high bound
492 -- of the discriminant is greater than the low bound of the array,
493 -- and is also greater than the high bound of the base type index.
495 if Dhiv
> Loval
and then Dhiv
> Ahiv
then
497 -- We can reset the upper bound of the discriminant type to
498 -- whichever is larger, the low bound of the component, or
499 -- the high bound of the base type array index.
501 -- We build a subtype that is declared as
503 -- subtype Tnn is discr_type range discr_type'First .. max;
505 -- And insert this declaration into the tree. The type of the
506 -- discriminant is then reset to this more restricted subtype.
508 Tnn
:= Make_Temporary
(Loc
, 'T');
510 Insert_Action
(Declaration_Node
(Rtype
),
511 Make_Subtype_Declaration
(Loc
,
512 Defining_Identifier
=> Tnn
,
513 Subtype_Indication
=>
514 Make_Subtype_Indication
(Loc
,
515 Subtype_Mark
=> New_Occurrence_Of
(Dtyp
, Loc
),
517 Make_Range_Constraint
(Loc
,
521 Make_Attribute_Reference
(Loc
,
522 Attribute_Name
=> Name_First
,
523 Prefix
=> New_Occurrence_Of
(Dtyp
, Loc
)),
525 Make_Integer_Literal
(Loc
,
526 Intval
=> UI_Max
(Loval
, Ahiv
)))))));
528 Set_Etype
(Discr
, Tnn
);
532 Next_Component
(Comp
);
534 end Adjust_Discriminants
;
536 ---------------------------
537 -- Build_Array_Init_Proc --
538 ---------------------------
540 procedure Build_Array_Init_Proc
(A_Type
: Entity_Id
; Nod
: Node_Id
) is
541 Comp_Type
: constant Entity_Id
:= Component_Type
(A_Type
);
542 Body_Stmts
: List_Id
;
543 Has_Default_Init
: Boolean;
544 Index_List
: List_Id
;
548 function Init_Component
return List_Id
;
549 -- Create one statement to initialize one array component, designated
550 -- by a full set of indexes.
552 function Init_One_Dimension
(N
: Int
) return List_Id
;
553 -- Create loop to initialize one dimension of the array. The single
554 -- statement in the loop body initializes the inner dimensions if any,
555 -- or else the single component. Note that this procedure is called
556 -- recursively, with N being the dimension to be initialized. A call
557 -- with N greater than the number of dimensions simply generates the
558 -- component initialization, terminating the recursion.
564 function Init_Component
return List_Id
is
569 Make_Indexed_Component
(Loc
,
570 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
571 Expressions
=> Index_List
);
573 if Has_Default_Aspect
(A_Type
) then
574 Set_Assignment_OK
(Comp
);
576 Make_Assignment_Statement
(Loc
,
579 Convert_To
(Comp_Type
,
580 Default_Aspect_Component_Value
(First_Subtype
(A_Type
)))));
582 elsif Needs_Simple_Initialization
(Comp_Type
) then
583 Set_Assignment_OK
(Comp
);
585 Make_Assignment_Statement
(Loc
,
589 (Comp_Type
, Nod
, Component_Size
(A_Type
))));
592 Clean_Task_Names
(Comp_Type
, Proc_Id
);
594 Build_Initialization_Call
595 (Loc
, Comp
, Comp_Type
,
596 In_Init_Proc
=> True,
597 Enclos_Type
=> A_Type
);
601 ------------------------
602 -- Init_One_Dimension --
603 ------------------------
605 function Init_One_Dimension
(N
: Int
) return List_Id
is
609 -- If the component does not need initializing, then there is nothing
610 -- to do here, so we return a null body. This occurs when generating
611 -- the dummy Init_Proc needed for Initialize_Scalars processing.
613 if not Has_Non_Null_Base_Init_Proc
(Comp_Type
)
614 and then not Needs_Simple_Initialization
(Comp_Type
)
615 and then not Has_Task
(Comp_Type
)
616 and then not Has_Default_Aspect
(A_Type
)
618 return New_List
(Make_Null_Statement
(Loc
));
620 -- If all dimensions dealt with, we simply initialize the component
622 elsif N
> Number_Dimensions
(A_Type
) then
623 return Init_Component
;
625 -- Here we generate the required loop
629 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
631 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
634 Make_Implicit_Loop_Statement
(Nod
,
637 Make_Iteration_Scheme
(Loc
,
638 Loop_Parameter_Specification
=>
639 Make_Loop_Parameter_Specification
(Loc
,
640 Defining_Identifier
=> Index
,
641 Discrete_Subtype_Definition
=>
642 Make_Attribute_Reference
(Loc
,
644 Make_Identifier
(Loc
, Name_uInit
),
645 Attribute_Name
=> Name_Range
,
646 Expressions
=> New_List
(
647 Make_Integer_Literal
(Loc
, N
))))),
648 Statements
=> Init_One_Dimension
(N
+ 1)));
650 end Init_One_Dimension
;
652 -- Start of processing for Build_Array_Init_Proc
655 -- The init proc is created when analyzing the freeze node for the type,
656 -- but it properly belongs with the array type declaration. However, if
657 -- the freeze node is for a subtype of a type declared in another unit
658 -- it seems preferable to use the freeze node as the source location of
659 -- the init proc. In any case this is preferable for gcov usage, and
660 -- the Sloc is not otherwise used by the compiler.
662 if In_Open_Scopes
(Scope
(A_Type
)) then
663 Loc
:= Sloc
(A_Type
);
668 -- Nothing to generate in the following cases:
670 -- 1. Initialization is suppressed for the type
671 -- 2. The type is a value type, in the CIL sense.
672 -- 3. The type has CIL/JVM convention.
673 -- 4. An initialization already exists for the base type
675 if Initialization_Suppressed
(A_Type
)
676 or else Is_Value_Type
(Comp_Type
)
677 or else Convention
(A_Type
) = Convention_CIL
678 or else Convention
(A_Type
) = Convention_Java
679 or else Present
(Base_Init_Proc
(A_Type
))
684 Index_List
:= New_List
;
686 -- We need an initialization procedure if any of the following is true:
688 -- 1. The component type has an initialization procedure
689 -- 2. The component type needs simple initialization
690 -- 3. Tasks are present
691 -- 4. The type is marked as a public entity
692 -- 5. The array type has a Default_Component_Value aspect
694 -- The reason for the public entity test is to deal properly with the
695 -- Initialize_Scalars pragma. This pragma can be set in the client and
696 -- not in the declaring package, this means the client will make a call
697 -- to the initialization procedure (because one of conditions 1-3 must
698 -- apply in this case), and we must generate a procedure (even if it is
699 -- null) to satisfy the call in this case.
701 -- Exception: do not build an array init_proc for a type whose root
702 -- type is Standard.String or Standard.Wide_[Wide_]String, since there
703 -- is no place to put the code, and in any case we handle initialization
704 -- of such types (in the Initialize_Scalars case, that's the only time
705 -- the issue arises) in a special manner anyway which does not need an
708 Has_Default_Init
:= Has_Non_Null_Base_Init_Proc
(Comp_Type
)
709 or else Needs_Simple_Initialization
(Comp_Type
)
710 or else Has_Task
(Comp_Type
)
711 or else Has_Default_Aspect
(A_Type
);
714 or else (not Restriction_Active
(No_Initialize_Scalars
)
715 and then Is_Public
(A_Type
)
716 and then not Is_Standard_String_Type
(A_Type
))
719 Make_Defining_Identifier
(Loc
,
720 Chars
=> Make_Init_Proc_Name
(A_Type
));
722 -- If No_Default_Initialization restriction is active, then we don't
723 -- want to build an init_proc, but we need to mark that an init_proc
724 -- would be needed if this restriction was not active (so that we can
725 -- detect attempts to call it), so set a dummy init_proc in place.
726 -- This is only done though when actual default initialization is
727 -- needed (and not done when only Is_Public is True), since otherwise
728 -- objects such as arrays of scalars could be wrongly flagged as
729 -- violating the restriction.
731 if Restriction_Active
(No_Default_Initialization
) then
732 if Has_Default_Init
then
733 Set_Init_Proc
(A_Type
, Proc_Id
);
739 Body_Stmts
:= Init_One_Dimension
(1);
742 Make_Subprogram_Body
(Loc
,
744 Make_Procedure_Specification
(Loc
,
745 Defining_Unit_Name
=> Proc_Id
,
746 Parameter_Specifications
=> Init_Formals
(A_Type
)),
747 Declarations
=> New_List
,
748 Handled_Statement_Sequence
=>
749 Make_Handled_Sequence_Of_Statements
(Loc
,
750 Statements
=> Body_Stmts
)));
752 Set_Ekind
(Proc_Id
, E_Procedure
);
753 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
754 Set_Is_Internal
(Proc_Id
);
755 Set_Has_Completion
(Proc_Id
);
757 if not Debug_Generated_Code
then
758 Set_Debug_Info_Off
(Proc_Id
);
761 -- Set inlined unless controlled stuff or tasks around, in which
762 -- case we do not want to inline, because nested stuff may cause
763 -- difficulties in inter-unit inlining, and furthermore there is
764 -- in any case no point in inlining such complex init procs.
766 if not Has_Task
(Proc_Id
)
767 and then not Needs_Finalization
(Proc_Id
)
769 Set_Is_Inlined
(Proc_Id
);
772 -- Associate Init_Proc with type, and determine if the procedure
773 -- is null (happens because of the Initialize_Scalars pragma case,
774 -- where we have to generate a null procedure in case it is called
775 -- by a client with Initialize_Scalars set). Such procedures have
776 -- to be generated, but do not have to be called, so we mark them
777 -- as null to suppress the call.
779 Set_Init_Proc
(A_Type
, Proc_Id
);
781 if List_Length
(Body_Stmts
) = 1
783 -- We must skip SCIL nodes because they may have been added to this
784 -- list by Insert_Actions.
786 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
788 Set_Is_Null_Init_Proc
(Proc_Id
);
791 -- Try to build a static aggregate to statically initialize
792 -- objects of the type. This can only be done for constrained
793 -- one-dimensional arrays with static bounds.
795 Set_Static_Initialization
797 Build_Equivalent_Array_Aggregate
(First_Subtype
(A_Type
)));
800 end Build_Array_Init_Proc
;
802 --------------------------------
803 -- Build_Array_Invariant_Proc --
804 --------------------------------
806 function Build_Array_Invariant_Proc
808 Nod
: Node_Id
) return Node_Id
810 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
812 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
813 -- Name for argument of invariant procedure
815 Object_Entity
: constant Node_Id
:=
816 Make_Defining_Identifier
(Loc
, Object_Name
);
817 -- The procedure declaration entity for the argument
819 Body_Stmts
: List_Id
;
820 Index_List
: List_Id
;
824 function Build_Component_Invariant_Call
return Node_Id
;
825 -- Create one statement to verify invariant on one array component,
826 -- designated by a full set of indexes.
828 function Check_One_Dimension
(N
: Int
) return List_Id
;
829 -- Create loop to check on one dimension of the array. The single
830 -- statement in the loop body checks the inner dimensions if any, or
831 -- else a single component. This procedure is called recursively, with
832 -- N being the dimension to be initialized. A call with N greater than
833 -- the number of dimensions generates the component initialization
834 -- and terminates the recursion.
836 ------------------------------------
837 -- Build_Component_Invariant_Call --
838 ------------------------------------
840 function Build_Component_Invariant_Call
return Node_Id
is
844 Make_Indexed_Component
(Loc
,
845 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
846 Expressions
=> Index_List
);
848 Make_Procedure_Call_Statement
(Loc
,
851 (Invariant_Procedure
(Component_Type
(A_Type
)), Loc
),
852 Parameter_Associations
=> New_List
(Comp
));
853 end Build_Component_Invariant_Call
;
855 -------------------------
856 -- Check_One_Dimension --
857 -------------------------
859 function Check_One_Dimension
(N
: Int
) return List_Id
is
863 -- If all dimensions dealt with, we simply check invariant of the
866 if N
> Number_Dimensions
(A_Type
) then
867 return New_List
(Build_Component_Invariant_Call
);
869 -- Else generate one loop and recurse
873 Make_Defining_Identifier
(Loc
, New_External_Name
('J', N
));
875 Append
(New_Occurrence_Of
(Index
, Loc
), Index_List
);
878 Make_Implicit_Loop_Statement
(Nod
,
881 Make_Iteration_Scheme
(Loc
,
882 Loop_Parameter_Specification
=>
883 Make_Loop_Parameter_Specification
(Loc
,
884 Defining_Identifier
=> Index
,
885 Discrete_Subtype_Definition
=>
886 Make_Attribute_Reference
(Loc
,
888 New_Occurrence_Of
(Object_Entity
, Loc
),
889 Attribute_Name
=> Name_Range
,
890 Expressions
=> New_List
(
891 Make_Integer_Literal
(Loc
, N
))))),
892 Statements
=> Check_One_Dimension
(N
+ 1)));
894 end Check_One_Dimension
;
896 -- Start of processing for Build_Array_Invariant_Proc
899 Index_List
:= New_List
;
902 Make_Defining_Identifier
(Loc
,
903 Chars
=> New_External_Name
(Chars
(A_Type
), "CInvariant"));
905 Body_Stmts
:= Check_One_Dimension
(1);
908 Make_Subprogram_Body
(Loc
,
910 Make_Procedure_Specification
(Loc
,
911 Defining_Unit_Name
=> Proc_Id
,
912 Parameter_Specifications
=> New_List
(
913 Make_Parameter_Specification
(Loc
,
914 Defining_Identifier
=> Object_Entity
,
915 Parameter_Type
=> New_Occurrence_Of
(A_Type
, Loc
)))),
917 Declarations
=> Empty_List
,
918 Handled_Statement_Sequence
=>
919 Make_Handled_Sequence_Of_Statements
(Loc
,
920 Statements
=> Body_Stmts
));
922 Set_Ekind
(Proc_Id
, E_Procedure
);
923 Set_Is_Public
(Proc_Id
, Is_Public
(A_Type
));
924 Set_Is_Internal
(Proc_Id
);
925 Set_Has_Completion
(Proc_Id
);
927 if not Debug_Generated_Code
then
928 Set_Debug_Info_Off
(Proc_Id
);
932 end Build_Array_Invariant_Proc
;
934 --------------------------------
935 -- Build_Discr_Checking_Funcs --
936 --------------------------------
938 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
) is
941 Enclosing_Func_Id
: Entity_Id
;
946 function Build_Case_Statement
947 (Case_Id
: Entity_Id
;
948 Variant
: Node_Id
) return Node_Id
;
949 -- Build a case statement containing only two alternatives. The first
950 -- alternative corresponds exactly to the discrete choices given on the
951 -- variant with contains the components that we are generating the
952 -- checks for. If the discriminant is one of these return False. The
953 -- second alternative is an OTHERS choice that will return True
954 -- indicating the discriminant did not match.
956 function Build_Dcheck_Function
957 (Case_Id
: Entity_Id
;
958 Variant
: Node_Id
) return Entity_Id
;
959 -- Build the discriminant checking function for a given variant
961 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
);
962 -- Builds the discriminant checking function for each variant of the
963 -- given variant part of the record type.
965 --------------------------
966 -- Build_Case_Statement --
967 --------------------------
969 function Build_Case_Statement
970 (Case_Id
: Entity_Id
;
971 Variant
: Node_Id
) return Node_Id
973 Alt_List
: constant List_Id
:= New_List
;
974 Actuals_List
: List_Id
;
976 Case_Alt_Node
: Node_Id
;
978 Choice_List
: List_Id
;
980 Return_Node
: Node_Id
;
983 Case_Node
:= New_Node
(N_Case_Statement
, Loc
);
985 -- Replace the discriminant which controls the variant with the name
986 -- of the formal of the checking function.
988 Set_Expression
(Case_Node
, Make_Identifier
(Loc
, Chars
(Case_Id
)));
990 Choice
:= First
(Discrete_Choices
(Variant
));
992 if Nkind
(Choice
) = N_Others_Choice
then
993 Choice_List
:= New_Copy_List
(Others_Discrete_Choices
(Choice
));
995 Choice_List
:= New_Copy_List
(Discrete_Choices
(Variant
));
998 if not Is_Empty_List
(Choice_List
) then
999 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1000 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1002 -- In case this is a nested variant, we need to return the result
1003 -- of the discriminant checking function for the immediately
1004 -- enclosing variant.
1006 if Present
(Enclosing_Func_Id
) then
1007 Actuals_List
:= New_List
;
1009 D
:= First_Discriminant
(Rec_Id
);
1010 while Present
(D
) loop
1011 Append
(Make_Identifier
(Loc
, Chars
(D
)), Actuals_List
);
1012 Next_Discriminant
(D
);
1016 Make_Simple_Return_Statement
(Loc
,
1018 Make_Function_Call
(Loc
,
1020 New_Occurrence_Of
(Enclosing_Func_Id
, Loc
),
1021 Parameter_Associations
=>
1026 Make_Simple_Return_Statement
(Loc
,
1028 New_Occurrence_Of
(Standard_False
, Loc
));
1031 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1032 Append
(Case_Alt_Node
, Alt_List
);
1035 Case_Alt_Node
:= New_Node
(N_Case_Statement_Alternative
, Loc
);
1036 Choice_List
:= New_List
(New_Node
(N_Others_Choice
, Loc
));
1037 Set_Discrete_Choices
(Case_Alt_Node
, Choice_List
);
1040 Make_Simple_Return_Statement
(Loc
,
1042 New_Occurrence_Of
(Standard_True
, Loc
));
1044 Set_Statements
(Case_Alt_Node
, New_List
(Return_Node
));
1045 Append
(Case_Alt_Node
, Alt_List
);
1047 Set_Alternatives
(Case_Node
, Alt_List
);
1049 end Build_Case_Statement
;
1051 ---------------------------
1052 -- Build_Dcheck_Function --
1053 ---------------------------
1055 function Build_Dcheck_Function
1056 (Case_Id
: Entity_Id
;
1057 Variant
: Node_Id
) return Entity_Id
1059 Body_Node
: Node_Id
;
1060 Func_Id
: Entity_Id
;
1061 Parameter_List
: List_Id
;
1062 Spec_Node
: Node_Id
;
1065 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
1066 Sequence
:= Sequence
+ 1;
1069 Make_Defining_Identifier
(Loc
,
1070 Chars
=> New_External_Name
(Chars
(Rec_Id
), 'D', Sequence
));
1071 Set_Is_Discriminant_Check_Function
(Func_Id
);
1073 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
1074 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
1076 Parameter_List
:= Build_Discriminant_Formals
(Rec_Id
, False);
1078 Set_Parameter_Specifications
(Spec_Node
, Parameter_List
);
1079 Set_Result_Definition
(Spec_Node
,
1080 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1081 Set_Specification
(Body_Node
, Spec_Node
);
1082 Set_Declarations
(Body_Node
, New_List
);
1084 Set_Handled_Statement_Sequence
(Body_Node
,
1085 Make_Handled_Sequence_Of_Statements
(Loc
,
1086 Statements
=> New_List
(
1087 Build_Case_Statement
(Case_Id
, Variant
))));
1089 Set_Ekind
(Func_Id
, E_Function
);
1090 Set_Mechanism
(Func_Id
, Default_Mechanism
);
1091 Set_Is_Inlined
(Func_Id
, True);
1092 Set_Is_Pure
(Func_Id
, True);
1093 Set_Is_Public
(Func_Id
, Is_Public
(Rec_Id
));
1094 Set_Is_Internal
(Func_Id
, True);
1096 if not Debug_Generated_Code
then
1097 Set_Debug_Info_Off
(Func_Id
);
1100 Analyze
(Body_Node
);
1102 Append_Freeze_Action
(Rec_Id
, Body_Node
);
1103 Set_Dcheck_Function
(Variant
, Func_Id
);
1105 end Build_Dcheck_Function
;
1107 ----------------------------
1108 -- Build_Dcheck_Functions --
1109 ----------------------------
1111 procedure Build_Dcheck_Functions
(Variant_Part_Node
: Node_Id
) is
1112 Component_List_Node
: Node_Id
;
1114 Discr_Name
: Entity_Id
;
1115 Func_Id
: Entity_Id
;
1117 Saved_Enclosing_Func_Id
: Entity_Id
;
1120 -- Build the discriminant-checking function for each variant, and
1121 -- label all components of that variant with the function's name.
1122 -- We only Generate a discriminant-checking function when the
1123 -- variant is not empty, to prevent the creation of dead code.
1124 -- The exception to that is when Frontend_Layout_On_Target is set,
1125 -- because the variant record size function generated in package
1126 -- Layout needs to generate calls to all discriminant-checking
1127 -- functions, including those for empty variants.
1129 Discr_Name
:= Entity
(Name
(Variant_Part_Node
));
1130 Variant
:= First_Non_Pragma
(Variants
(Variant_Part_Node
));
1132 while Present
(Variant
) loop
1133 Component_List_Node
:= Component_List
(Variant
);
1135 if not Null_Present
(Component_List_Node
)
1136 or else Frontend_Layout_On_Target
1138 Func_Id
:= Build_Dcheck_Function
(Discr_Name
, Variant
);
1140 First_Non_Pragma
(Component_Items
(Component_List_Node
));
1142 while Present
(Decl
) loop
1143 Set_Discriminant_Checking_Func
1144 (Defining_Identifier
(Decl
), Func_Id
);
1146 Next_Non_Pragma
(Decl
);
1149 if Present
(Variant_Part
(Component_List_Node
)) then
1150 Saved_Enclosing_Func_Id
:= Enclosing_Func_Id
;
1151 Enclosing_Func_Id
:= Func_Id
;
1152 Build_Dcheck_Functions
(Variant_Part
(Component_List_Node
));
1153 Enclosing_Func_Id
:= Saved_Enclosing_Func_Id
;
1157 Next_Non_Pragma
(Variant
);
1159 end Build_Dcheck_Functions
;
1161 -- Start of processing for Build_Discr_Checking_Funcs
1164 -- Only build if not done already
1166 if not Discr_Check_Funcs_Built
(N
) then
1167 Type_Def
:= Type_Definition
(N
);
1169 if Nkind
(Type_Def
) = N_Record_Definition
then
1170 if No
(Component_List
(Type_Def
)) then -- null record.
1173 V
:= Variant_Part
(Component_List
(Type_Def
));
1176 else pragma Assert
(Nkind
(Type_Def
) = N_Derived_Type_Definition
);
1177 if No
(Component_List
(Record_Extension_Part
(Type_Def
))) then
1181 (Component_List
(Record_Extension_Part
(Type_Def
)));
1185 Rec_Id
:= Defining_Identifier
(N
);
1187 if Present
(V
) and then not Is_Unchecked_Union
(Rec_Id
) then
1189 Enclosing_Func_Id
:= Empty
;
1190 Build_Dcheck_Functions
(V
);
1193 Set_Discr_Check_Funcs_Built
(N
);
1195 end Build_Discr_Checking_Funcs
;
1197 --------------------------------
1198 -- Build_Discriminant_Formals --
1199 --------------------------------
1201 function Build_Discriminant_Formals
1202 (Rec_Id
: Entity_Id
;
1203 Use_Dl
: Boolean) return List_Id
1205 Loc
: Source_Ptr
:= Sloc
(Rec_Id
);
1206 Parameter_List
: constant List_Id
:= New_List
;
1209 Formal_Type
: Entity_Id
;
1210 Param_Spec_Node
: Node_Id
;
1213 if Has_Discriminants
(Rec_Id
) then
1214 D
:= First_Discriminant
(Rec_Id
);
1215 while Present
(D
) loop
1219 Formal
:= Discriminal
(D
);
1220 Formal_Type
:= Etype
(Formal
);
1222 Formal
:= Make_Defining_Identifier
(Loc
, Chars
(D
));
1223 Formal_Type
:= Etype
(D
);
1227 Make_Parameter_Specification
(Loc
,
1228 Defining_Identifier
=> Formal
,
1230 New_Occurrence_Of
(Formal_Type
, Loc
));
1231 Append
(Param_Spec_Node
, Parameter_List
);
1232 Next_Discriminant
(D
);
1236 return Parameter_List
;
1237 end Build_Discriminant_Formals
;
1239 --------------------------------------
1240 -- Build_Equivalent_Array_Aggregate --
1241 --------------------------------------
1243 function Build_Equivalent_Array_Aggregate
(T
: Entity_Id
) return Node_Id
is
1244 Loc
: constant Source_Ptr
:= Sloc
(T
);
1245 Comp_Type
: constant Entity_Id
:= Component_Type
(T
);
1246 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(T
));
1247 Proc
: constant Entity_Id
:= Base_Init_Proc
(T
);
1253 if not Is_Constrained
(T
)
1254 or else Number_Dimensions
(T
) > 1
1257 Initialization_Warning
(T
);
1261 Lo
:= Type_Low_Bound
(Index_Type
);
1262 Hi
:= Type_High_Bound
(Index_Type
);
1264 if not Compile_Time_Known_Value
(Lo
)
1265 or else not Compile_Time_Known_Value
(Hi
)
1267 Initialization_Warning
(T
);
1271 if Is_Record_Type
(Comp_Type
)
1272 and then Present
(Base_Init_Proc
(Comp_Type
))
1274 Expr
:= Static_Initialization
(Base_Init_Proc
(Comp_Type
));
1277 Initialization_Warning
(T
);
1282 Initialization_Warning
(T
);
1286 Aggr
:= Make_Aggregate
(Loc
, No_List
, New_List
);
1287 Set_Etype
(Aggr
, T
);
1288 Set_Aggregate_Bounds
(Aggr
,
1290 Low_Bound
=> New_Copy
(Lo
),
1291 High_Bound
=> New_Copy
(Hi
)));
1292 Set_Parent
(Aggr
, Parent
(Proc
));
1294 Append_To
(Component_Associations
(Aggr
),
1295 Make_Component_Association
(Loc
,
1299 Low_Bound
=> New_Copy
(Lo
),
1300 High_Bound
=> New_Copy
(Hi
))),
1301 Expression
=> Expr
));
1303 if Static_Array_Aggregate
(Aggr
) then
1306 Initialization_Warning
(T
);
1309 end Build_Equivalent_Array_Aggregate
;
1311 ---------------------------------------
1312 -- Build_Equivalent_Record_Aggregate --
1313 ---------------------------------------
1315 function Build_Equivalent_Record_Aggregate
(T
: Entity_Id
) return Node_Id
is
1318 Comp_Type
: Entity_Id
;
1320 -- Start of processing for Build_Equivalent_Record_Aggregate
1323 if not Is_Record_Type
(T
)
1324 or else Has_Discriminants
(T
)
1325 or else Is_Limited_Type
(T
)
1326 or else Has_Non_Standard_Rep
(T
)
1328 Initialization_Warning
(T
);
1332 Comp
:= First_Component
(T
);
1334 -- A null record needs no warning
1340 while Present
(Comp
) loop
1342 -- Array components are acceptable if initialized by a positional
1343 -- aggregate with static components.
1345 if Is_Array_Type
(Etype
(Comp
)) then
1346 Comp_Type
:= Component_Type
(Etype
(Comp
));
1348 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1349 or else No
(Expression
(Parent
(Comp
)))
1350 or else Nkind
(Expression
(Parent
(Comp
))) /= N_Aggregate
1352 Initialization_Warning
(T
);
1355 elsif Is_Scalar_Type
(Component_Type
(Etype
(Comp
)))
1357 (not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1359 not Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
)))
1361 Initialization_Warning
(T
);
1365 not Static_Array_Aggregate
(Expression
(Parent
(Comp
)))
1367 Initialization_Warning
(T
);
1371 elsif Is_Scalar_Type
(Etype
(Comp
)) then
1372 Comp_Type
:= Etype
(Comp
);
1374 if Nkind
(Parent
(Comp
)) /= N_Component_Declaration
1375 or else No
(Expression
(Parent
(Comp
)))
1376 or else not Compile_Time_Known_Value
(Expression
(Parent
(Comp
)))
1377 or else not Compile_Time_Known_Value
(Type_Low_Bound
(Comp_Type
))
1379 Compile_Time_Known_Value
(Type_High_Bound
(Comp_Type
))
1381 Initialization_Warning
(T
);
1385 -- For now, other types are excluded
1388 Initialization_Warning
(T
);
1392 Next_Component
(Comp
);
1395 -- All components have static initialization. Build positional aggregate
1396 -- from the given expressions or defaults.
1398 Agg
:= Make_Aggregate
(Sloc
(T
), New_List
, New_List
);
1399 Set_Parent
(Agg
, Parent
(T
));
1401 Comp
:= First_Component
(T
);
1402 while Present
(Comp
) loop
1404 (New_Copy_Tree
(Expression
(Parent
(Comp
))), Expressions
(Agg
));
1405 Next_Component
(Comp
);
1408 Analyze_And_Resolve
(Agg
, T
);
1410 end Build_Equivalent_Record_Aggregate
;
1412 -------------------------------
1413 -- Build_Initialization_Call --
1414 -------------------------------
1416 -- References to a discriminant inside the record type declaration can
1417 -- appear either in the subtype_indication to constrain a record or an
1418 -- array, or as part of a larger expression given for the initial value
1419 -- of a component. In both of these cases N appears in the record
1420 -- initialization procedure and needs to be replaced by the formal
1421 -- parameter of the initialization procedure which corresponds to that
1424 -- In the example below, references to discriminants D1 and D2 in proc_1
1425 -- are replaced by references to formals with the same name
1428 -- A similar replacement is done for calls to any record initialization
1429 -- procedure for any components that are themselves of a record type.
1431 -- type R (D1, D2 : Integer) is record
1432 -- X : Integer := F * D1;
1433 -- Y : Integer := F * D2;
1436 -- procedure proc_1 (Out_2 : out R; D1 : Integer; D2 : Integer) is
1440 -- Out_2.X := F * D1;
1441 -- Out_2.Y := F * D2;
1444 function Build_Initialization_Call
1448 In_Init_Proc
: Boolean := False;
1449 Enclos_Type
: Entity_Id
:= Empty
;
1450 Discr_Map
: Elist_Id
:= New_Elmt_List
;
1451 With_Default_Init
: Boolean := False;
1452 Constructor_Ref
: Node_Id
:= Empty
) return List_Id
1454 Res
: constant List_Id
:= New_List
;
1460 First_Arg
: Node_Id
;
1461 Full_Init_Type
: Entity_Id
;
1462 Full_Type
: Entity_Id
:= Typ
;
1463 Init_Type
: Entity_Id
;
1467 pragma Assert
(Constructor_Ref
= Empty
1468 or else Is_CPP_Constructor_Call
(Constructor_Ref
));
1470 if No
(Constructor_Ref
) then
1471 Proc
:= Base_Init_Proc
(Typ
);
1473 Proc
:= Base_Init_Proc
(Typ
, Entity
(Name
(Constructor_Ref
)));
1476 pragma Assert
(Present
(Proc
));
1477 Init_Type
:= Etype
(First_Formal
(Proc
));
1478 Full_Init_Type
:= Underlying_Type
(Init_Type
);
1480 -- Nothing to do if the Init_Proc is null, unless Initialize_Scalars
1481 -- is active (in which case we make the call anyway, since in the
1482 -- actual compiled client it may be non null).
1483 -- Also nothing to do for value types.
1485 if (Is_Null_Init_Proc
(Proc
) and then not Init_Or_Norm_Scalars
)
1486 or else Is_Value_Type
(Typ
)
1488 (Is_Array_Type
(Typ
) and then Is_Value_Type
(Component_Type
(Typ
)))
1493 -- Go to full view or underlying full view if private type. In the case
1494 -- of successive private derivations, this can require two steps.
1496 if Is_Private_Type
(Full_Type
)
1497 and then Present
(Full_View
(Full_Type
))
1499 Full_Type
:= Full_View
(Full_Type
);
1502 if Is_Private_Type
(Full_Type
)
1503 and then Present
(Underlying_Full_View
(Full_Type
))
1505 Full_Type
:= Underlying_Full_View
(Full_Type
);
1508 -- If Typ is derived, the procedure is the initialization procedure for
1509 -- the root type. Wrap the argument in an conversion to make it type
1510 -- honest. Actually it isn't quite type honest, because there can be
1511 -- conflicts of views in the private type case. That is why we set
1512 -- Conversion_OK in the conversion node.
1514 if (Is_Record_Type
(Typ
)
1515 or else Is_Array_Type
(Typ
)
1516 or else Is_Private_Type
(Typ
))
1517 and then Init_Type
/= Base_Type
(Typ
)
1519 First_Arg
:= OK_Convert_To
(Etype
(Init_Type
), Id_Ref
);
1520 Set_Etype
(First_Arg
, Init_Type
);
1523 First_Arg
:= Id_Ref
;
1526 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Typ
));
1528 -- In the tasks case, add _Master as the value of the _Master parameter
1529 -- and _Chain as the value of the _Chain parameter. At the outer level,
1530 -- these will be variables holding the corresponding values obtained
1531 -- from GNARL. At inner levels, they will be the parameters passed down
1532 -- through the outer routines.
1534 if Has_Task
(Full_Type
) then
1535 if Restriction_Active
(No_Task_Hierarchy
) then
1537 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1539 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1542 -- Add _Chain (not done for sequential elaboration policy, see
1543 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1545 if Partition_Elaboration_Policy
/= 'S' then
1546 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1549 -- Ada 2005 (AI-287): In case of default initialized components
1550 -- with tasks, we generate a null string actual parameter.
1551 -- This is just a workaround that must be improved later???
1553 if With_Default_Init
then
1555 Make_String_Literal
(Loc
,
1560 Build_Task_Image_Decls
(Loc
, Id_Ref
, Enclos_Type
, In_Init_Proc
);
1561 Decl
:= Last
(Decls
);
1564 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
));
1565 Append_List
(Decls
, Res
);
1573 -- Add discriminant values if discriminants are present
1575 if Has_Discriminants
(Full_Init_Type
) then
1576 Discr
:= First_Discriminant
(Full_Init_Type
);
1578 while Present
(Discr
) loop
1580 -- If this is a discriminated concurrent type, the init_proc
1581 -- for the corresponding record is being called. Use that type
1582 -- directly to find the discriminant value, to handle properly
1583 -- intervening renamed discriminants.
1586 T
: Entity_Id
:= Full_Type
;
1589 if Is_Protected_Type
(T
) then
1590 T
:= Corresponding_Record_Type
(T
);
1594 Get_Discriminant_Value
(
1597 Discriminant_Constraint
(Full_Type
));
1600 -- If the target has access discriminants, and is constrained by
1601 -- an access to the enclosing construct, i.e. a current instance,
1602 -- replace the reference to the type by a reference to the object.
1604 if Nkind
(Arg
) = N_Attribute_Reference
1605 and then Is_Access_Type
(Etype
(Arg
))
1606 and then Is_Entity_Name
(Prefix
(Arg
))
1607 and then Is_Type
(Entity
(Prefix
(Arg
)))
1610 Make_Attribute_Reference
(Loc
,
1611 Prefix
=> New_Copy
(Prefix
(Id_Ref
)),
1612 Attribute_Name
=> Name_Unrestricted_Access
);
1614 elsif In_Init_Proc
then
1616 -- Replace any possible references to the discriminant in the
1617 -- call to the record initialization procedure with references
1618 -- to the appropriate formal parameter.
1620 if Nkind
(Arg
) = N_Identifier
1621 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1623 Arg
:= New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
);
1625 -- Otherwise make a copy of the default expression. Note that
1626 -- we use the current Sloc for this, because we do not want the
1627 -- call to appear to be at the declaration point. Within the
1628 -- expression, replace discriminants with their discriminals.
1632 New_Copy_Tree
(Arg
, Map
=> Discr_Map
, New_Sloc
=> Loc
);
1636 if Is_Constrained
(Full_Type
) then
1637 Arg
:= Duplicate_Subexpr_No_Checks
(Arg
);
1639 -- The constraints come from the discriminant default exps,
1640 -- they must be reevaluated, so we use New_Copy_Tree but we
1641 -- ensure the proper Sloc (for any embedded calls).
1643 Arg
:= New_Copy_Tree
(Arg
, New_Sloc
=> Loc
);
1647 -- Ada 2005 (AI-287): In case of default initialized components,
1648 -- if the component is constrained with a discriminant of the
1649 -- enclosing type, we need to generate the corresponding selected
1650 -- component node to access the discriminant value. In other cases
1651 -- this is not required, either because we are inside the init
1652 -- proc and we use the corresponding formal, or else because the
1653 -- component is constrained by an expression.
1655 if With_Default_Init
1656 and then Nkind
(Id_Ref
) = N_Selected_Component
1657 and then Nkind
(Arg
) = N_Identifier
1658 and then Ekind
(Entity
(Arg
)) = E_Discriminant
1661 Make_Selected_Component
(Loc
,
1662 Prefix
=> New_Copy_Tree
(Prefix
(Id_Ref
)),
1663 Selector_Name
=> Arg
));
1665 Append_To
(Args
, Arg
);
1668 Next_Discriminant
(Discr
);
1672 -- If this is a call to initialize the parent component of a derived
1673 -- tagged type, indicate that the tag should not be set in the parent.
1675 if Is_Tagged_Type
(Full_Init_Type
)
1676 and then not Is_CPP_Class
(Full_Init_Type
)
1677 and then Nkind
(Id_Ref
) = N_Selected_Component
1678 and then Chars
(Selector_Name
(Id_Ref
)) = Name_uParent
1680 Append_To
(Args
, New_Occurrence_Of
(Standard_False
, Loc
));
1682 elsif Present
(Constructor_Ref
) then
1683 Append_List_To
(Args
,
1684 New_Copy_List
(Parameter_Associations
(Constructor_Ref
)));
1688 Make_Procedure_Call_Statement
(Loc
,
1689 Name
=> New_Occurrence_Of
(Proc
, Loc
),
1690 Parameter_Associations
=> Args
));
1692 if Needs_Finalization
(Typ
)
1693 and then Nkind
(Id_Ref
) = N_Selected_Component
1695 if Chars
(Selector_Name
(Id_Ref
)) /= Name_uParent
then
1698 (Obj_Ref
=> New_Copy_Tree
(First_Arg
),
1706 when RE_Not_Available
=>
1708 end Build_Initialization_Call
;
1710 ----------------------------
1711 -- Build_Record_Init_Proc --
1712 ----------------------------
1714 procedure Build_Record_Init_Proc
(N
: Node_Id
; Rec_Ent
: Entity_Id
) is
1715 Decls
: constant List_Id
:= New_List
;
1716 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
1717 Loc
: constant Source_Ptr
:= Sloc
(Rec_Ent
);
1719 Proc_Id
: Entity_Id
;
1720 Rec_Type
: Entity_Id
;
1721 Set_Tag
: Entity_Id
:= Empty
;
1723 function Build_Assignment
(Id
: Entity_Id
; N
: Node_Id
) return List_Id
;
1724 -- Build an assignment statement which assigns the default expression
1725 -- to its corresponding record component if defined. The left hand side
1726 -- of the assignment is marked Assignment_OK so that initialization of
1727 -- limited private records works correctly. This routine may also build
1728 -- an adjustment call if the component is controlled.
1730 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
);
1731 -- If the record has discriminants, add assignment statements to
1732 -- Statement_List to initialize the discriminant values from the
1733 -- arguments of the initialization procedure.
1735 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
;
1736 -- Build a list representing a sequence of statements which initialize
1737 -- components of the given component list. This may involve building
1738 -- case statements for the variant parts. Append any locally declared
1739 -- objects on list Decls.
1741 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
;
1742 -- Given an untagged type-derivation that declares discriminants, e.g.
1744 -- type R (R1, R2 : Integer) is record ... end record;
1745 -- type D (D1 : Integer) is new R (1, D1);
1747 -- we make the _init_proc of D be
1749 -- procedure _init_proc (X : D; D1 : Integer) is
1751 -- _init_proc (R (X), 1, D1);
1754 -- This function builds the call statement in this _init_proc.
1756 procedure Build_CPP_Init_Procedure
;
1757 -- Build the tree corresponding to the procedure specification and body
1758 -- of the IC procedure that initializes the C++ part of the dispatch
1759 -- table of an Ada tagged type that is a derivation of a CPP type.
1760 -- Install it as the CPP_Init TSS.
1762 procedure Build_Init_Procedure
;
1763 -- Build the tree corresponding to the procedure specification and body
1764 -- of the initialization procedure and install it as the _init TSS.
1766 procedure Build_Offset_To_Top_Functions
;
1767 -- Ada 2005 (AI-251): Build the tree corresponding to the procedure spec
1768 -- and body of Offset_To_Top, a function used in conjuction with types
1769 -- having secondary dispatch tables.
1771 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
);
1772 -- Add range checks to components of discriminated records. S is a
1773 -- subtype indication of a record component. Check_List is a list
1774 -- to which the check actions are appended.
1776 function Component_Needs_Simple_Initialization
1777 (T
: Entity_Id
) return Boolean;
1778 -- Determine if a component needs simple initialization, given its type
1779 -- T. This routine is the same as Needs_Simple_Initialization except for
1780 -- components of type Tag and Interface_Tag. These two access types do
1781 -- not require initialization since they are explicitly initialized by
1784 function Parent_Subtype_Renaming_Discrims
return Boolean;
1785 -- Returns True for base types N that rename discriminants, else False
1787 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean;
1788 -- Determine whether a record initialization procedure needs to be
1789 -- generated for the given record type.
1791 ----------------------
1792 -- Build_Assignment --
1793 ----------------------
1795 function Build_Assignment
(Id
: Entity_Id
; N
: Node_Id
) return List_Id
is
1796 N_Loc
: constant Source_Ptr
:= Sloc
(N
);
1797 Typ
: constant Entity_Id
:= Underlying_Type
(Etype
(Id
));
1799 Kind
: Node_Kind
:= Nkind
(N
);
1805 Make_Selected_Component
(N_Loc
,
1806 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
1807 Selector_Name
=> New_Occurrence_Of
(Id
, N_Loc
));
1808 Set_Assignment_OK
(Lhs
);
1810 -- Case of an access attribute applied to the current instance.
1811 -- Replace the reference to the type by a reference to the actual
1812 -- object. (Note that this handles the case of the top level of
1813 -- the expression being given by such an attribute, but does not
1814 -- cover uses nested within an initial value expression. Nested
1815 -- uses are unlikely to occur in practice, but are theoretically
1816 -- possible.) It is not clear how to handle them without fully
1817 -- traversing the expression. ???
1819 if Kind
= N_Attribute_Reference
1820 and then Nam_In
(Attribute_Name
(N
), Name_Unchecked_Access
,
1821 Name_Unrestricted_Access
)
1822 and then Is_Entity_Name
(Prefix
(N
))
1823 and then Is_Type
(Entity
(Prefix
(N
)))
1824 and then Entity
(Prefix
(N
)) = Rec_Type
1827 Make_Attribute_Reference
(N_Loc
,
1829 Make_Identifier
(N_Loc
, Name_uInit
),
1830 Attribute_Name
=> Name_Unrestricted_Access
);
1833 -- Take a copy of Exp to ensure that later copies of this component
1834 -- declaration in derived types see the original tree, not a node
1835 -- rewritten during expansion of the init_proc. If the copy contains
1836 -- itypes, the scope of the new itypes is the init_proc being built.
1838 Exp
:= New_Copy_Tree
(Exp
, New_Scope
=> Proc_Id
);
1841 Make_Assignment_Statement
(Loc
,
1843 Expression
=> Exp
));
1845 Set_No_Ctrl_Actions
(First
(Res
));
1847 -- Adjust the tag if tagged (because of possible view conversions).
1848 -- Suppress the tag adjustment when VM_Target because VM tags are
1849 -- represented implicitly in objects.
1851 if Is_Tagged_Type
(Typ
) and then Tagged_Type_Expansion
then
1853 Make_Assignment_Statement
(N_Loc
,
1855 Make_Selected_Component
(N_Loc
,
1857 New_Copy_Tree
(Lhs
, New_Scope
=> Proc_Id
),
1859 New_Occurrence_Of
(First_Tag_Component
(Typ
), N_Loc
)),
1862 Unchecked_Convert_To
(RTE
(RE_Tag
),
1866 (Access_Disp_Table
(Underlying_Type
(Typ
)))),
1870 -- Adjust the component if controlled except if it is an aggregate
1871 -- that will be expanded inline.
1873 if Kind
= N_Qualified_Expression
then
1874 Kind
:= Nkind
(Expression
(N
));
1877 if Needs_Finalization
(Typ
)
1878 and then not (Nkind_In
(Kind
, N_Aggregate
, N_Extension_Aggregate
))
1879 and then not Is_Limited_View
(Typ
)
1883 (Obj_Ref
=> New_Copy_Tree
(Lhs
),
1884 Typ
=> Etype
(Id
)));
1890 when RE_Not_Available
=>
1892 end Build_Assignment
;
1894 ------------------------------------
1895 -- Build_Discriminant_Assignments --
1896 ------------------------------------
1898 procedure Build_Discriminant_Assignments
(Statement_List
: List_Id
) is
1899 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Rec_Type
);
1904 if Has_Discriminants
(Rec_Type
)
1905 and then not Is_Unchecked_Union
(Rec_Type
)
1907 D
:= First_Discriminant
(Rec_Type
);
1908 while Present
(D
) loop
1910 -- Don't generate the assignment for discriminants in derived
1911 -- tagged types if the discriminant is a renaming of some
1912 -- ancestor discriminant. This initialization will be done
1913 -- when initializing the _parent field of the derived record.
1916 and then Present
(Corresponding_Discriminant
(D
))
1922 Append_List_To
(Statement_List
,
1923 Build_Assignment
(D
,
1924 New_Occurrence_Of
(Discriminal
(D
), D_Loc
)));
1927 Next_Discriminant
(D
);
1930 end Build_Discriminant_Assignments
;
1932 --------------------------
1933 -- Build_Init_Call_Thru --
1934 --------------------------
1936 function Build_Init_Call_Thru
(Parameters
: List_Id
) return List_Id
is
1937 Parent_Proc
: constant Entity_Id
:=
1938 Base_Init_Proc
(Etype
(Rec_Type
));
1940 Parent_Type
: constant Entity_Id
:=
1941 Etype
(First_Formal
(Parent_Proc
));
1943 Uparent_Type
: constant Entity_Id
:=
1944 Underlying_Type
(Parent_Type
);
1946 First_Discr_Param
: Node_Id
;
1950 First_Arg
: Node_Id
;
1951 Parent_Discr
: Entity_Id
;
1955 -- First argument (_Init) is the object to be initialized.
1956 -- ??? not sure where to get a reasonable Loc for First_Arg
1959 OK_Convert_To
(Parent_Type
,
1961 (Defining_Identifier
(First
(Parameters
)), Loc
));
1963 Set_Etype
(First_Arg
, Parent_Type
);
1965 Args
:= New_List
(Convert_Concurrent
(First_Arg
, Rec_Type
));
1967 -- In the tasks case,
1968 -- add _Master as the value of the _Master parameter
1969 -- add _Chain as the value of the _Chain parameter.
1970 -- add _Task_Name as the value of the _Task_Name parameter.
1971 -- At the outer level, these will be variables holding the
1972 -- corresponding values obtained from GNARL or the expander.
1974 -- At inner levels, they will be the parameters passed down through
1975 -- the outer routines.
1977 First_Discr_Param
:= Next
(First
(Parameters
));
1979 if Has_Task
(Rec_Type
) then
1980 if Restriction_Active
(No_Task_Hierarchy
) then
1982 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
1984 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
1987 -- Add _Chain (not done for sequential elaboration policy, see
1988 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
1990 if Partition_Elaboration_Policy
/= 'S' then
1991 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
1994 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
1995 First_Discr_Param
:= Next
(Next
(Next
(First_Discr_Param
)));
1998 -- Append discriminant values
2000 if Has_Discriminants
(Uparent_Type
) then
2001 pragma Assert
(not Is_Tagged_Type
(Uparent_Type
));
2003 Parent_Discr
:= First_Discriminant
(Uparent_Type
);
2004 while Present
(Parent_Discr
) loop
2006 -- Get the initial value for this discriminant
2007 -- ??? needs to be cleaned up to use parent_Discr_Constr
2011 Discr
: Entity_Id
:=
2012 First_Stored_Discriminant
(Uparent_Type
);
2014 Discr_Value
: Elmt_Id
:=
2015 First_Elmt
(Stored_Constraint
(Rec_Type
));
2018 while Original_Record_Component
(Parent_Discr
) /= Discr
loop
2019 Next_Stored_Discriminant
(Discr
);
2020 Next_Elmt
(Discr_Value
);
2023 Arg
:= Node
(Discr_Value
);
2026 -- Append it to the list
2028 if Nkind
(Arg
) = N_Identifier
2029 and then Ekind
(Entity
(Arg
)) = E_Discriminant
2032 New_Occurrence_Of
(Discriminal
(Entity
(Arg
)), Loc
));
2034 -- Case of access discriminants. We replace the reference
2035 -- to the type by a reference to the actual object.
2037 -- Is above comment right??? Use of New_Copy below seems mighty
2041 Append_To
(Args
, New_Copy
(Arg
));
2044 Next_Discriminant
(Parent_Discr
);
2050 Make_Procedure_Call_Statement
(Loc
,
2052 New_Occurrence_Of
(Parent_Proc
, Loc
),
2053 Parameter_Associations
=> Args
));
2056 end Build_Init_Call_Thru
;
2058 -----------------------------------
2059 -- Build_Offset_To_Top_Functions --
2060 -----------------------------------
2062 procedure Build_Offset_To_Top_Functions
is
2064 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
);
2066 -- function Fxx (O : Address) return Storage_Offset is
2067 -- type Acc is access all <Typ>;
2069 -- return Acc!(O).Iface_Comp'Position;
2072 ----------------------------------
2073 -- Build_Offset_To_Top_Function --
2074 ----------------------------------
2076 procedure Build_Offset_To_Top_Function
(Iface_Comp
: Entity_Id
) is
2077 Body_Node
: Node_Id
;
2078 Func_Id
: Entity_Id
;
2079 Spec_Node
: Node_Id
;
2080 Acc_Type
: Entity_Id
;
2083 Func_Id
:= Make_Temporary
(Loc
, 'F');
2084 Set_DT_Offset_To_Top_Func
(Iface_Comp
, Func_Id
);
2087 -- function Fxx (O : in Rec_Typ) return Storage_Offset;
2089 Spec_Node
:= New_Node
(N_Function_Specification
, Loc
);
2090 Set_Defining_Unit_Name
(Spec_Node
, Func_Id
);
2091 Set_Parameter_Specifications
(Spec_Node
, New_List
(
2092 Make_Parameter_Specification
(Loc
,
2093 Defining_Identifier
=>
2094 Make_Defining_Identifier
(Loc
, Name_uO
),
2097 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))));
2098 Set_Result_Definition
(Spec_Node
,
2099 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
2102 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2104 -- return O.Iface_Comp'Position;
2107 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2108 Set_Specification
(Body_Node
, Spec_Node
);
2110 Acc_Type
:= Make_Temporary
(Loc
, 'T');
2111 Set_Declarations
(Body_Node
, New_List
(
2112 Make_Full_Type_Declaration
(Loc
,
2113 Defining_Identifier
=> Acc_Type
,
2115 Make_Access_To_Object_Definition
(Loc
,
2116 All_Present
=> True,
2117 Null_Exclusion_Present
=> False,
2118 Constant_Present
=> False,
2119 Subtype_Indication
=>
2120 New_Occurrence_Of
(Rec_Type
, Loc
)))));
2122 Set_Handled_Statement_Sequence
(Body_Node
,
2123 Make_Handled_Sequence_Of_Statements
(Loc
,
2124 Statements
=> New_List
(
2125 Make_Simple_Return_Statement
(Loc
,
2127 Make_Attribute_Reference
(Loc
,
2129 Make_Selected_Component
(Loc
,
2131 Unchecked_Convert_To
(Acc_Type
,
2132 Make_Identifier
(Loc
, Name_uO
)),
2134 New_Occurrence_Of
(Iface_Comp
, Loc
)),
2135 Attribute_Name
=> Name_Position
)))));
2137 Set_Ekind
(Func_Id
, E_Function
);
2138 Set_Mechanism
(Func_Id
, Default_Mechanism
);
2139 Set_Is_Internal
(Func_Id
, True);
2141 if not Debug_Generated_Code
then
2142 Set_Debug_Info_Off
(Func_Id
);
2145 Analyze
(Body_Node
);
2147 Append_Freeze_Action
(Rec_Type
, Body_Node
);
2148 end Build_Offset_To_Top_Function
;
2152 Iface_Comp
: Node_Id
;
2153 Iface_Comp_Elmt
: Elmt_Id
;
2154 Ifaces_Comp_List
: Elist_Id
;
2156 -- Start of processing for Build_Offset_To_Top_Functions
2159 -- Offset_To_Top_Functions are built only for derivations of types
2160 -- with discriminants that cover interface types.
2161 -- Nothing is needed either in case of virtual machines, since
2162 -- interfaces are handled directly by the VM.
2164 if not Is_Tagged_Type
(Rec_Type
)
2165 or else Etype
(Rec_Type
) = Rec_Type
2166 or else not Has_Discriminants
(Etype
(Rec_Type
))
2167 or else not Tagged_Type_Expansion
2172 Collect_Interface_Components
(Rec_Type
, Ifaces_Comp_List
);
2174 -- For each interface type with secondary dispatch table we generate
2175 -- the Offset_To_Top_Functions (required to displace the pointer in
2176 -- interface conversions)
2178 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
2179 while Present
(Iface_Comp_Elmt
) loop
2180 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
2181 pragma Assert
(Is_Interface
(Related_Type
(Iface_Comp
)));
2183 -- If the interface is a parent of Rec_Type it shares the primary
2184 -- dispatch table and hence there is no need to build the function
2186 if not Is_Ancestor
(Related_Type
(Iface_Comp
), Rec_Type
,
2187 Use_Full_View
=> True)
2189 Build_Offset_To_Top_Function
(Iface_Comp
);
2192 Next_Elmt
(Iface_Comp_Elmt
);
2194 end Build_Offset_To_Top_Functions
;
2196 ------------------------------
2197 -- Build_CPP_Init_Procedure --
2198 ------------------------------
2200 procedure Build_CPP_Init_Procedure
is
2201 Body_Node
: Node_Id
;
2202 Body_Stmts
: List_Id
;
2203 Flag_Id
: Entity_Id
;
2204 Handled_Stmt_Node
: Node_Id
;
2205 Init_Tags_List
: List_Id
;
2206 Proc_Id
: Entity_Id
;
2207 Proc_Spec_Node
: Node_Id
;
2210 -- Check cases requiring no IC routine
2212 if not Is_CPP_Class
(Root_Type
(Rec_Type
))
2213 or else Is_CPP_Class
(Rec_Type
)
2214 or else CPP_Num_Prims
(Rec_Type
) = 0
2215 or else not Tagged_Type_Expansion
2216 or else No_Run_Time_Mode
2223 -- Flag : Boolean := False;
2225 -- procedure Typ_IC is
2228 -- Copy C++ dispatch table slots from parent
2229 -- Update C++ slots of overridden primitives
2233 Flag_Id
:= Make_Temporary
(Loc
, 'F');
2235 Append_Freeze_Action
(Rec_Type
,
2236 Make_Object_Declaration
(Loc
,
2237 Defining_Identifier
=> Flag_Id
,
2238 Object_Definition
=>
2239 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2241 New_Occurrence_Of
(Standard_True
, Loc
)));
2243 Body_Stmts
:= New_List
;
2244 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2246 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2249 Make_Defining_Identifier
(Loc
,
2250 Chars
=> Make_TSS_Name
(Rec_Type
, TSS_CPP_Init_Proc
));
2252 Set_Ekind
(Proc_Id
, E_Procedure
);
2253 Set_Is_Internal
(Proc_Id
);
2255 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2257 Set_Parameter_Specifications
(Proc_Spec_Node
, New_List
);
2258 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2259 Set_Declarations
(Body_Node
, New_List
);
2261 Init_Tags_List
:= Build_Inherit_CPP_Prims
(Rec_Type
);
2263 Append_To
(Init_Tags_List
,
2264 Make_Assignment_Statement
(Loc
,
2266 New_Occurrence_Of
(Flag_Id
, Loc
),
2268 New_Occurrence_Of
(Standard_False
, Loc
)));
2270 Append_To
(Body_Stmts
,
2271 Make_If_Statement
(Loc
,
2272 Condition
=> New_Occurrence_Of
(Flag_Id
, Loc
),
2273 Then_Statements
=> Init_Tags_List
));
2275 Handled_Stmt_Node
:=
2276 New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2277 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2278 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2279 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2281 if not Debug_Generated_Code
then
2282 Set_Debug_Info_Off
(Proc_Id
);
2285 -- Associate CPP_Init_Proc with type
2287 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2288 end Build_CPP_Init_Procedure
;
2290 --------------------------
2291 -- Build_Init_Procedure --
2292 --------------------------
2294 procedure Build_Init_Procedure
is
2295 Body_Stmts
: List_Id
;
2296 Body_Node
: Node_Id
;
2297 Handled_Stmt_Node
: Node_Id
;
2298 Init_Tags_List
: List_Id
;
2299 Parameters
: List_Id
;
2300 Proc_Spec_Node
: Node_Id
;
2301 Record_Extension_Node
: Node_Id
;
2304 Body_Stmts
:= New_List
;
2305 Body_Node
:= New_Node
(N_Subprogram_Body
, Loc
);
2306 Set_Ekind
(Proc_Id
, E_Procedure
);
2308 Proc_Spec_Node
:= New_Node
(N_Procedure_Specification
, Loc
);
2309 Set_Defining_Unit_Name
(Proc_Spec_Node
, Proc_Id
);
2311 Parameters
:= Init_Formals
(Rec_Type
);
2312 Append_List_To
(Parameters
,
2313 Build_Discriminant_Formals
(Rec_Type
, True));
2315 -- For tagged types, we add a flag to indicate whether the routine
2316 -- is called to initialize a parent component in the init_proc of
2317 -- a type extension. If the flag is false, we do not set the tag
2318 -- because it has been set already in the extension.
2320 if Is_Tagged_Type
(Rec_Type
) then
2321 Set_Tag
:= Make_Temporary
(Loc
, 'P');
2323 Append_To
(Parameters
,
2324 Make_Parameter_Specification
(Loc
,
2325 Defining_Identifier
=> Set_Tag
,
2327 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2329 New_Occurrence_Of
(Standard_True
, Loc
)));
2332 Set_Parameter_Specifications
(Proc_Spec_Node
, Parameters
);
2333 Set_Specification
(Body_Node
, Proc_Spec_Node
);
2334 Set_Declarations
(Body_Node
, Decls
);
2336 -- N is a Derived_Type_Definition that renames the parameters of the
2337 -- ancestor type. We initialize it by expanding our discriminants and
2338 -- call the ancestor _init_proc with a type-converted object.
2340 if Parent_Subtype_Renaming_Discrims
then
2341 Append_List_To
(Body_Stmts
, Build_Init_Call_Thru
(Parameters
));
2343 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
2344 Build_Discriminant_Assignments
(Body_Stmts
);
2346 if not Null_Present
(Type_Definition
(N
)) then
2347 Append_List_To
(Body_Stmts
,
2348 Build_Init_Statements
(Component_List
(Type_Definition
(N
))));
2351 -- N is a Derived_Type_Definition with a possible non-empty
2352 -- extension. The initialization of a type extension consists in the
2353 -- initialization of the components in the extension.
2356 Build_Discriminant_Assignments
(Body_Stmts
);
2358 Record_Extension_Node
:=
2359 Record_Extension_Part
(Type_Definition
(N
));
2361 if not Null_Present
(Record_Extension_Node
) then
2363 Stmts
: constant List_Id
:=
2364 Build_Init_Statements
(
2365 Component_List
(Record_Extension_Node
));
2368 -- The parent field must be initialized first because the
2369 -- offset of the new discriminants may depend on it. This is
2370 -- not needed if the parent is an interface type because in
2371 -- such case the initialization of the _parent field was not
2374 if not Is_Interface
(Etype
(Rec_Ent
))
2375 and then Nkind
(First
(Stmts
)) = N_Procedure_Call_Statement
2376 and then Is_Init_Proc
(Name
(First
(Stmts
)))
2378 Prepend_To
(Body_Stmts
, Remove_Head
(Stmts
));
2381 Append_List_To
(Body_Stmts
, Stmts
);
2386 -- Add here the assignment to instantiate the Tag
2388 -- The assignment corresponds to the code:
2390 -- _Init._Tag := Typ'Tag;
2392 -- Suppress the tag assignment when VM_Target because VM tags are
2393 -- represented implicitly in objects. It is also suppressed in case
2394 -- of CPP_Class types because in this case the tag is initialized in
2397 if Is_Tagged_Type
(Rec_Type
)
2398 and then Tagged_Type_Expansion
2399 and then not No_Run_Time_Mode
2401 -- Case 1: Ada tagged types with no CPP ancestor. Set the tags of
2402 -- the actual object and invoke the IP of the parent (in this
2403 -- order). The tag must be initialized before the call to the IP
2404 -- of the parent and the assignments to other components because
2405 -- the initial value of the components may depend on the tag (eg.
2406 -- through a dispatching operation on an access to the current
2407 -- type). The tag assignment is not done when initializing the
2408 -- parent component of a type extension, because in that case the
2409 -- tag is set in the extension.
2411 if not Is_CPP_Class
(Root_Type
(Rec_Type
)) then
2413 -- Initialize the primary tag component
2415 Init_Tags_List
:= New_List
(
2416 Make_Assignment_Statement
(Loc
,
2418 Make_Selected_Component
(Loc
,
2419 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2422 (First_Tag_Component
(Rec_Type
), Loc
)),
2426 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2428 -- Ada 2005 (AI-251): Initialize the secondary tags components
2429 -- located at fixed positions (tags whose position depends on
2430 -- variable size components are initialized later ---see below)
2432 if Ada_Version
>= Ada_2005
2433 and then not Is_Interface
(Rec_Type
)
2434 and then Has_Interfaces
(Rec_Type
)
2438 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2439 Stmts_List
=> Init_Tags_List
,
2440 Fixed_Comps
=> True,
2441 Variable_Comps
=> False);
2444 Prepend_To
(Body_Stmts
,
2445 Make_If_Statement
(Loc
,
2446 Condition
=> New_Occurrence_Of
(Set_Tag
, Loc
),
2447 Then_Statements
=> Init_Tags_List
));
2449 -- Case 2: CPP type. The imported C++ constructor takes care of
2450 -- tags initialization. No action needed here because the IP
2451 -- is built by Set_CPP_Constructors; in this case the IP is a
2452 -- wrapper that invokes the C++ constructor and copies the C++
2453 -- tags locally. Done to inherit the C++ slots in Ada derivations
2456 elsif Is_CPP_Class
(Rec_Type
) then
2457 pragma Assert
(False);
2460 -- Case 3: Combined hierarchy containing C++ types and Ada tagged
2461 -- type derivations. Derivations of imported C++ classes add a
2462 -- complication, because we cannot inhibit tag setting in the
2463 -- constructor for the parent. Hence we initialize the tag after
2464 -- the call to the parent IP (that is, in reverse order compared
2465 -- with pure Ada hierarchies ---see comment on case 1).
2468 -- Initialize the primary tag
2470 Init_Tags_List
:= New_List
(
2471 Make_Assignment_Statement
(Loc
,
2473 Make_Selected_Component
(Loc
,
2474 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2477 (First_Tag_Component
(Rec_Type
), Loc
)),
2481 (First_Elmt
(Access_Disp_Table
(Rec_Type
))), Loc
)));
2483 -- Ada 2005 (AI-251): Initialize the secondary tags components
2484 -- located at fixed positions (tags whose position depends on
2485 -- variable size components are initialized later ---see below)
2487 if Ada_Version
>= Ada_2005
2488 and then not Is_Interface
(Rec_Type
)
2489 and then Has_Interfaces
(Rec_Type
)
2493 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2494 Stmts_List
=> Init_Tags_List
,
2495 Fixed_Comps
=> True,
2496 Variable_Comps
=> False);
2499 -- Initialize the tag component after invocation of parent IP.
2502 -- parent_IP(_init.parent); // Invokes the C++ constructor
2503 -- [ typIC; ] // Inherit C++ slots from parent
2510 -- Search for the call to the IP of the parent. We assume
2511 -- that the first init_proc call is for the parent.
2513 Ins_Nod
:= First
(Body_Stmts
);
2514 while Present
(Next
(Ins_Nod
))
2515 and then (Nkind
(Ins_Nod
) /= N_Procedure_Call_Statement
2516 or else not Is_Init_Proc
(Name
(Ins_Nod
)))
2521 -- The IC routine copies the inherited slots of the C+ part
2522 -- of the dispatch table from the parent and updates the
2523 -- overridden C++ slots.
2525 if CPP_Num_Prims
(Rec_Type
) > 0 then
2527 Init_DT
: Entity_Id
;
2531 Init_DT
:= CPP_Init_Proc
(Rec_Type
);
2532 pragma Assert
(Present
(Init_DT
));
2535 Make_Procedure_Call_Statement
(Loc
,
2536 New_Occurrence_Of
(Init_DT
, Loc
));
2537 Insert_After
(Ins_Nod
, New_Nod
);
2539 -- Update location of init tag statements
2545 Insert_List_After
(Ins_Nod
, Init_Tags_List
);
2549 -- Ada 2005 (AI-251): Initialize the secondary tag components
2550 -- located at variable positions. We delay the generation of this
2551 -- code until here because the value of the attribute 'Position
2552 -- applied to variable size components of the parent type that
2553 -- depend on discriminants is only safely read at runtime after
2554 -- the parent components have been initialized.
2556 if Ada_Version
>= Ada_2005
2557 and then not Is_Interface
(Rec_Type
)
2558 and then Has_Interfaces
(Rec_Type
)
2559 and then Has_Discriminants
(Etype
(Rec_Type
))
2560 and then Is_Variable_Size_Record
(Etype
(Rec_Type
))
2562 Init_Tags_List
:= New_List
;
2566 Target
=> Make_Identifier
(Loc
, Name_uInit
),
2567 Stmts_List
=> Init_Tags_List
,
2568 Fixed_Comps
=> False,
2569 Variable_Comps
=> True);
2571 if Is_Non_Empty_List
(Init_Tags_List
) then
2572 Append_List_To
(Body_Stmts
, Init_Tags_List
);
2577 Handled_Stmt_Node
:= New_Node
(N_Handled_Sequence_Of_Statements
, Loc
);
2578 Set_Statements
(Handled_Stmt_Node
, Body_Stmts
);
2581 -- Deep_Finalize (_init, C1, ..., CN);
2585 and then Needs_Finalization
(Rec_Type
)
2586 and then not Is_Abstract_Type
(Rec_Type
)
2587 and then not Restriction_Active
(No_Exception_Propagation
)
2594 -- Create a local version of Deep_Finalize which has indication
2595 -- of partial initialization state.
2597 DF_Id
:= Make_Temporary
(Loc
, 'F');
2599 Append_To
(Decls
, Make_Local_Deep_Finalize
(Rec_Type
, DF_Id
));
2602 Make_Procedure_Call_Statement
(Loc
,
2603 Name
=> New_Occurrence_Of
(DF_Id
, Loc
),
2604 Parameter_Associations
=> New_List
(
2605 Make_Identifier
(Loc
, Name_uInit
),
2606 New_Occurrence_Of
(Standard_False
, Loc
)));
2608 -- Do not emit warnings related to the elaboration order when a
2609 -- controlled object is declared before the body of Finalize is
2612 Set_No_Elaboration_Check
(DF_Call
);
2614 Set_Exception_Handlers
(Handled_Stmt_Node
, New_List
(
2615 Make_Exception_Handler
(Loc
,
2616 Exception_Choices
=> New_List
(
2617 Make_Others_Choice
(Loc
)),
2618 Statements
=> New_List
(
2620 Make_Raise_Statement
(Loc
)))));
2623 Set_Exception_Handlers
(Handled_Stmt_Node
, No_List
);
2626 Set_Handled_Statement_Sequence
(Body_Node
, Handled_Stmt_Node
);
2628 if not Debug_Generated_Code
then
2629 Set_Debug_Info_Off
(Proc_Id
);
2632 -- Associate Init_Proc with type, and determine if the procedure
2633 -- is null (happens because of the Initialize_Scalars pragma case,
2634 -- where we have to generate a null procedure in case it is called
2635 -- by a client with Initialize_Scalars set). Such procedures have
2636 -- to be generated, but do not have to be called, so we mark them
2637 -- as null to suppress the call.
2639 Set_Init_Proc
(Rec_Type
, Proc_Id
);
2641 if List_Length
(Body_Stmts
) = 1
2643 -- We must skip SCIL nodes because they may have been added to this
2644 -- list by Insert_Actions.
2646 and then Nkind
(First_Non_SCIL_Node
(Body_Stmts
)) = N_Null_Statement
2647 and then VM_Target
= No_VM
2649 -- Even though the init proc may be null at this time it might get
2650 -- some stuff added to it later by the VM backend.
2652 Set_Is_Null_Init_Proc
(Proc_Id
);
2654 end Build_Init_Procedure
;
2656 ---------------------------
2657 -- Build_Init_Statements --
2658 ---------------------------
2660 function Build_Init_Statements
(Comp_List
: Node_Id
) return List_Id
is
2661 Checks
: constant List_Id
:= New_List
;
2662 Actions
: List_Id
:= No_List
;
2663 Counter_Id
: Entity_Id
:= Empty
;
2664 Comp_Loc
: Source_Ptr
;
2668 Parent_Stmts
: List_Id
;
2672 procedure Increment_Counter
(Loc
: Source_Ptr
);
2673 -- Generate an "increment by one" statement for the current counter
2674 -- and append it to the list Stmts.
2676 procedure Make_Counter
(Loc
: Source_Ptr
);
2677 -- Create a new counter for the current component list. The routine
2678 -- creates a new defining Id, adds an object declaration and sets
2679 -- the Id generator for the next variant.
2681 -----------------------
2682 -- Increment_Counter --
2683 -----------------------
2685 procedure Increment_Counter
(Loc
: Source_Ptr
) is
2688 -- Counter := Counter + 1;
2691 Make_Assignment_Statement
(Loc
,
2692 Name
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2695 Left_Opnd
=> New_Occurrence_Of
(Counter_Id
, Loc
),
2696 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
2697 end Increment_Counter
;
2703 procedure Make_Counter
(Loc
: Source_Ptr
) is
2705 -- Increment the Id generator
2707 Counter
:= Counter
+ 1;
2709 -- Create the entity and declaration
2712 Make_Defining_Identifier
(Loc
,
2713 Chars
=> New_External_Name
('C', Counter
));
2716 -- Cnn : Integer := 0;
2719 Make_Object_Declaration
(Loc
,
2720 Defining_Identifier
=> Counter_Id
,
2721 Object_Definition
=>
2722 New_Occurrence_Of
(Standard_Integer
, Loc
),
2724 Make_Integer_Literal
(Loc
, 0)));
2727 -- Start of processing for Build_Init_Statements
2730 if Null_Present
(Comp_List
) then
2731 return New_List
(Make_Null_Statement
(Loc
));
2734 Parent_Stmts
:= New_List
;
2737 -- Loop through visible declarations of task types and protected
2738 -- types moving any expanded code from the spec to the body of the
2741 if Is_Task_Record_Type
(Rec_Type
)
2742 or else Is_Protected_Record_Type
(Rec_Type
)
2745 Decl
: constant Node_Id
:=
2746 Parent
(Corresponding_Concurrent_Type
(Rec_Type
));
2752 if Is_Task_Record_Type
(Rec_Type
) then
2753 Def
:= Task_Definition
(Decl
);
2755 Def
:= Protected_Definition
(Decl
);
2758 if Present
(Def
) then
2759 N1
:= First
(Visible_Declarations
(Def
));
2760 while Present
(N1
) loop
2764 if Nkind
(N2
) in N_Statement_Other_Than_Procedure_Call
2765 or else Nkind
(N2
) in N_Raise_xxx_Error
2766 or else Nkind
(N2
) = N_Procedure_Call_Statement
2769 New_Copy_Tree
(N2
, New_Scope
=> Proc_Id
));
2770 Rewrite
(N2
, Make_Null_Statement
(Sloc
(N2
)));
2778 -- Loop through components, skipping pragmas, in 2 steps. The first
2779 -- step deals with regular components. The second step deals with
2780 -- components that have per object constraints and no explicit
2785 -- First pass : regular components
2787 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
2788 while Present
(Decl
) loop
2789 Comp_Loc
:= Sloc
(Decl
);
2791 (Subtype_Indication
(Component_Definition
(Decl
)), Checks
);
2793 Id
:= Defining_Identifier
(Decl
);
2796 -- Leave any processing of per-object constrained component for
2799 if Has_Access_Constraint
(Id
) and then No
(Expression
(Decl
)) then
2802 -- Regular component cases
2805 -- In the context of the init proc, references to discriminants
2806 -- resolve to denote the discriminals: this is where we can
2807 -- freeze discriminant dependent component subtypes.
2809 if not Is_Frozen
(Typ
) then
2810 Append_List_To
(Stmts
, Freeze_Entity
(Typ
, N
));
2813 -- Explicit initialization
2815 if Present
(Expression
(Decl
)) then
2816 if Is_CPP_Constructor_Call
(Expression
(Decl
)) then
2818 Build_Initialization_Call
2821 Make_Selected_Component
(Comp_Loc
,
2823 Make_Identifier
(Comp_Loc
, Name_uInit
),
2825 New_Occurrence_Of
(Id
, Comp_Loc
)),
2827 In_Init_Proc
=> True,
2828 Enclos_Type
=> Rec_Type
,
2829 Discr_Map
=> Discr_Map
,
2830 Constructor_Ref
=> Expression
(Decl
));
2832 Actions
:= Build_Assignment
(Id
, Expression
(Decl
));
2835 -- CPU, Dispatching_Domain, Priority and Size components are
2836 -- filled with the corresponding rep item expression of the
2837 -- concurrent type (if any).
2839 elsif Ekind
(Scope
(Id
)) = E_Record_Type
2840 and then Present
(Corresponding_Concurrent_Type
(Scope
(Id
)))
2841 and then Nam_In
(Chars
(Id
), Name_uCPU
,
2842 Name_uDispatching_Domain
,
2851 if Chars
(Id
) = Name_uCPU
then
2854 elsif Chars
(Id
) = Name_uDispatching_Domain
then
2855 Nam
:= Name_Dispatching_Domain
;
2857 elsif Chars
(Id
) = Name_uPriority
then
2858 Nam
:= Name_Priority
;
2861 -- Get the Rep Item (aspect specification, attribute
2862 -- definition clause or pragma) of the corresponding
2867 (Corresponding_Concurrent_Type
(Scope
(Id
)),
2869 Check_Parents
=> False);
2871 if Present
(Ritem
) then
2875 if Nkind
(Ritem
) = N_Pragma
then
2876 Exp
:= First
(Pragma_Argument_Associations
(Ritem
));
2878 if Nkind
(Exp
) = N_Pragma_Argument_Association
then
2879 Exp
:= Expression
(Exp
);
2882 -- Conversion for Priority expression
2884 if Nam
= Name_Priority
then
2885 if Pragma_Name
(Ritem
) = Name_Priority
2886 and then not GNAT_Mode
2888 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
2891 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
2895 -- Aspect/Attribute definition clause case
2898 Exp
:= Expression
(Ritem
);
2900 -- Conversion for Priority expression
2902 if Nam
= Name_Priority
then
2903 if Chars
(Ritem
) = Name_Priority
2904 and then not GNAT_Mode
2906 Exp
:= Convert_To
(RTE
(RE_Priority
), Exp
);
2909 Convert_To
(RTE
(RE_Any_Priority
), Exp
);
2914 -- Conversion for Dispatching_Domain value
2916 if Nam
= Name_Dispatching_Domain
then
2918 Unchecked_Convert_To
2919 (RTE
(RE_Dispatching_Domain_Access
), Exp
);
2922 Actions
:= Build_Assignment
(Id
, Exp
);
2924 -- Nothing needed if no Rep Item
2931 -- Composite component with its own Init_Proc
2933 elsif not Is_Interface
(Typ
)
2934 and then Has_Non_Null_Base_Init_Proc
(Typ
)
2937 Build_Initialization_Call
2939 Make_Selected_Component
(Comp_Loc
,
2941 Make_Identifier
(Comp_Loc
, Name_uInit
),
2942 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
2944 In_Init_Proc
=> True,
2945 Enclos_Type
=> Rec_Type
,
2946 Discr_Map
=> Discr_Map
);
2948 Clean_Task_Names
(Typ
, Proc_Id
);
2950 -- Simple initialization
2952 elsif Component_Needs_Simple_Initialization
(Typ
) then
2955 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
)));
2957 -- Nothing needed for this case
2963 if Present
(Checks
) then
2964 if Chars
(Id
) = Name_uParent
then
2965 Append_List_To
(Parent_Stmts
, Checks
);
2967 Append_List_To
(Stmts
, Checks
);
2971 if Present
(Actions
) then
2972 if Chars
(Id
) = Name_uParent
then
2973 Append_List_To
(Parent_Stmts
, Actions
);
2976 Append_List_To
(Stmts
, Actions
);
2978 -- Preserve initialization state in the current counter
2980 if Needs_Finalization
(Typ
) then
2981 if No
(Counter_Id
) then
2982 Make_Counter
(Comp_Loc
);
2985 Increment_Counter
(Comp_Loc
);
2991 Next_Non_Pragma
(Decl
);
2994 -- The parent field must be initialized first because variable
2995 -- size components of the parent affect the location of all the
2998 Prepend_List_To
(Stmts
, Parent_Stmts
);
3000 -- Set up tasks and protected object support. This needs to be done
3001 -- before any component with a per-object access discriminant
3002 -- constraint, or any variant part (which may contain such
3003 -- components) is initialized, because the initialization of these
3004 -- components may reference the enclosing concurrent object.
3006 -- For a task record type, add the task create call and calls to bind
3007 -- any interrupt (signal) entries.
3009 if Is_Task_Record_Type
(Rec_Type
) then
3011 -- In the case of the restricted run time the ATCB has already
3012 -- been preallocated.
3014 if Restricted_Profile
then
3016 Make_Assignment_Statement
(Loc
,
3018 Make_Selected_Component
(Loc
,
3019 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3020 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3022 Make_Attribute_Reference
(Loc
,
3024 Make_Selected_Component
(Loc
,
3025 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
3026 Selector_Name
=> Make_Identifier
(Loc
, Name_uATCB
)),
3027 Attribute_Name
=> Name_Unchecked_Access
)));
3030 Append_To
(Stmts
, Make_Task_Create_Call
(Rec_Type
));
3033 Task_Type
: constant Entity_Id
:=
3034 Corresponding_Concurrent_Type
(Rec_Type
);
3035 Task_Decl
: constant Node_Id
:= Parent
(Task_Type
);
3036 Task_Def
: constant Node_Id
:= Task_Definition
(Task_Decl
);
3037 Decl_Loc
: Source_Ptr
;
3042 if Present
(Task_Def
) then
3043 Vis_Decl
:= First
(Visible_Declarations
(Task_Def
));
3044 while Present
(Vis_Decl
) loop
3045 Decl_Loc
:= Sloc
(Vis_Decl
);
3047 if Nkind
(Vis_Decl
) = N_Attribute_Definition_Clause
then
3048 if Get_Attribute_Id
(Chars
(Vis_Decl
)) =
3051 Ent
:= Entity
(Name
(Vis_Decl
));
3053 if Ekind
(Ent
) = E_Entry
then
3055 Make_Procedure_Call_Statement
(Decl_Loc
,
3057 New_Occurrence_Of
(RTE
(
3058 RE_Bind_Interrupt_To_Entry
), Decl_Loc
),
3059 Parameter_Associations
=> New_List
(
3060 Make_Selected_Component
(Decl_Loc
,
3062 Make_Identifier
(Decl_Loc
, Name_uInit
),
3065 (Decl_Loc
, Name_uTask_Id
)),
3066 Entry_Index_Expression
3067 (Decl_Loc
, Ent
, Empty
, Task_Type
),
3068 Expression
(Vis_Decl
))));
3079 -- For a protected type, add statements generated by
3080 -- Make_Initialize_Protection.
3082 if Is_Protected_Record_Type
(Rec_Type
) then
3083 Append_List_To
(Stmts
,
3084 Make_Initialize_Protection
(Rec_Type
));
3087 -- Second pass: components with per-object constraints
3090 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3091 while Present
(Decl
) loop
3092 Comp_Loc
:= Sloc
(Decl
);
3093 Id
:= Defining_Identifier
(Decl
);
3096 if Has_Access_Constraint
(Id
)
3097 and then No
(Expression
(Decl
))
3099 if Has_Non_Null_Base_Init_Proc
(Typ
) then
3100 Append_List_To
(Stmts
,
3101 Build_Initialization_Call
(Comp_Loc
,
3102 Make_Selected_Component
(Comp_Loc
,
3104 Make_Identifier
(Comp_Loc
, Name_uInit
),
3105 Selector_Name
=> New_Occurrence_Of
(Id
, Comp_Loc
)),
3107 In_Init_Proc
=> True,
3108 Enclos_Type
=> Rec_Type
,
3109 Discr_Map
=> Discr_Map
));
3111 Clean_Task_Names
(Typ
, Proc_Id
);
3113 -- Preserve initialization state in the current counter
3115 if Needs_Finalization
(Typ
) then
3116 if No
(Counter_Id
) then
3117 Make_Counter
(Comp_Loc
);
3120 Increment_Counter
(Comp_Loc
);
3123 elsif Component_Needs_Simple_Initialization
(Typ
) then
3124 Append_List_To
(Stmts
,
3126 (Id
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Id
))));
3130 Next_Non_Pragma
(Decl
);
3134 -- Process the variant part
3136 if Present
(Variant_Part
(Comp_List
)) then
3138 Variant_Alts
: constant List_Id
:= New_List
;
3139 Var_Loc
: Source_Ptr
;
3144 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3145 while Present
(Variant
) loop
3146 Var_Loc
:= Sloc
(Variant
);
3147 Append_To
(Variant_Alts
,
3148 Make_Case_Statement_Alternative
(Var_Loc
,
3150 New_Copy_List
(Discrete_Choices
(Variant
)),
3152 Build_Init_Statements
(Component_List
(Variant
))));
3153 Next_Non_Pragma
(Variant
);
3156 -- The expression of the case statement which is a reference
3157 -- to one of the discriminants is replaced by the appropriate
3158 -- formal parameter of the initialization procedure.
3161 Make_Case_Statement
(Var_Loc
,
3163 New_Occurrence_Of
(Discriminal
(
3164 Entity
(Name
(Variant_Part
(Comp_List
)))), Var_Loc
),
3165 Alternatives
=> Variant_Alts
));
3169 -- If no initializations when generated for component declarations
3170 -- corresponding to this Stmts, append a null statement to Stmts to
3171 -- to make it a valid Ada tree.
3173 if Is_Empty_List
(Stmts
) then
3174 Append
(Make_Null_Statement
(Loc
), Stmts
);
3180 when RE_Not_Available
=>
3182 end Build_Init_Statements
;
3184 -------------------------
3185 -- Build_Record_Checks --
3186 -------------------------
3188 procedure Build_Record_Checks
(S
: Node_Id
; Check_List
: List_Id
) is
3189 Subtype_Mark_Id
: Entity_Id
;
3191 procedure Constrain_Array
3193 Check_List
: List_Id
);
3194 -- Apply a list of index constraints to an unconstrained array type.
3195 -- The first parameter is the entity for the resulting subtype.
3196 -- Check_List is a list to which the check actions are appended.
3198 ---------------------
3199 -- Constrain_Array --
3200 ---------------------
3202 procedure Constrain_Array
3204 Check_List
: List_Id
)
3206 C
: constant Node_Id
:= Constraint
(SI
);
3207 Number_Of_Constraints
: Nat
:= 0;
3211 procedure Constrain_Index
3214 Check_List
: List_Id
);
3215 -- Process an index constraint in a constrained array declaration.
3216 -- The constraint can be either a subtype name or a range with or
3217 -- without an explicit subtype mark. Index is the corresponding
3218 -- index of the unconstrained array. S is the range expression.
3219 -- Check_List is a list to which the check actions are appended.
3221 ---------------------
3222 -- Constrain_Index --
3223 ---------------------
3225 procedure Constrain_Index
3228 Check_List
: List_Id
)
3230 T
: constant Entity_Id
:= Etype
(Index
);
3233 if Nkind
(S
) = N_Range
then
3234 Process_Range_Expr_In_Decl
(S
, T
, Check_List
=> Check_List
);
3236 end Constrain_Index
;
3238 -- Start of processing for Constrain_Array
3241 T
:= Entity
(Subtype_Mark
(SI
));
3243 if Is_Access_Type
(T
) then
3244 T
:= Designated_Type
(T
);
3247 S
:= First
(Constraints
(C
));
3249 while Present
(S
) loop
3250 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
3254 -- In either case, the index constraint must provide a discrete
3255 -- range for each index of the array type and the type of each
3256 -- discrete range must be the same as that of the corresponding
3257 -- index. (RM 3.6.1)
3259 S
:= First
(Constraints
(C
));
3260 Index
:= First_Index
(T
);
3263 -- Apply constraints to each index type
3265 for J
in 1 .. Number_Of_Constraints
loop
3266 Constrain_Index
(Index
, S
, Check_List
);
3270 end Constrain_Array
;
3272 -- Start of processing for Build_Record_Checks
3275 if Nkind
(S
) = N_Subtype_Indication
then
3276 Find_Type
(Subtype_Mark
(S
));
3277 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
3279 -- Remaining processing depends on type
3281 case Ekind
(Subtype_Mark_Id
) is
3284 Constrain_Array
(S
, Check_List
);
3290 end Build_Record_Checks
;
3292 -------------------------------------------
3293 -- Component_Needs_Simple_Initialization --
3294 -------------------------------------------
3296 function Component_Needs_Simple_Initialization
3297 (T
: Entity_Id
) return Boolean
3301 Needs_Simple_Initialization
(T
)
3302 and then not Is_RTE
(T
, RE_Tag
)
3304 -- Ada 2005 (AI-251): Check also the tag of abstract interfaces
3306 and then not Is_RTE
(T
, RE_Interface_Tag
);
3307 end Component_Needs_Simple_Initialization
;
3309 --------------------------------------
3310 -- Parent_Subtype_Renaming_Discrims --
3311 --------------------------------------
3313 function Parent_Subtype_Renaming_Discrims
return Boolean is
3318 if Base_Type
(Rec_Ent
) /= Rec_Ent
then
3322 if Etype
(Rec_Ent
) = Rec_Ent
3323 or else not Has_Discriminants
(Rec_Ent
)
3324 or else Is_Constrained
(Rec_Ent
)
3325 or else Is_Tagged_Type
(Rec_Ent
)
3330 -- If there are no explicit stored discriminants we have inherited
3331 -- the root type discriminants so far, so no renamings occurred.
3333 if First_Discriminant
(Rec_Ent
) =
3334 First_Stored_Discriminant
(Rec_Ent
)
3339 -- Check if we have done some trivial renaming of the parent
3340 -- discriminants, i.e. something like
3342 -- type DT (X1, X2: int) is new PT (X1, X2);
3344 De
:= First_Discriminant
(Rec_Ent
);
3345 Dp
:= First_Discriminant
(Etype
(Rec_Ent
));
3346 while Present
(De
) loop
3347 pragma Assert
(Present
(Dp
));
3349 if Corresponding_Discriminant
(De
) /= Dp
then
3353 Next_Discriminant
(De
);
3354 Next_Discriminant
(Dp
);
3357 return Present
(Dp
);
3358 end Parent_Subtype_Renaming_Discrims
;
3360 ------------------------
3361 -- Requires_Init_Proc --
3362 ------------------------
3364 function Requires_Init_Proc
(Rec_Id
: Entity_Id
) return Boolean is
3365 Comp_Decl
: Node_Id
;
3370 -- Definitely do not need one if specifically suppressed
3372 if Initialization_Suppressed
(Rec_Id
) then
3376 -- If it is a type derived from a type with unknown discriminants,
3377 -- we cannot build an initialization procedure for it.
3379 if Has_Unknown_Discriminants
(Rec_Id
)
3380 or else Has_Unknown_Discriminants
(Etype
(Rec_Id
))
3385 -- Otherwise we need to generate an initialization procedure if
3386 -- Is_CPP_Class is False and at least one of the following applies:
3388 -- 1. Discriminants are present, since they need to be initialized
3389 -- with the appropriate discriminant constraint expressions.
3390 -- However, the discriminant of an unchecked union does not
3391 -- count, since the discriminant is not present.
3393 -- 2. The type is a tagged type, since the implicit Tag component
3394 -- needs to be initialized with a pointer to the dispatch table.
3396 -- 3. The type contains tasks
3398 -- 4. One or more components has an initial value
3400 -- 5. One or more components is for a type which itself requires
3401 -- an initialization procedure.
3403 -- 6. One or more components is a type that requires simple
3404 -- initialization (see Needs_Simple_Initialization), except
3405 -- that types Tag and Interface_Tag are excluded, since fields
3406 -- of these types are initialized by other means.
3408 -- 7. The type is the record type built for a task type (since at
3409 -- the very least, Create_Task must be called)
3411 -- 8. The type is the record type built for a protected type (since
3412 -- at least Initialize_Protection must be called)
3414 -- 9. The type is marked as a public entity. The reason we add this
3415 -- case (even if none of the above apply) is to properly handle
3416 -- Initialize_Scalars. If a package is compiled without an IS
3417 -- pragma, and the client is compiled with an IS pragma, then
3418 -- the client will think an initialization procedure is present
3419 -- and call it, when in fact no such procedure is required, but
3420 -- since the call is generated, there had better be a routine
3421 -- at the other end of the call, even if it does nothing).
3423 -- Note: the reason we exclude the CPP_Class case is because in this
3424 -- case the initialization is performed by the C++ constructors, and
3425 -- the IP is built by Set_CPP_Constructors.
3427 if Is_CPP_Class
(Rec_Id
) then
3430 elsif Is_Interface
(Rec_Id
) then
3433 elsif (Has_Discriminants
(Rec_Id
)
3434 and then not Is_Unchecked_Union
(Rec_Id
))
3435 or else Is_Tagged_Type
(Rec_Id
)
3436 or else Is_Concurrent_Record_Type
(Rec_Id
)
3437 or else Has_Task
(Rec_Id
)
3442 Id
:= First_Component
(Rec_Id
);
3443 while Present
(Id
) loop
3444 Comp_Decl
:= Parent
(Id
);
3447 if Present
(Expression
(Comp_Decl
))
3448 or else Has_Non_Null_Base_Init_Proc
(Typ
)
3449 or else Component_Needs_Simple_Initialization
(Typ
)
3454 Next_Component
(Id
);
3457 -- As explained above, a record initialization procedure is needed
3458 -- for public types in case Initialize_Scalars applies to a client.
3459 -- However, such a procedure is not needed in the case where either
3460 -- of restrictions No_Initialize_Scalars or No_Default_Initialization
3461 -- applies. No_Initialize_Scalars excludes the possibility of using
3462 -- Initialize_Scalars in any partition, and No_Default_Initialization
3463 -- implies that no initialization should ever be done for objects of
3464 -- the type, so is incompatible with Initialize_Scalars.
3466 if not Restriction_Active
(No_Initialize_Scalars
)
3467 and then not Restriction_Active
(No_Default_Initialization
)
3468 and then Is_Public
(Rec_Id
)
3474 end Requires_Init_Proc
;
3476 -- Start of processing for Build_Record_Init_Proc
3479 -- Check for value type, which means no initialization required
3481 Rec_Type
:= Defining_Identifier
(N
);
3483 if Is_Value_Type
(Rec_Type
) then
3487 -- This may be full declaration of a private type, in which case
3488 -- the visible entity is a record, and the private entity has been
3489 -- exchanged with it in the private part of the current package.
3490 -- The initialization procedure is built for the record type, which
3491 -- is retrievable from the private entity.
3493 if Is_Incomplete_Or_Private_Type
(Rec_Type
) then
3494 Rec_Type
:= Underlying_Type
(Rec_Type
);
3497 -- If we have a variant record with restriction No_Implicit_Conditionals
3498 -- in effect, then we skip building the procedure. This is safe because
3499 -- if we can see the restriction, so can any caller, calls to initialize
3500 -- such records are not allowed for variant records if this restriction
3503 if Has_Variant_Part
(Rec_Type
)
3504 and then Restriction_Active
(No_Implicit_Conditionals
)
3509 -- If there are discriminants, build the discriminant map to replace
3510 -- discriminants by their discriminals in complex bound expressions.
3511 -- These only arise for the corresponding records of synchronized types.
3513 if Is_Concurrent_Record_Type
(Rec_Type
)
3514 and then Has_Discriminants
(Rec_Type
)
3519 Disc
:= First_Discriminant
(Rec_Type
);
3520 while Present
(Disc
) loop
3521 Append_Elmt
(Disc
, Discr_Map
);
3522 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
3523 Next_Discriminant
(Disc
);
3528 -- Derived types that have no type extension can use the initialization
3529 -- procedure of their parent and do not need a procedure of their own.
3530 -- This is only correct if there are no representation clauses for the
3531 -- type or its parent, and if the parent has in fact been frozen so
3532 -- that its initialization procedure exists.
3534 if Is_Derived_Type
(Rec_Type
)
3535 and then not Is_Tagged_Type
(Rec_Type
)
3536 and then not Is_Unchecked_Union
(Rec_Type
)
3537 and then not Has_New_Non_Standard_Rep
(Rec_Type
)
3538 and then not Parent_Subtype_Renaming_Discrims
3539 and then Has_Non_Null_Base_Init_Proc
(Etype
(Rec_Type
))
3541 Copy_TSS
(Base_Init_Proc
(Etype
(Rec_Type
)), Rec_Type
);
3543 -- Otherwise if we need an initialization procedure, then build one,
3544 -- mark it as public and inlinable and as having a completion.
3546 elsif Requires_Init_Proc
(Rec_Type
)
3547 or else Is_Unchecked_Union
(Rec_Type
)
3550 Make_Defining_Identifier
(Loc
,
3551 Chars
=> Make_Init_Proc_Name
(Rec_Type
));
3553 -- If No_Default_Initialization restriction is active, then we don't
3554 -- want to build an init_proc, but we need to mark that an init_proc
3555 -- would be needed if this restriction was not active (so that we can
3556 -- detect attempts to call it), so set a dummy init_proc in place.
3558 if Restriction_Active
(No_Default_Initialization
) then
3559 Set_Init_Proc
(Rec_Type
, Proc_Id
);
3563 Build_Offset_To_Top_Functions
;
3564 Build_CPP_Init_Procedure
;
3565 Build_Init_Procedure
;
3566 Set_Is_Public
(Proc_Id
, Is_Public
(Rec_Ent
));
3568 -- The initialization of protected records is not worth inlining.
3569 -- In addition, when compiled for another unit for inlining purposes,
3570 -- it may make reference to entities that have not been elaborated
3571 -- yet. The initialization of controlled records contains a nested
3572 -- clean-up procedure that makes it impractical to inline as well,
3573 -- and leads to undefined symbols if inlined in a different unit.
3574 -- Similar considerations apply to task types.
3576 if not Is_Concurrent_Type
(Rec_Type
)
3577 and then not Has_Task
(Rec_Type
)
3578 and then not Needs_Finalization
(Rec_Type
)
3580 Set_Is_Inlined
(Proc_Id
);
3583 Set_Is_Internal
(Proc_Id
);
3584 Set_Has_Completion
(Proc_Id
);
3586 if not Debug_Generated_Code
then
3587 Set_Debug_Info_Off
(Proc_Id
);
3591 Agg
: constant Node_Id
:=
3592 Build_Equivalent_Record_Aggregate
(Rec_Type
);
3594 procedure Collect_Itypes
(Comp
: Node_Id
);
3595 -- Generate references to itypes in the aggregate, because
3596 -- the first use of the aggregate may be in a nested scope.
3598 --------------------
3599 -- Collect_Itypes --
3600 --------------------
3602 procedure Collect_Itypes
(Comp
: Node_Id
) is
3605 Typ
: constant Entity_Id
:= Etype
(Comp
);
3608 if Is_Array_Type
(Typ
) and then Is_Itype
(Typ
) then
3609 Ref
:= Make_Itype_Reference
(Loc
);
3610 Set_Itype
(Ref
, Typ
);
3611 Append_Freeze_Action
(Rec_Type
, Ref
);
3613 Ref
:= Make_Itype_Reference
(Loc
);
3614 Set_Itype
(Ref
, Etype
(First_Index
(Typ
)));
3615 Append_Freeze_Action
(Rec_Type
, Ref
);
3617 Sub_Aggr
:= First
(Expressions
(Comp
));
3619 -- Recurse on nested arrays
3621 while Present
(Sub_Aggr
) loop
3622 Collect_Itypes
(Sub_Aggr
);
3629 -- If there is a static initialization aggregate for the type,
3630 -- generate itype references for the types of its (sub)components,
3631 -- to prevent out-of-scope errors in the resulting tree.
3632 -- The aggregate may have been rewritten as a Raise node, in which
3633 -- case there are no relevant itypes.
3635 if Present
(Agg
) and then Nkind
(Agg
) = N_Aggregate
then
3636 Set_Static_Initialization
(Proc_Id
, Agg
);
3641 Comp
:= First
(Component_Associations
(Agg
));
3642 while Present
(Comp
) loop
3643 Collect_Itypes
(Expression
(Comp
));
3650 end Build_Record_Init_Proc
;
3652 --------------------------------
3653 -- Build_Record_Invariant_Proc --
3654 --------------------------------
3656 function Build_Record_Invariant_Proc
3657 (R_Type
: Entity_Id
;
3658 Nod
: Node_Id
) return Node_Id
3660 Loc
: constant Source_Ptr
:= Sloc
(Nod
);
3662 Object_Name
: constant Name_Id
:= New_Internal_Name
('I');
3663 -- Name for argument of invariant procedure
3665 Object_Entity
: constant Node_Id
:=
3666 Make_Defining_Identifier
(Loc
, Object_Name
);
3667 -- The procedure declaration entity for the argument
3669 Invariant_Found
: Boolean;
3670 -- Set if any component needs an invariant check.
3672 Proc_Id
: Entity_Id
;
3673 Proc_Body
: Node_Id
;
3677 function Build_Invariant_Checks
(Comp_List
: Node_Id
) return List_Id
;
3678 -- Recursive procedure that generates a list of checks for components
3679 -- that need it, and recurses through variant parts when present.
3681 function Build_Component_Invariant_Call
(Comp
: Entity_Id
)
3683 -- Build call to invariant procedure for a record component.
3685 ------------------------------------
3686 -- Build_Component_Invariant_Call --
3687 ------------------------------------
3689 function Build_Component_Invariant_Call
(Comp
: Entity_Id
)
3697 Invariant_Found
:= True;
3698 Typ
:= Etype
(Comp
);
3701 Make_Selected_Component
(Loc
,
3702 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
3703 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
3705 if Is_Access_Type
(Typ
) then
3707 -- If the access component designates a type with an invariant,
3708 -- the check applies to the designated object. The access type
3709 -- itself may have an invariant, in which case it applies to the
3710 -- access value directly.
3712 -- Note: we are assuming that invariants will not occur on both
3713 -- the access type and the type that it designates. This is not
3714 -- really justified but it is hard to imagine that this case will
3715 -- ever cause trouble ???
3717 if not (Has_Invariants
(Typ
)) then
3718 Sel_Comp
:= Make_Explicit_Dereference
(Loc
, Sel_Comp
);
3719 Typ
:= Designated_Type
(Typ
);
3723 -- The aspect is type-specific, so retrieve it from the base type
3726 Make_Procedure_Call_Statement
(Loc
,
3728 New_Occurrence_Of
(Invariant_Procedure
(Base_Type
(Typ
)), Loc
),
3729 Parameter_Associations
=> New_List
(Sel_Comp
));
3731 if Is_Access_Type
(Etype
(Comp
)) then
3733 Make_If_Statement
(Loc
,
3736 Left_Opnd
=> Make_Null
(Loc
),
3738 Make_Selected_Component
(Loc
,
3739 Prefix
=> New_Occurrence_Of
(Object_Entity
, Loc
),
3740 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
))),
3741 Then_Statements
=> New_List
(Call
));
3745 end Build_Component_Invariant_Call
;
3747 ----------------------------
3748 -- Build_Invariant_Checks --
3749 ----------------------------
3751 function Build_Invariant_Checks
(Comp_List
: Node_Id
) return List_Id
is
3758 Decl
:= First_Non_Pragma
(Component_Items
(Comp_List
));
3759 while Present
(Decl
) loop
3760 if Nkind
(Decl
) = N_Component_Declaration
then
3761 Id
:= Defining_Identifier
(Decl
);
3763 if Has_Invariants
(Etype
(Id
))
3764 and then In_Open_Scopes
(Scope
(R_Type
))
3766 if Has_Unchecked_Union
(R_Type
) then
3768 ("invariants cannot be checked on components of "
3769 & "unchecked_union type&?", Decl
, R_Type
);
3773 Append_To
(Stmts
, Build_Component_Invariant_Call
(Id
));
3776 elsif Is_Access_Type
(Etype
(Id
))
3777 and then not Is_Access_Constant
(Etype
(Id
))
3778 and then Has_Invariants
(Designated_Type
(Etype
(Id
)))
3779 and then In_Open_Scopes
(Scope
(Designated_Type
(Etype
(Id
))))
3781 Append_To
(Stmts
, Build_Component_Invariant_Call
(Id
));
3788 if Present
(Variant_Part
(Comp_List
)) then
3790 Variant_Alts
: constant List_Id
:= New_List
;
3791 Var_Loc
: Source_Ptr
;
3793 Variant_Stmts
: List_Id
;
3797 First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3798 while Present
(Variant
) loop
3800 Build_Invariant_Checks
(Component_List
(Variant
));
3801 Var_Loc
:= Sloc
(Variant
);
3802 Append_To
(Variant_Alts
,
3803 Make_Case_Statement_Alternative
(Var_Loc
,
3805 New_Copy_List
(Discrete_Choices
(Variant
)),
3806 Statements
=> Variant_Stmts
));
3808 Next_Non_Pragma
(Variant
);
3811 -- The expression in the case statement is the reference to
3812 -- the discriminant of the target object.
3815 Make_Case_Statement
(Var_Loc
,
3817 Make_Selected_Component
(Var_Loc
,
3818 Prefix
=> New_Occurrence_Of
(Object_Entity
, Var_Loc
),
3819 Selector_Name
=> New_Occurrence_Of
3821 (Name
(Variant_Part
(Comp_List
))), Var_Loc
)),
3822 Alternatives
=> Variant_Alts
));
3827 end Build_Invariant_Checks
;
3829 -- Start of processing for Build_Record_Invariant_Proc
3832 Invariant_Found
:= False;
3833 Type_Def
:= Type_Definition
(Parent
(R_Type
));
3835 if Nkind
(Type_Def
) = N_Record_Definition
3836 and then not Null_Present
(Type_Def
)
3838 Stmts
:= Build_Invariant_Checks
(Component_List
(Type_Def
));
3843 if not Invariant_Found
then
3847 -- The name of the invariant procedure reflects the fact that the
3848 -- checks correspond to invariants on the component types. The
3849 -- record type itself may have invariants that will create a separate
3850 -- procedure whose name carries the Invariant suffix.
3853 Make_Defining_Identifier
(Loc
,
3854 Chars
=> New_External_Name
(Chars
(R_Type
), "CInvariant"));
3857 Make_Subprogram_Body
(Loc
,
3859 Make_Procedure_Specification
(Loc
,
3860 Defining_Unit_Name
=> Proc_Id
,
3861 Parameter_Specifications
=> New_List
(
3862 Make_Parameter_Specification
(Loc
,
3863 Defining_Identifier
=> Object_Entity
,
3864 Parameter_Type
=> New_Occurrence_Of
(R_Type
, Loc
)))),
3866 Declarations
=> Empty_List
,
3867 Handled_Statement_Sequence
=>
3868 Make_Handled_Sequence_Of_Statements
(Loc
,
3869 Statements
=> Stmts
));
3871 Set_Ekind
(Proc_Id
, E_Procedure
);
3872 Set_Is_Public
(Proc_Id
, Is_Public
(R_Type
));
3873 Set_Is_Internal
(Proc_Id
);
3874 Set_Has_Completion
(Proc_Id
);
3877 -- Insert_After (Nod, Proc_Body);
3878 -- Analyze (Proc_Body);
3879 end Build_Record_Invariant_Proc
;
3881 ----------------------------
3882 -- Build_Slice_Assignment --
3883 ----------------------------
3885 -- Generates the following subprogram:
3888 -- (Source, Target : Array_Type,
3889 -- Left_Lo, Left_Hi : Index;
3890 -- Right_Lo, Right_Hi : Index;
3898 -- if Left_Hi < Left_Lo then
3911 -- Target (Li1) := Source (Ri1);
3914 -- exit when Li1 = Left_Lo;
3915 -- Li1 := Index'pred (Li1);
3916 -- Ri1 := Index'pred (Ri1);
3918 -- exit when Li1 = Left_Hi;
3919 -- Li1 := Index'succ (Li1);
3920 -- Ri1 := Index'succ (Ri1);
3925 procedure Build_Slice_Assignment
(Typ
: Entity_Id
) is
3926 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3927 Index
: constant Entity_Id
:= Base_Type
(Etype
(First_Index
(Typ
)));
3929 Larray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
3930 Rarray
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3931 Left_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3932 Left_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3933 Right_Lo
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3934 Right_Hi
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3935 Rev
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
3936 -- Formal parameters of procedure
3938 Proc_Name
: constant Entity_Id
:=
3939 Make_Defining_Identifier
(Loc
,
3940 Chars
=> Make_TSS_Name
(Typ
, TSS_Slice_Assign
));
3942 Lnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
3943 Rnn
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3944 -- Subscripts for left and right sides
3951 -- Build declarations for indexes
3956 Make_Object_Declaration
(Loc
,
3957 Defining_Identifier
=> Lnn
,
3958 Object_Definition
=>
3959 New_Occurrence_Of
(Index
, Loc
)));
3962 Make_Object_Declaration
(Loc
,
3963 Defining_Identifier
=> Rnn
,
3964 Object_Definition
=>
3965 New_Occurrence_Of
(Index
, Loc
)));
3969 -- Build test for empty slice case
3972 Make_If_Statement
(Loc
,
3975 Left_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
),
3976 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, Loc
)),
3977 Then_Statements
=> New_List
(Make_Simple_Return_Statement
(Loc
))));
3979 -- Build initializations for indexes
3982 F_Init
: constant List_Id
:= New_List
;
3983 B_Init
: constant List_Id
:= New_List
;
3987 Make_Assignment_Statement
(Loc
,
3988 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3989 Expression
=> New_Occurrence_Of
(Left_Lo
, Loc
)));
3992 Make_Assignment_Statement
(Loc
,
3993 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
3994 Expression
=> New_Occurrence_Of
(Right_Lo
, Loc
)));
3997 Make_Assignment_Statement
(Loc
,
3998 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
3999 Expression
=> New_Occurrence_Of
(Left_Hi
, Loc
)));
4002 Make_Assignment_Statement
(Loc
,
4003 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4004 Expression
=> New_Occurrence_Of
(Right_Hi
, Loc
)));
4007 Make_If_Statement
(Loc
,
4008 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4009 Then_Statements
=> B_Init
,
4010 Else_Statements
=> F_Init
));
4013 -- Now construct the assignment statement
4016 Make_Loop_Statement
(Loc
,
4017 Statements
=> New_List
(
4018 Make_Assignment_Statement
(Loc
,
4020 Make_Indexed_Component
(Loc
,
4021 Prefix
=> New_Occurrence_Of
(Larray
, Loc
),
4022 Expressions
=> New_List
(New_Occurrence_Of
(Lnn
, Loc
))),
4024 Make_Indexed_Component
(Loc
,
4025 Prefix
=> New_Occurrence_Of
(Rarray
, Loc
),
4026 Expressions
=> New_List
(New_Occurrence_Of
(Rnn
, Loc
))))),
4027 End_Label
=> Empty
);
4029 -- Build the exit condition and increment/decrement statements
4032 F_Ass
: constant List_Id
:= New_List
;
4033 B_Ass
: constant List_Id
:= New_List
;
4037 Make_Exit_Statement
(Loc
,
4040 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4041 Right_Opnd
=> New_Occurrence_Of
(Left_Hi
, Loc
))));
4044 Make_Assignment_Statement
(Loc
,
4045 Name
=> New_Occurrence_Of
(Lnn
, Loc
),
4047 Make_Attribute_Reference
(Loc
,
4049 New_Occurrence_Of
(Index
, Loc
),
4050 Attribute_Name
=> Name_Succ
,
4051 Expressions
=> New_List
(
4052 New_Occurrence_Of
(Lnn
, Loc
)))));
4055 Make_Assignment_Statement
(Loc
,
4056 Name
=> New_Occurrence_Of
(Rnn
, Loc
),
4058 Make_Attribute_Reference
(Loc
,
4060 New_Occurrence_Of
(Index
, Loc
),
4061 Attribute_Name
=> Name_Succ
,
4062 Expressions
=> New_List
(
4063 New_Occurrence_Of
(Rnn
, Loc
)))));
4066 Make_Exit_Statement
(Loc
,
4069 Left_Opnd
=> New_Occurrence_Of
(Lnn
, Loc
),
4070 Right_Opnd
=> New_Occurrence_Of
(Left_Lo
, 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_Pred
,
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_Pred
,
4091 Expressions
=> New_List
(
4092 New_Occurrence_Of
(Rnn
, Loc
)))));
4094 Append_To
(Statements
(Loops
),
4095 Make_If_Statement
(Loc
,
4096 Condition
=> New_Occurrence_Of
(Rev
, Loc
),
4097 Then_Statements
=> B_Ass
,
4098 Else_Statements
=> F_Ass
));
4101 Append_To
(Stats
, Loops
);
4105 Formals
: List_Id
:= New_List
;
4108 Formals
:= New_List
(
4109 Make_Parameter_Specification
(Loc
,
4110 Defining_Identifier
=> Larray
,
4111 Out_Present
=> True,
4113 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4115 Make_Parameter_Specification
(Loc
,
4116 Defining_Identifier
=> Rarray
,
4118 New_Occurrence_Of
(Base_Type
(Typ
), Loc
)),
4120 Make_Parameter_Specification
(Loc
,
4121 Defining_Identifier
=> Left_Lo
,
4123 New_Occurrence_Of
(Index
, Loc
)),
4125 Make_Parameter_Specification
(Loc
,
4126 Defining_Identifier
=> Left_Hi
,
4128 New_Occurrence_Of
(Index
, Loc
)),
4130 Make_Parameter_Specification
(Loc
,
4131 Defining_Identifier
=> Right_Lo
,
4133 New_Occurrence_Of
(Index
, Loc
)),
4135 Make_Parameter_Specification
(Loc
,
4136 Defining_Identifier
=> Right_Hi
,
4138 New_Occurrence_Of
(Index
, Loc
)));
4141 Make_Parameter_Specification
(Loc
,
4142 Defining_Identifier
=> Rev
,
4144 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
4147 Make_Procedure_Specification
(Loc
,
4148 Defining_Unit_Name
=> Proc_Name
,
4149 Parameter_Specifications
=> Formals
);
4152 Make_Subprogram_Body
(Loc
,
4153 Specification
=> Spec
,
4154 Declarations
=> Decls
,
4155 Handled_Statement_Sequence
=>
4156 Make_Handled_Sequence_Of_Statements
(Loc
,
4157 Statements
=> Stats
)));
4160 Set_TSS
(Typ
, Proc_Name
);
4161 Set_Is_Pure
(Proc_Name
);
4162 end Build_Slice_Assignment
;
4164 -----------------------------
4165 -- Build_Untagged_Equality --
4166 -----------------------------
4168 procedure Build_Untagged_Equality
(Typ
: Entity_Id
) is
4176 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
;
4177 -- Check whether the type T has a user-defined primitive equality. If so
4178 -- return it, else return Empty. If true for a component of Typ, we have
4179 -- to build the primitive equality for it.
4181 ---------------------
4182 -- User_Defined_Eq --
4183 ---------------------
4185 function User_Defined_Eq
(T
: Entity_Id
) return Entity_Id
is
4190 Op
:= TSS
(T
, TSS_Composite_Equality
);
4192 if Present
(Op
) then
4196 Prim
:= First_Elmt
(Collect_Primitive_Operations
(T
));
4197 while Present
(Prim
) loop
4200 if Chars
(Op
) = Name_Op_Eq
4201 and then Etype
(Op
) = Standard_Boolean
4202 and then Etype
(First_Formal
(Op
)) = T
4203 and then Etype
(Next_Formal
(First_Formal
(Op
))) = T
4212 end User_Defined_Eq
;
4214 -- Start of processing for Build_Untagged_Equality
4217 -- If a record component has a primitive equality operation, we must
4218 -- build the corresponding one for the current type.
4221 Comp
:= First_Component
(Typ
);
4222 while Present
(Comp
) loop
4223 if Is_Record_Type
(Etype
(Comp
))
4224 and then Present
(User_Defined_Eq
(Etype
(Comp
)))
4229 Next_Component
(Comp
);
4232 -- If there is a user-defined equality for the type, we do not create
4233 -- the implicit one.
4235 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Typ
));
4237 while Present
(Prim
) loop
4238 if Chars
(Node
(Prim
)) = Name_Op_Eq
4239 and then Comes_From_Source
(Node
(Prim
))
4241 -- Don't we also need to check formal types and return type as in
4242 -- User_Defined_Eq above???
4245 Eq_Op
:= Node
(Prim
);
4253 -- If the type is derived, inherit the operation, if present, from the
4254 -- parent type. It may have been declared after the type derivation. If
4255 -- the parent type itself is derived, it may have inherited an operation
4256 -- that has itself been overridden, so update its alias and related
4257 -- flags. Ditto for inequality.
4259 if No
(Eq_Op
) and then Is_Derived_Type
(Typ
) then
4260 Prim
:= First_Elmt
(Collect_Primitive_Operations
(Etype
(Typ
)));
4261 while Present
(Prim
) loop
4262 if Chars
(Node
(Prim
)) = Name_Op_Eq
then
4263 Copy_TSS
(Node
(Prim
), Typ
);
4267 Op
: constant Entity_Id
:= User_Defined_Eq
(Typ
);
4268 Eq_Op
: constant Entity_Id
:= Node
(Prim
);
4269 NE_Op
: constant Entity_Id
:= Next_Entity
(Eq_Op
);
4272 if Present
(Op
) then
4273 Set_Alias
(Op
, Eq_Op
);
4274 Set_Is_Abstract_Subprogram
4275 (Op
, Is_Abstract_Subprogram
(Eq_Op
));
4277 if Chars
(Next_Entity
(Op
)) = Name_Op_Ne
then
4278 Set_Is_Abstract_Subprogram
4279 (Next_Entity
(Op
), Is_Abstract_Subprogram
(NE_Op
));
4291 -- If not inherited and not user-defined, build body as for a type with
4292 -- tagged components.
4296 Make_Eq_Body
(Typ
, Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4297 Op
:= Defining_Entity
(Decl
);
4301 if Is_Library_Level_Entity
(Typ
) then
4305 end Build_Untagged_Equality
;
4307 -----------------------------------
4308 -- Build_Variant_Record_Equality --
4309 -----------------------------------
4313 -- function _Equality (X, Y : T) return Boolean is
4315 -- -- Compare discriminants
4317 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4321 -- -- Compare components
4323 -- if X.C1 /= Y.C1 or else X.C2 /= Y.C2 or else ... then
4327 -- -- Compare variant part
4331 -- if X.C2 /= Y.C2 or else X.C3 /= Y.C3 or else ... then
4336 -- if X.Cn /= Y.Cn or else ... then
4344 procedure Build_Variant_Record_Equality
(Typ
: Entity_Id
) is
4345 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4347 F
: constant Entity_Id
:=
4348 Make_Defining_Identifier
(Loc
,
4349 Chars
=> Make_TSS_Name
(Typ
, TSS_Composite_Equality
));
4351 X
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_X
);
4352 Y
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_Y
);
4354 Def
: constant Node_Id
:= Parent
(Typ
);
4355 Comps
: constant Node_Id
:= Component_List
(Type_Definition
(Def
));
4356 Stmts
: constant List_Id
:= New_List
;
4357 Pspecs
: constant List_Id
:= New_List
;
4360 -- If we have a variant record with restriction No_Implicit_Conditionals
4361 -- in effect, then we skip building the procedure. This is safe because
4362 -- if we can see the restriction, so can any caller, calls to equality
4363 -- test routines are not allowed for variant records if this restriction
4366 if Restriction_Active
(No_Implicit_Conditionals
) then
4370 -- Derived Unchecked_Union types no longer inherit the equality function
4373 if Is_Derived_Type
(Typ
)
4374 and then not Is_Unchecked_Union
(Typ
)
4375 and then not Has_New_Non_Standard_Rep
(Typ
)
4378 Parent_Eq
: constant Entity_Id
:=
4379 TSS
(Root_Type
(Typ
), TSS_Composite_Equality
);
4381 if Present
(Parent_Eq
) then
4382 Copy_TSS
(Parent_Eq
, Typ
);
4389 Make_Subprogram_Body
(Loc
,
4391 Make_Function_Specification
(Loc
,
4392 Defining_Unit_Name
=> F
,
4393 Parameter_Specifications
=> Pspecs
,
4394 Result_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
)),
4395 Declarations
=> New_List
,
4396 Handled_Statement_Sequence
=>
4397 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
)));
4400 Make_Parameter_Specification
(Loc
,
4401 Defining_Identifier
=> X
,
4402 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4405 Make_Parameter_Specification
(Loc
,
4406 Defining_Identifier
=> Y
,
4407 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
4409 -- Unchecked_Unions require additional machinery to support equality.
4410 -- Two extra parameters (A and B) are added to the equality function
4411 -- parameter list for each discriminant of the type, in order to
4412 -- capture the inferred values of the discriminants in equality calls.
4413 -- The names of the parameters match the names of the corresponding
4414 -- discriminant, with an added suffix.
4416 if Is_Unchecked_Union
(Typ
) then
4419 Discr_Type
: Entity_Id
;
4421 New_Discrs
: Elist_Id
;
4424 New_Discrs
:= New_Elmt_List
;
4426 Discr
:= First_Discriminant
(Typ
);
4427 while Present
(Discr
) loop
4428 Discr_Type
:= Etype
(Discr
);
4429 A
:= Make_Defining_Identifier
(Loc
,
4430 Chars
=> New_External_Name
(Chars
(Discr
), 'A'));
4432 B
:= Make_Defining_Identifier
(Loc
,
4433 Chars
=> New_External_Name
(Chars
(Discr
), 'B'));
4435 -- Add new parameters to the parameter list
4438 Make_Parameter_Specification
(Loc
,
4439 Defining_Identifier
=> A
,
4441 New_Occurrence_Of
(Discr_Type
, Loc
)));
4444 Make_Parameter_Specification
(Loc
,
4445 Defining_Identifier
=> B
,
4447 New_Occurrence_Of
(Discr_Type
, Loc
)));
4449 Append_Elmt
(A
, New_Discrs
);
4451 -- Generate the following code to compare each of the inferred
4459 Make_If_Statement
(Loc
,
4462 Left_Opnd
=> New_Occurrence_Of
(A
, Loc
),
4463 Right_Opnd
=> New_Occurrence_Of
(B
, Loc
)),
4464 Then_Statements
=> New_List
(
4465 Make_Simple_Return_Statement
(Loc
,
4467 New_Occurrence_Of
(Standard_False
, Loc
)))));
4468 Next_Discriminant
(Discr
);
4471 -- Generate component-by-component comparison. Note that we must
4472 -- propagate the inferred discriminants formals to act as
4473 -- the case statement switch. Their value is added when an
4474 -- equality call on unchecked unions is expanded.
4476 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
, New_Discrs
));
4479 -- Normal case (not unchecked union)
4483 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
4484 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
4488 Make_Simple_Return_Statement
(Loc
,
4489 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
4494 if not Debug_Generated_Code
then
4495 Set_Debug_Info_Off
(F
);
4497 end Build_Variant_Record_Equality
;
4499 -----------------------------
4500 -- Check_Stream_Attributes --
4501 -----------------------------
4503 procedure Check_Stream_Attributes
(Typ
: Entity_Id
) is
4505 Par_Read
: constant Boolean :=
4506 Stream_Attribute_Available
(Typ
, TSS_Stream_Read
)
4507 and then not Has_Specified_Stream_Read
(Typ
);
4508 Par_Write
: constant Boolean :=
4509 Stream_Attribute_Available
(Typ
, TSS_Stream_Write
)
4510 and then not Has_Specified_Stream_Write
(Typ
);
4512 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
);
4513 -- Check that Comp has a user-specified Nam stream attribute
4519 procedure Check_Attr
(Nam
: Name_Id
; TSS_Nam
: TSS_Name_Type
) is
4521 if not Stream_Attribute_Available
(Etype
(Comp
), TSS_Nam
) then
4522 Error_Msg_Name_1
:= Nam
;
4524 ("|component& in limited extension must have% attribute", Comp
);
4528 -- Start of processing for Check_Stream_Attributes
4531 if Par_Read
or else Par_Write
then
4532 Comp
:= First_Component
(Typ
);
4533 while Present
(Comp
) loop
4534 if Comes_From_Source
(Comp
)
4535 and then Original_Record_Component
(Comp
) = Comp
4536 and then Is_Limited_Type
(Etype
(Comp
))
4539 Check_Attr
(Name_Read
, TSS_Stream_Read
);
4543 Check_Attr
(Name_Write
, TSS_Stream_Write
);
4547 Next_Component
(Comp
);
4550 end Check_Stream_Attributes
;
4552 -----------------------------
4553 -- Expand_Record_Extension --
4554 -----------------------------
4556 -- Add a field _parent at the beginning of the record extension. This is
4557 -- used to implement inheritance. Here are some examples of expansion:
4559 -- 1. no discriminants
4560 -- type T2 is new T1 with null record;
4562 -- type T2 is new T1 with record
4566 -- 2. renamed discriminants
4567 -- type T2 (B, C : Int) is new T1 (A => B) with record
4568 -- _Parent : T1 (A => B);
4572 -- 3. inherited discriminants
4573 -- type T2 is new T1 with record -- discriminant A inherited
4574 -- _Parent : T1 (A);
4578 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
) is
4579 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
4580 Loc
: constant Source_Ptr
:= Sloc
(Def
);
4581 Rec_Ext_Part
: Node_Id
:= Record_Extension_Part
(Def
);
4582 Par_Subtype
: Entity_Id
;
4583 Comp_List
: Node_Id
;
4584 Comp_Decl
: Node_Id
;
4587 List_Constr
: constant List_Id
:= New_List
;
4590 -- Expand_Record_Extension is called directly from the semantics, so
4591 -- we must check to see whether expansion is active before proceeding,
4592 -- because this affects the visibility of selected components in bodies
4595 if not Expander_Active
then
4599 -- This may be a derivation of an untagged private type whose full
4600 -- view is tagged, in which case the Derived_Type_Definition has no
4601 -- extension part. Build an empty one now.
4603 if No
(Rec_Ext_Part
) then
4605 Make_Record_Definition
(Loc
,
4607 Component_List
=> Empty
,
4608 Null_Present
=> True);
4610 Set_Record_Extension_Part
(Def
, Rec_Ext_Part
);
4611 Mark_Rewrite_Insertion
(Rec_Ext_Part
);
4614 Comp_List
:= Component_List
(Rec_Ext_Part
);
4616 Parent_N
:= Make_Defining_Identifier
(Loc
, Name_uParent
);
4618 -- If the derived type inherits its discriminants the type of the
4619 -- _parent field must be constrained by the inherited discriminants
4621 if Has_Discriminants
(T
)
4622 and then Nkind
(Indic
) /= N_Subtype_Indication
4623 and then not Is_Constrained
(Entity
(Indic
))
4625 D
:= First_Discriminant
(T
);
4626 while Present
(D
) loop
4627 Append_To
(List_Constr
, New_Occurrence_Of
(D
, Loc
));
4628 Next_Discriminant
(D
);
4633 Make_Subtype_Indication
(Loc
,
4634 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Indic
), Loc
),
4636 Make_Index_Or_Discriminant_Constraint
(Loc
,
4637 Constraints
=> List_Constr
)),
4640 -- Otherwise the original subtype_indication is just what is needed
4643 Par_Subtype
:= Process_Subtype
(New_Copy_Tree
(Indic
), Def
);
4646 Set_Parent_Subtype
(T
, Par_Subtype
);
4649 Make_Component_Declaration
(Loc
,
4650 Defining_Identifier
=> Parent_N
,
4651 Component_Definition
=>
4652 Make_Component_Definition
(Loc
,
4653 Aliased_Present
=> False,
4654 Subtype_Indication
=> New_Occurrence_Of
(Par_Subtype
, Loc
)));
4656 if Null_Present
(Rec_Ext_Part
) then
4657 Set_Component_List
(Rec_Ext_Part
,
4658 Make_Component_List
(Loc
,
4659 Component_Items
=> New_List
(Comp_Decl
),
4660 Variant_Part
=> Empty
,
4661 Null_Present
=> False));
4662 Set_Null_Present
(Rec_Ext_Part
, False);
4664 elsif Null_Present
(Comp_List
)
4665 or else Is_Empty_List
(Component_Items
(Comp_List
))
4667 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
4668 Set_Null_Present
(Comp_List
, False);
4671 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
4674 Analyze
(Comp_Decl
);
4675 end Expand_Record_Extension
;
4677 ------------------------------------
4678 -- Expand_N_Full_Type_Declaration --
4679 ------------------------------------
4681 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
) is
4682 procedure Build_Master
(Ptr_Typ
: Entity_Id
);
4683 -- Create the master associated with Ptr_Typ
4689 procedure Build_Master
(Ptr_Typ
: Entity_Id
) is
4690 Desig_Typ
: Entity_Id
:= Designated_Type
(Ptr_Typ
);
4693 -- If the designated type is an incomplete view coming from a
4694 -- limited-with'ed package, we need to use the nonlimited view in
4695 -- case it has tasks.
4697 if Ekind
(Desig_Typ
) in Incomplete_Kind
4698 and then Present
(Non_Limited_View
(Desig_Typ
))
4700 Desig_Typ
:= Non_Limited_View
(Desig_Typ
);
4703 -- Anonymous access types are created for the components of the
4704 -- record parameter for an entry declaration. No master is created
4707 if Comes_From_Source
(N
) and then Has_Task
(Desig_Typ
) then
4708 Build_Master_Entity
(Ptr_Typ
);
4709 Build_Master_Renaming
(Ptr_Typ
);
4711 -- Create a class-wide master because a Master_Id must be generated
4712 -- for access-to-limited-class-wide types whose root may be extended
4713 -- with task components.
4715 -- Note: This code covers access-to-limited-interfaces because they
4716 -- can be used to reference tasks implementing them.
4718 elsif Is_Limited_Class_Wide_Type
(Desig_Typ
)
4719 and then Tasking_Allowed
4721 -- Do not create a class-wide master for types whose convention is
4722 -- Java since these types cannot embed Ada tasks anyway. Note that
4723 -- the following test cannot catch the following case:
4725 -- package java.lang.Object is
4726 -- type Typ is tagged limited private;
4727 -- type Ref is access all Typ'Class;
4729 -- type Typ is tagged limited ...;
4730 -- pragma Convention (Typ, Java)
4733 -- Because the convention appears after we have done the
4734 -- processing for type Ref.
4736 and then Convention
(Desig_Typ
) /= Convention_Java
4737 and then Convention
(Desig_Typ
) /= Convention_CIL
4739 Build_Class_Wide_Master
(Ptr_Typ
);
4743 -- Local declarations
4745 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
4746 B_Id
: constant Entity_Id
:= Base_Type
(Def_Id
);
4750 -- Start of processing for Expand_N_Full_Type_Declaration
4753 if Is_Access_Type
(Def_Id
) then
4754 Build_Master
(Def_Id
);
4756 if Ekind
(Def_Id
) = E_Access_Protected_Subprogram_Type
then
4757 Expand_Access_Protected_Subprogram_Type
(N
);
4760 -- Array of anonymous access-to-task pointers
4762 elsif Ada_Version
>= Ada_2005
4763 and then Is_Array_Type
(Def_Id
)
4764 and then Is_Access_Type
(Component_Type
(Def_Id
))
4765 and then Ekind
(Component_Type
(Def_Id
)) = E_Anonymous_Access_Type
4767 Build_Master
(Component_Type
(Def_Id
));
4769 elsif Has_Task
(Def_Id
) then
4770 Expand_Previous_Access_Type
(Def_Id
);
4772 -- Check the components of a record type or array of records for
4773 -- anonymous access-to-task pointers.
4775 elsif Ada_Version
>= Ada_2005
4776 and then (Is_Record_Type
(Def_Id
)
4778 (Is_Array_Type
(Def_Id
)
4779 and then Is_Record_Type
(Component_Type
(Def_Id
))))
4788 if Is_Array_Type
(Def_Id
) then
4789 Comp
:= First_Entity
(Component_Type
(Def_Id
));
4791 Comp
:= First_Entity
(Def_Id
);
4794 -- Examine all components looking for anonymous access-to-task
4798 while Present
(Comp
) loop
4799 Typ
:= Etype
(Comp
);
4801 if Ekind
(Typ
) = E_Anonymous_Access_Type
4802 and then Has_Task
(Available_View
(Designated_Type
(Typ
)))
4803 and then No
(Master_Id
(Typ
))
4805 -- Ensure that the record or array type have a _master
4808 Build_Master_Entity
(Def_Id
);
4809 Build_Master_Renaming
(Typ
);
4810 M_Id
:= Master_Id
(Typ
);
4814 -- Reuse the same master to service any additional types
4817 Set_Master_Id
(Typ
, M_Id
);
4826 Par_Id
:= Etype
(B_Id
);
4828 -- The parent type is private then we need to inherit any TSS operations
4829 -- from the full view.
4831 if Ekind
(Par_Id
) in Private_Kind
4832 and then Present
(Full_View
(Par_Id
))
4834 Par_Id
:= Base_Type
(Full_View
(Par_Id
));
4837 if Nkind
(Type_Definition
(Original_Node
(N
))) =
4838 N_Derived_Type_Definition
4839 and then not Is_Tagged_Type
(Def_Id
)
4840 and then Present
(Freeze_Node
(Par_Id
))
4841 and then Present
(TSS_Elist
(Freeze_Node
(Par_Id
)))
4843 Ensure_Freeze_Node
(B_Id
);
4844 FN
:= Freeze_Node
(B_Id
);
4846 if No
(TSS_Elist
(FN
)) then
4847 Set_TSS_Elist
(FN
, New_Elmt_List
);
4851 T_E
: constant Elist_Id
:= TSS_Elist
(FN
);
4855 Elmt
:= First_Elmt
(TSS_Elist
(Freeze_Node
(Par_Id
)));
4856 while Present
(Elmt
) loop
4857 if Chars
(Node
(Elmt
)) /= Name_uInit
then
4858 Append_Elmt
(Node
(Elmt
), T_E
);
4864 -- If the derived type itself is private with a full view, then
4865 -- associate the full view with the inherited TSS_Elist as well.
4867 if Ekind
(B_Id
) in Private_Kind
4868 and then Present
(Full_View
(B_Id
))
4870 Ensure_Freeze_Node
(Base_Type
(Full_View
(B_Id
)));
4872 (Freeze_Node
(Base_Type
(Full_View
(B_Id
))), TSS_Elist
(FN
));
4876 end Expand_N_Full_Type_Declaration
;
4878 ---------------------------------
4879 -- Expand_N_Object_Declaration --
4880 ---------------------------------
4882 procedure Expand_N_Object_Declaration
(N
: Node_Id
) is
4883 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
4884 Expr
: constant Node_Id
:= Expression
(N
);
4885 Loc
: constant Source_Ptr
:= Sloc
(N
);
4886 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
4887 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
4888 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4891 function Build_Equivalent_Aggregate
return Boolean;
4892 -- If the object has a constrained discriminated type and no initial
4893 -- value, it may be possible to build an equivalent aggregate instead,
4894 -- and prevent an actual call to the initialization procedure.
4896 procedure Default_Initialize_Object
(After
: Node_Id
);
4897 -- Generate all default initialization actions for object Def_Id. Any
4898 -- new code is inserted after node After.
4900 function Rewrite_As_Renaming
return Boolean;
4901 -- Indicate whether to rewrite a declaration with initialization into an
4902 -- object renaming declaration (see below).
4904 --------------------------------
4905 -- Build_Equivalent_Aggregate --
4906 --------------------------------
4908 function Build_Equivalent_Aggregate
return Boolean is
4912 Full_Type
: Entity_Id
;
4917 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
4918 Full_Type
:= Full_View
(Typ
);
4921 -- Only perform this transformation if Elaboration_Code is forbidden
4922 -- or undesirable, and if this is a global entity of a constrained
4925 -- If Initialize_Scalars might be active this transformation cannot
4926 -- be performed either, because it will lead to different semantics
4927 -- or because elaboration code will in fact be created.
4929 if Ekind
(Full_Type
) /= E_Record_Subtype
4930 or else not Has_Discriminants
(Full_Type
)
4931 or else not Is_Constrained
(Full_Type
)
4932 or else Is_Controlled
(Full_Type
)
4933 or else Is_Limited_Type
(Full_Type
)
4934 or else not Restriction_Active
(No_Initialize_Scalars
)
4939 if Ekind
(Current_Scope
) = E_Package
4941 (Restriction_Active
(No_Elaboration_Code
)
4942 or else Is_Preelaborated
(Current_Scope
))
4944 -- Building a static aggregate is possible if the discriminants
4945 -- have static values and the other components have static
4946 -- defaults or none.
4948 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
4949 while Present
(Discr
) loop
4950 if not Is_OK_Static_Expression
(Node
(Discr
)) then
4957 -- Check that initialized components are OK, and that non-
4958 -- initialized components do not require a call to their own
4959 -- initialization procedure.
4961 Comp
:= First_Component
(Full_Type
);
4962 while Present
(Comp
) loop
4963 if Ekind
(Comp
) = E_Component
4964 and then Present
(Expression
(Parent
(Comp
)))
4966 not Is_OK_Static_Expression
(Expression
(Parent
(Comp
)))
4970 elsif Has_Non_Null_Base_Init_Proc
(Etype
(Comp
)) then
4975 Next_Component
(Comp
);
4978 -- Everything is static, assemble the aggregate, discriminant
4982 Make_Aggregate
(Loc
,
4983 Expressions
=> New_List
,
4984 Component_Associations
=> New_List
);
4986 Discr
:= First_Elmt
(Discriminant_Constraint
(Full_Type
));
4987 while Present
(Discr
) loop
4988 Append_To
(Expressions
(Aggr
), New_Copy
(Node
(Discr
)));
4992 -- Now collect values of initialized components
4994 Comp
:= First_Component
(Full_Type
);
4995 while Present
(Comp
) loop
4996 if Ekind
(Comp
) = E_Component
4997 and then Present
(Expression
(Parent
(Comp
)))
4999 Append_To
(Component_Associations
(Aggr
),
5000 Make_Component_Association
(Loc
,
5001 Choices
=> New_List
(New_Occurrence_Of
(Comp
, Loc
)),
5002 Expression
=> New_Copy_Tree
5003 (Expression
(Parent
(Comp
)))));
5006 Next_Component
(Comp
);
5009 -- Finally, box-initialize remaining components
5011 Append_To
(Component_Associations
(Aggr
),
5012 Make_Component_Association
(Loc
,
5013 Choices
=> New_List
(Make_Others_Choice
(Loc
)),
5014 Expression
=> Empty
));
5015 Set_Box_Present
(Last
(Component_Associations
(Aggr
)));
5016 Set_Expression
(N
, Aggr
);
5018 if Typ
/= Full_Type
then
5019 Analyze_And_Resolve
(Aggr
, Full_View
(Base_Type
(Full_Type
)));
5020 Rewrite
(Aggr
, Unchecked_Convert_To
(Typ
, Aggr
));
5021 Analyze_And_Resolve
(Aggr
, Typ
);
5023 Analyze_And_Resolve
(Aggr
, Full_Type
);
5031 end Build_Equivalent_Aggregate
;
5033 -------------------------------
5034 -- Default_Initialize_Object --
5035 -------------------------------
5037 procedure Default_Initialize_Object
(After
: Node_Id
) is
5038 function New_Object_Reference
return Node_Id
;
5039 -- Return a new reference to Def_Id with attributes Assignment_OK and
5040 -- Must_Not_Freeze already set.
5042 --------------------------
5043 -- New_Object_Reference --
5044 --------------------------
5046 function New_Object_Reference
return Node_Id
is
5047 Obj_Ref
: constant Node_Id
:= New_Occurrence_Of
(Def_Id
, Loc
);
5050 -- The call to the type init proc or [Deep_]Finalize must not
5051 -- freeze the related object as the call is internally generated.
5052 -- This way legal rep clauses that apply to the object will not be
5053 -- flagged. Note that the initialization call may be removed if
5054 -- pragma Import is encountered or moved to the freeze actions of
5055 -- the object because of an address clause.
5057 Set_Assignment_OK
(Obj_Ref
);
5058 Set_Must_Not_Freeze
(Obj_Ref
);
5061 end New_Object_Reference
;
5067 Abrt_Id
: Entity_Id
;
5068 Abrt_Stmts
: List_Id
;
5069 Aggr_Init
: Node_Id
;
5070 Comp_Init
: List_Id
:= No_List
;
5072 Fin_Stmts
: List_Id
:= No_List
;
5073 Obj_Init
: Node_Id
:= Empty
;
5077 -- This variable captures a dummy internal entity, see the comment
5078 -- associated with its use.
5080 -- Start of processing for Default_Initialize_Object
5083 -- Default initialization is suppressed for objects that are already
5084 -- known to be imported (i.e. whose declaration specifies the Import
5085 -- aspect). Note that for objects with a pragma Import, we generate
5086 -- initialization here, and then remove it downstream when processing
5087 -- the pragma. It is also suppressed for variables for which a pragma
5088 -- Suppress_Initialization has been explicitly given
5090 if Is_Imported
(Def_Id
) or else Suppress_Initialization
(Def_Id
) then
5094 -- Step 1: Initialize the object
5096 if Needs_Finalization
(Typ
) and then not No_Initialization
(N
) then
5099 (Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
5103 -- Step 2: Initialize the components of the object
5105 -- Do not initialize the components if their initialization is
5106 -- prohibited or the type represents a value type in a .NET VM.
5108 if Has_Non_Null_Base_Init_Proc
(Typ
)
5109 and then not No_Initialization
(N
)
5110 and then not Initialization_Suppressed
(Typ
)
5111 and then not Is_Value_Type
(Typ
)
5113 -- Do not initialize the components if No_Default_Initialization
5114 -- applies as the the actual restriction check will occur later
5115 -- when the object is frozen as it is not known yet whether the
5116 -- object is imported or not.
5118 if not Restriction_Active
(No_Default_Initialization
) then
5120 -- If the values of the components are compile-time known, use
5121 -- their prebuilt aggregate form directly.
5123 Aggr_Init
:= Static_Initialization
(Base_Init_Proc
(Typ
));
5125 if Present
(Aggr_Init
) then
5127 (N
, New_Copy_Tree
(Aggr_Init
, New_Scope
=> Current_Scope
));
5129 -- If type has discriminants, try to build an equivalent
5130 -- aggregate using discriminant values from the declaration.
5131 -- This is a useful optimization, in particular if restriction
5132 -- No_Elaboration_Code is active.
5134 elsif Build_Equivalent_Aggregate
then
5137 -- Otherwise invoke the type init proc
5140 Obj_Ref
:= New_Object_Reference
;
5142 if Comes_From_Source
(Def_Id
) then
5143 Initialization_Warning
(Obj_Ref
);
5146 Comp_Init
:= Build_Initialization_Call
(Loc
, Obj_Ref
, Typ
);
5150 -- Provide a default value if the object needs simple initialization
5151 -- and does not already have an initial value. A generated temporary
5152 -- do not require initialization because it will be assigned later.
5154 elsif Needs_Simple_Initialization
5155 (Typ
, Initialize_Scalars
5156 and then No
(Following_Address_Clause
(N
)))
5157 and then not Is_Internal
(Def_Id
)
5158 and then not Has_Init_Expression
(N
)
5160 Set_No_Initialization
(N
, False);
5161 Set_Expression
(N
, Get_Simple_Init_Val
(Typ
, N
, Esize
(Def_Id
)));
5162 Analyze_And_Resolve
(Expression
(N
), Typ
);
5165 -- Step 3: Add partial finalization and abort actions, generate:
5167 -- Type_Init_Proc (Obj);
5169 -- Deep_Initialize (Obj);
5172 -- Deep_Finalize (Obj, Self => False);
5176 -- Step 3a: Build the finalization block (if applicable)
5178 -- The finalization block is required when both the object and its
5179 -- controlled components are to be initialized. The block finalizes
5180 -- the components if the object initialization fails.
5182 if Has_Controlled_Component
(Typ
)
5183 and then Present
(Comp_Init
)
5184 and then Present
(Obj_Init
)
5185 and then not Restriction_Active
(No_Exception_Propagation
)
5188 -- Type_Init_Proc (Obj);
5190 Fin_Stmts
:= Comp_Init
;
5194 -- Deep_Initialize (Obj);
5197 -- Deep_Finalize (Obj, Self => False);
5203 (Obj_Ref
=> New_Object_Reference
,
5207 if Present
(Fin_Call
) then
5209 -- Do not emit warnings related to the elaboration order when a
5210 -- controlled object is declared before the body of Finalize is
5213 Set_No_Elaboration_Check
(Fin_Call
);
5215 Append_To
(Fin_Stmts
,
5216 Make_Block_Statement
(Loc
,
5217 Declarations
=> No_List
,
5219 Handled_Statement_Sequence
=>
5220 Make_Handled_Sequence_Of_Statements
(Loc
,
5221 Statements
=> New_List
(Obj_Init
),
5223 Exception_Handlers
=> New_List
(
5224 Make_Exception_Handler
(Loc
,
5225 Exception_Choices
=> New_List
(
5226 Make_Others_Choice
(Loc
)),
5228 Statements
=> New_List
(
5230 Make_Raise_Statement
(Loc
)))))));
5233 -- Finalization is not required, the initialization calls are passed
5234 -- to the abort block building circuitry, generate:
5236 -- Type_Init_Proc (Obj);
5237 -- Deep_Initialize (Obj);
5240 if Present
(Comp_Init
) then
5241 Fin_Stmts
:= Comp_Init
;
5244 if Present
(Obj_Init
) then
5245 if No
(Fin_Stmts
) then
5246 Fin_Stmts
:= New_List
;
5249 Append_To
(Fin_Stmts
, Obj_Init
);
5253 -- Step 3b: Build the abort block (if applicable)
5255 -- The abort block is required when aborts are allowed in order to
5256 -- protect both initialization calls.
5258 if Present
(Comp_Init
) and then Present
(Obj_Init
) then
5259 if Abort_Allowed
then
5265 (Fin_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
5270 -- <finalization statements>
5272 -- Abort_Undefer_Direct;
5276 Make_Handled_Sequence_Of_Statements
(Loc
,
5277 Statements
=> Fin_Stmts
,
5279 New_Occurrence_Of
(RTE
(RE_Abort_Undefer_Direct
), Loc
));
5282 Make_Block_Statement
(Loc
,
5283 Declarations
=> No_List
,
5284 Handled_Statement_Sequence
=> Abrt_HSS
);
5286 Add_Block_Identifier
(Abrt_Blk
, Abrt_Id
);
5287 Expand_At_End_Handler
(Abrt_HSS
, Abrt_Id
);
5289 Abrt_Stmts
:= New_List
(Abrt_Blk
);
5291 -- Abort is not required
5294 -- Generate a dummy entity to ensure that the internal symbols
5295 -- are in sync when a unit is compiled with and without aborts.
5296 -- The entity is a block with proper scope and type.
5298 Dummy
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
5299 Set_Etype
(Dummy
, Standard_Void_Type
);
5300 Abrt_Stmts
:= Fin_Stmts
;
5303 -- No initialization calls present
5306 Abrt_Stmts
:= Fin_Stmts
;
5309 -- Step 4: Insert the whole initialization sequence into the tree
5311 Insert_Actions_After
(After
, Abrt_Stmts
);
5312 end Default_Initialize_Object
;
5314 -------------------------
5315 -- Rewrite_As_Renaming --
5316 -------------------------
5318 function Rewrite_As_Renaming
return Boolean is
5320 return not Aliased_Present
(N
)
5321 and then Is_Entity_Name
(Expr_Q
)
5322 and then Ekind
(Entity
(Expr_Q
)) = E_Variable
5323 and then OK_To_Rename
(Entity
(Expr_Q
))
5324 and then Is_Entity_Name
(Obj_Def
);
5325 end Rewrite_As_Renaming
;
5329 Next_N
: constant Node_Id
:= Next
(N
);
5332 Init_After
: Node_Id
:= N
;
5333 -- Node after which the initialization actions are to be inserted. This
5334 -- is normally N, except for the case of a shared passive variable, in
5335 -- which case the init proc call must be inserted only after the bodies
5336 -- of the shared variable procedures have been seen.
5338 Tag_Assign
: Node_Id
;
5340 -- Start of processing for Expand_N_Object_Declaration
5343 -- Don't do anything for deferred constants. All proper actions will be
5344 -- expanded during the full declaration.
5346 if No
(Expr
) and Constant_Present
(N
) then
5350 -- The type of the object cannot be abstract. This is diagnosed at the
5351 -- point the object is frozen, which happens after the declaration is
5352 -- fully expanded, so simply return now.
5354 if Is_Abstract_Type
(Typ
) then
5358 -- First we do special processing for objects of a tagged type where
5359 -- this is the point at which the type is frozen. The creation of the
5360 -- dispatch table and the initialization procedure have to be deferred
5361 -- to this point, since we reference previously declared primitive
5364 -- Force construction of dispatch tables of library level tagged types
5366 if Tagged_Type_Expansion
5367 and then Static_Dispatch_Tables
5368 and then Is_Library_Level_Entity
(Def_Id
)
5369 and then Is_Library_Level_Tagged_Type
(Base_Typ
)
5370 and then Ekind_In
(Base_Typ
, E_Record_Type
,
5373 and then not Has_Dispatch_Table
(Base_Typ
)
5376 New_Nodes
: List_Id
:= No_List
;
5379 if Is_Concurrent_Type
(Base_Typ
) then
5380 New_Nodes
:= Make_DT
(Corresponding_Record_Type
(Base_Typ
), N
);
5382 New_Nodes
:= Make_DT
(Base_Typ
, N
);
5385 if not Is_Empty_List
(New_Nodes
) then
5386 Insert_List_Before
(N
, New_Nodes
);
5391 -- Make shared memory routines for shared passive variable
5393 if Is_Shared_Passive
(Def_Id
) then
5394 Init_After
:= Make_Shared_Var_Procs
(N
);
5397 -- If tasks being declared, make sure we have an activation chain
5398 -- defined for the tasks (has no effect if we already have one), and
5399 -- also that a Master variable is established and that the appropriate
5400 -- enclosing construct is established as a task master.
5402 if Has_Task
(Typ
) then
5403 Build_Activation_Chain_Entity
(N
);
5404 Build_Master_Entity
(Def_Id
);
5407 -- Default initialization required, and no expression present
5411 -- If we have a type with a variant part, the initialization proc
5412 -- will contain implicit tests of the discriminant values, which
5413 -- counts as a violation of the restriction No_Implicit_Conditionals.
5415 if Has_Variant_Part
(Typ
) then
5420 Check_Restriction
(Msg
, No_Implicit_Conditionals
, Obj_Def
);
5424 ("\initialization of variant record tests discriminants",
5431 -- For the default initialization case, if we have a private type
5432 -- with invariants, and invariant checks are enabled, then insert an
5433 -- invariant check after the object declaration. Note that it is OK
5434 -- to clobber the object with an invalid value since if the exception
5435 -- is raised, then the object will go out of scope. In the case where
5436 -- an array object is initialized with an aggregate, the expression
5437 -- is removed. Check flag Has_Init_Expression to avoid generating a
5438 -- junk invariant check and flag No_Initialization to avoid checking
5439 -- an uninitialized object such as a compiler temporary used for an
5442 if Has_Invariants
(Base_Typ
)
5443 and then Present
(Invariant_Procedure
(Base_Typ
))
5444 and then not Has_Init_Expression
(N
)
5445 and then not No_Initialization
(N
)
5448 Make_Invariant_Call
(New_Occurrence_Of
(Def_Id
, Loc
)));
5451 Default_Initialize_Object
(Init_After
);
5453 -- Generate attribute for Persistent_BSS if needed
5455 if Persistent_BSS_Mode
5456 and then Comes_From_Source
(N
)
5457 and then Is_Potentially_Persistent_Type
(Typ
)
5458 and then not Has_Init_Expression
(N
)
5459 and then Is_Library_Level_Entity
(Def_Id
)
5465 Make_Linker_Section_Pragma
5466 (Def_Id
, Sloc
(N
), ".persistent.bss");
5467 Insert_After
(N
, Prag
);
5472 -- If access type, then we know it is null if not initialized
5474 if Is_Access_Type
(Typ
) then
5475 Set_Is_Known_Null
(Def_Id
);
5478 -- Explicit initialization present
5481 -- Obtain actual expression from qualified expression
5483 if Nkind
(Expr
) = N_Qualified_Expression
then
5484 Expr_Q
:= Expression
(Expr
);
5489 -- When we have the appropriate type of aggregate in the expression
5490 -- (it has been determined during analysis of the aggregate by
5491 -- setting the delay flag), let's perform in place assignment and
5492 -- thus avoid creating a temporary.
5494 if Is_Delayed_Aggregate
(Expr_Q
) then
5495 Convert_Aggr_In_Object_Decl
(N
);
5497 -- Ada 2005 (AI-318-02): If the initialization expression is a call
5498 -- to a build-in-place function, then access to the declared object
5499 -- must be passed to the function. Currently we limit such functions
5500 -- to those with constrained limited result subtypes, but eventually
5501 -- plan to expand the allowed forms of functions that are treated as
5504 elsif Ada_Version
>= Ada_2005
5505 and then Is_Build_In_Place_Function_Call
(Expr_Q
)
5507 Make_Build_In_Place_Call_In_Object_Declaration
(N
, Expr_Q
);
5509 -- The previous call expands the expression initializing the
5510 -- built-in-place object into further code that will be analyzed
5511 -- later. No further expansion needed here.
5515 -- Ada 2005 (AI-251): Rewrite the expression that initializes a
5516 -- class-wide interface object to ensure that we copy the full
5517 -- object, unless we are targetting a VM where interfaces are handled
5518 -- by VM itself. Note that if the root type of Typ is an ancestor of
5519 -- Expr's type, both types share the same dispatch table and there is
5520 -- no need to displace the pointer.
5522 elsif Is_Interface
(Typ
)
5524 -- Avoid never-ending recursion because if Equivalent_Type is set
5525 -- then we've done it already and must not do it again.
5528 (Nkind
(Obj_Def
) = N_Identifier
5529 and then Present
(Equivalent_Type
(Entity
(Obj_Def
))))
5531 pragma Assert
(Is_Class_Wide_Type
(Typ
));
5533 -- If the object is a return object of an inherently limited type,
5534 -- which implies build-in-place treatment, bypass the special
5535 -- treatment of class-wide interface initialization below. In this
5536 -- case, the expansion of the return statement will take care of
5537 -- creating the object (via allocator) and initializing it.
5539 if Is_Return_Object
(Def_Id
) and then Is_Limited_View
(Typ
) then
5542 elsif Tagged_Type_Expansion
then
5544 Iface
: constant Entity_Id
:= Root_Type
(Typ
);
5545 Expr_N
: Node_Id
:= Expr
;
5546 Expr_Typ
: Entity_Id
;
5552 -- If the original node of the expression was a conversion
5553 -- to this specific class-wide interface type then restore
5554 -- the original node because we must copy the object before
5555 -- displacing the pointer to reference the secondary tag
5556 -- component. This code must be kept synchronized with the
5557 -- expansion done by routine Expand_Interface_Conversion
5559 if not Comes_From_Source
(Expr_N
)
5560 and then Nkind
(Expr_N
) = N_Explicit_Dereference
5561 and then Nkind
(Original_Node
(Expr_N
)) = N_Type_Conversion
5562 and then Etype
(Original_Node
(Expr_N
)) = Typ
5564 Rewrite
(Expr_N
, Original_Node
(Expression
(N
)));
5567 -- Avoid expansion of redundant interface conversion
5569 if Is_Interface
(Etype
(Expr_N
))
5570 and then Nkind
(Expr_N
) = N_Type_Conversion
5571 and then Etype
(Expr_N
) = Typ
5573 Expr_N
:= Expression
(Expr_N
);
5574 Set_Expression
(N
, Expr_N
);
5577 Obj_Id
:= Make_Temporary
(Loc
, 'D', Expr_N
);
5578 Expr_Typ
:= Base_Type
(Etype
(Expr_N
));
5580 if Is_Class_Wide_Type
(Expr_Typ
) then
5581 Expr_Typ
:= Root_Type
(Expr_Typ
);
5585 -- CW : I'Class := Obj;
5588 -- type Ityp is not null access I'Class;
5589 -- CW : I'Class renames Ityp (Tmp.I_Tag'Address).all;
5591 if Comes_From_Source
(Expr_N
)
5592 and then Nkind
(Expr_N
) = N_Identifier
5593 and then not Is_Interface
(Expr_Typ
)
5594 and then Interface_Present_In_Ancestor
(Expr_Typ
, Typ
)
5595 and then (Expr_Typ
= Etype
(Expr_Typ
)
5597 Is_Variable_Size_Record
(Etype
(Expr_Typ
)))
5602 Make_Object_Declaration
(Loc
,
5603 Defining_Identifier
=> Obj_Id
,
5604 Object_Definition
=>
5605 New_Occurrence_Of
(Expr_Typ
, Loc
),
5606 Expression
=> Relocate_Node
(Expr_N
)));
5608 -- Statically reference the tag associated with the
5612 Make_Selected_Component
(Loc
,
5613 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
5616 (Find_Interface_Tag
(Expr_Typ
, Iface
), Loc
));
5619 -- IW : I'Class := Obj;
5621 -- type Equiv_Record is record ... end record;
5622 -- implicit subtype CW is <Class_Wide_Subtype>;
5623 -- Tmp : CW := CW!(Obj);
5624 -- type Ityp is not null access I'Class;
5625 -- IW : I'Class renames
5626 -- Ityp!(Displace (Temp'Address, I'Tag)).all;
5629 -- Generate the equivalent record type and update the
5630 -- subtype indication to reference it.
5632 Expand_Subtype_From_Expr
5635 Subtype_Indic
=> Obj_Def
,
5638 if not Is_Interface
(Etype
(Expr_N
)) then
5639 New_Expr
:= Relocate_Node
(Expr_N
);
5641 -- For interface types we use 'Address which displaces
5642 -- the pointer to the base of the object (if required)
5646 Unchecked_Convert_To
(Etype
(Obj_Def
),
5647 Make_Explicit_Dereference
(Loc
,
5648 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5649 Make_Attribute_Reference
(Loc
,
5650 Prefix
=> Relocate_Node
(Expr_N
),
5651 Attribute_Name
=> Name_Address
))));
5656 if not Is_Limited_Record
(Expr_Typ
) then
5658 Make_Object_Declaration
(Loc
,
5659 Defining_Identifier
=> Obj_Id
,
5660 Object_Definition
=>
5661 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
5662 Expression
=> New_Expr
));
5664 -- Rename limited type object since they cannot be copied
5665 -- This case occurs when the initialization expression
5666 -- has been previously expanded into a temporary object.
5668 else pragma Assert
(not Comes_From_Source
(Expr_Q
));
5670 Make_Object_Renaming_Declaration
(Loc
,
5671 Defining_Identifier
=> Obj_Id
,
5673 New_Occurrence_Of
(Etype
(Obj_Def
), Loc
),
5675 Unchecked_Convert_To
5676 (Etype
(Obj_Def
), New_Expr
)));
5679 -- Dynamically reference the tag associated with the
5683 Make_Function_Call
(Loc
,
5684 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
5685 Parameter_Associations
=> New_List
(
5686 Make_Attribute_Reference
(Loc
,
5687 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
5688 Attribute_Name
=> Name_Address
),
5690 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
5695 Make_Object_Renaming_Declaration
(Loc
,
5696 Defining_Identifier
=> Make_Temporary
(Loc
, 'D'),
5697 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
5699 Convert_Tag_To_Interface
(Typ
, Tag_Comp
)));
5701 -- If the original entity comes from source, then mark the
5702 -- new entity as needing debug information, even though it's
5703 -- defined by a generated renaming that does not come from
5704 -- source, so that Materialize_Entity will be set on the
5705 -- entity when Debug_Renaming_Declaration is called during
5708 if Comes_From_Source
(Def_Id
) then
5709 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
5712 Analyze
(N
, Suppress
=> All_Checks
);
5714 -- Replace internal identifier of rewritten node by the
5715 -- identifier found in the sources. We also have to exchange
5716 -- entities containing their defining identifiers to ensure
5717 -- the correct replacement of the object declaration by this
5718 -- object renaming declaration because these identifiers
5719 -- were previously added by Enter_Name to the current scope.
5720 -- We must preserve the homonym chain of the source entity
5721 -- as well. We must also preserve the kind of the entity,
5722 -- which may be a constant. Preserve entity chain because
5723 -- itypes may have been generated already, and the full
5724 -- chain must be preserved for final freezing. Finally,
5725 -- preserve Comes_From_Source setting, so that debugging
5726 -- and cross-referencing information is properly kept, and
5727 -- preserve source location, to prevent spurious errors when
5728 -- entities are declared (they must have their own Sloc).
5731 New_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5732 Next_Temp
: constant Entity_Id
:= Next_Entity
(New_Id
);
5733 S_Flag
: constant Boolean :=
5734 Comes_From_Source
(Def_Id
);
5737 Set_Next_Entity
(New_Id
, Next_Entity
(Def_Id
));
5738 Set_Next_Entity
(Def_Id
, Next_Temp
);
5740 Set_Chars
(Defining_Identifier
(N
), Chars
(Def_Id
));
5741 Set_Homonym
(Defining_Identifier
(N
), Homonym
(Def_Id
));
5742 Set_Ekind
(Defining_Identifier
(N
), Ekind
(Def_Id
));
5743 Set_Sloc
(Defining_Identifier
(N
), Sloc
(Def_Id
));
5745 Set_Comes_From_Source
(Def_Id
, False);
5746 Exchange_Entities
(Defining_Identifier
(N
), Def_Id
);
5747 Set_Comes_From_Source
(Def_Id
, S_Flag
);
5754 -- Common case of explicit object initialization
5757 -- In most cases, we must check that the initial value meets any
5758 -- constraint imposed by the declared type. However, there is one
5759 -- very important exception to this rule. If the entity has an
5760 -- unconstrained nominal subtype, then it acquired its constraints
5761 -- from the expression in the first place, and not only does this
5762 -- mean that the constraint check is not needed, but an attempt to
5763 -- perform the constraint check can cause order of elaboration
5766 if not Is_Constr_Subt_For_U_Nominal
(Typ
) then
5768 -- If this is an allocator for an aggregate that has been
5769 -- allocated in place, delay checks until assignments are
5770 -- made, because the discriminants are not initialized.
5772 if Nkind
(Expr
) = N_Allocator
and then No_Initialization
(Expr
)
5776 -- Otherwise apply a constraint check now if no prev error
5778 elsif Nkind
(Expr
) /= N_Error
then
5779 Apply_Constraint_Check
(Expr
, Typ
);
5781 -- Deal with possible range check
5783 if Do_Range_Check
(Expr
) then
5785 -- If assignment checks are suppressed, turn off flag
5787 if Suppress_Assignment_Checks
(N
) then
5788 Set_Do_Range_Check
(Expr
, False);
5790 -- Otherwise generate the range check
5793 Generate_Range_Check
5794 (Expr
, Typ
, CE_Range_Check_Failed
);
5800 -- If the type is controlled and not inherently limited, then
5801 -- the target is adjusted after the copy and attached to the
5802 -- finalization list. However, no adjustment is done in the case
5803 -- where the object was initialized by a call to a function whose
5804 -- result is built in place, since no copy occurred. (Eventually
5805 -- we plan to support in-place function results for some cases
5806 -- of nonlimited types. ???) Similarly, no adjustment is required
5807 -- if we are going to rewrite the object declaration into a
5808 -- renaming declaration.
5810 if Needs_Finalization
(Typ
)
5811 and then not Is_Limited_View
(Typ
)
5812 and then not Rewrite_As_Renaming
5814 Insert_Action_After
(Init_After
,
5816 Obj_Ref
=> New_Occurrence_Of
(Def_Id
, Loc
),
5820 -- For tagged types, when an init value is given, the tag has to
5821 -- be re-initialized separately in order to avoid the propagation
5822 -- of a wrong tag coming from a view conversion unless the type
5823 -- is class wide (in this case the tag comes from the init value).
5824 -- Suppress the tag assignment when VM_Target because VM tags are
5825 -- represented implicitly in objects. Ditto for types that are
5826 -- CPP_CLASS, and for initializations that are aggregates, because
5827 -- they have to have the right tag.
5829 -- The re-assignment of the tag has to be done even if the object
5830 -- is a constant. The assignment must be analyzed after the
5831 -- declaration. If an address clause follows, this is handled as
5832 -- part of the freeze actions for the object, otherwise insert
5833 -- tag assignment here.
5835 Tag_Assign
:= Make_Tag_Assignment
(N
);
5837 if Present
(Tag_Assign
) then
5838 if Present
(Following_Address_Clause
(N
)) then
5839 Ensure_Freeze_Node
(Def_Id
);
5842 Insert_Action_After
(Init_After
, Tag_Assign
);
5845 -- Handle C++ constructor calls. Note that we do not check that
5846 -- Typ is a tagged type since the equivalent Ada type of a C++
5847 -- class that has no virtual methods is an untagged limited
5850 elsif Is_CPP_Constructor_Call
(Expr
) then
5852 -- The call to the initialization procedure does NOT freeze the
5853 -- object being initialized.
5855 Id_Ref
:= New_Occurrence_Of
(Def_Id
, Loc
);
5856 Set_Must_Not_Freeze
(Id_Ref
);
5857 Set_Assignment_OK
(Id_Ref
);
5859 Insert_Actions_After
(Init_After
,
5860 Build_Initialization_Call
(Loc
, Id_Ref
, Typ
,
5861 Constructor_Ref
=> Expr
));
5863 -- We remove here the original call to the constructor
5864 -- to avoid its management in the backend
5866 Set_Expression
(N
, Empty
);
5869 -- Handle initialization of limited tagged types
5871 elsif Is_Tagged_Type
(Typ
)
5872 and then Is_Class_Wide_Type
(Typ
)
5873 and then Is_Limited_Record
(Typ
)
5875 -- Given that the type is limited we cannot perform a copy. If
5876 -- Expr_Q is the reference to a variable we mark the variable
5877 -- as OK_To_Rename to expand this declaration into a renaming
5878 -- declaration (see bellow).
5880 if Is_Entity_Name
(Expr_Q
) then
5881 Set_OK_To_Rename
(Entity
(Expr_Q
));
5883 -- If we cannot convert the expression into a renaming we must
5884 -- consider it an internal error because the backend does not
5885 -- have support to handle it.
5888 pragma Assert
(False);
5889 raise Program_Error
;
5892 -- For discrete types, set the Is_Known_Valid flag if the
5893 -- initializing value is known to be valid. Only do this for
5894 -- source assignments, since otherwise we can end up turning
5895 -- on the known valid flag prematurely from inserted code.
5897 elsif Comes_From_Source
(N
)
5898 and then Is_Discrete_Type
(Typ
)
5899 and then Expr_Known_Valid
(Expr
)
5901 Set_Is_Known_Valid
(Def_Id
);
5903 elsif Is_Access_Type
(Typ
) then
5905 -- For access types set the Is_Known_Non_Null flag if the
5906 -- initializing value is known to be non-null. We can also set
5907 -- Can_Never_Be_Null if this is a constant.
5909 if Known_Non_Null
(Expr
) then
5910 Set_Is_Known_Non_Null
(Def_Id
, True);
5912 if Constant_Present
(N
) then
5913 Set_Can_Never_Be_Null
(Def_Id
);
5918 -- If validity checking on copies, validate initial expression.
5919 -- But skip this if declaration is for a generic type, since it
5920 -- makes no sense to validate generic types. Not clear if this
5921 -- can happen for legal programs, but it definitely can arise
5922 -- from previous instantiation errors.
5924 if Validity_Checks_On
5925 and then Validity_Check_Copies
5926 and then not Is_Generic_Type
(Etype
(Def_Id
))
5928 Ensure_Valid
(Expr
);
5929 Set_Is_Known_Valid
(Def_Id
);
5933 -- Cases where the back end cannot handle the initialization directly
5934 -- In such cases, we expand an assignment that will be appropriately
5935 -- handled by Expand_N_Assignment_Statement.
5937 -- The exclusion of the unconstrained case is wrong, but for now it
5938 -- is too much trouble ???
5940 if (Is_Possibly_Unaligned_Slice
(Expr
)
5941 or else (Is_Possibly_Unaligned_Object
(Expr
)
5942 and then not Represented_As_Scalar
(Etype
(Expr
))))
5943 and then not (Is_Array_Type
(Etype
(Expr
))
5944 and then not Is_Constrained
(Etype
(Expr
)))
5947 Stat
: constant Node_Id
:=
5948 Make_Assignment_Statement
(Loc
,
5949 Name
=> New_Occurrence_Of
(Def_Id
, Loc
),
5950 Expression
=> Relocate_Node
(Expr
));
5952 Set_Expression
(N
, Empty
);
5953 Set_No_Initialization
(N
);
5954 Set_Assignment_OK
(Name
(Stat
));
5955 Set_No_Ctrl_Actions
(Stat
);
5956 Insert_After_And_Analyze
(Init_After
, Stat
);
5960 -- Final transformation, if the initializing expression is an entity
5961 -- for a variable with OK_To_Rename set, then we transform:
5967 -- X : typ renames expr
5969 -- provided that X is not aliased. The aliased case has to be
5970 -- excluded in general because Expr will not be aliased in general.
5972 if Rewrite_As_Renaming
then
5974 Make_Object_Renaming_Declaration
(Loc
,
5975 Defining_Identifier
=> Defining_Identifier
(N
),
5976 Subtype_Mark
=> Obj_Def
,
5979 -- We do not analyze this renaming declaration, because all its
5980 -- components have already been analyzed, and if we were to go
5981 -- ahead and analyze it, we would in effect be trying to generate
5982 -- another declaration of X, which won't do.
5984 Set_Renamed_Object
(Defining_Identifier
(N
), Expr_Q
);
5987 -- We do need to deal with debug issues for this renaming
5989 -- First, if entity comes from source, then mark it as needing
5990 -- debug information, even though it is defined by a generated
5991 -- renaming that does not come from source.
5993 if Comes_From_Source
(Defining_Identifier
(N
)) then
5994 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
5997 -- Now call the routine to generate debug info for the renaming
6000 Decl
: constant Node_Id
:= Debug_Renaming_Declaration
(N
);
6002 if Present
(Decl
) then
6003 Insert_Action
(N
, Decl
);
6009 if Nkind
(N
) = N_Object_Declaration
6010 and then Nkind
(Obj_Def
) = N_Access_Definition
6011 and then not Is_Local_Anonymous_Access
(Etype
(Def_Id
))
6013 -- An Ada 2012 stand-alone object of an anonymous access type
6016 Loc
: constant Source_Ptr
:= Sloc
(N
);
6018 Level
: constant Entity_Id
:=
6019 Make_Defining_Identifier
(Sloc
(N
),
6021 New_External_Name
(Chars
(Def_Id
), Suffix
=> "L"));
6023 Level_Expr
: Node_Id
;
6024 Level_Decl
: Node_Id
;
6027 Set_Ekind
(Level
, Ekind
(Def_Id
));
6028 Set_Etype
(Level
, Standard_Natural
);
6029 Set_Scope
(Level
, Scope
(Def_Id
));
6033 -- Set accessibility level of null
6036 Make_Integer_Literal
(Loc
, Scope_Depth
(Standard_Standard
));
6039 Level_Expr
:= Dynamic_Accessibility_Level
(Expr
);
6043 Make_Object_Declaration
(Loc
,
6044 Defining_Identifier
=> Level
,
6045 Object_Definition
=>
6046 New_Occurrence_Of
(Standard_Natural
, Loc
),
6047 Expression
=> Level_Expr
,
6048 Constant_Present
=> Constant_Present
(N
),
6049 Has_Init_Expression
=> True);
6051 Insert_Action_After
(Init_After
, Level_Decl
);
6053 Set_Extra_Accessibility
(Def_Id
, Level
);
6057 -- At this point the object is fully initialized by either invoking the
6058 -- related type init proc, routine [Deep_]Initialize or performing in-
6059 -- place assingments for an array object. If the related type is subject
6060 -- to pragma Default_Initial_Condition, add a runtime check to verify
6061 -- the assumption of the pragma. Generate:
6063 -- <Base_Typ>Default_Init_Cond (<Base_Typ> (Def_Id));
6065 -- Note that the check is generated for source objects only
6067 if Comes_From_Source
(Def_Id
)
6068 and then (Has_Default_Init_Cond
(Base_Typ
)
6070 Has_Inherited_Default_Init_Cond
(Base_Typ
))
6073 DIC_Call
: constant Node_Id
:=
6074 Build_Default_Init_Cond_Call
(Loc
, Def_Id
, Base_Typ
);
6076 if Present
(Next_N
) then
6077 Insert_Before_And_Analyze
(Next_N
, DIC_Call
);
6079 -- The object declaration is the last node in a declarative or a
6083 Append_To
(List_Containing
(N
), DIC_Call
);
6089 -- Exception on library entity not available
6092 when RE_Not_Available
=>
6094 end Expand_N_Object_Declaration
;
6096 ---------------------------------
6097 -- Expand_N_Subtype_Indication --
6098 ---------------------------------
6100 -- Add a check on the range of the subtype. The static case is partially
6101 -- duplicated by Process_Range_Expr_In_Decl in Sem_Ch3, but we still need
6102 -- to check here for the static case in order to avoid generating
6103 -- extraneous expanded code. Also deal with validity checking.
6105 procedure Expand_N_Subtype_Indication
(N
: Node_Id
) is
6106 Ran
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6107 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
6110 if Nkind
(Constraint
(N
)) = N_Range_Constraint
then
6111 Validity_Check_Range
(Range_Expression
(Constraint
(N
)));
6114 if Nkind_In
(Parent
(N
), N_Constrained_Array_Definition
, N_Slice
) then
6115 Apply_Range_Check
(Ran
, Typ
);
6117 end Expand_N_Subtype_Indication
;
6119 ---------------------------
6120 -- Expand_N_Variant_Part --
6121 ---------------------------
6123 -- Note: this procedure no longer has any effect. It used to be that we
6124 -- would replace the choices in the last variant by a when others, and
6125 -- also expanded static predicates in variant choices here, but both of
6126 -- those activities were being done too early, since we can't check the
6127 -- choices until the statically predicated subtypes are frozen, which can
6128 -- happen as late as the free point of the record, and we can't change the
6129 -- last choice to an others before checking the choices, which is now done
6130 -- at the freeze point of the record.
6132 procedure Expand_N_Variant_Part
(N
: Node_Id
) is
6135 end Expand_N_Variant_Part
;
6137 ---------------------------------
6138 -- Expand_Previous_Access_Type --
6139 ---------------------------------
6141 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
) is
6142 Ptr_Typ
: Entity_Id
;
6145 -- Find all access types in the current scope whose designated type is
6146 -- Def_Id and build master renamings for them.
6148 Ptr_Typ
:= First_Entity
(Current_Scope
);
6149 while Present
(Ptr_Typ
) loop
6150 if Is_Access_Type
(Ptr_Typ
)
6151 and then Designated_Type
(Ptr_Typ
) = Def_Id
6152 and then No
(Master_Id
(Ptr_Typ
))
6154 -- Ensure that the designated type has a master
6156 Build_Master_Entity
(Def_Id
);
6158 -- Private and incomplete types complicate the insertion of master
6159 -- renamings because the access type may precede the full view of
6160 -- the designated type. For this reason, the master renamings are
6161 -- inserted relative to the designated type.
6163 Build_Master_Renaming
(Ptr_Typ
, Ins_Nod
=> Parent
(Def_Id
));
6166 Next_Entity
(Ptr_Typ
);
6168 end Expand_Previous_Access_Type
;
6170 ------------------------
6171 -- Expand_Tagged_Root --
6172 ------------------------
6174 procedure Expand_Tagged_Root
(T
: Entity_Id
) is
6175 Def
: constant Node_Id
:= Type_Definition
(Parent
(T
));
6176 Comp_List
: Node_Id
;
6177 Comp_Decl
: Node_Id
;
6178 Sloc_N
: Source_Ptr
;
6181 if Null_Present
(Def
) then
6182 Set_Component_List
(Def
,
6183 Make_Component_List
(Sloc
(Def
),
6184 Component_Items
=> Empty_List
,
6185 Variant_Part
=> Empty
,
6186 Null_Present
=> True));
6189 Comp_List
:= Component_List
(Def
);
6191 if Null_Present
(Comp_List
)
6192 or else Is_Empty_List
(Component_Items
(Comp_List
))
6194 Sloc_N
:= Sloc
(Comp_List
);
6196 Sloc_N
:= Sloc
(First
(Component_Items
(Comp_List
)));
6200 Make_Component_Declaration
(Sloc_N
,
6201 Defining_Identifier
=> First_Tag_Component
(T
),
6202 Component_Definition
=>
6203 Make_Component_Definition
(Sloc_N
,
6204 Aliased_Present
=> False,
6205 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RE_Tag
), Sloc_N
)));
6207 if Null_Present
(Comp_List
)
6208 or else Is_Empty_List
(Component_Items
(Comp_List
))
6210 Set_Component_Items
(Comp_List
, New_List
(Comp_Decl
));
6211 Set_Null_Present
(Comp_List
, False);
6214 Insert_Before
(First
(Component_Items
(Comp_List
)), Comp_Decl
);
6217 -- We don't Analyze the whole expansion because the tag component has
6218 -- already been analyzed previously. Here we just insure that the tree
6219 -- is coherent with the semantic decoration
6221 Find_Type
(Subtype_Indication
(Component_Definition
(Comp_Decl
)));
6224 when RE_Not_Available
=>
6226 end Expand_Tagged_Root
;
6228 ----------------------
6229 -- Clean_Task_Names --
6230 ----------------------
6232 procedure Clean_Task_Names
6234 Proc_Id
: Entity_Id
)
6238 and then not Restriction_Active
(No_Implicit_Heap_Allocations
)
6239 and then not Global_Discard_Names
6240 and then Tagged_Type_Expansion
6242 Set_Uses_Sec_Stack
(Proc_Id
);
6244 end Clean_Task_Names
;
6246 ------------------------------
6247 -- Expand_Freeze_Array_Type --
6248 ------------------------------
6250 procedure Expand_Freeze_Array_Type
(N
: Node_Id
) is
6251 Typ
: constant Entity_Id
:= Entity
(N
);
6252 Comp_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
6253 Base
: constant Entity_Id
:= Base_Type
(Typ
);
6256 if not Is_Bit_Packed_Array
(Typ
) then
6258 -- If the component contains tasks, so does the array type. This may
6259 -- not be indicated in the array type because the component may have
6260 -- been a private type at the point of definition. Same if component
6261 -- type is controlled or contains protected objects.
6263 Set_Has_Task
(Base
, Has_Task
(Comp_Typ
));
6264 Set_Has_Protected
(Base
, Has_Protected
(Comp_Typ
));
6265 Set_Has_Controlled_Component
6266 (Base
, Has_Controlled_Component
6269 Is_Controlled
(Comp_Typ
));
6271 if No
(Init_Proc
(Base
)) then
6273 -- If this is an anonymous array created for a declaration with
6274 -- an initial value, its init_proc will never be called. The
6275 -- initial value itself may have been expanded into assignments,
6276 -- in which case the object declaration is carries the
6277 -- No_Initialization flag.
6280 and then Nkind
(Associated_Node_For_Itype
(Base
)) =
6281 N_Object_Declaration
6283 (Present
(Expression
(Associated_Node_For_Itype
(Base
)))
6284 or else No_Initialization
(Associated_Node_For_Itype
(Base
)))
6288 -- We do not need an init proc for string or wide [wide] string,
6289 -- since the only time these need initialization in normalize or
6290 -- initialize scalars mode, and these types are treated specially
6291 -- and do not need initialization procedures.
6293 elsif Is_Standard_String_Type
(Base
) then
6296 -- Otherwise we have to build an init proc for the subtype
6299 Build_Array_Init_Proc
(Base
, N
);
6304 if Has_Controlled_Component
(Base
) then
6305 Build_Controlling_Procs
(Base
);
6307 if not Is_Limited_Type
(Comp_Typ
)
6308 and then Number_Dimensions
(Typ
) = 1
6310 Build_Slice_Assignment
(Typ
);
6314 -- Create a finalization master to service the anonymous access
6315 -- components of the array.
6317 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
6318 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
6320 Build_Finalization_Master
6322 Ins_Node
=> Parent
(Typ
),
6323 Encl_Scope
=> Scope
(Typ
));
6327 -- For packed case, default initialization, except if the component type
6328 -- is itself a packed structure with an initialization procedure, or
6329 -- initialize/normalize scalars active, and we have a base type, or the
6330 -- type is public, because in that case a client might specify
6331 -- Normalize_Scalars and there better be a public Init_Proc for it.
6333 elsif (Present
(Init_Proc
(Component_Type
(Base
)))
6334 and then No
(Base_Init_Proc
(Base
)))
6335 or else (Init_Or_Norm_Scalars
and then Base
= Typ
)
6336 or else Is_Public
(Typ
)
6338 Build_Array_Init_Proc
(Base
, N
);
6341 if Has_Invariants
(Component_Type
(Base
))
6343 and then In_Open_Scopes
(Scope
(Component_Type
(Base
)))
6345 -- Generate component invariant checking procedure. This is only
6346 -- relevant if the array type is within the scope of the component
6347 -- type. Otherwise an array object can only be built using the public
6348 -- subprograms for the component type, and calls to those will have
6349 -- invariant checks. The invariant procedure is only generated for
6350 -- a base type, not a subtype.
6352 Insert_Component_Invariant_Checks
6353 (N
, Base
, Build_Array_Invariant_Proc
(Base
, N
));
6355 end Expand_Freeze_Array_Type
;
6357 -----------------------------------
6358 -- Expand_Freeze_Class_Wide_Type --
6359 -----------------------------------
6361 procedure Expand_Freeze_Class_Wide_Type
(N
: Node_Id
) is
6362 Typ
: constant Entity_Id
:= Entity
(N
);
6363 Root
: constant Entity_Id
:= Root_Type
(Typ
);
6365 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean;
6366 -- Given a type, determine whether it is derived from a C or C++ root
6368 ---------------------
6369 -- Is_C_Derivation --
6370 ---------------------
6372 function Is_C_Derivation
(Typ
: Entity_Id
) return Boolean is
6373 T
: Entity_Id
:= Typ
;
6378 or else Convention
(T
) = Convention_C
6379 or else Convention
(T
) = Convention_CPP
6384 exit when T
= Etype
(T
);
6390 end Is_C_Derivation
;
6392 -- Start of processing for Expand_Freeze_Class_Wide_Type
6395 -- Certain run-time configurations and targets do not provide support
6396 -- for controlled types.
6398 if Restriction_Active
(No_Finalization
) then
6401 -- Do not create TSS routine Finalize_Address when dispatching calls are
6402 -- disabled since the core of the routine is a dispatching call.
6404 elsif Restriction_Active
(No_Dispatching_Calls
) then
6407 -- Do not create TSS routine Finalize_Address for concurrent class-wide
6408 -- types. Ignore C, C++, CIL and Java types since it is assumed that the
6409 -- non-Ada side will handle their destruction.
6411 elsif Is_Concurrent_Type
(Root
)
6412 or else Is_C_Derivation
(Root
)
6413 or else Convention
(Typ
) = Convention_CIL
6414 or else Convention
(Typ
) = Convention_CPP
6415 or else Convention
(Typ
) = Convention_Java
6419 -- Do not create TSS routine Finalize_Address for .NET/JVM because these
6420 -- targets do not support address arithmetic and unchecked conversions.
6422 elsif VM_Target
/= No_VM
then
6425 -- Do not create TSS routine Finalize_Address when compiling in CodePeer
6426 -- mode since the routine contains an Unchecked_Conversion.
6428 elsif CodePeer_Mode
then
6432 -- Create the body of TSS primitive Finalize_Address. This automatically
6433 -- sets the TSS entry for the class-wide type.
6435 Make_Finalize_Address_Body
(Typ
);
6436 end Expand_Freeze_Class_Wide_Type
;
6438 ------------------------------------
6439 -- Expand_Freeze_Enumeration_Type --
6440 ------------------------------------
6442 procedure Expand_Freeze_Enumeration_Type
(N
: Node_Id
) is
6443 Typ
: constant Entity_Id
:= Entity
(N
);
6444 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6451 Is_Contiguous
: Boolean;
6456 pragma Warnings
(Off
, Func
);
6459 -- Various optimizations possible if given representation is contiguous
6461 Is_Contiguous
:= True;
6463 Ent
:= First_Literal
(Typ
);
6464 Last_Repval
:= Enumeration_Rep
(Ent
);
6467 while Present
(Ent
) loop
6468 if Enumeration_Rep
(Ent
) - Last_Repval
/= 1 then
6469 Is_Contiguous
:= False;
6472 Last_Repval
:= Enumeration_Rep
(Ent
);
6478 if Is_Contiguous
then
6479 Set_Has_Contiguous_Rep
(Typ
);
6480 Ent
:= First_Literal
(Typ
);
6482 Lst
:= New_List
(New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
6485 -- Build list of literal references
6490 Ent
:= First_Literal
(Typ
);
6491 while Present
(Ent
) loop
6492 Append_To
(Lst
, New_Occurrence_Of
(Ent
, Sloc
(Ent
)));
6498 -- Now build an array declaration
6500 -- typA : array (Natural range 0 .. num - 1) of ctype :=
6501 -- (v, v, v, v, v, ....)
6503 -- where ctype is the corresponding integer type. If the representation
6504 -- is contiguous, we only keep the first literal, which provides the
6505 -- offset for Pos_To_Rep computations.
6508 Make_Defining_Identifier
(Loc
,
6509 Chars
=> New_External_Name
(Chars
(Typ
), 'A'));
6511 Append_Freeze_Action
(Typ
,
6512 Make_Object_Declaration
(Loc
,
6513 Defining_Identifier
=> Arr
,
6514 Constant_Present
=> True,
6516 Object_Definition
=>
6517 Make_Constrained_Array_Definition
(Loc
,
6518 Discrete_Subtype_Definitions
=> New_List
(
6519 Make_Subtype_Indication
(Loc
,
6520 Subtype_Mark
=> New_Occurrence_Of
(Standard_Natural
, Loc
),
6522 Make_Range_Constraint
(Loc
,
6526 Make_Integer_Literal
(Loc
, 0),
6528 Make_Integer_Literal
(Loc
, Num
- 1))))),
6530 Component_Definition
=>
6531 Make_Component_Definition
(Loc
,
6532 Aliased_Present
=> False,
6533 Subtype_Indication
=> New_Occurrence_Of
(Typ
, Loc
))),
6536 Make_Aggregate
(Loc
,
6537 Expressions
=> Lst
)));
6539 Set_Enum_Pos_To_Rep
(Typ
, Arr
);
6541 -- Now we build the function that converts representation values to
6542 -- position values. This function has the form:
6544 -- function _Rep_To_Pos (A : etype; F : Boolean) return Integer is
6547 -- when enum-lit'Enum_Rep => return posval;
6548 -- when enum-lit'Enum_Rep => return posval;
6551 -- [raise Constraint_Error when F "invalid data"]
6556 -- Note: the F parameter determines whether the others case (no valid
6557 -- representation) raises Constraint_Error or returns a unique value
6558 -- of minus one. The latter case is used, e.g. in 'Valid code.
6560 -- Note: the reason we use Enum_Rep values in the case here is to avoid
6561 -- the code generator making inappropriate assumptions about the range
6562 -- of the values in the case where the value is invalid. ityp is a
6563 -- signed or unsigned integer type of appropriate width.
6565 -- Note: if exceptions are not supported, then we suppress the raise
6566 -- and return -1 unconditionally (this is an erroneous program in any
6567 -- case and there is no obligation to raise Constraint_Error here). We
6568 -- also do this if pragma Restrictions (No_Exceptions) is active.
6570 -- Is this right??? What about No_Exception_Propagation???
6572 -- Representations are signed
6574 if Enumeration_Rep
(First_Literal
(Typ
)) < 0 then
6576 -- The underlying type is signed. Reset the Is_Unsigned_Type
6577 -- explicitly, because it might have been inherited from
6580 Set_Is_Unsigned_Type
(Typ
, False);
6582 if Esize
(Typ
) <= Standard_Integer_Size
then
6583 Ityp
:= Standard_Integer
;
6585 Ityp
:= Universal_Integer
;
6588 -- Representations are unsigned
6591 if Esize
(Typ
) <= Standard_Integer_Size
then
6592 Ityp
:= RTE
(RE_Unsigned
);
6594 Ityp
:= RTE
(RE_Long_Long_Unsigned
);
6598 -- The body of the function is a case statement. First collect case
6599 -- alternatives, or optimize the contiguous case.
6603 -- If representation is contiguous, Pos is computed by subtracting
6604 -- the representation of the first literal.
6606 if Is_Contiguous
then
6607 Ent
:= First_Literal
(Typ
);
6609 if Enumeration_Rep
(Ent
) = Last_Repval
then
6611 -- Another special case: for a single literal, Pos is zero
6613 Pos_Expr
:= Make_Integer_Literal
(Loc
, Uint_0
);
6617 Convert_To
(Standard_Integer
,
6618 Make_Op_Subtract
(Loc
,
6620 Unchecked_Convert_To
6621 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
6623 Make_Integer_Literal
(Loc
,
6624 Intval
=> Enumeration_Rep
(First_Literal
(Typ
)))));
6628 Make_Case_Statement_Alternative
(Loc
,
6629 Discrete_Choices
=> New_List
(
6630 Make_Range
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
6632 Make_Integer_Literal
(Loc
,
6633 Intval
=> Enumeration_Rep
(Ent
)),
6635 Make_Integer_Literal
(Loc
, Intval
=> Last_Repval
))),
6637 Statements
=> New_List
(
6638 Make_Simple_Return_Statement
(Loc
,
6639 Expression
=> Pos_Expr
))));
6642 Ent
:= First_Literal
(Typ
);
6643 while Present
(Ent
) loop
6645 Make_Case_Statement_Alternative
(Loc
,
6646 Discrete_Choices
=> New_List
(
6647 Make_Integer_Literal
(Sloc
(Enumeration_Rep_Expr
(Ent
)),
6648 Intval
=> Enumeration_Rep
(Ent
))),
6650 Statements
=> New_List
(
6651 Make_Simple_Return_Statement
(Loc
,
6653 Make_Integer_Literal
(Loc
,
6654 Intval
=> Enumeration_Pos
(Ent
))))));
6660 -- In normal mode, add the others clause with the test
6662 if not No_Exception_Handlers_Set
then
6664 Make_Case_Statement_Alternative
(Loc
,
6665 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6666 Statements
=> New_List
(
6667 Make_Raise_Constraint_Error
(Loc
,
6668 Condition
=> Make_Identifier
(Loc
, Name_uF
),
6669 Reason
=> CE_Invalid_Data
),
6670 Make_Simple_Return_Statement
(Loc
,
6672 Make_Integer_Literal
(Loc
, -1)))));
6674 -- If either of the restrictions No_Exceptions_Handlers/Propagation is
6675 -- active then return -1 (we cannot usefully raise Constraint_Error in
6676 -- this case). See description above for further details.
6680 Make_Case_Statement_Alternative
(Loc
,
6681 Discrete_Choices
=> New_List
(Make_Others_Choice
(Loc
)),
6682 Statements
=> New_List
(
6683 Make_Simple_Return_Statement
(Loc
,
6685 Make_Integer_Literal
(Loc
, -1)))));
6688 -- Now we can build the function body
6691 Make_Defining_Identifier
(Loc
, Make_TSS_Name
(Typ
, TSS_Rep_To_Pos
));
6694 Make_Subprogram_Body
(Loc
,
6696 Make_Function_Specification
(Loc
,
6697 Defining_Unit_Name
=> Fent
,
6698 Parameter_Specifications
=> New_List
(
6699 Make_Parameter_Specification
(Loc
,
6700 Defining_Identifier
=>
6701 Make_Defining_Identifier
(Loc
, Name_uA
),
6702 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
6703 Make_Parameter_Specification
(Loc
,
6704 Defining_Identifier
=>
6705 Make_Defining_Identifier
(Loc
, Name_uF
),
6707 New_Occurrence_Of
(Standard_Boolean
, Loc
))),
6709 Result_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
6711 Declarations
=> Empty_List
,
6713 Handled_Statement_Sequence
=>
6714 Make_Handled_Sequence_Of_Statements
(Loc
,
6715 Statements
=> New_List
(
6716 Make_Case_Statement
(Loc
,
6718 Unchecked_Convert_To
6719 (Ityp
, Make_Identifier
(Loc
, Name_uA
)),
6720 Alternatives
=> Lst
))));
6722 Set_TSS
(Typ
, Fent
);
6724 -- Set Pure flag (it will be reset if the current context is not Pure).
6725 -- We also pretend there was a pragma Pure_Function so that for purposes
6726 -- of optimization and constant-folding, we will consider the function
6727 -- Pure even if we are not in a Pure context).
6730 Set_Has_Pragma_Pure_Function
(Fent
);
6732 -- Unless we are in -gnatD mode, where we are debugging generated code,
6733 -- this is an internal entity for which we don't need debug info.
6735 if not Debug_Generated_Code
then
6736 Set_Debug_Info_Off
(Fent
);
6740 when RE_Not_Available
=>
6742 end Expand_Freeze_Enumeration_Type
;
6744 -------------------------------
6745 -- Expand_Freeze_Record_Type --
6746 -------------------------------
6748 procedure Expand_Freeze_Record_Type
(N
: Node_Id
) is
6749 Def_Id
: constant Node_Id
:= Entity
(N
);
6750 Type_Decl
: constant Node_Id
:= Parent
(Def_Id
);
6752 Comp_Typ
: Entity_Id
;
6754 Predef_List
: List_Id
;
6756 Renamed_Eq
: Node_Id
:= Empty
;
6757 -- Defining unit name for the predefined equality function in the case
6758 -- where the type has a primitive operation that is a renaming of
6759 -- predefined equality (but only if there is also an overriding
6760 -- user-defined equality function). Used to pass this entity from
6761 -- Make_Predefined_Primitive_Specs to Predefined_Primitive_Bodies.
6763 Wrapper_Decl_List
: List_Id
:= No_List
;
6764 Wrapper_Body_List
: List_Id
:= No_List
;
6766 -- Start of processing for Expand_Freeze_Record_Type
6769 -- Build discriminant checking functions if not a derived type (for
6770 -- derived types that are not tagged types, always use the discriminant
6771 -- checking functions of the parent type). However, for untagged types
6772 -- the derivation may have taken place before the parent was frozen, so
6773 -- we copy explicitly the discriminant checking functions from the
6774 -- parent into the components of the derived type.
6776 if not Is_Derived_Type
(Def_Id
)
6777 or else Has_New_Non_Standard_Rep
(Def_Id
)
6778 or else Is_Tagged_Type
(Def_Id
)
6780 Build_Discr_Checking_Funcs
(Type_Decl
);
6782 elsif Is_Derived_Type
(Def_Id
)
6783 and then not Is_Tagged_Type
(Def_Id
)
6785 -- If we have a derived Unchecked_Union, we do not inherit the
6786 -- discriminant checking functions from the parent type since the
6787 -- discriminants are non existent.
6789 and then not Is_Unchecked_Union
(Def_Id
)
6790 and then Has_Discriminants
(Def_Id
)
6793 Old_Comp
: Entity_Id
;
6797 First_Component
(Base_Type
(Underlying_Type
(Etype
(Def_Id
))));
6798 Comp
:= First_Component
(Def_Id
);
6799 while Present
(Comp
) loop
6800 if Ekind
(Comp
) = E_Component
6801 and then Chars
(Comp
) = Chars
(Old_Comp
)
6803 Set_Discriminant_Checking_Func
(Comp
,
6804 Discriminant_Checking_Func
(Old_Comp
));
6807 Next_Component
(Old_Comp
);
6808 Next_Component
(Comp
);
6813 if Is_Derived_Type
(Def_Id
)
6814 and then Is_Limited_Type
(Def_Id
)
6815 and then Is_Tagged_Type
(Def_Id
)
6817 Check_Stream_Attributes
(Def_Id
);
6820 -- Update task, protected, and controlled component flags, because some
6821 -- of the component types may have been private at the point of the
6822 -- record declaration. Detect anonymous access-to-controlled components.
6826 Comp
:= First_Component
(Def_Id
);
6827 while Present
(Comp
) loop
6828 Comp_Typ
:= Etype
(Comp
);
6830 if Has_Task
(Comp_Typ
) then
6831 Set_Has_Task
(Def_Id
);
6834 if Has_Protected
(Comp_Typ
) then
6835 Set_Has_Protected
(Def_Id
);
6838 -- Do not set Has_Controlled_Component on a class-wide equivalent
6839 -- type. See Make_CW_Equivalent_Type.
6841 if not Is_Class_Wide_Equivalent_Type
(Def_Id
)
6842 and then (Has_Controlled_Component
(Comp_Typ
)
6843 or else (Chars
(Comp
) /= Name_uParent
6844 and then Is_Controlled
(Comp_Typ
)))
6846 Set_Has_Controlled_Component
(Def_Id
);
6849 -- Non-self-referential anonymous access-to-controlled component
6851 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
6852 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
6853 and then Designated_Type
(Comp_Typ
) /= Def_Id
6858 Next_Component
(Comp
);
6861 -- Handle constructors of untagged CPP_Class types
6863 if not Is_Tagged_Type
(Def_Id
) and then Is_CPP_Class
(Def_Id
) then
6864 Set_CPP_Constructors
(Def_Id
);
6867 -- Creation of the Dispatch Table. Note that a Dispatch Table is built
6868 -- for regular tagged types as well as for Ada types deriving from a C++
6869 -- Class, but not for tagged types directly corresponding to C++ classes
6870 -- In the later case we assume that it is created in the C++ side and we
6873 if Is_Tagged_Type
(Def_Id
) then
6875 -- Add the _Tag component
6877 if Underlying_Type
(Etype
(Def_Id
)) = Def_Id
then
6878 Expand_Tagged_Root
(Def_Id
);
6881 if Is_CPP_Class
(Def_Id
) then
6882 Set_All_DT_Position
(Def_Id
);
6884 -- Create the tag entities with a minimum decoration
6886 if Tagged_Type_Expansion
then
6887 Append_Freeze_Actions
(Def_Id
, Make_Tags
(Def_Id
));
6890 Set_CPP_Constructors
(Def_Id
);
6893 if not Building_Static_DT
(Def_Id
) then
6895 -- Usually inherited primitives are not delayed but the first
6896 -- Ada extension of a CPP_Class is an exception since the
6897 -- address of the inherited subprogram has to be inserted in
6898 -- the new Ada Dispatch Table and this is a freezing action.
6900 -- Similarly, if this is an inherited operation whose parent is
6901 -- not frozen yet, it is not in the DT of the parent, and we
6902 -- generate an explicit freeze node for the inherited operation
6903 -- so it is properly inserted in the DT of the current type.
6910 Elmt
:= First_Elmt
(Primitive_Operations
(Def_Id
));
6911 while Present
(Elmt
) loop
6912 Subp
:= Node
(Elmt
);
6914 if Present
(Alias
(Subp
)) then
6915 if Is_CPP_Class
(Etype
(Def_Id
)) then
6916 Set_Has_Delayed_Freeze
(Subp
);
6918 elsif Has_Delayed_Freeze
(Alias
(Subp
))
6919 and then not Is_Frozen
(Alias
(Subp
))
6921 Set_Is_Frozen
(Subp
, False);
6922 Set_Has_Delayed_Freeze
(Subp
);
6931 -- Unfreeze momentarily the type to add the predefined primitives
6932 -- operations. The reason we unfreeze is so that these predefined
6933 -- operations will indeed end up as primitive operations (which
6934 -- must be before the freeze point).
6936 Set_Is_Frozen
(Def_Id
, False);
6938 -- Do not add the spec of predefined primitives in case of
6939 -- CPP tagged type derivations that have convention CPP.
6941 if Is_CPP_Class
(Root_Type
(Def_Id
))
6942 and then Convention
(Def_Id
) = Convention_CPP
6946 -- Do not add the spec of predefined primitives in case of
6947 -- CIL and Java tagged types
6949 elsif Convention
(Def_Id
) = Convention_CIL
6950 or else Convention
(Def_Id
) = Convention_Java
6954 -- Do not add the spec of the predefined primitives if we are
6955 -- compiling under restriction No_Dispatching_Calls.
6957 elsif not Restriction_Active
(No_Dispatching_Calls
) then
6958 Make_Predefined_Primitive_Specs
6959 (Def_Id
, Predef_List
, Renamed_Eq
);
6960 Insert_List_Before_And_Analyze
(N
, Predef_List
);
6963 -- Ada 2005 (AI-391): For a nonabstract null extension, create
6964 -- wrapper functions for each nonoverridden inherited function
6965 -- with a controlling result of the type. The wrapper for such
6966 -- a function returns an extension aggregate that invokes the
6969 if Ada_Version
>= Ada_2005
6970 and then not Is_Abstract_Type
(Def_Id
)
6971 and then Is_Null_Extension
(Def_Id
)
6973 Make_Controlling_Function_Wrappers
6974 (Def_Id
, Wrapper_Decl_List
, Wrapper_Body_List
);
6975 Insert_List_Before_And_Analyze
(N
, Wrapper_Decl_List
);
6978 -- Ada 2005 (AI-251): For a nonabstract type extension, build
6979 -- null procedure declarations for each set of homographic null
6980 -- procedures that are inherited from interface types but not
6981 -- overridden. This is done to ensure that the dispatch table
6982 -- entry associated with such null primitives are properly filled.
6984 if Ada_Version
>= Ada_2005
6985 and then Etype
(Def_Id
) /= Def_Id
6986 and then not Is_Abstract_Type
(Def_Id
)
6987 and then Has_Interfaces
(Def_Id
)
6989 Insert_Actions
(N
, Make_Null_Procedure_Specs
(Def_Id
));
6992 Set_Is_Frozen
(Def_Id
);
6993 if not Is_Derived_Type
(Def_Id
)
6994 or else Is_Tagged_Type
(Etype
(Def_Id
))
6996 Set_All_DT_Position
(Def_Id
);
6998 -- If this is a type derived from an untagged private type whose
6999 -- full view is tagged, the type is marked tagged for layout
7000 -- reasons, but it has no dispatch table.
7002 elsif Is_Derived_Type
(Def_Id
)
7003 and then Is_Private_Type
(Etype
(Def_Id
))
7004 and then not Is_Tagged_Type
(Etype
(Def_Id
))
7009 -- Create and decorate the tags. Suppress their creation when
7010 -- VM_Target because the dispatching mechanism is handled
7011 -- internally by the VMs.
7013 if Tagged_Type_Expansion
then
7014 Append_Freeze_Actions
(Def_Id
, Make_Tags
(Def_Id
));
7016 -- Generate dispatch table of locally defined tagged type.
7017 -- Dispatch tables of library level tagged types are built
7018 -- later (see Analyze_Declarations).
7020 if not Building_Static_DT
(Def_Id
) then
7021 Append_Freeze_Actions
(Def_Id
, Make_DT
(Def_Id
));
7024 elsif VM_Target
/= No_VM
then
7025 Append_Freeze_Actions
(Def_Id
, Make_VM_TSD
(Def_Id
));
7028 -- If the type has unknown discriminants, propagate dispatching
7029 -- information to its underlying record view, which does not get
7030 -- its own dispatch table.
7032 if Is_Derived_Type
(Def_Id
)
7033 and then Has_Unknown_Discriminants
(Def_Id
)
7034 and then Present
(Underlying_Record_View
(Def_Id
))
7037 Rep
: constant Entity_Id
:= Underlying_Record_View
(Def_Id
);
7039 Set_Access_Disp_Table
7040 (Rep
, Access_Disp_Table
(Def_Id
));
7041 Set_Dispatch_Table_Wrappers
7042 (Rep
, Dispatch_Table_Wrappers
(Def_Id
));
7043 Set_Direct_Primitive_Operations
7044 (Rep
, Direct_Primitive_Operations
(Def_Id
));
7048 -- Make sure that the primitives Initialize, Adjust and Finalize
7049 -- are Frozen before other TSS subprograms. We don't want them
7052 if Is_Controlled
(Def_Id
) then
7053 if not Is_Limited_Type
(Def_Id
) then
7054 Append_Freeze_Actions
(Def_Id
,
7056 (Find_Prim_Op
(Def_Id
, Name_Adjust
), Def_Id
));
7059 Append_Freeze_Actions
(Def_Id
,
7061 (Find_Prim_Op
(Def_Id
, Name_Initialize
), Def_Id
));
7063 Append_Freeze_Actions
(Def_Id
,
7065 (Find_Prim_Op
(Def_Id
, Name_Finalize
), Def_Id
));
7068 -- Freeze rest of primitive operations. There is no need to handle
7069 -- the predefined primitives if we are compiling under restriction
7070 -- No_Dispatching_Calls.
7072 if not Restriction_Active
(No_Dispatching_Calls
) then
7073 Append_Freeze_Actions
7074 (Def_Id
, Predefined_Primitive_Freeze
(Def_Id
));
7078 -- In the untagged case, ever since Ada 83 an equality function must
7079 -- be provided for variant records that are not unchecked unions.
7080 -- In Ada 2012 the equality function composes, and thus must be built
7081 -- explicitly just as for tagged records.
7083 elsif Has_Discriminants
(Def_Id
)
7084 and then not Is_Limited_Type
(Def_Id
)
7087 Comps
: constant Node_Id
:=
7088 Component_List
(Type_Definition
(Type_Decl
));
7091 and then Present
(Variant_Part
(Comps
))
7093 Build_Variant_Record_Equality
(Def_Id
);
7097 -- Otherwise create primitive equality operation (AI05-0123)
7099 -- This is done unconditionally to ensure that tools can be linked
7100 -- properly with user programs compiled with older language versions.
7101 -- In addition, this is needed because "=" composes for bounded strings
7102 -- in all language versions (see Exp_Ch4.Expand_Composite_Equality).
7104 elsif Comes_From_Source
(Def_Id
)
7105 and then Convention
(Def_Id
) = Convention_Ada
7106 and then not Is_Limited_Type
(Def_Id
)
7108 Build_Untagged_Equality
(Def_Id
);
7111 -- Before building the record initialization procedure, if we are
7112 -- dealing with a concurrent record value type, then we must go through
7113 -- the discriminants, exchanging discriminals between the concurrent
7114 -- type and the concurrent record value type. See the section "Handling
7115 -- of Discriminants" in the Einfo spec for details.
7117 if Is_Concurrent_Record_Type
(Def_Id
)
7118 and then Has_Discriminants
(Def_Id
)
7121 Ctyp
: constant Entity_Id
:=
7122 Corresponding_Concurrent_Type
(Def_Id
);
7123 Conc_Discr
: Entity_Id
;
7124 Rec_Discr
: Entity_Id
;
7128 Conc_Discr
:= First_Discriminant
(Ctyp
);
7129 Rec_Discr
:= First_Discriminant
(Def_Id
);
7130 while Present
(Conc_Discr
) loop
7131 Temp
:= Discriminal
(Conc_Discr
);
7132 Set_Discriminal
(Conc_Discr
, Discriminal
(Rec_Discr
));
7133 Set_Discriminal
(Rec_Discr
, Temp
);
7135 Set_Discriminal_Link
(Discriminal
(Conc_Discr
), Conc_Discr
);
7136 Set_Discriminal_Link
(Discriminal
(Rec_Discr
), Rec_Discr
);
7138 Next_Discriminant
(Conc_Discr
);
7139 Next_Discriminant
(Rec_Discr
);
7144 if Has_Controlled_Component
(Def_Id
) then
7145 Build_Controlling_Procs
(Def_Id
);
7148 Adjust_Discriminants
(Def_Id
);
7150 if Tagged_Type_Expansion
or else not Is_Interface
(Def_Id
) then
7152 -- Do not need init for interfaces on e.g. CIL since they're
7153 -- abstract. Helps operation of peverify (the PE Verify tool).
7155 Build_Record_Init_Proc
(Type_Decl
, Def_Id
);
7158 -- For tagged type that are not interfaces, build bodies of primitive
7159 -- operations. Note: do this after building the record initialization
7160 -- procedure, since the primitive operations may need the initialization
7161 -- routine. There is no need to add predefined primitives of interfaces
7162 -- because all their predefined primitives are abstract.
7164 if Is_Tagged_Type
(Def_Id
) and then not Is_Interface
(Def_Id
) then
7166 -- Do not add the body of predefined primitives in case of CPP tagged
7167 -- type derivations that have convention CPP.
7169 if Is_CPP_Class
(Root_Type
(Def_Id
))
7170 and then Convention
(Def_Id
) = Convention_CPP
7174 -- Do not add the body of predefined primitives in case of CIL and
7175 -- Java tagged types.
7177 elsif Convention
(Def_Id
) = Convention_CIL
7178 or else Convention
(Def_Id
) = Convention_Java
7182 -- Do not add the body of the predefined primitives if we are
7183 -- compiling under restriction No_Dispatching_Calls or if we are
7184 -- compiling a CPP tagged type.
7186 elsif not Restriction_Active
(No_Dispatching_Calls
) then
7188 -- Create the body of TSS primitive Finalize_Address. This must
7189 -- be done before the bodies of all predefined primitives are
7190 -- created. If Def_Id is limited, Stream_Input and Stream_Read
7191 -- may produce build-in-place allocations and for those the
7192 -- expander needs Finalize_Address.
7194 Make_Finalize_Address_Body
(Def_Id
);
7195 Predef_List
:= Predefined_Primitive_Bodies
(Def_Id
, Renamed_Eq
);
7196 Append_Freeze_Actions
(Def_Id
, Predef_List
);
7199 -- Ada 2005 (AI-391): If any wrappers were created for nonoverridden
7200 -- inherited functions, then add their bodies to the freeze actions.
7202 if Present
(Wrapper_Body_List
) then
7203 Append_Freeze_Actions
(Def_Id
, Wrapper_Body_List
);
7206 -- Create extra formals for the primitive operations of the type.
7207 -- This must be done before analyzing the body of the initialization
7208 -- procedure, because a self-referential type might call one of these
7209 -- primitives in the body of the init_proc itself.
7216 Elmt
:= First_Elmt
(Primitive_Operations
(Def_Id
));
7217 while Present
(Elmt
) loop
7218 Subp
:= Node
(Elmt
);
7219 if not Has_Foreign_Convention
(Subp
)
7220 and then not Is_Predefined_Dispatching_Operation
(Subp
)
7222 Create_Extra_Formals
(Subp
);
7230 -- Create a heterogeneous finalization master to service the anonymous
7231 -- access-to-controlled components of the record type.
7235 Encl_Scope
: constant Entity_Id
:= Scope
(Def_Id
);
7236 Ins_Node
: constant Node_Id
:= Parent
(Def_Id
);
7237 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7238 Fin_Mas_Id
: Entity_Id
;
7240 Attributes_Set
: Boolean := False;
7241 Master_Built
: Boolean := False;
7242 -- Two flags which control the creation and initialization of a
7243 -- common heterogeneous master.
7246 Comp
:= First_Component
(Def_Id
);
7247 while Present
(Comp
) loop
7248 Comp_Typ
:= Etype
(Comp
);
7250 -- A non-self-referential anonymous access-to-controlled
7253 if Ekind
(Comp_Typ
) = E_Anonymous_Access_Type
7254 and then Needs_Finalization
(Designated_Type
(Comp_Typ
))
7255 and then Designated_Type
(Comp_Typ
) /= Def_Id
7257 if VM_Target
= No_VM
then
7259 -- Build a homogeneous master for the first anonymous
7260 -- access-to-controlled component. This master may be
7261 -- converted into a heterogeneous collection if more
7262 -- components are to follow.
7264 if not Master_Built
then
7265 Master_Built
:= True;
7267 -- All anonymous access-to-controlled types allocate
7268 -- on the global pool. Note that the finalization
7269 -- master and the associated storage pool must be set
7270 -- on the root type (both are "root type only").
7272 Set_Associated_Storage_Pool
7273 (Root_Type
(Comp_Typ
), RTE
(RE_Global_Pool_Object
));
7275 Build_Finalization_Master
7276 (Typ
=> Root_Type
(Comp_Typ
),
7277 Ins_Node
=> Ins_Node
,
7278 Encl_Scope
=> Encl_Scope
);
7280 Fin_Mas_Id
:= Finalization_Master
(Comp_Typ
);
7282 -- Subsequent anonymous access-to-controlled components
7283 -- reuse the available master.
7286 -- All anonymous access-to-controlled types allocate
7287 -- on the global pool. Note that both the finalization
7288 -- master and the associated storage pool must be set
7289 -- on the root type (both are "root type only").
7291 Set_Associated_Storage_Pool
7292 (Root_Type
(Comp_Typ
), RTE
(RE_Global_Pool_Object
));
7294 -- Shared the master among multiple components
7296 Set_Finalization_Master
7297 (Root_Type
(Comp_Typ
), Fin_Mas_Id
);
7299 -- Convert the master into a heterogeneous collection.
7301 -- Set_Is_Heterogeneous (<Fin_Mas_Id>);
7303 if not Attributes_Set
then
7304 Attributes_Set
:= True;
7306 Insert_Action
(Ins_Node
,
7307 Make_Procedure_Call_Statement
(Loc
,
7310 (RTE
(RE_Set_Is_Heterogeneous
), Loc
),
7311 Parameter_Associations
=> New_List
(
7312 New_Occurrence_Of
(Fin_Mas_Id
, Loc
))));
7316 -- Since .NET/JVM targets do not support heterogeneous
7317 -- masters, each component must have its own master.
7320 Build_Finalization_Master
7322 Ins_Node
=> Ins_Node
,
7323 Encl_Scope
=> Encl_Scope
);
7327 Next_Component
(Comp
);
7332 -- Check whether individual components have a defined invariant, and add
7333 -- the corresponding component invariant checks.
7335 -- Do not create an invariant procedure for some internally generated
7336 -- subtypes, in particular those created for objects of a class-wide
7337 -- type. Such types may have components to which invariant apply, but
7338 -- the corresponding checks will be applied when an object of the parent
7339 -- type is constructed.
7341 -- Such objects will show up in a class-wide postcondition, and the
7342 -- invariant will be checked, if necessary, upon return from the
7343 -- enclosing subprogram.
7345 if not Is_Class_Wide_Equivalent_Type
(Def_Id
) then
7346 Insert_Component_Invariant_Checks
7347 (N
, Def_Id
, Build_Record_Invariant_Proc
(Def_Id
, N
));
7349 end Expand_Freeze_Record_Type
;
7351 ------------------------------
7352 -- Freeze_Stream_Operations --
7353 ------------------------------
7355 procedure Freeze_Stream_Operations
(N
: Node_Id
; Typ
: Entity_Id
) is
7356 Names
: constant array (1 .. 4) of TSS_Name_Type
:=
7361 Stream_Op
: Entity_Id
;
7364 -- Primitive operations of tagged types are frozen when the dispatch
7365 -- table is constructed.
7367 if not Comes_From_Source
(Typ
) or else Is_Tagged_Type
(Typ
) then
7371 for J
in Names
'Range loop
7372 Stream_Op
:= TSS
(Typ
, Names
(J
));
7374 if Present
(Stream_Op
)
7375 and then Is_Subprogram
(Stream_Op
)
7376 and then Nkind
(Unit_Declaration_Node
(Stream_Op
)) =
7377 N_Subprogram_Declaration
7378 and then not Is_Frozen
(Stream_Op
)
7380 Append_Freeze_Actions
(Typ
, Freeze_Entity
(Stream_Op
, N
));
7383 end Freeze_Stream_Operations
;
7389 -- Full type declarations are expanded at the point at which the type is
7390 -- frozen. The formal N is the Freeze_Node for the type. Any statements or
7391 -- declarations generated by the freezing (e.g. the procedure generated
7392 -- for initialization) are chained in the Actions field list of the freeze
7393 -- node using Append_Freeze_Actions.
7395 function Freeze_Type
(N
: Node_Id
) return Boolean is
7396 Def_Id
: constant Entity_Id
:= Entity
(N
);
7397 RACW_Seen
: Boolean := False;
7398 Result
: Boolean := False;
7401 -- Process associated access types needing special processing
7403 if Present
(Access_Types_To_Process
(N
)) then
7405 E
: Elmt_Id
:= First_Elmt
(Access_Types_To_Process
(N
));
7408 while Present
(E
) loop
7409 if Is_Remote_Access_To_Class_Wide_Type
(Node
(E
)) then
7410 Validate_RACW_Primitives
(Node
(E
));
7418 -- If there are RACWs designating this type, make stubs now
7421 Remote_Types_Tagged_Full_View_Encountered
(Def_Id
);
7425 -- Freeze processing for record types
7427 if Is_Record_Type
(Def_Id
) then
7428 if Ekind
(Def_Id
) = E_Record_Type
then
7429 Expand_Freeze_Record_Type
(N
);
7430 elsif Is_Class_Wide_Type
(Def_Id
) then
7431 Expand_Freeze_Class_Wide_Type
(N
);
7434 -- Freeze processing for array types
7436 elsif Is_Array_Type
(Def_Id
) then
7437 Expand_Freeze_Array_Type
(N
);
7439 -- Freeze processing for access types
7441 -- For pool-specific access types, find out the pool object used for
7442 -- this type, needs actual expansion of it in some cases. Here are the
7443 -- different cases :
7445 -- 1. Rep Clause "for Def_Id'Storage_Size use 0;"
7446 -- ---> don't use any storage pool
7448 -- 2. Rep Clause : for Def_Id'Storage_Size use Expr.
7450 -- Def_Id__Pool : Stack_Bounded_Pool (Expr, DT'Size, DT'Alignment);
7452 -- 3. Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7453 -- ---> Storage Pool is the specified one
7455 -- See GNAT Pool packages in the Run-Time for more details
7457 elsif Ekind_In
(Def_Id
, E_Access_Type
, E_General_Access_Type
) then
7459 Loc
: constant Source_Ptr
:= Sloc
(N
);
7460 Desig_Type
: constant Entity_Id
:= Designated_Type
(Def_Id
);
7461 Pool_Object
: Entity_Id
;
7463 Freeze_Action_Typ
: Entity_Id
;
7468 -- Rep Clause "for Def_Id'Storage_Size use 0;"
7469 -- ---> don't use any storage pool
7471 if No_Pool_Assigned
(Def_Id
) then
7476 -- Rep Clause : for Def_Id'Storage_Size use Expr.
7478 -- Def_Id__Pool : Stack_Bounded_Pool
7479 -- (Expr, DT'Size, DT'Alignment);
7481 elsif Has_Storage_Size_Clause
(Def_Id
) then
7487 -- For unconstrained composite types we give a size of zero
7488 -- so that the pool knows that it needs a special algorithm
7489 -- for variable size object allocation.
7491 if Is_Composite_Type
(Desig_Type
)
7492 and then not Is_Constrained
(Desig_Type
)
7494 DT_Size
:= Make_Integer_Literal
(Loc
, 0);
7495 DT_Align
:= Make_Integer_Literal
(Loc
, Maximum_Alignment
);
7499 Make_Attribute_Reference
(Loc
,
7500 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7501 Attribute_Name
=> Name_Max_Size_In_Storage_Elements
);
7504 Make_Attribute_Reference
(Loc
,
7505 Prefix
=> New_Occurrence_Of
(Desig_Type
, Loc
),
7506 Attribute_Name
=> Name_Alignment
);
7510 Make_Defining_Identifier
(Loc
,
7511 Chars
=> New_External_Name
(Chars
(Def_Id
), 'P'));
7513 -- We put the code associated with the pools in the entity
7514 -- that has the later freeze node, usually the access type
7515 -- but it can also be the designated_type; because the pool
7516 -- code requires both those types to be frozen
7518 if Is_Frozen
(Desig_Type
)
7519 and then (No
(Freeze_Node
(Desig_Type
))
7520 or else Analyzed
(Freeze_Node
(Desig_Type
)))
7522 Freeze_Action_Typ
:= Def_Id
;
7524 -- A Taft amendment type cannot get the freeze actions
7525 -- since the full view is not there.
7527 elsif Is_Incomplete_Or_Private_Type
(Desig_Type
)
7528 and then No
(Full_View
(Desig_Type
))
7530 Freeze_Action_Typ
:= Def_Id
;
7533 Freeze_Action_Typ
:= Desig_Type
;
7536 Append_Freeze_Action
(Freeze_Action_Typ
,
7537 Make_Object_Declaration
(Loc
,
7538 Defining_Identifier
=> Pool_Object
,
7539 Object_Definition
=>
7540 Make_Subtype_Indication
(Loc
,
7543 (RTE
(RE_Stack_Bounded_Pool
), Loc
),
7546 Make_Index_Or_Discriminant_Constraint
(Loc
,
7547 Constraints
=> New_List
(
7549 -- First discriminant is the Pool Size
7552 Storage_Size_Variable
(Def_Id
), Loc
),
7554 -- Second discriminant is the element size
7558 -- Third discriminant is the alignment
7563 Set_Associated_Storage_Pool
(Def_Id
, Pool_Object
);
7567 -- Rep Clause "for Def_Id'Storage_Pool use a_Pool_Object"
7568 -- ---> Storage Pool is the specified one
7570 -- When compiling in Ada 2012 mode, ensure that the accessibility
7571 -- level of the subpool access type is not deeper than that of the
7572 -- pool_with_subpools.
7574 elsif Ada_Version
>= Ada_2012
7575 and then Present
(Associated_Storage_Pool
(Def_Id
))
7577 -- Omit this check on .NET/JVM where pools are not supported
7579 and then VM_Target
= No_VM
7581 -- Omit this check for the case of a configurable run-time that
7582 -- does not provide package System.Storage_Pools.Subpools.
7584 and then RTE_Available
(RE_Root_Storage_Pool_With_Subpools
)
7587 Loc
: constant Source_Ptr
:= Sloc
(Def_Id
);
7588 Pool
: constant Entity_Id
:=
7589 Associated_Storage_Pool
(Def_Id
);
7590 RSPWS
: constant Entity_Id
:=
7591 RTE
(RE_Root_Storage_Pool_With_Subpools
);
7594 -- It is known that the accessibility level of the access
7595 -- type is deeper than that of the pool.
7597 if Type_Access_Level
(Def_Id
) > Object_Access_Level
(Pool
)
7598 and then not Accessibility_Checks_Suppressed
(Def_Id
)
7599 and then not Accessibility_Checks_Suppressed
(Pool
)
7601 -- Static case: the pool is known to be a descendant of
7602 -- Root_Storage_Pool_With_Subpools.
7604 if Is_Ancestor
(RSPWS
, Etype
(Pool
)) then
7606 ("??subpool access type has deeper accessibility "
7607 & "level than pool", Def_Id
);
7609 Append_Freeze_Action
(Def_Id
,
7610 Make_Raise_Program_Error
(Loc
,
7611 Reason
=> PE_Accessibility_Check_Failed
));
7613 -- Dynamic case: when the pool is of a class-wide type,
7614 -- it may or may not support subpools depending on the
7615 -- path of derivation. Generate:
7617 -- if Def_Id in RSPWS'Class then
7618 -- raise Program_Error;
7621 elsif Is_Class_Wide_Type
(Etype
(Pool
)) then
7622 Append_Freeze_Action
(Def_Id
,
7623 Make_If_Statement
(Loc
,
7626 Left_Opnd
=> New_Occurrence_Of
(Pool
, Loc
),
7629 (Class_Wide_Type
(RSPWS
), Loc
)),
7631 Then_Statements
=> New_List
(
7632 Make_Raise_Program_Error
(Loc
,
7633 Reason
=> PE_Accessibility_Check_Failed
))));
7639 -- For access-to-controlled types (including class-wide types and
7640 -- Taft-amendment types, which potentially have controlled
7641 -- components), expand the list controller object that will store
7642 -- the dynamically allocated objects. Don't do this transformation
7643 -- for expander-generated access types, but do it for types that
7644 -- are the full view of types derived from other private types.
7645 -- Also suppress the list controller in the case of a designated
7646 -- type with convention Java, since this is used when binding to
7647 -- Java API specs, where there's no equivalent of a finalization
7648 -- list and we don't want to pull in the finalization support if
7651 if not Comes_From_Source
(Def_Id
)
7652 and then not Has_Private_Declaration
(Def_Id
)
7656 -- An exception is made for types defined in the run-time because
7657 -- Ada.Tags.Tag itself is such a type and cannot afford this
7658 -- unnecessary overhead that would generates a loop in the
7659 -- expansion scheme. Another exception is if Restrictions
7660 -- (No_Finalization) is active, since then we know nothing is
7663 elsif Restriction_Active
(No_Finalization
)
7664 or else In_Runtime
(Def_Id
)
7668 -- Assume that incomplete and private types are always completed
7669 -- by a controlled full view.
7671 elsif Needs_Finalization
(Desig_Type
)
7673 (Is_Incomplete_Or_Private_Type
(Desig_Type
)
7674 and then No
(Full_View
(Desig_Type
)))
7676 (Is_Array_Type
(Desig_Type
)
7677 and then Needs_Finalization
(Component_Type
(Desig_Type
)))
7679 Build_Finalization_Master
(Def_Id
);
7683 -- Freeze processing for enumeration types
7685 elsif Ekind
(Def_Id
) = E_Enumeration_Type
then
7687 -- We only have something to do if we have a non-standard
7688 -- representation (i.e. at least one literal whose pos value
7689 -- is not the same as its representation)
7691 if Has_Non_Standard_Rep
(Def_Id
) then
7692 Expand_Freeze_Enumeration_Type
(N
);
7695 -- Private types that are completed by a derivation from a private
7696 -- type have an internally generated full view, that needs to be
7697 -- frozen. This must be done explicitly because the two views share
7698 -- the freeze node, and the underlying full view is not visible when
7699 -- the freeze node is analyzed.
7701 elsif Is_Private_Type
(Def_Id
)
7702 and then Is_Derived_Type
(Def_Id
)
7703 and then Present
(Full_View
(Def_Id
))
7704 and then Is_Itype
(Full_View
(Def_Id
))
7705 and then Has_Private_Declaration
(Full_View
(Def_Id
))
7706 and then Freeze_Node
(Full_View
(Def_Id
)) = N
7708 Set_Entity
(N
, Full_View
(Def_Id
));
7709 Result
:= Freeze_Type
(N
);
7710 Set_Entity
(N
, Def_Id
);
7712 -- All other types require no expander action. There are such cases
7713 -- (e.g. task types and protected types). In such cases, the freeze
7714 -- nodes are there for use by Gigi.
7718 Freeze_Stream_Operations
(N
, Def_Id
);
7722 when RE_Not_Available
=>
7726 -------------------------
7727 -- Get_Simple_Init_Val --
7728 -------------------------
7730 function Get_Simple_Init_Val
7733 Size
: Uint
:= No_Uint
) return Node_Id
7735 Loc
: constant Source_Ptr
:= Sloc
(N
);
7741 -- This is the size to be used for computation of the appropriate
7742 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
7744 IV_Attribute
: constant Boolean :=
7745 Nkind
(N
) = N_Attribute_Reference
7746 and then Attribute_Name
(N
) = Name_Invalid_Value
;
7750 -- These are the values computed by the procedure Check_Subtype_Bounds
7752 procedure Check_Subtype_Bounds
;
7753 -- This procedure examines the subtype T, and its ancestor subtypes and
7754 -- derived types to determine the best known information about the
7755 -- bounds of the subtype. After the call Lo_Bound is set either to
7756 -- No_Uint if no information can be determined, or to a value which
7757 -- represents a known low bound, i.e. a valid value of the subtype can
7758 -- not be less than this value. Hi_Bound is similarly set to a known
7759 -- high bound (valid value cannot be greater than this).
7761 --------------------------
7762 -- Check_Subtype_Bounds --
7763 --------------------------
7765 procedure Check_Subtype_Bounds
is
7774 Lo_Bound
:= No_Uint
;
7775 Hi_Bound
:= No_Uint
;
7777 -- Loop to climb ancestor subtypes and derived types
7781 if not Is_Discrete_Type
(ST1
) then
7785 Lo
:= Type_Low_Bound
(ST1
);
7786 Hi
:= Type_High_Bound
(ST1
);
7788 if Compile_Time_Known_Value
(Lo
) then
7789 Loval
:= Expr_Value
(Lo
);
7791 if Lo_Bound
= No_Uint
or else Lo_Bound
< Loval
then
7796 if Compile_Time_Known_Value
(Hi
) then
7797 Hival
:= Expr_Value
(Hi
);
7799 if Hi_Bound
= No_Uint
or else Hi_Bound
> Hival
then
7804 ST2
:= Ancestor_Subtype
(ST1
);
7810 exit when ST1
= ST2
;
7813 end Check_Subtype_Bounds
;
7815 -- Start of processing for Get_Simple_Init_Val
7818 -- For a private type, we should always have an underlying type (because
7819 -- this was already checked in Needs_Simple_Initialization). What we do
7820 -- is to get the value for the underlying type and then do an unchecked
7821 -- conversion to the private type.
7823 if Is_Private_Type
(T
) then
7824 Val
:= Get_Simple_Init_Val
(Underlying_Type
(T
), N
, Size
);
7826 -- A special case, if the underlying value is null, then qualify it
7827 -- with the underlying type, so that the null is properly typed.
7828 -- Similarly, if it is an aggregate it must be qualified, because an
7829 -- unchecked conversion does not provide a context for it.
7831 if Nkind_In
(Val
, N_Null
, N_Aggregate
) then
7833 Make_Qualified_Expression
(Loc
,
7835 New_Occurrence_Of
(Underlying_Type
(T
), Loc
),
7839 Result
:= Unchecked_Convert_To
(T
, Val
);
7841 -- Don't truncate result (important for Initialize/Normalize_Scalars)
7843 if Nkind
(Result
) = N_Unchecked_Type_Conversion
7844 and then Is_Scalar_Type
(Underlying_Type
(T
))
7846 Set_No_Truncation
(Result
);
7851 -- Scalars with Default_Value aspect. The first subtype may now be
7852 -- private, so retrieve value from underlying type.
7854 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
7855 if Is_Private_Type
(First_Subtype
(T
)) then
7856 return Unchecked_Convert_To
(T
,
7857 Default_Aspect_Value
(Full_View
(First_Subtype
(T
))));
7860 Convert_To
(T
, Default_Aspect_Value
(First_Subtype
(T
)));
7863 -- Otherwise, for scalars, we must have normalize/initialize scalars
7864 -- case, or if the node N is an 'Invalid_Value attribute node.
7866 elsif Is_Scalar_Type
(T
) then
7867 pragma Assert
(Init_Or_Norm_Scalars
or IV_Attribute
);
7869 -- Compute size of object. If it is given by the caller, we can use
7870 -- it directly, otherwise we use Esize (T) as an estimate. As far as
7871 -- we know this covers all cases correctly.
7873 if Size
= No_Uint
or else Size
<= Uint_0
then
7874 Size_To_Use
:= UI_Max
(Uint_1
, Esize
(T
));
7876 Size_To_Use
:= Size
;
7879 -- Maximum size to use is 64 bits, since we will create values of
7880 -- type Unsigned_64 and the range must fit this type.
7882 if Size_To_Use
/= No_Uint
and then Size_To_Use
> Uint_64
then
7883 Size_To_Use
:= Uint_64
;
7886 -- Check known bounds of subtype
7888 Check_Subtype_Bounds
;
7890 -- Processing for Normalize_Scalars case
7892 if Normalize_Scalars
and then not IV_Attribute
then
7894 -- If zero is invalid, it is a convenient value to use that is
7895 -- for sure an appropriate invalid value in all situations.
7897 if Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
7898 Val
:= Make_Integer_Literal
(Loc
, 0);
7900 -- Cases where all one bits is the appropriate invalid value
7902 -- For modular types, all 1 bits is either invalid or valid. If
7903 -- it is valid, then there is nothing that can be done since there
7904 -- are no invalid values (we ruled out zero already).
7906 -- For signed integer types that have no negative values, either
7907 -- there is room for negative values, or there is not. If there
7908 -- is, then all 1-bits may be interpreted as minus one, which is
7909 -- certainly invalid. Alternatively it is treated as the largest
7910 -- positive value, in which case the observation for modular types
7913 -- For float types, all 1-bits is a NaN (not a number), which is
7914 -- certainly an appropriately invalid value.
7916 elsif Is_Unsigned_Type
(T
)
7917 or else Is_Floating_Point_Type
(T
)
7918 or else Is_Enumeration_Type
(T
)
7920 Val
:= Make_Integer_Literal
(Loc
, 2 ** Size_To_Use
- 1);
7922 -- Resolve as Unsigned_64, because the largest number we can
7923 -- generate is out of range of universal integer.
7925 Analyze_And_Resolve
(Val
, RTE
(RE_Unsigned_64
));
7927 -- Case of signed types
7931 Signed_Size
: constant Uint
:=
7932 UI_Min
(Uint_63
, Size_To_Use
- 1);
7935 -- Normally we like to use the most negative number. The one
7936 -- exception is when this number is in the known subtype
7937 -- range and the largest positive number is not in the known
7940 -- For this exceptional case, use largest positive value
7942 if Lo_Bound
/= No_Uint
and then Hi_Bound
/= No_Uint
7943 and then Lo_Bound
<= (-(2 ** Signed_Size
))
7944 and then Hi_Bound
< 2 ** Signed_Size
7946 Val
:= Make_Integer_Literal
(Loc
, 2 ** Signed_Size
- 1);
7948 -- Normal case of largest negative value
7951 Val
:= Make_Integer_Literal
(Loc
, -(2 ** Signed_Size
));
7956 -- Here for Initialize_Scalars case (or Invalid_Value attribute used)
7959 -- For float types, use float values from System.Scalar_Values
7961 if Is_Floating_Point_Type
(T
) then
7962 if Root_Type
(T
) = Standard_Short_Float
then
7963 Val_RE
:= RE_IS_Isf
;
7964 elsif Root_Type
(T
) = Standard_Float
then
7965 Val_RE
:= RE_IS_Ifl
;
7966 elsif Root_Type
(T
) = Standard_Long_Float
then
7967 Val_RE
:= RE_IS_Ilf
;
7968 else pragma Assert
(Root_Type
(T
) = Standard_Long_Long_Float
);
7969 Val_RE
:= RE_IS_Ill
;
7972 -- If zero is invalid, use zero values from System.Scalar_Values
7974 elsif Lo_Bound
/= No_Uint
and then Lo_Bound
> Uint_0
then
7975 if Size_To_Use
<= 8 then
7976 Val_RE
:= RE_IS_Iz1
;
7977 elsif Size_To_Use
<= 16 then
7978 Val_RE
:= RE_IS_Iz2
;
7979 elsif Size_To_Use
<= 32 then
7980 Val_RE
:= RE_IS_Iz4
;
7982 Val_RE
:= RE_IS_Iz8
;
7985 -- For unsigned, use unsigned values from System.Scalar_Values
7987 elsif Is_Unsigned_Type
(T
) then
7988 if Size_To_Use
<= 8 then
7989 Val_RE
:= RE_IS_Iu1
;
7990 elsif Size_To_Use
<= 16 then
7991 Val_RE
:= RE_IS_Iu2
;
7992 elsif Size_To_Use
<= 32 then
7993 Val_RE
:= RE_IS_Iu4
;
7995 Val_RE
:= RE_IS_Iu8
;
7998 -- For signed, use signed values from System.Scalar_Values
8001 if Size_To_Use
<= 8 then
8002 Val_RE
:= RE_IS_Is1
;
8003 elsif Size_To_Use
<= 16 then
8004 Val_RE
:= RE_IS_Is2
;
8005 elsif Size_To_Use
<= 32 then
8006 Val_RE
:= RE_IS_Is4
;
8008 Val_RE
:= RE_IS_Is8
;
8012 Val
:= New_Occurrence_Of
(RTE
(Val_RE
), Loc
);
8015 -- The final expression is obtained by doing an unchecked conversion
8016 -- of this result to the base type of the required subtype. Use the
8017 -- base type to prevent the unchecked conversion from chopping bits,
8018 -- and then we set Kill_Range_Check to preserve the "bad" value.
8020 Result
:= Unchecked_Convert_To
(Base_Type
(T
), Val
);
8022 -- Ensure result is not truncated, since we want the "bad" bits, and
8023 -- also kill range check on result.
8025 if Nkind
(Result
) = N_Unchecked_Type_Conversion
then
8026 Set_No_Truncation
(Result
);
8027 Set_Kill_Range_Check
(Result
, True);
8032 -- String or Wide_[Wide]_String (must have Initialize_Scalars set)
8034 elsif Is_Standard_String_Type
(T
) then
8035 pragma Assert
(Init_Or_Norm_Scalars
);
8038 Make_Aggregate
(Loc
,
8039 Component_Associations
=> New_List
(
8040 Make_Component_Association
(Loc
,
8041 Choices
=> New_List
(
8042 Make_Others_Choice
(Loc
)),
8045 (Component_Type
(T
), N
, Esize
(Root_Type
(T
))))));
8047 -- Access type is initialized to null
8049 elsif Is_Access_Type
(T
) then
8050 return Make_Null
(Loc
);
8052 -- No other possibilities should arise, since we should only be calling
8053 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8054 -- indicating one of the above cases held.
8057 raise Program_Error
;
8061 when RE_Not_Available
=>
8063 end Get_Simple_Init_Val
;
8065 ------------------------------
8066 -- Has_New_Non_Standard_Rep --
8067 ------------------------------
8069 function Has_New_Non_Standard_Rep
(T
: Entity_Id
) return Boolean is
8071 if not Is_Derived_Type
(T
) then
8072 return Has_Non_Standard_Rep
(T
)
8073 or else Has_Non_Standard_Rep
(Root_Type
(T
));
8075 -- If Has_Non_Standard_Rep is not set on the derived type, the
8076 -- representation is fully inherited.
8078 elsif not Has_Non_Standard_Rep
(T
) then
8082 return First_Rep_Item
(T
) /= First_Rep_Item
(Root_Type
(T
));
8084 -- May need a more precise check here: the First_Rep_Item may be a
8085 -- stream attribute, which does not affect the representation of the
8089 end Has_New_Non_Standard_Rep
;
8095 function In_Runtime
(E
: Entity_Id
) return Boolean is
8100 while Scope
(S1
) /= Standard_Standard
loop
8104 return Is_RTU
(S1
, System
) or else Is_RTU
(S1
, Ada
);
8107 ---------------------------------------
8108 -- Insert_Component_Invariant_Checks --
8109 ---------------------------------------
8111 procedure Insert_Component_Invariant_Checks
8116 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8117 Proc_Id
: Entity_Id
;
8120 if Present
(Proc
) then
8121 Proc_Id
:= Defining_Entity
(Proc
);
8123 if not Has_Invariants
(Typ
) then
8124 Set_Has_Invariants
(Typ
);
8125 Set_Is_Invariant_Procedure
(Proc_Id
);
8126 Set_Invariant_Procedure
(Typ
, Proc_Id
);
8127 Insert_After
(N
, Proc
);
8132 -- Find already created invariant subprogram, insert body of
8133 -- component invariant proc in its body, and add call after
8138 Inv_Id
: constant Entity_Id
:= Invariant_Procedure
(Typ
);
8139 Call
: constant Node_Id
:=
8140 Make_Procedure_Call_Statement
(Sloc
(N
),
8141 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
8142 Parameter_Associations
=>
8144 (New_Occurrence_Of
(First_Formal
(Inv_Id
), Loc
)));
8147 -- The invariant body has not been analyzed yet, so we do a
8148 -- sequential search forward, and retrieve it by name.
8151 while Present
(Bod
) loop
8152 exit when Nkind
(Bod
) = N_Subprogram_Body
8153 and then Chars
(Defining_Entity
(Bod
)) = Chars
(Inv_Id
);
8157 -- If the body is not found, it is the case of an invariant
8158 -- appearing on a full declaration in a private part, in
8159 -- which case the type has been frozen but the invariant
8160 -- procedure for the composite type not created yet. Create
8164 Build_Invariant_Procedure
(Typ
, Parent
(Current_Scope
));
8165 Bod
:= Unit_Declaration_Node
8166 (Corresponding_Body
(Unit_Declaration_Node
(Inv_Id
)));
8169 Append_To
(Declarations
(Bod
), Proc
);
8170 Append_To
(Statements
(Handled_Statement_Sequence
(Bod
)), Call
);
8176 end Insert_Component_Invariant_Checks
;
8178 ----------------------------
8179 -- Initialization_Warning --
8180 ----------------------------
8182 procedure Initialization_Warning
(E
: Entity_Id
) is
8183 Warning_Needed
: Boolean;
8186 Warning_Needed
:= False;
8188 if Ekind
(Current_Scope
) = E_Package
8189 and then Static_Elaboration_Desired
(Current_Scope
)
8192 if Is_Record_Type
(E
) then
8193 if Has_Discriminants
(E
)
8194 or else Is_Limited_Type
(E
)
8195 or else Has_Non_Standard_Rep
(E
)
8197 Warning_Needed
:= True;
8200 -- Verify that at least one component has an initialization
8201 -- expression. No need for a warning on a type if all its
8202 -- components have no initialization.
8208 Comp
:= First_Component
(E
);
8209 while Present
(Comp
) loop
8210 if Ekind
(Comp
) = E_Discriminant
8212 (Nkind
(Parent
(Comp
)) = N_Component_Declaration
8213 and then Present
(Expression
(Parent
(Comp
))))
8215 Warning_Needed
:= True;
8219 Next_Component
(Comp
);
8224 if Warning_Needed
then
8226 ("Objects of the type cannot be initialized statically "
8227 & "by default??", Parent
(E
));
8232 Error_Msg_N
("Object cannot be initialized statically??", E
);
8235 end Initialization_Warning
;
8241 function Init_Formals
(Typ
: Entity_Id
) return List_Id
is
8242 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8246 -- First parameter is always _Init : in out typ. Note that we need this
8247 -- to be in/out because in the case of the task record value, there
8248 -- are default record fields (_Priority, _Size, -Task_Info) that may
8249 -- be referenced in the generated initialization routine.
8251 Formals
:= New_List
(
8252 Make_Parameter_Specification
(Loc
,
8253 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uInit
),
8255 Out_Present
=> True,
8256 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8258 -- For task record value, or type that contains tasks, add two more
8259 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8260 -- We also add these parameters for the task record type case.
8263 or else (Is_Record_Type
(Typ
) and then Is_Task_Record_Type
(Typ
))
8266 Make_Parameter_Specification
(Loc
,
8267 Defining_Identifier
=>
8268 Make_Defining_Identifier
(Loc
, Name_uMaster
),
8270 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
)));
8272 -- Add _Chain (not done for sequential elaboration policy, see
8273 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
8275 if Partition_Elaboration_Policy
/= 'S' then
8277 Make_Parameter_Specification
(Loc
,
8278 Defining_Identifier
=>
8279 Make_Defining_Identifier
(Loc
, Name_uChain
),
8281 Out_Present
=> True,
8283 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
)));
8287 Make_Parameter_Specification
(Loc
,
8288 Defining_Identifier
=>
8289 Make_Defining_Identifier
(Loc
, Name_uTask_Name
),
8291 Parameter_Type
=> New_Occurrence_Of
(Standard_String
, Loc
)));
8297 when RE_Not_Available
=>
8301 -------------------------
8302 -- Init_Secondary_Tags --
8303 -------------------------
8305 procedure Init_Secondary_Tags
8308 Stmts_List
: List_Id
;
8309 Fixed_Comps
: Boolean := True;
8310 Variable_Comps
: Boolean := True)
8312 Loc
: constant Source_Ptr
:= Sloc
(Target
);
8314 -- Inherit the C++ tag of the secondary dispatch table of Typ associated
8315 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8317 procedure Initialize_Tag
8320 Tag_Comp
: Entity_Id
;
8321 Iface_Tag
: Node_Id
);
8322 -- Initialize the tag of the secondary dispatch table of Typ associated
8323 -- with Iface. Tag_Comp is the component of Typ that stores Iface_Tag.
8324 -- Compiling under the CPP full ABI compatibility mode, if the ancestor
8325 -- of Typ CPP tagged type we generate code to inherit the contents of
8326 -- the dispatch table directly from the ancestor.
8328 --------------------
8329 -- Initialize_Tag --
8330 --------------------
8332 procedure Initialize_Tag
8335 Tag_Comp
: Entity_Id
;
8336 Iface_Tag
: Node_Id
)
8338 Comp_Typ
: Entity_Id
;
8339 Offset_To_Top_Comp
: Entity_Id
:= Empty
;
8342 -- Initialize pointer to secondary DT associated with the interface
8344 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8345 Append_To
(Stmts_List
,
8346 Make_Assignment_Statement
(Loc
,
8348 Make_Selected_Component
(Loc
,
8349 Prefix
=> New_Copy_Tree
(Target
),
8350 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8352 New_Occurrence_Of
(Iface_Tag
, Loc
)));
8355 Comp_Typ
:= Scope
(Tag_Comp
);
8357 -- Initialize the entries of the table of interfaces. We generate a
8358 -- different call when the parent of the type has variable size
8361 if Comp_Typ
/= Etype
(Comp_Typ
)
8362 and then Is_Variable_Size_Record
(Etype
(Comp_Typ
))
8363 and then Chars
(Tag_Comp
) /= Name_uTag
8365 pragma Assert
(Present
(DT_Offset_To_Top_Func
(Tag_Comp
)));
8367 -- Issue error if Set_Dynamic_Offset_To_Top is not available in a
8368 -- configurable run-time environment.
8370 if not RTE_Available
(RE_Set_Dynamic_Offset_To_Top
) then
8372 ("variable size record with interface types", Typ
);
8377 -- Set_Dynamic_Offset_To_Top
8379 -- Interface_T => Iface'Tag,
8380 -- Offset_Value => n,
8381 -- Offset_Func => Fn'Address)
8383 Append_To
(Stmts_List
,
8384 Make_Procedure_Call_Statement
(Loc
,
8386 New_Occurrence_Of
(RTE
(RE_Set_Dynamic_Offset_To_Top
), Loc
),
8387 Parameter_Associations
=> New_List
(
8388 Make_Attribute_Reference
(Loc
,
8389 Prefix
=> New_Copy_Tree
(Target
),
8390 Attribute_Name
=> Name_Address
),
8392 Unchecked_Convert_To
(RTE
(RE_Tag
),
8394 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))),
8397 Unchecked_Convert_To
8398 (RTE
(RE_Storage_Offset
),
8399 Make_Attribute_Reference
(Loc
,
8401 Make_Selected_Component
(Loc
,
8402 Prefix
=> New_Copy_Tree
(Target
),
8404 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8405 Attribute_Name
=> Name_Position
)),
8407 Unchecked_Convert_To
(RTE
(RE_Offset_To_Top_Function_Ptr
),
8408 Make_Attribute_Reference
(Loc
,
8409 Prefix
=> New_Occurrence_Of
8410 (DT_Offset_To_Top_Func
(Tag_Comp
), Loc
),
8411 Attribute_Name
=> Name_Address
)))));
8413 -- In this case the next component stores the value of the offset
8416 Offset_To_Top_Comp
:= Next_Entity
(Tag_Comp
);
8417 pragma Assert
(Present
(Offset_To_Top_Comp
));
8419 Append_To
(Stmts_List
,
8420 Make_Assignment_Statement
(Loc
,
8422 Make_Selected_Component
(Loc
,
8423 Prefix
=> New_Copy_Tree
(Target
),
8425 New_Occurrence_Of
(Offset_To_Top_Comp
, Loc
)),
8428 Make_Attribute_Reference
(Loc
,
8430 Make_Selected_Component
(Loc
,
8431 Prefix
=> New_Copy_Tree
(Target
),
8432 Selector_Name
=> New_Occurrence_Of
(Tag_Comp
, Loc
)),
8433 Attribute_Name
=> Name_Position
)));
8435 -- Normal case: No discriminants in the parent type
8438 -- Don't need to set any value if this interface shares the
8439 -- primary dispatch table.
8441 if not Is_Ancestor
(Iface
, Typ
, Use_Full_View
=> True) then
8442 Append_To
(Stmts_List
,
8443 Build_Set_Static_Offset_To_Top
(Loc
,
8444 Iface_Tag
=> New_Occurrence_Of
(Iface_Tag
, Loc
),
8446 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8447 Make_Attribute_Reference
(Loc
,
8449 Make_Selected_Component
(Loc
,
8450 Prefix
=> New_Copy_Tree
(Target
),
8452 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8453 Attribute_Name
=> Name_Position
))));
8457 -- Register_Interface_Offset
8459 -- Interface_T => Iface'Tag,
8460 -- Is_Constant => True,
8461 -- Offset_Value => n,
8462 -- Offset_Func => null);
8464 if RTE_Available
(RE_Register_Interface_Offset
) then
8465 Append_To
(Stmts_List
,
8466 Make_Procedure_Call_Statement
(Loc
,
8469 (RTE
(RE_Register_Interface_Offset
), Loc
),
8470 Parameter_Associations
=> New_List
(
8471 Make_Attribute_Reference
(Loc
,
8472 Prefix
=> New_Copy_Tree
(Target
),
8473 Attribute_Name
=> Name_Address
),
8475 Unchecked_Convert_To
(RTE
(RE_Tag
),
8477 (Node
(First_Elmt
(Access_Disp_Table
(Iface
))), Loc
)),
8479 New_Occurrence_Of
(Standard_True
, Loc
),
8481 Unchecked_Convert_To
(RTE
(RE_Storage_Offset
),
8482 Make_Attribute_Reference
(Loc
,
8484 Make_Selected_Component
(Loc
,
8485 Prefix
=> New_Copy_Tree
(Target
),
8487 New_Occurrence_Of
(Tag_Comp
, Loc
)),
8488 Attribute_Name
=> Name_Position
)),
8497 Full_Typ
: Entity_Id
;
8498 Ifaces_List
: Elist_Id
;
8499 Ifaces_Comp_List
: Elist_Id
;
8500 Ifaces_Tag_List
: Elist_Id
;
8501 Iface_Elmt
: Elmt_Id
;
8502 Iface_Comp_Elmt
: Elmt_Id
;
8503 Iface_Tag_Elmt
: Elmt_Id
;
8505 In_Variable_Pos
: Boolean;
8507 -- Start of processing for Init_Secondary_Tags
8510 -- Handle private types
8512 if Present
(Full_View
(Typ
)) then
8513 Full_Typ
:= Full_View
(Typ
);
8518 Collect_Interfaces_Info
8519 (Full_Typ
, Ifaces_List
, Ifaces_Comp_List
, Ifaces_Tag_List
);
8521 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8522 Iface_Comp_Elmt
:= First_Elmt
(Ifaces_Comp_List
);
8523 Iface_Tag_Elmt
:= First_Elmt
(Ifaces_Tag_List
);
8524 while Present
(Iface_Elmt
) loop
8525 Tag_Comp
:= Node
(Iface_Comp_Elmt
);
8527 -- Check if parent of record type has variable size components
8529 In_Variable_Pos
:= Scope
(Tag_Comp
) /= Etype
(Scope
(Tag_Comp
))
8530 and then Is_Variable_Size_Record
(Etype
(Scope
(Tag_Comp
)));
8532 -- If we are compiling under the CPP full ABI compatibility mode and
8533 -- the ancestor is a CPP_Pragma tagged type then we generate code to
8534 -- initialize the secondary tag components from tags that reference
8535 -- secondary tables filled with copy of parent slots.
8537 if Is_CPP_Class
(Root_Type
(Full_Typ
)) then
8539 -- Reject interface components located at variable offset in
8540 -- C++ derivations. This is currently unsupported.
8542 if not Fixed_Comps
and then In_Variable_Pos
then
8544 -- Locate the first dynamic component of the record. Done to
8545 -- improve the text of the warning.
8549 Comp_Typ
: Entity_Id
;
8552 Comp
:= First_Entity
(Typ
);
8553 while Present
(Comp
) loop
8554 Comp_Typ
:= Etype
(Comp
);
8556 if Ekind
(Comp
) /= E_Discriminant
8557 and then not Is_Tag
(Comp
)
8560 (Is_Record_Type
(Comp_Typ
)
8562 Is_Variable_Size_Record
(Base_Type
(Comp_Typ
)))
8564 (Is_Array_Type
(Comp_Typ
)
8565 and then Is_Variable_Size_Array
(Comp_Typ
));
8571 pragma Assert
(Present
(Comp
));
8572 Error_Msg_Node_2
:= Comp
;
8574 ("parent type & with dynamic component & cannot be parent"
8575 & " of 'C'P'P derivation if new interfaces are present",
8576 Typ
, Scope
(Original_Record_Component
(Comp
)));
8579 Sloc
(Scope
(Original_Record_Component
(Comp
)));
8581 ("type derived from 'C'P'P type & defined #",
8582 Typ
, Scope
(Original_Record_Component
(Comp
)));
8584 -- Avoid duplicated warnings
8589 -- Initialize secondary tags
8592 Append_To
(Stmts_List
,
8593 Make_Assignment_Statement
(Loc
,
8595 Make_Selected_Component
(Loc
,
8596 Prefix
=> New_Copy_Tree
(Target
),
8598 New_Occurrence_Of
(Node
(Iface_Comp_Elmt
), Loc
)),
8600 New_Occurrence_Of
(Node
(Iface_Tag_Elmt
), Loc
)));
8603 -- Otherwise generate code to initialize the tag
8606 if (In_Variable_Pos
and then Variable_Comps
)
8607 or else (not In_Variable_Pos
and then Fixed_Comps
)
8609 Initialize_Tag
(Full_Typ
,
8610 Iface
=> Node
(Iface_Elmt
),
8611 Tag_Comp
=> Tag_Comp
,
8612 Iface_Tag
=> Node
(Iface_Tag_Elmt
));
8616 Next_Elmt
(Iface_Elmt
);
8617 Next_Elmt
(Iface_Comp_Elmt
);
8618 Next_Elmt
(Iface_Tag_Elmt
);
8620 end Init_Secondary_Tags
;
8622 ------------------------
8623 -- Is_User_Defined_Eq --
8624 ------------------------
8626 function Is_User_Defined_Equality
(Prim
: Node_Id
) return Boolean is
8628 return Chars
(Prim
) = Name_Op_Eq
8629 and then Etype
(First_Formal
(Prim
)) =
8630 Etype
(Next_Formal
(First_Formal
(Prim
)))
8631 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
;
8632 end Is_User_Defined_Equality
;
8634 ----------------------------------------
8635 -- Make_Controlling_Function_Wrappers --
8636 ----------------------------------------
8638 procedure Make_Controlling_Function_Wrappers
8639 (Tag_Typ
: Entity_Id
;
8640 Decl_List
: out List_Id
;
8641 Body_List
: out List_Id
)
8643 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
8644 Prim_Elmt
: Elmt_Id
;
8646 Actual_List
: List_Id
;
8647 Formal_List
: List_Id
;
8649 Par_Formal
: Entity_Id
;
8650 Formal_Node
: Node_Id
;
8651 Func_Body
: Node_Id
;
8652 Func_Decl
: Node_Id
;
8653 Func_Spec
: Node_Id
;
8654 Return_Stmt
: Node_Id
;
8657 Decl_List
:= New_List
;
8658 Body_List
:= New_List
;
8660 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
8662 while Present
(Prim_Elmt
) loop
8663 Subp
:= Node
(Prim_Elmt
);
8665 -- If a primitive function with a controlling result of the type has
8666 -- not been overridden by the user, then we must create a wrapper
8667 -- function here that effectively overrides it and invokes the
8668 -- (non-abstract) parent function. This can only occur for a null
8669 -- extension. Note that functions with anonymous controlling access
8670 -- results don't qualify and must be overridden. We also exclude
8671 -- Input attributes, since each type will have its own version of
8672 -- Input constructed by the expander. The test for Comes_From_Source
8673 -- is needed to distinguish inherited operations from renamings
8674 -- (which also have Alias set). We exclude internal entities with
8675 -- Interface_Alias to avoid generating duplicated wrappers since
8676 -- the primitive which covers the interface is also available in
8677 -- the list of primitive operations.
8679 -- The function may be abstract, or require_Overriding may be set
8680 -- for it, because tests for null extensions may already have reset
8681 -- the Is_Abstract_Subprogram_Flag. If Requires_Overriding is not
8682 -- set, functions that need wrappers are recognized by having an
8683 -- alias that returns the parent type.
8685 if Comes_From_Source
(Subp
)
8686 or else No
(Alias
(Subp
))
8687 or else Present
(Interface_Alias
(Subp
))
8688 or else Ekind
(Subp
) /= E_Function
8689 or else not Has_Controlling_Result
(Subp
)
8690 or else Is_Access_Type
(Etype
(Subp
))
8691 or else Is_Abstract_Subprogram
(Alias
(Subp
))
8692 or else Is_TSS
(Subp
, TSS_Stream_Input
)
8696 elsif Is_Abstract_Subprogram
(Subp
)
8697 or else Requires_Overriding
(Subp
)
8699 (Is_Null_Extension
(Etype
(Subp
))
8700 and then Etype
(Alias
(Subp
)) /= Etype
(Subp
))
8702 Formal_List
:= No_List
;
8703 Formal
:= First_Formal
(Subp
);
8705 if Present
(Formal
) then
8706 Formal_List
:= New_List
;
8708 while Present
(Formal
) loop
8710 (Make_Parameter_Specification
8712 Defining_Identifier
=>
8713 Make_Defining_Identifier
(Sloc
(Formal
),
8714 Chars
=> Chars
(Formal
)),
8715 In_Present
=> In_Present
(Parent
(Formal
)),
8716 Out_Present
=> Out_Present
(Parent
(Formal
)),
8717 Null_Exclusion_Present
=>
8718 Null_Exclusion_Present
(Parent
(Formal
)),
8720 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8722 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
8725 Next_Formal
(Formal
);
8730 Make_Function_Specification
(Loc
,
8731 Defining_Unit_Name
=>
8732 Make_Defining_Identifier
(Loc
,
8733 Chars
=> Chars
(Subp
)),
8734 Parameter_Specifications
=> Formal_List
,
8735 Result_Definition
=>
8736 New_Occurrence_Of
(Etype
(Subp
), Loc
));
8738 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Func_Spec
);
8739 Append_To
(Decl_List
, Func_Decl
);
8741 -- Build a wrapper body that calls the parent function. The body
8742 -- contains a single return statement that returns an extension
8743 -- aggregate whose ancestor part is a call to the parent function,
8744 -- passing the formals as actuals (with any controlling arguments
8745 -- converted to the types of the corresponding formals of the
8746 -- parent function, which might be anonymous access types), and
8747 -- having a null extension.
8749 Formal
:= First_Formal
(Subp
);
8750 Par_Formal
:= First_Formal
(Alias
(Subp
));
8751 Formal_Node
:= First
(Formal_List
);
8753 if Present
(Formal
) then
8754 Actual_List
:= New_List
;
8756 Actual_List
:= No_List
;
8759 while Present
(Formal
) loop
8760 if Is_Controlling_Formal
(Formal
) then
8761 Append_To
(Actual_List
,
8762 Make_Type_Conversion
(Loc
,
8764 New_Occurrence_Of
(Etype
(Par_Formal
), Loc
),
8767 (Defining_Identifier
(Formal_Node
), Loc
)));
8772 (Defining_Identifier
(Formal_Node
), Loc
));
8775 Next_Formal
(Formal
);
8776 Next_Formal
(Par_Formal
);
8781 Make_Simple_Return_Statement
(Loc
,
8783 Make_Extension_Aggregate
(Loc
,
8785 Make_Function_Call
(Loc
,
8787 New_Occurrence_Of
(Alias
(Subp
), Loc
),
8788 Parameter_Associations
=> Actual_List
),
8789 Null_Record_Present
=> True));
8792 Make_Subprogram_Body
(Loc
,
8793 Specification
=> New_Copy_Tree
(Func_Spec
),
8794 Declarations
=> Empty_List
,
8795 Handled_Statement_Sequence
=>
8796 Make_Handled_Sequence_Of_Statements
(Loc
,
8797 Statements
=> New_List
(Return_Stmt
)));
8799 Set_Defining_Unit_Name
8800 (Specification
(Func_Body
),
8801 Make_Defining_Identifier
(Loc
, Chars
(Subp
)));
8803 Append_To
(Body_List
, Func_Body
);
8805 -- Replace the inherited function with the wrapper function in the
8806 -- primitive operations list. We add the minimum decoration needed
8807 -- to override interface primitives.
8809 Set_Ekind
(Defining_Unit_Name
(Func_Spec
), E_Function
);
8811 Override_Dispatching_Operation
8812 (Tag_Typ
, Subp
, New_Op
=> Defining_Unit_Name
(Func_Spec
),
8813 Is_Wrapper
=> True);
8817 Next_Elmt
(Prim_Elmt
);
8819 end Make_Controlling_Function_Wrappers
;
8825 function Make_Eq_Body
8827 Eq_Name
: Name_Id
) return Node_Id
8829 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Typ
));
8831 Def
: constant Node_Id
:= Parent
(Typ
);
8832 Stmts
: constant List_Id
:= New_List
;
8833 Variant_Case
: Boolean := Has_Discriminants
(Typ
);
8834 Comps
: Node_Id
:= Empty
;
8835 Typ_Def
: Node_Id
:= Type_Definition
(Def
);
8839 Predef_Spec_Or_Body
(Loc
,
8842 Profile
=> New_List
(
8843 Make_Parameter_Specification
(Loc
,
8844 Defining_Identifier
=>
8845 Make_Defining_Identifier
(Loc
, Name_X
),
8846 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)),
8848 Make_Parameter_Specification
(Loc
,
8849 Defining_Identifier
=>
8850 Make_Defining_Identifier
(Loc
, Name_Y
),
8851 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8853 Ret_Type
=> Standard_Boolean
,
8856 if Variant_Case
then
8857 if Nkind
(Typ_Def
) = N_Derived_Type_Definition
then
8858 Typ_Def
:= Record_Extension_Part
(Typ_Def
);
8861 if Present
(Typ_Def
) then
8862 Comps
:= Component_List
(Typ_Def
);
8866 Present
(Comps
) and then Present
(Variant_Part
(Comps
));
8869 if Variant_Case
then
8871 Make_Eq_If
(Typ
, Discriminant_Specifications
(Def
)));
8872 Append_List_To
(Stmts
, Make_Eq_Case
(Typ
, Comps
));
8874 Make_Simple_Return_Statement
(Loc
,
8875 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
8879 Make_Simple_Return_Statement
(Loc
,
8881 Expand_Record_Equality
8884 Lhs
=> Make_Identifier
(Loc
, Name_X
),
8885 Rhs
=> Make_Identifier
(Loc
, Name_Y
),
8886 Bodies
=> Declarations
(Decl
))));
8889 Set_Handled_Statement_Sequence
8890 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8898 -- <Make_Eq_If shared components>
8901 -- when V1 => <Make_Eq_Case> on subcomponents
8903 -- when Vn => <Make_Eq_Case> on subcomponents
8906 function Make_Eq_Case
8909 Discrs
: Elist_Id
:= New_Elmt_List
) return List_Id
8911 Loc
: constant Source_Ptr
:= Sloc
(E
);
8912 Result
: constant List_Id
:= New_List
;
8916 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
;
8917 -- Given the discriminant that controls a given variant of an unchecked
8918 -- union, find the formal of the equality function that carries the
8919 -- inferred value of the discriminant.
8921 function External_Name
(E
: Entity_Id
) return Name_Id
;
8922 -- The value of a given discriminant is conveyed in the corresponding
8923 -- formal parameter of the equality routine. The name of this formal
8924 -- parameter carries a one-character suffix which is removed here.
8926 --------------------------
8927 -- Corresponding_Formal --
8928 --------------------------
8930 function Corresponding_Formal
(C
: Node_Id
) return Entity_Id
is
8931 Discr
: constant Entity_Id
:= Entity
(Name
(Variant_Part
(C
)));
8935 Elm
:= First_Elmt
(Discrs
);
8936 while Present
(Elm
) loop
8937 if Chars
(Discr
) = External_Name
(Node
(Elm
)) then
8944 -- A formal of the proper name must be found
8946 raise Program_Error
;
8947 end Corresponding_Formal
;
8953 function External_Name
(E
: Entity_Id
) return Name_Id
is
8955 Get_Name_String
(Chars
(E
));
8956 Name_Len
:= Name_Len
- 1;
8960 -- Start of processing for Make_Eq_Case
8963 Append_To
(Result
, Make_Eq_If
(E
, Component_Items
(CL
)));
8965 if No
(Variant_Part
(CL
)) then
8969 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(CL
)));
8971 if No
(Variant
) then
8975 Alt_List
:= New_List
;
8976 while Present
(Variant
) loop
8977 Append_To
(Alt_List
,
8978 Make_Case_Statement_Alternative
(Loc
,
8979 Discrete_Choices
=> New_Copy_List
(Discrete_Choices
(Variant
)),
8981 Make_Eq_Case
(E
, Component_List
(Variant
), Discrs
)));
8982 Next_Non_Pragma
(Variant
);
8985 -- If we have an Unchecked_Union, use one of the parameters of the
8986 -- enclosing equality routine that captures the discriminant, to use
8987 -- as the expression in the generated case statement.
8989 if Is_Unchecked_Union
(E
) then
8991 Make_Case_Statement
(Loc
,
8993 New_Occurrence_Of
(Corresponding_Formal
(CL
), Loc
),
8994 Alternatives
=> Alt_List
));
8998 Make_Case_Statement
(Loc
,
9000 Make_Selected_Component
(Loc
,
9001 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9002 Selector_Name
=> New_Copy
(Name
(Variant_Part
(CL
)))),
9003 Alternatives
=> Alt_List
));
9024 -- or a null statement if the list L is empty
9028 L
: List_Id
) return Node_Id
9030 Loc
: constant Source_Ptr
:= Sloc
(E
);
9032 Field_Name
: Name_Id
;
9037 return Make_Null_Statement
(Loc
);
9042 C
:= First_Non_Pragma
(L
);
9043 while Present
(C
) loop
9044 Field_Name
:= Chars
(Defining_Identifier
(C
));
9046 -- The tags must not be compared: they are not part of the value.
9047 -- Ditto for parent interfaces because their equality operator is
9050 -- Note also that in the following, we use Make_Identifier for
9051 -- the component names. Use of New_Occurrence_Of to identify the
9052 -- components would be incorrect because the wrong entities for
9053 -- discriminants could be picked up in the private type case.
9055 if Field_Name
= Name_uParent
9056 and then Is_Interface
(Etype
(Defining_Identifier
(C
)))
9060 elsif Field_Name
/= Name_uTag
then
9061 Evolve_Or_Else
(Cond
,
9064 Make_Selected_Component
(Loc
,
9065 Prefix
=> Make_Identifier
(Loc
, Name_X
),
9066 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
)),
9069 Make_Selected_Component
(Loc
,
9070 Prefix
=> Make_Identifier
(Loc
, Name_Y
),
9071 Selector_Name
=> Make_Identifier
(Loc
, Field_Name
))));
9074 Next_Non_Pragma
(C
);
9078 return Make_Null_Statement
(Loc
);
9082 Make_Implicit_If_Statement
(E
,
9084 Then_Statements
=> New_List
(
9085 Make_Simple_Return_Statement
(Loc
,
9086 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
9095 function Make_Neq_Body
(Tag_Typ
: Entity_Id
) return Node_Id
is
9097 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean;
9098 -- Returns true if Prim is a renaming of an unresolved predefined
9099 -- inequality operation.
9101 --------------------------------
9102 -- Is_Predefined_Neq_Renaming --
9103 --------------------------------
9105 function Is_Predefined_Neq_Renaming
(Prim
: Node_Id
) return Boolean is
9107 return Chars
(Prim
) /= Name_Op_Ne
9108 and then Present
(Alias
(Prim
))
9109 and then Comes_From_Source
(Prim
)
9110 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9111 and then Chars
(Alias
(Prim
)) = Name_Op_Ne
;
9112 end Is_Predefined_Neq_Renaming
;
9116 Loc
: constant Source_Ptr
:= Sloc
(Parent
(Tag_Typ
));
9117 Stmts
: constant List_Id
:= New_List
;
9119 Eq_Prim
: Entity_Id
;
9120 Left_Op
: Entity_Id
;
9121 Renaming_Prim
: Entity_Id
;
9122 Right_Op
: Entity_Id
;
9125 -- Start of processing for Make_Neq_Body
9128 -- For a call on a renaming of a dispatching subprogram that is
9129 -- overridden, if the overriding occurred before the renaming, then
9130 -- the body executed is that of the overriding declaration, even if the
9131 -- overriding declaration is not visible at the place of the renaming;
9132 -- otherwise, the inherited or predefined subprogram is called, see
9135 -- Stage 1: Search for a renaming of the inequality primitive and also
9136 -- search for an overriding of the equality primitive located before the
9137 -- renaming declaration.
9145 Renaming_Prim
:= Empty
;
9147 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9148 while Present
(Elmt
) loop
9149 Prim
:= Node
(Elmt
);
9151 if Is_User_Defined_Equality
(Prim
) and then No
(Alias
(Prim
)) then
9152 if No
(Renaming_Prim
) then
9153 pragma Assert
(No
(Eq_Prim
));
9157 elsif Is_Predefined_Neq_Renaming
(Prim
) then
9158 Renaming_Prim
:= Prim
;
9165 -- No further action needed if no renaming was found
9167 if No
(Renaming_Prim
) then
9171 -- Stage 2: Replace the renaming declaration by a subprogram declaration
9172 -- (required to add its body)
9174 Decl
:= Parent
(Parent
(Renaming_Prim
));
9176 Make_Subprogram_Declaration
(Loc
,
9177 Specification
=> Specification
(Decl
)));
9178 Set_Analyzed
(Decl
);
9180 -- Remove the decoration of intrinsic renaming subprogram
9182 Set_Is_Intrinsic_Subprogram
(Renaming_Prim
, False);
9183 Set_Convention
(Renaming_Prim
, Convention_Ada
);
9184 Set_Alias
(Renaming_Prim
, Empty
);
9185 Set_Has_Completion
(Renaming_Prim
, False);
9187 -- Stage 3: Build the corresponding body
9189 Left_Op
:= First_Formal
(Renaming_Prim
);
9190 Right_Op
:= Next_Formal
(Left_Op
);
9193 Predef_Spec_Or_Body
(Loc
,
9195 Name
=> Chars
(Renaming_Prim
),
9196 Profile
=> New_List
(
9197 Make_Parameter_Specification
(Loc
,
9198 Defining_Identifier
=>
9199 Make_Defining_Identifier
(Loc
, Chars
(Left_Op
)),
9200 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9202 Make_Parameter_Specification
(Loc
,
9203 Defining_Identifier
=>
9204 Make_Defining_Identifier
(Loc
, Chars
(Right_Op
)),
9205 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9207 Ret_Type
=> Standard_Boolean
,
9210 -- If the overriding of the equality primitive occurred before the
9211 -- renaming, then generate:
9213 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9215 -- return not Oeq (X, Y);
9218 if Present
(Eq_Prim
) then
9221 -- Otherwise build a nested subprogram which performs the predefined
9222 -- evaluation of the equality operator. That is, generate:
9224 -- function <Neq_Name> (X : Y : Typ) return Boolean is
9225 -- function Oeq (X : Y) return Boolean is
9227 -- <<body of default implementation>>
9230 -- return not Oeq (X, Y);
9235 Local_Subp
: Node_Id
;
9237 Local_Subp
:= Make_Eq_Body
(Tag_Typ
, Name_Op_Eq
);
9238 Set_Declarations
(Decl
, New_List
(Local_Subp
));
9239 Target
:= Defining_Entity
(Local_Subp
);
9244 Make_Simple_Return_Statement
(Loc
,
9247 Make_Function_Call
(Loc
,
9248 Name
=> New_Occurrence_Of
(Target
, Loc
),
9249 Parameter_Associations
=> New_List
(
9250 Make_Identifier
(Loc
, Chars
(Left_Op
)),
9251 Make_Identifier
(Loc
, Chars
(Right_Op
)))))));
9253 Set_Handled_Statement_Sequence
9254 (Decl
, Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
9258 -------------------------------
9259 -- Make_Null_Procedure_Specs --
9260 -------------------------------
9262 function Make_Null_Procedure_Specs
(Tag_Typ
: Entity_Id
) return List_Id
is
9263 Decl_List
: constant List_Id
:= New_List
;
9264 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9266 Formal_List
: List_Id
;
9267 New_Param_Spec
: Node_Id
;
9268 Parent_Subp
: Entity_Id
;
9269 Prim_Elmt
: Elmt_Id
;
9273 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9274 while Present
(Prim_Elmt
) loop
9275 Subp
:= Node
(Prim_Elmt
);
9277 -- If a null procedure inherited from an interface has not been
9278 -- overridden, then we build a null procedure declaration to
9279 -- override the inherited procedure.
9281 Parent_Subp
:= Alias
(Subp
);
9283 if Present
(Parent_Subp
)
9284 and then Is_Null_Interface_Primitive
(Parent_Subp
)
9286 Formal_List
:= No_List
;
9287 Formal
:= First_Formal
(Subp
);
9289 if Present
(Formal
) then
9290 Formal_List
:= New_List
;
9292 while Present
(Formal
) loop
9294 -- Copy the parameter spec including default expressions
9297 New_Copy_Tree
(Parent
(Formal
), New_Sloc
=> Loc
);
9299 -- Generate a new defining identifier for the new formal.
9300 -- required because New_Copy_Tree does not duplicate
9301 -- semantic fields (except itypes).
9303 Set_Defining_Identifier
(New_Param_Spec
,
9304 Make_Defining_Identifier
(Sloc
(Formal
),
9305 Chars
=> Chars
(Formal
)));
9307 -- For controlling arguments we must change their
9308 -- parameter type to reference the tagged type (instead
9309 -- of the interface type)
9311 if Is_Controlling_Formal
(Formal
) then
9312 if Nkind
(Parameter_Type
(Parent
(Formal
))) = N_Identifier
9314 Set_Parameter_Type
(New_Param_Spec
,
9315 New_Occurrence_Of
(Tag_Typ
, Loc
));
9318 (Nkind
(Parameter_Type
(Parent
(Formal
))) =
9319 N_Access_Definition
);
9320 Set_Subtype_Mark
(Parameter_Type
(New_Param_Spec
),
9321 New_Occurrence_Of
(Tag_Typ
, Loc
));
9325 Append
(New_Param_Spec
, Formal_List
);
9327 Next_Formal
(Formal
);
9331 Append_To
(Decl_List
,
9332 Make_Subprogram_Declaration
(Loc
,
9333 Make_Procedure_Specification
(Loc
,
9334 Defining_Unit_Name
=>
9335 Make_Defining_Identifier
(Loc
, Chars
(Subp
)),
9336 Parameter_Specifications
=> Formal_List
,
9337 Null_Present
=> True)));
9340 Next_Elmt
(Prim_Elmt
);
9344 end Make_Null_Procedure_Specs
;
9346 -------------------------------------
9347 -- Make_Predefined_Primitive_Specs --
9348 -------------------------------------
9350 procedure Make_Predefined_Primitive_Specs
9351 (Tag_Typ
: Entity_Id
;
9352 Predef_List
: out List_Id
;
9353 Renamed_Eq
: out Entity_Id
)
9355 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean;
9356 -- Returns true if Prim is a renaming of an unresolved predefined
9357 -- equality operation.
9359 -------------------------------
9360 -- Is_Predefined_Eq_Renaming --
9361 -------------------------------
9363 function Is_Predefined_Eq_Renaming
(Prim
: Node_Id
) return Boolean is
9365 return Chars
(Prim
) /= Name_Op_Eq
9366 and then Present
(Alias
(Prim
))
9367 and then Comes_From_Source
(Prim
)
9368 and then Is_Intrinsic_Subprogram
(Alias
(Prim
))
9369 and then Chars
(Alias
(Prim
)) = Name_Op_Eq
;
9370 end Is_Predefined_Eq_Renaming
;
9374 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9375 Res
: constant List_Id
:= New_List
;
9376 Eq_Name
: Name_Id
:= Name_Op_Eq
;
9377 Eq_Needed
: Boolean;
9381 Has_Predef_Eq_Renaming
: Boolean := False;
9382 -- Set to True if Tag_Typ has a primitive that renames the predefined
9383 -- equality operator. Used to implement (RM 8-5-4(8)).
9385 -- Start of processing for Make_Predefined_Primitive_Specs
9388 Renamed_Eq
:= Empty
;
9392 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9395 Profile
=> New_List
(
9396 Make_Parameter_Specification
(Loc
,
9397 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9398 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9400 Ret_Type
=> Standard_Long_Long_Integer
));
9402 -- Specs for dispatching stream attributes
9405 Stream_Op_TSS_Names
:
9406 constant array (Integer range <>) of TSS_Name_Type
:=
9413 for Op
in Stream_Op_TSS_Names
'Range loop
9414 if Stream_Operation_OK
(Tag_Typ
, Stream_Op_TSS_Names
(Op
)) then
9416 Predef_Stream_Attr_Spec
(Loc
, Tag_Typ
,
9417 Stream_Op_TSS_Names
(Op
)));
9422 -- Spec of "=" is expanded if the type is not limited and if a user
9423 -- defined "=" was not already declared for the non-full view of a
9424 -- private extension
9426 if not Is_Limited_Type
(Tag_Typ
) then
9428 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9429 while Present
(Prim
) loop
9431 -- If a primitive is encountered that renames the predefined
9432 -- equality operator before reaching any explicit equality
9433 -- primitive, then we still need to create a predefined equality
9434 -- function, because calls to it can occur via the renaming. A
9435 -- new name is created for the equality to avoid conflicting with
9436 -- any user-defined equality. (Note that this doesn't account for
9437 -- renamings of equality nested within subpackages???)
9439 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9440 Has_Predef_Eq_Renaming
:= True;
9441 Eq_Name
:= New_External_Name
(Chars
(Node
(Prim
)), 'E');
9443 -- User-defined equality
9445 elsif Is_User_Defined_Equality
(Node
(Prim
)) then
9446 if No
(Alias
(Node
(Prim
)))
9447 or else Nkind
(Unit_Declaration_Node
(Node
(Prim
))) =
9448 N_Subprogram_Renaming_Declaration
9453 -- If the parent is not an interface type and has an abstract
9454 -- equality function, the inherited equality is abstract as
9455 -- well, and no body can be created for it.
9457 elsif not Is_Interface
(Etype
(Tag_Typ
))
9458 and then Present
(Alias
(Node
(Prim
)))
9459 and then Is_Abstract_Subprogram
(Alias
(Node
(Prim
)))
9464 -- If the type has an equality function corresponding with
9465 -- a primitive defined in an interface type, the inherited
9466 -- equality is abstract as well, and no body can be created
9469 elsif Present
(Alias
(Node
(Prim
)))
9470 and then Comes_From_Source
(Ultimate_Alias
(Node
(Prim
)))
9473 (Find_Dispatching_Type
(Ultimate_Alias
(Node
(Prim
))))
9483 -- If a renaming of predefined equality was found but there was no
9484 -- user-defined equality (so Eq_Needed is still true), then set the
9485 -- name back to Name_Op_Eq. But in the case where a user-defined
9486 -- equality was located after such a renaming, then the predefined
9487 -- equality function is still needed, so Eq_Needed must be set back
9490 if Eq_Name
/= Name_Op_Eq
then
9492 Eq_Name
:= Name_Op_Eq
;
9499 Eq_Spec
:= Predef_Spec_Or_Body
(Loc
,
9502 Profile
=> New_List
(
9503 Make_Parameter_Specification
(Loc
,
9504 Defining_Identifier
=>
9505 Make_Defining_Identifier
(Loc
, Name_X
),
9506 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9508 Make_Parameter_Specification
(Loc
,
9509 Defining_Identifier
=>
9510 Make_Defining_Identifier
(Loc
, Name_Y
),
9511 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
9512 Ret_Type
=> Standard_Boolean
);
9513 Append_To
(Res
, Eq_Spec
);
9515 if Has_Predef_Eq_Renaming
then
9516 Renamed_Eq
:= Defining_Unit_Name
(Specification
(Eq_Spec
));
9518 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9519 while Present
(Prim
) loop
9521 -- Any renamings of equality that appeared before an
9522 -- overriding equality must be updated to refer to the
9523 -- entity for the predefined equality, otherwise calls via
9524 -- the renaming would get incorrectly resolved to call the
9525 -- user-defined equality function.
9527 if Is_Predefined_Eq_Renaming
(Node
(Prim
)) then
9528 Set_Alias
(Node
(Prim
), Renamed_Eq
);
9530 -- Exit upon encountering a user-defined equality
9532 elsif Chars
(Node
(Prim
)) = Name_Op_Eq
9533 and then No
(Alias
(Node
(Prim
)))
9543 -- Spec for dispatching assignment
9545 Append_To
(Res
, Predef_Spec_Or_Body
(Loc
,
9547 Name
=> Name_uAssign
,
9548 Profile
=> New_List
(
9549 Make_Parameter_Specification
(Loc
,
9550 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
9551 Out_Present
=> True,
9552 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
9554 Make_Parameter_Specification
(Loc
,
9555 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
9556 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)))));
9559 -- Ada 2005: Generate declarations for the following primitive
9560 -- operations for limited interfaces and synchronized types that
9561 -- implement a limited interface.
9563 -- Disp_Asynchronous_Select
9564 -- Disp_Conditional_Select
9565 -- Disp_Get_Prim_Op_Kind
9568 -- Disp_Timed_Select
9570 -- Disable the generation of these bodies if No_Dispatching_Calls,
9571 -- Ravenscar or ZFP is active.
9573 if Ada_Version
>= Ada_2005
9574 and then not Restriction_Active
(No_Dispatching_Calls
)
9575 and then not Restriction_Active
(No_Select_Statements
)
9576 and then RTE_Available
(RE_Select_Specific_Data
)
9578 -- These primitives are defined abstract in interface types
9580 if Is_Interface
(Tag_Typ
)
9581 and then Is_Limited_Record
(Tag_Typ
)
9584 Make_Abstract_Subprogram_Declaration
(Loc
,
9586 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9589 Make_Abstract_Subprogram_Declaration
(Loc
,
9591 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9594 Make_Abstract_Subprogram_Declaration
(Loc
,
9596 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9599 Make_Abstract_Subprogram_Declaration
(Loc
,
9601 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9604 Make_Abstract_Subprogram_Declaration
(Loc
,
9606 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9609 Make_Abstract_Subprogram_Declaration
(Loc
,
9611 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9613 -- If ancestor is an interface type, declare non-abstract primitives
9614 -- to override the abstract primitives of the interface type.
9616 -- In VM targets we define these primitives in all root tagged types
9617 -- that are not interface types. Done because in VM targets we don't
9618 -- have secondary dispatch tables and any derivation of Tag_Typ may
9619 -- cover limited interfaces (which always have these primitives since
9620 -- they may be ancestors of synchronized interface types).
9622 elsif (not Is_Interface
(Tag_Typ
)
9623 and then Is_Interface
(Etype
(Tag_Typ
))
9624 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
9626 (Is_Concurrent_Record_Type
(Tag_Typ
)
9627 and then Has_Interfaces
(Tag_Typ
))
9629 (not Tagged_Type_Expansion
9630 and then not Is_Interface
(Tag_Typ
)
9631 and then Tag_Typ
= Root_Type
(Tag_Typ
))
9634 Make_Subprogram_Declaration
(Loc
,
9636 Make_Disp_Asynchronous_Select_Spec
(Tag_Typ
)));
9639 Make_Subprogram_Declaration
(Loc
,
9641 Make_Disp_Conditional_Select_Spec
(Tag_Typ
)));
9644 Make_Subprogram_Declaration
(Loc
,
9646 Make_Disp_Get_Prim_Op_Kind_Spec
(Tag_Typ
)));
9649 Make_Subprogram_Declaration
(Loc
,
9651 Make_Disp_Get_Task_Id_Spec
(Tag_Typ
)));
9654 Make_Subprogram_Declaration
(Loc
,
9656 Make_Disp_Requeue_Spec
(Tag_Typ
)));
9659 Make_Subprogram_Declaration
(Loc
,
9661 Make_Disp_Timed_Select_Spec
(Tag_Typ
)));
9665 -- All tagged types receive their own Deep_Adjust and Deep_Finalize
9666 -- regardless of whether they are controlled or may contain controlled
9669 -- Do not generate the routines if finalization is disabled
9671 if Restriction_Active
(No_Finalization
) then
9674 -- Finalization is not available for CIL value types
9676 elsif Is_Value_Type
(Tag_Typ
) then
9680 if not Is_Limited_Type
(Tag_Typ
) then
9681 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
));
9684 Append_To
(Res
, Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
));
9688 end Make_Predefined_Primitive_Specs
;
9690 -------------------------
9691 -- Make_Tag_Assignment --
9692 -------------------------
9694 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
is
9695 Loc
: constant Source_Ptr
:= Sloc
(N
);
9696 Def_If
: constant Entity_Id
:= Defining_Identifier
(N
);
9697 Expr
: constant Node_Id
:= Expression
(N
);
9698 Typ
: constant Entity_Id
:= Etype
(Def_If
);
9699 Full_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
9703 if Is_Tagged_Type
(Typ
)
9704 and then not Is_Class_Wide_Type
(Typ
)
9705 and then not Is_CPP_Class
(Typ
)
9706 and then Tagged_Type_Expansion
9707 and then Nkind
(Expr
) /= N_Aggregate
9708 and then (Nkind
(Expr
) /= N_Qualified_Expression
9709 or else Nkind
(Expression
(Expr
)) /= N_Aggregate
)
9712 Make_Selected_Component
(Loc
,
9713 Prefix
=> New_Occurrence_Of
(Def_If
, Loc
),
9715 New_Occurrence_Of
(First_Tag_Component
(Full_Typ
), Loc
));
9716 Set_Assignment_OK
(New_Ref
);
9719 Make_Assignment_Statement
(Loc
,
9722 Unchecked_Convert_To
(RTE
(RE_Tag
),
9723 New_Occurrence_Of
(Node
9724 (First_Elmt
(Access_Disp_Table
(Full_Typ
))), Loc
)));
9728 end Make_Tag_Assignment
;
9730 ---------------------------------
9731 -- Needs_Simple_Initialization --
9732 ---------------------------------
9734 function Needs_Simple_Initialization
9736 Consider_IS
: Boolean := True) return Boolean
9738 Consider_IS_NS
: constant Boolean :=
9739 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
9742 -- Never need initialization if it is suppressed
9744 if Initialization_Suppressed
(T
) then
9748 -- Check for private type, in which case test applies to the underlying
9749 -- type of the private type.
9751 if Is_Private_Type
(T
) then
9753 RT
: constant Entity_Id
:= Underlying_Type
(T
);
9755 if Present
(RT
) then
9756 return Needs_Simple_Initialization
(RT
);
9762 -- Scalar type with Default_Value aspect requires initialization
9764 elsif Is_Scalar_Type
(T
) and then Has_Default_Aspect
(T
) then
9767 -- Cases needing simple initialization are access types, and, if pragma
9768 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
9771 elsif Is_Access_Type
(T
)
9772 or else (Consider_IS_NS
and then (Is_Scalar_Type
(T
)))
9776 -- If Initialize/Normalize_Scalars is in effect, string objects also
9777 -- need initialization, unless they are created in the course of
9778 -- expanding an aggregate (since in the latter case they will be
9779 -- filled with appropriate initializing values before they are used).
9781 elsif Consider_IS_NS
9782 and then Is_Standard_String_Type
(T
)
9785 or else Nkind
(Associated_Node_For_Itype
(T
)) /= N_Aggregate
)
9792 end Needs_Simple_Initialization
;
9794 ----------------------
9795 -- Predef_Deep_Spec --
9796 ----------------------
9798 function Predef_Deep_Spec
9800 Tag_Typ
: Entity_Id
;
9801 Name
: TSS_Name_Type
;
9802 For_Body
: Boolean := False) return Node_Id
9807 -- V : in out Tag_Typ
9809 Formals
:= New_List
(
9810 Make_Parameter_Specification
(Loc
,
9811 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
9813 Out_Present
=> True,
9814 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)));
9816 -- F : Boolean := True
9818 if Name
= TSS_Deep_Adjust
9819 or else Name
= TSS_Deep_Finalize
9822 Make_Parameter_Specification
(Loc
,
9823 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_F
),
9824 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
9825 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
9829 Predef_Spec_Or_Body
(Loc
,
9830 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
9833 For_Body
=> For_Body
);
9836 when RE_Not_Available
=>
9838 end Predef_Deep_Spec
;
9840 -------------------------
9841 -- Predef_Spec_Or_Body --
9842 -------------------------
9844 function Predef_Spec_Or_Body
9846 Tag_Typ
: Entity_Id
;
9849 Ret_Type
: Entity_Id
:= Empty
;
9850 For_Body
: Boolean := False) return Node_Id
9852 Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name
);
9856 Set_Is_Public
(Id
, Is_Public
(Tag_Typ
));
9858 -- The internal flag is set to mark these declarations because they have
9859 -- specific properties. First, they are primitives even if they are not
9860 -- defined in the type scope (the freezing point is not necessarily in
9861 -- the same scope). Second, the predefined equality can be overridden by
9862 -- a user-defined equality, no body will be generated in this case.
9864 Set_Is_Internal
(Id
);
9866 if not Debug_Generated_Code
then
9867 Set_Debug_Info_Off
(Id
);
9870 if No
(Ret_Type
) then
9872 Make_Procedure_Specification
(Loc
,
9873 Defining_Unit_Name
=> Id
,
9874 Parameter_Specifications
=> Profile
);
9877 Make_Function_Specification
(Loc
,
9878 Defining_Unit_Name
=> Id
,
9879 Parameter_Specifications
=> Profile
,
9880 Result_Definition
=> New_Occurrence_Of
(Ret_Type
, Loc
));
9883 if Is_Interface
(Tag_Typ
) then
9884 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
9886 -- If body case, return empty subprogram body. Note that this is ill-
9887 -- formed, because there is not even a null statement, and certainly not
9888 -- a return in the function case. The caller is expected to do surgery
9889 -- on the body to add the appropriate stuff.
9892 return Make_Subprogram_Body
(Loc
, Spec
, Empty_List
, Empty
);
9894 -- For the case of an Input attribute predefined for an abstract type,
9895 -- generate an abstract specification. This will never be called, but we
9896 -- need the slot allocated in the dispatching table so that attributes
9897 -- typ'Class'Input and typ'Class'Output will work properly.
9899 elsif Is_TSS
(Name
, TSS_Stream_Input
)
9900 and then Is_Abstract_Type
(Tag_Typ
)
9902 return Make_Abstract_Subprogram_Declaration
(Loc
, Spec
);
9904 -- Normal spec case, where we return a subprogram declaration
9907 return Make_Subprogram_Declaration
(Loc
, Spec
);
9909 end Predef_Spec_Or_Body
;
9911 -----------------------------
9912 -- Predef_Stream_Attr_Spec --
9913 -----------------------------
9915 function Predef_Stream_Attr_Spec
9917 Tag_Typ
: Entity_Id
;
9918 Name
: TSS_Name_Type
;
9919 For_Body
: Boolean := False) return Node_Id
9921 Ret_Type
: Entity_Id
;
9924 if Name
= TSS_Stream_Input
then
9925 Ret_Type
:= Tag_Typ
;
9933 Name
=> Make_TSS_Name
(Tag_Typ
, Name
),
9935 Profile
=> Build_Stream_Attr_Profile
(Loc
, Tag_Typ
, Name
),
9936 Ret_Type
=> Ret_Type
,
9937 For_Body
=> For_Body
);
9938 end Predef_Stream_Attr_Spec
;
9940 ---------------------------------
9941 -- Predefined_Primitive_Bodies --
9942 ---------------------------------
9944 function Predefined_Primitive_Bodies
9945 (Tag_Typ
: Entity_Id
;
9946 Renamed_Eq
: Entity_Id
) return List_Id
9948 Loc
: constant Source_Ptr
:= Sloc
(Tag_Typ
);
9949 Res
: constant List_Id
:= New_List
;
9952 Eq_Needed
: Boolean;
9956 pragma Warnings
(Off
, Ent
);
9959 pragma Assert
(not Is_Interface
(Tag_Typ
));
9961 -- See if we have a predefined "=" operator
9963 if Present
(Renamed_Eq
) then
9965 Eq_Name
:= Chars
(Renamed_Eq
);
9967 -- If the parent is an interface type then it has defined all the
9968 -- predefined primitives abstract and we need to check if the type
9969 -- has some user defined "=" function which matches the profile of
9970 -- the Ada predefined equality operator to avoid generating it.
9972 elsif Is_Interface
(Etype
(Tag_Typ
)) then
9974 Eq_Name
:= Name_Op_Eq
;
9976 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
9977 while Present
(Prim
) loop
9978 if Chars
(Node
(Prim
)) = Name_Op_Eq
9979 and then not Is_Internal
(Node
(Prim
))
9980 and then Present
(First_Entity
(Node
(Prim
)))
9982 -- The predefined equality primitive must have exactly two
9983 -- formals whose type is this tagged type
9985 and then Present
(Last_Entity
(Node
(Prim
)))
9986 and then Next_Entity
(First_Entity
(Node
(Prim
)))
9987 = Last_Entity
(Node
(Prim
))
9988 and then Etype
(First_Entity
(Node
(Prim
))) = Tag_Typ
9989 and then Etype
(Last_Entity
(Node
(Prim
))) = Tag_Typ
10000 Eq_Needed
:= False;
10001 Eq_Name
:= No_Name
;
10003 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10004 while Present
(Prim
) loop
10005 if Chars
(Node
(Prim
)) = Name_Op_Eq
10006 and then Is_Internal
(Node
(Prim
))
10009 Eq_Name
:= Name_Op_Eq
;
10019 Decl
:= Predef_Spec_Or_Body
(Loc
,
10020 Tag_Typ
=> Tag_Typ
,
10021 Name
=> Name_uSize
,
10022 Profile
=> New_List
(
10023 Make_Parameter_Specification
(Loc
,
10024 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10025 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10027 Ret_Type
=> Standard_Long_Long_Integer
,
10030 Set_Handled_Statement_Sequence
(Decl
,
10031 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10032 Make_Simple_Return_Statement
(Loc
,
10034 Make_Attribute_Reference
(Loc
,
10035 Prefix
=> Make_Identifier
(Loc
, Name_X
),
10036 Attribute_Name
=> Name_Size
)))));
10038 Append_To
(Res
, Decl
);
10040 -- Bodies for Dispatching stream IO routines. We need these only for
10041 -- non-limited types (in the limited case there is no dispatching).
10042 -- We also skip them if dispatching or finalization are not available
10043 -- or if stream operations are prohibited by restriction No_Streams or
10044 -- from use of pragma/aspect No_Tagged_Streams.
10046 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Read
)
10047 and then No
(TSS
(Tag_Typ
, TSS_Stream_Read
))
10049 Build_Record_Read_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10050 Append_To
(Res
, Decl
);
10053 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Write
)
10054 and then No
(TSS
(Tag_Typ
, TSS_Stream_Write
))
10056 Build_Record_Write_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10057 Append_To
(Res
, Decl
);
10060 -- Skip body of _Input for the abstract case, since the corresponding
10061 -- spec is abstract (see Predef_Spec_Or_Body).
10063 if not Is_Abstract_Type
(Tag_Typ
)
10064 and then Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Input
)
10065 and then No
(TSS
(Tag_Typ
, TSS_Stream_Input
))
10067 Build_Record_Or_Elementary_Input_Function
10068 (Loc
, Tag_Typ
, Decl
, Ent
);
10069 Append_To
(Res
, Decl
);
10072 if Stream_Operation_OK
(Tag_Typ
, TSS_Stream_Output
)
10073 and then No
(TSS
(Tag_Typ
, TSS_Stream_Output
))
10075 Build_Record_Or_Elementary_Output_Procedure
(Loc
, Tag_Typ
, Decl
, Ent
);
10076 Append_To
(Res
, Decl
);
10079 -- Ada 2005: Generate bodies for the following primitive operations for
10080 -- limited interfaces and synchronized types that implement a limited
10083 -- disp_asynchronous_select
10084 -- disp_conditional_select
10085 -- disp_get_prim_op_kind
10086 -- disp_get_task_id
10087 -- disp_timed_select
10089 -- The interface versions will have null bodies
10091 -- Disable the generation of these bodies if No_Dispatching_Calls,
10092 -- Ravenscar or ZFP is active.
10094 -- In VM targets we define these primitives in all root tagged types
10095 -- that are not interface types. Done because in VM targets we don't
10096 -- have secondary dispatch tables and any derivation of Tag_Typ may
10097 -- cover limited interfaces (which always have these primitives since
10098 -- they may be ancestors of synchronized interface types).
10100 if Ada_Version
>= Ada_2005
10101 and then not Is_Interface
(Tag_Typ
)
10103 ((Is_Interface
(Etype
(Tag_Typ
))
10104 and then Is_Limited_Record
(Etype
(Tag_Typ
)))
10106 (Is_Concurrent_Record_Type
(Tag_Typ
)
10107 and then Has_Interfaces
(Tag_Typ
))
10109 (not Tagged_Type_Expansion
10110 and then Tag_Typ
= Root_Type
(Tag_Typ
)))
10111 and then not Restriction_Active
(No_Dispatching_Calls
)
10112 and then not Restriction_Active
(No_Select_Statements
)
10113 and then RTE_Available
(RE_Select_Specific_Data
)
10115 Append_To
(Res
, Make_Disp_Asynchronous_Select_Body
(Tag_Typ
));
10116 Append_To
(Res
, Make_Disp_Conditional_Select_Body
(Tag_Typ
));
10117 Append_To
(Res
, Make_Disp_Get_Prim_Op_Kind_Body
(Tag_Typ
));
10118 Append_To
(Res
, Make_Disp_Get_Task_Id_Body
(Tag_Typ
));
10119 Append_To
(Res
, Make_Disp_Requeue_Body
(Tag_Typ
));
10120 Append_To
(Res
, Make_Disp_Timed_Select_Body
(Tag_Typ
));
10123 if not Is_Limited_Type
(Tag_Typ
) and then not Is_Interface
(Tag_Typ
) then
10125 -- Body for equality
10128 Decl
:= Make_Eq_Body
(Tag_Typ
, Eq_Name
);
10129 Append_To
(Res
, Decl
);
10132 -- Body for inequality (if required)
10134 Decl
:= Make_Neq_Body
(Tag_Typ
);
10136 if Present
(Decl
) then
10137 Append_To
(Res
, Decl
);
10140 -- Body for dispatching assignment
10143 Predef_Spec_Or_Body
(Loc
,
10144 Tag_Typ
=> Tag_Typ
,
10145 Name
=> Name_uAssign
,
10146 Profile
=> New_List
(
10147 Make_Parameter_Specification
(Loc
,
10148 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_X
),
10149 Out_Present
=> True,
10150 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
)),
10152 Make_Parameter_Specification
(Loc
,
10153 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_Y
),
10154 Parameter_Type
=> New_Occurrence_Of
(Tag_Typ
, Loc
))),
10157 Set_Handled_Statement_Sequence
(Decl
,
10158 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(
10159 Make_Assignment_Statement
(Loc
,
10160 Name
=> Make_Identifier
(Loc
, Name_X
),
10161 Expression
=> Make_Identifier
(Loc
, Name_Y
)))));
10163 Append_To
(Res
, Decl
);
10166 -- Generate empty bodies of routines Deep_Adjust and Deep_Finalize for
10167 -- tagged types which do not contain controlled components.
10169 -- Do not generate the routines if finalization is disabled
10171 if Restriction_Active
(No_Finalization
) then
10174 elsif not Has_Controlled_Component
(Tag_Typ
) then
10175 if not Is_Limited_Type
(Tag_Typ
) then
10176 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Adjust
, True);
10178 if Is_Controlled
(Tag_Typ
) then
10179 Set_Handled_Statement_Sequence
(Decl
,
10180 Make_Handled_Sequence_Of_Statements
(Loc
,
10181 Statements
=> New_List
(
10183 Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10184 Typ
=> Tag_Typ
))));
10187 Set_Handled_Statement_Sequence
(Decl
,
10188 Make_Handled_Sequence_Of_Statements
(Loc
,
10189 Statements
=> New_List
(
10190 Make_Null_Statement
(Loc
))));
10193 Append_To
(Res
, Decl
);
10196 Decl
:= Predef_Deep_Spec
(Loc
, Tag_Typ
, TSS_Deep_Finalize
, True);
10198 if Is_Controlled
(Tag_Typ
) then
10199 Set_Handled_Statement_Sequence
(Decl
,
10200 Make_Handled_Sequence_Of_Statements
(Loc
,
10201 Statements
=> New_List
(
10203 (Obj_Ref
=> Make_Identifier
(Loc
, Name_V
),
10204 Typ
=> Tag_Typ
))));
10207 Set_Handled_Statement_Sequence
(Decl
,
10208 Make_Handled_Sequence_Of_Statements
(Loc
,
10209 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
10212 Append_To
(Res
, Decl
);
10216 end Predefined_Primitive_Bodies
;
10218 ---------------------------------
10219 -- Predefined_Primitive_Freeze --
10220 ---------------------------------
10222 function Predefined_Primitive_Freeze
10223 (Tag_Typ
: Entity_Id
) return List_Id
10225 Res
: constant List_Id
:= New_List
;
10230 Prim
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
10231 while Present
(Prim
) loop
10232 if Is_Predefined_Dispatching_Operation
(Node
(Prim
)) then
10233 Frnodes
:= Freeze_Entity
(Node
(Prim
), Tag_Typ
);
10235 if Present
(Frnodes
) then
10236 Append_List_To
(Res
, Frnodes
);
10244 end Predefined_Primitive_Freeze
;
10246 -------------------------
10247 -- Stream_Operation_OK --
10248 -------------------------
10250 function Stream_Operation_OK
10252 Operation
: TSS_Name_Type
) return Boolean
10254 Has_Predefined_Or_Specified_Stream_Attribute
: Boolean := False;
10257 -- Special case of a limited type extension: a default implementation
10258 -- of the stream attributes Read or Write exists if that attribute
10259 -- has been specified or is available for an ancestor type; a default
10260 -- implementation of the attribute Output (resp. Input) exists if the
10261 -- attribute has been specified or Write (resp. Read) is available for
10262 -- an ancestor type. The last condition only applies under Ada 2005.
10264 if Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
) then
10265 if Operation
= TSS_Stream_Read
then
10266 Has_Predefined_Or_Specified_Stream_Attribute
:=
10267 Has_Specified_Stream_Read
(Typ
);
10269 elsif Operation
= TSS_Stream_Write
then
10270 Has_Predefined_Or_Specified_Stream_Attribute
:=
10271 Has_Specified_Stream_Write
(Typ
);
10273 elsif Operation
= TSS_Stream_Input
then
10274 Has_Predefined_Or_Specified_Stream_Attribute
:=
10275 Has_Specified_Stream_Input
(Typ
)
10277 (Ada_Version
>= Ada_2005
10278 and then Stream_Operation_OK
(Typ
, TSS_Stream_Read
));
10280 elsif Operation
= TSS_Stream_Output
then
10281 Has_Predefined_Or_Specified_Stream_Attribute
:=
10282 Has_Specified_Stream_Output
(Typ
)
10284 (Ada_Version
>= Ada_2005
10285 and then Stream_Operation_OK
(Typ
, TSS_Stream_Write
));
10288 -- Case of inherited TSS_Stream_Read or TSS_Stream_Write
10290 if not Has_Predefined_Or_Specified_Stream_Attribute
10291 and then Is_Derived_Type
(Typ
)
10292 and then (Operation
= TSS_Stream_Read
10293 or else Operation
= TSS_Stream_Write
)
10295 Has_Predefined_Or_Specified_Stream_Attribute
:=
10297 (Find_Inherited_TSS
(Base_Type
(Etype
(Typ
)), Operation
));
10301 -- If the type is not limited, or else is limited but the attribute is
10302 -- explicitly specified or is predefined for the type, then return True,
10303 -- unless other conditions prevail, such as restrictions prohibiting
10304 -- streams or dispatching operations. We also return True for limited
10305 -- interfaces, because they may be extended by nonlimited types and
10306 -- permit inheritance in this case (addresses cases where an abstract
10307 -- extension doesn't get 'Input declared, as per comments below, but
10308 -- 'Class'Input must still be allowed). Note that attempts to apply
10309 -- stream attributes to a limited interface or its class-wide type
10310 -- (or limited extensions thereof) will still get properly rejected
10311 -- by Check_Stream_Attribute.
10313 -- We exclude the Input operation from being a predefined subprogram in
10314 -- the case where the associated type is an abstract extension, because
10315 -- the attribute is not callable in that case, per 13.13.2(49/2). Also,
10316 -- we don't want an abstract version created because types derived from
10317 -- the abstract type may not even have Input available (for example if
10318 -- derived from a private view of the abstract type that doesn't have
10319 -- a visible Input), but a VM such as .NET or the Java VM can treat the
10320 -- operation as inherited anyway, and we don't want an abstract function
10321 -- to be (implicitly) inherited in that case because it can lead to a VM
10324 -- Do not generate stream routines for type Finalization_Master because
10325 -- a master may never appear in types and therefore cannot be read or
10329 (not Is_Limited_Type
(Typ
)
10330 or else Is_Interface
(Typ
)
10331 or else Has_Predefined_Or_Specified_Stream_Attribute
)
10333 (Operation
/= TSS_Stream_Input
10334 or else not Is_Abstract_Type
(Typ
)
10335 or else not Is_Derived_Type
(Typ
))
10336 and then not Has_Unknown_Discriminants
(Typ
)
10338 (Is_Interface
(Typ
)
10340 (Is_Task_Interface
(Typ
)
10341 or else Is_Protected_Interface
(Typ
)
10342 or else Is_Synchronized_Interface
(Typ
)))
10343 and then not Restriction_Active
(No_Streams
)
10344 and then not Restriction_Active
(No_Dispatch
)
10345 and then No
(No_Tagged_Streams_Pragma
(Typ
))
10346 and then not No_Run_Time_Mode
10347 and then RTE_Available
(RE_Tag
)
10348 and then No
(Type_Without_Stream_Operation
(Typ
))
10349 and then RTE_Available
(RE_Root_Stream_Type
)
10350 and then not Is_RTE
(Typ
, RE_Finalization_Master
);
10351 end Stream_Operation_OK
;