1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Accessibility
; use Accessibility
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Debug
; use Debug
;
32 with Elists
; use Elists
;
33 with Einfo
; use Einfo
;
34 with Einfo
.Entities
; use Einfo
.Entities
;
35 with Einfo
.Utils
; use Einfo
.Utils
;
36 with Errout
; use Errout
;
37 with Eval_Fat
; use Eval_Fat
;
38 with Exp_Ch3
; use Exp_Ch3
;
39 with Exp_Ch9
; use Exp_Ch9
;
40 with Exp_Disp
; use Exp_Disp
;
41 with Exp_Dist
; use Exp_Dist
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Expander
; use Expander
;
45 with Freeze
; use Freeze
;
46 with Ghost
; use Ghost
;
47 with Itypes
; use Itypes
;
48 with Layout
; use Layout
;
50 with Lib
.Xref
; use Lib
.Xref
;
51 with Namet
; use Namet
;
52 with Nlists
; use Nlists
;
53 with Nmake
; use Nmake
;
55 with Restrict
; use Restrict
;
56 with Rident
; use Rident
;
57 with Rtsfind
; use Rtsfind
;
59 with Sem_Aux
; use Sem_Aux
;
60 with Sem_Case
; use Sem_Case
;
61 with Sem_Cat
; use Sem_Cat
;
62 with Sem_Ch6
; use Sem_Ch6
;
63 with Sem_Ch7
; use Sem_Ch7
;
64 with Sem_Ch8
; use Sem_Ch8
;
65 with Sem_Ch10
; use Sem_Ch10
;
66 with Sem_Ch13
; use Sem_Ch13
;
67 with Sem_Dim
; use Sem_Dim
;
68 with Sem_Disp
; use Sem_Disp
;
69 with Sem_Dist
; use Sem_Dist
;
70 with Sem_Elab
; use Sem_Elab
;
71 with Sem_Elim
; use Sem_Elim
;
72 with Sem_Eval
; use Sem_Eval
;
73 with Sem_Mech
; use Sem_Mech
;
74 with Sem_Res
; use Sem_Res
;
75 with Sem_Smem
; use Sem_Smem
;
76 with Sem_Type
; use Sem_Type
;
77 with Sem_Util
; use Sem_Util
;
78 with Sem_Warn
; use Sem_Warn
;
79 with Stand
; use Stand
;
80 with Sinfo
; use Sinfo
;
81 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
82 with Sinfo
.Utils
; use Sinfo
.Utils
;
83 with Sinput
; use Sinput
;
84 with Snames
; use Snames
;
85 with Strub
; use Strub
;
86 with Targparm
; use Targparm
;
87 with Tbuild
; use Tbuild
;
88 with Ttypes
; use Ttypes
;
89 with Uintp
; use Uintp
;
90 with Urealp
; use Urealp
;
91 with Warnsw
; use Warnsw
;
93 package body Sem_Ch3
is
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
);
100 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
101 -- abstract interface types implemented by a record type or a derived
104 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
);
105 -- When an access-to-subprogram type has pre/postconditions, we build a
106 -- subprogram that includes these contracts and is invoked by an indirect
107 -- call through the corresponding access type.
109 procedure Build_Derived_Type
111 Parent_Type
: Entity_Id
;
112 Derived_Type
: Entity_Id
;
113 Is_Completion
: Boolean;
114 Derive_Subps
: Boolean := True);
115 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
116 -- the N_Full_Type_Declaration node containing the derived type definition.
117 -- Parent_Type is the entity for the parent type in the derived type
118 -- definition and Derived_Type the actual derived type. Is_Completion must
119 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
120 -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the
121 -- completion of a private type declaration. If Is_Completion is set to
122 -- True, N is the completion of a private type declaration and Derived_Type
123 -- is different from the defining identifier inside N (i.e. Derived_Type /=
124 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
125 -- subprograms should be derived. The only case where this parameter is
126 -- False is when Build_Derived_Type is recursively called to process an
127 -- implicit derived full type for a type derived from a private type (in
128 -- that case the subprograms must only be derived for the private view of
131 -- ??? These flags need a bit of re-examination and re-documentation:
132 -- ??? are they both necessary (both seem related to the recursion)?
134 procedure Build_Derived_Access_Type
136 Parent_Type
: Entity_Id
;
137 Derived_Type
: Entity_Id
);
138 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
139 -- create an implicit base if the parent type is constrained or if the
140 -- subtype indication has a constraint.
142 procedure Build_Derived_Array_Type
144 Parent_Type
: Entity_Id
;
145 Derived_Type
: Entity_Id
);
146 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
147 -- create an implicit base if the parent type is constrained or if the
148 -- subtype indication has a constraint.
150 procedure Build_Derived_Concurrent_Type
152 Parent_Type
: Entity_Id
;
153 Derived_Type
: Entity_Id
);
154 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
155 -- protected type, inherit entries and protected subprograms, check
156 -- legality of discriminant constraints if any.
158 procedure Build_Derived_Enumeration_Type
160 Parent_Type
: Entity_Id
;
161 Derived_Type
: Entity_Id
);
162 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
163 -- type, we must create a new list of literals. Types derived from
164 -- Character and [Wide_]Wide_Character are special-cased.
166 procedure Build_Derived_Numeric_Type
168 Parent_Type
: Entity_Id
;
169 Derived_Type
: Entity_Id
);
170 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
171 -- an anonymous base type, and propagate constraint to subtype if needed.
173 procedure Build_Derived_Private_Type
175 Parent_Type
: Entity_Id
;
176 Derived_Type
: Entity_Id
;
177 Is_Completion
: Boolean;
178 Derive_Subps
: Boolean := True);
179 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
180 -- because the parent may or may not have a completion, and the derivation
181 -- may itself be a completion.
183 procedure Build_Derived_Record_Type
185 Parent_Type
: Entity_Id
;
186 Derived_Type
: Entity_Id
;
187 Derive_Subps
: Boolean := True);
188 -- Subsidiary procedure used for tagged and untagged record types
189 -- by Build_Derived_Type and Analyze_Private_Extension_Declaration.
190 -- All parameters are as in Build_Derived_Type except that N, in
191 -- addition to being an N_Full_Type_Declaration node, can also be an
192 -- N_Private_Extension_Declaration node. See the definition of this routine
193 -- for much more info. Derive_Subps indicates whether subprograms should be
194 -- derived from the parent type. The only case where Derive_Subps is False
195 -- is for an implicit derived full type for a type derived from a private
196 -- type (see Build_Derived_Type).
198 procedure Build_Discriminal
(Discrim
: Entity_Id
);
199 -- Create the discriminal corresponding to discriminant Discrim, that is
200 -- the parameter corresponding to Discrim to be used in initialization
201 -- procedures for the type where Discrim is a discriminant. Discriminals
202 -- are not used during semantic analysis, and are not fully defined
203 -- entities until expansion. Thus they are not given a scope until
204 -- initialization procedures are built.
206 function Build_Discriminant_Constraints
209 Derived_Def
: Boolean := False) return Elist_Id
;
210 -- Validate discriminant constraints and return the list of the constraints
211 -- in order of discriminant declarations, where T is the discriminated
212 -- unconstrained type. Def is the N_Subtype_Indication node where the
213 -- discriminants constraints for T are specified. Derived_Def is True
214 -- when building the discriminant constraints in a derived type definition
215 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
216 -- type and Def is the constraint "(xxx)" on T and this routine sets the
217 -- Corresponding_Discriminant field of the discriminants in the derived
218 -- type D to point to the corresponding discriminants in the parent type T.
220 procedure Build_Discriminated_Subtype
224 Related_Nod
: Node_Id
;
225 For_Access
: Boolean := False);
226 -- Subsidiary procedure to Constrain_Discriminated_Type and to
227 -- Process_Incomplete_Dependents. Given
229 -- T (a possibly discriminated base type)
230 -- Def_Id (a very partially built subtype for T),
232 -- the call completes Def_Id to be the appropriate E_*_Subtype.
234 -- The Elist is the list of discriminant constraints if any (it is set
235 -- to No_Elist if T is not a discriminated type, and to an empty list if
236 -- T has discriminants but there are no discriminant constraints). The
237 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
238 -- The For_Access says whether or not this subtype is really constraining
241 function Build_Scalar_Bound
244 Der_T
: Entity_Id
) return Node_Id
;
245 -- The bounds of a derived scalar type are conversions of the bounds of
246 -- the parent type. Optimize the representation if the bounds are literals.
247 -- Needs a more complete spec--what are the parameters exactly, and what
248 -- exactly is the returned value, and how is Bound affected???
250 procedure Check_Access_Discriminant_Requires_Limited
253 -- Check the restriction that the type to which an access discriminant
254 -- belongs must be a concurrent type or a descendant of a type with
255 -- the reserved word 'limited' in its declaration.
257 procedure Check_Anonymous_Access_Component
262 Access_Def
: Node_Id
);
263 -- Ada 2005 AI-382: an access component in a record definition can refer to
264 -- the enclosing record, in which case it denotes the type itself, and not
265 -- the current instance of the type. We create an anonymous access type for
266 -- the component, and flag it as an access to a component, so accessibility
267 -- checks are properly performed on it. The declaration of the access type
268 -- is placed ahead of that of the record to prevent order-of-elaboration
269 -- circularity issues in Gigi. We create an incomplete type for the record
270 -- declaration, which is the designated type of the anonymous access.
272 procedure Check_Anonymous_Access_Components
276 Comp_List
: Node_Id
);
277 -- Call Check_Anonymous_Access_Component on Comp_List
279 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
);
280 -- Check that, if a new discriminant is used in a constraint defining the
281 -- parent subtype of a derivation, its subtype is statically compatible
282 -- with the subtype of the corresponding parent discriminant (RM 3.7(15)).
284 procedure Check_Delta_Expression
(E
: Node_Id
);
285 -- Check that the expression represented by E is suitable for use as a
286 -- delta expression, i.e. it is of real type and is static.
288 procedure Check_Digits_Expression
(E
: Node_Id
);
289 -- Check that the expression represented by E is suitable for use as a
290 -- digits expression, i.e. it is of integer type, positive and static.
292 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
);
293 -- Validate the initialization of an object declaration. T is the required
294 -- type, and Exp is the initialization expression.
296 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
);
297 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
299 procedure Check_Or_Process_Discriminants
302 Prev
: Entity_Id
:= Empty
);
303 -- If N is the full declaration of the completion T of an incomplete or
304 -- private type, check its discriminants (which are already known to be
305 -- conformant with those of the partial view, see Find_Type_Name),
306 -- otherwise process them. Prev is the entity of the partial declaration,
309 procedure Check_Real_Bound
(Bound
: Node_Id
);
310 -- Check given bound for being of real type and static. If not, post an
311 -- appropriate message, and rewrite the bound with the real literal zero.
313 procedure Constant_Redeclaration
317 -- Various checks on legality of full declaration of deferred constant.
318 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
319 -- node. The caller has not yet set any attributes of this entity.
321 function Contain_Interface
323 Ifaces
: Elist_Id
) return Boolean;
324 -- Ada 2005: Determine whether Iface is present in the list Ifaces
326 procedure Convert_Scalar_Bounds
328 Parent_Type
: Entity_Id
;
329 Derived_Type
: Entity_Id
;
331 -- For derived scalar types, convert the bounds in the type definition to
332 -- the derived type, and complete their analysis. Given a constraint of the
333 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
334 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
335 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
336 -- subtype are conversions of those bounds to the derived_type, so that
337 -- their typing is consistent.
339 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
);
340 -- Copies attributes from array base type T2 to array base type T1. Copies
341 -- only attributes that apply to base types, but not subtypes.
343 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
);
344 -- Copies attributes from array subtype T2 to array subtype T1. Copies
345 -- attributes that apply to both subtypes and base types.
347 procedure Create_Constrained_Components
351 Constraints
: Elist_Id
);
352 -- Build the list of entities for a constrained discriminated record
353 -- subtype. If a component depends on a discriminant, replace its subtype
354 -- using the discriminant values in the discriminant constraint. Subt
355 -- is the defining identifier for the subtype whose list of constrained
356 -- entities we will create. Decl_Node is the type declaration node where
357 -- we will attach all the itypes created. Typ is the base discriminated
358 -- type for the subtype Subt. Constraints is the list of discriminant
359 -- constraints for Typ.
361 function Constrain_Component_Type
363 Constrained_Typ
: Entity_Id
;
364 Related_Node
: Node_Id
;
366 Constraints
: Elist_Id
) return Entity_Id
;
367 -- Given a discriminated base type Typ, a list of discriminant constraints,
368 -- Constraints, for Typ and a component Comp of Typ, create and return the
369 -- type corresponding to Etype (Comp) where all discriminant references
370 -- are replaced with the corresponding constraint. If Etype (Comp) contains
371 -- no discriminant references then it is returned as-is. Constrained_Typ
372 -- is the final constrained subtype to which the constrained component
373 -- belongs. Related_Node is the node where we attach all created itypes.
375 procedure Constrain_Access
376 (Def_Id
: in out Entity_Id
;
378 Related_Nod
: Node_Id
);
379 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
380 -- an anonymous type created for a subtype indication. In that case it is
381 -- created in the procedure and attached to Related_Nod.
383 procedure Constrain_Array
384 (Def_Id
: in out Entity_Id
;
386 Related_Nod
: Node_Id
;
387 Related_Id
: Entity_Id
;
389 -- Apply a list of index constraints to an unconstrained array type. The
390 -- first parameter is the entity for the resulting subtype. A value of
391 -- Empty for Def_Id indicates that an implicit type must be created, but
392 -- creation is delayed (and must be done by this procedure) because other
393 -- subsidiary implicit types must be created first (which is why Def_Id
394 -- is an in/out parameter). The second parameter is a subtype indication
395 -- node for the constrained array to be created (e.g. something of the
396 -- form string (1 .. 10)). Related_Nod gives the place where this type
397 -- has to be inserted in the tree. The Related_Id and Suffix parameters
398 -- are used to build the associated Implicit type name.
400 procedure Constrain_Concurrent
401 (Def_Id
: in out Entity_Id
;
403 Related_Nod
: Node_Id
;
404 Related_Id
: Entity_Id
;
406 -- Apply list of discriminant constraints to an unconstrained concurrent
409 -- SI is the N_Subtype_Indication node containing the constraint and
410 -- the unconstrained type to constrain.
412 -- Def_Id is the entity for the resulting constrained subtype. A value
413 -- of Empty for Def_Id indicates that an implicit type must be created,
414 -- but creation is delayed (and must be done by this procedure) because
415 -- other subsidiary implicit types must be created first (which is why
416 -- Def_Id is an in/out parameter).
418 -- Related_Nod gives the place where this type has to be inserted
421 -- The last two arguments are used to create its external name if needed.
423 function Constrain_Corresponding_Record
424 (Prot_Subt
: Entity_Id
;
425 Corr_Rec
: Entity_Id
;
426 Related_Nod
: Node_Id
) return Entity_Id
;
427 -- When constraining a protected type or task type with discriminants,
428 -- constrain the corresponding record with the same discriminant values.
430 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
);
431 -- Constrain a decimal fixed point type with a digits constraint and/or a
432 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
434 procedure Constrain_Discriminated_Type
437 Related_Nod
: Node_Id
;
438 For_Access
: Boolean := False);
439 -- Process discriminant constraints of composite type. Verify that values
440 -- have been provided for all discriminants, that the original type is
441 -- unconstrained, and that the types of the supplied expressions match
442 -- the discriminant types. The first three parameters are like in routine
443 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
446 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
);
447 -- Constrain an enumeration type with a range constraint. This is identical
448 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
450 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
);
451 -- Constrain a floating point type with either a digits constraint
452 -- and/or a range constraint, building a E_Floating_Point_Subtype.
454 procedure Constrain_Index
457 Related_Nod
: Node_Id
;
458 Related_Id
: Entity_Id
;
461 -- Process an index constraint S in a constrained array declaration. The
462 -- constraint can be a subtype name, or a range with or without an explicit
463 -- subtype mark. The index is the corresponding index of the unconstrained
464 -- array. The Related_Id and Suffix parameters are used to build the
465 -- associated Implicit type name.
467 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
);
468 -- Build subtype of a signed or modular integer type
470 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
);
471 -- Constrain an ordinary fixed point type with a range constraint, and
472 -- build an E_Ordinary_Fixed_Point_Subtype entity.
474 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
);
475 -- Copy the Priv entity into the entity of its full declaration then swap
476 -- the two entities in such a manner that the former private type is now
477 -- seen as a full type.
479 procedure Decimal_Fixed_Point_Type_Declaration
482 -- Create a new decimal fixed point type, and apply the constraint to
483 -- obtain a subtype of this new type.
485 procedure Complete_Private_Subtype
488 Full_Base
: Entity_Id
;
489 Related_Nod
: Node_Id
);
490 -- Complete the implicit full view of a private subtype by setting the
491 -- appropriate semantic fields. If the full view of the parent is a record
492 -- type, build constrained components of subtype.
494 procedure Derive_Progenitor_Subprograms
495 (Parent_Type
: Entity_Id
;
496 Tagged_Type
: Entity_Id
);
497 -- Ada 2005 (AI-251): To complete type derivation, collect the primitive
498 -- operations of progenitors of Tagged_Type, and replace the subsidiary
499 -- subtypes with Tagged_Type, to build the specs of the inherited interface
500 -- primitives. The derived primitives are aliased to those of the
501 -- interface. This routine takes care also of transferring to the full view
502 -- subprograms associated with the partial view of Tagged_Type that cover
503 -- interface primitives.
505 procedure Derived_Standard_Character
507 Parent_Type
: Entity_Id
;
508 Derived_Type
: Entity_Id
);
509 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
510 -- derivations from types Standard.Character and Standard.Wide_Character.
512 procedure Derived_Type_Declaration
515 Is_Completion
: Boolean);
516 -- Process a derived type declaration. Build_Derived_Type is invoked
517 -- to process the actual derived type definition. Parameters N and
518 -- Is_Completion have the same meaning as in Build_Derived_Type.
519 -- T is the N_Defining_Identifier for the entity defined in the
520 -- N_Full_Type_Declaration node N, that is T is the derived type.
522 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
523 -- Insert each literal in symbol table, as an overloadable identifier. Each
524 -- enumeration type is mapped into a sequence of integers, and each literal
525 -- is defined as a constant with integer value. If any of the literals are
526 -- character literals, the type is a character type, which means that
527 -- strings are legal aggregates for arrays of components of the type.
529 function Expand_To_Stored_Constraint
531 Constraint
: Elist_Id
) return Elist_Id
;
532 -- Given a constraint (i.e. a list of expressions) on the discriminants of
533 -- Typ, expand it into a constraint on the stored discriminants and return
534 -- the new list of expressions constraining the stored discriminants.
536 function Find_Type_Of_Object
538 Related_Nod
: Node_Id
) return Entity_Id
;
539 -- Get type entity for object referenced by Obj_Def, attaching the implicit
540 -- types generated to Related_Nod.
542 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
543 -- Create a new float and apply the constraint to obtain subtype of it
545 function Has_Range_Constraint
(N
: Node_Id
) return Boolean;
546 -- Given an N_Subtype_Indication node N, return True if a range constraint
547 -- is present, either directly, or as part of a digits or delta constraint.
548 -- In addition, a digits constraint in the decimal case returns True, since
549 -- it establishes a default range if no explicit range is present.
551 function Inherit_Components
553 Parent_Base
: Entity_Id
;
554 Derived_Base
: Entity_Id
;
556 Inherit_Discr
: Boolean;
557 Discs
: Elist_Id
) return Elist_Id
;
558 -- Called from Build_Derived_Record_Type to inherit the components of
559 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
560 -- For more information on derived types and component inheritance please
561 -- consult the comment above the body of Build_Derived_Record_Type.
563 -- N is the original derived type declaration
565 -- Is_Tagged is set if we are dealing with tagged types
567 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
568 -- Parent_Base, otherwise no discriminants are inherited.
570 -- Discs gives the list of constraints that apply to Parent_Base in the
571 -- derived type declaration. If Discs is set to No_Elist, then we have
572 -- the following situation:
574 -- type Parent (D1..Dn : ..) is [tagged] record ...;
575 -- type Derived is new Parent [with ...];
577 -- which gets treated as
579 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
581 -- For untagged types the returned value is an association list. The list
582 -- starts from the association (Parent_Base => Derived_Base), and then it
583 -- contains a sequence of the associations of the form
585 -- (Old_Component => New_Component),
587 -- where Old_Component is the Entity_Id of a component in Parent_Base and
588 -- New_Component is the Entity_Id of the corresponding component in
589 -- Derived_Base. For untagged records, this association list is needed when
590 -- copying the record declaration for the derived base. In the tagged case
591 -- the value returned is irrelevant.
593 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean;
594 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
595 -- Determine whether subprogram Subp is a procedure subject to pragma
596 -- Extensions_Visible with value False and has at least one controlling
597 -- parameter of mode OUT.
599 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean;
600 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
601 -- When applied to a primitive subprogram Prim, returns True if Prim is
602 -- declared as a private operation within a package or generic package,
603 -- and returns False otherwise.
605 function Is_Valid_Constraint_Kind
607 Constraint_Kind
: Node_Kind
) return Boolean;
608 -- Returns True if it is legal to apply the given kind of constraint to the
609 -- given kind of type (index constraint to an array type, for example).
611 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
612 -- Create new modular type. Verify that modulus is in bounds
614 procedure New_Concatenation_Op
(Typ
: Entity_Id
);
615 -- Create an abbreviated declaration for an operator in order to
616 -- materialize concatenation on array types.
618 procedure Ordinary_Fixed_Point_Type_Declaration
621 -- Create a new ordinary fixed point type, and apply the constraint to
622 -- obtain subtype of it.
624 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
);
625 -- Wrapper on Preanalyze_Spec_Expression for default expressions, so that
626 -- In_Default_Expr can be properly adjusted.
628 procedure Prepare_Private_Subtype_Completion
630 Related_Nod
: Node_Id
);
631 -- Id is a subtype of some private type. Creates the full declaration
632 -- associated with Id whenever possible, i.e. when the full declaration
633 -- of the base type is already known. Records each subtype into
634 -- Private_Dependents of the base type.
636 procedure Process_Incomplete_Dependents
640 -- Process all entities that depend on an incomplete type. There include
641 -- subtypes, subprogram types that mention the incomplete type in their
642 -- profiles, and subprogram with access parameters that designate the
645 -- Inc_T is the defining identifier of an incomplete type declaration, its
646 -- Ekind is E_Incomplete_Type.
648 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
650 -- Full_T is N's defining identifier.
652 -- Subtypes of incomplete types with discriminants are completed when the
653 -- parent type is. This is simpler than private subtypes, because they can
654 -- only appear in the same scope, and there is no need to exchange views.
655 -- Similarly, access_to_subprogram types may have a parameter or a return
656 -- type that is an incomplete type, and that must be replaced with the
659 -- If the full type is tagged, subprogram with access parameters that
660 -- designated the incomplete may be primitive operations of the full type,
661 -- and have to be processed accordingly.
663 procedure Process_Real_Range_Specification
(Def
: Node_Id
);
664 -- Given the type definition for a real type, this procedure processes and
665 -- checks the real range specification of this type definition if one is
666 -- present. If errors are found, error messages are posted, and the
667 -- Real_Range_Specification of Def is reset to Empty.
669 procedure Record_Type_Declaration
673 -- Process a record type declaration (for both untagged and tagged
674 -- records). Parameters T and N are exactly like in procedure
675 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
676 -- for this routine. If this is the completion of an incomplete type
677 -- declaration, Prev is the entity of the incomplete declaration, used for
678 -- cross-referencing. Otherwise Prev = T.
680 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
);
681 -- This routine is used to process the actual record type definition (both
682 -- for untagged and tagged records). Def is a record type definition node.
683 -- This procedure analyzes the components in this record type definition.
684 -- Prev_T is the entity for the enclosing record type. It is provided so
685 -- that its Has_Task flag can be set if any of the component have Has_Task
686 -- set. If the declaration is the completion of an incomplete type
687 -- declaration, Prev_T is the original incomplete type, whose full view is
690 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
);
691 -- Subsidiary to Build_Derived_Record_Type. For untagged record types, we
692 -- first create the list of components for the derived type from that of
693 -- the parent by means of Inherit_Components and then build a copy of the
694 -- declaration tree of the parent with the help of the mapping returned by
695 -- Inherit_Components, which will for example be used to validate record
696 -- representation clauses given for the derived type. If the parent type
697 -- is private and has discriminants, the ancestor discriminants used in the
698 -- inheritance are that of the private declaration, whereas the ancestor
699 -- discriminants present in the declaration tree of the parent are that of
700 -- the full declaration; as a consequence, the remapping done during the
701 -- copy will leave the references to the ancestor discriminants unchanged
702 -- in the declaration tree and they need to be fixed up. If the derived
703 -- type has a known discriminant part, then the remapping done during the
704 -- copy will only create references to the stored discriminants and they
705 -- need to be replaced with references to the non-stored discriminants.
707 procedure Set_Fixed_Range
712 -- Build a range node with the given bounds and set it as the Scalar_Range
713 -- of the given fixed-point type entity. Loc is the source location used
714 -- for the constructed range. See body for further details.
716 procedure Set_Scalar_Range_For_Subtype
720 -- This routine is used to set the scalar range field for a subtype given
721 -- Def_Id, the entity for the subtype, and R, the range expression for the
722 -- scalar range. Subt provides the parent subtype to be used to analyze,
723 -- resolve, and check the given range.
725 procedure Set_Default_SSO
(T
: Entity_Id
);
726 -- T is the entity for an array or record being declared. This procedure
727 -- sets the flags SSO_Set_Low_By_Default/SSO_Set_High_By_Default according
728 -- to the setting of Opt.Default_SSO.
730 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
731 -- Create a new signed integer entity, and apply the constraint to obtain
732 -- the required first named subtype of this type.
734 procedure Set_Stored_Constraint_From_Discriminant_Constraint
736 -- E is some record type. This routine computes E's Stored_Constraint
737 -- from its Discriminant_Constraint.
739 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
);
740 -- Check that an entity in a list of progenitors is an interface,
741 -- emit error otherwise.
743 -----------------------
744 -- Access_Definition --
745 -----------------------
747 function Access_Definition
748 (Related_Nod
: Node_Id
;
749 N
: Node_Id
) return Entity_Id
751 Anon_Type
: Entity_Id
;
752 Anon_Scope
: Entity_Id
;
753 Desig_Type
: Entity_Id
;
754 Enclosing_Prot_Type
: Entity_Id
:= Empty
;
757 if Is_Entry
(Current_Scope
)
758 and then Is_Task_Type
(Etype
(Scope
(Current_Scope
)))
760 Error_Msg_N
("task entries cannot have access parameters", N
);
764 -- Ada 2005: For an object declaration the corresponding anonymous
765 -- type is declared in the current scope.
767 -- If the access definition is the return type of another access to
768 -- function, scope is the current one, because it is the one of the
769 -- current type declaration, except for the pathological case below.
771 if Nkind
(Related_Nod
) in
772 N_Object_Declaration | N_Access_Function_Definition
774 Anon_Scope
:= Current_Scope
;
776 -- A pathological case: function returning access functions that
777 -- return access functions, etc. Each anonymous access type created
778 -- is in the enclosing scope of the outermost function.
786 N_Access_Function_Definition | N_Access_Definition
791 if Nkind
(Par
) = N_Function_Specification
then
792 Anon_Scope
:= Scope
(Defining_Entity
(Par
));
796 -- For the anonymous function result case, retrieve the scope of the
797 -- function specification's associated entity rather than using the
798 -- current scope. The current scope will be the function itself if the
799 -- formal part is currently being analyzed, but will be the parent scope
800 -- in the case of a parameterless function, and we always want to use
801 -- the function's parent scope. Finally, if the function is a child
802 -- unit, we must traverse the tree to retrieve the proper entity.
804 elsif Nkind
(Related_Nod
) = N_Function_Specification
805 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
807 -- If the current scope is a protected type, the anonymous access
808 -- is associated with one of the protected operations, and must
809 -- be available in the scope that encloses the protected declaration.
810 -- Otherwise the type is in the scope enclosing the subprogram.
812 -- If the function has formals, the return type of a subprogram
813 -- declaration is analyzed in the scope of the subprogram (see
814 -- Process_Formals) and thus the protected type, if present, is
815 -- the scope of the current function scope.
817 if Ekind
(Current_Scope
) = E_Protected_Type
then
818 Enclosing_Prot_Type
:= Current_Scope
;
820 elsif Ekind
(Current_Scope
) = E_Function
821 and then Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
823 Enclosing_Prot_Type
:= Scope
(Current_Scope
);
826 if Present
(Enclosing_Prot_Type
) then
827 Anon_Scope
:= Scope
(Enclosing_Prot_Type
);
830 Anon_Scope
:= Scope
(Defining_Entity
(Related_Nod
));
833 -- For an access type definition, if the current scope is a child
834 -- unit it is the scope of the type.
836 elsif Is_Compilation_Unit
(Current_Scope
) then
837 Anon_Scope
:= Current_Scope
;
839 -- For access formals, access components, and access discriminants, the
840 -- scope is that of the enclosing declaration,
843 Anon_Scope
:= Scope
(Current_Scope
);
848 (E_Anonymous_Access_Type
, Related_Nod
, Scope_Id
=> Anon_Scope
);
851 and then Ada_Version
>= Ada_2005
853 Error_Msg_N
("ALL not permitted for anonymous access types", N
);
856 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
857 -- the corresponding semantic routine
859 if Present
(Access_To_Subprogram_Definition
(N
)) then
860 Access_Subprogram_Declaration
861 (T_Name
=> Anon_Type
,
862 T_Def
=> Access_To_Subprogram_Definition
(N
));
864 if Ekind
(Anon_Type
) = E_Access_Protected_Subprogram_Type
then
866 (Anon_Type
, E_Anonymous_Access_Protected_Subprogram_Type
);
868 Mutate_Ekind
(Anon_Type
, E_Anonymous_Access_Subprogram_Type
);
871 -- If the anonymous access is associated with a protected operation,
872 -- create a reference to it after the enclosing protected definition
873 -- because the itype will be used in the subsequent bodies.
875 -- If the anonymous access itself is protected, a full type
876 -- declaratiton will be created for it, so that the equivalent
877 -- record type can be constructed. For further details, see
878 -- Replace_Anonymous_Access_To_Protected-Subprogram.
880 if Ekind
(Current_Scope
) = E_Protected_Type
881 and then not Protected_Present
(Access_To_Subprogram_Definition
(N
))
883 Build_Itype_Reference
(Anon_Type
, Parent
(Current_Scope
));
889 Find_Type
(Subtype_Mark
(N
));
890 Desig_Type
:= Entity
(Subtype_Mark
(N
));
892 Set_Directly_Designated_Type
(Anon_Type
, Desig_Type
);
893 Set_Etype
(Anon_Type
, Anon_Type
);
895 -- Make sure the anonymous access type has size and alignment fields
896 -- set, as required by gigi. This is necessary in the case of the
897 -- Task_Body_Procedure.
899 if not Has_Private_Component
(Desig_Type
) then
900 Layout_Type
(Anon_Type
);
903 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
904 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
905 -- the null value is allowed. In Ada 95 the null value is never allowed.
907 if Ada_Version
>= Ada_2005
then
908 Set_Can_Never_Be_Null
(Anon_Type
, Null_Exclusion_Present
(N
));
910 Set_Can_Never_Be_Null
(Anon_Type
, True);
913 -- The anonymous access type is as public as the discriminated type or
914 -- subprogram that defines it. It is imported (for back-end purposes)
915 -- if the designated type is.
917 Set_Is_Public
(Anon_Type
, Is_Public
(Scope
(Anon_Type
)));
919 -- Ada 2005 (AI-231): Propagate the access-constant attribute
921 Set_Is_Access_Constant
(Anon_Type
, Constant_Present
(N
));
923 -- The context is either a subprogram declaration, object declaration,
924 -- or an access discriminant, in a private or a full type declaration.
925 -- In the case of a subprogram, if the designated type is incomplete,
926 -- the operation will be a primitive operation of the full type, to be
927 -- updated subsequently. If the type is imported through a limited_with
928 -- clause, the subprogram is not a primitive operation of the type
929 -- (which is declared elsewhere in some other scope).
931 if Ekind
(Desig_Type
) = E_Incomplete_Type
932 and then not From_Limited_With
(Desig_Type
)
933 and then Is_Overloadable
(Current_Scope
)
935 Append_Elmt
(Current_Scope
, Private_Dependents
(Desig_Type
));
936 Set_Has_Delayed_Freeze
(Current_Scope
);
939 -- If the designated type is limited and class-wide, the object might
940 -- contain tasks, so we create a Master entity for the declaration. This
941 -- must be done before expansion of the full declaration, because the
942 -- declaration may include an expression that is an allocator, whose
943 -- expansion needs the proper Master for the created tasks.
946 and then Nkind
(Related_Nod
) = N_Object_Declaration
948 if Is_Limited_Record
(Desig_Type
)
949 and then Is_Class_Wide_Type
(Desig_Type
)
951 Build_Class_Wide_Master
(Anon_Type
);
953 -- Similarly, if the type is an anonymous access that designates
954 -- tasks, create a master entity for it in the current context.
956 elsif Has_Task
(Desig_Type
)
957 and then Comes_From_Source
(Related_Nod
)
959 Build_Master_Entity
(Defining_Identifier
(Related_Nod
));
960 Build_Master_Renaming
(Anon_Type
);
964 -- For a private component of a protected type, it is imperative that
965 -- the back-end elaborate the type immediately after the protected
966 -- declaration, because this type will be used in the declarations
967 -- created for the component within each protected body, so we must
968 -- create an itype reference for it now.
970 if Nkind
(Parent
(Related_Nod
)) = N_Protected_Definition
then
971 Build_Itype_Reference
(Anon_Type
, Parent
(Parent
(Related_Nod
)));
973 -- Similarly, if the access definition is the return result of a
974 -- function, create an itype reference for it because it will be used
975 -- within the function body. For a regular function that is not a
976 -- compilation unit, insert reference after the declaration. For a
977 -- protected operation, insert it after the enclosing protected type
978 -- declaration. In either case, do not create a reference for a type
979 -- obtained through a limited_with clause, because this would introduce
980 -- semantic dependencies.
982 -- Similarly, do not create a reference if the designated type is a
983 -- generic formal, because no use of it will reach the backend.
985 elsif Nkind
(Related_Nod
) = N_Function_Specification
986 and then not From_Limited_With
(Desig_Type
)
987 and then not Is_Generic_Type
(Desig_Type
)
989 if Present
(Enclosing_Prot_Type
) then
990 Build_Itype_Reference
(Anon_Type
, Parent
(Enclosing_Prot_Type
));
992 elsif Is_List_Member
(Parent
(Related_Nod
))
993 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
995 Build_Itype_Reference
(Anon_Type
, Parent
(Related_Nod
));
998 -- Finally, create an itype reference for an object declaration of an
999 -- anonymous access type. This is strictly necessary only for deferred
1000 -- constants, but in any case will avoid out-of-scope problems in the
1003 elsif Nkind
(Related_Nod
) = N_Object_Declaration
then
1004 Build_Itype_Reference
(Anon_Type
, Related_Nod
);
1008 end Access_Definition
;
1010 -----------------------------------
1011 -- Access_Subprogram_Declaration --
1012 -----------------------------------
1014 procedure Access_Subprogram_Declaration
1015 (T_Name
: Entity_Id
;
1018 procedure Check_For_Premature_Usage
(Def
: Node_Id
);
1019 -- Check that type T_Name is not used, directly or recursively, as a
1020 -- parameter or a return type in Def. Def is either a subtype, an
1021 -- access_definition, or an access_to_subprogram_definition.
1023 -------------------------------
1024 -- Check_For_Premature_Usage --
1025 -------------------------------
1027 procedure Check_For_Premature_Usage
(Def
: Node_Id
) is
1031 -- Check for a subtype mark
1033 if Nkind
(Def
) in N_Has_Etype
then
1034 if Etype
(Def
) = T_Name
then
1036 ("type& cannot be used before the end of its declaration",
1040 -- If this is not a subtype, then this is an access_definition
1042 elsif Nkind
(Def
) = N_Access_Definition
then
1043 if Present
(Access_To_Subprogram_Definition
(Def
)) then
1044 Check_For_Premature_Usage
1045 (Access_To_Subprogram_Definition
(Def
));
1047 Check_For_Premature_Usage
(Subtype_Mark
(Def
));
1050 -- The only cases left are N_Access_Function_Definition and
1051 -- N_Access_Procedure_Definition.
1054 if Present
(Parameter_Specifications
(Def
)) then
1055 Param
:= First
(Parameter_Specifications
(Def
));
1056 while Present
(Param
) loop
1057 Check_For_Premature_Usage
(Parameter_Type
(Param
));
1062 if Nkind
(Def
) = N_Access_Function_Definition
then
1063 Check_For_Premature_Usage
(Result_Definition
(Def
));
1066 end Check_For_Premature_Usage
;
1070 Formals
: constant List_Id
:= Parameter_Specifications
(T_Def
);
1073 Desig_Type
: constant Entity_Id
:=
1074 Create_Itype
(E_Subprogram_Type
, Parent
(T_Def
));
1076 -- Start of processing for Access_Subprogram_Declaration
1079 -- Associate the Itype node with the inner full-type declaration or
1080 -- subprogram spec or entry body. This is required to handle nested
1081 -- anonymous declarations. For example:
1084 -- (X : access procedure
1085 -- (Y : access procedure
1088 D_Ityp
:= Associated_Node_For_Itype
(Desig_Type
);
1089 while Nkind
(D_Ityp
) not in N_Full_Type_Declaration
1090 | N_Private_Type_Declaration
1091 | N_Private_Extension_Declaration
1092 | N_Procedure_Specification
1093 | N_Function_Specification
1095 | N_Object_Declaration
1096 | N_Object_Renaming_Declaration
1097 | N_Formal_Object_Declaration
1098 | N_Formal_Type_Declaration
1099 | N_Task_Type_Declaration
1100 | N_Protected_Type_Declaration
1102 D_Ityp
:= Parent
(D_Ityp
);
1103 pragma Assert
(D_Ityp
/= Empty
);
1106 Set_Associated_Node_For_Itype
(Desig_Type
, D_Ityp
);
1108 if Nkind
(D_Ityp
) in N_Procedure_Specification | N_Function_Specification
1110 Set_Scope
(Desig_Type
, Scope
(Defining_Entity
(D_Ityp
)));
1112 elsif Nkind
(D_Ityp
) in N_Full_Type_Declaration
1113 | N_Object_Declaration
1114 | N_Object_Renaming_Declaration
1115 | N_Formal_Type_Declaration
1117 Set_Scope
(Desig_Type
, Scope
(Defining_Identifier
(D_Ityp
)));
1120 if Nkind
(T_Def
) = N_Access_Function_Definition
then
1121 if Nkind
(Result_Definition
(T_Def
)) = N_Access_Definition
then
1123 Acc
: constant Node_Id
:= Result_Definition
(T_Def
);
1126 if Present
(Access_To_Subprogram_Definition
(Acc
))
1128 Protected_Present
(Access_To_Subprogram_Definition
(Acc
))
1132 Replace_Anonymous_Access_To_Protected_Subprogram
1138 Access_Definition
(T_Def
, Result_Definition
(T_Def
)));
1143 Analyze
(Result_Definition
(T_Def
));
1146 Typ
: constant Entity_Id
:= Entity
(Result_Definition
(T_Def
));
1149 -- If a null exclusion is imposed on the result type, then
1150 -- create a null-excluding itype (an access subtype) and use
1151 -- it as the function's Etype.
1153 if Is_Access_Type
(Typ
)
1154 and then Null_Exclusion_In_Return_Present
(T_Def
)
1156 Set_Etype
(Desig_Type
,
1157 Create_Null_Excluding_Itype
1159 Related_Nod
=> T_Def
,
1160 Scope_Id
=> Current_Scope
));
1163 if From_Limited_With
(Typ
) then
1165 -- AI05-151: Incomplete types are allowed in all basic
1166 -- declarations, including access to subprograms.
1168 if Ada_Version
>= Ada_2012
then
1173 ("illegal use of incomplete type&",
1174 Result_Definition
(T_Def
), Typ
);
1177 elsif Ekind
(Current_Scope
) = E_Package
1178 and then In_Private_Part
(Current_Scope
)
1180 if Ekind
(Typ
) = E_Incomplete_Type
then
1181 Append_Elmt
(Desig_Type
, Private_Dependents
(Typ
));
1183 elsif Is_Class_Wide_Type
(Typ
)
1184 and then Ekind
(Etype
(Typ
)) = E_Incomplete_Type
1187 (Desig_Type
, Private_Dependents
(Etype
(Typ
)));
1191 Set_Etype
(Desig_Type
, Typ
);
1196 if not Is_Type
(Etype
(Desig_Type
)) then
1198 ("expect type in function specification",
1199 Result_Definition
(T_Def
));
1203 Set_Etype
(Desig_Type
, Standard_Void_Type
);
1206 if Present
(Formals
) then
1207 Push_Scope
(Desig_Type
);
1209 -- Some special tests here. These special tests can be removed
1210 -- if and when Itypes always have proper parent pointers to their
1213 -- Special test 1) Link defining_identifier of formals. Required by
1214 -- First_Formal to provide its functionality.
1220 F
:= First
(Formals
);
1222 while Present
(F
) loop
1223 if No
(Parent
(Defining_Identifier
(F
))) then
1224 Set_Parent
(Defining_Identifier
(F
), F
);
1231 Process_Formals
(Formals
, Parent
(T_Def
));
1233 -- Special test 2) End_Scope requires that the parent pointer be set
1234 -- to something reasonable, but Itypes don't have parent pointers. So
1235 -- we set it and then unset it ???
1237 Set_Parent
(Desig_Type
, T_Name
);
1239 Set_Parent
(Desig_Type
, Empty
);
1242 -- Check for premature usage of the type being defined
1244 Check_For_Premature_Usage
(T_Def
);
1246 -- The return type and/or any parameter type may be incomplete. Mark the
1247 -- subprogram_type as depending on the incomplete type, so that it can
1248 -- be updated when the full type declaration is seen. This only applies
1249 -- to incomplete types declared in some enclosing scope, not to limited
1250 -- views from other packages.
1252 -- Prior to Ada 2012, access to functions can only have in_parameters.
1254 if Present
(Formals
) then
1255 Formal
:= First_Formal
(Desig_Type
);
1256 while Present
(Formal
) loop
1257 if Ekind
(Formal
) /= E_In_Parameter
1258 and then Nkind
(T_Def
) = N_Access_Function_Definition
1259 and then Ada_Version
< Ada_2012
1261 Error_Msg_N
("functions can only have IN parameters", Formal
);
1264 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
1265 and then In_Open_Scopes
(Scope
(Etype
(Formal
)))
1267 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Formal
)));
1268 Set_Has_Delayed_Freeze
(Desig_Type
);
1271 Next_Formal
(Formal
);
1275 -- Check whether an indirect call without actuals may be possible. This
1276 -- is used when resolving calls whose result is then indexed.
1278 May_Need_Actuals
(Desig_Type
);
1280 -- If the return type is incomplete, this is legal as long as the type
1281 -- is declared in the current scope and will be completed in it (rather
1282 -- than being part of limited view).
1284 if Ekind
(Etype
(Desig_Type
)) = E_Incomplete_Type
1285 and then not Has_Delayed_Freeze
(Desig_Type
)
1286 and then In_Open_Scopes
(Scope
(Etype
(Desig_Type
)))
1288 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Desig_Type
)));
1289 Set_Has_Delayed_Freeze
(Desig_Type
);
1292 Check_Delayed_Subprogram
(Desig_Type
);
1294 if Protected_Present
(T_Def
) then
1295 Mutate_Ekind
(T_Name
, E_Access_Protected_Subprogram_Type
);
1296 Set_Convention
(Desig_Type
, Convention_Protected
);
1298 Mutate_Ekind
(T_Name
, E_Access_Subprogram_Type
);
1301 Set_Can_Use_Internal_Rep
(T_Name
,
1302 not Always_Compatible_Rep_On_Target
);
1303 Set_Etype
(T_Name
, T_Name
);
1304 Reinit_Size_Align
(T_Name
);
1305 Set_Directly_Designated_Type
(T_Name
, Desig_Type
);
1307 -- If the access_to_subprogram is not declared at the library level,
1308 -- it can only point to subprograms that are at the same or deeper
1309 -- accessibility level. The corresponding subprogram type might
1310 -- require an activation record when compiling for C.
1312 Set_Needs_Activation_Record
(Desig_Type
,
1313 not Is_Library_Level_Entity
(T_Name
));
1315 Generate_Reference_To_Formals
(T_Name
);
1317 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1319 Set_Can_Never_Be_Null
(T_Name
, Null_Exclusion_Present
(T_Def
));
1321 Check_Restriction
(No_Access_Subprograms
, T_Def
);
1323 -- Addition of extra formals must be delayed till the freeze point so
1324 -- that we know the convention.
1325 end Access_Subprogram_Declaration
;
1327 ----------------------------
1328 -- Access_Type_Declaration --
1329 ----------------------------
1331 procedure Access_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
1333 procedure Setup_Access_Type
(Desig_Typ
: Entity_Id
);
1334 -- After type declaration is analysed with T being an incomplete type,
1335 -- this routine will mutate the kind of T to the appropriate access type
1336 -- and set its directly designated type to Desig_Typ.
1338 -----------------------
1339 -- Setup_Access_Type --
1340 -----------------------
1342 procedure Setup_Access_Type
(Desig_Typ
: Entity_Id
) is
1344 if All_Present
(Def
) or else Constant_Present
(Def
) then
1345 Mutate_Ekind
(T
, E_General_Access_Type
);
1347 Mutate_Ekind
(T
, E_Access_Type
);
1350 Set_Directly_Designated_Type
(T
, Desig_Typ
);
1351 end Setup_Access_Type
;
1355 P
: constant Node_Id
:= Parent
(Def
);
1356 S
: constant Node_Id
:= Subtype_Indication
(Def
);
1358 Full_Desig
: Entity_Id
;
1360 -- Start of processing for Access_Type_Declaration
1363 -- Check for permissible use of incomplete type
1365 if Nkind
(S
) /= N_Subtype_Indication
then
1369 if Nkind
(S
) in N_Has_Entity
1370 and then Present
(Entity
(S
))
1371 and then Ekind
(Root_Type
(Entity
(S
))) = E_Incomplete_Type
1373 Setup_Access_Type
(Desig_Typ
=> Entity
(S
));
1375 -- If the designated type is a limited view, we cannot tell if
1376 -- the full view contains tasks, and there is no way to handle
1377 -- that full view in a client. We create a master entity for the
1378 -- scope, which will be used when a client determines that one
1381 if From_Limited_With
(Entity
(S
))
1382 and then not Is_Class_Wide_Type
(Entity
(S
))
1384 Build_Master_Entity
(T
);
1385 Build_Master_Renaming
(T
);
1389 Setup_Access_Type
(Desig_Typ
=> Process_Subtype
(S
, P
, T
, 'P'));
1392 -- If the access definition is of the form: ACCESS NOT NULL ..
1393 -- the subtype indication must be of an access type. Create
1394 -- a null-excluding subtype of it.
1396 if Null_Excluding_Subtype
(Def
) then
1397 if not Is_Access_Type
(Entity
(S
)) then
1398 Error_Msg_N
("null exclusion must apply to access type", Def
);
1402 Loc
: constant Source_Ptr
:= Sloc
(S
);
1404 Nam
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1408 Make_Subtype_Declaration
(Loc
,
1409 Defining_Identifier
=> Nam
,
1410 Subtype_Indication
=>
1411 New_Occurrence_Of
(Entity
(S
), Loc
));
1412 Set_Null_Exclusion_Present
(Decl
);
1413 Insert_Before
(Parent
(Def
), Decl
);
1415 Set_Entity
(S
, Nam
);
1421 Setup_Access_Type
(Desig_Typ
=> Process_Subtype
(S
, P
, T
, 'P'));
1424 if not Error_Posted
(T
) then
1425 Full_Desig
:= Designated_Type
(T
);
1427 if Base_Type
(Full_Desig
) = T
then
1428 Error_Msg_N
("access type cannot designate itself", S
);
1430 -- In Ada 2005, the type may have a limited view through some unit in
1431 -- its own context, allowing the following circularity that cannot be
1432 -- detected earlier.
1434 elsif Is_Class_Wide_Type
(Full_Desig
) and then Etype
(Full_Desig
) = T
1437 ("access type cannot designate its own class-wide type", S
);
1439 -- Clean up indication of tagged status to prevent cascaded errors
1441 Set_Is_Tagged_Type
(T
, False);
1446 -- For SPARK, check that the designated type is compatible with
1447 -- respect to volatility with the access type.
1449 if SPARK_Mode
/= Off
1450 and then Comes_From_Source
(T
)
1452 -- ??? UNIMPLEMENTED
1453 -- In the case where the designated type is incomplete at this
1454 -- point, performing this check here is harmless but the check
1455 -- will need to be repeated when the designated type is complete.
1457 -- The preceding call to Comes_From_Source is needed because the
1458 -- FE sometimes introduces implicitly declared access types. See,
1459 -- for example, the expansion of nested_po.ads in OA28-015.
1461 Check_Volatility_Compatibility
1462 (Full_Desig
, T
, "designated type", "access type",
1463 Srcpos_Bearer
=> T
);
1467 -- If the type has appeared already in a with_type clause, it is frozen
1468 -- and the pointer size is already set. Else, initialize.
1470 if not From_Limited_With
(T
) then
1471 Reinit_Size_Align
(T
);
1474 -- Note that Has_Task is always false, since the access type itself
1475 -- is not a task type. See Einfo for more description on this point.
1476 -- Exactly the same consideration applies to Has_Controlled_Component
1477 -- and to Has_Protected.
1479 Set_Has_Task
(T
, False);
1480 Set_Has_Protected
(T
, False);
1481 Set_Has_Timing_Event
(T
, False);
1482 Set_Has_Controlled_Component
(T
, False);
1484 -- Initialize field Finalization_Master explicitly to Empty, to avoid
1485 -- problems where an incomplete view of this entity has been previously
1486 -- established by a limited with and an overlaid version of this field
1487 -- (Stored_Constraint) was initialized for the incomplete view.
1489 -- This reset is performed in most cases except where the access type
1490 -- has been created for the purposes of allocating or deallocating a
1491 -- build-in-place object. Such access types have explicitly set pools
1492 -- and finalization masters.
1494 if No
(Associated_Storage_Pool
(T
)) then
1495 Set_Finalization_Master
(T
, Empty
);
1498 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1501 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
1502 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
1503 end Access_Type_Declaration
;
1505 ----------------------------------
1506 -- Add_Interface_Tag_Components --
1507 ----------------------------------
1509 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
) is
1510 Loc
: constant Source_Ptr
:= Sloc
(N
);
1514 procedure Add_Tag
(Iface
: Entity_Id
);
1515 -- Add tag for one of the progenitor interfaces
1521 procedure Add_Tag
(Iface
: Entity_Id
) is
1528 pragma Assert
(Is_Tagged_Type
(Iface
) and then Is_Interface
(Iface
));
1530 -- This is a reasonable place to propagate predicates
1532 if Has_Predicates
(Iface
) then
1533 Set_Has_Predicates
(Typ
);
1537 Make_Component_Definition
(Loc
,
1538 Aliased_Present
=> True,
1539 Subtype_Indication
=>
1540 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
));
1542 Tag
:= Make_Temporary
(Loc
, 'V');
1545 Make_Component_Declaration
(Loc
,
1546 Defining_Identifier
=> Tag
,
1547 Component_Definition
=> Def
);
1549 Analyze_Component_Declaration
(Decl
);
1551 Set_Analyzed
(Decl
);
1552 Mutate_Ekind
(Tag
, E_Component
);
1554 Set_Is_Aliased
(Tag
);
1555 Set_Is_Independent
(Tag
);
1556 Set_Related_Type
(Tag
, Iface
);
1557 Reinit_Component_Location
(Tag
);
1559 pragma Assert
(Is_Frozen
(Iface
));
1561 Set_DT_Entry_Count
(Tag
,
1562 DT_Entry_Count
(First_Entity
(Iface
)));
1564 if No
(Last_Tag
) then
1567 Insert_After
(Last_Tag
, Decl
);
1572 -- If the ancestor has discriminants we need to give special support
1573 -- to store the offset_to_top value of the secondary dispatch tables.
1574 -- For this purpose we add a supplementary component just after the
1575 -- field that contains the tag associated with each secondary DT.
1577 if Typ
/= Etype
(Typ
) and then Has_Discriminants
(Etype
(Typ
)) then
1579 Make_Component_Definition
(Loc
,
1580 Subtype_Indication
=>
1581 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
1583 Offset
:= Make_Temporary
(Loc
, 'V');
1586 Make_Component_Declaration
(Loc
,
1587 Defining_Identifier
=> Offset
,
1588 Component_Definition
=> Def
);
1590 Analyze_Component_Declaration
(Decl
);
1592 Set_Analyzed
(Decl
);
1593 Mutate_Ekind
(Offset
, E_Component
);
1594 Set_Is_Aliased
(Offset
);
1595 Set_Is_Independent
(Offset
);
1596 Set_Related_Type
(Offset
, Iface
);
1597 Reinit_Component_Location
(Offset
);
1598 Insert_After
(Last_Tag
, Decl
);
1609 -- Start of processing for Add_Interface_Tag_Components
1612 if not RTE_Available
(RE_Interface_Tag
) then
1614 ("(Ada 2005) interface types not supported by this run-time!", N
);
1618 if Ekind
(Typ
) /= E_Record_Type
1619 or else (Is_Concurrent_Record_Type
(Typ
)
1620 and then Is_Empty_List
(Abstract_Interface_List
(Typ
)))
1621 or else (not Is_Concurrent_Record_Type
(Typ
)
1622 and then No
(Interfaces
(Typ
))
1623 and then Is_Empty_Elmt_List
(Interfaces
(Typ
)))
1628 -- Find the current last tag
1630 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1631 Ext
:= Record_Extension_Part
(Type_Definition
(N
));
1633 pragma Assert
(Nkind
(Type_Definition
(N
)) = N_Record_Definition
);
1634 Ext
:= Type_Definition
(N
);
1639 if not (Present
(Component_List
(Ext
))) then
1640 Set_Null_Present
(Ext
, False);
1642 Set_Component_List
(Ext
,
1643 Make_Component_List
(Loc
,
1644 Component_Items
=> L
,
1645 Null_Present
=> False));
1647 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1648 L
:= Component_Items
1650 (Record_Extension_Part
1651 (Type_Definition
(N
))));
1653 L
:= Component_Items
1655 (Type_Definition
(N
)));
1658 -- Find the last tag component
1661 while Present
(Comp
) loop
1662 if Nkind
(Comp
) = N_Component_Declaration
1663 and then Is_Tag
(Defining_Identifier
(Comp
))
1672 -- At this point L references the list of components and Last_Tag
1673 -- references the current last tag (if any). Now we add the tag
1674 -- corresponding with all the interfaces that are not implemented
1677 if Present
(Interfaces
(Typ
)) then
1678 Elmt
:= First_Elmt
(Interfaces
(Typ
));
1679 while Present
(Elmt
) loop
1680 Add_Tag
(Node
(Elmt
));
1684 end Add_Interface_Tag_Components
;
1686 -------------------------------------
1687 -- Add_Internal_Interface_Entities --
1688 -------------------------------------
1690 procedure Add_Internal_Interface_Entities
(Tagged_Type
: Entity_Id
) is
1692 function Error_Posted_In_Formals
(Subp
: Entity_Id
) return Boolean;
1693 -- Determine if an error has been posted in some formal of Subp.
1695 -----------------------------
1696 -- Error_Posted_In_Formals --
1697 -----------------------------
1699 function Error_Posted_In_Formals
(Subp
: Entity_Id
) return Boolean is
1700 Formal
: Entity_Id
:= First_Formal
(Subp
);
1703 while Present
(Formal
) loop
1704 if Error_Posted
(Formal
) then
1708 Next_Formal
(Formal
);
1712 end Error_Posted_In_Formals
;
1718 Iface_Elmt
: Elmt_Id
;
1719 Iface_Prim
: Entity_Id
;
1720 Ifaces_List
: Elist_Id
;
1721 New_Subp
: Entity_Id
:= Empty
;
1723 Restore_Scope
: Boolean := False;
1726 pragma Assert
(Ada_Version
>= Ada_2005
1727 and then Is_Record_Type
(Tagged_Type
)
1728 and then Is_Tagged_Type
(Tagged_Type
)
1729 and then Has_Interfaces
(Tagged_Type
)
1730 and then not Is_Interface
(Tagged_Type
));
1732 -- Ensure that the internal entities are added to the scope of the type
1734 if Scope
(Tagged_Type
) /= Current_Scope
then
1735 Push_Scope
(Scope
(Tagged_Type
));
1736 Restore_Scope
:= True;
1739 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1741 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1742 while Present
(Iface_Elmt
) loop
1743 Iface
:= Node
(Iface_Elmt
);
1745 -- Originally we excluded here from this processing interfaces that
1746 -- are parents of Tagged_Type because their primitives are located
1747 -- in the primary dispatch table (and hence no auxiliary internal
1748 -- entities are required to handle secondary dispatch tables in such
1749 -- case). However, these auxiliary entities are also required to
1750 -- handle derivations of interfaces in formals of generics (see
1751 -- Derive_Subprograms).
1753 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1754 while Present
(Elmt
) loop
1755 Iface_Prim
:= Node
(Elmt
);
1757 if not Is_Predefined_Dispatching_Operation
(Iface_Prim
) then
1759 Find_Primitive_Covering_Interface
1760 (Tagged_Type
=> Tagged_Type
,
1761 Iface_Prim
=> Iface_Prim
);
1763 if No
(Prim
) and then Serious_Errors_Detected
> 0 then
1767 pragma Assert
(Present
(Prim
));
1769 -- Check subtype conformance; we skip this check if errors have
1770 -- been reported in the primitive (or in the formals of the
1771 -- primitive) because Find_Primitive_Covering_Interface relies
1772 -- on the subprogram Type_Conformant to locate the primitive,
1773 -- and reports errors if the formals don't match.
1775 if not Error_Posted
(Prim
)
1776 and then not Error_Posted_In_Formals
(Prim
)
1779 Alias_Prim
: Entity_Id
;
1780 Alias_Typ
: Entity_Id
;
1781 Err_Loc
: Node_Id
:= Empty
;
1782 Ret_Type
: Entity_Id
;
1785 -- For inherited primitives, in case of reporting an
1786 -- error, the error must be reported on this primitive
1787 -- (i.e. in the name of its type declaration); otherwise
1788 -- the error would be reported in the formal of the
1789 -- alias primitive defined on its parent type.
1791 if Nkind
(Parent
(Prim
)) = N_Full_Type_Declaration
then
1795 -- Check subtype conformance of procedures, functions
1796 -- with matching return type, or functions not returning
1799 if Ekind
(Prim
) = E_Procedure
1800 or else Etype
(Iface_Prim
) = Etype
(Prim
)
1801 or else not Is_Interface
(Etype
(Iface_Prim
))
1803 Check_Subtype_Conformant
1805 Old_Id
=> Iface_Prim
,
1807 Skip_Controlling_Formals
=> True);
1809 -- Check subtype conformance of functions returning an
1810 -- interface type; temporarily force both entities to
1811 -- return the same type. Required because subprogram
1812 -- Subtype_Conformant does not handle this case.
1815 Ret_Type
:= Etype
(Iface_Prim
);
1816 Set_Etype
(Iface_Prim
, Etype
(Prim
));
1818 Check_Subtype_Conformant
1820 Old_Id
=> Iface_Prim
,
1822 Skip_Controlling_Formals
=> True);
1824 Set_Etype
(Iface_Prim
, Ret_Type
);
1827 -- Complete the error when reported on inherited
1830 if Nkind
(Parent
(Prim
)) = N_Full_Type_Declaration
1831 and then (Error_Posted
(Prim
)
1832 or else Error_Posted_In_Formals
(Prim
))
1833 and then Present
(Alias
(Prim
))
1835 Alias_Prim
:= Ultimate_Alias
(Prim
);
1836 Alias_Typ
:= Find_Dispatching_Type
(Alias_Prim
);
1838 if Alias_Typ
/= Tagged_Type
1839 and then Is_Ancestor
(Alias_Typ
, Tagged_Type
)
1841 Error_Msg_Sloc
:= Sloc
(Alias_Prim
);
1843 ("in primitive inherited from #!", Prim
);
1849 -- Ada 2012 (AI05-0197): If the name of the covering primitive
1850 -- differs from the name of the interface primitive then it is
1851 -- a private primitive inherited from a parent type. In such
1852 -- case, given that Tagged_Type covers the interface, the
1853 -- inherited private primitive becomes visible. For such
1854 -- purpose we add a new entity that renames the inherited
1855 -- private primitive.
1857 if Chars
(Prim
) /= Chars
(Iface_Prim
) then
1858 pragma Assert
(Has_Suffix
(Prim
, 'P'));
1860 (New_Subp
=> New_Subp
,
1861 Parent_Subp
=> Iface_Prim
,
1862 Derived_Type
=> Tagged_Type
,
1863 Parent_Type
=> Iface
);
1864 Set_Alias
(New_Subp
, Prim
);
1865 Set_Is_Abstract_Subprogram
1866 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1870 (New_Subp
=> New_Subp
,
1871 Parent_Subp
=> Iface_Prim
,
1872 Derived_Type
=> Tagged_Type
,
1873 Parent_Type
=> Iface
);
1878 if Is_Inherited_Operation
(Prim
)
1879 and then Present
(Alias
(Prim
))
1881 Anc
:= Alias
(Prim
);
1883 Anc
:= Overridden_Operation
(Prim
);
1886 -- Apply legality checks in RM 6.1.1 (10-13) concerning
1887 -- nonconforming preconditions in both an ancestor and
1888 -- a progenitor operation.
1890 -- If the operation is a primitive wrapper it is an explicit
1891 -- (overriding) operqtion and all is fine.
1894 and then Has_Non_Trivial_Precondition
(Anc
)
1895 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
1897 if Is_Abstract_Subprogram
(Prim
)
1899 (Ekind
(Prim
) = E_Procedure
1900 and then Nkind
(Parent
(Prim
)) =
1901 N_Procedure_Specification
1902 and then Null_Present
(Parent
(Prim
)))
1903 or else Is_Primitive_Wrapper
(Prim
)
1907 -- The operation is inherited and must be overridden
1909 elsif not Comes_From_Source
(Prim
) then
1911 ("&inherits non-conforming preconditions and must "
1912 & "be overridden (RM 6.1.1 (10-16))",
1913 Parent
(Tagged_Type
), Prim
);
1918 -- Ada 2005 (AI-251): Decorate internal entity Iface_Subp
1919 -- associated with interface types. These entities are
1920 -- only registered in the list of primitives of its
1921 -- corresponding tagged type because they are only used
1922 -- to fill the contents of the secondary dispatch tables.
1923 -- Therefore they are removed from the homonym chains.
1925 Set_Is_Hidden
(New_Subp
);
1926 Set_Is_Internal
(New_Subp
);
1927 Set_Alias
(New_Subp
, Prim
);
1928 Set_Is_Abstract_Subprogram
1929 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1930 Set_Interface_Alias
(New_Subp
, Iface_Prim
);
1932 -- If the returned type is an interface then propagate it to
1933 -- the returned type. Needed by the thunk to generate the code
1934 -- which displaces "this" to reference the corresponding
1935 -- secondary dispatch table in the returned object.
1937 if Is_Interface
(Etype
(Iface_Prim
)) then
1938 Set_Etype
(New_Subp
, Etype
(Iface_Prim
));
1941 -- Internal entities associated with interface types are only
1942 -- registered in the list of primitives of the tagged type.
1943 -- They are only used to fill the contents of the secondary
1944 -- dispatch tables. Therefore they are not needed in the
1947 Remove_Homonym
(New_Subp
);
1949 -- Hidden entities associated with interfaces must have set
1950 -- the Has_Delay_Freeze attribute to ensure that, in case
1951 -- of locally defined tagged types (or compiling with static
1952 -- dispatch tables generation disabled) the corresponding
1953 -- entry of the secondary dispatch table is filled when such
1954 -- an entity is frozen.
1956 Set_Has_Delayed_Freeze
(New_Subp
);
1963 Next_Elmt
(Iface_Elmt
);
1966 if Restore_Scope
then
1969 end Add_Internal_Interface_Entities
;
1971 -----------------------------------
1972 -- Analyze_Component_Declaration --
1973 -----------------------------------
1975 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
1976 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1977 E
: constant Node_Id
:= Expression
(N
);
1978 Typ
: constant Node_Id
:=
1979 Subtype_Indication
(Component_Definition
(N
));
1983 function Contains_POC
(Constr
: Node_Id
) return Boolean;
1984 -- Determines whether a constraint uses the discriminant of a record
1985 -- type thus becoming a per-object constraint (POC).
1987 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean;
1988 -- Typ is the type of the current component, check whether this type is
1989 -- a limited type. Used to validate declaration against that of
1990 -- enclosing record.
1996 function Contains_POC
(Constr
: Node_Id
) return Boolean is
1998 -- Prevent cascaded errors
2000 if Error_Posted
(Constr
) then
2004 case Nkind
(Constr
) is
2005 when N_Attribute_Reference
=>
2006 return Attribute_Name
(Constr
) = Name_Access
2007 and then Prefix
(Constr
) = Scope
(Entity
(Prefix
(Constr
)));
2009 when N_Discriminant_Association
=>
2010 return Denotes_Discriminant
(Expression
(Constr
));
2012 when N_Identifier
=>
2013 return Denotes_Discriminant
(Constr
);
2015 when N_Index_Or_Discriminant_Constraint
=>
2020 IDC
:= First
(Constraints
(Constr
));
2021 while Present
(IDC
) loop
2023 -- One per-object constraint is sufficient
2025 if Contains_POC
(IDC
) then
2036 return Denotes_Discriminant
(Low_Bound
(Constr
))
2038 Denotes_Discriminant
(High_Bound
(Constr
));
2040 when N_Range_Constraint
=>
2041 return Denotes_Discriminant
(Range_Expression
(Constr
));
2048 ----------------------
2049 -- Is_Known_Limited --
2050 ----------------------
2052 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean is
2053 P
: constant Entity_Id
:= Etype
(Typ
);
2054 R
: constant Entity_Id
:= Root_Type
(Typ
);
2057 if Is_Limited_Record
(Typ
) then
2060 -- If the root type is limited (and not a limited interface) so is
2061 -- the current type.
2063 elsif Is_Limited_Record
(R
)
2064 and then (not Is_Interface
(R
) or else not Is_Limited_Interface
(R
))
2068 -- Else the type may have a limited interface progenitor, but a
2069 -- limited record parent that is not an interface.
2072 and then Is_Limited_Record
(P
)
2073 and then not Is_Interface
(P
)
2080 end Is_Known_Limited
;
2082 -- Start of processing for Analyze_Component_Declaration
2085 Generate_Definition
(Id
);
2088 if Present
(Typ
) then
2089 T
:= Find_Type_Of_Object
2090 (Subtype_Indication
(Component_Definition
(N
)), N
);
2092 -- Ada 2005 (AI-230): Access Definition case
2095 pragma Assert
(Present
2096 (Access_Definition
(Component_Definition
(N
))));
2098 T
:= Access_Definition
2100 N
=> Access_Definition
(Component_Definition
(N
)));
2101 Set_Is_Local_Anonymous_Access
(T
);
2103 -- Ada 2005 (AI-254)
2105 if Present
(Access_To_Subprogram_Definition
2106 (Access_Definition
(Component_Definition
(N
))))
2107 and then Protected_Present
(Access_To_Subprogram_Definition
2109 (Component_Definition
(N
))))
2111 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2115 -- If the subtype is a constrained subtype of the enclosing record,
2116 -- (which must have a partial view) the back-end does not properly
2117 -- handle the recursion. Rewrite the component declaration with an
2118 -- explicit subtype indication, which is acceptable to Gigi. We can copy
2119 -- the tree directly because side effects have already been removed from
2120 -- discriminant constraints.
2122 if Ekind
(T
) = E_Access_Subtype
2123 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
2124 and then Comes_From_Source
(T
)
2125 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
2126 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
2129 (Subtype_Indication
(Component_Definition
(N
)),
2130 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
2131 T
:= Find_Type_Of_Object
2132 (Subtype_Indication
(Component_Definition
(N
)), N
);
2135 -- If the component declaration includes a default expression, then we
2136 -- check that the component is not of a limited type (RM 3.7(5)),
2137 -- and do the special preanalysis of the expression (see section on
2138 -- "Handling of Default and Per-Object Expressions" in the spec of
2142 Preanalyze_Default_Expression
(E
, T
);
2143 Check_Initialization
(T
, E
);
2145 if Ada_Version
>= Ada_2005
2146 and then Ekind
(T
) = E_Anonymous_Access_Type
2147 and then Etype
(E
) /= Any_Type
2149 -- Check RM 3.9.2(9): "if the expected type for an expression is
2150 -- an anonymous access-to-specific tagged type, then the object
2151 -- designated by the expression shall not be dynamically tagged
2152 -- unless it is a controlling operand in a call on a dispatching
2155 if Is_Tagged_Type
(Directly_Designated_Type
(T
))
2157 Ekind
(Directly_Designated_Type
(T
)) /= E_Class_Wide_Type
2159 Ekind
(Directly_Designated_Type
(Etype
(E
))) =
2163 ("access to specific tagged type required (RM 3.9.2(9))", E
);
2166 -- (Ada 2005: AI-230): Accessibility check for anonymous
2169 if Type_Access_Level
(Etype
(E
)) >
2170 Deepest_Type_Access_Level
(T
)
2173 ("expression has deeper access level than component " &
2174 "(RM 3.10.2 (12.2))", E
);
2177 -- The initialization expression is a reference to an access
2178 -- discriminant. The type of the discriminant is always deeper
2179 -- than any access type.
2181 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
2182 and then Is_Entity_Name
(E
)
2183 and then Ekind
(Entity
(E
)) = E_In_Parameter
2184 and then Present
(Discriminal_Link
(Entity
(E
)))
2187 ("discriminant has deeper accessibility level than target",
2193 -- The parent type may be a private view with unknown discriminants,
2194 -- and thus unconstrained. Regular components must be constrained.
2196 if not Is_Definite_Subtype
(T
)
2197 and then Chars
(Id
) /= Name_uParent
2199 if Is_Class_Wide_Type
(T
) then
2201 ("class-wide subtype with unknown discriminants" &
2202 " in component declaration",
2203 Subtype_Indication
(Component_Definition
(N
)));
2206 ("unconstrained subtype in component declaration",
2207 Subtype_Indication
(Component_Definition
(N
)));
2210 -- Components cannot be abstract, except for the special case of
2211 -- the _Parent field (case of extending an abstract tagged type)
2213 elsif Is_Abstract_Type
(T
) and then Chars
(Id
) /= Name_uParent
then
2214 Error_Msg_N
("type of a component cannot be abstract", N
);
2219 if Aliased_Present
(Component_Definition
(N
)) then
2220 Set_Is_Aliased
(Id
);
2222 -- AI12-001: All aliased objects are considered to be specified as
2223 -- independently addressable (RM C.6(8.1/4)).
2225 Set_Is_Independent
(Id
);
2228 -- The component declaration may have a per-object constraint, set
2229 -- the appropriate flag in the defining identifier of the subtype.
2231 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
2233 Sindic
: constant Node_Id
:=
2234 Subtype_Indication
(Component_Definition
(N
));
2236 if Nkind
(Sindic
) = N_Subtype_Indication
2237 and then Present
(Constraint
(Sindic
))
2238 and then Contains_POC
(Constraint
(Sindic
))
2240 Set_Has_Per_Object_Constraint
(Id
);
2245 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2246 -- out some static checks.
2248 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(T
) then
2249 Null_Exclusion_Static_Checks
(N
);
2252 -- If this component is private (or depends on a private type), flag the
2253 -- record type to indicate that some operations are not available.
2255 P
:= Private_Component
(T
);
2259 -- Check for circular definitions
2261 if P
= Any_Type
then
2262 Set_Etype
(Id
, Any_Type
);
2264 -- There is a gap in the visibility of operations only if the
2265 -- component type is not defined in the scope of the record type.
2267 elsif Scope
(P
) = Scope
(Current_Scope
) then
2270 elsif Is_Limited_Type
(P
) then
2271 Set_Is_Limited_Composite
(Current_Scope
);
2274 Set_Is_Private_Composite
(Current_Scope
);
2279 and then Is_Limited_Type
(T
)
2280 and then Chars
(Id
) /= Name_uParent
2281 and then Is_Tagged_Type
(Current_Scope
)
2283 if Is_Derived_Type
(Current_Scope
)
2284 and then not Is_Known_Limited
(Current_Scope
)
2287 ("extension of nonlimited type cannot have limited components",
2290 if Is_Interface
(Root_Type
(Current_Scope
)) then
2292 ("\limitedness is not inherited from limited interface", N
);
2293 Error_Msg_N
("\add LIMITED to type indication", N
);
2296 Explain_Limited_Type
(T
, N
);
2297 Set_Etype
(Id
, Any_Type
);
2298 Set_Is_Limited_Composite
(Current_Scope
, False);
2300 elsif not Is_Derived_Type
(Current_Scope
)
2301 and then not Is_Limited_Record
(Current_Scope
)
2302 and then not Is_Concurrent_Type
(Current_Scope
)
2305 ("nonlimited tagged type cannot have limited components", N
);
2306 Explain_Limited_Type
(T
, N
);
2307 Set_Etype
(Id
, Any_Type
);
2308 Set_Is_Limited_Composite
(Current_Scope
, False);
2312 Set_Original_Record_Component
(Id
, Id
);
2314 Analyze_Aspect_Specifications
(N
, Id
);
2316 Analyze_Dimension
(N
);
2317 end Analyze_Component_Declaration
;
2319 --------------------------
2320 -- Analyze_Declarations --
2321 --------------------------
2323 procedure Analyze_Declarations
(L
: List_Id
) is
2326 procedure Adjust_Decl
;
2327 -- Adjust Decl not to include implicit label declarations, since these
2328 -- have strange Sloc values that result in elaboration check problems.
2329 -- (They have the sloc of the label as found in the source, and that
2330 -- is ahead of the current declarative part).
2332 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
);
2333 -- Create the subprogram bodies which verify the run-time semantics of
2334 -- the pragmas listed below for each elibigle type found in declarative
2335 -- list Decls. The pragmas are:
2337 -- Default_Initial_Condition
2341 -- Context denotes the owner of the declarative list.
2343 procedure Check_Entry_Contracts
;
2344 -- Perform a preanalysis of the pre- and postconditions of an entry
2345 -- declaration. This must be done before full resolution and creation
2346 -- of the parameter block, etc. to catch illegal uses within the
2347 -- contract expression. Full analysis of the expression is done when
2348 -- the contract is processed.
2350 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean;
2351 -- Check if a nested package has entities within it that rely on library
2352 -- level private types where the full view has not been completed for
2353 -- the purposes of checking if it is acceptable to freeze an expression
2354 -- function at the point of declaration.
2356 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
);
2357 -- Determine whether Body_Decl denotes the body of a late controlled
2358 -- primitive (either Initialize, Adjust or Finalize). If this is the
2359 -- case, add a proper spec if the body lacks one. The spec is inserted
2360 -- before Body_Decl and immediately analyzed.
2362 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
);
2363 -- Spec_Id is the entity of a package that may define abstract states,
2364 -- and in the case of a child unit, whose ancestors may define abstract
2365 -- states. If the states have partial visible refinement, remove the
2366 -- partial visibility of each constituent at the end of the package
2367 -- spec and body declarations.
2369 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
);
2370 -- Spec_Id is the entity of a package that may define abstract states.
2371 -- If the states have visible refinement, remove the visibility of each
2372 -- constituent at the end of the package body declaration.
2374 procedure Resolve_Aspects
;
2375 -- Utility to resolve the expressions of aspects at the end of a list of
2376 -- declarations, or before a declaration that freezes previous entities,
2377 -- such as in a subprogram body.
2383 procedure Adjust_Decl
is
2385 while Present
(Prev
(Decl
))
2386 and then Nkind
(Decl
) = N_Implicit_Label_Declaration
2392 ----------------------------
2393 -- Build_Assertion_Bodies --
2394 ----------------------------
2396 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
) is
2397 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
);
2398 -- Create the subprogram bodies which verify the run-time semantics
2399 -- of the pragmas listed below for type Typ. The pragmas are:
2401 -- Default_Initial_Condition
2405 -------------------------------------
2406 -- Build_Assertion_Bodies_For_Type --
2407 -------------------------------------
2409 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
) is
2411 if Nkind
(Context
) = N_Package_Specification
then
2413 -- Preanalyze and resolve the class-wide invariants of an
2414 -- interface at the end of whichever declarative part has the
2415 -- interface type. Note that an interface may be declared in
2416 -- any non-package declarative part, but reaching the end of
2417 -- such a declarative part will always freeze the type and
2418 -- generate the invariant procedure (see Freeze_Type).
2420 if Is_Interface
(Typ
) then
2422 -- Interfaces are treated as the partial view of a private
2423 -- type, in order to achieve uniformity with the general
2424 -- case. As a result, an interface receives only a "partial"
2425 -- invariant procedure, which is never called.
2427 if Has_Own_Invariants
(Typ
) then
2428 Build_Invariant_Procedure_Body
2430 Partial_Invariant
=> True);
2433 elsif Decls
= Visible_Declarations
(Context
) then
2434 -- Preanalyze and resolve the invariants of a private type
2435 -- at the end of the visible declarations to catch potential
2436 -- errors. Inherited class-wide invariants are not included
2437 -- because they have already been resolved.
2439 if Ekind
(Typ
) in E_Limited_Private_Type
2441 | E_Record_Type_With_Private
2442 and then Has_Own_Invariants
(Typ
)
2444 Build_Invariant_Procedure_Body
2446 Partial_Invariant
=> True);
2449 -- Preanalyze and resolve the Default_Initial_Condition
2450 -- assertion expression at the end of the declarations to
2451 -- catch any errors.
2453 if Ekind
(Typ
) in E_Limited_Private_Type
2455 | E_Record_Type_With_Private
2456 and then Has_Own_DIC
(Typ
)
2458 Build_DIC_Procedure_Body
2460 Partial_DIC
=> True);
2463 elsif Decls
= Private_Declarations
(Context
) then
2465 -- Preanalyze and resolve the invariants of a private type's
2466 -- full view at the end of the private declarations to catch
2467 -- potential errors.
2469 if (not Is_Private_Type
(Typ
)
2470 or else Present
(Underlying_Full_View
(Typ
)))
2471 and then Has_Private_Declaration
(Typ
)
2472 and then Has_Invariants
(Typ
)
2474 Build_Invariant_Procedure_Body
(Typ
);
2477 if (not Is_Private_Type
(Typ
)
2478 or else Present
(Underlying_Full_View
(Typ
)))
2479 and then Has_Private_Declaration
(Typ
)
2480 and then Has_DIC
(Typ
)
2482 Build_DIC_Procedure_Body
(Typ
);
2486 end Build_Assertion_Bodies_For_Type
;
2491 Decl_Id
: Entity_Id
;
2493 -- Start of processing for Build_Assertion_Bodies
2496 Decl
:= First
(Decls
);
2497 while Present
(Decl
) loop
2498 if Is_Declaration
(Decl
) then
2499 Decl_Id
:= Defining_Entity
(Decl
);
2501 if Is_Type
(Decl_Id
) then
2502 Build_Assertion_Bodies_For_Type
(Decl_Id
);
2508 end Build_Assertion_Bodies
;
2510 ---------------------------
2511 -- Check_Entry_Contracts --
2512 ---------------------------
2514 procedure Check_Entry_Contracts
is
2520 Ent
:= First_Entity
(Current_Scope
);
2521 while Present
(Ent
) loop
2523 -- This only concerns entries with pre/postconditions
2525 if Ekind
(Ent
) = E_Entry
2526 and then Present
(Contract
(Ent
))
2527 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
2529 ASN
:= Pre_Post_Conditions
(Contract
(Ent
));
2531 Install_Formals
(Ent
);
2533 -- Pre/postconditions are rewritten as Check pragmas. Analysis
2534 -- is performed on a copy of the pragma expression, to prevent
2535 -- modifying the original expression.
2537 while Present
(ASN
) loop
2538 if Nkind
(ASN
) = N_Pragma
then
2542 (First
(Pragma_Argument_Associations
(ASN
))));
2543 Set_Parent
(Exp
, ASN
);
2545 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
2548 ASN
:= Next_Pragma
(ASN
);
2556 end Check_Entry_Contracts
;
2558 ----------------------------------
2559 -- Contains_Lib_Incomplete_Type --
2560 ----------------------------------
2562 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean is
2566 -- Avoid looking through scopes that do not meet the precondition of
2567 -- Pkg not being within a library unit spec.
2569 if not Is_Compilation_Unit
(Pkg
)
2570 and then not Is_Generic_Instance
(Pkg
)
2571 and then not In_Package_Body
(Enclosing_Lib_Unit_Entity
(Pkg
))
2573 -- Loop through all entities in the current scope to identify
2574 -- an entity that depends on a private type.
2576 Curr
:= First_Entity
(Pkg
);
2578 if Nkind
(Curr
) in N_Entity
2579 and then Depends_On_Private
(Curr
)
2584 exit when Last_Entity
(Current_Scope
) = Curr
;
2590 end Contains_Lib_Incomplete_Type
;
2592 --------------------------------------
2593 -- Handle_Late_Controlled_Primitive --
2594 --------------------------------------
2596 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
) is
2597 Body_Spec
: constant Node_Id
:= Specification
(Body_Decl
);
2598 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2599 Loc
: constant Source_Ptr
:= Sloc
(Body_Id
);
2600 Params
: constant List_Id
:=
2601 Parameter_Specifications
(Body_Spec
);
2603 Spec_Id
: Entity_Id
;
2607 -- Consider only procedure bodies whose name matches one of the three
2608 -- controlled primitives.
2610 if Nkind
(Body_Spec
) /= N_Procedure_Specification
2611 or else Chars
(Body_Id
) not in Name_Adjust
2617 -- A controlled primitive must have exactly one formal which is not
2618 -- an anonymous access type.
2620 elsif List_Length
(Params
) /= 1 then
2624 Typ
:= Parameter_Type
(First
(Params
));
2626 if Nkind
(Typ
) = N_Access_Definition
then
2632 -- The type of the formal must be derived from [Limited_]Controlled
2634 if not Is_Controlled
(Entity
(Typ
)) then
2638 -- Check whether a specification exists for this body. We do not
2639 -- analyze the spec of the body in full, because it will be analyzed
2640 -- again when the body is properly analyzed, and we cannot create
2641 -- duplicate entries in the formals chain. We look for an explicit
2642 -- specification because the body may be an overriding operation and
2643 -- an inherited spec may be present.
2645 Spec_Id
:= Current_Entity
(Body_Id
);
2647 while Present
(Spec_Id
) loop
2648 if Ekind
(Spec_Id
) in E_Procedure | E_Generic_Procedure
2649 and then Scope
(Spec_Id
) = Current_Scope
2650 and then Present
(First_Formal
(Spec_Id
))
2651 and then No
(Next_Formal
(First_Formal
(Spec_Id
)))
2652 and then Etype
(First_Formal
(Spec_Id
)) = Entity
(Typ
)
2653 and then Comes_From_Source
(Spec_Id
)
2658 Spec_Id
:= Homonym
(Spec_Id
);
2661 -- At this point the body is known to be a late controlled primitive.
2662 -- Generate a matching spec and insert it before the body. Note the
2663 -- use of Copy_Separate_Tree - we want an entirely separate semantic
2664 -- tree in this case.
2666 Spec
:= Copy_Separate_Tree
(Body_Spec
);
2668 -- Ensure that the subprogram declaration does not inherit the null
2669 -- indicator from the body as we now have a proper spec/body pair.
2671 Set_Null_Present
(Spec
, False);
2673 -- Ensure that the freeze node is inserted after the declaration of
2674 -- the primitive since its expansion will freeze the primitive.
2676 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
2678 Insert_Before_And_Analyze
(Body_Decl
, Decl
);
2679 end Handle_Late_Controlled_Primitive
;
2681 ----------------------------------------
2682 -- Remove_Partial_Visible_Refinements --
2683 ----------------------------------------
2685 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2686 State_Elmt
: Elmt_Id
;
2688 if Present
(Abstract_States
(Spec_Id
)) then
2689 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2690 while Present
(State_Elmt
) loop
2691 Set_Has_Partial_Visible_Refinement
(Node
(State_Elmt
), False);
2692 Next_Elmt
(State_Elmt
);
2696 -- For a child unit, also hide the partial state refinement from
2697 -- ancestor packages.
2699 if Is_Child_Unit
(Spec_Id
) then
2700 Remove_Partial_Visible_Refinements
(Scope
(Spec_Id
));
2702 end Remove_Partial_Visible_Refinements
;
2704 --------------------------------
2705 -- Remove_Visible_Refinements --
2706 --------------------------------
2708 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2709 State_Elmt
: Elmt_Id
;
2711 if Present
(Abstract_States
(Spec_Id
)) then
2712 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2713 while Present
(State_Elmt
) loop
2714 Set_Has_Visible_Refinement
(Node
(State_Elmt
), False);
2715 Next_Elmt
(State_Elmt
);
2718 end Remove_Visible_Refinements
;
2720 ---------------------
2721 -- Resolve_Aspects --
2722 ---------------------
2724 procedure Resolve_Aspects
is
2728 E
:= First_Entity
(Current_Scope
);
2729 while Present
(E
) loop
2730 Resolve_Aspect_Expressions
(E
);
2732 -- Now that the aspect expressions have been resolved, if this is
2733 -- at the end of the visible declarations, we can set the flag
2734 -- Known_To_Have_Preelab_Init properly on types declared in the
2735 -- visible part, which is needed for checking whether full types
2736 -- in the private part satisfy the Preelaborable_Initialization
2737 -- aspect of the partial view. We can't wait for the creation of
2738 -- the pragma by Analyze_Aspects_At_Freeze_Point, because the
2739 -- freeze point may occur after the end of the package declaration
2740 -- (in the case of nested packages).
2743 and then L
= Visible_Declarations
(Parent
(L
))
2744 and then Has_Aspect
(E
, Aspect_Preelaborable_Initialization
)
2747 ASN
: constant Node_Id
:=
2748 Find_Aspect
(E
, Aspect_Preelaborable_Initialization
);
2749 Expr
: constant Node_Id
:= Expression
(ASN
);
2751 -- Set Known_To_Have_Preelab_Init to True if aspect has no
2752 -- expression, or if the expression is True (or was folded
2753 -- to True), or if the expression is a conjunction of one or
2754 -- more Preelaborable_Initialization attributes applied to
2755 -- formal types and wasn't folded to False. (Note that
2756 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes goes to
2757 -- Original_Node if needed, hence test for Standard_False.)
2760 or else (Is_Entity_Name
(Expr
)
2761 and then Entity
(Expr
) = Standard_True
)
2763 (Is_Conjunction_Of_Formal_Preelab_Init_Attributes
(Expr
)
2765 not (Is_Entity_Name
(Expr
)
2766 and then Entity
(Expr
) = Standard_False
))
2768 Set_Known_To_Have_Preelab_Init
(E
);
2775 end Resolve_Aspects
;
2779 Context
: Node_Id
:= Empty
;
2780 Ctrl_Typ
: Entity_Id
:= Empty
;
2781 Freeze_From
: Entity_Id
:= Empty
;
2782 Next_Decl
: Node_Id
;
2784 -- Start of processing for Analyze_Declarations
2788 while Present
(Decl
) loop
2790 -- Complete analysis of declaration
2793 Next_Decl
:= Next
(Decl
);
2795 if No
(Freeze_From
) then
2796 Freeze_From
:= First_Entity
(Current_Scope
);
2799 -- Remember if the declaration we just processed is the full type
2800 -- declaration of a controlled type (to handle late overriding of
2801 -- initialize, adjust or finalize).
2803 if Nkind
(Decl
) = N_Full_Type_Declaration
2804 and then Is_Controlled
(Defining_Identifier
(Decl
))
2806 Ctrl_Typ
:= Defining_Identifier
(Decl
);
2809 -- At the end of a declarative part, freeze remaining entities
2810 -- declared in it. The end of the visible declarations of package
2811 -- specification is not the end of a declarative part if private
2812 -- declarations are present. The end of a package declaration is a
2813 -- freezing point only if it a library package. A task definition or
2814 -- protected type definition is not a freeze point either. Finally,
2815 -- we do not freeze entities in generic scopes, because there is no
2816 -- code generated for them and freeze nodes will be generated for
2819 -- The end of a package instantiation is not a freeze point, but
2820 -- for now we make it one, because the generic body is inserted
2821 -- (currently) immediately after. Generic instantiations will not
2822 -- be a freeze point once delayed freezing of bodies is implemented.
2823 -- (This is needed in any case for early instantiations ???).
2825 if No
(Next_Decl
) then
2826 if Nkind
(Parent
(L
)) = N_Component_List
then
2829 elsif Nkind
(Parent
(L
)) in
2830 N_Protected_Definition | N_Task_Definition
2832 Check_Entry_Contracts
;
2834 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
2835 if Nkind
(Parent
(L
)) = N_Package_Body
then
2836 Freeze_From
:= First_Entity
(Current_Scope
);
2839 -- There may have been several freezing points previously,
2840 -- for example object declarations or subprogram bodies, but
2841 -- at the end of a declarative part we check freezing from
2842 -- the beginning, even though entities may already be frozen,
2843 -- in order to perform visibility checks on delayed aspects.
2847 -- If the current scope is a generic subprogram body. Skip the
2848 -- generic formal parameters that are not frozen here.
2850 if Is_Subprogram
(Current_Scope
)
2851 and then Nkind
(Unit_Declaration_Node
(Current_Scope
)) =
2852 N_Generic_Subprogram_Declaration
2853 and then Present
(First_Entity
(Current_Scope
))
2855 while Is_Generic_Formal
(Freeze_From
) loop
2856 Next_Entity
(Freeze_From
);
2859 Freeze_All
(Freeze_From
, Decl
);
2860 Freeze_From
:= Last_Entity
(Current_Scope
);
2863 -- For declarations in a subprogram body there is no issue
2864 -- with name resolution in aspect specifications.
2866 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2867 Freeze_From
:= Last_Entity
(Current_Scope
);
2870 -- Current scope is a package specification
2872 elsif Scope
(Current_Scope
) /= Standard_Standard
2873 and then not Is_Child_Unit
(Current_Scope
)
2874 and then No
(Generic_Parent
(Parent
(L
)))
2876 -- ARM rule 13.1.1(11/3): usage names in aspect definitions are
2877 -- resolved at the end of the immediately enclosing declaration
2878 -- list (AI05-0183-1).
2882 elsif L
/= Visible_Declarations
(Parent
(L
))
2883 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
2887 -- End of a package declaration
2889 -- This is a freeze point because it is the end of a
2890 -- compilation unit.
2892 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2893 Freeze_From
:= Last_Entity
(Current_Scope
);
2895 -- At the end of the visible declarations the expressions in
2896 -- aspects of all entities declared so far must be resolved.
2897 -- The entities themselves might be frozen later, and the
2898 -- generated pragmas and attribute definition clauses analyzed
2899 -- in full at that point, but name resolution must take place
2901 -- In addition to being the proper semantics, this is mandatory
2902 -- within generic units, because global name capture requires
2903 -- those expressions to be analyzed, given that the generated
2904 -- pragmas do not appear in the original generic tree.
2906 elsif Serious_Errors_Detected
= 0 then
2910 -- If next node is a body then freeze all types before the body.
2911 -- An exception occurs for some expander-generated bodies. If these
2912 -- are generated at places where in general language rules would not
2913 -- allow a freeze point, then we assume that the expander has
2914 -- explicitly checked that all required types are properly frozen,
2915 -- and we do not cause general freezing here. This special circuit
2916 -- is used when the encountered body is marked as having already
2919 -- In all other cases (bodies that come from source, and expander
2920 -- generated bodies that have not been analyzed yet), freeze all
2921 -- types now. Note that in the latter case, the expander must take
2922 -- care to attach the bodies at a proper place in the tree so as to
2923 -- not cause unwanted freezing at that point.
2925 -- It is also necessary to check for a case where both an expression
2926 -- function is used and the current scope depends on an incomplete
2927 -- private type from a library unit, otherwise premature freezing of
2928 -- the private type will occur.
2930 elsif not Analyzed
(Next_Decl
) and then Is_Body
(Next_Decl
)
2931 and then ((Nkind
(Next_Decl
) /= N_Subprogram_Body
2932 or else not Was_Expression_Function
(Next_Decl
))
2933 or else (not Is_Ignored_Ghost_Entity
(Current_Scope
)
2934 and then not Contains_Lib_Incomplete_Type
2937 -- When a controlled type is frozen, the expander generates stream
2938 -- and controlled-type support routines. If the freeze is caused
2939 -- by the stand-alone body of Initialize, Adjust, or Finalize, the
2940 -- expander will end up using the wrong version of these routines,
2941 -- as the body has not been processed yet. To remedy this, detect
2942 -- a late controlled primitive and create a proper spec for it.
2943 -- This ensures that the primitive will override its inherited
2944 -- counterpart before the freeze takes place.
2946 -- If the declaration we just processed is a body, do not attempt
2947 -- to examine Next_Decl as the late primitive idiom can only apply
2948 -- to the first encountered body.
2950 -- ??? A cleaner approach may be possible and/or this solution
2951 -- could be extended to general-purpose late primitives.
2953 if Present
(Ctrl_Typ
) then
2955 -- No need to continue searching for late body overriding if
2956 -- the controlled type is already frozen.
2958 if Is_Frozen
(Ctrl_Typ
) then
2961 elsif Nkind
(Next_Decl
) = N_Subprogram_Body
then
2962 Handle_Late_Controlled_Primitive
(Next_Decl
);
2968 -- The generated body of an expression function does not freeze,
2969 -- unless it is a completion, in which case only the expression
2970 -- itself freezes. This is handled when the body itself is
2971 -- analyzed (see Freeze_Expr_Types, sem_ch6.adb).
2973 Freeze_All
(Freeze_From
, Decl
);
2974 Freeze_From
:= Last_Entity
(Current_Scope
);
2980 -- Post-freezing actions
2983 Context
:= Parent
(L
);
2985 -- Certain contract annotations have forward visibility semantics and
2986 -- must be analyzed after all declarative items have been processed.
2987 -- This timing ensures that entities referenced by such contracts are
2990 -- Analyze the contract of an immediately enclosing package spec or
2991 -- body first because other contracts may depend on its information.
2993 if Nkind
(Context
) = N_Package_Body
then
2994 Analyze_Package_Body_Contract
(Defining_Entity
(Context
));
2996 elsif Nkind
(Context
) = N_Package_Specification
then
2997 Analyze_Package_Contract
(Defining_Entity
(Context
));
3000 -- Analyze the contracts of various constructs in the declarative
3003 Analyze_Contracts
(L
);
3005 if Nkind
(Context
) = N_Package_Body
then
3007 -- Ensure that all abstract states and objects declared in the
3008 -- state space of a package body are utilized as constituents.
3010 Check_Unused_Body_States
(Defining_Entity
(Context
));
3012 -- State refinements are visible up to the end of the package body
3013 -- declarations. Hide the state refinements from visibility to
3014 -- restore the original state conditions.
3016 Remove_Visible_Refinements
(Corresponding_Spec
(Context
));
3017 Remove_Partial_Visible_Refinements
(Corresponding_Spec
(Context
));
3019 elsif Nkind
(Context
) = N_Package_Specification
then
3021 -- Partial state refinements are visible up to the end of the
3022 -- package spec declarations. Hide the partial state refinements
3023 -- from visibility to restore the original state conditions.
3025 Remove_Partial_Visible_Refinements
(Defining_Entity
(Context
));
3028 -- Verify that all abstract states found in any package declared in
3029 -- the input declarative list have proper refinements. The check is
3030 -- performed only when the context denotes a block, entry, package,
3031 -- protected, subprogram, or task body (SPARK RM 7.1.4(4) and SPARK
3034 Check_State_Refinements
(Context
);
3036 -- Create the subprogram bodies which verify the run-time semantics
3037 -- of pragmas Default_Initial_Condition and [Type_]Invariant for all
3038 -- types within the current declarative list. This ensures that all
3039 -- assertion expressions are preanalyzed and resolved at the end of
3040 -- the declarative part. Note that the resolution happens even when
3041 -- freezing does not take place.
3043 Build_Assertion_Bodies
(L
, Context
);
3045 end Analyze_Declarations
;
3047 -----------------------------------
3048 -- Analyze_Full_Type_Declaration --
3049 -----------------------------------
3051 procedure Analyze_Full_Type_Declaration
(N
: Node_Id
) is
3052 Def
: constant Node_Id
:= Type_Definition
(N
);
3053 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3057 Is_Remote
: constant Boolean :=
3058 (Is_Remote_Types
(Current_Scope
)
3059 or else Is_Remote_Call_Interface
(Current_Scope
))
3060 and then not (In_Private_Part
(Current_Scope
)
3061 or else In_Package_Body
(Current_Scope
));
3063 procedure Check_Nonoverridable_Aspects
;
3064 -- Apply the rule in RM 13.1.1(18.4/4) on iterator aspects that cannot
3065 -- be overridden, and can only be confirmed on derivation.
3067 procedure Check_Ops_From_Incomplete_Type
;
3068 -- If there is a tagged incomplete partial view of the type, traverse
3069 -- the primitives of the incomplete view and change the type of any
3070 -- controlling formals and result to indicate the full view. The
3071 -- primitives will be added to the full type's primitive operations
3072 -- list later in Sem_Disp.Check_Operation_From_Incomplete_Type (which
3073 -- is called from Process_Incomplete_Dependents).
3075 ----------------------------------
3076 -- Check_Nonoverridable_Aspects --
3077 ----------------------------------
3079 procedure Check_Nonoverridable_Aspects
is
3080 function Get_Aspect_Spec
3082 Aspect_Name
: Name_Id
) return Node_Id
;
3083 -- Check whether a list of aspect specifications includes an entry
3084 -- for a specific aspect. The list is either that of a partial or
3087 ---------------------
3088 -- Get_Aspect_Spec --
3089 ---------------------
3091 function Get_Aspect_Spec
3093 Aspect_Name
: Name_Id
) return Node_Id
3098 Spec
:= First
(Specs
);
3099 while Present
(Spec
) loop
3100 if Chars
(Identifier
(Spec
)) = Aspect_Name
then
3107 end Get_Aspect_Spec
;
3111 Prev_Aspects
: constant List_Id
:=
3112 Aspect_Specifications
(Parent
(Def_Id
));
3113 Par_Type
: Entity_Id
;
3114 Prev_Aspect
: Node_Id
;
3116 -- Start of processing for Check_Nonoverridable_Aspects
3119 -- Get parent type of derived type. Note that Prev is the entity in
3120 -- the partial declaration, but its contents are now those of full
3121 -- view, while Def_Id reflects the partial view.
3123 if Is_Private_Type
(Def_Id
) then
3124 Par_Type
:= Etype
(Full_View
(Def_Id
));
3126 Par_Type
:= Etype
(Def_Id
);
3129 -- If there is an inherited Implicit_Dereference, verify that it is
3130 -- made explicit in the partial view.
3132 if Has_Discriminants
(Base_Type
(Par_Type
))
3133 and then Nkind
(Parent
(Prev
)) = N_Full_Type_Declaration
3134 and then Present
(Discriminant_Specifications
(Parent
(Prev
)))
3135 and then Present
(Get_Reference_Discriminant
(Par_Type
))
3138 Get_Aspect_Spec
(Prev_Aspects
, Name_Implicit_Dereference
);
3142 (Discriminant_Specifications
3143 (Original_Node
(Parent
(Prev
))))
3146 ("type does not inherit implicit dereference", Prev
);
3149 -- If one of the views has the aspect specified, verify that it
3150 -- is consistent with that of the parent.
3153 Cur_Discr
: constant Entity_Id
:=
3154 Get_Reference_Discriminant
(Prev
);
3155 Par_Discr
: constant Entity_Id
:=
3156 Get_Reference_Discriminant
(Par_Type
);
3159 if Corresponding_Discriminant
(Cur_Discr
) /= Par_Discr
then
3161 ("aspect inconsistent with that of parent", N
);
3164 -- Check that specification in partial view matches the
3165 -- inherited aspect. Compare names directly because aspect
3166 -- expression may not be analyzed.
3168 if Present
(Prev_Aspect
)
3169 and then Nkind
(Expression
(Prev_Aspect
)) = N_Identifier
3170 and then Chars
(Expression
(Prev_Aspect
)) /=
3174 ("aspect inconsistent with that of parent", N
);
3180 -- What about other nonoverridable aspects???
3181 end Check_Nonoverridable_Aspects
;
3183 ------------------------------------
3184 -- Check_Ops_From_Incomplete_Type --
3185 ------------------------------------
3187 procedure Check_Ops_From_Incomplete_Type
is
3194 and then Ekind
(Prev
) = E_Incomplete_Type
3195 and then Is_Tagged_Type
(Prev
)
3196 and then Is_Tagged_Type
(T
)
3197 and then Present
(Primitive_Operations
(Prev
))
3199 Elmt
:= First_Elmt
(Primitive_Operations
(Prev
));
3200 while Present
(Elmt
) loop
3203 Formal
:= First_Formal
(Op
);
3204 while Present
(Formal
) loop
3205 if Etype
(Formal
) = Prev
then
3206 Set_Etype
(Formal
, T
);
3209 Next_Formal
(Formal
);
3212 if Etype
(Op
) = Prev
then
3219 end Check_Ops_From_Incomplete_Type
;
3221 -- Start of processing for Analyze_Full_Type_Declaration
3224 Prev
:= Find_Type_Name
(N
);
3226 -- The full view, if present, now points to the current type. If there
3227 -- is an incomplete partial view, set a link to it, to simplify the
3228 -- retrieval of primitive operations of the type.
3230 -- Ada 2005 (AI-50217): If the type was previously decorated when
3231 -- imported through a LIMITED WITH clause, it appears as incomplete
3232 -- but has no full view.
3234 if Ekind
(Prev
) = E_Incomplete_Type
3235 and then Present
(Full_View
(Prev
))
3237 T
:= Full_View
(Prev
);
3238 Set_Incomplete_View
(N
, Prev
);
3243 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
3245 -- We set the flag Is_First_Subtype here. It is needed to set the
3246 -- corresponding flag for the Implicit class-wide-type created
3247 -- during tagged types processing.
3249 Set_Is_First_Subtype
(T
, True);
3251 -- Only composite types other than array types are allowed to have
3256 -- For derived types, the rule will be checked once we've figured
3257 -- out the parent type.
3259 when N_Derived_Type_Definition
=>
3262 -- For record types, discriminants are allowed.
3264 when N_Record_Definition
=>
3268 if Present
(Discriminant_Specifications
(N
)) then
3270 ("elementary or array type cannot have discriminants",
3272 (First
(Discriminant_Specifications
(N
))));
3276 -- Elaborate the type definition according to kind, and generate
3277 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3278 -- already done (this happens during the reanalysis that follows a call
3279 -- to the high level optimizer).
3281 if not Analyzed
(T
) then
3284 -- Set the SPARK mode from the current context
3286 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3287 Set_SPARK_Pragma_Inherited
(T
);
3290 when N_Access_To_Subprogram_Definition
=>
3291 Access_Subprogram_Declaration
(T
, Def
);
3293 -- If this is a remote access to subprogram, we must create the
3294 -- equivalent fat pointer type, and related subprograms.
3297 Process_Remote_AST_Declaration
(N
);
3300 -- Validate categorization rule against access type declaration
3301 -- usually a violation in Pure unit, Shared_Passive unit.
3303 Validate_Access_Type_Declaration
(T
, N
);
3305 -- If the type has contracts, we create the corresponding
3306 -- wrapper at once, before analyzing the aspect specifications,
3307 -- so that pre/postconditions can be handled directly on the
3308 -- generated wrapper.
3310 if Ada_Version
>= Ada_2022
3311 and then Present
(Aspect_Specifications
(N
))
3312 and then Expander_Active
3314 Build_Access_Subprogram_Wrapper
(N
);
3317 when N_Access_To_Object_Definition
=>
3318 Access_Type_Declaration
(T
, Def
);
3320 -- Validate categorization rule against access type declaration
3321 -- usually a violation in Pure unit, Shared_Passive unit.
3323 Validate_Access_Type_Declaration
(T
, N
);
3325 -- If we are in a Remote_Call_Interface package and define a
3326 -- RACW, then calling stubs and specific stream attributes
3330 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
3332 Add_RACW_Features
(Def_Id
);
3335 when N_Array_Type_Definition
=>
3336 Array_Type_Declaration
(T
, Def
);
3338 when N_Derived_Type_Definition
=>
3339 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
3341 -- Save the scenario for examination by the ABE Processing
3344 Record_Elaboration_Scenario
(N
);
3346 when N_Enumeration_Type_Definition
=>
3347 Enumeration_Type_Declaration
(T
, Def
);
3349 when N_Floating_Point_Definition
=>
3350 Floating_Point_Type_Declaration
(T
, Def
);
3352 when N_Decimal_Fixed_Point_Definition
=>
3353 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
3355 when N_Ordinary_Fixed_Point_Definition
=>
3356 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
3358 when N_Signed_Integer_Type_Definition
=>
3359 Signed_Integer_Type_Declaration
(T
, Def
);
3361 when N_Modular_Type_Definition
=>
3362 Modular_Type_Declaration
(T
, Def
);
3364 when N_Record_Definition
=>
3365 Record_Type_Declaration
(T
, N
, Prev
);
3367 -- If declaration has a parse error, nothing to elaborate.
3373 raise Program_Error
;
3377 if Etype
(T
) = Any_Type
then
3381 -- Set the primitives list of the full type and its base type when
3382 -- needed. T may be E_Void in cases of earlier errors, and in that
3383 -- case we bypass this.
3385 if Ekind
(T
) /= E_Void
then
3386 if No
(Direct_Primitive_Operations
(T
)) then
3387 if Etype
(T
) = T
then
3388 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3390 -- If Etype of T is the base type (as opposed to a parent type)
3391 -- and already has an associated list of primitive operations,
3392 -- then set T's primitive list to the base type's list. Otherwise,
3393 -- create a new empty primitives list and share the list between
3394 -- T and its base type. The lists need to be shared in common.
3396 elsif Etype
(T
) = Base_Type
(T
) then
3398 if No
(Direct_Primitive_Operations
(Base_Type
(T
))) then
3399 Set_Direct_Primitive_Operations
3400 (Base_Type
(T
), New_Elmt_List
);
3403 Set_Direct_Primitive_Operations
3404 (T
, Direct_Primitive_Operations
(Base_Type
(T
)));
3406 -- Case where the Etype is a parent type, so we need a new
3407 -- primitives list for T.
3410 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3413 -- If T already has a Direct_Primitive_Operations list but its
3414 -- base type doesn't then set the base type's list to T's list.
3416 elsif No
(Direct_Primitive_Operations
(Base_Type
(T
))) then
3417 Set_Direct_Primitive_Operations
3418 (Base_Type
(T
), Direct_Primitive_Operations
(T
));
3422 -- Some common processing for all types
3424 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
3425 Check_Ops_From_Incomplete_Type
;
3427 -- Both the declared entity, and its anonymous base type if one was
3428 -- created, need freeze nodes allocated.
3431 B
: constant Entity_Id
:= Base_Type
(T
);
3434 -- In the case where the base type differs from the first subtype, we
3435 -- pre-allocate a freeze node, and set the proper link to the first
3436 -- subtype. Freeze_Entity will use this preallocated freeze node when
3437 -- it freezes the entity.
3439 -- This does not apply if the base type is a generic type, whose
3440 -- declaration is independent of the current derived definition.
3442 if B
/= T
and then not Is_Generic_Type
(B
) then
3443 Ensure_Freeze_Node
(B
);
3444 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
3447 -- A type that is imported through a limited_with clause cannot
3448 -- generate any code, and thus need not be frozen. However, an access
3449 -- type with an imported designated type needs a finalization list,
3450 -- which may be referenced in some other package that has non-limited
3451 -- visibility on the designated type. Thus we must create the
3452 -- finalization list at the point the access type is frozen, to
3453 -- prevent unsatisfied references at link time.
3455 if not From_Limited_With
(T
) or else Is_Access_Type
(T
) then
3456 Set_Has_Delayed_Freeze
(T
);
3460 -- Case where T is the full declaration of some private type which has
3461 -- been swapped in Defining_Identifier (N).
3463 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
3464 Process_Full_View
(N
, T
, Def_Id
);
3466 -- Record the reference. The form of this is a little strange, since
3467 -- the full declaration has been swapped in. So the first parameter
3468 -- here represents the entity to which a reference is made which is
3469 -- the "real" entity, i.e. the one swapped in, and the second
3470 -- parameter provides the reference location.
3472 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3473 -- since we don't want a complaint about the full type being an
3474 -- unwanted reference to the private type
3477 B
: constant Boolean := Has_Pragma_Unreferenced
(T
);
3479 Set_Has_Pragma_Unreferenced
(T
, False);
3480 Generate_Reference
(T
, T
, 'c');
3481 Set_Has_Pragma_Unreferenced
(T
, B
);
3484 Set_Completion_Referenced
(Def_Id
);
3486 -- For completion of incomplete type, process incomplete dependents
3487 -- and always mark the full type as referenced (it is the incomplete
3488 -- type that we get for any real reference).
3490 elsif Ekind
(Prev
) = E_Incomplete_Type
then
3491 Process_Incomplete_Dependents
(N
, T
, Prev
);
3492 Generate_Reference
(Prev
, Def_Id
, 'c');
3493 Set_Completion_Referenced
(Def_Id
);
3495 -- If not private type or incomplete type completion, this is a real
3496 -- definition of a new entity, so record it.
3499 Generate_Definition
(Def_Id
);
3502 -- Propagate any pending access types whose finalization masters need to
3503 -- be fully initialized from the partial to the full view. Guard against
3504 -- an illegal full view that remains unanalyzed.
3506 if Is_Type
(Def_Id
) and then Is_Incomplete_Or_Private_Type
(Prev
) then
3507 Set_Pending_Access_Types
(Def_Id
, Pending_Access_Types
(Prev
));
3510 if Chars
(Scope
(Def_Id
)) = Name_System
3511 and then Chars
(Def_Id
) = Name_Address
3512 and then In_Predefined_Unit
(N
)
3514 Set_Is_Descendant_Of_Address
(Def_Id
);
3515 Set_Is_Descendant_Of_Address
(Base_Type
(Def_Id
));
3516 Set_Is_Descendant_Of_Address
(Prev
);
3519 Set_Optimize_Alignment_Flags
(Def_Id
);
3520 Check_Eliminated
(Def_Id
);
3522 -- If the declaration is a completion and aspects are present, apply
3523 -- them to the entity for the type which is currently the partial
3524 -- view, but which is the one that will be frozen.
3526 -- In most cases the partial view is a private type, and both views
3527 -- appear in different declarative parts. In the unusual case where
3528 -- the partial view is incomplete, perform the analysis on the
3529 -- full view, to prevent freezing anomalies with the corresponding
3530 -- class-wide type, which otherwise might be frozen before the
3531 -- dispatch table is built.
3534 and then Ekind
(Prev
) /= E_Incomplete_Type
3536 Analyze_Aspect_Specifications
(N
, Prev
);
3541 Analyze_Aspect_Specifications
(N
, Def_Id
);
3544 if Is_Derived_Type
(Prev
)
3545 and then Def_Id
/= Prev
3547 Check_Nonoverridable_Aspects
;
3550 -- Check for tagged type declaration at library level
3552 if Is_Tagged_Type
(T
)
3553 and then not Is_Library_Level_Entity
(T
)
3555 Check_Restriction
(No_Local_Tagged_Types
, T
);
3557 end Analyze_Full_Type_Declaration
;
3559 ----------------------------------
3560 -- Analyze_Incomplete_Type_Decl --
3561 ----------------------------------
3563 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
3564 F
: constant Boolean := Is_Pure
(Current_Scope
);
3568 Generate_Definition
(Defining_Identifier
(N
));
3570 -- Process an incomplete declaration. The identifier must not have been
3571 -- declared already in the scope. However, an incomplete declaration may
3572 -- appear in the private part of a package, for a private type that has
3573 -- already been declared.
3575 -- In this case, the discriminants (if any) must match
3577 T
:= Find_Type_Name
(N
);
3579 Mutate_Ekind
(T
, E_Incomplete_Type
);
3581 Set_Is_First_Subtype
(T
);
3582 Reinit_Size_Align
(T
);
3584 -- Set the SPARK mode from the current context
3586 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3587 Set_SPARK_Pragma_Inherited
(T
);
3589 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
3590 -- incomplete types.
3592 if Tagged_Present
(N
) then
3593 Set_Is_Tagged_Type
(T
, True);
3594 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3595 Make_Class_Wide_Type
(T
);
3598 -- Initialize the list of primitive operations to an empty list,
3599 -- to cover tagged types as well as untagged types. For untagged
3600 -- types this is used either to analyze the call as legal when
3601 -- Core_Extensions_Allowed is True, or to issue a better error message
3604 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3606 Set_Stored_Constraint
(T
, No_Elist
);
3608 if Present
(Discriminant_Specifications
(N
)) then
3610 Process_Discriminants
(N
);
3614 -- If the type has discriminants, nontrivial subtypes may be declared
3615 -- before the full view of the type. The full views of those subtypes
3616 -- will be built after the full view of the type.
3618 Set_Private_Dependents
(T
, New_Elmt_List
);
3620 end Analyze_Incomplete_Type_Decl
;
3622 -----------------------------------
3623 -- Analyze_Interface_Declaration --
3624 -----------------------------------
3626 procedure Analyze_Interface_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
3627 CW
: constant Entity_Id
:= Class_Wide_Type
(T
);
3630 Set_Is_Tagged_Type
(T
);
3631 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3633 Set_Is_Limited_Record
(T
, Limited_Present
(Def
)
3634 or else Task_Present
(Def
)
3635 or else Protected_Present
(Def
)
3636 or else Synchronized_Present
(Def
));
3638 -- Type is abstract if full declaration carries keyword, or if previous
3639 -- partial view did.
3641 Set_Is_Abstract_Type
(T
);
3642 Set_Is_Interface
(T
);
3644 -- Type is a limited interface if it includes the keyword limited, task,
3645 -- protected, or synchronized.
3647 Set_Is_Limited_Interface
3648 (T
, Limited_Present
(Def
)
3649 or else Protected_Present
(Def
)
3650 or else Synchronized_Present
(Def
)
3651 or else Task_Present
(Def
));
3653 Set_Interfaces
(T
, New_Elmt_List
);
3654 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3656 -- Complete the decoration of the class-wide entity if it was already
3657 -- built (i.e. during the creation of the limited view)
3659 if Present
(CW
) then
3660 Set_Is_Interface
(CW
);
3661 Set_Is_Limited_Interface
(CW
, Is_Limited_Interface
(T
));
3664 -- Check runtime support for synchronized interfaces
3666 if Is_Concurrent_Interface
(T
)
3667 and then not RTE_Available
(RE_Select_Specific_Data
)
3669 Error_Msg_CRT
("synchronized interfaces", T
);
3671 end Analyze_Interface_Declaration
;
3673 -----------------------------
3674 -- Analyze_Itype_Reference --
3675 -----------------------------
3677 -- Nothing to do. This node is placed in the tree only for the benefit of
3678 -- back end processing, and has no effect on the semantic processing.
3680 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
3682 pragma Assert
(Is_Itype
(Itype
(N
)));
3684 end Analyze_Itype_Reference
;
3686 --------------------------------
3687 -- Analyze_Number_Declaration --
3688 --------------------------------
3690 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
3691 E
: constant Node_Id
:= Expression
(N
);
3692 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3693 Index
: Interp_Index
;
3698 Generate_Definition
(Id
);
3701 -- This is an optimization of a common case of an integer literal
3703 if Nkind
(E
) = N_Integer_Literal
then
3704 Set_Is_Static_Expression
(E
, True);
3705 Set_Etype
(E
, Universal_Integer
);
3707 Set_Etype
(Id
, Universal_Integer
);
3708 Mutate_Ekind
(Id
, E_Named_Integer
);
3709 Set_Is_Frozen
(Id
, True);
3711 Set_Debug_Info_Needed
(Id
);
3715 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3717 -- Process expression, replacing error by integer zero, to avoid
3718 -- cascaded errors or aborts further along in the processing
3720 -- Replace Error by integer zero, which seems least likely to cause
3724 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), Uint_0
));
3725 Set_Error_Posted
(E
);
3730 -- Verify that the expression is static and numeric. If
3731 -- the expression is overloaded, we apply the preference
3732 -- rule that favors root numeric types.
3734 if not Is_Overloaded
(E
) then
3736 if Has_Dynamic_Predicate_Aspect
(T
)
3737 or else Has_Ghost_Predicate_Aspect
(T
)
3740 ("subtype has non-static predicate, "
3741 & "not allowed in number declaration", N
);
3747 Get_First_Interp
(E
, Index
, It
);
3748 while Present
(It
.Typ
) loop
3749 if (Is_Integer_Type
(It
.Typ
) or else Is_Real_Type
(It
.Typ
))
3750 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
3752 if T
= Any_Type
then
3755 elsif Is_Universal_Numeric_Type
(It
.Typ
) then
3756 -- Choose universal interpretation over any other
3763 Get_Next_Interp
(Index
, It
);
3767 if Is_Integer_Type
(T
) then
3769 Set_Etype
(Id
, Universal_Integer
);
3770 Mutate_Ekind
(Id
, E_Named_Integer
);
3772 elsif Is_Real_Type
(T
) then
3774 -- Because the real value is converted to universal_real, this is a
3775 -- legal context for a universal fixed expression.
3777 if T
= Universal_Fixed
then
3779 Loc
: constant Source_Ptr
:= Sloc
(N
);
3780 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3782 New_Occurrence_Of
(Universal_Real
, Loc
),
3783 Expression
=> Relocate_Node
(E
));
3790 elsif T
= Any_Fixed
then
3791 Error_Msg_N
("illegal context for mixed mode operation", E
);
3793 -- Expression is of the form : universal_fixed * integer. Try to
3794 -- resolve as universal_real.
3796 T
:= Universal_Real
;
3801 Set_Etype
(Id
, Universal_Real
);
3802 Mutate_Ekind
(Id
, E_Named_Real
);
3805 Wrong_Type
(E
, Any_Numeric
);
3809 Mutate_Ekind
(Id
, E_Constant
);
3810 Set_Never_Set_In_Source
(Id
, True);
3811 Set_Is_True_Constant
(Id
, True);
3815 if Nkind
(E
) in N_Integer_Literal | N_Real_Literal
then
3816 Set_Etype
(E
, Etype
(Id
));
3819 if not Is_OK_Static_Expression
(E
) then
3820 Flag_Non_Static_Expr
3821 ("non-static expression used in number declaration!", E
);
3822 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
3823 Set_Etype
(E
, Any_Type
);
3826 Analyze_Dimension
(N
);
3827 end Analyze_Number_Declaration
;
3829 --------------------------------
3830 -- Analyze_Object_Declaration --
3831 --------------------------------
3833 -- WARNING: This routine manages Ghost regions. Return statements must be
3834 -- replaced by gotos which jump to the end of the routine and restore the
3837 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
3838 Loc
: constant Source_Ptr
:= Sloc
(N
);
3839 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3840 Next_Decl
: constant Node_Id
:= Next
(N
);
3845 E
: Node_Id
:= Expression
(N
);
3846 -- E is set to Expression (N) throughout this routine. When Expression
3847 -- (N) is modified, E is changed accordingly.
3849 procedure Check_Dynamic_Object
(Typ
: Entity_Id
);
3850 -- A library-level object with nonstatic discriminant constraints may
3851 -- require dynamic allocation. The declaration is illegal if the
3852 -- profile includes the restriction No_Implicit_Heap_Allocations.
3854 procedure Check_For_Null_Excluding_Components
3855 (Obj_Typ
: Entity_Id
;
3856 Obj_Decl
: Node_Id
);
3857 -- Verify that each null-excluding component of object declaration
3858 -- Obj_Decl carrying type Obj_Typ has explicit initialization. Emit
3859 -- a compile-time warning if this is not the case.
3861 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
3862 -- Check that the return subtype indication properly matches the result
3863 -- subtype of the function in an extended return object declaration, as
3864 -- required by RM 6.5(5.1/2-5.3/2).
3866 function Count_Tasks
(T
: Entity_Id
) return Uint
;
3867 -- This function is called when a non-generic library level object of a
3868 -- task type is declared. Its function is to count the static number of
3869 -- tasks declared within the type (it is only called if Has_Task is set
3870 -- for T). As a side effect, if an array of tasks with nonstatic bounds
3871 -- or a variant record type is encountered, Check_Restriction is called
3872 -- indicating the count is unknown.
3874 function Delayed_Aspect_Present
return Boolean;
3875 -- If the declaration has an expression that is an aggregate, and it
3876 -- has aspects that require delayed analysis, the resolution of the
3877 -- aggregate must be deferred to the freeze point of the object. This
3878 -- special processing was created for address clauses, but it must
3879 -- also apply to address aspects. This must be done before the aspect
3880 -- specifications are analyzed because we must handle the aggregate
3881 -- before the analysis of the object declaration is complete.
3883 -- Any other relevant delayed aspects on object declarations ???
3885 --------------------------
3886 -- Check_Dynamic_Object --
3887 --------------------------
3889 procedure Check_Dynamic_Object
(Typ
: Entity_Id
) is
3891 Obj_Type
: Entity_Id
;
3896 if Is_Private_Type
(Obj_Type
)
3897 and then Present
(Full_View
(Obj_Type
))
3899 Obj_Type
:= Full_View
(Obj_Type
);
3902 if Known_Static_Esize
(Obj_Type
) then
3906 if Restriction_Active
(No_Implicit_Heap_Allocations
)
3907 and then Expander_Active
3908 and then Has_Discriminants
(Obj_Type
)
3910 Comp
:= First_Component
(Obj_Type
);
3911 while Present
(Comp
) loop
3912 if Known_Static_Esize
(Etype
(Comp
))
3913 or else Size_Known_At_Compile_Time
(Etype
(Comp
))
3917 elsif Is_Record_Type
(Etype
(Comp
)) then
3918 Check_Dynamic_Object
(Etype
(Comp
));
3920 elsif not Discriminated_Size
(Comp
)
3921 and then Comes_From_Source
(Comp
)
3924 ("component& of non-static size will violate restriction "
3925 & "No_Implicit_Heap_Allocation?", N
, Comp
);
3929 Next_Component
(Comp
);
3932 end Check_Dynamic_Object
;
3934 -----------------------------------------
3935 -- Check_For_Null_Excluding_Components --
3936 -----------------------------------------
3938 procedure Check_For_Null_Excluding_Components
3939 (Obj_Typ
: Entity_Id
;
3942 procedure Check_Component
3943 (Comp_Typ
: Entity_Id
;
3944 Comp_Decl
: Node_Id
:= Empty
;
3945 Array_Comp
: Boolean := False);
3946 -- Apply a compile-time null-exclusion check on a component denoted
3947 -- by its declaration Comp_Decl and type Comp_Typ, and all of its
3948 -- subcomponents (if any).
3950 ---------------------
3951 -- Check_Component --
3952 ---------------------
3954 procedure Check_Component
3955 (Comp_Typ
: Entity_Id
;
3956 Comp_Decl
: Node_Id
:= Empty
;
3957 Array_Comp
: Boolean := False)
3963 -- Do not consider internally-generated components or those that
3964 -- are already initialized.
3966 if Present
(Comp_Decl
)
3967 and then (not Comes_From_Source
(Comp_Decl
)
3968 or else Present
(Expression
(Comp_Decl
)))
3973 if Is_Incomplete_Or_Private_Type
(Comp_Typ
)
3974 and then Present
(Full_View
(Comp_Typ
))
3976 T
:= Full_View
(Comp_Typ
);
3981 -- Verify a component of a null-excluding access type
3983 if Is_Access_Type
(T
)
3984 and then Can_Never_Be_Null
(T
)
3986 if Comp_Decl
= Obj_Decl
then
3987 Null_Exclusion_Static_Checks
3990 Array_Comp
=> Array_Comp
);
3993 Null_Exclusion_Static_Checks
3996 Array_Comp
=> Array_Comp
);
3999 -- Check array components
4001 elsif Is_Array_Type
(T
) then
4003 -- There is no suitable component when the object is of an
4004 -- array type. However, a namable component may appear at some
4005 -- point during the recursive inspection, but not at the top
4006 -- level. At the top level just indicate array component case.
4008 if Comp_Decl
= Obj_Decl
then
4009 Check_Component
(Component_Type
(T
), Array_Comp
=> True);
4011 Check_Component
(Component_Type
(T
), Comp_Decl
);
4014 -- Verify all components of type T
4016 -- Note: No checks are performed on types with discriminants due
4017 -- to complexities involving variants. ???
4019 elsif (Is_Concurrent_Type
(T
)
4020 or else Is_Incomplete_Or_Private_Type
(T
)
4021 or else Is_Record_Type
(T
))
4022 and then not Has_Discriminants
(T
)
4024 Comp
:= First_Component
(T
);
4025 while Present
(Comp
) loop
4026 Check_Component
(Etype
(Comp
), Parent
(Comp
));
4028 Next_Component
(Comp
);
4031 end Check_Component
;
4033 -- Start processing for Check_For_Null_Excluding_Components
4036 Check_Component
(Obj_Typ
, Obj_Decl
);
4037 end Check_For_Null_Excluding_Components
;
4039 -------------------------------------
4040 -- Check_Return_Subtype_Indication --
4041 -------------------------------------
4043 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
4044 Obj_Id
: constant Entity_Id
:= Defining_Identifier
(Obj_Decl
);
4045 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
4046 Func_Id
: constant Entity_Id
:= Return_Applies_To
(Scope
(Obj_Id
));
4047 R_Typ
: constant Entity_Id
:= Etype
(Func_Id
);
4048 Indic
: constant Node_Id
:=
4049 Object_Definition
(Original_Node
(Obj_Decl
));
4051 procedure Error_No_Match
(N
: Node_Id
);
4052 -- Output error messages for case where types do not statically
4053 -- match. N is the location for the messages.
4055 --------------------
4056 -- Error_No_Match --
4057 --------------------
4059 procedure Error_No_Match
(N
: Node_Id
) is
4062 ("subtype must statically match function result subtype", N
);
4064 if not Predicates_Match
(Obj_Typ
, R_Typ
) then
4065 Error_Msg_Node_2
:= R_Typ
;
4067 ("\predicate of& does not match predicate of&",
4072 -- Start of processing for Check_Return_Subtype_Indication
4075 -- First, avoid cascaded errors
4077 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Indic
) then
4081 -- "return access T" case; check that the return statement also has
4082 -- "access T", and that the subtypes statically match:
4083 -- if this is an access to subprogram the signatures must match.
4085 if Is_Anonymous_Access_Type
(R_Typ
) then
4086 if Is_Anonymous_Access_Type
(Obj_Typ
) then
4087 if Ekind
(Designated_Type
(Obj_Typ
)) /= E_Subprogram_Type
4089 if Base_Type
(Designated_Type
(Obj_Typ
)) /=
4090 Base_Type
(Designated_Type
(R_Typ
))
4091 or else not Subtypes_Statically_Match
(Obj_Typ
, R_Typ
)
4093 Error_No_Match
(Subtype_Mark
(Indic
));
4097 -- For two anonymous access to subprogram types, the types
4098 -- themselves must be type conformant.
4100 if not Conforming_Types
4101 (Obj_Typ
, R_Typ
, Fully_Conformant
)
4103 Error_No_Match
(Indic
);
4108 Error_Msg_N
("must use anonymous access type", Indic
);
4111 -- If the return object is of an anonymous access type, then report
4112 -- an error if the function's result type is not also anonymous.
4114 elsif Is_Anonymous_Access_Type
(Obj_Typ
) then
4115 pragma Assert
(not Is_Anonymous_Access_Type
(R_Typ
));
4117 ("anonymous access not allowed for function with named access "
4120 -- Subtype indication case: check that the return object's type is
4121 -- covered by the result type, and that the subtypes statically match
4122 -- when the result subtype is constrained. Also handle record types
4123 -- with unknown discriminants for which we have built the underlying
4124 -- record view. Coverage is needed to allow specific-type return
4125 -- objects when the result type is class-wide (see AI05-32).
4127 elsif Covers
(Base_Type
(R_Typ
), Base_Type
(Obj_Typ
))
4128 or else (Is_Underlying_Record_View
(Base_Type
(Obj_Typ
))
4132 Underlying_Record_View
(Base_Type
(Obj_Typ
))))
4134 -- A null exclusion may be present on the return type, on the
4135 -- function specification, on the object declaration or on the
4138 if Is_Access_Type
(R_Typ
)
4140 (Can_Never_Be_Null
(R_Typ
)
4141 or else Null_Exclusion_Present
(Parent
(Func_Id
))) /=
4142 Can_Never_Be_Null
(Obj_Typ
)
4144 Error_No_Match
(Indic
);
4147 -- AI05-103: for elementary types, subtypes must statically match
4149 if Is_Constrained
(R_Typ
) or else Is_Access_Type
(R_Typ
) then
4150 if not Subtypes_Statically_Match
(Obj_Typ
, R_Typ
) then
4151 Error_No_Match
(Indic
);
4155 -- All remaining cases are illegal
4157 -- Note: previous versions of this subprogram allowed the return
4158 -- value to be the ancestor of the return type if the return type
4159 -- was a null extension. This was plainly incorrect.
4163 ("wrong type for return_subtype_indication", Indic
);
4165 end Check_Return_Subtype_Indication
;
4171 function Count_Tasks
(T
: Entity_Id
) return Uint
is
4177 if Is_Task_Type
(T
) then
4180 elsif Is_Record_Type
(T
) then
4181 if Has_Discriminants
(T
) then
4182 Check_Restriction
(Max_Tasks
, N
);
4187 C
:= First_Component
(T
);
4188 while Present
(C
) loop
4189 V
:= V
+ Count_Tasks
(Etype
(C
));
4196 elsif Is_Array_Type
(T
) then
4197 X
:= First_Index
(T
);
4198 V
:= Count_Tasks
(Component_Type
(T
));
4199 while Present
(X
) loop
4202 if not Is_OK_Static_Subtype
(C
) then
4203 Check_Restriction
(Max_Tasks
, N
);
4206 V
:= V
* (UI_Max
(Uint_0
,
4207 Expr_Value
(Type_High_Bound
(C
)) -
4208 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
4221 ----------------------------
4222 -- Delayed_Aspect_Present --
4223 ----------------------------
4225 function Delayed_Aspect_Present
return Boolean is
4230 if Present
(Aspect_Specifications
(N
)) then
4231 A
:= First
(Aspect_Specifications
(N
));
4233 while Present
(A
) loop
4234 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(A
)));
4236 if A_Id
= Aspect_Address
then
4238 -- Set flag on object entity, for later processing at
4239 -- the freeze point.
4241 Set_Has_Delayed_Aspects
(Id
);
4250 end Delayed_Aspect_Present
;
4254 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4255 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
4256 -- Save the Ghost-related attributes to restore on exit
4258 Prev_Entity
: Entity_Id
:= Empty
;
4259 Related_Id
: Entity_Id
;
4261 -- Start of processing for Analyze_Object_Declaration
4264 -- There are three kinds of implicit types generated by an
4265 -- object declaration:
4267 -- 1. Those generated by the original Object Definition
4269 -- 2. Those generated by the Expression
4271 -- 3. Those used to constrain the Object Definition with the
4272 -- expression constraints when the definition is unconstrained.
4274 -- They must be generated in this order to avoid order of elaboration
4275 -- issues. Thus the first step (after entering the name) is to analyze
4276 -- the object definition.
4278 if Constant_Present
(N
) then
4279 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
4281 if Present
(Prev_Entity
)
4283 -- If the homograph is an implicit subprogram, it is overridden
4284 -- by the current declaration.
4286 ((Is_Overloadable
(Prev_Entity
)
4287 and then Is_Inherited_Operation
(Prev_Entity
))
4289 -- The current object is a discriminal generated for an entry
4290 -- family index. Even though the index is a constant, in this
4291 -- particular context there is no true constant redeclaration.
4292 -- Enter_Name will handle the visibility.
4295 (Is_Discriminal
(Id
)
4296 and then Ekind
(Discriminal_Link
(Id
)) =
4297 E_Entry_Index_Parameter
)
4299 -- The current object is the renaming for a generic declared
4300 -- within the instance.
4303 (Ekind
(Prev_Entity
) = E_Package
4304 and then Nkind
(Parent
(Prev_Entity
)) =
4305 N_Package_Renaming_Declaration
4306 and then not Comes_From_Source
(Prev_Entity
)
4308 Is_Generic_Instance
(Renamed_Entity
(Prev_Entity
)))
4310 -- The entity may be a homonym of a private component of the
4311 -- enclosing protected object, for which we create a local
4312 -- renaming declaration. The declaration is legal, even if
4313 -- useless when it just captures that component.
4316 (Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
4317 and then Nkind
(Parent
(Prev_Entity
)) =
4318 N_Object_Renaming_Declaration
))
4320 Prev_Entity
:= Empty
;
4324 if Present
(Prev_Entity
) then
4326 -- The object declaration is Ghost when it completes a deferred Ghost
4329 Mark_And_Set_Ghost_Completion
(N
, Prev_Entity
);
4331 Constant_Redeclaration
(Id
, N
, T
);
4333 Generate_Reference
(Prev_Entity
, Id
, 'c');
4334 Set_Completion_Referenced
(Id
);
4336 if Error_Posted
(N
) then
4338 -- Type mismatch or illegal redeclaration; do not analyze
4339 -- expression to avoid cascaded errors.
4341 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4343 Mutate_Ekind
(Id
, E_Variable
);
4347 -- In the normal case, enter identifier at the start to catch premature
4348 -- usage in the initialization expression.
4351 Generate_Definition
(Id
);
4354 Mark_Coextensions
(N
, Object_Definition
(N
));
4356 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4358 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
4360 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4361 and then Protected_Present
4362 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4364 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
4367 if Error_Posted
(Id
) then
4369 Mutate_Ekind
(Id
, E_Variable
);
4374 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
4375 -- out some static checks.
4377 if Ada_Version
>= Ada_2005
then
4379 -- In case of aggregates we must also take care of the correct
4380 -- initialization of nested aggregates bug this is done at the
4381 -- point of the analysis of the aggregate (see sem_aggr.adb) ???
4383 if Can_Never_Be_Null
(T
) then
4384 if Present
(Expression
(N
))
4385 and then Nkind
(Expression
(N
)) = N_Aggregate
4389 elsif Comes_From_Source
(Id
) then
4391 Save_Typ
: constant Entity_Id
:= Etype
(Id
);
4393 Set_Etype
(Id
, T
); -- Temp. decoration for static checks
4394 Null_Exclusion_Static_Checks
(N
);
4395 Set_Etype
(Id
, Save_Typ
);
4399 -- We might be dealing with an object of a composite type containing
4400 -- null-excluding components without an aggregate, so we must verify
4401 -- that such components have default initialization.
4404 Check_For_Null_Excluding_Components
(T
, N
);
4408 -- Object is marked pure if it is in a pure scope
4410 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
4412 -- If deferred constant, make sure context is appropriate. We detect
4413 -- a deferred constant as a constant declaration with no expression.
4414 -- A deferred constant can appear in a package body if its completion
4415 -- is by means of an interface pragma.
4417 if Constant_Present
(N
) and then No
(E
) then
4419 -- A deferred constant may appear in the declarative part of the
4420 -- following constructs:
4424 -- extended return statements
4427 -- subprogram bodies
4430 -- When declared inside a package spec, a deferred constant must be
4431 -- completed by a full constant declaration or pragma Import. In all
4432 -- other cases, the only proper completion is pragma Import. Extended
4433 -- return statements are flagged as invalid contexts because they do
4434 -- not have a declarative part and so cannot accommodate the pragma.
4436 if Ekind
(Current_Scope
) = E_Return_Statement
then
4438 ("invalid context for deferred constant declaration (RM 7.4)",
4441 ("\declaration requires an initialization expression",
4443 Set_Constant_Present
(N
, False);
4445 -- In Ada 83, deferred constant must be of private type
4447 elsif not Is_Private_Type
(T
) then
4448 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4450 ("(Ada 83) deferred constant must be private type", N
);
4454 -- If not a deferred constant, then the object declaration freezes
4455 -- its type, unless the object is of an anonymous type and has delayed
4456 -- aspects. In that case the type is frozen when the object itself is.
4459 Check_Fully_Declared
(T
, N
);
4461 if Has_Delayed_Aspects
(Id
)
4462 and then Is_Array_Type
(T
)
4463 and then Is_Itype
(T
)
4465 Set_Has_Delayed_Freeze
(T
);
4467 Freeze_Before
(N
, T
);
4471 -- If the object was created by a constrained array definition, then
4472 -- set the link in both the anonymous base type and anonymous subtype
4473 -- that are built to represent the array type to point to the object.
4475 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
4476 N_Constrained_Array_Definition
4478 Set_Related_Array_Object
(T
, Id
);
4479 Set_Related_Array_Object
(Base_Type
(T
), Id
);
4482 -- Check for protected objects not at library level
4484 if Has_Protected
(T
) and then not Is_Library_Level_Entity
(Id
) then
4485 Check_Restriction
(No_Local_Protected_Objects
, Id
);
4488 -- Check for violation of No_Local_Timing_Events
4490 if Has_Timing_Event
(T
) and then not Is_Library_Level_Entity
(Id
) then
4491 Check_Restriction
(No_Local_Timing_Events
, Id
);
4494 -- The actual subtype of the object is the nominal subtype, unless
4495 -- the nominal one is unconstrained and obtained from the expression.
4499 if Is_Library_Level_Entity
(Id
) then
4500 Check_Dynamic_Object
(T
);
4503 -- Process initialization expression if present and not in error
4505 if Present
(E
) and then E
/= Error
then
4507 -- Generate an error in case of CPP class-wide object initialization.
4508 -- Required because otherwise the expansion of the class-wide
4509 -- assignment would try to use 'size to initialize the object
4510 -- (primitive that is not available in CPP tagged types).
4512 if Is_Class_Wide_Type
(Act_T
)
4514 (Is_CPP_Class
(Root_Type
(Etype
(Act_T
)))
4516 (Present
(Full_View
(Root_Type
(Etype
(Act_T
))))
4518 Is_CPP_Class
(Full_View
(Root_Type
(Etype
(Act_T
))))))
4521 ("predefined assignment not available for 'C'P'P tagged types",
4525 Mark_Coextensions
(N
, E
);
4528 -- In case of errors detected in the analysis of the expression,
4529 -- decorate it with the expected type to avoid cascaded errors.
4531 if No
(Etype
(E
)) then
4535 -- If an initialization expression is present, then we set the
4536 -- Is_True_Constant flag. It will be reset if this is a variable
4537 -- and it is indeed modified.
4539 Set_Is_True_Constant
(Id
, True);
4541 -- If we are analyzing a constant declaration, set its completion
4542 -- flag after analyzing and resolving the expression.
4544 if Constant_Present
(N
) then
4545 Set_Has_Completion
(Id
);
4548 -- Set type and resolve (type may be overridden later on). Note:
4549 -- Ekind (Id) must still be E_Void at this point so that incorrect
4550 -- early usage within E is properly diagnosed.
4554 -- If the expression is an aggregate we must look ahead to detect
4555 -- the possible presence of an address clause, and defer resolution
4556 -- and expansion of the aggregate to the freeze point of the entity.
4558 -- This is not always legal because the aggregate may contain other
4559 -- references that need freezing, e.g. references to other entities
4560 -- with address clauses. In any case, when compiling with -gnatI the
4561 -- presence of the address clause must be ignored.
4563 if Comes_From_Source
(N
)
4564 and then Expander_Active
4565 and then Nkind
(E
) = N_Aggregate
4567 ((Present
(Following_Address_Clause
(N
))
4568 and then not Ignore_Rep_Clauses
)
4569 or else Delayed_Aspect_Present
)
4573 -- If the aggregate is limited it will be built in place, and its
4574 -- expansion is deferred until the object declaration is expanded.
4576 -- This is also required when generating C code to ensure that an
4577 -- object with an alignment or address clause can be initialized
4578 -- by means of component by component assignments.
4580 if Is_Limited_Type
(T
) or else Modify_Tree_For_C
then
4581 Set_Expansion_Delayed
(E
);
4585 -- If the expression is a formal that is a "subprogram pointer"
4586 -- this is illegal in accessibility terms (see RM 3.10.2 (13.1/2)
4587 -- and AARM 3.10.2 (13.b/2)). Add an explicit conversion to force
4588 -- the corresponding check, as is done for assignments.
4590 if Is_Entity_Name
(E
)
4591 and then Present
(Entity
(E
))
4592 and then Is_Formal
(Entity
(E
))
4594 Ekind
(Etype
(Entity
(E
))) = E_Anonymous_Access_Subprogram_Type
4595 and then Ekind
(T
) /= E_Anonymous_Access_Subprogram_Type
4597 Rewrite
(E
, Convert_To
(T
, Relocate_Node
(E
)));
4603 -- No further action needed if E is a call to an inlined function
4604 -- which returns an unconstrained type and it has been expanded into
4605 -- a procedure call. In that case N has been replaced by an object
4606 -- declaration without initializing expression and it has been
4607 -- analyzed (see Expand_Inlined_Call).
4609 if Back_End_Inlining
4610 and then Expander_Active
4611 and then Nkind
(E
) = N_Function_Call
4612 and then Nkind
(Name
(E
)) in N_Has_Entity
4613 and then Is_Inlined
(Entity
(Name
(E
)))
4614 and then not Is_Constrained
(Etype
(E
))
4615 and then Analyzed
(N
)
4616 and then No
(Expression
(N
))
4621 -- If E is null and has been replaced by an N_Raise_Constraint_Error
4622 -- node (which was marked already-analyzed), we need to set the type
4623 -- to something else than Universal_Access to keep gigi happy.
4625 if Etype
(E
) = Universal_Access
then
4629 -- If the object is an access to variable, the initialization
4630 -- expression cannot be an access to constant.
4632 if Is_Access_Type
(T
)
4633 and then not Is_Access_Constant
(T
)
4634 and then Is_Access_Type
(Etype
(E
))
4635 and then Is_Access_Constant
(Etype
(E
))
4638 ("access to variable cannot be initialized with an "
4639 & "access-to-constant expression", E
);
4642 if not Assignment_OK
(N
) then
4643 Check_Initialization
(T
, E
);
4646 Check_Unset_Reference
(E
);
4648 -- If this is a variable, then set current value. If this is a
4649 -- declared constant of a scalar type with a static expression,
4650 -- indicate that it is always valid.
4652 if not Constant_Present
(N
) then
4653 if Compile_Time_Known_Value
(E
) then
4654 Set_Current_Value
(Id
, E
);
4657 elsif Is_Scalar_Type
(T
) and then Is_OK_Static_Expression
(E
) then
4658 Set_Is_Known_Valid
(Id
);
4660 -- If it is a constant initialized with a valid nonstatic entity,
4661 -- the constant is known valid as well, and can inherit the subtype
4662 -- of the entity if it is a subtype of the given type. This info
4663 -- is preserved on the actual subtype of the constant.
4665 elsif Is_Scalar_Type
(T
)
4666 and then Is_Entity_Name
(E
)
4667 and then Is_Known_Valid
(Entity
(E
))
4668 and then In_Subrange_Of
(Etype
(Entity
(E
)), T
)
4670 Set_Is_Known_Valid
(Id
);
4671 Mutate_Ekind
(Id
, E_Constant
);
4672 Set_Actual_Subtype
(Id
, Etype
(Entity
(E
)));
4675 -- Deal with setting of null flags
4677 if Is_Access_Type
(T
) then
4678 if Known_Non_Null
(E
) then
4679 Set_Is_Known_Non_Null
(Id
, True);
4680 elsif Known_Null
(E
) and then not Can_Never_Be_Null
(Id
) then
4681 Set_Is_Known_Null
(Id
, True);
4685 -- Check incorrect use of dynamically tagged expressions
4687 if Is_Tagged_Type
(T
) then
4688 Check_Dynamically_Tagged_Expression
4694 Apply_Scalar_Range_Check
(E
, T
);
4695 Apply_Static_Length_Check
(E
, T
);
4697 -- A formal parameter of a specific tagged type whose related
4698 -- subprogram is subject to pragma Extensions_Visible with value
4699 -- "False" cannot be implicitly converted to a class-wide type by
4700 -- means of an initialization expression (SPARK RM 6.1.7(3)). Do
4701 -- not consider internally generated expressions.
4703 if Is_Class_Wide_Type
(T
)
4704 and then Comes_From_Source
(E
)
4705 and then Is_EVF_Expression
(E
)
4708 ("formal parameter cannot be implicitly converted to "
4709 & "class-wide type when Extensions_Visible is False", E
);
4713 -- If the No_Streams restriction is set, check that the type of the
4714 -- object is not, and does not contain, any subtype derived from
4715 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
4716 -- Has_Stream just for efficiency reasons. There is no point in
4717 -- spending time on a Has_Stream check if the restriction is not set.
4719 if Restriction_Check_Required
(No_Streams
) then
4720 if Has_Stream
(T
) then
4721 Check_Restriction
(No_Streams
, N
);
4725 -- Deal with predicate check before we start to do major rewriting. It
4726 -- is OK to initialize and then check the initialized value, since the
4727 -- object goes out of scope if we get a predicate failure. Note that we
4728 -- do this in the analyzer and not the expander because the analyzer
4729 -- does some substantial rewriting in some cases.
4731 -- We need a predicate check if the type has predicates that are not
4732 -- ignored, and if either there is an initializing expression, or for
4733 -- default initialization when we have at least one case of an explicit
4734 -- default initial value (including via a Default_Value or
4735 -- Default_Component_Value aspect, see AI12-0301) and then this is not
4736 -- an internal declaration whose initialization comes later (as for an
4737 -- aggregate expansion) or a deferred constant.
4738 -- If expression is an aggregate it may be expanded into assignments
4739 -- and the declaration itself is marked with No_Initialization, but
4740 -- the predicate still applies.
4742 if not Suppress_Assignment_Checks
(N
)
4743 and then (Predicate_Enabled
(T
) or else Has_Static_Predicate
(T
))
4745 (not No_Initialization
(N
)
4746 or else (Present
(E
) and then Nkind
(E
) = N_Aggregate
))
4750 Is_Partially_Initialized_Type
(T
, Include_Implicit
=> False))
4751 and then not (Constant_Present
(N
) and then No
(E
))
4753 -- If the type has a static predicate and the expression is known at
4754 -- compile time, see if the expression satisfies the predicate.
4755 -- In the case of a static expression, this must be done even if
4756 -- the predicate is not enabled (as per static expression rules).
4759 Check_Expression_Against_Static_Predicate
(E
, T
);
4762 -- Do not perform further predicate-related checks unless
4763 -- predicates are enabled for the subtype.
4765 if not Predicate_Enabled
(T
) then
4768 -- If the type is a null record and there is no explicit initial
4769 -- expression, no predicate check applies.
4771 elsif No
(E
) and then Is_Null_Record_Type
(T
) then
4774 -- If there is an address clause for this object, do not generate a
4775 -- predicate check here. It will be generated later, at the freezng
4776 -- point. It would be wrong to generate references to the object
4777 -- here, before the address has been determined.
4779 elsif Has_Aspect
(Id
, Aspect_Address
)
4780 or else Present
(Following_Address_Clause
(N
))
4784 -- Do not generate a predicate check if the initialization expression
4785 -- is a type conversion whose target subtype statically matches the
4786 -- object's subtype because the conversion has been subjected to the
4787 -- same check. This is a small optimization which avoids redundant
4791 and then Nkind
(E
) in N_Type_Conversion
4792 and then Subtypes_Statically_Match
(Etype
(Subtype_Mark
(E
)), T
)
4797 -- The check must be inserted after the expanded aggregate
4798 -- expansion code, if any.
4801 Check
: constant Node_Id
:=
4802 Make_Predicate_Check
(T
, New_Occurrence_Of
(Id
, Loc
));
4804 if No
(Next_Decl
) then
4805 Append_To
(List_Containing
(N
), Check
);
4807 Insert_Before
(Next_Decl
, Check
);
4813 -- Case of unconstrained type
4815 if not Is_Definite_Subtype
(T
) then
4817 -- Nothing to do in deferred constant case
4819 if Constant_Present
(N
) and then No
(E
) then
4822 -- Case of no initialization present
4825 if No_Initialization
(N
) then
4828 elsif Is_Class_Wide_Type
(T
) then
4830 ("initialization required in class-wide declaration", N
);
4834 ("unconstrained subtype not allowed (need initialization)",
4835 Object_Definition
(N
));
4837 if Is_Record_Type
(T
) and then Has_Discriminants
(T
) then
4839 ("\provide initial value or explicit discriminant values",
4840 Object_Definition
(N
));
4843 ("\or give default discriminant values for type&",
4844 Object_Definition
(N
), T
);
4846 elsif Is_Array_Type
(T
) then
4848 ("\provide initial value or explicit array bounds",
4849 Object_Definition
(N
));
4853 -- Case of initialization present but in error. Set initial
4854 -- expression as absent (but do not make above complaints).
4856 elsif E
= Error
then
4857 Set_Expression
(N
, Empty
);
4860 -- Case of initialization present
4863 -- Unconstrained variables not allowed in Ada 83
4865 if Ada_Version
= Ada_83
4866 and then not Constant_Present
(N
)
4867 and then Comes_From_Source
(Object_Definition
(N
))
4870 ("(Ada 83) unconstrained variable not allowed",
4871 Object_Definition
(N
));
4874 -- Now we constrain the variable from the initializing expression
4876 -- If the expression is an aggregate, it has been expanded into
4877 -- individual assignments. Retrieve the actual type from the
4878 -- expanded construct.
4880 if Is_Array_Type
(T
)
4881 and then No_Initialization
(N
)
4882 and then Nkind
(Original_Node
(E
)) = N_Aggregate
4886 -- In case of class-wide interface object declarations we delay
4887 -- the generation of the equivalent record type declarations until
4888 -- its expansion because there are cases in they are not required.
4890 elsif Is_Interface
(T
) then
4893 -- If the type is an unchecked union, no subtype can be built from
4894 -- the expression. Rewrite declaration as a renaming, which the
4895 -- back-end can handle properly. This is a rather unusual case,
4896 -- because most unchecked_union declarations have default values
4897 -- for discriminants and are thus not indefinite.
4899 elsif Is_Unchecked_Union
(T
) then
4900 if Constant_Present
(N
) or else Nkind
(E
) = N_Function_Call
then
4901 Mutate_Ekind
(Id
, E_Constant
);
4903 Mutate_Ekind
(Id
, E_Variable
);
4906 -- If the expression is an aggregate it contains the required
4907 -- discriminant values but it has not been resolved yet, so do
4908 -- it now, and treat it as the initial expression of an object
4909 -- declaration, rather than a renaming.
4911 if Nkind
(E
) = N_Aggregate
then
4912 Analyze_And_Resolve
(E
, T
);
4916 Make_Object_Renaming_Declaration
(Loc
,
4917 Defining_Identifier
=> Id
,
4918 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
4921 Set_Renamed_Object
(Id
, E
);
4922 Freeze_Before
(N
, T
);
4928 -- Ensure that the generated subtype has a unique external name
4929 -- when the related object is public. This guarantees that the
4930 -- subtype and its bounds will not be affected by switches or
4931 -- pragmas that may offset the internal counter due to extra
4934 if Is_Public
(Id
) then
4937 Related_Id
:= Empty
;
4940 -- If the object has an unconstrained array subtype with fixed
4941 -- lower bound, then sliding to that bound may be needed.
4943 if Is_Fixed_Lower_Bound_Array_Subtype
(T
) then
4944 Expand_Sliding_Conversion
(E
, T
);
4947 if In_Spec_Expression
and then In_Declare_Expr
> 0 then
4948 -- It is too early to be doing expansion-ish things,
4949 -- so exit early. But we have to set Ekind (Id) now so
4950 -- that subsequent uses of this entity are not rejected
4951 -- via the same mechanism that (correctly) rejects
4952 -- "X : Integer := X;".
4954 if Constant_Present
(N
) then
4955 Mutate_Ekind
(Id
, E_Constant
);
4956 Set_Is_True_Constant
(Id
);
4958 Mutate_Ekind
(Id
, E_Variable
);
4960 Set_Has_Initial_Value
(Id
);
4967 Expand_Subtype_From_Expr
4970 Subtype_Indic
=> Object_Definition
(N
),
4972 Related_Id
=> Related_Id
);
4974 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4979 Full_View_Present
: constant Boolean :=
4980 Is_Private_Type
(Act_T
)
4981 and then Present
(Full_View
(Act_T
));
4982 -- Propagate attributes to full view when needed
4985 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
4987 if Full_View_Present
then
4988 Set_Is_Constr_Subt_For_U_Nominal
(Full_View
(Act_T
));
4991 if Aliased_Present
(N
) then
4992 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
4994 if Full_View_Present
then
4995 Set_Is_Constr_Subt_For_UN_Aliased
(Full_View
(Act_T
));
4999 Freeze_Before
(N
, Act_T
);
5003 Freeze_Before
(N
, T
);
5006 elsif Is_Array_Type
(T
)
5007 and then No_Initialization
(N
)
5008 and then (Nkind
(Original_Node
(E
)) = N_Aggregate
5009 or else (Nkind
(Original_Node
(E
)) = N_Qualified_Expression
5010 and then Nkind
(Original_Node
(Expression
5011 (Original_Node
(E
)))) = N_Aggregate
))
5013 if not Is_Entity_Name
(Object_Definition
(N
)) then
5015 Check_Compile_Time_Size
(Act_T
);
5018 -- When the given object definition and the aggregate are specified
5019 -- independently, and their lengths might differ do a length check.
5020 -- This cannot happen if the aggregate is of the form (others =>...)
5022 if Nkind
(E
) = N_Raise_Constraint_Error
then
5024 -- Aggregate is statically illegal. Place back in declaration
5026 Set_Expression
(N
, E
);
5027 Set_No_Initialization
(N
, False);
5029 elsif T
= Etype
(E
) then
5032 elsif Nkind
(E
) = N_Aggregate
5033 and then Present
(Component_Associations
(E
))
5034 and then Present
(Choice_List
(First
(Component_Associations
(E
))))
5036 Nkind
(First
(Choice_List
(First
(Component_Associations
(E
))))) =
5042 Apply_Length_Check
(E
, T
);
5045 -- When possible, and not a deferred constant, build the default subtype
5047 elsif Build_Default_Subtype_OK
(T
)
5048 and then (not Constant_Present
(N
) or else Present
(E
))
5051 Act_T
:= Build_Default_Subtype
(T
, N
);
5053 -- Ada 2005: A limited object may be initialized by means of an
5054 -- aggregate. If the type has default discriminants it has an
5055 -- unconstrained nominal type, Its actual subtype will be obtained
5056 -- from the aggregate, and not from the default discriminants.
5061 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
5062 Freeze_Before
(N
, Act_T
);
5064 elsif Nkind
(E
) = N_Function_Call
5065 and then Constant_Present
(N
)
5066 and then Has_Unconstrained_Elements
(Etype
(E
))
5068 -- The back-end has problems with constants of a discriminated type
5069 -- with defaults, if the initial value is a function call. We
5070 -- generate an intermediate temporary that will receive a reference
5071 -- to the result of the call. The initialization expression then
5072 -- becomes a dereference of that temporary.
5074 Remove_Side_Effects
(E
);
5076 -- If this is a constant declaration of an unconstrained type and
5077 -- the initialization is an aggregate, we can use the subtype of the
5078 -- aggregate for the declared entity because it is immutable.
5080 elsif not Is_Constrained
(T
)
5081 and then Has_Discriminants
(T
)
5082 and then Constant_Present
(N
)
5083 and then not Has_Unchecked_Union
(T
)
5084 and then Nkind
(E
) = N_Aggregate
5089 -- Check No_Wide_Characters restriction
5091 Check_Wide_Character_Restriction
(T
, Object_Definition
(N
));
5093 -- Indicate this is not set in source. Certainly true for constants, and
5094 -- true for variables so far (will be reset for a variable if and when
5095 -- we encounter a modification in the source).
5097 Set_Never_Set_In_Source
(Id
);
5099 -- Now establish the proper kind and type of the object
5101 if Ekind
(Id
) = E_Void
then
5102 Reinit_Field_To_Zero
(Id
, F_Next_Inlined_Subprogram
);
5105 if Constant_Present
(N
) then
5106 Mutate_Ekind
(Id
, E_Constant
);
5107 Set_Is_True_Constant
(Id
);
5110 Mutate_Ekind
(Id
, E_Variable
);
5112 -- A variable is set as shared passive if it appears in a shared
5113 -- passive package, and is at the outer level. This is not done for
5114 -- entities generated during expansion, because those are always
5115 -- manipulated locally.
5117 if Is_Shared_Passive
(Current_Scope
)
5118 and then Is_Library_Level_Entity
(Id
)
5119 and then Comes_From_Source
(Id
)
5121 Set_Is_Shared_Passive
(Id
);
5122 Check_Shared_Var
(Id
, T
, N
);
5125 -- Set Has_Initial_Value if initializing expression present. Note
5126 -- that if there is no initializing expression, we leave the state
5127 -- of this flag unchanged (usually it will be False, but notably in
5128 -- the case of exception choice variables, it will already be true).
5131 Set_Has_Initial_Value
(Id
);
5135 -- Set the SPARK mode from the current context (may be overwritten later
5136 -- with explicit pragma).
5138 Set_SPARK_Pragma
(Id
, SPARK_Mode_Pragma
);
5139 Set_SPARK_Pragma_Inherited
(Id
);
5141 -- Preserve relevant elaboration-related attributes of the context which
5142 -- are no longer available or very expensive to recompute once analysis,
5143 -- resolution, and expansion are over.
5145 Mark_Elaboration_Attributes
5150 -- Initialize alignment and size and capture alignment setting
5152 Reinit_Alignment
(Id
);
5154 Set_Optimize_Alignment_Flags
(Id
);
5156 -- Deal with aliased case
5158 if Aliased_Present
(N
) then
5159 Set_Is_Aliased
(Id
);
5161 -- AI12-001: All aliased objects are considered to be specified as
5162 -- independently addressable (RM C.6(8.1/4)).
5164 Set_Is_Independent
(Id
);
5166 -- If the object is aliased and the type is unconstrained with
5167 -- defaulted discriminants and there is no expression, then the
5168 -- object is constrained by the defaults, so it is worthwhile
5169 -- building the corresponding subtype.
5171 -- Ada 2005 (AI-363): If the aliased object is discriminated and
5172 -- unconstrained, then only establish an actual subtype if the
5173 -- nominal subtype is indefinite. In definite cases the object is
5174 -- unconstrained in Ada 2005.
5177 and then Is_Record_Type
(T
)
5178 and then not Is_Constrained
(T
)
5179 and then Has_Discriminants
(T
)
5180 and then (Ada_Version
< Ada_2005
5181 or else not Is_Definite_Subtype
(T
))
5183 Set_Actual_Subtype
(Id
, Build_Default_Subtype
(T
, N
));
5187 -- Now we can set the type of the object
5189 Set_Etype
(Id
, Act_T
);
5191 -- Non-constant object is marked to be treated as volatile if type is
5192 -- volatile and we clear the Current_Value setting that may have been
5193 -- set above. Doing so for constants isn't required and might interfere
5194 -- with possible uses of the object as a static expression in contexts
5195 -- incompatible with volatility (e.g. as a case-statement alternative).
5197 if Ekind
(Id
) /= E_Constant
and then Treat_As_Volatile
(Etype
(Id
)) then
5198 Set_Treat_As_Volatile
(Id
);
5199 Set_Current_Value
(Id
, Empty
);
5202 -- Deal with controlled types
5204 if Has_Controlled_Component
(Etype
(Id
))
5205 or else Is_Controlled
(Etype
(Id
))
5207 if not Is_Library_Level_Entity
(Id
) then
5208 Check_Restriction
(No_Nested_Finalization
, N
);
5210 Validate_Controlled_Object
(Id
);
5214 if Has_Task
(Etype
(Id
)) then
5215 Check_Restriction
(No_Tasking
, N
);
5217 -- Deal with counting max tasks
5219 -- Nothing to do if inside a generic
5221 if Inside_A_Generic
then
5224 -- If library level entity, then count tasks
5226 elsif Is_Library_Level_Entity
(Id
) then
5227 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
5229 -- If not library level entity, then indicate we don't know max
5230 -- tasks and also check task hierarchy restriction and blocking
5231 -- operation (since starting a task is definitely blocking).
5234 Check_Restriction
(Max_Tasks
, N
);
5235 Check_Restriction
(No_Task_Hierarchy
, N
);
5236 Check_Potentially_Blocking_Operation
(N
);
5239 -- A rather specialized test. If we see two tasks being declared
5240 -- of the same type in the same object declaration, and the task
5241 -- has an entry with an address clause, we know that program error
5242 -- will be raised at run time since we can't have two tasks with
5243 -- entries at the same address.
5245 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
5250 E
:= First_Entity
(Etype
(Id
));
5251 while Present
(E
) loop
5252 if Ekind
(E
) = E_Entry
5253 and then Present
(Get_Attribute_Definition_Clause
5254 (E
, Attribute_Address
))
5256 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5258 ("more than one task with same entry address<<", N
);
5259 Error_Msg_N
("\Program_Error [<<", N
);
5261 Make_Raise_Program_Error
(Loc
,
5262 Reason
=> PE_Duplicated_Entry_Address
));
5272 -- Check specific legality rules for a return object
5274 if Is_Return_Object
(Id
) then
5275 Check_Return_Subtype_Indication
(N
);
5278 -- Some simple constant-propagation: if the expression is a constant
5279 -- string initialized with a literal, share the literal. This avoids
5283 and then Is_Entity_Name
(E
)
5284 and then Ekind
(Entity
(E
)) = E_Constant
5285 and then Base_Type
(Etype
(E
)) = Standard_String
5288 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
5290 if Present
(Val
) and then Nkind
(Val
) = N_String_Literal
then
5291 Rewrite
(E
, New_Copy
(Val
));
5296 if Present
(Prev_Entity
)
5297 and then Is_Frozen
(Prev_Entity
)
5298 and then not Error_Posted
(Id
)
5300 Error_Msg_N
("full constant declaration appears too late", N
);
5303 Check_Eliminated
(Id
);
5305 -- Deal with setting In_Private_Part flag if in private part
5307 if Ekind
(Scope
(Id
)) = E_Package
5308 and then In_Private_Part
(Scope
(Id
))
5310 Set_In_Private_Part
(Id
);
5314 -- Initialize the refined state of a variable here because this is a
5315 -- common destination for legal and illegal object declarations.
5317 if Ekind
(Id
) = E_Variable
then
5318 Set_Encapsulating_State
(Id
, Empty
);
5321 Analyze_Aspect_Specifications
(N
, Id
);
5323 Analyze_Dimension
(N
);
5325 -- Verify whether the object declaration introduces an illegal hidden
5326 -- state within a package subject to a null abstract state.
5328 if Ekind
(Id
) = E_Variable
then
5329 Check_No_Hidden_State
(Id
);
5332 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
5333 end Analyze_Object_Declaration
;
5335 ---------------------------
5336 -- Analyze_Others_Choice --
5337 ---------------------------
5339 -- Nothing to do for the others choice node itself, the semantic analysis
5340 -- of the others choice will occur as part of the processing of the parent
5342 procedure Analyze_Others_Choice
(N
: Node_Id
) is
5343 pragma Warnings
(Off
, N
);
5346 end Analyze_Others_Choice
;
5348 -------------------------------------------
5349 -- Analyze_Private_Extension_Declaration --
5350 -------------------------------------------
5352 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
5353 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
5354 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5356 Iface_Elmt
: Elmt_Id
;
5357 Parent_Base
: Entity_Id
;
5358 Parent_Type
: Entity_Id
;
5361 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
5363 if Is_Non_Empty_List
(Interface_List
(N
)) then
5369 Intf
:= First
(Interface_List
(N
));
5370 while Present
(Intf
) loop
5371 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
5373 Diagnose_Interface
(Intf
, T
);
5379 Generate_Definition
(T
);
5381 -- For other than Ada 2012, just enter the name in the current scope
5383 if Ada_Version
< Ada_2012
then
5386 -- Ada 2012 (AI05-0162): Enter the name in the current scope handling
5387 -- case of private type that completes an incomplete type.
5394 Prev
:= Find_Type_Name
(N
);
5396 pragma Assert
(Prev
= T
5397 or else (Ekind
(Prev
) = E_Incomplete_Type
5398 and then Present
(Full_View
(Prev
))
5399 and then Full_View
(Prev
) = T
));
5403 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
5404 Parent_Base
:= Base_Type
(Parent_Type
);
5406 if Parent_Type
= Any_Type
or else Etype
(Parent_Type
) = Any_Type
then
5407 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
5408 Set_Etype
(T
, Any_Type
);
5411 elsif not Is_Tagged_Type
(Parent_Type
) then
5413 ("parent of type extension must be a tagged type", Indic
);
5416 elsif Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
5417 Error_Msg_N
("premature derivation of incomplete type", Indic
);
5420 elsif Is_Concurrent_Type
(Parent_Type
) then
5422 ("parent type of a private extension cannot be a synchronized "
5423 & "tagged type (RM 3.9.1 (3/1))", N
);
5425 Set_Etype
(T
, Any_Type
);
5426 Mutate_Ekind
(T
, E_Limited_Private_Type
);
5427 Set_Private_Dependents
(T
, New_Elmt_List
);
5428 Set_Error_Posted
(T
);
5432 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
5434 -- Perhaps the parent type should be changed to the class-wide type's
5435 -- specific type in this case to prevent cascading errors ???
5437 if Is_Class_Wide_Type
(Parent_Type
) then
5439 ("parent of type extension must not be a class-wide type", Indic
);
5443 if (not Is_Package_Or_Generic_Package
(Current_Scope
)
5444 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
5445 or else In_Private_Part
(Current_Scope
)
5447 Error_Msg_N
("invalid context for private extension", N
);
5450 -- Set common attributes
5452 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
5453 Set_Scope
(T
, Current_Scope
);
5454 Mutate_Ekind
(T
, E_Record_Type_With_Private
);
5455 Reinit_Size_Align
(T
);
5456 Set_Default_SSO
(T
);
5457 Set_No_Reordering
(T
, No_Component_Reordering
);
5459 Set_Etype
(T
, Parent_Base
);
5460 Propagate_Concurrent_Flags
(T
, Parent_Base
);
5462 Set_Convention
(T
, Convention
(Parent_Type
));
5463 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
5464 Set_Is_First_Subtype
(T
);
5466 -- Set the SPARK mode from the current context
5468 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
5469 Set_SPARK_Pragma_Inherited
(T
);
5471 if Unknown_Discriminants_Present
(N
) then
5472 Set_Discriminant_Constraint
(T
, No_Elist
);
5475 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
5477 -- A private extension inherits the Default_Initial_Condition pragma
5478 -- coming from any parent type within the derivation chain.
5480 if Has_DIC
(Parent_Type
) then
5481 Set_Has_Inherited_DIC
(T
);
5484 -- A private extension inherits any class-wide invariants coming from a
5485 -- parent type or an interface. Note that the invariant procedure of the
5486 -- parent type should not be inherited because the private extension may
5487 -- define invariants of its own.
5489 if Has_Inherited_Invariants
(Parent_Type
)
5490 or else Has_Inheritable_Invariants
(Parent_Type
)
5492 Set_Has_Inherited_Invariants
(T
);
5494 elsif Present
(Interfaces
(T
)) then
5495 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5496 while Present
(Iface_Elmt
) loop
5497 Iface
:= Node
(Iface_Elmt
);
5499 if Has_Inheritable_Invariants
(Iface
) then
5500 Set_Has_Inherited_Invariants
(T
);
5504 Next_Elmt
(Iface_Elmt
);
5508 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
5509 -- synchronized formal derived type.
5511 if Ada_Version
>= Ada_2005
and then Synchronized_Present
(N
) then
5512 Set_Is_Limited_Record
(T
);
5514 -- Formal derived type case
5516 if Is_Generic_Type
(T
) then
5518 -- The parent must be a tagged limited type or a synchronized
5521 if (not Is_Tagged_Type
(Parent_Type
)
5522 or else not Is_Limited_Type
(Parent_Type
))
5524 (not Is_Interface
(Parent_Type
)
5525 or else not Is_Synchronized_Interface
(Parent_Type
))
5528 ("parent type of & must be tagged limited or synchronized",
5532 -- The progenitors (if any) must be limited or synchronized
5535 if Present
(Interfaces
(T
)) then
5536 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5537 while Present
(Iface_Elmt
) loop
5538 Iface
:= Node
(Iface_Elmt
);
5540 if not Is_Limited_Interface
(Iface
)
5541 and then not Is_Synchronized_Interface
(Iface
)
5544 ("progenitor & must be limited or synchronized",
5548 Next_Elmt
(Iface_Elmt
);
5552 -- Regular derived extension, the parent must be a limited or
5553 -- synchronized interface.
5556 if not Is_Interface
(Parent_Type
)
5557 or else (not Is_Limited_Interface
(Parent_Type
)
5558 and then not Is_Synchronized_Interface
(Parent_Type
))
5561 ("parent type of & must be limited interface", N
, T
);
5565 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
5566 -- extension with a synchronized parent must be explicitly declared
5567 -- synchronized, because the full view will be a synchronized type.
5568 -- This must be checked before the check for limited types below,
5569 -- to ensure that types declared limited are not allowed to extend
5570 -- synchronized interfaces.
5572 elsif Is_Interface
(Parent_Type
)
5573 and then Is_Synchronized_Interface
(Parent_Type
)
5574 and then not Synchronized_Present
(N
)
5577 ("private extension of& must be explicitly synchronized",
5580 elsif Limited_Present
(N
) then
5581 Set_Is_Limited_Record
(T
);
5583 if not Is_Limited_Type
(Parent_Type
)
5585 (not Is_Interface
(Parent_Type
)
5586 or else not Is_Limited_Interface
(Parent_Type
))
5588 Error_Msg_NE
("parent type& of limited extension must be limited",
5593 -- Remember that its parent type has a private extension. Used to warn
5594 -- on public primitives of the parent type defined after its private
5595 -- extensions (see Check_Dispatching_Operation).
5597 Set_Has_Private_Extension
(Parent_Type
);
5600 Analyze_Aspect_Specifications
(N
, T
);
5601 end Analyze_Private_Extension_Declaration
;
5603 ---------------------------------
5604 -- Analyze_Subtype_Declaration --
5605 ---------------------------------
5607 procedure Analyze_Subtype_Declaration
5609 Skip
: Boolean := False)
5611 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5615 Generate_Definition
(Id
);
5616 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
5617 Reinit_Size_Align
(Id
);
5619 -- The following guard condition on Enter_Name is to handle cases where
5620 -- the defining identifier has already been entered into the scope but
5621 -- the declaration as a whole needs to be analyzed.
5623 -- This case in particular happens for derived enumeration types. The
5624 -- derived enumeration type is processed as an inserted enumeration type
5625 -- declaration followed by a rewritten subtype declaration. The defining
5626 -- identifier, however, is entered into the name scope very early in the
5627 -- processing of the original type declaration and therefore needs to be
5628 -- avoided here, when the created subtype declaration is analyzed. (See
5629 -- Build_Derived_Types)
5631 -- This also happens when the full view of a private type is a derived
5632 -- type with constraints. In this case the entity has been introduced
5633 -- in the private declaration.
5635 -- Finally this happens in some complex cases when validity checks are
5636 -- enabled, where the same subtype declaration may be analyzed twice.
5637 -- This can happen if the subtype is created by the preanalysis of
5638 -- an attribute that gives the range of a loop statement, and the loop
5639 -- itself appears within an if_statement that will be rewritten during
5643 or else (Present
(Etype
(Id
))
5644 and then (Is_Private_Type
(Etype
(Id
))
5645 or else Is_Task_Type
(Etype
(Id
))
5646 or else Is_Rewrite_Substitution
(N
)))
5650 elsif Current_Entity
(Id
) = Id
then
5657 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
5659 -- Class-wide equivalent types of records with unknown discriminants
5660 -- involve the generation of an itype which serves as the private view
5661 -- of a constrained record subtype. In such cases the base type of the
5662 -- current subtype we are processing is the private itype. Use the full
5663 -- of the private itype when decorating various attributes.
5666 and then Is_Private_Type
(T
)
5667 and then Present
(Full_View
(T
))
5672 -- Inherit common attributes
5674 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
5675 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
5676 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
5677 Set_Convention
(Id
, Convention
(T
));
5679 -- If ancestor has predicates then so does the subtype, and in addition
5680 -- we must delay the freeze to properly arrange predicate inheritance.
5682 -- The Ancestor_Type test is really unpleasant, there seem to be cases
5683 -- in which T = ID, so the above tests and assignments do nothing???
5685 if Has_Predicates
(T
)
5686 or else (Present
(Ancestor_Subtype
(T
))
5687 and then Has_Predicates
(Ancestor_Subtype
(T
)))
5689 Set_Has_Predicates
(Id
);
5690 Set_Has_Delayed_Freeze
(Id
);
5692 -- Generated subtypes inherit the predicate function from the parent
5693 -- (no aspects to examine on the generated declaration).
5695 if not Comes_From_Source
(N
) then
5696 Mutate_Ekind
(Id
, Ekind
(T
));
5698 if Present
(Predicate_Function
(Id
)) then
5701 elsif Present
(Predicate_Function
(T
)) then
5702 Set_Predicate_Function
(Id
, Predicate_Function
(T
));
5704 elsif Present
(Ancestor_Subtype
(T
))
5705 and then Present
(Predicate_Function
(Ancestor_Subtype
(T
)))
5707 Set_Predicate_Function
(Id
,
5708 Predicate_Function
(Ancestor_Subtype
(T
)));
5713 -- In the case where there is no constraint given in the subtype
5714 -- indication, Process_Subtype just returns the Subtype_Mark, so its
5715 -- semantic attributes must be established here.
5717 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
5718 Set_Etype
(Id
, Base_Type
(T
));
5722 Mutate_Ekind
(Id
, E_Array_Subtype
);
5723 Copy_Array_Subtype_Attributes
(Id
, T
);
5724 Set_Packed_Array_Impl_Type
(Id
, Packed_Array_Impl_Type
(T
));
5726 when Decimal_Fixed_Point_Kind
=>
5727 Mutate_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
5728 Set_Digits_Value
(Id
, Digits_Value
(T
));
5729 Set_Delta_Value
(Id
, Delta_Value
(T
));
5730 Set_Scale_Value
(Id
, Scale_Value
(T
));
5731 Set_Small_Value
(Id
, Small_Value
(T
));
5732 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5733 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
5734 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5735 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5736 Copy_RM_Size
(To
=> Id
, From
=> T
);
5738 when Enumeration_Kind
=>
5739 Mutate_Ekind
(Id
, E_Enumeration_Subtype
);
5740 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
5741 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5742 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
5743 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5744 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5745 Copy_RM_Size
(To
=> Id
, From
=> T
);
5747 when Ordinary_Fixed_Point_Kind
=>
5748 Mutate_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
5749 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5750 Set_Small_Value
(Id
, Small_Value
(T
));
5751 Set_Delta_Value
(Id
, Delta_Value
(T
));
5752 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5753 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5754 Copy_RM_Size
(To
=> Id
, From
=> T
);
5757 Mutate_Ekind
(Id
, E_Floating_Point_Subtype
);
5758 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5759 Set_Digits_Value
(Id
, Digits_Value
(T
));
5760 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5762 -- If the floating point type has dimensions, these will be
5763 -- inherited subsequently when Analyze_Dimensions is called.
5765 when Signed_Integer_Kind
=>
5766 Mutate_Ekind
(Id
, E_Signed_Integer_Subtype
);
5767 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5768 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5769 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5770 Copy_RM_Size
(To
=> Id
, From
=> T
);
5772 when Modular_Integer_Kind
=>
5773 Mutate_Ekind
(Id
, E_Modular_Integer_Subtype
);
5774 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5775 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5776 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5777 Copy_RM_Size
(To
=> Id
, From
=> T
);
5779 when Class_Wide_Kind
=>
5780 Mutate_Ekind
(Id
, E_Class_Wide_Subtype
);
5781 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5782 Set_Cloned_Subtype
(Id
, T
);
5783 Set_Is_Tagged_Type
(Id
, True);
5784 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5785 Set_Has_Unknown_Discriminants
5787 Set_No_Tagged_Streams_Pragma
5788 (Id
, No_Tagged_Streams_Pragma
(T
));
5790 if Ekind
(T
) = E_Class_Wide_Subtype
then
5791 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
5794 when E_Record_Subtype
5797 Mutate_Ekind
(Id
, E_Record_Subtype
);
5799 -- Subtype declarations introduced for formal type parameters
5800 -- in generic instantiations should inherit the Size value of
5801 -- the type they rename.
5803 if Present
(Generic_Parent_Type
(N
)) then
5804 Copy_RM_Size
(To
=> Id
, From
=> T
);
5807 if Ekind
(T
) = E_Record_Subtype
5808 and then Present
(Cloned_Subtype
(T
))
5810 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
5812 Set_Cloned_Subtype
(Id
, T
);
5815 Set_First_Entity
(Id
, First_Entity
(T
));
5816 Set_Last_Entity
(Id
, Last_Entity
(T
));
5817 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5818 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5819 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5820 Set_Has_Implicit_Dereference
5821 (Id
, Has_Implicit_Dereference
(T
));
5822 Set_Has_Unknown_Discriminants
5823 (Id
, Has_Unknown_Discriminants
(T
));
5825 if Has_Discriminants
(T
) then
5826 Set_Discriminant_Constraint
5827 (Id
, Discriminant_Constraint
(T
));
5828 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5830 elsif Has_Unknown_Discriminants
(Id
) then
5831 Set_Discriminant_Constraint
(Id
, No_Elist
);
5834 if Is_Tagged_Type
(T
) then
5835 Set_Is_Tagged_Type
(Id
, True);
5836 Set_No_Tagged_Streams_Pragma
5837 (Id
, No_Tagged_Streams_Pragma
(T
));
5838 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5839 Set_Direct_Primitive_Operations
5840 (Id
, Direct_Primitive_Operations
(T
));
5841 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5843 if Is_Interface
(T
) then
5844 Set_Is_Interface
(Id
);
5845 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
5849 when Private_Kind
=>
5850 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5851 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5852 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5853 Set_First_Entity
(Id
, First_Entity
(T
));
5854 Set_Last_Entity
(Id
, Last_Entity
(T
));
5855 Set_Private_Dependents
(Id
, New_Elmt_List
);
5856 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5857 Set_Has_Implicit_Dereference
5858 (Id
, Has_Implicit_Dereference
(T
));
5859 Set_Has_Unknown_Discriminants
5860 (Id
, Has_Unknown_Discriminants
(T
));
5861 Set_Known_To_Have_Preelab_Init
5862 (Id
, Known_To_Have_Preelab_Init
(T
));
5864 if Is_Tagged_Type
(T
) then
5865 Set_Is_Tagged_Type
(Id
);
5866 Set_No_Tagged_Streams_Pragma
(Id
,
5867 No_Tagged_Streams_Pragma
(T
));
5868 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5869 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5870 Set_Direct_Primitive_Operations
(Id
,
5871 Direct_Primitive_Operations
(T
));
5874 -- In general the attributes of the subtype of a private type
5875 -- are the attributes of the partial view of parent. However,
5876 -- the full view may be a discriminated type, and the subtype
5877 -- must share the discriminant constraint to generate correct
5878 -- calls to initialization procedures.
5880 if Has_Discriminants
(T
) then
5881 Set_Discriminant_Constraint
5882 (Id
, Discriminant_Constraint
(T
));
5883 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5885 elsif Present
(Full_View
(T
))
5886 and then Has_Discriminants
(Full_View
(T
))
5888 Set_Discriminant_Constraint
5889 (Id
, Discriminant_Constraint
(Full_View
(T
)));
5890 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5892 -- This would seem semantically correct, but apparently
5893 -- generates spurious errors about missing components ???
5895 -- Set_Has_Discriminants (Id);
5898 Prepare_Private_Subtype_Completion
(Id
, N
);
5900 -- If this is the subtype of a constrained private type with
5901 -- discriminants that has got a full view and we also have
5902 -- built a completion just above, show that the completion
5903 -- is a clone of the full view to the back-end.
5905 if Has_Discriminants
(T
)
5906 and then not Has_Unknown_Discriminants
(T
)
5907 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(T
))
5908 and then Present
(Full_View
(T
))
5909 and then Present
(Full_View
(Id
))
5911 Set_Cloned_Subtype
(Full_View
(Id
), Full_View
(T
));
5915 Mutate_Ekind
(Id
, E_Access_Subtype
);
5916 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5917 Set_Is_Access_Constant
5918 (Id
, Is_Access_Constant
(T
));
5919 Set_Directly_Designated_Type
5920 (Id
, Designated_Type
(T
));
5921 Set_Can_Never_Be_Null
(Id
, Can_Never_Be_Null
(T
));
5923 -- A Pure library_item must not contain the declaration of a
5924 -- named access type, except within a subprogram, generic
5925 -- subprogram, task unit, or protected unit, or if it has
5926 -- a specified Storage_Size of zero (RM05-10.2.1(15.4-15.5)).
5928 if Comes_From_Source
(Id
)
5929 and then In_Pure_Unit
5930 and then not In_Subprogram_Task_Protected_Unit
5931 and then not No_Pool_Assigned
(Id
)
5934 ("named access types not allowed in pure unit", N
);
5937 when Concurrent_Kind
=>
5938 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5939 Set_Corresponding_Record_Type
(Id
,
5940 Corresponding_Record_Type
(T
));
5941 Set_First_Entity
(Id
, First_Entity
(T
));
5942 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
5943 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5944 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5945 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5946 Set_Last_Entity
(Id
, Last_Entity
(T
));
5948 if Is_Tagged_Type
(T
) then
5949 Set_No_Tagged_Streams_Pragma
5950 (Id
, No_Tagged_Streams_Pragma
(T
));
5953 if Has_Discriminants
(T
) then
5954 Set_Discriminant_Constraint
5955 (Id
, Discriminant_Constraint
(T
));
5956 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5959 when Incomplete_Kind
=>
5960 if Ada_Version
>= Ada_2005
then
5962 -- In Ada 2005 an incomplete type can be explicitly tagged:
5963 -- propagate indication. Note that we also have to include
5964 -- subtypes for Ada 2012 extended use of incomplete types.
5966 Mutate_Ekind
(Id
, E_Incomplete_Subtype
);
5967 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5968 Set_Private_Dependents
(Id
, New_Elmt_List
);
5970 if Is_Tagged_Type
(Id
) then
5971 Set_No_Tagged_Streams_Pragma
5972 (Id
, No_Tagged_Streams_Pragma
(T
));
5975 -- For tagged types, or when prefixed-call syntax is allowed
5976 -- for untagged types, initialize the list of primitive
5977 -- operations to an empty list.
5979 if Is_Tagged_Type
(Id
)
5980 or else Core_Extensions_Allowed
5982 Set_Direct_Primitive_Operations
(Id
, New_Elmt_List
);
5985 -- Ada 2005 (AI-412): Decorate an incomplete subtype of an
5986 -- incomplete type visible through a limited with clause.
5988 if From_Limited_With
(T
)
5989 and then Present
(Non_Limited_View
(T
))
5991 Set_From_Limited_With
(Id
);
5992 Set_Non_Limited_View
(Id
, Non_Limited_View
(T
));
5994 -- Ada 2005 (AI-412): Add the regular incomplete subtype
5995 -- to the private dependents of the original incomplete
5996 -- type for future transformation.
5999 Append_Elmt
(Id
, Private_Dependents
(T
));
6002 -- If the subtype name denotes an incomplete type an error
6003 -- was already reported by Process_Subtype.
6006 Set_Etype
(Id
, Any_Type
);
6010 raise Program_Error
;
6013 -- If there is no constraint in the subtype indication, the
6014 -- declared entity inherits predicates from the parent.
6016 Inherit_Predicate_Flags
(Id
, T
);
6019 if Etype
(Id
) = Any_Type
then
6023 -- When prefixed calls are enabled for untagged types, the subtype
6024 -- shares the primitive operations of its base type. Do this even
6025 -- when Extensions_Allowed is False to issue better error messages.
6027 Set_Direct_Primitive_Operations
6028 (Id
, Direct_Primitive_Operations
(Base_Type
(T
)));
6030 -- Some common processing on all types
6032 Set_Size_Info
(Id
, T
);
6033 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
6035 -- If the parent type is a generic actual, so is the subtype. This may
6036 -- happen in a nested instance. Why Comes_From_Source test???
6038 if not Comes_From_Source
(N
) then
6039 Set_Is_Generic_Actual_Type
(Id
, Is_Generic_Actual_Type
(T
));
6042 -- If this is a subtype declaration for an actual in an instance,
6043 -- inherit static and dynamic predicates if any.
6045 -- If declaration has no aspect specifications, inherit predicate
6046 -- info as well. Unclear how to handle the case of both specified
6047 -- and inherited predicates ??? Other inherited aspects, such as
6048 -- invariants, should be OK, but the combination with later pragmas
6049 -- may also require special merging.
6051 if Has_Predicates
(T
)
6052 and then Present
(Predicate_Function
(T
))
6054 ((In_Instance
and then not Comes_From_Source
(N
))
6055 or else No
(Aspect_Specifications
(N
)))
6057 -- Inherit Subprograms_For_Type from the full view, if present
6059 if Present
(Full_View
(T
))
6060 and then Present
(Subprograms_For_Type
(Full_View
(T
)))
6062 Set_Subprograms_For_Type
6063 (Id
, Subprograms_For_Type
(Full_View
(T
)));
6065 Set_Subprograms_For_Type
(Id
, Subprograms_For_Type
(T
));
6068 -- If the current declaration created both a private and a full view,
6069 -- then propagate Predicate_Function to the latter as well.
6071 if Present
(Full_View
(Id
))
6072 and then No
(Predicate_Function
(Full_View
(Id
)))
6074 Set_Subprograms_For_Type
6075 (Full_View
(Id
), Subprograms_For_Type
(Id
));
6078 if Has_Static_Predicate
(T
) then
6079 Set_Has_Static_Predicate
(Id
);
6080 Set_Static_Discrete_Predicate
(Id
, Static_Discrete_Predicate
(T
));
6084 -- If the base type is a scalar type, or else if there is no
6085 -- constraint, the atomic flag is inherited by the subtype.
6086 -- Ditto for the Independent aspect.
6088 if Is_Scalar_Type
(Id
)
6089 or else Is_Entity_Name
(Subtype_Indication
(N
))
6091 Set_Is_Atomic
(Id
, Is_Atomic
(T
));
6092 Set_Is_Independent
(Id
, Is_Independent
(T
));
6095 -- Remaining processing depends on characteristics of base type
6099 Set_Is_Immediately_Visible
(Id
, True);
6100 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
6101 Set_Is_Descendant_Of_Address
(Id
, Is_Descendant_Of_Address
(T
));
6103 if Is_Interface
(T
) then
6104 Set_Is_Interface
(Id
);
6105 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
6108 if Present
(Generic_Parent_Type
(N
))
6110 (Nkind
(Parent
(Generic_Parent_Type
(N
))) /=
6111 N_Formal_Type_Declaration
6112 or else Nkind
(Formal_Type_Definition
6113 (Parent
(Generic_Parent_Type
(N
)))) /=
6114 N_Formal_Private_Type_Definition
)
6116 if Is_Tagged_Type
(Id
) then
6118 -- If this is a generic actual subtype for a synchronized type,
6119 -- the primitive operations are those of the corresponding record
6120 -- for which there is a separate subtype declaration.
6122 if Is_Concurrent_Type
(Id
) then
6124 elsif Is_Class_Wide_Type
(Id
) then
6125 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
6127 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
6130 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
6131 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
6135 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
6136 Conditional_Delay
(Id
, Full_View
(T
));
6138 -- The subtypes of components or subcomponents of protected types
6139 -- do not need freeze nodes, which would otherwise appear in the
6140 -- wrong scope (before the freeze node for the protected type). The
6141 -- proper subtypes are those of the subcomponents of the corresponding
6144 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
6145 and then Present
(Scope
(Scope
(Id
))) -- error defense
6146 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
6148 Conditional_Delay
(Id
, T
);
6151 -- If we have a subtype of an incomplete type whose full type is a
6152 -- derived numeric type, we need to have a freeze node for the subtype.
6153 -- Otherwise gigi will complain while computing the (static) bounds of
6157 and then Is_Elementary_Type
(Id
)
6158 and then Etype
(Id
) /= Id
6161 Partial
: constant Entity_Id
:=
6162 Incomplete_Or_Partial_View
(First_Subtype
(Id
));
6164 if Present
(Partial
)
6165 and then Ekind
(Partial
) = E_Incomplete_Type
6167 Set_Has_Delayed_Freeze
(Id
);
6172 -- Check that Constraint_Error is raised for a scalar subtype indication
6173 -- when the lower or upper bound of a non-null range lies outside the
6174 -- range of the type mark. Likewise for an array subtype, but check the
6175 -- compatibility for each index.
6177 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6179 Indic_Typ
: constant Entity_Id
:=
6180 Underlying_Type
(Etype
(Subtype_Mark
(Subtype_Indication
(N
))));
6181 Subt_Index
: Node_Id
;
6182 Target_Index
: Node_Id
;
6185 if Is_Scalar_Type
(Etype
(Id
))
6186 and then Scalar_Range
(Id
) /= Scalar_Range
(Indic_Typ
)
6188 Apply_Range_Check
(Scalar_Range
(Id
), Indic_Typ
);
6190 elsif Is_Array_Type
(Etype
(Id
))
6191 and then Present
(First_Index
(Id
))
6193 Subt_Index
:= First_Index
(Id
);
6194 Target_Index
:= First_Index
(Indic_Typ
);
6196 while Present
(Subt_Index
) loop
6197 if ((Nkind
(Subt_Index
) in N_Expanded_Name | N_Identifier
6198 and then Is_Scalar_Type
(Entity
(Subt_Index
)))
6199 or else Nkind
(Subt_Index
) = N_Subtype_Indication
)
6201 Nkind
(Scalar_Range
(Etype
(Subt_Index
))) = N_Range
6204 (Scalar_Range
(Etype
(Subt_Index
)),
6205 Etype
(Target_Index
),
6209 Next_Index
(Subt_Index
);
6210 Next_Index
(Target_Index
);
6216 Set_Optimize_Alignment_Flags
(Id
);
6217 Check_Eliminated
(Id
);
6220 Analyze_Aspect_Specifications
(N
, Id
);
6222 Analyze_Dimension
(N
);
6224 -- Check No_Dynamic_Sized_Objects restriction, which disallows subtype
6225 -- indications on composite types where the constraints are dynamic.
6226 -- Note that object declarations and aggregates generate implicit
6227 -- subtype declarations, which this covers. One special case is that the
6228 -- implicitly generated "=" for discriminated types includes an
6229 -- offending subtype declaration, which is harmless, so we ignore it
6232 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6234 Cstr
: constant Node_Id
:= Constraint
(Subtype_Indication
(N
));
6236 if Nkind
(Cstr
) = N_Index_Or_Discriminant_Constraint
6237 and then not (Is_Internal
(Id
)
6238 and then Is_TSS
(Scope
(Id
),
6239 TSS_Composite_Equality
))
6240 and then not Within_Init_Proc
6241 and then not All_Composite_Constraints_Static
(Cstr
)
6243 Check_Restriction
(No_Dynamic_Sized_Objects
, Cstr
);
6247 end Analyze_Subtype_Declaration
;
6249 --------------------------------
6250 -- Analyze_Subtype_Indication --
6251 --------------------------------
6253 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
6254 T
: constant Entity_Id
:= Subtype_Mark
(N
);
6255 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6261 Set_Error_Posted
(R
);
6262 Set_Error_Posted
(T
);
6265 Set_Etype
(N
, Etype
(R
));
6266 Resolve
(R
, Entity
(T
));
6268 end Analyze_Subtype_Indication
;
6270 --------------------------
6271 -- Analyze_Variant_Part --
6272 --------------------------
6274 procedure Analyze_Variant_Part
(N
: Node_Id
) is
6275 Discr_Name
: Node_Id
;
6276 Discr_Type
: Entity_Id
;
6278 procedure Process_Variant
(A
: Node_Id
);
6279 -- Analyze declarations for a single variant
6281 package Analyze_Variant_Choices
is
6282 new Generic_Analyze_Choices
(Process_Variant
);
6283 use Analyze_Variant_Choices
;
6285 ---------------------
6286 -- Process_Variant --
6287 ---------------------
6289 procedure Process_Variant
(A
: Node_Id
) is
6290 CL
: constant Node_Id
:= Component_List
(A
);
6292 if not Null_Present
(CL
) then
6293 Analyze_Declarations
(Component_Items
(CL
));
6295 if Present
(Variant_Part
(CL
)) then
6296 Analyze
(Variant_Part
(CL
));
6299 end Process_Variant
;
6301 -- Start of processing for Analyze_Variant_Part
6304 Discr_Name
:= Name
(N
);
6305 Analyze
(Discr_Name
);
6307 -- If Discr_Name bad, get out (prevent cascaded errors)
6309 if Etype
(Discr_Name
) = Any_Type
then
6313 -- Check invalid discriminant in variant part
6315 if Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
6316 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
6319 Discr_Type
:= Etype
(Entity
(Discr_Name
));
6321 if not Is_Discrete_Type
(Discr_Type
) then
6323 ("discriminant in a variant part must be of a discrete type",
6328 -- Now analyze the choices, which also analyzes the declarations that
6329 -- are associated with each choice.
6331 Analyze_Choices
(Variants
(N
), Discr_Type
);
6333 -- Note: we used to instantiate and call Check_Choices here to check
6334 -- that the choices covered the discriminant, but it's too early to do
6335 -- that because of statically predicated subtypes, whose analysis may
6336 -- be deferred to their freeze point which may be as late as the freeze
6337 -- point of the containing record. So this call is now to be found in
6338 -- Freeze_Record_Declaration.
6340 end Analyze_Variant_Part
;
6342 ----------------------------
6343 -- Array_Type_Declaration --
6344 ----------------------------
6346 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
6347 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
6348 Component_Typ
: constant Node_Id
:= Subtype_Indication
(Component_Def
);
6349 P
: constant Node_Id
:= Parent
(Def
);
6350 Element_Type
: Entity_Id
;
6351 Implicit_Base
: Entity_Id
;
6355 Related_Id
: Entity_Id
;
6356 Has_FLB_Index
: Boolean := False;
6359 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6360 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
6362 Index
:= First
(Subtype_Marks
(Def
));
6365 -- Find proper names for the implicit types which may be public. In case
6366 -- of anonymous arrays we use the name of the first object of that type
6370 Related_Id
:= Defining_Identifier
(P
);
6376 while Present
(Index
) loop
6379 -- Test for odd case of trying to index a type by the type itself
6381 if Is_Entity_Name
(Index
) and then Entity
(Index
) = T
then
6382 Error_Msg_N
("type& cannot be indexed by itself", Index
);
6383 Set_Entity
(Index
, Standard_Boolean
);
6384 Set_Etype
(Index
, Standard_Boolean
);
6387 -- Add a subtype declaration for each index of private array type
6388 -- declaration whose type is also private. For example:
6391 -- type Index is private;
6393 -- type Table is array (Index) of ...
6396 -- This is currently required by the expander for the internally
6397 -- generated equality subprogram of records with variant parts in
6398 -- which the type of some component is such a private type. And it
6399 -- also helps semantic analysis in peculiar cases where the array
6400 -- type is referenced from an instance but not the index directly.
6402 if Is_Package_Or_Generic_Package
(Current_Scope
)
6403 and then In_Private_Part
(Current_Scope
)
6404 and then Has_Private_Declaration
(Etype
(Index
))
6405 and then Scope
(Etype
(Index
)) = Current_Scope
6408 Loc
: constant Source_Ptr
:= Sloc
(Def
);
6413 New_E
:= Make_Temporary
(Loc
, 'T');
6414 Set_Is_Internal
(New_E
);
6417 Make_Subtype_Declaration
(Loc
,
6418 Defining_Identifier
=> New_E
,
6419 Subtype_Indication
=>
6420 New_Occurrence_Of
(Etype
(Index
), Loc
));
6422 Insert_Before
(Parent
(Def
), Decl
);
6424 Set_Etype
(Index
, New_E
);
6426 -- If the index is a range or a subtype indication it carries
6427 -- no entity. Example:
6430 -- type T is private;
6432 -- type T is new Natural;
6433 -- Table : array (T(1) .. T(10)) of Boolean;
6436 -- Otherwise the type of the reference is its entity.
6438 if Is_Entity_Name
(Index
) then
6439 Set_Entity
(Index
, New_E
);
6444 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
6446 -- In the case where we have an unconstrained array with an index
6447 -- given by a subtype_indication, this is necessarily a "fixed lower
6448 -- bound" index. We change the upper bound of that index to the upper
6449 -- bound of the index's subtype (denoted by the subtype_mark), since
6450 -- that upper bound was originally set by the parser to be the same
6451 -- as the lower bound. In truth, that upper bound corresponds to
6452 -- a box ("<>"), and could be set to Empty, but it's convenient to
6453 -- set it to the upper bound to avoid needing to add special tests
6454 -- in various places for an Empty upper bound, and in any case that
6455 -- accurately characterizes the index's range of values.
6457 if Nkind
(Def
) = N_Unconstrained_Array_Definition
6458 and then Nkind
(Index
) = N_Subtype_Indication
6461 Index_Subtype_High_Bound
: constant Entity_Id
:=
6462 Type_High_Bound
(Entity
(Subtype_Mark
(Index
)));
6464 Set_High_Bound
(Range_Expression
(Constraint
(Index
)),
6465 Index_Subtype_High_Bound
);
6467 -- Record that the array type has one or more indexes with
6468 -- a fixed lower bound.
6470 Has_FLB_Index
:= True;
6472 -- Mark the index as belonging to an array type with a fixed
6475 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(Index
));
6479 -- Check error of subtype with predicate for index type
6481 Bad_Predicated_Subtype_Use
6482 ("subtype& has predicate, not allowed as index subtype",
6483 Index
, Etype
(Index
));
6485 -- Move to next index
6488 Nb_Index
:= Nb_Index
+ 1;
6491 -- Process subtype indication if one is present
6493 if Present
(Component_Typ
) then
6494 Element_Type
:= Process_Subtype
(Component_Typ
, P
, Related_Id
, 'C');
6495 Set_Etype
(Component_Typ
, Element_Type
);
6497 -- Ada 2005 (AI-230): Access Definition case
6499 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
6501 -- Indicate that the anonymous access type is created by the
6502 -- array type declaration.
6504 Element_Type
:= Access_Definition
6506 N
=> Access_Definition
(Component_Def
));
6507 Set_Is_Local_Anonymous_Access
(Element_Type
);
6509 -- Propagate the parent. This field is needed if we have to generate
6510 -- the master_id associated with an anonymous access to task type
6511 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
6513 Copy_Parent
(To
=> Element_Type
, From
=> T
);
6515 -- Ada 2005 (AI-230): In case of components that are anonymous access
6516 -- types the level of accessibility depends on the enclosing type
6519 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
6521 -- Ada 2005 (AI-254)
6524 CD
: constant Node_Id
:=
6525 Access_To_Subprogram_Definition
6526 (Access_Definition
(Component_Def
));
6528 if Present
(CD
) and then Protected_Present
(CD
) then
6530 Replace_Anonymous_Access_To_Protected_Subprogram
(Def
);
6535 -- Constrained array case
6538 -- We might be creating more than one itype with the same Related_Id,
6539 -- e.g. for an array object definition and its initial value. Give
6540 -- them unique suffixes, because GNATprove require distinct types to
6541 -- have different names.
6543 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T', Suffix_Index
=> -1);
6546 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6547 -- Establish Implicit_Base as unconstrained base type
6549 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
6551 Set_Etype
(Implicit_Base
, Implicit_Base
);
6552 Set_Scope
(Implicit_Base
, Current_Scope
);
6553 Set_Has_Delayed_Freeze
(Implicit_Base
);
6554 Set_Default_SSO
(Implicit_Base
);
6556 -- The constrained array type is a subtype of the unconstrained one
6558 Mutate_Ekind
(T
, E_Array_Subtype
);
6559 Reinit_Size_Align
(T
);
6560 Set_Etype
(T
, Implicit_Base
);
6561 Set_Scope
(T
, Current_Scope
);
6562 Set_Is_Constrained
(T
);
6564 First
(Discrete_Subtype_Definitions
(Def
)));
6565 Set_Has_Delayed_Freeze
(T
);
6567 -- Complete setup of implicit base type
6569 pragma Assert
(not Known_Component_Size
(Implicit_Base
));
6570 Set_Component_Type
(Implicit_Base
, Element_Type
);
6571 Set_Finalize_Storage_Only
6573 Finalize_Storage_Only
(Element_Type
));
6574 Set_First_Index
(Implicit_Base
, First_Index
(T
));
6575 Set_Has_Controlled_Component
6577 Has_Controlled_Component
(Element_Type
)
6578 or else Is_Controlled
(Element_Type
));
6579 Set_Packed_Array_Impl_Type
6580 (Implicit_Base
, Empty
);
6582 Propagate_Concurrent_Flags
(Implicit_Base
, Element_Type
);
6584 -- Unconstrained array case
6586 else pragma Assert
(Nkind
(Def
) = N_Unconstrained_Array_Definition
);
6587 Mutate_Ekind
(T
, E_Array_Type
);
6588 Reinit_Size_Align
(T
);
6590 Set_Scope
(T
, Current_Scope
);
6591 pragma Assert
(not Known_Component_Size
(T
));
6592 Set_Is_Constrained
(T
, False);
6593 Set_Is_Fixed_Lower_Bound_Array_Subtype
6595 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
6596 Set_Has_Delayed_Freeze
(T
, True);
6597 Propagate_Concurrent_Flags
(T
, Element_Type
);
6598 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
6601 Is_Controlled
(Element_Type
));
6602 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
6604 Set_Default_SSO
(T
);
6607 -- Common attributes for both cases
6609 Set_Component_Type
(Base_Type
(T
), Element_Type
);
6610 Set_Packed_Array_Impl_Type
(T
, Empty
);
6612 if Aliased_Present
(Component_Definition
(Def
)) then
6613 Set_Has_Aliased_Components
(Etype
(T
));
6615 -- AI12-001: All aliased objects are considered to be specified as
6616 -- independently addressable (RM C.6(8.1/4)).
6618 Set_Has_Independent_Components
(Etype
(T
));
6621 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
6622 -- array type to ensure that objects of this type are initialized.
6624 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(Element_Type
) then
6625 Set_Can_Never_Be_Null
(T
);
6627 if Null_Exclusion_Present
(Component_Definition
(Def
))
6629 -- No need to check itypes because in their case this check was
6630 -- done at their point of creation
6632 and then not Is_Itype
(Element_Type
)
6635 ("`NOT NULL` not allowed (null already excluded)",
6636 Subtype_Indication
(Component_Definition
(Def
)));
6640 Priv
:= Private_Component
(Element_Type
);
6642 if Present
(Priv
) then
6644 -- Check for circular definitions
6646 if Priv
= Any_Type
then
6647 Set_Component_Type
(Etype
(T
), Any_Type
);
6649 -- There is a gap in the visibility of operations on the composite
6650 -- type only if the component type is defined in a different scope.
6652 elsif Scope
(Priv
) = Current_Scope
then
6655 elsif Is_Limited_Type
(Priv
) then
6656 Set_Is_Limited_Composite
(Etype
(T
));
6657 Set_Is_Limited_Composite
(T
);
6659 Set_Is_Private_Composite
(Etype
(T
));
6660 Set_Is_Private_Composite
(T
);
6664 -- A syntax error in the declaration itself may lead to an empty index
6665 -- list, in which case do a minimal patch.
6667 if No
(First_Index
(T
)) then
6668 Error_Msg_N
("missing index definition in array type declaration", T
);
6671 Indexes
: constant List_Id
:=
6672 New_List
(New_Occurrence_Of
(Any_Id
, Sloc
(T
)));
6674 Set_Discrete_Subtype_Definitions
(Def
, Indexes
);
6675 Set_First_Index
(T
, First
(Indexes
));
6680 -- Create a concatenation operator for the new type. Internal array
6681 -- types created for packed entities do not need such, they are
6682 -- compatible with the user-defined type.
6684 if Number_Dimensions
(T
) = 1
6685 and then not Is_Packed_Array_Impl_Type
(T
)
6687 New_Concatenation_Op
(T
);
6690 -- In the case of an unconstrained array the parser has already verified
6691 -- that all the indexes are unconstrained but we still need to make sure
6692 -- that the element type is constrained.
6694 if not Is_Definite_Subtype
(Element_Type
) then
6696 ("unconstrained element type in array declaration",
6697 Subtype_Indication
(Component_Def
));
6699 elsif Is_Abstract_Type
(Element_Type
) then
6701 ("the type of a component cannot be abstract",
6702 Subtype_Indication
(Component_Def
));
6705 -- There may be an invariant declared for the component type, but
6706 -- the construction of the component invariant checking procedure
6707 -- takes place during expansion.
6708 end Array_Type_Declaration
;
6710 ------------------------------------------------------
6711 -- Replace_Anonymous_Access_To_Protected_Subprogram --
6712 ------------------------------------------------------
6714 function Replace_Anonymous_Access_To_Protected_Subprogram
6715 (N
: Node_Id
) return Entity_Id
6717 Loc
: constant Source_Ptr
:= Sloc
(N
);
6719 Curr_Scope
: constant Scope_Stack_Entry
:=
6720 Scope_Stack
.Table
(Scope_Stack
.Last
);
6722 Anon
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
6725 -- Access definition in declaration
6728 -- Object definition or formal definition with an access definition
6731 -- Declaration of anonymous access to subprogram type
6734 -- Original specification in access to subprogram
6739 Set_Is_Internal
(Anon
);
6742 when N_Constrained_Array_Definition
6743 | N_Component_Declaration
6744 | N_Unconstrained_Array_Definition
6746 Comp
:= Component_Definition
(N
);
6747 Acc
:= Access_Definition
(Comp
);
6749 when N_Discriminant_Specification
=>
6750 Comp
:= Discriminant_Type
(N
);
6753 when N_Parameter_Specification
=>
6754 Comp
:= Parameter_Type
(N
);
6757 when N_Access_Function_Definition
=>
6758 Comp
:= Result_Definition
(N
);
6761 when N_Object_Declaration
=>
6762 Comp
:= Object_Definition
(N
);
6765 when N_Function_Specification
=>
6766 Comp
:= Result_Definition
(N
);
6770 raise Program_Error
;
6773 Spec
:= Access_To_Subprogram_Definition
(Acc
);
6776 Make_Full_Type_Declaration
(Loc
,
6777 Defining_Identifier
=> Anon
,
6778 Type_Definition
=> Copy_Separate_Tree
(Spec
));
6780 Mark_Rewrite_Insertion
(Decl
);
6782 -- Insert the new declaration in the nearest enclosing scope. If the
6783 -- parent is a body and N is its return type, the declaration belongs
6784 -- in the enclosing scope. Likewise if N is the type of a parameter.
6788 if Nkind
(N
) = N_Function_Specification
6789 and then Nkind
(P
) = N_Subprogram_Body
6792 elsif Nkind
(N
) = N_Parameter_Specification
6793 and then Nkind
(P
) in N_Subprogram_Specification
6794 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
6796 P
:= Parent
(Parent
(P
));
6799 while Present
(P
) and then not Has_Declarations
(P
) loop
6803 pragma Assert
(Present
(P
));
6805 if Nkind
(P
) = N_Package_Specification
then
6806 Prepend
(Decl
, Visible_Declarations
(P
));
6808 Prepend
(Decl
, Declarations
(P
));
6811 -- Replace the anonymous type with an occurrence of the new declaration.
6812 -- In all cases the rewritten node does not have the null-exclusion
6813 -- attribute because (if present) it was already inherited by the
6814 -- anonymous entity (Anon). Thus, in case of components we do not
6815 -- inherit this attribute.
6817 if Nkind
(N
) = N_Parameter_Specification
then
6818 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6819 Set_Etype
(Defining_Identifier
(N
), Anon
);
6820 Set_Null_Exclusion_Present
(N
, False);
6822 elsif Nkind
(N
) = N_Object_Declaration
then
6823 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6824 Set_Etype
(Defining_Identifier
(N
), Anon
);
6826 elsif Nkind
(N
) = N_Access_Function_Definition
then
6827 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6829 elsif Nkind
(N
) = N_Function_Specification
then
6830 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6831 Set_Etype
(Defining_Unit_Name
(N
), Anon
);
6835 Make_Component_Definition
(Loc
,
6836 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
6839 Mark_Rewrite_Insertion
(Comp
);
6841 if Nkind
(N
) in N_Object_Declaration | N_Access_Function_Definition
6842 or else (Nkind
(Parent
(N
)) = N_Full_Type_Declaration
6843 and then not Is_Type
(Current_Scope
))
6846 -- Declaration can be analyzed in the current scope.
6851 -- Temporarily remove the current scope (record or subprogram) from
6852 -- the stack to add the new declarations to the enclosing scope.
6853 -- The anonymous entity is an Itype with the proper attributes.
6855 Scope_Stack
.Decrement_Last
;
6857 Set_Is_Itype
(Anon
);
6858 Set_Associated_Node_For_Itype
(Anon
, N
);
6859 Scope_Stack
.Append
(Curr_Scope
);
6862 Mutate_Ekind
(Anon
, E_Anonymous_Access_Protected_Subprogram_Type
);
6863 Set_Can_Use_Internal_Rep
(Anon
, not Always_Compatible_Rep_On_Target
);
6865 end Replace_Anonymous_Access_To_Protected_Subprogram
;
6867 -------------------------------------
6868 -- Build_Access_Subprogram_Wrapper --
6869 -------------------------------------
6871 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
) is
6872 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
6873 Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
6874 Type_Def
: constant Node_Id
:= Type_Definition
(Decl
);
6875 Specs
: constant List_Id
:=
6876 Parameter_Specifications
(Type_Def
);
6877 Profile
: constant List_Id
:= New_List
;
6878 Subp
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6880 Contracts
: constant List_Id
:= New_List
;
6886 procedure Replace_Type_Name
(Expr
: Node_Id
);
6887 -- In the expressions for contract aspects, replace occurrences of the
6888 -- access type with the name of the subprogram entity, as needed, e.g.
6889 -- for 'Result. Aspects that are not contracts, e.g. Size or Alignment)
6890 -- remain on the original access type declaration. What about expanded
6891 -- names denoting formals, whose prefix in source is the type name ???
6893 -----------------------
6894 -- Replace_Type_Name --
6895 -----------------------
6897 procedure Replace_Type_Name
(Expr
: Node_Id
) is
6898 function Process
(N
: Node_Id
) return Traverse_Result
;
6899 function Process
(N
: Node_Id
) return Traverse_Result
is
6901 if Nkind
(N
) = N_Attribute_Reference
6902 and then Is_Entity_Name
(Prefix
(N
))
6903 and then Chars
(Prefix
(N
)) = Chars
(Id
)
6905 Set_Prefix
(N
, Make_Identifier
(Sloc
(N
), Chars
(Subp
)));
6911 procedure Traverse
is new Traverse_Proc
(Process
);
6914 end Replace_Type_Name
;
6917 if Ekind
(Id
) in E_Access_Subprogram_Type
6918 | E_Access_Protected_Subprogram_Type
6919 | E_Anonymous_Access_Protected_Subprogram_Type
6920 | E_Anonymous_Access_Subprogram_Type
6926 ("illegal pre/postcondition on access type", Decl
);
6935 Asp
:= First
(Aspect_Specifications
(Decl
));
6936 while Present
(Asp
) loop
6937 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(Asp
)));
6938 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Post
then
6939 Append
(New_Copy_Tree
(Asp
), Contracts
);
6940 Replace_Type_Name
(Expression
(Last
(Contracts
)));
6946 -- If there are no contract aspects, no need for a wrapper.
6948 if Is_Empty_List
(Contracts
) then
6952 Form_P
:= First
(Specs
);
6954 while Present
(Form_P
) loop
6955 New_P
:= New_Copy_Tree
(Form_P
);
6956 Set_Defining_Identifier
(New_P
,
6957 Make_Defining_Identifier
6958 (Loc
, Chars
(Defining_Identifier
(Form_P
))));
6959 Append
(New_P
, Profile
);
6963 -- Add to parameter specifications the access parameter that is passed
6964 -- in from an indirect call.
6967 Make_Parameter_Specification
(Loc
,
6968 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6969 Parameter_Type
=> New_Occurrence_Of
(Id
, Loc
)),
6972 if Nkind
(Type_Def
) = N_Access_Procedure_Definition
then
6974 Make_Procedure_Specification
(Loc
,
6975 Defining_Unit_Name
=> Subp
,
6976 Parameter_Specifications
=> Profile
);
6977 Mutate_Ekind
(Subp
, E_Procedure
);
6980 Make_Function_Specification
(Loc
,
6981 Defining_Unit_Name
=> Subp
,
6982 Parameter_Specifications
=> Profile
,
6983 Result_Definition
=>
6985 (Result_Definition
(Type_Definition
(Decl
))));
6986 Mutate_Ekind
(Subp
, E_Function
);
6990 Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
6991 Set_Aspect_Specifications
(New_Decl
, Contracts
);
6992 Set_Is_Wrapper
(Subp
);
6994 -- The wrapper is declared in the freezing actions to facilitate its
6995 -- identification and thus avoid handling it as a primitive operation
6996 -- of a tagged type (see Is_Access_To_Subprogram_Wrapper); otherwise it
6997 -- may be handled as a dispatching operation and erroneously registered
6998 -- in a dispatch table.
7000 Append_Freeze_Action
(Id
, New_Decl
);
7002 Set_Access_Subprogram_Wrapper
(Designated_Type
(Id
), Subp
);
7003 Build_Access_Subprogram_Wrapper_Body
(Decl
, New_Decl
);
7004 end Build_Access_Subprogram_Wrapper
;
7006 -------------------------------
7007 -- Build_Derived_Access_Type --
7008 -------------------------------
7010 procedure Build_Derived_Access_Type
7012 Parent_Type
: Entity_Id
;
7013 Derived_Type
: Entity_Id
)
7015 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
7017 Desig_Type
: Entity_Id
;
7019 Discr_Con_Elist
: Elist_Id
;
7020 Discr_Con_El
: Elmt_Id
;
7024 -- Set the designated type so it is available in case this is an access
7025 -- to a self-referential type, e.g. a standard list type with a next
7026 -- pointer. Will be reset after subtype is built.
7028 Set_Directly_Designated_Type
7029 (Derived_Type
, Designated_Type
(Parent_Type
));
7031 Subt
:= Process_Subtype
(S
, N
);
7033 if Nkind
(S
) /= N_Subtype_Indication
7034 and then Subt
/= Base_Type
(Subt
)
7036 Mutate_Ekind
(Derived_Type
, E_Access_Subtype
);
7039 if Ekind
(Derived_Type
) = E_Access_Subtype
then
7041 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7042 Ibase
: constant Entity_Id
:=
7043 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
7044 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
7045 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
7046 Svg_Prev_E
: constant Entity_Id
:= Prev_Entity
(Ibase
);
7049 Copy_Node
(Pbase
, Ibase
);
7051 -- Restore Itype status after Copy_Node
7053 Set_Is_Itype
(Ibase
);
7054 Set_Associated_Node_For_Itype
(Ibase
, N
);
7056 Set_Chars
(Ibase
, Svg_Chars
);
7057 Set_Prev_Entity
(Ibase
, Svg_Prev_E
);
7058 Set_Next_Entity
(Ibase
, Svg_Next_E
);
7059 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
7060 Set_Scope
(Ibase
, Scope
(Derived_Type
));
7061 Set_Freeze_Node
(Ibase
, Empty
);
7062 Set_Is_Frozen
(Ibase
, False);
7063 Set_Comes_From_Source
(Ibase
, False);
7064 Set_Is_First_Subtype
(Ibase
, False);
7066 Set_Etype
(Ibase
, Pbase
);
7067 Set_Etype
(Derived_Type
, Ibase
);
7071 Set_Directly_Designated_Type
7072 (Derived_Type
, Designated_Type
(Subt
));
7074 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
7075 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
7076 Set_Size_Info
(Derived_Type
, Parent_Type
);
7077 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
7078 Set_Depends_On_Private
(Derived_Type
,
7079 Has_Private_Component
(Derived_Type
));
7080 Conditional_Delay
(Derived_Type
, Subt
);
7082 if Is_Access_Subprogram_Type
(Derived_Type
)
7083 and then Is_Base_Type
(Derived_Type
)
7085 Set_Can_Use_Internal_Rep
7086 (Derived_Type
, Can_Use_Internal_Rep
(Parent_Type
));
7089 -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
7090 -- that it is not redundant.
7092 if Null_Exclusion_Present
(Type_Definition
(N
)) then
7093 Set_Can_Never_Be_Null
(Derived_Type
);
7095 elsif Can_Never_Be_Null
(Parent_Type
) then
7096 Set_Can_Never_Be_Null
(Derived_Type
);
7099 -- Note: we do not copy the Storage_Size_Variable, since we always go to
7100 -- the root type for this information.
7102 -- Apply range checks to discriminants for derived record case
7103 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
7105 Desig_Type
:= Designated_Type
(Derived_Type
);
7107 if Is_Composite_Type
(Desig_Type
)
7108 and then not Is_Array_Type
(Desig_Type
)
7109 and then Has_Discriminants
(Desig_Type
)
7110 and then Base_Type
(Desig_Type
) /= Desig_Type
7112 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
7113 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
7115 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
7116 while Present
(Discr_Con_El
) loop
7117 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
7118 Next_Elmt
(Discr_Con_El
);
7119 Next_Discriminant
(Discr
);
7122 end Build_Derived_Access_Type
;
7124 ------------------------------
7125 -- Build_Derived_Array_Type --
7126 ------------------------------
7128 procedure Build_Derived_Array_Type
7130 Parent_Type
: Entity_Id
;
7131 Derived_Type
: Entity_Id
)
7133 Loc
: constant Source_Ptr
:= Sloc
(N
);
7134 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7135 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7136 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7137 Implicit_Base
: Entity_Id
:= Empty
;
7138 New_Indic
: Node_Id
;
7140 procedure Make_Implicit_Base
;
7141 -- If the parent subtype is constrained, the derived type is a subtype
7142 -- of an implicit base type derived from the parent base.
7144 ------------------------
7145 -- Make_Implicit_Base --
7146 ------------------------
7148 procedure Make_Implicit_Base
is
7151 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7153 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7154 Set_Etype
(Implicit_Base
, Parent_Base
);
7156 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
7157 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
7159 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
7160 end Make_Implicit_Base
;
7162 -- Start of processing for Build_Derived_Array_Type
7165 if not Is_Constrained
(Parent_Type
) then
7166 if Nkind
(Indic
) /= N_Subtype_Indication
then
7167 Mutate_Ekind
(Derived_Type
, E_Array_Type
);
7169 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7170 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
7172 Set_Has_Delayed_Freeze
(Derived_Type
, True);
7176 Set_Etype
(Derived_Type
, Implicit_Base
);
7179 Make_Subtype_Declaration
(Loc
,
7180 Defining_Identifier
=> Derived_Type
,
7181 Subtype_Indication
=>
7182 Make_Subtype_Indication
(Loc
,
7183 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7184 Constraint
=> Constraint
(Indic
)));
7186 Rewrite
(N
, New_Indic
);
7188 -- Keep the aspects from the original node
7190 Move_Aspects
(Original_Node
(N
), N
);
7196 if Nkind
(Indic
) /= N_Subtype_Indication
then
7199 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
7200 Set_Etype
(Derived_Type
, Implicit_Base
);
7201 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7204 Error_Msg_N
("illegal constraint on constrained type", Indic
);
7208 -- If parent type is not a derived type itself, and is declared in
7209 -- closed scope (e.g. a subprogram), then we must explicitly introduce
7210 -- the new type's concatenation operator since Derive_Subprograms
7211 -- will not inherit the parent's operator. If the parent type is
7212 -- unconstrained, the operator is of the unconstrained base type.
7214 if Number_Dimensions
(Parent_Type
) = 1
7215 and then not Is_Limited_Type
(Parent_Type
)
7216 and then not Is_Derived_Type
(Parent_Type
)
7217 and then not Is_Package_Or_Generic_Package
7218 (Scope
(Base_Type
(Parent_Type
)))
7220 if not Is_Constrained
(Parent_Type
)
7221 and then Is_Constrained
(Derived_Type
)
7223 New_Concatenation_Op
(Implicit_Base
);
7225 New_Concatenation_Op
(Derived_Type
);
7228 end Build_Derived_Array_Type
;
7230 -----------------------------------
7231 -- Build_Derived_Concurrent_Type --
7232 -----------------------------------
7234 procedure Build_Derived_Concurrent_Type
7236 Parent_Type
: Entity_Id
;
7237 Derived_Type
: Entity_Id
)
7239 Loc
: constant Source_Ptr
:= Sloc
(N
);
7240 Def
: constant Node_Id
:= Type_Definition
(N
);
7241 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7243 Corr_Record
: constant Entity_Id
:= Make_Temporary
(Loc
, 'C');
7244 Corr_Decl
: Node_Id
:= Empty
;
7245 Corr_Decl_Needed
: Boolean;
7246 -- If the derived type has fewer discriminants than its parent, the
7247 -- corresponding record is also a derived type, in order to account for
7248 -- the bound discriminants. We create a full type declaration for it in
7251 Constraint_Present
: constant Boolean :=
7252 Nkind
(Indic
) = N_Subtype_Indication
;
7254 D_Constraint
: Node_Id
;
7255 New_Constraint
: Elist_Id
:= No_Elist
;
7256 Old_Disc
: Entity_Id
;
7257 New_Disc
: Entity_Id
;
7261 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
7262 Corr_Decl_Needed
:= False;
7265 if Present
(Discriminant_Specifications
(N
))
7266 and then Constraint_Present
7268 Old_Disc
:= First_Discriminant
(Parent_Type
);
7269 New_Disc
:= First
(Discriminant_Specifications
(N
));
7270 while Present
(New_Disc
) and then Present
(Old_Disc
) loop
7271 Next_Discriminant
(Old_Disc
);
7276 if Present
(Old_Disc
) and then Expander_Active
then
7278 -- The new type has fewer discriminants, so we need to create a new
7279 -- corresponding record, which is derived from the corresponding
7280 -- record of the parent, and has a stored constraint that captures
7281 -- the values of the discriminant constraints. The corresponding
7282 -- record is needed only if expander is active and code generation is
7285 -- The type declaration for the derived corresponding record has the
7286 -- same discriminant part and constraints as the current declaration.
7287 -- Copy the unanalyzed tree to build declaration.
7289 Corr_Decl_Needed
:= True;
7290 New_N
:= Copy_Separate_Tree
(N
);
7293 Make_Full_Type_Declaration
(Loc
,
7294 Defining_Identifier
=> Corr_Record
,
7295 Discriminant_Specifications
=>
7296 Discriminant_Specifications
(New_N
),
7298 Make_Derived_Type_Definition
(Loc
,
7299 Subtype_Indication
=>
7300 Make_Subtype_Indication
(Loc
,
7303 (Corresponding_Record_Type
(Parent_Type
), Loc
),
7306 (Subtype_Indication
(Type_Definition
(New_N
))))));
7309 -- Copy Storage_Size and Relative_Deadline variables if task case
7311 if Is_Task_Type
(Parent_Type
) then
7312 Set_Storage_Size_Variable
(Derived_Type
,
7313 Storage_Size_Variable
(Parent_Type
));
7314 Set_Relative_Deadline_Variable
(Derived_Type
,
7315 Relative_Deadline_Variable
(Parent_Type
));
7318 if Present
(Discriminant_Specifications
(N
)) then
7319 Push_Scope
(Derived_Type
);
7320 Check_Or_Process_Discriminants
(N
, Derived_Type
);
7322 if Constraint_Present
then
7324 Expand_To_Stored_Constraint
7326 Build_Discriminant_Constraints
7327 (Parent_Type
, Indic
, True));
7332 elsif Constraint_Present
then
7334 -- Build an unconstrained derived type and rewrite the derived type
7335 -- as a subtype of this new base type.
7338 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7339 New_Base
: Entity_Id
;
7341 New_Indic
: Node_Id
;
7345 Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
7348 Make_Full_Type_Declaration
(Loc
,
7349 Defining_Identifier
=> New_Base
,
7351 Make_Derived_Type_Definition
(Loc
,
7352 Abstract_Present
=> Abstract_Present
(Def
),
7353 Limited_Present
=> Limited_Present
(Def
),
7354 Subtype_Indication
=>
7355 New_Occurrence_Of
(Parent_Base
, Loc
)));
7357 Mark_Rewrite_Insertion
(New_Decl
);
7358 Insert_Before
(N
, New_Decl
);
7362 Make_Subtype_Indication
(Loc
,
7363 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
7364 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
7367 Make_Subtype_Declaration
(Loc
,
7368 Defining_Identifier
=> Derived_Type
,
7369 Subtype_Indication
=> New_Indic
));
7371 -- Keep the aspects from the original node
7373 Move_Aspects
(Original_Node
(N
), N
);
7380 -- By default, operations and private data are inherited from parent.
7381 -- However, in the presence of bound discriminants, a new corresponding
7382 -- record will be created, see below.
7384 Set_Has_Discriminants
7385 (Derived_Type
, Has_Discriminants
(Parent_Type
));
7386 Set_Corresponding_Record_Type
7387 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
7389 -- Is_Constrained is set according the parent subtype, but is set to
7390 -- False if the derived type is declared with new discriminants.
7394 (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
7395 and then No
(Discriminant_Specifications
(N
)));
7397 if Constraint_Present
then
7398 if not Has_Discriminants
(Parent_Type
) then
7399 Error_Msg_N
("untagged parent must have discriminants", N
);
7401 elsif Present
(Discriminant_Specifications
(N
)) then
7403 -- Verify that new discriminants are used to constrain old ones
7405 D_Constraint
:= First
(Constraints
(Constraint
(Indic
)));
7407 Old_Disc
:= First_Discriminant
(Parent_Type
);
7409 while Present
(D_Constraint
) loop
7410 if Nkind
(D_Constraint
) /= N_Discriminant_Association
then
7412 -- Positional constraint. If it is a reference to a new
7413 -- discriminant, it constrains the corresponding old one.
7415 if Nkind
(D_Constraint
) = N_Identifier
then
7416 New_Disc
:= First_Discriminant
(Derived_Type
);
7417 while Present
(New_Disc
) loop
7418 exit when Chars
(New_Disc
) = Chars
(D_Constraint
);
7419 Next_Discriminant
(New_Disc
);
7422 if Present
(New_Disc
) then
7423 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
7427 Next_Discriminant
(Old_Disc
);
7429 -- if this is a named constraint, search by name for the old
7430 -- discriminants constrained by the new one.
7432 elsif Nkind
(Expression
(D_Constraint
)) = N_Identifier
then
7434 -- Find new discriminant with that name
7436 New_Disc
:= First_Discriminant
(Derived_Type
);
7437 while Present
(New_Disc
) loop
7439 Chars
(New_Disc
) = Chars
(Expression
(D_Constraint
));
7440 Next_Discriminant
(New_Disc
);
7443 if Present
(New_Disc
) then
7445 -- Verify that new discriminant renames some discriminant
7446 -- of the parent type, and associate the new discriminant
7447 -- with one or more old ones that it renames.
7453 Selector
:= First
(Selector_Names
(D_Constraint
));
7454 while Present
(Selector
) loop
7455 Old_Disc
:= First_Discriminant
(Parent_Type
);
7456 while Present
(Old_Disc
) loop
7457 exit when Chars
(Old_Disc
) = Chars
(Selector
);
7458 Next_Discriminant
(Old_Disc
);
7461 if Present
(Old_Disc
) then
7462 Set_Corresponding_Discriminant
7463 (New_Disc
, Old_Disc
);
7472 Next
(D_Constraint
);
7475 New_Disc
:= First_Discriminant
(Derived_Type
);
7476 while Present
(New_Disc
) loop
7477 if No
(Corresponding_Discriminant
(New_Disc
)) then
7479 ("new discriminant& must constrain old one", N
, New_Disc
);
7481 -- If a new discriminant is used in the constraint, then its
7482 -- subtype must be statically compatible with the subtype of
7483 -- the parent discriminant (RM 3.7(15)).
7486 Check_Constraining_Discriminant
7487 (New_Disc
, Corresponding_Discriminant
(New_Disc
));
7490 Next_Discriminant
(New_Disc
);
7494 elsif Present
(Discriminant_Specifications
(N
)) then
7496 ("missing discriminant constraint in untagged derivation", N
);
7499 -- The entity chain of the derived type includes the new discriminants
7500 -- but shares operations with the parent.
7502 if Present
(Discriminant_Specifications
(N
)) then
7503 Old_Disc
:= First_Discriminant
(Parent_Type
);
7504 while Present
(Old_Disc
) loop
7505 if No
(Next_Entity
(Old_Disc
))
7506 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
7509 (Last_Entity
(Derived_Type
), Next_Entity
(Old_Disc
));
7513 Next_Discriminant
(Old_Disc
);
7517 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
7518 if Has_Discriminants
(Parent_Type
) then
7519 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7520 Set_Discriminant_Constraint
(
7521 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
7525 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
7527 Set_Has_Completion
(Derived_Type
);
7529 if Corr_Decl_Needed
then
7530 Set_Stored_Constraint
(Derived_Type
, New_Constraint
);
7531 Insert_After
(N
, Corr_Decl
);
7532 Analyze
(Corr_Decl
);
7533 Set_Corresponding_Record_Type
(Derived_Type
, Corr_Record
);
7535 end Build_Derived_Concurrent_Type
;
7537 ------------------------------------
7538 -- Build_Derived_Enumeration_Type --
7539 ------------------------------------
7541 procedure Build_Derived_Enumeration_Type
7543 Parent_Type
: Entity_Id
;
7544 Derived_Type
: Entity_Id
)
7546 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean;
7547 -- When the type declaration includes a constraint, we generate
7548 -- a subtype declaration of an anonymous base type, with the constraint
7549 -- given in the original type declaration. Conceptually, the bounds
7550 -- are converted to the new base type, and this conversion freezes
7551 -- (prematurely) that base type, when the bounds are simply literals.
7552 -- As a result, a representation clause for the derived type is then
7553 -- rejected or ignored. This procedure recognizes the simple case of
7554 -- literal bounds, which allows us to indicate that the conversions
7555 -- are not freeze points, and the subsequent representation clause
7557 -- A similar approach might be used to resolve the long-standing
7558 -- problem of premature freezing of derived numeric types ???
7560 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean is
7562 return Nkind
(B
) = N_Type_Conversion
7563 and then Is_Entity_Name
(Expression
(B
))
7564 and then Ekind
(Entity
(Expression
(B
))) = E_Enumeration_Literal
;
7565 end Bound_Belongs_To_Type
;
7567 Loc
: constant Source_Ptr
:= Sloc
(N
);
7568 Def
: constant Node_Id
:= Type_Definition
(N
);
7569 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7570 Implicit_Base
: Entity_Id
;
7571 Literal
: Entity_Id
;
7572 New_Lit
: Entity_Id
;
7573 Literals_List
: List_Id
;
7574 Type_Decl
: Node_Id
;
7576 Rang_Expr
: Node_Id
;
7579 -- Since types Standard.Character and Standard.[Wide_]Wide_Character do
7580 -- not have explicit literals lists we need to process types derived
7581 -- from them specially. This is handled by Derived_Standard_Character.
7582 -- If the parent type is a generic type, there are no literals either,
7583 -- and we construct the same skeletal representation as for the generic
7586 if Is_Standard_Character_Type
(Parent_Type
) then
7587 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
7589 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
7595 if Nkind
(Indic
) /= N_Subtype_Indication
then
7597 Make_Attribute_Reference
(Loc
,
7598 Attribute_Name
=> Name_First
,
7599 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7600 Set_Etype
(Lo
, Derived_Type
);
7603 Make_Attribute_Reference
(Loc
,
7604 Attribute_Name
=> Name_Last
,
7605 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7606 Set_Etype
(Hi
, Derived_Type
);
7608 Set_Scalar_Range
(Derived_Type
,
7614 -- Analyze subtype indication and verify compatibility
7615 -- with parent type.
7617 if Base_Type
(Process_Subtype
(Indic
, N
)) /=
7618 Base_Type
(Parent_Type
)
7621 ("illegal constraint for formal discrete type", N
);
7627 -- If a constraint is present, analyze the bounds to catch
7628 -- premature usage of the derived literals.
7630 if Nkind
(Indic
) = N_Subtype_Indication
7631 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
7633 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
7634 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
7637 -- Create an implicit base type for the derived type even if there
7638 -- is no constraint attached to it, since this seems closer to the
7639 -- Ada semantics. Use an Itype like for the implicit base type of
7640 -- other kinds of derived type, but build a full type declaration
7641 -- for it so as to analyze the new literals properly. Then build a
7642 -- subtype declaration tree which applies the constraint (if any)
7643 -- and have it replace the derived type declaration.
7645 Literal
:= First_Literal
(Parent_Type
);
7646 Literals_List
:= New_List
;
7647 while Present
(Literal
)
7648 and then Ekind
(Literal
) = E_Enumeration_Literal
7650 -- Literals of the derived type have the same representation as
7651 -- those of the parent type, but this representation can be
7652 -- overridden by an explicit representation clause. Indicate
7653 -- that there is no explicit representation given yet. These
7654 -- derived literals are implicit operations of the new type,
7655 -- and can be overridden by explicit ones.
7657 if Nkind
(Literal
) = N_Defining_Character_Literal
then
7659 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
7661 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
7664 Mutate_Ekind
(New_Lit
, E_Enumeration_Literal
);
7665 Set_Is_Not_Self_Hidden
(New_Lit
);
7666 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
7667 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
7668 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
7669 Set_Alias
(New_Lit
, Literal
);
7670 Set_Is_Known_Valid
(New_Lit
, True);
7672 Append
(New_Lit
, Literals_List
);
7673 Next_Literal
(Literal
);
7677 Create_Itype
(E_Enumeration_Type
, N
, Derived_Type
, 'B');
7679 -- Indicate the proper nature of the derived type. This must be done
7680 -- before analysis of the literals, to recognize cases when a literal
7681 -- may be hidden by a previous explicit function definition (cf.
7684 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
7685 Set_Etype
(Derived_Type
, Implicit_Base
);
7688 Make_Full_Type_Declaration
(Loc
,
7689 Defining_Identifier
=> Implicit_Base
,
7691 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
7693 -- Do not insert the declarationn, just analyze it in the context
7695 Set_Parent
(Type_Decl
, Parent
(N
));
7696 Analyze
(Type_Decl
);
7698 -- The anonymous base now has a full declaration, but this base
7699 -- is not a first subtype.
7701 Set_Is_First_Subtype
(Implicit_Base
, False);
7703 -- After the implicit base is analyzed its Etype needs to be changed
7704 -- to reflect the fact that it is derived from the parent type which
7705 -- was ignored during analysis. We also set the size at this point.
7707 Set_Etype
(Implicit_Base
, Parent_Type
);
7709 Set_Size_Info
(Implicit_Base
, Parent_Type
);
7710 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
7711 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
7713 -- Copy other flags from parent type
7715 Set_Has_Non_Standard_Rep
7716 (Implicit_Base
, Has_Non_Standard_Rep
7718 Set_Has_Pragma_Ordered
7719 (Implicit_Base
, Has_Pragma_Ordered
7721 Set_Has_Delayed_Freeze
(Implicit_Base
);
7723 -- Process the subtype indication including a validation check on the
7724 -- constraint, if any. If a constraint is given, its bounds must be
7725 -- implicitly converted to the new type.
7727 if Nkind
(Indic
) = N_Subtype_Indication
then
7729 R
: constant Node_Id
:=
7730 Range_Expression
(Constraint
(Indic
));
7733 if Nkind
(R
) = N_Range
then
7734 Hi
:= Build_Scalar_Bound
7735 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
7736 Lo
:= Build_Scalar_Bound
7737 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
7740 -- Constraint is a Range attribute. Replace with explicit
7741 -- mention of the bounds of the prefix, which must be a
7744 Analyze
(Prefix
(R
));
7746 Convert_To
(Implicit_Base
,
7747 Make_Attribute_Reference
(Loc
,
7748 Attribute_Name
=> Name_Last
,
7750 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7753 Convert_To
(Implicit_Base
,
7754 Make_Attribute_Reference
(Loc
,
7755 Attribute_Name
=> Name_First
,
7757 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7764 (Type_High_Bound
(Parent_Type
),
7765 Parent_Type
, Implicit_Base
);
7768 (Type_Low_Bound
(Parent_Type
),
7769 Parent_Type
, Implicit_Base
);
7777 -- If we constructed a default range for the case where no range
7778 -- was given, then the expressions in the range must not freeze
7779 -- since they do not correspond to expressions in the source.
7780 -- However, if the type inherits predicates the expressions will
7781 -- be elaborated earlier and must freeze.
7783 if (Nkind
(Indic
) /= N_Subtype_Indication
7785 (Bound_Belongs_To_Type
(Lo
) and then Bound_Belongs_To_Type
(Hi
)))
7786 and then not Has_Predicates
(Derived_Type
)
7788 Set_Must_Not_Freeze
(Lo
);
7789 Set_Must_Not_Freeze
(Hi
);
7790 Set_Must_Not_Freeze
(Rang_Expr
);
7794 Make_Subtype_Declaration
(Loc
,
7795 Defining_Identifier
=> Derived_Type
,
7796 Subtype_Indication
=>
7797 Make_Subtype_Indication
(Loc
,
7798 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7800 Make_Range_Constraint
(Loc
,
7801 Range_Expression
=> Rang_Expr
))));
7803 -- Keep the aspects from the orignal node
7805 Move_Aspects
(Original_Node
(N
), N
);
7809 -- Propagate the aspects from the original type declaration to the
7810 -- declaration of the implicit base.
7812 Copy_Aspects
(From
=> N
, To
=> Type_Decl
);
7814 -- Apply a range check. Since this range expression doesn't have an
7815 -- Etype, we have to specifically pass the Source_Typ parameter. Is
7818 if Nkind
(Indic
) = N_Subtype_Indication
then
7820 (Range_Expression
(Constraint
(Indic
)), Parent_Type
,
7821 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
7824 end Build_Derived_Enumeration_Type
;
7826 --------------------------------
7827 -- Build_Derived_Numeric_Type --
7828 --------------------------------
7830 procedure Build_Derived_Numeric_Type
7832 Parent_Type
: Entity_Id
;
7833 Derived_Type
: Entity_Id
)
7835 Loc
: constant Source_Ptr
:= Sloc
(N
);
7836 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7837 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7838 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7839 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
7840 N_Subtype_Indication
;
7841 Implicit_Base
: Entity_Id
;
7847 -- Process the subtype indication including a validation check on
7848 -- the constraint if any.
7850 Discard_Node
(Process_Subtype
(Indic
, N
));
7852 -- Introduce an implicit base type for the derived type even if there
7853 -- is no constraint attached to it, since this seems closer to the Ada
7857 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7859 Set_Etype
(Implicit_Base
, Parent_Base
);
7860 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7861 Set_Size_Info
(Implicit_Base
, Parent_Base
);
7862 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
7863 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
7864 Set_Is_Known_Valid
(Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7865 Set_Is_Volatile
(Implicit_Base
, Is_Volatile
(Parent_Base
));
7867 -- Set RM Size for discrete type or decimal fixed-point type
7868 -- Ordinary fixed-point is excluded, why???
7870 if Is_Discrete_Type
(Parent_Base
)
7871 or else Is_Decimal_Fixed_Point_Type
(Parent_Base
)
7873 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
7876 Set_Has_Delayed_Freeze
(Implicit_Base
);
7878 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
7879 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
7881 Set_Scalar_Range
(Implicit_Base
,
7886 if Has_Infinities
(Parent_Base
) then
7887 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
7890 -- The Derived_Type, which is the entity of the declaration, is a
7891 -- subtype of the implicit base. Its Ekind is a subtype, even in the
7892 -- absence of an explicit constraint.
7894 Set_Etype
(Derived_Type
, Implicit_Base
);
7896 -- If we did not have a constraint, then the Ekind is set from the
7897 -- parent type (otherwise Process_Subtype has set the bounds)
7899 if No_Constraint
then
7900 Mutate_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
7903 -- If we did not have a range constraint, then set the range from the
7904 -- parent type. Otherwise, the Process_Subtype call has set the bounds.
7906 if No_Constraint
or else not Has_Range_Constraint
(Indic
) then
7907 Set_Scalar_Range
(Derived_Type
,
7909 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
7910 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
7911 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7913 if Has_Infinities
(Parent_Type
) then
7914 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
7917 Set_Is_Known_Valid
(Derived_Type
, Is_Known_Valid
(Parent_Type
));
7920 Set_Is_Descendant_Of_Address
(Derived_Type
,
7921 Is_Descendant_Of_Address
(Parent_Type
));
7922 Set_Is_Descendant_Of_Address
(Implicit_Base
,
7923 Is_Descendant_Of_Address
(Parent_Type
));
7925 -- Set remaining type-specific fields, depending on numeric type
7927 if Is_Modular_Integer_Type
(Parent_Type
) then
7928 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
7930 Set_Non_Binary_Modulus
7931 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
7934 (Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7936 elsif Is_Floating_Point_Type
(Parent_Type
) then
7938 -- Digits of base type is always copied from the digits value of
7939 -- the parent base type, but the digits of the derived type will
7940 -- already have been set if there was a constraint present.
7942 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7943 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Parent_Base
));
7945 if No_Constraint
then
7946 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
7949 elsif Is_Fixed_Point_Type
(Parent_Type
) then
7951 -- Small of base type and derived type are always copied from the
7952 -- parent base type, since smalls never change. The delta of the
7953 -- base type is also copied from the parent base type. However the
7954 -- delta of the derived type will have been set already if a
7955 -- constraint was present.
7957 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
7958 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
7959 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
7961 if No_Constraint
then
7962 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
7965 -- The scale and machine radix in the decimal case are always
7966 -- copied from the parent base type.
7968 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
7969 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
7970 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
7972 Set_Machine_Radix_10
7973 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
7974 Set_Machine_Radix_10
7975 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
7977 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7979 if No_Constraint
then
7980 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
7983 -- the analysis of the subtype_indication sets the
7984 -- digits value of the derived type.
7991 if Is_Integer_Type
(Parent_Type
) then
7992 Set_Has_Shift_Operator
7993 (Implicit_Base
, Has_Shift_Operator
(Parent_Type
));
7996 -- The type of the bounds is that of the parent type, and they
7997 -- must be converted to the derived type.
7999 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
8000 end Build_Derived_Numeric_Type
;
8002 --------------------------------
8003 -- Build_Derived_Private_Type --
8004 --------------------------------
8006 procedure Build_Derived_Private_Type
8008 Parent_Type
: Entity_Id
;
8009 Derived_Type
: Entity_Id
;
8010 Is_Completion
: Boolean;
8011 Derive_Subps
: Boolean := True)
8013 Loc
: constant Source_Ptr
:= Sloc
(N
);
8014 Par_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
8015 Par_Scope
: constant Entity_Id
:= Scope
(Par_Base
);
8016 Full_N
: constant Node_Id
:= New_Copy_Tree
(N
);
8017 Full_Der
: Entity_Id
:= New_Copy
(Derived_Type
);
8020 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
;
8021 -- Return the Full_View or Underlying_Full_View of Typ, whichever is
8022 -- present (they cannot be both present for the same type), or Empty.
8024 procedure Build_Full_Derivation
;
8025 -- Build full derivation, i.e. derive from the full view
8027 procedure Copy_And_Build
;
8028 -- Copy derived type declaration, replace parent with its full view,
8029 -- and build derivation
8031 -------------------------
8032 -- Available_Full_View --
8033 -------------------------
8035 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
is
8037 if Present
(Full_View
(Typ
)) then
8038 return Full_View
(Typ
);
8040 elsif Present
(Underlying_Full_View
(Typ
)) then
8042 -- We should be called on a type with an underlying full view
8043 -- only by means of the recursive call made in Copy_And_Build
8044 -- through the first call to Build_Derived_Type, or else if
8045 -- the parent scope is being analyzed because we are deriving
8048 pragma Assert
(Is_Completion
or else In_Private_Part
(Par_Scope
));
8050 return Underlying_Full_View
(Typ
);
8055 end Available_Full_View
;
8057 ---------------------------
8058 -- Build_Full_Derivation --
8059 ---------------------------
8061 procedure Build_Full_Derivation
is
8063 -- If parent scope is not open, install the declarations
8065 if not In_Open_Scopes
(Par_Scope
) then
8066 Install_Private_Declarations
(Par_Scope
);
8067 Install_Visible_Declarations
(Par_Scope
);
8069 Uninstall_Declarations
(Par_Scope
);
8071 -- If parent scope is open and in another unit, and parent has a
8072 -- completion, then the derivation is taking place in the visible
8073 -- part of a child unit. In that case retrieve the full view of
8074 -- the parent momentarily.
8076 elsif not In_Same_Source_Unit
(N
, Parent_Type
)
8077 and then Present
(Full_View
(Parent_Type
))
8079 Full_P
:= Full_View
(Parent_Type
);
8080 Exchange_Declarations
(Parent_Type
);
8082 Exchange_Declarations
(Full_P
);
8084 -- Otherwise it is a local derivation
8089 end Build_Full_Derivation
;
8091 --------------------
8092 -- Copy_And_Build --
8093 --------------------
8095 procedure Copy_And_Build
is
8096 Full_Parent
: Entity_Id
:= Parent_Type
;
8099 -- If the parent is itself derived from another private type,
8100 -- installing the private declarations has not affected its
8101 -- privacy status, so use its own full view explicitly.
8103 if Is_Private_Type
(Full_Parent
)
8104 and then Present
(Full_View
(Full_Parent
))
8106 Full_Parent
:= Full_View
(Full_Parent
);
8109 -- If the full view is itself derived from another private type
8110 -- and has got an underlying full view, and this is done for a
8111 -- completion, i.e. to build the underlying full view of the type,
8112 -- then use this underlying full view. We cannot do that if this
8113 -- is not a completion, i.e. to build the full view of the type,
8114 -- because this would break the privacy of the parent type, except
8115 -- if the parent scope is being analyzed because we are deriving a
8118 if Is_Private_Type
(Full_Parent
)
8119 and then Present
(Underlying_Full_View
(Full_Parent
))
8120 and then (Is_Completion
or else In_Private_Part
(Par_Scope
))
8122 Full_Parent
:= Underlying_Full_View
(Full_Parent
);
8125 -- For private, record, concurrent, access and almost all enumeration
8126 -- types, the derivation from the full view requires a fully-fledged
8127 -- declaration. In the other cases, just use an itype.
8129 if Is_Private_Type
(Full_Parent
)
8130 or else Is_Record_Type
(Full_Parent
)
8131 or else Is_Concurrent_Type
(Full_Parent
)
8132 or else Is_Access_Type
(Full_Parent
)
8134 (Is_Enumeration_Type
(Full_Parent
)
8135 and then not Is_Standard_Character_Type
(Full_Parent
)
8136 and then not Is_Generic_Type
(Root_Type
(Full_Parent
)))
8138 -- Copy and adjust declaration to provide a completion for what
8139 -- is originally a private declaration. Indicate that full view
8140 -- is internally generated.
8142 Set_Comes_From_Source
(Full_N
, False);
8143 Set_Comes_From_Source
(Full_Der
, False);
8144 Set_Parent
(Full_Der
, Full_N
);
8145 Set_Defining_Identifier
(Full_N
, Full_Der
);
8147 -- If there are no constraints, adjust the subtype mark
8149 if Nkind
(Subtype_Indication
(Type_Definition
(Full_N
))) /=
8150 N_Subtype_Indication
8152 Set_Subtype_Indication
8153 (Type_Definition
(Full_N
),
8154 New_Occurrence_Of
(Full_Parent
, Sloc
(Full_N
)));
8157 Insert_After
(N
, Full_N
);
8159 -- Build full view of derived type from full view of parent which
8160 -- is now installed. Subprograms have been derived on the partial
8161 -- view, the completion does not derive them anew.
8163 if Is_Record_Type
(Full_Parent
) then
8165 -- If parent type is tagged, the completion inherits the proper
8166 -- primitive operations.
8168 if Is_Tagged_Type
(Parent_Type
) then
8169 Build_Derived_Record_Type
8170 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
);
8172 Build_Derived_Record_Type
8173 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
=> False);
8177 -- If the parent type is private, this is not a completion and
8178 -- we build the full derivation recursively as a completion.
8181 (Full_N
, Full_Parent
, Full_Der
,
8182 Is_Completion
=> Is_Private_Type
(Full_Parent
),
8183 Derive_Subps
=> False);
8186 -- The full declaration has been introduced into the tree and
8187 -- processed in the step above. It should not be analyzed again
8188 -- (when encountered later in the current list of declarations)
8189 -- to prevent spurious name conflicts. The full entity remains
8192 Set_Analyzed
(Full_N
);
8196 Make_Defining_Identifier
(Sloc
(Derived_Type
),
8197 Chars
=> Chars
(Derived_Type
));
8198 Set_Is_Itype
(Full_Der
);
8199 Set_Associated_Node_For_Itype
(Full_Der
, N
);
8200 Set_Parent
(Full_Der
, N
);
8202 (N
, Full_Parent
, Full_Der
,
8203 Is_Completion
=> False, Derive_Subps
=> False);
8204 Set_Is_Not_Self_Hidden
(Full_Der
);
8207 Set_Has_Private_Declaration
(Full_Der
);
8208 Set_Has_Private_Declaration
(Derived_Type
);
8210 Set_Scope
(Full_Der
, Scope
(Derived_Type
));
8211 Set_Is_First_Subtype
(Full_Der
, Is_First_Subtype
(Derived_Type
));
8212 Set_Has_Size_Clause
(Full_Der
, False);
8213 Set_Has_Alignment_Clause
(Full_Der
, False);
8214 Set_Has_Delayed_Freeze
(Full_Der
);
8215 Set_Is_Frozen
(Full_Der
, False);
8216 Set_Freeze_Node
(Full_Der
, Empty
);
8217 Set_Depends_On_Private
(Full_Der
, Has_Private_Component
(Full_Der
));
8218 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
8220 -- The convention on the base type may be set in the private part
8221 -- and not propagated to the subtype until later, so we obtain the
8222 -- convention from the base type of the parent.
8224 Set_Convention
(Full_Der
, Convention
(Base_Type
(Full_Parent
)));
8227 -- Start of processing for Build_Derived_Private_Type
8230 if Is_Tagged_Type
(Parent_Type
) then
8231 Full_P
:= Full_View
(Parent_Type
);
8233 -- A type extension of a type with unknown discriminants is an
8234 -- indefinite type that the back-end cannot handle directly.
8235 -- We treat it as a private type, and build a completion that is
8236 -- derived from the full view of the parent, and hopefully has
8237 -- known discriminants.
8239 -- If the full view of the parent type has an underlying record view,
8240 -- use it to generate the underlying record view of this derived type
8241 -- (required for chains of derivations with unknown discriminants).
8243 -- Minor optimization: we avoid the generation of useless underlying
8244 -- record view entities if the private type declaration has unknown
8245 -- discriminants but its corresponding full view has no
8248 if Has_Unknown_Discriminants
(Parent_Type
)
8249 and then Present
(Full_P
)
8250 and then (Has_Discriminants
(Full_P
)
8251 or else Present
(Underlying_Record_View
(Full_P
)))
8252 and then not In_Open_Scopes
(Par_Scope
)
8253 and then Expander_Active
8256 Full_Der
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
8257 New_Ext
: constant Node_Id
:=
8259 (Record_Extension_Part
(Type_Definition
(N
)));
8263 Build_Derived_Record_Type
8264 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8266 -- Build anonymous completion, as a derivation from the full
8267 -- view of the parent. This is not a completion in the usual
8268 -- sense, because the current type is not private.
8271 Make_Full_Type_Declaration
(Loc
,
8272 Defining_Identifier
=> Full_Der
,
8274 Make_Derived_Type_Definition
(Loc
,
8275 Subtype_Indication
=>
8277 (Subtype_Indication
(Type_Definition
(N
))),
8278 Record_Extension_Part
=> New_Ext
));
8280 -- If the parent type has an underlying record view, use it
8281 -- here to build the new underlying record view.
8283 if Present
(Underlying_Record_View
(Full_P
)) then
8285 (Nkind
(Subtype_Indication
(Type_Definition
(Decl
)))
8287 Set_Entity
(Subtype_Indication
(Type_Definition
(Decl
)),
8288 Underlying_Record_View
(Full_P
));
8291 Install_Private_Declarations
(Par_Scope
);
8292 Install_Visible_Declarations
(Par_Scope
);
8293 Insert_Before
(N
, Decl
);
8295 -- Mark entity as an underlying record view before analysis,
8296 -- to avoid generating the list of its primitive operations
8297 -- (which is not really required for this entity) and thus
8298 -- prevent spurious errors associated with missing overriding
8299 -- of abstract primitives (overridden only for Derived_Type).
8301 Mutate_Ekind
(Full_Der
, E_Record_Type
);
8302 Set_Is_Underlying_Record_View
(Full_Der
);
8303 Set_Default_SSO
(Full_Der
);
8304 Set_No_Reordering
(Full_Der
, No_Component_Reordering
);
8308 pragma Assert
(Has_Discriminants
(Full_Der
)
8309 and then not Has_Unknown_Discriminants
(Full_Der
));
8311 Uninstall_Declarations
(Par_Scope
);
8313 -- Freeze the underlying record view, to prevent generation of
8314 -- useless dispatching information, which is simply shared with
8315 -- the real derived type.
8317 Set_Is_Frozen
(Full_Der
);
8319 -- If the derived type has access discriminants, create
8320 -- references to their anonymous types now, to prevent
8321 -- back-end problems when their first use is in generated
8322 -- bodies of primitives.
8328 E
:= First_Entity
(Full_Der
);
8330 while Present
(E
) loop
8331 if Ekind
(E
) = E_Discriminant
8332 and then Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
8334 Build_Itype_Reference
(Etype
(E
), Decl
);
8341 -- Set up links between real entity and underlying record view
8343 Set_Underlying_Record_View
(Derived_Type
, Base_Type
(Full_Der
));
8344 Set_Underlying_Record_View
(Base_Type
(Full_Der
), Derived_Type
);
8347 -- If discriminants are known, build derived record
8350 Build_Derived_Record_Type
8351 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8356 elsif Has_Discriminants
(Parent_Type
) then
8358 -- Build partial view of derived type from partial view of parent.
8359 -- This must be done before building the full derivation because the
8360 -- second derivation will modify the discriminants of the first and
8361 -- the discriminants are chained with the rest of the components in
8362 -- the full derivation.
8364 Build_Derived_Record_Type
8365 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8367 -- Build the full derivation if this is not the anonymous derived
8368 -- base type created by Build_Derived_Record_Type in the constrained
8369 -- case (see point 5. of its head comment) since we build it for the
8372 if Present
(Available_Full_View
(Parent_Type
))
8373 and then not Is_Itype
(Derived_Type
)
8376 Der_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
8378 Last_Discr
: Entity_Id
;
8381 -- If this is not a completion, construct the implicit full
8382 -- view by deriving from the full view of the parent type.
8383 -- But if this is a completion, the derived private type
8384 -- being built is a full view and the full derivation can
8385 -- only be its underlying full view.
8387 Build_Full_Derivation
;
8389 if not Is_Completion
then
8390 Set_Full_View
(Derived_Type
, Full_Der
);
8392 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8393 Set_Is_Underlying_Full_View
(Full_Der
);
8396 if not Is_Base_Type
(Derived_Type
) then
8397 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
8400 -- Copy the discriminant list from full view to the partial
8401 -- view (base type and its subtype). Gigi requires that the
8402 -- partial and full views have the same discriminants.
8404 -- Note that since the partial view points to discriminants
8405 -- in the full view, their scope will be that of the full
8406 -- view. This might cause some front end problems and need
8409 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
8410 Set_First_Entity
(Der_Base
, Discr
);
8413 Last_Discr
:= Discr
;
8414 Next_Discriminant
(Discr
);
8415 exit when No
(Discr
);
8418 Set_Last_Entity
(Der_Base
, Last_Discr
);
8419 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
8420 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
8424 elsif Present
(Available_Full_View
(Parent_Type
))
8425 and then Has_Discriminants
(Available_Full_View
(Parent_Type
))
8427 if Has_Unknown_Discriminants
(Parent_Type
)
8428 and then Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8429 N_Subtype_Indication
8432 ("cannot constrain type with unknown discriminants",
8433 Subtype_Indication
(Type_Definition
(N
)));
8437 -- If this is not a completion, construct the implicit full view by
8438 -- deriving from the full view of the parent type. But if this is a
8439 -- completion, the derived private type being built is a full view
8440 -- and the full derivation can only be its underlying full view.
8442 Build_Full_Derivation
;
8444 if not Is_Completion
then
8445 Set_Full_View
(Derived_Type
, Full_Der
);
8447 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8448 Set_Is_Underlying_Full_View
(Full_Der
);
8451 -- In any case, the primitive operations are inherited from the
8452 -- parent type, not from the internal full view.
8454 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
8456 if Derive_Subps
then
8457 -- Initialize the list of primitive operations to an empty list,
8458 -- to cover tagged types as well as untagged types. For untagged
8459 -- types this is used either to analyze the call as legal when
8460 -- Extensions_Allowed is True, or to issue a better error message
8463 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
8465 Derive_Subprograms
(Parent_Type
, Derived_Type
);
8468 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8470 (Derived_Type
, Is_Constrained
(Available_Full_View
(Parent_Type
)));
8473 -- Untagged type, No discriminants on either view
8475 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8476 N_Subtype_Indication
8479 ("illegal constraint on type without discriminants", N
);
8482 if Present
(Discriminant_Specifications
(N
))
8483 and then Present
(Available_Full_View
(Parent_Type
))
8484 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8486 Error_Msg_N
("cannot add discriminants to untagged type", N
);
8489 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8490 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
8492 Set_Is_Controlled_Active
8493 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
8495 Set_Disable_Controlled
8496 (Derived_Type
, Disable_Controlled
(Parent_Type
));
8498 Set_Has_Controlled_Component
8499 (Derived_Type
, Has_Controlled_Component
(Parent_Type
));
8501 -- Direct controlled types do not inherit Finalize_Storage_Only flag
8503 if not Is_Controlled
(Parent_Type
) then
8504 Set_Finalize_Storage_Only
8505 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
8508 -- If this is not a completion, construct the implicit full view by
8509 -- deriving from the full view of the parent type. But if this is a
8510 -- completion, the derived private type being built is a full view
8511 -- and the full derivation can only be its underlying full view.
8513 -- ??? If the parent type is untagged private and its completion is
8514 -- tagged, this mechanism will not work because we cannot derive from
8515 -- the tagged full view unless we have an extension.
8517 if Present
(Available_Full_View
(Parent_Type
))
8518 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8519 and then not Error_Posted
(N
)
8521 Build_Full_Derivation
;
8523 if not Is_Completion
then
8524 Set_Full_View
(Derived_Type
, Full_Der
);
8526 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8527 Set_Is_Underlying_Full_View
(Full_Der
);
8532 Set_Has_Unknown_Discriminants
(Derived_Type
,
8533 Has_Unknown_Discriminants
(Parent_Type
));
8535 if Is_Private_Type
(Derived_Type
) then
8536 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
8539 -- If the parent base type is in scope, add the derived type to its
8540 -- list of private dependents, because its full view may become
8541 -- visible subsequently (in a nested private part, a body, or in a
8542 -- further child unit).
8544 if Is_Private_Type
(Par_Base
) and then In_Open_Scopes
(Par_Scope
) then
8545 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
8547 -- Check for unusual case where a type completed by a private
8548 -- derivation occurs within a package nested in a child unit, and
8549 -- the parent is declared in an ancestor.
8551 if Is_Child_Unit
(Scope
(Current_Scope
))
8552 and then Is_Completion
8553 and then In_Private_Part
(Current_Scope
)
8554 and then Scope
(Parent_Type
) /= Current_Scope
8556 -- Note that if the parent has a completion in the private part,
8557 -- (which is itself a derivation from some other private type)
8558 -- it is that completion that is visible, there is no full view
8559 -- available, and no special processing is needed.
8561 and then Present
(Full_View
(Parent_Type
))
8563 -- In this case, the full view of the parent type will become
8564 -- visible in the body of the enclosing child, and only then will
8565 -- the current type be possibly non-private. Build an underlying
8566 -- full view that will be installed when the enclosing child body
8569 if Present
(Underlying_Full_View
(Derived_Type
)) then
8570 Full_Der
:= Underlying_Full_View
(Derived_Type
);
8572 Build_Full_Derivation
;
8573 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8574 Set_Is_Underlying_Full_View
(Full_Der
);
8577 -- The full view will be used to swap entities on entry/exit to
8578 -- the body, and must appear in the entity list for the package.
8580 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
8583 end Build_Derived_Private_Type
;
8585 -------------------------------
8586 -- Build_Derived_Record_Type --
8587 -------------------------------
8591 -- Ideally we would like to use the same model of type derivation for
8592 -- tagged and untagged record types. Unfortunately this is not quite
8593 -- possible because the semantics of representation clauses is different
8594 -- for tagged and untagged records under inheritance. Consider the
8597 -- type R (...) is [tagged] record ... end record;
8598 -- type T (...) is new R (...) [with ...];
8600 -- The representation clauses for T can specify a completely different
8601 -- record layout from R's. Hence the same component can be placed in two
8602 -- very different positions in objects of type T and R. If R and T are
8603 -- tagged types, representation clauses for T can only specify the layout
8604 -- of non inherited components, thus components that are common in R and T
8605 -- have the same position in objects of type R and T.
8607 -- This has two implications. The first is that the entire tree for R's
8608 -- declaration needs to be copied for T in the untagged case, so that T
8609 -- can be viewed as a record type of its own with its own representation
8610 -- clauses. The second implication is the way we handle discriminants.
8611 -- Specifically, in the untagged case we need a way to communicate to Gigi
8612 -- what are the real discriminants in the record, while for the semantics
8613 -- we need to consider those introduced by the user to rename the
8614 -- discriminants in the parent type. This is handled by introducing the
8615 -- notion of stored discriminants. See below for more.
8617 -- Fortunately the way regular components are inherited can be handled in
8618 -- the same way in tagged and untagged types.
8620 -- To complicate things a bit more the private view of a private extension
8621 -- cannot be handled in the same way as the full view (for one thing the
8622 -- semantic rules are somewhat different). We will explain what differs
8625 -- 2. DISCRIMINANTS UNDER INHERITANCE
8627 -- The semantic rules governing the discriminants of derived types are
8630 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
8631 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
8633 -- If parent type has discriminants, then the discriminants that are
8634 -- declared in the derived type are [3.4 (11)]:
8636 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
8639 -- o Otherwise, each discriminant of the parent type (implicitly declared
8640 -- in the same order with the same specifications). In this case, the
8641 -- discriminants are said to be "inherited", or if unknown in the parent
8642 -- are also unknown in the derived type.
8644 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
8646 -- o The parent subtype must be constrained;
8648 -- o If the parent type is not a tagged type, then each discriminant of
8649 -- the derived type must be used in the constraint defining a parent
8650 -- subtype. [Implementation note: This ensures that the new discriminant
8651 -- can share storage with an existing discriminant.]
8653 -- For the derived type each discriminant of the parent type is either
8654 -- inherited, constrained to equal some new discriminant of the derived
8655 -- type, or constrained to the value of an expression.
8657 -- When inherited or constrained to equal some new discriminant, the
8658 -- parent discriminant and the discriminant of the derived type are said
8661 -- If a discriminant of the parent type is constrained to a specific value
8662 -- in the derived type definition, then the discriminant is said to be
8663 -- "specified" by that derived type definition.
8665 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
8667 -- We have spoken about stored discriminants in point 1 (introduction)
8668 -- above. There are two sorts of stored discriminants: implicit and
8669 -- explicit. As long as the derived type inherits the same discriminants as
8670 -- the root record type, stored discriminants are the same as regular
8671 -- discriminants, and are said to be implicit. However, if any discriminant
8672 -- in the root type was renamed in the derived type, then the derived
8673 -- type will contain explicit stored discriminants. Explicit stored
8674 -- discriminants are discriminants in addition to the semantically visible
8675 -- discriminants defined for the derived type. Stored discriminants are
8676 -- used by Gigi to figure out what are the physical discriminants in
8677 -- objects of the derived type (see precise definition in einfo.ads).
8678 -- As an example, consider the following:
8680 -- type R (D1, D2, D3 : Int) is record ... end record;
8681 -- type T1 is new R;
8682 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
8683 -- type T3 is new T2;
8684 -- type T4 (Y : Int) is new T3 (Y, 99);
8686 -- The following table summarizes the discriminants and stored
8687 -- discriminants in R and T1 through T4:
8689 -- Type Discrim Stored Discrim Comment
8690 -- R (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in R
8691 -- T1 (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in T1
8692 -- T2 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T2
8693 -- T3 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T3
8694 -- T4 (Y) (D1, D2, D3) Stored discrims EXPLICIT in T4
8696 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
8697 -- find the corresponding discriminant in the parent type, while
8698 -- Original_Record_Component (abbreviated ORC below) the actual physical
8699 -- component that is renamed. Finally the field Is_Completely_Hidden
8700 -- (abbreviated ICH below) is set for all explicit stored discriminants
8701 -- (see einfo.ads for more info). For the above example this gives:
8703 -- Discrim CD ORC ICH
8704 -- ^^^^^^^ ^^ ^^^ ^^^
8705 -- D1 in R empty itself no
8706 -- D2 in R empty itself no
8707 -- D3 in R empty itself no
8709 -- D1 in T1 D1 in R itself no
8710 -- D2 in T1 D2 in R itself no
8711 -- D3 in T1 D3 in R itself no
8713 -- X1 in T2 D3 in T1 D3 in T2 no
8714 -- X2 in T2 D1 in T1 D1 in T2 no
8715 -- D1 in T2 empty itself yes
8716 -- D2 in T2 empty itself yes
8717 -- D3 in T2 empty itself yes
8719 -- X1 in T3 X1 in T2 D3 in T3 no
8720 -- X2 in T3 X2 in T2 D1 in T3 no
8721 -- D1 in T3 empty itself yes
8722 -- D2 in T3 empty itself yes
8723 -- D3 in T3 empty itself yes
8725 -- Y in T4 X1 in T3 D3 in T4 no
8726 -- D1 in T4 empty itself yes
8727 -- D2 in T4 empty itself yes
8728 -- D3 in T4 empty itself yes
8730 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
8732 -- Type derivation for tagged types is fairly straightforward. If no
8733 -- discriminants are specified by the derived type, these are inherited
8734 -- from the parent. No explicit stored discriminants are ever necessary.
8735 -- The only manipulation that is done to the tree is that of adding a
8736 -- _parent field with parent type and constrained to the same constraint
8737 -- specified for the parent in the derived type definition. For instance:
8739 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
8740 -- type T1 is new R with null record;
8741 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
8743 -- are changed into:
8745 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
8746 -- _parent : R (D1, D2, D3);
8749 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
8750 -- _parent : T1 (X2, 88, X1);
8753 -- The discriminants actually present in R, T1 and T2 as well as their CD,
8754 -- ORC and ICH fields are:
8756 -- Discrim CD ORC ICH
8757 -- ^^^^^^^ ^^ ^^^ ^^^
8758 -- D1 in R empty itself no
8759 -- D2 in R empty itself no
8760 -- D3 in R empty itself no
8762 -- D1 in T1 D1 in R D1 in R no
8763 -- D2 in T1 D2 in R D2 in R no
8764 -- D3 in T1 D3 in R D3 in R no
8766 -- X1 in T2 D3 in T1 D3 in R no
8767 -- X2 in T2 D1 in T1 D1 in R no
8769 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
8771 -- Regardless of whether we are dealing with a tagged or untagged type
8772 -- we will transform all derived type declarations of the form
8774 -- type T is new R (...) [with ...];
8776 -- subtype S is R (...);
8777 -- type T is new S [with ...];
8779 -- type BT is new R [with ...];
8780 -- subtype T is BT (...);
8782 -- That is, the base derived type is constrained only if it has no
8783 -- discriminants. The reason for doing this is that GNAT's semantic model
8784 -- assumes that a base type with discriminants is unconstrained.
8786 -- Note that, strictly speaking, the above transformation is not always
8787 -- correct. Consider for instance the following excerpt from ACVC b34011a:
8789 -- procedure B34011A is
8790 -- type REC (D : integer := 0) is record
8795 -- type T6 is new Rec;
8796 -- function F return T6;
8801 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
8804 -- The definition of Q6.U is illegal. However transforming Q6.U into
8806 -- type BaseU is new T6;
8807 -- subtype U is BaseU (Q6.F.I)
8809 -- turns U into a legal subtype, which is incorrect. To avoid this problem
8810 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
8811 -- the transformation described above.
8813 -- There is another instance where the above transformation is incorrect.
8817 -- type Base (D : Integer) is tagged null record;
8818 -- procedure P (X : Base);
8820 -- type Der is new Base (2) with null record;
8821 -- procedure P (X : Der);
8824 -- Then the above transformation turns this into
8826 -- type Der_Base is new Base with null record;
8827 -- -- procedure P (X : Base) is implicitly inherited here
8828 -- -- as procedure P (X : Der_Base).
8830 -- subtype Der is Der_Base (2);
8831 -- procedure P (X : Der);
8832 -- -- The overriding of P (X : Der_Base) is illegal since we
8833 -- -- have a parameter conformance problem.
8835 -- To get around this problem, after having semantically processed Der_Base
8836 -- and the rewritten subtype declaration for Der, we copy Der_Base field
8837 -- Discriminant_Constraint from Der so that when parameter conformance is
8838 -- checked when P is overridden, no semantic errors are flagged.
8840 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
8842 -- Regardless of whether we are dealing with a tagged or untagged type
8843 -- we will transform all derived type declarations of the form
8845 -- type R (D1, .., Dn : ...) is [tagged] record ...;
8846 -- type T is new R [with ...];
8848 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
8850 -- The reason for such transformation is that it allows us to implement a
8851 -- very clean form of component inheritance as explained below.
8853 -- Note that this transformation is not achieved by direct tree rewriting
8854 -- and manipulation, but rather by redoing the semantic actions that the
8855 -- above transformation will entail. This is done directly in routine
8856 -- Inherit_Components.
8858 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
8860 -- In both tagged and untagged derived types, regular non discriminant
8861 -- components are inherited in the derived type from the parent type. In
8862 -- the absence of discriminants component, inheritance is straightforward
8863 -- as components can simply be copied from the parent.
8865 -- If the parent has discriminants, inheriting components constrained with
8866 -- these discriminants requires caution. Consider the following example:
8868 -- type R (D1, D2 : Positive) is [tagged] record
8869 -- S : String (D1 .. D2);
8872 -- type T1 is new R [with null record];
8873 -- type T2 (X : positive) is new R (1, X) [with null record];
8875 -- As explained in 6. above, T1 is rewritten as
8876 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
8877 -- which makes the treatment for T1 and T2 identical.
8879 -- What we want when inheriting S, is that references to D1 and D2 in R are
8880 -- replaced with references to their correct constraints, i.e. D1 and D2 in
8881 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
8882 -- with either discriminant references in the derived type or expressions.
8883 -- This replacement is achieved as follows: before inheriting R's
8884 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
8885 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
8886 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
8887 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
8888 -- by String (1 .. X).
8890 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
8892 -- We explain here the rules governing private type extensions relevant to
8893 -- type derivation. These rules are explained on the following example:
8895 -- type D [(...)] is new A [(...)] with private; <-- partial view
8896 -- type D [(...)] is new P [(...)] with null record; <-- full view
8898 -- Type A is called the ancestor subtype of the private extension.
8899 -- Type P is the parent type of the full view of the private extension. It
8900 -- must be A or a type derived from A.
8902 -- The rules concerning the discriminants of private type extensions are
8905 -- o If a private extension inherits known discriminants from the ancestor
8906 -- subtype, then the full view must also inherit its discriminants from
8907 -- the ancestor subtype and the parent subtype of the full view must be
8908 -- constrained if and only if the ancestor subtype is constrained.
8910 -- o If a partial view has unknown discriminants, then the full view may
8911 -- define a definite or an indefinite subtype, with or without
8914 -- o If a partial view has neither known nor unknown discriminants, then
8915 -- the full view must define a definite subtype.
8917 -- o If the ancestor subtype of a private extension has constrained
8918 -- discriminants, then the parent subtype of the full view must impose a
8919 -- statically matching constraint on those discriminants.
8921 -- This means that only the following forms of private extensions are
8924 -- type D is new A with private; <-- partial view
8925 -- type D is new P with null record; <-- full view
8927 -- If A has no discriminants than P has no discriminants, otherwise P must
8928 -- inherit A's discriminants.
8930 -- type D is new A (...) with private; <-- partial view
8931 -- type D is new P (:::) with null record; <-- full view
8933 -- P must inherit A's discriminants and (...) and (:::) must statically
8936 -- subtype A is R (...);
8937 -- type D is new A with private; <-- partial view
8938 -- type D is new P with null record; <-- full view
8940 -- P must have inherited R's discriminants and must be derived from A or
8941 -- any of its subtypes.
8943 -- type D (..) is new A with private; <-- partial view
8944 -- type D (..) is new P [(:::)] with null record; <-- full view
8946 -- No specific constraints on P's discriminants or constraint (:::).
8947 -- Note that A can be unconstrained, but the parent subtype P must either
8948 -- be constrained or (:::) must be present.
8950 -- type D (..) is new A [(...)] with private; <-- partial view
8951 -- type D (..) is new P [(:::)] with null record; <-- full view
8953 -- P's constraints on A's discriminants must statically match those
8954 -- imposed by (...).
8956 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
8958 -- The full view of a private extension is handled exactly as described
8959 -- above. The model chose for the private view of a private extension is
8960 -- the same for what concerns discriminants (i.e. they receive the same
8961 -- treatment as in the tagged case). However, the private view of the
8962 -- private extension always inherits the components of the parent base,
8963 -- without replacing any discriminant reference. Strictly speaking this is
8964 -- incorrect. However, Gigi never uses this view to generate code so this
8965 -- is a purely semantic issue. In theory, a set of transformations similar
8966 -- to those given in 5. and 6. above could be applied to private views of
8967 -- private extensions to have the same model of component inheritance as
8968 -- for non private extensions. However, this is not done because it would
8969 -- further complicate private type processing. Semantically speaking, this
8970 -- leaves us in an uncomfortable situation. As an example consider:
8973 -- type R (D : integer) is tagged record
8974 -- S : String (1 .. D);
8976 -- procedure P (X : R);
8977 -- type T is new R (1) with private;
8979 -- type T is new R (1) with null record;
8982 -- This is transformed into:
8985 -- type R (D : integer) is tagged record
8986 -- S : String (1 .. D);
8988 -- procedure P (X : R);
8989 -- type T is new R (1) with private;
8991 -- type BaseT is new R with null record;
8992 -- subtype T is BaseT (1);
8995 -- (strictly speaking the above is incorrect Ada)
8997 -- From the semantic standpoint the private view of private extension T
8998 -- should be flagged as constrained since one can clearly have
9002 -- in a unit withing Pack. However, when deriving subprograms for the
9003 -- private view of private extension T, T must be seen as unconstrained
9004 -- since T has discriminants (this is a constraint of the current
9005 -- subprogram derivation model). Thus, when processing the private view of
9006 -- a private extension such as T, we first mark T as unconstrained, we
9007 -- process it, we perform program derivation and just before returning from
9008 -- Build_Derived_Record_Type we mark T as constrained.
9010 -- ??? Are there are other uncomfortable cases that we will have to
9013 -- 10. RECORD_TYPE_WITH_PRIVATE complications
9015 -- Types that are derived from a visible record type and have a private
9016 -- extension present other peculiarities. They behave mostly like private
9017 -- types, but if they have primitive operations defined, these will not
9018 -- have the proper signatures for further inheritance, because other
9019 -- primitive operations will use the implicit base that we define for
9020 -- private derivations below. This affect subprogram inheritance (see
9021 -- Derive_Subprograms for details). We also derive the implicit base from
9022 -- the base type of the full view, so that the implicit base is a record
9023 -- type and not another private type, This avoids infinite loops.
9025 procedure Build_Derived_Record_Type
9027 Parent_Type
: Entity_Id
;
9028 Derived_Type
: Entity_Id
;
9029 Derive_Subps
: Boolean := True)
9031 Discriminant_Specs
: constant Boolean :=
9032 Present
(Discriminant_Specifications
(N
));
9033 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
9034 Loc
: constant Source_Ptr
:= Sloc
(N
);
9035 Private_Extension
: constant Boolean :=
9036 Nkind
(N
) = N_Private_Extension_Declaration
;
9037 Assoc_List
: Elist_Id
;
9038 Constraint_Present
: Boolean;
9040 Discrim
: Entity_Id
;
9042 Inherit_Discrims
: Boolean := False;
9043 Last_Discrim
: Entity_Id
;
9044 New_Base
: Entity_Id
;
9046 New_Discrs
: Elist_Id
;
9047 New_Indic
: Node_Id
;
9048 Parent_Base
: Entity_Id
;
9049 Save_Etype
: Entity_Id
;
9050 Save_Discr_Constr
: Elist_Id
;
9051 Save_Next_Entity
: Entity_Id
;
9054 Discs
: Elist_Id
:= New_Elmt_List
;
9055 -- An empty Discs list means that there were no constraints in the
9056 -- subtype indication or that there was an error processing it.
9058 procedure Check_Generic_Ancestors
;
9059 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
9060 -- cannot be declared at a deeper level than its parent type is
9061 -- removed. The check on derivation within a generic body is also
9062 -- relaxed, but there's a restriction that a derived tagged type
9063 -- cannot be declared in a generic body if it's derived directly
9064 -- or indirectly from a formal type of that generic. This applies
9065 -- to progenitors as well.
9067 -----------------------------
9068 -- Check_Generic_Ancestors --
9069 -----------------------------
9071 procedure Check_Generic_Ancestors
is
9072 Ancestor_Type
: Entity_Id
;
9073 Intf_List
: List_Id
;
9074 Intf_Name
: Node_Id
;
9076 procedure Check_Ancestor
;
9077 -- For parent and progenitors.
9079 --------------------
9080 -- Check_Ancestor --
9081 --------------------
9083 procedure Check_Ancestor
is
9085 -- If the derived type does have a formal type as an ancestor
9086 -- then it's an error if the derived type is declared within
9087 -- the body of the generic unit that declares the formal type
9088 -- in its generic formal part. It's sufficient to check whether
9089 -- the ancestor type is declared inside the same generic body
9090 -- as the derived type (such as within a nested generic spec),
9091 -- in which case the derivation is legal. If the formal type is
9092 -- declared outside of that generic body, then it's certain
9093 -- that the derived type is declared within the generic body
9094 -- of the generic unit declaring the formal type.
9096 if Is_Generic_Type
(Ancestor_Type
)
9097 and then Enclosing_Generic_Body
(Ancestor_Type
) /=
9098 Enclosing_Generic_Body
(Derived_Type
)
9101 ("ancestor type& is formal type of enclosing"
9102 & " generic unit (RM 3.9.1 (4/2))",
9103 Indic
, Ancestor_Type
);
9108 if Nkind
(N
) = N_Private_Extension_Declaration
then
9109 Intf_List
:= Interface_List
(N
);
9111 Intf_List
:= Interface_List
(Type_Definition
(N
));
9114 if Present
(Enclosing_Generic_Body
(Derived_Type
)) then
9115 Ancestor_Type
:= Parent_Type
;
9117 while not Is_Generic_Type
(Ancestor_Type
)
9118 and then Etype
(Ancestor_Type
) /= Ancestor_Type
9120 Ancestor_Type
:= Etype
(Ancestor_Type
);
9125 if Present
(Intf_List
) then
9126 Intf_Name
:= First
(Intf_List
);
9127 while Present
(Intf_Name
) loop
9128 Ancestor_Type
:= Entity
(Intf_Name
);
9134 end Check_Generic_Ancestors
;
9136 -- Start of processing for Build_Derived_Record_Type
9139 -- If the parent type is a private extension with discriminants, we
9140 -- need to have an unconstrained type on which to apply the inherited
9141 -- constraint, so we get to the full view. However, this means that the
9142 -- derived type and its implicit base type created below will not point
9143 -- to the same view of their respective parent type and, thus, special
9144 -- glue code like Exp_Ch7.Convert_View is needed to bridge this gap.
9146 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
9147 and then Has_Discriminants
(Parent_Type
)
9148 and then Present
(Full_View
(Parent_Type
))
9150 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
9152 Parent_Base
:= Base_Type
(Parent_Type
);
9155 -- If the parent type is declared as a subtype of another private
9156 -- type with inherited discriminants, its generated base type is
9157 -- itself a record subtype. To further inherit the constraint we
9158 -- need to use its own base to have an unconstrained type on which
9159 -- to apply the inherited constraint.
9161 if Ekind
(Parent_Base
) = E_Record_Subtype
then
9162 Parent_Base
:= Base_Type
(Parent_Base
);
9165 -- If the parent base is a private type and only its full view has
9166 -- discriminants, use the full view's base type.
9168 -- This can happen when we are deriving from a subtype of a derived type
9169 -- of a private type derived from a discriminated type with known
9173 -- type Root_Type(I: Positive) is record
9176 -- type Bounded_Root_Type is private;
9178 -- type Bounded_Root_Type is new Root_Type(10);
9182 -- type Constrained_Root_Type is new Pkg.Bounded_Root_Type;
9184 -- subtype Sub_Base is Pkg2.Constrained_Root_Type;
9185 -- type New_Der_Type is new Sub_Base;
9187 if Is_Private_Type
(Parent_Base
)
9188 and then Present
(Full_View
(Parent_Base
))
9189 and then not Has_Discriminants
(Parent_Base
)
9190 and then Has_Discriminants
(Full_View
(Parent_Base
))
9192 Parent_Base
:= Base_Type
(Full_View
(Parent_Base
));
9195 -- AI05-0115: if this is a derivation from a private type in some
9196 -- other scope that may lead to invisible components for the derived
9197 -- type, mark it accordingly.
9199 if Is_Private_Type
(Parent_Type
) then
9200 if Scope
(Parent_Base
) = Scope
(Derived_Type
) then
9203 elsif In_Open_Scopes
(Scope
(Parent_Base
))
9204 and then In_Private_Part
(Scope
(Parent_Base
))
9209 Set_Has_Private_Ancestor
(Derived_Type
);
9213 Set_Has_Private_Ancestor
9214 (Derived_Type
, Has_Private_Ancestor
(Parent_Type
));
9217 -- Before we start the previously documented transformations, here is
9218 -- little fix for size and alignment of tagged types. Normally when we
9219 -- derive type D from type P, we copy the size and alignment of P as the
9220 -- default for D, and in the absence of explicit representation clauses
9221 -- for D, the size and alignment are indeed the same as the parent.
9223 -- But this is wrong for tagged types, since fields may be added, and
9224 -- the default size may need to be larger, and the default alignment may
9225 -- need to be larger.
9227 -- We therefore reset the size and alignment fields in the tagged case.
9228 -- Note that the size and alignment will in any case be at least as
9229 -- large as the parent type (since the derived type has a copy of the
9230 -- parent type in the _parent field)
9232 -- The type is also marked as being tagged here, which is needed when
9233 -- processing components with a self-referential anonymous access type
9234 -- in the call to Check_Anonymous_Access_Components below. Note that
9235 -- this flag is also set later on for completeness.
9238 Set_Is_Tagged_Type
(Derived_Type
);
9239 Reinit_Size_Align
(Derived_Type
);
9242 -- STEP 0a: figure out what kind of derived type declaration we have
9244 if Private_Extension
then
9246 Mutate_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
9247 Set_Default_SSO
(Derived_Type
);
9248 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9251 Type_Def
:= Type_Definition
(N
);
9253 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
9254 -- Parent_Base can be a private type or private extension. However,
9255 -- for tagged types with an extension the newly added fields are
9256 -- visible and hence the Derived_Type is always an E_Record_Type.
9257 -- (except that the parent may have its own private fields).
9258 -- For untagged types we preserve the Ekind of the Parent_Base.
9260 if Present
(Record_Extension_Part
(Type_Def
)) then
9261 Mutate_Ekind
(Derived_Type
, E_Record_Type
);
9262 Set_Default_SSO
(Derived_Type
);
9263 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9265 -- Create internal access types for components with anonymous
9268 if Ada_Version
>= Ada_2005
then
9269 Check_Anonymous_Access_Components
9270 (N
, Derived_Type
, Derived_Type
,
9271 Component_List
(Record_Extension_Part
(Type_Def
)));
9275 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
9279 -- Indic can either be an N_Identifier if the subtype indication
9280 -- contains no constraint or an N_Subtype_Indication if the subtype
9281 -- indication has a constraint. In either case it can include an
9284 Indic
:= Subtype_Indication
(Type_Def
);
9285 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
9287 -- Check that the type has visible discriminants. The type may be
9288 -- a private type with unknown discriminants whose full view has
9289 -- discriminants which are invisible.
9291 if Constraint_Present
then
9292 if not Has_Discriminants
(Parent_Base
)
9294 (Has_Unknown_Discriminants
(Parent_Base
)
9295 and then Is_Private_Type
(Parent_Base
))
9298 ("invalid constraint: type has no discriminant",
9299 Constraint
(Indic
));
9301 Constraint_Present
:= False;
9302 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9304 elsif Is_Constrained
(Parent_Type
) then
9306 ("invalid constraint: parent type is already constrained",
9307 Constraint
(Indic
));
9309 Constraint_Present
:= False;
9310 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9314 -- STEP 0b: If needed, apply transformation given in point 5. above
9316 if not Private_Extension
9317 and then Has_Discriminants
(Parent_Type
)
9318 and then not Discriminant_Specs
9319 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
9321 -- First, we must analyze the constraint (see comment in point 5.)
9322 -- The constraint may come from the subtype indication of the full
9323 -- declaration. Temporarily set the state of the Derived_Type to
9324 -- "self-hidden" (see RM-8.3(17)).
9326 if Constraint_Present
then
9327 pragma Assert
(Is_Not_Self_Hidden
(Derived_Type
));
9328 Set_Is_Not_Self_Hidden
(Derived_Type
, False);
9329 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9330 Set_Is_Not_Self_Hidden
(Derived_Type
);
9332 -- If there is no explicit constraint, there might be one that is
9333 -- inherited from a constrained parent type. In that case verify that
9334 -- it conforms to the constraint in the partial view. In perverse
9335 -- cases the parent subtypes of the partial and full view can have
9336 -- different constraints.
9338 elsif Present
(Stored_Constraint
(Parent_Type
)) then
9339 New_Discrs
:= Stored_Constraint
(Parent_Type
);
9342 New_Discrs
:= No_Elist
;
9345 if Has_Discriminants
(Derived_Type
)
9346 and then Has_Private_Declaration
(Derived_Type
)
9347 and then Present
(Discriminant_Constraint
(Derived_Type
))
9348 and then Present
(New_Discrs
)
9350 -- Verify that constraints of the full view statically match
9351 -- those given in the partial view.
9357 C1
:= First_Elmt
(New_Discrs
);
9358 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
9359 while Present
(C1
) and then Present
(C2
) loop
9360 if Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9362 (Is_OK_Static_Expression
(Node
(C1
))
9363 and then Is_OK_Static_Expression
(Node
(C2
))
9365 Expr_Value
(Node
(C1
)) = Expr_Value
(Node
(C2
)))
9370 if Constraint_Present
then
9372 ("constraint not conformant to previous declaration",
9376 ("constraint of full view is incompatible "
9377 & "with partial view", N
);
9387 -- Insert and analyze the declaration for the unconstrained base type
9389 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
9392 Make_Full_Type_Declaration
(Loc
,
9393 Defining_Identifier
=> New_Base
,
9395 Make_Derived_Type_Definition
(Loc
,
9396 Abstract_Present
=> Abstract_Present
(Type_Def
),
9397 Limited_Present
=> Limited_Present
(Type_Def
),
9398 Subtype_Indication
=>
9399 New_Occurrence_Of
(Parent_Base
, Loc
),
9400 Record_Extension_Part
=>
9401 Relocate_Node
(Record_Extension_Part
(Type_Def
)),
9402 Interface_List
=> Interface_List
(Type_Def
)));
9404 Set_Parent
(New_Decl
, Parent
(N
));
9405 Mark_Rewrite_Insertion
(New_Decl
);
9406 Insert_Before
(N
, New_Decl
);
9408 -- In the extension case, make sure ancestor is frozen appropriately
9409 -- (see also non-discriminated case below).
9411 if Present
(Record_Extension_Part
(Type_Def
))
9412 or else Is_Interface
(Parent_Base
)
9414 Freeze_Before
(New_Decl
, Parent_Type
);
9417 -- Note that this call passes False for the Derive_Subps parameter
9418 -- because subprogram derivation is deferred until after creating
9419 -- the subtype (see below).
9422 (New_Decl
, Parent_Base
, New_Base
,
9423 Is_Completion
=> False, Derive_Subps
=> False);
9425 -- ??? This needs re-examination to determine whether the
9426 -- following call can simply be replaced by a call to Analyze.
9428 Set_Analyzed
(New_Decl
);
9430 -- Insert and analyze the declaration for the constrained subtype
9432 if Constraint_Present
then
9434 Make_Subtype_Indication
(Loc
,
9435 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9436 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
9440 Constr_List
: constant List_Id
:= New_List
;
9445 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
9446 while Present
(C
) loop
9449 -- It is safe here to call New_Copy_Tree since we called
9450 -- Force_Evaluation on each constraint previously
9451 -- in Build_Discriminant_Constraints.
9453 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
9459 Make_Subtype_Indication
(Loc
,
9460 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9462 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
9467 Make_Subtype_Declaration
(Loc
,
9468 Defining_Identifier
=> Derived_Type
,
9469 Subtype_Indication
=> New_Indic
));
9471 -- Keep the aspects from the original node
9473 Move_Aspects
(Original_Node
(N
), N
);
9477 -- Derivation of subprograms must be delayed until the full subtype
9478 -- has been established, to ensure proper overriding of subprograms
9479 -- inherited by full types. If the derivations occurred as part of
9480 -- the call to Build_Derived_Type above, then the check for type
9481 -- conformance would fail because earlier primitive subprograms
9482 -- could still refer to the full type prior the change to the new
9483 -- subtype and hence would not match the new base type created here.
9484 -- Subprograms are not derived, however, when Derive_Subps is False
9485 -- (since otherwise there could be redundant derivations).
9487 if Derive_Subps
then
9488 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9491 -- For tagged types the Discriminant_Constraint of the new base itype
9492 -- is inherited from the first subtype so that no subtype conformance
9493 -- problem arise when the first subtype overrides primitive
9494 -- operations inherited by the implicit base type.
9497 Set_Discriminant_Constraint
9498 (New_Base
, Discriminant_Constraint
(Derived_Type
));
9504 -- If we get here Derived_Type will have no discriminants or it will be
9505 -- a discriminated unconstrained base type.
9507 -- STEP 1a: perform preliminary actions/checks for derived tagged types
9511 -- The parent type is frozen for non-private extensions (RM 13.14(7))
9512 -- The declaration of a specific descendant of an interface type
9513 -- freezes the interface type (RM 13.14).
9515 if not Private_Extension
or else Is_Interface
(Parent_Base
) then
9516 Freeze_Before
(N
, Parent_Type
);
9519 if Ada_Version
>= Ada_2005
then
9520 Check_Generic_Ancestors
;
9522 elsif Type_Access_Level
(Derived_Type
) /=
9523 Type_Access_Level
(Parent_Type
)
9524 and then not Is_Generic_Type
(Derived_Type
)
9526 if Is_Controlled
(Parent_Type
) then
9528 ("controlled type must be declared at the library level",
9532 ("type extension at deeper accessibility level than parent",
9538 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
9541 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
9544 ("parent type of& must not be outside generic body"
9546 Indic
, Derived_Type
);
9552 -- Ada 2005 (AI-251)
9554 if Ada_Version
>= Ada_2005
and then Is_Tagged
then
9556 -- "The declaration of a specific descendant of an interface type
9557 -- freezes the interface type" (RM 13.14).
9562 Iface
:= First
(Interface_List
(Type_Def
));
9563 while Present
(Iface
) loop
9564 Freeze_Before
(N
, Etype
(Iface
));
9570 -- STEP 1b : preliminary cleanup of the full view of private types
9572 -- If the type is already marked as having discriminants, then it's the
9573 -- completion of a private type or private extension and we need to
9574 -- retain the discriminants from the partial view if the current
9575 -- declaration has Discriminant_Specifications so that we can verify
9576 -- conformance. However, we must remove any existing components that
9577 -- were inherited from the parent (and attached in Copy_And_Swap)
9578 -- because the full type inherits all appropriate components anyway, and
9579 -- we do not want the partial view's components interfering.
9581 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
9582 Discrim
:= First_Discriminant
(Derived_Type
);
9584 Last_Discrim
:= Discrim
;
9585 Next_Discriminant
(Discrim
);
9586 exit when No
(Discrim
);
9589 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
9591 -- In all other cases wipe out the list of inherited components (even
9592 -- inherited discriminants), it will be properly rebuilt here.
9595 Set_First_Entity
(Derived_Type
, Empty
);
9596 Set_Last_Entity
(Derived_Type
, Empty
);
9599 -- STEP 1c: Initialize some flags for the Derived_Type
9601 -- The following flags must be initialized here so that
9602 -- Process_Discriminants can check that discriminants of tagged types do
9603 -- not have a default initial value and that access discriminants are
9604 -- only specified for limited records. For completeness, these flags are
9605 -- also initialized along with all the other flags below.
9607 -- AI-419: Limitedness is not inherited from an interface parent, so to
9608 -- be limited in that case the type must be explicitly declared as
9609 -- limited, or synchronized. While task and protected interfaces are
9610 -- always limited, a synchronized private extension might not inherit
9611 -- from such interfaces, and so we also need to recognize the
9612 -- explicit limitedness implied by a synchronized private extension
9613 -- that does not derive from a synchronized interface (see RM-7.3(6/2)).
9615 if Limited_Present
(Type_Def
)
9616 or else Synchronized_Present
(Type_Def
)
9618 Set_Is_Limited_Record
(Derived_Type
);
9620 elsif Is_Limited_Record
(Parent_Type
)
9621 or else (Present
(Full_View
(Parent_Type
))
9622 and then Is_Limited_Record
(Full_View
(Parent_Type
)))
9624 if not Is_Interface
(Parent_Type
)
9625 or else Is_Concurrent_Interface
(Parent_Type
)
9627 Set_Is_Limited_Record
(Derived_Type
);
9631 -- STEP 2a: process discriminants of derived type if any
9633 Push_Scope
(Derived_Type
);
9635 if Discriminant_Specs
then
9636 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
9638 -- The following call to Check_Or_Process_Discriminants initializes
9639 -- fields Has_Discriminants and Discriminant_Constraint, unless we
9640 -- are processing the completion of a private type declaration.
9641 -- Temporarily set the state of the Derived_Type to "self-hidden"
9642 -- (see RM-8.3(17)), unless it is already the case.
9644 if Is_Not_Self_Hidden
(Derived_Type
) then
9645 Set_Is_Not_Self_Hidden
(Derived_Type
, False);
9646 Check_Or_Process_Discriminants
(N
, Derived_Type
);
9647 Set_Is_Not_Self_Hidden
(Derived_Type
);
9649 Check_Or_Process_Discriminants
(N
, Derived_Type
);
9652 -- For untagged types, the constraint on the Parent_Type must be
9653 -- present and is used to rename the discriminants.
9655 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
9656 Error_Msg_N
("untagged parent must have discriminants", Indic
);
9658 elsif not Is_Tagged
and then not Constraint_Present
then
9660 ("discriminant constraint needed for derived untagged records",
9663 -- Otherwise the parent subtype must be constrained unless we have a
9664 -- private extension.
9666 elsif not Constraint_Present
9667 and then not Private_Extension
9668 and then not Is_Constrained
(Parent_Type
)
9671 ("unconstrained type not allowed in this context", Indic
);
9673 elsif Constraint_Present
then
9674 -- The following call sets the field Corresponding_Discriminant
9675 -- for the discriminants in the Derived_Type.
9677 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
9679 -- For untagged types all new discriminants must rename
9680 -- discriminants in the parent. For private extensions new
9681 -- discriminants cannot rename old ones (implied by [7.3(13)]).
9683 Discrim
:= First_Discriminant
(Derived_Type
);
9684 while Present
(Discrim
) loop
9686 and then No
(Corresponding_Discriminant
(Discrim
))
9689 ("new discriminants must constrain old ones", Discrim
);
9691 elsif Private_Extension
9692 and then Present
(Corresponding_Discriminant
(Discrim
))
9695 ("only static constraints allowed for parent"
9696 & " discriminants in the partial view", Indic
);
9700 -- If a new discriminant is used in the constraint, then its
9701 -- subtype must be statically compatible with the subtype of
9702 -- the parent discriminant (RM 3.7(15)).
9704 if Present
(Corresponding_Discriminant
(Discrim
)) then
9705 Check_Constraining_Discriminant
9706 (Discrim
, Corresponding_Discriminant
(Discrim
));
9709 Next_Discriminant
(Discrim
);
9712 -- Check whether the constraints of the full view statically
9713 -- match those imposed by the parent subtype [7.3(13)].
9715 if Present
(Stored_Constraint
(Derived_Type
)) then
9720 C1
:= First_Elmt
(Discs
);
9721 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
9722 while Present
(C1
) and then Present
(C2
) loop
9724 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9727 ("not conformant with previous declaration",
9738 -- STEP 2b: No new discriminants, inherit discriminants if any
9741 if Private_Extension
then
9742 Set_Has_Unknown_Discriminants
9744 Has_Unknown_Discriminants
(Parent_Type
)
9745 or else Unknown_Discriminants_Present
(N
));
9747 -- The partial view of the parent may have unknown discriminants,
9748 -- but if the full view has discriminants and the parent type is
9749 -- in scope they must be inherited.
9751 elsif Has_Unknown_Discriminants
(Parent_Type
)
9753 (not Has_Discriminants
(Parent_Type
)
9754 or else not In_Open_Scopes
(Scope
(Parent_Base
)))
9756 Set_Has_Unknown_Discriminants
(Derived_Type
);
9759 if not Has_Unknown_Discriminants
(Derived_Type
)
9760 and then not Has_Unknown_Discriminants
(Parent_Base
)
9761 and then Has_Discriminants
(Parent_Type
)
9763 Inherit_Discrims
:= True;
9764 Set_Has_Discriminants
9765 (Derived_Type
, True);
9766 Set_Discriminant_Constraint
9767 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
9770 -- The following test is true for private types (remember
9771 -- transformation 5. is not applied to those) and in an error
9774 if Constraint_Present
then
9775 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9778 -- For now mark a new derived type as constrained only if it has no
9779 -- discriminants. At the end of Build_Derived_Record_Type we properly
9780 -- set this flag in the case of private extensions. See comments in
9781 -- point 9. just before body of Build_Derived_Record_Type.
9785 not (Inherit_Discrims
9786 or else Has_Unknown_Discriminants
(Derived_Type
)));
9789 -- STEP 3: initialize fields of derived type
9791 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
9792 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
9794 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
9795 -- but cannot be interfaces
9797 if not Private_Extension
9798 and then Ekind
(Derived_Type
) /= E_Private_Type
9799 and then Ekind
(Derived_Type
) /= E_Limited_Private_Type
9801 if Interface_Present
(Type_Def
) then
9802 Analyze_Interface_Declaration
(Derived_Type
, Type_Def
);
9805 Set_Interfaces
(Derived_Type
, No_Elist
);
9808 -- Fields inherited from the Parent_Type
9810 Set_Has_Specified_Layout
9811 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
9812 Set_Is_Limited_Composite
9813 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
9814 Set_Is_Private_Composite
9815 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
9817 if Is_Tagged_Type
(Parent_Type
) then
9818 Set_No_Tagged_Streams_Pragma
9819 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
9822 -- Fields inherited from the Parent_Base
9824 Set_Has_Controlled_Component
9825 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
9826 Set_Has_Non_Standard_Rep
9827 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
9828 Set_Has_Primitive_Operations
9829 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
9831 -- Set fields for private derived types
9833 if Is_Private_Type
(Derived_Type
) then
9834 Set_Depends_On_Private
(Derived_Type
, True);
9835 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
9838 -- Inherit fields for non-private types. If this is the completion of a
9839 -- derivation from a private type, the parent itself is private and the
9840 -- attributes come from its full view, which must be present.
9842 if Is_Record_Type
(Derived_Type
) then
9844 Parent_Full
: Entity_Id
;
9847 if Is_Private_Type
(Parent_Base
)
9848 and then not Is_Record_Type
(Parent_Base
)
9850 Parent_Full
:= Full_View
(Parent_Base
);
9852 Parent_Full
:= Parent_Base
;
9855 Set_Component_Alignment
9856 (Derived_Type
, Component_Alignment
(Parent_Full
));
9858 (Derived_Type
, C_Pass_By_Copy
(Parent_Full
));
9859 Set_Has_Complex_Representation
9860 (Derived_Type
, Has_Complex_Representation
(Parent_Full
));
9862 -- For untagged types, inherit the layout by default to avoid
9863 -- costly changes of representation for type conversions.
9865 if not Is_Tagged
then
9866 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Full
));
9867 Set_No_Reordering
(Derived_Type
, No_Reordering
(Parent_Full
));
9872 -- Initialize the list of primitive operations to an empty list,
9873 -- to cover tagged types as well as untagged types. For untagged
9874 -- types this is used either to analyze the call as legal when
9875 -- Extensions_Allowed is True, or to issue a better error message
9878 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
9880 -- Set fields for tagged types
9883 -- All tagged types defined in Ada.Finalization are controlled
9885 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
9886 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
9887 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
9889 Set_Is_Controlled_Active
(Derived_Type
);
9891 Set_Is_Controlled_Active
9892 (Derived_Type
, Is_Controlled_Active
(Parent_Base
));
9895 -- Minor optimization: there is no need to generate the class-wide
9896 -- entity associated with an underlying record view.
9898 if not Is_Underlying_Record_View
(Derived_Type
) then
9899 Make_Class_Wide_Type
(Derived_Type
);
9902 Set_Is_Abstract_Type
(Derived_Type
, Abstract_Present
(Type_Def
));
9904 if Has_Discriminants
(Derived_Type
)
9905 and then Constraint_Present
9907 Set_Stored_Constraint
9908 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
9911 if Ada_Version
>= Ada_2005
then
9913 Ifaces_List
: Elist_Id
;
9916 -- Checks rules 3.9.4 (13/2 and 14/2)
9918 if Comes_From_Source
(Derived_Type
)
9919 and then not Is_Private_Type
(Derived_Type
)
9920 and then Is_Interface
(Parent_Type
)
9921 and then not Is_Interface
(Derived_Type
)
9923 if Is_Task_Interface
(Parent_Type
) then
9925 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
9928 elsif Is_Protected_Interface
(Parent_Type
) then
9930 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
9935 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
9937 Check_Interfaces
(N
, Type_Def
);
9939 -- Ada 2005 (AI-251): Collect the list of progenitors that are
9940 -- not already in the parents.
9944 Ifaces_List
=> Ifaces_List
,
9945 Exclude_Parents
=> True);
9947 Set_Interfaces
(Derived_Type
, Ifaces_List
);
9949 -- If the derived type is the anonymous type created for
9950 -- a declaration whose parent has a constraint, propagate
9951 -- the interface list to the source type. This must be done
9952 -- prior to the completion of the analysis of the source type
9953 -- because the components in the extension may contain current
9954 -- instances whose legality depends on some ancestor.
9956 if Is_Itype
(Derived_Type
) then
9958 Def
: constant Node_Id
:=
9959 Associated_Node_For_Itype
(Derived_Type
);
9962 and then Nkind
(Def
) = N_Full_Type_Declaration
9965 (Defining_Identifier
(Def
), Ifaces_List
);
9970 -- A type extension is automatically Ghost when one of its
9971 -- progenitors is Ghost (SPARK RM 6.9(9)). This property is
9972 -- also inherited when the parent type is Ghost, but this is
9973 -- done in Build_Derived_Type as the mechanism also handles
9974 -- untagged derivations.
9976 if Implements_Ghost_Interface
(Derived_Type
) then
9977 Set_Is_Ghost_Entity
(Derived_Type
);
9983 -- STEP 4: Inherit components from the parent base and constrain them.
9984 -- Apply the second transformation described in point 6. above.
9986 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
9987 or else not Has_Discriminants
(Parent_Type
)
9988 or else not Is_Constrained
(Parent_Type
)
9992 Constrs
:= Discriminant_Constraint
(Parent_Type
);
9997 (N
, Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
9999 -- STEP 5a: Copy the parent record declaration for untagged types
10001 Set_Has_Implicit_Dereference
10002 (Derived_Type
, Has_Implicit_Dereference
(Parent_Type
));
10004 if not Is_Tagged
then
10006 -- Discriminant_Constraint (Derived_Type) has been properly
10007 -- constructed. Save it and temporarily set it to Empty because we
10008 -- do not want the call to New_Copy_Tree below to mess this list.
10010 if Has_Discriminants
(Derived_Type
) then
10011 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
10012 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
10014 Save_Discr_Constr
:= No_Elist
;
10017 -- Save the Etype field of Derived_Type. It is correctly set now,
10018 -- but the call to New_Copy tree may remap it to point to itself,
10019 -- which is not what we want. Ditto for the Next_Entity field.
10021 Save_Etype
:= Etype
(Derived_Type
);
10022 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
10024 -- Assoc_List maps all stored discriminants in the Parent_Base to
10025 -- stored discriminants in the Derived_Type. It is fundamental that
10026 -- no types or itypes with discriminants other than the stored
10027 -- discriminants appear in the entities declared inside
10028 -- Derived_Type, since the back end cannot deal with it.
10032 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
10033 Copy_Dimensions_Of_Components
(Derived_Type
);
10035 -- Restore the fields saved prior to the New_Copy_Tree call
10036 -- and compute the stored constraint.
10038 Set_Etype
(Derived_Type
, Save_Etype
);
10039 Link_Entities
(Derived_Type
, Save_Next_Entity
);
10041 if Has_Discriminants
(Derived_Type
) then
10042 Set_Discriminant_Constraint
10043 (Derived_Type
, Save_Discr_Constr
);
10044 Set_Stored_Constraint
10045 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
10047 Replace_Discriminants
(Derived_Type
, New_Decl
);
10050 -- Relocate the aspects from the original type
10052 Remove_Aspects
(New_Decl
);
10053 Move_Aspects
(N
, New_Decl
);
10055 -- Insert the new derived type declaration
10057 Rewrite
(N
, New_Decl
);
10059 -- STEP 5b: Complete the processing for record extensions in generics
10061 -- There is no completion for record extensions declared in the
10062 -- parameter part of a generic, so we need to complete processing for
10063 -- these generic record extensions here. Record_Type_Definition will
10064 -- set the Is_Not_Self_Hidden flag.
10066 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
10067 Record_Type_Definition
(Empty
, Derived_Type
);
10069 -- STEP 5c: Process the record extension for non private tagged types
10071 elsif not Private_Extension
then
10072 Expand_Record_Extension
(Derived_Type
, Type_Def
);
10074 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
10075 -- implemented interfaces if we are in expansion mode
10078 and then Has_Interfaces
(Derived_Type
)
10080 Add_Interface_Tag_Components
(N
, Derived_Type
);
10083 -- Analyze the record extension
10085 Record_Type_Definition
10086 (Record_Extension_Part
(Type_Def
), Derived_Type
);
10091 -- Nothing else to do if there is an error in the derivation.
10092 -- An unusual case: the full view may be derived from a type in an
10093 -- instance, when the partial view was used illegally as an actual
10094 -- in that instance, leading to a circular definition.
10096 if Etype
(Derived_Type
) = Any_Type
10097 or else Etype
(Parent_Type
) = Derived_Type
10102 -- Set delayed freeze and then derive subprograms, we need to do
10103 -- this in this order so that derived subprograms inherit the
10104 -- derived freeze if necessary.
10106 Set_Has_Delayed_Freeze
(Derived_Type
);
10108 if Derive_Subps
then
10109 Derive_Subprograms
(Parent_Type
, Derived_Type
);
10112 -- If we have a private extension which defines a constrained derived
10113 -- type mark as constrained here after we have derived subprograms. See
10114 -- comment on point 9. just above the body of Build_Derived_Record_Type.
10116 if Private_Extension
and then Inherit_Discrims
then
10117 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
10118 Set_Is_Constrained
(Derived_Type
, True);
10119 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
10121 elsif Is_Constrained
(Parent_Type
) then
10123 (Derived_Type
, True);
10124 Set_Discriminant_Constraint
10125 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
10129 -- Update the class-wide type, which shares the now-completed entity
10130 -- list with its specific type. In case of underlying record views,
10131 -- we do not generate the corresponding class wide entity.
10134 and then not Is_Underlying_Record_View
(Derived_Type
)
10137 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
10139 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
10142 Check_Function_Writable_Actuals
(N
);
10143 end Build_Derived_Record_Type
;
10145 ------------------------
10146 -- Build_Derived_Type --
10147 ------------------------
10149 procedure Build_Derived_Type
10151 Parent_Type
: Entity_Id
;
10152 Derived_Type
: Entity_Id
;
10153 Is_Completion
: Boolean;
10154 Derive_Subps
: Boolean := True)
10156 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
10159 -- Set common attributes
10161 if Ekind
(Derived_Type
) in Incomplete_Or_Private_Kind
10162 and then Ekind
(Parent_Base
) in Elementary_Kind
10164 Reinit_Field_To_Zero
(Derived_Type
, F_Discriminant_Constraint
);
10167 Set_Scope
(Derived_Type
, Current_Scope
);
10168 Set_Etype
(Derived_Type
, Parent_Base
);
10169 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
10170 Propagate_Concurrent_Flags
(Derived_Type
, Parent_Base
);
10172 Set_Size_Info
(Derived_Type
, Parent_Type
);
10173 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
10175 Set_Is_Controlled_Active
10176 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
10178 Set_Disable_Controlled
(Derived_Type
, Disable_Controlled
(Parent_Type
));
10179 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged_Type
(Parent_Type
));
10180 Set_Is_Volatile
(Derived_Type
, Is_Volatile
(Parent_Type
));
10182 if Is_Tagged_Type
(Derived_Type
) then
10183 Set_No_Tagged_Streams_Pragma
10184 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
10187 -- If the parent has primitive routines and may have not-seen-yet aspect
10188 -- specifications (e.g., a Pack pragma), then set the derived type link
10189 -- in order to later diagnose "early derivation" issues. If in different
10190 -- compilation units, then "early derivation" cannot be an issue (and we
10191 -- don't like interunit references that go in the opposite direction of
10192 -- semantic dependencies).
10194 if Has_Primitive_Operations
(Parent_Type
)
10195 and then Enclosing_Comp_Unit_Node
(Parent_Type
) =
10196 Enclosing_Comp_Unit_Node
(Derived_Type
)
10198 Set_Derived_Type_Link
(Parent_Base
, Derived_Type
);
10201 -- If the parent type is a private subtype, the convention on the base
10202 -- type may be set in the private part, and not propagated to the
10203 -- subtype until later, so we obtain the convention from the base type.
10205 Set_Convention
(Derived_Type
, Convention
(Parent_Base
));
10207 if Is_Tagged_Type
(Derived_Type
)
10208 and then Present
(Class_Wide_Type
(Derived_Type
))
10210 Set_Convention
(Class_Wide_Type
(Derived_Type
),
10211 Convention
(Class_Wide_Type
(Parent_Base
)));
10214 -- Set SSO default for record or array type
10216 if (Is_Array_Type
(Derived_Type
) or else Is_Record_Type
(Derived_Type
))
10217 and then Is_Base_Type
(Derived_Type
)
10219 Set_Default_SSO
(Derived_Type
);
10222 -- A derived type inherits the Default_Initial_Condition pragma coming
10223 -- from any parent type within the derivation chain.
10225 if Has_DIC
(Parent_Type
) then
10226 Set_Has_Inherited_DIC
(Derived_Type
);
10229 -- A derived type inherits any class-wide invariants coming from a
10230 -- parent type or an interface. Note that the invariant procedure of
10231 -- the parent type should not be inherited because the derived type may
10232 -- define invariants of its own.
10234 if not Is_Interface
(Derived_Type
) then
10235 if Has_Inherited_Invariants
(Parent_Type
)
10236 or else Has_Inheritable_Invariants
(Parent_Type
)
10238 Set_Has_Inherited_Invariants
(Derived_Type
);
10240 elsif Is_Concurrent_Type
(Derived_Type
)
10241 or else Is_Tagged_Type
(Derived_Type
)
10246 Iface_Elmt
: Elmt_Id
;
10250 (T
=> Derived_Type
,
10251 Ifaces_List
=> Ifaces
,
10252 Exclude_Parents
=> True);
10254 if Present
(Ifaces
) then
10255 Iface_Elmt
:= First_Elmt
(Ifaces
);
10256 while Present
(Iface_Elmt
) loop
10257 Iface
:= Node
(Iface_Elmt
);
10259 if Has_Inheritable_Invariants
(Iface
) then
10260 Set_Has_Inherited_Invariants
(Derived_Type
);
10264 Next_Elmt
(Iface_Elmt
);
10271 -- We similarly inherit predicates
10273 Inherit_Predicate_Flags
(Derived_Type
, Parent_Type
, Only_Flags
=> True);
10275 -- The derived type inherits representation clauses from the parent
10276 -- type, and from any interfaces.
10278 Inherit_Rep_Item_Chain
(Derived_Type
, Parent_Type
);
10281 Iface
: Node_Id
:= First
(Abstract_Interface_List
(Derived_Type
));
10283 while Present
(Iface
) loop
10284 Inherit_Rep_Item_Chain
(Derived_Type
, Entity
(Iface
));
10289 -- If the parent type has delayed rep aspects, then mark the derived
10290 -- type as possibly inheriting a delayed rep aspect.
10292 if Has_Delayed_Rep_Aspects
(Parent_Type
) then
10293 Set_May_Inherit_Delayed_Rep_Aspects
(Derived_Type
);
10296 -- A derived type becomes Ghost when its parent type is also Ghost
10297 -- (SPARK RM 6.9(9)). Note that the Ghost-related attributes are not
10298 -- directly inherited because the Ghost policy in effect may differ.
10300 if Is_Ghost_Entity
(Parent_Type
) then
10301 Set_Is_Ghost_Entity
(Derived_Type
);
10304 -- Type dependent processing
10306 case Ekind
(Parent_Type
) is
10307 when Numeric_Kind
=>
10308 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
10311 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
10313 when Class_Wide_Kind
10317 Build_Derived_Record_Type
10318 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
10321 when Enumeration_Kind
=>
10322 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
10324 when Access_Kind
=>
10325 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
10327 when Incomplete_Or_Private_Kind
=>
10328 Build_Derived_Private_Type
10329 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
10331 -- For discriminated types, the derivation includes deriving
10332 -- primitive operations. For others it is done below.
10334 if Is_Tagged_Type
(Parent_Type
)
10335 or else Has_Discriminants
(Parent_Type
)
10336 or else (Present
(Full_View
(Parent_Type
))
10337 and then Has_Discriminants
(Full_View
(Parent_Type
)))
10342 when Concurrent_Kind
=>
10343 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
10346 raise Program_Error
;
10349 -- Nothing more to do if some error occurred
10351 if Etype
(Derived_Type
) = Any_Type
then
10355 -- If not already set, initialize the derived type's list of primitive
10356 -- operations to an empty element list.
10358 if No
(Direct_Primitive_Operations
(Derived_Type
)) then
10359 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
10361 -- If Etype of the derived type is the base type (as opposed to
10362 -- a parent type) and doesn't have an associated list of primitive
10363 -- operations, then set the base type's primitive list to the
10364 -- derived type's list. The lists need to be shared in common
10365 -- between the two.
10367 if Etype
(Derived_Type
) = Base_Type
(Derived_Type
)
10368 and then No
(Direct_Primitive_Operations
(Etype
(Derived_Type
)))
10370 Set_Direct_Primitive_Operations
10371 (Etype
(Derived_Type
),
10372 Direct_Primitive_Operations
(Derived_Type
));
10376 -- Set delayed freeze and then derive subprograms, we need to do this
10377 -- in this order so that derived subprograms inherit the derived freeze
10380 Set_Has_Delayed_Freeze
(Derived_Type
);
10382 if Derive_Subps
then
10383 Derive_Subprograms
(Parent_Type
, Derived_Type
);
10386 Set_Has_Primitive_Operations
10387 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
10388 end Build_Derived_Type
;
10390 -----------------------
10391 -- Build_Discriminal --
10392 -----------------------
10394 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
10395 D_Minal
: Entity_Id
;
10396 CR_Disc
: Entity_Id
;
10399 -- A discriminal has the same name as the discriminant
10401 D_Minal
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10403 Mutate_Ekind
(D_Minal
, E_In_Parameter
);
10404 Set_Mechanism
(D_Minal
, Default_Mechanism
);
10405 Set_Etype
(D_Minal
, Etype
(Discrim
));
10406 Set_Scope
(D_Minal
, Current_Scope
);
10407 Set_Parent
(D_Minal
, Parent
(Discrim
));
10409 Set_Discriminal
(Discrim
, D_Minal
);
10410 Set_Discriminal_Link
(D_Minal
, Discrim
);
10412 -- For task types, build at once the discriminants of the corresponding
10413 -- record, which are needed if discriminants are used in entry defaults
10414 -- and in family bounds.
10416 if Is_Concurrent_Type
(Current_Scope
)
10418 Is_Limited_Type
(Current_Scope
)
10420 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10422 Mutate_Ekind
(CR_Disc
, E_In_Parameter
);
10423 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
10424 Set_Etype
(CR_Disc
, Etype
(Discrim
));
10425 Set_Scope
(CR_Disc
, Current_Scope
);
10426 Set_Discriminal_Link
(CR_Disc
, Discrim
);
10427 Set_CR_Discriminant
(Discrim
, CR_Disc
);
10429 end Build_Discriminal
;
10431 ------------------------------------
10432 -- Build_Discriminant_Constraints --
10433 ------------------------------------
10435 function Build_Discriminant_Constraints
10438 Derived_Def
: Boolean := False) return Elist_Id
10440 C
: constant Node_Id
:= Constraint
(Def
);
10441 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
10443 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
10444 -- Saves the expression corresponding to a given discriminant in T
10446 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
10447 -- Return the Position number within array Discr_Expr of a discriminant
10448 -- D within the discriminant list of the discriminated type T.
10450 procedure Process_Discriminant_Expression
10453 -- If this is a discriminant constraint on a partial view, do not
10454 -- generate an overflow check on the discriminant expression. The check
10455 -- will be generated when constraining the full view. Otherwise the
10456 -- backend creates duplicate symbols for the temporaries corresponding
10457 -- to the expressions to be checked, causing spurious assembler errors.
10463 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
10467 Disc
:= First_Discriminant
(T
);
10468 for J
in Discr_Expr
'Range loop
10473 Next_Discriminant
(Disc
);
10476 -- Note: Since this function is called on discriminants that are
10477 -- known to belong to the discriminated type, falling through the
10478 -- loop with no match signals an internal compiler error.
10480 raise Program_Error
;
10483 -------------------------------------
10484 -- Process_Discriminant_Expression --
10485 -------------------------------------
10487 procedure Process_Discriminant_Expression
10491 BDT
: constant Entity_Id
:= Base_Type
(Etype
(D
));
10494 -- If this is a discriminant constraint on a partial view, do
10495 -- not generate an overflow on the discriminant expression. The
10496 -- check will be generated when constraining the full view.
10498 if Is_Private_Type
(T
)
10499 and then Present
(Full_View
(T
))
10501 Analyze_And_Resolve
(Expr
, BDT
, Suppress
=> Overflow_Check
);
10503 Analyze_And_Resolve
(Expr
, BDT
);
10505 end Process_Discriminant_Expression
;
10507 -- Declarations local to Build_Discriminant_Constraints
10511 Elist
: constant Elist_Id
:= New_Elmt_List
;
10519 Discrim_Present
: Boolean := False;
10521 -- Start of processing for Build_Discriminant_Constraints
10524 -- The following loop will process positional associations only.
10525 -- For a positional association, the (single) discriminant is
10526 -- implicitly specified by position, in textual order (RM 3.7.2).
10528 Discr
:= First_Discriminant
(T
);
10529 Constr
:= First
(Constraints
(C
));
10530 for D
in Discr_Expr
'Range loop
10531 exit when Nkind
(Constr
) = N_Discriminant_Association
;
10533 if No
(Constr
) then
10534 Error_Msg_N
("too few discriminants given in constraint", C
);
10535 return New_Elmt_List
;
10537 elsif Nkind
(Constr
) = N_Range
10538 or else (Nkind
(Constr
) = N_Attribute_Reference
10539 and then Attribute_Name
(Constr
) = Name_Range
)
10542 ("a range is not a valid discriminant constraint", Constr
);
10543 Discr_Expr
(D
) := Error
;
10545 elsif Nkind
(Constr
) = N_Subtype_Indication
then
10547 ("a subtype indication is not a valid discriminant constraint",
10549 Discr_Expr
(D
) := Error
;
10552 Process_Discriminant_Expression
(Constr
, Discr
);
10553 Discr_Expr
(D
) := Constr
;
10556 Next_Discriminant
(Discr
);
10560 if No
(Discr
) and then Present
(Constr
) then
10561 Error_Msg_N
("too many discriminants given in constraint", Constr
);
10562 return New_Elmt_List
;
10565 -- Named associations can be given in any order, but if both positional
10566 -- and named associations are used in the same discriminant constraint,
10567 -- then positional associations must occur first, at their normal
10568 -- position. Hence once a named association is used, the rest of the
10569 -- discriminant constraint must use only named associations.
10571 while Present
(Constr
) loop
10573 -- Positional association forbidden after a named association
10575 if Nkind
(Constr
) /= N_Discriminant_Association
then
10576 Error_Msg_N
("positional association follows named one", Constr
);
10577 return New_Elmt_List
;
10579 -- Otherwise it is a named association
10582 -- E records the type of the discriminants in the named
10583 -- association. All the discriminants specified in the same name
10584 -- association must have the same type.
10588 -- Search the list of discriminants in T to see if the simple name
10589 -- given in the constraint matches any of them.
10591 Id
:= First
(Selector_Names
(Constr
));
10592 while Present
(Id
) loop
10595 -- If Original_Discriminant is present, we are processing a
10596 -- generic instantiation and this is an instance node. We need
10597 -- to find the name of the corresponding discriminant in the
10598 -- actual record type T and not the name of the discriminant in
10599 -- the generic formal. Example:
10602 -- type G (D : int) is private;
10604 -- subtype W is G (D => 1);
10606 -- type Rec (X : int) is record ... end record;
10607 -- package Q is new P (G => Rec);
10609 -- At the point of the instantiation, formal type G is Rec
10610 -- and therefore when reanalyzing "subtype W is G (D => 1);"
10611 -- which really looks like "subtype W is Rec (D => 1);" at
10612 -- the point of instantiation, we want to find the discriminant
10613 -- that corresponds to D in Rec, i.e. X.
10615 if Present
(Original_Discriminant
(Id
))
10616 and then In_Instance
10618 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
10622 Discr
:= First_Discriminant
(T
);
10623 while Present
(Discr
) loop
10624 if Chars
(Discr
) = Chars
(Id
) then
10629 Next_Discriminant
(Discr
);
10633 Error_Msg_N
("& does not match any discriminant", Id
);
10634 return New_Elmt_List
;
10636 -- If the parent type is a generic formal, preserve the
10637 -- name of the discriminant for subsequent instances.
10638 -- see comment at the beginning of this if statement.
10640 elsif Is_Generic_Type
(Root_Type
(T
)) then
10641 Set_Original_Discriminant
(Id
, Discr
);
10645 Position
:= Pos_Of_Discr
(T
, Discr
);
10647 if Present
(Discr_Expr
(Position
)) then
10648 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
10651 -- Each discriminant specified in the same named association
10652 -- must be associated with a separate copy of the
10653 -- corresponding expression.
10655 if Present
(Next
(Id
)) then
10656 Expr
:= New_Copy_Tree
(Expression
(Constr
));
10657 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
10659 Expr
:= Expression
(Constr
);
10662 Discr_Expr
(Position
) := Expr
;
10663 Process_Discriminant_Expression
(Expr
, Discr
);
10666 -- A discriminant association with more than one discriminant
10667 -- name is only allowed if the named discriminants are all of
10668 -- the same type (RM 3.7.1(8)).
10671 E
:= Base_Type
(Etype
(Discr
));
10673 elsif Base_Type
(Etype
(Discr
)) /= E
then
10675 ("all discriminants in an association " &
10676 "must have the same type", Id
);
10686 -- A discriminant constraint must provide exactly one value for each
10687 -- discriminant of the type (RM 3.7.1(8)).
10689 for J
in Discr_Expr
'Range loop
10690 if No
(Discr_Expr
(J
)) then
10691 Error_Msg_N
("too few discriminants given in constraint", C
);
10692 return New_Elmt_List
;
10696 -- Determine if there are discriminant expressions in the constraint
10698 for J
in Discr_Expr
'Range loop
10699 if Denotes_Discriminant
10700 (Discr_Expr
(J
), Check_Concurrent
=> True)
10702 Discrim_Present
:= True;
10707 -- Build an element list consisting of the expressions given in the
10708 -- discriminant constraint and apply the appropriate checks. The list
10709 -- is constructed after resolving any named discriminant associations
10710 -- and therefore the expressions appear in the textual order of the
10713 Discr
:= First_Discriminant
(T
);
10714 for J
in Discr_Expr
'Range loop
10715 if Discr_Expr
(J
) /= Error
then
10716 Append_Elmt
(Discr_Expr
(J
), Elist
);
10718 -- If any of the discriminant constraints is given by a
10719 -- discriminant and we are in a derived type declaration we
10720 -- have a discriminant renaming. Establish link between new
10721 -- and old discriminant. The new discriminant has an implicit
10722 -- dereference if the old one does.
10724 if Denotes_Discriminant
(Discr_Expr
(J
)) then
10725 if Derived_Def
then
10727 New_Discr
: constant Entity_Id
:= Entity
(Discr_Expr
(J
));
10730 Set_Corresponding_Discriminant
(New_Discr
, Discr
);
10731 Set_Has_Implicit_Dereference
(New_Discr
,
10732 Has_Implicit_Dereference
(Discr
));
10736 -- Force the evaluation of non-discriminant expressions.
10737 -- If we have found a discriminant in the constraint 3.4(26)
10738 -- and 3.8(18) demand that no range checks are performed are
10739 -- after evaluation. If the constraint is for a component
10740 -- definition that has a per-object constraint, expressions are
10741 -- evaluated but not checked either. In all other cases perform
10745 if Discrim_Present
then
10748 elsif Parent_Kind
(Parent
(Def
)) = N_Component_Declaration
10749 and then Has_Per_Object_Constraint
10750 (Defining_Identifier
(Parent
(Parent
(Def
))))
10754 elsif Is_Access_Type
(Etype
(Discr
)) then
10755 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
10758 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
10761 -- If the value of the discriminant may be visible in
10762 -- another unit or child unit, create an external name
10763 -- for it. We use the name of the object or component
10764 -- that carries the discriminated subtype. The code
10765 -- below may generate external symbols for the discriminant
10766 -- expression when not strictly needed, which is harmless.
10769 and then Comes_From_Source
(Def
)
10770 and then not Is_Subprogram
(Current_Scope
)
10773 Id
: Entity_Id
:= Empty
;
10775 if Nkind
(Parent
(Def
)) = N_Object_Declaration
then
10776 Id
:= Defining_Identifier
(Parent
(Def
));
10778 elsif Nkind
(Parent
(Def
)) = N_Component_Definition
10780 Nkind
(Parent
(Parent
(Def
)))
10781 = N_Component_Declaration
10783 Id
:= Defining_Identifier
(Parent
(Parent
(Def
)));
10786 if Present
(Id
) then
10790 Discr_Number
=> J
);
10792 Force_Evaluation
(Discr_Expr
(J
));
10796 Force_Evaluation
(Discr_Expr
(J
));
10800 -- Check that the designated type of an access discriminant's
10801 -- expression is not a class-wide type unless the discriminant's
10802 -- designated type is also class-wide.
10804 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
10805 and then not Is_Class_Wide_Type
10806 (Designated_Type
(Etype
(Discr
)))
10807 and then Etype
(Discr_Expr
(J
)) /= Any_Type
10808 and then Is_Class_Wide_Type
10809 (Designated_Type
(Etype
(Discr_Expr
(J
))))
10811 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
10813 elsif Is_Access_Type
(Etype
(Discr
))
10814 and then not Is_Access_Constant
(Etype
(Discr
))
10815 and then Is_Access_Type
(Etype
(Discr_Expr
(J
)))
10816 and then Is_Access_Constant
(Etype
(Discr_Expr
(J
)))
10819 ("constraint for discriminant& must be access to variable",
10824 Next_Discriminant
(Discr
);
10828 end Build_Discriminant_Constraints
;
10830 ---------------------------------
10831 -- Build_Discriminated_Subtype --
10832 ---------------------------------
10834 procedure Build_Discriminated_Subtype
10836 Def_Id
: Entity_Id
;
10838 Related_Nod
: Node_Id
;
10839 For_Access
: Boolean := False)
10841 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
10842 Constrained
: constant Boolean :=
10844 and then not Is_Empty_Elmt_List
(Elist
)
10845 and then not Is_Class_Wide_Type
(T
))
10846 or else Is_Constrained
(T
);
10849 if Ekind
(T
) = E_Record_Type
then
10850 Mutate_Ekind
(Def_Id
, E_Record_Subtype
);
10852 -- Inherit preelaboration flag from base, for types for which it
10853 -- may have been set: records, private types, protected types.
10855 Set_Known_To_Have_Preelab_Init
10856 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10858 elsif Ekind
(T
) = E_Task_Type
then
10859 Mutate_Ekind
(Def_Id
, E_Task_Subtype
);
10861 elsif Ekind
(T
) = E_Protected_Type
then
10862 Mutate_Ekind
(Def_Id
, E_Protected_Subtype
);
10863 Set_Known_To_Have_Preelab_Init
10864 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10866 elsif Is_Private_Type
(T
) then
10867 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
10868 Set_Known_To_Have_Preelab_Init
10869 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10871 -- Private subtypes may have private dependents
10873 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
10875 elsif Is_Class_Wide_Type
(T
) then
10876 Mutate_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
10879 -- Incomplete type. Attach subtype to list of dependents, to be
10880 -- completed with full view of parent type, unless is it the
10881 -- designated subtype of a record component within an init_proc.
10882 -- This last case arises for a component of an access type whose
10883 -- designated type is incomplete (e.g. a Taft Amendment type).
10884 -- The designated subtype is within an inner scope, and needs no
10885 -- elaboration, because only the access type is needed in the
10886 -- initialization procedure.
10888 if Ekind
(T
) = E_Incomplete_Type
then
10889 Mutate_Ekind
(Def_Id
, E_Incomplete_Subtype
);
10891 Mutate_Ekind
(Def_Id
, Ekind
(T
));
10894 if For_Access
and then Within_Init_Proc
then
10897 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
10901 Set_Etype
(Def_Id
, T
);
10902 Reinit_Size_Align
(Def_Id
);
10903 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
10904 Set_Is_Constrained
(Def_Id
, Constrained
);
10906 Set_First_Entity
(Def_Id
, First_Entity
(T
));
10907 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
10908 Set_Has_Implicit_Dereference
10909 (Def_Id
, Has_Implicit_Dereference
(T
));
10910 Set_Has_Pragma_Unreferenced_Objects
10911 (Def_Id
, Has_Pragma_Unreferenced_Objects
(T
));
10913 -- If the subtype is the completion of a private declaration, there may
10914 -- have been representation clauses for the partial view, and they must
10915 -- be preserved. Build_Derived_Type chains the inherited clauses with
10916 -- the ones appearing on the extension. If this comes from a subtype
10917 -- declaration, all clauses are inherited.
10919 if No
(First_Rep_Item
(Def_Id
)) then
10920 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10923 if Is_Tagged_Type
(T
) then
10924 Set_Is_Tagged_Type
(Def_Id
);
10925 Set_No_Tagged_Streams_Pragma
(Def_Id
, No_Tagged_Streams_Pragma
(T
));
10926 Make_Class_Wide_Type
(Def_Id
);
10929 Set_Stored_Constraint
(Def_Id
, No_Elist
);
10932 Set_Discriminant_Constraint
(Def_Id
, Elist
);
10933 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
10936 if Is_Tagged_Type
(T
) then
10938 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
10939 -- concurrent record type (which has the list of primitive
10942 if Ada_Version
>= Ada_2005
10943 and then Is_Concurrent_Type
(T
)
10945 Set_Corresponding_Record_Type
(Def_Id
,
10946 Corresponding_Record_Type
(T
));
10948 Set_Direct_Primitive_Operations
(Def_Id
,
10949 Direct_Primitive_Operations
(T
));
10952 Set_Is_Abstract_Type
(Def_Id
, Is_Abstract_Type
(T
));
10955 -- Subtypes introduced by component declarations do not need to be
10956 -- marked as delayed, and do not get freeze nodes, because the semantics
10957 -- verifies that the parents of the subtypes are frozen before the
10958 -- enclosing record is frozen.
10960 if not Is_Type
(Scope
(Def_Id
)) then
10961 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
10963 if Is_Private_Type
(T
)
10964 and then Present
(Full_View
(T
))
10966 Conditional_Delay
(Def_Id
, Full_View
(T
));
10968 Conditional_Delay
(Def_Id
, T
);
10972 if Is_Record_Type
(T
) then
10973 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
10976 and then not Is_Empty_Elmt_List
(Elist
)
10977 and then not For_Access
10979 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
10981 elsif not Is_Private_Type
(T
) then
10982 Set_Cloned_Subtype
(Def_Id
, T
);
10985 end Build_Discriminated_Subtype
;
10987 ---------------------------
10988 -- Build_Itype_Reference --
10989 ---------------------------
10991 procedure Build_Itype_Reference
10995 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(Nod
));
10998 -- Itype references are only created for use by the back-end
11000 if Inside_A_Generic
then
11003 Set_Itype
(IR
, Ityp
);
11005 -- If Nod is a library unit entity, then Insert_After won't work,
11006 -- because Nod is not a member of any list. Therefore, we use
11007 -- Add_Global_Declaration in this case. This can happen if we have a
11008 -- build-in-place library function, child unit or not.
11010 if (Nkind
(Nod
) in N_Entity
and then Is_Compilation_Unit
(Nod
))
11011 or else (Nkind
(Nod
) in
11012 N_Defining_Program_Unit_Name | N_Subprogram_Declaration
11013 and then Is_Compilation_Unit
(Defining_Entity
(Nod
)))
11015 Add_Global_Declaration
(IR
);
11017 Insert_After
(Nod
, IR
);
11020 end Build_Itype_Reference
;
11022 ------------------------
11023 -- Build_Scalar_Bound --
11024 ------------------------
11026 function Build_Scalar_Bound
11029 Der_T
: Entity_Id
) return Node_Id
11031 New_Bound
: Entity_Id
;
11034 -- Note: not clear why this is needed, how can the original bound
11035 -- be unanalyzed at this point? and if it is, what business do we
11036 -- have messing around with it? and why is the base type of the
11037 -- parent type the right type for the resolution. It probably is
11038 -- not. It is OK for the new bound we are creating, but not for
11039 -- the old one??? Still if it never happens, no problem.
11041 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
11043 if Nkind
(Bound
) in N_Integer_Literal | N_Real_Literal
then
11044 New_Bound
:= New_Copy
(Bound
);
11045 Set_Etype
(New_Bound
, Der_T
);
11046 Set_Analyzed
(New_Bound
);
11048 elsif Is_Entity_Name
(Bound
) then
11049 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
11051 -- The following is almost certainly wrong. What business do we have
11052 -- relocating a node (Bound) that is presumably still attached to
11053 -- the tree elsewhere???
11056 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
11059 Set_Etype
(New_Bound
, Der_T
);
11061 end Build_Scalar_Bound
;
11063 -------------------------------
11064 -- Check_Abstract_Overriding --
11065 -------------------------------
11067 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
11068 Alias_Subp
: Entity_Id
;
11070 Op_List
: Elist_Id
;
11072 Type_Def
: Node_Id
;
11074 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
);
11075 -- Ada 2012 (AI05-0030): Subprogram Subp overrides an interface routine
11076 -- which has pragma Implemented already set. Check whether Subp's entity
11077 -- kind conforms to the implementation kind of the overridden routine.
11079 procedure Check_Pragma_Implemented
11081 Iface_Subp
: Entity_Id
);
11082 -- Ada 2012 (AI05-0030): Subprogram Subp overrides interface routine
11083 -- Iface_Subp and both entities have pragma Implemented already set on
11084 -- them. Check whether the two implementation kinds are conforming.
11086 procedure Inherit_Pragma_Implemented
11088 Iface_Subp
: Entity_Id
);
11089 -- Ada 2012 (AI05-0030): Interface primitive Subp overrides interface
11090 -- subprogram Iface_Subp which has been marked by pragma Implemented.
11091 -- Propagate the implementation kind of Iface_Subp to Subp.
11093 ------------------------------
11094 -- Check_Pragma_Implemented --
11095 ------------------------------
11097 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
) is
11098 Iface_Alias
: constant Entity_Id
:= Interface_Alias
(Subp
);
11099 Impl_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Alias
);
11100 Subp_Alias
: constant Entity_Id
:= Alias
(Subp
);
11101 Contr_Typ
: Entity_Id
;
11102 Impl_Subp
: Entity_Id
;
11105 -- Subp must have an alias since it is a hidden entity used to link
11106 -- an interface subprogram to its overriding counterpart.
11108 pragma Assert
(Present
(Subp_Alias
));
11110 -- Handle aliases to synchronized wrappers
11112 Impl_Subp
:= Subp_Alias
;
11114 if Is_Primitive_Wrapper
(Impl_Subp
) then
11115 Impl_Subp
:= Wrapped_Entity
(Impl_Subp
);
11118 -- Extract the type of the controlling formal
11120 Contr_Typ
:= Etype
(First_Formal
(Subp_Alias
));
11122 if Is_Concurrent_Record_Type
(Contr_Typ
) then
11123 Contr_Typ
:= Corresponding_Concurrent_Type
(Contr_Typ
);
11126 -- An interface subprogram whose implementation kind is By_Entry must
11127 -- be implemented by an entry.
11129 if Impl_Kind
= Name_By_Entry
11130 and then Ekind
(Impl_Subp
) /= E_Entry
11132 Error_Msg_Node_2
:= Iface_Alias
;
11134 ("type & must implement abstract subprogram & with an entry",
11135 Subp_Alias
, Contr_Typ
);
11137 elsif Impl_Kind
= Name_By_Protected_Procedure
then
11139 -- An interface subprogram whose implementation kind is By_
11140 -- Protected_Procedure cannot be implemented by a primitive
11141 -- procedure of a task type.
11143 if Ekind
(Contr_Typ
) /= E_Protected_Type
then
11144 Error_Msg_Node_2
:= Contr_Typ
;
11146 ("interface subprogram & cannot be implemented by a "
11147 & "primitive procedure of task type &",
11148 Subp_Alias
, Iface_Alias
);
11150 -- An interface subprogram whose implementation kind is By_
11151 -- Protected_Procedure must be implemented by a procedure.
11153 elsif Ekind
(Impl_Subp
) /= E_Procedure
then
11154 Error_Msg_Node_2
:= Iface_Alias
;
11156 ("type & must implement abstract subprogram & with a "
11157 & "procedure", Subp_Alias
, Contr_Typ
);
11159 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
11160 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
11162 Error_Msg_Name_1
:= Impl_Kind
;
11164 ("overriding operation& must have synchronization%",
11168 -- If primitive has Optional synchronization, overriding operation
11169 -- must match if it has an explicit synchronization.
11171 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
11172 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
11174 Error_Msg_Name_1
:= Impl_Kind
;
11176 ("overriding operation& must have synchronization%", Subp_Alias
);
11178 end Check_Pragma_Implemented
;
11180 ------------------------------
11181 -- Check_Pragma_Implemented --
11182 ------------------------------
11184 procedure Check_Pragma_Implemented
11186 Iface_Subp
: Entity_Id
)
11188 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
11189 Subp_Kind
: constant Name_Id
:= Implementation_Kind
(Subp
);
11192 -- Ada 2012 (AI05-0030): The implementation kinds of an overridden
11193 -- and overriding subprogram are different. In general this is an
11194 -- error except when the implementation kind of the overridden
11195 -- subprograms is By_Any or Optional.
11197 if Iface_Kind
/= Subp_Kind
11198 and then Iface_Kind
/= Name_By_Any
11199 and then Iface_Kind
/= Name_Optional
11201 if Iface_Kind
= Name_By_Entry
then
11203 ("incompatible implementation kind, overridden subprogram " &
11204 "is marked By_Entry", Subp
);
11207 ("incompatible implementation kind, overridden subprogram " &
11208 "is marked By_Protected_Procedure", Subp
);
11211 end Check_Pragma_Implemented
;
11213 --------------------------------
11214 -- Inherit_Pragma_Implemented --
11215 --------------------------------
11217 procedure Inherit_Pragma_Implemented
11219 Iface_Subp
: Entity_Id
)
11221 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
11222 Loc
: constant Source_Ptr
:= Sloc
(Subp
);
11223 Impl_Prag
: Node_Id
;
11226 -- Since the implementation kind is stored as a representation item
11227 -- rather than a flag, create a pragma node.
11231 Chars
=> Name_Implemented
,
11232 Pragma_Argument_Associations
=> New_List
(
11233 Make_Pragma_Argument_Association
(Loc
,
11234 Expression
=> New_Occurrence_Of
(Subp
, Loc
)),
11236 Make_Pragma_Argument_Association
(Loc
,
11237 Expression
=> Make_Identifier
(Loc
, Iface_Kind
))));
11239 -- The pragma doesn't need to be analyzed because it is internally
11240 -- built. It is safe to directly register it as a rep item since we
11241 -- are only interested in the characters of the implementation kind.
11243 Record_Rep_Item
(Subp
, Impl_Prag
);
11244 end Inherit_Pragma_Implemented
;
11246 -- Start of processing for Check_Abstract_Overriding
11249 Op_List
:= Primitive_Operations
(T
);
11251 -- Loop to check primitive operations
11253 Elmt
:= First_Elmt
(Op_List
);
11254 while Present
(Elmt
) loop
11255 Subp
:= Node
(Elmt
);
11256 Alias_Subp
:= Alias
(Subp
);
11258 -- If the parent type is untagged, then no overriding error checks
11259 -- are needed (such as in the case of an implicit full type for
11260 -- a derived type whose parent is an untagged private type with
11261 -- a tagged full type).
11263 if not Is_Tagged_Type
(Etype
(T
)) then
11266 -- Inherited subprograms are identified by the fact that they do not
11267 -- come from source, and the associated source location is the
11268 -- location of the first subtype of the derived type.
11270 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
11271 -- subprograms that "require overriding".
11273 -- Special exception, do not complain about failure to override the
11274 -- stream routines _Input and _Output, as well as the primitive
11275 -- operations used in dispatching selects since we always provide
11276 -- automatic overridings for these subprograms.
11278 -- The partial view of T may have been a private extension, for
11279 -- which inherited functions dispatching on result are abstract.
11280 -- If the full view is a null extension, there is no need for
11281 -- overriding in Ada 2005, but wrappers need to be built for them
11282 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
11284 elsif Is_Null_Extension
(T
)
11285 and then Has_Controlling_Result
(Subp
)
11286 and then Ada_Version
>= Ada_2005
11287 and then Present
(Alias_Subp
)
11288 and then not Comes_From_Source
(Subp
)
11289 and then not Is_Abstract_Subprogram
(Alias_Subp
)
11290 and then not Is_Access_Type
(Etype
(Subp
))
11294 -- Ada 2005 (AI-251): Internal entities of interfaces need no
11295 -- processing because this check is done with the aliased
11298 elsif Present
(Interface_Alias
(Subp
)) then
11301 -- AI12-0042: Test for rule in 7.3.2(6.1/4), that requires overriding
11302 -- of a visible private primitive inherited from an ancestor with
11303 -- the aspect Type_Invariant'Class, unless the inherited primitive
11306 elsif not Is_Abstract_Subprogram
(Subp
)
11307 and then not Comes_From_Source
(Subp
) -- An inherited subprogram
11308 and then Requires_Overriding
(Subp
)
11309 and then Present
(Alias_Subp
)
11310 and then Has_Invariants
(Etype
(T
))
11311 and then Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11312 and then Class_Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11313 and then Is_Private_Primitive
(Alias_Subp
)
11316 ("inherited private primitive & must be overridden", T
, Subp
);
11318 ("\because ancestor type has 'Type_'Invariant''Class " &
11319 "(RM 7.3.2(6.1))", T
);
11321 elsif (Is_Abstract_Subprogram
(Subp
)
11322 or else Requires_Overriding
(Subp
)
11324 (Has_Controlling_Result
(Subp
)
11325 and then Present
(Alias_Subp
)
11326 and then not Comes_From_Source
(Subp
)
11327 and then Sloc
(Subp
) = Sloc
(First_Subtype
(T
))))
11328 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
11329 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
11330 and then not Is_Abstract_Type
(T
)
11331 and then not Is_Predefined_Interface_Primitive
(Subp
)
11333 -- Ada 2005 (AI-251): Do not consider hidden entities associated
11334 -- with abstract interface types because the check will be done
11335 -- with the aliased entity (otherwise we generate a duplicated
11338 and then No
(Interface_Alias
(Subp
))
11340 if Present
(Alias_Subp
) then
11342 -- Only perform the check for a derived subprogram when the
11343 -- type has an explicit record extension. This avoids incorrect
11344 -- flagging of abstract subprograms for the case of a type
11345 -- without an extension that is derived from a formal type
11346 -- with a tagged actual (can occur within a private part).
11348 -- Ada 2005 (AI-391): In the case of an inherited function with
11349 -- a controlling result of the type, the rule does not apply if
11350 -- the type is a null extension (unless the parent function
11351 -- itself is abstract, in which case the function must still be
11352 -- be overridden). The expander will generate an overriding
11353 -- wrapper function calling the parent subprogram (see
11354 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
11356 Type_Def
:= Type_Definition
(Parent
(T
));
11358 if Nkind
(Type_Def
) = N_Derived_Type_Definition
11359 and then Present
(Record_Extension_Part
(Type_Def
))
11361 (Ada_Version
< Ada_2005
11362 or else not Is_Null_Extension
(T
)
11363 or else Ekind
(Subp
) = E_Procedure
11364 or else not Has_Controlling_Result
(Subp
)
11365 or else Is_Abstract_Subprogram
(Alias_Subp
)
11366 or else Requires_Overriding
(Subp
)
11367 or else Is_Access_Type
(Etype
(Subp
)))
11369 -- Avoid reporting error in case of abstract predefined
11370 -- primitive inherited from interface type because the
11371 -- body of internally generated predefined primitives
11372 -- of tagged types are generated later by Freeze_Type
11374 if Is_Interface
(Root_Type
(T
))
11375 and then Is_Abstract_Subprogram
(Subp
)
11376 and then Is_Predefined_Dispatching_Operation
(Subp
)
11377 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
11381 -- A null extension is not obliged to override an inherited
11382 -- procedure subject to pragma Extensions_Visible with value
11383 -- False and at least one controlling OUT parameter
11384 -- (SPARK RM 6.1.7(6)).
11386 elsif Is_Null_Extension
(T
)
11387 and then Is_EVF_Procedure
(Subp
)
11391 -- Subprogram renamings cannot be overridden
11393 elsif Comes_From_Source
(Subp
)
11394 and then Present
(Alias
(Subp
))
11398 -- Skip reporting the error on Ada 2022 only subprograms
11399 -- that require overriding if we are not in Ada 2022 mode.
11401 elsif Ada_Version
< Ada_2022
11402 and then Requires_Overriding
(Subp
)
11403 and then Is_Ada_2022_Only
(Ultimate_Alias
(Subp
))
11409 ("type must be declared abstract or & overridden",
11412 -- Traverse the whole chain of aliased subprograms to
11413 -- complete the error notification. This is especially
11414 -- useful for traceability of the chain of entities when
11415 -- the subprogram corresponds with an interface
11416 -- subprogram (which may be defined in another package).
11418 if Present
(Alias_Subp
) then
11424 while Present
(Alias
(E
)) loop
11426 -- Avoid reporting redundant errors on entities
11427 -- inherited from interfaces
11429 if Sloc
(E
) /= Sloc
(T
) then
11430 Error_Msg_Sloc
:= Sloc
(E
);
11432 ("\& has been inherited #", T
, Subp
);
11438 Error_Msg_Sloc
:= Sloc
(E
);
11440 -- AI05-0068: report if there is an overriding
11441 -- non-abstract subprogram that is invisible.
11444 and then not Is_Abstract_Subprogram
(E
)
11447 ("\& subprogram# is not visible",
11450 -- Clarify the case where a non-null extension must
11451 -- override inherited procedure subject to pragma
11452 -- Extensions_Visible with value False and at least
11453 -- one controlling OUT param.
11455 elsif Is_EVF_Procedure
(E
) then
11457 ("\& # is subject to Extensions_Visible False",
11462 ("\& has been inherited from subprogram #",
11469 -- Ada 2005 (AI-345): Protected or task type implementing
11470 -- abstract interfaces.
11472 elsif Is_Concurrent_Record_Type
(T
)
11473 and then Present
(Interfaces
(T
))
11475 -- There is no need to check here RM 9.4(11.9/3) since we
11476 -- are processing the corresponding record type and the
11477 -- mode of the overriding subprograms was verified by
11478 -- Check_Conformance when the corresponding concurrent
11479 -- type declaration was analyzed.
11482 ("interface subprogram & must be overridden", T
, Subp
);
11484 -- Examine primitive operations of synchronized type to find
11485 -- homonyms that have the wrong profile.
11491 Prim
:= First_Entity
(Corresponding_Concurrent_Type
(T
));
11492 while Present
(Prim
) loop
11493 if Chars
(Prim
) = Chars
(Subp
) then
11495 ("profile is not type conformant with prefixed "
11496 & "view profile of inherited operation&",
11500 Next_Entity
(Prim
);
11506 Error_Msg_Node_2
:= T
;
11508 ("abstract subprogram& not allowed for type&", Subp
);
11510 -- Also post unconditional warning on the type (unconditional
11511 -- so that if there are more than one of these cases, we get
11512 -- them all, and not just the first one).
11514 Error_Msg_Node_2
:= Subp
;
11515 Error_Msg_N
("nonabstract type& has abstract subprogram&!", T
);
11518 -- A subprogram subject to pragma Extensions_Visible with value
11519 -- "True" cannot override a subprogram subject to the same pragma
11520 -- with value "False" (SPARK RM 6.1.7(5)).
11522 elsif Extensions_Visible_Status
(Subp
) = Extensions_Visible_True
11523 and then Present
(Overridden_Operation
(Subp
))
11524 and then Extensions_Visible_Status
(Overridden_Operation
(Subp
)) =
11525 Extensions_Visible_False
11527 Error_Msg_Sloc
:= Sloc
(Overridden_Operation
(Subp
));
11529 ("subprogram & with Extensions_Visible True cannot override "
11530 & "subprogram # with Extensions_Visible False", Subp
);
11533 -- Ada 2012 (AI05-0030): Perform checks related to pragma Implemented
11535 -- Subp is an expander-generated procedure which maps an interface
11536 -- alias to a protected wrapper. The interface alias is flagged by
11537 -- pragma Implemented. Ensure that Subp is a procedure when the
11538 -- implementation kind is By_Protected_Procedure or an entry when
11541 if Ada_Version
>= Ada_2012
11542 and then Is_Hidden
(Subp
)
11543 and then Present
(Interface_Alias
(Subp
))
11544 and then Has_Rep_Pragma
(Interface_Alias
(Subp
), Name_Implemented
)
11546 Check_Pragma_Implemented
(Subp
);
11549 -- Subp is an interface primitive which overrides another interface
11550 -- primitive marked with pragma Implemented.
11552 if Ada_Version
>= Ada_2012
11553 and then Present
(Overridden_Operation
(Subp
))
11554 and then Has_Rep_Pragma
11555 (Overridden_Operation
(Subp
), Name_Implemented
)
11557 -- If the overriding routine is also marked by Implemented, check
11558 -- that the two implementation kinds are conforming.
11560 if Has_Rep_Pragma
(Subp
, Name_Implemented
) then
11561 Check_Pragma_Implemented
11563 Iface_Subp
=> Overridden_Operation
(Subp
));
11565 -- Otherwise the overriding routine inherits the implementation
11566 -- kind from the overridden subprogram.
11569 Inherit_Pragma_Implemented
11571 Iface_Subp
=> Overridden_Operation
(Subp
));
11575 -- Ada 2005 (AI95-0414) and Ada 2022 (AI12-0269): Diagnose failure to
11576 -- match No_Return in parent, but do it unconditionally in Ada 95 too
11577 -- for procedures, since this is our pragma.
11579 if Present
(Overridden_Operation
(Subp
))
11580 and then No_Return
(Overridden_Operation
(Subp
))
11583 -- If the subprogram is a renaming, check that the renamed
11584 -- subprogram is No_Return.
11586 if Present
(Renamed_Or_Alias
(Subp
)) then
11587 if not No_Return
(Renamed_Or_Alias
(Subp
)) then
11588 Error_Msg_NE
("subprogram & must be No_Return",
11590 Renamed_Or_Alias
(Subp
));
11591 Error_Msg_N
("\since renaming & overrides No_Return "
11592 & "subprogram (RM 6.5.1(6/2))",
11596 -- Make sure that the subprogram itself is No_Return.
11598 elsif not No_Return
(Subp
) then
11599 Error_Msg_N
("overriding subprogram & must be No_Return", Subp
);
11601 ("\since overridden subprogram is No_Return (RM 6.5.1(6/2))",
11606 -- If the operation is a wrapper for a synchronized primitive, it
11607 -- may be called indirectly through a dispatching select. We assume
11608 -- that it will be referenced elsewhere indirectly, and suppress
11609 -- warnings about an unused entity.
11611 if Is_Primitive_Wrapper
(Subp
)
11612 and then Present
(Wrapped_Entity
(Subp
))
11614 Set_Referenced
(Wrapped_Entity
(Subp
));
11619 end Check_Abstract_Overriding
;
11621 ------------------------------------------------
11622 -- Check_Access_Discriminant_Requires_Limited --
11623 ------------------------------------------------
11625 procedure Check_Access_Discriminant_Requires_Limited
11630 -- A discriminant_specification for an access discriminant shall appear
11631 -- only in the declaration for a task or protected type, or for a type
11632 -- with the reserved word 'limited' in its definition or in one of its
11633 -- ancestors (RM 3.7(10)).
11635 -- AI-0063: The proper condition is that type must be immutably limited,
11636 -- or else be a partial view.
11638 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
then
11639 if Is_Inherently_Limited_Type
(Current_Scope
)
11641 (Nkind
(Parent
(Current_Scope
)) = N_Private_Type_Declaration
11642 and then Limited_Present
(Parent
(Current_Scope
)))
11648 ("access discriminants allowed only for limited types", Loc
);
11651 end Check_Access_Discriminant_Requires_Limited
;
11653 -----------------------------------
11654 -- Check_Aliased_Component_Types --
11655 -----------------------------------
11657 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
11661 -- ??? Also need to check components of record extensions, but not
11662 -- components of protected types (which are always limited).
11664 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
11665 -- types to be unconstrained. This is safe because it is illegal to
11666 -- create access subtypes to such types with explicit discriminant
11669 if not Is_Limited_Type
(T
) then
11670 if Ekind
(T
) = E_Record_Type
then
11671 C
:= First_Component
(T
);
11672 while Present
(C
) loop
11674 and then Has_Discriminants
(Etype
(C
))
11675 and then not Is_Constrained
(Etype
(C
))
11676 and then not In_Instance_Body
11677 and then Ada_Version
< Ada_2005
11680 ("aliased component must be constrained (RM 3.6(11))",
11684 Next_Component
(C
);
11687 elsif Ekind
(T
) = E_Array_Type
then
11688 if Has_Aliased_Components
(T
)
11689 and then Has_Discriminants
(Component_Type
(T
))
11690 and then not Is_Constrained
(Component_Type
(T
))
11691 and then not In_Instance_Body
11692 and then Ada_Version
< Ada_2005
11695 ("aliased component type must be constrained (RM 3.6(11))",
11700 end Check_Aliased_Component_Types
;
11702 --------------------------------------
11703 -- Check_Anonymous_Access_Component --
11704 --------------------------------------
11706 procedure Check_Anonymous_Access_Component
11707 (Typ_Decl
: Node_Id
;
11710 Comp_Def
: Node_Id
;
11711 Access_Def
: Node_Id
)
11713 Loc
: constant Source_Ptr
:= Sloc
(Comp_Def
);
11714 Anon_Access
: Entity_Id
;
11717 Type_Def
: Node_Id
;
11719 procedure Build_Incomplete_Type_Declaration
;
11720 -- If the record type contains components that include an access to the
11721 -- current record, then create an incomplete type declaration for the
11722 -- record, to be used as the designated type of the anonymous access.
11723 -- This is done only once, and only if there is no previous partial
11724 -- view of the type.
11726 function Designates_T
(Subt
: Node_Id
) return Boolean;
11727 -- Check whether a node designates the enclosing record type, or 'Class
11730 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean;
11731 -- Check whether an access definition includes a reference to
11732 -- the enclosing record type. The reference can be a subtype mark
11733 -- in the access definition itself, a 'Class attribute reference, or
11734 -- recursively a reference appearing in a parameter specification
11735 -- or result definition of an access_to_subprogram definition.
11737 --------------------------------------
11738 -- Build_Incomplete_Type_Declaration --
11739 --------------------------------------
11741 procedure Build_Incomplete_Type_Declaration
is
11746 -- Is_Tagged indicates whether the type is tagged. It is tagged if
11747 -- it's "is new ... with record" or else "is tagged record ...".
11749 Typ_Def
: constant Node_Id
:=
11750 (if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
11751 then Type_Definition
(Typ_Decl
) else Empty
);
11752 Is_Tagged
: constant Boolean :=
11755 ((Nkind
(Typ_Def
) = N_Derived_Type_Definition
11757 Present
(Record_Extension_Part
(Typ_Def
)))
11759 (Nkind
(Typ_Def
) = N_Record_Definition
11760 and then Tagged_Present
(Typ_Def
)));
11763 -- If there is a previous partial view, no need to create a new one
11764 -- If the partial view, given by Prev, is incomplete, If Prev is
11765 -- a private declaration, full declaration is flagged accordingly.
11767 if Prev
/= Typ
then
11769 Make_Class_Wide_Type
(Prev
);
11770 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Prev
));
11771 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11776 elsif Has_Private_Declaration
(Typ
) then
11778 -- If we refer to T'Class inside T, and T is the completion of a
11779 -- private type, then make sure the class-wide type exists.
11782 Make_Class_Wide_Type
(Typ
);
11787 -- If there was a previous anonymous access type, the incomplete
11788 -- type declaration will have been created already.
11790 elsif Present
(Current_Entity
(Typ
))
11791 and then Ekind
(Current_Entity
(Typ
)) = E_Incomplete_Type
11792 and then Full_View
(Current_Entity
(Typ
)) = Typ
11795 and then Comes_From_Source
(Current_Entity
(Typ
))
11796 and then not Is_Tagged_Type
(Current_Entity
(Typ
))
11798 Make_Class_Wide_Type
(Typ
);
11800 ("incomplete view of tagged type should be declared tagged??",
11801 Parent
(Current_Entity
(Typ
)));
11806 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Typ
));
11807 Decl
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
11809 -- Type has already been inserted into the current scope. Remove
11810 -- it, and add incomplete declaration for type, so that subsequent
11811 -- anonymous access types can use it. The entity is unchained from
11812 -- the homonym list and from immediate visibility. After analysis,
11813 -- the entity in the incomplete declaration becomes immediately
11814 -- visible in the record declaration that follows.
11816 H
:= Current_Entity
(Typ
);
11819 Set_Name_Entity_Id
(Chars
(Typ
), Homonym
(Typ
));
11822 while Present
(Homonym
(H
)) and then Homonym
(H
) /= Typ
loop
11823 H
:= Homonym
(Typ
);
11826 Set_Homonym
(H
, Homonym
(Typ
));
11829 Insert_Before
(Typ_Decl
, Decl
);
11831 Set_Full_View
(Inc_T
, Typ
);
11832 Set_Incomplete_View
(Typ_Decl
, Inc_T
);
11834 -- If the type is tagged, create a common class-wide type for
11835 -- both views, and set the Etype of the class-wide type to the
11839 Make_Class_Wide_Type
(Inc_T
);
11840 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Inc_T
));
11841 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11844 -- If the scope is a package with a limited view, create a shadow
11845 -- entity for the incomplete type like Build_Limited_Views, so as
11846 -- to make it possible for Remove_Limited_With_Unit to reinstall
11847 -- this incomplete type as the visible entity.
11849 if Ekind
(Scope
(Inc_T
)) = E_Package
11850 and then Present
(Limited_View
(Scope
(Inc_T
)))
11853 Shadow
: constant Entity_Id
:= Make_Temporary
(Loc
, 'Z');
11856 -- This is modeled on Build_Shadow_Entity
11858 Set_Chars
(Shadow
, Chars
(Inc_T
));
11859 Set_Parent
(Shadow
, Decl
);
11860 Decorate_Type
(Shadow
, Scope
(Inc_T
), Is_Tagged
);
11861 Set_Is_Internal
(Shadow
);
11862 Set_From_Limited_With
(Shadow
);
11863 Set_Non_Limited_View
(Shadow
, Inc_T
);
11864 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
11867 Set_Non_Limited_View
11868 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Inc_T
));
11871 Append_Entity
(Shadow
, Limited_View
(Scope
(Inc_T
)));
11875 end Build_Incomplete_Type_Declaration
;
11881 function Designates_T
(Subt
: Node_Id
) return Boolean is
11882 Type_Id
: constant Name_Id
:= Chars
(Typ
);
11884 function Names_T
(Nam
: Node_Id
) return Boolean;
11885 -- The record type has not been introduced in the current scope
11886 -- yet, so we must examine the name of the type itself, either
11887 -- an identifier T, or an expanded name of the form P.T, where
11888 -- P denotes the current scope.
11894 function Names_T
(Nam
: Node_Id
) return Boolean is
11896 if Nkind
(Nam
) = N_Identifier
then
11897 return Chars
(Nam
) = Type_Id
;
11899 elsif Nkind
(Nam
) = N_Selected_Component
then
11900 if Chars
(Selector_Name
(Nam
)) = Type_Id
then
11901 if Nkind
(Prefix
(Nam
)) = N_Identifier
then
11902 return Chars
(Prefix
(Nam
)) = Chars
(Current_Scope
);
11904 elsif Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
11905 return Chars
(Selector_Name
(Prefix
(Nam
))) =
11906 Chars
(Current_Scope
);
11920 -- Start of processing for Designates_T
11923 if Nkind
(Subt
) = N_Identifier
then
11924 return Chars
(Subt
) = Type_Id
;
11926 -- Reference can be through an expanded name which has not been
11927 -- analyzed yet, and which designates enclosing scopes.
11929 elsif Nkind
(Subt
) = N_Selected_Component
then
11930 if Names_T
(Subt
) then
11933 -- Otherwise it must denote an entity that is already visible.
11934 -- The access definition may name a subtype of the enclosing
11935 -- type, if there is a previous incomplete declaration for it.
11938 Find_Selected_Component
(Subt
);
11940 Is_Entity_Name
(Subt
)
11941 and then Scope
(Entity
(Subt
)) = Current_Scope
11943 (Chars
(Base_Type
(Entity
(Subt
))) = Type_Id
11945 (Is_Class_Wide_Type
(Entity
(Subt
))
11947 Chars
(Etype
(Base_Type
(Entity
(Subt
)))) =
11951 -- A reference to the current type may appear as the prefix of
11952 -- a 'Class attribute.
11954 elsif Nkind
(Subt
) = N_Attribute_Reference
11955 and then Attribute_Name
(Subt
) = Name_Class
11957 return Names_T
(Prefix
(Subt
));
11968 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean is
11969 Param_Spec
: Node_Id
;
11971 Acc_Subprg
: constant Node_Id
:=
11972 Access_To_Subprogram_Definition
(Acc_Def
);
11975 if No
(Acc_Subprg
) then
11976 return Designates_T
(Subtype_Mark
(Acc_Def
));
11979 -- Component is an access_to_subprogram: examine its formals,
11980 -- and result definition in the case of an access_to_function.
11982 Param_Spec
:= First
(Parameter_Specifications
(Acc_Subprg
));
11983 while Present
(Param_Spec
) loop
11984 if Nkind
(Parameter_Type
(Param_Spec
)) = N_Access_Definition
11985 and then Mentions_T
(Parameter_Type
(Param_Spec
))
11989 elsif Designates_T
(Parameter_Type
(Param_Spec
)) then
11996 if Nkind
(Acc_Subprg
) = N_Access_Function_Definition
then
11997 if Nkind
(Result_Definition
(Acc_Subprg
)) =
11998 N_Access_Definition
12000 return Mentions_T
(Result_Definition
(Acc_Subprg
));
12002 return Designates_T
(Result_Definition
(Acc_Subprg
));
12009 -- Start of processing for Check_Anonymous_Access_Component
12012 if Present
(Access_Def
) and then Mentions_T
(Access_Def
) then
12013 Acc_Def
:= Access_To_Subprogram_Definition
(Access_Def
);
12015 Build_Incomplete_Type_Declaration
;
12016 Anon_Access
:= Make_Temporary
(Loc
, 'S');
12018 -- Create a declaration for the anonymous access type: either
12019 -- an access_to_object or an access_to_subprogram.
12021 if Present
(Acc_Def
) then
12022 if Nkind
(Acc_Def
) = N_Access_Function_Definition
then
12024 Make_Access_Function_Definition
(Loc
,
12025 Parameter_Specifications
=>
12026 Parameter_Specifications
(Acc_Def
),
12027 Result_Definition
=> Result_Definition
(Acc_Def
));
12030 Make_Access_Procedure_Definition
(Loc
,
12031 Parameter_Specifications
=>
12032 Parameter_Specifications
(Acc_Def
));
12037 Make_Access_To_Object_Definition
(Loc
,
12038 Subtype_Indication
=>
12039 Relocate_Node
(Subtype_Mark
(Access_Def
)));
12041 Set_Constant_Present
(Type_Def
, Constant_Present
(Access_Def
));
12042 Set_All_Present
(Type_Def
, All_Present
(Access_Def
));
12045 Set_Null_Exclusion_Present
12046 (Type_Def
, Null_Exclusion_Present
(Access_Def
));
12049 Make_Full_Type_Declaration
(Loc
,
12050 Defining_Identifier
=> Anon_Access
,
12051 Type_Definition
=> Type_Def
);
12053 Insert_Before
(Typ_Decl
, Decl
);
12056 -- At first sight we could add here the extra formals of an access to
12057 -- subprogram; however, it must delayed till the freeze point so that
12058 -- we know the convention.
12060 if Nkind
(Comp_Def
) = N_Component_Definition
then
12062 Make_Component_Definition
(Loc
,
12063 Subtype_Indication
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
12065 pragma Assert
(Nkind
(Comp_Def
) = N_Discriminant_Specification
);
12067 Make_Discriminant_Specification
(Loc
,
12068 Defining_Identifier
=> Defining_Identifier
(Comp_Def
),
12069 Discriminant_Type
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
12072 if Ekind
(Designated_Type
(Anon_Access
)) = E_Subprogram_Type
then
12073 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Subprogram_Type
);
12075 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Type
);
12078 Set_Is_Local_Anonymous_Access
(Anon_Access
);
12080 end Check_Anonymous_Access_Component
;
12082 ---------------------------------------
12083 -- Check_Anonymous_Access_Components --
12084 ---------------------------------------
12086 procedure Check_Anonymous_Access_Components
12087 (Typ_Decl
: Node_Id
;
12090 Comp_List
: Node_Id
)
12094 if No
(Comp_List
) then
12098 Set_Is_Not_Self_Hidden
(Typ
);
12100 Comp
:= First
(Component_Items
(Comp_List
));
12101 while Present
(Comp
) loop
12102 if Nkind
(Comp
) = N_Component_Declaration
then
12103 Check_Anonymous_Access_Component
12104 (Typ_Decl
, Typ
, Prev
,
12105 Component_Definition
(Comp
),
12106 Access_Definition
(Component_Definition
(Comp
)));
12112 if Present
(Variant_Part
(Comp_List
)) then
12116 V
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
12117 while Present
(V
) loop
12118 Check_Anonymous_Access_Components
12119 (Typ_Decl
, Typ
, Prev
, Component_List
(V
));
12120 Next_Non_Pragma
(V
);
12124 end Check_Anonymous_Access_Components
;
12126 ----------------------
12127 -- Check_Completion --
12128 ----------------------
12130 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
12133 procedure Post_Error
;
12134 -- Post error message for lack of completion for entity E
12140 procedure Post_Error
is
12141 procedure Missing_Body
;
12142 -- Output missing body message
12148 procedure Missing_Body
is
12150 -- Spec is in same unit, so we can post on spec
12152 if In_Same_Source_Unit
(Body_Id
, E
) then
12153 Error_Msg_N
("missing body for &", E
);
12155 -- Spec is in a separate unit, so we have to post on the body
12158 Error_Msg_NE
("missing body for & declared#!", Body_Id
, E
);
12162 -- Start of processing for Post_Error
12165 if not Comes_From_Source
(E
) then
12166 if Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12168 -- It may be an anonymous protected type created for a
12169 -- single variable. Post error on variable, if present.
12175 Var
:= First_Entity
(Current_Scope
);
12176 while Present
(Var
) loop
12177 exit when Etype
(Var
) = E
12178 and then Comes_From_Source
(Var
);
12183 if Present
(Var
) then
12190 -- If a generated entity has no completion, then either previous
12191 -- semantic errors have disabled the expansion phase, or else we had
12192 -- missing subunits, or else we are compiling without expansion,
12193 -- or else something is very wrong.
12195 if not Comes_From_Source
(E
) then
12197 (Serious_Errors_Detected
> 0
12198 or else Configurable_Run_Time_Violations
> 0
12199 or else Subunits_Missing
12200 or else not Expander_Active
);
12203 -- Here for source entity
12206 -- Here if no body to post the error message, so we post the error
12207 -- on the declaration that has no completion. This is not really
12208 -- the right place to post it, think about this later ???
12210 if No
(Body_Id
) then
12211 if Is_Type
(E
) then
12213 ("missing full declaration for }", Parent
(E
), E
);
12215 Error_Msg_NE
("missing body for &", Parent
(E
), E
);
12218 -- Package body has no completion for a declaration that appears
12219 -- in the corresponding spec. Post error on the body, with a
12220 -- reference to the non-completed declaration.
12223 Error_Msg_Sloc
:= Sloc
(E
);
12225 if Is_Type
(E
) then
12226 Error_Msg_NE
("missing full declaration for }!", Body_Id
, E
);
12228 elsif Is_Overloadable
(E
)
12229 and then Current_Entity_In_Scope
(E
) /= E
12231 -- It may be that the completion is mistyped and appears as
12232 -- a distinct overloading of the entity.
12235 Candidate
: constant Entity_Id
:=
12236 Current_Entity_In_Scope
(E
);
12237 Decl
: constant Node_Id
:=
12238 Unit_Declaration_Node
(Candidate
);
12241 if Is_Overloadable
(Candidate
)
12242 and then Ekind
(Candidate
) = Ekind
(E
)
12243 and then Nkind
(Decl
) = N_Subprogram_Body
12244 and then Acts_As_Spec
(Decl
)
12246 Check_Type_Conformant
(Candidate
, E
);
12262 Pack_Id
: constant Entity_Id
:= Current_Scope
;
12264 -- Start of processing for Check_Completion
12267 E
:= First_Entity
(Pack_Id
);
12268 while Present
(E
) loop
12269 if Is_Intrinsic_Subprogram
(E
) then
12272 -- The following situation requires special handling: a child unit
12273 -- that appears in the context clause of the body of its parent:
12275 -- procedure Parent.Child (...);
12277 -- with Parent.Child;
12278 -- package body Parent is
12280 -- Here Parent.Child appears as a local entity, but should not be
12281 -- flagged as requiring completion, because it is a compilation
12284 -- Ignore missing completion for a subprogram that does not come from
12285 -- source (including the _Call primitive operation of RAS types,
12286 -- which has to have the flag Comes_From_Source for other purposes):
12287 -- we assume that the expander will provide the missing completion.
12288 -- In case of previous errors, other expansion actions that provide
12289 -- bodies for null procedures with not be invoked, so inhibit message
12292 -- Note that E_Operator is not in the list that follows, because
12293 -- this kind is reserved for predefined operators, that are
12294 -- intrinsic and do not need completion.
12296 elsif Ekind
(E
) in E_Function
12298 | E_Generic_Function
12299 | E_Generic_Procedure
12301 if Has_Completion
(E
) then
12304 elsif Is_Subprogram
(E
) and then Is_Abstract_Subprogram
(E
) then
12307 elsif Is_Subprogram
(E
)
12308 and then (not Comes_From_Source
(E
)
12309 or else Chars
(E
) = Name_uCall
)
12314 Nkind
(Parent
(Unit_Declaration_Node
(E
))) = N_Compilation_Unit
12318 elsif Nkind
(Parent
(E
)) = N_Procedure_Specification
12319 and then Null_Present
(Parent
(E
))
12320 and then Serious_Errors_Detected
> 0
12328 elsif Is_Entry
(E
) then
12329 if not Has_Completion
(E
)
12330 and then Ekind
(Scope
(E
)) = E_Protected_Type
12335 elsif Is_Package_Or_Generic_Package
(E
) then
12336 if Unit_Requires_Body
(E
) then
12337 if not Has_Completion
(E
)
12338 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
12344 elsif not Is_Child_Unit
(E
) then
12345 May_Need_Implicit_Body
(E
);
12348 -- A formal incomplete type (Ada 2012) does not require a completion;
12349 -- other incomplete type declarations do.
12351 elsif Ekind
(E
) = E_Incomplete_Type
then
12352 if No
(Underlying_Type
(E
))
12353 and then not Is_Generic_Type
(E
)
12358 elsif Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12359 if not Has_Completion
(E
) then
12363 -- A single task declared in the current scope is a constant, verify
12364 -- that the body of its anonymous type is in the same scope. If the
12365 -- task is defined elsewhere, this may be a renaming declaration for
12366 -- which no completion is needed.
12368 elsif Ekind
(E
) = E_Constant
then
12369 if Ekind
(Etype
(E
)) = E_Task_Type
12370 and then not Has_Completion
(Etype
(E
))
12371 and then Scope
(Etype
(E
)) = Current_Scope
12376 elsif Ekind
(E
) = E_Record_Type
then
12377 if Is_Tagged_Type
(E
) then
12378 Check_Abstract_Overriding
(E
);
12379 Check_Conventions
(E
);
12382 Check_Aliased_Component_Types
(E
);
12384 elsif Ekind
(E
) = E_Array_Type
then
12385 Check_Aliased_Component_Types
(E
);
12391 end Check_Completion
;
12393 -------------------------------------
12394 -- Check_Constraining_Discriminant --
12395 -------------------------------------
12397 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
)
12399 New_Type
: constant Entity_Id
:= Etype
(New_Disc
);
12400 Old_Type
: Entity_Id
;
12403 -- If the record type contains an array constrained by the discriminant
12404 -- but with some different bound, the compiler tries to create a smaller
12405 -- range for the discriminant type (see exp_ch3.Adjust_Discriminants).
12406 -- In this case, where the discriminant type is a scalar type, the check
12407 -- must use the original discriminant type in the parent declaration.
12409 if Is_Scalar_Type
(New_Type
) then
12410 Old_Type
:= Entity
(Discriminant_Type
(Parent
(Old_Disc
)));
12412 Old_Type
:= Etype
(Old_Disc
);
12415 if not Subtypes_Statically_Compatible
(New_Type
, Old_Type
) then
12417 ("subtype must be statically compatible with parent discriminant",
12420 if not Predicates_Compatible
(New_Type
, Old_Type
) then
12422 ("\subtype predicate is not compatible with parent discriminant",
12426 end Check_Constraining_Discriminant
;
12428 ------------------------------------
12429 -- Check_CPP_Type_Has_No_Defaults --
12430 ------------------------------------
12432 procedure Check_CPP_Type_Has_No_Defaults
(T
: Entity_Id
) is
12433 Tdef
: constant Node_Id
:= Type_Definition
(Declaration_Node
(T
));
12438 -- Obtain the component list
12440 if Nkind
(Tdef
) = N_Record_Definition
then
12441 Clist
:= Component_List
(Tdef
);
12442 else pragma Assert
(Nkind
(Tdef
) = N_Derived_Type_Definition
);
12443 Clist
:= Component_List
(Record_Extension_Part
(Tdef
));
12446 -- Check all components to ensure no default expressions
12448 if Present
(Clist
) then
12449 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
12450 while Present
(Comp
) loop
12451 if Present
(Expression
(Comp
)) then
12453 ("component of imported 'C'P'P type cannot have "
12454 & "default expression", Expression
(Comp
));
12457 Next_Non_Pragma
(Comp
);
12460 end Check_CPP_Type_Has_No_Defaults
;
12462 ----------------------------
12463 -- Check_Delta_Expression --
12464 ----------------------------
12466 procedure Check_Delta_Expression
(E
: Node_Id
) is
12468 if not (Is_Real_Type
(Etype
(E
))) then
12469 Wrong_Type
(E
, Any_Real
);
12471 elsif not Is_OK_Static_Expression
(E
) then
12472 Flag_Non_Static_Expr
12473 ("non-static expression used for delta value!", E
);
12475 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
12476 Error_Msg_N
("delta expression must be positive", E
);
12482 -- If any of above errors occurred, then replace the incorrect
12483 -- expression by the real 0.1, which should prevent further errors.
12486 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
12487 Analyze_And_Resolve
(E
, Standard_Float
);
12488 end Check_Delta_Expression
;
12490 -----------------------------
12491 -- Check_Digits_Expression --
12492 -----------------------------
12494 procedure Check_Digits_Expression
(E
: Node_Id
) is
12496 if not (Is_Integer_Type
(Etype
(E
))) then
12497 Wrong_Type
(E
, Any_Integer
);
12499 elsif not Is_OK_Static_Expression
(E
) then
12500 Flag_Non_Static_Expr
12501 ("non-static expression used for digits value!", E
);
12503 elsif Expr_Value
(E
) <= 0 then
12504 Error_Msg_N
("digits value must be greater than zero", E
);
12510 -- If any of above errors occurred, then replace the incorrect
12511 -- expression by the integer 1, which should prevent further errors.
12513 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
12514 Analyze_And_Resolve
(E
, Standard_Integer
);
12516 end Check_Digits_Expression
;
12518 --------------------------
12519 -- Check_Initialization --
12520 --------------------------
12522 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
12524 -- Special processing for limited types
12526 if Is_Limited_Type
(T
)
12527 and then not In_Instance
12528 and then not In_Inlined_Body
12530 if not OK_For_Limited_Init
(T
, Exp
) then
12532 -- In GNAT mode, this is just a warning, to allow it to be evilly
12533 -- turned off. Otherwise it is a real error.
12537 ("??cannot initialize entities of limited type!", Exp
);
12539 elsif Ada_Version
< Ada_2005
then
12541 -- The side effect removal machinery may generate illegal Ada
12542 -- code to avoid the usage of access types and 'reference in
12543 -- SPARK mode. Since this is legal code with respect to theorem
12544 -- proving, do not emit the error.
12547 and then Nkind
(Exp
) = N_Function_Call
12548 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
12549 and then not Comes_From_Source
12550 (Defining_Identifier
(Parent
(Exp
)))
12556 ("cannot initialize entities of limited type", Exp
);
12557 Explain_Limited_Type
(T
, Exp
);
12561 -- Specialize error message according to kind of illegal
12562 -- initial expression. We check the Original_Node to cover
12563 -- cases where the initialization expression of an object
12564 -- declaration generated by the compiler has been rewritten
12565 -- (such as for dispatching calls).
12567 if Nkind
(Original_Node
(Exp
)) = N_Type_Conversion
12569 Nkind
(Expression
(Original_Node
(Exp
))) = N_Function_Call
12571 -- No error for internally-generated object declarations,
12572 -- which can come from build-in-place assignment statements.
12574 if Nkind
(Parent
(Exp
)) = N_Object_Declaration
12575 and then not Comes_From_Source
12576 (Defining_Identifier
(Parent
(Exp
)))
12582 ("illegal context for call to function with limited "
12588 ("initialization of limited object requires aggregate or "
12589 & "function call", Exp
);
12595 -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag gets
12596 -- set unless we can be sure that no range check is required.
12598 if not Expander_Active
12599 and then Is_Scalar_Type
(T
)
12600 and then not Is_In_Range
(Exp
, T
, Assume_Valid
=> True)
12602 Set_Do_Range_Check
(Exp
);
12604 end Check_Initialization
;
12606 ----------------------
12607 -- Check_Interfaces --
12608 ----------------------
12610 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
) is
12611 Parent_Type
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
12614 Iface_Def
: Node_Id
;
12615 Iface_Typ
: Entity_Id
;
12616 Parent_Node
: Node_Id
;
12618 Is_Task
: Boolean := False;
12619 -- Set True if parent type or any progenitor is a task interface
12621 Is_Protected
: Boolean := False;
12622 -- Set True if parent type or any progenitor is a protected interface
12624 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
);
12625 -- Check that a progenitor is compatible with declaration. If an error
12626 -- message is output, it is posted on Error_Node.
12632 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
) is
12633 Iface_Id
: constant Entity_Id
:=
12634 Defining_Identifier
(Parent
(Iface_Def
));
12635 Type_Def
: Node_Id
;
12638 if Nkind
(N
) = N_Private_Extension_Declaration
then
12641 Type_Def
:= Type_Definition
(N
);
12644 if Is_Task_Interface
(Iface_Id
) then
12647 elsif Is_Protected_Interface
(Iface_Id
) then
12648 Is_Protected
:= True;
12651 if Is_Synchronized_Interface
(Iface_Id
) then
12653 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
12654 -- extension derived from a synchronized interface must explicitly
12655 -- be declared synchronized, because the full view will be a
12656 -- synchronized type.
12658 if Nkind
(N
) = N_Private_Extension_Declaration
then
12659 if not Synchronized_Present
(N
) then
12661 ("private extension of& must be explicitly synchronized",
12665 -- However, by 3.9.4(16/2), a full type that is a record extension
12666 -- is never allowed to derive from a synchronized interface (note
12667 -- that interfaces must be excluded from this check, because those
12668 -- are represented by derived type definitions in some cases).
12670 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12671 and then not Interface_Present
(Type_Definition
(N
))
12673 Error_Msg_N
("record extension cannot derive from synchronized "
12674 & "interface", Error_Node
);
12678 -- Check that the characteristics of the progenitor are compatible
12679 -- with the explicit qualifier in the declaration.
12680 -- The check only applies to qualifiers that come from source.
12681 -- Limited_Present also appears in the declaration of corresponding
12682 -- records, and the check does not apply to them.
12684 if Limited_Present
(Type_Def
)
12686 Is_Concurrent_Record_Type
(Defining_Identifier
(N
))
12688 if Is_Limited_Interface
(Parent_Type
)
12689 and then not Is_Limited_Interface
(Iface_Id
)
12692 ("progenitor & must be limited interface",
12693 Error_Node
, Iface_Id
);
12696 (Task_Present
(Iface_Def
)
12697 or else Protected_Present
(Iface_Def
)
12698 or else Synchronized_Present
(Iface_Def
))
12699 and then Nkind
(N
) /= N_Private_Extension_Declaration
12700 and then not Error_Posted
(N
)
12703 ("progenitor & must be limited interface",
12704 Error_Node
, Iface_Id
);
12707 -- Protected interfaces can only inherit from limited, synchronized
12708 -- or protected interfaces.
12710 elsif Nkind
(N
) = N_Full_Type_Declaration
12711 and then Protected_Present
(Type_Def
)
12713 if Limited_Present
(Iface_Def
)
12714 or else Synchronized_Present
(Iface_Def
)
12715 or else Protected_Present
(Iface_Def
)
12719 elsif Task_Present
(Iface_Def
) then
12720 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12721 & "from task interface", Error_Node
);
12724 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12725 & "from non-limited interface", Error_Node
);
12728 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
12729 -- limited and synchronized.
12731 elsif Synchronized_Present
(Type_Def
) then
12732 if Limited_Present
(Iface_Def
)
12733 or else Synchronized_Present
(Iface_Def
)
12737 elsif Protected_Present
(Iface_Def
)
12738 and then Nkind
(N
) /= N_Private_Extension_Declaration
12740 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12741 & "from protected interface", Error_Node
);
12743 elsif Task_Present
(Iface_Def
)
12744 and then Nkind
(N
) /= N_Private_Extension_Declaration
12746 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12747 & "from task interface", Error_Node
);
12749 elsif not Is_Limited_Interface
(Iface_Id
) then
12750 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12751 & "from non-limited interface", Error_Node
);
12754 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
12755 -- synchronized or task interfaces.
12757 elsif Nkind
(N
) = N_Full_Type_Declaration
12758 and then Task_Present
(Type_Def
)
12760 if Limited_Present
(Iface_Def
)
12761 or else Synchronized_Present
(Iface_Def
)
12762 or else Task_Present
(Iface_Def
)
12766 elsif Protected_Present
(Iface_Def
) then
12767 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12768 & "protected interface", Error_Node
);
12771 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12772 & "non-limited interface", Error_Node
);
12777 -- Start of processing for Check_Interfaces
12780 if Is_Interface
(Parent_Type
) then
12781 if Is_Task_Interface
(Parent_Type
) then
12784 elsif Is_Protected_Interface
(Parent_Type
) then
12785 Is_Protected
:= True;
12789 if Nkind
(N
) = N_Private_Extension_Declaration
then
12791 -- Check that progenitors are compatible with declaration
12793 Iface
:= First
(Interface_List
(Def
));
12794 while Present
(Iface
) loop
12795 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12797 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12798 Iface_Def
:= Type_Definition
(Parent_Node
);
12800 if not Is_Interface
(Iface_Typ
) then
12801 Diagnose_Interface
(Iface
, Iface_Typ
);
12803 Check_Ifaces
(Iface_Def
, Iface
);
12809 if Is_Task
and Is_Protected
then
12811 ("type cannot derive from task and protected interface", N
);
12817 -- Full type declaration of derived type.
12818 -- Check compatibility with parent if it is interface type
12820 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12821 and then Is_Interface
(Parent_Type
)
12823 Parent_Node
:= Parent
(Parent_Type
);
12825 -- More detailed checks for interface varieties
12828 (Iface_Def
=> Type_Definition
(Parent_Node
),
12829 Error_Node
=> Subtype_Indication
(Type_Definition
(N
)));
12832 Iface
:= First
(Interface_List
(Def
));
12833 while Present
(Iface
) loop
12834 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12836 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12837 Iface_Def
:= Type_Definition
(Parent_Node
);
12839 if not Is_Interface
(Iface_Typ
) then
12840 Diagnose_Interface
(Iface
, Iface_Typ
);
12843 -- "The declaration of a specific descendant of an interface
12844 -- type freezes the interface type" RM 13.14
12846 Freeze_Before
(N
, Iface_Typ
);
12847 Check_Ifaces
(Iface_Def
, Error_Node
=> Iface
);
12853 if Is_Task
and Is_Protected
then
12855 ("type cannot derive from task and protected interface", N
);
12857 end Check_Interfaces
;
12859 ------------------------------------
12860 -- Check_Or_Process_Discriminants --
12861 ------------------------------------
12863 -- If an incomplete or private type declaration was already given for the
12864 -- type, the discriminants may have already been processed if they were
12865 -- present on the incomplete declaration. In this case a full conformance
12866 -- check has been performed in Find_Type_Name, and we then recheck here
12867 -- some properties that can't be checked on the partial view alone.
12868 -- Otherwise we call Process_Discriminants.
12870 procedure Check_Or_Process_Discriminants
12873 Prev
: Entity_Id
:= Empty
)
12876 if Has_Discriminants
(T
) then
12878 -- Discriminants are already set on T if they were already present
12879 -- on the partial view. Make them visible to component declarations.
12883 -- Discriminant on T (full view) referencing expr on partial view
12885 Prev_D
: Entity_Id
;
12886 -- Entity of corresponding discriminant on partial view
12889 -- Discriminant specification for full view, expression is
12890 -- the syntactic copy on full view (which has been checked for
12891 -- conformance with partial view), only used here to post error
12895 D
:= First_Discriminant
(T
);
12896 New_D
:= First
(Discriminant_Specifications
(N
));
12897 while Present
(D
) loop
12898 Prev_D
:= Current_Entity
(D
);
12899 Set_Current_Entity
(D
);
12900 Set_Is_Immediately_Visible
(D
);
12901 Set_Homonym
(D
, Prev_D
);
12903 -- Handle the case where there is an untagged partial view and
12904 -- the full view is tagged: must disallow discriminants with
12905 -- defaults, unless compiling for Ada 2012, which allows a
12906 -- limited tagged type to have defaulted discriminants (see
12907 -- AI05-0214). However, suppress error here if it was already
12908 -- reported on the default expression of the partial view.
12910 if Is_Tagged_Type
(T
)
12911 and then Present
(Expression
(Parent
(D
)))
12912 and then (not Is_Limited_Type
(Current_Scope
)
12913 or else Ada_Version
< Ada_2012
)
12914 and then not Error_Posted
(Expression
(Parent
(D
)))
12916 if Ada_Version
>= Ada_2012
then
12918 ("discriminants of nonlimited tagged type cannot have "
12920 Expression
(New_D
));
12923 ("discriminants of tagged type cannot have defaults",
12924 Expression
(New_D
));
12928 -- Ada 2005 (AI-230): Access discriminant allowed in
12929 -- non-limited record types.
12931 if Ada_Version
< Ada_2005
then
12933 -- This restriction gets applied to the full type here. It
12934 -- has already been applied earlier to the partial view.
12936 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
12939 Next_Discriminant
(D
);
12944 elsif Present
(Discriminant_Specifications
(N
)) then
12945 Process_Discriminants
(N
, Prev
);
12947 end Check_Or_Process_Discriminants
;
12949 ----------------------
12950 -- Check_Real_Bound --
12951 ----------------------
12953 procedure Check_Real_Bound
(Bound
: Node_Id
) is
12955 if not Is_Real_Type
(Etype
(Bound
)) then
12957 ("bound in real type definition must be of real type", Bound
);
12959 elsif not Is_OK_Static_Expression
(Bound
) then
12960 Flag_Non_Static_Expr
12961 ("non-static expression used for real type bound!", Bound
);
12968 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
12970 Resolve
(Bound
, Standard_Float
);
12971 end Check_Real_Bound
;
12973 ------------------------------
12974 -- Complete_Private_Subtype --
12975 ------------------------------
12977 procedure Complete_Private_Subtype
12980 Full_Base
: Entity_Id
;
12981 Related_Nod
: Node_Id
)
12983 Save_Next_Entity
: Entity_Id
;
12984 Save_Homonym
: Entity_Id
;
12987 -- Set semantic attributes for (implicit) private subtype completion.
12988 -- If the full type has no discriminants, then it is a copy of the
12989 -- full view of the base. Otherwise, it is a subtype of the base with
12990 -- a possible discriminant constraint. Save and restore the original
12991 -- Next_Entity field of full to ensure that the calls to Copy_Node do
12992 -- not corrupt the entity chain.
12994 Save_Next_Entity
:= Next_Entity
(Full
);
12995 Save_Homonym
:= Homonym
(Priv
);
12997 if Is_Private_Type
(Full_Base
)
12998 or else Is_Record_Type
(Full_Base
)
12999 or else Is_Concurrent_Type
(Full_Base
)
13001 Copy_Node
(Priv
, Full
);
13003 -- Note that the Etype of the full view is the same as the Etype of
13004 -- the partial view. In this fashion, the subtype has access to the
13005 -- correct view of the parent.
13007 Set_Has_Discriminants
(Full
, Has_Discriminants
(Full_Base
));
13008 Set_Has_Unknown_Discriminants
13009 (Full
, Has_Unknown_Discriminants
(Full_Base
));
13010 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
13011 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
13013 -- If the underlying base type is constrained, we know that the
13014 -- full view of the subtype is constrained as well (the converse
13015 -- is not necessarily true).
13017 if Is_Constrained
(Full_Base
) then
13018 Set_Is_Constrained
(Full
);
13022 Copy_Node
(Full_Base
, Full
);
13024 -- The following subtlety with the Etype of the full view needs to be
13025 -- taken into account here. One could think that it must naturally be
13026 -- set to the base type of the full base:
13028 -- Set_Etype (Full, Base_Type (Full_Base));
13030 -- so that the full view becomes a subtype of the full base when the
13031 -- latter is a base type, which must for example happen when the full
13032 -- base is declared as derived type. That's also correct if the full
13033 -- base is declared as an array type, or a floating-point type, or a
13034 -- fixed-point type, or a signed integer type, as these declarations
13035 -- create an implicit base type and a first subtype so the Etype of
13036 -- the full views must be the implicit base type. But that's wrong
13037 -- if the full base is declared as an access type, or an enumeration
13038 -- type, or a modular integer type, as these declarations directly
13039 -- create a base type, i.e. with Etype pointing to itself. Moreover
13040 -- the full base being declared in the private part, i.e. when the
13041 -- views are swapped, the end result is that the Etype of the full
13042 -- base is set to its private view in this case and that we need to
13043 -- propagate this setting to the full view in order for the subtype
13044 -- to be compatible with the base type.
13046 if Is_Base_Type
(Full_Base
)
13047 and then (Is_Derived_Type
(Full_Base
)
13048 or else Ekind
(Full_Base
) in Array_Kind
13049 or else Ekind
(Full_Base
) in Fixed_Point_Kind
13050 or else Ekind
(Full_Base
) in Float_Kind
13051 or else Ekind
(Full_Base
) in Signed_Integer_Kind
)
13053 Set_Etype
(Full
, Full_Base
);
13056 Set_Chars
(Full
, Chars
(Priv
));
13057 Set_Sloc
(Full
, Sloc
(Priv
));
13058 Conditional_Delay
(Full
, Priv
);
13061 Link_Entities
(Full
, Save_Next_Entity
);
13062 Set_Homonym
(Full
, Save_Homonym
);
13063 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
13065 if Ekind
(Full
) in Incomplete_Or_Private_Kind
then
13066 Reinit_Field_To_Zero
(Full
, F_Private_Dependents
);
13069 -- Set common attributes for all subtypes: kind, convention, etc.
13071 Mutate_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
13072 Set_Is_Not_Self_Hidden
(Full
);
13073 Set_Convention
(Full
, Convention
(Full_Base
));
13074 Set_Is_First_Subtype
(Full
, False);
13075 Set_Scope
(Full
, Scope
(Priv
));
13076 Set_Size_Info
(Full
, Full_Base
);
13077 Copy_RM_Size
(To
=> Full
, From
=> Full_Base
);
13078 Set_Is_Itype
(Full
);
13080 -- A subtype of a private-type-without-discriminants, whose full-view
13081 -- has discriminants with default expressions, is not constrained.
13083 if not Has_Discriminants
(Priv
) then
13084 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
13086 if Has_Discriminants
(Full_Base
) then
13087 Set_Discriminant_Constraint
13088 (Full
, Discriminant_Constraint
(Full_Base
));
13090 -- The partial view may have been indefinite, the full view
13093 Set_Has_Unknown_Discriminants
13094 (Full
, Has_Unknown_Discriminants
(Full_Base
));
13098 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
13099 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
13101 -- Freeze the private subtype entity if its parent is delayed, and not
13102 -- already frozen. We skip this processing if the type is an anonymous
13103 -- subtype of a record component, or is the corresponding record of a
13104 -- protected type, since these are processed when the enclosing type
13105 -- is frozen. If the parent type is declared in a nested package then
13106 -- the freezing of the private and full views also happens later.
13108 if not Is_Type
(Scope
(Full
)) then
13110 and then In_Same_Source_Unit
(Full
, Full_Base
)
13111 and then Scope
(Full_Base
) /= Scope
(Full
)
13113 Set_Has_Delayed_Freeze
(Full
);
13114 Set_Has_Delayed_Freeze
(Priv
);
13117 Set_Has_Delayed_Freeze
(Full
,
13118 Has_Delayed_Freeze
(Full_Base
)
13119 and then not Is_Frozen
(Full_Base
));
13123 Set_Freeze_Node
(Full
, Empty
);
13124 Set_Is_Frozen
(Full
, False);
13126 if Has_Discriminants
(Full
) then
13127 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
13128 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
13130 if Has_Unknown_Discriminants
(Full
) then
13131 Set_Discriminant_Constraint
(Full
, No_Elist
);
13135 if Ekind
(Full_Base
) = E_Record_Type
13136 and then Has_Discriminants
(Full_Base
)
13137 and then Has_Discriminants
(Priv
) -- might not, if errors
13138 and then not Has_Unknown_Discriminants
(Priv
)
13139 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
13141 Create_Constrained_Components
13142 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
13144 -- If the full base is itself derived from private, build a congruent
13145 -- subtype of its underlying full view, for use by the back end.
13147 elsif Is_Private_Type
(Full_Base
)
13148 and then Present
(Underlying_Full_View
(Full_Base
))
13151 Underlying_Full_Base
: constant Entity_Id
13152 := Underlying_Full_View
(Full_Base
);
13153 Underlying_Full
: constant Entity_Id
13154 := Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
13156 Set_Is_Itype
(Underlying_Full
);
13157 Set_Associated_Node_For_Itype
(Underlying_Full
, Related_Nod
);
13158 Complete_Private_Subtype
13159 (Priv
, Underlying_Full
, Underlying_Full_Base
, Related_Nod
);
13160 Set_Underlying_Full_View
(Full
, Underlying_Full
);
13161 Set_Is_Underlying_Full_View
(Underlying_Full
);
13164 elsif Is_Record_Type
(Full_Base
) then
13166 -- Show Full is simply a renaming of Full_Base
13168 Set_Cloned_Subtype
(Full
, Full_Base
);
13169 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
13171 -- Propagate predicates
13173 Propagate_Predicate_Attributes
(Full
, Full_Base
);
13176 -- It is unsafe to share the bounds of a scalar type, because the Itype
13177 -- is elaborated on demand, and if a bound is nonstatic, then different
13178 -- orders of elaboration in different units will lead to different
13179 -- external symbols.
13181 if Is_Scalar_Type
(Full_Base
) then
13182 Set_Scalar_Range
(Full
,
13183 Make_Range
(Sloc
(Related_Nod
),
13185 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
13187 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
13189 -- This completion inherits the bounds of the full parent, but if
13190 -- the parent is an unconstrained floating point type, so is the
13193 if Is_Floating_Point_Type
(Full_Base
) then
13194 Set_Includes_Infinities
13195 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
13199 -- ??? It seems that a lot of fields are missing that should be copied
13200 -- from Full_Base to Full. Here are some that are introduced in a
13201 -- non-disruptive way but a cleanup is necessary.
13203 if Is_Tagged_Type
(Full_Base
) then
13204 Set_Is_Tagged_Type
(Full
);
13205 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
13207 Set_Direct_Primitive_Operations
13208 (Full
, Direct_Primitive_Operations
(Full_Base
));
13209 Set_No_Tagged_Streams_Pragma
13210 (Full
, No_Tagged_Streams_Pragma
(Full_Base
));
13212 if Is_Interface
(Full_Base
) then
13213 Set_Is_Interface
(Full
);
13214 Set_Is_Limited_Interface
(Full
, Is_Limited_Interface
(Full_Base
));
13217 -- Inherit class_wide type of full_base in case the partial view was
13218 -- not tagged. Otherwise it has already been created when the private
13219 -- subtype was analyzed.
13221 if No
(Class_Wide_Type
(Full
)) then
13222 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
13225 -- If this is a subtype of a protected or task type, constrain its
13226 -- corresponding record, unless this is a subtype without constraints,
13227 -- i.e. a simple renaming as with an actual subtype in an instance.
13229 elsif Is_Concurrent_Type
(Full_Base
) then
13230 if Has_Discriminants
(Full
)
13231 and then Present
(Corresponding_Record_Type
(Full_Base
))
13233 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
13235 Set_Corresponding_Record_Type
(Full
,
13236 Constrain_Corresponding_Record
13237 (Full
, Corresponding_Record_Type
(Full_Base
), Related_Nod
));
13240 Set_Corresponding_Record_Type
(Full
,
13241 Corresponding_Record_Type
(Full_Base
));
13245 -- Link rep item chain, and also setting of Has_Predicates from private
13246 -- subtype to full subtype, since we will need these on the full subtype
13247 -- to create the predicate function. Note that the full subtype may
13248 -- already have rep items, inherited from the full view of the base
13249 -- type, so we must be sure not to overwrite these entries.
13254 Next_Item
: Node_Id
;
13255 Priv_Item
: Node_Id
;
13258 Item
:= First_Rep_Item
(Full
);
13259 Priv_Item
:= First_Rep_Item
(Priv
);
13261 -- If no existing rep items on full type, we can just link directly
13262 -- to the list of items on the private type, if any exist.. Same if
13263 -- the rep items are only those inherited from the base
13266 or else Nkind
(Item
) /= N_Aspect_Specification
13267 or else Entity
(Item
) = Full_Base
)
13268 and then Present
(First_Rep_Item
(Priv
))
13270 Set_First_Rep_Item
(Full
, Priv_Item
);
13272 -- Otherwise, search to the end of items currently linked to the full
13273 -- subtype and append the private items to the end. However, if Priv
13274 -- and Full already have the same list of rep items, then the append
13275 -- is not done, as that would create a circularity.
13277 -- The partial view may have a predicate and the rep item lists of
13278 -- both views agree when inherited from the same ancestor. In that
13279 -- case, simply propagate the list from one view to the other.
13280 -- A more complex analysis needed here ???
13282 elsif Present
(Priv_Item
)
13283 and then Item
= Next_Rep_Item
(Priv_Item
)
13285 Set_First_Rep_Item
(Full
, Priv_Item
);
13287 elsif Item
/= Priv_Item
then
13290 Next_Item
:= Next_Rep_Item
(Item
);
13291 exit when No
(Next_Item
);
13294 -- If the private view has aspect specifications, the full view
13295 -- inherits them. Since these aspects may already have been
13296 -- attached to the full view during derivation, do not append
13297 -- them if already present.
13299 if Item
= First_Rep_Item
(Priv
) then
13305 -- And link the private type items at the end of the chain
13308 Set_Next_Rep_Item
(Item
, First_Rep_Item
(Priv
));
13313 -- Make sure Has_Predicates is set on full type if it is set on the
13314 -- private type. Note that it may already be set on the full type and
13315 -- if so, we don't want to unset it. Similarly, propagate information
13316 -- about delayed aspects, because the corresponding pragmas must be
13317 -- analyzed when one of the views is frozen. This last step is needed
13318 -- in particular when the full type is a scalar type for which an
13319 -- anonymous base type is constructed.
13321 -- The predicate functions are generated either at the freeze point
13322 -- of the type or at the end of the visible part, and we must avoid
13323 -- generating them twice.
13325 Propagate_Predicate_Attributes
(Full
, Priv
);
13327 if Has_Delayed_Aspects
(Priv
) then
13328 Set_Has_Delayed_Aspects
(Full
);
13330 end Complete_Private_Subtype
;
13332 ----------------------------
13333 -- Constant_Redeclaration --
13334 ----------------------------
13336 procedure Constant_Redeclaration
13341 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
13342 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
13345 procedure Check_Possible_Deferred_Completion
13346 (Prev_Id
: Entity_Id
;
13347 Curr_Obj_Def
: Node_Id
);
13348 -- Determine whether the two object definitions describe the partial
13349 -- and the full view of a constrained deferred constant. Generate
13350 -- a subtype for the full view and verify that it statically matches
13351 -- the subtype of the partial view.
13353 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
13354 -- If deferred constant is an access type initialized with an allocator,
13355 -- check whether there is an illegal recursion in the definition,
13356 -- through a default value of some record subcomponent. This is normally
13357 -- detected when generating init procs, but requires this additional
13358 -- mechanism when expansion is disabled.
13360 ----------------------------------------
13361 -- Check_Possible_Deferred_Completion --
13362 ----------------------------------------
13364 procedure Check_Possible_Deferred_Completion
13365 (Prev_Id
: Entity_Id
;
13366 Curr_Obj_Def
: Node_Id
)
13368 Curr_Typ
: Entity_Id
;
13369 Prev_Typ
: constant Entity_Id
:= Etype
(Prev_Id
);
13370 Anon_Acc
: constant Boolean := Is_Anonymous_Access_Type
(Prev_Typ
);
13371 Mismatch
: Boolean := False;
13375 elsif Nkind
(Curr_Obj_Def
) = N_Subtype_Indication
then
13377 Loc
: constant Source_Ptr
:= Sloc
(N
);
13378 Def_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
13379 Decl
: constant Node_Id
:=
13380 Make_Subtype_Declaration
(Loc
,
13381 Defining_Identifier
=> Def_Id
,
13382 Subtype_Indication
=>
13383 Relocate_Node
(Curr_Obj_Def
));
13386 Insert_Before_And_Analyze
(N
, Decl
);
13387 Set_Etype
(Id
, Def_Id
);
13388 Curr_Typ
:= Def_Id
;
13391 Curr_Typ
:= Etype
(Curr_Obj_Def
);
13395 if Nkind
(Curr_Obj_Def
) /= N_Access_Definition
then
13397 elsif Has_Null_Exclusion
(Prev_Typ
)
13398 and then not Null_Exclusion_Present
(Curr_Obj_Def
)
13402 -- ??? Another check needed: mismatch if disagreement
13403 -- between designated types/profiles .
13406 Is_Constrained
(Prev_Typ
)
13407 and then not Subtypes_Statically_Match
(Prev_Typ
, Curr_Typ
);
13411 Error_Msg_Sloc
:= Sloc
(Prev_Id
);
13412 Error_Msg_N
("subtype does not statically match deferred "
13413 & "declaration #", N
);
13415 end Check_Possible_Deferred_Completion
;
13417 ---------------------------------
13418 -- Check_Recursive_Declaration --
13419 ---------------------------------
13421 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
13425 if Is_Record_Type
(Typ
) then
13426 Comp
:= First_Component
(Typ
);
13427 while Present
(Comp
) loop
13428 if Comes_From_Source
(Comp
) then
13429 if Present
(Expression
(Parent
(Comp
)))
13430 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
13431 and then Entity
(Expression
(Parent
(Comp
))) = Prev
13433 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
13435 ("illegal circularity with declaration for & #",
13439 elsif Is_Record_Type
(Etype
(Comp
)) then
13440 Check_Recursive_Declaration
(Etype
(Comp
));
13444 Next_Component
(Comp
);
13447 end Check_Recursive_Declaration
;
13449 -- Start of processing for Constant_Redeclaration
13452 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
13453 if Nkind
(Object_Definition
13454 (Parent
(Prev
))) = N_Subtype_Indication
13456 -- Find type of new declaration. The constraints of the two
13457 -- views must match statically, but there is no point in
13458 -- creating an itype for the full view.
13460 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
13461 Find_Type
(Subtype_Mark
(Obj_Def
));
13462 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
13465 Find_Type
(Obj_Def
);
13466 New_T
:= Entity
(Obj_Def
);
13472 -- The full view may impose a constraint, even if the partial
13473 -- view does not, so construct the subtype.
13475 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
13480 -- Current declaration is illegal, diagnosed below in Enter_Name
13486 -- If previous full declaration or a renaming declaration exists, or if
13487 -- a homograph is present, let Enter_Name handle it, either with an
13488 -- error or with the removal of an overridden implicit subprogram.
13489 -- The previous one is a full declaration if it has an expression
13490 -- (which in the case of an aggregate is indicated by the Init flag).
13492 if Ekind
(Prev
) /= E_Constant
13493 or else Nkind
(Parent
(Prev
)) = N_Object_Renaming_Declaration
13494 or else Present
(Expression
(Parent
(Prev
)))
13495 or else Has_Init_Expression
(Parent
(Prev
))
13496 or else Present
(Full_View
(Prev
))
13500 -- Verify that types of both declarations match, or else that both types
13501 -- are anonymous access types whose designated subtypes statically match
13502 -- (as allowed in Ada 2005 by AI-385).
13504 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
)
13506 (Ekind
(Etype
(Prev
)) /= E_Anonymous_Access_Type
13507 or else Ekind
(Etype
(New_T
)) /= E_Anonymous_Access_Type
13508 or else Is_Access_Constant
(Etype
(New_T
)) /=
13509 Is_Access_Constant
(Etype
(Prev
))
13510 or else Can_Never_Be_Null
(Etype
(New_T
)) /=
13511 Can_Never_Be_Null
(Etype
(Prev
))
13512 or else Null_Exclusion_Present
(Parent
(Prev
)) /=
13513 Null_Exclusion_Present
(Parent
(Id
))
13514 or else not Subtypes_Statically_Match
13515 (Designated_Type
(Etype
(Prev
)),
13516 Designated_Type
(Etype
(New_T
))))
13518 Error_Msg_Sloc
:= Sloc
(Prev
);
13519 Error_Msg_N
("type does not match declaration#", N
);
13520 Set_Full_View
(Prev
, Id
);
13521 Set_Etype
(Id
, Any_Type
);
13523 -- A deferred constant whose type is an anonymous array is always
13524 -- illegal (unless imported). A detailed error message might be
13525 -- helpful for Ada beginners.
13527 if Nkind
(Object_Definition
(Parent
(Prev
)))
13528 = N_Constrained_Array_Definition
13529 and then Nkind
(Object_Definition
(N
))
13530 = N_Constrained_Array_Definition
13532 Error_Msg_N
("\each anonymous array is a distinct type", N
);
13533 Error_Msg_N
("a deferred constant must have a named type",
13534 Object_Definition
(Parent
(Prev
)));
13538 Null_Exclusion_Present
(Parent
(Prev
))
13539 and then not Null_Exclusion_Present
(N
)
13541 Error_Msg_Sloc
:= Sloc
(Prev
);
13542 Error_Msg_N
("null-exclusion does not match declaration#", N
);
13543 Set_Full_View
(Prev
, Id
);
13544 Set_Etype
(Id
, Any_Type
);
13546 -- If so, process the full constant declaration
13549 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
13550 -- the deferred declaration is constrained, then the subtype defined
13551 -- by the subtype_indication in the full declaration shall match it
13554 Check_Possible_Deferred_Completion
13556 Curr_Obj_Def
=> Obj_Def
);
13558 Set_Full_View
(Prev
, Id
);
13559 Set_Is_Public
(Id
, Is_Public
(Prev
));
13560 Set_Is_Internal
(Id
);
13561 Append_Entity
(Id
, Current_Scope
);
13563 -- Check ALIASED present if present before (RM 7.4(7))
13565 if Is_Aliased
(Prev
)
13566 and then not Aliased_Present
(N
)
13568 Error_Msg_Sloc
:= Sloc
(Prev
);
13569 Error_Msg_N
("ALIASED required (see declaration #)", N
);
13572 -- Check that placement is in private part and that the incomplete
13573 -- declaration appeared in the visible part.
13575 if Ekind
(Current_Scope
) = E_Package
13576 and then not In_Private_Part
(Current_Scope
)
13578 Error_Msg_Sloc
:= Sloc
(Prev
);
13580 ("full constant for declaration # must be in private part", N
);
13582 elsif Ekind
(Current_Scope
) = E_Package
13584 List_Containing
(Parent
(Prev
)) /=
13585 Visible_Declarations
(Package_Specification
(Current_Scope
))
13588 ("deferred constant must be declared in visible part",
13592 if Is_Access_Type
(T
)
13593 and then Nkind
(Expression
(N
)) = N_Allocator
13595 Check_Recursive_Declaration
(Designated_Type
(T
));
13598 -- A deferred constant is a visible entity. If type has invariants,
13599 -- verify that the initial value satisfies them. This is not done in
13600 -- GNATprove mode, as GNATprove handles invariant checks itself.
13602 if Has_Invariants
(T
)
13603 and then Present
(Invariant_Procedure
(T
))
13604 and then not GNATprove_Mode
13607 Make_Invariant_Call
(New_Occurrence_Of
(Prev
, Sloc
(N
))));
13610 end Constant_Redeclaration
;
13612 ----------------------
13613 -- Constrain_Access --
13614 ----------------------
13616 procedure Constrain_Access
13617 (Def_Id
: in out Entity_Id
;
13619 Related_Nod
: Node_Id
)
13621 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13622 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
13623 Desig_Subtype
: Entity_Id
;
13624 Constraint_OK
: Boolean := True;
13627 if Is_Array_Type
(Desig_Type
) then
13628 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13629 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
13631 elsif (Is_Record_Type
(Desig_Type
)
13632 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
13633 and then not Is_Constrained
(Desig_Type
)
13635 -- If this is a constrained access definition for a record
13636 -- component, we leave the type as an unconstrained access,
13637 -- and mark the component so that its actual type is built
13638 -- at a point of use (e.g., an assignment statement). This
13639 -- is handled in Sem_Util.Build_Actual_Subtype_Of_Component.
13641 if Desig_Type
= Current_Scope
13642 and then No
(Def_Id
)
13646 (E_Void
, Related_Nod
, Scope_Id
=> Scope
(Desig_Type
));
13647 Mutate_Ekind
(Desig_Subtype
, E_Record_Subtype
);
13648 Def_Id
:= Entity
(Subtype_Mark
(S
));
13650 -- We indicate that the component has a per-object constraint
13651 -- for treatment at a point of use, even though the constraint
13652 -- may be independent of discriminants of the enclosing type.
13654 if Nkind
(Related_Nod
) = N_Component_Declaration
then
13655 Set_Has_Per_Object_Constraint
13656 (Defining_Identifier
(Related_Nod
));
13659 -- This call added to ensure that the constraint is analyzed
13660 -- (needed for a B test). Note that we still return early from
13661 -- this procedure to avoid recursive processing.
13663 Constrain_Discriminated_Type
13664 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
13668 -- Enforce rule that the constraint is illegal if there is an
13669 -- unconstrained view of the designated type. This means that the
13670 -- partial view (either a private type declaration or a derivation
13671 -- from a private type) has no discriminants. (Defect Report
13672 -- 8652/0008, Technical Corrigendum 1, checked by ACATS B371001).
13674 -- Rule updated for Ada 2005: The private type is said to have
13675 -- a constrained partial view, given that objects of the type
13676 -- can be declared. Furthermore, the rule applies to all access
13677 -- types, unlike the rule concerning default discriminants (see
13680 if (Ekind
(T
) = E_General_Access_Type
or else Ada_Version
>= Ada_2005
)
13681 and then Has_Private_Declaration
(Desig_Type
)
13682 and then In_Open_Scopes
(Scope
(Desig_Type
))
13683 and then Has_Discriminants
(Desig_Type
)
13686 Pack
: constant Node_Id
:=
13687 Unit_Declaration_Node
(Scope
(Desig_Type
));
13692 if Nkind
(Pack
) = N_Package_Declaration
then
13693 Decls
:= Visible_Declarations
(Specification
(Pack
));
13694 Decl
:= First
(Decls
);
13695 while Present
(Decl
) loop
13696 if (Nkind
(Decl
) = N_Private_Type_Declaration
13697 and then Chars
(Defining_Identifier
(Decl
)) =
13698 Chars
(Desig_Type
))
13701 (Nkind
(Decl
) = N_Full_Type_Declaration
13703 Chars
(Defining_Identifier
(Decl
)) =
13705 and then Is_Derived_Type
(Desig_Type
)
13707 Has_Private_Declaration
(Etype
(Desig_Type
)))
13709 if No
(Discriminant_Specifications
(Decl
)) then
13711 ("cannot constrain access type if designated "
13712 & "type has constrained partial view", S
);
13724 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13725 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
13726 For_Access
=> True);
13728 elsif Is_Concurrent_Type
(Desig_Type
)
13729 and then not Is_Constrained
(Desig_Type
)
13731 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13732 Constrain_Concurrent
(Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
13735 Error_Msg_N
("invalid constraint on access type", S
);
13737 -- We simply ignore an invalid constraint
13739 Desig_Subtype
:= Desig_Type
;
13740 Constraint_OK
:= False;
13743 if No
(Def_Id
) then
13744 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
13746 Mutate_Ekind
(Def_Id
, E_Access_Subtype
);
13749 if Constraint_OK
then
13750 Set_Etype
(Def_Id
, Base_Type
(T
));
13752 if Is_Private_Type
(Desig_Type
) then
13753 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
13756 Set_Etype
(Def_Id
, Any_Type
);
13759 Set_Size_Info
(Def_Id
, T
);
13760 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
13761 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
13762 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13763 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
13764 Set_Can_Never_Be_Null
(Def_Id
, Can_Never_Be_Null
(T
));
13766 Conditional_Delay
(Def_Id
, T
);
13768 -- AI-363 : Subtypes of general access types whose designated types have
13769 -- default discriminants are disallowed. In instances, the rule has to
13770 -- be checked against the actual, of which T is the subtype. In a
13771 -- generic body, the rule is checked assuming that the actual type has
13772 -- defaulted discriminants.
13774 if Ada_Version
>= Ada_2005
or else Warn_On_Ada_2005_Compatibility
then
13775 if Ekind
(Base_Type
(T
)) = E_General_Access_Type
13776 and then Has_Defaulted_Discriminants
(Desig_Type
)
13778 if Ada_Version
< Ada_2005
then
13780 ("access subtype of general access type would not " &
13781 "be allowed in Ada 2005?y?", S
);
13784 ("access subtype of general access type not allowed", S
);
13787 Error_Msg_N
("\discriminants have defaults", S
);
13789 elsif Is_Access_Type
(T
)
13790 and then Is_Generic_Type
(Desig_Type
)
13791 and then Has_Discriminants
(Desig_Type
)
13792 and then In_Package_Body
(Current_Scope
)
13794 if Ada_Version
< Ada_2005
then
13796 ("access subtype would not be allowed in generic body "
13797 & "in Ada 2005?y?", S
);
13800 ("access subtype not allowed in generic body", S
);
13804 ("\designated type is a discriminated formal", S
);
13807 end Constrain_Access
;
13809 ---------------------
13810 -- Constrain_Array --
13811 ---------------------
13813 procedure Constrain_Array
13814 (Def_Id
: in out Entity_Id
;
13816 Related_Nod
: Node_Id
;
13817 Related_Id
: Entity_Id
;
13818 Suffix
: Character)
13820 C
: constant Node_Id
:= Constraint
(SI
);
13821 Number_Of_Constraints
: constant Nat
:= List_Length
(Constraints
(C
));
13824 Constraint_OK
: Boolean := True;
13825 Is_FLB_Array_Subtype
: Boolean := False;
13828 T
:= Entity
(Subtype_Mark
(SI
));
13830 if Is_Access_Type
(T
) then
13831 T
:= Designated_Type
(T
);
13834 T
:= Underlying_Type
(T
);
13836 -- If an index constraint follows a subtype mark in a subtype indication
13837 -- then the type or subtype denoted by the subtype mark must not already
13838 -- impose an index constraint. The subtype mark must denote either an
13839 -- unconstrained array type or an access type whose designated type
13840 -- is such an array type... (RM 3.6.1)
13842 if Is_Constrained
(T
) then
13843 Error_Msg_N
("array type is already constrained", Subtype_Mark
(SI
));
13844 Constraint_OK
:= False;
13847 -- In either case, the index constraint must provide a discrete
13848 -- range for each index of the array type and the type of each
13849 -- discrete range must be the same as that of the corresponding
13850 -- index. (RM 3.6.1)
13852 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
13853 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
13854 Constraint_OK
:= False;
13857 S
:= First
(Constraints
(C
));
13858 Index
:= First_Index
(T
);
13861 -- Apply constraints to each index type
13863 for J
in 1 .. Number_Of_Constraints
loop
13864 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
13866 -- If the subtype of the index has been set to indicate that
13867 -- it has a fixed lower bound, then record that the subtype's
13868 -- entity will need to be marked as being a fixed-lower-bound
13871 if S
= First
(Constraints
(C
)) then
13872 Is_FLB_Array_Subtype
:=
13873 Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
));
13875 -- If the parent subtype (or should this be Etype of that?)
13876 -- is an FLB array subtype, we flag an error, because we
13877 -- don't currently allow subtypes of such subtypes to
13878 -- specify a fixed lower bound for any of their indexes,
13879 -- even if the index of the parent subtype is a "range <>"
13882 if Is_FLB_Array_Subtype
13883 and then Is_Fixed_Lower_Bound_Array_Subtype
(T
)
13886 ("index with fixed lower bound not allowed for subtype "
13887 & "of fixed-lower-bound }", S
, T
);
13889 Is_FLB_Array_Subtype
:= False;
13892 elsif Is_FLB_Array_Subtype
13893 and then not Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13896 ("constrained index not allowed for fixed-lower-bound "
13897 & "subtype of}", S
, T
);
13899 elsif not Is_FLB_Array_Subtype
13900 and then Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13903 ("index with fixed lower bound not allowed for "
13904 & "constrained subtype of}", S
, T
);
13914 if No
(Def_Id
) then
13916 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
13917 Set_Parent
(Def_Id
, Related_Nod
);
13920 Mutate_Ekind
(Def_Id
, E_Array_Subtype
);
13923 Set_Size_Info
(Def_Id
, (T
));
13924 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13925 Set_Etype
(Def_Id
, Base_Type
(T
));
13927 if Constraint_OK
then
13928 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
13930 Set_First_Index
(Def_Id
, First_Index
(T
));
13933 Set_Is_Constrained
(Def_Id
, not Is_FLB_Array_Subtype
);
13934 Set_Is_Fixed_Lower_Bound_Array_Subtype
13935 (Def_Id
, Is_FLB_Array_Subtype
);
13936 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
13937 Set_Is_Independent
(Def_Id
, Is_Independent
(T
));
13938 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13940 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
13941 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
13943 -- A subtype does not inherit the Packed_Array_Impl_Type of is parent.
13944 -- We need to initialize the attribute because if Def_Id is previously
13945 -- analyzed through a limited_with clause, it will have the attributes
13946 -- of an incomplete type, one of which is an Elist that overlaps the
13947 -- Packed_Array_Impl_Type field.
13949 Set_Packed_Array_Impl_Type
(Def_Id
, Empty
);
13951 -- Build a freeze node if parent still needs one. Also make sure that
13952 -- the Depends_On_Private status is set because the subtype will need
13953 -- reprocessing at the time the base type does, and also we must set a
13954 -- conditional delay.
13956 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
13957 Conditional_Delay
(Def_Id
, T
);
13958 end Constrain_Array
;
13960 ------------------------------
13961 -- Constrain_Component_Type --
13962 ------------------------------
13964 function Constrain_Component_Type
13966 Constrained_Typ
: Entity_Id
;
13967 Related_Node
: Node_Id
;
13969 Constraints
: Elist_Id
) return Entity_Id
13971 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
13972 Compon_Type
: constant Entity_Id
:= Etype
(Comp
);
13974 function Build_Constrained_Array_Type
13975 (Old_Type
: Entity_Id
) return Entity_Id
;
13976 -- If Old_Type is an array type, one of whose indexes is constrained
13977 -- by a discriminant, build an Itype whose constraint replaces the
13978 -- discriminant with its value in the constraint.
13980 function Build_Constrained_Discriminated_Type
13981 (Old_Type
: Entity_Id
) return Entity_Id
;
13982 -- Ditto for record components. Handle the case where the constraint
13983 -- is a conversion of the discriminant value, introduced during
13986 function Build_Constrained_Access_Type
13987 (Old_Type
: Entity_Id
) return Entity_Id
;
13988 -- Ditto for access types. Makes use of previous two functions, to
13989 -- constrain designated type.
13991 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
13992 -- Returns True if Expr is a discriminant
13994 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
;
13995 -- Find the value of a discriminant named by Discr_Expr in Constraints
13997 -----------------------------------
13998 -- Build_Constrained_Access_Type --
13999 -----------------------------------
14001 function Build_Constrained_Access_Type
14002 (Old_Type
: Entity_Id
) return Entity_Id
14004 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
14006 Desig_Subtype
: Entity_Id
;
14010 -- If the original access type was not embedded in the enclosing
14011 -- type definition, there is no need to produce a new access
14012 -- subtype. In fact every access type with an explicit constraint
14013 -- generates an itype whose scope is the enclosing record.
14015 if not Is_Type
(Scope
(Old_Type
)) then
14018 elsif Is_Array_Type
(Desig_Type
) then
14019 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
14021 elsif Has_Discriminants
(Desig_Type
) then
14023 -- This may be an access type to an enclosing record type for
14024 -- which we are constructing the constrained components. Return
14025 -- the enclosing record subtype. This is not always correct,
14026 -- but avoids infinite recursion. ???
14028 Desig_Subtype
:= Any_Type
;
14030 for J
in reverse 0 .. Scope_Stack
.Last
loop
14031 Scop
:= Scope_Stack
.Table
(J
).Entity
;
14034 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
14036 Desig_Subtype
:= Scop
;
14039 exit when not Is_Type
(Scop
);
14042 if Desig_Subtype
= Any_Type
then
14044 Build_Constrained_Discriminated_Type
(Desig_Type
);
14051 if Desig_Subtype
/= Desig_Type
then
14053 -- The Related_Node better be here or else we won't be able
14054 -- to attach new itypes to a node in the tree.
14056 pragma Assert
(Present
(Related_Node
));
14058 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
14060 Set_Etype
(Itype
, Base_Type
(Old_Type
));
14061 Set_Size_Info
(Itype
, (Old_Type
));
14062 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
14063 Set_Depends_On_Private
(Itype
, Has_Private_Component
14065 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
14068 -- The new itype needs freezing when it depends on a not frozen
14069 -- type and the enclosing subtype needs freezing.
14071 if Has_Delayed_Freeze
(Constrained_Typ
)
14072 and then not Is_Frozen
(Constrained_Typ
)
14074 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
14082 end Build_Constrained_Access_Type
;
14084 ----------------------------------
14085 -- Build_Constrained_Array_Type --
14086 ----------------------------------
14088 function Build_Constrained_Array_Type
14089 (Old_Type
: Entity_Id
) return Entity_Id
14093 Old_Index
: Node_Id
;
14094 Range_Node
: Node_Id
;
14095 Constr_List
: List_Id
;
14097 Need_To_Create_Itype
: Boolean := False;
14100 Old_Index
:= First_Index
(Old_Type
);
14101 while Present
(Old_Index
) loop
14102 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
14104 if Is_Discriminant
(Lo_Expr
)
14106 Is_Discriminant
(Hi_Expr
)
14108 Need_To_Create_Itype
:= True;
14112 Next_Index
(Old_Index
);
14115 if Need_To_Create_Itype
then
14116 Constr_List
:= New_List
;
14118 Old_Index
:= First_Index
(Old_Type
);
14119 while Present
(Old_Index
) loop
14120 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
14122 if Is_Discriminant
(Lo_Expr
) then
14123 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
14126 if Is_Discriminant
(Hi_Expr
) then
14127 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
14132 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
14134 Append
(Range_Node
, To
=> Constr_List
);
14136 Next_Index
(Old_Index
);
14139 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
14144 end Build_Constrained_Array_Type
;
14146 ------------------------------------------
14147 -- Build_Constrained_Discriminated_Type --
14148 ------------------------------------------
14150 function Build_Constrained_Discriminated_Type
14151 (Old_Type
: Entity_Id
) return Entity_Id
14154 Constr_List
: List_Id
;
14155 Old_Constraint
: Elmt_Id
;
14157 Need_To_Create_Itype
: Boolean := False;
14160 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
14161 while Present
(Old_Constraint
) loop
14162 Expr
:= Node
(Old_Constraint
);
14164 if Is_Discriminant
(Expr
) then
14165 Need_To_Create_Itype
:= True;
14168 -- After expansion of discriminated task types, the value
14169 -- of the discriminant may be converted to a run-time type
14170 -- for restricted run-times. Propagate the value of the
14171 -- discriminant as well, so that e.g. the secondary stack
14172 -- component has a static constraint. Necessary for LLVM.
14174 elsif Nkind
(Expr
) = N_Type_Conversion
14175 and then Is_Discriminant
(Expression
(Expr
))
14177 Need_To_Create_Itype
:= True;
14181 Next_Elmt
(Old_Constraint
);
14184 if Need_To_Create_Itype
then
14185 Constr_List
:= New_List
;
14187 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
14188 while Present
(Old_Constraint
) loop
14189 Expr
:= Node
(Old_Constraint
);
14191 if Is_Discriminant
(Expr
) then
14192 Expr
:= Get_Discr_Value
(Expr
);
14194 elsif Nkind
(Expr
) = N_Type_Conversion
14195 and then Is_Discriminant
(Expression
(Expr
))
14197 Expr
:= New_Copy_Tree
(Expr
);
14198 Set_Expression
(Expr
, Get_Discr_Value
(Expression
(Expr
)));
14201 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
14203 Next_Elmt
(Old_Constraint
);
14206 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
14211 end Build_Constrained_Discriminated_Type
;
14213 ---------------------
14214 -- Get_Discr_Value --
14215 ---------------------
14217 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
is
14218 Discr_Id
: constant Entity_Id
:= Entity
(Discr_Expr
);
14219 -- Entity of a discriminant that appear as a standalone expression in
14220 -- the constraint of a component.
14226 -- The discriminant may be declared for the type, in which case we
14227 -- find it by iterating over the list of discriminants. If the
14228 -- discriminant is inherited from a parent type, it appears as the
14229 -- corresponding discriminant of the current type. This will be the
14230 -- case when constraining an inherited component whose constraint is
14231 -- given by a discriminant of the parent.
14233 D
:= First_Discriminant
(Typ
);
14234 E
:= First_Elmt
(Constraints
);
14236 while Present
(D
) loop
14238 or else D
= CR_Discriminant
(Discr_Id
)
14239 or else Corresponding_Discriminant
(D
) = Discr_Id
14241 return New_Copy_Tree
(Node
(E
));
14244 Next_Discriminant
(D
);
14248 -- The Corresponding_Discriminant mechanism is incomplete, because
14249 -- the correspondence between new and old discriminants is not one
14250 -- to one: one new discriminant can constrain several old ones. In
14251 -- that case, scan sequentially the stored_constraint, the list of
14252 -- discriminants of the parents, and the constraints.
14254 -- Previous code checked for the present of the Stored_Constraint
14255 -- list for the derived type, but did not use it at all. Should it
14256 -- be present when the component is a discriminated task type?
14258 if Is_Derived_Type
(Typ
)
14259 and then Scope
(Discr_Id
) = Etype
(Typ
)
14261 D
:= First_Discriminant
(Etype
(Typ
));
14262 E
:= First_Elmt
(Constraints
);
14263 while Present
(D
) loop
14264 if D
= Discr_Id
then
14265 return New_Copy_Tree
(Node
(E
));
14268 Next_Discriminant
(D
);
14273 -- Something is wrong if we did not find the value
14275 raise Program_Error
;
14276 end Get_Discr_Value
;
14278 ---------------------
14279 -- Is_Discriminant --
14280 ---------------------
14282 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
14283 Discrim_Scope
: Entity_Id
;
14286 if Denotes_Discriminant
(Expr
) then
14287 Discrim_Scope
:= Scope
(Entity
(Expr
));
14289 -- Either we have a reference to one of Typ's discriminants,
14291 pragma Assert
(Discrim_Scope
= Typ
14293 -- or to the discriminants of the parent type, in the case
14294 -- of a derivation of a tagged type with variants.
14296 or else Discrim_Scope
= Etype
(Typ
)
14297 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
14299 -- or same as above for the case where the discriminants
14300 -- were declared in Typ's private view.
14302 or else (Is_Private_Type
(Discrim_Scope
)
14303 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14305 -- or else we are deriving from the full view and the
14306 -- discriminant is declared in the private entity.
14308 or else (Is_Private_Type
(Typ
)
14309 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14311 -- Or we are constrained the corresponding record of a
14312 -- synchronized type that completes a private declaration.
14314 or else (Is_Concurrent_Record_Type
(Typ
)
14316 Corresponding_Concurrent_Type
(Typ
) = Discrim_Scope
)
14318 -- or we have a class-wide type, in which case make sure the
14319 -- discriminant found belongs to the root type.
14321 or else (Is_Class_Wide_Type
(Typ
)
14322 and then Etype
(Typ
) = Discrim_Scope
));
14327 -- In all other cases we have something wrong
14330 end Is_Discriminant
;
14332 -- Start of processing for Constrain_Component_Type
14335 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
14336 and then Comes_From_Source
(Parent
(Comp
))
14337 and then Comes_From_Source
14338 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14341 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14343 return Compon_Type
;
14345 elsif Is_Array_Type
(Compon_Type
) then
14346 return Build_Constrained_Array_Type
(Compon_Type
);
14348 elsif Has_Discriminants
(Compon_Type
) then
14349 return Build_Constrained_Discriminated_Type
(Compon_Type
);
14351 elsif Is_Access_Type
(Compon_Type
) then
14352 return Build_Constrained_Access_Type
(Compon_Type
);
14355 return Compon_Type
;
14357 end Constrain_Component_Type
;
14359 --------------------------
14360 -- Constrain_Concurrent --
14361 --------------------------
14363 -- For concurrent types, the associated record value type carries the same
14364 -- discriminants, so when we constrain a concurrent type, we must constrain
14365 -- the corresponding record type as well.
14367 procedure Constrain_Concurrent
14368 (Def_Id
: in out Entity_Id
;
14370 Related_Nod
: Node_Id
;
14371 Related_Id
: Entity_Id
;
14372 Suffix
: Character)
14374 -- Retrieve Base_Type to ensure getting to the concurrent type in the
14375 -- case of a private subtype (needed when only doing semantic analysis).
14377 T_Ent
: Entity_Id
:= Base_Type
(Entity
(Subtype_Mark
(SI
)));
14381 if Is_Access_Type
(T_Ent
) then
14382 T_Ent
:= Designated_Type
(T_Ent
);
14385 T_Val
:= Corresponding_Record_Type
(T_Ent
);
14387 if Present
(T_Val
) then
14389 if No
(Def_Id
) then
14390 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14392 -- Elaborate itype now, as it may be used in a subsequent
14393 -- synchronized operation in another scope.
14395 if Nkind
(Related_Nod
) = N_Full_Type_Declaration
then
14396 Build_Itype_Reference
(Def_Id
, Related_Nod
);
14400 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14401 Set_First_Private_Entity
(Def_Id
, First_Private_Entity
(T_Ent
));
14403 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
14404 Set_Corresponding_Record_Type
(Def_Id
,
14405 Constrain_Corresponding_Record
(Def_Id
, T_Val
, Related_Nod
));
14408 -- If there is no associated record, expansion is disabled and this
14409 -- is a generic context. Create a subtype in any case, so that
14410 -- semantic analysis can proceed.
14412 if No
(Def_Id
) then
14413 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14416 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14418 end Constrain_Concurrent
;
14420 ------------------------------------
14421 -- Constrain_Corresponding_Record --
14422 ------------------------------------
14424 function Constrain_Corresponding_Record
14425 (Prot_Subt
: Entity_Id
;
14426 Corr_Rec
: Entity_Id
;
14427 Related_Nod
: Node_Id
) return Entity_Id
14429 T_Sub
: constant Entity_Id
:=
14431 (Ekind
=> E_Record_Subtype
,
14432 Related_Nod
=> Related_Nod
,
14433 Related_Id
=> Corr_Rec
,
14435 Suffix_Index
=> -1);
14438 Set_Etype
(T_Sub
, Corr_Rec
);
14439 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
14440 Set_Is_Tagged_Type
(T_Sub
, Is_Tagged_Type
(Corr_Rec
));
14441 Set_Is_Constrained
(T_Sub
, True);
14442 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
14443 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
14444 Set_Direct_Primitive_Operations
14445 (T_Sub
, Direct_Primitive_Operations
(Corr_Rec
));
14447 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
14448 Set_Discriminant_Constraint
14449 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
14450 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
14451 Create_Constrained_Components
14452 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
14455 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
14457 if Ekind
(Scope
(Prot_Subt
)) /= E_Record_Type
then
14458 Conditional_Delay
(T_Sub
, Corr_Rec
);
14461 -- This is a component subtype: it will be frozen in the context of
14462 -- the enclosing record's init_proc, so that discriminant references
14463 -- are resolved to discriminals. (Note: we used to skip freezing
14464 -- altogether in that case, which caused errors downstream for
14465 -- components of a bit packed array type).
14467 Set_Has_Delayed_Freeze
(T_Sub
);
14471 end Constrain_Corresponding_Record
;
14473 -----------------------
14474 -- Constrain_Decimal --
14475 -----------------------
14477 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14478 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14479 C
: constant Node_Id
:= Constraint
(S
);
14480 Loc
: constant Source_Ptr
:= Sloc
(C
);
14481 Range_Expr
: Node_Id
;
14482 Digits_Expr
: Node_Id
;
14487 Mutate_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
14489 if Nkind
(C
) = N_Range_Constraint
then
14490 Range_Expr
:= Range_Expression
(C
);
14491 Digits_Val
:= Digits_Value
(T
);
14494 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
14496 Digits_Expr
:= Digits_Expression
(C
);
14497 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
14499 Check_Digits_Expression
(Digits_Expr
);
14500 Digits_Val
:= Expr_Value
(Digits_Expr
);
14502 if Digits_Val
> Digits_Value
(T
) then
14504 ("digits expression is incompatible with subtype", C
);
14505 Digits_Val
:= Digits_Value
(T
);
14508 if Present
(Range_Constraint
(C
)) then
14509 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
14511 Range_Expr
:= Empty
;
14515 Set_Etype
(Def_Id
, Base_Type
(T
));
14516 Set_Size_Info
(Def_Id
, (T
));
14517 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14518 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
14519 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
14520 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14521 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
14522 Set_Digits_Value
(Def_Id
, Digits_Val
);
14524 -- Manufacture range from given digits value if no range present
14526 if No
(Range_Expr
) then
14527 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
14531 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
14533 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
14536 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
14537 Set_Discrete_RM_Size
(Def_Id
);
14539 -- Unconditionally delay the freeze, since we cannot set size
14540 -- information in all cases correctly until the freeze point.
14542 Set_Has_Delayed_Freeze
(Def_Id
);
14543 end Constrain_Decimal
;
14545 ----------------------------------
14546 -- Constrain_Discriminated_Type --
14547 ----------------------------------
14549 procedure Constrain_Discriminated_Type
14550 (Def_Id
: Entity_Id
;
14552 Related_Nod
: Node_Id
;
14553 For_Access
: Boolean := False)
14555 E
: Entity_Id
:= Entity
(Subtype_Mark
(S
));
14558 procedure Fixup_Bad_Constraint
;
14559 -- Called after finding a bad constraint, and after having posted an
14560 -- appropriate error message. The goal is to leave type Def_Id in as
14561 -- reasonable state as possible.
14563 --------------------------
14564 -- Fixup_Bad_Constraint --
14565 --------------------------
14567 procedure Fixup_Bad_Constraint
is
14569 -- Set a reasonable Ekind for the entity, including incomplete types.
14571 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
14573 -- Set Etype to the known type, to reduce chances of cascaded errors
14575 Set_Etype
(Def_Id
, E
);
14576 Set_Error_Posted
(Def_Id
);
14577 end Fixup_Bad_Constraint
;
14582 Constr
: Elist_Id
:= New_Elmt_List
;
14584 -- Start of processing for Constrain_Discriminated_Type
14587 C
:= Constraint
(S
);
14589 -- A discriminant constraint is only allowed in a subtype indication,
14590 -- after a subtype mark. This subtype mark must denote either a type
14591 -- with discriminants, or an access type whose designated type is a
14592 -- type with discriminants. A discriminant constraint specifies the
14593 -- values of these discriminants (RM 3.7.2(5)).
14595 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
14597 if Is_Access_Type
(T
) then
14598 T
:= Designated_Type
(T
);
14601 -- In an instance it may be necessary to retrieve the full view of a
14602 -- type with unknown discriminants, or a full view with defaulted
14603 -- discriminants. In other contexts the constraint is illegal.
14606 and then Is_Private_Type
(T
)
14607 and then Present
(Full_View
(T
))
14609 (Has_Unknown_Discriminants
(T
)
14611 (not Has_Discriminants
(T
)
14612 and then Has_Defaulted_Discriminants
(Full_View
(T
))))
14614 T
:= Full_View
(T
);
14615 E
:= Full_View
(E
);
14618 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal. Avoid
14619 -- generating an error for access-to-incomplete subtypes.
14621 if Ada_Version
>= Ada_2005
14622 and then Ekind
(T
) = E_Incomplete_Type
14623 and then Nkind
(Parent
(S
)) = N_Subtype_Declaration
14624 and then not Is_Itype
(Def_Id
)
14626 -- A little sanity check: emit an error message if the type has
14627 -- discriminants to begin with. Type T may be a regular incomplete
14628 -- type or imported via a limited with clause.
14630 if Has_Discriminants
(T
)
14631 or else (From_Limited_With
(T
)
14632 and then Present
(Non_Limited_View
(T
))
14633 and then Nkind
(Parent
(Non_Limited_View
(T
))) =
14634 N_Full_Type_Declaration
14635 and then Present
(Discriminant_Specifications
14636 (Parent
(Non_Limited_View
(T
)))))
14639 ("(Ada 2005) incomplete subtype may not be constrained", C
);
14641 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14644 Fixup_Bad_Constraint
;
14647 -- Check that the type has visible discriminants. The type may be
14648 -- a private type with unknown discriminants whose full view has
14649 -- discriminants which are invisible.
14651 elsif not Has_Discriminants
(T
)
14653 (Has_Unknown_Discriminants
(T
)
14654 and then Is_Private_Type
(T
))
14656 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14657 Fixup_Bad_Constraint
;
14660 elsif Is_Constrained
(E
)
14661 or else (Ekind
(E
) = E_Class_Wide_Subtype
14662 and then Present
(Discriminant_Constraint
(E
)))
14664 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
14665 Fixup_Bad_Constraint
;
14669 -- T may be an unconstrained subtype (e.g. a generic actual). Constraint
14670 -- applies to the base type.
14672 T
:= Base_Type
(T
);
14674 Constr
:= Build_Discriminant_Constraints
(T
, S
);
14676 -- If the list returned was empty we had an error in building the
14677 -- discriminant constraint. We have also already signalled an error
14678 -- in the incomplete type case
14680 if Is_Empty_Elmt_List
(Constr
) then
14681 Fixup_Bad_Constraint
;
14685 Build_Discriminated_Subtype
(T
, Def_Id
, Constr
, Related_Nod
, For_Access
);
14686 end Constrain_Discriminated_Type
;
14688 ---------------------------
14689 -- Constrain_Enumeration --
14690 ---------------------------
14692 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14693 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14694 C
: constant Node_Id
:= Constraint
(S
);
14697 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14699 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
14700 Set_Etype
(Def_Id
, Base_Type
(T
));
14701 Set_Size_Info
(Def_Id
, (T
));
14702 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14703 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14705 -- Inherit the chain of representation items instead of replacing it
14706 -- because Build_Derived_Enumeration_Type rewrites the declaration of
14707 -- the derived type as a subtype declaration and the former needs to
14708 -- preserve existing representation items (see Build_Derived_Type).
14710 Inherit_Rep_Item_Chain
(Def_Id
, T
);
14712 Set_Discrete_RM_Size
(Def_Id
);
14713 end Constrain_Enumeration
;
14715 ----------------------
14716 -- Constrain_Float --
14717 ----------------------
14719 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14720 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14726 Mutate_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
14728 Set_Etype
(Def_Id
, Base_Type
(T
));
14729 Set_Size_Info
(Def_Id
, (T
));
14730 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14732 -- Process the constraint
14734 C
:= Constraint
(S
);
14736 -- Digits constraint present
14738 if Nkind
(C
) = N_Digits_Constraint
then
14739 Check_Restriction
(No_Obsolescent_Features
, C
);
14741 if Warn_On_Obsolescent_Feature
then
14743 ("subtype digits constraint is an " &
14744 "obsolescent feature (RM J.3(8))?j?", C
);
14747 D
:= Digits_Expression
(C
);
14748 Analyze_And_Resolve
(D
, Any_Integer
);
14749 Check_Digits_Expression
(D
);
14750 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
14752 -- Check that digits value is in range. Obviously we can do this
14753 -- at compile time, but it is strictly a runtime check, and of
14754 -- course there is an ACVC test that checks this.
14756 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
14757 Error_Msg_Uint_1
:= Digits_Value
(T
);
14758 Error_Msg_N
("??digits value is too large, maximum is ^", D
);
14760 Make_Raise_Constraint_Error
(Sloc
(D
),
14761 Reason
=> CE_Range_Check_Failed
);
14762 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
14765 C
:= Range_Constraint
(C
);
14767 -- No digits constraint present
14770 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
14773 -- Range constraint present
14775 if Nkind
(C
) = N_Range_Constraint
then
14776 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14778 -- No range constraint present
14781 pragma Assert
(No
(C
));
14782 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
14785 Set_Is_Constrained
(Def_Id
);
14786 end Constrain_Float
;
14788 ---------------------
14789 -- Constrain_Index --
14790 ---------------------
14792 procedure Constrain_Index
14795 Related_Nod
: Node_Id
;
14796 Related_Id
: Entity_Id
;
14797 Suffix
: Character;
14798 Suffix_Index
: Pos
)
14800 Def_Id
: Entity_Id
;
14801 R
: Node_Id
:= Empty
;
14802 T
: constant Entity_Id
:= Etype
(Index
);
14803 Is_FLB_Index
: Boolean := False;
14807 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
14808 Set_Etype
(Def_Id
, Base_Type
(T
));
14810 if Nkind
(S
) = N_Range
14812 (Nkind
(S
) = N_Attribute_Reference
14813 and then Attribute_Name
(S
) = Name_Range
)
14815 -- A Range attribute will be transformed into N_Range by Resolve
14817 -- If a range has an Empty upper bound, then remember that for later
14818 -- setting of the index subtype's Is_Fixed_Lower_Bound_Index_Subtype
14819 -- flag, and also set the upper bound of the range to the index
14820 -- subtype's upper bound rather than leaving it Empty. In truth,
14821 -- that upper bound corresponds to a box ("<>"), but it's convenient
14822 -- to set it to the upper bound to avoid needing to add special tests
14823 -- in various places for an Empty upper bound, and in any case it
14824 -- accurately characterizes the index's range of values.
14826 if Nkind
(S
) = N_Range
and then No
(High_Bound
(S
)) then
14827 Is_FLB_Index
:= True;
14828 Set_High_Bound
(S
, Type_High_Bound
(T
));
14833 Process_Range_Expr_In_Decl
(R
, T
);
14835 if not Error_Posted
(S
)
14837 (Nkind
(S
) /= N_Range
14838 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
14839 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
14841 if Base_Type
(T
) /= Any_Type
14842 and then Etype
(Low_Bound
(S
)) /= Any_Type
14843 and then Etype
(High_Bound
(S
)) /= Any_Type
14845 Error_Msg_N
("range expected", S
);
14849 elsif Nkind
(S
) = N_Subtype_Indication
then
14851 -- The parser has verified that this is a discrete indication
14853 Resolve_Discrete_Subtype_Indication
(S
, T
);
14854 Bad_Predicated_Subtype_Use
14855 ("subtype& has predicate, not allowed in index constraint",
14856 S
, Entity
(Subtype_Mark
(S
)));
14858 R
:= Range_Expression
(Constraint
(S
));
14860 -- Capture values of bounds and generate temporaries for them if
14861 -- needed, since checks may cause duplication of the expressions
14862 -- which must not be reevaluated.
14864 -- The forced evaluation removes side effects from expressions, which
14865 -- should occur also in GNATprove mode. Otherwise, we end up with
14866 -- unexpected insertions of actions at places where this is not
14867 -- supposed to occur, e.g. on default parameters of a call.
14869 if Expander_Active
or GNATprove_Mode
then
14871 (Low_Bound
(R
), Related_Id
=> Def_Id
, Is_Low_Bound
=> True);
14873 (High_Bound
(R
), Related_Id
=> Def_Id
, Is_High_Bound
=> True);
14876 elsif Nkind
(S
) = N_Discriminant_Association
then
14878 -- Syntactically valid in subtype indication
14880 Error_Msg_N
("invalid index constraint", S
);
14881 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14884 -- Subtype_Mark case, no anonymous subtypes to construct
14889 if Is_Entity_Name
(S
) then
14890 if not Is_Type
(Entity
(S
)) then
14891 Error_Msg_N
("expect subtype mark for index constraint", S
);
14893 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
14894 Wrong_Type
(S
, Base_Type
(T
));
14896 -- Check error of subtype with predicate in index constraint
14899 Bad_Predicated_Subtype_Use
14900 ("subtype& has predicate, not allowed in index constraint",
14907 Error_Msg_N
("invalid index constraint", S
);
14908 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14913 -- Complete construction of the Itype
14915 if Is_Modular_Integer_Type
(T
) then
14916 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14918 elsif Is_Integer_Type
(T
) then
14919 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14922 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14923 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14924 Set_First_Literal
(Def_Id
, First_Literal
(T
));
14927 Set_Size_Info
(Def_Id
, (T
));
14928 Copy_RM_Size
(To
=> Def_Id
, From
=> T
);
14929 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14931 -- If this is a range for a fixed-lower-bound subtype, then set the
14932 -- index itype's low bound to the FLB and the index itype's upper bound
14933 -- to the high bound of the parent array type's index subtype. Also,
14934 -- mark the itype as an FLB index subtype.
14936 if Nkind
(S
) = N_Range
and then Is_FLB_Index
then
14939 Make_Range
(Sloc
(S
),
14940 Low_Bound
=> Low_Bound
(S
),
14941 High_Bound
=> Type_High_Bound
(T
)));
14942 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Def_Id
);
14945 Set_Scalar_Range
(Def_Id
, R
);
14948 Set_Etype
(S
, Def_Id
);
14949 Set_Discrete_RM_Size
(Def_Id
);
14950 end Constrain_Index
;
14952 -----------------------
14953 -- Constrain_Integer --
14954 -----------------------
14956 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14957 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14958 C
: constant Node_Id
:= Constraint
(S
);
14961 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14963 if Is_Modular_Integer_Type
(T
) then
14964 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14966 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14969 Set_Etype
(Def_Id
, Base_Type
(T
));
14970 Set_Size_Info
(Def_Id
, (T
));
14971 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14972 Set_Discrete_RM_Size
(Def_Id
);
14973 end Constrain_Integer
;
14975 ------------------------------
14976 -- Constrain_Ordinary_Fixed --
14977 ------------------------------
14979 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14980 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14986 Mutate_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
14987 Set_Etype
(Def_Id
, Base_Type
(T
));
14988 Set_Size_Info
(Def_Id
, (T
));
14989 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14990 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14992 -- Process the constraint
14994 C
:= Constraint
(S
);
14996 -- Delta constraint present
14998 if Nkind
(C
) = N_Delta_Constraint
then
14999 Check_Restriction
(No_Obsolescent_Features
, C
);
15001 if Warn_On_Obsolescent_Feature
then
15003 ("subtype delta constraint is an " &
15004 "obsolescent feature (RM J.3(7))?j?");
15007 D
:= Delta_Expression
(C
);
15008 Analyze_And_Resolve
(D
, Any_Real
);
15009 Check_Delta_Expression
(D
);
15010 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
15012 -- Check that delta value is in range. Obviously we can do this
15013 -- at compile time, but it is strictly a runtime check, and of
15014 -- course there is an ACVC test that checks this.
15016 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
15017 Error_Msg_N
("??delta value is too small", D
);
15019 Make_Raise_Constraint_Error
(Sloc
(D
),
15020 Reason
=> CE_Range_Check_Failed
);
15021 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
15024 C
:= Range_Constraint
(C
);
15026 -- No delta constraint present
15029 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
15032 -- Range constraint present
15034 if Nkind
(C
) = N_Range_Constraint
then
15035 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
15037 -- No range constraint present
15040 pragma Assert
(No
(C
));
15041 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
15044 Set_Discrete_RM_Size
(Def_Id
);
15046 -- Unconditionally delay the freeze, since we cannot set size
15047 -- information in all cases correctly until the freeze point.
15049 Set_Has_Delayed_Freeze
(Def_Id
);
15050 end Constrain_Ordinary_Fixed
;
15052 -----------------------
15053 -- Contain_Interface --
15054 -----------------------
15056 function Contain_Interface
15057 (Iface
: Entity_Id
;
15058 Ifaces
: Elist_Id
) return Boolean
15060 Iface_Elmt
: Elmt_Id
;
15063 if Present
(Ifaces
) then
15064 Iface_Elmt
:= First_Elmt
(Ifaces
);
15065 while Present
(Iface_Elmt
) loop
15066 if Node
(Iface_Elmt
) = Iface
then
15070 Next_Elmt
(Iface_Elmt
);
15075 end Contain_Interface
;
15077 ---------------------------
15078 -- Convert_Scalar_Bounds --
15079 ---------------------------
15081 procedure Convert_Scalar_Bounds
15083 Parent_Type
: Entity_Id
;
15084 Derived_Type
: Entity_Id
;
15087 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
15094 -- Defend against previous errors
15096 if No
(Scalar_Range
(Derived_Type
)) then
15097 Check_Error_Detected
;
15101 Lo
:= Build_Scalar_Bound
15102 (Type_Low_Bound
(Derived_Type
),
15103 Parent_Type
, Implicit_Base
);
15105 Hi
:= Build_Scalar_Bound
15106 (Type_High_Bound
(Derived_Type
),
15107 Parent_Type
, Implicit_Base
);
15114 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
15116 Set_Parent
(Rng
, N
);
15117 Set_Scalar_Range
(Derived_Type
, Rng
);
15119 -- Analyze the bounds
15121 Analyze_And_Resolve
(Lo
, Implicit_Base
);
15122 Analyze_And_Resolve
(Hi
, Implicit_Base
);
15124 -- Analyze the range itself, except that we do not analyze it if
15125 -- the bounds are real literals, and we have a fixed-point type.
15126 -- The reason for this is that we delay setting the bounds in this
15127 -- case till we know the final Small and Size values (see circuit
15128 -- in Freeze.Freeze_Fixed_Point_Type for further details).
15130 if Is_Fixed_Point_Type
(Parent_Type
)
15131 and then Nkind
(Lo
) = N_Real_Literal
15132 and then Nkind
(Hi
) = N_Real_Literal
15136 -- Here we do the analysis of the range
15138 -- Note: we do this manually, since if we do a normal Analyze and
15139 -- Resolve call, there are problems with the conversions used for
15140 -- the derived type range.
15143 Set_Etype
(Rng
, Implicit_Base
);
15144 Set_Analyzed
(Rng
, True);
15146 end Convert_Scalar_Bounds
;
15148 -------------------
15149 -- Copy_And_Swap --
15150 -------------------
15152 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
15154 -- Initialize new full declaration entity by copying the pertinent
15155 -- fields of the corresponding private declaration entity.
15157 -- We temporarily set Ekind to a value appropriate for a type to
15158 -- avoid assert failures in Einfo from checking for setting type
15159 -- attributes on something that is not a type. Ekind (Priv) is an
15160 -- appropriate choice, since it allowed the attributes to be set
15161 -- in the first place. This Ekind value will be modified later.
15163 Mutate_Ekind
(Full
, Ekind
(Priv
));
15165 -- Also set Etype temporarily to Any_Type, again, in the absence
15166 -- of errors, it will be properly reset, and if there are errors,
15167 -- then we want a value of Any_Type to remain.
15169 Set_Etype
(Full
, Any_Type
);
15171 -- Now start copying attributes
15173 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
15175 if Has_Discriminants
(Full
) then
15176 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
15177 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
15180 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
15181 Set_Homonym
(Full
, Homonym
(Priv
));
15182 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
15183 Set_Is_Public
(Full
, Is_Public
(Priv
));
15184 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
15185 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
15186 Set_Has_Pragma_Unmodified
(Full
, Has_Pragma_Unmodified
(Priv
));
15187 Set_Has_Pragma_Unreferenced
(Full
, Has_Pragma_Unreferenced
(Priv
));
15188 Set_Has_Pragma_Unreferenced_Objects
15189 (Full
, Has_Pragma_Unreferenced_Objects
15192 Conditional_Delay
(Full
, Priv
);
15194 if Is_Tagged_Type
(Full
) then
15195 Set_Direct_Primitive_Operations
15196 (Full
, Direct_Primitive_Operations
(Priv
));
15197 Set_No_Tagged_Streams_Pragma
15198 (Full
, No_Tagged_Streams_Pragma
(Priv
));
15200 if Is_Base_Type
(Priv
) then
15201 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
15205 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
15206 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
15207 Set_Scope
(Full
, Scope
(Priv
));
15208 Set_Prev_Entity
(Full
, Prev_Entity
(Priv
));
15209 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
15210 Set_First_Entity
(Full
, First_Entity
(Priv
));
15211 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
15213 -- If access types have been recorded for later handling, keep them in
15214 -- the full view so that they get handled when the full view freeze
15215 -- node is expanded.
15217 if Present
(Freeze_Node
(Priv
))
15218 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
15220 Ensure_Freeze_Node
(Full
);
15221 Set_Access_Types_To_Process
15222 (Freeze_Node
(Full
),
15223 Access_Types_To_Process
(Freeze_Node
(Priv
)));
15226 -- Swap the two entities. Now Private is the full type entity and Full
15227 -- is the private one. They will be swapped back at the end of the
15228 -- private part. This swapping ensures that the entity that is visible
15229 -- in the private part is the full declaration.
15231 Exchange_Entities
(Priv
, Full
);
15232 Set_Is_Not_Self_Hidden
(Priv
);
15233 Append_Entity
(Full
, Scope
(Full
));
15236 -------------------------------------
15237 -- Copy_Array_Base_Type_Attributes --
15238 -------------------------------------
15240 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
15242 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
15243 Set_Component_Type
(T1
, Component_Type
(T2
));
15244 Set_Component_Size
(T1
, Component_Size
(T2
));
15245 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
15246 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
15247 Propagate_Concurrent_Flags
(T1
, T2
);
15248 Set_Is_Packed
(T1
, Is_Packed
(T2
));
15249 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
15250 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
15251 Set_Has_Independent_Components
(T1
, Has_Independent_Components
(T2
));
15252 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
15253 end Copy_Array_Base_Type_Attributes
;
15255 -----------------------------------
15256 -- Copy_Array_Subtype_Attributes --
15257 -----------------------------------
15259 -- Note that we used to copy Packed_Array_Impl_Type too here, but we now
15260 -- let it be recreated during freezing for the sake of better debug info.
15262 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
15264 Set_Size_Info
(T1
, T2
);
15266 Set_First_Index
(T1
, First_Index
(T2
));
15267 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
15268 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
15269 Set_Is_Independent
(T1
, Is_Independent
(T2
));
15270 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
15271 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
15272 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
15273 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
15274 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
15275 Inherit_Rep_Item_Chain
(T1
, T2
);
15276 Set_Convention
(T1
, Convention
(T2
));
15277 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
15278 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
15279 end Copy_Array_Subtype_Attributes
;
15281 -----------------------------------
15282 -- Create_Constrained_Components --
15283 -----------------------------------
15285 procedure Create_Constrained_Components
15287 Decl_Node
: Node_Id
;
15289 Constraints
: Elist_Id
)
15291 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
15292 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
15293 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
15295 Assoc_List
: List_Id
;
15296 Discr_Val
: Elmt_Id
;
15300 Is_Static
: Boolean := True;
15301 Is_Compile_Time_Known
: Boolean := True;
15303 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
15304 -- Collect parent type components that do not appear in a variant part
15306 procedure Create_All_Components
;
15307 -- Iterate over Comp_List to create the components of the subtype
15309 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
15310 -- Creates a new component from Old_Compon, copying all the fields from
15311 -- it, including its Etype, inserts the new component in the Subt entity
15312 -- chain and returns the new component.
15314 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
15315 -- If true, and discriminants are static, collect only components from
15316 -- variants selected by discriminant values.
15318 ------------------------------
15319 -- Collect_Fixed_Components --
15320 ------------------------------
15322 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
15324 -- Build association list for discriminants, and find components of
15325 -- the variant part selected by the values of the discriminants.
15327 Assoc_List
:= New_List
;
15329 Old_C
:= First_Discriminant
(Typ
);
15330 Discr_Val
:= First_Elmt
(Constraints
);
15331 while Present
(Old_C
) loop
15332 Append_To
(Assoc_List
,
15333 Make_Component_Association
(Loc
,
15334 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
15335 Expression
=> New_Copy
(Node
(Discr_Val
))));
15337 Next_Elmt
(Discr_Val
);
15338 Next_Discriminant
(Old_C
);
15341 -- The tag and the possible parent component are unconditionally in
15344 if Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
15345 Old_C
:= First_Component
(Typ
);
15346 while Present
(Old_C
) loop
15347 if Chars
(Old_C
) in Name_uTag | Name_uParent
then
15348 Append_Elmt
(Old_C
, Comp_List
);
15351 Next_Component
(Old_C
);
15354 end Collect_Fixed_Components
;
15356 ---------------------------
15357 -- Create_All_Components --
15358 ---------------------------
15360 procedure Create_All_Components
is
15364 Comp
:= First_Elmt
(Comp_List
);
15365 while Present
(Comp
) loop
15366 Old_C
:= Node
(Comp
);
15367 New_C
:= Create_Component
(Old_C
);
15371 Constrain_Component_Type
15372 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15373 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15377 end Create_All_Components
;
15379 ----------------------
15380 -- Create_Component --
15381 ----------------------
15383 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
15384 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
15387 if Ekind
(Old_Compon
) = E_Discriminant
15388 and then Is_Completely_Hidden
(Old_Compon
)
15390 -- This is a shadow discriminant created for a discriminant of
15391 -- the parent type, which needs to be present in the subtype.
15392 -- Give the shadow discriminant an internal name that cannot
15393 -- conflict with that of visible components.
15395 Set_Chars
(New_Compon
, New_Internal_Name
('C'));
15398 -- Set the parent so we have a proper link for freezing etc. This is
15399 -- not a real parent pointer, since of course our parent does not own
15400 -- up to us and reference us, we are an illegitimate child of the
15401 -- original parent.
15403 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
15405 -- We do not want this node marked as Comes_From_Source, since
15406 -- otherwise it would get first class status and a separate cross-
15407 -- reference line would be generated. Illegitimate children do not
15408 -- rate such recognition.
15410 Set_Comes_From_Source
(New_Compon
, False);
15412 -- But it is a real entity, and a birth certificate must be properly
15413 -- registered by entering it into the entity list, and setting its
15414 -- scope to the given subtype. This turns out to be useful for the
15415 -- LLVM code generator, but that scope is not used otherwise.
15417 Enter_Name
(New_Compon
);
15418 Set_Scope
(New_Compon
, Subt
);
15421 end Create_Component
;
15423 -----------------------
15424 -- Is_Variant_Record --
15425 -----------------------
15427 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
15428 Decl
: constant Node_Id
:= Parent
(T
);
15430 return Nkind
(Decl
) = N_Full_Type_Declaration
15431 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
15432 and then Present
(Component_List
(Type_Definition
(Decl
)))
15434 Present
(Variant_Part
(Component_List
(Type_Definition
(Decl
))));
15435 end Is_Variant_Record
;
15437 -- Start of processing for Create_Constrained_Components
15440 pragma Assert
(Subt
/= Base_Type
(Subt
));
15441 pragma Assert
(Typ
= Base_Type
(Typ
));
15443 Set_First_Entity
(Subt
, Empty
);
15444 Set_Last_Entity
(Subt
, Empty
);
15446 -- Check whether constraint is fully static, in which case we can
15447 -- optimize the list of components.
15449 Discr_Val
:= First_Elmt
(Constraints
);
15450 while Present
(Discr_Val
) loop
15451 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
15452 Is_Static
:= False;
15454 if not Compile_Time_Known_Value
(Node
(Discr_Val
)) then
15455 Is_Compile_Time_Known
:= False;
15460 Next_Elmt
(Discr_Val
);
15463 Set_Has_Static_Discriminants
(Subt
, Is_Static
);
15467 -- Inherit the discriminants of the parent type
15469 Add_Discriminants
: declare
15475 Old_C
:= First_Discriminant
(Typ
);
15477 while Present
(Old_C
) loop
15478 Num_Disc
:= Num_Disc
+ 1;
15479 New_C
:= Create_Component
(Old_C
);
15480 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15481 Next_Discriminant
(Old_C
);
15484 -- For an untagged derived subtype, the number of discriminants may
15485 -- be smaller than the number of inherited discriminants, because
15486 -- several of them may be renamed by a single new discriminant or
15487 -- constrained. In this case, add the hidden discriminants back into
15488 -- the subtype, because they need to be present if the optimizer of
15489 -- the GCC 4.x back-end decides to break apart assignments between
15490 -- objects using the parent view into member-wise assignments.
15494 if Is_Derived_Type
(Typ
)
15495 and then not Is_Tagged_Type
(Typ
)
15497 Old_C
:= First_Stored_Discriminant
(Typ
);
15499 while Present
(Old_C
) loop
15500 Num_Stor
:= Num_Stor
+ 1;
15501 Next_Stored_Discriminant
(Old_C
);
15505 if Num_Stor
> Num_Disc
then
15507 -- Find out multiple uses of new discriminants, and add hidden
15508 -- components for the extra renamed discriminants. We recognize
15509 -- multiple uses through the Corresponding_Discriminant of a
15510 -- new discriminant: if it constrains several old discriminants,
15511 -- this field points to the last one in the parent type. The
15512 -- stored discriminants of the derived type have the same name
15513 -- as those of the parent.
15517 New_Discr
: Entity_Id
;
15518 Old_Discr
: Entity_Id
;
15521 Constr
:= First_Elmt
(Stored_Constraint
(Typ
));
15522 Old_Discr
:= First_Stored_Discriminant
(Typ
);
15523 while Present
(Constr
) loop
15524 if Is_Entity_Name
(Node
(Constr
))
15525 and then Ekind
(Entity
(Node
(Constr
))) = E_Discriminant
15527 New_Discr
:= Entity
(Node
(Constr
));
15529 if Chars
(Corresponding_Discriminant
(New_Discr
)) /=
15532 -- The new discriminant has been used to rename a
15533 -- subsequent old discriminant. Introduce a shadow
15534 -- component for the current old discriminant.
15536 New_C
:= Create_Component
(Old_Discr
);
15537 Set_Original_Record_Component
(New_C
, Old_Discr
);
15541 -- The constraint has eliminated the old discriminant.
15542 -- Introduce a shadow component.
15544 New_C
:= Create_Component
(Old_Discr
);
15545 Set_Original_Record_Component
(New_C
, Old_Discr
);
15548 Next_Elmt
(Constr
);
15549 Next_Stored_Discriminant
(Old_Discr
);
15553 end Add_Discriminants
;
15555 if Is_Compile_Time_Known
15556 and then Is_Variant_Record
(Typ
)
15558 Collect_Fixed_Components
(Typ
);
15561 Component_List
(Type_Definition
(Parent
(Typ
))),
15562 Governed_By
=> Assoc_List
,
15564 Report_Errors
=> Errors
,
15565 Allow_Compile_Time
=> True);
15566 pragma Assert
(not Errors
or else Serious_Errors_Detected
> 0);
15568 Create_All_Components
;
15570 -- If the subtype declaration is created for a tagged type derivation
15571 -- with constraints, we retrieve the record definition of the parent
15572 -- type to select the components of the proper variant.
15574 elsif Is_Compile_Time_Known
15575 and then Is_Tagged_Type
(Typ
)
15576 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
15578 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
15579 and then Is_Variant_Record
(Parent_Type
)
15581 Collect_Fixed_Components
(Typ
);
15584 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
15585 Governed_By
=> Assoc_List
,
15587 Report_Errors
=> Errors
,
15588 Allow_Compile_Time
=> True);
15590 -- Note: previously there was a check at this point that no errors
15591 -- were detected. As a consequence of AI05-220 there may be an error
15592 -- if an inherited discriminant that controls a variant has a non-
15593 -- static constraint.
15595 -- If the tagged derivation has a type extension, collect all the
15596 -- new relevant components therein via Gather_Components.
15598 if Present
(Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
15603 (Record_Extension_Part
(Type_Definition
(Parent
(Typ
)))),
15604 Governed_By
=> Assoc_List
,
15606 Report_Errors
=> Errors
,
15607 Allow_Compile_Time
=> True,
15608 Include_Interface_Tag
=> True);
15611 Create_All_Components
;
15614 -- If discriminants are not static, or if this is a multi-level type
15615 -- extension, we have to include all components of the parent type.
15617 Old_C
:= First_Component
(Typ
);
15618 while Present
(Old_C
) loop
15619 New_C
:= Create_Component
(Old_C
);
15623 Constrain_Component_Type
15624 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15625 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15627 Next_Component
(Old_C
);
15632 end Create_Constrained_Components
;
15634 ------------------------------------------
15635 -- Decimal_Fixed_Point_Type_Declaration --
15636 ------------------------------------------
15638 procedure Decimal_Fixed_Point_Type_Declaration
15642 Loc
: constant Source_Ptr
:= Sloc
(Def
);
15643 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
15644 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
15645 Max_Digits
: constant Nat
:=
15646 (if System_Max_Integer_Size
= 128 then 38 else 18);
15647 -- Maximum number of digits that can be represented in an integer
15649 Implicit_Base
: Entity_Id
;
15656 Check_Restriction
(No_Fixed_Point
, Def
);
15658 -- Create implicit base type
15661 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
15662 Set_Etype
(Implicit_Base
, Implicit_Base
);
15664 -- Analyze and process delta expression
15666 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
15668 Check_Delta_Expression
(Delta_Expr
);
15669 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
15671 -- Check delta is power of 10, and determine scale value from it
15677 Scale_Val
:= Uint_0
;
15680 if Val
< Ureal_1
then
15681 while Val
< Ureal_1
loop
15682 Val
:= Val
* Ureal_10
;
15683 Scale_Val
:= Scale_Val
+ 1;
15686 if Scale_Val
> Max_Digits
then
15687 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15688 Error_Msg_N
("scale exceeds maximum value of ^", Def
);
15689 Scale_Val
:= UI_From_Int
(Max_Digits
);
15693 while Val
> Ureal_1
loop
15694 Val
:= Val
/ Ureal_10
;
15695 Scale_Val
:= Scale_Val
- 1;
15698 if Scale_Val
< -Max_Digits
then
15699 Error_Msg_Uint_1
:= UI_From_Int
(-Max_Digits
);
15700 Error_Msg_N
("scale is less than minimum value of ^", Def
);
15701 Scale_Val
:= UI_From_Int
(-Max_Digits
);
15705 if Val
/= Ureal_1
then
15706 Error_Msg_N
("delta expression must be a power of 10", Def
);
15707 Delta_Val
:= Ureal_10
** (-Scale_Val
);
15711 -- Set delta, scale and small (small = delta for decimal type)
15713 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
15714 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
15715 Set_Small_Value
(Implicit_Base
, Delta_Val
);
15717 -- Analyze and process digits expression
15719 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
15720 Check_Digits_Expression
(Digs_Expr
);
15721 Digs_Val
:= Expr_Value
(Digs_Expr
);
15723 if Digs_Val
> Max_Digits
then
15724 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15725 Error_Msg_N
("digits value out of range, maximum is ^", Digs_Expr
);
15726 Digs_Val
:= UI_From_Int
(Max_Digits
);
15729 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
15730 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
15732 -- Set range of base type from digits value for now. This will be
15733 -- expanded to represent the true underlying base range by Freeze.
15735 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
15737 -- Note: We leave Esize unset for now, size will be set at freeze
15738 -- time. We have to do this for ordinary fixed-point, because the size
15739 -- depends on the specified small, and we might as well do the same for
15740 -- decimal fixed-point.
15742 pragma Assert
(not Known_Esize
(Implicit_Base
));
15744 -- If there are bounds given in the declaration use them as the
15745 -- bounds of the first named subtype.
15747 if Present
(Real_Range_Specification
(Def
)) then
15749 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
15750 Low
: constant Node_Id
:= Low_Bound
(RRS
);
15751 High
: constant Node_Id
:= High_Bound
(RRS
);
15756 Analyze_And_Resolve
(Low
, Any_Real
);
15757 Analyze_And_Resolve
(High
, Any_Real
);
15758 Check_Real_Bound
(Low
);
15759 Check_Real_Bound
(High
);
15760 Low_Val
:= Expr_Value_R
(Low
);
15761 High_Val
:= Expr_Value_R
(High
);
15763 if Low_Val
< (-Bound_Val
) then
15765 ("range low bound too small for digits value", Low
);
15766 Low_Val
:= -Bound_Val
;
15769 if High_Val
> Bound_Val
then
15771 ("range high bound too large for digits value", High
);
15772 High_Val
:= Bound_Val
;
15775 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
15778 -- If no explicit range, use range that corresponds to given
15779 -- digits value. This will end up as the final range for the
15783 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
15786 -- Complete entity for first subtype. The inheritance of the rep item
15787 -- chain ensures that SPARK-related pragmas are not clobbered when the
15788 -- decimal fixed point type acts as a full view of a private type.
15790 Mutate_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
15791 Set_Etype
(T
, Implicit_Base
);
15792 Set_Size_Info
(T
, Implicit_Base
);
15793 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
15794 Set_Digits_Value
(T
, Digs_Val
);
15795 Set_Delta_Value
(T
, Delta_Val
);
15796 Set_Small_Value
(T
, Delta_Val
);
15797 Set_Scale_Value
(T
, Scale_Val
);
15798 Set_Is_Constrained
(T
);
15799 end Decimal_Fixed_Point_Type_Declaration
;
15801 -----------------------------------
15802 -- Derive_Progenitor_Subprograms --
15803 -----------------------------------
15805 procedure Derive_Progenitor_Subprograms
15806 (Parent_Type
: Entity_Id
;
15807 Tagged_Type
: Entity_Id
)
15812 Iface_Alias
: Entity_Id
;
15813 Iface_Elmt
: Elmt_Id
;
15814 Iface_Subp
: Entity_Id
;
15815 New_Subp
: Entity_Id
:= Empty
;
15816 Prim_Elmt
: Elmt_Id
;
15821 pragma Assert
(Ada_Version
>= Ada_2005
15822 and then Is_Record_Type
(Tagged_Type
)
15823 and then Is_Tagged_Type
(Tagged_Type
)
15824 and then Has_Interfaces
(Tagged_Type
));
15826 -- Step 1: Transfer to the full-view primitives associated with the
15827 -- partial-view that cover interface primitives. Conceptually this
15828 -- work should be done later by Process_Full_View; done here to
15829 -- simplify its implementation at later stages. It can be safely
15830 -- done here because interfaces must be visible in the partial and
15831 -- private view (RM 7.3(7.3/2)).
15833 -- Small optimization: This work is only required if the parent may
15834 -- have entities whose Alias attribute reference an interface primitive.
15835 -- Such a situation may occur if the parent is an abstract type and the
15836 -- primitive has not been yet overridden or if the parent is a generic
15837 -- formal type covering interfaces.
15839 -- If the tagged type is not abstract, it cannot have abstract
15840 -- primitives (the only entities in the list of primitives of
15841 -- non-abstract tagged types that can reference abstract primitives
15842 -- through its Alias attribute are the internal entities that have
15843 -- attribute Interface_Alias, and these entities are generated later
15844 -- by Add_Internal_Interface_Entities).
15846 if In_Private_Part
(Current_Scope
)
15847 and then (Is_Abstract_Type
(Parent_Type
)
15849 Is_Generic_Type
(Parent_Type
))
15851 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
15852 while Present
(Elmt
) loop
15853 Subp
:= Node
(Elmt
);
15855 -- At this stage it is not possible to have entities in the list
15856 -- of primitives that have attribute Interface_Alias.
15858 pragma Assert
(No
(Interface_Alias
(Subp
)));
15860 Typ
:= Find_Dispatching_Type
(Ultimate_Alias
(Subp
));
15862 if Is_Interface
(Typ
) then
15863 E
:= Find_Primitive_Covering_Interface
15864 (Tagged_Type
=> Tagged_Type
,
15865 Iface_Prim
=> Subp
);
15868 and then Find_Dispatching_Type
(Ultimate_Alias
(E
)) /= Typ
15870 Replace_Elmt
(Elmt
, E
);
15871 Remove_Homonym
(Subp
);
15879 -- Step 2: Add primitives of progenitors that are not implemented by
15880 -- parents of Tagged_Type.
15882 if Present
(Interfaces
(Base_Type
(Tagged_Type
))) then
15883 Iface_Elmt
:= First_Elmt
(Interfaces
(Base_Type
(Tagged_Type
)));
15884 while Present
(Iface_Elmt
) loop
15885 Iface
:= Node
(Iface_Elmt
);
15887 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
15888 while Present
(Prim_Elmt
) loop
15889 Iface_Subp
:= Node
(Prim_Elmt
);
15890 Iface_Alias
:= Ultimate_Alias
(Iface_Subp
);
15892 -- Exclude derivation of predefined primitives except those
15893 -- that come from source, or are inherited from one that comes
15894 -- from source. Required to catch declarations of equality
15895 -- operators of interfaces. For example:
15897 -- type Iface is interface;
15898 -- function "=" (Left, Right : Iface) return Boolean;
15900 if not Is_Predefined_Dispatching_Operation
(Iface_Subp
)
15901 or else Comes_From_Source
(Iface_Alias
)
15904 Find_Primitive_Covering_Interface
15905 (Tagged_Type
=> Tagged_Type
,
15906 Iface_Prim
=> Iface_Subp
);
15908 -- If not found we derive a new primitive leaving its alias
15909 -- attribute referencing the interface primitive.
15913 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15915 -- Ada 2012 (AI05-0197): If the covering primitive's name
15916 -- differs from the name of the interface primitive then it
15917 -- is a private primitive inherited from a parent type. In
15918 -- such case, given that Tagged_Type covers the interface,
15919 -- the inherited private primitive becomes visible. For such
15920 -- purpose we add a new entity that renames the inherited
15921 -- private primitive.
15923 elsif Chars
(E
) /= Chars
(Iface_Subp
) then
15924 pragma Assert
(Has_Suffix
(E
, 'P'));
15926 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15927 Set_Alias
(New_Subp
, E
);
15928 Set_Is_Abstract_Subprogram
(New_Subp
,
15929 Is_Abstract_Subprogram
(E
));
15931 -- Propagate to the full view interface entities associated
15932 -- with the partial view.
15934 elsif In_Private_Part
(Current_Scope
)
15935 and then Present
(Alias
(E
))
15936 and then Alias
(E
) = Iface_Subp
15938 List_Containing
(Parent
(E
)) /=
15939 Private_Declarations
15941 (Unit_Declaration_Node
(Current_Scope
)))
15943 Append_Elmt
(E
, Primitive_Operations
(Tagged_Type
));
15947 Next_Elmt
(Prim_Elmt
);
15950 Next_Elmt
(Iface_Elmt
);
15953 end Derive_Progenitor_Subprograms
;
15955 -----------------------
15956 -- Derive_Subprogram --
15957 -----------------------
15959 procedure Derive_Subprogram
15960 (New_Subp
: out Entity_Id
;
15961 Parent_Subp
: Entity_Id
;
15962 Derived_Type
: Entity_Id
;
15963 Parent_Type
: Entity_Id
;
15964 Actual_Subp
: Entity_Id
:= Empty
)
15966 Formal
: Entity_Id
;
15967 -- Formal parameter of parent primitive operation
15969 Formal_Of_Actual
: Entity_Id
;
15970 -- Formal parameter of actual operation, when the derivation is to
15971 -- create a renaming for a primitive operation of an actual in an
15974 New_Formal
: Entity_Id
;
15975 -- Formal of inherited operation
15977 Visible_Subp
: Entity_Id
:= Parent_Subp
;
15979 function Is_Private_Overriding
return Boolean;
15980 -- If Subp is a private overriding of a visible operation, the inherited
15981 -- operation derives from the overridden op (even though its body is the
15982 -- overriding one) and the inherited operation is visible now. See
15983 -- sem_disp to see the full details of the handling of the overridden
15984 -- subprogram, which is removed from the list of primitive operations of
15985 -- the type. The overridden subprogram is saved locally in Visible_Subp,
15986 -- and used to diagnose abstract operations that need overriding in the
15989 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
15990 -- Set the Etype of New_Id to the appropriate subtype determined from
15991 -- the Etype of Id, following (RM 3.4 (18, 19, 20, 21)). Id is either
15992 -- the parent type's primitive subprogram or one of its formals, and
15993 -- New_Id is the corresponding entity for the derived type. When the
15994 -- Etype of Id is an anonymous access type, create a new access type
15995 -- designating the derived type.
15997 procedure Set_Derived_Name
;
15998 -- This procedure sets the appropriate Chars name for New_Subp. This
15999 -- is normally just a copy of the parent name. An exception arises for
16000 -- type support subprograms, where the name is changed to reflect the
16001 -- name of the derived type, e.g. if type foo is derived from type bar,
16002 -- then a procedure barDA is derived with a name fooDA.
16004 ---------------------------
16005 -- Is_Private_Overriding --
16006 ---------------------------
16008 function Is_Private_Overriding
return Boolean is
16012 -- If the parent is not a dispatching operation there is no
16013 -- need to investigate overridings
16015 if not Is_Dispatching_Operation
(Parent_Subp
) then
16019 -- The visible operation that is overridden is a homonym of the
16020 -- parent subprogram. We scan the homonym chain to find the one
16021 -- whose alias is the subprogram we are deriving.
16023 Prev
:= Current_Entity
(Parent_Subp
);
16024 while Present
(Prev
) loop
16025 if Ekind
(Prev
) = Ekind
(Parent_Subp
)
16026 and then Alias
(Prev
) = Parent_Subp
16027 and then Scope
(Parent_Subp
) = Scope
(Prev
)
16028 and then not Is_Hidden
(Prev
)
16030 Visible_Subp
:= Prev
;
16034 Prev
:= Homonym
(Prev
);
16038 end Is_Private_Overriding
;
16044 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
16045 Id_Type
: constant Entity_Id
:= Etype
(Id
);
16046 Par
: constant Node_Id
:= Parent
(Derived_Type
);
16049 -- When the type is an anonymous access type, create a new access
16050 -- type designating the derived type. This itype must be elaborated
16051 -- at the point of the derivation, not on subsequent calls that may
16052 -- be out of the proper scope for Gigi, so we insert a reference to
16053 -- it after the derivation.
16055 if Ekind
(Id_Type
) = E_Anonymous_Access_Type
then
16057 Acc_Type
: Entity_Id
;
16058 Desig_Typ
: Entity_Id
:= Designated_Type
(Id_Type
);
16061 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
16062 and then Present
(Full_View
(Desig_Typ
))
16063 and then not Is_Private_Type
(Parent_Type
)
16065 Desig_Typ
:= Full_View
(Desig_Typ
);
16068 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
)
16070 -- Ada 2005 (AI-251): Handle also derivations of abstract
16071 -- interface primitives.
16073 or else (Is_Interface
(Desig_Typ
)
16074 and then not Is_Class_Wide_Type
(Desig_Typ
))
16076 Acc_Type
:= New_Copy
(Id_Type
);
16077 Set_Etype
(Acc_Type
, Acc_Type
);
16078 Set_Scope
(Acc_Type
, New_Subp
);
16080 -- Set size of anonymous access type. If we have an access
16081 -- to an unconstrained array, this is a fat pointer, so it
16082 -- is sizes at twice addtress size.
16084 if Is_Array_Type
(Desig_Typ
)
16085 and then not Is_Constrained
(Desig_Typ
)
16087 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
16089 -- Other cases use a thin pointer
16092 Init_Size
(Acc_Type
, System_Address_Size
);
16095 -- Set remaining characterstics of anonymous access type
16097 Reinit_Alignment
(Acc_Type
);
16098 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
16100 Set_Etype
(New_Id
, Acc_Type
);
16101 Set_Scope
(New_Id
, New_Subp
);
16103 -- Create a reference to it
16105 Build_Itype_Reference
(Acc_Type
, Parent
(Derived_Type
));
16108 Set_Etype
(New_Id
, Id_Type
);
16112 -- In Ada2012, a formal may have an incomplete type but the type
16113 -- derivation that inherits the primitive follows the full view.
16115 elsif Base_Type
(Id_Type
) = Base_Type
(Parent_Type
)
16117 (Ekind
(Id_Type
) = E_Record_Type_With_Private
16118 and then Present
(Full_View
(Id_Type
))
16120 Base_Type
(Full_View
(Id_Type
)) = Base_Type
(Parent_Type
))
16122 (Ada_Version
>= Ada_2012
16123 and then Ekind
(Id_Type
) = E_Incomplete_Type
16124 and then Full_View
(Id_Type
) = Parent_Type
)
16126 -- Constraint checks on formals are generated during expansion,
16127 -- based on the signature of the original subprogram. The bounds
16128 -- of the derived type are not relevant, and thus we can use
16129 -- the base type for the formals. However, the return type may be
16130 -- used in a context that requires that the proper static bounds
16131 -- be used (a case statement, for example) and for those cases
16132 -- we must use the derived type (first subtype), not its base.
16134 -- If the derived_type_definition has no constraints, we know that
16135 -- the derived type has the same constraints as the first subtype
16136 -- of the parent, and we can also use it rather than its base,
16137 -- which can lead to more efficient code.
16139 if Id_Type
= Parent_Type
then
16140 if Is_Scalar_Type
(Parent_Type
)
16142 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
16144 Set_Etype
(New_Id
, Derived_Type
);
16146 elsif Nkind
(Par
) = N_Full_Type_Declaration
16148 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
16151 (Subtype_Indication
(Type_Definition
(Par
)))
16153 Set_Etype
(New_Id
, Derived_Type
);
16156 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
16160 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
16164 Set_Etype
(New_Id
, Id_Type
);
16168 ----------------------
16169 -- Set_Derived_Name --
16170 ----------------------
16172 procedure Set_Derived_Name
is
16173 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
16175 if Nm
= TSS_Null
then
16176 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
16178 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
16180 end Set_Derived_Name
;
16182 -- Start of processing for Derive_Subprogram
16185 New_Subp
:= New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
16186 Mutate_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
16187 Set_Is_Not_Self_Hidden
(New_Subp
);
16189 -- Check whether the inherited subprogram is a private operation that
16190 -- should be inherited but not yet made visible. Such subprograms can
16191 -- become visible at a later point (e.g., the private part of a public
16192 -- child unit) via Declare_Inherited_Private_Subprograms. If the
16193 -- following predicate is true, then this is not such a private
16194 -- operation and the subprogram simply inherits the name of the parent
16195 -- subprogram. Note the special check for the names of controlled
16196 -- operations, which are currently exempted from being inherited with
16197 -- a hidden name because they must be findable for generation of
16198 -- implicit run-time calls.
16200 if not Is_Hidden
(Parent_Subp
)
16201 or else Is_Internal
(Parent_Subp
)
16202 or else Is_Private_Overriding
16203 or else Is_Internal_Name
(Chars
(Parent_Subp
))
16204 or else (Is_Controlled
(Parent_Type
)
16205 and then Chars
(Parent_Subp
) in Name_Adjust
16211 -- An inherited dispatching equality will be overridden by an internally
16212 -- generated one, or by an explicit one, so preserve its name and thus
16213 -- its entry in the dispatch table. Otherwise, if Parent_Subp is a
16214 -- private operation it may become invisible if the full view has
16215 -- progenitors, and the dispatch table will be malformed.
16216 -- We check that the type is limited to handle the anomalous declaration
16217 -- of Limited_Controlled, which is derived from a non-limited type, and
16218 -- which is handled specially elsewhere as well.
16220 elsif Chars
(Parent_Subp
) = Name_Op_Eq
16221 and then Is_Dispatching_Operation
(Parent_Subp
)
16222 and then Etype
(Parent_Subp
) = Standard_Boolean
16223 and then not Is_Limited_Type
(Etype
(First_Formal
(Parent_Subp
)))
16225 Etype
(First_Formal
(Parent_Subp
)) =
16226 Etype
(Next_Formal
(First_Formal
(Parent_Subp
)))
16230 -- If parent is hidden, this can be a regular derivation if the
16231 -- parent is immediately visible in a non-instantiating context,
16232 -- or if we are in the private part of an instance. This test
16233 -- should still be refined ???
16235 -- The test for In_Instance_Not_Visible avoids inheriting the derived
16236 -- operation as a non-visible operation in cases where the parent
16237 -- subprogram might not be visible now, but was visible within the
16238 -- original generic, so it would be wrong to make the inherited
16239 -- subprogram non-visible now. (Not clear if this test is fully
16240 -- correct; are there any cases where we should declare the inherited
16241 -- operation as not visible to avoid it being overridden, e.g., when
16242 -- the parent type is a generic actual with private primitives ???)
16244 -- (they should be treated the same as other private inherited
16245 -- subprograms, but it's not clear how to do this cleanly). ???
16247 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
16248 and then Is_Immediately_Visible
(Parent_Subp
)
16249 and then not In_Instance
)
16250 or else In_Instance_Not_Visible
16254 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
16255 -- overrides an interface primitive because interface primitives
16256 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
16258 elsif Ada_Version
>= Ada_2005
16259 and then Is_Dispatching_Operation
(Parent_Subp
)
16260 and then Present
(Covered_Interface_Op
(Parent_Subp
))
16264 -- Otherwise, the type is inheriting a private operation, so enter it
16265 -- with a special name so it can't be overridden. See also below, where
16266 -- we check for this case, and if so avoid setting Requires_Overriding.
16269 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
16272 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
16274 if Present
(Actual_Subp
) then
16275 Replace_Type
(Actual_Subp
, New_Subp
);
16277 Replace_Type
(Parent_Subp
, New_Subp
);
16280 Conditional_Delay
(New_Subp
, Parent_Subp
);
16282 -- If we are creating a renaming for a primitive operation of an
16283 -- actual of a generic derived type, we must examine the signature
16284 -- of the actual primitive, not that of the generic formal, which for
16285 -- example may be an interface. However the name and initial value
16286 -- of the inherited operation are those of the formal primitive.
16288 Formal
:= First_Formal
(Parent_Subp
);
16290 if Present
(Actual_Subp
) then
16291 Formal_Of_Actual
:= First_Formal
(Actual_Subp
);
16293 Formal_Of_Actual
:= Empty
;
16296 while Present
(Formal
) loop
16297 New_Formal
:= New_Copy
(Formal
);
16299 -- Extra formals are not inherited from a limited interface parent
16300 -- since limitedness is not inherited in such case (AI-419) and this
16301 -- affects the extra formals.
16303 if Is_Limited_Interface
(Parent_Type
) then
16304 Set_Extra_Formal
(New_Formal
, Empty
);
16305 Set_Extra_Accessibility
(New_Formal
, Empty
);
16308 -- Normally we do not go copying parents, but in the case of
16309 -- formals, we need to link up to the declaration (which is the
16310 -- parameter specification), and it is fine to link up to the
16311 -- original formal's parameter specification in this case.
16313 Set_Parent
(New_Formal
, Parent
(Formal
));
16314 Append_Entity
(New_Formal
, New_Subp
);
16316 if Present
(Formal_Of_Actual
) then
16317 Replace_Type
(Formal_Of_Actual
, New_Formal
);
16318 Next_Formal
(Formal_Of_Actual
);
16320 Replace_Type
(Formal
, New_Formal
);
16323 Next_Formal
(Formal
);
16326 -- Extra formals are shared between the parent subprogram and this
16327 -- internal entity built by Derive_Subprogram (implicit in the above
16328 -- copy of formals), unless the parent type is a limited interface type;
16329 -- hence we must inherit also the reference to the first extra formal.
16330 -- When the parent type is an interface, the extra formals will be added
16331 -- when the tagged type is frozen (see Expand_Freeze_Record_Type).
16333 if not Is_Limited_Interface
(Parent_Type
) then
16334 Set_Extra_Formals
(New_Subp
, Extra_Formals
(Parent_Subp
));
16336 if Ekind
(New_Subp
) = E_Function
then
16337 Set_Extra_Accessibility_Of_Result
(New_Subp
,
16338 Extra_Accessibility_Of_Result
(Parent_Subp
));
16342 -- If this derivation corresponds to a tagged generic actual, then
16343 -- primitive operations rename those of the actual. Otherwise the
16344 -- primitive operations rename those of the parent type, If the parent
16345 -- renames an intrinsic operator, so does the new subprogram. We except
16346 -- concatenation, which is always properly typed, and does not get
16347 -- expanded as other intrinsic operations.
16349 if No
(Actual_Subp
) then
16350 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
16351 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16352 Set_Is_Intrinsic_Subprogram
(New_Subp
);
16354 if Present
(Alias
(Parent_Subp
))
16355 and then Chars
(Parent_Subp
) /= Name_Op_Concat
16357 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
16359 Set_Alias
(New_Subp
, Parent_Subp
);
16363 Set_Alias
(New_Subp
, Parent_Subp
);
16367 Set_Alias
(New_Subp
, Actual_Subp
);
16370 Copy_Strub_Mode
(New_Subp
, Alias
(New_Subp
));
16372 -- Derived subprograms of a tagged type must inherit the convention
16373 -- of the parent subprogram (a requirement of AI95-117). Derived
16374 -- subprograms of untagged types simply get convention Ada by default.
16376 -- If the derived type is a tagged generic formal type with unknown
16377 -- discriminants, its convention is intrinsic (RM 6.3.1 (8)).
16379 -- However, if the type is derived from a generic formal, the further
16380 -- inherited subprogram has the convention of the non-generic ancestor.
16381 -- Otherwise there would be no way to override the operation.
16382 -- (This is subject to forthcoming ARG discussions).
16384 if Is_Tagged_Type
(Derived_Type
) then
16385 if Is_Generic_Type
(Derived_Type
)
16386 and then Has_Unknown_Discriminants
(Derived_Type
)
16388 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16391 if Is_Generic_Type
(Parent_Type
)
16392 and then Has_Unknown_Discriminants
(Parent_Type
)
16394 Set_Convention
(New_Subp
, Convention
(Alias
(Parent_Subp
)));
16396 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
16401 -- Predefined controlled operations retain their name even if the parent
16402 -- is hidden (see above), but they are not primitive operations if the
16403 -- ancestor is not visible, for example if the parent is a private
16404 -- extension completed with a controlled extension. Note that a full
16405 -- type that is controlled can break privacy: the flag Is_Controlled is
16406 -- set on both views of the type.
16408 if Is_Controlled
(Parent_Type
)
16409 and then Chars
(Parent_Subp
) in Name_Initialize
16412 and then Is_Hidden
(Parent_Subp
)
16413 and then not Is_Visibly_Controlled
(Parent_Type
)
16415 Set_Is_Hidden
(New_Subp
);
16418 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
16419 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
16421 if Ekind
(Parent_Subp
) = E_Procedure
then
16422 Set_Is_Valued_Procedure
16423 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
16425 Set_Has_Controlling_Result
16426 (New_Subp
, Has_Controlling_Result
(Parent_Subp
));
16429 -- No_Return must be inherited properly. If this is overridden in the
16430 -- case of a dispatching operation, then the check is made later in
16431 -- Check_Abstract_Overriding that the overriding operation is also
16432 -- No_Return (no such check is required for the nondispatching case).
16434 Set_No_Return
(New_Subp
, No_Return
(Parent_Subp
));
16436 -- If the parent subprogram is marked as Ghost, then so is the derived
16437 -- subprogram. The ghost policy for the derived subprogram is set from
16438 -- the effective ghost policy at the point of derived type declaration.
16440 if Is_Ghost_Entity
(Parent_Subp
) then
16441 Set_Is_Ghost_Entity
(New_Subp
);
16444 -- A derived function with a controlling result is abstract. If the
16445 -- Derived_Type is a nonabstract formal generic derived type, then
16446 -- inherited operations are not abstract: the required check is done at
16447 -- instantiation time. If the derivation is for a generic actual, the
16448 -- function is not abstract unless the actual is.
16450 if Is_Generic_Type
(Derived_Type
)
16451 and then not Is_Abstract_Type
(Derived_Type
)
16455 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
16456 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2). Note
16457 -- that functions with controlling access results of record extensions
16458 -- with a null extension part require overriding (AI95-00391/06).
16460 -- Ada 2022 (AI12-0042): Similarly, set those properties for
16461 -- implementing the rule of RM 7.3.2(6.1/4).
16463 -- A subprogram subject to pragma Extensions_Visible with value False
16464 -- requires overriding if the subprogram has at least one controlling
16465 -- OUT parameter (SPARK RM 6.1.7(6)).
16467 elsif Ada_Version
>= Ada_2005
16468 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16469 or else (Is_Tagged_Type
(Derived_Type
)
16470 and then Etype
(New_Subp
) = Derived_Type
16471 and then not Is_Null_Extension
(Derived_Type
))
16472 or else (Is_Tagged_Type
(Derived_Type
)
16473 and then Ekind
(Etype
(New_Subp
)) =
16474 E_Anonymous_Access_Type
16475 and then Designated_Type
(Etype
(New_Subp
)) =
16477 or else (Comes_From_Source
(Alias
(New_Subp
))
16478 and then Is_EVF_Procedure
(Alias
(New_Subp
)))
16480 -- AI12-0042: Set Requires_Overriding when a type extension
16481 -- inherits a private operation that is visible at the
16482 -- point of extension (Has_Private_Ancestor is False) from
16483 -- an ancestor that has Type_Invariant'Class, and when the
16484 -- type extension is in a visible part (the latter as
16485 -- clarified by AI12-0382).
16488 (not Has_Private_Ancestor
(Derived_Type
)
16489 and then Has_Invariants
(Parent_Type
)
16491 Present
(Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16494 (Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16495 and then Is_Private_Primitive
(Parent_Subp
)
16496 and then In_Visible_Part
(Scope
(Derived_Type
))))
16498 and then No
(Actual_Subp
)
16500 if not Is_Tagged_Type
(Derived_Type
)
16501 or else Is_Abstract_Type
(Derived_Type
)
16502 or else Is_Abstract_Subprogram
(Alias
(New_Subp
))
16504 Set_Is_Abstract_Subprogram
(New_Subp
);
16506 -- If the Chars of the new subprogram is different from that of the
16507 -- parent's one, it means that we entered it with a special name so
16508 -- it can't be overridden (see above). In that case we had better not
16509 -- *require* it to be overridden. This is the case where the parent
16510 -- type inherited the operation privately, so there's no danger of
16511 -- dangling dispatching.
16513 elsif Chars
(New_Subp
) = Chars
(Alias
(New_Subp
)) then
16514 Set_Requires_Overriding
(New_Subp
);
16517 elsif Ada_Version
< Ada_2005
16518 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16519 or else (Is_Tagged_Type
(Derived_Type
)
16520 and then Etype
(New_Subp
) = Derived_Type
16521 and then No
(Actual_Subp
)))
16523 Set_Is_Abstract_Subprogram
(New_Subp
);
16525 -- AI05-0097 : an inherited operation that dispatches on result is
16526 -- abstract if the derived type is abstract, even if the parent type
16527 -- is concrete and the derived type is a null extension.
16529 elsif Has_Controlling_Result
(Alias
(New_Subp
))
16530 and then Is_Abstract_Type
(Etype
(New_Subp
))
16532 Set_Is_Abstract_Subprogram
(New_Subp
);
16534 -- Finally, if the parent type is abstract we must verify that all
16535 -- inherited operations are either non-abstract or overridden, or that
16536 -- the derived type itself is abstract (this check is performed at the
16537 -- end of a package declaration, in Check_Abstract_Overriding). A
16538 -- private overriding in the parent type will not be visible in the
16539 -- derivation if we are not in an inner package or in a child unit of
16540 -- the parent type, in which case the abstractness of the inherited
16541 -- operation is carried to the new subprogram.
16543 elsif Is_Abstract_Type
(Parent_Type
)
16544 and then not In_Open_Scopes
(Scope
(Parent_Type
))
16545 and then Is_Private_Overriding
16546 and then Is_Abstract_Subprogram
(Visible_Subp
)
16548 if No
(Actual_Subp
) then
16549 Set_Alias
(New_Subp
, Visible_Subp
);
16550 Set_Is_Abstract_Subprogram
(New_Subp
, True);
16553 -- If this is a derivation for an instance of a formal derived
16554 -- type, abstractness comes from the primitive operation of the
16555 -- actual, not from the operation inherited from the ancestor.
16557 Set_Is_Abstract_Subprogram
16558 (New_Subp
, Is_Abstract_Subprogram
(Actual_Subp
));
16562 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
16564 -- Ada RM 6.1.1 (15): If a subprogram inherits nonconforming class-wide
16565 -- preconditions and the derived type is abstract, the derived operation
16566 -- is abstract as well if parent subprogram is not abstract or null.
16568 if Is_Abstract_Type
(Derived_Type
)
16569 and then Has_Non_Trivial_Precondition
(Parent_Subp
)
16570 and then Present
(Interfaces
(Derived_Type
))
16573 -- Add useful attributes of subprogram before the freeze point,
16574 -- in case freezing is delayed or there are previous errors.
16576 Set_Is_Dispatching_Operation
(New_Subp
);
16579 Iface_Prim
: constant Entity_Id
:= Covered_Interface_Op
(New_Subp
);
16582 if Present
(Iface_Prim
)
16583 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
16585 Set_Is_Abstract_Subprogram
(New_Subp
);
16590 -- Check for case of a derived subprogram for the instantiation of a
16591 -- formal derived tagged type, if so mark the subprogram as dispatching
16592 -- and inherit the dispatching attributes of the actual subprogram. The
16593 -- derived subprogram is effectively renaming of the actual subprogram,
16594 -- so it needs to have the same attributes as the actual.
16596 if Present
(Actual_Subp
)
16597 and then Is_Dispatching_Operation
(Actual_Subp
)
16599 Set_Is_Dispatching_Operation
(New_Subp
);
16601 if Present
(DTC_Entity
(Actual_Subp
)) then
16602 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Actual_Subp
));
16603 Set_DT_Position_Value
(New_Subp
, DT_Position
(Actual_Subp
));
16607 -- Indicate that a derived subprogram does not require a body and that
16608 -- it does not require processing of default expressions.
16610 Set_Has_Completion
(New_Subp
);
16611 Set_Default_Expressions_Processed
(New_Subp
);
16613 if Ekind
(New_Subp
) = E_Function
then
16614 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
16615 Set_Returns_By_Ref
(New_Subp
, Returns_By_Ref
(Parent_Subp
));
16618 -- Ada 2022 (AI12-0279): If a Yield aspect is specified True for a
16619 -- primitive subprogram S of a type T, then the aspect is inherited
16620 -- by the corresponding primitive subprogram of each descendant of T.
16622 if Is_Tagged_Type
(Derived_Type
)
16623 and then Is_Dispatching_Operation
(New_Subp
)
16624 and then Has_Yield_Aspect
(Alias
(New_Subp
))
16626 Set_Has_Yield_Aspect
(New_Subp
, Has_Yield_Aspect
(Alias
(New_Subp
)));
16629 Set_Is_Ada_2022_Only
(New_Subp
, Is_Ada_2022_Only
(Parent_Subp
));
16630 end Derive_Subprogram
;
16632 ------------------------
16633 -- Derive_Subprograms --
16634 ------------------------
16636 procedure Derive_Subprograms
16637 (Parent_Type
: Entity_Id
;
16638 Derived_Type
: Entity_Id
;
16639 Generic_Actual
: Entity_Id
:= Empty
)
16641 Op_List
: constant Elist_Id
:=
16642 Collect_Primitive_Operations
(Parent_Type
);
16644 function Check_Derived_Type
return Boolean;
16645 -- Check that all the entities derived from Parent_Type are found in
16646 -- the list of primitives of Derived_Type exactly in the same order.
16648 procedure Derive_Interface_Subprogram
16649 (New_Subp
: out Entity_Id
;
16651 Actual_Subp
: Entity_Id
);
16652 -- Derive New_Subp from the ultimate alias of the parent subprogram Subp
16653 -- (which is an interface primitive). If Generic_Actual is present then
16654 -- Actual_Subp is the actual subprogram corresponding with the generic
16655 -- subprogram Subp.
16657 ------------------------
16658 -- Check_Derived_Type --
16659 ------------------------
16661 function Check_Derived_Type
return Boolean is
16663 Derived_Elmt
: Elmt_Id
;
16664 Derived_Op
: Entity_Id
;
16665 Derived_Ops
: Elist_Id
;
16666 Parent_Elmt
: Elmt_Id
;
16667 Parent_Op
: Entity_Id
;
16670 -- Traverse list of entities in the current scope searching for
16671 -- an incomplete type whose full-view is derived type.
16673 E
:= First_Entity
(Scope
(Derived_Type
));
16674 while Present
(E
) and then E
/= Derived_Type
loop
16675 if Ekind
(E
) = E_Incomplete_Type
16676 and then Present
(Full_View
(E
))
16677 and then Full_View
(E
) = Derived_Type
16679 -- Disable this test if Derived_Type completes an incomplete
16680 -- type because in such case more primitives can be added
16681 -- later to the list of primitives of Derived_Type by routine
16682 -- Process_Incomplete_Dependents.
16690 Derived_Ops
:= Collect_Primitive_Operations
(Derived_Type
);
16692 Derived_Elmt
:= First_Elmt
(Derived_Ops
);
16693 Parent_Elmt
:= First_Elmt
(Op_List
);
16694 while Present
(Parent_Elmt
) loop
16695 Parent_Op
:= Node
(Parent_Elmt
);
16696 Derived_Op
:= Node
(Derived_Elmt
);
16698 -- At this early stage Derived_Type has no entities with attribute
16699 -- Interface_Alias. In addition, such primitives are always
16700 -- located at the end of the list of primitives of Parent_Type.
16701 -- Therefore, if found we can safely stop processing pending
16704 exit when Present
(Interface_Alias
(Parent_Op
));
16706 -- Handle hidden entities
16708 if not Is_Predefined_Dispatching_Operation
(Parent_Op
)
16709 and then Is_Hidden
(Parent_Op
)
16711 if Present
(Derived_Op
)
16712 and then Primitive_Names_Match
(Parent_Op
, Derived_Op
)
16714 Next_Elmt
(Derived_Elmt
);
16719 or else Ekind
(Parent_Op
) /= Ekind
(Derived_Op
)
16720 or else not Primitive_Names_Match
(Parent_Op
, Derived_Op
)
16725 Next_Elmt
(Derived_Elmt
);
16728 Next_Elmt
(Parent_Elmt
);
16732 end Check_Derived_Type
;
16734 ---------------------------------
16735 -- Derive_Interface_Subprogram --
16736 ---------------------------------
16738 procedure Derive_Interface_Subprogram
16739 (New_Subp
: out Entity_Id
;
16741 Actual_Subp
: Entity_Id
)
16743 Iface_Subp
: constant Entity_Id
:= Ultimate_Alias
(Subp
);
16744 Iface_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Iface_Subp
);
16747 pragma Assert
(Is_Interface
(Iface_Type
));
16750 (New_Subp
=> New_Subp
,
16751 Parent_Subp
=> Iface_Subp
,
16752 Derived_Type
=> Derived_Type
,
16753 Parent_Type
=> Iface_Type
,
16754 Actual_Subp
=> Actual_Subp
);
16756 -- Given that this new interface entity corresponds with a primitive
16757 -- of the parent that was not overridden we must leave it associated
16758 -- with its parent primitive to ensure that it will share the same
16759 -- dispatch table slot when overridden. We must set the Alias to Subp
16760 -- (instead of Iface_Subp), and we must fix Is_Abstract_Subprogram
16761 -- (in case we inherited Subp from Iface_Type via a nonabstract
16762 -- generic formal type).
16764 if No
(Actual_Subp
) then
16765 Set_Alias
(New_Subp
, Subp
);
16768 T
: Entity_Id
:= Find_Dispatching_Type
(Subp
);
16770 while Etype
(T
) /= T
loop
16771 if Is_Generic_Type
(T
) and then not Is_Abstract_Type
(T
) then
16772 Set_Is_Abstract_Subprogram
(New_Subp
, False);
16780 -- For instantiations this is not needed since the previous call to
16781 -- Derive_Subprogram leaves the entity well decorated.
16784 pragma Assert
(Alias
(New_Subp
) = Actual_Subp
);
16787 end Derive_Interface_Subprogram
;
16791 Alias_Subp
: Entity_Id
;
16792 Act_List
: Elist_Id
;
16793 Act_Elmt
: Elmt_Id
;
16794 Act_Subp
: Entity_Id
:= Empty
;
16796 Need_Search
: Boolean := False;
16797 New_Subp
: Entity_Id
;
16798 Parent_Base
: Entity_Id
;
16801 -- Start of processing for Derive_Subprograms
16804 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
16805 and then Has_Discriminants
(Parent_Type
)
16806 and then Present
(Full_View
(Parent_Type
))
16808 Parent_Base
:= Full_View
(Parent_Type
);
16810 Parent_Base
:= Parent_Type
;
16813 if Present
(Generic_Actual
) then
16814 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
16815 Act_Elmt
:= First_Elmt
(Act_List
);
16817 Act_List
:= No_Elist
;
16818 Act_Elmt
:= No_Elmt
;
16821 -- Derive primitives inherited from the parent. Note that if the generic
16822 -- actual is present, this is not really a type derivation, it is a
16823 -- completion within an instance.
16825 -- Case 1: Derived_Type does not implement interfaces
16827 if not Is_Tagged_Type
(Derived_Type
)
16828 or else (not Has_Interfaces
(Derived_Type
)
16829 and then not (Present
(Generic_Actual
)
16830 and then Has_Interfaces
(Generic_Actual
)))
16832 Elmt
:= First_Elmt
(Op_List
);
16833 while Present
(Elmt
) loop
16834 Subp
:= Node
(Elmt
);
16836 -- Literals are derived earlier in the process of building the
16837 -- derived type, and are skipped here.
16839 if Ekind
(Subp
) = E_Enumeration_Literal
then
16842 -- The actual is a direct descendant and the common primitive
16843 -- operations appear in the same order.
16845 -- If the generic parent type is present, the derived type is an
16846 -- instance of a formal derived type, and within the instance its
16847 -- operations are those of the actual. We derive from the formal
16848 -- type but make the inherited operations aliases of the
16849 -- corresponding operations of the actual.
16852 pragma Assert
(No
(Node
(Act_Elmt
))
16853 or else (Primitive_Names_Match
(Subp
, Node
(Act_Elmt
))
16856 (Subp
, Node
(Act_Elmt
),
16857 Skip_Controlling_Formals
=> True)));
16860 (New_Subp
, Subp
, Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
16862 if Present
(Act_Elmt
) then
16863 Next_Elmt
(Act_Elmt
);
16870 -- Case 2: Derived_Type implements interfaces
16873 -- If the parent type has no predefined primitives we remove
16874 -- predefined primitives from the list of primitives of generic
16875 -- actual to simplify the complexity of this algorithm.
16877 if Present
(Generic_Actual
) then
16879 Has_Predefined_Primitives
: Boolean := False;
16882 -- Check if the parent type has predefined primitives
16884 Elmt
:= First_Elmt
(Op_List
);
16885 while Present
(Elmt
) loop
16886 Subp
:= Node
(Elmt
);
16888 if Is_Predefined_Dispatching_Operation
(Subp
)
16889 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
16891 Has_Predefined_Primitives
:= True;
16898 -- Remove predefined primitives of Generic_Actual. We must use
16899 -- an auxiliary list because in case of tagged types the value
16900 -- returned by Collect_Primitive_Operations is the value stored
16901 -- in its Primitive_Operations attribute (and we don't want to
16902 -- modify its current contents).
16904 if not Has_Predefined_Primitives
then
16906 Aux_List
: constant Elist_Id
:= New_Elmt_List
;
16909 Elmt
:= First_Elmt
(Act_List
);
16910 while Present
(Elmt
) loop
16911 Subp
:= Node
(Elmt
);
16913 if not Is_Predefined_Dispatching_Operation
(Subp
)
16914 or else Comes_From_Source
(Subp
)
16916 Append_Elmt
(Subp
, Aux_List
);
16922 Act_List
:= Aux_List
;
16926 Act_Elmt
:= First_Elmt
(Act_List
);
16927 Act_Subp
:= Node
(Act_Elmt
);
16931 -- Stage 1: If the generic actual is not present we derive the
16932 -- primitives inherited from the parent type. If the generic parent
16933 -- type is present, the derived type is an instance of a formal
16934 -- derived type, and within the instance its operations are those of
16935 -- the actual. We derive from the formal type but make the inherited
16936 -- operations aliases of the corresponding operations of the actual.
16938 Elmt
:= First_Elmt
(Op_List
);
16939 while Present
(Elmt
) loop
16940 Subp
:= Node
(Elmt
);
16941 Alias_Subp
:= Ultimate_Alias
(Subp
);
16943 -- Do not derive internal entities of the parent that link
16944 -- interface primitives with their covering primitive. These
16945 -- entities will be added to this type when frozen.
16947 if Present
(Interface_Alias
(Subp
)) then
16951 -- If the generic actual is present find the corresponding
16952 -- operation in the generic actual. If the parent type is a
16953 -- direct ancestor of the derived type then, even if it is an
16954 -- interface, the operations are inherited from the primary
16955 -- dispatch table and are in the proper order. If we detect here
16956 -- that primitives are not in the same order we traverse the list
16957 -- of primitive operations of the actual to find the one that
16958 -- implements the interface primitive.
16962 (Present
(Generic_Actual
)
16963 and then Present
(Act_Subp
)
16965 (Primitive_Names_Match
(Subp
, Act_Subp
)
16967 Type_Conformant
(Subp
, Act_Subp
,
16968 Skip_Controlling_Formals
=> True)))
16970 pragma Assert
(not Is_Ancestor
(Parent_Base
, Generic_Actual
,
16971 Use_Full_View
=> True));
16973 -- Remember that we need searching for all pending primitives
16975 Need_Search
:= True;
16977 -- Handle entities associated with interface primitives
16979 if Present
(Alias_Subp
)
16980 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
16981 and then not Is_Predefined_Dispatching_Operation
(Subp
)
16983 -- Search for the primitive in the homonym chain
16986 Find_Primitive_Covering_Interface
16987 (Tagged_Type
=> Generic_Actual
,
16988 Iface_Prim
=> Alias_Subp
);
16990 -- Previous search may not locate primitives covering
16991 -- interfaces defined in generics units or instantiations.
16992 -- (it fails if the covering primitive has formals whose
16993 -- type is also defined in generics or instantiations).
16994 -- In such case we search in the list of primitives of the
16995 -- generic actual for the internal entity that links the
16996 -- interface primitive and the covering primitive.
16999 and then Is_Generic_Type
(Parent_Type
)
17001 -- This code has been designed to handle only generic
17002 -- formals that implement interfaces that are defined
17003 -- in a generic unit or instantiation. If this code is
17004 -- needed for other cases we must review it because
17005 -- (given that it relies on Original_Location to locate
17006 -- the primitive of Generic_Actual that covers the
17007 -- interface) it could leave linked through attribute
17008 -- Alias entities of unrelated instantiations).
17012 (Scope
(Find_Dispatching_Type
(Alias_Subp
)))
17014 Instantiation_Location
17015 (Sloc
(Find_Dispatching_Type
(Alias_Subp
)))
17018 Iface_Prim_Loc
: constant Source_Ptr
:=
17019 Original_Location
(Sloc
(Alias_Subp
));
17026 First_Elmt
(Primitive_Operations
(Generic_Actual
));
17028 Search
: while Present
(Elmt
) loop
17029 Prim
:= Node
(Elmt
);
17031 if Present
(Interface_Alias
(Prim
))
17032 and then Original_Location
17033 (Sloc
(Interface_Alias
(Prim
))) =
17036 Act_Subp
:= Alias
(Prim
);
17045 pragma Assert
(Present
(Act_Subp
)
17046 or else Is_Abstract_Type
(Generic_Actual
)
17047 or else Serious_Errors_Detected
> 0);
17049 -- Handle predefined primitives plus the rest of user-defined
17053 Act_Elmt
:= First_Elmt
(Act_List
);
17054 while Present
(Act_Elmt
) loop
17055 Act_Subp
:= Node
(Act_Elmt
);
17057 exit when Primitive_Names_Match
(Subp
, Act_Subp
)
17058 and then Type_Conformant
17060 Skip_Controlling_Formals
=> True)
17061 and then No
(Interface_Alias
(Act_Subp
));
17063 Next_Elmt
(Act_Elmt
);
17066 if No
(Act_Elmt
) then
17072 -- Case 1: If the parent is a limited interface then it has the
17073 -- predefined primitives of synchronized interfaces. However, the
17074 -- actual type may be a non-limited type and hence it does not
17075 -- have such primitives.
17077 if Present
(Generic_Actual
)
17078 and then No
(Act_Subp
)
17079 and then Is_Limited_Interface
(Parent_Base
)
17080 and then Is_Predefined_Interface_Primitive
(Subp
)
17084 -- Case 2: Inherit entities associated with interfaces that were
17085 -- not covered by the parent type. We exclude here null interface
17086 -- primitives because they do not need special management.
17088 -- We also exclude interface operations that are renamings. If the
17089 -- subprogram is an explicit renaming of an interface primitive,
17090 -- it is a regular primitive operation, and the presence of its
17091 -- alias is not relevant: it has to be derived like any other
17094 elsif Present
(Alias
(Subp
))
17095 and then Nkind
(Unit_Declaration_Node
(Subp
)) /=
17096 N_Subprogram_Renaming_Declaration
17097 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
17099 (Nkind
(Parent
(Alias_Subp
)) = N_Procedure_Specification
17100 and then Null_Present
(Parent
(Alias_Subp
)))
17102 -- If this is an abstract private type then we transfer the
17103 -- derivation of the interface primitive from the partial view
17104 -- to the full view. This is safe because all the interfaces
17105 -- must be visible in the partial view. Done to avoid adding
17106 -- a new interface derivation to the private part of the
17107 -- enclosing package; otherwise this new derivation would be
17108 -- decorated as hidden when the analysis of the enclosing
17109 -- package completes.
17111 if Is_Abstract_Type
(Derived_Type
)
17112 and then In_Private_Part
(Current_Scope
)
17113 and then Has_Private_Declaration
(Derived_Type
)
17116 Partial_View
: Entity_Id
;
17121 Partial_View
:= First_Entity
(Current_Scope
);
17123 exit when No
(Partial_View
)
17124 or else (Has_Private_Declaration
(Partial_View
)
17126 Full_View
(Partial_View
) = Derived_Type
);
17128 Next_Entity
(Partial_View
);
17131 -- If the partial view was not found then the source code
17132 -- has errors and the derivation is not needed.
17134 if Present
(Partial_View
) then
17136 First_Elmt
(Primitive_Operations
(Partial_View
));
17137 while Present
(Elmt
) loop
17138 Ent
:= Node
(Elmt
);
17140 if Present
(Alias
(Ent
))
17141 and then Ultimate_Alias
(Ent
) = Alias
(Subp
)
17144 (Ent
, Primitive_Operations
(Derived_Type
));
17151 -- If the interface primitive was not found in the
17152 -- partial view then this interface primitive was
17153 -- overridden. We add a derivation to activate in
17154 -- Derive_Progenitor_Subprograms the machinery to
17158 Derive_Interface_Subprogram
17159 (New_Subp
=> New_Subp
,
17161 Actual_Subp
=> Act_Subp
);
17166 Derive_Interface_Subprogram
17167 (New_Subp
=> New_Subp
,
17169 Actual_Subp
=> Act_Subp
);
17172 -- Case 3: Common derivation
17176 (New_Subp
=> New_Subp
,
17177 Parent_Subp
=> Subp
,
17178 Derived_Type
=> Derived_Type
,
17179 Parent_Type
=> Parent_Base
,
17180 Actual_Subp
=> Act_Subp
);
17183 -- No need to update Act_Elm if we must search for the
17184 -- corresponding operation in the generic actual
17187 and then Present
(Act_Elmt
)
17189 Next_Elmt
(Act_Elmt
);
17190 Act_Subp
:= Node
(Act_Elmt
);
17197 -- Inherit additional operations from progenitors. If the derived
17198 -- type is a generic actual, there are not new primitive operations
17199 -- for the type because it has those of the actual, and therefore
17200 -- nothing needs to be done. The renamings generated above are not
17201 -- primitive operations, and their purpose is simply to make the
17202 -- proper operations visible within an instantiation.
17204 if No
(Generic_Actual
) then
17205 Derive_Progenitor_Subprograms
(Parent_Base
, Derived_Type
);
17209 -- Final check: Direct descendants must have their primitives in the
17210 -- same order. We exclude from this test untagged types and instances
17211 -- of formal derived types. We skip this test if we have already
17212 -- reported serious errors in the sources.
17214 pragma Assert
(not Is_Tagged_Type
(Derived_Type
)
17215 or else Present
(Generic_Actual
)
17216 or else Serious_Errors_Detected
> 0
17217 or else Check_Derived_Type
);
17218 end Derive_Subprograms
;
17220 --------------------------------
17221 -- Derived_Standard_Character --
17222 --------------------------------
17224 procedure Derived_Standard_Character
17226 Parent_Type
: Entity_Id
;
17227 Derived_Type
: Entity_Id
)
17229 Loc
: constant Source_Ptr
:= Sloc
(N
);
17230 Def
: constant Node_Id
:= Type_Definition
(N
);
17231 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17232 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
17233 Implicit_Base
: constant Entity_Id
:=
17235 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
17241 Discard_Node
(Process_Subtype
(Indic
, N
));
17243 Set_Etype
(Implicit_Base
, Parent_Base
);
17244 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
17245 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
17247 Set_Is_Character_Type
(Implicit_Base
, True);
17248 Set_Has_Delayed_Freeze
(Implicit_Base
);
17250 -- The bounds of the implicit base are the bounds of the parent base.
17251 -- Note that their type is the parent base.
17253 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
17254 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
17256 Set_Scalar_Range
(Implicit_Base
,
17259 High_Bound
=> Hi
));
17261 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
17262 Set_Etype
(Derived_Type
, Implicit_Base
);
17263 Set_Size_Info
(Derived_Type
, Parent_Type
);
17265 if not Known_RM_Size
(Derived_Type
) then
17266 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
17269 Set_Is_Character_Type
(Derived_Type
, True);
17271 if Nkind
(Indic
) /= N_Subtype_Indication
then
17273 -- If no explicit constraint, the bounds are those
17274 -- of the parent type.
17276 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
17277 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
17278 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
17281 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
17282 end Derived_Standard_Character
;
17284 ------------------------------
17285 -- Derived_Type_Declaration --
17286 ------------------------------
17288 procedure Derived_Type_Declaration
17291 Is_Completion
: Boolean)
17293 Parent_Type
: Entity_Id
;
17295 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean;
17296 -- Check whether the parent type is a generic formal, or derives
17297 -- directly or indirectly from one.
17299 ------------------------
17300 -- Comes_From_Generic --
17301 ------------------------
17303 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean is
17305 if Is_Generic_Type
(Typ
) then
17308 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
17311 elsif Is_Private_Type
(Typ
)
17312 and then Present
(Full_View
(Typ
))
17313 and then Is_Generic_Type
(Root_Type
(Full_View
(Typ
)))
17317 elsif Is_Generic_Actual_Type
(Typ
) then
17323 end Comes_From_Generic
;
17327 Def
: constant Node_Id
:= Type_Definition
(N
);
17328 Iface_Def
: Node_Id
;
17329 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17330 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
17331 Parent_Node
: Node_Id
;
17334 -- Start of processing for Derived_Type_Declaration
17337 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
17340 and then Is_Tagged_Type
(Parent_Type
)
17343 Partial_View
: constant Entity_Id
:=
17344 Incomplete_Or_Partial_View
(Parent_Type
);
17347 -- If the partial view was not found then the parent type is not
17348 -- a private type. Otherwise check if the partial view is a tagged
17351 if Present
(Partial_View
)
17352 and then Is_Private_Type
(Partial_View
)
17353 and then not Is_Tagged_Type
(Partial_View
)
17356 ("cannot derive from & declared as untagged private "
17357 & "(SPARK RM 3.4(1))", N
, Partial_View
);
17362 -- Ada 2005 (AI-251): In case of interface derivation check that the
17363 -- parent is also an interface.
17365 if Interface_Present
(Def
) then
17366 if not Is_Interface
(Parent_Type
) then
17367 Diagnose_Interface
(Indic
, Parent_Type
);
17370 Parent_Node
:= Parent
(Base_Type
(Parent_Type
));
17371 Iface_Def
:= Type_Definition
(Parent_Node
);
17373 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
17374 -- other limited interfaces.
17376 if Limited_Present
(Def
) then
17377 if Limited_Present
(Iface_Def
) then
17380 elsif Protected_Present
(Iface_Def
) then
17382 ("descendant of & must be declared as a protected "
17383 & "interface", N
, Parent_Type
);
17385 elsif Synchronized_Present
(Iface_Def
) then
17387 ("descendant of & must be declared as a synchronized "
17388 & "interface", N
, Parent_Type
);
17390 elsif Task_Present
(Iface_Def
) then
17392 ("descendant of & must be declared as a task interface",
17397 ("(Ada 2005) limited interface cannot inherit from "
17398 & "non-limited interface", Indic
);
17401 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
17402 -- from non-limited or limited interfaces.
17404 elsif not Protected_Present
(Def
)
17405 and then not Synchronized_Present
(Def
)
17406 and then not Task_Present
(Def
)
17408 if Limited_Present
(Iface_Def
) then
17411 elsif Protected_Present
(Iface_Def
) then
17413 ("descendant of & must be declared as a protected "
17414 & "interface", N
, Parent_Type
);
17416 elsif Synchronized_Present
(Iface_Def
) then
17418 ("descendant of & must be declared as a synchronized "
17419 & "interface", N
, Parent_Type
);
17421 elsif Task_Present
(Iface_Def
) then
17423 ("descendant of & must be declared as a task interface",
17432 if Is_Tagged_Type
(Parent_Type
)
17433 and then Is_Concurrent_Type
(Parent_Type
)
17434 and then not Is_Interface
(Parent_Type
)
17437 ("parent type of a record extension cannot be a synchronized "
17438 & "tagged type (RM 3.9.1 (3/1))", N
);
17439 Set_Etype
(T
, Any_Type
);
17443 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
17446 if Is_Tagged_Type
(Parent_Type
)
17447 and then Is_Non_Empty_List
(Interface_List
(Def
))
17454 Intf
:= First
(Interface_List
(Def
));
17455 while Present
(Intf
) loop
17456 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
17458 if not Is_Interface
(T
) then
17459 Diagnose_Interface
(Intf
, T
);
17461 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
17462 -- a limited type from having a nonlimited progenitor.
17464 elsif (Limited_Present
(Def
)
17465 or else (not Is_Interface
(Parent_Type
)
17466 and then Is_Limited_Type
(Parent_Type
)))
17467 and then not Is_Limited_Interface
(T
)
17470 ("progenitor interface& of limited type must be limited",
17478 -- Check consistency of any nonoverridable aspects that are
17479 -- inherited from multiple sources.
17481 Check_Inherited_Nonoverridable_Aspects
17483 Interface_List
=> Interface_List
(Def
),
17484 Parent_Type
=> Parent_Type
);
17487 if Parent_Type
= Any_Type
17488 or else Etype
(Parent_Type
) = Any_Type
17489 or else (Is_Class_Wide_Type
(Parent_Type
)
17490 and then Etype
(Parent_Type
) = T
)
17492 -- If Parent_Type is undefined or illegal, make new type into a
17493 -- subtype of Any_Type, and set a few attributes to prevent cascaded
17494 -- errors. If this is a self-definition, emit error now.
17496 if T
= Parent_Type
or else T
= Etype
(Parent_Type
) then
17497 Error_Msg_N
("type cannot be used in its own definition", Indic
);
17500 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
17501 Set_Etype
(T
, Any_Type
);
17502 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
17504 -- Initialize the list of primitive operations to an empty list,
17505 -- to cover tagged types as well as untagged types. For untagged
17506 -- types this is used either to analyze the call as legal when
17507 -- Extensions_Allowed is True, or to issue a better error message
17510 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
17515 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
17516 -- an interface is special because the list of interfaces in the full
17517 -- view can be given in any order. For example:
17519 -- type A is interface;
17520 -- type B is interface and A;
17521 -- type D is new B with private;
17523 -- type D is new A and B with null record; -- 1 --
17525 -- In this case we perform the following transformation of -1-:
17527 -- type D is new B and A with null record;
17529 -- If the parent of the full-view covers the parent of the partial-view
17530 -- we have two possible cases:
17532 -- 1) They have the same parent
17533 -- 2) The parent of the full-view implements some further interfaces
17535 -- In both cases we do not need to perform the transformation. In the
17536 -- first case the source program is correct and the transformation is
17537 -- not needed; in the second case the source program does not fulfill
17538 -- the no-hidden interfaces rule (AI-396) and the error will be reported
17541 -- This transformation not only simplifies the rest of the analysis of
17542 -- this type declaration but also simplifies the correct generation of
17543 -- the object layout to the expander.
17545 if In_Private_Part
(Current_Scope
)
17546 and then Is_Interface
(Parent_Type
)
17549 Partial_View
: Entity_Id
;
17550 Partial_View_Parent
: Entity_Id
;
17552 function Reorder_Interfaces
return Boolean;
17553 -- Look for an interface in the full view's interface list that
17554 -- matches the parent type of the partial view, and when found,
17555 -- rewrite the full view's parent with the partial view's parent,
17556 -- append the full view's original parent to the interface list,
17557 -- recursively call Derived_Type_Definition on the full type, and
17558 -- return True. If a match is not found, return False.
17560 ------------------------
17561 -- Reorder_Interfaces --
17562 ------------------------
17564 function Reorder_Interfaces
return Boolean is
17566 New_Iface
: Node_Id
;
17569 Iface
:= First
(Interface_List
(Def
));
17570 while Present
(Iface
) loop
17571 if Etype
(Iface
) = Etype
(Partial_View
) then
17572 Rewrite
(Subtype_Indication
(Def
),
17573 New_Copy
(Subtype_Indication
(Parent
(Partial_View
))));
17576 Make_Identifier
(Sloc
(N
), Chars
(Parent_Type
));
17577 Rewrite
(Iface
, New_Iface
);
17579 -- Analyze the transformed code
17581 Derived_Type_Declaration
(T
, N
, Is_Completion
);
17588 end Reorder_Interfaces
;
17591 -- Look for the associated private type declaration
17593 Partial_View
:= Incomplete_Or_Partial_View
(T
);
17595 -- If the partial view was not found then the source code has
17596 -- errors and the transformation is not needed.
17598 if Present
(Partial_View
) then
17599 Partial_View_Parent
:= Etype
(Partial_View
);
17601 -- If the parent of the full-view covers the parent of the
17602 -- partial-view we have nothing else to do.
17604 if Interface_Present_In_Ancestor
17605 (Parent_Type
, Partial_View_Parent
)
17609 -- Traverse the list of interfaces of the full view to look
17610 -- for the parent of the partial view and reorder the
17611 -- interfaces to match the order in the partial view,
17616 if Reorder_Interfaces
then
17617 -- Having the interfaces listed in any order is legal.
17618 -- However, the compiler does not properly handle
17619 -- different orders between partial and full views in
17620 -- generic units. We give a warning about the order
17621 -- mismatch, so the user can work around this problem.
17623 Error_Msg_N
("??full declaration does not respect " &
17624 "partial declaration order", T
);
17625 Error_Msg_N
("\??consider reordering", T
);
17634 -- Only composite types other than array types are allowed to have
17637 if Present
(Discriminant_Specifications
(N
)) then
17638 if (Is_Elementary_Type
(Parent_Type
)
17640 Is_Array_Type
(Parent_Type
))
17641 and then not Error_Posted
(N
)
17644 ("elementary or array type cannot have discriminants",
17645 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
17647 -- Unset Has_Discriminants flag to prevent cascaded errors, but
17648 -- only if we are not already processing a malformed syntax tree.
17650 if Is_Type
(T
) then
17651 Set_Has_Discriminants
(T
, False);
17656 -- In Ada 83, a derived type defined in a package specification cannot
17657 -- be used for further derivation until the end of its visible part.
17658 -- Note that derivation in the private part of the package is allowed.
17660 if Ada_Version
= Ada_83
17661 and then Is_Derived_Type
(Parent_Type
)
17662 and then In_Visible_Part
(Scope
(Parent_Type
))
17664 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
17666 ("(Ada 83) premature use of type for derivation", Indic
);
17670 -- Check for early use of incomplete or private type
17672 if Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
17673 Error_Msg_N
("premature derivation of incomplete type", Indic
);
17676 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
17677 and then not Comes_From_Generic
(Parent_Type
))
17678 or else Has_Private_Component
(Parent_Type
)
17680 -- The ancestor type of a formal type can be incomplete, in which
17681 -- case only the operations of the partial view are available in the
17682 -- generic. Subsequent checks may be required when the full view is
17683 -- analyzed to verify that a derivation from a tagged type has an
17686 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
17689 elsif No
(Underlying_Type
(Parent_Type
))
17690 or else Has_Private_Component
(Parent_Type
)
17693 ("premature derivation of derived or private type", Indic
);
17695 -- Flag the type itself as being in error, this prevents some
17696 -- nasty problems with subsequent uses of the malformed type.
17698 Set_Error_Posted
(T
);
17700 -- Check that within the immediate scope of an untagged partial
17701 -- view it's illegal to derive from the partial view if the
17702 -- full view is tagged. (7.3(7))
17704 -- We verify that the Parent_Type is a partial view by checking
17705 -- that it is not a Full_Type_Declaration (i.e. a private type or
17706 -- private extension declaration), to distinguish a partial view
17707 -- from a derivation from a private type which also appears as
17708 -- E_Private_Type. If the parent base type is not declared in an
17709 -- enclosing scope there is no need to check.
17711 elsif Present
(Full_View
(Parent_Type
))
17712 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
17713 and then not Is_Tagged_Type
(Parent_Type
)
17714 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
17715 and then In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
17718 ("premature derivation from type with tagged full view",
17723 -- Check that form of derivation is appropriate
17725 Taggd
:= Is_Tagged_Type
(Parent_Type
);
17727 -- Set the parent type to the class-wide type's specific type in this
17728 -- case to prevent cascading errors
17730 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
17731 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
17732 Set_Etype
(T
, Etype
(Parent_Type
));
17736 if Present
(Extension
) and then not Taggd
then
17738 ("type derived from untagged type cannot have extension", Indic
);
17740 elsif No
(Extension
) and then Taggd
then
17742 -- If this declaration is within a private part (or body) of a
17743 -- generic instantiation then the derivation is allowed (the parent
17744 -- type can only appear tagged in this case if it's a generic actual
17745 -- type, since it would otherwise have been rejected in the analysis
17746 -- of the generic template).
17748 if not Is_Generic_Actual_Type
(Parent_Type
)
17749 or else In_Visible_Part
(Scope
(Parent_Type
))
17751 if Is_Class_Wide_Type
(Parent_Type
) then
17753 ("parent type must not be a class-wide type", Indic
);
17755 -- Use specific type to prevent cascaded errors.
17757 Parent_Type
:= Etype
(Parent_Type
);
17761 ("type derived from tagged type must have extension", Indic
);
17766 -- AI-443: Synchronized formal derived types require a private
17767 -- extension. There is no point in checking the ancestor type or
17768 -- the progenitors since the construct is wrong to begin with.
17770 if Ada_Version
>= Ada_2005
17771 and then Is_Generic_Type
(T
)
17772 and then Present
(Original_Node
(N
))
17775 Decl
: constant Node_Id
:= Original_Node
(N
);
17778 if Nkind
(Decl
) = N_Formal_Type_Declaration
17779 and then Nkind
(Formal_Type_Definition
(Decl
)) =
17780 N_Formal_Derived_Type_Definition
17781 and then Synchronized_Present
(Formal_Type_Definition
(Decl
))
17782 and then No
(Extension
)
17784 -- Avoid emitting a duplicate error message
17786 and then not Error_Posted
(Indic
)
17789 ("synchronized derived type must have extension", N
);
17794 if Null_Exclusion_Present
(Def
)
17795 and then not Is_Access_Type
(Parent_Type
)
17797 Error_Msg_N
("null exclusion can only apply to an access type", N
);
17800 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
17802 -- Avoid deriving parent primitives of underlying record views
17804 Set_Is_Not_Self_Hidden
(T
);
17806 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
,
17807 Derive_Subps
=> not Is_Underlying_Record_View
(T
));
17809 -- AI-419: The parent type of an explicitly limited derived type must
17810 -- be a limited type or a limited interface.
17812 if Limited_Present
(Def
) then
17813 Set_Is_Limited_Record
(T
);
17815 if Is_Interface
(T
) then
17816 Set_Is_Limited_Interface
(T
);
17819 if not Is_Limited_Type
(Parent_Type
)
17821 (not Is_Interface
(Parent_Type
)
17822 or else not Is_Limited_Interface
(Parent_Type
))
17824 -- AI05-0096: a derivation in the private part of an instance is
17825 -- legal if the generic formal is untagged limited, and the actual
17828 if Is_Generic_Actual_Type
(Parent_Type
)
17829 and then In_Private_Part
(Current_Scope
)
17832 (Generic_Parent_Type
(Parent
(Parent_Type
)))
17838 ("parent type& of limited type must be limited",
17843 end Derived_Type_Declaration
;
17845 ------------------------
17846 -- Diagnose_Interface --
17847 ------------------------
17849 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
) is
17851 if not Is_Interface
(E
) and then E
/= Any_Type
then
17852 Error_Msg_NE
("(Ada 2005) & must be an interface", N
, E
);
17854 end Diagnose_Interface
;
17856 ----------------------------------
17857 -- Enumeration_Type_Declaration --
17858 ----------------------------------
17860 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
17867 -- Create identifier node representing lower bound
17869 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17870 L
:= First
(Literals
(Def
));
17871 Set_Chars
(B_Node
, Chars
(L
));
17872 Set_Entity
(B_Node
, L
);
17873 Set_Etype
(B_Node
, T
);
17874 Set_Is_Static_Expression
(B_Node
, True);
17876 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
17877 Set_Low_Bound
(R_Node
, B_Node
);
17879 Mutate_Ekind
(T
, E_Enumeration_Type
);
17880 Set_First_Literal
(T
, L
);
17882 Set_Is_Constrained
(T
);
17886 -- Loop through literals of enumeration type setting pos and rep values
17887 -- except that if the Ekind is already set, then it means the literal
17888 -- was already constructed (case of a derived type declaration and we
17889 -- should not disturb the Pos and Rep values.
17891 while Present
(L
) loop
17892 if Ekind
(L
) /= E_Enumeration_Literal
then
17893 Mutate_Ekind
(L
, E_Enumeration_Literal
);
17894 Set_Is_Not_Self_Hidden
(L
);
17895 Set_Enumeration_Pos
(L
, Ev
);
17896 Set_Enumeration_Rep
(L
, Ev
);
17897 Set_Is_Known_Valid
(L
, True);
17901 New_Overloaded_Entity
(L
);
17902 Generate_Definition
(L
);
17903 Set_Convention
(L
, Convention_Intrinsic
);
17905 -- Case of character literal
17907 if Nkind
(L
) = N_Defining_Character_Literal
then
17908 Set_Is_Character_Type
(T
, True);
17910 -- Check violation of No_Wide_Characters
17912 if Restriction_Check_Required
(No_Wide_Characters
) then
17913 Get_Name_String
(Chars
(L
));
17915 if Name_Len
>= 3 and then Name_Buffer
(1 .. 2) = "QW" then
17916 Check_Restriction
(No_Wide_Characters
, L
);
17925 -- Now create a node representing upper bound
17927 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17928 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
17929 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
17930 Set_Etype
(B_Node
, T
);
17931 Set_Is_Static_Expression
(B_Node
, True);
17933 Set_High_Bound
(R_Node
, B_Node
);
17935 -- Initialize various fields of the type. Some of this information
17936 -- may be overwritten later through rep. clauses.
17938 Set_Scalar_Range
(T
, R_Node
);
17939 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
17940 Set_Enum_Esize
(T
);
17941 Set_Enum_Pos_To_Rep
(T
, Empty
);
17943 -- Set Discard_Names if configuration pragma set, or if there is
17944 -- a parameterless pragma in the current declarative region
17946 if Global_Discard_Names
or else Discard_Names
(Scope
(T
)) then
17947 Set_Discard_Names
(T
);
17950 -- Process end label if there is one
17952 if Present
(Def
) then
17953 Process_End_Label
(Def
, 'e', T
);
17955 end Enumeration_Type_Declaration
;
17957 ---------------------------------
17958 -- Expand_To_Stored_Constraint --
17959 ---------------------------------
17961 function Expand_To_Stored_Constraint
17963 Constraint
: Elist_Id
) return Elist_Id
17965 Explicitly_Discriminated_Type
: Entity_Id
;
17966 Expansion
: Elist_Id
;
17967 Discriminant
: Entity_Id
;
17969 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
17970 -- Find the nearest type that actually specifies discriminants
17972 ---------------------------------
17973 -- Type_With_Explicit_Discrims --
17974 ---------------------------------
17976 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
17977 Typ
: constant E
:= Base_Type
(Id
);
17980 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
17981 if Present
(Full_View
(Typ
)) then
17982 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
17986 if Has_Discriminants
(Typ
) then
17991 if Etype
(Typ
) = Typ
then
17993 elsif Has_Discriminants
(Typ
) then
17996 return Type_With_Explicit_Discrims
(Etype
(Typ
));
17999 end Type_With_Explicit_Discrims
;
18001 -- Start of processing for Expand_To_Stored_Constraint
18004 if No
(Constraint
) or else Is_Empty_Elmt_List
(Constraint
) then
18008 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
18010 if No
(Explicitly_Discriminated_Type
) then
18014 Expansion
:= New_Elmt_List
;
18017 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
18018 while Present
(Discriminant
) loop
18020 (Get_Discriminant_Value
18021 (Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
18023 Next_Stored_Discriminant
(Discriminant
);
18027 end Expand_To_Stored_Constraint
;
18029 ---------------------------
18030 -- Find_Hidden_Interface --
18031 ---------------------------
18033 function Find_Hidden_Interface
18035 Dest
: Elist_Id
) return Entity_Id
18038 Iface_Elmt
: Elmt_Id
;
18041 if Present
(Src
) and then Present
(Dest
) then
18042 Iface_Elmt
:= First_Elmt
(Src
);
18043 while Present
(Iface_Elmt
) loop
18044 Iface
:= Node
(Iface_Elmt
);
18046 if Is_Interface
(Iface
)
18047 and then not Contain_Interface
(Iface
, Dest
)
18052 Next_Elmt
(Iface_Elmt
);
18057 end Find_Hidden_Interface
;
18059 --------------------
18060 -- Find_Type_Name --
18061 --------------------
18063 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
18064 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
18065 New_Id
: Entity_Id
;
18067 Prev_Par
: Node_Id
;
18069 procedure Check_Duplicate_Aspects
;
18070 -- Check that aspects specified in a completion have not been specified
18071 -- already in the partial view.
18073 procedure Tag_Mismatch
;
18074 -- Diagnose a tagged partial view whose full view is untagged. We post
18075 -- the message on the full view, with a reference to the previous
18076 -- partial view. The partial view can be private or incomplete, and
18077 -- these are handled in a different manner, so we determine the position
18078 -- of the error message from the respective slocs of both.
18080 -----------------------------
18081 -- Check_Duplicate_Aspects --
18082 -----------------------------
18084 procedure Check_Duplicate_Aspects
is
18085 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
;
18086 -- Return the corresponding aspect of the partial view which matches
18087 -- the aspect id of Asp. Return Empty is no such aspect exists.
18089 -----------------------------
18090 -- Get_Partial_View_Aspect --
18091 -----------------------------
18093 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
is
18094 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
18095 Prev_Asps
: constant List_Id
:= Aspect_Specifications
(Prev_Par
);
18096 Prev_Asp
: Node_Id
;
18099 if Present
(Prev_Asps
) then
18100 Prev_Asp
:= First
(Prev_Asps
);
18101 while Present
(Prev_Asp
) loop
18102 if Get_Aspect_Id
(Prev_Asp
) = Asp_Id
then
18111 end Get_Partial_View_Aspect
;
18115 Full_Asps
: constant List_Id
:= Aspect_Specifications
(N
);
18116 Full_Asp
: Node_Id
;
18117 Part_Asp
: Node_Id
;
18119 -- Start of processing for Check_Duplicate_Aspects
18122 if Present
(Full_Asps
) then
18123 Full_Asp
:= First
(Full_Asps
);
18124 while Present
(Full_Asp
) loop
18125 Part_Asp
:= Get_Partial_View_Aspect
(Full_Asp
);
18127 -- An aspect and its class-wide counterpart are two distinct
18128 -- aspects and may apply to both views of an entity.
18130 if Present
(Part_Asp
)
18131 and then Class_Present
(Part_Asp
) = Class_Present
(Full_Asp
)
18134 ("aspect already specified in private declaration",
18141 if Has_Discriminants
(Prev
)
18142 and then not Has_Unknown_Discriminants
(Prev
)
18143 and then Get_Aspect_Id
(Full_Asp
) =
18144 Aspect_Implicit_Dereference
18147 ("cannot specify aspect if partial view has known "
18148 & "discriminants", Full_Asp
);
18154 end Check_Duplicate_Aspects
;
18160 procedure Tag_Mismatch
is
18162 if Sloc
(Prev
) < Sloc
(Id
) then
18163 if Ada_Version
>= Ada_2012
18164 and then Nkind
(N
) = N_Private_Type_Declaration
18167 ("declaration of private } must be a tagged type", Id
, Prev
);
18170 ("full declaration of } must be a tagged type", Id
, Prev
);
18174 if Ada_Version
>= Ada_2012
18175 and then Nkind
(N
) = N_Private_Type_Declaration
18178 ("declaration of private } must be a tagged type", Prev
, Id
);
18181 ("full declaration of } must be a tagged type", Prev
, Id
);
18186 -- Start of processing for Find_Type_Name
18189 -- Find incomplete declaration, if one was given
18191 Prev
:= Current_Entity_In_Scope
(Id
);
18193 -- New type declaration
18199 -- Previous declaration exists
18202 Prev_Par
:= Parent
(Prev
);
18204 -- Error if not incomplete/private case except if previous
18205 -- declaration is implicit, etc. Enter_Name will emit error if
18208 if not Is_Incomplete_Or_Private_Type
(Prev
) then
18212 -- Check invalid completion of private or incomplete type
18214 elsif Nkind
(N
) not in N_Full_Type_Declaration
18215 | N_Task_Type_Declaration
18216 | N_Protected_Type_Declaration
18218 (Ada_Version
< Ada_2012
18219 or else not Is_Incomplete_Type
(Prev
)
18220 or else Nkind
(N
) not in N_Private_Type_Declaration
18221 | N_Private_Extension_Declaration
)
18223 -- Completion must be a full type declarations (RM 7.3(4))
18225 Error_Msg_Sloc
:= Sloc
(Prev
);
18226 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
18228 -- Set scope of Id to avoid cascaded errors. Entity is never
18229 -- examined again, except when saving globals in generics.
18231 Set_Scope
(Id
, Current_Scope
);
18234 -- If this is a repeated incomplete declaration, no further
18235 -- checks are possible.
18237 if Nkind
(N
) = N_Incomplete_Type_Declaration
then
18241 -- Case of full declaration of incomplete type
18243 elsif Ekind
(Prev
) = E_Incomplete_Type
18244 and then (Ada_Version
< Ada_2012
18245 or else No
(Full_View
(Prev
))
18246 or else not Is_Private_Type
(Full_View
(Prev
)))
18248 -- Indicate that the incomplete declaration has a matching full
18249 -- declaration. The defining occurrence of the incomplete
18250 -- declaration remains the visible one, and the procedure
18251 -- Get_Full_View dereferences it whenever the type is used.
18253 if Present
(Full_View
(Prev
)) then
18254 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
18257 Set_Full_View
(Prev
, Id
);
18258 Append_Entity
(Id
, Current_Scope
);
18259 Set_Is_Public
(Id
, Is_Public
(Prev
));
18260 Set_Is_Internal
(Id
);
18263 -- If the incomplete view is tagged, a class_wide type has been
18264 -- created already. Use it for the private type as well, in order
18265 -- to prevent multiple incompatible class-wide types that may be
18266 -- created for self-referential anonymous access components.
18268 if Is_Tagged_Type
(Prev
)
18269 and then Present
(Class_Wide_Type
(Prev
))
18271 Mutate_Ekind
(Id
, Ekind
(Prev
)); -- will be reset later
18272 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(Prev
));
18274 -- Type of the class-wide type is the current Id. Previously
18275 -- this was not done for private declarations because of order-
18276 -- of-elaboration issues in the back end, but gigi now handles
18279 Set_Etype
(Class_Wide_Type
(Id
), Id
);
18282 -- Case of full declaration of private type
18285 -- If the private type was a completion of an incomplete type then
18286 -- update Prev to reference the private type
18288 if Ada_Version
>= Ada_2012
18289 and then Ekind
(Prev
) = E_Incomplete_Type
18290 and then Present
(Full_View
(Prev
))
18291 and then Is_Private_Type
(Full_View
(Prev
))
18293 Prev
:= Full_View
(Prev
);
18294 Prev_Par
:= Parent
(Prev
);
18297 if Nkind
(N
) = N_Full_Type_Declaration
18298 and then Nkind
(Type_Definition
(N
)) in
18299 N_Record_Definition | N_Derived_Type_Definition
18300 and then Interface_Present
(Type_Definition
(N
))
18303 ("completion of private type cannot be an interface", N
);
18306 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
18307 if Etype
(Prev
) /= Prev
then
18309 -- Prev is a private subtype or a derived type, and needs
18312 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
18315 elsif Ekind
(Prev
) = E_Private_Type
18316 and then Nkind
(N
) in N_Task_Type_Declaration
18317 | N_Protected_Type_Declaration
18320 ("completion of nonlimited type cannot be limited", N
);
18322 elsif Ekind
(Prev
) = E_Record_Type_With_Private
18323 and then Nkind
(N
) in N_Task_Type_Declaration
18324 | N_Protected_Type_Declaration
18326 if not Is_Limited_Record
(Prev
) then
18328 ("completion of nonlimited type cannot be limited", N
);
18330 elsif No
(Interface_List
(N
)) then
18332 ("completion of tagged private type must be tagged",
18337 -- Ada 2005 (AI-251): Private extension declaration of a task
18338 -- type or a protected type. This case arises when covering
18339 -- interface types.
18341 elsif Nkind
(N
) in N_Task_Type_Declaration
18342 | N_Protected_Type_Declaration
18346 elsif Nkind
(N
) /= N_Full_Type_Declaration
18347 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
18350 ("full view of private extension must be an extension", N
);
18352 elsif not (Abstract_Present
(Parent
(Prev
)))
18353 and then Abstract_Present
(Type_Definition
(N
))
18356 ("full view of non-abstract extension cannot be abstract", N
);
18359 if not In_Private_Part
(Current_Scope
) then
18361 ("declaration of full view must appear in private part", N
);
18364 if Ada_Version
>= Ada_2012
then
18365 Check_Duplicate_Aspects
;
18368 Copy_And_Swap
(Prev
, Id
);
18369 Set_Has_Private_Declaration
(Prev
);
18370 Set_Has_Private_Declaration
(Id
);
18372 -- AI12-0133: Indicate whether we have a partial view with
18373 -- unknown discriminants, in which case initialization of objects
18374 -- of the type do not receive an invariant check.
18376 Set_Partial_View_Has_Unknown_Discr
18377 (Prev
, Has_Unknown_Discriminants
(Id
));
18379 -- Preserve aspect and iterator flags that may have been set on
18380 -- the partial view.
18382 Set_Has_Delayed_Aspects
(Prev
, Has_Delayed_Aspects
(Id
));
18383 Set_Has_Implicit_Dereference
(Prev
, Has_Implicit_Dereference
(Id
));
18385 -- If no error, propagate freeze_node from private to full view.
18386 -- It may have been generated for an early operational item.
18388 if Present
(Freeze_Node
(Id
))
18389 and then Serious_Errors_Detected
= 0
18390 and then No
(Full_View
(Id
))
18392 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
18393 Set_Freeze_Node
(Id
, Empty
);
18394 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
18397 Set_Full_View
(Id
, Prev
);
18401 -- Verify that full declaration conforms to partial one
18403 if Is_Incomplete_Or_Private_Type
(Prev
)
18404 and then Present
(Discriminant_Specifications
(Prev_Par
))
18406 if Present
(Discriminant_Specifications
(N
)) then
18407 if Ekind
(Prev
) = E_Incomplete_Type
then
18408 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
18410 Check_Discriminant_Conformance
(N
, Prev
, Id
);
18415 ("missing discriminants in full type declaration", N
);
18417 -- To avoid cascaded errors on subsequent use, share the
18418 -- discriminants of the partial view.
18420 Set_Discriminant_Specifications
(N
,
18421 Discriminant_Specifications
(Prev_Par
));
18425 -- A prior untagged partial view can have an associated class-wide
18426 -- type due to use of the class attribute, and in this case the full
18427 -- type must also be tagged. This Ada 95 usage is deprecated in favor
18428 -- of incomplete tagged declarations, but we check for it.
18431 and then (Is_Tagged_Type
(Prev
)
18432 or else Present
(Class_Wide_Type
(Prev
)))
18434 -- Ada 2012 (AI05-0162): A private type may be the completion of
18435 -- an incomplete type.
18437 if Ada_Version
>= Ada_2012
18438 and then Is_Incomplete_Type
(Prev
)
18439 and then Nkind
(N
) in N_Private_Type_Declaration
18440 | N_Private_Extension_Declaration
18442 -- No need to check private extensions since they are tagged
18444 if Nkind
(N
) = N_Private_Type_Declaration
18445 and then not Tagged_Present
(N
)
18450 -- The full declaration is either a tagged type (including
18451 -- a synchronized type that implements interfaces) or a
18452 -- type extension, otherwise this is an error.
18454 elsif Nkind
(N
) in N_Task_Type_Declaration
18455 | N_Protected_Type_Declaration
18457 if No
(Interface_List
(N
)) and then not Error_Posted
(N
) then
18461 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
18463 -- Indicate that the previous declaration (tagged incomplete
18464 -- or private declaration) requires the same on the full one.
18466 if not Tagged_Present
(Type_Definition
(N
)) then
18468 Set_Is_Tagged_Type
(Id
);
18471 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
18472 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
18474 ("full declaration of } must be a record extension",
18477 -- Set some attributes to produce a usable full view
18479 Set_Is_Tagged_Type
(Id
);
18488 and then Nkind
(Parent
(Prev
)) = N_Incomplete_Type_Declaration
18489 and then Present
(Premature_Use
(Parent
(Prev
)))
18491 Error_Msg_Sloc
:= Sloc
(N
);
18493 ("\full declaration #", Premature_Use
(Parent
(Prev
)));
18498 end Find_Type_Name
;
18500 -------------------------
18501 -- Find_Type_Of_Object --
18502 -------------------------
18504 function Find_Type_Of_Object
18505 (Obj_Def
: Node_Id
;
18506 Related_Nod
: Node_Id
) return Entity_Id
18508 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
18509 P
: Node_Id
:= Parent
(Obj_Def
);
18514 -- If the parent is a component_definition node we climb to the
18515 -- component_declaration node.
18517 if Nkind
(P
) = N_Component_Definition
then
18521 -- Case of an anonymous array subtype
18523 if Def_Kind
in N_Array_Type_Definition
then
18525 Array_Type_Declaration
(T
, Obj_Def
);
18527 -- Create an explicit subtype whenever possible
18529 elsif Nkind
(P
) /= N_Component_Declaration
18530 and then Def_Kind
= N_Subtype_Indication
18532 -- Base name of subtype on object name, which will be unique in
18533 -- the current scope.
18535 -- If this is a duplicate declaration, return base type, to avoid
18536 -- generating duplicate anonymous types.
18538 if Error_Posted
(P
) then
18539 Analyze
(Subtype_Mark
(Obj_Def
));
18540 return Entity
(Subtype_Mark
(Obj_Def
));
18545 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
18547 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
18549 -- If In_Spec_Expression, for example within a pre/postcondition,
18550 -- provide enough information for use of the subtype without
18551 -- depending on full analysis and freezing, which will happen when
18552 -- building the corresponding subprogram.
18554 if In_Spec_Expression
then
18555 Analyze
(Subtype_Mark
(Obj_Def
));
18558 Base_T
: constant Entity_Id
:= Entity
(Subtype_Mark
(Obj_Def
));
18559 New_Def
: constant Node_Id
:= New_Copy_Tree
(Obj_Def
);
18560 Decl
: constant Node_Id
:=
18561 Make_Subtype_Declaration
(Sloc
(P
),
18562 Defining_Identifier
=> T
,
18563 Subtype_Indication
=> New_Def
);
18566 Set_Etype
(T
, Base_T
);
18567 Mutate_Ekind
(T
, Subtype_Kind
(Ekind
(Base_T
)));
18568 Set_Parent
(T
, Decl
);
18569 Set_Scope
(T
, Current_Scope
);
18571 if Ekind
(T
) = E_Array_Subtype
then
18572 Constrain_Array
(T
, New_Def
, Related_Nod
, T
, 'P');
18574 elsif Ekind
(T
) = E_Record_Subtype
then
18575 Set_First_Entity
(T
, First_Entity
(Base_T
));
18576 Set_Has_Discriminants
(T
, Has_Discriminants
(Base_T
));
18577 Set_Is_Constrained
(T
);
18580 Insert_Before
(Related_Nod
, Decl
);
18586 -- When generating code, insert subtype declaration ahead of
18587 -- declaration that generated it.
18589 Insert_Action
(Obj_Def
,
18590 Make_Subtype_Declaration
(Sloc
(P
),
18591 Defining_Identifier
=> T
,
18592 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
18594 -- This subtype may need freezing, and this will not be done
18595 -- automatically if the object declaration is not in declarative
18596 -- part. Since this is an object declaration, the type cannot always
18597 -- be frozen here. Deferred constants do not freeze their type
18598 -- (which often enough will be private).
18600 if Nkind
(P
) = N_Object_Declaration
18601 and then Constant_Present
(P
)
18602 and then No
(Expression
(P
))
18606 -- Here we freeze the base type of object type to catch premature use
18607 -- of discriminated private type without a full view.
18610 Insert_Actions
(Obj_Def
, Freeze_Entity
(Base_Type
(T
), P
));
18613 -- Ada 2005 AI-406: the object definition in an object declaration
18614 -- can be an access definition.
18616 elsif Def_Kind
= N_Access_Definition
then
18617 T
:= Access_Definition
(Related_Nod
, Obj_Def
);
18619 Set_Is_Local_Anonymous_Access
18620 (T
, Ada_Version
< Ada_2012
18621 or else Nkind
(P
) /= N_Object_Declaration
18622 or else Is_Library_Level_Entity
(Defining_Identifier
(P
)));
18624 -- Otherwise, the object definition is just a subtype_mark
18627 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
18631 end Find_Type_Of_Object
;
18633 --------------------------------
18634 -- Find_Type_Of_Subtype_Indic --
18635 --------------------------------
18637 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
18641 -- Case of subtype mark with a constraint
18643 if Nkind
(S
) = N_Subtype_Indication
then
18644 Find_Type
(Subtype_Mark
(S
));
18645 Typ
:= Entity
(Subtype_Mark
(S
));
18648 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
18651 ("incorrect constraint for this kind of type", Constraint
(S
));
18652 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
18655 -- Otherwise we have a subtype mark without a constraint
18657 elsif Error_Posted
(S
) then
18658 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
18667 end Find_Type_Of_Subtype_Indic
;
18669 -------------------------------------
18670 -- Floating_Point_Type_Declaration --
18671 -------------------------------------
18673 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
18674 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
18675 Max_Digs_Val
: constant Uint
:= Digits_Value
(Standard_Long_Long_Float
);
18677 Base_Typ
: Entity_Id
;
18678 Implicit_Base
: Entity_Id
;
18680 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
18681 -- Find if given digits value, and possibly a specified range, allows
18682 -- derivation from specified type
18684 procedure Convert_Bound
(B
: Node_Id
);
18685 -- If specified, the bounds must be static but may be of different
18686 -- types. They must be converted into machine numbers of the base type,
18687 -- in accordance with RM 4.9(38).
18689 function Find_Base_Type
return Entity_Id
;
18690 -- Find a predefined base type that Def can derive from, or generate
18691 -- an error and substitute Long_Long_Float if none exists.
18693 ---------------------
18694 -- Can_Derive_From --
18695 ---------------------
18697 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
18698 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
18701 -- Check specified "digits" constraint
18703 if Digs_Val
> Digits_Value
(E
) then
18707 -- Check for matching range, if specified
18709 if Present
(Spec
) then
18710 if Expr_Value_R
(Type_Low_Bound
(E
)) >
18711 Expr_Value_R
(Low_Bound
(Spec
))
18716 if Expr_Value_R
(Type_High_Bound
(E
)) <
18717 Expr_Value_R
(High_Bound
(Spec
))
18724 end Can_Derive_From
;
18726 -------------------
18727 -- Convert_Bound --
18728 --------------------
18730 procedure Convert_Bound
(B
: Node_Id
) is
18732 -- If the bound is not a literal it can only be static if it is
18733 -- a static constant, possibly of a specified type.
18735 if Is_Entity_Name
(B
)
18736 and then Ekind
(Entity
(B
)) = E_Constant
18738 Rewrite
(B
, Constant_Value
(Entity
(B
)));
18741 if Nkind
(B
) = N_Real_Literal
then
18742 Set_Realval
(B
, Machine
(Base_Typ
, Realval
(B
), Round
, B
));
18743 Set_Is_Machine_Number
(B
);
18744 Set_Etype
(B
, Base_Typ
);
18748 --------------------
18749 -- Find_Base_Type --
18750 --------------------
18752 function Find_Base_Type
return Entity_Id
is
18753 Choice
: Elmt_Id
:= First_Elmt
(Predefined_Float_Types
);
18756 -- Iterate over the predefined types in order, returning the first
18757 -- one that Def can derive from.
18759 while Present
(Choice
) loop
18760 if Can_Derive_From
(Node
(Choice
)) then
18761 return Node
(Choice
);
18764 Next_Elmt
(Choice
);
18767 -- If we can't derive from any existing type, use Long_Long_Float
18768 -- and give appropriate message explaining the problem.
18770 if Digs_Val
> Max_Digs_Val
then
18771 -- It might be the case that there is a type with the requested
18772 -- range, just not the combination of digits and range.
18775 ("no predefined type has requested range and precision",
18776 Real_Range_Specification
(Def
));
18780 ("range too large for any predefined type",
18781 Real_Range_Specification
(Def
));
18784 return Standard_Long_Long_Float
;
18785 end Find_Base_Type
;
18787 -- Start of processing for Floating_Point_Type_Declaration
18790 Check_Restriction
(No_Floating_Point
, Def
);
18792 -- Create an implicit base type
18795 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
18797 -- Analyze and verify digits value
18799 Analyze_And_Resolve
(Digs
, Any_Integer
);
18800 Check_Digits_Expression
(Digs
);
18801 Digs_Val
:= Expr_Value
(Digs
);
18803 -- Process possible range spec and find correct type to derive from
18805 Process_Real_Range_Specification
(Def
);
18807 -- Check that requested number of digits is not too high.
18809 if Digs_Val
> Max_Digs_Val
then
18811 -- The check for Max_Base_Digits may be somewhat expensive, as it
18812 -- requires reading System, so only do it when necessary.
18815 Max_Base_Digits
: constant Uint
:=
18818 (Parent
(RTE
(RE_Max_Base_Digits
))));
18821 if Digs_Val
> Max_Base_Digits
then
18822 Error_Msg_Uint_1
:= Max_Base_Digits
;
18823 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
18825 elsif No
(Real_Range_Specification
(Def
)) then
18826 Error_Msg_Uint_1
:= Max_Digs_Val
;
18827 Error_Msg_N
("types with more than ^ digits need range spec "
18828 & "(RM 3.5.7(6))", Digs
);
18833 -- Find a suitable type to derive from or complain and use a substitute
18835 Base_Typ
:= Find_Base_Type
;
18837 -- If there are bounds given in the declaration use them as the bounds
18838 -- of the type, otherwise use the bounds of the predefined base type
18839 -- that was chosen based on the Digits value.
18841 if Present
(Real_Range_Specification
(Def
)) then
18842 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
18843 Set_Is_Constrained
(T
);
18845 Convert_Bound
(Type_Low_Bound
(T
));
18846 Convert_Bound
(Type_High_Bound
(T
));
18849 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
18852 -- Complete definition of implicit base and declared first subtype. The
18853 -- inheritance of the rep item chain ensures that SPARK-related pragmas
18854 -- are not clobbered when the floating point type acts as a full view of
18857 Set_Etype
(Implicit_Base
, Base_Typ
);
18858 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
18859 Set_Size_Info
(Implicit_Base
, Base_Typ
);
18860 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
18861 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
18862 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
18863 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Base_Typ
));
18865 Mutate_Ekind
(T
, E_Floating_Point_Subtype
);
18866 Set_Etype
(T
, Implicit_Base
);
18867 Set_Size_Info
(T
, Implicit_Base
);
18868 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
18869 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
18871 if Digs_Val
>= Uint_1
then
18872 Set_Digits_Value
(T
, Digs_Val
);
18874 pragma Assert
(Serious_Errors_Detected
> 0); null;
18876 end Floating_Point_Type_Declaration
;
18878 ----------------------------
18879 -- Get_Discriminant_Value --
18880 ----------------------------
18882 -- This is the situation:
18884 -- There is a non-derived type
18886 -- type T0 (Dx, Dy, Dz...)
18888 -- There are zero or more levels of derivation, with each derivation
18889 -- either purely inheriting the discriminants, or defining its own.
18891 -- type Ti is new Ti-1
18893 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
18895 -- subtype Ti is ...
18897 -- The subtype issue is avoided by the use of Original_Record_Component,
18898 -- and the fact that derived subtypes also derive the constraints.
18900 -- This chain leads back from
18902 -- Typ_For_Constraint
18904 -- Typ_For_Constraint has discriminants, and the value for each
18905 -- discriminant is given by its corresponding Elmt of Constraints.
18907 -- Discriminant is some discriminant in this hierarchy
18909 -- We need to return its value
18911 -- We do this by recursively searching each level, and looking for
18912 -- Discriminant. Once we get to the bottom, we start backing up
18913 -- returning the value for it which may in turn be a discriminant
18914 -- further up, so on the backup we continue the substitution.
18916 function Get_Discriminant_Value
18917 (Discriminant
: Entity_Id
;
18918 Typ_For_Constraint
: Entity_Id
;
18919 Constraint
: Elist_Id
) return Node_Id
18921 function Root_Corresponding_Discriminant
18922 (Discr
: Entity_Id
) return Entity_Id
;
18923 -- Given a discriminant, traverse the chain of inherited discriminants
18924 -- and return the topmost discriminant.
18926 function Search_Derivation_Levels
18928 Discrim_Values
: Elist_Id
;
18929 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
18930 -- This is the routine that performs the recursive search of levels
18931 -- as described above.
18933 -------------------------------------
18934 -- Root_Corresponding_Discriminant --
18935 -------------------------------------
18937 function Root_Corresponding_Discriminant
18938 (Discr
: Entity_Id
) return Entity_Id
18944 while Present
(Corresponding_Discriminant
(D
)) loop
18945 D
:= Corresponding_Discriminant
(D
);
18949 end Root_Corresponding_Discriminant
;
18951 ------------------------------
18952 -- Search_Derivation_Levels --
18953 ------------------------------
18955 function Search_Derivation_Levels
18957 Discrim_Values
: Elist_Id
;
18958 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
18962 Result
: Node_Or_Entity_Id
;
18963 Result_Entity
: Node_Id
;
18966 -- If inappropriate type, return Error, this happens only in
18967 -- cascaded error situations, and we want to avoid a blow up.
18969 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
18973 -- Look deeper if possible. Use Stored_Constraints only for
18974 -- untagged types. For tagged types use the given constraint.
18975 -- This asymmetry needs explanation???
18977 if not Stored_Discrim_Values
18978 and then Present
(Stored_Constraint
(Ti
))
18979 and then not Is_Tagged_Type
(Ti
)
18982 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
18986 Td
: Entity_Id
:= Etype
(Ti
);
18989 -- If the parent type is private, the full view may include
18990 -- renamed discriminants, and it is those stored values that
18991 -- may be needed (the partial view never has more information
18992 -- than the full view).
18994 if Is_Private_Type
(Td
) and then Present
(Full_View
(Td
)) then
18995 Td
:= Full_View
(Td
);
18999 Result
:= Discriminant
;
19002 if Present
(Stored_Constraint
(Ti
)) then
19004 Search_Derivation_Levels
19005 (Td
, Stored_Constraint
(Ti
), True);
19008 Search_Derivation_Levels
19009 (Td
, Discrim_Values
, Stored_Discrim_Values
);
19015 -- Extra underlying places to search, if not found above. For
19016 -- concurrent types, the relevant discriminant appears in the
19017 -- corresponding record. For a type derived from a private type
19018 -- without discriminant, the full view inherits the discriminants
19019 -- of the full view of the parent.
19021 if Result
= Discriminant
then
19022 if Is_Concurrent_Type
(Ti
)
19023 and then Present
(Corresponding_Record_Type
(Ti
))
19026 Search_Derivation_Levels
(
19027 Corresponding_Record_Type
(Ti
),
19029 Stored_Discrim_Values
);
19031 elsif Is_Private_Type
(Ti
)
19032 and then not Has_Discriminants
(Ti
)
19033 and then Present
(Full_View
(Ti
))
19034 and then Etype
(Full_View
(Ti
)) /= Ti
19037 Search_Derivation_Levels
(
19040 Stored_Discrim_Values
);
19044 -- If Result is not a (reference to a) discriminant, return it,
19045 -- otherwise set Result_Entity to the discriminant.
19047 if Nkind
(Result
) = N_Defining_Identifier
then
19048 pragma Assert
(Result
= Discriminant
);
19049 Result_Entity
:= Result
;
19052 if not Denotes_Discriminant
(Result
) then
19056 Result_Entity
:= Entity
(Result
);
19059 -- See if this level of derivation actually has discriminants because
19060 -- tagged derivations can add them, hence the lower levels need not
19063 if not Has_Discriminants
(Ti
) then
19067 -- Scan Ti's discriminants for Result_Entity, and return its
19068 -- corresponding value, if any.
19070 Result_Entity
:= Original_Record_Component
(Result_Entity
);
19072 Assoc
:= First_Elmt
(Discrim_Values
);
19074 if Stored_Discrim_Values
then
19075 Disc
:= First_Stored_Discriminant
(Ti
);
19077 Disc
:= First_Discriminant
(Ti
);
19080 while Present
(Disc
) loop
19082 -- If no further associations return the discriminant, value will
19083 -- be found on the second pass.
19089 if Original_Record_Component
(Disc
) = Result_Entity
then
19090 return Node
(Assoc
);
19095 if Stored_Discrim_Values
then
19096 Next_Stored_Discriminant
(Disc
);
19098 Next_Discriminant
(Disc
);
19102 -- Could not find it
19105 end Search_Derivation_Levels
;
19109 Result
: Node_Or_Entity_Id
;
19111 -- Start of processing for Get_Discriminant_Value
19114 -- ??? This routine is a gigantic mess and will be deleted. For the
19115 -- time being just test for the trivial case before calling recurse.
19117 -- We are now celebrating the 20th anniversary of this comment!
19119 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
19125 D
:= First_Discriminant
(Typ_For_Constraint
);
19126 E
:= First_Elmt
(Constraint
);
19127 while Present
(D
) loop
19128 if Chars
(D
) = Chars
(Discriminant
) then
19132 Next_Discriminant
(D
);
19138 Result
:= Search_Derivation_Levels
19139 (Typ_For_Constraint
, Constraint
, False);
19141 -- ??? hack to disappear when this routine is gone
19143 if Nkind
(Result
) = N_Defining_Identifier
then
19149 D
:= First_Discriminant
(Typ_For_Constraint
);
19150 E
:= First_Elmt
(Constraint
);
19151 while Present
(D
) loop
19152 if Root_Corresponding_Discriminant
(D
) = Discriminant
then
19156 Next_Discriminant
(D
);
19162 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
19164 end Get_Discriminant_Value
;
19166 --------------------------
19167 -- Has_Range_Constraint --
19168 --------------------------
19170 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
19171 C
: constant Node_Id
:= Constraint
(N
);
19174 if Nkind
(C
) = N_Range_Constraint
then
19177 elsif Nkind
(C
) = N_Digits_Constraint
then
19179 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
19180 or else Present
(Range_Constraint
(C
));
19182 elsif Nkind
(C
) = N_Delta_Constraint
then
19183 return Present
(Range_Constraint
(C
));
19188 end Has_Range_Constraint
;
19190 ------------------------
19191 -- Inherit_Components --
19192 ------------------------
19194 function Inherit_Components
19196 Parent_Base
: Entity_Id
;
19197 Derived_Base
: Entity_Id
;
19198 Is_Tagged
: Boolean;
19199 Inherit_Discr
: Boolean;
19200 Discs
: Elist_Id
) return Elist_Id
19202 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
19204 procedure Inherit_Component
19205 (Old_C
: Entity_Id
;
19206 Plain_Discrim
: Boolean := False;
19207 Stored_Discrim
: Boolean := False);
19208 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
19209 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
19210 -- True, Old_C is a stored discriminant. If they are both false then
19211 -- Old_C is a regular component.
19213 -----------------------
19214 -- Inherit_Component --
19215 -----------------------
19217 procedure Inherit_Component
19218 (Old_C
: Entity_Id
;
19219 Plain_Discrim
: Boolean := False;
19220 Stored_Discrim
: Boolean := False)
19222 procedure Set_Anonymous_Type
(Id
: Entity_Id
);
19223 -- Id denotes the entity of an access discriminant or anonymous
19224 -- access component. Set the type of Id to either the same type of
19225 -- Old_C or create a new one depending on whether the parent and
19226 -- the child types are in the same scope.
19228 ------------------------
19229 -- Set_Anonymous_Type --
19230 ------------------------
19232 procedure Set_Anonymous_Type
(Id
: Entity_Id
) is
19233 Old_Typ
: constant Entity_Id
:= Etype
(Old_C
);
19236 if Scope
(Parent_Base
) = Scope
(Derived_Base
) then
19237 Set_Etype
(Id
, Old_Typ
);
19239 -- The parent and the derived type are in two different scopes.
19240 -- Reuse the type of the original discriminant / component by
19241 -- copying it in order to preserve all attributes.
19245 Typ
: constant Entity_Id
:= New_Copy
(Old_Typ
);
19248 Set_Etype
(Id
, Typ
);
19250 -- Since we do not generate component declarations for
19251 -- inherited components, associate the itype with the
19254 Set_Associated_Node_For_Itype
(Typ
, Parent
(Derived_Base
));
19255 Set_Scope
(Typ
, Derived_Base
);
19258 end Set_Anonymous_Type
;
19260 -- Local variables and constants
19262 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
19264 Corr_Discrim
: Entity_Id
;
19265 Discrim
: Entity_Id
;
19267 -- Start of processing for Inherit_Component
19270 pragma Assert
(not Is_Tagged
or not Stored_Discrim
);
19272 Set_Parent
(New_C
, Parent
(Old_C
));
19274 -- Regular discriminants and components must be inserted in the scope
19275 -- of the Derived_Base. Do it here.
19277 if not Stored_Discrim
then
19278 Enter_Name
(New_C
);
19281 -- For tagged types the Original_Record_Component must point to
19282 -- whatever this field was pointing to in the parent type. This has
19283 -- already been achieved by the call to New_Copy above.
19285 if not Is_Tagged
then
19286 Set_Original_Record_Component
(New_C
, New_C
);
19287 Set_Corresponding_Record_Component
(New_C
, Old_C
);
19290 -- Set the proper type of an access discriminant
19292 if Ekind
(New_C
) = E_Discriminant
19293 and then Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
19295 Set_Anonymous_Type
(New_C
);
19298 -- If we have inherited a component then see if its Etype contains
19299 -- references to Parent_Base discriminants. In this case, replace
19300 -- these references with the constraints given in Discs. We do not
19301 -- do this for the partial view of private types because this is
19302 -- not needed (only the components of the full view will be used
19303 -- for code generation) and cause problem. We also avoid this
19304 -- transformation in some error situations.
19306 if Ekind
(New_C
) = E_Component
then
19308 -- Set the proper type of an anonymous access component
19310 if Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
then
19311 Set_Anonymous_Type
(New_C
);
19313 elsif (Is_Private_Type
(Derived_Base
)
19314 and then not Is_Generic_Type
(Derived_Base
))
19315 or else (Is_Empty_Elmt_List
(Discs
)
19316 and then not Expander_Active
)
19318 Set_Etype
(New_C
, Etype
(Old_C
));
19321 -- The current component introduces a circularity of the
19324 -- limited with Pack_2;
19325 -- package Pack_1 is
19326 -- type T_1 is tagged record
19327 -- Comp : access Pack_2.T_2;
19333 -- package Pack_2 is
19334 -- type T_2 is new Pack_1.T_1 with ...;
19339 Constrain_Component_Type
19340 (Old_C
, Derived_Base
, N
, Parent_Base
, Discs
));
19344 if Plain_Discrim
then
19345 Set_Corresponding_Discriminant
(New_C
, Old_C
);
19346 Build_Discriminal
(New_C
);
19348 -- If we are explicitly inheriting a stored discriminant it will be
19349 -- completely hidden.
19351 elsif Stored_Discrim
then
19352 Set_Corresponding_Discriminant
(New_C
, Empty
);
19353 Set_Discriminal
(New_C
, Empty
);
19354 Set_Is_Completely_Hidden
(New_C
);
19356 -- Set the Original_Record_Component of each discriminant in the
19357 -- derived base to point to the corresponding stored that we just
19360 Discrim
:= First_Discriminant
(Derived_Base
);
19361 while Present
(Discrim
) loop
19362 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
19364 -- Corr_Discrim could be missing in an error situation
19366 if Present
(Corr_Discrim
)
19367 and then Original_Record_Component
(Corr_Discrim
) = Old_C
19369 Set_Original_Record_Component
(Discrim
, New_C
);
19370 Set_Corresponding_Record_Component
(Discrim
, Empty
);
19373 Next_Discriminant
(Discrim
);
19376 Append_Entity
(New_C
, Derived_Base
);
19379 if not Is_Tagged
then
19380 Append_Elmt
(Old_C
, Assoc_List
);
19381 Append_Elmt
(New_C
, Assoc_List
);
19383 end Inherit_Component
;
19385 -- Variables local to Inherit_Component
19387 Loc
: constant Source_Ptr
:= Sloc
(N
);
19389 Parent_Discrim
: Entity_Id
;
19390 Stored_Discrim
: Entity_Id
;
19392 Component
: Entity_Id
;
19394 -- Start of processing for Inherit_Components
19397 if not Is_Tagged
then
19398 Append_Elmt
(Parent_Base
, Assoc_List
);
19399 Append_Elmt
(Derived_Base
, Assoc_List
);
19402 -- Inherit parent discriminants if needed
19404 if Inherit_Discr
then
19405 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
19406 while Present
(Parent_Discrim
) loop
19407 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
19408 Next_Discriminant
(Parent_Discrim
);
19412 -- Create explicit stored discrims for untagged types when necessary
19414 if not Has_Unknown_Discriminants
(Derived_Base
)
19415 and then Has_Discriminants
(Parent_Base
)
19416 and then not Is_Tagged
19419 or else First_Discriminant
(Parent_Base
) /=
19420 First_Stored_Discriminant
(Parent_Base
))
19422 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
19423 while Present
(Stored_Discrim
) loop
19424 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
19425 Next_Stored_Discriminant
(Stored_Discrim
);
19429 -- See if we can apply the second transformation for derived types, as
19430 -- explained in point 6. in the comments above Build_Derived_Record_Type
19431 -- This is achieved by appending Derived_Base discriminants into Discs,
19432 -- which has the side effect of returning a non empty Discs list to the
19433 -- caller of Inherit_Components, which is what we want. This must be
19434 -- done for private derived types if there are explicit stored
19435 -- discriminants, to ensure that we can retrieve the values of the
19436 -- constraints provided in the ancestors.
19439 and then Is_Empty_Elmt_List
(Discs
)
19440 and then Present
(First_Discriminant
(Derived_Base
))
19442 (not Is_Private_Type
(Derived_Base
)
19443 or else Is_Completely_Hidden
19444 (First_Stored_Discriminant
(Derived_Base
))
19445 or else Is_Generic_Type
(Derived_Base
))
19447 D
:= First_Discriminant
(Derived_Base
);
19448 while Present
(D
) loop
19449 Append_Elmt
(New_Occurrence_Of
(D
, Loc
), Discs
);
19450 Next_Discriminant
(D
);
19454 -- Finally, inherit non-discriminant components unless they are not
19455 -- visible because defined or inherited from the full view of the
19456 -- parent. Don't inherit the _parent field of the parent type.
19458 Component
:= First_Entity
(Parent_Base
);
19459 while Present
(Component
) loop
19461 -- Ada 2005 (AI-251): Do not inherit components associated with
19462 -- secondary tags of the parent.
19464 if Ekind
(Component
) = E_Component
19465 and then Present
(Related_Type
(Component
))
19469 elsif Ekind
(Component
) /= E_Component
19470 or else Chars
(Component
) = Name_uParent
19474 -- If the derived type is within the parent type's declarative
19475 -- region, then the components can still be inherited even though
19476 -- they aren't visible at this point. This can occur for cases
19477 -- such as within public child units where the components must
19478 -- become visible upon entering the child unit's private part.
19480 elsif not Is_Visible_Component
(Component
)
19481 and then not In_Open_Scopes
(Scope
(Parent_Base
))
19485 elsif Ekind
(Derived_Base
) in E_Private_Type | E_Limited_Private_Type
19490 Inherit_Component
(Component
);
19493 Next_Entity
(Component
);
19496 -- For tagged derived types, inherited discriminants cannot be used in
19497 -- component declarations of the record extension part. To achieve this
19498 -- we mark the inherited discriminants as not visible.
19500 if Is_Tagged
and then Inherit_Discr
then
19501 D
:= First_Discriminant
(Derived_Base
);
19502 while Present
(D
) loop
19503 Set_Is_Immediately_Visible
(D
, False);
19504 Next_Discriminant
(D
);
19509 end Inherit_Components
;
19511 ----------------------
19512 -- Is_EVF_Procedure --
19513 ----------------------
19515 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean is
19516 Formal
: Entity_Id
;
19519 -- Examine the formals of an Extensions_Visible False procedure looking
19520 -- for a controlling OUT parameter.
19522 if Ekind
(Subp
) = E_Procedure
19523 and then Extensions_Visible_Status
(Subp
) = Extensions_Visible_False
19525 Formal
:= First_Formal
(Subp
);
19526 while Present
(Formal
) loop
19527 if Ekind
(Formal
) = E_Out_Parameter
19528 and then Is_Controlling_Formal
(Formal
)
19533 Next_Formal
(Formal
);
19538 end Is_EVF_Procedure
;
19540 --------------------------
19541 -- Is_Private_Primitive --
19542 --------------------------
19544 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean is
19545 Prim_Scope
: constant Entity_Id
:= Scope
(Prim
);
19546 Priv_Entity
: Entity_Id
;
19548 if Is_Package_Or_Generic_Package
(Prim_Scope
) then
19549 Priv_Entity
:= First_Private_Entity
(Prim_Scope
);
19551 while Present
(Priv_Entity
) loop
19552 if Priv_Entity
= Prim
then
19556 Next_Entity
(Priv_Entity
);
19561 end Is_Private_Primitive
;
19563 ------------------------------
19564 -- Is_Valid_Constraint_Kind --
19565 ------------------------------
19567 function Is_Valid_Constraint_Kind
19568 (T_Kind
: Type_Kind
;
19569 Constraint_Kind
: Node_Kind
) return Boolean
19573 when Enumeration_Kind
19576 return Constraint_Kind
= N_Range_Constraint
;
19578 when Decimal_Fixed_Point_Kind
=>
19579 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19581 when Ordinary_Fixed_Point_Kind
=>
19582 return Constraint_Kind
in N_Delta_Constraint | N_Range_Constraint
;
19585 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19592 | E_Incomplete_Type
19596 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
19599 return True; -- Error will be detected later
19601 end Is_Valid_Constraint_Kind
;
19603 --------------------------
19604 -- Is_Visible_Component --
19605 --------------------------
19607 function Is_Visible_Component
19609 N
: Node_Id
:= Empty
) return Boolean
19611 Original_Comp
: Entity_Id
:= Empty
;
19612 Original_Type
: Entity_Id
;
19613 Type_Scope
: Entity_Id
;
19615 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
19616 -- Check whether parent type of inherited component is declared locally,
19617 -- possibly within a nested package or instance. The current scope is
19618 -- the derived record itself.
19620 -------------------
19621 -- Is_Local_Type --
19622 -------------------
19624 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
19626 return Scope_Within
(Inner
=> Typ
, Outer
=> Scope
(Current_Scope
));
19629 -- Start of processing for Is_Visible_Component
19632 if Ekind
(C
) in E_Component | E_Discriminant
then
19633 Original_Comp
:= Original_Record_Component
(C
);
19636 if No
(Original_Comp
) then
19638 -- Premature usage, or previous error
19643 Original_Type
:= Scope
(Original_Comp
);
19644 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
19647 -- This test only concerns tagged types
19649 if not Is_Tagged_Type
(Original_Type
) then
19651 -- Check if this is a renamed discriminant (hidden either by the
19652 -- derived type or by some ancestor), unless we are analyzing code
19653 -- generated by the expander since it may reference such components
19654 -- (for example see the expansion of Deep_Adjust).
19656 if Ekind
(C
) = E_Discriminant
and then Present
(N
) then
19658 not Comes_From_Source
(N
)
19659 or else not Is_Completely_Hidden
(C
);
19664 -- If it is _Parent or _Tag, there is no visibility issue
19666 elsif not Comes_From_Source
(Original_Comp
) then
19669 -- Discriminants are visible unless the (private) type has unknown
19670 -- discriminants. If the discriminant reference is inserted for a
19671 -- discriminant check on a full view it is also visible.
19673 elsif Ekind
(Original_Comp
) = E_Discriminant
19675 (not Has_Unknown_Discriminants
(Original_Type
)
19676 or else (Present
(N
)
19677 and then Nkind
(N
) = N_Selected_Component
19678 and then Nkind
(Prefix
(N
)) = N_Type_Conversion
19679 and then not Comes_From_Source
(Prefix
(N
))))
19683 -- If the component has been declared in an ancestor which is currently
19684 -- a private type, then it is not visible. The same applies if the
19685 -- component's containing type is not in an open scope and the original
19686 -- component's enclosing type is a visible full view of a private type
19687 -- (which can occur in cases where an attempt is being made to reference
19688 -- a component in a sibling package that is inherited from a visible
19689 -- component of a type in an ancestor package; the component in the
19690 -- sibling package should not be visible even though the component it
19691 -- inherited from is visible), but instance bodies are not subject to
19692 -- this second case since they have the Has_Private_View mechanism to
19693 -- ensure proper visibility. This does not apply however in the case
19694 -- where the scope of the type is a private child unit, or when the
19695 -- parent comes from a local package in which the ancestor is currently
19696 -- visible. The latter suppression of visibility is needed for cases
19697 -- that are tested in B730006.
19699 elsif Is_Private_Type
(Original_Type
)
19701 (not Is_Private_Descendant
(Type_Scope
)
19702 and then not In_Open_Scopes
(Type_Scope
)
19703 and then Has_Private_Declaration
(Original_Type
)
19704 and then not In_Instance_Body
)
19706 -- If the type derives from an entity in a formal package, there
19707 -- are no additional visible components.
19709 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
19710 N_Formal_Package_Declaration
19714 -- if we are not in the private part of the current package, there
19715 -- are no additional visible components.
19717 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
19718 and then not In_Private_Part
(Scope
(Current_Scope
))
19723 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
19724 and then In_Open_Scopes
(Scope
(Original_Type
))
19725 and then Is_Local_Type
(Type_Scope
);
19728 -- There is another weird way in which a component may be invisible when
19729 -- the private and the full view are not derived from the same ancestor.
19730 -- Here is an example :
19732 -- type A1 is tagged record F1 : integer; end record;
19733 -- type A2 is new A1 with record F2 : integer; end record;
19734 -- type T is new A1 with private;
19736 -- type T is new A2 with null record;
19738 -- In this case, the full view of T inherits F1 and F2 but the private
19739 -- view inherits only F1
19743 Ancestor
: Entity_Id
:= Scope
(C
);
19747 if Ancestor
= Original_Type
then
19750 -- The ancestor may have a partial view of the original type,
19751 -- but if the full view is in scope, as in a child body, the
19752 -- component is visible.
19754 elsif In_Private_Part
(Scope
(Original_Type
))
19755 and then Full_View
(Ancestor
) = Original_Type
19759 elsif Ancestor
= Etype
(Ancestor
) then
19761 -- No further ancestors to examine
19766 Ancestor
:= Etype
(Ancestor
);
19770 end Is_Visible_Component
;
19772 --------------------------
19773 -- Make_Class_Wide_Type --
19774 --------------------------
19776 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
19777 CW_Type
: Entity_Id
;
19779 Next_E
: Entity_Id
;
19780 Prev_E
: Entity_Id
;
19783 if Present
(Class_Wide_Type
(T
)) then
19785 -- The class-wide type is a partially decorated entity created for a
19786 -- unanalyzed tagged type referenced through a limited with clause.
19787 -- When the tagged type is analyzed, its class-wide type needs to be
19788 -- redecorated. Note that we reuse the entity created by Decorate_
19789 -- Tagged_Type in order to preserve all links.
19791 if Materialize_Entity
(Class_Wide_Type
(T
)) then
19792 CW_Type
:= Class_Wide_Type
(T
);
19793 Set_Materialize_Entity
(CW_Type
, False);
19795 -- The class wide type can have been defined by the partial view, in
19796 -- which case everything is already done.
19802 -- Default case, we need to create a new class-wide type
19806 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
19809 -- Inherit root type characteristics
19811 CW_Name
:= Chars
(CW_Type
);
19812 Next_E
:= Next_Entity
(CW_Type
);
19813 Prev_E
:= Prev_Entity
(CW_Type
);
19814 Copy_Node
(T
, CW_Type
);
19815 Set_Comes_From_Source
(CW_Type
, False);
19816 Set_Chars
(CW_Type
, CW_Name
);
19817 Set_Parent
(CW_Type
, Parent
(T
));
19818 Set_Prev_Entity
(CW_Type
, Prev_E
);
19819 Set_Next_Entity
(CW_Type
, Next_E
);
19821 -- Ensure we have a new freeze node for the class-wide type. The partial
19822 -- view may have freeze action of its own, requiring a proper freeze
19823 -- node, and the same freeze node cannot be shared between the two
19826 Set_Has_Delayed_Freeze
(CW_Type
);
19827 Set_Freeze_Node
(CW_Type
, Empty
);
19829 -- Customize the class-wide type: It has no prim. op., it cannot be
19830 -- abstract, its Etype points back to the specific root type, and it
19831 -- cannot have any invariants.
19833 if Ekind
(CW_Type
) in Incomplete_Or_Private_Kind
then
19834 Reinit_Field_To_Zero
(CW_Type
, F_Private_Dependents
);
19836 elsif Ekind
(CW_Type
) in Concurrent_Kind
then
19837 Reinit_Field_To_Zero
(CW_Type
, F_First_Private_Entity
);
19838 Reinit_Field_To_Zero
(CW_Type
, F_Scope_Depth_Value
);
19840 if Ekind
(CW_Type
) in Task_Kind
then
19841 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Checks_OK_Id
);
19842 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Warnings_OK_Id
);
19845 if Ekind
(CW_Type
) in E_Task_Type | E_Protected_Type
then
19846 Reinit_Field_To_Zero
(CW_Type
, F_SPARK_Aux_Pragma_Inherited
);
19849 elsif Ekind
(CW_Type
) = E_Record_Type
then
19850 Reinit_Field_To_Zero
(CW_Type
, F_Corresponding_Concurrent_Type
);
19853 Mutate_Ekind
(CW_Type
, E_Class_Wide_Type
);
19854 Set_Is_Tagged_Type
(CW_Type
, True);
19855 Set_Direct_Primitive_Operations
(CW_Type
, New_Elmt_List
);
19856 Set_Is_Abstract_Type
(CW_Type
, False);
19857 Set_Is_Constrained
(CW_Type
, False);
19858 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
19859 Set_Default_SSO
(CW_Type
);
19860 Set_Has_Inheritable_Invariants
(CW_Type
, False);
19861 Set_Has_Inherited_Invariants
(CW_Type
, False);
19862 Set_Has_Own_Invariants
(CW_Type
, False);
19864 if Ekind
(T
) = E_Class_Wide_Subtype
then
19865 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
19867 Set_Etype
(CW_Type
, T
);
19870 Set_No_Tagged_Streams_Pragma
(CW_Type
, No_Tagged_Streams
);
19872 -- If this is the class_wide type of a constrained subtype, it does
19873 -- not have discriminants.
19875 Set_Has_Discriminants
(CW_Type
,
19876 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
19878 Set_Has_Unknown_Discriminants
(CW_Type
, True);
19879 Set_Class_Wide_Type
(T
, CW_Type
);
19880 Set_Equivalent_Type
(CW_Type
, Empty
);
19882 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
19884 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
19885 end Make_Class_Wide_Type
;
19891 procedure Make_Index
19893 Related_Nod
: Node_Id
;
19894 Related_Id
: Entity_Id
:= Empty
;
19895 Suffix_Index
: Pos
:= 1)
19899 Def_Id
: Entity_Id
:= Empty
;
19900 Found
: Boolean := False;
19903 -- For a discrete range used in a constrained array definition and
19904 -- defined by a range, an implicit conversion to the predefined type
19905 -- INTEGER is assumed if each bound is either a numeric literal, a named
19906 -- number, or an attribute, and the type of both bounds (prior to the
19907 -- implicit conversion) is the type universal_integer. Otherwise, both
19908 -- bounds must be of the same discrete type, other than universal
19909 -- integer; this type must be determinable independently of the
19910 -- context, but using the fact that the type must be discrete and that
19911 -- both bounds must have the same type.
19913 -- Character literals also have a universal type in the absence of
19914 -- of additional context, and are resolved to Standard_Character.
19916 if Nkind
(N
) = N_Range
then
19918 -- The index is given by a range constraint. The bounds are known
19919 -- to be of a consistent type.
19921 if not Is_Overloaded
(N
) then
19924 -- For universal bounds, choose the specific predefined type
19926 if T
= Universal_Integer
then
19927 T
:= Standard_Integer
;
19929 elsif T
= Any_Character
then
19930 Ambiguous_Character
(Low_Bound
(N
));
19932 T
:= Standard_Character
;
19935 -- The node may be overloaded because some user-defined operators
19936 -- are available, but if a universal interpretation exists it is
19937 -- also the selected one.
19939 elsif Universal_Interpretation
(N
) = Universal_Integer
then
19940 T
:= Standard_Integer
;
19946 Ind
: Interp_Index
;
19950 Get_First_Interp
(N
, Ind
, It
);
19951 while Present
(It
.Typ
) loop
19952 if Is_Discrete_Type
(It
.Typ
) then
19955 and then not Covers
(It
.Typ
, T
)
19956 and then not Covers
(T
, It
.Typ
)
19958 Error_Msg_N
("ambiguous bounds in discrete range", N
);
19966 Get_Next_Interp
(Ind
, It
);
19969 if T
= Any_Type
then
19970 Error_Msg_N
("discrete type required for range", N
);
19971 Set_Etype
(N
, Any_Type
);
19974 elsif T
= Universal_Integer
then
19975 T
:= Standard_Integer
;
19980 if not Is_Discrete_Type
(T
) then
19981 Error_Msg_N
("discrete type required for range", N
);
19982 Set_Etype
(N
, Any_Type
);
19986 -- If the range bounds are "T'First .. T'Last" where T is a name of a
19987 -- discrete type, then use T as the type of the index.
19989 if Nkind
(Low_Bound
(N
)) = N_Attribute_Reference
19990 and then Attribute_Name
(Low_Bound
(N
)) = Name_First
19991 and then Is_Entity_Name
(Prefix
(Low_Bound
(N
)))
19992 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(N
))))
19994 and then Nkind
(High_Bound
(N
)) = N_Attribute_Reference
19995 and then Attribute_Name
(High_Bound
(N
)) = Name_Last
19996 and then Is_Entity_Name
(Prefix
(High_Bound
(N
)))
19997 and then Entity
(Prefix
(High_Bound
(N
))) = Def_Id
19999 Def_Id
:= Entity
(Prefix
(Low_Bound
(N
)));
20003 Process_Range_Expr_In_Decl
(R
, T
);
20005 elsif Nkind
(N
) = N_Subtype_Indication
then
20007 -- The index is given by a subtype with a range constraint
20009 T
:= Base_Type
(Entity
(Subtype_Mark
(N
)));
20011 if not Is_Discrete_Type
(T
) then
20012 Error_Msg_N
("discrete type required for range", N
);
20013 Set_Etype
(N
, Any_Type
);
20017 R
:= Range_Expression
(Constraint
(N
));
20020 Process_Range_Expr_In_Decl
(R
, Entity
(Subtype_Mark
(N
)));
20022 elsif Nkind
(N
) = N_Attribute_Reference
then
20024 -- Catch beginner's error (use of attribute other than 'Range)
20026 if Attribute_Name
(N
) /= Name_Range
then
20027 Error_Msg_N
("expect attribute ''Range", N
);
20028 Set_Etype
(N
, Any_Type
);
20032 -- If the node denotes the range of a type mark, that is also the
20033 -- resulting type, and we do not need to create an Itype for it.
20035 if Is_Entity_Name
(Prefix
(N
))
20036 and then Comes_From_Source
(N
)
20037 and then Is_Discrete_Type
(Entity
(Prefix
(N
)))
20039 Def_Id
:= Entity
(Prefix
(N
));
20042 Analyze_And_Resolve
(N
);
20046 -- If none of the above, must be a subtype. We convert this to a
20047 -- range attribute reference because in the case of declared first
20048 -- named subtypes, the types in the range reference can be different
20049 -- from the type of the entity. A range attribute normalizes the
20050 -- reference and obtains the correct types for the bounds.
20052 -- This transformation is in the nature of an expansion, is only
20053 -- done if expansion is active. In particular, it is not done on
20054 -- formal generic types, because we need to retain the name of the
20055 -- original index for instantiation purposes.
20058 if not Is_Entity_Name
(N
) or else not Is_Type
(Entity
(N
)) then
20059 Error_Msg_N
("invalid subtype mark in discrete range", N
);
20060 Set_Etype
(N
, Any_Integer
);
20064 -- The type mark may be that of an incomplete type. It is only
20065 -- now that we can get the full view, previous analysis does
20066 -- not look specifically for a type mark.
20068 Set_Entity
(N
, Get_Full_View
(Entity
(N
)));
20069 Set_Etype
(N
, Entity
(N
));
20070 Def_Id
:= Entity
(N
);
20072 if not Is_Discrete_Type
(Def_Id
) then
20073 Error_Msg_N
("discrete type required for index", N
);
20074 Set_Etype
(N
, Any_Type
);
20079 if Expander_Active
then
20081 Make_Attribute_Reference
(Sloc
(N
),
20082 Attribute_Name
=> Name_Range
,
20083 Prefix
=> Relocate_Node
(N
)));
20085 -- The original was a subtype mark that does not freeze. This
20086 -- means that the rewritten version must not freeze either.
20088 Set_Must_Not_Freeze
(N
);
20089 Set_Must_Not_Freeze
(Prefix
(N
));
20090 Analyze_And_Resolve
(N
);
20094 -- If expander is inactive, type is legal, nothing else to construct
20101 if not Is_Discrete_Type
(T
) then
20102 Error_Msg_N
("discrete type required for range", N
);
20103 Set_Etype
(N
, Any_Type
);
20106 elsif T
= Any_Type
then
20107 Set_Etype
(N
, Any_Type
);
20111 -- We will now create the appropriate Itype to describe the range, but
20112 -- first a check. If we originally had a subtype, then we just label
20113 -- the range with this subtype. Not only is there no need to construct
20114 -- a new subtype, but it is wrong to do so for two reasons:
20116 -- 1. A legality concern, if we have a subtype, it must not freeze,
20117 -- and the Itype would cause freezing incorrectly
20119 -- 2. An efficiency concern, if we created an Itype, it would not be
20120 -- recognized as the same type for the purposes of eliminating
20121 -- checks in some circumstances.
20123 -- We signal this case by setting the subtype entity in Def_Id
20125 if No
(Def_Id
) then
20127 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
20128 Set_Etype
(Def_Id
, Base_Type
(T
));
20130 if Is_Signed_Integer_Type
(T
) then
20131 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
20133 elsif Is_Modular_Integer_Type
(T
) then
20134 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
20137 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
20138 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
20139 Set_First_Literal
(Def_Id
, First_Literal
(T
));
20142 Set_Size_Info
(Def_Id
, (T
));
20143 Set_RM_Size
(Def_Id
, RM_Size
(T
));
20144 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
20146 Set_Scalar_Range
(Def_Id
, R
);
20147 Conditional_Delay
(Def_Id
, T
);
20149 -- In the subtype indication case inherit properties of the parent
20151 if Nkind
(N
) = N_Subtype_Indication
then
20153 -- It is enough to inherit predicate flags and not the predicate
20154 -- functions, because predicates on an index type are illegal
20155 -- anyway and the flags are enough to detect them.
20157 Inherit_Predicate_Flags
(Def_Id
, Entity
(Subtype_Mark
(N
)));
20159 -- If the immediate parent of the new subtype is nonstatic, then
20160 -- the subtype we create is nonstatic as well, even if its bounds
20163 if not Is_OK_Static_Subtype
(Entity
(Subtype_Mark
(N
))) then
20164 Set_Is_Non_Static_Subtype
(Def_Id
);
20168 Set_Parent
(Def_Id
, N
);
20171 -- Final step is to label the index with this constructed type
20173 Set_Etype
(N
, Def_Id
);
20176 ------------------------------
20177 -- Modular_Type_Declaration --
20178 ------------------------------
20180 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
20181 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
20184 procedure Set_Modular_Size
(Bits
: Int
);
20185 -- Sets RM_Size to Bits, and Esize to normal word size above this
20187 ----------------------
20188 -- Set_Modular_Size --
20189 ----------------------
20191 procedure Set_Modular_Size
(Bits
: Int
) is
20195 Set_RM_Size
(T
, UI_From_Int
(Bits
));
20197 if Bits
< System_Max_Binary_Modulus_Power
then
20200 while Siz
< 128 loop
20201 exit when Bits
<= Siz
;
20205 Set_Esize
(T
, UI_From_Int
(Siz
));
20208 Set_Esize
(T
, UI_From_Int
(System_Max_Binary_Modulus_Power
));
20211 if not Non_Binary_Modulus
(T
) and then Esize
(T
) = RM_Size
(T
) then
20212 Set_Is_Known_Valid
(T
);
20214 end Set_Modular_Size
;
20216 -- Start of processing for Modular_Type_Declaration
20219 -- If the mod expression is (exactly) 2 * literal, where literal is
20220 -- 128 or less, then almost certainly the * was meant to be **. Warn.
20222 if Warn_On_Suspicious_Modulus_Value
20223 and then Nkind
(Mod_Expr
) = N_Op_Multiply
20224 and then Nkind
(Left_Opnd
(Mod_Expr
)) = N_Integer_Literal
20225 and then Intval
(Left_Opnd
(Mod_Expr
)) = Uint_2
20226 and then Nkind
(Right_Opnd
(Mod_Expr
)) = N_Integer_Literal
20227 and then Intval
(Right_Opnd
(Mod_Expr
)) <= Uint_128
20230 ("suspicious MOD value, was '*'* intended'??.m?", Mod_Expr
);
20233 -- Proceed with analysis of mod expression
20235 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
20238 Mutate_Ekind
(T
, E_Modular_Integer_Type
);
20239 Reinit_Alignment
(T
);
20240 Set_Is_Constrained
(T
);
20242 if not Is_OK_Static_Expression
(Mod_Expr
) then
20243 Flag_Non_Static_Expr
20244 ("non-static expression used for modular type bound!", Mod_Expr
);
20245 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
20247 M_Val
:= Expr_Value
(Mod_Expr
);
20251 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
20252 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
20255 if M_Val
> 2 ** Standard_Long_Integer_Size
then
20256 Check_Restriction
(No_Long_Long_Integers
, Mod_Expr
);
20259 Set_Modulus
(T
, M_Val
);
20261 -- Create bounds for the modular type based on the modulus given in
20262 -- the type declaration and then analyze and resolve those bounds.
20264 Set_Scalar_Range
(T
,
20265 Make_Range
(Sloc
(Mod_Expr
),
20266 Low_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
20267 High_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
20269 -- Properly analyze the literals for the range. We do this manually
20270 -- because we can't go calling Resolve, since we are resolving these
20271 -- bounds with the type, and this type is certainly not complete yet.
20273 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
20274 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
20275 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
20276 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
20278 -- Loop through powers of two to find number of bits required
20280 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
20284 if M_Val
= 2 ** Bits
then
20285 Set_Modular_Size
(Bits
);
20290 elsif M_Val
< 2 ** Bits
then
20291 Set_Non_Binary_Modulus
(T
);
20293 if Bits
> System_Max_Nonbinary_Modulus_Power
then
20294 Error_Msg_Uint_1
:=
20295 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
20297 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
20298 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20302 -- In the nonbinary case, set size as per RM 13.3(55)
20304 Set_Modular_Size
(Bits
);
20311 -- If we fall through, then the size exceed System.Max_Binary_Modulus
20312 -- so we just signal an error and set the maximum size.
20314 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
20315 Error_Msg_F
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
20317 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20318 Reinit_Alignment
(T
);
20320 end Modular_Type_Declaration
;
20322 --------------------------
20323 -- New_Concatenation_Op --
20324 --------------------------
20326 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
20327 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
20330 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
20331 -- Create abbreviated declaration for the formal of a predefined
20332 -- Operator 'Op' of type 'Typ'
20334 --------------------
20335 -- Make_Op_Formal --
20336 --------------------
20338 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
20339 Formal
: Entity_Id
;
20341 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
20342 Set_Etype
(Formal
, Typ
);
20343 Set_Mechanism
(Formal
, Default_Mechanism
);
20345 end Make_Op_Formal
;
20347 -- Start of processing for New_Concatenation_Op
20350 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
20352 Mutate_Ekind
(Op
, E_Operator
);
20353 Set_Is_Not_Self_Hidden
(Op
);
20354 Set_Scope
(Op
, Current_Scope
);
20355 Set_Etype
(Op
, Typ
);
20356 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
20357 Set_Is_Immediately_Visible
(Op
);
20358 Set_Is_Intrinsic_Subprogram
(Op
);
20359 Set_Has_Completion
(Op
);
20360 Append_Entity
(Op
, Current_Scope
);
20362 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
20364 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20365 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20366 end New_Concatenation_Op
;
20368 -------------------------
20369 -- OK_For_Limited_Init --
20370 -------------------------
20372 -- ???Check all calls of this, and compare the conditions under which it's
20375 function OK_For_Limited_Init
20377 Exp
: Node_Id
) return Boolean
20380 return Is_CPP_Constructor_Call
(Exp
)
20381 or else (Ada_Version
>= Ada_2005
20382 and then not Debug_Flag_Dot_L
20383 and then OK_For_Limited_Init_In_05
(Typ
, Exp
));
20384 end OK_For_Limited_Init
;
20386 -------------------------------
20387 -- OK_For_Limited_Init_In_05 --
20388 -------------------------------
20390 function OK_For_Limited_Init_In_05
20392 Exp
: Node_Id
) return Boolean
20395 -- An object of a limited interface type can be initialized with any
20396 -- expression of a nonlimited descendant type. However this does not
20397 -- apply if this is a view conversion of some other expression. This
20398 -- is checked below.
20400 if Is_Class_Wide_Type
(Typ
)
20401 and then Is_Limited_Interface
(Typ
)
20402 and then not Is_Limited_Type
(Etype
(Exp
))
20403 and then Nkind
(Exp
) /= N_Type_Conversion
20408 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
20409 -- case of limited aggregates (including extension aggregates), and
20410 -- function calls. The function call may have been given in prefixed
20411 -- notation, in which case the original node is an indexed component.
20412 -- If the function is parameterless, the original node was an explicit
20413 -- dereference. The function may also be parameterless, in which case
20414 -- the source node is just an identifier.
20416 -- A branch of a conditional expression may have been removed if the
20417 -- condition is statically known. This happens during expansion, and
20418 -- thus will not happen if previous errors were encountered. The check
20419 -- will have been performed on the chosen branch, which replaces the
20420 -- original conditional expression.
20426 case Nkind
(Original_Node
(Exp
)) is
20428 | N_Delta_Aggregate
20429 | N_Extension_Aggregate
20435 when N_Identifier
=>
20436 return Present
(Entity
(Original_Node
(Exp
)))
20437 and then Ekind
(Entity
(Original_Node
(Exp
))) = E_Function
;
20439 when N_Qualified_Expression
=>
20441 OK_For_Limited_Init_In_05
20442 (Typ
, Expression
(Original_Node
(Exp
)));
20444 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
20445 -- with a function call, the expander has rewritten the call into an
20446 -- N_Type_Conversion node to force displacement of the pointer to
20447 -- reference the component containing the secondary dispatch table.
20448 -- Otherwise a type conversion is not a legal context.
20449 -- A return statement for a build-in-place function returning a
20450 -- synchronized type also introduces an unchecked conversion.
20452 when N_Type_Conversion
20453 | N_Unchecked_Type_Conversion
20455 return not Comes_From_Source
(Exp
)
20457 -- If the conversion has been rewritten, check Original_Node;
20458 -- otherwise, check the expression of the compiler-generated
20459 -- conversion (which is a conversion that we want to ignore
20460 -- for purposes of the limited-initialization restrictions).
20462 (if Is_Rewrite_Substitution
(Exp
)
20463 then OK_For_Limited_Init_In_05
(Typ
, Original_Node
(Exp
))
20464 else OK_For_Limited_Init_In_05
(Typ
, Expression
(Exp
)));
20466 when N_Explicit_Dereference
20467 | N_Indexed_Component
20468 | N_Selected_Component
20470 return Nkind
(Exp
) = N_Function_Call
;
20472 -- A use of 'Input is a function call, hence allowed. Normally the
20473 -- attribute will be changed to a call, but the attribute by itself
20474 -- can occur with -gnatc.
20476 when N_Attribute_Reference
=>
20477 return Attribute_Name
(Original_Node
(Exp
)) = Name_Input
;
20479 -- "return raise ..." is OK
20481 when N_Raise_Expression
=>
20484 -- For a case expression, all dependent expressions must be legal
20486 when N_Case_Expression
=>
20491 Alt
:= First
(Alternatives
(Original_Node
(Exp
)));
20492 while Present
(Alt
) loop
20493 if not OK_For_Limited_Init_In_05
(Typ
, Expression
(Alt
)) then
20503 -- For an if expression, all dependent expressions must be legal
20505 when N_If_Expression
=>
20507 Then_Expr
: constant Node_Id
:=
20508 Next
(First
(Expressions
(Original_Node
(Exp
))));
20509 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
20511 return OK_For_Limited_Init_In_05
(Typ
, Then_Expr
)
20513 OK_For_Limited_Init_In_05
(Typ
, Else_Expr
);
20519 end OK_For_Limited_Init_In_05
;
20521 -------------------------------------------
20522 -- Ordinary_Fixed_Point_Type_Declaration --
20523 -------------------------------------------
20525 procedure Ordinary_Fixed_Point_Type_Declaration
20529 Loc
: constant Source_Ptr
:= Sloc
(Def
);
20530 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
20531 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
20532 Implicit_Base
: Entity_Id
;
20539 Check_Restriction
(No_Fixed_Point
, Def
);
20541 -- Create implicit base type
20544 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
20545 Set_Etype
(Implicit_Base
, Implicit_Base
);
20547 -- Analyze and process delta expression
20549 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
20551 Check_Delta_Expression
(Delta_Expr
);
20552 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
20554 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
20556 -- Compute default small from given delta, which is the largest power
20557 -- of two that does not exceed the given delta value.
20567 if Delta_Val
< Ureal_1
then
20568 while Delta_Val
< Tmp
loop
20569 Tmp
:= Tmp
/ Ureal_2
;
20570 Scale
:= Scale
+ 1;
20575 Tmp
:= Tmp
* Ureal_2
;
20576 exit when Tmp
> Delta_Val
;
20577 Scale
:= Scale
- 1;
20581 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
20584 Set_Small_Value
(Implicit_Base
, Small_Val
);
20586 -- If no range was given, set a dummy range
20588 if RRS
<= Empty_Or_Error
then
20589 Low_Val
:= -Small_Val
;
20590 High_Val
:= Small_Val
;
20592 -- Otherwise analyze and process given range
20596 Low
: constant Node_Id
:= Low_Bound
(RRS
);
20597 High
: constant Node_Id
:= High_Bound
(RRS
);
20600 Analyze_And_Resolve
(Low
, Any_Real
);
20601 Analyze_And_Resolve
(High
, Any_Real
);
20602 Check_Real_Bound
(Low
);
20603 Check_Real_Bound
(High
);
20605 -- Obtain and set the range
20607 Low_Val
:= Expr_Value_R
(Low
);
20608 High_Val
:= Expr_Value_R
(High
);
20610 if Low_Val
> High_Val
then
20611 Error_Msg_NE
("??fixed point type& has null range", Def
, T
);
20616 -- The range for both the implicit base and the declared first subtype
20617 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
20618 -- set a temporary range in place. Note that the bounds of the base
20619 -- type will be widened to be symmetrical and to fill the available
20620 -- bits when the type is frozen.
20622 -- We could do this with all discrete types, and probably should, but
20623 -- we absolutely have to do it for fixed-point, since the end-points
20624 -- of the range and the size are determined by the small value, which
20625 -- could be reset before the freeze point.
20627 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
20628 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
20630 -- Complete definition of first subtype. The inheritance of the rep item
20631 -- chain ensures that SPARK-related pragmas are not clobbered when the
20632 -- ordinary fixed point type acts as a full view of a private type.
20634 Mutate_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
20635 Set_Etype
(T
, Implicit_Base
);
20636 Reinit_Size_Align
(T
);
20637 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
20638 Set_Small_Value
(T
, Small_Val
);
20639 Set_Delta_Value
(T
, Delta_Val
);
20640 Set_Is_Constrained
(T
);
20641 end Ordinary_Fixed_Point_Type_Declaration
;
20643 ----------------------------------
20644 -- Preanalyze_Assert_Expression --
20645 ----------------------------------
20647 procedure Preanalyze_Assert_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20649 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20650 Preanalyze_Spec_Expression
(N
, T
);
20651 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20652 end Preanalyze_Assert_Expression
;
20654 -- ??? The variant below explicitly saves and restores all the flags,
20655 -- because it is impossible to compose the existing variety of
20656 -- Analyze/Resolve (and their wrappers, e.g. Preanalyze_Spec_Expression)
20657 -- to achieve the desired semantics.
20659 procedure Preanalyze_Assert_Expression
(N
: Node_Id
) is
20660 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20661 Save_Must_Not_Freeze
: constant Boolean := Must_Not_Freeze
(N
);
20662 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
20665 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20666 In_Spec_Expression
:= True;
20667 Set_Must_Not_Freeze
(N
);
20668 Inside_Preanalysis_Without_Freezing
:=
20669 Inside_Preanalysis_Without_Freezing
+ 1;
20670 Full_Analysis
:= False;
20671 Expander_Mode_Save_And_Set
(False);
20673 if GNATprove_Mode
then
20674 Analyze_And_Resolve
(N
);
20676 Analyze_And_Resolve
(N
, Suppress
=> All_Checks
);
20679 Expander_Mode_Restore
;
20680 Full_Analysis
:= Save_Full_Analysis
;
20681 Inside_Preanalysis_Without_Freezing
:=
20682 Inside_Preanalysis_Without_Freezing
- 1;
20683 Set_Must_Not_Freeze
(N
, Save_Must_Not_Freeze
);
20684 In_Spec_Expression
:= Save_In_Spec_Expression
;
20685 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20686 end Preanalyze_Assert_Expression
;
20688 -----------------------------------
20689 -- Preanalyze_Default_Expression --
20690 -----------------------------------
20692 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20693 Save_In_Default_Expr
: constant Boolean := In_Default_Expr
;
20694 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20697 In_Default_Expr
:= True;
20698 In_Spec_Expression
:= True;
20700 Preanalyze_With_Freezing_And_Resolve
(N
, T
);
20702 In_Default_Expr
:= Save_In_Default_Expr
;
20703 In_Spec_Expression
:= Save_In_Spec_Expression
;
20704 end Preanalyze_Default_Expression
;
20706 --------------------------------
20707 -- Preanalyze_Spec_Expression --
20708 --------------------------------
20710 procedure Preanalyze_Spec_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20711 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20713 In_Spec_Expression
:= True;
20714 Preanalyze_And_Resolve
(N
, T
);
20715 In_Spec_Expression
:= Save_In_Spec_Expression
;
20716 end Preanalyze_Spec_Expression
;
20718 ----------------------------------------
20719 -- Prepare_Private_Subtype_Completion --
20720 ----------------------------------------
20722 procedure Prepare_Private_Subtype_Completion
20724 Related_Nod
: Node_Id
)
20726 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
20727 Full_B
: constant Entity_Id
:= Full_View
(Id_B
);
20731 if Present
(Full_B
) then
20733 -- The Base_Type is already completed, we can complete the subtype
20734 -- now. We have to create a new entity with the same name, Thus we
20735 -- can't use Create_Itype.
20737 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
20738 Set_Is_Itype
(Full
);
20739 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
20740 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
20741 Set_Full_View
(Id
, Full
);
20744 -- The parent subtype may be private, but the base might not, in some
20745 -- nested instances. In that case, the subtype does not need to be
20746 -- exchanged. It would still be nice to make private subtypes and their
20747 -- bases consistent at all times ???
20749 if Is_Private_Type
(Id_B
) then
20750 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
20752 end Prepare_Private_Subtype_Completion
;
20754 ---------------------------
20755 -- Process_Discriminants --
20756 ---------------------------
20758 procedure Process_Discriminants
20760 Prev
: Entity_Id
:= Empty
)
20762 Elist
: constant Elist_Id
:= New_Elmt_List
;
20765 Discr_Number
: Uint
;
20766 Discr_Type
: Entity_Id
;
20767 Default_Present
: Boolean := False;
20768 Default_Not_Present
: Boolean := False;
20771 -- A composite type other than an array type can have discriminants.
20772 -- On entry, the current scope is the composite type.
20774 -- The discriminants are initially entered into the scope of the type
20775 -- via Enter_Name with the default Ekind of E_Void to prevent premature
20776 -- use, as explained at the end of this procedure.
20778 Discr
:= First
(Discriminant_Specifications
(N
));
20779 while Present
(Discr
) loop
20780 Enter_Name
(Defining_Identifier
(Discr
));
20782 -- For navigation purposes we add a reference to the discriminant
20783 -- in the entity for the type. If the current declaration is a
20784 -- completion, place references on the partial view. Otherwise the
20785 -- type is the current scope.
20787 if Present
(Prev
) then
20789 -- The references go on the partial view, if present. If the
20790 -- partial view has discriminants, the references have been
20791 -- generated already.
20793 if not Has_Discriminants
(Prev
) then
20794 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
20798 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
20801 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
20802 Check_Anonymous_Access_Component
20804 Typ
=> Defining_Identifier
(N
),
20807 Access_Def
=> Discriminant_Type
(Discr
));
20809 -- if Check_Anonymous_Access_Component replaced Discr then
20810 -- its Original_Node points to the old Discr and the access type
20811 -- for Discr_Type has already been created.
20813 if Is_Rewrite_Substitution
(Discr
) then
20814 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20817 Access_Definition
(Discr
, Discriminant_Type
(Discr
));
20819 -- Ada 2005 (AI-254)
20821 if Present
(Access_To_Subprogram_Definition
20822 (Discriminant_Type
(Discr
)))
20823 and then Protected_Present
(Access_To_Subprogram_Definition
20824 (Discriminant_Type
(Discr
)))
20827 Replace_Anonymous_Access_To_Protected_Subprogram
(Discr
);
20831 Find_Type
(Discriminant_Type
(Discr
));
20832 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20834 if Error_Posted
(Discriminant_Type
(Discr
)) then
20835 Discr_Type
:= Any_Type
;
20839 -- Handling of discriminants that are access types
20841 if Is_Access_Type
(Discr_Type
) then
20843 -- Ada 2005 (AI-230): Access discriminant allowed in non-
20844 -- limited record types
20846 if Ada_Version
< Ada_2005
then
20847 Check_Access_Discriminant_Requires_Limited
20848 (Discr
, Discriminant_Type
(Discr
));
20851 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
20853 ("(Ada 83) access discriminant not allowed", Discr
);
20856 -- If not access type, must be a discrete type
20858 elsif not Is_Discrete_Type
(Discr_Type
) then
20860 ("discriminants must have a discrete or access type",
20861 Discriminant_Type
(Discr
));
20864 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
20866 -- If a discriminant specification includes the assignment compound
20867 -- delimiter followed by an expression, the expression is the default
20868 -- expression of the discriminant; the default expression must be of
20869 -- the type of the discriminant. (RM 3.7.1) Since this expression is
20870 -- a default expression, we do the special preanalysis, since this
20871 -- expression does not freeze (see section "Handling of Default and
20872 -- Per-Object Expressions" in spec of package Sem).
20874 if Present
(Expression
(Discr
)) then
20875 Preanalyze_Default_Expression
(Expression
(Discr
), Discr_Type
);
20879 if Nkind
(N
) = N_Formal_Type_Declaration
then
20881 ("discriminant defaults not allowed for formal type",
20882 Expression
(Discr
));
20884 -- Flag an error for a tagged type with defaulted discriminants,
20885 -- excluding limited tagged types when compiling for Ada 2012
20886 -- (see AI05-0214).
20888 elsif Is_Tagged_Type
(Current_Scope
)
20889 and then (not Is_Limited_Type
(Current_Scope
)
20890 or else Ada_Version
< Ada_2012
)
20891 and then Comes_From_Source
(N
)
20893 -- Note: see similar test in Check_Or_Process_Discriminants, to
20894 -- handle the (illegal) case of the completion of an untagged
20895 -- view with discriminants with defaults by a tagged full view.
20896 -- We skip the check if Discr does not come from source, to
20897 -- account for the case of an untagged derived type providing
20898 -- defaults for a renamed discriminant from a private untagged
20899 -- ancestor with a tagged full view (ACATS B460006).
20901 if Ada_Version
>= Ada_2012
then
20903 ("discriminants of nonlimited tagged type cannot have"
20905 Expression
(Discr
));
20908 ("discriminants of tagged type cannot have defaults",
20909 Expression
(Discr
));
20913 Default_Present
:= True;
20914 Append_Elmt
(Expression
(Discr
), Elist
);
20916 -- Tag the defining identifiers for the discriminants with
20917 -- their corresponding default expressions from the tree.
20919 Set_Discriminant_Default_Value
20920 (Defining_Identifier
(Discr
), Expression
(Discr
));
20923 -- In gnatc or GNATprove mode, make sure set Do_Range_Check flag
20924 -- gets set unless we can be sure that no range check is required.
20926 if not Expander_Active
20929 (Expression
(Discr
), Discr_Type
, Assume_Valid
=> True)
20931 Set_Do_Range_Check
(Expression
(Discr
));
20934 -- No default discriminant value given
20937 Default_Not_Present
:= True;
20940 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
20941 -- Discr_Type but with the null-exclusion attribute
20943 if Ada_Version
>= Ada_2005
then
20945 -- Ada 2005 (AI-231): Static checks
20947 if Can_Never_Be_Null
(Discr_Type
) then
20948 Null_Exclusion_Static_Checks
(Discr
);
20950 elsif Is_Access_Type
(Discr_Type
)
20951 and then Null_Exclusion_Present
(Discr
)
20953 -- No need to check itypes because in their case this check
20954 -- was done at their point of creation
20956 and then not Is_Itype
(Discr_Type
)
20958 if Can_Never_Be_Null
(Discr_Type
) then
20960 ("`NOT NULL` not allowed (& already excludes null)",
20965 Set_Etype
(Defining_Identifier
(Discr
),
20966 Create_Null_Excluding_Itype
20968 Related_Nod
=> Discr
));
20970 -- Check for improper null exclusion if the type is otherwise
20971 -- legal for a discriminant.
20973 elsif Null_Exclusion_Present
(Discr
)
20974 and then Is_Discrete_Type
(Discr_Type
)
20977 ("null exclusion can only apply to an access type", Discr
);
20980 -- Ada 2005 (AI-402): access discriminants of nonlimited types
20981 -- can't have defaults. Synchronized types, or types that are
20982 -- explicitly limited are fine, but special tests apply to derived
20983 -- types in generics: in a generic body we have to assume the
20984 -- worst, and therefore defaults are not allowed if the parent is
20985 -- a generic formal private type (see ACATS B370001).
20987 if Is_Access_Type
(Discr_Type
) and then Default_Present
then
20988 if Ekind
(Discr_Type
) /= E_Anonymous_Access_Type
20989 or else Is_Limited_Record
(Current_Scope
)
20990 or else Is_Concurrent_Type
(Current_Scope
)
20991 or else Is_Concurrent_Record_Type
(Current_Scope
)
20992 or else Ekind
(Current_Scope
) = E_Limited_Private_Type
20994 if not Is_Derived_Type
(Current_Scope
)
20995 or else not Is_Generic_Type
(Etype
(Current_Scope
))
20996 or else not In_Package_Body
(Scope
(Etype
(Current_Scope
)))
20997 or else Limited_Present
20998 (Type_Definition
(Parent
(Current_Scope
)))
21004 ("access discriminants of nonlimited types cannot "
21005 & "have defaults", Expression
(Discr
));
21008 elsif Present
(Expression
(Discr
)) then
21010 ("(Ada 2005) access discriminants of nonlimited types "
21011 & "cannot have defaults", Expression
(Discr
));
21016 -- A discriminant cannot be effectively volatile (SPARK RM 7.1.3(4)).
21017 -- This check is relevant only when SPARK_Mode is on as it is not a
21018 -- standard Ada legality rule. The only way for a discriminant to be
21019 -- effectively volatile is to have an effectively volatile type, so
21020 -- we check this directly, because the Ekind of Discr might not be
21021 -- set yet (to help preventing cascaded errors on derived types).
21024 and then Is_Effectively_Volatile
(Discr_Type
)
21026 Error_Msg_N
("discriminant cannot be volatile", Discr
);
21032 -- An element list consisting of the default expressions of the
21033 -- discriminants is constructed in the above loop and used to set
21034 -- the Discriminant_Constraint attribute for the type. If an object
21035 -- is declared of this (record or task) type without any explicit
21036 -- discriminant constraint given, this element list will form the
21037 -- actual parameters for the corresponding initialization procedure
21040 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
21041 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
21043 -- Default expressions must be provided either for all or for none
21044 -- of the discriminants of a discriminant part. (RM 3.7.1)
21046 if Default_Present
and then Default_Not_Present
then
21048 ("incomplete specification of defaults for discriminants", N
);
21051 -- The use of the name of a discriminant is not allowed in default
21052 -- expressions of a discriminant part if the specification of the
21053 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
21055 -- To detect this, the discriminant names are entered initially with an
21056 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
21057 -- attempt to use a void entity (for example in an expression that is
21058 -- type-checked) produces the error message: premature usage. Now after
21059 -- completing the semantic analysis of the discriminant part, we can set
21060 -- the Ekind of all the discriminants appropriately.
21062 Discr
:= First
(Discriminant_Specifications
(N
));
21063 Discr_Number
:= Uint_1
;
21064 while Present
(Discr
) loop
21065 Id
:= Defining_Identifier
(Discr
);
21067 if Ekind
(Id
) = E_In_Parameter
then
21068 Reinit_Field_To_Zero
(Id
, F_Discriminal_Link
);
21071 Mutate_Ekind
(Id
, E_Discriminant
);
21072 Set_Is_Not_Self_Hidden
(Id
);
21073 Reinit_Component_Location
(Id
);
21075 Set_Discriminant_Number
(Id
, Discr_Number
);
21077 -- Make sure this is always set, even in illegal programs
21079 Set_Corresponding_Discriminant
(Id
, Empty
);
21081 -- Initialize the Original_Record_Component to the entity itself.
21082 -- Inherit_Components will propagate the right value to
21083 -- discriminants in derived record types.
21085 Set_Original_Record_Component
(Id
, Id
);
21087 -- Create the discriminal for the discriminant
21089 Build_Discriminal
(Id
);
21092 Discr_Number
:= Discr_Number
+ 1;
21095 Set_Has_Discriminants
(Current_Scope
);
21096 end Process_Discriminants
;
21098 -----------------------
21099 -- Process_Full_View --
21100 -----------------------
21102 -- WARNING: This routine manages Ghost regions. Return statements must be
21103 -- replaced by gotos which jump to the end of the routine and restore the
21106 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
21107 procedure Collect_Implemented_Interfaces
21109 Ifaces
: Elist_Id
);
21110 -- Ada 2005: Gather all the interfaces that Typ directly or
21111 -- inherently implements. Duplicate entries are not added to
21112 -- the list Ifaces.
21114 ------------------------------------
21115 -- Collect_Implemented_Interfaces --
21116 ------------------------------------
21118 procedure Collect_Implemented_Interfaces
21123 Iface_Elmt
: Elmt_Id
;
21126 -- Abstract interfaces are only associated with tagged record types
21128 if not Is_Tagged_Type
(Typ
) or else not Is_Record_Type
(Typ
) then
21132 -- Recursively climb to the ancestors
21134 if Etype
(Typ
) /= Typ
21136 -- Protect the frontend against wrong cyclic declarations like:
21138 -- type B is new A with private;
21139 -- type C is new A with private;
21141 -- type B is new C with null record;
21142 -- type C is new B with null record;
21144 and then Etype
(Typ
) /= Priv_T
21145 and then Etype
(Typ
) /= Full_T
21147 -- Keep separate the management of private type declarations
21149 if Ekind
(Typ
) = E_Record_Type_With_Private
then
21151 -- Handle the following illegal usage:
21152 -- type Private_Type is tagged private;
21154 -- type Private_Type is new Type_Implementing_Iface;
21156 if Present
(Full_View
(Typ
))
21157 and then Etype
(Typ
) /= Full_View
(Typ
)
21159 if Is_Interface
(Etype
(Typ
)) then
21160 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
21163 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
21166 -- Non-private types
21169 if Is_Interface
(Etype
(Typ
)) then
21170 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
21173 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
21177 -- Handle entities in the list of abstract interfaces
21179 if Present
(Interfaces
(Typ
)) then
21180 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
21181 while Present
(Iface_Elmt
) loop
21182 Iface
:= Node
(Iface_Elmt
);
21184 pragma Assert
(Is_Interface
(Iface
));
21186 if not Contain_Interface
(Iface
, Ifaces
) then
21187 Append_Elmt
(Iface
, Ifaces
);
21188 Collect_Implemented_Interfaces
(Iface
, Ifaces
);
21191 Next_Elmt
(Iface_Elmt
);
21194 end Collect_Implemented_Interfaces
;
21198 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
21199 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
21200 -- Save the Ghost-related attributes to restore on exit
21202 Full_Indic
: Node_Id
;
21203 Full_Parent
: Entity_Id
;
21204 Priv_Parent
: Entity_Id
;
21206 -- Start of processing for Process_Full_View
21209 Mark_And_Set_Ghost_Completion
(N
, Priv_T
);
21211 -- First some sanity checks that must be done after semantic
21212 -- decoration of the full view and thus cannot be placed with other
21213 -- similar checks in Find_Type_Name
21215 if not Is_Limited_Type
(Priv_T
)
21216 and then (Is_Limited_Type
(Full_T
)
21217 or else Is_Limited_Composite
(Full_T
))
21219 if In_Instance
then
21223 ("completion of nonlimited type cannot be limited", Full_T
);
21224 Explain_Limited_Type
(Full_T
, Full_T
);
21227 elsif Is_Abstract_Type
(Full_T
)
21228 and then not Is_Abstract_Type
(Priv_T
)
21231 ("completion of nonabstract type cannot be abstract", Full_T
);
21233 elsif Is_Tagged_Type
(Priv_T
)
21234 and then Is_Limited_Type
(Priv_T
)
21235 and then not Is_Limited_Type
(Full_T
)
21237 -- If pragma CPP_Class was applied to the private declaration
21238 -- propagate the limitedness to the full-view
21240 if Is_CPP_Class
(Priv_T
) then
21241 Set_Is_Limited_Record
(Full_T
);
21243 -- GNAT allow its own definition of Limited_Controlled to disobey
21244 -- this rule in order in ease the implementation. This test is safe
21245 -- because Root_Controlled is defined in a child of System that
21246 -- normal programs are not supposed to use.
21248 elsif Is_RTE
(Etype
(Full_T
), RE_Root_Controlled
) then
21249 Set_Is_Limited_Composite
(Full_T
);
21252 ("completion of limited tagged type must be limited", Full_T
);
21255 elsif Is_Generic_Type
(Priv_T
) then
21256 Error_Msg_N
("generic type cannot have a completion", Full_T
);
21259 -- Check that ancestor interfaces of private and full views are
21260 -- consistent. We omit this check for synchronized types because
21261 -- they are performed on the corresponding record type when frozen.
21263 if Ada_Version
>= Ada_2005
21264 and then Is_Tagged_Type
(Priv_T
)
21265 and then Is_Tagged_Type
(Full_T
)
21266 and then not Is_Concurrent_Type
(Full_T
)
21270 Priv_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
21271 Full_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
21274 Collect_Implemented_Interfaces
(Priv_T
, Priv_T_Ifaces
);
21275 Collect_Implemented_Interfaces
(Full_T
, Full_T_Ifaces
);
21277 -- Ada 2005 (AI-251): The partial view shall be a descendant of
21278 -- an interface type if and only if the full type is descendant
21279 -- of the interface type (AARM 7.3 (7.3/2)).
21281 Iface
:= Find_Hidden_Interface
(Priv_T_Ifaces
, Full_T_Ifaces
);
21283 if Present
(Iface
) then
21285 ("interface in partial view& not implemented by full type "
21286 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
21289 Iface
:= Find_Hidden_Interface
(Full_T_Ifaces
, Priv_T_Ifaces
);
21291 if Present
(Iface
) then
21293 ("interface & not implemented by partial view "
21294 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
21299 if Is_Tagged_Type
(Priv_T
)
21300 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21301 and then Is_Derived_Type
(Full_T
)
21303 Priv_Parent
:= Etype
(Priv_T
);
21305 -- The full view of a private extension may have been transformed
21306 -- into an unconstrained derived type declaration and a subtype
21307 -- declaration (see build_derived_record_type for details).
21309 if Nkind
(N
) = N_Subtype_Declaration
then
21310 Full_Indic
:= Subtype_Indication
(N
);
21311 Full_Parent
:= Etype
(Base_Type
(Full_T
));
21313 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
21314 Full_Parent
:= Etype
(Full_T
);
21317 -- Check that the parent type of the full type is a descendant of
21318 -- the ancestor subtype given in the private extension. If either
21319 -- entity has an Etype equal to Any_Type then we had some previous
21320 -- error situation [7.3(8)].
21322 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
21325 -- Ada 2005 (AI-251): Interfaces in the full type can be given in
21326 -- any order. Therefore we don't have to check that its parent must
21327 -- be a descendant of the parent of the private type declaration.
21329 elsif Is_Interface
(Priv_Parent
)
21330 and then Is_Interface
(Full_Parent
)
21334 -- Ada 2005 (AI-251): If the parent of the private type declaration
21335 -- is an interface there is no need to check that it is an ancestor
21336 -- of the associated full type declaration. The required tests for
21337 -- this case are performed by Build_Derived_Record_Type.
21339 elsif not Is_Interface
(Base_Type
(Priv_Parent
))
21340 and then not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
)
21343 ("parent of full type must descend from parent of private "
21344 & "extension", Full_Indic
);
21346 -- First check a formal restriction, and then proceed with checking
21347 -- Ada rules. Since the formal restriction is not a serious error, we
21348 -- don't prevent further error detection for this check, hence the
21352 -- Check the rules of 7.3(10): if the private extension inherits
21353 -- known discriminants, then the full type must also inherit those
21354 -- discriminants from the same (ancestor) type, and the parent
21355 -- subtype of the full type must be constrained if and only if
21356 -- the ancestor subtype of the private extension is constrained.
21358 if No
(Discriminant_Specifications
(Parent
(Priv_T
)))
21359 and then not Has_Unknown_Discriminants
(Priv_T
)
21360 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
21363 Priv_Indic
: constant Node_Id
:=
21364 Subtype_Indication
(Parent
(Priv_T
));
21366 Priv_Constr
: constant Boolean :=
21367 Is_Constrained
(Priv_Parent
)
21369 Nkind
(Priv_Indic
) = N_Subtype_Indication
21371 Is_Constrained
(Entity
(Priv_Indic
));
21373 Full_Constr
: constant Boolean :=
21374 Is_Constrained
(Full_Parent
)
21376 Nkind
(Full_Indic
) = N_Subtype_Indication
21378 Is_Constrained
(Entity
(Full_Indic
));
21380 Priv_Discr
: Entity_Id
;
21381 Full_Discr
: Entity_Id
;
21384 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
21385 Full_Discr
:= First_Discriminant
(Full_Parent
);
21386 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
21387 if Original_Record_Component
(Priv_Discr
) =
21388 Original_Record_Component
(Full_Discr
)
21390 Corresponding_Discriminant
(Priv_Discr
) =
21391 Corresponding_Discriminant
(Full_Discr
)
21398 Next_Discriminant
(Priv_Discr
);
21399 Next_Discriminant
(Full_Discr
);
21402 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
21404 ("full view must inherit discriminants of the parent "
21405 & "type used in the private extension", Full_Indic
);
21407 elsif Priv_Constr
and then not Full_Constr
then
21409 ("parent subtype of full type must be constrained",
21412 elsif Full_Constr
and then not Priv_Constr
then
21414 ("parent subtype of full type must be unconstrained",
21419 -- Check the rules of 7.3(12): if a partial view has neither
21420 -- known or unknown discriminants, then the full type
21421 -- declaration shall define a definite subtype.
21423 elsif not Has_Unknown_Discriminants
(Priv_T
)
21424 and then not Has_Discriminants
(Priv_T
)
21425 and then not Is_Constrained
(Full_T
)
21428 ("full view must define a constrained type if partial view "
21429 & "has no discriminants", Full_T
);
21432 -- Do we implement the following properly???
21433 -- If the ancestor subtype of a private extension has constrained
21434 -- discriminants, then the parent subtype of the full view shall
21435 -- impose a statically matching constraint on those discriminants
21440 -- For untagged types, verify that a type without discriminants is
21441 -- not completed with an unconstrained type. A separate error message
21442 -- is produced if the full type has defaulted discriminants.
21444 if Is_Definite_Subtype
(Priv_T
)
21445 and then not Is_Definite_Subtype
(Full_T
)
21447 Error_Msg_Sloc
:= Sloc
(Parent
(Priv_T
));
21449 ("full view of& not compatible with declaration#",
21452 if not Is_Tagged_Type
(Full_T
) then
21454 ("\one is constrained, the other unconstrained", Full_T
);
21459 -- AI-419: verify that the use of "limited" is consistent
21462 Orig_Decl
: constant Node_Id
:= Original_Node
(N
);
21465 if Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21466 and then Nkind
(Orig_Decl
) = N_Full_Type_Declaration
21468 (Type_Definition
(Orig_Decl
)) = N_Derived_Type_Definition
21470 if not Limited_Present
(Parent
(Priv_T
))
21471 and then not Synchronized_Present
(Parent
(Priv_T
))
21472 and then Limited_Present
(Type_Definition
(Orig_Decl
))
21475 ("full view of non-limited extension cannot be limited", N
);
21477 -- Conversely, if the partial view carries the limited keyword,
21478 -- the full view must as well, even if it may be redundant.
21480 elsif Limited_Present
(Parent
(Priv_T
))
21481 and then not Limited_Present
(Type_Definition
(Orig_Decl
))
21484 ("full view of limited extension must be explicitly limited",
21490 -- Ada 2005 (AI-443): A synchronized private extension must be
21491 -- completed by a task or protected type.
21493 if Ada_Version
>= Ada_2005
21494 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21495 and then Synchronized_Present
(Parent
(Priv_T
))
21496 and then not Is_Concurrent_Type
(Full_T
)
21498 Error_Msg_N
("full view of synchronized extension must " &
21499 "be synchronized type", N
);
21502 -- Ada 2005 AI-363: if the full view has discriminants with
21503 -- defaults, it is illegal to declare constrained access subtypes
21504 -- whose designated type is the current type. This allows objects
21505 -- of the type that are declared in the heap to be unconstrained.
21507 if not Has_Unknown_Discriminants
(Priv_T
)
21508 and then not Has_Discriminants
(Priv_T
)
21509 and then Has_Defaulted_Discriminants
(Full_T
)
21511 Set_Has_Constrained_Partial_View
(Base_Type
(Full_T
));
21512 Set_Has_Constrained_Partial_View
(Priv_T
);
21515 -- Create a full declaration for all its subtypes recorded in
21516 -- Private_Dependents and swap them similarly to the base type. These
21517 -- are subtypes that have been define before the full declaration of
21518 -- the private type. We also swap the entry in Private_Dependents list
21519 -- so we can properly restore the private view on exit from the scope.
21522 Priv_Elmt
: Elmt_Id
;
21523 Priv_Scop
: Entity_Id
;
21528 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
21529 while Present
(Priv_Elmt
) loop
21530 Priv
:= Node
(Priv_Elmt
);
21531 Priv_Scop
:= Scope
(Priv
);
21533 if Ekind
(Priv
) in E_Private_Subtype
21534 | E_Limited_Private_Subtype
21535 | E_Record_Subtype_With_Private
21537 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
21538 Set_Is_Itype
(Full
);
21539 Set_Parent
(Full
, Parent
(Priv
));
21540 Set_Associated_Node_For_Itype
(Full
, N
);
21542 -- Now we need to complete the private subtype, but since the
21543 -- base type has already been swapped, we must also swap the
21544 -- subtypes (and thus, reverse the arguments in the call to
21545 -- Complete_Private_Subtype). Also note that we may need to
21546 -- re-establish the scope of the private subtype.
21548 Copy_And_Swap
(Priv
, Full
);
21550 if not In_Open_Scopes
(Priv_Scop
) then
21551 Push_Scope
(Priv_Scop
);
21554 -- Reset Priv_Scop to Empty to indicate no scope was pushed
21556 Priv_Scop
:= Empty
;
21559 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
21560 Set_Full_View
(Full
, Priv
);
21562 if Present
(Priv_Scop
) then
21566 Replace_Elmt
(Priv_Elmt
, Full
);
21569 Next_Elmt
(Priv_Elmt
);
21574 Disp_Typ
: Entity_Id
;
21575 Full_List
: Elist_Id
;
21577 Prim_Elmt
: Elmt_Id
;
21578 Priv_List
: Elist_Id
;
21582 L
: Elist_Id
) return Boolean;
21583 -- Determine whether list L contains element E
21591 L
: Elist_Id
) return Boolean
21593 List_Elmt
: Elmt_Id
;
21596 List_Elmt
:= First_Elmt
(L
);
21597 while Present
(List_Elmt
) loop
21598 if Node
(List_Elmt
) = E
then
21602 Next_Elmt
(List_Elmt
);
21608 -- Start of processing
21611 -- If the private view was tagged, copy the new primitive operations
21612 -- from the private view to the full view.
21614 if Is_Tagged_Type
(Full_T
) then
21615 if Is_Tagged_Type
(Priv_T
) then
21616 Priv_List
:= Primitive_Operations
(Priv_T
);
21617 Prim_Elmt
:= First_Elmt
(Priv_List
);
21619 -- In the case of a concurrent type completing a private tagged
21620 -- type, primitives may have been declared in between the two
21621 -- views. These subprograms need to be wrapped the same way
21622 -- entries and protected procedures are handled because they
21623 -- cannot be directly shared by the two views.
21625 if Is_Concurrent_Type
(Full_T
) then
21627 Conc_Typ
: constant Entity_Id
:=
21628 Corresponding_Record_Type
(Full_T
);
21629 Curr_Nod
: Node_Id
:= Parent
(Conc_Typ
);
21630 Wrap_Spec
: Node_Id
;
21633 while Present
(Prim_Elmt
) loop
21634 Prim
:= Node
(Prim_Elmt
);
21636 if Comes_From_Source
(Prim
)
21637 and then not Is_Abstract_Subprogram
(Prim
)
21640 Make_Subprogram_Declaration
(Sloc
(Prim
),
21644 Obj_Typ
=> Conc_Typ
,
21646 Parameter_Specifications
21649 Insert_After
(Curr_Nod
, Wrap_Spec
);
21650 Curr_Nod
:= Wrap_Spec
;
21652 Analyze
(Wrap_Spec
);
21654 -- Remove the wrapper from visibility to avoid
21655 -- spurious conflict with the wrapped entity.
21657 Set_Is_Immediately_Visible
21658 (Defining_Entity
(Specification
(Wrap_Spec
)),
21662 Next_Elmt
(Prim_Elmt
);
21668 -- For nonconcurrent types, transfer explicit primitives, but
21669 -- omit those inherited from the parent of the private view
21670 -- since they will be re-inherited later on.
21673 Full_List
:= Primitive_Operations
(Full_T
);
21674 while Present
(Prim_Elmt
) loop
21675 Prim
:= Node
(Prim_Elmt
);
21677 if Comes_From_Source
(Prim
)
21678 and then not Contains
(Prim
, Full_List
)
21680 Append_Elmt
(Prim
, Full_List
);
21683 Next_Elmt
(Prim_Elmt
);
21687 -- Untagged private view
21690 Full_List
:= Primitive_Operations
(Full_T
);
21692 -- In this case the partial view is untagged, so here we locate
21693 -- all of the earlier primitives that need to be treated as
21694 -- dispatching (those that appear between the two views). Note
21695 -- that these additional operations must all be new operations
21696 -- (any earlier operations that override inherited operations
21697 -- of the full view will already have been inserted in the
21698 -- primitives list, marked by Check_Operation_From_Private_View
21699 -- as dispatching. Note that implicit "/=" operators are
21700 -- excluded from being added to the primitives list since they
21701 -- shouldn't be treated as dispatching (tagged "/=" is handled
21704 Prim
:= Next_Entity
(Full_T
);
21705 while Present
(Prim
) and then Prim
/= Priv_T
loop
21706 if Ekind
(Prim
) in E_Procedure | E_Function
then
21707 Disp_Typ
:= Find_Dispatching_Type
(Prim
);
21709 if Disp_Typ
= Full_T
21710 and then (Chars
(Prim
) /= Name_Op_Ne
21711 or else Comes_From_Source
(Prim
))
21713 Check_Controlling_Formals
(Full_T
, Prim
);
21715 if Is_Suitable_Primitive
(Prim
)
21716 and then not Is_Dispatching_Operation
(Prim
)
21718 Append_Elmt
(Prim
, Full_List
);
21719 Set_Is_Dispatching_Operation
(Prim
);
21720 Set_DT_Position_Value
(Prim
, No_Uint
);
21723 elsif Is_Dispatching_Operation
(Prim
)
21724 and then Disp_Typ
/= Full_T
21726 -- Verify that it is not otherwise controlled by a
21727 -- formal or a return value of type T.
21729 Check_Controlling_Formals
(Disp_Typ
, Prim
);
21733 Next_Entity
(Prim
);
21737 -- For the tagged case, the two views can share the same primitive
21738 -- operations list and the same class-wide type. Update attributes
21739 -- of the class-wide type which depend on the full declaration.
21741 if Is_Tagged_Type
(Priv_T
) then
21742 Set_Direct_Primitive_Operations
(Priv_T
, Full_List
);
21743 Set_Class_Wide_Type
21744 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
21746 Propagate_Concurrent_Flags
(Class_Wide_Type
(Priv_T
), Full_T
);
21749 -- For untagged types, copy the primitives across from the private
21750 -- view to the full view, for support of prefixed calls when
21751 -- extensions are enabled, and better error messages otherwise.
21754 Priv_List
:= Primitive_Operations
(Priv_T
);
21755 Prim_Elmt
:= First_Elmt
(Priv_List
);
21757 Full_List
:= Primitive_Operations
(Full_T
);
21758 while Present
(Prim_Elmt
) loop
21759 Prim
:= Node
(Prim_Elmt
);
21760 Append_Elmt
(Prim
, Full_List
);
21761 Next_Elmt
(Prim_Elmt
);
21766 -- Ada 2005 AI 161: Check preelaborable initialization consistency
21768 if Known_To_Have_Preelab_Init
(Priv_T
) then
21770 -- Case where there is a pragma Preelaborable_Initialization. We
21771 -- always allow this in predefined units, which is cheating a bit,
21772 -- but it means we don't have to struggle to meet the requirements in
21773 -- the RM for having Preelaborable Initialization. Otherwise we
21774 -- require that the type meets the RM rules. But we can't check that
21775 -- yet, because of the rule about overriding Initialize, so we simply
21776 -- set a flag that will be checked at freeze time.
21778 if not In_Predefined_Unit
(Full_T
) then
21779 Set_Must_Have_Preelab_Init
(Full_T
);
21783 -- If pragma CPP_Class was applied to the private type declaration,
21784 -- propagate it now to the full type declaration.
21786 if Is_CPP_Class
(Priv_T
) then
21787 Set_Is_CPP_Class
(Full_T
);
21788 Set_Convention
(Full_T
, Convention_CPP
);
21790 -- Check that components of imported CPP types do not have default
21793 Check_CPP_Type_Has_No_Defaults
(Full_T
);
21796 -- If the private view has user specified stream attributes, then so has
21799 -- Why the test, how could these flags be already set in Full_T ???
21801 if Has_Specified_Stream_Read
(Priv_T
) then
21802 Set_Has_Specified_Stream_Read
(Full_T
);
21805 if Has_Specified_Stream_Write
(Priv_T
) then
21806 Set_Has_Specified_Stream_Write
(Full_T
);
21809 if Has_Specified_Stream_Input
(Priv_T
) then
21810 Set_Has_Specified_Stream_Input
(Full_T
);
21813 if Has_Specified_Stream_Output
(Priv_T
) then
21814 Set_Has_Specified_Stream_Output
(Full_T
);
21817 -- Propagate Default_Initial_Condition-related attributes from the
21818 -- partial view to the full view.
21820 Propagate_DIC_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21822 -- And to the underlying full view, if any
21824 if Is_Private_Type
(Full_T
)
21825 and then Present
(Underlying_Full_View
(Full_T
))
21827 Propagate_DIC_Attributes
21828 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21831 -- Propagate invariant-related attributes from the partial view to the
21834 Propagate_Invariant_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21836 -- And to the underlying full view, if any
21838 if Is_Private_Type
(Full_T
)
21839 and then Present
(Underlying_Full_View
(Full_T
))
21841 Propagate_Invariant_Attributes
21842 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21845 -- AI12-0041: Detect an attempt to inherit a class-wide type invariant
21846 -- in the full view without advertising the inheritance in the partial
21847 -- view. This can only occur when the partial view has no parent type
21848 -- and the full view has an interface as a parent. Any other scenarios
21849 -- are illegal because implemented interfaces must match between the
21852 if Is_Tagged_Type
(Priv_T
) and then Is_Tagged_Type
(Full_T
) then
21854 Full_Par
: constant Entity_Id
:= Etype
(Full_T
);
21855 Priv_Par
: constant Entity_Id
:= Etype
(Priv_T
);
21858 if not Is_Interface
(Priv_Par
)
21859 and then Is_Interface
(Full_Par
)
21860 and then Has_Inheritable_Invariants
(Full_Par
)
21863 ("hidden inheritance of class-wide type invariants not "
21869 -- Propagate predicates to full type, and predicate function if already
21870 -- defined. It is not clear that this can actually happen? the partial
21871 -- view cannot be frozen yet, and the predicate function has not been
21872 -- built. Still it is a cheap check and seems safer to make it.
21874 Propagate_Predicate_Attributes
(Full_T
, Priv_T
);
21876 if Is_Private_Type
(Full_T
)
21877 and then Present
(Underlying_Full_View
(Full_T
))
21879 Propagate_Predicate_Attributes
21880 (Underlying_Full_View
(Full_T
), Priv_T
);
21884 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
21885 end Process_Full_View
;
21887 -----------------------------------
21888 -- Process_Incomplete_Dependents --
21889 -----------------------------------
21891 procedure Process_Incomplete_Dependents
21893 Full_T
: Entity_Id
;
21896 Inc_Elmt
: Elmt_Id
;
21897 Priv_Dep
: Entity_Id
;
21898 New_Subt
: Entity_Id
;
21900 Disc_Constraint
: Elist_Id
;
21903 if No
(Private_Dependents
(Inc_T
)) then
21907 -- Itypes that may be generated by the completion of an incomplete
21908 -- subtype are not used by the back-end and not attached to the tree.
21909 -- They are created only for constraint-checking purposes.
21911 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
21912 while Present
(Inc_Elmt
) loop
21913 Priv_Dep
:= Node
(Inc_Elmt
);
21915 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
21917 -- An Access_To_Subprogram type may have a return type or a
21918 -- parameter type that is incomplete. Replace with the full view.
21920 if Etype
(Priv_Dep
) = Inc_T
then
21921 Set_Etype
(Priv_Dep
, Full_T
);
21925 Formal
: Entity_Id
;
21928 Formal
:= First_Formal
(Priv_Dep
);
21929 while Present
(Formal
) loop
21930 if Etype
(Formal
) = Inc_T
then
21931 Set_Etype
(Formal
, Full_T
);
21934 Next_Formal
(Formal
);
21938 elsif Is_Overloadable
(Priv_Dep
) then
21940 -- If a subprogram in the incomplete dependents list is primitive
21941 -- for a tagged full type then mark it as a dispatching operation,
21942 -- check whether it overrides an inherited subprogram, and check
21943 -- restrictions on its controlling formals. Note that a protected
21944 -- operation is never dispatching: only its wrapper operation
21945 -- (which has convention Ada) is.
21947 if Is_Tagged_Type
(Full_T
)
21948 and then Is_Primitive
(Priv_Dep
)
21949 and then Convention
(Priv_Dep
) /= Convention_Protected
21951 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
21952 Set_Is_Dispatching_Operation
(Priv_Dep
);
21953 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
21956 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
21958 -- Can happen during processing of a body before the completion
21959 -- of a TA type. Ignore, because spec is also on dependent list.
21963 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
21964 -- corresponding subtype of the full view.
21966 elsif Ekind
(Priv_Dep
) = E_Incomplete_Subtype
21967 and then Comes_From_Source
(Priv_Dep
)
21969 Set_Subtype_Indication
21970 (Parent
(Priv_Dep
), New_Occurrence_Of
(Full_T
, Sloc
(Priv_Dep
)));
21971 Reinit_Field_To_Zero
21972 (Priv_Dep
, F_Private_Dependents
,
21973 Old_Ekind
=> E_Incomplete_Subtype
);
21974 Mutate_Ekind
(Priv_Dep
, Subtype_Kind
(Ekind
(Full_T
)));
21975 Set_Etype
(Priv_Dep
, Full_T
);
21976 Set_Analyzed
(Parent
(Priv_Dep
), False);
21978 -- Reanalyze the declaration, suppressing the call to Enter_Name
21979 -- to avoid duplicate names.
21981 Analyze_Subtype_Declaration
21982 (N
=> Parent
(Priv_Dep
),
21985 -- Dependent is a subtype
21988 -- We build a new subtype indication using the full view of the
21989 -- incomplete parent. The discriminant constraints have been
21990 -- elaborated already at the point of the subtype declaration.
21992 New_Subt
:= Create_Itype
(E_Void
, N
);
21994 if Has_Discriminants
(Full_T
) then
21995 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
21997 Disc_Constraint
:= No_Elist
;
22000 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
22001 Set_Full_View
(Priv_Dep
, New_Subt
);
22004 Next_Elmt
(Inc_Elmt
);
22006 end Process_Incomplete_Dependents
;
22008 --------------------------------
22009 -- Process_Range_Expr_In_Decl --
22010 --------------------------------
22012 procedure Process_Range_Expr_In_Decl
22015 Subtyp
: Entity_Id
:= Empty
;
22016 Check_List
: List_Id
:= No_List
)
22019 R_Checks
: Check_Result
;
22020 Insert_Node
: Node_Id
;
22021 Def_Id
: Entity_Id
;
22024 Analyze_And_Resolve
(R
, Base_Type
(T
));
22026 if Nkind
(R
) = N_Range
then
22027 Lo
:= Low_Bound
(R
);
22028 Hi
:= High_Bound
(R
);
22030 -- Validity checks on the range of a quantified expression are
22031 -- delayed until the construct is transformed into a loop.
22033 if Nkind
(Parent
(R
)) = N_Loop_Parameter_Specification
22034 and then Nkind
(Parent
(Parent
(R
))) = N_Quantified_Expression
22038 -- We need to ensure validity of the bounds here, because if we
22039 -- go ahead and do the expansion, then the expanded code will get
22040 -- analyzed with range checks suppressed and we miss the check.
22042 -- WARNING: The capture of the range bounds with xxx_FIRST/_LAST and
22043 -- the temporaries generated by routine Remove_Side_Effects by means
22044 -- of validity checks must use the same names. When a range appears
22045 -- in the parent of a generic, the range is processed with checks
22046 -- disabled as part of the generic context and with checks enabled
22047 -- for code generation purposes. This leads to link issues as the
22048 -- generic contains references to xxx_FIRST/_LAST, but the inlined
22049 -- template sees the temporaries generated by Remove_Side_Effects.
22052 Validity_Check_Range
(R
, Subtyp
);
22055 -- If there were errors in the declaration, try and patch up some
22056 -- common mistakes in the bounds. The cases handled are literals
22057 -- which are Integer where the expected type is Real and vice versa.
22058 -- These corrections allow the compilation process to proceed further
22059 -- along since some basic assumptions of the format of the bounds
22062 if Etype
(R
) = Any_Type
then
22063 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
22065 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
22067 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
22069 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
22071 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
22073 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
22075 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
22077 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
22084 -- If the bounds of the range have been mistakenly given as string
22085 -- literals (perhaps in place of character literals), then an error
22086 -- has already been reported, but we rewrite the string literal as a
22087 -- bound of the range's type to avoid blowups in later processing
22088 -- that looks at static values.
22090 if Nkind
(Lo
) = N_String_Literal
then
22092 Make_Attribute_Reference
(Sloc
(Lo
),
22093 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Lo
)),
22094 Attribute_Name
=> Name_First
));
22095 Analyze_And_Resolve
(Lo
);
22098 if Nkind
(Hi
) = N_String_Literal
then
22100 Make_Attribute_Reference
(Sloc
(Hi
),
22101 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Hi
)),
22102 Attribute_Name
=> Name_First
));
22103 Analyze_And_Resolve
(Hi
);
22106 -- If bounds aren't scalar at this point then exit, avoiding
22107 -- problems with further processing of the range in this procedure.
22109 if not Is_Scalar_Type
(Etype
(Lo
)) then
22113 -- Resolve (actually Sem_Eval) has checked that the bounds are in
22114 -- then range of the base type. Here we check whether the bounds
22115 -- are in the range of the subtype itself. Note that if the bounds
22116 -- represent the null range the Constraint_Error exception should
22119 -- Capture values of bounds and generate temporaries for them
22120 -- if needed, before applying checks, since checks may cause
22121 -- duplication of the expression without forcing evaluation.
22123 -- The forced evaluation removes side effects from expressions,
22124 -- which should occur also in GNATprove mode. Otherwise, we end up
22125 -- with unexpected insertions of actions at places where this is
22126 -- not supposed to occur, e.g. on default parameters of a call.
22128 if Expander_Active
or GNATprove_Mode
then
22130 -- Call Force_Evaluation to create declarations as needed
22131 -- to deal with side effects, and also create typ_FIRST/LAST
22132 -- entities for bounds if we have a subtype name.
22134 -- Note: we do this transformation even if expansion is not
22135 -- active if we are in GNATprove_Mode since the transformation
22136 -- is in general required to ensure that the resulting tree has
22137 -- proper Ada semantics.
22140 (Lo
, Related_Id
=> Subtyp
, Is_Low_Bound
=> True);
22142 (Hi
, Related_Id
=> Subtyp
, Is_High_Bound
=> True);
22145 -- We use a flag here instead of suppressing checks on the type
22146 -- because the type we check against isn't necessarily the place
22147 -- where we put the check.
22149 R_Checks
:= Get_Range_Checks
(R
, T
);
22151 -- Look up tree to find an appropriate insertion point. We can't
22152 -- just use insert_actions because later processing depends on
22153 -- the insertion node. Prior to Ada 2012 the insertion point could
22154 -- only be a declaration or a loop, but quantified expressions can
22155 -- appear within any context in an expression, and the insertion
22156 -- point can be any statement, pragma, or declaration.
22158 Insert_Node
:= Parent
(R
);
22159 while Present
(Insert_Node
) loop
22161 Nkind
(Insert_Node
) in N_Declaration
22163 Nkind
(Insert_Node
) not in N_Component_Declaration
22164 | N_Loop_Parameter_Specification
22165 | N_Function_Specification
22166 | N_Procedure_Specification
;
22168 exit when Nkind
(Insert_Node
) in
22169 N_Later_Decl_Item |
22170 N_Statement_Other_Than_Procedure_Call |
22171 N_Procedure_Call_Statement |
22174 Insert_Node
:= Parent
(Insert_Node
);
22177 if Present
(Insert_Node
) then
22179 -- Case of loop statement. Verify that the range is part of the
22180 -- subtype indication of the iteration scheme.
22182 if Nkind
(Insert_Node
) = N_Loop_Statement
then
22187 Indic
:= Parent
(R
);
22188 while Present
(Indic
)
22189 and then Nkind
(Indic
) /= N_Subtype_Indication
22191 Indic
:= Parent
(Indic
);
22194 if Present
(Indic
) then
22195 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
22197 Insert_Range_Checks
22201 Sloc
(Insert_Node
),
22202 Do_Before
=> True);
22206 -- Case of declarations. If the declaration is for a type and
22207 -- involves discriminants, the checks are premature at the
22208 -- declaration point and need to wait for the expansion of the
22209 -- initialization procedure, which will pass in the list to put
22210 -- them on; otherwise, the checks are done at the declaration
22211 -- point and there is no need to do them again in the
22212 -- initialization procedure.
22214 elsif Nkind
(Insert_Node
) in N_Declaration
then
22215 Def_Id
:= Defining_Identifier
(Insert_Node
);
22217 if (Ekind
(Def_Id
) = E_Record_Type
22218 and then Depends_On_Discriminant
(R
))
22220 (Ekind
(Def_Id
) = E_Protected_Type
22221 and then Has_Discriminants
(Def_Id
))
22223 if Present
(Check_List
) then
22224 Append_Range_Checks
22226 Check_List
, Def_Id
, Sloc
(Insert_Node
));
22230 if No
(Check_List
) then
22231 Insert_Range_Checks
22233 Insert_Node
, Def_Id
, Sloc
(Insert_Node
));
22237 -- Case of statements. Drop the checks, as the range appears in
22238 -- the context of a quantified expression. Insertion will take
22239 -- place when expression is expanded.
22246 -- Case of other than an explicit N_Range node
22248 -- The forced evaluation removes side effects from expressions, which
22249 -- should occur also in GNATprove mode. Otherwise, we end up with
22250 -- unexpected insertions of actions at places where this is not
22251 -- supposed to occur, e.g. on default parameters of a call.
22253 elsif Expander_Active
or GNATprove_Mode
then
22254 Get_Index_Bounds
(R
, Lo
, Hi
);
22255 Force_Evaluation
(Lo
);
22256 Force_Evaluation
(Hi
);
22258 end Process_Range_Expr_In_Decl
;
22260 --------------------------------------
22261 -- Process_Real_Range_Specification --
22262 --------------------------------------
22264 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
22265 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
22268 Err
: Boolean := False;
22270 procedure Analyze_Bound
(N
: Node_Id
);
22271 -- Analyze and check one bound
22273 -------------------
22274 -- Analyze_Bound --
22275 -------------------
22277 procedure Analyze_Bound
(N
: Node_Id
) is
22279 Analyze_And_Resolve
(N
, Any_Real
);
22281 if not Is_OK_Static_Expression
(N
) then
22282 Flag_Non_Static_Expr
22283 ("bound in real type definition is not static!", N
);
22288 -- Start of processing for Process_Real_Range_Specification
22291 if Present
(Spec
) then
22292 Lo
:= Low_Bound
(Spec
);
22293 Hi
:= High_Bound
(Spec
);
22294 Analyze_Bound
(Lo
);
22295 Analyze_Bound
(Hi
);
22297 -- If error, clear away junk range specification
22300 Set_Real_Range_Specification
(Def
, Empty
);
22303 end Process_Real_Range_Specification
;
22305 ---------------------
22306 -- Process_Subtype --
22307 ---------------------
22309 function Process_Subtype
22311 Related_Nod
: Node_Id
;
22312 Related_Id
: Entity_Id
:= Empty
;
22313 Suffix
: Character := ' ') return Entity_Id
22315 procedure Check_Incomplete
(T
: Node_Id
);
22316 -- Called to verify that an incomplete type is not used prematurely
22318 ----------------------
22319 -- Check_Incomplete --
22320 ----------------------
22322 procedure Check_Incomplete
(T
: Node_Id
) is
22324 -- Ada 2005 (AI-412): Incomplete subtypes are legal
22326 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
22328 not (Ada_Version
>= Ada_2005
22330 (Nkind
(Parent
(T
)) = N_Subtype_Declaration
22331 or else (Nkind
(Parent
(T
)) = N_Subtype_Indication
22332 and then Nkind
(Parent
(Parent
(T
))) =
22333 N_Subtype_Declaration
)))
22335 Error_Msg_N
("invalid use of type before its full declaration", T
);
22337 end Check_Incomplete
;
22342 Def_Id
: Entity_Id
;
22343 Error_Node
: Node_Id
;
22344 Full_View_Id
: Entity_Id
;
22345 Subtype_Mark_Id
: Entity_Id
;
22347 May_Have_Null_Exclusion
: Boolean;
22349 -- Start of processing for Process_Subtype
22352 -- Case of no constraints present
22354 if Nkind
(S
) /= N_Subtype_Indication
then
22357 -- No way to proceed if the subtype indication is malformed. This
22358 -- will happen for example when the subtype indication in an object
22359 -- declaration is missing altogether and the expression is analyzed
22360 -- as if it were that indication.
22362 if not Is_Entity_Name
(S
) then
22366 Check_Incomplete
(S
);
22369 -- The following mirroring of assertion in Null_Exclusion_Present is
22370 -- ugly, can't we have a range, a static predicate or even a flag???
22372 May_Have_Null_Exclusion
:=
22375 Nkind
(P
) in N_Access_Definition
22376 | N_Access_Function_Definition
22377 | N_Access_Procedure_Definition
22378 | N_Access_To_Object_Definition
22380 | N_Component_Definition
22381 | N_Derived_Type_Definition
22382 | N_Discriminant_Specification
22383 | N_Formal_Object_Declaration
22384 | N_Function_Specification
22385 | N_Object_Declaration
22386 | N_Object_Renaming_Declaration
22387 | N_Parameter_Specification
22388 | N_Subtype_Declaration
;
22390 -- Ada 2005 (AI-231): Static check
22392 if Ada_Version
>= Ada_2005
22393 and then May_Have_Null_Exclusion
22394 and then Null_Exclusion_Present
(P
)
22395 and then Nkind
(P
) /= N_Access_To_Object_Definition
22396 and then not Is_Access_Type
(Entity
(S
))
22398 Error_Msg_N
("`NOT NULL` only allowed for an access type", S
);
22401 -- Create an Itype that is a duplicate of Entity (S) but with the
22402 -- null-exclusion attribute.
22404 if May_Have_Null_Exclusion
22405 and then Is_Access_Type
(Entity
(S
))
22406 and then Null_Exclusion_Present
(P
)
22408 -- No need to check the case of an access to object definition.
22409 -- It is correct to define double not-null pointers.
22412 -- type Not_Null_Int_Ptr is not null access Integer;
22413 -- type Acc is not null access Not_Null_Int_Ptr;
22415 and then Nkind
(P
) /= N_Access_To_Object_Definition
22417 if Can_Never_Be_Null
(Entity
(S
)) then
22418 case Nkind
(Related_Nod
) is
22419 when N_Full_Type_Declaration
=>
22420 if Nkind
(Type_Definition
(Related_Nod
))
22421 in N_Array_Type_Definition
22425 (Component_Definition
22426 (Type_Definition
(Related_Nod
)));
22429 Subtype_Indication
(Type_Definition
(Related_Nod
));
22432 when N_Subtype_Declaration
=>
22433 Error_Node
:= Subtype_Indication
(Related_Nod
);
22435 when N_Object_Declaration
=>
22436 Error_Node
:= Object_Definition
(Related_Nod
);
22438 when N_Component_Declaration
=>
22440 Subtype_Indication
(Component_Definition
(Related_Nod
));
22442 when N_Allocator
=>
22443 Error_Node
:= Expression
(Related_Nod
);
22446 pragma Assert
(False);
22447 Error_Node
:= Related_Nod
;
22451 ("`NOT NULL` not allowed (& already excludes null)",
22457 Create_Null_Excluding_Itype
22459 Related_Nod
=> P
));
22460 Set_Entity
(S
, Etype
(S
));
22465 -- Case of constraint present, so that we have an N_Subtype_Indication
22466 -- node (this node is created only if constraints are present).
22469 Find_Type
(Subtype_Mark
(S
));
22471 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
22473 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
22474 and then Is_Itype
(Defining_Identifier
(Parent
(S
))))
22476 Check_Incomplete
(Subtype_Mark
(S
));
22480 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
22482 -- Explicit subtype declaration case
22484 if Nkind
(P
) = N_Subtype_Declaration
then
22485 Def_Id
:= Defining_Identifier
(P
);
22487 -- Explicit derived type definition case
22489 elsif Nkind
(P
) = N_Derived_Type_Definition
then
22490 Def_Id
:= Defining_Identifier
(Parent
(P
));
22492 -- Implicit case, the Def_Id must be created as an implicit type.
22493 -- The one exception arises in the case of concurrent types, array
22494 -- and access types, where other subsidiary implicit types may be
22495 -- created and must appear before the main implicit type. In these
22496 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
22497 -- has not yet been called to create Def_Id.
22500 if Is_Array_Type
(Subtype_Mark_Id
)
22501 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
22502 or else Is_Access_Type
(Subtype_Mark_Id
)
22506 -- For the other cases, we create a new unattached Itype,
22507 -- and set the indication to ensure it gets attached later.
22511 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22515 -- If the kind of constraint is invalid for this kind of type,
22516 -- then give an error, and then pretend no constraint was given.
22518 if not Is_Valid_Constraint_Kind
22519 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
22522 ("incorrect constraint for this kind of type", Constraint
(S
));
22524 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
22526 -- Set Ekind of orphan itype, to prevent cascaded errors
22528 if Present
(Def_Id
) then
22529 Mutate_Ekind
(Def_Id
, Ekind
(Any_Type
));
22532 -- Make recursive call, having got rid of the bogus constraint
22534 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
22537 -- Remaining processing depends on type. Select on Base_Type kind to
22538 -- ensure getting to the concrete type kind in the case of a private
22539 -- subtype (needed when only doing semantic analysis).
22541 case Ekind
(Base_Type
(Subtype_Mark_Id
)) is
22542 when Access_Kind
=>
22544 -- If this is a constraint on a class-wide type, discard it.
22545 -- There is currently no way to express a partial discriminant
22546 -- constraint on a type with unknown discriminants. This is
22547 -- a pathology that the ACATS wisely decides not to test.
22549 if Is_Class_Wide_Type
(Designated_Type
(Subtype_Mark_Id
)) then
22550 if Comes_From_Source
(S
) then
22552 ("constraint on class-wide type ignored??",
22556 if Nkind
(P
) = N_Subtype_Declaration
then
22557 Set_Subtype_Indication
(P
,
22558 New_Occurrence_Of
(Subtype_Mark_Id
, Sloc
(S
)));
22561 return Subtype_Mark_Id
;
22564 Constrain_Access
(Def_Id
, S
, Related_Nod
);
22567 and then Is_Itype
(Designated_Type
(Def_Id
))
22568 and then Nkind
(Related_Nod
) = N_Subtype_Declaration
22569 and then not Is_Incomplete_Type
(Designated_Type
(Def_Id
))
22571 Build_Itype_Reference
22572 (Designated_Type
(Def_Id
), Related_Nod
);
22576 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22578 when Decimal_Fixed_Point_Kind
=>
22579 Constrain_Decimal
(Def_Id
, S
);
22581 when Enumeration_Kind
=>
22582 Constrain_Enumeration
(Def_Id
, S
);
22584 when Ordinary_Fixed_Point_Kind
=>
22585 Constrain_Ordinary_Fixed
(Def_Id
, S
);
22588 Constrain_Float
(Def_Id
, S
);
22590 when Integer_Kind
=>
22591 Constrain_Integer
(Def_Id
, S
);
22593 when Class_Wide_Kind
22594 | E_Incomplete_Type
22598 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22600 if Ekind
(Def_Id
) = E_Incomplete_Type
then
22601 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22604 when Private_Kind
=>
22606 -- A private type with unknown discriminants may be completed
22607 -- by an unconstrained array type.
22609 if Has_Unknown_Discriminants
(Subtype_Mark_Id
)
22610 and then Present
(Full_View
(Subtype_Mark_Id
))
22611 and then Is_Array_Type
(Full_View
(Subtype_Mark_Id
))
22613 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22615 -- ... but more commonly is completed by a discriminated record
22619 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22622 -- The base type may be private but Def_Id may be a full view
22625 if Is_Private_Type
(Def_Id
) then
22626 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22629 -- In case of an invalid constraint prevent further processing
22630 -- since the type constructed is missing expected fields.
22632 if Etype
(Def_Id
) = Any_Type
then
22636 -- If the full view is that of a task with discriminants,
22637 -- we must constrain both the concurrent type and its
22638 -- corresponding record type. Otherwise we will just propagate
22639 -- the constraint to the full view, if available.
22641 if Present
(Full_View
(Subtype_Mark_Id
))
22642 and then Has_Discriminants
(Subtype_Mark_Id
)
22643 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
22646 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22648 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
22649 Constrain_Concurrent
(Full_View_Id
, S
,
22650 Related_Nod
, Related_Id
, Suffix
);
22651 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
22652 Set_Full_View
(Def_Id
, Full_View_Id
);
22654 -- Introduce an explicit reference to the private subtype,
22655 -- to prevent scope anomalies in gigi if first use appears
22656 -- in a nested context, e.g. a later function body.
22657 -- Should this be generated in other contexts than a full
22658 -- type declaration?
22660 if Is_Itype
(Def_Id
)
22662 Nkind
(Parent
(P
)) = N_Full_Type_Declaration
22664 Build_Itype_Reference
(Def_Id
, Parent
(P
));
22668 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
22671 when Concurrent_Kind
=>
22672 Constrain_Concurrent
(Def_Id
, S
,
22673 Related_Nod
, Related_Id
, Suffix
);
22676 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
22679 -- Size, Alignment, Representation aspects and Convention are always
22680 -- inherited from the base type.
22682 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
22683 Set_Rep_Info
(Def_Id
, (Subtype_Mark_Id
));
22684 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
22686 -- The anonymous subtype created for the subtype indication
22687 -- inherits the predicates of the parent.
22689 if Has_Predicates
(Subtype_Mark_Id
) then
22690 Inherit_Predicate_Flags
(Def_Id
, Subtype_Mark_Id
);
22692 -- Indicate where the predicate function may be found
22694 if No
(Predicate_Function
(Def_Id
)) and then Is_Itype
(Def_Id
) then
22695 Set_Predicated_Parent
(Def_Id
, Subtype_Mark_Id
);
22701 end Process_Subtype
;
22703 -----------------------------
22704 -- Record_Type_Declaration --
22705 -----------------------------
22707 procedure Record_Type_Declaration
22712 Def
: constant Node_Id
:= Type_Definition
(N
);
22713 Is_Tagged
: Boolean;
22714 Tag_Comp
: Entity_Id
;
22717 -- These flags must be initialized before calling Process_Discriminants
22718 -- because this routine makes use of them.
22720 Mutate_Ekind
(T
, E_Record_Type
);
22722 Reinit_Size_Align
(T
);
22723 Set_Interfaces
(T
, No_Elist
);
22724 Set_Stored_Constraint
(T
, No_Elist
);
22725 Set_Default_SSO
(T
);
22726 Set_No_Reordering
(T
, No_Component_Reordering
);
22730 if Ada_Version
< Ada_2005
or else not Interface_Present
(Def
) then
22731 -- The flag Is_Tagged_Type might have already been set by
22732 -- Find_Type_Name if it detected an error for declaration T. This
22733 -- arises in the case of private tagged types where the full view
22734 -- omits the word tagged.
22737 Tagged_Present
(Def
)
22738 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
22740 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
22743 Set_Is_Tagged_Type
(T
, True);
22744 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
22747 -- Type is abstract if full declaration carries keyword, or if
22748 -- previous partial view did.
22750 Set_Is_Abstract_Type
(T
, Is_Abstract_Type
(T
)
22751 or else Abstract_Present
(Def
));
22755 Analyze_Interface_Declaration
(T
, Def
);
22757 if Present
(Discriminant_Specifications
(N
)) then
22759 ("interface types cannot have discriminants",
22760 Defining_Identifier
22761 (First
(Discriminant_Specifications
(N
))));
22765 -- First pass: if there are self-referential access components,
22766 -- create the required anonymous access type declarations, and if
22767 -- need be an incomplete type declaration for T itself.
22769 Check_Anonymous_Access_Components
(N
, T
, Prev
, Component_List
(Def
));
22771 if Ada_Version
>= Ada_2005
22772 and then Present
(Interface_List
(Def
))
22774 Check_Interfaces
(N
, Def
);
22777 Ifaces_List
: Elist_Id
;
22780 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
22781 -- already in the parents.
22785 Ifaces_List
=> Ifaces_List
,
22786 Exclude_Parents
=> True);
22788 Set_Interfaces
(T
, Ifaces_List
);
22792 -- Records constitute a scope for the component declarations within.
22793 -- The scope is created prior to the processing of these declarations.
22794 -- Discriminants are processed first, so that they are visible when
22795 -- processing the other components. The Ekind of the record type itself
22796 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
22798 -- Enter record scope
22802 -- If an incomplete or private type declaration was already given for
22803 -- the type, then this scope already exists, and the discriminants have
22804 -- been declared within. We must verify that the full declaration
22805 -- matches the incomplete one.
22807 Check_Or_Process_Discriminants
(N
, T
, Prev
);
22809 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
22810 Set_Has_Delayed_Freeze
(T
, True);
22812 -- For tagged types add a manually analyzed component corresponding
22813 -- to the component _tag, the corresponding piece of tree will be
22814 -- expanded as part of the freezing actions if it is not a CPP_Class.
22818 -- Do not add the tag unless we are in expansion mode
22820 if Expander_Active
then
22821 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
22822 Enter_Name
(Tag_Comp
);
22824 Mutate_Ekind
(Tag_Comp
, E_Component
);
22825 Set_Is_Tag
(Tag_Comp
);
22826 Set_Is_Aliased
(Tag_Comp
);
22827 Set_Is_Independent
(Tag_Comp
);
22828 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
22829 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
22830 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
22831 Reinit_Component_Location
(Tag_Comp
);
22833 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
22834 -- implemented interfaces.
22836 if Has_Interfaces
(T
) then
22837 Add_Interface_Tag_Components
(N
, T
);
22841 Make_Class_Wide_Type
(T
);
22842 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
22845 -- We must suppress range checks when processing record components in
22846 -- the presence of discriminants, since we don't want spurious checks to
22847 -- be generated during their analysis, but Suppress_Range_Checks flags
22848 -- must be reset the after processing the record definition.
22850 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
22851 -- couldn't we just use the normal range check suppression method here.
22852 -- That would seem cleaner ???
22854 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
22855 Set_Kill_Range_Checks
(T
, True);
22856 Record_Type_Definition
(Def
, Prev
);
22857 Set_Kill_Range_Checks
(T
, False);
22859 Record_Type_Definition
(Def
, Prev
);
22862 -- Exit from record scope
22866 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
22867 -- the implemented interfaces and associate them an aliased entity.
22870 and then not Is_Empty_List
(Interface_List
(Def
))
22872 Derive_Progenitor_Subprograms
(T
, T
);
22875 Check_Function_Writable_Actuals
(N
);
22876 end Record_Type_Declaration
;
22878 ----------------------------
22879 -- Record_Type_Definition --
22880 ----------------------------
22882 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
22883 Component
: Entity_Id
;
22884 Ctrl_Components
: Boolean := False;
22885 Final_Storage_Only
: Boolean;
22889 if Ekind
(Prev_T
) = E_Incomplete_Type
then
22890 T
:= Full_View
(Prev_T
);
22895 Set_Is_Not_Self_Hidden
(T
);
22897 Final_Storage_Only
:= not Is_Controlled
(T
);
22899 -- Ada 2005: Check whether an explicit "limited" is present in a derived
22900 -- type declaration.
22902 if Parent_Kind
(Def
) = N_Derived_Type_Definition
22903 and then Limited_Present
(Parent
(Def
))
22905 Set_Is_Limited_Record
(T
);
22908 -- If the component list of a record type is defined by the reserved
22909 -- word null and there is no discriminant part, then the record type has
22910 -- no components and all records of the type are null records (RM 3.7)
22911 -- This procedure is also called to process the extension part of a
22912 -- record extension, in which case the current scope may have inherited
22916 and then Present
(Component_List
(Def
))
22917 and then not Null_Present
(Component_List
(Def
))
22919 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
22921 if Present
(Variant_Part
(Component_List
(Def
))) then
22922 Analyze
(Variant_Part
(Component_List
(Def
)));
22926 -- After completing the semantic analysis of the record definition,
22927 -- record components, both new and inherited, are accessible. Set their
22928 -- kind accordingly. Exclude malformed itypes from illegal declarations,
22929 -- whose Ekind may be void.
22931 Component
:= First_Entity
(Current_Scope
);
22932 while Present
(Component
) loop
22933 if Ekind
(Component
) = E_Void
22934 and then not Is_Itype
(Component
)
22936 Mutate_Ekind
(Component
, E_Component
);
22937 Reinit_Component_Location
(Component
);
22938 Set_Is_Not_Self_Hidden
(Component
);
22941 Propagate_Concurrent_Flags
(T
, Etype
(Component
));
22943 if Ekind
(Component
) /= E_Component
then
22946 -- Do not set Has_Controlled_Component on a class-wide equivalent
22947 -- type. See Make_CW_Equivalent_Type.
22949 elsif not Is_Class_Wide_Equivalent_Type
(T
)
22950 and then (Has_Controlled_Component
(Etype
(Component
))
22951 or else (Chars
(Component
) /= Name_uParent
22952 and then Is_Controlled
(Etype
(Component
))))
22954 Set_Has_Controlled_Component
(T
, True);
22955 Final_Storage_Only
:=
22957 and then Finalize_Storage_Only
(Etype
(Component
));
22958 Ctrl_Components
:= True;
22961 Next_Entity
(Component
);
22964 -- A Type is Finalize_Storage_Only only if all its controlled components
22967 if Ctrl_Components
then
22968 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
22971 -- Place reference to end record on the proper entity, which may
22972 -- be a partial view.
22974 if Present
(Def
) then
22975 Process_End_Label
(Def
, 'e', Prev_T
);
22977 end Record_Type_Definition
;
22979 ---------------------------
22980 -- Replace_Discriminants --
22981 ---------------------------
22983 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
) is
22984 function Process
(N
: Node_Id
) return Traverse_Result
;
22990 function Process
(N
: Node_Id
) return Traverse_Result
is
22994 if Nkind
(N
) = N_Discriminant_Specification
then
22995 Comp
:= First_Discriminant
(Typ
);
22996 while Present
(Comp
) loop
22997 if Original_Record_Component
(Comp
) = Defining_Identifier
(N
)
22998 or else Chars
(Comp
) = Chars
(Defining_Identifier
(N
))
23000 Set_Defining_Identifier
(N
, Comp
);
23004 Next_Discriminant
(Comp
);
23007 elsif Nkind
(N
) = N_Variant_Part
then
23008 Comp
:= First_Discriminant
(Typ
);
23009 while Present
(Comp
) loop
23010 if Original_Record_Component
(Comp
) = Entity
(Name
(N
))
23011 or else Chars
(Comp
) = Chars
(Name
(N
))
23013 -- Make sure to preserve the type coming from the parent on
23014 -- the Name, even if the subtype of the discriminant can be
23015 -- constrained, so that discrete choices inherited from the
23016 -- parent in the variant part are not flagged as violating
23017 -- the constraints of the subtype.
23020 Typ
: constant Entity_Id
:= Etype
(Name
(N
));
23022 Rewrite
(Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
23023 Set_Etype
(Name
(N
), Typ
);
23028 Next_Discriminant
(Comp
);
23035 procedure Replace
is new Traverse_Proc
(Process
);
23037 -- Start of processing for Replace_Discriminants
23041 end Replace_Discriminants
;
23043 -------------------------------
23044 -- Set_Completion_Referenced --
23045 -------------------------------
23047 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
23049 -- If in main unit, mark entity that is a completion as referenced,
23050 -- warnings go on the partial view when needed.
23052 if In_Extended_Main_Source_Unit
(E
) then
23053 Set_Referenced
(E
);
23055 end Set_Completion_Referenced
;
23057 ---------------------
23058 -- Set_Default_SSO --
23059 ---------------------
23061 procedure Set_Default_SSO
(T
: Entity_Id
) is
23063 case Opt
.Default_SSO
is
23067 Set_SSO_Set_Low_By_Default
(T
, True);
23069 Set_SSO_Set_High_By_Default
(T
, True);
23071 raise Program_Error
;
23073 end Set_Default_SSO
;
23075 ---------------------
23076 -- Set_Fixed_Range --
23077 ---------------------
23079 -- The range for fixed-point types is complicated by the fact that we
23080 -- do not know the exact end points at the time of the declaration. This
23081 -- is true for three reasons:
23083 -- A size clause may affect the fudging of the end-points.
23084 -- A small clause may affect the values of the end-points.
23085 -- We try to include the end-points if it does not affect the size.
23087 -- This means that the actual end-points must be established at the
23088 -- point when the type is frozen. Meanwhile, we first narrow the range
23089 -- as permitted (so that it will fit if necessary in a small specified
23090 -- size), and then build a range subtree with these narrowed bounds.
23091 -- Set_Fixed_Range constructs the range from real literal values, and
23092 -- sets the range as the Scalar_Range of the given fixed-point type entity.
23094 -- The parent of this range is set to point to the entity so that it is
23095 -- properly hooked into the tree (unlike normal Scalar_Range entries for
23096 -- other scalar types, which are just pointers to the range in the
23097 -- original tree, this would otherwise be an orphan).
23099 -- The tree is left unanalyzed. When the type is frozen, the processing
23100 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
23101 -- analyzed, and uses this as an indication that it should complete
23102 -- work on the range (it will know the final small and size values).
23104 procedure Set_Fixed_Range
23110 S
: constant Node_Id
:=
23112 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
23113 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
23115 Set_Scalar_Range
(E
, S
);
23118 -- Before the freeze point, the bounds of a fixed point are universal
23119 -- and carry the corresponding type.
23121 Set_Etype
(Low_Bound
(S
), Universal_Real
);
23122 Set_Etype
(High_Bound
(S
), Universal_Real
);
23123 end Set_Fixed_Range
;
23125 ----------------------------------
23126 -- Set_Scalar_Range_For_Subtype --
23127 ----------------------------------
23129 procedure Set_Scalar_Range_For_Subtype
23130 (Def_Id
: Entity_Id
;
23134 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
23137 -- Defend against previous error
23139 if Nkind
(R
) = N_Error
then
23143 Set_Scalar_Range
(Def_Id
, R
);
23145 -- We need to link the range into the tree before resolving it so
23146 -- that types that are referenced, including importantly the subtype
23147 -- itself, are properly frozen (Freeze_Expression requires that the
23148 -- expression be properly linked into the tree). Of course if it is
23149 -- already linked in, then we do not disturb the current link.
23151 if No
(Parent
(R
)) then
23152 Set_Parent
(R
, Def_Id
);
23155 -- Reset the kind of the subtype during analysis of the range, to
23156 -- catch possible premature use in the bounds themselves.
23158 Process_Range_Expr_In_Decl
(R
, Subt
, Subtyp
=> Def_Id
);
23159 pragma Assert
(Ekind
(Def_Id
) = Kind
);
23160 end Set_Scalar_Range_For_Subtype
;
23162 --------------------------------------------------------
23163 -- Set_Stored_Constraint_From_Discriminant_Constraint --
23164 --------------------------------------------------------
23166 procedure Set_Stored_Constraint_From_Discriminant_Constraint
23170 -- Make sure set if encountered during Expand_To_Stored_Constraint
23172 Set_Stored_Constraint
(E
, No_Elist
);
23174 -- Give it the right value
23176 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
23177 Set_Stored_Constraint
(E
,
23178 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
23180 end Set_Stored_Constraint_From_Discriminant_Constraint
;
23182 -------------------------------------
23183 -- Signed_Integer_Type_Declaration --
23184 -------------------------------------
23186 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
23187 Implicit_Base
: Entity_Id
;
23188 Base_Typ
: Entity_Id
;
23191 Errs
: Boolean := False;
23195 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
23196 -- Determine whether given bounds allow derivation from specified type
23198 procedure Check_Bound
(Expr
: Node_Id
);
23199 -- Check bound to make sure it is integral and static. If not, post
23200 -- appropriate error message and set Errs flag
23202 ---------------------
23203 -- Can_Derive_From --
23204 ---------------------
23206 -- Note we check both bounds against both end values, to deal with
23207 -- strange types like ones with a range of 0 .. -12341234.
23209 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
23210 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
23211 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
23213 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
23215 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
23216 end Can_Derive_From
;
23222 procedure Check_Bound
(Expr
: Node_Id
) is
23224 -- If a range constraint is used as an integer type definition, each
23225 -- bound of the range must be defined by a static expression of some
23226 -- integer type, but the two bounds need not have the same integer
23227 -- type (Negative bounds are allowed.) (RM 3.5.4)
23229 if not Is_Integer_Type
(Etype
(Expr
)) then
23231 ("integer type definition bounds must be of integer type", Expr
);
23234 elsif not Is_OK_Static_Expression
(Expr
) then
23235 Flag_Non_Static_Expr
23236 ("non-static expression used for integer type bound!", Expr
);
23239 -- Otherwise the bounds are folded into literals
23241 elsif Is_Entity_Name
(Expr
) then
23242 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
23246 -- Start of processing for Signed_Integer_Type_Declaration
23249 -- Create an anonymous base type
23252 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
23254 -- Analyze and check the bounds, they can be of any integer type
23256 Lo
:= Low_Bound
(Def
);
23257 Hi
:= High_Bound
(Def
);
23259 -- Arbitrarily use Integer as the type if either bound had an error
23261 if Hi
= Error
or else Lo
= Error
then
23262 Base_Typ
:= Any_Integer
;
23263 Set_Error_Posted
(T
, True);
23266 -- Here both bounds are OK expressions
23269 Analyze_And_Resolve
(Lo
, Any_Integer
);
23270 Analyze_And_Resolve
(Hi
, Any_Integer
);
23276 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
23277 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
23280 -- Find type to derive from
23282 Lo_Val
:= Expr_Value
(Lo
);
23283 Hi_Val
:= Expr_Value
(Hi
);
23285 if Can_Derive_From
(Standard_Short_Short_Integer
) then
23286 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
23288 elsif Can_Derive_From
(Standard_Short_Integer
) then
23289 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
23291 elsif Can_Derive_From
(Standard_Integer
) then
23292 Base_Typ
:= Base_Type
(Standard_Integer
);
23294 elsif Can_Derive_From
(Standard_Long_Integer
) then
23295 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
23297 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
23298 Check_Restriction
(No_Long_Long_Integers
, Def
);
23299 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
23301 elsif Can_Derive_From
(Standard_Long_Long_Long_Integer
) then
23302 Check_Restriction
(No_Long_Long_Integers
, Def
);
23303 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
23306 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
23307 Error_Msg_N
("integer type definition bounds out of range", Def
);
23308 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
23309 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
23313 -- Set the type of the bounds to the implicit base: we cannot set it to
23314 -- the new type, because this would be a forward reference for the code
23315 -- generator and, if the original type is user-defined, this could even
23316 -- lead to spurious semantic errors. Furthermore we do not set it to be
23317 -- universal, because this could make it much larger than needed here.
23320 Set_Etype
(Lo
, Implicit_Base
);
23321 Set_Etype
(Hi
, Implicit_Base
);
23324 -- Complete both implicit base and declared first subtype entities. The
23325 -- inheritance of the rep item chain ensures that SPARK-related pragmas
23326 -- are not clobbered when the signed integer type acts as a full view of
23329 Set_Etype
(Implicit_Base
, Base_Typ
);
23330 Set_Size_Info
(Implicit_Base
, Base_Typ
);
23331 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
23332 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
23333 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
23335 Mutate_Ekind
(T
, E_Signed_Integer_Subtype
);
23336 Set_Etype
(T
, Implicit_Base
);
23337 Set_Size_Info
(T
, Implicit_Base
);
23338 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
23339 Set_Scalar_Range
(T
, Def
);
23340 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
23341 Set_Is_Constrained
(T
);
23342 end Signed_Integer_Type_Declaration
;