1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Debug
; use Debug
;
32 with Elists
; use Elists
;
33 with Einfo
; use Einfo
;
34 with Einfo
.Entities
; use Einfo
.Entities
;
35 with Einfo
.Utils
; use Einfo
.Utils
;
36 with Errout
; use Errout
;
37 with Eval_Fat
; use Eval_Fat
;
38 with Exp_Ch3
; use Exp_Ch3
;
39 with Exp_Ch9
; use Exp_Ch9
;
40 with Exp_Disp
; use Exp_Disp
;
41 with Exp_Dist
; use Exp_Dist
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Expander
; use Expander
;
45 with Freeze
; use Freeze
;
46 with Ghost
; use Ghost
;
47 with Itypes
; use Itypes
;
48 with Layout
; use Layout
;
50 with Lib
.Xref
; use Lib
.Xref
;
51 with Namet
; use Namet
;
52 with Nlists
; use Nlists
;
53 with Nmake
; use Nmake
;
55 with Restrict
; use Restrict
;
56 with Rident
; use Rident
;
57 with Rtsfind
; use Rtsfind
;
59 with Sem_Aux
; use Sem_Aux
;
60 with Sem_Case
; use Sem_Case
;
61 with Sem_Cat
; use Sem_Cat
;
62 with Sem_Ch6
; use Sem_Ch6
;
63 with Sem_Ch7
; use Sem_Ch7
;
64 with Sem_Ch8
; use Sem_Ch8
;
65 with Sem_Ch10
; use Sem_Ch10
;
66 with Sem_Ch13
; use Sem_Ch13
;
67 with Sem_Dim
; use Sem_Dim
;
68 with Sem_Disp
; use Sem_Disp
;
69 with Sem_Dist
; use Sem_Dist
;
70 with Sem_Elab
; use Sem_Elab
;
71 with Sem_Elim
; use Sem_Elim
;
72 with Sem_Eval
; use Sem_Eval
;
73 with Sem_Mech
; use Sem_Mech
;
74 with Sem_Res
; use Sem_Res
;
75 with Sem_Smem
; use Sem_Smem
;
76 with Sem_Type
; use Sem_Type
;
77 with Sem_Util
; use Sem_Util
;
78 with Sem_Warn
; use Sem_Warn
;
79 with Stand
; use Stand
;
80 with Sinfo
; use Sinfo
;
81 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
82 with Sinfo
.Utils
; use Sinfo
.Utils
;
83 with Sinput
; use Sinput
;
84 with Snames
; use Snames
;
85 with Strub
; use Strub
;
86 with Targparm
; use Targparm
;
87 with Tbuild
; use Tbuild
;
88 with Ttypes
; use Ttypes
;
89 with Uintp
; use Uintp
;
90 with Urealp
; use Urealp
;
91 with Warnsw
; use Warnsw
;
93 package body Sem_Ch3
is
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
);
100 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
101 -- abstract interface types implemented by a record type or a derived
104 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
);
105 -- When an access-to-subprogram type has pre/postconditions, we build a
106 -- subprogram that includes these contracts and is invoked by an indirect
107 -- call through the corresponding access type.
109 procedure Build_Derived_Type
111 Parent_Type
: Entity_Id
;
112 Derived_Type
: Entity_Id
;
113 Is_Completion
: Boolean;
114 Derive_Subps
: Boolean := True);
115 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
116 -- the N_Full_Type_Declaration node containing the derived type definition.
117 -- Parent_Type is the entity for the parent type in the derived type
118 -- definition and Derived_Type the actual derived type. Is_Completion must
119 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
120 -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the
121 -- completion of a private type declaration. If Is_Completion is set to
122 -- True, N is the completion of a private type declaration and Derived_Type
123 -- is different from the defining identifier inside N (i.e. Derived_Type /=
124 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
125 -- subprograms should be derived. The only case where this parameter is
126 -- False is when Build_Derived_Type is recursively called to process an
127 -- implicit derived full type for a type derived from a private type (in
128 -- that case the subprograms must only be derived for the private view of
131 -- ??? These flags need a bit of re-examination and re-documentation:
132 -- ??? are they both necessary (both seem related to the recursion)?
134 procedure Build_Derived_Access_Type
136 Parent_Type
: Entity_Id
;
137 Derived_Type
: Entity_Id
);
138 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
139 -- create an implicit base if the parent type is constrained or if the
140 -- subtype indication has a constraint.
142 procedure Build_Derived_Array_Type
144 Parent_Type
: Entity_Id
;
145 Derived_Type
: Entity_Id
);
146 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
147 -- create an implicit base if the parent type is constrained or if the
148 -- subtype indication has a constraint.
150 procedure Build_Derived_Concurrent_Type
152 Parent_Type
: Entity_Id
;
153 Derived_Type
: Entity_Id
);
154 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
155 -- protected type, inherit entries and protected subprograms, check
156 -- legality of discriminant constraints if any.
158 procedure Build_Derived_Enumeration_Type
160 Parent_Type
: Entity_Id
;
161 Derived_Type
: Entity_Id
);
162 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
163 -- type, we must create a new list of literals. Types derived from
164 -- Character and [Wide_]Wide_Character are special-cased.
166 procedure Build_Derived_Numeric_Type
168 Parent_Type
: Entity_Id
;
169 Derived_Type
: Entity_Id
);
170 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
171 -- an anonymous base type, and propagate constraint to subtype if needed.
173 procedure Build_Derived_Private_Type
175 Parent_Type
: Entity_Id
;
176 Derived_Type
: Entity_Id
;
177 Is_Completion
: Boolean;
178 Derive_Subps
: Boolean := True);
179 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
180 -- because the parent may or may not have a completion, and the derivation
181 -- may itself be a completion.
183 procedure Build_Derived_Record_Type
185 Parent_Type
: Entity_Id
;
186 Derived_Type
: Entity_Id
;
187 Derive_Subps
: Boolean := True);
188 -- Subsidiary procedure used for tagged and untagged record types
189 -- by Build_Derived_Type and Analyze_Private_Extension_Declaration.
190 -- All parameters are as in Build_Derived_Type except that N, in
191 -- addition to being an N_Full_Type_Declaration node, can also be an
192 -- N_Private_Extension_Declaration node. See the definition of this routine
193 -- for much more info. Derive_Subps indicates whether subprograms should be
194 -- derived from the parent type. The only case where Derive_Subps is False
195 -- is for an implicit derived full type for a type derived from a private
196 -- type (see Build_Derived_Type).
198 procedure Build_Discriminal
(Discrim
: Entity_Id
);
199 -- Create the discriminal corresponding to discriminant Discrim, that is
200 -- the parameter corresponding to Discrim to be used in initialization
201 -- procedures for the type where Discrim is a discriminant. Discriminals
202 -- are not used during semantic analysis, and are not fully defined
203 -- entities until expansion. Thus they are not given a scope until
204 -- initialization procedures are built.
206 function Build_Discriminant_Constraints
209 Derived_Def
: Boolean := False) return Elist_Id
;
210 -- Validate discriminant constraints and return the list of the constraints
211 -- in order of discriminant declarations, where T is the discriminated
212 -- unconstrained type. Def is the N_Subtype_Indication node where the
213 -- discriminants constraints for T are specified. Derived_Def is True
214 -- when building the discriminant constraints in a derived type definition
215 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
216 -- type and Def is the constraint "(xxx)" on T and this routine sets the
217 -- Corresponding_Discriminant field of the discriminants in the derived
218 -- type D to point to the corresponding discriminants in the parent type T.
220 procedure Build_Discriminated_Subtype
224 Related_Nod
: Node_Id
;
225 For_Access
: Boolean := False);
226 -- Subsidiary procedure to Constrain_Discriminated_Type and to
227 -- Process_Incomplete_Dependents. Given
229 -- T (a possibly discriminated base type)
230 -- Def_Id (a very partially built subtype for T),
232 -- the call completes Def_Id to be the appropriate E_*_Subtype.
234 -- The Elist is the list of discriminant constraints if any (it is set
235 -- to No_Elist if T is not a discriminated type, and to an empty list if
236 -- T has discriminants but there are no discriminant constraints). The
237 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
238 -- The For_Access says whether or not this subtype is really constraining
241 function Build_Scalar_Bound
244 Der_T
: Entity_Id
) return Node_Id
;
245 -- The bounds of a derived scalar type are conversions of the bounds of
246 -- the parent type. Optimize the representation if the bounds are literals.
247 -- Needs a more complete spec--what are the parameters exactly, and what
248 -- exactly is the returned value, and how is Bound affected???
250 procedure Check_Access_Discriminant_Requires_Limited
253 -- Check the restriction that the type to which an access discriminant
254 -- belongs must be a concurrent type or a descendant of a type with
255 -- the reserved word 'limited' in its declaration.
257 procedure Check_Anonymous_Access_Component
262 Access_Def
: Node_Id
);
263 -- Ada 2005 AI-382: an access component in a record definition can refer to
264 -- the enclosing record, in which case it denotes the type itself, and not
265 -- the current instance of the type. We create an anonymous access type for
266 -- the component, and flag it as an access to a component, so accessibility
267 -- checks are properly performed on it. The declaration of the access type
268 -- is placed ahead of that of the record to prevent order-of-elaboration
269 -- circularity issues in Gigi. We create an incomplete type for the record
270 -- declaration, which is the designated type of the anonymous access.
272 procedure Check_Anonymous_Access_Components
276 Comp_List
: Node_Id
);
277 -- Call Check_Anonymous_Access_Component on Comp_List
279 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
);
280 -- Check that, if a new discriminant is used in a constraint defining the
281 -- parent subtype of a derivation, its subtype is statically compatible
282 -- with the subtype of the corresponding parent discriminant (RM 3.7(15)).
284 procedure Check_Delta_Expression
(E
: Node_Id
);
285 -- Check that the expression represented by E is suitable for use as a
286 -- delta expression, i.e. it is of real type and is static.
288 procedure Check_Digits_Expression
(E
: Node_Id
);
289 -- Check that the expression represented by E is suitable for use as a
290 -- digits expression, i.e. it is of integer type, positive and static.
292 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
);
293 -- Validate the initialization of an object declaration. T is the required
294 -- type, and Exp is the initialization expression.
296 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
);
297 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
299 procedure Check_Or_Process_Discriminants
302 Prev
: Entity_Id
:= Empty
);
303 -- If N is the full declaration of the completion T of an incomplete or
304 -- private type, check its discriminants (which are already known to be
305 -- conformant with those of the partial view, see Find_Type_Name),
306 -- otherwise process them. Prev is the entity of the partial declaration,
309 procedure Check_Real_Bound
(Bound
: Node_Id
);
310 -- Check given bound for being of real type and static. If not, post an
311 -- appropriate message, and rewrite the bound with the real literal zero.
313 procedure Constant_Redeclaration
317 -- Various checks on legality of full declaration of deferred constant.
318 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
319 -- node. The caller has not yet set any attributes of this entity.
321 function Contain_Interface
323 Ifaces
: Elist_Id
) return Boolean;
324 -- Ada 2005: Determine whether Iface is present in the list Ifaces
326 procedure Convert_Scalar_Bounds
328 Parent_Type
: Entity_Id
;
329 Derived_Type
: Entity_Id
;
331 -- For derived scalar types, convert the bounds in the type definition to
332 -- the derived type, and complete their analysis. Given a constraint of the
333 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
334 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
335 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
336 -- subtype are conversions of those bounds to the derived_type, so that
337 -- their typing is consistent.
339 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
);
340 -- Copies attributes from array base type T2 to array base type T1. Copies
341 -- only attributes that apply to base types, but not subtypes.
343 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
);
344 -- Copies attributes from array subtype T2 to array subtype T1. Copies
345 -- attributes that apply to both subtypes and base types.
347 procedure Create_Constrained_Components
351 Constraints
: Elist_Id
);
352 -- Build the list of entities for a constrained discriminated record
353 -- subtype. If a component depends on a discriminant, replace its subtype
354 -- using the discriminant values in the discriminant constraint. Subt
355 -- is the defining identifier for the subtype whose list of constrained
356 -- entities we will create. Decl_Node is the type declaration node where
357 -- we will attach all the itypes created. Typ is the base discriminated
358 -- type for the subtype Subt. Constraints is the list of discriminant
359 -- constraints for Typ.
361 function Constrain_Component_Type
363 Constrained_Typ
: Entity_Id
;
364 Related_Node
: Node_Id
;
366 Constraints
: Elist_Id
) return Entity_Id
;
367 -- Given a discriminated base type Typ, a list of discriminant constraints,
368 -- Constraints, for Typ and a component Comp of Typ, create and return the
369 -- type corresponding to Etype (Comp) where all discriminant references
370 -- are replaced with the corresponding constraint. If Etype (Comp) contains
371 -- no discriminant references then it is returned as-is. Constrained_Typ
372 -- is the final constrained subtype to which the constrained component
373 -- belongs. Related_Node is the node where we attach all created itypes.
375 procedure Constrain_Access
376 (Def_Id
: in out Entity_Id
;
378 Related_Nod
: Node_Id
);
379 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
380 -- an anonymous type created for a subtype indication. In that case it is
381 -- created in the procedure and attached to Related_Nod.
383 procedure Constrain_Array
384 (Def_Id
: in out Entity_Id
;
386 Related_Nod
: Node_Id
;
387 Related_Id
: Entity_Id
;
389 -- Apply a list of index constraints to an unconstrained array type. The
390 -- first parameter is the entity for the resulting subtype. A value of
391 -- Empty for Def_Id indicates that an implicit type must be created, but
392 -- creation is delayed (and must be done by this procedure) because other
393 -- subsidiary implicit types must be created first (which is why Def_Id
394 -- is an in/out parameter). The second parameter is a subtype indication
395 -- node for the constrained array to be created (e.g. something of the
396 -- form string (1 .. 10)). Related_Nod gives the place where this type
397 -- has to be inserted in the tree. The Related_Id and Suffix parameters
398 -- are used to build the associated Implicit type name.
400 procedure Constrain_Concurrent
401 (Def_Id
: in out Entity_Id
;
403 Related_Nod
: Node_Id
;
404 Related_Id
: Entity_Id
;
406 -- Apply list of discriminant constraints to an unconstrained concurrent
409 -- SI is the N_Subtype_Indication node containing the constraint and
410 -- the unconstrained type to constrain.
412 -- Def_Id is the entity for the resulting constrained subtype. A value
413 -- of Empty for Def_Id indicates that an implicit type must be created,
414 -- but creation is delayed (and must be done by this procedure) because
415 -- other subsidiary implicit types must be created first (which is why
416 -- Def_Id is an in/out parameter).
418 -- Related_Nod gives the place where this type has to be inserted
421 -- The last two arguments are used to create its external name if needed.
423 function Constrain_Corresponding_Record
424 (Prot_Subt
: Entity_Id
;
425 Corr_Rec
: Entity_Id
;
426 Related_Nod
: Node_Id
) return Entity_Id
;
427 -- When constraining a protected type or task type with discriminants,
428 -- constrain the corresponding record with the same discriminant values.
430 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
);
431 -- Constrain a decimal fixed point type with a digits constraint and/or a
432 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
434 procedure Constrain_Discriminated_Type
437 Related_Nod
: Node_Id
;
438 For_Access
: Boolean := False);
439 -- Process discriminant constraints of composite type. Verify that values
440 -- have been provided for all discriminants, that the original type is
441 -- unconstrained, and that the types of the supplied expressions match
442 -- the discriminant types. The first three parameters are like in routine
443 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
446 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
);
447 -- Constrain an enumeration type with a range constraint. This is identical
448 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
450 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
);
451 -- Constrain a floating point type with either a digits constraint
452 -- and/or a range constraint, building a E_Floating_Point_Subtype.
454 procedure Constrain_Index
457 Related_Nod
: Node_Id
;
458 Related_Id
: Entity_Id
;
461 -- Process an index constraint S in a constrained array declaration. The
462 -- constraint can be a subtype name, or a range with or without an explicit
463 -- subtype mark. The index is the corresponding index of the unconstrained
464 -- array. The Related_Id and Suffix parameters are used to build the
465 -- associated Implicit type name.
467 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
);
468 -- Build subtype of a signed or modular integer type
470 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
);
471 -- Constrain an ordinary fixed point type with a range constraint, and
472 -- build an E_Ordinary_Fixed_Point_Subtype entity.
474 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
);
475 -- Copy the Priv entity into the entity of its full declaration then swap
476 -- the two entities in such a manner that the former private type is now
477 -- seen as a full type.
479 procedure Decimal_Fixed_Point_Type_Declaration
482 -- Create a new decimal fixed point type, and apply the constraint to
483 -- obtain a subtype of this new type.
485 procedure Complete_Private_Subtype
488 Full_Base
: Entity_Id
;
489 Related_Nod
: Node_Id
);
490 -- Complete the implicit full view of a private subtype by setting the
491 -- appropriate semantic fields. If the full view of the parent is a record
492 -- type, build constrained components of subtype.
494 procedure Derive_Progenitor_Subprograms
495 (Parent_Type
: Entity_Id
;
496 Tagged_Type
: Entity_Id
);
497 -- Ada 2005 (AI-251): To complete type derivation, collect the primitive
498 -- operations of progenitors of Tagged_Type, and replace the subsidiary
499 -- subtypes with Tagged_Type, to build the specs of the inherited interface
500 -- primitives. The derived primitives are aliased to those of the
501 -- interface. This routine takes care also of transferring to the full view
502 -- subprograms associated with the partial view of Tagged_Type that cover
503 -- interface primitives.
505 procedure Derived_Standard_Character
507 Parent_Type
: Entity_Id
;
508 Derived_Type
: Entity_Id
);
509 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
510 -- derivations from types Standard.Character and Standard.Wide_Character.
512 procedure Derived_Type_Declaration
515 Is_Completion
: Boolean);
516 -- Process a derived type declaration. Build_Derived_Type is invoked
517 -- to process the actual derived type definition. Parameters N and
518 -- Is_Completion have the same meaning as in Build_Derived_Type.
519 -- T is the N_Defining_Identifier for the entity defined in the
520 -- N_Full_Type_Declaration node N, that is T is the derived type.
522 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
523 -- Insert each literal in symbol table, as an overloadable identifier. Each
524 -- enumeration type is mapped into a sequence of integers, and each literal
525 -- is defined as a constant with integer value. If any of the literals are
526 -- character literals, the type is a character type, which means that
527 -- strings are legal aggregates for arrays of components of the type.
529 function Expand_To_Stored_Constraint
531 Constraint
: Elist_Id
) return Elist_Id
;
532 -- Given a constraint (i.e. a list of expressions) on the discriminants of
533 -- Typ, expand it into a constraint on the stored discriminants and return
534 -- the new list of expressions constraining the stored discriminants.
536 function Find_Type_Of_Object
538 Related_Nod
: Node_Id
) return Entity_Id
;
539 -- Get type entity for object referenced by Obj_Def, attaching the implicit
540 -- types generated to Related_Nod.
542 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
543 -- Create a new float and apply the constraint to obtain subtype of it
545 function Has_Range_Constraint
(N
: Node_Id
) return Boolean;
546 -- Given an N_Subtype_Indication node N, return True if a range constraint
547 -- is present, either directly, or as part of a digits or delta constraint.
548 -- In addition, a digits constraint in the decimal case returns True, since
549 -- it establishes a default range if no explicit range is present.
551 function Inherit_Components
553 Parent_Base
: Entity_Id
;
554 Derived_Base
: Entity_Id
;
556 Inherit_Discr
: Boolean;
557 Discs
: Elist_Id
) return Elist_Id
;
558 -- Called from Build_Derived_Record_Type to inherit the components of
559 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
560 -- For more information on derived types and component inheritance please
561 -- consult the comment above the body of Build_Derived_Record_Type.
563 -- N is the original derived type declaration
565 -- Is_Tagged is set if we are dealing with tagged types
567 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
568 -- Parent_Base, otherwise no discriminants are inherited.
570 -- Discs gives the list of constraints that apply to Parent_Base in the
571 -- derived type declaration. If Discs is set to No_Elist, then we have
572 -- the following situation:
574 -- type Parent (D1..Dn : ..) is [tagged] record ...;
575 -- type Derived is new Parent [with ...];
577 -- which gets treated as
579 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
581 -- For untagged types the returned value is an association list. The list
582 -- starts from the association (Parent_Base => Derived_Base), and then it
583 -- contains a sequence of the associations of the form
585 -- (Old_Component => New_Component),
587 -- where Old_Component is the Entity_Id of a component in Parent_Base and
588 -- New_Component is the Entity_Id of the corresponding component in
589 -- Derived_Base. For untagged records, this association list is needed when
590 -- copying the record declaration for the derived base. In the tagged case
591 -- the value returned is irrelevant.
593 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean;
594 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
595 -- Determine whether subprogram Subp is a procedure subject to pragma
596 -- Extensions_Visible with value False and has at least one controlling
597 -- parameter of mode OUT.
599 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean;
600 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
601 -- When applied to a primitive subprogram Prim, returns True if Prim is
602 -- declared as a private operation within a package or generic package,
603 -- and returns False otherwise.
605 function Is_Valid_Constraint_Kind
607 Constraint_Kind
: Node_Kind
) return Boolean;
608 -- Returns True if it is legal to apply the given kind of constraint to the
609 -- given kind of type (index constraint to an array type, for example).
611 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
612 -- Create new modular type. Verify that modulus is in bounds
614 procedure New_Concatenation_Op
(Typ
: Entity_Id
);
615 -- Create an abbreviated declaration for an operator in order to
616 -- materialize concatenation on array types.
618 procedure Ordinary_Fixed_Point_Type_Declaration
621 -- Create a new ordinary fixed point type, and apply the constraint to
622 -- obtain subtype of it.
624 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
);
625 -- Wrapper on Preanalyze_Spec_Expression for default expressions, so that
626 -- In_Default_Expr can be properly adjusted.
628 procedure Prepare_Private_Subtype_Completion
630 Related_Nod
: Node_Id
);
631 -- Id is a subtype of some private type. Creates the full declaration
632 -- associated with Id whenever possible, i.e. when the full declaration
633 -- of the base type is already known. Records each subtype into
634 -- Private_Dependents of the base type.
636 procedure Process_Incomplete_Dependents
640 -- Process all entities that depend on an incomplete type. There include
641 -- subtypes, subprogram types that mention the incomplete type in their
642 -- profiles, and subprogram with access parameters that designate the
645 -- Inc_T is the defining identifier of an incomplete type declaration, its
646 -- Ekind is E_Incomplete_Type.
648 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
650 -- Full_T is N's defining identifier.
652 -- Subtypes of incomplete types with discriminants are completed when the
653 -- parent type is. This is simpler than private subtypes, because they can
654 -- only appear in the same scope, and there is no need to exchange views.
655 -- Similarly, access_to_subprogram types may have a parameter or a return
656 -- type that is an incomplete type, and that must be replaced with the
659 -- If the full type is tagged, subprogram with access parameters that
660 -- designated the incomplete may be primitive operations of the full type,
661 -- and have to be processed accordingly.
663 procedure Process_Real_Range_Specification
(Def
: Node_Id
);
664 -- Given the type definition for a real type, this procedure processes and
665 -- checks the real range specification of this type definition if one is
666 -- present. If errors are found, error messages are posted, and the
667 -- Real_Range_Specification of Def is reset to Empty.
669 procedure Record_Type_Declaration
673 -- Process a record type declaration (for both untagged and tagged
674 -- records). Parameters T and N are exactly like in procedure
675 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
676 -- for this routine. If this is the completion of an incomplete type
677 -- declaration, Prev is the entity of the incomplete declaration, used for
678 -- cross-referencing. Otherwise Prev = T.
680 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
);
681 -- This routine is used to process the actual record type definition (both
682 -- for untagged and tagged records). Def is a record type definition node.
683 -- This procedure analyzes the components in this record type definition.
684 -- Prev_T is the entity for the enclosing record type. It is provided so
685 -- that its Has_Task flag can be set if any of the component have Has_Task
686 -- set. If the declaration is the completion of an incomplete type
687 -- declaration, Prev_T is the original incomplete type, whose full view is
690 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
);
691 -- Subsidiary to Build_Derived_Record_Type. For untagged record types, we
692 -- first create the list of components for the derived type from that of
693 -- the parent by means of Inherit_Components and then build a copy of the
694 -- declaration tree of the parent with the help of the mapping returned by
695 -- Inherit_Components, which will for example be used to validate record
696 -- representation clauses given for the derived type. If the parent type
697 -- is private and has discriminants, the ancestor discriminants used in the
698 -- inheritance are that of the private declaration, whereas the ancestor
699 -- discriminants present in the declaration tree of the parent are that of
700 -- the full declaration; as a consequence, the remapping done during the
701 -- copy will leave the references to the ancestor discriminants unchanged
702 -- in the declaration tree and they need to be fixed up. If the derived
703 -- type has a known discriminant part, then the remapping done during the
704 -- copy will only create references to the stored discriminants and they
705 -- need to be replaced with references to the non-stored discriminants.
707 procedure Set_Fixed_Range
712 -- Build a range node with the given bounds and set it as the Scalar_Range
713 -- of the given fixed-point type entity. Loc is the source location used
714 -- for the constructed range. See body for further details.
716 procedure Set_Scalar_Range_For_Subtype
720 -- This routine is used to set the scalar range field for a subtype given
721 -- Def_Id, the entity for the subtype, and R, the range expression for the
722 -- scalar range. Subt provides the parent subtype to be used to analyze,
723 -- resolve, and check the given range.
725 procedure Set_Default_SSO
(T
: Entity_Id
);
726 -- T is the entity for an array or record being declared. This procedure
727 -- sets the flags SSO_Set_Low_By_Default/SSO_Set_High_By_Default according
728 -- to the setting of Opt.Default_SSO.
730 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
731 -- Create a new signed integer entity, and apply the constraint to obtain
732 -- the required first named subtype of this type.
734 procedure Set_Stored_Constraint_From_Discriminant_Constraint
736 -- E is some record type. This routine computes E's Stored_Constraint
737 -- from its Discriminant_Constraint.
739 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
);
740 -- Check that an entity in a list of progenitors is an interface,
741 -- emit error otherwise.
743 -----------------------
744 -- Access_Definition --
745 -----------------------
747 function Access_Definition
748 (Related_Nod
: Node_Id
;
749 N
: Node_Id
) return Entity_Id
751 Anon_Type
: Entity_Id
;
752 Anon_Scope
: Entity_Id
;
753 Desig_Type
: Entity_Id
;
754 Enclosing_Prot_Type
: Entity_Id
:= Empty
;
757 if Is_Entry
(Current_Scope
)
758 and then Is_Task_Type
(Etype
(Scope
(Current_Scope
)))
760 Error_Msg_N
("task entries cannot have access parameters", N
);
764 -- Ada 2005: For an object declaration the corresponding anonymous
765 -- type is declared in the current scope.
767 -- If the access definition is the return type of another access to
768 -- function, scope is the current one, because it is the one of the
769 -- current type declaration, except for the pathological case below.
771 if Nkind
(Related_Nod
) in
772 N_Object_Declaration | N_Access_Function_Definition
774 Anon_Scope
:= Current_Scope
;
776 -- A pathological case: function returning access functions that
777 -- return access functions, etc. Each anonymous access type created
778 -- is in the enclosing scope of the outermost function.
786 N_Access_Function_Definition | N_Access_Definition
791 if Nkind
(Par
) = N_Function_Specification
then
792 Anon_Scope
:= Scope
(Defining_Entity
(Par
));
796 -- For the anonymous function result case, retrieve the scope of the
797 -- function specification's associated entity rather than using the
798 -- current scope. The current scope will be the function itself if the
799 -- formal part is currently being analyzed, but will be the parent scope
800 -- in the case of a parameterless function, and we always want to use
801 -- the function's parent scope. Finally, if the function is a child
802 -- unit, we must traverse the tree to retrieve the proper entity.
804 elsif Nkind
(Related_Nod
) = N_Function_Specification
805 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
807 -- If the current scope is a protected type, the anonymous access
808 -- is associated with one of the protected operations, and must
809 -- be available in the scope that encloses the protected declaration.
810 -- Otherwise the type is in the scope enclosing the subprogram.
812 -- If the function has formals, the return type of a subprogram
813 -- declaration is analyzed in the scope of the subprogram (see
814 -- Process_Formals) and thus the protected type, if present, is
815 -- the scope of the current function scope.
817 if Ekind
(Current_Scope
) = E_Protected_Type
then
818 Enclosing_Prot_Type
:= Current_Scope
;
820 elsif Ekind
(Current_Scope
) = E_Function
821 and then Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
823 Enclosing_Prot_Type
:= Scope
(Current_Scope
);
826 if Present
(Enclosing_Prot_Type
) then
827 Anon_Scope
:= Scope
(Enclosing_Prot_Type
);
830 Anon_Scope
:= Scope
(Defining_Entity
(Related_Nod
));
833 -- For an access type definition, if the current scope is a child
834 -- unit it is the scope of the type.
836 elsif Is_Compilation_Unit
(Current_Scope
) then
837 Anon_Scope
:= Current_Scope
;
839 -- For access formals, access components, and access discriminants, the
840 -- scope is that of the enclosing declaration,
843 Anon_Scope
:= Scope
(Current_Scope
);
848 (E_Anonymous_Access_Type
, Related_Nod
, Scope_Id
=> Anon_Scope
);
851 and then Ada_Version
>= Ada_2005
853 Error_Msg_N
("ALL not permitted for anonymous access types", N
);
856 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
857 -- the corresponding semantic routine
859 if Present
(Access_To_Subprogram_Definition
(N
)) then
860 Access_Subprogram_Declaration
861 (T_Name
=> Anon_Type
,
862 T_Def
=> Access_To_Subprogram_Definition
(N
));
864 if Ekind
(Anon_Type
) = E_Access_Protected_Subprogram_Type
then
866 (Anon_Type
, E_Anonymous_Access_Protected_Subprogram_Type
);
868 Mutate_Ekind
(Anon_Type
, E_Anonymous_Access_Subprogram_Type
);
871 -- If the anonymous access is associated with a protected operation,
872 -- create a reference to it after the enclosing protected definition
873 -- because the itype will be used in the subsequent bodies.
875 -- If the anonymous access itself is protected, a full type
876 -- declaratiton will be created for it, so that the equivalent
877 -- record type can be constructed. For further details, see
878 -- Replace_Anonymous_Access_To_Protected-Subprogram.
880 if Ekind
(Current_Scope
) = E_Protected_Type
881 and then not Protected_Present
(Access_To_Subprogram_Definition
(N
))
883 Build_Itype_Reference
(Anon_Type
, Parent
(Current_Scope
));
889 Find_Type
(Subtype_Mark
(N
));
890 Desig_Type
:= Entity
(Subtype_Mark
(N
));
892 Set_Directly_Designated_Type
(Anon_Type
, Desig_Type
);
893 Set_Etype
(Anon_Type
, Anon_Type
);
895 -- Make sure the anonymous access type has size and alignment fields
896 -- set, as required by gigi. This is necessary in the case of the
897 -- Task_Body_Procedure.
899 if not Has_Private_Component
(Desig_Type
) then
900 Layout_Type
(Anon_Type
);
903 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
904 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
905 -- the null value is allowed. In Ada 95 the null value is never allowed.
907 if Ada_Version
>= Ada_2005
then
908 Set_Can_Never_Be_Null
(Anon_Type
, Null_Exclusion_Present
(N
));
910 Set_Can_Never_Be_Null
(Anon_Type
, True);
913 -- The anonymous access type is as public as the discriminated type or
914 -- subprogram that defines it. It is imported (for back-end purposes)
915 -- if the designated type is.
917 Set_Is_Public
(Anon_Type
, Is_Public
(Scope
(Anon_Type
)));
919 -- Ada 2005 (AI-231): Propagate the access-constant attribute
921 Set_Is_Access_Constant
(Anon_Type
, Constant_Present
(N
));
923 -- The context is either a subprogram declaration, object declaration,
924 -- or an access discriminant, in a private or a full type declaration.
925 -- In the case of a subprogram, if the designated type is incomplete,
926 -- the operation will be a primitive operation of the full type, to be
927 -- updated subsequently. If the type is imported through a limited_with
928 -- clause, the subprogram is not a primitive operation of the type
929 -- (which is declared elsewhere in some other scope).
931 if Ekind
(Desig_Type
) = E_Incomplete_Type
932 and then not From_Limited_With
(Desig_Type
)
933 and then Is_Overloadable
(Current_Scope
)
935 Append_Elmt
(Current_Scope
, Private_Dependents
(Desig_Type
));
936 Set_Has_Delayed_Freeze
(Current_Scope
);
939 -- If the designated type is limited and class-wide, the object might
940 -- contain tasks, so we create a Master entity for the declaration. This
941 -- must be done before expansion of the full declaration, because the
942 -- declaration may include an expression that is an allocator, whose
943 -- expansion needs the proper Master for the created tasks.
946 and then Nkind
(Related_Nod
) = N_Object_Declaration
948 if Is_Limited_Record
(Desig_Type
)
949 and then Is_Class_Wide_Type
(Desig_Type
)
951 Build_Class_Wide_Master
(Anon_Type
);
953 -- Similarly, if the type is an anonymous access that designates
954 -- tasks, create a master entity for it in the current context.
956 elsif Has_Task
(Desig_Type
)
957 and then Comes_From_Source
(Related_Nod
)
959 Build_Master_Entity
(Defining_Identifier
(Related_Nod
));
960 Build_Master_Renaming
(Anon_Type
);
964 -- For a private component of a protected type, it is imperative that
965 -- the back-end elaborate the type immediately after the protected
966 -- declaration, because this type will be used in the declarations
967 -- created for the component within each protected body, so we must
968 -- create an itype reference for it now.
970 if Nkind
(Parent
(Related_Nod
)) = N_Protected_Definition
then
971 Build_Itype_Reference
(Anon_Type
, Parent
(Parent
(Related_Nod
)));
973 -- Similarly, if the access definition is the return result of a
974 -- function, create an itype reference for it because it will be used
975 -- within the function body. For a regular function that is not a
976 -- compilation unit, insert reference after the declaration. For a
977 -- protected operation, insert it after the enclosing protected type
978 -- declaration. In either case, do not create a reference for a type
979 -- obtained through a limited_with clause, because this would introduce
980 -- semantic dependencies.
982 -- Similarly, do not create a reference if the designated type is a
983 -- generic formal, because no use of it will reach the backend.
985 elsif Nkind
(Related_Nod
) = N_Function_Specification
986 and then not From_Limited_With
(Desig_Type
)
987 and then not Is_Generic_Type
(Desig_Type
)
989 if Present
(Enclosing_Prot_Type
) then
990 Build_Itype_Reference
(Anon_Type
, Parent
(Enclosing_Prot_Type
));
992 elsif Is_List_Member
(Parent
(Related_Nod
))
993 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
995 Build_Itype_Reference
(Anon_Type
, Parent
(Related_Nod
));
998 -- Finally, create an itype reference for an object declaration of an
999 -- anonymous access type. This is strictly necessary only for deferred
1000 -- constants, but in any case will avoid out-of-scope problems in the
1003 elsif Nkind
(Related_Nod
) = N_Object_Declaration
then
1004 Build_Itype_Reference
(Anon_Type
, Related_Nod
);
1008 end Access_Definition
;
1010 -----------------------------------
1011 -- Access_Subprogram_Declaration --
1012 -----------------------------------
1014 procedure Access_Subprogram_Declaration
1015 (T_Name
: Entity_Id
;
1018 procedure Check_For_Premature_Usage
(Def
: Node_Id
);
1019 -- Check that type T_Name is not used, directly or recursively, as a
1020 -- parameter or a return type in Def. Def is either a subtype, an
1021 -- access_definition, or an access_to_subprogram_definition.
1023 -------------------------------
1024 -- Check_For_Premature_Usage --
1025 -------------------------------
1027 procedure Check_For_Premature_Usage
(Def
: Node_Id
) is
1031 -- Check for a subtype mark
1033 if Nkind
(Def
) in N_Has_Etype
then
1034 if Etype
(Def
) = T_Name
then
1036 ("type& cannot be used before the end of its declaration",
1040 -- If this is not a subtype, then this is an access_definition
1042 elsif Nkind
(Def
) = N_Access_Definition
then
1043 if Present
(Access_To_Subprogram_Definition
(Def
)) then
1044 Check_For_Premature_Usage
1045 (Access_To_Subprogram_Definition
(Def
));
1047 Check_For_Premature_Usage
(Subtype_Mark
(Def
));
1050 -- The only cases left are N_Access_Function_Definition and
1051 -- N_Access_Procedure_Definition.
1054 if Present
(Parameter_Specifications
(Def
)) then
1055 Param
:= First
(Parameter_Specifications
(Def
));
1056 while Present
(Param
) loop
1057 Check_For_Premature_Usage
(Parameter_Type
(Param
));
1062 if Nkind
(Def
) = N_Access_Function_Definition
then
1063 Check_For_Premature_Usage
(Result_Definition
(Def
));
1066 end Check_For_Premature_Usage
;
1070 Formals
: constant List_Id
:= Parameter_Specifications
(T_Def
);
1073 Desig_Type
: constant Entity_Id
:=
1074 Create_Itype
(E_Subprogram_Type
, Parent
(T_Def
));
1076 -- Start of processing for Access_Subprogram_Declaration
1079 -- Associate the Itype node with the inner full-type declaration or
1080 -- subprogram spec or entry body. This is required to handle nested
1081 -- anonymous declarations. For example:
1084 -- (X : access procedure
1085 -- (Y : access procedure
1088 D_Ityp
:= Associated_Node_For_Itype
(Desig_Type
);
1089 while Nkind
(D_Ityp
) not in N_Full_Type_Declaration
1090 | N_Private_Type_Declaration
1091 | N_Private_Extension_Declaration
1092 | N_Procedure_Specification
1093 | N_Function_Specification
1095 | N_Object_Declaration
1096 | N_Object_Renaming_Declaration
1097 | N_Formal_Object_Declaration
1098 | N_Formal_Type_Declaration
1099 | N_Task_Type_Declaration
1100 | N_Protected_Type_Declaration
1102 D_Ityp
:= Parent
(D_Ityp
);
1103 pragma Assert
(D_Ityp
/= Empty
);
1106 Set_Associated_Node_For_Itype
(Desig_Type
, D_Ityp
);
1108 if Nkind
(D_Ityp
) in N_Procedure_Specification | N_Function_Specification
1110 Set_Scope
(Desig_Type
, Scope
(Defining_Entity
(D_Ityp
)));
1112 elsif Nkind
(D_Ityp
) in N_Full_Type_Declaration
1113 | N_Object_Declaration
1114 | N_Object_Renaming_Declaration
1115 | N_Formal_Type_Declaration
1117 Set_Scope
(Desig_Type
, Scope
(Defining_Identifier
(D_Ityp
)));
1120 if Nkind
(T_Def
) = N_Access_Function_Definition
then
1121 if Nkind
(Result_Definition
(T_Def
)) = N_Access_Definition
then
1123 Acc
: constant Node_Id
:= Result_Definition
(T_Def
);
1126 if Present
(Access_To_Subprogram_Definition
(Acc
))
1128 Protected_Present
(Access_To_Subprogram_Definition
(Acc
))
1132 Replace_Anonymous_Access_To_Protected_Subprogram
1138 Access_Definition
(T_Def
, Result_Definition
(T_Def
)));
1143 Analyze
(Result_Definition
(T_Def
));
1146 Typ
: constant Entity_Id
:= Entity
(Result_Definition
(T_Def
));
1149 -- If a null exclusion is imposed on the result type, then
1150 -- create a null-excluding itype (an access subtype) and use
1151 -- it as the function's Etype.
1153 if Is_Access_Type
(Typ
)
1154 and then Null_Exclusion_In_Return_Present
(T_Def
)
1156 Set_Etype
(Desig_Type
,
1157 Create_Null_Excluding_Itype
1159 Related_Nod
=> T_Def
,
1160 Scope_Id
=> Current_Scope
));
1163 if From_Limited_With
(Typ
) then
1165 -- AI05-151: Incomplete types are allowed in all basic
1166 -- declarations, including access to subprograms.
1168 if Ada_Version
>= Ada_2012
then
1173 ("illegal use of incomplete type&",
1174 Result_Definition
(T_Def
), Typ
);
1177 elsif Ekind
(Current_Scope
) = E_Package
1178 and then In_Private_Part
(Current_Scope
)
1180 if Ekind
(Typ
) = E_Incomplete_Type
then
1181 Append_Elmt
(Desig_Type
, Private_Dependents
(Typ
));
1183 elsif Is_Class_Wide_Type
(Typ
)
1184 and then Ekind
(Etype
(Typ
)) = E_Incomplete_Type
1187 (Desig_Type
, Private_Dependents
(Etype
(Typ
)));
1191 Set_Etype
(Desig_Type
, Typ
);
1196 if not Is_Type
(Etype
(Desig_Type
)) then
1198 ("expect type in function specification",
1199 Result_Definition
(T_Def
));
1203 Set_Etype
(Desig_Type
, Standard_Void_Type
);
1206 if Present
(Formals
) then
1207 Push_Scope
(Desig_Type
);
1209 -- Some special tests here. These special tests can be removed
1210 -- if and when Itypes always have proper parent pointers to their
1213 -- Special test 1) Link defining_identifier of formals. Required by
1214 -- First_Formal to provide its functionality.
1220 F
:= First
(Formals
);
1222 while Present
(F
) loop
1223 if No
(Parent
(Defining_Identifier
(F
))) then
1224 Set_Parent
(Defining_Identifier
(F
), F
);
1231 Process_Formals
(Formals
, Parent
(T_Def
));
1233 -- Special test 2) End_Scope requires that the parent pointer be set
1234 -- to something reasonable, but Itypes don't have parent pointers. So
1235 -- we set it and then unset it ???
1237 Set_Parent
(Desig_Type
, T_Name
);
1239 Set_Parent
(Desig_Type
, Empty
);
1242 -- Check for premature usage of the type being defined
1244 Check_For_Premature_Usage
(T_Def
);
1246 -- The return type and/or any parameter type may be incomplete. Mark the
1247 -- subprogram_type as depending on the incomplete type, so that it can
1248 -- be updated when the full type declaration is seen. This only applies
1249 -- to incomplete types declared in some enclosing scope, not to limited
1250 -- views from other packages.
1252 -- Prior to Ada 2012, access to functions can only have in_parameters.
1254 if Present
(Formals
) then
1255 Formal
:= First_Formal
(Desig_Type
);
1256 while Present
(Formal
) loop
1257 if Ekind
(Formal
) /= E_In_Parameter
1258 and then Nkind
(T_Def
) = N_Access_Function_Definition
1259 and then Ada_Version
< Ada_2012
1261 Error_Msg_N
("functions can only have IN parameters", Formal
);
1264 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
1265 and then In_Open_Scopes
(Scope
(Etype
(Formal
)))
1267 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Formal
)));
1268 Set_Has_Delayed_Freeze
(Desig_Type
);
1271 Next_Formal
(Formal
);
1275 -- Check whether an indirect call without actuals may be possible. This
1276 -- is used when resolving calls whose result is then indexed.
1278 May_Need_Actuals
(Desig_Type
);
1280 -- If the return type is incomplete, this is legal as long as the type
1281 -- is declared in the current scope and will be completed in it (rather
1282 -- than being part of limited view).
1284 if Ekind
(Etype
(Desig_Type
)) = E_Incomplete_Type
1285 and then not Has_Delayed_Freeze
(Desig_Type
)
1286 and then In_Open_Scopes
(Scope
(Etype
(Desig_Type
)))
1288 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Desig_Type
)));
1289 Set_Has_Delayed_Freeze
(Desig_Type
);
1292 Check_Delayed_Subprogram
(Desig_Type
);
1294 if Protected_Present
(T_Def
) then
1295 Mutate_Ekind
(T_Name
, E_Access_Protected_Subprogram_Type
);
1296 Set_Convention
(Desig_Type
, Convention_Protected
);
1298 Mutate_Ekind
(T_Name
, E_Access_Subprogram_Type
);
1301 Set_Can_Use_Internal_Rep
(T_Name
,
1302 not Always_Compatible_Rep_On_Target
);
1303 Set_Etype
(T_Name
, T_Name
);
1304 Reinit_Size_Align
(T_Name
);
1305 Set_Directly_Designated_Type
(T_Name
, Desig_Type
);
1307 -- If the access_to_subprogram is not declared at the library level,
1308 -- it can only point to subprograms that are at the same or deeper
1309 -- accessibility level. The corresponding subprogram type might
1310 -- require an activation record when compiling for C.
1312 Set_Needs_Activation_Record
(Desig_Type
,
1313 not Is_Library_Level_Entity
(T_Name
));
1315 Generate_Reference_To_Formals
(T_Name
);
1317 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1319 Set_Can_Never_Be_Null
(T_Name
, Null_Exclusion_Present
(T_Def
));
1321 Check_Restriction
(No_Access_Subprograms
, T_Def
);
1323 -- Addition of extra formals must be delayed till the freeze point so
1324 -- that we know the convention.
1325 end Access_Subprogram_Declaration
;
1327 ----------------------------
1328 -- Access_Type_Declaration --
1329 ----------------------------
1331 procedure Access_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
1333 procedure Setup_Access_Type
(Desig_Typ
: Entity_Id
);
1334 -- After type declaration is analysed with T being an incomplete type,
1335 -- this routine will mutate the kind of T to the appropriate access type
1336 -- and set its directly designated type to Desig_Typ.
1338 -----------------------
1339 -- Setup_Access_Type --
1340 -----------------------
1342 procedure Setup_Access_Type
(Desig_Typ
: Entity_Id
) is
1344 if All_Present
(Def
) or else Constant_Present
(Def
) then
1345 Mutate_Ekind
(T
, E_General_Access_Type
);
1347 Mutate_Ekind
(T
, E_Access_Type
);
1350 Set_Directly_Designated_Type
(T
, Desig_Typ
);
1351 end Setup_Access_Type
;
1355 P
: constant Node_Id
:= Parent
(Def
);
1356 S
: constant Node_Id
:= Subtype_Indication
(Def
);
1358 Full_Desig
: Entity_Id
;
1360 -- Start of processing for Access_Type_Declaration
1363 -- Check for permissible use of incomplete type
1365 if Nkind
(S
) /= N_Subtype_Indication
then
1369 if Nkind
(S
) in N_Has_Entity
1370 and then Present
(Entity
(S
))
1371 and then Ekind
(Root_Type
(Entity
(S
))) = E_Incomplete_Type
1373 Setup_Access_Type
(Desig_Typ
=> Entity
(S
));
1375 -- If the designated type is a limited view, we cannot tell if
1376 -- the full view contains tasks, and there is no way to handle
1377 -- that full view in a client. We create a master entity for the
1378 -- scope, which will be used when a client determines that one
1381 if From_Limited_With
(Entity
(S
))
1382 and then not Is_Class_Wide_Type
(Entity
(S
))
1384 Build_Master_Entity
(T
);
1385 Build_Master_Renaming
(T
);
1389 Setup_Access_Type
(Desig_Typ
=> Process_Subtype
(S
, P
, T
, 'P'));
1392 -- If the access definition is of the form: ACCESS NOT NULL ..
1393 -- the subtype indication must be of an access type. Create
1394 -- a null-excluding subtype of it.
1396 if Null_Excluding_Subtype
(Def
) then
1397 if not Is_Access_Type
(Entity
(S
)) then
1398 Error_Msg_N
("null exclusion must apply to access type", Def
);
1402 Loc
: constant Source_Ptr
:= Sloc
(S
);
1404 Nam
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1408 Make_Subtype_Declaration
(Loc
,
1409 Defining_Identifier
=> Nam
,
1410 Subtype_Indication
=>
1411 New_Occurrence_Of
(Entity
(S
), Loc
));
1412 Set_Null_Exclusion_Present
(Decl
);
1413 Insert_Before
(Parent
(Def
), Decl
);
1415 Set_Entity
(S
, Nam
);
1421 Setup_Access_Type
(Desig_Typ
=> Process_Subtype
(S
, P
, T
, 'P'));
1424 if not Error_Posted
(T
) then
1425 Full_Desig
:= Designated_Type
(T
);
1427 if Base_Type
(Full_Desig
) = T
then
1428 Error_Msg_N
("access type cannot designate itself", S
);
1430 -- In Ada 2005, the type may have a limited view through some unit in
1431 -- its own context, allowing the following circularity that cannot be
1432 -- detected earlier.
1434 elsif Is_Class_Wide_Type
(Full_Desig
) and then Etype
(Full_Desig
) = T
1437 ("access type cannot designate its own class-wide type", S
);
1439 -- Clean up indication of tagged status to prevent cascaded errors
1441 Set_Is_Tagged_Type
(T
, False);
1446 -- For SPARK, check that the designated type is compatible with
1447 -- respect to volatility with the access type.
1449 if SPARK_Mode
/= Off
1450 and then Comes_From_Source
(T
)
1452 -- ??? UNIMPLEMENTED
1453 -- In the case where the designated type is incomplete at this
1454 -- point, performing this check here is harmless but the check
1455 -- will need to be repeated when the designated type is complete.
1457 -- The preceding call to Comes_From_Source is needed because the
1458 -- FE sometimes introduces implicitly declared access types. See,
1459 -- for example, the expansion of nested_po.ads in OA28-015.
1461 Check_Volatility_Compatibility
1462 (Full_Desig
, T
, "designated type", "access type",
1463 Srcpos_Bearer
=> T
);
1467 -- If the type has appeared already in a with_type clause, it is frozen
1468 -- and the pointer size is already set. Else, initialize.
1470 if not From_Limited_With
(T
) then
1471 Reinit_Size_Align
(T
);
1474 -- Note that Has_Task is always false, since the access type itself
1475 -- is not a task type. See Einfo for more description on this point.
1476 -- Exactly the same consideration applies to Has_Controlled_Component
1477 -- and to Has_Protected.
1479 Set_Has_Task
(T
, False);
1480 Set_Has_Protected
(T
, False);
1481 Set_Has_Timing_Event
(T
, False);
1482 Set_Has_Controlled_Component
(T
, False);
1484 -- Initialize field Finalization_Master explicitly to Empty, to avoid
1485 -- problems where an incomplete view of this entity has been previously
1486 -- established by a limited with and an overlaid version of this field
1487 -- (Stored_Constraint) was initialized for the incomplete view.
1489 -- This reset is performed in most cases except where the access type
1490 -- has been created for the purposes of allocating or deallocating a
1491 -- build-in-place object. Such access types have explicitly set pools
1492 -- and finalization masters.
1494 if No
(Associated_Storage_Pool
(T
)) then
1495 Set_Finalization_Master
(T
, Empty
);
1498 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1501 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
1502 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
1503 end Access_Type_Declaration
;
1505 ----------------------------------
1506 -- Add_Interface_Tag_Components --
1507 ----------------------------------
1509 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
) is
1510 Loc
: constant Source_Ptr
:= Sloc
(N
);
1514 procedure Add_Tag
(Iface
: Entity_Id
);
1515 -- Add tag for one of the progenitor interfaces
1521 procedure Add_Tag
(Iface
: Entity_Id
) is
1528 pragma Assert
(Is_Tagged_Type
(Iface
) and then Is_Interface
(Iface
));
1530 -- This is a reasonable place to propagate predicates
1532 if Has_Predicates
(Iface
) then
1533 Set_Has_Predicates
(Typ
);
1537 Make_Component_Definition
(Loc
,
1538 Aliased_Present
=> True,
1539 Subtype_Indication
=>
1540 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
));
1542 Tag
:= Make_Temporary
(Loc
, 'V');
1545 Make_Component_Declaration
(Loc
,
1546 Defining_Identifier
=> Tag
,
1547 Component_Definition
=> Def
);
1549 Analyze_Component_Declaration
(Decl
);
1551 Set_Analyzed
(Decl
);
1552 Mutate_Ekind
(Tag
, E_Component
);
1554 Set_Is_Aliased
(Tag
);
1555 Set_Is_Independent
(Tag
);
1556 Set_Related_Type
(Tag
, Iface
);
1557 Reinit_Component_Location
(Tag
);
1559 pragma Assert
(Is_Frozen
(Iface
));
1561 Set_DT_Entry_Count
(Tag
,
1562 DT_Entry_Count
(First_Entity
(Iface
)));
1564 if No
(Last_Tag
) then
1567 Insert_After
(Last_Tag
, Decl
);
1572 -- If the ancestor has discriminants we need to give special support
1573 -- to store the offset_to_top value of the secondary dispatch tables.
1574 -- For this purpose we add a supplementary component just after the
1575 -- field that contains the tag associated with each secondary DT.
1577 if Typ
/= Etype
(Typ
) and then Has_Discriminants
(Etype
(Typ
)) then
1579 Make_Component_Definition
(Loc
,
1580 Subtype_Indication
=>
1581 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
1583 Offset
:= Make_Temporary
(Loc
, 'V');
1586 Make_Component_Declaration
(Loc
,
1587 Defining_Identifier
=> Offset
,
1588 Component_Definition
=> Def
);
1590 Analyze_Component_Declaration
(Decl
);
1592 Set_Analyzed
(Decl
);
1593 Mutate_Ekind
(Offset
, E_Component
);
1594 Set_Is_Aliased
(Offset
);
1595 Set_Is_Independent
(Offset
);
1596 Set_Related_Type
(Offset
, Iface
);
1597 Reinit_Component_Location
(Offset
);
1598 Insert_After
(Last_Tag
, Decl
);
1609 -- Start of processing for Add_Interface_Tag_Components
1612 if not RTE_Available
(RE_Interface_Tag
) then
1614 ("(Ada 2005) interface types not supported by this run-time!", N
);
1618 if Ekind
(Typ
) /= E_Record_Type
1619 or else (Is_Concurrent_Record_Type
(Typ
)
1620 and then Is_Empty_List
(Abstract_Interface_List
(Typ
)))
1621 or else (not Is_Concurrent_Record_Type
(Typ
)
1622 and then No
(Interfaces
(Typ
))
1623 and then Is_Empty_Elmt_List
(Interfaces
(Typ
)))
1628 -- Find the current last tag
1630 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1631 Ext
:= Record_Extension_Part
(Type_Definition
(N
));
1633 pragma Assert
(Nkind
(Type_Definition
(N
)) = N_Record_Definition
);
1634 Ext
:= Type_Definition
(N
);
1639 if not (Present
(Component_List
(Ext
))) then
1640 Set_Null_Present
(Ext
, False);
1642 Set_Component_List
(Ext
,
1643 Make_Component_List
(Loc
,
1644 Component_Items
=> L
,
1645 Null_Present
=> False));
1647 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1648 L
:= Component_Items
1650 (Record_Extension_Part
1651 (Type_Definition
(N
))));
1653 L
:= Component_Items
1655 (Type_Definition
(N
)));
1658 -- Find the last tag component
1661 while Present
(Comp
) loop
1662 if Nkind
(Comp
) = N_Component_Declaration
1663 and then Is_Tag
(Defining_Identifier
(Comp
))
1672 -- At this point L references the list of components and Last_Tag
1673 -- references the current last tag (if any). Now we add the tag
1674 -- corresponding with all the interfaces that are not implemented
1677 if Present
(Interfaces
(Typ
)) then
1678 Elmt
:= First_Elmt
(Interfaces
(Typ
));
1679 while Present
(Elmt
) loop
1680 Add_Tag
(Node
(Elmt
));
1684 end Add_Interface_Tag_Components
;
1686 -------------------------------------
1687 -- Add_Internal_Interface_Entities --
1688 -------------------------------------
1690 procedure Add_Internal_Interface_Entities
(Tagged_Type
: Entity_Id
) is
1693 Iface_Elmt
: Elmt_Id
;
1694 Iface_Prim
: Entity_Id
;
1695 Ifaces_List
: Elist_Id
;
1696 New_Subp
: Entity_Id
:= Empty
;
1698 Restore_Scope
: Boolean := False;
1701 pragma Assert
(Ada_Version
>= Ada_2005
1702 and then Is_Record_Type
(Tagged_Type
)
1703 and then Is_Tagged_Type
(Tagged_Type
)
1704 and then Has_Interfaces
(Tagged_Type
)
1705 and then not Is_Interface
(Tagged_Type
));
1707 -- Ensure that the internal entities are added to the scope of the type
1709 if Scope
(Tagged_Type
) /= Current_Scope
then
1710 Push_Scope
(Scope
(Tagged_Type
));
1711 Restore_Scope
:= True;
1714 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1716 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1717 while Present
(Iface_Elmt
) loop
1718 Iface
:= Node
(Iface_Elmt
);
1720 -- Originally we excluded here from this processing interfaces that
1721 -- are parents of Tagged_Type because their primitives are located
1722 -- in the primary dispatch table (and hence no auxiliary internal
1723 -- entities are required to handle secondary dispatch tables in such
1724 -- case). However, these auxiliary entities are also required to
1725 -- handle derivations of interfaces in formals of generics (see
1726 -- Derive_Subprograms).
1728 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1729 while Present
(Elmt
) loop
1730 Iface_Prim
:= Node
(Elmt
);
1732 if not Is_Predefined_Dispatching_Operation
(Iface_Prim
) then
1734 Find_Primitive_Covering_Interface
1735 (Tagged_Type
=> Tagged_Type
,
1736 Iface_Prim
=> Iface_Prim
);
1738 if No
(Prim
) and then Serious_Errors_Detected
> 0 then
1742 pragma Assert
(Present
(Prim
));
1744 -- Ada 2012 (AI05-0197): If the name of the covering primitive
1745 -- differs from the name of the interface primitive then it is
1746 -- a private primitive inherited from a parent type. In such
1747 -- case, given that Tagged_Type covers the interface, the
1748 -- inherited private primitive becomes visible. For such
1749 -- purpose we add a new entity that renames the inherited
1750 -- private primitive.
1752 if Chars
(Prim
) /= Chars
(Iface_Prim
) then
1753 pragma Assert
(Has_Suffix
(Prim
, 'P'));
1755 (New_Subp
=> New_Subp
,
1756 Parent_Subp
=> Iface_Prim
,
1757 Derived_Type
=> Tagged_Type
,
1758 Parent_Type
=> Iface
);
1759 Set_Alias
(New_Subp
, Prim
);
1760 Set_Is_Abstract_Subprogram
1761 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1765 (New_Subp
=> New_Subp
,
1766 Parent_Subp
=> Iface_Prim
,
1767 Derived_Type
=> Tagged_Type
,
1768 Parent_Type
=> Iface
);
1773 if Is_Inherited_Operation
(Prim
)
1774 and then Present
(Alias
(Prim
))
1776 Anc
:= Alias
(Prim
);
1778 Anc
:= Overridden_Operation
(Prim
);
1781 -- Apply legality checks in RM 6.1.1 (10-13) concerning
1782 -- nonconforming preconditions in both an ancestor and
1783 -- a progenitor operation.
1785 -- If the operation is a primitive wrapper it is an explicit
1786 -- (overriding) operqtion and all is fine.
1789 and then Has_Non_Trivial_Precondition
(Anc
)
1790 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
1792 if Is_Abstract_Subprogram
(Prim
)
1794 (Ekind
(Prim
) = E_Procedure
1795 and then Nkind
(Parent
(Prim
)) =
1796 N_Procedure_Specification
1797 and then Null_Present
(Parent
(Prim
)))
1798 or else Is_Primitive_Wrapper
(Prim
)
1802 -- The operation is inherited and must be overridden
1804 elsif not Comes_From_Source
(Prim
) then
1806 ("&inherits non-conforming preconditions and must "
1807 & "be overridden (RM 6.1.1 (10-16))",
1808 Parent
(Tagged_Type
), Prim
);
1813 -- Ada 2005 (AI-251): Decorate internal entity Iface_Subp
1814 -- associated with interface types. These entities are
1815 -- only registered in the list of primitives of its
1816 -- corresponding tagged type because they are only used
1817 -- to fill the contents of the secondary dispatch tables.
1818 -- Therefore they are removed from the homonym chains.
1820 Set_Is_Hidden
(New_Subp
);
1821 Set_Is_Internal
(New_Subp
);
1822 Set_Alias
(New_Subp
, Prim
);
1823 Set_Is_Abstract_Subprogram
1824 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1825 Set_Interface_Alias
(New_Subp
, Iface_Prim
);
1827 -- If the returned type is an interface then propagate it to
1828 -- the returned type. Needed by the thunk to generate the code
1829 -- which displaces "this" to reference the corresponding
1830 -- secondary dispatch table in the returned object.
1832 if Is_Interface
(Etype
(Iface_Prim
)) then
1833 Set_Etype
(New_Subp
, Etype
(Iface_Prim
));
1836 -- Internal entities associated with interface types are only
1837 -- registered in the list of primitives of the tagged type.
1838 -- They are only used to fill the contents of the secondary
1839 -- dispatch tables. Therefore they are not needed in the
1842 Remove_Homonym
(New_Subp
);
1844 -- Hidden entities associated with interfaces must have set
1845 -- the Has_Delay_Freeze attribute to ensure that, in case
1846 -- of locally defined tagged types (or compiling with static
1847 -- dispatch tables generation disabled) the corresponding
1848 -- entry of the secondary dispatch table is filled when such
1849 -- an entity is frozen.
1851 Set_Has_Delayed_Freeze
(New_Subp
);
1858 Next_Elmt
(Iface_Elmt
);
1861 if Restore_Scope
then
1864 end Add_Internal_Interface_Entities
;
1866 -----------------------------------
1867 -- Analyze_Component_Declaration --
1868 -----------------------------------
1870 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
1871 Loc
: constant Source_Ptr
:= Sloc
(Component_Definition
(N
));
1872 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1873 E
: constant Node_Id
:= Expression
(N
);
1874 Typ
: constant Node_Id
:=
1875 Subtype_Indication
(Component_Definition
(N
));
1879 function Contains_POC
(Constr
: Node_Id
) return Boolean;
1880 -- Determines whether a constraint uses the discriminant of a record
1881 -- type thus becoming a per-object constraint (POC).
1883 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean;
1884 -- Typ is the type of the current component, check whether this type is
1885 -- a limited type. Used to validate declaration against that of
1886 -- enclosing record.
1892 function Contains_POC
(Constr
: Node_Id
) return Boolean is
1894 -- Prevent cascaded errors
1896 if Error_Posted
(Constr
) then
1900 case Nkind
(Constr
) is
1901 when N_Attribute_Reference
=>
1902 return Attribute_Name
(Constr
) = Name_Access
1903 and then Prefix
(Constr
) = Scope
(Entity
(Prefix
(Constr
)));
1905 when N_Discriminant_Association
=>
1906 return Denotes_Discriminant
(Expression
(Constr
));
1908 when N_Identifier
=>
1909 return Denotes_Discriminant
(Constr
);
1911 when N_Index_Or_Discriminant_Constraint
=>
1916 IDC
:= First
(Constraints
(Constr
));
1917 while Present
(IDC
) loop
1919 -- One per-object constraint is sufficient
1921 if Contains_POC
(IDC
) then
1932 return Denotes_Discriminant
(Low_Bound
(Constr
))
1934 Denotes_Discriminant
(High_Bound
(Constr
));
1936 when N_Range_Constraint
=>
1937 return Denotes_Discriminant
(Range_Expression
(Constr
));
1944 ----------------------
1945 -- Is_Known_Limited --
1946 ----------------------
1948 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean is
1949 P
: constant Entity_Id
:= Etype
(Typ
);
1950 R
: constant Entity_Id
:= Root_Type
(Typ
);
1953 if Is_Limited_Record
(Typ
) then
1956 -- If the root type is limited (and not a limited interface) so is
1957 -- the current type.
1959 elsif Is_Limited_Record
(R
)
1960 and then (not Is_Interface
(R
) or else not Is_Limited_Interface
(R
))
1964 -- Else the type may have a limited interface progenitor, but a
1965 -- limited record parent that is not an interface.
1968 and then Is_Limited_Record
(P
)
1969 and then not Is_Interface
(P
)
1976 end Is_Known_Limited
;
1978 -- Start of processing for Analyze_Component_Declaration
1981 Generate_Definition
(Id
);
1984 if Present
(Typ
) then
1985 T
:= Find_Type_Of_Object
1986 (Subtype_Indication
(Component_Definition
(N
)), N
);
1988 -- Ada 2005 (AI-230): Access Definition case
1991 pragma Assert
(Present
1992 (Access_Definition
(Component_Definition
(N
))));
1994 T
:= Access_Definition
1996 N
=> Access_Definition
(Component_Definition
(N
)));
1997 Set_Is_Local_Anonymous_Access
(T
);
1999 -- Ada 2005 (AI-254)
2001 if Present
(Access_To_Subprogram_Definition
2002 (Access_Definition
(Component_Definition
(N
))))
2003 and then Protected_Present
(Access_To_Subprogram_Definition
2005 (Component_Definition
(N
))))
2007 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2011 -- If the subtype is a constrained subtype of the enclosing record,
2012 -- (which must have a partial view) the back-end does not properly
2013 -- handle the recursion. Rewrite the component declaration with an
2014 -- explicit subtype indication, which is acceptable to Gigi. We can copy
2015 -- the tree directly because side effects have already been removed from
2016 -- discriminant constraints.
2018 if Ekind
(T
) = E_Access_Subtype
2019 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
2020 and then Comes_From_Source
(T
)
2021 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
2022 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
2025 (Subtype_Indication
(Component_Definition
(N
)),
2026 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
2027 T
:= Find_Type_Of_Object
2028 (Subtype_Indication
(Component_Definition
(N
)), N
);
2031 -- If the component declaration includes a default expression, then we
2032 -- check that the component is not of a limited type (RM 3.7(5)),
2033 -- and do the special preanalysis of the expression (see section on
2034 -- "Handling of Default and Per-Object Expressions" in the spec of
2038 Preanalyze_Default_Expression
(E
, T
);
2039 Check_Initialization
(T
, E
);
2041 if Ada_Version
>= Ada_2005
2042 and then Ekind
(T
) = E_Anonymous_Access_Type
2043 and then Etype
(E
) /= Any_Type
2045 -- Check RM 3.9.2(9): "if the expected type for an expression is
2046 -- an anonymous access-to-specific tagged type, then the object
2047 -- designated by the expression shall not be dynamically tagged
2048 -- unless it is a controlling operand in a call on a dispatching
2051 if Is_Tagged_Type
(Directly_Designated_Type
(T
))
2053 Ekind
(Directly_Designated_Type
(T
)) /= E_Class_Wide_Type
2055 Ekind
(Directly_Designated_Type
(Etype
(E
))) =
2059 ("access to specific tagged type required (RM 3.9.2(9))", E
);
2062 -- (Ada 2005: AI-230): Accessibility check for anonymous
2065 if Type_Access_Level
(Etype
(E
)) >
2066 Deepest_Type_Access_Level
(T
)
2069 ("expression has deeper access level than component " &
2070 "(RM 3.10.2 (12.2))", E
);
2073 -- The initialization expression is a reference to an access
2074 -- discriminant. The type of the discriminant is always deeper
2075 -- than any access type.
2077 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
2078 and then Is_Entity_Name
(E
)
2079 and then Ekind
(Entity
(E
)) = E_In_Parameter
2080 and then Present
(Discriminal_Link
(Entity
(E
)))
2083 ("discriminant has deeper accessibility level than target",
2089 -- The parent type may be a private view with unknown discriminants,
2090 -- and thus unconstrained. Regular components must be constrained.
2092 if not Is_Definite_Subtype
(T
)
2093 and then Chars
(Id
) /= Name_uParent
2095 if Is_Class_Wide_Type
(T
) then
2097 ("class-wide subtype with unknown discriminants" &
2098 " in component declaration",
2099 Subtype_Indication
(Component_Definition
(N
)));
2102 ("unconstrained subtype in component declaration",
2103 Subtype_Indication
(Component_Definition
(N
)));
2106 -- Components cannot be abstract, except for the special case of
2107 -- the _Parent field (case of extending an abstract tagged type)
2109 elsif Is_Abstract_Type
(T
) and then Chars
(Id
) /= Name_uParent
then
2110 Error_Msg_N
("type of a component cannot be abstract", N
);
2115 if Aliased_Present
(Component_Definition
(N
)) then
2116 Set_Is_Aliased
(Id
);
2118 -- AI12-001: All aliased objects are considered to be specified as
2119 -- independently addressable (RM C.6(8.1/4)).
2121 Set_Is_Independent
(Id
);
2124 -- The component declaration may have a per-object constraint, set
2125 -- the appropriate flag in the defining identifier of the subtype.
2127 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
2129 Sindic
: constant Node_Id
:=
2130 Subtype_Indication
(Component_Definition
(N
));
2132 if Nkind
(Sindic
) = N_Subtype_Indication
2133 and then Present
(Constraint
(Sindic
))
2134 and then Contains_POC
(Constraint
(Sindic
))
2136 Set_Has_Per_Object_Constraint
(Id
);
2141 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2142 -- out some static checks.
2144 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(T
) then
2145 Null_Exclusion_Static_Checks
(N
);
2148 -- If this component is private (or depends on a private type), flag the
2149 -- record type to indicate that some operations are not available.
2151 P
:= Private_Component
(T
);
2155 -- Check for circular definitions
2157 if P
= Any_Type
then
2158 Set_Etype
(Id
, Any_Type
);
2160 -- There is a gap in the visibility of operations only if the
2161 -- component type is not defined in the scope of the record type.
2163 elsif Scope
(P
) = Scope
(Current_Scope
) then
2166 elsif Is_Limited_Type
(P
) then
2167 Set_Is_Limited_Composite
(Current_Scope
);
2170 Set_Is_Private_Composite
(Current_Scope
);
2175 and then Is_Limited_Type
(T
)
2176 and then Chars
(Id
) /= Name_uParent
2177 and then Is_Tagged_Type
(Current_Scope
)
2179 if Is_Derived_Type
(Current_Scope
)
2180 and then not Is_Known_Limited
(Current_Scope
)
2183 ("extension of nonlimited type cannot have limited components",
2186 if Is_Interface
(Root_Type
(Current_Scope
)) then
2188 ("\limitedness is not inherited from limited interface", N
);
2189 Error_Msg_N
("\add LIMITED to type indication", N
);
2192 Explain_Limited_Type
(T
, N
);
2193 Set_Etype
(Id
, Any_Type
);
2194 Set_Is_Limited_Composite
(Current_Scope
, False);
2196 elsif not Is_Derived_Type
(Current_Scope
)
2197 and then not Is_Limited_Record
(Current_Scope
)
2198 and then not Is_Concurrent_Type
(Current_Scope
)
2201 ("nonlimited tagged type cannot have limited components", N
);
2202 Explain_Limited_Type
(T
, N
);
2203 Set_Etype
(Id
, Any_Type
);
2204 Set_Is_Limited_Composite
(Current_Scope
, False);
2208 -- When possible, build the default subtype
2210 if Build_Default_Subtype_OK
(T
) then
2212 Act_T
: constant Entity_Id
:= Build_Default_Subtype
(T
, N
);
2215 Set_Etype
(Id
, Act_T
);
2217 -- Rewrite component definition to use the constrained subtype
2219 Rewrite
(Component_Definition
(N
),
2220 Make_Component_Definition
(Loc
,
2221 Subtype_Indication
=> New_Occurrence_Of
(Act_T
, Loc
)));
2225 Set_Original_Record_Component
(Id
, Id
);
2227 if Has_Aspects
(N
) then
2228 Analyze_Aspect_Specifications
(N
, Id
);
2231 Analyze_Dimension
(N
);
2232 end Analyze_Component_Declaration
;
2234 --------------------------
2235 -- Analyze_Declarations --
2236 --------------------------
2238 procedure Analyze_Declarations
(L
: List_Id
) is
2241 procedure Adjust_Decl
;
2242 -- Adjust Decl not to include implicit label declarations, since these
2243 -- have strange Sloc values that result in elaboration check problems.
2244 -- (They have the sloc of the label as found in the source, and that
2245 -- is ahead of the current declarative part).
2247 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
);
2248 -- Create the subprogram bodies which verify the run-time semantics of
2249 -- the pragmas listed below for each elibigle type found in declarative
2250 -- list Decls. The pragmas are:
2252 -- Default_Initial_Condition
2256 -- Context denotes the owner of the declarative list.
2258 procedure Check_Entry_Contracts
;
2259 -- Perform a preanalysis of the pre- and postconditions of an entry
2260 -- declaration. This must be done before full resolution and creation
2261 -- of the parameter block, etc. to catch illegal uses within the
2262 -- contract expression. Full analysis of the expression is done when
2263 -- the contract is processed.
2265 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean;
2266 -- Check if a nested package has entities within it that rely on library
2267 -- level private types where the full view has not been completed for
2268 -- the purposes of checking if it is acceptable to freeze an expression
2269 -- function at the point of declaration.
2271 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
);
2272 -- Determine whether Body_Decl denotes the body of a late controlled
2273 -- primitive (either Initialize, Adjust or Finalize). If this is the
2274 -- case, add a proper spec if the body lacks one. The spec is inserted
2275 -- before Body_Decl and immediately analyzed.
2277 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
);
2278 -- Spec_Id is the entity of a package that may define abstract states,
2279 -- and in the case of a child unit, whose ancestors may define abstract
2280 -- states. If the states have partial visible refinement, remove the
2281 -- partial visibility of each constituent at the end of the package
2282 -- spec and body declarations.
2284 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
);
2285 -- Spec_Id is the entity of a package that may define abstract states.
2286 -- If the states have visible refinement, remove the visibility of each
2287 -- constituent at the end of the package body declaration.
2289 procedure Resolve_Aspects
;
2290 -- Utility to resolve the expressions of aspects at the end of a list of
2291 -- declarations, or before a declaration that freezes previous entities,
2292 -- such as in a subprogram body.
2298 procedure Adjust_Decl
is
2300 while Present
(Prev
(Decl
))
2301 and then Nkind
(Decl
) = N_Implicit_Label_Declaration
2307 ----------------------------
2308 -- Build_Assertion_Bodies --
2309 ----------------------------
2311 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
) is
2312 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
);
2313 -- Create the subprogram bodies which verify the run-time semantics
2314 -- of the pragmas listed below for type Typ. The pragmas are:
2316 -- Default_Initial_Condition
2320 -------------------------------------
2321 -- Build_Assertion_Bodies_For_Type --
2322 -------------------------------------
2324 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
) is
2326 if Nkind
(Context
) = N_Package_Specification
then
2328 -- Preanalyze and resolve the class-wide invariants of an
2329 -- interface at the end of whichever declarative part has the
2330 -- interface type. Note that an interface may be declared in
2331 -- any non-package declarative part, but reaching the end of
2332 -- such a declarative part will always freeze the type and
2333 -- generate the invariant procedure (see Freeze_Type).
2335 if Is_Interface
(Typ
) then
2337 -- Interfaces are treated as the partial view of a private
2338 -- type, in order to achieve uniformity with the general
2339 -- case. As a result, an interface receives only a "partial"
2340 -- invariant procedure, which is never called.
2342 if Has_Own_Invariants
(Typ
) then
2343 Build_Invariant_Procedure_Body
2345 Partial_Invariant
=> True);
2348 elsif Decls
= Visible_Declarations
(Context
) then
2349 -- Preanalyze and resolve the invariants of a private type
2350 -- at the end of the visible declarations to catch potential
2351 -- errors. Inherited class-wide invariants are not included
2352 -- because they have already been resolved.
2354 if Ekind
(Typ
) in E_Limited_Private_Type
2356 | E_Record_Type_With_Private
2357 and then Has_Own_Invariants
(Typ
)
2359 Build_Invariant_Procedure_Body
2361 Partial_Invariant
=> True);
2364 -- Preanalyze and resolve the Default_Initial_Condition
2365 -- assertion expression at the end of the declarations to
2366 -- catch any errors.
2368 if Ekind
(Typ
) in E_Limited_Private_Type
2370 | E_Record_Type_With_Private
2371 and then Has_Own_DIC
(Typ
)
2373 Build_DIC_Procedure_Body
2375 Partial_DIC
=> True);
2378 elsif Decls
= Private_Declarations
(Context
) then
2380 -- Preanalyze and resolve the invariants of a private type's
2381 -- full view at the end of the private declarations to catch
2382 -- potential errors.
2384 if (not Is_Private_Type
(Typ
)
2385 or else Present
(Underlying_Full_View
(Typ
)))
2386 and then Has_Private_Declaration
(Typ
)
2387 and then Has_Invariants
(Typ
)
2389 Build_Invariant_Procedure_Body
(Typ
);
2392 if (not Is_Private_Type
(Typ
)
2393 or else Present
(Underlying_Full_View
(Typ
)))
2394 and then Has_Private_Declaration
(Typ
)
2395 and then Has_DIC
(Typ
)
2397 Build_DIC_Procedure_Body
(Typ
);
2401 end Build_Assertion_Bodies_For_Type
;
2406 Decl_Id
: Entity_Id
;
2408 -- Start of processing for Build_Assertion_Bodies
2411 Decl
:= First
(Decls
);
2412 while Present
(Decl
) loop
2413 if Is_Declaration
(Decl
) then
2414 Decl_Id
:= Defining_Entity
(Decl
);
2416 if Is_Type
(Decl_Id
) then
2417 Build_Assertion_Bodies_For_Type
(Decl_Id
);
2423 end Build_Assertion_Bodies
;
2425 ---------------------------
2426 -- Check_Entry_Contracts --
2427 ---------------------------
2429 procedure Check_Entry_Contracts
is
2435 Ent
:= First_Entity
(Current_Scope
);
2436 while Present
(Ent
) loop
2438 -- This only concerns entries with pre/postconditions
2440 if Ekind
(Ent
) = E_Entry
2441 and then Present
(Contract
(Ent
))
2442 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
2444 ASN
:= Pre_Post_Conditions
(Contract
(Ent
));
2446 Install_Formals
(Ent
);
2448 -- Pre/postconditions are rewritten as Check pragmas. Analysis
2449 -- is performed on a copy of the pragma expression, to prevent
2450 -- modifying the original expression.
2452 while Present
(ASN
) loop
2453 if Nkind
(ASN
) = N_Pragma
then
2457 (First
(Pragma_Argument_Associations
(ASN
))));
2458 Set_Parent
(Exp
, ASN
);
2460 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
2463 ASN
:= Next_Pragma
(ASN
);
2471 end Check_Entry_Contracts
;
2473 ----------------------------------
2474 -- Contains_Lib_Incomplete_Type --
2475 ----------------------------------
2477 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean is
2481 -- Avoid looking through scopes that do not meet the precondition of
2482 -- Pkg not being within a library unit spec.
2484 if not Is_Compilation_Unit
(Pkg
)
2485 and then not Is_Generic_Instance
(Pkg
)
2486 and then not In_Package_Body
(Enclosing_Lib_Unit_Entity
(Pkg
))
2488 -- Loop through all entities in the current scope to identify
2489 -- an entity that depends on a private type.
2491 Curr
:= First_Entity
(Pkg
);
2493 if Nkind
(Curr
) in N_Entity
2494 and then Depends_On_Private
(Curr
)
2499 exit when Last_Entity
(Current_Scope
) = Curr
;
2505 end Contains_Lib_Incomplete_Type
;
2507 --------------------------------------
2508 -- Handle_Late_Controlled_Primitive --
2509 --------------------------------------
2511 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
) is
2512 Body_Spec
: constant Node_Id
:= Specification
(Body_Decl
);
2513 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2514 Loc
: constant Source_Ptr
:= Sloc
(Body_Id
);
2515 Params
: constant List_Id
:=
2516 Parameter_Specifications
(Body_Spec
);
2518 Spec_Id
: Entity_Id
;
2522 -- Consider only procedure bodies whose name matches one of the three
2523 -- controlled primitives.
2525 if Nkind
(Body_Spec
) /= N_Procedure_Specification
2526 or else Chars
(Body_Id
) not in Name_Adjust
2532 -- A controlled primitive must have exactly one formal which is not
2533 -- an anonymous access type.
2535 elsif List_Length
(Params
) /= 1 then
2539 Typ
:= Parameter_Type
(First
(Params
));
2541 if Nkind
(Typ
) = N_Access_Definition
then
2547 -- The type of the formal must be derived from [Limited_]Controlled
2549 if not Is_Controlled
(Entity
(Typ
)) then
2553 -- Check whether a specification exists for this body. We do not
2554 -- analyze the spec of the body in full, because it will be analyzed
2555 -- again when the body is properly analyzed, and we cannot create
2556 -- duplicate entries in the formals chain. We look for an explicit
2557 -- specification because the body may be an overriding operation and
2558 -- an inherited spec may be present.
2560 Spec_Id
:= Current_Entity
(Body_Id
);
2562 while Present
(Spec_Id
) loop
2563 if Ekind
(Spec_Id
) in E_Procedure | E_Generic_Procedure
2564 and then Scope
(Spec_Id
) = Current_Scope
2565 and then Present
(First_Formal
(Spec_Id
))
2566 and then No
(Next_Formal
(First_Formal
(Spec_Id
)))
2567 and then Etype
(First_Formal
(Spec_Id
)) = Entity
(Typ
)
2568 and then Comes_From_Source
(Spec_Id
)
2573 Spec_Id
:= Homonym
(Spec_Id
);
2576 -- At this point the body is known to be a late controlled primitive.
2577 -- Generate a matching spec and insert it before the body. Note the
2578 -- use of Copy_Separate_Tree - we want an entirely separate semantic
2579 -- tree in this case.
2581 Spec
:= Copy_Separate_Tree
(Body_Spec
);
2583 -- Ensure that the subprogram declaration does not inherit the null
2584 -- indicator from the body as we now have a proper spec/body pair.
2586 Set_Null_Present
(Spec
, False);
2588 -- Ensure that the freeze node is inserted after the declaration of
2589 -- the primitive since its expansion will freeze the primitive.
2591 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
2593 Insert_Before_And_Analyze
(Body_Decl
, Decl
);
2594 end Handle_Late_Controlled_Primitive
;
2596 ----------------------------------------
2597 -- Remove_Partial_Visible_Refinements --
2598 ----------------------------------------
2600 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2601 State_Elmt
: Elmt_Id
;
2603 if Present
(Abstract_States
(Spec_Id
)) then
2604 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2605 while Present
(State_Elmt
) loop
2606 Set_Has_Partial_Visible_Refinement
(Node
(State_Elmt
), False);
2607 Next_Elmt
(State_Elmt
);
2611 -- For a child unit, also hide the partial state refinement from
2612 -- ancestor packages.
2614 if Is_Child_Unit
(Spec_Id
) then
2615 Remove_Partial_Visible_Refinements
(Scope
(Spec_Id
));
2617 end Remove_Partial_Visible_Refinements
;
2619 --------------------------------
2620 -- Remove_Visible_Refinements --
2621 --------------------------------
2623 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2624 State_Elmt
: Elmt_Id
;
2626 if Present
(Abstract_States
(Spec_Id
)) then
2627 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2628 while Present
(State_Elmt
) loop
2629 Set_Has_Visible_Refinement
(Node
(State_Elmt
), False);
2630 Next_Elmt
(State_Elmt
);
2633 end Remove_Visible_Refinements
;
2635 ---------------------
2636 -- Resolve_Aspects --
2637 ---------------------
2639 procedure Resolve_Aspects
is
2643 E
:= First_Entity
(Current_Scope
);
2644 while Present
(E
) loop
2645 Resolve_Aspect_Expressions
(E
);
2647 -- Now that the aspect expressions have been resolved, if this is
2648 -- at the end of the visible declarations, we can set the flag
2649 -- Known_To_Have_Preelab_Init properly on types declared in the
2650 -- visible part, which is needed for checking whether full types
2651 -- in the private part satisfy the Preelaborable_Initialization
2652 -- aspect of the partial view. We can't wait for the creation of
2653 -- the pragma by Analyze_Aspects_At_Freeze_Point, because the
2654 -- freeze point may occur after the end of the package declaration
2655 -- (in the case of nested packages).
2658 and then L
= Visible_Declarations
(Parent
(L
))
2659 and then Has_Aspect
(E
, Aspect_Preelaborable_Initialization
)
2662 ASN
: constant Node_Id
:=
2663 Find_Aspect
(E
, Aspect_Preelaborable_Initialization
);
2664 Expr
: constant Node_Id
:= Expression
(ASN
);
2666 -- Set Known_To_Have_Preelab_Init to True if aspect has no
2667 -- expression, or if the expression is True (or was folded
2668 -- to True), or if the expression is a conjunction of one or
2669 -- more Preelaborable_Initialization attributes applied to
2670 -- formal types and wasn't folded to False. (Note that
2671 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes goes to
2672 -- Original_Node if needed, hence test for Standard_False.)
2675 or else (Is_Entity_Name
(Expr
)
2676 and then Entity
(Expr
) = Standard_True
)
2678 (Is_Conjunction_Of_Formal_Preelab_Init_Attributes
(Expr
)
2680 not (Is_Entity_Name
(Expr
)
2681 and then Entity
(Expr
) = Standard_False
))
2683 Set_Known_To_Have_Preelab_Init
(E
);
2690 end Resolve_Aspects
;
2694 Context
: Node_Id
:= Empty
;
2695 Ctrl_Typ
: Entity_Id
:= Empty
;
2696 Freeze_From
: Entity_Id
:= Empty
;
2697 Next_Decl
: Node_Id
;
2699 -- Start of processing for Analyze_Declarations
2703 while Present
(Decl
) loop
2705 -- Complete analysis of declaration
2708 Next_Decl
:= Next
(Decl
);
2710 if No
(Freeze_From
) then
2711 Freeze_From
:= First_Entity
(Current_Scope
);
2714 -- Remember if the declaration we just processed is the full type
2715 -- declaration of a controlled type (to handle late overriding of
2716 -- initialize, adjust or finalize).
2718 if Nkind
(Decl
) = N_Full_Type_Declaration
2719 and then Is_Controlled
(Defining_Identifier
(Decl
))
2721 Ctrl_Typ
:= Defining_Identifier
(Decl
);
2724 -- At the end of a declarative part, freeze remaining entities
2725 -- declared in it. The end of the visible declarations of package
2726 -- specification is not the end of a declarative part if private
2727 -- declarations are present. The end of a package declaration is a
2728 -- freezing point only if it a library package. A task definition or
2729 -- protected type definition is not a freeze point either. Finally,
2730 -- we do not freeze entities in generic scopes, because there is no
2731 -- code generated for them and freeze nodes will be generated for
2734 -- The end of a package instantiation is not a freeze point, but
2735 -- for now we make it one, because the generic body is inserted
2736 -- (currently) immediately after. Generic instantiations will not
2737 -- be a freeze point once delayed freezing of bodies is implemented.
2738 -- (This is needed in any case for early instantiations ???).
2740 if No
(Next_Decl
) then
2741 if Nkind
(Parent
(L
)) = N_Component_List
then
2744 elsif Nkind
(Parent
(L
)) in
2745 N_Protected_Definition | N_Task_Definition
2747 Check_Entry_Contracts
;
2749 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
2750 if Nkind
(Parent
(L
)) = N_Package_Body
then
2751 Freeze_From
:= First_Entity
(Current_Scope
);
2754 -- There may have been several freezing points previously,
2755 -- for example object declarations or subprogram bodies, but
2756 -- at the end of a declarative part we check freezing from
2757 -- the beginning, even though entities may already be frozen,
2758 -- in order to perform visibility checks on delayed aspects.
2762 -- If the current scope is a generic subprogram body. Skip the
2763 -- generic formal parameters that are not frozen here.
2765 if Is_Subprogram
(Current_Scope
)
2766 and then Nkind
(Unit_Declaration_Node
(Current_Scope
)) =
2767 N_Generic_Subprogram_Declaration
2768 and then Present
(First_Entity
(Current_Scope
))
2770 while Is_Generic_Formal
(Freeze_From
) loop
2771 Next_Entity
(Freeze_From
);
2774 Freeze_All
(Freeze_From
, Decl
);
2775 Freeze_From
:= Last_Entity
(Current_Scope
);
2778 -- For declarations in a subprogram body there is no issue
2779 -- with name resolution in aspect specifications.
2781 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2782 Freeze_From
:= Last_Entity
(Current_Scope
);
2785 -- Current scope is a package specification
2787 elsif Scope
(Current_Scope
) /= Standard_Standard
2788 and then not Is_Child_Unit
(Current_Scope
)
2789 and then No
(Generic_Parent
(Parent
(L
)))
2791 -- ARM rule 13.1.1(11/3): usage names in aspect definitions are
2792 -- resolved at the end of the immediately enclosing declaration
2793 -- list (AI05-0183-1).
2797 elsif L
/= Visible_Declarations
(Parent
(L
))
2798 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
2802 -- End of a package declaration
2804 -- This is a freeze point because it is the end of a
2805 -- compilation unit.
2807 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2808 Freeze_From
:= Last_Entity
(Current_Scope
);
2810 -- At the end of the visible declarations the expressions in
2811 -- aspects of all entities declared so far must be resolved.
2812 -- The entities themselves might be frozen later, and the
2813 -- generated pragmas and attribute definition clauses analyzed
2814 -- in full at that point, but name resolution must take place
2816 -- In addition to being the proper semantics, this is mandatory
2817 -- within generic units, because global name capture requires
2818 -- those expressions to be analyzed, given that the generated
2819 -- pragmas do not appear in the original generic tree.
2821 elsif Serious_Errors_Detected
= 0 then
2825 -- If next node is a body then freeze all types before the body.
2826 -- An exception occurs for some expander-generated bodies. If these
2827 -- are generated at places where in general language rules would not
2828 -- allow a freeze point, then we assume that the expander has
2829 -- explicitly checked that all required types are properly frozen,
2830 -- and we do not cause general freezing here. This special circuit
2831 -- is used when the encountered body is marked as having already
2834 -- In all other cases (bodies that come from source, and expander
2835 -- generated bodies that have not been analyzed yet), freeze all
2836 -- types now. Note that in the latter case, the expander must take
2837 -- care to attach the bodies at a proper place in the tree so as to
2838 -- not cause unwanted freezing at that point.
2840 -- It is also necessary to check for a case where both an expression
2841 -- function is used and the current scope depends on an incomplete
2842 -- private type from a library unit, otherwise premature freezing of
2843 -- the private type will occur.
2845 elsif not Analyzed
(Next_Decl
) and then Is_Body
(Next_Decl
)
2846 and then ((Nkind
(Next_Decl
) /= N_Subprogram_Body
2847 or else not Was_Expression_Function
(Next_Decl
))
2848 or else (not Is_Ignored_Ghost_Entity
(Current_Scope
)
2849 and then not Contains_Lib_Incomplete_Type
2852 -- When a controlled type is frozen, the expander generates stream
2853 -- and controlled-type support routines. If the freeze is caused
2854 -- by the stand-alone body of Initialize, Adjust, or Finalize, the
2855 -- expander will end up using the wrong version of these routines,
2856 -- as the body has not been processed yet. To remedy this, detect
2857 -- a late controlled primitive and create a proper spec for it.
2858 -- This ensures that the primitive will override its inherited
2859 -- counterpart before the freeze takes place.
2861 -- If the declaration we just processed is a body, do not attempt
2862 -- to examine Next_Decl as the late primitive idiom can only apply
2863 -- to the first encountered body.
2865 -- ??? A cleaner approach may be possible and/or this solution
2866 -- could be extended to general-purpose late primitives.
2868 if Present
(Ctrl_Typ
) then
2870 -- No need to continue searching for late body overriding if
2871 -- the controlled type is already frozen.
2873 if Is_Frozen
(Ctrl_Typ
) then
2876 elsif Nkind
(Next_Decl
) = N_Subprogram_Body
then
2877 Handle_Late_Controlled_Primitive
(Next_Decl
);
2883 -- The generated body of an expression function does not freeze,
2884 -- unless it is a completion, in which case only the expression
2885 -- itself freezes. This is handled when the body itself is
2886 -- analyzed (see Freeze_Expr_Types, sem_ch6.adb).
2888 Freeze_All
(Freeze_From
, Decl
);
2889 Freeze_From
:= Last_Entity
(Current_Scope
);
2895 -- Post-freezing actions
2898 Context
:= Parent
(L
);
2900 -- Certain contract annotations have forward visibility semantics and
2901 -- must be analyzed after all declarative items have been processed.
2902 -- This timing ensures that entities referenced by such contracts are
2905 -- Analyze the contract of an immediately enclosing package spec or
2906 -- body first because other contracts may depend on its information.
2908 if Nkind
(Context
) = N_Package_Body
then
2909 Analyze_Package_Body_Contract
(Defining_Entity
(Context
));
2911 elsif Nkind
(Context
) = N_Package_Specification
then
2912 Analyze_Package_Contract
(Defining_Entity
(Context
));
2915 -- Analyze the contracts of various constructs in the declarative
2918 Analyze_Contracts
(L
);
2920 if Nkind
(Context
) = N_Package_Body
then
2922 -- Ensure that all abstract states and objects declared in the
2923 -- state space of a package body are utilized as constituents.
2925 Check_Unused_Body_States
(Defining_Entity
(Context
));
2927 -- State refinements are visible up to the end of the package body
2928 -- declarations. Hide the state refinements from visibility to
2929 -- restore the original state conditions.
2931 Remove_Visible_Refinements
(Corresponding_Spec
(Context
));
2932 Remove_Partial_Visible_Refinements
(Corresponding_Spec
(Context
));
2934 elsif Nkind
(Context
) = N_Package_Specification
then
2936 -- Partial state refinements are visible up to the end of the
2937 -- package spec declarations. Hide the partial state refinements
2938 -- from visibility to restore the original state conditions.
2940 Remove_Partial_Visible_Refinements
(Defining_Entity
(Context
));
2943 -- Verify that all abstract states found in any package declared in
2944 -- the input declarative list have proper refinements. The check is
2945 -- performed only when the context denotes a block, entry, package,
2946 -- protected, subprogram, or task body (SPARK RM 7.1.4(4) and SPARK
2949 Check_State_Refinements
(Context
);
2951 -- Create the subprogram bodies which verify the run-time semantics
2952 -- of pragmas Default_Initial_Condition and [Type_]Invariant for all
2953 -- types within the current declarative list. This ensures that all
2954 -- assertion expressions are preanalyzed and resolved at the end of
2955 -- the declarative part. Note that the resolution happens even when
2956 -- freezing does not take place.
2958 Build_Assertion_Bodies
(L
, Context
);
2960 end Analyze_Declarations
;
2962 -----------------------------------
2963 -- Analyze_Full_Type_Declaration --
2964 -----------------------------------
2966 procedure Analyze_Full_Type_Declaration
(N
: Node_Id
) is
2967 Def
: constant Node_Id
:= Type_Definition
(N
);
2968 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2972 Is_Remote
: constant Boolean :=
2973 (Is_Remote_Types
(Current_Scope
)
2974 or else Is_Remote_Call_Interface
(Current_Scope
))
2975 and then not (In_Private_Part
(Current_Scope
)
2976 or else In_Package_Body
(Current_Scope
));
2978 procedure Check_Nonoverridable_Aspects
;
2979 -- Apply the rule in RM 13.1.1(18.4/4) on iterator aspects that cannot
2980 -- be overridden, and can only be confirmed on derivation.
2982 procedure Check_Ops_From_Incomplete_Type
;
2983 -- If there is a tagged incomplete partial view of the type, traverse
2984 -- the primitives of the incomplete view and change the type of any
2985 -- controlling formals and result to indicate the full view. The
2986 -- primitives will be added to the full type's primitive operations
2987 -- list later in Sem_Disp.Check_Operation_From_Incomplete_Type (which
2988 -- is called from Process_Incomplete_Dependents).
2990 ----------------------------------
2991 -- Check_Nonoverridable_Aspects --
2992 ----------------------------------
2994 procedure Check_Nonoverridable_Aspects
is
2995 function Get_Aspect_Spec
2997 Aspect_Name
: Name_Id
) return Node_Id
;
2998 -- Check whether a list of aspect specifications includes an entry
2999 -- for a specific aspect. The list is either that of a partial or
3002 ---------------------
3003 -- Get_Aspect_Spec --
3004 ---------------------
3006 function Get_Aspect_Spec
3008 Aspect_Name
: Name_Id
) return Node_Id
3013 Spec
:= First
(Specs
);
3014 while Present
(Spec
) loop
3015 if Chars
(Identifier
(Spec
)) = Aspect_Name
then
3022 end Get_Aspect_Spec
;
3026 Prev_Aspects
: constant List_Id
:=
3027 Aspect_Specifications
(Parent
(Def_Id
));
3028 Par_Type
: Entity_Id
;
3029 Prev_Aspect
: Node_Id
;
3031 -- Start of processing for Check_Nonoverridable_Aspects
3034 -- Get parent type of derived type. Note that Prev is the entity in
3035 -- the partial declaration, but its contents are now those of full
3036 -- view, while Def_Id reflects the partial view.
3038 if Is_Private_Type
(Def_Id
) then
3039 Par_Type
:= Etype
(Full_View
(Def_Id
));
3041 Par_Type
:= Etype
(Def_Id
);
3044 -- If there is an inherited Implicit_Dereference, verify that it is
3045 -- made explicit in the partial view.
3047 if Has_Discriminants
(Base_Type
(Par_Type
))
3048 and then Nkind
(Parent
(Prev
)) = N_Full_Type_Declaration
3049 and then Present
(Discriminant_Specifications
(Parent
(Prev
)))
3050 and then Present
(Get_Reference_Discriminant
(Par_Type
))
3053 Get_Aspect_Spec
(Prev_Aspects
, Name_Implicit_Dereference
);
3057 (Discriminant_Specifications
3058 (Original_Node
(Parent
(Prev
))))
3061 ("type does not inherit implicit dereference", Prev
);
3064 -- If one of the views has the aspect specified, verify that it
3065 -- is consistent with that of the parent.
3068 Cur_Discr
: constant Entity_Id
:=
3069 Get_Reference_Discriminant
(Prev
);
3070 Par_Discr
: constant Entity_Id
:=
3071 Get_Reference_Discriminant
(Par_Type
);
3074 if Corresponding_Discriminant
(Cur_Discr
) /= Par_Discr
then
3076 ("aspect inconsistent with that of parent", N
);
3079 -- Check that specification in partial view matches the
3080 -- inherited aspect. Compare names directly because aspect
3081 -- expression may not be analyzed.
3083 if Present
(Prev_Aspect
)
3084 and then Nkind
(Expression
(Prev_Aspect
)) = N_Identifier
3085 and then Chars
(Expression
(Prev_Aspect
)) /=
3089 ("aspect inconsistent with that of parent", N
);
3095 -- What about other nonoverridable aspects???
3096 end Check_Nonoverridable_Aspects
;
3098 ------------------------------------
3099 -- Check_Ops_From_Incomplete_Type --
3100 ------------------------------------
3102 procedure Check_Ops_From_Incomplete_Type
is
3109 and then Ekind
(Prev
) = E_Incomplete_Type
3110 and then Is_Tagged_Type
(Prev
)
3111 and then Is_Tagged_Type
(T
)
3112 and then Present
(Primitive_Operations
(Prev
))
3114 Elmt
:= First_Elmt
(Primitive_Operations
(Prev
));
3115 while Present
(Elmt
) loop
3118 Formal
:= First_Formal
(Op
);
3119 while Present
(Formal
) loop
3120 if Etype
(Formal
) = Prev
then
3121 Set_Etype
(Formal
, T
);
3124 Next_Formal
(Formal
);
3127 if Etype
(Op
) = Prev
then
3134 end Check_Ops_From_Incomplete_Type
;
3136 -- Start of processing for Analyze_Full_Type_Declaration
3139 Prev
:= Find_Type_Name
(N
);
3141 -- The full view, if present, now points to the current type. If there
3142 -- is an incomplete partial view, set a link to it, to simplify the
3143 -- retrieval of primitive operations of the type.
3145 -- Ada 2005 (AI-50217): If the type was previously decorated when
3146 -- imported through a LIMITED WITH clause, it appears as incomplete
3147 -- but has no full view.
3149 if Ekind
(Prev
) = E_Incomplete_Type
3150 and then Present
(Full_View
(Prev
))
3152 T
:= Full_View
(Prev
);
3153 Set_Incomplete_View
(N
, Prev
);
3158 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
3160 -- We set the flag Is_First_Subtype here. It is needed to set the
3161 -- corresponding flag for the Implicit class-wide-type created
3162 -- during tagged types processing.
3164 Set_Is_First_Subtype
(T
, True);
3166 -- Only composite types other than array types are allowed to have
3171 -- For derived types, the rule will be checked once we've figured
3172 -- out the parent type.
3174 when N_Derived_Type_Definition
=>
3177 -- For record types, discriminants are allowed.
3179 when N_Record_Definition
=>
3183 if Present
(Discriminant_Specifications
(N
)) then
3185 ("elementary or array type cannot have discriminants",
3187 (First
(Discriminant_Specifications
(N
))));
3191 -- Elaborate the type definition according to kind, and generate
3192 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3193 -- already done (this happens during the reanalysis that follows a call
3194 -- to the high level optimizer).
3196 if not Analyzed
(T
) then
3199 -- Set the SPARK mode from the current context
3201 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3202 Set_SPARK_Pragma_Inherited
(T
);
3205 when N_Access_To_Subprogram_Definition
=>
3206 Access_Subprogram_Declaration
(T
, Def
);
3208 -- If this is a remote access to subprogram, we must create the
3209 -- equivalent fat pointer type, and related subprograms.
3212 Process_Remote_AST_Declaration
(N
);
3215 -- Validate categorization rule against access type declaration
3216 -- usually a violation in Pure unit, Shared_Passive unit.
3218 Validate_Access_Type_Declaration
(T
, N
);
3220 -- If the type has contracts, we create the corresponding
3221 -- wrapper at once, before analyzing the aspect specifications,
3222 -- so that pre/postconditions can be handled directly on the
3223 -- generated wrapper.
3225 if Ada_Version
>= Ada_2022
3226 and then Present
(Aspect_Specifications
(N
))
3228 Build_Access_Subprogram_Wrapper
(N
);
3231 when N_Access_To_Object_Definition
=>
3232 Access_Type_Declaration
(T
, Def
);
3234 -- Validate categorization rule against access type declaration
3235 -- usually a violation in Pure unit, Shared_Passive unit.
3237 Validate_Access_Type_Declaration
(T
, N
);
3239 -- If we are in a Remote_Call_Interface package and define a
3240 -- RACW, then calling stubs and specific stream attributes
3244 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
3246 Add_RACW_Features
(Def_Id
);
3249 when N_Array_Type_Definition
=>
3250 Array_Type_Declaration
(T
, Def
);
3252 when N_Derived_Type_Definition
=>
3253 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
3255 -- Inherit predicates from parent, and protect against illegal
3258 if Is_Type
(T
) and then Has_Predicates
(T
) then
3259 Set_Has_Predicates
(Def_Id
);
3262 -- Save the scenario for examination by the ABE Processing
3265 Record_Elaboration_Scenario
(N
);
3267 when N_Enumeration_Type_Definition
=>
3268 Enumeration_Type_Declaration
(T
, Def
);
3270 when N_Floating_Point_Definition
=>
3271 Floating_Point_Type_Declaration
(T
, Def
);
3273 when N_Decimal_Fixed_Point_Definition
=>
3274 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
3276 when N_Ordinary_Fixed_Point_Definition
=>
3277 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
3279 when N_Signed_Integer_Type_Definition
=>
3280 Signed_Integer_Type_Declaration
(T
, Def
);
3282 when N_Modular_Type_Definition
=>
3283 Modular_Type_Declaration
(T
, Def
);
3285 when N_Record_Definition
=>
3286 Record_Type_Declaration
(T
, N
, Prev
);
3288 -- If declaration has a parse error, nothing to elaborate.
3294 raise Program_Error
;
3298 if Etype
(T
) = Any_Type
then
3302 -- Set the primitives list of the full type and its base type when
3303 -- needed. T may be E_Void in cases of earlier errors, and in that
3304 -- case we bypass this.
3306 if Ekind
(T
) /= E_Void
then
3307 if not Present
(Direct_Primitive_Operations
(T
)) then
3308 if Etype
(T
) = T
then
3309 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3311 -- If Etype of T is the base type (as opposed to a parent type)
3312 -- and already has an associated list of primitive operations,
3313 -- then set T's primitive list to the base type's list. Otherwise,
3314 -- create a new empty primitives list and share the list between
3315 -- T and its base type. The lists need to be shared in common.
3317 elsif Etype
(T
) = Base_Type
(T
) then
3319 if not Present
(Direct_Primitive_Operations
(Base_Type
(T
)))
3321 Set_Direct_Primitive_Operations
3322 (Base_Type
(T
), New_Elmt_List
);
3325 Set_Direct_Primitive_Operations
3326 (T
, Direct_Primitive_Operations
(Base_Type
(T
)));
3328 -- Case where the Etype is a parent type, so we need a new
3329 -- primitives list for T.
3332 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3335 -- If T already has a Direct_Primitive_Operations list but its
3336 -- base type doesn't then set the base type's list to T's list.
3338 elsif not Present
(Direct_Primitive_Operations
(Base_Type
(T
))) then
3339 Set_Direct_Primitive_Operations
3340 (Base_Type
(T
), Direct_Primitive_Operations
(T
));
3344 -- Some common processing for all types
3346 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
3347 Check_Ops_From_Incomplete_Type
;
3349 -- Both the declared entity, and its anonymous base type if one was
3350 -- created, need freeze nodes allocated.
3353 B
: constant Entity_Id
:= Base_Type
(T
);
3356 -- In the case where the base type differs from the first subtype, we
3357 -- pre-allocate a freeze node, and set the proper link to the first
3358 -- subtype. Freeze_Entity will use this preallocated freeze node when
3359 -- it freezes the entity.
3361 -- This does not apply if the base type is a generic type, whose
3362 -- declaration is independent of the current derived definition.
3364 if B
/= T
and then not Is_Generic_Type
(B
) then
3365 Ensure_Freeze_Node
(B
);
3366 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
3369 -- A type that is imported through a limited_with clause cannot
3370 -- generate any code, and thus need not be frozen. However, an access
3371 -- type with an imported designated type needs a finalization list,
3372 -- which may be referenced in some other package that has non-limited
3373 -- visibility on the designated type. Thus we must create the
3374 -- finalization list at the point the access type is frozen, to
3375 -- prevent unsatisfied references at link time.
3377 if not From_Limited_With
(T
) or else Is_Access_Type
(T
) then
3378 Set_Has_Delayed_Freeze
(T
);
3382 -- Case where T is the full declaration of some private type which has
3383 -- been swapped in Defining_Identifier (N).
3385 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
3386 Process_Full_View
(N
, T
, Def_Id
);
3388 -- Record the reference. The form of this is a little strange, since
3389 -- the full declaration has been swapped in. So the first parameter
3390 -- here represents the entity to which a reference is made which is
3391 -- the "real" entity, i.e. the one swapped in, and the second
3392 -- parameter provides the reference location.
3394 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3395 -- since we don't want a complaint about the full type being an
3396 -- unwanted reference to the private type
3399 B
: constant Boolean := Has_Pragma_Unreferenced
(T
);
3401 Set_Has_Pragma_Unreferenced
(T
, False);
3402 Generate_Reference
(T
, T
, 'c');
3403 Set_Has_Pragma_Unreferenced
(T
, B
);
3406 Set_Completion_Referenced
(Def_Id
);
3408 -- For completion of incomplete type, process incomplete dependents
3409 -- and always mark the full type as referenced (it is the incomplete
3410 -- type that we get for any real reference).
3412 elsif Ekind
(Prev
) = E_Incomplete_Type
then
3413 Process_Incomplete_Dependents
(N
, T
, Prev
);
3414 Generate_Reference
(Prev
, Def_Id
, 'c');
3415 Set_Completion_Referenced
(Def_Id
);
3417 -- If not private type or incomplete type completion, this is a real
3418 -- definition of a new entity, so record it.
3421 Generate_Definition
(Def_Id
);
3424 -- Propagate any pending access types whose finalization masters need to
3425 -- be fully initialized from the partial to the full view. Guard against
3426 -- an illegal full view that remains unanalyzed.
3428 if Is_Type
(Def_Id
) and then Is_Incomplete_Or_Private_Type
(Prev
) then
3429 Set_Pending_Access_Types
(Def_Id
, Pending_Access_Types
(Prev
));
3432 if Chars
(Scope
(Def_Id
)) = Name_System
3433 and then Chars
(Def_Id
) = Name_Address
3434 and then In_Predefined_Unit
(N
)
3436 Set_Is_Descendant_Of_Address
(Def_Id
);
3437 Set_Is_Descendant_Of_Address
(Base_Type
(Def_Id
));
3438 Set_Is_Descendant_Of_Address
(Prev
);
3441 Set_Optimize_Alignment_Flags
(Def_Id
);
3442 Check_Eliminated
(Def_Id
);
3444 -- If the declaration is a completion and aspects are present, apply
3445 -- them to the entity for the type which is currently the partial
3446 -- view, but which is the one that will be frozen.
3448 if Has_Aspects
(N
) then
3450 -- In most cases the partial view is a private type, and both views
3451 -- appear in different declarative parts. In the unusual case where
3452 -- the partial view is incomplete, perform the analysis on the
3453 -- full view, to prevent freezing anomalies with the corresponding
3454 -- class-wide type, which otherwise might be frozen before the
3455 -- dispatch table is built.
3458 and then Ekind
(Prev
) /= E_Incomplete_Type
3460 Analyze_Aspect_Specifications
(N
, Prev
);
3465 Analyze_Aspect_Specifications
(N
, Def_Id
);
3469 if Is_Derived_Type
(Prev
)
3470 and then Def_Id
/= Prev
3472 Check_Nonoverridable_Aspects
;
3475 -- Check for tagged type declaration at library level
3477 if Is_Tagged_Type
(T
)
3478 and then not Is_Library_Level_Entity
(T
)
3480 Check_Restriction
(No_Local_Tagged_Types
, T
);
3482 end Analyze_Full_Type_Declaration
;
3484 ----------------------------------
3485 -- Analyze_Incomplete_Type_Decl --
3486 ----------------------------------
3488 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
3489 F
: constant Boolean := Is_Pure
(Current_Scope
);
3493 Generate_Definition
(Defining_Identifier
(N
));
3495 -- Process an incomplete declaration. The identifier must not have been
3496 -- declared already in the scope. However, an incomplete declaration may
3497 -- appear in the private part of a package, for a private type that has
3498 -- already been declared.
3500 -- In this case, the discriminants (if any) must match
3502 T
:= Find_Type_Name
(N
);
3504 Mutate_Ekind
(T
, E_Incomplete_Type
);
3506 Set_Is_First_Subtype
(T
);
3507 Reinit_Size_Align
(T
);
3509 -- Set the SPARK mode from the current context
3511 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3512 Set_SPARK_Pragma_Inherited
(T
);
3514 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
3515 -- incomplete types.
3517 if Tagged_Present
(N
) then
3518 Set_Is_Tagged_Type
(T
, True);
3519 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3520 Make_Class_Wide_Type
(T
);
3523 -- Initialize the list of primitive operations to an empty list,
3524 -- to cover tagged types as well as untagged types. For untagged
3525 -- types this is used either to analyze the call as legal when
3526 -- Core_Extensions_Allowed is True, or to issue a better error message
3529 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3531 Set_Stored_Constraint
(T
, No_Elist
);
3533 if Present
(Discriminant_Specifications
(N
)) then
3535 Process_Discriminants
(N
);
3539 -- If the type has discriminants, nontrivial subtypes may be declared
3540 -- before the full view of the type. The full views of those subtypes
3541 -- will be built after the full view of the type.
3543 Set_Private_Dependents
(T
, New_Elmt_List
);
3545 end Analyze_Incomplete_Type_Decl
;
3547 -----------------------------------
3548 -- Analyze_Interface_Declaration --
3549 -----------------------------------
3551 procedure Analyze_Interface_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
3552 CW
: constant Entity_Id
:= Class_Wide_Type
(T
);
3555 Set_Is_Tagged_Type
(T
);
3556 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3558 Set_Is_Limited_Record
(T
, Limited_Present
(Def
)
3559 or else Task_Present
(Def
)
3560 or else Protected_Present
(Def
)
3561 or else Synchronized_Present
(Def
));
3563 -- Type is abstract if full declaration carries keyword, or if previous
3564 -- partial view did.
3566 Set_Is_Abstract_Type
(T
);
3567 Set_Is_Interface
(T
);
3569 -- Type is a limited interface if it includes the keyword limited, task,
3570 -- protected, or synchronized.
3572 Set_Is_Limited_Interface
3573 (T
, Limited_Present
(Def
)
3574 or else Protected_Present
(Def
)
3575 or else Synchronized_Present
(Def
)
3576 or else Task_Present
(Def
));
3578 Set_Interfaces
(T
, New_Elmt_List
);
3579 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3581 -- Complete the decoration of the class-wide entity if it was already
3582 -- built (i.e. during the creation of the limited view)
3584 if Present
(CW
) then
3585 Set_Is_Interface
(CW
);
3586 Set_Is_Limited_Interface
(CW
, Is_Limited_Interface
(T
));
3589 -- Check runtime support for synchronized interfaces
3591 if Is_Concurrent_Interface
(T
)
3592 and then not RTE_Available
(RE_Select_Specific_Data
)
3594 Error_Msg_CRT
("synchronized interfaces", T
);
3596 end Analyze_Interface_Declaration
;
3598 -----------------------------
3599 -- Analyze_Itype_Reference --
3600 -----------------------------
3602 -- Nothing to do. This node is placed in the tree only for the benefit of
3603 -- back end processing, and has no effect on the semantic processing.
3605 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
3607 pragma Assert
(Is_Itype
(Itype
(N
)));
3609 end Analyze_Itype_Reference
;
3611 --------------------------------
3612 -- Analyze_Number_Declaration --
3613 --------------------------------
3615 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
3616 E
: constant Node_Id
:= Expression
(N
);
3617 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3618 Index
: Interp_Index
;
3623 Generate_Definition
(Id
);
3626 -- This is an optimization of a common case of an integer literal
3628 if Nkind
(E
) = N_Integer_Literal
then
3629 Set_Is_Static_Expression
(E
, True);
3630 Set_Etype
(E
, Universal_Integer
);
3632 Set_Etype
(Id
, Universal_Integer
);
3633 Mutate_Ekind
(Id
, E_Named_Integer
);
3634 Set_Is_Frozen
(Id
, True);
3636 Set_Debug_Info_Needed
(Id
);
3640 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3642 -- Process expression, replacing error by integer zero, to avoid
3643 -- cascaded errors or aborts further along in the processing
3645 -- Replace Error by integer zero, which seems least likely to cause
3649 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), Uint_0
));
3650 Set_Error_Posted
(E
);
3655 -- Verify that the expression is static and numeric. If
3656 -- the expression is overloaded, we apply the preference
3657 -- rule that favors root numeric types.
3659 if not Is_Overloaded
(E
) then
3661 if Has_Dynamic_Predicate_Aspect
(T
) then
3663 ("subtype has dynamic predicate, "
3664 & "not allowed in number declaration", N
);
3670 Get_First_Interp
(E
, Index
, It
);
3671 while Present
(It
.Typ
) loop
3672 if (Is_Integer_Type
(It
.Typ
) or else Is_Real_Type
(It
.Typ
))
3673 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
3675 if T
= Any_Type
then
3678 elsif Is_Universal_Numeric_Type
(It
.Typ
) then
3679 -- Choose universal interpretation over any other
3686 Get_Next_Interp
(Index
, It
);
3690 if Is_Integer_Type
(T
) then
3692 Set_Etype
(Id
, Universal_Integer
);
3693 Mutate_Ekind
(Id
, E_Named_Integer
);
3695 elsif Is_Real_Type
(T
) then
3697 -- Because the real value is converted to universal_real, this is a
3698 -- legal context for a universal fixed expression.
3700 if T
= Universal_Fixed
then
3702 Loc
: constant Source_Ptr
:= Sloc
(N
);
3703 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3705 New_Occurrence_Of
(Universal_Real
, Loc
),
3706 Expression
=> Relocate_Node
(E
));
3713 elsif T
= Any_Fixed
then
3714 Error_Msg_N
("illegal context for mixed mode operation", E
);
3716 -- Expression is of the form : universal_fixed * integer. Try to
3717 -- resolve as universal_real.
3719 T
:= Universal_Real
;
3724 Set_Etype
(Id
, Universal_Real
);
3725 Mutate_Ekind
(Id
, E_Named_Real
);
3728 Wrong_Type
(E
, Any_Numeric
);
3732 Mutate_Ekind
(Id
, E_Constant
);
3733 Set_Never_Set_In_Source
(Id
, True);
3734 Set_Is_True_Constant
(Id
, True);
3738 if Nkind
(E
) in N_Integer_Literal | N_Real_Literal
then
3739 Set_Etype
(E
, Etype
(Id
));
3742 if not Is_OK_Static_Expression
(E
) then
3743 Flag_Non_Static_Expr
3744 ("non-static expression used in number declaration!", E
);
3745 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
3746 Set_Etype
(E
, Any_Type
);
3749 Analyze_Dimension
(N
);
3750 end Analyze_Number_Declaration
;
3752 --------------------------------
3753 -- Analyze_Object_Declaration --
3754 --------------------------------
3756 -- WARNING: This routine manages Ghost regions. Return statements must be
3757 -- replaced by gotos which jump to the end of the routine and restore the
3760 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
3761 Loc
: constant Source_Ptr
:= Sloc
(N
);
3762 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3763 Next_Decl
: constant Node_Id
:= Next
(N
);
3768 E
: Node_Id
:= Expression
(N
);
3769 -- E is set to Expression (N) throughout this routine. When Expression
3770 -- (N) is modified, E is changed accordingly.
3772 procedure Check_Dynamic_Object
(Typ
: Entity_Id
);
3773 -- A library-level object with nonstatic discriminant constraints may
3774 -- require dynamic allocation. The declaration is illegal if the
3775 -- profile includes the restriction No_Implicit_Heap_Allocations.
3777 procedure Check_For_Null_Excluding_Components
3778 (Obj_Typ
: Entity_Id
;
3779 Obj_Decl
: Node_Id
);
3780 -- Verify that each null-excluding component of object declaration
3781 -- Obj_Decl carrying type Obj_Typ has explicit initialization. Emit
3782 -- a compile-time warning if this is not the case.
3784 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
3785 -- Check that the return subtype indication properly matches the result
3786 -- subtype of the function in an extended return object declaration, as
3787 -- required by RM 6.5(5.1/2-5.3/2).
3789 function Count_Tasks
(T
: Entity_Id
) return Uint
;
3790 -- This function is called when a non-generic library level object of a
3791 -- task type is declared. Its function is to count the static number of
3792 -- tasks declared within the type (it is only called if Has_Task is set
3793 -- for T). As a side effect, if an array of tasks with nonstatic bounds
3794 -- or a variant record type is encountered, Check_Restriction is called
3795 -- indicating the count is unknown.
3797 function Delayed_Aspect_Present
return Boolean;
3798 -- If the declaration has an expression that is an aggregate, and it
3799 -- has aspects that require delayed analysis, the resolution of the
3800 -- aggregate must be deferred to the freeze point of the object. This
3801 -- special processing was created for address clauses, but it must
3802 -- also apply to address aspects. This must be done before the aspect
3803 -- specifications are analyzed because we must handle the aggregate
3804 -- before the analysis of the object declaration is complete.
3806 -- Any other relevant delayed aspects on object declarations ???
3808 --------------------------
3809 -- Check_Dynamic_Object --
3810 --------------------------
3812 procedure Check_Dynamic_Object
(Typ
: Entity_Id
) is
3814 Obj_Type
: Entity_Id
;
3819 if Is_Private_Type
(Obj_Type
)
3820 and then Present
(Full_View
(Obj_Type
))
3822 Obj_Type
:= Full_View
(Obj_Type
);
3825 if Known_Static_Esize
(Obj_Type
) then
3829 if Restriction_Active
(No_Implicit_Heap_Allocations
)
3830 and then Expander_Active
3831 and then Has_Discriminants
(Obj_Type
)
3833 Comp
:= First_Component
(Obj_Type
);
3834 while Present
(Comp
) loop
3835 if Known_Static_Esize
(Etype
(Comp
))
3836 or else Size_Known_At_Compile_Time
(Etype
(Comp
))
3840 elsif Is_Record_Type
(Etype
(Comp
)) then
3841 Check_Dynamic_Object
(Etype
(Comp
));
3843 elsif not Discriminated_Size
(Comp
)
3844 and then Comes_From_Source
(Comp
)
3847 ("component& of non-static size will violate restriction "
3848 & "No_Implicit_Heap_Allocation?", N
, Comp
);
3852 Next_Component
(Comp
);
3855 end Check_Dynamic_Object
;
3857 -----------------------------------------
3858 -- Check_For_Null_Excluding_Components --
3859 -----------------------------------------
3861 procedure Check_For_Null_Excluding_Components
3862 (Obj_Typ
: Entity_Id
;
3865 procedure Check_Component
3866 (Comp_Typ
: Entity_Id
;
3867 Comp_Decl
: Node_Id
:= Empty
;
3868 Array_Comp
: Boolean := False);
3869 -- Apply a compile-time null-exclusion check on a component denoted
3870 -- by its declaration Comp_Decl and type Comp_Typ, and all of its
3871 -- subcomponents (if any).
3873 ---------------------
3874 -- Check_Component --
3875 ---------------------
3877 procedure Check_Component
3878 (Comp_Typ
: Entity_Id
;
3879 Comp_Decl
: Node_Id
:= Empty
;
3880 Array_Comp
: Boolean := False)
3886 -- Do not consider internally-generated components or those that
3887 -- are already initialized.
3889 if Present
(Comp_Decl
)
3890 and then (not Comes_From_Source
(Comp_Decl
)
3891 or else Present
(Expression
(Comp_Decl
)))
3896 if Is_Incomplete_Or_Private_Type
(Comp_Typ
)
3897 and then Present
(Full_View
(Comp_Typ
))
3899 T
:= Full_View
(Comp_Typ
);
3904 -- Verify a component of a null-excluding access type
3906 if Is_Access_Type
(T
)
3907 and then Can_Never_Be_Null
(T
)
3909 if Comp_Decl
= Obj_Decl
then
3910 Null_Exclusion_Static_Checks
3913 Array_Comp
=> Array_Comp
);
3916 Null_Exclusion_Static_Checks
3919 Array_Comp
=> Array_Comp
);
3922 -- Check array components
3924 elsif Is_Array_Type
(T
) then
3926 -- There is no suitable component when the object is of an
3927 -- array type. However, a namable component may appear at some
3928 -- point during the recursive inspection, but not at the top
3929 -- level. At the top level just indicate array component case.
3931 if Comp_Decl
= Obj_Decl
then
3932 Check_Component
(Component_Type
(T
), Array_Comp
=> True);
3934 Check_Component
(Component_Type
(T
), Comp_Decl
);
3937 -- Verify all components of type T
3939 -- Note: No checks are performed on types with discriminants due
3940 -- to complexities involving variants. ???
3942 elsif (Is_Concurrent_Type
(T
)
3943 or else Is_Incomplete_Or_Private_Type
(T
)
3944 or else Is_Record_Type
(T
))
3945 and then not Has_Discriminants
(T
)
3947 Comp
:= First_Component
(T
);
3948 while Present
(Comp
) loop
3949 Check_Component
(Etype
(Comp
), Parent
(Comp
));
3951 Next_Component
(Comp
);
3954 end Check_Component
;
3956 -- Start processing for Check_For_Null_Excluding_Components
3959 Check_Component
(Obj_Typ
, Obj_Decl
);
3960 end Check_For_Null_Excluding_Components
;
3962 -------------------------------------
3963 -- Check_Return_Subtype_Indication --
3964 -------------------------------------
3966 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
3967 Obj_Id
: constant Entity_Id
:= Defining_Identifier
(Obj_Decl
);
3968 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
3969 Func_Id
: constant Entity_Id
:= Return_Applies_To
(Scope
(Obj_Id
));
3970 R_Typ
: constant Entity_Id
:= Etype
(Func_Id
);
3971 Indic
: constant Node_Id
:=
3972 Object_Definition
(Original_Node
(Obj_Decl
));
3974 procedure Error_No_Match
(N
: Node_Id
);
3975 -- Output error messages for case where types do not statically
3976 -- match. N is the location for the messages.
3978 --------------------
3979 -- Error_No_Match --
3980 --------------------
3982 procedure Error_No_Match
(N
: Node_Id
) is
3985 ("subtype must statically match function result subtype", N
);
3987 if not Predicates_Match
(Obj_Typ
, R_Typ
) then
3988 Error_Msg_Node_2
:= R_Typ
;
3990 ("\predicate of& does not match predicate of&",
3995 -- Start of processing for Check_Return_Subtype_Indication
3998 -- First, avoid cascaded errors
4000 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Indic
) then
4004 -- "return access T" case; check that the return statement also has
4005 -- "access T", and that the subtypes statically match:
4006 -- if this is an access to subprogram the signatures must match.
4008 if Is_Anonymous_Access_Type
(R_Typ
) then
4009 if Is_Anonymous_Access_Type
(Obj_Typ
) then
4010 if Ekind
(Designated_Type
(Obj_Typ
)) /= E_Subprogram_Type
4012 if Base_Type
(Designated_Type
(Obj_Typ
)) /=
4013 Base_Type
(Designated_Type
(R_Typ
))
4014 or else not Subtypes_Statically_Match
(Obj_Typ
, R_Typ
)
4016 Error_No_Match
(Subtype_Mark
(Indic
));
4020 -- For two anonymous access to subprogram types, the types
4021 -- themselves must be type conformant.
4023 if not Conforming_Types
4024 (Obj_Typ
, R_Typ
, Fully_Conformant
)
4026 Error_No_Match
(Indic
);
4031 Error_Msg_N
("must use anonymous access type", Indic
);
4034 -- If the return object is of an anonymous access type, then report
4035 -- an error if the function's result type is not also anonymous.
4037 elsif Is_Anonymous_Access_Type
(Obj_Typ
) then
4038 pragma Assert
(not Is_Anonymous_Access_Type
(R_Typ
));
4040 ("anonymous access not allowed for function with named access "
4043 -- Subtype indication case: check that the return object's type is
4044 -- covered by the result type, and that the subtypes statically match
4045 -- when the result subtype is constrained. Also handle record types
4046 -- with unknown discriminants for which we have built the underlying
4047 -- record view. Coverage is needed to allow specific-type return
4048 -- objects when the result type is class-wide (see AI05-32).
4050 elsif Covers
(Base_Type
(R_Typ
), Base_Type
(Obj_Typ
))
4051 or else (Is_Underlying_Record_View
(Base_Type
(Obj_Typ
))
4055 Underlying_Record_View
(Base_Type
(Obj_Typ
))))
4057 -- A null exclusion may be present on the return type, on the
4058 -- function specification, on the object declaration or on the
4061 if Is_Access_Type
(R_Typ
)
4063 (Can_Never_Be_Null
(R_Typ
)
4064 or else Null_Exclusion_Present
(Parent
(Func_Id
))) /=
4065 Can_Never_Be_Null
(Obj_Typ
)
4067 Error_No_Match
(Indic
);
4070 -- AI05-103: for elementary types, subtypes must statically match
4072 if Is_Constrained
(R_Typ
) or else Is_Access_Type
(R_Typ
) then
4073 if not Subtypes_Statically_Match
(Obj_Typ
, R_Typ
) then
4074 Error_No_Match
(Indic
);
4078 -- All remaining cases are illegal
4080 -- Note: previous versions of this subprogram allowed the return
4081 -- value to be the ancestor of the return type if the return type
4082 -- was a null extension. This was plainly incorrect.
4086 ("wrong type for return_subtype_indication", Indic
);
4088 end Check_Return_Subtype_Indication
;
4094 function Count_Tasks
(T
: Entity_Id
) return Uint
is
4100 if Is_Task_Type
(T
) then
4103 elsif Is_Record_Type
(T
) then
4104 if Has_Discriminants
(T
) then
4105 Check_Restriction
(Max_Tasks
, N
);
4110 C
:= First_Component
(T
);
4111 while Present
(C
) loop
4112 V
:= V
+ Count_Tasks
(Etype
(C
));
4119 elsif Is_Array_Type
(T
) then
4120 X
:= First_Index
(T
);
4121 V
:= Count_Tasks
(Component_Type
(T
));
4122 while Present
(X
) loop
4125 if not Is_OK_Static_Subtype
(C
) then
4126 Check_Restriction
(Max_Tasks
, N
);
4129 V
:= V
* (UI_Max
(Uint_0
,
4130 Expr_Value
(Type_High_Bound
(C
)) -
4131 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
4144 ----------------------------
4145 -- Delayed_Aspect_Present --
4146 ----------------------------
4148 function Delayed_Aspect_Present
return Boolean is
4153 if Present
(Aspect_Specifications
(N
)) then
4154 A
:= First
(Aspect_Specifications
(N
));
4156 while Present
(A
) loop
4157 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(A
)));
4159 if A_Id
= Aspect_Address
then
4161 -- Set flag on object entity, for later processing at
4162 -- the freeze point.
4164 Set_Has_Delayed_Aspects
(Id
);
4173 end Delayed_Aspect_Present
;
4177 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4178 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
4179 -- Save the Ghost-related attributes to restore on exit
4181 Prev_Entity
: Entity_Id
:= Empty
;
4182 Related_Id
: Entity_Id
;
4184 -- Start of processing for Analyze_Object_Declaration
4187 -- There are three kinds of implicit types generated by an
4188 -- object declaration:
4190 -- 1. Those generated by the original Object Definition
4192 -- 2. Those generated by the Expression
4194 -- 3. Those used to constrain the Object Definition with the
4195 -- expression constraints when the definition is unconstrained.
4197 -- They must be generated in this order to avoid order of elaboration
4198 -- issues. Thus the first step (after entering the name) is to analyze
4199 -- the object definition.
4201 if Constant_Present
(N
) then
4202 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
4204 if Present
(Prev_Entity
)
4206 -- If the homograph is an implicit subprogram, it is overridden
4207 -- by the current declaration.
4209 ((Is_Overloadable
(Prev_Entity
)
4210 and then Is_Inherited_Operation
(Prev_Entity
))
4212 -- The current object is a discriminal generated for an entry
4213 -- family index. Even though the index is a constant, in this
4214 -- particular context there is no true constant redeclaration.
4215 -- Enter_Name will handle the visibility.
4218 (Is_Discriminal
(Id
)
4219 and then Ekind
(Discriminal_Link
(Id
)) =
4220 E_Entry_Index_Parameter
)
4222 -- The current object is the renaming for a generic declared
4223 -- within the instance.
4226 (Ekind
(Prev_Entity
) = E_Package
4227 and then Nkind
(Parent
(Prev_Entity
)) =
4228 N_Package_Renaming_Declaration
4229 and then not Comes_From_Source
(Prev_Entity
)
4231 Is_Generic_Instance
(Renamed_Entity
(Prev_Entity
)))
4233 -- The entity may be a homonym of a private component of the
4234 -- enclosing protected object, for which we create a local
4235 -- renaming declaration. The declaration is legal, even if
4236 -- useless when it just captures that component.
4239 (Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
4240 and then Nkind
(Parent
(Prev_Entity
)) =
4241 N_Object_Renaming_Declaration
))
4243 Prev_Entity
:= Empty
;
4247 if Present
(Prev_Entity
) then
4249 -- The object declaration is Ghost when it completes a deferred Ghost
4252 Mark_And_Set_Ghost_Completion
(N
, Prev_Entity
);
4254 Constant_Redeclaration
(Id
, N
, T
);
4256 Generate_Reference
(Prev_Entity
, Id
, 'c');
4257 Set_Completion_Referenced
(Id
);
4259 if Error_Posted
(N
) then
4261 -- Type mismatch or illegal redeclaration; do not analyze
4262 -- expression to avoid cascaded errors.
4264 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4266 Mutate_Ekind
(Id
, E_Variable
);
4270 -- In the normal case, enter identifier at the start to catch premature
4271 -- usage in the initialization expression.
4274 Generate_Definition
(Id
);
4277 Mark_Coextensions
(N
, Object_Definition
(N
));
4279 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4281 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
4283 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4284 and then Protected_Present
4285 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4287 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
4290 if Error_Posted
(Id
) then
4292 Mutate_Ekind
(Id
, E_Variable
);
4297 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
4298 -- out some static checks.
4300 if Ada_Version
>= Ada_2005
then
4302 -- In case of aggregates we must also take care of the correct
4303 -- initialization of nested aggregates bug this is done at the
4304 -- point of the analysis of the aggregate (see sem_aggr.adb) ???
4306 if Can_Never_Be_Null
(T
) then
4307 if Present
(Expression
(N
))
4308 and then Nkind
(Expression
(N
)) = N_Aggregate
4312 elsif Comes_From_Source
(Id
) then
4314 Save_Typ
: constant Entity_Id
:= Etype
(Id
);
4316 Set_Etype
(Id
, T
); -- Temp. decoration for static checks
4317 Null_Exclusion_Static_Checks
(N
);
4318 Set_Etype
(Id
, Save_Typ
);
4322 -- We might be dealing with an object of a composite type containing
4323 -- null-excluding components without an aggregate, so we must verify
4324 -- that such components have default initialization.
4327 Check_For_Null_Excluding_Components
(T
, N
);
4331 -- Object is marked pure if it is in a pure scope
4333 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
4335 -- If deferred constant, make sure context is appropriate. We detect
4336 -- a deferred constant as a constant declaration with no expression.
4337 -- A deferred constant can appear in a package body if its completion
4338 -- is by means of an interface pragma.
4340 if Constant_Present
(N
) and then No
(E
) then
4342 -- A deferred constant may appear in the declarative part of the
4343 -- following constructs:
4347 -- extended return statements
4350 -- subprogram bodies
4353 -- When declared inside a package spec, a deferred constant must be
4354 -- completed by a full constant declaration or pragma Import. In all
4355 -- other cases, the only proper completion is pragma Import. Extended
4356 -- return statements are flagged as invalid contexts because they do
4357 -- not have a declarative part and so cannot accommodate the pragma.
4359 if Ekind
(Current_Scope
) = E_Return_Statement
then
4361 ("invalid context for deferred constant declaration (RM 7.4)",
4364 ("\declaration requires an initialization expression",
4366 Set_Constant_Present
(N
, False);
4368 -- In Ada 83, deferred constant must be of private type
4370 elsif not Is_Private_Type
(T
) then
4371 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4373 ("(Ada 83) deferred constant must be private type", N
);
4377 -- If not a deferred constant, then the object declaration freezes
4378 -- its type, unless the object is of an anonymous type and has delayed
4379 -- aspects. In that case the type is frozen when the object itself is.
4382 Check_Fully_Declared
(T
, N
);
4384 if Has_Delayed_Aspects
(Id
)
4385 and then Is_Array_Type
(T
)
4386 and then Is_Itype
(T
)
4388 Set_Has_Delayed_Freeze
(T
);
4390 Freeze_Before
(N
, T
);
4394 -- If the object was created by a constrained array definition, then
4395 -- set the link in both the anonymous base type and anonymous subtype
4396 -- that are built to represent the array type to point to the object.
4398 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
4399 N_Constrained_Array_Definition
4401 Set_Related_Array_Object
(T
, Id
);
4402 Set_Related_Array_Object
(Base_Type
(T
), Id
);
4405 -- Check for protected objects not at library level
4407 if Has_Protected
(T
) and then not Is_Library_Level_Entity
(Id
) then
4408 Check_Restriction
(No_Local_Protected_Objects
, Id
);
4411 -- Check for violation of No_Local_Timing_Events
4413 if Has_Timing_Event
(T
) and then not Is_Library_Level_Entity
(Id
) then
4414 Check_Restriction
(No_Local_Timing_Events
, Id
);
4417 -- The actual subtype of the object is the nominal subtype, unless
4418 -- the nominal one is unconstrained and obtained from the expression.
4422 if Is_Library_Level_Entity
(Id
) then
4423 Check_Dynamic_Object
(T
);
4426 -- Process initialization expression if present and not in error
4428 if Present
(E
) and then E
/= Error
then
4430 -- Generate an error in case of CPP class-wide object initialization.
4431 -- Required because otherwise the expansion of the class-wide
4432 -- assignment would try to use 'size to initialize the object
4433 -- (primitive that is not available in CPP tagged types).
4435 if Is_Class_Wide_Type
(Act_T
)
4437 (Is_CPP_Class
(Root_Type
(Etype
(Act_T
)))
4439 (Present
(Full_View
(Root_Type
(Etype
(Act_T
))))
4441 Is_CPP_Class
(Full_View
(Root_Type
(Etype
(Act_T
))))))
4444 ("predefined assignment not available for 'C'P'P tagged types",
4448 Mark_Coextensions
(N
, E
);
4451 -- In case of errors detected in the analysis of the expression,
4452 -- decorate it with the expected type to avoid cascaded errors.
4454 if No
(Etype
(E
)) then
4458 -- If an initialization expression is present, then we set the
4459 -- Is_True_Constant flag. It will be reset if this is a variable
4460 -- and it is indeed modified.
4462 Set_Is_True_Constant
(Id
, True);
4464 -- If we are analyzing a constant declaration, set its completion
4465 -- flag after analyzing and resolving the expression.
4467 if Constant_Present
(N
) then
4468 Set_Has_Completion
(Id
);
4471 -- Set type and resolve (type may be overridden later on). Note:
4472 -- Ekind (Id) must still be E_Void at this point so that incorrect
4473 -- early usage within E is properly diagnosed.
4477 -- If the expression is an aggregate we must look ahead to detect
4478 -- the possible presence of an address clause, and defer resolution
4479 -- and expansion of the aggregate to the freeze point of the entity.
4481 -- This is not always legal because the aggregate may contain other
4482 -- references that need freezing, e.g. references to other entities
4483 -- with address clauses. In any case, when compiling with -gnatI the
4484 -- presence of the address clause must be ignored.
4486 if Comes_From_Source
(N
)
4487 and then Expander_Active
4488 and then Nkind
(E
) = N_Aggregate
4490 ((Present
(Following_Address_Clause
(N
))
4491 and then not Ignore_Rep_Clauses
)
4492 or else Delayed_Aspect_Present
)
4496 -- If the aggregate is limited it will be built in place, and its
4497 -- expansion is deferred until the object declaration is expanded.
4499 -- This is also required when generating C code to ensure that an
4500 -- object with an alignment or address clause can be initialized
4501 -- by means of component by component assignments.
4503 if Is_Limited_Type
(T
) or else Modify_Tree_For_C
then
4504 Set_Expansion_Delayed
(E
);
4508 -- If the expression is a formal that is a "subprogram pointer"
4509 -- this is illegal in accessibility terms (see RM 3.10.2 (13.1/2)
4510 -- and AARM 3.10.2 (13.b/2)). Add an explicit conversion to force
4511 -- the corresponding check, as is done for assignments.
4513 if Is_Entity_Name
(E
)
4514 and then Present
(Entity
(E
))
4515 and then Is_Formal
(Entity
(E
))
4517 Ekind
(Etype
(Entity
(E
))) = E_Anonymous_Access_Subprogram_Type
4518 and then Ekind
(T
) /= E_Anonymous_Access_Subprogram_Type
4520 Rewrite
(E
, Convert_To
(T
, Relocate_Node
(E
)));
4526 -- No further action needed if E is a call to an inlined function
4527 -- which returns an unconstrained type and it has been expanded into
4528 -- a procedure call. In that case N has been replaced by an object
4529 -- declaration without initializing expression and it has been
4530 -- analyzed (see Expand_Inlined_Call).
4532 if Back_End_Inlining
4533 and then Expander_Active
4534 and then Nkind
(E
) = N_Function_Call
4535 and then Nkind
(Name
(E
)) in N_Has_Entity
4536 and then Is_Inlined
(Entity
(Name
(E
)))
4537 and then not Is_Constrained
(Etype
(E
))
4538 and then Analyzed
(N
)
4539 and then No
(Expression
(N
))
4544 -- If E is null and has been replaced by an N_Raise_Constraint_Error
4545 -- node (which was marked already-analyzed), we need to set the type
4546 -- to something else than Universal_Access to keep gigi happy.
4548 if Etype
(E
) = Universal_Access
then
4552 -- If the object is an access to variable, the initialization
4553 -- expression cannot be an access to constant.
4555 if Is_Access_Type
(T
)
4556 and then not Is_Access_Constant
(T
)
4557 and then Is_Access_Type
(Etype
(E
))
4558 and then Is_Access_Constant
(Etype
(E
))
4561 ("access to variable cannot be initialized with an "
4562 & "access-to-constant expression", E
);
4565 if not Assignment_OK
(N
) then
4566 Check_Initialization
(T
, E
);
4569 Check_Unset_Reference
(E
);
4571 -- If this is a variable, then set current value. If this is a
4572 -- declared constant of a scalar type with a static expression,
4573 -- indicate that it is always valid.
4575 if not Constant_Present
(N
) then
4576 if Compile_Time_Known_Value
(E
) then
4577 Set_Current_Value
(Id
, E
);
4580 elsif Is_Scalar_Type
(T
) and then Is_OK_Static_Expression
(E
) then
4581 Set_Is_Known_Valid
(Id
);
4583 -- If it is a constant initialized with a valid nonstatic entity,
4584 -- the constant is known valid as well, and can inherit the subtype
4585 -- of the entity if it is a subtype of the given type. This info
4586 -- is preserved on the actual subtype of the constant.
4588 elsif Is_Scalar_Type
(T
)
4589 and then Is_Entity_Name
(E
)
4590 and then Is_Known_Valid
(Entity
(E
))
4591 and then In_Subrange_Of
(Etype
(Entity
(E
)), T
)
4593 Set_Is_Known_Valid
(Id
);
4594 Mutate_Ekind
(Id
, E_Constant
);
4595 Set_Actual_Subtype
(Id
, Etype
(Entity
(E
)));
4598 -- Deal with setting of null flags
4600 if Is_Access_Type
(T
) then
4601 if Known_Non_Null
(E
) then
4602 Set_Is_Known_Non_Null
(Id
, True);
4603 elsif Known_Null
(E
) and then not Can_Never_Be_Null
(Id
) then
4604 Set_Is_Known_Null
(Id
, True);
4608 -- Check incorrect use of dynamically tagged expressions
4610 if Is_Tagged_Type
(T
) then
4611 Check_Dynamically_Tagged_Expression
4617 Apply_Scalar_Range_Check
(E
, T
);
4618 Apply_Static_Length_Check
(E
, T
);
4620 -- A formal parameter of a specific tagged type whose related
4621 -- subprogram is subject to pragma Extensions_Visible with value
4622 -- "False" cannot be implicitly converted to a class-wide type by
4623 -- means of an initialization expression (SPARK RM 6.1.7(3)). Do
4624 -- not consider internally generated expressions.
4626 if Is_Class_Wide_Type
(T
)
4627 and then Comes_From_Source
(E
)
4628 and then Is_EVF_Expression
(E
)
4631 ("formal parameter cannot be implicitly converted to "
4632 & "class-wide type when Extensions_Visible is False", E
);
4636 -- If the No_Streams restriction is set, check that the type of the
4637 -- object is not, and does not contain, any subtype derived from
4638 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
4639 -- Has_Stream just for efficiency reasons. There is no point in
4640 -- spending time on a Has_Stream check if the restriction is not set.
4642 if Restriction_Check_Required
(No_Streams
) then
4643 if Has_Stream
(T
) then
4644 Check_Restriction
(No_Streams
, N
);
4648 -- Deal with predicate check before we start to do major rewriting. It
4649 -- is OK to initialize and then check the initialized value, since the
4650 -- object goes out of scope if we get a predicate failure. Note that we
4651 -- do this in the analyzer and not the expander because the analyzer
4652 -- does some substantial rewriting in some cases.
4654 -- We need a predicate check if the type has predicates that are not
4655 -- ignored, and if either there is an initializing expression, or for
4656 -- default initialization when we have at least one case of an explicit
4657 -- default initial value (including via a Default_Value or
4658 -- Default_Component_Value aspect, see AI12-0301) and then this is not
4659 -- an internal declaration whose initialization comes later (as for an
4660 -- aggregate expansion) or a deferred constant.
4661 -- If expression is an aggregate it may be expanded into assignments
4662 -- and the declaration itself is marked with No_Initialization, but
4663 -- the predicate still applies.
4665 if not Suppress_Assignment_Checks
(N
)
4666 and then (Predicate_Enabled
(T
) or else Has_Static_Predicate
(T
))
4668 (not No_Initialization
(N
)
4669 or else (Present
(E
) and then Nkind
(E
) = N_Aggregate
))
4673 Is_Partially_Initialized_Type
(T
, Include_Implicit
=> False))
4674 and then not (Constant_Present
(N
) and then No
(E
))
4676 -- If the type has a static predicate and the expression is known at
4677 -- compile time, see if the expression satisfies the predicate.
4678 -- In the case of a static expression, this must be done even if
4679 -- the predicate is not enabled (as per static expression rules).
4682 Check_Expression_Against_Static_Predicate
(E
, T
);
4685 -- Do not perform further predicate-related checks unless
4686 -- predicates are enabled for the subtype.
4688 if not Predicate_Enabled
(T
) then
4691 -- If the type is a null record and there is no explicit initial
4692 -- expression, no predicate check applies.
4694 elsif No
(E
) and then Is_Null_Record_Type
(T
) then
4697 -- Do not generate a predicate check if the initialization expression
4698 -- is a type conversion whose target subtype statically matches the
4699 -- object's subtype because the conversion has been subjected to the
4700 -- same check. This is a small optimization which avoids redundant
4704 and then Nkind
(E
) in N_Type_Conversion
4705 and then Subtypes_Statically_Match
(Etype
(Subtype_Mark
(E
)), T
)
4710 -- The check must be inserted after the expanded aggregate
4711 -- expansion code, if any.
4714 Check
: constant Node_Id
:=
4715 Make_Predicate_Check
(T
, New_Occurrence_Of
(Id
, Loc
));
4718 if No
(Next_Decl
) then
4719 Append_To
(List_Containing
(N
), Check
);
4721 Insert_Before
(Next_Decl
, Check
);
4727 -- Case of unconstrained type
4729 if not Is_Definite_Subtype
(T
) then
4731 -- Nothing to do in deferred constant case
4733 if Constant_Present
(N
) and then No
(E
) then
4736 -- Case of no initialization present
4739 if No_Initialization
(N
) then
4742 elsif Is_Class_Wide_Type
(T
) then
4744 ("initialization required in class-wide declaration", N
);
4748 ("unconstrained subtype not allowed (need initialization)",
4749 Object_Definition
(N
));
4751 if Is_Record_Type
(T
) and then Has_Discriminants
(T
) then
4753 ("\provide initial value or explicit discriminant values",
4754 Object_Definition
(N
));
4757 ("\or give default discriminant values for type&",
4758 Object_Definition
(N
), T
);
4760 elsif Is_Array_Type
(T
) then
4762 ("\provide initial value or explicit array bounds",
4763 Object_Definition
(N
));
4767 -- Case of initialization present but in error. Set initial
4768 -- expression as absent (but do not make above complaints).
4770 elsif E
= Error
then
4771 Set_Expression
(N
, Empty
);
4774 -- Case of initialization present
4777 -- Unconstrained variables not allowed in Ada 83
4779 if Ada_Version
= Ada_83
4780 and then not Constant_Present
(N
)
4781 and then Comes_From_Source
(Object_Definition
(N
))
4784 ("(Ada 83) unconstrained variable not allowed",
4785 Object_Definition
(N
));
4788 -- Now we constrain the variable from the initializing expression
4790 -- If the expression is an aggregate, it has been expanded into
4791 -- individual assignments. Retrieve the actual type from the
4792 -- expanded construct.
4794 if Is_Array_Type
(T
)
4795 and then No_Initialization
(N
)
4796 and then Nkind
(Original_Node
(E
)) = N_Aggregate
4800 -- In case of class-wide interface object declarations we delay
4801 -- the generation of the equivalent record type declarations until
4802 -- its expansion because there are cases in they are not required.
4804 elsif Is_Interface
(T
) then
4807 -- If the type is an unchecked union, no subtype can be built from
4808 -- the expression. Rewrite declaration as a renaming, which the
4809 -- back-end can handle properly. This is a rather unusual case,
4810 -- because most unchecked_union declarations have default values
4811 -- for discriminants and are thus not indefinite.
4813 elsif Is_Unchecked_Union
(T
) then
4814 if Constant_Present
(N
) or else Nkind
(E
) = N_Function_Call
then
4815 Mutate_Ekind
(Id
, E_Constant
);
4817 Mutate_Ekind
(Id
, E_Variable
);
4820 -- If the expression is an aggregate it contains the required
4821 -- discriminant values but it has not been resolved yet, so do
4822 -- it now, and treat it as the initial expression of an object
4823 -- declaration, rather than a renaming.
4825 if Nkind
(E
) = N_Aggregate
then
4826 Analyze_And_Resolve
(E
, T
);
4830 Make_Object_Renaming_Declaration
(Loc
,
4831 Defining_Identifier
=> Id
,
4832 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
4835 Set_Renamed_Object
(Id
, E
);
4836 Freeze_Before
(N
, T
);
4842 -- Ensure that the generated subtype has a unique external name
4843 -- when the related object is public. This guarantees that the
4844 -- subtype and its bounds will not be affected by switches or
4845 -- pragmas that may offset the internal counter due to extra
4848 if Is_Public
(Id
) then
4851 Related_Id
:= Empty
;
4854 -- If the object has an unconstrained array subtype with fixed
4855 -- lower bound, then sliding to that bound may be needed.
4857 if Is_Fixed_Lower_Bound_Array_Subtype
(T
) then
4858 Expand_Sliding_Conversion
(E
, T
);
4861 if In_Spec_Expression
and then In_Declare_Expr
> 0 then
4862 -- It is too early to be doing expansion-ish things,
4863 -- so exit early. But we have to set Ekind (Id) now so
4864 -- that subsequent uses of this entity are not rejected
4865 -- via the same mechanism that (correctly) rejects
4866 -- "X : Integer := X;".
4868 if Constant_Present
(N
) then
4869 Mutate_Ekind
(Id
, E_Constant
);
4870 Set_Is_True_Constant
(Id
);
4872 Mutate_Ekind
(Id
, E_Variable
);
4874 Set_Has_Initial_Value
(Id
);
4881 Expand_Subtype_From_Expr
4884 Subtype_Indic
=> Object_Definition
(N
),
4886 Related_Id
=> Related_Id
);
4888 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4893 Full_View_Present
: constant Boolean :=
4894 Is_Private_Type
(Act_T
)
4895 and then Present
(Full_View
(Act_T
));
4896 -- Propagate attributes to full view when needed
4899 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
4901 if Full_View_Present
then
4902 Set_Is_Constr_Subt_For_U_Nominal
(Full_View
(Act_T
));
4905 if Aliased_Present
(N
) then
4906 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
4908 if Full_View_Present
then
4909 Set_Is_Constr_Subt_For_UN_Aliased
(Full_View
(Act_T
));
4913 Freeze_Before
(N
, Act_T
);
4917 Freeze_Before
(N
, T
);
4920 elsif Is_Array_Type
(T
)
4921 and then No_Initialization
(N
)
4922 and then (Nkind
(Original_Node
(E
)) = N_Aggregate
4923 or else (Nkind
(Original_Node
(E
)) = N_Qualified_Expression
4924 and then Nkind
(Original_Node
(Expression
4925 (Original_Node
(E
)))) = N_Aggregate
))
4927 if not Is_Entity_Name
(Object_Definition
(N
)) then
4929 Check_Compile_Time_Size
(Act_T
);
4932 -- When the given object definition and the aggregate are specified
4933 -- independently, and their lengths might differ do a length check.
4934 -- This cannot happen if the aggregate is of the form (others =>...)
4936 if Nkind
(E
) = N_Raise_Constraint_Error
then
4938 -- Aggregate is statically illegal. Place back in declaration
4940 Set_Expression
(N
, E
);
4941 Set_No_Initialization
(N
, False);
4943 elsif T
= Etype
(E
) then
4946 elsif Nkind
(E
) = N_Aggregate
4947 and then Present
(Component_Associations
(E
))
4948 and then Present
(Choice_List
(First
(Component_Associations
(E
))))
4950 Nkind
(First
(Choice_List
(First
(Component_Associations
(E
))))) =
4956 Apply_Length_Check
(E
, T
);
4959 -- When possible, build the default subtype
4961 elsif Build_Default_Subtype_OK
(T
) then
4963 Act_T
:= Build_Default_Subtype
(T
, N
);
4965 -- Ada 2005: A limited object may be initialized by means of an
4966 -- aggregate. If the type has default discriminants it has an
4967 -- unconstrained nominal type, Its actual subtype will be obtained
4968 -- from the aggregate, and not from the default discriminants.
4973 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
4974 Freeze_Before
(N
, Act_T
);
4976 elsif Nkind
(E
) = N_Function_Call
4977 and then Constant_Present
(N
)
4978 and then Has_Unconstrained_Elements
(Etype
(E
))
4980 -- The back-end has problems with constants of a discriminated type
4981 -- with defaults, if the initial value is a function call. We
4982 -- generate an intermediate temporary that will receive a reference
4983 -- to the result of the call. The initialization expression then
4984 -- becomes a dereference of that temporary.
4986 Remove_Side_Effects
(E
);
4988 -- If this is a constant declaration of an unconstrained type and
4989 -- the initialization is an aggregate, we can use the subtype of the
4990 -- aggregate for the declared entity because it is immutable.
4992 elsif not Is_Constrained
(T
)
4993 and then Has_Discriminants
(T
)
4994 and then Constant_Present
(N
)
4995 and then not Has_Unchecked_Union
(T
)
4996 and then Nkind
(E
) = N_Aggregate
5001 -- Check No_Wide_Characters restriction
5003 Check_Wide_Character_Restriction
(T
, Object_Definition
(N
));
5005 -- Indicate this is not set in source. Certainly true for constants, and
5006 -- true for variables so far (will be reset for a variable if and when
5007 -- we encounter a modification in the source).
5009 Set_Never_Set_In_Source
(Id
);
5011 -- Now establish the proper kind and type of the object
5013 if Ekind
(Id
) = E_Void
then
5014 Reinit_Field_To_Zero
(Id
, F_Next_Inlined_Subprogram
);
5017 if Constant_Present
(N
) then
5018 Mutate_Ekind
(Id
, E_Constant
);
5019 Set_Is_True_Constant
(Id
);
5022 Mutate_Ekind
(Id
, E_Variable
);
5024 -- A variable is set as shared passive if it appears in a shared
5025 -- passive package, and is at the outer level. This is not done for
5026 -- entities generated during expansion, because those are always
5027 -- manipulated locally.
5029 if Is_Shared_Passive
(Current_Scope
)
5030 and then Is_Library_Level_Entity
(Id
)
5031 and then Comes_From_Source
(Id
)
5033 Set_Is_Shared_Passive
(Id
);
5034 Check_Shared_Var
(Id
, T
, N
);
5037 -- Set Has_Initial_Value if initializing expression present. Note
5038 -- that if there is no initializing expression, we leave the state
5039 -- of this flag unchanged (usually it will be False, but notably in
5040 -- the case of exception choice variables, it will already be true).
5043 Set_Has_Initial_Value
(Id
);
5047 -- Set the SPARK mode from the current context (may be overwritten later
5048 -- with explicit pragma).
5050 Set_SPARK_Pragma
(Id
, SPARK_Mode_Pragma
);
5051 Set_SPARK_Pragma_Inherited
(Id
);
5053 -- Preserve relevant elaboration-related attributes of the context which
5054 -- are no longer available or very expensive to recompute once analysis,
5055 -- resolution, and expansion are over.
5057 Mark_Elaboration_Attributes
5062 -- Initialize alignment and size and capture alignment setting
5064 Reinit_Alignment
(Id
);
5066 Set_Optimize_Alignment_Flags
(Id
);
5068 -- Deal with aliased case
5070 if Aliased_Present
(N
) then
5071 Set_Is_Aliased
(Id
);
5073 -- AI12-001: All aliased objects are considered to be specified as
5074 -- independently addressable (RM C.6(8.1/4)).
5076 Set_Is_Independent
(Id
);
5078 -- If the object is aliased and the type is unconstrained with
5079 -- defaulted discriminants and there is no expression, then the
5080 -- object is constrained by the defaults, so it is worthwhile
5081 -- building the corresponding subtype.
5083 -- Ada 2005 (AI-363): If the aliased object is discriminated and
5084 -- unconstrained, then only establish an actual subtype if the
5085 -- nominal subtype is indefinite. In definite cases the object is
5086 -- unconstrained in Ada 2005.
5089 and then Is_Record_Type
(T
)
5090 and then not Is_Constrained
(T
)
5091 and then Has_Discriminants
(T
)
5092 and then (Ada_Version
< Ada_2005
5093 or else not Is_Definite_Subtype
(T
))
5095 Set_Actual_Subtype
(Id
, Build_Default_Subtype
(T
, N
));
5099 -- Now we can set the type of the object
5101 Set_Etype
(Id
, Act_T
);
5103 -- Non-constant object is marked to be treated as volatile if type is
5104 -- volatile and we clear the Current_Value setting that may have been
5105 -- set above. Doing so for constants isn't required and might interfere
5106 -- with possible uses of the object as a static expression in contexts
5107 -- incompatible with volatility (e.g. as a case-statement alternative).
5109 if Ekind
(Id
) /= E_Constant
and then Treat_As_Volatile
(Etype
(Id
)) then
5110 Set_Treat_As_Volatile
(Id
);
5111 Set_Current_Value
(Id
, Empty
);
5114 -- Deal with controlled types
5116 if Has_Controlled_Component
(Etype
(Id
))
5117 or else Is_Controlled
(Etype
(Id
))
5119 if not Is_Library_Level_Entity
(Id
) then
5120 Check_Restriction
(No_Nested_Finalization
, N
);
5122 Validate_Controlled_Object
(Id
);
5126 if Has_Task
(Etype
(Id
)) then
5127 Check_Restriction
(No_Tasking
, N
);
5129 -- Deal with counting max tasks
5131 -- Nothing to do if inside a generic
5133 if Inside_A_Generic
then
5136 -- If library level entity, then count tasks
5138 elsif Is_Library_Level_Entity
(Id
) then
5139 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
5141 -- If not library level entity, then indicate we don't know max
5142 -- tasks and also check task hierarchy restriction and blocking
5143 -- operation (since starting a task is definitely blocking).
5146 Check_Restriction
(Max_Tasks
, N
);
5147 Check_Restriction
(No_Task_Hierarchy
, N
);
5148 Check_Potentially_Blocking_Operation
(N
);
5151 -- A rather specialized test. If we see two tasks being declared
5152 -- of the same type in the same object declaration, and the task
5153 -- has an entry with an address clause, we know that program error
5154 -- will be raised at run time since we can't have two tasks with
5155 -- entries at the same address.
5157 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
5162 E
:= First_Entity
(Etype
(Id
));
5163 while Present
(E
) loop
5164 if Ekind
(E
) = E_Entry
5165 and then Present
(Get_Attribute_Definition_Clause
5166 (E
, Attribute_Address
))
5168 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5170 ("more than one task with same entry address<<", N
);
5171 Error_Msg_N
("\Program_Error [<<", N
);
5173 Make_Raise_Program_Error
(Loc
,
5174 Reason
=> PE_Duplicated_Entry_Address
));
5184 -- Check specific legality rules for a return object
5186 if Is_Return_Object
(Id
) then
5187 Check_Return_Subtype_Indication
(N
);
5190 -- Some simple constant-propagation: if the expression is a constant
5191 -- string initialized with a literal, share the literal. This avoids
5195 and then Is_Entity_Name
(E
)
5196 and then Ekind
(Entity
(E
)) = E_Constant
5197 and then Base_Type
(Etype
(E
)) = Standard_String
5200 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
5202 if Present
(Val
) and then Nkind
(Val
) = N_String_Literal
then
5203 Rewrite
(E
, New_Copy
(Val
));
5208 if Present
(Prev_Entity
)
5209 and then Is_Frozen
(Prev_Entity
)
5210 and then not Error_Posted
(Id
)
5212 Error_Msg_N
("full constant declaration appears too late", N
);
5215 Check_Eliminated
(Id
);
5217 -- Deal with setting In_Private_Part flag if in private part
5219 if Ekind
(Scope
(Id
)) = E_Package
5220 and then In_Private_Part
(Scope
(Id
))
5222 Set_In_Private_Part
(Id
);
5226 -- Initialize the refined state of a variable here because this is a
5227 -- common destination for legal and illegal object declarations.
5229 if Ekind
(Id
) = E_Variable
then
5230 Set_Encapsulating_State
(Id
, Empty
);
5233 if Has_Aspects
(N
) then
5234 Analyze_Aspect_Specifications
(N
, Id
);
5237 Analyze_Dimension
(N
);
5239 -- Verify whether the object declaration introduces an illegal hidden
5240 -- state within a package subject to a null abstract state.
5242 if Ekind
(Id
) = E_Variable
then
5243 Check_No_Hidden_State
(Id
);
5246 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
5247 end Analyze_Object_Declaration
;
5249 ---------------------------
5250 -- Analyze_Others_Choice --
5251 ---------------------------
5253 -- Nothing to do for the others choice node itself, the semantic analysis
5254 -- of the others choice will occur as part of the processing of the parent
5256 procedure Analyze_Others_Choice
(N
: Node_Id
) is
5257 pragma Warnings
(Off
, N
);
5260 end Analyze_Others_Choice
;
5262 -------------------------------------------
5263 -- Analyze_Private_Extension_Declaration --
5264 -------------------------------------------
5266 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
5267 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
5268 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5270 Iface_Elmt
: Elmt_Id
;
5271 Parent_Base
: Entity_Id
;
5272 Parent_Type
: Entity_Id
;
5275 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
5277 if Is_Non_Empty_List
(Interface_List
(N
)) then
5283 Intf
:= First
(Interface_List
(N
));
5284 while Present
(Intf
) loop
5285 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
5287 Diagnose_Interface
(Intf
, T
);
5293 Generate_Definition
(T
);
5295 -- For other than Ada 2012, just enter the name in the current scope
5297 if Ada_Version
< Ada_2012
then
5300 -- Ada 2012 (AI05-0162): Enter the name in the current scope handling
5301 -- case of private type that completes an incomplete type.
5308 Prev
:= Find_Type_Name
(N
);
5310 pragma Assert
(Prev
= T
5311 or else (Ekind
(Prev
) = E_Incomplete_Type
5312 and then Present
(Full_View
(Prev
))
5313 and then Full_View
(Prev
) = T
));
5317 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
5318 Parent_Base
:= Base_Type
(Parent_Type
);
5320 if Parent_Type
= Any_Type
or else Etype
(Parent_Type
) = Any_Type
then
5321 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
5322 Set_Etype
(T
, Any_Type
);
5325 elsif not Is_Tagged_Type
(Parent_Type
) then
5327 ("parent of type extension must be a tagged type", Indic
);
5330 elsif Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
5331 Error_Msg_N
("premature derivation of incomplete type", Indic
);
5334 elsif Is_Concurrent_Type
(Parent_Type
) then
5336 ("parent type of a private extension cannot be a synchronized "
5337 & "tagged type (RM 3.9.1 (3/1))", N
);
5339 Set_Etype
(T
, Any_Type
);
5340 Mutate_Ekind
(T
, E_Limited_Private_Type
);
5341 Set_Private_Dependents
(T
, New_Elmt_List
);
5342 Set_Error_Posted
(T
);
5346 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
5348 -- Perhaps the parent type should be changed to the class-wide type's
5349 -- specific type in this case to prevent cascading errors ???
5351 if Is_Class_Wide_Type
(Parent_Type
) then
5353 ("parent of type extension must not be a class-wide type", Indic
);
5357 if (not Is_Package_Or_Generic_Package
(Current_Scope
)
5358 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
5359 or else In_Private_Part
(Current_Scope
)
5361 Error_Msg_N
("invalid context for private extension", N
);
5364 -- Set common attributes
5366 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
5367 Set_Scope
(T
, Current_Scope
);
5368 Mutate_Ekind
(T
, E_Record_Type_With_Private
);
5369 Reinit_Size_Align
(T
);
5370 Set_Default_SSO
(T
);
5371 Set_No_Reordering
(T
, No_Component_Reordering
);
5373 Set_Etype
(T
, Parent_Base
);
5374 Propagate_Concurrent_Flags
(T
, Parent_Base
);
5376 Set_Convention
(T
, Convention
(Parent_Type
));
5377 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
5378 Set_Is_First_Subtype
(T
);
5379 Make_Class_Wide_Type
(T
);
5381 -- Set the SPARK mode from the current context
5383 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
5384 Set_SPARK_Pragma_Inherited
(T
);
5386 if Unknown_Discriminants_Present
(N
) then
5387 Set_Discriminant_Constraint
(T
, No_Elist
);
5390 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
5392 -- A private extension inherits the Default_Initial_Condition pragma
5393 -- coming from any parent type within the derivation chain.
5395 if Has_DIC
(Parent_Type
) then
5396 Set_Has_Inherited_DIC
(T
);
5399 -- A private extension inherits any class-wide invariants coming from a
5400 -- parent type or an interface. Note that the invariant procedure of the
5401 -- parent type should not be inherited because the private extension may
5402 -- define invariants of its own.
5404 if Has_Inherited_Invariants
(Parent_Type
)
5405 or else Has_Inheritable_Invariants
(Parent_Type
)
5407 Set_Has_Inherited_Invariants
(T
);
5409 elsif Present
(Interfaces
(T
)) then
5410 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5411 while Present
(Iface_Elmt
) loop
5412 Iface
:= Node
(Iface_Elmt
);
5414 if Has_Inheritable_Invariants
(Iface
) then
5415 Set_Has_Inherited_Invariants
(T
);
5419 Next_Elmt
(Iface_Elmt
);
5423 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
5424 -- synchronized formal derived type.
5426 if Ada_Version
>= Ada_2005
and then Synchronized_Present
(N
) then
5427 Set_Is_Limited_Record
(T
);
5429 -- Formal derived type case
5431 if Is_Generic_Type
(T
) then
5433 -- The parent must be a tagged limited type or a synchronized
5436 if (not Is_Tagged_Type
(Parent_Type
)
5437 or else not Is_Limited_Type
(Parent_Type
))
5439 (not Is_Interface
(Parent_Type
)
5440 or else not Is_Synchronized_Interface
(Parent_Type
))
5443 ("parent type of & must be tagged limited or synchronized",
5447 -- The progenitors (if any) must be limited or synchronized
5450 if Present
(Interfaces
(T
)) then
5451 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5452 while Present
(Iface_Elmt
) loop
5453 Iface
:= Node
(Iface_Elmt
);
5455 if not Is_Limited_Interface
(Iface
)
5456 and then not Is_Synchronized_Interface
(Iface
)
5459 ("progenitor & must be limited or synchronized",
5463 Next_Elmt
(Iface_Elmt
);
5467 -- Regular derived extension, the parent must be a limited or
5468 -- synchronized interface.
5471 if not Is_Interface
(Parent_Type
)
5472 or else (not Is_Limited_Interface
(Parent_Type
)
5473 and then not Is_Synchronized_Interface
(Parent_Type
))
5476 ("parent type of & must be limited interface", N
, T
);
5480 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
5481 -- extension with a synchronized parent must be explicitly declared
5482 -- synchronized, because the full view will be a synchronized type.
5483 -- This must be checked before the check for limited types below,
5484 -- to ensure that types declared limited are not allowed to extend
5485 -- synchronized interfaces.
5487 elsif Is_Interface
(Parent_Type
)
5488 and then Is_Synchronized_Interface
(Parent_Type
)
5489 and then not Synchronized_Present
(N
)
5492 ("private extension of& must be explicitly synchronized",
5495 elsif Limited_Present
(N
) then
5496 Set_Is_Limited_Record
(T
);
5498 if not Is_Limited_Type
(Parent_Type
)
5500 (not Is_Interface
(Parent_Type
)
5501 or else not Is_Limited_Interface
(Parent_Type
))
5503 Error_Msg_NE
("parent type& of limited extension must be limited",
5508 -- Remember that its parent type has a private extension. Used to warn
5509 -- on public primitives of the parent type defined after its private
5510 -- extensions (see Check_Dispatching_Operation).
5512 Set_Has_Private_Extension
(Parent_Type
);
5515 if Has_Aspects
(N
) then
5516 Analyze_Aspect_Specifications
(N
, T
);
5518 end Analyze_Private_Extension_Declaration
;
5520 ---------------------------------
5521 -- Analyze_Subtype_Declaration --
5522 ---------------------------------
5524 procedure Analyze_Subtype_Declaration
5526 Skip
: Boolean := False)
5528 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5532 Generate_Definition
(Id
);
5533 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
5534 Reinit_Size_Align
(Id
);
5536 -- The following guard condition on Enter_Name is to handle cases where
5537 -- the defining identifier has already been entered into the scope but
5538 -- the declaration as a whole needs to be analyzed.
5540 -- This case in particular happens for derived enumeration types. The
5541 -- derived enumeration type is processed as an inserted enumeration type
5542 -- declaration followed by a rewritten subtype declaration. The defining
5543 -- identifier, however, is entered into the name scope very early in the
5544 -- processing of the original type declaration and therefore needs to be
5545 -- avoided here, when the created subtype declaration is analyzed. (See
5546 -- Build_Derived_Types)
5548 -- This also happens when the full view of a private type is derived
5549 -- type with constraints. In this case the entity has been introduced
5550 -- in the private declaration.
5552 -- Finally this happens in some complex cases when validity checks are
5553 -- enabled, where the same subtype declaration may be analyzed twice.
5554 -- This can happen if the subtype is created by the preanalysis of
5555 -- an attribute that gives the range of a loop statement, and the loop
5556 -- itself appears within an if_statement that will be rewritten during
5560 or else (Present
(Etype
(Id
))
5561 and then (Is_Private_Type
(Etype
(Id
))
5562 or else Is_Task_Type
(Etype
(Id
))
5563 or else Is_Rewrite_Substitution
(N
)))
5567 elsif Current_Entity
(Id
) = Id
then
5574 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
5576 -- Class-wide equivalent types of records with unknown discriminants
5577 -- involve the generation of an itype which serves as the private view
5578 -- of a constrained record subtype. In such cases the base type of the
5579 -- current subtype we are processing is the private itype. Use the full
5580 -- of the private itype when decorating various attributes.
5583 and then Is_Private_Type
(T
)
5584 and then Present
(Full_View
(T
))
5589 -- Inherit common attributes
5591 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
5592 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
5593 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
5594 Set_Convention
(Id
, Convention
(T
));
5596 -- If ancestor has predicates then so does the subtype, and in addition
5597 -- we must delay the freeze to properly arrange predicate inheritance.
5599 -- The Ancestor_Type test is really unpleasant, there seem to be cases
5600 -- in which T = ID, so the above tests and assignments do nothing???
5602 if Has_Predicates
(T
)
5603 or else (Present
(Ancestor_Subtype
(T
))
5604 and then Has_Predicates
(Ancestor_Subtype
(T
)))
5606 Set_Has_Predicates
(Id
);
5607 Set_Has_Delayed_Freeze
(Id
);
5609 -- Generated subtypes inherit the predicate function from the parent
5610 -- (no aspects to examine on the generated declaration).
5612 if not Comes_From_Source
(N
) then
5613 Mutate_Ekind
(Id
, Ekind
(T
));
5615 if Present
(Predicate_Function
(Id
)) then
5618 elsif Present
(Predicate_Function
(T
)) then
5619 Set_Predicate_Function
(Id
, Predicate_Function
(T
));
5621 elsif Present
(Ancestor_Subtype
(T
))
5622 and then Present
(Predicate_Function
(Ancestor_Subtype
(T
)))
5624 Set_Predicate_Function
(Id
,
5625 Predicate_Function
(Ancestor_Subtype
(T
)));
5630 -- In the case where there is no constraint given in the subtype
5631 -- indication, Process_Subtype just returns the Subtype_Mark, so its
5632 -- semantic attributes must be established here.
5634 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
5635 Set_Etype
(Id
, Base_Type
(T
));
5639 Mutate_Ekind
(Id
, E_Array_Subtype
);
5640 Copy_Array_Subtype_Attributes
(Id
, T
);
5641 Set_Packed_Array_Impl_Type
(Id
, Packed_Array_Impl_Type
(T
));
5643 when Decimal_Fixed_Point_Kind
=>
5644 Mutate_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
5645 Set_Digits_Value
(Id
, Digits_Value
(T
));
5646 Set_Delta_Value
(Id
, Delta_Value
(T
));
5647 Set_Scale_Value
(Id
, Scale_Value
(T
));
5648 Set_Small_Value
(Id
, Small_Value
(T
));
5649 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5650 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
5651 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5652 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5653 Copy_RM_Size
(To
=> Id
, From
=> T
);
5655 when Enumeration_Kind
=>
5656 Mutate_Ekind
(Id
, E_Enumeration_Subtype
);
5657 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
5658 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5659 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
5660 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5661 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5662 Copy_RM_Size
(To
=> Id
, From
=> T
);
5664 when Ordinary_Fixed_Point_Kind
=>
5665 Mutate_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
5666 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5667 Set_Small_Value
(Id
, Small_Value
(T
));
5668 Set_Delta_Value
(Id
, Delta_Value
(T
));
5669 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5670 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5671 Copy_RM_Size
(To
=> Id
, From
=> T
);
5674 Mutate_Ekind
(Id
, E_Floating_Point_Subtype
);
5675 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5676 Set_Digits_Value
(Id
, Digits_Value
(T
));
5677 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5679 -- If the floating point type has dimensions, these will be
5680 -- inherited subsequently when Analyze_Dimensions is called.
5682 when Signed_Integer_Kind
=>
5683 Mutate_Ekind
(Id
, E_Signed_Integer_Subtype
);
5684 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5685 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5686 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5687 Copy_RM_Size
(To
=> Id
, From
=> T
);
5689 when Modular_Integer_Kind
=>
5690 Mutate_Ekind
(Id
, E_Modular_Integer_Subtype
);
5691 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5692 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5693 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5694 Copy_RM_Size
(To
=> Id
, From
=> T
);
5696 when Class_Wide_Kind
=>
5697 Mutate_Ekind
(Id
, E_Class_Wide_Subtype
);
5698 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5699 Set_Cloned_Subtype
(Id
, T
);
5700 Set_Is_Tagged_Type
(Id
, True);
5701 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5702 Set_Has_Unknown_Discriminants
5704 Set_No_Tagged_Streams_Pragma
5705 (Id
, No_Tagged_Streams_Pragma
(T
));
5707 if Ekind
(T
) = E_Class_Wide_Subtype
then
5708 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
5711 when E_Record_Subtype
5714 Mutate_Ekind
(Id
, E_Record_Subtype
);
5716 -- Subtype declarations introduced for formal type parameters
5717 -- in generic instantiations should inherit the Size value of
5718 -- the type they rename.
5720 if Present
(Generic_Parent_Type
(N
)) then
5721 Copy_RM_Size
(To
=> Id
, From
=> T
);
5724 if Ekind
(T
) = E_Record_Subtype
5725 and then Present
(Cloned_Subtype
(T
))
5727 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
5729 Set_Cloned_Subtype
(Id
, T
);
5732 Set_First_Entity
(Id
, First_Entity
(T
));
5733 Set_Last_Entity
(Id
, Last_Entity
(T
));
5734 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5735 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5736 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5737 Set_Has_Implicit_Dereference
5738 (Id
, Has_Implicit_Dereference
(T
));
5739 Set_Has_Unknown_Discriminants
5740 (Id
, Has_Unknown_Discriminants
(T
));
5742 if Has_Discriminants
(T
) then
5743 Set_Discriminant_Constraint
5744 (Id
, Discriminant_Constraint
(T
));
5745 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5747 elsif Has_Unknown_Discriminants
(Id
) then
5748 Set_Discriminant_Constraint
(Id
, No_Elist
);
5751 if Is_Tagged_Type
(T
) then
5752 Set_Is_Tagged_Type
(Id
, True);
5753 Set_No_Tagged_Streams_Pragma
5754 (Id
, No_Tagged_Streams_Pragma
(T
));
5755 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5756 Set_Direct_Primitive_Operations
5757 (Id
, Direct_Primitive_Operations
(T
));
5758 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5760 if Is_Interface
(T
) then
5761 Set_Is_Interface
(Id
);
5762 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
5766 when Private_Kind
=>
5767 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5768 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5769 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5770 Set_First_Entity
(Id
, First_Entity
(T
));
5771 Set_Last_Entity
(Id
, Last_Entity
(T
));
5772 Set_Private_Dependents
(Id
, New_Elmt_List
);
5773 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5774 Set_Has_Implicit_Dereference
5775 (Id
, Has_Implicit_Dereference
(T
));
5776 Set_Has_Unknown_Discriminants
5777 (Id
, Has_Unknown_Discriminants
(T
));
5778 Set_Known_To_Have_Preelab_Init
5779 (Id
, Known_To_Have_Preelab_Init
(T
));
5781 if Is_Tagged_Type
(T
) then
5782 Set_Is_Tagged_Type
(Id
);
5783 Set_No_Tagged_Streams_Pragma
(Id
,
5784 No_Tagged_Streams_Pragma
(T
));
5785 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5786 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5787 Set_Direct_Primitive_Operations
(Id
,
5788 Direct_Primitive_Operations
(T
));
5791 -- In general the attributes of the subtype of a private type
5792 -- are the attributes of the partial view of parent. However,
5793 -- the full view may be a discriminated type, and the subtype
5794 -- must share the discriminant constraint to generate correct
5795 -- calls to initialization procedures.
5797 if Has_Discriminants
(T
) then
5798 Set_Discriminant_Constraint
5799 (Id
, Discriminant_Constraint
(T
));
5800 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5802 elsif Present
(Full_View
(T
))
5803 and then Has_Discriminants
(Full_View
(T
))
5805 Set_Discriminant_Constraint
5806 (Id
, Discriminant_Constraint
(Full_View
(T
)));
5807 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5809 -- This would seem semantically correct, but apparently
5810 -- generates spurious errors about missing components ???
5812 -- Set_Has_Discriminants (Id);
5815 Prepare_Private_Subtype_Completion
(Id
, N
);
5817 -- If this is the subtype of a constrained private type with
5818 -- discriminants that has got a full view and we also have
5819 -- built a completion just above, show that the completion
5820 -- is a clone of the full view to the back-end.
5822 if Has_Discriminants
(T
)
5823 and then not Has_Unknown_Discriminants
(T
)
5824 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(T
))
5825 and then Present
(Full_View
(T
))
5826 and then Present
(Full_View
(Id
))
5828 Set_Cloned_Subtype
(Full_View
(Id
), Full_View
(T
));
5832 Mutate_Ekind
(Id
, E_Access_Subtype
);
5833 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5834 Set_Is_Access_Constant
5835 (Id
, Is_Access_Constant
(T
));
5836 Set_Directly_Designated_Type
5837 (Id
, Designated_Type
(T
));
5838 Set_Can_Never_Be_Null
(Id
, Can_Never_Be_Null
(T
));
5840 -- A Pure library_item must not contain the declaration of a
5841 -- named access type, except within a subprogram, generic
5842 -- subprogram, task unit, or protected unit, or if it has
5843 -- a specified Storage_Size of zero (RM05-10.2.1(15.4-15.5)).
5845 if Comes_From_Source
(Id
)
5846 and then In_Pure_Unit
5847 and then not In_Subprogram_Task_Protected_Unit
5848 and then not No_Pool_Assigned
(Id
)
5851 ("named access types not allowed in pure unit", N
);
5854 when Concurrent_Kind
=>
5855 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5856 Set_Corresponding_Record_Type
(Id
,
5857 Corresponding_Record_Type
(T
));
5858 Set_First_Entity
(Id
, First_Entity
(T
));
5859 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
5860 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5861 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5862 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5863 Set_Last_Entity
(Id
, Last_Entity
(T
));
5865 if Is_Tagged_Type
(T
) then
5866 Set_No_Tagged_Streams_Pragma
5867 (Id
, No_Tagged_Streams_Pragma
(T
));
5870 if Has_Discriminants
(T
) then
5871 Set_Discriminant_Constraint
5872 (Id
, Discriminant_Constraint
(T
));
5873 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5876 when Incomplete_Kind
=>
5877 if Ada_Version
>= Ada_2005
then
5879 -- In Ada 2005 an incomplete type can be explicitly tagged:
5880 -- propagate indication. Note that we also have to include
5881 -- subtypes for Ada 2012 extended use of incomplete types.
5883 Mutate_Ekind
(Id
, E_Incomplete_Subtype
);
5884 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5885 Set_Private_Dependents
(Id
, New_Elmt_List
);
5887 if Is_Tagged_Type
(Id
) then
5888 Set_No_Tagged_Streams_Pragma
5889 (Id
, No_Tagged_Streams_Pragma
(T
));
5892 -- For tagged types, or when prefixed-call syntax is allowed
5893 -- for untagged types, initialize the list of primitive
5894 -- operations to an empty list.
5896 if Is_Tagged_Type
(Id
)
5897 or else Core_Extensions_Allowed
5899 Set_Direct_Primitive_Operations
(Id
, New_Elmt_List
);
5902 -- Ada 2005 (AI-412): Decorate an incomplete subtype of an
5903 -- incomplete type visible through a limited with clause.
5905 if From_Limited_With
(T
)
5906 and then Present
(Non_Limited_View
(T
))
5908 Set_From_Limited_With
(Id
);
5909 Set_Non_Limited_View
(Id
, Non_Limited_View
(T
));
5911 -- Ada 2005 (AI-412): Add the regular incomplete subtype
5912 -- to the private dependents of the original incomplete
5913 -- type for future transformation.
5916 Append_Elmt
(Id
, Private_Dependents
(T
));
5919 -- If the subtype name denotes an incomplete type an error
5920 -- was already reported by Process_Subtype.
5923 Set_Etype
(Id
, Any_Type
);
5927 raise Program_Error
;
5930 -- If there is no constraint in the subtype indication, the
5931 -- declared entity inherits predicates from the parent.
5933 Inherit_Predicate_Flags
(Id
, T
);
5936 if Etype
(Id
) = Any_Type
then
5940 -- When prefixed calls are enabled for untagged types, the subtype
5941 -- shares the primitive operations of its base type. Do this even
5942 -- when Extensions_Allowed is False to issue better error messages.
5944 Set_Direct_Primitive_Operations
5945 (Id
, Direct_Primitive_Operations
(Base_Type
(T
)));
5947 -- Some common processing on all types
5949 Set_Size_Info
(Id
, T
);
5950 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
5952 -- If the parent type is a generic actual, so is the subtype. This may
5953 -- happen in a nested instance. Why Comes_From_Source test???
5955 if not Comes_From_Source
(N
) then
5956 Set_Is_Generic_Actual_Type
(Id
, Is_Generic_Actual_Type
(T
));
5959 -- If this is a subtype declaration for an actual in an instance,
5960 -- inherit static and dynamic predicates if any.
5962 -- If declaration has no aspect specifications, inherit predicate
5963 -- info as well. Unclear how to handle the case of both specified
5964 -- and inherited predicates ??? Other inherited aspects, such as
5965 -- invariants, should be OK, but the combination with later pragmas
5966 -- may also require special merging.
5968 if Has_Predicates
(T
)
5969 and then Present
(Predicate_Function
(T
))
5971 ((In_Instance
and then not Comes_From_Source
(N
))
5972 or else No
(Aspect_Specifications
(N
)))
5974 -- Inherit Subprograms_For_Type from the full view, if present
5976 if Present
(Full_View
(T
))
5977 and then Present
(Subprograms_For_Type
(Full_View
(T
)))
5979 Set_Subprograms_For_Type
5980 (Id
, Subprograms_For_Type
(Full_View
(T
)));
5982 Set_Subprograms_For_Type
(Id
, Subprograms_For_Type
(T
));
5985 -- If the current declaration created both a private and a full view,
5986 -- then propagate Predicate_Function to the latter as well.
5988 if Present
(Full_View
(Id
))
5989 and then No
(Predicate_Function
(Full_View
(Id
)))
5991 Set_Subprograms_For_Type
5992 (Full_View
(Id
), Subprograms_For_Type
(Id
));
5995 if Has_Static_Predicate
(T
) then
5996 Set_Has_Static_Predicate
(Id
);
5997 Set_Static_Discrete_Predicate
(Id
, Static_Discrete_Predicate
(T
));
6001 -- If the base type is a scalar type, or else if there is no
6002 -- constraint, the atomic flag is inherited by the subtype.
6003 -- Ditto for the Independent aspect.
6005 if Is_Scalar_Type
(Id
)
6006 or else Is_Entity_Name
(Subtype_Indication
(N
))
6008 Set_Is_Atomic
(Id
, Is_Atomic
(T
));
6009 Set_Is_Independent
(Id
, Is_Independent
(T
));
6012 -- Remaining processing depends on characteristics of base type
6016 Set_Is_Immediately_Visible
(Id
, True);
6017 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
6018 Set_Is_Descendant_Of_Address
(Id
, Is_Descendant_Of_Address
(T
));
6020 if Is_Interface
(T
) then
6021 Set_Is_Interface
(Id
);
6022 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
6025 if Present
(Generic_Parent_Type
(N
))
6027 (Nkind
(Parent
(Generic_Parent_Type
(N
))) /=
6028 N_Formal_Type_Declaration
6029 or else Nkind
(Formal_Type_Definition
6030 (Parent
(Generic_Parent_Type
(N
)))) /=
6031 N_Formal_Private_Type_Definition
)
6033 if Is_Tagged_Type
(Id
) then
6035 -- If this is a generic actual subtype for a synchronized type,
6036 -- the primitive operations are those of the corresponding record
6037 -- for which there is a separate subtype declaration.
6039 if Is_Concurrent_Type
(Id
) then
6041 elsif Is_Class_Wide_Type
(Id
) then
6042 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
6044 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
6047 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
6048 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
6052 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
6053 Conditional_Delay
(Id
, Full_View
(T
));
6055 -- The subtypes of components or subcomponents of protected types
6056 -- do not need freeze nodes, which would otherwise appear in the
6057 -- wrong scope (before the freeze node for the protected type). The
6058 -- proper subtypes are those of the subcomponents of the corresponding
6061 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
6062 and then Present
(Scope
(Scope
(Id
))) -- error defense
6063 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
6065 Conditional_Delay
(Id
, T
);
6068 -- If we have a subtype of an incomplete type whose full type is a
6069 -- derived numeric type, we need to have a freeze node for the subtype.
6070 -- Otherwise gigi will complain while computing the (static) bounds of
6074 and then Is_Elementary_Type
(Id
)
6075 and then Etype
(Id
) /= Id
6078 Partial
: constant Entity_Id
:=
6079 Incomplete_Or_Partial_View
(First_Subtype
(Id
));
6081 if Present
(Partial
)
6082 and then Ekind
(Partial
) = E_Incomplete_Type
6084 Set_Has_Delayed_Freeze
(Id
);
6089 -- Check that Constraint_Error is raised for a scalar subtype indication
6090 -- when the lower or upper bound of a non-null range lies outside the
6091 -- range of the type mark. Likewise for an array subtype, but check the
6092 -- compatibility for each index.
6094 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6096 Indic_Typ
: constant Entity_Id
:=
6097 Underlying_Type
(Etype
(Subtype_Mark
(Subtype_Indication
(N
))));
6098 Subt_Index
: Node_Id
;
6099 Target_Index
: Node_Id
;
6102 if Is_Scalar_Type
(Etype
(Id
))
6103 and then Scalar_Range
(Id
) /= Scalar_Range
(Indic_Typ
)
6105 Apply_Range_Check
(Scalar_Range
(Id
), Indic_Typ
);
6107 elsif Is_Array_Type
(Etype
(Id
))
6108 and then Present
(First_Index
(Id
))
6110 Subt_Index
:= First_Index
(Id
);
6111 Target_Index
:= First_Index
(Indic_Typ
);
6113 while Present
(Subt_Index
) loop
6114 if ((Nkind
(Subt_Index
) in N_Expanded_Name | N_Identifier
6115 and then Is_Scalar_Type
(Entity
(Subt_Index
)))
6116 or else Nkind
(Subt_Index
) = N_Subtype_Indication
)
6118 Nkind
(Scalar_Range
(Etype
(Subt_Index
))) = N_Range
6121 (Scalar_Range
(Etype
(Subt_Index
)),
6122 Etype
(Target_Index
),
6126 Next_Index
(Subt_Index
);
6127 Next_Index
(Target_Index
);
6133 Set_Optimize_Alignment_Flags
(Id
);
6134 Check_Eliminated
(Id
);
6137 if Has_Aspects
(N
) then
6138 Analyze_Aspect_Specifications
(N
, Id
);
6141 Analyze_Dimension
(N
);
6143 -- Check No_Dynamic_Sized_Objects restriction, which disallows subtype
6144 -- indications on composite types where the constraints are dynamic.
6145 -- Note that object declarations and aggregates generate implicit
6146 -- subtype declarations, which this covers. One special case is that the
6147 -- implicitly generated "=" for discriminated types includes an
6148 -- offending subtype declaration, which is harmless, so we ignore it
6151 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6153 Cstr
: constant Node_Id
:= Constraint
(Subtype_Indication
(N
));
6155 if Nkind
(Cstr
) = N_Index_Or_Discriminant_Constraint
6156 and then not (Is_Internal
(Id
)
6157 and then Is_TSS
(Scope
(Id
),
6158 TSS_Composite_Equality
))
6159 and then not Within_Init_Proc
6160 and then not All_Composite_Constraints_Static
(Cstr
)
6162 Check_Restriction
(No_Dynamic_Sized_Objects
, Cstr
);
6166 end Analyze_Subtype_Declaration
;
6168 --------------------------------
6169 -- Analyze_Subtype_Indication --
6170 --------------------------------
6172 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
6173 T
: constant Entity_Id
:= Subtype_Mark
(N
);
6174 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6180 Set_Error_Posted
(R
);
6181 Set_Error_Posted
(T
);
6184 Set_Etype
(N
, Etype
(R
));
6185 Resolve
(R
, Entity
(T
));
6187 end Analyze_Subtype_Indication
;
6189 --------------------------
6190 -- Analyze_Variant_Part --
6191 --------------------------
6193 procedure Analyze_Variant_Part
(N
: Node_Id
) is
6194 Discr_Name
: Node_Id
;
6195 Discr_Type
: Entity_Id
;
6197 procedure Process_Variant
(A
: Node_Id
);
6198 -- Analyze declarations for a single variant
6200 package Analyze_Variant_Choices
is
6201 new Generic_Analyze_Choices
(Process_Variant
);
6202 use Analyze_Variant_Choices
;
6204 ---------------------
6205 -- Process_Variant --
6206 ---------------------
6208 procedure Process_Variant
(A
: Node_Id
) is
6209 CL
: constant Node_Id
:= Component_List
(A
);
6211 if not Null_Present
(CL
) then
6212 Analyze_Declarations
(Component_Items
(CL
));
6214 if Present
(Variant_Part
(CL
)) then
6215 Analyze
(Variant_Part
(CL
));
6218 end Process_Variant
;
6220 -- Start of processing for Analyze_Variant_Part
6223 Discr_Name
:= Name
(N
);
6224 Analyze
(Discr_Name
);
6226 -- If Discr_Name bad, get out (prevent cascaded errors)
6228 if Etype
(Discr_Name
) = Any_Type
then
6232 -- Check invalid discriminant in variant part
6234 if Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
6235 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
6238 Discr_Type
:= Etype
(Entity
(Discr_Name
));
6240 if not Is_Discrete_Type
(Discr_Type
) then
6242 ("discriminant in a variant part must be of a discrete type",
6247 -- Now analyze the choices, which also analyzes the declarations that
6248 -- are associated with each choice.
6250 Analyze_Choices
(Variants
(N
), Discr_Type
);
6252 -- Note: we used to instantiate and call Check_Choices here to check
6253 -- that the choices covered the discriminant, but it's too early to do
6254 -- that because of statically predicated subtypes, whose analysis may
6255 -- be deferred to their freeze point which may be as late as the freeze
6256 -- point of the containing record. So this call is now to be found in
6257 -- Freeze_Record_Declaration.
6259 end Analyze_Variant_Part
;
6261 ----------------------------
6262 -- Array_Type_Declaration --
6263 ----------------------------
6265 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
6266 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
6267 Component_Typ
: constant Node_Id
:= Subtype_Indication
(Component_Def
);
6268 P
: constant Node_Id
:= Parent
(Def
);
6269 Element_Type
: Entity_Id
;
6270 Implicit_Base
: Entity_Id
;
6274 Related_Id
: Entity_Id
;
6275 Has_FLB_Index
: Boolean := False;
6278 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6279 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
6281 Index
:= First
(Subtype_Marks
(Def
));
6284 -- Find proper names for the implicit types which may be public. In case
6285 -- of anonymous arrays we use the name of the first object of that type
6289 Related_Id
:= Defining_Identifier
(P
);
6295 while Present
(Index
) loop
6298 -- Test for odd case of trying to index a type by the type itself
6300 if Is_Entity_Name
(Index
) and then Entity
(Index
) = T
then
6301 Error_Msg_N
("type& cannot be indexed by itself", Index
);
6302 Set_Entity
(Index
, Standard_Boolean
);
6303 Set_Etype
(Index
, Standard_Boolean
);
6306 -- Add a subtype declaration for each index of private array type
6307 -- declaration whose type is also private. For example:
6310 -- type Index is private;
6312 -- type Table is array (Index) of ...
6315 -- This is currently required by the expander for the internally
6316 -- generated equality subprogram of records with variant parts in
6317 -- which the type of some component is such a private type. And it
6318 -- also helps semantic analysis in peculiar cases where the array
6319 -- type is referenced from an instance but not the index directly.
6321 if Is_Package_Or_Generic_Package
(Current_Scope
)
6322 and then In_Private_Part
(Current_Scope
)
6323 and then Has_Private_Declaration
(Etype
(Index
))
6324 and then Scope
(Etype
(Index
)) = Current_Scope
6327 Loc
: constant Source_Ptr
:= Sloc
(Def
);
6332 New_E
:= Make_Temporary
(Loc
, 'T');
6333 Set_Is_Internal
(New_E
);
6336 Make_Subtype_Declaration
(Loc
,
6337 Defining_Identifier
=> New_E
,
6338 Subtype_Indication
=>
6339 New_Occurrence_Of
(Etype
(Index
), Loc
));
6341 Insert_Before
(Parent
(Def
), Decl
);
6343 Set_Etype
(Index
, New_E
);
6345 -- If the index is a range or a subtype indication it carries
6346 -- no entity. Example:
6349 -- type T is private;
6351 -- type T is new Natural;
6352 -- Table : array (T(1) .. T(10)) of Boolean;
6355 -- Otherwise the type of the reference is its entity.
6357 if Is_Entity_Name
(Index
) then
6358 Set_Entity
(Index
, New_E
);
6363 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
6365 -- In the case where we have an unconstrained array with an index
6366 -- given by a subtype_indication, this is necessarily a "fixed lower
6367 -- bound" index. We change the upper bound of that index to the upper
6368 -- bound of the index's subtype (denoted by the subtype_mark), since
6369 -- that upper bound was originally set by the parser to be the same
6370 -- as the lower bound. In truth, that upper bound corresponds to
6371 -- a box ("<>"), and could be set to Empty, but it's convenient to
6372 -- set it to the upper bound to avoid needing to add special tests
6373 -- in various places for an Empty upper bound, and in any case that
6374 -- accurately characterizes the index's range of values.
6376 if Nkind
(Def
) = N_Unconstrained_Array_Definition
6377 and then Nkind
(Index
) = N_Subtype_Indication
6380 Index_Subtype_High_Bound
: constant Entity_Id
:=
6381 Type_High_Bound
(Entity
(Subtype_Mark
(Index
)));
6383 Set_High_Bound
(Range_Expression
(Constraint
(Index
)),
6384 Index_Subtype_High_Bound
);
6386 -- Record that the array type has one or more indexes with
6387 -- a fixed lower bound.
6389 Has_FLB_Index
:= True;
6391 -- Mark the index as belonging to an array type with a fixed
6394 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(Index
));
6398 -- Check error of subtype with predicate for index type
6400 Bad_Predicated_Subtype_Use
6401 ("subtype& has predicate, not allowed as index subtype",
6402 Index
, Etype
(Index
));
6404 -- Move to next index
6407 Nb_Index
:= Nb_Index
+ 1;
6410 -- Process subtype indication if one is present
6412 if Present
(Component_Typ
) then
6413 Element_Type
:= Process_Subtype
(Component_Typ
, P
, Related_Id
, 'C');
6414 Set_Etype
(Component_Typ
, Element_Type
);
6416 -- Ada 2005 (AI-230): Access Definition case
6418 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
6420 -- Indicate that the anonymous access type is created by the
6421 -- array type declaration.
6423 Element_Type
:= Access_Definition
6425 N
=> Access_Definition
(Component_Def
));
6426 Set_Is_Local_Anonymous_Access
(Element_Type
);
6428 -- Propagate the parent. This field is needed if we have to generate
6429 -- the master_id associated with an anonymous access to task type
6430 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
6432 Copy_Parent
(To
=> Element_Type
, From
=> T
);
6434 -- Ada 2005 (AI-230): In case of components that are anonymous access
6435 -- types the level of accessibility depends on the enclosing type
6438 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
6440 -- Ada 2005 (AI-254)
6443 CD
: constant Node_Id
:=
6444 Access_To_Subprogram_Definition
6445 (Access_Definition
(Component_Def
));
6447 if Present
(CD
) and then Protected_Present
(CD
) then
6449 Replace_Anonymous_Access_To_Protected_Subprogram
(Def
);
6454 -- Constrained array case
6457 -- We might be creating more than one itype with the same Related_Id,
6458 -- e.g. for an array object definition and its initial value. Give
6459 -- them unique suffixes, because GNATprove require distinct types to
6460 -- have different names.
6462 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T', Suffix_Index
=> -1);
6465 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6466 -- Establish Implicit_Base as unconstrained base type
6468 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
6470 Set_Etype
(Implicit_Base
, Implicit_Base
);
6471 Set_Scope
(Implicit_Base
, Current_Scope
);
6472 Set_Has_Delayed_Freeze
(Implicit_Base
);
6473 Set_Default_SSO
(Implicit_Base
);
6475 -- The constrained array type is a subtype of the unconstrained one
6477 Mutate_Ekind
(T
, E_Array_Subtype
);
6478 Reinit_Size_Align
(T
);
6479 Set_Etype
(T
, Implicit_Base
);
6480 Set_Scope
(T
, Current_Scope
);
6481 Set_Is_Constrained
(T
);
6483 First
(Discrete_Subtype_Definitions
(Def
)));
6484 Set_Has_Delayed_Freeze
(T
);
6486 -- Complete setup of implicit base type
6488 pragma Assert
(not Known_Component_Size
(Implicit_Base
));
6489 Set_Component_Type
(Implicit_Base
, Element_Type
);
6490 Set_Finalize_Storage_Only
6492 Finalize_Storage_Only
(Element_Type
));
6493 Set_First_Index
(Implicit_Base
, First_Index
(T
));
6494 Set_Has_Controlled_Component
6496 Has_Controlled_Component
(Element_Type
)
6497 or else Is_Controlled
(Element_Type
));
6498 Set_Packed_Array_Impl_Type
6499 (Implicit_Base
, Empty
);
6501 Propagate_Concurrent_Flags
(Implicit_Base
, Element_Type
);
6503 -- Unconstrained array case
6505 else pragma Assert
(Nkind
(Def
) = N_Unconstrained_Array_Definition
);
6506 Mutate_Ekind
(T
, E_Array_Type
);
6507 Reinit_Size_Align
(T
);
6509 Set_Scope
(T
, Current_Scope
);
6510 pragma Assert
(not Known_Component_Size
(T
));
6511 Set_Is_Constrained
(T
, False);
6512 Set_Is_Fixed_Lower_Bound_Array_Subtype
6514 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
6515 Set_Has_Delayed_Freeze
(T
, True);
6516 Propagate_Concurrent_Flags
(T
, Element_Type
);
6517 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
6520 Is_Controlled
(Element_Type
));
6521 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
6523 Set_Default_SSO
(T
);
6526 -- Common attributes for both cases
6528 Set_Component_Type
(Base_Type
(T
), Element_Type
);
6529 Set_Packed_Array_Impl_Type
(T
, Empty
);
6531 if Aliased_Present
(Component_Definition
(Def
)) then
6532 Set_Has_Aliased_Components
(Etype
(T
));
6534 -- AI12-001: All aliased objects are considered to be specified as
6535 -- independently addressable (RM C.6(8.1/4)).
6537 Set_Has_Independent_Components
(Etype
(T
));
6540 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
6541 -- array type to ensure that objects of this type are initialized.
6543 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(Element_Type
) then
6544 Set_Can_Never_Be_Null
(T
);
6546 if Null_Exclusion_Present
(Component_Definition
(Def
))
6548 -- No need to check itypes because in their case this check was
6549 -- done at their point of creation
6551 and then not Is_Itype
(Element_Type
)
6554 ("`NOT NULL` not allowed (null already excluded)",
6555 Subtype_Indication
(Component_Definition
(Def
)));
6559 Priv
:= Private_Component
(Element_Type
);
6561 if Present
(Priv
) then
6563 -- Check for circular definitions
6565 if Priv
= Any_Type
then
6566 Set_Component_Type
(Etype
(T
), Any_Type
);
6568 -- There is a gap in the visibility of operations on the composite
6569 -- type only if the component type is defined in a different scope.
6571 elsif Scope
(Priv
) = Current_Scope
then
6574 elsif Is_Limited_Type
(Priv
) then
6575 Set_Is_Limited_Composite
(Etype
(T
));
6576 Set_Is_Limited_Composite
(T
);
6578 Set_Is_Private_Composite
(Etype
(T
));
6579 Set_Is_Private_Composite
(T
);
6583 -- A syntax error in the declaration itself may lead to an empty index
6584 -- list, in which case do a minimal patch.
6586 if No
(First_Index
(T
)) then
6587 Error_Msg_N
("missing index definition in array type declaration", T
);
6590 Indexes
: constant List_Id
:=
6591 New_List
(New_Occurrence_Of
(Any_Id
, Sloc
(T
)));
6593 Set_Discrete_Subtype_Definitions
(Def
, Indexes
);
6594 Set_First_Index
(T
, First
(Indexes
));
6599 -- Create a concatenation operator for the new type. Internal array
6600 -- types created for packed entities do not need such, they are
6601 -- compatible with the user-defined type.
6603 if Number_Dimensions
(T
) = 1
6604 and then not Is_Packed_Array_Impl_Type
(T
)
6606 New_Concatenation_Op
(T
);
6609 -- In the case of an unconstrained array the parser has already verified
6610 -- that all the indexes are unconstrained but we still need to make sure
6611 -- that the element type is constrained.
6613 if not Is_Definite_Subtype
(Element_Type
) then
6615 ("unconstrained element type in array declaration",
6616 Subtype_Indication
(Component_Def
));
6618 elsif Is_Abstract_Type
(Element_Type
) then
6620 ("the type of a component cannot be abstract",
6621 Subtype_Indication
(Component_Def
));
6624 -- There may be an invariant declared for the component type, but
6625 -- the construction of the component invariant checking procedure
6626 -- takes place during expansion.
6627 end Array_Type_Declaration
;
6629 ------------------------------------------------------
6630 -- Replace_Anonymous_Access_To_Protected_Subprogram --
6631 ------------------------------------------------------
6633 function Replace_Anonymous_Access_To_Protected_Subprogram
6634 (N
: Node_Id
) return Entity_Id
6636 Loc
: constant Source_Ptr
:= Sloc
(N
);
6638 Curr_Scope
: constant Scope_Stack_Entry
:=
6639 Scope_Stack
.Table
(Scope_Stack
.Last
);
6641 Anon
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
6644 -- Access definition in declaration
6647 -- Object definition or formal definition with an access definition
6650 -- Declaration of anonymous access to subprogram type
6653 -- Original specification in access to subprogram
6658 Set_Is_Internal
(Anon
);
6661 when N_Constrained_Array_Definition
6662 | N_Component_Declaration
6663 | N_Unconstrained_Array_Definition
6665 Comp
:= Component_Definition
(N
);
6666 Acc
:= Access_Definition
(Comp
);
6668 when N_Discriminant_Specification
=>
6669 Comp
:= Discriminant_Type
(N
);
6672 when N_Parameter_Specification
=>
6673 Comp
:= Parameter_Type
(N
);
6676 when N_Access_Function_Definition
=>
6677 Comp
:= Result_Definition
(N
);
6680 when N_Object_Declaration
=>
6681 Comp
:= Object_Definition
(N
);
6684 when N_Function_Specification
=>
6685 Comp
:= Result_Definition
(N
);
6689 raise Program_Error
;
6692 Spec
:= Access_To_Subprogram_Definition
(Acc
);
6695 Make_Full_Type_Declaration
(Loc
,
6696 Defining_Identifier
=> Anon
,
6697 Type_Definition
=> Copy_Separate_Tree
(Spec
));
6699 Mark_Rewrite_Insertion
(Decl
);
6701 -- Insert the new declaration in the nearest enclosing scope. If the
6702 -- parent is a body and N is its return type, the declaration belongs
6703 -- in the enclosing scope. Likewise if N is the type of a parameter.
6707 if Nkind
(N
) = N_Function_Specification
6708 and then Nkind
(P
) = N_Subprogram_Body
6711 elsif Nkind
(N
) = N_Parameter_Specification
6712 and then Nkind
(P
) in N_Subprogram_Specification
6713 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
6715 P
:= Parent
(Parent
(P
));
6718 while Present
(P
) and then not Has_Declarations
(P
) loop
6722 pragma Assert
(Present
(P
));
6724 if Nkind
(P
) = N_Package_Specification
then
6725 Prepend
(Decl
, Visible_Declarations
(P
));
6727 Prepend
(Decl
, Declarations
(P
));
6730 -- Replace the anonymous type with an occurrence of the new declaration.
6731 -- In all cases the rewritten node does not have the null-exclusion
6732 -- attribute because (if present) it was already inherited by the
6733 -- anonymous entity (Anon). Thus, in case of components we do not
6734 -- inherit this attribute.
6736 if Nkind
(N
) = N_Parameter_Specification
then
6737 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6738 Set_Etype
(Defining_Identifier
(N
), Anon
);
6739 Set_Null_Exclusion_Present
(N
, False);
6741 elsif Nkind
(N
) = N_Object_Declaration
then
6742 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6743 Set_Etype
(Defining_Identifier
(N
), Anon
);
6745 elsif Nkind
(N
) = N_Access_Function_Definition
then
6746 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6748 elsif Nkind
(N
) = N_Function_Specification
then
6749 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6750 Set_Etype
(Defining_Unit_Name
(N
), Anon
);
6754 Make_Component_Definition
(Loc
,
6755 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
6758 Mark_Rewrite_Insertion
(Comp
);
6760 if Nkind
(N
) in N_Object_Declaration | N_Access_Function_Definition
6761 or else (Nkind
(Parent
(N
)) = N_Full_Type_Declaration
6762 and then not Is_Type
(Current_Scope
))
6765 -- Declaration can be analyzed in the current scope.
6770 -- Temporarily remove the current scope (record or subprogram) from
6771 -- the stack to add the new declarations to the enclosing scope.
6772 -- The anonymous entity is an Itype with the proper attributes.
6774 Scope_Stack
.Decrement_Last
;
6776 Set_Is_Itype
(Anon
);
6777 Set_Associated_Node_For_Itype
(Anon
, N
);
6778 Scope_Stack
.Append
(Curr_Scope
);
6781 Mutate_Ekind
(Anon
, E_Anonymous_Access_Protected_Subprogram_Type
);
6782 Set_Can_Use_Internal_Rep
(Anon
, not Always_Compatible_Rep_On_Target
);
6784 end Replace_Anonymous_Access_To_Protected_Subprogram
;
6786 -------------------------------------
6787 -- Build_Access_Subprogram_Wrapper --
6788 -------------------------------------
6790 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
) is
6791 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
6792 Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
6793 Type_Def
: constant Node_Id
:= Type_Definition
(Decl
);
6794 Specs
: constant List_Id
:=
6795 Parameter_Specifications
(Type_Def
);
6796 Profile
: constant List_Id
:= New_List
;
6797 Subp
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6799 Contracts
: constant List_Id
:= New_List
;
6805 procedure Replace_Type_Name
(Expr
: Node_Id
);
6806 -- In the expressions for contract aspects, replace occurrences of the
6807 -- access type with the name of the subprogram entity, as needed, e.g.
6808 -- for 'Result. Aspects that are not contracts, e.g. Size or Alignment)
6809 -- remain on the original access type declaration. What about expanded
6810 -- names denoting formals, whose prefix in source is the type name ???
6812 -----------------------
6813 -- Replace_Type_Name --
6814 -----------------------
6816 procedure Replace_Type_Name
(Expr
: Node_Id
) is
6817 function Process
(N
: Node_Id
) return Traverse_Result
;
6818 function Process
(N
: Node_Id
) return Traverse_Result
is
6820 if Nkind
(N
) = N_Attribute_Reference
6821 and then Is_Entity_Name
(Prefix
(N
))
6822 and then Chars
(Prefix
(N
)) = Chars
(Id
)
6824 Set_Prefix
(N
, Make_Identifier
(Sloc
(N
), Chars
(Subp
)));
6830 procedure Traverse
is new Traverse_Proc
(Process
);
6833 end Replace_Type_Name
;
6836 if Ekind
(Id
) in E_Access_Subprogram_Type
6837 | E_Access_Protected_Subprogram_Type
6838 | E_Anonymous_Access_Protected_Subprogram_Type
6839 | E_Anonymous_Access_Subprogram_Type
6845 ("illegal pre/postcondition on access type", Decl
);
6856 Asp
:= First
(Aspect_Specifications
(Decl
));
6857 while Present
(Asp
) loop
6858 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(Asp
)));
6859 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Post
then
6861 Expr
:= Expression
(Cond
);
6862 Replace_Type_Name
(Expr
);
6866 Append
(Cond
, Contracts
);
6874 -- If there are no contract aspects, no need for a wrapper.
6876 if Is_Empty_List
(Contracts
) then
6880 Form_P
:= First
(Specs
);
6882 while Present
(Form_P
) loop
6883 New_P
:= New_Copy_Tree
(Form_P
);
6884 Set_Defining_Identifier
(New_P
,
6885 Make_Defining_Identifier
6886 (Loc
, Chars
(Defining_Identifier
(Form_P
))));
6887 Append
(New_P
, Profile
);
6891 -- Add to parameter specifications the access parameter that is passed
6892 -- in from an indirect call.
6895 Make_Parameter_Specification
(Loc
,
6896 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6897 Parameter_Type
=> New_Occurrence_Of
(Id
, Loc
)),
6900 if Nkind
(Type_Def
) = N_Access_Procedure_Definition
then
6902 Make_Procedure_Specification
(Loc
,
6903 Defining_Unit_Name
=> Subp
,
6904 Parameter_Specifications
=> Profile
);
6905 Mutate_Ekind
(Subp
, E_Procedure
);
6908 Make_Function_Specification
(Loc
,
6909 Defining_Unit_Name
=> Subp
,
6910 Parameter_Specifications
=> Profile
,
6911 Result_Definition
=>
6913 (Result_Definition
(Type_Definition
(Decl
))));
6914 Mutate_Ekind
(Subp
, E_Function
);
6918 Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
6919 Set_Aspect_Specifications
(New_Decl
, Contracts
);
6920 Set_Is_Wrapper
(Subp
);
6922 -- The wrapper is declared in the freezing actions to facilitate its
6923 -- identification and thus avoid handling it as a primitive operation
6924 -- of a tagged type (see Is_Access_To_Subprogram_Wrapper); otherwise it
6925 -- may be handled as a dispatching operation and erroneously registered
6926 -- in a dispatch table.
6928 if not GNATprove_Mode
then
6929 Append_Freeze_Action
(Id
, New_Decl
);
6931 -- Under GNATprove mode there is no such problem but we do not declare
6932 -- it in the freezing actions since they are not analyzed under this
6936 Insert_After
(Decl
, New_Decl
);
6939 Set_Access_Subprogram_Wrapper
(Designated_Type
(Id
), Subp
);
6940 Build_Access_Subprogram_Wrapper_Body
(Decl
, New_Decl
);
6941 end Build_Access_Subprogram_Wrapper
;
6943 -------------------------------
6944 -- Build_Derived_Access_Type --
6945 -------------------------------
6947 procedure Build_Derived_Access_Type
6949 Parent_Type
: Entity_Id
;
6950 Derived_Type
: Entity_Id
)
6952 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
6954 Desig_Type
: Entity_Id
;
6956 Discr_Con_Elist
: Elist_Id
;
6957 Discr_Con_El
: Elmt_Id
;
6961 -- Set the designated type so it is available in case this is an access
6962 -- to a self-referential type, e.g. a standard list type with a next
6963 -- pointer. Will be reset after subtype is built.
6965 Set_Directly_Designated_Type
6966 (Derived_Type
, Designated_Type
(Parent_Type
));
6968 Subt
:= Process_Subtype
(S
, N
);
6970 if Nkind
(S
) /= N_Subtype_Indication
6971 and then Subt
/= Base_Type
(Subt
)
6973 Mutate_Ekind
(Derived_Type
, E_Access_Subtype
);
6976 if Ekind
(Derived_Type
) = E_Access_Subtype
then
6978 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6979 Ibase
: constant Entity_Id
:=
6980 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
6981 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
6982 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
6983 Svg_Prev_E
: constant Entity_Id
:= Prev_Entity
(Ibase
);
6986 Copy_Node
(Pbase
, Ibase
);
6988 -- Restore Itype status after Copy_Node
6990 Set_Is_Itype
(Ibase
);
6991 Set_Associated_Node_For_Itype
(Ibase
, N
);
6993 Set_Chars
(Ibase
, Svg_Chars
);
6994 Set_Prev_Entity
(Ibase
, Svg_Prev_E
);
6995 Set_Next_Entity
(Ibase
, Svg_Next_E
);
6996 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
6997 Set_Scope
(Ibase
, Scope
(Derived_Type
));
6998 Set_Freeze_Node
(Ibase
, Empty
);
6999 Set_Is_Frozen
(Ibase
, False);
7000 Set_Comes_From_Source
(Ibase
, False);
7001 Set_Is_First_Subtype
(Ibase
, False);
7003 Set_Etype
(Ibase
, Pbase
);
7004 Set_Etype
(Derived_Type
, Ibase
);
7008 Set_Directly_Designated_Type
7009 (Derived_Type
, Designated_Type
(Subt
));
7011 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
7012 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
7013 Set_Size_Info
(Derived_Type
, Parent_Type
);
7014 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
7015 Set_Depends_On_Private
(Derived_Type
,
7016 Has_Private_Component
(Derived_Type
));
7017 Conditional_Delay
(Derived_Type
, Subt
);
7019 if Is_Access_Subprogram_Type
(Derived_Type
)
7020 and then Is_Base_Type
(Derived_Type
)
7022 Set_Can_Use_Internal_Rep
7023 (Derived_Type
, Can_Use_Internal_Rep
(Parent_Type
));
7026 -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
7027 -- that it is not redundant.
7029 if Null_Exclusion_Present
(Type_Definition
(N
)) then
7030 Set_Can_Never_Be_Null
(Derived_Type
);
7032 elsif Can_Never_Be_Null
(Parent_Type
) then
7033 Set_Can_Never_Be_Null
(Derived_Type
);
7036 -- Note: we do not copy the Storage_Size_Variable, since we always go to
7037 -- the root type for this information.
7039 -- Apply range checks to discriminants for derived record case
7040 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
7042 Desig_Type
:= Designated_Type
(Derived_Type
);
7044 if Is_Composite_Type
(Desig_Type
)
7045 and then not Is_Array_Type
(Desig_Type
)
7046 and then Has_Discriminants
(Desig_Type
)
7047 and then Base_Type
(Desig_Type
) /= Desig_Type
7049 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
7050 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
7052 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
7053 while Present
(Discr_Con_El
) loop
7054 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
7055 Next_Elmt
(Discr_Con_El
);
7056 Next_Discriminant
(Discr
);
7059 end Build_Derived_Access_Type
;
7061 ------------------------------
7062 -- Build_Derived_Array_Type --
7063 ------------------------------
7065 procedure Build_Derived_Array_Type
7067 Parent_Type
: Entity_Id
;
7068 Derived_Type
: Entity_Id
)
7070 Loc
: constant Source_Ptr
:= Sloc
(N
);
7071 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7072 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7073 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7074 Implicit_Base
: Entity_Id
:= Empty
;
7075 New_Indic
: Node_Id
;
7077 procedure Make_Implicit_Base
;
7078 -- If the parent subtype is constrained, the derived type is a subtype
7079 -- of an implicit base type derived from the parent base.
7081 ------------------------
7082 -- Make_Implicit_Base --
7083 ------------------------
7085 procedure Make_Implicit_Base
is
7088 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7090 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7091 Set_Etype
(Implicit_Base
, Parent_Base
);
7093 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
7094 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
7096 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
7097 end Make_Implicit_Base
;
7099 -- Start of processing for Build_Derived_Array_Type
7102 if not Is_Constrained
(Parent_Type
) then
7103 if Nkind
(Indic
) /= N_Subtype_Indication
then
7104 Mutate_Ekind
(Derived_Type
, E_Array_Type
);
7106 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7107 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
7109 Set_Has_Delayed_Freeze
(Derived_Type
, True);
7113 Set_Etype
(Derived_Type
, Implicit_Base
);
7116 Make_Subtype_Declaration
(Loc
,
7117 Defining_Identifier
=> Derived_Type
,
7118 Subtype_Indication
=>
7119 Make_Subtype_Indication
(Loc
,
7120 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7121 Constraint
=> Constraint
(Indic
)));
7123 Rewrite
(N
, New_Indic
);
7128 if Nkind
(Indic
) /= N_Subtype_Indication
then
7131 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
7132 Set_Etype
(Derived_Type
, Implicit_Base
);
7133 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7136 Error_Msg_N
("illegal constraint on constrained type", Indic
);
7140 -- If parent type is not a derived type itself, and is declared in
7141 -- closed scope (e.g. a subprogram), then we must explicitly introduce
7142 -- the new type's concatenation operator since Derive_Subprograms
7143 -- will not inherit the parent's operator. If the parent type is
7144 -- unconstrained, the operator is of the unconstrained base type.
7146 if Number_Dimensions
(Parent_Type
) = 1
7147 and then not Is_Limited_Type
(Parent_Type
)
7148 and then not Is_Derived_Type
(Parent_Type
)
7149 and then not Is_Package_Or_Generic_Package
7150 (Scope
(Base_Type
(Parent_Type
)))
7152 if not Is_Constrained
(Parent_Type
)
7153 and then Is_Constrained
(Derived_Type
)
7155 New_Concatenation_Op
(Implicit_Base
);
7157 New_Concatenation_Op
(Derived_Type
);
7160 end Build_Derived_Array_Type
;
7162 -----------------------------------
7163 -- Build_Derived_Concurrent_Type --
7164 -----------------------------------
7166 procedure Build_Derived_Concurrent_Type
7168 Parent_Type
: Entity_Id
;
7169 Derived_Type
: Entity_Id
)
7171 Loc
: constant Source_Ptr
:= Sloc
(N
);
7172 Def
: constant Node_Id
:= Type_Definition
(N
);
7173 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7175 Corr_Record
: constant Entity_Id
:= Make_Temporary
(Loc
, 'C');
7176 Corr_Decl
: Node_Id
:= Empty
;
7177 Corr_Decl_Needed
: Boolean;
7178 -- If the derived type has fewer discriminants than its parent, the
7179 -- corresponding record is also a derived type, in order to account for
7180 -- the bound discriminants. We create a full type declaration for it in
7183 Constraint_Present
: constant Boolean :=
7184 Nkind
(Indic
) = N_Subtype_Indication
;
7186 D_Constraint
: Node_Id
;
7187 New_Constraint
: Elist_Id
:= No_Elist
;
7188 Old_Disc
: Entity_Id
;
7189 New_Disc
: Entity_Id
;
7193 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
7194 Corr_Decl_Needed
:= False;
7197 if Present
(Discriminant_Specifications
(N
))
7198 and then Constraint_Present
7200 Old_Disc
:= First_Discriminant
(Parent_Type
);
7201 New_Disc
:= First
(Discriminant_Specifications
(N
));
7202 while Present
(New_Disc
) and then Present
(Old_Disc
) loop
7203 Next_Discriminant
(Old_Disc
);
7208 if Present
(Old_Disc
) and then Expander_Active
then
7210 -- The new type has fewer discriminants, so we need to create a new
7211 -- corresponding record, which is derived from the corresponding
7212 -- record of the parent, and has a stored constraint that captures
7213 -- the values of the discriminant constraints. The corresponding
7214 -- record is needed only if expander is active and code generation is
7217 -- The type declaration for the derived corresponding record has the
7218 -- same discriminant part and constraints as the current declaration.
7219 -- Copy the unanalyzed tree to build declaration.
7221 Corr_Decl_Needed
:= True;
7222 New_N
:= Copy_Separate_Tree
(N
);
7225 Make_Full_Type_Declaration
(Loc
,
7226 Defining_Identifier
=> Corr_Record
,
7227 Discriminant_Specifications
=>
7228 Discriminant_Specifications
(New_N
),
7230 Make_Derived_Type_Definition
(Loc
,
7231 Subtype_Indication
=>
7232 Make_Subtype_Indication
(Loc
,
7235 (Corresponding_Record_Type
(Parent_Type
), Loc
),
7238 (Subtype_Indication
(Type_Definition
(New_N
))))));
7241 -- Copy Storage_Size and Relative_Deadline variables if task case
7243 if Is_Task_Type
(Parent_Type
) then
7244 Set_Storage_Size_Variable
(Derived_Type
,
7245 Storage_Size_Variable
(Parent_Type
));
7246 Set_Relative_Deadline_Variable
(Derived_Type
,
7247 Relative_Deadline_Variable
(Parent_Type
));
7250 if Present
(Discriminant_Specifications
(N
)) then
7251 Push_Scope
(Derived_Type
);
7252 Check_Or_Process_Discriminants
(N
, Derived_Type
);
7254 if Constraint_Present
then
7256 Expand_To_Stored_Constraint
7258 Build_Discriminant_Constraints
7259 (Parent_Type
, Indic
, True));
7264 elsif Constraint_Present
then
7266 -- Build an unconstrained derived type and rewrite the derived type
7267 -- as a subtype of this new base type.
7270 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7271 New_Base
: Entity_Id
;
7273 New_Indic
: Node_Id
;
7277 Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
7280 Make_Full_Type_Declaration
(Loc
,
7281 Defining_Identifier
=> New_Base
,
7283 Make_Derived_Type_Definition
(Loc
,
7284 Abstract_Present
=> Abstract_Present
(Def
),
7285 Limited_Present
=> Limited_Present
(Def
),
7286 Subtype_Indication
=>
7287 New_Occurrence_Of
(Parent_Base
, Loc
)));
7289 Mark_Rewrite_Insertion
(New_Decl
);
7290 Insert_Before
(N
, New_Decl
);
7294 Make_Subtype_Indication
(Loc
,
7295 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
7296 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
7299 Make_Subtype_Declaration
(Loc
,
7300 Defining_Identifier
=> Derived_Type
,
7301 Subtype_Indication
=> New_Indic
));
7308 -- By default, operations and private data are inherited from parent.
7309 -- However, in the presence of bound discriminants, a new corresponding
7310 -- record will be created, see below.
7312 Set_Has_Discriminants
7313 (Derived_Type
, Has_Discriminants
(Parent_Type
));
7314 Set_Corresponding_Record_Type
7315 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
7317 -- Is_Constrained is set according the parent subtype, but is set to
7318 -- False if the derived type is declared with new discriminants.
7322 (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
7323 and then not Present
(Discriminant_Specifications
(N
)));
7325 if Constraint_Present
then
7326 if not Has_Discriminants
(Parent_Type
) then
7327 Error_Msg_N
("untagged parent must have discriminants", N
);
7329 elsif Present
(Discriminant_Specifications
(N
)) then
7331 -- Verify that new discriminants are used to constrain old ones
7333 D_Constraint
:= First
(Constraints
(Constraint
(Indic
)));
7335 Old_Disc
:= First_Discriminant
(Parent_Type
);
7337 while Present
(D_Constraint
) loop
7338 if Nkind
(D_Constraint
) /= N_Discriminant_Association
then
7340 -- Positional constraint. If it is a reference to a new
7341 -- discriminant, it constrains the corresponding old one.
7343 if Nkind
(D_Constraint
) = N_Identifier
then
7344 New_Disc
:= First_Discriminant
(Derived_Type
);
7345 while Present
(New_Disc
) loop
7346 exit when Chars
(New_Disc
) = Chars
(D_Constraint
);
7347 Next_Discriminant
(New_Disc
);
7350 if Present
(New_Disc
) then
7351 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
7355 Next_Discriminant
(Old_Disc
);
7357 -- if this is a named constraint, search by name for the old
7358 -- discriminants constrained by the new one.
7360 elsif Nkind
(Expression
(D_Constraint
)) = N_Identifier
then
7362 -- Find new discriminant with that name
7364 New_Disc
:= First_Discriminant
(Derived_Type
);
7365 while Present
(New_Disc
) loop
7367 Chars
(New_Disc
) = Chars
(Expression
(D_Constraint
));
7368 Next_Discriminant
(New_Disc
);
7371 if Present
(New_Disc
) then
7373 -- Verify that new discriminant renames some discriminant
7374 -- of the parent type, and associate the new discriminant
7375 -- with one or more old ones that it renames.
7381 Selector
:= First
(Selector_Names
(D_Constraint
));
7382 while Present
(Selector
) loop
7383 Old_Disc
:= First_Discriminant
(Parent_Type
);
7384 while Present
(Old_Disc
) loop
7385 exit when Chars
(Old_Disc
) = Chars
(Selector
);
7386 Next_Discriminant
(Old_Disc
);
7389 if Present
(Old_Disc
) then
7390 Set_Corresponding_Discriminant
7391 (New_Disc
, Old_Disc
);
7400 Next
(D_Constraint
);
7403 New_Disc
:= First_Discriminant
(Derived_Type
);
7404 while Present
(New_Disc
) loop
7405 if No
(Corresponding_Discriminant
(New_Disc
)) then
7407 ("new discriminant& must constrain old one", N
, New_Disc
);
7409 -- If a new discriminant is used in the constraint, then its
7410 -- subtype must be statically compatible with the subtype of
7411 -- the parent discriminant (RM 3.7(15)).
7414 Check_Constraining_Discriminant
7415 (New_Disc
, Corresponding_Discriminant
(New_Disc
));
7418 Next_Discriminant
(New_Disc
);
7422 elsif Present
(Discriminant_Specifications
(N
)) then
7424 ("missing discriminant constraint in untagged derivation", N
);
7427 -- The entity chain of the derived type includes the new discriminants
7428 -- but shares operations with the parent.
7430 if Present
(Discriminant_Specifications
(N
)) then
7431 Old_Disc
:= First_Discriminant
(Parent_Type
);
7432 while Present
(Old_Disc
) loop
7433 if No
(Next_Entity
(Old_Disc
))
7434 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
7437 (Last_Entity
(Derived_Type
), Next_Entity
(Old_Disc
));
7441 Next_Discriminant
(Old_Disc
);
7445 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
7446 if Has_Discriminants
(Parent_Type
) then
7447 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7448 Set_Discriminant_Constraint
(
7449 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
7453 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
7455 Set_Has_Completion
(Derived_Type
);
7457 if Corr_Decl_Needed
then
7458 Set_Stored_Constraint
(Derived_Type
, New_Constraint
);
7459 Insert_After
(N
, Corr_Decl
);
7460 Analyze
(Corr_Decl
);
7461 Set_Corresponding_Record_Type
(Derived_Type
, Corr_Record
);
7463 end Build_Derived_Concurrent_Type
;
7465 ------------------------------------
7466 -- Build_Derived_Enumeration_Type --
7467 ------------------------------------
7469 procedure Build_Derived_Enumeration_Type
7471 Parent_Type
: Entity_Id
;
7472 Derived_Type
: Entity_Id
)
7474 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean;
7475 -- When the type declaration includes a constraint, we generate
7476 -- a subtype declaration of an anonymous base type, with the constraint
7477 -- given in the original type declaration. Conceptually, the bounds
7478 -- are converted to the new base type, and this conversion freezes
7479 -- (prematurely) that base type, when the bounds are simply literals.
7480 -- As a result, a representation clause for the derived type is then
7481 -- rejected or ignored. This procedure recognizes the simple case of
7482 -- literal bounds, which allows us to indicate that the conversions
7483 -- are not freeze points, and the subsequent representation clause
7485 -- A similar approach might be used to resolve the long-standing
7486 -- problem of premature freezing of derived numeric types ???
7488 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean is
7490 return Nkind
(B
) = N_Type_Conversion
7491 and then Is_Entity_Name
(Expression
(B
))
7492 and then Ekind
(Entity
(Expression
(B
))) = E_Enumeration_Literal
;
7493 end Bound_Belongs_To_Type
;
7495 Loc
: constant Source_Ptr
:= Sloc
(N
);
7496 Def
: constant Node_Id
:= Type_Definition
(N
);
7497 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7498 Implicit_Base
: Entity_Id
;
7499 Literal
: Entity_Id
;
7500 New_Lit
: Entity_Id
;
7501 Literals_List
: List_Id
;
7502 Type_Decl
: Node_Id
;
7504 Rang_Expr
: Node_Id
;
7507 -- Since types Standard.Character and Standard.[Wide_]Wide_Character do
7508 -- not have explicit literals lists we need to process types derived
7509 -- from them specially. This is handled by Derived_Standard_Character.
7510 -- If the parent type is a generic type, there are no literals either,
7511 -- and we construct the same skeletal representation as for the generic
7514 if Is_Standard_Character_Type
(Parent_Type
) then
7515 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
7517 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
7523 if Nkind
(Indic
) /= N_Subtype_Indication
then
7525 Make_Attribute_Reference
(Loc
,
7526 Attribute_Name
=> Name_First
,
7527 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7528 Set_Etype
(Lo
, Derived_Type
);
7531 Make_Attribute_Reference
(Loc
,
7532 Attribute_Name
=> Name_Last
,
7533 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7534 Set_Etype
(Hi
, Derived_Type
);
7536 Set_Scalar_Range
(Derived_Type
,
7542 -- Analyze subtype indication and verify compatibility
7543 -- with parent type.
7545 if Base_Type
(Process_Subtype
(Indic
, N
)) /=
7546 Base_Type
(Parent_Type
)
7549 ("illegal constraint for formal discrete type", N
);
7555 -- If a constraint is present, analyze the bounds to catch
7556 -- premature usage of the derived literals.
7558 if Nkind
(Indic
) = N_Subtype_Indication
7559 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
7561 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
7562 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
7565 -- Create an implicit base type for the derived type even if there
7566 -- is no constraint attached to it, since this seems closer to the
7567 -- Ada semantics. Use an Itype like for the implicit base type of
7568 -- other kinds of derived type, but build a full type declaration
7569 -- for it so as to analyze the new literals properly. Then build a
7570 -- subtype declaration tree which applies the constraint (if any)
7571 -- and have it replace the derived type declaration.
7573 Literal
:= First_Literal
(Parent_Type
);
7574 Literals_List
:= New_List
;
7575 while Present
(Literal
)
7576 and then Ekind
(Literal
) = E_Enumeration_Literal
7578 -- Literals of the derived type have the same representation as
7579 -- those of the parent type, but this representation can be
7580 -- overridden by an explicit representation clause. Indicate
7581 -- that there is no explicit representation given yet. These
7582 -- derived literals are implicit operations of the new type,
7583 -- and can be overridden by explicit ones.
7585 if Nkind
(Literal
) = N_Defining_Character_Literal
then
7587 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
7589 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
7592 Mutate_Ekind
(New_Lit
, E_Enumeration_Literal
);
7593 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
7594 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
7595 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
7596 Set_Alias
(New_Lit
, Literal
);
7597 Set_Is_Known_Valid
(New_Lit
, True);
7599 Append
(New_Lit
, Literals_List
);
7600 Next_Literal
(Literal
);
7604 Create_Itype
(E_Enumeration_Type
, N
, Derived_Type
, 'B');
7606 -- Indicate the proper nature of the derived type. This must be done
7607 -- before analysis of the literals, to recognize cases when a literal
7608 -- may be hidden by a previous explicit function definition (cf.
7611 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
7612 Set_Etype
(Derived_Type
, Implicit_Base
);
7615 Make_Full_Type_Declaration
(Loc
,
7616 Defining_Identifier
=> Implicit_Base
,
7618 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
7620 -- Do not insert the declarationn, just analyze it in the context
7622 Set_Parent
(Type_Decl
, Parent
(N
));
7623 Analyze
(Type_Decl
);
7625 -- The anonymous base now has a full declaration, but this base
7626 -- is not a first subtype.
7628 Set_Is_First_Subtype
(Implicit_Base
, False);
7630 -- After the implicit base is analyzed its Etype needs to be changed
7631 -- to reflect the fact that it is derived from the parent type which
7632 -- was ignored during analysis. We also set the size at this point.
7634 Set_Etype
(Implicit_Base
, Parent_Type
);
7636 Set_Size_Info
(Implicit_Base
, Parent_Type
);
7637 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
7638 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
7640 -- Copy other flags from parent type
7642 Set_Has_Non_Standard_Rep
7643 (Implicit_Base
, Has_Non_Standard_Rep
7645 Set_Has_Pragma_Ordered
7646 (Implicit_Base
, Has_Pragma_Ordered
7648 Set_Has_Delayed_Freeze
(Implicit_Base
);
7650 -- Process the subtype indication including a validation check on the
7651 -- constraint, if any. If a constraint is given, its bounds must be
7652 -- implicitly converted to the new type.
7654 if Nkind
(Indic
) = N_Subtype_Indication
then
7656 R
: constant Node_Id
:=
7657 Range_Expression
(Constraint
(Indic
));
7660 if Nkind
(R
) = N_Range
then
7661 Hi
:= Build_Scalar_Bound
7662 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
7663 Lo
:= Build_Scalar_Bound
7664 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
7667 -- Constraint is a Range attribute. Replace with explicit
7668 -- mention of the bounds of the prefix, which must be a
7671 Analyze
(Prefix
(R
));
7673 Convert_To
(Implicit_Base
,
7674 Make_Attribute_Reference
(Loc
,
7675 Attribute_Name
=> Name_Last
,
7677 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7680 Convert_To
(Implicit_Base
,
7681 Make_Attribute_Reference
(Loc
,
7682 Attribute_Name
=> Name_First
,
7684 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7691 (Type_High_Bound
(Parent_Type
),
7692 Parent_Type
, Implicit_Base
);
7695 (Type_Low_Bound
(Parent_Type
),
7696 Parent_Type
, Implicit_Base
);
7704 -- If we constructed a default range for the case where no range
7705 -- was given, then the expressions in the range must not freeze
7706 -- since they do not correspond to expressions in the source.
7707 -- However, if the type inherits predicates the expressions will
7708 -- be elaborated earlier and must freeze.
7710 if (Nkind
(Indic
) /= N_Subtype_Indication
7712 (Bound_Belongs_To_Type
(Lo
) and then Bound_Belongs_To_Type
(Hi
)))
7713 and then not Has_Predicates
(Derived_Type
)
7715 Set_Must_Not_Freeze
(Lo
);
7716 Set_Must_Not_Freeze
(Hi
);
7717 Set_Must_Not_Freeze
(Rang_Expr
);
7721 Make_Subtype_Declaration
(Loc
,
7722 Defining_Identifier
=> Derived_Type
,
7723 Subtype_Indication
=>
7724 Make_Subtype_Indication
(Loc
,
7725 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7727 Make_Range_Constraint
(Loc
,
7728 Range_Expression
=> Rang_Expr
))));
7732 -- Propagate the aspects from the original type declaration to the
7733 -- declaration of the implicit base.
7735 Move_Aspects
(From
=> Original_Node
(N
), To
=> Type_Decl
);
7737 -- Apply a range check. Since this range expression doesn't have an
7738 -- Etype, we have to specifically pass the Source_Typ parameter. Is
7741 if Nkind
(Indic
) = N_Subtype_Indication
then
7743 (Range_Expression
(Constraint
(Indic
)), Parent_Type
,
7744 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
7747 end Build_Derived_Enumeration_Type
;
7749 --------------------------------
7750 -- Build_Derived_Numeric_Type --
7751 --------------------------------
7753 procedure Build_Derived_Numeric_Type
7755 Parent_Type
: Entity_Id
;
7756 Derived_Type
: Entity_Id
)
7758 Loc
: constant Source_Ptr
:= Sloc
(N
);
7759 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7760 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7761 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7762 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
7763 N_Subtype_Indication
;
7764 Implicit_Base
: Entity_Id
;
7770 -- Process the subtype indication including a validation check on
7771 -- the constraint if any.
7773 Discard_Node
(Process_Subtype
(Indic
, N
));
7775 -- Introduce an implicit base type for the derived type even if there
7776 -- is no constraint attached to it, since this seems closer to the Ada
7780 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7782 Set_Etype
(Implicit_Base
, Parent_Base
);
7783 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7784 Set_Size_Info
(Implicit_Base
, Parent_Base
);
7785 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
7786 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
7787 Set_Is_Known_Valid
(Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7788 Set_Is_Volatile
(Implicit_Base
, Is_Volatile
(Parent_Base
));
7790 -- Set RM Size for discrete type or decimal fixed-point type
7791 -- Ordinary fixed-point is excluded, why???
7793 if Is_Discrete_Type
(Parent_Base
)
7794 or else Is_Decimal_Fixed_Point_Type
(Parent_Base
)
7796 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
7799 Set_Has_Delayed_Freeze
(Implicit_Base
);
7801 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
7802 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
7804 Set_Scalar_Range
(Implicit_Base
,
7809 if Has_Infinities
(Parent_Base
) then
7810 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
7813 -- The Derived_Type, which is the entity of the declaration, is a
7814 -- subtype of the implicit base. Its Ekind is a subtype, even in the
7815 -- absence of an explicit constraint.
7817 Set_Etype
(Derived_Type
, Implicit_Base
);
7819 -- If we did not have a constraint, then the Ekind is set from the
7820 -- parent type (otherwise Process_Subtype has set the bounds)
7822 if No_Constraint
then
7823 Mutate_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
7826 -- If we did not have a range constraint, then set the range from the
7827 -- parent type. Otherwise, the Process_Subtype call has set the bounds.
7829 if No_Constraint
or else not Has_Range_Constraint
(Indic
) then
7830 Set_Scalar_Range
(Derived_Type
,
7832 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
7833 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
7834 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7836 if Has_Infinities
(Parent_Type
) then
7837 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
7840 Set_Is_Known_Valid
(Derived_Type
, Is_Known_Valid
(Parent_Type
));
7843 Set_Is_Descendant_Of_Address
(Derived_Type
,
7844 Is_Descendant_Of_Address
(Parent_Type
));
7845 Set_Is_Descendant_Of_Address
(Implicit_Base
,
7846 Is_Descendant_Of_Address
(Parent_Type
));
7848 -- Set remaining type-specific fields, depending on numeric type
7850 if Is_Modular_Integer_Type
(Parent_Type
) then
7851 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
7853 Set_Non_Binary_Modulus
7854 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
7857 (Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7859 elsif Is_Floating_Point_Type
(Parent_Type
) then
7861 -- Digits of base type is always copied from the digits value of
7862 -- the parent base type, but the digits of the derived type will
7863 -- already have been set if there was a constraint present.
7865 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7866 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Parent_Base
));
7868 if No_Constraint
then
7869 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
7872 elsif Is_Fixed_Point_Type
(Parent_Type
) then
7874 -- Small of base type and derived type are always copied from the
7875 -- parent base type, since smalls never change. The delta of the
7876 -- base type is also copied from the parent base type. However the
7877 -- delta of the derived type will have been set already if a
7878 -- constraint was present.
7880 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
7881 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
7882 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
7884 if No_Constraint
then
7885 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
7888 -- The scale and machine radix in the decimal case are always
7889 -- copied from the parent base type.
7891 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
7892 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
7893 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
7895 Set_Machine_Radix_10
7896 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
7897 Set_Machine_Radix_10
7898 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
7900 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7902 if No_Constraint
then
7903 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
7906 -- the analysis of the subtype_indication sets the
7907 -- digits value of the derived type.
7914 if Is_Integer_Type
(Parent_Type
) then
7915 Set_Has_Shift_Operator
7916 (Implicit_Base
, Has_Shift_Operator
(Parent_Type
));
7919 -- The type of the bounds is that of the parent type, and they
7920 -- must be converted to the derived type.
7922 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
7923 end Build_Derived_Numeric_Type
;
7925 --------------------------------
7926 -- Build_Derived_Private_Type --
7927 --------------------------------
7929 procedure Build_Derived_Private_Type
7931 Parent_Type
: Entity_Id
;
7932 Derived_Type
: Entity_Id
;
7933 Is_Completion
: Boolean;
7934 Derive_Subps
: Boolean := True)
7936 Loc
: constant Source_Ptr
:= Sloc
(N
);
7937 Par_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7938 Par_Scope
: constant Entity_Id
:= Scope
(Par_Base
);
7939 Full_N
: constant Node_Id
:= New_Copy_Tree
(N
);
7940 Full_Der
: Entity_Id
:= New_Copy
(Derived_Type
);
7943 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
;
7944 -- Return the Full_View or Underlying_Full_View of Typ, whichever is
7945 -- present (they cannot be both present for the same type), or Empty.
7947 procedure Build_Full_Derivation
;
7948 -- Build full derivation, i.e. derive from the full view
7950 procedure Copy_And_Build
;
7951 -- Copy derived type declaration, replace parent with its full view,
7952 -- and build derivation
7954 -------------------------
7955 -- Available_Full_View --
7956 -------------------------
7958 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
is
7960 if Present
(Full_View
(Typ
)) then
7961 return Full_View
(Typ
);
7963 elsif Present
(Underlying_Full_View
(Typ
)) then
7965 -- We should be called on a type with an underlying full view
7966 -- only by means of the recursive call made in Copy_And_Build
7967 -- through the first call to Build_Derived_Type, or else if
7968 -- the parent scope is being analyzed because we are deriving
7971 pragma Assert
(Is_Completion
or else In_Private_Part
(Par_Scope
));
7973 return Underlying_Full_View
(Typ
);
7978 end Available_Full_View
;
7980 ---------------------------
7981 -- Build_Full_Derivation --
7982 ---------------------------
7984 procedure Build_Full_Derivation
is
7986 -- If parent scope is not open, install the declarations
7988 if not In_Open_Scopes
(Par_Scope
) then
7989 Install_Private_Declarations
(Par_Scope
);
7990 Install_Visible_Declarations
(Par_Scope
);
7992 Uninstall_Declarations
(Par_Scope
);
7994 -- If parent scope is open and in another unit, and parent has a
7995 -- completion, then the derivation is taking place in the visible
7996 -- part of a child unit. In that case retrieve the full view of
7997 -- the parent momentarily.
7999 elsif not In_Same_Source_Unit
(N
, Parent_Type
)
8000 and then Present
(Full_View
(Parent_Type
))
8002 Full_P
:= Full_View
(Parent_Type
);
8003 Exchange_Declarations
(Parent_Type
);
8005 Exchange_Declarations
(Full_P
);
8007 -- Otherwise it is a local derivation
8012 end Build_Full_Derivation
;
8014 --------------------
8015 -- Copy_And_Build --
8016 --------------------
8018 procedure Copy_And_Build
is
8019 Full_Parent
: Entity_Id
:= Parent_Type
;
8022 -- If the parent is itself derived from another private type,
8023 -- installing the private declarations has not affected its
8024 -- privacy status, so use its own full view explicitly.
8026 if Is_Private_Type
(Full_Parent
)
8027 and then Present
(Full_View
(Full_Parent
))
8029 Full_Parent
:= Full_View
(Full_Parent
);
8032 -- If the full view is itself derived from another private type
8033 -- and has got an underlying full view, and this is done for a
8034 -- completion, i.e. to build the underlying full view of the type,
8035 -- then use this underlying full view. We cannot do that if this
8036 -- is not a completion, i.e. to build the full view of the type,
8037 -- because this would break the privacy of the parent type, except
8038 -- if the parent scope is being analyzed because we are deriving a
8041 if Is_Private_Type
(Full_Parent
)
8042 and then Present
(Underlying_Full_View
(Full_Parent
))
8043 and then (Is_Completion
or else In_Private_Part
(Par_Scope
))
8045 Full_Parent
:= Underlying_Full_View
(Full_Parent
);
8048 -- For private, record, concurrent, access and almost all enumeration
8049 -- types, the derivation from the full view requires a fully-fledged
8050 -- declaration. In the other cases, just use an itype.
8052 if Is_Private_Type
(Full_Parent
)
8053 or else Is_Record_Type
(Full_Parent
)
8054 or else Is_Concurrent_Type
(Full_Parent
)
8055 or else Is_Access_Type
(Full_Parent
)
8057 (Is_Enumeration_Type
(Full_Parent
)
8058 and then not Is_Standard_Character_Type
(Full_Parent
)
8059 and then not Is_Generic_Type
(Root_Type
(Full_Parent
)))
8061 -- Copy and adjust declaration to provide a completion for what
8062 -- is originally a private declaration. Indicate that full view
8063 -- is internally generated.
8065 Set_Comes_From_Source
(Full_N
, False);
8066 Set_Comes_From_Source
(Full_Der
, False);
8067 Set_Parent
(Full_Der
, Full_N
);
8068 Set_Defining_Identifier
(Full_N
, Full_Der
);
8070 -- If there are no constraints, adjust the subtype mark
8072 if Nkind
(Subtype_Indication
(Type_Definition
(Full_N
))) /=
8073 N_Subtype_Indication
8075 Set_Subtype_Indication
8076 (Type_Definition
(Full_N
),
8077 New_Occurrence_Of
(Full_Parent
, Sloc
(Full_N
)));
8080 Insert_After
(N
, Full_N
);
8082 -- Build full view of derived type from full view of parent which
8083 -- is now installed. Subprograms have been derived on the partial
8084 -- view, the completion does not derive them anew.
8086 if Is_Record_Type
(Full_Parent
) then
8088 -- If parent type is tagged, the completion inherits the proper
8089 -- primitive operations.
8091 if Is_Tagged_Type
(Parent_Type
) then
8092 Build_Derived_Record_Type
8093 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
);
8095 Build_Derived_Record_Type
8096 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
=> False);
8100 -- If the parent type is private, this is not a completion and
8101 -- we build the full derivation recursively as a completion.
8104 (Full_N
, Full_Parent
, Full_Der
,
8105 Is_Completion
=> Is_Private_Type
(Full_Parent
),
8106 Derive_Subps
=> False);
8109 -- The full declaration has been introduced into the tree and
8110 -- processed in the step above. It should not be analyzed again
8111 -- (when encountered later in the current list of declarations)
8112 -- to prevent spurious name conflicts. The full entity remains
8115 Set_Analyzed
(Full_N
);
8119 Make_Defining_Identifier
(Sloc
(Derived_Type
),
8120 Chars
=> Chars
(Derived_Type
));
8121 Set_Is_Itype
(Full_Der
);
8122 Set_Associated_Node_For_Itype
(Full_Der
, N
);
8123 Set_Parent
(Full_Der
, N
);
8125 (N
, Full_Parent
, Full_Der
,
8126 Is_Completion
=> False, Derive_Subps
=> False);
8129 Set_Has_Private_Declaration
(Full_Der
);
8130 Set_Has_Private_Declaration
(Derived_Type
);
8132 Set_Scope
(Full_Der
, Scope
(Derived_Type
));
8133 Set_Is_First_Subtype
(Full_Der
, Is_First_Subtype
(Derived_Type
));
8134 Set_Has_Size_Clause
(Full_Der
, False);
8135 Set_Has_Alignment_Clause
(Full_Der
, False);
8136 Set_Has_Delayed_Freeze
(Full_Der
);
8137 Set_Is_Frozen
(Full_Der
, False);
8138 Set_Freeze_Node
(Full_Der
, Empty
);
8139 Set_Depends_On_Private
(Full_Der
, Has_Private_Component
(Full_Der
));
8140 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
8142 -- The convention on the base type may be set in the private part
8143 -- and not propagated to the subtype until later, so we obtain the
8144 -- convention from the base type of the parent.
8146 Set_Convention
(Full_Der
, Convention
(Base_Type
(Full_Parent
)));
8149 -- Start of processing for Build_Derived_Private_Type
8152 if Is_Tagged_Type
(Parent_Type
) then
8153 Full_P
:= Full_View
(Parent_Type
);
8155 -- A type extension of a type with unknown discriminants is an
8156 -- indefinite type that the back-end cannot handle directly.
8157 -- We treat it as a private type, and build a completion that is
8158 -- derived from the full view of the parent, and hopefully has
8159 -- known discriminants.
8161 -- If the full view of the parent type has an underlying record view,
8162 -- use it to generate the underlying record view of this derived type
8163 -- (required for chains of derivations with unknown discriminants).
8165 -- Minor optimization: we avoid the generation of useless underlying
8166 -- record view entities if the private type declaration has unknown
8167 -- discriminants but its corresponding full view has no
8170 if Has_Unknown_Discriminants
(Parent_Type
)
8171 and then Present
(Full_P
)
8172 and then (Has_Discriminants
(Full_P
)
8173 or else Present
(Underlying_Record_View
(Full_P
)))
8174 and then not In_Open_Scopes
(Par_Scope
)
8175 and then Expander_Active
8178 Full_Der
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
8179 New_Ext
: constant Node_Id
:=
8181 (Record_Extension_Part
(Type_Definition
(N
)));
8185 Build_Derived_Record_Type
8186 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8188 -- Build anonymous completion, as a derivation from the full
8189 -- view of the parent. This is not a completion in the usual
8190 -- sense, because the current type is not private.
8193 Make_Full_Type_Declaration
(Loc
,
8194 Defining_Identifier
=> Full_Der
,
8196 Make_Derived_Type_Definition
(Loc
,
8197 Subtype_Indication
=>
8199 (Subtype_Indication
(Type_Definition
(N
))),
8200 Record_Extension_Part
=> New_Ext
));
8202 -- If the parent type has an underlying record view, use it
8203 -- here to build the new underlying record view.
8205 if Present
(Underlying_Record_View
(Full_P
)) then
8207 (Nkind
(Subtype_Indication
(Type_Definition
(Decl
)))
8209 Set_Entity
(Subtype_Indication
(Type_Definition
(Decl
)),
8210 Underlying_Record_View
(Full_P
));
8213 Install_Private_Declarations
(Par_Scope
);
8214 Install_Visible_Declarations
(Par_Scope
);
8215 Insert_Before
(N
, Decl
);
8217 -- Mark entity as an underlying record view before analysis,
8218 -- to avoid generating the list of its primitive operations
8219 -- (which is not really required for this entity) and thus
8220 -- prevent spurious errors associated with missing overriding
8221 -- of abstract primitives (overridden only for Derived_Type).
8223 Mutate_Ekind
(Full_Der
, E_Record_Type
);
8224 Set_Is_Underlying_Record_View
(Full_Der
);
8225 Set_Default_SSO
(Full_Der
);
8226 Set_No_Reordering
(Full_Der
, No_Component_Reordering
);
8230 pragma Assert
(Has_Discriminants
(Full_Der
)
8231 and then not Has_Unknown_Discriminants
(Full_Der
));
8233 Uninstall_Declarations
(Par_Scope
);
8235 -- Freeze the underlying record view, to prevent generation of
8236 -- useless dispatching information, which is simply shared with
8237 -- the real derived type.
8239 Set_Is_Frozen
(Full_Der
);
8241 -- If the derived type has access discriminants, create
8242 -- references to their anonymous types now, to prevent
8243 -- back-end problems when their first use is in generated
8244 -- bodies of primitives.
8250 E
:= First_Entity
(Full_Der
);
8252 while Present
(E
) loop
8253 if Ekind
(E
) = E_Discriminant
8254 and then Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
8256 Build_Itype_Reference
(Etype
(E
), Decl
);
8263 -- Set up links between real entity and underlying record view
8265 Set_Underlying_Record_View
(Derived_Type
, Base_Type
(Full_Der
));
8266 Set_Underlying_Record_View
(Base_Type
(Full_Der
), Derived_Type
);
8269 -- If discriminants are known, build derived record
8272 Build_Derived_Record_Type
8273 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8278 elsif Has_Discriminants
(Parent_Type
) then
8280 -- Build partial view of derived type from partial view of parent.
8281 -- This must be done before building the full derivation because the
8282 -- second derivation will modify the discriminants of the first and
8283 -- the discriminants are chained with the rest of the components in
8284 -- the full derivation.
8286 Build_Derived_Record_Type
8287 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8289 -- Build the full derivation if this is not the anonymous derived
8290 -- base type created by Build_Derived_Record_Type in the constrained
8291 -- case (see point 5. of its head comment) since we build it for the
8294 if Present
(Available_Full_View
(Parent_Type
))
8295 and then not Is_Itype
(Derived_Type
)
8298 Der_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
8300 Last_Discr
: Entity_Id
;
8303 -- If this is not a completion, construct the implicit full
8304 -- view by deriving from the full view of the parent type.
8305 -- But if this is a completion, the derived private type
8306 -- being built is a full view and the full derivation can
8307 -- only be its underlying full view.
8309 Build_Full_Derivation
;
8311 if not Is_Completion
then
8312 Set_Full_View
(Derived_Type
, Full_Der
);
8314 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8315 Set_Is_Underlying_Full_View
(Full_Der
);
8318 if not Is_Base_Type
(Derived_Type
) then
8319 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
8322 -- Copy the discriminant list from full view to the partial
8323 -- view (base type and its subtype). Gigi requires that the
8324 -- partial and full views have the same discriminants.
8326 -- Note that since the partial view points to discriminants
8327 -- in the full view, their scope will be that of the full
8328 -- view. This might cause some front end problems and need
8331 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
8332 Set_First_Entity
(Der_Base
, Discr
);
8335 Last_Discr
:= Discr
;
8336 Next_Discriminant
(Discr
);
8337 exit when No
(Discr
);
8340 Set_Last_Entity
(Der_Base
, Last_Discr
);
8341 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
8342 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
8346 elsif Present
(Available_Full_View
(Parent_Type
))
8347 and then Has_Discriminants
(Available_Full_View
(Parent_Type
))
8349 if Has_Unknown_Discriminants
(Parent_Type
)
8350 and then Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8351 N_Subtype_Indication
8354 ("cannot constrain type with unknown discriminants",
8355 Subtype_Indication
(Type_Definition
(N
)));
8359 -- If this is not a completion, construct the implicit full view by
8360 -- deriving from the full view of the parent type. But if this is a
8361 -- completion, the derived private type being built is a full view
8362 -- and the full derivation can only be its underlying full view.
8364 Build_Full_Derivation
;
8366 if not Is_Completion
then
8367 Set_Full_View
(Derived_Type
, Full_Der
);
8369 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8370 Set_Is_Underlying_Full_View
(Full_Der
);
8373 -- In any case, the primitive operations are inherited from the
8374 -- parent type, not from the internal full view.
8376 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
8378 if Derive_Subps
then
8379 -- Initialize the list of primitive operations to an empty list,
8380 -- to cover tagged types as well as untagged types. For untagged
8381 -- types this is used either to analyze the call as legal when
8382 -- Extensions_Allowed is True, or to issue a better error message
8385 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
8387 Derive_Subprograms
(Parent_Type
, Derived_Type
);
8390 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8392 (Derived_Type
, Is_Constrained
(Available_Full_View
(Parent_Type
)));
8395 -- Untagged type, No discriminants on either view
8397 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8398 N_Subtype_Indication
8401 ("illegal constraint on type without discriminants", N
);
8404 if Present
(Discriminant_Specifications
(N
))
8405 and then Present
(Available_Full_View
(Parent_Type
))
8406 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8408 Error_Msg_N
("cannot add discriminants to untagged type", N
);
8411 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8412 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
8414 Set_Is_Controlled_Active
8415 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
8417 Set_Disable_Controlled
8418 (Derived_Type
, Disable_Controlled
(Parent_Type
));
8420 Set_Has_Controlled_Component
8421 (Derived_Type
, Has_Controlled_Component
(Parent_Type
));
8423 -- Direct controlled types do not inherit Finalize_Storage_Only flag
8425 if not Is_Controlled
(Parent_Type
) then
8426 Set_Finalize_Storage_Only
8427 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
8430 -- If this is not a completion, construct the implicit full view by
8431 -- deriving from the full view of the parent type. But if this is a
8432 -- completion, the derived private type being built is a full view
8433 -- and the full derivation can only be its underlying full view.
8435 -- ??? If the parent type is untagged private and its completion is
8436 -- tagged, this mechanism will not work because we cannot derive from
8437 -- the tagged full view unless we have an extension.
8439 if Present
(Available_Full_View
(Parent_Type
))
8440 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8441 and then not Error_Posted
(N
)
8443 Build_Full_Derivation
;
8445 if not Is_Completion
then
8446 Set_Full_View
(Derived_Type
, Full_Der
);
8448 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8449 Set_Is_Underlying_Full_View
(Full_Der
);
8454 Set_Has_Unknown_Discriminants
(Derived_Type
,
8455 Has_Unknown_Discriminants
(Parent_Type
));
8457 if Is_Private_Type
(Derived_Type
) then
8458 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
8461 -- If the parent base type is in scope, add the derived type to its
8462 -- list of private dependents, because its full view may become
8463 -- visible subsequently (in a nested private part, a body, or in a
8464 -- further child unit).
8466 if Is_Private_Type
(Par_Base
) and then In_Open_Scopes
(Par_Scope
) then
8467 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
8469 -- Check for unusual case where a type completed by a private
8470 -- derivation occurs within a package nested in a child unit, and
8471 -- the parent is declared in an ancestor.
8473 if Is_Child_Unit
(Scope
(Current_Scope
))
8474 and then Is_Completion
8475 and then In_Private_Part
(Current_Scope
)
8476 and then Scope
(Parent_Type
) /= Current_Scope
8478 -- Note that if the parent has a completion in the private part,
8479 -- (which is itself a derivation from some other private type)
8480 -- it is that completion that is visible, there is no full view
8481 -- available, and no special processing is needed.
8483 and then Present
(Full_View
(Parent_Type
))
8485 -- In this case, the full view of the parent type will become
8486 -- visible in the body of the enclosing child, and only then will
8487 -- the current type be possibly non-private. Build an underlying
8488 -- full view that will be installed when the enclosing child body
8491 if Present
(Underlying_Full_View
(Derived_Type
)) then
8492 Full_Der
:= Underlying_Full_View
(Derived_Type
);
8494 Build_Full_Derivation
;
8495 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8496 Set_Is_Underlying_Full_View
(Full_Der
);
8499 -- The full view will be used to swap entities on entry/exit to
8500 -- the body, and must appear in the entity list for the package.
8502 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
8505 end Build_Derived_Private_Type
;
8507 -------------------------------
8508 -- Build_Derived_Record_Type --
8509 -------------------------------
8513 -- Ideally we would like to use the same model of type derivation for
8514 -- tagged and untagged record types. Unfortunately this is not quite
8515 -- possible because the semantics of representation clauses is different
8516 -- for tagged and untagged records under inheritance. Consider the
8519 -- type R (...) is [tagged] record ... end record;
8520 -- type T (...) is new R (...) [with ...];
8522 -- The representation clauses for T can specify a completely different
8523 -- record layout from R's. Hence the same component can be placed in two
8524 -- very different positions in objects of type T and R. If R and T are
8525 -- tagged types, representation clauses for T can only specify the layout
8526 -- of non inherited components, thus components that are common in R and T
8527 -- have the same position in objects of type R and T.
8529 -- This has two implications. The first is that the entire tree for R's
8530 -- declaration needs to be copied for T in the untagged case, so that T
8531 -- can be viewed as a record type of its own with its own representation
8532 -- clauses. The second implication is the way we handle discriminants.
8533 -- Specifically, in the untagged case we need a way to communicate to Gigi
8534 -- what are the real discriminants in the record, while for the semantics
8535 -- we need to consider those introduced by the user to rename the
8536 -- discriminants in the parent type. This is handled by introducing the
8537 -- notion of stored discriminants. See below for more.
8539 -- Fortunately the way regular components are inherited can be handled in
8540 -- the same way in tagged and untagged types.
8542 -- To complicate things a bit more the private view of a private extension
8543 -- cannot be handled in the same way as the full view (for one thing the
8544 -- semantic rules are somewhat different). We will explain what differs
8547 -- 2. DISCRIMINANTS UNDER INHERITANCE
8549 -- The semantic rules governing the discriminants of derived types are
8552 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
8553 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
8555 -- If parent type has discriminants, then the discriminants that are
8556 -- declared in the derived type are [3.4 (11)]:
8558 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
8561 -- o Otherwise, each discriminant of the parent type (implicitly declared
8562 -- in the same order with the same specifications). In this case, the
8563 -- discriminants are said to be "inherited", or if unknown in the parent
8564 -- are also unknown in the derived type.
8566 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
8568 -- o The parent subtype must be constrained;
8570 -- o If the parent type is not a tagged type, then each discriminant of
8571 -- the derived type must be used in the constraint defining a parent
8572 -- subtype. [Implementation note: This ensures that the new discriminant
8573 -- can share storage with an existing discriminant.]
8575 -- For the derived type each discriminant of the parent type is either
8576 -- inherited, constrained to equal some new discriminant of the derived
8577 -- type, or constrained to the value of an expression.
8579 -- When inherited or constrained to equal some new discriminant, the
8580 -- parent discriminant and the discriminant of the derived type are said
8583 -- If a discriminant of the parent type is constrained to a specific value
8584 -- in the derived type definition, then the discriminant is said to be
8585 -- "specified" by that derived type definition.
8587 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
8589 -- We have spoken about stored discriminants in point 1 (introduction)
8590 -- above. There are two sorts of stored discriminants: implicit and
8591 -- explicit. As long as the derived type inherits the same discriminants as
8592 -- the root record type, stored discriminants are the same as regular
8593 -- discriminants, and are said to be implicit. However, if any discriminant
8594 -- in the root type was renamed in the derived type, then the derived
8595 -- type will contain explicit stored discriminants. Explicit stored
8596 -- discriminants are discriminants in addition to the semantically visible
8597 -- discriminants defined for the derived type. Stored discriminants are
8598 -- used by Gigi to figure out what are the physical discriminants in
8599 -- objects of the derived type (see precise definition in einfo.ads).
8600 -- As an example, consider the following:
8602 -- type R (D1, D2, D3 : Int) is record ... end record;
8603 -- type T1 is new R;
8604 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
8605 -- type T3 is new T2;
8606 -- type T4 (Y : Int) is new T3 (Y, 99);
8608 -- The following table summarizes the discriminants and stored
8609 -- discriminants in R and T1 through T4:
8611 -- Type Discrim Stored Discrim Comment
8612 -- R (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in R
8613 -- T1 (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in T1
8614 -- T2 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T2
8615 -- T3 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T3
8616 -- T4 (Y) (D1, D2, D3) Stored discrims EXPLICIT in T4
8618 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
8619 -- find the corresponding discriminant in the parent type, while
8620 -- Original_Record_Component (abbreviated ORC below) the actual physical
8621 -- component that is renamed. Finally the field Is_Completely_Hidden
8622 -- (abbreviated ICH below) is set for all explicit stored discriminants
8623 -- (see einfo.ads for more info). For the above example this gives:
8625 -- Discrim CD ORC ICH
8626 -- ^^^^^^^ ^^ ^^^ ^^^
8627 -- D1 in R empty itself no
8628 -- D2 in R empty itself no
8629 -- D3 in R empty itself no
8631 -- D1 in T1 D1 in R itself no
8632 -- D2 in T1 D2 in R itself no
8633 -- D3 in T1 D3 in R itself no
8635 -- X1 in T2 D3 in T1 D3 in T2 no
8636 -- X2 in T2 D1 in T1 D1 in T2 no
8637 -- D1 in T2 empty itself yes
8638 -- D2 in T2 empty itself yes
8639 -- D3 in T2 empty itself yes
8641 -- X1 in T3 X1 in T2 D3 in T3 no
8642 -- X2 in T3 X2 in T2 D1 in T3 no
8643 -- D1 in T3 empty itself yes
8644 -- D2 in T3 empty itself yes
8645 -- D3 in T3 empty itself yes
8647 -- Y in T4 X1 in T3 D3 in T4 no
8648 -- D1 in T4 empty itself yes
8649 -- D2 in T4 empty itself yes
8650 -- D3 in T4 empty itself yes
8652 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
8654 -- Type derivation for tagged types is fairly straightforward. If no
8655 -- discriminants are specified by the derived type, these are inherited
8656 -- from the parent. No explicit stored discriminants are ever necessary.
8657 -- The only manipulation that is done to the tree is that of adding a
8658 -- _parent field with parent type and constrained to the same constraint
8659 -- specified for the parent in the derived type definition. For instance:
8661 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
8662 -- type T1 is new R with null record;
8663 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
8665 -- are changed into:
8667 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
8668 -- _parent : R (D1, D2, D3);
8671 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
8672 -- _parent : T1 (X2, 88, X1);
8675 -- The discriminants actually present in R, T1 and T2 as well as their CD,
8676 -- ORC and ICH fields are:
8678 -- Discrim CD ORC ICH
8679 -- ^^^^^^^ ^^ ^^^ ^^^
8680 -- D1 in R empty itself no
8681 -- D2 in R empty itself no
8682 -- D3 in R empty itself no
8684 -- D1 in T1 D1 in R D1 in R no
8685 -- D2 in T1 D2 in R D2 in R no
8686 -- D3 in T1 D3 in R D3 in R no
8688 -- X1 in T2 D3 in T1 D3 in R no
8689 -- X2 in T2 D1 in T1 D1 in R no
8691 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
8693 -- Regardless of whether we dealing with a tagged or untagged type
8694 -- we will transform all derived type declarations of the form
8696 -- type T is new R (...) [with ...];
8698 -- subtype S is R (...);
8699 -- type T is new S [with ...];
8701 -- type BT is new R [with ...];
8702 -- subtype T is BT (...);
8704 -- That is, the base derived type is constrained only if it has no
8705 -- discriminants. The reason for doing this is that GNAT's semantic model
8706 -- assumes that a base type with discriminants is unconstrained.
8708 -- Note that, strictly speaking, the above transformation is not always
8709 -- correct. Consider for instance the following excerpt from ACVC b34011a:
8711 -- procedure B34011A is
8712 -- type REC (D : integer := 0) is record
8717 -- type T6 is new Rec;
8718 -- function F return T6;
8723 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
8726 -- The definition of Q6.U is illegal. However transforming Q6.U into
8728 -- type BaseU is new T6;
8729 -- subtype U is BaseU (Q6.F.I)
8731 -- turns U into a legal subtype, which is incorrect. To avoid this problem
8732 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
8733 -- the transformation described above.
8735 -- There is another instance where the above transformation is incorrect.
8739 -- type Base (D : Integer) is tagged null record;
8740 -- procedure P (X : Base);
8742 -- type Der is new Base (2) with null record;
8743 -- procedure P (X : Der);
8746 -- Then the above transformation turns this into
8748 -- type Der_Base is new Base with null record;
8749 -- -- procedure P (X : Base) is implicitly inherited here
8750 -- -- as procedure P (X : Der_Base).
8752 -- subtype Der is Der_Base (2);
8753 -- procedure P (X : Der);
8754 -- -- The overriding of P (X : Der_Base) is illegal since we
8755 -- -- have a parameter conformance problem.
8757 -- To get around this problem, after having semantically processed Der_Base
8758 -- and the rewritten subtype declaration for Der, we copy Der_Base field
8759 -- Discriminant_Constraint from Der so that when parameter conformance is
8760 -- checked when P is overridden, no semantic errors are flagged.
8762 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
8764 -- Regardless of whether we are dealing with a tagged or untagged type
8765 -- we will transform all derived type declarations of the form
8767 -- type R (D1, .., Dn : ...) is [tagged] record ...;
8768 -- type T is new R [with ...];
8770 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
8772 -- The reason for such transformation is that it allows us to implement a
8773 -- very clean form of component inheritance as explained below.
8775 -- Note that this transformation is not achieved by direct tree rewriting
8776 -- and manipulation, but rather by redoing the semantic actions that the
8777 -- above transformation will entail. This is done directly in routine
8778 -- Inherit_Components.
8780 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
8782 -- In both tagged and untagged derived types, regular non discriminant
8783 -- components are inherited in the derived type from the parent type. In
8784 -- the absence of discriminants component, inheritance is straightforward
8785 -- as components can simply be copied from the parent.
8787 -- If the parent has discriminants, inheriting components constrained with
8788 -- these discriminants requires caution. Consider the following example:
8790 -- type R (D1, D2 : Positive) is [tagged] record
8791 -- S : String (D1 .. D2);
8794 -- type T1 is new R [with null record];
8795 -- type T2 (X : positive) is new R (1, X) [with null record];
8797 -- As explained in 6. above, T1 is rewritten as
8798 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
8799 -- which makes the treatment for T1 and T2 identical.
8801 -- What we want when inheriting S, is that references to D1 and D2 in R are
8802 -- replaced with references to their correct constraints, i.e. D1 and D2 in
8803 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
8804 -- with either discriminant references in the derived type or expressions.
8805 -- This replacement is achieved as follows: before inheriting R's
8806 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
8807 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
8808 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
8809 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
8810 -- by String (1 .. X).
8812 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
8814 -- We explain here the rules governing private type extensions relevant to
8815 -- type derivation. These rules are explained on the following example:
8817 -- type D [(...)] is new A [(...)] with private; <-- partial view
8818 -- type D [(...)] is new P [(...)] with null record; <-- full view
8820 -- Type A is called the ancestor subtype of the private extension.
8821 -- Type P is the parent type of the full view of the private extension. It
8822 -- must be A or a type derived from A.
8824 -- The rules concerning the discriminants of private type extensions are
8827 -- o If a private extension inherits known discriminants from the ancestor
8828 -- subtype, then the full view must also inherit its discriminants from
8829 -- the ancestor subtype and the parent subtype of the full view must be
8830 -- constrained if and only if the ancestor subtype is constrained.
8832 -- o If a partial view has unknown discriminants, then the full view may
8833 -- define a definite or an indefinite subtype, with or without
8836 -- o If a partial view has neither known nor unknown discriminants, then
8837 -- the full view must define a definite subtype.
8839 -- o If the ancestor subtype of a private extension has constrained
8840 -- discriminants, then the parent subtype of the full view must impose a
8841 -- statically matching constraint on those discriminants.
8843 -- This means that only the following forms of private extensions are
8846 -- type D is new A with private; <-- partial view
8847 -- type D is new P with null record; <-- full view
8849 -- If A has no discriminants than P has no discriminants, otherwise P must
8850 -- inherit A's discriminants.
8852 -- type D is new A (...) with private; <-- partial view
8853 -- type D is new P (:::) with null record; <-- full view
8855 -- P must inherit A's discriminants and (...) and (:::) must statically
8858 -- subtype A is R (...);
8859 -- type D is new A with private; <-- partial view
8860 -- type D is new P with null record; <-- full view
8862 -- P must have inherited R's discriminants and must be derived from A or
8863 -- any of its subtypes.
8865 -- type D (..) is new A with private; <-- partial view
8866 -- type D (..) is new P [(:::)] with null record; <-- full view
8868 -- No specific constraints on P's discriminants or constraint (:::).
8869 -- Note that A can be unconstrained, but the parent subtype P must either
8870 -- be constrained or (:::) must be present.
8872 -- type D (..) is new A [(...)] with private; <-- partial view
8873 -- type D (..) is new P [(:::)] with null record; <-- full view
8875 -- P's constraints on A's discriminants must statically match those
8876 -- imposed by (...).
8878 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
8880 -- The full view of a private extension is handled exactly as described
8881 -- above. The model chose for the private view of a private extension is
8882 -- the same for what concerns discriminants (i.e. they receive the same
8883 -- treatment as in the tagged case). However, the private view of the
8884 -- private extension always inherits the components of the parent base,
8885 -- without replacing any discriminant reference. Strictly speaking this is
8886 -- incorrect. However, Gigi never uses this view to generate code so this
8887 -- is a purely semantic issue. In theory, a set of transformations similar
8888 -- to those given in 5. and 6. above could be applied to private views of
8889 -- private extensions to have the same model of component inheritance as
8890 -- for non private extensions. However, this is not done because it would
8891 -- further complicate private type processing. Semantically speaking, this
8892 -- leaves us in an uncomfortable situation. As an example consider:
8895 -- type R (D : integer) is tagged record
8896 -- S : String (1 .. D);
8898 -- procedure P (X : R);
8899 -- type T is new R (1) with private;
8901 -- type T is new R (1) with null record;
8904 -- This is transformed into:
8907 -- type R (D : integer) is tagged record
8908 -- S : String (1 .. D);
8910 -- procedure P (X : R);
8911 -- type T is new R (1) with private;
8913 -- type BaseT is new R with null record;
8914 -- subtype T is BaseT (1);
8917 -- (strictly speaking the above is incorrect Ada)
8919 -- From the semantic standpoint the private view of private extension T
8920 -- should be flagged as constrained since one can clearly have
8924 -- in a unit withing Pack. However, when deriving subprograms for the
8925 -- private view of private extension T, T must be seen as unconstrained
8926 -- since T has discriminants (this is a constraint of the current
8927 -- subprogram derivation model). Thus, when processing the private view of
8928 -- a private extension such as T, we first mark T as unconstrained, we
8929 -- process it, we perform program derivation and just before returning from
8930 -- Build_Derived_Record_Type we mark T as constrained.
8932 -- ??? Are there are other uncomfortable cases that we will have to
8935 -- 10. RECORD_TYPE_WITH_PRIVATE complications
8937 -- Types that are derived from a visible record type and have a private
8938 -- extension present other peculiarities. They behave mostly like private
8939 -- types, but if they have primitive operations defined, these will not
8940 -- have the proper signatures for further inheritance, because other
8941 -- primitive operations will use the implicit base that we define for
8942 -- private derivations below. This affect subprogram inheritance (see
8943 -- Derive_Subprograms for details). We also derive the implicit base from
8944 -- the base type of the full view, so that the implicit base is a record
8945 -- type and not another private type, This avoids infinite loops.
8947 procedure Build_Derived_Record_Type
8949 Parent_Type
: Entity_Id
;
8950 Derived_Type
: Entity_Id
;
8951 Derive_Subps
: Boolean := True)
8953 Discriminant_Specs
: constant Boolean :=
8954 Present
(Discriminant_Specifications
(N
));
8955 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
8956 Loc
: constant Source_Ptr
:= Sloc
(N
);
8957 Private_Extension
: constant Boolean :=
8958 Nkind
(N
) = N_Private_Extension_Declaration
;
8959 Assoc_List
: Elist_Id
;
8960 Constraint_Present
: Boolean;
8962 Discrim
: Entity_Id
;
8964 Inherit_Discrims
: Boolean := False;
8965 Last_Discrim
: Entity_Id
;
8966 New_Base
: Entity_Id
;
8968 New_Discrs
: Elist_Id
;
8969 New_Indic
: Node_Id
;
8970 Parent_Base
: Entity_Id
;
8971 Save_Etype
: Entity_Id
;
8972 Save_Discr_Constr
: Elist_Id
;
8973 Save_Next_Entity
: Entity_Id
;
8976 Discs
: Elist_Id
:= New_Elmt_List
;
8977 -- An empty Discs list means that there were no constraints in the
8978 -- subtype indication or that there was an error processing it.
8980 procedure Check_Generic_Ancestors
;
8981 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
8982 -- cannot be declared at a deeper level than its parent type is
8983 -- removed. The check on derivation within a generic body is also
8984 -- relaxed, but there's a restriction that a derived tagged type
8985 -- cannot be declared in a generic body if it's derived directly
8986 -- or indirectly from a formal type of that generic. This applies
8987 -- to progenitors as well.
8989 -----------------------------
8990 -- Check_Generic_Ancestors --
8991 -----------------------------
8993 procedure Check_Generic_Ancestors
is
8994 Ancestor_Type
: Entity_Id
;
8995 Intf_List
: List_Id
;
8996 Intf_Name
: Node_Id
;
8998 procedure Check_Ancestor
;
8999 -- For parent and progenitors.
9001 --------------------
9002 -- Check_Ancestor --
9003 --------------------
9005 procedure Check_Ancestor
is
9007 -- If the derived type does have a formal type as an ancestor
9008 -- then it's an error if the derived type is declared within
9009 -- the body of the generic unit that declares the formal type
9010 -- in its generic formal part. It's sufficient to check whether
9011 -- the ancestor type is declared inside the same generic body
9012 -- as the derived type (such as within a nested generic spec),
9013 -- in which case the derivation is legal. If the formal type is
9014 -- declared outside of that generic body, then it's certain
9015 -- that the derived type is declared within the generic body
9016 -- of the generic unit declaring the formal type.
9018 if Is_Generic_Type
(Ancestor_Type
)
9019 and then Enclosing_Generic_Body
(Ancestor_Type
) /=
9020 Enclosing_Generic_Body
(Derived_Type
)
9023 ("ancestor type& is formal type of enclosing"
9024 & " generic unit (RM 3.9.1 (4/2))",
9025 Indic
, Ancestor_Type
);
9030 if Nkind
(N
) = N_Private_Extension_Declaration
then
9031 Intf_List
:= Interface_List
(N
);
9033 Intf_List
:= Interface_List
(Type_Definition
(N
));
9036 if Present
(Enclosing_Generic_Body
(Derived_Type
)) then
9037 Ancestor_Type
:= Parent_Type
;
9039 while not Is_Generic_Type
(Ancestor_Type
)
9040 and then Etype
(Ancestor_Type
) /= Ancestor_Type
9042 Ancestor_Type
:= Etype
(Ancestor_Type
);
9047 if Present
(Intf_List
) then
9048 Intf_Name
:= First
(Intf_List
);
9049 while Present
(Intf_Name
) loop
9050 Ancestor_Type
:= Entity
(Intf_Name
);
9056 end Check_Generic_Ancestors
;
9058 -- Start of processing for Build_Derived_Record_Type
9061 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
9062 and then Present
(Full_View
(Parent_Type
))
9063 and then Has_Discriminants
(Parent_Type
)
9065 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
9067 Parent_Base
:= Base_Type
(Parent_Type
);
9070 -- If the parent type is declared as a subtype of another private
9071 -- type with inherited discriminants, its generated base type is
9072 -- itself a record subtype. To further inherit the constraint we
9073 -- need to use its own base to have an unconstrained type on which
9074 -- to apply the inherited constraint.
9076 if Ekind
(Parent_Base
) = E_Record_Subtype
then
9077 Parent_Base
:= Base_Type
(Parent_Base
);
9080 -- AI05-0115: if this is a derivation from a private type in some
9081 -- other scope that may lead to invisible components for the derived
9082 -- type, mark it accordingly.
9084 if Is_Private_Type
(Parent_Type
) then
9085 if Scope
(Parent_Base
) = Scope
(Derived_Type
) then
9088 elsif In_Open_Scopes
(Scope
(Parent_Base
))
9089 and then In_Private_Part
(Scope
(Parent_Base
))
9094 Set_Has_Private_Ancestor
(Derived_Type
);
9098 Set_Has_Private_Ancestor
9099 (Derived_Type
, Has_Private_Ancestor
(Parent_Type
));
9102 -- Before we start the previously documented transformations, here is
9103 -- little fix for size and alignment of tagged types. Normally when we
9104 -- derive type D from type P, we copy the size and alignment of P as the
9105 -- default for D, and in the absence of explicit representation clauses
9106 -- for D, the size and alignment are indeed the same as the parent.
9108 -- But this is wrong for tagged types, since fields may be added, and
9109 -- the default size may need to be larger, and the default alignment may
9110 -- need to be larger.
9112 -- We therefore reset the size and alignment fields in the tagged case.
9113 -- Note that the size and alignment will in any case be at least as
9114 -- large as the parent type (since the derived type has a copy of the
9115 -- parent type in the _parent field)
9117 -- The type is also marked as being tagged here, which is needed when
9118 -- processing components with a self-referential anonymous access type
9119 -- in the call to Check_Anonymous_Access_Components below. Note that
9120 -- this flag is also set later on for completeness.
9123 Set_Is_Tagged_Type
(Derived_Type
);
9124 Reinit_Size_Align
(Derived_Type
);
9127 -- STEP 0a: figure out what kind of derived type declaration we have
9129 if Private_Extension
then
9131 Mutate_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
9132 Set_Default_SSO
(Derived_Type
);
9133 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9136 Type_Def
:= Type_Definition
(N
);
9138 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
9139 -- Parent_Base can be a private type or private extension. However,
9140 -- for tagged types with an extension the newly added fields are
9141 -- visible and hence the Derived_Type is always an E_Record_Type.
9142 -- (except that the parent may have its own private fields).
9143 -- For untagged types we preserve the Ekind of the Parent_Base.
9145 if Present
(Record_Extension_Part
(Type_Def
)) then
9146 Mutate_Ekind
(Derived_Type
, E_Record_Type
);
9147 Set_Default_SSO
(Derived_Type
);
9148 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9150 -- Create internal access types for components with anonymous
9153 if Ada_Version
>= Ada_2005
then
9154 Check_Anonymous_Access_Components
9155 (N
, Derived_Type
, Derived_Type
,
9156 Component_List
(Record_Extension_Part
(Type_Def
)));
9160 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
9164 -- Indic can either be an N_Identifier if the subtype indication
9165 -- contains no constraint or an N_Subtype_Indication if the subtype
9166 -- indication has a constraint. In either case it can include an
9169 Indic
:= Subtype_Indication
(Type_Def
);
9170 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
9172 -- Check that the type has visible discriminants. The type may be
9173 -- a private type with unknown discriminants whose full view has
9174 -- discriminants which are invisible.
9176 if Constraint_Present
then
9177 if not Has_Discriminants
(Parent_Base
)
9179 (Has_Unknown_Discriminants
(Parent_Base
)
9180 and then Is_Private_Type
(Parent_Base
))
9183 ("invalid constraint: type has no discriminant",
9184 Constraint
(Indic
));
9186 Constraint_Present
:= False;
9187 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9189 elsif Is_Constrained
(Parent_Type
) then
9191 ("invalid constraint: parent type is already constrained",
9192 Constraint
(Indic
));
9194 Constraint_Present
:= False;
9195 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9199 -- STEP 0b: If needed, apply transformation given in point 5. above
9201 if not Private_Extension
9202 and then Has_Discriminants
(Parent_Type
)
9203 and then not Discriminant_Specs
9204 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
9206 -- First, we must analyze the constraint (see comment in point 5.)
9207 -- The constraint may come from the subtype indication of the full
9210 if Constraint_Present
then
9211 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9213 -- If there is no explicit constraint, there might be one that is
9214 -- inherited from a constrained parent type. In that case verify that
9215 -- it conforms to the constraint in the partial view. In perverse
9216 -- cases the parent subtypes of the partial and full view can have
9217 -- different constraints.
9219 elsif Present
(Stored_Constraint
(Parent_Type
)) then
9220 New_Discrs
:= Stored_Constraint
(Parent_Type
);
9223 New_Discrs
:= No_Elist
;
9226 if Has_Discriminants
(Derived_Type
)
9227 and then Has_Private_Declaration
(Derived_Type
)
9228 and then Present
(Discriminant_Constraint
(Derived_Type
))
9229 and then Present
(New_Discrs
)
9231 -- Verify that constraints of the full view statically match
9232 -- those given in the partial view.
9238 C1
:= First_Elmt
(New_Discrs
);
9239 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
9240 while Present
(C1
) and then Present
(C2
) loop
9241 if Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9243 (Is_OK_Static_Expression
(Node
(C1
))
9244 and then Is_OK_Static_Expression
(Node
(C2
))
9246 Expr_Value
(Node
(C1
)) = Expr_Value
(Node
(C2
)))
9251 if Constraint_Present
then
9253 ("constraint not conformant to previous declaration",
9257 ("constraint of full view is incompatible "
9258 & "with partial view", N
);
9268 -- Insert and analyze the declaration for the unconstrained base type
9270 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
9273 Make_Full_Type_Declaration
(Loc
,
9274 Defining_Identifier
=> New_Base
,
9276 Make_Derived_Type_Definition
(Loc
,
9277 Abstract_Present
=> Abstract_Present
(Type_Def
),
9278 Limited_Present
=> Limited_Present
(Type_Def
),
9279 Subtype_Indication
=>
9280 New_Occurrence_Of
(Parent_Base
, Loc
),
9281 Record_Extension_Part
=>
9282 Relocate_Node
(Record_Extension_Part
(Type_Def
)),
9283 Interface_List
=> Interface_List
(Type_Def
)));
9285 Set_Parent
(New_Decl
, Parent
(N
));
9286 Mark_Rewrite_Insertion
(New_Decl
);
9287 Insert_Before
(N
, New_Decl
);
9289 -- In the extension case, make sure ancestor is frozen appropriately
9290 -- (see also non-discriminated case below).
9292 if Present
(Record_Extension_Part
(Type_Def
))
9293 or else Is_Interface
(Parent_Base
)
9295 Freeze_Before
(New_Decl
, Parent_Type
);
9298 -- Note that this call passes False for the Derive_Subps parameter
9299 -- because subprogram derivation is deferred until after creating
9300 -- the subtype (see below).
9303 (New_Decl
, Parent_Base
, New_Base
,
9304 Is_Completion
=> False, Derive_Subps
=> False);
9306 -- ??? This needs re-examination to determine whether the
9307 -- above call can simply be replaced by a call to Analyze.
9309 Set_Analyzed
(New_Decl
);
9311 -- Insert and analyze the declaration for the constrained subtype
9313 if Constraint_Present
then
9315 Make_Subtype_Indication
(Loc
,
9316 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9317 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
9321 Constr_List
: constant List_Id
:= New_List
;
9326 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
9327 while Present
(C
) loop
9330 -- It is safe here to call New_Copy_Tree since we called
9331 -- Force_Evaluation on each constraint previously
9332 -- in Build_Discriminant_Constraints.
9334 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
9340 Make_Subtype_Indication
(Loc
,
9341 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9343 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
9348 Make_Subtype_Declaration
(Loc
,
9349 Defining_Identifier
=> Derived_Type
,
9350 Subtype_Indication
=> New_Indic
));
9354 -- Derivation of subprograms must be delayed until the full subtype
9355 -- has been established, to ensure proper overriding of subprograms
9356 -- inherited by full types. If the derivations occurred as part of
9357 -- the call to Build_Derived_Type above, then the check for type
9358 -- conformance would fail because earlier primitive subprograms
9359 -- could still refer to the full type prior the change to the new
9360 -- subtype and hence would not match the new base type created here.
9361 -- Subprograms are not derived, however, when Derive_Subps is False
9362 -- (since otherwise there could be redundant derivations).
9364 if Derive_Subps
then
9365 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9368 -- For tagged types the Discriminant_Constraint of the new base itype
9369 -- is inherited from the first subtype so that no subtype conformance
9370 -- problem arise when the first subtype overrides primitive
9371 -- operations inherited by the implicit base type.
9374 Set_Discriminant_Constraint
9375 (New_Base
, Discriminant_Constraint
(Derived_Type
));
9381 -- If we get here Derived_Type will have no discriminants or it will be
9382 -- a discriminated unconstrained base type.
9384 -- STEP 1a: perform preliminary actions/checks for derived tagged types
9388 -- The parent type is frozen for non-private extensions (RM 13.14(7))
9389 -- The declaration of a specific descendant of an interface type
9390 -- freezes the interface type (RM 13.14).
9392 if not Private_Extension
or else Is_Interface
(Parent_Base
) then
9393 Freeze_Before
(N
, Parent_Type
);
9396 if Ada_Version
>= Ada_2005
then
9397 Check_Generic_Ancestors
;
9399 elsif Type_Access_Level
(Derived_Type
) /=
9400 Type_Access_Level
(Parent_Type
)
9401 and then not Is_Generic_Type
(Derived_Type
)
9403 if Is_Controlled
(Parent_Type
) then
9405 ("controlled type must be declared at the library level",
9409 ("type extension at deeper accessibility level than parent",
9415 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
9418 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
9421 ("parent type of& must not be outside generic body"
9423 Indic
, Derived_Type
);
9429 -- Ada 2005 (AI-251)
9431 if Ada_Version
>= Ada_2005
and then Is_Tagged
then
9433 -- "The declaration of a specific descendant of an interface type
9434 -- freezes the interface type" (RM 13.14).
9439 Iface
:= First
(Interface_List
(Type_Def
));
9440 while Present
(Iface
) loop
9441 Freeze_Before
(N
, Etype
(Iface
));
9447 -- STEP 1b : preliminary cleanup of the full view of private types
9449 -- If the type is already marked as having discriminants, then it's the
9450 -- completion of a private type or private extension and we need to
9451 -- retain the discriminants from the partial view if the current
9452 -- declaration has Discriminant_Specifications so that we can verify
9453 -- conformance. However, we must remove any existing components that
9454 -- were inherited from the parent (and attached in Copy_And_Swap)
9455 -- because the full type inherits all appropriate components anyway, and
9456 -- we do not want the partial view's components interfering.
9458 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
9459 Discrim
:= First_Discriminant
(Derived_Type
);
9461 Last_Discrim
:= Discrim
;
9462 Next_Discriminant
(Discrim
);
9463 exit when No
(Discrim
);
9466 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
9468 -- In all other cases wipe out the list of inherited components (even
9469 -- inherited discriminants), it will be properly rebuilt here.
9472 Set_First_Entity
(Derived_Type
, Empty
);
9473 Set_Last_Entity
(Derived_Type
, Empty
);
9476 -- STEP 1c: Initialize some flags for the Derived_Type
9478 -- The following flags must be initialized here so that
9479 -- Process_Discriminants can check that discriminants of tagged types do
9480 -- not have a default initial value and that access discriminants are
9481 -- only specified for limited records. For completeness, these flags are
9482 -- also initialized along with all the other flags below.
9484 -- AI-419: Limitedness is not inherited from an interface parent, so to
9485 -- be limited in that case the type must be explicitly declared as
9486 -- limited. However, task and protected interfaces are always limited.
9488 if Limited_Present
(Type_Def
) then
9489 Set_Is_Limited_Record
(Derived_Type
);
9491 elsif Is_Limited_Record
(Parent_Type
)
9492 or else (Present
(Full_View
(Parent_Type
))
9493 and then Is_Limited_Record
(Full_View
(Parent_Type
)))
9495 if not Is_Interface
(Parent_Type
)
9496 or else Is_Concurrent_Interface
(Parent_Type
)
9498 Set_Is_Limited_Record
(Derived_Type
);
9502 -- STEP 2a: process discriminants of derived type if any
9504 Push_Scope
(Derived_Type
);
9506 if Discriminant_Specs
then
9507 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
9509 -- The following call initializes fields Has_Discriminants and
9510 -- Discriminant_Constraint, unless we are processing the completion
9511 -- of a private type declaration.
9513 Check_Or_Process_Discriminants
(N
, Derived_Type
);
9515 -- For untagged types, the constraint on the Parent_Type must be
9516 -- present and is used to rename the discriminants.
9518 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
9519 Error_Msg_N
("untagged parent must have discriminants", Indic
);
9521 elsif not Is_Tagged
and then not Constraint_Present
then
9523 ("discriminant constraint needed for derived untagged records",
9526 -- Otherwise the parent subtype must be constrained unless we have a
9527 -- private extension.
9529 elsif not Constraint_Present
9530 and then not Private_Extension
9531 and then not Is_Constrained
(Parent_Type
)
9534 ("unconstrained type not allowed in this context", Indic
);
9536 elsif Constraint_Present
then
9537 -- The following call sets the field Corresponding_Discriminant
9538 -- for the discriminants in the Derived_Type.
9540 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
9542 -- For untagged types all new discriminants must rename
9543 -- discriminants in the parent. For private extensions new
9544 -- discriminants cannot rename old ones (implied by [7.3(13)]).
9546 Discrim
:= First_Discriminant
(Derived_Type
);
9547 while Present
(Discrim
) loop
9549 and then No
(Corresponding_Discriminant
(Discrim
))
9552 ("new discriminants must constrain old ones", Discrim
);
9554 elsif Private_Extension
9555 and then Present
(Corresponding_Discriminant
(Discrim
))
9558 ("only static constraints allowed for parent"
9559 & " discriminants in the partial view", Indic
);
9563 -- If a new discriminant is used in the constraint, then its
9564 -- subtype must be statically compatible with the subtype of
9565 -- the parent discriminant (RM 3.7(15)).
9567 if Present
(Corresponding_Discriminant
(Discrim
)) then
9568 Check_Constraining_Discriminant
9569 (Discrim
, Corresponding_Discriminant
(Discrim
));
9572 Next_Discriminant
(Discrim
);
9575 -- Check whether the constraints of the full view statically
9576 -- match those imposed by the parent subtype [7.3(13)].
9578 if Present
(Stored_Constraint
(Derived_Type
)) then
9583 C1
:= First_Elmt
(Discs
);
9584 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
9585 while Present
(C1
) and then Present
(C2
) loop
9587 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9590 ("not conformant with previous declaration",
9601 -- STEP 2b: No new discriminants, inherit discriminants if any
9604 if Private_Extension
then
9605 Set_Has_Unknown_Discriminants
9607 Has_Unknown_Discriminants
(Parent_Type
)
9608 or else Unknown_Discriminants_Present
(N
));
9610 -- The partial view of the parent may have unknown discriminants,
9611 -- but if the full view has discriminants and the parent type is
9612 -- in scope they must be inherited.
9614 elsif Has_Unknown_Discriminants
(Parent_Type
)
9616 (not Has_Discriminants
(Parent_Type
)
9617 or else not In_Open_Scopes
(Scope
(Parent_Base
)))
9619 Set_Has_Unknown_Discriminants
(Derived_Type
);
9622 if not Has_Unknown_Discriminants
(Derived_Type
)
9623 and then not Has_Unknown_Discriminants
(Parent_Base
)
9624 and then Has_Discriminants
(Parent_Type
)
9626 Inherit_Discrims
:= True;
9627 Set_Has_Discriminants
9628 (Derived_Type
, True);
9629 Set_Discriminant_Constraint
9630 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
9633 -- The following test is true for private types (remember
9634 -- transformation 5. is not applied to those) and in an error
9637 if Constraint_Present
then
9638 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9641 -- For now mark a new derived type as constrained only if it has no
9642 -- discriminants. At the end of Build_Derived_Record_Type we properly
9643 -- set this flag in the case of private extensions. See comments in
9644 -- point 9. just before body of Build_Derived_Record_Type.
9648 not (Inherit_Discrims
9649 or else Has_Unknown_Discriminants
(Derived_Type
)));
9652 -- STEP 3: initialize fields of derived type
9654 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
9655 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
9657 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
9658 -- but cannot be interfaces
9660 if not Private_Extension
9661 and then Ekind
(Derived_Type
) /= E_Private_Type
9662 and then Ekind
(Derived_Type
) /= E_Limited_Private_Type
9664 if Interface_Present
(Type_Def
) then
9665 Analyze_Interface_Declaration
(Derived_Type
, Type_Def
);
9668 Set_Interfaces
(Derived_Type
, No_Elist
);
9671 -- Fields inherited from the Parent_Type
9673 Set_Has_Specified_Layout
9674 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
9675 Set_Is_Limited_Composite
9676 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
9677 Set_Is_Private_Composite
9678 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
9680 if Is_Tagged_Type
(Parent_Type
) then
9681 Set_No_Tagged_Streams_Pragma
9682 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
9685 -- Fields inherited from the Parent_Base
9687 Set_Has_Controlled_Component
9688 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
9689 Set_Has_Non_Standard_Rep
9690 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
9691 Set_Has_Primitive_Operations
9692 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
9694 -- Set fields for private derived types
9696 if Is_Private_Type
(Derived_Type
) then
9697 Set_Depends_On_Private
(Derived_Type
, True);
9698 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
9701 -- Inherit fields for non-private types. If this is the completion of a
9702 -- derivation from a private type, the parent itself is private and the
9703 -- attributes come from its full view, which must be present.
9705 if Is_Record_Type
(Derived_Type
) then
9707 Parent_Full
: Entity_Id
;
9710 if Is_Private_Type
(Parent_Base
)
9711 and then not Is_Record_Type
(Parent_Base
)
9713 Parent_Full
:= Full_View
(Parent_Base
);
9715 Parent_Full
:= Parent_Base
;
9718 Set_Component_Alignment
9719 (Derived_Type
, Component_Alignment
(Parent_Full
));
9721 (Derived_Type
, C_Pass_By_Copy
(Parent_Full
));
9722 Set_Has_Complex_Representation
9723 (Derived_Type
, Has_Complex_Representation
(Parent_Full
));
9725 -- For untagged types, inherit the layout by default to avoid
9726 -- costly changes of representation for type conversions.
9728 if not Is_Tagged
then
9729 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Full
));
9730 Set_No_Reordering
(Derived_Type
, No_Reordering
(Parent_Full
));
9735 -- Initialize the list of primitive operations to an empty list,
9736 -- to cover tagged types as well as untagged types. For untagged
9737 -- types this is used either to analyze the call as legal when
9738 -- Extensions_Allowed is True, or to issue a better error message
9741 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
9743 -- Set fields for tagged types
9746 -- All tagged types defined in Ada.Finalization are controlled
9748 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
9749 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
9750 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
9752 Set_Is_Controlled_Active
(Derived_Type
);
9754 Set_Is_Controlled_Active
9755 (Derived_Type
, Is_Controlled_Active
(Parent_Base
));
9758 -- Minor optimization: there is no need to generate the class-wide
9759 -- entity associated with an underlying record view.
9761 if not Is_Underlying_Record_View
(Derived_Type
) then
9762 Make_Class_Wide_Type
(Derived_Type
);
9765 Set_Is_Abstract_Type
(Derived_Type
, Abstract_Present
(Type_Def
));
9767 if Has_Discriminants
(Derived_Type
)
9768 and then Constraint_Present
9770 Set_Stored_Constraint
9771 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
9774 if Ada_Version
>= Ada_2005
then
9776 Ifaces_List
: Elist_Id
;
9779 -- Checks rules 3.9.4 (13/2 and 14/2)
9781 if Comes_From_Source
(Derived_Type
)
9782 and then not Is_Private_Type
(Derived_Type
)
9783 and then Is_Interface
(Parent_Type
)
9784 and then not Is_Interface
(Derived_Type
)
9786 if Is_Task_Interface
(Parent_Type
) then
9788 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
9791 elsif Is_Protected_Interface
(Parent_Type
) then
9793 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
9798 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
9800 Check_Interfaces
(N
, Type_Def
);
9802 -- Ada 2005 (AI-251): Collect the list of progenitors that are
9803 -- not already in the parents.
9807 Ifaces_List
=> Ifaces_List
,
9808 Exclude_Parents
=> True);
9810 Set_Interfaces
(Derived_Type
, Ifaces_List
);
9812 -- If the derived type is the anonymous type created for
9813 -- a declaration whose parent has a constraint, propagate
9814 -- the interface list to the source type. This must be done
9815 -- prior to the completion of the analysis of the source type
9816 -- because the components in the extension may contain current
9817 -- instances whose legality depends on some ancestor.
9819 if Is_Itype
(Derived_Type
) then
9821 Def
: constant Node_Id
:=
9822 Associated_Node_For_Itype
(Derived_Type
);
9825 and then Nkind
(Def
) = N_Full_Type_Declaration
9828 (Defining_Identifier
(Def
), Ifaces_List
);
9833 -- A type extension is automatically Ghost when one of its
9834 -- progenitors is Ghost (SPARK RM 6.9(9)). This property is
9835 -- also inherited when the parent type is Ghost, but this is
9836 -- done in Build_Derived_Type as the mechanism also handles
9837 -- untagged derivations.
9839 if Implements_Ghost_Interface
(Derived_Type
) then
9840 Set_Is_Ghost_Entity
(Derived_Type
);
9846 -- STEP 4: Inherit components from the parent base and constrain them.
9847 -- Apply the second transformation described in point 6. above.
9849 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
9850 or else not Has_Discriminants
(Parent_Type
)
9851 or else not Is_Constrained
(Parent_Type
)
9855 Constrs
:= Discriminant_Constraint
(Parent_Type
);
9860 (N
, Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
9862 -- STEP 5a: Copy the parent record declaration for untagged types
9864 Set_Has_Implicit_Dereference
9865 (Derived_Type
, Has_Implicit_Dereference
(Parent_Type
));
9867 if not Is_Tagged
then
9869 -- Discriminant_Constraint (Derived_Type) has been properly
9870 -- constructed. Save it and temporarily set it to Empty because we
9871 -- do not want the call to New_Copy_Tree below to mess this list.
9873 if Has_Discriminants
(Derived_Type
) then
9874 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
9875 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
9877 Save_Discr_Constr
:= No_Elist
;
9880 -- Save the Etype field of Derived_Type. It is correctly set now,
9881 -- but the call to New_Copy tree may remap it to point to itself,
9882 -- which is not what we want. Ditto for the Next_Entity field.
9884 Save_Etype
:= Etype
(Derived_Type
);
9885 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
9887 -- Assoc_List maps all stored discriminants in the Parent_Base to
9888 -- stored discriminants in the Derived_Type. It is fundamental that
9889 -- no types or itypes with discriminants other than the stored
9890 -- discriminants appear in the entities declared inside
9891 -- Derived_Type, since the back end cannot deal with it.
9895 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
9896 Copy_Dimensions_Of_Components
(Derived_Type
);
9898 -- Restore the fields saved prior to the New_Copy_Tree call
9899 -- and compute the stored constraint.
9901 Set_Etype
(Derived_Type
, Save_Etype
);
9902 Link_Entities
(Derived_Type
, Save_Next_Entity
);
9904 if Has_Discriminants
(Derived_Type
) then
9905 Set_Discriminant_Constraint
9906 (Derived_Type
, Save_Discr_Constr
);
9907 Set_Stored_Constraint
9908 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
9910 Replace_Discriminants
(Derived_Type
, New_Decl
);
9913 -- Insert the new derived type declaration
9915 Rewrite
(N
, New_Decl
);
9917 -- STEP 5b: Complete the processing for record extensions in generics
9919 -- There is no completion for record extensions declared in the
9920 -- parameter part of a generic, so we need to complete processing for
9921 -- these generic record extensions here. The Record_Type_Definition call
9922 -- will change the Ekind of the components from E_Void to E_Component.
9924 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
9925 Record_Type_Definition
(Empty
, Derived_Type
);
9927 -- STEP 5c: Process the record extension for non private tagged types
9929 elsif not Private_Extension
then
9930 Expand_Record_Extension
(Derived_Type
, Type_Def
);
9932 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
9933 -- implemented interfaces if we are in expansion mode
9936 and then Has_Interfaces
(Derived_Type
)
9938 Add_Interface_Tag_Components
(N
, Derived_Type
);
9941 -- Analyze the record extension
9943 Record_Type_Definition
9944 (Record_Extension_Part
(Type_Def
), Derived_Type
);
9949 -- Nothing else to do if there is an error in the derivation.
9950 -- An unusual case: the full view may be derived from a type in an
9951 -- instance, when the partial view was used illegally as an actual
9952 -- in that instance, leading to a circular definition.
9954 if Etype
(Derived_Type
) = Any_Type
9955 or else Etype
(Parent_Type
) = Derived_Type
9960 -- Set delayed freeze and then derive subprograms, we need to do
9961 -- this in this order so that derived subprograms inherit the
9962 -- derived freeze if necessary.
9964 Set_Has_Delayed_Freeze
(Derived_Type
);
9966 if Derive_Subps
then
9967 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9970 -- If we have a private extension which defines a constrained derived
9971 -- type mark as constrained here after we have derived subprograms. See
9972 -- comment on point 9. just above the body of Build_Derived_Record_Type.
9974 if Private_Extension
and then Inherit_Discrims
then
9975 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
9976 Set_Is_Constrained
(Derived_Type
, True);
9977 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
9979 elsif Is_Constrained
(Parent_Type
) then
9981 (Derived_Type
, True);
9982 Set_Discriminant_Constraint
9983 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
9987 -- Update the class-wide type, which shares the now-completed entity
9988 -- list with its specific type. In case of underlying record views,
9989 -- we do not generate the corresponding class wide entity.
9992 and then not Is_Underlying_Record_View
(Derived_Type
)
9995 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
9997 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
10000 Check_Function_Writable_Actuals
(N
);
10001 end Build_Derived_Record_Type
;
10003 ------------------------
10004 -- Build_Derived_Type --
10005 ------------------------
10007 procedure Build_Derived_Type
10009 Parent_Type
: Entity_Id
;
10010 Derived_Type
: Entity_Id
;
10011 Is_Completion
: Boolean;
10012 Derive_Subps
: Boolean := True)
10014 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
10017 -- Set common attributes
10019 if Ekind
(Derived_Type
) in Incomplete_Or_Private_Kind
10020 and then Ekind
(Parent_Base
) in Elementary_Kind
10022 Reinit_Field_To_Zero
(Derived_Type
, F_Discriminant_Constraint
);
10025 Set_Scope
(Derived_Type
, Current_Scope
);
10026 Set_Etype
(Derived_Type
, Parent_Base
);
10027 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
10028 Propagate_Concurrent_Flags
(Derived_Type
, Parent_Base
);
10030 Set_Size_Info
(Derived_Type
, Parent_Type
);
10031 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
10033 Set_Is_Controlled_Active
10034 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
10036 Set_Disable_Controlled
(Derived_Type
, Disable_Controlled
(Parent_Type
));
10037 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged_Type
(Parent_Type
));
10038 Set_Is_Volatile
(Derived_Type
, Is_Volatile
(Parent_Type
));
10040 if Is_Tagged_Type
(Derived_Type
) then
10041 Set_No_Tagged_Streams_Pragma
10042 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
10045 -- If the parent has primitive routines and may have not-seen-yet aspect
10046 -- specifications (e.g., a Pack pragma), then set the derived type link
10047 -- in order to later diagnose "early derivation" issues. If in different
10048 -- compilation units, then "early derivation" cannot be an issue (and we
10049 -- don't like interunit references that go in the opposite direction of
10050 -- semantic dependencies).
10052 if Has_Primitive_Operations
(Parent_Type
)
10053 and then Enclosing_Comp_Unit_Node
(Parent_Type
) =
10054 Enclosing_Comp_Unit_Node
(Derived_Type
)
10056 Set_Derived_Type_Link
(Parent_Base
, Derived_Type
);
10059 -- If the parent type is a private subtype, the convention on the base
10060 -- type may be set in the private part, and not propagated to the
10061 -- subtype until later, so we obtain the convention from the base type.
10063 Set_Convention
(Derived_Type
, Convention
(Parent_Base
));
10065 if Is_Tagged_Type
(Derived_Type
)
10066 and then Present
(Class_Wide_Type
(Derived_Type
))
10068 Set_Convention
(Class_Wide_Type
(Derived_Type
),
10069 Convention
(Class_Wide_Type
(Parent_Base
)));
10072 -- Set SSO default for record or array type
10074 if (Is_Array_Type
(Derived_Type
) or else Is_Record_Type
(Derived_Type
))
10075 and then Is_Base_Type
(Derived_Type
)
10077 Set_Default_SSO
(Derived_Type
);
10080 -- A derived type inherits the Default_Initial_Condition pragma coming
10081 -- from any parent type within the derivation chain.
10083 if Has_DIC
(Parent_Type
) then
10084 Set_Has_Inherited_DIC
(Derived_Type
);
10087 -- A derived type inherits any class-wide invariants coming from a
10088 -- parent type or an interface. Note that the invariant procedure of
10089 -- the parent type should not be inherited because the derived type may
10090 -- define invariants of its own.
10092 if not Is_Interface
(Derived_Type
) then
10093 if Has_Inherited_Invariants
(Parent_Type
)
10094 or else Has_Inheritable_Invariants
(Parent_Type
)
10096 Set_Has_Inherited_Invariants
(Derived_Type
);
10098 elsif Is_Concurrent_Type
(Derived_Type
)
10099 or else Is_Tagged_Type
(Derived_Type
)
10104 Iface_Elmt
: Elmt_Id
;
10108 (T
=> Derived_Type
,
10109 Ifaces_List
=> Ifaces
,
10110 Exclude_Parents
=> True);
10112 if Present
(Ifaces
) then
10113 Iface_Elmt
:= First_Elmt
(Ifaces
);
10114 while Present
(Iface_Elmt
) loop
10115 Iface
:= Node
(Iface_Elmt
);
10117 if Has_Inheritable_Invariants
(Iface
) then
10118 Set_Has_Inherited_Invariants
(Derived_Type
);
10122 Next_Elmt
(Iface_Elmt
);
10129 -- We similarly inherit predicates. Note that for scalar derived types
10130 -- the predicate is inherited from the first subtype, and not from its
10131 -- (anonymous) base type.
10133 if Has_Predicates
(Parent_Type
)
10134 or else Has_Predicates
(First_Subtype
(Parent_Type
))
10136 Set_Has_Predicates
(Derived_Type
);
10139 -- The derived type inherits representation clauses from the parent
10140 -- type, and from any interfaces.
10142 Inherit_Rep_Item_Chain
(Derived_Type
, Parent_Type
);
10145 Iface
: Node_Id
:= First
(Abstract_Interface_List
(Derived_Type
));
10147 while Present
(Iface
) loop
10148 Inherit_Rep_Item_Chain
(Derived_Type
, Entity
(Iface
));
10153 -- If the parent type has delayed rep aspects, then mark the derived
10154 -- type as possibly inheriting a delayed rep aspect.
10156 if Has_Delayed_Rep_Aspects
(Parent_Type
) then
10157 Set_May_Inherit_Delayed_Rep_Aspects
(Derived_Type
);
10160 -- A derived type becomes Ghost when its parent type is also Ghost
10161 -- (SPARK RM 6.9(9)). Note that the Ghost-related attributes are not
10162 -- directly inherited because the Ghost policy in effect may differ.
10164 if Is_Ghost_Entity
(Parent_Type
) then
10165 Set_Is_Ghost_Entity
(Derived_Type
);
10168 -- Type dependent processing
10170 case Ekind
(Parent_Type
) is
10171 when Numeric_Kind
=>
10172 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
10175 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
10177 when Class_Wide_Kind
10181 Build_Derived_Record_Type
10182 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
10185 when Enumeration_Kind
=>
10186 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
10188 when Access_Kind
=>
10189 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
10191 when Incomplete_Or_Private_Kind
=>
10192 Build_Derived_Private_Type
10193 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
10195 -- For discriminated types, the derivation includes deriving
10196 -- primitive operations. For others it is done below.
10198 if Is_Tagged_Type
(Parent_Type
)
10199 or else Has_Discriminants
(Parent_Type
)
10200 or else (Present
(Full_View
(Parent_Type
))
10201 and then Has_Discriminants
(Full_View
(Parent_Type
)))
10206 when Concurrent_Kind
=>
10207 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
10210 raise Program_Error
;
10213 -- Nothing more to do if some error occurred
10215 if Etype
(Derived_Type
) = Any_Type
then
10219 -- If not already set, initialize the derived type's list of primitive
10220 -- operations to an empty element list.
10222 if not Present
(Direct_Primitive_Operations
(Derived_Type
)) then
10223 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
10225 -- If Etype of the derived type is the base type (as opposed to
10226 -- a parent type) and doesn't have an associated list of primitive
10227 -- operations, then set the base type's primitive list to the
10228 -- derived type's list. The lists need to be shared in common
10229 -- between the two.
10231 if Etype
(Derived_Type
) = Base_Type
(Derived_Type
)
10233 not Present
(Direct_Primitive_Operations
(Etype
(Derived_Type
)))
10235 Set_Direct_Primitive_Operations
10236 (Etype
(Derived_Type
),
10237 Direct_Primitive_Operations
(Derived_Type
));
10241 -- Set delayed freeze and then derive subprograms, we need to do this
10242 -- in this order so that derived subprograms inherit the derived freeze
10245 Set_Has_Delayed_Freeze
(Derived_Type
);
10247 if Derive_Subps
then
10248 Derive_Subprograms
(Parent_Type
, Derived_Type
);
10251 Set_Has_Primitive_Operations
10252 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
10253 end Build_Derived_Type
;
10255 -----------------------
10256 -- Build_Discriminal --
10257 -----------------------
10259 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
10260 D_Minal
: Entity_Id
;
10261 CR_Disc
: Entity_Id
;
10264 -- A discriminal has the same name as the discriminant
10266 D_Minal
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10268 Mutate_Ekind
(D_Minal
, E_In_Parameter
);
10269 Set_Mechanism
(D_Minal
, Default_Mechanism
);
10270 Set_Etype
(D_Minal
, Etype
(Discrim
));
10271 Set_Scope
(D_Minal
, Current_Scope
);
10272 Set_Parent
(D_Minal
, Parent
(Discrim
));
10274 Set_Discriminal
(Discrim
, D_Minal
);
10275 Set_Discriminal_Link
(D_Minal
, Discrim
);
10277 -- For task types, build at once the discriminants of the corresponding
10278 -- record, which are needed if discriminants are used in entry defaults
10279 -- and in family bounds.
10281 if Is_Concurrent_Type
(Current_Scope
)
10283 Is_Limited_Type
(Current_Scope
)
10285 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10287 Mutate_Ekind
(CR_Disc
, E_In_Parameter
);
10288 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
10289 Set_Etype
(CR_Disc
, Etype
(Discrim
));
10290 Set_Scope
(CR_Disc
, Current_Scope
);
10291 Set_Discriminal_Link
(CR_Disc
, Discrim
);
10292 Set_CR_Discriminant
(Discrim
, CR_Disc
);
10294 end Build_Discriminal
;
10296 ------------------------------------
10297 -- Build_Discriminant_Constraints --
10298 ------------------------------------
10300 function Build_Discriminant_Constraints
10303 Derived_Def
: Boolean := False) return Elist_Id
10305 C
: constant Node_Id
:= Constraint
(Def
);
10306 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
10308 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
10309 -- Saves the expression corresponding to a given discriminant in T
10311 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
10312 -- Return the Position number within array Discr_Expr of a discriminant
10313 -- D within the discriminant list of the discriminated type T.
10315 procedure Process_Discriminant_Expression
10318 -- If this is a discriminant constraint on a partial view, do not
10319 -- generate an overflow check on the discriminant expression. The check
10320 -- will be generated when constraining the full view. Otherwise the
10321 -- backend creates duplicate symbols for the temporaries corresponding
10322 -- to the expressions to be checked, causing spurious assembler errors.
10328 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
10332 Disc
:= First_Discriminant
(T
);
10333 for J
in Discr_Expr
'Range loop
10338 Next_Discriminant
(Disc
);
10341 -- Note: Since this function is called on discriminants that are
10342 -- known to belong to the discriminated type, falling through the
10343 -- loop with no match signals an internal compiler error.
10345 raise Program_Error
;
10348 -------------------------------------
10349 -- Process_Discriminant_Expression --
10350 -------------------------------------
10352 procedure Process_Discriminant_Expression
10356 BDT
: constant Entity_Id
:= Base_Type
(Etype
(D
));
10359 -- If this is a discriminant constraint on a partial view, do
10360 -- not generate an overflow on the discriminant expression. The
10361 -- check will be generated when constraining the full view.
10363 if Is_Private_Type
(T
)
10364 and then Present
(Full_View
(T
))
10366 Analyze_And_Resolve
(Expr
, BDT
, Suppress
=> Overflow_Check
);
10368 Analyze_And_Resolve
(Expr
, BDT
);
10370 end Process_Discriminant_Expression
;
10372 -- Declarations local to Build_Discriminant_Constraints
10376 Elist
: constant Elist_Id
:= New_Elmt_List
;
10384 Discrim_Present
: Boolean := False;
10386 -- Start of processing for Build_Discriminant_Constraints
10389 -- The following loop will process positional associations only.
10390 -- For a positional association, the (single) discriminant is
10391 -- implicitly specified by position, in textual order (RM 3.7.2).
10393 Discr
:= First_Discriminant
(T
);
10394 Constr
:= First
(Constraints
(C
));
10395 for D
in Discr_Expr
'Range loop
10396 exit when Nkind
(Constr
) = N_Discriminant_Association
;
10398 if No
(Constr
) then
10399 Error_Msg_N
("too few discriminants given in constraint", C
);
10400 return New_Elmt_List
;
10402 elsif Nkind
(Constr
) = N_Range
10403 or else (Nkind
(Constr
) = N_Attribute_Reference
10404 and then Attribute_Name
(Constr
) = Name_Range
)
10407 ("a range is not a valid discriminant constraint", Constr
);
10408 Discr_Expr
(D
) := Error
;
10410 elsif Nkind
(Constr
) = N_Subtype_Indication
then
10412 ("a subtype indication is not a valid discriminant constraint",
10414 Discr_Expr
(D
) := Error
;
10417 Process_Discriminant_Expression
(Constr
, Discr
);
10418 Discr_Expr
(D
) := Constr
;
10421 Next_Discriminant
(Discr
);
10425 if No
(Discr
) and then Present
(Constr
) then
10426 Error_Msg_N
("too many discriminants given in constraint", Constr
);
10427 return New_Elmt_List
;
10430 -- Named associations can be given in any order, but if both positional
10431 -- and named associations are used in the same discriminant constraint,
10432 -- then positional associations must occur first, at their normal
10433 -- position. Hence once a named association is used, the rest of the
10434 -- discriminant constraint must use only named associations.
10436 while Present
(Constr
) loop
10438 -- Positional association forbidden after a named association
10440 if Nkind
(Constr
) /= N_Discriminant_Association
then
10441 Error_Msg_N
("positional association follows named one", Constr
);
10442 return New_Elmt_List
;
10444 -- Otherwise it is a named association
10447 -- E records the type of the discriminants in the named
10448 -- association. All the discriminants specified in the same name
10449 -- association must have the same type.
10453 -- Search the list of discriminants in T to see if the simple name
10454 -- given in the constraint matches any of them.
10456 Id
:= First
(Selector_Names
(Constr
));
10457 while Present
(Id
) loop
10460 -- If Original_Discriminant is present, we are processing a
10461 -- generic instantiation and this is an instance node. We need
10462 -- to find the name of the corresponding discriminant in the
10463 -- actual record type T and not the name of the discriminant in
10464 -- the generic formal. Example:
10467 -- type G (D : int) is private;
10469 -- subtype W is G (D => 1);
10471 -- type Rec (X : int) is record ... end record;
10472 -- package Q is new P (G => Rec);
10474 -- At the point of the instantiation, formal type G is Rec
10475 -- and therefore when reanalyzing "subtype W is G (D => 1);"
10476 -- which really looks like "subtype W is Rec (D => 1);" at
10477 -- the point of instantiation, we want to find the discriminant
10478 -- that corresponds to D in Rec, i.e. X.
10480 if Present
(Original_Discriminant
(Id
))
10481 and then In_Instance
10483 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
10487 Discr
:= First_Discriminant
(T
);
10488 while Present
(Discr
) loop
10489 if Chars
(Discr
) = Chars
(Id
) then
10494 Next_Discriminant
(Discr
);
10498 Error_Msg_N
("& does not match any discriminant", Id
);
10499 return New_Elmt_List
;
10501 -- If the parent type is a generic formal, preserve the
10502 -- name of the discriminant for subsequent instances.
10503 -- see comment at the beginning of this if statement.
10505 elsif Is_Generic_Type
(Root_Type
(T
)) then
10506 Set_Original_Discriminant
(Id
, Discr
);
10510 Position
:= Pos_Of_Discr
(T
, Discr
);
10512 if Present
(Discr_Expr
(Position
)) then
10513 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
10516 -- Each discriminant specified in the same named association
10517 -- must be associated with a separate copy of the
10518 -- corresponding expression.
10520 if Present
(Next
(Id
)) then
10521 Expr
:= New_Copy_Tree
(Expression
(Constr
));
10522 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
10524 Expr
:= Expression
(Constr
);
10527 Discr_Expr
(Position
) := Expr
;
10528 Process_Discriminant_Expression
(Expr
, Discr
);
10531 -- A discriminant association with more than one discriminant
10532 -- name is only allowed if the named discriminants are all of
10533 -- the same type (RM 3.7.1(8)).
10536 E
:= Base_Type
(Etype
(Discr
));
10538 elsif Base_Type
(Etype
(Discr
)) /= E
then
10540 ("all discriminants in an association " &
10541 "must have the same type", Id
);
10551 -- A discriminant constraint must provide exactly one value for each
10552 -- discriminant of the type (RM 3.7.1(8)).
10554 for J
in Discr_Expr
'Range loop
10555 if No
(Discr_Expr
(J
)) then
10556 Error_Msg_N
("too few discriminants given in constraint", C
);
10557 return New_Elmt_List
;
10561 -- Determine if there are discriminant expressions in the constraint
10563 for J
in Discr_Expr
'Range loop
10564 if Denotes_Discriminant
10565 (Discr_Expr
(J
), Check_Concurrent
=> True)
10567 Discrim_Present
:= True;
10572 -- Build an element list consisting of the expressions given in the
10573 -- discriminant constraint and apply the appropriate checks. The list
10574 -- is constructed after resolving any named discriminant associations
10575 -- and therefore the expressions appear in the textual order of the
10578 Discr
:= First_Discriminant
(T
);
10579 for J
in Discr_Expr
'Range loop
10580 if Discr_Expr
(J
) /= Error
then
10581 Append_Elmt
(Discr_Expr
(J
), Elist
);
10583 -- If any of the discriminant constraints is given by a
10584 -- discriminant and we are in a derived type declaration we
10585 -- have a discriminant renaming. Establish link between new
10586 -- and old discriminant. The new discriminant has an implicit
10587 -- dereference if the old one does.
10589 if Denotes_Discriminant
(Discr_Expr
(J
)) then
10590 if Derived_Def
then
10592 New_Discr
: constant Entity_Id
:= Entity
(Discr_Expr
(J
));
10595 Set_Corresponding_Discriminant
(New_Discr
, Discr
);
10596 Set_Has_Implicit_Dereference
(New_Discr
,
10597 Has_Implicit_Dereference
(Discr
));
10601 -- Force the evaluation of non-discriminant expressions.
10602 -- If we have found a discriminant in the constraint 3.4(26)
10603 -- and 3.8(18) demand that no range checks are performed are
10604 -- after evaluation. If the constraint is for a component
10605 -- definition that has a per-object constraint, expressions are
10606 -- evaluated but not checked either. In all other cases perform
10610 if Discrim_Present
then
10613 elsif Parent_Kind
(Parent
(Def
)) = N_Component_Declaration
10614 and then Has_Per_Object_Constraint
10615 (Defining_Identifier
(Parent
(Parent
(Def
))))
10619 elsif Is_Access_Type
(Etype
(Discr
)) then
10620 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
10623 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
10626 -- If the value of the discriminant may be visible in
10627 -- another unit or child unit, create an external name
10628 -- for it. We use the name of the object or component
10629 -- that carries the discriminated subtype. The code
10630 -- below may generate external symbols for the discriminant
10631 -- expression when not strictly needed, which is harmless.
10634 and then Comes_From_Source
(Def
)
10635 and then not Is_Subprogram
(Current_Scope
)
10638 Id
: Entity_Id
:= Empty
;
10640 if Nkind
(Parent
(Def
)) = N_Object_Declaration
then
10641 Id
:= Defining_Identifier
(Parent
(Def
));
10643 elsif Nkind
(Parent
(Def
)) = N_Component_Definition
10645 Nkind
(Parent
(Parent
(Def
)))
10646 = N_Component_Declaration
10648 Id
:= Defining_Identifier
(Parent
(Parent
(Def
)));
10651 if Present
(Id
) then
10655 Discr_Number
=> J
);
10657 Force_Evaluation
(Discr_Expr
(J
));
10661 Force_Evaluation
(Discr_Expr
(J
));
10665 -- Check that the designated type of an access discriminant's
10666 -- expression is not a class-wide type unless the discriminant's
10667 -- designated type is also class-wide.
10669 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
10670 and then not Is_Class_Wide_Type
10671 (Designated_Type
(Etype
(Discr
)))
10672 and then Etype
(Discr_Expr
(J
)) /= Any_Type
10673 and then Is_Class_Wide_Type
10674 (Designated_Type
(Etype
(Discr_Expr
(J
))))
10676 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
10678 elsif Is_Access_Type
(Etype
(Discr
))
10679 and then not Is_Access_Constant
(Etype
(Discr
))
10680 and then Is_Access_Type
(Etype
(Discr_Expr
(J
)))
10681 and then Is_Access_Constant
(Etype
(Discr_Expr
(J
)))
10684 ("constraint for discriminant& must be access to variable",
10689 Next_Discriminant
(Discr
);
10693 end Build_Discriminant_Constraints
;
10695 ---------------------------------
10696 -- Build_Discriminated_Subtype --
10697 ---------------------------------
10699 procedure Build_Discriminated_Subtype
10701 Def_Id
: Entity_Id
;
10703 Related_Nod
: Node_Id
;
10704 For_Access
: Boolean := False)
10706 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
10707 Constrained
: constant Boolean :=
10709 and then not Is_Empty_Elmt_List
(Elist
)
10710 and then not Is_Class_Wide_Type
(T
))
10711 or else Is_Constrained
(T
);
10714 if Ekind
(T
) = E_Record_Type
then
10715 Mutate_Ekind
(Def_Id
, E_Record_Subtype
);
10717 -- Inherit preelaboration flag from base, for types for which it
10718 -- may have been set: records, private types, protected types.
10720 Set_Known_To_Have_Preelab_Init
10721 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10723 elsif Ekind
(T
) = E_Task_Type
then
10724 Mutate_Ekind
(Def_Id
, E_Task_Subtype
);
10726 elsif Ekind
(T
) = E_Protected_Type
then
10727 Mutate_Ekind
(Def_Id
, E_Protected_Subtype
);
10728 Set_Known_To_Have_Preelab_Init
10729 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10731 elsif Is_Private_Type
(T
) then
10732 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
10733 Set_Known_To_Have_Preelab_Init
10734 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10736 -- Private subtypes may have private dependents
10738 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
10740 elsif Is_Class_Wide_Type
(T
) then
10741 Mutate_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
10744 -- Incomplete type. Attach subtype to list of dependents, to be
10745 -- completed with full view of parent type, unless is it the
10746 -- designated subtype of a record component within an init_proc.
10747 -- This last case arises for a component of an access type whose
10748 -- designated type is incomplete (e.g. a Taft Amendment type).
10749 -- The designated subtype is within an inner scope, and needs no
10750 -- elaboration, because only the access type is needed in the
10751 -- initialization procedure.
10753 if Ekind
(T
) = E_Incomplete_Type
then
10754 Mutate_Ekind
(Def_Id
, E_Incomplete_Subtype
);
10756 Mutate_Ekind
(Def_Id
, Ekind
(T
));
10759 if For_Access
and then Within_Init_Proc
then
10762 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
10766 Set_Etype
(Def_Id
, T
);
10767 Reinit_Size_Align
(Def_Id
);
10768 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
10769 Set_Is_Constrained
(Def_Id
, Constrained
);
10771 Set_First_Entity
(Def_Id
, First_Entity
(T
));
10772 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
10773 Set_Has_Implicit_Dereference
10774 (Def_Id
, Has_Implicit_Dereference
(T
));
10775 Set_Has_Pragma_Unreferenced_Objects
10776 (Def_Id
, Has_Pragma_Unreferenced_Objects
(T
));
10778 -- If the subtype is the completion of a private declaration, there may
10779 -- have been representation clauses for the partial view, and they must
10780 -- be preserved. Build_Derived_Type chains the inherited clauses with
10781 -- the ones appearing on the extension. If this comes from a subtype
10782 -- declaration, all clauses are inherited.
10784 if No
(First_Rep_Item
(Def_Id
)) then
10785 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10788 if Is_Tagged_Type
(T
) then
10789 Set_Is_Tagged_Type
(Def_Id
);
10790 Set_No_Tagged_Streams_Pragma
(Def_Id
, No_Tagged_Streams_Pragma
(T
));
10791 Make_Class_Wide_Type
(Def_Id
);
10794 Set_Stored_Constraint
(Def_Id
, No_Elist
);
10797 Set_Discriminant_Constraint
(Def_Id
, Elist
);
10798 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
10801 if Is_Tagged_Type
(T
) then
10803 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
10804 -- concurrent record type (which has the list of primitive
10807 if Ada_Version
>= Ada_2005
10808 and then Is_Concurrent_Type
(T
)
10810 Set_Corresponding_Record_Type
(Def_Id
,
10811 Corresponding_Record_Type
(T
));
10813 Set_Direct_Primitive_Operations
(Def_Id
,
10814 Direct_Primitive_Operations
(T
));
10817 Set_Is_Abstract_Type
(Def_Id
, Is_Abstract_Type
(T
));
10820 -- Subtypes introduced by component declarations do not need to be
10821 -- marked as delayed, and do not get freeze nodes, because the semantics
10822 -- verifies that the parents of the subtypes are frozen before the
10823 -- enclosing record is frozen.
10825 if not Is_Type
(Scope
(Def_Id
)) then
10826 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
10828 if Is_Private_Type
(T
)
10829 and then Present
(Full_View
(T
))
10831 Conditional_Delay
(Def_Id
, Full_View
(T
));
10833 Conditional_Delay
(Def_Id
, T
);
10837 if Is_Record_Type
(T
) then
10838 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
10841 and then not Is_Empty_Elmt_List
(Elist
)
10842 and then not For_Access
10844 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
10846 elsif not Is_Private_Type
(T
) then
10847 Set_Cloned_Subtype
(Def_Id
, T
);
10850 end Build_Discriminated_Subtype
;
10852 ---------------------------
10853 -- Build_Itype_Reference --
10854 ---------------------------
10856 procedure Build_Itype_Reference
10860 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(Nod
));
10863 -- Itype references are only created for use by the back-end
10865 if Inside_A_Generic
then
10868 Set_Itype
(IR
, Ityp
);
10870 -- If Nod is a library unit entity, then Insert_After won't work,
10871 -- because Nod is not a member of any list. Therefore, we use
10872 -- Add_Global_Declaration in this case. This can happen if we have a
10873 -- build-in-place library function, child unit or not.
10875 if (Nkind
(Nod
) in N_Entity
and then Is_Compilation_Unit
(Nod
))
10876 or else (Nkind
(Nod
) in
10877 N_Defining_Program_Unit_Name | N_Subprogram_Declaration
10878 and then Is_Compilation_Unit
(Defining_Entity
(Nod
)))
10880 Add_Global_Declaration
(IR
);
10882 Insert_After
(Nod
, IR
);
10885 end Build_Itype_Reference
;
10887 ------------------------
10888 -- Build_Scalar_Bound --
10889 ------------------------
10891 function Build_Scalar_Bound
10894 Der_T
: Entity_Id
) return Node_Id
10896 New_Bound
: Entity_Id
;
10899 -- Note: not clear why this is needed, how can the original bound
10900 -- be unanalyzed at this point? and if it is, what business do we
10901 -- have messing around with it? and why is the base type of the
10902 -- parent type the right type for the resolution. It probably is
10903 -- not. It is OK for the new bound we are creating, but not for
10904 -- the old one??? Still if it never happens, no problem.
10906 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
10908 if Nkind
(Bound
) in N_Integer_Literal | N_Real_Literal
then
10909 New_Bound
:= New_Copy
(Bound
);
10910 Set_Etype
(New_Bound
, Der_T
);
10911 Set_Analyzed
(New_Bound
);
10913 elsif Is_Entity_Name
(Bound
) then
10914 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
10916 -- The following is almost certainly wrong. What business do we have
10917 -- relocating a node (Bound) that is presumably still attached to
10918 -- the tree elsewhere???
10921 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
10924 Set_Etype
(New_Bound
, Der_T
);
10926 end Build_Scalar_Bound
;
10928 -------------------------------
10929 -- Check_Abstract_Overriding --
10930 -------------------------------
10932 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
10933 Alias_Subp
: Entity_Id
;
10935 Op_List
: Elist_Id
;
10937 Type_Def
: Node_Id
;
10939 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
);
10940 -- Ada 2012 (AI05-0030): Subprogram Subp overrides an interface routine
10941 -- which has pragma Implemented already set. Check whether Subp's entity
10942 -- kind conforms to the implementation kind of the overridden routine.
10944 procedure Check_Pragma_Implemented
10946 Iface_Subp
: Entity_Id
);
10947 -- Ada 2012 (AI05-0030): Subprogram Subp overrides interface routine
10948 -- Iface_Subp and both entities have pragma Implemented already set on
10949 -- them. Check whether the two implementation kinds are conforming.
10951 procedure Inherit_Pragma_Implemented
10953 Iface_Subp
: Entity_Id
);
10954 -- Ada 2012 (AI05-0030): Interface primitive Subp overrides interface
10955 -- subprogram Iface_Subp which has been marked by pragma Implemented.
10956 -- Propagate the implementation kind of Iface_Subp to Subp.
10958 ------------------------------
10959 -- Check_Pragma_Implemented --
10960 ------------------------------
10962 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
) is
10963 Iface_Alias
: constant Entity_Id
:= Interface_Alias
(Subp
);
10964 Impl_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Alias
);
10965 Subp_Alias
: constant Entity_Id
:= Alias
(Subp
);
10966 Contr_Typ
: Entity_Id
;
10967 Impl_Subp
: Entity_Id
;
10970 -- Subp must have an alias since it is a hidden entity used to link
10971 -- an interface subprogram to its overriding counterpart.
10973 pragma Assert
(Present
(Subp_Alias
));
10975 -- Handle aliases to synchronized wrappers
10977 Impl_Subp
:= Subp_Alias
;
10979 if Is_Primitive_Wrapper
(Impl_Subp
) then
10980 Impl_Subp
:= Wrapped_Entity
(Impl_Subp
);
10983 -- Extract the type of the controlling formal
10985 Contr_Typ
:= Etype
(First_Formal
(Subp_Alias
));
10987 if Is_Concurrent_Record_Type
(Contr_Typ
) then
10988 Contr_Typ
:= Corresponding_Concurrent_Type
(Contr_Typ
);
10991 -- An interface subprogram whose implementation kind is By_Entry must
10992 -- be implemented by an entry.
10994 if Impl_Kind
= Name_By_Entry
10995 and then Ekind
(Impl_Subp
) /= E_Entry
10997 Error_Msg_Node_2
:= Iface_Alias
;
10999 ("type & must implement abstract subprogram & with an entry",
11000 Subp_Alias
, Contr_Typ
);
11002 elsif Impl_Kind
= Name_By_Protected_Procedure
then
11004 -- An interface subprogram whose implementation kind is By_
11005 -- Protected_Procedure cannot be implemented by a primitive
11006 -- procedure of a task type.
11008 if Ekind
(Contr_Typ
) /= E_Protected_Type
then
11009 Error_Msg_Node_2
:= Contr_Typ
;
11011 ("interface subprogram & cannot be implemented by a "
11012 & "primitive procedure of task type &",
11013 Subp_Alias
, Iface_Alias
);
11015 -- An interface subprogram whose implementation kind is By_
11016 -- Protected_Procedure must be implemented by a procedure.
11018 elsif Ekind
(Impl_Subp
) /= E_Procedure
then
11019 Error_Msg_Node_2
:= Iface_Alias
;
11021 ("type & must implement abstract subprogram & with a "
11022 & "procedure", Subp_Alias
, Contr_Typ
);
11024 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
11025 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
11027 Error_Msg_Name_1
:= Impl_Kind
;
11029 ("overriding operation& must have synchronization%",
11033 -- If primitive has Optional synchronization, overriding operation
11034 -- must match if it has an explicit synchronization.
11036 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
11037 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
11039 Error_Msg_Name_1
:= Impl_Kind
;
11041 ("overriding operation& must have synchronization%", Subp_Alias
);
11043 end Check_Pragma_Implemented
;
11045 ------------------------------
11046 -- Check_Pragma_Implemented --
11047 ------------------------------
11049 procedure Check_Pragma_Implemented
11051 Iface_Subp
: Entity_Id
)
11053 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
11054 Subp_Kind
: constant Name_Id
:= Implementation_Kind
(Subp
);
11057 -- Ada 2012 (AI05-0030): The implementation kinds of an overridden
11058 -- and overriding subprogram are different. In general this is an
11059 -- error except when the implementation kind of the overridden
11060 -- subprograms is By_Any or Optional.
11062 if Iface_Kind
/= Subp_Kind
11063 and then Iface_Kind
/= Name_By_Any
11064 and then Iface_Kind
/= Name_Optional
11066 if Iface_Kind
= Name_By_Entry
then
11068 ("incompatible implementation kind, overridden subprogram " &
11069 "is marked By_Entry", Subp
);
11072 ("incompatible implementation kind, overridden subprogram " &
11073 "is marked By_Protected_Procedure", Subp
);
11076 end Check_Pragma_Implemented
;
11078 --------------------------------
11079 -- Inherit_Pragma_Implemented --
11080 --------------------------------
11082 procedure Inherit_Pragma_Implemented
11084 Iface_Subp
: Entity_Id
)
11086 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
11087 Loc
: constant Source_Ptr
:= Sloc
(Subp
);
11088 Impl_Prag
: Node_Id
;
11091 -- Since the implementation kind is stored as a representation item
11092 -- rather than a flag, create a pragma node.
11096 Chars
=> Name_Implemented
,
11097 Pragma_Argument_Associations
=> New_List
(
11098 Make_Pragma_Argument_Association
(Loc
,
11099 Expression
=> New_Occurrence_Of
(Subp
, Loc
)),
11101 Make_Pragma_Argument_Association
(Loc
,
11102 Expression
=> Make_Identifier
(Loc
, Iface_Kind
))));
11104 -- The pragma doesn't need to be analyzed because it is internally
11105 -- built. It is safe to directly register it as a rep item since we
11106 -- are only interested in the characters of the implementation kind.
11108 Record_Rep_Item
(Subp
, Impl_Prag
);
11109 end Inherit_Pragma_Implemented
;
11111 -- Start of processing for Check_Abstract_Overriding
11114 Op_List
:= Primitive_Operations
(T
);
11116 -- Loop to check primitive operations
11118 Elmt
:= First_Elmt
(Op_List
);
11119 while Present
(Elmt
) loop
11120 Subp
:= Node
(Elmt
);
11121 Alias_Subp
:= Alias
(Subp
);
11123 -- If the parent type is untagged, then no overriding error checks
11124 -- are needed (such as in the case of an implicit full type for
11125 -- a derived type whose parent is an untagged private type with
11126 -- a tagged full type).
11128 if not Is_Tagged_Type
(Etype
(T
)) then
11131 -- Inherited subprograms are identified by the fact that they do not
11132 -- come from source, and the associated source location is the
11133 -- location of the first subtype of the derived type.
11135 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
11136 -- subprograms that "require overriding".
11138 -- Special exception, do not complain about failure to override the
11139 -- stream routines _Input and _Output, as well as the primitive
11140 -- operations used in dispatching selects since we always provide
11141 -- automatic overridings for these subprograms.
11143 -- The partial view of T may have been a private extension, for
11144 -- which inherited functions dispatching on result are abstract.
11145 -- If the full view is a null extension, there is no need for
11146 -- overriding in Ada 2005, but wrappers need to be built for them
11147 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
11149 elsif Is_Null_Extension
(T
)
11150 and then Has_Controlling_Result
(Subp
)
11151 and then Ada_Version
>= Ada_2005
11152 and then Present
(Alias_Subp
)
11153 and then not Comes_From_Source
(Subp
)
11154 and then not Is_Abstract_Subprogram
(Alias_Subp
)
11155 and then not Is_Access_Type
(Etype
(Subp
))
11159 -- Ada 2005 (AI-251): Internal entities of interfaces need no
11160 -- processing because this check is done with the aliased
11163 elsif Present
(Interface_Alias
(Subp
)) then
11166 -- AI12-0042: Test for rule in 7.3.2(6.1/4), that requires overriding
11167 -- of a visible private primitive inherited from an ancestor with
11168 -- the aspect Type_Invariant'Class, unless the inherited primitive
11171 elsif not Is_Abstract_Subprogram
(Subp
)
11172 and then not Comes_From_Source
(Subp
) -- An inherited subprogram
11173 and then Requires_Overriding
(Subp
)
11174 and then Present
(Alias_Subp
)
11175 and then Has_Invariants
(Etype
(T
))
11176 and then Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11177 and then Class_Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11178 and then Is_Private_Primitive
(Alias_Subp
)
11181 ("inherited private primitive & must be overridden", T
, Subp
);
11183 ("\because ancestor type has 'Type_'Invariant''Class " &
11184 "(RM 7.3.2(6.1))", T
);
11186 elsif (Is_Abstract_Subprogram
(Subp
)
11187 or else Requires_Overriding
(Subp
)
11189 (Has_Controlling_Result
(Subp
)
11190 and then Present
(Alias_Subp
)
11191 and then not Comes_From_Source
(Subp
)
11192 and then Sloc
(Subp
) = Sloc
(First_Subtype
(T
))))
11193 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
11194 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
11195 and then not Is_Abstract_Type
(T
)
11196 and then not Is_Predefined_Interface_Primitive
(Subp
)
11198 -- Ada 2005 (AI-251): Do not consider hidden entities associated
11199 -- with abstract interface types because the check will be done
11200 -- with the aliased entity (otherwise we generate a duplicated
11203 and then No
(Interface_Alias
(Subp
))
11205 if Present
(Alias_Subp
) then
11207 -- Only perform the check for a derived subprogram when the
11208 -- type has an explicit record extension. This avoids incorrect
11209 -- flagging of abstract subprograms for the case of a type
11210 -- without an extension that is derived from a formal type
11211 -- with a tagged actual (can occur within a private part).
11213 -- Ada 2005 (AI-391): In the case of an inherited function with
11214 -- a controlling result of the type, the rule does not apply if
11215 -- the type is a null extension (unless the parent function
11216 -- itself is abstract, in which case the function must still be
11217 -- be overridden). The expander will generate an overriding
11218 -- wrapper function calling the parent subprogram (see
11219 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
11221 Type_Def
:= Type_Definition
(Parent
(T
));
11223 if Nkind
(Type_Def
) = N_Derived_Type_Definition
11224 and then Present
(Record_Extension_Part
(Type_Def
))
11226 (Ada_Version
< Ada_2005
11227 or else not Is_Null_Extension
(T
)
11228 or else Ekind
(Subp
) = E_Procedure
11229 or else not Has_Controlling_Result
(Subp
)
11230 or else Is_Abstract_Subprogram
(Alias_Subp
)
11231 or else Requires_Overriding
(Subp
)
11232 or else Is_Access_Type
(Etype
(Subp
)))
11234 -- Avoid reporting error in case of abstract predefined
11235 -- primitive inherited from interface type because the
11236 -- body of internally generated predefined primitives
11237 -- of tagged types are generated later by Freeze_Type
11239 if Is_Interface
(Root_Type
(T
))
11240 and then Is_Abstract_Subprogram
(Subp
)
11241 and then Is_Predefined_Dispatching_Operation
(Subp
)
11242 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
11246 -- A null extension is not obliged to override an inherited
11247 -- procedure subject to pragma Extensions_Visible with value
11248 -- False and at least one controlling OUT parameter
11249 -- (SPARK RM 6.1.7(6)).
11251 elsif Is_Null_Extension
(T
)
11252 and then Is_EVF_Procedure
(Subp
)
11256 -- Subprogram renamings cannot be overridden
11258 elsif Comes_From_Source
(Subp
)
11259 and then Present
(Alias
(Subp
))
11263 -- Skip reporting the error on Ada 2022 only subprograms
11264 -- that require overriding if we are not in Ada 2022 mode.
11266 elsif Ada_Version
< Ada_2022
11267 and then Requires_Overriding
(Subp
)
11268 and then Is_Ada_2022_Only
(Ultimate_Alias
(Subp
))
11274 ("type must be declared abstract or & overridden",
11277 -- Traverse the whole chain of aliased subprograms to
11278 -- complete the error notification. This is especially
11279 -- useful for traceability of the chain of entities when
11280 -- the subprogram corresponds with an interface
11281 -- subprogram (which may be defined in another package).
11283 if Present
(Alias_Subp
) then
11289 while Present
(Alias
(E
)) loop
11291 -- Avoid reporting redundant errors on entities
11292 -- inherited from interfaces
11294 if Sloc
(E
) /= Sloc
(T
) then
11295 Error_Msg_Sloc
:= Sloc
(E
);
11297 ("\& has been inherited #", T
, Subp
);
11303 Error_Msg_Sloc
:= Sloc
(E
);
11305 -- AI05-0068: report if there is an overriding
11306 -- non-abstract subprogram that is invisible.
11309 and then not Is_Abstract_Subprogram
(E
)
11312 ("\& subprogram# is not visible",
11315 -- Clarify the case where a non-null extension must
11316 -- override inherited procedure subject to pragma
11317 -- Extensions_Visible with value False and at least
11318 -- one controlling OUT param.
11320 elsif Is_EVF_Procedure
(E
) then
11322 ("\& # is subject to Extensions_Visible False",
11327 ("\& has been inherited from subprogram #",
11334 -- Ada 2005 (AI-345): Protected or task type implementing
11335 -- abstract interfaces.
11337 elsif Is_Concurrent_Record_Type
(T
)
11338 and then Present
(Interfaces
(T
))
11340 -- There is no need to check here RM 9.4(11.9/3) since we
11341 -- are processing the corresponding record type and the
11342 -- mode of the overriding subprograms was verified by
11343 -- Check_Conformance when the corresponding concurrent
11344 -- type declaration was analyzed.
11347 ("interface subprogram & must be overridden", T
, Subp
);
11349 -- Examine primitive operations of synchronized type to find
11350 -- homonyms that have the wrong profile.
11356 Prim
:= First_Entity
(Corresponding_Concurrent_Type
(T
));
11357 while Present
(Prim
) loop
11358 if Chars
(Prim
) = Chars
(Subp
) then
11360 ("profile is not type conformant with prefixed "
11361 & "view profile of inherited operation&",
11365 Next_Entity
(Prim
);
11371 Error_Msg_Node_2
:= T
;
11373 ("abstract subprogram& not allowed for type&", Subp
);
11375 -- Also post unconditional warning on the type (unconditional
11376 -- so that if there are more than one of these cases, we get
11377 -- them all, and not just the first one).
11379 Error_Msg_Node_2
:= Subp
;
11380 Error_Msg_N
("nonabstract type& has abstract subprogram&!", T
);
11383 -- A subprogram subject to pragma Extensions_Visible with value
11384 -- "True" cannot override a subprogram subject to the same pragma
11385 -- with value "False" (SPARK RM 6.1.7(5)).
11387 elsif Extensions_Visible_Status
(Subp
) = Extensions_Visible_True
11388 and then Present
(Overridden_Operation
(Subp
))
11389 and then Extensions_Visible_Status
(Overridden_Operation
(Subp
)) =
11390 Extensions_Visible_False
11392 Error_Msg_Sloc
:= Sloc
(Overridden_Operation
(Subp
));
11394 ("subprogram & with Extensions_Visible True cannot override "
11395 & "subprogram # with Extensions_Visible False", Subp
);
11398 -- Ada 2012 (AI05-0030): Perform checks related to pragma Implemented
11400 -- Subp is an expander-generated procedure which maps an interface
11401 -- alias to a protected wrapper. The interface alias is flagged by
11402 -- pragma Implemented. Ensure that Subp is a procedure when the
11403 -- implementation kind is By_Protected_Procedure or an entry when
11406 if Ada_Version
>= Ada_2012
11407 and then Is_Hidden
(Subp
)
11408 and then Present
(Interface_Alias
(Subp
))
11409 and then Has_Rep_Pragma
(Interface_Alias
(Subp
), Name_Implemented
)
11411 Check_Pragma_Implemented
(Subp
);
11414 -- Subp is an interface primitive which overrides another interface
11415 -- primitive marked with pragma Implemented.
11417 if Ada_Version
>= Ada_2012
11418 and then Present
(Overridden_Operation
(Subp
))
11419 and then Has_Rep_Pragma
11420 (Overridden_Operation
(Subp
), Name_Implemented
)
11422 -- If the overriding routine is also marked by Implemented, check
11423 -- that the two implementation kinds are conforming.
11425 if Has_Rep_Pragma
(Subp
, Name_Implemented
) then
11426 Check_Pragma_Implemented
11428 Iface_Subp
=> Overridden_Operation
(Subp
));
11430 -- Otherwise the overriding routine inherits the implementation
11431 -- kind from the overridden subprogram.
11434 Inherit_Pragma_Implemented
11436 Iface_Subp
=> Overridden_Operation
(Subp
));
11440 -- Ada 2005 (AI95-0414) and Ada 2022 (AI12-0269): Diagnose failure to
11441 -- match No_Return in parent, but do it unconditionally in Ada 95 too
11442 -- for procedures, since this is our pragma.
11444 if Present
(Overridden_Operation
(Subp
))
11445 and then No_Return
(Overridden_Operation
(Subp
))
11448 -- If the subprogram is a renaming, check that the renamed
11449 -- subprogram is No_Return.
11451 if Present
(Renamed_Or_Alias
(Subp
)) then
11452 if not No_Return
(Renamed_Or_Alias
(Subp
)) then
11453 Error_Msg_NE
("subprogram & must be No_Return",
11455 Renamed_Or_Alias
(Subp
));
11456 Error_Msg_N
("\since renaming & overrides No_Return "
11457 & "subprogram (RM 6.5.1(6/2))",
11461 -- Make sure that the subprogram itself is No_Return.
11463 elsif not No_Return
(Subp
) then
11464 Error_Msg_N
("overriding subprogram & must be No_Return", Subp
);
11466 ("\since overridden subprogram is No_Return (RM 6.5.1(6/2))",
11471 -- If the operation is a wrapper for a synchronized primitive, it
11472 -- may be called indirectly through a dispatching select. We assume
11473 -- that it will be referenced elsewhere indirectly, and suppress
11474 -- warnings about an unused entity.
11476 if Is_Primitive_Wrapper
(Subp
)
11477 and then Present
(Wrapped_Entity
(Subp
))
11479 Set_Referenced
(Wrapped_Entity
(Subp
));
11484 end Check_Abstract_Overriding
;
11486 ------------------------------------------------
11487 -- Check_Access_Discriminant_Requires_Limited --
11488 ------------------------------------------------
11490 procedure Check_Access_Discriminant_Requires_Limited
11495 -- A discriminant_specification for an access discriminant shall appear
11496 -- only in the declaration for a task or protected type, or for a type
11497 -- with the reserved word 'limited' in its definition or in one of its
11498 -- ancestors (RM 3.7(10)).
11500 -- AI-0063: The proper condition is that type must be immutably limited,
11501 -- or else be a partial view.
11503 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
then
11504 if Is_Limited_View
(Current_Scope
)
11506 (Nkind
(Parent
(Current_Scope
)) = N_Private_Type_Declaration
11507 and then Limited_Present
(Parent
(Current_Scope
)))
11513 ("access discriminants allowed only for limited types", Loc
);
11516 end Check_Access_Discriminant_Requires_Limited
;
11518 -----------------------------------
11519 -- Check_Aliased_Component_Types --
11520 -----------------------------------
11522 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
11526 -- ??? Also need to check components of record extensions, but not
11527 -- components of protected types (which are always limited).
11529 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
11530 -- types to be unconstrained. This is safe because it is illegal to
11531 -- create access subtypes to such types with explicit discriminant
11534 if not Is_Limited_Type
(T
) then
11535 if Ekind
(T
) = E_Record_Type
then
11536 C
:= First_Component
(T
);
11537 while Present
(C
) loop
11539 and then Has_Discriminants
(Etype
(C
))
11540 and then not Is_Constrained
(Etype
(C
))
11541 and then not In_Instance_Body
11542 and then Ada_Version
< Ada_2005
11545 ("aliased component must be constrained (RM 3.6(11))",
11549 Next_Component
(C
);
11552 elsif Ekind
(T
) = E_Array_Type
then
11553 if Has_Aliased_Components
(T
)
11554 and then Has_Discriminants
(Component_Type
(T
))
11555 and then not Is_Constrained
(Component_Type
(T
))
11556 and then not In_Instance_Body
11557 and then Ada_Version
< Ada_2005
11560 ("aliased component type must be constrained (RM 3.6(11))",
11565 end Check_Aliased_Component_Types
;
11567 --------------------------------------
11568 -- Check_Anonymous_Access_Component --
11569 --------------------------------------
11571 procedure Check_Anonymous_Access_Component
11572 (Typ_Decl
: Node_Id
;
11575 Comp_Def
: Node_Id
;
11576 Access_Def
: Node_Id
)
11578 Loc
: constant Source_Ptr
:= Sloc
(Comp_Def
);
11579 Anon_Access
: Entity_Id
;
11582 Type_Def
: Node_Id
;
11584 procedure Build_Incomplete_Type_Declaration
;
11585 -- If the record type contains components that include an access to the
11586 -- current record, then create an incomplete type declaration for the
11587 -- record, to be used as the designated type of the anonymous access.
11588 -- This is done only once, and only if there is no previous partial
11589 -- view of the type.
11591 function Designates_T
(Subt
: Node_Id
) return Boolean;
11592 -- Check whether a node designates the enclosing record type, or 'Class
11595 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean;
11596 -- Check whether an access definition includes a reference to
11597 -- the enclosing record type. The reference can be a subtype mark
11598 -- in the access definition itself, a 'Class attribute reference, or
11599 -- recursively a reference appearing in a parameter specification
11600 -- or result definition of an access_to_subprogram definition.
11602 --------------------------------------
11603 -- Build_Incomplete_Type_Declaration --
11604 --------------------------------------
11606 procedure Build_Incomplete_Type_Declaration
is
11611 -- Is_Tagged indicates whether the type is tagged. It is tagged if
11612 -- it's "is new ... with record" or else "is tagged record ...".
11614 Typ_Def
: constant Node_Id
:=
11615 (if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
11616 then Type_Definition
(Typ_Decl
) else Empty
);
11617 Is_Tagged
: constant Boolean :=
11620 ((Nkind
(Typ_Def
) = N_Derived_Type_Definition
11622 Present
(Record_Extension_Part
(Typ_Def
)))
11624 (Nkind
(Typ_Def
) = N_Record_Definition
11625 and then Tagged_Present
(Typ_Def
)));
11628 -- If there is a previous partial view, no need to create a new one
11629 -- If the partial view, given by Prev, is incomplete, If Prev is
11630 -- a private declaration, full declaration is flagged accordingly.
11632 if Prev
/= Typ
then
11634 Make_Class_Wide_Type
(Prev
);
11635 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Prev
));
11636 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11641 elsif Has_Private_Declaration
(Typ
) then
11643 -- If we refer to T'Class inside T, and T is the completion of a
11644 -- private type, then make sure the class-wide type exists.
11647 Make_Class_Wide_Type
(Typ
);
11652 -- If there was a previous anonymous access type, the incomplete
11653 -- type declaration will have been created already.
11655 elsif Present
(Current_Entity
(Typ
))
11656 and then Ekind
(Current_Entity
(Typ
)) = E_Incomplete_Type
11657 and then Full_View
(Current_Entity
(Typ
)) = Typ
11660 and then Comes_From_Source
(Current_Entity
(Typ
))
11661 and then not Is_Tagged_Type
(Current_Entity
(Typ
))
11663 Make_Class_Wide_Type
(Typ
);
11665 ("incomplete view of tagged type should be declared tagged??",
11666 Parent
(Current_Entity
(Typ
)));
11671 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Typ
));
11672 Decl
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
11674 -- Type has already been inserted into the current scope. Remove
11675 -- it, and add incomplete declaration for type, so that subsequent
11676 -- anonymous access types can use it. The entity is unchained from
11677 -- the homonym list and from immediate visibility. After analysis,
11678 -- the entity in the incomplete declaration becomes immediately
11679 -- visible in the record declaration that follows.
11681 H
:= Current_Entity
(Typ
);
11684 Set_Name_Entity_Id
(Chars
(Typ
), Homonym
(Typ
));
11687 while Present
(Homonym
(H
)) and then Homonym
(H
) /= Typ
loop
11688 H
:= Homonym
(Typ
);
11691 Set_Homonym
(H
, Homonym
(Typ
));
11694 Insert_Before
(Typ_Decl
, Decl
);
11696 Set_Full_View
(Inc_T
, Typ
);
11697 Set_Incomplete_View
(Typ_Decl
, Inc_T
);
11699 -- If the type is tagged, create a common class-wide type for
11700 -- both views, and set the Etype of the class-wide type to the
11704 Make_Class_Wide_Type
(Inc_T
);
11705 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Inc_T
));
11706 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11709 -- If the scope is a package with a limited view, create a shadow
11710 -- entity for the incomplete type like Build_Limited_Views, so as
11711 -- to make it possible for Remove_Limited_With_Unit to reinstall
11712 -- this incomplete type as the visible entity.
11714 if Ekind
(Scope
(Inc_T
)) = E_Package
11715 and then Present
(Limited_View
(Scope
(Inc_T
)))
11718 Shadow
: constant Entity_Id
:= Make_Temporary
(Loc
, 'Z');
11721 -- This is modeled on Build_Shadow_Entity
11723 Set_Chars
(Shadow
, Chars
(Inc_T
));
11724 Set_Parent
(Shadow
, Decl
);
11725 Decorate_Type
(Shadow
, Scope
(Inc_T
), Is_Tagged
);
11726 Set_Is_Internal
(Shadow
);
11727 Set_From_Limited_With
(Shadow
);
11728 Set_Non_Limited_View
(Shadow
, Inc_T
);
11729 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
11732 Set_Non_Limited_View
11733 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Inc_T
));
11736 Append_Entity
(Shadow
, Limited_View
(Scope
(Inc_T
)));
11740 end Build_Incomplete_Type_Declaration
;
11746 function Designates_T
(Subt
: Node_Id
) return Boolean is
11747 Type_Id
: constant Name_Id
:= Chars
(Typ
);
11749 function Names_T
(Nam
: Node_Id
) return Boolean;
11750 -- The record type has not been introduced in the current scope
11751 -- yet, so we must examine the name of the type itself, either
11752 -- an identifier T, or an expanded name of the form P.T, where
11753 -- P denotes the current scope.
11759 function Names_T
(Nam
: Node_Id
) return Boolean is
11761 if Nkind
(Nam
) = N_Identifier
then
11762 return Chars
(Nam
) = Type_Id
;
11764 elsif Nkind
(Nam
) = N_Selected_Component
then
11765 if Chars
(Selector_Name
(Nam
)) = Type_Id
then
11766 if Nkind
(Prefix
(Nam
)) = N_Identifier
then
11767 return Chars
(Prefix
(Nam
)) = Chars
(Current_Scope
);
11769 elsif Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
11770 return Chars
(Selector_Name
(Prefix
(Nam
))) =
11771 Chars
(Current_Scope
);
11785 -- Start of processing for Designates_T
11788 if Nkind
(Subt
) = N_Identifier
then
11789 return Chars
(Subt
) = Type_Id
;
11791 -- Reference can be through an expanded name which has not been
11792 -- analyzed yet, and which designates enclosing scopes.
11794 elsif Nkind
(Subt
) = N_Selected_Component
then
11795 if Names_T
(Subt
) then
11798 -- Otherwise it must denote an entity that is already visible.
11799 -- The access definition may name a subtype of the enclosing
11800 -- type, if there is a previous incomplete declaration for it.
11803 Find_Selected_Component
(Subt
);
11805 Is_Entity_Name
(Subt
)
11806 and then Scope
(Entity
(Subt
)) = Current_Scope
11808 (Chars
(Base_Type
(Entity
(Subt
))) = Type_Id
11810 (Is_Class_Wide_Type
(Entity
(Subt
))
11812 Chars
(Etype
(Base_Type
(Entity
(Subt
)))) =
11816 -- A reference to the current type may appear as the prefix of
11817 -- a 'Class attribute.
11819 elsif Nkind
(Subt
) = N_Attribute_Reference
11820 and then Attribute_Name
(Subt
) = Name_Class
11822 return Names_T
(Prefix
(Subt
));
11833 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean is
11834 Param_Spec
: Node_Id
;
11836 Acc_Subprg
: constant Node_Id
:=
11837 Access_To_Subprogram_Definition
(Acc_Def
);
11840 if No
(Acc_Subprg
) then
11841 return Designates_T
(Subtype_Mark
(Acc_Def
));
11844 -- Component is an access_to_subprogram: examine its formals,
11845 -- and result definition in the case of an access_to_function.
11847 Param_Spec
:= First
(Parameter_Specifications
(Acc_Subprg
));
11848 while Present
(Param_Spec
) loop
11849 if Nkind
(Parameter_Type
(Param_Spec
)) = N_Access_Definition
11850 and then Mentions_T
(Parameter_Type
(Param_Spec
))
11854 elsif Designates_T
(Parameter_Type
(Param_Spec
)) then
11861 if Nkind
(Acc_Subprg
) = N_Access_Function_Definition
then
11862 if Nkind
(Result_Definition
(Acc_Subprg
)) =
11863 N_Access_Definition
11865 return Mentions_T
(Result_Definition
(Acc_Subprg
));
11867 return Designates_T
(Result_Definition
(Acc_Subprg
));
11874 -- Start of processing for Check_Anonymous_Access_Component
11877 if Present
(Access_Def
) and then Mentions_T
(Access_Def
) then
11878 Acc_Def
:= Access_To_Subprogram_Definition
(Access_Def
);
11880 Build_Incomplete_Type_Declaration
;
11881 Anon_Access
:= Make_Temporary
(Loc
, 'S');
11883 -- Create a declaration for the anonymous access type: either
11884 -- an access_to_object or an access_to_subprogram.
11886 if Present
(Acc_Def
) then
11887 if Nkind
(Acc_Def
) = N_Access_Function_Definition
then
11889 Make_Access_Function_Definition
(Loc
,
11890 Parameter_Specifications
=>
11891 Parameter_Specifications
(Acc_Def
),
11892 Result_Definition
=> Result_Definition
(Acc_Def
));
11895 Make_Access_Procedure_Definition
(Loc
,
11896 Parameter_Specifications
=>
11897 Parameter_Specifications
(Acc_Def
));
11902 Make_Access_To_Object_Definition
(Loc
,
11903 Subtype_Indication
=>
11904 Relocate_Node
(Subtype_Mark
(Access_Def
)));
11906 Set_Constant_Present
(Type_Def
, Constant_Present
(Access_Def
));
11907 Set_All_Present
(Type_Def
, All_Present
(Access_Def
));
11910 Set_Null_Exclusion_Present
11911 (Type_Def
, Null_Exclusion_Present
(Access_Def
));
11914 Make_Full_Type_Declaration
(Loc
,
11915 Defining_Identifier
=> Anon_Access
,
11916 Type_Definition
=> Type_Def
);
11918 Insert_Before
(Typ_Decl
, Decl
);
11921 -- At first sight we could add here the extra formals of an access to
11922 -- subprogram; however, it must delayed till the freeze point so that
11923 -- we know the convention.
11925 if Nkind
(Comp_Def
) = N_Component_Definition
then
11927 Make_Component_Definition
(Loc
,
11928 Subtype_Indication
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
11930 pragma Assert
(Nkind
(Comp_Def
) = N_Discriminant_Specification
);
11932 Make_Discriminant_Specification
(Loc
,
11933 Defining_Identifier
=> Defining_Identifier
(Comp_Def
),
11934 Discriminant_Type
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
11937 if Ekind
(Designated_Type
(Anon_Access
)) = E_Subprogram_Type
then
11938 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Subprogram_Type
);
11940 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Type
);
11943 Set_Is_Local_Anonymous_Access
(Anon_Access
);
11945 end Check_Anonymous_Access_Component
;
11947 ---------------------------------------
11948 -- Check_Anonymous_Access_Components --
11949 ---------------------------------------
11951 procedure Check_Anonymous_Access_Components
11952 (Typ_Decl
: Node_Id
;
11955 Comp_List
: Node_Id
)
11959 if No
(Comp_List
) then
11963 Comp
:= First
(Component_Items
(Comp_List
));
11964 while Present
(Comp
) loop
11965 if Nkind
(Comp
) = N_Component_Declaration
then
11966 Check_Anonymous_Access_Component
11967 (Typ_Decl
, Typ
, Prev
,
11968 Component_Definition
(Comp
),
11969 Access_Definition
(Component_Definition
(Comp
)));
11975 if Present
(Variant_Part
(Comp_List
)) then
11979 V
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
11980 while Present
(V
) loop
11981 Check_Anonymous_Access_Components
11982 (Typ_Decl
, Typ
, Prev
, Component_List
(V
));
11983 Next_Non_Pragma
(V
);
11987 end Check_Anonymous_Access_Components
;
11989 ----------------------
11990 -- Check_Completion --
11991 ----------------------
11993 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
11996 procedure Post_Error
;
11997 -- Post error message for lack of completion for entity E
12003 procedure Post_Error
is
12004 procedure Missing_Body
;
12005 -- Output missing body message
12011 procedure Missing_Body
is
12013 -- Spec is in same unit, so we can post on spec
12015 if In_Same_Source_Unit
(Body_Id
, E
) then
12016 Error_Msg_N
("missing body for &", E
);
12018 -- Spec is in a separate unit, so we have to post on the body
12021 Error_Msg_NE
("missing body for & declared#!", Body_Id
, E
);
12025 -- Start of processing for Post_Error
12028 if not Comes_From_Source
(E
) then
12029 if Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12031 -- It may be an anonymous protected type created for a
12032 -- single variable. Post error on variable, if present.
12038 Var
:= First_Entity
(Current_Scope
);
12039 while Present
(Var
) loop
12040 exit when Etype
(Var
) = E
12041 and then Comes_From_Source
(Var
);
12046 if Present
(Var
) then
12053 -- If a generated entity has no completion, then either previous
12054 -- semantic errors have disabled the expansion phase, or else we had
12055 -- missing subunits, or else we are compiling without expansion,
12056 -- or else something is very wrong.
12058 if not Comes_From_Source
(E
) then
12060 (Serious_Errors_Detected
> 0
12061 or else Configurable_Run_Time_Violations
> 0
12062 or else Subunits_Missing
12063 or else not Expander_Active
);
12066 -- Here for source entity
12069 -- Here if no body to post the error message, so we post the error
12070 -- on the declaration that has no completion. This is not really
12071 -- the right place to post it, think about this later ???
12073 if No
(Body_Id
) then
12074 if Is_Type
(E
) then
12076 ("missing full declaration for }", Parent
(E
), E
);
12078 Error_Msg_NE
("missing body for &", Parent
(E
), E
);
12081 -- Package body has no completion for a declaration that appears
12082 -- in the corresponding spec. Post error on the body, with a
12083 -- reference to the non-completed declaration.
12086 Error_Msg_Sloc
:= Sloc
(E
);
12088 if Is_Type
(E
) then
12089 Error_Msg_NE
("missing full declaration for }!", Body_Id
, E
);
12091 elsif Is_Overloadable
(E
)
12092 and then Current_Entity_In_Scope
(E
) /= E
12094 -- It may be that the completion is mistyped and appears as
12095 -- a distinct overloading of the entity.
12098 Candidate
: constant Entity_Id
:=
12099 Current_Entity_In_Scope
(E
);
12100 Decl
: constant Node_Id
:=
12101 Unit_Declaration_Node
(Candidate
);
12104 if Is_Overloadable
(Candidate
)
12105 and then Ekind
(Candidate
) = Ekind
(E
)
12106 and then Nkind
(Decl
) = N_Subprogram_Body
12107 and then Acts_As_Spec
(Decl
)
12109 Check_Type_Conformant
(Candidate
, E
);
12125 Pack_Id
: constant Entity_Id
:= Current_Scope
;
12127 -- Start of processing for Check_Completion
12130 E
:= First_Entity
(Pack_Id
);
12131 while Present
(E
) loop
12132 if Is_Intrinsic_Subprogram
(E
) then
12135 -- The following situation requires special handling: a child unit
12136 -- that appears in the context clause of the body of its parent:
12138 -- procedure Parent.Child (...);
12140 -- with Parent.Child;
12141 -- package body Parent is
12143 -- Here Parent.Child appears as a local entity, but should not be
12144 -- flagged as requiring completion, because it is a compilation
12147 -- Ignore missing completion for a subprogram that does not come from
12148 -- source (including the _Call primitive operation of RAS types,
12149 -- which has to have the flag Comes_From_Source for other purposes):
12150 -- we assume that the expander will provide the missing completion.
12151 -- In case of previous errors, other expansion actions that provide
12152 -- bodies for null procedures with not be invoked, so inhibit message
12155 -- Note that E_Operator is not in the list that follows, because
12156 -- this kind is reserved for predefined operators, that are
12157 -- intrinsic and do not need completion.
12159 elsif Ekind
(E
) in E_Function
12161 | E_Generic_Function
12162 | E_Generic_Procedure
12164 if Has_Completion
(E
) then
12167 elsif Is_Subprogram
(E
) and then Is_Abstract_Subprogram
(E
) then
12170 elsif Is_Subprogram
(E
)
12171 and then (not Comes_From_Source
(E
)
12172 or else Chars
(E
) = Name_uCall
)
12177 Nkind
(Parent
(Unit_Declaration_Node
(E
))) = N_Compilation_Unit
12181 elsif Nkind
(Parent
(E
)) = N_Procedure_Specification
12182 and then Null_Present
(Parent
(E
))
12183 and then Serious_Errors_Detected
> 0
12191 elsif Is_Entry
(E
) then
12192 if not Has_Completion
(E
)
12193 and then Ekind
(Scope
(E
)) = E_Protected_Type
12198 elsif Is_Package_Or_Generic_Package
(E
) then
12199 if Unit_Requires_Body
(E
) then
12200 if not Has_Completion
(E
)
12201 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
12207 elsif not Is_Child_Unit
(E
) then
12208 May_Need_Implicit_Body
(E
);
12211 -- A formal incomplete type (Ada 2012) does not require a completion;
12212 -- other incomplete type declarations do.
12214 elsif Ekind
(E
) = E_Incomplete_Type
then
12215 if No
(Underlying_Type
(E
))
12216 and then not Is_Generic_Type
(E
)
12221 elsif Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12222 if not Has_Completion
(E
) then
12226 -- A single task declared in the current scope is a constant, verify
12227 -- that the body of its anonymous type is in the same scope. If the
12228 -- task is defined elsewhere, this may be a renaming declaration for
12229 -- which no completion is needed.
12231 elsif Ekind
(E
) = E_Constant
then
12232 if Ekind
(Etype
(E
)) = E_Task_Type
12233 and then not Has_Completion
(Etype
(E
))
12234 and then Scope
(Etype
(E
)) = Current_Scope
12239 elsif Ekind
(E
) = E_Record_Type
then
12240 if Is_Tagged_Type
(E
) then
12241 Check_Abstract_Overriding
(E
);
12242 Check_Conventions
(E
);
12245 Check_Aliased_Component_Types
(E
);
12247 elsif Ekind
(E
) = E_Array_Type
then
12248 Check_Aliased_Component_Types
(E
);
12254 end Check_Completion
;
12256 -------------------------------------
12257 -- Check_Constraining_Discriminant --
12258 -------------------------------------
12260 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
)
12262 New_Type
: constant Entity_Id
:= Etype
(New_Disc
);
12263 Old_Type
: Entity_Id
;
12266 -- If the record type contains an array constrained by the discriminant
12267 -- but with some different bound, the compiler tries to create a smaller
12268 -- range for the discriminant type (see exp_ch3.Adjust_Discriminants).
12269 -- In this case, where the discriminant type is a scalar type, the check
12270 -- must use the original discriminant type in the parent declaration.
12272 if Is_Scalar_Type
(New_Type
) then
12273 Old_Type
:= Entity
(Discriminant_Type
(Parent
(Old_Disc
)));
12275 Old_Type
:= Etype
(Old_Disc
);
12278 if not Subtypes_Statically_Compatible
(New_Type
, Old_Type
) then
12280 ("subtype must be statically compatible with parent discriminant",
12283 if not Predicates_Compatible
(New_Type
, Old_Type
) then
12285 ("\subtype predicate is not compatible with parent discriminant",
12289 end Check_Constraining_Discriminant
;
12291 ------------------------------------
12292 -- Check_CPP_Type_Has_No_Defaults --
12293 ------------------------------------
12295 procedure Check_CPP_Type_Has_No_Defaults
(T
: Entity_Id
) is
12296 Tdef
: constant Node_Id
:= Type_Definition
(Declaration_Node
(T
));
12301 -- Obtain the component list
12303 if Nkind
(Tdef
) = N_Record_Definition
then
12304 Clist
:= Component_List
(Tdef
);
12305 else pragma Assert
(Nkind
(Tdef
) = N_Derived_Type_Definition
);
12306 Clist
:= Component_List
(Record_Extension_Part
(Tdef
));
12309 -- Check all components to ensure no default expressions
12311 if Present
(Clist
) then
12312 Comp
:= First
(Component_Items
(Clist
));
12313 while Present
(Comp
) loop
12314 if Present
(Expression
(Comp
)) then
12316 ("component of imported 'C'P'P type cannot have "
12317 & "default expression", Expression
(Comp
));
12323 end Check_CPP_Type_Has_No_Defaults
;
12325 ----------------------------
12326 -- Check_Delta_Expression --
12327 ----------------------------
12329 procedure Check_Delta_Expression
(E
: Node_Id
) is
12331 if not (Is_Real_Type
(Etype
(E
))) then
12332 Wrong_Type
(E
, Any_Real
);
12334 elsif not Is_OK_Static_Expression
(E
) then
12335 Flag_Non_Static_Expr
12336 ("non-static expression used for delta value!", E
);
12338 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
12339 Error_Msg_N
("delta expression must be positive", E
);
12345 -- If any of above errors occurred, then replace the incorrect
12346 -- expression by the real 0.1, which should prevent further errors.
12349 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
12350 Analyze_And_Resolve
(E
, Standard_Float
);
12351 end Check_Delta_Expression
;
12353 -----------------------------
12354 -- Check_Digits_Expression --
12355 -----------------------------
12357 procedure Check_Digits_Expression
(E
: Node_Id
) is
12359 if not (Is_Integer_Type
(Etype
(E
))) then
12360 Wrong_Type
(E
, Any_Integer
);
12362 elsif not Is_OK_Static_Expression
(E
) then
12363 Flag_Non_Static_Expr
12364 ("non-static expression used for digits value!", E
);
12366 elsif Expr_Value
(E
) <= 0 then
12367 Error_Msg_N
("digits value must be greater than zero", E
);
12373 -- If any of above errors occurred, then replace the incorrect
12374 -- expression by the integer 1, which should prevent further errors.
12376 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
12377 Analyze_And_Resolve
(E
, Standard_Integer
);
12379 end Check_Digits_Expression
;
12381 --------------------------
12382 -- Check_Initialization --
12383 --------------------------
12385 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
12387 -- Special processing for limited types
12389 if Is_Limited_Type
(T
)
12390 and then not In_Instance
12391 and then not In_Inlined_Body
12393 if not OK_For_Limited_Init
(T
, Exp
) then
12395 -- In GNAT mode, this is just a warning, to allow it to be evilly
12396 -- turned off. Otherwise it is a real error.
12400 ("??cannot initialize entities of limited type!", Exp
);
12402 elsif Ada_Version
< Ada_2005
then
12404 -- The side effect removal machinery may generate illegal Ada
12405 -- code to avoid the usage of access types and 'reference in
12406 -- SPARK mode. Since this is legal code with respect to theorem
12407 -- proving, do not emit the error.
12410 and then Nkind
(Exp
) = N_Function_Call
12411 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
12412 and then not Comes_From_Source
12413 (Defining_Identifier
(Parent
(Exp
)))
12419 ("cannot initialize entities of limited type", Exp
);
12420 Explain_Limited_Type
(T
, Exp
);
12424 -- Specialize error message according to kind of illegal
12425 -- initial expression. We check the Original_Node to cover
12426 -- cases where the initialization expression of an object
12427 -- declaration generated by the compiler has been rewritten
12428 -- (such as for dispatching calls).
12430 if Nkind
(Original_Node
(Exp
)) = N_Type_Conversion
12432 Nkind
(Expression
(Original_Node
(Exp
))) = N_Function_Call
12434 -- No error for internally-generated object declarations,
12435 -- which can come from build-in-place assignment statements.
12437 if Nkind
(Parent
(Exp
)) = N_Object_Declaration
12438 and then not Comes_From_Source
12439 (Defining_Identifier
(Parent
(Exp
)))
12445 ("illegal context for call to function with limited "
12451 ("initialization of limited object requires aggregate or "
12452 & "function call", Exp
);
12458 -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag gets
12459 -- set unless we can be sure that no range check is required.
12461 if not Expander_Active
12462 and then Is_Scalar_Type
(T
)
12463 and then not Is_In_Range
(Exp
, T
, Assume_Valid
=> True)
12465 Set_Do_Range_Check
(Exp
);
12467 end Check_Initialization
;
12469 ----------------------
12470 -- Check_Interfaces --
12471 ----------------------
12473 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
) is
12474 Parent_Type
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
12477 Iface_Def
: Node_Id
;
12478 Iface_Typ
: Entity_Id
;
12479 Parent_Node
: Node_Id
;
12481 Is_Task
: Boolean := False;
12482 -- Set True if parent type or any progenitor is a task interface
12484 Is_Protected
: Boolean := False;
12485 -- Set True if parent type or any progenitor is a protected interface
12487 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
);
12488 -- Check that a progenitor is compatible with declaration. If an error
12489 -- message is output, it is posted on Error_Node.
12495 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
) is
12496 Iface_Id
: constant Entity_Id
:=
12497 Defining_Identifier
(Parent
(Iface_Def
));
12498 Type_Def
: Node_Id
;
12501 if Nkind
(N
) = N_Private_Extension_Declaration
then
12504 Type_Def
:= Type_Definition
(N
);
12507 if Is_Task_Interface
(Iface_Id
) then
12510 elsif Is_Protected_Interface
(Iface_Id
) then
12511 Is_Protected
:= True;
12514 if Is_Synchronized_Interface
(Iface_Id
) then
12516 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
12517 -- extension derived from a synchronized interface must explicitly
12518 -- be declared synchronized, because the full view will be a
12519 -- synchronized type.
12521 if Nkind
(N
) = N_Private_Extension_Declaration
then
12522 if not Synchronized_Present
(N
) then
12524 ("private extension of& must be explicitly synchronized",
12528 -- However, by 3.9.4(16/2), a full type that is a record extension
12529 -- is never allowed to derive from a synchronized interface (note
12530 -- that interfaces must be excluded from this check, because those
12531 -- are represented by derived type definitions in some cases).
12533 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12534 and then not Interface_Present
(Type_Definition
(N
))
12536 Error_Msg_N
("record extension cannot derive from synchronized "
12537 & "interface", Error_Node
);
12541 -- Check that the characteristics of the progenitor are compatible
12542 -- with the explicit qualifier in the declaration.
12543 -- The check only applies to qualifiers that come from source.
12544 -- Limited_Present also appears in the declaration of corresponding
12545 -- records, and the check does not apply to them.
12547 if Limited_Present
(Type_Def
)
12549 Is_Concurrent_Record_Type
(Defining_Identifier
(N
))
12551 if Is_Limited_Interface
(Parent_Type
)
12552 and then not Is_Limited_Interface
(Iface_Id
)
12555 ("progenitor & must be limited interface",
12556 Error_Node
, Iface_Id
);
12559 (Task_Present
(Iface_Def
)
12560 or else Protected_Present
(Iface_Def
)
12561 or else Synchronized_Present
(Iface_Def
))
12562 and then Nkind
(N
) /= N_Private_Extension_Declaration
12563 and then not Error_Posted
(N
)
12566 ("progenitor & must be limited interface",
12567 Error_Node
, Iface_Id
);
12570 -- Protected interfaces can only inherit from limited, synchronized
12571 -- or protected interfaces.
12573 elsif Nkind
(N
) = N_Full_Type_Declaration
12574 and then Protected_Present
(Type_Def
)
12576 if Limited_Present
(Iface_Def
)
12577 or else Synchronized_Present
(Iface_Def
)
12578 or else Protected_Present
(Iface_Def
)
12582 elsif Task_Present
(Iface_Def
) then
12583 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12584 & "from task interface", Error_Node
);
12587 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12588 & "from non-limited interface", Error_Node
);
12591 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
12592 -- limited and synchronized.
12594 elsif Synchronized_Present
(Type_Def
) then
12595 if Limited_Present
(Iface_Def
)
12596 or else Synchronized_Present
(Iface_Def
)
12600 elsif Protected_Present
(Iface_Def
)
12601 and then Nkind
(N
) /= N_Private_Extension_Declaration
12603 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12604 & "from protected interface", Error_Node
);
12606 elsif Task_Present
(Iface_Def
)
12607 and then Nkind
(N
) /= N_Private_Extension_Declaration
12609 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12610 & "from task interface", Error_Node
);
12612 elsif not Is_Limited_Interface
(Iface_Id
) then
12613 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12614 & "from non-limited interface", Error_Node
);
12617 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
12618 -- synchronized or task interfaces.
12620 elsif Nkind
(N
) = N_Full_Type_Declaration
12621 and then Task_Present
(Type_Def
)
12623 if Limited_Present
(Iface_Def
)
12624 or else Synchronized_Present
(Iface_Def
)
12625 or else Task_Present
(Iface_Def
)
12629 elsif Protected_Present
(Iface_Def
) then
12630 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12631 & "protected interface", Error_Node
);
12634 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12635 & "non-limited interface", Error_Node
);
12640 -- Start of processing for Check_Interfaces
12643 if Is_Interface
(Parent_Type
) then
12644 if Is_Task_Interface
(Parent_Type
) then
12647 elsif Is_Protected_Interface
(Parent_Type
) then
12648 Is_Protected
:= True;
12652 if Nkind
(N
) = N_Private_Extension_Declaration
then
12654 -- Check that progenitors are compatible with declaration
12656 Iface
:= First
(Interface_List
(Def
));
12657 while Present
(Iface
) loop
12658 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12660 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12661 Iface_Def
:= Type_Definition
(Parent_Node
);
12663 if not Is_Interface
(Iface_Typ
) then
12664 Diagnose_Interface
(Iface
, Iface_Typ
);
12666 Check_Ifaces
(Iface_Def
, Iface
);
12672 if Is_Task
and Is_Protected
then
12674 ("type cannot derive from task and protected interface", N
);
12680 -- Full type declaration of derived type.
12681 -- Check compatibility with parent if it is interface type
12683 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12684 and then Is_Interface
(Parent_Type
)
12686 Parent_Node
:= Parent
(Parent_Type
);
12688 -- More detailed checks for interface varieties
12691 (Iface_Def
=> Type_Definition
(Parent_Node
),
12692 Error_Node
=> Subtype_Indication
(Type_Definition
(N
)));
12695 Iface
:= First
(Interface_List
(Def
));
12696 while Present
(Iface
) loop
12697 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12699 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12700 Iface_Def
:= Type_Definition
(Parent_Node
);
12702 if not Is_Interface
(Iface_Typ
) then
12703 Diagnose_Interface
(Iface
, Iface_Typ
);
12706 -- "The declaration of a specific descendant of an interface
12707 -- type freezes the interface type" RM 13.14
12709 Freeze_Before
(N
, Iface_Typ
);
12710 Check_Ifaces
(Iface_Def
, Error_Node
=> Iface
);
12716 if Is_Task
and Is_Protected
then
12718 ("type cannot derive from task and protected interface", N
);
12720 end Check_Interfaces
;
12722 ------------------------------------
12723 -- Check_Or_Process_Discriminants --
12724 ------------------------------------
12726 -- If an incomplete or private type declaration was already given for the
12727 -- type, the discriminants may have already been processed if they were
12728 -- present on the incomplete declaration. In this case a full conformance
12729 -- check has been performed in Find_Type_Name, and we then recheck here
12730 -- some properties that can't be checked on the partial view alone.
12731 -- Otherwise we call Process_Discriminants.
12733 procedure Check_Or_Process_Discriminants
12736 Prev
: Entity_Id
:= Empty
)
12739 if Has_Discriminants
(T
) then
12741 -- Discriminants are already set on T if they were already present
12742 -- on the partial view. Make them visible to component declarations.
12746 -- Discriminant on T (full view) referencing expr on partial view
12748 Prev_D
: Entity_Id
;
12749 -- Entity of corresponding discriminant on partial view
12752 -- Discriminant specification for full view, expression is
12753 -- the syntactic copy on full view (which has been checked for
12754 -- conformance with partial view), only used here to post error
12758 D
:= First_Discriminant
(T
);
12759 New_D
:= First
(Discriminant_Specifications
(N
));
12760 while Present
(D
) loop
12761 Prev_D
:= Current_Entity
(D
);
12762 Set_Current_Entity
(D
);
12763 Set_Is_Immediately_Visible
(D
);
12764 Set_Homonym
(D
, Prev_D
);
12766 -- Handle the case where there is an untagged partial view and
12767 -- the full view is tagged: must disallow discriminants with
12768 -- defaults, unless compiling for Ada 2012, which allows a
12769 -- limited tagged type to have defaulted discriminants (see
12770 -- AI05-0214). However, suppress error here if it was already
12771 -- reported on the default expression of the partial view.
12773 if Is_Tagged_Type
(T
)
12774 and then Present
(Expression
(Parent
(D
)))
12775 and then (not Is_Limited_Type
(Current_Scope
)
12776 or else Ada_Version
< Ada_2012
)
12777 and then not Error_Posted
(Expression
(Parent
(D
)))
12779 if Ada_Version
>= Ada_2012
then
12781 ("discriminants of nonlimited tagged type cannot have "
12783 Expression
(New_D
));
12786 ("discriminants of tagged type cannot have defaults",
12787 Expression
(New_D
));
12791 -- Ada 2005 (AI-230): Access discriminant allowed in
12792 -- non-limited record types.
12794 if Ada_Version
< Ada_2005
then
12796 -- This restriction gets applied to the full type here. It
12797 -- has already been applied earlier to the partial view.
12799 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
12802 Next_Discriminant
(D
);
12807 elsif Present
(Discriminant_Specifications
(N
)) then
12808 Process_Discriminants
(N
, Prev
);
12810 end Check_Or_Process_Discriminants
;
12812 ----------------------
12813 -- Check_Real_Bound --
12814 ----------------------
12816 procedure Check_Real_Bound
(Bound
: Node_Id
) is
12818 if not Is_Real_Type
(Etype
(Bound
)) then
12820 ("bound in real type definition must be of real type", Bound
);
12822 elsif not Is_OK_Static_Expression
(Bound
) then
12823 Flag_Non_Static_Expr
12824 ("non-static expression used for real type bound!", Bound
);
12831 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
12833 Resolve
(Bound
, Standard_Float
);
12834 end Check_Real_Bound
;
12836 ------------------------------
12837 -- Complete_Private_Subtype --
12838 ------------------------------
12840 procedure Complete_Private_Subtype
12843 Full_Base
: Entity_Id
;
12844 Related_Nod
: Node_Id
)
12846 Save_Next_Entity
: Entity_Id
;
12847 Save_Homonym
: Entity_Id
;
12850 -- Set semantic attributes for (implicit) private subtype completion.
12851 -- If the full type has no discriminants, then it is a copy of the
12852 -- full view of the base. Otherwise, it is a subtype of the base with
12853 -- a possible discriminant constraint. Save and restore the original
12854 -- Next_Entity field of full to ensure that the calls to Copy_Node do
12855 -- not corrupt the entity chain.
12857 Save_Next_Entity
:= Next_Entity
(Full
);
12858 Save_Homonym
:= Homonym
(Priv
);
12860 if Is_Private_Type
(Full_Base
)
12861 or else Is_Record_Type
(Full_Base
)
12862 or else Is_Concurrent_Type
(Full_Base
)
12864 Copy_Node
(Priv
, Full
);
12866 -- Note that the Etype of the full view is the same as the Etype of
12867 -- the partial view. In this fashion, the subtype has access to the
12868 -- correct view of the parent.
12870 Set_Has_Discriminants
(Full
, Has_Discriminants
(Full_Base
));
12871 Set_Has_Unknown_Discriminants
12872 (Full
, Has_Unknown_Discriminants
(Full_Base
));
12873 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
12874 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
12876 -- If the underlying base type is constrained, we know that the
12877 -- full view of the subtype is constrained as well (the converse
12878 -- is not necessarily true).
12880 if Is_Constrained
(Full_Base
) then
12881 Set_Is_Constrained
(Full
);
12885 Copy_Node
(Full_Base
, Full
);
12887 -- The following subtlety with the Etype of the full view needs to be
12888 -- taken into account here. One could think that it must naturally be
12889 -- set to the base type of the full base:
12891 -- Set_Etype (Full, Base_Type (Full_Base));
12893 -- so that the full view becomes a subtype of the full base when the
12894 -- latter is a base type, which must for example happen when the full
12895 -- base is declared as derived type. That's also correct if the full
12896 -- base is declared as an array type, or a floating-point type, or a
12897 -- fixed-point type, or a signed integer type, as these declarations
12898 -- create an implicit base type and a first subtype so the Etype of
12899 -- the full views must be the implicit base type. But that's wrong
12900 -- if the full base is declared as an access type, or an enumeration
12901 -- type, or a modular integer type, as these declarations directly
12902 -- create a base type, i.e. with Etype pointing to itself. Moreover
12903 -- the full base being declared in the private part, i.e. when the
12904 -- views are swapped, the end result is that the Etype of the full
12905 -- base is set to its private view in this case and that we need to
12906 -- propagate this setting to the full view in order for the subtype
12907 -- to be compatible with the base type.
12909 if Is_Base_Type
(Full_Base
)
12910 and then (Is_Derived_Type
(Full_Base
)
12911 or else Ekind
(Full_Base
) in Array_Kind
12912 or else Ekind
(Full_Base
) in Fixed_Point_Kind
12913 or else Ekind
(Full_Base
) in Float_Kind
12914 or else Ekind
(Full_Base
) in Signed_Integer_Kind
)
12916 Set_Etype
(Full
, Full_Base
);
12919 Set_Chars
(Full
, Chars
(Priv
));
12920 Set_Sloc
(Full
, Sloc
(Priv
));
12921 Conditional_Delay
(Full
, Priv
);
12924 Link_Entities
(Full
, Save_Next_Entity
);
12925 Set_Homonym
(Full
, Save_Homonym
);
12926 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
12928 if Ekind
(Full
) in Incomplete_Or_Private_Kind
then
12929 Reinit_Field_To_Zero
(Full
, F_Private_Dependents
);
12932 -- Set common attributes for all subtypes: kind, convention, etc.
12934 Mutate_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
12935 Set_Convention
(Full
, Convention
(Full_Base
));
12936 Set_Is_First_Subtype
(Full
, False);
12937 Set_Scope
(Full
, Scope
(Priv
));
12938 Set_Size_Info
(Full
, Full_Base
);
12939 Copy_RM_Size
(To
=> Full
, From
=> Full_Base
);
12940 Set_Is_Itype
(Full
);
12942 -- A subtype of a private-type-without-discriminants, whose full-view
12943 -- has discriminants with default expressions, is not constrained.
12945 if not Has_Discriminants
(Priv
) then
12946 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
12948 if Has_Discriminants
(Full_Base
) then
12949 Set_Discriminant_Constraint
12950 (Full
, Discriminant_Constraint
(Full_Base
));
12952 -- The partial view may have been indefinite, the full view
12955 Set_Has_Unknown_Discriminants
12956 (Full
, Has_Unknown_Discriminants
(Full_Base
));
12960 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
12961 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
12963 -- Freeze the private subtype entity if its parent is delayed, and not
12964 -- already frozen. We skip this processing if the type is an anonymous
12965 -- subtype of a record component, or is the corresponding record of a
12966 -- protected type, since these are processed when the enclosing type
12967 -- is frozen. If the parent type is declared in a nested package then
12968 -- the freezing of the private and full views also happens later.
12970 if not Is_Type
(Scope
(Full
)) then
12972 and then In_Same_Source_Unit
(Full
, Full_Base
)
12973 and then Scope
(Full_Base
) /= Scope
(Full
)
12975 Set_Has_Delayed_Freeze
(Full
);
12976 Set_Has_Delayed_Freeze
(Priv
);
12979 Set_Has_Delayed_Freeze
(Full
,
12980 Has_Delayed_Freeze
(Full_Base
)
12981 and then not Is_Frozen
(Full_Base
));
12985 Set_Freeze_Node
(Full
, Empty
);
12986 Set_Is_Frozen
(Full
, False);
12988 if Has_Discriminants
(Full
) then
12989 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
12990 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
12992 if Has_Unknown_Discriminants
(Full
) then
12993 Set_Discriminant_Constraint
(Full
, No_Elist
);
12997 if Ekind
(Full_Base
) = E_Record_Type
12998 and then Has_Discriminants
(Full_Base
)
12999 and then Has_Discriminants
(Priv
) -- might not, if errors
13000 and then not Has_Unknown_Discriminants
(Priv
)
13001 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
13003 Create_Constrained_Components
13004 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
13006 -- If the full base is itself derived from private, build a congruent
13007 -- subtype of its underlying full view, for use by the back end.
13009 elsif Is_Private_Type
(Full_Base
)
13010 and then Present
(Underlying_Full_View
(Full_Base
))
13013 Underlying_Full_Base
: constant Entity_Id
13014 := Underlying_Full_View
(Full_Base
);
13015 Underlying_Full
: constant Entity_Id
13016 := Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
13018 Set_Is_Itype
(Underlying_Full
);
13019 Set_Associated_Node_For_Itype
(Underlying_Full
, Related_Nod
);
13020 Complete_Private_Subtype
13021 (Priv
, Underlying_Full
, Underlying_Full_Base
, Related_Nod
);
13022 Set_Underlying_Full_View
(Full
, Underlying_Full
);
13023 Set_Is_Underlying_Full_View
(Underlying_Full
);
13026 elsif Is_Record_Type
(Full_Base
) then
13028 -- Show Full is simply a renaming of Full_Base
13030 Set_Cloned_Subtype
(Full
, Full_Base
);
13031 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
13033 -- Propagate predicates
13035 Propagate_Predicate_Attributes
(Full
, Full_Base
);
13038 -- It is unsafe to share the bounds of a scalar type, because the Itype
13039 -- is elaborated on demand, and if a bound is nonstatic, then different
13040 -- orders of elaboration in different units will lead to different
13041 -- external symbols.
13043 if Is_Scalar_Type
(Full_Base
) then
13044 Set_Scalar_Range
(Full
,
13045 Make_Range
(Sloc
(Related_Nod
),
13047 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
13049 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
13051 -- This completion inherits the bounds of the full parent, but if
13052 -- the parent is an unconstrained floating point type, so is the
13055 if Is_Floating_Point_Type
(Full_Base
) then
13056 Set_Includes_Infinities
13057 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
13061 -- ??? It seems that a lot of fields are missing that should be copied
13062 -- from Full_Base to Full. Here are some that are introduced in a
13063 -- non-disruptive way but a cleanup is necessary.
13065 if Is_Tagged_Type
(Full_Base
) then
13066 Set_Is_Tagged_Type
(Full
);
13067 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
13069 Set_Direct_Primitive_Operations
13070 (Full
, Direct_Primitive_Operations
(Full_Base
));
13071 Set_No_Tagged_Streams_Pragma
13072 (Full
, No_Tagged_Streams_Pragma
(Full_Base
));
13074 if Is_Interface
(Full_Base
) then
13075 Set_Is_Interface
(Full
);
13076 Set_Is_Limited_Interface
(Full
, Is_Limited_Interface
(Full_Base
));
13079 -- Inherit class_wide type of full_base in case the partial view was
13080 -- not tagged. Otherwise it has already been created when the private
13081 -- subtype was analyzed.
13083 if No
(Class_Wide_Type
(Full
)) then
13084 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
13087 -- If this is a subtype of a protected or task type, constrain its
13088 -- corresponding record, unless this is a subtype without constraints,
13089 -- i.e. a simple renaming as with an actual subtype in an instance.
13091 elsif Is_Concurrent_Type
(Full_Base
) then
13092 if Has_Discriminants
(Full
)
13093 and then Present
(Corresponding_Record_Type
(Full_Base
))
13095 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
13097 Set_Corresponding_Record_Type
(Full
,
13098 Constrain_Corresponding_Record
13099 (Full
, Corresponding_Record_Type
(Full_Base
), Related_Nod
));
13102 Set_Corresponding_Record_Type
(Full
,
13103 Corresponding_Record_Type
(Full_Base
));
13107 -- Link rep item chain, and also setting of Has_Predicates from private
13108 -- subtype to full subtype, since we will need these on the full subtype
13109 -- to create the predicate function. Note that the full subtype may
13110 -- already have rep items, inherited from the full view of the base
13111 -- type, so we must be sure not to overwrite these entries.
13116 Next_Item
: Node_Id
;
13117 Priv_Item
: Node_Id
;
13120 Item
:= First_Rep_Item
(Full
);
13121 Priv_Item
:= First_Rep_Item
(Priv
);
13123 -- If no existing rep items on full type, we can just link directly
13124 -- to the list of items on the private type, if any exist.. Same if
13125 -- the rep items are only those inherited from the base
13128 or else Nkind
(Item
) /= N_Aspect_Specification
13129 or else Entity
(Item
) = Full_Base
)
13130 and then Present
(First_Rep_Item
(Priv
))
13132 Set_First_Rep_Item
(Full
, Priv_Item
);
13134 -- Otherwise, search to the end of items currently linked to the full
13135 -- subtype and append the private items to the end. However, if Priv
13136 -- and Full already have the same list of rep items, then the append
13137 -- is not done, as that would create a circularity.
13139 -- The partial view may have a predicate and the rep item lists of
13140 -- both views agree when inherited from the same ancestor. In that
13141 -- case, simply propagate the list from one view to the other.
13142 -- A more complex analysis needed here ???
13144 elsif Present
(Priv_Item
)
13145 and then Item
= Next_Rep_Item
(Priv_Item
)
13147 Set_First_Rep_Item
(Full
, Priv_Item
);
13149 elsif Item
/= Priv_Item
then
13152 Next_Item
:= Next_Rep_Item
(Item
);
13153 exit when No
(Next_Item
);
13156 -- If the private view has aspect specifications, the full view
13157 -- inherits them. Since these aspects may already have been
13158 -- attached to the full view during derivation, do not append
13159 -- them if already present.
13161 if Item
= First_Rep_Item
(Priv
) then
13167 -- And link the private type items at the end of the chain
13170 Set_Next_Rep_Item
(Item
, First_Rep_Item
(Priv
));
13175 -- Make sure Has_Predicates is set on full type if it is set on the
13176 -- private type. Note that it may already be set on the full type and
13177 -- if so, we don't want to unset it. Similarly, propagate information
13178 -- about delayed aspects, because the corresponding pragmas must be
13179 -- analyzed when one of the views is frozen. This last step is needed
13180 -- in particular when the full type is a scalar type for which an
13181 -- anonymous base type is constructed.
13183 -- The predicate functions are generated either at the freeze point
13184 -- of the type or at the end of the visible part, and we must avoid
13185 -- generating them twice.
13187 Propagate_Predicate_Attributes
(Full
, Priv
);
13189 if Has_Delayed_Aspects
(Priv
) then
13190 Set_Has_Delayed_Aspects
(Full
);
13192 end Complete_Private_Subtype
;
13194 ----------------------------
13195 -- Constant_Redeclaration --
13196 ----------------------------
13198 procedure Constant_Redeclaration
13203 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
13204 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
13207 procedure Check_Possible_Deferred_Completion
13208 (Prev_Id
: Entity_Id
;
13209 Curr_Obj_Def
: Node_Id
);
13210 -- Determine whether the two object definitions describe the partial
13211 -- and the full view of a constrained deferred constant. Generate
13212 -- a subtype for the full view and verify that it statically matches
13213 -- the subtype of the partial view.
13215 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
13216 -- If deferred constant is an access type initialized with an allocator,
13217 -- check whether there is an illegal recursion in the definition,
13218 -- through a default value of some record subcomponent. This is normally
13219 -- detected when generating init procs, but requires this additional
13220 -- mechanism when expansion is disabled.
13222 ----------------------------------------
13223 -- Check_Possible_Deferred_Completion --
13224 ----------------------------------------
13226 procedure Check_Possible_Deferred_Completion
13227 (Prev_Id
: Entity_Id
;
13228 Curr_Obj_Def
: Node_Id
)
13230 Curr_Typ
: Entity_Id
;
13231 Prev_Typ
: constant Entity_Id
:= Etype
(Prev_Id
);
13232 Anon_Acc
: constant Boolean := Is_Anonymous_Access_Type
(Prev_Typ
);
13233 Mismatch
: Boolean := False;
13237 elsif Nkind
(Curr_Obj_Def
) = N_Subtype_Indication
then
13239 Loc
: constant Source_Ptr
:= Sloc
(N
);
13240 Def_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
13241 Decl
: constant Node_Id
:=
13242 Make_Subtype_Declaration
(Loc
,
13243 Defining_Identifier
=> Def_Id
,
13244 Subtype_Indication
=>
13245 Relocate_Node
(Curr_Obj_Def
));
13248 Insert_Before_And_Analyze
(N
, Decl
);
13249 Set_Etype
(Id
, Def_Id
);
13250 Curr_Typ
:= Def_Id
;
13253 Curr_Typ
:= Etype
(Curr_Obj_Def
);
13257 if Nkind
(Curr_Obj_Def
) /= N_Access_Definition
then
13259 elsif Has_Null_Exclusion
(Prev_Typ
)
13260 and then not Null_Exclusion_Present
(Curr_Obj_Def
)
13264 -- ??? Another check needed: mismatch if disagreement
13265 -- between designated types/profiles .
13268 Is_Constrained
(Prev_Typ
)
13269 and then not Subtypes_Statically_Match
(Prev_Typ
, Curr_Typ
);
13273 Error_Msg_Sloc
:= Sloc
(Prev_Id
);
13274 Error_Msg_N
("subtype does not statically match deferred "
13275 & "declaration #", N
);
13277 end Check_Possible_Deferred_Completion
;
13279 ---------------------------------
13280 -- Check_Recursive_Declaration --
13281 ---------------------------------
13283 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
13287 if Is_Record_Type
(Typ
) then
13288 Comp
:= First_Component
(Typ
);
13289 while Present
(Comp
) loop
13290 if Comes_From_Source
(Comp
) then
13291 if Present
(Expression
(Parent
(Comp
)))
13292 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
13293 and then Entity
(Expression
(Parent
(Comp
))) = Prev
13295 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
13297 ("illegal circularity with declaration for & #",
13301 elsif Is_Record_Type
(Etype
(Comp
)) then
13302 Check_Recursive_Declaration
(Etype
(Comp
));
13306 Next_Component
(Comp
);
13309 end Check_Recursive_Declaration
;
13311 -- Start of processing for Constant_Redeclaration
13314 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
13315 if Nkind
(Object_Definition
13316 (Parent
(Prev
))) = N_Subtype_Indication
13318 -- Find type of new declaration. The constraints of the two
13319 -- views must match statically, but there is no point in
13320 -- creating an itype for the full view.
13322 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
13323 Find_Type
(Subtype_Mark
(Obj_Def
));
13324 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
13327 Find_Type
(Obj_Def
);
13328 New_T
:= Entity
(Obj_Def
);
13334 -- The full view may impose a constraint, even if the partial
13335 -- view does not, so construct the subtype.
13337 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
13342 -- Current declaration is illegal, diagnosed below in Enter_Name
13348 -- If previous full declaration or a renaming declaration exists, or if
13349 -- a homograph is present, let Enter_Name handle it, either with an
13350 -- error or with the removal of an overridden implicit subprogram.
13351 -- The previous one is a full declaration if it has an expression
13352 -- (which in the case of an aggregate is indicated by the Init flag).
13354 if Ekind
(Prev
) /= E_Constant
13355 or else Nkind
(Parent
(Prev
)) = N_Object_Renaming_Declaration
13356 or else Present
(Expression
(Parent
(Prev
)))
13357 or else Has_Init_Expression
(Parent
(Prev
))
13358 or else Present
(Full_View
(Prev
))
13362 -- Verify that types of both declarations match, or else that both types
13363 -- are anonymous access types whose designated subtypes statically match
13364 -- (as allowed in Ada 2005 by AI-385).
13366 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
)
13368 (Ekind
(Etype
(Prev
)) /= E_Anonymous_Access_Type
13369 or else Ekind
(Etype
(New_T
)) /= E_Anonymous_Access_Type
13370 or else Is_Access_Constant
(Etype
(New_T
)) /=
13371 Is_Access_Constant
(Etype
(Prev
))
13372 or else Can_Never_Be_Null
(Etype
(New_T
)) /=
13373 Can_Never_Be_Null
(Etype
(Prev
))
13374 or else Null_Exclusion_Present
(Parent
(Prev
)) /=
13375 Null_Exclusion_Present
(Parent
(Id
))
13376 or else not Subtypes_Statically_Match
13377 (Designated_Type
(Etype
(Prev
)),
13378 Designated_Type
(Etype
(New_T
))))
13380 Error_Msg_Sloc
:= Sloc
(Prev
);
13381 Error_Msg_N
("type does not match declaration#", N
);
13382 Set_Full_View
(Prev
, Id
);
13383 Set_Etype
(Id
, Any_Type
);
13385 -- A deferred constant whose type is an anonymous array is always
13386 -- illegal (unless imported). A detailed error message might be
13387 -- helpful for Ada beginners.
13389 if Nkind
(Object_Definition
(Parent
(Prev
)))
13390 = N_Constrained_Array_Definition
13391 and then Nkind
(Object_Definition
(N
))
13392 = N_Constrained_Array_Definition
13394 Error_Msg_N
("\each anonymous array is a distinct type", N
);
13395 Error_Msg_N
("a deferred constant must have a named type",
13396 Object_Definition
(Parent
(Prev
)));
13400 Null_Exclusion_Present
(Parent
(Prev
))
13401 and then not Null_Exclusion_Present
(N
)
13403 Error_Msg_Sloc
:= Sloc
(Prev
);
13404 Error_Msg_N
("null-exclusion does not match declaration#", N
);
13405 Set_Full_View
(Prev
, Id
);
13406 Set_Etype
(Id
, Any_Type
);
13408 -- If so, process the full constant declaration
13411 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
13412 -- the deferred declaration is constrained, then the subtype defined
13413 -- by the subtype_indication in the full declaration shall match it
13416 Check_Possible_Deferred_Completion
13418 Curr_Obj_Def
=> Obj_Def
);
13420 Set_Full_View
(Prev
, Id
);
13421 Set_Is_Public
(Id
, Is_Public
(Prev
));
13422 Set_Is_Internal
(Id
);
13423 Append_Entity
(Id
, Current_Scope
);
13425 -- Check ALIASED present if present before (RM 7.4(7))
13427 if Is_Aliased
(Prev
)
13428 and then not Aliased_Present
(N
)
13430 Error_Msg_Sloc
:= Sloc
(Prev
);
13431 Error_Msg_N
("ALIASED required (see declaration #)", N
);
13434 -- Check that placement is in private part and that the incomplete
13435 -- declaration appeared in the visible part.
13437 if Ekind
(Current_Scope
) = E_Package
13438 and then not In_Private_Part
(Current_Scope
)
13440 Error_Msg_Sloc
:= Sloc
(Prev
);
13442 ("full constant for declaration # must be in private part", N
);
13444 elsif Ekind
(Current_Scope
) = E_Package
13446 List_Containing
(Parent
(Prev
)) /=
13447 Visible_Declarations
(Package_Specification
(Current_Scope
))
13450 ("deferred constant must be declared in visible part",
13454 if Is_Access_Type
(T
)
13455 and then Nkind
(Expression
(N
)) = N_Allocator
13457 Check_Recursive_Declaration
(Designated_Type
(T
));
13460 -- A deferred constant is a visible entity. If type has invariants,
13461 -- verify that the initial value satisfies them. This is not done in
13462 -- GNATprove mode, as GNATprove handles invariant checks itself.
13464 if Has_Invariants
(T
)
13465 and then Present
(Invariant_Procedure
(T
))
13466 and then not GNATprove_Mode
13469 Make_Invariant_Call
(New_Occurrence_Of
(Prev
, Sloc
(N
))));
13472 end Constant_Redeclaration
;
13474 ----------------------
13475 -- Constrain_Access --
13476 ----------------------
13478 procedure Constrain_Access
13479 (Def_Id
: in out Entity_Id
;
13481 Related_Nod
: Node_Id
)
13483 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13484 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
13485 Desig_Subtype
: Entity_Id
;
13486 Constraint_OK
: Boolean := True;
13489 if Is_Array_Type
(Desig_Type
) then
13490 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13491 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
13493 elsif (Is_Record_Type
(Desig_Type
)
13494 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
13495 and then not Is_Constrained
(Desig_Type
)
13497 -- If this is a constrained access definition for a record
13498 -- component, we leave the type as an unconstrained access,
13499 -- and mark the component so that its actual type is built
13500 -- at a point of use (e.g., an assignment statement). This
13501 -- is handled in Sem_Util.Build_Actual_Subtype_Of_Component.
13503 if Desig_Type
= Current_Scope
13504 and then No
(Def_Id
)
13508 (E_Void
, Related_Nod
, Scope_Id
=> Scope
(Desig_Type
));
13509 Mutate_Ekind
(Desig_Subtype
, E_Record_Subtype
);
13510 Def_Id
:= Entity
(Subtype_Mark
(S
));
13512 -- We indicate that the component has a per-object constraint
13513 -- for treatment at a point of use, even though the constraint
13514 -- may be independent of discriminants of the enclosing type.
13516 if Nkind
(Related_Nod
) = N_Component_Declaration
then
13517 Set_Has_Per_Object_Constraint
13518 (Defining_Identifier
(Related_Nod
));
13521 -- This call added to ensure that the constraint is analyzed
13522 -- (needed for a B test). Note that we still return early from
13523 -- this procedure to avoid recursive processing.
13525 Constrain_Discriminated_Type
13526 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
13530 -- Enforce rule that the constraint is illegal if there is an
13531 -- unconstrained view of the designated type. This means that the
13532 -- partial view (either a private type declaration or a derivation
13533 -- from a private type) has no discriminants. (Defect Report
13534 -- 8652/0008, Technical Corrigendum 1, checked by ACATS B371001).
13536 -- Rule updated for Ada 2005: The private type is said to have
13537 -- a constrained partial view, given that objects of the type
13538 -- can be declared. Furthermore, the rule applies to all access
13539 -- types, unlike the rule concerning default discriminants (see
13542 if (Ekind
(T
) = E_General_Access_Type
or else Ada_Version
>= Ada_2005
)
13543 and then Has_Private_Declaration
(Desig_Type
)
13544 and then In_Open_Scopes
(Scope
(Desig_Type
))
13545 and then Has_Discriminants
(Desig_Type
)
13548 Pack
: constant Node_Id
:=
13549 Unit_Declaration_Node
(Scope
(Desig_Type
));
13554 if Nkind
(Pack
) = N_Package_Declaration
then
13555 Decls
:= Visible_Declarations
(Specification
(Pack
));
13556 Decl
:= First
(Decls
);
13557 while Present
(Decl
) loop
13558 if (Nkind
(Decl
) = N_Private_Type_Declaration
13559 and then Chars
(Defining_Identifier
(Decl
)) =
13560 Chars
(Desig_Type
))
13563 (Nkind
(Decl
) = N_Full_Type_Declaration
13565 Chars
(Defining_Identifier
(Decl
)) =
13567 and then Is_Derived_Type
(Desig_Type
)
13569 Has_Private_Declaration
(Etype
(Desig_Type
)))
13571 if No
(Discriminant_Specifications
(Decl
)) then
13573 ("cannot constrain access type if designated "
13574 & "type has constrained partial view", S
);
13586 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13587 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
13588 For_Access
=> True);
13590 elsif Is_Concurrent_Type
(Desig_Type
)
13591 and then not Is_Constrained
(Desig_Type
)
13593 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13594 Constrain_Concurrent
(Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
13597 Error_Msg_N
("invalid constraint on access type", S
);
13599 -- We simply ignore an invalid constraint
13601 Desig_Subtype
:= Desig_Type
;
13602 Constraint_OK
:= False;
13605 if No
(Def_Id
) then
13606 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
13608 Mutate_Ekind
(Def_Id
, E_Access_Subtype
);
13611 if Constraint_OK
then
13612 Set_Etype
(Def_Id
, Base_Type
(T
));
13614 if Is_Private_Type
(Desig_Type
) then
13615 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
13618 Set_Etype
(Def_Id
, Any_Type
);
13621 Set_Size_Info
(Def_Id
, T
);
13622 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
13623 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
13624 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13625 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
13626 Set_Can_Never_Be_Null
(Def_Id
, Can_Never_Be_Null
(T
));
13628 Conditional_Delay
(Def_Id
, T
);
13630 -- AI-363 : Subtypes of general access types whose designated types have
13631 -- default discriminants are disallowed. In instances, the rule has to
13632 -- be checked against the actual, of which T is the subtype. In a
13633 -- generic body, the rule is checked assuming that the actual type has
13634 -- defaulted discriminants.
13636 if Ada_Version
>= Ada_2005
or else Warn_On_Ada_2005_Compatibility
then
13637 if Ekind
(Base_Type
(T
)) = E_General_Access_Type
13638 and then Has_Defaulted_Discriminants
(Desig_Type
)
13640 if Ada_Version
< Ada_2005
then
13642 ("access subtype of general access type would not " &
13643 "be allowed in Ada 2005?y?", S
);
13646 ("access subtype of general access type not allowed", S
);
13649 Error_Msg_N
("\discriminants have defaults", S
);
13651 elsif Is_Access_Type
(T
)
13652 and then Is_Generic_Type
(Desig_Type
)
13653 and then Has_Discriminants
(Desig_Type
)
13654 and then In_Package_Body
(Current_Scope
)
13656 if Ada_Version
< Ada_2005
then
13658 ("access subtype would not be allowed in generic body "
13659 & "in Ada 2005?y?", S
);
13662 ("access subtype not allowed in generic body", S
);
13666 ("\designated type is a discriminated formal", S
);
13669 end Constrain_Access
;
13671 ---------------------
13672 -- Constrain_Array --
13673 ---------------------
13675 procedure Constrain_Array
13676 (Def_Id
: in out Entity_Id
;
13678 Related_Nod
: Node_Id
;
13679 Related_Id
: Entity_Id
;
13680 Suffix
: Character)
13682 C
: constant Node_Id
:= Constraint
(SI
);
13683 Number_Of_Constraints
: Nat
:= 0;
13686 Constraint_OK
: Boolean := True;
13687 Is_FLB_Array_Subtype
: Boolean := False;
13690 T
:= Entity
(Subtype_Mark
(SI
));
13692 if Is_Access_Type
(T
) then
13693 T
:= Designated_Type
(T
);
13696 T
:= Underlying_Type
(T
);
13698 -- If an index constraint follows a subtype mark in a subtype indication
13699 -- then the type or subtype denoted by the subtype mark must not already
13700 -- impose an index constraint. The subtype mark must denote either an
13701 -- unconstrained array type or an access type whose designated type
13702 -- is such an array type... (RM 3.6.1)
13704 if Is_Constrained
(T
) then
13705 Error_Msg_N
("array type is already constrained", Subtype_Mark
(SI
));
13706 Constraint_OK
:= False;
13709 S
:= First
(Constraints
(C
));
13710 while Present
(S
) loop
13711 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
13715 -- In either case, the index constraint must provide a discrete
13716 -- range for each index of the array type and the type of each
13717 -- discrete range must be the same as that of the corresponding
13718 -- index. (RM 3.6.1)
13720 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
13721 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
13722 Constraint_OK
:= False;
13725 S
:= First
(Constraints
(C
));
13726 Index
:= First_Index
(T
);
13729 -- Apply constraints to each index type
13731 for J
in 1 .. Number_Of_Constraints
loop
13732 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
13734 -- If the subtype of the index has been set to indicate that
13735 -- it has a fixed lower bound, then record that the subtype's
13736 -- entity will need to be marked as being a fixed-lower-bound
13739 if S
= First
(Constraints
(C
)) then
13740 Is_FLB_Array_Subtype
:=
13741 Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
));
13743 -- If the parent subtype (or should this be Etype of that?)
13744 -- is an FLB array subtype, we flag an error, because we
13745 -- don't currently allow subtypes of such subtypes to
13746 -- specify a fixed lower bound for any of their indexes,
13747 -- even if the index of the parent subtype is a "range <>"
13750 if Is_FLB_Array_Subtype
13751 and then Is_Fixed_Lower_Bound_Array_Subtype
(T
)
13754 ("index with fixed lower bound not allowed for subtype "
13755 & "of fixed-lower-bound }", S
, T
);
13757 Is_FLB_Array_Subtype
:= False;
13760 elsif Is_FLB_Array_Subtype
13761 and then not Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13764 ("constrained index not allowed for fixed-lower-bound "
13765 & "subtype of}", S
, T
);
13767 elsif not Is_FLB_Array_Subtype
13768 and then Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13771 ("index with fixed lower bound not allowed for "
13772 & "constrained subtype of}", S
, T
);
13782 if No
(Def_Id
) then
13784 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
13785 Set_Parent
(Def_Id
, Related_Nod
);
13788 Mutate_Ekind
(Def_Id
, E_Array_Subtype
);
13791 Set_Size_Info
(Def_Id
, (T
));
13792 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13793 Set_Etype
(Def_Id
, Base_Type
(T
));
13795 if Constraint_OK
then
13796 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
13798 Set_First_Index
(Def_Id
, First_Index
(T
));
13801 Set_Is_Constrained
(Def_Id
, not Is_FLB_Array_Subtype
);
13802 Set_Is_Fixed_Lower_Bound_Array_Subtype
13803 (Def_Id
, Is_FLB_Array_Subtype
);
13804 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
13805 Set_Is_Independent
(Def_Id
, Is_Independent
(T
));
13806 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13808 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
13809 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
13811 -- A subtype does not inherit the Packed_Array_Impl_Type of is parent.
13812 -- We need to initialize the attribute because if Def_Id is previously
13813 -- analyzed through a limited_with clause, it will have the attributes
13814 -- of an incomplete type, one of which is an Elist that overlaps the
13815 -- Packed_Array_Impl_Type field.
13817 Set_Packed_Array_Impl_Type
(Def_Id
, Empty
);
13819 -- Build a freeze node if parent still needs one. Also make sure that
13820 -- the Depends_On_Private status is set because the subtype will need
13821 -- reprocessing at the time the base type does, and also we must set a
13822 -- conditional delay.
13824 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
13825 Conditional_Delay
(Def_Id
, T
);
13826 end Constrain_Array
;
13828 ------------------------------
13829 -- Constrain_Component_Type --
13830 ------------------------------
13832 function Constrain_Component_Type
13834 Constrained_Typ
: Entity_Id
;
13835 Related_Node
: Node_Id
;
13837 Constraints
: Elist_Id
) return Entity_Id
13839 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
13840 Compon_Type
: constant Entity_Id
:= Etype
(Comp
);
13842 function Build_Constrained_Array_Type
13843 (Old_Type
: Entity_Id
) return Entity_Id
;
13844 -- If Old_Type is an array type, one of whose indexes is constrained
13845 -- by a discriminant, build an Itype whose constraint replaces the
13846 -- discriminant with its value in the constraint.
13848 function Build_Constrained_Discriminated_Type
13849 (Old_Type
: Entity_Id
) return Entity_Id
;
13850 -- Ditto for record components. Handle the case where the constraint
13851 -- is a conversion of the discriminant value, introduced during
13854 function Build_Constrained_Access_Type
13855 (Old_Type
: Entity_Id
) return Entity_Id
;
13856 -- Ditto for access types. Makes use of previous two functions, to
13857 -- constrain designated type.
13859 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
13860 -- Returns True if Expr is a discriminant
13862 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
;
13863 -- Find the value of a discriminant named by Discr_Expr in Constraints
13865 -----------------------------------
13866 -- Build_Constrained_Access_Type --
13867 -----------------------------------
13869 function Build_Constrained_Access_Type
13870 (Old_Type
: Entity_Id
) return Entity_Id
13872 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
13874 Desig_Subtype
: Entity_Id
;
13878 -- If the original access type was not embedded in the enclosing
13879 -- type definition, there is no need to produce a new access
13880 -- subtype. In fact every access type with an explicit constraint
13881 -- generates an itype whose scope is the enclosing record.
13883 if not Is_Type
(Scope
(Old_Type
)) then
13886 elsif Is_Array_Type
(Desig_Type
) then
13887 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
13889 elsif Has_Discriminants
(Desig_Type
) then
13891 -- This may be an access type to an enclosing record type for
13892 -- which we are constructing the constrained components. Return
13893 -- the enclosing record subtype. This is not always correct,
13894 -- but avoids infinite recursion. ???
13896 Desig_Subtype
:= Any_Type
;
13898 for J
in reverse 0 .. Scope_Stack
.Last
loop
13899 Scop
:= Scope_Stack
.Table
(J
).Entity
;
13902 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
13904 Desig_Subtype
:= Scop
;
13907 exit when not Is_Type
(Scop
);
13910 if Desig_Subtype
= Any_Type
then
13912 Build_Constrained_Discriminated_Type
(Desig_Type
);
13919 if Desig_Subtype
/= Desig_Type
then
13921 -- The Related_Node better be here or else we won't be able
13922 -- to attach new itypes to a node in the tree.
13924 pragma Assert
(Present
(Related_Node
));
13926 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
13928 Set_Etype
(Itype
, Base_Type
(Old_Type
));
13929 Set_Size_Info
(Itype
, (Old_Type
));
13930 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
13931 Set_Depends_On_Private
(Itype
, Has_Private_Component
13933 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
13936 -- The new itype needs freezing when it depends on a not frozen
13937 -- type and the enclosing subtype needs freezing.
13939 if Has_Delayed_Freeze
(Constrained_Typ
)
13940 and then not Is_Frozen
(Constrained_Typ
)
13942 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
13950 end Build_Constrained_Access_Type
;
13952 ----------------------------------
13953 -- Build_Constrained_Array_Type --
13954 ----------------------------------
13956 function Build_Constrained_Array_Type
13957 (Old_Type
: Entity_Id
) return Entity_Id
13961 Old_Index
: Node_Id
;
13962 Range_Node
: Node_Id
;
13963 Constr_List
: List_Id
;
13965 Need_To_Create_Itype
: Boolean := False;
13968 Old_Index
:= First_Index
(Old_Type
);
13969 while Present
(Old_Index
) loop
13970 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
13972 if Is_Discriminant
(Lo_Expr
)
13974 Is_Discriminant
(Hi_Expr
)
13976 Need_To_Create_Itype
:= True;
13980 Next_Index
(Old_Index
);
13983 if Need_To_Create_Itype
then
13984 Constr_List
:= New_List
;
13986 Old_Index
:= First_Index
(Old_Type
);
13987 while Present
(Old_Index
) loop
13988 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
13990 if Is_Discriminant
(Lo_Expr
) then
13991 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
13994 if Is_Discriminant
(Hi_Expr
) then
13995 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
14000 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
14002 Append
(Range_Node
, To
=> Constr_List
);
14004 Next_Index
(Old_Index
);
14007 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
14012 end Build_Constrained_Array_Type
;
14014 ------------------------------------------
14015 -- Build_Constrained_Discriminated_Type --
14016 ------------------------------------------
14018 function Build_Constrained_Discriminated_Type
14019 (Old_Type
: Entity_Id
) return Entity_Id
14022 Constr_List
: List_Id
;
14023 Old_Constraint
: Elmt_Id
;
14025 Need_To_Create_Itype
: Boolean := False;
14028 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
14029 while Present
(Old_Constraint
) loop
14030 Expr
:= Node
(Old_Constraint
);
14032 if Is_Discriminant
(Expr
) then
14033 Need_To_Create_Itype
:= True;
14036 -- After expansion of discriminated task types, the value
14037 -- of the discriminant may be converted to a run-time type
14038 -- for restricted run-times. Propagate the value of the
14039 -- discriminant as well, so that e.g. the secondary stack
14040 -- component has a static constraint. Necessary for LLVM.
14042 elsif Nkind
(Expr
) = N_Type_Conversion
14043 and then Is_Discriminant
(Expression
(Expr
))
14045 Need_To_Create_Itype
:= True;
14049 Next_Elmt
(Old_Constraint
);
14052 if Need_To_Create_Itype
then
14053 Constr_List
:= New_List
;
14055 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
14056 while Present
(Old_Constraint
) loop
14057 Expr
:= Node
(Old_Constraint
);
14059 if Is_Discriminant
(Expr
) then
14060 Expr
:= Get_Discr_Value
(Expr
);
14062 elsif Nkind
(Expr
) = N_Type_Conversion
14063 and then Is_Discriminant
(Expression
(Expr
))
14065 Expr
:= New_Copy_Tree
(Expr
);
14066 Set_Expression
(Expr
, Get_Discr_Value
(Expression
(Expr
)));
14069 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
14071 Next_Elmt
(Old_Constraint
);
14074 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
14079 end Build_Constrained_Discriminated_Type
;
14081 ---------------------
14082 -- Get_Discr_Value --
14083 ---------------------
14085 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
is
14086 Discr_Id
: constant Entity_Id
:= Entity
(Discr_Expr
);
14087 -- Entity of a discriminant that appear as a standalone expression in
14088 -- the constraint of a component.
14094 -- The discriminant may be declared for the type, in which case we
14095 -- find it by iterating over the list of discriminants. If the
14096 -- discriminant is inherited from a parent type, it appears as the
14097 -- corresponding discriminant of the current type. This will be the
14098 -- case when constraining an inherited component whose constraint is
14099 -- given by a discriminant of the parent.
14101 D
:= First_Discriminant
(Typ
);
14102 E
:= First_Elmt
(Constraints
);
14104 while Present
(D
) loop
14106 or else D
= CR_Discriminant
(Discr_Id
)
14107 or else Corresponding_Discriminant
(D
) = Discr_Id
14109 return New_Copy_Tree
(Node
(E
));
14112 Next_Discriminant
(D
);
14116 -- The Corresponding_Discriminant mechanism is incomplete, because
14117 -- the correspondence between new and old discriminants is not one
14118 -- to one: one new discriminant can constrain several old ones. In
14119 -- that case, scan sequentially the stored_constraint, the list of
14120 -- discriminants of the parents, and the constraints.
14122 -- Previous code checked for the present of the Stored_Constraint
14123 -- list for the derived type, but did not use it at all. Should it
14124 -- be present when the component is a discriminated task type?
14126 if Is_Derived_Type
(Typ
)
14127 and then Scope
(Discr_Id
) = Etype
(Typ
)
14129 D
:= First_Discriminant
(Etype
(Typ
));
14130 E
:= First_Elmt
(Constraints
);
14131 while Present
(D
) loop
14132 if D
= Discr_Id
then
14133 return New_Copy_Tree
(Node
(E
));
14136 Next_Discriminant
(D
);
14141 -- Something is wrong if we did not find the value
14143 raise Program_Error
;
14144 end Get_Discr_Value
;
14146 ---------------------
14147 -- Is_Discriminant --
14148 ---------------------
14150 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
14151 Discrim_Scope
: Entity_Id
;
14154 if Denotes_Discriminant
(Expr
) then
14155 Discrim_Scope
:= Scope
(Entity
(Expr
));
14157 -- Either we have a reference to one of Typ's discriminants,
14159 pragma Assert
(Discrim_Scope
= Typ
14161 -- or to the discriminants of the parent type, in the case
14162 -- of a derivation of a tagged type with variants.
14164 or else Discrim_Scope
= Etype
(Typ
)
14165 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
14167 -- or same as above for the case where the discriminants
14168 -- were declared in Typ's private view.
14170 or else (Is_Private_Type
(Discrim_Scope
)
14171 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14173 -- or else we are deriving from the full view and the
14174 -- discriminant is declared in the private entity.
14176 or else (Is_Private_Type
(Typ
)
14177 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14179 -- Or we are constrained the corresponding record of a
14180 -- synchronized type that completes a private declaration.
14182 or else (Is_Concurrent_Record_Type
(Typ
)
14184 Corresponding_Concurrent_Type
(Typ
) = Discrim_Scope
)
14186 -- or we have a class-wide type, in which case make sure the
14187 -- discriminant found belongs to the root type.
14189 or else (Is_Class_Wide_Type
(Typ
)
14190 and then Etype
(Typ
) = Discrim_Scope
));
14195 -- In all other cases we have something wrong
14198 end Is_Discriminant
;
14200 -- Start of processing for Constrain_Component_Type
14203 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
14204 and then Comes_From_Source
(Parent
(Comp
))
14205 and then Comes_From_Source
14206 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14209 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14211 return Compon_Type
;
14213 elsif Is_Array_Type
(Compon_Type
) then
14214 return Build_Constrained_Array_Type
(Compon_Type
);
14216 elsif Has_Discriminants
(Compon_Type
) then
14217 return Build_Constrained_Discriminated_Type
(Compon_Type
);
14219 elsif Is_Access_Type
(Compon_Type
) then
14220 return Build_Constrained_Access_Type
(Compon_Type
);
14223 return Compon_Type
;
14225 end Constrain_Component_Type
;
14227 --------------------------
14228 -- Constrain_Concurrent --
14229 --------------------------
14231 -- For concurrent types, the associated record value type carries the same
14232 -- discriminants, so when we constrain a concurrent type, we must constrain
14233 -- the corresponding record type as well.
14235 procedure Constrain_Concurrent
14236 (Def_Id
: in out Entity_Id
;
14238 Related_Nod
: Node_Id
;
14239 Related_Id
: Entity_Id
;
14240 Suffix
: Character)
14242 -- Retrieve Base_Type to ensure getting to the concurrent type in the
14243 -- case of a private subtype (needed when only doing semantic analysis).
14245 T_Ent
: Entity_Id
:= Base_Type
(Entity
(Subtype_Mark
(SI
)));
14249 if Is_Access_Type
(T_Ent
) then
14250 T_Ent
:= Designated_Type
(T_Ent
);
14253 T_Val
:= Corresponding_Record_Type
(T_Ent
);
14255 if Present
(T_Val
) then
14257 if No
(Def_Id
) then
14258 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14260 -- Elaborate itype now, as it may be used in a subsequent
14261 -- synchronized operation in another scope.
14263 if Nkind
(Related_Nod
) = N_Full_Type_Declaration
then
14264 Build_Itype_Reference
(Def_Id
, Related_Nod
);
14268 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14269 Set_First_Private_Entity
(Def_Id
, First_Private_Entity
(T_Ent
));
14271 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
14272 Set_Corresponding_Record_Type
(Def_Id
,
14273 Constrain_Corresponding_Record
(Def_Id
, T_Val
, Related_Nod
));
14276 -- If there is no associated record, expansion is disabled and this
14277 -- is a generic context. Create a subtype in any case, so that
14278 -- semantic analysis can proceed.
14280 if No
(Def_Id
) then
14281 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14284 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14286 end Constrain_Concurrent
;
14288 ------------------------------------
14289 -- Constrain_Corresponding_Record --
14290 ------------------------------------
14292 function Constrain_Corresponding_Record
14293 (Prot_Subt
: Entity_Id
;
14294 Corr_Rec
: Entity_Id
;
14295 Related_Nod
: Node_Id
) return Entity_Id
14297 T_Sub
: constant Entity_Id
:=
14299 (Ekind
=> E_Record_Subtype
,
14300 Related_Nod
=> Related_Nod
,
14301 Related_Id
=> Corr_Rec
,
14303 Suffix_Index
=> -1);
14306 Set_Etype
(T_Sub
, Corr_Rec
);
14307 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
14308 Set_Is_Tagged_Type
(T_Sub
, Is_Tagged_Type
(Corr_Rec
));
14309 Set_Is_Constrained
(T_Sub
, True);
14310 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
14311 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
14313 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
14314 Set_Discriminant_Constraint
14315 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
14316 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
14317 Create_Constrained_Components
14318 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
14321 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
14323 if Ekind
(Scope
(Prot_Subt
)) /= E_Record_Type
then
14324 Conditional_Delay
(T_Sub
, Corr_Rec
);
14327 -- This is a component subtype: it will be frozen in the context of
14328 -- the enclosing record's init_proc, so that discriminant references
14329 -- are resolved to discriminals. (Note: we used to skip freezing
14330 -- altogether in that case, which caused errors downstream for
14331 -- components of a bit packed array type).
14333 Set_Has_Delayed_Freeze
(T_Sub
);
14337 end Constrain_Corresponding_Record
;
14339 -----------------------
14340 -- Constrain_Decimal --
14341 -----------------------
14343 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14344 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14345 C
: constant Node_Id
:= Constraint
(S
);
14346 Loc
: constant Source_Ptr
:= Sloc
(C
);
14347 Range_Expr
: Node_Id
;
14348 Digits_Expr
: Node_Id
;
14353 Mutate_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
14355 if Nkind
(C
) = N_Range_Constraint
then
14356 Range_Expr
:= Range_Expression
(C
);
14357 Digits_Val
:= Digits_Value
(T
);
14360 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
14362 Digits_Expr
:= Digits_Expression
(C
);
14363 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
14365 Check_Digits_Expression
(Digits_Expr
);
14366 Digits_Val
:= Expr_Value
(Digits_Expr
);
14368 if Digits_Val
> Digits_Value
(T
) then
14370 ("digits expression is incompatible with subtype", C
);
14371 Digits_Val
:= Digits_Value
(T
);
14374 if Present
(Range_Constraint
(C
)) then
14375 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
14377 Range_Expr
:= Empty
;
14381 Set_Etype
(Def_Id
, Base_Type
(T
));
14382 Set_Size_Info
(Def_Id
, (T
));
14383 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14384 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
14385 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
14386 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14387 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
14388 Set_Digits_Value
(Def_Id
, Digits_Val
);
14390 -- Manufacture range from given digits value if no range present
14392 if No
(Range_Expr
) then
14393 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
14397 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
14399 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
14402 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
14403 Set_Discrete_RM_Size
(Def_Id
);
14405 -- Unconditionally delay the freeze, since we cannot set size
14406 -- information in all cases correctly until the freeze point.
14408 Set_Has_Delayed_Freeze
(Def_Id
);
14409 end Constrain_Decimal
;
14411 ----------------------------------
14412 -- Constrain_Discriminated_Type --
14413 ----------------------------------
14415 procedure Constrain_Discriminated_Type
14416 (Def_Id
: Entity_Id
;
14418 Related_Nod
: Node_Id
;
14419 For_Access
: Boolean := False)
14421 E
: Entity_Id
:= Entity
(Subtype_Mark
(S
));
14424 procedure Fixup_Bad_Constraint
;
14425 -- Called after finding a bad constraint, and after having posted an
14426 -- appropriate error message. The goal is to leave type Def_Id in as
14427 -- reasonable state as possible.
14429 --------------------------
14430 -- Fixup_Bad_Constraint --
14431 --------------------------
14433 procedure Fixup_Bad_Constraint
is
14435 -- Set a reasonable Ekind for the entity, including incomplete types.
14437 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
14439 -- Set Etype to the known type, to reduce chances of cascaded errors
14441 Set_Etype
(Def_Id
, E
);
14442 Set_Error_Posted
(Def_Id
);
14443 end Fixup_Bad_Constraint
;
14448 Constr
: Elist_Id
:= New_Elmt_List
;
14450 -- Start of processing for Constrain_Discriminated_Type
14453 C
:= Constraint
(S
);
14455 -- A discriminant constraint is only allowed in a subtype indication,
14456 -- after a subtype mark. This subtype mark must denote either a type
14457 -- with discriminants, or an access type whose designated type is a
14458 -- type with discriminants. A discriminant constraint specifies the
14459 -- values of these discriminants (RM 3.7.2(5)).
14461 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
14463 if Is_Access_Type
(T
) then
14464 T
:= Designated_Type
(T
);
14467 -- In an instance it may be necessary to retrieve the full view of a
14468 -- type with unknown discriminants, or a full view with defaulted
14469 -- discriminants. In other contexts the constraint is illegal.
14472 and then Is_Private_Type
(T
)
14473 and then Present
(Full_View
(T
))
14475 (Has_Unknown_Discriminants
(T
)
14477 (not Has_Discriminants
(T
)
14478 and then Has_Defaulted_Discriminants
(Full_View
(T
))))
14480 T
:= Full_View
(T
);
14481 E
:= Full_View
(E
);
14484 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal. Avoid
14485 -- generating an error for access-to-incomplete subtypes.
14487 if Ada_Version
>= Ada_2005
14488 and then Ekind
(T
) = E_Incomplete_Type
14489 and then Nkind
(Parent
(S
)) = N_Subtype_Declaration
14490 and then not Is_Itype
(Def_Id
)
14492 -- A little sanity check: emit an error message if the type has
14493 -- discriminants to begin with. Type T may be a regular incomplete
14494 -- type or imported via a limited with clause.
14496 if Has_Discriminants
(T
)
14497 or else (From_Limited_With
(T
)
14498 and then Present
(Non_Limited_View
(T
))
14499 and then Nkind
(Parent
(Non_Limited_View
(T
))) =
14500 N_Full_Type_Declaration
14501 and then Present
(Discriminant_Specifications
14502 (Parent
(Non_Limited_View
(T
)))))
14505 ("(Ada 2005) incomplete subtype may not be constrained", C
);
14507 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14510 Fixup_Bad_Constraint
;
14513 -- Check that the type has visible discriminants. The type may be
14514 -- a private type with unknown discriminants whose full view has
14515 -- discriminants which are invisible.
14517 elsif not Has_Discriminants
(T
)
14519 (Has_Unknown_Discriminants
(T
)
14520 and then Is_Private_Type
(T
))
14522 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14523 Fixup_Bad_Constraint
;
14526 elsif Is_Constrained
(E
)
14527 or else (Ekind
(E
) = E_Class_Wide_Subtype
14528 and then Present
(Discriminant_Constraint
(E
)))
14530 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
14531 Fixup_Bad_Constraint
;
14535 -- T may be an unconstrained subtype (e.g. a generic actual). Constraint
14536 -- applies to the base type.
14538 T
:= Base_Type
(T
);
14540 Constr
:= Build_Discriminant_Constraints
(T
, S
);
14542 -- If the list returned was empty we had an error in building the
14543 -- discriminant constraint. We have also already signalled an error
14544 -- in the incomplete type case
14546 if Is_Empty_Elmt_List
(Constr
) then
14547 Fixup_Bad_Constraint
;
14551 Build_Discriminated_Subtype
(T
, Def_Id
, Constr
, Related_Nod
, For_Access
);
14552 end Constrain_Discriminated_Type
;
14554 ---------------------------
14555 -- Constrain_Enumeration --
14556 ---------------------------
14558 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14559 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14560 C
: constant Node_Id
:= Constraint
(S
);
14563 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14565 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
14566 Set_Etype
(Def_Id
, Base_Type
(T
));
14567 Set_Size_Info
(Def_Id
, (T
));
14568 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14569 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14571 -- Inherit the chain of representation items instead of replacing it
14572 -- because Build_Derived_Enumeration_Type rewrites the declaration of
14573 -- the derived type as a subtype declaration and the former needs to
14574 -- preserve existing representation items (see Build_Derived_Type).
14576 Inherit_Rep_Item_Chain
(Def_Id
, T
);
14578 Set_Discrete_RM_Size
(Def_Id
);
14579 end Constrain_Enumeration
;
14581 ----------------------
14582 -- Constrain_Float --
14583 ----------------------
14585 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14586 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14592 Mutate_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
14594 Set_Etype
(Def_Id
, Base_Type
(T
));
14595 Set_Size_Info
(Def_Id
, (T
));
14596 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14598 -- Process the constraint
14600 C
:= Constraint
(S
);
14602 -- Digits constraint present
14604 if Nkind
(C
) = N_Digits_Constraint
then
14605 Check_Restriction
(No_Obsolescent_Features
, C
);
14607 if Warn_On_Obsolescent_Feature
then
14609 ("subtype digits constraint is an " &
14610 "obsolescent feature (RM J.3(8))?j?", C
);
14613 D
:= Digits_Expression
(C
);
14614 Analyze_And_Resolve
(D
, Any_Integer
);
14615 Check_Digits_Expression
(D
);
14616 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
14618 -- Check that digits value is in range. Obviously we can do this
14619 -- at compile time, but it is strictly a runtime check, and of
14620 -- course there is an ACVC test that checks this.
14622 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
14623 Error_Msg_Uint_1
:= Digits_Value
(T
);
14624 Error_Msg_N
("??digits value is too large, maximum is ^", D
);
14626 Make_Raise_Constraint_Error
(Sloc
(D
),
14627 Reason
=> CE_Range_Check_Failed
);
14628 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
14631 C
:= Range_Constraint
(C
);
14633 -- No digits constraint present
14636 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
14639 -- Range constraint present
14641 if Nkind
(C
) = N_Range_Constraint
then
14642 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14644 -- No range constraint present
14647 pragma Assert
(No
(C
));
14648 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
14651 Set_Is_Constrained
(Def_Id
);
14652 end Constrain_Float
;
14654 ---------------------
14655 -- Constrain_Index --
14656 ---------------------
14658 procedure Constrain_Index
14661 Related_Nod
: Node_Id
;
14662 Related_Id
: Entity_Id
;
14663 Suffix
: Character;
14664 Suffix_Index
: Pos
)
14666 Def_Id
: Entity_Id
;
14667 R
: Node_Id
:= Empty
;
14668 T
: constant Entity_Id
:= Etype
(Index
);
14669 Is_FLB_Index
: Boolean := False;
14673 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
14674 Set_Etype
(Def_Id
, Base_Type
(T
));
14676 if Nkind
(S
) = N_Range
14678 (Nkind
(S
) = N_Attribute_Reference
14679 and then Attribute_Name
(S
) = Name_Range
)
14681 -- A Range attribute will be transformed into N_Range by Resolve
14683 -- If a range has an Empty upper bound, then remember that for later
14684 -- setting of the index subtype's Is_Fixed_Lower_Bound_Index_Subtype
14685 -- flag, and also set the upper bound of the range to the index
14686 -- subtype's upper bound rather than leaving it Empty. In truth,
14687 -- that upper bound corresponds to a box ("<>"), but it's convenient
14688 -- to set it to the upper bound to avoid needing to add special tests
14689 -- in various places for an Empty upper bound, and in any case it
14690 -- accurately characterizes the index's range of values.
14692 if Nkind
(S
) = N_Range
and then No
(High_Bound
(S
)) then
14693 Is_FLB_Index
:= True;
14694 Set_High_Bound
(S
, Type_High_Bound
(T
));
14699 Process_Range_Expr_In_Decl
(R
, T
);
14701 if not Error_Posted
(S
)
14703 (Nkind
(S
) /= N_Range
14704 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
14705 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
14707 if Base_Type
(T
) /= Any_Type
14708 and then Etype
(Low_Bound
(S
)) /= Any_Type
14709 and then Etype
(High_Bound
(S
)) /= Any_Type
14711 Error_Msg_N
("range expected", S
);
14715 elsif Nkind
(S
) = N_Subtype_Indication
then
14717 -- The parser has verified that this is a discrete indication
14719 Resolve_Discrete_Subtype_Indication
(S
, T
);
14720 Bad_Predicated_Subtype_Use
14721 ("subtype& has predicate, not allowed in index constraint",
14722 S
, Entity
(Subtype_Mark
(S
)));
14724 R
:= Range_Expression
(Constraint
(S
));
14726 -- Capture values of bounds and generate temporaries for them if
14727 -- needed, since checks may cause duplication of the expressions
14728 -- which must not be reevaluated.
14730 -- The forced evaluation removes side effects from expressions, which
14731 -- should occur also in GNATprove mode. Otherwise, we end up with
14732 -- unexpected insertions of actions at places where this is not
14733 -- supposed to occur, e.g. on default parameters of a call.
14735 if Expander_Active
or GNATprove_Mode
then
14737 (Low_Bound
(R
), Related_Id
=> Def_Id
, Is_Low_Bound
=> True);
14739 (High_Bound
(R
), Related_Id
=> Def_Id
, Is_High_Bound
=> True);
14742 elsif Nkind
(S
) = N_Discriminant_Association
then
14744 -- Syntactically valid in subtype indication
14746 Error_Msg_N
("invalid index constraint", S
);
14747 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14750 -- Subtype_Mark case, no anonymous subtypes to construct
14755 if Is_Entity_Name
(S
) then
14756 if not Is_Type
(Entity
(S
)) then
14757 Error_Msg_N
("expect subtype mark for index constraint", S
);
14759 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
14760 Wrong_Type
(S
, Base_Type
(T
));
14762 -- Check error of subtype with predicate in index constraint
14765 Bad_Predicated_Subtype_Use
14766 ("subtype& has predicate, not allowed in index constraint",
14773 Error_Msg_N
("invalid index constraint", S
);
14774 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14779 -- Complete construction of the Itype
14781 if Is_Modular_Integer_Type
(T
) then
14782 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14784 elsif Is_Integer_Type
(T
) then
14785 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14788 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14789 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14790 Set_First_Literal
(Def_Id
, First_Literal
(T
));
14793 Set_Size_Info
(Def_Id
, (T
));
14794 Copy_RM_Size
(To
=> Def_Id
, From
=> T
);
14795 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14797 -- If this is a range for a fixed-lower-bound subtype, then set the
14798 -- index itype's low bound to the FLB and the index itype's upper bound
14799 -- to the high bound of the parent array type's index subtype. Also,
14800 -- mark the itype as an FLB index subtype.
14802 if Nkind
(S
) = N_Range
and then Is_FLB_Index
then
14805 Make_Range
(Sloc
(S
),
14806 Low_Bound
=> Low_Bound
(S
),
14807 High_Bound
=> Type_High_Bound
(T
)));
14808 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Def_Id
);
14811 Set_Scalar_Range
(Def_Id
, R
);
14814 Set_Etype
(S
, Def_Id
);
14815 Set_Discrete_RM_Size
(Def_Id
);
14816 end Constrain_Index
;
14818 -----------------------
14819 -- Constrain_Integer --
14820 -----------------------
14822 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14823 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14824 C
: constant Node_Id
:= Constraint
(S
);
14827 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14829 if Is_Modular_Integer_Type
(T
) then
14830 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14832 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14835 Set_Etype
(Def_Id
, Base_Type
(T
));
14836 Set_Size_Info
(Def_Id
, (T
));
14837 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14838 Set_Discrete_RM_Size
(Def_Id
);
14839 end Constrain_Integer
;
14841 ------------------------------
14842 -- Constrain_Ordinary_Fixed --
14843 ------------------------------
14845 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14846 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14852 Mutate_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
14853 Set_Etype
(Def_Id
, Base_Type
(T
));
14854 Set_Size_Info
(Def_Id
, (T
));
14855 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14856 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14858 -- Process the constraint
14860 C
:= Constraint
(S
);
14862 -- Delta constraint present
14864 if Nkind
(C
) = N_Delta_Constraint
then
14865 Check_Restriction
(No_Obsolescent_Features
, C
);
14867 if Warn_On_Obsolescent_Feature
then
14869 ("subtype delta constraint is an " &
14870 "obsolescent feature (RM J.3(7))?j?");
14873 D
:= Delta_Expression
(C
);
14874 Analyze_And_Resolve
(D
, Any_Real
);
14875 Check_Delta_Expression
(D
);
14876 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
14878 -- Check that delta value is in range. Obviously we can do this
14879 -- at compile time, but it is strictly a runtime check, and of
14880 -- course there is an ACVC test that checks this.
14882 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
14883 Error_Msg_N
("??delta value is too small", D
);
14885 Make_Raise_Constraint_Error
(Sloc
(D
),
14886 Reason
=> CE_Range_Check_Failed
);
14887 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
14890 C
:= Range_Constraint
(C
);
14892 -- No delta constraint present
14895 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
14898 -- Range constraint present
14900 if Nkind
(C
) = N_Range_Constraint
then
14901 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14903 -- No range constraint present
14906 pragma Assert
(No
(C
));
14907 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
14910 Set_Discrete_RM_Size
(Def_Id
);
14912 -- Unconditionally delay the freeze, since we cannot set size
14913 -- information in all cases correctly until the freeze point.
14915 Set_Has_Delayed_Freeze
(Def_Id
);
14916 end Constrain_Ordinary_Fixed
;
14918 -----------------------
14919 -- Contain_Interface --
14920 -----------------------
14922 function Contain_Interface
14923 (Iface
: Entity_Id
;
14924 Ifaces
: Elist_Id
) return Boolean
14926 Iface_Elmt
: Elmt_Id
;
14929 if Present
(Ifaces
) then
14930 Iface_Elmt
:= First_Elmt
(Ifaces
);
14931 while Present
(Iface_Elmt
) loop
14932 if Node
(Iface_Elmt
) = Iface
then
14936 Next_Elmt
(Iface_Elmt
);
14941 end Contain_Interface
;
14943 ---------------------------
14944 -- Convert_Scalar_Bounds --
14945 ---------------------------
14947 procedure Convert_Scalar_Bounds
14949 Parent_Type
: Entity_Id
;
14950 Derived_Type
: Entity_Id
;
14953 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
14960 -- Defend against previous errors
14962 if No
(Scalar_Range
(Derived_Type
)) then
14963 Check_Error_Detected
;
14967 Lo
:= Build_Scalar_Bound
14968 (Type_Low_Bound
(Derived_Type
),
14969 Parent_Type
, Implicit_Base
);
14971 Hi
:= Build_Scalar_Bound
14972 (Type_High_Bound
(Derived_Type
),
14973 Parent_Type
, Implicit_Base
);
14980 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
14982 Set_Parent
(Rng
, N
);
14983 Set_Scalar_Range
(Derived_Type
, Rng
);
14985 -- Analyze the bounds
14987 Analyze_And_Resolve
(Lo
, Implicit_Base
);
14988 Analyze_And_Resolve
(Hi
, Implicit_Base
);
14990 -- Analyze the range itself, except that we do not analyze it if
14991 -- the bounds are real literals, and we have a fixed-point type.
14992 -- The reason for this is that we delay setting the bounds in this
14993 -- case till we know the final Small and Size values (see circuit
14994 -- in Freeze.Freeze_Fixed_Point_Type for further details).
14996 if Is_Fixed_Point_Type
(Parent_Type
)
14997 and then Nkind
(Lo
) = N_Real_Literal
14998 and then Nkind
(Hi
) = N_Real_Literal
15002 -- Here we do the analysis of the range
15004 -- Note: we do this manually, since if we do a normal Analyze and
15005 -- Resolve call, there are problems with the conversions used for
15006 -- the derived type range.
15009 Set_Etype
(Rng
, Implicit_Base
);
15010 Set_Analyzed
(Rng
, True);
15012 end Convert_Scalar_Bounds
;
15014 -------------------
15015 -- Copy_And_Swap --
15016 -------------------
15018 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
15020 -- Initialize new full declaration entity by copying the pertinent
15021 -- fields of the corresponding private declaration entity.
15023 -- We temporarily set Ekind to a value appropriate for a type to
15024 -- avoid assert failures in Einfo from checking for setting type
15025 -- attributes on something that is not a type. Ekind (Priv) is an
15026 -- appropriate choice, since it allowed the attributes to be set
15027 -- in the first place. This Ekind value will be modified later.
15029 Mutate_Ekind
(Full
, Ekind
(Priv
));
15031 -- Also set Etype temporarily to Any_Type, again, in the absence
15032 -- of errors, it will be properly reset, and if there are errors,
15033 -- then we want a value of Any_Type to remain.
15035 Set_Etype
(Full
, Any_Type
);
15037 -- Now start copying attributes
15039 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
15041 if Has_Discriminants
(Full
) then
15042 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
15043 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
15046 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
15047 Set_Homonym
(Full
, Homonym
(Priv
));
15048 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
15049 Set_Is_Public
(Full
, Is_Public
(Priv
));
15050 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
15051 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
15052 Set_Has_Pragma_Unmodified
(Full
, Has_Pragma_Unmodified
(Priv
));
15053 Set_Has_Pragma_Unreferenced
(Full
, Has_Pragma_Unreferenced
(Priv
));
15054 Set_Has_Pragma_Unreferenced_Objects
15055 (Full
, Has_Pragma_Unreferenced_Objects
15058 Conditional_Delay
(Full
, Priv
);
15060 if Is_Tagged_Type
(Full
) then
15061 Set_Direct_Primitive_Operations
15062 (Full
, Direct_Primitive_Operations
(Priv
));
15063 Set_No_Tagged_Streams_Pragma
15064 (Full
, No_Tagged_Streams_Pragma
(Priv
));
15066 if Is_Base_Type
(Priv
) then
15067 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
15071 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
15072 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
15073 Set_Scope
(Full
, Scope
(Priv
));
15074 Set_Prev_Entity
(Full
, Prev_Entity
(Priv
));
15075 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
15076 Set_First_Entity
(Full
, First_Entity
(Priv
));
15077 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
15079 -- If access types have been recorded for later handling, keep them in
15080 -- the full view so that they get handled when the full view freeze
15081 -- node is expanded.
15083 if Present
(Freeze_Node
(Priv
))
15084 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
15086 Ensure_Freeze_Node
(Full
);
15087 Set_Access_Types_To_Process
15088 (Freeze_Node
(Full
),
15089 Access_Types_To_Process
(Freeze_Node
(Priv
)));
15092 -- Swap the two entities. Now Private is the full type entity and Full
15093 -- is the private one. They will be swapped back at the end of the
15094 -- private part. This swapping ensures that the entity that is visible
15095 -- in the private part is the full declaration.
15097 Exchange_Entities
(Priv
, Full
);
15098 Append_Entity
(Full
, Scope
(Full
));
15101 -------------------------------------
15102 -- Copy_Array_Base_Type_Attributes --
15103 -------------------------------------
15105 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
15107 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
15108 Set_Component_Type
(T1
, Component_Type
(T2
));
15109 Set_Component_Size
(T1
, Component_Size
(T2
));
15110 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
15111 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
15112 Propagate_Concurrent_Flags
(T1
, T2
);
15113 Set_Is_Packed
(T1
, Is_Packed
(T2
));
15114 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
15115 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
15116 Set_Has_Independent_Components
(T1
, Has_Independent_Components
(T2
));
15117 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
15118 end Copy_Array_Base_Type_Attributes
;
15120 -----------------------------------
15121 -- Copy_Array_Subtype_Attributes --
15122 -----------------------------------
15124 -- Note that we used to copy Packed_Array_Impl_Type too here, but we now
15125 -- let it be recreated during freezing for the sake of better debug info.
15127 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
15129 Set_Size_Info
(T1
, T2
);
15131 Set_First_Index
(T1
, First_Index
(T2
));
15132 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
15133 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
15134 Set_Is_Independent
(T1
, Is_Independent
(T2
));
15135 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
15136 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
15137 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
15138 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
15139 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
15140 Inherit_Rep_Item_Chain
(T1
, T2
);
15141 Set_Convention
(T1
, Convention
(T2
));
15142 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
15143 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
15144 end Copy_Array_Subtype_Attributes
;
15146 -----------------------------------
15147 -- Create_Constrained_Components --
15148 -----------------------------------
15150 procedure Create_Constrained_Components
15152 Decl_Node
: Node_Id
;
15154 Constraints
: Elist_Id
)
15156 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
15157 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
15158 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
15159 Assoc_List
: constant List_Id
:= New_List
;
15161 Discr_Val
: Elmt_Id
;
15165 Is_Static
: Boolean := True;
15166 Is_Compile_Time_Known
: Boolean := True;
15168 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
15169 -- Collect parent type components that do not appear in a variant part
15171 procedure Create_All_Components
;
15172 -- Iterate over Comp_List to create the components of the subtype
15174 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
15175 -- Creates a new component from Old_Compon, copying all the fields from
15176 -- it, including its Etype, inserts the new component in the Subt entity
15177 -- chain and returns the new component.
15179 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
15180 -- If true, and discriminants are static, collect only components from
15181 -- variants selected by discriminant values.
15183 ------------------------------
15184 -- Collect_Fixed_Components --
15185 ------------------------------
15187 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
15189 -- Build association list for discriminants, and find components of the
15190 -- variant part selected by the values of the discriminants.
15192 Old_C
:= First_Discriminant
(Typ
);
15193 Discr_Val
:= First_Elmt
(Constraints
);
15194 while Present
(Old_C
) loop
15195 Append_To
(Assoc_List
,
15196 Make_Component_Association
(Loc
,
15197 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
15198 Expression
=> New_Copy
(Node
(Discr_Val
))));
15200 Next_Elmt
(Discr_Val
);
15201 Next_Discriminant
(Old_C
);
15204 -- The tag and the possible parent component are unconditionally in
15207 if Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
15208 Old_C
:= First_Component
(Typ
);
15209 while Present
(Old_C
) loop
15210 if Chars
(Old_C
) in Name_uTag | Name_uParent
then
15211 Append_Elmt
(Old_C
, Comp_List
);
15214 Next_Component
(Old_C
);
15217 end Collect_Fixed_Components
;
15219 ---------------------------
15220 -- Create_All_Components --
15221 ---------------------------
15223 procedure Create_All_Components
is
15227 Comp
:= First_Elmt
(Comp_List
);
15228 while Present
(Comp
) loop
15229 Old_C
:= Node
(Comp
);
15230 New_C
:= Create_Component
(Old_C
);
15234 Constrain_Component_Type
15235 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15236 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15240 end Create_All_Components
;
15242 ----------------------
15243 -- Create_Component --
15244 ----------------------
15246 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
15247 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
15250 if Ekind
(Old_Compon
) = E_Discriminant
15251 and then Is_Completely_Hidden
(Old_Compon
)
15253 -- This is a shadow discriminant created for a discriminant of
15254 -- the parent type, which needs to be present in the subtype.
15255 -- Give the shadow discriminant an internal name that cannot
15256 -- conflict with that of visible components.
15258 Set_Chars
(New_Compon
, New_Internal_Name
('C'));
15261 -- Set the parent so we have a proper link for freezing etc. This is
15262 -- not a real parent pointer, since of course our parent does not own
15263 -- up to us and reference us, we are an illegitimate child of the
15264 -- original parent.
15266 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
15268 -- We do not want this node marked as Comes_From_Source, since
15269 -- otherwise it would get first class status and a separate cross-
15270 -- reference line would be generated. Illegitimate children do not
15271 -- rate such recognition.
15273 Set_Comes_From_Source
(New_Compon
, False);
15275 -- But it is a real entity, and a birth certificate must be properly
15276 -- registered by entering it into the entity list, and setting its
15277 -- scope to the given subtype. This turns out to be useful for the
15278 -- LLVM code generator, but that scope is not used otherwise.
15280 Enter_Name
(New_Compon
);
15281 Set_Scope
(New_Compon
, Subt
);
15284 end Create_Component
;
15286 -----------------------
15287 -- Is_Variant_Record --
15288 -----------------------
15290 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
15292 return Nkind
(Parent
(T
)) = N_Full_Type_Declaration
15293 and then Nkind
(Type_Definition
(Parent
(T
))) = N_Record_Definition
15294 and then Present
(Component_List
(Type_Definition
(Parent
(T
))))
15297 (Variant_Part
(Component_List
(Type_Definition
(Parent
(T
)))));
15298 end Is_Variant_Record
;
15300 -- Start of processing for Create_Constrained_Components
15303 pragma Assert
(Subt
/= Base_Type
(Subt
));
15304 pragma Assert
(Typ
= Base_Type
(Typ
));
15306 Set_First_Entity
(Subt
, Empty
);
15307 Set_Last_Entity
(Subt
, Empty
);
15309 -- Check whether constraint is fully static, in which case we can
15310 -- optimize the list of components.
15312 Discr_Val
:= First_Elmt
(Constraints
);
15313 while Present
(Discr_Val
) loop
15314 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
15315 Is_Static
:= False;
15317 if not Compile_Time_Known_Value
(Node
(Discr_Val
)) then
15318 Is_Compile_Time_Known
:= False;
15323 Next_Elmt
(Discr_Val
);
15326 Set_Has_Static_Discriminants
(Subt
, Is_Static
);
15330 -- Inherit the discriminants of the parent type
15332 Add_Discriminants
: declare
15338 Old_C
:= First_Discriminant
(Typ
);
15340 while Present
(Old_C
) loop
15341 Num_Disc
:= Num_Disc
+ 1;
15342 New_C
:= Create_Component
(Old_C
);
15343 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15344 Next_Discriminant
(Old_C
);
15347 -- For an untagged derived subtype, the number of discriminants may
15348 -- be smaller than the number of inherited discriminants, because
15349 -- several of them may be renamed by a single new discriminant or
15350 -- constrained. In this case, add the hidden discriminants back into
15351 -- the subtype, because they need to be present if the optimizer of
15352 -- the GCC 4.x back-end decides to break apart assignments between
15353 -- objects using the parent view into member-wise assignments.
15357 if Is_Derived_Type
(Typ
)
15358 and then not Is_Tagged_Type
(Typ
)
15360 Old_C
:= First_Stored_Discriminant
(Typ
);
15362 while Present
(Old_C
) loop
15363 Num_Stor
:= Num_Stor
+ 1;
15364 Next_Stored_Discriminant
(Old_C
);
15368 if Num_Stor
> Num_Disc
then
15370 -- Find out multiple uses of new discriminants, and add hidden
15371 -- components for the extra renamed discriminants. We recognize
15372 -- multiple uses through the Corresponding_Discriminant of a
15373 -- new discriminant: if it constrains several old discriminants,
15374 -- this field points to the last one in the parent type. The
15375 -- stored discriminants of the derived type have the same name
15376 -- as those of the parent.
15380 New_Discr
: Entity_Id
;
15381 Old_Discr
: Entity_Id
;
15384 Constr
:= First_Elmt
(Stored_Constraint
(Typ
));
15385 Old_Discr
:= First_Stored_Discriminant
(Typ
);
15386 while Present
(Constr
) loop
15387 if Is_Entity_Name
(Node
(Constr
))
15388 and then Ekind
(Entity
(Node
(Constr
))) = E_Discriminant
15390 New_Discr
:= Entity
(Node
(Constr
));
15392 if Chars
(Corresponding_Discriminant
(New_Discr
)) /=
15395 -- The new discriminant has been used to rename a
15396 -- subsequent old discriminant. Introduce a shadow
15397 -- component for the current old discriminant.
15399 New_C
:= Create_Component
(Old_Discr
);
15400 Set_Original_Record_Component
(New_C
, Old_Discr
);
15404 -- The constraint has eliminated the old discriminant.
15405 -- Introduce a shadow component.
15407 New_C
:= Create_Component
(Old_Discr
);
15408 Set_Original_Record_Component
(New_C
, Old_Discr
);
15411 Next_Elmt
(Constr
);
15412 Next_Stored_Discriminant
(Old_Discr
);
15416 end Add_Discriminants
;
15418 if Is_Compile_Time_Known
15419 and then Is_Variant_Record
(Typ
)
15421 Collect_Fixed_Components
(Typ
);
15424 Component_List
(Type_Definition
(Parent
(Typ
))),
15425 Governed_By
=> Assoc_List
,
15427 Report_Errors
=> Errors
,
15428 Allow_Compile_Time
=> True);
15429 pragma Assert
(not Errors
or else Serious_Errors_Detected
> 0);
15431 Create_All_Components
;
15433 -- If the subtype declaration is created for a tagged type derivation
15434 -- with constraints, we retrieve the record definition of the parent
15435 -- type to select the components of the proper variant.
15437 elsif Is_Compile_Time_Known
15438 and then Is_Tagged_Type
(Typ
)
15439 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
15441 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
15442 and then Is_Variant_Record
(Parent_Type
)
15444 Collect_Fixed_Components
(Typ
);
15447 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
15448 Governed_By
=> Assoc_List
,
15450 Report_Errors
=> Errors
,
15451 Allow_Compile_Time
=> True);
15453 -- Note: previously there was a check at this point that no errors
15454 -- were detected. As a consequence of AI05-220 there may be an error
15455 -- if an inherited discriminant that controls a variant has a non-
15456 -- static constraint.
15458 -- If the tagged derivation has a type extension, collect all the
15459 -- new relevant components therein via Gather_Components.
15461 if Present
(Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
15466 (Record_Extension_Part
(Type_Definition
(Parent
(Typ
)))),
15467 Governed_By
=> Assoc_List
,
15469 Report_Errors
=> Errors
,
15470 Allow_Compile_Time
=> True,
15471 Include_Interface_Tag
=> True);
15474 Create_All_Components
;
15477 -- If discriminants are not static, or if this is a multi-level type
15478 -- extension, we have to include all components of the parent type.
15480 Old_C
:= First_Component
(Typ
);
15481 while Present
(Old_C
) loop
15482 New_C
:= Create_Component
(Old_C
);
15486 Constrain_Component_Type
15487 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15488 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15490 Next_Component
(Old_C
);
15495 end Create_Constrained_Components
;
15497 ------------------------------------------
15498 -- Decimal_Fixed_Point_Type_Declaration --
15499 ------------------------------------------
15501 procedure Decimal_Fixed_Point_Type_Declaration
15505 Loc
: constant Source_Ptr
:= Sloc
(Def
);
15506 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
15507 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
15508 Max_Digits
: constant Nat
:=
15509 (if System_Max_Integer_Size
= 128 then 38 else 18);
15510 -- Maximum number of digits that can be represented in an integer
15512 Implicit_Base
: Entity_Id
;
15519 Check_Restriction
(No_Fixed_Point
, Def
);
15521 -- Create implicit base type
15524 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
15525 Set_Etype
(Implicit_Base
, Implicit_Base
);
15527 -- Analyze and process delta expression
15529 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
15531 Check_Delta_Expression
(Delta_Expr
);
15532 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
15534 -- Check delta is power of 10, and determine scale value from it
15540 Scale_Val
:= Uint_0
;
15543 if Val
< Ureal_1
then
15544 while Val
< Ureal_1
loop
15545 Val
:= Val
* Ureal_10
;
15546 Scale_Val
:= Scale_Val
+ 1;
15549 if Scale_Val
> Max_Digits
then
15550 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15551 Error_Msg_N
("scale exceeds maximum value of ^", Def
);
15552 Scale_Val
:= UI_From_Int
(Max_Digits
);
15556 while Val
> Ureal_1
loop
15557 Val
:= Val
/ Ureal_10
;
15558 Scale_Val
:= Scale_Val
- 1;
15561 if Scale_Val
< -Max_Digits
then
15562 Error_Msg_Uint_1
:= UI_From_Int
(-Max_Digits
);
15563 Error_Msg_N
("scale is less than minimum value of ^", Def
);
15564 Scale_Val
:= UI_From_Int
(-Max_Digits
);
15568 if Val
/= Ureal_1
then
15569 Error_Msg_N
("delta expression must be a power of 10", Def
);
15570 Delta_Val
:= Ureal_10
** (-Scale_Val
);
15574 -- Set delta, scale and small (small = delta for decimal type)
15576 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
15577 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
15578 Set_Small_Value
(Implicit_Base
, Delta_Val
);
15580 -- Analyze and process digits expression
15582 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
15583 Check_Digits_Expression
(Digs_Expr
);
15584 Digs_Val
:= Expr_Value
(Digs_Expr
);
15586 if Digs_Val
> Max_Digits
then
15587 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15588 Error_Msg_N
("digits value out of range, maximum is ^", Digs_Expr
);
15589 Digs_Val
:= UI_From_Int
(Max_Digits
);
15592 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
15593 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
15595 -- Set range of base type from digits value for now. This will be
15596 -- expanded to represent the true underlying base range by Freeze.
15598 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
15600 -- Note: We leave Esize unset for now, size will be set at freeze
15601 -- time. We have to do this for ordinary fixed-point, because the size
15602 -- depends on the specified small, and we might as well do the same for
15603 -- decimal fixed-point.
15605 pragma Assert
(not Known_Esize
(Implicit_Base
));
15607 -- If there are bounds given in the declaration use them as the
15608 -- bounds of the first named subtype.
15610 if Present
(Real_Range_Specification
(Def
)) then
15612 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
15613 Low
: constant Node_Id
:= Low_Bound
(RRS
);
15614 High
: constant Node_Id
:= High_Bound
(RRS
);
15619 Analyze_And_Resolve
(Low
, Any_Real
);
15620 Analyze_And_Resolve
(High
, Any_Real
);
15621 Check_Real_Bound
(Low
);
15622 Check_Real_Bound
(High
);
15623 Low_Val
:= Expr_Value_R
(Low
);
15624 High_Val
:= Expr_Value_R
(High
);
15626 if Low_Val
< (-Bound_Val
) then
15628 ("range low bound too small for digits value", Low
);
15629 Low_Val
:= -Bound_Val
;
15632 if High_Val
> Bound_Val
then
15634 ("range high bound too large for digits value", High
);
15635 High_Val
:= Bound_Val
;
15638 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
15641 -- If no explicit range, use range that corresponds to given
15642 -- digits value. This will end up as the final range for the
15646 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
15649 -- Complete entity for first subtype. The inheritance of the rep item
15650 -- chain ensures that SPARK-related pragmas are not clobbered when the
15651 -- decimal fixed point type acts as a full view of a private type.
15653 Mutate_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
15654 Set_Etype
(T
, Implicit_Base
);
15655 Set_Size_Info
(T
, Implicit_Base
);
15656 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
15657 Set_Digits_Value
(T
, Digs_Val
);
15658 Set_Delta_Value
(T
, Delta_Val
);
15659 Set_Small_Value
(T
, Delta_Val
);
15660 Set_Scale_Value
(T
, Scale_Val
);
15661 Set_Is_Constrained
(T
);
15662 end Decimal_Fixed_Point_Type_Declaration
;
15664 -----------------------------------
15665 -- Derive_Progenitor_Subprograms --
15666 -----------------------------------
15668 procedure Derive_Progenitor_Subprograms
15669 (Parent_Type
: Entity_Id
;
15670 Tagged_Type
: Entity_Id
)
15675 Iface_Alias
: Entity_Id
;
15676 Iface_Elmt
: Elmt_Id
;
15677 Iface_Subp
: Entity_Id
;
15678 New_Subp
: Entity_Id
:= Empty
;
15679 Prim_Elmt
: Elmt_Id
;
15684 pragma Assert
(Ada_Version
>= Ada_2005
15685 and then Is_Record_Type
(Tagged_Type
)
15686 and then Is_Tagged_Type
(Tagged_Type
)
15687 and then Has_Interfaces
(Tagged_Type
));
15689 -- Step 1: Transfer to the full-view primitives associated with the
15690 -- partial-view that cover interface primitives. Conceptually this
15691 -- work should be done later by Process_Full_View; done here to
15692 -- simplify its implementation at later stages. It can be safely
15693 -- done here because interfaces must be visible in the partial and
15694 -- private view (RM 7.3(7.3/2)).
15696 -- Small optimization: This work is only required if the parent may
15697 -- have entities whose Alias attribute reference an interface primitive.
15698 -- Such a situation may occur if the parent is an abstract type and the
15699 -- primitive has not been yet overridden or if the parent is a generic
15700 -- formal type covering interfaces.
15702 -- If the tagged type is not abstract, it cannot have abstract
15703 -- primitives (the only entities in the list of primitives of
15704 -- non-abstract tagged types that can reference abstract primitives
15705 -- through its Alias attribute are the internal entities that have
15706 -- attribute Interface_Alias, and these entities are generated later
15707 -- by Add_Internal_Interface_Entities).
15709 if In_Private_Part
(Current_Scope
)
15710 and then (Is_Abstract_Type
(Parent_Type
)
15712 Is_Generic_Type
(Parent_Type
))
15714 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
15715 while Present
(Elmt
) loop
15716 Subp
:= Node
(Elmt
);
15718 -- At this stage it is not possible to have entities in the list
15719 -- of primitives that have attribute Interface_Alias.
15721 pragma Assert
(No
(Interface_Alias
(Subp
)));
15723 Typ
:= Find_Dispatching_Type
(Ultimate_Alias
(Subp
));
15725 if Is_Interface
(Typ
) then
15726 E
:= Find_Primitive_Covering_Interface
15727 (Tagged_Type
=> Tagged_Type
,
15728 Iface_Prim
=> Subp
);
15731 and then Find_Dispatching_Type
(Ultimate_Alias
(E
)) /= Typ
15733 Replace_Elmt
(Elmt
, E
);
15734 Remove_Homonym
(Subp
);
15742 -- Step 2: Add primitives of progenitors that are not implemented by
15743 -- parents of Tagged_Type.
15745 if Present
(Interfaces
(Base_Type
(Tagged_Type
))) then
15746 Iface_Elmt
:= First_Elmt
(Interfaces
(Base_Type
(Tagged_Type
)));
15747 while Present
(Iface_Elmt
) loop
15748 Iface
:= Node
(Iface_Elmt
);
15750 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
15751 while Present
(Prim_Elmt
) loop
15752 Iface_Subp
:= Node
(Prim_Elmt
);
15753 Iface_Alias
:= Ultimate_Alias
(Iface_Subp
);
15755 -- Exclude derivation of predefined primitives except those
15756 -- that come from source, or are inherited from one that comes
15757 -- from source. Required to catch declarations of equality
15758 -- operators of interfaces. For example:
15760 -- type Iface is interface;
15761 -- function "=" (Left, Right : Iface) return Boolean;
15763 if not Is_Predefined_Dispatching_Operation
(Iface_Subp
)
15764 or else Comes_From_Source
(Iface_Alias
)
15767 Find_Primitive_Covering_Interface
15768 (Tagged_Type
=> Tagged_Type
,
15769 Iface_Prim
=> Iface_Subp
);
15771 -- If not found we derive a new primitive leaving its alias
15772 -- attribute referencing the interface primitive.
15776 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15778 -- Ada 2012 (AI05-0197): If the covering primitive's name
15779 -- differs from the name of the interface primitive then it
15780 -- is a private primitive inherited from a parent type. In
15781 -- such case, given that Tagged_Type covers the interface,
15782 -- the inherited private primitive becomes visible. For such
15783 -- purpose we add a new entity that renames the inherited
15784 -- private primitive.
15786 elsif Chars
(E
) /= Chars
(Iface_Subp
) then
15787 pragma Assert
(Has_Suffix
(E
, 'P'));
15789 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15790 Set_Alias
(New_Subp
, E
);
15791 Set_Is_Abstract_Subprogram
(New_Subp
,
15792 Is_Abstract_Subprogram
(E
));
15794 -- Propagate to the full view interface entities associated
15795 -- with the partial view.
15797 elsif In_Private_Part
(Current_Scope
)
15798 and then Present
(Alias
(E
))
15799 and then Alias
(E
) = Iface_Subp
15801 List_Containing
(Parent
(E
)) /=
15802 Private_Declarations
15804 (Unit_Declaration_Node
(Current_Scope
)))
15806 Append_Elmt
(E
, Primitive_Operations
(Tagged_Type
));
15810 Next_Elmt
(Prim_Elmt
);
15813 Next_Elmt
(Iface_Elmt
);
15816 end Derive_Progenitor_Subprograms
;
15818 -----------------------
15819 -- Derive_Subprogram --
15820 -----------------------
15822 procedure Derive_Subprogram
15823 (New_Subp
: out Entity_Id
;
15824 Parent_Subp
: Entity_Id
;
15825 Derived_Type
: Entity_Id
;
15826 Parent_Type
: Entity_Id
;
15827 Actual_Subp
: Entity_Id
:= Empty
)
15829 Formal
: Entity_Id
;
15830 -- Formal parameter of parent primitive operation
15832 Formal_Of_Actual
: Entity_Id
;
15833 -- Formal parameter of actual operation, when the derivation is to
15834 -- create a renaming for a primitive operation of an actual in an
15837 New_Formal
: Entity_Id
;
15838 -- Formal of inherited operation
15840 Visible_Subp
: Entity_Id
:= Parent_Subp
;
15842 function Is_Private_Overriding
return Boolean;
15843 -- If Subp is a private overriding of a visible operation, the inherited
15844 -- operation derives from the overridden op (even though its body is the
15845 -- overriding one) and the inherited operation is visible now. See
15846 -- sem_disp to see the full details of the handling of the overridden
15847 -- subprogram, which is removed from the list of primitive operations of
15848 -- the type. The overridden subprogram is saved locally in Visible_Subp,
15849 -- and used to diagnose abstract operations that need overriding in the
15852 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
15853 -- When the type is an anonymous access type, create a new access type
15854 -- designating the derived type.
15856 procedure Set_Derived_Name
;
15857 -- This procedure sets the appropriate Chars name for New_Subp. This
15858 -- is normally just a copy of the parent name. An exception arises for
15859 -- type support subprograms, where the name is changed to reflect the
15860 -- name of the derived type, e.g. if type foo is derived from type bar,
15861 -- then a procedure barDA is derived with a name fooDA.
15863 ---------------------------
15864 -- Is_Private_Overriding --
15865 ---------------------------
15867 function Is_Private_Overriding
return Boolean is
15871 -- If the parent is not a dispatching operation there is no
15872 -- need to investigate overridings
15874 if not Is_Dispatching_Operation
(Parent_Subp
) then
15878 -- The visible operation that is overridden is a homonym of the
15879 -- parent subprogram. We scan the homonym chain to find the one
15880 -- whose alias is the subprogram we are deriving.
15882 Prev
:= Current_Entity
(Parent_Subp
);
15883 while Present
(Prev
) loop
15884 if Ekind
(Prev
) = Ekind
(Parent_Subp
)
15885 and then Alias
(Prev
) = Parent_Subp
15886 and then Scope
(Parent_Subp
) = Scope
(Prev
)
15887 and then not Is_Hidden
(Prev
)
15889 Visible_Subp
:= Prev
;
15893 Prev
:= Homonym
(Prev
);
15897 end Is_Private_Overriding
;
15903 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
15904 Id_Type
: constant Entity_Id
:= Etype
(Id
);
15905 Acc_Type
: Entity_Id
;
15906 Par
: constant Node_Id
:= Parent
(Derived_Type
);
15909 -- When the type is an anonymous access type, create a new access
15910 -- type designating the derived type. This itype must be elaborated
15911 -- at the point of the derivation, not on subsequent calls that may
15912 -- be out of the proper scope for Gigi, so we insert a reference to
15913 -- it after the derivation.
15915 if Ekind
(Id_Type
) = E_Anonymous_Access_Type
then
15917 Desig_Typ
: Entity_Id
:= Designated_Type
(Id_Type
);
15920 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
15921 and then Present
(Full_View
(Desig_Typ
))
15922 and then not Is_Private_Type
(Parent_Type
)
15924 Desig_Typ
:= Full_View
(Desig_Typ
);
15927 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
)
15929 -- Ada 2005 (AI-251): Handle also derivations of abstract
15930 -- interface primitives.
15932 or else (Is_Interface
(Desig_Typ
)
15933 and then not Is_Class_Wide_Type
(Desig_Typ
))
15935 Acc_Type
:= New_Copy
(Id_Type
);
15936 Set_Etype
(Acc_Type
, Acc_Type
);
15937 Set_Scope
(Acc_Type
, New_Subp
);
15939 -- Set size of anonymous access type. If we have an access
15940 -- to an unconstrained array, this is a fat pointer, so it
15941 -- is sizes at twice addtress size.
15943 if Is_Array_Type
(Desig_Typ
)
15944 and then not Is_Constrained
(Desig_Typ
)
15946 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
15948 -- Other cases use a thin pointer
15951 Init_Size
(Acc_Type
, System_Address_Size
);
15954 -- Set remaining characterstics of anonymous access type
15956 Reinit_Alignment
(Acc_Type
);
15957 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
15959 Set_Etype
(New_Id
, Acc_Type
);
15960 Set_Scope
(New_Id
, New_Subp
);
15962 -- Create a reference to it
15964 Build_Itype_Reference
(Acc_Type
, Parent
(Derived_Type
));
15967 Set_Etype
(New_Id
, Id_Type
);
15971 -- In Ada2012, a formal may have an incomplete type but the type
15972 -- derivation that inherits the primitive follows the full view.
15974 elsif Base_Type
(Id_Type
) = Base_Type
(Parent_Type
)
15976 (Ekind
(Id_Type
) = E_Record_Type_With_Private
15977 and then Present
(Full_View
(Id_Type
))
15979 Base_Type
(Full_View
(Id_Type
)) = Base_Type
(Parent_Type
))
15981 (Ada_Version
>= Ada_2012
15982 and then Ekind
(Id_Type
) = E_Incomplete_Type
15983 and then Full_View
(Id_Type
) = Parent_Type
)
15985 -- Constraint checks on formals are generated during expansion,
15986 -- based on the signature of the original subprogram. The bounds
15987 -- of the derived type are not relevant, and thus we can use
15988 -- the base type for the formals. However, the return type may be
15989 -- used in a context that requires that the proper static bounds
15990 -- be used (a case statement, for example) and for those cases
15991 -- we must use the derived type (first subtype), not its base.
15993 -- If the derived_type_definition has no constraints, we know that
15994 -- the derived type has the same constraints as the first subtype
15995 -- of the parent, and we can also use it rather than its base,
15996 -- which can lead to more efficient code.
15998 if Etype
(Id
) = Parent_Type
then
15999 if Is_Scalar_Type
(Parent_Type
)
16001 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
16003 Set_Etype
(New_Id
, Derived_Type
);
16005 elsif Nkind
(Par
) = N_Full_Type_Declaration
16007 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
16010 (Subtype_Indication
(Type_Definition
(Par
)))
16012 Set_Etype
(New_Id
, Derived_Type
);
16015 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
16019 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
16023 Set_Etype
(New_Id
, Etype
(Id
));
16027 ----------------------
16028 -- Set_Derived_Name --
16029 ----------------------
16031 procedure Set_Derived_Name
is
16032 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
16034 if Nm
= TSS_Null
then
16035 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
16037 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
16039 end Set_Derived_Name
;
16041 -- Start of processing for Derive_Subprogram
16044 New_Subp
:= New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
16045 Mutate_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
16047 -- Check whether the inherited subprogram is a private operation that
16048 -- should be inherited but not yet made visible. Such subprograms can
16049 -- become visible at a later point (e.g., the private part of a public
16050 -- child unit) via Declare_Inherited_Private_Subprograms. If the
16051 -- following predicate is true, then this is not such a private
16052 -- operation and the subprogram simply inherits the name of the parent
16053 -- subprogram. Note the special check for the names of controlled
16054 -- operations, which are currently exempted from being inherited with
16055 -- a hidden name because they must be findable for generation of
16056 -- implicit run-time calls.
16058 if not Is_Hidden
(Parent_Subp
)
16059 or else Is_Internal
(Parent_Subp
)
16060 or else Is_Private_Overriding
16061 or else Is_Internal_Name
(Chars
(Parent_Subp
))
16062 or else (Is_Controlled
(Parent_Type
)
16063 and then Chars
(Parent_Subp
) in Name_Adjust
16069 -- An inherited dispatching equality will be overridden by an internally
16070 -- generated one, or by an explicit one, so preserve its name and thus
16071 -- its entry in the dispatch table. Otherwise, if Parent_Subp is a
16072 -- private operation it may become invisible if the full view has
16073 -- progenitors, and the dispatch table will be malformed.
16074 -- We check that the type is limited to handle the anomalous declaration
16075 -- of Limited_Controlled, which is derived from a non-limited type, and
16076 -- which is handled specially elsewhere as well.
16078 elsif Chars
(Parent_Subp
) = Name_Op_Eq
16079 and then Is_Dispatching_Operation
(Parent_Subp
)
16080 and then Etype
(Parent_Subp
) = Standard_Boolean
16081 and then not Is_Limited_Type
(Etype
(First_Formal
(Parent_Subp
)))
16083 Etype
(First_Formal
(Parent_Subp
)) =
16084 Etype
(Next_Formal
(First_Formal
(Parent_Subp
)))
16088 -- If parent is hidden, this can be a regular derivation if the
16089 -- parent is immediately visible in a non-instantiating context,
16090 -- or if we are in the private part of an instance. This test
16091 -- should still be refined ???
16093 -- The test for In_Instance_Not_Visible avoids inheriting the derived
16094 -- operation as a non-visible operation in cases where the parent
16095 -- subprogram might not be visible now, but was visible within the
16096 -- original generic, so it would be wrong to make the inherited
16097 -- subprogram non-visible now. (Not clear if this test is fully
16098 -- correct; are there any cases where we should declare the inherited
16099 -- operation as not visible to avoid it being overridden, e.g., when
16100 -- the parent type is a generic actual with private primitives ???)
16102 -- (they should be treated the same as other private inherited
16103 -- subprograms, but it's not clear how to do this cleanly). ???
16105 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
16106 and then Is_Immediately_Visible
(Parent_Subp
)
16107 and then not In_Instance
)
16108 or else In_Instance_Not_Visible
16112 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
16113 -- overrides an interface primitive because interface primitives
16114 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
16116 elsif Ada_Version
>= Ada_2005
16117 and then Is_Dispatching_Operation
(Parent_Subp
)
16118 and then Present
(Covered_Interface_Op
(Parent_Subp
))
16122 -- Otherwise, the type is inheriting a private operation, so enter it
16123 -- with a special name so it can't be overridden. See also below, where
16124 -- we check for this case, and if so avoid setting Requires_Overriding.
16127 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
16130 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
16132 if Present
(Actual_Subp
) then
16133 Replace_Type
(Actual_Subp
, New_Subp
);
16135 Replace_Type
(Parent_Subp
, New_Subp
);
16138 Conditional_Delay
(New_Subp
, Parent_Subp
);
16140 -- If we are creating a renaming for a primitive operation of an
16141 -- actual of a generic derived type, we must examine the signature
16142 -- of the actual primitive, not that of the generic formal, which for
16143 -- example may be an interface. However the name and initial value
16144 -- of the inherited operation are those of the formal primitive.
16146 Formal
:= First_Formal
(Parent_Subp
);
16148 if Present
(Actual_Subp
) then
16149 Formal_Of_Actual
:= First_Formal
(Actual_Subp
);
16151 Formal_Of_Actual
:= Empty
;
16154 while Present
(Formal
) loop
16155 New_Formal
:= New_Copy
(Formal
);
16157 -- Extra formals are not inherited from a limited interface parent
16158 -- since limitedness is not inherited in such case (AI-419) and this
16159 -- affects the extra formals.
16161 if Is_Limited_Interface
(Parent_Type
) then
16162 Set_Extra_Formal
(New_Formal
, Empty
);
16163 Set_Extra_Accessibility
(New_Formal
, Empty
);
16166 -- Normally we do not go copying parents, but in the case of
16167 -- formals, we need to link up to the declaration (which is the
16168 -- parameter specification), and it is fine to link up to the
16169 -- original formal's parameter specification in this case.
16171 Set_Parent
(New_Formal
, Parent
(Formal
));
16172 Append_Entity
(New_Formal
, New_Subp
);
16174 if Present
(Formal_Of_Actual
) then
16175 Replace_Type
(Formal_Of_Actual
, New_Formal
);
16176 Next_Formal
(Formal_Of_Actual
);
16178 Replace_Type
(Formal
, New_Formal
);
16181 Next_Formal
(Formal
);
16184 -- Extra formals are shared between the parent subprogram and this
16185 -- internal entity built by Derive_Subprogram (implicit in the above
16186 -- copy of formals), unless the parent type is a limited interface type;
16187 -- hence we must inherit also the reference to the first extra formal.
16188 -- When the parent type is an interface, the extra formals will be added
16189 -- when the tagged type is frozen (see Expand_Freeze_Record_Type).
16191 if not Is_Limited_Interface
(Parent_Type
) then
16192 Set_Extra_Formals
(New_Subp
, Extra_Formals
(Parent_Subp
));
16194 if Ekind
(New_Subp
) = E_Function
then
16195 Set_Extra_Accessibility_Of_Result
(New_Subp
,
16196 Extra_Accessibility_Of_Result
(Parent_Subp
));
16200 -- If this derivation corresponds to a tagged generic actual, then
16201 -- primitive operations rename those of the actual. Otherwise the
16202 -- primitive operations rename those of the parent type, If the parent
16203 -- renames an intrinsic operator, so does the new subprogram. We except
16204 -- concatenation, which is always properly typed, and does not get
16205 -- expanded as other intrinsic operations.
16207 if No
(Actual_Subp
) then
16208 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
16209 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16210 Set_Is_Intrinsic_Subprogram
(New_Subp
);
16212 if Present
(Alias
(Parent_Subp
))
16213 and then Chars
(Parent_Subp
) /= Name_Op_Concat
16215 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
16217 Set_Alias
(New_Subp
, Parent_Subp
);
16221 Set_Alias
(New_Subp
, Parent_Subp
);
16225 Set_Alias
(New_Subp
, Actual_Subp
);
16228 Copy_Strub_Mode
(New_Subp
, Alias
(New_Subp
));
16230 -- Derived subprograms of a tagged type must inherit the convention
16231 -- of the parent subprogram (a requirement of AI95-117). Derived
16232 -- subprograms of untagged types simply get convention Ada by default.
16234 -- If the derived type is a tagged generic formal type with unknown
16235 -- discriminants, its convention is intrinsic (RM 6.3.1 (8)).
16237 -- However, if the type is derived from a generic formal, the further
16238 -- inherited subprogram has the convention of the non-generic ancestor.
16239 -- Otherwise there would be no way to override the operation.
16240 -- (This is subject to forthcoming ARG discussions).
16242 if Is_Tagged_Type
(Derived_Type
) then
16243 if Is_Generic_Type
(Derived_Type
)
16244 and then Has_Unknown_Discriminants
(Derived_Type
)
16246 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16249 if Is_Generic_Type
(Parent_Type
)
16250 and then Has_Unknown_Discriminants
(Parent_Type
)
16252 Set_Convention
(New_Subp
, Convention
(Alias
(Parent_Subp
)));
16254 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
16259 -- Predefined controlled operations retain their name even if the parent
16260 -- is hidden (see above), but they are not primitive operations if the
16261 -- ancestor is not visible, for example if the parent is a private
16262 -- extension completed with a controlled extension. Note that a full
16263 -- type that is controlled can break privacy: the flag Is_Controlled is
16264 -- set on both views of the type.
16266 if Is_Controlled
(Parent_Type
)
16267 and then Chars
(Parent_Subp
) in Name_Initialize
16270 and then Is_Hidden
(Parent_Subp
)
16271 and then not Is_Visibly_Controlled
(Parent_Type
)
16273 Set_Is_Hidden
(New_Subp
);
16276 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
16277 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
16279 if Ekind
(Parent_Subp
) = E_Procedure
then
16280 Set_Is_Valued_Procedure
16281 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
16283 Set_Has_Controlling_Result
16284 (New_Subp
, Has_Controlling_Result
(Parent_Subp
));
16287 -- No_Return must be inherited properly. If this is overridden in the
16288 -- case of a dispatching operation, then the check is made later in
16289 -- Check_Abstract_Overriding that the overriding operation is also
16290 -- No_Return (no such check is required for the nondispatching case).
16292 Set_No_Return
(New_Subp
, No_Return
(Parent_Subp
));
16294 -- If the parent subprogram is marked as Ghost, then so is the derived
16295 -- subprogram. The ghost policy for the derived subprogram is set from
16296 -- the effective ghost policy at the point of derived type declaration.
16298 if Is_Ghost_Entity
(Parent_Subp
) then
16299 Set_Is_Ghost_Entity
(New_Subp
);
16302 -- A derived function with a controlling result is abstract. If the
16303 -- Derived_Type is a nonabstract formal generic derived type, then
16304 -- inherited operations are not abstract: the required check is done at
16305 -- instantiation time. If the derivation is for a generic actual, the
16306 -- function is not abstract unless the actual is.
16308 if Is_Generic_Type
(Derived_Type
)
16309 and then not Is_Abstract_Type
(Derived_Type
)
16313 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
16314 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2). Note
16315 -- that functions with controlling access results of record extensions
16316 -- with a null extension part require overriding (AI95-00391/06).
16318 -- Ada 2022 (AI12-0042): Similarly, set those properties for
16319 -- implementing the rule of RM 7.3.2(6.1/4).
16321 -- A subprogram subject to pragma Extensions_Visible with value False
16322 -- requires overriding if the subprogram has at least one controlling
16323 -- OUT parameter (SPARK RM 6.1.7(6)).
16325 elsif Ada_Version
>= Ada_2005
16326 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16327 or else (Is_Tagged_Type
(Derived_Type
)
16328 and then Etype
(New_Subp
) = Derived_Type
16329 and then not Is_Null_Extension
(Derived_Type
))
16330 or else (Is_Tagged_Type
(Derived_Type
)
16331 and then Ekind
(Etype
(New_Subp
)) =
16332 E_Anonymous_Access_Type
16333 and then Designated_Type
(Etype
(New_Subp
)) =
16335 or else (Comes_From_Source
(Alias
(New_Subp
))
16336 and then Is_EVF_Procedure
(Alias
(New_Subp
)))
16338 -- AI12-0042: Set Requires_Overriding when a type extension
16339 -- inherits a private operation that is visible at the
16340 -- point of extension (Has_Private_Ancestor is False) from
16341 -- an ancestor that has Type_Invariant'Class, and when the
16342 -- type extension is in a visible part (the latter as
16343 -- clarified by AI12-0382).
16346 (not Has_Private_Ancestor
(Derived_Type
)
16347 and then Has_Invariants
(Parent_Type
)
16349 Present
(Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16352 (Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16353 and then Is_Private_Primitive
(Parent_Subp
)
16354 and then In_Visible_Part
(Scope
(Derived_Type
))))
16356 and then No
(Actual_Subp
)
16358 if not Is_Tagged_Type
(Derived_Type
)
16359 or else Is_Abstract_Type
(Derived_Type
)
16360 or else Is_Abstract_Subprogram
(Alias
(New_Subp
))
16362 Set_Is_Abstract_Subprogram
(New_Subp
);
16364 -- If the Chars of the new subprogram is different from that of the
16365 -- parent's one, it means that we entered it with a special name so
16366 -- it can't be overridden (see above). In that case we had better not
16367 -- *require* it to be overridden. This is the case where the parent
16368 -- type inherited the operation privately, so there's no danger of
16369 -- dangling dispatching.
16371 elsif Chars
(New_Subp
) = Chars
(Alias
(New_Subp
)) then
16372 Set_Requires_Overriding
(New_Subp
);
16375 elsif Ada_Version
< Ada_2005
16376 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16377 or else (Is_Tagged_Type
(Derived_Type
)
16378 and then Etype
(New_Subp
) = Derived_Type
16379 and then No
(Actual_Subp
)))
16381 Set_Is_Abstract_Subprogram
(New_Subp
);
16383 -- AI05-0097 : an inherited operation that dispatches on result is
16384 -- abstract if the derived type is abstract, even if the parent type
16385 -- is concrete and the derived type is a null extension.
16387 elsif Has_Controlling_Result
(Alias
(New_Subp
))
16388 and then Is_Abstract_Type
(Etype
(New_Subp
))
16390 Set_Is_Abstract_Subprogram
(New_Subp
);
16392 -- Finally, if the parent type is abstract we must verify that all
16393 -- inherited operations are either non-abstract or overridden, or that
16394 -- the derived type itself is abstract (this check is performed at the
16395 -- end of a package declaration, in Check_Abstract_Overriding). A
16396 -- private overriding in the parent type will not be visible in the
16397 -- derivation if we are not in an inner package or in a child unit of
16398 -- the parent type, in which case the abstractness of the inherited
16399 -- operation is carried to the new subprogram.
16401 elsif Is_Abstract_Type
(Parent_Type
)
16402 and then not In_Open_Scopes
(Scope
(Parent_Type
))
16403 and then Is_Private_Overriding
16404 and then Is_Abstract_Subprogram
(Visible_Subp
)
16406 if No
(Actual_Subp
) then
16407 Set_Alias
(New_Subp
, Visible_Subp
);
16408 Set_Is_Abstract_Subprogram
(New_Subp
, True);
16411 -- If this is a derivation for an instance of a formal derived
16412 -- type, abstractness comes from the primitive operation of the
16413 -- actual, not from the operation inherited from the ancestor.
16415 Set_Is_Abstract_Subprogram
16416 (New_Subp
, Is_Abstract_Subprogram
(Actual_Subp
));
16420 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
16422 -- Ada RM 6.1.1 (15): If a subprogram inherits nonconforming class-wide
16423 -- preconditions and the derived type is abstract, the derived operation
16424 -- is abstract as well if parent subprogram is not abstract or null.
16426 if Is_Abstract_Type
(Derived_Type
)
16427 and then Has_Non_Trivial_Precondition
(Parent_Subp
)
16428 and then Present
(Interfaces
(Derived_Type
))
16431 -- Add useful attributes of subprogram before the freeze point,
16432 -- in case freezing is delayed or there are previous errors.
16434 Set_Is_Dispatching_Operation
(New_Subp
);
16437 Iface_Prim
: constant Entity_Id
:= Covered_Interface_Op
(New_Subp
);
16440 if Present
(Iface_Prim
)
16441 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
16443 Set_Is_Abstract_Subprogram
(New_Subp
);
16448 -- Check for case of a derived subprogram for the instantiation of a
16449 -- formal derived tagged type, if so mark the subprogram as dispatching
16450 -- and inherit the dispatching attributes of the actual subprogram. The
16451 -- derived subprogram is effectively renaming of the actual subprogram,
16452 -- so it needs to have the same attributes as the actual.
16454 if Present
(Actual_Subp
)
16455 and then Is_Dispatching_Operation
(Actual_Subp
)
16457 Set_Is_Dispatching_Operation
(New_Subp
);
16459 if Present
(DTC_Entity
(Actual_Subp
)) then
16460 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Actual_Subp
));
16461 Set_DT_Position_Value
(New_Subp
, DT_Position
(Actual_Subp
));
16465 -- Indicate that a derived subprogram does not require a body and that
16466 -- it does not require processing of default expressions.
16468 Set_Has_Completion
(New_Subp
);
16469 Set_Default_Expressions_Processed
(New_Subp
);
16471 if Ekind
(New_Subp
) = E_Function
then
16472 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
16473 Set_Returns_By_Ref
(New_Subp
, Returns_By_Ref
(Parent_Subp
));
16476 -- Ada 2022 (AI12-0279): If a Yield aspect is specified True for a
16477 -- primitive subprogram S of a type T, then the aspect is inherited
16478 -- by the corresponding primitive subprogram of each descendant of T.
16480 if Is_Tagged_Type
(Derived_Type
)
16481 and then Is_Dispatching_Operation
(New_Subp
)
16482 and then Has_Yield_Aspect
(Alias
(New_Subp
))
16484 Set_Has_Yield_Aspect
(New_Subp
, Has_Yield_Aspect
(Alias
(New_Subp
)));
16487 Set_Is_Ada_2022_Only
(New_Subp
, Is_Ada_2022_Only
(Parent_Subp
));
16488 end Derive_Subprogram
;
16490 ------------------------
16491 -- Derive_Subprograms --
16492 ------------------------
16494 procedure Derive_Subprograms
16495 (Parent_Type
: Entity_Id
;
16496 Derived_Type
: Entity_Id
;
16497 Generic_Actual
: Entity_Id
:= Empty
)
16499 Op_List
: constant Elist_Id
:=
16500 Collect_Primitive_Operations
(Parent_Type
);
16502 function Check_Derived_Type
return Boolean;
16503 -- Check that all the entities derived from Parent_Type are found in
16504 -- the list of primitives of Derived_Type exactly in the same order.
16506 procedure Derive_Interface_Subprogram
16507 (New_Subp
: out Entity_Id
;
16509 Actual_Subp
: Entity_Id
);
16510 -- Derive New_Subp from the ultimate alias of the parent subprogram Subp
16511 -- (which is an interface primitive). If Generic_Actual is present then
16512 -- Actual_Subp is the actual subprogram corresponding with the generic
16513 -- subprogram Subp.
16515 ------------------------
16516 -- Check_Derived_Type --
16517 ------------------------
16519 function Check_Derived_Type
return Boolean is
16521 Derived_Elmt
: Elmt_Id
;
16522 Derived_Op
: Entity_Id
;
16523 Derived_Ops
: Elist_Id
;
16524 Parent_Elmt
: Elmt_Id
;
16525 Parent_Op
: Entity_Id
;
16528 -- Traverse list of entities in the current scope searching for
16529 -- an incomplete type whose full-view is derived type.
16531 E
:= First_Entity
(Scope
(Derived_Type
));
16532 while Present
(E
) and then E
/= Derived_Type
loop
16533 if Ekind
(E
) = E_Incomplete_Type
16534 and then Present
(Full_View
(E
))
16535 and then Full_View
(E
) = Derived_Type
16537 -- Disable this test if Derived_Type completes an incomplete
16538 -- type because in such case more primitives can be added
16539 -- later to the list of primitives of Derived_Type by routine
16540 -- Process_Incomplete_Dependents.
16548 Derived_Ops
:= Collect_Primitive_Operations
(Derived_Type
);
16550 Derived_Elmt
:= First_Elmt
(Derived_Ops
);
16551 Parent_Elmt
:= First_Elmt
(Op_List
);
16552 while Present
(Parent_Elmt
) loop
16553 Parent_Op
:= Node
(Parent_Elmt
);
16554 Derived_Op
:= Node
(Derived_Elmt
);
16556 -- At this early stage Derived_Type has no entities with attribute
16557 -- Interface_Alias. In addition, such primitives are always
16558 -- located at the end of the list of primitives of Parent_Type.
16559 -- Therefore, if found we can safely stop processing pending
16562 exit when Present
(Interface_Alias
(Parent_Op
));
16564 -- Handle hidden entities
16566 if not Is_Predefined_Dispatching_Operation
(Parent_Op
)
16567 and then Is_Hidden
(Parent_Op
)
16569 if Present
(Derived_Op
)
16570 and then Primitive_Names_Match
(Parent_Op
, Derived_Op
)
16572 Next_Elmt
(Derived_Elmt
);
16577 or else Ekind
(Parent_Op
) /= Ekind
(Derived_Op
)
16578 or else not Primitive_Names_Match
(Parent_Op
, Derived_Op
)
16583 Next_Elmt
(Derived_Elmt
);
16586 Next_Elmt
(Parent_Elmt
);
16590 end Check_Derived_Type
;
16592 ---------------------------------
16593 -- Derive_Interface_Subprogram --
16594 ---------------------------------
16596 procedure Derive_Interface_Subprogram
16597 (New_Subp
: out Entity_Id
;
16599 Actual_Subp
: Entity_Id
)
16601 Iface_Subp
: constant Entity_Id
:= Ultimate_Alias
(Subp
);
16602 Iface_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Iface_Subp
);
16605 pragma Assert
(Is_Interface
(Iface_Type
));
16608 (New_Subp
=> New_Subp
,
16609 Parent_Subp
=> Iface_Subp
,
16610 Derived_Type
=> Derived_Type
,
16611 Parent_Type
=> Iface_Type
,
16612 Actual_Subp
=> Actual_Subp
);
16614 -- Given that this new interface entity corresponds with a primitive
16615 -- of the parent that was not overridden we must leave it associated
16616 -- with its parent primitive to ensure that it will share the same
16617 -- dispatch table slot when overridden. We must set the Alias to Subp
16618 -- (instead of Iface_Subp), and we must fix Is_Abstract_Subprogram
16619 -- (in case we inherited Subp from Iface_Type via a nonabstract
16620 -- generic formal type).
16622 if No
(Actual_Subp
) then
16623 Set_Alias
(New_Subp
, Subp
);
16626 T
: Entity_Id
:= Find_Dispatching_Type
(Subp
);
16628 while Etype
(T
) /= T
loop
16629 if Is_Generic_Type
(T
) and then not Is_Abstract_Type
(T
) then
16630 Set_Is_Abstract_Subprogram
(New_Subp
, False);
16638 -- For instantiations this is not needed since the previous call to
16639 -- Derive_Subprogram leaves the entity well decorated.
16642 pragma Assert
(Alias
(New_Subp
) = Actual_Subp
);
16645 end Derive_Interface_Subprogram
;
16649 Alias_Subp
: Entity_Id
;
16650 Act_List
: Elist_Id
;
16651 Act_Elmt
: Elmt_Id
;
16652 Act_Subp
: Entity_Id
:= Empty
;
16654 Need_Search
: Boolean := False;
16655 New_Subp
: Entity_Id
;
16656 Parent_Base
: Entity_Id
;
16659 -- Start of processing for Derive_Subprograms
16662 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
16663 and then Has_Discriminants
(Parent_Type
)
16664 and then Present
(Full_View
(Parent_Type
))
16666 Parent_Base
:= Full_View
(Parent_Type
);
16668 Parent_Base
:= Parent_Type
;
16671 if Present
(Generic_Actual
) then
16672 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
16673 Act_Elmt
:= First_Elmt
(Act_List
);
16675 Act_List
:= No_Elist
;
16676 Act_Elmt
:= No_Elmt
;
16679 -- Derive primitives inherited from the parent. Note that if the generic
16680 -- actual is present, this is not really a type derivation, it is a
16681 -- completion within an instance.
16683 -- Case 1: Derived_Type does not implement interfaces
16685 if not Is_Tagged_Type
(Derived_Type
)
16686 or else (not Has_Interfaces
(Derived_Type
)
16687 and then not (Present
(Generic_Actual
)
16688 and then Has_Interfaces
(Generic_Actual
)))
16690 Elmt
:= First_Elmt
(Op_List
);
16691 while Present
(Elmt
) loop
16692 Subp
:= Node
(Elmt
);
16694 -- Literals are derived earlier in the process of building the
16695 -- derived type, and are skipped here.
16697 if Ekind
(Subp
) = E_Enumeration_Literal
then
16700 -- The actual is a direct descendant and the common primitive
16701 -- operations appear in the same order.
16703 -- If the generic parent type is present, the derived type is an
16704 -- instance of a formal derived type, and within the instance its
16705 -- operations are those of the actual. We derive from the formal
16706 -- type but make the inherited operations aliases of the
16707 -- corresponding operations of the actual.
16710 pragma Assert
(No
(Node
(Act_Elmt
))
16711 or else (Primitive_Names_Match
(Subp
, Node
(Act_Elmt
))
16714 (Subp
, Node
(Act_Elmt
),
16715 Skip_Controlling_Formals
=> True)));
16718 (New_Subp
, Subp
, Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
16720 if Present
(Act_Elmt
) then
16721 Next_Elmt
(Act_Elmt
);
16728 -- Case 2: Derived_Type implements interfaces
16731 -- If the parent type has no predefined primitives we remove
16732 -- predefined primitives from the list of primitives of generic
16733 -- actual to simplify the complexity of this algorithm.
16735 if Present
(Generic_Actual
) then
16737 Has_Predefined_Primitives
: Boolean := False;
16740 -- Check if the parent type has predefined primitives
16742 Elmt
:= First_Elmt
(Op_List
);
16743 while Present
(Elmt
) loop
16744 Subp
:= Node
(Elmt
);
16746 if Is_Predefined_Dispatching_Operation
(Subp
)
16747 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
16749 Has_Predefined_Primitives
:= True;
16756 -- Remove predefined primitives of Generic_Actual. We must use
16757 -- an auxiliary list because in case of tagged types the value
16758 -- returned by Collect_Primitive_Operations is the value stored
16759 -- in its Primitive_Operations attribute (and we don't want to
16760 -- modify its current contents).
16762 if not Has_Predefined_Primitives
then
16764 Aux_List
: constant Elist_Id
:= New_Elmt_List
;
16767 Elmt
:= First_Elmt
(Act_List
);
16768 while Present
(Elmt
) loop
16769 Subp
:= Node
(Elmt
);
16771 if not Is_Predefined_Dispatching_Operation
(Subp
)
16772 or else Comes_From_Source
(Subp
)
16774 Append_Elmt
(Subp
, Aux_List
);
16780 Act_List
:= Aux_List
;
16784 Act_Elmt
:= First_Elmt
(Act_List
);
16785 Act_Subp
:= Node
(Act_Elmt
);
16789 -- Stage 1: If the generic actual is not present we derive the
16790 -- primitives inherited from the parent type. If the generic parent
16791 -- type is present, the derived type is an instance of a formal
16792 -- derived type, and within the instance its operations are those of
16793 -- the actual. We derive from the formal type but make the inherited
16794 -- operations aliases of the corresponding operations of the actual.
16796 Elmt
:= First_Elmt
(Op_List
);
16797 while Present
(Elmt
) loop
16798 Subp
:= Node
(Elmt
);
16799 Alias_Subp
:= Ultimate_Alias
(Subp
);
16801 -- Do not derive internal entities of the parent that link
16802 -- interface primitives with their covering primitive. These
16803 -- entities will be added to this type when frozen.
16805 if Present
(Interface_Alias
(Subp
)) then
16809 -- If the generic actual is present find the corresponding
16810 -- operation in the generic actual. If the parent type is a
16811 -- direct ancestor of the derived type then, even if it is an
16812 -- interface, the operations are inherited from the primary
16813 -- dispatch table and are in the proper order. If we detect here
16814 -- that primitives are not in the same order we traverse the list
16815 -- of primitive operations of the actual to find the one that
16816 -- implements the interface primitive.
16820 (Present
(Generic_Actual
)
16821 and then Present
(Act_Subp
)
16823 (Primitive_Names_Match
(Subp
, Act_Subp
)
16825 Type_Conformant
(Subp
, Act_Subp
,
16826 Skip_Controlling_Formals
=> True)))
16828 pragma Assert
(not Is_Ancestor
(Parent_Base
, Generic_Actual
,
16829 Use_Full_View
=> True));
16831 -- Remember that we need searching for all pending primitives
16833 Need_Search
:= True;
16835 -- Handle entities associated with interface primitives
16837 if Present
(Alias_Subp
)
16838 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
16839 and then not Is_Predefined_Dispatching_Operation
(Subp
)
16841 -- Search for the primitive in the homonym chain
16844 Find_Primitive_Covering_Interface
16845 (Tagged_Type
=> Generic_Actual
,
16846 Iface_Prim
=> Alias_Subp
);
16848 -- Previous search may not locate primitives covering
16849 -- interfaces defined in generics units or instantiations.
16850 -- (it fails if the covering primitive has formals whose
16851 -- type is also defined in generics or instantiations).
16852 -- In such case we search in the list of primitives of the
16853 -- generic actual for the internal entity that links the
16854 -- interface primitive and the covering primitive.
16857 and then Is_Generic_Type
(Parent_Type
)
16859 -- This code has been designed to handle only generic
16860 -- formals that implement interfaces that are defined
16861 -- in a generic unit or instantiation. If this code is
16862 -- needed for other cases we must review it because
16863 -- (given that it relies on Original_Location to locate
16864 -- the primitive of Generic_Actual that covers the
16865 -- interface) it could leave linked through attribute
16866 -- Alias entities of unrelated instantiations).
16870 (Scope
(Find_Dispatching_Type
(Alias_Subp
)))
16872 Instantiation_Location
16873 (Sloc
(Find_Dispatching_Type
(Alias_Subp
)))
16876 Iface_Prim_Loc
: constant Source_Ptr
:=
16877 Original_Location
(Sloc
(Alias_Subp
));
16884 First_Elmt
(Primitive_Operations
(Generic_Actual
));
16886 Search
: while Present
(Elmt
) loop
16887 Prim
:= Node
(Elmt
);
16889 if Present
(Interface_Alias
(Prim
))
16890 and then Original_Location
16891 (Sloc
(Interface_Alias
(Prim
))) =
16894 Act_Subp
:= Alias
(Prim
);
16903 pragma Assert
(Present
(Act_Subp
)
16904 or else Is_Abstract_Type
(Generic_Actual
)
16905 or else Serious_Errors_Detected
> 0);
16907 -- Handle predefined primitives plus the rest of user-defined
16911 Act_Elmt
:= First_Elmt
(Act_List
);
16912 while Present
(Act_Elmt
) loop
16913 Act_Subp
:= Node
(Act_Elmt
);
16915 exit when Primitive_Names_Match
(Subp
, Act_Subp
)
16916 and then Type_Conformant
16918 Skip_Controlling_Formals
=> True)
16919 and then No
(Interface_Alias
(Act_Subp
));
16921 Next_Elmt
(Act_Elmt
);
16924 if No
(Act_Elmt
) then
16930 -- Case 1: If the parent is a limited interface then it has the
16931 -- predefined primitives of synchronized interfaces. However, the
16932 -- actual type may be a non-limited type and hence it does not
16933 -- have such primitives.
16935 if Present
(Generic_Actual
)
16936 and then No
(Act_Subp
)
16937 and then Is_Limited_Interface
(Parent_Base
)
16938 and then Is_Predefined_Interface_Primitive
(Subp
)
16942 -- Case 2: Inherit entities associated with interfaces that were
16943 -- not covered by the parent type. We exclude here null interface
16944 -- primitives because they do not need special management.
16946 -- We also exclude interface operations that are renamings. If the
16947 -- subprogram is an explicit renaming of an interface primitive,
16948 -- it is a regular primitive operation, and the presence of its
16949 -- alias is not relevant: it has to be derived like any other
16952 elsif Present
(Alias
(Subp
))
16953 and then Nkind
(Unit_Declaration_Node
(Subp
)) /=
16954 N_Subprogram_Renaming_Declaration
16955 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
16957 (Nkind
(Parent
(Alias_Subp
)) = N_Procedure_Specification
16958 and then Null_Present
(Parent
(Alias_Subp
)))
16960 -- If this is an abstract private type then we transfer the
16961 -- derivation of the interface primitive from the partial view
16962 -- to the full view. This is safe because all the interfaces
16963 -- must be visible in the partial view. Done to avoid adding
16964 -- a new interface derivation to the private part of the
16965 -- enclosing package; otherwise this new derivation would be
16966 -- decorated as hidden when the analysis of the enclosing
16967 -- package completes.
16969 if Is_Abstract_Type
(Derived_Type
)
16970 and then In_Private_Part
(Current_Scope
)
16971 and then Has_Private_Declaration
(Derived_Type
)
16974 Partial_View
: Entity_Id
;
16979 Partial_View
:= First_Entity
(Current_Scope
);
16981 exit when No
(Partial_View
)
16982 or else (Has_Private_Declaration
(Partial_View
)
16984 Full_View
(Partial_View
) = Derived_Type
);
16986 Next_Entity
(Partial_View
);
16989 -- If the partial view was not found then the source code
16990 -- has errors and the derivation is not needed.
16992 if Present
(Partial_View
) then
16994 First_Elmt
(Primitive_Operations
(Partial_View
));
16995 while Present
(Elmt
) loop
16996 Ent
:= Node
(Elmt
);
16998 if Present
(Alias
(Ent
))
16999 and then Ultimate_Alias
(Ent
) = Alias
(Subp
)
17002 (Ent
, Primitive_Operations
(Derived_Type
));
17009 -- If the interface primitive was not found in the
17010 -- partial view then this interface primitive was
17011 -- overridden. We add a derivation to activate in
17012 -- Derive_Progenitor_Subprograms the machinery to
17016 Derive_Interface_Subprogram
17017 (New_Subp
=> New_Subp
,
17019 Actual_Subp
=> Act_Subp
);
17024 Derive_Interface_Subprogram
17025 (New_Subp
=> New_Subp
,
17027 Actual_Subp
=> Act_Subp
);
17030 -- Case 3: Common derivation
17034 (New_Subp
=> New_Subp
,
17035 Parent_Subp
=> Subp
,
17036 Derived_Type
=> Derived_Type
,
17037 Parent_Type
=> Parent_Base
,
17038 Actual_Subp
=> Act_Subp
);
17041 -- No need to update Act_Elm if we must search for the
17042 -- corresponding operation in the generic actual
17045 and then Present
(Act_Elmt
)
17047 Next_Elmt
(Act_Elmt
);
17048 Act_Subp
:= Node
(Act_Elmt
);
17055 -- Inherit additional operations from progenitors. If the derived
17056 -- type is a generic actual, there are not new primitive operations
17057 -- for the type because it has those of the actual, and therefore
17058 -- nothing needs to be done. The renamings generated above are not
17059 -- primitive operations, and their purpose is simply to make the
17060 -- proper operations visible within an instantiation.
17062 if No
(Generic_Actual
) then
17063 Derive_Progenitor_Subprograms
(Parent_Base
, Derived_Type
);
17067 -- Final check: Direct descendants must have their primitives in the
17068 -- same order. We exclude from this test untagged types and instances
17069 -- of formal derived types. We skip this test if we have already
17070 -- reported serious errors in the sources.
17072 pragma Assert
(not Is_Tagged_Type
(Derived_Type
)
17073 or else Present
(Generic_Actual
)
17074 or else Serious_Errors_Detected
> 0
17075 or else Check_Derived_Type
);
17076 end Derive_Subprograms
;
17078 --------------------------------
17079 -- Derived_Standard_Character --
17080 --------------------------------
17082 procedure Derived_Standard_Character
17084 Parent_Type
: Entity_Id
;
17085 Derived_Type
: Entity_Id
)
17087 Loc
: constant Source_Ptr
:= Sloc
(N
);
17088 Def
: constant Node_Id
:= Type_Definition
(N
);
17089 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17090 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
17091 Implicit_Base
: constant Entity_Id
:=
17093 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
17099 Discard_Node
(Process_Subtype
(Indic
, N
));
17101 Set_Etype
(Implicit_Base
, Parent_Base
);
17102 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
17103 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
17105 Set_Is_Character_Type
(Implicit_Base
, True);
17106 Set_Has_Delayed_Freeze
(Implicit_Base
);
17108 -- The bounds of the implicit base are the bounds of the parent base.
17109 -- Note that their type is the parent base.
17111 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
17112 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
17114 Set_Scalar_Range
(Implicit_Base
,
17117 High_Bound
=> Hi
));
17119 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
17120 Set_Etype
(Derived_Type
, Implicit_Base
);
17121 Set_Size_Info
(Derived_Type
, Parent_Type
);
17123 if not Known_RM_Size
(Derived_Type
) then
17124 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
17127 Set_Is_Character_Type
(Derived_Type
, True);
17129 if Nkind
(Indic
) /= N_Subtype_Indication
then
17131 -- If no explicit constraint, the bounds are those
17132 -- of the parent type.
17134 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
17135 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
17136 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
17139 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
17140 end Derived_Standard_Character
;
17142 ------------------------------
17143 -- Derived_Type_Declaration --
17144 ------------------------------
17146 procedure Derived_Type_Declaration
17149 Is_Completion
: Boolean)
17151 Parent_Type
: Entity_Id
;
17153 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean;
17154 -- Check whether the parent type is a generic formal, or derives
17155 -- directly or indirectly from one.
17157 ------------------------
17158 -- Comes_From_Generic --
17159 ------------------------
17161 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean is
17163 if Is_Generic_Type
(Typ
) then
17166 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
17169 elsif Is_Private_Type
(Typ
)
17170 and then Present
(Full_View
(Typ
))
17171 and then Is_Generic_Type
(Root_Type
(Full_View
(Typ
)))
17175 elsif Is_Generic_Actual_Type
(Typ
) then
17181 end Comes_From_Generic
;
17185 Def
: constant Node_Id
:= Type_Definition
(N
);
17186 Iface_Def
: Node_Id
;
17187 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17188 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
17189 Parent_Node
: Node_Id
;
17192 -- Start of processing for Derived_Type_Declaration
17195 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
17198 and then Is_Tagged_Type
(Parent_Type
)
17201 Partial_View
: constant Entity_Id
:=
17202 Incomplete_Or_Partial_View
(Parent_Type
);
17205 -- If the partial view was not found then the parent type is not
17206 -- a private type. Otherwise check if the partial view is a tagged
17209 if Present
(Partial_View
)
17210 and then Is_Private_Type
(Partial_View
)
17211 and then not Is_Tagged_Type
(Partial_View
)
17214 ("cannot derive from & declared as untagged private "
17215 & "(SPARK RM 3.4(1))", N
, Partial_View
);
17220 -- Ada 2005 (AI-251): In case of interface derivation check that the
17221 -- parent is also an interface.
17223 if Interface_Present
(Def
) then
17224 if not Is_Interface
(Parent_Type
) then
17225 Diagnose_Interface
(Indic
, Parent_Type
);
17228 Parent_Node
:= Parent
(Base_Type
(Parent_Type
));
17229 Iface_Def
:= Type_Definition
(Parent_Node
);
17231 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
17232 -- other limited interfaces.
17234 if Limited_Present
(Def
) then
17235 if Limited_Present
(Iface_Def
) then
17238 elsif Protected_Present
(Iface_Def
) then
17240 ("descendant of & must be declared as a protected "
17241 & "interface", N
, Parent_Type
);
17243 elsif Synchronized_Present
(Iface_Def
) then
17245 ("descendant of & must be declared as a synchronized "
17246 & "interface", N
, Parent_Type
);
17248 elsif Task_Present
(Iface_Def
) then
17250 ("descendant of & must be declared as a task interface",
17255 ("(Ada 2005) limited interface cannot inherit from "
17256 & "non-limited interface", Indic
);
17259 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
17260 -- from non-limited or limited interfaces.
17262 elsif not Protected_Present
(Def
)
17263 and then not Synchronized_Present
(Def
)
17264 and then not Task_Present
(Def
)
17266 if Limited_Present
(Iface_Def
) then
17269 elsif Protected_Present
(Iface_Def
) then
17271 ("descendant of & must be declared as a protected "
17272 & "interface", N
, Parent_Type
);
17274 elsif Synchronized_Present
(Iface_Def
) then
17276 ("descendant of & must be declared as a synchronized "
17277 & "interface", N
, Parent_Type
);
17279 elsif Task_Present
(Iface_Def
) then
17281 ("descendant of & must be declared as a task interface",
17290 if Is_Tagged_Type
(Parent_Type
)
17291 and then Is_Concurrent_Type
(Parent_Type
)
17292 and then not Is_Interface
(Parent_Type
)
17295 ("parent type of a record extension cannot be a synchronized "
17296 & "tagged type (RM 3.9.1 (3/1))", N
);
17297 Set_Etype
(T
, Any_Type
);
17301 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
17304 if Is_Tagged_Type
(Parent_Type
)
17305 and then Is_Non_Empty_List
(Interface_List
(Def
))
17312 Intf
:= First
(Interface_List
(Def
));
17313 while Present
(Intf
) loop
17314 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
17316 if not Is_Interface
(T
) then
17317 Diagnose_Interface
(Intf
, T
);
17319 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
17320 -- a limited type from having a nonlimited progenitor.
17322 elsif (Limited_Present
(Def
)
17323 or else (not Is_Interface
(Parent_Type
)
17324 and then Is_Limited_Type
(Parent_Type
)))
17325 and then not Is_Limited_Interface
(T
)
17328 ("progenitor interface& of limited type must be limited",
17336 -- Check consistency of any nonoverridable aspects that are
17337 -- inherited from multiple sources.
17339 Check_Inherited_Nonoverridable_Aspects
17341 Interface_List
=> Interface_List
(Def
),
17342 Parent_Type
=> Parent_Type
);
17345 if Parent_Type
= Any_Type
17346 or else Etype
(Parent_Type
) = Any_Type
17347 or else (Is_Class_Wide_Type
(Parent_Type
)
17348 and then Etype
(Parent_Type
) = T
)
17350 -- If Parent_Type is undefined or illegal, make new type into a
17351 -- subtype of Any_Type, and set a few attributes to prevent cascaded
17352 -- errors. If this is a self-definition, emit error now.
17354 if T
= Parent_Type
or else T
= Etype
(Parent_Type
) then
17355 Error_Msg_N
("type cannot be used in its own definition", Indic
);
17358 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
17359 Set_Etype
(T
, Any_Type
);
17360 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
17362 -- Initialize the list of primitive operations to an empty list,
17363 -- to cover tagged types as well as untagged types. For untagged
17364 -- types this is used either to analyze the call as legal when
17365 -- Extensions_Allowed is True, or to issue a better error message
17368 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
17373 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
17374 -- an interface is special because the list of interfaces in the full
17375 -- view can be given in any order. For example:
17377 -- type A is interface;
17378 -- type B is interface and A;
17379 -- type D is new B with private;
17381 -- type D is new A and B with null record; -- 1 --
17383 -- In this case we perform the following transformation of -1-:
17385 -- type D is new B and A with null record;
17387 -- If the parent of the full-view covers the parent of the partial-view
17388 -- we have two possible cases:
17390 -- 1) They have the same parent
17391 -- 2) The parent of the full-view implements some further interfaces
17393 -- In both cases we do not need to perform the transformation. In the
17394 -- first case the source program is correct and the transformation is
17395 -- not needed; in the second case the source program does not fulfill
17396 -- the no-hidden interfaces rule (AI-396) and the error will be reported
17399 -- This transformation not only simplifies the rest of the analysis of
17400 -- this type declaration but also simplifies the correct generation of
17401 -- the object layout to the expander.
17403 if In_Private_Part
(Current_Scope
)
17404 and then Is_Interface
(Parent_Type
)
17407 Partial_View
: Entity_Id
;
17408 Partial_View_Parent
: Entity_Id
;
17410 function Reorder_Interfaces
return Boolean;
17411 -- Look for an interface in the full view's interface list that
17412 -- matches the parent type of the partial view, and when found,
17413 -- rewrite the full view's parent with the partial view's parent,
17414 -- append the full view's original parent to the interface list,
17415 -- recursively call Derived_Type_Definition on the full type, and
17416 -- return True. If a match is not found, return False.
17418 ------------------------
17419 -- Reorder_Interfaces --
17420 ------------------------
17422 function Reorder_Interfaces
return Boolean is
17424 New_Iface
: Node_Id
;
17427 Iface
:= First
(Interface_List
(Def
));
17428 while Present
(Iface
) loop
17429 if Etype
(Iface
) = Etype
(Partial_View
) then
17430 Rewrite
(Subtype_Indication
(Def
),
17431 New_Copy
(Subtype_Indication
(Parent
(Partial_View
))));
17434 Make_Identifier
(Sloc
(N
), Chars
(Parent_Type
));
17435 Rewrite
(Iface
, New_Iface
);
17437 -- Analyze the transformed code
17439 Derived_Type_Declaration
(T
, N
, Is_Completion
);
17446 end Reorder_Interfaces
;
17449 -- Look for the associated private type declaration
17451 Partial_View
:= Incomplete_Or_Partial_View
(T
);
17453 -- If the partial view was not found then the source code has
17454 -- errors and the transformation is not needed.
17456 if Present
(Partial_View
) then
17457 Partial_View_Parent
:= Etype
(Partial_View
);
17459 -- If the parent of the full-view covers the parent of the
17460 -- partial-view we have nothing else to do.
17462 if Interface_Present_In_Ancestor
17463 (Parent_Type
, Partial_View_Parent
)
17467 -- Traverse the list of interfaces of the full view to look
17468 -- for the parent of the partial view and reorder the
17469 -- interfaces to match the order in the partial view,
17474 if Reorder_Interfaces
then
17475 -- Having the interfaces listed in any order is legal.
17476 -- However, the compiler does not properly handle
17477 -- different orders between partial and full views in
17478 -- generic units. We give a warning about the order
17479 -- mismatch, so the user can work around this problem.
17481 Error_Msg_N
("??full declaration does not respect " &
17482 "partial declaration order", T
);
17483 Error_Msg_N
("\??consider reordering", T
);
17492 -- Only composite types other than array types are allowed to have
17495 if Present
(Discriminant_Specifications
(N
)) then
17496 if (Is_Elementary_Type
(Parent_Type
)
17498 Is_Array_Type
(Parent_Type
))
17499 and then not Error_Posted
(N
)
17502 ("elementary or array type cannot have discriminants",
17503 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
17505 -- Unset Has_Discriminants flag to prevent cascaded errors, but
17506 -- only if we are not already processing a malformed syntax tree.
17508 if Is_Type
(T
) then
17509 Set_Has_Discriminants
(T
, False);
17514 -- In Ada 83, a derived type defined in a package specification cannot
17515 -- be used for further derivation until the end of its visible part.
17516 -- Note that derivation in the private part of the package is allowed.
17518 if Ada_Version
= Ada_83
17519 and then Is_Derived_Type
(Parent_Type
)
17520 and then In_Visible_Part
(Scope
(Parent_Type
))
17522 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
17524 ("(Ada 83) premature use of type for derivation", Indic
);
17528 -- Check for early use of incomplete or private type
17530 if Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
17531 Error_Msg_N
("premature derivation of incomplete type", Indic
);
17534 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
17535 and then not Comes_From_Generic
(Parent_Type
))
17536 or else Has_Private_Component
(Parent_Type
)
17538 -- The ancestor type of a formal type can be incomplete, in which
17539 -- case only the operations of the partial view are available in the
17540 -- generic. Subsequent checks may be required when the full view is
17541 -- analyzed to verify that a derivation from a tagged type has an
17544 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
17547 elsif No
(Underlying_Type
(Parent_Type
))
17548 or else Has_Private_Component
(Parent_Type
)
17551 ("premature derivation of derived or private type", Indic
);
17553 -- Flag the type itself as being in error, this prevents some
17554 -- nasty problems with subsequent uses of the malformed type.
17556 Set_Error_Posted
(T
);
17558 -- Check that within the immediate scope of an untagged partial
17559 -- view it's illegal to derive from the partial view if the
17560 -- full view is tagged. (7.3(7))
17562 -- We verify that the Parent_Type is a partial view by checking
17563 -- that it is not a Full_Type_Declaration (i.e. a private type or
17564 -- private extension declaration), to distinguish a partial view
17565 -- from a derivation from a private type which also appears as
17566 -- E_Private_Type. If the parent base type is not declared in an
17567 -- enclosing scope there is no need to check.
17569 elsif Present
(Full_View
(Parent_Type
))
17570 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
17571 and then not Is_Tagged_Type
(Parent_Type
)
17572 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
17573 and then In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
17576 ("premature derivation from type with tagged full view",
17581 -- Check that form of derivation is appropriate
17583 Taggd
:= Is_Tagged_Type
(Parent_Type
);
17585 -- Set the parent type to the class-wide type's specific type in this
17586 -- case to prevent cascading errors
17588 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
17589 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
17590 Set_Etype
(T
, Etype
(Parent_Type
));
17594 if Present
(Extension
) and then not Taggd
then
17596 ("type derived from untagged type cannot have extension", Indic
);
17598 elsif No
(Extension
) and then Taggd
then
17600 -- If this declaration is within a private part (or body) of a
17601 -- generic instantiation then the derivation is allowed (the parent
17602 -- type can only appear tagged in this case if it's a generic actual
17603 -- type, since it would otherwise have been rejected in the analysis
17604 -- of the generic template).
17606 if not Is_Generic_Actual_Type
(Parent_Type
)
17607 or else In_Visible_Part
(Scope
(Parent_Type
))
17609 if Is_Class_Wide_Type
(Parent_Type
) then
17611 ("parent type must not be a class-wide type", Indic
);
17613 -- Use specific type to prevent cascaded errors.
17615 Parent_Type
:= Etype
(Parent_Type
);
17619 ("type derived from tagged type must have extension", Indic
);
17624 -- AI-443: Synchronized formal derived types require a private
17625 -- extension. There is no point in checking the ancestor type or
17626 -- the progenitors since the construct is wrong to begin with.
17628 if Ada_Version
>= Ada_2005
17629 and then Is_Generic_Type
(T
)
17630 and then Present
(Original_Node
(N
))
17633 Decl
: constant Node_Id
:= Original_Node
(N
);
17636 if Nkind
(Decl
) = N_Formal_Type_Declaration
17637 and then Nkind
(Formal_Type_Definition
(Decl
)) =
17638 N_Formal_Derived_Type_Definition
17639 and then Synchronized_Present
(Formal_Type_Definition
(Decl
))
17640 and then No
(Extension
)
17642 -- Avoid emitting a duplicate error message
17644 and then not Error_Posted
(Indic
)
17647 ("synchronized derived type must have extension", N
);
17652 if Null_Exclusion_Present
(Def
)
17653 and then not Is_Access_Type
(Parent_Type
)
17655 Error_Msg_N
("null exclusion can only apply to an access type", N
);
17658 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
17660 -- Avoid deriving parent primitives of underlying record views
17662 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
,
17663 Derive_Subps
=> not Is_Underlying_Record_View
(T
));
17665 -- AI-419: The parent type of an explicitly limited derived type must
17666 -- be a limited type or a limited interface.
17668 if Limited_Present
(Def
) then
17669 Set_Is_Limited_Record
(T
);
17671 if Is_Interface
(T
) then
17672 Set_Is_Limited_Interface
(T
);
17675 if not Is_Limited_Type
(Parent_Type
)
17677 (not Is_Interface
(Parent_Type
)
17678 or else not Is_Limited_Interface
(Parent_Type
))
17680 -- AI05-0096: a derivation in the private part of an instance is
17681 -- legal if the generic formal is untagged limited, and the actual
17684 if Is_Generic_Actual_Type
(Parent_Type
)
17685 and then In_Private_Part
(Current_Scope
)
17688 (Generic_Parent_Type
(Parent
(Parent_Type
)))
17694 ("parent type& of limited type must be limited",
17699 end Derived_Type_Declaration
;
17701 ------------------------
17702 -- Diagnose_Interface --
17703 ------------------------
17705 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
) is
17707 if not Is_Interface
(E
) and then E
/= Any_Type
then
17708 Error_Msg_NE
("(Ada 2005) & must be an interface", N
, E
);
17710 end Diagnose_Interface
;
17712 ----------------------------------
17713 -- Enumeration_Type_Declaration --
17714 ----------------------------------
17716 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
17723 -- Create identifier node representing lower bound
17725 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17726 L
:= First
(Literals
(Def
));
17727 Set_Chars
(B_Node
, Chars
(L
));
17728 Set_Entity
(B_Node
, L
);
17729 Set_Etype
(B_Node
, T
);
17730 Set_Is_Static_Expression
(B_Node
, True);
17732 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
17733 Set_Low_Bound
(R_Node
, B_Node
);
17735 Mutate_Ekind
(T
, E_Enumeration_Type
);
17736 Set_First_Literal
(T
, L
);
17738 Set_Is_Constrained
(T
);
17742 -- Loop through literals of enumeration type setting pos and rep values
17743 -- except that if the Ekind is already set, then it means the literal
17744 -- was already constructed (case of a derived type declaration and we
17745 -- should not disturb the Pos and Rep values.
17747 while Present
(L
) loop
17748 if Ekind
(L
) /= E_Enumeration_Literal
then
17749 Mutate_Ekind
(L
, E_Enumeration_Literal
);
17750 Set_Enumeration_Pos
(L
, Ev
);
17751 Set_Enumeration_Rep
(L
, Ev
);
17752 Set_Is_Known_Valid
(L
, True);
17756 New_Overloaded_Entity
(L
);
17757 Generate_Definition
(L
);
17758 Set_Convention
(L
, Convention_Intrinsic
);
17760 -- Case of character literal
17762 if Nkind
(L
) = N_Defining_Character_Literal
then
17763 Set_Is_Character_Type
(T
, True);
17765 -- Check violation of No_Wide_Characters
17767 if Restriction_Check_Required
(No_Wide_Characters
) then
17768 Get_Name_String
(Chars
(L
));
17770 if Name_Len
>= 3 and then Name_Buffer
(1 .. 2) = "QW" then
17771 Check_Restriction
(No_Wide_Characters
, L
);
17780 -- Now create a node representing upper bound
17782 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17783 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
17784 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
17785 Set_Etype
(B_Node
, T
);
17786 Set_Is_Static_Expression
(B_Node
, True);
17788 Set_High_Bound
(R_Node
, B_Node
);
17790 -- Initialize various fields of the type. Some of this information
17791 -- may be overwritten later through rep. clauses.
17793 Set_Scalar_Range
(T
, R_Node
);
17794 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
17795 Set_Enum_Esize
(T
);
17796 Set_Enum_Pos_To_Rep
(T
, Empty
);
17798 -- Set Discard_Names if configuration pragma set, or if there is
17799 -- a parameterless pragma in the current declarative region
17801 if Global_Discard_Names
or else Discard_Names
(Scope
(T
)) then
17802 Set_Discard_Names
(T
);
17805 -- Process end label if there is one
17807 if Present
(Def
) then
17808 Process_End_Label
(Def
, 'e', T
);
17810 end Enumeration_Type_Declaration
;
17812 ---------------------------------
17813 -- Expand_To_Stored_Constraint --
17814 ---------------------------------
17816 function Expand_To_Stored_Constraint
17818 Constraint
: Elist_Id
) return Elist_Id
17820 Explicitly_Discriminated_Type
: Entity_Id
;
17821 Expansion
: Elist_Id
;
17822 Discriminant
: Entity_Id
;
17824 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
17825 -- Find the nearest type that actually specifies discriminants
17827 ---------------------------------
17828 -- Type_With_Explicit_Discrims --
17829 ---------------------------------
17831 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
17832 Typ
: constant E
:= Base_Type
(Id
);
17835 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
17836 if Present
(Full_View
(Typ
)) then
17837 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
17841 if Has_Discriminants
(Typ
) then
17846 if Etype
(Typ
) = Typ
then
17848 elsif Has_Discriminants
(Typ
) then
17851 return Type_With_Explicit_Discrims
(Etype
(Typ
));
17854 end Type_With_Explicit_Discrims
;
17856 -- Start of processing for Expand_To_Stored_Constraint
17859 if No
(Constraint
) or else Is_Empty_Elmt_List
(Constraint
) then
17863 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
17865 if No
(Explicitly_Discriminated_Type
) then
17869 Expansion
:= New_Elmt_List
;
17872 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
17873 while Present
(Discriminant
) loop
17875 (Get_Discriminant_Value
17876 (Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
17878 Next_Stored_Discriminant
(Discriminant
);
17882 end Expand_To_Stored_Constraint
;
17884 ---------------------------
17885 -- Find_Hidden_Interface --
17886 ---------------------------
17888 function Find_Hidden_Interface
17890 Dest
: Elist_Id
) return Entity_Id
17893 Iface_Elmt
: Elmt_Id
;
17896 if Present
(Src
) and then Present
(Dest
) then
17897 Iface_Elmt
:= First_Elmt
(Src
);
17898 while Present
(Iface_Elmt
) loop
17899 Iface
:= Node
(Iface_Elmt
);
17901 if Is_Interface
(Iface
)
17902 and then not Contain_Interface
(Iface
, Dest
)
17907 Next_Elmt
(Iface_Elmt
);
17912 end Find_Hidden_Interface
;
17914 --------------------
17915 -- Find_Type_Name --
17916 --------------------
17918 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
17919 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
17920 New_Id
: Entity_Id
;
17922 Prev_Par
: Node_Id
;
17924 procedure Check_Duplicate_Aspects
;
17925 -- Check that aspects specified in a completion have not been specified
17926 -- already in the partial view.
17928 procedure Tag_Mismatch
;
17929 -- Diagnose a tagged partial view whose full view is untagged. We post
17930 -- the message on the full view, with a reference to the previous
17931 -- partial view. The partial view can be private or incomplete, and
17932 -- these are handled in a different manner, so we determine the position
17933 -- of the error message from the respective slocs of both.
17935 -----------------------------
17936 -- Check_Duplicate_Aspects --
17937 -----------------------------
17939 procedure Check_Duplicate_Aspects
is
17940 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
;
17941 -- Return the corresponding aspect of the partial view which matches
17942 -- the aspect id of Asp. Return Empty is no such aspect exists.
17944 -----------------------------
17945 -- Get_Partial_View_Aspect --
17946 -----------------------------
17948 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
is
17949 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
17950 Prev_Asps
: constant List_Id
:= Aspect_Specifications
(Prev_Par
);
17951 Prev_Asp
: Node_Id
;
17954 if Present
(Prev_Asps
) then
17955 Prev_Asp
:= First
(Prev_Asps
);
17956 while Present
(Prev_Asp
) loop
17957 if Get_Aspect_Id
(Prev_Asp
) = Asp_Id
then
17966 end Get_Partial_View_Aspect
;
17970 Full_Asps
: constant List_Id
:= Aspect_Specifications
(N
);
17971 Full_Asp
: Node_Id
;
17972 Part_Asp
: Node_Id
;
17974 -- Start of processing for Check_Duplicate_Aspects
17977 if Present
(Full_Asps
) then
17978 Full_Asp
:= First
(Full_Asps
);
17979 while Present
(Full_Asp
) loop
17980 Part_Asp
:= Get_Partial_View_Aspect
(Full_Asp
);
17982 -- An aspect and its class-wide counterpart are two distinct
17983 -- aspects and may apply to both views of an entity.
17985 if Present
(Part_Asp
)
17986 and then Class_Present
(Part_Asp
) = Class_Present
(Full_Asp
)
17989 ("aspect already specified in private declaration",
17996 if Has_Discriminants
(Prev
)
17997 and then not Has_Unknown_Discriminants
(Prev
)
17998 and then Get_Aspect_Id
(Full_Asp
) =
17999 Aspect_Implicit_Dereference
18002 ("cannot specify aspect if partial view has known "
18003 & "discriminants", Full_Asp
);
18009 end Check_Duplicate_Aspects
;
18015 procedure Tag_Mismatch
is
18017 if Sloc
(Prev
) < Sloc
(Id
) then
18018 if Ada_Version
>= Ada_2012
18019 and then Nkind
(N
) = N_Private_Type_Declaration
18022 ("declaration of private } must be a tagged type", Id
, Prev
);
18025 ("full declaration of } must be a tagged type", Id
, Prev
);
18029 if Ada_Version
>= Ada_2012
18030 and then Nkind
(N
) = N_Private_Type_Declaration
18033 ("declaration of private } must be a tagged type", Prev
, Id
);
18036 ("full declaration of } must be a tagged type", Prev
, Id
);
18041 -- Start of processing for Find_Type_Name
18044 -- Find incomplete declaration, if one was given
18046 Prev
:= Current_Entity_In_Scope
(Id
);
18048 -- New type declaration
18054 -- Previous declaration exists
18057 Prev_Par
:= Parent
(Prev
);
18059 -- Error if not incomplete/private case except if previous
18060 -- declaration is implicit, etc. Enter_Name will emit error if
18063 if not Is_Incomplete_Or_Private_Type
(Prev
) then
18067 -- Check invalid completion of private or incomplete type
18069 elsif Nkind
(N
) not in N_Full_Type_Declaration
18070 | N_Task_Type_Declaration
18071 | N_Protected_Type_Declaration
18073 (Ada_Version
< Ada_2012
18074 or else not Is_Incomplete_Type
(Prev
)
18075 or else Nkind
(N
) not in N_Private_Type_Declaration
18076 | N_Private_Extension_Declaration
)
18078 -- Completion must be a full type declarations (RM 7.3(4))
18080 Error_Msg_Sloc
:= Sloc
(Prev
);
18081 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
18083 -- Set scope of Id to avoid cascaded errors. Entity is never
18084 -- examined again, except when saving globals in generics.
18086 Set_Scope
(Id
, Current_Scope
);
18089 -- If this is a repeated incomplete declaration, no further
18090 -- checks are possible.
18092 if Nkind
(N
) = N_Incomplete_Type_Declaration
then
18096 -- Case of full declaration of incomplete type
18098 elsif Ekind
(Prev
) = E_Incomplete_Type
18099 and then (Ada_Version
< Ada_2012
18100 or else No
(Full_View
(Prev
))
18101 or else not Is_Private_Type
(Full_View
(Prev
)))
18103 -- Indicate that the incomplete declaration has a matching full
18104 -- declaration. The defining occurrence of the incomplete
18105 -- declaration remains the visible one, and the procedure
18106 -- Get_Full_View dereferences it whenever the type is used.
18108 if Present
(Full_View
(Prev
)) then
18109 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
18112 Set_Full_View
(Prev
, Id
);
18113 Append_Entity
(Id
, Current_Scope
);
18114 Set_Is_Public
(Id
, Is_Public
(Prev
));
18115 Set_Is_Internal
(Id
);
18118 -- If the incomplete view is tagged, a class_wide type has been
18119 -- created already. Use it for the private type as well, in order
18120 -- to prevent multiple incompatible class-wide types that may be
18121 -- created for self-referential anonymous access components.
18123 if Is_Tagged_Type
(Prev
)
18124 and then Present
(Class_Wide_Type
(Prev
))
18126 Mutate_Ekind
(Id
, Ekind
(Prev
)); -- will be reset later
18127 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(Prev
));
18129 -- Type of the class-wide type is the current Id. Previously
18130 -- this was not done for private declarations because of order-
18131 -- of-elaboration issues in the back end, but gigi now handles
18134 Set_Etype
(Class_Wide_Type
(Id
), Id
);
18137 -- Case of full declaration of private type
18140 -- If the private type was a completion of an incomplete type then
18141 -- update Prev to reference the private type
18143 if Ada_Version
>= Ada_2012
18144 and then Ekind
(Prev
) = E_Incomplete_Type
18145 and then Present
(Full_View
(Prev
))
18146 and then Is_Private_Type
(Full_View
(Prev
))
18148 Prev
:= Full_View
(Prev
);
18149 Prev_Par
:= Parent
(Prev
);
18152 if Nkind
(N
) = N_Full_Type_Declaration
18153 and then Nkind
(Type_Definition
(N
)) in
18154 N_Record_Definition | N_Derived_Type_Definition
18155 and then Interface_Present
(Type_Definition
(N
))
18158 ("completion of private type cannot be an interface", N
);
18161 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
18162 if Etype
(Prev
) /= Prev
then
18164 -- Prev is a private subtype or a derived type, and needs
18167 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
18170 elsif Ekind
(Prev
) = E_Private_Type
18171 and then Nkind
(N
) in N_Task_Type_Declaration
18172 | N_Protected_Type_Declaration
18175 ("completion of nonlimited type cannot be limited", N
);
18177 elsif Ekind
(Prev
) = E_Record_Type_With_Private
18178 and then Nkind
(N
) in N_Task_Type_Declaration
18179 | N_Protected_Type_Declaration
18181 if not Is_Limited_Record
(Prev
) then
18183 ("completion of nonlimited type cannot be limited", N
);
18185 elsif No
(Interface_List
(N
)) then
18187 ("completion of tagged private type must be tagged",
18192 -- Ada 2005 (AI-251): Private extension declaration of a task
18193 -- type or a protected type. This case arises when covering
18194 -- interface types.
18196 elsif Nkind
(N
) in N_Task_Type_Declaration
18197 | N_Protected_Type_Declaration
18201 elsif Nkind
(N
) /= N_Full_Type_Declaration
18202 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
18205 ("full view of private extension must be an extension", N
);
18207 elsif not (Abstract_Present
(Parent
(Prev
)))
18208 and then Abstract_Present
(Type_Definition
(N
))
18211 ("full view of non-abstract extension cannot be abstract", N
);
18214 if not In_Private_Part
(Current_Scope
) then
18216 ("declaration of full view must appear in private part", N
);
18219 if Ada_Version
>= Ada_2012
then
18220 Check_Duplicate_Aspects
;
18223 Copy_And_Swap
(Prev
, Id
);
18224 Set_Has_Private_Declaration
(Prev
);
18225 Set_Has_Private_Declaration
(Id
);
18227 -- AI12-0133: Indicate whether we have a partial view with
18228 -- unknown discriminants, in which case initialization of objects
18229 -- of the type do not receive an invariant check.
18231 Set_Partial_View_Has_Unknown_Discr
18232 (Prev
, Has_Unknown_Discriminants
(Id
));
18234 -- Preserve aspect and iterator flags that may have been set on
18235 -- the partial view.
18237 Set_Has_Delayed_Aspects
(Prev
, Has_Delayed_Aspects
(Id
));
18238 Set_Has_Implicit_Dereference
(Prev
, Has_Implicit_Dereference
(Id
));
18240 -- If no error, propagate freeze_node from private to full view.
18241 -- It may have been generated for an early operational item.
18243 if Present
(Freeze_Node
(Id
))
18244 and then Serious_Errors_Detected
= 0
18245 and then No
(Full_View
(Id
))
18247 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
18248 Set_Freeze_Node
(Id
, Empty
);
18249 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
18252 Set_Full_View
(Id
, Prev
);
18256 -- Verify that full declaration conforms to partial one
18258 if Is_Incomplete_Or_Private_Type
(Prev
)
18259 and then Present
(Discriminant_Specifications
(Prev_Par
))
18261 if Present
(Discriminant_Specifications
(N
)) then
18262 if Ekind
(Prev
) = E_Incomplete_Type
then
18263 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
18265 Check_Discriminant_Conformance
(N
, Prev
, Id
);
18270 ("missing discriminants in full type declaration", N
);
18272 -- To avoid cascaded errors on subsequent use, share the
18273 -- discriminants of the partial view.
18275 Set_Discriminant_Specifications
(N
,
18276 Discriminant_Specifications
(Prev_Par
));
18280 -- A prior untagged partial view can have an associated class-wide
18281 -- type due to use of the class attribute, and in this case the full
18282 -- type must also be tagged. This Ada 95 usage is deprecated in favor
18283 -- of incomplete tagged declarations, but we check for it.
18286 and then (Is_Tagged_Type
(Prev
)
18287 or else Present
(Class_Wide_Type
(Prev
)))
18289 -- Ada 2012 (AI05-0162): A private type may be the completion of
18290 -- an incomplete type.
18292 if Ada_Version
>= Ada_2012
18293 and then Is_Incomplete_Type
(Prev
)
18294 and then Nkind
(N
) in N_Private_Type_Declaration
18295 | N_Private_Extension_Declaration
18297 -- No need to check private extensions since they are tagged
18299 if Nkind
(N
) = N_Private_Type_Declaration
18300 and then not Tagged_Present
(N
)
18305 -- The full declaration is either a tagged type (including
18306 -- a synchronized type that implements interfaces) or a
18307 -- type extension, otherwise this is an error.
18309 elsif Nkind
(N
) in N_Task_Type_Declaration
18310 | N_Protected_Type_Declaration
18312 if No
(Interface_List
(N
)) and then not Error_Posted
(N
) then
18316 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
18318 -- Indicate that the previous declaration (tagged incomplete
18319 -- or private declaration) requires the same on the full one.
18321 if not Tagged_Present
(Type_Definition
(N
)) then
18323 Set_Is_Tagged_Type
(Id
);
18326 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
18327 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
18329 ("full declaration of } must be a record extension",
18332 -- Set some attributes to produce a usable full view
18334 Set_Is_Tagged_Type
(Id
);
18343 and then Nkind
(Parent
(Prev
)) = N_Incomplete_Type_Declaration
18344 and then Present
(Premature_Use
(Parent
(Prev
)))
18346 Error_Msg_Sloc
:= Sloc
(N
);
18348 ("\full declaration #", Premature_Use
(Parent
(Prev
)));
18353 end Find_Type_Name
;
18355 -------------------------
18356 -- Find_Type_Of_Object --
18357 -------------------------
18359 function Find_Type_Of_Object
18360 (Obj_Def
: Node_Id
;
18361 Related_Nod
: Node_Id
) return Entity_Id
18363 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
18364 P
: Node_Id
:= Parent
(Obj_Def
);
18369 -- If the parent is a component_definition node we climb to the
18370 -- component_declaration node.
18372 if Nkind
(P
) = N_Component_Definition
then
18376 -- Case of an anonymous array subtype
18378 if Def_Kind
in N_Array_Type_Definition
then
18380 Array_Type_Declaration
(T
, Obj_Def
);
18382 -- Create an explicit subtype whenever possible
18384 elsif Nkind
(P
) /= N_Component_Declaration
18385 and then Def_Kind
= N_Subtype_Indication
18387 -- Base name of subtype on object name, which will be unique in
18388 -- the current scope.
18390 -- If this is a duplicate declaration, return base type, to avoid
18391 -- generating duplicate anonymous types.
18393 if Error_Posted
(P
) then
18394 Analyze
(Subtype_Mark
(Obj_Def
));
18395 return Entity
(Subtype_Mark
(Obj_Def
));
18400 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
18402 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
18404 -- If In_Spec_Expression, for example within a pre/postcondition,
18405 -- provide enough information for use of the subtype without
18406 -- depending on full analysis and freezing, which will happen when
18407 -- building the corresponding subprogram.
18409 if In_Spec_Expression
then
18410 Analyze
(Subtype_Mark
(Obj_Def
));
18413 Base_T
: constant Entity_Id
:= Entity
(Subtype_Mark
(Obj_Def
));
18414 Decl
: constant Node_Id
:=
18415 Make_Subtype_Declaration
(Sloc
(P
),
18416 Defining_Identifier
=> T
,
18417 Subtype_Indication
=> Relocate_Node
(Obj_Def
));
18419 Set_Etype
(T
, Base_T
);
18420 Mutate_Ekind
(T
, Subtype_Kind
(Ekind
(Base_T
)));
18421 Set_Parent
(T
, Obj_Def
);
18422 Set_Scope
(T
, Current_Scope
);
18424 if Ekind
(T
) = E_Array_Subtype
then
18425 Constrain_Array
(T
, Obj_Def
, Related_Nod
, T
, 'P');
18427 elsif Ekind
(T
) = E_Record_Subtype
then
18428 Set_First_Entity
(T
, First_Entity
(Base_T
));
18429 Set_Has_Discriminants
(T
, Has_Discriminants
(Base_T
));
18430 Set_Is_Constrained
(T
);
18433 Insert_Before
(Related_Nod
, Decl
);
18439 -- When generating code, insert subtype declaration ahead of
18440 -- declaration that generated it.
18442 Insert_Action
(Obj_Def
,
18443 Make_Subtype_Declaration
(Sloc
(P
),
18444 Defining_Identifier
=> T
,
18445 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
18447 -- This subtype may need freezing, and this will not be done
18448 -- automatically if the object declaration is not in declarative
18449 -- part. Since this is an object declaration, the type cannot always
18450 -- be frozen here. Deferred constants do not freeze their type
18451 -- (which often enough will be private).
18453 if Nkind
(P
) = N_Object_Declaration
18454 and then Constant_Present
(P
)
18455 and then No
(Expression
(P
))
18459 -- Here we freeze the base type of object type to catch premature use
18460 -- of discriminated private type without a full view.
18463 Insert_Actions
(Obj_Def
, Freeze_Entity
(Base_Type
(T
), P
));
18466 -- Ada 2005 AI-406: the object definition in an object declaration
18467 -- can be an access definition.
18469 elsif Def_Kind
= N_Access_Definition
then
18470 T
:= Access_Definition
(Related_Nod
, Obj_Def
);
18472 Set_Is_Local_Anonymous_Access
18473 (T
, Ada_Version
< Ada_2012
18474 or else Nkind
(P
) /= N_Object_Declaration
18475 or else Is_Library_Level_Entity
(Defining_Identifier
(P
)));
18477 -- Otherwise, the object definition is just a subtype_mark
18480 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
18484 end Find_Type_Of_Object
;
18486 --------------------------------
18487 -- Find_Type_Of_Subtype_Indic --
18488 --------------------------------
18490 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
18494 -- Case of subtype mark with a constraint
18496 if Nkind
(S
) = N_Subtype_Indication
then
18497 Find_Type
(Subtype_Mark
(S
));
18498 Typ
:= Entity
(Subtype_Mark
(S
));
18501 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
18504 ("incorrect constraint for this kind of type", Constraint
(S
));
18505 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
18508 -- Otherwise we have a subtype mark without a constraint
18510 elsif Error_Posted
(S
) then
18511 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
18520 end Find_Type_Of_Subtype_Indic
;
18522 -------------------------------------
18523 -- Floating_Point_Type_Declaration --
18524 -------------------------------------
18526 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
18527 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
18528 Max_Digs_Val
: constant Uint
:= Digits_Value
(Standard_Long_Long_Float
);
18530 Base_Typ
: Entity_Id
;
18531 Implicit_Base
: Entity_Id
;
18533 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
18534 -- Find if given digits value, and possibly a specified range, allows
18535 -- derivation from specified type
18537 procedure Convert_Bound
(B
: Node_Id
);
18538 -- If specified, the bounds must be static but may be of different
18539 -- types. They must be converted into machine numbers of the base type,
18540 -- in accordance with RM 4.9(38).
18542 function Find_Base_Type
return Entity_Id
;
18543 -- Find a predefined base type that Def can derive from, or generate
18544 -- an error and substitute Long_Long_Float if none exists.
18546 ---------------------
18547 -- Can_Derive_From --
18548 ---------------------
18550 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
18551 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
18554 -- Check specified "digits" constraint
18556 if Digs_Val
> Digits_Value
(E
) then
18560 -- Check for matching range, if specified
18562 if Present
(Spec
) then
18563 if Expr_Value_R
(Type_Low_Bound
(E
)) >
18564 Expr_Value_R
(Low_Bound
(Spec
))
18569 if Expr_Value_R
(Type_High_Bound
(E
)) <
18570 Expr_Value_R
(High_Bound
(Spec
))
18577 end Can_Derive_From
;
18579 -------------------
18580 -- Convert_Bound --
18581 --------------------
18583 procedure Convert_Bound
(B
: Node_Id
) is
18585 -- If the bound is not a literal it can only be static if it is
18586 -- a static constant, possibly of a specified type.
18588 if Is_Entity_Name
(B
)
18589 and then Ekind
(Entity
(B
)) = E_Constant
18591 Rewrite
(B
, Constant_Value
(Entity
(B
)));
18594 if Nkind
(B
) = N_Real_Literal
then
18595 Set_Realval
(B
, Machine
(Base_Typ
, Realval
(B
), Round
, B
));
18596 Set_Is_Machine_Number
(B
);
18597 Set_Etype
(B
, Base_Typ
);
18601 --------------------
18602 -- Find_Base_Type --
18603 --------------------
18605 function Find_Base_Type
return Entity_Id
is
18606 Choice
: Elmt_Id
:= First_Elmt
(Predefined_Float_Types
);
18609 -- Iterate over the predefined types in order, returning the first
18610 -- one that Def can derive from.
18612 while Present
(Choice
) loop
18613 if Can_Derive_From
(Node
(Choice
)) then
18614 return Node
(Choice
);
18617 Next_Elmt
(Choice
);
18620 -- If we can't derive from any existing type, use Long_Long_Float
18621 -- and give appropriate message explaining the problem.
18623 if Digs_Val
> Max_Digs_Val
then
18624 -- It might be the case that there is a type with the requested
18625 -- range, just not the combination of digits and range.
18628 ("no predefined type has requested range and precision",
18629 Real_Range_Specification
(Def
));
18633 ("range too large for any predefined type",
18634 Real_Range_Specification
(Def
));
18637 return Standard_Long_Long_Float
;
18638 end Find_Base_Type
;
18640 -- Start of processing for Floating_Point_Type_Declaration
18643 Check_Restriction
(No_Floating_Point
, Def
);
18645 -- Create an implicit base type
18648 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
18650 -- Analyze and verify digits value
18652 Analyze_And_Resolve
(Digs
, Any_Integer
);
18653 Check_Digits_Expression
(Digs
);
18654 Digs_Val
:= Expr_Value
(Digs
);
18656 -- Process possible range spec and find correct type to derive from
18658 Process_Real_Range_Specification
(Def
);
18660 -- Check that requested number of digits is not too high.
18662 if Digs_Val
> Max_Digs_Val
then
18664 -- The check for Max_Base_Digits may be somewhat expensive, as it
18665 -- requires reading System, so only do it when necessary.
18668 Max_Base_Digits
: constant Uint
:=
18671 (Parent
(RTE
(RE_Max_Base_Digits
))));
18674 if Digs_Val
> Max_Base_Digits
then
18675 Error_Msg_Uint_1
:= Max_Base_Digits
;
18676 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
18678 elsif No
(Real_Range_Specification
(Def
)) then
18679 Error_Msg_Uint_1
:= Max_Digs_Val
;
18680 Error_Msg_N
("types with more than ^ digits need range spec "
18681 & "(RM 3.5.7(6))", Digs
);
18686 -- Find a suitable type to derive from or complain and use a substitute
18688 Base_Typ
:= Find_Base_Type
;
18690 -- If there are bounds given in the declaration use them as the bounds
18691 -- of the type, otherwise use the bounds of the predefined base type
18692 -- that was chosen based on the Digits value.
18694 if Present
(Real_Range_Specification
(Def
)) then
18695 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
18696 Set_Is_Constrained
(T
);
18698 Convert_Bound
(Type_Low_Bound
(T
));
18699 Convert_Bound
(Type_High_Bound
(T
));
18702 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
18705 -- Complete definition of implicit base and declared first subtype. The
18706 -- inheritance of the rep item chain ensures that SPARK-related pragmas
18707 -- are not clobbered when the floating point type acts as a full view of
18710 Set_Etype
(Implicit_Base
, Base_Typ
);
18711 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
18712 Set_Size_Info
(Implicit_Base
, Base_Typ
);
18713 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
18714 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
18715 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
18716 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Base_Typ
));
18718 Mutate_Ekind
(T
, E_Floating_Point_Subtype
);
18719 Set_Etype
(T
, Implicit_Base
);
18720 Set_Size_Info
(T
, Implicit_Base
);
18721 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
18722 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
18724 if Digs_Val
>= Uint_1
then
18725 Set_Digits_Value
(T
, Digs_Val
);
18727 pragma Assert
(Serious_Errors_Detected
> 0); null;
18729 end Floating_Point_Type_Declaration
;
18731 ----------------------------
18732 -- Get_Discriminant_Value --
18733 ----------------------------
18735 -- This is the situation:
18737 -- There is a non-derived type
18739 -- type T0 (Dx, Dy, Dz...)
18741 -- There are zero or more levels of derivation, with each derivation
18742 -- either purely inheriting the discriminants, or defining its own.
18744 -- type Ti is new Ti-1
18746 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
18748 -- subtype Ti is ...
18750 -- The subtype issue is avoided by the use of Original_Record_Component,
18751 -- and the fact that derived subtypes also derive the constraints.
18753 -- This chain leads back from
18755 -- Typ_For_Constraint
18757 -- Typ_For_Constraint has discriminants, and the value for each
18758 -- discriminant is given by its corresponding Elmt of Constraints.
18760 -- Discriminant is some discriminant in this hierarchy
18762 -- We need to return its value
18764 -- We do this by recursively searching each level, and looking for
18765 -- Discriminant. Once we get to the bottom, we start backing up
18766 -- returning the value for it which may in turn be a discriminant
18767 -- further up, so on the backup we continue the substitution.
18769 function Get_Discriminant_Value
18770 (Discriminant
: Entity_Id
;
18771 Typ_For_Constraint
: Entity_Id
;
18772 Constraint
: Elist_Id
) return Node_Id
18774 function Root_Corresponding_Discriminant
18775 (Discr
: Entity_Id
) return Entity_Id
;
18776 -- Given a discriminant, traverse the chain of inherited discriminants
18777 -- and return the topmost discriminant.
18779 function Search_Derivation_Levels
18781 Discrim_Values
: Elist_Id
;
18782 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
18783 -- This is the routine that performs the recursive search of levels
18784 -- as described above.
18786 -------------------------------------
18787 -- Root_Corresponding_Discriminant --
18788 -------------------------------------
18790 function Root_Corresponding_Discriminant
18791 (Discr
: Entity_Id
) return Entity_Id
18797 while Present
(Corresponding_Discriminant
(D
)) loop
18798 D
:= Corresponding_Discriminant
(D
);
18802 end Root_Corresponding_Discriminant
;
18804 ------------------------------
18805 -- Search_Derivation_Levels --
18806 ------------------------------
18808 function Search_Derivation_Levels
18810 Discrim_Values
: Elist_Id
;
18811 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
18815 Result
: Node_Or_Entity_Id
;
18816 Result_Entity
: Node_Id
;
18819 -- If inappropriate type, return Error, this happens only in
18820 -- cascaded error situations, and we want to avoid a blow up.
18822 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
18826 -- Look deeper if possible. Use Stored_Constraints only for
18827 -- untagged types. For tagged types use the given constraint.
18828 -- This asymmetry needs explanation???
18830 if not Stored_Discrim_Values
18831 and then Present
(Stored_Constraint
(Ti
))
18832 and then not Is_Tagged_Type
(Ti
)
18835 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
18839 Td
: Entity_Id
:= Etype
(Ti
);
18842 -- If the parent type is private, the full view may include
18843 -- renamed discriminants, and it is those stored values that
18844 -- may be needed (the partial view never has more information
18845 -- than the full view).
18847 if Is_Private_Type
(Td
) and then Present
(Full_View
(Td
)) then
18848 Td
:= Full_View
(Td
);
18852 Result
:= Discriminant
;
18855 if Present
(Stored_Constraint
(Ti
)) then
18857 Search_Derivation_Levels
18858 (Td
, Stored_Constraint
(Ti
), True);
18861 Search_Derivation_Levels
18862 (Td
, Discrim_Values
, Stored_Discrim_Values
);
18868 -- Extra underlying places to search, if not found above. For
18869 -- concurrent types, the relevant discriminant appears in the
18870 -- corresponding record. For a type derived from a private type
18871 -- without discriminant, the full view inherits the discriminants
18872 -- of the full view of the parent.
18874 if Result
= Discriminant
then
18875 if Is_Concurrent_Type
(Ti
)
18876 and then Present
(Corresponding_Record_Type
(Ti
))
18879 Search_Derivation_Levels
(
18880 Corresponding_Record_Type
(Ti
),
18882 Stored_Discrim_Values
);
18884 elsif Is_Private_Type
(Ti
)
18885 and then not Has_Discriminants
(Ti
)
18886 and then Present
(Full_View
(Ti
))
18887 and then Etype
(Full_View
(Ti
)) /= Ti
18890 Search_Derivation_Levels
(
18893 Stored_Discrim_Values
);
18897 -- If Result is not a (reference to a) discriminant, return it,
18898 -- otherwise set Result_Entity to the discriminant.
18900 if Nkind
(Result
) = N_Defining_Identifier
then
18901 pragma Assert
(Result
= Discriminant
);
18902 Result_Entity
:= Result
;
18905 if not Denotes_Discriminant
(Result
) then
18909 Result_Entity
:= Entity
(Result
);
18912 -- See if this level of derivation actually has discriminants because
18913 -- tagged derivations can add them, hence the lower levels need not
18916 if not Has_Discriminants
(Ti
) then
18920 -- Scan Ti's discriminants for Result_Entity, and return its
18921 -- corresponding value, if any.
18923 Result_Entity
:= Original_Record_Component
(Result_Entity
);
18925 Assoc
:= First_Elmt
(Discrim_Values
);
18927 if Stored_Discrim_Values
then
18928 Disc
:= First_Stored_Discriminant
(Ti
);
18930 Disc
:= First_Discriminant
(Ti
);
18933 while Present
(Disc
) loop
18935 -- If no further associations return the discriminant, value will
18936 -- be found on the second pass.
18942 if Original_Record_Component
(Disc
) = Result_Entity
then
18943 return Node
(Assoc
);
18948 if Stored_Discrim_Values
then
18949 Next_Stored_Discriminant
(Disc
);
18951 Next_Discriminant
(Disc
);
18955 -- Could not find it
18958 end Search_Derivation_Levels
;
18962 Result
: Node_Or_Entity_Id
;
18964 -- Start of processing for Get_Discriminant_Value
18967 -- ??? This routine is a gigantic mess and will be deleted. For the
18968 -- time being just test for the trivial case before calling recurse.
18970 -- We are now celebrating the 20th anniversary of this comment!
18972 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
18978 D
:= First_Discriminant
(Typ_For_Constraint
);
18979 E
:= First_Elmt
(Constraint
);
18980 while Present
(D
) loop
18981 if Chars
(D
) = Chars
(Discriminant
) then
18985 Next_Discriminant
(D
);
18991 Result
:= Search_Derivation_Levels
18992 (Typ_For_Constraint
, Constraint
, False);
18994 -- ??? hack to disappear when this routine is gone
18996 if Nkind
(Result
) = N_Defining_Identifier
then
19002 D
:= First_Discriminant
(Typ_For_Constraint
);
19003 E
:= First_Elmt
(Constraint
);
19004 while Present
(D
) loop
19005 if Root_Corresponding_Discriminant
(D
) = Discriminant
then
19009 Next_Discriminant
(D
);
19015 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
19017 end Get_Discriminant_Value
;
19019 --------------------------
19020 -- Has_Range_Constraint --
19021 --------------------------
19023 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
19024 C
: constant Node_Id
:= Constraint
(N
);
19027 if Nkind
(C
) = N_Range_Constraint
then
19030 elsif Nkind
(C
) = N_Digits_Constraint
then
19032 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
19033 or else Present
(Range_Constraint
(C
));
19035 elsif Nkind
(C
) = N_Delta_Constraint
then
19036 return Present
(Range_Constraint
(C
));
19041 end Has_Range_Constraint
;
19043 ------------------------
19044 -- Inherit_Components --
19045 ------------------------
19047 function Inherit_Components
19049 Parent_Base
: Entity_Id
;
19050 Derived_Base
: Entity_Id
;
19051 Is_Tagged
: Boolean;
19052 Inherit_Discr
: Boolean;
19053 Discs
: Elist_Id
) return Elist_Id
19055 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
19057 procedure Inherit_Component
19058 (Old_C
: Entity_Id
;
19059 Plain_Discrim
: Boolean := False;
19060 Stored_Discrim
: Boolean := False);
19061 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
19062 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
19063 -- True, Old_C is a stored discriminant. If they are both false then
19064 -- Old_C is a regular component.
19066 -----------------------
19067 -- Inherit_Component --
19068 -----------------------
19070 procedure Inherit_Component
19071 (Old_C
: Entity_Id
;
19072 Plain_Discrim
: Boolean := False;
19073 Stored_Discrim
: Boolean := False)
19075 procedure Set_Anonymous_Type
(Id
: Entity_Id
);
19076 -- Id denotes the entity of an access discriminant or anonymous
19077 -- access component. Set the type of Id to either the same type of
19078 -- Old_C or create a new one depending on whether the parent and
19079 -- the child types are in the same scope.
19081 ------------------------
19082 -- Set_Anonymous_Type --
19083 ------------------------
19085 procedure Set_Anonymous_Type
(Id
: Entity_Id
) is
19086 Old_Typ
: constant Entity_Id
:= Etype
(Old_C
);
19089 if Scope
(Parent_Base
) = Scope
(Derived_Base
) then
19090 Set_Etype
(Id
, Old_Typ
);
19092 -- The parent and the derived type are in two different scopes.
19093 -- Reuse the type of the original discriminant / component by
19094 -- copying it in order to preserve all attributes.
19098 Typ
: constant Entity_Id
:= New_Copy
(Old_Typ
);
19101 Set_Etype
(Id
, Typ
);
19103 -- Since we do not generate component declarations for
19104 -- inherited components, associate the itype with the
19107 Set_Associated_Node_For_Itype
(Typ
, Parent
(Derived_Base
));
19108 Set_Scope
(Typ
, Derived_Base
);
19111 end Set_Anonymous_Type
;
19113 -- Local variables and constants
19115 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
19117 Corr_Discrim
: Entity_Id
;
19118 Discrim
: Entity_Id
;
19120 -- Start of processing for Inherit_Component
19123 pragma Assert
(not Is_Tagged
or not Stored_Discrim
);
19125 Set_Parent
(New_C
, Parent
(Old_C
));
19127 -- Regular discriminants and components must be inserted in the scope
19128 -- of the Derived_Base. Do it here.
19130 if not Stored_Discrim
then
19131 Enter_Name
(New_C
);
19134 -- For tagged types the Original_Record_Component must point to
19135 -- whatever this field was pointing to in the parent type. This has
19136 -- already been achieved by the call to New_Copy above.
19138 if not Is_Tagged
then
19139 Set_Original_Record_Component
(New_C
, New_C
);
19140 Set_Corresponding_Record_Component
(New_C
, Old_C
);
19143 -- Set the proper type of an access discriminant
19145 if Ekind
(New_C
) = E_Discriminant
19146 and then Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
19148 Set_Anonymous_Type
(New_C
);
19151 -- If we have inherited a component then see if its Etype contains
19152 -- references to Parent_Base discriminants. In this case, replace
19153 -- these references with the constraints given in Discs. We do not
19154 -- do this for the partial view of private types because this is
19155 -- not needed (only the components of the full view will be used
19156 -- for code generation) and cause problem. We also avoid this
19157 -- transformation in some error situations.
19159 if Ekind
(New_C
) = E_Component
then
19161 -- Set the proper type of an anonymous access component
19163 if Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
then
19164 Set_Anonymous_Type
(New_C
);
19166 elsif (Is_Private_Type
(Derived_Base
)
19167 and then not Is_Generic_Type
(Derived_Base
))
19168 or else (Is_Empty_Elmt_List
(Discs
)
19169 and then not Expander_Active
)
19171 Set_Etype
(New_C
, Etype
(Old_C
));
19174 -- The current component introduces a circularity of the
19177 -- limited with Pack_2;
19178 -- package Pack_1 is
19179 -- type T_1 is tagged record
19180 -- Comp : access Pack_2.T_2;
19186 -- package Pack_2 is
19187 -- type T_2 is new Pack_1.T_1 with ...;
19192 Constrain_Component_Type
19193 (Old_C
, Derived_Base
, N
, Parent_Base
, Discs
));
19197 -- In derived tagged types it is illegal to reference a non
19198 -- discriminant component in the parent type. To catch this, mark
19199 -- these components with an Ekind of E_Void. This will be reset in
19200 -- Record_Type_Definition after processing the record extension of
19201 -- the derived type.
19203 -- If the declaration is a private extension, there is no further
19204 -- record extension to process, and the components retain their
19205 -- current kind, because they are visible at this point.
19207 if Is_Tagged
and then Ekind
(New_C
) = E_Component
19208 and then Nkind
(N
) /= N_Private_Extension_Declaration
19210 Mutate_Ekind
(New_C
, E_Void
);
19213 if Plain_Discrim
then
19214 Set_Corresponding_Discriminant
(New_C
, Old_C
);
19215 Build_Discriminal
(New_C
);
19217 -- If we are explicitly inheriting a stored discriminant it will be
19218 -- completely hidden.
19220 elsif Stored_Discrim
then
19221 Set_Corresponding_Discriminant
(New_C
, Empty
);
19222 Set_Discriminal
(New_C
, Empty
);
19223 Set_Is_Completely_Hidden
(New_C
);
19225 -- Set the Original_Record_Component of each discriminant in the
19226 -- derived base to point to the corresponding stored that we just
19229 Discrim
:= First_Discriminant
(Derived_Base
);
19230 while Present
(Discrim
) loop
19231 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
19233 -- Corr_Discrim could be missing in an error situation
19235 if Present
(Corr_Discrim
)
19236 and then Original_Record_Component
(Corr_Discrim
) = Old_C
19238 Set_Original_Record_Component
(Discrim
, New_C
);
19239 Set_Corresponding_Record_Component
(Discrim
, Empty
);
19242 Next_Discriminant
(Discrim
);
19245 Append_Entity
(New_C
, Derived_Base
);
19248 if not Is_Tagged
then
19249 Append_Elmt
(Old_C
, Assoc_List
);
19250 Append_Elmt
(New_C
, Assoc_List
);
19252 end Inherit_Component
;
19254 -- Variables local to Inherit_Component
19256 Loc
: constant Source_Ptr
:= Sloc
(N
);
19258 Parent_Discrim
: Entity_Id
;
19259 Stored_Discrim
: Entity_Id
;
19261 Component
: Entity_Id
;
19263 -- Start of processing for Inherit_Components
19266 if not Is_Tagged
then
19267 Append_Elmt
(Parent_Base
, Assoc_List
);
19268 Append_Elmt
(Derived_Base
, Assoc_List
);
19271 -- Inherit parent discriminants if needed
19273 if Inherit_Discr
then
19274 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
19275 while Present
(Parent_Discrim
) loop
19276 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
19277 Next_Discriminant
(Parent_Discrim
);
19281 -- Create explicit stored discrims for untagged types when necessary
19283 if not Has_Unknown_Discriminants
(Derived_Base
)
19284 and then Has_Discriminants
(Parent_Base
)
19285 and then not Is_Tagged
19288 or else First_Discriminant
(Parent_Base
) /=
19289 First_Stored_Discriminant
(Parent_Base
))
19291 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
19292 while Present
(Stored_Discrim
) loop
19293 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
19294 Next_Stored_Discriminant
(Stored_Discrim
);
19298 -- See if we can apply the second transformation for derived types, as
19299 -- explained in point 6. in the comments above Build_Derived_Record_Type
19300 -- This is achieved by appending Derived_Base discriminants into Discs,
19301 -- which has the side effect of returning a non empty Discs list to the
19302 -- caller of Inherit_Components, which is what we want. This must be
19303 -- done for private derived types if there are explicit stored
19304 -- discriminants, to ensure that we can retrieve the values of the
19305 -- constraints provided in the ancestors.
19308 and then Is_Empty_Elmt_List
(Discs
)
19309 and then Present
(First_Discriminant
(Derived_Base
))
19311 (not Is_Private_Type
(Derived_Base
)
19312 or else Is_Completely_Hidden
19313 (First_Stored_Discriminant
(Derived_Base
))
19314 or else Is_Generic_Type
(Derived_Base
))
19316 D
:= First_Discriminant
(Derived_Base
);
19317 while Present
(D
) loop
19318 Append_Elmt
(New_Occurrence_Of
(D
, Loc
), Discs
);
19319 Next_Discriminant
(D
);
19323 -- Finally, inherit non-discriminant components unless they are not
19324 -- visible because defined or inherited from the full view of the
19325 -- parent. Don't inherit the _parent field of the parent type.
19327 Component
:= First_Entity
(Parent_Base
);
19328 while Present
(Component
) loop
19330 -- Ada 2005 (AI-251): Do not inherit components associated with
19331 -- secondary tags of the parent.
19333 if Ekind
(Component
) = E_Component
19334 and then Present
(Related_Type
(Component
))
19338 elsif Ekind
(Component
) /= E_Component
19339 or else Chars
(Component
) = Name_uParent
19343 -- If the derived type is within the parent type's declarative
19344 -- region, then the components can still be inherited even though
19345 -- they aren't visible at this point. This can occur for cases
19346 -- such as within public child units where the components must
19347 -- become visible upon entering the child unit's private part.
19349 elsif not Is_Visible_Component
(Component
)
19350 and then not In_Open_Scopes
(Scope
(Parent_Base
))
19354 elsif Ekind
(Derived_Base
) in E_Private_Type | E_Limited_Private_Type
19359 Inherit_Component
(Component
);
19362 Next_Entity
(Component
);
19365 -- For tagged derived types, inherited discriminants cannot be used in
19366 -- component declarations of the record extension part. To achieve this
19367 -- we mark the inherited discriminants as not visible.
19369 if Is_Tagged
and then Inherit_Discr
then
19370 D
:= First_Discriminant
(Derived_Base
);
19371 while Present
(D
) loop
19372 Set_Is_Immediately_Visible
(D
, False);
19373 Next_Discriminant
(D
);
19378 end Inherit_Components
;
19380 ----------------------
19381 -- Is_EVF_Procedure --
19382 ----------------------
19384 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean is
19385 Formal
: Entity_Id
;
19388 -- Examine the formals of an Extensions_Visible False procedure looking
19389 -- for a controlling OUT parameter.
19391 if Ekind
(Subp
) = E_Procedure
19392 and then Extensions_Visible_Status
(Subp
) = Extensions_Visible_False
19394 Formal
:= First_Formal
(Subp
);
19395 while Present
(Formal
) loop
19396 if Ekind
(Formal
) = E_Out_Parameter
19397 and then Is_Controlling_Formal
(Formal
)
19402 Next_Formal
(Formal
);
19407 end Is_EVF_Procedure
;
19409 --------------------------
19410 -- Is_Private_Primitive --
19411 --------------------------
19413 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean is
19414 Prim_Scope
: constant Entity_Id
:= Scope
(Prim
);
19415 Priv_Entity
: Entity_Id
;
19417 if Is_Package_Or_Generic_Package
(Prim_Scope
) then
19418 Priv_Entity
:= First_Private_Entity
(Prim_Scope
);
19420 while Present
(Priv_Entity
) loop
19421 if Priv_Entity
= Prim
then
19425 Next_Entity
(Priv_Entity
);
19430 end Is_Private_Primitive
;
19432 ------------------------------
19433 -- Is_Valid_Constraint_Kind --
19434 ------------------------------
19436 function Is_Valid_Constraint_Kind
19437 (T_Kind
: Type_Kind
;
19438 Constraint_Kind
: Node_Kind
) return Boolean
19442 when Enumeration_Kind
19445 return Constraint_Kind
= N_Range_Constraint
;
19447 when Decimal_Fixed_Point_Kind
=>
19448 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19450 when Ordinary_Fixed_Point_Kind
=>
19451 return Constraint_Kind
in N_Delta_Constraint | N_Range_Constraint
;
19454 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19461 | E_Incomplete_Type
19465 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
19468 return True; -- Error will be detected later
19470 end Is_Valid_Constraint_Kind
;
19472 --------------------------
19473 -- Is_Visible_Component --
19474 --------------------------
19476 function Is_Visible_Component
19478 N
: Node_Id
:= Empty
) return Boolean
19480 Original_Comp
: Entity_Id
:= Empty
;
19481 Original_Type
: Entity_Id
;
19482 Type_Scope
: Entity_Id
;
19484 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
19485 -- Check whether parent type of inherited component is declared locally,
19486 -- possibly within a nested package or instance. The current scope is
19487 -- the derived record itself.
19489 -------------------
19490 -- Is_Local_Type --
19491 -------------------
19493 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
19495 return Scope_Within
(Inner
=> Typ
, Outer
=> Scope
(Current_Scope
));
19498 -- Start of processing for Is_Visible_Component
19501 if Ekind
(C
) in E_Component | E_Discriminant
then
19502 Original_Comp
:= Original_Record_Component
(C
);
19505 if No
(Original_Comp
) then
19507 -- Premature usage, or previous error
19512 Original_Type
:= Scope
(Original_Comp
);
19513 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
19516 -- This test only concerns tagged types
19518 if not Is_Tagged_Type
(Original_Type
) then
19520 -- Check if this is a renamed discriminant (hidden either by the
19521 -- derived type or by some ancestor), unless we are analyzing code
19522 -- generated by the expander since it may reference such components
19523 -- (for example see the expansion of Deep_Adjust).
19525 if Ekind
(C
) = E_Discriminant
and then Present
(N
) then
19527 not Comes_From_Source
(N
)
19528 or else not Is_Completely_Hidden
(C
);
19533 -- If it is _Parent or _Tag, there is no visibility issue
19535 elsif not Comes_From_Source
(Original_Comp
) then
19538 -- Discriminants are visible unless the (private) type has unknown
19539 -- discriminants. If the discriminant reference is inserted for a
19540 -- discriminant check on a full view it is also visible.
19542 elsif Ekind
(Original_Comp
) = E_Discriminant
19544 (not Has_Unknown_Discriminants
(Original_Type
)
19545 or else (Present
(N
)
19546 and then Nkind
(N
) = N_Selected_Component
19547 and then Nkind
(Prefix
(N
)) = N_Type_Conversion
19548 and then not Comes_From_Source
(Prefix
(N
))))
19552 -- If the component has been declared in an ancestor which is currently
19553 -- a private type, then it is not visible. The same applies if the
19554 -- component's containing type is not in an open scope and the original
19555 -- component's enclosing type is a visible full view of a private type
19556 -- (which can occur in cases where an attempt is being made to reference
19557 -- a component in a sibling package that is inherited from a visible
19558 -- component of a type in an ancestor package; the component in the
19559 -- sibling package should not be visible even though the component it
19560 -- inherited from is visible), but instance bodies are not subject to
19561 -- this second case since they have the Has_Private_View mechanism to
19562 -- ensure proper visibility. This does not apply however in the case
19563 -- where the scope of the type is a private child unit, or when the
19564 -- parent comes from a local package in which the ancestor is currently
19565 -- visible. The latter suppression of visibility is needed for cases
19566 -- that are tested in B730006.
19568 elsif Is_Private_Type
(Original_Type
)
19570 (not Is_Private_Descendant
(Type_Scope
)
19571 and then not In_Open_Scopes
(Type_Scope
)
19572 and then Has_Private_Declaration
(Original_Type
)
19573 and then not In_Instance_Body
)
19575 -- If the type derives from an entity in a formal package, there
19576 -- are no additional visible components.
19578 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
19579 N_Formal_Package_Declaration
19583 -- if we are not in the private part of the current package, there
19584 -- are no additional visible components.
19586 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
19587 and then not In_Private_Part
(Scope
(Current_Scope
))
19592 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
19593 and then In_Open_Scopes
(Scope
(Original_Type
))
19594 and then Is_Local_Type
(Type_Scope
);
19597 -- There is another weird way in which a component may be invisible when
19598 -- the private and the full view are not derived from the same ancestor.
19599 -- Here is an example :
19601 -- type A1 is tagged record F1 : integer; end record;
19602 -- type A2 is new A1 with record F2 : integer; end record;
19603 -- type T is new A1 with private;
19605 -- type T is new A2 with null record;
19607 -- In this case, the full view of T inherits F1 and F2 but the private
19608 -- view inherits only F1
19612 Ancestor
: Entity_Id
:= Scope
(C
);
19616 if Ancestor
= Original_Type
then
19619 -- The ancestor may have a partial view of the original type,
19620 -- but if the full view is in scope, as in a child body, the
19621 -- component is visible.
19623 elsif In_Private_Part
(Scope
(Original_Type
))
19624 and then Full_View
(Ancestor
) = Original_Type
19628 elsif Ancestor
= Etype
(Ancestor
) then
19630 -- No further ancestors to examine
19635 Ancestor
:= Etype
(Ancestor
);
19639 end Is_Visible_Component
;
19641 --------------------------
19642 -- Make_Class_Wide_Type --
19643 --------------------------
19645 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
19646 CW_Type
: Entity_Id
;
19648 Next_E
: Entity_Id
;
19649 Prev_E
: Entity_Id
;
19652 if Present
(Class_Wide_Type
(T
)) then
19654 -- The class-wide type is a partially decorated entity created for a
19655 -- unanalyzed tagged type referenced through a limited with clause.
19656 -- When the tagged type is analyzed, its class-wide type needs to be
19657 -- redecorated. Note that we reuse the entity created by Decorate_
19658 -- Tagged_Type in order to preserve all links.
19660 if Materialize_Entity
(Class_Wide_Type
(T
)) then
19661 CW_Type
:= Class_Wide_Type
(T
);
19662 Set_Materialize_Entity
(CW_Type
, False);
19664 -- The class wide type can have been defined by the partial view, in
19665 -- which case everything is already done.
19671 -- Default case, we need to create a new class-wide type
19675 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
19678 -- Inherit root type characteristics
19680 CW_Name
:= Chars
(CW_Type
);
19681 Next_E
:= Next_Entity
(CW_Type
);
19682 Prev_E
:= Prev_Entity
(CW_Type
);
19683 Copy_Node
(T
, CW_Type
);
19684 Set_Comes_From_Source
(CW_Type
, False);
19685 Set_Chars
(CW_Type
, CW_Name
);
19686 Set_Parent
(CW_Type
, Parent
(T
));
19687 Set_Prev_Entity
(CW_Type
, Prev_E
);
19688 Set_Next_Entity
(CW_Type
, Next_E
);
19690 -- Ensure we have a new freeze node for the class-wide type. The partial
19691 -- view may have freeze action of its own, requiring a proper freeze
19692 -- node, and the same freeze node cannot be shared between the two
19695 Set_Has_Delayed_Freeze
(CW_Type
);
19696 Set_Freeze_Node
(CW_Type
, Empty
);
19698 -- Customize the class-wide type: It has no prim. op., it cannot be
19699 -- abstract, its Etype points back to the specific root type, and it
19700 -- cannot have any invariants.
19702 if Ekind
(CW_Type
) in Incomplete_Or_Private_Kind
then
19703 Reinit_Field_To_Zero
(CW_Type
, F_Private_Dependents
);
19705 elsif Ekind
(CW_Type
) in Concurrent_Kind
then
19706 Reinit_Field_To_Zero
(CW_Type
, F_First_Private_Entity
);
19707 Reinit_Field_To_Zero
(CW_Type
, F_Scope_Depth_Value
);
19709 if Ekind
(CW_Type
) in Task_Kind
then
19710 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Checks_OK_Id
);
19711 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Warnings_OK_Id
);
19714 if Ekind
(CW_Type
) in E_Task_Type | E_Protected_Type
then
19715 Reinit_Field_To_Zero
(CW_Type
, F_SPARK_Aux_Pragma_Inherited
);
19718 elsif Ekind
(CW_Type
) = E_Record_Type
then
19719 Reinit_Field_To_Zero
(CW_Type
, F_Corresponding_Concurrent_Type
);
19722 Mutate_Ekind
(CW_Type
, E_Class_Wide_Type
);
19723 Set_Is_Tagged_Type
(CW_Type
, True);
19724 Set_Direct_Primitive_Operations
(CW_Type
, New_Elmt_List
);
19725 Set_Is_Abstract_Type
(CW_Type
, False);
19726 Set_Is_Constrained
(CW_Type
, False);
19727 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
19728 Set_Default_SSO
(CW_Type
);
19729 Set_Has_Inheritable_Invariants
(CW_Type
, False);
19730 Set_Has_Inherited_Invariants
(CW_Type
, False);
19731 Set_Has_Own_Invariants
(CW_Type
, False);
19733 if Ekind
(T
) = E_Class_Wide_Subtype
then
19734 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
19736 Set_Etype
(CW_Type
, T
);
19739 Set_No_Tagged_Streams_Pragma
(CW_Type
, No_Tagged_Streams
);
19741 -- If this is the class_wide type of a constrained subtype, it does
19742 -- not have discriminants.
19744 Set_Has_Discriminants
(CW_Type
,
19745 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
19747 Set_Has_Unknown_Discriminants
(CW_Type
, True);
19748 Set_Class_Wide_Type
(T
, CW_Type
);
19749 Set_Equivalent_Type
(CW_Type
, Empty
);
19751 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
19753 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
19754 end Make_Class_Wide_Type
;
19760 procedure Make_Index
19762 Related_Nod
: Node_Id
;
19763 Related_Id
: Entity_Id
:= Empty
;
19764 Suffix_Index
: Pos
:= 1)
19768 Def_Id
: Entity_Id
:= Empty
;
19769 Found
: Boolean := False;
19772 -- For a discrete range used in a constrained array definition and
19773 -- defined by a range, an implicit conversion to the predefined type
19774 -- INTEGER is assumed if each bound is either a numeric literal, a named
19775 -- number, or an attribute, and the type of both bounds (prior to the
19776 -- implicit conversion) is the type universal_integer. Otherwise, both
19777 -- bounds must be of the same discrete type, other than universal
19778 -- integer; this type must be determinable independently of the
19779 -- context, but using the fact that the type must be discrete and that
19780 -- both bounds must have the same type.
19782 -- Character literals also have a universal type in the absence of
19783 -- of additional context, and are resolved to Standard_Character.
19785 if Nkind
(N
) = N_Range
then
19787 -- The index is given by a range constraint. The bounds are known
19788 -- to be of a consistent type.
19790 if not Is_Overloaded
(N
) then
19793 -- For universal bounds, choose the specific predefined type
19795 if T
= Universal_Integer
then
19796 T
:= Standard_Integer
;
19798 elsif T
= Any_Character
then
19799 Ambiguous_Character
(Low_Bound
(N
));
19801 T
:= Standard_Character
;
19804 -- The node may be overloaded because some user-defined operators
19805 -- are available, but if a universal interpretation exists it is
19806 -- also the selected one.
19808 elsif Universal_Interpretation
(N
) = Universal_Integer
then
19809 T
:= Standard_Integer
;
19815 Ind
: Interp_Index
;
19819 Get_First_Interp
(N
, Ind
, It
);
19820 while Present
(It
.Typ
) loop
19821 if Is_Discrete_Type
(It
.Typ
) then
19824 and then not Covers
(It
.Typ
, T
)
19825 and then not Covers
(T
, It
.Typ
)
19827 Error_Msg_N
("ambiguous bounds in discrete range", N
);
19835 Get_Next_Interp
(Ind
, It
);
19838 if T
= Any_Type
then
19839 Error_Msg_N
("discrete type required for range", N
);
19840 Set_Etype
(N
, Any_Type
);
19843 elsif T
= Universal_Integer
then
19844 T
:= Standard_Integer
;
19849 if not Is_Discrete_Type
(T
) then
19850 Error_Msg_N
("discrete type required for range", N
);
19851 Set_Etype
(N
, Any_Type
);
19855 -- If the range bounds are "T'First .. T'Last" where T is a name of a
19856 -- discrete type, then use T as the type of the index.
19858 if Nkind
(Low_Bound
(N
)) = N_Attribute_Reference
19859 and then Attribute_Name
(Low_Bound
(N
)) = Name_First
19860 and then Is_Entity_Name
(Prefix
(Low_Bound
(N
)))
19861 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(N
))))
19863 and then Nkind
(High_Bound
(N
)) = N_Attribute_Reference
19864 and then Attribute_Name
(High_Bound
(N
)) = Name_Last
19865 and then Is_Entity_Name
(Prefix
(High_Bound
(N
)))
19866 and then Entity
(Prefix
(High_Bound
(N
))) = Def_Id
19868 Def_Id
:= Entity
(Prefix
(Low_Bound
(N
)));
19872 Process_Range_Expr_In_Decl
(R
, T
);
19874 elsif Nkind
(N
) = N_Subtype_Indication
then
19876 -- The index is given by a subtype with a range constraint
19878 T
:= Base_Type
(Entity
(Subtype_Mark
(N
)));
19880 if not Is_Discrete_Type
(T
) then
19881 Error_Msg_N
("discrete type required for range", N
);
19882 Set_Etype
(N
, Any_Type
);
19886 R
:= Range_Expression
(Constraint
(N
));
19889 Process_Range_Expr_In_Decl
(R
, Entity
(Subtype_Mark
(N
)));
19891 elsif Nkind
(N
) = N_Attribute_Reference
then
19893 -- Catch beginner's error (use of attribute other than 'Range)
19895 if Attribute_Name
(N
) /= Name_Range
then
19896 Error_Msg_N
("expect attribute ''Range", N
);
19897 Set_Etype
(N
, Any_Type
);
19901 -- If the node denotes the range of a type mark, that is also the
19902 -- resulting type, and we do not need to create an Itype for it.
19904 if Is_Entity_Name
(Prefix
(N
))
19905 and then Comes_From_Source
(N
)
19906 and then Is_Discrete_Type
(Entity
(Prefix
(N
)))
19908 Def_Id
:= Entity
(Prefix
(N
));
19911 Analyze_And_Resolve
(N
);
19915 -- If none of the above, must be a subtype. We convert this to a
19916 -- range attribute reference because in the case of declared first
19917 -- named subtypes, the types in the range reference can be different
19918 -- from the type of the entity. A range attribute normalizes the
19919 -- reference and obtains the correct types for the bounds.
19921 -- This transformation is in the nature of an expansion, is only
19922 -- done if expansion is active. In particular, it is not done on
19923 -- formal generic types, because we need to retain the name of the
19924 -- original index for instantiation purposes.
19927 if not Is_Entity_Name
(N
) or else not Is_Type
(Entity
(N
)) then
19928 Error_Msg_N
("invalid subtype mark in discrete range", N
);
19929 Set_Etype
(N
, Any_Integer
);
19933 -- The type mark may be that of an incomplete type. It is only
19934 -- now that we can get the full view, previous analysis does
19935 -- not look specifically for a type mark.
19937 Set_Entity
(N
, Get_Full_View
(Entity
(N
)));
19938 Set_Etype
(N
, Entity
(N
));
19939 Def_Id
:= Entity
(N
);
19941 if not Is_Discrete_Type
(Def_Id
) then
19942 Error_Msg_N
("discrete type required for index", N
);
19943 Set_Etype
(N
, Any_Type
);
19948 if Expander_Active
then
19950 Make_Attribute_Reference
(Sloc
(N
),
19951 Attribute_Name
=> Name_Range
,
19952 Prefix
=> Relocate_Node
(N
)));
19954 -- The original was a subtype mark that does not freeze. This
19955 -- means that the rewritten version must not freeze either.
19957 Set_Must_Not_Freeze
(N
);
19958 Set_Must_Not_Freeze
(Prefix
(N
));
19959 Analyze_And_Resolve
(N
);
19963 -- If expander is inactive, type is legal, nothing else to construct
19970 if not Is_Discrete_Type
(T
) then
19971 Error_Msg_N
("discrete type required for range", N
);
19972 Set_Etype
(N
, Any_Type
);
19975 elsif T
= Any_Type
then
19976 Set_Etype
(N
, Any_Type
);
19980 -- We will now create the appropriate Itype to describe the range, but
19981 -- first a check. If we originally had a subtype, then we just label
19982 -- the range with this subtype. Not only is there no need to construct
19983 -- a new subtype, but it is wrong to do so for two reasons:
19985 -- 1. A legality concern, if we have a subtype, it must not freeze,
19986 -- and the Itype would cause freezing incorrectly
19988 -- 2. An efficiency concern, if we created an Itype, it would not be
19989 -- recognized as the same type for the purposes of eliminating
19990 -- checks in some circumstances.
19992 -- We signal this case by setting the subtype entity in Def_Id
19994 if No
(Def_Id
) then
19996 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
19997 Set_Etype
(Def_Id
, Base_Type
(T
));
19999 if Is_Signed_Integer_Type
(T
) then
20000 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
20002 elsif Is_Modular_Integer_Type
(T
) then
20003 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
20006 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
20007 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
20008 Set_First_Literal
(Def_Id
, First_Literal
(T
));
20011 Set_Size_Info
(Def_Id
, (T
));
20012 Set_RM_Size
(Def_Id
, RM_Size
(T
));
20013 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
20015 Set_Scalar_Range
(Def_Id
, R
);
20016 Conditional_Delay
(Def_Id
, T
);
20018 -- In the subtype indication case inherit properties of the parent
20020 if Nkind
(N
) = N_Subtype_Indication
then
20022 -- It is enough to inherit predicate flags and not the predicate
20023 -- functions, because predicates on an index type are illegal
20024 -- anyway and the flags are enough to detect them.
20026 Inherit_Predicate_Flags
(Def_Id
, Entity
(Subtype_Mark
(N
)));
20028 -- If the immediate parent of the new subtype is nonstatic, then
20029 -- the subtype we create is nonstatic as well, even if its bounds
20032 if not Is_OK_Static_Subtype
(Entity
(Subtype_Mark
(N
))) then
20033 Set_Is_Non_Static_Subtype
(Def_Id
);
20037 Set_Parent
(Def_Id
, N
);
20040 -- Final step is to label the index with this constructed type
20042 Set_Etype
(N
, Def_Id
);
20045 ------------------------------
20046 -- Modular_Type_Declaration --
20047 ------------------------------
20049 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
20050 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
20053 procedure Set_Modular_Size
(Bits
: Int
);
20054 -- Sets RM_Size to Bits, and Esize to normal word size above this
20056 ----------------------
20057 -- Set_Modular_Size --
20058 ----------------------
20060 procedure Set_Modular_Size
(Bits
: Int
) is
20064 Set_RM_Size
(T
, UI_From_Int
(Bits
));
20066 if Bits
< System_Max_Binary_Modulus_Power
then
20069 while Siz
< 128 loop
20070 exit when Bits
<= Siz
;
20074 Set_Esize
(T
, UI_From_Int
(Siz
));
20077 Set_Esize
(T
, UI_From_Int
(System_Max_Binary_Modulus_Power
));
20080 if not Non_Binary_Modulus
(T
) and then Esize
(T
) = RM_Size
(T
) then
20081 Set_Is_Known_Valid
(T
);
20083 end Set_Modular_Size
;
20085 -- Start of processing for Modular_Type_Declaration
20088 -- If the mod expression is (exactly) 2 * literal, where literal is
20089 -- 128 or less, then almost certainly the * was meant to be **. Warn.
20091 if Warn_On_Suspicious_Modulus_Value
20092 and then Nkind
(Mod_Expr
) = N_Op_Multiply
20093 and then Nkind
(Left_Opnd
(Mod_Expr
)) = N_Integer_Literal
20094 and then Intval
(Left_Opnd
(Mod_Expr
)) = Uint_2
20095 and then Nkind
(Right_Opnd
(Mod_Expr
)) = N_Integer_Literal
20096 and then Intval
(Right_Opnd
(Mod_Expr
)) <= Uint_128
20099 ("suspicious MOD value, was '*'* intended'??.m?", Mod_Expr
);
20102 -- Proceed with analysis of mod expression
20104 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
20107 Mutate_Ekind
(T
, E_Modular_Integer_Type
);
20108 Reinit_Alignment
(T
);
20109 Set_Is_Constrained
(T
);
20111 if not Is_OK_Static_Expression
(Mod_Expr
) then
20112 Flag_Non_Static_Expr
20113 ("non-static expression used for modular type bound!", Mod_Expr
);
20114 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
20116 M_Val
:= Expr_Value
(Mod_Expr
);
20120 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
20121 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
20124 if M_Val
> 2 ** Standard_Long_Integer_Size
then
20125 Check_Restriction
(No_Long_Long_Integers
, Mod_Expr
);
20128 Set_Modulus
(T
, M_Val
);
20130 -- Create bounds for the modular type based on the modulus given in
20131 -- the type declaration and then analyze and resolve those bounds.
20133 Set_Scalar_Range
(T
,
20134 Make_Range
(Sloc
(Mod_Expr
),
20135 Low_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
20136 High_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
20138 -- Properly analyze the literals for the range. We do this manually
20139 -- because we can't go calling Resolve, since we are resolving these
20140 -- bounds with the type, and this type is certainly not complete yet.
20142 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
20143 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
20144 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
20145 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
20147 -- Loop through powers of two to find number of bits required
20149 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
20153 if M_Val
= 2 ** Bits
then
20154 Set_Modular_Size
(Bits
);
20159 elsif M_Val
< 2 ** Bits
then
20160 Set_Non_Binary_Modulus
(T
);
20162 if Bits
> System_Max_Nonbinary_Modulus_Power
then
20163 Error_Msg_Uint_1
:=
20164 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
20166 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
20167 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20171 -- In the nonbinary case, set size as per RM 13.3(55)
20173 Set_Modular_Size
(Bits
);
20180 -- If we fall through, then the size exceed System.Max_Binary_Modulus
20181 -- so we just signal an error and set the maximum size.
20183 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
20184 Error_Msg_F
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
20186 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20187 Reinit_Alignment
(T
);
20189 end Modular_Type_Declaration
;
20191 --------------------------
20192 -- New_Concatenation_Op --
20193 --------------------------
20195 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
20196 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
20199 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
20200 -- Create abbreviated declaration for the formal of a predefined
20201 -- Operator 'Op' of type 'Typ'
20203 --------------------
20204 -- Make_Op_Formal --
20205 --------------------
20207 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
20208 Formal
: Entity_Id
;
20210 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
20211 Set_Etype
(Formal
, Typ
);
20212 Set_Mechanism
(Formal
, Default_Mechanism
);
20214 end Make_Op_Formal
;
20216 -- Start of processing for New_Concatenation_Op
20219 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
20221 Mutate_Ekind
(Op
, E_Operator
);
20222 Set_Scope
(Op
, Current_Scope
);
20223 Set_Etype
(Op
, Typ
);
20224 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
20225 Set_Is_Immediately_Visible
(Op
);
20226 Set_Is_Intrinsic_Subprogram
(Op
);
20227 Set_Has_Completion
(Op
);
20228 Append_Entity
(Op
, Current_Scope
);
20230 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
20232 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20233 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20234 end New_Concatenation_Op
;
20236 -------------------------
20237 -- OK_For_Limited_Init --
20238 -------------------------
20240 -- ???Check all calls of this, and compare the conditions under which it's
20243 function OK_For_Limited_Init
20245 Exp
: Node_Id
) return Boolean
20248 return Is_CPP_Constructor_Call
(Exp
)
20249 or else (Ada_Version
>= Ada_2005
20250 and then not Debug_Flag_Dot_L
20251 and then OK_For_Limited_Init_In_05
(Typ
, Exp
));
20252 end OK_For_Limited_Init
;
20254 -------------------------------
20255 -- OK_For_Limited_Init_In_05 --
20256 -------------------------------
20258 function OK_For_Limited_Init_In_05
20260 Exp
: Node_Id
) return Boolean
20263 -- An object of a limited interface type can be initialized with any
20264 -- expression of a nonlimited descendant type. However this does not
20265 -- apply if this is a view conversion of some other expression. This
20266 -- is checked below.
20268 if Is_Class_Wide_Type
(Typ
)
20269 and then Is_Limited_Interface
(Typ
)
20270 and then not Is_Limited_Type
(Etype
(Exp
))
20271 and then Nkind
(Exp
) /= N_Type_Conversion
20276 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
20277 -- case of limited aggregates (including extension aggregates), and
20278 -- function calls. The function call may have been given in prefixed
20279 -- notation, in which case the original node is an indexed component.
20280 -- If the function is parameterless, the original node was an explicit
20281 -- dereference. The function may also be parameterless, in which case
20282 -- the source node is just an identifier.
20284 -- A branch of a conditional expression may have been removed if the
20285 -- condition is statically known. This happens during expansion, and
20286 -- thus will not happen if previous errors were encountered. The check
20287 -- will have been performed on the chosen branch, which replaces the
20288 -- original conditional expression.
20294 case Nkind
(Original_Node
(Exp
)) is
20296 | N_Delta_Aggregate
20297 | N_Extension_Aggregate
20303 when N_Identifier
=>
20304 return Present
(Entity
(Original_Node
(Exp
)))
20305 and then Ekind
(Entity
(Original_Node
(Exp
))) = E_Function
;
20307 when N_Qualified_Expression
=>
20309 OK_For_Limited_Init_In_05
20310 (Typ
, Expression
(Original_Node
(Exp
)));
20312 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
20313 -- with a function call, the expander has rewritten the call into an
20314 -- N_Type_Conversion node to force displacement of the pointer to
20315 -- reference the component containing the secondary dispatch table.
20316 -- Otherwise a type conversion is not a legal context.
20317 -- A return statement for a build-in-place function returning a
20318 -- synchronized type also introduces an unchecked conversion.
20320 when N_Type_Conversion
20321 | N_Unchecked_Type_Conversion
20323 return not Comes_From_Source
(Exp
)
20325 -- If the conversion has been rewritten, check Original_Node;
20326 -- otherwise, check the expression of the compiler-generated
20327 -- conversion (which is a conversion that we want to ignore
20328 -- for purposes of the limited-initialization restrictions).
20330 (if Is_Rewrite_Substitution
(Exp
)
20331 then OK_For_Limited_Init_In_05
(Typ
, Original_Node
(Exp
))
20332 else OK_For_Limited_Init_In_05
(Typ
, Expression
(Exp
)));
20334 when N_Explicit_Dereference
20335 | N_Indexed_Component
20336 | N_Selected_Component
20338 return Nkind
(Exp
) = N_Function_Call
;
20340 -- A use of 'Input is a function call, hence allowed. Normally the
20341 -- attribute will be changed to a call, but the attribute by itself
20342 -- can occur with -gnatc.
20344 when N_Attribute_Reference
=>
20345 return Attribute_Name
(Original_Node
(Exp
)) = Name_Input
;
20347 -- "return raise ..." is OK
20349 when N_Raise_Expression
=>
20352 -- For a case expression, all dependent expressions must be legal
20354 when N_Case_Expression
=>
20359 Alt
:= First
(Alternatives
(Original_Node
(Exp
)));
20360 while Present
(Alt
) loop
20361 if not OK_For_Limited_Init_In_05
(Typ
, Expression
(Alt
)) then
20371 -- For an if expression, all dependent expressions must be legal
20373 when N_If_Expression
=>
20375 Then_Expr
: constant Node_Id
:=
20376 Next
(First
(Expressions
(Original_Node
(Exp
))));
20377 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
20379 return OK_For_Limited_Init_In_05
(Typ
, Then_Expr
)
20381 OK_For_Limited_Init_In_05
(Typ
, Else_Expr
);
20387 end OK_For_Limited_Init_In_05
;
20389 -------------------------------------------
20390 -- Ordinary_Fixed_Point_Type_Declaration --
20391 -------------------------------------------
20393 procedure Ordinary_Fixed_Point_Type_Declaration
20397 Loc
: constant Source_Ptr
:= Sloc
(Def
);
20398 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
20399 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
20400 Implicit_Base
: Entity_Id
;
20407 Check_Restriction
(No_Fixed_Point
, Def
);
20409 -- Create implicit base type
20412 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
20413 Set_Etype
(Implicit_Base
, Implicit_Base
);
20415 -- Analyze and process delta expression
20417 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
20419 Check_Delta_Expression
(Delta_Expr
);
20420 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
20422 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
20424 -- Compute default small from given delta, which is the largest power
20425 -- of two that does not exceed the given delta value.
20435 if Delta_Val
< Ureal_1
then
20436 while Delta_Val
< Tmp
loop
20437 Tmp
:= Tmp
/ Ureal_2
;
20438 Scale
:= Scale
+ 1;
20443 Tmp
:= Tmp
* Ureal_2
;
20444 exit when Tmp
> Delta_Val
;
20445 Scale
:= Scale
- 1;
20449 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
20452 Set_Small_Value
(Implicit_Base
, Small_Val
);
20454 -- If no range was given, set a dummy range
20456 if RRS
<= Empty_Or_Error
then
20457 Low_Val
:= -Small_Val
;
20458 High_Val
:= Small_Val
;
20460 -- Otherwise analyze and process given range
20464 Low
: constant Node_Id
:= Low_Bound
(RRS
);
20465 High
: constant Node_Id
:= High_Bound
(RRS
);
20468 Analyze_And_Resolve
(Low
, Any_Real
);
20469 Analyze_And_Resolve
(High
, Any_Real
);
20470 Check_Real_Bound
(Low
);
20471 Check_Real_Bound
(High
);
20473 -- Obtain and set the range
20475 Low_Val
:= Expr_Value_R
(Low
);
20476 High_Val
:= Expr_Value_R
(High
);
20478 if Low_Val
> High_Val
then
20479 Error_Msg_NE
("??fixed point type& has null range", Def
, T
);
20484 -- The range for both the implicit base and the declared first subtype
20485 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
20486 -- set a temporary range in place. Note that the bounds of the base
20487 -- type will be widened to be symmetrical and to fill the available
20488 -- bits when the type is frozen.
20490 -- We could do this with all discrete types, and probably should, but
20491 -- we absolutely have to do it for fixed-point, since the end-points
20492 -- of the range and the size are determined by the small value, which
20493 -- could be reset before the freeze point.
20495 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
20496 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
20498 -- Complete definition of first subtype. The inheritance of the rep item
20499 -- chain ensures that SPARK-related pragmas are not clobbered when the
20500 -- ordinary fixed point type acts as a full view of a private type.
20502 Mutate_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
20503 Set_Etype
(T
, Implicit_Base
);
20504 Reinit_Size_Align
(T
);
20505 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
20506 Set_Small_Value
(T
, Small_Val
);
20507 Set_Delta_Value
(T
, Delta_Val
);
20508 Set_Is_Constrained
(T
);
20509 end Ordinary_Fixed_Point_Type_Declaration
;
20511 ----------------------------------
20512 -- Preanalyze_Assert_Expression --
20513 ----------------------------------
20515 procedure Preanalyze_Assert_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20517 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20518 Preanalyze_Spec_Expression
(N
, T
);
20519 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20520 end Preanalyze_Assert_Expression
;
20522 -- ??? The variant below explicitly saves and restores all the flags,
20523 -- because it is impossible to compose the existing variety of
20524 -- Analyze/Resolve (and their wrappers, e.g. Preanalyze_Spec_Expression)
20525 -- to achieve the desired semantics.
20527 procedure Preanalyze_Assert_Expression
(N
: Node_Id
) is
20528 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20529 Save_Must_Not_Freeze
: constant Boolean := Must_Not_Freeze
(N
);
20530 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
20533 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20534 In_Spec_Expression
:= True;
20535 Set_Must_Not_Freeze
(N
);
20536 Inside_Preanalysis_Without_Freezing
:=
20537 Inside_Preanalysis_Without_Freezing
+ 1;
20538 Full_Analysis
:= False;
20539 Expander_Mode_Save_And_Set
(False);
20541 if GNATprove_Mode
then
20542 Analyze_And_Resolve
(N
);
20544 Analyze_And_Resolve
(N
, Suppress
=> All_Checks
);
20547 Expander_Mode_Restore
;
20548 Full_Analysis
:= Save_Full_Analysis
;
20549 Inside_Preanalysis_Without_Freezing
:=
20550 Inside_Preanalysis_Without_Freezing
- 1;
20551 Set_Must_Not_Freeze
(N
, Save_Must_Not_Freeze
);
20552 In_Spec_Expression
:= Save_In_Spec_Expression
;
20553 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20554 end Preanalyze_Assert_Expression
;
20556 -----------------------------------
20557 -- Preanalyze_Default_Expression --
20558 -----------------------------------
20560 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20561 Save_In_Default_Expr
: constant Boolean := In_Default_Expr
;
20562 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20565 In_Default_Expr
:= True;
20566 In_Spec_Expression
:= True;
20568 Preanalyze_With_Freezing_And_Resolve
(N
, T
);
20570 In_Default_Expr
:= Save_In_Default_Expr
;
20571 In_Spec_Expression
:= Save_In_Spec_Expression
;
20572 end Preanalyze_Default_Expression
;
20574 --------------------------------
20575 -- Preanalyze_Spec_Expression --
20576 --------------------------------
20578 procedure Preanalyze_Spec_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20579 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20581 In_Spec_Expression
:= True;
20582 Preanalyze_And_Resolve
(N
, T
);
20583 In_Spec_Expression
:= Save_In_Spec_Expression
;
20584 end Preanalyze_Spec_Expression
;
20586 ----------------------------------------
20587 -- Prepare_Private_Subtype_Completion --
20588 ----------------------------------------
20590 procedure Prepare_Private_Subtype_Completion
20592 Related_Nod
: Node_Id
)
20594 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
20595 Full_B
: constant Entity_Id
:= Full_View
(Id_B
);
20599 if Present
(Full_B
) then
20601 -- The Base_Type is already completed, we can complete the subtype
20602 -- now. We have to create a new entity with the same name, Thus we
20603 -- can't use Create_Itype.
20605 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
20606 Set_Is_Itype
(Full
);
20607 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
20608 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
20609 Set_Full_View
(Id
, Full
);
20612 -- The parent subtype may be private, but the base might not, in some
20613 -- nested instances. In that case, the subtype does not need to be
20614 -- exchanged. It would still be nice to make private subtypes and their
20615 -- bases consistent at all times ???
20617 if Is_Private_Type
(Id_B
) then
20618 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
20620 end Prepare_Private_Subtype_Completion
;
20622 ---------------------------
20623 -- Process_Discriminants --
20624 ---------------------------
20626 procedure Process_Discriminants
20628 Prev
: Entity_Id
:= Empty
)
20630 Elist
: constant Elist_Id
:= New_Elmt_List
;
20633 Discr_Number
: Uint
;
20634 Discr_Type
: Entity_Id
;
20635 Default_Present
: Boolean := False;
20636 Default_Not_Present
: Boolean := False;
20639 -- A composite type other than an array type can have discriminants.
20640 -- On entry, the current scope is the composite type.
20642 -- The discriminants are initially entered into the scope of the type
20643 -- via Enter_Name with the default Ekind of E_Void to prevent premature
20644 -- use, as explained at the end of this procedure.
20646 Discr
:= First
(Discriminant_Specifications
(N
));
20647 while Present
(Discr
) loop
20648 Enter_Name
(Defining_Identifier
(Discr
));
20650 -- For navigation purposes we add a reference to the discriminant
20651 -- in the entity for the type. If the current declaration is a
20652 -- completion, place references on the partial view. Otherwise the
20653 -- type is the current scope.
20655 if Present
(Prev
) then
20657 -- The references go on the partial view, if present. If the
20658 -- partial view has discriminants, the references have been
20659 -- generated already.
20661 if not Has_Discriminants
(Prev
) then
20662 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
20666 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
20669 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
20670 Check_Anonymous_Access_Component
20672 Typ
=> Defining_Identifier
(N
),
20675 Access_Def
=> Discriminant_Type
(Discr
));
20677 -- if Check_Anonymous_Access_Component replaced Discr then
20678 -- its Original_Node points to the old Discr and the access type
20679 -- for Discr_Type has already been created.
20681 if Is_Rewrite_Substitution
(Discr
) then
20682 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20685 Access_Definition
(Discr
, Discriminant_Type
(Discr
));
20687 -- Ada 2005 (AI-254)
20689 if Present
(Access_To_Subprogram_Definition
20690 (Discriminant_Type
(Discr
)))
20691 and then Protected_Present
(Access_To_Subprogram_Definition
20692 (Discriminant_Type
(Discr
)))
20695 Replace_Anonymous_Access_To_Protected_Subprogram
(Discr
);
20699 Find_Type
(Discriminant_Type
(Discr
));
20700 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20702 if Error_Posted
(Discriminant_Type
(Discr
)) then
20703 Discr_Type
:= Any_Type
;
20707 -- Handling of discriminants that are access types
20709 if Is_Access_Type
(Discr_Type
) then
20711 -- Ada 2005 (AI-230): Access discriminant allowed in non-
20712 -- limited record types
20714 if Ada_Version
< Ada_2005
then
20715 Check_Access_Discriminant_Requires_Limited
20716 (Discr
, Discriminant_Type
(Discr
));
20719 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
20721 ("(Ada 83) access discriminant not allowed", Discr
);
20724 -- If not access type, must be a discrete type
20726 elsif not Is_Discrete_Type
(Discr_Type
) then
20728 ("discriminants must have a discrete or access type",
20729 Discriminant_Type
(Discr
));
20732 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
20734 -- If a discriminant specification includes the assignment compound
20735 -- delimiter followed by an expression, the expression is the default
20736 -- expression of the discriminant; the default expression must be of
20737 -- the type of the discriminant. (RM 3.7.1) Since this expression is
20738 -- a default expression, we do the special preanalysis, since this
20739 -- expression does not freeze (see section "Handling of Default and
20740 -- Per-Object Expressions" in spec of package Sem).
20742 if Present
(Expression
(Discr
)) then
20743 Preanalyze_Default_Expression
(Expression
(Discr
), Discr_Type
);
20747 if Nkind
(N
) = N_Formal_Type_Declaration
then
20749 ("discriminant defaults not allowed for formal type",
20750 Expression
(Discr
));
20752 -- Flag an error for a tagged type with defaulted discriminants,
20753 -- excluding limited tagged types when compiling for Ada 2012
20754 -- (see AI05-0214).
20756 elsif Is_Tagged_Type
(Current_Scope
)
20757 and then (not Is_Limited_Type
(Current_Scope
)
20758 or else Ada_Version
< Ada_2012
)
20759 and then Comes_From_Source
(N
)
20761 -- Note: see similar test in Check_Or_Process_Discriminants, to
20762 -- handle the (illegal) case of the completion of an untagged
20763 -- view with discriminants with defaults by a tagged full view.
20764 -- We skip the check if Discr does not come from source, to
20765 -- account for the case of an untagged derived type providing
20766 -- defaults for a renamed discriminant from a private untagged
20767 -- ancestor with a tagged full view (ACATS B460006).
20769 if Ada_Version
>= Ada_2012
then
20771 ("discriminants of nonlimited tagged type cannot have"
20773 Expression
(Discr
));
20776 ("discriminants of tagged type cannot have defaults",
20777 Expression
(Discr
));
20781 Default_Present
:= True;
20782 Append_Elmt
(Expression
(Discr
), Elist
);
20784 -- Tag the defining identifiers for the discriminants with
20785 -- their corresponding default expressions from the tree.
20787 Set_Discriminant_Default_Value
20788 (Defining_Identifier
(Discr
), Expression
(Discr
));
20791 -- In gnatc or GNATprove mode, make sure set Do_Range_Check flag
20792 -- gets set unless we can be sure that no range check is required.
20794 if not Expander_Active
20797 (Expression
(Discr
), Discr_Type
, Assume_Valid
=> True)
20799 Set_Do_Range_Check
(Expression
(Discr
));
20802 -- No default discriminant value given
20805 Default_Not_Present
:= True;
20808 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
20809 -- Discr_Type but with the null-exclusion attribute
20811 if Ada_Version
>= Ada_2005
then
20813 -- Ada 2005 (AI-231): Static checks
20815 if Can_Never_Be_Null
(Discr_Type
) then
20816 Null_Exclusion_Static_Checks
(Discr
);
20818 elsif Is_Access_Type
(Discr_Type
)
20819 and then Null_Exclusion_Present
(Discr
)
20821 -- No need to check itypes because in their case this check
20822 -- was done at their point of creation
20824 and then not Is_Itype
(Discr_Type
)
20826 if Can_Never_Be_Null
(Discr_Type
) then
20828 ("`NOT NULL` not allowed (& already excludes null)",
20833 Set_Etype
(Defining_Identifier
(Discr
),
20834 Create_Null_Excluding_Itype
20836 Related_Nod
=> Discr
));
20838 -- Check for improper null exclusion if the type is otherwise
20839 -- legal for a discriminant.
20841 elsif Null_Exclusion_Present
(Discr
)
20842 and then Is_Discrete_Type
(Discr_Type
)
20845 ("null exclusion can only apply to an access type", Discr
);
20848 -- Ada 2005 (AI-402): access discriminants of nonlimited types
20849 -- can't have defaults. Synchronized types, or types that are
20850 -- explicitly limited are fine, but special tests apply to derived
20851 -- types in generics: in a generic body we have to assume the
20852 -- worst, and therefore defaults are not allowed if the parent is
20853 -- a generic formal private type (see ACATS B370001).
20855 if Is_Access_Type
(Discr_Type
) and then Default_Present
then
20856 if Ekind
(Discr_Type
) /= E_Anonymous_Access_Type
20857 or else Is_Limited_Record
(Current_Scope
)
20858 or else Is_Concurrent_Type
(Current_Scope
)
20859 or else Is_Concurrent_Record_Type
(Current_Scope
)
20860 or else Ekind
(Current_Scope
) = E_Limited_Private_Type
20862 if not Is_Derived_Type
(Current_Scope
)
20863 or else not Is_Generic_Type
(Etype
(Current_Scope
))
20864 or else not In_Package_Body
(Scope
(Etype
(Current_Scope
)))
20865 or else Limited_Present
20866 (Type_Definition
(Parent
(Current_Scope
)))
20872 ("access discriminants of nonlimited types cannot "
20873 & "have defaults", Expression
(Discr
));
20876 elsif Present
(Expression
(Discr
)) then
20878 ("(Ada 2005) access discriminants of nonlimited types "
20879 & "cannot have defaults", Expression
(Discr
));
20884 -- A discriminant cannot be effectively volatile (SPARK RM 7.1.3(4)).
20885 -- This check is relevant only when SPARK_Mode is on as it is not a
20886 -- standard Ada legality rule. The only way for a discriminant to be
20887 -- effectively volatile is to have an effectively volatile type, so
20888 -- we check this directly, because the Ekind of Discr might not be
20889 -- set yet (to help preventing cascaded errors on derived types).
20892 and then Is_Effectively_Volatile
(Discr_Type
)
20894 Error_Msg_N
("discriminant cannot be volatile", Discr
);
20900 -- An element list consisting of the default expressions of the
20901 -- discriminants is constructed in the above loop and used to set
20902 -- the Discriminant_Constraint attribute for the type. If an object
20903 -- is declared of this (record or task) type without any explicit
20904 -- discriminant constraint given, this element list will form the
20905 -- actual parameters for the corresponding initialization procedure
20908 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
20909 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
20911 -- Default expressions must be provided either for all or for none
20912 -- of the discriminants of a discriminant part. (RM 3.7.1)
20914 if Default_Present
and then Default_Not_Present
then
20916 ("incomplete specification of defaults for discriminants", N
);
20919 -- The use of the name of a discriminant is not allowed in default
20920 -- expressions of a discriminant part if the specification of the
20921 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
20923 -- To detect this, the discriminant names are entered initially with an
20924 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
20925 -- attempt to use a void entity (for example in an expression that is
20926 -- type-checked) produces the error message: premature usage. Now after
20927 -- completing the semantic analysis of the discriminant part, we can set
20928 -- the Ekind of all the discriminants appropriately.
20930 Discr
:= First
(Discriminant_Specifications
(N
));
20931 Discr_Number
:= Uint_1
;
20932 while Present
(Discr
) loop
20933 Id
:= Defining_Identifier
(Discr
);
20935 if Ekind
(Id
) = E_In_Parameter
then
20936 Reinit_Field_To_Zero
(Id
, F_Discriminal_Link
);
20939 Mutate_Ekind
(Id
, E_Discriminant
);
20940 Reinit_Component_Location
(Id
);
20942 Set_Discriminant_Number
(Id
, Discr_Number
);
20944 -- Make sure this is always set, even in illegal programs
20946 Set_Corresponding_Discriminant
(Id
, Empty
);
20948 -- Initialize the Original_Record_Component to the entity itself.
20949 -- Inherit_Components will propagate the right value to
20950 -- discriminants in derived record types.
20952 Set_Original_Record_Component
(Id
, Id
);
20954 -- Create the discriminal for the discriminant
20956 Build_Discriminal
(Id
);
20959 Discr_Number
:= Discr_Number
+ 1;
20962 Set_Has_Discriminants
(Current_Scope
);
20963 end Process_Discriminants
;
20965 -----------------------
20966 -- Process_Full_View --
20967 -----------------------
20969 -- WARNING: This routine manages Ghost regions. Return statements must be
20970 -- replaced by gotos which jump to the end of the routine and restore the
20973 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
20974 procedure Collect_Implemented_Interfaces
20976 Ifaces
: Elist_Id
);
20977 -- Ada 2005: Gather all the interfaces that Typ directly or
20978 -- inherently implements. Duplicate entries are not added to
20979 -- the list Ifaces.
20981 ------------------------------------
20982 -- Collect_Implemented_Interfaces --
20983 ------------------------------------
20985 procedure Collect_Implemented_Interfaces
20990 Iface_Elmt
: Elmt_Id
;
20993 -- Abstract interfaces are only associated with tagged record types
20995 if not Is_Tagged_Type
(Typ
) or else not Is_Record_Type
(Typ
) then
20999 -- Recursively climb to the ancestors
21001 if Etype
(Typ
) /= Typ
21003 -- Protect the frontend against wrong cyclic declarations like:
21005 -- type B is new A with private;
21006 -- type C is new A with private;
21008 -- type B is new C with null record;
21009 -- type C is new B with null record;
21011 and then Etype
(Typ
) /= Priv_T
21012 and then Etype
(Typ
) /= Full_T
21014 -- Keep separate the management of private type declarations
21016 if Ekind
(Typ
) = E_Record_Type_With_Private
then
21018 -- Handle the following illegal usage:
21019 -- type Private_Type is tagged private;
21021 -- type Private_Type is new Type_Implementing_Iface;
21023 if Present
(Full_View
(Typ
))
21024 and then Etype
(Typ
) /= Full_View
(Typ
)
21026 if Is_Interface
(Etype
(Typ
)) then
21027 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
21030 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
21033 -- Non-private types
21036 if Is_Interface
(Etype
(Typ
)) then
21037 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
21040 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
21044 -- Handle entities in the list of abstract interfaces
21046 if Present
(Interfaces
(Typ
)) then
21047 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
21048 while Present
(Iface_Elmt
) loop
21049 Iface
:= Node
(Iface_Elmt
);
21051 pragma Assert
(Is_Interface
(Iface
));
21053 if not Contain_Interface
(Iface
, Ifaces
) then
21054 Append_Elmt
(Iface
, Ifaces
);
21055 Collect_Implemented_Interfaces
(Iface
, Ifaces
);
21058 Next_Elmt
(Iface_Elmt
);
21061 end Collect_Implemented_Interfaces
;
21065 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
21066 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
21067 -- Save the Ghost-related attributes to restore on exit
21069 Full_Indic
: Node_Id
;
21070 Full_Parent
: Entity_Id
;
21071 Priv_Parent
: Entity_Id
;
21073 -- Start of processing for Process_Full_View
21076 Mark_And_Set_Ghost_Completion
(N
, Priv_T
);
21078 -- First some sanity checks that must be done after semantic
21079 -- decoration of the full view and thus cannot be placed with other
21080 -- similar checks in Find_Type_Name
21082 if not Is_Limited_Type
(Priv_T
)
21083 and then (Is_Limited_Type
(Full_T
)
21084 or else Is_Limited_Composite
(Full_T
))
21086 if In_Instance
then
21090 ("completion of nonlimited type cannot be limited", Full_T
);
21091 Explain_Limited_Type
(Full_T
, Full_T
);
21094 elsif Is_Abstract_Type
(Full_T
)
21095 and then not Is_Abstract_Type
(Priv_T
)
21098 ("completion of nonabstract type cannot be abstract", Full_T
);
21100 elsif Is_Tagged_Type
(Priv_T
)
21101 and then Is_Limited_Type
(Priv_T
)
21102 and then not Is_Limited_Type
(Full_T
)
21104 -- If pragma CPP_Class was applied to the private declaration
21105 -- propagate the limitedness to the full-view
21107 if Is_CPP_Class
(Priv_T
) then
21108 Set_Is_Limited_Record
(Full_T
);
21110 -- GNAT allow its own definition of Limited_Controlled to disobey
21111 -- this rule in order in ease the implementation. This test is safe
21112 -- because Root_Controlled is defined in a child of System that
21113 -- normal programs are not supposed to use.
21115 elsif Is_RTE
(Etype
(Full_T
), RE_Root_Controlled
) then
21116 Set_Is_Limited_Composite
(Full_T
);
21119 ("completion of limited tagged type must be limited", Full_T
);
21122 elsif Is_Generic_Type
(Priv_T
) then
21123 Error_Msg_N
("generic type cannot have a completion", Full_T
);
21126 -- Check that ancestor interfaces of private and full views are
21127 -- consistent. We omit this check for synchronized types because
21128 -- they are performed on the corresponding record type when frozen.
21130 if Ada_Version
>= Ada_2005
21131 and then Is_Tagged_Type
(Priv_T
)
21132 and then Is_Tagged_Type
(Full_T
)
21133 and then not Is_Concurrent_Type
(Full_T
)
21137 Priv_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
21138 Full_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
21141 Collect_Implemented_Interfaces
(Priv_T
, Priv_T_Ifaces
);
21142 Collect_Implemented_Interfaces
(Full_T
, Full_T_Ifaces
);
21144 -- Ada 2005 (AI-251): The partial view shall be a descendant of
21145 -- an interface type if and only if the full type is descendant
21146 -- of the interface type (AARM 7.3 (7.3/2)).
21148 Iface
:= Find_Hidden_Interface
(Priv_T_Ifaces
, Full_T_Ifaces
);
21150 if Present
(Iface
) then
21152 ("interface in partial view& not implemented by full type "
21153 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
21156 Iface
:= Find_Hidden_Interface
(Full_T_Ifaces
, Priv_T_Ifaces
);
21158 if Present
(Iface
) then
21160 ("interface & not implemented by partial view "
21161 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
21166 if Is_Tagged_Type
(Priv_T
)
21167 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21168 and then Is_Derived_Type
(Full_T
)
21170 Priv_Parent
:= Etype
(Priv_T
);
21172 -- The full view of a private extension may have been transformed
21173 -- into an unconstrained derived type declaration and a subtype
21174 -- declaration (see build_derived_record_type for details).
21176 if Nkind
(N
) = N_Subtype_Declaration
then
21177 Full_Indic
:= Subtype_Indication
(N
);
21178 Full_Parent
:= Etype
(Base_Type
(Full_T
));
21180 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
21181 Full_Parent
:= Etype
(Full_T
);
21184 -- Check that the parent type of the full type is a descendant of
21185 -- the ancestor subtype given in the private extension. If either
21186 -- entity has an Etype equal to Any_Type then we had some previous
21187 -- error situation [7.3(8)].
21189 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
21192 -- Ada 2005 (AI-251): Interfaces in the full type can be given in
21193 -- any order. Therefore we don't have to check that its parent must
21194 -- be a descendant of the parent of the private type declaration.
21196 elsif Is_Interface
(Priv_Parent
)
21197 and then Is_Interface
(Full_Parent
)
21201 -- Ada 2005 (AI-251): If the parent of the private type declaration
21202 -- is an interface there is no need to check that it is an ancestor
21203 -- of the associated full type declaration. The required tests for
21204 -- this case are performed by Build_Derived_Record_Type.
21206 elsif not Is_Interface
(Base_Type
(Priv_Parent
))
21207 and then not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
)
21210 ("parent of full type must descend from parent of private "
21211 & "extension", Full_Indic
);
21213 -- First check a formal restriction, and then proceed with checking
21214 -- Ada rules. Since the formal restriction is not a serious error, we
21215 -- don't prevent further error detection for this check, hence the
21219 -- Check the rules of 7.3(10): if the private extension inherits
21220 -- known discriminants, then the full type must also inherit those
21221 -- discriminants from the same (ancestor) type, and the parent
21222 -- subtype of the full type must be constrained if and only if
21223 -- the ancestor subtype of the private extension is constrained.
21225 if No
(Discriminant_Specifications
(Parent
(Priv_T
)))
21226 and then not Has_Unknown_Discriminants
(Priv_T
)
21227 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
21230 Priv_Indic
: constant Node_Id
:=
21231 Subtype_Indication
(Parent
(Priv_T
));
21233 Priv_Constr
: constant Boolean :=
21234 Is_Constrained
(Priv_Parent
)
21236 Nkind
(Priv_Indic
) = N_Subtype_Indication
21238 Is_Constrained
(Entity
(Priv_Indic
));
21240 Full_Constr
: constant Boolean :=
21241 Is_Constrained
(Full_Parent
)
21243 Nkind
(Full_Indic
) = N_Subtype_Indication
21245 Is_Constrained
(Entity
(Full_Indic
));
21247 Priv_Discr
: Entity_Id
;
21248 Full_Discr
: Entity_Id
;
21251 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
21252 Full_Discr
:= First_Discriminant
(Full_Parent
);
21253 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
21254 if Original_Record_Component
(Priv_Discr
) =
21255 Original_Record_Component
(Full_Discr
)
21257 Corresponding_Discriminant
(Priv_Discr
) =
21258 Corresponding_Discriminant
(Full_Discr
)
21265 Next_Discriminant
(Priv_Discr
);
21266 Next_Discriminant
(Full_Discr
);
21269 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
21271 ("full view must inherit discriminants of the parent "
21272 & "type used in the private extension", Full_Indic
);
21274 elsif Priv_Constr
and then not Full_Constr
then
21276 ("parent subtype of full type must be constrained",
21279 elsif Full_Constr
and then not Priv_Constr
then
21281 ("parent subtype of full type must be unconstrained",
21286 -- Check the rules of 7.3(12): if a partial view has neither
21287 -- known or unknown discriminants, then the full type
21288 -- declaration shall define a definite subtype.
21290 elsif not Has_Unknown_Discriminants
(Priv_T
)
21291 and then not Has_Discriminants
(Priv_T
)
21292 and then not Is_Constrained
(Full_T
)
21295 ("full view must define a constrained type if partial view "
21296 & "has no discriminants", Full_T
);
21299 -- Do we implement the following properly???
21300 -- If the ancestor subtype of a private extension has constrained
21301 -- discriminants, then the parent subtype of the full view shall
21302 -- impose a statically matching constraint on those discriminants
21307 -- For untagged types, verify that a type without discriminants is
21308 -- not completed with an unconstrained type. A separate error message
21309 -- is produced if the full type has defaulted discriminants.
21311 if Is_Definite_Subtype
(Priv_T
)
21312 and then not Is_Definite_Subtype
(Full_T
)
21314 Error_Msg_Sloc
:= Sloc
(Parent
(Priv_T
));
21316 ("full view of& not compatible with declaration#",
21319 if not Is_Tagged_Type
(Full_T
) then
21321 ("\one is constrained, the other unconstrained", Full_T
);
21326 -- AI-419: verify that the use of "limited" is consistent
21329 Orig_Decl
: constant Node_Id
:= Original_Node
(N
);
21332 if Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21333 and then Nkind
(Orig_Decl
) = N_Full_Type_Declaration
21335 (Type_Definition
(Orig_Decl
)) = N_Derived_Type_Definition
21337 if not Limited_Present
(Parent
(Priv_T
))
21338 and then not Synchronized_Present
(Parent
(Priv_T
))
21339 and then Limited_Present
(Type_Definition
(Orig_Decl
))
21342 ("full view of non-limited extension cannot be limited", N
);
21344 -- Conversely, if the partial view carries the limited keyword,
21345 -- the full view must as well, even if it may be redundant.
21347 elsif Limited_Present
(Parent
(Priv_T
))
21348 and then not Limited_Present
(Type_Definition
(Orig_Decl
))
21351 ("full view of limited extension must be explicitly limited",
21357 -- Ada 2005 (AI-443): A synchronized private extension must be
21358 -- completed by a task or protected type.
21360 if Ada_Version
>= Ada_2005
21361 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21362 and then Synchronized_Present
(Parent
(Priv_T
))
21363 and then not Is_Concurrent_Type
(Full_T
)
21365 Error_Msg_N
("full view of synchronized extension must " &
21366 "be synchronized type", N
);
21369 -- Ada 2005 AI-363: if the full view has discriminants with
21370 -- defaults, it is illegal to declare constrained access subtypes
21371 -- whose designated type is the current type. This allows objects
21372 -- of the type that are declared in the heap to be unconstrained.
21374 if not Has_Unknown_Discriminants
(Priv_T
)
21375 and then not Has_Discriminants
(Priv_T
)
21376 and then Has_Defaulted_Discriminants
(Full_T
)
21378 Set_Has_Constrained_Partial_View
(Base_Type
(Full_T
));
21379 Set_Has_Constrained_Partial_View
(Priv_T
);
21382 -- Create a full declaration for all its subtypes recorded in
21383 -- Private_Dependents and swap them similarly to the base type. These
21384 -- are subtypes that have been define before the full declaration of
21385 -- the private type. We also swap the entry in Private_Dependents list
21386 -- so we can properly restore the private view on exit from the scope.
21389 Priv_Elmt
: Elmt_Id
;
21390 Priv_Scop
: Entity_Id
;
21395 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
21396 while Present
(Priv_Elmt
) loop
21397 Priv
:= Node
(Priv_Elmt
);
21398 Priv_Scop
:= Scope
(Priv
);
21400 if Ekind
(Priv
) in E_Private_Subtype
21401 | E_Limited_Private_Subtype
21402 | E_Record_Subtype_With_Private
21404 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
21405 Set_Is_Itype
(Full
);
21406 Set_Parent
(Full
, Parent
(Priv
));
21407 Set_Associated_Node_For_Itype
(Full
, N
);
21409 -- Now we need to complete the private subtype, but since the
21410 -- base type has already been swapped, we must also swap the
21411 -- subtypes (and thus, reverse the arguments in the call to
21412 -- Complete_Private_Subtype). Also note that we may need to
21413 -- re-establish the scope of the private subtype.
21415 Copy_And_Swap
(Priv
, Full
);
21417 if not In_Open_Scopes
(Priv_Scop
) then
21418 Push_Scope
(Priv_Scop
);
21421 -- Reset Priv_Scop to Empty to indicate no scope was pushed
21423 Priv_Scop
:= Empty
;
21426 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
21427 Set_Full_View
(Full
, Priv
);
21429 if Present
(Priv_Scop
) then
21433 Replace_Elmt
(Priv_Elmt
, Full
);
21436 Next_Elmt
(Priv_Elmt
);
21441 Disp_Typ
: Entity_Id
;
21442 Full_List
: Elist_Id
;
21444 Prim_Elmt
: Elmt_Id
;
21445 Priv_List
: Elist_Id
;
21449 L
: Elist_Id
) return Boolean;
21450 -- Determine whether list L contains element E
21458 L
: Elist_Id
) return Boolean
21460 List_Elmt
: Elmt_Id
;
21463 List_Elmt
:= First_Elmt
(L
);
21464 while Present
(List_Elmt
) loop
21465 if Node
(List_Elmt
) = E
then
21469 Next_Elmt
(List_Elmt
);
21475 -- Start of processing
21478 -- If the private view was tagged, copy the new primitive operations
21479 -- from the private view to the full view.
21481 if Is_Tagged_Type
(Full_T
) then
21482 if Is_Tagged_Type
(Priv_T
) then
21483 Priv_List
:= Primitive_Operations
(Priv_T
);
21484 Prim_Elmt
:= First_Elmt
(Priv_List
);
21486 -- In the case of a concurrent type completing a private tagged
21487 -- type, primitives may have been declared in between the two
21488 -- views. These subprograms need to be wrapped the same way
21489 -- entries and protected procedures are handled because they
21490 -- cannot be directly shared by the two views.
21492 if Is_Concurrent_Type
(Full_T
) then
21494 Conc_Typ
: constant Entity_Id
:=
21495 Corresponding_Record_Type
(Full_T
);
21496 Curr_Nod
: Node_Id
:= Parent
(Conc_Typ
);
21497 Wrap_Spec
: Node_Id
;
21500 while Present
(Prim_Elmt
) loop
21501 Prim
:= Node
(Prim_Elmt
);
21503 if Comes_From_Source
(Prim
)
21504 and then not Is_Abstract_Subprogram
(Prim
)
21507 Make_Subprogram_Declaration
(Sloc
(Prim
),
21511 Obj_Typ
=> Conc_Typ
,
21513 Parameter_Specifications
21516 Insert_After
(Curr_Nod
, Wrap_Spec
);
21517 Curr_Nod
:= Wrap_Spec
;
21519 Analyze
(Wrap_Spec
);
21521 -- Remove the wrapper from visibility to avoid
21522 -- spurious conflict with the wrapped entity.
21524 Set_Is_Immediately_Visible
21525 (Defining_Entity
(Specification
(Wrap_Spec
)),
21529 Next_Elmt
(Prim_Elmt
);
21535 -- For nonconcurrent types, transfer explicit primitives, but
21536 -- omit those inherited from the parent of the private view
21537 -- since they will be re-inherited later on.
21540 Full_List
:= Primitive_Operations
(Full_T
);
21541 while Present
(Prim_Elmt
) loop
21542 Prim
:= Node
(Prim_Elmt
);
21544 if Comes_From_Source
(Prim
)
21545 and then not Contains
(Prim
, Full_List
)
21547 Append_Elmt
(Prim
, Full_List
);
21550 Next_Elmt
(Prim_Elmt
);
21554 -- Untagged private view
21557 Full_List
:= Primitive_Operations
(Full_T
);
21559 -- In this case the partial view is untagged, so here we locate
21560 -- all of the earlier primitives that need to be treated as
21561 -- dispatching (those that appear between the two views). Note
21562 -- that these additional operations must all be new operations
21563 -- (any earlier operations that override inherited operations
21564 -- of the full view will already have been inserted in the
21565 -- primitives list, marked by Check_Operation_From_Private_View
21566 -- as dispatching. Note that implicit "/=" operators are
21567 -- excluded from being added to the primitives list since they
21568 -- shouldn't be treated as dispatching (tagged "/=" is handled
21571 Prim
:= Next_Entity
(Full_T
);
21572 while Present
(Prim
) and then Prim
/= Priv_T
loop
21573 if Ekind
(Prim
) in E_Procedure | E_Function
then
21574 Disp_Typ
:= Find_Dispatching_Type
(Prim
);
21576 if Disp_Typ
= Full_T
21577 and then (Chars
(Prim
) /= Name_Op_Ne
21578 or else Comes_From_Source
(Prim
))
21580 Check_Controlling_Formals
(Full_T
, Prim
);
21582 if Is_Suitable_Primitive
(Prim
)
21583 and then not Is_Dispatching_Operation
(Prim
)
21585 Append_Elmt
(Prim
, Full_List
);
21586 Set_Is_Dispatching_Operation
(Prim
);
21587 Set_DT_Position_Value
(Prim
, No_Uint
);
21590 elsif Is_Dispatching_Operation
(Prim
)
21591 and then Disp_Typ
/= Full_T
21593 -- Verify that it is not otherwise controlled by a
21594 -- formal or a return value of type T.
21596 Check_Controlling_Formals
(Disp_Typ
, Prim
);
21600 Next_Entity
(Prim
);
21604 -- For the tagged case, the two views can share the same primitive
21605 -- operations list and the same class-wide type. Update attributes
21606 -- of the class-wide type which depend on the full declaration.
21608 if Is_Tagged_Type
(Priv_T
) then
21609 Set_Direct_Primitive_Operations
(Priv_T
, Full_List
);
21610 Set_Class_Wide_Type
21611 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
21613 Propagate_Concurrent_Flags
(Class_Wide_Type
(Priv_T
), Full_T
);
21616 -- For untagged types, copy the primitives across from the private
21617 -- view to the full view, for support of prefixed calls when
21618 -- extensions are enabled, and better error messages otherwise.
21621 Priv_List
:= Primitive_Operations
(Priv_T
);
21622 Prim_Elmt
:= First_Elmt
(Priv_List
);
21624 Full_List
:= Primitive_Operations
(Full_T
);
21625 while Present
(Prim_Elmt
) loop
21626 Prim
:= Node
(Prim_Elmt
);
21627 Append_Elmt
(Prim
, Full_List
);
21628 Next_Elmt
(Prim_Elmt
);
21633 -- Ada 2005 AI 161: Check preelaborable initialization consistency
21635 if Known_To_Have_Preelab_Init
(Priv_T
) then
21637 -- Case where there is a pragma Preelaborable_Initialization. We
21638 -- always allow this in predefined units, which is cheating a bit,
21639 -- but it means we don't have to struggle to meet the requirements in
21640 -- the RM for having Preelaborable Initialization. Otherwise we
21641 -- require that the type meets the RM rules. But we can't check that
21642 -- yet, because of the rule about overriding Initialize, so we simply
21643 -- set a flag that will be checked at freeze time.
21645 if not In_Predefined_Unit
(Full_T
) then
21646 Set_Must_Have_Preelab_Init
(Full_T
);
21650 -- If pragma CPP_Class was applied to the private type declaration,
21651 -- propagate it now to the full type declaration.
21653 if Is_CPP_Class
(Priv_T
) then
21654 Set_Is_CPP_Class
(Full_T
);
21655 Set_Convention
(Full_T
, Convention_CPP
);
21657 -- Check that components of imported CPP types do not have default
21660 Check_CPP_Type_Has_No_Defaults
(Full_T
);
21663 -- If the private view has user specified stream attributes, then so has
21666 -- Why the test, how could these flags be already set in Full_T ???
21668 if Has_Specified_Stream_Read
(Priv_T
) then
21669 Set_Has_Specified_Stream_Read
(Full_T
);
21672 if Has_Specified_Stream_Write
(Priv_T
) then
21673 Set_Has_Specified_Stream_Write
(Full_T
);
21676 if Has_Specified_Stream_Input
(Priv_T
) then
21677 Set_Has_Specified_Stream_Input
(Full_T
);
21680 if Has_Specified_Stream_Output
(Priv_T
) then
21681 Set_Has_Specified_Stream_Output
(Full_T
);
21684 -- Propagate Default_Initial_Condition-related attributes from the
21685 -- partial view to the full view.
21687 Propagate_DIC_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21689 -- And to the underlying full view, if any
21691 if Is_Private_Type
(Full_T
)
21692 and then Present
(Underlying_Full_View
(Full_T
))
21694 Propagate_DIC_Attributes
21695 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21698 -- Propagate invariant-related attributes from the partial view to the
21701 Propagate_Invariant_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21703 -- And to the underlying full view, if any
21705 if Is_Private_Type
(Full_T
)
21706 and then Present
(Underlying_Full_View
(Full_T
))
21708 Propagate_Invariant_Attributes
21709 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21712 -- AI12-0041: Detect an attempt to inherit a class-wide type invariant
21713 -- in the full view without advertising the inheritance in the partial
21714 -- view. This can only occur when the partial view has no parent type
21715 -- and the full view has an interface as a parent. Any other scenarios
21716 -- are illegal because implemented interfaces must match between the
21719 if Is_Tagged_Type
(Priv_T
) and then Is_Tagged_Type
(Full_T
) then
21721 Full_Par
: constant Entity_Id
:= Etype
(Full_T
);
21722 Priv_Par
: constant Entity_Id
:= Etype
(Priv_T
);
21725 if not Is_Interface
(Priv_Par
)
21726 and then Is_Interface
(Full_Par
)
21727 and then Has_Inheritable_Invariants
(Full_Par
)
21730 ("hidden inheritance of class-wide type invariants not "
21736 -- Propagate predicates to full type, and predicate function if already
21737 -- defined. It is not clear that this can actually happen? the partial
21738 -- view cannot be frozen yet, and the predicate function has not been
21739 -- built. Still it is a cheap check and seems safer to make it.
21741 Propagate_Predicate_Attributes
(Full_T
, Priv_T
);
21743 if Is_Private_Type
(Full_T
)
21744 and then Present
(Underlying_Full_View
(Full_T
))
21746 Propagate_Predicate_Attributes
21747 (Underlying_Full_View
(Full_T
), Priv_T
);
21751 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
21752 end Process_Full_View
;
21754 -----------------------------------
21755 -- Process_Incomplete_Dependents --
21756 -----------------------------------
21758 procedure Process_Incomplete_Dependents
21760 Full_T
: Entity_Id
;
21763 Inc_Elmt
: Elmt_Id
;
21764 Priv_Dep
: Entity_Id
;
21765 New_Subt
: Entity_Id
;
21767 Disc_Constraint
: Elist_Id
;
21770 if No
(Private_Dependents
(Inc_T
)) then
21774 -- Itypes that may be generated by the completion of an incomplete
21775 -- subtype are not used by the back-end and not attached to the tree.
21776 -- They are created only for constraint-checking purposes.
21778 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
21779 while Present
(Inc_Elmt
) loop
21780 Priv_Dep
:= Node
(Inc_Elmt
);
21782 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
21784 -- An Access_To_Subprogram type may have a return type or a
21785 -- parameter type that is incomplete. Replace with the full view.
21787 if Etype
(Priv_Dep
) = Inc_T
then
21788 Set_Etype
(Priv_Dep
, Full_T
);
21792 Formal
: Entity_Id
;
21795 Formal
:= First_Formal
(Priv_Dep
);
21796 while Present
(Formal
) loop
21797 if Etype
(Formal
) = Inc_T
then
21798 Set_Etype
(Formal
, Full_T
);
21801 Next_Formal
(Formal
);
21805 elsif Is_Overloadable
(Priv_Dep
) then
21807 -- If a subprogram in the incomplete dependents list is primitive
21808 -- for a tagged full type then mark it as a dispatching operation,
21809 -- check whether it overrides an inherited subprogram, and check
21810 -- restrictions on its controlling formals. Note that a protected
21811 -- operation is never dispatching: only its wrapper operation
21812 -- (which has convention Ada) is.
21814 if Is_Tagged_Type
(Full_T
)
21815 and then Is_Primitive
(Priv_Dep
)
21816 and then Convention
(Priv_Dep
) /= Convention_Protected
21818 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
21819 Set_Is_Dispatching_Operation
(Priv_Dep
);
21820 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
21823 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
21825 -- Can happen during processing of a body before the completion
21826 -- of a TA type. Ignore, because spec is also on dependent list.
21830 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
21831 -- corresponding subtype of the full view.
21833 elsif Ekind
(Priv_Dep
) = E_Incomplete_Subtype
21834 and then Comes_From_Source
(Priv_Dep
)
21836 Set_Subtype_Indication
21837 (Parent
(Priv_Dep
), New_Occurrence_Of
(Full_T
, Sloc
(Priv_Dep
)));
21838 Reinit_Field_To_Zero
21839 (Priv_Dep
, F_Private_Dependents
,
21840 Old_Ekind
=> E_Incomplete_Subtype
);
21841 Mutate_Ekind
(Priv_Dep
, Subtype_Kind
(Ekind
(Full_T
)));
21842 Set_Etype
(Priv_Dep
, Full_T
);
21843 Set_Analyzed
(Parent
(Priv_Dep
), False);
21845 -- Reanalyze the declaration, suppressing the call to Enter_Name
21846 -- to avoid duplicate names.
21848 Analyze_Subtype_Declaration
21849 (N
=> Parent
(Priv_Dep
),
21852 -- Dependent is a subtype
21855 -- We build a new subtype indication using the full view of the
21856 -- incomplete parent. The discriminant constraints have been
21857 -- elaborated already at the point of the subtype declaration.
21859 New_Subt
:= Create_Itype
(E_Void
, N
);
21861 if Has_Discriminants
(Full_T
) then
21862 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
21864 Disc_Constraint
:= No_Elist
;
21867 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
21868 Set_Full_View
(Priv_Dep
, New_Subt
);
21871 Next_Elmt
(Inc_Elmt
);
21873 end Process_Incomplete_Dependents
;
21875 --------------------------------
21876 -- Process_Range_Expr_In_Decl --
21877 --------------------------------
21879 procedure Process_Range_Expr_In_Decl
21882 Subtyp
: Entity_Id
:= Empty
;
21883 Check_List
: List_Id
:= No_List
)
21886 R_Checks
: Check_Result
;
21887 Insert_Node
: Node_Id
;
21888 Def_Id
: Entity_Id
;
21891 Analyze_And_Resolve
(R
, Base_Type
(T
));
21893 if Nkind
(R
) = N_Range
then
21894 Lo
:= Low_Bound
(R
);
21895 Hi
:= High_Bound
(R
);
21897 -- Validity checks on the range of a quantified expression are
21898 -- delayed until the construct is transformed into a loop.
21900 if Nkind
(Parent
(R
)) = N_Loop_Parameter_Specification
21901 and then Nkind
(Parent
(Parent
(R
))) = N_Quantified_Expression
21905 -- We need to ensure validity of the bounds here, because if we
21906 -- go ahead and do the expansion, then the expanded code will get
21907 -- analyzed with range checks suppressed and we miss the check.
21909 -- WARNING: The capture of the range bounds with xxx_FIRST/_LAST and
21910 -- the temporaries generated by routine Remove_Side_Effects by means
21911 -- of validity checks must use the same names. When a range appears
21912 -- in the parent of a generic, the range is processed with checks
21913 -- disabled as part of the generic context and with checks enabled
21914 -- for code generation purposes. This leads to link issues as the
21915 -- generic contains references to xxx_FIRST/_LAST, but the inlined
21916 -- template sees the temporaries generated by Remove_Side_Effects.
21919 Validity_Check_Range
(R
, Subtyp
);
21922 -- If there were errors in the declaration, try and patch up some
21923 -- common mistakes in the bounds. The cases handled are literals
21924 -- which are Integer where the expected type is Real and vice versa.
21925 -- These corrections allow the compilation process to proceed further
21926 -- along since some basic assumptions of the format of the bounds
21929 if Etype
(R
) = Any_Type
then
21930 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
21932 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
21934 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
21936 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
21938 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
21940 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
21942 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
21944 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
21951 -- If the bounds of the range have been mistakenly given as string
21952 -- literals (perhaps in place of character literals), then an error
21953 -- has already been reported, but we rewrite the string literal as a
21954 -- bound of the range's type to avoid blowups in later processing
21955 -- that looks at static values.
21957 if Nkind
(Lo
) = N_String_Literal
then
21959 Make_Attribute_Reference
(Sloc
(Lo
),
21960 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Lo
)),
21961 Attribute_Name
=> Name_First
));
21962 Analyze_And_Resolve
(Lo
);
21965 if Nkind
(Hi
) = N_String_Literal
then
21967 Make_Attribute_Reference
(Sloc
(Hi
),
21968 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Hi
)),
21969 Attribute_Name
=> Name_First
));
21970 Analyze_And_Resolve
(Hi
);
21973 -- If bounds aren't scalar at this point then exit, avoiding
21974 -- problems with further processing of the range in this procedure.
21976 if not Is_Scalar_Type
(Etype
(Lo
)) then
21980 -- Resolve (actually Sem_Eval) has checked that the bounds are in
21981 -- then range of the base type. Here we check whether the bounds
21982 -- are in the range of the subtype itself. Note that if the bounds
21983 -- represent the null range the Constraint_Error exception should
21986 -- Capture values of bounds and generate temporaries for them
21987 -- if needed, before applying checks, since checks may cause
21988 -- duplication of the expression without forcing evaluation.
21990 -- The forced evaluation removes side effects from expressions,
21991 -- which should occur also in GNATprove mode. Otherwise, we end up
21992 -- with unexpected insertions of actions at places where this is
21993 -- not supposed to occur, e.g. on default parameters of a call.
21995 if Expander_Active
or GNATprove_Mode
then
21997 -- Call Force_Evaluation to create declarations as needed
21998 -- to deal with side effects, and also create typ_FIRST/LAST
21999 -- entities for bounds if we have a subtype name.
22001 -- Note: we do this transformation even if expansion is not
22002 -- active if we are in GNATprove_Mode since the transformation
22003 -- is in general required to ensure that the resulting tree has
22004 -- proper Ada semantics.
22007 (Lo
, Related_Id
=> Subtyp
, Is_Low_Bound
=> True);
22009 (Hi
, Related_Id
=> Subtyp
, Is_High_Bound
=> True);
22012 -- We use a flag here instead of suppressing checks on the type
22013 -- because the type we check against isn't necessarily the place
22014 -- where we put the check.
22016 R_Checks
:= Get_Range_Checks
(R
, T
);
22018 -- Look up tree to find an appropriate insertion point. We can't
22019 -- just use insert_actions because later processing depends on
22020 -- the insertion node. Prior to Ada 2012 the insertion point could
22021 -- only be a declaration or a loop, but quantified expressions can
22022 -- appear within any context in an expression, and the insertion
22023 -- point can be any statement, pragma, or declaration.
22025 Insert_Node
:= Parent
(R
);
22026 while Present
(Insert_Node
) loop
22028 Nkind
(Insert_Node
) in N_Declaration
22030 Nkind
(Insert_Node
) not in N_Component_Declaration
22031 | N_Loop_Parameter_Specification
22032 | N_Function_Specification
22033 | N_Procedure_Specification
;
22035 exit when Nkind
(Insert_Node
) in
22036 N_Later_Decl_Item |
22037 N_Statement_Other_Than_Procedure_Call |
22038 N_Procedure_Call_Statement |
22041 Insert_Node
:= Parent
(Insert_Node
);
22044 if Present
(Insert_Node
) then
22046 -- Case of loop statement. Verify that the range is part of the
22047 -- subtype indication of the iteration scheme.
22049 if Nkind
(Insert_Node
) = N_Loop_Statement
then
22054 Indic
:= Parent
(R
);
22055 while Present
(Indic
)
22056 and then Nkind
(Indic
) /= N_Subtype_Indication
22058 Indic
:= Parent
(Indic
);
22061 if Present
(Indic
) then
22062 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
22064 Insert_Range_Checks
22068 Sloc
(Insert_Node
),
22069 Do_Before
=> True);
22073 -- Case of declarations. If the declaration is for a type and
22074 -- involves discriminants, the checks are premature at the
22075 -- declaration point and need to wait for the expansion of the
22076 -- initialization procedure, which will pass in the list to put
22077 -- them on; otherwise, the checks are done at the declaration
22078 -- point and there is no need to do them again in the
22079 -- initialization procedure.
22081 elsif Nkind
(Insert_Node
) in N_Declaration
then
22082 Def_Id
:= Defining_Identifier
(Insert_Node
);
22084 if (Ekind
(Def_Id
) = E_Record_Type
22085 and then Depends_On_Discriminant
(R
))
22087 (Ekind
(Def_Id
) = E_Protected_Type
22088 and then Has_Discriminants
(Def_Id
))
22090 if Present
(Check_List
) then
22091 Append_Range_Checks
22093 Check_List
, Def_Id
, Sloc
(Insert_Node
));
22097 if No
(Check_List
) then
22098 Insert_Range_Checks
22100 Insert_Node
, Def_Id
, Sloc
(Insert_Node
));
22104 -- Case of statements. Drop the checks, as the range appears in
22105 -- the context of a quantified expression. Insertion will take
22106 -- place when expression is expanded.
22113 -- Case of other than an explicit N_Range node
22115 -- The forced evaluation removes side effects from expressions, which
22116 -- should occur also in GNATprove mode. Otherwise, we end up with
22117 -- unexpected insertions of actions at places where this is not
22118 -- supposed to occur, e.g. on default parameters of a call.
22120 elsif Expander_Active
or GNATprove_Mode
then
22121 Get_Index_Bounds
(R
, Lo
, Hi
);
22122 Force_Evaluation
(Lo
);
22123 Force_Evaluation
(Hi
);
22125 end Process_Range_Expr_In_Decl
;
22127 --------------------------------------
22128 -- Process_Real_Range_Specification --
22129 --------------------------------------
22131 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
22132 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
22135 Err
: Boolean := False;
22137 procedure Analyze_Bound
(N
: Node_Id
);
22138 -- Analyze and check one bound
22140 -------------------
22141 -- Analyze_Bound --
22142 -------------------
22144 procedure Analyze_Bound
(N
: Node_Id
) is
22146 Analyze_And_Resolve
(N
, Any_Real
);
22148 if not Is_OK_Static_Expression
(N
) then
22149 Flag_Non_Static_Expr
22150 ("bound in real type definition is not static!", N
);
22155 -- Start of processing for Process_Real_Range_Specification
22158 if Present
(Spec
) then
22159 Lo
:= Low_Bound
(Spec
);
22160 Hi
:= High_Bound
(Spec
);
22161 Analyze_Bound
(Lo
);
22162 Analyze_Bound
(Hi
);
22164 -- If error, clear away junk range specification
22167 Set_Real_Range_Specification
(Def
, Empty
);
22170 end Process_Real_Range_Specification
;
22172 ---------------------
22173 -- Process_Subtype --
22174 ---------------------
22176 function Process_Subtype
22178 Related_Nod
: Node_Id
;
22179 Related_Id
: Entity_Id
:= Empty
;
22180 Suffix
: Character := ' ') return Entity_Id
22182 procedure Check_Incomplete
(T
: Node_Id
);
22183 -- Called to verify that an incomplete type is not used prematurely
22185 ----------------------
22186 -- Check_Incomplete --
22187 ----------------------
22189 procedure Check_Incomplete
(T
: Node_Id
) is
22191 -- Ada 2005 (AI-412): Incomplete subtypes are legal
22193 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
22195 not (Ada_Version
>= Ada_2005
22197 (Nkind
(Parent
(T
)) = N_Subtype_Declaration
22198 or else (Nkind
(Parent
(T
)) = N_Subtype_Indication
22199 and then Nkind
(Parent
(Parent
(T
))) =
22200 N_Subtype_Declaration
)))
22202 Error_Msg_N
("invalid use of type before its full declaration", T
);
22204 end Check_Incomplete
;
22209 Def_Id
: Entity_Id
;
22210 Error_Node
: Node_Id
;
22211 Full_View_Id
: Entity_Id
;
22212 Subtype_Mark_Id
: Entity_Id
;
22214 May_Have_Null_Exclusion
: Boolean;
22216 -- Start of processing for Process_Subtype
22219 -- Case of no constraints present
22221 if Nkind
(S
) /= N_Subtype_Indication
then
22224 -- No way to proceed if the subtype indication is malformed. This
22225 -- will happen for example when the subtype indication in an object
22226 -- declaration is missing altogether and the expression is analyzed
22227 -- as if it were that indication.
22229 if not Is_Entity_Name
(S
) then
22233 Check_Incomplete
(S
);
22236 -- The following mirroring of assertion in Null_Exclusion_Present is
22237 -- ugly, can't we have a range, a static predicate or even a flag???
22239 May_Have_Null_Exclusion
:=
22242 Nkind
(P
) in N_Access_Definition
22243 | N_Access_Function_Definition
22244 | N_Access_Procedure_Definition
22245 | N_Access_To_Object_Definition
22247 | N_Component_Definition
22248 | N_Derived_Type_Definition
22249 | N_Discriminant_Specification
22250 | N_Formal_Object_Declaration
22251 | N_Function_Specification
22252 | N_Object_Declaration
22253 | N_Object_Renaming_Declaration
22254 | N_Parameter_Specification
22255 | N_Subtype_Declaration
;
22257 -- Ada 2005 (AI-231): Static check
22259 if Ada_Version
>= Ada_2005
22260 and then May_Have_Null_Exclusion
22261 and then Null_Exclusion_Present
(P
)
22262 and then Nkind
(P
) /= N_Access_To_Object_Definition
22263 and then not Is_Access_Type
(Entity
(S
))
22265 Error_Msg_N
("`NOT NULL` only allowed for an access type", S
);
22268 -- Create an Itype that is a duplicate of Entity (S) but with the
22269 -- null-exclusion attribute.
22271 if May_Have_Null_Exclusion
22272 and then Is_Access_Type
(Entity
(S
))
22273 and then Null_Exclusion_Present
(P
)
22275 -- No need to check the case of an access to object definition.
22276 -- It is correct to define double not-null pointers.
22279 -- type Not_Null_Int_Ptr is not null access Integer;
22280 -- type Acc is not null access Not_Null_Int_Ptr;
22282 and then Nkind
(P
) /= N_Access_To_Object_Definition
22284 if Can_Never_Be_Null
(Entity
(S
)) then
22285 case Nkind
(Related_Nod
) is
22286 when N_Full_Type_Declaration
=>
22287 if Nkind
(Type_Definition
(Related_Nod
))
22288 in N_Array_Type_Definition
22292 (Component_Definition
22293 (Type_Definition
(Related_Nod
)));
22296 Subtype_Indication
(Type_Definition
(Related_Nod
));
22299 when N_Subtype_Declaration
=>
22300 Error_Node
:= Subtype_Indication
(Related_Nod
);
22302 when N_Object_Declaration
=>
22303 Error_Node
:= Object_Definition
(Related_Nod
);
22305 when N_Component_Declaration
=>
22307 Subtype_Indication
(Component_Definition
(Related_Nod
));
22309 when N_Allocator
=>
22310 Error_Node
:= Expression
(Related_Nod
);
22313 pragma Assert
(False);
22314 Error_Node
:= Related_Nod
;
22318 ("`NOT NULL` not allowed (& already excludes null)",
22324 Create_Null_Excluding_Itype
22326 Related_Nod
=> P
));
22327 Set_Entity
(S
, Etype
(S
));
22332 -- Case of constraint present, so that we have an N_Subtype_Indication
22333 -- node (this node is created only if constraints are present).
22336 Find_Type
(Subtype_Mark
(S
));
22338 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
22340 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
22341 and then Is_Itype
(Defining_Identifier
(Parent
(S
))))
22343 Check_Incomplete
(Subtype_Mark
(S
));
22347 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
22349 -- Explicit subtype declaration case
22351 if Nkind
(P
) = N_Subtype_Declaration
then
22352 Def_Id
:= Defining_Identifier
(P
);
22354 -- Explicit derived type definition case
22356 elsif Nkind
(P
) = N_Derived_Type_Definition
then
22357 Def_Id
:= Defining_Identifier
(Parent
(P
));
22359 -- Implicit case, the Def_Id must be created as an implicit type.
22360 -- The one exception arises in the case of concurrent types, array
22361 -- and access types, where other subsidiary implicit types may be
22362 -- created and must appear before the main implicit type. In these
22363 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
22364 -- has not yet been called to create Def_Id.
22367 if Is_Array_Type
(Subtype_Mark_Id
)
22368 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
22369 or else Is_Access_Type
(Subtype_Mark_Id
)
22373 -- For the other cases, we create a new unattached Itype,
22374 -- and set the indication to ensure it gets attached later.
22378 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22382 -- If the kind of constraint is invalid for this kind of type,
22383 -- then give an error, and then pretend no constraint was given.
22385 if not Is_Valid_Constraint_Kind
22386 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
22389 ("incorrect constraint for this kind of type", Constraint
(S
));
22391 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
22393 -- Set Ekind of orphan itype, to prevent cascaded errors
22395 if Present
(Def_Id
) then
22396 Mutate_Ekind
(Def_Id
, Ekind
(Any_Type
));
22399 -- Make recursive call, having got rid of the bogus constraint
22401 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
22404 -- Remaining processing depends on type. Select on Base_Type kind to
22405 -- ensure getting to the concrete type kind in the case of a private
22406 -- subtype (needed when only doing semantic analysis).
22408 case Ekind
(Base_Type
(Subtype_Mark_Id
)) is
22409 when Access_Kind
=>
22411 -- If this is a constraint on a class-wide type, discard it.
22412 -- There is currently no way to express a partial discriminant
22413 -- constraint on a type with unknown discriminants. This is
22414 -- a pathology that the ACATS wisely decides not to test.
22416 if Is_Class_Wide_Type
(Designated_Type
(Subtype_Mark_Id
)) then
22417 if Comes_From_Source
(S
) then
22419 ("constraint on class-wide type ignored??",
22423 if Nkind
(P
) = N_Subtype_Declaration
then
22424 Set_Subtype_Indication
(P
,
22425 New_Occurrence_Of
(Subtype_Mark_Id
, Sloc
(S
)));
22428 return Subtype_Mark_Id
;
22431 Constrain_Access
(Def_Id
, S
, Related_Nod
);
22434 and then Is_Itype
(Designated_Type
(Def_Id
))
22435 and then Nkind
(Related_Nod
) = N_Subtype_Declaration
22436 and then not Is_Incomplete_Type
(Designated_Type
(Def_Id
))
22438 Build_Itype_Reference
22439 (Designated_Type
(Def_Id
), Related_Nod
);
22443 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22445 when Decimal_Fixed_Point_Kind
=>
22446 Constrain_Decimal
(Def_Id
, S
);
22448 when Enumeration_Kind
=>
22449 Constrain_Enumeration
(Def_Id
, S
);
22451 when Ordinary_Fixed_Point_Kind
=>
22452 Constrain_Ordinary_Fixed
(Def_Id
, S
);
22455 Constrain_Float
(Def_Id
, S
);
22457 when Integer_Kind
=>
22458 Constrain_Integer
(Def_Id
, S
);
22460 when Class_Wide_Kind
22461 | E_Incomplete_Type
22465 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22467 if Ekind
(Def_Id
) = E_Incomplete_Type
then
22468 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22471 when Private_Kind
=>
22473 -- A private type with unknown discriminants may be completed
22474 -- by an unconstrained array type.
22476 if Has_Unknown_Discriminants
(Subtype_Mark_Id
)
22477 and then Present
(Full_View
(Subtype_Mark_Id
))
22478 and then Is_Array_Type
(Full_View
(Subtype_Mark_Id
))
22480 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22482 -- ... but more commonly is completed by a discriminated record
22486 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22489 -- The base type may be private but Def_Id may be a full view
22492 if Is_Private_Type
(Def_Id
) then
22493 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22496 -- In case of an invalid constraint prevent further processing
22497 -- since the type constructed is missing expected fields.
22499 if Etype
(Def_Id
) = Any_Type
then
22503 -- If the full view is that of a task with discriminants,
22504 -- we must constrain both the concurrent type and its
22505 -- corresponding record type. Otherwise we will just propagate
22506 -- the constraint to the full view, if available.
22508 if Present
(Full_View
(Subtype_Mark_Id
))
22509 and then Has_Discriminants
(Subtype_Mark_Id
)
22510 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
22513 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22515 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
22516 Constrain_Concurrent
(Full_View_Id
, S
,
22517 Related_Nod
, Related_Id
, Suffix
);
22518 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
22519 Set_Full_View
(Def_Id
, Full_View_Id
);
22521 -- Introduce an explicit reference to the private subtype,
22522 -- to prevent scope anomalies in gigi if first use appears
22523 -- in a nested context, e.g. a later function body.
22524 -- Should this be generated in other contexts than a full
22525 -- type declaration?
22527 if Is_Itype
(Def_Id
)
22529 Nkind
(Parent
(P
)) = N_Full_Type_Declaration
22531 Build_Itype_Reference
(Def_Id
, Parent
(P
));
22535 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
22538 when Concurrent_Kind
=>
22539 Constrain_Concurrent
(Def_Id
, S
,
22540 Related_Nod
, Related_Id
, Suffix
);
22543 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
22546 -- Size, Alignment, Representation aspects and Convention are always
22547 -- inherited from the base type.
22549 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
22550 Set_Rep_Info
(Def_Id
, (Subtype_Mark_Id
));
22551 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
22553 -- The anonymous subtype created for the subtype indication
22554 -- inherits the predicates of the parent.
22556 if Has_Predicates
(Subtype_Mark_Id
) then
22557 Inherit_Predicate_Flags
(Def_Id
, Subtype_Mark_Id
);
22559 -- Indicate where the predicate function may be found
22561 if No
(Predicate_Function
(Def_Id
)) and then Is_Itype
(Def_Id
) then
22562 Set_Predicated_Parent
(Def_Id
, Subtype_Mark_Id
);
22568 end Process_Subtype
;
22570 -----------------------------
22571 -- Record_Type_Declaration --
22572 -----------------------------
22574 procedure Record_Type_Declaration
22579 Def
: constant Node_Id
:= Type_Definition
(N
);
22580 Is_Tagged
: Boolean;
22581 Tag_Comp
: Entity_Id
;
22584 -- These flags must be initialized before calling Process_Discriminants
22585 -- because this routine makes use of them.
22587 Mutate_Ekind
(T
, E_Record_Type
);
22589 Reinit_Size_Align
(T
);
22590 Set_Interfaces
(T
, No_Elist
);
22591 Set_Stored_Constraint
(T
, No_Elist
);
22592 Set_Default_SSO
(T
);
22593 Set_No_Reordering
(T
, No_Component_Reordering
);
22597 if Ada_Version
< Ada_2005
or else not Interface_Present
(Def
) then
22598 -- The flag Is_Tagged_Type might have already been set by
22599 -- Find_Type_Name if it detected an error for declaration T. This
22600 -- arises in the case of private tagged types where the full view
22601 -- omits the word tagged.
22604 Tagged_Present
(Def
)
22605 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
22607 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
22610 Set_Is_Tagged_Type
(T
, True);
22611 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
22614 -- Type is abstract if full declaration carries keyword, or if
22615 -- previous partial view did.
22617 Set_Is_Abstract_Type
(T
, Is_Abstract_Type
(T
)
22618 or else Abstract_Present
(Def
));
22622 Analyze_Interface_Declaration
(T
, Def
);
22624 if Present
(Discriminant_Specifications
(N
)) then
22626 ("interface types cannot have discriminants",
22627 Defining_Identifier
22628 (First
(Discriminant_Specifications
(N
))));
22632 -- First pass: if there are self-referential access components,
22633 -- create the required anonymous access type declarations, and if
22634 -- need be an incomplete type declaration for T itself.
22636 Check_Anonymous_Access_Components
(N
, T
, Prev
, Component_List
(Def
));
22638 if Ada_Version
>= Ada_2005
22639 and then Present
(Interface_List
(Def
))
22641 Check_Interfaces
(N
, Def
);
22644 Ifaces_List
: Elist_Id
;
22647 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
22648 -- already in the parents.
22652 Ifaces_List
=> Ifaces_List
,
22653 Exclude_Parents
=> True);
22655 Set_Interfaces
(T
, Ifaces_List
);
22659 -- Records constitute a scope for the component declarations within.
22660 -- The scope is created prior to the processing of these declarations.
22661 -- Discriminants are processed first, so that they are visible when
22662 -- processing the other components. The Ekind of the record type itself
22663 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
22665 -- Enter record scope
22669 -- If an incomplete or private type declaration was already given for
22670 -- the type, then this scope already exists, and the discriminants have
22671 -- been declared within. We must verify that the full declaration
22672 -- matches the incomplete one.
22674 Check_Or_Process_Discriminants
(N
, T
, Prev
);
22676 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
22677 Set_Has_Delayed_Freeze
(T
, True);
22679 -- For tagged types add a manually analyzed component corresponding
22680 -- to the component _tag, the corresponding piece of tree will be
22681 -- expanded as part of the freezing actions if it is not a CPP_Class.
22685 -- Do not add the tag unless we are in expansion mode
22687 if Expander_Active
then
22688 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
22689 Enter_Name
(Tag_Comp
);
22691 Mutate_Ekind
(Tag_Comp
, E_Component
);
22692 Set_Is_Tag
(Tag_Comp
);
22693 Set_Is_Aliased
(Tag_Comp
);
22694 Set_Is_Independent
(Tag_Comp
);
22695 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
22696 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
22697 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
22698 Reinit_Component_Location
(Tag_Comp
);
22700 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
22701 -- implemented interfaces.
22703 if Has_Interfaces
(T
) then
22704 Add_Interface_Tag_Components
(N
, T
);
22708 Make_Class_Wide_Type
(T
);
22709 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
22712 -- We must suppress range checks when processing record components in
22713 -- the presence of discriminants, since we don't want spurious checks to
22714 -- be generated during their analysis, but Suppress_Range_Checks flags
22715 -- must be reset the after processing the record definition.
22717 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
22718 -- couldn't we just use the normal range check suppression method here.
22719 -- That would seem cleaner ???
22721 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
22722 Set_Kill_Range_Checks
(T
, True);
22723 Record_Type_Definition
(Def
, Prev
);
22724 Set_Kill_Range_Checks
(T
, False);
22726 Record_Type_Definition
(Def
, Prev
);
22729 -- Exit from record scope
22733 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
22734 -- the implemented interfaces and associate them an aliased entity.
22737 and then not Is_Empty_List
(Interface_List
(Def
))
22739 Derive_Progenitor_Subprograms
(T
, T
);
22742 Check_Function_Writable_Actuals
(N
);
22743 end Record_Type_Declaration
;
22745 ----------------------------
22746 -- Record_Type_Definition --
22747 ----------------------------
22749 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
22750 Component
: Entity_Id
;
22751 Ctrl_Components
: Boolean := False;
22752 Final_Storage_Only
: Boolean;
22756 if Ekind
(Prev_T
) = E_Incomplete_Type
then
22757 T
:= Full_View
(Prev_T
);
22762 Final_Storage_Only
:= not Is_Controlled
(T
);
22764 -- Ada 2005: Check whether an explicit "limited" is present in a derived
22765 -- type declaration.
22767 if Parent_Kind
(Def
) = N_Derived_Type_Definition
22768 and then Limited_Present
(Parent
(Def
))
22770 Set_Is_Limited_Record
(T
);
22773 -- If the component list of a record type is defined by the reserved
22774 -- word null and there is no discriminant part, then the record type has
22775 -- no components and all records of the type are null records (RM 3.7)
22776 -- This procedure is also called to process the extension part of a
22777 -- record extension, in which case the current scope may have inherited
22781 and then Present
(Component_List
(Def
))
22782 and then not Null_Present
(Component_List
(Def
))
22784 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
22786 if Present
(Variant_Part
(Component_List
(Def
))) then
22787 Analyze
(Variant_Part
(Component_List
(Def
)));
22791 -- After completing the semantic analysis of the record definition,
22792 -- record components, both new and inherited, are accessible. Set their
22793 -- kind accordingly. Exclude malformed itypes from illegal declarations,
22794 -- whose Ekind may be void.
22796 Component
:= First_Entity
(Current_Scope
);
22797 while Present
(Component
) loop
22798 if Ekind
(Component
) = E_Void
22799 and then not Is_Itype
(Component
)
22801 Mutate_Ekind
(Component
, E_Component
);
22802 Reinit_Component_Location
(Component
);
22805 Propagate_Concurrent_Flags
(T
, Etype
(Component
));
22807 if Ekind
(Component
) /= E_Component
then
22810 -- Do not set Has_Controlled_Component on a class-wide equivalent
22811 -- type. See Make_CW_Equivalent_Type.
22813 elsif not Is_Class_Wide_Equivalent_Type
(T
)
22814 and then (Has_Controlled_Component
(Etype
(Component
))
22815 or else (Chars
(Component
) /= Name_uParent
22816 and then Is_Controlled
(Etype
(Component
))))
22818 Set_Has_Controlled_Component
(T
, True);
22819 Final_Storage_Only
:=
22821 and then Finalize_Storage_Only
(Etype
(Component
));
22822 Ctrl_Components
:= True;
22825 Next_Entity
(Component
);
22828 -- A Type is Finalize_Storage_Only only if all its controlled components
22831 if Ctrl_Components
then
22832 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
22835 -- Place reference to end record on the proper entity, which may
22836 -- be a partial view.
22838 if Present
(Def
) then
22839 Process_End_Label
(Def
, 'e', Prev_T
);
22841 end Record_Type_Definition
;
22843 ---------------------------
22844 -- Replace_Discriminants --
22845 ---------------------------
22847 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
) is
22848 function Process
(N
: Node_Id
) return Traverse_Result
;
22854 function Process
(N
: Node_Id
) return Traverse_Result
is
22858 if Nkind
(N
) = N_Discriminant_Specification
then
22859 Comp
:= First_Discriminant
(Typ
);
22860 while Present
(Comp
) loop
22861 if Original_Record_Component
(Comp
) = Defining_Identifier
(N
)
22862 or else Chars
(Comp
) = Chars
(Defining_Identifier
(N
))
22864 Set_Defining_Identifier
(N
, Comp
);
22868 Next_Discriminant
(Comp
);
22871 elsif Nkind
(N
) = N_Variant_Part
then
22872 Comp
:= First_Discriminant
(Typ
);
22873 while Present
(Comp
) loop
22874 if Original_Record_Component
(Comp
) = Entity
(Name
(N
))
22875 or else Chars
(Comp
) = Chars
(Name
(N
))
22877 -- Make sure to preserve the type coming from the parent on
22878 -- the Name, even if the subtype of the discriminant can be
22879 -- constrained, so that discrete choices inherited from the
22880 -- parent in the variant part are not flagged as violating
22881 -- the constraints of the subtype.
22884 Typ
: constant Entity_Id
:= Etype
(Name
(N
));
22886 Rewrite
(Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
22887 Set_Etype
(Name
(N
), Typ
);
22892 Next_Discriminant
(Comp
);
22899 procedure Replace
is new Traverse_Proc
(Process
);
22901 -- Start of processing for Replace_Discriminants
22905 end Replace_Discriminants
;
22907 -------------------------------
22908 -- Set_Completion_Referenced --
22909 -------------------------------
22911 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
22913 -- If in main unit, mark entity that is a completion as referenced,
22914 -- warnings go on the partial view when needed.
22916 if In_Extended_Main_Source_Unit
(E
) then
22917 Set_Referenced
(E
);
22919 end Set_Completion_Referenced
;
22921 ---------------------
22922 -- Set_Default_SSO --
22923 ---------------------
22925 procedure Set_Default_SSO
(T
: Entity_Id
) is
22927 case Opt
.Default_SSO
is
22931 Set_SSO_Set_Low_By_Default
(T
, True);
22933 Set_SSO_Set_High_By_Default
(T
, True);
22935 raise Program_Error
;
22937 end Set_Default_SSO
;
22939 ---------------------
22940 -- Set_Fixed_Range --
22941 ---------------------
22943 -- The range for fixed-point types is complicated by the fact that we
22944 -- do not know the exact end points at the time of the declaration. This
22945 -- is true for three reasons:
22947 -- A size clause may affect the fudging of the end-points.
22948 -- A small clause may affect the values of the end-points.
22949 -- We try to include the end-points if it does not affect the size.
22951 -- This means that the actual end-points must be established at the
22952 -- point when the type is frozen. Meanwhile, we first narrow the range
22953 -- as permitted (so that it will fit if necessary in a small specified
22954 -- size), and then build a range subtree with these narrowed bounds.
22955 -- Set_Fixed_Range constructs the range from real literal values, and
22956 -- sets the range as the Scalar_Range of the given fixed-point type entity.
22958 -- The parent of this range is set to point to the entity so that it is
22959 -- properly hooked into the tree (unlike normal Scalar_Range entries for
22960 -- other scalar types, which are just pointers to the range in the
22961 -- original tree, this would otherwise be an orphan).
22963 -- The tree is left unanalyzed. When the type is frozen, the processing
22964 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
22965 -- analyzed, and uses this as an indication that it should complete
22966 -- work on the range (it will know the final small and size values).
22968 procedure Set_Fixed_Range
22974 S
: constant Node_Id
:=
22976 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
22977 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
22979 Set_Scalar_Range
(E
, S
);
22982 -- Before the freeze point, the bounds of a fixed point are universal
22983 -- and carry the corresponding type.
22985 Set_Etype
(Low_Bound
(S
), Universal_Real
);
22986 Set_Etype
(High_Bound
(S
), Universal_Real
);
22987 end Set_Fixed_Range
;
22989 ----------------------------------
22990 -- Set_Scalar_Range_For_Subtype --
22991 ----------------------------------
22993 procedure Set_Scalar_Range_For_Subtype
22994 (Def_Id
: Entity_Id
;
22998 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
23001 -- Defend against previous error
23003 if Nkind
(R
) = N_Error
then
23007 Set_Scalar_Range
(Def_Id
, R
);
23009 -- We need to link the range into the tree before resolving it so
23010 -- that types that are referenced, including importantly the subtype
23011 -- itself, are properly frozen (Freeze_Expression requires that the
23012 -- expression be properly linked into the tree). Of course if it is
23013 -- already linked in, then we do not disturb the current link.
23015 if No
(Parent
(R
)) then
23016 Set_Parent
(R
, Def_Id
);
23019 -- Reset the kind of the subtype during analysis of the range, to
23020 -- catch possible premature use in the bounds themselves.
23022 Mutate_Ekind
(Def_Id
, E_Void
);
23023 Process_Range_Expr_In_Decl
(R
, Subt
, Subtyp
=> Def_Id
);
23024 Mutate_Ekind
(Def_Id
, Kind
);
23025 end Set_Scalar_Range_For_Subtype
;
23027 --------------------------------------------------------
23028 -- Set_Stored_Constraint_From_Discriminant_Constraint --
23029 --------------------------------------------------------
23031 procedure Set_Stored_Constraint_From_Discriminant_Constraint
23035 -- Make sure set if encountered during Expand_To_Stored_Constraint
23037 Set_Stored_Constraint
(E
, No_Elist
);
23039 -- Give it the right value
23041 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
23042 Set_Stored_Constraint
(E
,
23043 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
23045 end Set_Stored_Constraint_From_Discriminant_Constraint
;
23047 -------------------------------------
23048 -- Signed_Integer_Type_Declaration --
23049 -------------------------------------
23051 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
23052 Implicit_Base
: Entity_Id
;
23053 Base_Typ
: Entity_Id
;
23056 Errs
: Boolean := False;
23060 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
23061 -- Determine whether given bounds allow derivation from specified type
23063 procedure Check_Bound
(Expr
: Node_Id
);
23064 -- Check bound to make sure it is integral and static. If not, post
23065 -- appropriate error message and set Errs flag
23067 ---------------------
23068 -- Can_Derive_From --
23069 ---------------------
23071 -- Note we check both bounds against both end values, to deal with
23072 -- strange types like ones with a range of 0 .. -12341234.
23074 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
23075 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
23076 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
23078 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
23080 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
23081 end Can_Derive_From
;
23087 procedure Check_Bound
(Expr
: Node_Id
) is
23089 -- If a range constraint is used as an integer type definition, each
23090 -- bound of the range must be defined by a static expression of some
23091 -- integer type, but the two bounds need not have the same integer
23092 -- type (Negative bounds are allowed.) (RM 3.5.4)
23094 if not Is_Integer_Type
(Etype
(Expr
)) then
23096 ("integer type definition bounds must be of integer type", Expr
);
23099 elsif not Is_OK_Static_Expression
(Expr
) then
23100 Flag_Non_Static_Expr
23101 ("non-static expression used for integer type bound!", Expr
);
23104 -- Otherwise the bounds are folded into literals
23106 elsif Is_Entity_Name
(Expr
) then
23107 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
23111 -- Start of processing for Signed_Integer_Type_Declaration
23114 -- Create an anonymous base type
23117 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
23119 -- Analyze and check the bounds, they can be of any integer type
23121 Lo
:= Low_Bound
(Def
);
23122 Hi
:= High_Bound
(Def
);
23124 -- Arbitrarily use Integer as the type if either bound had an error
23126 if Hi
= Error
or else Lo
= Error
then
23127 Base_Typ
:= Any_Integer
;
23128 Set_Error_Posted
(T
, True);
23131 -- Here both bounds are OK expressions
23134 Analyze_And_Resolve
(Lo
, Any_Integer
);
23135 Analyze_And_Resolve
(Hi
, Any_Integer
);
23141 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
23142 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
23145 -- Find type to derive from
23147 Lo_Val
:= Expr_Value
(Lo
);
23148 Hi_Val
:= Expr_Value
(Hi
);
23150 if Can_Derive_From
(Standard_Short_Short_Integer
) then
23151 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
23153 elsif Can_Derive_From
(Standard_Short_Integer
) then
23154 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
23156 elsif Can_Derive_From
(Standard_Integer
) then
23157 Base_Typ
:= Base_Type
(Standard_Integer
);
23159 elsif Can_Derive_From
(Standard_Long_Integer
) then
23160 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
23162 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
23163 Check_Restriction
(No_Long_Long_Integers
, Def
);
23164 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
23166 elsif Can_Derive_From
(Standard_Long_Long_Long_Integer
) then
23167 Check_Restriction
(No_Long_Long_Integers
, Def
);
23168 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
23171 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
23172 Error_Msg_N
("integer type definition bounds out of range", Def
);
23173 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
23174 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
23178 -- Set the type of the bounds to the implicit base: we cannot set it to
23179 -- the new type, because this would be a forward reference for the code
23180 -- generator and, if the original type is user-defined, this could even
23181 -- lead to spurious semantic errors. Furthermore we do not set it to be
23182 -- universal, because this could make it much larger than needed here.
23185 Set_Etype
(Lo
, Implicit_Base
);
23186 Set_Etype
(Hi
, Implicit_Base
);
23189 -- Complete both implicit base and declared first subtype entities. The
23190 -- inheritance of the rep item chain ensures that SPARK-related pragmas
23191 -- are not clobbered when the signed integer type acts as a full view of
23194 Set_Etype
(Implicit_Base
, Base_Typ
);
23195 Set_Size_Info
(Implicit_Base
, Base_Typ
);
23196 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
23197 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
23198 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
23200 Mutate_Ekind
(T
, E_Signed_Integer_Subtype
);
23201 Set_Etype
(T
, Implicit_Base
);
23202 Set_Size_Info
(T
, Implicit_Base
);
23203 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
23204 Set_Scalar_Range
(T
, Def
);
23205 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
23206 Set_Is_Constrained
(T
);
23207 end Signed_Integer_Type_Declaration
;