1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2021, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Elists
; use Elists
;
32 with Einfo
; use Einfo
;
33 with Einfo
.Entities
; use Einfo
.Entities
;
34 with Einfo
.Utils
; use Einfo
.Utils
;
35 with Errout
; use Errout
;
36 with Eval_Fat
; use Eval_Fat
;
37 with Exp_Ch3
; use Exp_Ch3
;
38 with Exp_Ch9
; use Exp_Ch9
;
39 with Exp_Disp
; use Exp_Disp
;
40 with Exp_Dist
; use Exp_Dist
;
41 with Exp_Tss
; use Exp_Tss
;
42 with Exp_Util
; use Exp_Util
;
43 with Freeze
; use Freeze
;
44 with Ghost
; use Ghost
;
45 with Itypes
; use Itypes
;
46 with Layout
; use Layout
;
48 with Lib
.Xref
; use Lib
.Xref
;
49 with Namet
; use Namet
;
50 with Nlists
; use Nlists
;
51 with Nmake
; use Nmake
;
53 with Restrict
; use Restrict
;
54 with Rident
; use Rident
;
55 with Rtsfind
; use Rtsfind
;
57 with Sem_Aux
; use Sem_Aux
;
58 with Sem_Case
; use Sem_Case
;
59 with Sem_Cat
; use Sem_Cat
;
60 with Sem_Ch6
; use Sem_Ch6
;
61 with Sem_Ch7
; use Sem_Ch7
;
62 with Sem_Ch8
; use Sem_Ch8
;
63 with Sem_Ch13
; use Sem_Ch13
;
64 with Sem_Dim
; use Sem_Dim
;
65 with Sem_Disp
; use Sem_Disp
;
66 with Sem_Dist
; use Sem_Dist
;
67 with Sem_Elab
; use Sem_Elab
;
68 with Sem_Elim
; use Sem_Elim
;
69 with Sem_Eval
; use Sem_Eval
;
70 with Sem_Mech
; use Sem_Mech
;
71 with Sem_Res
; use Sem_Res
;
72 with Sem_Smem
; use Sem_Smem
;
73 with Sem_Type
; use Sem_Type
;
74 with Sem_Util
; use Sem_Util
;
75 with Sem_Warn
; use Sem_Warn
;
76 with Stand
; use Stand
;
77 with Sinfo
; use Sinfo
;
78 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
79 with Sinfo
.Utils
; use Sinfo
.Utils
;
80 with Sinput
; use Sinput
;
81 with Snames
; use Snames
;
82 with Targparm
; use Targparm
;
83 with Tbuild
; use Tbuild
;
84 with Ttypes
; use Ttypes
;
85 with Uintp
; use Uintp
;
86 with Urealp
; use Urealp
;
88 package body Sem_Ch3
is
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
);
95 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
96 -- abstract interface types implemented by a record type or a derived
99 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
);
100 -- When an access-to-subprogram type has pre/postconditions, we build a
101 -- subprogram that includes these contracts and is invoked by an indirect
102 -- call through the corresponding access type.
104 procedure Build_Derived_Type
106 Parent_Type
: Entity_Id
;
107 Derived_Type
: Entity_Id
;
108 Is_Completion
: Boolean;
109 Derive_Subps
: Boolean := True);
110 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
111 -- the N_Full_Type_Declaration node containing the derived type definition.
112 -- Parent_Type is the entity for the parent type in the derived type
113 -- definition and Derived_Type the actual derived type. Is_Completion must
114 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
115 -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the
116 -- completion of a private type declaration. If Is_Completion is set to
117 -- True, N is the completion of a private type declaration and Derived_Type
118 -- is different from the defining identifier inside N (i.e. Derived_Type /=
119 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
120 -- subprograms should be derived. The only case where this parameter is
121 -- False is when Build_Derived_Type is recursively called to process an
122 -- implicit derived full type for a type derived from a private type (in
123 -- that case the subprograms must only be derived for the private view of
126 -- ??? These flags need a bit of re-examination and re-documentation:
127 -- ??? are they both necessary (both seem related to the recursion)?
129 procedure Build_Derived_Access_Type
131 Parent_Type
: Entity_Id
;
132 Derived_Type
: Entity_Id
);
133 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
134 -- create an implicit base if the parent type is constrained or if the
135 -- subtype indication has a constraint.
137 procedure Build_Derived_Array_Type
139 Parent_Type
: Entity_Id
;
140 Derived_Type
: Entity_Id
);
141 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
142 -- create an implicit base if the parent type is constrained or if the
143 -- subtype indication has a constraint.
145 procedure Build_Derived_Concurrent_Type
147 Parent_Type
: Entity_Id
;
148 Derived_Type
: Entity_Id
);
149 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
150 -- protected type, inherit entries and protected subprograms, check
151 -- legality of discriminant constraints if any.
153 procedure Build_Derived_Enumeration_Type
155 Parent_Type
: Entity_Id
;
156 Derived_Type
: Entity_Id
);
157 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
158 -- type, we must create a new list of literals. Types derived from
159 -- Character and [Wide_]Wide_Character are special-cased.
161 procedure Build_Derived_Numeric_Type
163 Parent_Type
: Entity_Id
;
164 Derived_Type
: Entity_Id
);
165 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
166 -- an anonymous base type, and propagate constraint to subtype if needed.
168 procedure Build_Derived_Private_Type
170 Parent_Type
: Entity_Id
;
171 Derived_Type
: Entity_Id
;
172 Is_Completion
: Boolean;
173 Derive_Subps
: Boolean := True);
174 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
175 -- because the parent may or may not have a completion, and the derivation
176 -- may itself be a completion.
178 procedure Build_Derived_Record_Type
180 Parent_Type
: Entity_Id
;
181 Derived_Type
: Entity_Id
;
182 Derive_Subps
: Boolean := True);
183 -- Subsidiary procedure used for tagged and untagged record types
184 -- by Build_Derived_Type and Analyze_Private_Extension_Declaration.
185 -- All parameters are as in Build_Derived_Type except that N, in
186 -- addition to being an N_Full_Type_Declaration node, can also be an
187 -- N_Private_Extension_Declaration node. See the definition of this routine
188 -- for much more info. Derive_Subps indicates whether subprograms should be
189 -- derived from the parent type. The only case where Derive_Subps is False
190 -- is for an implicit derived full type for a type derived from a private
191 -- type (see Build_Derived_Type).
193 procedure Build_Discriminal
(Discrim
: Entity_Id
);
194 -- Create the discriminal corresponding to discriminant Discrim, that is
195 -- the parameter corresponding to Discrim to be used in initialization
196 -- procedures for the type where Discrim is a discriminant. Discriminals
197 -- are not used during semantic analysis, and are not fully defined
198 -- entities until expansion. Thus they are not given a scope until
199 -- initialization procedures are built.
201 function Build_Discriminant_Constraints
204 Derived_Def
: Boolean := False) return Elist_Id
;
205 -- Validate discriminant constraints and return the list of the constraints
206 -- in order of discriminant declarations, where T is the discriminated
207 -- unconstrained type. Def is the N_Subtype_Indication node where the
208 -- discriminants constraints for T are specified. Derived_Def is True
209 -- when building the discriminant constraints in a derived type definition
210 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
211 -- type and Def is the constraint "(xxx)" on T and this routine sets the
212 -- Corresponding_Discriminant field of the discriminants in the derived
213 -- type D to point to the corresponding discriminants in the parent type T.
215 procedure Build_Discriminated_Subtype
219 Related_Nod
: Node_Id
;
220 For_Access
: Boolean := False);
221 -- Subsidiary procedure to Constrain_Discriminated_Type and to
222 -- Process_Incomplete_Dependents. Given
224 -- T (a possibly discriminated base type)
225 -- Def_Id (a very partially built subtype for T),
227 -- the call completes Def_Id to be the appropriate E_*_Subtype.
229 -- The Elist is the list of discriminant constraints if any (it is set
230 -- to No_Elist if T is not a discriminated type, and to an empty list if
231 -- T has discriminants but there are no discriminant constraints). The
232 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
233 -- The For_Access says whether or not this subtype is really constraining
236 function Build_Scalar_Bound
239 Der_T
: Entity_Id
) return Node_Id
;
240 -- The bounds of a derived scalar type are conversions of the bounds of
241 -- the parent type. Optimize the representation if the bounds are literals.
242 -- Needs a more complete spec--what are the parameters exactly, and what
243 -- exactly is the returned value, and how is Bound affected???
245 procedure Check_Access_Discriminant_Requires_Limited
248 -- Check the restriction that the type to which an access discriminant
249 -- belongs must be a concurrent type or a descendant of a type with
250 -- the reserved word 'limited' in its declaration.
252 procedure Check_Anonymous_Access_Component
257 Access_Def
: Node_Id
);
258 -- Ada 2005 AI-382: an access component in a record definition can refer to
259 -- the enclosing record, in which case it denotes the type itself, and not
260 -- the current instance of the type. We create an anonymous access type for
261 -- the component, and flag it as an access to a component, so accessibility
262 -- checks are properly performed on it. The declaration of the access type
263 -- is placed ahead of that of the record to prevent order-of-elaboration
264 -- circularity issues in Gigi. We create an incomplete type for the record
265 -- declaration, which is the designated type of the anonymous access.
267 procedure Check_Anonymous_Access_Components
271 Comp_List
: Node_Id
);
272 -- Call Check_Anonymous_Access_Component on Comp_List
274 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
);
275 -- Check that, if a new discriminant is used in a constraint defining the
276 -- parent subtype of a derivation, its subtype is statically compatible
277 -- with the subtype of the corresponding parent discriminant (RM 3.7(15)).
279 procedure Check_Delta_Expression
(E
: Node_Id
);
280 -- Check that the expression represented by E is suitable for use as a
281 -- delta expression, i.e. it is of real type and is static.
283 procedure Check_Digits_Expression
(E
: Node_Id
);
284 -- Check that the expression represented by E is suitable for use as a
285 -- digits expression, i.e. it is of integer type, positive and static.
287 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
);
288 -- Validate the initialization of an object declaration. T is the required
289 -- type, and Exp is the initialization expression.
291 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
);
292 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
294 procedure Check_Or_Process_Discriminants
297 Prev
: Entity_Id
:= Empty
);
298 -- If N is the full declaration of the completion T of an incomplete or
299 -- private type, check its discriminants (which are already known to be
300 -- conformant with those of the partial view, see Find_Type_Name),
301 -- otherwise process them. Prev is the entity of the partial declaration,
304 procedure Check_Real_Bound
(Bound
: Node_Id
);
305 -- Check given bound for being of real type and static. If not, post an
306 -- appropriate message, and rewrite the bound with the real literal zero.
308 procedure Constant_Redeclaration
312 -- Various checks on legality of full declaration of deferred constant.
313 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
314 -- node. The caller has not yet set any attributes of this entity.
316 function Contain_Interface
318 Ifaces
: Elist_Id
) return Boolean;
319 -- Ada 2005: Determine whether Iface is present in the list Ifaces
321 procedure Convert_Scalar_Bounds
323 Parent_Type
: Entity_Id
;
324 Derived_Type
: Entity_Id
;
326 -- For derived scalar types, convert the bounds in the type definition to
327 -- the derived type, and complete their analysis. Given a constraint of the
328 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
329 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
330 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
331 -- subtype are conversions of those bounds to the derived_type, so that
332 -- their typing is consistent.
334 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
);
335 -- Copies attributes from array base type T2 to array base type T1. Copies
336 -- only attributes that apply to base types, but not subtypes.
338 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
);
339 -- Copies attributes from array subtype T2 to array subtype T1. Copies
340 -- attributes that apply to both subtypes and base types.
342 procedure Create_Constrained_Components
346 Constraints
: Elist_Id
);
347 -- Build the list of entities for a constrained discriminated record
348 -- subtype. If a component depends on a discriminant, replace its subtype
349 -- using the discriminant values in the discriminant constraint. Subt
350 -- is the defining identifier for the subtype whose list of constrained
351 -- entities we will create. Decl_Node is the type declaration node where
352 -- we will attach all the itypes created. Typ is the base discriminated
353 -- type for the subtype Subt. Constraints is the list of discriminant
354 -- constraints for Typ.
356 function Constrain_Component_Type
358 Constrained_Typ
: Entity_Id
;
359 Related_Node
: Node_Id
;
361 Constraints
: Elist_Id
) return Entity_Id
;
362 -- Given a discriminated base type Typ, a list of discriminant constraints,
363 -- Constraints, for Typ and a component Comp of Typ, create and return the
364 -- type corresponding to Etype (Comp) where all discriminant references
365 -- are replaced with the corresponding constraint. If Etype (Comp) contains
366 -- no discriminant references then it is returned as-is. Constrained_Typ
367 -- is the final constrained subtype to which the constrained component
368 -- belongs. Related_Node is the node where we attach all created itypes.
370 procedure Constrain_Access
371 (Def_Id
: in out Entity_Id
;
373 Related_Nod
: Node_Id
);
374 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
375 -- an anonymous type created for a subtype indication. In that case it is
376 -- created in the procedure and attached to Related_Nod.
378 procedure Constrain_Array
379 (Def_Id
: in out Entity_Id
;
381 Related_Nod
: Node_Id
;
382 Related_Id
: Entity_Id
;
384 -- Apply a list of index constraints to an unconstrained array type. The
385 -- first parameter is the entity for the resulting subtype. A value of
386 -- Empty for Def_Id indicates that an implicit type must be created, but
387 -- creation is delayed (and must be done by this procedure) because other
388 -- subsidiary implicit types must be created first (which is why Def_Id
389 -- is an in/out parameter). The second parameter is a subtype indication
390 -- node for the constrained array to be created (e.g. something of the
391 -- form string (1 .. 10)). Related_Nod gives the place where this type
392 -- has to be inserted in the tree. The Related_Id and Suffix parameters
393 -- are used to build the associated Implicit type name.
395 procedure Constrain_Concurrent
396 (Def_Id
: in out Entity_Id
;
398 Related_Nod
: Node_Id
;
399 Related_Id
: Entity_Id
;
401 -- Apply list of discriminant constraints to an unconstrained concurrent
404 -- SI is the N_Subtype_Indication node containing the constraint and
405 -- the unconstrained type to constrain.
407 -- Def_Id is the entity for the resulting constrained subtype. A value
408 -- of Empty for Def_Id indicates that an implicit type must be created,
409 -- but creation is delayed (and must be done by this procedure) because
410 -- other subsidiary implicit types must be created first (which is why
411 -- Def_Id is an in/out parameter).
413 -- Related_Nod gives the place where this type has to be inserted
416 -- The last two arguments are used to create its external name if needed.
418 function Constrain_Corresponding_Record
419 (Prot_Subt
: Entity_Id
;
420 Corr_Rec
: Entity_Id
;
421 Related_Nod
: Node_Id
) return Entity_Id
;
422 -- When constraining a protected type or task type with discriminants,
423 -- constrain the corresponding record with the same discriminant values.
425 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
);
426 -- Constrain a decimal fixed point type with a digits constraint and/or a
427 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
429 procedure Constrain_Discriminated_Type
432 Related_Nod
: Node_Id
;
433 For_Access
: Boolean := False);
434 -- Process discriminant constraints of composite type. Verify that values
435 -- have been provided for all discriminants, that the original type is
436 -- unconstrained, and that the types of the supplied expressions match
437 -- the discriminant types. The first three parameters are like in routine
438 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
441 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
);
442 -- Constrain an enumeration type with a range constraint. This is identical
443 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
445 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
);
446 -- Constrain a floating point type with either a digits constraint
447 -- and/or a range constraint, building a E_Floating_Point_Subtype.
449 procedure Constrain_Index
452 Related_Nod
: Node_Id
;
453 Related_Id
: Entity_Id
;
456 -- Process an index constraint S in a constrained array declaration. The
457 -- constraint can be a subtype name, or a range with or without an explicit
458 -- subtype mark. The index is the corresponding index of the unconstrained
459 -- array. The Related_Id and Suffix parameters are used to build the
460 -- associated Implicit type name.
462 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
);
463 -- Build subtype of a signed or modular integer type
465 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
);
466 -- Constrain an ordinary fixed point type with a range constraint, and
467 -- build an E_Ordinary_Fixed_Point_Subtype entity.
469 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
);
470 -- Copy the Priv entity into the entity of its full declaration then swap
471 -- the two entities in such a manner that the former private type is now
472 -- seen as a full type.
474 procedure Decimal_Fixed_Point_Type_Declaration
477 -- Create a new decimal fixed point type, and apply the constraint to
478 -- obtain a subtype of this new type.
480 procedure Complete_Private_Subtype
483 Full_Base
: Entity_Id
;
484 Related_Nod
: Node_Id
);
485 -- Complete the implicit full view of a private subtype by setting the
486 -- appropriate semantic fields. If the full view of the parent is a record
487 -- type, build constrained components of subtype.
489 procedure Derive_Progenitor_Subprograms
490 (Parent_Type
: Entity_Id
;
491 Tagged_Type
: Entity_Id
);
492 -- Ada 2005 (AI-251): To complete type derivation, collect the primitive
493 -- operations of progenitors of Tagged_Type, and replace the subsidiary
494 -- subtypes with Tagged_Type, to build the specs of the inherited interface
495 -- primitives. The derived primitives are aliased to those of the
496 -- interface. This routine takes care also of transferring to the full view
497 -- subprograms associated with the partial view of Tagged_Type that cover
498 -- interface primitives.
500 procedure Derived_Standard_Character
502 Parent_Type
: Entity_Id
;
503 Derived_Type
: Entity_Id
);
504 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
505 -- derivations from types Standard.Character and Standard.Wide_Character.
507 procedure Derived_Type_Declaration
510 Is_Completion
: Boolean);
511 -- Process a derived type declaration. Build_Derived_Type is invoked
512 -- to process the actual derived type definition. Parameters N and
513 -- Is_Completion have the same meaning as in Build_Derived_Type.
514 -- T is the N_Defining_Identifier for the entity defined in the
515 -- N_Full_Type_Declaration node N, that is T is the derived type.
517 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
518 -- Insert each literal in symbol table, as an overloadable identifier. Each
519 -- enumeration type is mapped into a sequence of integers, and each literal
520 -- is defined as a constant with integer value. If any of the literals are
521 -- character literals, the type is a character type, which means that
522 -- strings are legal aggregates for arrays of components of the type.
524 function Expand_To_Stored_Constraint
526 Constraint
: Elist_Id
) return Elist_Id
;
527 -- Given a constraint (i.e. a list of expressions) on the discriminants of
528 -- Typ, expand it into a constraint on the stored discriminants and return
529 -- the new list of expressions constraining the stored discriminants.
531 function Find_Type_Of_Object
533 Related_Nod
: Node_Id
) return Entity_Id
;
534 -- Get type entity for object referenced by Obj_Def, attaching the implicit
535 -- types generated to Related_Nod.
537 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
538 -- Create a new float and apply the constraint to obtain subtype of it
540 function Has_Range_Constraint
(N
: Node_Id
) return Boolean;
541 -- Given an N_Subtype_Indication node N, return True if a range constraint
542 -- is present, either directly, or as part of a digits or delta constraint.
543 -- In addition, a digits constraint in the decimal case returns True, since
544 -- it establishes a default range if no explicit range is present.
546 function Inherit_Components
548 Parent_Base
: Entity_Id
;
549 Derived_Base
: Entity_Id
;
551 Inherit_Discr
: Boolean;
552 Discs
: Elist_Id
) return Elist_Id
;
553 -- Called from Build_Derived_Record_Type to inherit the components of
554 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
555 -- For more information on derived types and component inheritance please
556 -- consult the comment above the body of Build_Derived_Record_Type.
558 -- N is the original derived type declaration
560 -- Is_Tagged is set if we are dealing with tagged types
562 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
563 -- Parent_Base, otherwise no discriminants are inherited.
565 -- Discs gives the list of constraints that apply to Parent_Base in the
566 -- derived type declaration. If Discs is set to No_Elist, then we have
567 -- the following situation:
569 -- type Parent (D1..Dn : ..) is [tagged] record ...;
570 -- type Derived is new Parent [with ...];
572 -- which gets treated as
574 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
576 -- For untagged types the returned value is an association list. The list
577 -- starts from the association (Parent_Base => Derived_Base), and then it
578 -- contains a sequence of the associations of the form
580 -- (Old_Component => New_Component),
582 -- where Old_Component is the Entity_Id of a component in Parent_Base and
583 -- New_Component is the Entity_Id of the corresponding component in
584 -- Derived_Base. For untagged records, this association list is needed when
585 -- copying the record declaration for the derived base. In the tagged case
586 -- the value returned is irrelevant.
588 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean;
589 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
590 -- Determine whether subprogram Subp is a procedure subject to pragma
591 -- Extensions_Visible with value False and has at least one controlling
592 -- parameter of mode OUT.
594 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean;
595 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
596 -- When applied to a primitive subprogram Prim, returns True if Prim is
597 -- declared as a private operation within a package or generic package,
598 -- and returns False otherwise.
600 function Is_Valid_Constraint_Kind
602 Constraint_Kind
: Node_Kind
) return Boolean;
603 -- Returns True if it is legal to apply the given kind of constraint to the
604 -- given kind of type (index constraint to an array type, for example).
606 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
607 -- Create new modular type. Verify that modulus is in bounds
609 procedure New_Concatenation_Op
(Typ
: Entity_Id
);
610 -- Create an abbreviated declaration for an operator in order to
611 -- materialize concatenation on array types.
613 procedure Ordinary_Fixed_Point_Type_Declaration
616 -- Create a new ordinary fixed point type, and apply the constraint to
617 -- obtain subtype of it.
619 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
);
620 -- Wrapper on Preanalyze_Spec_Expression for default expressions, so that
621 -- In_Default_Expr can be properly adjusted.
623 procedure Prepare_Private_Subtype_Completion
625 Related_Nod
: Node_Id
);
626 -- Id is a subtype of some private type. Creates the full declaration
627 -- associated with Id whenever possible, i.e. when the full declaration
628 -- of the base type is already known. Records each subtype into
629 -- Private_Dependents of the base type.
631 procedure Process_Incomplete_Dependents
635 -- Process all entities that depend on an incomplete type. There include
636 -- subtypes, subprogram types that mention the incomplete type in their
637 -- profiles, and subprogram with access parameters that designate the
640 -- Inc_T is the defining identifier of an incomplete type declaration, its
641 -- Ekind is E_Incomplete_Type.
643 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
645 -- Full_T is N's defining identifier.
647 -- Subtypes of incomplete types with discriminants are completed when the
648 -- parent type is. This is simpler than private subtypes, because they can
649 -- only appear in the same scope, and there is no need to exchange views.
650 -- Similarly, access_to_subprogram types may have a parameter or a return
651 -- type that is an incomplete type, and that must be replaced with the
654 -- If the full type is tagged, subprogram with access parameters that
655 -- designated the incomplete may be primitive operations of the full type,
656 -- and have to be processed accordingly.
658 procedure Process_Real_Range_Specification
(Def
: Node_Id
);
659 -- Given the type definition for a real type, this procedure processes and
660 -- checks the real range specification of this type definition if one is
661 -- present. If errors are found, error messages are posted, and the
662 -- Real_Range_Specification of Def is reset to Empty.
664 procedure Record_Type_Declaration
668 -- Process a record type declaration (for both untagged and tagged
669 -- records). Parameters T and N are exactly like in procedure
670 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
671 -- for this routine. If this is the completion of an incomplete type
672 -- declaration, Prev is the entity of the incomplete declaration, used for
673 -- cross-referencing. Otherwise Prev = T.
675 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
);
676 -- This routine is used to process the actual record type definition (both
677 -- for untagged and tagged records). Def is a record type definition node.
678 -- This procedure analyzes the components in this record type definition.
679 -- Prev_T is the entity for the enclosing record type. It is provided so
680 -- that its Has_Task flag can be set if any of the component have Has_Task
681 -- set. If the declaration is the completion of an incomplete type
682 -- declaration, Prev_T is the original incomplete type, whose full view is
685 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
);
686 -- Subsidiary to Build_Derived_Record_Type. For untagged record types, we
687 -- first create the list of components for the derived type from that of
688 -- the parent by means of Inherit_Components and then build a copy of the
689 -- declaration tree of the parent with the help of the mapping returned by
690 -- Inherit_Components, which will for example be used to validate record
691 -- representation clauses given for the derived type. If the parent type
692 -- is private and has discriminants, the ancestor discriminants used in the
693 -- inheritance are that of the private declaration, whereas the ancestor
694 -- discriminants present in the declaration tree of the parent are that of
695 -- the full declaration; as a consequence, the remapping done during the
696 -- copy will leave the references to the ancestor discriminants unchanged
697 -- in the declaration tree and they need to be fixed up. If the derived
698 -- type has a known discriminant part, then the remapping done during the
699 -- copy will only create references to the stored discriminants and they
700 -- need to be replaced with references to the non-stored discriminants.
702 procedure Set_Fixed_Range
707 -- Build a range node with the given bounds and set it as the Scalar_Range
708 -- of the given fixed-point type entity. Loc is the source location used
709 -- for the constructed range. See body for further details.
711 procedure Set_Scalar_Range_For_Subtype
715 -- This routine is used to set the scalar range field for a subtype given
716 -- Def_Id, the entity for the subtype, and R, the range expression for the
717 -- scalar range. Subt provides the parent subtype to be used to analyze,
718 -- resolve, and check the given range.
720 procedure Set_Default_SSO
(T
: Entity_Id
);
721 -- T is the entity for an array or record being declared. This procedure
722 -- sets the flags SSO_Set_Low_By_Default/SSO_Set_High_By_Default according
723 -- to the setting of Opt.Default_SSO.
725 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
726 -- Create a new signed integer entity, and apply the constraint to obtain
727 -- the required first named subtype of this type.
729 procedure Set_Stored_Constraint_From_Discriminant_Constraint
731 -- E is some record type. This routine computes E's Stored_Constraint
732 -- from its Discriminant_Constraint.
734 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
);
735 -- Check that an entity in a list of progenitors is an interface,
736 -- emit error otherwise.
738 -----------------------
739 -- Access_Definition --
740 -----------------------
742 function Access_Definition
743 (Related_Nod
: Node_Id
;
744 N
: Node_Id
) return Entity_Id
746 Anon_Type
: Entity_Id
;
747 Anon_Scope
: Entity_Id
;
748 Desig_Type
: Entity_Id
;
749 Enclosing_Prot_Type
: Entity_Id
:= Empty
;
752 if Is_Entry
(Current_Scope
)
753 and then Is_Task_Type
(Etype
(Scope
(Current_Scope
)))
755 Error_Msg_N
("task entries cannot have access parameters", N
);
759 -- Ada 2005: For an object declaration the corresponding anonymous
760 -- type is declared in the current scope.
762 -- If the access definition is the return type of another access to
763 -- function, scope is the current one, because it is the one of the
764 -- current type declaration, except for the pathological case below.
766 if Nkind
(Related_Nod
) in
767 N_Object_Declaration | N_Access_Function_Definition
769 Anon_Scope
:= Current_Scope
;
771 -- A pathological case: function returning access functions that
772 -- return access functions, etc. Each anonymous access type created
773 -- is in the enclosing scope of the outermost function.
781 N_Access_Function_Definition | N_Access_Definition
786 if Nkind
(Par
) = N_Function_Specification
then
787 Anon_Scope
:= Scope
(Defining_Entity
(Par
));
791 -- For the anonymous function result case, retrieve the scope of the
792 -- function specification's associated entity rather than using the
793 -- current scope. The current scope will be the function itself if the
794 -- formal part is currently being analyzed, but will be the parent scope
795 -- in the case of a parameterless function, and we always want to use
796 -- the function's parent scope. Finally, if the function is a child
797 -- unit, we must traverse the tree to retrieve the proper entity.
799 elsif Nkind
(Related_Nod
) = N_Function_Specification
800 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
802 -- If the current scope is a protected type, the anonymous access
803 -- is associated with one of the protected operations, and must
804 -- be available in the scope that encloses the protected declaration.
805 -- Otherwise the type is in the scope enclosing the subprogram.
807 -- If the function has formals, the return type of a subprogram
808 -- declaration is analyzed in the scope of the subprogram (see
809 -- Process_Formals) and thus the protected type, if present, is
810 -- the scope of the current function scope.
812 if Ekind
(Current_Scope
) = E_Protected_Type
then
813 Enclosing_Prot_Type
:= Current_Scope
;
815 elsif Ekind
(Current_Scope
) = E_Function
816 and then Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
818 Enclosing_Prot_Type
:= Scope
(Current_Scope
);
821 if Present
(Enclosing_Prot_Type
) then
822 Anon_Scope
:= Scope
(Enclosing_Prot_Type
);
825 Anon_Scope
:= Scope
(Defining_Entity
(Related_Nod
));
828 -- For an access type definition, if the current scope is a child
829 -- unit it is the scope of the type.
831 elsif Is_Compilation_Unit
(Current_Scope
) then
832 Anon_Scope
:= Current_Scope
;
834 -- For access formals, access components, and access discriminants, the
835 -- scope is that of the enclosing declaration,
838 Anon_Scope
:= Scope
(Current_Scope
);
843 (E_Anonymous_Access_Type
, Related_Nod
, Scope_Id
=> Anon_Scope
);
846 and then Ada_Version
>= Ada_2005
848 Error_Msg_N
("ALL not permitted for anonymous access types", N
);
851 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
852 -- the corresponding semantic routine
854 if Present
(Access_To_Subprogram_Definition
(N
)) then
855 Access_Subprogram_Declaration
856 (T_Name
=> Anon_Type
,
857 T_Def
=> Access_To_Subprogram_Definition
(N
));
859 if Ekind
(Anon_Type
) = E_Access_Protected_Subprogram_Type
then
861 (Anon_Type
, E_Anonymous_Access_Protected_Subprogram_Type
);
863 Mutate_Ekind
(Anon_Type
, E_Anonymous_Access_Subprogram_Type
);
866 Set_Can_Use_Internal_Rep
867 (Anon_Type
, not Always_Compatible_Rep_On_Target
);
869 -- If the anonymous access is associated with a protected operation,
870 -- create a reference to it after the enclosing protected definition
871 -- because the itype will be used in the subsequent bodies.
873 -- If the anonymous access itself is protected, a full type
874 -- declaratiton will be created for it, so that the equivalent
875 -- record type can be constructed. For further details, see
876 -- Replace_Anonymous_Access_To_Protected-Subprogram.
878 if Ekind
(Current_Scope
) = E_Protected_Type
879 and then not Protected_Present
(Access_To_Subprogram_Definition
(N
))
881 Build_Itype_Reference
(Anon_Type
, Parent
(Current_Scope
));
887 Find_Type
(Subtype_Mark
(N
));
888 Desig_Type
:= Entity
(Subtype_Mark
(N
));
890 Set_Directly_Designated_Type
(Anon_Type
, Desig_Type
);
891 Set_Etype
(Anon_Type
, Anon_Type
);
893 -- Make sure the anonymous access type has size and alignment fields
894 -- set, as required by gigi. This is necessary in the case of the
895 -- Task_Body_Procedure.
897 if not Has_Private_Component
(Desig_Type
) then
898 Layout_Type
(Anon_Type
);
901 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
902 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
903 -- the null value is allowed. In Ada 95 the null value is never allowed.
905 if Ada_Version
>= Ada_2005
then
906 Set_Can_Never_Be_Null
(Anon_Type
, Null_Exclusion_Present
(N
));
908 Set_Can_Never_Be_Null
(Anon_Type
, True);
911 -- The anonymous access type is as public as the discriminated type or
912 -- subprogram that defines it. It is imported (for back-end purposes)
913 -- if the designated type is.
915 Set_Is_Public
(Anon_Type
, Is_Public
(Scope
(Anon_Type
)));
917 -- Ada 2005 (AI-231): Propagate the access-constant attribute
919 Set_Is_Access_Constant
(Anon_Type
, Constant_Present
(N
));
921 -- The context is either a subprogram declaration, object declaration,
922 -- or an access discriminant, in a private or a full type declaration.
923 -- In the case of a subprogram, if the designated type is incomplete,
924 -- the operation will be a primitive operation of the full type, to be
925 -- updated subsequently. If the type is imported through a limited_with
926 -- clause, the subprogram is not a primitive operation of the type
927 -- (which is declared elsewhere in some other scope).
929 if Ekind
(Desig_Type
) = E_Incomplete_Type
930 and then not From_Limited_With
(Desig_Type
)
931 and then Is_Overloadable
(Current_Scope
)
933 Append_Elmt
(Current_Scope
, Private_Dependents
(Desig_Type
));
934 Set_Has_Delayed_Freeze
(Current_Scope
);
937 -- If the designated type is limited and class-wide, the object might
938 -- contain tasks, so we create a Master entity for the declaration. This
939 -- must be done before expansion of the full declaration, because the
940 -- declaration may include an expression that is an allocator, whose
941 -- expansion needs the proper Master for the created tasks.
944 and then Nkind
(Related_Nod
) = N_Object_Declaration
946 if Is_Limited_Record
(Desig_Type
)
947 and then Is_Class_Wide_Type
(Desig_Type
)
949 Build_Class_Wide_Master
(Anon_Type
);
951 -- Similarly, if the type is an anonymous access that designates
952 -- tasks, create a master entity for it in the current context.
954 elsif Has_Task
(Desig_Type
)
955 and then Comes_From_Source
(Related_Nod
)
957 Build_Master_Entity
(Defining_Identifier
(Related_Nod
));
958 Build_Master_Renaming
(Anon_Type
);
962 -- For a private component of a protected type, it is imperative that
963 -- the back-end elaborate the type immediately after the protected
964 -- declaration, because this type will be used in the declarations
965 -- created for the component within each protected body, so we must
966 -- create an itype reference for it now.
968 if Nkind
(Parent
(Related_Nod
)) = N_Protected_Definition
then
969 Build_Itype_Reference
(Anon_Type
, Parent
(Parent
(Related_Nod
)));
971 -- Similarly, if the access definition is the return result of a
972 -- function, create an itype reference for it because it will be used
973 -- within the function body. For a regular function that is not a
974 -- compilation unit, insert reference after the declaration. For a
975 -- protected operation, insert it after the enclosing protected type
976 -- declaration. In either case, do not create a reference for a type
977 -- obtained through a limited_with clause, because this would introduce
978 -- semantic dependencies.
980 -- Similarly, do not create a reference if the designated type is a
981 -- generic formal, because no use of it will reach the backend.
983 elsif Nkind
(Related_Nod
) = N_Function_Specification
984 and then not From_Limited_With
(Desig_Type
)
985 and then not Is_Generic_Type
(Desig_Type
)
987 if Present
(Enclosing_Prot_Type
) then
988 Build_Itype_Reference
(Anon_Type
, Parent
(Enclosing_Prot_Type
));
990 elsif Is_List_Member
(Parent
(Related_Nod
))
991 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
993 Build_Itype_Reference
(Anon_Type
, Parent
(Related_Nod
));
996 -- Finally, create an itype reference for an object declaration of an
997 -- anonymous access type. This is strictly necessary only for deferred
998 -- constants, but in any case will avoid out-of-scope problems in the
1001 elsif Nkind
(Related_Nod
) = N_Object_Declaration
then
1002 Build_Itype_Reference
(Anon_Type
, Related_Nod
);
1006 end Access_Definition
;
1008 -----------------------------------
1009 -- Access_Subprogram_Declaration --
1010 -----------------------------------
1012 procedure Access_Subprogram_Declaration
1013 (T_Name
: Entity_Id
;
1016 procedure Check_For_Premature_Usage
(Def
: Node_Id
);
1017 -- Check that type T_Name is not used, directly or recursively, as a
1018 -- parameter or a return type in Def. Def is either a subtype, an
1019 -- access_definition, or an access_to_subprogram_definition.
1021 -------------------------------
1022 -- Check_For_Premature_Usage --
1023 -------------------------------
1025 procedure Check_For_Premature_Usage
(Def
: Node_Id
) is
1029 -- Check for a subtype mark
1031 if Nkind
(Def
) in N_Has_Etype
then
1032 if Etype
(Def
) = T_Name
then
1034 ("type& cannot be used before the end of its declaration",
1038 -- If this is not a subtype, then this is an access_definition
1040 elsif Nkind
(Def
) = N_Access_Definition
then
1041 if Present
(Access_To_Subprogram_Definition
(Def
)) then
1042 Check_For_Premature_Usage
1043 (Access_To_Subprogram_Definition
(Def
));
1045 Check_For_Premature_Usage
(Subtype_Mark
(Def
));
1048 -- The only cases left are N_Access_Function_Definition and
1049 -- N_Access_Procedure_Definition.
1052 if Present
(Parameter_Specifications
(Def
)) then
1053 Param
:= First
(Parameter_Specifications
(Def
));
1054 while Present
(Param
) loop
1055 Check_For_Premature_Usage
(Parameter_Type
(Param
));
1060 if Nkind
(Def
) = N_Access_Function_Definition
then
1061 Check_For_Premature_Usage
(Result_Definition
(Def
));
1064 end Check_For_Premature_Usage
;
1068 Formals
: constant List_Id
:= Parameter_Specifications
(T_Def
);
1071 Desig_Type
: constant Entity_Id
:=
1072 Create_Itype
(E_Subprogram_Type
, Parent
(T_Def
));
1074 -- Start of processing for Access_Subprogram_Declaration
1077 -- Associate the Itype node with the inner full-type declaration or
1078 -- subprogram spec or entry body. This is required to handle nested
1079 -- anonymous declarations. For example:
1082 -- (X : access procedure
1083 -- (Y : access procedure
1086 D_Ityp
:= Associated_Node_For_Itype
(Desig_Type
);
1087 while Nkind
(D_Ityp
) not in N_Full_Type_Declaration
1088 | N_Private_Type_Declaration
1089 | N_Private_Extension_Declaration
1090 | N_Procedure_Specification
1091 | N_Function_Specification
1093 | N_Object_Declaration
1094 | N_Object_Renaming_Declaration
1095 | N_Formal_Object_Declaration
1096 | N_Formal_Type_Declaration
1097 | N_Task_Type_Declaration
1098 | N_Protected_Type_Declaration
1100 D_Ityp
:= Parent
(D_Ityp
);
1101 pragma Assert
(D_Ityp
/= Empty
);
1104 Set_Associated_Node_For_Itype
(Desig_Type
, D_Ityp
);
1106 if Nkind
(D_Ityp
) in N_Procedure_Specification | N_Function_Specification
1108 Set_Scope
(Desig_Type
, Scope
(Defining_Entity
(D_Ityp
)));
1110 elsif Nkind
(D_Ityp
) in N_Full_Type_Declaration
1111 | N_Object_Declaration
1112 | N_Object_Renaming_Declaration
1113 | N_Formal_Type_Declaration
1115 Set_Scope
(Desig_Type
, Scope
(Defining_Identifier
(D_Ityp
)));
1118 if Nkind
(T_Def
) = N_Access_Function_Definition
then
1119 if Nkind
(Result_Definition
(T_Def
)) = N_Access_Definition
then
1121 Acc
: constant Node_Id
:= Result_Definition
(T_Def
);
1124 if Present
(Access_To_Subprogram_Definition
(Acc
))
1126 Protected_Present
(Access_To_Subprogram_Definition
(Acc
))
1130 Replace_Anonymous_Access_To_Protected_Subprogram
1136 Access_Definition
(T_Def
, Result_Definition
(T_Def
)));
1141 Analyze
(Result_Definition
(T_Def
));
1144 Typ
: constant Entity_Id
:= Entity
(Result_Definition
(T_Def
));
1147 -- If a null exclusion is imposed on the result type, then
1148 -- create a null-excluding itype (an access subtype) and use
1149 -- it as the function's Etype.
1151 if Is_Access_Type
(Typ
)
1152 and then Null_Exclusion_In_Return_Present
(T_Def
)
1154 Set_Etype
(Desig_Type
,
1155 Create_Null_Excluding_Itype
1157 Related_Nod
=> T_Def
,
1158 Scope_Id
=> Current_Scope
));
1161 if From_Limited_With
(Typ
) then
1163 -- AI05-151: Incomplete types are allowed in all basic
1164 -- declarations, including access to subprograms.
1166 if Ada_Version
>= Ada_2012
then
1171 ("illegal use of incomplete type&",
1172 Result_Definition
(T_Def
), Typ
);
1175 elsif Ekind
(Current_Scope
) = E_Package
1176 and then In_Private_Part
(Current_Scope
)
1178 if Ekind
(Typ
) = E_Incomplete_Type
then
1179 Append_Elmt
(Desig_Type
, Private_Dependents
(Typ
));
1181 elsif Is_Class_Wide_Type
(Typ
)
1182 and then Ekind
(Etype
(Typ
)) = E_Incomplete_Type
1185 (Desig_Type
, Private_Dependents
(Etype
(Typ
)));
1189 Set_Etype
(Desig_Type
, Typ
);
1194 if not Is_Type
(Etype
(Desig_Type
)) then
1196 ("expect type in function specification",
1197 Result_Definition
(T_Def
));
1201 Set_Etype
(Desig_Type
, Standard_Void_Type
);
1204 if Present
(Formals
) then
1205 Push_Scope
(Desig_Type
);
1207 -- Some special tests here. These special tests can be removed
1208 -- if and when Itypes always have proper parent pointers to their
1211 -- Special test 1) Link defining_identifier of formals. Required by
1212 -- First_Formal to provide its functionality.
1218 F
:= First
(Formals
);
1220 while Present
(F
) loop
1221 if No
(Parent
(Defining_Identifier
(F
))) then
1222 Set_Parent
(Defining_Identifier
(F
), F
);
1229 Process_Formals
(Formals
, Parent
(T_Def
));
1231 -- Special test 2) End_Scope requires that the parent pointer be set
1232 -- to something reasonable, but Itypes don't have parent pointers. So
1233 -- we set it and then unset it ???
1235 Set_Parent
(Desig_Type
, T_Name
);
1237 Set_Parent
(Desig_Type
, Empty
);
1240 -- Check for premature usage of the type being defined
1242 Check_For_Premature_Usage
(T_Def
);
1244 -- The return type and/or any parameter type may be incomplete. Mark the
1245 -- subprogram_type as depending on the incomplete type, so that it can
1246 -- be updated when the full type declaration is seen. This only applies
1247 -- to incomplete types declared in some enclosing scope, not to limited
1248 -- views from other packages.
1250 -- Prior to Ada 2012, access to functions can only have in_parameters.
1252 if Present
(Formals
) then
1253 Formal
:= First_Formal
(Desig_Type
);
1254 while Present
(Formal
) loop
1255 if Ekind
(Formal
) /= E_In_Parameter
1256 and then Nkind
(T_Def
) = N_Access_Function_Definition
1257 and then Ada_Version
< Ada_2012
1259 Error_Msg_N
("functions can only have IN parameters", Formal
);
1262 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
1263 and then In_Open_Scopes
(Scope
(Etype
(Formal
)))
1265 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Formal
)));
1266 Set_Has_Delayed_Freeze
(Desig_Type
);
1269 Next_Formal
(Formal
);
1273 -- Check whether an indirect call without actuals may be possible. This
1274 -- is used when resolving calls whose result is then indexed.
1276 May_Need_Actuals
(Desig_Type
);
1278 -- If the return type is incomplete, this is legal as long as the type
1279 -- is declared in the current scope and will be completed in it (rather
1280 -- than being part of limited view).
1282 if Ekind
(Etype
(Desig_Type
)) = E_Incomplete_Type
1283 and then not Has_Delayed_Freeze
(Desig_Type
)
1284 and then In_Open_Scopes
(Scope
(Etype
(Desig_Type
)))
1286 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Desig_Type
)));
1287 Set_Has_Delayed_Freeze
(Desig_Type
);
1290 Check_Delayed_Subprogram
(Desig_Type
);
1292 if Protected_Present
(T_Def
) then
1293 Mutate_Ekind
(T_Name
, E_Access_Protected_Subprogram_Type
);
1294 Set_Convention
(Desig_Type
, Convention_Protected
);
1296 Mutate_Ekind
(T_Name
, E_Access_Subprogram_Type
);
1299 Set_Can_Use_Internal_Rep
(T_Name
,
1300 not Always_Compatible_Rep_On_Target
);
1301 Set_Etype
(T_Name
, T_Name
);
1302 Reinit_Size_Align
(T_Name
);
1303 Set_Directly_Designated_Type
(T_Name
, Desig_Type
);
1305 -- If the access_to_subprogram is not declared at the library level,
1306 -- it can only point to subprograms that are at the same or deeper
1307 -- accessibility level. The corresponding subprogram type might
1308 -- require an activation record when compiling for C.
1310 Set_Needs_Activation_Record
(Desig_Type
,
1311 not Is_Library_Level_Entity
(T_Name
));
1313 Generate_Reference_To_Formals
(T_Name
);
1315 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1317 Set_Can_Never_Be_Null
(T_Name
, Null_Exclusion_Present
(T_Def
));
1319 Check_Restriction
(No_Access_Subprograms
, T_Def
);
1321 Create_Extra_Formals
(Desig_Type
);
1322 end Access_Subprogram_Declaration
;
1324 ----------------------------
1325 -- Access_Type_Declaration --
1326 ----------------------------
1328 procedure Access_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
1330 procedure Setup_Access_Type
(Desig_Typ
: Entity_Id
);
1331 -- After type declaration is analysed with T being an incomplete type,
1332 -- this routine will mutate the kind of T to the appropriate access type
1333 -- and set its directly designated type to Desig_Typ.
1335 -----------------------
1336 -- Setup_Access_Type --
1337 -----------------------
1339 procedure Setup_Access_Type
(Desig_Typ
: Entity_Id
) is
1341 if All_Present
(Def
) or else Constant_Present
(Def
) then
1342 Mutate_Ekind
(T
, E_General_Access_Type
);
1344 Mutate_Ekind
(T
, E_Access_Type
);
1347 Set_Directly_Designated_Type
(T
, Desig_Typ
);
1348 end Setup_Access_Type
;
1352 P
: constant Node_Id
:= Parent
(Def
);
1353 S
: constant Node_Id
:= Subtype_Indication
(Def
);
1355 Full_Desig
: Entity_Id
;
1357 -- Start of processing for Access_Type_Declaration
1360 -- Check for permissible use of incomplete type
1362 if Nkind
(S
) /= N_Subtype_Indication
then
1366 if Nkind
(S
) in N_Has_Entity
1367 and then Present
(Entity
(S
))
1368 and then Ekind
(Root_Type
(Entity
(S
))) = E_Incomplete_Type
1370 Setup_Access_Type
(Desig_Typ
=> Entity
(S
));
1372 -- If the designated type is a limited view, we cannot tell if
1373 -- the full view contains tasks, and there is no way to handle
1374 -- that full view in a client. We create a master entity for the
1375 -- scope, which will be used when a client determines that one
1378 if From_Limited_With
(Entity
(S
))
1379 and then not Is_Class_Wide_Type
(Entity
(S
))
1381 Build_Master_Entity
(T
);
1382 Build_Master_Renaming
(T
);
1386 Setup_Access_Type
(Desig_Typ
=> Process_Subtype
(S
, P
, T
, 'P'));
1389 -- If the access definition is of the form: ACCESS NOT NULL ..
1390 -- the subtype indication must be of an access type. Create
1391 -- a null-excluding subtype of it.
1393 if Null_Excluding_Subtype
(Def
) then
1394 if not Is_Access_Type
(Entity
(S
)) then
1395 Error_Msg_N
("null exclusion must apply to access type", Def
);
1399 Loc
: constant Source_Ptr
:= Sloc
(S
);
1401 Nam
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1405 Make_Subtype_Declaration
(Loc
,
1406 Defining_Identifier
=> Nam
,
1407 Subtype_Indication
=>
1408 New_Occurrence_Of
(Entity
(S
), Loc
));
1409 Set_Null_Exclusion_Present
(Decl
);
1410 Insert_Before
(Parent
(Def
), Decl
);
1412 Set_Entity
(S
, Nam
);
1418 Setup_Access_Type
(Desig_Typ
=> Process_Subtype
(S
, P
, T
, 'P'));
1421 if not Error_Posted
(T
) then
1422 Full_Desig
:= Designated_Type
(T
);
1424 if Base_Type
(Full_Desig
) = T
then
1425 Error_Msg_N
("access type cannot designate itself", S
);
1427 -- In Ada 2005, the type may have a limited view through some unit in
1428 -- its own context, allowing the following circularity that cannot be
1429 -- detected earlier.
1431 elsif Is_Class_Wide_Type
(Full_Desig
) and then Etype
(Full_Desig
) = T
1434 ("access type cannot designate its own class-wide type", S
);
1436 -- Clean up indication of tagged status to prevent cascaded errors
1438 Set_Is_Tagged_Type
(T
, False);
1443 -- For SPARK, check that the designated type is compatible with
1444 -- respect to volatility with the access type.
1446 if SPARK_Mode
/= Off
1447 and then Comes_From_Source
(T
)
1449 -- ??? UNIMPLEMENTED
1450 -- In the case where the designated type is incomplete at this
1451 -- point, performing this check here is harmless but the check
1452 -- will need to be repeated when the designated type is complete.
1454 -- The preceding call to Comes_From_Source is needed because the
1455 -- FE sometimes introduces implicitly declared access types. See,
1456 -- for example, the expansion of nested_po.ads in OA28-015.
1458 Check_Volatility_Compatibility
1459 (Full_Desig
, T
, "designated type", "access type",
1460 Srcpos_Bearer
=> T
);
1464 -- If the type has appeared already in a with_type clause, it is frozen
1465 -- and the pointer size is already set. Else, initialize.
1467 if not From_Limited_With
(T
) then
1468 Reinit_Size_Align
(T
);
1471 -- Note that Has_Task is always false, since the access type itself
1472 -- is not a task type. See Einfo for more description on this point.
1473 -- Exactly the same consideration applies to Has_Controlled_Component
1474 -- and to Has_Protected.
1476 Set_Has_Task
(T
, False);
1477 Set_Has_Protected
(T
, False);
1478 Set_Has_Timing_Event
(T
, False);
1479 Set_Has_Controlled_Component
(T
, False);
1481 -- Initialize field Finalization_Master explicitly to Empty, to avoid
1482 -- problems where an incomplete view of this entity has been previously
1483 -- established by a limited with and an overlaid version of this field
1484 -- (Stored_Constraint) was initialized for the incomplete view.
1486 -- This reset is performed in most cases except where the access type
1487 -- has been created for the purposes of allocating or deallocating a
1488 -- build-in-place object. Such access types have explicitly set pools
1489 -- and finalization masters.
1491 if No
(Associated_Storage_Pool
(T
)) then
1492 Set_Finalization_Master
(T
, Empty
);
1495 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1498 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
1499 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
1500 end Access_Type_Declaration
;
1502 ----------------------------------
1503 -- Add_Interface_Tag_Components --
1504 ----------------------------------
1506 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
) is
1507 Loc
: constant Source_Ptr
:= Sloc
(N
);
1511 procedure Add_Tag
(Iface
: Entity_Id
);
1512 -- Add tag for one of the progenitor interfaces
1518 procedure Add_Tag
(Iface
: Entity_Id
) is
1525 pragma Assert
(Is_Tagged_Type
(Iface
) and then Is_Interface
(Iface
));
1527 -- This is a reasonable place to propagate predicates
1529 if Has_Predicates
(Iface
) then
1530 Set_Has_Predicates
(Typ
);
1534 Make_Component_Definition
(Loc
,
1535 Aliased_Present
=> True,
1536 Subtype_Indication
=>
1537 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
));
1539 Tag
:= Make_Temporary
(Loc
, 'V');
1542 Make_Component_Declaration
(Loc
,
1543 Defining_Identifier
=> Tag
,
1544 Component_Definition
=> Def
);
1546 Analyze_Component_Declaration
(Decl
);
1548 Set_Analyzed
(Decl
);
1549 Mutate_Ekind
(Tag
, E_Component
);
1551 Set_Is_Aliased
(Tag
);
1552 Set_Is_Independent
(Tag
);
1553 Set_Related_Type
(Tag
, Iface
);
1554 Reinit_Component_Location
(Tag
);
1556 pragma Assert
(Is_Frozen
(Iface
));
1558 Set_DT_Entry_Count
(Tag
,
1559 DT_Entry_Count
(First_Entity
(Iface
)));
1561 if No
(Last_Tag
) then
1564 Insert_After
(Last_Tag
, Decl
);
1569 -- If the ancestor has discriminants we need to give special support
1570 -- to store the offset_to_top value of the secondary dispatch tables.
1571 -- For this purpose we add a supplementary component just after the
1572 -- field that contains the tag associated with each secondary DT.
1574 if Typ
/= Etype
(Typ
) and then Has_Discriminants
(Etype
(Typ
)) then
1576 Make_Component_Definition
(Loc
,
1577 Subtype_Indication
=>
1578 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
1580 Offset
:= Make_Temporary
(Loc
, 'V');
1583 Make_Component_Declaration
(Loc
,
1584 Defining_Identifier
=> Offset
,
1585 Component_Definition
=> Def
);
1587 Analyze_Component_Declaration
(Decl
);
1589 Set_Analyzed
(Decl
);
1590 Mutate_Ekind
(Offset
, E_Component
);
1591 Set_Is_Aliased
(Offset
);
1592 Set_Is_Independent
(Offset
);
1593 Set_Related_Type
(Offset
, Iface
);
1594 Reinit_Component_Location
(Offset
);
1595 Insert_After
(Last_Tag
, Decl
);
1606 -- Start of processing for Add_Interface_Tag_Components
1609 if not RTE_Available
(RE_Interface_Tag
) then
1611 ("(Ada 2005) interface types not supported by this run-time!", N
);
1615 if Ekind
(Typ
) /= E_Record_Type
1616 or else (Is_Concurrent_Record_Type
(Typ
)
1617 and then Is_Empty_List
(Abstract_Interface_List
(Typ
)))
1618 or else (not Is_Concurrent_Record_Type
(Typ
)
1619 and then No
(Interfaces
(Typ
))
1620 and then Is_Empty_Elmt_List
(Interfaces
(Typ
)))
1625 -- Find the current last tag
1627 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1628 Ext
:= Record_Extension_Part
(Type_Definition
(N
));
1630 pragma Assert
(Nkind
(Type_Definition
(N
)) = N_Record_Definition
);
1631 Ext
:= Type_Definition
(N
);
1636 if not (Present
(Component_List
(Ext
))) then
1637 Set_Null_Present
(Ext
, False);
1639 Set_Component_List
(Ext
,
1640 Make_Component_List
(Loc
,
1641 Component_Items
=> L
,
1642 Null_Present
=> False));
1644 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1645 L
:= Component_Items
1647 (Record_Extension_Part
1648 (Type_Definition
(N
))));
1650 L
:= Component_Items
1652 (Type_Definition
(N
)));
1655 -- Find the last tag component
1658 while Present
(Comp
) loop
1659 if Nkind
(Comp
) = N_Component_Declaration
1660 and then Is_Tag
(Defining_Identifier
(Comp
))
1669 -- At this point L references the list of components and Last_Tag
1670 -- references the current last tag (if any). Now we add the tag
1671 -- corresponding with all the interfaces that are not implemented
1674 if Present
(Interfaces
(Typ
)) then
1675 Elmt
:= First_Elmt
(Interfaces
(Typ
));
1676 while Present
(Elmt
) loop
1677 Add_Tag
(Node
(Elmt
));
1681 end Add_Interface_Tag_Components
;
1683 -------------------------------------
1684 -- Add_Internal_Interface_Entities --
1685 -------------------------------------
1687 procedure Add_Internal_Interface_Entities
(Tagged_Type
: Entity_Id
) is
1690 Iface_Elmt
: Elmt_Id
;
1691 Iface_Prim
: Entity_Id
;
1692 Ifaces_List
: Elist_Id
;
1693 New_Subp
: Entity_Id
:= Empty
;
1695 Restore_Scope
: Boolean := False;
1698 pragma Assert
(Ada_Version
>= Ada_2005
1699 and then Is_Record_Type
(Tagged_Type
)
1700 and then Is_Tagged_Type
(Tagged_Type
)
1701 and then Has_Interfaces
(Tagged_Type
)
1702 and then not Is_Interface
(Tagged_Type
));
1704 -- Ensure that the internal entities are added to the scope of the type
1706 if Scope
(Tagged_Type
) /= Current_Scope
then
1707 Push_Scope
(Scope
(Tagged_Type
));
1708 Restore_Scope
:= True;
1711 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1713 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1714 while Present
(Iface_Elmt
) loop
1715 Iface
:= Node
(Iface_Elmt
);
1717 -- Originally we excluded here from this processing interfaces that
1718 -- are parents of Tagged_Type because their primitives are located
1719 -- in the primary dispatch table (and hence no auxiliary internal
1720 -- entities are required to handle secondary dispatch tables in such
1721 -- case). However, these auxiliary entities are also required to
1722 -- handle derivations of interfaces in formals of generics (see
1723 -- Derive_Subprograms).
1725 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1726 while Present
(Elmt
) loop
1727 Iface_Prim
:= Node
(Elmt
);
1729 if not Is_Predefined_Dispatching_Operation
(Iface_Prim
) then
1731 Find_Primitive_Covering_Interface
1732 (Tagged_Type
=> Tagged_Type
,
1733 Iface_Prim
=> Iface_Prim
);
1735 if No
(Prim
) and then Serious_Errors_Detected
> 0 then
1739 pragma Assert
(Present
(Prim
));
1741 -- Ada 2012 (AI05-0197): If the name of the covering primitive
1742 -- differs from the name of the interface primitive then it is
1743 -- a private primitive inherited from a parent type. In such
1744 -- case, given that Tagged_Type covers the interface, the
1745 -- inherited private primitive becomes visible. For such
1746 -- purpose we add a new entity that renames the inherited
1747 -- private primitive.
1749 if Chars
(Prim
) /= Chars
(Iface_Prim
) then
1750 pragma Assert
(Has_Suffix
(Prim
, 'P'));
1752 (New_Subp
=> New_Subp
,
1753 Parent_Subp
=> Iface_Prim
,
1754 Derived_Type
=> Tagged_Type
,
1755 Parent_Type
=> Iface
);
1756 Set_Alias
(New_Subp
, Prim
);
1757 Set_Is_Abstract_Subprogram
1758 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1762 (New_Subp
=> New_Subp
,
1763 Parent_Subp
=> Iface_Prim
,
1764 Derived_Type
=> Tagged_Type
,
1765 Parent_Type
=> Iface
);
1770 if Is_Inherited_Operation
(Prim
)
1771 and then Present
(Alias
(Prim
))
1773 Anc
:= Alias
(Prim
);
1775 Anc
:= Overridden_Operation
(Prim
);
1778 -- Apply legality checks in RM 6.1.1 (10-13) concerning
1779 -- nonconforming preconditions in both an ancestor and
1780 -- a progenitor operation.
1782 -- If the operation is a primitive wrapper it is an explicit
1783 -- (overriding) operqtion and all is fine.
1786 and then Has_Non_Trivial_Precondition
(Anc
)
1787 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
1789 if Is_Abstract_Subprogram
(Prim
)
1791 (Ekind
(Prim
) = E_Procedure
1792 and then Nkind
(Parent
(Prim
)) =
1793 N_Procedure_Specification
1794 and then Null_Present
(Parent
(Prim
)))
1795 or else Is_Primitive_Wrapper
(Prim
)
1799 -- The operation is inherited and must be overridden
1801 elsif not Comes_From_Source
(Prim
) then
1803 ("&inherits non-conforming preconditions and must "
1804 & "be overridden (RM 6.1.1 (10-16))",
1805 Parent
(Tagged_Type
), Prim
);
1810 -- Ada 2005 (AI-251): Decorate internal entity Iface_Subp
1811 -- associated with interface types. These entities are
1812 -- only registered in the list of primitives of its
1813 -- corresponding tagged type because they are only used
1814 -- to fill the contents of the secondary dispatch tables.
1815 -- Therefore they are removed from the homonym chains.
1817 Set_Is_Hidden
(New_Subp
);
1818 Set_Is_Internal
(New_Subp
);
1819 Set_Alias
(New_Subp
, Prim
);
1820 Set_Is_Abstract_Subprogram
1821 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1822 Set_Interface_Alias
(New_Subp
, Iface_Prim
);
1824 -- If the returned type is an interface then propagate it to
1825 -- the returned type. Needed by the thunk to generate the code
1826 -- which displaces "this" to reference the corresponding
1827 -- secondary dispatch table in the returned object.
1829 if Is_Interface
(Etype
(Iface_Prim
)) then
1830 Set_Etype
(New_Subp
, Etype
(Iface_Prim
));
1833 -- Internal entities associated with interface types are only
1834 -- registered in the list of primitives of the tagged type.
1835 -- They are only used to fill the contents of the secondary
1836 -- dispatch tables. Therefore they are not needed in the
1839 Remove_Homonym
(New_Subp
);
1841 -- Hidden entities associated with interfaces must have set
1842 -- the Has_Delay_Freeze attribute to ensure that, in case
1843 -- of locally defined tagged types (or compiling with static
1844 -- dispatch tables generation disabled) the corresponding
1845 -- entry of the secondary dispatch table is filled when such
1846 -- an entity is frozen.
1848 Set_Has_Delayed_Freeze
(New_Subp
);
1855 Next_Elmt
(Iface_Elmt
);
1858 if Restore_Scope
then
1861 end Add_Internal_Interface_Entities
;
1863 -----------------------------------
1864 -- Analyze_Component_Declaration --
1865 -----------------------------------
1867 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
1868 Loc
: constant Source_Ptr
:= Sloc
(Component_Definition
(N
));
1869 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1870 E
: constant Node_Id
:= Expression
(N
);
1871 Typ
: constant Node_Id
:=
1872 Subtype_Indication
(Component_Definition
(N
));
1876 function Contains_POC
(Constr
: Node_Id
) return Boolean;
1877 -- Determines whether a constraint uses the discriminant of a record
1878 -- type thus becoming a per-object constraint (POC).
1880 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean;
1881 -- Typ is the type of the current component, check whether this type is
1882 -- a limited type. Used to validate declaration against that of
1883 -- enclosing record.
1889 function Contains_POC
(Constr
: Node_Id
) return Boolean is
1891 -- Prevent cascaded errors
1893 if Error_Posted
(Constr
) then
1897 case Nkind
(Constr
) is
1898 when N_Attribute_Reference
=>
1899 return Attribute_Name
(Constr
) = Name_Access
1900 and then Prefix
(Constr
) = Scope
(Entity
(Prefix
(Constr
)));
1902 when N_Discriminant_Association
=>
1903 return Denotes_Discriminant
(Expression
(Constr
));
1905 when N_Identifier
=>
1906 return Denotes_Discriminant
(Constr
);
1908 when N_Index_Or_Discriminant_Constraint
=>
1913 IDC
:= First
(Constraints
(Constr
));
1914 while Present
(IDC
) loop
1916 -- One per-object constraint is sufficient
1918 if Contains_POC
(IDC
) then
1929 return Denotes_Discriminant
(Low_Bound
(Constr
))
1931 Denotes_Discriminant
(High_Bound
(Constr
));
1933 when N_Range_Constraint
=>
1934 return Denotes_Discriminant
(Range_Expression
(Constr
));
1941 ----------------------
1942 -- Is_Known_Limited --
1943 ----------------------
1945 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean is
1946 P
: constant Entity_Id
:= Etype
(Typ
);
1947 R
: constant Entity_Id
:= Root_Type
(Typ
);
1950 if Is_Limited_Record
(Typ
) then
1953 -- If the root type is limited (and not a limited interface) so is
1954 -- the current type.
1956 elsif Is_Limited_Record
(R
)
1957 and then (not Is_Interface
(R
) or else not Is_Limited_Interface
(R
))
1961 -- Else the type may have a limited interface progenitor, but a
1962 -- limited record parent that is not an interface.
1965 and then Is_Limited_Record
(P
)
1966 and then not Is_Interface
(P
)
1973 end Is_Known_Limited
;
1975 -- Start of processing for Analyze_Component_Declaration
1978 Generate_Definition
(Id
);
1981 if Present
(Typ
) then
1982 T
:= Find_Type_Of_Object
1983 (Subtype_Indication
(Component_Definition
(N
)), N
);
1985 -- Ada 2005 (AI-230): Access Definition case
1988 pragma Assert
(Present
1989 (Access_Definition
(Component_Definition
(N
))));
1991 T
:= Access_Definition
1993 N
=> Access_Definition
(Component_Definition
(N
)));
1994 Set_Is_Local_Anonymous_Access
(T
);
1996 -- Ada 2005 (AI-254)
1998 if Present
(Access_To_Subprogram_Definition
1999 (Access_Definition
(Component_Definition
(N
))))
2000 and then Protected_Present
(Access_To_Subprogram_Definition
2002 (Component_Definition
(N
))))
2004 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2008 -- If the subtype is a constrained subtype of the enclosing record,
2009 -- (which must have a partial view) the back-end does not properly
2010 -- handle the recursion. Rewrite the component declaration with an
2011 -- explicit subtype indication, which is acceptable to Gigi. We can copy
2012 -- the tree directly because side effects have already been removed from
2013 -- discriminant constraints.
2015 if Ekind
(T
) = E_Access_Subtype
2016 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
2017 and then Comes_From_Source
(T
)
2018 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
2019 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
2022 (Subtype_Indication
(Component_Definition
(N
)),
2023 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
2024 T
:= Find_Type_Of_Object
2025 (Subtype_Indication
(Component_Definition
(N
)), N
);
2028 -- If the component declaration includes a default expression, then we
2029 -- check that the component is not of a limited type (RM 3.7(5)),
2030 -- and do the special preanalysis of the expression (see section on
2031 -- "Handling of Default and Per-Object Expressions" in the spec of
2035 Preanalyze_Default_Expression
(E
, T
);
2036 Check_Initialization
(T
, E
);
2038 if Ada_Version
>= Ada_2005
2039 and then Ekind
(T
) = E_Anonymous_Access_Type
2040 and then Etype
(E
) /= Any_Type
2042 -- Check RM 3.9.2(9): "if the expected type for an expression is
2043 -- an anonymous access-to-specific tagged type, then the object
2044 -- designated by the expression shall not be dynamically tagged
2045 -- unless it is a controlling operand in a call on a dispatching
2048 if Is_Tagged_Type
(Directly_Designated_Type
(T
))
2050 Ekind
(Directly_Designated_Type
(T
)) /= E_Class_Wide_Type
2052 Ekind
(Directly_Designated_Type
(Etype
(E
))) =
2056 ("access to specific tagged type required (RM 3.9.2(9))", E
);
2059 -- (Ada 2005: AI-230): Accessibility check for anonymous
2062 if Type_Access_Level
(Etype
(E
)) >
2063 Deepest_Type_Access_Level
(T
)
2066 ("expression has deeper access level than component " &
2067 "(RM 3.10.2 (12.2))", E
);
2070 -- The initialization expression is a reference to an access
2071 -- discriminant. The type of the discriminant is always deeper
2072 -- than any access type.
2074 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
2075 and then Is_Entity_Name
(E
)
2076 and then Ekind
(Entity
(E
)) = E_In_Parameter
2077 and then Present
(Discriminal_Link
(Entity
(E
)))
2080 ("discriminant has deeper accessibility level than target",
2086 -- The parent type may be a private view with unknown discriminants,
2087 -- and thus unconstrained. Regular components must be constrained.
2089 if not Is_Definite_Subtype
(T
)
2090 and then Chars
(Id
) /= Name_uParent
2092 if Is_Class_Wide_Type
(T
) then
2094 ("class-wide subtype with unknown discriminants" &
2095 " in component declaration",
2096 Subtype_Indication
(Component_Definition
(N
)));
2099 ("unconstrained subtype in component declaration",
2100 Subtype_Indication
(Component_Definition
(N
)));
2103 -- Components cannot be abstract, except for the special case of
2104 -- the _Parent field (case of extending an abstract tagged type)
2106 elsif Is_Abstract_Type
(T
) and then Chars
(Id
) /= Name_uParent
then
2107 Error_Msg_N
("type of a component cannot be abstract", N
);
2112 if Aliased_Present
(Component_Definition
(N
)) then
2113 Set_Is_Aliased
(Id
);
2115 -- AI12-001: All aliased objects are considered to be specified as
2116 -- independently addressable (RM C.6(8.1/4)).
2118 Set_Is_Independent
(Id
);
2121 -- The component declaration may have a per-object constraint, set
2122 -- the appropriate flag in the defining identifier of the subtype.
2124 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
2126 Sindic
: constant Node_Id
:=
2127 Subtype_Indication
(Component_Definition
(N
));
2129 if Nkind
(Sindic
) = N_Subtype_Indication
2130 and then Present
(Constraint
(Sindic
))
2131 and then Contains_POC
(Constraint
(Sindic
))
2133 Set_Has_Per_Object_Constraint
(Id
);
2138 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2139 -- out some static checks.
2141 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(T
) then
2142 Null_Exclusion_Static_Checks
(N
);
2145 -- If this component is private (or depends on a private type), flag the
2146 -- record type to indicate that some operations are not available.
2148 P
:= Private_Component
(T
);
2152 -- Check for circular definitions
2154 if P
= Any_Type
then
2155 Set_Etype
(Id
, Any_Type
);
2157 -- There is a gap in the visibility of operations only if the
2158 -- component type is not defined in the scope of the record type.
2160 elsif Scope
(P
) = Scope
(Current_Scope
) then
2163 elsif Is_Limited_Type
(P
) then
2164 Set_Is_Limited_Composite
(Current_Scope
);
2167 Set_Is_Private_Composite
(Current_Scope
);
2172 and then Is_Limited_Type
(T
)
2173 and then Chars
(Id
) /= Name_uParent
2174 and then Is_Tagged_Type
(Current_Scope
)
2176 if Is_Derived_Type
(Current_Scope
)
2177 and then not Is_Known_Limited
(Current_Scope
)
2180 ("extension of nonlimited type cannot have limited components",
2183 if Is_Interface
(Root_Type
(Current_Scope
)) then
2185 ("\limitedness is not inherited from limited interface", N
);
2186 Error_Msg_N
("\add LIMITED to type indication", N
);
2189 Explain_Limited_Type
(T
, N
);
2190 Set_Etype
(Id
, Any_Type
);
2191 Set_Is_Limited_Composite
(Current_Scope
, False);
2193 elsif not Is_Derived_Type
(Current_Scope
)
2194 and then not Is_Limited_Record
(Current_Scope
)
2195 and then not Is_Concurrent_Type
(Current_Scope
)
2198 ("nonlimited tagged type cannot have limited components", N
);
2199 Explain_Limited_Type
(T
, N
);
2200 Set_Etype
(Id
, Any_Type
);
2201 Set_Is_Limited_Composite
(Current_Scope
, False);
2205 -- If the component is an unconstrained task or protected type with
2206 -- discriminants, the component and the enclosing record are limited
2207 -- and the component is constrained by its default values. Compute
2208 -- its actual subtype, else it may be allocated the maximum size by
2209 -- the backend, and possibly overflow.
2211 if Is_Concurrent_Type
(T
)
2212 and then not Is_Constrained
(T
)
2213 and then Has_Discriminants
(T
)
2214 and then not Has_Discriminants
(Current_Scope
)
2217 Act_T
: constant Entity_Id
:= Build_Default_Subtype
(T
, N
);
2220 Set_Etype
(Id
, Act_T
);
2222 -- Rewrite component definition to use the constrained subtype
2224 Rewrite
(Component_Definition
(N
),
2225 Make_Component_Definition
(Loc
,
2226 Subtype_Indication
=> New_Occurrence_Of
(Act_T
, Loc
)));
2230 Set_Original_Record_Component
(Id
, Id
);
2232 if Has_Aspects
(N
) then
2233 Analyze_Aspect_Specifications
(N
, Id
);
2236 Analyze_Dimension
(N
);
2237 end Analyze_Component_Declaration
;
2239 --------------------------
2240 -- Analyze_Declarations --
2241 --------------------------
2243 procedure Analyze_Declarations
(L
: List_Id
) is
2246 procedure Adjust_Decl
;
2247 -- Adjust Decl not to include implicit label declarations, since these
2248 -- have strange Sloc values that result in elaboration check problems.
2249 -- (They have the sloc of the label as found in the source, and that
2250 -- is ahead of the current declarative part).
2252 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
);
2253 -- Create the subprogram bodies which verify the run-time semantics of
2254 -- the pragmas listed below for each elibigle type found in declarative
2255 -- list Decls. The pragmas are:
2257 -- Default_Initial_Condition
2261 -- Context denotes the owner of the declarative list.
2263 procedure Check_Entry_Contracts
;
2264 -- Perform a preanalysis of the pre- and postconditions of an entry
2265 -- declaration. This must be done before full resolution and creation
2266 -- of the parameter block, etc. to catch illegal uses within the
2267 -- contract expression. Full analysis of the expression is done when
2268 -- the contract is processed.
2270 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean;
2271 -- Check if a nested package has entities within it that rely on library
2272 -- level private types where the full view has not been completed for
2273 -- the purposes of checking if it is acceptable to freeze an expression
2274 -- function at the point of declaration.
2276 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
);
2277 -- Determine whether Body_Decl denotes the body of a late controlled
2278 -- primitive (either Initialize, Adjust or Finalize). If this is the
2279 -- case, add a proper spec if the body lacks one. The spec is inserted
2280 -- before Body_Decl and immediately analyzed.
2282 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
);
2283 -- Spec_Id is the entity of a package that may define abstract states,
2284 -- and in the case of a child unit, whose ancestors may define abstract
2285 -- states. If the states have partial visible refinement, remove the
2286 -- partial visibility of each constituent at the end of the package
2287 -- spec and body declarations.
2289 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
);
2290 -- Spec_Id is the entity of a package that may define abstract states.
2291 -- If the states have visible refinement, remove the visibility of each
2292 -- constituent at the end of the package body declaration.
2294 procedure Resolve_Aspects
;
2295 -- Utility to resolve the expressions of aspects at the end of a list of
2296 -- declarations, or before a declaration that freezes previous entities,
2297 -- such as in a subprogram body.
2303 procedure Adjust_Decl
is
2305 while Present
(Prev
(Decl
))
2306 and then Nkind
(Decl
) = N_Implicit_Label_Declaration
2312 ----------------------------
2313 -- Build_Assertion_Bodies --
2314 ----------------------------
2316 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
) is
2317 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
);
2318 -- Create the subprogram bodies which verify the run-time semantics
2319 -- of the pragmas listed below for type Typ. The pragmas are:
2321 -- Default_Initial_Condition
2325 -------------------------------------
2326 -- Build_Assertion_Bodies_For_Type --
2327 -------------------------------------
2329 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
) is
2331 if Nkind
(Context
) = N_Package_Specification
then
2333 -- Preanalyze and resolve the class-wide invariants of an
2334 -- interface at the end of whichever declarative part has the
2335 -- interface type. Note that an interface may be declared in
2336 -- any non-package declarative part, but reaching the end of
2337 -- such a declarative part will always freeze the type and
2338 -- generate the invariant procedure (see Freeze_Type).
2340 if Is_Interface
(Typ
) then
2342 -- Interfaces are treated as the partial view of a private
2343 -- type, in order to achieve uniformity with the general
2344 -- case. As a result, an interface receives only a "partial"
2345 -- invariant procedure, which is never called.
2347 if Has_Own_Invariants
(Typ
) then
2348 Build_Invariant_Procedure_Body
2350 Partial_Invariant
=> True);
2353 elsif Decls
= Visible_Declarations
(Context
) then
2354 -- Preanalyze and resolve the invariants of a private type
2355 -- at the end of the visible declarations to catch potential
2356 -- errors. Inherited class-wide invariants are not included
2357 -- because they have already been resolved.
2359 if Ekind
(Typ
) in E_Limited_Private_Type
2361 | E_Record_Type_With_Private
2362 and then Has_Own_Invariants
(Typ
)
2364 Build_Invariant_Procedure_Body
2366 Partial_Invariant
=> True);
2369 -- Preanalyze and resolve the Default_Initial_Condition
2370 -- assertion expression at the end of the declarations to
2371 -- catch any errors.
2373 if Ekind
(Typ
) in E_Limited_Private_Type
2375 | E_Record_Type_With_Private
2376 and then Has_Own_DIC
(Typ
)
2378 Build_DIC_Procedure_Body
2380 Partial_DIC
=> True);
2383 elsif Decls
= Private_Declarations
(Context
) then
2385 -- Preanalyze and resolve the invariants of a private type's
2386 -- full view at the end of the private declarations to catch
2387 -- potential errors.
2389 if (not Is_Private_Type
(Typ
)
2390 or else Present
(Underlying_Full_View
(Typ
)))
2391 and then Has_Private_Declaration
(Typ
)
2392 and then Has_Invariants
(Typ
)
2394 Build_Invariant_Procedure_Body
(Typ
);
2397 if (not Is_Private_Type
(Typ
)
2398 or else Present
(Underlying_Full_View
(Typ
)))
2399 and then Has_Private_Declaration
(Typ
)
2400 and then Has_DIC
(Typ
)
2402 Build_DIC_Procedure_Body
(Typ
);
2406 end Build_Assertion_Bodies_For_Type
;
2411 Decl_Id
: Entity_Id
;
2413 -- Start of processing for Build_Assertion_Bodies
2416 Decl
:= First
(Decls
);
2417 while Present
(Decl
) loop
2418 if Is_Declaration
(Decl
) then
2419 Decl_Id
:= Defining_Entity
(Decl
);
2421 if Is_Type
(Decl_Id
) then
2422 Build_Assertion_Bodies_For_Type
(Decl_Id
);
2428 end Build_Assertion_Bodies
;
2430 ---------------------------
2431 -- Check_Entry_Contracts --
2432 ---------------------------
2434 procedure Check_Entry_Contracts
is
2440 Ent
:= First_Entity
(Current_Scope
);
2441 while Present
(Ent
) loop
2443 -- This only concerns entries with pre/postconditions
2445 if Ekind
(Ent
) = E_Entry
2446 and then Present
(Contract
(Ent
))
2447 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
2449 ASN
:= Pre_Post_Conditions
(Contract
(Ent
));
2451 Install_Formals
(Ent
);
2453 -- Pre/postconditions are rewritten as Check pragmas. Analysis
2454 -- is performed on a copy of the pragma expression, to prevent
2455 -- modifying the original expression.
2457 while Present
(ASN
) loop
2458 if Nkind
(ASN
) = N_Pragma
then
2462 (First
(Pragma_Argument_Associations
(ASN
))));
2463 Set_Parent
(Exp
, ASN
);
2465 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
2468 ASN
:= Next_Pragma
(ASN
);
2476 end Check_Entry_Contracts
;
2478 ----------------------------------
2479 -- Contains_Lib_Incomplete_Type --
2480 ----------------------------------
2482 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean is
2486 -- Avoid looking through scopes that do not meet the precondition of
2487 -- Pkg not being within a library unit spec.
2489 if not Is_Compilation_Unit
(Pkg
)
2490 and then not Is_Generic_Instance
(Pkg
)
2491 and then not In_Package_Body
(Enclosing_Lib_Unit_Entity
(Pkg
))
2493 -- Loop through all entities in the current scope to identify
2494 -- an entity that depends on a private type.
2496 Curr
:= First_Entity
(Pkg
);
2498 if Nkind
(Curr
) in N_Entity
2499 and then Depends_On_Private
(Curr
)
2504 exit when Last_Entity
(Current_Scope
) = Curr
;
2510 end Contains_Lib_Incomplete_Type
;
2512 --------------------------------------
2513 -- Handle_Late_Controlled_Primitive --
2514 --------------------------------------
2516 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
) is
2517 Body_Spec
: constant Node_Id
:= Specification
(Body_Decl
);
2518 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2519 Loc
: constant Source_Ptr
:= Sloc
(Body_Id
);
2520 Params
: constant List_Id
:=
2521 Parameter_Specifications
(Body_Spec
);
2523 Spec_Id
: Entity_Id
;
2527 -- Consider only procedure bodies whose name matches one of the three
2528 -- controlled primitives.
2530 if Nkind
(Body_Spec
) /= N_Procedure_Specification
2531 or else Chars
(Body_Id
) not in Name_Adjust
2537 -- A controlled primitive must have exactly one formal which is not
2538 -- an anonymous access type.
2540 elsif List_Length
(Params
) /= 1 then
2544 Typ
:= Parameter_Type
(First
(Params
));
2546 if Nkind
(Typ
) = N_Access_Definition
then
2552 -- The type of the formal must be derived from [Limited_]Controlled
2554 if not Is_Controlled
(Entity
(Typ
)) then
2558 -- Check whether a specification exists for this body. We do not
2559 -- analyze the spec of the body in full, because it will be analyzed
2560 -- again when the body is properly analyzed, and we cannot create
2561 -- duplicate entries in the formals chain. We look for an explicit
2562 -- specification because the body may be an overriding operation and
2563 -- an inherited spec may be present.
2565 Spec_Id
:= Current_Entity
(Body_Id
);
2567 while Present
(Spec_Id
) loop
2568 if Ekind
(Spec_Id
) in E_Procedure | E_Generic_Procedure
2569 and then Scope
(Spec_Id
) = Current_Scope
2570 and then Present
(First_Formal
(Spec_Id
))
2571 and then No
(Next_Formal
(First_Formal
(Spec_Id
)))
2572 and then Etype
(First_Formal
(Spec_Id
)) = Entity
(Typ
)
2573 and then Comes_From_Source
(Spec_Id
)
2578 Spec_Id
:= Homonym
(Spec_Id
);
2581 -- At this point the body is known to be a late controlled primitive.
2582 -- Generate a matching spec and insert it before the body. Note the
2583 -- use of Copy_Separate_Tree - we want an entirely separate semantic
2584 -- tree in this case.
2586 Spec
:= Copy_Separate_Tree
(Body_Spec
);
2588 -- Ensure that the subprogram declaration does not inherit the null
2589 -- indicator from the body as we now have a proper spec/body pair.
2591 Set_Null_Present
(Spec
, False);
2593 -- Ensure that the freeze node is inserted after the declaration of
2594 -- the primitive since its expansion will freeze the primitive.
2596 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
2598 Insert_Before_And_Analyze
(Body_Decl
, Decl
);
2599 end Handle_Late_Controlled_Primitive
;
2601 ----------------------------------------
2602 -- Remove_Partial_Visible_Refinements --
2603 ----------------------------------------
2605 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2606 State_Elmt
: Elmt_Id
;
2608 if Present
(Abstract_States
(Spec_Id
)) then
2609 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2610 while Present
(State_Elmt
) loop
2611 Set_Has_Partial_Visible_Refinement
(Node
(State_Elmt
), False);
2612 Next_Elmt
(State_Elmt
);
2616 -- For a child unit, also hide the partial state refinement from
2617 -- ancestor packages.
2619 if Is_Child_Unit
(Spec_Id
) then
2620 Remove_Partial_Visible_Refinements
(Scope
(Spec_Id
));
2622 end Remove_Partial_Visible_Refinements
;
2624 --------------------------------
2625 -- Remove_Visible_Refinements --
2626 --------------------------------
2628 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2629 State_Elmt
: Elmt_Id
;
2631 if Present
(Abstract_States
(Spec_Id
)) then
2632 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2633 while Present
(State_Elmt
) loop
2634 Set_Has_Visible_Refinement
(Node
(State_Elmt
), False);
2635 Next_Elmt
(State_Elmt
);
2638 end Remove_Visible_Refinements
;
2640 ---------------------
2641 -- Resolve_Aspects --
2642 ---------------------
2644 procedure Resolve_Aspects
is
2648 E
:= First_Entity
(Current_Scope
);
2649 while Present
(E
) loop
2650 Resolve_Aspect_Expressions
(E
);
2652 -- Now that the aspect expressions have been resolved, if this is
2653 -- at the end of the visible declarations, we can set the flag
2654 -- Known_To_Have_Preelab_Init properly on types declared in the
2655 -- visible part, which is needed for checking whether full types
2656 -- in the private part satisfy the Preelaborable_Initialization
2657 -- aspect of the partial view. We can't wait for the creation of
2658 -- the pragma by Analyze_Aspects_At_Freeze_Point, because the
2659 -- freeze point may occur after the end of the package declaration
2660 -- (in the case of nested packages).
2663 and then L
= Visible_Declarations
(Parent
(L
))
2664 and then Has_Aspect
(E
, Aspect_Preelaborable_Initialization
)
2667 ASN
: constant Node_Id
:=
2668 Find_Aspect
(E
, Aspect_Preelaborable_Initialization
);
2669 Expr
: constant Node_Id
:= Expression
(ASN
);
2671 -- Set Known_To_Have_Preelab_Init to True if aspect has no
2672 -- expression, or if the expression is True (or was folded
2673 -- to True), or if the expression is a conjunction of one or
2674 -- more Preelaborable_Initialization attributes applied to
2675 -- formal types and wasn't folded to False. (Note that
2676 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes goes to
2677 -- Original_Node if needed, hence test for Standard_False.)
2679 if not Present
(Expr
)
2680 or else (Is_Entity_Name
(Expr
)
2681 and then Entity
(Expr
) = Standard_True
)
2683 (Is_Conjunction_Of_Formal_Preelab_Init_Attributes
(Expr
)
2685 not (Is_Entity_Name
(Expr
)
2686 and then Entity
(Expr
) = Standard_False
))
2688 Set_Known_To_Have_Preelab_Init
(E
);
2695 end Resolve_Aspects
;
2699 Context
: Node_Id
:= Empty
;
2700 Ctrl_Typ
: Entity_Id
:= Empty
;
2701 Freeze_From
: Entity_Id
:= Empty
;
2702 Next_Decl
: Node_Id
;
2704 -- Start of processing for Analyze_Declarations
2708 while Present
(Decl
) loop
2710 -- Complete analysis of declaration
2713 Next_Decl
:= Next
(Decl
);
2715 if No
(Freeze_From
) then
2716 Freeze_From
:= First_Entity
(Current_Scope
);
2719 -- Remember if the declaration we just processed is the full type
2720 -- declaration of a controlled type (to handle late overriding of
2721 -- initialize, adjust or finalize).
2723 if Nkind
(Decl
) = N_Full_Type_Declaration
2724 and then Is_Controlled
(Defining_Identifier
(Decl
))
2726 Ctrl_Typ
:= Defining_Identifier
(Decl
);
2729 -- At the end of a declarative part, freeze remaining entities
2730 -- declared in it. The end of the visible declarations of package
2731 -- specification is not the end of a declarative part if private
2732 -- declarations are present. The end of a package declaration is a
2733 -- freezing point only if it a library package. A task definition or
2734 -- protected type definition is not a freeze point either. Finally,
2735 -- we do not freeze entities in generic scopes, because there is no
2736 -- code generated for them and freeze nodes will be generated for
2739 -- The end of a package instantiation is not a freeze point, but
2740 -- for now we make it one, because the generic body is inserted
2741 -- (currently) immediately after. Generic instantiations will not
2742 -- be a freeze point once delayed freezing of bodies is implemented.
2743 -- (This is needed in any case for early instantiations ???).
2745 if No
(Next_Decl
) then
2746 if Nkind
(Parent
(L
)) = N_Component_List
then
2749 elsif Nkind
(Parent
(L
)) in
2750 N_Protected_Definition | N_Task_Definition
2752 Check_Entry_Contracts
;
2754 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
2755 if Nkind
(Parent
(L
)) = N_Package_Body
then
2756 Freeze_From
:= First_Entity
(Current_Scope
);
2759 -- There may have been several freezing points previously,
2760 -- for example object declarations or subprogram bodies, but
2761 -- at the end of a declarative part we check freezing from
2762 -- the beginning, even though entities may already be frozen,
2763 -- in order to perform visibility checks on delayed aspects.
2767 -- If the current scope is a generic subprogram body. Skip the
2768 -- generic formal parameters that are not frozen here.
2770 if Is_Subprogram
(Current_Scope
)
2771 and then Nkind
(Unit_Declaration_Node
(Current_Scope
)) =
2772 N_Generic_Subprogram_Declaration
2773 and then Present
(First_Entity
(Current_Scope
))
2775 while Is_Generic_Formal
(Freeze_From
) loop
2776 Next_Entity
(Freeze_From
);
2779 Freeze_All
(Freeze_From
, Decl
);
2780 Freeze_From
:= Last_Entity
(Current_Scope
);
2783 -- For declarations in a subprogram body there is no issue
2784 -- with name resolution in aspect specifications.
2786 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2787 Freeze_From
:= Last_Entity
(Current_Scope
);
2790 -- Current scope is a package specification
2792 elsif Scope
(Current_Scope
) /= Standard_Standard
2793 and then not Is_Child_Unit
(Current_Scope
)
2794 and then No
(Generic_Parent
(Parent
(L
)))
2796 -- ARM rule 13.1.1(11/3): usage names in aspect definitions are
2797 -- resolved at the end of the immediately enclosing declaration
2798 -- list (AI05-0183-1).
2802 elsif L
/= Visible_Declarations
(Parent
(L
))
2803 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
2807 -- End of a package declaration
2809 -- This is a freeze point because it is the end of a
2810 -- compilation unit.
2812 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2813 Freeze_From
:= Last_Entity
(Current_Scope
);
2815 -- At the end of the visible declarations the expressions in
2816 -- aspects of all entities declared so far must be resolved.
2817 -- The entities themselves might be frozen later, and the
2818 -- generated pragmas and attribute definition clauses analyzed
2819 -- in full at that point, but name resolution must take place
2821 -- In addition to being the proper semantics, this is mandatory
2822 -- within generic units, because global name capture requires
2823 -- those expressions to be analyzed, given that the generated
2824 -- pragmas do not appear in the original generic tree.
2826 elsif Serious_Errors_Detected
= 0 then
2830 -- If next node is a body then freeze all types before the body.
2831 -- An exception occurs for some expander-generated bodies. If these
2832 -- are generated at places where in general language rules would not
2833 -- allow a freeze point, then we assume that the expander has
2834 -- explicitly checked that all required types are properly frozen,
2835 -- and we do not cause general freezing here. This special circuit
2836 -- is used when the encountered body is marked as having already
2839 -- In all other cases (bodies that come from source, and expander
2840 -- generated bodies that have not been analyzed yet), freeze all
2841 -- types now. Note that in the latter case, the expander must take
2842 -- care to attach the bodies at a proper place in the tree so as to
2843 -- not cause unwanted freezing at that point.
2845 -- It is also necessary to check for a case where both an expression
2846 -- function is used and the current scope depends on an incomplete
2847 -- private type from a library unit, otherwise premature freezing of
2848 -- the private type will occur.
2850 elsif not Analyzed
(Next_Decl
) and then Is_Body
(Next_Decl
)
2851 and then ((Nkind
(Next_Decl
) /= N_Subprogram_Body
2852 or else not Was_Expression_Function
(Next_Decl
))
2853 or else (not Is_Ignored_Ghost_Entity
(Current_Scope
)
2854 and then not Contains_Lib_Incomplete_Type
2857 -- When a controlled type is frozen, the expander generates stream
2858 -- and controlled-type support routines. If the freeze is caused
2859 -- by the stand-alone body of Initialize, Adjust, or Finalize, the
2860 -- expander will end up using the wrong version of these routines,
2861 -- as the body has not been processed yet. To remedy this, detect
2862 -- a late controlled primitive and create a proper spec for it.
2863 -- This ensures that the primitive will override its inherited
2864 -- counterpart before the freeze takes place.
2866 -- If the declaration we just processed is a body, do not attempt
2867 -- to examine Next_Decl as the late primitive idiom can only apply
2868 -- to the first encountered body.
2870 -- ??? A cleaner approach may be possible and/or this solution
2871 -- could be extended to general-purpose late primitives.
2873 if Present
(Ctrl_Typ
) then
2875 -- No need to continue searching for late body overriding if
2876 -- the controlled type is already frozen.
2878 if Is_Frozen
(Ctrl_Typ
) then
2881 elsif Nkind
(Next_Decl
) = N_Subprogram_Body
then
2882 Handle_Late_Controlled_Primitive
(Next_Decl
);
2888 -- The generated body of an expression function does not freeze,
2889 -- unless it is a completion, in which case only the expression
2890 -- itself freezes. This is handled when the body itself is
2891 -- analyzed (see Freeze_Expr_Types, sem_ch6.adb).
2893 Freeze_All
(Freeze_From
, Decl
);
2894 Freeze_From
:= Last_Entity
(Current_Scope
);
2900 -- Post-freezing actions
2903 Context
:= Parent
(L
);
2905 -- Certain contract annotations have forward visibility semantics and
2906 -- must be analyzed after all declarative items have been processed.
2907 -- This timing ensures that entities referenced by such contracts are
2910 -- Analyze the contract of an immediately enclosing package spec or
2911 -- body first because other contracts may depend on its information.
2913 if Nkind
(Context
) = N_Package_Body
then
2914 Analyze_Package_Body_Contract
(Defining_Entity
(Context
));
2916 elsif Nkind
(Context
) = N_Package_Specification
then
2917 Analyze_Package_Contract
(Defining_Entity
(Context
));
2920 -- Analyze the contracts of various constructs in the declarative
2923 Analyze_Contracts
(L
);
2925 if Nkind
(Context
) = N_Package_Body
then
2927 -- Ensure that all abstract states and objects declared in the
2928 -- state space of a package body are utilized as constituents.
2930 Check_Unused_Body_States
(Defining_Entity
(Context
));
2932 -- State refinements are visible up to the end of the package body
2933 -- declarations. Hide the state refinements from visibility to
2934 -- restore the original state conditions.
2936 Remove_Visible_Refinements
(Corresponding_Spec
(Context
));
2937 Remove_Partial_Visible_Refinements
(Corresponding_Spec
(Context
));
2939 elsif Nkind
(Context
) = N_Package_Specification
then
2941 -- Partial state refinements are visible up to the end of the
2942 -- package spec declarations. Hide the partial state refinements
2943 -- from visibility to restore the original state conditions.
2945 Remove_Partial_Visible_Refinements
(Defining_Entity
(Context
));
2948 -- Verify that all abstract states found in any package declared in
2949 -- the input declarative list have proper refinements. The check is
2950 -- performed only when the context denotes a block, entry, package,
2951 -- protected, subprogram, or task body (SPARK RM 7.2.2(3)).
2953 Check_State_Refinements
(Context
);
2955 -- Create the subprogram bodies which verify the run-time semantics
2956 -- of pragmas Default_Initial_Condition and [Type_]Invariant for all
2957 -- types within the current declarative list. This ensures that all
2958 -- assertion expressions are preanalyzed and resolved at the end of
2959 -- the declarative part. Note that the resolution happens even when
2960 -- freezing does not take place.
2962 Build_Assertion_Bodies
(L
, Context
);
2964 end Analyze_Declarations
;
2966 -----------------------------------
2967 -- Analyze_Full_Type_Declaration --
2968 -----------------------------------
2970 procedure Analyze_Full_Type_Declaration
(N
: Node_Id
) is
2971 Def
: constant Node_Id
:= Type_Definition
(N
);
2972 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2976 Is_Remote
: constant Boolean :=
2977 (Is_Remote_Types
(Current_Scope
)
2978 or else Is_Remote_Call_Interface
(Current_Scope
))
2979 and then not (In_Private_Part
(Current_Scope
)
2980 or else In_Package_Body
(Current_Scope
));
2982 procedure Check_Nonoverridable_Aspects
;
2983 -- Apply the rule in RM 13.1.1(18.4/4) on iterator aspects that cannot
2984 -- be overridden, and can only be confirmed on derivation.
2986 procedure Check_Ops_From_Incomplete_Type
;
2987 -- If there is a tagged incomplete partial view of the type, traverse
2988 -- the primitives of the incomplete view and change the type of any
2989 -- controlling formals and result to indicate the full view. The
2990 -- primitives will be added to the full type's primitive operations
2991 -- list later in Sem_Disp.Check_Operation_From_Incomplete_Type (which
2992 -- is called from Process_Incomplete_Dependents).
2994 ----------------------------------
2995 -- Check_Nonoverridable_Aspects --
2996 ----------------------------------
2998 procedure Check_Nonoverridable_Aspects
is
2999 function Get_Aspect_Spec
3001 Aspect_Name
: Name_Id
) return Node_Id
;
3002 -- Check whether a list of aspect specifications includes an entry
3003 -- for a specific aspect. The list is either that of a partial or
3006 ---------------------
3007 -- Get_Aspect_Spec --
3008 ---------------------
3010 function Get_Aspect_Spec
3012 Aspect_Name
: Name_Id
) return Node_Id
3017 Spec
:= First
(Specs
);
3018 while Present
(Spec
) loop
3019 if Chars
(Identifier
(Spec
)) = Aspect_Name
then
3026 end Get_Aspect_Spec
;
3030 Prev_Aspects
: constant List_Id
:=
3031 Aspect_Specifications
(Parent
(Def_Id
));
3032 Par_Type
: Entity_Id
;
3033 Prev_Aspect
: Node_Id
;
3035 -- Start of processing for Check_Nonoverridable_Aspects
3038 -- Get parent type of derived type. Note that Prev is the entity in
3039 -- the partial declaration, but its contents are now those of full
3040 -- view, while Def_Id reflects the partial view.
3042 if Is_Private_Type
(Def_Id
) then
3043 Par_Type
:= Etype
(Full_View
(Def_Id
));
3045 Par_Type
:= Etype
(Def_Id
);
3048 -- If there is an inherited Implicit_Dereference, verify that it is
3049 -- made explicit in the partial view.
3051 if Has_Discriminants
(Base_Type
(Par_Type
))
3052 and then Nkind
(Parent
(Prev
)) = N_Full_Type_Declaration
3053 and then Present
(Discriminant_Specifications
(Parent
(Prev
)))
3054 and then Present
(Get_Reference_Discriminant
(Par_Type
))
3057 Get_Aspect_Spec
(Prev_Aspects
, Name_Implicit_Dereference
);
3061 (Discriminant_Specifications
3062 (Original_Node
(Parent
(Prev
))))
3065 ("type does not inherit implicit dereference", Prev
);
3068 -- If one of the views has the aspect specified, verify that it
3069 -- is consistent with that of the parent.
3072 Cur_Discr
: constant Entity_Id
:=
3073 Get_Reference_Discriminant
(Prev
);
3074 Par_Discr
: constant Entity_Id
:=
3075 Get_Reference_Discriminant
(Par_Type
);
3078 if Corresponding_Discriminant
(Cur_Discr
) /= Par_Discr
then
3080 ("aspect inconsistent with that of parent", N
);
3083 -- Check that specification in partial view matches the
3084 -- inherited aspect. Compare names directly because aspect
3085 -- expression may not be analyzed.
3087 if Present
(Prev_Aspect
)
3088 and then Nkind
(Expression
(Prev_Aspect
)) = N_Identifier
3089 and then Chars
(Expression
(Prev_Aspect
)) /=
3093 ("aspect inconsistent with that of parent", N
);
3099 -- What about other nonoverridable aspects???
3100 end Check_Nonoverridable_Aspects
;
3102 ------------------------------------
3103 -- Check_Ops_From_Incomplete_Type --
3104 ------------------------------------
3106 procedure Check_Ops_From_Incomplete_Type
is
3113 and then Ekind
(Prev
) = E_Incomplete_Type
3114 and then Is_Tagged_Type
(Prev
)
3115 and then Is_Tagged_Type
(T
)
3116 and then Present
(Primitive_Operations
(Prev
))
3118 Elmt
:= First_Elmt
(Primitive_Operations
(Prev
));
3119 while Present
(Elmt
) loop
3122 Formal
:= First_Formal
(Op
);
3123 while Present
(Formal
) loop
3124 if Etype
(Formal
) = Prev
then
3125 Set_Etype
(Formal
, T
);
3128 Next_Formal
(Formal
);
3131 if Etype
(Op
) = Prev
then
3138 end Check_Ops_From_Incomplete_Type
;
3140 -- Start of processing for Analyze_Full_Type_Declaration
3143 Prev
:= Find_Type_Name
(N
);
3145 -- The full view, if present, now points to the current type. If there
3146 -- is an incomplete partial view, set a link to it, to simplify the
3147 -- retrieval of primitive operations of the type.
3149 -- Ada 2005 (AI-50217): If the type was previously decorated when
3150 -- imported through a LIMITED WITH clause, it appears as incomplete
3151 -- but has no full view.
3153 if Ekind
(Prev
) = E_Incomplete_Type
3154 and then Present
(Full_View
(Prev
))
3156 T
:= Full_View
(Prev
);
3157 Set_Incomplete_View
(N
, Parent
(Prev
));
3162 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
3164 -- We set the flag Is_First_Subtype here. It is needed to set the
3165 -- corresponding flag for the Implicit class-wide-type created
3166 -- during tagged types processing.
3168 Set_Is_First_Subtype
(T
, True);
3170 -- Only composite types other than array types are allowed to have
3175 -- For derived types, the rule will be checked once we've figured
3176 -- out the parent type.
3178 when N_Derived_Type_Definition
=>
3181 -- For record types, discriminants are allowed.
3183 when N_Record_Definition
=>
3187 if Present
(Discriminant_Specifications
(N
)) then
3189 ("elementary or array type cannot have discriminants",
3191 (First
(Discriminant_Specifications
(N
))));
3195 -- Elaborate the type definition according to kind, and generate
3196 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3197 -- already done (this happens during the reanalysis that follows a call
3198 -- to the high level optimizer).
3200 if not Analyzed
(T
) then
3203 -- Set the SPARK mode from the current context
3205 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3206 Set_SPARK_Pragma_Inherited
(T
);
3209 when N_Access_To_Subprogram_Definition
=>
3210 Access_Subprogram_Declaration
(T
, Def
);
3212 -- If this is a remote access to subprogram, we must create the
3213 -- equivalent fat pointer type, and related subprograms.
3216 Process_Remote_AST_Declaration
(N
);
3219 -- Validate categorization rule against access type declaration
3220 -- usually a violation in Pure unit, Shared_Passive unit.
3222 Validate_Access_Type_Declaration
(T
, N
);
3224 -- If the type has contracts, we create the corresponding
3225 -- wrapper at once, before analyzing the aspect specifications,
3226 -- so that pre/postconditions can be handled directly on the
3227 -- generated wrapper.
3229 if Ada_Version
>= Ada_2022
3230 and then Present
(Aspect_Specifications
(N
))
3232 Build_Access_Subprogram_Wrapper
(N
);
3235 when N_Access_To_Object_Definition
=>
3236 Access_Type_Declaration
(T
, Def
);
3238 -- Validate categorization rule against access type declaration
3239 -- usually a violation in Pure unit, Shared_Passive unit.
3241 Validate_Access_Type_Declaration
(T
, N
);
3243 -- If we are in a Remote_Call_Interface package and define a
3244 -- RACW, then calling stubs and specific stream attributes
3248 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
3250 Add_RACW_Features
(Def_Id
);
3253 when N_Array_Type_Definition
=>
3254 Array_Type_Declaration
(T
, Def
);
3256 when N_Derived_Type_Definition
=>
3257 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
3259 -- Inherit predicates from parent, and protect against illegal
3262 if Is_Type
(T
) and then Has_Predicates
(T
) then
3263 Set_Has_Predicates
(Def_Id
);
3266 -- Save the scenario for examination by the ABE Processing
3269 Record_Elaboration_Scenario
(N
);
3271 when N_Enumeration_Type_Definition
=>
3272 Enumeration_Type_Declaration
(T
, Def
);
3274 when N_Floating_Point_Definition
=>
3275 Floating_Point_Type_Declaration
(T
, Def
);
3277 when N_Decimal_Fixed_Point_Definition
=>
3278 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
3280 when N_Ordinary_Fixed_Point_Definition
=>
3281 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
3283 when N_Signed_Integer_Type_Definition
=>
3284 Signed_Integer_Type_Declaration
(T
, Def
);
3286 when N_Modular_Type_Definition
=>
3287 Modular_Type_Declaration
(T
, Def
);
3289 when N_Record_Definition
=>
3290 Record_Type_Declaration
(T
, N
, Prev
);
3292 -- If declaration has a parse error, nothing to elaborate.
3298 raise Program_Error
;
3302 if Etype
(T
) = Any_Type
then
3306 -- Set the primitives list of the full type and its base type when
3307 -- needed. T may be E_Void in cases of earlier errors, and in that
3308 -- case we bypass this.
3310 if Ekind
(T
) /= E_Void
3311 and then not Present
(Direct_Primitive_Operations
(T
))
3313 if Etype
(T
) = T
then
3314 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3316 -- If Etype of T is the base type (as opposed to a parent type) and
3317 -- already has an associated list of primitive operations, then set
3318 -- T's primitive list to the base type's list. Otherwise, create a
3319 -- new empty primitives list and share the list between T and its
3320 -- base type. The lists need to be shared in common between the two.
3322 elsif Etype
(T
) = Base_Type
(T
) then
3324 if not Present
(Direct_Primitive_Operations
(Base_Type
(T
))) then
3325 Set_Direct_Primitive_Operations
3326 (Base_Type
(T
), New_Elmt_List
);
3329 Set_Direct_Primitive_Operations
3330 (T
, Direct_Primitive_Operations
(Base_Type
(T
)));
3332 -- Case where the Etype is a parent type, so we need a new primitives
3336 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3340 -- Some common processing for all types
3342 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
3343 Check_Ops_From_Incomplete_Type
;
3345 -- Both the declared entity, and its anonymous base type if one was
3346 -- created, need freeze nodes allocated.
3349 B
: constant Entity_Id
:= Base_Type
(T
);
3352 -- In the case where the base type differs from the first subtype, we
3353 -- pre-allocate a freeze node, and set the proper link to the first
3354 -- subtype. Freeze_Entity will use this preallocated freeze node when
3355 -- it freezes the entity.
3357 -- This does not apply if the base type is a generic type, whose
3358 -- declaration is independent of the current derived definition.
3360 if B
/= T
and then not Is_Generic_Type
(B
) then
3361 Ensure_Freeze_Node
(B
);
3362 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
3365 -- A type that is imported through a limited_with clause cannot
3366 -- generate any code, and thus need not be frozen. However, an access
3367 -- type with an imported designated type needs a finalization list,
3368 -- which may be referenced in some other package that has non-limited
3369 -- visibility on the designated type. Thus we must create the
3370 -- finalization list at the point the access type is frozen, to
3371 -- prevent unsatisfied references at link time.
3373 if not From_Limited_With
(T
) or else Is_Access_Type
(T
) then
3374 Set_Has_Delayed_Freeze
(T
);
3378 -- Case where T is the full declaration of some private type which has
3379 -- been swapped in Defining_Identifier (N).
3381 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
3382 Process_Full_View
(N
, T
, Def_Id
);
3384 -- Record the reference. The form of this is a little strange, since
3385 -- the full declaration has been swapped in. So the first parameter
3386 -- here represents the entity to which a reference is made which is
3387 -- the "real" entity, i.e. the one swapped in, and the second
3388 -- parameter provides the reference location.
3390 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3391 -- since we don't want a complaint about the full type being an
3392 -- unwanted reference to the private type
3395 B
: constant Boolean := Has_Pragma_Unreferenced
(T
);
3397 Set_Has_Pragma_Unreferenced
(T
, False);
3398 Generate_Reference
(T
, T
, 'c');
3399 Set_Has_Pragma_Unreferenced
(T
, B
);
3402 Set_Completion_Referenced
(Def_Id
);
3404 -- For completion of incomplete type, process incomplete dependents
3405 -- and always mark the full type as referenced (it is the incomplete
3406 -- type that we get for any real reference).
3408 elsif Ekind
(Prev
) = E_Incomplete_Type
then
3409 Process_Incomplete_Dependents
(N
, T
, Prev
);
3410 Generate_Reference
(Prev
, Def_Id
, 'c');
3411 Set_Completion_Referenced
(Def_Id
);
3413 -- If not private type or incomplete type completion, this is a real
3414 -- definition of a new entity, so record it.
3417 Generate_Definition
(Def_Id
);
3420 -- Propagate any pending access types whose finalization masters need to
3421 -- be fully initialized from the partial to the full view. Guard against
3422 -- an illegal full view that remains unanalyzed.
3424 if Is_Type
(Def_Id
) and then Is_Incomplete_Or_Private_Type
(Prev
) then
3425 Set_Pending_Access_Types
(Def_Id
, Pending_Access_Types
(Prev
));
3428 if Chars
(Scope
(Def_Id
)) = Name_System
3429 and then Chars
(Def_Id
) = Name_Address
3430 and then In_Predefined_Unit
(N
)
3432 Set_Is_Descendant_Of_Address
(Def_Id
);
3433 Set_Is_Descendant_Of_Address
(Base_Type
(Def_Id
));
3434 Set_Is_Descendant_Of_Address
(Prev
);
3437 Set_Optimize_Alignment_Flags
(Def_Id
);
3438 Check_Eliminated
(Def_Id
);
3440 -- If the declaration is a completion and aspects are present, apply
3441 -- them to the entity for the type which is currently the partial
3442 -- view, but which is the one that will be frozen.
3444 if Has_Aspects
(N
) then
3446 -- In most cases the partial view is a private type, and both views
3447 -- appear in different declarative parts. In the unusual case where
3448 -- the partial view is incomplete, perform the analysis on the
3449 -- full view, to prevent freezing anomalies with the corresponding
3450 -- class-wide type, which otherwise might be frozen before the
3451 -- dispatch table is built.
3454 and then Ekind
(Prev
) /= E_Incomplete_Type
3456 Analyze_Aspect_Specifications
(N
, Prev
);
3461 Analyze_Aspect_Specifications
(N
, Def_Id
);
3465 if Is_Derived_Type
(Prev
)
3466 and then Def_Id
/= Prev
3468 Check_Nonoverridable_Aspects
;
3470 end Analyze_Full_Type_Declaration
;
3472 ----------------------------------
3473 -- Analyze_Incomplete_Type_Decl --
3474 ----------------------------------
3476 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
3477 F
: constant Boolean := Is_Pure
(Current_Scope
);
3481 Generate_Definition
(Defining_Identifier
(N
));
3483 -- Process an incomplete declaration. The identifier must not have been
3484 -- declared already in the scope. However, an incomplete declaration may
3485 -- appear in the private part of a package, for a private type that has
3486 -- already been declared.
3488 -- In this case, the discriminants (if any) must match
3490 T
:= Find_Type_Name
(N
);
3492 Mutate_Ekind
(T
, E_Incomplete_Type
);
3494 Set_Is_First_Subtype
(T
);
3495 Reinit_Size_Align
(T
);
3497 -- Set the SPARK mode from the current context
3499 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3500 Set_SPARK_Pragma_Inherited
(T
);
3502 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
3503 -- incomplete types.
3505 if Tagged_Present
(N
) then
3506 Set_Is_Tagged_Type
(T
, True);
3507 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3508 Make_Class_Wide_Type
(T
);
3511 -- For tagged types, or when prefixed-call syntax is allowed for
3512 -- untagged types, initialize the list of primitive operations to
3515 if Tagged_Present
(N
)
3516 or else Extensions_Allowed
3518 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3521 Set_Stored_Constraint
(T
, No_Elist
);
3523 if Present
(Discriminant_Specifications
(N
)) then
3525 Process_Discriminants
(N
);
3529 -- If the type has discriminants, nontrivial subtypes may be declared
3530 -- before the full view of the type. The full views of those subtypes
3531 -- will be built after the full view of the type.
3533 Set_Private_Dependents
(T
, New_Elmt_List
);
3535 end Analyze_Incomplete_Type_Decl
;
3537 -----------------------------------
3538 -- Analyze_Interface_Declaration --
3539 -----------------------------------
3541 procedure Analyze_Interface_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
3542 CW
: constant Entity_Id
:= Class_Wide_Type
(T
);
3545 Set_Is_Tagged_Type
(T
);
3546 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3548 Set_Is_Limited_Record
(T
, Limited_Present
(Def
)
3549 or else Task_Present
(Def
)
3550 or else Protected_Present
(Def
)
3551 or else Synchronized_Present
(Def
));
3553 -- Type is abstract if full declaration carries keyword, or if previous
3554 -- partial view did.
3556 Set_Is_Abstract_Type
(T
);
3557 Set_Is_Interface
(T
);
3559 -- Type is a limited interface if it includes the keyword limited, task,
3560 -- protected, or synchronized.
3562 Set_Is_Limited_Interface
3563 (T
, Limited_Present
(Def
)
3564 or else Protected_Present
(Def
)
3565 or else Synchronized_Present
(Def
)
3566 or else Task_Present
(Def
));
3568 Set_Interfaces
(T
, New_Elmt_List
);
3569 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3571 -- Complete the decoration of the class-wide entity if it was already
3572 -- built (i.e. during the creation of the limited view)
3574 if Present
(CW
) then
3575 Set_Is_Interface
(CW
);
3576 Set_Is_Limited_Interface
(CW
, Is_Limited_Interface
(T
));
3579 -- Check runtime support for synchronized interfaces
3581 if Is_Concurrent_Interface
(T
)
3582 and then not RTE_Available
(RE_Select_Specific_Data
)
3584 Error_Msg_CRT
("synchronized interfaces", T
);
3586 end Analyze_Interface_Declaration
;
3588 -----------------------------
3589 -- Analyze_Itype_Reference --
3590 -----------------------------
3592 -- Nothing to do. This node is placed in the tree only for the benefit of
3593 -- back end processing, and has no effect on the semantic processing.
3595 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
3597 pragma Assert
(Is_Itype
(Itype
(N
)));
3599 end Analyze_Itype_Reference
;
3601 --------------------------------
3602 -- Analyze_Number_Declaration --
3603 --------------------------------
3605 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
3606 E
: constant Node_Id
:= Expression
(N
);
3607 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3608 Index
: Interp_Index
;
3613 Generate_Definition
(Id
);
3616 -- This is an optimization of a common case of an integer literal
3618 if Nkind
(E
) = N_Integer_Literal
then
3619 Set_Is_Static_Expression
(E
, True);
3620 Set_Etype
(E
, Universal_Integer
);
3622 Set_Etype
(Id
, Universal_Integer
);
3623 Mutate_Ekind
(Id
, E_Named_Integer
);
3624 Set_Is_Frozen
(Id
, True);
3626 Set_Debug_Info_Needed
(Id
);
3630 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3632 -- Process expression, replacing error by integer zero, to avoid
3633 -- cascaded errors or aborts further along in the processing
3635 -- Replace Error by integer zero, which seems least likely to cause
3639 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), Uint_0
));
3640 Set_Error_Posted
(E
);
3645 -- Verify that the expression is static and numeric. If
3646 -- the expression is overloaded, we apply the preference
3647 -- rule that favors root numeric types.
3649 if not Is_Overloaded
(E
) then
3651 if Has_Dynamic_Predicate_Aspect
(T
) then
3653 ("subtype has dynamic predicate, "
3654 & "not allowed in number declaration", N
);
3660 Get_First_Interp
(E
, Index
, It
);
3661 while Present
(It
.Typ
) loop
3662 if (Is_Integer_Type
(It
.Typ
) or else Is_Real_Type
(It
.Typ
))
3663 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
3665 if T
= Any_Type
then
3668 elsif Is_Universal_Numeric_Type
(It
.Typ
) then
3669 -- Choose universal interpretation over any other
3676 Get_Next_Interp
(Index
, It
);
3680 if Is_Integer_Type
(T
) then
3682 Set_Etype
(Id
, Universal_Integer
);
3683 Mutate_Ekind
(Id
, E_Named_Integer
);
3685 elsif Is_Real_Type
(T
) then
3687 -- Because the real value is converted to universal_real, this is a
3688 -- legal context for a universal fixed expression.
3690 if T
= Universal_Fixed
then
3692 Loc
: constant Source_Ptr
:= Sloc
(N
);
3693 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3695 New_Occurrence_Of
(Universal_Real
, Loc
),
3696 Expression
=> Relocate_Node
(E
));
3703 elsif T
= Any_Fixed
then
3704 Error_Msg_N
("illegal context for mixed mode operation", E
);
3706 -- Expression is of the form : universal_fixed * integer. Try to
3707 -- resolve as universal_real.
3709 T
:= Universal_Real
;
3714 Set_Etype
(Id
, Universal_Real
);
3715 Mutate_Ekind
(Id
, E_Named_Real
);
3718 Wrong_Type
(E
, Any_Numeric
);
3722 Mutate_Ekind
(Id
, E_Constant
);
3723 Set_Never_Set_In_Source
(Id
, True);
3724 Set_Is_True_Constant
(Id
, True);
3728 if Nkind
(E
) in N_Integer_Literal | N_Real_Literal
then
3729 Set_Etype
(E
, Etype
(Id
));
3732 if not Is_OK_Static_Expression
(E
) then
3733 Flag_Non_Static_Expr
3734 ("non-static expression used in number declaration!", E
);
3735 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
3736 Set_Etype
(E
, Any_Type
);
3739 Analyze_Dimension
(N
);
3740 end Analyze_Number_Declaration
;
3742 --------------------------------
3743 -- Analyze_Object_Declaration --
3744 --------------------------------
3746 -- WARNING: This routine manages Ghost regions. Return statements must be
3747 -- replaced by gotos which jump to the end of the routine and restore the
3750 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
3751 Loc
: constant Source_Ptr
:= Sloc
(N
);
3752 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3753 Next_Decl
: constant Node_Id
:= Next
(N
);
3758 E
: Node_Id
:= Expression
(N
);
3759 -- E is set to Expression (N) throughout this routine. When Expression
3760 -- (N) is modified, E is changed accordingly.
3762 procedure Check_Dynamic_Object
(Typ
: Entity_Id
);
3763 -- A library-level object with nonstatic discriminant constraints may
3764 -- require dynamic allocation. The declaration is illegal if the
3765 -- profile includes the restriction No_Implicit_Heap_Allocations.
3767 procedure Check_For_Null_Excluding_Components
3768 (Obj_Typ
: Entity_Id
;
3769 Obj_Decl
: Node_Id
);
3770 -- Verify that each null-excluding component of object declaration
3771 -- Obj_Decl carrying type Obj_Typ has explicit initialization. Emit
3772 -- a compile-time warning if this is not the case.
3774 function Count_Tasks
(T
: Entity_Id
) return Uint
;
3775 -- This function is called when a non-generic library level object of a
3776 -- task type is declared. Its function is to count the static number of
3777 -- tasks declared within the type (it is only called if Has_Task is set
3778 -- for T). As a side effect, if an array of tasks with nonstatic bounds
3779 -- or a variant record type is encountered, Check_Restriction is called
3780 -- indicating the count is unknown.
3782 function Delayed_Aspect_Present
return Boolean;
3783 -- If the declaration has an expression that is an aggregate, and it
3784 -- has aspects that require delayed analysis, the resolution of the
3785 -- aggregate must be deferred to the freeze point of the object. This
3786 -- special processing was created for address clauses, but it must
3787 -- also apply to address aspects. This must be done before the aspect
3788 -- specifications are analyzed because we must handle the aggregate
3789 -- before the analysis of the object declaration is complete.
3791 -- Any other relevant delayed aspects on object declarations ???
3793 --------------------------
3794 -- Check_Dynamic_Object --
3795 --------------------------
3797 procedure Check_Dynamic_Object
(Typ
: Entity_Id
) is
3799 Obj_Type
: Entity_Id
;
3804 if Is_Private_Type
(Obj_Type
)
3805 and then Present
(Full_View
(Obj_Type
))
3807 Obj_Type
:= Full_View
(Obj_Type
);
3810 if Known_Static_Esize
(Obj_Type
) then
3814 if Restriction_Active
(No_Implicit_Heap_Allocations
)
3815 and then Expander_Active
3816 and then Has_Discriminants
(Obj_Type
)
3818 Comp
:= First_Component
(Obj_Type
);
3819 while Present
(Comp
) loop
3820 if Known_Static_Esize
(Etype
(Comp
))
3821 or else Size_Known_At_Compile_Time
(Etype
(Comp
))
3825 elsif not Discriminated_Size
(Comp
)
3826 and then Comes_From_Source
(Comp
)
3829 ("component& of non-static size will violate restriction "
3830 & "No_Implicit_Heap_Allocation?", N
, Comp
);
3832 elsif Is_Record_Type
(Etype
(Comp
)) then
3833 Check_Dynamic_Object
(Etype
(Comp
));
3836 Next_Component
(Comp
);
3839 end Check_Dynamic_Object
;
3841 -----------------------------------------
3842 -- Check_For_Null_Excluding_Components --
3843 -----------------------------------------
3845 procedure Check_For_Null_Excluding_Components
3846 (Obj_Typ
: Entity_Id
;
3849 procedure Check_Component
3850 (Comp_Typ
: Entity_Id
;
3851 Comp_Decl
: Node_Id
:= Empty
;
3852 Array_Comp
: Boolean := False);
3853 -- Apply a compile-time null-exclusion check on a component denoted
3854 -- by its declaration Comp_Decl and type Comp_Typ, and all of its
3855 -- subcomponents (if any).
3857 ---------------------
3858 -- Check_Component --
3859 ---------------------
3861 procedure Check_Component
3862 (Comp_Typ
: Entity_Id
;
3863 Comp_Decl
: Node_Id
:= Empty
;
3864 Array_Comp
: Boolean := False)
3870 -- Do not consider internally-generated components or those that
3871 -- are already initialized.
3873 if Present
(Comp_Decl
)
3874 and then (not Comes_From_Source
(Comp_Decl
)
3875 or else Present
(Expression
(Comp_Decl
)))
3880 if Is_Incomplete_Or_Private_Type
(Comp_Typ
)
3881 and then Present
(Full_View
(Comp_Typ
))
3883 T
:= Full_View
(Comp_Typ
);
3888 -- Verify a component of a null-excluding access type
3890 if Is_Access_Type
(T
)
3891 and then Can_Never_Be_Null
(T
)
3893 if Comp_Decl
= Obj_Decl
then
3894 Null_Exclusion_Static_Checks
3897 Array_Comp
=> Array_Comp
);
3900 Null_Exclusion_Static_Checks
3903 Array_Comp
=> Array_Comp
);
3906 -- Check array components
3908 elsif Is_Array_Type
(T
) then
3910 -- There is no suitable component when the object is of an
3911 -- array type. However, a namable component may appear at some
3912 -- point during the recursive inspection, but not at the top
3913 -- level. At the top level just indicate array component case.
3915 if Comp_Decl
= Obj_Decl
then
3916 Check_Component
(Component_Type
(T
), Array_Comp
=> True);
3918 Check_Component
(Component_Type
(T
), Comp_Decl
);
3921 -- Verify all components of type T
3923 -- Note: No checks are performed on types with discriminants due
3924 -- to complexities involving variants. ???
3926 elsif (Is_Concurrent_Type
(T
)
3927 or else Is_Incomplete_Or_Private_Type
(T
)
3928 or else Is_Record_Type
(T
))
3929 and then not Has_Discriminants
(T
)
3931 Comp
:= First_Component
(T
);
3932 while Present
(Comp
) loop
3933 Check_Component
(Etype
(Comp
), Parent
(Comp
));
3935 Next_Component
(Comp
);
3938 end Check_Component
;
3940 -- Start processing for Check_For_Null_Excluding_Components
3943 Check_Component
(Obj_Typ
, Obj_Decl
);
3944 end Check_For_Null_Excluding_Components
;
3950 function Count_Tasks
(T
: Entity_Id
) return Uint
is
3956 if Is_Task_Type
(T
) then
3959 elsif Is_Record_Type
(T
) then
3960 if Has_Discriminants
(T
) then
3961 Check_Restriction
(Max_Tasks
, N
);
3966 C
:= First_Component
(T
);
3967 while Present
(C
) loop
3968 V
:= V
+ Count_Tasks
(Etype
(C
));
3975 elsif Is_Array_Type
(T
) then
3976 X
:= First_Index
(T
);
3977 V
:= Count_Tasks
(Component_Type
(T
));
3978 while Present
(X
) loop
3981 if not Is_OK_Static_Subtype
(C
) then
3982 Check_Restriction
(Max_Tasks
, N
);
3985 V
:= V
* (UI_Max
(Uint_0
,
3986 Expr_Value
(Type_High_Bound
(C
)) -
3987 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
4000 ----------------------------
4001 -- Delayed_Aspect_Present --
4002 ----------------------------
4004 function Delayed_Aspect_Present
return Boolean is
4009 if Present
(Aspect_Specifications
(N
)) then
4010 A
:= First
(Aspect_Specifications
(N
));
4012 while Present
(A
) loop
4013 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(A
)));
4015 if A_Id
= Aspect_Address
then
4017 -- Set flag on object entity, for later processing at
4018 -- the freeze point.
4020 Set_Has_Delayed_Aspects
(Id
);
4029 end Delayed_Aspect_Present
;
4033 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4034 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
4035 -- Save the Ghost-related attributes to restore on exit
4037 Prev_Entity
: Entity_Id
:= Empty
;
4038 Related_Id
: Entity_Id
;
4039 Full_View_Present
: Boolean := False;
4041 -- Start of processing for Analyze_Object_Declaration
4044 -- There are three kinds of implicit types generated by an
4045 -- object declaration:
4047 -- 1. Those generated by the original Object Definition
4049 -- 2. Those generated by the Expression
4051 -- 3. Those used to constrain the Object Definition with the
4052 -- expression constraints when the definition is unconstrained.
4054 -- They must be generated in this order to avoid order of elaboration
4055 -- issues. Thus the first step (after entering the name) is to analyze
4056 -- the object definition.
4058 if Constant_Present
(N
) then
4059 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
4061 if Present
(Prev_Entity
)
4063 -- If the homograph is an implicit subprogram, it is overridden
4064 -- by the current declaration.
4066 ((Is_Overloadable
(Prev_Entity
)
4067 and then Is_Inherited_Operation
(Prev_Entity
))
4069 -- The current object is a discriminal generated for an entry
4070 -- family index. Even though the index is a constant, in this
4071 -- particular context there is no true constant redeclaration.
4072 -- Enter_Name will handle the visibility.
4075 (Is_Discriminal
(Id
)
4076 and then Ekind
(Discriminal_Link
(Id
)) =
4077 E_Entry_Index_Parameter
)
4079 -- The current object is the renaming for a generic declared
4080 -- within the instance.
4083 (Ekind
(Prev_Entity
) = E_Package
4084 and then Nkind
(Parent
(Prev_Entity
)) =
4085 N_Package_Renaming_Declaration
4086 and then not Comes_From_Source
(Prev_Entity
)
4088 Is_Generic_Instance
(Renamed_Entity
(Prev_Entity
)))
4090 -- The entity may be a homonym of a private component of the
4091 -- enclosing protected object, for which we create a local
4092 -- renaming declaration. The declaration is legal, even if
4093 -- useless when it just captures that component.
4096 (Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
4097 and then Nkind
(Parent
(Prev_Entity
)) =
4098 N_Object_Renaming_Declaration
))
4100 Prev_Entity
:= Empty
;
4104 if Present
(Prev_Entity
) then
4106 -- The object declaration is Ghost when it completes a deferred Ghost
4109 Mark_And_Set_Ghost_Completion
(N
, Prev_Entity
);
4111 Constant_Redeclaration
(Id
, N
, T
);
4113 Generate_Reference
(Prev_Entity
, Id
, 'c');
4114 Set_Completion_Referenced
(Id
);
4116 if Error_Posted
(N
) then
4118 -- Type mismatch or illegal redeclaration; do not analyze
4119 -- expression to avoid cascaded errors.
4121 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4123 Mutate_Ekind
(Id
, E_Variable
);
4127 -- In the normal case, enter identifier at the start to catch premature
4128 -- usage in the initialization expression.
4131 Generate_Definition
(Id
);
4134 Mark_Coextensions
(N
, Object_Definition
(N
));
4136 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4138 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
4140 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4141 and then Protected_Present
4142 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4144 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
4147 if Error_Posted
(Id
) then
4149 Mutate_Ekind
(Id
, E_Variable
);
4154 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
4155 -- out some static checks.
4157 if Ada_Version
>= Ada_2005
then
4159 -- In case of aggregates we must also take care of the correct
4160 -- initialization of nested aggregates bug this is done at the
4161 -- point of the analysis of the aggregate (see sem_aggr.adb) ???
4163 if Can_Never_Be_Null
(T
) then
4164 if Present
(Expression
(N
))
4165 and then Nkind
(Expression
(N
)) = N_Aggregate
4169 elsif Comes_From_Source
(Id
) then
4171 Save_Typ
: constant Entity_Id
:= Etype
(Id
);
4173 Set_Etype
(Id
, T
); -- Temp. decoration for static checks
4174 Null_Exclusion_Static_Checks
(N
);
4175 Set_Etype
(Id
, Save_Typ
);
4179 -- We might be dealing with an object of a composite type containing
4180 -- null-excluding components without an aggregate, so we must verify
4181 -- that such components have default initialization.
4184 Check_For_Null_Excluding_Components
(T
, N
);
4188 -- Object is marked pure if it is in a pure scope
4190 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
4192 -- If deferred constant, make sure context is appropriate. We detect
4193 -- a deferred constant as a constant declaration with no expression.
4194 -- A deferred constant can appear in a package body if its completion
4195 -- is by means of an interface pragma.
4197 if Constant_Present
(N
) and then No
(E
) then
4199 -- A deferred constant may appear in the declarative part of the
4200 -- following constructs:
4204 -- extended return statements
4207 -- subprogram bodies
4210 -- When declared inside a package spec, a deferred constant must be
4211 -- completed by a full constant declaration or pragma Import. In all
4212 -- other cases, the only proper completion is pragma Import. Extended
4213 -- return statements are flagged as invalid contexts because they do
4214 -- not have a declarative part and so cannot accommodate the pragma.
4216 if Ekind
(Current_Scope
) = E_Return_Statement
then
4218 ("invalid context for deferred constant declaration (RM 7.4)",
4221 ("\declaration requires an initialization expression",
4223 Set_Constant_Present
(N
, False);
4225 -- In Ada 83, deferred constant must be of private type
4227 elsif not Is_Private_Type
(T
) then
4228 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4230 ("(Ada 83) deferred constant must be private type", N
);
4234 -- If not a deferred constant, then the object declaration freezes
4235 -- its type, unless the object is of an anonymous type and has delayed
4236 -- aspects. In that case the type is frozen when the object itself is.
4239 Check_Fully_Declared
(T
, N
);
4241 if Has_Delayed_Aspects
(Id
)
4242 and then Is_Array_Type
(T
)
4243 and then Is_Itype
(T
)
4245 Set_Has_Delayed_Freeze
(T
);
4247 Freeze_Before
(N
, T
);
4251 -- If the object was created by a constrained array definition, then
4252 -- set the link in both the anonymous base type and anonymous subtype
4253 -- that are built to represent the array type to point to the object.
4255 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
4256 N_Constrained_Array_Definition
4258 Set_Related_Array_Object
(T
, Id
);
4259 Set_Related_Array_Object
(Base_Type
(T
), Id
);
4262 -- Check for protected objects not at library level
4264 if Has_Protected
(T
) and then not Is_Library_Level_Entity
(Id
) then
4265 Check_Restriction
(No_Local_Protected_Objects
, Id
);
4268 -- Check for violation of No_Local_Timing_Events
4270 if Has_Timing_Event
(T
) and then not Is_Library_Level_Entity
(Id
) then
4271 Check_Restriction
(No_Local_Timing_Events
, Id
);
4274 -- The actual subtype of the object is the nominal subtype, unless
4275 -- the nominal one is unconstrained and obtained from the expression.
4279 if Is_Library_Level_Entity
(Id
) then
4280 Check_Dynamic_Object
(T
);
4283 -- Process initialization expression if present and not in error
4285 if Present
(E
) and then E
/= Error
then
4287 -- Generate an error in case of CPP class-wide object initialization.
4288 -- Required because otherwise the expansion of the class-wide
4289 -- assignment would try to use 'size to initialize the object
4290 -- (primitive that is not available in CPP tagged types).
4292 if Is_Class_Wide_Type
(Act_T
)
4294 (Is_CPP_Class
(Root_Type
(Etype
(Act_T
)))
4296 (Present
(Full_View
(Root_Type
(Etype
(Act_T
))))
4298 Is_CPP_Class
(Full_View
(Root_Type
(Etype
(Act_T
))))))
4301 ("predefined assignment not available for 'C'P'P tagged types",
4305 Mark_Coextensions
(N
, E
);
4308 -- In case of errors detected in the analysis of the expression,
4309 -- decorate it with the expected type to avoid cascaded errors.
4311 if No
(Etype
(E
)) then
4315 -- If an initialization expression is present, then we set the
4316 -- Is_True_Constant flag. It will be reset if this is a variable
4317 -- and it is indeed modified.
4319 Set_Is_True_Constant
(Id
, True);
4321 -- If we are analyzing a constant declaration, set its completion
4322 -- flag after analyzing and resolving the expression.
4324 if Constant_Present
(N
) then
4325 Set_Has_Completion
(Id
);
4328 -- Set type and resolve (type may be overridden later on). Note:
4329 -- Ekind (Id) must still be E_Void at this point so that incorrect
4330 -- early usage within E is properly diagnosed.
4334 -- If the expression is an aggregate we must look ahead to detect
4335 -- the possible presence of an address clause, and defer resolution
4336 -- and expansion of the aggregate to the freeze point of the entity.
4338 -- This is not always legal because the aggregate may contain other
4339 -- references that need freezing, e.g. references to other entities
4340 -- with address clauses. In any case, when compiling with -gnatI the
4341 -- presence of the address clause must be ignored.
4343 if Comes_From_Source
(N
)
4344 and then Expander_Active
4345 and then Nkind
(E
) = N_Aggregate
4347 ((Present
(Following_Address_Clause
(N
))
4348 and then not Ignore_Rep_Clauses
)
4349 or else Delayed_Aspect_Present
)
4353 -- If the aggregate is limited it will be built in place, and its
4354 -- expansion is deferred until the object declaration is expanded.
4356 -- This is also required when generating C code to ensure that an
4357 -- object with an alignment or address clause can be initialized
4358 -- by means of component by component assignments.
4360 if Is_Limited_Type
(T
) or else Modify_Tree_For_C
then
4361 Set_Expansion_Delayed
(E
);
4365 -- If the expression is a formal that is a "subprogram pointer"
4366 -- this is illegal in accessibility terms (see RM 3.10.2 (13.1/2)
4367 -- and AARM 3.10.2 (13.b/2)). Add an explicit conversion to force
4368 -- the corresponding check, as is done for assignments.
4370 if Is_Entity_Name
(E
)
4371 and then Present
(Entity
(E
))
4372 and then Is_Formal
(Entity
(E
))
4374 Ekind
(Etype
(Entity
(E
))) = E_Anonymous_Access_Subprogram_Type
4375 and then Ekind
(T
) /= E_Anonymous_Access_Subprogram_Type
4377 Rewrite
(E
, Convert_To
(T
, Relocate_Node
(E
)));
4383 -- No further action needed if E is a call to an inlined function
4384 -- which returns an unconstrained type and it has been expanded into
4385 -- a procedure call. In that case N has been replaced by an object
4386 -- declaration without initializing expression and it has been
4387 -- analyzed (see Expand_Inlined_Call).
4389 if Back_End_Inlining
4390 and then Expander_Active
4391 and then Nkind
(E
) = N_Function_Call
4392 and then Nkind
(Name
(E
)) in N_Has_Entity
4393 and then Is_Inlined
(Entity
(Name
(E
)))
4394 and then not Is_Constrained
(Etype
(E
))
4395 and then Analyzed
(N
)
4396 and then No
(Expression
(N
))
4401 -- If E is null and has been replaced by an N_Raise_Constraint_Error
4402 -- node (which was marked already-analyzed), we need to set the type
4403 -- to something other than Any_Access in order to keep gigi happy.
4405 if Etype
(E
) = Any_Access
then
4409 -- If the object is an access to variable, the initialization
4410 -- expression cannot be an access to constant.
4412 if Is_Access_Type
(T
)
4413 and then not Is_Access_Constant
(T
)
4414 and then Is_Access_Type
(Etype
(E
))
4415 and then Is_Access_Constant
(Etype
(E
))
4418 ("access to variable cannot be initialized with an "
4419 & "access-to-constant expression", E
);
4422 if not Assignment_OK
(N
) then
4423 Check_Initialization
(T
, E
);
4426 Check_Unset_Reference
(E
);
4428 -- If this is a variable, then set current value. If this is a
4429 -- declared constant of a scalar type with a static expression,
4430 -- indicate that it is always valid.
4432 if not Constant_Present
(N
) then
4433 if Compile_Time_Known_Value
(E
) then
4434 Set_Current_Value
(Id
, E
);
4437 elsif Is_Scalar_Type
(T
) and then Is_OK_Static_Expression
(E
) then
4438 Set_Is_Known_Valid
(Id
);
4440 -- If it is a constant initialized with a valid nonstatic entity,
4441 -- the constant is known valid as well, and can inherit the subtype
4442 -- of the entity if it is a subtype of the given type. This info
4443 -- is preserved on the actual subtype of the constant.
4445 elsif Is_Scalar_Type
(T
)
4446 and then Is_Entity_Name
(E
)
4447 and then Is_Known_Valid
(Entity
(E
))
4448 and then In_Subrange_Of
(Etype
(Entity
(E
)), T
)
4450 Set_Is_Known_Valid
(Id
);
4451 Mutate_Ekind
(Id
, E_Constant
);
4452 Set_Actual_Subtype
(Id
, Etype
(Entity
(E
)));
4455 -- Deal with setting of null flags
4457 if Is_Access_Type
(T
) then
4458 if Known_Non_Null
(E
) then
4459 Set_Is_Known_Non_Null
(Id
, True);
4460 elsif Known_Null
(E
) and then not Can_Never_Be_Null
(Id
) then
4461 Set_Is_Known_Null
(Id
, True);
4465 -- Check incorrect use of dynamically tagged expressions
4467 if Is_Tagged_Type
(T
) then
4468 Check_Dynamically_Tagged_Expression
4474 Apply_Scalar_Range_Check
(E
, T
);
4475 Apply_Static_Length_Check
(E
, T
);
4477 -- A formal parameter of a specific tagged type whose related
4478 -- subprogram is subject to pragma Extensions_Visible with value
4479 -- "False" cannot be implicitly converted to a class-wide type by
4480 -- means of an initialization expression (SPARK RM 6.1.7(3)). Do
4481 -- not consider internally generated expressions.
4483 if Is_Class_Wide_Type
(T
)
4484 and then Comes_From_Source
(E
)
4485 and then Is_EVF_Expression
(E
)
4488 ("formal parameter cannot be implicitly converted to "
4489 & "class-wide type when Extensions_Visible is False", E
);
4493 -- If the No_Streams restriction is set, check that the type of the
4494 -- object is not, and does not contain, any subtype derived from
4495 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
4496 -- Has_Stream just for efficiency reasons. There is no point in
4497 -- spending time on a Has_Stream check if the restriction is not set.
4499 if Restriction_Check_Required
(No_Streams
) then
4500 if Has_Stream
(T
) then
4501 Check_Restriction
(No_Streams
, N
);
4505 -- Deal with predicate check before we start to do major rewriting. It
4506 -- is OK to initialize and then check the initialized value, since the
4507 -- object goes out of scope if we get a predicate failure. Note that we
4508 -- do this in the analyzer and not the expander because the analyzer
4509 -- does some substantial rewriting in some cases.
4511 -- We need a predicate check if the type has predicates that are not
4512 -- ignored, and if either there is an initializing expression, or for
4513 -- default initialization when we have at least one case of an explicit
4514 -- default initial value (including via a Default_Value or
4515 -- Default_Component_Value aspect, see AI12-0301) and then this is not
4516 -- an internal declaration whose initialization comes later (as for an
4517 -- aggregate expansion) or a deferred constant.
4518 -- If expression is an aggregate it may be expanded into assignments
4519 -- and the declaration itself is marked with No_Initialization, but
4520 -- the predicate still applies.
4522 if not Suppress_Assignment_Checks
(N
)
4523 and then (Predicate_Enabled
(T
) or else Has_Static_Predicate
(T
))
4525 (not No_Initialization
(N
)
4526 or else (Present
(E
) and then Nkind
(E
) = N_Aggregate
))
4530 Is_Partially_Initialized_Type
(T
, Include_Implicit
=> False))
4531 and then not (Constant_Present
(N
) and then No
(E
))
4533 -- If the type has a static predicate and the expression is known at
4534 -- compile time, see if the expression satisfies the predicate.
4535 -- In the case of a static expression, this must be done even if
4536 -- the predicate is not enabled (as per static expression rules).
4539 Check_Expression_Against_Static_Predicate
(E
, T
);
4542 -- Do not perform further predicate-related checks unless
4543 -- predicates are enabled for the subtype.
4545 if not Predicate_Enabled
(T
) then
4548 -- If the type is a null record and there is no explicit initial
4549 -- expression, no predicate check applies.
4551 elsif No
(E
) and then Is_Null_Record_Type
(T
) then
4554 -- Do not generate a predicate check if the initialization expression
4555 -- is a type conversion because the conversion has been subjected to
4556 -- the same check. This is a small optimization which avoid redundant
4559 elsif Present
(E
) and then Nkind
(E
) = N_Type_Conversion
then
4563 -- The check must be inserted after the expanded aggregate
4564 -- expansion code, if any.
4567 Check
: constant Node_Id
:=
4568 Make_Predicate_Check
(T
, New_Occurrence_Of
(Id
, Loc
));
4571 if No
(Next_Decl
) then
4572 Append_To
(List_Containing
(N
), Check
);
4574 Insert_Before
(Next_Decl
, Check
);
4580 -- Case of unconstrained type
4582 if not Is_Definite_Subtype
(T
) then
4584 -- Nothing to do in deferred constant case
4586 if Constant_Present
(N
) and then No
(E
) then
4589 -- Case of no initialization present
4592 if No_Initialization
(N
) then
4595 elsif Is_Class_Wide_Type
(T
) then
4597 ("initialization required in class-wide declaration", N
);
4601 ("unconstrained subtype not allowed (need initialization)",
4602 Object_Definition
(N
));
4604 if Is_Record_Type
(T
) and then Has_Discriminants
(T
) then
4606 ("\provide initial value or explicit discriminant values",
4607 Object_Definition
(N
));
4610 ("\or give default discriminant values for type&",
4611 Object_Definition
(N
), T
);
4613 elsif Is_Array_Type
(T
) then
4615 ("\provide initial value or explicit array bounds",
4616 Object_Definition
(N
));
4620 -- Case of initialization present but in error. Set initial
4621 -- expression as absent (but do not make above complaints).
4623 elsif E
= Error
then
4624 Set_Expression
(N
, Empty
);
4627 -- Case of initialization present
4630 -- Unconstrained variables not allowed in Ada 83
4632 if Ada_Version
= Ada_83
4633 and then not Constant_Present
(N
)
4634 and then Comes_From_Source
(Object_Definition
(N
))
4637 ("(Ada 83) unconstrained variable not allowed",
4638 Object_Definition
(N
));
4641 -- Now we constrain the variable from the initializing expression
4643 -- If the expression is an aggregate, it has been expanded into
4644 -- individual assignments. Retrieve the actual type from the
4645 -- expanded construct.
4647 if Is_Array_Type
(T
)
4648 and then No_Initialization
(N
)
4649 and then Nkind
(Original_Node
(E
)) = N_Aggregate
4653 -- In case of class-wide interface object declarations we delay
4654 -- the generation of the equivalent record type declarations until
4655 -- its expansion because there are cases in they are not required.
4657 elsif Is_Interface
(T
) then
4660 -- If the type is an unchecked union, no subtype can be built from
4661 -- the expression. Rewrite declaration as a renaming, which the
4662 -- back-end can handle properly. This is a rather unusual case,
4663 -- because most unchecked_union declarations have default values
4664 -- for discriminants and are thus not indefinite.
4666 elsif Is_Unchecked_Union
(T
) then
4667 if Constant_Present
(N
) or else Nkind
(E
) = N_Function_Call
then
4668 Mutate_Ekind
(Id
, E_Constant
);
4670 Mutate_Ekind
(Id
, E_Variable
);
4673 -- If the expression is an aggregate it contains the required
4674 -- discriminant values but it has not been resolved yet, so do
4675 -- it now, and treat it as the initial expression of an object
4676 -- declaration, rather than a renaming.
4678 if Nkind
(E
) = N_Aggregate
then
4679 Analyze_And_Resolve
(E
, T
);
4683 Make_Object_Renaming_Declaration
(Loc
,
4684 Defining_Identifier
=> Id
,
4685 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
4688 Set_Renamed_Object
(Id
, E
);
4689 Freeze_Before
(N
, T
);
4695 -- Ensure that the generated subtype has a unique external name
4696 -- when the related object is public. This guarantees that the
4697 -- subtype and its bounds will not be affected by switches or
4698 -- pragmas that may offset the internal counter due to extra
4701 if Is_Public
(Id
) then
4704 Related_Id
:= Empty
;
4707 -- If the object has an unconstrained array subtype with fixed
4708 -- lower bound, then sliding to that bound may be needed.
4710 if Is_Fixed_Lower_Bound_Array_Subtype
(T
) then
4711 Expand_Sliding_Conversion
(E
, T
);
4714 Expand_Subtype_From_Expr
4717 Subtype_Indic
=> Object_Definition
(N
),
4719 Related_Id
=> Related_Id
);
4721 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4724 -- Propagate attributes to full view when needed
4726 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
4728 if Is_Private_Type
(Act_T
) and then Present
(Full_View
(Act_T
))
4730 Full_View_Present
:= True;
4733 if Full_View_Present
then
4734 Set_Is_Constr_Subt_For_U_Nominal
(Full_View
(Act_T
));
4737 if Aliased_Present
(N
) then
4738 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
4740 if Full_View_Present
then
4741 Set_Is_Constr_Subt_For_UN_Aliased
(Full_View
(Act_T
));
4745 Freeze_Before
(N
, Act_T
);
4746 Freeze_Before
(N
, T
);
4749 elsif Is_Array_Type
(T
)
4750 and then No_Initialization
(N
)
4751 and then (Nkind
(Original_Node
(E
)) = N_Aggregate
4752 or else (Nkind
(Original_Node
(E
)) = N_Qualified_Expression
4753 and then Nkind
(Original_Node
(Expression
4754 (Original_Node
(E
)))) = N_Aggregate
))
4756 if not Is_Entity_Name
(Object_Definition
(N
)) then
4758 Check_Compile_Time_Size
(Act_T
);
4760 if Aliased_Present
(N
) then
4761 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
4765 -- When the given object definition and the aggregate are specified
4766 -- independently, and their lengths might differ do a length check.
4767 -- This cannot happen if the aggregate is of the form (others =>...)
4769 if not Is_Constrained
(T
) then
4772 elsif Nkind
(E
) = N_Raise_Constraint_Error
then
4774 -- Aggregate is statically illegal. Place back in declaration
4776 Set_Expression
(N
, E
);
4777 Set_No_Initialization
(N
, False);
4779 elsif T
= Etype
(E
) then
4782 elsif Nkind
(E
) = N_Aggregate
4783 and then Present
(Component_Associations
(E
))
4784 and then Present
(Choice_List
(First
(Component_Associations
(E
))))
4786 Nkind
(First
(Choice_List
(First
(Component_Associations
(E
))))) =
4792 Apply_Length_Check
(E
, T
);
4795 -- If the type is limited unconstrained with defaulted discriminants and
4796 -- there is no expression, then the object is constrained by the
4797 -- defaults, so it is worthwhile building the corresponding subtype.
4799 elsif (Is_Limited_Record
(T
) or else Is_Concurrent_Type
(T
))
4800 and then not Is_Constrained
(T
)
4801 and then Has_Discriminants
(T
)
4804 Act_T
:= Build_Default_Subtype
(T
, N
);
4806 -- Ada 2005: A limited object may be initialized by means of an
4807 -- aggregate. If the type has default discriminants it has an
4808 -- unconstrained nominal type, Its actual subtype will be obtained
4809 -- from the aggregate, and not from the default discriminants.
4814 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
4816 elsif Nkind
(E
) = N_Function_Call
4817 and then Constant_Present
(N
)
4818 and then Has_Unconstrained_Elements
(Etype
(E
))
4820 -- The back-end has problems with constants of a discriminated type
4821 -- with defaults, if the initial value is a function call. We
4822 -- generate an intermediate temporary that will receive a reference
4823 -- to the result of the call. The initialization expression then
4824 -- becomes a dereference of that temporary.
4826 Remove_Side_Effects
(E
);
4828 -- If this is a constant declaration of an unconstrained type and
4829 -- the initialization is an aggregate, we can use the subtype of the
4830 -- aggregate for the declared entity because it is immutable.
4832 elsif not Is_Constrained
(T
)
4833 and then Has_Discriminants
(T
)
4834 and then Constant_Present
(N
)
4835 and then not Has_Unchecked_Union
(T
)
4836 and then Nkind
(E
) = N_Aggregate
4841 -- Check No_Wide_Characters restriction
4843 Check_Wide_Character_Restriction
(T
, Object_Definition
(N
));
4845 -- Indicate this is not set in source. Certainly true for constants, and
4846 -- true for variables so far (will be reset for a variable if and when
4847 -- we encounter a modification in the source).
4849 Set_Never_Set_In_Source
(Id
);
4851 -- Now establish the proper kind and type of the object
4853 if Ekind
(Id
) = E_Void
then
4854 Reinit_Field_To_Zero
(Id
, F_Next_Inlined_Subprogram
);
4857 if Constant_Present
(N
) then
4858 Mutate_Ekind
(Id
, E_Constant
);
4859 Set_Is_True_Constant
(Id
);
4862 Mutate_Ekind
(Id
, E_Variable
);
4864 -- A variable is set as shared passive if it appears in a shared
4865 -- passive package, and is at the outer level. This is not done for
4866 -- entities generated during expansion, because those are always
4867 -- manipulated locally.
4869 if Is_Shared_Passive
(Current_Scope
)
4870 and then Is_Library_Level_Entity
(Id
)
4871 and then Comes_From_Source
(Id
)
4873 Set_Is_Shared_Passive
(Id
);
4874 Check_Shared_Var
(Id
, T
, N
);
4877 -- Set Has_Initial_Value if initializing expression present. Note
4878 -- that if there is no initializing expression, we leave the state
4879 -- of this flag unchanged (usually it will be False, but notably in
4880 -- the case of exception choice variables, it will already be true).
4883 Set_Has_Initial_Value
(Id
);
4887 -- Set the SPARK mode from the current context (may be overwritten later
4888 -- with explicit pragma).
4890 Set_SPARK_Pragma
(Id
, SPARK_Mode_Pragma
);
4891 Set_SPARK_Pragma_Inherited
(Id
);
4893 -- Preserve relevant elaboration-related attributes of the context which
4894 -- are no longer available or very expensive to recompute once analysis,
4895 -- resolution, and expansion are over.
4897 Mark_Elaboration_Attributes
4902 -- Initialize alignment and size and capture alignment setting
4904 Reinit_Alignment
(Id
);
4906 Set_Optimize_Alignment_Flags
(Id
);
4908 -- Deal with aliased case
4910 if Aliased_Present
(N
) then
4911 Set_Is_Aliased
(Id
);
4913 -- AI12-001: All aliased objects are considered to be specified as
4914 -- independently addressable (RM C.6(8.1/4)).
4916 Set_Is_Independent
(Id
);
4918 -- If the object is aliased and the type is unconstrained with
4919 -- defaulted discriminants and there is no expression, then the
4920 -- object is constrained by the defaults, so it is worthwhile
4921 -- building the corresponding subtype.
4923 -- Ada 2005 (AI-363): If the aliased object is discriminated and
4924 -- unconstrained, then only establish an actual subtype if the
4925 -- nominal subtype is indefinite. In definite cases the object is
4926 -- unconstrained in Ada 2005.
4929 and then Is_Record_Type
(T
)
4930 and then not Is_Constrained
(T
)
4931 and then Has_Discriminants
(T
)
4932 and then (Ada_Version
< Ada_2005
4933 or else not Is_Definite_Subtype
(T
))
4935 Set_Actual_Subtype
(Id
, Build_Default_Subtype
(T
, N
));
4939 -- Now we can set the type of the object
4941 Set_Etype
(Id
, Act_T
);
4943 -- Non-constant object is marked to be treated as volatile if type is
4944 -- volatile and we clear the Current_Value setting that may have been
4945 -- set above. Doing so for constants isn't required and might interfere
4946 -- with possible uses of the object as a static expression in contexts
4947 -- incompatible with volatility (e.g. as a case-statement alternative).
4949 if Ekind
(Id
) /= E_Constant
and then Treat_As_Volatile
(Etype
(Id
)) then
4950 Set_Treat_As_Volatile
(Id
);
4951 Set_Current_Value
(Id
, Empty
);
4954 -- Deal with controlled types
4956 if Has_Controlled_Component
(Etype
(Id
))
4957 or else Is_Controlled
(Etype
(Id
))
4959 if not Is_Library_Level_Entity
(Id
) then
4960 Check_Restriction
(No_Nested_Finalization
, N
);
4962 Validate_Controlled_Object
(Id
);
4966 if Has_Task
(Etype
(Id
)) then
4967 Check_Restriction
(No_Tasking
, N
);
4969 -- Deal with counting max tasks
4971 -- Nothing to do if inside a generic
4973 if Inside_A_Generic
then
4976 -- If library level entity, then count tasks
4978 elsif Is_Library_Level_Entity
(Id
) then
4979 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
4981 -- If not library level entity, then indicate we don't know max
4982 -- tasks and also check task hierarchy restriction and blocking
4983 -- operation (since starting a task is definitely blocking).
4986 Check_Restriction
(Max_Tasks
, N
);
4987 Check_Restriction
(No_Task_Hierarchy
, N
);
4988 Check_Potentially_Blocking_Operation
(N
);
4991 -- A rather specialized test. If we see two tasks being declared
4992 -- of the same type in the same object declaration, and the task
4993 -- has an entry with an address clause, we know that program error
4994 -- will be raised at run time since we can't have two tasks with
4995 -- entries at the same address.
4997 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
5002 E
:= First_Entity
(Etype
(Id
));
5003 while Present
(E
) loop
5004 if Ekind
(E
) = E_Entry
5005 and then Present
(Get_Attribute_Definition_Clause
5006 (E
, Attribute_Address
))
5008 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5010 ("more than one task with same entry address<<", N
);
5011 Error_Msg_N
("\Program_Error [<<", N
);
5013 Make_Raise_Program_Error
(Loc
,
5014 Reason
=> PE_Duplicated_Entry_Address
));
5024 -- Some simple constant-propagation: if the expression is a constant
5025 -- string initialized with a literal, share the literal. This avoids
5029 and then Is_Entity_Name
(E
)
5030 and then Ekind
(Entity
(E
)) = E_Constant
5031 and then Base_Type
(Etype
(E
)) = Standard_String
5034 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
5036 if Present
(Val
) and then Nkind
(Val
) = N_String_Literal
then
5037 Rewrite
(E
, New_Copy
(Val
));
5042 -- Another optimization: if the nominal subtype is unconstrained and
5043 -- the expression is a function call that returns an unconstrained
5044 -- type, rewrite the declaration as a renaming of the result of the
5045 -- call. The exceptions below are cases where the copy is expected,
5046 -- either by the back end (Aliased case) or by the semantics, as for
5047 -- initializing controlled types or copying tags for class-wide types.
5050 and then Nkind
(E
) = N_Explicit_Dereference
5051 and then Nkind
(Original_Node
(E
)) = N_Function_Call
5052 and then not Is_Library_Level_Entity
(Id
)
5053 and then not Is_Constrained
(Underlying_Type
(T
))
5054 and then not Is_Aliased
(Id
)
5055 and then not Is_Class_Wide_Type
(T
)
5056 and then not Is_Controlled
(T
)
5057 and then not Has_Controlled_Component
(Base_Type
(T
))
5058 and then Expander_Active
5061 Make_Object_Renaming_Declaration
(Loc
,
5062 Defining_Identifier
=> Id
,
5063 Access_Definition
=> Empty
,
5064 Subtype_Mark
=> New_Occurrence_Of
5065 (Base_Type
(Etype
(Id
)), Loc
),
5068 Set_Renamed_Object
(Id
, E
);
5070 -- Force generation of debugging information for the constant and for
5071 -- the renamed function call.
5073 Set_Debug_Info_Needed
(Id
);
5074 Set_Debug_Info_Needed
(Entity
(Prefix
(E
)));
5077 if Present
(Prev_Entity
)
5078 and then Is_Frozen
(Prev_Entity
)
5079 and then not Error_Posted
(Id
)
5081 Error_Msg_N
("full constant declaration appears too late", N
);
5084 Check_Eliminated
(Id
);
5086 -- Deal with setting In_Private_Part flag if in private part
5088 if Ekind
(Scope
(Id
)) = E_Package
5089 and then In_Private_Part
(Scope
(Id
))
5091 Set_In_Private_Part
(Id
);
5095 -- Initialize the refined state of a variable here because this is a
5096 -- common destination for legal and illegal object declarations.
5098 if Ekind
(Id
) = E_Variable
then
5099 Set_Encapsulating_State
(Id
, Empty
);
5102 if Has_Aspects
(N
) then
5103 Analyze_Aspect_Specifications
(N
, Id
);
5106 Analyze_Dimension
(N
);
5108 -- Verify whether the object declaration introduces an illegal hidden
5109 -- state within a package subject to a null abstract state.
5111 if Ekind
(Id
) = E_Variable
then
5112 Check_No_Hidden_State
(Id
);
5115 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
5116 end Analyze_Object_Declaration
;
5118 ---------------------------
5119 -- Analyze_Others_Choice --
5120 ---------------------------
5122 -- Nothing to do for the others choice node itself, the semantic analysis
5123 -- of the others choice will occur as part of the processing of the parent
5125 procedure Analyze_Others_Choice
(N
: Node_Id
) is
5126 pragma Warnings
(Off
, N
);
5129 end Analyze_Others_Choice
;
5131 -------------------------------------------
5132 -- Analyze_Private_Extension_Declaration --
5133 -------------------------------------------
5135 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
5136 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
5137 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5139 Iface_Elmt
: Elmt_Id
;
5140 Parent_Base
: Entity_Id
;
5141 Parent_Type
: Entity_Id
;
5144 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
5146 if Is_Non_Empty_List
(Interface_List
(N
)) then
5152 Intf
:= First
(Interface_List
(N
));
5153 while Present
(Intf
) loop
5154 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
5156 Diagnose_Interface
(Intf
, T
);
5162 Generate_Definition
(T
);
5164 -- For other than Ada 2012, just enter the name in the current scope
5166 if Ada_Version
< Ada_2012
then
5169 -- Ada 2012 (AI05-0162): Enter the name in the current scope handling
5170 -- case of private type that completes an incomplete type.
5177 Prev
:= Find_Type_Name
(N
);
5179 pragma Assert
(Prev
= T
5180 or else (Ekind
(Prev
) = E_Incomplete_Type
5181 and then Present
(Full_View
(Prev
))
5182 and then Full_View
(Prev
) = T
));
5186 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
5187 Parent_Base
:= Base_Type
(Parent_Type
);
5189 if Parent_Type
= Any_Type
or else Etype
(Parent_Type
) = Any_Type
then
5190 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
5191 Set_Etype
(T
, Any_Type
);
5194 elsif not Is_Tagged_Type
(Parent_Type
) then
5196 ("parent of type extension must be a tagged type", Indic
);
5199 elsif Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
5200 Error_Msg_N
("premature derivation of incomplete type", Indic
);
5203 elsif Is_Concurrent_Type
(Parent_Type
) then
5205 ("parent type of a private extension cannot be a synchronized "
5206 & "tagged type (RM 3.9.1 (3/1))", N
);
5208 Set_Etype
(T
, Any_Type
);
5209 Mutate_Ekind
(T
, E_Limited_Private_Type
);
5210 Set_Private_Dependents
(T
, New_Elmt_List
);
5211 Set_Error_Posted
(T
);
5215 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
5217 -- Perhaps the parent type should be changed to the class-wide type's
5218 -- specific type in this case to prevent cascading errors ???
5220 if Is_Class_Wide_Type
(Parent_Type
) then
5222 ("parent of type extension must not be a class-wide type", Indic
);
5226 if (not Is_Package_Or_Generic_Package
(Current_Scope
)
5227 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
5228 or else In_Private_Part
(Current_Scope
)
5230 Error_Msg_N
("invalid context for private extension", N
);
5233 -- Set common attributes
5235 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
5236 Set_Scope
(T
, Current_Scope
);
5237 Mutate_Ekind
(T
, E_Record_Type_With_Private
);
5238 Reinit_Size_Align
(T
);
5239 Set_Default_SSO
(T
);
5240 Set_No_Reordering
(T
, No_Component_Reordering
);
5242 Set_Etype
(T
, Parent_Base
);
5243 Propagate_Concurrent_Flags
(T
, Parent_Base
);
5245 Set_Convention
(T
, Convention
(Parent_Type
));
5246 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
5247 Set_Is_First_Subtype
(T
);
5248 Make_Class_Wide_Type
(T
);
5250 -- Set the SPARK mode from the current context
5252 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
5253 Set_SPARK_Pragma_Inherited
(T
);
5255 if Unknown_Discriminants_Present
(N
) then
5256 Set_Discriminant_Constraint
(T
, No_Elist
);
5259 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
5261 -- A private extension inherits the Default_Initial_Condition pragma
5262 -- coming from any parent type within the derivation chain.
5264 if Has_DIC
(Parent_Type
) then
5265 Set_Has_Inherited_DIC
(T
);
5268 -- A private extension inherits any class-wide invariants coming from a
5269 -- parent type or an interface. Note that the invariant procedure of the
5270 -- parent type should not be inherited because the private extension may
5271 -- define invariants of its own.
5273 if Has_Inherited_Invariants
(Parent_Type
)
5274 or else Has_Inheritable_Invariants
(Parent_Type
)
5276 Set_Has_Inherited_Invariants
(T
);
5278 elsif Present
(Interfaces
(T
)) then
5279 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5280 while Present
(Iface_Elmt
) loop
5281 Iface
:= Node
(Iface_Elmt
);
5283 if Has_Inheritable_Invariants
(Iface
) then
5284 Set_Has_Inherited_Invariants
(T
);
5288 Next_Elmt
(Iface_Elmt
);
5292 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
5293 -- synchronized formal derived type.
5295 if Ada_Version
>= Ada_2005
and then Synchronized_Present
(N
) then
5296 Set_Is_Limited_Record
(T
);
5298 -- Formal derived type case
5300 if Is_Generic_Type
(T
) then
5302 -- The parent must be a tagged limited type or a synchronized
5305 if (not Is_Tagged_Type
(Parent_Type
)
5306 or else not Is_Limited_Type
(Parent_Type
))
5308 (not Is_Interface
(Parent_Type
)
5309 or else not Is_Synchronized_Interface
(Parent_Type
))
5312 ("parent type of & must be tagged limited or synchronized",
5316 -- The progenitors (if any) must be limited or synchronized
5319 if Present
(Interfaces
(T
)) then
5320 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5321 while Present
(Iface_Elmt
) loop
5322 Iface
:= Node
(Iface_Elmt
);
5324 if not Is_Limited_Interface
(Iface
)
5325 and then not Is_Synchronized_Interface
(Iface
)
5328 ("progenitor & must be limited or synchronized",
5332 Next_Elmt
(Iface_Elmt
);
5336 -- Regular derived extension, the parent must be a limited or
5337 -- synchronized interface.
5340 if not Is_Interface
(Parent_Type
)
5341 or else (not Is_Limited_Interface
(Parent_Type
)
5342 and then not Is_Synchronized_Interface
(Parent_Type
))
5345 ("parent type of & must be limited interface", N
, T
);
5349 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
5350 -- extension with a synchronized parent must be explicitly declared
5351 -- synchronized, because the full view will be a synchronized type.
5352 -- This must be checked before the check for limited types below,
5353 -- to ensure that types declared limited are not allowed to extend
5354 -- synchronized interfaces.
5356 elsif Is_Interface
(Parent_Type
)
5357 and then Is_Synchronized_Interface
(Parent_Type
)
5358 and then not Synchronized_Present
(N
)
5361 ("private extension of& must be explicitly synchronized",
5364 elsif Limited_Present
(N
) then
5365 Set_Is_Limited_Record
(T
);
5367 if not Is_Limited_Type
(Parent_Type
)
5369 (not Is_Interface
(Parent_Type
)
5370 or else not Is_Limited_Interface
(Parent_Type
))
5372 Error_Msg_NE
("parent type& of limited extension must be limited",
5377 -- Remember that its parent type has a private extension. Used to warn
5378 -- on public primitives of the parent type defined after its private
5379 -- extensions (see Check_Dispatching_Operation).
5381 Set_Has_Private_Extension
(Parent_Type
);
5384 if Has_Aspects
(N
) then
5385 Analyze_Aspect_Specifications
(N
, T
);
5387 end Analyze_Private_Extension_Declaration
;
5389 ---------------------------------
5390 -- Analyze_Subtype_Declaration --
5391 ---------------------------------
5393 procedure Analyze_Subtype_Declaration
5395 Skip
: Boolean := False)
5397 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5401 Generate_Definition
(Id
);
5402 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
5403 Reinit_Size_Align
(Id
);
5405 -- The following guard condition on Enter_Name is to handle cases where
5406 -- the defining identifier has already been entered into the scope but
5407 -- the declaration as a whole needs to be analyzed.
5409 -- This case in particular happens for derived enumeration types. The
5410 -- derived enumeration type is processed as an inserted enumeration type
5411 -- declaration followed by a rewritten subtype declaration. The defining
5412 -- identifier, however, is entered into the name scope very early in the
5413 -- processing of the original type declaration and therefore needs to be
5414 -- avoided here, when the created subtype declaration is analyzed. (See
5415 -- Build_Derived_Types)
5417 -- This also happens when the full view of a private type is derived
5418 -- type with constraints. In this case the entity has been introduced
5419 -- in the private declaration.
5421 -- Finally this happens in some complex cases when validity checks are
5422 -- enabled, where the same subtype declaration may be analyzed twice.
5423 -- This can happen if the subtype is created by the preanalysis of
5424 -- an attribute tht gives the range of a loop statement, and the loop
5425 -- itself appears within an if_statement that will be rewritten during
5429 or else (Present
(Etype
(Id
))
5430 and then (Is_Private_Type
(Etype
(Id
))
5431 or else Is_Task_Type
(Etype
(Id
))
5432 or else Is_Rewrite_Substitution
(N
)))
5436 elsif Current_Entity
(Id
) = Id
then
5443 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
5445 -- Class-wide equivalent types of records with unknown discriminants
5446 -- involve the generation of an itype which serves as the private view
5447 -- of a constrained record subtype. In such cases the base type of the
5448 -- current subtype we are processing is the private itype. Use the full
5449 -- of the private itype when decorating various attributes.
5452 and then Is_Private_Type
(T
)
5453 and then Present
(Full_View
(T
))
5458 -- Inherit common attributes
5460 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
5461 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
5462 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
5463 Set_Convention
(Id
, Convention
(T
));
5465 -- If ancestor has predicates then so does the subtype, and in addition
5466 -- we must delay the freeze to properly arrange predicate inheritance.
5468 -- The Ancestor_Type test is really unpleasant, there seem to be cases
5469 -- in which T = ID, so the above tests and assignments do nothing???
5471 if Has_Predicates
(T
)
5472 or else (Present
(Ancestor_Subtype
(T
))
5473 and then Has_Predicates
(Ancestor_Subtype
(T
)))
5475 Set_Has_Predicates
(Id
);
5476 Set_Has_Delayed_Freeze
(Id
);
5478 -- Generated subtypes inherit the predicate function from the parent
5479 -- (no aspects to examine on the generated declaration).
5481 if not Comes_From_Source
(N
) then
5482 Mutate_Ekind
(Id
, Ekind
(T
));
5484 if Present
(Predicate_Function
(Id
)) then
5487 elsif Present
(Predicate_Function
(T
)) then
5488 Set_Predicate_Function
(Id
, Predicate_Function
(T
));
5490 elsif Present
(Ancestor_Subtype
(T
))
5491 and then Present
(Predicate_Function
(Ancestor_Subtype
(T
)))
5493 Set_Predicate_Function
(Id
,
5494 Predicate_Function
(Ancestor_Subtype
(T
)));
5499 -- In the case where there is no constraint given in the subtype
5500 -- indication, Process_Subtype just returns the Subtype_Mark, so its
5501 -- semantic attributes must be established here.
5503 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
5504 Set_Etype
(Id
, Base_Type
(T
));
5508 Mutate_Ekind
(Id
, E_Array_Subtype
);
5509 Copy_Array_Subtype_Attributes
(Id
, T
);
5511 when Decimal_Fixed_Point_Kind
=>
5512 Mutate_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
5513 Set_Digits_Value
(Id
, Digits_Value
(T
));
5514 Set_Delta_Value
(Id
, Delta_Value
(T
));
5515 Set_Scale_Value
(Id
, Scale_Value
(T
));
5516 Set_Small_Value
(Id
, Small_Value
(T
));
5517 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5518 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
5519 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5520 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5521 Copy_RM_Size
(To
=> Id
, From
=> T
);
5523 when Enumeration_Kind
=>
5524 Mutate_Ekind
(Id
, E_Enumeration_Subtype
);
5525 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
5526 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5527 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
5528 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5529 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5530 Copy_RM_Size
(To
=> Id
, From
=> T
);
5532 when Ordinary_Fixed_Point_Kind
=>
5533 Mutate_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
5534 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5535 Set_Small_Value
(Id
, Small_Value
(T
));
5536 Set_Delta_Value
(Id
, Delta_Value
(T
));
5537 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5538 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5539 Copy_RM_Size
(To
=> Id
, From
=> T
);
5542 Mutate_Ekind
(Id
, E_Floating_Point_Subtype
);
5543 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5544 Set_Digits_Value
(Id
, Digits_Value
(T
));
5545 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5547 -- If the floating point type has dimensions, these will be
5548 -- inherited subsequently when Analyze_Dimensions is called.
5550 when Signed_Integer_Kind
=>
5551 Mutate_Ekind
(Id
, E_Signed_Integer_Subtype
);
5552 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5553 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5554 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5555 Copy_RM_Size
(To
=> Id
, From
=> T
);
5557 when Modular_Integer_Kind
=>
5558 Mutate_Ekind
(Id
, E_Modular_Integer_Subtype
);
5559 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5560 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5561 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5562 Copy_RM_Size
(To
=> Id
, From
=> T
);
5564 when Class_Wide_Kind
=>
5565 Mutate_Ekind
(Id
, E_Class_Wide_Subtype
);
5566 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5567 Set_Cloned_Subtype
(Id
, T
);
5568 Set_Is_Tagged_Type
(Id
, True);
5569 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5570 Set_Has_Unknown_Discriminants
5572 Set_No_Tagged_Streams_Pragma
5573 (Id
, No_Tagged_Streams_Pragma
(T
));
5575 if Ekind
(T
) = E_Class_Wide_Subtype
then
5576 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
5579 when E_Record_Subtype
5582 Mutate_Ekind
(Id
, E_Record_Subtype
);
5584 -- Subtype declarations introduced for formal type parameters
5585 -- in generic instantiations should inherit the Size value of
5586 -- the type they rename.
5588 if Present
(Generic_Parent_Type
(N
)) then
5589 Copy_RM_Size
(To
=> Id
, From
=> T
);
5592 if Ekind
(T
) = E_Record_Subtype
5593 and then Present
(Cloned_Subtype
(T
))
5595 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
5597 Set_Cloned_Subtype
(Id
, T
);
5600 Set_First_Entity
(Id
, First_Entity
(T
));
5601 Set_Last_Entity
(Id
, Last_Entity
(T
));
5602 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5603 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5604 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5605 Set_Has_Implicit_Dereference
5606 (Id
, Has_Implicit_Dereference
(T
));
5607 Set_Has_Unknown_Discriminants
5608 (Id
, Has_Unknown_Discriminants
(T
));
5610 if Has_Discriminants
(T
) then
5611 Set_Discriminant_Constraint
5612 (Id
, Discriminant_Constraint
(T
));
5613 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5615 elsif Has_Unknown_Discriminants
(Id
) then
5616 Set_Discriminant_Constraint
(Id
, No_Elist
);
5619 if Is_Tagged_Type
(T
) then
5620 Set_Is_Tagged_Type
(Id
, True);
5621 Set_No_Tagged_Streams_Pragma
5622 (Id
, No_Tagged_Streams_Pragma
(T
));
5623 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5624 Set_Direct_Primitive_Operations
5625 (Id
, Direct_Primitive_Operations
(T
));
5626 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5628 if Is_Interface
(T
) then
5629 Set_Is_Interface
(Id
);
5630 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
5634 when Private_Kind
=>
5635 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5636 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5637 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5638 Set_First_Entity
(Id
, First_Entity
(T
));
5639 Set_Last_Entity
(Id
, Last_Entity
(T
));
5640 Set_Private_Dependents
(Id
, New_Elmt_List
);
5641 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5642 Set_Has_Implicit_Dereference
5643 (Id
, Has_Implicit_Dereference
(T
));
5644 Set_Has_Unknown_Discriminants
5645 (Id
, Has_Unknown_Discriminants
(T
));
5646 Set_Known_To_Have_Preelab_Init
5647 (Id
, Known_To_Have_Preelab_Init
(T
));
5649 if Is_Tagged_Type
(T
) then
5650 Set_Is_Tagged_Type
(Id
);
5651 Set_No_Tagged_Streams_Pragma
(Id
,
5652 No_Tagged_Streams_Pragma
(T
));
5653 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5654 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5655 Set_Direct_Primitive_Operations
(Id
,
5656 Direct_Primitive_Operations
(T
));
5659 -- In general the attributes of the subtype of a private type
5660 -- are the attributes of the partial view of parent. However,
5661 -- the full view may be a discriminated type, and the subtype
5662 -- must share the discriminant constraint to generate correct
5663 -- calls to initialization procedures.
5665 if Has_Discriminants
(T
) then
5666 Set_Discriminant_Constraint
5667 (Id
, Discriminant_Constraint
(T
));
5668 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5670 elsif Present
(Full_View
(T
))
5671 and then Has_Discriminants
(Full_View
(T
))
5673 Set_Discriminant_Constraint
5674 (Id
, Discriminant_Constraint
(Full_View
(T
)));
5675 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5677 -- This would seem semantically correct, but apparently
5678 -- generates spurious errors about missing components ???
5680 -- Set_Has_Discriminants (Id);
5683 Prepare_Private_Subtype_Completion
(Id
, N
);
5685 -- If this is the subtype of a constrained private type with
5686 -- discriminants that has got a full view and we also have
5687 -- built a completion just above, show that the completion
5688 -- is a clone of the full view to the back-end.
5690 if Has_Discriminants
(T
)
5691 and then not Has_Unknown_Discriminants
(T
)
5692 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(T
))
5693 and then Present
(Full_View
(T
))
5694 and then Present
(Full_View
(Id
))
5696 Set_Cloned_Subtype
(Full_View
(Id
), Full_View
(T
));
5700 Mutate_Ekind
(Id
, E_Access_Subtype
);
5701 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5702 Set_Is_Access_Constant
5703 (Id
, Is_Access_Constant
(T
));
5704 Set_Directly_Designated_Type
5705 (Id
, Designated_Type
(T
));
5706 Set_Can_Never_Be_Null
(Id
, Can_Never_Be_Null
(T
));
5708 -- A Pure library_item must not contain the declaration of a
5709 -- named access type, except within a subprogram, generic
5710 -- subprogram, task unit, or protected unit, or if it has
5711 -- a specified Storage_Size of zero (RM05-10.2.1(15.4-15.5)).
5713 if Comes_From_Source
(Id
)
5714 and then In_Pure_Unit
5715 and then not In_Subprogram_Task_Protected_Unit
5716 and then not No_Pool_Assigned
(Id
)
5719 ("named access types not allowed in pure unit", N
);
5722 when Concurrent_Kind
=>
5723 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5724 Set_Corresponding_Record_Type
(Id
,
5725 Corresponding_Record_Type
(T
));
5726 Set_First_Entity
(Id
, First_Entity
(T
));
5727 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
5728 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5729 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5730 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5731 Set_Last_Entity
(Id
, Last_Entity
(T
));
5733 if Is_Tagged_Type
(T
) then
5734 Set_No_Tagged_Streams_Pragma
5735 (Id
, No_Tagged_Streams_Pragma
(T
));
5738 if Has_Discriminants
(T
) then
5739 Set_Discriminant_Constraint
5740 (Id
, Discriminant_Constraint
(T
));
5741 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5744 when Incomplete_Kind
=>
5745 if Ada_Version
>= Ada_2005
then
5747 -- In Ada 2005 an incomplete type can be explicitly tagged:
5748 -- propagate indication. Note that we also have to include
5749 -- subtypes for Ada 2012 extended use of incomplete types.
5751 Mutate_Ekind
(Id
, E_Incomplete_Subtype
);
5752 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5753 Set_Private_Dependents
(Id
, New_Elmt_List
);
5755 if Is_Tagged_Type
(Id
) then
5756 Set_No_Tagged_Streams_Pragma
5757 (Id
, No_Tagged_Streams_Pragma
(T
));
5760 -- For tagged types, or when prefixed-call syntax is allowed
5761 -- for untagged types, initialize the list of primitive
5762 -- operations to an empty list.
5764 if Is_Tagged_Type
(Id
)
5765 or else Extensions_Allowed
5767 Set_Direct_Primitive_Operations
(Id
, New_Elmt_List
);
5770 -- Ada 2005 (AI-412): Decorate an incomplete subtype of an
5771 -- incomplete type visible through a limited with clause.
5773 if From_Limited_With
(T
)
5774 and then Present
(Non_Limited_View
(T
))
5776 Set_From_Limited_With
(Id
);
5777 Set_Non_Limited_View
(Id
, Non_Limited_View
(T
));
5779 -- Ada 2005 (AI-412): Add the regular incomplete subtype
5780 -- to the private dependents of the original incomplete
5781 -- type for future transformation.
5784 Append_Elmt
(Id
, Private_Dependents
(T
));
5787 -- If the subtype name denotes an incomplete type an error
5788 -- was already reported by Process_Subtype.
5791 Set_Etype
(Id
, Any_Type
);
5795 raise Program_Error
;
5798 -- If there is no constraint in the subtype indication, the
5799 -- declared entity inherits predicates from the parent.
5801 Inherit_Predicate_Flags
(Id
, T
);
5804 -- When prefixed calls are enabled for untagged types, the subtype
5805 -- shares the primitive operations of its base type.
5807 if Extensions_Allowed
then
5808 Set_Direct_Primitive_Operations
5809 (Id
, Direct_Primitive_Operations
(Base_Type
(T
)));
5812 if Etype
(Id
) = Any_Type
then
5816 -- Some common processing on all types
5818 Set_Size_Info
(Id
, T
);
5819 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
5821 -- If the parent type is a generic actual, so is the subtype. This may
5822 -- happen in a nested instance. Why Comes_From_Source test???
5824 if not Comes_From_Source
(N
) then
5825 Set_Is_Generic_Actual_Type
(Id
, Is_Generic_Actual_Type
(T
));
5828 -- If this is a subtype declaration for an actual in an instance,
5829 -- inherit static and dynamic predicates if any.
5831 -- If declaration has no aspect specifications, inherit predicate
5832 -- info as well. Unclear how to handle the case of both specified
5833 -- and inherited predicates ??? Other inherited aspects, such as
5834 -- invariants, should be OK, but the combination with later pragmas
5835 -- may also require special merging.
5837 if Has_Predicates
(T
)
5838 and then Present
(Predicate_Function
(T
))
5840 ((In_Instance
and then not Comes_From_Source
(N
))
5841 or else No
(Aspect_Specifications
(N
)))
5843 -- Inherit Subprograms_For_Type from the full view, if present
5845 if Present
(Full_View
(T
))
5846 and then Subprograms_For_Type
(Full_View
(T
)) /= No_Elist
5848 Set_Subprograms_For_Type
5849 (Id
, Subprograms_For_Type
(Full_View
(T
)));
5851 Set_Subprograms_For_Type
(Id
, Subprograms_For_Type
(T
));
5854 -- If the current declaration created both a private and a full view,
5855 -- then propagate Predicate_Function to the latter as well.
5857 if Present
(Full_View
(Id
))
5858 and then No
(Predicate_Function
(Full_View
(Id
)))
5860 Set_Subprograms_For_Type
5861 (Full_View
(Id
), Subprograms_For_Type
(Id
));
5864 if Has_Static_Predicate
(T
) then
5865 Set_Has_Static_Predicate
(Id
);
5866 Set_Static_Discrete_Predicate
(Id
, Static_Discrete_Predicate
(T
));
5870 -- If the base type is a scalar type, or else if there is no
5871 -- constraint, the atomic flag is inherited by the subtype.
5872 -- Ditto for the Independent aspect.
5874 if Is_Scalar_Type
(Id
)
5875 or else Is_Entity_Name
(Subtype_Indication
(N
))
5877 Set_Is_Atomic
(Id
, Is_Atomic
(T
));
5878 Set_Is_Independent
(Id
, Is_Independent
(T
));
5881 -- Remaining processing depends on characteristics of base type
5885 Set_Is_Immediately_Visible
(Id
, True);
5886 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
5887 Set_Is_Descendant_Of_Address
(Id
, Is_Descendant_Of_Address
(T
));
5889 if Is_Interface
(T
) then
5890 Set_Is_Interface
(Id
);
5891 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
5894 if Present
(Generic_Parent_Type
(N
))
5896 (Nkind
(Parent
(Generic_Parent_Type
(N
))) /=
5897 N_Formal_Type_Declaration
5898 or else Nkind
(Formal_Type_Definition
5899 (Parent
(Generic_Parent_Type
(N
)))) /=
5900 N_Formal_Private_Type_Definition
)
5902 if Is_Tagged_Type
(Id
) then
5904 -- If this is a generic actual subtype for a synchronized type,
5905 -- the primitive operations are those of the corresponding record
5906 -- for which there is a separate subtype declaration.
5908 if Is_Concurrent_Type
(Id
) then
5910 elsif Is_Class_Wide_Type
(Id
) then
5911 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
5913 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
5916 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
5917 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
5921 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
5922 Conditional_Delay
(Id
, Full_View
(T
));
5924 -- The subtypes of components or subcomponents of protected types
5925 -- do not need freeze nodes, which would otherwise appear in the
5926 -- wrong scope (before the freeze node for the protected type). The
5927 -- proper subtypes are those of the subcomponents of the corresponding
5930 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
5931 and then Present
(Scope
(Scope
(Id
))) -- error defense
5932 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
5934 Conditional_Delay
(Id
, T
);
5937 -- If we have a subtype of an incomplete type whose full type is a
5938 -- derived numeric type, we need to have a freeze node for the subtype.
5939 -- Otherwise gigi will complain while computing the (static) bounds of
5943 and then Is_Elementary_Type
(Id
)
5944 and then Etype
(Id
) /= Id
5947 Partial
: constant Entity_Id
:=
5948 Incomplete_Or_Partial_View
(First_Subtype
(Id
));
5950 if Present
(Partial
)
5951 and then Ekind
(Partial
) = E_Incomplete_Type
5953 Set_Has_Delayed_Freeze
(Id
);
5958 -- Check that Constraint_Error is raised for a scalar subtype indication
5959 -- when the lower or upper bound of a non-null range lies outside the
5960 -- range of the type mark. Likewise for an array subtype, but check the
5961 -- compatibility for each index.
5963 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
5965 Indic_Typ
: constant Entity_Id
:=
5966 Etype
(Subtype_Mark
(Subtype_Indication
(N
)));
5967 Subt_Index
: Node_Id
;
5968 Target_Index
: Node_Id
;
5971 if Is_Scalar_Type
(Etype
(Id
))
5972 and then Scalar_Range
(Id
) /= Scalar_Range
(Indic_Typ
)
5974 Apply_Range_Check
(Scalar_Range
(Id
), Indic_Typ
);
5976 elsif Is_Array_Type
(Etype
(Id
))
5977 and then Present
(First_Index
(Id
))
5979 Subt_Index
:= First_Index
(Id
);
5980 Target_Index
:= First_Index
(Indic_Typ
);
5982 while Present
(Subt_Index
) loop
5983 if ((Nkind
(Subt_Index
) in N_Expanded_Name | N_Identifier
5984 and then Is_Scalar_Type
(Entity
(Subt_Index
)))
5985 or else Nkind
(Subt_Index
) = N_Subtype_Indication
)
5987 Nkind
(Scalar_Range
(Etype
(Subt_Index
))) = N_Range
5990 (Scalar_Range
(Etype
(Subt_Index
)),
5991 Etype
(Target_Index
),
5995 Next_Index
(Subt_Index
);
5996 Next_Index
(Target_Index
);
6002 Set_Optimize_Alignment_Flags
(Id
);
6003 Check_Eliminated
(Id
);
6006 if Has_Aspects
(N
) then
6007 Analyze_Aspect_Specifications
(N
, Id
);
6010 Analyze_Dimension
(N
);
6012 -- Check No_Dynamic_Sized_Objects restriction, which disallows subtype
6013 -- indications on composite types where the constraints are dynamic.
6014 -- Note that object declarations and aggregates generate implicit
6015 -- subtype declarations, which this covers. One special case is that the
6016 -- implicitly generated "=" for discriminated types includes an
6017 -- offending subtype declaration, which is harmless, so we ignore it
6020 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6022 Cstr
: constant Node_Id
:= Constraint
(Subtype_Indication
(N
));
6024 if Nkind
(Cstr
) = N_Index_Or_Discriminant_Constraint
6025 and then not (Is_Internal
(Id
)
6026 and then Is_TSS
(Scope
(Id
),
6027 TSS_Composite_Equality
))
6028 and then not Within_Init_Proc
6029 and then not All_Composite_Constraints_Static
(Cstr
)
6031 Check_Restriction
(No_Dynamic_Sized_Objects
, Cstr
);
6035 end Analyze_Subtype_Declaration
;
6037 --------------------------------
6038 -- Analyze_Subtype_Indication --
6039 --------------------------------
6041 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
6042 T
: constant Entity_Id
:= Subtype_Mark
(N
);
6043 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6050 Set_Etype
(N
, Etype
(R
));
6051 Resolve
(R
, Entity
(T
));
6053 Set_Error_Posted
(R
);
6054 Set_Error_Posted
(T
);
6056 end Analyze_Subtype_Indication
;
6058 --------------------------
6059 -- Analyze_Variant_Part --
6060 --------------------------
6062 procedure Analyze_Variant_Part
(N
: Node_Id
) is
6063 Discr_Name
: Node_Id
;
6064 Discr_Type
: Entity_Id
;
6066 procedure Process_Variant
(A
: Node_Id
);
6067 -- Analyze declarations for a single variant
6069 package Analyze_Variant_Choices
is
6070 new Generic_Analyze_Choices
(Process_Variant
);
6071 use Analyze_Variant_Choices
;
6073 ---------------------
6074 -- Process_Variant --
6075 ---------------------
6077 procedure Process_Variant
(A
: Node_Id
) is
6078 CL
: constant Node_Id
:= Component_List
(A
);
6080 if not Null_Present
(CL
) then
6081 Analyze_Declarations
(Component_Items
(CL
));
6083 if Present
(Variant_Part
(CL
)) then
6084 Analyze
(Variant_Part
(CL
));
6087 end Process_Variant
;
6089 -- Start of processing for Analyze_Variant_Part
6092 Discr_Name
:= Name
(N
);
6093 Analyze
(Discr_Name
);
6095 -- If Discr_Name bad, get out (prevent cascaded errors)
6097 if Etype
(Discr_Name
) = Any_Type
then
6101 -- Check invalid discriminant in variant part
6103 if Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
6104 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
6107 Discr_Type
:= Etype
(Entity
(Discr_Name
));
6109 if not Is_Discrete_Type
(Discr_Type
) then
6111 ("discriminant in a variant part must be of a discrete type",
6116 -- Now analyze the choices, which also analyzes the declarations that
6117 -- are associated with each choice.
6119 Analyze_Choices
(Variants
(N
), Discr_Type
);
6121 -- Note: we used to instantiate and call Check_Choices here to check
6122 -- that the choices covered the discriminant, but it's too early to do
6123 -- that because of statically predicated subtypes, whose analysis may
6124 -- be deferred to their freeze point which may be as late as the freeze
6125 -- point of the containing record. So this call is now to be found in
6126 -- Freeze_Record_Declaration.
6128 end Analyze_Variant_Part
;
6130 ----------------------------
6131 -- Array_Type_Declaration --
6132 ----------------------------
6134 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
6135 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
6136 Component_Typ
: constant Node_Id
:= Subtype_Indication
(Component_Def
);
6137 P
: constant Node_Id
:= Parent
(Def
);
6138 Element_Type
: Entity_Id
;
6139 Implicit_Base
: Entity_Id
;
6143 Related_Id
: Entity_Id
;
6144 Has_FLB_Index
: Boolean := False;
6147 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6148 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
6150 Index
:= First
(Subtype_Marks
(Def
));
6153 -- Find proper names for the implicit types which may be public. In case
6154 -- of anonymous arrays we use the name of the first object of that type
6158 Related_Id
:= Defining_Identifier
(P
);
6164 while Present
(Index
) loop
6167 -- Test for odd case of trying to index a type by the type itself
6169 if Is_Entity_Name
(Index
) and then Entity
(Index
) = T
then
6170 Error_Msg_N
("type& cannot be indexed by itself", Index
);
6171 Set_Entity
(Index
, Standard_Boolean
);
6172 Set_Etype
(Index
, Standard_Boolean
);
6175 -- Add a subtype declaration for each index of private array type
6176 -- declaration whose type is also private. For example:
6179 -- type Index is private;
6181 -- type Table is array (Index) of ...
6184 -- This is currently required by the expander for the internally
6185 -- generated equality subprogram of records with variant parts in
6186 -- which the type of some component is such a private type. And it
6187 -- also helps semantic analysis in peculiar cases where the array
6188 -- type is referenced from an instance but not the index directly.
6190 if Is_Package_Or_Generic_Package
(Current_Scope
)
6191 and then In_Private_Part
(Current_Scope
)
6192 and then Has_Private_Declaration
(Etype
(Index
))
6193 and then Scope
(Etype
(Index
)) = Current_Scope
6196 Loc
: constant Source_Ptr
:= Sloc
(Def
);
6201 New_E
:= Make_Temporary
(Loc
, 'T');
6202 Set_Is_Internal
(New_E
);
6205 Make_Subtype_Declaration
(Loc
,
6206 Defining_Identifier
=> New_E
,
6207 Subtype_Indication
=>
6208 New_Occurrence_Of
(Etype
(Index
), Loc
));
6210 Insert_Before
(Parent
(Def
), Decl
);
6212 Set_Etype
(Index
, New_E
);
6214 -- If the index is a range or a subtype indication it carries
6215 -- no entity. Example:
6218 -- type T is private;
6220 -- type T is new Natural;
6221 -- Table : array (T(1) .. T(10)) of Boolean;
6224 -- Otherwise the type of the reference is its entity.
6226 if Is_Entity_Name
(Index
) then
6227 Set_Entity
(Index
, New_E
);
6232 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
6234 -- In the case where we have an unconstrained array with an index
6235 -- given by a subtype_indication, this is necessarily a "fixed lower
6236 -- bound" index. We change the upper bound of that index to the upper
6237 -- bound of the index's subtype (denoted by the subtype_mark), since
6238 -- that upper bound was originally set by the parser to be the same
6239 -- as the lower bound. In truth, that upper bound corresponds to
6240 -- a box ("<>"), and could be set to Empty, but it's convenient to
6241 -- set it to the upper bound to avoid needing to add special tests
6242 -- in various places for an Empty upper bound, and in any case that
6243 -- accurately characterizes the index's range of values.
6245 if Nkind
(Def
) = N_Unconstrained_Array_Definition
6246 and then Nkind
(Index
) = N_Subtype_Indication
6249 Index_Subtype_High_Bound
: constant Entity_Id
:=
6250 Type_High_Bound
(Entity
(Subtype_Mark
(Index
)));
6252 Set_High_Bound
(Range_Expression
(Constraint
(Index
)),
6253 Index_Subtype_High_Bound
);
6255 -- Record that the array type has one or more indexes with
6256 -- a fixed lower bound.
6258 Has_FLB_Index
:= True;
6260 -- Mark the index as belonging to an array type with a fixed
6263 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(Index
));
6267 -- Check error of subtype with predicate for index type
6269 Bad_Predicated_Subtype_Use
6270 ("subtype& has predicate, not allowed as index subtype",
6271 Index
, Etype
(Index
));
6273 -- Move to next index
6276 Nb_Index
:= Nb_Index
+ 1;
6279 -- Process subtype indication if one is present
6281 if Present
(Component_Typ
) then
6282 Element_Type
:= Process_Subtype
(Component_Typ
, P
, Related_Id
, 'C');
6283 Set_Etype
(Component_Typ
, Element_Type
);
6285 -- Ada 2005 (AI-230): Access Definition case
6287 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
6289 -- Indicate that the anonymous access type is created by the
6290 -- array type declaration.
6292 Element_Type
:= Access_Definition
6294 N
=> Access_Definition
(Component_Def
));
6295 Set_Is_Local_Anonymous_Access
(Element_Type
);
6297 -- Propagate the parent. This field is needed if we have to generate
6298 -- the master_id associated with an anonymous access to task type
6299 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
6301 Copy_Parent
(To
=> Element_Type
, From
=> T
);
6303 -- Ada 2005 (AI-230): In case of components that are anonymous access
6304 -- types the level of accessibility depends on the enclosing type
6307 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
6309 -- Ada 2005 (AI-254)
6312 CD
: constant Node_Id
:=
6313 Access_To_Subprogram_Definition
6314 (Access_Definition
(Component_Def
));
6316 if Present
(CD
) and then Protected_Present
(CD
) then
6318 Replace_Anonymous_Access_To_Protected_Subprogram
(Def
);
6323 -- Constrained array case
6326 -- We might be creating more than one itype with the same Related_Id,
6327 -- e.g. for an array object definition and its initial value. Give
6328 -- them unique suffixes, because GNATprove require distinct types to
6329 -- have different names.
6331 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T', Suffix_Index
=> -1);
6334 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6336 if Ekind
(T
) in Incomplete_Or_Private_Kind
then
6337 Reinit_Field_To_Zero
(T
, F_Stored_Constraint
);
6339 pragma Assert
(Ekind
(T
) = E_Void
);
6342 -- Establish Implicit_Base as unconstrained base type
6344 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
6346 Set_Etype
(Implicit_Base
, Implicit_Base
);
6347 Set_Scope
(Implicit_Base
, Current_Scope
);
6348 Set_Has_Delayed_Freeze
(Implicit_Base
);
6349 Set_Default_SSO
(Implicit_Base
);
6351 -- The constrained array type is a subtype of the unconstrained one
6353 Mutate_Ekind
(T
, E_Array_Subtype
);
6354 Reinit_Size_Align
(T
);
6355 Set_Etype
(T
, Implicit_Base
);
6356 Set_Scope
(T
, Current_Scope
);
6357 Set_Is_Constrained
(T
);
6359 First
(Discrete_Subtype_Definitions
(Def
)));
6360 Set_Has_Delayed_Freeze
(T
);
6362 -- Complete setup of implicit base type
6364 pragma Assert
(not Known_Component_Size
(Implicit_Base
));
6365 Set_Component_Type
(Implicit_Base
, Element_Type
);
6366 Set_Finalize_Storage_Only
6368 Finalize_Storage_Only
(Element_Type
));
6369 Set_First_Index
(Implicit_Base
, First_Index
(T
));
6370 Set_Has_Controlled_Component
6372 Has_Controlled_Component
(Element_Type
)
6373 or else Is_Controlled
(Element_Type
));
6374 Set_Packed_Array_Impl_Type
6375 (Implicit_Base
, Empty
);
6377 Propagate_Concurrent_Flags
(Implicit_Base
, Element_Type
);
6379 -- Unconstrained array case
6381 else pragma Assert
(Nkind
(Def
) = N_Unconstrained_Array_Definition
);
6383 if Ekind
(T
) in Incomplete_Or_Private_Kind
then
6384 Reinit_Field_To_Zero
(T
, F_Stored_Constraint
);
6386 pragma Assert
(Ekind
(T
) = E_Void
);
6389 Mutate_Ekind
(T
, E_Array_Type
);
6390 Reinit_Size_Align
(T
);
6392 Set_Scope
(T
, Current_Scope
);
6393 pragma Assert
(not Known_Component_Size
(T
));
6394 Set_Is_Constrained
(T
, False);
6395 Set_Is_Fixed_Lower_Bound_Array_Subtype
6397 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
6398 Set_Has_Delayed_Freeze
(T
, True);
6399 Propagate_Concurrent_Flags
(T
, Element_Type
);
6400 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
6403 Is_Controlled
(Element_Type
));
6404 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
6406 Set_Default_SSO
(T
);
6409 -- Common attributes for both cases
6411 Set_Component_Type
(Base_Type
(T
), Element_Type
);
6412 Set_Packed_Array_Impl_Type
(T
, Empty
);
6414 if Aliased_Present
(Component_Definition
(Def
)) then
6415 Set_Has_Aliased_Components
(Etype
(T
));
6417 -- AI12-001: All aliased objects are considered to be specified as
6418 -- independently addressable (RM C.6(8.1/4)).
6420 Set_Has_Independent_Components
(Etype
(T
));
6423 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
6424 -- array type to ensure that objects of this type are initialized.
6426 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(Element_Type
) then
6427 Set_Can_Never_Be_Null
(T
);
6429 if Null_Exclusion_Present
(Component_Definition
(Def
))
6431 -- No need to check itypes because in their case this check was
6432 -- done at their point of creation
6434 and then not Is_Itype
(Element_Type
)
6437 ("`NOT NULL` not allowed (null already excluded)",
6438 Subtype_Indication
(Component_Definition
(Def
)));
6442 Priv
:= Private_Component
(Element_Type
);
6444 if Present
(Priv
) then
6446 -- Check for circular definitions
6448 if Priv
= Any_Type
then
6449 Set_Component_Type
(Etype
(T
), Any_Type
);
6451 -- There is a gap in the visibility of operations on the composite
6452 -- type only if the component type is defined in a different scope.
6454 elsif Scope
(Priv
) = Current_Scope
then
6457 elsif Is_Limited_Type
(Priv
) then
6458 Set_Is_Limited_Composite
(Etype
(T
));
6459 Set_Is_Limited_Composite
(T
);
6461 Set_Is_Private_Composite
(Etype
(T
));
6462 Set_Is_Private_Composite
(T
);
6466 -- A syntax error in the declaration itself may lead to an empty index
6467 -- list, in which case do a minimal patch.
6469 if No
(First_Index
(T
)) then
6470 Error_Msg_N
("missing index definition in array type declaration", T
);
6473 Indexes
: constant List_Id
:=
6474 New_List
(New_Occurrence_Of
(Any_Id
, Sloc
(T
)));
6476 Set_Discrete_Subtype_Definitions
(Def
, Indexes
);
6477 Set_First_Index
(T
, First
(Indexes
));
6482 -- Create a concatenation operator for the new type. Internal array
6483 -- types created for packed entities do not need such, they are
6484 -- compatible with the user-defined type.
6486 if Number_Dimensions
(T
) = 1
6487 and then not Is_Packed_Array_Impl_Type
(T
)
6489 New_Concatenation_Op
(T
);
6492 -- In the case of an unconstrained array the parser has already verified
6493 -- that all the indexes are unconstrained but we still need to make sure
6494 -- that the element type is constrained.
6496 if not Is_Definite_Subtype
(Element_Type
) then
6498 ("unconstrained element type in array declaration",
6499 Subtype_Indication
(Component_Def
));
6501 elsif Is_Abstract_Type
(Element_Type
) then
6503 ("the type of a component cannot be abstract",
6504 Subtype_Indication
(Component_Def
));
6507 -- There may be an invariant declared for the component type, but
6508 -- the construction of the component invariant checking procedure
6509 -- takes place during expansion.
6510 end Array_Type_Declaration
;
6512 ------------------------------------------------------
6513 -- Replace_Anonymous_Access_To_Protected_Subprogram --
6514 ------------------------------------------------------
6516 function Replace_Anonymous_Access_To_Protected_Subprogram
6517 (N
: Node_Id
) return Entity_Id
6519 Loc
: constant Source_Ptr
:= Sloc
(N
);
6521 Curr_Scope
: constant Scope_Stack_Entry
:=
6522 Scope_Stack
.Table
(Scope_Stack
.Last
);
6524 Anon
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
6527 -- Access definition in declaration
6530 -- Object definition or formal definition with an access definition
6533 -- Declaration of anonymous access to subprogram type
6536 -- Original specification in access to subprogram
6541 Set_Is_Internal
(Anon
);
6544 when N_Constrained_Array_Definition
6545 | N_Component_Declaration
6546 | N_Unconstrained_Array_Definition
6548 Comp
:= Component_Definition
(N
);
6549 Acc
:= Access_Definition
(Comp
);
6551 when N_Discriminant_Specification
=>
6552 Comp
:= Discriminant_Type
(N
);
6555 when N_Parameter_Specification
=>
6556 Comp
:= Parameter_Type
(N
);
6559 when N_Access_Function_Definition
=>
6560 Comp
:= Result_Definition
(N
);
6563 when N_Object_Declaration
=>
6564 Comp
:= Object_Definition
(N
);
6567 when N_Function_Specification
=>
6568 Comp
:= Result_Definition
(N
);
6572 raise Program_Error
;
6575 Spec
:= Access_To_Subprogram_Definition
(Acc
);
6578 Make_Full_Type_Declaration
(Loc
,
6579 Defining_Identifier
=> Anon
,
6580 Type_Definition
=> Copy_Separate_Tree
(Spec
));
6582 Mark_Rewrite_Insertion
(Decl
);
6584 -- Insert the new declaration in the nearest enclosing scope. If the
6585 -- parent is a body and N is its return type, the declaration belongs
6586 -- in the enclosing scope. Likewise if N is the type of a parameter.
6590 if Nkind
(N
) = N_Function_Specification
6591 and then Nkind
(P
) = N_Subprogram_Body
6594 elsif Nkind
(N
) = N_Parameter_Specification
6595 and then Nkind
(P
) in N_Subprogram_Specification
6596 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
6598 P
:= Parent
(Parent
(P
));
6601 while Present
(P
) and then not Has_Declarations
(P
) loop
6605 pragma Assert
(Present
(P
));
6607 if Nkind
(P
) = N_Package_Specification
then
6608 Prepend
(Decl
, Visible_Declarations
(P
));
6610 Prepend
(Decl
, Declarations
(P
));
6613 -- Replace the anonymous type with an occurrence of the new declaration.
6614 -- In all cases the rewritten node does not have the null-exclusion
6615 -- attribute because (if present) it was already inherited by the
6616 -- anonymous entity (Anon). Thus, in case of components we do not
6617 -- inherit this attribute.
6619 if Nkind
(N
) = N_Parameter_Specification
then
6620 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6621 Set_Etype
(Defining_Identifier
(N
), Anon
);
6622 Set_Null_Exclusion_Present
(N
, False);
6624 elsif Nkind
(N
) = N_Object_Declaration
then
6625 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6626 Set_Etype
(Defining_Identifier
(N
), Anon
);
6628 elsif Nkind
(N
) = N_Access_Function_Definition
then
6629 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6631 elsif Nkind
(N
) = N_Function_Specification
then
6632 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6633 Set_Etype
(Defining_Unit_Name
(N
), Anon
);
6637 Make_Component_Definition
(Loc
,
6638 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
6641 Mark_Rewrite_Insertion
(Comp
);
6643 if Nkind
(N
) in N_Object_Declaration | N_Access_Function_Definition
6644 or else (Nkind
(Parent
(N
)) = N_Full_Type_Declaration
6645 and then not Is_Type
(Current_Scope
))
6648 -- Declaration can be analyzed in the current scope.
6653 -- Temporarily remove the current scope (record or subprogram) from
6654 -- the stack to add the new declarations to the enclosing scope.
6655 -- The anonymous entity is an Itype with the proper attributes.
6657 Scope_Stack
.Decrement_Last
;
6659 Set_Is_Itype
(Anon
);
6660 Set_Associated_Node_For_Itype
(Anon
, N
);
6661 Scope_Stack
.Append
(Curr_Scope
);
6664 Mutate_Ekind
(Anon
, E_Anonymous_Access_Protected_Subprogram_Type
);
6665 Set_Can_Use_Internal_Rep
(Anon
, not Always_Compatible_Rep_On_Target
);
6667 end Replace_Anonymous_Access_To_Protected_Subprogram
;
6669 -------------------------------------
6670 -- Build_Access_Subprogram_Wrapper --
6671 -------------------------------------
6673 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
) is
6674 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
6675 Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
6676 Type_Def
: constant Node_Id
:= Type_Definition
(Decl
);
6677 Specs
: constant List_Id
:=
6678 Parameter_Specifications
(Type_Def
);
6679 Profile
: constant List_Id
:= New_List
;
6680 Subp
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6682 Contracts
: constant List_Id
:= New_List
;
6688 procedure Replace_Type_Name
(Expr
: Node_Id
);
6689 -- In the expressions for contract aspects, replace occurrences of the
6690 -- access type with the name of the subprogram entity, as needed, e.g.
6691 -- for 'Result. Aspects that are not contracts, e.g. Size or Alignment)
6692 -- remain on the original access type declaration. What about expanded
6693 -- names denoting formals, whose prefix in source is the type name ???
6695 -----------------------
6696 -- Replace_Type_Name --
6697 -----------------------
6699 procedure Replace_Type_Name
(Expr
: Node_Id
) is
6700 function Process
(N
: Node_Id
) return Traverse_Result
;
6701 function Process
(N
: Node_Id
) return Traverse_Result
is
6703 if Nkind
(N
) = N_Attribute_Reference
6704 and then Is_Entity_Name
(Prefix
(N
))
6705 and then Chars
(Prefix
(N
)) = Chars
(Id
)
6707 Set_Prefix
(N
, Make_Identifier
(Sloc
(N
), Chars
(Subp
)));
6713 procedure Traverse
is new Traverse_Proc
(Process
);
6716 end Replace_Type_Name
;
6719 if Ekind
(Id
) in E_Access_Subprogram_Type
6720 | E_Access_Protected_Subprogram_Type
6721 | E_Anonymous_Access_Protected_Subprogram_Type
6722 | E_Anonymous_Access_Subprogram_Type
6728 ("illegal pre/postcondition on access type", Decl
);
6739 Asp
:= First
(Aspect_Specifications
(Decl
));
6740 while Present
(Asp
) loop
6741 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(Asp
)));
6742 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Post
then
6744 Expr
:= Expression
(Cond
);
6745 Replace_Type_Name
(Expr
);
6749 Append
(Cond
, Contracts
);
6757 -- If there are no contract aspects, no need for a wrapper.
6759 if Is_Empty_List
(Contracts
) then
6763 Form_P
:= First
(Specs
);
6765 while Present
(Form_P
) loop
6766 New_P
:= New_Copy_Tree
(Form_P
);
6767 Set_Defining_Identifier
(New_P
,
6768 Make_Defining_Identifier
6769 (Loc
, Chars
(Defining_Identifier
(Form_P
))));
6770 Append
(New_P
, Profile
);
6774 -- Add to parameter specifications the access parameter that is passed
6775 -- in from an indirect call.
6778 Make_Parameter_Specification
(Loc
,
6779 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6780 Parameter_Type
=> New_Occurrence_Of
(Id
, Loc
)),
6783 if Nkind
(Type_Def
) = N_Access_Procedure_Definition
then
6785 Make_Procedure_Specification
(Loc
,
6786 Defining_Unit_Name
=> Subp
,
6787 Parameter_Specifications
=> Profile
);
6788 Mutate_Ekind
(Subp
, E_Procedure
);
6791 Make_Function_Specification
(Loc
,
6792 Defining_Unit_Name
=> Subp
,
6793 Parameter_Specifications
=> Profile
,
6794 Result_Definition
=>
6796 (Result_Definition
(Type_Definition
(Decl
))));
6797 Mutate_Ekind
(Subp
, E_Function
);
6801 Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
6802 Set_Aspect_Specifications
(New_Decl
, Contracts
);
6803 Set_Is_Wrapper
(Subp
);
6805 -- The wrapper is declared in the freezing actions to facilitate its
6806 -- identification and thus avoid handling it as a primitive operation
6807 -- of a tagged type (see Is_Access_To_Subprogram_Wrapper); otherwise it
6808 -- may be handled as a dispatching operation and erroneously registered
6809 -- in a dispatch table.
6811 if not GNATprove_Mode
then
6812 Ensure_Freeze_Node
(Id
);
6813 Append_Freeze_Actions
(Id
, New_List
(New_Decl
));
6815 -- Under GNATprove mode there is no such problem but we do not declare
6816 -- it in the freezing actions since they are not analyzed under this
6820 Insert_After
(Decl
, New_Decl
);
6823 Set_Access_Subprogram_Wrapper
(Designated_Type
(Id
), Subp
);
6824 Build_Access_Subprogram_Wrapper_Body
(Decl
, New_Decl
);
6825 end Build_Access_Subprogram_Wrapper
;
6827 -------------------------------
6828 -- Build_Derived_Access_Type --
6829 -------------------------------
6831 procedure Build_Derived_Access_Type
6833 Parent_Type
: Entity_Id
;
6834 Derived_Type
: Entity_Id
)
6836 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
6838 Desig_Type
: Entity_Id
;
6840 Discr_Con_Elist
: Elist_Id
;
6841 Discr_Con_El
: Elmt_Id
;
6845 -- Set the designated type so it is available in case this is an access
6846 -- to a self-referential type, e.g. a standard list type with a next
6847 -- pointer. Will be reset after subtype is built.
6849 Set_Directly_Designated_Type
6850 (Derived_Type
, Designated_Type
(Parent_Type
));
6852 Subt
:= Process_Subtype
(S
, N
);
6854 if Nkind
(S
) /= N_Subtype_Indication
6855 and then Subt
/= Base_Type
(Subt
)
6857 Mutate_Ekind
(Derived_Type
, E_Access_Subtype
);
6860 if Ekind
(Derived_Type
) = E_Access_Subtype
then
6862 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6863 Ibase
: constant Entity_Id
:=
6864 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
6865 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
6866 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
6867 Svg_Prev_E
: constant Entity_Id
:= Prev_Entity
(Ibase
);
6870 Copy_Node
(Pbase
, Ibase
);
6872 -- Restore Itype status after Copy_Node
6874 Set_Is_Itype
(Ibase
);
6875 Set_Associated_Node_For_Itype
(Ibase
, N
);
6877 Set_Chars
(Ibase
, Svg_Chars
);
6878 Set_Prev_Entity
(Ibase
, Svg_Prev_E
);
6879 Set_Next_Entity
(Ibase
, Svg_Next_E
);
6880 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
6881 Set_Scope
(Ibase
, Scope
(Derived_Type
));
6882 Set_Freeze_Node
(Ibase
, Empty
);
6883 Set_Is_Frozen
(Ibase
, False);
6884 Set_Comes_From_Source
(Ibase
, False);
6885 Set_Is_First_Subtype
(Ibase
, False);
6887 Set_Etype
(Ibase
, Pbase
);
6888 Set_Etype
(Derived_Type
, Ibase
);
6892 Set_Directly_Designated_Type
6893 (Derived_Type
, Designated_Type
(Subt
));
6895 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
6896 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
6897 Set_Size_Info
(Derived_Type
, Parent_Type
);
6898 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
6899 Set_Depends_On_Private
(Derived_Type
,
6900 Has_Private_Component
(Derived_Type
));
6901 Conditional_Delay
(Derived_Type
, Subt
);
6903 if Is_Access_Subprogram_Type
(Derived_Type
)
6904 and then Is_Base_Type
(Derived_Type
)
6906 Set_Can_Use_Internal_Rep
6907 (Derived_Type
, Can_Use_Internal_Rep
(Parent_Type
));
6910 -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
6911 -- that it is not redundant.
6913 if Null_Exclusion_Present
(Type_Definition
(N
)) then
6914 Set_Can_Never_Be_Null
(Derived_Type
);
6916 elsif Can_Never_Be_Null
(Parent_Type
) then
6917 Set_Can_Never_Be_Null
(Derived_Type
);
6920 -- Note: we do not copy the Storage_Size_Variable, since we always go to
6921 -- the root type for this information.
6923 -- Apply range checks to discriminants for derived record case
6924 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
6926 Desig_Type
:= Designated_Type
(Derived_Type
);
6928 if Is_Composite_Type
(Desig_Type
)
6929 and then (not Is_Array_Type
(Desig_Type
))
6930 and then Has_Discriminants
(Desig_Type
)
6931 and then Base_Type
(Desig_Type
) /= Desig_Type
6933 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
6934 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
6936 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
6937 while Present
(Discr_Con_El
) loop
6938 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
6939 Next_Elmt
(Discr_Con_El
);
6940 Next_Discriminant
(Discr
);
6943 end Build_Derived_Access_Type
;
6945 ------------------------------
6946 -- Build_Derived_Array_Type --
6947 ------------------------------
6949 procedure Build_Derived_Array_Type
6951 Parent_Type
: Entity_Id
;
6952 Derived_Type
: Entity_Id
)
6954 Loc
: constant Source_Ptr
:= Sloc
(N
);
6955 Tdef
: constant Node_Id
:= Type_Definition
(N
);
6956 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
6957 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6958 Implicit_Base
: Entity_Id
:= Empty
;
6959 New_Indic
: Node_Id
;
6961 procedure Make_Implicit_Base
;
6962 -- If the parent subtype is constrained, the derived type is a subtype
6963 -- of an implicit base type derived from the parent base.
6965 ------------------------
6966 -- Make_Implicit_Base --
6967 ------------------------
6969 procedure Make_Implicit_Base
is
6972 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
6974 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
6975 Set_Etype
(Implicit_Base
, Parent_Base
);
6977 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
6978 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
6980 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
6981 end Make_Implicit_Base
;
6983 -- Start of processing for Build_Derived_Array_Type
6986 if not Is_Constrained
(Parent_Type
) then
6987 if Nkind
(Indic
) /= N_Subtype_Indication
then
6988 Mutate_Ekind
(Derived_Type
, E_Array_Type
);
6990 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
6991 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
6993 Set_Has_Delayed_Freeze
(Derived_Type
, True);
6997 Set_Etype
(Derived_Type
, Implicit_Base
);
7000 Make_Subtype_Declaration
(Loc
,
7001 Defining_Identifier
=> Derived_Type
,
7002 Subtype_Indication
=>
7003 Make_Subtype_Indication
(Loc
,
7004 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7005 Constraint
=> Constraint
(Indic
)));
7007 Rewrite
(N
, New_Indic
);
7012 if Nkind
(Indic
) /= N_Subtype_Indication
then
7015 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
7016 Set_Etype
(Derived_Type
, Implicit_Base
);
7017 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7020 Error_Msg_N
("illegal constraint on constrained type", Indic
);
7024 -- If parent type is not a derived type itself, and is declared in
7025 -- closed scope (e.g. a subprogram), then we must explicitly introduce
7026 -- the new type's concatenation operator since Derive_Subprograms
7027 -- will not inherit the parent's operator. If the parent type is
7028 -- unconstrained, the operator is of the unconstrained base type.
7030 if Number_Dimensions
(Parent_Type
) = 1
7031 and then not Is_Limited_Type
(Parent_Type
)
7032 and then not Is_Derived_Type
(Parent_Type
)
7033 and then not Is_Package_Or_Generic_Package
7034 (Scope
(Base_Type
(Parent_Type
)))
7036 if not Is_Constrained
(Parent_Type
)
7037 and then Is_Constrained
(Derived_Type
)
7039 New_Concatenation_Op
(Implicit_Base
);
7041 New_Concatenation_Op
(Derived_Type
);
7044 end Build_Derived_Array_Type
;
7046 -----------------------------------
7047 -- Build_Derived_Concurrent_Type --
7048 -----------------------------------
7050 procedure Build_Derived_Concurrent_Type
7052 Parent_Type
: Entity_Id
;
7053 Derived_Type
: Entity_Id
)
7055 Loc
: constant Source_Ptr
:= Sloc
(N
);
7056 Def
: constant Node_Id
:= Type_Definition
(N
);
7057 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7059 Corr_Record
: constant Entity_Id
:= Make_Temporary
(Loc
, 'C');
7060 Corr_Decl
: Node_Id
;
7061 Corr_Decl_Needed
: Boolean;
7062 -- If the derived type has fewer discriminants than its parent, the
7063 -- corresponding record is also a derived type, in order to account for
7064 -- the bound discriminants. We create a full type declaration for it in
7067 Constraint_Present
: constant Boolean :=
7068 Nkind
(Indic
) = N_Subtype_Indication
;
7070 D_Constraint
: Node_Id
;
7071 New_Constraint
: Elist_Id
:= No_Elist
;
7072 Old_Disc
: Entity_Id
;
7073 New_Disc
: Entity_Id
;
7077 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
7078 Corr_Decl_Needed
:= False;
7081 if Present
(Discriminant_Specifications
(N
))
7082 and then Constraint_Present
7084 Old_Disc
:= First_Discriminant
(Parent_Type
);
7085 New_Disc
:= First
(Discriminant_Specifications
(N
));
7086 while Present
(New_Disc
) and then Present
(Old_Disc
) loop
7087 Next_Discriminant
(Old_Disc
);
7092 if Present
(Old_Disc
) and then Expander_Active
then
7094 -- The new type has fewer discriminants, so we need to create a new
7095 -- corresponding record, which is derived from the corresponding
7096 -- record of the parent, and has a stored constraint that captures
7097 -- the values of the discriminant constraints. The corresponding
7098 -- record is needed only if expander is active and code generation is
7101 -- The type declaration for the derived corresponding record has the
7102 -- same discriminant part and constraints as the current declaration.
7103 -- Copy the unanalyzed tree to build declaration.
7105 Corr_Decl_Needed
:= True;
7106 New_N
:= Copy_Separate_Tree
(N
);
7109 Make_Full_Type_Declaration
(Loc
,
7110 Defining_Identifier
=> Corr_Record
,
7111 Discriminant_Specifications
=>
7112 Discriminant_Specifications
(New_N
),
7114 Make_Derived_Type_Definition
(Loc
,
7115 Subtype_Indication
=>
7116 Make_Subtype_Indication
(Loc
,
7119 (Corresponding_Record_Type
(Parent_Type
), Loc
),
7122 (Subtype_Indication
(Type_Definition
(New_N
))))));
7125 -- Copy Storage_Size and Relative_Deadline variables if task case
7127 if Is_Task_Type
(Parent_Type
) then
7128 Set_Storage_Size_Variable
(Derived_Type
,
7129 Storage_Size_Variable
(Parent_Type
));
7130 Set_Relative_Deadline_Variable
(Derived_Type
,
7131 Relative_Deadline_Variable
(Parent_Type
));
7134 if Present
(Discriminant_Specifications
(N
)) then
7135 Push_Scope
(Derived_Type
);
7136 Check_Or_Process_Discriminants
(N
, Derived_Type
);
7138 if Constraint_Present
then
7140 Expand_To_Stored_Constraint
7142 Build_Discriminant_Constraints
7143 (Parent_Type
, Indic
, True));
7148 elsif Constraint_Present
then
7150 -- Build an unconstrained derived type and rewrite the derived type
7151 -- as a subtype of this new base type.
7154 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7155 New_Base
: Entity_Id
;
7157 New_Indic
: Node_Id
;
7161 Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
7164 Make_Full_Type_Declaration
(Loc
,
7165 Defining_Identifier
=> New_Base
,
7167 Make_Derived_Type_Definition
(Loc
,
7168 Abstract_Present
=> Abstract_Present
(Def
),
7169 Limited_Present
=> Limited_Present
(Def
),
7170 Subtype_Indication
=>
7171 New_Occurrence_Of
(Parent_Base
, Loc
)));
7173 Mark_Rewrite_Insertion
(New_Decl
);
7174 Insert_Before
(N
, New_Decl
);
7178 Make_Subtype_Indication
(Loc
,
7179 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
7180 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
7183 Make_Subtype_Declaration
(Loc
,
7184 Defining_Identifier
=> Derived_Type
,
7185 Subtype_Indication
=> New_Indic
));
7192 -- By default, operations and private data are inherited from parent.
7193 -- However, in the presence of bound discriminants, a new corresponding
7194 -- record will be created, see below.
7196 Set_Has_Discriminants
7197 (Derived_Type
, Has_Discriminants
(Parent_Type
));
7198 Set_Corresponding_Record_Type
7199 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
7201 -- Is_Constrained is set according the parent subtype, but is set to
7202 -- False if the derived type is declared with new discriminants.
7206 (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
7207 and then not Present
(Discriminant_Specifications
(N
)));
7209 if Constraint_Present
then
7210 if not Has_Discriminants
(Parent_Type
) then
7211 Error_Msg_N
("untagged parent must have discriminants", N
);
7213 elsif Present
(Discriminant_Specifications
(N
)) then
7215 -- Verify that new discriminants are used to constrain old ones
7217 D_Constraint
:= First
(Constraints
(Constraint
(Indic
)));
7219 Old_Disc
:= First_Discriminant
(Parent_Type
);
7221 while Present
(D_Constraint
) loop
7222 if Nkind
(D_Constraint
) /= N_Discriminant_Association
then
7224 -- Positional constraint. If it is a reference to a new
7225 -- discriminant, it constrains the corresponding old one.
7227 if Nkind
(D_Constraint
) = N_Identifier
then
7228 New_Disc
:= First_Discriminant
(Derived_Type
);
7229 while Present
(New_Disc
) loop
7230 exit when Chars
(New_Disc
) = Chars
(D_Constraint
);
7231 Next_Discriminant
(New_Disc
);
7234 if Present
(New_Disc
) then
7235 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
7239 Next_Discriminant
(Old_Disc
);
7241 -- if this is a named constraint, search by name for the old
7242 -- discriminants constrained by the new one.
7244 elsif Nkind
(Expression
(D_Constraint
)) = N_Identifier
then
7246 -- Find new discriminant with that name
7248 New_Disc
:= First_Discriminant
(Derived_Type
);
7249 while Present
(New_Disc
) loop
7251 Chars
(New_Disc
) = Chars
(Expression
(D_Constraint
));
7252 Next_Discriminant
(New_Disc
);
7255 if Present
(New_Disc
) then
7257 -- Verify that new discriminant renames some discriminant
7258 -- of the parent type, and associate the new discriminant
7259 -- with one or more old ones that it renames.
7265 Selector
:= First
(Selector_Names
(D_Constraint
));
7266 while Present
(Selector
) loop
7267 Old_Disc
:= First_Discriminant
(Parent_Type
);
7268 while Present
(Old_Disc
) loop
7269 exit when Chars
(Old_Disc
) = Chars
(Selector
);
7270 Next_Discriminant
(Old_Disc
);
7273 if Present
(Old_Disc
) then
7274 Set_Corresponding_Discriminant
7275 (New_Disc
, Old_Disc
);
7284 Next
(D_Constraint
);
7287 New_Disc
:= First_Discriminant
(Derived_Type
);
7288 while Present
(New_Disc
) loop
7289 if No
(Corresponding_Discriminant
(New_Disc
)) then
7291 ("new discriminant& must constrain old one", N
, New_Disc
);
7293 -- If a new discriminant is used in the constraint, then its
7294 -- subtype must be statically compatible with the subtype of
7295 -- the parent discriminant (RM 3.7(15)).
7298 Check_Constraining_Discriminant
7299 (New_Disc
, Corresponding_Discriminant
(New_Disc
));
7302 Next_Discriminant
(New_Disc
);
7306 elsif Present
(Discriminant_Specifications
(N
)) then
7308 ("missing discriminant constraint in untagged derivation", N
);
7311 -- The entity chain of the derived type includes the new discriminants
7312 -- but shares operations with the parent.
7314 if Present
(Discriminant_Specifications
(N
)) then
7315 Old_Disc
:= First_Discriminant
(Parent_Type
);
7316 while Present
(Old_Disc
) loop
7317 if No
(Next_Entity
(Old_Disc
))
7318 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
7321 (Last_Entity
(Derived_Type
), Next_Entity
(Old_Disc
));
7325 Next_Discriminant
(Old_Disc
);
7329 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
7330 if Has_Discriminants
(Parent_Type
) then
7331 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7332 Set_Discriminant_Constraint
(
7333 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
7337 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
7339 Set_Has_Completion
(Derived_Type
);
7341 if Corr_Decl_Needed
then
7342 Set_Stored_Constraint
(Derived_Type
, New_Constraint
);
7343 Insert_After
(N
, Corr_Decl
);
7344 Analyze
(Corr_Decl
);
7345 Set_Corresponding_Record_Type
(Derived_Type
, Corr_Record
);
7347 end Build_Derived_Concurrent_Type
;
7349 ------------------------------------
7350 -- Build_Derived_Enumeration_Type --
7351 ------------------------------------
7353 procedure Build_Derived_Enumeration_Type
7355 Parent_Type
: Entity_Id
;
7356 Derived_Type
: Entity_Id
)
7358 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean;
7359 -- When the type declaration includes a constraint, we generate
7360 -- a subtype declaration of an anonymous base type, with the constraint
7361 -- given in the original type declaration. Conceptually, the bounds
7362 -- are converted to the new base type, and this conversion freezes
7363 -- (prematurely) that base type, when the bounds are simply literals.
7364 -- As a result, a representation clause for the derived type is then
7365 -- rejected or ignored. This procedure recognizes the simple case of
7366 -- literal bounds, which allows us to indicate that the conversions
7367 -- are not freeze points, and the subsequent representation clause
7369 -- A similar approach might be used to resolve the long-standing
7370 -- problem of premature freezing of derived numeric types ???
7372 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean is
7374 return Nkind
(B
) = N_Type_Conversion
7375 and then Is_Entity_Name
(Expression
(B
))
7376 and then Ekind
(Entity
(Expression
(B
))) = E_Enumeration_Literal
;
7377 end Bound_Belongs_To_Type
;
7379 Loc
: constant Source_Ptr
:= Sloc
(N
);
7380 Def
: constant Node_Id
:= Type_Definition
(N
);
7381 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7382 Implicit_Base
: Entity_Id
;
7383 Literal
: Entity_Id
;
7384 New_Lit
: Entity_Id
;
7385 Literals_List
: List_Id
;
7386 Type_Decl
: Node_Id
;
7388 Rang_Expr
: Node_Id
;
7391 -- Since types Standard.Character and Standard.[Wide_]Wide_Character do
7392 -- not have explicit literals lists we need to process types derived
7393 -- from them specially. This is handled by Derived_Standard_Character.
7394 -- If the parent type is a generic type, there are no literals either,
7395 -- and we construct the same skeletal representation as for the generic
7398 if Is_Standard_Character_Type
(Parent_Type
) then
7399 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
7401 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
7407 if Nkind
(Indic
) /= N_Subtype_Indication
then
7409 Make_Attribute_Reference
(Loc
,
7410 Attribute_Name
=> Name_First
,
7411 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7412 Set_Etype
(Lo
, Derived_Type
);
7415 Make_Attribute_Reference
(Loc
,
7416 Attribute_Name
=> Name_Last
,
7417 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7418 Set_Etype
(Hi
, Derived_Type
);
7420 Set_Scalar_Range
(Derived_Type
,
7426 -- Analyze subtype indication and verify compatibility
7427 -- with parent type.
7429 if Base_Type
(Process_Subtype
(Indic
, N
)) /=
7430 Base_Type
(Parent_Type
)
7433 ("illegal constraint for formal discrete type", N
);
7439 -- If a constraint is present, analyze the bounds to catch
7440 -- premature usage of the derived literals.
7442 if Nkind
(Indic
) = N_Subtype_Indication
7443 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
7445 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
7446 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
7449 -- Introduce an implicit base type for the derived type even if there
7450 -- is no constraint attached to it, since this seems closer to the
7451 -- Ada semantics. Build a full type declaration tree for the derived
7452 -- type using the implicit base type as the defining identifier. Then
7453 -- build a subtype declaration tree which applies the constraint (if
7454 -- any) have it replace the derived type declaration.
7456 Literal
:= First_Literal
(Parent_Type
);
7457 Literals_List
:= New_List
;
7458 while Present
(Literal
)
7459 and then Ekind
(Literal
) = E_Enumeration_Literal
7461 -- Literals of the derived type have the same representation as
7462 -- those of the parent type, but this representation can be
7463 -- overridden by an explicit representation clause. Indicate
7464 -- that there is no explicit representation given yet. These
7465 -- derived literals are implicit operations of the new type,
7466 -- and can be overridden by explicit ones.
7468 if Nkind
(Literal
) = N_Defining_Character_Literal
then
7470 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
7472 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
7475 Mutate_Ekind
(New_Lit
, E_Enumeration_Literal
);
7476 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
7477 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
7478 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
7479 Set_Alias
(New_Lit
, Literal
);
7480 Set_Is_Known_Valid
(New_Lit
, True);
7482 Append
(New_Lit
, Literals_List
);
7483 Next_Literal
(Literal
);
7487 Make_Defining_Identifier
(Sloc
(Derived_Type
),
7488 Chars
=> New_External_Name
(Chars
(Derived_Type
), 'B'));
7490 -- Indicate the proper nature of the derived type. This must be done
7491 -- before analysis of the literals, to recognize cases when a literal
7492 -- may be hidden by a previous explicit function definition (cf.
7495 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
7496 Set_Etype
(Derived_Type
, Implicit_Base
);
7499 Make_Full_Type_Declaration
(Loc
,
7500 Defining_Identifier
=> Implicit_Base
,
7501 Discriminant_Specifications
=> No_List
,
7503 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
7505 Mark_Rewrite_Insertion
(Type_Decl
);
7506 Insert_Before
(N
, Type_Decl
);
7507 Analyze
(Type_Decl
);
7509 -- The anonymous base now has a full declaration, but this base
7510 -- is not a first subtype.
7512 Set_Is_First_Subtype
(Implicit_Base
, False);
7514 -- After the implicit base is analyzed its Etype needs to be changed
7515 -- to reflect the fact that it is derived from the parent type which
7516 -- was ignored during analysis. We also set the size at this point.
7518 Set_Etype
(Implicit_Base
, Parent_Type
);
7520 Set_Size_Info
(Implicit_Base
, Parent_Type
);
7521 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
7522 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
7524 -- Copy other flags from parent type
7526 Set_Has_Non_Standard_Rep
7527 (Implicit_Base
, Has_Non_Standard_Rep
7529 Set_Has_Pragma_Ordered
7530 (Implicit_Base
, Has_Pragma_Ordered
7532 Set_Has_Delayed_Freeze
(Implicit_Base
);
7534 -- Process the subtype indication including a validation check on the
7535 -- constraint, if any. If a constraint is given, its bounds must be
7536 -- implicitly converted to the new type.
7538 if Nkind
(Indic
) = N_Subtype_Indication
then
7540 R
: constant Node_Id
:=
7541 Range_Expression
(Constraint
(Indic
));
7544 if Nkind
(R
) = N_Range
then
7545 Hi
:= Build_Scalar_Bound
7546 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
7547 Lo
:= Build_Scalar_Bound
7548 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
7551 -- Constraint is a Range attribute. Replace with explicit
7552 -- mention of the bounds of the prefix, which must be a
7555 Analyze
(Prefix
(R
));
7557 Convert_To
(Implicit_Base
,
7558 Make_Attribute_Reference
(Loc
,
7559 Attribute_Name
=> Name_Last
,
7561 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7564 Convert_To
(Implicit_Base
,
7565 Make_Attribute_Reference
(Loc
,
7566 Attribute_Name
=> Name_First
,
7568 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7575 (Type_High_Bound
(Parent_Type
),
7576 Parent_Type
, Implicit_Base
);
7579 (Type_Low_Bound
(Parent_Type
),
7580 Parent_Type
, Implicit_Base
);
7588 -- If we constructed a default range for the case where no range
7589 -- was given, then the expressions in the range must not freeze
7590 -- since they do not correspond to expressions in the source.
7591 -- However, if the type inherits predicates the expressions will
7592 -- be elaborated earlier and must freeze.
7594 if (Nkind
(Indic
) /= N_Subtype_Indication
7596 (Bound_Belongs_To_Type
(Lo
) and then Bound_Belongs_To_Type
(Hi
)))
7597 and then not Has_Predicates
(Derived_Type
)
7599 Set_Must_Not_Freeze
(Lo
);
7600 Set_Must_Not_Freeze
(Hi
);
7601 Set_Must_Not_Freeze
(Rang_Expr
);
7605 Make_Subtype_Declaration
(Loc
,
7606 Defining_Identifier
=> Derived_Type
,
7607 Subtype_Indication
=>
7608 Make_Subtype_Indication
(Loc
,
7609 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7611 Make_Range_Constraint
(Loc
,
7612 Range_Expression
=> Rang_Expr
))));
7616 -- Propagate the aspects from the original type declaration to the
7617 -- declaration of the implicit base.
7619 Move_Aspects
(From
=> Original_Node
(N
), To
=> Type_Decl
);
7621 -- Apply a range check. Since this range expression doesn't have an
7622 -- Etype, we have to specifically pass the Source_Typ parameter. Is
7625 if Nkind
(Indic
) = N_Subtype_Indication
then
7627 (Range_Expression
(Constraint
(Indic
)), Parent_Type
,
7628 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
7631 end Build_Derived_Enumeration_Type
;
7633 --------------------------------
7634 -- Build_Derived_Numeric_Type --
7635 --------------------------------
7637 procedure Build_Derived_Numeric_Type
7639 Parent_Type
: Entity_Id
;
7640 Derived_Type
: Entity_Id
)
7642 Loc
: constant Source_Ptr
:= Sloc
(N
);
7643 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7644 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7645 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7646 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
7647 N_Subtype_Indication
;
7648 Implicit_Base
: Entity_Id
;
7654 -- Process the subtype indication including a validation check on
7655 -- the constraint if any.
7657 Discard_Node
(Process_Subtype
(Indic
, N
));
7659 -- Introduce an implicit base type for the derived type even if there
7660 -- is no constraint attached to it, since this seems closer to the Ada
7664 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7666 Set_Etype
(Implicit_Base
, Parent_Base
);
7667 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7668 Set_Size_Info
(Implicit_Base
, Parent_Base
);
7669 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
7670 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
7671 Set_Is_Known_Valid
(Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7672 Set_Is_Volatile
(Implicit_Base
, Is_Volatile
(Parent_Base
));
7674 -- Set RM Size for discrete type or decimal fixed-point type
7675 -- Ordinary fixed-point is excluded, why???
7677 if Is_Discrete_Type
(Parent_Base
)
7678 or else Is_Decimal_Fixed_Point_Type
(Parent_Base
)
7680 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
7683 Set_Has_Delayed_Freeze
(Implicit_Base
);
7685 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
7686 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
7688 Set_Scalar_Range
(Implicit_Base
,
7693 if Has_Infinities
(Parent_Base
) then
7694 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
7697 -- The Derived_Type, which is the entity of the declaration, is a
7698 -- subtype of the implicit base. Its Ekind is a subtype, even in the
7699 -- absence of an explicit constraint.
7701 Set_Etype
(Derived_Type
, Implicit_Base
);
7703 -- If we did not have a constraint, then the Ekind is set from the
7704 -- parent type (otherwise Process_Subtype has set the bounds)
7706 if No_Constraint
then
7707 Mutate_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
7710 -- If we did not have a range constraint, then set the range from the
7711 -- parent type. Otherwise, the Process_Subtype call has set the bounds.
7713 if No_Constraint
or else not Has_Range_Constraint
(Indic
) then
7714 Set_Scalar_Range
(Derived_Type
,
7716 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
7717 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
7718 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7720 if Has_Infinities
(Parent_Type
) then
7721 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
7724 Set_Is_Known_Valid
(Derived_Type
, Is_Known_Valid
(Parent_Type
));
7727 Set_Is_Descendant_Of_Address
(Derived_Type
,
7728 Is_Descendant_Of_Address
(Parent_Type
));
7729 Set_Is_Descendant_Of_Address
(Implicit_Base
,
7730 Is_Descendant_Of_Address
(Parent_Type
));
7732 -- Set remaining type-specific fields, depending on numeric type
7734 if Is_Modular_Integer_Type
(Parent_Type
) then
7735 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
7737 Set_Non_Binary_Modulus
7738 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
7741 (Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7743 elsif Is_Floating_Point_Type
(Parent_Type
) then
7745 -- Digits of base type is always copied from the digits value of
7746 -- the parent base type, but the digits of the derived type will
7747 -- already have been set if there was a constraint present.
7749 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7750 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Parent_Base
));
7752 if No_Constraint
then
7753 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
7756 elsif Is_Fixed_Point_Type
(Parent_Type
) then
7758 -- Small of base type and derived type are always copied from the
7759 -- parent base type, since smalls never change. The delta of the
7760 -- base type is also copied from the parent base type. However the
7761 -- delta of the derived type will have been set already if a
7762 -- constraint was present.
7764 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
7765 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
7766 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
7768 if No_Constraint
then
7769 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
7772 -- The scale and machine radix in the decimal case are always
7773 -- copied from the parent base type.
7775 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
7776 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
7777 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
7779 Set_Machine_Radix_10
7780 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
7781 Set_Machine_Radix_10
7782 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
7784 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7786 if No_Constraint
then
7787 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
7790 -- the analysis of the subtype_indication sets the
7791 -- digits value of the derived type.
7798 if Is_Integer_Type
(Parent_Type
) then
7799 Set_Has_Shift_Operator
7800 (Implicit_Base
, Has_Shift_Operator
(Parent_Type
));
7803 -- The type of the bounds is that of the parent type, and they
7804 -- must be converted to the derived type.
7806 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
7808 -- The implicit_base should be frozen when the derived type is frozen,
7809 -- but note that it is used in the conversions of the bounds. For fixed
7810 -- types we delay the determination of the bounds until the proper
7811 -- freezing point. For other numeric types this is rejected by GCC, for
7812 -- reasons that are currently unclear (???), so we choose to freeze the
7813 -- implicit base now. In the case of integers and floating point types
7814 -- this is harmless because subsequent representation clauses cannot
7815 -- affect anything, but it is still baffling that we cannot use the
7816 -- same mechanism for all derived numeric types.
7818 -- There is a further complication: actually some representation
7819 -- clauses can affect the implicit base type. For example, attribute
7820 -- definition clauses for stream-oriented attributes need to set the
7821 -- corresponding TSS entries on the base type, and this normally
7822 -- cannot be done after the base type is frozen, so the circuitry in
7823 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility
7824 -- and not use Set_TSS in this case.
7826 -- There are also consequences for the case of delayed representation
7827 -- aspects for some cases. For example, a Size aspect is delayed and
7828 -- should not be evaluated to the freeze point. This early freezing
7829 -- means that the size attribute evaluation happens too early???
7831 if Is_Fixed_Point_Type
(Parent_Type
) then
7832 Conditional_Delay
(Implicit_Base
, Parent_Type
);
7834 Freeze_Before
(N
, Implicit_Base
);
7836 end Build_Derived_Numeric_Type
;
7838 --------------------------------
7839 -- Build_Derived_Private_Type --
7840 --------------------------------
7842 procedure Build_Derived_Private_Type
7844 Parent_Type
: Entity_Id
;
7845 Derived_Type
: Entity_Id
;
7846 Is_Completion
: Boolean;
7847 Derive_Subps
: Boolean := True)
7849 Loc
: constant Source_Ptr
:= Sloc
(N
);
7850 Par_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7851 Par_Scope
: constant Entity_Id
:= Scope
(Par_Base
);
7852 Full_N
: constant Node_Id
:= New_Copy_Tree
(N
);
7853 Full_Der
: Entity_Id
:= New_Copy
(Derived_Type
);
7856 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
;
7857 -- Return the Full_View or Underlying_Full_View of Typ, whichever is
7858 -- present (they cannot be both present for the same type), or Empty.
7860 procedure Build_Full_Derivation
;
7861 -- Build full derivation, i.e. derive from the full view
7863 procedure Copy_And_Build
;
7864 -- Copy derived type declaration, replace parent with its full view,
7865 -- and build derivation
7867 -------------------------
7868 -- Available_Full_View --
7869 -------------------------
7871 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
is
7873 if Present
(Full_View
(Typ
)) then
7874 return Full_View
(Typ
);
7876 elsif Present
(Underlying_Full_View
(Typ
)) then
7878 -- We should be called on a type with an underlying full view
7879 -- only by means of the recursive call made in Copy_And_Build
7880 -- through the first call to Build_Derived_Type, or else if
7881 -- the parent scope is being analyzed because we are deriving
7884 pragma Assert
(Is_Completion
or else In_Private_Part
(Par_Scope
));
7886 return Underlying_Full_View
(Typ
);
7891 end Available_Full_View
;
7893 ---------------------------
7894 -- Build_Full_Derivation --
7895 ---------------------------
7897 procedure Build_Full_Derivation
is
7899 -- If parent scope is not open, install the declarations
7901 if not In_Open_Scopes
(Par_Scope
) then
7902 Install_Private_Declarations
(Par_Scope
);
7903 Install_Visible_Declarations
(Par_Scope
);
7905 Uninstall_Declarations
(Par_Scope
);
7907 -- If parent scope is open and in another unit, and parent has a
7908 -- completion, then the derivation is taking place in the visible
7909 -- part of a child unit. In that case retrieve the full view of
7910 -- the parent momentarily.
7912 elsif not In_Same_Source_Unit
(N
, Parent_Type
)
7913 and then Present
(Full_View
(Parent_Type
))
7915 Full_P
:= Full_View
(Parent_Type
);
7916 Exchange_Declarations
(Parent_Type
);
7918 Exchange_Declarations
(Full_P
);
7920 -- Otherwise it is a local derivation
7925 end Build_Full_Derivation
;
7927 --------------------
7928 -- Copy_And_Build --
7929 --------------------
7931 procedure Copy_And_Build
is
7932 Full_Parent
: Entity_Id
:= Parent_Type
;
7935 -- If the parent is itself derived from another private type,
7936 -- installing the private declarations has not affected its
7937 -- privacy status, so use its own full view explicitly.
7939 if Is_Private_Type
(Full_Parent
)
7940 and then Present
(Full_View
(Full_Parent
))
7942 Full_Parent
:= Full_View
(Full_Parent
);
7945 -- If the full view is itself derived from another private type
7946 -- and has got an underlying full view, and this is done for a
7947 -- completion, i.e. to build the underlying full view of the type,
7948 -- then use this underlying full view. We cannot do that if this
7949 -- is not a completion, i.e. to build the full view of the type,
7950 -- because this would break the privacy of the parent type, except
7951 -- if the parent scope is being analyzed because we are deriving a
7954 if Is_Private_Type
(Full_Parent
)
7955 and then Present
(Underlying_Full_View
(Full_Parent
))
7956 and then (Is_Completion
or else In_Private_Part
(Par_Scope
))
7958 Full_Parent
:= Underlying_Full_View
(Full_Parent
);
7961 -- For private, record, concurrent, access and almost all enumeration
7962 -- types, the derivation from the full view requires a fully-fledged
7963 -- declaration. In the other cases, just use an itype.
7965 if Is_Private_Type
(Full_Parent
)
7966 or else Is_Record_Type
(Full_Parent
)
7967 or else Is_Concurrent_Type
(Full_Parent
)
7968 or else Is_Access_Type
(Full_Parent
)
7970 (Is_Enumeration_Type
(Full_Parent
)
7971 and then not Is_Standard_Character_Type
(Full_Parent
)
7972 and then not Is_Generic_Type
(Root_Type
(Full_Parent
)))
7974 -- Copy and adjust declaration to provide a completion for what
7975 -- is originally a private declaration. Indicate that full view
7976 -- is internally generated.
7978 Set_Comes_From_Source
(Full_N
, False);
7979 Set_Comes_From_Source
(Full_Der
, False);
7980 Set_Parent
(Full_Der
, Full_N
);
7981 Set_Defining_Identifier
(Full_N
, Full_Der
);
7983 -- If there are no constraints, adjust the subtype mark
7985 if Nkind
(Subtype_Indication
(Type_Definition
(Full_N
))) /=
7986 N_Subtype_Indication
7988 Set_Subtype_Indication
7989 (Type_Definition
(Full_N
),
7990 New_Occurrence_Of
(Full_Parent
, Sloc
(Full_N
)));
7993 Insert_After
(N
, Full_N
);
7995 -- Build full view of derived type from full view of parent which
7996 -- is now installed. Subprograms have been derived on the partial
7997 -- view, the completion does not derive them anew.
7999 if Is_Record_Type
(Full_Parent
) then
8001 -- If parent type is tagged, the completion inherits the proper
8002 -- primitive operations.
8004 if Is_Tagged_Type
(Parent_Type
) then
8005 Build_Derived_Record_Type
8006 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
);
8008 Build_Derived_Record_Type
8009 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
=> False);
8013 -- If the parent type is private, this is not a completion and
8014 -- we build the full derivation recursively as a completion.
8017 (Full_N
, Full_Parent
, Full_Der
,
8018 Is_Completion
=> Is_Private_Type
(Full_Parent
),
8019 Derive_Subps
=> False);
8022 -- The full declaration has been introduced into the tree and
8023 -- processed in the step above. It should not be analyzed again
8024 -- (when encountered later in the current list of declarations)
8025 -- to prevent spurious name conflicts. The full entity remains
8028 Set_Analyzed
(Full_N
);
8032 Make_Defining_Identifier
(Sloc
(Derived_Type
),
8033 Chars
=> Chars
(Derived_Type
));
8034 Set_Is_Itype
(Full_Der
);
8035 Set_Associated_Node_For_Itype
(Full_Der
, N
);
8036 Set_Parent
(Full_Der
, N
);
8038 (N
, Full_Parent
, Full_Der
,
8039 Is_Completion
=> False, Derive_Subps
=> False);
8042 Set_Has_Private_Declaration
(Full_Der
);
8043 Set_Has_Private_Declaration
(Derived_Type
);
8045 Set_Scope
(Full_Der
, Scope
(Derived_Type
));
8046 Set_Is_First_Subtype
(Full_Der
, Is_First_Subtype
(Derived_Type
));
8047 Set_Has_Size_Clause
(Full_Der
, False);
8048 Set_Has_Alignment_Clause
(Full_Der
, False);
8049 Set_Has_Delayed_Freeze
(Full_Der
);
8050 Set_Is_Frozen
(Full_Der
, False);
8051 Set_Freeze_Node
(Full_Der
, Empty
);
8052 Set_Depends_On_Private
(Full_Der
, Has_Private_Component
(Full_Der
));
8053 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
8055 -- The convention on the base type may be set in the private part
8056 -- and not propagated to the subtype until later, so we obtain the
8057 -- convention from the base type of the parent.
8059 Set_Convention
(Full_Der
, Convention
(Base_Type
(Full_Parent
)));
8062 -- Start of processing for Build_Derived_Private_Type
8065 if Is_Tagged_Type
(Parent_Type
) then
8066 Full_P
:= Full_View
(Parent_Type
);
8068 -- A type extension of a type with unknown discriminants is an
8069 -- indefinite type that the back-end cannot handle directly.
8070 -- We treat it as a private type, and build a completion that is
8071 -- derived from the full view of the parent, and hopefully has
8072 -- known discriminants.
8074 -- If the full view of the parent type has an underlying record view,
8075 -- use it to generate the underlying record view of this derived type
8076 -- (required for chains of derivations with unknown discriminants).
8078 -- Minor optimization: we avoid the generation of useless underlying
8079 -- record view entities if the private type declaration has unknown
8080 -- discriminants but its corresponding full view has no
8083 if Has_Unknown_Discriminants
(Parent_Type
)
8084 and then Present
(Full_P
)
8085 and then (Has_Discriminants
(Full_P
)
8086 or else Present
(Underlying_Record_View
(Full_P
)))
8087 and then not In_Open_Scopes
(Par_Scope
)
8088 and then Expander_Active
8091 Full_Der
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
8092 New_Ext
: constant Node_Id
:=
8094 (Record_Extension_Part
(Type_Definition
(N
)));
8098 Build_Derived_Record_Type
8099 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8101 -- Build anonymous completion, as a derivation from the full
8102 -- view of the parent. This is not a completion in the usual
8103 -- sense, because the current type is not private.
8106 Make_Full_Type_Declaration
(Loc
,
8107 Defining_Identifier
=> Full_Der
,
8109 Make_Derived_Type_Definition
(Loc
,
8110 Subtype_Indication
=>
8112 (Subtype_Indication
(Type_Definition
(N
))),
8113 Record_Extension_Part
=> New_Ext
));
8115 -- If the parent type has an underlying record view, use it
8116 -- here to build the new underlying record view.
8118 if Present
(Underlying_Record_View
(Full_P
)) then
8120 (Nkind
(Subtype_Indication
(Type_Definition
(Decl
)))
8122 Set_Entity
(Subtype_Indication
(Type_Definition
(Decl
)),
8123 Underlying_Record_View
(Full_P
));
8126 Install_Private_Declarations
(Par_Scope
);
8127 Install_Visible_Declarations
(Par_Scope
);
8128 Insert_Before
(N
, Decl
);
8130 -- Mark entity as an underlying record view before analysis,
8131 -- to avoid generating the list of its primitive operations
8132 -- (which is not really required for this entity) and thus
8133 -- prevent spurious errors associated with missing overriding
8134 -- of abstract primitives (overridden only for Derived_Type).
8136 Mutate_Ekind
(Full_Der
, E_Record_Type
);
8137 Set_Is_Underlying_Record_View
(Full_Der
);
8138 Set_Default_SSO
(Full_Der
);
8139 Set_No_Reordering
(Full_Der
, No_Component_Reordering
);
8143 pragma Assert
(Has_Discriminants
(Full_Der
)
8144 and then not Has_Unknown_Discriminants
(Full_Der
));
8146 Uninstall_Declarations
(Par_Scope
);
8148 -- Freeze the underlying record view, to prevent generation of
8149 -- useless dispatching information, which is simply shared with
8150 -- the real derived type.
8152 Set_Is_Frozen
(Full_Der
);
8154 -- If the derived type has access discriminants, create
8155 -- references to their anonymous types now, to prevent
8156 -- back-end problems when their first use is in generated
8157 -- bodies of primitives.
8163 E
:= First_Entity
(Full_Der
);
8165 while Present
(E
) loop
8166 if Ekind
(E
) = E_Discriminant
8167 and then Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
8169 Build_Itype_Reference
(Etype
(E
), Decl
);
8176 -- Set up links between real entity and underlying record view
8178 Set_Underlying_Record_View
(Derived_Type
, Base_Type
(Full_Der
));
8179 Set_Underlying_Record_View
(Base_Type
(Full_Der
), Derived_Type
);
8182 -- If discriminants are known, build derived record
8185 Build_Derived_Record_Type
8186 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8191 elsif Has_Discriminants
(Parent_Type
) then
8193 -- Build partial view of derived type from partial view of parent.
8194 -- This must be done before building the full derivation because the
8195 -- second derivation will modify the discriminants of the first and
8196 -- the discriminants are chained with the rest of the components in
8197 -- the full derivation.
8199 Build_Derived_Record_Type
8200 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8202 -- Build the full derivation if this is not the anonymous derived
8203 -- base type created by Build_Derived_Record_Type in the constrained
8204 -- case (see point 5. of its head comment) since we build it for the
8207 if Present
(Available_Full_View
(Parent_Type
))
8208 and then not Is_Itype
(Derived_Type
)
8211 Der_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
8213 Last_Discr
: Entity_Id
;
8216 -- If this is not a completion, construct the implicit full
8217 -- view by deriving from the full view of the parent type.
8218 -- But if this is a completion, the derived private type
8219 -- being built is a full view and the full derivation can
8220 -- only be its underlying full view.
8222 Build_Full_Derivation
;
8224 if not Is_Completion
then
8225 Set_Full_View
(Derived_Type
, Full_Der
);
8227 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8228 Set_Is_Underlying_Full_View
(Full_Der
);
8231 if not Is_Base_Type
(Derived_Type
) then
8232 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
8235 -- Copy the discriminant list from full view to the partial
8236 -- view (base type and its subtype). Gigi requires that the
8237 -- partial and full views have the same discriminants.
8239 -- Note that since the partial view points to discriminants
8240 -- in the full view, their scope will be that of the full
8241 -- view. This might cause some front end problems and need
8244 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
8245 Set_First_Entity
(Der_Base
, Discr
);
8248 Last_Discr
:= Discr
;
8249 Next_Discriminant
(Discr
);
8250 exit when No
(Discr
);
8253 Set_Last_Entity
(Der_Base
, Last_Discr
);
8254 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
8255 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
8259 elsif Present
(Available_Full_View
(Parent_Type
))
8260 and then Has_Discriminants
(Available_Full_View
(Parent_Type
))
8262 if Has_Unknown_Discriminants
(Parent_Type
)
8263 and then Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8264 N_Subtype_Indication
8267 ("cannot constrain type with unknown discriminants",
8268 Subtype_Indication
(Type_Definition
(N
)));
8272 -- If this is not a completion, construct the implicit full view by
8273 -- deriving from the full view of the parent type. But if this is a
8274 -- completion, the derived private type being built is a full view
8275 -- and the full derivation can only be its underlying full view.
8277 Build_Full_Derivation
;
8279 if not Is_Completion
then
8280 Set_Full_View
(Derived_Type
, Full_Der
);
8282 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8283 Set_Is_Underlying_Full_View
(Full_Der
);
8286 -- In any case, the primitive operations are inherited from the
8287 -- parent type, not from the internal full view.
8289 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
8291 if Derive_Subps
then
8292 Derive_Subprograms
(Parent_Type
, Derived_Type
);
8295 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8297 (Derived_Type
, Is_Constrained
(Available_Full_View
(Parent_Type
)));
8300 -- Untagged type, No discriminants on either view
8302 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8303 N_Subtype_Indication
8306 ("illegal constraint on type without discriminants", N
);
8309 if Present
(Discriminant_Specifications
(N
))
8310 and then Present
(Available_Full_View
(Parent_Type
))
8311 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8313 Error_Msg_N
("cannot add discriminants to untagged type", N
);
8316 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8317 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
8319 Set_Is_Controlled_Active
8320 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
8322 Set_Disable_Controlled
8323 (Derived_Type
, Disable_Controlled
(Parent_Type
));
8325 Set_Has_Controlled_Component
8326 (Derived_Type
, Has_Controlled_Component
(Parent_Type
));
8328 -- Direct controlled types do not inherit Finalize_Storage_Only flag
8330 if not Is_Controlled
(Parent_Type
) then
8331 Set_Finalize_Storage_Only
8332 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
8335 -- If this is not a completion, construct the implicit full view by
8336 -- deriving from the full view of the parent type. But if this is a
8337 -- completion, the derived private type being built is a full view
8338 -- and the full derivation can only be its underlying full view.
8340 -- ??? If the parent type is untagged private and its completion is
8341 -- tagged, this mechanism will not work because we cannot derive from
8342 -- the tagged full view unless we have an extension.
8344 if Present
(Available_Full_View
(Parent_Type
))
8345 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8346 and then not Error_Posted
(N
)
8348 Build_Full_Derivation
;
8350 if not Is_Completion
then
8351 Set_Full_View
(Derived_Type
, Full_Der
);
8353 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8354 Set_Is_Underlying_Full_View
(Full_Der
);
8359 Set_Has_Unknown_Discriminants
(Derived_Type
,
8360 Has_Unknown_Discriminants
(Parent_Type
));
8362 if Is_Private_Type
(Derived_Type
) then
8363 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
8366 -- If the parent base type is in scope, add the derived type to its
8367 -- list of private dependents, because its full view may become
8368 -- visible subsequently (in a nested private part, a body, or in a
8369 -- further child unit).
8371 if Is_Private_Type
(Par_Base
) and then In_Open_Scopes
(Par_Scope
) then
8372 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
8374 -- Check for unusual case where a type completed by a private
8375 -- derivation occurs within a package nested in a child unit, and
8376 -- the parent is declared in an ancestor.
8378 if Is_Child_Unit
(Scope
(Current_Scope
))
8379 and then Is_Completion
8380 and then In_Private_Part
(Current_Scope
)
8381 and then Scope
(Parent_Type
) /= Current_Scope
8383 -- Note that if the parent has a completion in the private part,
8384 -- (which is itself a derivation from some other private type)
8385 -- it is that completion that is visible, there is no full view
8386 -- available, and no special processing is needed.
8388 and then Present
(Full_View
(Parent_Type
))
8390 -- In this case, the full view of the parent type will become
8391 -- visible in the body of the enclosing child, and only then will
8392 -- the current type be possibly non-private. Build an underlying
8393 -- full view that will be installed when the enclosing child body
8396 if Present
(Underlying_Full_View
(Derived_Type
)) then
8397 Full_Der
:= Underlying_Full_View
(Derived_Type
);
8399 Build_Full_Derivation
;
8400 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8401 Set_Is_Underlying_Full_View
(Full_Der
);
8404 -- The full view will be used to swap entities on entry/exit to
8405 -- the body, and must appear in the entity list for the package.
8407 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
8410 end Build_Derived_Private_Type
;
8412 -------------------------------
8413 -- Build_Derived_Record_Type --
8414 -------------------------------
8418 -- Ideally we would like to use the same model of type derivation for
8419 -- tagged and untagged record types. Unfortunately this is not quite
8420 -- possible because the semantics of representation clauses is different
8421 -- for tagged and untagged records under inheritance. Consider the
8424 -- type R (...) is [tagged] record ... end record;
8425 -- type T (...) is new R (...) [with ...];
8427 -- The representation clauses for T can specify a completely different
8428 -- record layout from R's. Hence the same component can be placed in two
8429 -- very different positions in objects of type T and R. If R and T are
8430 -- tagged types, representation clauses for T can only specify the layout
8431 -- of non inherited components, thus components that are common in R and T
8432 -- have the same position in objects of type R and T.
8434 -- This has two implications. The first is that the entire tree for R's
8435 -- declaration needs to be copied for T in the untagged case, so that T
8436 -- can be viewed as a record type of its own with its own representation
8437 -- clauses. The second implication is the way we handle discriminants.
8438 -- Specifically, in the untagged case we need a way to communicate to Gigi
8439 -- what are the real discriminants in the record, while for the semantics
8440 -- we need to consider those introduced by the user to rename the
8441 -- discriminants in the parent type. This is handled by introducing the
8442 -- notion of stored discriminants. See below for more.
8444 -- Fortunately the way regular components are inherited can be handled in
8445 -- the same way in tagged and untagged types.
8447 -- To complicate things a bit more the private view of a private extension
8448 -- cannot be handled in the same way as the full view (for one thing the
8449 -- semantic rules are somewhat different). We will explain what differs
8452 -- 2. DISCRIMINANTS UNDER INHERITANCE
8454 -- The semantic rules governing the discriminants of derived types are
8457 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
8458 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
8460 -- If parent type has discriminants, then the discriminants that are
8461 -- declared in the derived type are [3.4 (11)]:
8463 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
8466 -- o Otherwise, each discriminant of the parent type (implicitly declared
8467 -- in the same order with the same specifications). In this case, the
8468 -- discriminants are said to be "inherited", or if unknown in the parent
8469 -- are also unknown in the derived type.
8471 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
8473 -- o The parent subtype must be constrained;
8475 -- o If the parent type is not a tagged type, then each discriminant of
8476 -- the derived type must be used in the constraint defining a parent
8477 -- subtype. [Implementation note: This ensures that the new discriminant
8478 -- can share storage with an existing discriminant.]
8480 -- For the derived type each discriminant of the parent type is either
8481 -- inherited, constrained to equal some new discriminant of the derived
8482 -- type, or constrained to the value of an expression.
8484 -- When inherited or constrained to equal some new discriminant, the
8485 -- parent discriminant and the discriminant of the derived type are said
8488 -- If a discriminant of the parent type is constrained to a specific value
8489 -- in the derived type definition, then the discriminant is said to be
8490 -- "specified" by that derived type definition.
8492 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
8494 -- We have spoken about stored discriminants in point 1 (introduction)
8495 -- above. There are two sorts of stored discriminants: implicit and
8496 -- explicit. As long as the derived type inherits the same discriminants as
8497 -- the root record type, stored discriminants are the same as regular
8498 -- discriminants, and are said to be implicit. However, if any discriminant
8499 -- in the root type was renamed in the derived type, then the derived
8500 -- type will contain explicit stored discriminants. Explicit stored
8501 -- discriminants are discriminants in addition to the semantically visible
8502 -- discriminants defined for the derived type. Stored discriminants are
8503 -- used by Gigi to figure out what are the physical discriminants in
8504 -- objects of the derived type (see precise definition in einfo.ads).
8505 -- As an example, consider the following:
8507 -- type R (D1, D2, D3 : Int) is record ... end record;
8508 -- type T1 is new R;
8509 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
8510 -- type T3 is new T2;
8511 -- type T4 (Y : Int) is new T3 (Y, 99);
8513 -- The following table summarizes the discriminants and stored
8514 -- discriminants in R and T1 through T4:
8516 -- Type Discrim Stored Discrim Comment
8517 -- R (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in R
8518 -- T1 (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in T1
8519 -- T2 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T2
8520 -- T3 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T3
8521 -- T4 (Y) (D1, D2, D3) Stored discrims EXPLICIT in T4
8523 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
8524 -- find the corresponding discriminant in the parent type, while
8525 -- Original_Record_Component (abbreviated ORC below) the actual physical
8526 -- component that is renamed. Finally the field Is_Completely_Hidden
8527 -- (abbreviated ICH below) is set for all explicit stored discriminants
8528 -- (see einfo.ads for more info). For the above example this gives:
8530 -- Discrim CD ORC ICH
8531 -- ^^^^^^^ ^^ ^^^ ^^^
8532 -- D1 in R empty itself no
8533 -- D2 in R empty itself no
8534 -- D3 in R empty itself no
8536 -- D1 in T1 D1 in R itself no
8537 -- D2 in T1 D2 in R itself no
8538 -- D3 in T1 D3 in R itself no
8540 -- X1 in T2 D3 in T1 D3 in T2 no
8541 -- X2 in T2 D1 in T1 D1 in T2 no
8542 -- D1 in T2 empty itself yes
8543 -- D2 in T2 empty itself yes
8544 -- D3 in T2 empty itself yes
8546 -- X1 in T3 X1 in T2 D3 in T3 no
8547 -- X2 in T3 X2 in T2 D1 in T3 no
8548 -- D1 in T3 empty itself yes
8549 -- D2 in T3 empty itself yes
8550 -- D3 in T3 empty itself yes
8552 -- Y in T4 X1 in T3 D3 in T4 no
8553 -- D1 in T4 empty itself yes
8554 -- D2 in T4 empty itself yes
8555 -- D3 in T4 empty itself yes
8557 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
8559 -- Type derivation for tagged types is fairly straightforward. If no
8560 -- discriminants are specified by the derived type, these are inherited
8561 -- from the parent. No explicit stored discriminants are ever necessary.
8562 -- The only manipulation that is done to the tree is that of adding a
8563 -- _parent field with parent type and constrained to the same constraint
8564 -- specified for the parent in the derived type definition. For instance:
8566 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
8567 -- type T1 is new R with null record;
8568 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
8570 -- are changed into:
8572 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
8573 -- _parent : R (D1, D2, D3);
8576 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
8577 -- _parent : T1 (X2, 88, X1);
8580 -- The discriminants actually present in R, T1 and T2 as well as their CD,
8581 -- ORC and ICH fields are:
8583 -- Discrim CD ORC ICH
8584 -- ^^^^^^^ ^^ ^^^ ^^^
8585 -- D1 in R empty itself no
8586 -- D2 in R empty itself no
8587 -- D3 in R empty itself no
8589 -- D1 in T1 D1 in R D1 in R no
8590 -- D2 in T1 D2 in R D2 in R no
8591 -- D3 in T1 D3 in R D3 in R no
8593 -- X1 in T2 D3 in T1 D3 in R no
8594 -- X2 in T2 D1 in T1 D1 in R no
8596 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
8598 -- Regardless of whether we dealing with a tagged or untagged type
8599 -- we will transform all derived type declarations of the form
8601 -- type T is new R (...) [with ...];
8603 -- subtype S is R (...);
8604 -- type T is new S [with ...];
8606 -- type BT is new R [with ...];
8607 -- subtype T is BT (...);
8609 -- That is, the base derived type is constrained only if it has no
8610 -- discriminants. The reason for doing this is that GNAT's semantic model
8611 -- assumes that a base type with discriminants is unconstrained.
8613 -- Note that, strictly speaking, the above transformation is not always
8614 -- correct. Consider for instance the following excerpt from ACVC b34011a:
8616 -- procedure B34011A is
8617 -- type REC (D : integer := 0) is record
8622 -- type T6 is new Rec;
8623 -- function F return T6;
8628 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
8631 -- The definition of Q6.U is illegal. However transforming Q6.U into
8633 -- type BaseU is new T6;
8634 -- subtype U is BaseU (Q6.F.I)
8636 -- turns U into a legal subtype, which is incorrect. To avoid this problem
8637 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
8638 -- the transformation described above.
8640 -- There is another instance where the above transformation is incorrect.
8644 -- type Base (D : Integer) is tagged null record;
8645 -- procedure P (X : Base);
8647 -- type Der is new Base (2) with null record;
8648 -- procedure P (X : Der);
8651 -- Then the above transformation turns this into
8653 -- type Der_Base is new Base with null record;
8654 -- -- procedure P (X : Base) is implicitly inherited here
8655 -- -- as procedure P (X : Der_Base).
8657 -- subtype Der is Der_Base (2);
8658 -- procedure P (X : Der);
8659 -- -- The overriding of P (X : Der_Base) is illegal since we
8660 -- -- have a parameter conformance problem.
8662 -- To get around this problem, after having semantically processed Der_Base
8663 -- and the rewritten subtype declaration for Der, we copy Der_Base field
8664 -- Discriminant_Constraint from Der so that when parameter conformance is
8665 -- checked when P is overridden, no semantic errors are flagged.
8667 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
8669 -- Regardless of whether we are dealing with a tagged or untagged type
8670 -- we will transform all derived type declarations of the form
8672 -- type R (D1, .., Dn : ...) is [tagged] record ...;
8673 -- type T is new R [with ...];
8675 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
8677 -- The reason for such transformation is that it allows us to implement a
8678 -- very clean form of component inheritance as explained below.
8680 -- Note that this transformation is not achieved by direct tree rewriting
8681 -- and manipulation, but rather by redoing the semantic actions that the
8682 -- above transformation will entail. This is done directly in routine
8683 -- Inherit_Components.
8685 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
8687 -- In both tagged and untagged derived types, regular non discriminant
8688 -- components are inherited in the derived type from the parent type. In
8689 -- the absence of discriminants component, inheritance is straightforward
8690 -- as components can simply be copied from the parent.
8692 -- If the parent has discriminants, inheriting components constrained with
8693 -- these discriminants requires caution. Consider the following example:
8695 -- type R (D1, D2 : Positive) is [tagged] record
8696 -- S : String (D1 .. D2);
8699 -- type T1 is new R [with null record];
8700 -- type T2 (X : positive) is new R (1, X) [with null record];
8702 -- As explained in 6. above, T1 is rewritten as
8703 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
8704 -- which makes the treatment for T1 and T2 identical.
8706 -- What we want when inheriting S, is that references to D1 and D2 in R are
8707 -- replaced with references to their correct constraints, i.e. D1 and D2 in
8708 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
8709 -- with either discriminant references in the derived type or expressions.
8710 -- This replacement is achieved as follows: before inheriting R's
8711 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
8712 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
8713 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
8714 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
8715 -- by String (1 .. X).
8717 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
8719 -- We explain here the rules governing private type extensions relevant to
8720 -- type derivation. These rules are explained on the following example:
8722 -- type D [(...)] is new A [(...)] with private; <-- partial view
8723 -- type D [(...)] is new P [(...)] with null record; <-- full view
8725 -- Type A is called the ancestor subtype of the private extension.
8726 -- Type P is the parent type of the full view of the private extension. It
8727 -- must be A or a type derived from A.
8729 -- The rules concerning the discriminants of private type extensions are
8732 -- o If a private extension inherits known discriminants from the ancestor
8733 -- subtype, then the full view must also inherit its discriminants from
8734 -- the ancestor subtype and the parent subtype of the full view must be
8735 -- constrained if and only if the ancestor subtype is constrained.
8737 -- o If a partial view has unknown discriminants, then the full view may
8738 -- define a definite or an indefinite subtype, with or without
8741 -- o If a partial view has neither known nor unknown discriminants, then
8742 -- the full view must define a definite subtype.
8744 -- o If the ancestor subtype of a private extension has constrained
8745 -- discriminants, then the parent subtype of the full view must impose a
8746 -- statically matching constraint on those discriminants.
8748 -- This means that only the following forms of private extensions are
8751 -- type D is new A with private; <-- partial view
8752 -- type D is new P with null record; <-- full view
8754 -- If A has no discriminants than P has no discriminants, otherwise P must
8755 -- inherit A's discriminants.
8757 -- type D is new A (...) with private; <-- partial view
8758 -- type D is new P (:::) with null record; <-- full view
8760 -- P must inherit A's discriminants and (...) and (:::) must statically
8763 -- subtype A is R (...);
8764 -- type D is new A with private; <-- partial view
8765 -- type D is new P with null record; <-- full view
8767 -- P must have inherited R's discriminants and must be derived from A or
8768 -- any of its subtypes.
8770 -- type D (..) is new A with private; <-- partial view
8771 -- type D (..) is new P [(:::)] with null record; <-- full view
8773 -- No specific constraints on P's discriminants or constraint (:::).
8774 -- Note that A can be unconstrained, but the parent subtype P must either
8775 -- be constrained or (:::) must be present.
8777 -- type D (..) is new A [(...)] with private; <-- partial view
8778 -- type D (..) is new P [(:::)] with null record; <-- full view
8780 -- P's constraints on A's discriminants must statically match those
8781 -- imposed by (...).
8783 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
8785 -- The full view of a private extension is handled exactly as described
8786 -- above. The model chose for the private view of a private extension is
8787 -- the same for what concerns discriminants (i.e. they receive the same
8788 -- treatment as in the tagged case). However, the private view of the
8789 -- private extension always inherits the components of the parent base,
8790 -- without replacing any discriminant reference. Strictly speaking this is
8791 -- incorrect. However, Gigi never uses this view to generate code so this
8792 -- is a purely semantic issue. In theory, a set of transformations similar
8793 -- to those given in 5. and 6. above could be applied to private views of
8794 -- private extensions to have the same model of component inheritance as
8795 -- for non private extensions. However, this is not done because it would
8796 -- further complicate private type processing. Semantically speaking, this
8797 -- leaves us in an uncomfortable situation. As an example consider:
8800 -- type R (D : integer) is tagged record
8801 -- S : String (1 .. D);
8803 -- procedure P (X : R);
8804 -- type T is new R (1) with private;
8806 -- type T is new R (1) with null record;
8809 -- This is transformed into:
8812 -- type R (D : integer) is tagged record
8813 -- S : String (1 .. D);
8815 -- procedure P (X : R);
8816 -- type T is new R (1) with private;
8818 -- type BaseT is new R with null record;
8819 -- subtype T is BaseT (1);
8822 -- (strictly speaking the above is incorrect Ada)
8824 -- From the semantic standpoint the private view of private extension T
8825 -- should be flagged as constrained since one can clearly have
8829 -- in a unit withing Pack. However, when deriving subprograms for the
8830 -- private view of private extension T, T must be seen as unconstrained
8831 -- since T has discriminants (this is a constraint of the current
8832 -- subprogram derivation model). Thus, when processing the private view of
8833 -- a private extension such as T, we first mark T as unconstrained, we
8834 -- process it, we perform program derivation and just before returning from
8835 -- Build_Derived_Record_Type we mark T as constrained.
8837 -- ??? Are there are other uncomfortable cases that we will have to
8840 -- 10. RECORD_TYPE_WITH_PRIVATE complications
8842 -- Types that are derived from a visible record type and have a private
8843 -- extension present other peculiarities. They behave mostly like private
8844 -- types, but if they have primitive operations defined, these will not
8845 -- have the proper signatures for further inheritance, because other
8846 -- primitive operations will use the implicit base that we define for
8847 -- private derivations below. This affect subprogram inheritance (see
8848 -- Derive_Subprograms for details). We also derive the implicit base from
8849 -- the base type of the full view, so that the implicit base is a record
8850 -- type and not another private type, This avoids infinite loops.
8852 procedure Build_Derived_Record_Type
8854 Parent_Type
: Entity_Id
;
8855 Derived_Type
: Entity_Id
;
8856 Derive_Subps
: Boolean := True)
8858 Discriminant_Specs
: constant Boolean :=
8859 Present
(Discriminant_Specifications
(N
));
8860 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
8861 Loc
: constant Source_Ptr
:= Sloc
(N
);
8862 Private_Extension
: constant Boolean :=
8863 Nkind
(N
) = N_Private_Extension_Declaration
;
8864 Assoc_List
: Elist_Id
;
8865 Constraint_Present
: Boolean;
8867 Discrim
: Entity_Id
;
8869 Inherit_Discrims
: Boolean := False;
8870 Last_Discrim
: Entity_Id
;
8871 New_Base
: Entity_Id
;
8873 New_Discrs
: Elist_Id
;
8874 New_Indic
: Node_Id
;
8875 Parent_Base
: Entity_Id
;
8876 Save_Etype
: Entity_Id
;
8877 Save_Discr_Constr
: Elist_Id
;
8878 Save_Next_Entity
: Entity_Id
;
8881 Discs
: Elist_Id
:= New_Elmt_List
;
8882 -- An empty Discs list means that there were no constraints in the
8883 -- subtype indication or that there was an error processing it.
8885 procedure Check_Generic_Ancestors
;
8886 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
8887 -- cannot be declared at a deeper level than its parent type is
8888 -- removed. The check on derivation within a generic body is also
8889 -- relaxed, but there's a restriction that a derived tagged type
8890 -- cannot be declared in a generic body if it's derived directly
8891 -- or indirectly from a formal type of that generic. This applies
8892 -- to progenitors as well.
8894 -----------------------------
8895 -- Check_Generic_Ancestors --
8896 -----------------------------
8898 procedure Check_Generic_Ancestors
is
8899 Ancestor_Type
: Entity_Id
;
8900 Intf_List
: List_Id
;
8901 Intf_Name
: Node_Id
;
8903 procedure Check_Ancestor
;
8904 -- For parent and progenitors.
8906 --------------------
8907 -- Check_Ancestor --
8908 --------------------
8910 procedure Check_Ancestor
is
8912 -- If the derived type does have a formal type as an ancestor
8913 -- then it's an error if the derived type is declared within
8914 -- the body of the generic unit that declares the formal type
8915 -- in its generic formal part. It's sufficient to check whether
8916 -- the ancestor type is declared inside the same generic body
8917 -- as the derived type (such as within a nested generic spec),
8918 -- in which case the derivation is legal. If the formal type is
8919 -- declared outside of that generic body, then it's certain
8920 -- that the derived type is declared within the generic body
8921 -- of the generic unit declaring the formal type.
8923 if Is_Generic_Type
(Ancestor_Type
)
8924 and then Enclosing_Generic_Body
(Ancestor_Type
) /=
8925 Enclosing_Generic_Body
(Derived_Type
)
8928 ("ancestor type& is formal type of enclosing"
8929 & " generic unit (RM 3.9.1 (4/2))",
8930 Indic
, Ancestor_Type
);
8935 if Nkind
(N
) = N_Private_Extension_Declaration
then
8936 Intf_List
:= Interface_List
(N
);
8938 Intf_List
:= Interface_List
(Type_Definition
(N
));
8941 if Present
(Enclosing_Generic_Body
(Derived_Type
)) then
8942 Ancestor_Type
:= Parent_Type
;
8944 while not Is_Generic_Type
(Ancestor_Type
)
8945 and then Etype
(Ancestor_Type
) /= Ancestor_Type
8947 Ancestor_Type
:= Etype
(Ancestor_Type
);
8952 if Present
(Intf_List
) then
8953 Intf_Name
:= First
(Intf_List
);
8954 while Present
(Intf_Name
) loop
8955 Ancestor_Type
:= Entity
(Intf_Name
);
8961 end Check_Generic_Ancestors
;
8963 -- Start of processing for Build_Derived_Record_Type
8966 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
8967 and then Present
(Full_View
(Parent_Type
))
8968 and then Has_Discriminants
(Parent_Type
)
8970 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
8972 Parent_Base
:= Base_Type
(Parent_Type
);
8975 -- If the parent type is declared as a subtype of another private
8976 -- type with inherited discriminants, its generated base type is
8977 -- itself a record subtype. To further inherit the constraint we
8978 -- need to use its own base to have an unconstrained type on which
8979 -- to apply the inherited constraint.
8981 if Ekind
(Parent_Base
) = E_Record_Subtype
then
8982 Parent_Base
:= Base_Type
(Parent_Base
);
8985 -- AI05-0115: if this is a derivation from a private type in some
8986 -- other scope that may lead to invisible components for the derived
8987 -- type, mark it accordingly.
8989 if Is_Private_Type
(Parent_Type
) then
8990 if Scope
(Parent_Base
) = Scope
(Derived_Type
) then
8993 elsif In_Open_Scopes
(Scope
(Parent_Base
))
8994 and then In_Private_Part
(Scope
(Parent_Base
))
8999 Set_Has_Private_Ancestor
(Derived_Type
);
9003 Set_Has_Private_Ancestor
9004 (Derived_Type
, Has_Private_Ancestor
(Parent_Type
));
9007 -- Before we start the previously documented transformations, here is
9008 -- little fix for size and alignment of tagged types. Normally when we
9009 -- derive type D from type P, we copy the size and alignment of P as the
9010 -- default for D, and in the absence of explicit representation clauses
9011 -- for D, the size and alignment are indeed the same as the parent.
9013 -- But this is wrong for tagged types, since fields may be added, and
9014 -- the default size may need to be larger, and the default alignment may
9015 -- need to be larger.
9017 -- We therefore reset the size and alignment fields in the tagged case.
9018 -- Note that the size and alignment will in any case be at least as
9019 -- large as the parent type (since the derived type has a copy of the
9020 -- parent type in the _parent field)
9022 -- The type is also marked as being tagged here, which is needed when
9023 -- processing components with a self-referential anonymous access type
9024 -- in the call to Check_Anonymous_Access_Components below. Note that
9025 -- this flag is also set later on for completeness.
9028 Set_Is_Tagged_Type
(Derived_Type
);
9029 Reinit_Size_Align
(Derived_Type
);
9032 -- STEP 0a: figure out what kind of derived type declaration we have
9034 if Private_Extension
then
9036 Mutate_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
9037 Set_Default_SSO
(Derived_Type
);
9038 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9041 Type_Def
:= Type_Definition
(N
);
9043 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
9044 -- Parent_Base can be a private type or private extension. However,
9045 -- for tagged types with an extension the newly added fields are
9046 -- visible and hence the Derived_Type is always an E_Record_Type.
9047 -- (except that the parent may have its own private fields).
9048 -- For untagged types we preserve the Ekind of the Parent_Base.
9050 if Present
(Record_Extension_Part
(Type_Def
)) then
9051 Mutate_Ekind
(Derived_Type
, E_Record_Type
);
9052 Set_Default_SSO
(Derived_Type
);
9053 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9055 -- Create internal access types for components with anonymous
9058 if Ada_Version
>= Ada_2005
then
9059 Check_Anonymous_Access_Components
9060 (N
, Derived_Type
, Derived_Type
,
9061 Component_List
(Record_Extension_Part
(Type_Def
)));
9065 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
9069 -- Indic can either be an N_Identifier if the subtype indication
9070 -- contains no constraint or an N_Subtype_Indication if the subtype
9071 -- indication has a constraint. In either case it can include an
9074 Indic
:= Subtype_Indication
(Type_Def
);
9075 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
9077 -- Check that the type has visible discriminants. The type may be
9078 -- a private type with unknown discriminants whose full view has
9079 -- discriminants which are invisible.
9081 if Constraint_Present
then
9082 if not Has_Discriminants
(Parent_Base
)
9084 (Has_Unknown_Discriminants
(Parent_Base
)
9085 and then Is_Private_Type
(Parent_Base
))
9088 ("invalid constraint: type has no discriminant",
9089 Constraint
(Indic
));
9091 Constraint_Present
:= False;
9092 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9094 elsif Is_Constrained
(Parent_Type
) then
9096 ("invalid constraint: parent type is already constrained",
9097 Constraint
(Indic
));
9099 Constraint_Present
:= False;
9100 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9104 -- STEP 0b: If needed, apply transformation given in point 5. above
9106 if not Private_Extension
9107 and then Has_Discriminants
(Parent_Type
)
9108 and then not Discriminant_Specs
9109 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
9111 -- First, we must analyze the constraint (see comment in point 5.)
9112 -- The constraint may come from the subtype indication of the full
9115 if Constraint_Present
then
9116 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9118 -- If there is no explicit constraint, there might be one that is
9119 -- inherited from a constrained parent type. In that case verify that
9120 -- it conforms to the constraint in the partial view. In perverse
9121 -- cases the parent subtypes of the partial and full view can have
9122 -- different constraints.
9124 elsif Present
(Stored_Constraint
(Parent_Type
)) then
9125 New_Discrs
:= Stored_Constraint
(Parent_Type
);
9128 New_Discrs
:= No_Elist
;
9131 if Has_Discriminants
(Derived_Type
)
9132 and then Has_Private_Declaration
(Derived_Type
)
9133 and then Present
(Discriminant_Constraint
(Derived_Type
))
9134 and then Present
(New_Discrs
)
9136 -- Verify that constraints of the full view statically match
9137 -- those given in the partial view.
9143 C1
:= First_Elmt
(New_Discrs
);
9144 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
9145 while Present
(C1
) and then Present
(C2
) loop
9146 if Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9148 (Is_OK_Static_Expression
(Node
(C1
))
9149 and then Is_OK_Static_Expression
(Node
(C2
))
9151 Expr_Value
(Node
(C1
)) = Expr_Value
(Node
(C2
)))
9156 if Constraint_Present
then
9158 ("constraint not conformant to previous declaration",
9162 ("constraint of full view is incompatible "
9163 & "with partial view", N
);
9173 -- Insert and analyze the declaration for the unconstrained base type
9175 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
9178 Make_Full_Type_Declaration
(Loc
,
9179 Defining_Identifier
=> New_Base
,
9181 Make_Derived_Type_Definition
(Loc
,
9182 Abstract_Present
=> Abstract_Present
(Type_Def
),
9183 Limited_Present
=> Limited_Present
(Type_Def
),
9184 Subtype_Indication
=>
9185 New_Occurrence_Of
(Parent_Base
, Loc
),
9186 Record_Extension_Part
=>
9187 Relocate_Node
(Record_Extension_Part
(Type_Def
)),
9188 Interface_List
=> Interface_List
(Type_Def
)));
9190 Set_Parent
(New_Decl
, Parent
(N
));
9191 Mark_Rewrite_Insertion
(New_Decl
);
9192 Insert_Before
(N
, New_Decl
);
9194 -- In the extension case, make sure ancestor is frozen appropriately
9195 -- (see also non-discriminated case below).
9197 if Present
(Record_Extension_Part
(Type_Def
))
9198 or else Is_Interface
(Parent_Base
)
9200 Freeze_Before
(New_Decl
, Parent_Type
);
9203 -- Note that this call passes False for the Derive_Subps parameter
9204 -- because subprogram derivation is deferred until after creating
9205 -- the subtype (see below).
9208 (New_Decl
, Parent_Base
, New_Base
,
9209 Is_Completion
=> False, Derive_Subps
=> False);
9211 -- ??? This needs re-examination to determine whether the
9212 -- above call can simply be replaced by a call to Analyze.
9214 Set_Analyzed
(New_Decl
);
9216 -- Insert and analyze the declaration for the constrained subtype
9218 if Constraint_Present
then
9220 Make_Subtype_Indication
(Loc
,
9221 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9222 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
9226 Constr_List
: constant List_Id
:= New_List
;
9231 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
9232 while Present
(C
) loop
9235 -- It is safe here to call New_Copy_Tree since we called
9236 -- Force_Evaluation on each constraint previously
9237 -- in Build_Discriminant_Constraints.
9239 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
9245 Make_Subtype_Indication
(Loc
,
9246 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9248 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
9253 Make_Subtype_Declaration
(Loc
,
9254 Defining_Identifier
=> Derived_Type
,
9255 Subtype_Indication
=> New_Indic
));
9259 -- Derivation of subprograms must be delayed until the full subtype
9260 -- has been established, to ensure proper overriding of subprograms
9261 -- inherited by full types. If the derivations occurred as part of
9262 -- the call to Build_Derived_Type above, then the check for type
9263 -- conformance would fail because earlier primitive subprograms
9264 -- could still refer to the full type prior the change to the new
9265 -- subtype and hence would not match the new base type created here.
9266 -- Subprograms are not derived, however, when Derive_Subps is False
9267 -- (since otherwise there could be redundant derivations).
9269 if Derive_Subps
then
9270 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9273 -- For tagged types the Discriminant_Constraint of the new base itype
9274 -- is inherited from the first subtype so that no subtype conformance
9275 -- problem arise when the first subtype overrides primitive
9276 -- operations inherited by the implicit base type.
9279 Set_Discriminant_Constraint
9280 (New_Base
, Discriminant_Constraint
(Derived_Type
));
9286 -- If we get here Derived_Type will have no discriminants or it will be
9287 -- a discriminated unconstrained base type.
9289 -- STEP 1a: perform preliminary actions/checks for derived tagged types
9293 -- The parent type is frozen for non-private extensions (RM 13.14(7))
9294 -- The declaration of a specific descendant of an interface type
9295 -- freezes the interface type (RM 13.14).
9297 if not Private_Extension
or else Is_Interface
(Parent_Base
) then
9298 Freeze_Before
(N
, Parent_Type
);
9301 if Ada_Version
>= Ada_2005
then
9302 Check_Generic_Ancestors
;
9304 elsif Type_Access_Level
(Derived_Type
) /=
9305 Type_Access_Level
(Parent_Type
)
9306 and then not Is_Generic_Type
(Derived_Type
)
9308 if Is_Controlled
(Parent_Type
) then
9310 ("controlled type must be declared at the library level",
9314 ("type extension at deeper accessibility level than parent",
9320 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
9323 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
9326 ("parent type of& must not be outside generic body"
9328 Indic
, Derived_Type
);
9334 -- Ada 2005 (AI-251)
9336 if Ada_Version
>= Ada_2005
and then Is_Tagged
then
9338 -- "The declaration of a specific descendant of an interface type
9339 -- freezes the interface type" (RM 13.14).
9344 if Is_Non_Empty_List
(Interface_List
(Type_Def
)) then
9345 Iface
:= First
(Interface_List
(Type_Def
));
9346 while Present
(Iface
) loop
9347 Freeze_Before
(N
, Etype
(Iface
));
9354 -- STEP 1b : preliminary cleanup of the full view of private types
9356 -- If the type is already marked as having discriminants, then it's the
9357 -- completion of a private type or private extension and we need to
9358 -- retain the discriminants from the partial view if the current
9359 -- declaration has Discriminant_Specifications so that we can verify
9360 -- conformance. However, we must remove any existing components that
9361 -- were inherited from the parent (and attached in Copy_And_Swap)
9362 -- because the full type inherits all appropriate components anyway, and
9363 -- we do not want the partial view's components interfering.
9365 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
9366 Discrim
:= First_Discriminant
(Derived_Type
);
9368 Last_Discrim
:= Discrim
;
9369 Next_Discriminant
(Discrim
);
9370 exit when No
(Discrim
);
9373 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
9375 -- In all other cases wipe out the list of inherited components (even
9376 -- inherited discriminants), it will be properly rebuilt here.
9379 Set_First_Entity
(Derived_Type
, Empty
);
9380 Set_Last_Entity
(Derived_Type
, Empty
);
9383 -- STEP 1c: Initialize some flags for the Derived_Type
9385 -- The following flags must be initialized here so that
9386 -- Process_Discriminants can check that discriminants of tagged types do
9387 -- not have a default initial value and that access discriminants are
9388 -- only specified for limited records. For completeness, these flags are
9389 -- also initialized along with all the other flags below.
9391 -- AI-419: Limitedness is not inherited from an interface parent, so to
9392 -- be limited in that case the type must be explicitly declared as
9393 -- limited. However, task and protected interfaces are always limited.
9395 if Limited_Present
(Type_Def
) then
9396 Set_Is_Limited_Record
(Derived_Type
);
9398 elsif Is_Limited_Record
(Parent_Type
)
9399 or else (Present
(Full_View
(Parent_Type
))
9400 and then Is_Limited_Record
(Full_View
(Parent_Type
)))
9402 if not Is_Interface
(Parent_Type
)
9403 or else Is_Concurrent_Interface
(Parent_Type
)
9405 Set_Is_Limited_Record
(Derived_Type
);
9409 -- STEP 2a: process discriminants of derived type if any
9411 Push_Scope
(Derived_Type
);
9413 if Discriminant_Specs
then
9414 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
9416 -- The following call initializes fields Has_Discriminants and
9417 -- Discriminant_Constraint, unless we are processing the completion
9418 -- of a private type declaration.
9420 Check_Or_Process_Discriminants
(N
, Derived_Type
);
9422 -- For untagged types, the constraint on the Parent_Type must be
9423 -- present and is used to rename the discriminants.
9425 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
9426 Error_Msg_N
("untagged parent must have discriminants", Indic
);
9428 elsif not Is_Tagged
and then not Constraint_Present
then
9430 ("discriminant constraint needed for derived untagged records",
9433 -- Otherwise the parent subtype must be constrained unless we have a
9434 -- private extension.
9436 elsif not Constraint_Present
9437 and then not Private_Extension
9438 and then not Is_Constrained
(Parent_Type
)
9441 ("unconstrained type not allowed in this context", Indic
);
9443 elsif Constraint_Present
then
9444 -- The following call sets the field Corresponding_Discriminant
9445 -- for the discriminants in the Derived_Type.
9447 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
9449 -- For untagged types all new discriminants must rename
9450 -- discriminants in the parent. For private extensions new
9451 -- discriminants cannot rename old ones (implied by [7.3(13)]).
9453 Discrim
:= First_Discriminant
(Derived_Type
);
9454 while Present
(Discrim
) loop
9456 and then No
(Corresponding_Discriminant
(Discrim
))
9459 ("new discriminants must constrain old ones", Discrim
);
9461 elsif Private_Extension
9462 and then Present
(Corresponding_Discriminant
(Discrim
))
9465 ("only static constraints allowed for parent"
9466 & " discriminants in the partial view", Indic
);
9470 -- If a new discriminant is used in the constraint, then its
9471 -- subtype must be statically compatible with the subtype of
9472 -- the parent discriminant (RM 3.7(15)).
9474 if Present
(Corresponding_Discriminant
(Discrim
)) then
9475 Check_Constraining_Discriminant
9476 (Discrim
, Corresponding_Discriminant
(Discrim
));
9479 Next_Discriminant
(Discrim
);
9482 -- Check whether the constraints of the full view statically
9483 -- match those imposed by the parent subtype [7.3(13)].
9485 if Present
(Stored_Constraint
(Derived_Type
)) then
9490 C1
:= First_Elmt
(Discs
);
9491 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
9492 while Present
(C1
) and then Present
(C2
) loop
9494 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9497 ("not conformant with previous declaration",
9508 -- STEP 2b: No new discriminants, inherit discriminants if any
9511 if Private_Extension
then
9512 Set_Has_Unknown_Discriminants
9514 Has_Unknown_Discriminants
(Parent_Type
)
9515 or else Unknown_Discriminants_Present
(N
));
9517 -- The partial view of the parent may have unknown discriminants,
9518 -- but if the full view has discriminants and the parent type is
9519 -- in scope they must be inherited.
9521 elsif Has_Unknown_Discriminants
(Parent_Type
)
9523 (not Has_Discriminants
(Parent_Type
)
9524 or else not In_Open_Scopes
(Scope
(Parent_Base
)))
9526 Set_Has_Unknown_Discriminants
(Derived_Type
);
9529 if not Has_Unknown_Discriminants
(Derived_Type
)
9530 and then not Has_Unknown_Discriminants
(Parent_Base
)
9531 and then Has_Discriminants
(Parent_Type
)
9533 Inherit_Discrims
:= True;
9534 Set_Has_Discriminants
9535 (Derived_Type
, True);
9536 Set_Discriminant_Constraint
9537 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
9540 -- The following test is true for private types (remember
9541 -- transformation 5. is not applied to those) and in an error
9544 if Constraint_Present
then
9545 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9548 -- For now mark a new derived type as constrained only if it has no
9549 -- discriminants. At the end of Build_Derived_Record_Type we properly
9550 -- set this flag in the case of private extensions. See comments in
9551 -- point 9. just before body of Build_Derived_Record_Type.
9555 not (Inherit_Discrims
9556 or else Has_Unknown_Discriminants
(Derived_Type
)));
9559 -- STEP 3: initialize fields of derived type
9561 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
9562 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
9564 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
9565 -- but cannot be interfaces
9567 if not Private_Extension
9568 and then Ekind
(Derived_Type
) /= E_Private_Type
9569 and then Ekind
(Derived_Type
) /= E_Limited_Private_Type
9571 if Interface_Present
(Type_Def
) then
9572 Analyze_Interface_Declaration
(Derived_Type
, Type_Def
);
9575 Set_Interfaces
(Derived_Type
, No_Elist
);
9578 -- Fields inherited from the Parent_Type
9580 Set_Has_Specified_Layout
9581 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
9582 Set_Is_Limited_Composite
9583 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
9584 Set_Is_Private_Composite
9585 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
9587 if Is_Tagged_Type
(Parent_Type
) then
9588 Set_No_Tagged_Streams_Pragma
9589 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
9592 -- Fields inherited from the Parent_Base
9594 Set_Has_Controlled_Component
9595 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
9596 Set_Has_Non_Standard_Rep
9597 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
9598 Set_Has_Primitive_Operations
9599 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
9601 -- Set fields for private derived types
9603 if Is_Private_Type
(Derived_Type
) then
9604 Set_Depends_On_Private
(Derived_Type
, True);
9605 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
9608 -- Inherit fields for non-private types. If this is the completion of a
9609 -- derivation from a private type, the parent itself is private and the
9610 -- attributes come from its full view, which must be present.
9612 if Is_Record_Type
(Derived_Type
) then
9614 Parent_Full
: Entity_Id
;
9617 if Is_Private_Type
(Parent_Base
)
9618 and then not Is_Record_Type
(Parent_Base
)
9620 Parent_Full
:= Full_View
(Parent_Base
);
9622 Parent_Full
:= Parent_Base
;
9625 Set_Component_Alignment
9626 (Derived_Type
, Component_Alignment
(Parent_Full
));
9628 (Derived_Type
, C_Pass_By_Copy
(Parent_Full
));
9629 Set_Has_Complex_Representation
9630 (Derived_Type
, Has_Complex_Representation
(Parent_Full
));
9632 -- For untagged types, inherit the layout by default to avoid
9633 -- costly changes of representation for type conversions.
9635 if not Is_Tagged
then
9636 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Full
));
9637 Set_No_Reordering
(Derived_Type
, No_Reordering
(Parent_Full
));
9642 -- When prefixed-call syntax is allowed for untagged types, initialize
9643 -- the list of primitive operations to an empty list.
9645 if Extensions_Allowed
and then not Is_Tagged
then
9646 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
9649 -- Set fields for tagged types
9652 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
9654 -- All tagged types defined in Ada.Finalization are controlled
9656 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
9657 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
9658 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
9660 Set_Is_Controlled_Active
(Derived_Type
);
9662 Set_Is_Controlled_Active
9663 (Derived_Type
, Is_Controlled_Active
(Parent_Base
));
9666 -- Minor optimization: there is no need to generate the class-wide
9667 -- entity associated with an underlying record view.
9669 if not Is_Underlying_Record_View
(Derived_Type
) then
9670 Make_Class_Wide_Type
(Derived_Type
);
9673 Set_Is_Abstract_Type
(Derived_Type
, Abstract_Present
(Type_Def
));
9675 if Has_Discriminants
(Derived_Type
)
9676 and then Constraint_Present
9678 Set_Stored_Constraint
9679 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
9682 if Ada_Version
>= Ada_2005
then
9684 Ifaces_List
: Elist_Id
;
9687 -- Checks rules 3.9.4 (13/2 and 14/2)
9689 if Comes_From_Source
(Derived_Type
)
9690 and then not Is_Private_Type
(Derived_Type
)
9691 and then Is_Interface
(Parent_Type
)
9692 and then not Is_Interface
(Derived_Type
)
9694 if Is_Task_Interface
(Parent_Type
) then
9696 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
9699 elsif Is_Protected_Interface
(Parent_Type
) then
9701 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
9706 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
9708 Check_Interfaces
(N
, Type_Def
);
9710 -- Ada 2005 (AI-251): Collect the list of progenitors that are
9711 -- not already in the parents.
9715 Ifaces_List
=> Ifaces_List
,
9716 Exclude_Parents
=> True);
9718 Set_Interfaces
(Derived_Type
, Ifaces_List
);
9720 -- If the derived type is the anonymous type created for
9721 -- a declaration whose parent has a constraint, propagate
9722 -- the interface list to the source type. This must be done
9723 -- prior to the completion of the analysis of the source type
9724 -- because the components in the extension may contain current
9725 -- instances whose legality depends on some ancestor.
9727 if Is_Itype
(Derived_Type
) then
9729 Def
: constant Node_Id
:=
9730 Associated_Node_For_Itype
(Derived_Type
);
9733 and then Nkind
(Def
) = N_Full_Type_Declaration
9736 (Defining_Identifier
(Def
), Ifaces_List
);
9741 -- A type extension is automatically Ghost when one of its
9742 -- progenitors is Ghost (SPARK RM 6.9(9)). This property is
9743 -- also inherited when the parent type is Ghost, but this is
9744 -- done in Build_Derived_Type as the mechanism also handles
9745 -- untagged derivations.
9747 if Implements_Ghost_Interface
(Derived_Type
) then
9748 Set_Is_Ghost_Entity
(Derived_Type
);
9754 -- STEP 4: Inherit components from the parent base and constrain them.
9755 -- Apply the second transformation described in point 6. above.
9757 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
9758 or else not Has_Discriminants
(Parent_Type
)
9759 or else not Is_Constrained
(Parent_Type
)
9763 Constrs
:= Discriminant_Constraint
(Parent_Type
);
9768 (N
, Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
9770 -- STEP 5a: Copy the parent record declaration for untagged types
9772 Set_Has_Implicit_Dereference
9773 (Derived_Type
, Has_Implicit_Dereference
(Parent_Type
));
9775 if not Is_Tagged
then
9777 -- Discriminant_Constraint (Derived_Type) has been properly
9778 -- constructed. Save it and temporarily set it to Empty because we
9779 -- do not want the call to New_Copy_Tree below to mess this list.
9781 if Has_Discriminants
(Derived_Type
) then
9782 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
9783 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
9785 Save_Discr_Constr
:= No_Elist
;
9788 -- Save the Etype field of Derived_Type. It is correctly set now,
9789 -- but the call to New_Copy tree may remap it to point to itself,
9790 -- which is not what we want. Ditto for the Next_Entity field.
9792 Save_Etype
:= Etype
(Derived_Type
);
9793 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
9795 -- Assoc_List maps all stored discriminants in the Parent_Base to
9796 -- stored discriminants in the Derived_Type. It is fundamental that
9797 -- no types or itypes with discriminants other than the stored
9798 -- discriminants appear in the entities declared inside
9799 -- Derived_Type, since the back end cannot deal with it.
9803 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
9804 Copy_Dimensions_Of_Components
(Derived_Type
);
9806 -- Restore the fields saved prior to the New_Copy_Tree call
9807 -- and compute the stored constraint.
9809 Set_Etype
(Derived_Type
, Save_Etype
);
9810 Link_Entities
(Derived_Type
, Save_Next_Entity
);
9812 if Has_Discriminants
(Derived_Type
) then
9813 Set_Discriminant_Constraint
9814 (Derived_Type
, Save_Discr_Constr
);
9815 Set_Stored_Constraint
9816 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
9818 Replace_Discriminants
(Derived_Type
, New_Decl
);
9821 -- Insert the new derived type declaration
9823 Rewrite
(N
, New_Decl
);
9825 -- STEP 5b: Complete the processing for record extensions in generics
9827 -- There is no completion for record extensions declared in the
9828 -- parameter part of a generic, so we need to complete processing for
9829 -- these generic record extensions here. The Record_Type_Definition call
9830 -- will change the Ekind of the components from E_Void to E_Component.
9832 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
9833 Record_Type_Definition
(Empty
, Derived_Type
);
9835 -- STEP 5c: Process the record extension for non private tagged types
9837 elsif not Private_Extension
then
9838 Expand_Record_Extension
(Derived_Type
, Type_Def
);
9840 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
9841 -- implemented interfaces if we are in expansion mode
9844 and then Has_Interfaces
(Derived_Type
)
9846 Add_Interface_Tag_Components
(N
, Derived_Type
);
9849 -- Analyze the record extension
9851 Record_Type_Definition
9852 (Record_Extension_Part
(Type_Def
), Derived_Type
);
9857 -- Nothing else to do if there is an error in the derivation.
9858 -- An unusual case: the full view may be derived from a type in an
9859 -- instance, when the partial view was used illegally as an actual
9860 -- in that instance, leading to a circular definition.
9862 if Etype
(Derived_Type
) = Any_Type
9863 or else Etype
(Parent_Type
) = Derived_Type
9868 -- Set delayed freeze and then derive subprograms, we need to do
9869 -- this in this order so that derived subprograms inherit the
9870 -- derived freeze if necessary.
9872 Set_Has_Delayed_Freeze
(Derived_Type
);
9874 if Derive_Subps
then
9875 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9878 -- If we have a private extension which defines a constrained derived
9879 -- type mark as constrained here after we have derived subprograms. See
9880 -- comment on point 9. just above the body of Build_Derived_Record_Type.
9882 if Private_Extension
and then Inherit_Discrims
then
9883 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
9884 Set_Is_Constrained
(Derived_Type
, True);
9885 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
9887 elsif Is_Constrained
(Parent_Type
) then
9889 (Derived_Type
, True);
9890 Set_Discriminant_Constraint
9891 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
9895 -- Update the class-wide type, which shares the now-completed entity
9896 -- list with its specific type. In case of underlying record views,
9897 -- we do not generate the corresponding class wide entity.
9900 and then not Is_Underlying_Record_View
(Derived_Type
)
9903 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
9905 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
9908 Check_Function_Writable_Actuals
(N
);
9909 end Build_Derived_Record_Type
;
9911 ------------------------
9912 -- Build_Derived_Type --
9913 ------------------------
9915 procedure Build_Derived_Type
9917 Parent_Type
: Entity_Id
;
9918 Derived_Type
: Entity_Id
;
9919 Is_Completion
: Boolean;
9920 Derive_Subps
: Boolean := True)
9922 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
9925 -- Set common attributes
9927 if Ekind
(Derived_Type
) in Incomplete_Or_Private_Kind
9928 and then Ekind
(Parent_Base
) in Modular_Integer_Kind | Array_Kind
9930 Reinit_Field_To_Zero
(Derived_Type
, F_Stored_Constraint
);
9933 Set_Scope
(Derived_Type
, Current_Scope
);
9934 Set_Etype
(Derived_Type
, Parent_Base
);
9935 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
9936 Propagate_Concurrent_Flags
(Derived_Type
, Parent_Base
);
9938 Set_Size_Info
(Derived_Type
, Parent_Type
);
9939 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
9941 Set_Is_Controlled_Active
9942 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
9944 Set_Disable_Controlled
(Derived_Type
, Disable_Controlled
(Parent_Type
));
9945 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged_Type
(Parent_Type
));
9946 Set_Is_Volatile
(Derived_Type
, Is_Volatile
(Parent_Type
));
9948 if Is_Tagged_Type
(Derived_Type
) then
9949 Set_No_Tagged_Streams_Pragma
9950 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
9953 -- If the parent has primitive routines and may have not-seen-yet aspect
9954 -- specifications (e.g., a Pack pragma), then set the derived type link
9955 -- in order to later diagnose "early derivation" issues. If in different
9956 -- compilation units, then "early derivation" cannot be an issue (and we
9957 -- don't like interunit references that go in the opposite direction of
9958 -- semantic dependencies).
9960 if Has_Primitive_Operations
(Parent_Type
)
9961 and then Enclosing_Comp_Unit_Node
(Parent_Type
) =
9962 Enclosing_Comp_Unit_Node
(Derived_Type
)
9964 Set_Derived_Type_Link
(Parent_Base
, Derived_Type
);
9967 -- If the parent type is a private subtype, the convention on the base
9968 -- type may be set in the private part, and not propagated to the
9969 -- subtype until later, so we obtain the convention from the base type.
9971 Set_Convention
(Derived_Type
, Convention
(Parent_Base
));
9973 if Is_Tagged_Type
(Derived_Type
)
9974 and then Present
(Class_Wide_Type
(Derived_Type
))
9976 Set_Convention
(Class_Wide_Type
(Derived_Type
),
9977 Convention
(Class_Wide_Type
(Parent_Base
)));
9980 -- Set SSO default for record or array type
9982 if (Is_Array_Type
(Derived_Type
) or else Is_Record_Type
(Derived_Type
))
9983 and then Is_Base_Type
(Derived_Type
)
9985 Set_Default_SSO
(Derived_Type
);
9988 -- A derived type inherits the Default_Initial_Condition pragma coming
9989 -- from any parent type within the derivation chain.
9991 if Has_DIC
(Parent_Type
) then
9992 Set_Has_Inherited_DIC
(Derived_Type
);
9995 -- A derived type inherits any class-wide invariants coming from a
9996 -- parent type or an interface. Note that the invariant procedure of
9997 -- the parent type should not be inherited because the derived type may
9998 -- define invariants of its own.
10000 if not Is_Interface
(Derived_Type
) then
10001 if Has_Inherited_Invariants
(Parent_Type
)
10002 or else Has_Inheritable_Invariants
(Parent_Type
)
10004 Set_Has_Inherited_Invariants
(Derived_Type
);
10006 elsif Is_Concurrent_Type
(Derived_Type
)
10007 or else Is_Tagged_Type
(Derived_Type
)
10012 Iface_Elmt
: Elmt_Id
;
10016 (T
=> Derived_Type
,
10017 Ifaces_List
=> Ifaces
,
10018 Exclude_Parents
=> True);
10020 if Present
(Ifaces
) then
10021 Iface_Elmt
:= First_Elmt
(Ifaces
);
10022 while Present
(Iface_Elmt
) loop
10023 Iface
:= Node
(Iface_Elmt
);
10025 if Has_Inheritable_Invariants
(Iface
) then
10026 Set_Has_Inherited_Invariants
(Derived_Type
);
10030 Next_Elmt
(Iface_Elmt
);
10037 -- We similarly inherit predicates. Note that for scalar derived types
10038 -- the predicate is inherited from the first subtype, and not from its
10039 -- (anonymous) base type.
10041 if Has_Predicates
(Parent_Type
)
10042 or else Has_Predicates
(First_Subtype
(Parent_Type
))
10044 Set_Has_Predicates
(Derived_Type
);
10047 -- The derived type inherits representation clauses from the parent
10048 -- type, and from any interfaces.
10050 Inherit_Rep_Item_Chain
(Derived_Type
, Parent_Type
);
10053 Iface
: Node_Id
:= First
(Abstract_Interface_List
(Derived_Type
));
10055 while Present
(Iface
) loop
10056 Inherit_Rep_Item_Chain
(Derived_Type
, Entity
(Iface
));
10061 -- If the parent type has delayed rep aspects, then mark the derived
10062 -- type as possibly inheriting a delayed rep aspect.
10064 if Has_Delayed_Rep_Aspects
(Parent_Type
) then
10065 Set_May_Inherit_Delayed_Rep_Aspects
(Derived_Type
);
10068 -- A derived type becomes Ghost when its parent type is also Ghost
10069 -- (SPARK RM 6.9(9)). Note that the Ghost-related attributes are not
10070 -- directly inherited because the Ghost policy in effect may differ.
10072 if Is_Ghost_Entity
(Parent_Type
) then
10073 Set_Is_Ghost_Entity
(Derived_Type
);
10076 -- Type dependent processing
10078 case Ekind
(Parent_Type
) is
10079 when Numeric_Kind
=>
10080 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
10083 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
10085 when Class_Wide_Kind
10089 Build_Derived_Record_Type
10090 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
10093 when Enumeration_Kind
=>
10094 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
10096 when Access_Kind
=>
10097 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
10099 when Incomplete_Or_Private_Kind
=>
10100 Build_Derived_Private_Type
10101 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
10103 -- For discriminated types, the derivation includes deriving
10104 -- primitive operations. For others it is done below.
10106 if Is_Tagged_Type
(Parent_Type
)
10107 or else Has_Discriminants
(Parent_Type
)
10108 or else (Present
(Full_View
(Parent_Type
))
10109 and then Has_Discriminants
(Full_View
(Parent_Type
)))
10114 when Concurrent_Kind
=>
10115 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
10118 raise Program_Error
;
10121 -- Nothing more to do if some error occurred
10123 if Etype
(Derived_Type
) = Any_Type
then
10127 -- If not already set, initialize the derived type's list of primitive
10128 -- operations to an empty element list.
10130 if not Present
(Direct_Primitive_Operations
(Derived_Type
)) then
10131 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
10133 -- If Etype of the derived type is the base type (as opposed to
10134 -- a parent type) and doesn't have an associated list of primitive
10135 -- operations, then set the base type's primitive list to the
10136 -- derived type's list. The lists need to be shared in common
10137 -- between the two.
10139 if Etype
(Derived_Type
) = Base_Type
(Derived_Type
)
10141 not Present
(Direct_Primitive_Operations
(Etype
(Derived_Type
)))
10143 Set_Direct_Primitive_Operations
10144 (Etype
(Derived_Type
),
10145 Direct_Primitive_Operations
(Derived_Type
));
10149 -- Set delayed freeze and then derive subprograms, we need to do this
10150 -- in this order so that derived subprograms inherit the derived freeze
10153 Set_Has_Delayed_Freeze
(Derived_Type
);
10155 if Derive_Subps
then
10156 Derive_Subprograms
(Parent_Type
, Derived_Type
);
10159 Set_Has_Primitive_Operations
10160 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
10161 end Build_Derived_Type
;
10163 -----------------------
10164 -- Build_Discriminal --
10165 -----------------------
10167 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
10168 D_Minal
: Entity_Id
;
10169 CR_Disc
: Entity_Id
;
10172 -- A discriminal has the same name as the discriminant
10174 D_Minal
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10176 Mutate_Ekind
(D_Minal
, E_In_Parameter
);
10177 Set_Mechanism
(D_Minal
, Default_Mechanism
);
10178 Set_Etype
(D_Minal
, Etype
(Discrim
));
10179 Set_Scope
(D_Minal
, Current_Scope
);
10180 Set_Parent
(D_Minal
, Parent
(Discrim
));
10182 Set_Discriminal
(Discrim
, D_Minal
);
10183 Set_Discriminal_Link
(D_Minal
, Discrim
);
10185 -- For task types, build at once the discriminants of the corresponding
10186 -- record, which are needed if discriminants are used in entry defaults
10187 -- and in family bounds.
10189 if Is_Concurrent_Type
(Current_Scope
)
10191 Is_Limited_Type
(Current_Scope
)
10193 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10195 Mutate_Ekind
(CR_Disc
, E_In_Parameter
);
10196 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
10197 Set_Etype
(CR_Disc
, Etype
(Discrim
));
10198 Set_Scope
(CR_Disc
, Current_Scope
);
10199 Set_Discriminal_Link
(CR_Disc
, Discrim
);
10200 Set_CR_Discriminant
(Discrim
, CR_Disc
);
10202 end Build_Discriminal
;
10204 ------------------------------------
10205 -- Build_Discriminant_Constraints --
10206 ------------------------------------
10208 function Build_Discriminant_Constraints
10211 Derived_Def
: Boolean := False) return Elist_Id
10213 C
: constant Node_Id
:= Constraint
(Def
);
10214 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
10216 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
10217 -- Saves the expression corresponding to a given discriminant in T
10219 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
10220 -- Return the Position number within array Discr_Expr of a discriminant
10221 -- D within the discriminant list of the discriminated type T.
10223 procedure Process_Discriminant_Expression
10226 -- If this is a discriminant constraint on a partial view, do not
10227 -- generate an overflow check on the discriminant expression. The check
10228 -- will be generated when constraining the full view. Otherwise the
10229 -- backend creates duplicate symbols for the temporaries corresponding
10230 -- to the expressions to be checked, causing spurious assembler errors.
10236 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
10240 Disc
:= First_Discriminant
(T
);
10241 for J
in Discr_Expr
'Range loop
10246 Next_Discriminant
(Disc
);
10249 -- Note: Since this function is called on discriminants that are
10250 -- known to belong to the discriminated type, falling through the
10251 -- loop with no match signals an internal compiler error.
10253 raise Program_Error
;
10256 -------------------------------------
10257 -- Process_Discriminant_Expression --
10258 -------------------------------------
10260 procedure Process_Discriminant_Expression
10264 BDT
: constant Entity_Id
:= Base_Type
(Etype
(D
));
10267 -- If this is a discriminant constraint on a partial view, do
10268 -- not generate an overflow on the discriminant expression. The
10269 -- check will be generated when constraining the full view.
10271 if Is_Private_Type
(T
)
10272 and then Present
(Full_View
(T
))
10274 Analyze_And_Resolve
(Expr
, BDT
, Suppress
=> Overflow_Check
);
10276 Analyze_And_Resolve
(Expr
, BDT
);
10278 end Process_Discriminant_Expression
;
10280 -- Declarations local to Build_Discriminant_Constraints
10284 Elist
: constant Elist_Id
:= New_Elmt_List
;
10292 Discrim_Present
: Boolean := False;
10294 -- Start of processing for Build_Discriminant_Constraints
10297 -- The following loop will process positional associations only.
10298 -- For a positional association, the (single) discriminant is
10299 -- implicitly specified by position, in textual order (RM 3.7.2).
10301 Discr
:= First_Discriminant
(T
);
10302 Constr
:= First
(Constraints
(C
));
10303 for D
in Discr_Expr
'Range loop
10304 exit when Nkind
(Constr
) = N_Discriminant_Association
;
10306 if No
(Constr
) then
10307 Error_Msg_N
("too few discriminants given in constraint", C
);
10308 return New_Elmt_List
;
10310 elsif Nkind
(Constr
) = N_Range
10311 or else (Nkind
(Constr
) = N_Attribute_Reference
10312 and then Attribute_Name
(Constr
) = Name_Range
)
10315 ("a range is not a valid discriminant constraint", Constr
);
10316 Discr_Expr
(D
) := Error
;
10318 elsif Nkind
(Constr
) = N_Subtype_Indication
then
10320 ("a subtype indication is not a valid discriminant constraint",
10322 Discr_Expr
(D
) := Error
;
10325 Process_Discriminant_Expression
(Constr
, Discr
);
10326 Discr_Expr
(D
) := Constr
;
10329 Next_Discriminant
(Discr
);
10333 if No
(Discr
) and then Present
(Constr
) then
10334 Error_Msg_N
("too many discriminants given in constraint", Constr
);
10335 return New_Elmt_List
;
10338 -- Named associations can be given in any order, but if both positional
10339 -- and named associations are used in the same discriminant constraint,
10340 -- then positional associations must occur first, at their normal
10341 -- position. Hence once a named association is used, the rest of the
10342 -- discriminant constraint must use only named associations.
10344 while Present
(Constr
) loop
10346 -- Positional association forbidden after a named association
10348 if Nkind
(Constr
) /= N_Discriminant_Association
then
10349 Error_Msg_N
("positional association follows named one", Constr
);
10350 return New_Elmt_List
;
10352 -- Otherwise it is a named association
10355 -- E records the type of the discriminants in the named
10356 -- association. All the discriminants specified in the same name
10357 -- association must have the same type.
10361 -- Search the list of discriminants in T to see if the simple name
10362 -- given in the constraint matches any of them.
10364 Id
:= First
(Selector_Names
(Constr
));
10365 while Present
(Id
) loop
10368 -- If Original_Discriminant is present, we are processing a
10369 -- generic instantiation and this is an instance node. We need
10370 -- to find the name of the corresponding discriminant in the
10371 -- actual record type T and not the name of the discriminant in
10372 -- the generic formal. Example:
10375 -- type G (D : int) is private;
10377 -- subtype W is G (D => 1);
10379 -- type Rec (X : int) is record ... end record;
10380 -- package Q is new P (G => Rec);
10382 -- At the point of the instantiation, formal type G is Rec
10383 -- and therefore when reanalyzing "subtype W is G (D => 1);"
10384 -- which really looks like "subtype W is Rec (D => 1);" at
10385 -- the point of instantiation, we want to find the discriminant
10386 -- that corresponds to D in Rec, i.e. X.
10388 if Present
(Original_Discriminant
(Id
))
10389 and then In_Instance
10391 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
10395 Discr
:= First_Discriminant
(T
);
10396 while Present
(Discr
) loop
10397 if Chars
(Discr
) = Chars
(Id
) then
10402 Next_Discriminant
(Discr
);
10406 Error_Msg_N
("& does not match any discriminant", Id
);
10407 return New_Elmt_List
;
10409 -- If the parent type is a generic formal, preserve the
10410 -- name of the discriminant for subsequent instances.
10411 -- see comment at the beginning of this if statement.
10413 elsif Is_Generic_Type
(Root_Type
(T
)) then
10414 Set_Original_Discriminant
(Id
, Discr
);
10418 Position
:= Pos_Of_Discr
(T
, Discr
);
10420 if Present
(Discr_Expr
(Position
)) then
10421 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
10424 -- Each discriminant specified in the same named association
10425 -- must be associated with a separate copy of the
10426 -- corresponding expression.
10428 if Present
(Next
(Id
)) then
10429 Expr
:= New_Copy_Tree
(Expression
(Constr
));
10430 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
10432 Expr
:= Expression
(Constr
);
10435 Discr_Expr
(Position
) := Expr
;
10436 Process_Discriminant_Expression
(Expr
, Discr
);
10439 -- A discriminant association with more than one discriminant
10440 -- name is only allowed if the named discriminants are all of
10441 -- the same type (RM 3.7.1(8)).
10444 E
:= Base_Type
(Etype
(Discr
));
10446 elsif Base_Type
(Etype
(Discr
)) /= E
then
10448 ("all discriminants in an association " &
10449 "must have the same type", Id
);
10459 -- A discriminant constraint must provide exactly one value for each
10460 -- discriminant of the type (RM 3.7.1(8)).
10462 for J
in Discr_Expr
'Range loop
10463 if No
(Discr_Expr
(J
)) then
10464 Error_Msg_N
("too few discriminants given in constraint", C
);
10465 return New_Elmt_List
;
10469 -- Determine if there are discriminant expressions in the constraint
10471 for J
in Discr_Expr
'Range loop
10472 if Denotes_Discriminant
10473 (Discr_Expr
(J
), Check_Concurrent
=> True)
10475 Discrim_Present
:= True;
10480 -- Build an element list consisting of the expressions given in the
10481 -- discriminant constraint and apply the appropriate checks. The list
10482 -- is constructed after resolving any named discriminant associations
10483 -- and therefore the expressions appear in the textual order of the
10486 Discr
:= First_Discriminant
(T
);
10487 for J
in Discr_Expr
'Range loop
10488 if Discr_Expr
(J
) /= Error
then
10489 Append_Elmt
(Discr_Expr
(J
), Elist
);
10491 -- If any of the discriminant constraints is given by a
10492 -- discriminant and we are in a derived type declaration we
10493 -- have a discriminant renaming. Establish link between new
10494 -- and old discriminant. The new discriminant has an implicit
10495 -- dereference if the old one does.
10497 if Denotes_Discriminant
(Discr_Expr
(J
)) then
10498 if Derived_Def
then
10500 New_Discr
: constant Entity_Id
:= Entity
(Discr_Expr
(J
));
10503 Set_Corresponding_Discriminant
(New_Discr
, Discr
);
10504 Set_Has_Implicit_Dereference
(New_Discr
,
10505 Has_Implicit_Dereference
(Discr
));
10509 -- Force the evaluation of non-discriminant expressions.
10510 -- If we have found a discriminant in the constraint 3.4(26)
10511 -- and 3.8(18) demand that no range checks are performed are
10512 -- after evaluation. If the constraint is for a component
10513 -- definition that has a per-object constraint, expressions are
10514 -- evaluated but not checked either. In all other cases perform
10518 if Discrim_Present
then
10521 elsif Parent_Kind
(Parent
(Def
)) = N_Component_Declaration
10522 and then Has_Per_Object_Constraint
10523 (Defining_Identifier
(Parent
(Parent
(Def
))))
10527 elsif Is_Access_Type
(Etype
(Discr
)) then
10528 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
10531 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
10534 -- If the value of the discriminant may be visible in
10535 -- another unit or child unit, create an external name
10536 -- for it. We use the name of the object or component
10537 -- that carries the discriminated subtype. The code
10538 -- below may generate external symbols for the discriminant
10539 -- expression when not strictly needed, which is harmless.
10542 and then Comes_From_Source
(Def
)
10543 and then not Is_Subprogram
(Current_Scope
)
10546 Id
: Entity_Id
:= Empty
;
10548 if Nkind
(Parent
(Def
)) = N_Object_Declaration
then
10549 Id
:= Defining_Identifier
(Parent
(Def
));
10551 elsif Nkind
(Parent
(Def
)) = N_Component_Definition
10553 Nkind
(Parent
(Parent
(Def
)))
10554 = N_Component_Declaration
10556 Id
:= Defining_Identifier
(Parent
(Parent
(Def
)));
10559 if Present
(Id
) then
10563 Discr_Number
=> J
);
10565 Force_Evaluation
(Discr_Expr
(J
));
10569 Force_Evaluation
(Discr_Expr
(J
));
10573 -- Check that the designated type of an access discriminant's
10574 -- expression is not a class-wide type unless the discriminant's
10575 -- designated type is also class-wide.
10577 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
10578 and then not Is_Class_Wide_Type
10579 (Designated_Type
(Etype
(Discr
)))
10580 and then Etype
(Discr_Expr
(J
)) /= Any_Type
10581 and then Is_Class_Wide_Type
10582 (Designated_Type
(Etype
(Discr_Expr
(J
))))
10584 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
10586 elsif Is_Access_Type
(Etype
(Discr
))
10587 and then not Is_Access_Constant
(Etype
(Discr
))
10588 and then Is_Access_Type
(Etype
(Discr_Expr
(J
)))
10589 and then Is_Access_Constant
(Etype
(Discr_Expr
(J
)))
10592 ("constraint for discriminant& must be access to variable",
10597 Next_Discriminant
(Discr
);
10601 end Build_Discriminant_Constraints
;
10603 ---------------------------------
10604 -- Build_Discriminated_Subtype --
10605 ---------------------------------
10607 procedure Build_Discriminated_Subtype
10609 Def_Id
: Entity_Id
;
10611 Related_Nod
: Node_Id
;
10612 For_Access
: Boolean := False)
10614 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
10615 Constrained
: constant Boolean :=
10617 and then not Is_Empty_Elmt_List
(Elist
)
10618 and then not Is_Class_Wide_Type
(T
))
10619 or else Is_Constrained
(T
);
10622 if Ekind
(T
) = E_Record_Type
then
10623 Mutate_Ekind
(Def_Id
, E_Record_Subtype
);
10625 -- Inherit preelaboration flag from base, for types for which it
10626 -- may have been set: records, private types, protected types.
10628 Set_Known_To_Have_Preelab_Init
10629 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10631 elsif Ekind
(T
) = E_Task_Type
then
10632 Mutate_Ekind
(Def_Id
, E_Task_Subtype
);
10634 elsif Ekind
(T
) = E_Protected_Type
then
10635 Mutate_Ekind
(Def_Id
, E_Protected_Subtype
);
10636 Set_Known_To_Have_Preelab_Init
10637 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10639 elsif Is_Private_Type
(T
) then
10640 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
10641 Set_Known_To_Have_Preelab_Init
10642 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10644 -- Private subtypes may have private dependents
10646 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
10648 elsif Is_Class_Wide_Type
(T
) then
10649 Mutate_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
10652 -- Incomplete type. Attach subtype to list of dependents, to be
10653 -- completed with full view of parent type, unless is it the
10654 -- designated subtype of a record component within an init_proc.
10655 -- This last case arises for a component of an access type whose
10656 -- designated type is incomplete (e.g. a Taft Amendment type).
10657 -- The designated subtype is within an inner scope, and needs no
10658 -- elaboration, because only the access type is needed in the
10659 -- initialization procedure.
10661 if Ekind
(T
) = E_Incomplete_Type
then
10662 Mutate_Ekind
(Def_Id
, E_Incomplete_Subtype
);
10664 Mutate_Ekind
(Def_Id
, Ekind
(T
));
10667 if For_Access
and then Within_Init_Proc
then
10670 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
10674 Set_Etype
(Def_Id
, T
);
10675 Reinit_Size_Align
(Def_Id
);
10676 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
10677 Set_Is_Constrained
(Def_Id
, Constrained
);
10679 Set_First_Entity
(Def_Id
, First_Entity
(T
));
10680 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
10681 Set_Has_Implicit_Dereference
10682 (Def_Id
, Has_Implicit_Dereference
(T
));
10683 Set_Has_Pragma_Unreferenced_Objects
10684 (Def_Id
, Has_Pragma_Unreferenced_Objects
(T
));
10686 -- If the subtype is the completion of a private declaration, there may
10687 -- have been representation clauses for the partial view, and they must
10688 -- be preserved. Build_Derived_Type chains the inherited clauses with
10689 -- the ones appearing on the extension. If this comes from a subtype
10690 -- declaration, all clauses are inherited.
10692 if No
(First_Rep_Item
(Def_Id
)) then
10693 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10696 if Is_Tagged_Type
(T
) then
10697 Set_Is_Tagged_Type
(Def_Id
);
10698 Set_No_Tagged_Streams_Pragma
(Def_Id
, No_Tagged_Streams_Pragma
(T
));
10699 Make_Class_Wide_Type
(Def_Id
);
10702 Set_Stored_Constraint
(Def_Id
, No_Elist
);
10705 Set_Discriminant_Constraint
(Def_Id
, Elist
);
10706 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
10709 if Is_Tagged_Type
(T
) then
10711 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
10712 -- concurrent record type (which has the list of primitive
10715 if Ada_Version
>= Ada_2005
10716 and then Is_Concurrent_Type
(T
)
10718 Set_Corresponding_Record_Type
(Def_Id
,
10719 Corresponding_Record_Type
(T
));
10721 Set_Direct_Primitive_Operations
(Def_Id
,
10722 Direct_Primitive_Operations
(T
));
10725 Set_Is_Abstract_Type
(Def_Id
, Is_Abstract_Type
(T
));
10728 -- Subtypes introduced by component declarations do not need to be
10729 -- marked as delayed, and do not get freeze nodes, because the semantics
10730 -- verifies that the parents of the subtypes are frozen before the
10731 -- enclosing record is frozen.
10733 if not Is_Type
(Scope
(Def_Id
)) then
10734 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
10736 if Is_Private_Type
(T
)
10737 and then Present
(Full_View
(T
))
10739 Conditional_Delay
(Def_Id
, Full_View
(T
));
10741 Conditional_Delay
(Def_Id
, T
);
10745 if Is_Record_Type
(T
) then
10746 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
10749 and then not Is_Empty_Elmt_List
(Elist
)
10750 and then not For_Access
10752 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
10754 elsif not Is_Private_Type
(T
) then
10755 Set_Cloned_Subtype
(Def_Id
, T
);
10758 end Build_Discriminated_Subtype
;
10760 ---------------------------
10761 -- Build_Itype_Reference --
10762 ---------------------------
10764 procedure Build_Itype_Reference
10768 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(Nod
));
10771 -- Itype references are only created for use by the back-end
10773 if Inside_A_Generic
then
10776 Set_Itype
(IR
, Ityp
);
10778 -- If Nod is a library unit entity, then Insert_After won't work,
10779 -- because Nod is not a member of any list. Therefore, we use
10780 -- Add_Global_Declaration in this case. This can happen if we have a
10781 -- build-in-place library function, child unit or not.
10783 if (Nkind
(Nod
) in N_Entity
and then Is_Compilation_Unit
(Nod
))
10784 or else (Nkind
(Nod
) in
10785 N_Defining_Program_Unit_Name | N_Subprogram_Declaration
10786 and then Is_Compilation_Unit
(Defining_Entity
(Nod
)))
10788 Add_Global_Declaration
(IR
);
10790 Insert_After
(Nod
, IR
);
10793 end Build_Itype_Reference
;
10795 ------------------------
10796 -- Build_Scalar_Bound --
10797 ------------------------
10799 function Build_Scalar_Bound
10802 Der_T
: Entity_Id
) return Node_Id
10804 New_Bound
: Entity_Id
;
10807 -- Note: not clear why this is needed, how can the original bound
10808 -- be unanalyzed at this point? and if it is, what business do we
10809 -- have messing around with it? and why is the base type of the
10810 -- parent type the right type for the resolution. It probably is
10811 -- not. It is OK for the new bound we are creating, but not for
10812 -- the old one??? Still if it never happens, no problem.
10814 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
10816 if Nkind
(Bound
) in N_Integer_Literal | N_Real_Literal
then
10817 New_Bound
:= New_Copy
(Bound
);
10818 Set_Etype
(New_Bound
, Der_T
);
10819 Set_Analyzed
(New_Bound
);
10821 elsif Is_Entity_Name
(Bound
) then
10822 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
10824 -- The following is almost certainly wrong. What business do we have
10825 -- relocating a node (Bound) that is presumably still attached to
10826 -- the tree elsewhere???
10829 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
10832 Set_Etype
(New_Bound
, Der_T
);
10834 end Build_Scalar_Bound
;
10836 -------------------------------
10837 -- Check_Abstract_Overriding --
10838 -------------------------------
10840 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
10841 Alias_Subp
: Entity_Id
;
10843 Op_List
: Elist_Id
;
10845 Type_Def
: Node_Id
;
10847 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
);
10848 -- Ada 2012 (AI05-0030): Subprogram Subp overrides an interface routine
10849 -- which has pragma Implemented already set. Check whether Subp's entity
10850 -- kind conforms to the implementation kind of the overridden routine.
10852 procedure Check_Pragma_Implemented
10854 Iface_Subp
: Entity_Id
);
10855 -- Ada 2012 (AI05-0030): Subprogram Subp overrides interface routine
10856 -- Iface_Subp and both entities have pragma Implemented already set on
10857 -- them. Check whether the two implementation kinds are conforming.
10859 procedure Inherit_Pragma_Implemented
10861 Iface_Subp
: Entity_Id
);
10862 -- Ada 2012 (AI05-0030): Interface primitive Subp overrides interface
10863 -- subprogram Iface_Subp which has been marked by pragma Implemented.
10864 -- Propagate the implementation kind of Iface_Subp to Subp.
10866 ------------------------------
10867 -- Check_Pragma_Implemented --
10868 ------------------------------
10870 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
) is
10871 Iface_Alias
: constant Entity_Id
:= Interface_Alias
(Subp
);
10872 Impl_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Alias
);
10873 Subp_Alias
: constant Entity_Id
:= Alias
(Subp
);
10874 Contr_Typ
: Entity_Id
;
10875 Impl_Subp
: Entity_Id
;
10878 -- Subp must have an alias since it is a hidden entity used to link
10879 -- an interface subprogram to its overriding counterpart.
10881 pragma Assert
(Present
(Subp_Alias
));
10883 -- Handle aliases to synchronized wrappers
10885 Impl_Subp
:= Subp_Alias
;
10887 if Is_Primitive_Wrapper
(Impl_Subp
) then
10888 Impl_Subp
:= Wrapped_Entity
(Impl_Subp
);
10891 -- Extract the type of the controlling formal
10893 Contr_Typ
:= Etype
(First_Formal
(Subp_Alias
));
10895 if Is_Concurrent_Record_Type
(Contr_Typ
) then
10896 Contr_Typ
:= Corresponding_Concurrent_Type
(Contr_Typ
);
10899 -- An interface subprogram whose implementation kind is By_Entry must
10900 -- be implemented by an entry.
10902 if Impl_Kind
= Name_By_Entry
10903 and then Ekind
(Impl_Subp
) /= E_Entry
10905 Error_Msg_Node_2
:= Iface_Alias
;
10907 ("type & must implement abstract subprogram & with an entry",
10908 Subp_Alias
, Contr_Typ
);
10910 elsif Impl_Kind
= Name_By_Protected_Procedure
then
10912 -- An interface subprogram whose implementation kind is By_
10913 -- Protected_Procedure cannot be implemented by a primitive
10914 -- procedure of a task type.
10916 if Ekind
(Contr_Typ
) /= E_Protected_Type
then
10917 Error_Msg_Node_2
:= Contr_Typ
;
10919 ("interface subprogram & cannot be implemented by a "
10920 & "primitive procedure of task type &",
10921 Subp_Alias
, Iface_Alias
);
10923 -- An interface subprogram whose implementation kind is By_
10924 -- Protected_Procedure must be implemented by a procedure.
10926 elsif Ekind
(Impl_Subp
) /= E_Procedure
then
10927 Error_Msg_Node_2
:= Iface_Alias
;
10929 ("type & must implement abstract subprogram & with a "
10930 & "procedure", Subp_Alias
, Contr_Typ
);
10932 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
10933 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
10935 Error_Msg_Name_1
:= Impl_Kind
;
10937 ("overriding operation& must have synchronization%",
10941 -- If primitive has Optional synchronization, overriding operation
10942 -- must match if it has an explicit synchronization.
10944 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
10945 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
10947 Error_Msg_Name_1
:= Impl_Kind
;
10949 ("overriding operation& must have synchronization%", Subp_Alias
);
10951 end Check_Pragma_Implemented
;
10953 ------------------------------
10954 -- Check_Pragma_Implemented --
10955 ------------------------------
10957 procedure Check_Pragma_Implemented
10959 Iface_Subp
: Entity_Id
)
10961 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
10962 Subp_Kind
: constant Name_Id
:= Implementation_Kind
(Subp
);
10965 -- Ada 2012 (AI05-0030): The implementation kinds of an overridden
10966 -- and overriding subprogram are different. In general this is an
10967 -- error except when the implementation kind of the overridden
10968 -- subprograms is By_Any or Optional.
10970 if Iface_Kind
/= Subp_Kind
10971 and then Iface_Kind
/= Name_By_Any
10972 and then Iface_Kind
/= Name_Optional
10974 if Iface_Kind
= Name_By_Entry
then
10976 ("incompatible implementation kind, overridden subprogram " &
10977 "is marked By_Entry", Subp
);
10980 ("incompatible implementation kind, overridden subprogram " &
10981 "is marked By_Protected_Procedure", Subp
);
10984 end Check_Pragma_Implemented
;
10986 --------------------------------
10987 -- Inherit_Pragma_Implemented --
10988 --------------------------------
10990 procedure Inherit_Pragma_Implemented
10992 Iface_Subp
: Entity_Id
)
10994 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
10995 Loc
: constant Source_Ptr
:= Sloc
(Subp
);
10996 Impl_Prag
: Node_Id
;
10999 -- Since the implementation kind is stored as a representation item
11000 -- rather than a flag, create a pragma node.
11004 Chars
=> Name_Implemented
,
11005 Pragma_Argument_Associations
=> New_List
(
11006 Make_Pragma_Argument_Association
(Loc
,
11007 Expression
=> New_Occurrence_Of
(Subp
, Loc
)),
11009 Make_Pragma_Argument_Association
(Loc
,
11010 Expression
=> Make_Identifier
(Loc
, Iface_Kind
))));
11012 -- The pragma doesn't need to be analyzed because it is internally
11013 -- built. It is safe to directly register it as a rep item since we
11014 -- are only interested in the characters of the implementation kind.
11016 Record_Rep_Item
(Subp
, Impl_Prag
);
11017 end Inherit_Pragma_Implemented
;
11019 -- Start of processing for Check_Abstract_Overriding
11022 Op_List
:= Primitive_Operations
(T
);
11024 -- Loop to check primitive operations
11026 Elmt
:= First_Elmt
(Op_List
);
11027 while Present
(Elmt
) loop
11028 Subp
:= Node
(Elmt
);
11029 Alias_Subp
:= Alias
(Subp
);
11031 -- Inherited subprograms are identified by the fact that they do not
11032 -- come from source, and the associated source location is the
11033 -- location of the first subtype of the derived type.
11035 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
11036 -- subprograms that "require overriding".
11038 -- Special exception, do not complain about failure to override the
11039 -- stream routines _Input and _Output, as well as the primitive
11040 -- operations used in dispatching selects since we always provide
11041 -- automatic overridings for these subprograms.
11043 -- The partial view of T may have been a private extension, for
11044 -- which inherited functions dispatching on result are abstract.
11045 -- If the full view is a null extension, there is no need for
11046 -- overriding in Ada 2005, but wrappers need to be built for them
11047 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
11049 if Is_Null_Extension
(T
)
11050 and then Has_Controlling_Result
(Subp
)
11051 and then Ada_Version
>= Ada_2005
11052 and then Present
(Alias_Subp
)
11053 and then not Comes_From_Source
(Subp
)
11054 and then not Is_Abstract_Subprogram
(Alias_Subp
)
11055 and then not Is_Access_Type
(Etype
(Subp
))
11059 -- Ada 2005 (AI-251): Internal entities of interfaces need no
11060 -- processing because this check is done with the aliased
11063 elsif Present
(Interface_Alias
(Subp
)) then
11066 -- AI12-0042: Test for rule in 7.3.2(6.1/4), that requires overriding
11067 -- of a visible private primitive inherited from an ancestor with
11068 -- the aspect Type_Invariant'Class, unless the inherited primitive
11071 elsif not Is_Abstract_Subprogram
(Subp
)
11072 and then not Comes_From_Source
(Subp
) -- An inherited subprogram
11073 and then Requires_Overriding
(Subp
)
11074 and then Present
(Alias_Subp
)
11075 and then Has_Invariants
(Etype
(T
))
11076 and then Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11077 and then Class_Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11078 and then Is_Private_Primitive
(Alias_Subp
)
11081 ("inherited private primitive & must be overridden", T
, Subp
);
11083 ("\because ancestor type has 'Type_'Invariant''Class " &
11084 "(RM 7.3.2(6.1))", T
);
11086 elsif (Is_Abstract_Subprogram
(Subp
)
11087 or else Requires_Overriding
(Subp
)
11089 (Has_Controlling_Result
(Subp
)
11090 and then Present
(Alias_Subp
)
11091 and then not Comes_From_Source
(Subp
)
11092 and then Sloc
(Subp
) = Sloc
(First_Subtype
(T
))))
11093 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
11094 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
11095 and then not Is_Abstract_Type
(T
)
11096 and then not Is_Predefined_Interface_Primitive
(Subp
)
11098 -- Ada 2005 (AI-251): Do not consider hidden entities associated
11099 -- with abstract interface types because the check will be done
11100 -- with the aliased entity (otherwise we generate a duplicated
11103 and then not Present
(Interface_Alias
(Subp
))
11105 if Present
(Alias_Subp
) then
11107 -- Only perform the check for a derived subprogram when the
11108 -- type has an explicit record extension. This avoids incorrect
11109 -- flagging of abstract subprograms for the case of a type
11110 -- without an extension that is derived from a formal type
11111 -- with a tagged actual (can occur within a private part).
11113 -- Ada 2005 (AI-391): In the case of an inherited function with
11114 -- a controlling result of the type, the rule does not apply if
11115 -- the type is a null extension (unless the parent function
11116 -- itself is abstract, in which case the function must still be
11117 -- be overridden). The expander will generate an overriding
11118 -- wrapper function calling the parent subprogram (see
11119 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
11121 Type_Def
:= Type_Definition
(Parent
(T
));
11123 if Nkind
(Type_Def
) = N_Derived_Type_Definition
11124 and then Present
(Record_Extension_Part
(Type_Def
))
11126 (Ada_Version
< Ada_2005
11127 or else not Is_Null_Extension
(T
)
11128 or else Ekind
(Subp
) = E_Procedure
11129 or else not Has_Controlling_Result
(Subp
)
11130 or else Is_Abstract_Subprogram
(Alias_Subp
)
11131 or else Requires_Overriding
(Subp
)
11132 or else Is_Access_Type
(Etype
(Subp
)))
11134 -- Avoid reporting error in case of abstract predefined
11135 -- primitive inherited from interface type because the
11136 -- body of internally generated predefined primitives
11137 -- of tagged types are generated later by Freeze_Type
11139 if Is_Interface
(Root_Type
(T
))
11140 and then Is_Abstract_Subprogram
(Subp
)
11141 and then Is_Predefined_Dispatching_Operation
(Subp
)
11142 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
11146 -- A null extension is not obliged to override an inherited
11147 -- procedure subject to pragma Extensions_Visible with value
11148 -- False and at least one controlling OUT parameter
11149 -- (SPARK RM 6.1.7(6)).
11151 elsif Is_Null_Extension
(T
)
11152 and then Is_EVF_Procedure
(Subp
)
11156 -- Subprogram renamings cannot be overridden
11158 elsif Comes_From_Source
(Subp
)
11159 and then Present
(Alias
(Subp
))
11163 -- Skip reporting the error on Ada 2022 only subprograms
11164 -- that require overriding if we are not in Ada 2022 mode.
11166 elsif Ada_Version
< Ada_2022
11167 and then Requires_Overriding
(Subp
)
11168 and then Is_Ada_2022_Only
(Ultimate_Alias
(Subp
))
11174 ("type must be declared abstract or & overridden",
11177 -- Traverse the whole chain of aliased subprograms to
11178 -- complete the error notification. This is especially
11179 -- useful for traceability of the chain of entities when
11180 -- the subprogram corresponds with an interface
11181 -- subprogram (which may be defined in another package).
11183 if Present
(Alias_Subp
) then
11189 while Present
(Alias
(E
)) loop
11191 -- Avoid reporting redundant errors on entities
11192 -- inherited from interfaces
11194 if Sloc
(E
) /= Sloc
(T
) then
11195 Error_Msg_Sloc
:= Sloc
(E
);
11197 ("\& has been inherited #", T
, Subp
);
11203 Error_Msg_Sloc
:= Sloc
(E
);
11205 -- AI05-0068: report if there is an overriding
11206 -- non-abstract subprogram that is invisible.
11209 and then not Is_Abstract_Subprogram
(E
)
11212 ("\& subprogram# is not visible",
11215 -- Clarify the case where a non-null extension must
11216 -- override inherited procedure subject to pragma
11217 -- Extensions_Visible with value False and at least
11218 -- one controlling OUT param.
11220 elsif Is_EVF_Procedure
(E
) then
11222 ("\& # is subject to Extensions_Visible False",
11227 ("\& has been inherited from subprogram #",
11234 -- Ada 2005 (AI-345): Protected or task type implementing
11235 -- abstract interfaces.
11237 elsif Is_Concurrent_Record_Type
(T
)
11238 and then Present
(Interfaces
(T
))
11240 -- There is no need to check here RM 9.4(11.9/3) since we
11241 -- are processing the corresponding record type and the
11242 -- mode of the overriding subprograms was verified by
11243 -- Check_Conformance when the corresponding concurrent
11244 -- type declaration was analyzed.
11247 ("interface subprogram & must be overridden", T
, Subp
);
11249 -- Examine primitive operations of synchronized type to find
11250 -- homonyms that have the wrong profile.
11256 Prim
:= First_Entity
(Corresponding_Concurrent_Type
(T
));
11257 while Present
(Prim
) loop
11258 if Chars
(Prim
) = Chars
(Subp
) then
11260 ("profile is not type conformant with prefixed "
11261 & "view profile of inherited operation&",
11265 Next_Entity
(Prim
);
11271 Error_Msg_Node_2
:= T
;
11273 ("abstract subprogram& not allowed for type&", Subp
);
11275 -- Also post unconditional warning on the type (unconditional
11276 -- so that if there are more than one of these cases, we get
11277 -- them all, and not just the first one).
11279 Error_Msg_Node_2
:= Subp
;
11280 Error_Msg_N
("nonabstract type& has abstract subprogram&!", T
);
11283 -- A subprogram subject to pragma Extensions_Visible with value
11284 -- "True" cannot override a subprogram subject to the same pragma
11285 -- with value "False" (SPARK RM 6.1.7(5)).
11287 elsif Extensions_Visible_Status
(Subp
) = Extensions_Visible_True
11288 and then Present
(Overridden_Operation
(Subp
))
11289 and then Extensions_Visible_Status
(Overridden_Operation
(Subp
)) =
11290 Extensions_Visible_False
11292 Error_Msg_Sloc
:= Sloc
(Overridden_Operation
(Subp
));
11294 ("subprogram & with Extensions_Visible True cannot override "
11295 & "subprogram # with Extensions_Visible False", Subp
);
11298 -- Ada 2012 (AI05-0030): Perform checks related to pragma Implemented
11300 -- Subp is an expander-generated procedure which maps an interface
11301 -- alias to a protected wrapper. The interface alias is flagged by
11302 -- pragma Implemented. Ensure that Subp is a procedure when the
11303 -- implementation kind is By_Protected_Procedure or an entry when
11306 if Ada_Version
>= Ada_2012
11307 and then Is_Hidden
(Subp
)
11308 and then Present
(Interface_Alias
(Subp
))
11309 and then Has_Rep_Pragma
(Interface_Alias
(Subp
), Name_Implemented
)
11311 Check_Pragma_Implemented
(Subp
);
11314 -- Subp is an interface primitive which overrides another interface
11315 -- primitive marked with pragma Implemented.
11317 if Ada_Version
>= Ada_2012
11318 and then Present
(Overridden_Operation
(Subp
))
11319 and then Has_Rep_Pragma
11320 (Overridden_Operation
(Subp
), Name_Implemented
)
11322 -- If the overriding routine is also marked by Implemented, check
11323 -- that the two implementation kinds are conforming.
11325 if Has_Rep_Pragma
(Subp
, Name_Implemented
) then
11326 Check_Pragma_Implemented
11328 Iface_Subp
=> Overridden_Operation
(Subp
));
11330 -- Otherwise the overriding routine inherits the implementation
11331 -- kind from the overridden subprogram.
11334 Inherit_Pragma_Implemented
11336 Iface_Subp
=> Overridden_Operation
(Subp
));
11340 -- Ada 2005 (AI95-0414) and Ada 2022 (AI12-0269): Diagnose failure to
11341 -- match No_Return in parent, but do it unconditionally in Ada 95 too
11342 -- for procedures, since this is our pragma.
11344 if Present
(Overridden_Operation
(Subp
))
11345 and then No_Return
(Overridden_Operation
(Subp
))
11348 -- If the subprogram is a renaming, check that the renamed
11349 -- subprogram is No_Return.
11351 if Present
(Renamed_Or_Alias
(Subp
)) then
11352 if not No_Return
(Renamed_Or_Alias
(Subp
)) then
11353 Error_Msg_NE
("subprogram & must be No_Return",
11355 Renamed_Or_Alias
(Subp
));
11356 Error_Msg_N
("\since renaming & overrides No_Return "
11357 & "subprogram (RM 6.5.1(6/2))",
11361 -- Make sure that the subprogram itself is No_Return.
11363 elsif not No_Return
(Subp
) then
11364 Error_Msg_N
("overriding subprogram & must be No_Return", Subp
);
11366 ("\since overridden subprogram is No_Return (RM 6.5.1(6/2))",
11371 -- If the operation is a wrapper for a synchronized primitive, it
11372 -- may be called indirectly through a dispatching select. We assume
11373 -- that it will be referenced elsewhere indirectly, and suppress
11374 -- warnings about an unused entity.
11376 if Is_Primitive_Wrapper
(Subp
)
11377 and then Present
(Wrapped_Entity
(Subp
))
11379 Set_Referenced
(Wrapped_Entity
(Subp
));
11384 end Check_Abstract_Overriding
;
11386 ------------------------------------------------
11387 -- Check_Access_Discriminant_Requires_Limited --
11388 ------------------------------------------------
11390 procedure Check_Access_Discriminant_Requires_Limited
11395 -- A discriminant_specification for an access discriminant shall appear
11396 -- only in the declaration for a task or protected type, or for a type
11397 -- with the reserved word 'limited' in its definition or in one of its
11398 -- ancestors (RM 3.7(10)).
11400 -- AI-0063: The proper condition is that type must be immutably limited,
11401 -- or else be a partial view.
11403 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
then
11404 if Is_Limited_View
(Current_Scope
)
11406 (Nkind
(Parent
(Current_Scope
)) = N_Private_Type_Declaration
11407 and then Limited_Present
(Parent
(Current_Scope
)))
11413 ("access discriminants allowed only for limited types", Loc
);
11416 end Check_Access_Discriminant_Requires_Limited
;
11418 -----------------------------------
11419 -- Check_Aliased_Component_Types --
11420 -----------------------------------
11422 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
11426 -- ??? Also need to check components of record extensions, but not
11427 -- components of protected types (which are always limited).
11429 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
11430 -- types to be unconstrained. This is safe because it is illegal to
11431 -- create access subtypes to such types with explicit discriminant
11434 if not Is_Limited_Type
(T
) then
11435 if Ekind
(T
) = E_Record_Type
then
11436 C
:= First_Component
(T
);
11437 while Present
(C
) loop
11439 and then Has_Discriminants
(Etype
(C
))
11440 and then not Is_Constrained
(Etype
(C
))
11441 and then not In_Instance_Body
11442 and then Ada_Version
< Ada_2005
11445 ("aliased component must be constrained (RM 3.6(11))",
11449 Next_Component
(C
);
11452 elsif Ekind
(T
) = E_Array_Type
then
11453 if Has_Aliased_Components
(T
)
11454 and then Has_Discriminants
(Component_Type
(T
))
11455 and then not Is_Constrained
(Component_Type
(T
))
11456 and then not In_Instance_Body
11457 and then Ada_Version
< Ada_2005
11460 ("aliased component type must be constrained (RM 3.6(11))",
11465 end Check_Aliased_Component_Types
;
11467 --------------------------------------
11468 -- Check_Anonymous_Access_Component --
11469 --------------------------------------
11471 procedure Check_Anonymous_Access_Component
11472 (Typ_Decl
: Node_Id
;
11475 Comp_Def
: Node_Id
;
11476 Access_Def
: Node_Id
)
11478 Loc
: constant Source_Ptr
:= Sloc
(Comp_Def
);
11479 Anon_Access
: Entity_Id
;
11482 Type_Def
: Node_Id
;
11484 procedure Build_Incomplete_Type_Declaration
;
11485 -- If the record type contains components that include an access to the
11486 -- current record, then create an incomplete type declaration for the
11487 -- record, to be used as the designated type of the anonymous access.
11488 -- This is done only once, and only if there is no previous partial
11489 -- view of the type.
11491 function Designates_T
(Subt
: Node_Id
) return Boolean;
11492 -- Check whether a node designates the enclosing record type, or 'Class
11495 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean;
11496 -- Check whether an access definition includes a reference to
11497 -- the enclosing record type. The reference can be a subtype mark
11498 -- in the access definition itself, a 'Class attribute reference, or
11499 -- recursively a reference appearing in a parameter specification
11500 -- or result definition of an access_to_subprogram definition.
11502 --------------------------------------
11503 -- Build_Incomplete_Type_Declaration --
11504 --------------------------------------
11506 procedure Build_Incomplete_Type_Declaration
is
11511 -- Is_Tagged indicates whether the type is tagged. It is tagged if
11512 -- it's "is new ... with record" or else "is tagged record ...".
11514 Typ_Def
: constant Node_Id
:=
11515 (if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
11516 then Type_Definition
(Typ_Decl
) else Empty
);
11517 Is_Tagged
: constant Boolean :=
11520 ((Nkind
(Typ_Def
) = N_Derived_Type_Definition
11522 Present
(Record_Extension_Part
(Typ_Def
)))
11524 (Nkind
(Typ_Def
) = N_Record_Definition
11525 and then Tagged_Present
(Typ_Def
)));
11528 -- If there is a previous partial view, no need to create a new one
11529 -- If the partial view, given by Prev, is incomplete, If Prev is
11530 -- a private declaration, full declaration is flagged accordingly.
11532 if Prev
/= Typ
then
11534 Make_Class_Wide_Type
(Prev
);
11535 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Prev
));
11536 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11541 elsif Has_Private_Declaration
(Typ
) then
11543 -- If we refer to T'Class inside T, and T is the completion of a
11544 -- private type, then make sure the class-wide type exists.
11547 Make_Class_Wide_Type
(Typ
);
11552 -- If there was a previous anonymous access type, the incomplete
11553 -- type declaration will have been created already.
11555 elsif Present
(Current_Entity
(Typ
))
11556 and then Ekind
(Current_Entity
(Typ
)) = E_Incomplete_Type
11557 and then Full_View
(Current_Entity
(Typ
)) = Typ
11560 and then Comes_From_Source
(Current_Entity
(Typ
))
11561 and then not Is_Tagged_Type
(Current_Entity
(Typ
))
11563 Make_Class_Wide_Type
(Typ
);
11565 ("incomplete view of tagged type should be declared tagged??",
11566 Parent
(Current_Entity
(Typ
)));
11571 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Typ
));
11572 Decl
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
11574 -- Type has already been inserted into the current scope. Remove
11575 -- it, and add incomplete declaration for type, so that subsequent
11576 -- anonymous access types can use it. The entity is unchained from
11577 -- the homonym list and from immediate visibility. After analysis,
11578 -- the entity in the incomplete declaration becomes immediately
11579 -- visible in the record declaration that follows.
11581 H
:= Current_Entity
(Typ
);
11584 Set_Name_Entity_Id
(Chars
(Typ
), Homonym
(Typ
));
11587 and then Homonym
(H
) /= Typ
11589 H
:= Homonym
(Typ
);
11592 Set_Homonym
(H
, Homonym
(Typ
));
11595 Insert_Before
(Typ_Decl
, Decl
);
11597 Set_Full_View
(Inc_T
, Typ
);
11601 -- Create a common class-wide type for both views, and set the
11602 -- Etype of the class-wide type to the full view.
11604 Make_Class_Wide_Type
(Inc_T
);
11605 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Inc_T
));
11606 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11609 end Build_Incomplete_Type_Declaration
;
11615 function Designates_T
(Subt
: Node_Id
) return Boolean is
11616 Type_Id
: constant Name_Id
:= Chars
(Typ
);
11618 function Names_T
(Nam
: Node_Id
) return Boolean;
11619 -- The record type has not been introduced in the current scope
11620 -- yet, so we must examine the name of the type itself, either
11621 -- an identifier T, or an expanded name of the form P.T, where
11622 -- P denotes the current scope.
11628 function Names_T
(Nam
: Node_Id
) return Boolean is
11630 if Nkind
(Nam
) = N_Identifier
then
11631 return Chars
(Nam
) = Type_Id
;
11633 elsif Nkind
(Nam
) = N_Selected_Component
then
11634 if Chars
(Selector_Name
(Nam
)) = Type_Id
then
11635 if Nkind
(Prefix
(Nam
)) = N_Identifier
then
11636 return Chars
(Prefix
(Nam
)) = Chars
(Current_Scope
);
11638 elsif Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
11639 return Chars
(Selector_Name
(Prefix
(Nam
))) =
11640 Chars
(Current_Scope
);
11654 -- Start of processing for Designates_T
11657 if Nkind
(Subt
) = N_Identifier
then
11658 return Chars
(Subt
) = Type_Id
;
11660 -- Reference can be through an expanded name which has not been
11661 -- analyzed yet, and which designates enclosing scopes.
11663 elsif Nkind
(Subt
) = N_Selected_Component
then
11664 if Names_T
(Subt
) then
11667 -- Otherwise it must denote an entity that is already visible.
11668 -- The access definition may name a subtype of the enclosing
11669 -- type, if there is a previous incomplete declaration for it.
11672 Find_Selected_Component
(Subt
);
11674 Is_Entity_Name
(Subt
)
11675 and then Scope
(Entity
(Subt
)) = Current_Scope
11677 (Chars
(Base_Type
(Entity
(Subt
))) = Type_Id
11679 (Is_Class_Wide_Type
(Entity
(Subt
))
11681 Chars
(Etype
(Base_Type
(Entity
(Subt
)))) =
11685 -- A reference to the current type may appear as the prefix of
11686 -- a 'Class attribute.
11688 elsif Nkind
(Subt
) = N_Attribute_Reference
11689 and then Attribute_Name
(Subt
) = Name_Class
11691 return Names_T
(Prefix
(Subt
));
11702 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean is
11703 Param_Spec
: Node_Id
;
11705 Acc_Subprg
: constant Node_Id
:=
11706 Access_To_Subprogram_Definition
(Acc_Def
);
11709 if No
(Acc_Subprg
) then
11710 return Designates_T
(Subtype_Mark
(Acc_Def
));
11713 -- Component is an access_to_subprogram: examine its formals,
11714 -- and result definition in the case of an access_to_function.
11716 Param_Spec
:= First
(Parameter_Specifications
(Acc_Subprg
));
11717 while Present
(Param_Spec
) loop
11718 if Nkind
(Parameter_Type
(Param_Spec
)) = N_Access_Definition
11719 and then Mentions_T
(Parameter_Type
(Param_Spec
))
11723 elsif Designates_T
(Parameter_Type
(Param_Spec
)) then
11730 if Nkind
(Acc_Subprg
) = N_Access_Function_Definition
then
11731 if Nkind
(Result_Definition
(Acc_Subprg
)) =
11732 N_Access_Definition
11734 return Mentions_T
(Result_Definition
(Acc_Subprg
));
11736 return Designates_T
(Result_Definition
(Acc_Subprg
));
11743 -- Start of processing for Check_Anonymous_Access_Component
11746 if Present
(Access_Def
) and then Mentions_T
(Access_Def
) then
11747 Acc_Def
:= Access_To_Subprogram_Definition
(Access_Def
);
11749 Build_Incomplete_Type_Declaration
;
11750 Anon_Access
:= Make_Temporary
(Loc
, 'S');
11752 -- Create a declaration for the anonymous access type: either
11753 -- an access_to_object or an access_to_subprogram.
11755 if Present
(Acc_Def
) then
11756 if Nkind
(Acc_Def
) = N_Access_Function_Definition
then
11758 Make_Access_Function_Definition
(Loc
,
11759 Parameter_Specifications
=>
11760 Parameter_Specifications
(Acc_Def
),
11761 Result_Definition
=> Result_Definition
(Acc_Def
));
11764 Make_Access_Procedure_Definition
(Loc
,
11765 Parameter_Specifications
=>
11766 Parameter_Specifications
(Acc_Def
));
11771 Make_Access_To_Object_Definition
(Loc
,
11772 Subtype_Indication
=>
11773 Relocate_Node
(Subtype_Mark
(Access_Def
)));
11775 Set_Constant_Present
(Type_Def
, Constant_Present
(Access_Def
));
11776 Set_All_Present
(Type_Def
, All_Present
(Access_Def
));
11779 Set_Null_Exclusion_Present
11780 (Type_Def
, Null_Exclusion_Present
(Access_Def
));
11783 Make_Full_Type_Declaration
(Loc
,
11784 Defining_Identifier
=> Anon_Access
,
11785 Type_Definition
=> Type_Def
);
11787 Insert_Before
(Typ_Decl
, Decl
);
11790 -- If an access to subprogram, create the extra formals
11792 if Present
(Acc_Def
) then
11793 Create_Extra_Formals
(Designated_Type
(Anon_Access
));
11796 if Nkind
(Comp_Def
) = N_Component_Definition
then
11798 Make_Component_Definition
(Loc
,
11799 Subtype_Indication
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
11801 pragma Assert
(Nkind
(Comp_Def
) = N_Discriminant_Specification
);
11803 Make_Discriminant_Specification
(Loc
,
11804 Defining_Identifier
=> Defining_Identifier
(Comp_Def
),
11805 Discriminant_Type
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
11808 if Ekind
(Designated_Type
(Anon_Access
)) = E_Subprogram_Type
then
11809 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Subprogram_Type
);
11811 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Type
);
11814 Set_Is_Local_Anonymous_Access
(Anon_Access
);
11816 end Check_Anonymous_Access_Component
;
11818 ---------------------------------------
11819 -- Check_Anonymous_Access_Components --
11820 ---------------------------------------
11822 procedure Check_Anonymous_Access_Components
11823 (Typ_Decl
: Node_Id
;
11826 Comp_List
: Node_Id
)
11830 if No
(Comp_List
) then
11834 Comp
:= First
(Component_Items
(Comp_List
));
11835 while Present
(Comp
) loop
11836 if Nkind
(Comp
) = N_Component_Declaration
then
11837 Check_Anonymous_Access_Component
11838 (Typ_Decl
, Typ
, Prev
,
11839 Component_Definition
(Comp
),
11840 Access_Definition
(Component_Definition
(Comp
)));
11846 if Present
(Variant_Part
(Comp_List
)) then
11850 V
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
11851 while Present
(V
) loop
11852 Check_Anonymous_Access_Components
11853 (Typ_Decl
, Typ
, Prev
, Component_List
(V
));
11854 Next_Non_Pragma
(V
);
11858 end Check_Anonymous_Access_Components
;
11860 ----------------------
11861 -- Check_Completion --
11862 ----------------------
11864 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
11867 procedure Post_Error
;
11868 -- Post error message for lack of completion for entity E
11874 procedure Post_Error
is
11875 procedure Missing_Body
;
11876 -- Output missing body message
11882 procedure Missing_Body
is
11884 -- Spec is in same unit, so we can post on spec
11886 if In_Same_Source_Unit
(Body_Id
, E
) then
11887 Error_Msg_N
("missing body for &", E
);
11889 -- Spec is in a separate unit, so we have to post on the body
11892 Error_Msg_NE
("missing body for & declared#!", Body_Id
, E
);
11896 -- Start of processing for Post_Error
11899 if not Comes_From_Source
(E
) then
11900 if Ekind
(E
) in E_Task_Type | E_Protected_Type
then
11902 -- It may be an anonymous protected type created for a
11903 -- single variable. Post error on variable, if present.
11909 Var
:= First_Entity
(Current_Scope
);
11910 while Present
(Var
) loop
11911 exit when Etype
(Var
) = E
11912 and then Comes_From_Source
(Var
);
11917 if Present
(Var
) then
11924 -- If a generated entity has no completion, then either previous
11925 -- semantic errors have disabled the expansion phase, or else we had
11926 -- missing subunits, or else we are compiling without expansion,
11927 -- or else something is very wrong.
11929 if not Comes_From_Source
(E
) then
11931 (Serious_Errors_Detected
> 0
11932 or else Configurable_Run_Time_Violations
> 0
11933 or else Subunits_Missing
11934 or else not Expander_Active
);
11937 -- Here for source entity
11940 -- Here if no body to post the error message, so we post the error
11941 -- on the declaration that has no completion. This is not really
11942 -- the right place to post it, think about this later ???
11944 if No
(Body_Id
) then
11945 if Is_Type
(E
) then
11947 ("missing full declaration for }", Parent
(E
), E
);
11949 Error_Msg_NE
("missing body for &", Parent
(E
), E
);
11952 -- Package body has no completion for a declaration that appears
11953 -- in the corresponding spec. Post error on the body, with a
11954 -- reference to the non-completed declaration.
11957 Error_Msg_Sloc
:= Sloc
(E
);
11959 if Is_Type
(E
) then
11960 Error_Msg_NE
("missing full declaration for }!", Body_Id
, E
);
11962 elsif Is_Overloadable
(E
)
11963 and then Current_Entity_In_Scope
(E
) /= E
11965 -- It may be that the completion is mistyped and appears as
11966 -- a distinct overloading of the entity.
11969 Candidate
: constant Entity_Id
:=
11970 Current_Entity_In_Scope
(E
);
11971 Decl
: constant Node_Id
:=
11972 Unit_Declaration_Node
(Candidate
);
11975 if Is_Overloadable
(Candidate
)
11976 and then Ekind
(Candidate
) = Ekind
(E
)
11977 and then Nkind
(Decl
) = N_Subprogram_Body
11978 and then Acts_As_Spec
(Decl
)
11980 Check_Type_Conformant
(Candidate
, E
);
11996 Pack_Id
: constant Entity_Id
:= Current_Scope
;
11998 -- Start of processing for Check_Completion
12001 E
:= First_Entity
(Pack_Id
);
12002 while Present
(E
) loop
12003 if Is_Intrinsic_Subprogram
(E
) then
12006 -- The following situation requires special handling: a child unit
12007 -- that appears in the context clause of the body of its parent:
12009 -- procedure Parent.Child (...);
12011 -- with Parent.Child;
12012 -- package body Parent is
12014 -- Here Parent.Child appears as a local entity, but should not be
12015 -- flagged as requiring completion, because it is a compilation
12018 -- Ignore missing completion for a subprogram that does not come from
12019 -- source (including the _Call primitive operation of RAS types,
12020 -- which has to have the flag Comes_From_Source for other purposes):
12021 -- we assume that the expander will provide the missing completion.
12022 -- In case of previous errors, other expansion actions that provide
12023 -- bodies for null procedures with not be invoked, so inhibit message
12026 -- Note that E_Operator is not in the list that follows, because
12027 -- this kind is reserved for predefined operators, that are
12028 -- intrinsic and do not need completion.
12030 elsif Ekind
(E
) in E_Function
12032 | E_Generic_Function
12033 | E_Generic_Procedure
12035 if Has_Completion
(E
) then
12038 elsif Is_Subprogram
(E
) and then Is_Abstract_Subprogram
(E
) then
12041 elsif Is_Subprogram
(E
)
12042 and then (not Comes_From_Source
(E
)
12043 or else Chars
(E
) = Name_uCall
)
12048 Nkind
(Parent
(Unit_Declaration_Node
(E
))) = N_Compilation_Unit
12052 elsif Nkind
(Parent
(E
)) = N_Procedure_Specification
12053 and then Null_Present
(Parent
(E
))
12054 and then Serious_Errors_Detected
> 0
12062 elsif Is_Entry
(E
) then
12063 if not Has_Completion
(E
)
12064 and then Ekind
(Scope
(E
)) = E_Protected_Type
12069 elsif Is_Package_Or_Generic_Package
(E
) then
12070 if Unit_Requires_Body
(E
) then
12071 if not Has_Completion
(E
)
12072 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
12078 elsif not Is_Child_Unit
(E
) then
12079 May_Need_Implicit_Body
(E
);
12082 -- A formal incomplete type (Ada 2012) does not require a completion;
12083 -- other incomplete type declarations do.
12085 elsif Ekind
(E
) = E_Incomplete_Type
then
12086 if No
(Underlying_Type
(E
))
12087 and then not Is_Generic_Type
(E
)
12092 elsif Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12093 if not Has_Completion
(E
) then
12097 -- A single task declared in the current scope is a constant, verify
12098 -- that the body of its anonymous type is in the same scope. If the
12099 -- task is defined elsewhere, this may be a renaming declaration for
12100 -- which no completion is needed.
12102 elsif Ekind
(E
) = E_Constant
then
12103 if Ekind
(Etype
(E
)) = E_Task_Type
12104 and then not Has_Completion
(Etype
(E
))
12105 and then Scope
(Etype
(E
)) = Current_Scope
12110 elsif Ekind
(E
) = E_Record_Type
then
12111 if Is_Tagged_Type
(E
) then
12112 Check_Abstract_Overriding
(E
);
12113 Check_Conventions
(E
);
12116 Check_Aliased_Component_Types
(E
);
12118 elsif Ekind
(E
) = E_Array_Type
then
12119 Check_Aliased_Component_Types
(E
);
12125 end Check_Completion
;
12127 -------------------------------------
12128 -- Check_Constraining_Discriminant --
12129 -------------------------------------
12131 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
)
12133 New_Type
: constant Entity_Id
:= Etype
(New_Disc
);
12134 Old_Type
: Entity_Id
;
12137 -- If the record type contains an array constrained by the discriminant
12138 -- but with some different bound, the compiler tries to create a smaller
12139 -- range for the discriminant type (see exp_ch3.Adjust_Discriminants).
12140 -- In this case, where the discriminant type is a scalar type, the check
12141 -- must use the original discriminant type in the parent declaration.
12143 if Is_Scalar_Type
(New_Type
) then
12144 Old_Type
:= Entity
(Discriminant_Type
(Parent
(Old_Disc
)));
12146 Old_Type
:= Etype
(Old_Disc
);
12149 if not Subtypes_Statically_Compatible
(New_Type
, Old_Type
) then
12151 ("subtype must be statically compatible with parent discriminant",
12154 if not Predicates_Compatible
(New_Type
, Old_Type
) then
12156 ("\subtype predicate is not compatible with parent discriminant",
12160 end Check_Constraining_Discriminant
;
12162 ------------------------------------
12163 -- Check_CPP_Type_Has_No_Defaults --
12164 ------------------------------------
12166 procedure Check_CPP_Type_Has_No_Defaults
(T
: Entity_Id
) is
12167 Tdef
: constant Node_Id
:= Type_Definition
(Declaration_Node
(T
));
12172 -- Obtain the component list
12174 if Nkind
(Tdef
) = N_Record_Definition
then
12175 Clist
:= Component_List
(Tdef
);
12176 else pragma Assert
(Nkind
(Tdef
) = N_Derived_Type_Definition
);
12177 Clist
:= Component_List
(Record_Extension_Part
(Tdef
));
12180 -- Check all components to ensure no default expressions
12182 if Present
(Clist
) then
12183 Comp
:= First
(Component_Items
(Clist
));
12184 while Present
(Comp
) loop
12185 if Present
(Expression
(Comp
)) then
12187 ("component of imported 'C'P'P type cannot have "
12188 & "default expression", Expression
(Comp
));
12194 end Check_CPP_Type_Has_No_Defaults
;
12196 ----------------------------
12197 -- Check_Delta_Expression --
12198 ----------------------------
12200 procedure Check_Delta_Expression
(E
: Node_Id
) is
12202 if not (Is_Real_Type
(Etype
(E
))) then
12203 Wrong_Type
(E
, Any_Real
);
12205 elsif not Is_OK_Static_Expression
(E
) then
12206 Flag_Non_Static_Expr
12207 ("non-static expression used for delta value!", E
);
12209 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
12210 Error_Msg_N
("delta expression must be positive", E
);
12216 -- If any of above errors occurred, then replace the incorrect
12217 -- expression by the real 0.1, which should prevent further errors.
12220 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
12221 Analyze_And_Resolve
(E
, Standard_Float
);
12222 end Check_Delta_Expression
;
12224 -----------------------------
12225 -- Check_Digits_Expression --
12226 -----------------------------
12228 procedure Check_Digits_Expression
(E
: Node_Id
) is
12230 if not (Is_Integer_Type
(Etype
(E
))) then
12231 Wrong_Type
(E
, Any_Integer
);
12233 elsif not Is_OK_Static_Expression
(E
) then
12234 Flag_Non_Static_Expr
12235 ("non-static expression used for digits value!", E
);
12237 elsif Expr_Value
(E
) <= 0 then
12238 Error_Msg_N
("digits value must be greater than zero", E
);
12244 -- If any of above errors occurred, then replace the incorrect
12245 -- expression by the integer 1, which should prevent further errors.
12247 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
12248 Analyze_And_Resolve
(E
, Standard_Integer
);
12250 end Check_Digits_Expression
;
12252 --------------------------
12253 -- Check_Initialization --
12254 --------------------------
12256 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
12258 -- Special processing for limited types
12260 if Is_Limited_Type
(T
)
12261 and then not In_Instance
12262 and then not In_Inlined_Body
12264 if not OK_For_Limited_Init
(T
, Exp
) then
12266 -- In GNAT mode, this is just a warning, to allow it to be evilly
12267 -- turned off. Otherwise it is a real error.
12271 ("??cannot initialize entities of limited type!", Exp
);
12273 elsif Ada_Version
< Ada_2005
then
12275 -- The side effect removal machinery may generate illegal Ada
12276 -- code to avoid the usage of access types and 'reference in
12277 -- SPARK mode. Since this is legal code with respect to theorem
12278 -- proving, do not emit the error.
12281 and then Nkind
(Exp
) = N_Function_Call
12282 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
12283 and then not Comes_From_Source
12284 (Defining_Identifier
(Parent
(Exp
)))
12290 ("cannot initialize entities of limited type", Exp
);
12291 Explain_Limited_Type
(T
, Exp
);
12295 -- Specialize error message according to kind of illegal
12296 -- initial expression. We check the Original_Node to cover
12297 -- cases where the initialization expression of an object
12298 -- declaration generated by the compiler has been rewritten
12299 -- (such as for dispatching calls).
12301 if Nkind
(Original_Node
(Exp
)) = N_Type_Conversion
12303 Nkind
(Expression
(Original_Node
(Exp
))) = N_Function_Call
12305 -- No error for internally-generated object declarations,
12306 -- which can come from build-in-place assignment statements.
12308 if Nkind
(Parent
(Exp
)) = N_Object_Declaration
12309 and then not Comes_From_Source
12310 (Defining_Identifier
(Parent
(Exp
)))
12316 ("illegal context for call to function with limited "
12322 ("initialization of limited object requires aggregate or "
12323 & "function call", Exp
);
12329 -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag gets
12330 -- set unless we can be sure that no range check is required.
12332 if not Expander_Active
12333 and then Is_Scalar_Type
(T
)
12334 and then not Is_In_Range
(Exp
, T
, Assume_Valid
=> True)
12336 Set_Do_Range_Check
(Exp
);
12338 end Check_Initialization
;
12340 ----------------------
12341 -- Check_Interfaces --
12342 ----------------------
12344 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
) is
12345 Parent_Type
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
12348 Iface_Def
: Node_Id
;
12349 Iface_Typ
: Entity_Id
;
12350 Parent_Node
: Node_Id
;
12352 Is_Task
: Boolean := False;
12353 -- Set True if parent type or any progenitor is a task interface
12355 Is_Protected
: Boolean := False;
12356 -- Set True if parent type or any progenitor is a protected interface
12358 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
);
12359 -- Check that a progenitor is compatible with declaration. If an error
12360 -- message is output, it is posted on Error_Node.
12366 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
) is
12367 Iface_Id
: constant Entity_Id
:=
12368 Defining_Identifier
(Parent
(Iface_Def
));
12369 Type_Def
: Node_Id
;
12372 if Nkind
(N
) = N_Private_Extension_Declaration
then
12375 Type_Def
:= Type_Definition
(N
);
12378 if Is_Task_Interface
(Iface_Id
) then
12381 elsif Is_Protected_Interface
(Iface_Id
) then
12382 Is_Protected
:= True;
12385 if Is_Synchronized_Interface
(Iface_Id
) then
12387 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
12388 -- extension derived from a synchronized interface must explicitly
12389 -- be declared synchronized, because the full view will be a
12390 -- synchronized type.
12392 if Nkind
(N
) = N_Private_Extension_Declaration
then
12393 if not Synchronized_Present
(N
) then
12395 ("private extension of& must be explicitly synchronized",
12399 -- However, by 3.9.4(16/2), a full type that is a record extension
12400 -- is never allowed to derive from a synchronized interface (note
12401 -- that interfaces must be excluded from this check, because those
12402 -- are represented by derived type definitions in some cases).
12404 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12405 and then not Interface_Present
(Type_Definition
(N
))
12407 Error_Msg_N
("record extension cannot derive from synchronized "
12408 & "interface", Error_Node
);
12412 -- Check that the characteristics of the progenitor are compatible
12413 -- with the explicit qualifier in the declaration.
12414 -- The check only applies to qualifiers that come from source.
12415 -- Limited_Present also appears in the declaration of corresponding
12416 -- records, and the check does not apply to them.
12418 if Limited_Present
(Type_Def
)
12420 Is_Concurrent_Record_Type
(Defining_Identifier
(N
))
12422 if Is_Limited_Interface
(Parent_Type
)
12423 and then not Is_Limited_Interface
(Iface_Id
)
12426 ("progenitor & must be limited interface",
12427 Error_Node
, Iface_Id
);
12430 (Task_Present
(Iface_Def
)
12431 or else Protected_Present
(Iface_Def
)
12432 or else Synchronized_Present
(Iface_Def
))
12433 and then Nkind
(N
) /= N_Private_Extension_Declaration
12434 and then not Error_Posted
(N
)
12437 ("progenitor & must be limited interface",
12438 Error_Node
, Iface_Id
);
12441 -- Protected interfaces can only inherit from limited, synchronized
12442 -- or protected interfaces.
12444 elsif Nkind
(N
) = N_Full_Type_Declaration
12445 and then Protected_Present
(Type_Def
)
12447 if Limited_Present
(Iface_Def
)
12448 or else Synchronized_Present
(Iface_Def
)
12449 or else Protected_Present
(Iface_Def
)
12453 elsif Task_Present
(Iface_Def
) then
12454 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12455 & "from task interface", Error_Node
);
12458 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12459 & "from non-limited interface", Error_Node
);
12462 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
12463 -- limited and synchronized.
12465 elsif Synchronized_Present
(Type_Def
) then
12466 if Limited_Present
(Iface_Def
)
12467 or else Synchronized_Present
(Iface_Def
)
12471 elsif Protected_Present
(Iface_Def
)
12472 and then Nkind
(N
) /= N_Private_Extension_Declaration
12474 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12475 & "from protected interface", Error_Node
);
12477 elsif Task_Present
(Iface_Def
)
12478 and then Nkind
(N
) /= N_Private_Extension_Declaration
12480 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12481 & "from task interface", Error_Node
);
12483 elsif not Is_Limited_Interface
(Iface_Id
) then
12484 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12485 & "from non-limited interface", Error_Node
);
12488 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
12489 -- synchronized or task interfaces.
12491 elsif Nkind
(N
) = N_Full_Type_Declaration
12492 and then Task_Present
(Type_Def
)
12494 if Limited_Present
(Iface_Def
)
12495 or else Synchronized_Present
(Iface_Def
)
12496 or else Task_Present
(Iface_Def
)
12500 elsif Protected_Present
(Iface_Def
) then
12501 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12502 & "protected interface", Error_Node
);
12505 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12506 & "non-limited interface", Error_Node
);
12511 -- Start of processing for Check_Interfaces
12514 if Is_Interface
(Parent_Type
) then
12515 if Is_Task_Interface
(Parent_Type
) then
12518 elsif Is_Protected_Interface
(Parent_Type
) then
12519 Is_Protected
:= True;
12523 if Nkind
(N
) = N_Private_Extension_Declaration
then
12525 -- Check that progenitors are compatible with declaration
12527 Iface
:= First
(Interface_List
(Def
));
12528 while Present
(Iface
) loop
12529 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12531 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12532 Iface_Def
:= Type_Definition
(Parent_Node
);
12534 if not Is_Interface
(Iface_Typ
) then
12535 Diagnose_Interface
(Iface
, Iface_Typ
);
12537 Check_Ifaces
(Iface_Def
, Iface
);
12543 if Is_Task
and Is_Protected
then
12545 ("type cannot derive from task and protected interface", N
);
12551 -- Full type declaration of derived type.
12552 -- Check compatibility with parent if it is interface type
12554 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12555 and then Is_Interface
(Parent_Type
)
12557 Parent_Node
:= Parent
(Parent_Type
);
12559 -- More detailed checks for interface varieties
12562 (Iface_Def
=> Type_Definition
(Parent_Node
),
12563 Error_Node
=> Subtype_Indication
(Type_Definition
(N
)));
12566 Iface
:= First
(Interface_List
(Def
));
12567 while Present
(Iface
) loop
12568 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12570 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12571 Iface_Def
:= Type_Definition
(Parent_Node
);
12573 if not Is_Interface
(Iface_Typ
) then
12574 Diagnose_Interface
(Iface
, Iface_Typ
);
12577 -- "The declaration of a specific descendant of an interface
12578 -- type freezes the interface type" RM 13.14
12580 Freeze_Before
(N
, Iface_Typ
);
12581 Check_Ifaces
(Iface_Def
, Error_Node
=> Iface
);
12587 if Is_Task
and Is_Protected
then
12589 ("type cannot derive from task and protected interface", N
);
12591 end Check_Interfaces
;
12593 ------------------------------------
12594 -- Check_Or_Process_Discriminants --
12595 ------------------------------------
12597 -- If an incomplete or private type declaration was already given for the
12598 -- type, the discriminants may have already been processed if they were
12599 -- present on the incomplete declaration. In this case a full conformance
12600 -- check has been performed in Find_Type_Name, and we then recheck here
12601 -- some properties that can't be checked on the partial view alone.
12602 -- Otherwise we call Process_Discriminants.
12604 procedure Check_Or_Process_Discriminants
12607 Prev
: Entity_Id
:= Empty
)
12610 if Has_Discriminants
(T
) then
12612 -- Discriminants are already set on T if they were already present
12613 -- on the partial view. Make them visible to component declarations.
12617 -- Discriminant on T (full view) referencing expr on partial view
12619 Prev_D
: Entity_Id
;
12620 -- Entity of corresponding discriminant on partial view
12623 -- Discriminant specification for full view, expression is
12624 -- the syntactic copy on full view (which has been checked for
12625 -- conformance with partial view), only used here to post error
12629 D
:= First_Discriminant
(T
);
12630 New_D
:= First
(Discriminant_Specifications
(N
));
12631 while Present
(D
) loop
12632 Prev_D
:= Current_Entity
(D
);
12633 Set_Current_Entity
(D
);
12634 Set_Is_Immediately_Visible
(D
);
12635 Set_Homonym
(D
, Prev_D
);
12637 -- Handle the case where there is an untagged partial view and
12638 -- the full view is tagged: must disallow discriminants with
12639 -- defaults, unless compiling for Ada 2012, which allows a
12640 -- limited tagged type to have defaulted discriminants (see
12641 -- AI05-0214). However, suppress error here if it was already
12642 -- reported on the default expression of the partial view.
12644 if Is_Tagged_Type
(T
)
12645 and then Present
(Expression
(Parent
(D
)))
12646 and then (not Is_Limited_Type
(Current_Scope
)
12647 or else Ada_Version
< Ada_2012
)
12648 and then not Error_Posted
(Expression
(Parent
(D
)))
12650 if Ada_Version
>= Ada_2012
then
12652 ("discriminants of nonlimited tagged type cannot have "
12654 Expression
(New_D
));
12657 ("discriminants of tagged type cannot have defaults",
12658 Expression
(New_D
));
12662 -- Ada 2005 (AI-230): Access discriminant allowed in
12663 -- non-limited record types.
12665 if Ada_Version
< Ada_2005
then
12667 -- This restriction gets applied to the full type here. It
12668 -- has already been applied earlier to the partial view.
12670 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
12673 Next_Discriminant
(D
);
12678 elsif Present
(Discriminant_Specifications
(N
)) then
12679 Process_Discriminants
(N
, Prev
);
12681 end Check_Or_Process_Discriminants
;
12683 ----------------------
12684 -- Check_Real_Bound --
12685 ----------------------
12687 procedure Check_Real_Bound
(Bound
: Node_Id
) is
12689 if not Is_Real_Type
(Etype
(Bound
)) then
12691 ("bound in real type definition must be of real type", Bound
);
12693 elsif not Is_OK_Static_Expression
(Bound
) then
12694 Flag_Non_Static_Expr
12695 ("non-static expression used for real type bound!", Bound
);
12702 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
12704 Resolve
(Bound
, Standard_Float
);
12705 end Check_Real_Bound
;
12707 ------------------------------
12708 -- Complete_Private_Subtype --
12709 ------------------------------
12711 procedure Complete_Private_Subtype
12714 Full_Base
: Entity_Id
;
12715 Related_Nod
: Node_Id
)
12717 Save_Next_Entity
: Entity_Id
;
12718 Save_Homonym
: Entity_Id
;
12721 -- Set semantic attributes for (implicit) private subtype completion.
12722 -- If the full type has no discriminants, then it is a copy of the
12723 -- full view of the base. Otherwise, it is a subtype of the base with
12724 -- a possible discriminant constraint. Save and restore the original
12725 -- Next_Entity field of full to ensure that the calls to Copy_Node do
12726 -- not corrupt the entity chain.
12728 Save_Next_Entity
:= Next_Entity
(Full
);
12729 Save_Homonym
:= Homonym
(Priv
);
12731 if Is_Private_Type
(Full_Base
)
12732 or else Is_Record_Type
(Full_Base
)
12733 or else Is_Concurrent_Type
(Full_Base
)
12735 Copy_Node
(Priv
, Full
);
12737 -- Note that the Etype of the full view is the same as the Etype of
12738 -- the partial view. In this fashion, the subtype has access to the
12739 -- correct view of the parent.
12741 Set_Has_Discriminants
(Full
, Has_Discriminants
(Full_Base
));
12742 Set_Has_Unknown_Discriminants
12743 (Full
, Has_Unknown_Discriminants
(Full_Base
));
12744 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
12745 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
12747 -- If the underlying base type is constrained, we know that the
12748 -- full view of the subtype is constrained as well (the converse
12749 -- is not necessarily true).
12751 if Is_Constrained
(Full_Base
) then
12752 Set_Is_Constrained
(Full
);
12756 Copy_Node
(Full_Base
, Full
);
12758 -- The following subtlety with the Etype of the full view needs to be
12759 -- taken into account here. One could think that it must naturally be
12760 -- set to the base type of the full base:
12762 -- Set_Etype (Full, Base_Type (Full_Base));
12764 -- so that the full view becomes a subtype of the full base when the
12765 -- latter is a base type, which must for example happen when the full
12766 -- base is declared as derived type. That's also correct if the full
12767 -- base is declared as an array type, or a floating-point type, or a
12768 -- fixed-point type, or a signed integer type, as these declarations
12769 -- create an implicit base type and a first subtype so the Etype of
12770 -- the full views must be the implicit base type. But that's wrong
12771 -- if the full base is declared as an access type, or an enumeration
12772 -- type, or a modular integer type, as these declarations directly
12773 -- create a base type, i.e. with Etype pointing to itself. Moreover
12774 -- the full base being declared in the private part, i.e. when the
12775 -- views are swapped, the end result is that the Etype of the full
12776 -- base is set to its private view in this case and that we need to
12777 -- propagate this setting to the full view in order for the subtype
12778 -- to be compatible with the base type.
12780 if Is_Base_Type
(Full_Base
)
12781 and then (Is_Derived_Type
(Full_Base
)
12782 or else Ekind
(Full_Base
) in Array_Kind
12783 or else Ekind
(Full_Base
) in Fixed_Point_Kind
12784 or else Ekind
(Full_Base
) in Float_Kind
12785 or else Ekind
(Full_Base
) in Signed_Integer_Kind
)
12787 Set_Etype
(Full
, Full_Base
);
12790 Set_Chars
(Full
, Chars
(Priv
));
12791 Set_Sloc
(Full
, Sloc
(Priv
));
12792 Conditional_Delay
(Full
, Priv
);
12795 Link_Entities
(Full
, Save_Next_Entity
);
12796 Set_Homonym
(Full
, Save_Homonym
);
12797 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
12799 if Ekind
(Full
) in Incomplete_Or_Private_Kind
then
12800 Reinit_Field_To_Zero
(Full
, F_Private_Dependents
);
12803 -- Set common attributes for all subtypes: kind, convention, etc.
12805 Mutate_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
12806 Set_Convention
(Full
, Convention
(Full_Base
));
12807 Set_Is_First_Subtype
(Full
, False);
12808 Set_Scope
(Full
, Scope
(Priv
));
12809 Set_Size_Info
(Full
, Full_Base
);
12810 Copy_RM_Size
(To
=> Full
, From
=> Full_Base
);
12811 Set_Is_Itype
(Full
);
12813 -- A subtype of a private-type-without-discriminants, whose full-view
12814 -- has discriminants with default expressions, is not constrained.
12816 if not Has_Discriminants
(Priv
) then
12817 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
12819 if Has_Discriminants
(Full_Base
) then
12820 Set_Discriminant_Constraint
12821 (Full
, Discriminant_Constraint
(Full_Base
));
12823 -- The partial view may have been indefinite, the full view
12826 Set_Has_Unknown_Discriminants
12827 (Full
, Has_Unknown_Discriminants
(Full_Base
));
12831 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
12832 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
12834 -- Freeze the private subtype entity if its parent is delayed, and not
12835 -- already frozen. We skip this processing if the type is an anonymous
12836 -- subtype of a record component, or is the corresponding record of a
12837 -- protected type, since these are processed when the enclosing type
12838 -- is frozen. If the parent type is declared in a nested package then
12839 -- the freezing of the private and full views also happens later.
12841 if not Is_Type
(Scope
(Full
)) then
12843 and then In_Same_Source_Unit
(Full
, Full_Base
)
12844 and then Scope
(Full_Base
) /= Scope
(Full
)
12846 Set_Has_Delayed_Freeze
(Full
);
12847 Set_Has_Delayed_Freeze
(Priv
);
12850 Set_Has_Delayed_Freeze
(Full
,
12851 Has_Delayed_Freeze
(Full_Base
)
12852 and then not Is_Frozen
(Full_Base
));
12856 Set_Freeze_Node
(Full
, Empty
);
12857 Set_Is_Frozen
(Full
, False);
12859 if Has_Discriminants
(Full
) then
12860 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
12861 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
12863 if Has_Unknown_Discriminants
(Full
) then
12864 Set_Discriminant_Constraint
(Full
, No_Elist
);
12868 if Ekind
(Full_Base
) = E_Record_Type
12869 and then Has_Discriminants
(Full_Base
)
12870 and then Has_Discriminants
(Priv
) -- might not, if errors
12871 and then not Has_Unknown_Discriminants
(Priv
)
12872 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
12874 Create_Constrained_Components
12875 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
12877 -- If the full base is itself derived from private, build a congruent
12878 -- subtype of its underlying full view, for use by the back end.
12880 elsif Is_Private_Type
(Full_Base
)
12881 and then Present
(Underlying_Full_View
(Full_Base
))
12884 Underlying_Full_Base
: constant Entity_Id
12885 := Underlying_Full_View
(Full_Base
);
12886 Underlying_Full
: constant Entity_Id
12887 := Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
12889 Set_Is_Itype
(Underlying_Full
);
12890 Set_Associated_Node_For_Itype
(Underlying_Full
, Related_Nod
);
12891 Complete_Private_Subtype
12892 (Priv
, Underlying_Full
, Underlying_Full_Base
, Related_Nod
);
12893 Set_Underlying_Full_View
(Full
, Underlying_Full
);
12894 Set_Is_Underlying_Full_View
(Underlying_Full
);
12897 elsif Is_Record_Type
(Full_Base
) then
12899 -- Show Full is simply a renaming of Full_Base
12901 Set_Cloned_Subtype
(Full
, Full_Base
);
12902 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
12904 -- Propagate predicates
12906 Propagate_Predicate_Attributes
(Full
, Full_Base
);
12909 -- It is unsafe to share the bounds of a scalar type, because the Itype
12910 -- is elaborated on demand, and if a bound is nonstatic, then different
12911 -- orders of elaboration in different units will lead to different
12912 -- external symbols.
12914 if Is_Scalar_Type
(Full_Base
) then
12915 Set_Scalar_Range
(Full
,
12916 Make_Range
(Sloc
(Related_Nod
),
12918 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
12920 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
12922 -- This completion inherits the bounds of the full parent, but if
12923 -- the parent is an unconstrained floating point type, so is the
12926 if Is_Floating_Point_Type
(Full_Base
) then
12927 Set_Includes_Infinities
12928 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
12932 -- ??? It seems that a lot of fields are missing that should be copied
12933 -- from Full_Base to Full. Here are some that are introduced in a
12934 -- non-disruptive way but a cleanup is necessary.
12936 if Is_Tagged_Type
(Full_Base
) then
12937 Set_Is_Tagged_Type
(Full
);
12938 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
12940 Set_Direct_Primitive_Operations
12941 (Full
, Direct_Primitive_Operations
(Full_Base
));
12942 Set_No_Tagged_Streams_Pragma
12943 (Full
, No_Tagged_Streams_Pragma
(Full_Base
));
12945 if Is_Interface
(Full_Base
) then
12946 Set_Is_Interface
(Full
);
12947 Set_Is_Limited_Interface
(Full
, Is_Limited_Interface
(Full_Base
));
12950 -- Inherit class_wide type of full_base in case the partial view was
12951 -- not tagged. Otherwise it has already been created when the private
12952 -- subtype was analyzed.
12954 if No
(Class_Wide_Type
(Full
)) then
12955 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
12958 -- If this is a subtype of a protected or task type, constrain its
12959 -- corresponding record, unless this is a subtype without constraints,
12960 -- i.e. a simple renaming as with an actual subtype in an instance.
12962 elsif Is_Concurrent_Type
(Full_Base
) then
12963 if Has_Discriminants
(Full
)
12964 and then Present
(Corresponding_Record_Type
(Full_Base
))
12966 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
12968 Set_Corresponding_Record_Type
(Full
,
12969 Constrain_Corresponding_Record
12970 (Full
, Corresponding_Record_Type
(Full_Base
), Related_Nod
));
12973 Set_Corresponding_Record_Type
(Full
,
12974 Corresponding_Record_Type
(Full_Base
));
12978 -- Link rep item chain, and also setting of Has_Predicates from private
12979 -- subtype to full subtype, since we will need these on the full subtype
12980 -- to create the predicate function. Note that the full subtype may
12981 -- already have rep items, inherited from the full view of the base
12982 -- type, so we must be sure not to overwrite these entries.
12987 Next_Item
: Node_Id
;
12988 Priv_Item
: Node_Id
;
12991 Item
:= First_Rep_Item
(Full
);
12992 Priv_Item
:= First_Rep_Item
(Priv
);
12994 -- If no existing rep items on full type, we can just link directly
12995 -- to the list of items on the private type, if any exist.. Same if
12996 -- the rep items are only those inherited from the base
12999 or else Nkind
(Item
) /= N_Aspect_Specification
13000 or else Entity
(Item
) = Full_Base
)
13001 and then Present
(First_Rep_Item
(Priv
))
13003 Set_First_Rep_Item
(Full
, Priv_Item
);
13005 -- Otherwise, search to the end of items currently linked to the full
13006 -- subtype and append the private items to the end. However, if Priv
13007 -- and Full already have the same list of rep items, then the append
13008 -- is not done, as that would create a circularity.
13010 -- The partial view may have a predicate and the rep item lists of
13011 -- both views agree when inherited from the same ancestor. In that
13012 -- case, simply propagate the list from one view to the other.
13013 -- A more complex analysis needed here ???
13015 elsif Present
(Priv_Item
)
13016 and then Item
= Next_Rep_Item
(Priv_Item
)
13018 Set_First_Rep_Item
(Full
, Priv_Item
);
13020 elsif Item
/= Priv_Item
then
13023 Next_Item
:= Next_Rep_Item
(Item
);
13024 exit when No
(Next_Item
);
13027 -- If the private view has aspect specifications, the full view
13028 -- inherits them. Since these aspects may already have been
13029 -- attached to the full view during derivation, do not append
13030 -- them if already present.
13032 if Item
= First_Rep_Item
(Priv
) then
13038 -- And link the private type items at the end of the chain
13041 Set_Next_Rep_Item
(Item
, First_Rep_Item
(Priv
));
13046 -- Make sure Has_Predicates is set on full type if it is set on the
13047 -- private type. Note that it may already be set on the full type and
13048 -- if so, we don't want to unset it. Similarly, propagate information
13049 -- about delayed aspects, because the corresponding pragmas must be
13050 -- analyzed when one of the views is frozen. This last step is needed
13051 -- in particular when the full type is a scalar type for which an
13052 -- anonymous base type is constructed.
13054 -- The predicate functions are generated either at the freeze point
13055 -- of the type or at the end of the visible part, and we must avoid
13056 -- generating them twice.
13058 Propagate_Predicate_Attributes
(Full
, Priv
);
13060 if Has_Delayed_Aspects
(Priv
) then
13061 Set_Has_Delayed_Aspects
(Full
);
13063 end Complete_Private_Subtype
;
13065 ----------------------------
13066 -- Constant_Redeclaration --
13067 ----------------------------
13069 procedure Constant_Redeclaration
13074 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
13075 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
13078 procedure Check_Possible_Deferred_Completion
13079 (Prev_Id
: Entity_Id
;
13080 Prev_Obj_Def
: Node_Id
;
13081 Curr_Obj_Def
: Node_Id
);
13082 -- Determine whether the two object definitions describe the partial
13083 -- and the full view of a constrained deferred constant. Generate
13084 -- a subtype for the full view and verify that it statically matches
13085 -- the subtype of the partial view.
13087 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
13088 -- If deferred constant is an access type initialized with an allocator,
13089 -- check whether there is an illegal recursion in the definition,
13090 -- through a default value of some record subcomponent. This is normally
13091 -- detected when generating init procs, but requires this additional
13092 -- mechanism when expansion is disabled.
13094 ----------------------------------------
13095 -- Check_Possible_Deferred_Completion --
13096 ----------------------------------------
13098 procedure Check_Possible_Deferred_Completion
13099 (Prev_Id
: Entity_Id
;
13100 Prev_Obj_Def
: Node_Id
;
13101 Curr_Obj_Def
: Node_Id
)
13104 if Nkind
(Prev_Obj_Def
) = N_Subtype_Indication
13105 and then Present
(Constraint
(Prev_Obj_Def
))
13106 and then Nkind
(Curr_Obj_Def
) = N_Subtype_Indication
13107 and then Present
(Constraint
(Curr_Obj_Def
))
13110 Loc
: constant Source_Ptr
:= Sloc
(N
);
13111 Def_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
13112 Decl
: constant Node_Id
:=
13113 Make_Subtype_Declaration
(Loc
,
13114 Defining_Identifier
=> Def_Id
,
13115 Subtype_Indication
=>
13116 Relocate_Node
(Curr_Obj_Def
));
13119 Insert_Before_And_Analyze
(N
, Decl
);
13120 Set_Etype
(Id
, Def_Id
);
13122 if not Subtypes_Statically_Match
(Etype
(Prev_Id
), Def_Id
) then
13123 Error_Msg_Sloc
:= Sloc
(Prev_Id
);
13124 Error_Msg_N
("subtype does not statically match deferred "
13125 & "declaration #", N
);
13129 end Check_Possible_Deferred_Completion
;
13131 ---------------------------------
13132 -- Check_Recursive_Declaration --
13133 ---------------------------------
13135 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
13139 if Is_Record_Type
(Typ
) then
13140 Comp
:= First_Component
(Typ
);
13141 while Present
(Comp
) loop
13142 if Comes_From_Source
(Comp
) then
13143 if Present
(Expression
(Parent
(Comp
)))
13144 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
13145 and then Entity
(Expression
(Parent
(Comp
))) = Prev
13147 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
13149 ("illegal circularity with declaration for & #",
13153 elsif Is_Record_Type
(Etype
(Comp
)) then
13154 Check_Recursive_Declaration
(Etype
(Comp
));
13158 Next_Component
(Comp
);
13161 end Check_Recursive_Declaration
;
13163 -- Start of processing for Constant_Redeclaration
13166 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
13167 if Nkind
(Object_Definition
13168 (Parent
(Prev
))) = N_Subtype_Indication
13170 -- Find type of new declaration. The constraints of the two
13171 -- views must match statically, but there is no point in
13172 -- creating an itype for the full view.
13174 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
13175 Find_Type
(Subtype_Mark
(Obj_Def
));
13176 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
13179 Find_Type
(Obj_Def
);
13180 New_T
:= Entity
(Obj_Def
);
13186 -- The full view may impose a constraint, even if the partial
13187 -- view does not, so construct the subtype.
13189 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
13194 -- Current declaration is illegal, diagnosed below in Enter_Name
13200 -- If previous full declaration or a renaming declaration exists, or if
13201 -- a homograph is present, let Enter_Name handle it, either with an
13202 -- error or with the removal of an overridden implicit subprogram.
13203 -- The previous one is a full declaration if it has an expression
13204 -- (which in the case of an aggregate is indicated by the Init flag).
13206 if Ekind
(Prev
) /= E_Constant
13207 or else Nkind
(Parent
(Prev
)) = N_Object_Renaming_Declaration
13208 or else Present
(Expression
(Parent
(Prev
)))
13209 or else Has_Init_Expression
(Parent
(Prev
))
13210 or else Present
(Full_View
(Prev
))
13214 -- Verify that types of both declarations match, or else that both types
13215 -- are anonymous access types whose designated subtypes statically match
13216 -- (as allowed in Ada 2005 by AI-385).
13218 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
)
13220 (Ekind
(Etype
(Prev
)) /= E_Anonymous_Access_Type
13221 or else Ekind
(Etype
(New_T
)) /= E_Anonymous_Access_Type
13222 or else Is_Access_Constant
(Etype
(New_T
)) /=
13223 Is_Access_Constant
(Etype
(Prev
))
13224 or else Can_Never_Be_Null
(Etype
(New_T
)) /=
13225 Can_Never_Be_Null
(Etype
(Prev
))
13226 or else Null_Exclusion_Present
(Parent
(Prev
)) /=
13227 Null_Exclusion_Present
(Parent
(Id
))
13228 or else not Subtypes_Statically_Match
13229 (Designated_Type
(Etype
(Prev
)),
13230 Designated_Type
(Etype
(New_T
))))
13232 Error_Msg_Sloc
:= Sloc
(Prev
);
13233 Error_Msg_N
("type does not match declaration#", N
);
13234 Set_Full_View
(Prev
, Id
);
13235 Set_Etype
(Id
, Any_Type
);
13237 -- A deferred constant whose type is an anonymous array is always
13238 -- illegal (unless imported). A detailed error message might be
13239 -- helpful for Ada beginners.
13241 if Nkind
(Object_Definition
(Parent
(Prev
)))
13242 = N_Constrained_Array_Definition
13243 and then Nkind
(Object_Definition
(N
))
13244 = N_Constrained_Array_Definition
13246 Error_Msg_N
("\each anonymous array is a distinct type", N
);
13247 Error_Msg_N
("a deferred constant must have a named type",
13248 Object_Definition
(Parent
(Prev
)));
13252 Null_Exclusion_Present
(Parent
(Prev
))
13253 and then not Null_Exclusion_Present
(N
)
13255 Error_Msg_Sloc
:= Sloc
(Prev
);
13256 Error_Msg_N
("null-exclusion does not match declaration#", N
);
13257 Set_Full_View
(Prev
, Id
);
13258 Set_Etype
(Id
, Any_Type
);
13260 -- If so, process the full constant declaration
13263 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
13264 -- the deferred declaration is constrained, then the subtype defined
13265 -- by the subtype_indication in the full declaration shall match it
13268 Check_Possible_Deferred_Completion
13270 Prev_Obj_Def
=> Object_Definition
(Parent
(Prev
)),
13271 Curr_Obj_Def
=> Obj_Def
);
13273 Set_Full_View
(Prev
, Id
);
13274 Set_Is_Public
(Id
, Is_Public
(Prev
));
13275 Set_Is_Internal
(Id
);
13276 Append_Entity
(Id
, Current_Scope
);
13278 -- Check ALIASED present if present before (RM 7.4(7))
13280 if Is_Aliased
(Prev
)
13281 and then not Aliased_Present
(N
)
13283 Error_Msg_Sloc
:= Sloc
(Prev
);
13284 Error_Msg_N
("ALIASED required (see declaration #)", N
);
13287 -- Check that placement is in private part and that the incomplete
13288 -- declaration appeared in the visible part.
13290 if Ekind
(Current_Scope
) = E_Package
13291 and then not In_Private_Part
(Current_Scope
)
13293 Error_Msg_Sloc
:= Sloc
(Prev
);
13295 ("full constant for declaration # must be in private part", N
);
13297 elsif Ekind
(Current_Scope
) = E_Package
13299 List_Containing
(Parent
(Prev
)) /=
13300 Visible_Declarations
(Package_Specification
(Current_Scope
))
13303 ("deferred constant must be declared in visible part",
13307 if Is_Access_Type
(T
)
13308 and then Nkind
(Expression
(N
)) = N_Allocator
13310 Check_Recursive_Declaration
(Designated_Type
(T
));
13313 -- A deferred constant is a visible entity. If type has invariants,
13314 -- verify that the initial value satisfies them. This is not done in
13315 -- GNATprove mode, as GNATprove handles invariant checks itself.
13317 if Has_Invariants
(T
)
13318 and then Present
(Invariant_Procedure
(T
))
13319 and then not GNATprove_Mode
13322 Make_Invariant_Call
(New_Occurrence_Of
(Prev
, Sloc
(N
))));
13325 end Constant_Redeclaration
;
13327 ----------------------
13328 -- Constrain_Access --
13329 ----------------------
13331 procedure Constrain_Access
13332 (Def_Id
: in out Entity_Id
;
13334 Related_Nod
: Node_Id
)
13336 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13337 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
13338 Desig_Subtype
: Entity_Id
:= Create_Itype
(E_Void
, Related_Nod
);
13339 Constraint_OK
: Boolean := True;
13342 if Is_Array_Type
(Desig_Type
) then
13343 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
13345 elsif (Is_Record_Type
(Desig_Type
)
13346 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
13347 and then not Is_Constrained
(Desig_Type
)
13349 -- If this is a constrained access definition for a record
13350 -- component, we leave the type as an unconstrained access,
13351 -- and mark the component so that its actual type is built
13352 -- at a point of use (e.g., an assignment statement). This
13353 -- is handled in Sem_Util.Build_Actual_Subtype_Of_Component.
13355 if Desig_Type
= Current_Scope
13356 and then No
(Def_Id
)
13360 (E_Void
, Related_Nod
, Scope_Id
=> Scope
(Desig_Type
));
13361 Mutate_Ekind
(Desig_Subtype
, E_Record_Subtype
);
13362 Def_Id
:= Entity
(Subtype_Mark
(S
));
13364 -- We indicate that the component has a per-object constraint
13365 -- for treatment at a point of use, even though the constraint
13366 -- may be independent of discriminants of the enclosing type.
13368 if Nkind
(Related_Nod
) = N_Component_Declaration
then
13369 Set_Has_Per_Object_Constraint
13370 (Defining_Identifier
(Related_Nod
));
13373 -- This call added to ensure that the constraint is analyzed
13374 -- (needed for a B test). Note that we still return early from
13375 -- this procedure to avoid recursive processing.
13377 Constrain_Discriminated_Type
13378 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
13382 -- Enforce rule that the constraint is illegal if there is an
13383 -- unconstrained view of the designated type. This means that the
13384 -- partial view (either a private type declaration or a derivation
13385 -- from a private type) has no discriminants. (Defect Report
13386 -- 8652/0008, Technical Corrigendum 1, checked by ACATS B371001).
13388 -- Rule updated for Ada 2005: The private type is said to have
13389 -- a constrained partial view, given that objects of the type
13390 -- can be declared. Furthermore, the rule applies to all access
13391 -- types, unlike the rule concerning default discriminants (see
13394 if (Ekind
(T
) = E_General_Access_Type
or else Ada_Version
>= Ada_2005
)
13395 and then Has_Private_Declaration
(Desig_Type
)
13396 and then In_Open_Scopes
(Scope
(Desig_Type
))
13397 and then Has_Discriminants
(Desig_Type
)
13400 Pack
: constant Node_Id
:=
13401 Unit_Declaration_Node
(Scope
(Desig_Type
));
13406 if Nkind
(Pack
) = N_Package_Declaration
then
13407 Decls
:= Visible_Declarations
(Specification
(Pack
));
13408 Decl
:= First
(Decls
);
13409 while Present
(Decl
) loop
13410 if (Nkind
(Decl
) = N_Private_Type_Declaration
13411 and then Chars
(Defining_Identifier
(Decl
)) =
13412 Chars
(Desig_Type
))
13415 (Nkind
(Decl
) = N_Full_Type_Declaration
13417 Chars
(Defining_Identifier
(Decl
)) =
13419 and then Is_Derived_Type
(Desig_Type
)
13421 Has_Private_Declaration
(Etype
(Desig_Type
)))
13423 if No
(Discriminant_Specifications
(Decl
)) then
13425 ("cannot constrain access type if designated "
13426 & "type has constrained partial view", S
);
13438 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
13439 For_Access
=> True);
13441 elsif Is_Concurrent_Type
(Desig_Type
)
13442 and then not Is_Constrained
(Desig_Type
)
13444 Constrain_Concurrent
(Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
13447 Error_Msg_N
("invalid constraint on access type", S
);
13449 -- We simply ignore an invalid constraint
13451 Desig_Subtype
:= Desig_Type
;
13452 Constraint_OK
:= False;
13455 if No
(Def_Id
) then
13456 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
13458 Mutate_Ekind
(Def_Id
, E_Access_Subtype
);
13461 if Constraint_OK
then
13462 Set_Etype
(Def_Id
, Base_Type
(T
));
13464 if Is_Private_Type
(Desig_Type
) then
13465 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
13468 Set_Etype
(Def_Id
, Any_Type
);
13471 Set_Size_Info
(Def_Id
, T
);
13472 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
13473 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
13474 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13475 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
13477 Conditional_Delay
(Def_Id
, T
);
13479 -- AI-363 : Subtypes of general access types whose designated types have
13480 -- default discriminants are disallowed. In instances, the rule has to
13481 -- be checked against the actual, of which T is the subtype. In a
13482 -- generic body, the rule is checked assuming that the actual type has
13483 -- defaulted discriminants.
13485 if Ada_Version
>= Ada_2005
or else Warn_On_Ada_2005_Compatibility
then
13486 if Ekind
(Base_Type
(T
)) = E_General_Access_Type
13487 and then Has_Defaulted_Discriminants
(Desig_Type
)
13489 if Ada_Version
< Ada_2005
then
13491 ("access subtype of general access type would not " &
13492 "be allowed in Ada 2005?y?", S
);
13495 ("access subtype of general access type not allowed", S
);
13498 Error_Msg_N
("\discriminants have defaults", S
);
13500 elsif Is_Access_Type
(T
)
13501 and then Is_Generic_Type
(Desig_Type
)
13502 and then Has_Discriminants
(Desig_Type
)
13503 and then In_Package_Body
(Current_Scope
)
13505 if Ada_Version
< Ada_2005
then
13507 ("access subtype would not be allowed in generic body "
13508 & "in Ada 2005?y?", S
);
13511 ("access subtype not allowed in generic body", S
);
13515 ("\designated type is a discriminated formal", S
);
13518 end Constrain_Access
;
13520 ---------------------
13521 -- Constrain_Array --
13522 ---------------------
13524 procedure Constrain_Array
13525 (Def_Id
: in out Entity_Id
;
13527 Related_Nod
: Node_Id
;
13528 Related_Id
: Entity_Id
;
13529 Suffix
: Character)
13531 C
: constant Node_Id
:= Constraint
(SI
);
13532 Number_Of_Constraints
: Nat
:= 0;
13535 Constraint_OK
: Boolean := True;
13536 Is_FLB_Array_Subtype
: Boolean := False;
13539 T
:= Entity
(Subtype_Mark
(SI
));
13541 if Is_Access_Type
(T
) then
13542 T
:= Designated_Type
(T
);
13545 -- If an index constraint follows a subtype mark in a subtype indication
13546 -- then the type or subtype denoted by the subtype mark must not already
13547 -- impose an index constraint. The subtype mark must denote either an
13548 -- unconstrained array type or an access type whose designated type
13549 -- is such an array type... (RM 3.6.1)
13551 if Is_Constrained
(T
) then
13552 Error_Msg_N
("array type is already constrained", Subtype_Mark
(SI
));
13553 Constraint_OK
:= False;
13556 S
:= First
(Constraints
(C
));
13557 while Present
(S
) loop
13558 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
13562 -- In either case, the index constraint must provide a discrete
13563 -- range for each index of the array type and the type of each
13564 -- discrete range must be the same as that of the corresponding
13565 -- index. (RM 3.6.1)
13567 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
13568 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
13569 Constraint_OK
:= False;
13572 S
:= First
(Constraints
(C
));
13573 Index
:= First_Index
(T
);
13576 -- Apply constraints to each index type
13578 for J
in 1 .. Number_Of_Constraints
loop
13579 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
13581 -- If the subtype of the index has been set to indicate that
13582 -- it has a fixed lower bound, then record that the subtype's
13583 -- entity will need to be marked as being a fixed-lower-bound
13586 if S
= First
(Constraints
(C
)) then
13587 Is_FLB_Array_Subtype
:=
13588 Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
));
13590 -- If the parent subtype (or should this be Etype of that?)
13591 -- is an FLB array subtype, we flag an error, because we
13592 -- don't currently allow subtypes of such subtypes to
13593 -- specify a fixed lower bound for any of their indexes,
13594 -- even if the index of the parent subtype is a "range <>"
13597 if Is_FLB_Array_Subtype
13598 and then Is_Fixed_Lower_Bound_Array_Subtype
(T
)
13601 ("index with fixed lower bound not allowed for subtype "
13602 & "of fixed-lower-bound }", S
, T
);
13604 Is_FLB_Array_Subtype
:= False;
13607 elsif Is_FLB_Array_Subtype
13608 and then not Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13611 ("constrained index not allowed for fixed-lower-bound "
13612 & "subtype of}", S
, T
);
13614 elsif not Is_FLB_Array_Subtype
13615 and then Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13618 ("index with fixed lower bound not allowed for "
13619 & "constrained subtype of}", S
, T
);
13629 if No
(Def_Id
) then
13631 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
13632 Set_Parent
(Def_Id
, Related_Nod
);
13635 Mutate_Ekind
(Def_Id
, E_Array_Subtype
);
13638 Set_Size_Info
(Def_Id
, (T
));
13639 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13640 Set_Etype
(Def_Id
, Base_Type
(T
));
13642 if Constraint_OK
then
13643 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
13645 Set_First_Index
(Def_Id
, First_Index
(T
));
13648 Set_Is_Constrained
(Def_Id
, not Is_FLB_Array_Subtype
);
13649 Set_Is_Fixed_Lower_Bound_Array_Subtype
13650 (Def_Id
, Is_FLB_Array_Subtype
);
13651 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
13652 Set_Is_Independent
(Def_Id
, Is_Independent
(T
));
13653 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13655 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
13656 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
13658 -- A subtype does not inherit the Packed_Array_Impl_Type of is parent.
13659 -- We need to initialize the attribute because if Def_Id is previously
13660 -- analyzed through a limited_with clause, it will have the attributes
13661 -- of an incomplete type, one of which is an Elist that overlaps the
13662 -- Packed_Array_Impl_Type field.
13664 Set_Packed_Array_Impl_Type
(Def_Id
, Empty
);
13666 -- Build a freeze node if parent still needs one. Also make sure that
13667 -- the Depends_On_Private status is set because the subtype will need
13668 -- reprocessing at the time the base type does, and also we must set a
13669 -- conditional delay.
13671 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
13672 Conditional_Delay
(Def_Id
, T
);
13673 end Constrain_Array
;
13675 ------------------------------
13676 -- Constrain_Component_Type --
13677 ------------------------------
13679 function Constrain_Component_Type
13681 Constrained_Typ
: Entity_Id
;
13682 Related_Node
: Node_Id
;
13684 Constraints
: Elist_Id
) return Entity_Id
13686 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
13687 Compon_Type
: constant Entity_Id
:= Etype
(Comp
);
13689 function Build_Constrained_Array_Type
13690 (Old_Type
: Entity_Id
) return Entity_Id
;
13691 -- If Old_Type is an array type, one of whose indexes is constrained
13692 -- by a discriminant, build an Itype whose constraint replaces the
13693 -- discriminant with its value in the constraint.
13695 function Build_Constrained_Discriminated_Type
13696 (Old_Type
: Entity_Id
) return Entity_Id
;
13697 -- Ditto for record components. Handle the case where the constraint
13698 -- is a conversion of the discriminant value, introduced during
13701 function Build_Constrained_Access_Type
13702 (Old_Type
: Entity_Id
) return Entity_Id
;
13703 -- Ditto for access types. Makes use of previous two functions, to
13704 -- constrain designated type.
13706 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
13707 -- Returns True if Expr is a discriminant
13709 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
;
13710 -- Find the value of a discriminant named by Discr_Expr in Constraints
13712 -----------------------------------
13713 -- Build_Constrained_Access_Type --
13714 -----------------------------------
13716 function Build_Constrained_Access_Type
13717 (Old_Type
: Entity_Id
) return Entity_Id
13719 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
13721 Desig_Subtype
: Entity_Id
;
13725 -- If the original access type was not embedded in the enclosing
13726 -- type definition, there is no need to produce a new access
13727 -- subtype. In fact every access type with an explicit constraint
13728 -- generates an itype whose scope is the enclosing record.
13730 if not Is_Type
(Scope
(Old_Type
)) then
13733 elsif Is_Array_Type
(Desig_Type
) then
13734 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
13736 elsif Has_Discriminants
(Desig_Type
) then
13738 -- This may be an access type to an enclosing record type for
13739 -- which we are constructing the constrained components. Return
13740 -- the enclosing record subtype. This is not always correct,
13741 -- but avoids infinite recursion. ???
13743 Desig_Subtype
:= Any_Type
;
13745 for J
in reverse 0 .. Scope_Stack
.Last
loop
13746 Scop
:= Scope_Stack
.Table
(J
).Entity
;
13749 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
13751 Desig_Subtype
:= Scop
;
13754 exit when not Is_Type
(Scop
);
13757 if Desig_Subtype
= Any_Type
then
13759 Build_Constrained_Discriminated_Type
(Desig_Type
);
13766 if Desig_Subtype
/= Desig_Type
then
13768 -- The Related_Node better be here or else we won't be able
13769 -- to attach new itypes to a node in the tree.
13771 pragma Assert
(Present
(Related_Node
));
13773 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
13775 Set_Etype
(Itype
, Base_Type
(Old_Type
));
13776 Set_Size_Info
(Itype
, (Old_Type
));
13777 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
13778 Set_Depends_On_Private
(Itype
, Has_Private_Component
13780 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
13783 -- The new itype needs freezing when it depends on a not frozen
13784 -- type and the enclosing subtype needs freezing.
13786 if Has_Delayed_Freeze
(Constrained_Typ
)
13787 and then not Is_Frozen
(Constrained_Typ
)
13789 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
13797 end Build_Constrained_Access_Type
;
13799 ----------------------------------
13800 -- Build_Constrained_Array_Type --
13801 ----------------------------------
13803 function Build_Constrained_Array_Type
13804 (Old_Type
: Entity_Id
) return Entity_Id
13808 Old_Index
: Node_Id
;
13809 Range_Node
: Node_Id
;
13810 Constr_List
: List_Id
;
13812 Need_To_Create_Itype
: Boolean := False;
13815 Old_Index
:= First_Index
(Old_Type
);
13816 while Present
(Old_Index
) loop
13817 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
13819 if Is_Discriminant
(Lo_Expr
)
13821 Is_Discriminant
(Hi_Expr
)
13823 Need_To_Create_Itype
:= True;
13827 Next_Index
(Old_Index
);
13830 if Need_To_Create_Itype
then
13831 Constr_List
:= New_List
;
13833 Old_Index
:= First_Index
(Old_Type
);
13834 while Present
(Old_Index
) loop
13835 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
13837 if Is_Discriminant
(Lo_Expr
) then
13838 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
13841 if Is_Discriminant
(Hi_Expr
) then
13842 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
13847 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
13849 Append
(Range_Node
, To
=> Constr_List
);
13851 Next_Index
(Old_Index
);
13854 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
13859 end Build_Constrained_Array_Type
;
13861 ------------------------------------------
13862 -- Build_Constrained_Discriminated_Type --
13863 ------------------------------------------
13865 function Build_Constrained_Discriminated_Type
13866 (Old_Type
: Entity_Id
) return Entity_Id
13869 Constr_List
: List_Id
;
13870 Old_Constraint
: Elmt_Id
;
13872 Need_To_Create_Itype
: Boolean := False;
13875 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
13876 while Present
(Old_Constraint
) loop
13877 Expr
:= Node
(Old_Constraint
);
13879 if Is_Discriminant
(Expr
) then
13880 Need_To_Create_Itype
:= True;
13883 -- After expansion of discriminated task types, the value
13884 -- of the discriminant may be converted to a run-time type
13885 -- for restricted run-times. Propagate the value of the
13886 -- discriminant as well, so that e.g. the secondary stack
13887 -- component has a static constraint. Necessary for LLVM.
13889 elsif Nkind
(Expr
) = N_Type_Conversion
13890 and then Is_Discriminant
(Expression
(Expr
))
13892 Need_To_Create_Itype
:= True;
13896 Next_Elmt
(Old_Constraint
);
13899 if Need_To_Create_Itype
then
13900 Constr_List
:= New_List
;
13902 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
13903 while Present
(Old_Constraint
) loop
13904 Expr
:= Node
(Old_Constraint
);
13906 if Is_Discriminant
(Expr
) then
13907 Expr
:= Get_Discr_Value
(Expr
);
13909 elsif Nkind
(Expr
) = N_Type_Conversion
13910 and then Is_Discriminant
(Expression
(Expr
))
13912 Expr
:= New_Copy_Tree
(Expr
);
13913 Set_Expression
(Expr
, Get_Discr_Value
(Expression
(Expr
)));
13916 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
13918 Next_Elmt
(Old_Constraint
);
13921 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
13926 end Build_Constrained_Discriminated_Type
;
13928 ---------------------
13929 -- Get_Discr_Value --
13930 ---------------------
13932 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
is
13933 Discr_Id
: constant Entity_Id
:= Entity
(Discr_Expr
);
13934 -- Entity of a discriminant that appear as a standalone expression in
13935 -- the constraint of a component.
13941 -- The discriminant may be declared for the type, in which case we
13942 -- find it by iterating over the list of discriminants. If the
13943 -- discriminant is inherited from a parent type, it appears as the
13944 -- corresponding discriminant of the current type. This will be the
13945 -- case when constraining an inherited component whose constraint is
13946 -- given by a discriminant of the parent.
13948 D
:= First_Discriminant
(Typ
);
13949 E
:= First_Elmt
(Constraints
);
13951 while Present
(D
) loop
13953 or else D
= CR_Discriminant
(Discr_Id
)
13954 or else Corresponding_Discriminant
(D
) = Discr_Id
13959 Next_Discriminant
(D
);
13963 -- The Corresponding_Discriminant mechanism is incomplete, because
13964 -- the correspondence between new and old discriminants is not one
13965 -- to one: one new discriminant can constrain several old ones. In
13966 -- that case, scan sequentially the stored_constraint, the list of
13967 -- discriminants of the parents, and the constraints.
13969 -- Previous code checked for the present of the Stored_Constraint
13970 -- list for the derived type, but did not use it at all. Should it
13971 -- be present when the component is a discriminated task type?
13973 if Is_Derived_Type
(Typ
)
13974 and then Scope
(Discr_Id
) = Etype
(Typ
)
13976 D
:= First_Discriminant
(Etype
(Typ
));
13977 E
:= First_Elmt
(Constraints
);
13978 while Present
(D
) loop
13979 if D
= Discr_Id
then
13983 Next_Discriminant
(D
);
13988 -- Something is wrong if we did not find the value
13990 raise Program_Error
;
13991 end Get_Discr_Value
;
13993 ---------------------
13994 -- Is_Discriminant --
13995 ---------------------
13997 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
13998 Discrim_Scope
: Entity_Id
;
14001 if Denotes_Discriminant
(Expr
) then
14002 Discrim_Scope
:= Scope
(Entity
(Expr
));
14004 -- Either we have a reference to one of Typ's discriminants,
14006 pragma Assert
(Discrim_Scope
= Typ
14008 -- or to the discriminants of the parent type, in the case
14009 -- of a derivation of a tagged type with variants.
14011 or else Discrim_Scope
= Etype
(Typ
)
14012 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
14014 -- or same as above for the case where the discriminants
14015 -- were declared in Typ's private view.
14017 or else (Is_Private_Type
(Discrim_Scope
)
14018 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14020 -- or else we are deriving from the full view and the
14021 -- discriminant is declared in the private entity.
14023 or else (Is_Private_Type
(Typ
)
14024 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14026 -- Or we are constrained the corresponding record of a
14027 -- synchronized type that completes a private declaration.
14029 or else (Is_Concurrent_Record_Type
(Typ
)
14031 Corresponding_Concurrent_Type
(Typ
) = Discrim_Scope
)
14033 -- or we have a class-wide type, in which case make sure the
14034 -- discriminant found belongs to the root type.
14036 or else (Is_Class_Wide_Type
(Typ
)
14037 and then Etype
(Typ
) = Discrim_Scope
));
14042 -- In all other cases we have something wrong
14045 end Is_Discriminant
;
14047 -- Start of processing for Constrain_Component_Type
14050 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
14051 and then Comes_From_Source
(Parent
(Comp
))
14052 and then Comes_From_Source
14053 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14056 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14058 return Compon_Type
;
14060 elsif Is_Array_Type
(Compon_Type
) then
14061 return Build_Constrained_Array_Type
(Compon_Type
);
14063 elsif Has_Discriminants
(Compon_Type
) then
14064 return Build_Constrained_Discriminated_Type
(Compon_Type
);
14066 elsif Is_Access_Type
(Compon_Type
) then
14067 return Build_Constrained_Access_Type
(Compon_Type
);
14070 return Compon_Type
;
14072 end Constrain_Component_Type
;
14074 --------------------------
14075 -- Constrain_Concurrent --
14076 --------------------------
14078 -- For concurrent types, the associated record value type carries the same
14079 -- discriminants, so when we constrain a concurrent type, we must constrain
14080 -- the corresponding record type as well.
14082 procedure Constrain_Concurrent
14083 (Def_Id
: in out Entity_Id
;
14085 Related_Nod
: Node_Id
;
14086 Related_Id
: Entity_Id
;
14087 Suffix
: Character)
14089 -- Retrieve Base_Type to ensure getting to the concurrent type in the
14090 -- case of a private subtype (needed when only doing semantic analysis).
14092 T_Ent
: Entity_Id
:= Base_Type
(Entity
(Subtype_Mark
(SI
)));
14096 if Is_Access_Type
(T_Ent
) then
14097 T_Ent
:= Designated_Type
(T_Ent
);
14100 T_Val
:= Corresponding_Record_Type
(T_Ent
);
14102 if Present
(T_Val
) then
14104 if No
(Def_Id
) then
14105 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14107 -- Elaborate itype now, as it may be used in a subsequent
14108 -- synchronized operation in another scope.
14110 if Nkind
(Related_Nod
) = N_Full_Type_Declaration
then
14111 Build_Itype_Reference
(Def_Id
, Related_Nod
);
14115 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14116 Set_First_Private_Entity
(Def_Id
, First_Private_Entity
(T_Ent
));
14118 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
14119 Set_Corresponding_Record_Type
(Def_Id
,
14120 Constrain_Corresponding_Record
(Def_Id
, T_Val
, Related_Nod
));
14123 -- If there is no associated record, expansion is disabled and this
14124 -- is a generic context. Create a subtype in any case, so that
14125 -- semantic analysis can proceed.
14127 if No
(Def_Id
) then
14128 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14131 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14133 end Constrain_Concurrent
;
14135 ------------------------------------
14136 -- Constrain_Corresponding_Record --
14137 ------------------------------------
14139 function Constrain_Corresponding_Record
14140 (Prot_Subt
: Entity_Id
;
14141 Corr_Rec
: Entity_Id
;
14142 Related_Nod
: Node_Id
) return Entity_Id
14144 T_Sub
: constant Entity_Id
:=
14146 (Ekind
=> E_Record_Subtype
,
14147 Related_Nod
=> Related_Nod
,
14148 Related_Id
=> Corr_Rec
,
14150 Suffix_Index
=> -1);
14153 Set_Etype
(T_Sub
, Corr_Rec
);
14154 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
14155 Set_Is_Tagged_Type
(T_Sub
, Is_Tagged_Type
(Corr_Rec
));
14156 Set_Is_Constrained
(T_Sub
, True);
14157 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
14158 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
14160 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
14161 Set_Discriminant_Constraint
14162 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
14163 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
14164 Create_Constrained_Components
14165 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
14168 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
14170 if Ekind
(Scope
(Prot_Subt
)) /= E_Record_Type
then
14171 Conditional_Delay
(T_Sub
, Corr_Rec
);
14174 -- This is a component subtype: it will be frozen in the context of
14175 -- the enclosing record's init_proc, so that discriminant references
14176 -- are resolved to discriminals. (Note: we used to skip freezing
14177 -- altogether in that case, which caused errors downstream for
14178 -- components of a bit packed array type).
14180 Set_Has_Delayed_Freeze
(T_Sub
);
14184 end Constrain_Corresponding_Record
;
14186 -----------------------
14187 -- Constrain_Decimal --
14188 -----------------------
14190 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14191 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14192 C
: constant Node_Id
:= Constraint
(S
);
14193 Loc
: constant Source_Ptr
:= Sloc
(C
);
14194 Range_Expr
: Node_Id
;
14195 Digits_Expr
: Node_Id
;
14200 Mutate_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
14202 if Nkind
(C
) = N_Range_Constraint
then
14203 Range_Expr
:= Range_Expression
(C
);
14204 Digits_Val
:= Digits_Value
(T
);
14207 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
14209 Digits_Expr
:= Digits_Expression
(C
);
14210 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
14212 Check_Digits_Expression
(Digits_Expr
);
14213 Digits_Val
:= Expr_Value
(Digits_Expr
);
14215 if Digits_Val
> Digits_Value
(T
) then
14217 ("digits expression is incompatible with subtype", C
);
14218 Digits_Val
:= Digits_Value
(T
);
14221 if Present
(Range_Constraint
(C
)) then
14222 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
14224 Range_Expr
:= Empty
;
14228 Set_Etype
(Def_Id
, Base_Type
(T
));
14229 Set_Size_Info
(Def_Id
, (T
));
14230 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14231 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
14232 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
14233 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14234 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
14235 Set_Digits_Value
(Def_Id
, Digits_Val
);
14237 -- Manufacture range from given digits value if no range present
14239 if No
(Range_Expr
) then
14240 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
14244 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
14246 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
14249 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
14250 Set_Discrete_RM_Size
(Def_Id
);
14252 -- Unconditionally delay the freeze, since we cannot set size
14253 -- information in all cases correctly until the freeze point.
14255 Set_Has_Delayed_Freeze
(Def_Id
);
14256 end Constrain_Decimal
;
14258 ----------------------------------
14259 -- Constrain_Discriminated_Type --
14260 ----------------------------------
14262 procedure Constrain_Discriminated_Type
14263 (Def_Id
: Entity_Id
;
14265 Related_Nod
: Node_Id
;
14266 For_Access
: Boolean := False)
14268 E
: Entity_Id
:= Entity
(Subtype_Mark
(S
));
14271 procedure Fixup_Bad_Constraint
;
14272 -- Called after finding a bad constraint, and after having posted an
14273 -- appropriate error message. The goal is to leave type Def_Id in as
14274 -- reasonable state as possible.
14276 --------------------------
14277 -- Fixup_Bad_Constraint --
14278 --------------------------
14280 procedure Fixup_Bad_Constraint
is
14282 -- Set a reasonable Ekind for the entity, including incomplete types.
14284 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
14286 -- Set Etype to the known type, to reduce chances of cascaded errors
14288 Set_Etype
(Def_Id
, E
);
14289 Set_Error_Posted
(Def_Id
);
14290 end Fixup_Bad_Constraint
;
14295 Constr
: Elist_Id
:= New_Elmt_List
;
14297 -- Start of processing for Constrain_Discriminated_Type
14300 C
:= Constraint
(S
);
14302 -- A discriminant constraint is only allowed in a subtype indication,
14303 -- after a subtype mark. This subtype mark must denote either a type
14304 -- with discriminants, or an access type whose designated type is a
14305 -- type with discriminants. A discriminant constraint specifies the
14306 -- values of these discriminants (RM 3.7.2(5)).
14308 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
14310 if Is_Access_Type
(T
) then
14311 T
:= Designated_Type
(T
);
14314 -- In an instance it may be necessary to retrieve the full view of a
14315 -- type with unknown discriminants, or a full view with defaulted
14316 -- discriminants. In other contexts the constraint is illegal.
14319 and then Is_Private_Type
(T
)
14320 and then Present
(Full_View
(T
))
14322 (Has_Unknown_Discriminants
(T
)
14324 (not Has_Discriminants
(T
)
14325 and then Has_Defaulted_Discriminants
(Full_View
(T
))))
14327 T
:= Full_View
(T
);
14328 E
:= Full_View
(E
);
14331 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal. Avoid
14332 -- generating an error for access-to-incomplete subtypes.
14334 if Ada_Version
>= Ada_2005
14335 and then Ekind
(T
) = E_Incomplete_Type
14336 and then Nkind
(Parent
(S
)) = N_Subtype_Declaration
14337 and then not Is_Itype
(Def_Id
)
14339 -- A little sanity check: emit an error message if the type has
14340 -- discriminants to begin with. Type T may be a regular incomplete
14341 -- type or imported via a limited with clause.
14343 if Has_Discriminants
(T
)
14344 or else (From_Limited_With
(T
)
14345 and then Present
(Non_Limited_View
(T
))
14346 and then Nkind
(Parent
(Non_Limited_View
(T
))) =
14347 N_Full_Type_Declaration
14348 and then Present
(Discriminant_Specifications
14349 (Parent
(Non_Limited_View
(T
)))))
14352 ("(Ada 2005) incomplete subtype may not be constrained", C
);
14354 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14357 Fixup_Bad_Constraint
;
14360 -- Check that the type has visible discriminants. The type may be
14361 -- a private type with unknown discriminants whose full view has
14362 -- discriminants which are invisible.
14364 elsif not Has_Discriminants
(T
)
14366 (Has_Unknown_Discriminants
(T
)
14367 and then Is_Private_Type
(T
))
14369 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14370 Fixup_Bad_Constraint
;
14373 elsif Is_Constrained
(E
)
14374 or else (Ekind
(E
) = E_Class_Wide_Subtype
14375 and then Present
(Discriminant_Constraint
(E
)))
14377 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
14378 Fixup_Bad_Constraint
;
14382 -- T may be an unconstrained subtype (e.g. a generic actual). Constraint
14383 -- applies to the base type.
14385 T
:= Base_Type
(T
);
14387 Constr
:= Build_Discriminant_Constraints
(T
, S
);
14389 -- If the list returned was empty we had an error in building the
14390 -- discriminant constraint. We have also already signalled an error
14391 -- in the incomplete type case
14393 if Is_Empty_Elmt_List
(Constr
) then
14394 Fixup_Bad_Constraint
;
14398 Build_Discriminated_Subtype
(T
, Def_Id
, Constr
, Related_Nod
, For_Access
);
14399 end Constrain_Discriminated_Type
;
14401 ---------------------------
14402 -- Constrain_Enumeration --
14403 ---------------------------
14405 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14406 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14407 C
: constant Node_Id
:= Constraint
(S
);
14410 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14412 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
14414 Set_Etype
(Def_Id
, Base_Type
(T
));
14415 Set_Size_Info
(Def_Id
, (T
));
14416 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14417 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14419 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14421 Set_Discrete_RM_Size
(Def_Id
);
14422 end Constrain_Enumeration
;
14424 ----------------------
14425 -- Constrain_Float --
14426 ----------------------
14428 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14429 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14435 Mutate_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
14437 Set_Etype
(Def_Id
, Base_Type
(T
));
14438 Set_Size_Info
(Def_Id
, (T
));
14439 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14441 -- Process the constraint
14443 C
:= Constraint
(S
);
14445 -- Digits constraint present
14447 if Nkind
(C
) = N_Digits_Constraint
then
14448 Check_Restriction
(No_Obsolescent_Features
, C
);
14450 if Warn_On_Obsolescent_Feature
then
14452 ("subtype digits constraint is an " &
14453 "obsolescent feature (RM J.3(8))?j?", C
);
14456 D
:= Digits_Expression
(C
);
14457 Analyze_And_Resolve
(D
, Any_Integer
);
14458 Check_Digits_Expression
(D
);
14459 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
14461 -- Check that digits value is in range. Obviously we can do this
14462 -- at compile time, but it is strictly a runtime check, and of
14463 -- course there is an ACVC test that checks this.
14465 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
14466 Error_Msg_Uint_1
:= Digits_Value
(T
);
14467 Error_Msg_N
("??digits value is too large, maximum is ^", D
);
14469 Make_Raise_Constraint_Error
(Sloc
(D
),
14470 Reason
=> CE_Range_Check_Failed
);
14471 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
14474 C
:= Range_Constraint
(C
);
14476 -- No digits constraint present
14479 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
14482 -- Range constraint present
14484 if Nkind
(C
) = N_Range_Constraint
then
14485 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14487 -- No range constraint present
14490 pragma Assert
(No
(C
));
14491 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
14494 Set_Is_Constrained
(Def_Id
);
14495 end Constrain_Float
;
14497 ---------------------
14498 -- Constrain_Index --
14499 ---------------------
14501 procedure Constrain_Index
14504 Related_Nod
: Node_Id
;
14505 Related_Id
: Entity_Id
;
14506 Suffix
: Character;
14507 Suffix_Index
: Pos
)
14509 Def_Id
: Entity_Id
;
14510 R
: Node_Id
:= Empty
;
14511 T
: constant Entity_Id
:= Etype
(Index
);
14512 Is_FLB_Index
: Boolean := False;
14516 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
14517 Set_Etype
(Def_Id
, Base_Type
(T
));
14519 if Nkind
(S
) = N_Range
14521 (Nkind
(S
) = N_Attribute_Reference
14522 and then Attribute_Name
(S
) = Name_Range
)
14524 -- A Range attribute will be transformed into N_Range by Resolve
14526 -- If a range has an Empty upper bound, then remember that for later
14527 -- setting of the index subtype's Is_Fixed_Lower_Bound_Index_Subtype
14528 -- flag, and also set the upper bound of the range to the index
14529 -- subtype's upper bound rather than leaving it Empty. In truth,
14530 -- that upper bound corresponds to a box ("<>"), but it's convenient
14531 -- to set it to the upper bound to avoid needing to add special tests
14532 -- in various places for an Empty upper bound, and in any case it
14533 -- accurately characterizes the index's range of values.
14535 if Nkind
(S
) = N_Range
and then not Present
(High_Bound
(S
)) then
14536 Is_FLB_Index
:= True;
14537 Set_High_Bound
(S
, Type_High_Bound
(T
));
14542 Process_Range_Expr_In_Decl
(R
, T
);
14544 if not Error_Posted
(S
)
14546 (Nkind
(S
) /= N_Range
14547 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
14548 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
14550 if Base_Type
(T
) /= Any_Type
14551 and then Etype
(Low_Bound
(S
)) /= Any_Type
14552 and then Etype
(High_Bound
(S
)) /= Any_Type
14554 Error_Msg_N
("range expected", S
);
14558 elsif Nkind
(S
) = N_Subtype_Indication
then
14560 -- The parser has verified that this is a discrete indication
14562 Resolve_Discrete_Subtype_Indication
(S
, T
);
14563 Bad_Predicated_Subtype_Use
14564 ("subtype& has predicate, not allowed in index constraint",
14565 S
, Entity
(Subtype_Mark
(S
)));
14567 R
:= Range_Expression
(Constraint
(S
));
14569 -- Capture values of bounds and generate temporaries for them if
14570 -- needed, since checks may cause duplication of the expressions
14571 -- which must not be reevaluated.
14573 -- The forced evaluation removes side effects from expressions, which
14574 -- should occur also in GNATprove mode. Otherwise, we end up with
14575 -- unexpected insertions of actions at places where this is not
14576 -- supposed to occur, e.g. on default parameters of a call.
14578 if Expander_Active
or GNATprove_Mode
then
14580 (Low_Bound
(R
), Related_Id
=> Def_Id
, Is_Low_Bound
=> True);
14582 (High_Bound
(R
), Related_Id
=> Def_Id
, Is_High_Bound
=> True);
14585 elsif Nkind
(S
) = N_Discriminant_Association
then
14587 -- Syntactically valid in subtype indication
14589 Error_Msg_N
("invalid index constraint", S
);
14590 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14593 -- Subtype_Mark case, no anonymous subtypes to construct
14598 if Is_Entity_Name
(S
) then
14599 if not Is_Type
(Entity
(S
)) then
14600 Error_Msg_N
("expect subtype mark for index constraint", S
);
14602 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
14603 Wrong_Type
(S
, Base_Type
(T
));
14605 -- Check error of subtype with predicate in index constraint
14608 Bad_Predicated_Subtype_Use
14609 ("subtype& has predicate, not allowed in index constraint",
14616 Error_Msg_N
("invalid index constraint", S
);
14617 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14622 -- Complete construction of the Itype
14624 if Is_Modular_Integer_Type
(T
) then
14625 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14627 elsif Is_Integer_Type
(T
) then
14628 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14631 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14632 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14633 Set_First_Literal
(Def_Id
, First_Literal
(T
));
14636 Set_Size_Info
(Def_Id
, (T
));
14637 Copy_RM_Size
(To
=> Def_Id
, From
=> T
);
14638 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14640 -- If this is a range for a fixed-lower-bound subtype, then set the
14641 -- index itype's low bound to the FLB and the index itype's upper bound
14642 -- to the high bound of the parent array type's index subtype. Also,
14643 -- mark the itype as an FLB index subtype.
14645 if Nkind
(S
) = N_Range
and then Is_FLB_Index
then
14648 Make_Range
(Sloc
(S
),
14649 Low_Bound
=> Low_Bound
(S
),
14650 High_Bound
=> Type_High_Bound
(T
)));
14651 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Def_Id
);
14654 Set_Scalar_Range
(Def_Id
, R
);
14657 Set_Etype
(S
, Def_Id
);
14658 Set_Discrete_RM_Size
(Def_Id
);
14659 end Constrain_Index
;
14661 -----------------------
14662 -- Constrain_Integer --
14663 -----------------------
14665 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14666 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14667 C
: constant Node_Id
:= Constraint
(S
);
14670 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14672 if Is_Modular_Integer_Type
(T
) then
14673 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14675 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14678 Set_Etype
(Def_Id
, Base_Type
(T
));
14679 Set_Size_Info
(Def_Id
, (T
));
14680 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14681 Set_Discrete_RM_Size
(Def_Id
);
14682 end Constrain_Integer
;
14684 ------------------------------
14685 -- Constrain_Ordinary_Fixed --
14686 ------------------------------
14688 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14689 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14695 Mutate_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
14696 Set_Etype
(Def_Id
, Base_Type
(T
));
14697 Set_Size_Info
(Def_Id
, (T
));
14698 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14699 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14701 -- Process the constraint
14703 C
:= Constraint
(S
);
14705 -- Delta constraint present
14707 if Nkind
(C
) = N_Delta_Constraint
then
14708 Check_Restriction
(No_Obsolescent_Features
, C
);
14710 if Warn_On_Obsolescent_Feature
then
14712 ("subtype delta constraint is an " &
14713 "obsolescent feature (RM J.3(7))?j?");
14716 D
:= Delta_Expression
(C
);
14717 Analyze_And_Resolve
(D
, Any_Real
);
14718 Check_Delta_Expression
(D
);
14719 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
14721 -- Check that delta value is in range. Obviously we can do this
14722 -- at compile time, but it is strictly a runtime check, and of
14723 -- course there is an ACVC test that checks this.
14725 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
14726 Error_Msg_N
("??delta value is too small", D
);
14728 Make_Raise_Constraint_Error
(Sloc
(D
),
14729 Reason
=> CE_Range_Check_Failed
);
14730 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
14733 C
:= Range_Constraint
(C
);
14735 -- No delta constraint present
14738 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
14741 -- Range constraint present
14743 if Nkind
(C
) = N_Range_Constraint
then
14744 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14746 -- No range constraint present
14749 pragma Assert
(No
(C
));
14750 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
14753 Set_Discrete_RM_Size
(Def_Id
);
14755 -- Unconditionally delay the freeze, since we cannot set size
14756 -- information in all cases correctly until the freeze point.
14758 Set_Has_Delayed_Freeze
(Def_Id
);
14759 end Constrain_Ordinary_Fixed
;
14761 -----------------------
14762 -- Contain_Interface --
14763 -----------------------
14765 function Contain_Interface
14766 (Iface
: Entity_Id
;
14767 Ifaces
: Elist_Id
) return Boolean
14769 Iface_Elmt
: Elmt_Id
;
14772 if Present
(Ifaces
) then
14773 Iface_Elmt
:= First_Elmt
(Ifaces
);
14774 while Present
(Iface_Elmt
) loop
14775 if Node
(Iface_Elmt
) = Iface
then
14779 Next_Elmt
(Iface_Elmt
);
14784 end Contain_Interface
;
14786 ---------------------------
14787 -- Convert_Scalar_Bounds --
14788 ---------------------------
14790 procedure Convert_Scalar_Bounds
14792 Parent_Type
: Entity_Id
;
14793 Derived_Type
: Entity_Id
;
14796 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
14803 -- Defend against previous errors
14805 if No
(Scalar_Range
(Derived_Type
)) then
14806 Check_Error_Detected
;
14810 Lo
:= Build_Scalar_Bound
14811 (Type_Low_Bound
(Derived_Type
),
14812 Parent_Type
, Implicit_Base
);
14814 Hi
:= Build_Scalar_Bound
14815 (Type_High_Bound
(Derived_Type
),
14816 Parent_Type
, Implicit_Base
);
14823 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
14825 Set_Parent
(Rng
, N
);
14826 Set_Scalar_Range
(Derived_Type
, Rng
);
14828 -- Analyze the bounds
14830 Analyze_And_Resolve
(Lo
, Implicit_Base
);
14831 Analyze_And_Resolve
(Hi
, Implicit_Base
);
14833 -- Analyze the range itself, except that we do not analyze it if
14834 -- the bounds are real literals, and we have a fixed-point type.
14835 -- The reason for this is that we delay setting the bounds in this
14836 -- case till we know the final Small and Size values (see circuit
14837 -- in Freeze.Freeze_Fixed_Point_Type for further details).
14839 if Is_Fixed_Point_Type
(Parent_Type
)
14840 and then Nkind
(Lo
) = N_Real_Literal
14841 and then Nkind
(Hi
) = N_Real_Literal
14845 -- Here we do the analysis of the range
14847 -- Note: we do this manually, since if we do a normal Analyze and
14848 -- Resolve call, there are problems with the conversions used for
14849 -- the derived type range.
14852 Set_Etype
(Rng
, Implicit_Base
);
14853 Set_Analyzed
(Rng
, True);
14855 end Convert_Scalar_Bounds
;
14857 -------------------
14858 -- Copy_And_Swap --
14859 -------------------
14861 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
14863 -- Initialize new full declaration entity by copying the pertinent
14864 -- fields of the corresponding private declaration entity.
14866 -- We temporarily set Ekind to a value appropriate for a type to
14867 -- avoid assert failures in Einfo from checking for setting type
14868 -- attributes on something that is not a type. Ekind (Priv) is an
14869 -- appropriate choice, since it allowed the attributes to be set
14870 -- in the first place. This Ekind value will be modified later.
14872 Mutate_Ekind
(Full
, Ekind
(Priv
));
14874 -- Also set Etype temporarily to Any_Type, again, in the absence
14875 -- of errors, it will be properly reset, and if there are errors,
14876 -- then we want a value of Any_Type to remain.
14878 Set_Etype
(Full
, Any_Type
);
14880 -- Now start copying attributes
14882 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
14884 if Has_Discriminants
(Full
) then
14885 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
14886 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
14889 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
14890 Set_Homonym
(Full
, Homonym
(Priv
));
14891 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
14892 Set_Is_Public
(Full
, Is_Public
(Priv
));
14893 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
14894 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
14895 Set_Has_Pragma_Unmodified
(Full
, Has_Pragma_Unmodified
(Priv
));
14896 Set_Has_Pragma_Unreferenced
(Full
, Has_Pragma_Unreferenced
(Priv
));
14897 Set_Has_Pragma_Unreferenced_Objects
14898 (Full
, Has_Pragma_Unreferenced_Objects
14901 Conditional_Delay
(Full
, Priv
);
14903 if Is_Tagged_Type
(Full
) then
14904 Set_Direct_Primitive_Operations
14905 (Full
, Direct_Primitive_Operations
(Priv
));
14906 Set_No_Tagged_Streams_Pragma
14907 (Full
, No_Tagged_Streams_Pragma
(Priv
));
14909 if Is_Base_Type
(Priv
) then
14910 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
14914 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
14915 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
14916 Set_Scope
(Full
, Scope
(Priv
));
14917 Set_Prev_Entity
(Full
, Prev_Entity
(Priv
));
14918 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
14919 Set_First_Entity
(Full
, First_Entity
(Priv
));
14920 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
14922 -- If access types have been recorded for later handling, keep them in
14923 -- the full view so that they get handled when the full view freeze
14924 -- node is expanded.
14926 if Present
(Freeze_Node
(Priv
))
14927 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
14929 Ensure_Freeze_Node
(Full
);
14930 Set_Access_Types_To_Process
14931 (Freeze_Node
(Full
),
14932 Access_Types_To_Process
(Freeze_Node
(Priv
)));
14935 -- Swap the two entities. Now Private is the full type entity and Full
14936 -- is the private one. They will be swapped back at the end of the
14937 -- private part. This swapping ensures that the entity that is visible
14938 -- in the private part is the full declaration.
14940 Exchange_Entities
(Priv
, Full
);
14941 Append_Entity
(Full
, Scope
(Full
));
14944 -------------------------------------
14945 -- Copy_Array_Base_Type_Attributes --
14946 -------------------------------------
14948 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
14950 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
14951 Set_Component_Type
(T1
, Component_Type
(T2
));
14952 Set_Component_Size
(T1
, Component_Size
(T2
));
14953 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
14954 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
14955 Propagate_Concurrent_Flags
(T1
, T2
);
14956 Set_Is_Packed
(T1
, Is_Packed
(T2
));
14957 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
14958 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
14959 Set_Has_Independent_Components
(T1
, Has_Independent_Components
(T2
));
14960 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
14961 end Copy_Array_Base_Type_Attributes
;
14963 -----------------------------------
14964 -- Copy_Array_Subtype_Attributes --
14965 -----------------------------------
14967 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
14969 Set_Size_Info
(T1
, T2
);
14971 Set_First_Index
(T1
, First_Index
(T2
));
14972 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
14973 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
14974 Set_Is_Independent
(T1
, Is_Independent
(T2
));
14975 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
14976 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
14977 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
14978 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
14979 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
14980 Inherit_Rep_Item_Chain
(T1
, T2
);
14981 Set_Convention
(T1
, Convention
(T2
));
14982 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
14983 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
14984 Set_Packed_Array_Impl_Type
(T1
, Packed_Array_Impl_Type
(T2
));
14985 end Copy_Array_Subtype_Attributes
;
14987 -----------------------------------
14988 -- Create_Constrained_Components --
14989 -----------------------------------
14991 procedure Create_Constrained_Components
14993 Decl_Node
: Node_Id
;
14995 Constraints
: Elist_Id
)
14997 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
14998 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
14999 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
15000 Assoc_List
: constant List_Id
:= New_List
;
15002 Discr_Val
: Elmt_Id
;
15006 Is_Static
: Boolean := True;
15007 Is_Compile_Time_Known
: Boolean := True;
15009 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
15010 -- Collect parent type components that do not appear in a variant part
15012 procedure Create_All_Components
;
15013 -- Iterate over Comp_List to create the components of the subtype
15015 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
15016 -- Creates a new component from Old_Compon, copying all the fields from
15017 -- it, including its Etype, inserts the new component in the Subt entity
15018 -- chain and returns the new component.
15020 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
15021 -- If true, and discriminants are static, collect only components from
15022 -- variants selected by discriminant values.
15024 ------------------------------
15025 -- Collect_Fixed_Components --
15026 ------------------------------
15028 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
15030 -- Build association list for discriminants, and find components of the
15031 -- variant part selected by the values of the discriminants.
15033 Old_C
:= First_Discriminant
(Typ
);
15034 Discr_Val
:= First_Elmt
(Constraints
);
15035 while Present
(Old_C
) loop
15036 Append_To
(Assoc_List
,
15037 Make_Component_Association
(Loc
,
15038 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
15039 Expression
=> New_Copy
(Node
(Discr_Val
))));
15041 Next_Elmt
(Discr_Val
);
15042 Next_Discriminant
(Old_C
);
15045 -- The tag and the possible parent component are unconditionally in
15048 if Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
15049 Old_C
:= First_Component
(Typ
);
15050 while Present
(Old_C
) loop
15051 if Chars
(Old_C
) in Name_uTag | Name_uParent
then
15052 Append_Elmt
(Old_C
, Comp_List
);
15055 Next_Component
(Old_C
);
15058 end Collect_Fixed_Components
;
15060 ---------------------------
15061 -- Create_All_Components --
15062 ---------------------------
15064 procedure Create_All_Components
is
15068 Comp
:= First_Elmt
(Comp_List
);
15069 while Present
(Comp
) loop
15070 Old_C
:= Node
(Comp
);
15071 New_C
:= Create_Component
(Old_C
);
15075 Constrain_Component_Type
15076 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15077 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15081 end Create_All_Components
;
15083 ----------------------
15084 -- Create_Component --
15085 ----------------------
15087 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
15088 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
15091 if Ekind
(Old_Compon
) = E_Discriminant
15092 and then Is_Completely_Hidden
(Old_Compon
)
15094 -- This is a shadow discriminant created for a discriminant of
15095 -- the parent type, which needs to be present in the subtype.
15096 -- Give the shadow discriminant an internal name that cannot
15097 -- conflict with that of visible components.
15099 Set_Chars
(New_Compon
, New_Internal_Name
('C'));
15102 -- Set the parent so we have a proper link for freezing etc. This is
15103 -- not a real parent pointer, since of course our parent does not own
15104 -- up to us and reference us, we are an illegitimate child of the
15105 -- original parent.
15107 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
15109 -- We do not want this node marked as Comes_From_Source, since
15110 -- otherwise it would get first class status and a separate cross-
15111 -- reference line would be generated. Illegitimate children do not
15112 -- rate such recognition.
15114 Set_Comes_From_Source
(New_Compon
, False);
15116 -- But it is a real entity, and a birth certificate must be properly
15117 -- registered by entering it into the entity list, and setting its
15118 -- scope to the given subtype. This turns out to be useful for the
15119 -- LLVM code generator, but that scope is not used otherwise.
15121 Enter_Name
(New_Compon
);
15122 Set_Scope
(New_Compon
, Subt
);
15125 end Create_Component
;
15127 -----------------------
15128 -- Is_Variant_Record --
15129 -----------------------
15131 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
15133 return Nkind
(Parent
(T
)) = N_Full_Type_Declaration
15134 and then Nkind
(Type_Definition
(Parent
(T
))) = N_Record_Definition
15135 and then Present
(Component_List
(Type_Definition
(Parent
(T
))))
15138 (Variant_Part
(Component_List
(Type_Definition
(Parent
(T
)))));
15139 end Is_Variant_Record
;
15141 -- Start of processing for Create_Constrained_Components
15144 pragma Assert
(Subt
/= Base_Type
(Subt
));
15145 pragma Assert
(Typ
= Base_Type
(Typ
));
15147 Set_First_Entity
(Subt
, Empty
);
15148 Set_Last_Entity
(Subt
, Empty
);
15150 -- Check whether constraint is fully static, in which case we can
15151 -- optimize the list of components.
15153 Discr_Val
:= First_Elmt
(Constraints
);
15154 while Present
(Discr_Val
) loop
15155 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
15156 Is_Static
:= False;
15158 if not Compile_Time_Known_Value
(Node
(Discr_Val
)) then
15159 Is_Compile_Time_Known
:= False;
15164 Next_Elmt
(Discr_Val
);
15167 Set_Has_Static_Discriminants
(Subt
, Is_Static
);
15171 -- Inherit the discriminants of the parent type
15173 Add_Discriminants
: declare
15179 Old_C
:= First_Discriminant
(Typ
);
15181 while Present
(Old_C
) loop
15182 Num_Disc
:= Num_Disc
+ 1;
15183 New_C
:= Create_Component
(Old_C
);
15184 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15185 Next_Discriminant
(Old_C
);
15188 -- For an untagged derived subtype, the number of discriminants may
15189 -- be smaller than the number of inherited discriminants, because
15190 -- several of them may be renamed by a single new discriminant or
15191 -- constrained. In this case, add the hidden discriminants back into
15192 -- the subtype, because they need to be present if the optimizer of
15193 -- the GCC 4.x back-end decides to break apart assignments between
15194 -- objects using the parent view into member-wise assignments.
15198 if Is_Derived_Type
(Typ
)
15199 and then not Is_Tagged_Type
(Typ
)
15201 Old_C
:= First_Stored_Discriminant
(Typ
);
15203 while Present
(Old_C
) loop
15204 Num_Stor
:= Num_Stor
+ 1;
15205 Next_Stored_Discriminant
(Old_C
);
15209 if Num_Stor
> Num_Disc
then
15211 -- Find out multiple uses of new discriminants, and add hidden
15212 -- components for the extra renamed discriminants. We recognize
15213 -- multiple uses through the Corresponding_Discriminant of a
15214 -- new discriminant: if it constrains several old discriminants,
15215 -- this field points to the last one in the parent type. The
15216 -- stored discriminants of the derived type have the same name
15217 -- as those of the parent.
15221 New_Discr
: Entity_Id
;
15222 Old_Discr
: Entity_Id
;
15225 Constr
:= First_Elmt
(Stored_Constraint
(Typ
));
15226 Old_Discr
:= First_Stored_Discriminant
(Typ
);
15227 while Present
(Constr
) loop
15228 if Is_Entity_Name
(Node
(Constr
))
15229 and then Ekind
(Entity
(Node
(Constr
))) = E_Discriminant
15231 New_Discr
:= Entity
(Node
(Constr
));
15233 if Chars
(Corresponding_Discriminant
(New_Discr
)) /=
15236 -- The new discriminant has been used to rename a
15237 -- subsequent old discriminant. Introduce a shadow
15238 -- component for the current old discriminant.
15240 New_C
:= Create_Component
(Old_Discr
);
15241 Set_Original_Record_Component
(New_C
, Old_Discr
);
15245 -- The constraint has eliminated the old discriminant.
15246 -- Introduce a shadow component.
15248 New_C
:= Create_Component
(Old_Discr
);
15249 Set_Original_Record_Component
(New_C
, Old_Discr
);
15252 Next_Elmt
(Constr
);
15253 Next_Stored_Discriminant
(Old_Discr
);
15257 end Add_Discriminants
;
15259 if Is_Compile_Time_Known
15260 and then Is_Variant_Record
(Typ
)
15262 Collect_Fixed_Components
(Typ
);
15265 Component_List
(Type_Definition
(Parent
(Typ
))),
15266 Governed_By
=> Assoc_List
,
15268 Report_Errors
=> Errors
,
15269 Allow_Compile_Time
=> True);
15270 pragma Assert
(not Errors
or else Serious_Errors_Detected
> 0);
15272 Create_All_Components
;
15274 -- If the subtype declaration is created for a tagged type derivation
15275 -- with constraints, we retrieve the record definition of the parent
15276 -- type to select the components of the proper variant.
15278 elsif Is_Compile_Time_Known
15279 and then Is_Tagged_Type
(Typ
)
15280 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
15282 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
15283 and then Is_Variant_Record
(Parent_Type
)
15285 Collect_Fixed_Components
(Typ
);
15288 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
15289 Governed_By
=> Assoc_List
,
15291 Report_Errors
=> Errors
,
15292 Allow_Compile_Time
=> True);
15294 -- Note: previously there was a check at this point that no errors
15295 -- were detected. As a consequence of AI05-220 there may be an error
15296 -- if an inherited discriminant that controls a variant has a non-
15297 -- static constraint.
15299 -- If the tagged derivation has a type extension, collect all the
15300 -- new relevant components therein via Gather_Components.
15302 if Present
(Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
15307 (Record_Extension_Part
(Type_Definition
(Parent
(Typ
)))),
15308 Governed_By
=> Assoc_List
,
15310 Report_Errors
=> Errors
,
15311 Allow_Compile_Time
=> True,
15312 Include_Interface_Tag
=> True);
15315 Create_All_Components
;
15318 -- If discriminants are not static, or if this is a multi-level type
15319 -- extension, we have to include all components of the parent type.
15321 Old_C
:= First_Component
(Typ
);
15322 while Present
(Old_C
) loop
15323 New_C
:= Create_Component
(Old_C
);
15327 Constrain_Component_Type
15328 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15329 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15331 Next_Component
(Old_C
);
15336 end Create_Constrained_Components
;
15338 ------------------------------------------
15339 -- Decimal_Fixed_Point_Type_Declaration --
15340 ------------------------------------------
15342 procedure Decimal_Fixed_Point_Type_Declaration
15346 Loc
: constant Source_Ptr
:= Sloc
(Def
);
15347 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
15348 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
15349 Max_Digits
: constant Nat
:=
15350 (if System_Max_Integer_Size
= 128 then 38 else 18);
15351 -- Maximum number of digits that can be represented in an integer
15353 Implicit_Base
: Entity_Id
;
15360 Check_Restriction
(No_Fixed_Point
, Def
);
15362 -- Create implicit base type
15365 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
15366 Set_Etype
(Implicit_Base
, Implicit_Base
);
15368 -- Analyze and process delta expression
15370 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
15372 Check_Delta_Expression
(Delta_Expr
);
15373 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
15375 -- Check delta is power of 10, and determine scale value from it
15381 Scale_Val
:= Uint_0
;
15384 if Val
< Ureal_1
then
15385 while Val
< Ureal_1
loop
15386 Val
:= Val
* Ureal_10
;
15387 Scale_Val
:= Scale_Val
+ 1;
15390 if Scale_Val
> Max_Digits
then
15391 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15392 Error_Msg_N
("scale exceeds maximum value of ^", Def
);
15393 Scale_Val
:= UI_From_Int
(Max_Digits
);
15397 while Val
> Ureal_1
loop
15398 Val
:= Val
/ Ureal_10
;
15399 Scale_Val
:= Scale_Val
- 1;
15402 if Scale_Val
< -Max_Digits
then
15403 Error_Msg_Uint_1
:= UI_From_Int
(-Max_Digits
);
15404 Error_Msg_N
("scale is less than minimum value of ^", Def
);
15405 Scale_Val
:= UI_From_Int
(-Max_Digits
);
15409 if Val
/= Ureal_1
then
15410 Error_Msg_N
("delta expression must be a power of 10", Def
);
15411 Delta_Val
:= Ureal_10
** (-Scale_Val
);
15415 -- Set delta, scale and small (small = delta for decimal type)
15417 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
15418 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
15419 Set_Small_Value
(Implicit_Base
, Delta_Val
);
15421 -- Analyze and process digits expression
15423 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
15424 Check_Digits_Expression
(Digs_Expr
);
15425 Digs_Val
:= Expr_Value
(Digs_Expr
);
15427 if Digs_Val
> Max_Digits
then
15428 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15429 Error_Msg_N
("digits value out of range, maximum is ^", Digs_Expr
);
15430 Digs_Val
:= UI_From_Int
(Max_Digits
);
15433 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
15434 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
15436 -- Set range of base type from digits value for now. This will be
15437 -- expanded to represent the true underlying base range by Freeze.
15439 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
15441 -- Note: We leave Esize unset for now, size will be set at freeze
15442 -- time. We have to do this for ordinary fixed-point, because the size
15443 -- depends on the specified small, and we might as well do the same for
15444 -- decimal fixed-point.
15446 pragma Assert
(not Known_Esize
(Implicit_Base
));
15448 -- If there are bounds given in the declaration use them as the
15449 -- bounds of the first named subtype.
15451 if Present
(Real_Range_Specification
(Def
)) then
15453 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
15454 Low
: constant Node_Id
:= Low_Bound
(RRS
);
15455 High
: constant Node_Id
:= High_Bound
(RRS
);
15460 Analyze_And_Resolve
(Low
, Any_Real
);
15461 Analyze_And_Resolve
(High
, Any_Real
);
15462 Check_Real_Bound
(Low
);
15463 Check_Real_Bound
(High
);
15464 Low_Val
:= Expr_Value_R
(Low
);
15465 High_Val
:= Expr_Value_R
(High
);
15467 if Low_Val
< (-Bound_Val
) then
15469 ("range low bound too small for digits value", Low
);
15470 Low_Val
:= -Bound_Val
;
15473 if High_Val
> Bound_Val
then
15475 ("range high bound too large for digits value", High
);
15476 High_Val
:= Bound_Val
;
15479 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
15482 -- If no explicit range, use range that corresponds to given
15483 -- digits value. This will end up as the final range for the
15487 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
15490 -- Complete entity for first subtype. The inheritance of the rep item
15491 -- chain ensures that SPARK-related pragmas are not clobbered when the
15492 -- decimal fixed point type acts as a full view of a private type.
15494 Mutate_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
15495 Set_Etype
(T
, Implicit_Base
);
15496 Set_Size_Info
(T
, Implicit_Base
);
15497 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
15498 Set_Digits_Value
(T
, Digs_Val
);
15499 Set_Delta_Value
(T
, Delta_Val
);
15500 Set_Small_Value
(T
, Delta_Val
);
15501 Set_Scale_Value
(T
, Scale_Val
);
15502 Set_Is_Constrained
(T
);
15503 end Decimal_Fixed_Point_Type_Declaration
;
15505 -----------------------------------
15506 -- Derive_Progenitor_Subprograms --
15507 -----------------------------------
15509 procedure Derive_Progenitor_Subprograms
15510 (Parent_Type
: Entity_Id
;
15511 Tagged_Type
: Entity_Id
)
15516 Iface_Alias
: Entity_Id
;
15517 Iface_Elmt
: Elmt_Id
;
15518 Iface_Subp
: Entity_Id
;
15519 New_Subp
: Entity_Id
:= Empty
;
15520 Prim_Elmt
: Elmt_Id
;
15525 pragma Assert
(Ada_Version
>= Ada_2005
15526 and then Is_Record_Type
(Tagged_Type
)
15527 and then Is_Tagged_Type
(Tagged_Type
)
15528 and then Has_Interfaces
(Tagged_Type
));
15530 -- Step 1: Transfer to the full-view primitives associated with the
15531 -- partial-view that cover interface primitives. Conceptually this
15532 -- work should be done later by Process_Full_View; done here to
15533 -- simplify its implementation at later stages. It can be safely
15534 -- done here because interfaces must be visible in the partial and
15535 -- private view (RM 7.3(7.3/2)).
15537 -- Small optimization: This work is only required if the parent may
15538 -- have entities whose Alias attribute reference an interface primitive.
15539 -- Such a situation may occur if the parent is an abstract type and the
15540 -- primitive has not been yet overridden or if the parent is a generic
15541 -- formal type covering interfaces.
15543 -- If the tagged type is not abstract, it cannot have abstract
15544 -- primitives (the only entities in the list of primitives of
15545 -- non-abstract tagged types that can reference abstract primitives
15546 -- through its Alias attribute are the internal entities that have
15547 -- attribute Interface_Alias, and these entities are generated later
15548 -- by Add_Internal_Interface_Entities).
15550 if In_Private_Part
(Current_Scope
)
15551 and then (Is_Abstract_Type
(Parent_Type
)
15553 Is_Generic_Type
(Parent_Type
))
15555 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
15556 while Present
(Elmt
) loop
15557 Subp
:= Node
(Elmt
);
15559 -- At this stage it is not possible to have entities in the list
15560 -- of primitives that have attribute Interface_Alias.
15562 pragma Assert
(No
(Interface_Alias
(Subp
)));
15564 Typ
:= Find_Dispatching_Type
(Ultimate_Alias
(Subp
));
15566 if Is_Interface
(Typ
) then
15567 E
:= Find_Primitive_Covering_Interface
15568 (Tagged_Type
=> Tagged_Type
,
15569 Iface_Prim
=> Subp
);
15572 and then Find_Dispatching_Type
(Ultimate_Alias
(E
)) /= Typ
15574 Replace_Elmt
(Elmt
, E
);
15575 Remove_Homonym
(Subp
);
15583 -- Step 2: Add primitives of progenitors that are not implemented by
15584 -- parents of Tagged_Type.
15586 if Present
(Interfaces
(Base_Type
(Tagged_Type
))) then
15587 Iface_Elmt
:= First_Elmt
(Interfaces
(Base_Type
(Tagged_Type
)));
15588 while Present
(Iface_Elmt
) loop
15589 Iface
:= Node
(Iface_Elmt
);
15591 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
15592 while Present
(Prim_Elmt
) loop
15593 Iface_Subp
:= Node
(Prim_Elmt
);
15594 Iface_Alias
:= Ultimate_Alias
(Iface_Subp
);
15596 -- Exclude derivation of predefined primitives except those
15597 -- that come from source, or are inherited from one that comes
15598 -- from source. Required to catch declarations of equality
15599 -- operators of interfaces. For example:
15601 -- type Iface is interface;
15602 -- function "=" (Left, Right : Iface) return Boolean;
15604 if not Is_Predefined_Dispatching_Operation
(Iface_Subp
)
15605 or else Comes_From_Source
(Iface_Alias
)
15608 Find_Primitive_Covering_Interface
15609 (Tagged_Type
=> Tagged_Type
,
15610 Iface_Prim
=> Iface_Subp
);
15612 -- If not found we derive a new primitive leaving its alias
15613 -- attribute referencing the interface primitive.
15617 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15619 -- Ada 2012 (AI05-0197): If the covering primitive's name
15620 -- differs from the name of the interface primitive then it
15621 -- is a private primitive inherited from a parent type. In
15622 -- such case, given that Tagged_Type covers the interface,
15623 -- the inherited private primitive becomes visible. For such
15624 -- purpose we add a new entity that renames the inherited
15625 -- private primitive.
15627 elsif Chars
(E
) /= Chars
(Iface_Subp
) then
15628 pragma Assert
(Has_Suffix
(E
, 'P'));
15630 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15631 Set_Alias
(New_Subp
, E
);
15632 Set_Is_Abstract_Subprogram
(New_Subp
,
15633 Is_Abstract_Subprogram
(E
));
15635 -- Propagate to the full view interface entities associated
15636 -- with the partial view.
15638 elsif In_Private_Part
(Current_Scope
)
15639 and then Present
(Alias
(E
))
15640 and then Alias
(E
) = Iface_Subp
15642 List_Containing
(Parent
(E
)) /=
15643 Private_Declarations
15645 (Unit_Declaration_Node
(Current_Scope
)))
15647 Append_Elmt
(E
, Primitive_Operations
(Tagged_Type
));
15651 Next_Elmt
(Prim_Elmt
);
15654 Next_Elmt
(Iface_Elmt
);
15657 end Derive_Progenitor_Subprograms
;
15659 -----------------------
15660 -- Derive_Subprogram --
15661 -----------------------
15663 procedure Derive_Subprogram
15664 (New_Subp
: out Entity_Id
;
15665 Parent_Subp
: Entity_Id
;
15666 Derived_Type
: Entity_Id
;
15667 Parent_Type
: Entity_Id
;
15668 Actual_Subp
: Entity_Id
:= Empty
)
15670 Formal
: Entity_Id
;
15671 -- Formal parameter of parent primitive operation
15673 Formal_Of_Actual
: Entity_Id
;
15674 -- Formal parameter of actual operation, when the derivation is to
15675 -- create a renaming for a primitive operation of an actual in an
15678 New_Formal
: Entity_Id
;
15679 -- Formal of inherited operation
15681 Visible_Subp
: Entity_Id
:= Parent_Subp
;
15683 function Is_Private_Overriding
return Boolean;
15684 -- If Subp is a private overriding of a visible operation, the inherited
15685 -- operation derives from the overridden op (even though its body is the
15686 -- overriding one) and the inherited operation is visible now. See
15687 -- sem_disp to see the full details of the handling of the overridden
15688 -- subprogram, which is removed from the list of primitive operations of
15689 -- the type. The overridden subprogram is saved locally in Visible_Subp,
15690 -- and used to diagnose abstract operations that need overriding in the
15693 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
15694 -- When the type is an anonymous access type, create a new access type
15695 -- designating the derived type.
15697 procedure Set_Derived_Name
;
15698 -- This procedure sets the appropriate Chars name for New_Subp. This
15699 -- is normally just a copy of the parent name. An exception arises for
15700 -- type support subprograms, where the name is changed to reflect the
15701 -- name of the derived type, e.g. if type foo is derived from type bar,
15702 -- then a procedure barDA is derived with a name fooDA.
15704 ---------------------------
15705 -- Is_Private_Overriding --
15706 ---------------------------
15708 function Is_Private_Overriding
return Boolean is
15712 -- If the parent is not a dispatching operation there is no
15713 -- need to investigate overridings
15715 if not Is_Dispatching_Operation
(Parent_Subp
) then
15719 -- The visible operation that is overridden is a homonym of the
15720 -- parent subprogram. We scan the homonym chain to find the one
15721 -- whose alias is the subprogram we are deriving.
15723 Prev
:= Current_Entity
(Parent_Subp
);
15724 while Present
(Prev
) loop
15725 if Ekind
(Prev
) = Ekind
(Parent_Subp
)
15726 and then Alias
(Prev
) = Parent_Subp
15727 and then Scope
(Parent_Subp
) = Scope
(Prev
)
15728 and then not Is_Hidden
(Prev
)
15730 Visible_Subp
:= Prev
;
15734 Prev
:= Homonym
(Prev
);
15738 end Is_Private_Overriding
;
15744 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
15745 Id_Type
: constant Entity_Id
:= Etype
(Id
);
15746 Acc_Type
: Entity_Id
;
15747 Par
: constant Node_Id
:= Parent
(Derived_Type
);
15750 -- When the type is an anonymous access type, create a new access
15751 -- type designating the derived type. This itype must be elaborated
15752 -- at the point of the derivation, not on subsequent calls that may
15753 -- be out of the proper scope for Gigi, so we insert a reference to
15754 -- it after the derivation.
15756 if Ekind
(Id_Type
) = E_Anonymous_Access_Type
then
15758 Desig_Typ
: Entity_Id
:= Designated_Type
(Id_Type
);
15761 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
15762 and then Present
(Full_View
(Desig_Typ
))
15763 and then not Is_Private_Type
(Parent_Type
)
15765 Desig_Typ
:= Full_View
(Desig_Typ
);
15768 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
)
15770 -- Ada 2005 (AI-251): Handle also derivations of abstract
15771 -- interface primitives.
15773 or else (Is_Interface
(Desig_Typ
)
15774 and then not Is_Class_Wide_Type
(Desig_Typ
))
15776 Acc_Type
:= New_Copy
(Id_Type
);
15777 Set_Etype
(Acc_Type
, Acc_Type
);
15778 Set_Scope
(Acc_Type
, New_Subp
);
15780 -- Set size of anonymous access type. If we have an access
15781 -- to an unconstrained array, this is a fat pointer, so it
15782 -- is sizes at twice addtress size.
15784 if Is_Array_Type
(Desig_Typ
)
15785 and then not Is_Constrained
(Desig_Typ
)
15787 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
15789 -- Other cases use a thin pointer
15792 Init_Size
(Acc_Type
, System_Address_Size
);
15795 -- Set remaining characterstics of anonymous access type
15797 Reinit_Alignment
(Acc_Type
);
15798 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
15800 Set_Etype
(New_Id
, Acc_Type
);
15801 Set_Scope
(New_Id
, New_Subp
);
15803 -- Create a reference to it
15805 Build_Itype_Reference
(Acc_Type
, Parent
(Derived_Type
));
15808 Set_Etype
(New_Id
, Id_Type
);
15812 -- In Ada2012, a formal may have an incomplete type but the type
15813 -- derivation that inherits the primitive follows the full view.
15815 elsif Base_Type
(Id_Type
) = Base_Type
(Parent_Type
)
15817 (Ekind
(Id_Type
) = E_Record_Type_With_Private
15818 and then Present
(Full_View
(Id_Type
))
15820 Base_Type
(Full_View
(Id_Type
)) = Base_Type
(Parent_Type
))
15822 (Ada_Version
>= Ada_2012
15823 and then Ekind
(Id_Type
) = E_Incomplete_Type
15824 and then Full_View
(Id_Type
) = Parent_Type
)
15826 -- Constraint checks on formals are generated during expansion,
15827 -- based on the signature of the original subprogram. The bounds
15828 -- of the derived type are not relevant, and thus we can use
15829 -- the base type for the formals. However, the return type may be
15830 -- used in a context that requires that the proper static bounds
15831 -- be used (a case statement, for example) and for those cases
15832 -- we must use the derived type (first subtype), not its base.
15834 -- If the derived_type_definition has no constraints, we know that
15835 -- the derived type has the same constraints as the first subtype
15836 -- of the parent, and we can also use it rather than its base,
15837 -- which can lead to more efficient code.
15839 if Etype
(Id
) = Parent_Type
then
15840 if Is_Scalar_Type
(Parent_Type
)
15842 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
15844 Set_Etype
(New_Id
, Derived_Type
);
15846 elsif Nkind
(Par
) = N_Full_Type_Declaration
15848 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
15851 (Subtype_Indication
(Type_Definition
(Par
)))
15853 Set_Etype
(New_Id
, Derived_Type
);
15856 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
15860 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
15864 Set_Etype
(New_Id
, Etype
(Id
));
15868 ----------------------
15869 -- Set_Derived_Name --
15870 ----------------------
15872 procedure Set_Derived_Name
is
15873 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
15875 if Nm
= TSS_Null
then
15876 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
15878 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
15880 end Set_Derived_Name
;
15882 -- Start of processing for Derive_Subprogram
15885 New_Subp
:= New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
15886 Mutate_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
15888 -- Check whether the inherited subprogram is a private operation that
15889 -- should be inherited but not yet made visible. Such subprograms can
15890 -- become visible at a later point (e.g., the private part of a public
15891 -- child unit) via Declare_Inherited_Private_Subprograms. If the
15892 -- following predicate is true, then this is not such a private
15893 -- operation and the subprogram simply inherits the name of the parent
15894 -- subprogram. Note the special check for the names of controlled
15895 -- operations, which are currently exempted from being inherited with
15896 -- a hidden name because they must be findable for generation of
15897 -- implicit run-time calls.
15899 if not Is_Hidden
(Parent_Subp
)
15900 or else Is_Internal
(Parent_Subp
)
15901 or else Is_Private_Overriding
15902 or else Is_Internal_Name
(Chars
(Parent_Subp
))
15903 or else (Is_Controlled
(Parent_Type
)
15904 and then Chars
(Parent_Subp
) in Name_Adjust
15910 -- An inherited dispatching equality will be overridden by an internally
15911 -- generated one, or by an explicit one, so preserve its name and thus
15912 -- its entry in the dispatch table. Otherwise, if Parent_Subp is a
15913 -- private operation it may become invisible if the full view has
15914 -- progenitors, and the dispatch table will be malformed.
15915 -- We check that the type is limited to handle the anomalous declaration
15916 -- of Limited_Controlled, which is derived from a non-limited type, and
15917 -- which is handled specially elsewhere as well.
15919 elsif Chars
(Parent_Subp
) = Name_Op_Eq
15920 and then Is_Dispatching_Operation
(Parent_Subp
)
15921 and then Etype
(Parent_Subp
) = Standard_Boolean
15922 and then not Is_Limited_Type
(Etype
(First_Formal
(Parent_Subp
)))
15924 Etype
(First_Formal
(Parent_Subp
)) =
15925 Etype
(Next_Formal
(First_Formal
(Parent_Subp
)))
15929 -- If parent is hidden, this can be a regular derivation if the
15930 -- parent is immediately visible in a non-instantiating context,
15931 -- or if we are in the private part of an instance. This test
15932 -- should still be refined ???
15934 -- The test for In_Instance_Not_Visible avoids inheriting the derived
15935 -- operation as a non-visible operation in cases where the parent
15936 -- subprogram might not be visible now, but was visible within the
15937 -- original generic, so it would be wrong to make the inherited
15938 -- subprogram non-visible now. (Not clear if this test is fully
15939 -- correct; are there any cases where we should declare the inherited
15940 -- operation as not visible to avoid it being overridden, e.g., when
15941 -- the parent type is a generic actual with private primitives ???)
15943 -- (they should be treated the same as other private inherited
15944 -- subprograms, but it's not clear how to do this cleanly). ???
15946 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
15947 and then Is_Immediately_Visible
(Parent_Subp
)
15948 and then not In_Instance
)
15949 or else In_Instance_Not_Visible
15953 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
15954 -- overrides an interface primitive because interface primitives
15955 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
15957 elsif Ada_Version
>= Ada_2005
15958 and then Is_Dispatching_Operation
(Parent_Subp
)
15959 and then Present
(Covered_Interface_Op
(Parent_Subp
))
15963 -- Otherwise, the type is inheriting a private operation, so enter it
15964 -- with a special name so it can't be overridden. See also below, where
15965 -- we check for this case, and if so avoid setting Requires_Overriding.
15968 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
15971 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
15973 if Present
(Actual_Subp
) then
15974 Replace_Type
(Actual_Subp
, New_Subp
);
15976 Replace_Type
(Parent_Subp
, New_Subp
);
15979 Conditional_Delay
(New_Subp
, Parent_Subp
);
15981 -- If we are creating a renaming for a primitive operation of an
15982 -- actual of a generic derived type, we must examine the signature
15983 -- of the actual primitive, not that of the generic formal, which for
15984 -- example may be an interface. However the name and initial value
15985 -- of the inherited operation are those of the formal primitive.
15987 Formal
:= First_Formal
(Parent_Subp
);
15989 if Present
(Actual_Subp
) then
15990 Formal_Of_Actual
:= First_Formal
(Actual_Subp
);
15992 Formal_Of_Actual
:= Empty
;
15995 while Present
(Formal
) loop
15996 New_Formal
:= New_Copy
(Formal
);
15998 -- Extra formals are not inherited from a limited interface parent
15999 -- since limitedness is not inherited in such case (AI-419) and this
16000 -- affects the extra formals.
16002 if Is_Limited_Interface
(Parent_Type
) then
16003 Set_Extra_Formal
(New_Formal
, Empty
);
16004 Set_Extra_Accessibility
(New_Formal
, Empty
);
16007 -- Normally we do not go copying parents, but in the case of
16008 -- formals, we need to link up to the declaration (which is the
16009 -- parameter specification), and it is fine to link up to the
16010 -- original formal's parameter specification in this case.
16012 Set_Parent
(New_Formal
, Parent
(Formal
));
16013 Append_Entity
(New_Formal
, New_Subp
);
16015 if Present
(Formal_Of_Actual
) then
16016 Replace_Type
(Formal_Of_Actual
, New_Formal
);
16017 Next_Formal
(Formal_Of_Actual
);
16019 Replace_Type
(Formal
, New_Formal
);
16022 Next_Formal
(Formal
);
16025 -- Extra formals are shared between the parent subprogram and the
16026 -- derived subprogram (implicit in the above copy of formals), unless
16027 -- the parent type is a limited interface type; hence we must inherit
16028 -- also the reference to the first extra formal. When the parent type is
16029 -- an interface the extra formals will be added when the subprogram is
16030 -- frozen (see Freeze.Freeze_Subprogram).
16032 if not Is_Limited_Interface
(Parent_Type
) then
16033 Set_Extra_Formals
(New_Subp
, Extra_Formals
(Parent_Subp
));
16035 if Ekind
(New_Subp
) = E_Function
then
16036 Set_Extra_Accessibility_Of_Result
(New_Subp
,
16037 Extra_Accessibility_Of_Result
(Parent_Subp
));
16041 -- If this derivation corresponds to a tagged generic actual, then
16042 -- primitive operations rename those of the actual. Otherwise the
16043 -- primitive operations rename those of the parent type, If the parent
16044 -- renames an intrinsic operator, so does the new subprogram. We except
16045 -- concatenation, which is always properly typed, and does not get
16046 -- expanded as other intrinsic operations.
16048 if No
(Actual_Subp
) then
16049 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
16050 Set_Is_Intrinsic_Subprogram
(New_Subp
);
16052 if Present
(Alias
(Parent_Subp
))
16053 and then Chars
(Parent_Subp
) /= Name_Op_Concat
16055 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
16057 Set_Alias
(New_Subp
, Parent_Subp
);
16061 Set_Alias
(New_Subp
, Parent_Subp
);
16065 Set_Alias
(New_Subp
, Actual_Subp
);
16068 -- Derived subprograms of a tagged type must inherit the convention
16069 -- of the parent subprogram (a requirement of AI-117). Derived
16070 -- subprograms of untagged types simply get convention Ada by default.
16072 -- If the derived type is a tagged generic formal type with unknown
16073 -- discriminants, its convention is intrinsic (RM 6.3.1 (8)).
16075 -- However, if the type is derived from a generic formal, the further
16076 -- inherited subprogram has the convention of the non-generic ancestor.
16077 -- Otherwise there would be no way to override the operation.
16078 -- (This is subject to forthcoming ARG discussions).
16080 if Is_Tagged_Type
(Derived_Type
) then
16081 if Is_Generic_Type
(Derived_Type
)
16082 and then Has_Unknown_Discriminants
(Derived_Type
)
16084 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16087 if Is_Generic_Type
(Parent_Type
)
16088 and then Has_Unknown_Discriminants
(Parent_Type
)
16090 Set_Convention
(New_Subp
, Convention
(Alias
(Parent_Subp
)));
16092 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
16097 -- Predefined controlled operations retain their name even if the parent
16098 -- is hidden (see above), but they are not primitive operations if the
16099 -- ancestor is not visible, for example if the parent is a private
16100 -- extension completed with a controlled extension. Note that a full
16101 -- type that is controlled can break privacy: the flag Is_Controlled is
16102 -- set on both views of the type.
16104 if Is_Controlled
(Parent_Type
)
16105 and then Chars
(Parent_Subp
) in Name_Initialize
16108 and then Is_Hidden
(Parent_Subp
)
16109 and then not Is_Visibly_Controlled
(Parent_Type
)
16111 Set_Is_Hidden
(New_Subp
);
16114 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
16115 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
16117 if Ekind
(Parent_Subp
) = E_Procedure
then
16118 Set_Is_Valued_Procedure
16119 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
16121 Set_Has_Controlling_Result
16122 (New_Subp
, Has_Controlling_Result
(Parent_Subp
));
16125 -- No_Return must be inherited properly. If this is overridden in the
16126 -- case of a dispatching operation, then the check is made later in
16127 -- Check_Abstract_Overriding that the overriding operation is also
16128 -- No_Return (no such check is required for the nondispatching case).
16130 Set_No_Return
(New_Subp
, No_Return
(Parent_Subp
));
16132 -- If the parent subprogram is marked as Ghost, then so is the derived
16133 -- subprogram. The ghost policy for the derived subprogram is set from
16134 -- the effective ghost policy at the point of derived type declaration.
16136 if Is_Ghost_Entity
(Parent_Subp
) then
16137 Set_Is_Ghost_Entity
(New_Subp
);
16140 -- A derived function with a controlling result is abstract. If the
16141 -- Derived_Type is a nonabstract formal generic derived type, then
16142 -- inherited operations are not abstract: the required check is done at
16143 -- instantiation time. If the derivation is for a generic actual, the
16144 -- function is not abstract unless the actual is.
16146 if Is_Generic_Type
(Derived_Type
)
16147 and then not Is_Abstract_Type
(Derived_Type
)
16151 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
16152 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2). Note
16153 -- that functions with controlling access results of record extensions
16154 -- with a null extension part require overriding (AI95-00391/06).
16156 -- Ada 2022 (AI12-0042): Similarly, set those properties for
16157 -- implementing the rule of RM 7.3.2(6.1/4).
16159 -- A subprogram subject to pragma Extensions_Visible with value False
16160 -- requires overriding if the subprogram has at least one controlling
16161 -- OUT parameter (SPARK RM 6.1.7(6)).
16163 elsif Ada_Version
>= Ada_2005
16164 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16165 or else (Is_Tagged_Type
(Derived_Type
)
16166 and then Etype
(New_Subp
) = Derived_Type
16167 and then not Is_Null_Extension
(Derived_Type
))
16168 or else (Is_Tagged_Type
(Derived_Type
)
16169 and then Ekind
(Etype
(New_Subp
)) =
16170 E_Anonymous_Access_Type
16171 and then Designated_Type
(Etype
(New_Subp
)) =
16173 or else (Comes_From_Source
(Alias
(New_Subp
))
16174 and then Is_EVF_Procedure
(Alias
(New_Subp
)))
16176 -- AI12-0042: Set Requires_Overriding when a type extension
16177 -- inherits a private operation that is visible at the
16178 -- point of extension (Has_Private_Ancestor is False) from
16179 -- an ancestor that has Type_Invariant'Class, and when the
16180 -- type extension is in a visible part (the latter as
16181 -- clarified by AI12-0382).
16184 (not Has_Private_Ancestor
(Derived_Type
)
16185 and then Has_Invariants
(Parent_Type
)
16187 Present
(Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16190 (Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16191 and then Is_Private_Primitive
(Parent_Subp
)
16192 and then In_Visible_Part
(Scope
(Derived_Type
))))
16194 and then No
(Actual_Subp
)
16196 if not Is_Tagged_Type
(Derived_Type
)
16197 or else Is_Abstract_Type
(Derived_Type
)
16198 or else Is_Abstract_Subprogram
(Alias
(New_Subp
))
16200 Set_Is_Abstract_Subprogram
(New_Subp
);
16202 -- If the Chars of the new subprogram is different from that of the
16203 -- parent's one, it means that we entered it with a special name so
16204 -- it can't be overridden (see above). In that case we had better not
16205 -- *require* it to be overridden. This is the case where the parent
16206 -- type inherited the operation privately, so there's no danger of
16207 -- dangling dispatching.
16209 elsif Chars
(New_Subp
) = Chars
(Alias
(New_Subp
)) then
16210 Set_Requires_Overriding
(New_Subp
);
16213 elsif Ada_Version
< Ada_2005
16214 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16215 or else (Is_Tagged_Type
(Derived_Type
)
16216 and then Etype
(New_Subp
) = Derived_Type
16217 and then No
(Actual_Subp
)))
16219 Set_Is_Abstract_Subprogram
(New_Subp
);
16221 -- AI05-0097 : an inherited operation that dispatches on result is
16222 -- abstract if the derived type is abstract, even if the parent type
16223 -- is concrete and the derived type is a null extension.
16225 elsif Has_Controlling_Result
(Alias
(New_Subp
))
16226 and then Is_Abstract_Type
(Etype
(New_Subp
))
16228 Set_Is_Abstract_Subprogram
(New_Subp
);
16230 -- Finally, if the parent type is abstract we must verify that all
16231 -- inherited operations are either non-abstract or overridden, or that
16232 -- the derived type itself is abstract (this check is performed at the
16233 -- end of a package declaration, in Check_Abstract_Overriding). A
16234 -- private overriding in the parent type will not be visible in the
16235 -- derivation if we are not in an inner package or in a child unit of
16236 -- the parent type, in which case the abstractness of the inherited
16237 -- operation is carried to the new subprogram.
16239 elsif Is_Abstract_Type
(Parent_Type
)
16240 and then not In_Open_Scopes
(Scope
(Parent_Type
))
16241 and then Is_Private_Overriding
16242 and then Is_Abstract_Subprogram
(Visible_Subp
)
16244 if No
(Actual_Subp
) then
16245 Set_Alias
(New_Subp
, Visible_Subp
);
16246 Set_Is_Abstract_Subprogram
(New_Subp
, True);
16249 -- If this is a derivation for an instance of a formal derived
16250 -- type, abstractness comes from the primitive operation of the
16251 -- actual, not from the operation inherited from the ancestor.
16253 Set_Is_Abstract_Subprogram
16254 (New_Subp
, Is_Abstract_Subprogram
(Actual_Subp
));
16258 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
16260 -- Ada RM 6.1.1 (15): If a subprogram inherits nonconforming class-wide
16261 -- preconditions and the derived type is abstract, the derived operation
16262 -- is abstract as well if parent subprogram is not abstract or null.
16264 if Is_Abstract_Type
(Derived_Type
)
16265 and then Has_Non_Trivial_Precondition
(Parent_Subp
)
16266 and then Present
(Interfaces
(Derived_Type
))
16269 -- Add useful attributes of subprogram before the freeze point,
16270 -- in case freezing is delayed or there are previous errors.
16272 Set_Is_Dispatching_Operation
(New_Subp
);
16275 Iface_Prim
: constant Entity_Id
:= Covered_Interface_Op
(New_Subp
);
16278 if Present
(Iface_Prim
)
16279 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
16281 Set_Is_Abstract_Subprogram
(New_Subp
);
16286 -- Check for case of a derived subprogram for the instantiation of a
16287 -- formal derived tagged type, if so mark the subprogram as dispatching
16288 -- and inherit the dispatching attributes of the actual subprogram. The
16289 -- derived subprogram is effectively renaming of the actual subprogram,
16290 -- so it needs to have the same attributes as the actual.
16292 if Present
(Actual_Subp
)
16293 and then Is_Dispatching_Operation
(Actual_Subp
)
16295 Set_Is_Dispatching_Operation
(New_Subp
);
16297 if Present
(DTC_Entity
(Actual_Subp
)) then
16298 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Actual_Subp
));
16299 Set_DT_Position_Value
(New_Subp
, DT_Position
(Actual_Subp
));
16303 -- Indicate that a derived subprogram does not require a body and that
16304 -- it does not require processing of default expressions.
16306 Set_Has_Completion
(New_Subp
);
16307 Set_Default_Expressions_Processed
(New_Subp
);
16309 if Ekind
(New_Subp
) = E_Function
then
16310 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
16313 -- Ada 2022 (AI12-0279): If a Yield aspect is specified True for a
16314 -- primitive subprogram S of a type T, then the aspect is inherited
16315 -- by the corresponding primitive subprogram of each descendant of T.
16317 if Is_Tagged_Type
(Derived_Type
)
16318 and then Is_Dispatching_Operation
(New_Subp
)
16319 and then Has_Yield_Aspect
(Alias
(New_Subp
))
16321 Set_Has_Yield_Aspect
(New_Subp
, Has_Yield_Aspect
(Alias
(New_Subp
)));
16324 Set_Is_Ada_2022_Only
(New_Subp
, Is_Ada_2022_Only
(Parent_Subp
));
16325 end Derive_Subprogram
;
16327 ------------------------
16328 -- Derive_Subprograms --
16329 ------------------------
16331 procedure Derive_Subprograms
16332 (Parent_Type
: Entity_Id
;
16333 Derived_Type
: Entity_Id
;
16334 Generic_Actual
: Entity_Id
:= Empty
)
16336 Op_List
: constant Elist_Id
:=
16337 Collect_Primitive_Operations
(Parent_Type
);
16339 function Check_Derived_Type
return Boolean;
16340 -- Check that all the entities derived from Parent_Type are found in
16341 -- the list of primitives of Derived_Type exactly in the same order.
16343 procedure Derive_Interface_Subprogram
16344 (New_Subp
: out Entity_Id
;
16346 Actual_Subp
: Entity_Id
);
16347 -- Derive New_Subp from the ultimate alias of the parent subprogram Subp
16348 -- (which is an interface primitive). If Generic_Actual is present then
16349 -- Actual_Subp is the actual subprogram corresponding with the generic
16350 -- subprogram Subp.
16352 ------------------------
16353 -- Check_Derived_Type --
16354 ------------------------
16356 function Check_Derived_Type
return Boolean is
16360 New_Subp
: Entity_Id
;
16365 -- Traverse list of entities in the current scope searching for
16366 -- an incomplete type whose full-view is derived type.
16368 E
:= First_Entity
(Scope
(Derived_Type
));
16369 while Present
(E
) and then E
/= Derived_Type
loop
16370 if Ekind
(E
) = E_Incomplete_Type
16371 and then Present
(Full_View
(E
))
16372 and then Full_View
(E
) = Derived_Type
16374 -- Disable this test if Derived_Type completes an incomplete
16375 -- type because in such case more primitives can be added
16376 -- later to the list of primitives of Derived_Type by routine
16377 -- Process_Incomplete_Dependents
16385 List
:= Collect_Primitive_Operations
(Derived_Type
);
16386 Elmt
:= First_Elmt
(List
);
16388 Op_Elmt
:= First_Elmt
(Op_List
);
16389 while Present
(Op_Elmt
) loop
16390 Subp
:= Node
(Op_Elmt
);
16391 New_Subp
:= Node
(Elmt
);
16393 -- At this early stage Derived_Type has no entities with attribute
16394 -- Interface_Alias. In addition, such primitives are always
16395 -- located at the end of the list of primitives of Parent_Type.
16396 -- Therefore, if found we can safely stop processing pending
16399 exit when Present
(Interface_Alias
(Subp
));
16401 -- Handle hidden entities
16403 if not Is_Predefined_Dispatching_Operation
(Subp
)
16404 and then Is_Hidden
(Subp
)
16406 if Present
(New_Subp
)
16407 and then Primitive_Names_Match
(Subp
, New_Subp
)
16413 if not Present
(New_Subp
)
16414 or else Ekind
(Subp
) /= Ekind
(New_Subp
)
16415 or else not Primitive_Names_Match
(Subp
, New_Subp
)
16423 Next_Elmt
(Op_Elmt
);
16427 end Check_Derived_Type
;
16429 ---------------------------------
16430 -- Derive_Interface_Subprogram --
16431 ---------------------------------
16433 procedure Derive_Interface_Subprogram
16434 (New_Subp
: out Entity_Id
;
16436 Actual_Subp
: Entity_Id
)
16438 Iface_Subp
: constant Entity_Id
:= Ultimate_Alias
(Subp
);
16439 Iface_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Iface_Subp
);
16442 pragma Assert
(Is_Interface
(Iface_Type
));
16445 (New_Subp
=> New_Subp
,
16446 Parent_Subp
=> Iface_Subp
,
16447 Derived_Type
=> Derived_Type
,
16448 Parent_Type
=> Iface_Type
,
16449 Actual_Subp
=> Actual_Subp
);
16451 -- Given that this new interface entity corresponds with a primitive
16452 -- of the parent that was not overridden we must leave it associated
16453 -- with its parent primitive to ensure that it will share the same
16454 -- dispatch table slot when overridden. We must set the Alias to Subp
16455 -- (instead of Iface_Subp), and we must fix Is_Abstract_Subprogram
16456 -- (in case we inherited Subp from Iface_Type via a nonabstract
16457 -- generic formal type).
16459 if No
(Actual_Subp
) then
16460 Set_Alias
(New_Subp
, Subp
);
16463 T
: Entity_Id
:= Find_Dispatching_Type
(Subp
);
16465 while Etype
(T
) /= T
loop
16466 if Is_Generic_Type
(T
) and then not Is_Abstract_Type
(T
) then
16467 Set_Is_Abstract_Subprogram
(New_Subp
, False);
16475 -- For instantiations this is not needed since the previous call to
16476 -- Derive_Subprogram leaves the entity well decorated.
16479 pragma Assert
(Alias
(New_Subp
) = Actual_Subp
);
16482 end Derive_Interface_Subprogram
;
16486 Alias_Subp
: Entity_Id
;
16487 Act_List
: Elist_Id
;
16488 Act_Elmt
: Elmt_Id
;
16489 Act_Subp
: Entity_Id
:= Empty
;
16491 Need_Search
: Boolean := False;
16492 New_Subp
: Entity_Id
:= Empty
;
16493 Parent_Base
: Entity_Id
;
16496 -- Start of processing for Derive_Subprograms
16499 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
16500 and then Has_Discriminants
(Parent_Type
)
16501 and then Present
(Full_View
(Parent_Type
))
16503 Parent_Base
:= Full_View
(Parent_Type
);
16505 Parent_Base
:= Parent_Type
;
16508 if Present
(Generic_Actual
) then
16509 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
16510 Act_Elmt
:= First_Elmt
(Act_List
);
16512 Act_List
:= No_Elist
;
16513 Act_Elmt
:= No_Elmt
;
16516 -- Derive primitives inherited from the parent. Note that if the generic
16517 -- actual is present, this is not really a type derivation, it is a
16518 -- completion within an instance.
16520 -- Case 1: Derived_Type does not implement interfaces
16522 if not Is_Tagged_Type
(Derived_Type
)
16523 or else (not Has_Interfaces
(Derived_Type
)
16524 and then not (Present
(Generic_Actual
)
16525 and then Has_Interfaces
(Generic_Actual
)))
16527 Elmt
:= First_Elmt
(Op_List
);
16528 while Present
(Elmt
) loop
16529 Subp
:= Node
(Elmt
);
16531 -- Literals are derived earlier in the process of building the
16532 -- derived type, and are skipped here.
16534 if Ekind
(Subp
) = E_Enumeration_Literal
then
16537 -- The actual is a direct descendant and the common primitive
16538 -- operations appear in the same order.
16540 -- If the generic parent type is present, the derived type is an
16541 -- instance of a formal derived type, and within the instance its
16542 -- operations are those of the actual. We derive from the formal
16543 -- type but make the inherited operations aliases of the
16544 -- corresponding operations of the actual.
16547 pragma Assert
(No
(Node
(Act_Elmt
))
16548 or else (Primitive_Names_Match
(Subp
, Node
(Act_Elmt
))
16551 (Subp
, Node
(Act_Elmt
),
16552 Skip_Controlling_Formals
=> True)));
16555 (New_Subp
, Subp
, Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
16557 if Present
(Act_Elmt
) then
16558 Next_Elmt
(Act_Elmt
);
16565 -- Case 2: Derived_Type implements interfaces
16568 -- If the parent type has no predefined primitives we remove
16569 -- predefined primitives from the list of primitives of generic
16570 -- actual to simplify the complexity of this algorithm.
16572 if Present
(Generic_Actual
) then
16574 Has_Predefined_Primitives
: Boolean := False;
16577 -- Check if the parent type has predefined primitives
16579 Elmt
:= First_Elmt
(Op_List
);
16580 while Present
(Elmt
) loop
16581 Subp
:= Node
(Elmt
);
16583 if Is_Predefined_Dispatching_Operation
(Subp
)
16584 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
16586 Has_Predefined_Primitives
:= True;
16593 -- Remove predefined primitives of Generic_Actual. We must use
16594 -- an auxiliary list because in case of tagged types the value
16595 -- returned by Collect_Primitive_Operations is the value stored
16596 -- in its Primitive_Operations attribute (and we don't want to
16597 -- modify its current contents).
16599 if not Has_Predefined_Primitives
then
16601 Aux_List
: constant Elist_Id
:= New_Elmt_List
;
16604 Elmt
:= First_Elmt
(Act_List
);
16605 while Present
(Elmt
) loop
16606 Subp
:= Node
(Elmt
);
16608 if not Is_Predefined_Dispatching_Operation
(Subp
)
16609 or else Comes_From_Source
(Subp
)
16611 Append_Elmt
(Subp
, Aux_List
);
16617 Act_List
:= Aux_List
;
16621 Act_Elmt
:= First_Elmt
(Act_List
);
16622 Act_Subp
:= Node
(Act_Elmt
);
16626 -- Stage 1: If the generic actual is not present we derive the
16627 -- primitives inherited from the parent type. If the generic parent
16628 -- type is present, the derived type is an instance of a formal
16629 -- derived type, and within the instance its operations are those of
16630 -- the actual. We derive from the formal type but make the inherited
16631 -- operations aliases of the corresponding operations of the actual.
16633 Elmt
:= First_Elmt
(Op_List
);
16634 while Present
(Elmt
) loop
16635 Subp
:= Node
(Elmt
);
16636 Alias_Subp
:= Ultimate_Alias
(Subp
);
16638 -- Do not derive internal entities of the parent that link
16639 -- interface primitives with their covering primitive. These
16640 -- entities will be added to this type when frozen.
16642 if Present
(Interface_Alias
(Subp
)) then
16646 -- If the generic actual is present find the corresponding
16647 -- operation in the generic actual. If the parent type is a
16648 -- direct ancestor of the derived type then, even if it is an
16649 -- interface, the operations are inherited from the primary
16650 -- dispatch table and are in the proper order. If we detect here
16651 -- that primitives are not in the same order we traverse the list
16652 -- of primitive operations of the actual to find the one that
16653 -- implements the interface primitive.
16657 (Present
(Generic_Actual
)
16658 and then Present
(Act_Subp
)
16660 (Primitive_Names_Match
(Subp
, Act_Subp
)
16662 Type_Conformant
(Subp
, Act_Subp
,
16663 Skip_Controlling_Formals
=> True)))
16665 pragma Assert
(not Is_Ancestor
(Parent_Base
, Generic_Actual
,
16666 Use_Full_View
=> True));
16668 -- Remember that we need searching for all pending primitives
16670 Need_Search
:= True;
16672 -- Handle entities associated with interface primitives
16674 if Present
(Alias_Subp
)
16675 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
16676 and then not Is_Predefined_Dispatching_Operation
(Subp
)
16678 -- Search for the primitive in the homonym chain
16681 Find_Primitive_Covering_Interface
16682 (Tagged_Type
=> Generic_Actual
,
16683 Iface_Prim
=> Alias_Subp
);
16685 -- Previous search may not locate primitives covering
16686 -- interfaces defined in generics units or instantiations.
16687 -- (it fails if the covering primitive has formals whose
16688 -- type is also defined in generics or instantiations).
16689 -- In such case we search in the list of primitives of the
16690 -- generic actual for the internal entity that links the
16691 -- interface primitive and the covering primitive.
16694 and then Is_Generic_Type
(Parent_Type
)
16696 -- This code has been designed to handle only generic
16697 -- formals that implement interfaces that are defined
16698 -- in a generic unit or instantiation. If this code is
16699 -- needed for other cases we must review it because
16700 -- (given that it relies on Original_Location to locate
16701 -- the primitive of Generic_Actual that covers the
16702 -- interface) it could leave linked through attribute
16703 -- Alias entities of unrelated instantiations).
16707 (Scope
(Find_Dispatching_Type
(Alias_Subp
)))
16709 Instantiation_Depth
16710 (Sloc
(Find_Dispatching_Type
(Alias_Subp
))) > 0);
16713 Iface_Prim_Loc
: constant Source_Ptr
:=
16714 Original_Location
(Sloc
(Alias_Subp
));
16721 First_Elmt
(Primitive_Operations
(Generic_Actual
));
16723 Search
: while Present
(Elmt
) loop
16724 Prim
:= Node
(Elmt
);
16726 if Present
(Interface_Alias
(Prim
))
16727 and then Original_Location
16728 (Sloc
(Interface_Alias
(Prim
))) =
16731 Act_Subp
:= Alias
(Prim
);
16740 pragma Assert
(Present
(Act_Subp
)
16741 or else Is_Abstract_Type
(Generic_Actual
)
16742 or else Serious_Errors_Detected
> 0);
16744 -- Handle predefined primitives plus the rest of user-defined
16748 Act_Elmt
:= First_Elmt
(Act_List
);
16749 while Present
(Act_Elmt
) loop
16750 Act_Subp
:= Node
(Act_Elmt
);
16752 exit when Primitive_Names_Match
(Subp
, Act_Subp
)
16753 and then Type_Conformant
16755 Skip_Controlling_Formals
=> True)
16756 and then No
(Interface_Alias
(Act_Subp
));
16758 Next_Elmt
(Act_Elmt
);
16761 if No
(Act_Elmt
) then
16767 -- Case 1: If the parent is a limited interface then it has the
16768 -- predefined primitives of synchronized interfaces. However, the
16769 -- actual type may be a non-limited type and hence it does not
16770 -- have such primitives.
16772 if Present
(Generic_Actual
)
16773 and then not Present
(Act_Subp
)
16774 and then Is_Limited_Interface
(Parent_Base
)
16775 and then Is_Predefined_Interface_Primitive
(Subp
)
16779 -- Case 2: Inherit entities associated with interfaces that were
16780 -- not covered by the parent type. We exclude here null interface
16781 -- primitives because they do not need special management.
16783 -- We also exclude interface operations that are renamings. If the
16784 -- subprogram is an explicit renaming of an interface primitive,
16785 -- it is a regular primitive operation, and the presence of its
16786 -- alias is not relevant: it has to be derived like any other
16789 elsif Present
(Alias
(Subp
))
16790 and then Nkind
(Unit_Declaration_Node
(Subp
)) /=
16791 N_Subprogram_Renaming_Declaration
16792 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
16794 (Nkind
(Parent
(Alias_Subp
)) = N_Procedure_Specification
16795 and then Null_Present
(Parent
(Alias_Subp
)))
16797 -- If this is an abstract private type then we transfer the
16798 -- derivation of the interface primitive from the partial view
16799 -- to the full view. This is safe because all the interfaces
16800 -- must be visible in the partial view. Done to avoid adding
16801 -- a new interface derivation to the private part of the
16802 -- enclosing package; otherwise this new derivation would be
16803 -- decorated as hidden when the analysis of the enclosing
16804 -- package completes.
16806 if Is_Abstract_Type
(Derived_Type
)
16807 and then In_Private_Part
(Current_Scope
)
16808 and then Has_Private_Declaration
(Derived_Type
)
16811 Partial_View
: Entity_Id
;
16816 Partial_View
:= First_Entity
(Current_Scope
);
16818 exit when No
(Partial_View
)
16819 or else (Has_Private_Declaration
(Partial_View
)
16821 Full_View
(Partial_View
) = Derived_Type
);
16823 Next_Entity
(Partial_View
);
16826 -- If the partial view was not found then the source code
16827 -- has errors and the derivation is not needed.
16829 if Present
(Partial_View
) then
16831 First_Elmt
(Primitive_Operations
(Partial_View
));
16832 while Present
(Elmt
) loop
16833 Ent
:= Node
(Elmt
);
16835 if Present
(Alias
(Ent
))
16836 and then Ultimate_Alias
(Ent
) = Alias
(Subp
)
16839 (Ent
, Primitive_Operations
(Derived_Type
));
16846 -- If the interface primitive was not found in the
16847 -- partial view then this interface primitive was
16848 -- overridden. We add a derivation to activate in
16849 -- Derive_Progenitor_Subprograms the machinery to
16853 Derive_Interface_Subprogram
16854 (New_Subp
=> New_Subp
,
16856 Actual_Subp
=> Act_Subp
);
16861 Derive_Interface_Subprogram
16862 (New_Subp
=> New_Subp
,
16864 Actual_Subp
=> Act_Subp
);
16867 -- Case 3: Common derivation
16871 (New_Subp
=> New_Subp
,
16872 Parent_Subp
=> Subp
,
16873 Derived_Type
=> Derived_Type
,
16874 Parent_Type
=> Parent_Base
,
16875 Actual_Subp
=> Act_Subp
);
16878 -- No need to update Act_Elm if we must search for the
16879 -- corresponding operation in the generic actual
16882 and then Present
(Act_Elmt
)
16884 Next_Elmt
(Act_Elmt
);
16885 Act_Subp
:= Node
(Act_Elmt
);
16892 -- Inherit additional operations from progenitors. If the derived
16893 -- type is a generic actual, there are not new primitive operations
16894 -- for the type because it has those of the actual, and therefore
16895 -- nothing needs to be done. The renamings generated above are not
16896 -- primitive operations, and their purpose is simply to make the
16897 -- proper operations visible within an instantiation.
16899 if No
(Generic_Actual
) then
16900 Derive_Progenitor_Subprograms
(Parent_Base
, Derived_Type
);
16904 -- Final check: Direct descendants must have their primitives in the
16905 -- same order. We exclude from this test untagged types and instances
16906 -- of formal derived types. We skip this test if we have already
16907 -- reported serious errors in the sources.
16909 pragma Assert
(not Is_Tagged_Type
(Derived_Type
)
16910 or else Present
(Generic_Actual
)
16911 or else Serious_Errors_Detected
> 0
16912 or else Check_Derived_Type
);
16913 end Derive_Subprograms
;
16915 --------------------------------
16916 -- Derived_Standard_Character --
16917 --------------------------------
16919 procedure Derived_Standard_Character
16921 Parent_Type
: Entity_Id
;
16922 Derived_Type
: Entity_Id
)
16924 Loc
: constant Source_Ptr
:= Sloc
(N
);
16925 Def
: constant Node_Id
:= Type_Definition
(N
);
16926 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
16927 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
16928 Implicit_Base
: constant Entity_Id
:=
16930 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
16936 Discard_Node
(Process_Subtype
(Indic
, N
));
16938 Set_Etype
(Implicit_Base
, Parent_Base
);
16939 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
16940 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
16942 Set_Is_Character_Type
(Implicit_Base
, True);
16943 Set_Has_Delayed_Freeze
(Implicit_Base
);
16945 -- The bounds of the implicit base are the bounds of the parent base.
16946 -- Note that their type is the parent base.
16948 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
16949 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
16951 Set_Scalar_Range
(Implicit_Base
,
16954 High_Bound
=> Hi
));
16956 Conditional_Delay
(Derived_Type
, Parent_Type
);
16958 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
16959 Set_Etype
(Derived_Type
, Implicit_Base
);
16960 Set_Size_Info
(Derived_Type
, Parent_Type
);
16962 if not Known_RM_Size
(Derived_Type
) then
16963 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
16966 Set_Is_Character_Type
(Derived_Type
, True);
16968 if Nkind
(Indic
) /= N_Subtype_Indication
then
16970 -- If no explicit constraint, the bounds are those
16971 -- of the parent type.
16973 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
16974 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
16975 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
16978 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
16980 -- Because the implicit base is used in the conversion of the bounds, we
16981 -- have to freeze it now. This is similar to what is done for numeric
16982 -- types, and it equally suspicious, but otherwise a nonstatic bound
16983 -- will have a reference to an unfrozen type, which is rejected by Gigi
16984 -- (???). This requires specific care for definition of stream
16985 -- attributes. For details, see comments at the end of
16986 -- Build_Derived_Numeric_Type.
16988 Freeze_Before
(N
, Implicit_Base
);
16989 end Derived_Standard_Character
;
16991 ------------------------------
16992 -- Derived_Type_Declaration --
16993 ------------------------------
16995 procedure Derived_Type_Declaration
16998 Is_Completion
: Boolean)
17000 Parent_Type
: Entity_Id
;
17002 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean;
17003 -- Check whether the parent type is a generic formal, or derives
17004 -- directly or indirectly from one.
17006 ------------------------
17007 -- Comes_From_Generic --
17008 ------------------------
17010 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean is
17012 if Is_Generic_Type
(Typ
) then
17015 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
17018 elsif Is_Private_Type
(Typ
)
17019 and then Present
(Full_View
(Typ
))
17020 and then Is_Generic_Type
(Root_Type
(Full_View
(Typ
)))
17024 elsif Is_Generic_Actual_Type
(Typ
) then
17030 end Comes_From_Generic
;
17034 Def
: constant Node_Id
:= Type_Definition
(N
);
17035 Iface_Def
: Node_Id
;
17036 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17037 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
17038 Parent_Node
: Node_Id
;
17041 -- Start of processing for Derived_Type_Declaration
17044 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
17047 and then Is_Tagged_Type
(Parent_Type
)
17050 Partial_View
: constant Entity_Id
:=
17051 Incomplete_Or_Partial_View
(Parent_Type
);
17054 -- If the partial view was not found then the parent type is not
17055 -- a private type. Otherwise check if the partial view is a tagged
17058 if Present
(Partial_View
)
17059 and then Is_Private_Type
(Partial_View
)
17060 and then not Is_Tagged_Type
(Partial_View
)
17063 ("cannot derive from & declared as untagged private "
17064 & "(SPARK RM 3.4(1))", N
, Partial_View
);
17069 -- Ada 2005 (AI-251): In case of interface derivation check that the
17070 -- parent is also an interface.
17072 if Interface_Present
(Def
) then
17073 if not Is_Interface
(Parent_Type
) then
17074 Diagnose_Interface
(Indic
, Parent_Type
);
17077 Parent_Node
:= Parent
(Base_Type
(Parent_Type
));
17078 Iface_Def
:= Type_Definition
(Parent_Node
);
17080 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
17081 -- other limited interfaces.
17083 if Limited_Present
(Def
) then
17084 if Limited_Present
(Iface_Def
) then
17087 elsif Protected_Present
(Iface_Def
) then
17089 ("descendant of & must be declared as a protected "
17090 & "interface", N
, Parent_Type
);
17092 elsif Synchronized_Present
(Iface_Def
) then
17094 ("descendant of & must be declared as a synchronized "
17095 & "interface", N
, Parent_Type
);
17097 elsif Task_Present
(Iface_Def
) then
17099 ("descendant of & must be declared as a task interface",
17104 ("(Ada 2005) limited interface cannot inherit from "
17105 & "non-limited interface", Indic
);
17108 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
17109 -- from non-limited or limited interfaces.
17111 elsif not Protected_Present
(Def
)
17112 and then not Synchronized_Present
(Def
)
17113 and then not Task_Present
(Def
)
17115 if Limited_Present
(Iface_Def
) then
17118 elsif Protected_Present
(Iface_Def
) then
17120 ("descendant of & must be declared as a protected "
17121 & "interface", N
, Parent_Type
);
17123 elsif Synchronized_Present
(Iface_Def
) then
17125 ("descendant of & must be declared as a synchronized "
17126 & "interface", N
, Parent_Type
);
17128 elsif Task_Present
(Iface_Def
) then
17130 ("descendant of & must be declared as a task interface",
17139 if Is_Tagged_Type
(Parent_Type
)
17140 and then Is_Concurrent_Type
(Parent_Type
)
17141 and then not Is_Interface
(Parent_Type
)
17144 ("parent type of a record extension cannot be a synchronized "
17145 & "tagged type (RM 3.9.1 (3/1))", N
);
17146 Set_Etype
(T
, Any_Type
);
17150 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
17153 if Is_Tagged_Type
(Parent_Type
)
17154 and then Is_Non_Empty_List
(Interface_List
(Def
))
17161 Intf
:= First
(Interface_List
(Def
));
17162 while Present
(Intf
) loop
17163 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
17165 if not Is_Interface
(T
) then
17166 Diagnose_Interface
(Intf
, T
);
17168 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
17169 -- a limited type from having a nonlimited progenitor.
17171 elsif (Limited_Present
(Def
)
17172 or else (not Is_Interface
(Parent_Type
)
17173 and then Is_Limited_Type
(Parent_Type
)))
17174 and then not Is_Limited_Interface
(T
)
17177 ("progenitor interface& of limited type must be limited",
17185 -- Check consistency of any nonoverridable aspects that are
17186 -- inherited from multiple sources.
17188 Check_Inherited_Nonoverridable_Aspects
17190 Interface_List
=> Interface_List
(Def
),
17191 Parent_Type
=> Parent_Type
);
17194 if Parent_Type
= Any_Type
17195 or else Etype
(Parent_Type
) = Any_Type
17196 or else (Is_Class_Wide_Type
(Parent_Type
)
17197 and then Etype
(Parent_Type
) = T
)
17199 -- If Parent_Type is undefined or illegal, make new type into a
17200 -- subtype of Any_Type, and set a few attributes to prevent cascaded
17201 -- errors. If this is a self-definition, emit error now.
17203 if T
= Parent_Type
or else T
= Etype
(Parent_Type
) then
17204 Error_Msg_N
("type cannot be used in its own definition", Indic
);
17207 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
17208 Set_Etype
(T
, Any_Type
);
17209 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
17211 -- For tagged types, or when prefixed-call syntax is allowed for
17212 -- untagged types, initialize the list of primitive operations to
17215 if (Is_Tagged_Type
(T
) and then Is_Record_Type
(T
))
17216 or else Extensions_Allowed
17218 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
17224 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
17225 -- an interface is special because the list of interfaces in the full
17226 -- view can be given in any order. For example:
17228 -- type A is interface;
17229 -- type B is interface and A;
17230 -- type D is new B with private;
17232 -- type D is new A and B with null record; -- 1 --
17234 -- In this case we perform the following transformation of -1-:
17236 -- type D is new B and A with null record;
17238 -- If the parent of the full-view covers the parent of the partial-view
17239 -- we have two possible cases:
17241 -- 1) They have the same parent
17242 -- 2) The parent of the full-view implements some further interfaces
17244 -- In both cases we do not need to perform the transformation. In the
17245 -- first case the source program is correct and the transformation is
17246 -- not needed; in the second case the source program does not fulfill
17247 -- the no-hidden interfaces rule (AI-396) and the error will be reported
17250 -- This transformation not only simplifies the rest of the analysis of
17251 -- this type declaration but also simplifies the correct generation of
17252 -- the object layout to the expander.
17254 if In_Private_Part
(Current_Scope
)
17255 and then Is_Interface
(Parent_Type
)
17259 Partial_View
: Entity_Id
;
17260 Partial_View_Parent
: Entity_Id
;
17261 New_Iface
: Node_Id
;
17264 -- Look for the associated private type declaration
17266 Partial_View
:= Incomplete_Or_Partial_View
(T
);
17268 -- If the partial view was not found then the source code has
17269 -- errors and the transformation is not needed.
17271 if Present
(Partial_View
) then
17272 Partial_View_Parent
:= Etype
(Partial_View
);
17274 -- If the parent of the full-view covers the parent of the
17275 -- partial-view we have nothing else to do.
17277 if Interface_Present_In_Ancestor
17278 (Parent_Type
, Partial_View_Parent
)
17282 -- Traverse the list of interfaces of the full-view to look
17283 -- for the parent of the partial-view and perform the tree
17287 Iface
:= First
(Interface_List
(Def
));
17288 while Present
(Iface
) loop
17289 if Etype
(Iface
) = Etype
(Partial_View
) then
17290 Rewrite
(Subtype_Indication
(Def
),
17291 New_Copy
(Subtype_Indication
17292 (Parent
(Partial_View
))));
17295 Make_Identifier
(Sloc
(N
), Chars
(Parent_Type
));
17296 Append
(New_Iface
, Interface_List
(Def
));
17298 -- Analyze the transformed code
17300 Derived_Type_Declaration
(T
, N
, Is_Completion
);
17311 -- Only composite types other than array types are allowed to have
17314 if Present
(Discriminant_Specifications
(N
)) then
17315 if (Is_Elementary_Type
(Parent_Type
)
17317 Is_Array_Type
(Parent_Type
))
17318 and then not Error_Posted
(N
)
17321 ("elementary or array type cannot have discriminants",
17322 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
17324 -- Unset Has_Discriminants flag to prevent cascaded errors, but
17325 -- only if we are not already processing a malformed syntax tree.
17327 if Is_Type
(T
) then
17328 Set_Has_Discriminants
(T
, False);
17333 -- In Ada 83, a derived type defined in a package specification cannot
17334 -- be used for further derivation until the end of its visible part.
17335 -- Note that derivation in the private part of the package is allowed.
17337 if Ada_Version
= Ada_83
17338 and then Is_Derived_Type
(Parent_Type
)
17339 and then In_Visible_Part
(Scope
(Parent_Type
))
17341 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
17343 ("(Ada 83) premature use of type for derivation", Indic
);
17347 -- Check for early use of incomplete or private type
17349 if Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
17350 Error_Msg_N
("premature derivation of incomplete type", Indic
);
17353 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
17354 and then not Comes_From_Generic
(Parent_Type
))
17355 or else Has_Private_Component
(Parent_Type
)
17357 -- The ancestor type of a formal type can be incomplete, in which
17358 -- case only the operations of the partial view are available in the
17359 -- generic. Subsequent checks may be required when the full view is
17360 -- analyzed to verify that a derivation from a tagged type has an
17363 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
17366 elsif No
(Underlying_Type
(Parent_Type
))
17367 or else Has_Private_Component
(Parent_Type
)
17370 ("premature derivation of derived or private type", Indic
);
17372 -- Flag the type itself as being in error, this prevents some
17373 -- nasty problems with subsequent uses of the malformed type.
17375 Set_Error_Posted
(T
);
17377 -- Check that within the immediate scope of an untagged partial
17378 -- view it's illegal to derive from the partial view if the
17379 -- full view is tagged. (7.3(7))
17381 -- We verify that the Parent_Type is a partial view by checking
17382 -- that it is not a Full_Type_Declaration (i.e. a private type or
17383 -- private extension declaration), to distinguish a partial view
17384 -- from a derivation from a private type which also appears as
17385 -- E_Private_Type. If the parent base type is not declared in an
17386 -- enclosing scope there is no need to check.
17388 elsif Present
(Full_View
(Parent_Type
))
17389 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
17390 and then not Is_Tagged_Type
(Parent_Type
)
17391 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
17392 and then In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
17395 ("premature derivation from type with tagged full view",
17400 -- Check that form of derivation is appropriate
17402 Taggd
:= Is_Tagged_Type
(Parent_Type
);
17404 -- Set the parent type to the class-wide type's specific type in this
17405 -- case to prevent cascading errors
17407 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
17408 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
17409 Set_Etype
(T
, Etype
(Parent_Type
));
17413 if Present
(Extension
) and then not Taggd
then
17415 ("type derived from untagged type cannot have extension", Indic
);
17417 elsif No
(Extension
) and then Taggd
then
17419 -- If this declaration is within a private part (or body) of a
17420 -- generic instantiation then the derivation is allowed (the parent
17421 -- type can only appear tagged in this case if it's a generic actual
17422 -- type, since it would otherwise have been rejected in the analysis
17423 -- of the generic template).
17425 if not Is_Generic_Actual_Type
(Parent_Type
)
17426 or else In_Visible_Part
(Scope
(Parent_Type
))
17428 if Is_Class_Wide_Type
(Parent_Type
) then
17430 ("parent type must not be a class-wide type", Indic
);
17432 -- Use specific type to prevent cascaded errors.
17434 Parent_Type
:= Etype
(Parent_Type
);
17438 ("type derived from tagged type must have extension", Indic
);
17443 -- AI-443: Synchronized formal derived types require a private
17444 -- extension. There is no point in checking the ancestor type or
17445 -- the progenitors since the construct is wrong to begin with.
17447 if Ada_Version
>= Ada_2005
17448 and then Is_Generic_Type
(T
)
17449 and then Present
(Original_Node
(N
))
17452 Decl
: constant Node_Id
:= Original_Node
(N
);
17455 if Nkind
(Decl
) = N_Formal_Type_Declaration
17456 and then Nkind
(Formal_Type_Definition
(Decl
)) =
17457 N_Formal_Derived_Type_Definition
17458 and then Synchronized_Present
(Formal_Type_Definition
(Decl
))
17459 and then No
(Extension
)
17461 -- Avoid emitting a duplicate error message
17463 and then not Error_Posted
(Indic
)
17466 ("synchronized derived type must have extension", N
);
17471 if Null_Exclusion_Present
(Def
)
17472 and then not Is_Access_Type
(Parent_Type
)
17474 Error_Msg_N
("null exclusion can only apply to an access type", N
);
17477 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
17479 -- Avoid deriving parent primitives of underlying record views
17481 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
,
17482 Derive_Subps
=> not Is_Underlying_Record_View
(T
));
17484 -- AI-419: The parent type of an explicitly limited derived type must
17485 -- be a limited type or a limited interface.
17487 if Limited_Present
(Def
) then
17488 Set_Is_Limited_Record
(T
);
17490 if Is_Interface
(T
) then
17491 Set_Is_Limited_Interface
(T
);
17494 if not Is_Limited_Type
(Parent_Type
)
17496 (not Is_Interface
(Parent_Type
)
17497 or else not Is_Limited_Interface
(Parent_Type
))
17499 -- AI05-0096: a derivation in the private part of an instance is
17500 -- legal if the generic formal is untagged limited, and the actual
17503 if Is_Generic_Actual_Type
(Parent_Type
)
17504 and then In_Private_Part
(Current_Scope
)
17507 (Generic_Parent_Type
(Parent
(Parent_Type
)))
17513 ("parent type& of limited type must be limited",
17518 end Derived_Type_Declaration
;
17520 ------------------------
17521 -- Diagnose_Interface --
17522 ------------------------
17524 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
) is
17526 if not Is_Interface
(E
) and then E
/= Any_Type
then
17527 Error_Msg_NE
("(Ada 2005) & must be an interface", N
, E
);
17529 end Diagnose_Interface
;
17531 ----------------------------------
17532 -- Enumeration_Type_Declaration --
17533 ----------------------------------
17535 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
17542 -- Create identifier node representing lower bound
17544 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17545 L
:= First
(Literals
(Def
));
17546 Set_Chars
(B_Node
, Chars
(L
));
17547 Set_Entity
(B_Node
, L
);
17548 Set_Etype
(B_Node
, T
);
17549 Set_Is_Static_Expression
(B_Node
, True);
17551 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
17552 Set_Low_Bound
(R_Node
, B_Node
);
17554 Mutate_Ekind
(T
, E_Enumeration_Type
);
17555 Set_First_Literal
(T
, L
);
17557 Set_Is_Constrained
(T
);
17561 -- Loop through literals of enumeration type setting pos and rep values
17562 -- except that if the Ekind is already set, then it means the literal
17563 -- was already constructed (case of a derived type declaration and we
17564 -- should not disturb the Pos and Rep values.
17566 while Present
(L
) loop
17567 if Ekind
(L
) /= E_Enumeration_Literal
then
17568 Mutate_Ekind
(L
, E_Enumeration_Literal
);
17569 Set_Enumeration_Pos
(L
, Ev
);
17570 Set_Enumeration_Rep
(L
, Ev
);
17571 Set_Is_Known_Valid
(L
, True);
17575 New_Overloaded_Entity
(L
);
17576 Generate_Definition
(L
);
17577 Set_Convention
(L
, Convention_Intrinsic
);
17579 -- Case of character literal
17581 if Nkind
(L
) = N_Defining_Character_Literal
then
17582 Set_Is_Character_Type
(T
, True);
17584 -- Check violation of No_Wide_Characters
17586 if Restriction_Check_Required
(No_Wide_Characters
) then
17587 Get_Name_String
(Chars
(L
));
17589 if Name_Len
>= 3 and then Name_Buffer
(1 .. 2) = "QW" then
17590 Check_Restriction
(No_Wide_Characters
, L
);
17599 -- Now create a node representing upper bound
17601 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17602 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
17603 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
17604 Set_Etype
(B_Node
, T
);
17605 Set_Is_Static_Expression
(B_Node
, True);
17607 Set_High_Bound
(R_Node
, B_Node
);
17609 -- Initialize various fields of the type. Some of this information
17610 -- may be overwritten later through rep. clauses.
17612 Set_Scalar_Range
(T
, R_Node
);
17613 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
17614 Set_Enum_Esize
(T
);
17615 Set_Enum_Pos_To_Rep
(T
, Empty
);
17617 -- Set Discard_Names if configuration pragma set, or if there is
17618 -- a parameterless pragma in the current declarative region
17620 if Global_Discard_Names
or else Discard_Names
(Scope
(T
)) then
17621 Set_Discard_Names
(T
);
17624 -- Process end label if there is one
17626 if Present
(Def
) then
17627 Process_End_Label
(Def
, 'e', T
);
17629 end Enumeration_Type_Declaration
;
17631 ---------------------------------
17632 -- Expand_To_Stored_Constraint --
17633 ---------------------------------
17635 function Expand_To_Stored_Constraint
17637 Constraint
: Elist_Id
) return Elist_Id
17639 Explicitly_Discriminated_Type
: Entity_Id
;
17640 Expansion
: Elist_Id
;
17641 Discriminant
: Entity_Id
;
17643 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
17644 -- Find the nearest type that actually specifies discriminants
17646 ---------------------------------
17647 -- Type_With_Explicit_Discrims --
17648 ---------------------------------
17650 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
17651 Typ
: constant E
:= Base_Type
(Id
);
17654 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
17655 if Present
(Full_View
(Typ
)) then
17656 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
17660 if Has_Discriminants
(Typ
) then
17665 if Etype
(Typ
) = Typ
then
17667 elsif Has_Discriminants
(Typ
) then
17670 return Type_With_Explicit_Discrims
(Etype
(Typ
));
17673 end Type_With_Explicit_Discrims
;
17675 -- Start of processing for Expand_To_Stored_Constraint
17678 if No
(Constraint
) or else Is_Empty_Elmt_List
(Constraint
) then
17682 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
17684 if No
(Explicitly_Discriminated_Type
) then
17688 Expansion
:= New_Elmt_List
;
17691 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
17692 while Present
(Discriminant
) loop
17694 (Get_Discriminant_Value
17695 (Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
17697 Next_Stored_Discriminant
(Discriminant
);
17701 end Expand_To_Stored_Constraint
;
17703 ---------------------------
17704 -- Find_Hidden_Interface --
17705 ---------------------------
17707 function Find_Hidden_Interface
17709 Dest
: Elist_Id
) return Entity_Id
17712 Iface_Elmt
: Elmt_Id
;
17715 if Present
(Src
) and then Present
(Dest
) then
17716 Iface_Elmt
:= First_Elmt
(Src
);
17717 while Present
(Iface_Elmt
) loop
17718 Iface
:= Node
(Iface_Elmt
);
17720 if Is_Interface
(Iface
)
17721 and then not Contain_Interface
(Iface
, Dest
)
17726 Next_Elmt
(Iface_Elmt
);
17731 end Find_Hidden_Interface
;
17733 --------------------
17734 -- Find_Type_Name --
17735 --------------------
17737 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
17738 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
17739 New_Id
: Entity_Id
;
17741 Prev_Par
: Node_Id
;
17743 procedure Check_Duplicate_Aspects
;
17744 -- Check that aspects specified in a completion have not been specified
17745 -- already in the partial view.
17747 procedure Tag_Mismatch
;
17748 -- Diagnose a tagged partial view whose full view is untagged. We post
17749 -- the message on the full view, with a reference to the previous
17750 -- partial view. The partial view can be private or incomplete, and
17751 -- these are handled in a different manner, so we determine the position
17752 -- of the error message from the respective slocs of both.
17754 -----------------------------
17755 -- Check_Duplicate_Aspects --
17756 -----------------------------
17758 procedure Check_Duplicate_Aspects
is
17759 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
;
17760 -- Return the corresponding aspect of the partial view which matches
17761 -- the aspect id of Asp. Return Empty is no such aspect exists.
17763 -----------------------------
17764 -- Get_Partial_View_Aspect --
17765 -----------------------------
17767 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
is
17768 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
17769 Prev_Asps
: constant List_Id
:= Aspect_Specifications
(Prev_Par
);
17770 Prev_Asp
: Node_Id
;
17773 if Present
(Prev_Asps
) then
17774 Prev_Asp
:= First
(Prev_Asps
);
17775 while Present
(Prev_Asp
) loop
17776 if Get_Aspect_Id
(Prev_Asp
) = Asp_Id
then
17785 end Get_Partial_View_Aspect
;
17789 Full_Asps
: constant List_Id
:= Aspect_Specifications
(N
);
17790 Full_Asp
: Node_Id
;
17791 Part_Asp
: Node_Id
;
17793 -- Start of processing for Check_Duplicate_Aspects
17796 if Present
(Full_Asps
) then
17797 Full_Asp
:= First
(Full_Asps
);
17798 while Present
(Full_Asp
) loop
17799 Part_Asp
:= Get_Partial_View_Aspect
(Full_Asp
);
17801 -- An aspect and its class-wide counterpart are two distinct
17802 -- aspects and may apply to both views of an entity.
17804 if Present
(Part_Asp
)
17805 and then Class_Present
(Part_Asp
) = Class_Present
(Full_Asp
)
17808 ("aspect already specified in private declaration",
17815 if Has_Discriminants
(Prev
)
17816 and then not Has_Unknown_Discriminants
(Prev
)
17817 and then Get_Aspect_Id
(Full_Asp
) =
17818 Aspect_Implicit_Dereference
17821 ("cannot specify aspect if partial view has known "
17822 & "discriminants", Full_Asp
);
17828 end Check_Duplicate_Aspects
;
17834 procedure Tag_Mismatch
is
17836 if Sloc
(Prev
) < Sloc
(Id
) then
17837 if Ada_Version
>= Ada_2012
17838 and then Nkind
(N
) = N_Private_Type_Declaration
17841 ("declaration of private } must be a tagged type", Id
, Prev
);
17844 ("full declaration of } must be a tagged type", Id
, Prev
);
17848 if Ada_Version
>= Ada_2012
17849 and then Nkind
(N
) = N_Private_Type_Declaration
17852 ("declaration of private } must be a tagged type", Prev
, Id
);
17855 ("full declaration of } must be a tagged type", Prev
, Id
);
17860 -- Start of processing for Find_Type_Name
17863 -- Find incomplete declaration, if one was given
17865 Prev
:= Current_Entity_In_Scope
(Id
);
17867 -- New type declaration
17873 -- Previous declaration exists
17876 Prev_Par
:= Parent
(Prev
);
17878 -- Error if not incomplete/private case except if previous
17879 -- declaration is implicit, etc. Enter_Name will emit error if
17882 if not Is_Incomplete_Or_Private_Type
(Prev
) then
17886 -- Check invalid completion of private or incomplete type
17888 elsif Nkind
(N
) not in N_Full_Type_Declaration
17889 | N_Task_Type_Declaration
17890 | N_Protected_Type_Declaration
17892 (Ada_Version
< Ada_2012
17893 or else not Is_Incomplete_Type
(Prev
)
17894 or else Nkind
(N
) not in N_Private_Type_Declaration
17895 | N_Private_Extension_Declaration
)
17897 -- Completion must be a full type declarations (RM 7.3(4))
17899 Error_Msg_Sloc
:= Sloc
(Prev
);
17900 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
17902 -- Set scope of Id to avoid cascaded errors. Entity is never
17903 -- examined again, except when saving globals in generics.
17905 Set_Scope
(Id
, Current_Scope
);
17908 -- If this is a repeated incomplete declaration, no further
17909 -- checks are possible.
17911 if Nkind
(N
) = N_Incomplete_Type_Declaration
then
17915 -- Case of full declaration of incomplete type
17917 elsif Ekind
(Prev
) = E_Incomplete_Type
17918 and then (Ada_Version
< Ada_2012
17919 or else No
(Full_View
(Prev
))
17920 or else not Is_Private_Type
(Full_View
(Prev
)))
17922 -- Indicate that the incomplete declaration has a matching full
17923 -- declaration. The defining occurrence of the incomplete
17924 -- declaration remains the visible one, and the procedure
17925 -- Get_Full_View dereferences it whenever the type is used.
17927 if Present
(Full_View
(Prev
)) then
17928 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
17931 Set_Full_View
(Prev
, Id
);
17932 Append_Entity
(Id
, Current_Scope
);
17933 Set_Is_Public
(Id
, Is_Public
(Prev
));
17934 Set_Is_Internal
(Id
);
17937 -- If the incomplete view is tagged, a class_wide type has been
17938 -- created already. Use it for the private type as well, in order
17939 -- to prevent multiple incompatible class-wide types that may be
17940 -- created for self-referential anonymous access components.
17942 if Is_Tagged_Type
(Prev
)
17943 and then Present
(Class_Wide_Type
(Prev
))
17945 Mutate_Ekind
(Id
, Ekind
(Prev
)); -- will be reset later
17946 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(Prev
));
17948 -- Type of the class-wide type is the current Id. Previously
17949 -- this was not done for private declarations because of order-
17950 -- of-elaboration issues in the back end, but gigi now handles
17953 Set_Etype
(Class_Wide_Type
(Id
), Id
);
17956 -- Case of full declaration of private type
17959 -- If the private type was a completion of an incomplete type then
17960 -- update Prev to reference the private type
17962 if Ada_Version
>= Ada_2012
17963 and then Ekind
(Prev
) = E_Incomplete_Type
17964 and then Present
(Full_View
(Prev
))
17965 and then Is_Private_Type
(Full_View
(Prev
))
17967 Prev
:= Full_View
(Prev
);
17968 Prev_Par
:= Parent
(Prev
);
17971 if Nkind
(N
) = N_Full_Type_Declaration
17972 and then Nkind
(Type_Definition
(N
)) in
17973 N_Record_Definition | N_Derived_Type_Definition
17974 and then Interface_Present
(Type_Definition
(N
))
17977 ("completion of private type cannot be an interface", N
);
17980 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
17981 if Etype
(Prev
) /= Prev
then
17983 -- Prev is a private subtype or a derived type, and needs
17986 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
17989 elsif Ekind
(Prev
) = E_Private_Type
17990 and then Nkind
(N
) in N_Task_Type_Declaration
17991 | N_Protected_Type_Declaration
17994 ("completion of nonlimited type cannot be limited", N
);
17996 elsif Ekind
(Prev
) = E_Record_Type_With_Private
17997 and then Nkind
(N
) in N_Task_Type_Declaration
17998 | N_Protected_Type_Declaration
18000 if not Is_Limited_Record
(Prev
) then
18002 ("completion of nonlimited type cannot be limited", N
);
18004 elsif No
(Interface_List
(N
)) then
18006 ("completion of tagged private type must be tagged",
18011 -- Ada 2005 (AI-251): Private extension declaration of a task
18012 -- type or a protected type. This case arises when covering
18013 -- interface types.
18015 elsif Nkind
(N
) in N_Task_Type_Declaration
18016 | N_Protected_Type_Declaration
18020 elsif Nkind
(N
) /= N_Full_Type_Declaration
18021 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
18024 ("full view of private extension must be an extension", N
);
18026 elsif not (Abstract_Present
(Parent
(Prev
)))
18027 and then Abstract_Present
(Type_Definition
(N
))
18030 ("full view of non-abstract extension cannot be abstract", N
);
18033 if not In_Private_Part
(Current_Scope
) then
18035 ("declaration of full view must appear in private part", N
);
18038 if Ada_Version
>= Ada_2012
then
18039 Check_Duplicate_Aspects
;
18042 Copy_And_Swap
(Prev
, Id
);
18043 Set_Has_Private_Declaration
(Prev
);
18044 Set_Has_Private_Declaration
(Id
);
18046 -- AI12-0133: Indicate whether we have a partial view with
18047 -- unknown discriminants, in which case initialization of objects
18048 -- of the type do not receive an invariant check.
18050 Set_Partial_View_Has_Unknown_Discr
18051 (Prev
, Has_Unknown_Discriminants
(Id
));
18053 -- Preserve aspect and iterator flags that may have been set on
18054 -- the partial view.
18056 Set_Has_Delayed_Aspects
(Prev
, Has_Delayed_Aspects
(Id
));
18057 Set_Has_Implicit_Dereference
(Prev
, Has_Implicit_Dereference
(Id
));
18059 -- If no error, propagate freeze_node from private to full view.
18060 -- It may have been generated for an early operational item.
18062 if Present
(Freeze_Node
(Id
))
18063 and then Serious_Errors_Detected
= 0
18064 and then No
(Full_View
(Id
))
18066 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
18067 Set_Freeze_Node
(Id
, Empty
);
18068 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
18071 Set_Full_View
(Id
, Prev
);
18075 -- Verify that full declaration conforms to partial one
18077 if Is_Incomplete_Or_Private_Type
(Prev
)
18078 and then Present
(Discriminant_Specifications
(Prev_Par
))
18080 if Present
(Discriminant_Specifications
(N
)) then
18081 if Ekind
(Prev
) = E_Incomplete_Type
then
18082 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
18084 Check_Discriminant_Conformance
(N
, Prev
, Id
);
18089 ("missing discriminants in full type declaration", N
);
18091 -- To avoid cascaded errors on subsequent use, share the
18092 -- discriminants of the partial view.
18094 Set_Discriminant_Specifications
(N
,
18095 Discriminant_Specifications
(Prev_Par
));
18099 -- A prior untagged partial view can have an associated class-wide
18100 -- type due to use of the class attribute, and in this case the full
18101 -- type must also be tagged. This Ada 95 usage is deprecated in favor
18102 -- of incomplete tagged declarations, but we check for it.
18105 and then (Is_Tagged_Type
(Prev
)
18106 or else Present
(Class_Wide_Type
(Prev
)))
18108 -- Ada 2012 (AI05-0162): A private type may be the completion of
18109 -- an incomplete type.
18111 if Ada_Version
>= Ada_2012
18112 and then Is_Incomplete_Type
(Prev
)
18113 and then Nkind
(N
) in N_Private_Type_Declaration
18114 | N_Private_Extension_Declaration
18116 -- No need to check private extensions since they are tagged
18118 if Nkind
(N
) = N_Private_Type_Declaration
18119 and then not Tagged_Present
(N
)
18124 -- The full declaration is either a tagged type (including
18125 -- a synchronized type that implements interfaces) or a
18126 -- type extension, otherwise this is an error.
18128 elsif Nkind
(N
) in N_Task_Type_Declaration
18129 | N_Protected_Type_Declaration
18131 if No
(Interface_List
(N
)) and then not Error_Posted
(N
) then
18135 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
18137 -- Indicate that the previous declaration (tagged incomplete
18138 -- or private declaration) requires the same on the full one.
18140 if not Tagged_Present
(Type_Definition
(N
)) then
18142 Set_Is_Tagged_Type
(Id
);
18145 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
18146 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
18148 ("full declaration of } must be a record extension",
18151 -- Set some attributes to produce a usable full view
18153 Set_Is_Tagged_Type
(Id
);
18162 and then Nkind
(Parent
(Prev
)) = N_Incomplete_Type_Declaration
18163 and then Present
(Premature_Use
(Parent
(Prev
)))
18165 Error_Msg_Sloc
:= Sloc
(N
);
18167 ("\full declaration #", Premature_Use
(Parent
(Prev
)));
18172 end Find_Type_Name
;
18174 -------------------------
18175 -- Find_Type_Of_Object --
18176 -------------------------
18178 function Find_Type_Of_Object
18179 (Obj_Def
: Node_Id
;
18180 Related_Nod
: Node_Id
) return Entity_Id
18182 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
18183 P
: Node_Id
:= Parent
(Obj_Def
);
18188 -- If the parent is a component_definition node we climb to the
18189 -- component_declaration node
18191 if Nkind
(P
) = N_Component_Definition
then
18195 -- Case of an anonymous array subtype
18197 if Def_Kind
in N_Array_Type_Definition
then
18199 Array_Type_Declaration
(T
, Obj_Def
);
18201 -- Create an explicit subtype whenever possible
18203 elsif Nkind
(P
) /= N_Component_Declaration
18204 and then Def_Kind
= N_Subtype_Indication
18206 -- Base name of subtype on object name, which will be unique in
18207 -- the current scope.
18209 -- If this is a duplicate declaration, return base type, to avoid
18210 -- generating duplicate anonymous types.
18212 if Error_Posted
(P
) then
18213 Analyze
(Subtype_Mark
(Obj_Def
));
18214 return Entity
(Subtype_Mark
(Obj_Def
));
18219 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
18221 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
18223 -- If In_Spec_Expression, for example within a pre/postcondition,
18224 -- provide enough information for use of the subtype without
18225 -- depending on full analysis and freezing, which will happen when
18226 -- building the correspondiing subprogram.
18228 if In_Spec_Expression
then
18229 Analyze
(Subtype_Mark
(Obj_Def
));
18232 Base_T
: constant Entity_Id
:= Entity
(Subtype_Mark
(Obj_Def
));
18233 Decl
: constant Node_Id
:=
18234 Make_Subtype_Declaration
(Sloc
(P
),
18235 Defining_Identifier
=> T
,
18236 Subtype_Indication
=> Relocate_Node
(Obj_Def
));
18238 Set_Etype
(T
, Base_T
);
18239 Mutate_Ekind
(T
, Subtype_Kind
(Ekind
(Base_T
)));
18240 Set_Parent
(T
, Obj_Def
);
18242 if Ekind
(T
) = E_Array_Subtype
then
18243 Set_First_Index
(T
, First_Index
(Base_T
));
18244 Set_Is_Constrained
(T
);
18246 elsif Ekind
(T
) = E_Record_Subtype
then
18247 Set_First_Entity
(T
, First_Entity
(Base_T
));
18248 Set_Has_Discriminants
(T
, Has_Discriminants
(Base_T
));
18249 Set_Is_Constrained
(T
);
18252 Insert_Before
(Related_Nod
, Decl
);
18258 -- When generating code, insert subtype declaration ahead of
18259 -- declaration that generated it.
18261 Insert_Action
(Obj_Def
,
18262 Make_Subtype_Declaration
(Sloc
(P
),
18263 Defining_Identifier
=> T
,
18264 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
18266 -- This subtype may need freezing, and this will not be done
18267 -- automatically if the object declaration is not in declarative
18268 -- part. Since this is an object declaration, the type cannot always
18269 -- be frozen here. Deferred constants do not freeze their type
18270 -- (which often enough will be private).
18272 if Nkind
(P
) = N_Object_Declaration
18273 and then Constant_Present
(P
)
18274 and then No
(Expression
(P
))
18278 -- Here we freeze the base type of object type to catch premature use
18279 -- of discriminated private type without a full view.
18282 Insert_Actions
(Obj_Def
, Freeze_Entity
(Base_Type
(T
), P
));
18285 -- Ada 2005 AI-406: the object definition in an object declaration
18286 -- can be an access definition.
18288 elsif Def_Kind
= N_Access_Definition
then
18289 T
:= Access_Definition
(Related_Nod
, Obj_Def
);
18291 Set_Is_Local_Anonymous_Access
18292 (T
, Ada_Version
< Ada_2012
18293 or else Nkind
(P
) /= N_Object_Declaration
18294 or else Is_Library_Level_Entity
(Defining_Identifier
(P
)));
18296 -- Otherwise, the object definition is just a subtype_mark
18299 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
18303 end Find_Type_Of_Object
;
18305 --------------------------------
18306 -- Find_Type_Of_Subtype_Indic --
18307 --------------------------------
18309 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
18313 -- Case of subtype mark with a constraint
18315 if Nkind
(S
) = N_Subtype_Indication
then
18316 Find_Type
(Subtype_Mark
(S
));
18317 Typ
:= Entity
(Subtype_Mark
(S
));
18320 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
18323 ("incorrect constraint for this kind of type", Constraint
(S
));
18324 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
18327 -- Otherwise we have a subtype mark without a constraint
18329 elsif Error_Posted
(S
) then
18330 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
18339 end Find_Type_Of_Subtype_Indic
;
18341 -------------------------------------
18342 -- Floating_Point_Type_Declaration --
18343 -------------------------------------
18345 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
18346 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
18347 Max_Digs_Val
: constant Uint
:= Digits_Value
(Standard_Long_Long_Float
);
18349 Base_Typ
: Entity_Id
;
18350 Implicit_Base
: Entity_Id
;
18352 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
18353 -- Find if given digits value, and possibly a specified range, allows
18354 -- derivation from specified type
18356 procedure Convert_Bound
(B
: Node_Id
);
18357 -- If specified, the bounds must be static but may be of different
18358 -- types. They must be converted into machine numbers of the base type,
18359 -- in accordance with RM 4.9(38).
18361 function Find_Base_Type
return Entity_Id
;
18362 -- Find a predefined base type that Def can derive from, or generate
18363 -- an error and substitute Long_Long_Float if none exists.
18365 ---------------------
18366 -- Can_Derive_From --
18367 ---------------------
18369 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
18370 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
18373 -- Check specified "digits" constraint
18375 if Digs_Val
> Digits_Value
(E
) then
18379 -- Check for matching range, if specified
18381 if Present
(Spec
) then
18382 if Expr_Value_R
(Type_Low_Bound
(E
)) >
18383 Expr_Value_R
(Low_Bound
(Spec
))
18388 if Expr_Value_R
(Type_High_Bound
(E
)) <
18389 Expr_Value_R
(High_Bound
(Spec
))
18396 end Can_Derive_From
;
18398 -------------------
18399 -- Convert_Bound --
18400 --------------------
18402 procedure Convert_Bound
(B
: Node_Id
) is
18404 -- If the bound is not a literal it can only be static if it is
18405 -- a static constant, possibly of a specified type.
18407 if Is_Entity_Name
(B
)
18408 and then Ekind
(Entity
(B
)) = E_Constant
18410 Rewrite
(B
, Constant_Value
(Entity
(B
)));
18413 if Nkind
(B
) = N_Real_Literal
then
18414 Set_Realval
(B
, Machine
(Base_Typ
, Realval
(B
), Round
, B
));
18415 Set_Is_Machine_Number
(B
);
18416 Set_Etype
(B
, Base_Typ
);
18420 --------------------
18421 -- Find_Base_Type --
18422 --------------------
18424 function Find_Base_Type
return Entity_Id
is
18425 Choice
: Elmt_Id
:= First_Elmt
(Predefined_Float_Types
);
18428 -- Iterate over the predefined types in order, returning the first
18429 -- one that Def can derive from.
18431 while Present
(Choice
) loop
18432 if Can_Derive_From
(Node
(Choice
)) then
18433 return Node
(Choice
);
18436 Next_Elmt
(Choice
);
18439 -- If we can't derive from any existing type, use Long_Long_Float
18440 -- and give appropriate message explaining the problem.
18442 if Digs_Val
> Max_Digs_Val
then
18443 -- It might be the case that there is a type with the requested
18444 -- range, just not the combination of digits and range.
18447 ("no predefined type has requested range and precision",
18448 Real_Range_Specification
(Def
));
18452 ("range too large for any predefined type",
18453 Real_Range_Specification
(Def
));
18456 return Standard_Long_Long_Float
;
18457 end Find_Base_Type
;
18459 -- Start of processing for Floating_Point_Type_Declaration
18462 Check_Restriction
(No_Floating_Point
, Def
);
18464 -- Create an implicit base type
18467 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
18469 -- Analyze and verify digits value
18471 Analyze_And_Resolve
(Digs
, Any_Integer
);
18472 Check_Digits_Expression
(Digs
);
18473 Digs_Val
:= Expr_Value
(Digs
);
18475 -- Process possible range spec and find correct type to derive from
18477 Process_Real_Range_Specification
(Def
);
18479 -- Check that requested number of digits is not too high.
18481 if Digs_Val
> Max_Digs_Val
then
18483 -- The check for Max_Base_Digits may be somewhat expensive, as it
18484 -- requires reading System, so only do it when necessary.
18487 Max_Base_Digits
: constant Uint
:=
18490 (Parent
(RTE
(RE_Max_Base_Digits
))));
18493 if Digs_Val
> Max_Base_Digits
then
18494 Error_Msg_Uint_1
:= Max_Base_Digits
;
18495 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
18497 elsif No
(Real_Range_Specification
(Def
)) then
18498 Error_Msg_Uint_1
:= Max_Digs_Val
;
18499 Error_Msg_N
("types with more than ^ digits need range spec "
18500 & "(RM 3.5.7(6))", Digs
);
18505 -- Find a suitable type to derive from or complain and use a substitute
18507 Base_Typ
:= Find_Base_Type
;
18509 -- If there are bounds given in the declaration use them as the bounds
18510 -- of the type, otherwise use the bounds of the predefined base type
18511 -- that was chosen based on the Digits value.
18513 if Present
(Real_Range_Specification
(Def
)) then
18514 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
18515 Set_Is_Constrained
(T
);
18517 Convert_Bound
(Type_Low_Bound
(T
));
18518 Convert_Bound
(Type_High_Bound
(T
));
18521 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
18524 -- Complete definition of implicit base and declared first subtype. The
18525 -- inheritance of the rep item chain ensures that SPARK-related pragmas
18526 -- are not clobbered when the floating point type acts as a full view of
18529 Set_Etype
(Implicit_Base
, Base_Typ
);
18530 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
18531 Set_Size_Info
(Implicit_Base
, Base_Typ
);
18532 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
18533 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
18534 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
18535 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Base_Typ
));
18537 Mutate_Ekind
(T
, E_Floating_Point_Subtype
);
18538 Set_Etype
(T
, Implicit_Base
);
18539 Set_Size_Info
(T
, Implicit_Base
);
18540 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
18541 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
18543 if Digs_Val
>= Uint_1
then
18544 Set_Digits_Value
(T
, Digs_Val
);
18546 pragma Assert
(Serious_Errors_Detected
> 0); null;
18548 end Floating_Point_Type_Declaration
;
18550 ----------------------------
18551 -- Get_Discriminant_Value --
18552 ----------------------------
18554 -- This is the situation:
18556 -- There is a non-derived type
18558 -- type T0 (Dx, Dy, Dz...)
18560 -- There are zero or more levels of derivation, with each derivation
18561 -- either purely inheriting the discriminants, or defining its own.
18563 -- type Ti is new Ti-1
18565 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
18567 -- subtype Ti is ...
18569 -- The subtype issue is avoided by the use of Original_Record_Component,
18570 -- and the fact that derived subtypes also derive the constraints.
18572 -- This chain leads back from
18574 -- Typ_For_Constraint
18576 -- Typ_For_Constraint has discriminants, and the value for each
18577 -- discriminant is given by its corresponding Elmt of Constraints.
18579 -- Discriminant is some discriminant in this hierarchy
18581 -- We need to return its value
18583 -- We do this by recursively searching each level, and looking for
18584 -- Discriminant. Once we get to the bottom, we start backing up
18585 -- returning the value for it which may in turn be a discriminant
18586 -- further up, so on the backup we continue the substitution.
18588 function Get_Discriminant_Value
18589 (Discriminant
: Entity_Id
;
18590 Typ_For_Constraint
: Entity_Id
;
18591 Constraint
: Elist_Id
) return Node_Id
18593 function Root_Corresponding_Discriminant
18594 (Discr
: Entity_Id
) return Entity_Id
;
18595 -- Given a discriminant, traverse the chain of inherited discriminants
18596 -- and return the topmost discriminant.
18598 function Search_Derivation_Levels
18600 Discrim_Values
: Elist_Id
;
18601 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
18602 -- This is the routine that performs the recursive search of levels
18603 -- as described above.
18605 -------------------------------------
18606 -- Root_Corresponding_Discriminant --
18607 -------------------------------------
18609 function Root_Corresponding_Discriminant
18610 (Discr
: Entity_Id
) return Entity_Id
18616 while Present
(Corresponding_Discriminant
(D
)) loop
18617 D
:= Corresponding_Discriminant
(D
);
18621 end Root_Corresponding_Discriminant
;
18623 ------------------------------
18624 -- Search_Derivation_Levels --
18625 ------------------------------
18627 function Search_Derivation_Levels
18629 Discrim_Values
: Elist_Id
;
18630 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
18634 Result
: Node_Or_Entity_Id
;
18635 Result_Entity
: Node_Id
;
18638 -- If inappropriate type, return Error, this happens only in
18639 -- cascaded error situations, and we want to avoid a blow up.
18641 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
18645 -- Look deeper if possible. Use Stored_Constraints only for
18646 -- untagged types. For tagged types use the given constraint.
18647 -- This asymmetry needs explanation???
18649 if not Stored_Discrim_Values
18650 and then Present
(Stored_Constraint
(Ti
))
18651 and then not Is_Tagged_Type
(Ti
)
18654 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
18658 Td
: Entity_Id
:= Etype
(Ti
);
18661 -- If the parent type is private, the full view may include
18662 -- renamed discriminants, and it is those stored values that
18663 -- may be needed (the partial view never has more information
18664 -- than the full view).
18666 if Is_Private_Type
(Td
) and then Present
(Full_View
(Td
)) then
18667 Td
:= Full_View
(Td
);
18671 Result
:= Discriminant
;
18674 if Present
(Stored_Constraint
(Ti
)) then
18676 Search_Derivation_Levels
18677 (Td
, Stored_Constraint
(Ti
), True);
18680 Search_Derivation_Levels
18681 (Td
, Discrim_Values
, Stored_Discrim_Values
);
18687 -- Extra underlying places to search, if not found above. For
18688 -- concurrent types, the relevant discriminant appears in the
18689 -- corresponding record. For a type derived from a private type
18690 -- without discriminant, the full view inherits the discriminants
18691 -- of the full view of the parent.
18693 if Result
= Discriminant
then
18694 if Is_Concurrent_Type
(Ti
)
18695 and then Present
(Corresponding_Record_Type
(Ti
))
18698 Search_Derivation_Levels
(
18699 Corresponding_Record_Type
(Ti
),
18701 Stored_Discrim_Values
);
18703 elsif Is_Private_Type
(Ti
)
18704 and then not Has_Discriminants
(Ti
)
18705 and then Present
(Full_View
(Ti
))
18706 and then Etype
(Full_View
(Ti
)) /= Ti
18709 Search_Derivation_Levels
(
18712 Stored_Discrim_Values
);
18716 -- If Result is not a (reference to a) discriminant, return it,
18717 -- otherwise set Result_Entity to the discriminant.
18719 if Nkind
(Result
) = N_Defining_Identifier
then
18720 pragma Assert
(Result
= Discriminant
);
18721 Result_Entity
:= Result
;
18724 if not Denotes_Discriminant
(Result
) then
18728 Result_Entity
:= Entity
(Result
);
18731 -- See if this level of derivation actually has discriminants because
18732 -- tagged derivations can add them, hence the lower levels need not
18735 if not Has_Discriminants
(Ti
) then
18739 -- Scan Ti's discriminants for Result_Entity, and return its
18740 -- corresponding value, if any.
18742 Result_Entity
:= Original_Record_Component
(Result_Entity
);
18744 Assoc
:= First_Elmt
(Discrim_Values
);
18746 if Stored_Discrim_Values
then
18747 Disc
:= First_Stored_Discriminant
(Ti
);
18749 Disc
:= First_Discriminant
(Ti
);
18752 while Present
(Disc
) loop
18754 -- If no further associations return the discriminant, value will
18755 -- be found on the second pass.
18761 if Original_Record_Component
(Disc
) = Result_Entity
then
18762 return Node
(Assoc
);
18767 if Stored_Discrim_Values
then
18768 Next_Stored_Discriminant
(Disc
);
18770 Next_Discriminant
(Disc
);
18774 -- Could not find it
18777 end Search_Derivation_Levels
;
18781 Result
: Node_Or_Entity_Id
;
18783 -- Start of processing for Get_Discriminant_Value
18786 -- ??? This routine is a gigantic mess and will be deleted. For the
18787 -- time being just test for the trivial case before calling recurse.
18789 -- We are now celebrating the 20th anniversary of this comment!
18791 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
18797 D
:= First_Discriminant
(Typ_For_Constraint
);
18798 E
:= First_Elmt
(Constraint
);
18799 while Present
(D
) loop
18800 if Chars
(D
) = Chars
(Discriminant
) then
18804 Next_Discriminant
(D
);
18810 Result
:= Search_Derivation_Levels
18811 (Typ_For_Constraint
, Constraint
, False);
18813 -- ??? hack to disappear when this routine is gone
18815 if Nkind
(Result
) = N_Defining_Identifier
then
18821 D
:= First_Discriminant
(Typ_For_Constraint
);
18822 E
:= First_Elmt
(Constraint
);
18823 while Present
(D
) loop
18824 if Root_Corresponding_Discriminant
(D
) = Discriminant
then
18828 Next_Discriminant
(D
);
18834 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
18836 end Get_Discriminant_Value
;
18838 --------------------------
18839 -- Has_Range_Constraint --
18840 --------------------------
18842 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
18843 C
: constant Node_Id
:= Constraint
(N
);
18846 if Nkind
(C
) = N_Range_Constraint
then
18849 elsif Nkind
(C
) = N_Digits_Constraint
then
18851 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
18852 or else Present
(Range_Constraint
(C
));
18854 elsif Nkind
(C
) = N_Delta_Constraint
then
18855 return Present
(Range_Constraint
(C
));
18860 end Has_Range_Constraint
;
18862 ------------------------
18863 -- Inherit_Components --
18864 ------------------------
18866 function Inherit_Components
18868 Parent_Base
: Entity_Id
;
18869 Derived_Base
: Entity_Id
;
18870 Is_Tagged
: Boolean;
18871 Inherit_Discr
: Boolean;
18872 Discs
: Elist_Id
) return Elist_Id
18874 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
18876 procedure Inherit_Component
18877 (Old_C
: Entity_Id
;
18878 Plain_Discrim
: Boolean := False;
18879 Stored_Discrim
: Boolean := False);
18880 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
18881 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
18882 -- True, Old_C is a stored discriminant. If they are both false then
18883 -- Old_C is a regular component.
18885 -----------------------
18886 -- Inherit_Component --
18887 -----------------------
18889 procedure Inherit_Component
18890 (Old_C
: Entity_Id
;
18891 Plain_Discrim
: Boolean := False;
18892 Stored_Discrim
: Boolean := False)
18894 procedure Set_Anonymous_Type
(Id
: Entity_Id
);
18895 -- Id denotes the entity of an access discriminant or anonymous
18896 -- access component. Set the type of Id to either the same type of
18897 -- Old_C or create a new one depending on whether the parent and
18898 -- the child types are in the same scope.
18900 ------------------------
18901 -- Set_Anonymous_Type --
18902 ------------------------
18904 procedure Set_Anonymous_Type
(Id
: Entity_Id
) is
18905 Old_Typ
: constant Entity_Id
:= Etype
(Old_C
);
18908 if Scope
(Parent_Base
) = Scope
(Derived_Base
) then
18909 Set_Etype
(Id
, Old_Typ
);
18911 -- The parent and the derived type are in two different scopes.
18912 -- Reuse the type of the original discriminant / component by
18913 -- copying it in order to preserve all attributes.
18917 Typ
: constant Entity_Id
:= New_Copy
(Old_Typ
);
18920 Set_Etype
(Id
, Typ
);
18922 -- Since we do not generate component declarations for
18923 -- inherited components, associate the itype with the
18926 Set_Associated_Node_For_Itype
(Typ
, Parent
(Derived_Base
));
18927 Set_Scope
(Typ
, Derived_Base
);
18930 end Set_Anonymous_Type
;
18932 -- Local variables and constants
18934 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
18936 Corr_Discrim
: Entity_Id
;
18937 Discrim
: Entity_Id
;
18939 -- Start of processing for Inherit_Component
18942 pragma Assert
(not Is_Tagged
or not Stored_Discrim
);
18944 Set_Parent
(New_C
, Parent
(Old_C
));
18946 -- Regular discriminants and components must be inserted in the scope
18947 -- of the Derived_Base. Do it here.
18949 if not Stored_Discrim
then
18950 Enter_Name
(New_C
);
18953 -- For tagged types the Original_Record_Component must point to
18954 -- whatever this field was pointing to in the parent type. This has
18955 -- already been achieved by the call to New_Copy above.
18957 if not Is_Tagged
then
18958 Set_Original_Record_Component
(New_C
, New_C
);
18959 Set_Corresponding_Record_Component
(New_C
, Old_C
);
18962 -- Set the proper type of an access discriminant
18964 if Ekind
(New_C
) = E_Discriminant
18965 and then Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
18967 Set_Anonymous_Type
(New_C
);
18970 -- If we have inherited a component then see if its Etype contains
18971 -- references to Parent_Base discriminants. In this case, replace
18972 -- these references with the constraints given in Discs. We do not
18973 -- do this for the partial view of private types because this is
18974 -- not needed (only the components of the full view will be used
18975 -- for code generation) and cause problem. We also avoid this
18976 -- transformation in some error situations.
18978 if Ekind
(New_C
) = E_Component
then
18980 -- Set the proper type of an anonymous access component
18982 if Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
then
18983 Set_Anonymous_Type
(New_C
);
18985 elsif (Is_Private_Type
(Derived_Base
)
18986 and then not Is_Generic_Type
(Derived_Base
))
18987 or else (Is_Empty_Elmt_List
(Discs
)
18988 and then not Expander_Active
)
18990 Set_Etype
(New_C
, Etype
(Old_C
));
18993 -- The current component introduces a circularity of the
18996 -- limited with Pack_2;
18997 -- package Pack_1 is
18998 -- type T_1 is tagged record
18999 -- Comp : access Pack_2.T_2;
19005 -- package Pack_2 is
19006 -- type T_2 is new Pack_1.T_1 with ...;
19011 Constrain_Component_Type
19012 (Old_C
, Derived_Base
, N
, Parent_Base
, Discs
));
19016 -- In derived tagged types it is illegal to reference a non
19017 -- discriminant component in the parent type. To catch this, mark
19018 -- these components with an Ekind of E_Void. This will be reset in
19019 -- Record_Type_Definition after processing the record extension of
19020 -- the derived type.
19022 -- If the declaration is a private extension, there is no further
19023 -- record extension to process, and the components retain their
19024 -- current kind, because they are visible at this point.
19026 if Is_Tagged
and then Ekind
(New_C
) = E_Component
19027 and then Nkind
(N
) /= N_Private_Extension_Declaration
19029 Mutate_Ekind
(New_C
, E_Void
);
19032 if Plain_Discrim
then
19033 Set_Corresponding_Discriminant
(New_C
, Old_C
);
19034 Build_Discriminal
(New_C
);
19036 -- If we are explicitly inheriting a stored discriminant it will be
19037 -- completely hidden.
19039 elsif Stored_Discrim
then
19040 Set_Corresponding_Discriminant
(New_C
, Empty
);
19041 Set_Discriminal
(New_C
, Empty
);
19042 Set_Is_Completely_Hidden
(New_C
);
19044 -- Set the Original_Record_Component of each discriminant in the
19045 -- derived base to point to the corresponding stored that we just
19048 Discrim
:= First_Discriminant
(Derived_Base
);
19049 while Present
(Discrim
) loop
19050 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
19052 -- Corr_Discrim could be missing in an error situation
19054 if Present
(Corr_Discrim
)
19055 and then Original_Record_Component
(Corr_Discrim
) = Old_C
19057 Set_Original_Record_Component
(Discrim
, New_C
);
19058 Set_Corresponding_Record_Component
(Discrim
, Empty
);
19061 Next_Discriminant
(Discrim
);
19064 Append_Entity
(New_C
, Derived_Base
);
19067 if not Is_Tagged
then
19068 Append_Elmt
(Old_C
, Assoc_List
);
19069 Append_Elmt
(New_C
, Assoc_List
);
19071 end Inherit_Component
;
19073 -- Variables local to Inherit_Component
19075 Loc
: constant Source_Ptr
:= Sloc
(N
);
19077 Parent_Discrim
: Entity_Id
;
19078 Stored_Discrim
: Entity_Id
;
19080 Component
: Entity_Id
;
19082 -- Start of processing for Inherit_Components
19085 if not Is_Tagged
then
19086 Append_Elmt
(Parent_Base
, Assoc_List
);
19087 Append_Elmt
(Derived_Base
, Assoc_List
);
19090 -- Inherit parent discriminants if needed
19092 if Inherit_Discr
then
19093 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
19094 while Present
(Parent_Discrim
) loop
19095 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
19096 Next_Discriminant
(Parent_Discrim
);
19100 -- Create explicit stored discrims for untagged types when necessary
19102 if not Has_Unknown_Discriminants
(Derived_Base
)
19103 and then Has_Discriminants
(Parent_Base
)
19104 and then not Is_Tagged
19107 or else First_Discriminant
(Parent_Base
) /=
19108 First_Stored_Discriminant
(Parent_Base
))
19110 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
19111 while Present
(Stored_Discrim
) loop
19112 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
19113 Next_Stored_Discriminant
(Stored_Discrim
);
19117 -- See if we can apply the second transformation for derived types, as
19118 -- explained in point 6. in the comments above Build_Derived_Record_Type
19119 -- This is achieved by appending Derived_Base discriminants into Discs,
19120 -- which has the side effect of returning a non empty Discs list to the
19121 -- caller of Inherit_Components, which is what we want. This must be
19122 -- done for private derived types if there are explicit stored
19123 -- discriminants, to ensure that we can retrieve the values of the
19124 -- constraints provided in the ancestors.
19127 and then Is_Empty_Elmt_List
(Discs
)
19128 and then Present
(First_Discriminant
(Derived_Base
))
19130 (not Is_Private_Type
(Derived_Base
)
19131 or else Is_Completely_Hidden
19132 (First_Stored_Discriminant
(Derived_Base
))
19133 or else Is_Generic_Type
(Derived_Base
))
19135 D
:= First_Discriminant
(Derived_Base
);
19136 while Present
(D
) loop
19137 Append_Elmt
(New_Occurrence_Of
(D
, Loc
), Discs
);
19138 Next_Discriminant
(D
);
19142 -- Finally, inherit non-discriminant components unless they are not
19143 -- visible because defined or inherited from the full view of the
19144 -- parent. Don't inherit the _parent field of the parent type.
19146 Component
:= First_Entity
(Parent_Base
);
19147 while Present
(Component
) loop
19149 -- Ada 2005 (AI-251): Do not inherit components associated with
19150 -- secondary tags of the parent.
19152 if Ekind
(Component
) = E_Component
19153 and then Present
(Related_Type
(Component
))
19157 elsif Ekind
(Component
) /= E_Component
19158 or else Chars
(Component
) = Name_uParent
19162 -- If the derived type is within the parent type's declarative
19163 -- region, then the components can still be inherited even though
19164 -- they aren't visible at this point. This can occur for cases
19165 -- such as within public child units where the components must
19166 -- become visible upon entering the child unit's private part.
19168 elsif not Is_Visible_Component
(Component
)
19169 and then not In_Open_Scopes
(Scope
(Parent_Base
))
19173 elsif Ekind
(Derived_Base
) in E_Private_Type | E_Limited_Private_Type
19178 Inherit_Component
(Component
);
19181 Next_Entity
(Component
);
19184 -- For tagged derived types, inherited discriminants cannot be used in
19185 -- component declarations of the record extension part. To achieve this
19186 -- we mark the inherited discriminants as not visible.
19188 if Is_Tagged
and then Inherit_Discr
then
19189 D
:= First_Discriminant
(Derived_Base
);
19190 while Present
(D
) loop
19191 Set_Is_Immediately_Visible
(D
, False);
19192 Next_Discriminant
(D
);
19197 end Inherit_Components
;
19199 ----------------------
19200 -- Is_EVF_Procedure --
19201 ----------------------
19203 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean is
19204 Formal
: Entity_Id
;
19207 -- Examine the formals of an Extensions_Visible False procedure looking
19208 -- for a controlling OUT parameter.
19210 if Ekind
(Subp
) = E_Procedure
19211 and then Extensions_Visible_Status
(Subp
) = Extensions_Visible_False
19213 Formal
:= First_Formal
(Subp
);
19214 while Present
(Formal
) loop
19215 if Ekind
(Formal
) = E_Out_Parameter
19216 and then Is_Controlling_Formal
(Formal
)
19221 Next_Formal
(Formal
);
19226 end Is_EVF_Procedure
;
19228 --------------------------
19229 -- Is_Private_Primitive --
19230 --------------------------
19232 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean is
19233 Prim_Scope
: constant Entity_Id
:= Scope
(Prim
);
19234 Priv_Entity
: Entity_Id
;
19236 if Is_Package_Or_Generic_Package
(Prim_Scope
) then
19237 Priv_Entity
:= First_Private_Entity
(Prim_Scope
);
19239 while Present
(Priv_Entity
) loop
19240 if Priv_Entity
= Prim
then
19244 Next_Entity
(Priv_Entity
);
19249 end Is_Private_Primitive
;
19251 ------------------------------
19252 -- Is_Valid_Constraint_Kind --
19253 ------------------------------
19255 function Is_Valid_Constraint_Kind
19256 (T_Kind
: Type_Kind
;
19257 Constraint_Kind
: Node_Kind
) return Boolean
19261 when Enumeration_Kind
19264 return Constraint_Kind
= N_Range_Constraint
;
19266 when Decimal_Fixed_Point_Kind
=>
19267 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19269 when Ordinary_Fixed_Point_Kind
=>
19270 return Constraint_Kind
in N_Delta_Constraint | N_Range_Constraint
;
19273 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19280 | E_Incomplete_Type
19284 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
19287 return True; -- Error will be detected later
19289 end Is_Valid_Constraint_Kind
;
19291 --------------------------
19292 -- Is_Visible_Component --
19293 --------------------------
19295 function Is_Visible_Component
19297 N
: Node_Id
:= Empty
) return Boolean
19299 Original_Comp
: Entity_Id
:= Empty
;
19300 Original_Type
: Entity_Id
;
19301 Type_Scope
: Entity_Id
;
19303 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
19304 -- Check whether parent type of inherited component is declared locally,
19305 -- possibly within a nested package or instance. The current scope is
19306 -- the derived record itself.
19308 -------------------
19309 -- Is_Local_Type --
19310 -------------------
19312 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
19314 return Scope_Within
(Inner
=> Typ
, Outer
=> Scope
(Current_Scope
));
19317 -- Start of processing for Is_Visible_Component
19320 if Ekind
(C
) in E_Component | E_Discriminant
then
19321 Original_Comp
:= Original_Record_Component
(C
);
19324 if No
(Original_Comp
) then
19326 -- Premature usage, or previous error
19331 Original_Type
:= Scope
(Original_Comp
);
19332 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
19335 -- This test only concerns tagged types
19337 if not Is_Tagged_Type
(Original_Type
) then
19339 -- Check if this is a renamed discriminant (hidden either by the
19340 -- derived type or by some ancestor), unless we are analyzing code
19341 -- generated by the expander since it may reference such components
19342 -- (for example see the expansion of Deep_Adjust).
19344 if Ekind
(C
) = E_Discriminant
and then Present
(N
) then
19346 not Comes_From_Source
(N
)
19347 or else not Is_Completely_Hidden
(C
);
19352 -- If it is _Parent or _Tag, there is no visibility issue
19354 elsif not Comes_From_Source
(Original_Comp
) then
19357 -- Discriminants are visible unless the (private) type has unknown
19358 -- discriminants. If the discriminant reference is inserted for a
19359 -- discriminant check on a full view it is also visible.
19361 elsif Ekind
(Original_Comp
) = E_Discriminant
19363 (not Has_Unknown_Discriminants
(Original_Type
)
19364 or else (Present
(N
)
19365 and then Nkind
(N
) = N_Selected_Component
19366 and then Nkind
(Prefix
(N
)) = N_Type_Conversion
19367 and then not Comes_From_Source
(Prefix
(N
))))
19371 -- If the component has been declared in an ancestor which is currently
19372 -- a private type, then it is not visible. The same applies if the
19373 -- component's containing type is not in an open scope and the original
19374 -- component's enclosing type is a visible full view of a private type
19375 -- (which can occur in cases where an attempt is being made to reference
19376 -- a component in a sibling package that is inherited from a visible
19377 -- component of a type in an ancestor package; the component in the
19378 -- sibling package should not be visible even though the component it
19379 -- inherited from is visible), but instance bodies are not subject to
19380 -- this second case since they have the Has_Private_View mechanism to
19381 -- ensure proper visibility. This does not apply however in the case
19382 -- where the scope of the type is a private child unit, or when the
19383 -- parent comes from a local package in which the ancestor is currently
19384 -- visible. The latter suppression of visibility is needed for cases
19385 -- that are tested in B730006.
19387 elsif Is_Private_Type
(Original_Type
)
19389 (not Is_Private_Descendant
(Type_Scope
)
19390 and then not In_Open_Scopes
(Type_Scope
)
19391 and then Has_Private_Declaration
(Original_Type
)
19392 and then not In_Instance_Body
)
19394 -- If the type derives from an entity in a formal package, there
19395 -- are no additional visible components.
19397 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
19398 N_Formal_Package_Declaration
19402 -- if we are not in the private part of the current package, there
19403 -- are no additional visible components.
19405 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
19406 and then not In_Private_Part
(Scope
(Current_Scope
))
19411 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
19412 and then In_Open_Scopes
(Scope
(Original_Type
))
19413 and then Is_Local_Type
(Type_Scope
);
19416 -- There is another weird way in which a component may be invisible when
19417 -- the private and the full view are not derived from the same ancestor.
19418 -- Here is an example :
19420 -- type A1 is tagged record F1 : integer; end record;
19421 -- type A2 is new A1 with record F2 : integer; end record;
19422 -- type T is new A1 with private;
19424 -- type T is new A2 with null record;
19426 -- In this case, the full view of T inherits F1 and F2 but the private
19427 -- view inherits only F1
19431 Ancestor
: Entity_Id
:= Scope
(C
);
19435 if Ancestor
= Original_Type
then
19438 -- The ancestor may have a partial view of the original type,
19439 -- but if the full view is in scope, as in a child body, the
19440 -- component is visible.
19442 elsif In_Private_Part
(Scope
(Original_Type
))
19443 and then Full_View
(Ancestor
) = Original_Type
19447 elsif Ancestor
= Etype
(Ancestor
) then
19449 -- No further ancestors to examine
19454 Ancestor
:= Etype
(Ancestor
);
19458 end Is_Visible_Component
;
19460 --------------------------
19461 -- Make_Class_Wide_Type --
19462 --------------------------
19464 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
19465 CW_Type
: Entity_Id
;
19467 Next_E
: Entity_Id
;
19468 Prev_E
: Entity_Id
;
19471 if Present
(Class_Wide_Type
(T
)) then
19473 -- The class-wide type is a partially decorated entity created for a
19474 -- unanalyzed tagged type referenced through a limited with clause.
19475 -- When the tagged type is analyzed, its class-wide type needs to be
19476 -- redecorated. Note that we reuse the entity created by Decorate_
19477 -- Tagged_Type in order to preserve all links.
19479 if Materialize_Entity
(Class_Wide_Type
(T
)) then
19480 CW_Type
:= Class_Wide_Type
(T
);
19481 Set_Materialize_Entity
(CW_Type
, False);
19483 -- The class wide type can have been defined by the partial view, in
19484 -- which case everything is already done.
19490 -- Default case, we need to create a new class-wide type
19494 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
19497 -- Inherit root type characteristics
19499 CW_Name
:= Chars
(CW_Type
);
19500 Next_E
:= Next_Entity
(CW_Type
);
19501 Prev_E
:= Prev_Entity
(CW_Type
);
19502 Copy_Node
(T
, CW_Type
);
19503 Set_Comes_From_Source
(CW_Type
, False);
19504 Set_Chars
(CW_Type
, CW_Name
);
19505 Set_Parent
(CW_Type
, Parent
(T
));
19506 Set_Prev_Entity
(CW_Type
, Prev_E
);
19507 Set_Next_Entity
(CW_Type
, Next_E
);
19509 -- Ensure we have a new freeze node for the class-wide type. The partial
19510 -- view may have freeze action of its own, requiring a proper freeze
19511 -- node, and the same freeze node cannot be shared between the two
19514 Set_Has_Delayed_Freeze
(CW_Type
);
19515 Set_Freeze_Node
(CW_Type
, Empty
);
19517 -- Customize the class-wide type: It has no prim. op., it cannot be
19518 -- abstract, its Etype points back to the specific root type, and it
19519 -- cannot have any invariants.
19521 if Ekind
(CW_Type
) in Incomplete_Or_Private_Kind
then
19522 Reinit_Field_To_Zero
(CW_Type
, F_Private_Dependents
);
19524 elsif Ekind
(CW_Type
) in Concurrent_Kind
then
19525 Reinit_Field_To_Zero
(CW_Type
, F_First_Private_Entity
);
19526 Reinit_Field_To_Zero
(CW_Type
, F_Scope_Depth_Value
);
19528 if Ekind
(CW_Type
) in Task_Kind
then
19529 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Checks_OK_Id
);
19530 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Warnings_OK_Id
);
19533 if Ekind
(CW_Type
) in E_Task_Type | E_Protected_Type
then
19534 Reinit_Field_To_Zero
(CW_Type
, F_SPARK_Aux_Pragma_Inherited
);
19538 Mutate_Ekind
(CW_Type
, E_Class_Wide_Type
);
19539 Set_Is_Tagged_Type
(CW_Type
, True);
19540 Set_Direct_Primitive_Operations
(CW_Type
, New_Elmt_List
);
19541 Set_Is_Abstract_Type
(CW_Type
, False);
19542 Set_Is_Constrained
(CW_Type
, False);
19543 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
19544 Set_Default_SSO
(CW_Type
);
19545 Set_Has_Inheritable_Invariants
(CW_Type
, False);
19546 Set_Has_Inherited_Invariants
(CW_Type
, False);
19547 Set_Has_Own_Invariants
(CW_Type
, False);
19549 if Ekind
(T
) = E_Class_Wide_Subtype
then
19550 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
19552 Set_Etype
(CW_Type
, T
);
19555 Set_No_Tagged_Streams_Pragma
(CW_Type
, No_Tagged_Streams
);
19557 -- If this is the class_wide type of a constrained subtype, it does
19558 -- not have discriminants.
19560 Set_Has_Discriminants
(CW_Type
,
19561 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
19563 Set_Has_Unknown_Discriminants
(CW_Type
, True);
19564 Set_Class_Wide_Type
(T
, CW_Type
);
19565 Set_Equivalent_Type
(CW_Type
, Empty
);
19567 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
19569 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
19570 end Make_Class_Wide_Type
;
19576 procedure Make_Index
19578 Related_Nod
: Node_Id
;
19579 Related_Id
: Entity_Id
:= Empty
;
19580 Suffix_Index
: Pos
:= 1)
19584 Def_Id
: Entity_Id
:= Empty
;
19585 Found
: Boolean := False;
19588 -- For a discrete range used in a constrained array definition and
19589 -- defined by a range, an implicit conversion to the predefined type
19590 -- INTEGER is assumed if each bound is either a numeric literal, a named
19591 -- number, or an attribute, and the type of both bounds (prior to the
19592 -- implicit conversion) is the type universal_integer. Otherwise, both
19593 -- bounds must be of the same discrete type, other than universal
19594 -- integer; this type must be determinable independently of the
19595 -- context, but using the fact that the type must be discrete and that
19596 -- both bounds must have the same type.
19598 -- Character literals also have a universal type in the absence of
19599 -- of additional context, and are resolved to Standard_Character.
19601 if Nkind
(N
) = N_Range
then
19603 -- The index is given by a range constraint. The bounds are known
19604 -- to be of a consistent type.
19606 if not Is_Overloaded
(N
) then
19609 -- For universal bounds, choose the specific predefined type
19611 if T
= Universal_Integer
then
19612 T
:= Standard_Integer
;
19614 elsif T
= Any_Character
then
19615 Ambiguous_Character
(Low_Bound
(N
));
19617 T
:= Standard_Character
;
19620 -- The node may be overloaded because some user-defined operators
19621 -- are available, but if a universal interpretation exists it is
19622 -- also the selected one.
19624 elsif Universal_Interpretation
(N
) = Universal_Integer
then
19625 T
:= Standard_Integer
;
19631 Ind
: Interp_Index
;
19635 Get_First_Interp
(N
, Ind
, It
);
19636 while Present
(It
.Typ
) loop
19637 if Is_Discrete_Type
(It
.Typ
) then
19640 and then not Covers
(It
.Typ
, T
)
19641 and then not Covers
(T
, It
.Typ
)
19643 Error_Msg_N
("ambiguous bounds in discrete range", N
);
19651 Get_Next_Interp
(Ind
, It
);
19654 if T
= Any_Type
then
19655 Error_Msg_N
("discrete type required for range", N
);
19656 Set_Etype
(N
, Any_Type
);
19659 elsif T
= Universal_Integer
then
19660 T
:= Standard_Integer
;
19665 if not Is_Discrete_Type
(T
) then
19666 Error_Msg_N
("discrete type required for range", N
);
19667 Set_Etype
(N
, Any_Type
);
19671 -- If the range bounds are "T'First .. T'Last" where T is a name of a
19672 -- discrete type, then use T as the type of the index.
19674 if Nkind
(Low_Bound
(N
)) = N_Attribute_Reference
19675 and then Attribute_Name
(Low_Bound
(N
)) = Name_First
19676 and then Is_Entity_Name
(Prefix
(Low_Bound
(N
)))
19677 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(N
))))
19679 and then Nkind
(High_Bound
(N
)) = N_Attribute_Reference
19680 and then Attribute_Name
(High_Bound
(N
)) = Name_Last
19681 and then Is_Entity_Name
(Prefix
(High_Bound
(N
)))
19682 and then Entity
(Prefix
(High_Bound
(N
))) = Def_Id
19684 Def_Id
:= Entity
(Prefix
(Low_Bound
(N
)));
19688 Process_Range_Expr_In_Decl
(R
, T
);
19690 elsif Nkind
(N
) = N_Subtype_Indication
then
19692 -- The index is given by a subtype with a range constraint
19694 T
:= Base_Type
(Entity
(Subtype_Mark
(N
)));
19696 if not Is_Discrete_Type
(T
) then
19697 Error_Msg_N
("discrete type required for range", N
);
19698 Set_Etype
(N
, Any_Type
);
19702 R
:= Range_Expression
(Constraint
(N
));
19705 Process_Range_Expr_In_Decl
(R
, Entity
(Subtype_Mark
(N
)));
19707 elsif Nkind
(N
) = N_Attribute_Reference
then
19709 -- Catch beginner's error (use of attribute other than 'Range)
19711 if Attribute_Name
(N
) /= Name_Range
then
19712 Error_Msg_N
("expect attribute ''Range", N
);
19713 Set_Etype
(N
, Any_Type
);
19717 -- If the node denotes the range of a type mark, that is also the
19718 -- resulting type, and we do not need to create an Itype for it.
19720 if Is_Entity_Name
(Prefix
(N
))
19721 and then Comes_From_Source
(N
)
19722 and then Is_Discrete_Type
(Entity
(Prefix
(N
)))
19724 Def_Id
:= Entity
(Prefix
(N
));
19727 Analyze_And_Resolve
(N
);
19731 -- If none of the above, must be a subtype. We convert this to a
19732 -- range attribute reference because in the case of declared first
19733 -- named subtypes, the types in the range reference can be different
19734 -- from the type of the entity. A range attribute normalizes the
19735 -- reference and obtains the correct types for the bounds.
19737 -- This transformation is in the nature of an expansion, is only
19738 -- done if expansion is active. In particular, it is not done on
19739 -- formal generic types, because we need to retain the name of the
19740 -- original index for instantiation purposes.
19743 if not Is_Entity_Name
(N
) or else not Is_Type
(Entity
(N
)) then
19744 Error_Msg_N
("invalid subtype mark in discrete range", N
);
19745 Set_Etype
(N
, Any_Integer
);
19749 -- The type mark may be that of an incomplete type. It is only
19750 -- now that we can get the full view, previous analysis does
19751 -- not look specifically for a type mark.
19753 Set_Entity
(N
, Get_Full_View
(Entity
(N
)));
19754 Set_Etype
(N
, Entity
(N
));
19755 Def_Id
:= Entity
(N
);
19757 if not Is_Discrete_Type
(Def_Id
) then
19758 Error_Msg_N
("discrete type required for index", N
);
19759 Set_Etype
(N
, Any_Type
);
19764 if Expander_Active
then
19766 Make_Attribute_Reference
(Sloc
(N
),
19767 Attribute_Name
=> Name_Range
,
19768 Prefix
=> Relocate_Node
(N
)));
19770 -- The original was a subtype mark that does not freeze. This
19771 -- means that the rewritten version must not freeze either.
19773 Set_Must_Not_Freeze
(N
);
19774 Set_Must_Not_Freeze
(Prefix
(N
));
19775 Analyze_And_Resolve
(N
);
19779 -- If expander is inactive, type is legal, nothing else to construct
19786 if not Is_Discrete_Type
(T
) then
19787 Error_Msg_N
("discrete type required for range", N
);
19788 Set_Etype
(N
, Any_Type
);
19791 elsif T
= Any_Type
then
19792 Set_Etype
(N
, Any_Type
);
19796 -- We will now create the appropriate Itype to describe the range, but
19797 -- first a check. If we originally had a subtype, then we just label
19798 -- the range with this subtype. Not only is there no need to construct
19799 -- a new subtype, but it is wrong to do so for two reasons:
19801 -- 1. A legality concern, if we have a subtype, it must not freeze,
19802 -- and the Itype would cause freezing incorrectly
19804 -- 2. An efficiency concern, if we created an Itype, it would not be
19805 -- recognized as the same type for the purposes of eliminating
19806 -- checks in some circumstances.
19808 -- We signal this case by setting the subtype entity in Def_Id
19810 if No
(Def_Id
) then
19812 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
19813 Set_Etype
(Def_Id
, Base_Type
(T
));
19815 if Is_Signed_Integer_Type
(T
) then
19816 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
19818 elsif Is_Modular_Integer_Type
(T
) then
19819 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
19822 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
19823 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
19824 Set_First_Literal
(Def_Id
, First_Literal
(T
));
19827 Set_Size_Info
(Def_Id
, (T
));
19828 Set_RM_Size
(Def_Id
, RM_Size
(T
));
19829 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
19831 Set_Scalar_Range
(Def_Id
, R
);
19832 Conditional_Delay
(Def_Id
, T
);
19834 -- In the subtype indication case inherit properties of the parent
19836 if Nkind
(N
) = N_Subtype_Indication
then
19838 -- It is enough to inherit predicate flags and not the predicate
19839 -- functions, because predicates on an index type are illegal
19840 -- anyway and the flags are enough to detect them.
19842 Inherit_Predicate_Flags
(Def_Id
, Entity
(Subtype_Mark
(N
)));
19844 -- If the immediate parent of the new subtype is nonstatic, then
19845 -- the subtype we create is nonstatic as well, even if its bounds
19848 if not Is_OK_Static_Subtype
(Entity
(Subtype_Mark
(N
))) then
19849 Set_Is_Non_Static_Subtype
(Def_Id
);
19853 Set_Parent
(Def_Id
, N
);
19856 -- Final step is to label the index with this constructed type
19858 Set_Etype
(N
, Def_Id
);
19861 ------------------------------
19862 -- Modular_Type_Declaration --
19863 ------------------------------
19865 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
19866 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
19869 procedure Set_Modular_Size
(Bits
: Int
);
19870 -- Sets RM_Size to Bits, and Esize to normal word size above this
19872 ----------------------
19873 -- Set_Modular_Size --
19874 ----------------------
19876 procedure Set_Modular_Size
(Bits
: Int
) is
19880 Set_RM_Size
(T
, UI_From_Int
(Bits
));
19882 if Bits
< System_Max_Binary_Modulus_Power
then
19885 while Siz
< 128 loop
19886 exit when Bits
<= Siz
;
19890 Set_Esize
(T
, UI_From_Int
(Siz
));
19893 Set_Esize
(T
, UI_From_Int
(System_Max_Binary_Modulus_Power
));
19896 if not Non_Binary_Modulus
(T
) and then Esize
(T
) = RM_Size
(T
) then
19897 Set_Is_Known_Valid
(T
);
19899 end Set_Modular_Size
;
19901 -- Start of processing for Modular_Type_Declaration
19904 -- If the mod expression is (exactly) 2 * literal, where literal is
19905 -- 128 or less, then almost certainly the * was meant to be **. Warn.
19907 if Warn_On_Suspicious_Modulus_Value
19908 and then Nkind
(Mod_Expr
) = N_Op_Multiply
19909 and then Nkind
(Left_Opnd
(Mod_Expr
)) = N_Integer_Literal
19910 and then Intval
(Left_Opnd
(Mod_Expr
)) = Uint_2
19911 and then Nkind
(Right_Opnd
(Mod_Expr
)) = N_Integer_Literal
19912 and then Intval
(Right_Opnd
(Mod_Expr
)) <= Uint_128
19915 ("suspicious MOD value, was '*'* intended'??.m?", Mod_Expr
);
19918 -- Proceed with analysis of mod expression
19920 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
19922 if Ekind
(T
) in Incomplete_Or_Private_Kind
then
19923 Reinit_Field_To_Zero
(T
, F_Stored_Constraint
);
19927 Mutate_Ekind
(T
, E_Modular_Integer_Type
);
19928 Reinit_Alignment
(T
);
19929 Set_Is_Constrained
(T
);
19931 if not Is_OK_Static_Expression
(Mod_Expr
) then
19932 Flag_Non_Static_Expr
19933 ("non-static expression used for modular type bound!", Mod_Expr
);
19934 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
19936 M_Val
:= Expr_Value
(Mod_Expr
);
19940 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
19941 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
19944 if M_Val
> 2 ** Standard_Long_Integer_Size
then
19945 Check_Restriction
(No_Long_Long_Integers
, Mod_Expr
);
19948 Set_Modulus
(T
, M_Val
);
19950 -- Create bounds for the modular type based on the modulus given in
19951 -- the type declaration and then analyze and resolve those bounds.
19953 Set_Scalar_Range
(T
,
19954 Make_Range
(Sloc
(Mod_Expr
),
19955 Low_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
19956 High_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
19958 -- Properly analyze the literals for the range. We do this manually
19959 -- because we can't go calling Resolve, since we are resolving these
19960 -- bounds with the type, and this type is certainly not complete yet.
19962 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
19963 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
19964 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
19965 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
19967 -- Loop through powers of two to find number of bits required
19969 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
19973 if M_Val
= 2 ** Bits
then
19974 Set_Modular_Size
(Bits
);
19979 elsif M_Val
< 2 ** Bits
then
19980 Set_Non_Binary_Modulus
(T
);
19982 if Bits
> System_Max_Nonbinary_Modulus_Power
then
19983 Error_Msg_Uint_1
:=
19984 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
19986 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
19987 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
19991 -- In the nonbinary case, set size as per RM 13.3(55)
19993 Set_Modular_Size
(Bits
);
20000 -- If we fall through, then the size exceed System.Max_Binary_Modulus
20001 -- so we just signal an error and set the maximum size.
20003 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
20004 Error_Msg_F
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
20006 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20007 Reinit_Alignment
(T
);
20009 end Modular_Type_Declaration
;
20011 --------------------------
20012 -- New_Concatenation_Op --
20013 --------------------------
20015 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
20016 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
20019 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
20020 -- Create abbreviated declaration for the formal of a predefined
20021 -- Operator 'Op' of type 'Typ'
20023 --------------------
20024 -- Make_Op_Formal --
20025 --------------------
20027 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
20028 Formal
: Entity_Id
;
20030 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
20031 Set_Etype
(Formal
, Typ
);
20032 Set_Mechanism
(Formal
, Default_Mechanism
);
20034 end Make_Op_Formal
;
20036 -- Start of processing for New_Concatenation_Op
20039 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
20041 Mutate_Ekind
(Op
, E_Operator
);
20042 Set_Scope
(Op
, Current_Scope
);
20043 Set_Etype
(Op
, Typ
);
20044 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
20045 Set_Is_Immediately_Visible
(Op
);
20046 Set_Is_Intrinsic_Subprogram
(Op
);
20047 Set_Has_Completion
(Op
);
20048 Append_Entity
(Op
, Current_Scope
);
20050 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
20052 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20053 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20054 end New_Concatenation_Op
;
20056 -------------------------
20057 -- OK_For_Limited_Init --
20058 -------------------------
20060 -- ???Check all calls of this, and compare the conditions under which it's
20063 function OK_For_Limited_Init
20065 Exp
: Node_Id
) return Boolean
20068 return Is_CPP_Constructor_Call
(Exp
)
20069 or else (Ada_Version
>= Ada_2005
20070 and then not Debug_Flag_Dot_L
20071 and then OK_For_Limited_Init_In_05
(Typ
, Exp
));
20072 end OK_For_Limited_Init
;
20074 -------------------------------
20075 -- OK_For_Limited_Init_In_05 --
20076 -------------------------------
20078 function OK_For_Limited_Init_In_05
20080 Exp
: Node_Id
) return Boolean
20083 -- An object of a limited interface type can be initialized with any
20084 -- expression of a nonlimited descendant type. However this does not
20085 -- apply if this is a view conversion of some other expression. This
20086 -- is checked below.
20088 if Is_Class_Wide_Type
(Typ
)
20089 and then Is_Limited_Interface
(Typ
)
20090 and then not Is_Limited_Type
(Etype
(Exp
))
20091 and then Nkind
(Exp
) /= N_Type_Conversion
20096 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
20097 -- case of limited aggregates (including extension aggregates), and
20098 -- function calls. The function call may have been given in prefixed
20099 -- notation, in which case the original node is an indexed component.
20100 -- If the function is parameterless, the original node was an explicit
20101 -- dereference. The function may also be parameterless, in which case
20102 -- the source node is just an identifier.
20104 -- A branch of a conditional expression may have been removed if the
20105 -- condition is statically known. This happens during expansion, and
20106 -- thus will not happen if previous errors were encountered. The check
20107 -- will have been performed on the chosen branch, which replaces the
20108 -- original conditional expression.
20114 case Nkind
(Original_Node
(Exp
)) is
20116 | N_Extension_Aggregate
20122 when N_Identifier
=>
20123 return Present
(Entity
(Original_Node
(Exp
)))
20124 and then Ekind
(Entity
(Original_Node
(Exp
))) = E_Function
;
20126 when N_Qualified_Expression
=>
20128 OK_For_Limited_Init_In_05
20129 (Typ
, Expression
(Original_Node
(Exp
)));
20131 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
20132 -- with a function call, the expander has rewritten the call into an
20133 -- N_Type_Conversion node to force displacement of the pointer to
20134 -- reference the component containing the secondary dispatch table.
20135 -- Otherwise a type conversion is not a legal context.
20136 -- A return statement for a build-in-place function returning a
20137 -- synchronized type also introduces an unchecked conversion.
20139 when N_Type_Conversion
20140 | N_Unchecked_Type_Conversion
20142 return not Comes_From_Source
(Exp
)
20144 -- If the conversion has been rewritten, check Original_Node
20146 ((Original_Node
(Exp
) /= Exp
20148 OK_For_Limited_Init_In_05
(Typ
, Original_Node
(Exp
)))
20150 -- Otherwise, check the expression of the compiler-generated
20151 -- conversion (which is a conversion that we want to ignore
20152 -- for purposes of the limited-initialization restrictions).
20155 (Original_Node
(Exp
) = Exp
20157 OK_For_Limited_Init_In_05
(Typ
, Expression
(Exp
))));
20159 when N_Explicit_Dereference
20160 | N_Indexed_Component
20161 | N_Selected_Component
20163 return Nkind
(Exp
) = N_Function_Call
;
20165 -- A use of 'Input is a function call, hence allowed. Normally the
20166 -- attribute will be changed to a call, but the attribute by itself
20167 -- can occur with -gnatc.
20169 when N_Attribute_Reference
=>
20170 return Attribute_Name
(Original_Node
(Exp
)) = Name_Input
;
20172 -- "return raise ..." is OK
20174 when N_Raise_Expression
=>
20177 -- For a case expression, all dependent expressions must be legal
20179 when N_Case_Expression
=>
20184 Alt
:= First
(Alternatives
(Original_Node
(Exp
)));
20185 while Present
(Alt
) loop
20186 if not OK_For_Limited_Init_In_05
(Typ
, Expression
(Alt
)) then
20196 -- For an if expression, all dependent expressions must be legal
20198 when N_If_Expression
=>
20200 Then_Expr
: constant Node_Id
:=
20201 Next
(First
(Expressions
(Original_Node
(Exp
))));
20202 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
20204 return OK_For_Limited_Init_In_05
(Typ
, Then_Expr
)
20206 OK_For_Limited_Init_In_05
(Typ
, Else_Expr
);
20212 end OK_For_Limited_Init_In_05
;
20214 -------------------------------------------
20215 -- Ordinary_Fixed_Point_Type_Declaration --
20216 -------------------------------------------
20218 procedure Ordinary_Fixed_Point_Type_Declaration
20222 Loc
: constant Source_Ptr
:= Sloc
(Def
);
20223 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
20224 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
20225 Implicit_Base
: Entity_Id
;
20232 Check_Restriction
(No_Fixed_Point
, Def
);
20234 -- Create implicit base type
20237 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
20238 Set_Etype
(Implicit_Base
, Implicit_Base
);
20240 -- Analyze and process delta expression
20242 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
20244 Check_Delta_Expression
(Delta_Expr
);
20245 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
20247 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
20249 -- Compute default small from given delta, which is the largest power
20250 -- of two that does not exceed the given delta value.
20260 if Delta_Val
< Ureal_1
then
20261 while Delta_Val
< Tmp
loop
20262 Tmp
:= Tmp
/ Ureal_2
;
20263 Scale
:= Scale
+ 1;
20268 Tmp
:= Tmp
* Ureal_2
;
20269 exit when Tmp
> Delta_Val
;
20270 Scale
:= Scale
- 1;
20274 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
20277 Set_Small_Value
(Implicit_Base
, Small_Val
);
20279 -- If no range was given, set a dummy range
20281 if RRS
<= Empty_Or_Error
then
20282 Low_Val
:= -Small_Val
;
20283 High_Val
:= Small_Val
;
20285 -- Otherwise analyze and process given range
20289 Low
: constant Node_Id
:= Low_Bound
(RRS
);
20290 High
: constant Node_Id
:= High_Bound
(RRS
);
20293 Analyze_And_Resolve
(Low
, Any_Real
);
20294 Analyze_And_Resolve
(High
, Any_Real
);
20295 Check_Real_Bound
(Low
);
20296 Check_Real_Bound
(High
);
20298 -- Obtain and set the range
20300 Low_Val
:= Expr_Value_R
(Low
);
20301 High_Val
:= Expr_Value_R
(High
);
20303 if Low_Val
> High_Val
then
20304 Error_Msg_NE
("??fixed point type& has null range", Def
, T
);
20309 -- The range for both the implicit base and the declared first subtype
20310 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
20311 -- set a temporary range in place. Note that the bounds of the base
20312 -- type will be widened to be symmetrical and to fill the available
20313 -- bits when the type is frozen.
20315 -- We could do this with all discrete types, and probably should, but
20316 -- we absolutely have to do it for fixed-point, since the end-points
20317 -- of the range and the size are determined by the small value, which
20318 -- could be reset before the freeze point.
20320 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
20321 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
20323 -- Complete definition of first subtype. The inheritance of the rep item
20324 -- chain ensures that SPARK-related pragmas are not clobbered when the
20325 -- ordinary fixed point type acts as a full view of a private type.
20327 Mutate_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
20328 Set_Etype
(T
, Implicit_Base
);
20329 Reinit_Size_Align
(T
);
20330 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
20331 Set_Small_Value
(T
, Small_Val
);
20332 Set_Delta_Value
(T
, Delta_Val
);
20333 Set_Is_Constrained
(T
);
20334 end Ordinary_Fixed_Point_Type_Declaration
;
20336 ----------------------------------
20337 -- Preanalyze_Assert_Expression --
20338 ----------------------------------
20340 procedure Preanalyze_Assert_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20342 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20343 Preanalyze_Spec_Expression
(N
, T
);
20344 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20345 end Preanalyze_Assert_Expression
;
20347 -----------------------------------
20348 -- Preanalyze_Default_Expression --
20349 -----------------------------------
20351 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20352 Save_In_Default_Expr
: constant Boolean := In_Default_Expr
;
20353 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20356 In_Default_Expr
:= True;
20357 In_Spec_Expression
:= True;
20359 Preanalyze_With_Freezing_And_Resolve
(N
, T
);
20361 In_Default_Expr
:= Save_In_Default_Expr
;
20362 In_Spec_Expression
:= Save_In_Spec_Expression
;
20363 end Preanalyze_Default_Expression
;
20365 --------------------------------
20366 -- Preanalyze_Spec_Expression --
20367 --------------------------------
20369 procedure Preanalyze_Spec_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20370 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20372 In_Spec_Expression
:= True;
20373 Preanalyze_And_Resolve
(N
, T
);
20374 In_Spec_Expression
:= Save_In_Spec_Expression
;
20375 end Preanalyze_Spec_Expression
;
20377 ----------------------------------------
20378 -- Prepare_Private_Subtype_Completion --
20379 ----------------------------------------
20381 procedure Prepare_Private_Subtype_Completion
20383 Related_Nod
: Node_Id
)
20385 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
20386 Full_B
: constant Entity_Id
:= Full_View
(Id_B
);
20390 if Present
(Full_B
) then
20392 -- The Base_Type is already completed, we can complete the subtype
20393 -- now. We have to create a new entity with the same name, Thus we
20394 -- can't use Create_Itype.
20396 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
20397 Set_Is_Itype
(Full
);
20398 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
20399 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
20400 Set_Full_View
(Id
, Full
);
20403 -- The parent subtype may be private, but the base might not, in some
20404 -- nested instances. In that case, the subtype does not need to be
20405 -- exchanged. It would still be nice to make private subtypes and their
20406 -- bases consistent at all times ???
20408 if Is_Private_Type
(Id_B
) then
20409 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
20411 end Prepare_Private_Subtype_Completion
;
20413 ---------------------------
20414 -- Process_Discriminants --
20415 ---------------------------
20417 procedure Process_Discriminants
20419 Prev
: Entity_Id
:= Empty
)
20421 Elist
: constant Elist_Id
:= New_Elmt_List
;
20424 Discr_Number
: Uint
;
20425 Discr_Type
: Entity_Id
;
20426 Default_Present
: Boolean := False;
20427 Default_Not_Present
: Boolean := False;
20430 -- A composite type other than an array type can have discriminants.
20431 -- On entry, the current scope is the composite type.
20433 -- The discriminants are initially entered into the scope of the type
20434 -- via Enter_Name with the default Ekind of E_Void to prevent premature
20435 -- use, as explained at the end of this procedure.
20437 Discr
:= First
(Discriminant_Specifications
(N
));
20438 while Present
(Discr
) loop
20439 Enter_Name
(Defining_Identifier
(Discr
));
20441 -- For navigation purposes we add a reference to the discriminant
20442 -- in the entity for the type. If the current declaration is a
20443 -- completion, place references on the partial view. Otherwise the
20444 -- type is the current scope.
20446 if Present
(Prev
) then
20448 -- The references go on the partial view, if present. If the
20449 -- partial view has discriminants, the references have been
20450 -- generated already.
20452 if not Has_Discriminants
(Prev
) then
20453 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
20457 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
20460 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
20461 Check_Anonymous_Access_Component
20463 Typ
=> Defining_Identifier
(N
),
20466 Access_Def
=> Discriminant_Type
(Discr
));
20468 -- if Check_Anonymous_Access_Component replaced Discr then
20469 -- its Original_Node points to the old Discr and the access type
20470 -- for Discr_Type has already been created.
20472 if Original_Node
(Discr
) /= Discr
then
20473 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20476 Access_Definition
(Discr
, Discriminant_Type
(Discr
));
20478 -- Ada 2005 (AI-254)
20480 if Present
(Access_To_Subprogram_Definition
20481 (Discriminant_Type
(Discr
)))
20482 and then Protected_Present
(Access_To_Subprogram_Definition
20483 (Discriminant_Type
(Discr
)))
20486 Replace_Anonymous_Access_To_Protected_Subprogram
(Discr
);
20490 Find_Type
(Discriminant_Type
(Discr
));
20491 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20493 if Error_Posted
(Discriminant_Type
(Discr
)) then
20494 Discr_Type
:= Any_Type
;
20498 -- Handling of discriminants that are access types
20500 if Is_Access_Type
(Discr_Type
) then
20502 -- Ada 2005 (AI-230): Access discriminant allowed in non-
20503 -- limited record types
20505 if Ada_Version
< Ada_2005
then
20506 Check_Access_Discriminant_Requires_Limited
20507 (Discr
, Discriminant_Type
(Discr
));
20510 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
20512 ("(Ada 83) access discriminant not allowed", Discr
);
20515 -- If not access type, must be a discrete type
20517 elsif not Is_Discrete_Type
(Discr_Type
) then
20519 ("discriminants must have a discrete or access type",
20520 Discriminant_Type
(Discr
));
20523 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
20525 -- If a discriminant specification includes the assignment compound
20526 -- delimiter followed by an expression, the expression is the default
20527 -- expression of the discriminant; the default expression must be of
20528 -- the type of the discriminant. (RM 3.7.1) Since this expression is
20529 -- a default expression, we do the special preanalysis, since this
20530 -- expression does not freeze (see section "Handling of Default and
20531 -- Per-Object Expressions" in spec of package Sem).
20533 if Present
(Expression
(Discr
)) then
20534 Preanalyze_Default_Expression
(Expression
(Discr
), Discr_Type
);
20538 if Nkind
(N
) = N_Formal_Type_Declaration
then
20540 ("discriminant defaults not allowed for formal type",
20541 Expression
(Discr
));
20543 -- Flag an error for a tagged type with defaulted discriminants,
20544 -- excluding limited tagged types when compiling for Ada 2012
20545 -- (see AI05-0214).
20547 elsif Is_Tagged_Type
(Current_Scope
)
20548 and then (not Is_Limited_Type
(Current_Scope
)
20549 or else Ada_Version
< Ada_2012
)
20550 and then Comes_From_Source
(N
)
20552 -- Note: see similar test in Check_Or_Process_Discriminants, to
20553 -- handle the (illegal) case of the completion of an untagged
20554 -- view with discriminants with defaults by a tagged full view.
20555 -- We skip the check if Discr does not come from source, to
20556 -- account for the case of an untagged derived type providing
20557 -- defaults for a renamed discriminant from a private untagged
20558 -- ancestor with a tagged full view (ACATS B460006).
20560 if Ada_Version
>= Ada_2012
then
20562 ("discriminants of nonlimited tagged type cannot have"
20564 Expression
(Discr
));
20567 ("discriminants of tagged type cannot have defaults",
20568 Expression
(Discr
));
20572 Default_Present
:= True;
20573 Append_Elmt
(Expression
(Discr
), Elist
);
20575 -- Tag the defining identifiers for the discriminants with
20576 -- their corresponding default expressions from the tree.
20578 Set_Discriminant_Default_Value
20579 (Defining_Identifier
(Discr
), Expression
(Discr
));
20582 -- In gnatc or GNATprove mode, make sure set Do_Range_Check flag
20583 -- gets set unless we can be sure that no range check is required.
20585 if not Expander_Active
20588 (Expression
(Discr
), Discr_Type
, Assume_Valid
=> True)
20590 Set_Do_Range_Check
(Expression
(Discr
));
20593 -- No default discriminant value given
20596 Default_Not_Present
:= True;
20599 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
20600 -- Discr_Type but with the null-exclusion attribute
20602 if Ada_Version
>= Ada_2005
then
20604 -- Ada 2005 (AI-231): Static checks
20606 if Can_Never_Be_Null
(Discr_Type
) then
20607 Null_Exclusion_Static_Checks
(Discr
);
20609 elsif Is_Access_Type
(Discr_Type
)
20610 and then Null_Exclusion_Present
(Discr
)
20612 -- No need to check itypes because in their case this check
20613 -- was done at their point of creation
20615 and then not Is_Itype
(Discr_Type
)
20617 if Can_Never_Be_Null
(Discr_Type
) then
20619 ("`NOT NULL` not allowed (& already excludes null)",
20624 Set_Etype
(Defining_Identifier
(Discr
),
20625 Create_Null_Excluding_Itype
20627 Related_Nod
=> Discr
));
20629 -- Check for improper null exclusion if the type is otherwise
20630 -- legal for a discriminant.
20632 elsif Null_Exclusion_Present
(Discr
)
20633 and then Is_Discrete_Type
(Discr_Type
)
20636 ("null exclusion can only apply to an access type", Discr
);
20639 -- Ada 2005 (AI-402): access discriminants of nonlimited types
20640 -- can't have defaults. Synchronized types, or types that are
20641 -- explicitly limited are fine, but special tests apply to derived
20642 -- types in generics: in a generic body we have to assume the
20643 -- worst, and therefore defaults are not allowed if the parent is
20644 -- a generic formal private type (see ACATS B370001).
20646 if Is_Access_Type
(Discr_Type
) and then Default_Present
then
20647 if Ekind
(Discr_Type
) /= E_Anonymous_Access_Type
20648 or else Is_Limited_Record
(Current_Scope
)
20649 or else Is_Concurrent_Type
(Current_Scope
)
20650 or else Is_Concurrent_Record_Type
(Current_Scope
)
20651 or else Ekind
(Current_Scope
) = E_Limited_Private_Type
20653 if not Is_Derived_Type
(Current_Scope
)
20654 or else not Is_Generic_Type
(Etype
(Current_Scope
))
20655 or else not In_Package_Body
(Scope
(Etype
(Current_Scope
)))
20656 or else Limited_Present
20657 (Type_Definition
(Parent
(Current_Scope
)))
20663 ("access discriminants of nonlimited types cannot "
20664 & "have defaults", Expression
(Discr
));
20667 elsif Present
(Expression
(Discr
)) then
20669 ("(Ada 2005) access discriminants of nonlimited types "
20670 & "cannot have defaults", Expression
(Discr
));
20675 -- A discriminant cannot be effectively volatile (SPARK RM 7.1.3(4)).
20676 -- This check is relevant only when SPARK_Mode is on as it is not a
20677 -- standard Ada legality rule. The only way for a discriminant to be
20678 -- effectively volatile is to have an effectively volatile type, so
20679 -- we check this directly, because the Ekind of Discr might not be
20680 -- set yet (to help preventing cascaded errors on derived types).
20683 and then Is_Effectively_Volatile
(Discr_Type
)
20685 Error_Msg_N
("discriminant cannot be volatile", Discr
);
20691 -- An element list consisting of the default expressions of the
20692 -- discriminants is constructed in the above loop and used to set
20693 -- the Discriminant_Constraint attribute for the type. If an object
20694 -- is declared of this (record or task) type without any explicit
20695 -- discriminant constraint given, this element list will form the
20696 -- actual parameters for the corresponding initialization procedure
20699 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
20700 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
20702 -- Default expressions must be provided either for all or for none
20703 -- of the discriminants of a discriminant part. (RM 3.7.1)
20705 if Default_Present
and then Default_Not_Present
then
20707 ("incomplete specification of defaults for discriminants", N
);
20710 -- The use of the name of a discriminant is not allowed in default
20711 -- expressions of a discriminant part if the specification of the
20712 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
20714 -- To detect this, the discriminant names are entered initially with an
20715 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
20716 -- attempt to use a void entity (for example in an expression that is
20717 -- type-checked) produces the error message: premature usage. Now after
20718 -- completing the semantic analysis of the discriminant part, we can set
20719 -- the Ekind of all the discriminants appropriately.
20721 Discr
:= First
(Discriminant_Specifications
(N
));
20722 Discr_Number
:= Uint_1
;
20723 while Present
(Discr
) loop
20724 Id
:= Defining_Identifier
(Discr
);
20726 if Ekind
(Id
) = E_In_Parameter
then
20727 Reinit_Field_To_Zero
(Id
, F_Discriminal_Link
);
20730 Mutate_Ekind
(Id
, E_Discriminant
);
20731 Reinit_Component_Location
(Id
);
20733 Set_Discriminant_Number
(Id
, Discr_Number
);
20735 -- Make sure this is always set, even in illegal programs
20737 Set_Corresponding_Discriminant
(Id
, Empty
);
20739 -- Initialize the Original_Record_Component to the entity itself.
20740 -- Inherit_Components will propagate the right value to
20741 -- discriminants in derived record types.
20743 Set_Original_Record_Component
(Id
, Id
);
20745 -- Create the discriminal for the discriminant
20747 Build_Discriminal
(Id
);
20750 Discr_Number
:= Discr_Number
+ 1;
20753 Set_Has_Discriminants
(Current_Scope
);
20754 end Process_Discriminants
;
20756 -----------------------
20757 -- Process_Full_View --
20758 -----------------------
20760 -- WARNING: This routine manages Ghost regions. Return statements must be
20761 -- replaced by gotos which jump to the end of the routine and restore the
20764 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
20765 procedure Collect_Implemented_Interfaces
20767 Ifaces
: Elist_Id
);
20768 -- Ada 2005: Gather all the interfaces that Typ directly or
20769 -- inherently implements. Duplicate entries are not added to
20770 -- the list Ifaces.
20772 ------------------------------------
20773 -- Collect_Implemented_Interfaces --
20774 ------------------------------------
20776 procedure Collect_Implemented_Interfaces
20781 Iface_Elmt
: Elmt_Id
;
20784 -- Abstract interfaces are only associated with tagged record types
20786 if not Is_Tagged_Type
(Typ
) or else not Is_Record_Type
(Typ
) then
20790 -- Recursively climb to the ancestors
20792 if Etype
(Typ
) /= Typ
20794 -- Protect the frontend against wrong cyclic declarations like:
20796 -- type B is new A with private;
20797 -- type C is new A with private;
20799 -- type B is new C with null record;
20800 -- type C is new B with null record;
20802 and then Etype
(Typ
) /= Priv_T
20803 and then Etype
(Typ
) /= Full_T
20805 -- Keep separate the management of private type declarations
20807 if Ekind
(Typ
) = E_Record_Type_With_Private
then
20809 -- Handle the following illegal usage:
20810 -- type Private_Type is tagged private;
20812 -- type Private_Type is new Type_Implementing_Iface;
20814 if Present
(Full_View
(Typ
))
20815 and then Etype
(Typ
) /= Full_View
(Typ
)
20817 if Is_Interface
(Etype
(Typ
)) then
20818 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
20821 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
20824 -- Non-private types
20827 if Is_Interface
(Etype
(Typ
)) then
20828 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
20831 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
20835 -- Handle entities in the list of abstract interfaces
20837 if Present
(Interfaces
(Typ
)) then
20838 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
20839 while Present
(Iface_Elmt
) loop
20840 Iface
:= Node
(Iface_Elmt
);
20842 pragma Assert
(Is_Interface
(Iface
));
20844 if not Contain_Interface
(Iface
, Ifaces
) then
20845 Append_Elmt
(Iface
, Ifaces
);
20846 Collect_Implemented_Interfaces
(Iface
, Ifaces
);
20849 Next_Elmt
(Iface_Elmt
);
20852 end Collect_Implemented_Interfaces
;
20856 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
20857 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
20858 -- Save the Ghost-related attributes to restore on exit
20860 Full_Indic
: Node_Id
;
20861 Full_Parent
: Entity_Id
;
20862 Priv_Parent
: Entity_Id
;
20864 -- Start of processing for Process_Full_View
20867 Mark_And_Set_Ghost_Completion
(N
, Priv_T
);
20869 -- First some sanity checks that must be done after semantic
20870 -- decoration of the full view and thus cannot be placed with other
20871 -- similar checks in Find_Type_Name
20873 if not Is_Limited_Type
(Priv_T
)
20874 and then (Is_Limited_Type
(Full_T
)
20875 or else Is_Limited_Composite
(Full_T
))
20877 if In_Instance
then
20881 ("completion of nonlimited type cannot be limited", Full_T
);
20882 Explain_Limited_Type
(Full_T
, Full_T
);
20885 elsif Is_Abstract_Type
(Full_T
)
20886 and then not Is_Abstract_Type
(Priv_T
)
20889 ("completion of nonabstract type cannot be abstract", Full_T
);
20891 elsif Is_Tagged_Type
(Priv_T
)
20892 and then Is_Limited_Type
(Priv_T
)
20893 and then not Is_Limited_Type
(Full_T
)
20895 -- If pragma CPP_Class was applied to the private declaration
20896 -- propagate the limitedness to the full-view
20898 if Is_CPP_Class
(Priv_T
) then
20899 Set_Is_Limited_Record
(Full_T
);
20901 -- GNAT allow its own definition of Limited_Controlled to disobey
20902 -- this rule in order in ease the implementation. This test is safe
20903 -- because Root_Controlled is defined in a child of System that
20904 -- normal programs are not supposed to use.
20906 elsif Is_RTE
(Etype
(Full_T
), RE_Root_Controlled
) then
20907 Set_Is_Limited_Composite
(Full_T
);
20910 ("completion of limited tagged type must be limited", Full_T
);
20913 elsif Is_Generic_Type
(Priv_T
) then
20914 Error_Msg_N
("generic type cannot have a completion", Full_T
);
20917 -- Check that ancestor interfaces of private and full views are
20918 -- consistent. We omit this check for synchronized types because
20919 -- they are performed on the corresponding record type when frozen.
20921 if Ada_Version
>= Ada_2005
20922 and then Is_Tagged_Type
(Priv_T
)
20923 and then Is_Tagged_Type
(Full_T
)
20924 and then not Is_Concurrent_Type
(Full_T
)
20928 Priv_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
20929 Full_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
20932 Collect_Implemented_Interfaces
(Priv_T
, Priv_T_Ifaces
);
20933 Collect_Implemented_Interfaces
(Full_T
, Full_T_Ifaces
);
20935 -- Ada 2005 (AI-251): The partial view shall be a descendant of
20936 -- an interface type if and only if the full type is descendant
20937 -- of the interface type (AARM 7.3 (7.3/2)).
20939 Iface
:= Find_Hidden_Interface
(Priv_T_Ifaces
, Full_T_Ifaces
);
20941 if Present
(Iface
) then
20943 ("interface in partial view& not implemented by full type "
20944 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
20947 Iface
:= Find_Hidden_Interface
(Full_T_Ifaces
, Priv_T_Ifaces
);
20949 if Present
(Iface
) then
20951 ("interface & not implemented by partial view "
20952 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
20957 if Is_Tagged_Type
(Priv_T
)
20958 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
20959 and then Is_Derived_Type
(Full_T
)
20961 Priv_Parent
:= Etype
(Priv_T
);
20963 -- The full view of a private extension may have been transformed
20964 -- into an unconstrained derived type declaration and a subtype
20965 -- declaration (see build_derived_record_type for details).
20967 if Nkind
(N
) = N_Subtype_Declaration
then
20968 Full_Indic
:= Subtype_Indication
(N
);
20969 Full_Parent
:= Etype
(Base_Type
(Full_T
));
20971 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
20972 Full_Parent
:= Etype
(Full_T
);
20975 -- Check that the parent type of the full type is a descendant of
20976 -- the ancestor subtype given in the private extension. If either
20977 -- entity has an Etype equal to Any_Type then we had some previous
20978 -- error situation [7.3(8)].
20980 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
20983 -- Ada 2005 (AI-251): Interfaces in the full type can be given in
20984 -- any order. Therefore we don't have to check that its parent must
20985 -- be a descendant of the parent of the private type declaration.
20987 elsif Is_Interface
(Priv_Parent
)
20988 and then Is_Interface
(Full_Parent
)
20992 -- Ada 2005 (AI-251): If the parent of the private type declaration
20993 -- is an interface there is no need to check that it is an ancestor
20994 -- of the associated full type declaration. The required tests for
20995 -- this case are performed by Build_Derived_Record_Type.
20997 elsif not Is_Interface
(Base_Type
(Priv_Parent
))
20998 and then not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
)
21001 ("parent of full type must descend from parent of private "
21002 & "extension", Full_Indic
);
21004 -- First check a formal restriction, and then proceed with checking
21005 -- Ada rules. Since the formal restriction is not a serious error, we
21006 -- don't prevent further error detection for this check, hence the
21010 -- Check the rules of 7.3(10): if the private extension inherits
21011 -- known discriminants, then the full type must also inherit those
21012 -- discriminants from the same (ancestor) type, and the parent
21013 -- subtype of the full type must be constrained if and only if
21014 -- the ancestor subtype of the private extension is constrained.
21016 if No
(Discriminant_Specifications
(Parent
(Priv_T
)))
21017 and then not Has_Unknown_Discriminants
(Priv_T
)
21018 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
21021 Priv_Indic
: constant Node_Id
:=
21022 Subtype_Indication
(Parent
(Priv_T
));
21024 Priv_Constr
: constant Boolean :=
21025 Is_Constrained
(Priv_Parent
)
21027 Nkind
(Priv_Indic
) = N_Subtype_Indication
21029 Is_Constrained
(Entity
(Priv_Indic
));
21031 Full_Constr
: constant Boolean :=
21032 Is_Constrained
(Full_Parent
)
21034 Nkind
(Full_Indic
) = N_Subtype_Indication
21036 Is_Constrained
(Entity
(Full_Indic
));
21038 Priv_Discr
: Entity_Id
;
21039 Full_Discr
: Entity_Id
;
21042 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
21043 Full_Discr
:= First_Discriminant
(Full_Parent
);
21044 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
21045 if Original_Record_Component
(Priv_Discr
) =
21046 Original_Record_Component
(Full_Discr
)
21048 Corresponding_Discriminant
(Priv_Discr
) =
21049 Corresponding_Discriminant
(Full_Discr
)
21056 Next_Discriminant
(Priv_Discr
);
21057 Next_Discriminant
(Full_Discr
);
21060 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
21062 ("full view must inherit discriminants of the parent "
21063 & "type used in the private extension", Full_Indic
);
21065 elsif Priv_Constr
and then not Full_Constr
then
21067 ("parent subtype of full type must be constrained",
21070 elsif Full_Constr
and then not Priv_Constr
then
21072 ("parent subtype of full type must be unconstrained",
21077 -- Check the rules of 7.3(12): if a partial view has neither
21078 -- known or unknown discriminants, then the full type
21079 -- declaration shall define a definite subtype.
21081 elsif not Has_Unknown_Discriminants
(Priv_T
)
21082 and then not Has_Discriminants
(Priv_T
)
21083 and then not Is_Constrained
(Full_T
)
21086 ("full view must define a constrained type if partial view "
21087 & "has no discriminants", Full_T
);
21090 -- Do we implement the following properly???
21091 -- If the ancestor subtype of a private extension has constrained
21092 -- discriminants, then the parent subtype of the full view shall
21093 -- impose a statically matching constraint on those discriminants
21098 -- For untagged types, verify that a type without discriminants is
21099 -- not completed with an unconstrained type. A separate error message
21100 -- is produced if the full type has defaulted discriminants.
21102 if Is_Definite_Subtype
(Priv_T
)
21103 and then not Is_Definite_Subtype
(Full_T
)
21105 Error_Msg_Sloc
:= Sloc
(Parent
(Priv_T
));
21107 ("full view of& not compatible with declaration#",
21110 if not Is_Tagged_Type
(Full_T
) then
21112 ("\one is constrained, the other unconstrained", Full_T
);
21117 -- AI-419: verify that the use of "limited" is consistent
21120 Orig_Decl
: constant Node_Id
:= Original_Node
(N
);
21123 if Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21124 and then Nkind
(Orig_Decl
) = N_Full_Type_Declaration
21126 (Type_Definition
(Orig_Decl
)) = N_Derived_Type_Definition
21128 if not Limited_Present
(Parent
(Priv_T
))
21129 and then not Synchronized_Present
(Parent
(Priv_T
))
21130 and then Limited_Present
(Type_Definition
(Orig_Decl
))
21133 ("full view of non-limited extension cannot be limited", N
);
21135 -- Conversely, if the partial view carries the limited keyword,
21136 -- the full view must as well, even if it may be redundant.
21138 elsif Limited_Present
(Parent
(Priv_T
))
21139 and then not Limited_Present
(Type_Definition
(Orig_Decl
))
21142 ("full view of limited extension must be explicitly limited",
21148 -- Ada 2005 (AI-443): A synchronized private extension must be
21149 -- completed by a task or protected type.
21151 if Ada_Version
>= Ada_2005
21152 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21153 and then Synchronized_Present
(Parent
(Priv_T
))
21154 and then not Is_Concurrent_Type
(Full_T
)
21156 Error_Msg_N
("full view of synchronized extension must " &
21157 "be synchronized type", N
);
21160 -- Ada 2005 AI-363: if the full view has discriminants with
21161 -- defaults, it is illegal to declare constrained access subtypes
21162 -- whose designated type is the current type. This allows objects
21163 -- of the type that are declared in the heap to be unconstrained.
21165 if not Has_Unknown_Discriminants
(Priv_T
)
21166 and then not Has_Discriminants
(Priv_T
)
21167 and then Has_Defaulted_Discriminants
(Full_T
)
21169 Set_Has_Constrained_Partial_View
(Base_Type
(Full_T
));
21170 Set_Has_Constrained_Partial_View
(Priv_T
);
21173 -- Create a full declaration for all its subtypes recorded in
21174 -- Private_Dependents and swap them similarly to the base type. These
21175 -- are subtypes that have been define before the full declaration of
21176 -- the private type. We also swap the entry in Private_Dependents list
21177 -- so we can properly restore the private view on exit from the scope.
21180 Priv_Elmt
: Elmt_Id
;
21181 Priv_Scop
: Entity_Id
;
21186 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
21187 while Present
(Priv_Elmt
) loop
21188 Priv
:= Node
(Priv_Elmt
);
21189 Priv_Scop
:= Scope
(Priv
);
21191 if Ekind
(Priv
) in E_Private_Subtype
21192 | E_Limited_Private_Subtype
21193 | E_Record_Subtype_With_Private
21195 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
21196 Set_Is_Itype
(Full
);
21197 Set_Parent
(Full
, Parent
(Priv
));
21198 Set_Associated_Node_For_Itype
(Full
, N
);
21200 -- Now we need to complete the private subtype, but since the
21201 -- base type has already been swapped, we must also swap the
21202 -- subtypes (and thus, reverse the arguments in the call to
21203 -- Complete_Private_Subtype). Also note that we may need to
21204 -- re-establish the scope of the private subtype.
21206 Copy_And_Swap
(Priv
, Full
);
21208 if not In_Open_Scopes
(Priv_Scop
) then
21209 Push_Scope
(Priv_Scop
);
21212 -- Reset Priv_Scop to Empty to indicate no scope was pushed
21214 Priv_Scop
:= Empty
;
21217 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
21218 Set_Full_View
(Full
, Priv
);
21220 if Present
(Priv_Scop
) then
21224 Replace_Elmt
(Priv_Elmt
, Full
);
21227 Next_Elmt
(Priv_Elmt
);
21232 Disp_Typ
: Entity_Id
;
21233 Full_List
: Elist_Id
;
21235 Prim_Elmt
: Elmt_Id
;
21236 Priv_List
: Elist_Id
;
21240 L
: Elist_Id
) return Boolean;
21241 -- Determine whether list L contains element E
21249 L
: Elist_Id
) return Boolean
21251 List_Elmt
: Elmt_Id
;
21254 List_Elmt
:= First_Elmt
(L
);
21255 while Present
(List_Elmt
) loop
21256 if Node
(List_Elmt
) = E
then
21260 Next_Elmt
(List_Elmt
);
21266 -- Start of processing
21269 -- If the private view was tagged, copy the new primitive operations
21270 -- from the private view to the full view.
21272 if Is_Tagged_Type
(Full_T
) then
21273 if Is_Tagged_Type
(Priv_T
) then
21274 Priv_List
:= Primitive_Operations
(Priv_T
);
21275 Prim_Elmt
:= First_Elmt
(Priv_List
);
21277 -- In the case of a concurrent type completing a private tagged
21278 -- type, primitives may have been declared in between the two
21279 -- views. These subprograms need to be wrapped the same way
21280 -- entries and protected procedures are handled because they
21281 -- cannot be directly shared by the two views.
21283 if Is_Concurrent_Type
(Full_T
) then
21285 Conc_Typ
: constant Entity_Id
:=
21286 Corresponding_Record_Type
(Full_T
);
21287 Curr_Nod
: Node_Id
:= Parent
(Conc_Typ
);
21288 Wrap_Spec
: Node_Id
;
21291 while Present
(Prim_Elmt
) loop
21292 Prim
:= Node
(Prim_Elmt
);
21294 if Comes_From_Source
(Prim
)
21295 and then not Is_Abstract_Subprogram
(Prim
)
21298 Make_Subprogram_Declaration
(Sloc
(Prim
),
21302 Obj_Typ
=> Conc_Typ
,
21304 Parameter_Specifications
21307 Insert_After
(Curr_Nod
, Wrap_Spec
);
21308 Curr_Nod
:= Wrap_Spec
;
21310 Analyze
(Wrap_Spec
);
21312 -- Remove the wrapper from visibility to avoid
21313 -- spurious conflict with the wrapped entity.
21315 Set_Is_Immediately_Visible
21316 (Defining_Entity
(Specification
(Wrap_Spec
)),
21320 Next_Elmt
(Prim_Elmt
);
21326 -- For nonconcurrent types, transfer explicit primitives, but
21327 -- omit those inherited from the parent of the private view
21328 -- since they will be re-inherited later on.
21331 Full_List
:= Primitive_Operations
(Full_T
);
21332 while Present
(Prim_Elmt
) loop
21333 Prim
:= Node
(Prim_Elmt
);
21335 if Comes_From_Source
(Prim
)
21336 and then not Contains
(Prim
, Full_List
)
21338 Append_Elmt
(Prim
, Full_List
);
21341 Next_Elmt
(Prim_Elmt
);
21345 -- Untagged private view
21348 Full_List
:= Primitive_Operations
(Full_T
);
21350 -- In this case the partial view is untagged, so here we locate
21351 -- all of the earlier primitives that need to be treated as
21352 -- dispatching (those that appear between the two views). Note
21353 -- that these additional operations must all be new operations
21354 -- (any earlier operations that override inherited operations
21355 -- of the full view will already have been inserted in the
21356 -- primitives list, marked by Check_Operation_From_Private_View
21357 -- as dispatching. Note that implicit "/=" operators are
21358 -- excluded from being added to the primitives list since they
21359 -- shouldn't be treated as dispatching (tagged "/=" is handled
21362 Prim
:= Next_Entity
(Full_T
);
21363 while Present
(Prim
) and then Prim
/= Priv_T
loop
21364 if Ekind
(Prim
) in E_Procedure | E_Function
then
21365 Disp_Typ
:= Find_Dispatching_Type
(Prim
);
21367 if Disp_Typ
= Full_T
21368 and then (Chars
(Prim
) /= Name_Op_Ne
21369 or else Comes_From_Source
(Prim
))
21371 Check_Controlling_Formals
(Full_T
, Prim
);
21373 if Is_Suitable_Primitive
(Prim
)
21374 and then not Is_Dispatching_Operation
(Prim
)
21376 Append_Elmt
(Prim
, Full_List
);
21377 Set_Is_Dispatching_Operation
(Prim
);
21378 Set_DT_Position_Value
(Prim
, No_Uint
);
21381 elsif Is_Dispatching_Operation
(Prim
)
21382 and then Disp_Typ
/= Full_T
21384 -- Verify that it is not otherwise controlled by a
21385 -- formal or a return value of type T.
21387 Check_Controlling_Formals
(Disp_Typ
, Prim
);
21391 Next_Entity
(Prim
);
21395 -- For the tagged case, the two views can share the same primitive
21396 -- operations list and the same class-wide type. Update attributes
21397 -- of the class-wide type which depend on the full declaration.
21399 if Is_Tagged_Type
(Priv_T
) then
21400 Set_Direct_Primitive_Operations
(Priv_T
, Full_List
);
21401 Set_Class_Wide_Type
21402 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
21404 Propagate_Concurrent_Flags
(Class_Wide_Type
(Priv_T
), Full_T
);
21407 -- For untagged types, copy the primitives across from the private
21408 -- view to the full view (when extensions are allowed), for support
21409 -- of prefixed calls (when extensions are enabled).
21411 elsif Extensions_Allowed
then
21412 Priv_List
:= Primitive_Operations
(Priv_T
);
21413 Prim_Elmt
:= First_Elmt
(Priv_List
);
21415 Full_List
:= Primitive_Operations
(Full_T
);
21416 while Present
(Prim_Elmt
) loop
21417 Prim
:= Node
(Prim_Elmt
);
21418 Append_Elmt
(Prim
, Full_List
);
21419 Next_Elmt
(Prim_Elmt
);
21424 -- Ada 2005 AI 161: Check preelaborable initialization consistency
21426 if Known_To_Have_Preelab_Init
(Priv_T
) then
21428 -- Case where there is a pragma Preelaborable_Initialization. We
21429 -- always allow this in predefined units, which is cheating a bit,
21430 -- but it means we don't have to struggle to meet the requirements in
21431 -- the RM for having Preelaborable Initialization. Otherwise we
21432 -- require that the type meets the RM rules. But we can't check that
21433 -- yet, because of the rule about overriding Initialize, so we simply
21434 -- set a flag that will be checked at freeze time.
21436 if not In_Predefined_Unit
(Full_T
) then
21437 Set_Must_Have_Preelab_Init
(Full_T
);
21441 -- If pragma CPP_Class was applied to the private type declaration,
21442 -- propagate it now to the full type declaration.
21444 if Is_CPP_Class
(Priv_T
) then
21445 Set_Is_CPP_Class
(Full_T
);
21446 Set_Convention
(Full_T
, Convention_CPP
);
21448 -- Check that components of imported CPP types do not have default
21451 Check_CPP_Type_Has_No_Defaults
(Full_T
);
21454 -- If the private view has user specified stream attributes, then so has
21457 -- Why the test, how could these flags be already set in Full_T ???
21459 if Has_Specified_Stream_Read
(Priv_T
) then
21460 Set_Has_Specified_Stream_Read
(Full_T
);
21463 if Has_Specified_Stream_Write
(Priv_T
) then
21464 Set_Has_Specified_Stream_Write
(Full_T
);
21467 if Has_Specified_Stream_Input
(Priv_T
) then
21468 Set_Has_Specified_Stream_Input
(Full_T
);
21471 if Has_Specified_Stream_Output
(Priv_T
) then
21472 Set_Has_Specified_Stream_Output
(Full_T
);
21475 -- Propagate Default_Initial_Condition-related attributes from the
21476 -- partial view to the full view.
21478 Propagate_DIC_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21480 -- And to the underlying full view, if any
21482 if Is_Private_Type
(Full_T
)
21483 and then Present
(Underlying_Full_View
(Full_T
))
21485 Propagate_DIC_Attributes
21486 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21489 -- Propagate invariant-related attributes from the partial view to the
21492 Propagate_Invariant_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21494 -- And to the underlying full view, if any
21496 if Is_Private_Type
(Full_T
)
21497 and then Present
(Underlying_Full_View
(Full_T
))
21499 Propagate_Invariant_Attributes
21500 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21503 -- AI12-0041: Detect an attempt to inherit a class-wide type invariant
21504 -- in the full view without advertising the inheritance in the partial
21505 -- view. This can only occur when the partial view has no parent type
21506 -- and the full view has an interface as a parent. Any other scenarios
21507 -- are illegal because implemented interfaces must match between the
21510 if Is_Tagged_Type
(Priv_T
) and then Is_Tagged_Type
(Full_T
) then
21512 Full_Par
: constant Entity_Id
:= Etype
(Full_T
);
21513 Priv_Par
: constant Entity_Id
:= Etype
(Priv_T
);
21516 if not Is_Interface
(Priv_Par
)
21517 and then Is_Interface
(Full_Par
)
21518 and then Has_Inheritable_Invariants
(Full_Par
)
21521 ("hidden inheritance of class-wide type invariants not "
21527 -- Propagate predicates to full type, and predicate function if already
21528 -- defined. It is not clear that this can actually happen? the partial
21529 -- view cannot be frozen yet, and the predicate function has not been
21530 -- built. Still it is a cheap check and seems safer to make it.
21532 Propagate_Predicate_Attributes
(Full_T
, Priv_T
);
21534 if Is_Private_Type
(Full_T
)
21535 and then Present
(Underlying_Full_View
(Full_T
))
21537 Propagate_Predicate_Attributes
21538 (Underlying_Full_View
(Full_T
), Priv_T
);
21542 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
21543 end Process_Full_View
;
21545 -----------------------------------
21546 -- Process_Incomplete_Dependents --
21547 -----------------------------------
21549 procedure Process_Incomplete_Dependents
21551 Full_T
: Entity_Id
;
21554 Inc_Elmt
: Elmt_Id
;
21555 Priv_Dep
: Entity_Id
;
21556 New_Subt
: Entity_Id
;
21558 Disc_Constraint
: Elist_Id
;
21561 if No
(Private_Dependents
(Inc_T
)) then
21565 -- Itypes that may be generated by the completion of an incomplete
21566 -- subtype are not used by the back-end and not attached to the tree.
21567 -- They are created only for constraint-checking purposes.
21569 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
21570 while Present
(Inc_Elmt
) loop
21571 Priv_Dep
:= Node
(Inc_Elmt
);
21573 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
21575 -- An Access_To_Subprogram type may have a return type or a
21576 -- parameter type that is incomplete. Replace with the full view.
21578 if Etype
(Priv_Dep
) = Inc_T
then
21579 Set_Etype
(Priv_Dep
, Full_T
);
21583 Formal
: Entity_Id
;
21586 Formal
:= First_Formal
(Priv_Dep
);
21587 while Present
(Formal
) loop
21588 if Etype
(Formal
) = Inc_T
then
21589 Set_Etype
(Formal
, Full_T
);
21592 Next_Formal
(Formal
);
21596 elsif Is_Overloadable
(Priv_Dep
) then
21598 -- If a subprogram in the incomplete dependents list is primitive
21599 -- for a tagged full type then mark it as a dispatching operation,
21600 -- check whether it overrides an inherited subprogram, and check
21601 -- restrictions on its controlling formals. Note that a protected
21602 -- operation is never dispatching: only its wrapper operation
21603 -- (which has convention Ada) is.
21605 if Is_Tagged_Type
(Full_T
)
21606 and then Is_Primitive
(Priv_Dep
)
21607 and then Convention
(Priv_Dep
) /= Convention_Protected
21609 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
21610 Set_Is_Dispatching_Operation
(Priv_Dep
);
21611 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
21614 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
21616 -- Can happen during processing of a body before the completion
21617 -- of a TA type. Ignore, because spec is also on dependent list.
21621 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
21622 -- corresponding subtype of the full view.
21624 elsif Ekind
(Priv_Dep
) = E_Incomplete_Subtype
21625 and then Comes_From_Source
(Priv_Dep
)
21627 Set_Subtype_Indication
21628 (Parent
(Priv_Dep
), New_Occurrence_Of
(Full_T
, Sloc
(Priv_Dep
)));
21629 Reinit_Field_To_Zero
21630 (Priv_Dep
, F_Private_Dependents
,
21631 Old_Ekind
=> E_Incomplete_Subtype
);
21632 Mutate_Ekind
(Priv_Dep
, Subtype_Kind
(Ekind
(Full_T
)));
21633 Set_Etype
(Priv_Dep
, Full_T
);
21634 Set_Analyzed
(Parent
(Priv_Dep
), False);
21636 -- Reanalyze the declaration, suppressing the call to Enter_Name
21637 -- to avoid duplicate names.
21639 Analyze_Subtype_Declaration
21640 (N
=> Parent
(Priv_Dep
),
21643 -- Dependent is a subtype
21646 -- We build a new subtype indication using the full view of the
21647 -- incomplete parent. The discriminant constraints have been
21648 -- elaborated already at the point of the subtype declaration.
21650 New_Subt
:= Create_Itype
(E_Void
, N
);
21652 if Has_Discriminants
(Full_T
) then
21653 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
21655 Disc_Constraint
:= No_Elist
;
21658 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
21659 Set_Full_View
(Priv_Dep
, New_Subt
);
21662 Next_Elmt
(Inc_Elmt
);
21664 end Process_Incomplete_Dependents
;
21666 --------------------------------
21667 -- Process_Range_Expr_In_Decl --
21668 --------------------------------
21670 procedure Process_Range_Expr_In_Decl
21673 Subtyp
: Entity_Id
:= Empty
;
21674 Check_List
: List_Id
:= No_List
)
21677 R_Checks
: Check_Result
;
21678 Insert_Node
: Node_Id
;
21679 Def_Id
: Entity_Id
;
21682 Analyze_And_Resolve
(R
, Base_Type
(T
));
21684 if Nkind
(R
) = N_Range
then
21685 Lo
:= Low_Bound
(R
);
21686 Hi
:= High_Bound
(R
);
21688 -- Validity checks on the range of a quantified expression are
21689 -- delayed until the construct is transformed into a loop.
21691 if Nkind
(Parent
(R
)) = N_Loop_Parameter_Specification
21692 and then Nkind
(Parent
(Parent
(R
))) = N_Quantified_Expression
21696 -- We need to ensure validity of the bounds here, because if we
21697 -- go ahead and do the expansion, then the expanded code will get
21698 -- analyzed with range checks suppressed and we miss the check.
21700 -- WARNING: The capture of the range bounds with xxx_FIRST/_LAST and
21701 -- the temporaries generated by routine Remove_Side_Effects by means
21702 -- of validity checks must use the same names. When a range appears
21703 -- in the parent of a generic, the range is processed with checks
21704 -- disabled as part of the generic context and with checks enabled
21705 -- for code generation purposes. This leads to link issues as the
21706 -- generic contains references to xxx_FIRST/_LAST, but the inlined
21707 -- template sees the temporaries generated by Remove_Side_Effects.
21710 Validity_Check_Range
(R
, Subtyp
);
21713 -- If there were errors in the declaration, try and patch up some
21714 -- common mistakes in the bounds. The cases handled are literals
21715 -- which are Integer where the expected type is Real and vice versa.
21716 -- These corrections allow the compilation process to proceed further
21717 -- along since some basic assumptions of the format of the bounds
21720 if Etype
(R
) = Any_Type
then
21721 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
21723 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
21725 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
21727 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
21729 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
21731 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
21733 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
21735 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
21742 -- If the bounds of the range have been mistakenly given as string
21743 -- literals (perhaps in place of character literals), then an error
21744 -- has already been reported, but we rewrite the string literal as a
21745 -- bound of the range's type to avoid blowups in later processing
21746 -- that looks at static values.
21748 if Nkind
(Lo
) = N_String_Literal
then
21750 Make_Attribute_Reference
(Sloc
(Lo
),
21751 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Lo
)),
21752 Attribute_Name
=> Name_First
));
21753 Analyze_And_Resolve
(Lo
);
21756 if Nkind
(Hi
) = N_String_Literal
then
21758 Make_Attribute_Reference
(Sloc
(Hi
),
21759 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Hi
)),
21760 Attribute_Name
=> Name_First
));
21761 Analyze_And_Resolve
(Hi
);
21764 -- If bounds aren't scalar at this point then exit, avoiding
21765 -- problems with further processing of the range in this procedure.
21767 if not Is_Scalar_Type
(Etype
(Lo
)) then
21771 -- Resolve (actually Sem_Eval) has checked that the bounds are in
21772 -- then range of the base type. Here we check whether the bounds
21773 -- are in the range of the subtype itself. Note that if the bounds
21774 -- represent the null range the Constraint_Error exception should
21777 -- Capture values of bounds and generate temporaries for them
21778 -- if needed, before applying checks, since checks may cause
21779 -- duplication of the expression without forcing evaluation.
21781 -- The forced evaluation removes side effects from expressions,
21782 -- which should occur also in GNATprove mode. Otherwise, we end up
21783 -- with unexpected insertions of actions at places where this is
21784 -- not supposed to occur, e.g. on default parameters of a call.
21786 if Expander_Active
or GNATprove_Mode
then
21788 -- Call Force_Evaluation to create declarations as needed
21789 -- to deal with side effects, and also create typ_FIRST/LAST
21790 -- entities for bounds if we have a subtype name.
21792 -- Note: we do this transformation even if expansion is not
21793 -- active if we are in GNATprove_Mode since the transformation
21794 -- is in general required to ensure that the resulting tree has
21795 -- proper Ada semantics.
21798 (Lo
, Related_Id
=> Subtyp
, Is_Low_Bound
=> True);
21800 (Hi
, Related_Id
=> Subtyp
, Is_High_Bound
=> True);
21803 -- We use a flag here instead of suppressing checks on the type
21804 -- because the type we check against isn't necessarily the place
21805 -- where we put the check.
21807 R_Checks
:= Get_Range_Checks
(R
, T
);
21809 -- Look up tree to find an appropriate insertion point. We can't
21810 -- just use insert_actions because later processing depends on
21811 -- the insertion node. Prior to Ada 2012 the insertion point could
21812 -- only be a declaration or a loop, but quantified expressions can
21813 -- appear within any context in an expression, and the insertion
21814 -- point can be any statement, pragma, or declaration.
21816 Insert_Node
:= Parent
(R
);
21817 while Present
(Insert_Node
) loop
21819 Nkind
(Insert_Node
) in N_Declaration
21821 Nkind
(Insert_Node
) not in N_Component_Declaration
21822 | N_Loop_Parameter_Specification
21823 | N_Function_Specification
21824 | N_Procedure_Specification
;
21826 exit when Nkind
(Insert_Node
) in
21827 N_Later_Decl_Item |
21828 N_Statement_Other_Than_Procedure_Call |
21829 N_Procedure_Call_Statement |
21832 Insert_Node
:= Parent
(Insert_Node
);
21835 if Present
(Insert_Node
) then
21837 -- Case of loop statement. Verify that the range is part of the
21838 -- subtype indication of the iteration scheme.
21840 if Nkind
(Insert_Node
) = N_Loop_Statement
then
21845 Indic
:= Parent
(R
);
21846 while Present
(Indic
)
21847 and then Nkind
(Indic
) /= N_Subtype_Indication
21849 Indic
:= Parent
(Indic
);
21852 if Present
(Indic
) then
21853 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
21855 Insert_Range_Checks
21859 Sloc
(Insert_Node
),
21860 Do_Before
=> True);
21864 -- Case of declarations. If the declaration is for a type and
21865 -- involves discriminants, the checks are premature at the
21866 -- declaration point and need to wait for the expansion of the
21867 -- initialization procedure, which will pass in the list to put
21868 -- them on; otherwise, the checks are done at the declaration
21869 -- point and there is no need to do them again in the
21870 -- initialization procedure.
21872 elsif Nkind
(Insert_Node
) in N_Declaration
then
21873 Def_Id
:= Defining_Identifier
(Insert_Node
);
21875 if (Ekind
(Def_Id
) = E_Record_Type
21876 and then Depends_On_Discriminant
(R
))
21878 (Ekind
(Def_Id
) = E_Protected_Type
21879 and then Has_Discriminants
(Def_Id
))
21881 if Present
(Check_List
) then
21882 Append_Range_Checks
21884 Check_List
, Def_Id
, Sloc
(Insert_Node
));
21888 if No
(Check_List
) then
21889 Insert_Range_Checks
21891 Insert_Node
, Def_Id
, Sloc
(Insert_Node
));
21895 -- Case of statements. Drop the checks, as the range appears in
21896 -- the context of a quantified expression. Insertion will take
21897 -- place when expression is expanded.
21904 -- Case of other than an explicit N_Range node
21906 -- The forced evaluation removes side effects from expressions, which
21907 -- should occur also in GNATprove mode. Otherwise, we end up with
21908 -- unexpected insertions of actions at places where this is not
21909 -- supposed to occur, e.g. on default parameters of a call.
21911 elsif Expander_Active
or GNATprove_Mode
then
21912 Get_Index_Bounds
(R
, Lo
, Hi
);
21913 Force_Evaluation
(Lo
);
21914 Force_Evaluation
(Hi
);
21916 end Process_Range_Expr_In_Decl
;
21918 --------------------------------------
21919 -- Process_Real_Range_Specification --
21920 --------------------------------------
21922 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
21923 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
21926 Err
: Boolean := False;
21928 procedure Analyze_Bound
(N
: Node_Id
);
21929 -- Analyze and check one bound
21931 -------------------
21932 -- Analyze_Bound --
21933 -------------------
21935 procedure Analyze_Bound
(N
: Node_Id
) is
21937 Analyze_And_Resolve
(N
, Any_Real
);
21939 if not Is_OK_Static_Expression
(N
) then
21940 Flag_Non_Static_Expr
21941 ("bound in real type definition is not static!", N
);
21946 -- Start of processing for Process_Real_Range_Specification
21949 if Present
(Spec
) then
21950 Lo
:= Low_Bound
(Spec
);
21951 Hi
:= High_Bound
(Spec
);
21952 Analyze_Bound
(Lo
);
21953 Analyze_Bound
(Hi
);
21955 -- If error, clear away junk range specification
21958 Set_Real_Range_Specification
(Def
, Empty
);
21961 end Process_Real_Range_Specification
;
21963 ---------------------
21964 -- Process_Subtype --
21965 ---------------------
21967 function Process_Subtype
21969 Related_Nod
: Node_Id
;
21970 Related_Id
: Entity_Id
:= Empty
;
21971 Suffix
: Character := ' ') return Entity_Id
21973 procedure Check_Incomplete
(T
: Node_Id
);
21974 -- Called to verify that an incomplete type is not used prematurely
21976 ----------------------
21977 -- Check_Incomplete --
21978 ----------------------
21980 procedure Check_Incomplete
(T
: Node_Id
) is
21982 -- Ada 2005 (AI-412): Incomplete subtypes are legal
21984 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
21986 not (Ada_Version
>= Ada_2005
21988 (Nkind
(Parent
(T
)) = N_Subtype_Declaration
21989 or else (Nkind
(Parent
(T
)) = N_Subtype_Indication
21990 and then Nkind
(Parent
(Parent
(T
))) =
21991 N_Subtype_Declaration
)))
21993 Error_Msg_N
("invalid use of type before its full declaration", T
);
21995 end Check_Incomplete
;
22000 Def_Id
: Entity_Id
;
22001 Error_Node
: Node_Id
;
22002 Full_View_Id
: Entity_Id
;
22003 Subtype_Mark_Id
: Entity_Id
;
22005 May_Have_Null_Exclusion
: Boolean;
22007 -- Start of processing for Process_Subtype
22010 -- Case of no constraints present
22012 if Nkind
(S
) /= N_Subtype_Indication
then
22015 -- No way to proceed if the subtype indication is malformed. This
22016 -- will happen for example when the subtype indication in an object
22017 -- declaration is missing altogether and the expression is analyzed
22018 -- as if it were that indication.
22020 if not Is_Entity_Name
(S
) then
22024 Check_Incomplete
(S
);
22027 -- The following mirroring of assertion in Null_Exclusion_Present is
22028 -- ugly, can't we have a range, a static predicate or even a flag???
22030 May_Have_Null_Exclusion
:=
22033 Nkind
(P
) in N_Access_Definition
22034 | N_Access_Function_Definition
22035 | N_Access_Procedure_Definition
22036 | N_Access_To_Object_Definition
22038 | N_Component_Definition
22039 | N_Derived_Type_Definition
22040 | N_Discriminant_Specification
22041 | N_Formal_Object_Declaration
22042 | N_Function_Specification
22043 | N_Object_Declaration
22044 | N_Object_Renaming_Declaration
22045 | N_Parameter_Specification
22046 | N_Subtype_Declaration
;
22048 -- Ada 2005 (AI-231): Static check
22050 if Ada_Version
>= Ada_2005
22051 and then May_Have_Null_Exclusion
22052 and then Null_Exclusion_Present
(P
)
22053 and then Nkind
(P
) /= N_Access_To_Object_Definition
22054 and then not Is_Access_Type
(Entity
(S
))
22056 Error_Msg_N
("`NOT NULL` only allowed for an access type", S
);
22059 -- Create an Itype that is a duplicate of Entity (S) but with the
22060 -- null-exclusion attribute.
22062 if May_Have_Null_Exclusion
22063 and then Is_Access_Type
(Entity
(S
))
22064 and then Null_Exclusion_Present
(P
)
22066 -- No need to check the case of an access to object definition.
22067 -- It is correct to define double not-null pointers.
22070 -- type Not_Null_Int_Ptr is not null access Integer;
22071 -- type Acc is not null access Not_Null_Int_Ptr;
22073 and then Nkind
(P
) /= N_Access_To_Object_Definition
22075 if Can_Never_Be_Null
(Entity
(S
)) then
22076 case Nkind
(Related_Nod
) is
22077 when N_Full_Type_Declaration
=>
22078 if Nkind
(Type_Definition
(Related_Nod
))
22079 in N_Array_Type_Definition
22083 (Component_Definition
22084 (Type_Definition
(Related_Nod
)));
22087 Subtype_Indication
(Type_Definition
(Related_Nod
));
22090 when N_Subtype_Declaration
=>
22091 Error_Node
:= Subtype_Indication
(Related_Nod
);
22093 when N_Object_Declaration
=>
22094 Error_Node
:= Object_Definition
(Related_Nod
);
22096 when N_Component_Declaration
=>
22098 Subtype_Indication
(Component_Definition
(Related_Nod
));
22100 when N_Allocator
=>
22101 Error_Node
:= Expression
(Related_Nod
);
22104 pragma Assert
(False);
22105 Error_Node
:= Related_Nod
;
22109 ("`NOT NULL` not allowed (& already excludes null)",
22115 Create_Null_Excluding_Itype
22117 Related_Nod
=> P
));
22118 Set_Entity
(S
, Etype
(S
));
22123 -- Case of constraint present, so that we have an N_Subtype_Indication
22124 -- node (this node is created only if constraints are present).
22127 Find_Type
(Subtype_Mark
(S
));
22129 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
22131 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
22132 and then Is_Itype
(Defining_Identifier
(Parent
(S
))))
22134 Check_Incomplete
(Subtype_Mark
(S
));
22138 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
22140 -- Explicit subtype declaration case
22142 if Nkind
(P
) = N_Subtype_Declaration
then
22143 Def_Id
:= Defining_Identifier
(P
);
22145 -- Explicit derived type definition case
22147 elsif Nkind
(P
) = N_Derived_Type_Definition
then
22148 Def_Id
:= Defining_Identifier
(Parent
(P
));
22150 -- Implicit case, the Def_Id must be created as an implicit type.
22151 -- The one exception arises in the case of concurrent types, array
22152 -- and access types, where other subsidiary implicit types may be
22153 -- created and must appear before the main implicit type. In these
22154 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
22155 -- has not yet been called to create Def_Id.
22158 if Is_Array_Type
(Subtype_Mark_Id
)
22159 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
22160 or else Is_Access_Type
(Subtype_Mark_Id
)
22164 -- For the other cases, we create a new unattached Itype,
22165 -- and set the indication to ensure it gets attached later.
22169 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22173 -- If the kind of constraint is invalid for this kind of type,
22174 -- then give an error, and then pretend no constraint was given.
22176 if not Is_Valid_Constraint_Kind
22177 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
22180 ("incorrect constraint for this kind of type", Constraint
(S
));
22182 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
22184 -- Set Ekind of orphan itype, to prevent cascaded errors
22186 if Present
(Def_Id
) then
22187 Mutate_Ekind
(Def_Id
, Ekind
(Any_Type
));
22190 -- Make recursive call, having got rid of the bogus constraint
22192 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
22195 -- Remaining processing depends on type. Select on Base_Type kind to
22196 -- ensure getting to the concrete type kind in the case of a private
22197 -- subtype (needed when only doing semantic analysis).
22199 case Ekind
(Base_Type
(Subtype_Mark_Id
)) is
22200 when Access_Kind
=>
22202 -- If this is a constraint on a class-wide type, discard it.
22203 -- There is currently no way to express a partial discriminant
22204 -- constraint on a type with unknown discriminants. This is
22205 -- a pathology that the ACATS wisely decides not to test.
22207 if Is_Class_Wide_Type
(Designated_Type
(Subtype_Mark_Id
)) then
22208 if Comes_From_Source
(S
) then
22210 ("constraint on class-wide type ignored??",
22214 if Nkind
(P
) = N_Subtype_Declaration
then
22215 Set_Subtype_Indication
(P
,
22216 New_Occurrence_Of
(Subtype_Mark_Id
, Sloc
(S
)));
22219 return Subtype_Mark_Id
;
22222 Constrain_Access
(Def_Id
, S
, Related_Nod
);
22225 and then Is_Itype
(Designated_Type
(Def_Id
))
22226 and then Nkind
(Related_Nod
) = N_Subtype_Declaration
22227 and then not Is_Incomplete_Type
(Designated_Type
(Def_Id
))
22229 Build_Itype_Reference
22230 (Designated_Type
(Def_Id
), Related_Nod
);
22234 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22236 when Decimal_Fixed_Point_Kind
=>
22237 Constrain_Decimal
(Def_Id
, S
);
22239 when Enumeration_Kind
=>
22240 Constrain_Enumeration
(Def_Id
, S
);
22242 when Ordinary_Fixed_Point_Kind
=>
22243 Constrain_Ordinary_Fixed
(Def_Id
, S
);
22246 Constrain_Float
(Def_Id
, S
);
22248 when Integer_Kind
=>
22249 Constrain_Integer
(Def_Id
, S
);
22251 when Class_Wide_Kind
22252 | E_Incomplete_Type
22256 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22258 if Ekind
(Def_Id
) = E_Incomplete_Type
then
22259 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22262 when Private_Kind
=>
22264 -- A private type with unknown discriminants may be completed
22265 -- by an unconstrained array type.
22267 if Has_Unknown_Discriminants
(Subtype_Mark_Id
)
22268 and then Present
(Full_View
(Subtype_Mark_Id
))
22269 and then Is_Array_Type
(Full_View
(Subtype_Mark_Id
))
22271 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22273 -- ... but more commonly is completed by a discriminated record
22277 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22280 -- The base type may be private but Def_Id may be a full view
22283 if Is_Private_Type
(Def_Id
) then
22284 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22287 -- In case of an invalid constraint prevent further processing
22288 -- since the type constructed is missing expected fields.
22290 if Etype
(Def_Id
) = Any_Type
then
22294 -- If the full view is that of a task with discriminants,
22295 -- we must constrain both the concurrent type and its
22296 -- corresponding record type. Otherwise we will just propagate
22297 -- the constraint to the full view, if available.
22299 if Present
(Full_View
(Subtype_Mark_Id
))
22300 and then Has_Discriminants
(Subtype_Mark_Id
)
22301 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
22304 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22306 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
22307 Constrain_Concurrent
(Full_View_Id
, S
,
22308 Related_Nod
, Related_Id
, Suffix
);
22309 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
22310 Set_Full_View
(Def_Id
, Full_View_Id
);
22312 -- Introduce an explicit reference to the private subtype,
22313 -- to prevent scope anomalies in gigi if first use appears
22314 -- in a nested context, e.g. a later function body.
22315 -- Should this be generated in other contexts than a full
22316 -- type declaration?
22318 if Is_Itype
(Def_Id
)
22320 Nkind
(Parent
(P
)) = N_Full_Type_Declaration
22322 Build_Itype_Reference
(Def_Id
, Parent
(P
));
22326 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
22329 when Concurrent_Kind
=>
22330 Constrain_Concurrent
(Def_Id
, S
,
22331 Related_Nod
, Related_Id
, Suffix
);
22334 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
22337 -- Size, Alignment, Representation aspects and Convention are always
22338 -- inherited from the base type.
22340 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
22341 Set_Rep_Info
(Def_Id
, (Subtype_Mark_Id
));
22342 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
22344 -- The anonymous subtype created for the subtype indication
22345 -- inherits the predicates of the parent.
22347 if Has_Predicates
(Subtype_Mark_Id
) then
22348 Inherit_Predicate_Flags
(Def_Id
, Subtype_Mark_Id
);
22350 -- Indicate where the predicate function may be found
22352 if No
(Predicate_Function
(Def_Id
)) and then Is_Itype
(Def_Id
) then
22353 Set_Predicated_Parent
(Def_Id
, Subtype_Mark_Id
);
22359 end Process_Subtype
;
22361 -----------------------------
22362 -- Record_Type_Declaration --
22363 -----------------------------
22365 procedure Record_Type_Declaration
22370 Def
: constant Node_Id
:= Type_Definition
(N
);
22371 Is_Tagged
: Boolean;
22372 Tag_Comp
: Entity_Id
;
22375 -- These flags must be initialized before calling Process_Discriminants
22376 -- because this routine makes use of them.
22378 Mutate_Ekind
(T
, E_Record_Type
);
22380 Reinit_Size_Align
(T
);
22381 Set_Interfaces
(T
, No_Elist
);
22382 Set_Stored_Constraint
(T
, No_Elist
);
22383 Set_Default_SSO
(T
);
22384 Set_No_Reordering
(T
, No_Component_Reordering
);
22388 if Ada_Version
< Ada_2005
or else not Interface_Present
(Def
) then
22389 -- The flag Is_Tagged_Type might have already been set by
22390 -- Find_Type_Name if it detected an error for declaration T. This
22391 -- arises in the case of private tagged types where the full view
22392 -- omits the word tagged.
22395 Tagged_Present
(Def
)
22396 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
22398 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
22401 Set_Is_Tagged_Type
(T
, True);
22402 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
22405 -- Type is abstract if full declaration carries keyword, or if
22406 -- previous partial view did.
22408 Set_Is_Abstract_Type
(T
, Is_Abstract_Type
(T
)
22409 or else Abstract_Present
(Def
));
22413 Analyze_Interface_Declaration
(T
, Def
);
22415 if Present
(Discriminant_Specifications
(N
)) then
22417 ("interface types cannot have discriminants",
22418 Defining_Identifier
22419 (First
(Discriminant_Specifications
(N
))));
22423 -- First pass: if there are self-referential access components,
22424 -- create the required anonymous access type declarations, and if
22425 -- need be an incomplete type declaration for T itself.
22427 Check_Anonymous_Access_Components
(N
, T
, Prev
, Component_List
(Def
));
22429 if Ada_Version
>= Ada_2005
22430 and then Present
(Interface_List
(Def
))
22432 Check_Interfaces
(N
, Def
);
22435 Ifaces_List
: Elist_Id
;
22438 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
22439 -- already in the parents.
22443 Ifaces_List
=> Ifaces_List
,
22444 Exclude_Parents
=> True);
22446 Set_Interfaces
(T
, Ifaces_List
);
22450 -- Records constitute a scope for the component declarations within.
22451 -- The scope is created prior to the processing of these declarations.
22452 -- Discriminants are processed first, so that they are visible when
22453 -- processing the other components. The Ekind of the record type itself
22454 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
22456 -- Enter record scope
22460 -- If an incomplete or private type declaration was already given for
22461 -- the type, then this scope already exists, and the discriminants have
22462 -- been declared within. We must verify that the full declaration
22463 -- matches the incomplete one.
22465 Check_Or_Process_Discriminants
(N
, T
, Prev
);
22467 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
22468 Set_Has_Delayed_Freeze
(T
, True);
22470 -- For tagged types add a manually analyzed component corresponding
22471 -- to the component _tag, the corresponding piece of tree will be
22472 -- expanded as part of the freezing actions if it is not a CPP_Class.
22476 -- Do not add the tag unless we are in expansion mode
22478 if Expander_Active
then
22479 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
22480 Enter_Name
(Tag_Comp
);
22482 Mutate_Ekind
(Tag_Comp
, E_Component
);
22483 Set_Is_Tag
(Tag_Comp
);
22484 Set_Is_Aliased
(Tag_Comp
);
22485 Set_Is_Independent
(Tag_Comp
);
22486 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
22487 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
22488 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
22489 Reinit_Component_Location
(Tag_Comp
);
22491 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
22492 -- implemented interfaces.
22494 if Has_Interfaces
(T
) then
22495 Add_Interface_Tag_Components
(N
, T
);
22499 Make_Class_Wide_Type
(T
);
22500 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
22503 -- We must suppress range checks when processing record components in
22504 -- the presence of discriminants, since we don't want spurious checks to
22505 -- be generated during their analysis, but Suppress_Range_Checks flags
22506 -- must be reset the after processing the record definition.
22508 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
22509 -- couldn't we just use the normal range check suppression method here.
22510 -- That would seem cleaner ???
22512 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
22513 Set_Kill_Range_Checks
(T
, True);
22514 Record_Type_Definition
(Def
, Prev
);
22515 Set_Kill_Range_Checks
(T
, False);
22517 Record_Type_Definition
(Def
, Prev
);
22520 -- Exit from record scope
22524 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
22525 -- the implemented interfaces and associate them an aliased entity.
22528 and then not Is_Empty_List
(Interface_List
(Def
))
22530 Derive_Progenitor_Subprograms
(T
, T
);
22533 Check_Function_Writable_Actuals
(N
);
22534 end Record_Type_Declaration
;
22536 ----------------------------
22537 -- Record_Type_Definition --
22538 ----------------------------
22540 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
22541 Component
: Entity_Id
;
22542 Ctrl_Components
: Boolean := False;
22543 Final_Storage_Only
: Boolean;
22547 if Ekind
(Prev_T
) = E_Incomplete_Type
then
22548 T
:= Full_View
(Prev_T
);
22553 Final_Storage_Only
:= not Is_Controlled
(T
);
22555 -- Ada 2005: Check whether an explicit "limited" is present in a derived
22556 -- type declaration.
22558 if Parent_Kind
(Def
) = N_Derived_Type_Definition
22559 and then Limited_Present
(Parent
(Def
))
22561 Set_Is_Limited_Record
(T
);
22564 -- If the component list of a record type is defined by the reserved
22565 -- word null and there is no discriminant part, then the record type has
22566 -- no components and all records of the type are null records (RM 3.7)
22567 -- This procedure is also called to process the extension part of a
22568 -- record extension, in which case the current scope may have inherited
22572 and then Present
(Component_List
(Def
))
22573 and then not Null_Present
(Component_List
(Def
))
22575 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
22577 if Present
(Variant_Part
(Component_List
(Def
))) then
22578 Analyze
(Variant_Part
(Component_List
(Def
)));
22582 -- After completing the semantic analysis of the record definition,
22583 -- record components, both new and inherited, are accessible. Set their
22584 -- kind accordingly. Exclude malformed itypes from illegal declarations,
22585 -- whose Ekind may be void.
22587 Component
:= First_Entity
(Current_Scope
);
22588 while Present
(Component
) loop
22589 if Ekind
(Component
) = E_Void
22590 and then not Is_Itype
(Component
)
22592 Mutate_Ekind
(Component
, E_Component
);
22593 Reinit_Component_Location
(Component
);
22596 Propagate_Concurrent_Flags
(T
, Etype
(Component
));
22598 if Ekind
(Component
) /= E_Component
then
22601 -- Do not set Has_Controlled_Component on a class-wide equivalent
22602 -- type. See Make_CW_Equivalent_Type.
22604 elsif not Is_Class_Wide_Equivalent_Type
(T
)
22605 and then (Has_Controlled_Component
(Etype
(Component
))
22606 or else (Chars
(Component
) /= Name_uParent
22607 and then Is_Controlled
(Etype
(Component
))))
22609 Set_Has_Controlled_Component
(T
, True);
22610 Final_Storage_Only
:=
22612 and then Finalize_Storage_Only
(Etype
(Component
));
22613 Ctrl_Components
:= True;
22616 Next_Entity
(Component
);
22619 -- A Type is Finalize_Storage_Only only if all its controlled components
22622 if Ctrl_Components
then
22623 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
22626 -- Place reference to end record on the proper entity, which may
22627 -- be a partial view.
22629 if Present
(Def
) then
22630 Process_End_Label
(Def
, 'e', Prev_T
);
22632 end Record_Type_Definition
;
22634 ---------------------------
22635 -- Replace_Discriminants --
22636 ---------------------------
22638 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
) is
22639 function Process
(N
: Node_Id
) return Traverse_Result
;
22645 function Process
(N
: Node_Id
) return Traverse_Result
is
22649 if Nkind
(N
) = N_Discriminant_Specification
then
22650 Comp
:= First_Discriminant
(Typ
);
22651 while Present
(Comp
) loop
22652 if Original_Record_Component
(Comp
) = Defining_Identifier
(N
)
22653 or else Chars
(Comp
) = Chars
(Defining_Identifier
(N
))
22655 Set_Defining_Identifier
(N
, Comp
);
22659 Next_Discriminant
(Comp
);
22662 elsif Nkind
(N
) = N_Variant_Part
then
22663 Comp
:= First_Discriminant
(Typ
);
22664 while Present
(Comp
) loop
22665 if Original_Record_Component
(Comp
) = Entity
(Name
(N
))
22666 or else Chars
(Comp
) = Chars
(Name
(N
))
22668 -- Make sure to preserve the type coming from the parent on
22669 -- the Name, even if the subtype of the discriminant can be
22670 -- constrained, so that discrete choices inherited from the
22671 -- parent in the variant part are not flagged as violating
22672 -- the constraints of the subtype.
22675 Typ
: constant Entity_Id
:= Etype
(Name
(N
));
22677 Rewrite
(Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
22678 Set_Etype
(Name
(N
), Typ
);
22683 Next_Discriminant
(Comp
);
22690 procedure Replace
is new Traverse_Proc
(Process
);
22692 -- Start of processing for Replace_Discriminants
22696 end Replace_Discriminants
;
22698 -------------------------------
22699 -- Set_Completion_Referenced --
22700 -------------------------------
22702 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
22704 -- If in main unit, mark entity that is a completion as referenced,
22705 -- warnings go on the partial view when needed.
22707 if In_Extended_Main_Source_Unit
(E
) then
22708 Set_Referenced
(E
);
22710 end Set_Completion_Referenced
;
22712 ---------------------
22713 -- Set_Default_SSO --
22714 ---------------------
22716 procedure Set_Default_SSO
(T
: Entity_Id
) is
22718 case Opt
.Default_SSO
is
22722 Set_SSO_Set_Low_By_Default
(T
, True);
22724 Set_SSO_Set_High_By_Default
(T
, True);
22726 raise Program_Error
;
22728 end Set_Default_SSO
;
22730 ---------------------
22731 -- Set_Fixed_Range --
22732 ---------------------
22734 -- The range for fixed-point types is complicated by the fact that we
22735 -- do not know the exact end points at the time of the declaration. This
22736 -- is true for three reasons:
22738 -- A size clause may affect the fudging of the end-points.
22739 -- A small clause may affect the values of the end-points.
22740 -- We try to include the end-points if it does not affect the size.
22742 -- This means that the actual end-points must be established at the
22743 -- point when the type is frozen. Meanwhile, we first narrow the range
22744 -- as permitted (so that it will fit if necessary in a small specified
22745 -- size), and then build a range subtree with these narrowed bounds.
22746 -- Set_Fixed_Range constructs the range from real literal values, and
22747 -- sets the range as the Scalar_Range of the given fixed-point type entity.
22749 -- The parent of this range is set to point to the entity so that it is
22750 -- properly hooked into the tree (unlike normal Scalar_Range entries for
22751 -- other scalar types, which are just pointers to the range in the
22752 -- original tree, this would otherwise be an orphan).
22754 -- The tree is left unanalyzed. When the type is frozen, the processing
22755 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
22756 -- analyzed, and uses this as an indication that it should complete
22757 -- work on the range (it will know the final small and size values).
22759 procedure Set_Fixed_Range
22765 S
: constant Node_Id
:=
22767 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
22768 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
22770 Set_Scalar_Range
(E
, S
);
22773 -- Before the freeze point, the bounds of a fixed point are universal
22774 -- and carry the corresponding type.
22776 Set_Etype
(Low_Bound
(S
), Universal_Real
);
22777 Set_Etype
(High_Bound
(S
), Universal_Real
);
22778 end Set_Fixed_Range
;
22780 ----------------------------------
22781 -- Set_Scalar_Range_For_Subtype --
22782 ----------------------------------
22784 procedure Set_Scalar_Range_For_Subtype
22785 (Def_Id
: Entity_Id
;
22789 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
22792 -- Defend against previous error
22794 if Nkind
(R
) = N_Error
then
22798 Set_Scalar_Range
(Def_Id
, R
);
22800 -- We need to link the range into the tree before resolving it so
22801 -- that types that are referenced, including importantly the subtype
22802 -- itself, are properly frozen (Freeze_Expression requires that the
22803 -- expression be properly linked into the tree). Of course if it is
22804 -- already linked in, then we do not disturb the current link.
22806 if No
(Parent
(R
)) then
22807 Set_Parent
(R
, Def_Id
);
22810 -- Reset the kind of the subtype during analysis of the range, to
22811 -- catch possible premature use in the bounds themselves.
22813 Mutate_Ekind
(Def_Id
, E_Void
);
22814 Process_Range_Expr_In_Decl
(R
, Subt
, Subtyp
=> Def_Id
);
22815 Mutate_Ekind
(Def_Id
, Kind
);
22816 end Set_Scalar_Range_For_Subtype
;
22818 --------------------------------------------------------
22819 -- Set_Stored_Constraint_From_Discriminant_Constraint --
22820 --------------------------------------------------------
22822 procedure Set_Stored_Constraint_From_Discriminant_Constraint
22826 -- Make sure set if encountered during Expand_To_Stored_Constraint
22828 Set_Stored_Constraint
(E
, No_Elist
);
22830 -- Give it the right value
22832 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
22833 Set_Stored_Constraint
(E
,
22834 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
22836 end Set_Stored_Constraint_From_Discriminant_Constraint
;
22838 -------------------------------------
22839 -- Signed_Integer_Type_Declaration --
22840 -------------------------------------
22842 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
22843 Implicit_Base
: Entity_Id
;
22844 Base_Typ
: Entity_Id
;
22847 Errs
: Boolean := False;
22851 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
22852 -- Determine whether given bounds allow derivation from specified type
22854 procedure Check_Bound
(Expr
: Node_Id
);
22855 -- Check bound to make sure it is integral and static. If not, post
22856 -- appropriate error message and set Errs flag
22858 ---------------------
22859 -- Can_Derive_From --
22860 ---------------------
22862 -- Note we check both bounds against both end values, to deal with
22863 -- strange types like ones with a range of 0 .. -12341234.
22865 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
22866 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
22867 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
22869 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
22871 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
22872 end Can_Derive_From
;
22878 procedure Check_Bound
(Expr
: Node_Id
) is
22880 -- If a range constraint is used as an integer type definition, each
22881 -- bound of the range must be defined by a static expression of some
22882 -- integer type, but the two bounds need not have the same integer
22883 -- type (Negative bounds are allowed.) (RM 3.5.4)
22885 if not Is_Integer_Type
(Etype
(Expr
)) then
22887 ("integer type definition bounds must be of integer type", Expr
);
22890 elsif not Is_OK_Static_Expression
(Expr
) then
22891 Flag_Non_Static_Expr
22892 ("non-static expression used for integer type bound!", Expr
);
22895 -- Otherwise the bounds are folded into literals
22897 elsif Is_Entity_Name
(Expr
) then
22898 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
22902 -- Start of processing for Signed_Integer_Type_Declaration
22905 -- Create an anonymous base type
22908 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
22910 -- Analyze and check the bounds, they can be of any integer type
22912 Lo
:= Low_Bound
(Def
);
22913 Hi
:= High_Bound
(Def
);
22915 -- Arbitrarily use Integer as the type if either bound had an error
22917 if Hi
= Error
or else Lo
= Error
then
22918 Base_Typ
:= Any_Integer
;
22919 Set_Error_Posted
(T
, True);
22922 -- Here both bounds are OK expressions
22925 Analyze_And_Resolve
(Lo
, Any_Integer
);
22926 Analyze_And_Resolve
(Hi
, Any_Integer
);
22932 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
22933 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
22936 -- Find type to derive from
22938 Lo_Val
:= Expr_Value
(Lo
);
22939 Hi_Val
:= Expr_Value
(Hi
);
22941 if Can_Derive_From
(Standard_Short_Short_Integer
) then
22942 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
22944 elsif Can_Derive_From
(Standard_Short_Integer
) then
22945 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
22947 elsif Can_Derive_From
(Standard_Integer
) then
22948 Base_Typ
:= Base_Type
(Standard_Integer
);
22950 elsif Can_Derive_From
(Standard_Long_Integer
) then
22951 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
22953 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
22954 Check_Restriction
(No_Long_Long_Integers
, Def
);
22955 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
22957 elsif Can_Derive_From
(Standard_Long_Long_Long_Integer
) then
22958 Check_Restriction
(No_Long_Long_Integers
, Def
);
22959 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
22962 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
22963 Error_Msg_N
("integer type definition bounds out of range", Def
);
22964 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
22965 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
22969 -- Set the type of the bounds to the implicit base: we cannot set it to
22970 -- the new type, because this would be a forward reference for the code
22971 -- generator and, if the original type is user-defined, this could even
22972 -- lead to spurious semantic errors. Furthermore we do not set it to be
22973 -- universal, because this could make it much larger than needed here.
22976 Set_Etype
(Lo
, Implicit_Base
);
22977 Set_Etype
(Hi
, Implicit_Base
);
22980 -- Complete both implicit base and declared first subtype entities. The
22981 -- inheritance of the rep item chain ensures that SPARK-related pragmas
22982 -- are not clobbered when the signed integer type acts as a full view of
22985 Set_Etype
(Implicit_Base
, Base_Typ
);
22986 Set_Size_Info
(Implicit_Base
, Base_Typ
);
22987 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
22988 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
22989 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
22991 Mutate_Ekind
(T
, E_Signed_Integer_Subtype
);
22992 Set_Etype
(T
, Implicit_Base
);
22993 Set_Size_Info
(T
, Implicit_Base
);
22994 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
22995 Set_Scalar_Range
(T
, Def
);
22996 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
22997 Set_Is_Constrained
(T
);
22998 end Signed_Integer_Type_Declaration
;